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 (struct dwarf2_per_cu_data
*);
1573 static struct type
*set_die_type (struct die_info
*, struct type
*,
1574 struct dwarf2_cu
*);
1576 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1578 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1580 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1581 dwarf2_per_objfile
*per_objfile
,
1583 enum language pretend_language
);
1585 static void process_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1586 dwarf2_per_objfile
*per_objfile
,
1587 enum language pretend_language
);
1589 static void process_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1590 dwarf2_per_objfile
*per_objfile
,
1591 enum language pretend_language
);
1593 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1594 struct dwarf2_per_cu_data
*);
1596 static void dwarf2_mark (struct dwarf2_cu
*);
1598 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1600 static struct type
*get_die_type_at_offset (sect_offset
,
1601 struct dwarf2_per_cu_data
*);
1603 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1605 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1606 enum language pretend_language
);
1608 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1610 /* Class, the destructor of which frees all allocated queue entries. This
1611 will only have work to do if an error was thrown while processing the
1612 dwarf. If no error was thrown then the queue entries should have all
1613 been processed, and freed, as we went along. */
1615 class dwarf2_queue_guard
1618 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1619 : m_per_objfile (per_objfile
)
1623 /* Free any entries remaining on the queue. There should only be
1624 entries left if we hit an error while processing the dwarf. */
1625 ~dwarf2_queue_guard ()
1627 /* Ensure that no memory is allocated by the queue. */
1628 std::queue
<dwarf2_queue_item
> empty
;
1629 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1632 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1635 dwarf2_per_objfile
*m_per_objfile
;
1638 dwarf2_queue_item::~dwarf2_queue_item ()
1640 /* Anything still marked queued is likely to be in an
1641 inconsistent state, so discard it. */
1644 if (per_cu
->cu
!= NULL
)
1645 free_one_cached_comp_unit (per_cu
);
1650 /* The return type of find_file_and_directory. Note, the enclosed
1651 string pointers are only valid while this object is valid. */
1653 struct file_and_directory
1655 /* The filename. This is never NULL. */
1658 /* The compilation directory. NULL if not known. If we needed to
1659 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1660 points directly to the DW_AT_comp_dir string attribute owned by
1661 the obstack that owns the DIE. */
1662 const char *comp_dir
;
1664 /* If we needed to build a new string for comp_dir, this is what
1665 owns the storage. */
1666 std::string comp_dir_storage
;
1669 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1670 struct dwarf2_cu
*cu
);
1672 static htab_up
allocate_signatured_type_table ();
1674 static htab_up
allocate_dwo_unit_table ();
1676 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1677 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1678 struct dwp_file
*dwp_file
, const char *comp_dir
,
1679 ULONGEST signature
, int is_debug_types
);
1681 static struct dwp_file
*get_dwp_file
1682 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1684 static struct dwo_unit
*lookup_dwo_comp_unit
1685 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1686 ULONGEST signature
);
1688 static struct dwo_unit
*lookup_dwo_type_unit
1689 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1691 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1693 /* A unique pointer to a dwo_file. */
1695 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1697 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1699 static void check_producer (struct dwarf2_cu
*cu
);
1701 static void free_line_header_voidp (void *arg
);
1703 /* Various complaints about symbol reading that don't abort the process. */
1706 dwarf2_debug_line_missing_file_complaint (void)
1708 complaint (_(".debug_line section has line data without a file"));
1712 dwarf2_debug_line_missing_end_sequence_complaint (void)
1714 complaint (_(".debug_line section has line "
1715 "program sequence without an end"));
1719 dwarf2_complex_location_expr_complaint (void)
1721 complaint (_("location expression too complex"));
1725 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1728 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1733 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1735 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1739 /* Hash function for line_header_hash. */
1742 line_header_hash (const struct line_header
*ofs
)
1744 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1747 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1750 line_header_hash_voidp (const void *item
)
1752 const struct line_header
*ofs
= (const struct line_header
*) item
;
1754 return line_header_hash (ofs
);
1757 /* Equality function for line_header_hash. */
1760 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1762 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1763 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1765 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1766 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1771 /* See declaration. */
1773 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1776 can_copy (can_copy_
)
1779 names
= &dwarf2_elf_names
;
1781 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1782 locate_sections (obfd
, sec
, *names
);
1785 dwarf2_per_bfd::~dwarf2_per_bfd ()
1787 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1788 free_cached_comp_units ();
1790 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1791 per_cu
->imported_symtabs_free ();
1793 for (signatured_type
*sig_type
: all_type_units
)
1794 sig_type
->per_cu
.imported_symtabs_free ();
1796 /* Everything else should be on this->obstack. */
1799 /* See declaration. */
1802 dwarf2_per_bfd::free_cached_comp_units ()
1804 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1805 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1806 while (per_cu
!= NULL
)
1808 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1811 *last_chain
= next_cu
;
1816 /* A helper class that calls free_cached_comp_units on
1819 class free_cached_comp_units
1823 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1824 : m_per_objfile (per_objfile
)
1828 ~free_cached_comp_units ()
1830 m_per_objfile
->per_bfd
->free_cached_comp_units ();
1833 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1837 dwarf2_per_objfile
*m_per_objfile
;
1843 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1845 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1847 return this->m_symtabs
[per_cu
->index
] != nullptr;
1853 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1855 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1857 return this->m_symtabs
[per_cu
->index
];
1863 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1864 compunit_symtab
*symtab
)
1866 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1867 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1869 this->m_symtabs
[per_cu
->index
] = symtab
;
1872 /* Try to locate the sections we need for DWARF 2 debugging
1873 information and return true if we have enough to do something.
1874 NAMES points to the dwarf2 section names, or is NULL if the standard
1875 ELF names are used. CAN_COPY is true for formats where symbol
1876 interposition is possible and so symbol values must follow copy
1877 relocation rules. */
1880 dwarf2_has_info (struct objfile
*objfile
,
1881 const struct dwarf2_debug_sections
*names
,
1884 if (objfile
->flags
& OBJF_READNEVER
)
1887 struct dwarf2_per_objfile
*dwarf2_per_objfile
1888 = get_dwarf2_per_objfile (objfile
);
1890 if (dwarf2_per_objfile
== NULL
)
1892 /* For now, each dwarf2_per_objfile owns its own dwarf2_per_bfd (no
1894 dwarf2_per_bfd
*per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1896 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1899 return (!dwarf2_per_objfile
->per_bfd
->info
.is_virtual
1900 && dwarf2_per_objfile
->per_bfd
->info
.s
.section
!= NULL
1901 && !dwarf2_per_objfile
->per_bfd
->abbrev
.is_virtual
1902 && dwarf2_per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1905 /* When loading sections, we look either for uncompressed section or for
1906 compressed section names. */
1909 section_is_p (const char *section_name
,
1910 const struct dwarf2_section_names
*names
)
1912 if (names
->normal
!= NULL
1913 && strcmp (section_name
, names
->normal
) == 0)
1915 if (names
->compressed
!= NULL
1916 && strcmp (section_name
, names
->compressed
) == 0)
1921 /* See declaration. */
1924 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1925 const dwarf2_debug_sections
&names
)
1927 flagword aflag
= bfd_section_flags (sectp
);
1929 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1932 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1933 > bfd_get_file_size (abfd
))
1935 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1936 warning (_("Discarding section %s which has a section size (%s"
1937 ") larger than the file size [in module %s]"),
1938 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1939 bfd_get_filename (abfd
));
1941 else if (section_is_p (sectp
->name
, &names
.info
))
1943 this->info
.s
.section
= sectp
;
1944 this->info
.size
= bfd_section_size (sectp
);
1946 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1948 this->abbrev
.s
.section
= sectp
;
1949 this->abbrev
.size
= bfd_section_size (sectp
);
1951 else if (section_is_p (sectp
->name
, &names
.line
))
1953 this->line
.s
.section
= sectp
;
1954 this->line
.size
= bfd_section_size (sectp
);
1956 else if (section_is_p (sectp
->name
, &names
.loc
))
1958 this->loc
.s
.section
= sectp
;
1959 this->loc
.size
= bfd_section_size (sectp
);
1961 else if (section_is_p (sectp
->name
, &names
.loclists
))
1963 this->loclists
.s
.section
= sectp
;
1964 this->loclists
.size
= bfd_section_size (sectp
);
1966 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1968 this->macinfo
.s
.section
= sectp
;
1969 this->macinfo
.size
= bfd_section_size (sectp
);
1971 else if (section_is_p (sectp
->name
, &names
.macro
))
1973 this->macro
.s
.section
= sectp
;
1974 this->macro
.size
= bfd_section_size (sectp
);
1976 else if (section_is_p (sectp
->name
, &names
.str
))
1978 this->str
.s
.section
= sectp
;
1979 this->str
.size
= bfd_section_size (sectp
);
1981 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1983 this->str_offsets
.s
.section
= sectp
;
1984 this->str_offsets
.size
= bfd_section_size (sectp
);
1986 else if (section_is_p (sectp
->name
, &names
.line_str
))
1988 this->line_str
.s
.section
= sectp
;
1989 this->line_str
.size
= bfd_section_size (sectp
);
1991 else if (section_is_p (sectp
->name
, &names
.addr
))
1993 this->addr
.s
.section
= sectp
;
1994 this->addr
.size
= bfd_section_size (sectp
);
1996 else if (section_is_p (sectp
->name
, &names
.frame
))
1998 this->frame
.s
.section
= sectp
;
1999 this->frame
.size
= bfd_section_size (sectp
);
2001 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2003 this->eh_frame
.s
.section
= sectp
;
2004 this->eh_frame
.size
= bfd_section_size (sectp
);
2006 else if (section_is_p (sectp
->name
, &names
.ranges
))
2008 this->ranges
.s
.section
= sectp
;
2009 this->ranges
.size
= bfd_section_size (sectp
);
2011 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2013 this->rnglists
.s
.section
= sectp
;
2014 this->rnglists
.size
= bfd_section_size (sectp
);
2016 else if (section_is_p (sectp
->name
, &names
.types
))
2018 struct dwarf2_section_info type_section
;
2020 memset (&type_section
, 0, sizeof (type_section
));
2021 type_section
.s
.section
= sectp
;
2022 type_section
.size
= bfd_section_size (sectp
);
2024 this->types
.push_back (type_section
);
2026 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2028 this->gdb_index
.s
.section
= sectp
;
2029 this->gdb_index
.size
= bfd_section_size (sectp
);
2031 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2033 this->debug_names
.s
.section
= sectp
;
2034 this->debug_names
.size
= bfd_section_size (sectp
);
2036 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2038 this->debug_aranges
.s
.section
= sectp
;
2039 this->debug_aranges
.size
= bfd_section_size (sectp
);
2042 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2043 && bfd_section_vma (sectp
) == 0)
2044 this->has_section_at_zero
= true;
2047 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2051 dwarf2_get_section_info (struct objfile
*objfile
,
2052 enum dwarf2_section_enum sect
,
2053 asection
**sectp
, const gdb_byte
**bufp
,
2054 bfd_size_type
*sizep
)
2056 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2057 struct dwarf2_section_info
*info
;
2059 /* We may see an objfile without any DWARF, in which case we just
2070 case DWARF2_DEBUG_FRAME
:
2071 info
= &data
->per_bfd
->frame
;
2073 case DWARF2_EH_FRAME
:
2074 info
= &data
->per_bfd
->eh_frame
;
2077 gdb_assert_not_reached ("unexpected section");
2080 info
->read (objfile
);
2082 *sectp
= info
->get_bfd_section ();
2083 *bufp
= info
->buffer
;
2084 *sizep
= info
->size
;
2087 /* A helper function to find the sections for a .dwz file. */
2090 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2092 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2094 /* Note that we only support the standard ELF names, because .dwz
2095 is ELF-only (at the time of writing). */
2096 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2098 dwz_file
->abbrev
.s
.section
= sectp
;
2099 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2101 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2103 dwz_file
->info
.s
.section
= sectp
;
2104 dwz_file
->info
.size
= bfd_section_size (sectp
);
2106 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2108 dwz_file
->str
.s
.section
= sectp
;
2109 dwz_file
->str
.size
= bfd_section_size (sectp
);
2111 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2113 dwz_file
->line
.s
.section
= sectp
;
2114 dwz_file
->line
.size
= bfd_section_size (sectp
);
2116 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2118 dwz_file
->macro
.s
.section
= sectp
;
2119 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2121 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2123 dwz_file
->gdb_index
.s
.section
= sectp
;
2124 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2126 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2128 dwz_file
->debug_names
.s
.section
= sectp
;
2129 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2133 /* See dwarf2read.h. */
2136 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2138 const char *filename
;
2139 bfd_size_type buildid_len_arg
;
2143 if (per_bfd
->dwz_file
!= NULL
)
2144 return per_bfd
->dwz_file
.get ();
2146 bfd_set_error (bfd_error_no_error
);
2147 gdb::unique_xmalloc_ptr
<char> data
2148 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2149 &buildid_len_arg
, &buildid
));
2152 if (bfd_get_error () == bfd_error_no_error
)
2154 error (_("could not read '.gnu_debugaltlink' section: %s"),
2155 bfd_errmsg (bfd_get_error ()));
2158 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2160 buildid_len
= (size_t) buildid_len_arg
;
2162 filename
= data
.get ();
2164 std::string abs_storage
;
2165 if (!IS_ABSOLUTE_PATH (filename
))
2167 gdb::unique_xmalloc_ptr
<char> abs
2168 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2170 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2171 filename
= abs_storage
.c_str ();
2174 /* First try the file name given in the section. If that doesn't
2175 work, try to use the build-id instead. */
2176 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2177 if (dwz_bfd
!= NULL
)
2179 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2180 dwz_bfd
.reset (nullptr);
2183 if (dwz_bfd
== NULL
)
2184 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2186 if (dwz_bfd
== nullptr)
2188 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2189 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2191 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2198 /* File successfully retrieved from server. */
2199 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2201 if (dwz_bfd
== nullptr)
2202 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2203 alt_filename
.get ());
2204 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2205 dwz_bfd
.reset (nullptr);
2209 if (dwz_bfd
== NULL
)
2210 error (_("could not find '.gnu_debugaltlink' file for %s"),
2211 bfd_get_filename (per_bfd
->obfd
));
2213 std::unique_ptr
<struct dwz_file
> result
2214 (new struct dwz_file (std::move (dwz_bfd
)));
2216 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2219 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2220 per_bfd
->dwz_file
= std::move (result
);
2221 return per_bfd
->dwz_file
.get ();
2224 /* DWARF quick_symbols_functions support. */
2226 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2227 unique line tables, so we maintain a separate table of all .debug_line
2228 derived entries to support the sharing.
2229 All the quick functions need is the list of file names. We discard the
2230 line_header when we're done and don't need to record it here. */
2231 struct quick_file_names
2233 /* The data used to construct the hash key. */
2234 struct stmt_list_hash hash
;
2236 /* The number of entries in file_names, real_names. */
2237 unsigned int num_file_names
;
2239 /* The file names from the line table, after being run through
2241 const char **file_names
;
2243 /* The file names from the line table after being run through
2244 gdb_realpath. These are computed lazily. */
2245 const char **real_names
;
2248 /* When using the index (and thus not using psymtabs), each CU has an
2249 object of this type. This is used to hold information needed by
2250 the various "quick" methods. */
2251 struct dwarf2_per_cu_quick_data
2253 /* The file table. This can be NULL if there was no file table
2254 or it's currently not read in.
2255 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2256 struct quick_file_names
*file_names
;
2258 /* A temporary mark bit used when iterating over all CUs in
2259 expand_symtabs_matching. */
2260 unsigned int mark
: 1;
2262 /* True if we've tried to read the file table and found there isn't one.
2263 There will be no point in trying to read it again next time. */
2264 unsigned int no_file_data
: 1;
2267 /* Utility hash function for a stmt_list_hash. */
2270 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2274 if (stmt_list_hash
->dwo_unit
!= NULL
)
2275 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2276 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2280 /* Utility equality function for a stmt_list_hash. */
2283 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2284 const struct stmt_list_hash
*rhs
)
2286 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2288 if (lhs
->dwo_unit
!= NULL
2289 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2292 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2295 /* Hash function for a quick_file_names. */
2298 hash_file_name_entry (const void *e
)
2300 const struct quick_file_names
*file_data
2301 = (const struct quick_file_names
*) e
;
2303 return hash_stmt_list_entry (&file_data
->hash
);
2306 /* Equality function for a quick_file_names. */
2309 eq_file_name_entry (const void *a
, const void *b
)
2311 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2312 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2314 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2317 /* Delete function for a quick_file_names. */
2320 delete_file_name_entry (void *e
)
2322 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2325 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2327 xfree ((void*) file_data
->file_names
[i
]);
2328 if (file_data
->real_names
)
2329 xfree ((void*) file_data
->real_names
[i
]);
2332 /* The space for the struct itself lives on the obstack, so we don't
2336 /* Create a quick_file_names hash table. */
2339 create_quick_file_names_table (unsigned int nr_initial_entries
)
2341 return htab_up (htab_create_alloc (nr_initial_entries
,
2342 hash_file_name_entry
, eq_file_name_entry
,
2343 delete_file_name_entry
, xcalloc
, xfree
));
2346 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2347 function is unrelated to symtabs, symtab would have to be created afterwards.
2348 You should call age_cached_comp_units after processing the CU. */
2351 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2354 if (per_cu
->is_debug_types
)
2355 load_full_type_unit (per_cu
, per_objfile
);
2357 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2359 if (per_cu
->cu
== NULL
)
2360 return; /* Dummy CU. */
2362 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2365 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2368 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2369 dwarf2_per_objfile
*dwarf2_per_objfile
,
2372 /* Skip type_unit_groups, reading the type units they contain
2373 is handled elsewhere. */
2374 if (per_cu
->type_unit_group_p ())
2377 /* The destructor of dwarf2_queue_guard frees any entries left on
2378 the queue. After this point we're guaranteed to leave this function
2379 with the dwarf queue empty. */
2380 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2382 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2384 queue_comp_unit (per_cu
, language_minimal
);
2385 load_cu (per_cu
, dwarf2_per_objfile
, skip_partial
);
2387 /* If we just loaded a CU from a DWO, and we're working with an index
2388 that may badly handle TUs, load all the TUs in that DWO as well.
2389 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2390 if (!per_cu
->is_debug_types
2391 && per_cu
->cu
!= NULL
2392 && per_cu
->cu
->dwo_unit
!= NULL
2393 && dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
2394 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7
2395 /* DWP files aren't supported yet. */
2396 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2397 queue_and_load_all_dwo_tus (per_cu
);
2400 process_queue (dwarf2_per_objfile
);
2402 /* Age the cache, releasing compilation units that have not
2403 been used recently. */
2404 age_cached_comp_units (dwarf2_per_objfile
);
2407 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2408 the per-objfile for which this symtab is instantiated.
2410 Returns the resulting symbol table. */
2412 static struct compunit_symtab
*
2413 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2414 dwarf2_per_objfile
*dwarf2_per_objfile
,
2417 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
2419 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2421 free_cached_comp_units
freer (dwarf2_per_objfile
);
2422 scoped_restore decrementer
= increment_reading_symtab ();
2423 dw2_do_instantiate_symtab (per_cu
, dwarf2_per_objfile
, skip_partial
);
2424 process_cu_includes (dwarf2_per_objfile
);
2427 return dwarf2_per_objfile
->get_symtab (per_cu
);
2430 /* See declaration. */
2432 dwarf2_per_cu_data
*
2433 dwarf2_per_bfd::get_cutu (int index
)
2435 if (index
>= this->all_comp_units
.size ())
2437 index
-= this->all_comp_units
.size ();
2438 gdb_assert (index
< this->all_type_units
.size ());
2439 return &this->all_type_units
[index
]->per_cu
;
2442 return this->all_comp_units
[index
];
2445 /* See declaration. */
2447 dwarf2_per_cu_data
*
2448 dwarf2_per_bfd::get_cu (int index
)
2450 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2452 return this->all_comp_units
[index
];
2455 /* See declaration. */
2458 dwarf2_per_bfd::get_tu (int index
)
2460 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2462 return this->all_type_units
[index
];
2467 dwarf2_per_cu_data
*
2468 dwarf2_per_bfd::allocate_per_cu ()
2470 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2471 result
->per_bfd
= this;
2472 result
->index
= m_num_psymtabs
++;
2479 dwarf2_per_bfd::allocate_signatured_type ()
2481 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2482 result
->per_cu
.per_bfd
= this;
2483 result
->per_cu
.index
= m_num_psymtabs
++;
2487 /* Return a new dwarf2_per_cu_data allocated on the dwarf2_per_objfile
2488 obstack, and constructed with the specified field values. */
2490 static dwarf2_per_cu_data
*
2491 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2492 struct dwarf2_section_info
*section
,
2494 sect_offset sect_off
, ULONGEST length
)
2496 dwarf2_per_cu_data
*the_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
2497 the_cu
->sect_off
= sect_off
;
2498 the_cu
->length
= length
;
2499 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2500 the_cu
->section
= section
;
2501 the_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2502 struct dwarf2_per_cu_quick_data
);
2503 the_cu
->is_dwz
= is_dwz
;
2507 /* A helper for create_cus_from_index that handles a given list of
2511 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2512 const gdb_byte
*cu_list
, offset_type n_elements
,
2513 struct dwarf2_section_info
*section
,
2516 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2518 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2520 sect_offset sect_off
2521 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2522 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2525 dwarf2_per_cu_data
*per_cu
2526 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2528 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
2532 /* Read the CU list from the mapped index, and use it to create all
2533 the CU objects for this objfile. */
2536 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2537 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2538 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2540 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
2541 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve
2542 ((cu_list_elements
+ dwz_elements
) / 2);
2544 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2545 &dwarf2_per_objfile
->per_bfd
->info
, 0);
2547 if (dwz_elements
== 0)
2550 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
2551 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2555 /* Create the signatured type hash table from the index. */
2558 create_signatured_type_table_from_index
2559 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2560 struct dwarf2_section_info
*section
,
2561 const gdb_byte
*bytes
,
2562 offset_type elements
)
2564 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2565 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (elements
/ 3);
2567 htab_up sig_types_hash
= allocate_signatured_type_table ();
2569 for (offset_type i
= 0; i
< elements
; i
+= 3)
2571 struct signatured_type
*sig_type
;
2574 cu_offset type_offset_in_tu
;
2576 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2577 sect_offset sect_off
2578 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2580 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2582 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2585 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2586 sig_type
->signature
= signature
;
2587 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2588 sig_type
->per_cu
.is_debug_types
= 1;
2589 sig_type
->per_cu
.section
= section
;
2590 sig_type
->per_cu
.sect_off
= sect_off
;
2591 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2592 sig_type
->per_cu
.v
.quick
2593 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2594 struct dwarf2_per_cu_quick_data
);
2596 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2599 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2602 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2605 /* Create the signatured type hash table from .debug_names. */
2608 create_signatured_type_table_from_debug_names
2609 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2610 const mapped_debug_names
&map
,
2611 struct dwarf2_section_info
*section
,
2612 struct dwarf2_section_info
*abbrev_section
)
2614 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2616 section
->read (objfile
);
2617 abbrev_section
->read (objfile
);
2619 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2620 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2622 htab_up sig_types_hash
= allocate_signatured_type_table ();
2624 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2626 struct signatured_type
*sig_type
;
2629 sect_offset sect_off
2630 = (sect_offset
) (extract_unsigned_integer
2631 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2633 map
.dwarf5_byte_order
));
2635 comp_unit_head cu_header
;
2636 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2638 section
->buffer
+ to_underlying (sect_off
),
2641 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2642 sig_type
->signature
= cu_header
.signature
;
2643 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2644 sig_type
->per_cu
.is_debug_types
= 1;
2645 sig_type
->per_cu
.section
= section
;
2646 sig_type
->per_cu
.sect_off
= sect_off
;
2647 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2648 sig_type
->per_cu
.v
.quick
2649 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2650 struct dwarf2_per_cu_quick_data
);
2652 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2655 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2658 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2661 /* Read the address map data from the mapped index, and use it to
2662 populate the objfile's psymtabs_addrmap. */
2665 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2666 struct mapped_index
*index
)
2668 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2669 struct gdbarch
*gdbarch
= objfile
->arch ();
2670 const gdb_byte
*iter
, *end
;
2671 struct addrmap
*mutable_map
;
2674 auto_obstack temp_obstack
;
2676 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2678 iter
= index
->address_table
.data ();
2679 end
= iter
+ index
->address_table
.size ();
2681 baseaddr
= objfile
->text_section_offset ();
2685 ULONGEST hi
, lo
, cu_index
;
2686 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2688 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2690 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2695 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2696 hex_string (lo
), hex_string (hi
));
2700 if (cu_index
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
2702 complaint (_(".gdb_index address table has invalid CU number %u"),
2703 (unsigned) cu_index
);
2707 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2708 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2709 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2710 dwarf2_per_objfile
->per_bfd
->get_cu (cu_index
));
2713 objfile
->partial_symtabs
->psymtabs_addrmap
2714 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2717 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2718 populate the objfile's psymtabs_addrmap. */
2721 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2722 struct dwarf2_section_info
*section
)
2724 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2725 bfd
*abfd
= objfile
->obfd
;
2726 struct gdbarch
*gdbarch
= objfile
->arch ();
2727 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2729 auto_obstack temp_obstack
;
2730 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2732 std::unordered_map
<sect_offset
,
2733 dwarf2_per_cu_data
*,
2734 gdb::hash_enum
<sect_offset
>>
2735 debug_info_offset_to_per_cu
;
2736 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
2738 const auto insertpair
2739 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2740 if (!insertpair
.second
)
2742 warning (_("Section .debug_aranges in %s has duplicate "
2743 "debug_info_offset %s, ignoring .debug_aranges."),
2744 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2749 section
->read (objfile
);
2751 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2753 const gdb_byte
*addr
= section
->buffer
;
2755 while (addr
< section
->buffer
+ section
->size
)
2757 const gdb_byte
*const entry_addr
= addr
;
2758 unsigned int bytes_read
;
2760 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2764 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2765 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2766 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2767 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2769 warning (_("Section .debug_aranges in %s entry at offset %s "
2770 "length %s exceeds section length %s, "
2771 "ignoring .debug_aranges."),
2772 objfile_name (objfile
),
2773 plongest (entry_addr
- section
->buffer
),
2774 plongest (bytes_read
+ entry_length
),
2775 pulongest (section
->size
));
2779 /* The version number. */
2780 const uint16_t version
= read_2_bytes (abfd
, addr
);
2784 warning (_("Section .debug_aranges in %s entry at offset %s "
2785 "has unsupported version %d, ignoring .debug_aranges."),
2786 objfile_name (objfile
),
2787 plongest (entry_addr
- section
->buffer
), version
);
2791 const uint64_t debug_info_offset
2792 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2793 addr
+= offset_size
;
2794 const auto per_cu_it
2795 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2796 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2798 warning (_("Section .debug_aranges in %s entry at offset %s "
2799 "debug_info_offset %s does not exists, "
2800 "ignoring .debug_aranges."),
2801 objfile_name (objfile
),
2802 plongest (entry_addr
- section
->buffer
),
2803 pulongest (debug_info_offset
));
2806 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2808 const uint8_t address_size
= *addr
++;
2809 if (address_size
< 1 || address_size
> 8)
2811 warning (_("Section .debug_aranges in %s entry at offset %s "
2812 "address_size %u is invalid, ignoring .debug_aranges."),
2813 objfile_name (objfile
),
2814 plongest (entry_addr
- section
->buffer
), address_size
);
2818 const uint8_t segment_selector_size
= *addr
++;
2819 if (segment_selector_size
!= 0)
2821 warning (_("Section .debug_aranges in %s entry at offset %s "
2822 "segment_selector_size %u is not supported, "
2823 "ignoring .debug_aranges."),
2824 objfile_name (objfile
),
2825 plongest (entry_addr
- section
->buffer
),
2826 segment_selector_size
);
2830 /* Must pad to an alignment boundary that is twice the address
2831 size. It is undocumented by the DWARF standard but GCC does
2833 for (size_t padding
= ((-(addr
- section
->buffer
))
2834 & (2 * address_size
- 1));
2835 padding
> 0; padding
--)
2838 warning (_("Section .debug_aranges in %s entry at offset %s "
2839 "padding is not zero, ignoring .debug_aranges."),
2840 objfile_name (objfile
),
2841 plongest (entry_addr
- section
->buffer
));
2847 if (addr
+ 2 * address_size
> entry_end
)
2849 warning (_("Section .debug_aranges in %s entry at offset %s "
2850 "address list is not properly terminated, "
2851 "ignoring .debug_aranges."),
2852 objfile_name (objfile
),
2853 plongest (entry_addr
- section
->buffer
));
2856 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2858 addr
+= address_size
;
2859 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2861 addr
+= address_size
;
2862 if (start
== 0 && length
== 0)
2864 if (start
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
2866 /* Symbol was eliminated due to a COMDAT group. */
2869 ULONGEST end
= start
+ length
;
2870 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2872 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2874 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2878 objfile
->partial_symtabs
->psymtabs_addrmap
2879 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2882 /* Find a slot in the mapped index INDEX for the object named NAME.
2883 If NAME is found, set *VEC_OUT to point to the CU vector in the
2884 constant pool and return true. If NAME cannot be found, return
2888 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2889 offset_type
**vec_out
)
2892 offset_type slot
, step
;
2893 int (*cmp
) (const char *, const char *);
2895 gdb::unique_xmalloc_ptr
<char> without_params
;
2896 if (current_language
->la_language
== language_cplus
2897 || current_language
->la_language
== language_fortran
2898 || current_language
->la_language
== language_d
)
2900 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2903 if (strchr (name
, '(') != NULL
)
2905 without_params
= cp_remove_params (name
);
2907 if (without_params
!= NULL
)
2908 name
= without_params
.get ();
2912 /* Index version 4 did not support case insensitive searches. But the
2913 indices for case insensitive languages are built in lowercase, therefore
2914 simulate our NAME being searched is also lowercased. */
2915 hash
= mapped_index_string_hash ((index
->version
== 4
2916 && case_sensitivity
== case_sensitive_off
2917 ? 5 : index
->version
),
2920 slot
= hash
& (index
->symbol_table
.size () - 1);
2921 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2922 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2928 const auto &bucket
= index
->symbol_table
[slot
];
2929 if (bucket
.name
== 0 && bucket
.vec
== 0)
2932 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2933 if (!cmp (name
, str
))
2935 *vec_out
= (offset_type
*) (index
->constant_pool
2936 + MAYBE_SWAP (bucket
.vec
));
2940 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2944 /* A helper function that reads the .gdb_index from BUFFER and fills
2945 in MAP. FILENAME is the name of the file containing the data;
2946 it is used for error reporting. DEPRECATED_OK is true if it is
2947 ok to use deprecated sections.
2949 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2950 out parameters that are filled in with information about the CU and
2951 TU lists in the section.
2953 Returns true if all went well, false otherwise. */
2956 read_gdb_index_from_buffer (const char *filename
,
2958 gdb::array_view
<const gdb_byte
> buffer
,
2959 struct mapped_index
*map
,
2960 const gdb_byte
**cu_list
,
2961 offset_type
*cu_list_elements
,
2962 const gdb_byte
**types_list
,
2963 offset_type
*types_list_elements
)
2965 const gdb_byte
*addr
= &buffer
[0];
2967 /* Version check. */
2968 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2969 /* Versions earlier than 3 emitted every copy of a psymbol. This
2970 causes the index to behave very poorly for certain requests. Version 3
2971 contained incomplete addrmap. So, it seems better to just ignore such
2975 static int warning_printed
= 0;
2976 if (!warning_printed
)
2978 warning (_("Skipping obsolete .gdb_index section in %s."),
2980 warning_printed
= 1;
2984 /* Index version 4 uses a different hash function than index version
2987 Versions earlier than 6 did not emit psymbols for inlined
2988 functions. Using these files will cause GDB not to be able to
2989 set breakpoints on inlined functions by name, so we ignore these
2990 indices unless the user has done
2991 "set use-deprecated-index-sections on". */
2992 if (version
< 6 && !deprecated_ok
)
2994 static int warning_printed
= 0;
2995 if (!warning_printed
)
2998 Skipping deprecated .gdb_index section in %s.\n\
2999 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3000 to use the section anyway."),
3002 warning_printed
= 1;
3006 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3007 of the TU (for symbols coming from TUs),
3008 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3009 Plus gold-generated indices can have duplicate entries for global symbols,
3010 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3011 These are just performance bugs, and we can't distinguish gdb-generated
3012 indices from gold-generated ones, so issue no warning here. */
3014 /* Indexes with higher version than the one supported by GDB may be no
3015 longer backward compatible. */
3019 map
->version
= version
;
3021 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3024 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3025 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3029 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3030 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3031 - MAYBE_SWAP (metadata
[i
]))
3035 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3036 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3038 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3041 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3042 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3044 = gdb::array_view
<mapped_index::symbol_table_slot
>
3045 ((mapped_index::symbol_table_slot
*) symbol_table
,
3046 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3049 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3054 /* Callback types for dwarf2_read_gdb_index. */
3056 typedef gdb::function_view
3057 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3058 get_gdb_index_contents_ftype
;
3059 typedef gdb::function_view
3060 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3061 get_gdb_index_contents_dwz_ftype
;
3063 /* Read .gdb_index. If everything went ok, initialize the "quick"
3064 elements of all the CUs and return 1. Otherwise, return 0. */
3067 dwarf2_read_gdb_index
3068 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3069 get_gdb_index_contents_ftype get_gdb_index_contents
,
3070 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3072 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3073 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3074 struct dwz_file
*dwz
;
3075 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3077 gdb::array_view
<const gdb_byte
> main_index_contents
3078 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
->per_bfd
);
3080 if (main_index_contents
.empty ())
3083 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3084 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3085 use_deprecated_index_sections
,
3086 main_index_contents
, map
.get (), &cu_list
,
3087 &cu_list_elements
, &types_list
,
3088 &types_list_elements
))
3091 /* Don't use the index if it's empty. */
3092 if (map
->symbol_table
.empty ())
3095 /* If there is a .dwz file, read it so we can get its CU list as
3097 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
3100 struct mapped_index dwz_map
;
3101 const gdb_byte
*dwz_types_ignore
;
3102 offset_type dwz_types_elements_ignore
;
3104 gdb::array_view
<const gdb_byte
> dwz_index_content
3105 = get_gdb_index_contents_dwz (objfile
, dwz
);
3107 if (dwz_index_content
.empty ())
3110 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3111 1, dwz_index_content
, &dwz_map
,
3112 &dwz_list
, &dwz_list_elements
,
3114 &dwz_types_elements_ignore
))
3116 warning (_("could not read '.gdb_index' section from %s; skipping"),
3117 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3122 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3123 dwz_list
, dwz_list_elements
);
3125 if (types_list_elements
)
3127 /* We can only handle a single .debug_types when we have an
3129 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
3132 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
3134 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3135 types_list
, types_list_elements
);
3138 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3140 dwarf2_per_objfile
->per_bfd
->index_table
= std::move (map
);
3141 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
3142 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
3143 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
3148 /* die_reader_func for dw2_get_file_names. */
3151 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3152 const gdb_byte
*info_ptr
,
3153 struct die_info
*comp_unit_die
)
3155 struct dwarf2_cu
*cu
= reader
->cu
;
3156 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3157 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
3158 struct dwarf2_per_cu_data
*lh_cu
;
3159 struct attribute
*attr
;
3161 struct quick_file_names
*qfn
;
3163 gdb_assert (! this_cu
->is_debug_types
);
3165 /* Our callers never want to match partial units -- instead they
3166 will match the enclosing full CU. */
3167 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3169 this_cu
->v
.quick
->no_file_data
= 1;
3177 sect_offset line_offset
{};
3179 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3180 if (attr
!= nullptr)
3182 struct quick_file_names find_entry
;
3184 line_offset
= (sect_offset
) DW_UNSND (attr
);
3186 /* We may have already read in this line header (TU line header sharing).
3187 If we have we're done. */
3188 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3189 find_entry
.hash
.line_sect_off
= line_offset
;
3190 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3191 &find_entry
, INSERT
);
3194 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3198 lh
= dwarf_decode_line_header (line_offset
, cu
);
3202 lh_cu
->v
.quick
->no_file_data
= 1;
3206 qfn
= XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3207 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3208 qfn
->hash
.line_sect_off
= line_offset
;
3209 gdb_assert (slot
!= NULL
);
3212 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3215 if (strcmp (fnd
.name
, "<unknown>") != 0)
3218 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3220 XOBNEWVEC (&dwarf2_per_objfile
->per_bfd
->obstack
, const char *,
3221 qfn
->num_file_names
);
3223 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3224 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3225 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3226 fnd
.comp_dir
).release ();
3227 qfn
->real_names
= NULL
;
3229 lh_cu
->v
.quick
->file_names
= qfn
;
3232 /* A helper for the "quick" functions which attempts to read the line
3233 table for THIS_CU. */
3235 static struct quick_file_names
*
3236 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3237 dwarf2_per_objfile
*per_objfile
)
3239 /* This should never be called for TUs. */
3240 gdb_assert (! this_cu
->is_debug_types
);
3241 /* Nor type unit groups. */
3242 gdb_assert (! this_cu
->type_unit_group_p ());
3244 if (this_cu
->v
.quick
->file_names
!= NULL
)
3245 return this_cu
->v
.quick
->file_names
;
3246 /* If we know there is no line data, no point in looking again. */
3247 if (this_cu
->v
.quick
->no_file_data
)
3250 cutu_reader
reader (this_cu
, per_objfile
);
3251 if (!reader
.dummy_p
)
3252 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3254 if (this_cu
->v
.quick
->no_file_data
)
3256 return this_cu
->v
.quick
->file_names
;
3259 /* A helper for the "quick" functions which computes and caches the
3260 real path for a given file name from the line table. */
3263 dw2_get_real_path (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3264 struct quick_file_names
*qfn
, int index
)
3266 if (qfn
->real_names
== NULL
)
3267 qfn
->real_names
= OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
3268 qfn
->num_file_names
, const char *);
3270 if (qfn
->real_names
[index
] == NULL
)
3271 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3273 return qfn
->real_names
[index
];
3276 static struct symtab
*
3277 dw2_find_last_source_symtab (struct objfile
*objfile
)
3279 struct dwarf2_per_objfile
*dwarf2_per_objfile
3280 = get_dwarf2_per_objfile (objfile
);
3281 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->per_bfd
->all_comp_units
.back ();
3282 compunit_symtab
*cust
3283 = dw2_instantiate_symtab (dwarf_cu
, dwarf2_per_objfile
, false);
3288 return compunit_primary_filetab (cust
);
3291 /* Traversal function for dw2_forget_cached_source_info. */
3294 dw2_free_cached_file_names (void **slot
, void *info
)
3296 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3298 if (file_data
->real_names
)
3302 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3304 xfree ((void*) file_data
->real_names
[i
]);
3305 file_data
->real_names
[i
] = NULL
;
3313 dw2_forget_cached_source_info (struct objfile
*objfile
)
3315 struct dwarf2_per_objfile
*dwarf2_per_objfile
3316 = get_dwarf2_per_objfile (objfile
);
3318 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3319 dw2_free_cached_file_names
, NULL
);
3322 /* Helper function for dw2_map_symtabs_matching_filename that expands
3323 the symtabs and calls the iterator. */
3326 dw2_map_expand_apply (struct objfile
*objfile
,
3327 struct dwarf2_per_cu_data
*per_cu
,
3328 const char *name
, const char *real_path
,
3329 gdb::function_view
<bool (symtab
*)> callback
)
3331 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3333 /* Don't visit already-expanded CUs. */
3334 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3335 if (per_objfile
->symtab_set_p (per_cu
))
3338 /* This may expand more than one symtab, and we want to iterate over
3340 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3342 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3343 last_made
, callback
);
3346 /* Implementation of the map_symtabs_matching_filename method. */
3349 dw2_map_symtabs_matching_filename
3350 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3351 gdb::function_view
<bool (symtab
*)> callback
)
3353 const char *name_basename
= lbasename (name
);
3354 struct dwarf2_per_objfile
*dwarf2_per_objfile
3355 = get_dwarf2_per_objfile (objfile
);
3357 /* The rule is CUs specify all the files, including those used by
3358 any TU, so there's no need to scan TUs here. */
3360 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3362 /* We only need to look at symtabs not already expanded. */
3363 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3366 quick_file_names
*file_data
3367 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3368 if (file_data
== NULL
)
3371 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3373 const char *this_name
= file_data
->file_names
[j
];
3374 const char *this_real_name
;
3376 if (compare_filenames_for_search (this_name
, name
))
3378 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3384 /* Before we invoke realpath, which can get expensive when many
3385 files are involved, do a quick comparison of the basenames. */
3386 if (! basenames_may_differ
3387 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3390 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
3392 if (compare_filenames_for_search (this_real_name
, name
))
3394 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3400 if (real_path
!= NULL
)
3402 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3403 gdb_assert (IS_ABSOLUTE_PATH (name
));
3404 if (this_real_name
!= NULL
3405 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3407 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3419 /* Struct used to manage iterating over all CUs looking for a symbol. */
3421 struct dw2_symtab_iterator
3423 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3424 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3425 /* If set, only look for symbols that match that block. Valid values are
3426 GLOBAL_BLOCK and STATIC_BLOCK. */
3427 gdb::optional
<block_enum
> block_index
;
3428 /* The kind of symbol we're looking for. */
3430 /* The list of CUs from the index entry of the symbol,
3431 or NULL if not found. */
3433 /* The next element in VEC to look at. */
3435 /* The number of elements in VEC, or zero if there is no match. */
3437 /* Have we seen a global version of the symbol?
3438 If so we can ignore all further global instances.
3439 This is to work around gold/15646, inefficient gold-generated
3444 /* Initialize the index symtab iterator ITER. */
3447 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3448 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3449 gdb::optional
<block_enum
> block_index
,
3453 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3454 iter
->block_index
= block_index
;
3455 iter
->domain
= domain
;
3457 iter
->global_seen
= 0;
3459 mapped_index
*index
= dwarf2_per_objfile
->per_bfd
->index_table
.get ();
3461 /* index is NULL if OBJF_READNOW. */
3462 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3463 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3471 /* Return the next matching CU or NULL if there are no more. */
3473 static struct dwarf2_per_cu_data
*
3474 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3476 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3478 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3480 offset_type cu_index_and_attrs
=
3481 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3482 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3483 gdb_index_symbol_kind symbol_kind
=
3484 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3485 /* Only check the symbol attributes if they're present.
3486 Indices prior to version 7 don't record them,
3487 and indices >= 7 may elide them for certain symbols
3488 (gold does this). */
3490 (dwarf2_per_objfile
->per_bfd
->index_table
->version
>= 7
3491 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3493 /* Don't crash on bad data. */
3494 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3495 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
3497 complaint (_(".gdb_index entry has bad CU index"
3499 objfile_name (dwarf2_per_objfile
->objfile
));
3503 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
3505 /* Skip if already read in. */
3506 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3509 /* Check static vs global. */
3512 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3514 if (iter
->block_index
.has_value ())
3516 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3518 if (is_static
!= want_static
)
3522 /* Work around gold/15646. */
3523 if (!is_static
&& iter
->global_seen
)
3526 iter
->global_seen
= 1;
3529 /* Only check the symbol's kind if it has one. */
3532 switch (iter
->domain
)
3535 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3536 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3537 /* Some types are also in VAR_DOMAIN. */
3538 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3542 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3546 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3550 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3565 static struct compunit_symtab
*
3566 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3567 const char *name
, domain_enum domain
)
3569 struct compunit_symtab
*stab_best
= NULL
;
3570 struct dwarf2_per_objfile
*dwarf2_per_objfile
3571 = get_dwarf2_per_objfile (objfile
);
3573 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3575 struct dw2_symtab_iterator iter
;
3576 struct dwarf2_per_cu_data
*per_cu
;
3578 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3580 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3582 struct symbol
*sym
, *with_opaque
= NULL
;
3583 struct compunit_symtab
*stab
3584 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3585 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3586 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3588 sym
= block_find_symbol (block
, name
, domain
,
3589 block_find_non_opaque_type_preferred
,
3592 /* Some caution must be observed with overloaded functions
3593 and methods, since the index will not contain any overload
3594 information (but NAME might contain it). */
3597 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3599 if (with_opaque
!= NULL
3600 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3603 /* Keep looking through other CUs. */
3610 dw2_print_stats (struct objfile
*objfile
)
3612 struct dwarf2_per_objfile
*dwarf2_per_objfile
3613 = get_dwarf2_per_objfile (objfile
);
3614 int total
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3615 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3618 for (int i
= 0; i
< total
; ++i
)
3620 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3622 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
3625 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3626 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3629 /* This dumps minimal information about the index.
3630 It is called via "mt print objfiles".
3631 One use is to verify .gdb_index has been loaded by the
3632 gdb.dwarf2/gdb-index.exp testcase. */
3635 dw2_dump (struct objfile
*objfile
)
3637 struct dwarf2_per_objfile
*dwarf2_per_objfile
3638 = get_dwarf2_per_objfile (objfile
);
3640 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
3641 printf_filtered (".gdb_index:");
3642 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
)
3644 printf_filtered (" version %d\n",
3645 dwarf2_per_objfile
->per_bfd
->index_table
->version
);
3648 printf_filtered (" faked for \"readnow\"\n");
3649 printf_filtered ("\n");
3653 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3654 const char *func_name
)
3656 struct dwarf2_per_objfile
*dwarf2_per_objfile
3657 = get_dwarf2_per_objfile (objfile
);
3659 struct dw2_symtab_iterator iter
;
3660 struct dwarf2_per_cu_data
*per_cu
;
3662 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3664 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3665 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3670 dw2_expand_all_symtabs (struct objfile
*objfile
)
3672 struct dwarf2_per_objfile
*dwarf2_per_objfile
3673 = get_dwarf2_per_objfile (objfile
);
3674 int total_units
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3675 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3677 for (int i
= 0; i
< total_units
; ++i
)
3679 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3681 /* We don't want to directly expand a partial CU, because if we
3682 read it with the wrong language, then assertion failures can
3683 be triggered later on. See PR symtab/23010. So, tell
3684 dw2_instantiate_symtab to skip partial CUs -- any important
3685 partial CU will be read via DW_TAG_imported_unit anyway. */
3686 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, true);
3691 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3692 const char *fullname
)
3694 struct dwarf2_per_objfile
*dwarf2_per_objfile
3695 = get_dwarf2_per_objfile (objfile
);
3697 /* We don't need to consider type units here.
3698 This is only called for examining code, e.g. expand_line_sal.
3699 There can be an order of magnitude (or more) more type units
3700 than comp units, and we avoid them if we can. */
3702 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3704 /* We only need to look at symtabs not already expanded. */
3705 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3708 quick_file_names
*file_data
3709 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3710 if (file_data
== NULL
)
3713 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3715 const char *this_fullname
= file_data
->file_names
[j
];
3717 if (filename_cmp (this_fullname
, fullname
) == 0)
3719 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3727 dw2_expand_symtabs_matching_symbol
3728 (mapped_index_base
&index
,
3729 const lookup_name_info
&lookup_name_in
,
3730 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3731 enum search_domain kind
,
3732 gdb::function_view
<bool (offset_type
)> match_callback
);
3735 dw2_expand_symtabs_matching_one
3736 (dwarf2_per_cu_data
*per_cu
,
3737 dwarf2_per_objfile
*per_objfile
,
3738 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3739 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3742 dw2_map_matching_symbols
3743 (struct objfile
*objfile
,
3744 const lookup_name_info
&name
, domain_enum domain
,
3746 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3747 symbol_compare_ftype
*ordered_compare
)
3750 struct dwarf2_per_objfile
*dwarf2_per_objfile
3751 = get_dwarf2_per_objfile (objfile
);
3753 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3755 if (dwarf2_per_objfile
->per_bfd
->index_table
!= nullptr)
3757 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3758 here though if the current language is Ada for a non-Ada objfile
3760 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
3762 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3763 auto matcher
= [&] (const char *symname
)
3765 if (ordered_compare
== nullptr)
3767 return ordered_compare (symname
, match_name
) == 0;
3770 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3771 [&] (offset_type namei
)
3773 struct dw2_symtab_iterator iter
;
3774 struct dwarf2_per_cu_data
*per_cu
;
3776 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_kind
, domain
,
3778 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3779 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
3786 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3787 proceed assuming all symtabs have been read in. */
3790 for (compunit_symtab
*cust
: objfile
->compunits ())
3792 const struct block
*block
;
3796 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3797 if (!iterate_over_symbols_terminated (block
, name
,
3803 /* Starting from a search name, return the string that finds the upper
3804 bound of all strings that start with SEARCH_NAME in a sorted name
3805 list. Returns the empty string to indicate that the upper bound is
3806 the end of the list. */
3809 make_sort_after_prefix_name (const char *search_name
)
3811 /* When looking to complete "func", we find the upper bound of all
3812 symbols that start with "func" by looking for where we'd insert
3813 the closest string that would follow "func" in lexicographical
3814 order. Usually, that's "func"-with-last-character-incremented,
3815 i.e. "fund". Mind non-ASCII characters, though. Usually those
3816 will be UTF-8 multi-byte sequences, but we can't be certain.
3817 Especially mind the 0xff character, which is a valid character in
3818 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3819 rule out compilers allowing it in identifiers. Note that
3820 conveniently, strcmp/strcasecmp are specified to compare
3821 characters interpreted as unsigned char. So what we do is treat
3822 the whole string as a base 256 number composed of a sequence of
3823 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3824 to 0, and carries 1 to the following more-significant position.
3825 If the very first character in SEARCH_NAME ends up incremented
3826 and carries/overflows, then the upper bound is the end of the
3827 list. The string after the empty string is also the empty
3830 Some examples of this operation:
3832 SEARCH_NAME => "+1" RESULT
3836 "\xff" "a" "\xff" => "\xff" "b"
3841 Then, with these symbols for example:
3847 completing "func" looks for symbols between "func" and
3848 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3849 which finds "func" and "func1", but not "fund".
3853 funcÿ (Latin1 'ÿ' [0xff])
3857 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3858 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3862 ÿÿ (Latin1 'ÿ' [0xff])
3865 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3866 the end of the list.
3868 std::string after
= search_name
;
3869 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3871 if (!after
.empty ())
3872 after
.back () = (unsigned char) after
.back () + 1;
3876 /* See declaration. */
3878 std::pair
<std::vector
<name_component
>::const_iterator
,
3879 std::vector
<name_component
>::const_iterator
>
3880 mapped_index_base::find_name_components_bounds
3881 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3884 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3886 const char *lang_name
3887 = lookup_name_without_params
.language_lookup_name (lang
);
3889 /* Comparison function object for lower_bound that matches against a
3890 given symbol name. */
3891 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3894 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3895 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3896 return name_cmp (elem_name
, name
) < 0;
3899 /* Comparison function object for upper_bound that matches against a
3900 given symbol name. */
3901 auto lookup_compare_upper
= [&] (const char *name
,
3902 const name_component
&elem
)
3904 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3905 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3906 return name_cmp (name
, elem_name
) < 0;
3909 auto begin
= this->name_components
.begin ();
3910 auto end
= this->name_components
.end ();
3912 /* Find the lower bound. */
3915 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3918 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3921 /* Find the upper bound. */
3924 if (lookup_name_without_params
.completion_mode ())
3926 /* In completion mode, we want UPPER to point past all
3927 symbols names that have the same prefix. I.e., with
3928 these symbols, and completing "func":
3930 function << lower bound
3932 other_function << upper bound
3934 We find the upper bound by looking for the insertion
3935 point of "func"-with-last-character-incremented,
3937 std::string after
= make_sort_after_prefix_name (lang_name
);
3940 return std::lower_bound (lower
, end
, after
.c_str (),
3941 lookup_compare_lower
);
3944 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3947 return {lower
, upper
};
3950 /* See declaration. */
3953 mapped_index_base::build_name_components ()
3955 if (!this->name_components
.empty ())
3958 this->name_components_casing
= case_sensitivity
;
3960 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3962 /* The code below only knows how to break apart components of C++
3963 symbol names (and other languages that use '::' as
3964 namespace/module separator) and Ada symbol names. */
3965 auto count
= this->symbol_name_count ();
3966 for (offset_type idx
= 0; idx
< count
; idx
++)
3968 if (this->symbol_name_slot_invalid (idx
))
3971 const char *name
= this->symbol_name_at (idx
);
3973 /* Add each name component to the name component table. */
3974 unsigned int previous_len
= 0;
3976 if (strstr (name
, "::") != nullptr)
3978 for (unsigned int current_len
= cp_find_first_component (name
);
3979 name
[current_len
] != '\0';
3980 current_len
+= cp_find_first_component (name
+ current_len
))
3982 gdb_assert (name
[current_len
] == ':');
3983 this->name_components
.push_back ({previous_len
, idx
});
3984 /* Skip the '::'. */
3986 previous_len
= current_len
;
3991 /* Handle the Ada encoded (aka mangled) form here. */
3992 for (const char *iter
= strstr (name
, "__");
3994 iter
= strstr (iter
, "__"))
3996 this->name_components
.push_back ({previous_len
, idx
});
3998 previous_len
= iter
- name
;
4002 this->name_components
.push_back ({previous_len
, idx
});
4005 /* Sort name_components elements by name. */
4006 auto name_comp_compare
= [&] (const name_component
&left
,
4007 const name_component
&right
)
4009 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4010 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4012 const char *left_name
= left_qualified
+ left
.name_offset
;
4013 const char *right_name
= right_qualified
+ right
.name_offset
;
4015 return name_cmp (left_name
, right_name
) < 0;
4018 std::sort (this->name_components
.begin (),
4019 this->name_components
.end (),
4023 /* Helper for dw2_expand_symtabs_matching that works with a
4024 mapped_index_base instead of the containing objfile. This is split
4025 to a separate function in order to be able to unit test the
4026 name_components matching using a mock mapped_index_base. For each
4027 symbol name that matches, calls MATCH_CALLBACK, passing it the
4028 symbol's index in the mapped_index_base symbol table. */
4031 dw2_expand_symtabs_matching_symbol
4032 (mapped_index_base
&index
,
4033 const lookup_name_info
&lookup_name_in
,
4034 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4035 enum search_domain kind
,
4036 gdb::function_view
<bool (offset_type
)> match_callback
)
4038 lookup_name_info lookup_name_without_params
4039 = lookup_name_in
.make_ignore_params ();
4041 /* Build the symbol name component sorted vector, if we haven't
4043 index
.build_name_components ();
4045 /* The same symbol may appear more than once in the range though.
4046 E.g., if we're looking for symbols that complete "w", and we have
4047 a symbol named "w1::w2", we'll find the two name components for
4048 that same symbol in the range. To be sure we only call the
4049 callback once per symbol, we first collect the symbol name
4050 indexes that matched in a temporary vector and ignore
4052 std::vector
<offset_type
> matches
;
4054 struct name_and_matcher
4056 symbol_name_matcher_ftype
*matcher
;
4059 bool operator== (const name_and_matcher
&other
) const
4061 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4065 /* A vector holding all the different symbol name matchers, for all
4067 std::vector
<name_and_matcher
> matchers
;
4069 for (int i
= 0; i
< nr_languages
; i
++)
4071 enum language lang_e
= (enum language
) i
;
4073 const language_defn
*lang
= language_def (lang_e
);
4074 symbol_name_matcher_ftype
*name_matcher
4075 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4077 name_and_matcher key
{
4079 lookup_name_without_params
.language_lookup_name (lang_e
)
4082 /* Don't insert the same comparison routine more than once.
4083 Note that we do this linear walk. This is not a problem in
4084 practice because the number of supported languages is
4086 if (std::find (matchers
.begin (), matchers
.end (), key
)
4089 matchers
.push_back (std::move (key
));
4092 = index
.find_name_components_bounds (lookup_name_without_params
,
4095 /* Now for each symbol name in range, check to see if we have a name
4096 match, and if so, call the MATCH_CALLBACK callback. */
4098 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4100 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4102 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4103 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4106 matches
.push_back (bounds
.first
->idx
);
4110 std::sort (matches
.begin (), matches
.end ());
4112 /* Finally call the callback, once per match. */
4114 for (offset_type idx
: matches
)
4118 if (!match_callback (idx
))
4124 /* Above we use a type wider than idx's for 'prev', since 0 and
4125 (offset_type)-1 are both possible values. */
4126 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4131 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4133 /* A mock .gdb_index/.debug_names-like name index table, enough to
4134 exercise dw2_expand_symtabs_matching_symbol, which works with the
4135 mapped_index_base interface. Builds an index from the symbol list
4136 passed as parameter to the constructor. */
4137 class mock_mapped_index
: public mapped_index_base
4140 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4141 : m_symbol_table (symbols
)
4144 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4146 /* Return the number of names in the symbol table. */
4147 size_t symbol_name_count () const override
4149 return m_symbol_table
.size ();
4152 /* Get the name of the symbol at IDX in the symbol table. */
4153 const char *symbol_name_at (offset_type idx
) const override
4155 return m_symbol_table
[idx
];
4159 gdb::array_view
<const char *> m_symbol_table
;
4162 /* Convenience function that converts a NULL pointer to a "<null>"
4163 string, to pass to print routines. */
4166 string_or_null (const char *str
)
4168 return str
!= NULL
? str
: "<null>";
4171 /* Check if a lookup_name_info built from
4172 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4173 index. EXPECTED_LIST is the list of expected matches, in expected
4174 matching order. If no match expected, then an empty list is
4175 specified. Returns true on success. On failure prints a warning
4176 indicating the file:line that failed, and returns false. */
4179 check_match (const char *file
, int line
,
4180 mock_mapped_index
&mock_index
,
4181 const char *name
, symbol_name_match_type match_type
,
4182 bool completion_mode
,
4183 std::initializer_list
<const char *> expected_list
)
4185 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4187 bool matched
= true;
4189 auto mismatch
= [&] (const char *expected_str
,
4192 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4193 "expected=\"%s\", got=\"%s\"\n"),
4195 (match_type
== symbol_name_match_type::FULL
4197 name
, string_or_null (expected_str
), string_or_null (got
));
4201 auto expected_it
= expected_list
.begin ();
4202 auto expected_end
= expected_list
.end ();
4204 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4206 [&] (offset_type idx
)
4208 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4209 const char *expected_str
4210 = expected_it
== expected_end
? NULL
: *expected_it
++;
4212 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4213 mismatch (expected_str
, matched_name
);
4217 const char *expected_str
4218 = expected_it
== expected_end
? NULL
: *expected_it
++;
4219 if (expected_str
!= NULL
)
4220 mismatch (expected_str
, NULL
);
4225 /* The symbols added to the mock mapped_index for testing (in
4227 static const char *test_symbols
[] = {
4236 "ns2::tmpl<int>::foo2",
4237 "(anonymous namespace)::A::B::C",
4239 /* These are used to check that the increment-last-char in the
4240 matching algorithm for completion doesn't match "t1_fund" when
4241 completing "t1_func". */
4247 /* A UTF-8 name with multi-byte sequences to make sure that
4248 cp-name-parser understands this as a single identifier ("função"
4249 is "function" in PT). */
4252 /* \377 (0xff) is Latin1 'ÿ'. */
4255 /* \377 (0xff) is Latin1 'ÿ'. */
4259 /* A name with all sorts of complications. Starts with "z" to make
4260 it easier for the completion tests below. */
4261 #define Z_SYM_NAME \
4262 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4263 "::tuple<(anonymous namespace)::ui*, " \
4264 "std::default_delete<(anonymous namespace)::ui>, void>"
4269 /* Returns true if the mapped_index_base::find_name_component_bounds
4270 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4271 in completion mode. */
4274 check_find_bounds_finds (mapped_index_base
&index
,
4275 const char *search_name
,
4276 gdb::array_view
<const char *> expected_syms
)
4278 lookup_name_info
lookup_name (search_name
,
4279 symbol_name_match_type::FULL
, true);
4281 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4284 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4285 if (distance
!= expected_syms
.size ())
4288 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4290 auto nc_elem
= bounds
.first
+ exp_elem
;
4291 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4292 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4299 /* Test the lower-level mapped_index::find_name_component_bounds
4303 test_mapped_index_find_name_component_bounds ()
4305 mock_mapped_index
mock_index (test_symbols
);
4307 mock_index
.build_name_components ();
4309 /* Test the lower-level mapped_index::find_name_component_bounds
4310 method in completion mode. */
4312 static const char *expected_syms
[] = {
4317 SELF_CHECK (check_find_bounds_finds (mock_index
,
4318 "t1_func", expected_syms
));
4321 /* Check that the increment-last-char in the name matching algorithm
4322 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4324 static const char *expected_syms1
[] = {
4328 SELF_CHECK (check_find_bounds_finds (mock_index
,
4329 "\377", expected_syms1
));
4331 static const char *expected_syms2
[] = {
4334 SELF_CHECK (check_find_bounds_finds (mock_index
,
4335 "\377\377", expected_syms2
));
4339 /* Test dw2_expand_symtabs_matching_symbol. */
4342 test_dw2_expand_symtabs_matching_symbol ()
4344 mock_mapped_index
mock_index (test_symbols
);
4346 /* We let all tests run until the end even if some fails, for debug
4348 bool any_mismatch
= false;
4350 /* Create the expected symbols list (an initializer_list). Needed
4351 because lists have commas, and we need to pass them to CHECK,
4352 which is a macro. */
4353 #define EXPECT(...) { __VA_ARGS__ }
4355 /* Wrapper for check_match that passes down the current
4356 __FILE__/__LINE__. */
4357 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4358 any_mismatch |= !check_match (__FILE__, __LINE__, \
4360 NAME, MATCH_TYPE, COMPLETION_MODE, \
4363 /* Identity checks. */
4364 for (const char *sym
: test_symbols
)
4366 /* Should be able to match all existing symbols. */
4367 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4370 /* Should be able to match all existing symbols with
4372 std::string with_params
= std::string (sym
) + "(int)";
4373 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4376 /* Should be able to match all existing symbols with
4377 parameters and qualifiers. */
4378 with_params
= std::string (sym
) + " ( int ) const";
4379 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4382 /* This should really find sym, but cp-name-parser.y doesn't
4383 know about lvalue/rvalue qualifiers yet. */
4384 with_params
= std::string (sym
) + " ( int ) &&";
4385 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4389 /* Check that the name matching algorithm for completion doesn't get
4390 confused with Latin1 'ÿ' / 0xff. */
4392 static const char str
[] = "\377";
4393 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4394 EXPECT ("\377", "\377\377123"));
4397 /* Check that the increment-last-char in the matching algorithm for
4398 completion doesn't match "t1_fund" when completing "t1_func". */
4400 static const char str
[] = "t1_func";
4401 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4402 EXPECT ("t1_func", "t1_func1"));
4405 /* Check that completion mode works at each prefix of the expected
4408 static const char str
[] = "function(int)";
4409 size_t len
= strlen (str
);
4412 for (size_t i
= 1; i
< len
; i
++)
4414 lookup
.assign (str
, i
);
4415 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4416 EXPECT ("function"));
4420 /* While "w" is a prefix of both components, the match function
4421 should still only be called once. */
4423 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4425 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4429 /* Same, with a "complicated" symbol. */
4431 static const char str
[] = Z_SYM_NAME
;
4432 size_t len
= strlen (str
);
4435 for (size_t i
= 1; i
< len
; i
++)
4437 lookup
.assign (str
, i
);
4438 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4439 EXPECT (Z_SYM_NAME
));
4443 /* In FULL mode, an incomplete symbol doesn't match. */
4445 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4449 /* A complete symbol with parameters matches any overload, since the
4450 index has no overload info. */
4452 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4453 EXPECT ("std::zfunction", "std::zfunction2"));
4454 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4455 EXPECT ("std::zfunction", "std::zfunction2"));
4456 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4457 EXPECT ("std::zfunction", "std::zfunction2"));
4460 /* Check that whitespace is ignored appropriately. A symbol with a
4461 template argument list. */
4463 static const char expected
[] = "ns::foo<int>";
4464 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4466 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4470 /* Check that whitespace is ignored appropriately. A symbol with a
4471 template argument list that includes a pointer. */
4473 static const char expected
[] = "ns::foo<char*>";
4474 /* Try both completion and non-completion modes. */
4475 static const bool completion_mode
[2] = {false, true};
4476 for (size_t i
= 0; i
< 2; i
++)
4478 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4479 completion_mode
[i
], EXPECT (expected
));
4480 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4481 completion_mode
[i
], EXPECT (expected
));
4483 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4484 completion_mode
[i
], EXPECT (expected
));
4485 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4486 completion_mode
[i
], EXPECT (expected
));
4491 /* Check method qualifiers are ignored. */
4492 static const char expected
[] = "ns::foo<char*>";
4493 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4494 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4495 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4496 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4497 CHECK_MATCH ("foo < char * > ( int ) const",
4498 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4499 CHECK_MATCH ("foo < char * > ( int ) &&",
4500 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4503 /* Test lookup names that don't match anything. */
4505 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4508 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4512 /* Some wild matching tests, exercising "(anonymous namespace)",
4513 which should not be confused with a parameter list. */
4515 static const char *syms
[] = {
4519 "A :: B :: C ( int )",
4524 for (const char *s
: syms
)
4526 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4527 EXPECT ("(anonymous namespace)::A::B::C"));
4532 static const char expected
[] = "ns2::tmpl<int>::foo2";
4533 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4535 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4539 SELF_CHECK (!any_mismatch
);
4548 test_mapped_index_find_name_component_bounds ();
4549 test_dw2_expand_symtabs_matching_symbol ();
4552 }} // namespace selftests::dw2_expand_symtabs_matching
4554 #endif /* GDB_SELF_TEST */
4556 /* If FILE_MATCHER is NULL or if PER_CU has
4557 dwarf2_per_cu_quick_data::MARK set (see
4558 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4559 EXPANSION_NOTIFY on it. */
4562 dw2_expand_symtabs_matching_one
4563 (dwarf2_per_cu_data
*per_cu
,
4564 dwarf2_per_objfile
*per_objfile
,
4565 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4566 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4568 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4570 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4572 compunit_symtab
*symtab
4573 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4574 gdb_assert (symtab
!= nullptr);
4576 if (expansion_notify
!= NULL
&& symtab_was_null
)
4577 expansion_notify (symtab
);
4581 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4582 matched, to expand corresponding CUs that were marked. IDX is the
4583 index of the symbol name that matched. */
4586 dw2_expand_marked_cus
4587 (dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4588 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4589 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4592 offset_type
*vec
, vec_len
, vec_idx
;
4593 bool global_seen
= false;
4594 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4596 vec
= (offset_type
*) (index
.constant_pool
4597 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4598 vec_len
= MAYBE_SWAP (vec
[0]);
4599 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4601 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4602 /* This value is only valid for index versions >= 7. */
4603 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4604 gdb_index_symbol_kind symbol_kind
=
4605 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4606 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4607 /* Only check the symbol attributes if they're present.
4608 Indices prior to version 7 don't record them,
4609 and indices >= 7 may elide them for certain symbols
4610 (gold does this). */
4613 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4615 /* Work around gold/15646. */
4618 if (!is_static
&& global_seen
)
4624 /* Only check the symbol's kind if it has one. */
4629 case VARIABLES_DOMAIN
:
4630 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4633 case FUNCTIONS_DOMAIN
:
4634 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4638 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4641 case MODULES_DOMAIN
:
4642 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4650 /* Don't crash on bad data. */
4651 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
4652 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
4654 complaint (_(".gdb_index entry has bad CU index"
4656 objfile_name (dwarf2_per_objfile
->objfile
));
4660 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
4661 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, file_matcher
,
4666 /* If FILE_MATCHER is non-NULL, set all the
4667 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4668 that match FILE_MATCHER. */
4671 dw_expand_symtabs_matching_file_matcher
4672 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4673 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4675 if (file_matcher
== NULL
)
4678 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4680 NULL
, xcalloc
, xfree
));
4681 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4683 NULL
, xcalloc
, xfree
));
4685 /* The rule is CUs specify all the files, including those used by
4686 any TU, so there's no need to scan TUs here. */
4688 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4692 per_cu
->v
.quick
->mark
= 0;
4694 /* We only need to look at symtabs not already expanded. */
4695 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4698 quick_file_names
*file_data
4699 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4700 if (file_data
== NULL
)
4703 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4705 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4707 per_cu
->v
.quick
->mark
= 1;
4711 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4713 const char *this_real_name
;
4715 if (file_matcher (file_data
->file_names
[j
], false))
4717 per_cu
->v
.quick
->mark
= 1;
4721 /* Before we invoke realpath, which can get expensive when many
4722 files are involved, do a quick comparison of the basenames. */
4723 if (!basenames_may_differ
4724 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4728 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
4730 if (file_matcher (this_real_name
, false))
4732 per_cu
->v
.quick
->mark
= 1;
4737 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4738 ? visited_found
.get ()
4739 : visited_not_found
.get (),
4746 dw2_expand_symtabs_matching
4747 (struct objfile
*objfile
,
4748 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4749 const lookup_name_info
*lookup_name
,
4750 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4751 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4752 enum search_domain kind
)
4754 struct dwarf2_per_objfile
*dwarf2_per_objfile
4755 = get_dwarf2_per_objfile (objfile
);
4757 /* index_table is NULL if OBJF_READNOW. */
4758 if (!dwarf2_per_objfile
->per_bfd
->index_table
)
4761 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4763 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4765 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4769 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
4770 file_matcher
, expansion_notify
);
4775 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4777 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4779 kind
, [&] (offset_type idx
)
4781 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4782 expansion_notify
, kind
);
4787 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4790 static struct compunit_symtab
*
4791 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4796 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4797 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4800 if (cust
->includes
== NULL
)
4803 for (i
= 0; cust
->includes
[i
]; ++i
)
4805 struct compunit_symtab
*s
= cust
->includes
[i
];
4807 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4815 static struct compunit_symtab
*
4816 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4817 struct bound_minimal_symbol msymbol
,
4819 struct obj_section
*section
,
4822 struct dwarf2_per_cu_data
*data
;
4823 struct compunit_symtab
*result
;
4825 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4828 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4829 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4830 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4834 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4835 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4836 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4837 paddress (objfile
->arch (), pc
));
4839 result
= recursively_find_pc_sect_compunit_symtab
4840 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4842 gdb_assert (result
!= NULL
);
4847 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4848 void *data
, int need_fullname
)
4850 struct dwarf2_per_objfile
*dwarf2_per_objfile
4851 = get_dwarf2_per_objfile (objfile
);
4853 if (!dwarf2_per_objfile
->per_bfd
->filenames_cache
)
4855 dwarf2_per_objfile
->per_bfd
->filenames_cache
.emplace ();
4857 htab_up
visited (htab_create_alloc (10,
4858 htab_hash_pointer
, htab_eq_pointer
,
4859 NULL
, xcalloc
, xfree
));
4861 /* The rule is CUs specify all the files, including those used
4862 by any TU, so there's no need to scan TUs here. We can
4863 ignore file names coming from already-expanded CUs. */
4865 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4867 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4869 void **slot
= htab_find_slot (visited
.get (),
4870 per_cu
->v
.quick
->file_names
,
4873 *slot
= per_cu
->v
.quick
->file_names
;
4877 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4879 /* We only need to look at symtabs not already expanded. */
4880 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4883 quick_file_names
*file_data
4884 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4885 if (file_data
== NULL
)
4888 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4891 /* Already visited. */
4896 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4898 const char *filename
= file_data
->file_names
[j
];
4899 dwarf2_per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4904 dwarf2_per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4906 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4909 this_real_name
= gdb_realpath (filename
);
4910 (*fun
) (filename
, this_real_name
.get (), data
);
4915 dw2_has_symbols (struct objfile
*objfile
)
4920 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4923 dw2_find_last_source_symtab
,
4924 dw2_forget_cached_source_info
,
4925 dw2_map_symtabs_matching_filename
,
4930 dw2_expand_symtabs_for_function
,
4931 dw2_expand_all_symtabs
,
4932 dw2_expand_symtabs_with_fullname
,
4933 dw2_map_matching_symbols
,
4934 dw2_expand_symtabs_matching
,
4935 dw2_find_pc_sect_compunit_symtab
,
4937 dw2_map_symbol_filenames
4940 /* DWARF-5 debug_names reader. */
4942 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4943 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4945 /* A helper function that reads the .debug_names section in SECTION
4946 and fills in MAP. FILENAME is the name of the file containing the
4947 section; it is used for error reporting.
4949 Returns true if all went well, false otherwise. */
4952 read_debug_names_from_section (struct objfile
*objfile
,
4953 const char *filename
,
4954 struct dwarf2_section_info
*section
,
4955 mapped_debug_names
&map
)
4957 if (section
->empty ())
4960 /* Older elfutils strip versions could keep the section in the main
4961 executable while splitting it for the separate debug info file. */
4962 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4965 section
->read (objfile
);
4967 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4969 const gdb_byte
*addr
= section
->buffer
;
4971 bfd
*const abfd
= section
->get_bfd_owner ();
4973 unsigned int bytes_read
;
4974 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4977 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4978 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4979 if (bytes_read
+ length
!= section
->size
)
4981 /* There may be multiple per-CU indices. */
4982 warning (_("Section .debug_names in %s length %s does not match "
4983 "section length %s, ignoring .debug_names."),
4984 filename
, plongest (bytes_read
+ length
),
4985 pulongest (section
->size
));
4989 /* The version number. */
4990 uint16_t version
= read_2_bytes (abfd
, addr
);
4994 warning (_("Section .debug_names in %s has unsupported version %d, "
4995 "ignoring .debug_names."),
5001 uint16_t padding
= read_2_bytes (abfd
, addr
);
5005 warning (_("Section .debug_names in %s has unsupported padding %d, "
5006 "ignoring .debug_names."),
5011 /* comp_unit_count - The number of CUs in the CU list. */
5012 map
.cu_count
= read_4_bytes (abfd
, addr
);
5015 /* local_type_unit_count - The number of TUs in the local TU
5017 map
.tu_count
= read_4_bytes (abfd
, addr
);
5020 /* foreign_type_unit_count - The number of TUs in the foreign TU
5022 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5024 if (foreign_tu_count
!= 0)
5026 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5027 "ignoring .debug_names."),
5028 filename
, static_cast<unsigned long> (foreign_tu_count
));
5032 /* bucket_count - The number of hash buckets in the hash lookup
5034 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5037 /* name_count - The number of unique names in the index. */
5038 map
.name_count
= read_4_bytes (abfd
, addr
);
5041 /* abbrev_table_size - The size in bytes of the abbreviations
5043 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5046 /* augmentation_string_size - The size in bytes of the augmentation
5047 string. This value is rounded up to a multiple of 4. */
5048 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5050 map
.augmentation_is_gdb
= ((augmentation_string_size
5051 == sizeof (dwarf5_augmentation
))
5052 && memcmp (addr
, dwarf5_augmentation
,
5053 sizeof (dwarf5_augmentation
)) == 0);
5054 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5055 addr
+= augmentation_string_size
;
5058 map
.cu_table_reordered
= addr
;
5059 addr
+= map
.cu_count
* map
.offset_size
;
5061 /* List of Local TUs */
5062 map
.tu_table_reordered
= addr
;
5063 addr
+= map
.tu_count
* map
.offset_size
;
5065 /* Hash Lookup Table */
5066 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5067 addr
+= map
.bucket_count
* 4;
5068 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5069 addr
+= map
.name_count
* 4;
5072 map
.name_table_string_offs_reordered
= addr
;
5073 addr
+= map
.name_count
* map
.offset_size
;
5074 map
.name_table_entry_offs_reordered
= addr
;
5075 addr
+= map
.name_count
* map
.offset_size
;
5077 const gdb_byte
*abbrev_table_start
= addr
;
5080 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5085 const auto insertpair
5086 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5087 if (!insertpair
.second
)
5089 warning (_("Section .debug_names in %s has duplicate index %s, "
5090 "ignoring .debug_names."),
5091 filename
, pulongest (index_num
));
5094 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5095 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5100 mapped_debug_names::index_val::attr attr
;
5101 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5103 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5105 if (attr
.form
== DW_FORM_implicit_const
)
5107 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5111 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5113 indexval
.attr_vec
.push_back (std::move (attr
));
5116 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5118 warning (_("Section .debug_names in %s has abbreviation_table "
5119 "of size %s vs. written as %u, ignoring .debug_names."),
5120 filename
, plongest (addr
- abbrev_table_start
),
5124 map
.entry_pool
= addr
;
5129 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5133 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5134 const mapped_debug_names
&map
,
5135 dwarf2_section_info
§ion
,
5138 if (!map
.augmentation_is_gdb
)
5140 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5142 sect_offset sect_off
5143 = (sect_offset
) (extract_unsigned_integer
5144 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5146 map
.dwarf5_byte_order
));
5147 /* We don't know the length of the CU, because the CU list in a
5148 .debug_names index can be incomplete, so we can't use the start of
5149 the next CU as end of this CU. We create the CUs here with length 0,
5150 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5151 dwarf2_per_cu_data
*per_cu
5152 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5154 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5158 sect_offset sect_off_prev
;
5159 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5161 sect_offset sect_off_next
;
5162 if (i
< map
.cu_count
)
5165 = (sect_offset
) (extract_unsigned_integer
5166 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5168 map
.dwarf5_byte_order
));
5171 sect_off_next
= (sect_offset
) section
.size
;
5174 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5175 dwarf2_per_cu_data
*per_cu
5176 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5177 sect_off_prev
, length
);
5178 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5180 sect_off_prev
= sect_off_next
;
5184 /* Read the CU list from the mapped index, and use it to create all
5185 the CU objects for this dwarf2_per_objfile. */
5188 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5189 const mapped_debug_names
&map
,
5190 const mapped_debug_names
&dwz_map
)
5192 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
5193 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5195 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5196 dwarf2_per_objfile
->per_bfd
->info
,
5197 false /* is_dwz */);
5199 if (dwz_map
.cu_count
== 0)
5202 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
5203 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5207 /* Read .debug_names. If everything went ok, initialize the "quick"
5208 elements of all the CUs and return true. Otherwise, return false. */
5211 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5213 std::unique_ptr
<mapped_debug_names
> map
5214 (new mapped_debug_names (dwarf2_per_objfile
));
5215 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5216 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5218 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5219 &dwarf2_per_objfile
->per_bfd
->debug_names
,
5223 /* Don't use the index if it's empty. */
5224 if (map
->name_count
== 0)
5227 /* If there is a .dwz file, read it so we can get its CU list as
5229 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
5232 if (!read_debug_names_from_section (objfile
,
5233 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5234 &dwz
->debug_names
, dwz_map
))
5236 warning (_("could not read '.debug_names' section from %s; skipping"),
5237 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5242 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5244 if (map
->tu_count
!= 0)
5246 /* We can only handle a single .debug_types when we have an
5248 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
5251 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
5253 create_signatured_type_table_from_debug_names
5254 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->per_bfd
->abbrev
);
5257 create_addrmap_from_aranges (dwarf2_per_objfile
,
5258 &dwarf2_per_objfile
->per_bfd
->debug_aranges
);
5260 dwarf2_per_objfile
->per_bfd
->debug_names_table
= std::move (map
);
5261 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5262 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
5263 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5268 /* Type used to manage iterating over all CUs looking for a symbol for
5271 class dw2_debug_names_iterator
5274 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5275 gdb::optional
<block_enum
> block_index
,
5278 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5279 m_addr (find_vec_in_debug_names (map
, name
))
5282 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5283 search_domain search
, uint32_t namei
)
5286 m_addr (find_vec_in_debug_names (map
, namei
))
5289 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5290 block_enum block_index
, domain_enum domain
,
5292 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5293 m_addr (find_vec_in_debug_names (map
, namei
))
5296 /* Return the next matching CU or NULL if there are no more. */
5297 dwarf2_per_cu_data
*next ();
5300 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5302 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5305 /* The internalized form of .debug_names. */
5306 const mapped_debug_names
&m_map
;
5308 /* If set, only look for symbols that match that block. Valid values are
5309 GLOBAL_BLOCK and STATIC_BLOCK. */
5310 const gdb::optional
<block_enum
> m_block_index
;
5312 /* The kind of symbol we're looking for. */
5313 const domain_enum m_domain
= UNDEF_DOMAIN
;
5314 const search_domain m_search
= ALL_DOMAIN
;
5316 /* The list of CUs from the index entry of the symbol, or NULL if
5318 const gdb_byte
*m_addr
;
5322 mapped_debug_names::namei_to_name (uint32_t namei
) const
5324 const ULONGEST namei_string_offs
5325 = extract_unsigned_integer ((name_table_string_offs_reordered
5326 + namei
* offset_size
),
5329 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5333 /* Find a slot in .debug_names for the object named NAME. If NAME is
5334 found, return pointer to its pool data. If NAME cannot be found,
5338 dw2_debug_names_iterator::find_vec_in_debug_names
5339 (const mapped_debug_names
&map
, const char *name
)
5341 int (*cmp
) (const char *, const char *);
5343 gdb::unique_xmalloc_ptr
<char> without_params
;
5344 if (current_language
->la_language
== language_cplus
5345 || current_language
->la_language
== language_fortran
5346 || current_language
->la_language
== language_d
)
5348 /* NAME is already canonical. Drop any qualifiers as
5349 .debug_names does not contain any. */
5351 if (strchr (name
, '(') != NULL
)
5353 without_params
= cp_remove_params (name
);
5354 if (without_params
!= NULL
)
5355 name
= without_params
.get ();
5359 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5361 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5363 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5364 (map
.bucket_table_reordered
5365 + (full_hash
% map
.bucket_count
)), 4,
5366 map
.dwarf5_byte_order
);
5370 if (namei
>= map
.name_count
)
5372 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5374 namei
, map
.name_count
,
5375 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5381 const uint32_t namei_full_hash
5382 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5383 (map
.hash_table_reordered
+ namei
), 4,
5384 map
.dwarf5_byte_order
);
5385 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5388 if (full_hash
== namei_full_hash
)
5390 const char *const namei_string
= map
.namei_to_name (namei
);
5392 #if 0 /* An expensive sanity check. */
5393 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5395 complaint (_("Wrong .debug_names hash for string at index %u "
5397 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5402 if (cmp (namei_string
, name
) == 0)
5404 const ULONGEST namei_entry_offs
5405 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5406 + namei
* map
.offset_size
),
5407 map
.offset_size
, map
.dwarf5_byte_order
);
5408 return map
.entry_pool
+ namei_entry_offs
;
5413 if (namei
>= map
.name_count
)
5419 dw2_debug_names_iterator::find_vec_in_debug_names
5420 (const mapped_debug_names
&map
, uint32_t namei
)
5422 if (namei
>= map
.name_count
)
5424 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5426 namei
, map
.name_count
,
5427 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5431 const ULONGEST namei_entry_offs
5432 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5433 + namei
* map
.offset_size
),
5434 map
.offset_size
, map
.dwarf5_byte_order
);
5435 return map
.entry_pool
+ namei_entry_offs
;
5438 /* See dw2_debug_names_iterator. */
5440 dwarf2_per_cu_data
*
5441 dw2_debug_names_iterator::next ()
5446 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5447 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5448 bfd
*const abfd
= objfile
->obfd
;
5452 unsigned int bytes_read
;
5453 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5454 m_addr
+= bytes_read
;
5458 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5459 if (indexval_it
== m_map
.abbrev_map
.cend ())
5461 complaint (_("Wrong .debug_names undefined abbrev code %s "
5463 pulongest (abbrev
), objfile_name (objfile
));
5466 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5467 enum class symbol_linkage
{
5471 } symbol_linkage_
= symbol_linkage::unknown
;
5472 dwarf2_per_cu_data
*per_cu
= NULL
;
5473 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5478 case DW_FORM_implicit_const
:
5479 ull
= attr
.implicit_const
;
5481 case DW_FORM_flag_present
:
5485 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5486 m_addr
+= bytes_read
;
5489 ull
= read_4_bytes (abfd
, m_addr
);
5493 ull
= read_8_bytes (abfd
, m_addr
);
5496 case DW_FORM_ref_sig8
:
5497 ull
= read_8_bytes (abfd
, m_addr
);
5501 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5502 dwarf_form_name (attr
.form
),
5503 objfile_name (objfile
));
5506 switch (attr
.dw_idx
)
5508 case DW_IDX_compile_unit
:
5509 /* Don't crash on bad data. */
5510 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
5512 complaint (_(".debug_names entry has bad CU index %s"
5515 objfile_name (dwarf2_per_objfile
->objfile
));
5518 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (ull
);
5520 case DW_IDX_type_unit
:
5521 /* Don't crash on bad data. */
5522 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_type_units
.size ())
5524 complaint (_(".debug_names entry has bad TU index %s"
5527 objfile_name (dwarf2_per_objfile
->objfile
));
5530 per_cu
= &dwarf2_per_objfile
->per_bfd
->get_tu (ull
)->per_cu
;
5532 case DW_IDX_die_offset
:
5533 /* In a per-CU index (as opposed to a per-module index), index
5534 entries without CU attribute implicitly refer to the single CU. */
5536 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cu (0);
5538 case DW_IDX_GNU_internal
:
5539 if (!m_map
.augmentation_is_gdb
)
5541 symbol_linkage_
= symbol_linkage::static_
;
5543 case DW_IDX_GNU_external
:
5544 if (!m_map
.augmentation_is_gdb
)
5546 symbol_linkage_
= symbol_linkage::extern_
;
5551 /* Skip if already read in. */
5552 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
5555 /* Check static vs global. */
5556 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5558 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5559 const bool symbol_is_static
=
5560 symbol_linkage_
== symbol_linkage::static_
;
5561 if (want_static
!= symbol_is_static
)
5565 /* Match dw2_symtab_iter_next, symbol_kind
5566 and debug_names::psymbol_tag. */
5570 switch (indexval
.dwarf_tag
)
5572 case DW_TAG_variable
:
5573 case DW_TAG_subprogram
:
5574 /* Some types are also in VAR_DOMAIN. */
5575 case DW_TAG_typedef
:
5576 case DW_TAG_structure_type
:
5583 switch (indexval
.dwarf_tag
)
5585 case DW_TAG_typedef
:
5586 case DW_TAG_structure_type
:
5593 switch (indexval
.dwarf_tag
)
5596 case DW_TAG_variable
:
5603 switch (indexval
.dwarf_tag
)
5615 /* Match dw2_expand_symtabs_matching, symbol_kind and
5616 debug_names::psymbol_tag. */
5619 case VARIABLES_DOMAIN
:
5620 switch (indexval
.dwarf_tag
)
5622 case DW_TAG_variable
:
5628 case FUNCTIONS_DOMAIN
:
5629 switch (indexval
.dwarf_tag
)
5631 case DW_TAG_subprogram
:
5638 switch (indexval
.dwarf_tag
)
5640 case DW_TAG_typedef
:
5641 case DW_TAG_structure_type
:
5647 case MODULES_DOMAIN
:
5648 switch (indexval
.dwarf_tag
)
5662 static struct compunit_symtab
*
5663 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5664 const char *name
, domain_enum domain
)
5666 struct dwarf2_per_objfile
*dwarf2_per_objfile
5667 = get_dwarf2_per_objfile (objfile
);
5669 const auto &mapp
= dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5672 /* index is NULL if OBJF_READNOW. */
5675 const auto &map
= *mapp
;
5677 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5679 struct compunit_symtab
*stab_best
= NULL
;
5680 struct dwarf2_per_cu_data
*per_cu
;
5681 while ((per_cu
= iter
.next ()) != NULL
)
5683 struct symbol
*sym
, *with_opaque
= NULL
;
5684 compunit_symtab
*stab
5685 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5686 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5687 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5689 sym
= block_find_symbol (block
, name
, domain
,
5690 block_find_non_opaque_type_preferred
,
5693 /* Some caution must be observed with overloaded functions and
5694 methods, since the index will not contain any overload
5695 information (but NAME might contain it). */
5698 && strcmp_iw (sym
->search_name (), name
) == 0)
5700 if (with_opaque
!= NULL
5701 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5704 /* Keep looking through other CUs. */
5710 /* This dumps minimal information about .debug_names. It is called
5711 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5712 uses this to verify that .debug_names has been loaded. */
5715 dw2_debug_names_dump (struct objfile
*objfile
)
5717 struct dwarf2_per_objfile
*dwarf2_per_objfile
5718 = get_dwarf2_per_objfile (objfile
);
5720 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
5721 printf_filtered (".debug_names:");
5722 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5723 printf_filtered (" exists\n");
5725 printf_filtered (" faked for \"readnow\"\n");
5726 printf_filtered ("\n");
5730 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5731 const char *func_name
)
5733 struct dwarf2_per_objfile
*dwarf2_per_objfile
5734 = get_dwarf2_per_objfile (objfile
);
5736 /* dwarf2_per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5737 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5739 const mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5741 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5743 struct dwarf2_per_cu_data
*per_cu
;
5744 while ((per_cu
= iter
.next ()) != NULL
)
5745 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5750 dw2_debug_names_map_matching_symbols
5751 (struct objfile
*objfile
,
5752 const lookup_name_info
&name
, domain_enum domain
,
5754 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5755 symbol_compare_ftype
*ordered_compare
)
5757 struct dwarf2_per_objfile
*dwarf2_per_objfile
5758 = get_dwarf2_per_objfile (objfile
);
5760 /* debug_names_table is NULL if OBJF_READNOW. */
5761 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5764 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5765 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5767 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5768 auto matcher
= [&] (const char *symname
)
5770 if (ordered_compare
== nullptr)
5772 return ordered_compare (symname
, match_name
) == 0;
5775 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5776 [&] (offset_type namei
)
5778 /* The name was matched, now expand corresponding CUs that were
5780 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5782 struct dwarf2_per_cu_data
*per_cu
;
5783 while ((per_cu
= iter
.next ()) != NULL
)
5784 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
5789 /* It's a shame we couldn't do this inside the
5790 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5791 that have already been expanded. Instead, this loop matches what
5792 the psymtab code does. */
5793 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5795 compunit_symtab
*symtab
= dwarf2_per_objfile
->get_symtab (per_cu
);
5796 if (symtab
!= nullptr)
5798 const struct block
*block
5799 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5800 if (!iterate_over_symbols_terminated (block
, name
,
5808 dw2_debug_names_expand_symtabs_matching
5809 (struct objfile
*objfile
,
5810 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5811 const lookup_name_info
*lookup_name
,
5812 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5813 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5814 enum search_domain kind
)
5816 struct dwarf2_per_objfile
*dwarf2_per_objfile
5817 = get_dwarf2_per_objfile (objfile
);
5819 /* debug_names_table is NULL if OBJF_READNOW. */
5820 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5823 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5825 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5827 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5831 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5832 file_matcher
, expansion_notify
);
5837 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5839 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5841 kind
, [&] (offset_type namei
)
5843 /* The name was matched, now expand corresponding CUs that were
5845 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5847 struct dwarf2_per_cu_data
*per_cu
;
5848 while ((per_cu
= iter
.next ()) != NULL
)
5849 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5850 file_matcher
, expansion_notify
);
5855 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5858 dw2_find_last_source_symtab
,
5859 dw2_forget_cached_source_info
,
5860 dw2_map_symtabs_matching_filename
,
5861 dw2_debug_names_lookup_symbol
,
5864 dw2_debug_names_dump
,
5865 dw2_debug_names_expand_symtabs_for_function
,
5866 dw2_expand_all_symtabs
,
5867 dw2_expand_symtabs_with_fullname
,
5868 dw2_debug_names_map_matching_symbols
,
5869 dw2_debug_names_expand_symtabs_matching
,
5870 dw2_find_pc_sect_compunit_symtab
,
5872 dw2_map_symbol_filenames
5875 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5876 to either a dwarf2_per_bfd or dwz_file object. */
5878 template <typename T
>
5879 static gdb::array_view
<const gdb_byte
>
5880 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5882 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5884 if (section
->empty ())
5887 /* Older elfutils strip versions could keep the section in the main
5888 executable while splitting it for the separate debug info file. */
5889 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5892 section
->read (obj
);
5894 /* dwarf2_section_info::size is a bfd_size_type, while
5895 gdb::array_view works with size_t. On 32-bit hosts, with
5896 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5897 is 32-bit. So we need an explicit narrowing conversion here.
5898 This is fine, because it's impossible to allocate or mmap an
5899 array/buffer larger than what size_t can represent. */
5900 return gdb::make_array_view (section
->buffer
, section
->size
);
5903 /* Lookup the index cache for the contents of the index associated to
5906 static gdb::array_view
<const gdb_byte
>
5907 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5909 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5910 if (build_id
== nullptr)
5913 return global_index_cache
.lookup_gdb_index (build_id
,
5914 &dwarf2_per_bfd
->index_cache_res
);
5917 /* Same as the above, but for DWZ. */
5919 static gdb::array_view
<const gdb_byte
>
5920 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5922 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5923 if (build_id
== nullptr)
5926 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5929 /* See symfile.h. */
5932 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5934 struct dwarf2_per_objfile
*dwarf2_per_objfile
5935 = get_dwarf2_per_objfile (objfile
);
5937 /* If we're about to read full symbols, don't bother with the
5938 indices. In this case we also don't care if some other debug
5939 format is making psymtabs, because they are all about to be
5941 if ((objfile
->flags
& OBJF_READNOW
))
5943 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5944 create_all_comp_units (dwarf2_per_objfile
);
5945 create_all_type_units (dwarf2_per_objfile
);
5946 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
5947 = create_quick_file_names_table
5948 (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5949 dwarf2_per_objfile
->resize_symtabs ();
5951 for (int i
= 0; i
< (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
5952 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()); ++i
)
5954 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
5956 per_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
5957 struct dwarf2_per_cu_quick_data
);
5960 /* Return 1 so that gdb sees the "quick" functions. However,
5961 these functions will be no-ops because we will have expanded
5963 *index_kind
= dw_index_kind::GDB_INDEX
;
5967 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5969 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5970 dwarf2_per_objfile
->resize_symtabs ();
5974 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5975 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5976 get_gdb_index_contents_from_section
<dwz_file
>))
5978 *index_kind
= dw_index_kind::GDB_INDEX
;
5979 dwarf2_per_objfile
->resize_symtabs ();
5983 /* ... otherwise, try to find the index in the index cache. */
5984 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5985 get_gdb_index_contents_from_cache
,
5986 get_gdb_index_contents_from_cache_dwz
))
5988 global_index_cache
.hit ();
5989 *index_kind
= dw_index_kind::GDB_INDEX
;
5990 dwarf2_per_objfile
->resize_symtabs ();
5994 global_index_cache
.miss ();
6000 /* Build a partial symbol table. */
6003 dwarf2_build_psymtabs (struct objfile
*objfile
)
6005 struct dwarf2_per_objfile
*dwarf2_per_objfile
6006 = get_dwarf2_per_objfile (objfile
);
6008 init_psymbol_list (objfile
, 1024);
6012 /* This isn't really ideal: all the data we allocate on the
6013 objfile's obstack is still uselessly kept around. However,
6014 freeing it seems unsafe. */
6015 psymtab_discarder
psymtabs (objfile
);
6016 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6019 dwarf2_per_objfile
->resize_symtabs ();
6021 /* (maybe) store an index in the cache. */
6022 global_index_cache
.store (dwarf2_per_objfile
);
6024 catch (const gdb_exception_error
&except
)
6026 exception_print (gdb_stderr
, except
);
6030 /* Find the base address of the compilation unit for range lists and
6031 location lists. It will normally be specified by DW_AT_low_pc.
6032 In DWARF-3 draft 4, the base address could be overridden by
6033 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6034 compilation units with discontinuous ranges. */
6037 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6039 struct attribute
*attr
;
6041 cu
->base_address
.reset ();
6043 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6044 if (attr
!= nullptr)
6045 cu
->base_address
= attr
->value_as_address ();
6048 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6049 if (attr
!= nullptr)
6050 cu
->base_address
= attr
->value_as_address ();
6054 /* Helper function that returns the proper abbrev section for
6057 static struct dwarf2_section_info
*
6058 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6060 struct dwarf2_section_info
*abbrev
;
6061 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6063 if (this_cu
->is_dwz
)
6064 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6066 abbrev
= &per_bfd
->abbrev
;
6071 /* Fetch the abbreviation table offset from a comp or type unit header. */
6074 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6075 struct dwarf2_section_info
*section
,
6076 sect_offset sect_off
)
6078 bfd
*abfd
= section
->get_bfd_owner ();
6079 const gdb_byte
*info_ptr
;
6080 unsigned int initial_length_size
, offset_size
;
6083 section
->read (dwarf2_per_objfile
->objfile
);
6084 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6085 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6086 offset_size
= initial_length_size
== 4 ? 4 : 8;
6087 info_ptr
+= initial_length_size
;
6089 version
= read_2_bytes (abfd
, info_ptr
);
6093 /* Skip unit type and address size. */
6097 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6100 /* A partial symtab that is used only for include files. */
6101 struct dwarf2_include_psymtab
: public partial_symtab
6103 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6104 : partial_symtab (filename
, objfile
)
6108 void read_symtab (struct objfile
*objfile
) override
6110 /* It's an include file, no symbols to read for it.
6111 Everything is in the includer symtab. */
6113 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6114 expansion of the includer psymtab. We use the dependencies[0] field to
6115 model the includer. But if we go the regular route of calling
6116 expand_psymtab here, and having expand_psymtab call expand_dependencies
6117 to expand the includer, we'll only use expand_psymtab on the includer
6118 (making it a non-toplevel psymtab), while if we expand the includer via
6119 another path, we'll use read_symtab (making it a toplevel psymtab).
6120 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6121 psymtab, and trigger read_symtab on the includer here directly. */
6122 includer ()->read_symtab (objfile
);
6125 void expand_psymtab (struct objfile
*objfile
) override
6127 /* This is not called by read_symtab, and should not be called by any
6128 expand_dependencies. */
6132 bool readin_p (struct objfile
*objfile
) const override
6134 return includer ()->readin_p (objfile
);
6137 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6143 partial_symtab
*includer () const
6145 /* An include psymtab has exactly one dependency: the psymtab that
6147 gdb_assert (this->number_of_dependencies
== 1);
6148 return this->dependencies
[0];
6152 /* Allocate a new partial symtab for file named NAME and mark this new
6153 partial symtab as being an include of PST. */
6156 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6157 struct objfile
*objfile
)
6159 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6161 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6162 subpst
->dirname
= pst
->dirname
;
6164 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6165 subpst
->dependencies
[0] = pst
;
6166 subpst
->number_of_dependencies
= 1;
6169 /* Read the Line Number Program data and extract the list of files
6170 included by the source file represented by PST. Build an include
6171 partial symtab for each of these included files. */
6174 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6175 struct die_info
*die
,
6176 dwarf2_psymtab
*pst
)
6179 struct attribute
*attr
;
6181 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6182 if (attr
!= nullptr)
6183 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6185 return; /* No linetable, so no includes. */
6187 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6188 that we pass in the raw text_low here; that is ok because we're
6189 only decoding the line table to make include partial symtabs, and
6190 so the addresses aren't really used. */
6191 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6192 pst
->raw_text_low (), 1);
6196 hash_signatured_type (const void *item
)
6198 const struct signatured_type
*sig_type
6199 = (const struct signatured_type
*) item
;
6201 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6202 return sig_type
->signature
;
6206 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6208 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6209 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6211 return lhs
->signature
== rhs
->signature
;
6214 /* Allocate a hash table for signatured types. */
6217 allocate_signatured_type_table ()
6219 return htab_up (htab_create_alloc (41,
6220 hash_signatured_type
,
6222 NULL
, xcalloc
, xfree
));
6225 /* A helper function to add a signatured type CU to a table. */
6228 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6230 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6231 std::vector
<signatured_type
*> *all_type_units
6232 = (std::vector
<signatured_type
*> *) datum
;
6234 all_type_units
->push_back (sigt
);
6239 /* A helper for create_debug_types_hash_table. Read types from SECTION
6240 and fill them into TYPES_HTAB. It will process only type units,
6241 therefore DW_UT_type. */
6244 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6245 struct dwo_file
*dwo_file
,
6246 dwarf2_section_info
*section
, htab_up
&types_htab
,
6247 rcuh_kind section_kind
)
6249 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6250 struct dwarf2_section_info
*abbrev_section
;
6252 const gdb_byte
*info_ptr
, *end_ptr
;
6254 abbrev_section
= (dwo_file
!= NULL
6255 ? &dwo_file
->sections
.abbrev
6256 : &dwarf2_per_objfile
->per_bfd
->abbrev
);
6258 if (dwarf_read_debug
)
6259 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6260 section
->get_name (),
6261 abbrev_section
->get_file_name ());
6263 section
->read (objfile
);
6264 info_ptr
= section
->buffer
;
6266 if (info_ptr
== NULL
)
6269 /* We can't set abfd until now because the section may be empty or
6270 not present, in which case the bfd is unknown. */
6271 abfd
= section
->get_bfd_owner ();
6273 /* We don't use cutu_reader here because we don't need to read
6274 any dies: the signature is in the header. */
6276 end_ptr
= info_ptr
+ section
->size
;
6277 while (info_ptr
< end_ptr
)
6279 struct signatured_type
*sig_type
;
6280 struct dwo_unit
*dwo_tu
;
6282 const gdb_byte
*ptr
= info_ptr
;
6283 struct comp_unit_head header
;
6284 unsigned int length
;
6286 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6288 /* Initialize it due to a false compiler warning. */
6289 header
.signature
= -1;
6290 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6292 /* We need to read the type's signature in order to build the hash
6293 table, but we don't need anything else just yet. */
6295 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6296 abbrev_section
, ptr
, section_kind
);
6298 length
= header
.get_length ();
6300 /* Skip dummy type units. */
6301 if (ptr
>= info_ptr
+ length
6302 || peek_abbrev_code (abfd
, ptr
) == 0
6303 || header
.unit_type
!= DW_UT_type
)
6309 if (types_htab
== NULL
)
6312 types_htab
= allocate_dwo_unit_table ();
6314 types_htab
= allocate_signatured_type_table ();
6320 dwo_tu
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6322 dwo_tu
->dwo_file
= dwo_file
;
6323 dwo_tu
->signature
= header
.signature
;
6324 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6325 dwo_tu
->section
= section
;
6326 dwo_tu
->sect_off
= sect_off
;
6327 dwo_tu
->length
= length
;
6331 /* N.B.: type_offset is not usable if this type uses a DWO file.
6332 The real type_offset is in the DWO file. */
6334 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6335 sig_type
->signature
= header
.signature
;
6336 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6337 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6338 sig_type
->per_cu
.is_debug_types
= 1;
6339 sig_type
->per_cu
.section
= section
;
6340 sig_type
->per_cu
.sect_off
= sect_off
;
6341 sig_type
->per_cu
.length
= length
;
6344 slot
= htab_find_slot (types_htab
.get (),
6345 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6347 gdb_assert (slot
!= NULL
);
6350 sect_offset dup_sect_off
;
6354 const struct dwo_unit
*dup_tu
6355 = (const struct dwo_unit
*) *slot
;
6357 dup_sect_off
= dup_tu
->sect_off
;
6361 const struct signatured_type
*dup_tu
6362 = (const struct signatured_type
*) *slot
;
6364 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6367 complaint (_("debug type entry at offset %s is duplicate to"
6368 " the entry at offset %s, signature %s"),
6369 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6370 hex_string (header
.signature
));
6372 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6374 if (dwarf_read_debug
> 1)
6375 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6376 sect_offset_str (sect_off
),
6377 hex_string (header
.signature
));
6383 /* Create the hash table of all entries in the .debug_types
6384 (or .debug_types.dwo) section(s).
6385 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6386 otherwise it is NULL.
6388 The result is a pointer to the hash table or NULL if there are no types.
6390 Note: This function processes DWO files only, not DWP files. */
6393 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6394 struct dwo_file
*dwo_file
,
6395 gdb::array_view
<dwarf2_section_info
> type_sections
,
6396 htab_up
&types_htab
)
6398 for (dwarf2_section_info
§ion
: type_sections
)
6399 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6400 types_htab
, rcuh_kind::TYPE
);
6403 /* Create the hash table of all entries in the .debug_types section,
6404 and initialize all_type_units.
6405 The result is zero if there is an error (e.g. missing .debug_types section),
6406 otherwise non-zero. */
6409 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6413 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6414 &dwarf2_per_objfile
->per_bfd
->info
, types_htab
,
6415 rcuh_kind::COMPILE
);
6416 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6417 dwarf2_per_objfile
->per_bfd
->types
, types_htab
);
6418 if (types_htab
== NULL
)
6420 dwarf2_per_objfile
->per_bfd
->signatured_types
= NULL
;
6424 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6426 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
6427 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve
6428 (htab_elements (dwarf2_per_objfile
->per_bfd
->signatured_types
.get ()));
6430 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6431 add_signatured_type_cu_to_table
,
6432 &dwarf2_per_objfile
->per_bfd
->all_type_units
);
6437 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6438 If SLOT is non-NULL, it is the entry to use in the hash table.
6439 Otherwise we find one. */
6441 static struct signatured_type
*
6442 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6445 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()
6446 == dwarf2_per_objfile
->per_bfd
->all_type_units
.capacity ())
6447 ++dwarf2_per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6449 signatured_type
*sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6451 dwarf2_per_objfile
->resize_symtabs ();
6453 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6454 sig_type
->signature
= sig
;
6455 sig_type
->per_cu
.is_debug_types
= 1;
6456 if (dwarf2_per_objfile
->per_bfd
->using_index
)
6458 sig_type
->per_cu
.v
.quick
=
6459 OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6460 struct dwarf2_per_cu_quick_data
);
6465 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6468 gdb_assert (*slot
== NULL
);
6470 /* The rest of sig_type must be filled in by the caller. */
6474 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6475 Fill in SIG_ENTRY with DWO_ENTRY. */
6478 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6479 struct signatured_type
*sig_entry
,
6480 struct dwo_unit
*dwo_entry
)
6482 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
6484 /* Make sure we're not clobbering something we don't expect to. */
6485 gdb_assert (! sig_entry
->per_cu
.queued
);
6486 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6487 if (per_bfd
->using_index
)
6489 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6490 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6493 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6494 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6495 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6496 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6497 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6499 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6500 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6501 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6502 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6503 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6504 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6505 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6506 sig_entry
->dwo_unit
= dwo_entry
;
6509 /* Subroutine of lookup_signatured_type.
6510 If we haven't read the TU yet, create the signatured_type data structure
6511 for a TU to be read in directly from a DWO file, bypassing the stub.
6512 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6513 using .gdb_index, then when reading a CU we want to stay in the DWO file
6514 containing that CU. Otherwise we could end up reading several other DWO
6515 files (due to comdat folding) to process the transitive closure of all the
6516 mentioned TUs, and that can be slow. The current DWO file will have every
6517 type signature that it needs.
6518 We only do this for .gdb_index because in the psymtab case we already have
6519 to read all the DWOs to build the type unit groups. */
6521 static struct signatured_type
*
6522 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6524 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6525 struct dwo_file
*dwo_file
;
6526 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6527 struct signatured_type find_sig_entry
, *sig_entry
;
6530 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6532 /* If TU skeletons have been removed then we may not have read in any
6534 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6535 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6537 /* We only ever need to read in one copy of a signatured type.
6538 Use the global signatured_types array to do our own comdat-folding
6539 of types. If this is the first time we're reading this TU, and
6540 the TU has an entry in .gdb_index, replace the recorded data from
6541 .gdb_index with this TU. */
6543 find_sig_entry
.signature
= sig
;
6544 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6545 &find_sig_entry
, INSERT
);
6546 sig_entry
= (struct signatured_type
*) *slot
;
6548 /* We can get here with the TU already read, *or* in the process of being
6549 read. Don't reassign the global entry to point to this DWO if that's
6550 the case. Also note that if the TU is already being read, it may not
6551 have come from a DWO, the program may be a mix of Fission-compiled
6552 code and non-Fission-compiled code. */
6554 /* Have we already tried to read this TU?
6555 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6556 needn't exist in the global table yet). */
6557 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6560 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6561 dwo_unit of the TU itself. */
6562 dwo_file
= cu
->dwo_unit
->dwo_file
;
6564 /* Ok, this is the first time we're reading this TU. */
6565 if (dwo_file
->tus
== NULL
)
6567 find_dwo_entry
.signature
= sig
;
6568 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6570 if (dwo_entry
== NULL
)
6573 /* If the global table doesn't have an entry for this TU, add one. */
6574 if (sig_entry
== NULL
)
6575 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6577 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6578 sig_entry
->per_cu
.tu_read
= 1;
6582 /* Subroutine of lookup_signatured_type.
6583 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6584 then try the DWP file. If the TU stub (skeleton) has been removed then
6585 it won't be in .gdb_index. */
6587 static struct signatured_type
*
6588 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6590 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6591 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6592 struct dwo_unit
*dwo_entry
;
6593 struct signatured_type find_sig_entry
, *sig_entry
;
6596 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6597 gdb_assert (dwp_file
!= NULL
);
6599 /* If TU skeletons have been removed then we may not have read in any
6601 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6602 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6604 find_sig_entry
.signature
= sig
;
6605 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6606 &find_sig_entry
, INSERT
);
6607 sig_entry
= (struct signatured_type
*) *slot
;
6609 /* Have we already tried to read this TU?
6610 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6611 needn't exist in the global table yet). */
6612 if (sig_entry
!= NULL
)
6615 if (dwp_file
->tus
== NULL
)
6617 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6618 sig
, 1 /* is_debug_types */);
6619 if (dwo_entry
== NULL
)
6622 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6623 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6628 /* Lookup a signature based type for DW_FORM_ref_sig8.
6629 Returns NULL if signature SIG is not present in the table.
6630 It is up to the caller to complain about this. */
6632 static struct signatured_type
*
6633 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6635 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6638 && dwarf2_per_objfile
->per_bfd
->using_index
)
6640 /* We're in a DWO/DWP file, and we're using .gdb_index.
6641 These cases require special processing. */
6642 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6643 return lookup_dwo_signatured_type (cu
, sig
);
6645 return lookup_dwp_signatured_type (cu
, sig
);
6649 struct signatured_type find_entry
, *entry
;
6651 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6653 find_entry
.signature
= sig
;
6654 entry
= ((struct signatured_type
*)
6655 htab_find (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6661 /* Low level DIE reading support. */
6663 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6666 init_cu_die_reader (struct die_reader_specs
*reader
,
6667 struct dwarf2_cu
*cu
,
6668 struct dwarf2_section_info
*section
,
6669 struct dwo_file
*dwo_file
,
6670 struct abbrev_table
*abbrev_table
)
6672 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6673 reader
->abfd
= section
->get_bfd_owner ();
6675 reader
->dwo_file
= dwo_file
;
6676 reader
->die_section
= section
;
6677 reader
->buffer
= section
->buffer
;
6678 reader
->buffer_end
= section
->buffer
+ section
->size
;
6679 reader
->abbrev_table
= abbrev_table
;
6682 /* Subroutine of cutu_reader to simplify it.
6683 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6684 There's just a lot of work to do, and cutu_reader is big enough
6687 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6688 from it to the DIE in the DWO. If NULL we are skipping the stub.
6689 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6690 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6691 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6692 STUB_COMP_DIR may be non-NULL.
6693 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6694 are filled in with the info of the DIE from the DWO file.
6695 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6696 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6697 kept around for at least as long as *RESULT_READER.
6699 The result is non-zero if a valid (non-dummy) DIE was found. */
6702 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6703 struct dwo_unit
*dwo_unit
,
6704 struct die_info
*stub_comp_unit_die
,
6705 const char *stub_comp_dir
,
6706 struct die_reader_specs
*result_reader
,
6707 const gdb_byte
**result_info_ptr
,
6708 struct die_info
**result_comp_unit_die
,
6709 abbrev_table_up
*result_dwo_abbrev_table
)
6711 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6712 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6713 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6715 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6716 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6717 int i
,num_extra_attrs
;
6718 struct dwarf2_section_info
*dwo_abbrev_section
;
6719 struct die_info
*comp_unit_die
;
6721 /* At most one of these may be provided. */
6722 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6724 /* These attributes aren't processed until later:
6725 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6726 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6727 referenced later. However, these attributes are found in the stub
6728 which we won't have later. In order to not impose this complication
6729 on the rest of the code, we read them here and copy them to the
6738 if (stub_comp_unit_die
!= NULL
)
6740 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6742 if (!per_cu
->is_debug_types
)
6743 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6744 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6745 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6746 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6747 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6749 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6751 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6752 here (if needed). We need the value before we can process
6754 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6756 else if (stub_comp_dir
!= NULL
)
6758 /* Reconstruct the comp_dir attribute to simplify the code below. */
6759 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6760 comp_dir
->name
= DW_AT_comp_dir
;
6761 comp_dir
->form
= DW_FORM_string
;
6762 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6763 DW_STRING (comp_dir
) = stub_comp_dir
;
6766 /* Set up for reading the DWO CU/TU. */
6767 cu
->dwo_unit
= dwo_unit
;
6768 dwarf2_section_info
*section
= dwo_unit
->section
;
6769 section
->read (objfile
);
6770 abfd
= section
->get_bfd_owner ();
6771 begin_info_ptr
= info_ptr
= (section
->buffer
6772 + to_underlying (dwo_unit
->sect_off
));
6773 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6775 if (per_cu
->is_debug_types
)
6777 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6779 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6780 &cu
->header
, section
,
6782 info_ptr
, rcuh_kind::TYPE
);
6783 /* This is not an assert because it can be caused by bad debug info. */
6784 if (sig_type
->signature
!= cu
->header
.signature
)
6786 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6787 " TU at offset %s [in module %s]"),
6788 hex_string (sig_type
->signature
),
6789 hex_string (cu
->header
.signature
),
6790 sect_offset_str (dwo_unit
->sect_off
),
6791 bfd_get_filename (abfd
));
6793 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6794 /* For DWOs coming from DWP files, we don't know the CU length
6795 nor the type's offset in the TU until now. */
6796 dwo_unit
->length
= cu
->header
.get_length ();
6797 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6799 /* Establish the type offset that can be used to lookup the type.
6800 For DWO files, we don't know it until now. */
6801 sig_type
->type_offset_in_section
6802 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6806 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6807 &cu
->header
, section
,
6809 info_ptr
, rcuh_kind::COMPILE
);
6810 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6811 /* For DWOs coming from DWP files, we don't know the CU length
6813 dwo_unit
->length
= cu
->header
.get_length ();
6816 *result_dwo_abbrev_table
6817 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6818 cu
->header
.abbrev_sect_off
);
6819 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6820 result_dwo_abbrev_table
->get ());
6822 /* Read in the die, but leave space to copy over the attributes
6823 from the stub. This has the benefit of simplifying the rest of
6824 the code - all the work to maintain the illusion of a single
6825 DW_TAG_{compile,type}_unit DIE is done here. */
6826 num_extra_attrs
= ((stmt_list
!= NULL
)
6830 + (comp_dir
!= NULL
));
6831 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6834 /* Copy over the attributes from the stub to the DIE we just read in. */
6835 comp_unit_die
= *result_comp_unit_die
;
6836 i
= comp_unit_die
->num_attrs
;
6837 if (stmt_list
!= NULL
)
6838 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6840 comp_unit_die
->attrs
[i
++] = *low_pc
;
6841 if (high_pc
!= NULL
)
6842 comp_unit_die
->attrs
[i
++] = *high_pc
;
6844 comp_unit_die
->attrs
[i
++] = *ranges
;
6845 if (comp_dir
!= NULL
)
6846 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6847 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6849 if (dwarf_die_debug
)
6851 fprintf_unfiltered (gdb_stdlog
,
6852 "Read die from %s@0x%x of %s:\n",
6853 section
->get_name (),
6854 (unsigned) (begin_info_ptr
- section
->buffer
),
6855 bfd_get_filename (abfd
));
6856 dump_die (comp_unit_die
, dwarf_die_debug
);
6859 /* Skip dummy compilation units. */
6860 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6861 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6864 *result_info_ptr
= info_ptr
;
6868 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6869 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6870 signature is part of the header. */
6871 static gdb::optional
<ULONGEST
>
6872 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6874 if (cu
->header
.version
>= 5)
6875 return cu
->header
.signature
;
6876 struct attribute
*attr
;
6877 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6878 if (attr
== nullptr)
6879 return gdb::optional
<ULONGEST
> ();
6880 return DW_UNSND (attr
);
6883 /* Subroutine of cutu_reader to simplify it.
6884 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6885 Returns NULL if the specified DWO unit cannot be found. */
6887 static struct dwo_unit
*
6888 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6890 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6891 struct dwo_unit
*dwo_unit
;
6892 const char *comp_dir
;
6894 gdb_assert (cu
!= NULL
);
6896 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6897 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6898 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6900 if (per_cu
->is_debug_types
)
6901 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6904 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6906 if (!signature
.has_value ())
6907 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6909 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6911 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6917 /* Subroutine of cutu_reader to simplify it.
6918 See it for a description of the parameters.
6919 Read a TU directly from a DWO file, bypassing the stub. */
6922 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6923 dwarf2_per_objfile
*per_objfile
,
6924 int use_existing_cu
)
6926 struct signatured_type
*sig_type
;
6928 /* Verify we can do the following downcast, and that we have the
6930 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6931 sig_type
= (struct signatured_type
*) this_cu
;
6932 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6934 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6936 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6937 /* There's no need to do the rereading_dwo_cu handling that
6938 cutu_reader does since we don't read the stub. */
6942 /* If !use_existing_cu, this_cu->cu must be NULL. */
6943 gdb_assert (this_cu
->cu
== NULL
);
6944 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6947 /* A future optimization, if needed, would be to use an existing
6948 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6949 could share abbrev tables. */
6951 if (read_cutu_die_from_dwo (this_cu
->cu
, sig_type
->dwo_unit
,
6952 NULL
/* stub_comp_unit_die */,
6953 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6956 &m_dwo_abbrev_table
) == 0)
6963 /* Initialize a CU (or TU) and read its DIEs.
6964 If the CU defers to a DWO file, read the DWO file as well.
6966 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6967 Otherwise the table specified in the comp unit header is read in and used.
6968 This is an optimization for when we already have the abbrev table.
6970 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6971 Otherwise, a new CU is allocated with xmalloc. */
6973 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6974 dwarf2_per_objfile
*dwarf2_per_objfile
,
6975 struct abbrev_table
*abbrev_table
,
6976 int use_existing_cu
,
6978 : die_reader_specs
{},
6981 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6982 struct dwarf2_section_info
*section
= this_cu
->section
;
6983 bfd
*abfd
= section
->get_bfd_owner ();
6984 struct dwarf2_cu
*cu
;
6985 const gdb_byte
*begin_info_ptr
;
6986 struct signatured_type
*sig_type
= NULL
;
6987 struct dwarf2_section_info
*abbrev_section
;
6988 /* Non-zero if CU currently points to a DWO file and we need to
6989 reread it. When this happens we need to reread the skeleton die
6990 before we can reread the DWO file (this only applies to CUs, not TUs). */
6991 int rereading_dwo_cu
= 0;
6993 if (dwarf_die_debug
)
6994 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6995 this_cu
->is_debug_types
? "type" : "comp",
6996 sect_offset_str (this_cu
->sect_off
));
6998 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6999 file (instead of going through the stub), short-circuit all of this. */
7000 if (this_cu
->reading_dwo_directly
)
7002 /* Narrow down the scope of possibilities to have to understand. */
7003 gdb_assert (this_cu
->is_debug_types
);
7004 gdb_assert (abbrev_table
== NULL
);
7005 init_tu_and_read_dwo_dies (this_cu
, dwarf2_per_objfile
, use_existing_cu
);
7009 /* This is cheap if the section is already read in. */
7010 section
->read (objfile
);
7012 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7014 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7016 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7019 /* If this CU is from a DWO file we need to start over, we need to
7020 refetch the attributes from the skeleton CU.
7021 This could be optimized by retrieving those attributes from when we
7022 were here the first time: the previous comp_unit_die was stored in
7023 comp_unit_obstack. But there's no data yet that we need this
7025 if (cu
->dwo_unit
!= NULL
)
7026 rereading_dwo_cu
= 1;
7030 /* If !use_existing_cu, this_cu->cu must be NULL. */
7031 gdb_assert (this_cu
->cu
== NULL
);
7032 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7033 cu
= m_new_cu
.get ();
7036 /* Get the header. */
7037 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7039 /* We already have the header, there's no need to read it in again. */
7040 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7044 if (this_cu
->is_debug_types
)
7046 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7047 &cu
->header
, section
,
7048 abbrev_section
, info_ptr
,
7051 /* Since per_cu is the first member of struct signatured_type,
7052 we can go from a pointer to one to a pointer to the other. */
7053 sig_type
= (struct signatured_type
*) this_cu
;
7054 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7055 gdb_assert (sig_type
->type_offset_in_tu
7056 == cu
->header
.type_cu_offset_in_tu
);
7057 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7059 /* LENGTH has not been set yet for type units if we're
7060 using .gdb_index. */
7061 this_cu
->length
= cu
->header
.get_length ();
7063 /* Establish the type offset that can be used to lookup the type. */
7064 sig_type
->type_offset_in_section
=
7065 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7067 this_cu
->dwarf_version
= cu
->header
.version
;
7071 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7072 &cu
->header
, section
,
7075 rcuh_kind::COMPILE
);
7077 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7078 if (this_cu
->length
== 0)
7079 this_cu
->length
= cu
->header
.get_length ();
7081 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7082 this_cu
->dwarf_version
= cu
->header
.version
;
7086 /* Skip dummy compilation units. */
7087 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7088 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7094 /* If we don't have them yet, read the abbrevs for this compilation unit.
7095 And if we need to read them now, make sure they're freed when we're
7097 if (abbrev_table
!= NULL
)
7098 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7101 m_abbrev_table_holder
7102 = abbrev_table::read (objfile
, abbrev_section
,
7103 cu
->header
.abbrev_sect_off
);
7104 abbrev_table
= m_abbrev_table_holder
.get ();
7107 /* Read the top level CU/TU die. */
7108 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7109 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7111 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7117 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7118 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7119 table from the DWO file and pass the ownership over to us. It will be
7120 referenced from READER, so we must make sure to free it after we're done
7123 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7124 DWO CU, that this test will fail (the attribute will not be present). */
7125 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7126 if (dwo_name
!= nullptr)
7128 struct dwo_unit
*dwo_unit
;
7129 struct die_info
*dwo_comp_unit_die
;
7131 if (comp_unit_die
->has_children
)
7133 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7134 " has children (offset %s) [in module %s]"),
7135 sect_offset_str (this_cu
->sect_off
),
7136 bfd_get_filename (abfd
));
7138 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7139 if (dwo_unit
!= NULL
)
7141 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7142 comp_unit_die
, NULL
,
7145 &m_dwo_abbrev_table
) == 0)
7151 comp_unit_die
= dwo_comp_unit_die
;
7155 /* Yikes, we couldn't find the rest of the DIE, we only have
7156 the stub. A complaint has already been logged. There's
7157 not much more we can do except pass on the stub DIE to
7158 die_reader_func. We don't want to throw an error on bad
7165 cutu_reader::keep ()
7167 /* Done, clean up. */
7168 gdb_assert (!dummy_p
);
7169 if (m_new_cu
!= NULL
)
7171 /* We know that m_this_cu->cu is set, since we are in the process of
7173 gdb_assert (m_this_cu
->cu
!= nullptr);
7174 dwarf2_per_objfile
*dwarf2_per_objfile
= m_this_cu
->cu
->per_objfile
;
7176 /* Link this CU into read_in_chain. */
7177 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
7178 dwarf2_per_objfile
->per_bfd
->read_in_chain
= m_this_cu
;
7179 /* The chain owns it now. */
7180 m_new_cu
.release ();
7184 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7185 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7186 assumed to have already done the lookup to find the DWO file).
7188 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7189 THIS_CU->is_debug_types, but nothing else.
7191 We fill in THIS_CU->length.
7193 THIS_CU->cu is always freed when done.
7194 This is done in order to not leave THIS_CU->cu in a state where we have
7195 to care whether it refers to the "main" CU or the DWO CU.
7197 When parent_cu is passed, it is used to provide a default value for
7198 str_offsets_base and addr_base from the parent. */
7200 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7201 dwarf2_per_objfile
*dwarf2_per_objfile
,
7202 struct dwarf2_cu
*parent_cu
,
7203 struct dwo_file
*dwo_file
)
7204 : die_reader_specs
{},
7207 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7208 struct dwarf2_section_info
*section
= this_cu
->section
;
7209 bfd
*abfd
= section
->get_bfd_owner ();
7210 struct dwarf2_section_info
*abbrev_section
;
7211 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7213 if (dwarf_die_debug
)
7214 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7215 this_cu
->is_debug_types
? "type" : "comp",
7216 sect_offset_str (this_cu
->sect_off
));
7218 gdb_assert (this_cu
->cu
== NULL
);
7220 abbrev_section
= (dwo_file
!= NULL
7221 ? &dwo_file
->sections
.abbrev
7222 : get_abbrev_section_for_cu (this_cu
));
7224 /* This is cheap if the section is already read in. */
7225 section
->read (objfile
);
7227 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7229 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7230 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7231 &m_new_cu
->header
, section
,
7232 abbrev_section
, info_ptr
,
7233 (this_cu
->is_debug_types
7235 : rcuh_kind::COMPILE
));
7237 if (parent_cu
!= nullptr)
7239 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7240 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7242 this_cu
->length
= m_new_cu
->header
.get_length ();
7244 /* Skip dummy compilation units. */
7245 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7246 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7252 m_abbrev_table_holder
7253 = abbrev_table::read (objfile
, abbrev_section
,
7254 m_new_cu
->header
.abbrev_sect_off
);
7256 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7257 m_abbrev_table_holder
.get ());
7258 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7262 /* Type Unit Groups.
7264 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7265 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7266 so that all types coming from the same compilation (.o file) are grouped
7267 together. A future step could be to put the types in the same symtab as
7268 the CU the types ultimately came from. */
7271 hash_type_unit_group (const void *item
)
7273 const struct type_unit_group
*tu_group
7274 = (const struct type_unit_group
*) item
;
7276 return hash_stmt_list_entry (&tu_group
->hash
);
7280 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7282 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7283 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7285 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7288 /* Allocate a hash table for type unit groups. */
7291 allocate_type_unit_groups_table ()
7293 return htab_up (htab_create_alloc (3,
7294 hash_type_unit_group
,
7296 NULL
, xcalloc
, xfree
));
7299 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7300 partial symtabs. We combine several TUs per psymtab to not let the size
7301 of any one psymtab grow too big. */
7302 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7303 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7305 /* Helper routine for get_type_unit_group.
7306 Create the type_unit_group object used to hold one or more TUs. */
7308 static struct type_unit_group
*
7309 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7311 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7312 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
7313 struct dwarf2_per_cu_data
*per_cu
;
7314 struct type_unit_group
*tu_group
;
7316 tu_group
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
7317 struct type_unit_group
);
7318 per_cu
= &tu_group
->per_cu
;
7319 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7320 per_cu
->per_bfd
= per_bfd
;
7322 if (per_bfd
->using_index
)
7324 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7325 struct dwarf2_per_cu_quick_data
);
7329 unsigned int line_offset
= to_underlying (line_offset_struct
);
7330 dwarf2_psymtab
*pst
;
7333 /* Give the symtab a useful name for debug purposes. */
7334 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7335 name
= string_printf ("<type_units_%d>",
7336 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7338 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7340 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, name
.c_str ());
7341 pst
->anonymous
= true;
7344 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7345 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7350 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7351 STMT_LIST is a DW_AT_stmt_list attribute. */
7353 static struct type_unit_group
*
7354 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7356 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7357 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7358 struct type_unit_group
*tu_group
;
7360 unsigned int line_offset
;
7361 struct type_unit_group type_unit_group_for_lookup
;
7363 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7364 dwarf2_per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7366 /* Do we need to create a new group, or can we use an existing one? */
7370 line_offset
= DW_UNSND (stmt_list
);
7371 ++tu_stats
->nr_symtab_sharers
;
7375 /* Ugh, no stmt_list. Rare, but we have to handle it.
7376 We can do various things here like create one group per TU or
7377 spread them over multiple groups to split up the expansion work.
7378 To avoid worst case scenarios (too many groups or too large groups)
7379 we, umm, group them in bunches. */
7380 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7381 | (tu_stats
->nr_stmt_less_type_units
7382 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7383 ++tu_stats
->nr_stmt_less_type_units
;
7386 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7387 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7388 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7389 &type_unit_group_for_lookup
, INSERT
);
7392 tu_group
= (struct type_unit_group
*) *slot
;
7393 gdb_assert (tu_group
!= NULL
);
7397 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7398 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7400 ++tu_stats
->nr_symtabs
;
7406 /* Partial symbol tables. */
7408 /* Create a psymtab named NAME and assign it to PER_CU.
7410 The caller must fill in the following details:
7411 dirname, textlow, texthigh. */
7413 static dwarf2_psymtab
*
7414 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7415 dwarf2_per_objfile
*per_objfile
,
7418 struct objfile
*objfile
= per_objfile
->objfile
;
7419 dwarf2_psymtab
*pst
;
7421 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7423 pst
->psymtabs_addrmap_supported
= true;
7425 /* This is the glue that links PST into GDB's symbol API. */
7426 per_cu
->v
.psymtab
= pst
;
7431 /* DIE reader function for process_psymtab_comp_unit. */
7434 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7435 const gdb_byte
*info_ptr
,
7436 struct die_info
*comp_unit_die
,
7437 enum language pretend_language
)
7439 struct dwarf2_cu
*cu
= reader
->cu
;
7440 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7441 struct objfile
*objfile
= per_objfile
->objfile
;
7442 struct gdbarch
*gdbarch
= objfile
->arch ();
7443 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7445 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7446 dwarf2_psymtab
*pst
;
7447 enum pc_bounds_kind cu_bounds_kind
;
7448 const char *filename
;
7450 gdb_assert (! per_cu
->is_debug_types
);
7452 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7454 /* Allocate a new partial symbol table structure. */
7455 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7456 static const char artificial
[] = "<artificial>";
7457 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7458 if (filename
== NULL
)
7460 else if (strcmp (filename
, artificial
) == 0)
7462 debug_filename
.reset (concat (artificial
, "@",
7463 sect_offset_str (per_cu
->sect_off
),
7465 filename
= debug_filename
.get ();
7468 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7470 /* This must be done before calling dwarf2_build_include_psymtabs. */
7471 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7473 baseaddr
= objfile
->text_section_offset ();
7475 dwarf2_find_base_address (comp_unit_die
, cu
);
7477 /* Possibly set the default values of LOWPC and HIGHPC from
7479 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7480 &best_highpc
, cu
, pst
);
7481 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7484 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7487 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7489 /* Store the contiguous range if it is not empty; it can be
7490 empty for CUs with no code. */
7491 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7495 /* Check if comp unit has_children.
7496 If so, read the rest of the partial symbols from this comp unit.
7497 If not, there's no more debug_info for this comp unit. */
7498 if (comp_unit_die
->has_children
)
7500 struct partial_die_info
*first_die
;
7501 CORE_ADDR lowpc
, highpc
;
7503 lowpc
= ((CORE_ADDR
) -1);
7504 highpc
= ((CORE_ADDR
) 0);
7506 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7508 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7509 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7511 /* If we didn't find a lowpc, set it to highpc to avoid
7512 complaints from `maint check'. */
7513 if (lowpc
== ((CORE_ADDR
) -1))
7516 /* If the compilation unit didn't have an explicit address range,
7517 then use the information extracted from its child dies. */
7518 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7521 best_highpc
= highpc
;
7524 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7525 best_lowpc
+ baseaddr
)
7527 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7528 best_highpc
+ baseaddr
)
7531 end_psymtab_common (objfile
, pst
);
7533 if (!cu
->per_cu
->imported_symtabs_empty ())
7536 int len
= cu
->per_cu
->imported_symtabs_size ();
7538 /* Fill in 'dependencies' here; we fill in 'users' in a
7540 pst
->number_of_dependencies
= len
;
7542 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7543 for (i
= 0; i
< len
; ++i
)
7545 pst
->dependencies
[i
]
7546 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7549 cu
->per_cu
->imported_symtabs_free ();
7552 /* Get the list of files included in the current compilation unit,
7553 and build a psymtab for each of them. */
7554 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7556 if (dwarf_read_debug
)
7557 fprintf_unfiltered (gdb_stdlog
,
7558 "Psymtab for %s unit @%s: %s - %s"
7559 ", %d global, %d static syms\n",
7560 per_cu
->is_debug_types
? "type" : "comp",
7561 sect_offset_str (per_cu
->sect_off
),
7562 paddress (gdbarch
, pst
->text_low (objfile
)),
7563 paddress (gdbarch
, pst
->text_high (objfile
)),
7564 pst
->n_global_syms
, pst
->n_static_syms
);
7567 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7568 Process compilation unit THIS_CU for a psymtab. */
7571 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7572 dwarf2_per_objfile
*per_objfile
,
7573 bool want_partial_unit
,
7574 enum language pretend_language
)
7576 /* If this compilation unit was already read in, free the
7577 cached copy in order to read it in again. This is
7578 necessary because we skipped some symbols when we first
7579 read in the compilation unit (see load_partial_dies).
7580 This problem could be avoided, but the benefit is unclear. */
7581 if (this_cu
->cu
!= NULL
)
7582 free_one_cached_comp_unit (this_cu
);
7584 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 0, false);
7586 switch (reader
.comp_unit_die
->tag
)
7588 case DW_TAG_compile_unit
:
7589 this_cu
->unit_type
= DW_UT_compile
;
7591 case DW_TAG_partial_unit
:
7592 this_cu
->unit_type
= DW_UT_partial
;
7602 else if (this_cu
->is_debug_types
)
7603 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7604 reader
.comp_unit_die
);
7605 else if (want_partial_unit
7606 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7607 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7608 reader
.comp_unit_die
,
7611 this_cu
->lang
= this_cu
->cu
->language
;
7613 /* Age out any secondary CUs. */
7614 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7617 /* Reader function for build_type_psymtabs. */
7620 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7621 const gdb_byte
*info_ptr
,
7622 struct die_info
*type_unit_die
)
7624 struct dwarf2_per_objfile
*dwarf2_per_objfile
= reader
->cu
->per_objfile
;
7625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7626 struct dwarf2_cu
*cu
= reader
->cu
;
7627 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7628 struct signatured_type
*sig_type
;
7629 struct type_unit_group
*tu_group
;
7630 struct attribute
*attr
;
7631 struct partial_die_info
*first_die
;
7632 CORE_ADDR lowpc
, highpc
;
7633 dwarf2_psymtab
*pst
;
7635 gdb_assert (per_cu
->is_debug_types
);
7636 sig_type
= (struct signatured_type
*) per_cu
;
7638 if (! type_unit_die
->has_children
)
7641 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7642 tu_group
= get_type_unit_group (cu
, attr
);
7644 if (tu_group
->tus
== nullptr)
7645 tu_group
->tus
= new std::vector
<signatured_type
*>;
7646 tu_group
->tus
->push_back (sig_type
);
7648 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7649 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, "");
7650 pst
->anonymous
= true;
7652 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7654 lowpc
= (CORE_ADDR
) -1;
7655 highpc
= (CORE_ADDR
) 0;
7656 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7658 end_psymtab_common (objfile
, pst
);
7661 /* Struct used to sort TUs by their abbreviation table offset. */
7663 struct tu_abbrev_offset
7665 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7666 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7669 signatured_type
*sig_type
;
7670 sect_offset abbrev_offset
;
7673 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7676 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7677 const struct tu_abbrev_offset
&b
)
7679 return a
.abbrev_offset
< b
.abbrev_offset
;
7682 /* Efficiently read all the type units.
7683 This does the bulk of the work for build_type_psymtabs.
7685 The efficiency is because we sort TUs by the abbrev table they use and
7686 only read each abbrev table once. In one program there are 200K TUs
7687 sharing 8K abbrev tables.
7689 The main purpose of this function is to support building the
7690 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7691 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7692 can collapse the search space by grouping them by stmt_list.
7693 The savings can be significant, in the same program from above the 200K TUs
7694 share 8K stmt_list tables.
7696 FUNC is expected to call get_type_unit_group, which will create the
7697 struct type_unit_group if necessary and add it to
7698 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7701 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7703 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7704 abbrev_table_up abbrev_table
;
7705 sect_offset abbrev_offset
;
7707 /* It's up to the caller to not call us multiple times. */
7708 gdb_assert (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7710 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ())
7713 /* TUs typically share abbrev tables, and there can be way more TUs than
7714 abbrev tables. Sort by abbrev table to reduce the number of times we
7715 read each abbrev table in.
7716 Alternatives are to punt or to maintain a cache of abbrev tables.
7717 This is simpler and efficient enough for now.
7719 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7720 symtab to use). Typically TUs with the same abbrev offset have the same
7721 stmt_list value too so in practice this should work well.
7723 The basic algorithm here is:
7725 sort TUs by abbrev table
7726 for each TU with same abbrev table:
7727 read abbrev table if first user
7728 read TU top level DIE
7729 [IWBN if DWO skeletons had DW_AT_stmt_list]
7732 if (dwarf_read_debug
)
7733 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7735 /* Sort in a separate table to maintain the order of all_type_units
7736 for .gdb_index: TU indices directly index all_type_units. */
7737 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7738 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7740 for (signatured_type
*sig_type
: dwarf2_per_objfile
->per_bfd
->all_type_units
)
7741 sorted_by_abbrev
.emplace_back
7742 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7743 sig_type
->per_cu
.section
,
7744 sig_type
->per_cu
.sect_off
));
7746 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7747 sort_tu_by_abbrev_offset
);
7749 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7751 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7753 /* Switch to the next abbrev table if necessary. */
7754 if (abbrev_table
== NULL
7755 || tu
.abbrev_offset
!= abbrev_offset
)
7757 abbrev_offset
= tu
.abbrev_offset
;
7759 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7760 &dwarf2_per_objfile
->per_bfd
->abbrev
,
7762 ++tu_stats
->nr_uniq_abbrev_tables
;
7765 cutu_reader
reader (&tu
.sig_type
->per_cu
, dwarf2_per_objfile
,
7766 abbrev_table
.get (), 0, false);
7767 if (!reader
.dummy_p
)
7768 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7769 reader
.comp_unit_die
);
7773 /* Print collected type unit statistics. */
7776 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7778 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7780 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7781 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7782 dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7783 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7784 tu_stats
->nr_uniq_abbrev_tables
);
7785 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7786 tu_stats
->nr_symtabs
);
7787 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7788 tu_stats
->nr_symtab_sharers
);
7789 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7790 tu_stats
->nr_stmt_less_type_units
);
7791 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7792 tu_stats
->nr_all_type_units_reallocs
);
7795 /* Traversal function for build_type_psymtabs. */
7798 build_type_psymtab_dependencies (void **slot
, void *info
)
7800 struct dwarf2_per_objfile
*dwarf2_per_objfile
7801 = (struct dwarf2_per_objfile
*) info
;
7802 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7803 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7804 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7805 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7806 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7809 gdb_assert (len
> 0);
7810 gdb_assert (per_cu
->type_unit_group_p ());
7812 pst
->number_of_dependencies
= len
;
7813 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7814 for (i
= 0; i
< len
; ++i
)
7816 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7817 gdb_assert (iter
->per_cu
.is_debug_types
);
7818 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7819 iter
->type_unit_group
= tu_group
;
7822 delete tu_group
->tus
;
7823 tu_group
->tus
= nullptr;
7828 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7829 Build partial symbol tables for the .debug_types comp-units. */
7832 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7834 if (! create_all_type_units (dwarf2_per_objfile
))
7837 build_type_psymtabs_1 (dwarf2_per_objfile
);
7840 /* Traversal function for process_skeletonless_type_unit.
7841 Read a TU in a DWO file and build partial symbols for it. */
7844 process_skeletonless_type_unit (void **slot
, void *info
)
7846 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7847 struct dwarf2_per_objfile
*dwarf2_per_objfile
7848 = (struct dwarf2_per_objfile
*) info
;
7849 struct signatured_type find_entry
, *entry
;
7851 /* If this TU doesn't exist in the global table, add it and read it in. */
7853 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
7854 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7856 find_entry
.signature
= dwo_unit
->signature
;
7857 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
7858 &find_entry
, INSERT
);
7859 /* If we've already seen this type there's nothing to do. What's happening
7860 is we're doing our own version of comdat-folding here. */
7864 /* This does the job that create_all_type_units would have done for
7866 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7867 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7870 /* This does the job that build_type_psymtabs_1 would have done. */
7871 cutu_reader
reader (&entry
->per_cu
, dwarf2_per_objfile
, NULL
, 0, false);
7872 if (!reader
.dummy_p
)
7873 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7874 reader
.comp_unit_die
);
7879 /* Traversal function for process_skeletonless_type_units. */
7882 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7884 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7886 if (dwo_file
->tus
!= NULL
)
7887 htab_traverse_noresize (dwo_file
->tus
.get (),
7888 process_skeletonless_type_unit
, info
);
7893 /* Scan all TUs of DWO files, verifying we've processed them.
7894 This is needed in case a TU was emitted without its skeleton.
7895 Note: This can't be done until we know what all the DWO files are. */
7898 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7900 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7901 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7902 && dwarf2_per_objfile
->per_bfd
->dwo_files
!= NULL
)
7904 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (),
7905 process_dwo_file_for_skeletonless_type_units
,
7906 dwarf2_per_objfile
);
7910 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7913 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7915 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7917 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7922 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7924 /* Set the 'user' field only if it is not already set. */
7925 if (pst
->dependencies
[j
]->user
== NULL
)
7926 pst
->dependencies
[j
]->user
= pst
;
7931 /* Build the partial symbol table by doing a quick pass through the
7932 .debug_info and .debug_abbrev sections. */
7935 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7937 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7939 if (dwarf_read_debug
)
7941 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7942 objfile_name (objfile
));
7945 scoped_restore restore_reading_psyms
7946 = make_scoped_restore (&dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
,
7949 dwarf2_per_objfile
->per_bfd
->info
.read (objfile
);
7951 /* Any cached compilation units will be linked by the per-objfile
7952 read_in_chain. Make sure to free them when we're done. */
7953 free_cached_comp_units
freer (dwarf2_per_objfile
);
7955 build_type_psymtabs (dwarf2_per_objfile
);
7957 create_all_comp_units (dwarf2_per_objfile
);
7959 /* Create a temporary address map on a temporary obstack. We later
7960 copy this to the final obstack. */
7961 auto_obstack temp_obstack
;
7963 scoped_restore save_psymtabs_addrmap
7964 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7965 addrmap_create_mutable (&temp_obstack
));
7967 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7969 if (per_cu
->v
.psymtab
!= NULL
)
7970 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7972 process_psymtab_comp_unit (per_cu
, dwarf2_per_objfile
, false,
7976 /* This has to wait until we read the CUs, we need the list of DWOs. */
7977 process_skeletonless_type_units (dwarf2_per_objfile
);
7979 /* Now that all TUs have been processed we can fill in the dependencies. */
7980 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
7982 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7983 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7986 if (dwarf_read_debug
)
7987 print_tu_stats (dwarf2_per_objfile
);
7989 set_partial_user (dwarf2_per_objfile
);
7991 objfile
->partial_symtabs
->psymtabs_addrmap
7992 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7993 objfile
->partial_symtabs
->obstack ());
7994 /* At this point we want to keep the address map. */
7995 save_psymtabs_addrmap
.release ();
7997 if (dwarf_read_debug
)
7998 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7999 objfile_name (objfile
));
8002 /* Load the partial DIEs for a secondary CU into memory.
8003 This is also used when rereading a primary CU with load_all_dies. */
8006 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8007 dwarf2_per_objfile
*per_objfile
)
8009 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 1, false);
8011 if (!reader
.dummy_p
)
8013 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8016 /* Check if comp unit has_children.
8017 If so, read the rest of the partial symbols from this comp unit.
8018 If not, there's no more debug_info for this comp unit. */
8019 if (reader
.comp_unit_die
->has_children
)
8020 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8027 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8028 struct dwarf2_section_info
*section
,
8029 struct dwarf2_section_info
*abbrev_section
,
8030 unsigned int is_dwz
)
8032 const gdb_byte
*info_ptr
;
8033 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8035 if (dwarf_read_debug
)
8036 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8037 section
->get_name (),
8038 section
->get_file_name ());
8040 section
->read (objfile
);
8042 info_ptr
= section
->buffer
;
8044 while (info_ptr
< section
->buffer
+ section
->size
)
8046 struct dwarf2_per_cu_data
*this_cu
;
8048 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8050 comp_unit_head cu_header
;
8051 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8052 abbrev_section
, info_ptr
,
8053 rcuh_kind::COMPILE
);
8055 /* Save the compilation unit for later lookup. */
8056 if (cu_header
.unit_type
!= DW_UT_type
)
8057 this_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
8060 auto sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
8061 sig_type
->signature
= cu_header
.signature
;
8062 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8063 this_cu
= &sig_type
->per_cu
;
8065 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8066 this_cu
->sect_off
= sect_off
;
8067 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8068 this_cu
->is_dwz
= is_dwz
;
8069 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8070 this_cu
->section
= section
;
8072 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8074 info_ptr
= info_ptr
+ this_cu
->length
;
8078 /* Create a list of all compilation units in OBJFILE.
8079 This is only done for -readnow and building partial symtabs. */
8082 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8084 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
8085 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->per_bfd
->info
,
8086 &dwarf2_per_objfile
->per_bfd
->abbrev
, 0);
8088 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
8090 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8094 /* Process all loaded DIEs for compilation unit CU, starting at
8095 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8096 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8097 DW_AT_ranges). See the comments of add_partial_subprogram on how
8098 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8101 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8102 CORE_ADDR
*highpc
, int set_addrmap
,
8103 struct dwarf2_cu
*cu
)
8105 struct partial_die_info
*pdi
;
8107 /* Now, march along the PDI's, descending into ones which have
8108 interesting children but skipping the children of the other ones,
8109 until we reach the end of the compilation unit. */
8117 /* Anonymous namespaces or modules have no name but have interesting
8118 children, so we need to look at them. Ditto for anonymous
8121 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8122 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8123 || pdi
->tag
== DW_TAG_imported_unit
8124 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8128 case DW_TAG_subprogram
:
8129 case DW_TAG_inlined_subroutine
:
8130 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8132 case DW_TAG_constant
:
8133 case DW_TAG_variable
:
8134 case DW_TAG_typedef
:
8135 case DW_TAG_union_type
:
8136 if (!pdi
->is_declaration
8137 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8139 add_partial_symbol (pdi
, cu
);
8142 case DW_TAG_class_type
:
8143 case DW_TAG_interface_type
:
8144 case DW_TAG_structure_type
:
8145 if (!pdi
->is_declaration
)
8147 add_partial_symbol (pdi
, cu
);
8149 if ((cu
->language
== language_rust
8150 || cu
->language
== language_cplus
) && pdi
->has_children
)
8151 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8154 case DW_TAG_enumeration_type
:
8155 if (!pdi
->is_declaration
)
8156 add_partial_enumeration (pdi
, cu
);
8158 case DW_TAG_base_type
:
8159 case DW_TAG_subrange_type
:
8160 /* File scope base type definitions are added to the partial
8162 add_partial_symbol (pdi
, cu
);
8164 case DW_TAG_namespace
:
8165 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8168 if (!pdi
->is_declaration
)
8169 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8171 case DW_TAG_imported_unit
:
8173 struct dwarf2_per_cu_data
*per_cu
;
8175 /* For now we don't handle imported units in type units. */
8176 if (cu
->per_cu
->is_debug_types
)
8178 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8179 " supported in type units [in module %s]"),
8180 objfile_name (cu
->per_objfile
->objfile
));
8183 per_cu
= dwarf2_find_containing_comp_unit
8184 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8186 /* Go read the partial unit, if needed. */
8187 if (per_cu
->v
.psymtab
== NULL
)
8188 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8191 cu
->per_cu
->imported_symtabs_push (per_cu
);
8194 case DW_TAG_imported_declaration
:
8195 add_partial_symbol (pdi
, cu
);
8202 /* If the die has a sibling, skip to the sibling. */
8204 pdi
= pdi
->die_sibling
;
8208 /* Functions used to compute the fully scoped name of a partial DIE.
8210 Normally, this is simple. For C++, the parent DIE's fully scoped
8211 name is concatenated with "::" and the partial DIE's name.
8212 Enumerators are an exception; they use the scope of their parent
8213 enumeration type, i.e. the name of the enumeration type is not
8214 prepended to the enumerator.
8216 There are two complexities. One is DW_AT_specification; in this
8217 case "parent" means the parent of the target of the specification,
8218 instead of the direct parent of the DIE. The other is compilers
8219 which do not emit DW_TAG_namespace; in this case we try to guess
8220 the fully qualified name of structure types from their members'
8221 linkage names. This must be done using the DIE's children rather
8222 than the children of any DW_AT_specification target. We only need
8223 to do this for structures at the top level, i.e. if the target of
8224 any DW_AT_specification (if any; otherwise the DIE itself) does not
8227 /* Compute the scope prefix associated with PDI's parent, in
8228 compilation unit CU. The result will be allocated on CU's
8229 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8230 field. NULL is returned if no prefix is necessary. */
8232 partial_die_parent_scope (struct partial_die_info
*pdi
,
8233 struct dwarf2_cu
*cu
)
8235 const char *grandparent_scope
;
8236 struct partial_die_info
*parent
, *real_pdi
;
8238 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8239 then this means the parent of the specification DIE. */
8242 while (real_pdi
->has_specification
)
8244 auto res
= find_partial_die (real_pdi
->spec_offset
,
8245 real_pdi
->spec_is_dwz
, cu
);
8250 parent
= real_pdi
->die_parent
;
8254 if (parent
->scope_set
)
8255 return parent
->scope
;
8259 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8261 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8262 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8263 Work around this problem here. */
8264 if (cu
->language
== language_cplus
8265 && parent
->tag
== DW_TAG_namespace
8266 && strcmp (parent
->name
, "::") == 0
8267 && grandparent_scope
== NULL
)
8269 parent
->scope
= NULL
;
8270 parent
->scope_set
= 1;
8274 /* Nested subroutines in Fortran get a prefix. */
8275 if (pdi
->tag
== DW_TAG_enumerator
)
8276 /* Enumerators should not get the name of the enumeration as a prefix. */
8277 parent
->scope
= grandparent_scope
;
8278 else if (parent
->tag
== DW_TAG_namespace
8279 || parent
->tag
== DW_TAG_module
8280 || parent
->tag
== DW_TAG_structure_type
8281 || parent
->tag
== DW_TAG_class_type
8282 || parent
->tag
== DW_TAG_interface_type
8283 || parent
->tag
== DW_TAG_union_type
8284 || parent
->tag
== DW_TAG_enumeration_type
8285 || (cu
->language
== language_fortran
8286 && parent
->tag
== DW_TAG_subprogram
8287 && pdi
->tag
== DW_TAG_subprogram
))
8289 if (grandparent_scope
== NULL
)
8290 parent
->scope
= parent
->name
;
8292 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8294 parent
->name
, 0, cu
);
8298 /* FIXME drow/2004-04-01: What should we be doing with
8299 function-local names? For partial symbols, we should probably be
8301 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8302 dwarf_tag_name (parent
->tag
),
8303 sect_offset_str (pdi
->sect_off
));
8304 parent
->scope
= grandparent_scope
;
8307 parent
->scope_set
= 1;
8308 return parent
->scope
;
8311 /* Return the fully scoped name associated with PDI, from compilation unit
8312 CU. The result will be allocated with malloc. */
8314 static gdb::unique_xmalloc_ptr
<char>
8315 partial_die_full_name (struct partial_die_info
*pdi
,
8316 struct dwarf2_cu
*cu
)
8318 const char *parent_scope
;
8320 /* If this is a template instantiation, we can not work out the
8321 template arguments from partial DIEs. So, unfortunately, we have
8322 to go through the full DIEs. At least any work we do building
8323 types here will be reused if full symbols are loaded later. */
8324 if (pdi
->has_template_arguments
)
8328 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8330 struct die_info
*die
;
8331 struct attribute attr
;
8332 struct dwarf2_cu
*ref_cu
= cu
;
8334 /* DW_FORM_ref_addr is using section offset. */
8335 attr
.name
= (enum dwarf_attribute
) 0;
8336 attr
.form
= DW_FORM_ref_addr
;
8337 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8338 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8340 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8344 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8345 if (parent_scope
== NULL
)
8348 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8353 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8355 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
8356 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8357 struct gdbarch
*gdbarch
= objfile
->arch ();
8359 const char *actual_name
= NULL
;
8362 baseaddr
= objfile
->text_section_offset ();
8364 gdb::unique_xmalloc_ptr
<char> built_actual_name
8365 = partial_die_full_name (pdi
, cu
);
8366 if (built_actual_name
!= NULL
)
8367 actual_name
= built_actual_name
.get ();
8369 if (actual_name
== NULL
)
8370 actual_name
= pdi
->name
;
8372 partial_symbol psymbol
;
8373 memset (&psymbol
, 0, sizeof (psymbol
));
8374 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8375 psymbol
.ginfo
.section
= -1;
8377 /* The code below indicates that the psymbol should be installed by
8379 gdb::optional
<psymbol_placement
> where
;
8383 case DW_TAG_inlined_subroutine
:
8384 case DW_TAG_subprogram
:
8385 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8387 if (pdi
->is_external
8388 || cu
->language
== language_ada
8389 || (cu
->language
== language_fortran
8390 && pdi
->die_parent
!= NULL
8391 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8393 /* Normally, only "external" DIEs are part of the global scope.
8394 But in Ada and Fortran, we want to be able to access nested
8395 procedures globally. So all Ada and Fortran subprograms are
8396 stored in the global scope. */
8397 where
= psymbol_placement::GLOBAL
;
8400 where
= psymbol_placement::STATIC
;
8402 psymbol
.domain
= VAR_DOMAIN
;
8403 psymbol
.aclass
= LOC_BLOCK
;
8404 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8405 psymbol
.ginfo
.value
.address
= addr
;
8407 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8408 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8410 case DW_TAG_constant
:
8411 psymbol
.domain
= VAR_DOMAIN
;
8412 psymbol
.aclass
= LOC_STATIC
;
8413 where
= (pdi
->is_external
8414 ? psymbol_placement::GLOBAL
8415 : psymbol_placement::STATIC
);
8417 case DW_TAG_variable
:
8419 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8423 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
8425 /* A global or static variable may also have been stripped
8426 out by the linker if unused, in which case its address
8427 will be nullified; do not add such variables into partial
8428 symbol table then. */
8430 else if (pdi
->is_external
)
8433 Don't enter into the minimal symbol tables as there is
8434 a minimal symbol table entry from the ELF symbols already.
8435 Enter into partial symbol table if it has a location
8436 descriptor or a type.
8437 If the location descriptor is missing, new_symbol will create
8438 a LOC_UNRESOLVED symbol, the address of the variable will then
8439 be determined from the minimal symbol table whenever the variable
8441 The address for the partial symbol table entry is not
8442 used by GDB, but it comes in handy for debugging partial symbol
8445 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8447 psymbol
.domain
= VAR_DOMAIN
;
8448 psymbol
.aclass
= LOC_STATIC
;
8449 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8450 psymbol
.ginfo
.value
.address
= addr
;
8451 where
= psymbol_placement::GLOBAL
;
8456 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8458 /* Static Variable. Skip symbols whose value we cannot know (those
8459 without location descriptors or constant values). */
8460 if (!has_loc
&& !pdi
->has_const_value
)
8463 psymbol
.domain
= VAR_DOMAIN
;
8464 psymbol
.aclass
= LOC_STATIC
;
8465 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8467 psymbol
.ginfo
.value
.address
= addr
;
8468 where
= psymbol_placement::STATIC
;
8471 case DW_TAG_typedef
:
8472 case DW_TAG_base_type
:
8473 case DW_TAG_subrange_type
:
8474 psymbol
.domain
= VAR_DOMAIN
;
8475 psymbol
.aclass
= LOC_TYPEDEF
;
8476 where
= psymbol_placement::STATIC
;
8478 case DW_TAG_imported_declaration
:
8479 case DW_TAG_namespace
:
8480 psymbol
.domain
= VAR_DOMAIN
;
8481 psymbol
.aclass
= LOC_TYPEDEF
;
8482 where
= psymbol_placement::GLOBAL
;
8485 /* With Fortran 77 there might be a "BLOCK DATA" module
8486 available without any name. If so, we skip the module as it
8487 doesn't bring any value. */
8488 if (actual_name
!= nullptr)
8490 psymbol
.domain
= MODULE_DOMAIN
;
8491 psymbol
.aclass
= LOC_TYPEDEF
;
8492 where
= psymbol_placement::GLOBAL
;
8495 case DW_TAG_class_type
:
8496 case DW_TAG_interface_type
:
8497 case DW_TAG_structure_type
:
8498 case DW_TAG_union_type
:
8499 case DW_TAG_enumeration_type
:
8500 /* Skip external references. The DWARF standard says in the section
8501 about "Structure, Union, and Class Type Entries": "An incomplete
8502 structure, union or class type is represented by a structure,
8503 union or class entry that does not have a byte size attribute
8504 and that has a DW_AT_declaration attribute." */
8505 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8508 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8509 static vs. global. */
8510 psymbol
.domain
= STRUCT_DOMAIN
;
8511 psymbol
.aclass
= LOC_TYPEDEF
;
8512 where
= (cu
->language
== language_cplus
8513 ? psymbol_placement::GLOBAL
8514 : psymbol_placement::STATIC
);
8516 case DW_TAG_enumerator
:
8517 psymbol
.domain
= VAR_DOMAIN
;
8518 psymbol
.aclass
= LOC_CONST
;
8519 where
= (cu
->language
== language_cplus
8520 ? psymbol_placement::GLOBAL
8521 : psymbol_placement::STATIC
);
8527 if (where
.has_value ())
8529 if (built_actual_name
!= nullptr)
8530 actual_name
= objfile
->intern (actual_name
);
8531 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8532 psymbol
.ginfo
.set_linkage_name (actual_name
);
8535 psymbol
.ginfo
.set_demangled_name (actual_name
,
8536 &objfile
->objfile_obstack
);
8537 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8539 add_psymbol_to_list (psymbol
, *where
, objfile
);
8543 /* Read a partial die corresponding to a namespace; also, add a symbol
8544 corresponding to that namespace to the symbol table. NAMESPACE is
8545 the name of the enclosing namespace. */
8548 add_partial_namespace (struct partial_die_info
*pdi
,
8549 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8550 int set_addrmap
, struct dwarf2_cu
*cu
)
8552 /* Add a symbol for the namespace. */
8554 add_partial_symbol (pdi
, cu
);
8556 /* Now scan partial symbols in that namespace. */
8558 if (pdi
->has_children
)
8559 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8562 /* Read a partial die corresponding to a Fortran module. */
8565 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8566 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8568 /* Add a symbol for the namespace. */
8570 add_partial_symbol (pdi
, cu
);
8572 /* Now scan partial symbols in that module. */
8574 if (pdi
->has_children
)
8575 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8578 /* Read a partial die corresponding to a subprogram or an inlined
8579 subprogram and create a partial symbol for that subprogram.
8580 When the CU language allows it, this routine also defines a partial
8581 symbol for each nested subprogram that this subprogram contains.
8582 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8583 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8585 PDI may also be a lexical block, in which case we simply search
8586 recursively for subprograms defined inside that lexical block.
8587 Again, this is only performed when the CU language allows this
8588 type of definitions. */
8591 add_partial_subprogram (struct partial_die_info
*pdi
,
8592 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8593 int set_addrmap
, struct dwarf2_cu
*cu
)
8595 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8597 if (pdi
->has_pc_info
)
8599 if (pdi
->lowpc
< *lowpc
)
8600 *lowpc
= pdi
->lowpc
;
8601 if (pdi
->highpc
> *highpc
)
8602 *highpc
= pdi
->highpc
;
8605 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8606 struct gdbarch
*gdbarch
= objfile
->arch ();
8608 CORE_ADDR this_highpc
;
8609 CORE_ADDR this_lowpc
;
8611 baseaddr
= objfile
->text_section_offset ();
8613 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8614 pdi
->lowpc
+ baseaddr
)
8617 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8618 pdi
->highpc
+ baseaddr
)
8620 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8621 this_lowpc
, this_highpc
- 1,
8622 cu
->per_cu
->v
.psymtab
);
8626 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8628 if (!pdi
->is_declaration
)
8629 /* Ignore subprogram DIEs that do not have a name, they are
8630 illegal. Do not emit a complaint at this point, we will
8631 do so when we convert this psymtab into a symtab. */
8633 add_partial_symbol (pdi
, cu
);
8637 if (! pdi
->has_children
)
8640 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8642 pdi
= pdi
->die_child
;
8646 if (pdi
->tag
== DW_TAG_subprogram
8647 || pdi
->tag
== DW_TAG_inlined_subroutine
8648 || pdi
->tag
== DW_TAG_lexical_block
)
8649 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8650 pdi
= pdi
->die_sibling
;
8655 /* Read a partial die corresponding to an enumeration type. */
8658 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8659 struct dwarf2_cu
*cu
)
8661 struct partial_die_info
*pdi
;
8663 if (enum_pdi
->name
!= NULL
)
8664 add_partial_symbol (enum_pdi
, cu
);
8666 pdi
= enum_pdi
->die_child
;
8669 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8670 complaint (_("malformed enumerator DIE ignored"));
8672 add_partial_symbol (pdi
, cu
);
8673 pdi
= pdi
->die_sibling
;
8677 /* Return the initial uleb128 in the die at INFO_PTR. */
8680 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8682 unsigned int bytes_read
;
8684 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8687 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8688 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8690 Return the corresponding abbrev, or NULL if the number is zero (indicating
8691 an empty DIE). In either case *BYTES_READ will be set to the length of
8692 the initial number. */
8694 static struct abbrev_info
*
8695 peek_die_abbrev (const die_reader_specs
&reader
,
8696 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8698 dwarf2_cu
*cu
= reader
.cu
;
8699 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8700 unsigned int abbrev_number
8701 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8703 if (abbrev_number
== 0)
8706 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8709 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8710 " at offset %s [in module %s]"),
8711 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8712 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8718 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8719 Returns a pointer to the end of a series of DIEs, terminated by an empty
8720 DIE. Any children of the skipped DIEs will also be skipped. */
8722 static const gdb_byte
*
8723 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8727 unsigned int bytes_read
;
8728 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8731 return info_ptr
+ bytes_read
;
8733 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8737 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8738 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8739 abbrev corresponding to that skipped uleb128 should be passed in
8740 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8743 static const gdb_byte
*
8744 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8745 struct abbrev_info
*abbrev
)
8747 unsigned int bytes_read
;
8748 struct attribute attr
;
8749 bfd
*abfd
= reader
->abfd
;
8750 struct dwarf2_cu
*cu
= reader
->cu
;
8751 const gdb_byte
*buffer
= reader
->buffer
;
8752 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8753 unsigned int form
, i
;
8755 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8757 /* The only abbrev we care about is DW_AT_sibling. */
8758 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8761 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8763 if (attr
.form
== DW_FORM_ref_addr
)
8764 complaint (_("ignoring absolute DW_AT_sibling"));
8767 sect_offset off
= attr
.get_ref_die_offset ();
8768 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8770 if (sibling_ptr
< info_ptr
)
8771 complaint (_("DW_AT_sibling points backwards"));
8772 else if (sibling_ptr
> reader
->buffer_end
)
8773 reader
->die_section
->overflow_complaint ();
8779 /* If it isn't DW_AT_sibling, skip this attribute. */
8780 form
= abbrev
->attrs
[i
].form
;
8784 case DW_FORM_ref_addr
:
8785 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8786 and later it is offset sized. */
8787 if (cu
->header
.version
== 2)
8788 info_ptr
+= cu
->header
.addr_size
;
8790 info_ptr
+= cu
->header
.offset_size
;
8792 case DW_FORM_GNU_ref_alt
:
8793 info_ptr
+= cu
->header
.offset_size
;
8796 info_ptr
+= cu
->header
.addr_size
;
8804 case DW_FORM_flag_present
:
8805 case DW_FORM_implicit_const
:
8822 case DW_FORM_ref_sig8
:
8825 case DW_FORM_data16
:
8828 case DW_FORM_string
:
8829 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8830 info_ptr
+= bytes_read
;
8832 case DW_FORM_sec_offset
:
8834 case DW_FORM_GNU_strp_alt
:
8835 info_ptr
+= cu
->header
.offset_size
;
8837 case DW_FORM_exprloc
:
8839 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8840 info_ptr
+= bytes_read
;
8842 case DW_FORM_block1
:
8843 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8845 case DW_FORM_block2
:
8846 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8848 case DW_FORM_block4
:
8849 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8855 case DW_FORM_ref_udata
:
8856 case DW_FORM_GNU_addr_index
:
8857 case DW_FORM_GNU_str_index
:
8858 case DW_FORM_rnglistx
:
8859 case DW_FORM_loclistx
:
8860 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8862 case DW_FORM_indirect
:
8863 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8864 info_ptr
+= bytes_read
;
8865 /* We need to continue parsing from here, so just go back to
8867 goto skip_attribute
;
8870 error (_("Dwarf Error: Cannot handle %s "
8871 "in DWARF reader [in module %s]"),
8872 dwarf_form_name (form
),
8873 bfd_get_filename (abfd
));
8877 if (abbrev
->has_children
)
8878 return skip_children (reader
, info_ptr
);
8883 /* Locate ORIG_PDI's sibling.
8884 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8886 static const gdb_byte
*
8887 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8888 struct partial_die_info
*orig_pdi
,
8889 const gdb_byte
*info_ptr
)
8891 /* Do we know the sibling already? */
8893 if (orig_pdi
->sibling
)
8894 return orig_pdi
->sibling
;
8896 /* Are there any children to deal with? */
8898 if (!orig_pdi
->has_children
)
8901 /* Skip the children the long way. */
8903 return skip_children (reader
, info_ptr
);
8906 /* Expand this partial symbol table into a full symbol table. SELF is
8910 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8912 struct dwarf2_per_objfile
*dwarf2_per_objfile
8913 = get_dwarf2_per_objfile (objfile
);
8915 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (per_cu_data
));
8917 /* If this psymtab is constructed from a debug-only objfile, the
8918 has_section_at_zero flag will not necessarily be correct. We
8919 can get the correct value for this flag by looking at the data
8920 associated with the (presumably stripped) associated objfile. */
8921 if (objfile
->separate_debug_objfile_backlink
)
8923 struct dwarf2_per_objfile
*dpo_backlink
8924 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8926 dwarf2_per_objfile
->per_bfd
->has_section_at_zero
8927 = dpo_backlink
->per_bfd
->has_section_at_zero
;
8930 expand_psymtab (objfile
);
8932 process_cu_includes (dwarf2_per_objfile
);
8935 /* Reading in full CUs. */
8937 /* Add PER_CU to the queue. */
8940 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8941 enum language pretend_language
)
8944 per_cu
->per_bfd
->queue
.emplace (per_cu
, pretend_language
);
8947 /* If PER_CU is not yet queued, add it to the queue.
8948 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8950 The result is non-zero if PER_CU was queued, otherwise the result is zero
8951 meaning either PER_CU is already queued or it is already loaded.
8953 N.B. There is an invariant here that if a CU is queued then it is loaded.
8954 The caller is required to load PER_CU if we return non-zero. */
8957 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8958 struct dwarf2_per_cu_data
*per_cu
,
8959 enum language pretend_language
)
8961 /* We may arrive here during partial symbol reading, if we need full
8962 DIEs to process an unusual case (e.g. template arguments). Do
8963 not queue PER_CU, just tell our caller to load its DIEs. */
8964 if (per_cu
->per_bfd
->reading_partial_symbols
)
8966 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8971 /* Mark the dependence relation so that we don't flush PER_CU
8973 if (dependent_cu
!= NULL
)
8974 dwarf2_add_dependence (dependent_cu
, per_cu
);
8976 /* If it's already on the queue, we have nothing to do. */
8980 /* If the compilation unit is already loaded, just mark it as
8982 if (per_cu
->cu
!= NULL
)
8984 per_cu
->cu
->last_used
= 0;
8988 /* Add it to the queue. */
8989 queue_comp_unit (per_cu
, pretend_language
);
8994 /* Process the queue. */
8997 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8999 if (dwarf_read_debug
)
9001 fprintf_unfiltered (gdb_stdlog
,
9002 "Expanding one or more symtabs of objfile %s ...\n",
9003 objfile_name (dwarf2_per_objfile
->objfile
));
9006 /* The queue starts out with one item, but following a DIE reference
9007 may load a new CU, adding it to the end of the queue. */
9008 while (!dwarf2_per_objfile
->per_bfd
->queue
.empty ())
9010 dwarf2_queue_item
&item
= dwarf2_per_objfile
->per_bfd
->queue
.front ();
9012 if (!dwarf2_per_objfile
->symtab_set_p (item
.per_cu
)
9013 /* Skip dummy CUs. */
9014 && item
.per_cu
->cu
!= NULL
)
9016 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9017 unsigned int debug_print_threshold
;
9020 if (per_cu
->is_debug_types
)
9022 struct signatured_type
*sig_type
=
9023 (struct signatured_type
*) per_cu
;
9025 sprintf (buf
, "TU %s at offset %s",
9026 hex_string (sig_type
->signature
),
9027 sect_offset_str (per_cu
->sect_off
));
9028 /* There can be 100s of TUs.
9029 Only print them in verbose mode. */
9030 debug_print_threshold
= 2;
9034 sprintf (buf
, "CU at offset %s",
9035 sect_offset_str (per_cu
->sect_off
));
9036 debug_print_threshold
= 1;
9039 if (dwarf_read_debug
>= debug_print_threshold
)
9040 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9042 if (per_cu
->is_debug_types
)
9043 process_full_type_unit (per_cu
, dwarf2_per_objfile
,
9044 item
.pretend_language
);
9046 process_full_comp_unit (per_cu
, dwarf2_per_objfile
,
9047 item
.pretend_language
);
9049 if (dwarf_read_debug
>= debug_print_threshold
)
9050 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9053 item
.per_cu
->queued
= 0;
9054 dwarf2_per_objfile
->per_bfd
->queue
.pop ();
9057 if (dwarf_read_debug
)
9059 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9060 objfile_name (dwarf2_per_objfile
->objfile
));
9064 /* Read in full symbols for PST, and anything it depends on. */
9067 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9069 gdb_assert (!readin_p (objfile
));
9071 expand_dependencies (objfile
);
9073 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9074 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9075 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9078 /* See psympriv.h. */
9081 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9083 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9084 return per_objfile
->symtab_set_p (per_cu_data
);
9087 /* See psympriv.h. */
9090 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9092 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9093 return per_objfile
->get_symtab (per_cu_data
);
9096 /* Trivial hash function for die_info: the hash value of a DIE
9097 is its offset in .debug_info for this objfile. */
9100 die_hash (const void *item
)
9102 const struct die_info
*die
= (const struct die_info
*) item
;
9104 return to_underlying (die
->sect_off
);
9107 /* Trivial comparison function for die_info structures: two DIEs
9108 are equal if they have the same offset. */
9111 die_eq (const void *item_lhs
, const void *item_rhs
)
9113 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9114 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9116 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9119 /* Load the DIEs associated with PER_CU into memory. */
9122 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9123 dwarf2_per_objfile
*per_objfile
,
9125 enum language pretend_language
)
9127 gdb_assert (! this_cu
->is_debug_types
);
9129 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 1, skip_partial
);
9133 struct dwarf2_cu
*cu
= reader
.cu
;
9134 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9136 gdb_assert (cu
->die_hash
== NULL
);
9138 htab_create_alloc_ex (cu
->header
.length
/ 12,
9142 &cu
->comp_unit_obstack
,
9143 hashtab_obstack_allocate
,
9144 dummy_obstack_deallocate
);
9146 if (reader
.comp_unit_die
->has_children
)
9147 reader
.comp_unit_die
->child
9148 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9149 &info_ptr
, reader
.comp_unit_die
);
9150 cu
->dies
= reader
.comp_unit_die
;
9151 /* comp_unit_die is not stored in die_hash, no need. */
9153 /* We try not to read any attributes in this function, because not
9154 all CUs needed for references have been loaded yet, and symbol
9155 table processing isn't initialized. But we have to set the CU language,
9156 or we won't be able to build types correctly.
9157 Similarly, if we do not read the producer, we can not apply
9158 producer-specific interpretation. */
9159 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9164 /* Add a DIE to the delayed physname list. */
9167 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9168 const char *name
, struct die_info
*die
,
9169 struct dwarf2_cu
*cu
)
9171 struct delayed_method_info mi
;
9173 mi
.fnfield_index
= fnfield_index
;
9177 cu
->method_list
.push_back (mi
);
9180 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9181 "const" / "volatile". If so, decrements LEN by the length of the
9182 modifier and return true. Otherwise return false. */
9186 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9188 size_t mod_len
= sizeof (mod
) - 1;
9189 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9197 /* Compute the physnames of any methods on the CU's method list.
9199 The computation of method physnames is delayed in order to avoid the
9200 (bad) condition that one of the method's formal parameters is of an as yet
9204 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9206 /* Only C++ delays computing physnames. */
9207 if (cu
->method_list
.empty ())
9209 gdb_assert (cu
->language
== language_cplus
);
9211 for (const delayed_method_info
&mi
: cu
->method_list
)
9213 const char *physname
;
9214 struct fn_fieldlist
*fn_flp
9215 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9216 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9217 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9218 = physname
? physname
: "";
9220 /* Since there's no tag to indicate whether a method is a
9221 const/volatile overload, extract that information out of the
9223 if (physname
!= NULL
)
9225 size_t len
= strlen (physname
);
9229 if (physname
[len
] == ')') /* shortcut */
9231 else if (check_modifier (physname
, len
, " const"))
9232 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9233 else if (check_modifier (physname
, len
, " volatile"))
9234 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9241 /* The list is no longer needed. */
9242 cu
->method_list
.clear ();
9245 /* Go objects should be embedded in a DW_TAG_module DIE,
9246 and it's not clear if/how imported objects will appear.
9247 To keep Go support simple until that's worked out,
9248 go back through what we've read and create something usable.
9249 We could do this while processing each DIE, and feels kinda cleaner,
9250 but that way is more invasive.
9251 This is to, for example, allow the user to type "p var" or "b main"
9252 without having to specify the package name, and allow lookups
9253 of module.object to work in contexts that use the expression
9257 fixup_go_packaging (struct dwarf2_cu
*cu
)
9259 gdb::unique_xmalloc_ptr
<char> package_name
;
9260 struct pending
*list
;
9263 for (list
= *cu
->get_builder ()->get_global_symbols ();
9267 for (i
= 0; i
< list
->nsyms
; ++i
)
9269 struct symbol
*sym
= list
->symbol
[i
];
9271 if (sym
->language () == language_go
9272 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9274 gdb::unique_xmalloc_ptr
<char> this_package_name
9275 (go_symbol_package_name (sym
));
9277 if (this_package_name
== NULL
)
9279 if (package_name
== NULL
)
9280 package_name
= std::move (this_package_name
);
9283 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9284 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9285 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9286 (symbol_symtab (sym
) != NULL
9287 ? symtab_to_filename_for_display
9288 (symbol_symtab (sym
))
9289 : objfile_name (objfile
)),
9290 this_package_name
.get (), package_name
.get ());
9296 if (package_name
!= NULL
)
9298 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9299 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9300 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9301 saved_package_name
);
9304 sym
= new (&objfile
->objfile_obstack
) symbol
;
9305 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9306 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9307 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9308 e.g., "main" finds the "main" module and not C's main(). */
9309 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9310 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9311 SYMBOL_TYPE (sym
) = type
;
9313 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9317 /* Allocate a fully-qualified name consisting of the two parts on the
9321 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9323 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9326 /* A helper that allocates a variant part to attach to a Rust enum
9327 type. OBSTACK is where the results should be allocated. TYPE is
9328 the type we're processing. DISCRIMINANT_INDEX is the index of the
9329 discriminant. It must be the index of one of the fields of TYPE.
9330 DEFAULT_INDEX is the index of the default field; or -1 if there is
9331 no default. RANGES is indexed by "effective" field number (the
9332 field index, but omitting the discriminant and default fields) and
9333 must hold the discriminant values used by the variants. Note that
9334 RANGES must have a lifetime at least as long as OBSTACK -- either
9335 already allocated on it, or static. */
9338 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9339 int discriminant_index
, int default_index
,
9340 gdb::array_view
<discriminant_range
> ranges
)
9342 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9343 must be handled by the caller. */
9344 gdb_assert (discriminant_index
>= 0
9345 && discriminant_index
< type
->num_fields ());
9346 gdb_assert (default_index
== -1
9347 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9349 /* We have one variant for each non-discriminant field. */
9350 int n_variants
= type
->num_fields () - 1;
9352 variant
*variants
= new (obstack
) variant
[n_variants
];
9355 for (int i
= 0; i
< type
->num_fields (); ++i
)
9357 if (i
== discriminant_index
)
9360 variants
[var_idx
].first_field
= i
;
9361 variants
[var_idx
].last_field
= i
+ 1;
9363 /* The default field does not need a range, but other fields do.
9364 We skipped the discriminant above. */
9365 if (i
!= default_index
)
9367 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9374 gdb_assert (range_idx
== ranges
.size ());
9375 gdb_assert (var_idx
== n_variants
);
9377 variant_part
*part
= new (obstack
) variant_part
;
9378 part
->discriminant_index
= discriminant_index
;
9379 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9380 discriminant_index
));
9381 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9383 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9384 gdb::array_view
<variant_part
> *prop_value
9385 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9387 struct dynamic_prop prop
;
9388 prop
.kind
= PROP_VARIANT_PARTS
;
9389 prop
.data
.variant_parts
= prop_value
;
9391 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9394 /* Some versions of rustc emitted enums in an unusual way.
9396 Ordinary enums were emitted as unions. The first element of each
9397 structure in the union was named "RUST$ENUM$DISR". This element
9398 held the discriminant.
9400 These versions of Rust also implemented the "non-zero"
9401 optimization. When the enum had two values, and one is empty and
9402 the other holds a pointer that cannot be zero, the pointer is used
9403 as the discriminant, with a zero value meaning the empty variant.
9404 Here, the union's first member is of the form
9405 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9406 where the fieldnos are the indices of the fields that should be
9407 traversed in order to find the field (which may be several fields deep)
9408 and the variantname is the name of the variant of the case when the
9411 This function recognizes whether TYPE is of one of these forms,
9412 and, if so, smashes it to be a variant type. */
9415 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9417 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9419 /* We don't need to deal with empty enums. */
9420 if (type
->num_fields () == 0)
9423 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9424 if (type
->num_fields () == 1
9425 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9427 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9429 /* Decode the field name to find the offset of the
9431 ULONGEST bit_offset
= 0;
9432 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9433 while (name
[0] >= '0' && name
[0] <= '9')
9436 unsigned long index
= strtoul (name
, &tail
, 10);
9439 || index
>= field_type
->num_fields ()
9440 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9441 != FIELD_LOC_KIND_BITPOS
))
9443 complaint (_("Could not parse Rust enum encoding string \"%s\""
9445 TYPE_FIELD_NAME (type
, 0),
9446 objfile_name (objfile
));
9451 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9452 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9455 /* Smash this type to be a structure type. We have to do this
9456 because the type has already been recorded. */
9457 type
->set_code (TYPE_CODE_STRUCT
);
9458 type
->set_num_fields (3);
9459 /* Save the field we care about. */
9460 struct field saved_field
= type
->field (0);
9462 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9464 /* Put the discriminant at index 0. */
9465 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9466 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9467 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9468 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9470 /* The order of fields doesn't really matter, so put the real
9471 field at index 1 and the data-less field at index 2. */
9472 type
->field (1) = saved_field
;
9473 TYPE_FIELD_NAME (type
, 1)
9474 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9475 TYPE_FIELD_TYPE (type
, 1)->set_name
9476 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9477 TYPE_FIELD_NAME (type
, 1)));
9479 const char *dataless_name
9480 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9482 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9484 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9485 /* NAME points into the original discriminant name, which
9486 already has the correct lifetime. */
9487 TYPE_FIELD_NAME (type
, 2) = name
;
9488 SET_FIELD_BITPOS (type
->field (2), 0);
9490 /* Indicate that this is a variant type. */
9491 static discriminant_range ranges
[1] = { { 0, 0 } };
9492 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9494 /* A union with a single anonymous field is probably an old-style
9496 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9498 /* Smash this type to be a structure type. We have to do this
9499 because the type has already been recorded. */
9500 type
->set_code (TYPE_CODE_STRUCT
);
9502 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9503 const char *variant_name
9504 = rust_last_path_segment (field_type
->name ());
9505 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9506 field_type
->set_name
9507 (rust_fully_qualify (&objfile
->objfile_obstack
,
9508 type
->name (), variant_name
));
9512 struct type
*disr_type
= nullptr;
9513 for (int i
= 0; i
< type
->num_fields (); ++i
)
9515 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9517 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9519 /* All fields of a true enum will be structs. */
9522 else if (disr_type
->num_fields () == 0)
9524 /* Could be data-less variant, so keep going. */
9525 disr_type
= nullptr;
9527 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9528 "RUST$ENUM$DISR") != 0)
9530 /* Not a Rust enum. */
9540 /* If we got here without a discriminant, then it's probably
9542 if (disr_type
== nullptr)
9545 /* Smash this type to be a structure type. We have to do this
9546 because the type has already been recorded. */
9547 type
->set_code (TYPE_CODE_STRUCT
);
9549 /* Make space for the discriminant field. */
9550 struct field
*disr_field
= &disr_type
->field (0);
9552 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9553 * sizeof (struct field
)));
9554 memcpy (new_fields
+ 1, type
->fields (),
9555 type
->num_fields () * sizeof (struct field
));
9556 type
->set_fields (new_fields
);
9557 type
->set_num_fields (type
->num_fields () + 1);
9559 /* Install the discriminant at index 0 in the union. */
9560 type
->field (0) = *disr_field
;
9561 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9562 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9564 /* We need a way to find the correct discriminant given a
9565 variant name. For convenience we build a map here. */
9566 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9567 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9568 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9570 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9573 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9574 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9578 int n_fields
= type
->num_fields ();
9579 /* We don't need a range entry for the discriminant, but we do
9580 need one for every other field, as there is no default
9582 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9585 /* Skip the discriminant here. */
9586 for (int i
= 1; i
< n_fields
; ++i
)
9588 /* Find the final word in the name of this variant's type.
9589 That name can be used to look up the correct
9591 const char *variant_name
9592 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9594 auto iter
= discriminant_map
.find (variant_name
);
9595 if (iter
!= discriminant_map
.end ())
9597 ranges
[i
].low
= iter
->second
;
9598 ranges
[i
].high
= iter
->second
;
9601 /* Remove the discriminant field, if it exists. */
9602 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9603 if (sub_type
->num_fields () > 0)
9605 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9606 sub_type
->set_fields (sub_type
->fields () + 1);
9608 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9610 (rust_fully_qualify (&objfile
->objfile_obstack
,
9611 type
->name (), variant_name
));
9614 /* Indicate that this is a variant type. */
9615 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9616 gdb::array_view
<discriminant_range
> (ranges
,
9621 /* Rewrite some Rust unions to be structures with variants parts. */
9624 rust_union_quirks (struct dwarf2_cu
*cu
)
9626 gdb_assert (cu
->language
== language_rust
);
9627 for (type
*type_
: cu
->rust_unions
)
9628 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9629 /* We don't need this any more. */
9630 cu
->rust_unions
.clear ();
9633 /* A helper function for computing the list of all symbol tables
9634 included by PER_CU. */
9637 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9638 htab_t all_children
, htab_t all_type_symtabs
,
9639 dwarf2_per_cu_data
*per_cu
,
9640 dwarf2_per_objfile
*per_objfile
,
9641 struct compunit_symtab
*immediate_parent
)
9643 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9646 /* This inclusion and its children have been processed. */
9652 /* Only add a CU if it has a symbol table. */
9653 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9656 /* If this is a type unit only add its symbol table if we haven't
9657 seen it yet (type unit per_cu's can share symtabs). */
9658 if (per_cu
->is_debug_types
)
9660 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9664 result
->push_back (cust
);
9665 if (cust
->user
== NULL
)
9666 cust
->user
= immediate_parent
;
9671 result
->push_back (cust
);
9672 if (cust
->user
== NULL
)
9673 cust
->user
= immediate_parent
;
9677 if (!per_cu
->imported_symtabs_empty ())
9678 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9680 recursively_compute_inclusions (result
, all_children
,
9681 all_type_symtabs
, ptr
, per_objfile
,
9686 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9690 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9691 dwarf2_per_objfile
*per_objfile
)
9693 gdb_assert (! per_cu
->is_debug_types
);
9695 if (!per_cu
->imported_symtabs_empty ())
9698 std::vector
<compunit_symtab
*> result_symtabs
;
9699 htab_t all_children
, all_type_symtabs
;
9700 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9702 /* If we don't have a symtab, we can just skip this case. */
9706 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9707 NULL
, xcalloc
, xfree
);
9708 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9709 NULL
, xcalloc
, xfree
);
9711 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9713 recursively_compute_inclusions (&result_symtabs
, all_children
,
9714 all_type_symtabs
, ptr
, per_objfile
,
9718 /* Now we have a transitive closure of all the included symtabs. */
9719 len
= result_symtabs
.size ();
9721 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9722 struct compunit_symtab
*, len
+ 1);
9723 memcpy (cust
->includes
, result_symtabs
.data (),
9724 len
* sizeof (compunit_symtab
*));
9725 cust
->includes
[len
] = NULL
;
9727 htab_delete (all_children
);
9728 htab_delete (all_type_symtabs
);
9732 /* Compute the 'includes' field for the symtabs of all the CUs we just
9736 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9738 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->per_bfd
->just_read_cus
)
9740 if (! iter
->is_debug_types
)
9741 compute_compunit_symtab_includes (iter
, dwarf2_per_objfile
);
9744 dwarf2_per_objfile
->per_bfd
->just_read_cus
.clear ();
9747 /* Generate full symbol information for PER_CU, whose DIEs have
9748 already been loaded into memory. */
9751 process_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
9752 dwarf2_per_objfile
*dwarf2_per_objfile
,
9753 enum language pretend_language
)
9755 struct dwarf2_cu
*cu
= per_cu
->cu
;
9756 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9757 struct gdbarch
*gdbarch
= objfile
->arch ();
9758 CORE_ADDR lowpc
, highpc
;
9759 struct compunit_symtab
*cust
;
9761 struct block
*static_block
;
9764 baseaddr
= objfile
->text_section_offset ();
9766 /* Clear the list here in case something was left over. */
9767 cu
->method_list
.clear ();
9769 cu
->language
= pretend_language
;
9770 cu
->language_defn
= language_def (cu
->language
);
9772 /* Do line number decoding in read_file_scope () */
9773 process_die (cu
->dies
, cu
);
9775 /* For now fudge the Go package. */
9776 if (cu
->language
== language_go
)
9777 fixup_go_packaging (cu
);
9779 /* Now that we have processed all the DIEs in the CU, all the types
9780 should be complete, and it should now be safe to compute all of the
9782 compute_delayed_physnames (cu
);
9784 if (cu
->language
== language_rust
)
9785 rust_union_quirks (cu
);
9787 /* Some compilers don't define a DW_AT_high_pc attribute for the
9788 compilation unit. If the DW_AT_high_pc is missing, synthesize
9789 it, by scanning the DIE's below the compilation unit. */
9790 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9792 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9793 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9795 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9796 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9797 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9798 addrmap to help ensure it has an accurate map of pc values belonging to
9800 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9802 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9803 SECT_OFF_TEXT (objfile
),
9808 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9810 /* Set symtab language to language from DW_AT_language. If the
9811 compilation is from a C file generated by language preprocessors, do
9812 not set the language if it was already deduced by start_subfile. */
9813 if (!(cu
->language
== language_c
9814 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9815 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9817 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9818 produce DW_AT_location with location lists but it can be possibly
9819 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9820 there were bugs in prologue debug info, fixed later in GCC-4.5
9821 by "unwind info for epilogues" patch (which is not directly related).
9823 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9824 needed, it would be wrong due to missing DW_AT_producer there.
9826 Still one can confuse GDB by using non-standard GCC compilation
9827 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9829 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9830 cust
->locations_valid
= 1;
9832 if (gcc_4_minor
>= 5)
9833 cust
->epilogue_unwind_valid
= 1;
9835 cust
->call_site_htab
= cu
->call_site_htab
;
9838 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9840 /* Push it for inclusion processing later. */
9841 dwarf2_per_objfile
->per_bfd
->just_read_cus
.push_back (per_cu
);
9843 /* Not needed any more. */
9844 cu
->reset_builder ();
9847 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9848 already been loaded into memory. */
9851 process_full_type_unit (dwarf2_per_cu_data
*per_cu
,
9852 dwarf2_per_objfile
*dwarf2_per_objfile
,
9853 enum language pretend_language
)
9855 struct dwarf2_cu
*cu
= per_cu
->cu
;
9856 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9857 struct compunit_symtab
*cust
;
9858 struct signatured_type
*sig_type
;
9860 gdb_assert (per_cu
->is_debug_types
);
9861 sig_type
= (struct signatured_type
*) per_cu
;
9863 /* Clear the list here in case something was left over. */
9864 cu
->method_list
.clear ();
9866 cu
->language
= pretend_language
;
9867 cu
->language_defn
= language_def (cu
->language
);
9869 /* The symbol tables are set up in read_type_unit_scope. */
9870 process_die (cu
->dies
, cu
);
9872 /* For now fudge the Go package. */
9873 if (cu
->language
== language_go
)
9874 fixup_go_packaging (cu
);
9876 /* Now that we have processed all the DIEs in the CU, all the types
9877 should be complete, and it should now be safe to compute all of the
9879 compute_delayed_physnames (cu
);
9881 if (cu
->language
== language_rust
)
9882 rust_union_quirks (cu
);
9884 /* TUs share symbol tables.
9885 If this is the first TU to use this symtab, complete the construction
9886 of it with end_expandable_symtab. Otherwise, complete the addition of
9887 this TU's symbols to the existing symtab. */
9888 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9890 buildsym_compunit
*builder
= cu
->get_builder ();
9891 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9892 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9896 /* Set symtab language to language from DW_AT_language. If the
9897 compilation is from a C file generated by language preprocessors,
9898 do not set the language if it was already deduced by
9900 if (!(cu
->language
== language_c
9901 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9902 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9907 cu
->get_builder ()->augment_type_symtab ();
9908 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9911 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9913 /* Not needed any more. */
9914 cu
->reset_builder ();
9917 /* Process an imported unit DIE. */
9920 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9922 struct attribute
*attr
;
9924 /* For now we don't handle imported units in type units. */
9925 if (cu
->per_cu
->is_debug_types
)
9927 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9928 " supported in type units [in module %s]"),
9929 objfile_name (cu
->per_objfile
->objfile
));
9932 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9935 sect_offset sect_off
= attr
->get_ref_die_offset ();
9936 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9937 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9938 dwarf2_per_cu_data
*per_cu
9939 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9941 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9942 into another compilation unit, at root level. Regard this as a hint,
9944 if (die
->parent
&& die
->parent
->parent
== NULL
9945 && per_cu
->unit_type
== DW_UT_compile
9946 && per_cu
->lang
== language_cplus
)
9949 /* If necessary, add it to the queue and load its DIEs. */
9950 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9951 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
9953 cu
->per_cu
->imported_symtabs_push (per_cu
);
9957 /* RAII object that represents a process_die scope: i.e.,
9958 starts/finishes processing a DIE. */
9959 class process_die_scope
9962 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9963 : m_die (die
), m_cu (cu
)
9965 /* We should only be processing DIEs not already in process. */
9966 gdb_assert (!m_die
->in_process
);
9967 m_die
->in_process
= true;
9970 ~process_die_scope ()
9972 m_die
->in_process
= false;
9974 /* If we're done processing the DIE for the CU that owns the line
9975 header, we don't need the line header anymore. */
9976 if (m_cu
->line_header_die_owner
== m_die
)
9978 delete m_cu
->line_header
;
9979 m_cu
->line_header
= NULL
;
9980 m_cu
->line_header_die_owner
= NULL
;
9989 /* Process a die and its children. */
9992 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9994 process_die_scope
scope (die
, cu
);
9998 case DW_TAG_padding
:
10000 case DW_TAG_compile_unit
:
10001 case DW_TAG_partial_unit
:
10002 read_file_scope (die
, cu
);
10004 case DW_TAG_type_unit
:
10005 read_type_unit_scope (die
, cu
);
10007 case DW_TAG_subprogram
:
10008 /* Nested subprograms in Fortran get a prefix. */
10009 if (cu
->language
== language_fortran
10010 && die
->parent
!= NULL
10011 && die
->parent
->tag
== DW_TAG_subprogram
)
10012 cu
->processing_has_namespace_info
= true;
10013 /* Fall through. */
10014 case DW_TAG_inlined_subroutine
:
10015 read_func_scope (die
, cu
);
10017 case DW_TAG_lexical_block
:
10018 case DW_TAG_try_block
:
10019 case DW_TAG_catch_block
:
10020 read_lexical_block_scope (die
, cu
);
10022 case DW_TAG_call_site
:
10023 case DW_TAG_GNU_call_site
:
10024 read_call_site_scope (die
, cu
);
10026 case DW_TAG_class_type
:
10027 case DW_TAG_interface_type
:
10028 case DW_TAG_structure_type
:
10029 case DW_TAG_union_type
:
10030 process_structure_scope (die
, cu
);
10032 case DW_TAG_enumeration_type
:
10033 process_enumeration_scope (die
, cu
);
10036 /* These dies have a type, but processing them does not create
10037 a symbol or recurse to process the children. Therefore we can
10038 read them on-demand through read_type_die. */
10039 case DW_TAG_subroutine_type
:
10040 case DW_TAG_set_type
:
10041 case DW_TAG_array_type
:
10042 case DW_TAG_pointer_type
:
10043 case DW_TAG_ptr_to_member_type
:
10044 case DW_TAG_reference_type
:
10045 case DW_TAG_rvalue_reference_type
:
10046 case DW_TAG_string_type
:
10049 case DW_TAG_base_type
:
10050 case DW_TAG_subrange_type
:
10051 case DW_TAG_typedef
:
10052 /* Add a typedef symbol for the type definition, if it has a
10054 new_symbol (die
, read_type_die (die
, cu
), cu
);
10056 case DW_TAG_common_block
:
10057 read_common_block (die
, cu
);
10059 case DW_TAG_common_inclusion
:
10061 case DW_TAG_namespace
:
10062 cu
->processing_has_namespace_info
= true;
10063 read_namespace (die
, cu
);
10065 case DW_TAG_module
:
10066 cu
->processing_has_namespace_info
= true;
10067 read_module (die
, cu
);
10069 case DW_TAG_imported_declaration
:
10070 cu
->processing_has_namespace_info
= true;
10071 if (read_namespace_alias (die
, cu
))
10073 /* The declaration is not a global namespace alias. */
10074 /* Fall through. */
10075 case DW_TAG_imported_module
:
10076 cu
->processing_has_namespace_info
= true;
10077 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10078 || cu
->language
!= language_fortran
))
10079 complaint (_("Tag '%s' has unexpected children"),
10080 dwarf_tag_name (die
->tag
));
10081 read_import_statement (die
, cu
);
10084 case DW_TAG_imported_unit
:
10085 process_imported_unit_die (die
, cu
);
10088 case DW_TAG_variable
:
10089 read_variable (die
, cu
);
10093 new_symbol (die
, NULL
, cu
);
10098 /* DWARF name computation. */
10100 /* A helper function for dwarf2_compute_name which determines whether DIE
10101 needs to have the name of the scope prepended to the name listed in the
10105 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10107 struct attribute
*attr
;
10111 case DW_TAG_namespace
:
10112 case DW_TAG_typedef
:
10113 case DW_TAG_class_type
:
10114 case DW_TAG_interface_type
:
10115 case DW_TAG_structure_type
:
10116 case DW_TAG_union_type
:
10117 case DW_TAG_enumeration_type
:
10118 case DW_TAG_enumerator
:
10119 case DW_TAG_subprogram
:
10120 case DW_TAG_inlined_subroutine
:
10121 case DW_TAG_member
:
10122 case DW_TAG_imported_declaration
:
10125 case DW_TAG_variable
:
10126 case DW_TAG_constant
:
10127 /* We only need to prefix "globally" visible variables. These include
10128 any variable marked with DW_AT_external or any variable that
10129 lives in a namespace. [Variables in anonymous namespaces
10130 require prefixing, but they are not DW_AT_external.] */
10132 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10134 struct dwarf2_cu
*spec_cu
= cu
;
10136 return die_needs_namespace (die_specification (die
, &spec_cu
),
10140 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10141 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10142 && die
->parent
->tag
!= DW_TAG_module
)
10144 /* A variable in a lexical block of some kind does not need a
10145 namespace, even though in C++ such variables may be external
10146 and have a mangled name. */
10147 if (die
->parent
->tag
== DW_TAG_lexical_block
10148 || die
->parent
->tag
== DW_TAG_try_block
10149 || die
->parent
->tag
== DW_TAG_catch_block
10150 || die
->parent
->tag
== DW_TAG_subprogram
)
10159 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10160 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10161 defined for the given DIE. */
10163 static struct attribute
*
10164 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10166 struct attribute
*attr
;
10168 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10170 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10175 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10176 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10177 defined for the given DIE. */
10179 static const char *
10180 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10182 const char *linkage_name
;
10184 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10185 if (linkage_name
== NULL
)
10186 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10188 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10189 See https://github.com/rust-lang/rust/issues/32925. */
10190 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10191 && strchr (linkage_name
, '{') != NULL
)
10192 linkage_name
= NULL
;
10194 return linkage_name
;
10197 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10198 compute the physname for the object, which include a method's:
10199 - formal parameters (C++),
10200 - receiver type (Go),
10202 The term "physname" is a bit confusing.
10203 For C++, for example, it is the demangled name.
10204 For Go, for example, it's the mangled name.
10206 For Ada, return the DIE's linkage name rather than the fully qualified
10207 name. PHYSNAME is ignored..
10209 The result is allocated on the objfile->per_bfd's obstack and
10212 static const char *
10213 dwarf2_compute_name (const char *name
,
10214 struct die_info
*die
, struct dwarf2_cu
*cu
,
10217 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10220 name
= dwarf2_name (die
, cu
);
10222 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10223 but otherwise compute it by typename_concat inside GDB.
10224 FIXME: Actually this is not really true, or at least not always true.
10225 It's all very confusing. compute_and_set_names doesn't try to demangle
10226 Fortran names because there is no mangling standard. So new_symbol
10227 will set the demangled name to the result of dwarf2_full_name, and it is
10228 the demangled name that GDB uses if it exists. */
10229 if (cu
->language
== language_ada
10230 || (cu
->language
== language_fortran
&& physname
))
10232 /* For Ada unit, we prefer the linkage name over the name, as
10233 the former contains the exported name, which the user expects
10234 to be able to reference. Ideally, we want the user to be able
10235 to reference this entity using either natural or linkage name,
10236 but we haven't started looking at this enhancement yet. */
10237 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10239 if (linkage_name
!= NULL
)
10240 return linkage_name
;
10243 /* These are the only languages we know how to qualify names in. */
10245 && (cu
->language
== language_cplus
10246 || cu
->language
== language_fortran
|| cu
->language
== language_d
10247 || cu
->language
== language_rust
))
10249 if (die_needs_namespace (die
, cu
))
10251 const char *prefix
;
10252 const char *canonical_name
= NULL
;
10256 prefix
= determine_prefix (die
, cu
);
10257 if (*prefix
!= '\0')
10259 gdb::unique_xmalloc_ptr
<char> prefixed_name
10260 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10262 buf
.puts (prefixed_name
.get ());
10267 /* Template parameters may be specified in the DIE's DW_AT_name, or
10268 as children with DW_TAG_template_type_param or
10269 DW_TAG_value_type_param. If the latter, add them to the name
10270 here. If the name already has template parameters, then
10271 skip this step; some versions of GCC emit both, and
10272 it is more efficient to use the pre-computed name.
10274 Something to keep in mind about this process: it is very
10275 unlikely, or in some cases downright impossible, to produce
10276 something that will match the mangled name of a function.
10277 If the definition of the function has the same debug info,
10278 we should be able to match up with it anyway. But fallbacks
10279 using the minimal symbol, for instance to find a method
10280 implemented in a stripped copy of libstdc++, will not work.
10281 If we do not have debug info for the definition, we will have to
10282 match them up some other way.
10284 When we do name matching there is a related problem with function
10285 templates; two instantiated function templates are allowed to
10286 differ only by their return types, which we do not add here. */
10288 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10290 struct attribute
*attr
;
10291 struct die_info
*child
;
10294 die
->building_fullname
= 1;
10296 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10300 const gdb_byte
*bytes
;
10301 struct dwarf2_locexpr_baton
*baton
;
10304 if (child
->tag
!= DW_TAG_template_type_param
10305 && child
->tag
!= DW_TAG_template_value_param
)
10316 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10319 complaint (_("template parameter missing DW_AT_type"));
10320 buf
.puts ("UNKNOWN_TYPE");
10323 type
= die_type (child
, cu
);
10325 if (child
->tag
== DW_TAG_template_type_param
)
10327 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10328 &type_print_raw_options
);
10332 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10335 complaint (_("template parameter missing "
10336 "DW_AT_const_value"));
10337 buf
.puts ("UNKNOWN_VALUE");
10341 dwarf2_const_value_attr (attr
, type
, name
,
10342 &cu
->comp_unit_obstack
, cu
,
10343 &value
, &bytes
, &baton
);
10345 if (TYPE_NOSIGN (type
))
10346 /* GDB prints characters as NUMBER 'CHAR'. If that's
10347 changed, this can use value_print instead. */
10348 c_printchar (value
, type
, &buf
);
10351 struct value_print_options opts
;
10354 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10358 baton
->per_objfile
);
10359 else if (bytes
!= NULL
)
10361 v
= allocate_value (type
);
10362 memcpy (value_contents_writeable (v
), bytes
,
10363 TYPE_LENGTH (type
));
10366 v
= value_from_longest (type
, value
);
10368 /* Specify decimal so that we do not depend on
10370 get_formatted_print_options (&opts
, 'd');
10372 value_print (v
, &buf
, &opts
);
10377 die
->building_fullname
= 0;
10381 /* Close the argument list, with a space if necessary
10382 (nested templates). */
10383 if (!buf
.empty () && buf
.string ().back () == '>')
10390 /* For C++ methods, append formal parameter type
10391 information, if PHYSNAME. */
10393 if (physname
&& die
->tag
== DW_TAG_subprogram
10394 && cu
->language
== language_cplus
)
10396 struct type
*type
= read_type_die (die
, cu
);
10398 c_type_print_args (type
, &buf
, 1, cu
->language
,
10399 &type_print_raw_options
);
10401 if (cu
->language
== language_cplus
)
10403 /* Assume that an artificial first parameter is
10404 "this", but do not crash if it is not. RealView
10405 marks unnamed (and thus unused) parameters as
10406 artificial; there is no way to differentiate
10408 if (type
->num_fields () > 0
10409 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10410 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10411 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10413 buf
.puts (" const");
10417 const std::string
&intermediate_name
= buf
.string ();
10419 if (cu
->language
== language_cplus
)
10421 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10424 /* If we only computed INTERMEDIATE_NAME, or if
10425 INTERMEDIATE_NAME is already canonical, then we need to
10427 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10428 name
= objfile
->intern (intermediate_name
);
10430 name
= canonical_name
;
10437 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10438 If scope qualifiers are appropriate they will be added. The result
10439 will be allocated on the storage_obstack, or NULL if the DIE does
10440 not have a name. NAME may either be from a previous call to
10441 dwarf2_name or NULL.
10443 The output string will be canonicalized (if C++). */
10445 static const char *
10446 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10448 return dwarf2_compute_name (name
, die
, cu
, 0);
10451 /* Construct a physname for the given DIE in CU. NAME may either be
10452 from a previous call to dwarf2_name or NULL. The result will be
10453 allocated on the objfile_objstack or NULL if the DIE does not have a
10456 The output string will be canonicalized (if C++). */
10458 static const char *
10459 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10461 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10462 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10465 /* In this case dwarf2_compute_name is just a shortcut not building anything
10467 if (!die_needs_namespace (die
, cu
))
10468 return dwarf2_compute_name (name
, die
, cu
, 1);
10470 if (cu
->language
!= language_rust
)
10471 mangled
= dw2_linkage_name (die
, cu
);
10473 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10475 gdb::unique_xmalloc_ptr
<char> demangled
;
10476 if (mangled
!= NULL
)
10479 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10481 /* Do nothing (do not demangle the symbol name). */
10483 else if (cu
->language
== language_go
)
10485 /* This is a lie, but we already lie to the caller new_symbol.
10486 new_symbol assumes we return the mangled name.
10487 This just undoes that lie until things are cleaned up. */
10491 /* Use DMGL_RET_DROP for C++ template functions to suppress
10492 their return type. It is easier for GDB users to search
10493 for such functions as `name(params)' than `long name(params)'.
10494 In such case the minimal symbol names do not match the full
10495 symbol names but for template functions there is never a need
10496 to look up their definition from their declaration so
10497 the only disadvantage remains the minimal symbol variant
10498 `long name(params)' does not have the proper inferior type. */
10499 demangled
.reset (gdb_demangle (mangled
,
10500 (DMGL_PARAMS
| DMGL_ANSI
10501 | DMGL_RET_DROP
)));
10504 canon
= demangled
.get ();
10512 if (canon
== NULL
|| check_physname
)
10514 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10516 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10518 /* It may not mean a bug in GDB. The compiler could also
10519 compute DW_AT_linkage_name incorrectly. But in such case
10520 GDB would need to be bug-to-bug compatible. */
10522 complaint (_("Computed physname <%s> does not match demangled <%s> "
10523 "(from linkage <%s>) - DIE at %s [in module %s]"),
10524 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10525 objfile_name (objfile
));
10527 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10528 is available here - over computed PHYSNAME. It is safer
10529 against both buggy GDB and buggy compilers. */
10543 retval
= objfile
->intern (retval
);
10548 /* Inspect DIE in CU for a namespace alias. If one exists, record
10549 a new symbol for it.
10551 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10554 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10556 struct attribute
*attr
;
10558 /* If the die does not have a name, this is not a namespace
10560 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10564 struct die_info
*d
= die
;
10565 struct dwarf2_cu
*imported_cu
= cu
;
10567 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10568 keep inspecting DIEs until we hit the underlying import. */
10569 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10570 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10572 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10576 d
= follow_die_ref (d
, attr
, &imported_cu
);
10577 if (d
->tag
!= DW_TAG_imported_declaration
)
10581 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10583 complaint (_("DIE at %s has too many recursively imported "
10584 "declarations"), sect_offset_str (d
->sect_off
));
10591 sect_offset sect_off
= attr
->get_ref_die_offset ();
10593 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10594 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10596 /* This declaration is a global namespace alias. Add
10597 a symbol for it whose type is the aliased namespace. */
10598 new_symbol (die
, type
, cu
);
10607 /* Return the using directives repository (global or local?) to use in the
10608 current context for CU.
10610 For Ada, imported declarations can materialize renamings, which *may* be
10611 global. However it is impossible (for now?) in DWARF to distinguish
10612 "external" imported declarations and "static" ones. As all imported
10613 declarations seem to be static in all other languages, make them all CU-wide
10614 global only in Ada. */
10616 static struct using_direct
**
10617 using_directives (struct dwarf2_cu
*cu
)
10619 if (cu
->language
== language_ada
10620 && cu
->get_builder ()->outermost_context_p ())
10621 return cu
->get_builder ()->get_global_using_directives ();
10623 return cu
->get_builder ()->get_local_using_directives ();
10626 /* Read the import statement specified by the given die and record it. */
10629 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10631 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10632 struct attribute
*import_attr
;
10633 struct die_info
*imported_die
, *child_die
;
10634 struct dwarf2_cu
*imported_cu
;
10635 const char *imported_name
;
10636 const char *imported_name_prefix
;
10637 const char *canonical_name
;
10638 const char *import_alias
;
10639 const char *imported_declaration
= NULL
;
10640 const char *import_prefix
;
10641 std::vector
<const char *> excludes
;
10643 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10644 if (import_attr
== NULL
)
10646 complaint (_("Tag '%s' has no DW_AT_import"),
10647 dwarf_tag_name (die
->tag
));
10652 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10653 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10654 if (imported_name
== NULL
)
10656 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10658 The import in the following code:
10672 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10673 <52> DW_AT_decl_file : 1
10674 <53> DW_AT_decl_line : 6
10675 <54> DW_AT_import : <0x75>
10676 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10677 <59> DW_AT_name : B
10678 <5b> DW_AT_decl_file : 1
10679 <5c> DW_AT_decl_line : 2
10680 <5d> DW_AT_type : <0x6e>
10682 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10683 <76> DW_AT_byte_size : 4
10684 <77> DW_AT_encoding : 5 (signed)
10686 imports the wrong die ( 0x75 instead of 0x58 ).
10687 This case will be ignored until the gcc bug is fixed. */
10691 /* Figure out the local name after import. */
10692 import_alias
= dwarf2_name (die
, cu
);
10694 /* Figure out where the statement is being imported to. */
10695 import_prefix
= determine_prefix (die
, cu
);
10697 /* Figure out what the scope of the imported die is and prepend it
10698 to the name of the imported die. */
10699 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10701 if (imported_die
->tag
!= DW_TAG_namespace
10702 && imported_die
->tag
!= DW_TAG_module
)
10704 imported_declaration
= imported_name
;
10705 canonical_name
= imported_name_prefix
;
10707 else if (strlen (imported_name_prefix
) > 0)
10708 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10709 imported_name_prefix
,
10710 (cu
->language
== language_d
? "." : "::"),
10711 imported_name
, (char *) NULL
);
10713 canonical_name
= imported_name
;
10715 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10716 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10717 child_die
= child_die
->sibling
)
10719 /* DWARF-4: A Fortran use statement with a “rename list” may be
10720 represented by an imported module entry with an import attribute
10721 referring to the module and owned entries corresponding to those
10722 entities that are renamed as part of being imported. */
10724 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10726 complaint (_("child DW_TAG_imported_declaration expected "
10727 "- DIE at %s [in module %s]"),
10728 sect_offset_str (child_die
->sect_off
),
10729 objfile_name (objfile
));
10733 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10734 if (import_attr
== NULL
)
10736 complaint (_("Tag '%s' has no DW_AT_import"),
10737 dwarf_tag_name (child_die
->tag
));
10742 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10744 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10745 if (imported_name
== NULL
)
10747 complaint (_("child DW_TAG_imported_declaration has unknown "
10748 "imported name - DIE at %s [in module %s]"),
10749 sect_offset_str (child_die
->sect_off
),
10750 objfile_name (objfile
));
10754 excludes
.push_back (imported_name
);
10756 process_die (child_die
, cu
);
10759 add_using_directive (using_directives (cu
),
10763 imported_declaration
,
10766 &objfile
->objfile_obstack
);
10769 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10770 types, but gives them a size of zero. Starting with version 14,
10771 ICC is compatible with GCC. */
10774 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10776 if (!cu
->checked_producer
)
10777 check_producer (cu
);
10779 return cu
->producer_is_icc_lt_14
;
10782 /* ICC generates a DW_AT_type for C void functions. This was observed on
10783 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10784 which says that void functions should not have a DW_AT_type. */
10787 producer_is_icc (struct dwarf2_cu
*cu
)
10789 if (!cu
->checked_producer
)
10790 check_producer (cu
);
10792 return cu
->producer_is_icc
;
10795 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10796 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10797 this, it was first present in GCC release 4.3.0. */
10800 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10802 if (!cu
->checked_producer
)
10803 check_producer (cu
);
10805 return cu
->producer_is_gcc_lt_4_3
;
10808 static file_and_directory
10809 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10811 file_and_directory res
;
10813 /* Find the filename. Do not use dwarf2_name here, since the filename
10814 is not a source language identifier. */
10815 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10816 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10818 if (res
.comp_dir
== NULL
10819 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10820 && IS_ABSOLUTE_PATH (res
.name
))
10822 res
.comp_dir_storage
= ldirname (res
.name
);
10823 if (!res
.comp_dir_storage
.empty ())
10824 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10826 if (res
.comp_dir
!= NULL
)
10828 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10829 directory, get rid of it. */
10830 const char *cp
= strchr (res
.comp_dir
, ':');
10832 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10833 res
.comp_dir
= cp
+ 1;
10836 if (res
.name
== NULL
)
10837 res
.name
= "<unknown>";
10842 /* Handle DW_AT_stmt_list for a compilation unit.
10843 DIE is the DW_TAG_compile_unit die for CU.
10844 COMP_DIR is the compilation directory. LOWPC is passed to
10845 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10848 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10849 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10851 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10852 struct attribute
*attr
;
10853 struct line_header line_header_local
;
10854 hashval_t line_header_local_hash
;
10856 int decode_mapping
;
10858 gdb_assert (! cu
->per_cu
->is_debug_types
);
10860 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10864 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10866 /* The line header hash table is only created if needed (it exists to
10867 prevent redundant reading of the line table for partial_units).
10868 If we're given a partial_unit, we'll need it. If we're given a
10869 compile_unit, then use the line header hash table if it's already
10870 created, but don't create one just yet. */
10872 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
10873 && die
->tag
== DW_TAG_partial_unit
)
10875 dwarf2_per_objfile
->per_bfd
->line_header_hash
10876 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10877 line_header_eq_voidp
,
10878 free_line_header_voidp
,
10882 line_header_local
.sect_off
= line_offset
;
10883 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10884 line_header_local_hash
= line_header_hash (&line_header_local
);
10885 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
!= NULL
)
10887 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10888 &line_header_local
,
10889 line_header_local_hash
, NO_INSERT
);
10891 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10892 is not present in *SLOT (since if there is something in *SLOT then
10893 it will be for a partial_unit). */
10894 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10896 gdb_assert (*slot
!= NULL
);
10897 cu
->line_header
= (struct line_header
*) *slot
;
10902 /* dwarf_decode_line_header does not yet provide sufficient information.
10903 We always have to call also dwarf_decode_lines for it. */
10904 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10908 cu
->line_header
= lh
.release ();
10909 cu
->line_header_die_owner
= die
;
10911 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
)
10915 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10916 &line_header_local
,
10917 line_header_local_hash
, INSERT
);
10918 gdb_assert (slot
!= NULL
);
10920 if (slot
!= NULL
&& *slot
== NULL
)
10922 /* This newly decoded line number information unit will be owned
10923 by line_header_hash hash table. */
10924 *slot
= cu
->line_header
;
10925 cu
->line_header_die_owner
= NULL
;
10929 /* We cannot free any current entry in (*slot) as that struct line_header
10930 may be already used by multiple CUs. Create only temporary decoded
10931 line_header for this CU - it may happen at most once for each line
10932 number information unit. And if we're not using line_header_hash
10933 then this is what we want as well. */
10934 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10936 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10937 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10942 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10945 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10947 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10948 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10949 struct gdbarch
*gdbarch
= objfile
->arch ();
10950 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10951 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10952 struct attribute
*attr
;
10953 struct die_info
*child_die
;
10954 CORE_ADDR baseaddr
;
10956 prepare_one_comp_unit (cu
, die
, cu
->language
);
10957 baseaddr
= objfile
->text_section_offset ();
10959 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10961 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10962 from finish_block. */
10963 if (lowpc
== ((CORE_ADDR
) -1))
10965 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10967 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10969 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10970 standardised yet. As a workaround for the language detection we fall
10971 back to the DW_AT_producer string. */
10972 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10973 cu
->language
= language_opencl
;
10975 /* Similar hack for Go. */
10976 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10977 set_cu_language (DW_LANG_Go
, cu
);
10979 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10981 /* Decode line number information if present. We do this before
10982 processing child DIEs, so that the line header table is available
10983 for DW_AT_decl_file. */
10984 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10986 /* Process all dies in compilation unit. */
10987 if (die
->child
!= NULL
)
10989 child_die
= die
->child
;
10990 while (child_die
&& child_die
->tag
)
10992 process_die (child_die
, cu
);
10993 child_die
= child_die
->sibling
;
10997 /* Decode macro information, if present. Dwarf 2 macro information
10998 refers to information in the line number info statement program
10999 header, so we can only read it if we've read the header
11001 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11003 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11004 if (attr
&& cu
->line_header
)
11006 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11007 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11009 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11013 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11014 if (attr
&& cu
->line_header
)
11016 unsigned int macro_offset
= DW_UNSND (attr
);
11018 dwarf_decode_macros (cu
, macro_offset
, 0);
11024 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11026 struct type_unit_group
*tu_group
;
11028 struct attribute
*attr
;
11030 struct signatured_type
*sig_type
;
11032 gdb_assert (per_cu
->is_debug_types
);
11033 sig_type
= (struct signatured_type
*) per_cu
;
11035 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11037 /* If we're using .gdb_index (includes -readnow) then
11038 per_cu->type_unit_group may not have been set up yet. */
11039 if (sig_type
->type_unit_group
== NULL
)
11040 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11041 tu_group
= sig_type
->type_unit_group
;
11043 /* If we've already processed this stmt_list there's no real need to
11044 do it again, we could fake it and just recreate the part we need
11045 (file name,index -> symtab mapping). If data shows this optimization
11046 is useful we can do it then. */
11047 first_time
= tu_group
->compunit_symtab
== NULL
;
11049 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11054 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11055 lh
= dwarf_decode_line_header (line_offset
, this);
11060 start_symtab ("", NULL
, 0);
11063 gdb_assert (tu_group
->symtabs
== NULL
);
11064 gdb_assert (m_builder
== nullptr);
11065 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11066 m_builder
.reset (new struct buildsym_compunit
11067 (COMPUNIT_OBJFILE (cust
), "",
11068 COMPUNIT_DIRNAME (cust
),
11069 compunit_language (cust
),
11071 list_in_scope
= get_builder ()->get_file_symbols ();
11076 line_header
= lh
.release ();
11077 line_header_die_owner
= die
;
11081 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11083 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11084 still initializing it, and our caller (a few levels up)
11085 process_full_type_unit still needs to know if this is the first
11089 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11090 struct symtab
*, line_header
->file_names_size ());
11092 auto &file_names
= line_header
->file_names ();
11093 for (i
= 0; i
< file_names
.size (); ++i
)
11095 file_entry
&fe
= file_names
[i
];
11096 dwarf2_start_subfile (this, fe
.name
,
11097 fe
.include_dir (line_header
));
11098 buildsym_compunit
*b
= get_builder ();
11099 if (b
->get_current_subfile ()->symtab
== NULL
)
11101 /* NOTE: start_subfile will recognize when it's been
11102 passed a file it has already seen. So we can't
11103 assume there's a simple mapping from
11104 cu->line_header->file_names to subfiles, plus
11105 cu->line_header->file_names may contain dups. */
11106 b
->get_current_subfile ()->symtab
11107 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11110 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11111 tu_group
->symtabs
[i
] = fe
.symtab
;
11116 gdb_assert (m_builder
== nullptr);
11117 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11118 m_builder
.reset (new struct buildsym_compunit
11119 (COMPUNIT_OBJFILE (cust
), "",
11120 COMPUNIT_DIRNAME (cust
),
11121 compunit_language (cust
),
11123 list_in_scope
= get_builder ()->get_file_symbols ();
11125 auto &file_names
= line_header
->file_names ();
11126 for (i
= 0; i
< file_names
.size (); ++i
)
11128 file_entry
&fe
= file_names
[i
];
11129 fe
.symtab
= tu_group
->symtabs
[i
];
11133 /* The main symtab is allocated last. Type units don't have DW_AT_name
11134 so they don't have a "real" (so to speak) symtab anyway.
11135 There is later code that will assign the main symtab to all symbols
11136 that don't have one. We need to handle the case of a symbol with a
11137 missing symtab (DW_AT_decl_file) anyway. */
11140 /* Process DW_TAG_type_unit.
11141 For TUs we want to skip the first top level sibling if it's not the
11142 actual type being defined by this TU. In this case the first top
11143 level sibling is there to provide context only. */
11146 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11148 struct die_info
*child_die
;
11150 prepare_one_comp_unit (cu
, die
, language_minimal
);
11152 /* Initialize (or reinitialize) the machinery for building symtabs.
11153 We do this before processing child DIEs, so that the line header table
11154 is available for DW_AT_decl_file. */
11155 cu
->setup_type_unit_groups (die
);
11157 if (die
->child
!= NULL
)
11159 child_die
= die
->child
;
11160 while (child_die
&& child_die
->tag
)
11162 process_die (child_die
, cu
);
11163 child_die
= child_die
->sibling
;
11170 http://gcc.gnu.org/wiki/DebugFission
11171 http://gcc.gnu.org/wiki/DebugFissionDWP
11173 To simplify handling of both DWO files ("object" files with the DWARF info)
11174 and DWP files (a file with the DWOs packaged up into one file), we treat
11175 DWP files as having a collection of virtual DWO files. */
11178 hash_dwo_file (const void *item
)
11180 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11183 hash
= htab_hash_string (dwo_file
->dwo_name
);
11184 if (dwo_file
->comp_dir
!= NULL
)
11185 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11190 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11192 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11193 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11195 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11197 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11198 return lhs
->comp_dir
== rhs
->comp_dir
;
11199 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11202 /* Allocate a hash table for DWO files. */
11205 allocate_dwo_file_hash_table ()
11207 auto delete_dwo_file
= [] (void *item
)
11209 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11214 return htab_up (htab_create_alloc (41,
11221 /* Lookup DWO file DWO_NAME. */
11224 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11225 const char *dwo_name
,
11226 const char *comp_dir
)
11228 struct dwo_file find_entry
;
11231 if (dwarf2_per_objfile
->per_bfd
->dwo_files
== NULL
)
11232 dwarf2_per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11234 find_entry
.dwo_name
= dwo_name
;
11235 find_entry
.comp_dir
= comp_dir
;
11236 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11243 hash_dwo_unit (const void *item
)
11245 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11247 /* This drops the top 32 bits of the id, but is ok for a hash. */
11248 return dwo_unit
->signature
;
11252 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11254 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11255 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11257 /* The signature is assumed to be unique within the DWO file.
11258 So while object file CU dwo_id's always have the value zero,
11259 that's OK, assuming each object file DWO file has only one CU,
11260 and that's the rule for now. */
11261 return lhs
->signature
== rhs
->signature
;
11264 /* Allocate a hash table for DWO CUs,TUs.
11265 There is one of these tables for each of CUs,TUs for each DWO file. */
11268 allocate_dwo_unit_table ()
11270 /* Start out with a pretty small number.
11271 Generally DWO files contain only one CU and maybe some TUs. */
11272 return htab_up (htab_create_alloc (3,
11275 NULL
, xcalloc
, xfree
));
11278 /* die_reader_func for create_dwo_cu. */
11281 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11282 const gdb_byte
*info_ptr
,
11283 struct die_info
*comp_unit_die
,
11284 struct dwo_file
*dwo_file
,
11285 struct dwo_unit
*dwo_unit
)
11287 struct dwarf2_cu
*cu
= reader
->cu
;
11288 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11289 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11291 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11292 if (!signature
.has_value ())
11294 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11295 " its dwo_id [in module %s]"),
11296 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11300 dwo_unit
->dwo_file
= dwo_file
;
11301 dwo_unit
->signature
= *signature
;
11302 dwo_unit
->section
= section
;
11303 dwo_unit
->sect_off
= sect_off
;
11304 dwo_unit
->length
= cu
->per_cu
->length
;
11306 if (dwarf_read_debug
)
11307 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11308 sect_offset_str (sect_off
),
11309 hex_string (dwo_unit
->signature
));
11312 /* Create the dwo_units for the CUs in a DWO_FILE.
11313 Note: This function processes DWO files only, not DWP files. */
11316 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11317 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11318 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11320 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11321 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
11322 const gdb_byte
*info_ptr
, *end_ptr
;
11324 section
.read (objfile
);
11325 info_ptr
= section
.buffer
;
11327 if (info_ptr
== NULL
)
11330 if (dwarf_read_debug
)
11332 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11333 section
.get_name (),
11334 section
.get_file_name ());
11337 end_ptr
= info_ptr
+ section
.size
;
11338 while (info_ptr
< end_ptr
)
11340 struct dwarf2_per_cu_data per_cu
;
11341 struct dwo_unit read_unit
{};
11342 struct dwo_unit
*dwo_unit
;
11344 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11346 memset (&per_cu
, 0, sizeof (per_cu
));
11347 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11348 per_cu
.per_bfd
= per_bfd
;
11349 per_cu
.is_debug_types
= 0;
11350 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11351 per_cu
.section
= §ion
;
11353 cutu_reader
reader (&per_cu
, dwarf2_per_objfile
, cu
, &dwo_file
);
11354 if (!reader
.dummy_p
)
11355 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11356 &dwo_file
, &read_unit
);
11357 info_ptr
+= per_cu
.length
;
11359 // If the unit could not be parsed, skip it.
11360 if (read_unit
.dwo_file
== NULL
)
11363 if (cus_htab
== NULL
)
11364 cus_htab
= allocate_dwo_unit_table ();
11366 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11368 *dwo_unit
= read_unit
;
11369 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11370 gdb_assert (slot
!= NULL
);
11373 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11374 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11376 complaint (_("debug cu entry at offset %s is duplicate to"
11377 " the entry at offset %s, signature %s"),
11378 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11379 hex_string (dwo_unit
->signature
));
11381 *slot
= (void *)dwo_unit
;
11385 /* DWP file .debug_{cu,tu}_index section format:
11386 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11390 Both index sections have the same format, and serve to map a 64-bit
11391 signature to a set of section numbers. Each section begins with a header,
11392 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11393 indexes, and a pool of 32-bit section numbers. The index sections will be
11394 aligned at 8-byte boundaries in the file.
11396 The index section header consists of:
11398 V, 32 bit version number
11400 N, 32 bit number of compilation units or type units in the index
11401 M, 32 bit number of slots in the hash table
11403 Numbers are recorded using the byte order of the application binary.
11405 The hash table begins at offset 16 in the section, and consists of an array
11406 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11407 order of the application binary). Unused slots in the hash table are 0.
11408 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11410 The parallel table begins immediately after the hash table
11411 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11412 array of 32-bit indexes (using the byte order of the application binary),
11413 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11414 table contains a 32-bit index into the pool of section numbers. For unused
11415 hash table slots, the corresponding entry in the parallel table will be 0.
11417 The pool of section numbers begins immediately following the hash table
11418 (at offset 16 + 12 * M from the beginning of the section). The pool of
11419 section numbers consists of an array of 32-bit words (using the byte order
11420 of the application binary). Each item in the array is indexed starting
11421 from 0. The hash table entry provides the index of the first section
11422 number in the set. Additional section numbers in the set follow, and the
11423 set is terminated by a 0 entry (section number 0 is not used in ELF).
11425 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11426 section must be the first entry in the set, and the .debug_abbrev.dwo must
11427 be the second entry. Other members of the set may follow in any order.
11433 DWP Version 2 combines all the .debug_info, etc. sections into one,
11434 and the entries in the index tables are now offsets into these sections.
11435 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11438 Index Section Contents:
11440 Hash Table of Signatures dwp_hash_table.hash_table
11441 Parallel Table of Indices dwp_hash_table.unit_table
11442 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11443 Table of Section Sizes dwp_hash_table.v2.sizes
11445 The index section header consists of:
11447 V, 32 bit version number
11448 L, 32 bit number of columns in the table of section offsets
11449 N, 32 bit number of compilation units or type units in the index
11450 M, 32 bit number of slots in the hash table
11452 Numbers are recorded using the byte order of the application binary.
11454 The hash table has the same format as version 1.
11455 The parallel table of indices has the same format as version 1,
11456 except that the entries are origin-1 indices into the table of sections
11457 offsets and the table of section sizes.
11459 The table of offsets begins immediately following the parallel table
11460 (at offset 16 + 12 * M from the beginning of the section). The table is
11461 a two-dimensional array of 32-bit words (using the byte order of the
11462 application binary), with L columns and N+1 rows, in row-major order.
11463 Each row in the array is indexed starting from 0. The first row provides
11464 a key to the remaining rows: each column in this row provides an identifier
11465 for a debug section, and the offsets in the same column of subsequent rows
11466 refer to that section. The section identifiers are:
11468 DW_SECT_INFO 1 .debug_info.dwo
11469 DW_SECT_TYPES 2 .debug_types.dwo
11470 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11471 DW_SECT_LINE 4 .debug_line.dwo
11472 DW_SECT_LOC 5 .debug_loc.dwo
11473 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11474 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11475 DW_SECT_MACRO 8 .debug_macro.dwo
11477 The offsets provided by the CU and TU index sections are the base offsets
11478 for the contributions made by each CU or TU to the corresponding section
11479 in the package file. Each CU and TU header contains an abbrev_offset
11480 field, used to find the abbreviations table for that CU or TU within the
11481 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11482 be interpreted as relative to the base offset given in the index section.
11483 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11484 should be interpreted as relative to the base offset for .debug_line.dwo,
11485 and offsets into other debug sections obtained from DWARF attributes should
11486 also be interpreted as relative to the corresponding base offset.
11488 The table of sizes begins immediately following the table of offsets.
11489 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11490 with L columns and N rows, in row-major order. Each row in the array is
11491 indexed starting from 1 (row 0 is shared by the two tables).
11495 Hash table lookup is handled the same in version 1 and 2:
11497 We assume that N and M will not exceed 2^32 - 1.
11498 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11500 Given a 64-bit compilation unit signature or a type signature S, an entry
11501 in the hash table is located as follows:
11503 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11504 the low-order k bits all set to 1.
11506 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11508 3) If the hash table entry at index H matches the signature, use that
11509 entry. If the hash table entry at index H is unused (all zeroes),
11510 terminate the search: the signature is not present in the table.
11512 4) Let H = (H + H') modulo M. Repeat at Step 3.
11514 Because M > N and H' and M are relatively prime, the search is guaranteed
11515 to stop at an unused slot or find the match. */
11517 /* Create a hash table to map DWO IDs to their CU/TU entry in
11518 .debug_{info,types}.dwo in DWP_FILE.
11519 Returns NULL if there isn't one.
11520 Note: This function processes DWP files only, not DWO files. */
11522 static struct dwp_hash_table
*
11523 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11524 struct dwp_file
*dwp_file
, int is_debug_types
)
11526 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11527 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11528 const gdb_byte
*index_ptr
, *index_end
;
11529 struct dwarf2_section_info
*index
;
11530 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11531 struct dwp_hash_table
*htab
;
11533 if (is_debug_types
)
11534 index
= &dwp_file
->sections
.tu_index
;
11536 index
= &dwp_file
->sections
.cu_index
;
11538 if (index
->empty ())
11540 index
->read (objfile
);
11542 index_ptr
= index
->buffer
;
11543 index_end
= index_ptr
+ index
->size
;
11545 version
= read_4_bytes (dbfd
, index_ptr
);
11548 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11552 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11554 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11557 if (version
!= 1 && version
!= 2)
11559 error (_("Dwarf Error: unsupported DWP file version (%s)"
11560 " [in module %s]"),
11561 pulongest (version
), dwp_file
->name
);
11563 if (nr_slots
!= (nr_slots
& -nr_slots
))
11565 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11566 " is not power of 2 [in module %s]"),
11567 pulongest (nr_slots
), dwp_file
->name
);
11570 htab
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11571 htab
->version
= version
;
11572 htab
->nr_columns
= nr_columns
;
11573 htab
->nr_units
= nr_units
;
11574 htab
->nr_slots
= nr_slots
;
11575 htab
->hash_table
= index_ptr
;
11576 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11578 /* Exit early if the table is empty. */
11579 if (nr_slots
== 0 || nr_units
== 0
11580 || (version
== 2 && nr_columns
== 0))
11582 /* All must be zero. */
11583 if (nr_slots
!= 0 || nr_units
!= 0
11584 || (version
== 2 && nr_columns
!= 0))
11586 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11587 " all zero [in modules %s]"),
11595 htab
->section_pool
.v1
.indices
=
11596 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11597 /* It's harder to decide whether the section is too small in v1.
11598 V1 is deprecated anyway so we punt. */
11602 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11603 int *ids
= htab
->section_pool
.v2
.section_ids
;
11604 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11605 /* Reverse map for error checking. */
11606 int ids_seen
[DW_SECT_MAX
+ 1];
11609 if (nr_columns
< 2)
11611 error (_("Dwarf Error: bad DWP hash table, too few columns"
11612 " in section table [in module %s]"),
11615 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11617 error (_("Dwarf Error: bad DWP hash table, too many columns"
11618 " in section table [in module %s]"),
11621 memset (ids
, 255, sizeof_ids
);
11622 memset (ids_seen
, 255, sizeof (ids_seen
));
11623 for (i
= 0; i
< nr_columns
; ++i
)
11625 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11627 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11629 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11630 " in section table [in module %s]"),
11631 id
, dwp_file
->name
);
11633 if (ids_seen
[id
] != -1)
11635 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11636 " id %d in section table [in module %s]"),
11637 id
, dwp_file
->name
);
11642 /* Must have exactly one info or types section. */
11643 if (((ids_seen
[DW_SECT_INFO
] != -1)
11644 + (ids_seen
[DW_SECT_TYPES
] != -1))
11647 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11648 " DWO info/types section [in module %s]"),
11651 /* Must have an abbrev section. */
11652 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11654 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11655 " section [in module %s]"),
11658 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11659 htab
->section_pool
.v2
.sizes
=
11660 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11661 * nr_units
* nr_columns
);
11662 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11663 * nr_units
* nr_columns
))
11666 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11667 " [in module %s]"),
11675 /* Update SECTIONS with the data from SECTP.
11677 This function is like the other "locate" section routines that are
11678 passed to bfd_map_over_sections, but in this context the sections to
11679 read comes from the DWP V1 hash table, not the full ELF section table.
11681 The result is non-zero for success, or zero if an error was found. */
11684 locate_v1_virtual_dwo_sections (asection
*sectp
,
11685 struct virtual_v1_dwo_sections
*sections
)
11687 const struct dwop_section_names
*names
= &dwop_section_names
;
11689 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11691 /* There can be only one. */
11692 if (sections
->abbrev
.s
.section
!= NULL
)
11694 sections
->abbrev
.s
.section
= sectp
;
11695 sections
->abbrev
.size
= bfd_section_size (sectp
);
11697 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11698 || section_is_p (sectp
->name
, &names
->types_dwo
))
11700 /* There can be only one. */
11701 if (sections
->info_or_types
.s
.section
!= NULL
)
11703 sections
->info_or_types
.s
.section
= sectp
;
11704 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11706 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11708 /* There can be only one. */
11709 if (sections
->line
.s
.section
!= NULL
)
11711 sections
->line
.s
.section
= sectp
;
11712 sections
->line
.size
= bfd_section_size (sectp
);
11714 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11716 /* There can be only one. */
11717 if (sections
->loc
.s
.section
!= NULL
)
11719 sections
->loc
.s
.section
= sectp
;
11720 sections
->loc
.size
= bfd_section_size (sectp
);
11722 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11724 /* There can be only one. */
11725 if (sections
->macinfo
.s
.section
!= NULL
)
11727 sections
->macinfo
.s
.section
= sectp
;
11728 sections
->macinfo
.size
= bfd_section_size (sectp
);
11730 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11732 /* There can be only one. */
11733 if (sections
->macro
.s
.section
!= NULL
)
11735 sections
->macro
.s
.section
= sectp
;
11736 sections
->macro
.size
= bfd_section_size (sectp
);
11738 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11740 /* There can be only one. */
11741 if (sections
->str_offsets
.s
.section
!= NULL
)
11743 sections
->str_offsets
.s
.section
= sectp
;
11744 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11748 /* No other kind of section is valid. */
11755 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11756 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11757 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11758 This is for DWP version 1 files. */
11760 static struct dwo_unit
*
11761 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11762 struct dwp_file
*dwp_file
,
11763 uint32_t unit_index
,
11764 const char *comp_dir
,
11765 ULONGEST signature
, int is_debug_types
)
11767 const struct dwp_hash_table
*dwp_htab
=
11768 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11769 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11770 const char *kind
= is_debug_types
? "TU" : "CU";
11771 struct dwo_file
*dwo_file
;
11772 struct dwo_unit
*dwo_unit
;
11773 struct virtual_v1_dwo_sections sections
;
11774 void **dwo_file_slot
;
11777 gdb_assert (dwp_file
->version
== 1);
11779 if (dwarf_read_debug
)
11781 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11783 pulongest (unit_index
), hex_string (signature
),
11787 /* Fetch the sections of this DWO unit.
11788 Put a limit on the number of sections we look for so that bad data
11789 doesn't cause us to loop forever. */
11791 #define MAX_NR_V1_DWO_SECTIONS \
11792 (1 /* .debug_info or .debug_types */ \
11793 + 1 /* .debug_abbrev */ \
11794 + 1 /* .debug_line */ \
11795 + 1 /* .debug_loc */ \
11796 + 1 /* .debug_str_offsets */ \
11797 + 1 /* .debug_macro or .debug_macinfo */ \
11798 + 1 /* trailing zero */)
11800 memset (§ions
, 0, sizeof (sections
));
11802 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11805 uint32_t section_nr
=
11806 read_4_bytes (dbfd
,
11807 dwp_htab
->section_pool
.v1
.indices
11808 + (unit_index
+ i
) * sizeof (uint32_t));
11810 if (section_nr
== 0)
11812 if (section_nr
>= dwp_file
->num_sections
)
11814 error (_("Dwarf Error: bad DWP hash table, section number too large"
11815 " [in module %s]"),
11819 sectp
= dwp_file
->elf_sections
[section_nr
];
11820 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11822 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11823 " [in module %s]"),
11829 || sections
.info_or_types
.empty ()
11830 || sections
.abbrev
.empty ())
11832 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11833 " [in module %s]"),
11836 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11838 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11839 " [in module %s]"),
11843 /* It's easier for the rest of the code if we fake a struct dwo_file and
11844 have dwo_unit "live" in that. At least for now.
11846 The DWP file can be made up of a random collection of CUs and TUs.
11847 However, for each CU + set of TUs that came from the same original DWO
11848 file, we can combine them back into a virtual DWO file to save space
11849 (fewer struct dwo_file objects to allocate). Remember that for really
11850 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11852 std::string virtual_dwo_name
=
11853 string_printf ("virtual-dwo/%d-%d-%d-%d",
11854 sections
.abbrev
.get_id (),
11855 sections
.line
.get_id (),
11856 sections
.loc
.get_id (),
11857 sections
.str_offsets
.get_id ());
11858 /* Can we use an existing virtual DWO file? */
11859 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11860 virtual_dwo_name
.c_str (),
11862 /* Create one if necessary. */
11863 if (*dwo_file_slot
== NULL
)
11865 if (dwarf_read_debug
)
11867 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11868 virtual_dwo_name
.c_str ());
11870 dwo_file
= new struct dwo_file
;
11871 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
11872 dwo_file
->comp_dir
= comp_dir
;
11873 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11874 dwo_file
->sections
.line
= sections
.line
;
11875 dwo_file
->sections
.loc
= sections
.loc
;
11876 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11877 dwo_file
->sections
.macro
= sections
.macro
;
11878 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11879 /* The "str" section is global to the entire DWP file. */
11880 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11881 /* The info or types section is assigned below to dwo_unit,
11882 there's no need to record it in dwo_file.
11883 Also, we can't simply record type sections in dwo_file because
11884 we record a pointer into the vector in dwo_unit. As we collect more
11885 types we'll grow the vector and eventually have to reallocate space
11886 for it, invalidating all copies of pointers into the previous
11888 *dwo_file_slot
= dwo_file
;
11892 if (dwarf_read_debug
)
11894 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11895 virtual_dwo_name
.c_str ());
11897 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11900 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11901 dwo_unit
->dwo_file
= dwo_file
;
11902 dwo_unit
->signature
= signature
;
11903 dwo_unit
->section
=
11904 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11905 *dwo_unit
->section
= sections
.info_or_types
;
11906 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11911 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11912 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11913 piece within that section used by a TU/CU, return a virtual section
11914 of just that piece. */
11916 static struct dwarf2_section_info
11917 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11918 struct dwarf2_section_info
*section
,
11919 bfd_size_type offset
, bfd_size_type size
)
11921 struct dwarf2_section_info result
;
11924 gdb_assert (section
!= NULL
);
11925 gdb_assert (!section
->is_virtual
);
11927 memset (&result
, 0, sizeof (result
));
11928 result
.s
.containing_section
= section
;
11929 result
.is_virtual
= true;
11934 sectp
= section
->get_bfd_section ();
11936 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11937 bounds of the real section. This is a pretty-rare event, so just
11938 flag an error (easier) instead of a warning and trying to cope. */
11940 || offset
+ size
> bfd_section_size (sectp
))
11942 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11943 " in section %s [in module %s]"),
11944 sectp
? bfd_section_name (sectp
) : "<unknown>",
11945 objfile_name (dwarf2_per_objfile
->objfile
));
11948 result
.virtual_offset
= offset
;
11949 result
.size
= size
;
11953 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11954 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11955 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11956 This is for DWP version 2 files. */
11958 static struct dwo_unit
*
11959 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11960 struct dwp_file
*dwp_file
,
11961 uint32_t unit_index
,
11962 const char *comp_dir
,
11963 ULONGEST signature
, int is_debug_types
)
11965 const struct dwp_hash_table
*dwp_htab
=
11966 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11967 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11968 const char *kind
= is_debug_types
? "TU" : "CU";
11969 struct dwo_file
*dwo_file
;
11970 struct dwo_unit
*dwo_unit
;
11971 struct virtual_v2_dwo_sections sections
;
11972 void **dwo_file_slot
;
11975 gdb_assert (dwp_file
->version
== 2);
11977 if (dwarf_read_debug
)
11979 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11981 pulongest (unit_index
), hex_string (signature
),
11985 /* Fetch the section offsets of this DWO unit. */
11987 memset (§ions
, 0, sizeof (sections
));
11989 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11991 uint32_t offset
= read_4_bytes (dbfd
,
11992 dwp_htab
->section_pool
.v2
.offsets
11993 + (((unit_index
- 1) * dwp_htab
->nr_columns
11995 * sizeof (uint32_t)));
11996 uint32_t size
= read_4_bytes (dbfd
,
11997 dwp_htab
->section_pool
.v2
.sizes
11998 + (((unit_index
- 1) * dwp_htab
->nr_columns
12000 * sizeof (uint32_t)));
12002 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12005 case DW_SECT_TYPES
:
12006 sections
.info_or_types_offset
= offset
;
12007 sections
.info_or_types_size
= size
;
12009 case DW_SECT_ABBREV
:
12010 sections
.abbrev_offset
= offset
;
12011 sections
.abbrev_size
= size
;
12014 sections
.line_offset
= offset
;
12015 sections
.line_size
= size
;
12018 sections
.loc_offset
= offset
;
12019 sections
.loc_size
= size
;
12021 case DW_SECT_STR_OFFSETS
:
12022 sections
.str_offsets_offset
= offset
;
12023 sections
.str_offsets_size
= size
;
12025 case DW_SECT_MACINFO
:
12026 sections
.macinfo_offset
= offset
;
12027 sections
.macinfo_size
= size
;
12029 case DW_SECT_MACRO
:
12030 sections
.macro_offset
= offset
;
12031 sections
.macro_size
= size
;
12036 /* It's easier for the rest of the code if we fake a struct dwo_file and
12037 have dwo_unit "live" in that. At least for now.
12039 The DWP file can be made up of a random collection of CUs and TUs.
12040 However, for each CU + set of TUs that came from the same original DWO
12041 file, we can combine them back into a virtual DWO file to save space
12042 (fewer struct dwo_file objects to allocate). Remember that for really
12043 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12045 std::string virtual_dwo_name
=
12046 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12047 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12048 (long) (sections
.line_size
? sections
.line_offset
: 0),
12049 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12050 (long) (sections
.str_offsets_size
12051 ? sections
.str_offsets_offset
: 0));
12052 /* Can we use an existing virtual DWO file? */
12053 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12054 virtual_dwo_name
.c_str (),
12056 /* Create one if necessary. */
12057 if (*dwo_file_slot
== NULL
)
12059 if (dwarf_read_debug
)
12061 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12062 virtual_dwo_name
.c_str ());
12064 dwo_file
= new struct dwo_file
;
12065 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
12066 dwo_file
->comp_dir
= comp_dir
;
12067 dwo_file
->sections
.abbrev
=
12068 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12069 sections
.abbrev_offset
, sections
.abbrev_size
);
12070 dwo_file
->sections
.line
=
12071 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12072 sections
.line_offset
, sections
.line_size
);
12073 dwo_file
->sections
.loc
=
12074 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12075 sections
.loc_offset
, sections
.loc_size
);
12076 dwo_file
->sections
.macinfo
=
12077 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12078 sections
.macinfo_offset
, sections
.macinfo_size
);
12079 dwo_file
->sections
.macro
=
12080 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12081 sections
.macro_offset
, sections
.macro_size
);
12082 dwo_file
->sections
.str_offsets
=
12083 create_dwp_v2_section (dwarf2_per_objfile
,
12084 &dwp_file
->sections
.str_offsets
,
12085 sections
.str_offsets_offset
,
12086 sections
.str_offsets_size
);
12087 /* The "str" section is global to the entire DWP file. */
12088 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12089 /* The info or types section is assigned below to dwo_unit,
12090 there's no need to record it in dwo_file.
12091 Also, we can't simply record type sections in dwo_file because
12092 we record a pointer into the vector in dwo_unit. As we collect more
12093 types we'll grow the vector and eventually have to reallocate space
12094 for it, invalidating all copies of pointers into the previous
12096 *dwo_file_slot
= dwo_file
;
12100 if (dwarf_read_debug
)
12102 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12103 virtual_dwo_name
.c_str ());
12105 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12108 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12109 dwo_unit
->dwo_file
= dwo_file
;
12110 dwo_unit
->signature
= signature
;
12111 dwo_unit
->section
=
12112 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12113 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12115 ? &dwp_file
->sections
.types
12116 : &dwp_file
->sections
.info
,
12117 sections
.info_or_types_offset
,
12118 sections
.info_or_types_size
);
12119 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12124 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12125 Returns NULL if the signature isn't found. */
12127 static struct dwo_unit
*
12128 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12129 struct dwp_file
*dwp_file
, const char *comp_dir
,
12130 ULONGEST signature
, int is_debug_types
)
12132 const struct dwp_hash_table
*dwp_htab
=
12133 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12134 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12135 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12136 uint32_t hash
= signature
& mask
;
12137 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12140 struct dwo_unit find_dwo_cu
;
12142 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12143 find_dwo_cu
.signature
= signature
;
12144 slot
= htab_find_slot (is_debug_types
12145 ? dwp_file
->loaded_tus
.get ()
12146 : dwp_file
->loaded_cus
.get (),
12147 &find_dwo_cu
, INSERT
);
12150 return (struct dwo_unit
*) *slot
;
12152 /* Use a for loop so that we don't loop forever on bad debug info. */
12153 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12155 ULONGEST signature_in_table
;
12157 signature_in_table
=
12158 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12159 if (signature_in_table
== signature
)
12161 uint32_t unit_index
=
12162 read_4_bytes (dbfd
,
12163 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12165 if (dwp_file
->version
== 1)
12167 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12168 dwp_file
, unit_index
,
12169 comp_dir
, signature
,
12174 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12175 dwp_file
, unit_index
,
12176 comp_dir
, signature
,
12179 return (struct dwo_unit
*) *slot
;
12181 if (signature_in_table
== 0)
12183 hash
= (hash
+ hash2
) & mask
;
12186 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12187 " [in module %s]"),
12191 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12192 Open the file specified by FILE_NAME and hand it off to BFD for
12193 preliminary analysis. Return a newly initialized bfd *, which
12194 includes a canonicalized copy of FILE_NAME.
12195 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12196 SEARCH_CWD is true if the current directory is to be searched.
12197 It will be searched before debug-file-directory.
12198 If successful, the file is added to the bfd include table of the
12199 objfile's bfd (see gdb_bfd_record_inclusion).
12200 If unable to find/open the file, return NULL.
12201 NOTE: This function is derived from symfile_bfd_open. */
12203 static gdb_bfd_ref_ptr
12204 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12205 const char *file_name
, int is_dwp
, int search_cwd
)
12208 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12209 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12210 to debug_file_directory. */
12211 const char *search_path
;
12212 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12214 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12217 if (*debug_file_directory
!= '\0')
12219 search_path_holder
.reset (concat (".", dirname_separator_string
,
12220 debug_file_directory
,
12222 search_path
= search_path_holder
.get ();
12228 search_path
= debug_file_directory
;
12230 openp_flags flags
= OPF_RETURN_REALPATH
;
12232 flags
|= OPF_SEARCH_IN_PATH
;
12234 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12235 desc
= openp (search_path
, flags
, file_name
,
12236 O_RDONLY
| O_BINARY
, &absolute_name
);
12240 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12242 if (sym_bfd
== NULL
)
12244 bfd_set_cacheable (sym_bfd
.get (), 1);
12246 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12249 /* Success. Record the bfd as having been included by the objfile's bfd.
12250 This is important because things like demangled_names_hash lives in the
12251 objfile's per_bfd space and may have references to things like symbol
12252 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12253 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12258 /* Try to open DWO file FILE_NAME.
12259 COMP_DIR is the DW_AT_comp_dir attribute.
12260 The result is the bfd handle of the file.
12261 If there is a problem finding or opening the file, return NULL.
12262 Upon success, the canonicalized path of the file is stored in the bfd,
12263 same as symfile_bfd_open. */
12265 static gdb_bfd_ref_ptr
12266 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12267 const char *file_name
, const char *comp_dir
)
12269 if (IS_ABSOLUTE_PATH (file_name
))
12270 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12271 0 /*is_dwp*/, 0 /*search_cwd*/);
12273 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12275 if (comp_dir
!= NULL
)
12277 gdb::unique_xmalloc_ptr
<char> path_to_try
12278 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12280 /* NOTE: If comp_dir is a relative path, this will also try the
12281 search path, which seems useful. */
12282 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12283 path_to_try
.get (),
12285 1 /*search_cwd*/));
12290 /* That didn't work, try debug-file-directory, which, despite its name,
12291 is a list of paths. */
12293 if (*debug_file_directory
== '\0')
12296 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12297 0 /*is_dwp*/, 1 /*search_cwd*/);
12300 /* This function is mapped across the sections and remembers the offset and
12301 size of each of the DWO debugging sections we are interested in. */
12304 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12306 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12307 const struct dwop_section_names
*names
= &dwop_section_names
;
12309 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12311 dwo_sections
->abbrev
.s
.section
= sectp
;
12312 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12314 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12316 dwo_sections
->info
.s
.section
= sectp
;
12317 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12319 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12321 dwo_sections
->line
.s
.section
= sectp
;
12322 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12324 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12326 dwo_sections
->loc
.s
.section
= sectp
;
12327 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12329 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12331 dwo_sections
->loclists
.s
.section
= sectp
;
12332 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12334 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12336 dwo_sections
->macinfo
.s
.section
= sectp
;
12337 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12339 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12341 dwo_sections
->macro
.s
.section
= sectp
;
12342 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12344 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12346 dwo_sections
->str
.s
.section
= sectp
;
12347 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12349 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12351 dwo_sections
->str_offsets
.s
.section
= sectp
;
12352 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12354 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12356 struct dwarf2_section_info type_section
;
12358 memset (&type_section
, 0, sizeof (type_section
));
12359 type_section
.s
.section
= sectp
;
12360 type_section
.size
= bfd_section_size (sectp
);
12361 dwo_sections
->types
.push_back (type_section
);
12365 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12366 by PER_CU. This is for the non-DWP case.
12367 The result is NULL if DWO_NAME can't be found. */
12369 static struct dwo_file
*
12370 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12371 const char *comp_dir
)
12373 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12375 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12378 if (dwarf_read_debug
)
12379 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12383 dwo_file_up
dwo_file (new struct dwo_file
);
12384 dwo_file
->dwo_name
= dwo_name
;
12385 dwo_file
->comp_dir
= comp_dir
;
12386 dwo_file
->dbfd
= std::move (dbfd
);
12388 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12389 &dwo_file
->sections
);
12391 create_cus_hash_table (dwarf2_per_objfile
, cu
, *dwo_file
,
12392 dwo_file
->sections
.info
, dwo_file
->cus
);
12394 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12395 dwo_file
->sections
.types
, dwo_file
->tus
);
12397 if (dwarf_read_debug
)
12398 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12400 return dwo_file
.release ();
12403 /* This function is mapped across the sections and remembers the offset and
12404 size of each of the DWP debugging sections common to version 1 and 2 that
12405 we are interested in. */
12408 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12409 void *dwp_file_ptr
)
12411 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12412 const struct dwop_section_names
*names
= &dwop_section_names
;
12413 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12415 /* Record the ELF section number for later lookup: this is what the
12416 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12417 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12418 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12420 /* Look for specific sections that we need. */
12421 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12423 dwp_file
->sections
.str
.s
.section
= sectp
;
12424 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12426 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12428 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12429 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12431 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12433 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12434 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12438 /* This function is mapped across the sections and remembers the offset and
12439 size of each of the DWP version 2 debugging sections that we are interested
12440 in. This is split into a separate function because we don't know if we
12441 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12444 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12446 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12447 const struct dwop_section_names
*names
= &dwop_section_names
;
12448 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12450 /* Record the ELF section number for later lookup: this is what the
12451 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12452 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12453 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12455 /* Look for specific sections that we need. */
12456 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12458 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12459 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12461 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12463 dwp_file
->sections
.info
.s
.section
= sectp
;
12464 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12466 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12468 dwp_file
->sections
.line
.s
.section
= sectp
;
12469 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12471 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12473 dwp_file
->sections
.loc
.s
.section
= sectp
;
12474 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12476 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12478 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12479 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12481 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12483 dwp_file
->sections
.macro
.s
.section
= sectp
;
12484 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12486 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12488 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12489 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12491 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12493 dwp_file
->sections
.types
.s
.section
= sectp
;
12494 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12498 /* Hash function for dwp_file loaded CUs/TUs. */
12501 hash_dwp_loaded_cutus (const void *item
)
12503 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12505 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12506 return dwo_unit
->signature
;
12509 /* Equality function for dwp_file loaded CUs/TUs. */
12512 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12514 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12515 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12517 return dua
->signature
== dub
->signature
;
12520 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12523 allocate_dwp_loaded_cutus_table ()
12525 return htab_up (htab_create_alloc (3,
12526 hash_dwp_loaded_cutus
,
12527 eq_dwp_loaded_cutus
,
12528 NULL
, xcalloc
, xfree
));
12531 /* Try to open DWP file FILE_NAME.
12532 The result is the bfd handle of the file.
12533 If there is a problem finding or opening the file, return NULL.
12534 Upon success, the canonicalized path of the file is stored in the bfd,
12535 same as symfile_bfd_open. */
12537 static gdb_bfd_ref_ptr
12538 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12539 const char *file_name
)
12541 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12543 1 /*search_cwd*/));
12547 /* Work around upstream bug 15652.
12548 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12549 [Whether that's a "bug" is debatable, but it is getting in our way.]
12550 We have no real idea where the dwp file is, because gdb's realpath-ing
12551 of the executable's path may have discarded the needed info.
12552 [IWBN if the dwp file name was recorded in the executable, akin to
12553 .gnu_debuglink, but that doesn't exist yet.]
12554 Strip the directory from FILE_NAME and search again. */
12555 if (*debug_file_directory
!= '\0')
12557 /* Don't implicitly search the current directory here.
12558 If the user wants to search "." to handle this case,
12559 it must be added to debug-file-directory. */
12560 return try_open_dwop_file (dwarf2_per_objfile
,
12561 lbasename (file_name
), 1 /*is_dwp*/,
12568 /* Initialize the use of the DWP file for the current objfile.
12569 By convention the name of the DWP file is ${objfile}.dwp.
12570 The result is NULL if it can't be found. */
12572 static std::unique_ptr
<struct dwp_file
>
12573 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12575 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12577 /* Try to find first .dwp for the binary file before any symbolic links
12580 /* If the objfile is a debug file, find the name of the real binary
12581 file and get the name of dwp file from there. */
12582 std::string dwp_name
;
12583 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12585 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12586 const char *backlink_basename
= lbasename (backlink
->original_name
);
12588 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12591 dwp_name
= objfile
->original_name
;
12593 dwp_name
+= ".dwp";
12595 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12597 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12599 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12600 dwp_name
= objfile_name (objfile
);
12601 dwp_name
+= ".dwp";
12602 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12607 if (dwarf_read_debug
)
12608 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12609 return std::unique_ptr
<dwp_file
> ();
12612 const char *name
= bfd_get_filename (dbfd
.get ());
12613 std::unique_ptr
<struct dwp_file
> dwp_file
12614 (new struct dwp_file (name
, std::move (dbfd
)));
12616 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12617 dwp_file
->elf_sections
=
12618 OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
12619 dwp_file
->num_sections
, asection
*);
12621 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12622 dwarf2_locate_common_dwp_sections
,
12625 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12628 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12631 /* The DWP file version is stored in the hash table. Oh well. */
12632 if (dwp_file
->cus
&& dwp_file
->tus
12633 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12635 /* Technically speaking, we should try to limp along, but this is
12636 pretty bizarre. We use pulongest here because that's the established
12637 portability solution (e.g, we cannot use %u for uint32_t). */
12638 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12639 " TU version %s [in DWP file %s]"),
12640 pulongest (dwp_file
->cus
->version
),
12641 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12645 dwp_file
->version
= dwp_file
->cus
->version
;
12646 else if (dwp_file
->tus
)
12647 dwp_file
->version
= dwp_file
->tus
->version
;
12649 dwp_file
->version
= 2;
12651 if (dwp_file
->version
== 2)
12652 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12653 dwarf2_locate_v2_dwp_sections
,
12656 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12657 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12659 if (dwarf_read_debug
)
12661 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12662 fprintf_unfiltered (gdb_stdlog
,
12663 " %s CUs, %s TUs\n",
12664 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12665 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12671 /* Wrapper around open_and_init_dwp_file, only open it once. */
12673 static struct dwp_file
*
12674 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12676 if (! dwarf2_per_objfile
->per_bfd
->dwp_checked
)
12678 dwarf2_per_objfile
->per_bfd
->dwp_file
12679 = open_and_init_dwp_file (dwarf2_per_objfile
);
12680 dwarf2_per_objfile
->per_bfd
->dwp_checked
= 1;
12682 return dwarf2_per_objfile
->per_bfd
->dwp_file
.get ();
12685 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12686 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12687 or in the DWP file for the objfile, referenced by THIS_UNIT.
12688 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12689 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12691 This is called, for example, when wanting to read a variable with a
12692 complex location. Therefore we don't want to do file i/o for every call.
12693 Therefore we don't want to look for a DWO file on every call.
12694 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12695 then we check if we've already seen DWO_NAME, and only THEN do we check
12698 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12699 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12701 static struct dwo_unit
*
12702 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12703 ULONGEST signature
, int is_debug_types
)
12705 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12706 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12707 const char *kind
= is_debug_types
? "TU" : "CU";
12708 void **dwo_file_slot
;
12709 struct dwo_file
*dwo_file
;
12710 struct dwp_file
*dwp_file
;
12712 /* First see if there's a DWP file.
12713 If we have a DWP file but didn't find the DWO inside it, don't
12714 look for the original DWO file. It makes gdb behave differently
12715 depending on whether one is debugging in the build tree. */
12717 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12718 if (dwp_file
!= NULL
)
12720 const struct dwp_hash_table
*dwp_htab
=
12721 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12723 if (dwp_htab
!= NULL
)
12725 struct dwo_unit
*dwo_cutu
=
12726 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12727 signature
, is_debug_types
);
12729 if (dwo_cutu
!= NULL
)
12731 if (dwarf_read_debug
)
12733 fprintf_unfiltered (gdb_stdlog
,
12734 "Virtual DWO %s %s found: @%s\n",
12735 kind
, hex_string (signature
),
12736 host_address_to_string (dwo_cutu
));
12744 /* No DWP file, look for the DWO file. */
12746 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12747 dwo_name
, comp_dir
);
12748 if (*dwo_file_slot
== NULL
)
12750 /* Read in the file and build a table of the CUs/TUs it contains. */
12751 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12753 /* NOTE: This will be NULL if unable to open the file. */
12754 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12756 if (dwo_file
!= NULL
)
12758 struct dwo_unit
*dwo_cutu
= NULL
;
12760 if (is_debug_types
&& dwo_file
->tus
)
12762 struct dwo_unit find_dwo_cutu
;
12764 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12765 find_dwo_cutu
.signature
= signature
;
12767 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12770 else if (!is_debug_types
&& dwo_file
->cus
)
12772 struct dwo_unit find_dwo_cutu
;
12774 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12775 find_dwo_cutu
.signature
= signature
;
12776 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12780 if (dwo_cutu
!= NULL
)
12782 if (dwarf_read_debug
)
12784 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12785 kind
, dwo_name
, hex_string (signature
),
12786 host_address_to_string (dwo_cutu
));
12793 /* We didn't find it. This could mean a dwo_id mismatch, or
12794 someone deleted the DWO/DWP file, or the search path isn't set up
12795 correctly to find the file. */
12797 if (dwarf_read_debug
)
12799 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12800 kind
, dwo_name
, hex_string (signature
));
12803 /* This is a warning and not a complaint because it can be caused by
12804 pilot error (e.g., user accidentally deleting the DWO). */
12806 /* Print the name of the DWP file if we looked there, helps the user
12807 better diagnose the problem. */
12808 std::string dwp_text
;
12810 if (dwp_file
!= NULL
)
12811 dwp_text
= string_printf (" [in DWP file %s]",
12812 lbasename (dwp_file
->name
));
12814 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12815 " [in module %s]"),
12816 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12817 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12822 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12823 See lookup_dwo_cutu_unit for details. */
12825 static struct dwo_unit
*
12826 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12827 ULONGEST signature
)
12829 gdb_assert (!cu
->per_cu
->is_debug_types
);
12831 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12834 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12835 See lookup_dwo_cutu_unit for details. */
12837 static struct dwo_unit
*
12838 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12840 gdb_assert (cu
->per_cu
->is_debug_types
);
12842 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12844 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12847 /* Traversal function for queue_and_load_all_dwo_tus. */
12850 queue_and_load_dwo_tu (void **slot
, void *info
)
12852 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12853 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12854 ULONGEST signature
= dwo_unit
->signature
;
12855 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12857 if (sig_type
!= NULL
)
12859 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12861 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12862 a real dependency of PER_CU on SIG_TYPE. That is detected later
12863 while processing PER_CU. */
12864 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->language
))
12865 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12866 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12872 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12873 The DWO may have the only definition of the type, though it may not be
12874 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12875 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12878 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12880 struct dwo_unit
*dwo_unit
;
12881 struct dwo_file
*dwo_file
;
12883 gdb_assert (!per_cu
->is_debug_types
);
12884 gdb_assert (per_cu
->cu
!= NULL
);
12885 gdb_assert (get_dwp_file (per_cu
->cu
->per_objfile
) == NULL
);
12887 dwo_unit
= per_cu
->cu
->dwo_unit
;
12888 gdb_assert (dwo_unit
!= NULL
);
12890 dwo_file
= dwo_unit
->dwo_file
;
12891 if (dwo_file
->tus
!= NULL
)
12892 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12896 /* Read in various DIEs. */
12898 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12899 Inherit only the children of the DW_AT_abstract_origin DIE not being
12900 already referenced by DW_AT_abstract_origin from the children of the
12904 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12906 struct die_info
*child_die
;
12907 sect_offset
*offsetp
;
12908 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12909 struct die_info
*origin_die
;
12910 /* Iterator of the ORIGIN_DIE children. */
12911 struct die_info
*origin_child_die
;
12912 struct attribute
*attr
;
12913 struct dwarf2_cu
*origin_cu
;
12914 struct pending
**origin_previous_list_in_scope
;
12916 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12920 /* Note that following die references may follow to a die in a
12924 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12926 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12928 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12929 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12931 if (die
->tag
!= origin_die
->tag
12932 && !(die
->tag
== DW_TAG_inlined_subroutine
12933 && origin_die
->tag
== DW_TAG_subprogram
))
12934 complaint (_("DIE %s and its abstract origin %s have different tags"),
12935 sect_offset_str (die
->sect_off
),
12936 sect_offset_str (origin_die
->sect_off
));
12938 std::vector
<sect_offset
> offsets
;
12940 for (child_die
= die
->child
;
12941 child_die
&& child_die
->tag
;
12942 child_die
= child_die
->sibling
)
12944 struct die_info
*child_origin_die
;
12945 struct dwarf2_cu
*child_origin_cu
;
12947 /* We are trying to process concrete instance entries:
12948 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12949 it's not relevant to our analysis here. i.e. detecting DIEs that are
12950 present in the abstract instance but not referenced in the concrete
12952 if (child_die
->tag
== DW_TAG_call_site
12953 || child_die
->tag
== DW_TAG_GNU_call_site
)
12956 /* For each CHILD_DIE, find the corresponding child of
12957 ORIGIN_DIE. If there is more than one layer of
12958 DW_AT_abstract_origin, follow them all; there shouldn't be,
12959 but GCC versions at least through 4.4 generate this (GCC PR
12961 child_origin_die
= child_die
;
12962 child_origin_cu
= cu
;
12965 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12969 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12973 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12974 counterpart may exist. */
12975 if (child_origin_die
!= child_die
)
12977 if (child_die
->tag
!= child_origin_die
->tag
12978 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12979 && child_origin_die
->tag
== DW_TAG_subprogram
))
12980 complaint (_("Child DIE %s and its abstract origin %s have "
12982 sect_offset_str (child_die
->sect_off
),
12983 sect_offset_str (child_origin_die
->sect_off
));
12984 if (child_origin_die
->parent
!= origin_die
)
12985 complaint (_("Child DIE %s and its abstract origin %s have "
12986 "different parents"),
12987 sect_offset_str (child_die
->sect_off
),
12988 sect_offset_str (child_origin_die
->sect_off
));
12990 offsets
.push_back (child_origin_die
->sect_off
);
12993 std::sort (offsets
.begin (), offsets
.end ());
12994 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12995 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12996 if (offsetp
[-1] == *offsetp
)
12997 complaint (_("Multiple children of DIE %s refer "
12998 "to DIE %s as their abstract origin"),
12999 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13001 offsetp
= offsets
.data ();
13002 origin_child_die
= origin_die
->child
;
13003 while (origin_child_die
&& origin_child_die
->tag
)
13005 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13006 while (offsetp
< offsets_end
13007 && *offsetp
< origin_child_die
->sect_off
)
13009 if (offsetp
>= offsets_end
13010 || *offsetp
> origin_child_die
->sect_off
)
13012 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13013 Check whether we're already processing ORIGIN_CHILD_DIE.
13014 This can happen with mutually referenced abstract_origins.
13016 if (!origin_child_die
->in_process
)
13017 process_die (origin_child_die
, origin_cu
);
13019 origin_child_die
= origin_child_die
->sibling
;
13021 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13023 if (cu
!= origin_cu
)
13024 compute_delayed_physnames (origin_cu
);
13028 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13030 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13031 struct gdbarch
*gdbarch
= objfile
->arch ();
13032 struct context_stack
*newobj
;
13035 struct die_info
*child_die
;
13036 struct attribute
*attr
, *call_line
, *call_file
;
13038 CORE_ADDR baseaddr
;
13039 struct block
*block
;
13040 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13041 std::vector
<struct symbol
*> template_args
;
13042 struct template_symbol
*templ_func
= NULL
;
13046 /* If we do not have call site information, we can't show the
13047 caller of this inlined function. That's too confusing, so
13048 only use the scope for local variables. */
13049 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13050 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13051 if (call_line
== NULL
|| call_file
== NULL
)
13053 read_lexical_block_scope (die
, cu
);
13058 baseaddr
= objfile
->text_section_offset ();
13060 name
= dwarf2_name (die
, cu
);
13062 /* Ignore functions with missing or empty names. These are actually
13063 illegal according to the DWARF standard. */
13066 complaint (_("missing name for subprogram DIE at %s"),
13067 sect_offset_str (die
->sect_off
));
13071 /* Ignore functions with missing or invalid low and high pc attributes. */
13072 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13073 <= PC_BOUNDS_INVALID
)
13075 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13076 if (!attr
|| !DW_UNSND (attr
))
13077 complaint (_("cannot get low and high bounds "
13078 "for subprogram DIE at %s"),
13079 sect_offset_str (die
->sect_off
));
13083 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13084 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13086 /* If we have any template arguments, then we must allocate a
13087 different sort of symbol. */
13088 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13090 if (child_die
->tag
== DW_TAG_template_type_param
13091 || child_die
->tag
== DW_TAG_template_value_param
)
13093 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13094 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13099 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13100 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13101 (struct symbol
*) templ_func
);
13103 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13104 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13107 /* If there is a location expression for DW_AT_frame_base, record
13109 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13110 if (attr
!= nullptr)
13111 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13113 /* If there is a location for the static link, record it. */
13114 newobj
->static_link
= NULL
;
13115 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13116 if (attr
!= nullptr)
13118 newobj
->static_link
13119 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13120 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13124 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13126 if (die
->child
!= NULL
)
13128 child_die
= die
->child
;
13129 while (child_die
&& child_die
->tag
)
13131 if (child_die
->tag
== DW_TAG_template_type_param
13132 || child_die
->tag
== DW_TAG_template_value_param
)
13134 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13137 template_args
.push_back (arg
);
13140 process_die (child_die
, cu
);
13141 child_die
= child_die
->sibling
;
13145 inherit_abstract_dies (die
, cu
);
13147 /* If we have a DW_AT_specification, we might need to import using
13148 directives from the context of the specification DIE. See the
13149 comment in determine_prefix. */
13150 if (cu
->language
== language_cplus
13151 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13153 struct dwarf2_cu
*spec_cu
= cu
;
13154 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13158 child_die
= spec_die
->child
;
13159 while (child_die
&& child_die
->tag
)
13161 if (child_die
->tag
== DW_TAG_imported_module
)
13162 process_die (child_die
, spec_cu
);
13163 child_die
= child_die
->sibling
;
13166 /* In some cases, GCC generates specification DIEs that
13167 themselves contain DW_AT_specification attributes. */
13168 spec_die
= die_specification (spec_die
, &spec_cu
);
13172 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13173 /* Make a block for the local symbols within. */
13174 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13175 cstk
.static_link
, lowpc
, highpc
);
13177 /* For C++, set the block's scope. */
13178 if ((cu
->language
== language_cplus
13179 || cu
->language
== language_fortran
13180 || cu
->language
== language_d
13181 || cu
->language
== language_rust
)
13182 && cu
->processing_has_namespace_info
)
13183 block_set_scope (block
, determine_prefix (die
, cu
),
13184 &objfile
->objfile_obstack
);
13186 /* If we have address ranges, record them. */
13187 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13189 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13191 /* Attach template arguments to function. */
13192 if (!template_args
.empty ())
13194 gdb_assert (templ_func
!= NULL
);
13196 templ_func
->n_template_arguments
= template_args
.size ();
13197 templ_func
->template_arguments
13198 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13199 templ_func
->n_template_arguments
);
13200 memcpy (templ_func
->template_arguments
,
13201 template_args
.data (),
13202 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13204 /* Make sure that the symtab is set on the new symbols. Even
13205 though they don't appear in this symtab directly, other parts
13206 of gdb assume that symbols do, and this is reasonably
13208 for (symbol
*sym
: template_args
)
13209 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13212 /* In C++, we can have functions nested inside functions (e.g., when
13213 a function declares a class that has methods). This means that
13214 when we finish processing a function scope, we may need to go
13215 back to building a containing block's symbol lists. */
13216 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13217 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13219 /* If we've finished processing a top-level function, subsequent
13220 symbols go in the file symbol list. */
13221 if (cu
->get_builder ()->outermost_context_p ())
13222 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13225 /* Process all the DIES contained within a lexical block scope. Start
13226 a new scope, process the dies, and then close the scope. */
13229 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13231 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13232 struct gdbarch
*gdbarch
= objfile
->arch ();
13233 CORE_ADDR lowpc
, highpc
;
13234 struct die_info
*child_die
;
13235 CORE_ADDR baseaddr
;
13237 baseaddr
= objfile
->text_section_offset ();
13239 /* Ignore blocks with missing or invalid low and high pc attributes. */
13240 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13241 as multiple lexical blocks? Handling children in a sane way would
13242 be nasty. Might be easier to properly extend generic blocks to
13243 describe ranges. */
13244 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13246 case PC_BOUNDS_NOT_PRESENT
:
13247 /* DW_TAG_lexical_block has no attributes, process its children as if
13248 there was no wrapping by that DW_TAG_lexical_block.
13249 GCC does no longer produces such DWARF since GCC r224161. */
13250 for (child_die
= die
->child
;
13251 child_die
!= NULL
&& child_die
->tag
;
13252 child_die
= child_die
->sibling
)
13254 /* We might already be processing this DIE. This can happen
13255 in an unusual circumstance -- where a subroutine A
13256 appears lexically in another subroutine B, but A actually
13257 inlines B. The recursion is broken here, rather than in
13258 inherit_abstract_dies, because it seems better to simply
13259 drop concrete children here. */
13260 if (!child_die
->in_process
)
13261 process_die (child_die
, cu
);
13264 case PC_BOUNDS_INVALID
:
13267 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13268 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13270 cu
->get_builder ()->push_context (0, lowpc
);
13271 if (die
->child
!= NULL
)
13273 child_die
= die
->child
;
13274 while (child_die
&& child_die
->tag
)
13276 process_die (child_die
, cu
);
13277 child_die
= child_die
->sibling
;
13280 inherit_abstract_dies (die
, cu
);
13281 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13283 if (*cu
->get_builder ()->get_local_symbols () != NULL
13284 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13286 struct block
*block
13287 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13288 cstk
.start_addr
, highpc
);
13290 /* Note that recording ranges after traversing children, as we
13291 do here, means that recording a parent's ranges entails
13292 walking across all its children's ranges as they appear in
13293 the address map, which is quadratic behavior.
13295 It would be nicer to record the parent's ranges before
13296 traversing its children, simply overriding whatever you find
13297 there. But since we don't even decide whether to create a
13298 block until after we've traversed its children, that's hard
13300 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13302 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13303 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13306 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13309 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13311 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13312 struct objfile
*objfile
= per_objfile
->objfile
;
13313 struct gdbarch
*gdbarch
= objfile
->arch ();
13314 CORE_ADDR pc
, baseaddr
;
13315 struct attribute
*attr
;
13316 struct call_site
*call_site
, call_site_local
;
13319 struct die_info
*child_die
;
13321 baseaddr
= objfile
->text_section_offset ();
13323 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13326 /* This was a pre-DWARF-5 GNU extension alias
13327 for DW_AT_call_return_pc. */
13328 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13332 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13333 "DIE %s [in module %s]"),
13334 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13337 pc
= attr
->value_as_address () + baseaddr
;
13338 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13340 if (cu
->call_site_htab
== NULL
)
13341 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13342 NULL
, &objfile
->objfile_obstack
,
13343 hashtab_obstack_allocate
, NULL
);
13344 call_site_local
.pc
= pc
;
13345 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13348 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13349 "DIE %s [in module %s]"),
13350 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13351 objfile_name (objfile
));
13355 /* Count parameters at the caller. */
13358 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13359 child_die
= child_die
->sibling
)
13361 if (child_die
->tag
!= DW_TAG_call_site_parameter
13362 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13364 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13365 "DW_TAG_call_site child DIE %s [in module %s]"),
13366 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13367 objfile_name (objfile
));
13375 = ((struct call_site
*)
13376 obstack_alloc (&objfile
->objfile_obstack
,
13377 sizeof (*call_site
)
13378 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13380 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13381 call_site
->pc
= pc
;
13383 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13384 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13386 struct die_info
*func_die
;
13388 /* Skip also over DW_TAG_inlined_subroutine. */
13389 for (func_die
= die
->parent
;
13390 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13391 && func_die
->tag
!= DW_TAG_subroutine_type
;
13392 func_die
= func_die
->parent
);
13394 /* DW_AT_call_all_calls is a superset
13395 of DW_AT_call_all_tail_calls. */
13397 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13398 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13399 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13400 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13402 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13403 not complete. But keep CALL_SITE for look ups via call_site_htab,
13404 both the initial caller containing the real return address PC and
13405 the final callee containing the current PC of a chain of tail
13406 calls do not need to have the tail call list complete. But any
13407 function candidate for a virtual tail call frame searched via
13408 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13409 determined unambiguously. */
13413 struct type
*func_type
= NULL
;
13416 func_type
= get_die_type (func_die
, cu
);
13417 if (func_type
!= NULL
)
13419 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13421 /* Enlist this call site to the function. */
13422 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13423 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13426 complaint (_("Cannot find function owning DW_TAG_call_site "
13427 "DIE %s [in module %s]"),
13428 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13432 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13434 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13436 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13439 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13440 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13442 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13443 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13444 /* Keep NULL DWARF_BLOCK. */;
13445 else if (attr
->form_is_block ())
13447 struct dwarf2_locexpr_baton
*dlbaton
;
13449 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13450 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13451 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13452 dlbaton
->per_objfile
= per_objfile
;
13453 dlbaton
->per_cu
= cu
->per_cu
;
13455 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13457 else if (attr
->form_is_ref ())
13459 struct dwarf2_cu
*target_cu
= cu
;
13460 struct die_info
*target_die
;
13462 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13463 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13464 if (die_is_declaration (target_die
, target_cu
))
13466 const char *target_physname
;
13468 /* Prefer the mangled name; otherwise compute the demangled one. */
13469 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13470 if (target_physname
== NULL
)
13471 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13472 if (target_physname
== NULL
)
13473 complaint (_("DW_AT_call_target target DIE has invalid "
13474 "physname, for referencing DIE %s [in module %s]"),
13475 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13477 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13483 /* DW_AT_entry_pc should be preferred. */
13484 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13485 <= PC_BOUNDS_INVALID
)
13486 complaint (_("DW_AT_call_target target DIE has invalid "
13487 "low pc, for referencing DIE %s [in module %s]"),
13488 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13491 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13492 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13497 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13498 "block nor reference, for DIE %s [in module %s]"),
13499 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13501 call_site
->per_cu
= cu
->per_cu
;
13502 call_site
->per_objfile
= per_objfile
;
13504 for (child_die
= die
->child
;
13505 child_die
&& child_die
->tag
;
13506 child_die
= child_die
->sibling
)
13508 struct call_site_parameter
*parameter
;
13509 struct attribute
*loc
, *origin
;
13511 if (child_die
->tag
!= DW_TAG_call_site_parameter
13512 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13514 /* Already printed the complaint above. */
13518 gdb_assert (call_site
->parameter_count
< nparams
);
13519 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13521 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13522 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13523 register is contained in DW_AT_call_value. */
13525 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13526 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13527 if (origin
== NULL
)
13529 /* This was a pre-DWARF-5 GNU extension alias
13530 for DW_AT_call_parameter. */
13531 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13533 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13535 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13537 sect_offset sect_off
= origin
->get_ref_die_offset ();
13538 if (!cu
->header
.offset_in_cu_p (sect_off
))
13540 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13541 binding can be done only inside one CU. Such referenced DIE
13542 therefore cannot be even moved to DW_TAG_partial_unit. */
13543 complaint (_("DW_AT_call_parameter offset is not in CU for "
13544 "DW_TAG_call_site child DIE %s [in module %s]"),
13545 sect_offset_str (child_die
->sect_off
),
13546 objfile_name (objfile
));
13549 parameter
->u
.param_cu_off
13550 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13552 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13554 complaint (_("No DW_FORM_block* DW_AT_location for "
13555 "DW_TAG_call_site child DIE %s [in module %s]"),
13556 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13561 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13562 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13563 if (parameter
->u
.dwarf_reg
!= -1)
13564 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13565 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13566 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13567 ¶meter
->u
.fb_offset
))
13568 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13571 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13572 "for DW_FORM_block* DW_AT_location is supported for "
13573 "DW_TAG_call_site child DIE %s "
13575 sect_offset_str (child_die
->sect_off
),
13576 objfile_name (objfile
));
13581 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13583 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13584 if (attr
== NULL
|| !attr
->form_is_block ())
13586 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13587 "DW_TAG_call_site child DIE %s [in module %s]"),
13588 sect_offset_str (child_die
->sect_off
),
13589 objfile_name (objfile
));
13592 parameter
->value
= DW_BLOCK (attr
)->data
;
13593 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13595 /* Parameters are not pre-cleared by memset above. */
13596 parameter
->data_value
= NULL
;
13597 parameter
->data_value_size
= 0;
13598 call_site
->parameter_count
++;
13600 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13602 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13603 if (attr
!= nullptr)
13605 if (!attr
->form_is_block ())
13606 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13607 "DW_TAG_call_site child DIE %s [in module %s]"),
13608 sect_offset_str (child_die
->sect_off
),
13609 objfile_name (objfile
));
13612 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13613 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13619 /* Helper function for read_variable. If DIE represents a virtual
13620 table, then return the type of the concrete object that is
13621 associated with the virtual table. Otherwise, return NULL. */
13623 static struct type
*
13624 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13626 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13630 /* Find the type DIE. */
13631 struct die_info
*type_die
= NULL
;
13632 struct dwarf2_cu
*type_cu
= cu
;
13634 if (attr
->form_is_ref ())
13635 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13636 if (type_die
== NULL
)
13639 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13641 return die_containing_type (type_die
, type_cu
);
13644 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13647 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13649 struct rust_vtable_symbol
*storage
= NULL
;
13651 if (cu
->language
== language_rust
)
13653 struct type
*containing_type
= rust_containing_type (die
, cu
);
13655 if (containing_type
!= NULL
)
13657 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13659 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13660 storage
->concrete_type
= containing_type
;
13661 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13665 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13666 struct attribute
*abstract_origin
13667 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13668 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13669 if (res
== NULL
&& loc
&& abstract_origin
)
13671 /* We have a variable without a name, but with a location and an abstract
13672 origin. This may be a concrete instance of an abstract variable
13673 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13675 struct dwarf2_cu
*origin_cu
= cu
;
13676 struct die_info
*origin_die
13677 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13678 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13679 per_objfile
->per_bfd
->abstract_to_concrete
13680 [origin_die
->sect_off
].push_back (die
->sect_off
);
13684 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13685 reading .debug_rnglists.
13686 Callback's type should be:
13687 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13688 Return true if the attributes are present and valid, otherwise,
13691 template <typename Callback
>
13693 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13694 Callback
&&callback
)
13696 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
13697 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13698 bfd
*obfd
= objfile
->obfd
;
13699 /* Base address selection entry. */
13700 gdb::optional
<CORE_ADDR
> base
;
13701 const gdb_byte
*buffer
;
13702 CORE_ADDR baseaddr
;
13703 bool overflow
= false;
13705 base
= cu
->base_address
;
13707 dwarf2_per_objfile
->per_bfd
->rnglists
.read (objfile
);
13708 if (offset
>= dwarf2_per_objfile
->per_bfd
->rnglists
.size
)
13710 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13714 buffer
= dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13716 baseaddr
= objfile
->text_section_offset ();
13720 /* Initialize it due to a false compiler warning. */
13721 CORE_ADDR range_beginning
= 0, range_end
= 0;
13722 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
13723 + dwarf2_per_objfile
->per_bfd
->rnglists
.size
);
13724 unsigned int bytes_read
;
13726 if (buffer
== buf_end
)
13731 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13734 case DW_RLE_end_of_list
:
13736 case DW_RLE_base_address
:
13737 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13742 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13743 buffer
+= bytes_read
;
13745 case DW_RLE_start_length
:
13746 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13751 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13753 buffer
+= bytes_read
;
13754 range_end
= (range_beginning
13755 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13756 buffer
+= bytes_read
;
13757 if (buffer
> buf_end
)
13763 case DW_RLE_offset_pair
:
13764 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13765 buffer
+= bytes_read
;
13766 if (buffer
> buf_end
)
13771 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13772 buffer
+= bytes_read
;
13773 if (buffer
> buf_end
)
13779 case DW_RLE_start_end
:
13780 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13785 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13787 buffer
+= bytes_read
;
13788 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13789 buffer
+= bytes_read
;
13792 complaint (_("Invalid .debug_rnglists data (no base address)"));
13795 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13797 if (rlet
== DW_RLE_base_address
)
13800 if (!base
.has_value ())
13802 /* We have no valid base address for the ranges
13804 complaint (_("Invalid .debug_rnglists data (no base address)"));
13808 if (range_beginning
> range_end
)
13810 /* Inverted range entries are invalid. */
13811 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13815 /* Empty range entries have no effect. */
13816 if (range_beginning
== range_end
)
13819 range_beginning
+= *base
;
13820 range_end
+= *base
;
13822 /* A not-uncommon case of bad debug info.
13823 Don't pollute the addrmap with bad data. */
13824 if (range_beginning
+ baseaddr
== 0
13825 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
13827 complaint (_(".debug_rnglists entry has start address of zero"
13828 " [in module %s]"), objfile_name (objfile
));
13832 callback (range_beginning
, range_end
);
13837 complaint (_("Offset %d is not terminated "
13838 "for DW_AT_ranges attribute"),
13846 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13847 Callback's type should be:
13848 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13849 Return 1 if the attributes are present and valid, otherwise, return 0. */
13851 template <typename Callback
>
13853 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13854 Callback
&&callback
)
13856 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13857 struct objfile
*objfile
= per_objfile
->objfile
;
13858 struct comp_unit_head
*cu_header
= &cu
->header
;
13859 bfd
*obfd
= objfile
->obfd
;
13860 unsigned int addr_size
= cu_header
->addr_size
;
13861 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13862 /* Base address selection entry. */
13863 gdb::optional
<CORE_ADDR
> base
;
13864 unsigned int dummy
;
13865 const gdb_byte
*buffer
;
13866 CORE_ADDR baseaddr
;
13868 if (cu_header
->version
>= 5)
13869 return dwarf2_rnglists_process (offset
, cu
, callback
);
13871 base
= cu
->base_address
;
13873 per_objfile
->per_bfd
->ranges
.read (objfile
);
13874 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13876 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13880 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13882 baseaddr
= objfile
->text_section_offset ();
13886 CORE_ADDR range_beginning
, range_end
;
13888 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13889 buffer
+= addr_size
;
13890 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13891 buffer
+= addr_size
;
13892 offset
+= 2 * addr_size
;
13894 /* An end of list marker is a pair of zero addresses. */
13895 if (range_beginning
== 0 && range_end
== 0)
13896 /* Found the end of list entry. */
13899 /* Each base address selection entry is a pair of 2 values.
13900 The first is the largest possible address, the second is
13901 the base address. Check for a base address here. */
13902 if ((range_beginning
& mask
) == mask
)
13904 /* If we found the largest possible address, then we already
13905 have the base address in range_end. */
13910 if (!base
.has_value ())
13912 /* We have no valid base address for the ranges
13914 complaint (_("Invalid .debug_ranges data (no base address)"));
13918 if (range_beginning
> range_end
)
13920 /* Inverted range entries are invalid. */
13921 complaint (_("Invalid .debug_ranges data (inverted range)"));
13925 /* Empty range entries have no effect. */
13926 if (range_beginning
== range_end
)
13929 range_beginning
+= *base
;
13930 range_end
+= *base
;
13932 /* A not-uncommon case of bad debug info.
13933 Don't pollute the addrmap with bad data. */
13934 if (range_beginning
+ baseaddr
== 0
13935 && !per_objfile
->per_bfd
->has_section_at_zero
)
13937 complaint (_(".debug_ranges entry has start address of zero"
13938 " [in module %s]"), objfile_name (objfile
));
13942 callback (range_beginning
, range_end
);
13948 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13949 Return 1 if the attributes are present and valid, otherwise, return 0.
13950 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13953 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13954 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13955 dwarf2_psymtab
*ranges_pst
)
13957 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13958 struct gdbarch
*gdbarch
= objfile
->arch ();
13959 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13962 CORE_ADDR high
= 0;
13965 retval
= dwarf2_ranges_process (offset
, cu
,
13966 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13968 if (ranges_pst
!= NULL
)
13973 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13974 range_beginning
+ baseaddr
)
13976 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13977 range_end
+ baseaddr
)
13979 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13980 lowpc
, highpc
- 1, ranges_pst
);
13983 /* FIXME: This is recording everything as a low-high
13984 segment of consecutive addresses. We should have a
13985 data structure for discontiguous block ranges
13989 low
= range_beginning
;
13995 if (range_beginning
< low
)
13996 low
= range_beginning
;
13997 if (range_end
> high
)
14005 /* If the first entry is an end-of-list marker, the range
14006 describes an empty scope, i.e. no instructions. */
14012 *high_return
= high
;
14016 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14017 definition for the return value. *LOWPC and *HIGHPC are set iff
14018 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14020 static enum pc_bounds_kind
14021 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14022 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14023 dwarf2_psymtab
*pst
)
14025 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
14026 struct attribute
*attr
;
14027 struct attribute
*attr_high
;
14029 CORE_ADDR high
= 0;
14030 enum pc_bounds_kind ret
;
14032 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14035 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14036 if (attr
!= nullptr)
14038 low
= attr
->value_as_address ();
14039 high
= attr_high
->value_as_address ();
14040 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14044 /* Found high w/o low attribute. */
14045 return PC_BOUNDS_INVALID
;
14047 /* Found consecutive range of addresses. */
14048 ret
= PC_BOUNDS_HIGH_LOW
;
14052 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14055 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14056 We take advantage of the fact that DW_AT_ranges does not appear
14057 in DW_TAG_compile_unit of DWO files. */
14058 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14059 unsigned int ranges_offset
= (DW_UNSND (attr
)
14060 + (need_ranges_base
14064 /* Value of the DW_AT_ranges attribute is the offset in the
14065 .debug_ranges section. */
14066 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14067 return PC_BOUNDS_INVALID
;
14068 /* Found discontinuous range of addresses. */
14069 ret
= PC_BOUNDS_RANGES
;
14072 return PC_BOUNDS_NOT_PRESENT
;
14075 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14077 return PC_BOUNDS_INVALID
;
14079 /* When using the GNU linker, .gnu.linkonce. sections are used to
14080 eliminate duplicate copies of functions and vtables and such.
14081 The linker will arbitrarily choose one and discard the others.
14082 The AT_*_pc values for such functions refer to local labels in
14083 these sections. If the section from that file was discarded, the
14084 labels are not in the output, so the relocs get a value of 0.
14085 If this is a discarded function, mark the pc bounds as invalid,
14086 so that GDB will ignore it. */
14087 if (low
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
14088 return PC_BOUNDS_INVALID
;
14096 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14097 its low and high PC addresses. Do nothing if these addresses could not
14098 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14099 and HIGHPC to the high address if greater than HIGHPC. */
14102 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14103 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14104 struct dwarf2_cu
*cu
)
14106 CORE_ADDR low
, high
;
14107 struct die_info
*child
= die
->child
;
14109 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14111 *lowpc
= std::min (*lowpc
, low
);
14112 *highpc
= std::max (*highpc
, high
);
14115 /* If the language does not allow nested subprograms (either inside
14116 subprograms or lexical blocks), we're done. */
14117 if (cu
->language
!= language_ada
)
14120 /* Check all the children of the given DIE. If it contains nested
14121 subprograms, then check their pc bounds. Likewise, we need to
14122 check lexical blocks as well, as they may also contain subprogram
14124 while (child
&& child
->tag
)
14126 if (child
->tag
== DW_TAG_subprogram
14127 || child
->tag
== DW_TAG_lexical_block
)
14128 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14129 child
= child
->sibling
;
14133 /* Get the low and high pc's represented by the scope DIE, and store
14134 them in *LOWPC and *HIGHPC. If the correct values can't be
14135 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14138 get_scope_pc_bounds (struct die_info
*die
,
14139 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14140 struct dwarf2_cu
*cu
)
14142 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14143 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14144 CORE_ADDR current_low
, current_high
;
14146 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14147 >= PC_BOUNDS_RANGES
)
14149 best_low
= current_low
;
14150 best_high
= current_high
;
14154 struct die_info
*child
= die
->child
;
14156 while (child
&& child
->tag
)
14158 switch (child
->tag
) {
14159 case DW_TAG_subprogram
:
14160 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14162 case DW_TAG_namespace
:
14163 case DW_TAG_module
:
14164 /* FIXME: carlton/2004-01-16: Should we do this for
14165 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14166 that current GCC's always emit the DIEs corresponding
14167 to definitions of methods of classes as children of a
14168 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14169 the DIEs giving the declarations, which could be
14170 anywhere). But I don't see any reason why the
14171 standards says that they have to be there. */
14172 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14174 if (current_low
!= ((CORE_ADDR
) -1))
14176 best_low
= std::min (best_low
, current_low
);
14177 best_high
= std::max (best_high
, current_high
);
14185 child
= child
->sibling
;
14190 *highpc
= best_high
;
14193 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14197 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14198 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14200 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14201 struct gdbarch
*gdbarch
= objfile
->arch ();
14202 struct attribute
*attr
;
14203 struct attribute
*attr_high
;
14205 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14208 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14209 if (attr
!= nullptr)
14211 CORE_ADDR low
= attr
->value_as_address ();
14212 CORE_ADDR high
= attr_high
->value_as_address ();
14214 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14217 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14218 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14219 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14223 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14224 if (attr
!= nullptr)
14226 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14227 We take advantage of the fact that DW_AT_ranges does not appear
14228 in DW_TAG_compile_unit of DWO files. */
14229 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14231 /* The value of the DW_AT_ranges attribute is the offset of the
14232 address range list in the .debug_ranges section. */
14233 unsigned long offset
= (DW_UNSND (attr
)
14234 + (need_ranges_base
? cu
->ranges_base
: 0));
14236 std::vector
<blockrange
> blockvec
;
14237 dwarf2_ranges_process (offset
, cu
,
14238 [&] (CORE_ADDR start
, CORE_ADDR end
)
14242 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14243 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14244 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14245 blockvec
.emplace_back (start
, end
);
14248 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14252 /* Check whether the producer field indicates either of GCC < 4.6, or the
14253 Intel C/C++ compiler, and cache the result in CU. */
14256 check_producer (struct dwarf2_cu
*cu
)
14260 if (cu
->producer
== NULL
)
14262 /* For unknown compilers expect their behavior is DWARF version
14265 GCC started to support .debug_types sections by -gdwarf-4 since
14266 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14267 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14268 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14269 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14271 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14273 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14274 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14276 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14278 cu
->producer_is_icc
= true;
14279 cu
->producer_is_icc_lt_14
= major
< 14;
14281 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14282 cu
->producer_is_codewarrior
= true;
14285 /* For other non-GCC compilers, expect their behavior is DWARF version
14289 cu
->checked_producer
= true;
14292 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14293 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14294 during 4.6.0 experimental. */
14297 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14299 if (!cu
->checked_producer
)
14300 check_producer (cu
);
14302 return cu
->producer_is_gxx_lt_4_6
;
14306 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14307 with incorrect is_stmt attributes. */
14310 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14312 if (!cu
->checked_producer
)
14313 check_producer (cu
);
14315 return cu
->producer_is_codewarrior
;
14318 /* Return the default accessibility type if it is not overridden by
14319 DW_AT_accessibility. */
14321 static enum dwarf_access_attribute
14322 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14324 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14326 /* The default DWARF 2 accessibility for members is public, the default
14327 accessibility for inheritance is private. */
14329 if (die
->tag
!= DW_TAG_inheritance
)
14330 return DW_ACCESS_public
;
14332 return DW_ACCESS_private
;
14336 /* DWARF 3+ defines the default accessibility a different way. The same
14337 rules apply now for DW_TAG_inheritance as for the members and it only
14338 depends on the container kind. */
14340 if (die
->parent
->tag
== DW_TAG_class_type
)
14341 return DW_ACCESS_private
;
14343 return DW_ACCESS_public
;
14347 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14348 offset. If the attribute was not found return 0, otherwise return
14349 1. If it was found but could not properly be handled, set *OFFSET
14353 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14356 struct attribute
*attr
;
14358 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14363 /* Note that we do not check for a section offset first here.
14364 This is because DW_AT_data_member_location is new in DWARF 4,
14365 so if we see it, we can assume that a constant form is really
14366 a constant and not a section offset. */
14367 if (attr
->form_is_constant ())
14368 *offset
= attr
->constant_value (0);
14369 else if (attr
->form_is_section_offset ())
14370 dwarf2_complex_location_expr_complaint ();
14371 else if (attr
->form_is_block ())
14372 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14374 dwarf2_complex_location_expr_complaint ();
14382 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14385 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14386 struct field
*field
)
14388 struct attribute
*attr
;
14390 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14393 if (attr
->form_is_constant ())
14395 LONGEST offset
= attr
->constant_value (0);
14396 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14398 else if (attr
->form_is_section_offset ())
14399 dwarf2_complex_location_expr_complaint ();
14400 else if (attr
->form_is_block ())
14403 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14405 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14408 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14409 struct objfile
*objfile
= per_objfile
->objfile
;
14410 struct dwarf2_locexpr_baton
*dlbaton
14411 = XOBNEW (&objfile
->objfile_obstack
,
14412 struct dwarf2_locexpr_baton
);
14413 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14414 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14415 /* When using this baton, we want to compute the address
14416 of the field, not the value. This is why
14417 is_reference is set to false here. */
14418 dlbaton
->is_reference
= false;
14419 dlbaton
->per_objfile
= per_objfile
;
14420 dlbaton
->per_cu
= cu
->per_cu
;
14422 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14426 dwarf2_complex_location_expr_complaint ();
14430 /* Add an aggregate field to the field list. */
14433 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14434 struct dwarf2_cu
*cu
)
14436 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14437 struct gdbarch
*gdbarch
= objfile
->arch ();
14438 struct nextfield
*new_field
;
14439 struct attribute
*attr
;
14441 const char *fieldname
= "";
14443 if (die
->tag
== DW_TAG_inheritance
)
14445 fip
->baseclasses
.emplace_back ();
14446 new_field
= &fip
->baseclasses
.back ();
14450 fip
->fields
.emplace_back ();
14451 new_field
= &fip
->fields
.back ();
14454 new_field
->offset
= die
->sect_off
;
14456 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14457 if (attr
!= nullptr)
14458 new_field
->accessibility
= DW_UNSND (attr
);
14460 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14461 if (new_field
->accessibility
!= DW_ACCESS_public
)
14462 fip
->non_public_fields
= 1;
14464 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14465 if (attr
!= nullptr)
14466 new_field
->virtuality
= DW_UNSND (attr
);
14468 new_field
->virtuality
= DW_VIRTUALITY_none
;
14470 fp
= &new_field
->field
;
14472 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14474 /* Data member other than a C++ static data member. */
14476 /* Get type of field. */
14477 fp
->type
= die_type (die
, cu
);
14479 SET_FIELD_BITPOS (*fp
, 0);
14481 /* Get bit size of field (zero if none). */
14482 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14483 if (attr
!= nullptr)
14485 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14489 FIELD_BITSIZE (*fp
) = 0;
14492 /* Get bit offset of field. */
14493 handle_data_member_location (die
, cu
, fp
);
14494 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14495 if (attr
!= nullptr)
14497 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14499 /* For big endian bits, the DW_AT_bit_offset gives the
14500 additional bit offset from the MSB of the containing
14501 anonymous object to the MSB of the field. We don't
14502 have to do anything special since we don't need to
14503 know the size of the anonymous object. */
14504 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14508 /* For little endian bits, compute the bit offset to the
14509 MSB of the anonymous object, subtract off the number of
14510 bits from the MSB of the field to the MSB of the
14511 object, and then subtract off the number of bits of
14512 the field itself. The result is the bit offset of
14513 the LSB of the field. */
14514 int anonymous_size
;
14515 int bit_offset
= DW_UNSND (attr
);
14517 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14518 if (attr
!= nullptr)
14520 /* The size of the anonymous object containing
14521 the bit field is explicit, so use the
14522 indicated size (in bytes). */
14523 anonymous_size
= DW_UNSND (attr
);
14527 /* The size of the anonymous object containing
14528 the bit field must be inferred from the type
14529 attribute of the data member containing the
14531 anonymous_size
= TYPE_LENGTH (fp
->type
);
14533 SET_FIELD_BITPOS (*fp
,
14534 (FIELD_BITPOS (*fp
)
14535 + anonymous_size
* bits_per_byte
14536 - bit_offset
- FIELD_BITSIZE (*fp
)));
14539 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14541 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14542 + attr
->constant_value (0)));
14544 /* Get name of field. */
14545 fieldname
= dwarf2_name (die
, cu
);
14546 if (fieldname
== NULL
)
14549 /* The name is already allocated along with this objfile, so we don't
14550 need to duplicate it for the type. */
14551 fp
->name
= fieldname
;
14553 /* Change accessibility for artificial fields (e.g. virtual table
14554 pointer or virtual base class pointer) to private. */
14555 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14557 FIELD_ARTIFICIAL (*fp
) = 1;
14558 new_field
->accessibility
= DW_ACCESS_private
;
14559 fip
->non_public_fields
= 1;
14562 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14564 /* C++ static member. */
14566 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14567 is a declaration, but all versions of G++ as of this writing
14568 (so through at least 3.2.1) incorrectly generate
14569 DW_TAG_variable tags. */
14571 const char *physname
;
14573 /* Get name of field. */
14574 fieldname
= dwarf2_name (die
, cu
);
14575 if (fieldname
== NULL
)
14578 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14580 /* Only create a symbol if this is an external value.
14581 new_symbol checks this and puts the value in the global symbol
14582 table, which we want. If it is not external, new_symbol
14583 will try to put the value in cu->list_in_scope which is wrong. */
14584 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14586 /* A static const member, not much different than an enum as far as
14587 we're concerned, except that we can support more types. */
14588 new_symbol (die
, NULL
, cu
);
14591 /* Get physical name. */
14592 physname
= dwarf2_physname (fieldname
, die
, cu
);
14594 /* The name is already allocated along with this objfile, so we don't
14595 need to duplicate it for the type. */
14596 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14597 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14598 FIELD_NAME (*fp
) = fieldname
;
14600 else if (die
->tag
== DW_TAG_inheritance
)
14602 /* C++ base class field. */
14603 handle_data_member_location (die
, cu
, fp
);
14604 FIELD_BITSIZE (*fp
) = 0;
14605 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14606 FIELD_NAME (*fp
) = fp
->type
->name ();
14609 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14612 /* Can the type given by DIE define another type? */
14615 type_can_define_types (const struct die_info
*die
)
14619 case DW_TAG_typedef
:
14620 case DW_TAG_class_type
:
14621 case DW_TAG_structure_type
:
14622 case DW_TAG_union_type
:
14623 case DW_TAG_enumeration_type
:
14631 /* Add a type definition defined in the scope of the FIP's class. */
14634 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14635 struct dwarf2_cu
*cu
)
14637 struct decl_field fp
;
14638 memset (&fp
, 0, sizeof (fp
));
14640 gdb_assert (type_can_define_types (die
));
14642 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14643 fp
.name
= dwarf2_name (die
, cu
);
14644 fp
.type
= read_type_die (die
, cu
);
14646 /* Save accessibility. */
14647 enum dwarf_access_attribute accessibility
;
14648 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14650 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14652 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14653 switch (accessibility
)
14655 case DW_ACCESS_public
:
14656 /* The assumed value if neither private nor protected. */
14658 case DW_ACCESS_private
:
14661 case DW_ACCESS_protected
:
14662 fp
.is_protected
= 1;
14665 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14668 if (die
->tag
== DW_TAG_typedef
)
14669 fip
->typedef_field_list
.push_back (fp
);
14671 fip
->nested_types_list
.push_back (fp
);
14674 /* A convenience typedef that's used when finding the discriminant
14675 field for a variant part. */
14676 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14679 /* Compute the discriminant range for a given variant. OBSTACK is
14680 where the results will be stored. VARIANT is the variant to
14681 process. IS_UNSIGNED indicates whether the discriminant is signed
14684 static const gdb::array_view
<discriminant_range
>
14685 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14688 std::vector
<discriminant_range
> ranges
;
14690 if (variant
.default_branch
)
14693 if (variant
.discr_list_data
== nullptr)
14695 discriminant_range r
14696 = {variant
.discriminant_value
, variant
.discriminant_value
};
14697 ranges
.push_back (r
);
14701 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14702 variant
.discr_list_data
->size
);
14703 while (!data
.empty ())
14705 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14707 complaint (_("invalid discriminant marker: %d"), data
[0]);
14710 bool is_range
= data
[0] == DW_DSC_range
;
14711 data
= data
.slice (1);
14713 ULONGEST low
, high
;
14714 unsigned int bytes_read
;
14718 complaint (_("DW_AT_discr_list missing low value"));
14722 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14724 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14726 data
= data
.slice (bytes_read
);
14732 complaint (_("DW_AT_discr_list missing high value"));
14736 high
= read_unsigned_leb128 (nullptr, data
.data (),
14739 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14741 data
= data
.slice (bytes_read
);
14746 ranges
.push_back ({ low
, high
});
14750 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14752 std::copy (ranges
.begin (), ranges
.end (), result
);
14753 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14756 static const gdb::array_view
<variant_part
> create_variant_parts
14757 (struct obstack
*obstack
,
14758 const offset_map_type
&offset_map
,
14759 struct field_info
*fi
,
14760 const std::vector
<variant_part_builder
> &variant_parts
);
14762 /* Fill in a "struct variant" for a given variant field. RESULT is
14763 the variant to fill in. OBSTACK is where any needed allocations
14764 will be done. OFFSET_MAP holds the mapping from section offsets to
14765 fields for the type. FI describes the fields of the type we're
14766 processing. FIELD is the variant field we're converting. */
14769 create_one_variant (variant
&result
, struct obstack
*obstack
,
14770 const offset_map_type
&offset_map
,
14771 struct field_info
*fi
, const variant_field
&field
)
14773 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14774 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14775 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14776 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14777 field
.variant_parts
);
14780 /* Fill in a "struct variant_part" for a given variant part. RESULT
14781 is the variant part to fill in. OBSTACK is where any needed
14782 allocations will be done. OFFSET_MAP holds the mapping from
14783 section offsets to fields for the type. FI describes the fields of
14784 the type we're processing. BUILDER is the variant part to be
14788 create_one_variant_part (variant_part
&result
,
14789 struct obstack
*obstack
,
14790 const offset_map_type
&offset_map
,
14791 struct field_info
*fi
,
14792 const variant_part_builder
&builder
)
14794 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14795 if (iter
== offset_map
.end ())
14797 result
.discriminant_index
= -1;
14798 /* Doesn't matter. */
14799 result
.is_unsigned
= false;
14803 result
.discriminant_index
= iter
->second
;
14805 = TYPE_UNSIGNED (FIELD_TYPE
14806 (fi
->fields
[result
.discriminant_index
].field
));
14809 size_t n
= builder
.variants
.size ();
14810 variant
*output
= new (obstack
) variant
[n
];
14811 for (size_t i
= 0; i
< n
; ++i
)
14812 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14813 builder
.variants
[i
]);
14815 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14818 /* Create a vector of variant parts that can be attached to a type.
14819 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14820 holds the mapping from section offsets to fields for the type. FI
14821 describes the fields of the type we're processing. VARIANT_PARTS
14822 is the vector to convert. */
14824 static const gdb::array_view
<variant_part
>
14825 create_variant_parts (struct obstack
*obstack
,
14826 const offset_map_type
&offset_map
,
14827 struct field_info
*fi
,
14828 const std::vector
<variant_part_builder
> &variant_parts
)
14830 if (variant_parts
.empty ())
14833 size_t n
= variant_parts
.size ();
14834 variant_part
*result
= new (obstack
) variant_part
[n
];
14835 for (size_t i
= 0; i
< n
; ++i
)
14836 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14839 return gdb::array_view
<variant_part
> (result
, n
);
14842 /* Compute the variant part vector for FIP, attaching it to TYPE when
14846 add_variant_property (struct field_info
*fip
, struct type
*type
,
14847 struct dwarf2_cu
*cu
)
14849 /* Map section offsets of fields to their field index. Note the
14850 field index here does not take the number of baseclasses into
14852 offset_map_type offset_map
;
14853 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14854 offset_map
[fip
->fields
[i
].offset
] = i
;
14856 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14857 gdb::array_view
<variant_part
> parts
14858 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14859 fip
->variant_parts
);
14861 struct dynamic_prop prop
;
14862 prop
.kind
= PROP_VARIANT_PARTS
;
14863 prop
.data
.variant_parts
14864 = ((gdb::array_view
<variant_part
> *)
14865 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14867 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14870 /* Create the vector of fields, and attach it to the type. */
14873 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14874 struct dwarf2_cu
*cu
)
14876 int nfields
= fip
->nfields ();
14878 /* Record the field count, allocate space for the array of fields,
14879 and create blank accessibility bitfields if necessary. */
14880 type
->set_num_fields (nfields
);
14882 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14884 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14886 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14888 TYPE_FIELD_PRIVATE_BITS (type
) =
14889 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14890 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14892 TYPE_FIELD_PROTECTED_BITS (type
) =
14893 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14894 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14896 TYPE_FIELD_IGNORE_BITS (type
) =
14897 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14898 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14901 /* If the type has baseclasses, allocate and clear a bit vector for
14902 TYPE_FIELD_VIRTUAL_BITS. */
14903 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14905 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14906 unsigned char *pointer
;
14908 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14909 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14910 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14911 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14912 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14915 if (!fip
->variant_parts
.empty ())
14916 add_variant_property (fip
, type
, cu
);
14918 /* Copy the saved-up fields into the field vector. */
14919 for (int i
= 0; i
< nfields
; ++i
)
14921 struct nextfield
&field
14922 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14923 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14925 type
->field (i
) = field
.field
;
14926 switch (field
.accessibility
)
14928 case DW_ACCESS_private
:
14929 if (cu
->language
!= language_ada
)
14930 SET_TYPE_FIELD_PRIVATE (type
, i
);
14933 case DW_ACCESS_protected
:
14934 if (cu
->language
!= language_ada
)
14935 SET_TYPE_FIELD_PROTECTED (type
, i
);
14938 case DW_ACCESS_public
:
14942 /* Unknown accessibility. Complain and treat it as public. */
14944 complaint (_("unsupported accessibility %d"),
14945 field
.accessibility
);
14949 if (i
< fip
->baseclasses
.size ())
14951 switch (field
.virtuality
)
14953 case DW_VIRTUALITY_virtual
:
14954 case DW_VIRTUALITY_pure_virtual
:
14955 if (cu
->language
== language_ada
)
14956 error (_("unexpected virtuality in component of Ada type"));
14957 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14964 /* Return true if this member function is a constructor, false
14968 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14970 const char *fieldname
;
14971 const char *type_name
;
14974 if (die
->parent
== NULL
)
14977 if (die
->parent
->tag
!= DW_TAG_structure_type
14978 && die
->parent
->tag
!= DW_TAG_union_type
14979 && die
->parent
->tag
!= DW_TAG_class_type
)
14982 fieldname
= dwarf2_name (die
, cu
);
14983 type_name
= dwarf2_name (die
->parent
, cu
);
14984 if (fieldname
== NULL
|| type_name
== NULL
)
14987 len
= strlen (fieldname
);
14988 return (strncmp (fieldname
, type_name
, len
) == 0
14989 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14992 /* Check if the given VALUE is a recognized enum
14993 dwarf_defaulted_attribute constant according to DWARF5 spec,
14997 is_valid_DW_AT_defaulted (ULONGEST value
)
15001 case DW_DEFAULTED_no
:
15002 case DW_DEFAULTED_in_class
:
15003 case DW_DEFAULTED_out_of_class
:
15007 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15011 /* Add a member function to the proper fieldlist. */
15014 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15015 struct type
*type
, struct dwarf2_cu
*cu
)
15017 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15018 struct attribute
*attr
;
15020 struct fnfieldlist
*flp
= nullptr;
15021 struct fn_field
*fnp
;
15022 const char *fieldname
;
15023 struct type
*this_type
;
15024 enum dwarf_access_attribute accessibility
;
15026 if (cu
->language
== language_ada
)
15027 error (_("unexpected member function in Ada type"));
15029 /* Get name of member function. */
15030 fieldname
= dwarf2_name (die
, cu
);
15031 if (fieldname
== NULL
)
15034 /* Look up member function name in fieldlist. */
15035 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15037 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15039 flp
= &fip
->fnfieldlists
[i
];
15044 /* Create a new fnfieldlist if necessary. */
15045 if (flp
== nullptr)
15047 fip
->fnfieldlists
.emplace_back ();
15048 flp
= &fip
->fnfieldlists
.back ();
15049 flp
->name
= fieldname
;
15050 i
= fip
->fnfieldlists
.size () - 1;
15053 /* Create a new member function field and add it to the vector of
15055 flp
->fnfields
.emplace_back ();
15056 fnp
= &flp
->fnfields
.back ();
15058 /* Delay processing of the physname until later. */
15059 if (cu
->language
== language_cplus
)
15060 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15064 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15065 fnp
->physname
= physname
? physname
: "";
15068 fnp
->type
= alloc_type (objfile
);
15069 this_type
= read_type_die (die
, cu
);
15070 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15072 int nparams
= this_type
->num_fields ();
15074 /* TYPE is the domain of this method, and THIS_TYPE is the type
15075 of the method itself (TYPE_CODE_METHOD). */
15076 smash_to_method_type (fnp
->type
, type
,
15077 TYPE_TARGET_TYPE (this_type
),
15078 this_type
->fields (),
15079 this_type
->num_fields (),
15080 TYPE_VARARGS (this_type
));
15082 /* Handle static member functions.
15083 Dwarf2 has no clean way to discern C++ static and non-static
15084 member functions. G++ helps GDB by marking the first
15085 parameter for non-static member functions (which is the this
15086 pointer) as artificial. We obtain this information from
15087 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15088 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15089 fnp
->voffset
= VOFFSET_STATIC
;
15092 complaint (_("member function type missing for '%s'"),
15093 dwarf2_full_name (fieldname
, die
, cu
));
15095 /* Get fcontext from DW_AT_containing_type if present. */
15096 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15097 fnp
->fcontext
= die_containing_type (die
, cu
);
15099 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15100 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15102 /* Get accessibility. */
15103 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15104 if (attr
!= nullptr)
15105 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15107 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15108 switch (accessibility
)
15110 case DW_ACCESS_private
:
15111 fnp
->is_private
= 1;
15113 case DW_ACCESS_protected
:
15114 fnp
->is_protected
= 1;
15118 /* Check for artificial methods. */
15119 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15120 if (attr
&& DW_UNSND (attr
) != 0)
15121 fnp
->is_artificial
= 1;
15123 /* Check for defaulted methods. */
15124 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15125 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15126 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15128 /* Check for deleted methods. */
15129 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15130 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15131 fnp
->is_deleted
= 1;
15133 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15135 /* Get index in virtual function table if it is a virtual member
15136 function. For older versions of GCC, this is an offset in the
15137 appropriate virtual table, as specified by DW_AT_containing_type.
15138 For everyone else, it is an expression to be evaluated relative
15139 to the object address. */
15141 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15142 if (attr
!= nullptr)
15144 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15146 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15148 /* Old-style GCC. */
15149 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15151 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15152 || (DW_BLOCK (attr
)->size
> 1
15153 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15154 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15156 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15157 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15158 dwarf2_complex_location_expr_complaint ();
15160 fnp
->voffset
/= cu
->header
.addr_size
;
15164 dwarf2_complex_location_expr_complaint ();
15166 if (!fnp
->fcontext
)
15168 /* If there is no `this' field and no DW_AT_containing_type,
15169 we cannot actually find a base class context for the
15171 if (this_type
->num_fields () == 0
15172 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15174 complaint (_("cannot determine context for virtual member "
15175 "function \"%s\" (offset %s)"),
15176 fieldname
, sect_offset_str (die
->sect_off
));
15181 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15185 else if (attr
->form_is_section_offset ())
15187 dwarf2_complex_location_expr_complaint ();
15191 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15197 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15198 if (attr
&& DW_UNSND (attr
))
15200 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15201 complaint (_("Member function \"%s\" (offset %s) is virtual "
15202 "but the vtable offset is not specified"),
15203 fieldname
, sect_offset_str (die
->sect_off
));
15204 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15205 TYPE_CPLUS_DYNAMIC (type
) = 1;
15210 /* Create the vector of member function fields, and attach it to the type. */
15213 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15214 struct dwarf2_cu
*cu
)
15216 if (cu
->language
== language_ada
)
15217 error (_("unexpected member functions in Ada type"));
15219 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15220 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15222 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15224 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15226 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15227 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15229 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15230 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15231 fn_flp
->fn_fields
= (struct fn_field
*)
15232 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15234 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15235 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15238 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15241 /* Returns non-zero if NAME is the name of a vtable member in CU's
15242 language, zero otherwise. */
15244 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15246 static const char vptr
[] = "_vptr";
15248 /* Look for the C++ form of the vtable. */
15249 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15255 /* GCC outputs unnamed structures that are really pointers to member
15256 functions, with the ABI-specified layout. If TYPE describes
15257 such a structure, smash it into a member function type.
15259 GCC shouldn't do this; it should just output pointer to member DIEs.
15260 This is GCC PR debug/28767. */
15263 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15265 struct type
*pfn_type
, *self_type
, *new_type
;
15267 /* Check for a structure with no name and two children. */
15268 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15271 /* Check for __pfn and __delta members. */
15272 if (TYPE_FIELD_NAME (type
, 0) == NULL
15273 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15274 || TYPE_FIELD_NAME (type
, 1) == NULL
15275 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15278 /* Find the type of the method. */
15279 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15280 if (pfn_type
== NULL
15281 || pfn_type
->code () != TYPE_CODE_PTR
15282 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15285 /* Look for the "this" argument. */
15286 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15287 if (pfn_type
->num_fields () == 0
15288 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15289 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15292 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15293 new_type
= alloc_type (objfile
);
15294 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15295 pfn_type
->fields (), pfn_type
->num_fields (),
15296 TYPE_VARARGS (pfn_type
));
15297 smash_to_methodptr_type (type
, new_type
);
15300 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15301 appropriate error checking and issuing complaints if there is a
15305 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15307 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15309 if (attr
== nullptr)
15312 if (!attr
->form_is_constant ())
15314 complaint (_("DW_AT_alignment must have constant form"
15315 " - DIE at %s [in module %s]"),
15316 sect_offset_str (die
->sect_off
),
15317 objfile_name (cu
->per_objfile
->objfile
));
15322 if (attr
->form
== DW_FORM_sdata
)
15324 LONGEST val
= DW_SND (attr
);
15327 complaint (_("DW_AT_alignment value must not be negative"
15328 " - DIE at %s [in module %s]"),
15329 sect_offset_str (die
->sect_off
),
15330 objfile_name (cu
->per_objfile
->objfile
));
15336 align
= DW_UNSND (attr
);
15340 complaint (_("DW_AT_alignment value must not be zero"
15341 " - DIE at %s [in module %s]"),
15342 sect_offset_str (die
->sect_off
),
15343 objfile_name (cu
->per_objfile
->objfile
));
15346 if ((align
& (align
- 1)) != 0)
15348 complaint (_("DW_AT_alignment value must be a power of 2"
15349 " - DIE at %s [in module %s]"),
15350 sect_offset_str (die
->sect_off
),
15351 objfile_name (cu
->per_objfile
->objfile
));
15358 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15359 the alignment for TYPE. */
15362 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15365 if (!set_type_align (type
, get_alignment (cu
, die
)))
15366 complaint (_("DW_AT_alignment value too large"
15367 " - DIE at %s [in module %s]"),
15368 sect_offset_str (die
->sect_off
),
15369 objfile_name (cu
->per_objfile
->objfile
));
15372 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15373 constant for a type, according to DWARF5 spec, Table 5.5. */
15376 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15381 case DW_CC_pass_by_reference
:
15382 case DW_CC_pass_by_value
:
15386 complaint (_("unrecognized DW_AT_calling_convention value "
15387 "(%s) for a type"), pulongest (value
));
15392 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15393 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15394 also according to GNU-specific values (see include/dwarf2.h). */
15397 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15402 case DW_CC_program
:
15406 case DW_CC_GNU_renesas_sh
:
15407 case DW_CC_GNU_borland_fastcall_i386
:
15408 case DW_CC_GDB_IBM_OpenCL
:
15412 complaint (_("unrecognized DW_AT_calling_convention value "
15413 "(%s) for a subroutine"), pulongest (value
));
15418 /* Called when we find the DIE that starts a structure or union scope
15419 (definition) to create a type for the structure or union. Fill in
15420 the type's name and general properties; the members will not be
15421 processed until process_structure_scope. A symbol table entry for
15422 the type will also not be done until process_structure_scope (assuming
15423 the type has a name).
15425 NOTE: we need to call these functions regardless of whether or not the
15426 DIE has a DW_AT_name attribute, since it might be an anonymous
15427 structure or union. This gets the type entered into our set of
15428 user defined types. */
15430 static struct type
*
15431 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15433 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15435 struct attribute
*attr
;
15438 /* If the definition of this type lives in .debug_types, read that type.
15439 Don't follow DW_AT_specification though, that will take us back up
15440 the chain and we want to go down. */
15441 attr
= die
->attr (DW_AT_signature
);
15442 if (attr
!= nullptr)
15444 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15446 /* The type's CU may not be the same as CU.
15447 Ensure TYPE is recorded with CU in die_type_hash. */
15448 return set_die_type (die
, type
, cu
);
15451 type
= alloc_type (objfile
);
15452 INIT_CPLUS_SPECIFIC (type
);
15454 name
= dwarf2_name (die
, cu
);
15457 if (cu
->language
== language_cplus
15458 || cu
->language
== language_d
15459 || cu
->language
== language_rust
)
15461 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15463 /* dwarf2_full_name might have already finished building the DIE's
15464 type. If so, there is no need to continue. */
15465 if (get_die_type (die
, cu
) != NULL
)
15466 return get_die_type (die
, cu
);
15468 type
->set_name (full_name
);
15472 /* The name is already allocated along with this objfile, so
15473 we don't need to duplicate it for the type. */
15474 type
->set_name (name
);
15478 if (die
->tag
== DW_TAG_structure_type
)
15480 type
->set_code (TYPE_CODE_STRUCT
);
15482 else if (die
->tag
== DW_TAG_union_type
)
15484 type
->set_code (TYPE_CODE_UNION
);
15488 type
->set_code (TYPE_CODE_STRUCT
);
15491 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15492 TYPE_DECLARED_CLASS (type
) = 1;
15494 /* Store the calling convention in the type if it's available in
15495 the die. Otherwise the calling convention remains set to
15496 the default value DW_CC_normal. */
15497 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15498 if (attr
!= nullptr
15499 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15501 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15502 TYPE_CPLUS_CALLING_CONVENTION (type
)
15503 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15506 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15507 if (attr
!= nullptr)
15509 if (attr
->form_is_constant ())
15510 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15513 struct dynamic_prop prop
;
15514 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15515 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15516 TYPE_LENGTH (type
) = 0;
15521 TYPE_LENGTH (type
) = 0;
15524 maybe_set_alignment (cu
, die
, type
);
15526 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15528 /* ICC<14 does not output the required DW_AT_declaration on
15529 incomplete types, but gives them a size of zero. */
15530 TYPE_STUB (type
) = 1;
15533 TYPE_STUB_SUPPORTED (type
) = 1;
15535 if (die_is_declaration (die
, cu
))
15536 TYPE_STUB (type
) = 1;
15537 else if (attr
== NULL
&& die
->child
== NULL
15538 && producer_is_realview (cu
->producer
))
15539 /* RealView does not output the required DW_AT_declaration
15540 on incomplete types. */
15541 TYPE_STUB (type
) = 1;
15543 /* We need to add the type field to the die immediately so we don't
15544 infinitely recurse when dealing with pointers to the structure
15545 type within the structure itself. */
15546 set_die_type (die
, type
, cu
);
15548 /* set_die_type should be already done. */
15549 set_descriptive_type (type
, die
, cu
);
15554 static void handle_struct_member_die
15555 (struct die_info
*child_die
,
15557 struct field_info
*fi
,
15558 std::vector
<struct symbol
*> *template_args
,
15559 struct dwarf2_cu
*cu
);
15561 /* A helper for handle_struct_member_die that handles
15562 DW_TAG_variant_part. */
15565 handle_variant_part (struct die_info
*die
, struct type
*type
,
15566 struct field_info
*fi
,
15567 std::vector
<struct symbol
*> *template_args
,
15568 struct dwarf2_cu
*cu
)
15570 variant_part_builder
*new_part
;
15571 if (fi
->current_variant_part
== nullptr)
15573 fi
->variant_parts
.emplace_back ();
15574 new_part
= &fi
->variant_parts
.back ();
15576 else if (!fi
->current_variant_part
->processing_variant
)
15578 complaint (_("nested DW_TAG_variant_part seen "
15579 "- DIE at %s [in module %s]"),
15580 sect_offset_str (die
->sect_off
),
15581 objfile_name (cu
->per_objfile
->objfile
));
15586 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15587 current
.variant_parts
.emplace_back ();
15588 new_part
= ¤t
.variant_parts
.back ();
15591 /* When we recurse, we want callees to add to this new variant
15593 scoped_restore save_current_variant_part
15594 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15596 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15599 /* It's a univariant form, an extension we support. */
15601 else if (discr
->form_is_ref ())
15603 struct dwarf2_cu
*target_cu
= cu
;
15604 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15606 new_part
->discriminant_offset
= target_die
->sect_off
;
15610 complaint (_("DW_AT_discr does not have DIE reference form"
15611 " - DIE at %s [in module %s]"),
15612 sect_offset_str (die
->sect_off
),
15613 objfile_name (cu
->per_objfile
->objfile
));
15616 for (die_info
*child_die
= die
->child
;
15618 child_die
= child_die
->sibling
)
15619 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15622 /* A helper for handle_struct_member_die that handles
15626 handle_variant (struct die_info
*die
, struct type
*type
,
15627 struct field_info
*fi
,
15628 std::vector
<struct symbol
*> *template_args
,
15629 struct dwarf2_cu
*cu
)
15631 if (fi
->current_variant_part
== nullptr)
15633 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15634 "- DIE at %s [in module %s]"),
15635 sect_offset_str (die
->sect_off
),
15636 objfile_name (cu
->per_objfile
->objfile
));
15639 if (fi
->current_variant_part
->processing_variant
)
15641 complaint (_("nested DW_TAG_variant seen "
15642 "- DIE at %s [in module %s]"),
15643 sect_offset_str (die
->sect_off
),
15644 objfile_name (cu
->per_objfile
->objfile
));
15648 scoped_restore save_processing_variant
15649 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15652 fi
->current_variant_part
->variants
.emplace_back ();
15653 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15654 variant
.first_field
= fi
->fields
.size ();
15656 /* In a variant we want to get the discriminant and also add a
15657 field for our sole member child. */
15658 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15659 if (discr
== nullptr)
15661 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15662 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15663 variant
.default_branch
= true;
15665 variant
.discr_list_data
= DW_BLOCK (discr
);
15668 variant
.discriminant_value
= DW_UNSND (discr
);
15670 for (die_info
*variant_child
= die
->child
;
15671 variant_child
!= NULL
;
15672 variant_child
= variant_child
->sibling
)
15673 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15675 variant
.last_field
= fi
->fields
.size ();
15678 /* A helper for process_structure_scope that handles a single member
15682 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15683 struct field_info
*fi
,
15684 std::vector
<struct symbol
*> *template_args
,
15685 struct dwarf2_cu
*cu
)
15687 if (child_die
->tag
== DW_TAG_member
15688 || child_die
->tag
== DW_TAG_variable
)
15690 /* NOTE: carlton/2002-11-05: A C++ static data member
15691 should be a DW_TAG_member that is a declaration, but
15692 all versions of G++ as of this writing (so through at
15693 least 3.2.1) incorrectly generate DW_TAG_variable
15694 tags for them instead. */
15695 dwarf2_add_field (fi
, child_die
, cu
);
15697 else if (child_die
->tag
== DW_TAG_subprogram
)
15699 /* Rust doesn't have member functions in the C++ sense.
15700 However, it does emit ordinary functions as children
15701 of a struct DIE. */
15702 if (cu
->language
== language_rust
)
15703 read_func_scope (child_die
, cu
);
15706 /* C++ member function. */
15707 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15710 else if (child_die
->tag
== DW_TAG_inheritance
)
15712 /* C++ base class field. */
15713 dwarf2_add_field (fi
, child_die
, cu
);
15715 else if (type_can_define_types (child_die
))
15716 dwarf2_add_type_defn (fi
, child_die
, cu
);
15717 else if (child_die
->tag
== DW_TAG_template_type_param
15718 || child_die
->tag
== DW_TAG_template_value_param
)
15720 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15723 template_args
->push_back (arg
);
15725 else if (child_die
->tag
== DW_TAG_variant_part
)
15726 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15727 else if (child_die
->tag
== DW_TAG_variant
)
15728 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15731 /* Finish creating a structure or union type, including filling in
15732 its members and creating a symbol for it. */
15735 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15737 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15738 struct die_info
*child_die
;
15741 type
= get_die_type (die
, cu
);
15743 type
= read_structure_type (die
, cu
);
15745 bool has_template_parameters
= false;
15746 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15748 struct field_info fi
;
15749 std::vector
<struct symbol
*> template_args
;
15751 child_die
= die
->child
;
15753 while (child_die
&& child_die
->tag
)
15755 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15756 child_die
= child_die
->sibling
;
15759 /* Attach template arguments to type. */
15760 if (!template_args
.empty ())
15762 has_template_parameters
= true;
15763 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15764 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15765 TYPE_TEMPLATE_ARGUMENTS (type
)
15766 = XOBNEWVEC (&objfile
->objfile_obstack
,
15768 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15769 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15770 template_args
.data (),
15771 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15772 * sizeof (struct symbol
*)));
15775 /* Attach fields and member functions to the type. */
15776 if (fi
.nfields () > 0)
15777 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15778 if (!fi
.fnfieldlists
.empty ())
15780 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15782 /* Get the type which refers to the base class (possibly this
15783 class itself) which contains the vtable pointer for the current
15784 class from the DW_AT_containing_type attribute. This use of
15785 DW_AT_containing_type is a GNU extension. */
15787 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15789 struct type
*t
= die_containing_type (die
, cu
);
15791 set_type_vptr_basetype (type
, t
);
15796 /* Our own class provides vtbl ptr. */
15797 for (i
= t
->num_fields () - 1;
15798 i
>= TYPE_N_BASECLASSES (t
);
15801 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15803 if (is_vtable_name (fieldname
, cu
))
15805 set_type_vptr_fieldno (type
, i
);
15810 /* Complain if virtual function table field not found. */
15811 if (i
< TYPE_N_BASECLASSES (t
))
15812 complaint (_("virtual function table pointer "
15813 "not found when defining class '%s'"),
15814 type
->name () ? type
->name () : "");
15818 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15821 else if (cu
->producer
15822 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15824 /* The IBM XLC compiler does not provide direct indication
15825 of the containing type, but the vtable pointer is
15826 always named __vfp. */
15830 for (i
= type
->num_fields () - 1;
15831 i
>= TYPE_N_BASECLASSES (type
);
15834 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15836 set_type_vptr_fieldno (type
, i
);
15837 set_type_vptr_basetype (type
, type
);
15844 /* Copy fi.typedef_field_list linked list elements content into the
15845 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15846 if (!fi
.typedef_field_list
.empty ())
15848 int count
= fi
.typedef_field_list
.size ();
15850 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15851 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15852 = ((struct decl_field
*)
15854 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15855 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15857 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15858 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15861 /* Copy fi.nested_types_list linked list elements content into the
15862 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15863 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15865 int count
= fi
.nested_types_list
.size ();
15867 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15868 TYPE_NESTED_TYPES_ARRAY (type
)
15869 = ((struct decl_field
*)
15870 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15871 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15873 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15874 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15878 quirk_gcc_member_function_pointer (type
, objfile
);
15879 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15880 cu
->rust_unions
.push_back (type
);
15882 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15883 snapshots) has been known to create a die giving a declaration
15884 for a class that has, as a child, a die giving a definition for a
15885 nested class. So we have to process our children even if the
15886 current die is a declaration. Normally, of course, a declaration
15887 won't have any children at all. */
15889 child_die
= die
->child
;
15891 while (child_die
!= NULL
&& child_die
->tag
)
15893 if (child_die
->tag
== DW_TAG_member
15894 || child_die
->tag
== DW_TAG_variable
15895 || child_die
->tag
== DW_TAG_inheritance
15896 || child_die
->tag
== DW_TAG_template_value_param
15897 || child_die
->tag
== DW_TAG_template_type_param
)
15902 process_die (child_die
, cu
);
15904 child_die
= child_die
->sibling
;
15907 /* Do not consider external references. According to the DWARF standard,
15908 these DIEs are identified by the fact that they have no byte_size
15909 attribute, and a declaration attribute. */
15910 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15911 || !die_is_declaration (die
, cu
)
15912 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15914 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15916 if (has_template_parameters
)
15918 struct symtab
*symtab
;
15919 if (sym
!= nullptr)
15920 symtab
= symbol_symtab (sym
);
15921 else if (cu
->line_header
!= nullptr)
15923 /* Any related symtab will do. */
15925 = cu
->line_header
->file_names ()[0].symtab
;
15930 complaint (_("could not find suitable "
15931 "symtab for template parameter"
15932 " - DIE at %s [in module %s]"),
15933 sect_offset_str (die
->sect_off
),
15934 objfile_name (objfile
));
15937 if (symtab
!= nullptr)
15939 /* Make sure that the symtab is set on the new symbols.
15940 Even though they don't appear in this symtab directly,
15941 other parts of gdb assume that symbols do, and this is
15942 reasonably true. */
15943 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15944 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15950 /* Assuming DIE is an enumeration type, and TYPE is its associated
15951 type, update TYPE using some information only available in DIE's
15952 children. In particular, the fields are computed. */
15955 update_enumeration_type_from_children (struct die_info
*die
,
15957 struct dwarf2_cu
*cu
)
15959 struct die_info
*child_die
;
15960 int unsigned_enum
= 1;
15963 auto_obstack obstack
;
15964 std::vector
<struct field
> fields
;
15966 for (child_die
= die
->child
;
15967 child_die
!= NULL
&& child_die
->tag
;
15968 child_die
= child_die
->sibling
)
15970 struct attribute
*attr
;
15972 const gdb_byte
*bytes
;
15973 struct dwarf2_locexpr_baton
*baton
;
15976 if (child_die
->tag
!= DW_TAG_enumerator
)
15979 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15983 name
= dwarf2_name (child_die
, cu
);
15985 name
= "<anonymous enumerator>";
15987 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15988 &value
, &bytes
, &baton
);
15996 if (count_one_bits_ll (value
) >= 2)
16000 fields
.emplace_back ();
16001 struct field
&field
= fields
.back ();
16002 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16003 SET_FIELD_ENUMVAL (field
, value
);
16006 if (!fields
.empty ())
16008 type
->set_num_fields (fields
.size ());
16011 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16012 memcpy (type
->fields (), fields
.data (),
16013 sizeof (struct field
) * fields
.size ());
16017 TYPE_UNSIGNED (type
) = 1;
16019 TYPE_FLAG_ENUM (type
) = 1;
16022 /* Given a DW_AT_enumeration_type die, set its type. We do not
16023 complete the type's fields yet, or create any symbols. */
16025 static struct type
*
16026 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16028 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16030 struct attribute
*attr
;
16033 /* If the definition of this type lives in .debug_types, read that type.
16034 Don't follow DW_AT_specification though, that will take us back up
16035 the chain and we want to go down. */
16036 attr
= die
->attr (DW_AT_signature
);
16037 if (attr
!= nullptr)
16039 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16041 /* The type's CU may not be the same as CU.
16042 Ensure TYPE is recorded with CU in die_type_hash. */
16043 return set_die_type (die
, type
, cu
);
16046 type
= alloc_type (objfile
);
16048 type
->set_code (TYPE_CODE_ENUM
);
16049 name
= dwarf2_full_name (NULL
, die
, cu
);
16051 type
->set_name (name
);
16053 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16056 struct type
*underlying_type
= die_type (die
, cu
);
16058 TYPE_TARGET_TYPE (type
) = underlying_type
;
16061 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16062 if (attr
!= nullptr)
16064 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16068 TYPE_LENGTH (type
) = 0;
16071 maybe_set_alignment (cu
, die
, type
);
16073 /* The enumeration DIE can be incomplete. In Ada, any type can be
16074 declared as private in the package spec, and then defined only
16075 inside the package body. Such types are known as Taft Amendment
16076 Types. When another package uses such a type, an incomplete DIE
16077 may be generated by the compiler. */
16078 if (die_is_declaration (die
, cu
))
16079 TYPE_STUB (type
) = 1;
16081 /* If this type has an underlying type that is not a stub, then we
16082 may use its attributes. We always use the "unsigned" attribute
16083 in this situation, because ordinarily we guess whether the type
16084 is unsigned -- but the guess can be wrong and the underlying type
16085 can tell us the reality. However, we defer to a local size
16086 attribute if one exists, because this lets the compiler override
16087 the underlying type if needed. */
16088 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16090 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16091 underlying_type
= check_typedef (underlying_type
);
16092 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16093 if (TYPE_LENGTH (type
) == 0)
16094 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16095 if (TYPE_RAW_ALIGN (type
) == 0
16096 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16097 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16100 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16102 set_die_type (die
, type
, cu
);
16104 /* Finish the creation of this type by using the enum's children.
16105 Note that, as usual, this must come after set_die_type to avoid
16106 infinite recursion when trying to compute the names of the
16108 update_enumeration_type_from_children (die
, type
, cu
);
16113 /* Given a pointer to a die which begins an enumeration, process all
16114 the dies that define the members of the enumeration, and create the
16115 symbol for the enumeration type.
16117 NOTE: We reverse the order of the element list. */
16120 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16122 struct type
*this_type
;
16124 this_type
= get_die_type (die
, cu
);
16125 if (this_type
== NULL
)
16126 this_type
= read_enumeration_type (die
, cu
);
16128 if (die
->child
!= NULL
)
16130 struct die_info
*child_die
;
16133 child_die
= die
->child
;
16134 while (child_die
&& child_die
->tag
)
16136 if (child_die
->tag
!= DW_TAG_enumerator
)
16138 process_die (child_die
, cu
);
16142 name
= dwarf2_name (child_die
, cu
);
16144 new_symbol (child_die
, this_type
, cu
);
16147 child_die
= child_die
->sibling
;
16151 /* If we are reading an enum from a .debug_types unit, and the enum
16152 is a declaration, and the enum is not the signatured type in the
16153 unit, then we do not want to add a symbol for it. Adding a
16154 symbol would in some cases obscure the true definition of the
16155 enum, giving users an incomplete type when the definition is
16156 actually available. Note that we do not want to do this for all
16157 enums which are just declarations, because C++0x allows forward
16158 enum declarations. */
16159 if (cu
->per_cu
->is_debug_types
16160 && die_is_declaration (die
, cu
))
16162 struct signatured_type
*sig_type
;
16164 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16165 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16166 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16170 new_symbol (die
, this_type
, cu
);
16173 /* Extract all information from a DW_TAG_array_type DIE and put it in
16174 the DIE's type field. For now, this only handles one dimensional
16177 static struct type
*
16178 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16180 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16181 struct die_info
*child_die
;
16183 struct type
*element_type
, *range_type
, *index_type
;
16184 struct attribute
*attr
;
16186 struct dynamic_prop
*byte_stride_prop
= NULL
;
16187 unsigned int bit_stride
= 0;
16189 element_type
= die_type (die
, cu
);
16191 /* The die_type call above may have already set the type for this DIE. */
16192 type
= get_die_type (die
, cu
);
16196 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16200 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16203 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16204 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16208 complaint (_("unable to read array DW_AT_byte_stride "
16209 " - DIE at %s [in module %s]"),
16210 sect_offset_str (die
->sect_off
),
16211 objfile_name (cu
->per_objfile
->objfile
));
16212 /* Ignore this attribute. We will likely not be able to print
16213 arrays of this type correctly, but there is little we can do
16214 to help if we cannot read the attribute's value. */
16215 byte_stride_prop
= NULL
;
16219 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16221 bit_stride
= DW_UNSND (attr
);
16223 /* Irix 6.2 native cc creates array types without children for
16224 arrays with unspecified length. */
16225 if (die
->child
== NULL
)
16227 index_type
= objfile_type (objfile
)->builtin_int
;
16228 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16229 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16230 byte_stride_prop
, bit_stride
);
16231 return set_die_type (die
, type
, cu
);
16234 std::vector
<struct type
*> range_types
;
16235 child_die
= die
->child
;
16236 while (child_die
&& child_die
->tag
)
16238 if (child_die
->tag
== DW_TAG_subrange_type
)
16240 struct type
*child_type
= read_type_die (child_die
, cu
);
16242 if (child_type
!= NULL
)
16244 /* The range type was succesfully read. Save it for the
16245 array type creation. */
16246 range_types
.push_back (child_type
);
16249 child_die
= child_die
->sibling
;
16252 /* Dwarf2 dimensions are output from left to right, create the
16253 necessary array types in backwards order. */
16255 type
= element_type
;
16257 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16261 while (i
< range_types
.size ())
16262 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16263 byte_stride_prop
, bit_stride
);
16267 size_t ndim
= range_types
.size ();
16269 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16270 byte_stride_prop
, bit_stride
);
16273 /* Understand Dwarf2 support for vector types (like they occur on
16274 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16275 array type. This is not part of the Dwarf2/3 standard yet, but a
16276 custom vendor extension. The main difference between a regular
16277 array and the vector variant is that vectors are passed by value
16279 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16280 if (attr
!= nullptr)
16281 make_vector_type (type
);
16283 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16284 implementation may choose to implement triple vectors using this
16286 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16287 if (attr
!= nullptr)
16289 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16290 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16292 complaint (_("DW_AT_byte_size for array type smaller "
16293 "than the total size of elements"));
16296 name
= dwarf2_name (die
, cu
);
16298 type
->set_name (name
);
16300 maybe_set_alignment (cu
, die
, type
);
16302 /* Install the type in the die. */
16303 set_die_type (die
, type
, cu
);
16305 /* set_die_type should be already done. */
16306 set_descriptive_type (type
, die
, cu
);
16311 static enum dwarf_array_dim_ordering
16312 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16314 struct attribute
*attr
;
16316 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16318 if (attr
!= nullptr)
16319 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16321 /* GNU F77 is a special case, as at 08/2004 array type info is the
16322 opposite order to the dwarf2 specification, but data is still
16323 laid out as per normal fortran.
16325 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16326 version checking. */
16328 if (cu
->language
== language_fortran
16329 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16331 return DW_ORD_row_major
;
16334 switch (cu
->language_defn
->la_array_ordering
)
16336 case array_column_major
:
16337 return DW_ORD_col_major
;
16338 case array_row_major
:
16340 return DW_ORD_row_major
;
16344 /* Extract all information from a DW_TAG_set_type DIE and put it in
16345 the DIE's type field. */
16347 static struct type
*
16348 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16350 struct type
*domain_type
, *set_type
;
16351 struct attribute
*attr
;
16353 domain_type
= die_type (die
, cu
);
16355 /* The die_type call above may have already set the type for this DIE. */
16356 set_type
= get_die_type (die
, cu
);
16360 set_type
= create_set_type (NULL
, domain_type
);
16362 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16363 if (attr
!= nullptr)
16364 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16366 maybe_set_alignment (cu
, die
, set_type
);
16368 return set_die_type (die
, set_type
, cu
);
16371 /* A helper for read_common_block that creates a locexpr baton.
16372 SYM is the symbol which we are marking as computed.
16373 COMMON_DIE is the DIE for the common block.
16374 COMMON_LOC is the location expression attribute for the common
16376 MEMBER_LOC is the location expression attribute for the particular
16377 member of the common block that we are processing.
16378 CU is the CU from which the above come. */
16381 mark_common_block_symbol_computed (struct symbol
*sym
,
16382 struct die_info
*common_die
,
16383 struct attribute
*common_loc
,
16384 struct attribute
*member_loc
,
16385 struct dwarf2_cu
*cu
)
16387 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16388 struct objfile
*objfile
= per_objfile
->objfile
;
16389 struct dwarf2_locexpr_baton
*baton
;
16391 unsigned int cu_off
;
16392 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16393 LONGEST offset
= 0;
16395 gdb_assert (common_loc
&& member_loc
);
16396 gdb_assert (common_loc
->form_is_block ());
16397 gdb_assert (member_loc
->form_is_block ()
16398 || member_loc
->form_is_constant ());
16400 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16401 baton
->per_objfile
= per_objfile
;
16402 baton
->per_cu
= cu
->per_cu
;
16403 gdb_assert (baton
->per_cu
);
16405 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16407 if (member_loc
->form_is_constant ())
16409 offset
= member_loc
->constant_value (0);
16410 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16413 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16415 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16418 *ptr
++ = DW_OP_call4
;
16419 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16420 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16423 if (member_loc
->form_is_constant ())
16425 *ptr
++ = DW_OP_addr
;
16426 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16427 ptr
+= cu
->header
.addr_size
;
16431 /* We have to copy the data here, because DW_OP_call4 will only
16432 use a DW_AT_location attribute. */
16433 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16434 ptr
+= DW_BLOCK (member_loc
)->size
;
16437 *ptr
++ = DW_OP_plus
;
16438 gdb_assert (ptr
- baton
->data
== baton
->size
);
16440 SYMBOL_LOCATION_BATON (sym
) = baton
;
16441 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16444 /* Create appropriate locally-scoped variables for all the
16445 DW_TAG_common_block entries. Also create a struct common_block
16446 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16447 is used to separate the common blocks name namespace from regular
16451 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16453 struct attribute
*attr
;
16455 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16456 if (attr
!= nullptr)
16458 /* Support the .debug_loc offsets. */
16459 if (attr
->form_is_block ())
16463 else if (attr
->form_is_section_offset ())
16465 dwarf2_complex_location_expr_complaint ();
16470 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16471 "common block member");
16476 if (die
->child
!= NULL
)
16478 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16479 struct die_info
*child_die
;
16480 size_t n_entries
= 0, size
;
16481 struct common_block
*common_block
;
16482 struct symbol
*sym
;
16484 for (child_die
= die
->child
;
16485 child_die
&& child_die
->tag
;
16486 child_die
= child_die
->sibling
)
16489 size
= (sizeof (struct common_block
)
16490 + (n_entries
- 1) * sizeof (struct symbol
*));
16492 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16494 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16495 common_block
->n_entries
= 0;
16497 for (child_die
= die
->child
;
16498 child_die
&& child_die
->tag
;
16499 child_die
= child_die
->sibling
)
16501 /* Create the symbol in the DW_TAG_common_block block in the current
16503 sym
= new_symbol (child_die
, NULL
, cu
);
16506 struct attribute
*member_loc
;
16508 common_block
->contents
[common_block
->n_entries
++] = sym
;
16510 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16514 /* GDB has handled this for a long time, but it is
16515 not specified by DWARF. It seems to have been
16516 emitted by gfortran at least as recently as:
16517 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16518 complaint (_("Variable in common block has "
16519 "DW_AT_data_member_location "
16520 "- DIE at %s [in module %s]"),
16521 sect_offset_str (child_die
->sect_off
),
16522 objfile_name (objfile
));
16524 if (member_loc
->form_is_section_offset ())
16525 dwarf2_complex_location_expr_complaint ();
16526 else if (member_loc
->form_is_constant ()
16527 || member_loc
->form_is_block ())
16529 if (attr
!= nullptr)
16530 mark_common_block_symbol_computed (sym
, die
, attr
,
16534 dwarf2_complex_location_expr_complaint ();
16539 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16540 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16544 /* Create a type for a C++ namespace. */
16546 static struct type
*
16547 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16549 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16550 const char *previous_prefix
, *name
;
16554 /* For extensions, reuse the type of the original namespace. */
16555 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16557 struct die_info
*ext_die
;
16558 struct dwarf2_cu
*ext_cu
= cu
;
16560 ext_die
= dwarf2_extension (die
, &ext_cu
);
16561 type
= read_type_die (ext_die
, ext_cu
);
16563 /* EXT_CU may not be the same as CU.
16564 Ensure TYPE is recorded with CU in die_type_hash. */
16565 return set_die_type (die
, type
, cu
);
16568 name
= namespace_name (die
, &is_anonymous
, cu
);
16570 /* Now build the name of the current namespace. */
16572 previous_prefix
= determine_prefix (die
, cu
);
16573 if (previous_prefix
[0] != '\0')
16574 name
= typename_concat (&objfile
->objfile_obstack
,
16575 previous_prefix
, name
, 0, cu
);
16577 /* Create the type. */
16578 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16580 return set_die_type (die
, type
, cu
);
16583 /* Read a namespace scope. */
16586 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16588 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16591 /* Add a symbol associated to this if we haven't seen the namespace
16592 before. Also, add a using directive if it's an anonymous
16595 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16599 type
= read_type_die (die
, cu
);
16600 new_symbol (die
, type
, cu
);
16602 namespace_name (die
, &is_anonymous
, cu
);
16605 const char *previous_prefix
= determine_prefix (die
, cu
);
16607 std::vector
<const char *> excludes
;
16608 add_using_directive (using_directives (cu
),
16609 previous_prefix
, type
->name (), NULL
,
16610 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16614 if (die
->child
!= NULL
)
16616 struct die_info
*child_die
= die
->child
;
16618 while (child_die
&& child_die
->tag
)
16620 process_die (child_die
, cu
);
16621 child_die
= child_die
->sibling
;
16626 /* Read a Fortran module as type. This DIE can be only a declaration used for
16627 imported module. Still we need that type as local Fortran "use ... only"
16628 declaration imports depend on the created type in determine_prefix. */
16630 static struct type
*
16631 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16633 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16634 const char *module_name
;
16637 module_name
= dwarf2_name (die
, cu
);
16638 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16640 return set_die_type (die
, type
, cu
);
16643 /* Read a Fortran module. */
16646 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16648 struct die_info
*child_die
= die
->child
;
16651 type
= read_type_die (die
, cu
);
16652 new_symbol (die
, type
, cu
);
16654 while (child_die
&& child_die
->tag
)
16656 process_die (child_die
, cu
);
16657 child_die
= child_die
->sibling
;
16661 /* Return the name of the namespace represented by DIE. Set
16662 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16665 static const char *
16666 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16668 struct die_info
*current_die
;
16669 const char *name
= NULL
;
16671 /* Loop through the extensions until we find a name. */
16673 for (current_die
= die
;
16674 current_die
!= NULL
;
16675 current_die
= dwarf2_extension (die
, &cu
))
16677 /* We don't use dwarf2_name here so that we can detect the absence
16678 of a name -> anonymous namespace. */
16679 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16685 /* Is it an anonymous namespace? */
16687 *is_anonymous
= (name
== NULL
);
16689 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16694 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16695 the user defined type vector. */
16697 static struct type
*
16698 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16700 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16701 struct comp_unit_head
*cu_header
= &cu
->header
;
16703 struct attribute
*attr_byte_size
;
16704 struct attribute
*attr_address_class
;
16705 int byte_size
, addr_class
;
16706 struct type
*target_type
;
16708 target_type
= die_type (die
, cu
);
16710 /* The die_type call above may have already set the type for this DIE. */
16711 type
= get_die_type (die
, cu
);
16715 type
= lookup_pointer_type (target_type
);
16717 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16718 if (attr_byte_size
)
16719 byte_size
= DW_UNSND (attr_byte_size
);
16721 byte_size
= cu_header
->addr_size
;
16723 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16724 if (attr_address_class
)
16725 addr_class
= DW_UNSND (attr_address_class
);
16727 addr_class
= DW_ADDR_none
;
16729 ULONGEST alignment
= get_alignment (cu
, die
);
16731 /* If the pointer size, alignment, or address class is different
16732 than the default, create a type variant marked as such and set
16733 the length accordingly. */
16734 if (TYPE_LENGTH (type
) != byte_size
16735 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16736 && alignment
!= TYPE_RAW_ALIGN (type
))
16737 || addr_class
!= DW_ADDR_none
)
16739 if (gdbarch_address_class_type_flags_p (gdbarch
))
16743 type_flags
= gdbarch_address_class_type_flags
16744 (gdbarch
, byte_size
, addr_class
);
16745 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16747 type
= make_type_with_address_space (type
, type_flags
);
16749 else if (TYPE_LENGTH (type
) != byte_size
)
16751 complaint (_("invalid pointer size %d"), byte_size
);
16753 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16755 complaint (_("Invalid DW_AT_alignment"
16756 " - DIE at %s [in module %s]"),
16757 sect_offset_str (die
->sect_off
),
16758 objfile_name (cu
->per_objfile
->objfile
));
16762 /* Should we also complain about unhandled address classes? */
16766 TYPE_LENGTH (type
) = byte_size
;
16767 set_type_align (type
, alignment
);
16768 return set_die_type (die
, type
, cu
);
16771 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16772 the user defined type vector. */
16774 static struct type
*
16775 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16778 struct type
*to_type
;
16779 struct type
*domain
;
16781 to_type
= die_type (die
, cu
);
16782 domain
= die_containing_type (die
, cu
);
16784 /* The calls above may have already set the type for this DIE. */
16785 type
= get_die_type (die
, cu
);
16789 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16790 type
= lookup_methodptr_type (to_type
);
16791 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16793 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16795 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16796 to_type
->fields (), to_type
->num_fields (),
16797 TYPE_VARARGS (to_type
));
16798 type
= lookup_methodptr_type (new_type
);
16801 type
= lookup_memberptr_type (to_type
, domain
);
16803 return set_die_type (die
, type
, cu
);
16806 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16807 the user defined type vector. */
16809 static struct type
*
16810 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16811 enum type_code refcode
)
16813 struct comp_unit_head
*cu_header
= &cu
->header
;
16814 struct type
*type
, *target_type
;
16815 struct attribute
*attr
;
16817 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16819 target_type
= die_type (die
, cu
);
16821 /* The die_type call above may have already set the type for this DIE. */
16822 type
= get_die_type (die
, cu
);
16826 type
= lookup_reference_type (target_type
, refcode
);
16827 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16828 if (attr
!= nullptr)
16830 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16834 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16836 maybe_set_alignment (cu
, die
, type
);
16837 return set_die_type (die
, type
, cu
);
16840 /* Add the given cv-qualifiers to the element type of the array. GCC
16841 outputs DWARF type qualifiers that apply to an array, not the
16842 element type. But GDB relies on the array element type to carry
16843 the cv-qualifiers. This mimics section 6.7.3 of the C99
16846 static struct type
*
16847 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16848 struct type
*base_type
, int cnst
, int voltl
)
16850 struct type
*el_type
, *inner_array
;
16852 base_type
= copy_type (base_type
);
16853 inner_array
= base_type
;
16855 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16857 TYPE_TARGET_TYPE (inner_array
) =
16858 copy_type (TYPE_TARGET_TYPE (inner_array
));
16859 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16862 el_type
= TYPE_TARGET_TYPE (inner_array
);
16863 cnst
|= TYPE_CONST (el_type
);
16864 voltl
|= TYPE_VOLATILE (el_type
);
16865 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16867 return set_die_type (die
, base_type
, cu
);
16870 static struct type
*
16871 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16873 struct type
*base_type
, *cv_type
;
16875 base_type
= die_type (die
, cu
);
16877 /* The die_type call above may have already set the type for this DIE. */
16878 cv_type
= get_die_type (die
, cu
);
16882 /* In case the const qualifier is applied to an array type, the element type
16883 is so qualified, not the array type (section 6.7.3 of C99). */
16884 if (base_type
->code () == TYPE_CODE_ARRAY
)
16885 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16887 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16888 return set_die_type (die
, cv_type
, cu
);
16891 static struct type
*
16892 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16894 struct type
*base_type
, *cv_type
;
16896 base_type
= die_type (die
, cu
);
16898 /* The die_type call above may have already set the type for this DIE. */
16899 cv_type
= get_die_type (die
, cu
);
16903 /* In case the volatile qualifier is applied to an array type, the
16904 element type is so qualified, not the array type (section 6.7.3
16906 if (base_type
->code () == TYPE_CODE_ARRAY
)
16907 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16909 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16910 return set_die_type (die
, cv_type
, cu
);
16913 /* Handle DW_TAG_restrict_type. */
16915 static struct type
*
16916 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16918 struct type
*base_type
, *cv_type
;
16920 base_type
= die_type (die
, cu
);
16922 /* The die_type call above may have already set the type for this DIE. */
16923 cv_type
= get_die_type (die
, cu
);
16927 cv_type
= make_restrict_type (base_type
);
16928 return set_die_type (die
, cv_type
, cu
);
16931 /* Handle DW_TAG_atomic_type. */
16933 static struct type
*
16934 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16936 struct type
*base_type
, *cv_type
;
16938 base_type
= die_type (die
, cu
);
16940 /* The die_type call above may have already set the type for this DIE. */
16941 cv_type
= get_die_type (die
, cu
);
16945 cv_type
= make_atomic_type (base_type
);
16946 return set_die_type (die
, cv_type
, cu
);
16949 /* Extract all information from a DW_TAG_string_type DIE and add to
16950 the user defined type vector. It isn't really a user defined type,
16951 but it behaves like one, with other DIE's using an AT_user_def_type
16952 attribute to reference it. */
16954 static struct type
*
16955 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16957 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16958 struct gdbarch
*gdbarch
= objfile
->arch ();
16959 struct type
*type
, *range_type
, *index_type
, *char_type
;
16960 struct attribute
*attr
;
16961 struct dynamic_prop prop
;
16962 bool length_is_constant
= true;
16965 /* There are a couple of places where bit sizes might be made use of
16966 when parsing a DW_TAG_string_type, however, no producer that we know
16967 of make use of these. Handling bit sizes that are a multiple of the
16968 byte size is easy enough, but what about other bit sizes? Lets deal
16969 with that problem when we have to. Warn about these attributes being
16970 unsupported, then parse the type and ignore them like we always
16972 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16973 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16975 static bool warning_printed
= false;
16976 if (!warning_printed
)
16978 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16979 "currently supported on DW_TAG_string_type."));
16980 warning_printed
= true;
16984 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16985 if (attr
!= nullptr && !attr
->form_is_constant ())
16987 /* The string length describes the location at which the length of
16988 the string can be found. The size of the length field can be
16989 specified with one of the attributes below. */
16990 struct type
*prop_type
;
16991 struct attribute
*len
16992 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16993 if (len
== nullptr)
16994 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16995 if (len
!= nullptr && len
->form_is_constant ())
16997 /* Pass 0 as the default as we know this attribute is constant
16998 and the default value will not be returned. */
16999 LONGEST sz
= len
->constant_value (0);
17000 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17004 /* If the size is not specified then we assume it is the size of
17005 an address on this target. */
17006 prop_type
= cu
->addr_sized_int_type (true);
17009 /* Convert the attribute into a dynamic property. */
17010 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17013 length_is_constant
= false;
17015 else if (attr
!= nullptr)
17017 /* This DW_AT_string_length just contains the length with no
17018 indirection. There's no need to create a dynamic property in this
17019 case. Pass 0 for the default value as we know it will not be
17020 returned in this case. */
17021 length
= attr
->constant_value (0);
17023 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17025 /* We don't currently support non-constant byte sizes for strings. */
17026 length
= attr
->constant_value (1);
17030 /* Use 1 as a fallback length if we have nothing else. */
17034 index_type
= objfile_type (objfile
)->builtin_int
;
17035 if (length_is_constant
)
17036 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17039 struct dynamic_prop low_bound
;
17041 low_bound
.kind
= PROP_CONST
;
17042 low_bound
.data
.const_val
= 1;
17043 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17045 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17046 type
= create_string_type (NULL
, char_type
, range_type
);
17048 return set_die_type (die
, type
, cu
);
17051 /* Assuming that DIE corresponds to a function, returns nonzero
17052 if the function is prototyped. */
17055 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17057 struct attribute
*attr
;
17059 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17060 if (attr
&& (DW_UNSND (attr
) != 0))
17063 /* The DWARF standard implies that the DW_AT_prototyped attribute
17064 is only meaningful for C, but the concept also extends to other
17065 languages that allow unprototyped functions (Eg: Objective C).
17066 For all other languages, assume that functions are always
17068 if (cu
->language
!= language_c
17069 && cu
->language
!= language_objc
17070 && cu
->language
!= language_opencl
)
17073 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17074 prototyped and unprototyped functions; default to prototyped,
17075 since that is more common in modern code (and RealView warns
17076 about unprototyped functions). */
17077 if (producer_is_realview (cu
->producer
))
17083 /* Handle DIES due to C code like:
17087 int (*funcp)(int a, long l);
17091 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17093 static struct type
*
17094 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17096 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17097 struct type
*type
; /* Type that this function returns. */
17098 struct type
*ftype
; /* Function that returns above type. */
17099 struct attribute
*attr
;
17101 type
= die_type (die
, cu
);
17103 /* The die_type call above may have already set the type for this DIE. */
17104 ftype
= get_die_type (die
, cu
);
17108 ftype
= lookup_function_type (type
);
17110 if (prototyped_function_p (die
, cu
))
17111 TYPE_PROTOTYPED (ftype
) = 1;
17113 /* Store the calling convention in the type if it's available in
17114 the subroutine die. Otherwise set the calling convention to
17115 the default value DW_CC_normal. */
17116 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17117 if (attr
!= nullptr
17118 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17119 TYPE_CALLING_CONVENTION (ftype
)
17120 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17121 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17122 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17124 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17126 /* Record whether the function returns normally to its caller or not
17127 if the DWARF producer set that information. */
17128 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17129 if (attr
&& (DW_UNSND (attr
) != 0))
17130 TYPE_NO_RETURN (ftype
) = 1;
17132 /* We need to add the subroutine type to the die immediately so
17133 we don't infinitely recurse when dealing with parameters
17134 declared as the same subroutine type. */
17135 set_die_type (die
, ftype
, cu
);
17137 if (die
->child
!= NULL
)
17139 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17140 struct die_info
*child_die
;
17141 int nparams
, iparams
;
17143 /* Count the number of parameters.
17144 FIXME: GDB currently ignores vararg functions, but knows about
17145 vararg member functions. */
17147 child_die
= die
->child
;
17148 while (child_die
&& child_die
->tag
)
17150 if (child_die
->tag
== DW_TAG_formal_parameter
)
17152 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17153 TYPE_VARARGS (ftype
) = 1;
17154 child_die
= child_die
->sibling
;
17157 /* Allocate storage for parameters and fill them in. */
17158 ftype
->set_num_fields (nparams
);
17160 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17162 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17163 even if we error out during the parameters reading below. */
17164 for (iparams
= 0; iparams
< nparams
; iparams
++)
17165 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17168 child_die
= die
->child
;
17169 while (child_die
&& child_die
->tag
)
17171 if (child_die
->tag
== DW_TAG_formal_parameter
)
17173 struct type
*arg_type
;
17175 /* DWARF version 2 has no clean way to discern C++
17176 static and non-static member functions. G++ helps
17177 GDB by marking the first parameter for non-static
17178 member functions (which is the this pointer) as
17179 artificial. We pass this information to
17180 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17182 DWARF version 3 added DW_AT_object_pointer, which GCC
17183 4.5 does not yet generate. */
17184 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17185 if (attr
!= nullptr)
17186 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17188 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17189 arg_type
= die_type (child_die
, cu
);
17191 /* RealView does not mark THIS as const, which the testsuite
17192 expects. GCC marks THIS as const in method definitions,
17193 but not in the class specifications (GCC PR 43053). */
17194 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17195 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17198 struct dwarf2_cu
*arg_cu
= cu
;
17199 const char *name
= dwarf2_name (child_die
, cu
);
17201 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17202 if (attr
!= nullptr)
17204 /* If the compiler emits this, use it. */
17205 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17208 else if (name
&& strcmp (name
, "this") == 0)
17209 /* Function definitions will have the argument names. */
17211 else if (name
== NULL
&& iparams
== 0)
17212 /* Declarations may not have the names, so like
17213 elsewhere in GDB, assume an artificial first
17214 argument is "this". */
17218 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17222 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17225 child_die
= child_die
->sibling
;
17232 static struct type
*
17233 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17235 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17236 const char *name
= NULL
;
17237 struct type
*this_type
, *target_type
;
17239 name
= dwarf2_full_name (NULL
, die
, cu
);
17240 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17241 TYPE_TARGET_STUB (this_type
) = 1;
17242 set_die_type (die
, this_type
, cu
);
17243 target_type
= die_type (die
, cu
);
17244 if (target_type
!= this_type
)
17245 TYPE_TARGET_TYPE (this_type
) = target_type
;
17248 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17249 spec and cause infinite loops in GDB. */
17250 complaint (_("Self-referential DW_TAG_typedef "
17251 "- DIE at %s [in module %s]"),
17252 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17253 TYPE_TARGET_TYPE (this_type
) = NULL
;
17257 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17258 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17259 Handle these by just returning the target type, rather than
17260 constructing an anonymous typedef type and trying to handle this
17262 set_die_type (die
, target_type
, cu
);
17263 return target_type
;
17268 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17269 (which may be different from NAME) to the architecture back-end to allow
17270 it to guess the correct format if necessary. */
17272 static struct type
*
17273 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17274 const char *name_hint
, enum bfd_endian byte_order
)
17276 struct gdbarch
*gdbarch
= objfile
->arch ();
17277 const struct floatformat
**format
;
17280 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17282 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17284 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17289 /* Allocate an integer type of size BITS and name NAME. */
17291 static struct type
*
17292 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17293 int bits
, int unsigned_p
, const char *name
)
17297 /* Versions of Intel's C Compiler generate an integer type called "void"
17298 instead of using DW_TAG_unspecified_type. This has been seen on
17299 at least versions 14, 17, and 18. */
17300 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17301 && strcmp (name
, "void") == 0)
17302 type
= objfile_type (objfile
)->builtin_void
;
17304 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17309 /* Initialise and return a floating point type of size BITS suitable for
17310 use as a component of a complex number. The NAME_HINT is passed through
17311 when initialising the floating point type and is the name of the complex
17314 As DWARF doesn't currently provide an explicit name for the components
17315 of a complex number, but it can be helpful to have these components
17316 named, we try to select a suitable name based on the size of the
17318 static struct type
*
17319 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17320 struct objfile
*objfile
,
17321 int bits
, const char *name_hint
,
17322 enum bfd_endian byte_order
)
17324 gdbarch
*gdbarch
= objfile
->arch ();
17325 struct type
*tt
= nullptr;
17327 /* Try to find a suitable floating point builtin type of size BITS.
17328 We're going to use the name of this type as the name for the complex
17329 target type that we are about to create. */
17330 switch (cu
->language
)
17332 case language_fortran
:
17336 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17339 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17341 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17343 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17351 tt
= builtin_type (gdbarch
)->builtin_float
;
17354 tt
= builtin_type (gdbarch
)->builtin_double
;
17356 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17358 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17364 /* If the type we found doesn't match the size we were looking for, then
17365 pretend we didn't find a type at all, the complex target type we
17366 create will then be nameless. */
17367 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17370 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17371 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17374 /* Find a representation of a given base type and install
17375 it in the TYPE field of the die. */
17377 static struct type
*
17378 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17380 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17382 struct attribute
*attr
;
17383 int encoding
= 0, bits
= 0;
17387 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17388 if (attr
!= nullptr)
17389 encoding
= DW_UNSND (attr
);
17390 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17391 if (attr
!= nullptr)
17392 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17393 name
= dwarf2_name (die
, cu
);
17395 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17397 arch
= objfile
->arch ();
17398 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17400 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17403 int endianity
= DW_UNSND (attr
);
17408 byte_order
= BFD_ENDIAN_BIG
;
17410 case DW_END_little
:
17411 byte_order
= BFD_ENDIAN_LITTLE
;
17414 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17421 case DW_ATE_address
:
17422 /* Turn DW_ATE_address into a void * pointer. */
17423 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17424 type
= init_pointer_type (objfile
, bits
, name
, type
);
17426 case DW_ATE_boolean
:
17427 type
= init_boolean_type (objfile
, bits
, 1, name
);
17429 case DW_ATE_complex_float
:
17430 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17432 if (type
->code () == TYPE_CODE_ERROR
)
17434 if (name
== nullptr)
17436 struct obstack
*obstack
17437 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17438 name
= obconcat (obstack
, "_Complex ", type
->name (),
17441 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17444 type
= init_complex_type (name
, type
);
17446 case DW_ATE_decimal_float
:
17447 type
= init_decfloat_type (objfile
, bits
, name
);
17450 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17452 case DW_ATE_signed
:
17453 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17455 case DW_ATE_unsigned
:
17456 if (cu
->language
== language_fortran
17458 && startswith (name
, "character("))
17459 type
= init_character_type (objfile
, bits
, 1, name
);
17461 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17463 case DW_ATE_signed_char
:
17464 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17465 || cu
->language
== language_pascal
17466 || cu
->language
== language_fortran
)
17467 type
= init_character_type (objfile
, bits
, 0, name
);
17469 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17471 case DW_ATE_unsigned_char
:
17472 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17473 || cu
->language
== language_pascal
17474 || cu
->language
== language_fortran
17475 || cu
->language
== language_rust
)
17476 type
= init_character_type (objfile
, bits
, 1, name
);
17478 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17483 type
= builtin_type (arch
)->builtin_char16
;
17484 else if (bits
== 32)
17485 type
= builtin_type (arch
)->builtin_char32
;
17488 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17490 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17492 return set_die_type (die
, type
, cu
);
17497 complaint (_("unsupported DW_AT_encoding: '%s'"),
17498 dwarf_type_encoding_name (encoding
));
17499 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17503 if (name
&& strcmp (name
, "char") == 0)
17504 TYPE_NOSIGN (type
) = 1;
17506 maybe_set_alignment (cu
, die
, type
);
17508 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17510 return set_die_type (die
, type
, cu
);
17513 /* Parse dwarf attribute if it's a block, reference or constant and put the
17514 resulting value of the attribute into struct bound_prop.
17515 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17518 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17519 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17520 struct type
*default_type
)
17522 struct dwarf2_property_baton
*baton
;
17523 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17524 struct objfile
*objfile
= per_objfile
->objfile
;
17525 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17527 gdb_assert (default_type
!= NULL
);
17529 if (attr
== NULL
|| prop
== NULL
)
17532 if (attr
->form_is_block ())
17534 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17535 baton
->property_type
= default_type
;
17536 baton
->locexpr
.per_cu
= cu
->per_cu
;
17537 baton
->locexpr
.per_objfile
= per_objfile
;
17538 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17539 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17540 switch (attr
->name
)
17542 case DW_AT_string_length
:
17543 baton
->locexpr
.is_reference
= true;
17546 baton
->locexpr
.is_reference
= false;
17549 prop
->data
.baton
= baton
;
17550 prop
->kind
= PROP_LOCEXPR
;
17551 gdb_assert (prop
->data
.baton
!= NULL
);
17553 else if (attr
->form_is_ref ())
17555 struct dwarf2_cu
*target_cu
= cu
;
17556 struct die_info
*target_die
;
17557 struct attribute
*target_attr
;
17559 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17560 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17561 if (target_attr
== NULL
)
17562 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17564 if (target_attr
== NULL
)
17567 switch (target_attr
->name
)
17569 case DW_AT_location
:
17570 if (target_attr
->form_is_section_offset ())
17572 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17573 baton
->property_type
= die_type (target_die
, target_cu
);
17574 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17575 prop
->data
.baton
= baton
;
17576 prop
->kind
= PROP_LOCLIST
;
17577 gdb_assert (prop
->data
.baton
!= NULL
);
17579 else if (target_attr
->form_is_block ())
17581 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17582 baton
->property_type
= die_type (target_die
, target_cu
);
17583 baton
->locexpr
.per_cu
= cu
->per_cu
;
17584 baton
->locexpr
.per_objfile
= per_objfile
;
17585 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17586 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17587 baton
->locexpr
.is_reference
= true;
17588 prop
->data
.baton
= baton
;
17589 prop
->kind
= PROP_LOCEXPR
;
17590 gdb_assert (prop
->data
.baton
!= NULL
);
17594 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17595 "dynamic property");
17599 case DW_AT_data_member_location
:
17603 if (!handle_data_member_location (target_die
, target_cu
,
17607 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17608 baton
->property_type
= read_type_die (target_die
->parent
,
17610 baton
->offset_info
.offset
= offset
;
17611 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17612 prop
->data
.baton
= baton
;
17613 prop
->kind
= PROP_ADDR_OFFSET
;
17618 else if (attr
->form_is_constant ())
17620 prop
->data
.const_val
= attr
->constant_value (0);
17621 prop
->kind
= PROP_CONST
;
17625 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17626 dwarf2_name (die
, cu
));
17636 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17638 struct type
*int_type
;
17640 /* Helper macro to examine the various builtin types. */
17641 #define TRY_TYPE(F) \
17642 int_type = (unsigned_p \
17643 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17644 : objfile_type (objfile)->builtin_ ## F); \
17645 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17652 TRY_TYPE (long_long
);
17656 gdb_assert_not_reached ("unable to find suitable integer type");
17662 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17664 int addr_size
= this->per_cu
->addr_size ();
17665 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17668 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17669 present (which is valid) then compute the default type based on the
17670 compilation units address size. */
17672 static struct type
*
17673 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17675 struct type
*index_type
= die_type (die
, cu
);
17677 /* Dwarf-2 specifications explicitly allows to create subrange types
17678 without specifying a base type.
17679 In that case, the base type must be set to the type of
17680 the lower bound, upper bound or count, in that order, if any of these
17681 three attributes references an object that has a type.
17682 If no base type is found, the Dwarf-2 specifications say that
17683 a signed integer type of size equal to the size of an address should
17685 For the following C code: `extern char gdb_int [];'
17686 GCC produces an empty range DIE.
17687 FIXME: muller/2010-05-28: Possible references to object for low bound,
17688 high bound or count are not yet handled by this code. */
17689 if (index_type
->code () == TYPE_CODE_VOID
)
17690 index_type
= cu
->addr_sized_int_type (false);
17695 /* Read the given DW_AT_subrange DIE. */
17697 static struct type
*
17698 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17700 struct type
*base_type
, *orig_base_type
;
17701 struct type
*range_type
;
17702 struct attribute
*attr
;
17703 struct dynamic_prop low
, high
;
17704 int low_default_is_valid
;
17705 int high_bound_is_count
= 0;
17707 ULONGEST negative_mask
;
17709 orig_base_type
= read_subrange_index_type (die
, cu
);
17711 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17712 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17713 creating the range type, but we use the result of check_typedef
17714 when examining properties of the type. */
17715 base_type
= check_typedef (orig_base_type
);
17717 /* The die_type call above may have already set the type for this DIE. */
17718 range_type
= get_die_type (die
, cu
);
17722 low
.kind
= PROP_CONST
;
17723 high
.kind
= PROP_CONST
;
17724 high
.data
.const_val
= 0;
17726 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17727 omitting DW_AT_lower_bound. */
17728 switch (cu
->language
)
17731 case language_cplus
:
17732 low
.data
.const_val
= 0;
17733 low_default_is_valid
= 1;
17735 case language_fortran
:
17736 low
.data
.const_val
= 1;
17737 low_default_is_valid
= 1;
17740 case language_objc
:
17741 case language_rust
:
17742 low
.data
.const_val
= 0;
17743 low_default_is_valid
= (cu
->header
.version
>= 4);
17747 case language_pascal
:
17748 low
.data
.const_val
= 1;
17749 low_default_is_valid
= (cu
->header
.version
>= 4);
17752 low
.data
.const_val
= 0;
17753 low_default_is_valid
= 0;
17757 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17758 if (attr
!= nullptr)
17759 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17760 else if (!low_default_is_valid
)
17761 complaint (_("Missing DW_AT_lower_bound "
17762 "- DIE at %s [in module %s]"),
17763 sect_offset_str (die
->sect_off
),
17764 objfile_name (cu
->per_objfile
->objfile
));
17766 struct attribute
*attr_ub
, *attr_count
;
17767 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17768 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17770 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17771 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17773 /* If bounds are constant do the final calculation here. */
17774 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17775 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17777 high_bound_is_count
= 1;
17781 if (attr_ub
!= NULL
)
17782 complaint (_("Unresolved DW_AT_upper_bound "
17783 "- DIE at %s [in module %s]"),
17784 sect_offset_str (die
->sect_off
),
17785 objfile_name (cu
->per_objfile
->objfile
));
17786 if (attr_count
!= NULL
)
17787 complaint (_("Unresolved DW_AT_count "
17788 "- DIE at %s [in module %s]"),
17789 sect_offset_str (die
->sect_off
),
17790 objfile_name (cu
->per_objfile
->objfile
));
17795 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17796 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17797 bias
= bias_attr
->constant_value (0);
17799 /* Normally, the DWARF producers are expected to use a signed
17800 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17801 But this is unfortunately not always the case, as witnessed
17802 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17803 is used instead. To work around that ambiguity, we treat
17804 the bounds as signed, and thus sign-extend their values, when
17805 the base type is signed. */
17807 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17808 if (low
.kind
== PROP_CONST
17809 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17810 low
.data
.const_val
|= negative_mask
;
17811 if (high
.kind
== PROP_CONST
17812 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17813 high
.data
.const_val
|= negative_mask
;
17815 /* Check for bit and byte strides. */
17816 struct dynamic_prop byte_stride_prop
;
17817 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17818 if (attr_byte_stride
!= nullptr)
17820 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17821 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17825 struct dynamic_prop bit_stride_prop
;
17826 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17827 if (attr_bit_stride
!= nullptr)
17829 /* It only makes sense to have either a bit or byte stride. */
17830 if (attr_byte_stride
!= nullptr)
17832 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17833 "- DIE at %s [in module %s]"),
17834 sect_offset_str (die
->sect_off
),
17835 objfile_name (cu
->per_objfile
->objfile
));
17836 attr_bit_stride
= nullptr;
17840 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17841 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17846 if (attr_byte_stride
!= nullptr
17847 || attr_bit_stride
!= nullptr)
17849 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17850 struct dynamic_prop
*stride
17851 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17854 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17855 &high
, bias
, stride
, byte_stride_p
);
17858 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17860 if (high_bound_is_count
)
17861 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17863 /* Ada expects an empty array on no boundary attributes. */
17864 if (attr
== NULL
&& cu
->language
!= language_ada
)
17865 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17867 name
= dwarf2_name (die
, cu
);
17869 range_type
->set_name (name
);
17871 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17872 if (attr
!= nullptr)
17873 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17875 maybe_set_alignment (cu
, die
, range_type
);
17877 set_die_type (die
, range_type
, cu
);
17879 /* set_die_type should be already done. */
17880 set_descriptive_type (range_type
, die
, cu
);
17885 static struct type
*
17886 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17890 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17891 type
->set_name (dwarf2_name (die
, cu
));
17893 /* In Ada, an unspecified type is typically used when the description
17894 of the type is deferred to a different unit. When encountering
17895 such a type, we treat it as a stub, and try to resolve it later on,
17897 if (cu
->language
== language_ada
)
17898 TYPE_STUB (type
) = 1;
17900 return set_die_type (die
, type
, cu
);
17903 /* Read a single die and all its descendents. Set the die's sibling
17904 field to NULL; set other fields in the die correctly, and set all
17905 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17906 location of the info_ptr after reading all of those dies. PARENT
17907 is the parent of the die in question. */
17909 static struct die_info
*
17910 read_die_and_children (const struct die_reader_specs
*reader
,
17911 const gdb_byte
*info_ptr
,
17912 const gdb_byte
**new_info_ptr
,
17913 struct die_info
*parent
)
17915 struct die_info
*die
;
17916 const gdb_byte
*cur_ptr
;
17918 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17921 *new_info_ptr
= cur_ptr
;
17924 store_in_ref_table (die
, reader
->cu
);
17926 if (die
->has_children
)
17927 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17931 *new_info_ptr
= cur_ptr
;
17934 die
->sibling
= NULL
;
17935 die
->parent
= parent
;
17939 /* Read a die, all of its descendents, and all of its siblings; set
17940 all of the fields of all of the dies correctly. Arguments are as
17941 in read_die_and_children. */
17943 static struct die_info
*
17944 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17945 const gdb_byte
*info_ptr
,
17946 const gdb_byte
**new_info_ptr
,
17947 struct die_info
*parent
)
17949 struct die_info
*first_die
, *last_sibling
;
17950 const gdb_byte
*cur_ptr
;
17952 cur_ptr
= info_ptr
;
17953 first_die
= last_sibling
= NULL
;
17957 struct die_info
*die
17958 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17962 *new_info_ptr
= cur_ptr
;
17969 last_sibling
->sibling
= die
;
17971 last_sibling
= die
;
17975 /* Read a die, all of its descendents, and all of its siblings; set
17976 all of the fields of all of the dies correctly. Arguments are as
17977 in read_die_and_children.
17978 This the main entry point for reading a DIE and all its children. */
17980 static struct die_info
*
17981 read_die_and_siblings (const struct die_reader_specs
*reader
,
17982 const gdb_byte
*info_ptr
,
17983 const gdb_byte
**new_info_ptr
,
17984 struct die_info
*parent
)
17986 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17987 new_info_ptr
, parent
);
17989 if (dwarf_die_debug
)
17991 fprintf_unfiltered (gdb_stdlog
,
17992 "Read die from %s@0x%x of %s:\n",
17993 reader
->die_section
->get_name (),
17994 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17995 bfd_get_filename (reader
->abfd
));
17996 dump_die (die
, dwarf_die_debug
);
18002 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18004 The caller is responsible for filling in the extra attributes
18005 and updating (*DIEP)->num_attrs.
18006 Set DIEP to point to a newly allocated die with its information,
18007 except for its child, sibling, and parent fields. */
18009 static const gdb_byte
*
18010 read_full_die_1 (const struct die_reader_specs
*reader
,
18011 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18012 int num_extra_attrs
)
18014 unsigned int abbrev_number
, bytes_read
, i
;
18015 struct abbrev_info
*abbrev
;
18016 struct die_info
*die
;
18017 struct dwarf2_cu
*cu
= reader
->cu
;
18018 bfd
*abfd
= reader
->abfd
;
18020 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18021 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18022 info_ptr
+= bytes_read
;
18023 if (!abbrev_number
)
18029 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18031 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18033 bfd_get_filename (abfd
));
18035 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18036 die
->sect_off
= sect_off
;
18037 die
->tag
= abbrev
->tag
;
18038 die
->abbrev
= abbrev_number
;
18039 die
->has_children
= abbrev
->has_children
;
18041 /* Make the result usable.
18042 The caller needs to update num_attrs after adding the extra
18044 die
->num_attrs
= abbrev
->num_attrs
;
18046 std::vector
<int> indexes_that_need_reprocess
;
18047 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18049 bool need_reprocess
;
18051 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18052 info_ptr
, &need_reprocess
);
18053 if (need_reprocess
)
18054 indexes_that_need_reprocess
.push_back (i
);
18057 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18058 if (attr
!= nullptr)
18059 cu
->str_offsets_base
= DW_UNSND (attr
);
18061 attr
= die
->attr (DW_AT_loclists_base
);
18062 if (attr
!= nullptr)
18063 cu
->loclist_base
= DW_UNSND (attr
);
18065 auto maybe_addr_base
= die
->addr_base ();
18066 if (maybe_addr_base
.has_value ())
18067 cu
->addr_base
= *maybe_addr_base
;
18068 for (int index
: indexes_that_need_reprocess
)
18069 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18074 /* Read a die and all its attributes.
18075 Set DIEP to point to a newly allocated die with its information,
18076 except for its child, sibling, and parent fields. */
18078 static const gdb_byte
*
18079 read_full_die (const struct die_reader_specs
*reader
,
18080 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18082 const gdb_byte
*result
;
18084 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18086 if (dwarf_die_debug
)
18088 fprintf_unfiltered (gdb_stdlog
,
18089 "Read die from %s@0x%x of %s:\n",
18090 reader
->die_section
->get_name (),
18091 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18092 bfd_get_filename (reader
->abfd
));
18093 dump_die (*diep
, dwarf_die_debug
);
18100 /* Returns nonzero if TAG represents a type that we might generate a partial
18104 is_type_tag_for_partial (int tag
)
18109 /* Some types that would be reasonable to generate partial symbols for,
18110 that we don't at present. */
18111 case DW_TAG_array_type
:
18112 case DW_TAG_file_type
:
18113 case DW_TAG_ptr_to_member_type
:
18114 case DW_TAG_set_type
:
18115 case DW_TAG_string_type
:
18116 case DW_TAG_subroutine_type
:
18118 case DW_TAG_base_type
:
18119 case DW_TAG_class_type
:
18120 case DW_TAG_interface_type
:
18121 case DW_TAG_enumeration_type
:
18122 case DW_TAG_structure_type
:
18123 case DW_TAG_subrange_type
:
18124 case DW_TAG_typedef
:
18125 case DW_TAG_union_type
:
18132 /* Load all DIEs that are interesting for partial symbols into memory. */
18134 static struct partial_die_info
*
18135 load_partial_dies (const struct die_reader_specs
*reader
,
18136 const gdb_byte
*info_ptr
, int building_psymtab
)
18138 struct dwarf2_cu
*cu
= reader
->cu
;
18139 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18140 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18141 unsigned int bytes_read
;
18142 unsigned int load_all
= 0;
18143 int nesting_level
= 1;
18148 gdb_assert (cu
->per_cu
!= NULL
);
18149 if (cu
->per_cu
->load_all_dies
)
18153 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18157 &cu
->comp_unit_obstack
,
18158 hashtab_obstack_allocate
,
18159 dummy_obstack_deallocate
);
18163 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18165 /* A NULL abbrev means the end of a series of children. */
18166 if (abbrev
== NULL
)
18168 if (--nesting_level
== 0)
18171 info_ptr
+= bytes_read
;
18172 last_die
= parent_die
;
18173 parent_die
= parent_die
->die_parent
;
18177 /* Check for template arguments. We never save these; if
18178 they're seen, we just mark the parent, and go on our way. */
18179 if (parent_die
!= NULL
18180 && cu
->language
== language_cplus
18181 && (abbrev
->tag
== DW_TAG_template_type_param
18182 || abbrev
->tag
== DW_TAG_template_value_param
))
18184 parent_die
->has_template_arguments
= 1;
18188 /* We don't need a partial DIE for the template argument. */
18189 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18194 /* We only recurse into c++ subprograms looking for template arguments.
18195 Skip their other children. */
18197 && cu
->language
== language_cplus
18198 && parent_die
!= NULL
18199 && parent_die
->tag
== DW_TAG_subprogram
)
18201 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18205 /* Check whether this DIE is interesting enough to save. Normally
18206 we would not be interested in members here, but there may be
18207 later variables referencing them via DW_AT_specification (for
18208 static members). */
18210 && !is_type_tag_for_partial (abbrev
->tag
)
18211 && abbrev
->tag
!= DW_TAG_constant
18212 && abbrev
->tag
!= DW_TAG_enumerator
18213 && abbrev
->tag
!= DW_TAG_subprogram
18214 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18215 && abbrev
->tag
!= DW_TAG_lexical_block
18216 && abbrev
->tag
!= DW_TAG_variable
18217 && abbrev
->tag
!= DW_TAG_namespace
18218 && abbrev
->tag
!= DW_TAG_module
18219 && abbrev
->tag
!= DW_TAG_member
18220 && abbrev
->tag
!= DW_TAG_imported_unit
18221 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18223 /* Otherwise we skip to the next sibling, if any. */
18224 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18228 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18231 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18233 /* This two-pass algorithm for processing partial symbols has a
18234 high cost in cache pressure. Thus, handle some simple cases
18235 here which cover the majority of C partial symbols. DIEs
18236 which neither have specification tags in them, nor could have
18237 specification tags elsewhere pointing at them, can simply be
18238 processed and discarded.
18240 This segment is also optional; scan_partial_symbols and
18241 add_partial_symbol will handle these DIEs if we chain
18242 them in normally. When compilers which do not emit large
18243 quantities of duplicate debug information are more common,
18244 this code can probably be removed. */
18246 /* Any complete simple types at the top level (pretty much all
18247 of them, for a language without namespaces), can be processed
18249 if (parent_die
== NULL
18250 && pdi
.has_specification
== 0
18251 && pdi
.is_declaration
== 0
18252 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18253 || pdi
.tag
== DW_TAG_base_type
18254 || pdi
.tag
== DW_TAG_subrange_type
))
18256 if (building_psymtab
&& pdi
.name
!= NULL
)
18257 add_psymbol_to_list (pdi
.name
, false,
18258 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18259 psymbol_placement::STATIC
,
18260 0, cu
->language
, objfile
);
18261 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18265 /* The exception for DW_TAG_typedef with has_children above is
18266 a workaround of GCC PR debug/47510. In the case of this complaint
18267 type_name_or_error will error on such types later.
18269 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18270 it could not find the child DIEs referenced later, this is checked
18271 above. In correct DWARF DW_TAG_typedef should have no children. */
18273 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18274 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18275 "- DIE at %s [in module %s]"),
18276 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18278 /* If we're at the second level, and we're an enumerator, and
18279 our parent has no specification (meaning possibly lives in a
18280 namespace elsewhere), then we can add the partial symbol now
18281 instead of queueing it. */
18282 if (pdi
.tag
== DW_TAG_enumerator
18283 && parent_die
!= NULL
18284 && parent_die
->die_parent
== NULL
18285 && parent_die
->tag
== DW_TAG_enumeration_type
18286 && parent_die
->has_specification
== 0)
18288 if (pdi
.name
== NULL
)
18289 complaint (_("malformed enumerator DIE ignored"));
18290 else if (building_psymtab
)
18291 add_psymbol_to_list (pdi
.name
, false,
18292 VAR_DOMAIN
, LOC_CONST
, -1,
18293 cu
->language
== language_cplus
18294 ? psymbol_placement::GLOBAL
18295 : psymbol_placement::STATIC
,
18296 0, cu
->language
, objfile
);
18298 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18302 struct partial_die_info
*part_die
18303 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18305 /* We'll save this DIE so link it in. */
18306 part_die
->die_parent
= parent_die
;
18307 part_die
->die_sibling
= NULL
;
18308 part_die
->die_child
= NULL
;
18310 if (last_die
&& last_die
== parent_die
)
18311 last_die
->die_child
= part_die
;
18313 last_die
->die_sibling
= part_die
;
18315 last_die
= part_die
;
18317 if (first_die
== NULL
)
18318 first_die
= part_die
;
18320 /* Maybe add the DIE to the hash table. Not all DIEs that we
18321 find interesting need to be in the hash table, because we
18322 also have the parent/sibling/child chains; only those that we
18323 might refer to by offset later during partial symbol reading.
18325 For now this means things that might have be the target of a
18326 DW_AT_specification, DW_AT_abstract_origin, or
18327 DW_AT_extension. DW_AT_extension will refer only to
18328 namespaces; DW_AT_abstract_origin refers to functions (and
18329 many things under the function DIE, but we do not recurse
18330 into function DIEs during partial symbol reading) and
18331 possibly variables as well; DW_AT_specification refers to
18332 declarations. Declarations ought to have the DW_AT_declaration
18333 flag. It happens that GCC forgets to put it in sometimes, but
18334 only for functions, not for types.
18336 Adding more things than necessary to the hash table is harmless
18337 except for the performance cost. Adding too few will result in
18338 wasted time in find_partial_die, when we reread the compilation
18339 unit with load_all_dies set. */
18342 || abbrev
->tag
== DW_TAG_constant
18343 || abbrev
->tag
== DW_TAG_subprogram
18344 || abbrev
->tag
== DW_TAG_variable
18345 || abbrev
->tag
== DW_TAG_namespace
18346 || part_die
->is_declaration
)
18350 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18351 to_underlying (part_die
->sect_off
),
18356 /* For some DIEs we want to follow their children (if any). For C
18357 we have no reason to follow the children of structures; for other
18358 languages we have to, so that we can get at method physnames
18359 to infer fully qualified class names, for DW_AT_specification,
18360 and for C++ template arguments. For C++, we also look one level
18361 inside functions to find template arguments (if the name of the
18362 function does not already contain the template arguments).
18364 For Ada and Fortran, we need to scan the children of subprograms
18365 and lexical blocks as well because these languages allow the
18366 definition of nested entities that could be interesting for the
18367 debugger, such as nested subprograms for instance. */
18368 if (last_die
->has_children
18370 || last_die
->tag
== DW_TAG_namespace
18371 || last_die
->tag
== DW_TAG_module
18372 || last_die
->tag
== DW_TAG_enumeration_type
18373 || (cu
->language
== language_cplus
18374 && last_die
->tag
== DW_TAG_subprogram
18375 && (last_die
->name
== NULL
18376 || strchr (last_die
->name
, '<') == NULL
))
18377 || (cu
->language
!= language_c
18378 && (last_die
->tag
== DW_TAG_class_type
18379 || last_die
->tag
== DW_TAG_interface_type
18380 || last_die
->tag
== DW_TAG_structure_type
18381 || last_die
->tag
== DW_TAG_union_type
))
18382 || ((cu
->language
== language_ada
18383 || cu
->language
== language_fortran
)
18384 && (last_die
->tag
== DW_TAG_subprogram
18385 || last_die
->tag
== DW_TAG_lexical_block
))))
18388 parent_die
= last_die
;
18392 /* Otherwise we skip to the next sibling, if any. */
18393 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18395 /* Back to the top, do it again. */
18399 partial_die_info::partial_die_info (sect_offset sect_off_
,
18400 struct abbrev_info
*abbrev
)
18401 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18405 /* Read a minimal amount of information into the minimal die structure.
18406 INFO_PTR should point just after the initial uleb128 of a DIE. */
18409 partial_die_info::read (const struct die_reader_specs
*reader
,
18410 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18412 struct dwarf2_cu
*cu
= reader
->cu
;
18413 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18415 int has_low_pc_attr
= 0;
18416 int has_high_pc_attr
= 0;
18417 int high_pc_relative
= 0;
18419 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18422 bool need_reprocess
;
18423 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18424 info_ptr
, &need_reprocess
);
18425 /* String and address offsets that need to do the reprocessing have
18426 already been read at this point, so there is no need to wait until
18427 the loop terminates to do the reprocessing. */
18428 if (need_reprocess
)
18429 read_attribute_reprocess (reader
, &attr
);
18430 /* Store the data if it is of an attribute we want to keep in a
18431 partial symbol table. */
18437 case DW_TAG_compile_unit
:
18438 case DW_TAG_partial_unit
:
18439 case DW_TAG_type_unit
:
18440 /* Compilation units have a DW_AT_name that is a filename, not
18441 a source language identifier. */
18442 case DW_TAG_enumeration_type
:
18443 case DW_TAG_enumerator
:
18444 /* These tags always have simple identifiers already; no need
18445 to canonicalize them. */
18446 name
= DW_STRING (&attr
);
18450 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18453 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18458 case DW_AT_linkage_name
:
18459 case DW_AT_MIPS_linkage_name
:
18460 /* Note that both forms of linkage name might appear. We
18461 assume they will be the same, and we only store the last
18463 linkage_name
= attr
.value_as_string ();
18464 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18465 See https://github.com/rust-lang/rust/issues/32925. */
18466 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18467 && strchr (linkage_name
, '{') != NULL
)
18468 linkage_name
= NULL
;
18471 has_low_pc_attr
= 1;
18472 lowpc
= attr
.value_as_address ();
18474 case DW_AT_high_pc
:
18475 has_high_pc_attr
= 1;
18476 highpc
= attr
.value_as_address ();
18477 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18478 high_pc_relative
= 1;
18480 case DW_AT_location
:
18481 /* Support the .debug_loc offsets. */
18482 if (attr
.form_is_block ())
18484 d
.locdesc
= DW_BLOCK (&attr
);
18486 else if (attr
.form_is_section_offset ())
18488 dwarf2_complex_location_expr_complaint ();
18492 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18493 "partial symbol information");
18496 case DW_AT_external
:
18497 is_external
= DW_UNSND (&attr
);
18499 case DW_AT_declaration
:
18500 is_declaration
= DW_UNSND (&attr
);
18505 case DW_AT_abstract_origin
:
18506 case DW_AT_specification
:
18507 case DW_AT_extension
:
18508 has_specification
= 1;
18509 spec_offset
= attr
.get_ref_die_offset ();
18510 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18511 || cu
->per_cu
->is_dwz
);
18513 case DW_AT_sibling
:
18514 /* Ignore absolute siblings, they might point outside of
18515 the current compile unit. */
18516 if (attr
.form
== DW_FORM_ref_addr
)
18517 complaint (_("ignoring absolute DW_AT_sibling"));
18520 const gdb_byte
*buffer
= reader
->buffer
;
18521 sect_offset off
= attr
.get_ref_die_offset ();
18522 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18524 if (sibling_ptr
< info_ptr
)
18525 complaint (_("DW_AT_sibling points backwards"));
18526 else if (sibling_ptr
> reader
->buffer_end
)
18527 reader
->die_section
->overflow_complaint ();
18529 sibling
= sibling_ptr
;
18532 case DW_AT_byte_size
:
18535 case DW_AT_const_value
:
18536 has_const_value
= 1;
18538 case DW_AT_calling_convention
:
18539 /* DWARF doesn't provide a way to identify a program's source-level
18540 entry point. DW_AT_calling_convention attributes are only meant
18541 to describe functions' calling conventions.
18543 However, because it's a necessary piece of information in
18544 Fortran, and before DWARF 4 DW_CC_program was the only
18545 piece of debugging information whose definition refers to
18546 a 'main program' at all, several compilers marked Fortran
18547 main programs with DW_CC_program --- even when those
18548 functions use the standard calling conventions.
18550 Although DWARF now specifies a way to provide this
18551 information, we support this practice for backward
18553 if (DW_UNSND (&attr
) == DW_CC_program
18554 && cu
->language
== language_fortran
)
18555 main_subprogram
= 1;
18558 if (DW_UNSND (&attr
) == DW_INL_inlined
18559 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18560 may_be_inlined
= 1;
18564 if (tag
== DW_TAG_imported_unit
)
18566 d
.sect_off
= attr
.get_ref_die_offset ();
18567 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18568 || cu
->per_cu
->is_dwz
);
18572 case DW_AT_main_subprogram
:
18573 main_subprogram
= DW_UNSND (&attr
);
18578 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18579 but that requires a full DIE, so instead we just
18581 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18582 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18583 + (need_ranges_base
18587 /* Value of the DW_AT_ranges attribute is the offset in the
18588 .debug_ranges section. */
18589 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18600 /* For Ada, if both the name and the linkage name appear, we prefer
18601 the latter. This lets "catch exception" work better, regardless
18602 of the order in which the name and linkage name were emitted.
18603 Really, though, this is just a workaround for the fact that gdb
18604 doesn't store both the name and the linkage name. */
18605 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18606 name
= linkage_name
;
18608 if (high_pc_relative
)
18611 if (has_low_pc_attr
&& has_high_pc_attr
)
18613 /* When using the GNU linker, .gnu.linkonce. sections are used to
18614 eliminate duplicate copies of functions and vtables and such.
18615 The linker will arbitrarily choose one and discard the others.
18616 The AT_*_pc values for such functions refer to local labels in
18617 these sections. If the section from that file was discarded, the
18618 labels are not in the output, so the relocs get a value of 0.
18619 If this is a discarded function, mark the pc bounds as invalid,
18620 so that GDB will ignore it. */
18621 if (lowpc
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
18623 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18624 struct gdbarch
*gdbarch
= objfile
->arch ();
18626 complaint (_("DW_AT_low_pc %s is zero "
18627 "for DIE at %s [in module %s]"),
18628 paddress (gdbarch
, lowpc
),
18629 sect_offset_str (sect_off
),
18630 objfile_name (objfile
));
18632 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18633 else if (lowpc
>= highpc
)
18635 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18636 struct gdbarch
*gdbarch
= objfile
->arch ();
18638 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18639 "for DIE at %s [in module %s]"),
18640 paddress (gdbarch
, lowpc
),
18641 paddress (gdbarch
, highpc
),
18642 sect_offset_str (sect_off
),
18643 objfile_name (objfile
));
18652 /* Find a cached partial DIE at OFFSET in CU. */
18654 struct partial_die_info
*
18655 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18657 struct partial_die_info
*lookup_die
= NULL
;
18658 struct partial_die_info
part_die (sect_off
);
18660 lookup_die
= ((struct partial_die_info
*)
18661 htab_find_with_hash (partial_dies
, &part_die
,
18662 to_underlying (sect_off
)));
18667 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18668 except in the case of .debug_types DIEs which do not reference
18669 outside their CU (they do however referencing other types via
18670 DW_FORM_ref_sig8). */
18672 static const struct cu_partial_die_info
18673 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18675 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18676 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18677 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18678 struct partial_die_info
*pd
= NULL
;
18680 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18681 && cu
->header
.offset_in_cu_p (sect_off
))
18683 pd
= cu
->find_partial_die (sect_off
);
18686 /* We missed recording what we needed.
18687 Load all dies and try again. */
18688 per_cu
= cu
->per_cu
;
18692 /* TUs don't reference other CUs/TUs (except via type signatures). */
18693 if (cu
->per_cu
->is_debug_types
)
18695 error (_("Dwarf Error: Type Unit at offset %s contains"
18696 " external reference to offset %s [in module %s].\n"),
18697 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18698 bfd_get_filename (objfile
->obfd
));
18700 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18701 dwarf2_per_objfile
);
18703 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18704 load_partial_comp_unit (per_cu
, cu
->per_objfile
);
18706 per_cu
->cu
->last_used
= 0;
18707 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18710 /* If we didn't find it, and not all dies have been loaded,
18711 load them all and try again. */
18713 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18715 per_cu
->load_all_dies
= 1;
18717 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18718 THIS_CU->cu may already be in use. So we can't just free it and
18719 replace its DIEs with the ones we read in. Instead, we leave those
18720 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18721 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18723 load_partial_comp_unit (per_cu
, cu
->per_objfile
);
18725 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18729 internal_error (__FILE__
, __LINE__
,
18730 _("could not find partial DIE %s "
18731 "in cache [from module %s]\n"),
18732 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18733 return { per_cu
->cu
, pd
};
18736 /* See if we can figure out if the class lives in a namespace. We do
18737 this by looking for a member function; its demangled name will
18738 contain namespace info, if there is any. */
18741 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18742 struct dwarf2_cu
*cu
)
18744 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18745 what template types look like, because the demangler
18746 frequently doesn't give the same name as the debug info. We
18747 could fix this by only using the demangled name to get the
18748 prefix (but see comment in read_structure_type). */
18750 struct partial_die_info
*real_pdi
;
18751 struct partial_die_info
*child_pdi
;
18753 /* If this DIE (this DIE's specification, if any) has a parent, then
18754 we should not do this. We'll prepend the parent's fully qualified
18755 name when we create the partial symbol. */
18757 real_pdi
= struct_pdi
;
18758 while (real_pdi
->has_specification
)
18760 auto res
= find_partial_die (real_pdi
->spec_offset
,
18761 real_pdi
->spec_is_dwz
, cu
);
18762 real_pdi
= res
.pdi
;
18766 if (real_pdi
->die_parent
!= NULL
)
18769 for (child_pdi
= struct_pdi
->die_child
;
18771 child_pdi
= child_pdi
->die_sibling
)
18773 if (child_pdi
->tag
== DW_TAG_subprogram
18774 && child_pdi
->linkage_name
!= NULL
)
18776 gdb::unique_xmalloc_ptr
<char> actual_class_name
18777 (language_class_name_from_physname (cu
->language_defn
,
18778 child_pdi
->linkage_name
));
18779 if (actual_class_name
!= NULL
)
18781 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18782 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18789 /* Return true if a DIE with TAG may have the DW_AT_const_value
18793 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18797 case DW_TAG_constant
:
18798 case DW_TAG_enumerator
:
18799 case DW_TAG_formal_parameter
:
18800 case DW_TAG_template_value_param
:
18801 case DW_TAG_variable
:
18809 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18811 /* Once we've fixed up a die, there's no point in doing so again.
18812 This also avoids a memory leak if we were to call
18813 guess_partial_die_structure_name multiple times. */
18817 /* If we found a reference attribute and the DIE has no name, try
18818 to find a name in the referred to DIE. */
18820 if (name
== NULL
&& has_specification
)
18822 struct partial_die_info
*spec_die
;
18824 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18825 spec_die
= res
.pdi
;
18828 spec_die
->fixup (cu
);
18830 if (spec_die
->name
)
18832 name
= spec_die
->name
;
18834 /* Copy DW_AT_external attribute if it is set. */
18835 if (spec_die
->is_external
)
18836 is_external
= spec_die
->is_external
;
18840 if (!has_const_value
&& has_specification
18841 && can_have_DW_AT_const_value_p (tag
))
18843 struct partial_die_info
*spec_die
;
18845 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18846 spec_die
= res
.pdi
;
18849 spec_die
->fixup (cu
);
18851 if (spec_die
->has_const_value
)
18853 /* Copy DW_AT_const_value attribute if it is set. */
18854 has_const_value
= spec_die
->has_const_value
;
18858 /* Set default names for some unnamed DIEs. */
18860 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18861 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18863 /* If there is no parent die to provide a namespace, and there are
18864 children, see if we can determine the namespace from their linkage
18866 if (cu
->language
== language_cplus
18867 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18868 && die_parent
== NULL
18870 && (tag
== DW_TAG_class_type
18871 || tag
== DW_TAG_structure_type
18872 || tag
== DW_TAG_union_type
))
18873 guess_partial_die_structure_name (this, cu
);
18875 /* GCC might emit a nameless struct or union that has a linkage
18876 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18878 && (tag
== DW_TAG_class_type
18879 || tag
== DW_TAG_interface_type
18880 || tag
== DW_TAG_structure_type
18881 || tag
== DW_TAG_union_type
)
18882 && linkage_name
!= NULL
)
18884 gdb::unique_xmalloc_ptr
<char> demangled
18885 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18886 if (demangled
!= nullptr)
18890 /* Strip any leading namespaces/classes, keep only the base name.
18891 DW_AT_name for named DIEs does not contain the prefixes. */
18892 base
= strrchr (demangled
.get (), ':');
18893 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18896 base
= demangled
.get ();
18898 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18899 name
= objfile
->intern (base
);
18906 /* Read the .debug_loclists header contents from the given SECTION in the
18909 read_loclist_header (struct loclist_header
*header
,
18910 struct dwarf2_section_info
*section
)
18912 unsigned int bytes_read
;
18913 bfd
*abfd
= section
->get_bfd_owner ();
18914 const gdb_byte
*info_ptr
= section
->buffer
;
18915 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18916 info_ptr
+= bytes_read
;
18917 header
->version
= read_2_bytes (abfd
, info_ptr
);
18919 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18921 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18923 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18926 /* Return the DW_AT_loclists_base value for the CU. */
18928 lookup_loclist_base (struct dwarf2_cu
*cu
)
18930 /* For the .dwo unit, the loclist_base points to the first offset following
18931 the header. The header consists of the following entities-
18932 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18934 2. version (2 bytes)
18935 3. address size (1 byte)
18936 4. segment selector size (1 byte)
18937 5. offset entry count (4 bytes)
18938 These sizes are derived as per the DWARFv5 standard. */
18939 if (cu
->dwo_unit
!= nullptr)
18941 if (cu
->header
.initial_length_size
== 4)
18942 return LOCLIST_HEADER_SIZE32
;
18943 return LOCLIST_HEADER_SIZE64
;
18945 return cu
->loclist_base
;
18948 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18949 array of offsets in the .debug_loclists section. */
18951 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18953 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18954 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18955 bfd
*abfd
= objfile
->obfd
;
18956 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18957 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18959 section
->read (objfile
);
18960 if (section
->buffer
== NULL
)
18961 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18962 "section [in module %s]"), objfile_name (objfile
));
18963 struct loclist_header header
;
18964 read_loclist_header (&header
, section
);
18965 if (loclist_index
>= header
.offset_entry_count
)
18966 complaint (_("DW_FORM_loclistx pointing outside of "
18967 ".debug_loclists offset array [in module %s]"),
18968 objfile_name (objfile
));
18969 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18971 complaint (_("DW_FORM_loclistx pointing outside of "
18972 ".debug_loclists section [in module %s]"),
18973 objfile_name (objfile
));
18974 const gdb_byte
*info_ptr
18975 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18977 if (cu
->header
.offset_size
== 4)
18978 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18980 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18983 /* Process the attributes that had to be skipped in the first round. These
18984 attributes are the ones that need str_offsets_base or addr_base attributes.
18985 They could not have been processed in the first round, because at the time
18986 the values of str_offsets_base or addr_base may not have been known. */
18988 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18989 struct attribute
*attr
)
18991 struct dwarf2_cu
*cu
= reader
->cu
;
18992 switch (attr
->form
)
18994 case DW_FORM_addrx
:
18995 case DW_FORM_GNU_addr_index
:
18996 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18998 case DW_FORM_loclistx
:
18999 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19002 case DW_FORM_strx1
:
19003 case DW_FORM_strx2
:
19004 case DW_FORM_strx3
:
19005 case DW_FORM_strx4
:
19006 case DW_FORM_GNU_str_index
:
19008 unsigned int str_index
= DW_UNSND (attr
);
19009 if (reader
->dwo_file
!= NULL
)
19011 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19012 DW_STRING_IS_CANONICAL (attr
) = 0;
19016 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19017 DW_STRING_IS_CANONICAL (attr
) = 0;
19022 gdb_assert_not_reached (_("Unexpected DWARF form."));
19026 /* Read an attribute value described by an attribute form. */
19028 static const gdb_byte
*
19029 read_attribute_value (const struct die_reader_specs
*reader
,
19030 struct attribute
*attr
, unsigned form
,
19031 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19032 bool *need_reprocess
)
19034 struct dwarf2_cu
*cu
= reader
->cu
;
19035 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19036 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19037 bfd
*abfd
= reader
->abfd
;
19038 struct comp_unit_head
*cu_header
= &cu
->header
;
19039 unsigned int bytes_read
;
19040 struct dwarf_block
*blk
;
19041 *need_reprocess
= false;
19043 attr
->form
= (enum dwarf_form
) form
;
19046 case DW_FORM_ref_addr
:
19047 if (cu
->header
.version
== 2)
19048 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19051 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19053 info_ptr
+= bytes_read
;
19055 case DW_FORM_GNU_ref_alt
:
19056 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19057 info_ptr
+= bytes_read
;
19061 struct gdbarch
*gdbarch
= objfile
->arch ();
19062 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19063 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19064 info_ptr
+= bytes_read
;
19067 case DW_FORM_block2
:
19068 blk
= dwarf_alloc_block (cu
);
19069 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19071 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19072 info_ptr
+= blk
->size
;
19073 DW_BLOCK (attr
) = blk
;
19075 case DW_FORM_block4
:
19076 blk
= dwarf_alloc_block (cu
);
19077 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19079 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19080 info_ptr
+= blk
->size
;
19081 DW_BLOCK (attr
) = blk
;
19083 case DW_FORM_data2
:
19084 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19087 case DW_FORM_data4
:
19088 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19091 case DW_FORM_data8
:
19092 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19095 case DW_FORM_data16
:
19096 blk
= dwarf_alloc_block (cu
);
19098 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19100 DW_BLOCK (attr
) = blk
;
19102 case DW_FORM_sec_offset
:
19103 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19104 info_ptr
+= bytes_read
;
19106 case DW_FORM_loclistx
:
19108 *need_reprocess
= true;
19109 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19110 info_ptr
+= bytes_read
;
19113 case DW_FORM_string
:
19114 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19115 DW_STRING_IS_CANONICAL (attr
) = 0;
19116 info_ptr
+= bytes_read
;
19119 if (!cu
->per_cu
->is_dwz
)
19121 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19122 abfd
, info_ptr
, cu_header
,
19124 DW_STRING_IS_CANONICAL (attr
) = 0;
19125 info_ptr
+= bytes_read
;
19129 case DW_FORM_line_strp
:
19130 if (!cu
->per_cu
->is_dwz
)
19133 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
19135 DW_STRING_IS_CANONICAL (attr
) = 0;
19136 info_ptr
+= bytes_read
;
19140 case DW_FORM_GNU_strp_alt
:
19142 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19143 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19146 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19147 DW_STRING_IS_CANONICAL (attr
) = 0;
19148 info_ptr
+= bytes_read
;
19151 case DW_FORM_exprloc
:
19152 case DW_FORM_block
:
19153 blk
= dwarf_alloc_block (cu
);
19154 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19155 info_ptr
+= bytes_read
;
19156 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19157 info_ptr
+= blk
->size
;
19158 DW_BLOCK (attr
) = blk
;
19160 case DW_FORM_block1
:
19161 blk
= dwarf_alloc_block (cu
);
19162 blk
->size
= read_1_byte (abfd
, info_ptr
);
19164 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19165 info_ptr
+= blk
->size
;
19166 DW_BLOCK (attr
) = blk
;
19168 case DW_FORM_data1
:
19169 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19173 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19176 case DW_FORM_flag_present
:
19177 DW_UNSND (attr
) = 1;
19179 case DW_FORM_sdata
:
19180 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19181 info_ptr
+= bytes_read
;
19183 case DW_FORM_udata
:
19184 case DW_FORM_rnglistx
:
19185 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19186 info_ptr
+= bytes_read
;
19189 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19190 + read_1_byte (abfd
, info_ptr
));
19194 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19195 + read_2_bytes (abfd
, info_ptr
));
19199 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19200 + read_4_bytes (abfd
, info_ptr
));
19204 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19205 + read_8_bytes (abfd
, info_ptr
));
19208 case DW_FORM_ref_sig8
:
19209 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19212 case DW_FORM_ref_udata
:
19213 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19214 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19215 info_ptr
+= bytes_read
;
19217 case DW_FORM_indirect
:
19218 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19219 info_ptr
+= bytes_read
;
19220 if (form
== DW_FORM_implicit_const
)
19222 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19223 info_ptr
+= bytes_read
;
19225 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19226 info_ptr
, need_reprocess
);
19228 case DW_FORM_implicit_const
:
19229 DW_SND (attr
) = implicit_const
;
19231 case DW_FORM_addrx
:
19232 case DW_FORM_GNU_addr_index
:
19233 *need_reprocess
= true;
19234 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19235 info_ptr
+= bytes_read
;
19238 case DW_FORM_strx1
:
19239 case DW_FORM_strx2
:
19240 case DW_FORM_strx3
:
19241 case DW_FORM_strx4
:
19242 case DW_FORM_GNU_str_index
:
19244 ULONGEST str_index
;
19245 if (form
== DW_FORM_strx1
)
19247 str_index
= read_1_byte (abfd
, info_ptr
);
19250 else if (form
== DW_FORM_strx2
)
19252 str_index
= read_2_bytes (abfd
, info_ptr
);
19255 else if (form
== DW_FORM_strx3
)
19257 str_index
= read_3_bytes (abfd
, info_ptr
);
19260 else if (form
== DW_FORM_strx4
)
19262 str_index
= read_4_bytes (abfd
, info_ptr
);
19267 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19268 info_ptr
+= bytes_read
;
19270 *need_reprocess
= true;
19271 DW_UNSND (attr
) = str_index
;
19275 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19276 dwarf_form_name (form
),
19277 bfd_get_filename (abfd
));
19281 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19282 attr
->form
= DW_FORM_GNU_ref_alt
;
19284 /* We have seen instances where the compiler tried to emit a byte
19285 size attribute of -1 which ended up being encoded as an unsigned
19286 0xffffffff. Although 0xffffffff is technically a valid size value,
19287 an object of this size seems pretty unlikely so we can relatively
19288 safely treat these cases as if the size attribute was invalid and
19289 treat them as zero by default. */
19290 if (attr
->name
== DW_AT_byte_size
19291 && form
== DW_FORM_data4
19292 && DW_UNSND (attr
) >= 0xffffffff)
19295 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19296 hex_string (DW_UNSND (attr
)));
19297 DW_UNSND (attr
) = 0;
19303 /* Read an attribute described by an abbreviated attribute. */
19305 static const gdb_byte
*
19306 read_attribute (const struct die_reader_specs
*reader
,
19307 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19308 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19310 attr
->name
= abbrev
->name
;
19311 return read_attribute_value (reader
, attr
, abbrev
->form
,
19312 abbrev
->implicit_const
, info_ptr
,
19316 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19318 static const char *
19319 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19320 LONGEST str_offset
)
19322 return dwarf2_per_objfile
->per_bfd
->str
.read_string
19323 (dwarf2_per_objfile
->objfile
, str_offset
, "DW_FORM_strp");
19326 /* Return pointer to string at .debug_str offset as read from BUF.
19327 BUF is assumed to be in a compilation unit described by CU_HEADER.
19328 Return *BYTES_READ_PTR count of bytes read from BUF. */
19330 static const char *
19331 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19332 const gdb_byte
*buf
,
19333 const struct comp_unit_head
*cu_header
,
19334 unsigned int *bytes_read_ptr
)
19336 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19338 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
19344 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19345 const struct comp_unit_head
*cu_header
,
19346 unsigned int *bytes_read_ptr
)
19348 bfd
*abfd
= objfile
->obfd
;
19349 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19351 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19354 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19355 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19356 ADDR_SIZE is the size of addresses from the CU header. */
19359 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19360 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19363 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19364 bfd
*abfd
= objfile
->obfd
;
19365 const gdb_byte
*info_ptr
;
19366 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19368 dwarf2_per_objfile
->per_bfd
->addr
.read (objfile
);
19369 if (dwarf2_per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19370 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19371 objfile_name (objfile
));
19372 if (addr_base_or_zero
+ addr_index
* addr_size
19373 >= dwarf2_per_objfile
->per_bfd
->addr
.size
)
19374 error (_("DW_FORM_addr_index pointing outside of "
19375 ".debug_addr section [in module %s]"),
19376 objfile_name (objfile
));
19377 info_ptr
= (dwarf2_per_objfile
->per_bfd
->addr
.buffer
19378 + addr_base_or_zero
+ addr_index
* addr_size
);
19379 if (addr_size
== 4)
19380 return bfd_get_32 (abfd
, info_ptr
);
19382 return bfd_get_64 (abfd
, info_ptr
);
19385 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19388 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19390 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19391 cu
->addr_base
, cu
->header
.addr_size
);
19394 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19397 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19398 unsigned int *bytes_read
)
19400 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19401 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19403 return read_addr_index (cu
, addr_index
);
19409 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19410 dwarf2_per_objfile
*dwarf2_per_objfile
,
19411 unsigned int addr_index
)
19413 struct dwarf2_cu
*cu
= per_cu
->cu
;
19414 gdb::optional
<ULONGEST
> addr_base
;
19417 /* We need addr_base and addr_size.
19418 If we don't have PER_CU->cu, we have to get it.
19419 Nasty, but the alternative is storing the needed info in PER_CU,
19420 which at this point doesn't seem justified: it's not clear how frequently
19421 it would get used and it would increase the size of every PER_CU.
19422 Entry points like dwarf2_per_cu_addr_size do a similar thing
19423 so we're not in uncharted territory here.
19424 Alas we need to be a bit more complicated as addr_base is contained
19427 We don't need to read the entire CU(/TU).
19428 We just need the header and top level die.
19430 IWBN to use the aging mechanism to let us lazily later discard the CU.
19431 For now we skip this optimization. */
19435 addr_base
= cu
->addr_base
;
19436 addr_size
= cu
->header
.addr_size
;
19440 cutu_reader
reader (per_cu
, dwarf2_per_objfile
, NULL
, 0, false);
19441 addr_base
= reader
.cu
->addr_base
;
19442 addr_size
= reader
.cu
->header
.addr_size
;
19445 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19449 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19450 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19453 static const char *
19454 read_str_index (struct dwarf2_cu
*cu
,
19455 struct dwarf2_section_info
*str_section
,
19456 struct dwarf2_section_info
*str_offsets_section
,
19457 ULONGEST str_offsets_base
, ULONGEST str_index
)
19459 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19460 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19461 const char *objf_name
= objfile_name (objfile
);
19462 bfd
*abfd
= objfile
->obfd
;
19463 const gdb_byte
*info_ptr
;
19464 ULONGEST str_offset
;
19465 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19467 str_section
->read (objfile
);
19468 str_offsets_section
->read (objfile
);
19469 if (str_section
->buffer
== NULL
)
19470 error (_("%s used without %s section"
19471 " in CU at offset %s [in module %s]"),
19472 form_name
, str_section
->get_name (),
19473 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19474 if (str_offsets_section
->buffer
== NULL
)
19475 error (_("%s used without %s section"
19476 " in CU at offset %s [in module %s]"),
19477 form_name
, str_section
->get_name (),
19478 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19479 info_ptr
= (str_offsets_section
->buffer
19481 + str_index
* cu
->header
.offset_size
);
19482 if (cu
->header
.offset_size
== 4)
19483 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19485 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19486 if (str_offset
>= str_section
->size
)
19487 error (_("Offset from %s pointing outside of"
19488 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19489 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19490 return (const char *) (str_section
->buffer
+ str_offset
);
19493 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19495 static const char *
19496 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19498 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19499 ? reader
->cu
->header
.addr_size
: 0;
19500 return read_str_index (reader
->cu
,
19501 &reader
->dwo_file
->sections
.str
,
19502 &reader
->dwo_file
->sections
.str_offsets
,
19503 str_offsets_base
, str_index
);
19506 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19508 static const char *
19509 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19511 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19512 const char *objf_name
= objfile_name (objfile
);
19513 static const char form_name
[] = "DW_FORM_GNU_str_index";
19514 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19516 if (!cu
->str_offsets_base
.has_value ())
19517 error (_("%s used in Fission stub without %s"
19518 " in CU at offset 0x%lx [in module %s]"),
19519 form_name
, str_offsets_attr_name
,
19520 (long) cu
->header
.offset_size
, objf_name
);
19522 return read_str_index (cu
,
19523 &cu
->per_objfile
->per_bfd
->str
,
19524 &cu
->per_objfile
->per_bfd
->str_offsets
,
19525 *cu
->str_offsets_base
, str_index
);
19528 /* Return the length of an LEB128 number in BUF. */
19531 leb128_size (const gdb_byte
*buf
)
19533 const gdb_byte
*begin
= buf
;
19539 if ((byte
& 128) == 0)
19540 return buf
- begin
;
19545 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19554 cu
->language
= language_c
;
19557 case DW_LANG_C_plus_plus
:
19558 case DW_LANG_C_plus_plus_11
:
19559 case DW_LANG_C_plus_plus_14
:
19560 cu
->language
= language_cplus
;
19563 cu
->language
= language_d
;
19565 case DW_LANG_Fortran77
:
19566 case DW_LANG_Fortran90
:
19567 case DW_LANG_Fortran95
:
19568 case DW_LANG_Fortran03
:
19569 case DW_LANG_Fortran08
:
19570 cu
->language
= language_fortran
;
19573 cu
->language
= language_go
;
19575 case DW_LANG_Mips_Assembler
:
19576 cu
->language
= language_asm
;
19578 case DW_LANG_Ada83
:
19579 case DW_LANG_Ada95
:
19580 cu
->language
= language_ada
;
19582 case DW_LANG_Modula2
:
19583 cu
->language
= language_m2
;
19585 case DW_LANG_Pascal83
:
19586 cu
->language
= language_pascal
;
19589 cu
->language
= language_objc
;
19592 case DW_LANG_Rust_old
:
19593 cu
->language
= language_rust
;
19595 case DW_LANG_Cobol74
:
19596 case DW_LANG_Cobol85
:
19598 cu
->language
= language_minimal
;
19601 cu
->language_defn
= language_def (cu
->language
);
19604 /* Return the named attribute or NULL if not there. */
19606 static struct attribute
*
19607 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19612 struct attribute
*spec
= NULL
;
19614 for (i
= 0; i
< die
->num_attrs
; ++i
)
19616 if (die
->attrs
[i
].name
== name
)
19617 return &die
->attrs
[i
];
19618 if (die
->attrs
[i
].name
== DW_AT_specification
19619 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19620 spec
= &die
->attrs
[i
];
19626 die
= follow_die_ref (die
, spec
, &cu
);
19632 /* Return the string associated with a string-typed attribute, or NULL if it
19633 is either not found or is of an incorrect type. */
19635 static const char *
19636 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19638 struct attribute
*attr
;
19639 const char *str
= NULL
;
19641 attr
= dwarf2_attr (die
, name
, cu
);
19645 str
= attr
->value_as_string ();
19646 if (str
== nullptr)
19647 complaint (_("string type expected for attribute %s for "
19648 "DIE at %s in module %s"),
19649 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19650 objfile_name (cu
->per_objfile
->objfile
));
19656 /* Return the dwo name or NULL if not present. If present, it is in either
19657 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19658 static const char *
19659 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19661 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19662 if (dwo_name
== nullptr)
19663 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19667 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19668 and holds a non-zero value. This function should only be used for
19669 DW_FORM_flag or DW_FORM_flag_present attributes. */
19672 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19674 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19676 return (attr
&& DW_UNSND (attr
));
19680 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19682 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19683 which value is non-zero. However, we have to be careful with
19684 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19685 (via dwarf2_flag_true_p) follows this attribute. So we may
19686 end up accidently finding a declaration attribute that belongs
19687 to a different DIE referenced by the specification attribute,
19688 even though the given DIE does not have a declaration attribute. */
19689 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19690 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19693 /* Return the die giving the specification for DIE, if there is
19694 one. *SPEC_CU is the CU containing DIE on input, and the CU
19695 containing the return value on output. If there is no
19696 specification, but there is an abstract origin, that is
19699 static struct die_info
*
19700 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19702 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19705 if (spec_attr
== NULL
)
19706 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19708 if (spec_attr
== NULL
)
19711 return follow_die_ref (die
, spec_attr
, spec_cu
);
19714 /* Stub for free_line_header to match void * callback types. */
19717 free_line_header_voidp (void *arg
)
19719 struct line_header
*lh
= (struct line_header
*) arg
;
19724 /* A convenience function to find the proper .debug_line section for a CU. */
19726 static struct dwarf2_section_info
*
19727 get_debug_line_section (struct dwarf2_cu
*cu
)
19729 struct dwarf2_section_info
*section
;
19730 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19732 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19734 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19735 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19736 else if (cu
->per_cu
->is_dwz
)
19738 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19740 section
= &dwz
->line
;
19743 section
= &dwarf2_per_objfile
->per_bfd
->line
;
19748 /* Read the statement program header starting at OFFSET in
19749 .debug_line, or .debug_line.dwo. Return a pointer
19750 to a struct line_header, allocated using xmalloc.
19751 Returns NULL if there is a problem reading the header, e.g., if it
19752 has a version we don't understand.
19754 NOTE: the strings in the include directory and file name tables of
19755 the returned object point into the dwarf line section buffer,
19756 and must not be freed. */
19758 static line_header_up
19759 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19761 struct dwarf2_section_info
*section
;
19762 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19764 section
= get_debug_line_section (cu
);
19765 section
->read (dwarf2_per_objfile
->objfile
);
19766 if (section
->buffer
== NULL
)
19768 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19769 complaint (_("missing .debug_line.dwo section"));
19771 complaint (_("missing .debug_line section"));
19775 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19776 dwarf2_per_objfile
, section
,
19780 /* Subroutine of dwarf_decode_lines to simplify it.
19781 Return the file name of the psymtab for the given file_entry.
19782 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19783 If space for the result is malloc'd, *NAME_HOLDER will be set.
19784 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19786 static const char *
19787 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19788 const dwarf2_psymtab
*pst
,
19789 const char *comp_dir
,
19790 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19792 const char *include_name
= fe
.name
;
19793 const char *include_name_to_compare
= include_name
;
19794 const char *pst_filename
;
19797 const char *dir_name
= fe
.include_dir (lh
);
19799 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19800 if (!IS_ABSOLUTE_PATH (include_name
)
19801 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19803 /* Avoid creating a duplicate psymtab for PST.
19804 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19805 Before we do the comparison, however, we need to account
19806 for DIR_NAME and COMP_DIR.
19807 First prepend dir_name (if non-NULL). If we still don't
19808 have an absolute path prepend comp_dir (if non-NULL).
19809 However, the directory we record in the include-file's
19810 psymtab does not contain COMP_DIR (to match the
19811 corresponding symtab(s)).
19816 bash$ gcc -g ./hello.c
19817 include_name = "hello.c"
19819 DW_AT_comp_dir = comp_dir = "/tmp"
19820 DW_AT_name = "./hello.c"
19824 if (dir_name
!= NULL
)
19826 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19827 include_name
, (char *) NULL
));
19828 include_name
= name_holder
->get ();
19829 include_name_to_compare
= include_name
;
19831 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19833 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19834 include_name
, (char *) NULL
));
19835 include_name_to_compare
= hold_compare
.get ();
19839 pst_filename
= pst
->filename
;
19840 gdb::unique_xmalloc_ptr
<char> copied_name
;
19841 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19843 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19844 pst_filename
, (char *) NULL
));
19845 pst_filename
= copied_name
.get ();
19848 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19852 return include_name
;
19855 /* State machine to track the state of the line number program. */
19857 class lnp_state_machine
19860 /* Initialize a machine state for the start of a line number
19862 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19863 bool record_lines_p
);
19865 file_entry
*current_file ()
19867 /* lh->file_names is 0-based, but the file name numbers in the
19868 statement program are 1-based. */
19869 return m_line_header
->file_name_at (m_file
);
19872 /* Record the line in the state machine. END_SEQUENCE is true if
19873 we're processing the end of a sequence. */
19874 void record_line (bool end_sequence
);
19876 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19877 nop-out rest of the lines in this sequence. */
19878 void check_line_address (struct dwarf2_cu
*cu
,
19879 const gdb_byte
*line_ptr
,
19880 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19882 void handle_set_discriminator (unsigned int discriminator
)
19884 m_discriminator
= discriminator
;
19885 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19888 /* Handle DW_LNE_set_address. */
19889 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19892 address
+= baseaddr
;
19893 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19896 /* Handle DW_LNS_advance_pc. */
19897 void handle_advance_pc (CORE_ADDR adjust
);
19899 /* Handle a special opcode. */
19900 void handle_special_opcode (unsigned char op_code
);
19902 /* Handle DW_LNS_advance_line. */
19903 void handle_advance_line (int line_delta
)
19905 advance_line (line_delta
);
19908 /* Handle DW_LNS_set_file. */
19909 void handle_set_file (file_name_index file
);
19911 /* Handle DW_LNS_negate_stmt. */
19912 void handle_negate_stmt ()
19914 m_is_stmt
= !m_is_stmt
;
19917 /* Handle DW_LNS_const_add_pc. */
19918 void handle_const_add_pc ();
19920 /* Handle DW_LNS_fixed_advance_pc. */
19921 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19923 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19927 /* Handle DW_LNS_copy. */
19928 void handle_copy ()
19930 record_line (false);
19931 m_discriminator
= 0;
19934 /* Handle DW_LNE_end_sequence. */
19935 void handle_end_sequence ()
19937 m_currently_recording_lines
= true;
19941 /* Advance the line by LINE_DELTA. */
19942 void advance_line (int line_delta
)
19944 m_line
+= line_delta
;
19946 if (line_delta
!= 0)
19947 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19950 struct dwarf2_cu
*m_cu
;
19952 gdbarch
*m_gdbarch
;
19954 /* True if we're recording lines.
19955 Otherwise we're building partial symtabs and are just interested in
19956 finding include files mentioned by the line number program. */
19957 bool m_record_lines_p
;
19959 /* The line number header. */
19960 line_header
*m_line_header
;
19962 /* These are part of the standard DWARF line number state machine,
19963 and initialized according to the DWARF spec. */
19965 unsigned char m_op_index
= 0;
19966 /* The line table index of the current file. */
19967 file_name_index m_file
= 1;
19968 unsigned int m_line
= 1;
19970 /* These are initialized in the constructor. */
19972 CORE_ADDR m_address
;
19974 unsigned int m_discriminator
;
19976 /* Additional bits of state we need to track. */
19978 /* The last file that we called dwarf2_start_subfile for.
19979 This is only used for TLLs. */
19980 unsigned int m_last_file
= 0;
19981 /* The last file a line number was recorded for. */
19982 struct subfile
*m_last_subfile
= NULL
;
19984 /* When true, record the lines we decode. */
19985 bool m_currently_recording_lines
= false;
19987 /* The last line number that was recorded, used to coalesce
19988 consecutive entries for the same line. This can happen, for
19989 example, when discriminators are present. PR 17276. */
19990 unsigned int m_last_line
= 0;
19991 bool m_line_has_non_zero_discriminator
= false;
19995 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19997 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19998 / m_line_header
->maximum_ops_per_instruction
)
19999 * m_line_header
->minimum_instruction_length
);
20000 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20001 m_op_index
= ((m_op_index
+ adjust
)
20002 % m_line_header
->maximum_ops_per_instruction
);
20006 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20008 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20009 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20010 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20011 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20012 / m_line_header
->maximum_ops_per_instruction
)
20013 * m_line_header
->minimum_instruction_length
);
20014 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20015 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20016 % m_line_header
->maximum_ops_per_instruction
);
20018 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20019 advance_line (line_delta
);
20020 record_line (false);
20021 m_discriminator
= 0;
20025 lnp_state_machine::handle_set_file (file_name_index file
)
20029 const file_entry
*fe
= current_file ();
20031 dwarf2_debug_line_missing_file_complaint ();
20032 else if (m_record_lines_p
)
20034 const char *dir
= fe
->include_dir (m_line_header
);
20036 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20037 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20038 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20043 lnp_state_machine::handle_const_add_pc ()
20046 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20049 = (((m_op_index
+ adjust
)
20050 / m_line_header
->maximum_ops_per_instruction
)
20051 * m_line_header
->minimum_instruction_length
);
20053 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20054 m_op_index
= ((m_op_index
+ adjust
)
20055 % m_line_header
->maximum_ops_per_instruction
);
20058 /* Return non-zero if we should add LINE to the line number table.
20059 LINE is the line to add, LAST_LINE is the last line that was added,
20060 LAST_SUBFILE is the subfile for LAST_LINE.
20061 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20062 had a non-zero discriminator.
20064 We have to be careful in the presence of discriminators.
20065 E.g., for this line:
20067 for (i = 0; i < 100000; i++);
20069 clang can emit four line number entries for that one line,
20070 each with a different discriminator.
20071 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20073 However, we want gdb to coalesce all four entries into one.
20074 Otherwise the user could stepi into the middle of the line and
20075 gdb would get confused about whether the pc really was in the
20076 middle of the line.
20078 Things are further complicated by the fact that two consecutive
20079 line number entries for the same line is a heuristic used by gcc
20080 to denote the end of the prologue. So we can't just discard duplicate
20081 entries, we have to be selective about it. The heuristic we use is
20082 that we only collapse consecutive entries for the same line if at least
20083 one of those entries has a non-zero discriminator. PR 17276.
20085 Note: Addresses in the line number state machine can never go backwards
20086 within one sequence, thus this coalescing is ok. */
20089 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20090 unsigned int line
, unsigned int last_line
,
20091 int line_has_non_zero_discriminator
,
20092 struct subfile
*last_subfile
)
20094 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20096 if (line
!= last_line
)
20098 /* Same line for the same file that we've seen already.
20099 As a last check, for pr 17276, only record the line if the line
20100 has never had a non-zero discriminator. */
20101 if (!line_has_non_zero_discriminator
)
20106 /* Use the CU's builder to record line number LINE beginning at
20107 address ADDRESS in the line table of subfile SUBFILE. */
20110 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20111 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20112 struct dwarf2_cu
*cu
)
20114 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20116 if (dwarf_line_debug
)
20118 fprintf_unfiltered (gdb_stdlog
,
20119 "Recording line %u, file %s, address %s\n",
20120 line
, lbasename (subfile
->name
),
20121 paddress (gdbarch
, address
));
20125 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20128 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20129 Mark the end of a set of line number records.
20130 The arguments are the same as for dwarf_record_line_1.
20131 If SUBFILE is NULL the request is ignored. */
20134 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20135 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20137 if (subfile
== NULL
)
20140 if (dwarf_line_debug
)
20142 fprintf_unfiltered (gdb_stdlog
,
20143 "Finishing current line, file %s, address %s\n",
20144 lbasename (subfile
->name
),
20145 paddress (gdbarch
, address
));
20148 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20152 lnp_state_machine::record_line (bool end_sequence
)
20154 if (dwarf_line_debug
)
20156 fprintf_unfiltered (gdb_stdlog
,
20157 "Processing actual line %u: file %u,"
20158 " address %s, is_stmt %u, discrim %u%s\n",
20160 paddress (m_gdbarch
, m_address
),
20161 m_is_stmt
, m_discriminator
,
20162 (end_sequence
? "\t(end sequence)" : ""));
20165 file_entry
*fe
= current_file ();
20168 dwarf2_debug_line_missing_file_complaint ();
20169 /* For now we ignore lines not starting on an instruction boundary.
20170 But not when processing end_sequence for compatibility with the
20171 previous version of the code. */
20172 else if (m_op_index
== 0 || end_sequence
)
20174 fe
->included_p
= 1;
20175 if (m_record_lines_p
)
20177 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20180 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20181 m_currently_recording_lines
? m_cu
: nullptr);
20186 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20188 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20189 m_line_has_non_zero_discriminator
,
20192 buildsym_compunit
*builder
= m_cu
->get_builder ();
20193 dwarf_record_line_1 (m_gdbarch
,
20194 builder
->get_current_subfile (),
20195 m_line
, m_address
, is_stmt
,
20196 m_currently_recording_lines
? m_cu
: nullptr);
20198 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20199 m_last_line
= m_line
;
20205 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20206 line_header
*lh
, bool record_lines_p
)
20210 m_record_lines_p
= record_lines_p
;
20211 m_line_header
= lh
;
20213 m_currently_recording_lines
= true;
20215 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20216 was a line entry for it so that the backend has a chance to adjust it
20217 and also record it in case it needs it. This is currently used by MIPS
20218 code, cf. `mips_adjust_dwarf2_line'. */
20219 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20220 m_is_stmt
= lh
->default_is_stmt
;
20221 m_discriminator
= 0;
20225 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20226 const gdb_byte
*line_ptr
,
20227 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20229 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20230 the pc range of the CU. However, we restrict the test to only ADDRESS
20231 values of zero to preserve GDB's previous behaviour which is to handle
20232 the specific case of a function being GC'd by the linker. */
20234 if (address
== 0 && address
< unrelocated_lowpc
)
20236 /* This line table is for a function which has been
20237 GCd by the linker. Ignore it. PR gdb/12528 */
20239 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20240 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20242 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20243 line_offset
, objfile_name (objfile
));
20244 m_currently_recording_lines
= false;
20245 /* Note: m_currently_recording_lines is left as false until we see
20246 DW_LNE_end_sequence. */
20250 /* Subroutine of dwarf_decode_lines to simplify it.
20251 Process the line number information in LH.
20252 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20253 program in order to set included_p for every referenced header. */
20256 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20257 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20259 const gdb_byte
*line_ptr
, *extended_end
;
20260 const gdb_byte
*line_end
;
20261 unsigned int bytes_read
, extended_len
;
20262 unsigned char op_code
, extended_op
;
20263 CORE_ADDR baseaddr
;
20264 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20265 bfd
*abfd
= objfile
->obfd
;
20266 struct gdbarch
*gdbarch
= objfile
->arch ();
20267 /* True if we're recording line info (as opposed to building partial
20268 symtabs and just interested in finding include files mentioned by
20269 the line number program). */
20270 bool record_lines_p
= !decode_for_pst_p
;
20272 baseaddr
= objfile
->text_section_offset ();
20274 line_ptr
= lh
->statement_program_start
;
20275 line_end
= lh
->statement_program_end
;
20277 /* Read the statement sequences until there's nothing left. */
20278 while (line_ptr
< line_end
)
20280 /* The DWARF line number program state machine. Reset the state
20281 machine at the start of each sequence. */
20282 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20283 bool end_sequence
= false;
20285 if (record_lines_p
)
20287 /* Start a subfile for the current file of the state
20289 const file_entry
*fe
= state_machine
.current_file ();
20292 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20295 /* Decode the table. */
20296 while (line_ptr
< line_end
&& !end_sequence
)
20298 op_code
= read_1_byte (abfd
, line_ptr
);
20301 if (op_code
>= lh
->opcode_base
)
20303 /* Special opcode. */
20304 state_machine
.handle_special_opcode (op_code
);
20306 else switch (op_code
)
20308 case DW_LNS_extended_op
:
20309 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20311 line_ptr
+= bytes_read
;
20312 extended_end
= line_ptr
+ extended_len
;
20313 extended_op
= read_1_byte (abfd
, line_ptr
);
20315 switch (extended_op
)
20317 case DW_LNE_end_sequence
:
20318 state_machine
.handle_end_sequence ();
20319 end_sequence
= true;
20321 case DW_LNE_set_address
:
20324 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20325 line_ptr
+= bytes_read
;
20327 state_machine
.check_line_address (cu
, line_ptr
,
20328 lowpc
- baseaddr
, address
);
20329 state_machine
.handle_set_address (baseaddr
, address
);
20332 case DW_LNE_define_file
:
20334 const char *cur_file
;
20335 unsigned int mod_time
, length
;
20338 cur_file
= read_direct_string (abfd
, line_ptr
,
20340 line_ptr
+= bytes_read
;
20341 dindex
= (dir_index
)
20342 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20343 line_ptr
+= bytes_read
;
20345 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20346 line_ptr
+= bytes_read
;
20348 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20349 line_ptr
+= bytes_read
;
20350 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20353 case DW_LNE_set_discriminator
:
20355 /* The discriminator is not interesting to the
20356 debugger; just ignore it. We still need to
20357 check its value though:
20358 if there are consecutive entries for the same
20359 (non-prologue) line we want to coalesce them.
20362 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20363 line_ptr
+= bytes_read
;
20365 state_machine
.handle_set_discriminator (discr
);
20369 complaint (_("mangled .debug_line section"));
20372 /* Make sure that we parsed the extended op correctly. If e.g.
20373 we expected a different address size than the producer used,
20374 we may have read the wrong number of bytes. */
20375 if (line_ptr
!= extended_end
)
20377 complaint (_("mangled .debug_line section"));
20382 state_machine
.handle_copy ();
20384 case DW_LNS_advance_pc
:
20387 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20388 line_ptr
+= bytes_read
;
20390 state_machine
.handle_advance_pc (adjust
);
20393 case DW_LNS_advance_line
:
20396 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20397 line_ptr
+= bytes_read
;
20399 state_machine
.handle_advance_line (line_delta
);
20402 case DW_LNS_set_file
:
20404 file_name_index file
20405 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20407 line_ptr
+= bytes_read
;
20409 state_machine
.handle_set_file (file
);
20412 case DW_LNS_set_column
:
20413 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20414 line_ptr
+= bytes_read
;
20416 case DW_LNS_negate_stmt
:
20417 state_machine
.handle_negate_stmt ();
20419 case DW_LNS_set_basic_block
:
20421 /* Add to the address register of the state machine the
20422 address increment value corresponding to special opcode
20423 255. I.e., this value is scaled by the minimum
20424 instruction length since special opcode 255 would have
20425 scaled the increment. */
20426 case DW_LNS_const_add_pc
:
20427 state_machine
.handle_const_add_pc ();
20429 case DW_LNS_fixed_advance_pc
:
20431 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20434 state_machine
.handle_fixed_advance_pc (addr_adj
);
20439 /* Unknown standard opcode, ignore it. */
20442 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20444 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20445 line_ptr
+= bytes_read
;
20452 dwarf2_debug_line_missing_end_sequence_complaint ();
20454 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20455 in which case we still finish recording the last line). */
20456 state_machine
.record_line (true);
20460 /* Decode the Line Number Program (LNP) for the given line_header
20461 structure and CU. The actual information extracted and the type
20462 of structures created from the LNP depends on the value of PST.
20464 1. If PST is NULL, then this procedure uses the data from the program
20465 to create all necessary symbol tables, and their linetables.
20467 2. If PST is not NULL, this procedure reads the program to determine
20468 the list of files included by the unit represented by PST, and
20469 builds all the associated partial symbol tables.
20471 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20472 It is used for relative paths in the line table.
20473 NOTE: When processing partial symtabs (pst != NULL),
20474 comp_dir == pst->dirname.
20476 NOTE: It is important that psymtabs have the same file name (via strcmp)
20477 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20478 symtab we don't use it in the name of the psymtabs we create.
20479 E.g. expand_line_sal requires this when finding psymtabs to expand.
20480 A good testcase for this is mb-inline.exp.
20482 LOWPC is the lowest address in CU (or 0 if not known).
20484 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20485 for its PC<->lines mapping information. Otherwise only the filename
20486 table is read in. */
20489 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20490 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20491 CORE_ADDR lowpc
, int decode_mapping
)
20493 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20494 const int decode_for_pst_p
= (pst
!= NULL
);
20496 if (decode_mapping
)
20497 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20499 if (decode_for_pst_p
)
20501 /* Now that we're done scanning the Line Header Program, we can
20502 create the psymtab of each included file. */
20503 for (auto &file_entry
: lh
->file_names ())
20504 if (file_entry
.included_p
== 1)
20506 gdb::unique_xmalloc_ptr
<char> name_holder
;
20507 const char *include_name
=
20508 psymtab_include_file_name (lh
, file_entry
, pst
,
20509 comp_dir
, &name_holder
);
20510 if (include_name
!= NULL
)
20511 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20516 /* Make sure a symtab is created for every file, even files
20517 which contain only variables (i.e. no code with associated
20519 buildsym_compunit
*builder
= cu
->get_builder ();
20520 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20522 for (auto &fe
: lh
->file_names ())
20524 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20525 if (builder
->get_current_subfile ()->symtab
== NULL
)
20527 builder
->get_current_subfile ()->symtab
20528 = allocate_symtab (cust
,
20529 builder
->get_current_subfile ()->name
);
20531 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20536 /* Start a subfile for DWARF. FILENAME is the name of the file and
20537 DIRNAME the name of the source directory which contains FILENAME
20538 or NULL if not known.
20539 This routine tries to keep line numbers from identical absolute and
20540 relative file names in a common subfile.
20542 Using the `list' example from the GDB testsuite, which resides in
20543 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20544 of /srcdir/list0.c yields the following debugging information for list0.c:
20546 DW_AT_name: /srcdir/list0.c
20547 DW_AT_comp_dir: /compdir
20548 files.files[0].name: list0.h
20549 files.files[0].dir: /srcdir
20550 files.files[1].name: list0.c
20551 files.files[1].dir: /srcdir
20553 The line number information for list0.c has to end up in a single
20554 subfile, so that `break /srcdir/list0.c:1' works as expected.
20555 start_subfile will ensure that this happens provided that we pass the
20556 concatenation of files.files[1].dir and files.files[1].name as the
20560 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20561 const char *dirname
)
20563 gdb::unique_xmalloc_ptr
<char> copy
;
20565 /* In order not to lose the line information directory,
20566 we concatenate it to the filename when it makes sense.
20567 Note that the Dwarf3 standard says (speaking of filenames in line
20568 information): ``The directory index is ignored for file names
20569 that represent full path names''. Thus ignoring dirname in the
20570 `else' branch below isn't an issue. */
20572 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20574 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20575 filename
= copy
.get ();
20578 cu
->get_builder ()->start_subfile (filename
);
20581 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20582 buildsym_compunit constructor. */
20584 struct compunit_symtab
*
20585 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20588 gdb_assert (m_builder
== nullptr);
20590 m_builder
.reset (new struct buildsym_compunit
20591 (per_cu
->dwarf2_per_objfile
->objfile
,
20592 name
, comp_dir
, language
, low_pc
));
20594 list_in_scope
= get_builder ()->get_file_symbols ();
20596 get_builder ()->record_debugformat ("DWARF 2");
20597 get_builder ()->record_producer (producer
);
20599 processing_has_namespace_info
= false;
20601 return get_builder ()->get_compunit_symtab ();
20605 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20606 struct dwarf2_cu
*cu
)
20608 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20609 struct comp_unit_head
*cu_header
= &cu
->header
;
20611 /* NOTE drow/2003-01-30: There used to be a comment and some special
20612 code here to turn a symbol with DW_AT_external and a
20613 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20614 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20615 with some versions of binutils) where shared libraries could have
20616 relocations against symbols in their debug information - the
20617 minimal symbol would have the right address, but the debug info
20618 would not. It's no longer necessary, because we will explicitly
20619 apply relocations when we read in the debug information now. */
20621 /* A DW_AT_location attribute with no contents indicates that a
20622 variable has been optimized away. */
20623 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20625 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20629 /* Handle one degenerate form of location expression specially, to
20630 preserve GDB's previous behavior when section offsets are
20631 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20632 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20634 if (attr
->form_is_block ()
20635 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20636 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20637 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20638 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20639 && (DW_BLOCK (attr
)->size
20640 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20642 unsigned int dummy
;
20644 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20645 SET_SYMBOL_VALUE_ADDRESS
20646 (sym
, cu
->header
.read_address (objfile
->obfd
,
20647 DW_BLOCK (attr
)->data
+ 1,
20650 SET_SYMBOL_VALUE_ADDRESS
20651 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20653 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20654 fixup_symbol_section (sym
, objfile
);
20655 SET_SYMBOL_VALUE_ADDRESS
20657 SYMBOL_VALUE_ADDRESS (sym
)
20658 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20662 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20663 expression evaluator, and use LOC_COMPUTED only when necessary
20664 (i.e. when the value of a register or memory location is
20665 referenced, or a thread-local block, etc.). Then again, it might
20666 not be worthwhile. I'm assuming that it isn't unless performance
20667 or memory numbers show me otherwise. */
20669 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20671 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20672 cu
->has_loclist
= true;
20675 /* Given a pointer to a DWARF information entry, figure out if we need
20676 to make a symbol table entry for it, and if so, create a new entry
20677 and return a pointer to it.
20678 If TYPE is NULL, determine symbol type from the die, otherwise
20679 used the passed type.
20680 If SPACE is not NULL, use it to hold the new symbol. If it is
20681 NULL, allocate a new symbol on the objfile's obstack. */
20683 static struct symbol
*
20684 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20685 struct symbol
*space
)
20687 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20688 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20689 struct gdbarch
*gdbarch
= objfile
->arch ();
20690 struct symbol
*sym
= NULL
;
20692 struct attribute
*attr
= NULL
;
20693 struct attribute
*attr2
= NULL
;
20694 CORE_ADDR baseaddr
;
20695 struct pending
**list_to_add
= NULL
;
20697 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20699 baseaddr
= objfile
->text_section_offset ();
20701 name
= dwarf2_name (die
, cu
);
20704 int suppress_add
= 0;
20709 sym
= new (&objfile
->objfile_obstack
) symbol
;
20710 OBJSTAT (objfile
, n_syms
++);
20712 /* Cache this symbol's name and the name's demangled form (if any). */
20713 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20714 /* Fortran does not have mangling standard and the mangling does differ
20715 between gfortran, iFort etc. */
20716 const char *physname
20717 = (cu
->language
== language_fortran
20718 ? dwarf2_full_name (name
, die
, cu
)
20719 : dwarf2_physname (name
, die
, cu
));
20720 const char *linkagename
= dw2_linkage_name (die
, cu
);
20722 if (linkagename
== nullptr || cu
->language
== language_ada
)
20723 sym
->set_linkage_name (physname
);
20726 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20727 sym
->set_linkage_name (linkagename
);
20730 /* Default assumptions.
20731 Use the passed type or decode it from the die. */
20732 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20733 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20735 SYMBOL_TYPE (sym
) = type
;
20737 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20738 attr
= dwarf2_attr (die
,
20739 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20741 if (attr
!= nullptr)
20743 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20746 attr
= dwarf2_attr (die
,
20747 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20749 if (attr
!= nullptr)
20751 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20752 struct file_entry
*fe
;
20754 if (cu
->line_header
!= NULL
)
20755 fe
= cu
->line_header
->file_name_at (file_index
);
20760 complaint (_("file index out of range"));
20762 symbol_set_symtab (sym
, fe
->symtab
);
20768 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20769 if (attr
!= nullptr)
20773 addr
= attr
->value_as_address ();
20774 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20775 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20777 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20778 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20779 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20780 add_symbol_to_list (sym
, cu
->list_in_scope
);
20782 case DW_TAG_subprogram
:
20783 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20785 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20786 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20787 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20788 || cu
->language
== language_ada
20789 || cu
->language
== language_fortran
)
20791 /* Subprograms marked external are stored as a global symbol.
20792 Ada and Fortran subprograms, whether marked external or
20793 not, are always stored as a global symbol, because we want
20794 to be able to access them globally. For instance, we want
20795 to be able to break on a nested subprogram without having
20796 to specify the context. */
20797 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20801 list_to_add
= cu
->list_in_scope
;
20804 case DW_TAG_inlined_subroutine
:
20805 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20807 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20808 SYMBOL_INLINED (sym
) = 1;
20809 list_to_add
= cu
->list_in_scope
;
20811 case DW_TAG_template_value_param
:
20813 /* Fall through. */
20814 case DW_TAG_constant
:
20815 case DW_TAG_variable
:
20816 case DW_TAG_member
:
20817 /* Compilation with minimal debug info may result in
20818 variables with missing type entries. Change the
20819 misleading `void' type to something sensible. */
20820 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20821 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20823 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20824 /* In the case of DW_TAG_member, we should only be called for
20825 static const members. */
20826 if (die
->tag
== DW_TAG_member
)
20828 /* dwarf2_add_field uses die_is_declaration,
20829 so we do the same. */
20830 gdb_assert (die_is_declaration (die
, cu
));
20833 if (attr
!= nullptr)
20835 dwarf2_const_value (attr
, sym
, cu
);
20836 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20839 if (attr2
&& (DW_UNSND (attr2
) != 0))
20840 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20842 list_to_add
= cu
->list_in_scope
;
20846 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20847 if (attr
!= nullptr)
20849 var_decode_location (attr
, sym
, cu
);
20850 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20852 /* Fortran explicitly imports any global symbols to the local
20853 scope by DW_TAG_common_block. */
20854 if (cu
->language
== language_fortran
&& die
->parent
20855 && die
->parent
->tag
== DW_TAG_common_block
)
20858 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20859 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20860 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
20862 /* When a static variable is eliminated by the linker,
20863 the corresponding debug information is not stripped
20864 out, but the variable address is set to null;
20865 do not add such variables into symbol table. */
20867 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20869 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20870 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20871 && dwarf2_per_objfile
->per_bfd
->can_copy
)
20873 /* A global static variable might be subject to
20874 copy relocation. We first check for a local
20875 minsym, though, because maybe the symbol was
20876 marked hidden, in which case this would not
20878 bound_minimal_symbol found
20879 = (lookup_minimal_symbol_linkage
20880 (sym
->linkage_name (), objfile
));
20881 if (found
.minsym
!= nullptr)
20882 sym
->maybe_copied
= 1;
20885 /* A variable with DW_AT_external is never static,
20886 but it may be block-scoped. */
20888 = ((cu
->list_in_scope
20889 == cu
->get_builder ()->get_file_symbols ())
20890 ? cu
->get_builder ()->get_global_symbols ()
20891 : cu
->list_in_scope
);
20894 list_to_add
= cu
->list_in_scope
;
20898 /* We do not know the address of this symbol.
20899 If it is an external symbol and we have type information
20900 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20901 The address of the variable will then be determined from
20902 the minimal symbol table whenever the variable is
20904 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20906 /* Fortran explicitly imports any global symbols to the local
20907 scope by DW_TAG_common_block. */
20908 if (cu
->language
== language_fortran
&& die
->parent
20909 && die
->parent
->tag
== DW_TAG_common_block
)
20911 /* SYMBOL_CLASS doesn't matter here because
20912 read_common_block is going to reset it. */
20914 list_to_add
= cu
->list_in_scope
;
20916 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20917 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20919 /* A variable with DW_AT_external is never static, but it
20920 may be block-scoped. */
20922 = ((cu
->list_in_scope
20923 == cu
->get_builder ()->get_file_symbols ())
20924 ? cu
->get_builder ()->get_global_symbols ()
20925 : cu
->list_in_scope
);
20927 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20929 else if (!die_is_declaration (die
, cu
))
20931 /* Use the default LOC_OPTIMIZED_OUT class. */
20932 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20934 list_to_add
= cu
->list_in_scope
;
20938 case DW_TAG_formal_parameter
:
20940 /* If we are inside a function, mark this as an argument. If
20941 not, we might be looking at an argument to an inlined function
20942 when we do not have enough information to show inlined frames;
20943 pretend it's a local variable in that case so that the user can
20945 struct context_stack
*curr
20946 = cu
->get_builder ()->get_current_context_stack ();
20947 if (curr
!= nullptr && curr
->name
!= nullptr)
20948 SYMBOL_IS_ARGUMENT (sym
) = 1;
20949 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20950 if (attr
!= nullptr)
20952 var_decode_location (attr
, sym
, cu
);
20954 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20955 if (attr
!= nullptr)
20957 dwarf2_const_value (attr
, sym
, cu
);
20960 list_to_add
= cu
->list_in_scope
;
20963 case DW_TAG_unspecified_parameters
:
20964 /* From varargs functions; gdb doesn't seem to have any
20965 interest in this information, so just ignore it for now.
20968 case DW_TAG_template_type_param
:
20970 /* Fall through. */
20971 case DW_TAG_class_type
:
20972 case DW_TAG_interface_type
:
20973 case DW_TAG_structure_type
:
20974 case DW_TAG_union_type
:
20975 case DW_TAG_set_type
:
20976 case DW_TAG_enumeration_type
:
20977 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20978 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20981 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20982 really ever be static objects: otherwise, if you try
20983 to, say, break of a class's method and you're in a file
20984 which doesn't mention that class, it won't work unless
20985 the check for all static symbols in lookup_symbol_aux
20986 saves you. See the OtherFileClass tests in
20987 gdb.c++/namespace.exp. */
20991 buildsym_compunit
*builder
= cu
->get_builder ();
20993 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20994 && cu
->language
== language_cplus
20995 ? builder
->get_global_symbols ()
20996 : cu
->list_in_scope
);
20998 /* The semantics of C++ state that "struct foo {
20999 ... }" also defines a typedef for "foo". */
21000 if (cu
->language
== language_cplus
21001 || cu
->language
== language_ada
21002 || cu
->language
== language_d
21003 || cu
->language
== language_rust
)
21005 /* The symbol's name is already allocated along
21006 with this objfile, so we don't need to
21007 duplicate it for the type. */
21008 if (SYMBOL_TYPE (sym
)->name () == 0)
21009 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21014 case DW_TAG_typedef
:
21015 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21016 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21017 list_to_add
= cu
->list_in_scope
;
21019 case DW_TAG_base_type
:
21020 case DW_TAG_subrange_type
:
21021 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21022 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21023 list_to_add
= cu
->list_in_scope
;
21025 case DW_TAG_enumerator
:
21026 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21027 if (attr
!= nullptr)
21029 dwarf2_const_value (attr
, sym
, cu
);
21032 /* NOTE: carlton/2003-11-10: See comment above in the
21033 DW_TAG_class_type, etc. block. */
21036 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21037 && cu
->language
== language_cplus
21038 ? cu
->get_builder ()->get_global_symbols ()
21039 : cu
->list_in_scope
);
21042 case DW_TAG_imported_declaration
:
21043 case DW_TAG_namespace
:
21044 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21045 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21047 case DW_TAG_module
:
21048 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21049 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21050 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21052 case DW_TAG_common_block
:
21053 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21054 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21055 add_symbol_to_list (sym
, cu
->list_in_scope
);
21058 /* Not a tag we recognize. Hopefully we aren't processing
21059 trash data, but since we must specifically ignore things
21060 we don't recognize, there is nothing else we should do at
21062 complaint (_("unsupported tag: '%s'"),
21063 dwarf_tag_name (die
->tag
));
21069 sym
->hash_next
= objfile
->template_symbols
;
21070 objfile
->template_symbols
= sym
;
21071 list_to_add
= NULL
;
21074 if (list_to_add
!= NULL
)
21075 add_symbol_to_list (sym
, list_to_add
);
21077 /* For the benefit of old versions of GCC, check for anonymous
21078 namespaces based on the demangled name. */
21079 if (!cu
->processing_has_namespace_info
21080 && cu
->language
== language_cplus
)
21081 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21086 /* Given an attr with a DW_FORM_dataN value in host byte order,
21087 zero-extend it as appropriate for the symbol's type. The DWARF
21088 standard (v4) is not entirely clear about the meaning of using
21089 DW_FORM_dataN for a constant with a signed type, where the type is
21090 wider than the data. The conclusion of a discussion on the DWARF
21091 list was that this is unspecified. We choose to always zero-extend
21092 because that is the interpretation long in use by GCC. */
21095 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21096 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21098 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21099 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21100 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21101 LONGEST l
= DW_UNSND (attr
);
21103 if (bits
< sizeof (*value
) * 8)
21105 l
&= ((LONGEST
) 1 << bits
) - 1;
21108 else if (bits
== sizeof (*value
) * 8)
21112 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21113 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21120 /* Read a constant value from an attribute. Either set *VALUE, or if
21121 the value does not fit in *VALUE, set *BYTES - either already
21122 allocated on the objfile obstack, or newly allocated on OBSTACK,
21123 or, set *BATON, if we translated the constant to a location
21127 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21128 const char *name
, struct obstack
*obstack
,
21129 struct dwarf2_cu
*cu
,
21130 LONGEST
*value
, const gdb_byte
**bytes
,
21131 struct dwarf2_locexpr_baton
**baton
)
21133 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21134 struct objfile
*objfile
= per_objfile
->objfile
;
21135 struct comp_unit_head
*cu_header
= &cu
->header
;
21136 struct dwarf_block
*blk
;
21137 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21138 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21144 switch (attr
->form
)
21147 case DW_FORM_addrx
:
21148 case DW_FORM_GNU_addr_index
:
21152 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21153 dwarf2_const_value_length_mismatch_complaint (name
,
21154 cu_header
->addr_size
,
21155 TYPE_LENGTH (type
));
21156 /* Symbols of this form are reasonably rare, so we just
21157 piggyback on the existing location code rather than writing
21158 a new implementation of symbol_computed_ops. */
21159 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21160 (*baton
)->per_objfile
= per_objfile
;
21161 (*baton
)->per_cu
= cu
->per_cu
;
21162 gdb_assert ((*baton
)->per_cu
);
21164 (*baton
)->size
= 2 + cu_header
->addr_size
;
21165 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21166 (*baton
)->data
= data
;
21168 data
[0] = DW_OP_addr
;
21169 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21170 byte_order
, DW_ADDR (attr
));
21171 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21174 case DW_FORM_string
:
21177 case DW_FORM_GNU_str_index
:
21178 case DW_FORM_GNU_strp_alt
:
21179 /* DW_STRING is already allocated on the objfile obstack, point
21181 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21183 case DW_FORM_block1
:
21184 case DW_FORM_block2
:
21185 case DW_FORM_block4
:
21186 case DW_FORM_block
:
21187 case DW_FORM_exprloc
:
21188 case DW_FORM_data16
:
21189 blk
= DW_BLOCK (attr
);
21190 if (TYPE_LENGTH (type
) != blk
->size
)
21191 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21192 TYPE_LENGTH (type
));
21193 *bytes
= blk
->data
;
21196 /* The DW_AT_const_value attributes are supposed to carry the
21197 symbol's value "represented as it would be on the target
21198 architecture." By the time we get here, it's already been
21199 converted to host endianness, so we just need to sign- or
21200 zero-extend it as appropriate. */
21201 case DW_FORM_data1
:
21202 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21204 case DW_FORM_data2
:
21205 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21207 case DW_FORM_data4
:
21208 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21210 case DW_FORM_data8
:
21211 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21214 case DW_FORM_sdata
:
21215 case DW_FORM_implicit_const
:
21216 *value
= DW_SND (attr
);
21219 case DW_FORM_udata
:
21220 *value
= DW_UNSND (attr
);
21224 complaint (_("unsupported const value attribute form: '%s'"),
21225 dwarf_form_name (attr
->form
));
21232 /* Copy constant value from an attribute to a symbol. */
21235 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21236 struct dwarf2_cu
*cu
)
21238 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21240 const gdb_byte
*bytes
;
21241 struct dwarf2_locexpr_baton
*baton
;
21243 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21244 sym
->print_name (),
21245 &objfile
->objfile_obstack
, cu
,
21246 &value
, &bytes
, &baton
);
21250 SYMBOL_LOCATION_BATON (sym
) = baton
;
21251 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21253 else if (bytes
!= NULL
)
21255 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21256 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21260 SYMBOL_VALUE (sym
) = value
;
21261 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21265 /* Return the type of the die in question using its DW_AT_type attribute. */
21267 static struct type
*
21268 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21270 struct attribute
*type_attr
;
21272 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21275 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21276 /* A missing DW_AT_type represents a void type. */
21277 return objfile_type (objfile
)->builtin_void
;
21280 return lookup_die_type (die
, type_attr
, cu
);
21283 /* True iff CU's producer generates GNAT Ada auxiliary information
21284 that allows to find parallel types through that information instead
21285 of having to do expensive parallel lookups by type name. */
21288 need_gnat_info (struct dwarf2_cu
*cu
)
21290 /* Assume that the Ada compiler was GNAT, which always produces
21291 the auxiliary information. */
21292 return (cu
->language
== language_ada
);
21295 /* Return the auxiliary type of the die in question using its
21296 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21297 attribute is not present. */
21299 static struct type
*
21300 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21302 struct attribute
*type_attr
;
21304 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21308 return lookup_die_type (die
, type_attr
, cu
);
21311 /* If DIE has a descriptive_type attribute, then set the TYPE's
21312 descriptive type accordingly. */
21315 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21316 struct dwarf2_cu
*cu
)
21318 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21320 if (descriptive_type
)
21322 ALLOCATE_GNAT_AUX_TYPE (type
);
21323 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21327 /* Return the containing type of the die in question using its
21328 DW_AT_containing_type attribute. */
21330 static struct type
*
21331 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21333 struct attribute
*type_attr
;
21334 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21336 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21338 error (_("Dwarf Error: Problem turning containing type into gdb type "
21339 "[in module %s]"), objfile_name (objfile
));
21341 return lookup_die_type (die
, type_attr
, cu
);
21344 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21346 static struct type
*
21347 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21349 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21350 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21353 std::string message
21354 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21355 objfile_name (objfile
),
21356 sect_offset_str (cu
->header
.sect_off
),
21357 sect_offset_str (die
->sect_off
));
21358 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21360 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21363 /* Look up the type of DIE in CU using its type attribute ATTR.
21364 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21365 DW_AT_containing_type.
21366 If there is no type substitute an error marker. */
21368 static struct type
*
21369 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21370 struct dwarf2_cu
*cu
)
21372 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21373 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21374 struct type
*this_type
;
21376 gdb_assert (attr
->name
== DW_AT_type
21377 || attr
->name
== DW_AT_GNAT_descriptive_type
21378 || attr
->name
== DW_AT_containing_type
);
21380 /* First see if we have it cached. */
21382 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21384 struct dwarf2_per_cu_data
*per_cu
;
21385 sect_offset sect_off
= attr
->get_ref_die_offset ();
21387 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21388 dwarf2_per_objfile
);
21389 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21391 else if (attr
->form_is_ref ())
21393 sect_offset sect_off
= attr
->get_ref_die_offset ();
21395 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21397 else if (attr
->form
== DW_FORM_ref_sig8
)
21399 ULONGEST signature
= DW_SIGNATURE (attr
);
21401 return get_signatured_type (die
, signature
, cu
);
21405 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21406 " at %s [in module %s]"),
21407 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21408 objfile_name (objfile
));
21409 return build_error_marker_type (cu
, die
);
21412 /* If not cached we need to read it in. */
21414 if (this_type
== NULL
)
21416 struct die_info
*type_die
= NULL
;
21417 struct dwarf2_cu
*type_cu
= cu
;
21419 if (attr
->form_is_ref ())
21420 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21421 if (type_die
== NULL
)
21422 return build_error_marker_type (cu
, die
);
21423 /* If we find the type now, it's probably because the type came
21424 from an inter-CU reference and the type's CU got expanded before
21426 this_type
= read_type_die (type_die
, type_cu
);
21429 /* If we still don't have a type use an error marker. */
21431 if (this_type
== NULL
)
21432 return build_error_marker_type (cu
, die
);
21437 /* Return the type in DIE, CU.
21438 Returns NULL for invalid types.
21440 This first does a lookup in die_type_hash,
21441 and only reads the die in if necessary.
21443 NOTE: This can be called when reading in partial or full symbols. */
21445 static struct type
*
21446 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21448 struct type
*this_type
;
21450 this_type
= get_die_type (die
, cu
);
21454 return read_type_die_1 (die
, cu
);
21457 /* Read the type in DIE, CU.
21458 Returns NULL for invalid types. */
21460 static struct type
*
21461 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21463 struct type
*this_type
= NULL
;
21467 case DW_TAG_class_type
:
21468 case DW_TAG_interface_type
:
21469 case DW_TAG_structure_type
:
21470 case DW_TAG_union_type
:
21471 this_type
= read_structure_type (die
, cu
);
21473 case DW_TAG_enumeration_type
:
21474 this_type
= read_enumeration_type (die
, cu
);
21476 case DW_TAG_subprogram
:
21477 case DW_TAG_subroutine_type
:
21478 case DW_TAG_inlined_subroutine
:
21479 this_type
= read_subroutine_type (die
, cu
);
21481 case DW_TAG_array_type
:
21482 this_type
= read_array_type (die
, cu
);
21484 case DW_TAG_set_type
:
21485 this_type
= read_set_type (die
, cu
);
21487 case DW_TAG_pointer_type
:
21488 this_type
= read_tag_pointer_type (die
, cu
);
21490 case DW_TAG_ptr_to_member_type
:
21491 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21493 case DW_TAG_reference_type
:
21494 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21496 case DW_TAG_rvalue_reference_type
:
21497 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21499 case DW_TAG_const_type
:
21500 this_type
= read_tag_const_type (die
, cu
);
21502 case DW_TAG_volatile_type
:
21503 this_type
= read_tag_volatile_type (die
, cu
);
21505 case DW_TAG_restrict_type
:
21506 this_type
= read_tag_restrict_type (die
, cu
);
21508 case DW_TAG_string_type
:
21509 this_type
= read_tag_string_type (die
, cu
);
21511 case DW_TAG_typedef
:
21512 this_type
= read_typedef (die
, cu
);
21514 case DW_TAG_subrange_type
:
21515 this_type
= read_subrange_type (die
, cu
);
21517 case DW_TAG_base_type
:
21518 this_type
= read_base_type (die
, cu
);
21520 case DW_TAG_unspecified_type
:
21521 this_type
= read_unspecified_type (die
, cu
);
21523 case DW_TAG_namespace
:
21524 this_type
= read_namespace_type (die
, cu
);
21526 case DW_TAG_module
:
21527 this_type
= read_module_type (die
, cu
);
21529 case DW_TAG_atomic_type
:
21530 this_type
= read_tag_atomic_type (die
, cu
);
21533 complaint (_("unexpected tag in read_type_die: '%s'"),
21534 dwarf_tag_name (die
->tag
));
21541 /* See if we can figure out if the class lives in a namespace. We do
21542 this by looking for a member function; its demangled name will
21543 contain namespace info, if there is any.
21544 Return the computed name or NULL.
21545 Space for the result is allocated on the objfile's obstack.
21546 This is the full-die version of guess_partial_die_structure_name.
21547 In this case we know DIE has no useful parent. */
21549 static const char *
21550 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21552 struct die_info
*spec_die
;
21553 struct dwarf2_cu
*spec_cu
;
21554 struct die_info
*child
;
21555 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21558 spec_die
= die_specification (die
, &spec_cu
);
21559 if (spec_die
!= NULL
)
21565 for (child
= die
->child
;
21567 child
= child
->sibling
)
21569 if (child
->tag
== DW_TAG_subprogram
)
21571 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21573 if (linkage_name
!= NULL
)
21575 gdb::unique_xmalloc_ptr
<char> actual_name
21576 (language_class_name_from_physname (cu
->language_defn
,
21578 const char *name
= NULL
;
21580 if (actual_name
!= NULL
)
21582 const char *die_name
= dwarf2_name (die
, cu
);
21584 if (die_name
!= NULL
21585 && strcmp (die_name
, actual_name
.get ()) != 0)
21587 /* Strip off the class name from the full name.
21588 We want the prefix. */
21589 int die_name_len
= strlen (die_name
);
21590 int actual_name_len
= strlen (actual_name
.get ());
21591 const char *ptr
= actual_name
.get ();
21593 /* Test for '::' as a sanity check. */
21594 if (actual_name_len
> die_name_len
+ 2
21595 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21596 name
= obstack_strndup (
21597 &objfile
->per_bfd
->storage_obstack
,
21598 ptr
, actual_name_len
- die_name_len
- 2);
21609 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21610 prefix part in such case. See
21611 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21613 static const char *
21614 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21616 struct attribute
*attr
;
21619 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21620 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21623 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21626 attr
= dw2_linkage_name_attr (die
, cu
);
21627 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21630 /* dwarf2_name had to be already called. */
21631 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21633 /* Strip the base name, keep any leading namespaces/classes. */
21634 base
= strrchr (DW_STRING (attr
), ':');
21635 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21638 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21639 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21641 &base
[-1] - DW_STRING (attr
));
21644 /* Return the name of the namespace/class that DIE is defined within,
21645 or "" if we can't tell. The caller should not xfree the result.
21647 For example, if we're within the method foo() in the following
21657 then determine_prefix on foo's die will return "N::C". */
21659 static const char *
21660 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21662 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21663 struct die_info
*parent
, *spec_die
;
21664 struct dwarf2_cu
*spec_cu
;
21665 struct type
*parent_type
;
21666 const char *retval
;
21668 if (cu
->language
!= language_cplus
21669 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21670 && cu
->language
!= language_rust
)
21673 retval
= anonymous_struct_prefix (die
, cu
);
21677 /* We have to be careful in the presence of DW_AT_specification.
21678 For example, with GCC 3.4, given the code
21682 // Definition of N::foo.
21686 then we'll have a tree of DIEs like this:
21688 1: DW_TAG_compile_unit
21689 2: DW_TAG_namespace // N
21690 3: DW_TAG_subprogram // declaration of N::foo
21691 4: DW_TAG_subprogram // definition of N::foo
21692 DW_AT_specification // refers to die #3
21694 Thus, when processing die #4, we have to pretend that we're in
21695 the context of its DW_AT_specification, namely the contex of die
21698 spec_die
= die_specification (die
, &spec_cu
);
21699 if (spec_die
== NULL
)
21700 parent
= die
->parent
;
21703 parent
= spec_die
->parent
;
21707 if (parent
== NULL
)
21709 else if (parent
->building_fullname
)
21712 const char *parent_name
;
21714 /* It has been seen on RealView 2.2 built binaries,
21715 DW_TAG_template_type_param types actually _defined_ as
21716 children of the parent class:
21719 template class <class Enum> Class{};
21720 Class<enum E> class_e;
21722 1: DW_TAG_class_type (Class)
21723 2: DW_TAG_enumeration_type (E)
21724 3: DW_TAG_enumerator (enum1:0)
21725 3: DW_TAG_enumerator (enum2:1)
21727 2: DW_TAG_template_type_param
21728 DW_AT_type DW_FORM_ref_udata (E)
21730 Besides being broken debug info, it can put GDB into an
21731 infinite loop. Consider:
21733 When we're building the full name for Class<E>, we'll start
21734 at Class, and go look over its template type parameters,
21735 finding E. We'll then try to build the full name of E, and
21736 reach here. We're now trying to build the full name of E,
21737 and look over the parent DIE for containing scope. In the
21738 broken case, if we followed the parent DIE of E, we'd again
21739 find Class, and once again go look at its template type
21740 arguments, etc., etc. Simply don't consider such parent die
21741 as source-level parent of this die (it can't be, the language
21742 doesn't allow it), and break the loop here. */
21743 name
= dwarf2_name (die
, cu
);
21744 parent_name
= dwarf2_name (parent
, cu
);
21745 complaint (_("template param type '%s' defined within parent '%s'"),
21746 name
? name
: "<unknown>",
21747 parent_name
? parent_name
: "<unknown>");
21751 switch (parent
->tag
)
21753 case DW_TAG_namespace
:
21754 parent_type
= read_type_die (parent
, cu
);
21755 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21756 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21757 Work around this problem here. */
21758 if (cu
->language
== language_cplus
21759 && strcmp (parent_type
->name (), "::") == 0)
21761 /* We give a name to even anonymous namespaces. */
21762 return parent_type
->name ();
21763 case DW_TAG_class_type
:
21764 case DW_TAG_interface_type
:
21765 case DW_TAG_structure_type
:
21766 case DW_TAG_union_type
:
21767 case DW_TAG_module
:
21768 parent_type
= read_type_die (parent
, cu
);
21769 if (parent_type
->name () != NULL
)
21770 return parent_type
->name ();
21772 /* An anonymous structure is only allowed non-static data
21773 members; no typedefs, no member functions, et cetera.
21774 So it does not need a prefix. */
21776 case DW_TAG_compile_unit
:
21777 case DW_TAG_partial_unit
:
21778 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21779 if (cu
->language
== language_cplus
21780 && !dwarf2_per_objfile
->per_bfd
->types
.empty ()
21781 && die
->child
!= NULL
21782 && (die
->tag
== DW_TAG_class_type
21783 || die
->tag
== DW_TAG_structure_type
21784 || die
->tag
== DW_TAG_union_type
))
21786 const char *name
= guess_full_die_structure_name (die
, cu
);
21791 case DW_TAG_subprogram
:
21792 /* Nested subroutines in Fortran get a prefix with the name
21793 of the parent's subroutine. */
21794 if (cu
->language
== language_fortran
)
21796 if ((die
->tag
== DW_TAG_subprogram
)
21797 && (dwarf2_name (parent
, cu
) != NULL
))
21798 return dwarf2_name (parent
, cu
);
21800 return determine_prefix (parent
, cu
);
21801 case DW_TAG_enumeration_type
:
21802 parent_type
= read_type_die (parent
, cu
);
21803 if (TYPE_DECLARED_CLASS (parent_type
))
21805 if (parent_type
->name () != NULL
)
21806 return parent_type
->name ();
21809 /* Fall through. */
21811 return determine_prefix (parent
, cu
);
21815 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21816 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21817 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21818 an obconcat, otherwise allocate storage for the result. The CU argument is
21819 used to determine the language and hence, the appropriate separator. */
21821 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21824 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21825 int physname
, struct dwarf2_cu
*cu
)
21827 const char *lead
= "";
21830 if (suffix
== NULL
|| suffix
[0] == '\0'
21831 || prefix
== NULL
|| prefix
[0] == '\0')
21833 else if (cu
->language
== language_d
)
21835 /* For D, the 'main' function could be defined in any module, but it
21836 should never be prefixed. */
21837 if (strcmp (suffix
, "D main") == 0)
21845 else if (cu
->language
== language_fortran
&& physname
)
21847 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21848 DW_AT_MIPS_linkage_name is preferred and used instead. */
21856 if (prefix
== NULL
)
21858 if (suffix
== NULL
)
21865 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21867 strcpy (retval
, lead
);
21868 strcat (retval
, prefix
);
21869 strcat (retval
, sep
);
21870 strcat (retval
, suffix
);
21875 /* We have an obstack. */
21876 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21880 /* Get name of a die, return NULL if not found. */
21882 static const char *
21883 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21884 struct objfile
*objfile
)
21886 if (name
&& cu
->language
== language_cplus
)
21888 gdb::unique_xmalloc_ptr
<char> canon_name
21889 = cp_canonicalize_string (name
);
21891 if (canon_name
!= nullptr)
21892 name
= objfile
->intern (canon_name
.get ());
21898 /* Get name of a die, return NULL if not found.
21899 Anonymous namespaces are converted to their magic string. */
21901 static const char *
21902 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21904 struct attribute
*attr
;
21905 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21907 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21908 if ((!attr
|| !DW_STRING (attr
))
21909 && die
->tag
!= DW_TAG_namespace
21910 && die
->tag
!= DW_TAG_class_type
21911 && die
->tag
!= DW_TAG_interface_type
21912 && die
->tag
!= DW_TAG_structure_type
21913 && die
->tag
!= DW_TAG_union_type
)
21918 case DW_TAG_compile_unit
:
21919 case DW_TAG_partial_unit
:
21920 /* Compilation units have a DW_AT_name that is a filename, not
21921 a source language identifier. */
21922 case DW_TAG_enumeration_type
:
21923 case DW_TAG_enumerator
:
21924 /* These tags always have simple identifiers already; no need
21925 to canonicalize them. */
21926 return DW_STRING (attr
);
21928 case DW_TAG_namespace
:
21929 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21930 return DW_STRING (attr
);
21931 return CP_ANONYMOUS_NAMESPACE_STR
;
21933 case DW_TAG_class_type
:
21934 case DW_TAG_interface_type
:
21935 case DW_TAG_structure_type
:
21936 case DW_TAG_union_type
:
21937 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21938 structures or unions. These were of the form "._%d" in GCC 4.1,
21939 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21940 and GCC 4.4. We work around this problem by ignoring these. */
21941 if (attr
&& DW_STRING (attr
)
21942 && (startswith (DW_STRING (attr
), "._")
21943 || startswith (DW_STRING (attr
), "<anonymous")))
21946 /* GCC might emit a nameless typedef that has a linkage name. See
21947 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21948 if (!attr
|| DW_STRING (attr
) == NULL
)
21950 attr
= dw2_linkage_name_attr (die
, cu
);
21951 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21954 /* Avoid demangling DW_STRING (attr) the second time on a second
21955 call for the same DIE. */
21956 if (!DW_STRING_IS_CANONICAL (attr
))
21958 gdb::unique_xmalloc_ptr
<char> demangled
21959 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21960 if (demangled
== nullptr)
21963 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21964 DW_STRING_IS_CANONICAL (attr
) = 1;
21967 /* Strip any leading namespaces/classes, keep only the base name.
21968 DW_AT_name for named DIEs does not contain the prefixes. */
21969 const char *base
= strrchr (DW_STRING (attr
), ':');
21970 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21973 return DW_STRING (attr
);
21981 if (!DW_STRING_IS_CANONICAL (attr
))
21983 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21985 DW_STRING_IS_CANONICAL (attr
) = 1;
21987 return DW_STRING (attr
);
21990 /* Return the die that this die in an extension of, or NULL if there
21991 is none. *EXT_CU is the CU containing DIE on input, and the CU
21992 containing the return value on output. */
21994 static struct die_info
*
21995 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21997 struct attribute
*attr
;
21999 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22003 return follow_die_ref (die
, attr
, ext_cu
);
22007 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22011 print_spaces (indent
, f
);
22012 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22013 dwarf_tag_name (die
->tag
), die
->abbrev
,
22014 sect_offset_str (die
->sect_off
));
22016 if (die
->parent
!= NULL
)
22018 print_spaces (indent
, f
);
22019 fprintf_unfiltered (f
, " parent at offset: %s\n",
22020 sect_offset_str (die
->parent
->sect_off
));
22023 print_spaces (indent
, f
);
22024 fprintf_unfiltered (f
, " has children: %s\n",
22025 dwarf_bool_name (die
->child
!= NULL
));
22027 print_spaces (indent
, f
);
22028 fprintf_unfiltered (f
, " attributes:\n");
22030 for (i
= 0; i
< die
->num_attrs
; ++i
)
22032 print_spaces (indent
, f
);
22033 fprintf_unfiltered (f
, " %s (%s) ",
22034 dwarf_attr_name (die
->attrs
[i
].name
),
22035 dwarf_form_name (die
->attrs
[i
].form
));
22037 switch (die
->attrs
[i
].form
)
22040 case DW_FORM_addrx
:
22041 case DW_FORM_GNU_addr_index
:
22042 fprintf_unfiltered (f
, "address: ");
22043 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22045 case DW_FORM_block2
:
22046 case DW_FORM_block4
:
22047 case DW_FORM_block
:
22048 case DW_FORM_block1
:
22049 fprintf_unfiltered (f
, "block: size %s",
22050 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22052 case DW_FORM_exprloc
:
22053 fprintf_unfiltered (f
, "expression: size %s",
22054 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22056 case DW_FORM_data16
:
22057 fprintf_unfiltered (f
, "constant of 16 bytes");
22059 case DW_FORM_ref_addr
:
22060 fprintf_unfiltered (f
, "ref address: ");
22061 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22063 case DW_FORM_GNU_ref_alt
:
22064 fprintf_unfiltered (f
, "alt ref address: ");
22065 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22071 case DW_FORM_ref_udata
:
22072 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22073 (long) (DW_UNSND (&die
->attrs
[i
])));
22075 case DW_FORM_data1
:
22076 case DW_FORM_data2
:
22077 case DW_FORM_data4
:
22078 case DW_FORM_data8
:
22079 case DW_FORM_udata
:
22080 case DW_FORM_sdata
:
22081 fprintf_unfiltered (f
, "constant: %s",
22082 pulongest (DW_UNSND (&die
->attrs
[i
])));
22084 case DW_FORM_sec_offset
:
22085 fprintf_unfiltered (f
, "section offset: %s",
22086 pulongest (DW_UNSND (&die
->attrs
[i
])));
22088 case DW_FORM_ref_sig8
:
22089 fprintf_unfiltered (f
, "signature: %s",
22090 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22092 case DW_FORM_string
:
22094 case DW_FORM_line_strp
:
22096 case DW_FORM_GNU_str_index
:
22097 case DW_FORM_GNU_strp_alt
:
22098 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22099 DW_STRING (&die
->attrs
[i
])
22100 ? DW_STRING (&die
->attrs
[i
]) : "",
22101 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22104 if (DW_UNSND (&die
->attrs
[i
]))
22105 fprintf_unfiltered (f
, "flag: TRUE");
22107 fprintf_unfiltered (f
, "flag: FALSE");
22109 case DW_FORM_flag_present
:
22110 fprintf_unfiltered (f
, "flag: TRUE");
22112 case DW_FORM_indirect
:
22113 /* The reader will have reduced the indirect form to
22114 the "base form" so this form should not occur. */
22115 fprintf_unfiltered (f
,
22116 "unexpected attribute form: DW_FORM_indirect");
22118 case DW_FORM_implicit_const
:
22119 fprintf_unfiltered (f
, "constant: %s",
22120 plongest (DW_SND (&die
->attrs
[i
])));
22123 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22124 die
->attrs
[i
].form
);
22127 fprintf_unfiltered (f
, "\n");
22132 dump_die_for_error (struct die_info
*die
)
22134 dump_die_shallow (gdb_stderr
, 0, die
);
22138 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22140 int indent
= level
* 4;
22142 gdb_assert (die
!= NULL
);
22144 if (level
>= max_level
)
22147 dump_die_shallow (f
, indent
, die
);
22149 if (die
->child
!= NULL
)
22151 print_spaces (indent
, f
);
22152 fprintf_unfiltered (f
, " Children:");
22153 if (level
+ 1 < max_level
)
22155 fprintf_unfiltered (f
, "\n");
22156 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22160 fprintf_unfiltered (f
,
22161 " [not printed, max nesting level reached]\n");
22165 if (die
->sibling
!= NULL
&& level
> 0)
22167 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22171 /* This is called from the pdie macro in gdbinit.in.
22172 It's not static so gcc will keep a copy callable from gdb. */
22175 dump_die (struct die_info
*die
, int max_level
)
22177 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22181 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22185 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22186 to_underlying (die
->sect_off
),
22192 /* Follow reference or signature attribute ATTR of SRC_DIE.
22193 On entry *REF_CU is the CU of SRC_DIE.
22194 On exit *REF_CU is the CU of the result. */
22196 static struct die_info
*
22197 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22198 struct dwarf2_cu
**ref_cu
)
22200 struct die_info
*die
;
22202 if (attr
->form_is_ref ())
22203 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22204 else if (attr
->form
== DW_FORM_ref_sig8
)
22205 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22208 dump_die_for_error (src_die
);
22209 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22210 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22216 /* Follow reference OFFSET.
22217 On entry *REF_CU is the CU of the source die referencing OFFSET.
22218 On exit *REF_CU is the CU of the result.
22219 Returns NULL if OFFSET is invalid. */
22221 static struct die_info
*
22222 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22223 struct dwarf2_cu
**ref_cu
)
22225 struct die_info temp_die
;
22226 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22227 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22229 gdb_assert (cu
->per_cu
!= NULL
);
22233 if (cu
->per_cu
->is_debug_types
)
22235 /* .debug_types CUs cannot reference anything outside their CU.
22236 If they need to, they have to reference a signatured type via
22237 DW_FORM_ref_sig8. */
22238 if (!cu
->header
.offset_in_cu_p (sect_off
))
22241 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22242 || !cu
->header
.offset_in_cu_p (sect_off
))
22244 struct dwarf2_per_cu_data
*per_cu
;
22246 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22247 dwarf2_per_objfile
);
22249 /* If necessary, add it to the queue and load its DIEs. */
22250 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22251 load_full_comp_unit (per_cu
, dwarf2_per_objfile
, false, cu
->language
);
22253 target_cu
= per_cu
->cu
;
22255 else if (cu
->dies
== NULL
)
22257 /* We're loading full DIEs during partial symbol reading. */
22258 gdb_assert (dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
);
22259 load_full_comp_unit (cu
->per_cu
, dwarf2_per_objfile
, false,
22263 *ref_cu
= target_cu
;
22264 temp_die
.sect_off
= sect_off
;
22266 if (target_cu
!= cu
)
22267 target_cu
->ancestor
= cu
;
22269 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22271 to_underlying (sect_off
));
22274 /* Follow reference attribute ATTR of SRC_DIE.
22275 On entry *REF_CU is the CU of SRC_DIE.
22276 On exit *REF_CU is the CU of the result. */
22278 static struct die_info
*
22279 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22280 struct dwarf2_cu
**ref_cu
)
22282 sect_offset sect_off
= attr
->get_ref_die_offset ();
22283 struct dwarf2_cu
*cu
= *ref_cu
;
22284 struct die_info
*die
;
22286 die
= follow_die_offset (sect_off
,
22287 (attr
->form
== DW_FORM_GNU_ref_alt
22288 || cu
->per_cu
->is_dwz
),
22291 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22292 "at %s [in module %s]"),
22293 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22294 objfile_name (cu
->per_objfile
->objfile
));
22301 struct dwarf2_locexpr_baton
22302 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22303 dwarf2_per_cu_data
*per_cu
,
22304 dwarf2_per_objfile
*dwarf2_per_objfile
,
22305 CORE_ADDR (*get_frame_pc
) (void *baton
),
22306 void *baton
, bool resolve_abstract_p
)
22308 struct dwarf2_cu
*cu
;
22309 struct die_info
*die
;
22310 struct attribute
*attr
;
22311 struct dwarf2_locexpr_baton retval
;
22312 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22314 if (per_cu
->cu
== NULL
)
22315 load_cu (per_cu
, dwarf2_per_objfile
, false);
22319 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22320 Instead just throw an error, not much else we can do. */
22321 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22322 sect_offset_str (sect_off
), objfile_name (objfile
));
22325 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22327 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22328 sect_offset_str (sect_off
), objfile_name (objfile
));
22330 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22331 if (!attr
&& resolve_abstract_p
22332 && (dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22333 != dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22335 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22336 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22337 struct gdbarch
*gdbarch
= objfile
->arch ();
22339 for (const auto &cand_off
22340 : dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22342 struct dwarf2_cu
*cand_cu
= cu
;
22343 struct die_info
*cand
22344 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22347 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22350 CORE_ADDR pc_low
, pc_high
;
22351 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22352 if (pc_low
== ((CORE_ADDR
) -1))
22354 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22355 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22356 if (!(pc_low
<= pc
&& pc
< pc_high
))
22360 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22367 /* DWARF: "If there is no such attribute, then there is no effect.".
22368 DATA is ignored if SIZE is 0. */
22370 retval
.data
= NULL
;
22373 else if (attr
->form_is_section_offset ())
22375 struct dwarf2_loclist_baton loclist_baton
;
22376 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22379 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22381 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22383 retval
.size
= size
;
22387 if (!attr
->form_is_block ())
22388 error (_("Dwarf Error: DIE at %s referenced in module %s "
22389 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22390 sect_offset_str (sect_off
), objfile_name (objfile
));
22392 retval
.data
= DW_BLOCK (attr
)->data
;
22393 retval
.size
= DW_BLOCK (attr
)->size
;
22395 retval
.per_objfile
= dwarf2_per_objfile
;
22396 retval
.per_cu
= cu
->per_cu
;
22398 age_cached_comp_units (dwarf2_per_objfile
);
22405 struct dwarf2_locexpr_baton
22406 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22407 dwarf2_per_cu_data
*per_cu
,
22408 dwarf2_per_objfile
*per_objfile
,
22409 CORE_ADDR (*get_frame_pc
) (void *baton
),
22412 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22414 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22415 get_frame_pc
, baton
);
22418 /* Write a constant of a given type as target-ordered bytes into
22421 static const gdb_byte
*
22422 write_constant_as_bytes (struct obstack
*obstack
,
22423 enum bfd_endian byte_order
,
22430 *len
= TYPE_LENGTH (type
);
22431 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22432 store_unsigned_integer (result
, *len
, byte_order
, value
);
22440 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22441 dwarf2_per_cu_data
*per_cu
,
22442 dwarf2_per_objfile
*per_objfile
,
22446 struct dwarf2_cu
*cu
;
22447 struct die_info
*die
;
22448 struct attribute
*attr
;
22449 const gdb_byte
*result
= NULL
;
22452 enum bfd_endian byte_order
;
22453 struct objfile
*objfile
= per_objfile
->objfile
;
22455 if (per_cu
->cu
== NULL
)
22456 load_cu (per_cu
, per_objfile
, false);
22460 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22461 Instead just throw an error, not much else we can do. */
22462 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22463 sect_offset_str (sect_off
), objfile_name (objfile
));
22466 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22468 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22469 sect_offset_str (sect_off
), objfile_name (objfile
));
22471 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22475 byte_order
= (bfd_big_endian (objfile
->obfd
)
22476 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22478 switch (attr
->form
)
22481 case DW_FORM_addrx
:
22482 case DW_FORM_GNU_addr_index
:
22486 *len
= cu
->header
.addr_size
;
22487 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22488 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22492 case DW_FORM_string
:
22495 case DW_FORM_GNU_str_index
:
22496 case DW_FORM_GNU_strp_alt
:
22497 /* DW_STRING is already allocated on the objfile obstack, point
22499 result
= (const gdb_byte
*) DW_STRING (attr
);
22500 *len
= strlen (DW_STRING (attr
));
22502 case DW_FORM_block1
:
22503 case DW_FORM_block2
:
22504 case DW_FORM_block4
:
22505 case DW_FORM_block
:
22506 case DW_FORM_exprloc
:
22507 case DW_FORM_data16
:
22508 result
= DW_BLOCK (attr
)->data
;
22509 *len
= DW_BLOCK (attr
)->size
;
22512 /* The DW_AT_const_value attributes are supposed to carry the
22513 symbol's value "represented as it would be on the target
22514 architecture." By the time we get here, it's already been
22515 converted to host endianness, so we just need to sign- or
22516 zero-extend it as appropriate. */
22517 case DW_FORM_data1
:
22518 type
= die_type (die
, cu
);
22519 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22520 if (result
== NULL
)
22521 result
= write_constant_as_bytes (obstack
, byte_order
,
22524 case DW_FORM_data2
:
22525 type
= die_type (die
, cu
);
22526 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22527 if (result
== NULL
)
22528 result
= write_constant_as_bytes (obstack
, byte_order
,
22531 case DW_FORM_data4
:
22532 type
= die_type (die
, cu
);
22533 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22534 if (result
== NULL
)
22535 result
= write_constant_as_bytes (obstack
, byte_order
,
22538 case DW_FORM_data8
:
22539 type
= die_type (die
, cu
);
22540 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22541 if (result
== NULL
)
22542 result
= write_constant_as_bytes (obstack
, byte_order
,
22546 case DW_FORM_sdata
:
22547 case DW_FORM_implicit_const
:
22548 type
= die_type (die
, cu
);
22549 result
= write_constant_as_bytes (obstack
, byte_order
,
22550 type
, DW_SND (attr
), len
);
22553 case DW_FORM_udata
:
22554 type
= die_type (die
, cu
);
22555 result
= write_constant_as_bytes (obstack
, byte_order
,
22556 type
, DW_UNSND (attr
), len
);
22560 complaint (_("unsupported const value attribute form: '%s'"),
22561 dwarf_form_name (attr
->form
));
22571 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22572 dwarf2_per_cu_data
*per_cu
,
22573 dwarf2_per_objfile
*per_objfile
)
22575 struct dwarf2_cu
*cu
;
22576 struct die_info
*die
;
22578 if (per_cu
->cu
== NULL
)
22579 load_cu (per_cu
, per_objfile
, false);
22584 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22588 return die_type (die
, cu
);
22594 dwarf2_get_die_type (cu_offset die_offset
,
22595 struct dwarf2_per_cu_data
*per_cu
)
22597 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22598 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22601 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22602 On entry *REF_CU is the CU of SRC_DIE.
22603 On exit *REF_CU is the CU of the result.
22604 Returns NULL if the referenced DIE isn't found. */
22606 static struct die_info
*
22607 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22608 struct dwarf2_cu
**ref_cu
)
22610 struct die_info temp_die
;
22611 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22612 struct die_info
*die
;
22614 /* While it might be nice to assert sig_type->type == NULL here,
22615 we can get here for DW_AT_imported_declaration where we need
22616 the DIE not the type. */
22618 /* If necessary, add it to the queue and load its DIEs. */
22620 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22621 read_signatured_type (sig_type
, (*ref_cu
)->per_objfile
);
22623 sig_cu
= sig_type
->per_cu
.cu
;
22624 gdb_assert (sig_cu
!= NULL
);
22625 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22626 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22627 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22628 to_underlying (temp_die
.sect_off
));
22631 struct dwarf2_per_objfile
*dwarf2_per_objfile
= (*ref_cu
)->per_objfile
;
22633 /* For .gdb_index version 7 keep track of included TUs.
22634 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22635 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
22636 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7)
22638 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22643 sig_cu
->ancestor
= cu
;
22651 /* Follow signatured type referenced by ATTR in SRC_DIE.
22652 On entry *REF_CU is the CU of SRC_DIE.
22653 On exit *REF_CU is the CU of the result.
22654 The result is the DIE of the type.
22655 If the referenced type cannot be found an error is thrown. */
22657 static struct die_info
*
22658 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22659 struct dwarf2_cu
**ref_cu
)
22661 ULONGEST signature
= DW_SIGNATURE (attr
);
22662 struct signatured_type
*sig_type
;
22663 struct die_info
*die
;
22665 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22667 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22668 /* sig_type will be NULL if the signatured type is missing from
22670 if (sig_type
== NULL
)
22672 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22673 " from DIE at %s [in module %s]"),
22674 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22675 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22678 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22681 dump_die_for_error (src_die
);
22682 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22683 " from DIE at %s [in module %s]"),
22684 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22685 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22691 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22692 reading in and processing the type unit if necessary. */
22694 static struct type
*
22695 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22696 struct dwarf2_cu
*cu
)
22698 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22699 struct signatured_type
*sig_type
;
22700 struct dwarf2_cu
*type_cu
;
22701 struct die_info
*type_die
;
22704 sig_type
= lookup_signatured_type (cu
, signature
);
22705 /* sig_type will be NULL if the signatured type is missing from
22707 if (sig_type
== NULL
)
22709 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22710 " from DIE at %s [in module %s]"),
22711 hex_string (signature
), sect_offset_str (die
->sect_off
),
22712 objfile_name (dwarf2_per_objfile
->objfile
));
22713 return build_error_marker_type (cu
, die
);
22716 /* If we already know the type we're done. */
22717 if (sig_type
->type
!= NULL
)
22718 return sig_type
->type
;
22721 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22722 if (type_die
!= NULL
)
22724 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22725 is created. This is important, for example, because for c++ classes
22726 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22727 type
= read_type_die (type_die
, type_cu
);
22730 complaint (_("Dwarf Error: Cannot build signatured type %s"
22731 " referenced from DIE at %s [in module %s]"),
22732 hex_string (signature
), sect_offset_str (die
->sect_off
),
22733 objfile_name (dwarf2_per_objfile
->objfile
));
22734 type
= build_error_marker_type (cu
, die
);
22739 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22740 " from DIE at %s [in module %s]"),
22741 hex_string (signature
), sect_offset_str (die
->sect_off
),
22742 objfile_name (dwarf2_per_objfile
->objfile
));
22743 type
= build_error_marker_type (cu
, die
);
22745 sig_type
->type
= type
;
22750 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22751 reading in and processing the type unit if necessary. */
22753 static struct type
*
22754 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22755 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22757 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22758 if (attr
->form_is_ref ())
22760 struct dwarf2_cu
*type_cu
= cu
;
22761 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22763 return read_type_die (type_die
, type_cu
);
22765 else if (attr
->form
== DW_FORM_ref_sig8
)
22767 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22771 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22773 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22774 " at %s [in module %s]"),
22775 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22776 objfile_name (dwarf2_per_objfile
->objfile
));
22777 return build_error_marker_type (cu
, die
);
22781 /* Load the DIEs associated with type unit PER_CU into memory. */
22784 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22785 dwarf2_per_objfile
*per_objfile
)
22787 struct signatured_type
*sig_type
;
22789 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22790 gdb_assert (! per_cu
->type_unit_group_p ());
22792 /* We have the per_cu, but we need the signatured_type.
22793 Fortunately this is an easy translation. */
22794 gdb_assert (per_cu
->is_debug_types
);
22795 sig_type
= (struct signatured_type
*) per_cu
;
22797 gdb_assert (per_cu
->cu
== NULL
);
22799 read_signatured_type (sig_type
, per_objfile
);
22801 gdb_assert (per_cu
->cu
!= NULL
);
22804 /* Read in a signatured type and build its CU and DIEs.
22805 If the type is a stub for the real type in a DWO file,
22806 read in the real type from the DWO file as well. */
22809 read_signatured_type (signatured_type
*sig_type
,
22810 dwarf2_per_objfile
*per_objfile
)
22812 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22814 gdb_assert (per_cu
->is_debug_types
);
22815 gdb_assert (per_cu
->cu
== NULL
);
22817 cutu_reader
reader (per_cu
, per_objfile
, NULL
, 0, false);
22819 if (!reader
.dummy_p
)
22821 struct dwarf2_cu
*cu
= reader
.cu
;
22822 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22824 gdb_assert (cu
->die_hash
== NULL
);
22826 htab_create_alloc_ex (cu
->header
.length
/ 12,
22830 &cu
->comp_unit_obstack
,
22831 hashtab_obstack_allocate
,
22832 dummy_obstack_deallocate
);
22834 if (reader
.comp_unit_die
->has_children
)
22835 reader
.comp_unit_die
->child
22836 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22837 reader
.comp_unit_die
);
22838 cu
->dies
= reader
.comp_unit_die
;
22839 /* comp_unit_die is not stored in die_hash, no need. */
22841 /* We try not to read any attributes in this function, because
22842 not all CUs needed for references have been loaded yet, and
22843 symbol table processing isn't initialized. But we have to
22844 set the CU language, or we won't be able to build types
22845 correctly. Similarly, if we do not read the producer, we can
22846 not apply producer-specific interpretation. */
22847 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22852 sig_type
->per_cu
.tu_read
= 1;
22855 /* Decode simple location descriptions.
22856 Given a pointer to a dwarf block that defines a location, compute
22857 the location and return the value. If COMPUTED is non-null, it is
22858 set to true to indicate that decoding was successful, and false
22859 otherwise. If COMPUTED is null, then this function may emit a
22863 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22865 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22867 size_t size
= blk
->size
;
22868 const gdb_byte
*data
= blk
->data
;
22869 CORE_ADDR stack
[64];
22871 unsigned int bytes_read
, unsnd
;
22874 if (computed
!= nullptr)
22880 stack
[++stacki
] = 0;
22919 stack
[++stacki
] = op
- DW_OP_lit0
;
22954 stack
[++stacki
] = op
- DW_OP_reg0
;
22957 if (computed
== nullptr)
22958 dwarf2_complex_location_expr_complaint ();
22965 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22967 stack
[++stacki
] = unsnd
;
22970 if (computed
== nullptr)
22971 dwarf2_complex_location_expr_complaint ();
22978 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22983 case DW_OP_const1u
:
22984 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22988 case DW_OP_const1s
:
22989 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22993 case DW_OP_const2u
:
22994 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22998 case DW_OP_const2s
:
22999 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23003 case DW_OP_const4u
:
23004 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23008 case DW_OP_const4s
:
23009 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23013 case DW_OP_const8u
:
23014 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23019 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23025 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23030 stack
[stacki
+ 1] = stack
[stacki
];
23035 stack
[stacki
- 1] += stack
[stacki
];
23039 case DW_OP_plus_uconst
:
23040 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23046 stack
[stacki
- 1] -= stack
[stacki
];
23051 /* If we're not the last op, then we definitely can't encode
23052 this using GDB's address_class enum. This is valid for partial
23053 global symbols, although the variable's address will be bogus
23057 if (computed
== nullptr)
23058 dwarf2_complex_location_expr_complaint ();
23064 case DW_OP_GNU_push_tls_address
:
23065 case DW_OP_form_tls_address
:
23066 /* The top of the stack has the offset from the beginning
23067 of the thread control block at which the variable is located. */
23068 /* Nothing should follow this operator, so the top of stack would
23070 /* This is valid for partial global symbols, but the variable's
23071 address will be bogus in the psymtab. Make it always at least
23072 non-zero to not look as a variable garbage collected by linker
23073 which have DW_OP_addr 0. */
23076 if (computed
== nullptr)
23077 dwarf2_complex_location_expr_complaint ();
23084 case DW_OP_GNU_uninit
:
23085 if (computed
!= nullptr)
23090 case DW_OP_GNU_addr_index
:
23091 case DW_OP_GNU_const_index
:
23092 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23098 if (computed
== nullptr)
23100 const char *name
= get_DW_OP_name (op
);
23103 complaint (_("unsupported stack op: '%s'"),
23106 complaint (_("unsupported stack op: '%02x'"),
23110 return (stack
[stacki
]);
23113 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23114 outside of the allocated space. Also enforce minimum>0. */
23115 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23117 if (computed
== nullptr)
23118 complaint (_("location description stack overflow"));
23124 if (computed
== nullptr)
23125 complaint (_("location description stack underflow"));
23130 if (computed
!= nullptr)
23132 return (stack
[stacki
]);
23135 /* memory allocation interface */
23137 static struct dwarf_block
*
23138 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23140 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23143 static struct die_info
*
23144 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23146 struct die_info
*die
;
23147 size_t size
= sizeof (struct die_info
);
23150 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23152 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23153 memset (die
, 0, sizeof (struct die_info
));
23159 /* Macro support. */
23161 /* An overload of dwarf_decode_macros that finds the correct section
23162 and ensures it is read in before calling the other overload. */
23165 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23166 int section_is_gnu
)
23168 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23169 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23170 const struct line_header
*lh
= cu
->line_header
;
23171 unsigned int offset_size
= cu
->header
.offset_size
;
23172 struct dwarf2_section_info
*section
;
23173 const char *section_name
;
23175 if (cu
->dwo_unit
!= nullptr)
23177 if (section_is_gnu
)
23179 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23180 section_name
= ".debug_macro.dwo";
23184 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23185 section_name
= ".debug_macinfo.dwo";
23190 if (section_is_gnu
)
23192 section
= &dwarf2_per_objfile
->per_bfd
->macro
;
23193 section_name
= ".debug_macro";
23197 section
= &dwarf2_per_objfile
->per_bfd
->macinfo
;
23198 section_name
= ".debug_macinfo";
23202 section
->read (objfile
);
23203 if (section
->buffer
== nullptr)
23205 complaint (_("missing %s section"), section_name
);
23209 buildsym_compunit
*builder
= cu
->get_builder ();
23211 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23212 offset_size
, offset
, section_is_gnu
);
23215 /* Return the .debug_loc section to use for CU.
23216 For DWO files use .debug_loc.dwo. */
23218 static struct dwarf2_section_info
*
23219 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23221 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23225 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23227 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23229 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->per_bfd
->loclists
23230 : &dwarf2_per_objfile
->per_bfd
->loc
);
23233 /* A helper function that fills in a dwarf2_loclist_baton. */
23236 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23237 struct dwarf2_loclist_baton
*baton
,
23238 const struct attribute
*attr
)
23240 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23241 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23243 section
->read (dwarf2_per_objfile
->objfile
);
23245 baton
->per_objfile
= dwarf2_per_objfile
;
23246 baton
->per_cu
= cu
->per_cu
;
23247 gdb_assert (baton
->per_cu
);
23248 /* We don't know how long the location list is, but make sure we
23249 don't run off the edge of the section. */
23250 baton
->size
= section
->size
- DW_UNSND (attr
);
23251 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23252 if (cu
->base_address
.has_value ())
23253 baton
->base_address
= *cu
->base_address
;
23255 baton
->base_address
= 0;
23256 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23260 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23261 struct dwarf2_cu
*cu
, int is_block
)
23263 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23264 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23265 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23267 if (attr
->form_is_section_offset ()
23268 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23269 the section. If so, fall through to the complaint in the
23271 && DW_UNSND (attr
) < section
->get_size (objfile
))
23273 struct dwarf2_loclist_baton
*baton
;
23275 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23277 fill_in_loclist_baton (cu
, baton
, attr
);
23279 if (!cu
->base_address
.has_value ())
23280 complaint (_("Location list used without "
23281 "specifying the CU base address."));
23283 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23284 ? dwarf2_loclist_block_index
23285 : dwarf2_loclist_index
);
23286 SYMBOL_LOCATION_BATON (sym
) = baton
;
23290 struct dwarf2_locexpr_baton
*baton
;
23292 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23293 baton
->per_objfile
= dwarf2_per_objfile
;
23294 baton
->per_cu
= cu
->per_cu
;
23295 gdb_assert (baton
->per_cu
);
23297 if (attr
->form_is_block ())
23299 /* Note that we're just copying the block's data pointer
23300 here, not the actual data. We're still pointing into the
23301 info_buffer for SYM's objfile; right now we never release
23302 that buffer, but when we do clean up properly this may
23304 baton
->size
= DW_BLOCK (attr
)->size
;
23305 baton
->data
= DW_BLOCK (attr
)->data
;
23309 dwarf2_invalid_attrib_class_complaint ("location description",
23310 sym
->natural_name ());
23314 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23315 ? dwarf2_locexpr_block_index
23316 : dwarf2_locexpr_index
);
23317 SYMBOL_LOCATION_BATON (sym
) = baton
;
23321 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
23322 (CU_HEADERP is unused in such case) or prepare a temporary copy at
23323 CU_HEADERP first. */
23325 static const struct comp_unit_head
*
23326 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
23327 const struct dwarf2_per_cu_data
*per_cu
)
23329 const gdb_byte
*info_ptr
;
23332 return &per_cu
->cu
->header
;
23334 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
23336 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
23337 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
23338 rcuh_kind::COMPILE
);
23346 dwarf2_per_cu_data::addr_size () const
23348 struct comp_unit_head cu_header_local
;
23349 const struct comp_unit_head
*cu_headerp
;
23351 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23353 return cu_headerp
->addr_size
;
23359 dwarf2_per_cu_data::offset_size () const
23361 struct comp_unit_head cu_header_local
;
23362 const struct comp_unit_head
*cu_headerp
;
23364 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23366 return cu_headerp
->offset_size
;
23372 dwarf2_per_cu_data::ref_addr_size () const
23374 struct comp_unit_head cu_header_local
;
23375 const struct comp_unit_head
*cu_headerp
;
23377 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23379 if (cu_headerp
->version
== 2)
23380 return cu_headerp
->addr_size
;
23382 return cu_headerp
->offset_size
;
23388 dwarf2_cu::addr_type () const
23390 struct objfile
*objfile
= this->per_objfile
->objfile
;
23391 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23392 struct type
*addr_type
= lookup_pointer_type (void_type
);
23393 int addr_size
= this->per_cu
->addr_size ();
23395 if (TYPE_LENGTH (addr_type
) == addr_size
)
23398 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23402 /* A helper function for dwarf2_find_containing_comp_unit that returns
23403 the index of the result, and that searches a vector. It will
23404 return a result even if the offset in question does not actually
23405 occur in any CU. This is separate so that it can be unit
23409 dwarf2_find_containing_comp_unit
23410 (sect_offset sect_off
,
23411 unsigned int offset_in_dwz
,
23412 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23417 high
= all_comp_units
.size () - 1;
23420 struct dwarf2_per_cu_data
*mid_cu
;
23421 int mid
= low
+ (high
- low
) / 2;
23423 mid_cu
= all_comp_units
[mid
];
23424 if (mid_cu
->is_dwz
> offset_in_dwz
23425 || (mid_cu
->is_dwz
== offset_in_dwz
23426 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23431 gdb_assert (low
== high
);
23435 /* Locate the .debug_info compilation unit from CU's objfile which contains
23436 the DIE at OFFSET. Raises an error on failure. */
23438 static struct dwarf2_per_cu_data
*
23439 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23440 unsigned int offset_in_dwz
,
23441 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23444 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23445 dwarf2_per_objfile
->per_bfd
->all_comp_units
);
23446 struct dwarf2_per_cu_data
*this_cu
23447 = dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
];
23449 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23451 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23452 error (_("Dwarf Error: could not find partial DIE containing "
23453 "offset %s [in module %s]"),
23454 sect_offset_str (sect_off
),
23455 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23457 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23459 return dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1];
23463 if (low
== dwarf2_per_objfile
->per_bfd
->all_comp_units
.size () - 1
23464 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23465 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23466 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23473 namespace selftests
{
23474 namespace find_containing_comp_unit
{
23479 struct dwarf2_per_cu_data one
{};
23480 struct dwarf2_per_cu_data two
{};
23481 struct dwarf2_per_cu_data three
{};
23482 struct dwarf2_per_cu_data four
{};
23485 two
.sect_off
= sect_offset (one
.length
);
23490 four
.sect_off
= sect_offset (three
.length
);
23494 std::vector
<dwarf2_per_cu_data
*> units
;
23495 units
.push_back (&one
);
23496 units
.push_back (&two
);
23497 units
.push_back (&three
);
23498 units
.push_back (&four
);
23502 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23503 SELF_CHECK (units
[result
] == &one
);
23504 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23505 SELF_CHECK (units
[result
] == &one
);
23506 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23507 SELF_CHECK (units
[result
] == &two
);
23509 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23510 SELF_CHECK (units
[result
] == &three
);
23511 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23512 SELF_CHECK (units
[result
] == &three
);
23513 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23514 SELF_CHECK (units
[result
] == &four
);
23520 #endif /* GDB_SELF_TEST */
23522 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23524 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23525 dwarf2_per_objfile
*per_objfile
)
23527 per_objfile (per_objfile
),
23529 has_loclist (false),
23530 checked_producer (false),
23531 producer_is_gxx_lt_4_6 (false),
23532 producer_is_gcc_lt_4_3 (false),
23533 producer_is_icc (false),
23534 producer_is_icc_lt_14 (false),
23535 producer_is_codewarrior (false),
23536 processing_has_namespace_info (false)
23541 /* Destroy a dwarf2_cu. */
23543 dwarf2_cu::~dwarf2_cu ()
23548 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23551 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23552 enum language pretend_language
)
23554 struct attribute
*attr
;
23556 /* Set the language we're debugging. */
23557 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23558 if (attr
!= nullptr)
23559 set_cu_language (DW_UNSND (attr
), cu
);
23562 cu
->language
= pretend_language
;
23563 cu
->language_defn
= language_def (cu
->language
);
23566 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23569 /* Increase the age counter on each cached compilation unit, and free
23570 any that are too old. */
23573 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23575 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23577 dwarf2_clear_marks (dwarf2_per_objfile
->per_bfd
->read_in_chain
);
23578 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23579 while (per_cu
!= NULL
)
23581 per_cu
->cu
->last_used
++;
23582 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23583 dwarf2_mark (per_cu
->cu
);
23584 per_cu
= per_cu
->cu
->read_in_chain
;
23587 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23588 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23589 while (per_cu
!= NULL
)
23591 struct dwarf2_per_cu_data
*next_cu
;
23593 next_cu
= per_cu
->cu
->read_in_chain
;
23595 if (!per_cu
->cu
->mark
)
23598 *last_chain
= next_cu
;
23601 last_chain
= &per_cu
->cu
->read_in_chain
;
23607 /* Remove a single compilation unit from the cache. */
23610 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23612 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23613 struct dwarf2_per_objfile
*dwarf2_per_objfile
23614 = target_per_cu
->dwarf2_per_objfile
;
23616 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23617 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23618 while (per_cu
!= NULL
)
23620 struct dwarf2_per_cu_data
*next_cu
;
23622 next_cu
= per_cu
->cu
->read_in_chain
;
23624 if (per_cu
== target_per_cu
)
23628 *last_chain
= next_cu
;
23632 last_chain
= &per_cu
->cu
->read_in_chain
;
23638 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23639 We store these in a hash table separate from the DIEs, and preserve them
23640 when the DIEs are flushed out of cache.
23642 The CU "per_cu" pointer is needed because offset alone is not enough to
23643 uniquely identify the type. A file may have multiple .debug_types sections,
23644 or the type may come from a DWO file. Furthermore, while it's more logical
23645 to use per_cu->section+offset, with Fission the section with the data is in
23646 the DWO file but we don't know that section at the point we need it.
23647 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23648 because we can enter the lookup routine, get_die_type_at_offset, from
23649 outside this file, and thus won't necessarily have PER_CU->cu.
23650 Fortunately, PER_CU is stable for the life of the objfile. */
23652 struct dwarf2_per_cu_offset_and_type
23654 const struct dwarf2_per_cu_data
*per_cu
;
23655 sect_offset sect_off
;
23659 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23662 per_cu_offset_and_type_hash (const void *item
)
23664 const struct dwarf2_per_cu_offset_and_type
*ofs
23665 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23667 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23670 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23673 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23675 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23676 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23677 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23678 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23680 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23681 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23684 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23685 table if necessary. For convenience, return TYPE.
23687 The DIEs reading must have careful ordering to:
23688 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23689 reading current DIE.
23690 * Not trying to dereference contents of still incompletely read in types
23691 while reading in other DIEs.
23692 * Enable referencing still incompletely read in types just by a pointer to
23693 the type without accessing its fields.
23695 Therefore caller should follow these rules:
23696 * Try to fetch any prerequisite types we may need to build this DIE type
23697 before building the type and calling set_die_type.
23698 * After building type call set_die_type for current DIE as soon as
23699 possible before fetching more types to complete the current type.
23700 * Make the type as complete as possible before fetching more types. */
23702 static struct type
*
23703 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23705 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23706 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23707 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23708 struct attribute
*attr
;
23709 struct dynamic_prop prop
;
23711 /* For Ada types, make sure that the gnat-specific data is always
23712 initialized (if not already set). There are a few types where
23713 we should not be doing so, because the type-specific area is
23714 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23715 where the type-specific area is used to store the floatformat).
23716 But this is not a problem, because the gnat-specific information
23717 is actually not needed for these types. */
23718 if (need_gnat_info (cu
)
23719 && type
->code () != TYPE_CODE_FUNC
23720 && type
->code () != TYPE_CODE_FLT
23721 && type
->code () != TYPE_CODE_METHODPTR
23722 && type
->code () != TYPE_CODE_MEMBERPTR
23723 && type
->code () != TYPE_CODE_METHOD
23724 && !HAVE_GNAT_AUX_INFO (type
))
23725 INIT_GNAT_SPECIFIC (type
);
23727 /* Read DW_AT_allocated and set in type. */
23728 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23729 if (attr
!= NULL
&& attr
->form_is_block ())
23731 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23732 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23733 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23735 else if (attr
!= NULL
)
23737 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23738 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23739 sect_offset_str (die
->sect_off
));
23742 /* Read DW_AT_associated and set in type. */
23743 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23744 if (attr
!= NULL
&& attr
->form_is_block ())
23746 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23747 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23748 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23750 else if (attr
!= NULL
)
23752 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23753 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23754 sect_offset_str (die
->sect_off
));
23757 /* Read DW_AT_data_location and set in type. */
23758 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23759 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23760 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23762 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23763 dwarf2_per_objfile
->die_type_hash
23764 = htab_up (htab_create_alloc (127,
23765 per_cu_offset_and_type_hash
,
23766 per_cu_offset_and_type_eq
,
23767 NULL
, xcalloc
, xfree
));
23769 ofs
.per_cu
= cu
->per_cu
;
23770 ofs
.sect_off
= die
->sect_off
;
23772 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23773 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23775 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23776 sect_offset_str (die
->sect_off
));
23777 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23778 struct dwarf2_per_cu_offset_and_type
);
23783 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23784 or return NULL if the die does not have a saved type. */
23786 static struct type
*
23787 get_die_type_at_offset (sect_offset sect_off
,
23788 struct dwarf2_per_cu_data
*per_cu
)
23790 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23791 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23793 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23796 ofs
.per_cu
= per_cu
;
23797 ofs
.sect_off
= sect_off
;
23798 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23799 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23806 /* Look up the type for DIE in CU in die_type_hash,
23807 or return NULL if DIE does not have a saved type. */
23809 static struct type
*
23810 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23812 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23815 /* Add a dependence relationship from CU to REF_PER_CU. */
23818 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23819 struct dwarf2_per_cu_data
*ref_per_cu
)
23823 if (cu
->dependencies
== NULL
)
23825 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23826 NULL
, &cu
->comp_unit_obstack
,
23827 hashtab_obstack_allocate
,
23828 dummy_obstack_deallocate
);
23830 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23832 *slot
= ref_per_cu
;
23835 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23836 Set the mark field in every compilation unit in the
23837 cache that we must keep because we are keeping CU. */
23840 dwarf2_mark_helper (void **slot
, void *data
)
23842 struct dwarf2_per_cu_data
*per_cu
;
23844 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23846 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23847 reading of the chain. As such dependencies remain valid it is not much
23848 useful to track and undo them during QUIT cleanups. */
23849 if (per_cu
->cu
== NULL
)
23852 if (per_cu
->cu
->mark
)
23854 per_cu
->cu
->mark
= true;
23856 if (per_cu
->cu
->dependencies
!= NULL
)
23857 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23862 /* Set the mark field in CU and in every other compilation unit in the
23863 cache that we must keep because we are keeping CU. */
23866 dwarf2_mark (struct dwarf2_cu
*cu
)
23871 if (cu
->dependencies
!= NULL
)
23872 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23876 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23880 per_cu
->cu
->mark
= false;
23881 per_cu
= per_cu
->cu
->read_in_chain
;
23885 /* Trivial hash function for partial_die_info: the hash value of a DIE
23886 is its offset in .debug_info for this objfile. */
23889 partial_die_hash (const void *item
)
23891 const struct partial_die_info
*part_die
23892 = (const struct partial_die_info
*) item
;
23894 return to_underlying (part_die
->sect_off
);
23897 /* Trivial comparison function for partial_die_info structures: two DIEs
23898 are equal if they have the same offset. */
23901 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23903 const struct partial_die_info
*part_die_lhs
23904 = (const struct partial_die_info
*) item_lhs
;
23905 const struct partial_die_info
*part_die_rhs
23906 = (const struct partial_die_info
*) item_rhs
;
23908 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23911 struct cmd_list_element
*set_dwarf_cmdlist
;
23912 struct cmd_list_element
*show_dwarf_cmdlist
;
23915 show_check_physname (struct ui_file
*file
, int from_tty
,
23916 struct cmd_list_element
*c
, const char *value
)
23918 fprintf_filtered (file
,
23919 _("Whether to check \"physname\" is %s.\n"),
23923 void _initialize_dwarf2_read ();
23925 _initialize_dwarf2_read ()
23927 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
23928 Set DWARF specific variables.\n\
23929 Configure DWARF variables such as the cache size."),
23930 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23931 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23933 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
23934 Show DWARF specific variables.\n\
23935 Show DWARF variables such as the cache size."),
23936 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23937 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23939 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23940 &dwarf_max_cache_age
, _("\
23941 Set the upper bound on the age of cached DWARF compilation units."), _("\
23942 Show the upper bound on the age of cached DWARF compilation units."), _("\
23943 A higher limit means that cached compilation units will be stored\n\
23944 in memory longer, and more total memory will be used. Zero disables\n\
23945 caching, which can slow down startup."),
23947 show_dwarf_max_cache_age
,
23948 &set_dwarf_cmdlist
,
23949 &show_dwarf_cmdlist
);
23951 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23952 Set debugging of the DWARF reader."), _("\
23953 Show debugging of the DWARF reader."), _("\
23954 When enabled (non-zero), debugging messages are printed during DWARF\n\
23955 reading and symtab expansion. A value of 1 (one) provides basic\n\
23956 information. A value greater than 1 provides more verbose information."),
23959 &setdebuglist
, &showdebuglist
);
23961 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23962 Set debugging of the DWARF DIE reader."), _("\
23963 Show debugging of the DWARF DIE reader."), _("\
23964 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23965 The value is the maximum depth to print."),
23968 &setdebuglist
, &showdebuglist
);
23970 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23971 Set debugging of the dwarf line reader."), _("\
23972 Show debugging of the dwarf line reader."), _("\
23973 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23974 A value of 1 (one) provides basic information.\n\
23975 A value greater than 1 provides more verbose information."),
23978 &setdebuglist
, &showdebuglist
);
23980 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23981 Set cross-checking of \"physname\" code against demangler."), _("\
23982 Show cross-checking of \"physname\" code against demangler."), _("\
23983 When enabled, GDB's internal \"physname\" code is checked against\n\
23985 NULL
, show_check_physname
,
23986 &setdebuglist
, &showdebuglist
);
23988 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23989 no_class
, &use_deprecated_index_sections
, _("\
23990 Set whether to use deprecated gdb_index sections."), _("\
23991 Show whether to use deprecated gdb_index sections."), _("\
23992 When enabled, deprecated .gdb_index sections are used anyway.\n\
23993 Normally they are ignored either because of a missing feature or\n\
23994 performance issue.\n\
23995 Warning: This option must be enabled before gdb reads the file."),
23998 &setlist
, &showlist
);
24000 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24001 &dwarf2_locexpr_funcs
);
24002 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24003 &dwarf2_loclist_funcs
);
24005 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24006 &dwarf2_block_frame_base_locexpr_funcs
);
24007 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24008 &dwarf2_block_frame_base_loclist_funcs
);
24011 selftests::register_test ("dw2_expand_symtabs_matching",
24012 selftests::dw2_expand_symtabs_matching::run_test
);
24013 selftests::register_test ("dwarf2_find_containing_comp_unit",
24014 selftests::find_containing_comp_unit::run_test
);