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 /* The header of the compilation unit. */
425 struct comp_unit_head header
{};
427 /* Base address of this compilation unit. */
428 gdb::optional
<CORE_ADDR
> base_address
;
430 /* The language we are debugging. */
431 enum language language
= language_unknown
;
432 const struct language_defn
*language_defn
= nullptr;
434 const char *producer
= nullptr;
437 /* The symtab builder for this CU. This is only non-NULL when full
438 symbols are being read. */
439 std::unique_ptr
<buildsym_compunit
> m_builder
;
442 /* The generic symbol table building routines have separate lists for
443 file scope symbols and all all other scopes (local scopes). So
444 we need to select the right one to pass to add_symbol_to_list().
445 We do it by keeping a pointer to the correct list in list_in_scope.
447 FIXME: The original dwarf code just treated the file scope as the
448 first local scope, and all other local scopes as nested local
449 scopes, and worked fine. Check to see if we really need to
450 distinguish these in buildsym.c. */
451 struct pending
**list_in_scope
= nullptr;
453 /* Hash table holding all the loaded partial DIEs
454 with partial_die->offset.SECT_OFF as hash. */
455 htab_t partial_dies
= nullptr;
457 /* Storage for things with the same lifetime as this read-in compilation
458 unit, including partial DIEs. */
459 auto_obstack comp_unit_obstack
;
461 /* When multiple dwarf2_cu structures are living in memory, this field
462 chains them all together, so that they can be released efficiently.
463 We will probably also want a generation counter so that most-recently-used
464 compilation units are cached... */
465 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
467 /* Backlink to our per_cu entry. */
468 struct dwarf2_per_cu_data
*per_cu
;
470 /* The dwarf2_per_objfile that owns this. */
471 struct dwarf2_per_objfile
*per_objfile
;
473 /* How many compilation units ago was this CU last referenced? */
476 /* A hash table of DIE cu_offset for following references with
477 die_info->offset.sect_off as hash. */
478 htab_t die_hash
= nullptr;
480 /* Full DIEs if read in. */
481 struct die_info
*dies
= nullptr;
483 /* A set of pointers to dwarf2_per_cu_data objects for compilation
484 units referenced by this one. Only set during full symbol processing;
485 partial symbol tables do not have dependencies. */
486 htab_t dependencies
= nullptr;
488 /* Header data from the line table, during full symbol processing. */
489 struct line_header
*line_header
= nullptr;
490 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
491 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
492 this is the DW_TAG_compile_unit die for this CU. We'll hold on
493 to the line header as long as this DIE is being processed. See
494 process_die_scope. */
495 die_info
*line_header_die_owner
= nullptr;
497 /* A list of methods which need to have physnames computed
498 after all type information has been read. */
499 std::vector
<delayed_method_info
> method_list
;
501 /* To be copied to symtab->call_site_htab. */
502 htab_t call_site_htab
= nullptr;
504 /* Non-NULL if this CU came from a DWO file.
505 There is an invariant here that is important to remember:
506 Except for attributes copied from the top level DIE in the "main"
507 (or "stub") file in preparation for reading the DWO file
508 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
509 Either there isn't a DWO file (in which case this is NULL and the point
510 is moot), or there is and either we're not going to read it (in which
511 case this is NULL) or there is and we are reading it (in which case this
513 struct dwo_unit
*dwo_unit
= nullptr;
515 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
516 Note this value comes from the Fission stub CU/TU's DIE. */
517 gdb::optional
<ULONGEST
> addr_base
;
519 /* The DW_AT_rnglists_base attribute if present.
520 Note this value comes from the Fission stub CU/TU's DIE.
521 Also note that the value is zero in the non-DWO case so this value can
522 be used without needing to know whether DWO files are in use or not.
523 N.B. This does not apply to DW_AT_ranges appearing in
524 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
525 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
526 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
527 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
528 ULONGEST ranges_base
= 0;
530 /* The DW_AT_loclists_base attribute if present. */
531 ULONGEST loclist_base
= 0;
533 /* When reading debug info generated by older versions of rustc, we
534 have to rewrite some union types to be struct types with a
535 variant part. This rewriting must be done after the CU is fully
536 read in, because otherwise at the point of rewriting some struct
537 type might not have been fully processed. So, we keep a list of
538 all such types here and process them after expansion. */
539 std::vector
<struct type
*> rust_unions
;
541 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
542 files, the value is implicitly zero. For DWARF 5 version DWO files, the
543 value is often implicit and is the size of the header of
544 .debug_str_offsets section (8 or 4, depending on the address size). */
545 gdb::optional
<ULONGEST
> str_offsets_base
;
547 /* Mark used when releasing cached dies. */
550 /* This CU references .debug_loc. See the symtab->locations_valid field.
551 This test is imperfect as there may exist optimized debug code not using
552 any location list and still facing inlining issues if handled as
553 unoptimized code. For a future better test see GCC PR other/32998. */
554 bool has_loclist
: 1;
556 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
557 if all the producer_is_* fields are valid. This information is cached
558 because profiling CU expansion showed excessive time spent in
559 producer_is_gxx_lt_4_6. */
560 bool checked_producer
: 1;
561 bool producer_is_gxx_lt_4_6
: 1;
562 bool producer_is_gcc_lt_4_3
: 1;
563 bool producer_is_icc
: 1;
564 bool producer_is_icc_lt_14
: 1;
565 bool producer_is_codewarrior
: 1;
567 /* When true, the file that we're processing is known to have
568 debugging info for C++ namespaces. GCC 3.3.x did not produce
569 this information, but later versions do. */
571 bool processing_has_namespace_info
: 1;
573 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
575 /* If this CU was inherited by another CU (via specification,
576 abstract_origin, etc), this is the ancestor CU. */
579 /* Get the buildsym_compunit for this CU. */
580 buildsym_compunit
*get_builder ()
582 /* If this CU has a builder associated with it, use that. */
583 if (m_builder
!= nullptr)
584 return m_builder
.get ();
586 /* Otherwise, search ancestors for a valid builder. */
587 if (ancestor
!= nullptr)
588 return ancestor
->get_builder ();
594 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
595 This includes type_unit_group and quick_file_names. */
597 struct stmt_list_hash
599 /* The DWO unit this table is from or NULL if there is none. */
600 struct dwo_unit
*dwo_unit
;
602 /* Offset in .debug_line or .debug_line.dwo. */
603 sect_offset line_sect_off
;
606 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
607 an object of this type. */
609 struct type_unit_group
611 /* dwarf2read.c's main "handle" on a TU symtab.
612 To simplify things we create an artificial CU that "includes" all the
613 type units using this stmt_list so that the rest of the code still has
614 a "per_cu" handle on the symtab. */
615 struct dwarf2_per_cu_data per_cu
;
617 /* The TUs that share this DW_AT_stmt_list entry.
618 This is added to while parsing type units to build partial symtabs,
619 and is deleted afterwards and not used again. */
620 std::vector
<signatured_type
*> *tus
;
622 /* The compunit symtab.
623 Type units in a group needn't all be defined in the same source file,
624 so we create an essentially anonymous symtab as the compunit symtab. */
625 struct compunit_symtab
*compunit_symtab
;
627 /* The data used to construct the hash key. */
628 struct stmt_list_hash hash
;
630 /* The symbol tables for this TU (obtained from the files listed in
632 WARNING: The order of entries here must match the order of entries
633 in the line header. After the first TU using this type_unit_group, the
634 line header for the subsequent TUs is recreated from this. This is done
635 because we need to use the same symtabs for each TU using the same
636 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
637 there's no guarantee the line header doesn't have duplicate entries. */
638 struct symtab
**symtabs
;
641 /* These sections are what may appear in a (real or virtual) DWO file. */
645 struct dwarf2_section_info abbrev
;
646 struct dwarf2_section_info line
;
647 struct dwarf2_section_info loc
;
648 struct dwarf2_section_info loclists
;
649 struct dwarf2_section_info macinfo
;
650 struct dwarf2_section_info macro
;
651 struct dwarf2_section_info str
;
652 struct dwarf2_section_info str_offsets
;
653 /* In the case of a virtual DWO file, these two are unused. */
654 struct dwarf2_section_info info
;
655 std::vector
<dwarf2_section_info
> types
;
658 /* CUs/TUs in DWP/DWO files. */
662 /* Backlink to the containing struct dwo_file. */
663 struct dwo_file
*dwo_file
;
665 /* The "id" that distinguishes this CU/TU.
666 .debug_info calls this "dwo_id", .debug_types calls this "signature".
667 Since signatures came first, we stick with it for consistency. */
670 /* The section this CU/TU lives in, in the DWO file. */
671 struct dwarf2_section_info
*section
;
673 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
674 sect_offset sect_off
;
677 /* For types, offset in the type's DIE of the type defined by this TU. */
678 cu_offset type_offset_in_tu
;
681 /* include/dwarf2.h defines the DWP section codes.
682 It defines a max value but it doesn't define a min value, which we
683 use for error checking, so provide one. */
685 enum dwp_v2_section_ids
690 /* Data for one DWO file.
692 This includes virtual DWO files (a virtual DWO file is a DWO file as it
693 appears in a DWP file). DWP files don't really have DWO files per se -
694 comdat folding of types "loses" the DWO file they came from, and from
695 a high level view DWP files appear to contain a mass of random types.
696 However, to maintain consistency with the non-DWP case we pretend DWP
697 files contain virtual DWO files, and we assign each TU with one virtual
698 DWO file (generally based on the line and abbrev section offsets -
699 a heuristic that seems to work in practice). */
703 dwo_file () = default;
704 DISABLE_COPY_AND_ASSIGN (dwo_file
);
706 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
707 For virtual DWO files the name is constructed from the section offsets
708 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
709 from related CU+TUs. */
710 const char *dwo_name
= nullptr;
712 /* The DW_AT_comp_dir attribute. */
713 const char *comp_dir
= nullptr;
715 /* The bfd, when the file is open. Otherwise this is NULL.
716 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
717 gdb_bfd_ref_ptr dbfd
;
719 /* The sections that make up this DWO file.
720 Remember that for virtual DWO files in DWP V2, these are virtual
721 sections (for lack of a better name). */
722 struct dwo_sections sections
{};
724 /* The CUs in the file.
725 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
726 an extension to handle LLVM's Link Time Optimization output (where
727 multiple source files may be compiled into a single object/dwo pair). */
730 /* Table of TUs in the file.
731 Each element is a struct dwo_unit. */
735 /* These sections are what may appear in a DWP file. */
739 /* These are used by both DWP version 1 and 2. */
740 struct dwarf2_section_info str
;
741 struct dwarf2_section_info cu_index
;
742 struct dwarf2_section_info tu_index
;
744 /* These are only used by DWP version 2 files.
745 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
746 sections are referenced by section number, and are not recorded here.
747 In DWP version 2 there is at most one copy of all these sections, each
748 section being (effectively) comprised of the concatenation of all of the
749 individual sections that exist in the version 1 format.
750 To keep the code simple we treat each of these concatenated pieces as a
751 section itself (a virtual section?). */
752 struct dwarf2_section_info abbrev
;
753 struct dwarf2_section_info info
;
754 struct dwarf2_section_info line
;
755 struct dwarf2_section_info loc
;
756 struct dwarf2_section_info macinfo
;
757 struct dwarf2_section_info macro
;
758 struct dwarf2_section_info str_offsets
;
759 struct dwarf2_section_info types
;
762 /* These sections are what may appear in a virtual DWO file in DWP version 1.
763 A virtual DWO file is a DWO file as it appears in a DWP file. */
765 struct virtual_v1_dwo_sections
767 struct dwarf2_section_info abbrev
;
768 struct dwarf2_section_info line
;
769 struct dwarf2_section_info loc
;
770 struct dwarf2_section_info macinfo
;
771 struct dwarf2_section_info macro
;
772 struct dwarf2_section_info str_offsets
;
773 /* Each DWP hash table entry records one CU or one TU.
774 That is recorded here, and copied to dwo_unit.section. */
775 struct dwarf2_section_info info_or_types
;
778 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
779 In version 2, the sections of the DWO files are concatenated together
780 and stored in one section of that name. Thus each ELF section contains
781 several "virtual" sections. */
783 struct virtual_v2_dwo_sections
785 bfd_size_type abbrev_offset
;
786 bfd_size_type abbrev_size
;
788 bfd_size_type line_offset
;
789 bfd_size_type line_size
;
791 bfd_size_type loc_offset
;
792 bfd_size_type loc_size
;
794 bfd_size_type macinfo_offset
;
795 bfd_size_type macinfo_size
;
797 bfd_size_type macro_offset
;
798 bfd_size_type macro_size
;
800 bfd_size_type str_offsets_offset
;
801 bfd_size_type str_offsets_size
;
803 /* Each DWP hash table entry records one CU or one TU.
804 That is recorded here, and copied to dwo_unit.section. */
805 bfd_size_type info_or_types_offset
;
806 bfd_size_type info_or_types_size
;
809 /* Contents of DWP hash tables. */
811 struct dwp_hash_table
813 uint32_t version
, nr_columns
;
814 uint32_t nr_units
, nr_slots
;
815 const gdb_byte
*hash_table
, *unit_table
;
820 const gdb_byte
*indices
;
824 /* This is indexed by column number and gives the id of the section
826 #define MAX_NR_V2_DWO_SECTIONS \
827 (1 /* .debug_info or .debug_types */ \
828 + 1 /* .debug_abbrev */ \
829 + 1 /* .debug_line */ \
830 + 1 /* .debug_loc */ \
831 + 1 /* .debug_str_offsets */ \
832 + 1 /* .debug_macro or .debug_macinfo */)
833 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
834 const gdb_byte
*offsets
;
835 const gdb_byte
*sizes
;
840 /* Data for one DWP file. */
844 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
846 dbfd (std::move (abfd
))
850 /* Name of the file. */
853 /* File format version. */
857 gdb_bfd_ref_ptr dbfd
;
859 /* Section info for this file. */
860 struct dwp_sections sections
{};
862 /* Table of CUs in the file. */
863 const struct dwp_hash_table
*cus
= nullptr;
865 /* Table of TUs in the file. */
866 const struct dwp_hash_table
*tus
= nullptr;
868 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
872 /* Table to map ELF section numbers to their sections.
873 This is only needed for the DWP V1 file format. */
874 unsigned int num_sections
= 0;
875 asection
**elf_sections
= nullptr;
878 /* Struct used to pass misc. parameters to read_die_and_children, et
879 al. which are used for both .debug_info and .debug_types dies.
880 All parameters here are unchanging for the life of the call. This
881 struct exists to abstract away the constant parameters of die reading. */
883 struct die_reader_specs
885 /* The bfd of die_section. */
888 /* The CU of the DIE we are parsing. */
889 struct dwarf2_cu
*cu
;
891 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
892 struct dwo_file
*dwo_file
;
894 /* The section the die comes from.
895 This is either .debug_info or .debug_types, or the .dwo variants. */
896 struct dwarf2_section_info
*die_section
;
898 /* die_section->buffer. */
899 const gdb_byte
*buffer
;
901 /* The end of the buffer. */
902 const gdb_byte
*buffer_end
;
904 /* The abbreviation table to use when reading the DIEs. */
905 struct abbrev_table
*abbrev_table
;
908 /* A subclass of die_reader_specs that holds storage and has complex
909 constructor and destructor behavior. */
911 class cutu_reader
: public die_reader_specs
915 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
916 struct abbrev_table
*abbrev_table
,
920 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
921 struct dwarf2_cu
*parent_cu
= nullptr,
922 struct dwo_file
*dwo_file
= nullptr);
924 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
926 const gdb_byte
*info_ptr
= nullptr;
927 struct die_info
*comp_unit_die
= nullptr;
928 bool dummy_p
= false;
930 /* Release the new CU, putting it on the chain. This cannot be done
935 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
936 dwarf2_per_objfile
*per_objfile
,
937 int use_existing_cu
);
939 struct dwarf2_per_cu_data
*m_this_cu
;
940 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
942 /* The ordinary abbreviation table. */
943 abbrev_table_up m_abbrev_table_holder
;
945 /* The DWO abbreviation table. */
946 abbrev_table_up m_dwo_abbrev_table
;
949 /* When we construct a partial symbol table entry we only
950 need this much information. */
951 struct partial_die_info
: public allocate_on_obstack
953 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
955 /* Disable assign but still keep copy ctor, which is needed
956 load_partial_dies. */
957 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
959 /* Adjust the partial die before generating a symbol for it. This
960 function may set the is_external flag or change the DIE's
962 void fixup (struct dwarf2_cu
*cu
);
964 /* Read a minimal amount of information into the minimal die
966 const gdb_byte
*read (const struct die_reader_specs
*reader
,
967 const struct abbrev_info
&abbrev
,
968 const gdb_byte
*info_ptr
);
970 /* Offset of this DIE. */
971 const sect_offset sect_off
;
973 /* DWARF-2 tag for this DIE. */
974 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
976 /* Assorted flags describing the data found in this DIE. */
977 const unsigned int has_children
: 1;
979 unsigned int is_external
: 1;
980 unsigned int is_declaration
: 1;
981 unsigned int has_type
: 1;
982 unsigned int has_specification
: 1;
983 unsigned int has_pc_info
: 1;
984 unsigned int may_be_inlined
: 1;
986 /* This DIE has been marked DW_AT_main_subprogram. */
987 unsigned int main_subprogram
: 1;
989 /* Flag set if the SCOPE field of this structure has been
991 unsigned int scope_set
: 1;
993 /* Flag set if the DIE has a byte_size attribute. */
994 unsigned int has_byte_size
: 1;
996 /* Flag set if the DIE has a DW_AT_const_value attribute. */
997 unsigned int has_const_value
: 1;
999 /* Flag set if any of the DIE's children are template arguments. */
1000 unsigned int has_template_arguments
: 1;
1002 /* Flag set if fixup has been called on this die. */
1003 unsigned int fixup_called
: 1;
1005 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1006 unsigned int is_dwz
: 1;
1008 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1009 unsigned int spec_is_dwz
: 1;
1011 /* The name of this DIE. Normally the value of DW_AT_name, but
1012 sometimes a default name for unnamed DIEs. */
1013 const char *name
= nullptr;
1015 /* The linkage name, if present. */
1016 const char *linkage_name
= nullptr;
1018 /* The scope to prepend to our children. This is generally
1019 allocated on the comp_unit_obstack, so will disappear
1020 when this compilation unit leaves the cache. */
1021 const char *scope
= nullptr;
1023 /* Some data associated with the partial DIE. The tag determines
1024 which field is live. */
1027 /* The location description associated with this DIE, if any. */
1028 struct dwarf_block
*locdesc
;
1029 /* The offset of an import, for DW_TAG_imported_unit. */
1030 sect_offset sect_off
;
1033 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1034 CORE_ADDR lowpc
= 0;
1035 CORE_ADDR highpc
= 0;
1037 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1038 DW_AT_sibling, if any. */
1039 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1040 could return DW_AT_sibling values to its caller load_partial_dies. */
1041 const gdb_byte
*sibling
= nullptr;
1043 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1044 DW_AT_specification (or DW_AT_abstract_origin or
1045 DW_AT_extension). */
1046 sect_offset spec_offset
{};
1048 /* Pointers to this DIE's parent, first child, and next sibling,
1050 struct partial_die_info
*die_parent
= nullptr;
1051 struct partial_die_info
*die_child
= nullptr;
1052 struct partial_die_info
*die_sibling
= nullptr;
1054 friend struct partial_die_info
*
1055 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1058 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1059 partial_die_info (sect_offset sect_off
)
1060 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1064 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1066 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1071 has_specification
= 0;
1074 main_subprogram
= 0;
1077 has_const_value
= 0;
1078 has_template_arguments
= 0;
1085 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1086 but this would require a corresponding change in unpack_field_as_long
1088 static int bits_per_byte
= 8;
1090 struct variant_part_builder
;
1092 /* When reading a variant, we track a bit more information about the
1093 field, and store it in an object of this type. */
1095 struct variant_field
1097 int first_field
= -1;
1098 int last_field
= -1;
1100 /* A variant can contain other variant parts. */
1101 std::vector
<variant_part_builder
> variant_parts
;
1103 /* If we see a DW_TAG_variant, then this will be set if this is the
1105 bool default_branch
= false;
1106 /* If we see a DW_AT_discr_value, then this will be the discriminant
1108 ULONGEST discriminant_value
= 0;
1109 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1111 struct dwarf_block
*discr_list_data
= nullptr;
1114 /* This represents a DW_TAG_variant_part. */
1116 struct variant_part_builder
1118 /* The offset of the discriminant field. */
1119 sect_offset discriminant_offset
{};
1121 /* Variants that are direct children of this variant part. */
1122 std::vector
<variant_field
> variants
;
1124 /* True if we're currently reading a variant. */
1125 bool processing_variant
= false;
1130 int accessibility
= 0;
1132 /* Variant parts need to find the discriminant, which is a DIE
1133 reference. We track the section offset of each field to make
1136 struct field field
{};
1141 const char *name
= nullptr;
1142 std::vector
<struct fn_field
> fnfields
;
1145 /* The routines that read and process dies for a C struct or C++ class
1146 pass lists of data member fields and lists of member function fields
1147 in an instance of a field_info structure, as defined below. */
1150 /* List of data member and baseclasses fields. */
1151 std::vector
<struct nextfield
> fields
;
1152 std::vector
<struct nextfield
> baseclasses
;
1154 /* Set if the accessibility of one of the fields is not public. */
1155 int non_public_fields
= 0;
1157 /* Member function fieldlist array, contains name of possibly overloaded
1158 member function, number of overloaded member functions and a pointer
1159 to the head of the member function field chain. */
1160 std::vector
<struct fnfieldlist
> fnfieldlists
;
1162 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1163 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1164 std::vector
<struct decl_field
> typedef_field_list
;
1166 /* Nested types defined by this class and the number of elements in this
1168 std::vector
<struct decl_field
> nested_types_list
;
1170 /* If non-null, this is the variant part we are currently
1172 variant_part_builder
*current_variant_part
= nullptr;
1173 /* This holds all the top-level variant parts attached to the type
1175 std::vector
<variant_part_builder
> variant_parts
;
1177 /* Return the total number of fields (including baseclasses). */
1178 int nfields () const
1180 return fields
.size () + baseclasses
.size ();
1184 /* Loaded secondary compilation units are kept in memory until they
1185 have not been referenced for the processing of this many
1186 compilation units. Set this to zero to disable caching. Cache
1187 sizes of up to at least twenty will improve startup time for
1188 typical inter-CU-reference binaries, at an obvious memory cost. */
1189 static int dwarf_max_cache_age
= 5;
1191 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1192 struct cmd_list_element
*c
, const char *value
)
1194 fprintf_filtered (file
, _("The upper bound on the age of cached "
1195 "DWARF compilation units is %s.\n"),
1199 /* local function prototypes */
1201 static void dwarf2_find_base_address (struct die_info
*die
,
1202 struct dwarf2_cu
*cu
);
1204 static dwarf2_psymtab
*create_partial_symtab
1205 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1207 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1208 const gdb_byte
*info_ptr
,
1209 struct die_info
*type_unit_die
);
1211 static void dwarf2_build_psymtabs_hard
1212 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1214 static void scan_partial_symbols (struct partial_die_info
*,
1215 CORE_ADDR
*, CORE_ADDR
*,
1216 int, struct dwarf2_cu
*);
1218 static void add_partial_symbol (struct partial_die_info
*,
1219 struct dwarf2_cu
*);
1221 static void add_partial_namespace (struct partial_die_info
*pdi
,
1222 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1223 int set_addrmap
, struct dwarf2_cu
*cu
);
1225 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1226 CORE_ADDR
*highpc
, int set_addrmap
,
1227 struct dwarf2_cu
*cu
);
1229 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1230 struct dwarf2_cu
*cu
);
1232 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1233 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1234 int need_pc
, struct dwarf2_cu
*cu
);
1236 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1238 static struct partial_die_info
*load_partial_dies
1239 (const struct die_reader_specs
*, const gdb_byte
*, int);
1241 /* A pair of partial_die_info and compilation unit. */
1242 struct cu_partial_die_info
1244 /* The compilation unit of the partial_die_info. */
1245 struct dwarf2_cu
*cu
;
1246 /* A partial_die_info. */
1247 struct partial_die_info
*pdi
;
1249 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1255 cu_partial_die_info () = delete;
1258 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1259 struct dwarf2_cu
*);
1261 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1262 struct attribute
*, struct attr_abbrev
*,
1263 const gdb_byte
*, bool *need_reprocess
);
1265 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1266 struct attribute
*attr
);
1268 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1270 static sect_offset read_abbrev_offset
1271 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1272 struct dwarf2_section_info
*, sect_offset
);
1274 static const char *read_indirect_string
1275 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1276 const struct comp_unit_head
*, unsigned int *);
1278 static const char *read_indirect_string_at_offset
1279 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1281 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1285 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1286 ULONGEST str_index
);
1288 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1289 ULONGEST str_index
);
1291 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1293 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1294 struct dwarf2_cu
*);
1296 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1297 struct dwarf2_cu
*cu
);
1299 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1301 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1302 struct dwarf2_cu
*cu
);
1304 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1306 static struct die_info
*die_specification (struct die_info
*die
,
1307 struct dwarf2_cu
**);
1309 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1310 struct dwarf2_cu
*cu
);
1312 static void dwarf_decode_lines (struct line_header
*, const char *,
1313 struct dwarf2_cu
*, dwarf2_psymtab
*,
1314 CORE_ADDR
, int decode_mapping
);
1316 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1319 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1320 struct dwarf2_cu
*, struct symbol
* = NULL
);
1322 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1323 struct dwarf2_cu
*);
1325 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1328 struct obstack
*obstack
,
1329 struct dwarf2_cu
*cu
, LONGEST
*value
,
1330 const gdb_byte
**bytes
,
1331 struct dwarf2_locexpr_baton
**baton
);
1333 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1335 static int need_gnat_info (struct dwarf2_cu
*);
1337 static struct type
*die_descriptive_type (struct die_info
*,
1338 struct dwarf2_cu
*);
1340 static void set_descriptive_type (struct type
*, struct die_info
*,
1341 struct dwarf2_cu
*);
1343 static struct type
*die_containing_type (struct die_info
*,
1344 struct dwarf2_cu
*);
1346 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1347 struct dwarf2_cu
*);
1349 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1351 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1353 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1355 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1356 const char *suffix
, int physname
,
1357 struct dwarf2_cu
*cu
);
1359 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1361 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1363 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1365 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1367 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1369 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1371 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1372 struct dwarf2_cu
*, dwarf2_psymtab
*);
1374 /* Return the .debug_loclists section to use for cu. */
1375 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1377 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1378 values. Keep the items ordered with increasing constraints compliance. */
1381 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1382 PC_BOUNDS_NOT_PRESENT
,
1384 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1385 were present but they do not form a valid range of PC addresses. */
1388 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1391 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1395 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1396 CORE_ADDR
*, CORE_ADDR
*,
1400 static void get_scope_pc_bounds (struct die_info
*,
1401 CORE_ADDR
*, CORE_ADDR
*,
1402 struct dwarf2_cu
*);
1404 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1405 CORE_ADDR
, struct dwarf2_cu
*);
1407 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1408 struct dwarf2_cu
*);
1410 static void dwarf2_attach_fields_to_type (struct field_info
*,
1411 struct type
*, struct dwarf2_cu
*);
1413 static void dwarf2_add_member_fn (struct field_info
*,
1414 struct die_info
*, struct type
*,
1415 struct dwarf2_cu
*);
1417 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1419 struct dwarf2_cu
*);
1421 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1423 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1425 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1427 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1429 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1431 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1433 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1435 static struct type
*read_module_type (struct die_info
*die
,
1436 struct dwarf2_cu
*cu
);
1438 static const char *namespace_name (struct die_info
*die
,
1439 int *is_anonymous
, struct dwarf2_cu
*);
1441 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1443 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1446 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1447 struct dwarf2_cu
*);
1449 static struct die_info
*read_die_and_siblings_1
1450 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1453 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1454 const gdb_byte
*info_ptr
,
1455 const gdb_byte
**new_info_ptr
,
1456 struct die_info
*parent
);
1458 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1459 struct die_info
**, const gdb_byte
*,
1462 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1463 struct die_info
**, const gdb_byte
*);
1465 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1467 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1470 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1472 static const char *dwarf2_full_name (const char *name
,
1473 struct die_info
*die
,
1474 struct dwarf2_cu
*cu
);
1476 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1477 struct dwarf2_cu
*cu
);
1479 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1480 struct dwarf2_cu
**);
1482 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1484 static void dump_die_for_error (struct die_info
*);
1486 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1489 /*static*/ void dump_die (struct die_info
*, int max_level
);
1491 static void store_in_ref_table (struct die_info
*,
1492 struct dwarf2_cu
*);
1494 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1495 const struct attribute
*,
1496 struct dwarf2_cu
**);
1498 static struct die_info
*follow_die_ref (struct die_info
*,
1499 const struct attribute
*,
1500 struct dwarf2_cu
**);
1502 static struct die_info
*follow_die_sig (struct die_info
*,
1503 const struct attribute
*,
1504 struct dwarf2_cu
**);
1506 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1507 struct dwarf2_cu
*);
1509 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1510 const struct attribute
*,
1511 struct dwarf2_cu
*);
1513 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1515 static void read_signatured_type (struct signatured_type
*);
1517 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1518 struct die_info
*die
, struct dwarf2_cu
*cu
,
1519 struct dynamic_prop
*prop
, struct type
*type
);
1521 /* memory allocation interface */
1523 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1525 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1527 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1529 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1530 struct dwarf2_loclist_baton
*baton
,
1531 const struct attribute
*attr
);
1533 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1535 struct dwarf2_cu
*cu
,
1538 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1539 const gdb_byte
*info_ptr
,
1540 struct abbrev_info
*abbrev
);
1542 static hashval_t
partial_die_hash (const void *item
);
1544 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1546 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1547 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1548 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1550 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1551 struct die_info
*comp_unit_die
,
1552 enum language pretend_language
);
1554 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1556 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1558 static struct type
*set_die_type (struct die_info
*, struct type
*,
1559 struct dwarf2_cu
*);
1561 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1563 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1565 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1568 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1571 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1574 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1575 struct dwarf2_per_cu_data
*);
1577 static void dwarf2_mark (struct dwarf2_cu
*);
1579 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1581 static struct type
*get_die_type_at_offset (sect_offset
,
1582 struct dwarf2_per_cu_data
*);
1584 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1586 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1587 enum language pretend_language
);
1589 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1591 /* Class, the destructor of which frees all allocated queue entries. This
1592 will only have work to do if an error was thrown while processing the
1593 dwarf. If no error was thrown then the queue entries should have all
1594 been processed, and freed, as we went along. */
1596 class dwarf2_queue_guard
1599 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1600 : m_per_objfile (per_objfile
)
1604 /* Free any entries remaining on the queue. There should only be
1605 entries left if we hit an error while processing the dwarf. */
1606 ~dwarf2_queue_guard ()
1608 /* Ensure that no memory is allocated by the queue. */
1609 std::queue
<dwarf2_queue_item
> empty
;
1610 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1613 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1616 dwarf2_per_objfile
*m_per_objfile
;
1619 dwarf2_queue_item::~dwarf2_queue_item ()
1621 /* Anything still marked queued is likely to be in an
1622 inconsistent state, so discard it. */
1625 if (per_cu
->cu
!= NULL
)
1626 free_one_cached_comp_unit (per_cu
);
1631 /* The return type of find_file_and_directory. Note, the enclosed
1632 string pointers are only valid while this object is valid. */
1634 struct file_and_directory
1636 /* The filename. This is never NULL. */
1639 /* The compilation directory. NULL if not known. If we needed to
1640 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1641 points directly to the DW_AT_comp_dir string attribute owned by
1642 the obstack that owns the DIE. */
1643 const char *comp_dir
;
1645 /* If we needed to build a new string for comp_dir, this is what
1646 owns the storage. */
1647 std::string comp_dir_storage
;
1650 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1651 struct dwarf2_cu
*cu
);
1653 static htab_up
allocate_signatured_type_table ();
1655 static htab_up
allocate_dwo_unit_table ();
1657 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1658 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1659 struct dwp_file
*dwp_file
, const char *comp_dir
,
1660 ULONGEST signature
, int is_debug_types
);
1662 static struct dwp_file
*get_dwp_file
1663 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1665 static struct dwo_unit
*lookup_dwo_comp_unit
1666 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1668 static struct dwo_unit
*lookup_dwo_type_unit
1669 (struct signatured_type
*, const char *, const char *);
1671 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1673 /* A unique pointer to a dwo_file. */
1675 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1677 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1679 static void check_producer (struct dwarf2_cu
*cu
);
1681 static void free_line_header_voidp (void *arg
);
1683 /* Various complaints about symbol reading that don't abort the process. */
1686 dwarf2_debug_line_missing_file_complaint (void)
1688 complaint (_(".debug_line section has line data without a file"));
1692 dwarf2_debug_line_missing_end_sequence_complaint (void)
1694 complaint (_(".debug_line section has line "
1695 "program sequence without an end"));
1699 dwarf2_complex_location_expr_complaint (void)
1701 complaint (_("location expression too complex"));
1705 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1708 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1713 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1715 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1719 /* Hash function for line_header_hash. */
1722 line_header_hash (const struct line_header
*ofs
)
1724 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1727 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1730 line_header_hash_voidp (const void *item
)
1732 const struct line_header
*ofs
= (const struct line_header
*) item
;
1734 return line_header_hash (ofs
);
1737 /* Equality function for line_header_hash. */
1740 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1742 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1743 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1745 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1746 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1751 /* See declaration. */
1753 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1755 : can_copy (can_copy_
)
1758 names
= &dwarf2_elf_names
;
1760 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1761 locate_sections (obfd
, sec
, *names
);
1764 dwarf2_per_bfd::~dwarf2_per_bfd ()
1766 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1767 free_cached_comp_units ();
1769 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1770 per_cu
->imported_symtabs_free ();
1772 for (signatured_type
*sig_type
: all_type_units
)
1773 sig_type
->per_cu
.imported_symtabs_free ();
1775 /* Everything else should be on this->obstack. */
1778 /* See declaration. */
1781 dwarf2_per_bfd::free_cached_comp_units ()
1783 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1784 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1785 while (per_cu
!= NULL
)
1787 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1790 *last_chain
= next_cu
;
1795 /* A helper class that calls free_cached_comp_units on
1798 class free_cached_comp_units
1802 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1803 : m_per_objfile (per_objfile
)
1807 ~free_cached_comp_units ()
1809 m_per_objfile
->per_bfd
->free_cached_comp_units ();
1812 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1816 dwarf2_per_objfile
*m_per_objfile
;
1822 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1824 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1826 return this->m_symtabs
[per_cu
->index
] != nullptr;
1832 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1834 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1836 return this->m_symtabs
[per_cu
->index
];
1842 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1843 compunit_symtab
*symtab
)
1845 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1846 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1848 this->m_symtabs
[per_cu
->index
] = symtab
;
1851 /* Try to locate the sections we need for DWARF 2 debugging
1852 information and return true if we have enough to do something.
1853 NAMES points to the dwarf2 section names, or is NULL if the standard
1854 ELF names are used. CAN_COPY is true for formats where symbol
1855 interposition is possible and so symbol values must follow copy
1856 relocation rules. */
1859 dwarf2_has_info (struct objfile
*objfile
,
1860 const struct dwarf2_debug_sections
*names
,
1863 if (objfile
->flags
& OBJF_READNEVER
)
1866 struct dwarf2_per_objfile
*dwarf2_per_objfile
1867 = get_dwarf2_per_objfile (objfile
);
1869 if (dwarf2_per_objfile
== NULL
)
1871 /* For now, each dwarf2_per_objfile owns its own dwarf2_per_bfd (no
1873 dwarf2_per_bfd
*per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1875 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1878 return (!dwarf2_per_objfile
->per_bfd
->info
.is_virtual
1879 && dwarf2_per_objfile
->per_bfd
->info
.s
.section
!= NULL
1880 && !dwarf2_per_objfile
->per_bfd
->abbrev
.is_virtual
1881 && dwarf2_per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1884 /* When loading sections, we look either for uncompressed section or for
1885 compressed section names. */
1888 section_is_p (const char *section_name
,
1889 const struct dwarf2_section_names
*names
)
1891 if (names
->normal
!= NULL
1892 && strcmp (section_name
, names
->normal
) == 0)
1894 if (names
->compressed
!= NULL
1895 && strcmp (section_name
, names
->compressed
) == 0)
1900 /* See declaration. */
1903 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1904 const dwarf2_debug_sections
&names
)
1906 flagword aflag
= bfd_section_flags (sectp
);
1908 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1911 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1912 > bfd_get_file_size (abfd
))
1914 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1915 warning (_("Discarding section %s which has a section size (%s"
1916 ") larger than the file size [in module %s]"),
1917 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1918 bfd_get_filename (abfd
));
1920 else if (section_is_p (sectp
->name
, &names
.info
))
1922 this->info
.s
.section
= sectp
;
1923 this->info
.size
= bfd_section_size (sectp
);
1925 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1927 this->abbrev
.s
.section
= sectp
;
1928 this->abbrev
.size
= bfd_section_size (sectp
);
1930 else if (section_is_p (sectp
->name
, &names
.line
))
1932 this->line
.s
.section
= sectp
;
1933 this->line
.size
= bfd_section_size (sectp
);
1935 else if (section_is_p (sectp
->name
, &names
.loc
))
1937 this->loc
.s
.section
= sectp
;
1938 this->loc
.size
= bfd_section_size (sectp
);
1940 else if (section_is_p (sectp
->name
, &names
.loclists
))
1942 this->loclists
.s
.section
= sectp
;
1943 this->loclists
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1947 this->macinfo
.s
.section
= sectp
;
1948 this->macinfo
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.macro
))
1952 this->macro
.s
.section
= sectp
;
1953 this->macro
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.str
))
1957 this->str
.s
.section
= sectp
;
1958 this->str
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1962 this->str_offsets
.s
.section
= sectp
;
1963 this->str_offsets
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.line_str
))
1967 this->line_str
.s
.section
= sectp
;
1968 this->line_str
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.addr
))
1972 this->addr
.s
.section
= sectp
;
1973 this->addr
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.frame
))
1977 this->frame
.s
.section
= sectp
;
1978 this->frame
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1982 this->eh_frame
.s
.section
= sectp
;
1983 this->eh_frame
.size
= bfd_section_size (sectp
);
1985 else if (section_is_p (sectp
->name
, &names
.ranges
))
1987 this->ranges
.s
.section
= sectp
;
1988 this->ranges
.size
= bfd_section_size (sectp
);
1990 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1992 this->rnglists
.s
.section
= sectp
;
1993 this->rnglists
.size
= bfd_section_size (sectp
);
1995 else if (section_is_p (sectp
->name
, &names
.types
))
1997 struct dwarf2_section_info type_section
;
1999 memset (&type_section
, 0, sizeof (type_section
));
2000 type_section
.s
.section
= sectp
;
2001 type_section
.size
= bfd_section_size (sectp
);
2003 this->types
.push_back (type_section
);
2005 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2007 this->gdb_index
.s
.section
= sectp
;
2008 this->gdb_index
.size
= bfd_section_size (sectp
);
2010 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2012 this->debug_names
.s
.section
= sectp
;
2013 this->debug_names
.size
= bfd_section_size (sectp
);
2015 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2017 this->debug_aranges
.s
.section
= sectp
;
2018 this->debug_aranges
.size
= bfd_section_size (sectp
);
2021 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2022 && bfd_section_vma (sectp
) == 0)
2023 this->has_section_at_zero
= true;
2026 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2030 dwarf2_get_section_info (struct objfile
*objfile
,
2031 enum dwarf2_section_enum sect
,
2032 asection
**sectp
, const gdb_byte
**bufp
,
2033 bfd_size_type
*sizep
)
2035 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2036 struct dwarf2_section_info
*info
;
2038 /* We may see an objfile without any DWARF, in which case we just
2049 case DWARF2_DEBUG_FRAME
:
2050 info
= &data
->per_bfd
->frame
;
2052 case DWARF2_EH_FRAME
:
2053 info
= &data
->per_bfd
->eh_frame
;
2056 gdb_assert_not_reached ("unexpected section");
2059 info
->read (objfile
);
2061 *sectp
= info
->get_bfd_section ();
2062 *bufp
= info
->buffer
;
2063 *sizep
= info
->size
;
2066 /* A helper function to find the sections for a .dwz file. */
2069 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2071 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2073 /* Note that we only support the standard ELF names, because .dwz
2074 is ELF-only (at the time of writing). */
2075 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2077 dwz_file
->abbrev
.s
.section
= sectp
;
2078 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2080 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2082 dwz_file
->info
.s
.section
= sectp
;
2083 dwz_file
->info
.size
= bfd_section_size (sectp
);
2085 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2087 dwz_file
->str
.s
.section
= sectp
;
2088 dwz_file
->str
.size
= bfd_section_size (sectp
);
2090 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2092 dwz_file
->line
.s
.section
= sectp
;
2093 dwz_file
->line
.size
= bfd_section_size (sectp
);
2095 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2097 dwz_file
->macro
.s
.section
= sectp
;
2098 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2100 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2102 dwz_file
->gdb_index
.s
.section
= sectp
;
2103 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2105 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2107 dwz_file
->debug_names
.s
.section
= sectp
;
2108 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2112 /* See dwarf2read.h. */
2115 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2117 const char *filename
;
2118 bfd_size_type buildid_len_arg
;
2122 if (dwarf2_per_objfile
->per_bfd
->dwz_file
!= NULL
)
2123 return dwarf2_per_objfile
->per_bfd
->dwz_file
.get ();
2125 bfd_set_error (bfd_error_no_error
);
2126 gdb::unique_xmalloc_ptr
<char> data
2127 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2128 &buildid_len_arg
, &buildid
));
2131 if (bfd_get_error () == bfd_error_no_error
)
2133 error (_("could not read '.gnu_debugaltlink' section: %s"),
2134 bfd_errmsg (bfd_get_error ()));
2137 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2139 buildid_len
= (size_t) buildid_len_arg
;
2141 filename
= data
.get ();
2143 std::string abs_storage
;
2144 if (!IS_ABSOLUTE_PATH (filename
))
2146 gdb::unique_xmalloc_ptr
<char> abs
2147 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2149 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2150 filename
= abs_storage
.c_str ();
2153 /* First try the file name given in the section. If that doesn't
2154 work, try to use the build-id instead. */
2155 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2156 if (dwz_bfd
!= NULL
)
2158 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2159 dwz_bfd
.reset (nullptr);
2162 if (dwz_bfd
== NULL
)
2163 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2165 if (dwz_bfd
== nullptr)
2167 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2168 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2170 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2177 /* File successfully retrieved from server. */
2178 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2180 if (dwz_bfd
== nullptr)
2181 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2182 alt_filename
.get ());
2183 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2184 dwz_bfd
.reset (nullptr);
2188 if (dwz_bfd
== NULL
)
2189 error (_("could not find '.gnu_debugaltlink' file for %s"),
2190 objfile_name (dwarf2_per_objfile
->objfile
));
2192 std::unique_ptr
<struct dwz_file
> result
2193 (new struct dwz_file (std::move (dwz_bfd
)));
2195 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2198 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2199 result
->dwz_bfd
.get ());
2200 dwarf2_per_objfile
->per_bfd
->dwz_file
= std::move (result
);
2201 return dwarf2_per_objfile
->per_bfd
->dwz_file
.get ();
2204 /* DWARF quick_symbols_functions support. */
2206 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2207 unique line tables, so we maintain a separate table of all .debug_line
2208 derived entries to support the sharing.
2209 All the quick functions need is the list of file names. We discard the
2210 line_header when we're done and don't need to record it here. */
2211 struct quick_file_names
2213 /* The data used to construct the hash key. */
2214 struct stmt_list_hash hash
;
2216 /* The number of entries in file_names, real_names. */
2217 unsigned int num_file_names
;
2219 /* The file names from the line table, after being run through
2221 const char **file_names
;
2223 /* The file names from the line table after being run through
2224 gdb_realpath. These are computed lazily. */
2225 const char **real_names
;
2228 /* When using the index (and thus not using psymtabs), each CU has an
2229 object of this type. This is used to hold information needed by
2230 the various "quick" methods. */
2231 struct dwarf2_per_cu_quick_data
2233 /* The file table. This can be NULL if there was no file table
2234 or it's currently not read in.
2235 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2236 struct quick_file_names
*file_names
;
2238 /* A temporary mark bit used when iterating over all CUs in
2239 expand_symtabs_matching. */
2240 unsigned int mark
: 1;
2242 /* True if we've tried to read the file table and found there isn't one.
2243 There will be no point in trying to read it again next time. */
2244 unsigned int no_file_data
: 1;
2247 /* Utility hash function for a stmt_list_hash. */
2250 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2254 if (stmt_list_hash
->dwo_unit
!= NULL
)
2255 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2256 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2260 /* Utility equality function for a stmt_list_hash. */
2263 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2264 const struct stmt_list_hash
*rhs
)
2266 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2268 if (lhs
->dwo_unit
!= NULL
2269 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2272 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2275 /* Hash function for a quick_file_names. */
2278 hash_file_name_entry (const void *e
)
2280 const struct quick_file_names
*file_data
2281 = (const struct quick_file_names
*) e
;
2283 return hash_stmt_list_entry (&file_data
->hash
);
2286 /* Equality function for a quick_file_names. */
2289 eq_file_name_entry (const void *a
, const void *b
)
2291 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2292 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2294 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2297 /* Delete function for a quick_file_names. */
2300 delete_file_name_entry (void *e
)
2302 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2305 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2307 xfree ((void*) file_data
->file_names
[i
]);
2308 if (file_data
->real_names
)
2309 xfree ((void*) file_data
->real_names
[i
]);
2312 /* The space for the struct itself lives on the obstack, so we don't
2316 /* Create a quick_file_names hash table. */
2319 create_quick_file_names_table (unsigned int nr_initial_entries
)
2321 return htab_up (htab_create_alloc (nr_initial_entries
,
2322 hash_file_name_entry
, eq_file_name_entry
,
2323 delete_file_name_entry
, xcalloc
, xfree
));
2326 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2327 have to be created afterwards. You should call age_cached_comp_units after
2328 processing PER_CU->CU. dw2_setup must have been already called. */
2331 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2333 if (per_cu
->is_debug_types
)
2334 load_full_type_unit (per_cu
);
2336 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2338 if (per_cu
->cu
== NULL
)
2339 return; /* Dummy CU. */
2341 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2344 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2347 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2348 dwarf2_per_objfile
*dwarf2_per_objfile
,
2351 /* Skip type_unit_groups, reading the type units they contain
2352 is handled elsewhere. */
2353 if (per_cu
->type_unit_group_p ())
2356 /* The destructor of dwarf2_queue_guard frees any entries left on
2357 the queue. After this point we're guaranteed to leave this function
2358 with the dwarf queue empty. */
2359 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2361 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2363 queue_comp_unit (per_cu
, language_minimal
);
2364 load_cu (per_cu
, skip_partial
);
2366 /* If we just loaded a CU from a DWO, and we're working with an index
2367 that may badly handle TUs, load all the TUs in that DWO as well.
2368 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2369 if (!per_cu
->is_debug_types
2370 && per_cu
->cu
!= NULL
2371 && per_cu
->cu
->dwo_unit
!= NULL
2372 && dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
2373 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7
2374 /* DWP files aren't supported yet. */
2375 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2376 queue_and_load_all_dwo_tus (per_cu
);
2379 process_queue (dwarf2_per_objfile
);
2381 /* Age the cache, releasing compilation units that have not
2382 been used recently. */
2383 age_cached_comp_units (dwarf2_per_objfile
);
2386 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2387 the per-objfile for which this symtab is instantiated.
2389 Returns the resulting symbol table. */
2391 static struct compunit_symtab
*
2392 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2393 dwarf2_per_objfile
*dwarf2_per_objfile
,
2396 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
2398 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2400 free_cached_comp_units
freer (dwarf2_per_objfile
);
2401 scoped_restore decrementer
= increment_reading_symtab ();
2402 dw2_do_instantiate_symtab (per_cu
, dwarf2_per_objfile
, skip_partial
);
2403 process_cu_includes (dwarf2_per_objfile
);
2406 return dwarf2_per_objfile
->get_symtab (per_cu
);
2409 /* See declaration. */
2411 dwarf2_per_cu_data
*
2412 dwarf2_per_bfd::get_cutu (int index
)
2414 if (index
>= this->all_comp_units
.size ())
2416 index
-= this->all_comp_units
.size ();
2417 gdb_assert (index
< this->all_type_units
.size ());
2418 return &this->all_type_units
[index
]->per_cu
;
2421 return this->all_comp_units
[index
];
2424 /* See declaration. */
2426 dwarf2_per_cu_data
*
2427 dwarf2_per_bfd::get_cu (int index
)
2429 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2431 return this->all_comp_units
[index
];
2434 /* See declaration. */
2437 dwarf2_per_bfd::get_tu (int index
)
2439 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2441 return this->all_type_units
[index
];
2446 dwarf2_per_cu_data
*
2447 dwarf2_per_bfd::allocate_per_cu ()
2449 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2450 result
->index
= m_num_psymtabs
++;
2457 dwarf2_per_bfd::allocate_signatured_type ()
2459 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2460 result
->per_cu
.index
= m_num_psymtabs
++;
2464 /* Return a new dwarf2_per_cu_data allocated on the dwarf2_per_objfile
2465 obstack, and constructed with the specified field values. */
2467 static dwarf2_per_cu_data
*
2468 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2469 struct dwarf2_section_info
*section
,
2471 sect_offset sect_off
, ULONGEST length
)
2473 dwarf2_per_cu_data
*the_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
2474 the_cu
->sect_off
= sect_off
;
2475 the_cu
->length
= length
;
2476 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2477 the_cu
->section
= section
;
2478 the_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2479 struct dwarf2_per_cu_quick_data
);
2480 the_cu
->is_dwz
= is_dwz
;
2484 /* A helper for create_cus_from_index that handles a given list of
2488 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2489 const gdb_byte
*cu_list
, offset_type n_elements
,
2490 struct dwarf2_section_info
*section
,
2493 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2495 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2497 sect_offset sect_off
2498 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2499 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2502 dwarf2_per_cu_data
*per_cu
2503 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2505 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
2509 /* Read the CU list from the mapped index, and use it to create all
2510 the CU objects for this objfile. */
2513 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2514 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2515 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2517 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
2518 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve
2519 ((cu_list_elements
+ dwz_elements
) / 2);
2521 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2522 &dwarf2_per_objfile
->per_bfd
->info
, 0);
2524 if (dwz_elements
== 0)
2527 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2528 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2532 /* Create the signatured type hash table from the index. */
2535 create_signatured_type_table_from_index
2536 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2537 struct dwarf2_section_info
*section
,
2538 const gdb_byte
*bytes
,
2539 offset_type elements
)
2541 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2542 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (elements
/ 3);
2544 htab_up sig_types_hash
= allocate_signatured_type_table ();
2546 for (offset_type i
= 0; i
< elements
; i
+= 3)
2548 struct signatured_type
*sig_type
;
2551 cu_offset type_offset_in_tu
;
2553 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2554 sect_offset sect_off
2555 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2557 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2559 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2562 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2563 sig_type
->signature
= signature
;
2564 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2565 sig_type
->per_cu
.is_debug_types
= 1;
2566 sig_type
->per_cu
.section
= section
;
2567 sig_type
->per_cu
.sect_off
= sect_off
;
2568 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2569 sig_type
->per_cu
.v
.quick
2570 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2571 struct dwarf2_per_cu_quick_data
);
2573 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2576 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2579 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2582 /* Create the signatured type hash table from .debug_names. */
2585 create_signatured_type_table_from_debug_names
2586 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2587 const mapped_debug_names
&map
,
2588 struct dwarf2_section_info
*section
,
2589 struct dwarf2_section_info
*abbrev_section
)
2591 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2593 section
->read (objfile
);
2594 abbrev_section
->read (objfile
);
2596 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2597 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2599 htab_up sig_types_hash
= allocate_signatured_type_table ();
2601 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2603 struct signatured_type
*sig_type
;
2606 sect_offset sect_off
2607 = (sect_offset
) (extract_unsigned_integer
2608 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2610 map
.dwarf5_byte_order
));
2612 comp_unit_head cu_header
;
2613 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2615 section
->buffer
+ to_underlying (sect_off
),
2618 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2619 sig_type
->signature
= cu_header
.signature
;
2620 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2621 sig_type
->per_cu
.is_debug_types
= 1;
2622 sig_type
->per_cu
.section
= section
;
2623 sig_type
->per_cu
.sect_off
= sect_off
;
2624 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2625 sig_type
->per_cu
.v
.quick
2626 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2627 struct dwarf2_per_cu_quick_data
);
2629 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2632 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2635 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2638 /* Read the address map data from the mapped index, and use it to
2639 populate the objfile's psymtabs_addrmap. */
2642 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2643 struct mapped_index
*index
)
2645 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2646 struct gdbarch
*gdbarch
= objfile
->arch ();
2647 const gdb_byte
*iter
, *end
;
2648 struct addrmap
*mutable_map
;
2651 auto_obstack temp_obstack
;
2653 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2655 iter
= index
->address_table
.data ();
2656 end
= iter
+ index
->address_table
.size ();
2658 baseaddr
= objfile
->text_section_offset ();
2662 ULONGEST hi
, lo
, cu_index
;
2663 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2665 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2667 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2672 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2673 hex_string (lo
), hex_string (hi
));
2677 if (cu_index
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
2679 complaint (_(".gdb_index address table has invalid CU number %u"),
2680 (unsigned) cu_index
);
2684 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2685 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2686 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2687 dwarf2_per_objfile
->per_bfd
->get_cu (cu_index
));
2690 objfile
->partial_symtabs
->psymtabs_addrmap
2691 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2694 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2695 populate the objfile's psymtabs_addrmap. */
2698 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2699 struct dwarf2_section_info
*section
)
2701 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2702 bfd
*abfd
= objfile
->obfd
;
2703 struct gdbarch
*gdbarch
= objfile
->arch ();
2704 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2706 auto_obstack temp_obstack
;
2707 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2709 std::unordered_map
<sect_offset
,
2710 dwarf2_per_cu_data
*,
2711 gdb::hash_enum
<sect_offset
>>
2712 debug_info_offset_to_per_cu
;
2713 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
2715 const auto insertpair
2716 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2717 if (!insertpair
.second
)
2719 warning (_("Section .debug_aranges in %s has duplicate "
2720 "debug_info_offset %s, ignoring .debug_aranges."),
2721 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2726 section
->read (objfile
);
2728 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2730 const gdb_byte
*addr
= section
->buffer
;
2732 while (addr
< section
->buffer
+ section
->size
)
2734 const gdb_byte
*const entry_addr
= addr
;
2735 unsigned int bytes_read
;
2737 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2741 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2742 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2743 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2744 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2746 warning (_("Section .debug_aranges in %s entry at offset %s "
2747 "length %s exceeds section length %s, "
2748 "ignoring .debug_aranges."),
2749 objfile_name (objfile
),
2750 plongest (entry_addr
- section
->buffer
),
2751 plongest (bytes_read
+ entry_length
),
2752 pulongest (section
->size
));
2756 /* The version number. */
2757 const uint16_t version
= read_2_bytes (abfd
, addr
);
2761 warning (_("Section .debug_aranges in %s entry at offset %s "
2762 "has unsupported version %d, ignoring .debug_aranges."),
2763 objfile_name (objfile
),
2764 plongest (entry_addr
- section
->buffer
), version
);
2768 const uint64_t debug_info_offset
2769 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2770 addr
+= offset_size
;
2771 const auto per_cu_it
2772 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2773 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2775 warning (_("Section .debug_aranges in %s entry at offset %s "
2776 "debug_info_offset %s does not exists, "
2777 "ignoring .debug_aranges."),
2778 objfile_name (objfile
),
2779 plongest (entry_addr
- section
->buffer
),
2780 pulongest (debug_info_offset
));
2783 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2785 const uint8_t address_size
= *addr
++;
2786 if (address_size
< 1 || address_size
> 8)
2788 warning (_("Section .debug_aranges in %s entry at offset %s "
2789 "address_size %u is invalid, ignoring .debug_aranges."),
2790 objfile_name (objfile
),
2791 plongest (entry_addr
- section
->buffer
), address_size
);
2795 const uint8_t segment_selector_size
= *addr
++;
2796 if (segment_selector_size
!= 0)
2798 warning (_("Section .debug_aranges in %s entry at offset %s "
2799 "segment_selector_size %u is not supported, "
2800 "ignoring .debug_aranges."),
2801 objfile_name (objfile
),
2802 plongest (entry_addr
- section
->buffer
),
2803 segment_selector_size
);
2807 /* Must pad to an alignment boundary that is twice the address
2808 size. It is undocumented by the DWARF standard but GCC does
2810 for (size_t padding
= ((-(addr
- section
->buffer
))
2811 & (2 * address_size
- 1));
2812 padding
> 0; padding
--)
2815 warning (_("Section .debug_aranges in %s entry at offset %s "
2816 "padding is not zero, ignoring .debug_aranges."),
2817 objfile_name (objfile
),
2818 plongest (entry_addr
- section
->buffer
));
2824 if (addr
+ 2 * address_size
> entry_end
)
2826 warning (_("Section .debug_aranges in %s entry at offset %s "
2827 "address list is not properly terminated, "
2828 "ignoring .debug_aranges."),
2829 objfile_name (objfile
),
2830 plongest (entry_addr
- section
->buffer
));
2833 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2835 addr
+= address_size
;
2836 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2838 addr
+= address_size
;
2839 if (start
== 0 && length
== 0)
2841 if (start
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
2843 /* Symbol was eliminated due to a COMDAT group. */
2846 ULONGEST end
= start
+ length
;
2847 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2849 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2851 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2855 objfile
->partial_symtabs
->psymtabs_addrmap
2856 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2859 /* Find a slot in the mapped index INDEX for the object named NAME.
2860 If NAME is found, set *VEC_OUT to point to the CU vector in the
2861 constant pool and return true. If NAME cannot be found, return
2865 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2866 offset_type
**vec_out
)
2869 offset_type slot
, step
;
2870 int (*cmp
) (const char *, const char *);
2872 gdb::unique_xmalloc_ptr
<char> without_params
;
2873 if (current_language
->la_language
== language_cplus
2874 || current_language
->la_language
== language_fortran
2875 || current_language
->la_language
== language_d
)
2877 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2880 if (strchr (name
, '(') != NULL
)
2882 without_params
= cp_remove_params (name
);
2884 if (without_params
!= NULL
)
2885 name
= without_params
.get ();
2889 /* Index version 4 did not support case insensitive searches. But the
2890 indices for case insensitive languages are built in lowercase, therefore
2891 simulate our NAME being searched is also lowercased. */
2892 hash
= mapped_index_string_hash ((index
->version
== 4
2893 && case_sensitivity
== case_sensitive_off
2894 ? 5 : index
->version
),
2897 slot
= hash
& (index
->symbol_table
.size () - 1);
2898 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2899 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2905 const auto &bucket
= index
->symbol_table
[slot
];
2906 if (bucket
.name
== 0 && bucket
.vec
== 0)
2909 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2910 if (!cmp (name
, str
))
2912 *vec_out
= (offset_type
*) (index
->constant_pool
2913 + MAYBE_SWAP (bucket
.vec
));
2917 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2921 /* A helper function that reads the .gdb_index from BUFFER and fills
2922 in MAP. FILENAME is the name of the file containing the data;
2923 it is used for error reporting. DEPRECATED_OK is true if it is
2924 ok to use deprecated sections.
2926 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2927 out parameters that are filled in with information about the CU and
2928 TU lists in the section.
2930 Returns true if all went well, false otherwise. */
2933 read_gdb_index_from_buffer (const char *filename
,
2935 gdb::array_view
<const gdb_byte
> buffer
,
2936 struct mapped_index
*map
,
2937 const gdb_byte
**cu_list
,
2938 offset_type
*cu_list_elements
,
2939 const gdb_byte
**types_list
,
2940 offset_type
*types_list_elements
)
2942 const gdb_byte
*addr
= &buffer
[0];
2944 /* Version check. */
2945 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2946 /* Versions earlier than 3 emitted every copy of a psymbol. This
2947 causes the index to behave very poorly for certain requests. Version 3
2948 contained incomplete addrmap. So, it seems better to just ignore such
2952 static int warning_printed
= 0;
2953 if (!warning_printed
)
2955 warning (_("Skipping obsolete .gdb_index section in %s."),
2957 warning_printed
= 1;
2961 /* Index version 4 uses a different hash function than index version
2964 Versions earlier than 6 did not emit psymbols for inlined
2965 functions. Using these files will cause GDB not to be able to
2966 set breakpoints on inlined functions by name, so we ignore these
2967 indices unless the user has done
2968 "set use-deprecated-index-sections on". */
2969 if (version
< 6 && !deprecated_ok
)
2971 static int warning_printed
= 0;
2972 if (!warning_printed
)
2975 Skipping deprecated .gdb_index section in %s.\n\
2976 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2977 to use the section anyway."),
2979 warning_printed
= 1;
2983 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2984 of the TU (for symbols coming from TUs),
2985 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2986 Plus gold-generated indices can have duplicate entries for global symbols,
2987 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2988 These are just performance bugs, and we can't distinguish gdb-generated
2989 indices from gold-generated ones, so issue no warning here. */
2991 /* Indexes with higher version than the one supported by GDB may be no
2992 longer backward compatible. */
2996 map
->version
= version
;
2998 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3001 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3002 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3006 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3007 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3008 - MAYBE_SWAP (metadata
[i
]))
3012 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3013 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3015 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3018 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3019 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3021 = gdb::array_view
<mapped_index::symbol_table_slot
>
3022 ((mapped_index::symbol_table_slot
*) symbol_table
,
3023 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3026 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3031 /* Callback types for dwarf2_read_gdb_index. */
3033 typedef gdb::function_view
3034 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3035 get_gdb_index_contents_ftype
;
3036 typedef gdb::function_view
3037 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3038 get_gdb_index_contents_dwz_ftype
;
3040 /* Read .gdb_index. If everything went ok, initialize the "quick"
3041 elements of all the CUs and return 1. Otherwise, return 0. */
3044 dwarf2_read_gdb_index
3045 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3046 get_gdb_index_contents_ftype get_gdb_index_contents
,
3047 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3049 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3050 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3051 struct dwz_file
*dwz
;
3052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3054 gdb::array_view
<const gdb_byte
> main_index_contents
3055 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
->per_bfd
);
3057 if (main_index_contents
.empty ())
3060 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3061 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3062 use_deprecated_index_sections
,
3063 main_index_contents
, map
.get (), &cu_list
,
3064 &cu_list_elements
, &types_list
,
3065 &types_list_elements
))
3068 /* Don't use the index if it's empty. */
3069 if (map
->symbol_table
.empty ())
3072 /* If there is a .dwz file, read it so we can get its CU list as
3074 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3077 struct mapped_index dwz_map
;
3078 const gdb_byte
*dwz_types_ignore
;
3079 offset_type dwz_types_elements_ignore
;
3081 gdb::array_view
<const gdb_byte
> dwz_index_content
3082 = get_gdb_index_contents_dwz (objfile
, dwz
);
3084 if (dwz_index_content
.empty ())
3087 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3088 1, dwz_index_content
, &dwz_map
,
3089 &dwz_list
, &dwz_list_elements
,
3091 &dwz_types_elements_ignore
))
3093 warning (_("could not read '.gdb_index' section from %s; skipping"),
3094 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3099 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3100 dwz_list
, dwz_list_elements
);
3102 if (types_list_elements
)
3104 /* We can only handle a single .debug_types when we have an
3106 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
3109 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
3111 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3112 types_list
, types_list_elements
);
3115 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3117 dwarf2_per_objfile
->per_bfd
->index_table
= std::move (map
);
3118 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
3119 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
3120 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
3125 /* die_reader_func for dw2_get_file_names. */
3128 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3129 const gdb_byte
*info_ptr
,
3130 struct die_info
*comp_unit_die
)
3132 struct dwarf2_cu
*cu
= reader
->cu
;
3133 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3134 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
3135 struct dwarf2_per_cu_data
*lh_cu
;
3136 struct attribute
*attr
;
3138 struct quick_file_names
*qfn
;
3140 gdb_assert (! this_cu
->is_debug_types
);
3142 /* Our callers never want to match partial units -- instead they
3143 will match the enclosing full CU. */
3144 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3146 this_cu
->v
.quick
->no_file_data
= 1;
3154 sect_offset line_offset
{};
3156 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3157 if (attr
!= nullptr)
3159 struct quick_file_names find_entry
;
3161 line_offset
= (sect_offset
) DW_UNSND (attr
);
3163 /* We may have already read in this line header (TU line header sharing).
3164 If we have we're done. */
3165 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3166 find_entry
.hash
.line_sect_off
= line_offset
;
3167 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3168 &find_entry
, INSERT
);
3171 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3175 lh
= dwarf_decode_line_header (line_offset
, cu
);
3179 lh_cu
->v
.quick
->no_file_data
= 1;
3183 qfn
= XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3184 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3185 qfn
->hash
.line_sect_off
= line_offset
;
3186 gdb_assert (slot
!= NULL
);
3189 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3192 if (strcmp (fnd
.name
, "<unknown>") != 0)
3195 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3197 XOBNEWVEC (&dwarf2_per_objfile
->per_bfd
->obstack
, const char *,
3198 qfn
->num_file_names
);
3200 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3201 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3202 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3203 fnd
.comp_dir
).release ();
3204 qfn
->real_names
= NULL
;
3206 lh_cu
->v
.quick
->file_names
= qfn
;
3209 /* A helper for the "quick" functions which attempts to read the line
3210 table for THIS_CU. */
3212 static struct quick_file_names
*
3213 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3215 /* This should never be called for TUs. */
3216 gdb_assert (! this_cu
->is_debug_types
);
3217 /* Nor type unit groups. */
3218 gdb_assert (! this_cu
->type_unit_group_p ());
3220 if (this_cu
->v
.quick
->file_names
!= NULL
)
3221 return this_cu
->v
.quick
->file_names
;
3222 /* If we know there is no line data, no point in looking again. */
3223 if (this_cu
->v
.quick
->no_file_data
)
3226 cutu_reader
reader (this_cu
);
3227 if (!reader
.dummy_p
)
3228 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3230 if (this_cu
->v
.quick
->no_file_data
)
3232 return this_cu
->v
.quick
->file_names
;
3235 /* A helper for the "quick" functions which computes and caches the
3236 real path for a given file name from the line table. */
3239 dw2_get_real_path (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3240 struct quick_file_names
*qfn
, int index
)
3242 if (qfn
->real_names
== NULL
)
3243 qfn
->real_names
= OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
3244 qfn
->num_file_names
, const char *);
3246 if (qfn
->real_names
[index
] == NULL
)
3247 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3249 return qfn
->real_names
[index
];
3252 static struct symtab
*
3253 dw2_find_last_source_symtab (struct objfile
*objfile
)
3255 struct dwarf2_per_objfile
*dwarf2_per_objfile
3256 = get_dwarf2_per_objfile (objfile
);
3257 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->per_bfd
->all_comp_units
.back ();
3258 compunit_symtab
*cust
3259 = dw2_instantiate_symtab (dwarf_cu
, dwarf2_per_objfile
, false);
3264 return compunit_primary_filetab (cust
);
3267 /* Traversal function for dw2_forget_cached_source_info. */
3270 dw2_free_cached_file_names (void **slot
, void *info
)
3272 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3274 if (file_data
->real_names
)
3278 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3280 xfree ((void*) file_data
->real_names
[i
]);
3281 file_data
->real_names
[i
] = NULL
;
3289 dw2_forget_cached_source_info (struct objfile
*objfile
)
3291 struct dwarf2_per_objfile
*dwarf2_per_objfile
3292 = get_dwarf2_per_objfile (objfile
);
3294 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3295 dw2_free_cached_file_names
, NULL
);
3298 /* Helper function for dw2_map_symtabs_matching_filename that expands
3299 the symtabs and calls the iterator. */
3302 dw2_map_expand_apply (struct objfile
*objfile
,
3303 struct dwarf2_per_cu_data
*per_cu
,
3304 const char *name
, const char *real_path
,
3305 gdb::function_view
<bool (symtab
*)> callback
)
3307 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3309 /* Don't visit already-expanded CUs. */
3310 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3311 if (per_objfile
->symtab_set_p (per_cu
))
3314 /* This may expand more than one symtab, and we want to iterate over
3316 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3318 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3319 last_made
, callback
);
3322 /* Implementation of the map_symtabs_matching_filename method. */
3325 dw2_map_symtabs_matching_filename
3326 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3327 gdb::function_view
<bool (symtab
*)> callback
)
3329 const char *name_basename
= lbasename (name
);
3330 struct dwarf2_per_objfile
*dwarf2_per_objfile
3331 = get_dwarf2_per_objfile (objfile
);
3333 /* The rule is CUs specify all the files, including those used by
3334 any TU, so there's no need to scan TUs here. */
3336 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3338 /* We only need to look at symtabs not already expanded. */
3339 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3342 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3343 if (file_data
== NULL
)
3346 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3348 const char *this_name
= file_data
->file_names
[j
];
3349 const char *this_real_name
;
3351 if (compare_filenames_for_search (this_name
, name
))
3353 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3359 /* Before we invoke realpath, which can get expensive when many
3360 files are involved, do a quick comparison of the basenames. */
3361 if (! basenames_may_differ
3362 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3365 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
3367 if (compare_filenames_for_search (this_real_name
, name
))
3369 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3375 if (real_path
!= NULL
)
3377 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3378 gdb_assert (IS_ABSOLUTE_PATH (name
));
3379 if (this_real_name
!= NULL
3380 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3382 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3394 /* Struct used to manage iterating over all CUs looking for a symbol. */
3396 struct dw2_symtab_iterator
3398 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3399 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3400 /* If set, only look for symbols that match that block. Valid values are
3401 GLOBAL_BLOCK and STATIC_BLOCK. */
3402 gdb::optional
<block_enum
> block_index
;
3403 /* The kind of symbol we're looking for. */
3405 /* The list of CUs from the index entry of the symbol,
3406 or NULL if not found. */
3408 /* The next element in VEC to look at. */
3410 /* The number of elements in VEC, or zero if there is no match. */
3412 /* Have we seen a global version of the symbol?
3413 If so we can ignore all further global instances.
3414 This is to work around gold/15646, inefficient gold-generated
3419 /* Initialize the index symtab iterator ITER. */
3422 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3423 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3424 gdb::optional
<block_enum
> block_index
,
3428 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3429 iter
->block_index
= block_index
;
3430 iter
->domain
= domain
;
3432 iter
->global_seen
= 0;
3434 mapped_index
*index
= dwarf2_per_objfile
->per_bfd
->index_table
.get ();
3436 /* index is NULL if OBJF_READNOW. */
3437 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3438 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3446 /* Return the next matching CU or NULL if there are no more. */
3448 static struct dwarf2_per_cu_data
*
3449 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3451 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3453 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3455 offset_type cu_index_and_attrs
=
3456 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3457 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3458 gdb_index_symbol_kind symbol_kind
=
3459 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3460 /* Only check the symbol attributes if they're present.
3461 Indices prior to version 7 don't record them,
3462 and indices >= 7 may elide them for certain symbols
3463 (gold does this). */
3465 (dwarf2_per_objfile
->per_bfd
->index_table
->version
>= 7
3466 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3468 /* Don't crash on bad data. */
3469 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3470 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
3472 complaint (_(".gdb_index entry has bad CU index"
3474 objfile_name (dwarf2_per_objfile
->objfile
));
3478 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
3480 /* Skip if already read in. */
3481 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3484 /* Check static vs global. */
3487 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3489 if (iter
->block_index
.has_value ())
3491 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3493 if (is_static
!= want_static
)
3497 /* Work around gold/15646. */
3498 if (!is_static
&& iter
->global_seen
)
3501 iter
->global_seen
= 1;
3504 /* Only check the symbol's kind if it has one. */
3507 switch (iter
->domain
)
3510 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3511 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3512 /* Some types are also in VAR_DOMAIN. */
3513 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3517 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3521 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3525 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3540 static struct compunit_symtab
*
3541 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3542 const char *name
, domain_enum domain
)
3544 struct compunit_symtab
*stab_best
= NULL
;
3545 struct dwarf2_per_objfile
*dwarf2_per_objfile
3546 = get_dwarf2_per_objfile (objfile
);
3548 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3550 struct dw2_symtab_iterator iter
;
3551 struct dwarf2_per_cu_data
*per_cu
;
3553 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3555 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3557 struct symbol
*sym
, *with_opaque
= NULL
;
3558 struct compunit_symtab
*stab
3559 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3560 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3561 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3563 sym
= block_find_symbol (block
, name
, domain
,
3564 block_find_non_opaque_type_preferred
,
3567 /* Some caution must be observed with overloaded functions
3568 and methods, since the index will not contain any overload
3569 information (but NAME might contain it). */
3572 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3574 if (with_opaque
!= NULL
3575 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3578 /* Keep looking through other CUs. */
3585 dw2_print_stats (struct objfile
*objfile
)
3587 struct dwarf2_per_objfile
*dwarf2_per_objfile
3588 = get_dwarf2_per_objfile (objfile
);
3589 int total
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3590 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3593 for (int i
= 0; i
< total
; ++i
)
3595 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3597 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
3600 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3601 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3604 /* This dumps minimal information about the index.
3605 It is called via "mt print objfiles".
3606 One use is to verify .gdb_index has been loaded by the
3607 gdb.dwarf2/gdb-index.exp testcase. */
3610 dw2_dump (struct objfile
*objfile
)
3612 struct dwarf2_per_objfile
*dwarf2_per_objfile
3613 = get_dwarf2_per_objfile (objfile
);
3615 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
3616 printf_filtered (".gdb_index:");
3617 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
)
3619 printf_filtered (" version %d\n",
3620 dwarf2_per_objfile
->per_bfd
->index_table
->version
);
3623 printf_filtered (" faked for \"readnow\"\n");
3624 printf_filtered ("\n");
3628 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3629 const char *func_name
)
3631 struct dwarf2_per_objfile
*dwarf2_per_objfile
3632 = get_dwarf2_per_objfile (objfile
);
3634 struct dw2_symtab_iterator iter
;
3635 struct dwarf2_per_cu_data
*per_cu
;
3637 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3639 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3640 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3645 dw2_expand_all_symtabs (struct objfile
*objfile
)
3647 struct dwarf2_per_objfile
*dwarf2_per_objfile
3648 = get_dwarf2_per_objfile (objfile
);
3649 int total_units
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3650 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3652 for (int i
= 0; i
< total_units
; ++i
)
3654 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3656 /* We don't want to directly expand a partial CU, because if we
3657 read it with the wrong language, then assertion failures can
3658 be triggered later on. See PR symtab/23010. So, tell
3659 dw2_instantiate_symtab to skip partial CUs -- any important
3660 partial CU will be read via DW_TAG_imported_unit anyway. */
3661 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, true);
3666 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3667 const char *fullname
)
3669 struct dwarf2_per_objfile
*dwarf2_per_objfile
3670 = get_dwarf2_per_objfile (objfile
);
3672 /* We don't need to consider type units here.
3673 This is only called for examining code, e.g. expand_line_sal.
3674 There can be an order of magnitude (or more) more type units
3675 than comp units, and we avoid them if we can. */
3677 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3679 /* We only need to look at symtabs not already expanded. */
3680 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3683 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3684 if (file_data
== NULL
)
3687 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3689 const char *this_fullname
= file_data
->file_names
[j
];
3691 if (filename_cmp (this_fullname
, fullname
) == 0)
3693 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3701 dw2_expand_symtabs_matching_symbol
3702 (mapped_index_base
&index
,
3703 const lookup_name_info
&lookup_name_in
,
3704 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3705 enum search_domain kind
,
3706 gdb::function_view
<bool (offset_type
)> match_callback
);
3709 dw2_expand_symtabs_matching_one
3710 (dwarf2_per_cu_data
*per_cu
,
3711 dwarf2_per_objfile
*per_objfile
,
3712 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3713 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3716 dw2_map_matching_symbols
3717 (struct objfile
*objfile
,
3718 const lookup_name_info
&name
, domain_enum domain
,
3720 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3721 symbol_compare_ftype
*ordered_compare
)
3724 struct dwarf2_per_objfile
*dwarf2_per_objfile
3725 = get_dwarf2_per_objfile (objfile
);
3727 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3729 if (dwarf2_per_objfile
->per_bfd
->index_table
!= nullptr)
3731 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3732 here though if the current language is Ada for a non-Ada objfile
3734 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
3736 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3737 auto matcher
= [&] (const char *symname
)
3739 if (ordered_compare
== nullptr)
3741 return ordered_compare (symname
, match_name
) == 0;
3744 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3745 [&] (offset_type namei
)
3747 struct dw2_symtab_iterator iter
;
3748 struct dwarf2_per_cu_data
*per_cu
;
3750 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_kind
, domain
,
3752 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3753 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
3760 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3761 proceed assuming all symtabs have been read in. */
3764 for (compunit_symtab
*cust
: objfile
->compunits ())
3766 const struct block
*block
;
3770 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3771 if (!iterate_over_symbols_terminated (block
, name
,
3777 /* Starting from a search name, return the string that finds the upper
3778 bound of all strings that start with SEARCH_NAME in a sorted name
3779 list. Returns the empty string to indicate that the upper bound is
3780 the end of the list. */
3783 make_sort_after_prefix_name (const char *search_name
)
3785 /* When looking to complete "func", we find the upper bound of all
3786 symbols that start with "func" by looking for where we'd insert
3787 the closest string that would follow "func" in lexicographical
3788 order. Usually, that's "func"-with-last-character-incremented,
3789 i.e. "fund". Mind non-ASCII characters, though. Usually those
3790 will be UTF-8 multi-byte sequences, but we can't be certain.
3791 Especially mind the 0xff character, which is a valid character in
3792 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3793 rule out compilers allowing it in identifiers. Note that
3794 conveniently, strcmp/strcasecmp are specified to compare
3795 characters interpreted as unsigned char. So what we do is treat
3796 the whole string as a base 256 number composed of a sequence of
3797 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3798 to 0, and carries 1 to the following more-significant position.
3799 If the very first character in SEARCH_NAME ends up incremented
3800 and carries/overflows, then the upper bound is the end of the
3801 list. The string after the empty string is also the empty
3804 Some examples of this operation:
3806 SEARCH_NAME => "+1" RESULT
3810 "\xff" "a" "\xff" => "\xff" "b"
3815 Then, with these symbols for example:
3821 completing "func" looks for symbols between "func" and
3822 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3823 which finds "func" and "func1", but not "fund".
3827 funcÿ (Latin1 'ÿ' [0xff])
3831 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3832 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3836 ÿÿ (Latin1 'ÿ' [0xff])
3839 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3840 the end of the list.
3842 std::string after
= search_name
;
3843 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3845 if (!after
.empty ())
3846 after
.back () = (unsigned char) after
.back () + 1;
3850 /* See declaration. */
3852 std::pair
<std::vector
<name_component
>::const_iterator
,
3853 std::vector
<name_component
>::const_iterator
>
3854 mapped_index_base::find_name_components_bounds
3855 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3858 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3860 const char *lang_name
3861 = lookup_name_without_params
.language_lookup_name (lang
);
3863 /* Comparison function object for lower_bound that matches against a
3864 given symbol name. */
3865 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3868 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3869 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3870 return name_cmp (elem_name
, name
) < 0;
3873 /* Comparison function object for upper_bound that matches against a
3874 given symbol name. */
3875 auto lookup_compare_upper
= [&] (const char *name
,
3876 const name_component
&elem
)
3878 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3879 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3880 return name_cmp (name
, elem_name
) < 0;
3883 auto begin
= this->name_components
.begin ();
3884 auto end
= this->name_components
.end ();
3886 /* Find the lower bound. */
3889 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3892 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3895 /* Find the upper bound. */
3898 if (lookup_name_without_params
.completion_mode ())
3900 /* In completion mode, we want UPPER to point past all
3901 symbols names that have the same prefix. I.e., with
3902 these symbols, and completing "func":
3904 function << lower bound
3906 other_function << upper bound
3908 We find the upper bound by looking for the insertion
3909 point of "func"-with-last-character-incremented,
3911 std::string after
= make_sort_after_prefix_name (lang_name
);
3914 return std::lower_bound (lower
, end
, after
.c_str (),
3915 lookup_compare_lower
);
3918 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3921 return {lower
, upper
};
3924 /* See declaration. */
3927 mapped_index_base::build_name_components ()
3929 if (!this->name_components
.empty ())
3932 this->name_components_casing
= case_sensitivity
;
3934 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3936 /* The code below only knows how to break apart components of C++
3937 symbol names (and other languages that use '::' as
3938 namespace/module separator) and Ada symbol names. */
3939 auto count
= this->symbol_name_count ();
3940 for (offset_type idx
= 0; idx
< count
; idx
++)
3942 if (this->symbol_name_slot_invalid (idx
))
3945 const char *name
= this->symbol_name_at (idx
);
3947 /* Add each name component to the name component table. */
3948 unsigned int previous_len
= 0;
3950 if (strstr (name
, "::") != nullptr)
3952 for (unsigned int current_len
= cp_find_first_component (name
);
3953 name
[current_len
] != '\0';
3954 current_len
+= cp_find_first_component (name
+ current_len
))
3956 gdb_assert (name
[current_len
] == ':');
3957 this->name_components
.push_back ({previous_len
, idx
});
3958 /* Skip the '::'. */
3960 previous_len
= current_len
;
3965 /* Handle the Ada encoded (aka mangled) form here. */
3966 for (const char *iter
= strstr (name
, "__");
3968 iter
= strstr (iter
, "__"))
3970 this->name_components
.push_back ({previous_len
, idx
});
3972 previous_len
= iter
- name
;
3976 this->name_components
.push_back ({previous_len
, idx
});
3979 /* Sort name_components elements by name. */
3980 auto name_comp_compare
= [&] (const name_component
&left
,
3981 const name_component
&right
)
3983 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3984 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3986 const char *left_name
= left_qualified
+ left
.name_offset
;
3987 const char *right_name
= right_qualified
+ right
.name_offset
;
3989 return name_cmp (left_name
, right_name
) < 0;
3992 std::sort (this->name_components
.begin (),
3993 this->name_components
.end (),
3997 /* Helper for dw2_expand_symtabs_matching that works with a
3998 mapped_index_base instead of the containing objfile. This is split
3999 to a separate function in order to be able to unit test the
4000 name_components matching using a mock mapped_index_base. For each
4001 symbol name that matches, calls MATCH_CALLBACK, passing it the
4002 symbol's index in the mapped_index_base symbol table. */
4005 dw2_expand_symtabs_matching_symbol
4006 (mapped_index_base
&index
,
4007 const lookup_name_info
&lookup_name_in
,
4008 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4009 enum search_domain kind
,
4010 gdb::function_view
<bool (offset_type
)> match_callback
)
4012 lookup_name_info lookup_name_without_params
4013 = lookup_name_in
.make_ignore_params ();
4015 /* Build the symbol name component sorted vector, if we haven't
4017 index
.build_name_components ();
4019 /* The same symbol may appear more than once in the range though.
4020 E.g., if we're looking for symbols that complete "w", and we have
4021 a symbol named "w1::w2", we'll find the two name components for
4022 that same symbol in the range. To be sure we only call the
4023 callback once per symbol, we first collect the symbol name
4024 indexes that matched in a temporary vector and ignore
4026 std::vector
<offset_type
> matches
;
4028 struct name_and_matcher
4030 symbol_name_matcher_ftype
*matcher
;
4033 bool operator== (const name_and_matcher
&other
) const
4035 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4039 /* A vector holding all the different symbol name matchers, for all
4041 std::vector
<name_and_matcher
> matchers
;
4043 for (int i
= 0; i
< nr_languages
; i
++)
4045 enum language lang_e
= (enum language
) i
;
4047 const language_defn
*lang
= language_def (lang_e
);
4048 symbol_name_matcher_ftype
*name_matcher
4049 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4051 name_and_matcher key
{
4053 lookup_name_without_params
.language_lookup_name (lang_e
)
4056 /* Don't insert the same comparison routine more than once.
4057 Note that we do this linear walk. This is not a problem in
4058 practice because the number of supported languages is
4060 if (std::find (matchers
.begin (), matchers
.end (), key
)
4063 matchers
.push_back (std::move (key
));
4066 = index
.find_name_components_bounds (lookup_name_without_params
,
4069 /* Now for each symbol name in range, check to see if we have a name
4070 match, and if so, call the MATCH_CALLBACK callback. */
4072 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4074 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4076 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4077 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4080 matches
.push_back (bounds
.first
->idx
);
4084 std::sort (matches
.begin (), matches
.end ());
4086 /* Finally call the callback, once per match. */
4088 for (offset_type idx
: matches
)
4092 if (!match_callback (idx
))
4098 /* Above we use a type wider than idx's for 'prev', since 0 and
4099 (offset_type)-1 are both possible values. */
4100 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4105 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4107 /* A mock .gdb_index/.debug_names-like name index table, enough to
4108 exercise dw2_expand_symtabs_matching_symbol, which works with the
4109 mapped_index_base interface. Builds an index from the symbol list
4110 passed as parameter to the constructor. */
4111 class mock_mapped_index
: public mapped_index_base
4114 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4115 : m_symbol_table (symbols
)
4118 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4120 /* Return the number of names in the symbol table. */
4121 size_t symbol_name_count () const override
4123 return m_symbol_table
.size ();
4126 /* Get the name of the symbol at IDX in the symbol table. */
4127 const char *symbol_name_at (offset_type idx
) const override
4129 return m_symbol_table
[idx
];
4133 gdb::array_view
<const char *> m_symbol_table
;
4136 /* Convenience function that converts a NULL pointer to a "<null>"
4137 string, to pass to print routines. */
4140 string_or_null (const char *str
)
4142 return str
!= NULL
? str
: "<null>";
4145 /* Check if a lookup_name_info built from
4146 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4147 index. EXPECTED_LIST is the list of expected matches, in expected
4148 matching order. If no match expected, then an empty list is
4149 specified. Returns true on success. On failure prints a warning
4150 indicating the file:line that failed, and returns false. */
4153 check_match (const char *file
, int line
,
4154 mock_mapped_index
&mock_index
,
4155 const char *name
, symbol_name_match_type match_type
,
4156 bool completion_mode
,
4157 std::initializer_list
<const char *> expected_list
)
4159 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4161 bool matched
= true;
4163 auto mismatch
= [&] (const char *expected_str
,
4166 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4167 "expected=\"%s\", got=\"%s\"\n"),
4169 (match_type
== symbol_name_match_type::FULL
4171 name
, string_or_null (expected_str
), string_or_null (got
));
4175 auto expected_it
= expected_list
.begin ();
4176 auto expected_end
= expected_list
.end ();
4178 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4180 [&] (offset_type idx
)
4182 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4183 const char *expected_str
4184 = expected_it
== expected_end
? NULL
: *expected_it
++;
4186 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4187 mismatch (expected_str
, matched_name
);
4191 const char *expected_str
4192 = expected_it
== expected_end
? NULL
: *expected_it
++;
4193 if (expected_str
!= NULL
)
4194 mismatch (expected_str
, NULL
);
4199 /* The symbols added to the mock mapped_index for testing (in
4201 static const char *test_symbols
[] = {
4210 "ns2::tmpl<int>::foo2",
4211 "(anonymous namespace)::A::B::C",
4213 /* These are used to check that the increment-last-char in the
4214 matching algorithm for completion doesn't match "t1_fund" when
4215 completing "t1_func". */
4221 /* A UTF-8 name with multi-byte sequences to make sure that
4222 cp-name-parser understands this as a single identifier ("função"
4223 is "function" in PT). */
4226 /* \377 (0xff) is Latin1 'ÿ'. */
4229 /* \377 (0xff) is Latin1 'ÿ'. */
4233 /* A name with all sorts of complications. Starts with "z" to make
4234 it easier for the completion tests below. */
4235 #define Z_SYM_NAME \
4236 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4237 "::tuple<(anonymous namespace)::ui*, " \
4238 "std::default_delete<(anonymous namespace)::ui>, void>"
4243 /* Returns true if the mapped_index_base::find_name_component_bounds
4244 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4245 in completion mode. */
4248 check_find_bounds_finds (mapped_index_base
&index
,
4249 const char *search_name
,
4250 gdb::array_view
<const char *> expected_syms
)
4252 lookup_name_info
lookup_name (search_name
,
4253 symbol_name_match_type::FULL
, true);
4255 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4258 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4259 if (distance
!= expected_syms
.size ())
4262 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4264 auto nc_elem
= bounds
.first
+ exp_elem
;
4265 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4266 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4273 /* Test the lower-level mapped_index::find_name_component_bounds
4277 test_mapped_index_find_name_component_bounds ()
4279 mock_mapped_index
mock_index (test_symbols
);
4281 mock_index
.build_name_components ();
4283 /* Test the lower-level mapped_index::find_name_component_bounds
4284 method in completion mode. */
4286 static const char *expected_syms
[] = {
4291 SELF_CHECK (check_find_bounds_finds (mock_index
,
4292 "t1_func", expected_syms
));
4295 /* Check that the increment-last-char in the name matching algorithm
4296 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4298 static const char *expected_syms1
[] = {
4302 SELF_CHECK (check_find_bounds_finds (mock_index
,
4303 "\377", expected_syms1
));
4305 static const char *expected_syms2
[] = {
4308 SELF_CHECK (check_find_bounds_finds (mock_index
,
4309 "\377\377", expected_syms2
));
4313 /* Test dw2_expand_symtabs_matching_symbol. */
4316 test_dw2_expand_symtabs_matching_symbol ()
4318 mock_mapped_index
mock_index (test_symbols
);
4320 /* We let all tests run until the end even if some fails, for debug
4322 bool any_mismatch
= false;
4324 /* Create the expected symbols list (an initializer_list). Needed
4325 because lists have commas, and we need to pass them to CHECK,
4326 which is a macro. */
4327 #define EXPECT(...) { __VA_ARGS__ }
4329 /* Wrapper for check_match that passes down the current
4330 __FILE__/__LINE__. */
4331 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4332 any_mismatch |= !check_match (__FILE__, __LINE__, \
4334 NAME, MATCH_TYPE, COMPLETION_MODE, \
4337 /* Identity checks. */
4338 for (const char *sym
: test_symbols
)
4340 /* Should be able to match all existing symbols. */
4341 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4344 /* Should be able to match all existing symbols with
4346 std::string with_params
= std::string (sym
) + "(int)";
4347 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4350 /* Should be able to match all existing symbols with
4351 parameters and qualifiers. */
4352 with_params
= std::string (sym
) + " ( int ) const";
4353 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4356 /* This should really find sym, but cp-name-parser.y doesn't
4357 know about lvalue/rvalue qualifiers yet. */
4358 with_params
= std::string (sym
) + " ( int ) &&";
4359 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4363 /* Check that the name matching algorithm for completion doesn't get
4364 confused with Latin1 'ÿ' / 0xff. */
4366 static const char str
[] = "\377";
4367 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4368 EXPECT ("\377", "\377\377123"));
4371 /* Check that the increment-last-char in the matching algorithm for
4372 completion doesn't match "t1_fund" when completing "t1_func". */
4374 static const char str
[] = "t1_func";
4375 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4376 EXPECT ("t1_func", "t1_func1"));
4379 /* Check that completion mode works at each prefix of the expected
4382 static const char str
[] = "function(int)";
4383 size_t len
= strlen (str
);
4386 for (size_t i
= 1; i
< len
; i
++)
4388 lookup
.assign (str
, i
);
4389 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4390 EXPECT ("function"));
4394 /* While "w" is a prefix of both components, the match function
4395 should still only be called once. */
4397 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4399 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4403 /* Same, with a "complicated" symbol. */
4405 static const char str
[] = Z_SYM_NAME
;
4406 size_t len
= strlen (str
);
4409 for (size_t i
= 1; i
< len
; i
++)
4411 lookup
.assign (str
, i
);
4412 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4413 EXPECT (Z_SYM_NAME
));
4417 /* In FULL mode, an incomplete symbol doesn't match. */
4419 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4423 /* A complete symbol with parameters matches any overload, since the
4424 index has no overload info. */
4426 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4427 EXPECT ("std::zfunction", "std::zfunction2"));
4428 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4429 EXPECT ("std::zfunction", "std::zfunction2"));
4430 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4431 EXPECT ("std::zfunction", "std::zfunction2"));
4434 /* Check that whitespace is ignored appropriately. A symbol with a
4435 template argument list. */
4437 static const char expected
[] = "ns::foo<int>";
4438 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4440 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4444 /* Check that whitespace is ignored appropriately. A symbol with a
4445 template argument list that includes a pointer. */
4447 static const char expected
[] = "ns::foo<char*>";
4448 /* Try both completion and non-completion modes. */
4449 static const bool completion_mode
[2] = {false, true};
4450 for (size_t i
= 0; i
< 2; i
++)
4452 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4453 completion_mode
[i
], EXPECT (expected
));
4454 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4455 completion_mode
[i
], EXPECT (expected
));
4457 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4458 completion_mode
[i
], EXPECT (expected
));
4459 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4460 completion_mode
[i
], EXPECT (expected
));
4465 /* Check method qualifiers are ignored. */
4466 static const char expected
[] = "ns::foo<char*>";
4467 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4468 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4469 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4470 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4471 CHECK_MATCH ("foo < char * > ( int ) const",
4472 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4473 CHECK_MATCH ("foo < char * > ( int ) &&",
4474 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4477 /* Test lookup names that don't match anything. */
4479 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4482 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4486 /* Some wild matching tests, exercising "(anonymous namespace)",
4487 which should not be confused with a parameter list. */
4489 static const char *syms
[] = {
4493 "A :: B :: C ( int )",
4498 for (const char *s
: syms
)
4500 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4501 EXPECT ("(anonymous namespace)::A::B::C"));
4506 static const char expected
[] = "ns2::tmpl<int>::foo2";
4507 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4509 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4513 SELF_CHECK (!any_mismatch
);
4522 test_mapped_index_find_name_component_bounds ();
4523 test_dw2_expand_symtabs_matching_symbol ();
4526 }} // namespace selftests::dw2_expand_symtabs_matching
4528 #endif /* GDB_SELF_TEST */
4530 /* If FILE_MATCHER is NULL or if PER_CU has
4531 dwarf2_per_cu_quick_data::MARK set (see
4532 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4533 EXPANSION_NOTIFY on it. */
4536 dw2_expand_symtabs_matching_one
4537 (dwarf2_per_cu_data
*per_cu
,
4538 dwarf2_per_objfile
*per_objfile
,
4539 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4540 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4542 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4544 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4546 compunit_symtab
*symtab
4547 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4548 gdb_assert (symtab
!= nullptr);
4550 if (expansion_notify
!= NULL
&& symtab_was_null
)
4551 expansion_notify (symtab
);
4555 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4556 matched, to expand corresponding CUs that were marked. IDX is the
4557 index of the symbol name that matched. */
4560 dw2_expand_marked_cus
4561 (dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4562 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4563 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4566 offset_type
*vec
, vec_len
, vec_idx
;
4567 bool global_seen
= false;
4568 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4570 vec
= (offset_type
*) (index
.constant_pool
4571 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4572 vec_len
= MAYBE_SWAP (vec
[0]);
4573 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4575 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4576 /* This value is only valid for index versions >= 7. */
4577 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4578 gdb_index_symbol_kind symbol_kind
=
4579 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4580 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4581 /* Only check the symbol attributes if they're present.
4582 Indices prior to version 7 don't record them,
4583 and indices >= 7 may elide them for certain symbols
4584 (gold does this). */
4587 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4589 /* Work around gold/15646. */
4592 if (!is_static
&& global_seen
)
4598 /* Only check the symbol's kind if it has one. */
4603 case VARIABLES_DOMAIN
:
4604 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4607 case FUNCTIONS_DOMAIN
:
4608 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4612 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4615 case MODULES_DOMAIN
:
4616 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4624 /* Don't crash on bad data. */
4625 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
4626 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
4628 complaint (_(".gdb_index entry has bad CU index"
4630 objfile_name (dwarf2_per_objfile
->objfile
));
4634 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
4635 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, file_matcher
,
4640 /* If FILE_MATCHER is non-NULL, set all the
4641 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4642 that match FILE_MATCHER. */
4645 dw_expand_symtabs_matching_file_matcher
4646 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4647 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4649 if (file_matcher
== NULL
)
4652 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4654 NULL
, xcalloc
, xfree
));
4655 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4657 NULL
, xcalloc
, xfree
));
4659 /* The rule is CUs specify all the files, including those used by
4660 any TU, so there's no need to scan TUs here. */
4662 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4666 per_cu
->v
.quick
->mark
= 0;
4668 /* We only need to look at symtabs not already expanded. */
4669 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4672 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4673 if (file_data
== NULL
)
4676 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4678 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4680 per_cu
->v
.quick
->mark
= 1;
4684 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4686 const char *this_real_name
;
4688 if (file_matcher (file_data
->file_names
[j
], false))
4690 per_cu
->v
.quick
->mark
= 1;
4694 /* Before we invoke realpath, which can get expensive when many
4695 files are involved, do a quick comparison of the basenames. */
4696 if (!basenames_may_differ
4697 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4701 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
4703 if (file_matcher (this_real_name
, false))
4705 per_cu
->v
.quick
->mark
= 1;
4710 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4711 ? visited_found
.get ()
4712 : visited_not_found
.get (),
4719 dw2_expand_symtabs_matching
4720 (struct objfile
*objfile
,
4721 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4722 const lookup_name_info
*lookup_name
,
4723 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4724 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4725 enum search_domain kind
)
4727 struct dwarf2_per_objfile
*dwarf2_per_objfile
4728 = get_dwarf2_per_objfile (objfile
);
4730 /* index_table is NULL if OBJF_READNOW. */
4731 if (!dwarf2_per_objfile
->per_bfd
->index_table
)
4734 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4736 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4738 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4742 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
4743 file_matcher
, expansion_notify
);
4748 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4750 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4752 kind
, [&] (offset_type idx
)
4754 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4755 expansion_notify
, kind
);
4760 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4763 static struct compunit_symtab
*
4764 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4769 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4770 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4773 if (cust
->includes
== NULL
)
4776 for (i
= 0; cust
->includes
[i
]; ++i
)
4778 struct compunit_symtab
*s
= cust
->includes
[i
];
4780 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4788 static struct compunit_symtab
*
4789 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4790 struct bound_minimal_symbol msymbol
,
4792 struct obj_section
*section
,
4795 struct dwarf2_per_cu_data
*data
;
4796 struct compunit_symtab
*result
;
4798 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4801 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4802 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4803 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4807 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4808 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4809 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4810 paddress (objfile
->arch (), pc
));
4812 result
= recursively_find_pc_sect_compunit_symtab
4813 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4815 gdb_assert (result
!= NULL
);
4820 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4821 void *data
, int need_fullname
)
4823 struct dwarf2_per_objfile
*dwarf2_per_objfile
4824 = get_dwarf2_per_objfile (objfile
);
4826 if (!dwarf2_per_objfile
->per_bfd
->filenames_cache
)
4828 dwarf2_per_objfile
->per_bfd
->filenames_cache
.emplace ();
4830 htab_up
visited (htab_create_alloc (10,
4831 htab_hash_pointer
, htab_eq_pointer
,
4832 NULL
, xcalloc
, xfree
));
4834 /* The rule is CUs specify all the files, including those used
4835 by any TU, so there's no need to scan TUs here. We can
4836 ignore file names coming from already-expanded CUs. */
4838 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4840 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4842 void **slot
= htab_find_slot (visited
.get (),
4843 per_cu
->v
.quick
->file_names
,
4846 *slot
= per_cu
->v
.quick
->file_names
;
4850 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4852 /* We only need to look at symtabs not already expanded. */
4853 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4856 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4857 if (file_data
== NULL
)
4860 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4863 /* Already visited. */
4868 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4870 const char *filename
= file_data
->file_names
[j
];
4871 dwarf2_per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4876 dwarf2_per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4878 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4881 this_real_name
= gdb_realpath (filename
);
4882 (*fun
) (filename
, this_real_name
.get (), data
);
4887 dw2_has_symbols (struct objfile
*objfile
)
4892 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4895 dw2_find_last_source_symtab
,
4896 dw2_forget_cached_source_info
,
4897 dw2_map_symtabs_matching_filename
,
4902 dw2_expand_symtabs_for_function
,
4903 dw2_expand_all_symtabs
,
4904 dw2_expand_symtabs_with_fullname
,
4905 dw2_map_matching_symbols
,
4906 dw2_expand_symtabs_matching
,
4907 dw2_find_pc_sect_compunit_symtab
,
4909 dw2_map_symbol_filenames
4912 /* DWARF-5 debug_names reader. */
4914 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4915 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4917 /* A helper function that reads the .debug_names section in SECTION
4918 and fills in MAP. FILENAME is the name of the file containing the
4919 section; it is used for error reporting.
4921 Returns true if all went well, false otherwise. */
4924 read_debug_names_from_section (struct objfile
*objfile
,
4925 const char *filename
,
4926 struct dwarf2_section_info
*section
,
4927 mapped_debug_names
&map
)
4929 if (section
->empty ())
4932 /* Older elfutils strip versions could keep the section in the main
4933 executable while splitting it for the separate debug info file. */
4934 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4937 section
->read (objfile
);
4939 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4941 const gdb_byte
*addr
= section
->buffer
;
4943 bfd
*const abfd
= section
->get_bfd_owner ();
4945 unsigned int bytes_read
;
4946 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4949 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4950 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4951 if (bytes_read
+ length
!= section
->size
)
4953 /* There may be multiple per-CU indices. */
4954 warning (_("Section .debug_names in %s length %s does not match "
4955 "section length %s, ignoring .debug_names."),
4956 filename
, plongest (bytes_read
+ length
),
4957 pulongest (section
->size
));
4961 /* The version number. */
4962 uint16_t version
= read_2_bytes (abfd
, addr
);
4966 warning (_("Section .debug_names in %s has unsupported version %d, "
4967 "ignoring .debug_names."),
4973 uint16_t padding
= read_2_bytes (abfd
, addr
);
4977 warning (_("Section .debug_names in %s has unsupported padding %d, "
4978 "ignoring .debug_names."),
4983 /* comp_unit_count - The number of CUs in the CU list. */
4984 map
.cu_count
= read_4_bytes (abfd
, addr
);
4987 /* local_type_unit_count - The number of TUs in the local TU
4989 map
.tu_count
= read_4_bytes (abfd
, addr
);
4992 /* foreign_type_unit_count - The number of TUs in the foreign TU
4994 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4996 if (foreign_tu_count
!= 0)
4998 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4999 "ignoring .debug_names."),
5000 filename
, static_cast<unsigned long> (foreign_tu_count
));
5004 /* bucket_count - The number of hash buckets in the hash lookup
5006 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5009 /* name_count - The number of unique names in the index. */
5010 map
.name_count
= read_4_bytes (abfd
, addr
);
5013 /* abbrev_table_size - The size in bytes of the abbreviations
5015 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5018 /* augmentation_string_size - The size in bytes of the augmentation
5019 string. This value is rounded up to a multiple of 4. */
5020 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5022 map
.augmentation_is_gdb
= ((augmentation_string_size
5023 == sizeof (dwarf5_augmentation
))
5024 && memcmp (addr
, dwarf5_augmentation
,
5025 sizeof (dwarf5_augmentation
)) == 0);
5026 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5027 addr
+= augmentation_string_size
;
5030 map
.cu_table_reordered
= addr
;
5031 addr
+= map
.cu_count
* map
.offset_size
;
5033 /* List of Local TUs */
5034 map
.tu_table_reordered
= addr
;
5035 addr
+= map
.tu_count
* map
.offset_size
;
5037 /* Hash Lookup Table */
5038 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5039 addr
+= map
.bucket_count
* 4;
5040 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5041 addr
+= map
.name_count
* 4;
5044 map
.name_table_string_offs_reordered
= addr
;
5045 addr
+= map
.name_count
* map
.offset_size
;
5046 map
.name_table_entry_offs_reordered
= addr
;
5047 addr
+= map
.name_count
* map
.offset_size
;
5049 const gdb_byte
*abbrev_table_start
= addr
;
5052 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5057 const auto insertpair
5058 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5059 if (!insertpair
.second
)
5061 warning (_("Section .debug_names in %s has duplicate index %s, "
5062 "ignoring .debug_names."),
5063 filename
, pulongest (index_num
));
5066 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5067 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5072 mapped_debug_names::index_val::attr attr
;
5073 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5075 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5077 if (attr
.form
== DW_FORM_implicit_const
)
5079 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5083 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5085 indexval
.attr_vec
.push_back (std::move (attr
));
5088 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5090 warning (_("Section .debug_names in %s has abbreviation_table "
5091 "of size %s vs. written as %u, ignoring .debug_names."),
5092 filename
, plongest (addr
- abbrev_table_start
),
5096 map
.entry_pool
= addr
;
5101 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5105 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5106 const mapped_debug_names
&map
,
5107 dwarf2_section_info
§ion
,
5110 if (!map
.augmentation_is_gdb
)
5112 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5114 sect_offset sect_off
5115 = (sect_offset
) (extract_unsigned_integer
5116 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5118 map
.dwarf5_byte_order
));
5119 /* We don't know the length of the CU, because the CU list in a
5120 .debug_names index can be incomplete, so we can't use the start of
5121 the next CU as end of this CU. We create the CUs here with length 0,
5122 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5123 dwarf2_per_cu_data
*per_cu
5124 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5126 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5130 sect_offset sect_off_prev
;
5131 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5133 sect_offset sect_off_next
;
5134 if (i
< map
.cu_count
)
5137 = (sect_offset
) (extract_unsigned_integer
5138 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5140 map
.dwarf5_byte_order
));
5143 sect_off_next
= (sect_offset
) section
.size
;
5146 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5147 dwarf2_per_cu_data
*per_cu
5148 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5149 sect_off_prev
, length
);
5150 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5152 sect_off_prev
= sect_off_next
;
5156 /* Read the CU list from the mapped index, and use it to create all
5157 the CU objects for this dwarf2_per_objfile. */
5160 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5161 const mapped_debug_names
&map
,
5162 const mapped_debug_names
&dwz_map
)
5164 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
5165 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5167 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5168 dwarf2_per_objfile
->per_bfd
->info
,
5169 false /* is_dwz */);
5171 if (dwz_map
.cu_count
== 0)
5174 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5175 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5179 /* Read .debug_names. If everything went ok, initialize the "quick"
5180 elements of all the CUs and return true. Otherwise, return false. */
5183 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5185 std::unique_ptr
<mapped_debug_names
> map
5186 (new mapped_debug_names (dwarf2_per_objfile
));
5187 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5188 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5190 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5191 &dwarf2_per_objfile
->per_bfd
->debug_names
,
5195 /* Don't use the index if it's empty. */
5196 if (map
->name_count
== 0)
5199 /* If there is a .dwz file, read it so we can get its CU list as
5201 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5204 if (!read_debug_names_from_section (objfile
,
5205 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5206 &dwz
->debug_names
, dwz_map
))
5208 warning (_("could not read '.debug_names' section from %s; skipping"),
5209 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5214 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5216 if (map
->tu_count
!= 0)
5218 /* We can only handle a single .debug_types when we have an
5220 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
5223 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
5225 create_signatured_type_table_from_debug_names
5226 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->per_bfd
->abbrev
);
5229 create_addrmap_from_aranges (dwarf2_per_objfile
,
5230 &dwarf2_per_objfile
->per_bfd
->debug_aranges
);
5232 dwarf2_per_objfile
->per_bfd
->debug_names_table
= std::move (map
);
5233 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5234 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
5235 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5240 /* Type used to manage iterating over all CUs looking for a symbol for
5243 class dw2_debug_names_iterator
5246 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5247 gdb::optional
<block_enum
> block_index
,
5250 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5251 m_addr (find_vec_in_debug_names (map
, name
))
5254 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5255 search_domain search
, uint32_t namei
)
5258 m_addr (find_vec_in_debug_names (map
, namei
))
5261 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5262 block_enum block_index
, domain_enum domain
,
5264 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5265 m_addr (find_vec_in_debug_names (map
, namei
))
5268 /* Return the next matching CU or NULL if there are no more. */
5269 dwarf2_per_cu_data
*next ();
5272 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5274 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5277 /* The internalized form of .debug_names. */
5278 const mapped_debug_names
&m_map
;
5280 /* If set, only look for symbols that match that block. Valid values are
5281 GLOBAL_BLOCK and STATIC_BLOCK. */
5282 const gdb::optional
<block_enum
> m_block_index
;
5284 /* The kind of symbol we're looking for. */
5285 const domain_enum m_domain
= UNDEF_DOMAIN
;
5286 const search_domain m_search
= ALL_DOMAIN
;
5288 /* The list of CUs from the index entry of the symbol, or NULL if
5290 const gdb_byte
*m_addr
;
5294 mapped_debug_names::namei_to_name (uint32_t namei
) const
5296 const ULONGEST namei_string_offs
5297 = extract_unsigned_integer ((name_table_string_offs_reordered
5298 + namei
* offset_size
),
5301 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5305 /* Find a slot in .debug_names for the object named NAME. If NAME is
5306 found, return pointer to its pool data. If NAME cannot be found,
5310 dw2_debug_names_iterator::find_vec_in_debug_names
5311 (const mapped_debug_names
&map
, const char *name
)
5313 int (*cmp
) (const char *, const char *);
5315 gdb::unique_xmalloc_ptr
<char> without_params
;
5316 if (current_language
->la_language
== language_cplus
5317 || current_language
->la_language
== language_fortran
5318 || current_language
->la_language
== language_d
)
5320 /* NAME is already canonical. Drop any qualifiers as
5321 .debug_names does not contain any. */
5323 if (strchr (name
, '(') != NULL
)
5325 without_params
= cp_remove_params (name
);
5326 if (without_params
!= NULL
)
5327 name
= without_params
.get ();
5331 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5333 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5335 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5336 (map
.bucket_table_reordered
5337 + (full_hash
% map
.bucket_count
)), 4,
5338 map
.dwarf5_byte_order
);
5342 if (namei
>= map
.name_count
)
5344 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5346 namei
, map
.name_count
,
5347 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5353 const uint32_t namei_full_hash
5354 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5355 (map
.hash_table_reordered
+ namei
), 4,
5356 map
.dwarf5_byte_order
);
5357 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5360 if (full_hash
== namei_full_hash
)
5362 const char *const namei_string
= map
.namei_to_name (namei
);
5364 #if 0 /* An expensive sanity check. */
5365 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5367 complaint (_("Wrong .debug_names hash for string at index %u "
5369 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5374 if (cmp (namei_string
, name
) == 0)
5376 const ULONGEST namei_entry_offs
5377 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5378 + namei
* map
.offset_size
),
5379 map
.offset_size
, map
.dwarf5_byte_order
);
5380 return map
.entry_pool
+ namei_entry_offs
;
5385 if (namei
>= map
.name_count
)
5391 dw2_debug_names_iterator::find_vec_in_debug_names
5392 (const mapped_debug_names
&map
, uint32_t namei
)
5394 if (namei
>= map
.name_count
)
5396 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5398 namei
, map
.name_count
,
5399 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5403 const ULONGEST namei_entry_offs
5404 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5405 + namei
* map
.offset_size
),
5406 map
.offset_size
, map
.dwarf5_byte_order
);
5407 return map
.entry_pool
+ namei_entry_offs
;
5410 /* See dw2_debug_names_iterator. */
5412 dwarf2_per_cu_data
*
5413 dw2_debug_names_iterator::next ()
5418 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5419 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5420 bfd
*const abfd
= objfile
->obfd
;
5424 unsigned int bytes_read
;
5425 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5426 m_addr
+= bytes_read
;
5430 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5431 if (indexval_it
== m_map
.abbrev_map
.cend ())
5433 complaint (_("Wrong .debug_names undefined abbrev code %s "
5435 pulongest (abbrev
), objfile_name (objfile
));
5438 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5439 enum class symbol_linkage
{
5443 } symbol_linkage_
= symbol_linkage::unknown
;
5444 dwarf2_per_cu_data
*per_cu
= NULL
;
5445 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5450 case DW_FORM_implicit_const
:
5451 ull
= attr
.implicit_const
;
5453 case DW_FORM_flag_present
:
5457 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5458 m_addr
+= bytes_read
;
5461 ull
= read_4_bytes (abfd
, m_addr
);
5465 ull
= read_8_bytes (abfd
, m_addr
);
5468 case DW_FORM_ref_sig8
:
5469 ull
= read_8_bytes (abfd
, m_addr
);
5473 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5474 dwarf_form_name (attr
.form
),
5475 objfile_name (objfile
));
5478 switch (attr
.dw_idx
)
5480 case DW_IDX_compile_unit
:
5481 /* Don't crash on bad data. */
5482 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
5484 complaint (_(".debug_names entry has bad CU index %s"
5487 objfile_name (dwarf2_per_objfile
->objfile
));
5490 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (ull
);
5492 case DW_IDX_type_unit
:
5493 /* Don't crash on bad data. */
5494 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_type_units
.size ())
5496 complaint (_(".debug_names entry has bad TU index %s"
5499 objfile_name (dwarf2_per_objfile
->objfile
));
5502 per_cu
= &dwarf2_per_objfile
->per_bfd
->get_tu (ull
)->per_cu
;
5504 case DW_IDX_die_offset
:
5505 /* In a per-CU index (as opposed to a per-module index), index
5506 entries without CU attribute implicitly refer to the single CU. */
5508 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cu (0);
5510 case DW_IDX_GNU_internal
:
5511 if (!m_map
.augmentation_is_gdb
)
5513 symbol_linkage_
= symbol_linkage::static_
;
5515 case DW_IDX_GNU_external
:
5516 if (!m_map
.augmentation_is_gdb
)
5518 symbol_linkage_
= symbol_linkage::extern_
;
5523 /* Skip if already read in. */
5524 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
5527 /* Check static vs global. */
5528 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5530 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5531 const bool symbol_is_static
=
5532 symbol_linkage_
== symbol_linkage::static_
;
5533 if (want_static
!= symbol_is_static
)
5537 /* Match dw2_symtab_iter_next, symbol_kind
5538 and debug_names::psymbol_tag. */
5542 switch (indexval
.dwarf_tag
)
5544 case DW_TAG_variable
:
5545 case DW_TAG_subprogram
:
5546 /* Some types are also in VAR_DOMAIN. */
5547 case DW_TAG_typedef
:
5548 case DW_TAG_structure_type
:
5555 switch (indexval
.dwarf_tag
)
5557 case DW_TAG_typedef
:
5558 case DW_TAG_structure_type
:
5565 switch (indexval
.dwarf_tag
)
5568 case DW_TAG_variable
:
5575 switch (indexval
.dwarf_tag
)
5587 /* Match dw2_expand_symtabs_matching, symbol_kind and
5588 debug_names::psymbol_tag. */
5591 case VARIABLES_DOMAIN
:
5592 switch (indexval
.dwarf_tag
)
5594 case DW_TAG_variable
:
5600 case FUNCTIONS_DOMAIN
:
5601 switch (indexval
.dwarf_tag
)
5603 case DW_TAG_subprogram
:
5610 switch (indexval
.dwarf_tag
)
5612 case DW_TAG_typedef
:
5613 case DW_TAG_structure_type
:
5619 case MODULES_DOMAIN
:
5620 switch (indexval
.dwarf_tag
)
5634 static struct compunit_symtab
*
5635 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5636 const char *name
, domain_enum domain
)
5638 struct dwarf2_per_objfile
*dwarf2_per_objfile
5639 = get_dwarf2_per_objfile (objfile
);
5641 const auto &mapp
= dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5644 /* index is NULL if OBJF_READNOW. */
5647 const auto &map
= *mapp
;
5649 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5651 struct compunit_symtab
*stab_best
= NULL
;
5652 struct dwarf2_per_cu_data
*per_cu
;
5653 while ((per_cu
= iter
.next ()) != NULL
)
5655 struct symbol
*sym
, *with_opaque
= NULL
;
5656 compunit_symtab
*stab
5657 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5658 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5659 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5661 sym
= block_find_symbol (block
, name
, domain
,
5662 block_find_non_opaque_type_preferred
,
5665 /* Some caution must be observed with overloaded functions and
5666 methods, since the index will not contain any overload
5667 information (but NAME might contain it). */
5670 && strcmp_iw (sym
->search_name (), name
) == 0)
5672 if (with_opaque
!= NULL
5673 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5676 /* Keep looking through other CUs. */
5682 /* This dumps minimal information about .debug_names. It is called
5683 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5684 uses this to verify that .debug_names has been loaded. */
5687 dw2_debug_names_dump (struct objfile
*objfile
)
5689 struct dwarf2_per_objfile
*dwarf2_per_objfile
5690 = get_dwarf2_per_objfile (objfile
);
5692 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
5693 printf_filtered (".debug_names:");
5694 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5695 printf_filtered (" exists\n");
5697 printf_filtered (" faked for \"readnow\"\n");
5698 printf_filtered ("\n");
5702 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5703 const char *func_name
)
5705 struct dwarf2_per_objfile
*dwarf2_per_objfile
5706 = get_dwarf2_per_objfile (objfile
);
5708 /* dwarf2_per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5709 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5711 const mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5713 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5715 struct dwarf2_per_cu_data
*per_cu
;
5716 while ((per_cu
= iter
.next ()) != NULL
)
5717 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5722 dw2_debug_names_map_matching_symbols
5723 (struct objfile
*objfile
,
5724 const lookup_name_info
&name
, domain_enum domain
,
5726 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5727 symbol_compare_ftype
*ordered_compare
)
5729 struct dwarf2_per_objfile
*dwarf2_per_objfile
5730 = get_dwarf2_per_objfile (objfile
);
5732 /* debug_names_table is NULL if OBJF_READNOW. */
5733 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5736 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5737 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5739 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5740 auto matcher
= [&] (const char *symname
)
5742 if (ordered_compare
== nullptr)
5744 return ordered_compare (symname
, match_name
) == 0;
5747 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5748 [&] (offset_type namei
)
5750 /* The name was matched, now expand corresponding CUs that were
5752 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5754 struct dwarf2_per_cu_data
*per_cu
;
5755 while ((per_cu
= iter
.next ()) != NULL
)
5756 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
5761 /* It's a shame we couldn't do this inside the
5762 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5763 that have already been expanded. Instead, this loop matches what
5764 the psymtab code does. */
5765 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5767 compunit_symtab
*symtab
= dwarf2_per_objfile
->get_symtab (per_cu
);
5768 if (symtab
!= nullptr)
5770 const struct block
*block
5771 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5772 if (!iterate_over_symbols_terminated (block
, name
,
5780 dw2_debug_names_expand_symtabs_matching
5781 (struct objfile
*objfile
,
5782 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5783 const lookup_name_info
*lookup_name
,
5784 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5785 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5786 enum search_domain kind
)
5788 struct dwarf2_per_objfile
*dwarf2_per_objfile
5789 = get_dwarf2_per_objfile (objfile
);
5791 /* debug_names_table is NULL if OBJF_READNOW. */
5792 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5795 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5797 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5799 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5803 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5804 file_matcher
, expansion_notify
);
5809 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5811 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5813 kind
, [&] (offset_type namei
)
5815 /* The name was matched, now expand corresponding CUs that were
5817 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5819 struct dwarf2_per_cu_data
*per_cu
;
5820 while ((per_cu
= iter
.next ()) != NULL
)
5821 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5822 file_matcher
, expansion_notify
);
5827 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5830 dw2_find_last_source_symtab
,
5831 dw2_forget_cached_source_info
,
5832 dw2_map_symtabs_matching_filename
,
5833 dw2_debug_names_lookup_symbol
,
5836 dw2_debug_names_dump
,
5837 dw2_debug_names_expand_symtabs_for_function
,
5838 dw2_expand_all_symtabs
,
5839 dw2_expand_symtabs_with_fullname
,
5840 dw2_debug_names_map_matching_symbols
,
5841 dw2_debug_names_expand_symtabs_matching
,
5842 dw2_find_pc_sect_compunit_symtab
,
5844 dw2_map_symbol_filenames
5847 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5848 to either a dwarf2_per_bfd or dwz_file object. */
5850 template <typename T
>
5851 static gdb::array_view
<const gdb_byte
>
5852 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5854 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5856 if (section
->empty ())
5859 /* Older elfutils strip versions could keep the section in the main
5860 executable while splitting it for the separate debug info file. */
5861 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5864 section
->read (obj
);
5866 /* dwarf2_section_info::size is a bfd_size_type, while
5867 gdb::array_view works with size_t. On 32-bit hosts, with
5868 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5869 is 32-bit. So we need an explicit narrowing conversion here.
5870 This is fine, because it's impossible to allocate or mmap an
5871 array/buffer larger than what size_t can represent. */
5872 return gdb::make_array_view (section
->buffer
, section
->size
);
5875 /* Lookup the index cache for the contents of the index associated to
5878 static gdb::array_view
<const gdb_byte
>
5879 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5881 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5882 if (build_id
== nullptr)
5885 return global_index_cache
.lookup_gdb_index (build_id
,
5886 &dwarf2_per_bfd
->index_cache_res
);
5889 /* Same as the above, but for DWZ. */
5891 static gdb::array_view
<const gdb_byte
>
5892 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5894 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5895 if (build_id
== nullptr)
5898 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5901 /* See symfile.h. */
5904 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5906 struct dwarf2_per_objfile
*dwarf2_per_objfile
5907 = get_dwarf2_per_objfile (objfile
);
5909 /* If we're about to read full symbols, don't bother with the
5910 indices. In this case we also don't care if some other debug
5911 format is making psymtabs, because they are all about to be
5913 if ((objfile
->flags
& OBJF_READNOW
))
5915 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5916 create_all_comp_units (dwarf2_per_objfile
);
5917 create_all_type_units (dwarf2_per_objfile
);
5918 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
5919 = create_quick_file_names_table
5920 (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5921 dwarf2_per_objfile
->resize_symtabs ();
5923 for (int i
= 0; i
< (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
5924 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()); ++i
)
5926 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
5928 per_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
5929 struct dwarf2_per_cu_quick_data
);
5932 /* Return 1 so that gdb sees the "quick" functions. However,
5933 these functions will be no-ops because we will have expanded
5935 *index_kind
= dw_index_kind::GDB_INDEX
;
5939 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5941 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5942 dwarf2_per_objfile
->resize_symtabs ();
5946 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5947 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5948 get_gdb_index_contents_from_section
<dwz_file
>))
5950 *index_kind
= dw_index_kind::GDB_INDEX
;
5951 dwarf2_per_objfile
->resize_symtabs ();
5955 /* ... otherwise, try to find the index in the index cache. */
5956 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5957 get_gdb_index_contents_from_cache
,
5958 get_gdb_index_contents_from_cache_dwz
))
5960 global_index_cache
.hit ();
5961 *index_kind
= dw_index_kind::GDB_INDEX
;
5962 dwarf2_per_objfile
->resize_symtabs ();
5966 global_index_cache
.miss ();
5972 /* Build a partial symbol table. */
5975 dwarf2_build_psymtabs (struct objfile
*objfile
)
5977 struct dwarf2_per_objfile
*dwarf2_per_objfile
5978 = get_dwarf2_per_objfile (objfile
);
5980 init_psymbol_list (objfile
, 1024);
5984 /* This isn't really ideal: all the data we allocate on the
5985 objfile's obstack is still uselessly kept around. However,
5986 freeing it seems unsafe. */
5987 psymtab_discarder
psymtabs (objfile
);
5988 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5991 dwarf2_per_objfile
->resize_symtabs ();
5993 /* (maybe) store an index in the cache. */
5994 global_index_cache
.store (dwarf2_per_objfile
);
5996 catch (const gdb_exception_error
&except
)
5998 exception_print (gdb_stderr
, except
);
6002 /* Find the base address of the compilation unit for range lists and
6003 location lists. It will normally be specified by DW_AT_low_pc.
6004 In DWARF-3 draft 4, the base address could be overridden by
6005 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6006 compilation units with discontinuous ranges. */
6009 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6011 struct attribute
*attr
;
6013 cu
->base_address
.reset ();
6015 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6016 if (attr
!= nullptr)
6017 cu
->base_address
= attr
->value_as_address ();
6020 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6021 if (attr
!= nullptr)
6022 cu
->base_address
= attr
->value_as_address ();
6026 /* Helper function that returns the proper abbrev section for
6029 static struct dwarf2_section_info
*
6030 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6032 struct dwarf2_section_info
*abbrev
;
6033 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6035 if (this_cu
->is_dwz
)
6036 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6038 abbrev
= &dwarf2_per_objfile
->per_bfd
->abbrev
;
6043 /* Fetch the abbreviation table offset from a comp or type unit header. */
6046 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6047 struct dwarf2_section_info
*section
,
6048 sect_offset sect_off
)
6050 bfd
*abfd
= section
->get_bfd_owner ();
6051 const gdb_byte
*info_ptr
;
6052 unsigned int initial_length_size
, offset_size
;
6055 section
->read (dwarf2_per_objfile
->objfile
);
6056 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6057 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6058 offset_size
= initial_length_size
== 4 ? 4 : 8;
6059 info_ptr
+= initial_length_size
;
6061 version
= read_2_bytes (abfd
, info_ptr
);
6065 /* Skip unit type and address size. */
6069 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6072 /* A partial symtab that is used only for include files. */
6073 struct dwarf2_include_psymtab
: public partial_symtab
6075 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6076 : partial_symtab (filename
, objfile
)
6080 void read_symtab (struct objfile
*objfile
) override
6082 /* It's an include file, no symbols to read for it.
6083 Everything is in the includer symtab. */
6085 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6086 expansion of the includer psymtab. We use the dependencies[0] field to
6087 model the includer. But if we go the regular route of calling
6088 expand_psymtab here, and having expand_psymtab call expand_dependencies
6089 to expand the includer, we'll only use expand_psymtab on the includer
6090 (making it a non-toplevel psymtab), while if we expand the includer via
6091 another path, we'll use read_symtab (making it a toplevel psymtab).
6092 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6093 psymtab, and trigger read_symtab on the includer here directly. */
6094 includer ()->read_symtab (objfile
);
6097 void expand_psymtab (struct objfile
*objfile
) override
6099 /* This is not called by read_symtab, and should not be called by any
6100 expand_dependencies. */
6104 bool readin_p (struct objfile
*objfile
) const override
6106 return includer ()->readin_p (objfile
);
6109 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6115 partial_symtab
*includer () const
6117 /* An include psymtab has exactly one dependency: the psymtab that
6119 gdb_assert (this->number_of_dependencies
== 1);
6120 return this->dependencies
[0];
6124 /* Allocate a new partial symtab for file named NAME and mark this new
6125 partial symtab as being an include of PST. */
6128 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6129 struct objfile
*objfile
)
6131 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6133 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6134 subpst
->dirname
= pst
->dirname
;
6136 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6137 subpst
->dependencies
[0] = pst
;
6138 subpst
->number_of_dependencies
= 1;
6141 /* Read the Line Number Program data and extract the list of files
6142 included by the source file represented by PST. Build an include
6143 partial symtab for each of these included files. */
6146 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6147 struct die_info
*die
,
6148 dwarf2_psymtab
*pst
)
6151 struct attribute
*attr
;
6153 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6154 if (attr
!= nullptr)
6155 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6157 return; /* No linetable, so no includes. */
6159 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6160 that we pass in the raw text_low here; that is ok because we're
6161 only decoding the line table to make include partial symtabs, and
6162 so the addresses aren't really used. */
6163 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6164 pst
->raw_text_low (), 1);
6168 hash_signatured_type (const void *item
)
6170 const struct signatured_type
*sig_type
6171 = (const struct signatured_type
*) item
;
6173 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6174 return sig_type
->signature
;
6178 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6180 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6181 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6183 return lhs
->signature
== rhs
->signature
;
6186 /* Allocate a hash table for signatured types. */
6189 allocate_signatured_type_table ()
6191 return htab_up (htab_create_alloc (41,
6192 hash_signatured_type
,
6194 NULL
, xcalloc
, xfree
));
6197 /* A helper function to add a signatured type CU to a table. */
6200 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6202 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6203 std::vector
<signatured_type
*> *all_type_units
6204 = (std::vector
<signatured_type
*> *) datum
;
6206 all_type_units
->push_back (sigt
);
6211 /* A helper for create_debug_types_hash_table. Read types from SECTION
6212 and fill them into TYPES_HTAB. It will process only type units,
6213 therefore DW_UT_type. */
6216 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6217 struct dwo_file
*dwo_file
,
6218 dwarf2_section_info
*section
, htab_up
&types_htab
,
6219 rcuh_kind section_kind
)
6221 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6222 struct dwarf2_section_info
*abbrev_section
;
6224 const gdb_byte
*info_ptr
, *end_ptr
;
6226 abbrev_section
= (dwo_file
!= NULL
6227 ? &dwo_file
->sections
.abbrev
6228 : &dwarf2_per_objfile
->per_bfd
->abbrev
);
6230 if (dwarf_read_debug
)
6231 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6232 section
->get_name (),
6233 abbrev_section
->get_file_name ());
6235 section
->read (objfile
);
6236 info_ptr
= section
->buffer
;
6238 if (info_ptr
== NULL
)
6241 /* We can't set abfd until now because the section may be empty or
6242 not present, in which case the bfd is unknown. */
6243 abfd
= section
->get_bfd_owner ();
6245 /* We don't use cutu_reader here because we don't need to read
6246 any dies: the signature is in the header. */
6248 end_ptr
= info_ptr
+ section
->size
;
6249 while (info_ptr
< end_ptr
)
6251 struct signatured_type
*sig_type
;
6252 struct dwo_unit
*dwo_tu
;
6254 const gdb_byte
*ptr
= info_ptr
;
6255 struct comp_unit_head header
;
6256 unsigned int length
;
6258 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6260 /* Initialize it due to a false compiler warning. */
6261 header
.signature
= -1;
6262 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6264 /* We need to read the type's signature in order to build the hash
6265 table, but we don't need anything else just yet. */
6267 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6268 abbrev_section
, ptr
, section_kind
);
6270 length
= header
.get_length ();
6272 /* Skip dummy type units. */
6273 if (ptr
>= info_ptr
+ length
6274 || peek_abbrev_code (abfd
, ptr
) == 0
6275 || header
.unit_type
!= DW_UT_type
)
6281 if (types_htab
== NULL
)
6284 types_htab
= allocate_dwo_unit_table ();
6286 types_htab
= allocate_signatured_type_table ();
6292 dwo_tu
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6294 dwo_tu
->dwo_file
= dwo_file
;
6295 dwo_tu
->signature
= header
.signature
;
6296 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6297 dwo_tu
->section
= section
;
6298 dwo_tu
->sect_off
= sect_off
;
6299 dwo_tu
->length
= length
;
6303 /* N.B.: type_offset is not usable if this type uses a DWO file.
6304 The real type_offset is in the DWO file. */
6306 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6307 sig_type
->signature
= header
.signature
;
6308 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6309 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6310 sig_type
->per_cu
.is_debug_types
= 1;
6311 sig_type
->per_cu
.section
= section
;
6312 sig_type
->per_cu
.sect_off
= sect_off
;
6313 sig_type
->per_cu
.length
= length
;
6316 slot
= htab_find_slot (types_htab
.get (),
6317 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6319 gdb_assert (slot
!= NULL
);
6322 sect_offset dup_sect_off
;
6326 const struct dwo_unit
*dup_tu
6327 = (const struct dwo_unit
*) *slot
;
6329 dup_sect_off
= dup_tu
->sect_off
;
6333 const struct signatured_type
*dup_tu
6334 = (const struct signatured_type
*) *slot
;
6336 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6339 complaint (_("debug type entry at offset %s is duplicate to"
6340 " the entry at offset %s, signature %s"),
6341 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6342 hex_string (header
.signature
));
6344 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6346 if (dwarf_read_debug
> 1)
6347 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6348 sect_offset_str (sect_off
),
6349 hex_string (header
.signature
));
6355 /* Create the hash table of all entries in the .debug_types
6356 (or .debug_types.dwo) section(s).
6357 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6358 otherwise it is NULL.
6360 The result is a pointer to the hash table or NULL if there are no types.
6362 Note: This function processes DWO files only, not DWP files. */
6365 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6366 struct dwo_file
*dwo_file
,
6367 gdb::array_view
<dwarf2_section_info
> type_sections
,
6368 htab_up
&types_htab
)
6370 for (dwarf2_section_info
§ion
: type_sections
)
6371 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6372 types_htab
, rcuh_kind::TYPE
);
6375 /* Create the hash table of all entries in the .debug_types section,
6376 and initialize all_type_units.
6377 The result is zero if there is an error (e.g. missing .debug_types section),
6378 otherwise non-zero. */
6381 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6385 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6386 &dwarf2_per_objfile
->per_bfd
->info
, types_htab
,
6387 rcuh_kind::COMPILE
);
6388 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6389 dwarf2_per_objfile
->per_bfd
->types
, types_htab
);
6390 if (types_htab
== NULL
)
6392 dwarf2_per_objfile
->per_bfd
->signatured_types
= NULL
;
6396 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6398 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
6399 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve
6400 (htab_elements (dwarf2_per_objfile
->per_bfd
->signatured_types
.get ()));
6402 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6403 add_signatured_type_cu_to_table
,
6404 &dwarf2_per_objfile
->per_bfd
->all_type_units
);
6409 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6410 If SLOT is non-NULL, it is the entry to use in the hash table.
6411 Otherwise we find one. */
6413 static struct signatured_type
*
6414 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6417 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()
6418 == dwarf2_per_objfile
->per_bfd
->all_type_units
.capacity ())
6419 ++dwarf2_per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6421 signatured_type
*sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6423 dwarf2_per_objfile
->resize_symtabs ();
6425 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6426 sig_type
->signature
= sig
;
6427 sig_type
->per_cu
.is_debug_types
= 1;
6428 if (dwarf2_per_objfile
->per_bfd
->using_index
)
6430 sig_type
->per_cu
.v
.quick
=
6431 OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6432 struct dwarf2_per_cu_quick_data
);
6437 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6440 gdb_assert (*slot
== NULL
);
6442 /* The rest of sig_type must be filled in by the caller. */
6446 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6447 Fill in SIG_ENTRY with DWO_ENTRY. */
6450 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6451 struct signatured_type
*sig_entry
,
6452 struct dwo_unit
*dwo_entry
)
6454 /* Make sure we're not clobbering something we don't expect to. */
6455 gdb_assert (! sig_entry
->per_cu
.queued
);
6456 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6457 if (dwarf2_per_objfile
->per_bfd
->using_index
)
6459 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6460 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6463 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6464 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6465 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6466 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6467 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6469 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6470 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6471 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6472 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6473 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6474 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6475 sig_entry
->dwo_unit
= dwo_entry
;
6478 /* Subroutine of lookup_signatured_type.
6479 If we haven't read the TU yet, create the signatured_type data structure
6480 for a TU to be read in directly from a DWO file, bypassing the stub.
6481 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6482 using .gdb_index, then when reading a CU we want to stay in the DWO file
6483 containing that CU. Otherwise we could end up reading several other DWO
6484 files (due to comdat folding) to process the transitive closure of all the
6485 mentioned TUs, and that can be slow. The current DWO file will have every
6486 type signature that it needs.
6487 We only do this for .gdb_index because in the psymtab case we already have
6488 to read all the DWOs to build the type unit groups. */
6490 static struct signatured_type
*
6491 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6493 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6494 struct dwo_file
*dwo_file
;
6495 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6496 struct signatured_type find_sig_entry
, *sig_entry
;
6499 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6501 /* If TU skeletons have been removed then we may not have read in any
6503 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6504 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6506 /* We only ever need to read in one copy of a signatured type.
6507 Use the global signatured_types array to do our own comdat-folding
6508 of types. If this is the first time we're reading this TU, and
6509 the TU has an entry in .gdb_index, replace the recorded data from
6510 .gdb_index with this TU. */
6512 find_sig_entry
.signature
= sig
;
6513 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6514 &find_sig_entry
, INSERT
);
6515 sig_entry
= (struct signatured_type
*) *slot
;
6517 /* We can get here with the TU already read, *or* in the process of being
6518 read. Don't reassign the global entry to point to this DWO if that's
6519 the case. Also note that if the TU is already being read, it may not
6520 have come from a DWO, the program may be a mix of Fission-compiled
6521 code and non-Fission-compiled code. */
6523 /* Have we already tried to read this TU?
6524 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6525 needn't exist in the global table yet). */
6526 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6529 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6530 dwo_unit of the TU itself. */
6531 dwo_file
= cu
->dwo_unit
->dwo_file
;
6533 /* Ok, this is the first time we're reading this TU. */
6534 if (dwo_file
->tus
== NULL
)
6536 find_dwo_entry
.signature
= sig
;
6537 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6539 if (dwo_entry
== NULL
)
6542 /* If the global table doesn't have an entry for this TU, add one. */
6543 if (sig_entry
== NULL
)
6544 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6546 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6547 sig_entry
->per_cu
.tu_read
= 1;
6551 /* Subroutine of lookup_signatured_type.
6552 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6553 then try the DWP file. If the TU stub (skeleton) has been removed then
6554 it won't be in .gdb_index. */
6556 static struct signatured_type
*
6557 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6559 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6560 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6561 struct dwo_unit
*dwo_entry
;
6562 struct signatured_type find_sig_entry
, *sig_entry
;
6565 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6566 gdb_assert (dwp_file
!= NULL
);
6568 /* If TU skeletons have been removed then we may not have read in any
6570 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6571 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6573 find_sig_entry
.signature
= sig
;
6574 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6575 &find_sig_entry
, INSERT
);
6576 sig_entry
= (struct signatured_type
*) *slot
;
6578 /* Have we already tried to read this TU?
6579 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6580 needn't exist in the global table yet). */
6581 if (sig_entry
!= NULL
)
6584 if (dwp_file
->tus
== NULL
)
6586 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6587 sig
, 1 /* is_debug_types */);
6588 if (dwo_entry
== NULL
)
6591 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6592 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6597 /* Lookup a signature based type for DW_FORM_ref_sig8.
6598 Returns NULL if signature SIG is not present in the table.
6599 It is up to the caller to complain about this. */
6601 static struct signatured_type
*
6602 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6604 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6607 && dwarf2_per_objfile
->per_bfd
->using_index
)
6609 /* We're in a DWO/DWP file, and we're using .gdb_index.
6610 These cases require special processing. */
6611 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6612 return lookup_dwo_signatured_type (cu
, sig
);
6614 return lookup_dwp_signatured_type (cu
, sig
);
6618 struct signatured_type find_entry
, *entry
;
6620 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6622 find_entry
.signature
= sig
;
6623 entry
= ((struct signatured_type
*)
6624 htab_find (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6630 /* Low level DIE reading support. */
6632 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6635 init_cu_die_reader (struct die_reader_specs
*reader
,
6636 struct dwarf2_cu
*cu
,
6637 struct dwarf2_section_info
*section
,
6638 struct dwo_file
*dwo_file
,
6639 struct abbrev_table
*abbrev_table
)
6641 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6642 reader
->abfd
= section
->get_bfd_owner ();
6644 reader
->dwo_file
= dwo_file
;
6645 reader
->die_section
= section
;
6646 reader
->buffer
= section
->buffer
;
6647 reader
->buffer_end
= section
->buffer
+ section
->size
;
6648 reader
->abbrev_table
= abbrev_table
;
6651 /* Subroutine of cutu_reader to simplify it.
6652 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6653 There's just a lot of work to do, and cutu_reader is big enough
6656 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6657 from it to the DIE in the DWO. If NULL we are skipping the stub.
6658 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6659 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6660 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6661 STUB_COMP_DIR may be non-NULL.
6662 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6663 are filled in with the info of the DIE from the DWO file.
6664 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6665 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6666 kept around for at least as long as *RESULT_READER.
6668 The result is non-zero if a valid (non-dummy) DIE was found. */
6671 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6672 struct dwo_unit
*dwo_unit
,
6673 struct die_info
*stub_comp_unit_die
,
6674 const char *stub_comp_dir
,
6675 struct die_reader_specs
*result_reader
,
6676 const gdb_byte
**result_info_ptr
,
6677 struct die_info
**result_comp_unit_die
,
6678 abbrev_table_up
*result_dwo_abbrev_table
)
6680 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6681 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6682 struct dwarf2_cu
*cu
= this_cu
->cu
;
6684 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6685 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6686 int i
,num_extra_attrs
;
6687 struct dwarf2_section_info
*dwo_abbrev_section
;
6688 struct die_info
*comp_unit_die
;
6690 /* At most one of these may be provided. */
6691 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6693 /* These attributes aren't processed until later:
6694 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6695 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6696 referenced later. However, these attributes are found in the stub
6697 which we won't have later. In order to not impose this complication
6698 on the rest of the code, we read them here and copy them to the
6707 if (stub_comp_unit_die
!= NULL
)
6709 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6711 if (! this_cu
->is_debug_types
)
6712 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6713 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6714 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6715 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6716 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6718 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6720 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6721 here (if needed). We need the value before we can process
6723 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6725 else if (stub_comp_dir
!= NULL
)
6727 /* Reconstruct the comp_dir attribute to simplify the code below. */
6728 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6729 comp_dir
->name
= DW_AT_comp_dir
;
6730 comp_dir
->form
= DW_FORM_string
;
6731 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6732 DW_STRING (comp_dir
) = stub_comp_dir
;
6735 /* Set up for reading the DWO CU/TU. */
6736 cu
->dwo_unit
= dwo_unit
;
6737 dwarf2_section_info
*section
= dwo_unit
->section
;
6738 section
->read (objfile
);
6739 abfd
= section
->get_bfd_owner ();
6740 begin_info_ptr
= info_ptr
= (section
->buffer
6741 + to_underlying (dwo_unit
->sect_off
));
6742 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6744 if (this_cu
->is_debug_types
)
6746 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6748 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6749 &cu
->header
, section
,
6751 info_ptr
, rcuh_kind::TYPE
);
6752 /* This is not an assert because it can be caused by bad debug info. */
6753 if (sig_type
->signature
!= cu
->header
.signature
)
6755 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6756 " TU at offset %s [in module %s]"),
6757 hex_string (sig_type
->signature
),
6758 hex_string (cu
->header
.signature
),
6759 sect_offset_str (dwo_unit
->sect_off
),
6760 bfd_get_filename (abfd
));
6762 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6763 /* For DWOs coming from DWP files, we don't know the CU length
6764 nor the type's offset in the TU until now. */
6765 dwo_unit
->length
= cu
->header
.get_length ();
6766 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6768 /* Establish the type offset that can be used to lookup the type.
6769 For DWO files, we don't know it until now. */
6770 sig_type
->type_offset_in_section
6771 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6775 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6776 &cu
->header
, section
,
6778 info_ptr
, rcuh_kind::COMPILE
);
6779 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6780 /* For DWOs coming from DWP files, we don't know the CU length
6782 dwo_unit
->length
= cu
->header
.get_length ();
6785 *result_dwo_abbrev_table
6786 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6787 cu
->header
.abbrev_sect_off
);
6788 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6789 result_dwo_abbrev_table
->get ());
6791 /* Read in the die, but leave space to copy over the attributes
6792 from the stub. This has the benefit of simplifying the rest of
6793 the code - all the work to maintain the illusion of a single
6794 DW_TAG_{compile,type}_unit DIE is done here. */
6795 num_extra_attrs
= ((stmt_list
!= NULL
)
6799 + (comp_dir
!= NULL
));
6800 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6803 /* Copy over the attributes from the stub to the DIE we just read in. */
6804 comp_unit_die
= *result_comp_unit_die
;
6805 i
= comp_unit_die
->num_attrs
;
6806 if (stmt_list
!= NULL
)
6807 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6809 comp_unit_die
->attrs
[i
++] = *low_pc
;
6810 if (high_pc
!= NULL
)
6811 comp_unit_die
->attrs
[i
++] = *high_pc
;
6813 comp_unit_die
->attrs
[i
++] = *ranges
;
6814 if (comp_dir
!= NULL
)
6815 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6816 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6818 if (dwarf_die_debug
)
6820 fprintf_unfiltered (gdb_stdlog
,
6821 "Read die from %s@0x%x of %s:\n",
6822 section
->get_name (),
6823 (unsigned) (begin_info_ptr
- section
->buffer
),
6824 bfd_get_filename (abfd
));
6825 dump_die (comp_unit_die
, dwarf_die_debug
);
6828 /* Skip dummy compilation units. */
6829 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6830 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6833 *result_info_ptr
= info_ptr
;
6837 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6838 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6839 signature is part of the header. */
6840 static gdb::optional
<ULONGEST
>
6841 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6843 if (cu
->header
.version
>= 5)
6844 return cu
->header
.signature
;
6845 struct attribute
*attr
;
6846 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6847 if (attr
== nullptr)
6848 return gdb::optional
<ULONGEST
> ();
6849 return DW_UNSND (attr
);
6852 /* Subroutine of cutu_reader to simplify it.
6853 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6854 Returns NULL if the specified DWO unit cannot be found. */
6856 static struct dwo_unit
*
6857 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6858 struct die_info
*comp_unit_die
,
6859 const char *dwo_name
)
6861 struct dwarf2_cu
*cu
= this_cu
->cu
;
6862 struct dwo_unit
*dwo_unit
;
6863 const char *comp_dir
;
6865 gdb_assert (cu
!= NULL
);
6867 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6868 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6869 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6871 if (this_cu
->is_debug_types
)
6873 struct signatured_type
*sig_type
;
6875 /* Since this_cu is the first member of struct signatured_type,
6876 we can go from a pointer to one to a pointer to the other. */
6877 sig_type
= (struct signatured_type
*) this_cu
;
6878 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6882 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6883 if (!signature
.has_value ())
6884 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6886 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6887 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6894 /* Subroutine of cutu_reader to simplify it.
6895 See it for a description of the parameters.
6896 Read a TU directly from a DWO file, bypassing the stub. */
6899 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6900 dwarf2_per_objfile
*per_objfile
,
6901 int use_existing_cu
)
6903 struct signatured_type
*sig_type
;
6905 /* Verify we can do the following downcast, and that we have the
6907 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6908 sig_type
= (struct signatured_type
*) this_cu
;
6909 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6911 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6913 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6914 /* There's no need to do the rereading_dwo_cu handling that
6915 cutu_reader does since we don't read the stub. */
6919 /* If !use_existing_cu, this_cu->cu must be NULL. */
6920 gdb_assert (this_cu
->cu
== NULL
);
6921 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6924 /* A future optimization, if needed, would be to use an existing
6925 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6926 could share abbrev tables. */
6928 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6929 NULL
/* stub_comp_unit_die */,
6930 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6933 &m_dwo_abbrev_table
) == 0)
6940 /* Initialize a CU (or TU) and read its DIEs.
6941 If the CU defers to a DWO file, read the DWO file as well.
6943 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6944 Otherwise the table specified in the comp unit header is read in and used.
6945 This is an optimization for when we already have the abbrev table.
6947 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6948 Otherwise, a new CU is allocated with xmalloc. */
6950 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6951 struct abbrev_table
*abbrev_table
,
6952 int use_existing_cu
,
6954 : die_reader_specs
{},
6957 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6958 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6959 struct dwarf2_section_info
*section
= this_cu
->section
;
6960 bfd
*abfd
= section
->get_bfd_owner ();
6961 struct dwarf2_cu
*cu
;
6962 const gdb_byte
*begin_info_ptr
;
6963 struct signatured_type
*sig_type
= NULL
;
6964 struct dwarf2_section_info
*abbrev_section
;
6965 /* Non-zero if CU currently points to a DWO file and we need to
6966 reread it. When this happens we need to reread the skeleton die
6967 before we can reread the DWO file (this only applies to CUs, not TUs). */
6968 int rereading_dwo_cu
= 0;
6970 if (dwarf_die_debug
)
6971 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6972 this_cu
->is_debug_types
? "type" : "comp",
6973 sect_offset_str (this_cu
->sect_off
));
6975 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6976 file (instead of going through the stub), short-circuit all of this. */
6977 if (this_cu
->reading_dwo_directly
)
6979 /* Narrow down the scope of possibilities to have to understand. */
6980 gdb_assert (this_cu
->is_debug_types
);
6981 gdb_assert (abbrev_table
== NULL
);
6982 init_tu_and_read_dwo_dies (this_cu
, dwarf2_per_objfile
, use_existing_cu
);
6986 /* This is cheap if the section is already read in. */
6987 section
->read (objfile
);
6989 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6991 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6993 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6996 /* If this CU is from a DWO file we need to start over, we need to
6997 refetch the attributes from the skeleton CU.
6998 This could be optimized by retrieving those attributes from when we
6999 were here the first time: the previous comp_unit_die was stored in
7000 comp_unit_obstack. But there's no data yet that we need this
7002 if (cu
->dwo_unit
!= NULL
)
7003 rereading_dwo_cu
= 1;
7007 /* If !use_existing_cu, this_cu->cu must be NULL. */
7008 gdb_assert (this_cu
->cu
== NULL
);
7009 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7010 cu
= m_new_cu
.get ();
7013 /* Get the header. */
7014 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7016 /* We already have the header, there's no need to read it in again. */
7017 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7021 if (this_cu
->is_debug_types
)
7023 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7024 &cu
->header
, section
,
7025 abbrev_section
, info_ptr
,
7028 /* Since per_cu is the first member of struct signatured_type,
7029 we can go from a pointer to one to a pointer to the other. */
7030 sig_type
= (struct signatured_type
*) this_cu
;
7031 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7032 gdb_assert (sig_type
->type_offset_in_tu
7033 == cu
->header
.type_cu_offset_in_tu
);
7034 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7036 /* LENGTH has not been set yet for type units if we're
7037 using .gdb_index. */
7038 this_cu
->length
= cu
->header
.get_length ();
7040 /* Establish the type offset that can be used to lookup the type. */
7041 sig_type
->type_offset_in_section
=
7042 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7044 this_cu
->dwarf_version
= cu
->header
.version
;
7048 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7049 &cu
->header
, section
,
7052 rcuh_kind::COMPILE
);
7054 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7055 if (this_cu
->length
== 0)
7056 this_cu
->length
= cu
->header
.get_length ();
7058 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7059 this_cu
->dwarf_version
= cu
->header
.version
;
7063 /* Skip dummy compilation units. */
7064 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7065 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7071 /* If we don't have them yet, read the abbrevs for this compilation unit.
7072 And if we need to read them now, make sure they're freed when we're
7074 if (abbrev_table
!= NULL
)
7075 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7078 m_abbrev_table_holder
7079 = abbrev_table::read (objfile
, abbrev_section
,
7080 cu
->header
.abbrev_sect_off
);
7081 abbrev_table
= m_abbrev_table_holder
.get ();
7084 /* Read the top level CU/TU die. */
7085 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7086 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7088 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7094 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7095 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7096 table from the DWO file and pass the ownership over to us. It will be
7097 referenced from READER, so we must make sure to free it after we're done
7100 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7101 DWO CU, that this test will fail (the attribute will not be present). */
7102 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7103 if (dwo_name
!= nullptr)
7105 struct dwo_unit
*dwo_unit
;
7106 struct die_info
*dwo_comp_unit_die
;
7108 if (comp_unit_die
->has_children
)
7110 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7111 " has children (offset %s) [in module %s]"),
7112 sect_offset_str (this_cu
->sect_off
),
7113 bfd_get_filename (abfd
));
7115 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
7116 if (dwo_unit
!= NULL
)
7118 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7119 comp_unit_die
, NULL
,
7122 &m_dwo_abbrev_table
) == 0)
7128 comp_unit_die
= dwo_comp_unit_die
;
7132 /* Yikes, we couldn't find the rest of the DIE, we only have
7133 the stub. A complaint has already been logged. There's
7134 not much more we can do except pass on the stub DIE to
7135 die_reader_func. We don't want to throw an error on bad
7142 cutu_reader::keep ()
7144 /* Done, clean up. */
7145 gdb_assert (!dummy_p
);
7146 if (m_new_cu
!= NULL
)
7148 struct dwarf2_per_objfile
*dwarf2_per_objfile
7149 = m_this_cu
->dwarf2_per_objfile
;
7150 /* Link this CU into read_in_chain. */
7151 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
7152 dwarf2_per_objfile
->per_bfd
->read_in_chain
= m_this_cu
;
7153 /* The chain owns it now. */
7154 m_new_cu
.release ();
7158 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7159 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7160 assumed to have already done the lookup to find the DWO file).
7162 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7163 THIS_CU->is_debug_types, but nothing else.
7165 We fill in THIS_CU->length.
7167 THIS_CU->cu is always freed when done.
7168 This is done in order to not leave THIS_CU->cu in a state where we have
7169 to care whether it refers to the "main" CU or the DWO CU.
7171 When parent_cu is passed, it is used to provide a default value for
7172 str_offsets_base and addr_base from the parent. */
7174 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7175 struct dwarf2_cu
*parent_cu
,
7176 struct dwo_file
*dwo_file
)
7177 : die_reader_specs
{},
7180 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7181 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7182 struct dwarf2_section_info
*section
= this_cu
->section
;
7183 bfd
*abfd
= section
->get_bfd_owner ();
7184 struct dwarf2_section_info
*abbrev_section
;
7185 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7187 if (dwarf_die_debug
)
7188 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7189 this_cu
->is_debug_types
? "type" : "comp",
7190 sect_offset_str (this_cu
->sect_off
));
7192 gdb_assert (this_cu
->cu
== NULL
);
7194 abbrev_section
= (dwo_file
!= NULL
7195 ? &dwo_file
->sections
.abbrev
7196 : get_abbrev_section_for_cu (this_cu
));
7198 /* This is cheap if the section is already read in. */
7199 section
->read (objfile
);
7201 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7203 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7204 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7205 &m_new_cu
->header
, section
,
7206 abbrev_section
, info_ptr
,
7207 (this_cu
->is_debug_types
7209 : rcuh_kind::COMPILE
));
7211 if (parent_cu
!= nullptr)
7213 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7214 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7216 this_cu
->length
= m_new_cu
->header
.get_length ();
7218 /* Skip dummy compilation units. */
7219 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7220 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7226 m_abbrev_table_holder
7227 = abbrev_table::read (objfile
, abbrev_section
,
7228 m_new_cu
->header
.abbrev_sect_off
);
7230 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7231 m_abbrev_table_holder
.get ());
7232 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7236 /* Type Unit Groups.
7238 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7239 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7240 so that all types coming from the same compilation (.o file) are grouped
7241 together. A future step could be to put the types in the same symtab as
7242 the CU the types ultimately came from. */
7245 hash_type_unit_group (const void *item
)
7247 const struct type_unit_group
*tu_group
7248 = (const struct type_unit_group
*) item
;
7250 return hash_stmt_list_entry (&tu_group
->hash
);
7254 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7256 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7257 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7259 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7262 /* Allocate a hash table for type unit groups. */
7265 allocate_type_unit_groups_table ()
7267 return htab_up (htab_create_alloc (3,
7268 hash_type_unit_group
,
7270 NULL
, xcalloc
, xfree
));
7273 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7274 partial symtabs. We combine several TUs per psymtab to not let the size
7275 of any one psymtab grow too big. */
7276 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7277 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7279 /* Helper routine for get_type_unit_group.
7280 Create the type_unit_group object used to hold one or more TUs. */
7282 static struct type_unit_group
*
7283 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7285 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7286 struct dwarf2_per_cu_data
*per_cu
;
7287 struct type_unit_group
*tu_group
;
7289 tu_group
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
7290 struct type_unit_group
);
7291 per_cu
= &tu_group
->per_cu
;
7292 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7294 if (dwarf2_per_objfile
->per_bfd
->using_index
)
7296 per_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
7297 struct dwarf2_per_cu_quick_data
);
7301 unsigned int line_offset
= to_underlying (line_offset_struct
);
7302 dwarf2_psymtab
*pst
;
7305 /* Give the symtab a useful name for debug purposes. */
7306 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7307 name
= string_printf ("<type_units_%d>",
7308 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7310 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7312 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7313 pst
->anonymous
= true;
7316 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7317 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7322 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7323 STMT_LIST is a DW_AT_stmt_list attribute. */
7325 static struct type_unit_group
*
7326 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7328 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7329 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7330 struct type_unit_group
*tu_group
;
7332 unsigned int line_offset
;
7333 struct type_unit_group type_unit_group_for_lookup
;
7335 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7336 dwarf2_per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7338 /* Do we need to create a new group, or can we use an existing one? */
7342 line_offset
= DW_UNSND (stmt_list
);
7343 ++tu_stats
->nr_symtab_sharers
;
7347 /* Ugh, no stmt_list. Rare, but we have to handle it.
7348 We can do various things here like create one group per TU or
7349 spread them over multiple groups to split up the expansion work.
7350 To avoid worst case scenarios (too many groups or too large groups)
7351 we, umm, group them in bunches. */
7352 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7353 | (tu_stats
->nr_stmt_less_type_units
7354 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7355 ++tu_stats
->nr_stmt_less_type_units
;
7358 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7359 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7360 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7361 &type_unit_group_for_lookup
, INSERT
);
7364 tu_group
= (struct type_unit_group
*) *slot
;
7365 gdb_assert (tu_group
!= NULL
);
7369 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7370 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7372 ++tu_stats
->nr_symtabs
;
7378 /* Partial symbol tables. */
7380 /* Create a psymtab named NAME and assign it to PER_CU.
7382 The caller must fill in the following details:
7383 dirname, textlow, texthigh. */
7385 static dwarf2_psymtab
*
7386 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7388 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7389 dwarf2_psymtab
*pst
;
7391 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7393 pst
->psymtabs_addrmap_supported
= true;
7395 /* This is the glue that links PST into GDB's symbol API. */
7396 per_cu
->v
.psymtab
= pst
;
7401 /* DIE reader function for process_psymtab_comp_unit. */
7404 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7405 const gdb_byte
*info_ptr
,
7406 struct die_info
*comp_unit_die
,
7407 enum language pretend_language
)
7409 struct dwarf2_cu
*cu
= reader
->cu
;
7410 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
7411 struct gdbarch
*gdbarch
= objfile
->arch ();
7412 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7414 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7415 dwarf2_psymtab
*pst
;
7416 enum pc_bounds_kind cu_bounds_kind
;
7417 const char *filename
;
7419 gdb_assert (! per_cu
->is_debug_types
);
7421 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7423 /* Allocate a new partial symbol table structure. */
7424 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7425 static const char artificial
[] = "<artificial>";
7426 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7427 if (filename
== NULL
)
7429 else if (strcmp (filename
, artificial
) == 0)
7431 debug_filename
.reset (concat (artificial
, "@",
7432 sect_offset_str (per_cu
->sect_off
),
7434 filename
= debug_filename
.get ();
7437 pst
= create_partial_symtab (per_cu
, filename
);
7439 /* This must be done before calling dwarf2_build_include_psymtabs. */
7440 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7442 baseaddr
= objfile
->text_section_offset ();
7444 dwarf2_find_base_address (comp_unit_die
, cu
);
7446 /* Possibly set the default values of LOWPC and HIGHPC from
7448 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7449 &best_highpc
, cu
, pst
);
7450 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7453 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7456 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7458 /* Store the contiguous range if it is not empty; it can be
7459 empty for CUs with no code. */
7460 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7464 /* Check if comp unit has_children.
7465 If so, read the rest of the partial symbols from this comp unit.
7466 If not, there's no more debug_info for this comp unit. */
7467 if (comp_unit_die
->has_children
)
7469 struct partial_die_info
*first_die
;
7470 CORE_ADDR lowpc
, highpc
;
7472 lowpc
= ((CORE_ADDR
) -1);
7473 highpc
= ((CORE_ADDR
) 0);
7475 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7477 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7478 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7480 /* If we didn't find a lowpc, set it to highpc to avoid
7481 complaints from `maint check'. */
7482 if (lowpc
== ((CORE_ADDR
) -1))
7485 /* If the compilation unit didn't have an explicit address range,
7486 then use the information extracted from its child dies. */
7487 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7490 best_highpc
= highpc
;
7493 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7494 best_lowpc
+ baseaddr
)
7496 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7497 best_highpc
+ baseaddr
)
7500 end_psymtab_common (objfile
, pst
);
7502 if (!cu
->per_cu
->imported_symtabs_empty ())
7505 int len
= cu
->per_cu
->imported_symtabs_size ();
7507 /* Fill in 'dependencies' here; we fill in 'users' in a
7509 pst
->number_of_dependencies
= len
;
7511 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7512 for (i
= 0; i
< len
; ++i
)
7514 pst
->dependencies
[i
]
7515 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7518 cu
->per_cu
->imported_symtabs_free ();
7521 /* Get the list of files included in the current compilation unit,
7522 and build a psymtab for each of them. */
7523 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7525 if (dwarf_read_debug
)
7526 fprintf_unfiltered (gdb_stdlog
,
7527 "Psymtab for %s unit @%s: %s - %s"
7528 ", %d global, %d static syms\n",
7529 per_cu
->is_debug_types
? "type" : "comp",
7530 sect_offset_str (per_cu
->sect_off
),
7531 paddress (gdbarch
, pst
->text_low (objfile
)),
7532 paddress (gdbarch
, pst
->text_high (objfile
)),
7533 pst
->n_global_syms
, pst
->n_static_syms
);
7536 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7537 Process compilation unit THIS_CU for a psymtab. */
7540 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7541 bool want_partial_unit
,
7542 enum language pretend_language
)
7544 /* If this compilation unit was already read in, free the
7545 cached copy in order to read it in again. This is
7546 necessary because we skipped some symbols when we first
7547 read in the compilation unit (see load_partial_dies).
7548 This problem could be avoided, but the benefit is unclear. */
7549 if (this_cu
->cu
!= NULL
)
7550 free_one_cached_comp_unit (this_cu
);
7552 cutu_reader
reader (this_cu
, NULL
, 0, false);
7554 switch (reader
.comp_unit_die
->tag
)
7556 case DW_TAG_compile_unit
:
7557 this_cu
->unit_type
= DW_UT_compile
;
7559 case DW_TAG_partial_unit
:
7560 this_cu
->unit_type
= DW_UT_partial
;
7570 else if (this_cu
->is_debug_types
)
7571 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7572 reader
.comp_unit_die
);
7573 else if (want_partial_unit
7574 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7575 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7576 reader
.comp_unit_die
,
7579 this_cu
->lang
= this_cu
->cu
->language
;
7581 /* Age out any secondary CUs. */
7582 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7585 /* Reader function for build_type_psymtabs. */
7588 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7589 const gdb_byte
*info_ptr
,
7590 struct die_info
*type_unit_die
)
7592 struct dwarf2_per_objfile
*dwarf2_per_objfile
= reader
->cu
->per_objfile
;
7593 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7594 struct dwarf2_cu
*cu
= reader
->cu
;
7595 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7596 struct signatured_type
*sig_type
;
7597 struct type_unit_group
*tu_group
;
7598 struct attribute
*attr
;
7599 struct partial_die_info
*first_die
;
7600 CORE_ADDR lowpc
, highpc
;
7601 dwarf2_psymtab
*pst
;
7603 gdb_assert (per_cu
->is_debug_types
);
7604 sig_type
= (struct signatured_type
*) per_cu
;
7606 if (! type_unit_die
->has_children
)
7609 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7610 tu_group
= get_type_unit_group (cu
, attr
);
7612 if (tu_group
->tus
== nullptr)
7613 tu_group
->tus
= new std::vector
<signatured_type
*>;
7614 tu_group
->tus
->push_back (sig_type
);
7616 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7617 pst
= create_partial_symtab (per_cu
, "");
7618 pst
->anonymous
= true;
7620 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7622 lowpc
= (CORE_ADDR
) -1;
7623 highpc
= (CORE_ADDR
) 0;
7624 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7626 end_psymtab_common (objfile
, pst
);
7629 /* Struct used to sort TUs by their abbreviation table offset. */
7631 struct tu_abbrev_offset
7633 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7634 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7637 signatured_type
*sig_type
;
7638 sect_offset abbrev_offset
;
7641 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7644 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7645 const struct tu_abbrev_offset
&b
)
7647 return a
.abbrev_offset
< b
.abbrev_offset
;
7650 /* Efficiently read all the type units.
7651 This does the bulk of the work for build_type_psymtabs.
7653 The efficiency is because we sort TUs by the abbrev table they use and
7654 only read each abbrev table once. In one program there are 200K TUs
7655 sharing 8K abbrev tables.
7657 The main purpose of this function is to support building the
7658 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7659 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7660 can collapse the search space by grouping them by stmt_list.
7661 The savings can be significant, in the same program from above the 200K TUs
7662 share 8K stmt_list tables.
7664 FUNC is expected to call get_type_unit_group, which will create the
7665 struct type_unit_group if necessary and add it to
7666 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7669 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7671 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7672 abbrev_table_up abbrev_table
;
7673 sect_offset abbrev_offset
;
7675 /* It's up to the caller to not call us multiple times. */
7676 gdb_assert (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7678 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ())
7681 /* TUs typically share abbrev tables, and there can be way more TUs than
7682 abbrev tables. Sort by abbrev table to reduce the number of times we
7683 read each abbrev table in.
7684 Alternatives are to punt or to maintain a cache of abbrev tables.
7685 This is simpler and efficient enough for now.
7687 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7688 symtab to use). Typically TUs with the same abbrev offset have the same
7689 stmt_list value too so in practice this should work well.
7691 The basic algorithm here is:
7693 sort TUs by abbrev table
7694 for each TU with same abbrev table:
7695 read abbrev table if first user
7696 read TU top level DIE
7697 [IWBN if DWO skeletons had DW_AT_stmt_list]
7700 if (dwarf_read_debug
)
7701 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7703 /* Sort in a separate table to maintain the order of all_type_units
7704 for .gdb_index: TU indices directly index all_type_units. */
7705 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7706 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7708 for (signatured_type
*sig_type
: dwarf2_per_objfile
->per_bfd
->all_type_units
)
7709 sorted_by_abbrev
.emplace_back
7710 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7711 sig_type
->per_cu
.section
,
7712 sig_type
->per_cu
.sect_off
));
7714 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7715 sort_tu_by_abbrev_offset
);
7717 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7719 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7721 /* Switch to the next abbrev table if necessary. */
7722 if (abbrev_table
== NULL
7723 || tu
.abbrev_offset
!= abbrev_offset
)
7725 abbrev_offset
= tu
.abbrev_offset
;
7727 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7728 &dwarf2_per_objfile
->per_bfd
->abbrev
,
7730 ++tu_stats
->nr_uniq_abbrev_tables
;
7733 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7735 if (!reader
.dummy_p
)
7736 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7737 reader
.comp_unit_die
);
7741 /* Print collected type unit statistics. */
7744 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7746 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7748 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7749 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7750 dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7751 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7752 tu_stats
->nr_uniq_abbrev_tables
);
7753 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7754 tu_stats
->nr_symtabs
);
7755 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7756 tu_stats
->nr_symtab_sharers
);
7757 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7758 tu_stats
->nr_stmt_less_type_units
);
7759 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7760 tu_stats
->nr_all_type_units_reallocs
);
7763 /* Traversal function for build_type_psymtabs. */
7766 build_type_psymtab_dependencies (void **slot
, void *info
)
7768 struct dwarf2_per_objfile
*dwarf2_per_objfile
7769 = (struct dwarf2_per_objfile
*) info
;
7770 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7771 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7772 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7773 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7774 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7777 gdb_assert (len
> 0);
7778 gdb_assert (per_cu
->type_unit_group_p ());
7780 pst
->number_of_dependencies
= len
;
7781 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7782 for (i
= 0; i
< len
; ++i
)
7784 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7785 gdb_assert (iter
->per_cu
.is_debug_types
);
7786 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7787 iter
->type_unit_group
= tu_group
;
7790 delete tu_group
->tus
;
7791 tu_group
->tus
= nullptr;
7796 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7797 Build partial symbol tables for the .debug_types comp-units. */
7800 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7802 if (! create_all_type_units (dwarf2_per_objfile
))
7805 build_type_psymtabs_1 (dwarf2_per_objfile
);
7808 /* Traversal function for process_skeletonless_type_unit.
7809 Read a TU in a DWO file and build partial symbols for it. */
7812 process_skeletonless_type_unit (void **slot
, void *info
)
7814 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7815 struct dwarf2_per_objfile
*dwarf2_per_objfile
7816 = (struct dwarf2_per_objfile
*) info
;
7817 struct signatured_type find_entry
, *entry
;
7819 /* If this TU doesn't exist in the global table, add it and read it in. */
7821 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
7822 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7824 find_entry
.signature
= dwo_unit
->signature
;
7825 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
7826 &find_entry
, INSERT
);
7827 /* If we've already seen this type there's nothing to do. What's happening
7828 is we're doing our own version of comdat-folding here. */
7832 /* This does the job that create_all_type_units would have done for
7834 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7835 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7838 /* This does the job that build_type_psymtabs_1 would have done. */
7839 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7840 if (!reader
.dummy_p
)
7841 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7842 reader
.comp_unit_die
);
7847 /* Traversal function for process_skeletonless_type_units. */
7850 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7852 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7854 if (dwo_file
->tus
!= NULL
)
7855 htab_traverse_noresize (dwo_file
->tus
.get (),
7856 process_skeletonless_type_unit
, info
);
7861 /* Scan all TUs of DWO files, verifying we've processed them.
7862 This is needed in case a TU was emitted without its skeleton.
7863 Note: This can't be done until we know what all the DWO files are. */
7866 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7868 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7869 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7870 && dwarf2_per_objfile
->per_bfd
->dwo_files
!= NULL
)
7872 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (),
7873 process_dwo_file_for_skeletonless_type_units
,
7874 dwarf2_per_objfile
);
7878 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7881 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7883 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7885 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7890 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7892 /* Set the 'user' field only if it is not already set. */
7893 if (pst
->dependencies
[j
]->user
== NULL
)
7894 pst
->dependencies
[j
]->user
= pst
;
7899 /* Build the partial symbol table by doing a quick pass through the
7900 .debug_info and .debug_abbrev sections. */
7903 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7905 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7907 if (dwarf_read_debug
)
7909 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7910 objfile_name (objfile
));
7913 scoped_restore restore_reading_psyms
7914 = make_scoped_restore (&dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
,
7917 dwarf2_per_objfile
->per_bfd
->info
.read (objfile
);
7919 /* Any cached compilation units will be linked by the per-objfile
7920 read_in_chain. Make sure to free them when we're done. */
7921 free_cached_comp_units
freer (dwarf2_per_objfile
);
7923 build_type_psymtabs (dwarf2_per_objfile
);
7925 create_all_comp_units (dwarf2_per_objfile
);
7927 /* Create a temporary address map on a temporary obstack. We later
7928 copy this to the final obstack. */
7929 auto_obstack temp_obstack
;
7931 scoped_restore save_psymtabs_addrmap
7932 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7933 addrmap_create_mutable (&temp_obstack
));
7935 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7937 if (per_cu
->v
.psymtab
!= NULL
)
7938 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7940 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7943 /* This has to wait until we read the CUs, we need the list of DWOs. */
7944 process_skeletonless_type_units (dwarf2_per_objfile
);
7946 /* Now that all TUs have been processed we can fill in the dependencies. */
7947 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
7949 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7950 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7953 if (dwarf_read_debug
)
7954 print_tu_stats (dwarf2_per_objfile
);
7956 set_partial_user (dwarf2_per_objfile
);
7958 objfile
->partial_symtabs
->psymtabs_addrmap
7959 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7960 objfile
->partial_symtabs
->obstack ());
7961 /* At this point we want to keep the address map. */
7962 save_psymtabs_addrmap
.release ();
7964 if (dwarf_read_debug
)
7965 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7966 objfile_name (objfile
));
7969 /* Load the partial DIEs for a secondary CU into memory.
7970 This is also used when rereading a primary CU with load_all_dies. */
7973 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7975 cutu_reader
reader (this_cu
, NULL
, 1, false);
7977 if (!reader
.dummy_p
)
7979 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7982 /* Check if comp unit has_children.
7983 If so, read the rest of the partial symbols from this comp unit.
7984 If not, there's no more debug_info for this comp unit. */
7985 if (reader
.comp_unit_die
->has_children
)
7986 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7993 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7994 struct dwarf2_section_info
*section
,
7995 struct dwarf2_section_info
*abbrev_section
,
7996 unsigned int is_dwz
)
7998 const gdb_byte
*info_ptr
;
7999 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8001 if (dwarf_read_debug
)
8002 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8003 section
->get_name (),
8004 section
->get_file_name ());
8006 section
->read (objfile
);
8008 info_ptr
= section
->buffer
;
8010 while (info_ptr
< section
->buffer
+ section
->size
)
8012 struct dwarf2_per_cu_data
*this_cu
;
8014 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8016 comp_unit_head cu_header
;
8017 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8018 abbrev_section
, info_ptr
,
8019 rcuh_kind::COMPILE
);
8021 /* Save the compilation unit for later lookup. */
8022 if (cu_header
.unit_type
!= DW_UT_type
)
8023 this_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
8026 auto sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
8027 sig_type
->signature
= cu_header
.signature
;
8028 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8029 this_cu
= &sig_type
->per_cu
;
8031 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8032 this_cu
->sect_off
= sect_off
;
8033 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8034 this_cu
->is_dwz
= is_dwz
;
8035 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8036 this_cu
->section
= section
;
8038 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8040 info_ptr
= info_ptr
+ this_cu
->length
;
8044 /* Create a list of all compilation units in OBJFILE.
8045 This is only done for -readnow and building partial symtabs. */
8048 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8050 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
8051 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->per_bfd
->info
,
8052 &dwarf2_per_objfile
->per_bfd
->abbrev
, 0);
8054 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8056 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8060 /* Process all loaded DIEs for compilation unit CU, starting at
8061 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8062 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8063 DW_AT_ranges). See the comments of add_partial_subprogram on how
8064 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8067 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8068 CORE_ADDR
*highpc
, int set_addrmap
,
8069 struct dwarf2_cu
*cu
)
8071 struct partial_die_info
*pdi
;
8073 /* Now, march along the PDI's, descending into ones which have
8074 interesting children but skipping the children of the other ones,
8075 until we reach the end of the compilation unit. */
8083 /* Anonymous namespaces or modules have no name but have interesting
8084 children, so we need to look at them. Ditto for anonymous
8087 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8088 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8089 || pdi
->tag
== DW_TAG_imported_unit
8090 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8094 case DW_TAG_subprogram
:
8095 case DW_TAG_inlined_subroutine
:
8096 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8098 case DW_TAG_constant
:
8099 case DW_TAG_variable
:
8100 case DW_TAG_typedef
:
8101 case DW_TAG_union_type
:
8102 if (!pdi
->is_declaration
8103 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8105 add_partial_symbol (pdi
, cu
);
8108 case DW_TAG_class_type
:
8109 case DW_TAG_interface_type
:
8110 case DW_TAG_structure_type
:
8111 if (!pdi
->is_declaration
)
8113 add_partial_symbol (pdi
, cu
);
8115 if ((cu
->language
== language_rust
8116 || cu
->language
== language_cplus
) && pdi
->has_children
)
8117 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8120 case DW_TAG_enumeration_type
:
8121 if (!pdi
->is_declaration
)
8122 add_partial_enumeration (pdi
, cu
);
8124 case DW_TAG_base_type
:
8125 case DW_TAG_subrange_type
:
8126 /* File scope base type definitions are added to the partial
8128 add_partial_symbol (pdi
, cu
);
8130 case DW_TAG_namespace
:
8131 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8134 if (!pdi
->is_declaration
)
8135 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8137 case DW_TAG_imported_unit
:
8139 struct dwarf2_per_cu_data
*per_cu
;
8141 /* For now we don't handle imported units in type units. */
8142 if (cu
->per_cu
->is_debug_types
)
8144 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8145 " supported in type units [in module %s]"),
8146 objfile_name (cu
->per_objfile
->objfile
));
8149 per_cu
= dwarf2_find_containing_comp_unit
8150 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8152 /* Go read the partial unit, if needed. */
8153 if (per_cu
->v
.psymtab
== NULL
)
8154 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
8156 cu
->per_cu
->imported_symtabs_push (per_cu
);
8159 case DW_TAG_imported_declaration
:
8160 add_partial_symbol (pdi
, cu
);
8167 /* If the die has a sibling, skip to the sibling. */
8169 pdi
= pdi
->die_sibling
;
8173 /* Functions used to compute the fully scoped name of a partial DIE.
8175 Normally, this is simple. For C++, the parent DIE's fully scoped
8176 name is concatenated with "::" and the partial DIE's name.
8177 Enumerators are an exception; they use the scope of their parent
8178 enumeration type, i.e. the name of the enumeration type is not
8179 prepended to the enumerator.
8181 There are two complexities. One is DW_AT_specification; in this
8182 case "parent" means the parent of the target of the specification,
8183 instead of the direct parent of the DIE. The other is compilers
8184 which do not emit DW_TAG_namespace; in this case we try to guess
8185 the fully qualified name of structure types from their members'
8186 linkage names. This must be done using the DIE's children rather
8187 than the children of any DW_AT_specification target. We only need
8188 to do this for structures at the top level, i.e. if the target of
8189 any DW_AT_specification (if any; otherwise the DIE itself) does not
8192 /* Compute the scope prefix associated with PDI's parent, in
8193 compilation unit CU. The result will be allocated on CU's
8194 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8195 field. NULL is returned if no prefix is necessary. */
8197 partial_die_parent_scope (struct partial_die_info
*pdi
,
8198 struct dwarf2_cu
*cu
)
8200 const char *grandparent_scope
;
8201 struct partial_die_info
*parent
, *real_pdi
;
8203 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8204 then this means the parent of the specification DIE. */
8207 while (real_pdi
->has_specification
)
8209 auto res
= find_partial_die (real_pdi
->spec_offset
,
8210 real_pdi
->spec_is_dwz
, cu
);
8215 parent
= real_pdi
->die_parent
;
8219 if (parent
->scope_set
)
8220 return parent
->scope
;
8224 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8226 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8227 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8228 Work around this problem here. */
8229 if (cu
->language
== language_cplus
8230 && parent
->tag
== DW_TAG_namespace
8231 && strcmp (parent
->name
, "::") == 0
8232 && grandparent_scope
== NULL
)
8234 parent
->scope
= NULL
;
8235 parent
->scope_set
= 1;
8239 /* Nested subroutines in Fortran get a prefix. */
8240 if (pdi
->tag
== DW_TAG_enumerator
)
8241 /* Enumerators should not get the name of the enumeration as a prefix. */
8242 parent
->scope
= grandparent_scope
;
8243 else if (parent
->tag
== DW_TAG_namespace
8244 || parent
->tag
== DW_TAG_module
8245 || parent
->tag
== DW_TAG_structure_type
8246 || parent
->tag
== DW_TAG_class_type
8247 || parent
->tag
== DW_TAG_interface_type
8248 || parent
->tag
== DW_TAG_union_type
8249 || parent
->tag
== DW_TAG_enumeration_type
8250 || (cu
->language
== language_fortran
8251 && parent
->tag
== DW_TAG_subprogram
8252 && pdi
->tag
== DW_TAG_subprogram
))
8254 if (grandparent_scope
== NULL
)
8255 parent
->scope
= parent
->name
;
8257 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8259 parent
->name
, 0, cu
);
8263 /* FIXME drow/2004-04-01: What should we be doing with
8264 function-local names? For partial symbols, we should probably be
8266 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8267 dwarf_tag_name (parent
->tag
),
8268 sect_offset_str (pdi
->sect_off
));
8269 parent
->scope
= grandparent_scope
;
8272 parent
->scope_set
= 1;
8273 return parent
->scope
;
8276 /* Return the fully scoped name associated with PDI, from compilation unit
8277 CU. The result will be allocated with malloc. */
8279 static gdb::unique_xmalloc_ptr
<char>
8280 partial_die_full_name (struct partial_die_info
*pdi
,
8281 struct dwarf2_cu
*cu
)
8283 const char *parent_scope
;
8285 /* If this is a template instantiation, we can not work out the
8286 template arguments from partial DIEs. So, unfortunately, we have
8287 to go through the full DIEs. At least any work we do building
8288 types here will be reused if full symbols are loaded later. */
8289 if (pdi
->has_template_arguments
)
8293 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8295 struct die_info
*die
;
8296 struct attribute attr
;
8297 struct dwarf2_cu
*ref_cu
= cu
;
8299 /* DW_FORM_ref_addr is using section offset. */
8300 attr
.name
= (enum dwarf_attribute
) 0;
8301 attr
.form
= DW_FORM_ref_addr
;
8302 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8303 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8305 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8309 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8310 if (parent_scope
== NULL
)
8313 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8318 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8320 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
8321 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8322 struct gdbarch
*gdbarch
= objfile
->arch ();
8324 const char *actual_name
= NULL
;
8327 baseaddr
= objfile
->text_section_offset ();
8329 gdb::unique_xmalloc_ptr
<char> built_actual_name
8330 = partial_die_full_name (pdi
, cu
);
8331 if (built_actual_name
!= NULL
)
8332 actual_name
= built_actual_name
.get ();
8334 if (actual_name
== NULL
)
8335 actual_name
= pdi
->name
;
8337 partial_symbol psymbol
;
8338 memset (&psymbol
, 0, sizeof (psymbol
));
8339 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8340 psymbol
.ginfo
.section
= -1;
8342 /* The code below indicates that the psymbol should be installed by
8344 gdb::optional
<psymbol_placement
> where
;
8348 case DW_TAG_inlined_subroutine
:
8349 case DW_TAG_subprogram
:
8350 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8352 if (pdi
->is_external
8353 || cu
->language
== language_ada
8354 || (cu
->language
== language_fortran
8355 && pdi
->die_parent
!= NULL
8356 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8358 /* Normally, only "external" DIEs are part of the global scope.
8359 But in Ada and Fortran, we want to be able to access nested
8360 procedures globally. So all Ada and Fortran subprograms are
8361 stored in the global scope. */
8362 where
= psymbol_placement::GLOBAL
;
8365 where
= psymbol_placement::STATIC
;
8367 psymbol
.domain
= VAR_DOMAIN
;
8368 psymbol
.aclass
= LOC_BLOCK
;
8369 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8370 psymbol
.ginfo
.value
.address
= addr
;
8372 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8373 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8375 case DW_TAG_constant
:
8376 psymbol
.domain
= VAR_DOMAIN
;
8377 psymbol
.aclass
= LOC_STATIC
;
8378 where
= (pdi
->is_external
8379 ? psymbol_placement::GLOBAL
8380 : psymbol_placement::STATIC
);
8382 case DW_TAG_variable
:
8384 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8388 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
8390 /* A global or static variable may also have been stripped
8391 out by the linker if unused, in which case its address
8392 will be nullified; do not add such variables into partial
8393 symbol table then. */
8395 else if (pdi
->is_external
)
8398 Don't enter into the minimal symbol tables as there is
8399 a minimal symbol table entry from the ELF symbols already.
8400 Enter into partial symbol table if it has a location
8401 descriptor or a type.
8402 If the location descriptor is missing, new_symbol will create
8403 a LOC_UNRESOLVED symbol, the address of the variable will then
8404 be determined from the minimal symbol table whenever the variable
8406 The address for the partial symbol table entry is not
8407 used by GDB, but it comes in handy for debugging partial symbol
8410 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8412 psymbol
.domain
= VAR_DOMAIN
;
8413 psymbol
.aclass
= LOC_STATIC
;
8414 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8415 psymbol
.ginfo
.value
.address
= addr
;
8416 where
= psymbol_placement::GLOBAL
;
8421 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8423 /* Static Variable. Skip symbols whose value we cannot know (those
8424 without location descriptors or constant values). */
8425 if (!has_loc
&& !pdi
->has_const_value
)
8428 psymbol
.domain
= VAR_DOMAIN
;
8429 psymbol
.aclass
= LOC_STATIC
;
8430 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8432 psymbol
.ginfo
.value
.address
= addr
;
8433 where
= psymbol_placement::STATIC
;
8436 case DW_TAG_typedef
:
8437 case DW_TAG_base_type
:
8438 case DW_TAG_subrange_type
:
8439 psymbol
.domain
= VAR_DOMAIN
;
8440 psymbol
.aclass
= LOC_TYPEDEF
;
8441 where
= psymbol_placement::STATIC
;
8443 case DW_TAG_imported_declaration
:
8444 case DW_TAG_namespace
:
8445 psymbol
.domain
= VAR_DOMAIN
;
8446 psymbol
.aclass
= LOC_TYPEDEF
;
8447 where
= psymbol_placement::GLOBAL
;
8450 /* With Fortran 77 there might be a "BLOCK DATA" module
8451 available without any name. If so, we skip the module as it
8452 doesn't bring any value. */
8453 if (actual_name
!= nullptr)
8455 psymbol
.domain
= MODULE_DOMAIN
;
8456 psymbol
.aclass
= LOC_TYPEDEF
;
8457 where
= psymbol_placement::GLOBAL
;
8460 case DW_TAG_class_type
:
8461 case DW_TAG_interface_type
:
8462 case DW_TAG_structure_type
:
8463 case DW_TAG_union_type
:
8464 case DW_TAG_enumeration_type
:
8465 /* Skip external references. The DWARF standard says in the section
8466 about "Structure, Union, and Class Type Entries": "An incomplete
8467 structure, union or class type is represented by a structure,
8468 union or class entry that does not have a byte size attribute
8469 and that has a DW_AT_declaration attribute." */
8470 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8473 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8474 static vs. global. */
8475 psymbol
.domain
= STRUCT_DOMAIN
;
8476 psymbol
.aclass
= LOC_TYPEDEF
;
8477 where
= (cu
->language
== language_cplus
8478 ? psymbol_placement::GLOBAL
8479 : psymbol_placement::STATIC
);
8481 case DW_TAG_enumerator
:
8482 psymbol
.domain
= VAR_DOMAIN
;
8483 psymbol
.aclass
= LOC_CONST
;
8484 where
= (cu
->language
== language_cplus
8485 ? psymbol_placement::GLOBAL
8486 : psymbol_placement::STATIC
);
8492 if (where
.has_value ())
8494 if (built_actual_name
!= nullptr)
8495 actual_name
= objfile
->intern (actual_name
);
8496 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8497 psymbol
.ginfo
.set_linkage_name (actual_name
);
8500 psymbol
.ginfo
.set_demangled_name (actual_name
,
8501 &objfile
->objfile_obstack
);
8502 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8504 add_psymbol_to_list (psymbol
, *where
, objfile
);
8508 /* Read a partial die corresponding to a namespace; also, add a symbol
8509 corresponding to that namespace to the symbol table. NAMESPACE is
8510 the name of the enclosing namespace. */
8513 add_partial_namespace (struct partial_die_info
*pdi
,
8514 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8515 int set_addrmap
, struct dwarf2_cu
*cu
)
8517 /* Add a symbol for the namespace. */
8519 add_partial_symbol (pdi
, cu
);
8521 /* Now scan partial symbols in that namespace. */
8523 if (pdi
->has_children
)
8524 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8527 /* Read a partial die corresponding to a Fortran module. */
8530 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8531 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8533 /* Add a symbol for the namespace. */
8535 add_partial_symbol (pdi
, cu
);
8537 /* Now scan partial symbols in that module. */
8539 if (pdi
->has_children
)
8540 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8543 /* Read a partial die corresponding to a subprogram or an inlined
8544 subprogram and create a partial symbol for that subprogram.
8545 When the CU language allows it, this routine also defines a partial
8546 symbol for each nested subprogram that this subprogram contains.
8547 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8548 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8550 PDI may also be a lexical block, in which case we simply search
8551 recursively for subprograms defined inside that lexical block.
8552 Again, this is only performed when the CU language allows this
8553 type of definitions. */
8556 add_partial_subprogram (struct partial_die_info
*pdi
,
8557 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8558 int set_addrmap
, struct dwarf2_cu
*cu
)
8560 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8562 if (pdi
->has_pc_info
)
8564 if (pdi
->lowpc
< *lowpc
)
8565 *lowpc
= pdi
->lowpc
;
8566 if (pdi
->highpc
> *highpc
)
8567 *highpc
= pdi
->highpc
;
8570 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8571 struct gdbarch
*gdbarch
= objfile
->arch ();
8573 CORE_ADDR this_highpc
;
8574 CORE_ADDR this_lowpc
;
8576 baseaddr
= objfile
->text_section_offset ();
8578 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8579 pdi
->lowpc
+ baseaddr
)
8582 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8583 pdi
->highpc
+ baseaddr
)
8585 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8586 this_lowpc
, this_highpc
- 1,
8587 cu
->per_cu
->v
.psymtab
);
8591 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8593 if (!pdi
->is_declaration
)
8594 /* Ignore subprogram DIEs that do not have a name, they are
8595 illegal. Do not emit a complaint at this point, we will
8596 do so when we convert this psymtab into a symtab. */
8598 add_partial_symbol (pdi
, cu
);
8602 if (! pdi
->has_children
)
8605 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8607 pdi
= pdi
->die_child
;
8611 if (pdi
->tag
== DW_TAG_subprogram
8612 || pdi
->tag
== DW_TAG_inlined_subroutine
8613 || pdi
->tag
== DW_TAG_lexical_block
)
8614 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8615 pdi
= pdi
->die_sibling
;
8620 /* Read a partial die corresponding to an enumeration type. */
8623 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8624 struct dwarf2_cu
*cu
)
8626 struct partial_die_info
*pdi
;
8628 if (enum_pdi
->name
!= NULL
)
8629 add_partial_symbol (enum_pdi
, cu
);
8631 pdi
= enum_pdi
->die_child
;
8634 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8635 complaint (_("malformed enumerator DIE ignored"));
8637 add_partial_symbol (pdi
, cu
);
8638 pdi
= pdi
->die_sibling
;
8642 /* Return the initial uleb128 in the die at INFO_PTR. */
8645 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8647 unsigned int bytes_read
;
8649 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8652 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8653 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8655 Return the corresponding abbrev, or NULL if the number is zero (indicating
8656 an empty DIE). In either case *BYTES_READ will be set to the length of
8657 the initial number. */
8659 static struct abbrev_info
*
8660 peek_die_abbrev (const die_reader_specs
&reader
,
8661 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8663 dwarf2_cu
*cu
= reader
.cu
;
8664 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8665 unsigned int abbrev_number
8666 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8668 if (abbrev_number
== 0)
8671 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8674 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8675 " at offset %s [in module %s]"),
8676 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8677 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8683 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8684 Returns a pointer to the end of a series of DIEs, terminated by an empty
8685 DIE. Any children of the skipped DIEs will also be skipped. */
8687 static const gdb_byte
*
8688 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8692 unsigned int bytes_read
;
8693 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8696 return info_ptr
+ bytes_read
;
8698 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8702 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8703 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8704 abbrev corresponding to that skipped uleb128 should be passed in
8705 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8708 static const gdb_byte
*
8709 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8710 struct abbrev_info
*abbrev
)
8712 unsigned int bytes_read
;
8713 struct attribute attr
;
8714 bfd
*abfd
= reader
->abfd
;
8715 struct dwarf2_cu
*cu
= reader
->cu
;
8716 const gdb_byte
*buffer
= reader
->buffer
;
8717 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8718 unsigned int form
, i
;
8720 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8722 /* The only abbrev we care about is DW_AT_sibling. */
8723 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8726 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8728 if (attr
.form
== DW_FORM_ref_addr
)
8729 complaint (_("ignoring absolute DW_AT_sibling"));
8732 sect_offset off
= attr
.get_ref_die_offset ();
8733 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8735 if (sibling_ptr
< info_ptr
)
8736 complaint (_("DW_AT_sibling points backwards"));
8737 else if (sibling_ptr
> reader
->buffer_end
)
8738 reader
->die_section
->overflow_complaint ();
8744 /* If it isn't DW_AT_sibling, skip this attribute. */
8745 form
= abbrev
->attrs
[i
].form
;
8749 case DW_FORM_ref_addr
:
8750 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8751 and later it is offset sized. */
8752 if (cu
->header
.version
== 2)
8753 info_ptr
+= cu
->header
.addr_size
;
8755 info_ptr
+= cu
->header
.offset_size
;
8757 case DW_FORM_GNU_ref_alt
:
8758 info_ptr
+= cu
->header
.offset_size
;
8761 info_ptr
+= cu
->header
.addr_size
;
8769 case DW_FORM_flag_present
:
8770 case DW_FORM_implicit_const
:
8787 case DW_FORM_ref_sig8
:
8790 case DW_FORM_data16
:
8793 case DW_FORM_string
:
8794 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8795 info_ptr
+= bytes_read
;
8797 case DW_FORM_sec_offset
:
8799 case DW_FORM_GNU_strp_alt
:
8800 info_ptr
+= cu
->header
.offset_size
;
8802 case DW_FORM_exprloc
:
8804 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8805 info_ptr
+= bytes_read
;
8807 case DW_FORM_block1
:
8808 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8810 case DW_FORM_block2
:
8811 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8813 case DW_FORM_block4
:
8814 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8820 case DW_FORM_ref_udata
:
8821 case DW_FORM_GNU_addr_index
:
8822 case DW_FORM_GNU_str_index
:
8823 case DW_FORM_rnglistx
:
8824 case DW_FORM_loclistx
:
8825 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8827 case DW_FORM_indirect
:
8828 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8829 info_ptr
+= bytes_read
;
8830 /* We need to continue parsing from here, so just go back to
8832 goto skip_attribute
;
8835 error (_("Dwarf Error: Cannot handle %s "
8836 "in DWARF reader [in module %s]"),
8837 dwarf_form_name (form
),
8838 bfd_get_filename (abfd
));
8842 if (abbrev
->has_children
)
8843 return skip_children (reader
, info_ptr
);
8848 /* Locate ORIG_PDI's sibling.
8849 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8851 static const gdb_byte
*
8852 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8853 struct partial_die_info
*orig_pdi
,
8854 const gdb_byte
*info_ptr
)
8856 /* Do we know the sibling already? */
8858 if (orig_pdi
->sibling
)
8859 return orig_pdi
->sibling
;
8861 /* Are there any children to deal with? */
8863 if (!orig_pdi
->has_children
)
8866 /* Skip the children the long way. */
8868 return skip_children (reader
, info_ptr
);
8871 /* Expand this partial symbol table into a full symbol table. SELF is
8875 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8877 struct dwarf2_per_objfile
*dwarf2_per_objfile
8878 = get_dwarf2_per_objfile (objfile
);
8880 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (per_cu_data
));
8882 /* If this psymtab is constructed from a debug-only objfile, the
8883 has_section_at_zero flag will not necessarily be correct. We
8884 can get the correct value for this flag by looking at the data
8885 associated with the (presumably stripped) associated objfile. */
8886 if (objfile
->separate_debug_objfile_backlink
)
8888 struct dwarf2_per_objfile
*dpo_backlink
8889 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8891 dwarf2_per_objfile
->per_bfd
->has_section_at_zero
8892 = dpo_backlink
->per_bfd
->has_section_at_zero
;
8895 expand_psymtab (objfile
);
8897 process_cu_includes (dwarf2_per_objfile
);
8900 /* Reading in full CUs. */
8902 /* Add PER_CU to the queue. */
8905 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8906 enum language pretend_language
)
8909 per_cu
->dwarf2_per_objfile
->per_bfd
->queue
.emplace (per_cu
, pretend_language
);
8912 /* If PER_CU is not yet queued, add it to the queue.
8913 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8915 The result is non-zero if PER_CU was queued, otherwise the result is zero
8916 meaning either PER_CU is already queued or it is already loaded.
8918 N.B. There is an invariant here that if a CU is queued then it is loaded.
8919 The caller is required to load PER_CU if we return non-zero. */
8922 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8923 struct dwarf2_per_cu_data
*per_cu
,
8924 enum language pretend_language
)
8926 /* We may arrive here during partial symbol reading, if we need full
8927 DIEs to process an unusual case (e.g. template arguments). Do
8928 not queue PER_CU, just tell our caller to load its DIEs. */
8929 if (per_cu
->dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
)
8931 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8936 /* Mark the dependence relation so that we don't flush PER_CU
8938 if (dependent_cu
!= NULL
)
8939 dwarf2_add_dependence (dependent_cu
, per_cu
);
8941 /* If it's already on the queue, we have nothing to do. */
8945 /* If the compilation unit is already loaded, just mark it as
8947 if (per_cu
->cu
!= NULL
)
8949 per_cu
->cu
->last_used
= 0;
8953 /* Add it to the queue. */
8954 queue_comp_unit (per_cu
, pretend_language
);
8959 /* Process the queue. */
8962 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8964 if (dwarf_read_debug
)
8966 fprintf_unfiltered (gdb_stdlog
,
8967 "Expanding one or more symtabs of objfile %s ...\n",
8968 objfile_name (dwarf2_per_objfile
->objfile
));
8971 /* The queue starts out with one item, but following a DIE reference
8972 may load a new CU, adding it to the end of the queue. */
8973 while (!dwarf2_per_objfile
->per_bfd
->queue
.empty ())
8975 dwarf2_queue_item
&item
= dwarf2_per_objfile
->per_bfd
->queue
.front ();
8977 if (!dwarf2_per_objfile
->symtab_set_p (item
.per_cu
)
8978 /* Skip dummy CUs. */
8979 && item
.per_cu
->cu
!= NULL
)
8981 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8982 unsigned int debug_print_threshold
;
8985 if (per_cu
->is_debug_types
)
8987 struct signatured_type
*sig_type
=
8988 (struct signatured_type
*) per_cu
;
8990 sprintf (buf
, "TU %s at offset %s",
8991 hex_string (sig_type
->signature
),
8992 sect_offset_str (per_cu
->sect_off
));
8993 /* There can be 100s of TUs.
8994 Only print them in verbose mode. */
8995 debug_print_threshold
= 2;
8999 sprintf (buf
, "CU at offset %s",
9000 sect_offset_str (per_cu
->sect_off
));
9001 debug_print_threshold
= 1;
9004 if (dwarf_read_debug
>= debug_print_threshold
)
9005 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9007 if (per_cu
->is_debug_types
)
9008 process_full_type_unit (per_cu
, item
.pretend_language
);
9010 process_full_comp_unit (per_cu
, item
.pretend_language
);
9012 if (dwarf_read_debug
>= debug_print_threshold
)
9013 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9016 item
.per_cu
->queued
= 0;
9017 dwarf2_per_objfile
->per_bfd
->queue
.pop ();
9020 if (dwarf_read_debug
)
9022 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9023 objfile_name (dwarf2_per_objfile
->objfile
));
9027 /* Read in full symbols for PST, and anything it depends on. */
9030 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9032 gdb_assert (!readin_p (objfile
));
9034 expand_dependencies (objfile
);
9036 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9037 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9038 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9041 /* See psympriv.h. */
9044 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9046 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9047 return per_objfile
->symtab_set_p (per_cu_data
);
9050 /* See psympriv.h. */
9053 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9055 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9056 return per_objfile
->get_symtab (per_cu_data
);
9059 /* Trivial hash function for die_info: the hash value of a DIE
9060 is its offset in .debug_info for this objfile. */
9063 die_hash (const void *item
)
9065 const struct die_info
*die
= (const struct die_info
*) item
;
9067 return to_underlying (die
->sect_off
);
9070 /* Trivial comparison function for die_info structures: two DIEs
9071 are equal if they have the same offset. */
9074 die_eq (const void *item_lhs
, const void *item_rhs
)
9076 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9077 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9079 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9082 /* Load the DIEs associated with PER_CU into memory. */
9085 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9087 enum language pretend_language
)
9089 gdb_assert (! this_cu
->is_debug_types
);
9091 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
9095 struct dwarf2_cu
*cu
= reader
.cu
;
9096 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9098 gdb_assert (cu
->die_hash
== NULL
);
9100 htab_create_alloc_ex (cu
->header
.length
/ 12,
9104 &cu
->comp_unit_obstack
,
9105 hashtab_obstack_allocate
,
9106 dummy_obstack_deallocate
);
9108 if (reader
.comp_unit_die
->has_children
)
9109 reader
.comp_unit_die
->child
9110 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9111 &info_ptr
, reader
.comp_unit_die
);
9112 cu
->dies
= reader
.comp_unit_die
;
9113 /* comp_unit_die is not stored in die_hash, no need. */
9115 /* We try not to read any attributes in this function, because not
9116 all CUs needed for references have been loaded yet, and symbol
9117 table processing isn't initialized. But we have to set the CU language,
9118 or we won't be able to build types correctly.
9119 Similarly, if we do not read the producer, we can not apply
9120 producer-specific interpretation. */
9121 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9126 /* Add a DIE to the delayed physname list. */
9129 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9130 const char *name
, struct die_info
*die
,
9131 struct dwarf2_cu
*cu
)
9133 struct delayed_method_info mi
;
9135 mi
.fnfield_index
= fnfield_index
;
9139 cu
->method_list
.push_back (mi
);
9142 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9143 "const" / "volatile". If so, decrements LEN by the length of the
9144 modifier and return true. Otherwise return false. */
9148 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9150 size_t mod_len
= sizeof (mod
) - 1;
9151 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9159 /* Compute the physnames of any methods on the CU's method list.
9161 The computation of method physnames is delayed in order to avoid the
9162 (bad) condition that one of the method's formal parameters is of an as yet
9166 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9168 /* Only C++ delays computing physnames. */
9169 if (cu
->method_list
.empty ())
9171 gdb_assert (cu
->language
== language_cplus
);
9173 for (const delayed_method_info
&mi
: cu
->method_list
)
9175 const char *physname
;
9176 struct fn_fieldlist
*fn_flp
9177 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9178 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9179 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9180 = physname
? physname
: "";
9182 /* Since there's no tag to indicate whether a method is a
9183 const/volatile overload, extract that information out of the
9185 if (physname
!= NULL
)
9187 size_t len
= strlen (physname
);
9191 if (physname
[len
] == ')') /* shortcut */
9193 else if (check_modifier (physname
, len
, " const"))
9194 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9195 else if (check_modifier (physname
, len
, " volatile"))
9196 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9203 /* The list is no longer needed. */
9204 cu
->method_list
.clear ();
9207 /* Go objects should be embedded in a DW_TAG_module DIE,
9208 and it's not clear if/how imported objects will appear.
9209 To keep Go support simple until that's worked out,
9210 go back through what we've read and create something usable.
9211 We could do this while processing each DIE, and feels kinda cleaner,
9212 but that way is more invasive.
9213 This is to, for example, allow the user to type "p var" or "b main"
9214 without having to specify the package name, and allow lookups
9215 of module.object to work in contexts that use the expression
9219 fixup_go_packaging (struct dwarf2_cu
*cu
)
9221 gdb::unique_xmalloc_ptr
<char> package_name
;
9222 struct pending
*list
;
9225 for (list
= *cu
->get_builder ()->get_global_symbols ();
9229 for (i
= 0; i
< list
->nsyms
; ++i
)
9231 struct symbol
*sym
= list
->symbol
[i
];
9233 if (sym
->language () == language_go
9234 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9236 gdb::unique_xmalloc_ptr
<char> this_package_name
9237 (go_symbol_package_name (sym
));
9239 if (this_package_name
== NULL
)
9241 if (package_name
== NULL
)
9242 package_name
= std::move (this_package_name
);
9245 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9246 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9247 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9248 (symbol_symtab (sym
) != NULL
9249 ? symtab_to_filename_for_display
9250 (symbol_symtab (sym
))
9251 : objfile_name (objfile
)),
9252 this_package_name
.get (), package_name
.get ());
9258 if (package_name
!= NULL
)
9260 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9261 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9262 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9263 saved_package_name
);
9266 sym
= new (&objfile
->objfile_obstack
) symbol
;
9267 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9268 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9269 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9270 e.g., "main" finds the "main" module and not C's main(). */
9271 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9272 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9273 SYMBOL_TYPE (sym
) = type
;
9275 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9279 /* Allocate a fully-qualified name consisting of the two parts on the
9283 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9285 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9288 /* A helper that allocates a variant part to attach to a Rust enum
9289 type. OBSTACK is where the results should be allocated. TYPE is
9290 the type we're processing. DISCRIMINANT_INDEX is the index of the
9291 discriminant. It must be the index of one of the fields of TYPE.
9292 DEFAULT_INDEX is the index of the default field; or -1 if there is
9293 no default. RANGES is indexed by "effective" field number (the
9294 field index, but omitting the discriminant and default fields) and
9295 must hold the discriminant values used by the variants. Note that
9296 RANGES must have a lifetime at least as long as OBSTACK -- either
9297 already allocated on it, or static. */
9300 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9301 int discriminant_index
, int default_index
,
9302 gdb::array_view
<discriminant_range
> ranges
)
9304 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9305 must be handled by the caller. */
9306 gdb_assert (discriminant_index
>= 0
9307 && discriminant_index
< type
->num_fields ());
9308 gdb_assert (default_index
== -1
9309 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9311 /* We have one variant for each non-discriminant field. */
9312 int n_variants
= type
->num_fields () - 1;
9314 variant
*variants
= new (obstack
) variant
[n_variants
];
9317 for (int i
= 0; i
< type
->num_fields (); ++i
)
9319 if (i
== discriminant_index
)
9322 variants
[var_idx
].first_field
= i
;
9323 variants
[var_idx
].last_field
= i
+ 1;
9325 /* The default field does not need a range, but other fields do.
9326 We skipped the discriminant above. */
9327 if (i
!= default_index
)
9329 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9336 gdb_assert (range_idx
== ranges
.size ());
9337 gdb_assert (var_idx
== n_variants
);
9339 variant_part
*part
= new (obstack
) variant_part
;
9340 part
->discriminant_index
= discriminant_index
;
9341 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9342 discriminant_index
));
9343 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9345 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9346 gdb::array_view
<variant_part
> *prop_value
9347 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9349 struct dynamic_prop prop
;
9350 prop
.kind
= PROP_VARIANT_PARTS
;
9351 prop
.data
.variant_parts
= prop_value
;
9353 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9356 /* Some versions of rustc emitted enums in an unusual way.
9358 Ordinary enums were emitted as unions. The first element of each
9359 structure in the union was named "RUST$ENUM$DISR". This element
9360 held the discriminant.
9362 These versions of Rust also implemented the "non-zero"
9363 optimization. When the enum had two values, and one is empty and
9364 the other holds a pointer that cannot be zero, the pointer is used
9365 as the discriminant, with a zero value meaning the empty variant.
9366 Here, the union's first member is of the form
9367 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9368 where the fieldnos are the indices of the fields that should be
9369 traversed in order to find the field (which may be several fields deep)
9370 and the variantname is the name of the variant of the case when the
9373 This function recognizes whether TYPE is of one of these forms,
9374 and, if so, smashes it to be a variant type. */
9377 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9379 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9381 /* We don't need to deal with empty enums. */
9382 if (type
->num_fields () == 0)
9385 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9386 if (type
->num_fields () == 1
9387 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9389 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9391 /* Decode the field name to find the offset of the
9393 ULONGEST bit_offset
= 0;
9394 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9395 while (name
[0] >= '0' && name
[0] <= '9')
9398 unsigned long index
= strtoul (name
, &tail
, 10);
9401 || index
>= field_type
->num_fields ()
9402 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9403 != FIELD_LOC_KIND_BITPOS
))
9405 complaint (_("Could not parse Rust enum encoding string \"%s\""
9407 TYPE_FIELD_NAME (type
, 0),
9408 objfile_name (objfile
));
9413 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9414 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9417 /* Smash this type to be a structure type. We have to do this
9418 because the type has already been recorded. */
9419 type
->set_code (TYPE_CODE_STRUCT
);
9420 type
->set_num_fields (3);
9421 /* Save the field we care about. */
9422 struct field saved_field
= type
->field (0);
9424 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9426 /* Put the discriminant at index 0. */
9427 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9428 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9429 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9430 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9432 /* The order of fields doesn't really matter, so put the real
9433 field at index 1 and the data-less field at index 2. */
9434 type
->field (1) = saved_field
;
9435 TYPE_FIELD_NAME (type
, 1)
9436 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9437 TYPE_FIELD_TYPE (type
, 1)->set_name
9438 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9439 TYPE_FIELD_NAME (type
, 1)));
9441 const char *dataless_name
9442 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9444 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9446 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9447 /* NAME points into the original discriminant name, which
9448 already has the correct lifetime. */
9449 TYPE_FIELD_NAME (type
, 2) = name
;
9450 SET_FIELD_BITPOS (type
->field (2), 0);
9452 /* Indicate that this is a variant type. */
9453 static discriminant_range ranges
[1] = { { 0, 0 } };
9454 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9456 /* A union with a single anonymous field is probably an old-style
9458 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9460 /* Smash this type to be a structure type. We have to do this
9461 because the type has already been recorded. */
9462 type
->set_code (TYPE_CODE_STRUCT
);
9464 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9465 const char *variant_name
9466 = rust_last_path_segment (field_type
->name ());
9467 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9468 field_type
->set_name
9469 (rust_fully_qualify (&objfile
->objfile_obstack
,
9470 type
->name (), variant_name
));
9474 struct type
*disr_type
= nullptr;
9475 for (int i
= 0; i
< type
->num_fields (); ++i
)
9477 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9479 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9481 /* All fields of a true enum will be structs. */
9484 else if (disr_type
->num_fields () == 0)
9486 /* Could be data-less variant, so keep going. */
9487 disr_type
= nullptr;
9489 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9490 "RUST$ENUM$DISR") != 0)
9492 /* Not a Rust enum. */
9502 /* If we got here without a discriminant, then it's probably
9504 if (disr_type
== nullptr)
9507 /* Smash this type to be a structure type. We have to do this
9508 because the type has already been recorded. */
9509 type
->set_code (TYPE_CODE_STRUCT
);
9511 /* Make space for the discriminant field. */
9512 struct field
*disr_field
= &disr_type
->field (0);
9514 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9515 * sizeof (struct field
)));
9516 memcpy (new_fields
+ 1, type
->fields (),
9517 type
->num_fields () * sizeof (struct field
));
9518 type
->set_fields (new_fields
);
9519 type
->set_num_fields (type
->num_fields () + 1);
9521 /* Install the discriminant at index 0 in the union. */
9522 type
->field (0) = *disr_field
;
9523 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9524 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9526 /* We need a way to find the correct discriminant given a
9527 variant name. For convenience we build a map here. */
9528 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9529 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9530 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9532 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9535 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9536 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9540 int n_fields
= type
->num_fields ();
9541 /* We don't need a range entry for the discriminant, but we do
9542 need one for every other field, as there is no default
9544 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9547 /* Skip the discriminant here. */
9548 for (int i
= 1; i
< n_fields
; ++i
)
9550 /* Find the final word in the name of this variant's type.
9551 That name can be used to look up the correct
9553 const char *variant_name
9554 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9556 auto iter
= discriminant_map
.find (variant_name
);
9557 if (iter
!= discriminant_map
.end ())
9559 ranges
[i
].low
= iter
->second
;
9560 ranges
[i
].high
= iter
->second
;
9563 /* Remove the discriminant field, if it exists. */
9564 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9565 if (sub_type
->num_fields () > 0)
9567 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9568 sub_type
->set_fields (sub_type
->fields () + 1);
9570 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9572 (rust_fully_qualify (&objfile
->objfile_obstack
,
9573 type
->name (), variant_name
));
9576 /* Indicate that this is a variant type. */
9577 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9578 gdb::array_view
<discriminant_range
> (ranges
,
9583 /* Rewrite some Rust unions to be structures with variants parts. */
9586 rust_union_quirks (struct dwarf2_cu
*cu
)
9588 gdb_assert (cu
->language
== language_rust
);
9589 for (type
*type_
: cu
->rust_unions
)
9590 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9591 /* We don't need this any more. */
9592 cu
->rust_unions
.clear ();
9595 /* A helper function for computing the list of all symbol tables
9596 included by PER_CU. */
9599 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9600 htab_t all_children
, htab_t all_type_symtabs
,
9601 struct dwarf2_per_cu_data
*per_cu
,
9602 struct compunit_symtab
*immediate_parent
)
9604 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9607 /* This inclusion and its children have been processed. */
9613 /* Only add a CU if it has a symbol table. */
9614 compunit_symtab
*cust
= per_cu
->dwarf2_per_objfile
->get_symtab (per_cu
);
9617 /* If this is a type unit only add its symbol table if we haven't
9618 seen it yet (type unit per_cu's can share symtabs). */
9619 if (per_cu
->is_debug_types
)
9621 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9625 result
->push_back (cust
);
9626 if (cust
->user
== NULL
)
9627 cust
->user
= immediate_parent
;
9632 result
->push_back (cust
);
9633 if (cust
->user
== NULL
)
9634 cust
->user
= immediate_parent
;
9638 if (!per_cu
->imported_symtabs_empty ())
9639 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9641 recursively_compute_inclusions (result
, all_children
,
9642 all_type_symtabs
, ptr
, cust
);
9646 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9650 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9652 gdb_assert (! per_cu
->is_debug_types
);
9654 if (!per_cu
->imported_symtabs_empty ())
9657 std::vector
<compunit_symtab
*> result_symtabs
;
9658 htab_t all_children
, all_type_symtabs
;
9659 compunit_symtab
*cust
= per_cu
->dwarf2_per_objfile
->get_symtab (per_cu
);
9661 /* If we don't have a symtab, we can just skip this case. */
9665 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9666 NULL
, xcalloc
, xfree
);
9667 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9668 NULL
, xcalloc
, xfree
);
9670 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9672 recursively_compute_inclusions (&result_symtabs
, all_children
,
9673 all_type_symtabs
, ptr
, cust
);
9676 /* Now we have a transitive closure of all the included symtabs. */
9677 len
= result_symtabs
.size ();
9679 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9680 struct compunit_symtab
*, len
+ 1);
9681 memcpy (cust
->includes
, result_symtabs
.data (),
9682 len
* sizeof (compunit_symtab
*));
9683 cust
->includes
[len
] = NULL
;
9685 htab_delete (all_children
);
9686 htab_delete (all_type_symtabs
);
9690 /* Compute the 'includes' field for the symtabs of all the CUs we just
9694 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9696 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->per_bfd
->just_read_cus
)
9698 if (! iter
->is_debug_types
)
9699 compute_compunit_symtab_includes (iter
);
9702 dwarf2_per_objfile
->per_bfd
->just_read_cus
.clear ();
9705 /* Generate full symbol information for PER_CU, whose DIEs have
9706 already been loaded into memory. */
9709 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9710 enum language pretend_language
)
9712 struct dwarf2_cu
*cu
= per_cu
->cu
;
9713 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9714 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9715 struct gdbarch
*gdbarch
= objfile
->arch ();
9716 CORE_ADDR lowpc
, highpc
;
9717 struct compunit_symtab
*cust
;
9719 struct block
*static_block
;
9722 baseaddr
= objfile
->text_section_offset ();
9724 /* Clear the list here in case something was left over. */
9725 cu
->method_list
.clear ();
9727 cu
->language
= pretend_language
;
9728 cu
->language_defn
= language_def (cu
->language
);
9730 /* Do line number decoding in read_file_scope () */
9731 process_die (cu
->dies
, cu
);
9733 /* For now fudge the Go package. */
9734 if (cu
->language
== language_go
)
9735 fixup_go_packaging (cu
);
9737 /* Now that we have processed all the DIEs in the CU, all the types
9738 should be complete, and it should now be safe to compute all of the
9740 compute_delayed_physnames (cu
);
9742 if (cu
->language
== language_rust
)
9743 rust_union_quirks (cu
);
9745 /* Some compilers don't define a DW_AT_high_pc attribute for the
9746 compilation unit. If the DW_AT_high_pc is missing, synthesize
9747 it, by scanning the DIE's below the compilation unit. */
9748 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9750 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9751 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9753 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9754 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9755 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9756 addrmap to help ensure it has an accurate map of pc values belonging to
9758 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9760 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9761 SECT_OFF_TEXT (objfile
),
9766 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9768 /* Set symtab language to language from DW_AT_language. If the
9769 compilation is from a C file generated by language preprocessors, do
9770 not set the language if it was already deduced by start_subfile. */
9771 if (!(cu
->language
== language_c
9772 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9773 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9775 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9776 produce DW_AT_location with location lists but it can be possibly
9777 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9778 there were bugs in prologue debug info, fixed later in GCC-4.5
9779 by "unwind info for epilogues" patch (which is not directly related).
9781 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9782 needed, it would be wrong due to missing DW_AT_producer there.
9784 Still one can confuse GDB by using non-standard GCC compilation
9785 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9787 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9788 cust
->locations_valid
= 1;
9790 if (gcc_4_minor
>= 5)
9791 cust
->epilogue_unwind_valid
= 1;
9793 cust
->call_site_htab
= cu
->call_site_htab
;
9796 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9798 /* Push it for inclusion processing later. */
9799 dwarf2_per_objfile
->per_bfd
->just_read_cus
.push_back (per_cu
);
9801 /* Not needed any more. */
9802 cu
->reset_builder ();
9805 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9806 already been loaded into memory. */
9809 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9810 enum language pretend_language
)
9812 struct dwarf2_cu
*cu
= per_cu
->cu
;
9813 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9814 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9815 struct compunit_symtab
*cust
;
9816 struct signatured_type
*sig_type
;
9818 gdb_assert (per_cu
->is_debug_types
);
9819 sig_type
= (struct signatured_type
*) per_cu
;
9821 /* Clear the list here in case something was left over. */
9822 cu
->method_list
.clear ();
9824 cu
->language
= pretend_language
;
9825 cu
->language_defn
= language_def (cu
->language
);
9827 /* The symbol tables are set up in read_type_unit_scope. */
9828 process_die (cu
->dies
, cu
);
9830 /* For now fudge the Go package. */
9831 if (cu
->language
== language_go
)
9832 fixup_go_packaging (cu
);
9834 /* Now that we have processed all the DIEs in the CU, all the types
9835 should be complete, and it should now be safe to compute all of the
9837 compute_delayed_physnames (cu
);
9839 if (cu
->language
== language_rust
)
9840 rust_union_quirks (cu
);
9842 /* TUs share symbol tables.
9843 If this is the first TU to use this symtab, complete the construction
9844 of it with end_expandable_symtab. Otherwise, complete the addition of
9845 this TU's symbols to the existing symtab. */
9846 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9848 buildsym_compunit
*builder
= cu
->get_builder ();
9849 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9850 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9854 /* Set symtab language to language from DW_AT_language. If the
9855 compilation is from a C file generated by language preprocessors,
9856 do not set the language if it was already deduced by
9858 if (!(cu
->language
== language_c
9859 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9860 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9865 cu
->get_builder ()->augment_type_symtab ();
9866 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9869 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9871 /* Not needed any more. */
9872 cu
->reset_builder ();
9875 /* Process an imported unit DIE. */
9878 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9880 struct attribute
*attr
;
9882 /* For now we don't handle imported units in type units. */
9883 if (cu
->per_cu
->is_debug_types
)
9885 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9886 " supported in type units [in module %s]"),
9887 objfile_name (cu
->per_objfile
->objfile
));
9890 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9893 sect_offset sect_off
= attr
->get_ref_die_offset ();
9894 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9895 dwarf2_per_cu_data
*per_cu
9896 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, cu
->per_objfile
);
9898 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9899 into another compilation unit, at root level. Regard this as a hint,
9901 if (die
->parent
&& die
->parent
->parent
== NULL
9902 && per_cu
->unit_type
== DW_UT_compile
9903 && per_cu
->lang
== language_cplus
)
9906 /* If necessary, add it to the queue and load its DIEs. */
9907 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9908 load_full_comp_unit (per_cu
, false, cu
->language
);
9910 cu
->per_cu
->imported_symtabs_push (per_cu
);
9914 /* RAII object that represents a process_die scope: i.e.,
9915 starts/finishes processing a DIE. */
9916 class process_die_scope
9919 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9920 : m_die (die
), m_cu (cu
)
9922 /* We should only be processing DIEs not already in process. */
9923 gdb_assert (!m_die
->in_process
);
9924 m_die
->in_process
= true;
9927 ~process_die_scope ()
9929 m_die
->in_process
= false;
9931 /* If we're done processing the DIE for the CU that owns the line
9932 header, we don't need the line header anymore. */
9933 if (m_cu
->line_header_die_owner
== m_die
)
9935 delete m_cu
->line_header
;
9936 m_cu
->line_header
= NULL
;
9937 m_cu
->line_header_die_owner
= NULL
;
9946 /* Process a die and its children. */
9949 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9951 process_die_scope
scope (die
, cu
);
9955 case DW_TAG_padding
:
9957 case DW_TAG_compile_unit
:
9958 case DW_TAG_partial_unit
:
9959 read_file_scope (die
, cu
);
9961 case DW_TAG_type_unit
:
9962 read_type_unit_scope (die
, cu
);
9964 case DW_TAG_subprogram
:
9965 /* Nested subprograms in Fortran get a prefix. */
9966 if (cu
->language
== language_fortran
9967 && die
->parent
!= NULL
9968 && die
->parent
->tag
== DW_TAG_subprogram
)
9969 cu
->processing_has_namespace_info
= true;
9971 case DW_TAG_inlined_subroutine
:
9972 read_func_scope (die
, cu
);
9974 case DW_TAG_lexical_block
:
9975 case DW_TAG_try_block
:
9976 case DW_TAG_catch_block
:
9977 read_lexical_block_scope (die
, cu
);
9979 case DW_TAG_call_site
:
9980 case DW_TAG_GNU_call_site
:
9981 read_call_site_scope (die
, cu
);
9983 case DW_TAG_class_type
:
9984 case DW_TAG_interface_type
:
9985 case DW_TAG_structure_type
:
9986 case DW_TAG_union_type
:
9987 process_structure_scope (die
, cu
);
9989 case DW_TAG_enumeration_type
:
9990 process_enumeration_scope (die
, cu
);
9993 /* These dies have a type, but processing them does not create
9994 a symbol or recurse to process the children. Therefore we can
9995 read them on-demand through read_type_die. */
9996 case DW_TAG_subroutine_type
:
9997 case DW_TAG_set_type
:
9998 case DW_TAG_array_type
:
9999 case DW_TAG_pointer_type
:
10000 case DW_TAG_ptr_to_member_type
:
10001 case DW_TAG_reference_type
:
10002 case DW_TAG_rvalue_reference_type
:
10003 case DW_TAG_string_type
:
10006 case DW_TAG_base_type
:
10007 case DW_TAG_subrange_type
:
10008 case DW_TAG_typedef
:
10009 /* Add a typedef symbol for the type definition, if it has a
10011 new_symbol (die
, read_type_die (die
, cu
), cu
);
10013 case DW_TAG_common_block
:
10014 read_common_block (die
, cu
);
10016 case DW_TAG_common_inclusion
:
10018 case DW_TAG_namespace
:
10019 cu
->processing_has_namespace_info
= true;
10020 read_namespace (die
, cu
);
10022 case DW_TAG_module
:
10023 cu
->processing_has_namespace_info
= true;
10024 read_module (die
, cu
);
10026 case DW_TAG_imported_declaration
:
10027 cu
->processing_has_namespace_info
= true;
10028 if (read_namespace_alias (die
, cu
))
10030 /* The declaration is not a global namespace alias. */
10031 /* Fall through. */
10032 case DW_TAG_imported_module
:
10033 cu
->processing_has_namespace_info
= true;
10034 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10035 || cu
->language
!= language_fortran
))
10036 complaint (_("Tag '%s' has unexpected children"),
10037 dwarf_tag_name (die
->tag
));
10038 read_import_statement (die
, cu
);
10041 case DW_TAG_imported_unit
:
10042 process_imported_unit_die (die
, cu
);
10045 case DW_TAG_variable
:
10046 read_variable (die
, cu
);
10050 new_symbol (die
, NULL
, cu
);
10055 /* DWARF name computation. */
10057 /* A helper function for dwarf2_compute_name which determines whether DIE
10058 needs to have the name of the scope prepended to the name listed in the
10062 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10064 struct attribute
*attr
;
10068 case DW_TAG_namespace
:
10069 case DW_TAG_typedef
:
10070 case DW_TAG_class_type
:
10071 case DW_TAG_interface_type
:
10072 case DW_TAG_structure_type
:
10073 case DW_TAG_union_type
:
10074 case DW_TAG_enumeration_type
:
10075 case DW_TAG_enumerator
:
10076 case DW_TAG_subprogram
:
10077 case DW_TAG_inlined_subroutine
:
10078 case DW_TAG_member
:
10079 case DW_TAG_imported_declaration
:
10082 case DW_TAG_variable
:
10083 case DW_TAG_constant
:
10084 /* We only need to prefix "globally" visible variables. These include
10085 any variable marked with DW_AT_external or any variable that
10086 lives in a namespace. [Variables in anonymous namespaces
10087 require prefixing, but they are not DW_AT_external.] */
10089 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10091 struct dwarf2_cu
*spec_cu
= cu
;
10093 return die_needs_namespace (die_specification (die
, &spec_cu
),
10097 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10098 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10099 && die
->parent
->tag
!= DW_TAG_module
)
10101 /* A variable in a lexical block of some kind does not need a
10102 namespace, even though in C++ such variables may be external
10103 and have a mangled name. */
10104 if (die
->parent
->tag
== DW_TAG_lexical_block
10105 || die
->parent
->tag
== DW_TAG_try_block
10106 || die
->parent
->tag
== DW_TAG_catch_block
10107 || die
->parent
->tag
== DW_TAG_subprogram
)
10116 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10117 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10118 defined for the given DIE. */
10120 static struct attribute
*
10121 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10123 struct attribute
*attr
;
10125 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10127 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10132 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10133 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10134 defined for the given DIE. */
10136 static const char *
10137 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10139 const char *linkage_name
;
10141 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10142 if (linkage_name
== NULL
)
10143 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10145 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10146 See https://github.com/rust-lang/rust/issues/32925. */
10147 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10148 && strchr (linkage_name
, '{') != NULL
)
10149 linkage_name
= NULL
;
10151 return linkage_name
;
10154 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10155 compute the physname for the object, which include a method's:
10156 - formal parameters (C++),
10157 - receiver type (Go),
10159 The term "physname" is a bit confusing.
10160 For C++, for example, it is the demangled name.
10161 For Go, for example, it's the mangled name.
10163 For Ada, return the DIE's linkage name rather than the fully qualified
10164 name. PHYSNAME is ignored..
10166 The result is allocated on the objfile->per_bfd's obstack and
10169 static const char *
10170 dwarf2_compute_name (const char *name
,
10171 struct die_info
*die
, struct dwarf2_cu
*cu
,
10174 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10177 name
= dwarf2_name (die
, cu
);
10179 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10180 but otherwise compute it by typename_concat inside GDB.
10181 FIXME: Actually this is not really true, or at least not always true.
10182 It's all very confusing. compute_and_set_names doesn't try to demangle
10183 Fortran names because there is no mangling standard. So new_symbol
10184 will set the demangled name to the result of dwarf2_full_name, and it is
10185 the demangled name that GDB uses if it exists. */
10186 if (cu
->language
== language_ada
10187 || (cu
->language
== language_fortran
&& physname
))
10189 /* For Ada unit, we prefer the linkage name over the name, as
10190 the former contains the exported name, which the user expects
10191 to be able to reference. Ideally, we want the user to be able
10192 to reference this entity using either natural or linkage name,
10193 but we haven't started looking at this enhancement yet. */
10194 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10196 if (linkage_name
!= NULL
)
10197 return linkage_name
;
10200 /* These are the only languages we know how to qualify names in. */
10202 && (cu
->language
== language_cplus
10203 || cu
->language
== language_fortran
|| cu
->language
== language_d
10204 || cu
->language
== language_rust
))
10206 if (die_needs_namespace (die
, cu
))
10208 const char *prefix
;
10209 const char *canonical_name
= NULL
;
10213 prefix
= determine_prefix (die
, cu
);
10214 if (*prefix
!= '\0')
10216 gdb::unique_xmalloc_ptr
<char> prefixed_name
10217 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10219 buf
.puts (prefixed_name
.get ());
10224 /* Template parameters may be specified in the DIE's DW_AT_name, or
10225 as children with DW_TAG_template_type_param or
10226 DW_TAG_value_type_param. If the latter, add them to the name
10227 here. If the name already has template parameters, then
10228 skip this step; some versions of GCC emit both, and
10229 it is more efficient to use the pre-computed name.
10231 Something to keep in mind about this process: it is very
10232 unlikely, or in some cases downright impossible, to produce
10233 something that will match the mangled name of a function.
10234 If the definition of the function has the same debug info,
10235 we should be able to match up with it anyway. But fallbacks
10236 using the minimal symbol, for instance to find a method
10237 implemented in a stripped copy of libstdc++, will not work.
10238 If we do not have debug info for the definition, we will have to
10239 match them up some other way.
10241 When we do name matching there is a related problem with function
10242 templates; two instantiated function templates are allowed to
10243 differ only by their return types, which we do not add here. */
10245 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10247 struct attribute
*attr
;
10248 struct die_info
*child
;
10251 die
->building_fullname
= 1;
10253 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10257 const gdb_byte
*bytes
;
10258 struct dwarf2_locexpr_baton
*baton
;
10261 if (child
->tag
!= DW_TAG_template_type_param
10262 && child
->tag
!= DW_TAG_template_value_param
)
10273 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10276 complaint (_("template parameter missing DW_AT_type"));
10277 buf
.puts ("UNKNOWN_TYPE");
10280 type
= die_type (child
, cu
);
10282 if (child
->tag
== DW_TAG_template_type_param
)
10284 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10285 &type_print_raw_options
);
10289 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10292 complaint (_("template parameter missing "
10293 "DW_AT_const_value"));
10294 buf
.puts ("UNKNOWN_VALUE");
10298 dwarf2_const_value_attr (attr
, type
, name
,
10299 &cu
->comp_unit_obstack
, cu
,
10300 &value
, &bytes
, &baton
);
10302 if (TYPE_NOSIGN (type
))
10303 /* GDB prints characters as NUMBER 'CHAR'. If that's
10304 changed, this can use value_print instead. */
10305 c_printchar (value
, type
, &buf
);
10308 struct value_print_options opts
;
10311 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10315 else if (bytes
!= NULL
)
10317 v
= allocate_value (type
);
10318 memcpy (value_contents_writeable (v
), bytes
,
10319 TYPE_LENGTH (type
));
10322 v
= value_from_longest (type
, value
);
10324 /* Specify decimal so that we do not depend on
10326 get_formatted_print_options (&opts
, 'd');
10328 value_print (v
, &buf
, &opts
);
10333 die
->building_fullname
= 0;
10337 /* Close the argument list, with a space if necessary
10338 (nested templates). */
10339 if (!buf
.empty () && buf
.string ().back () == '>')
10346 /* For C++ methods, append formal parameter type
10347 information, if PHYSNAME. */
10349 if (physname
&& die
->tag
== DW_TAG_subprogram
10350 && cu
->language
== language_cplus
)
10352 struct type
*type
= read_type_die (die
, cu
);
10354 c_type_print_args (type
, &buf
, 1, cu
->language
,
10355 &type_print_raw_options
);
10357 if (cu
->language
== language_cplus
)
10359 /* Assume that an artificial first parameter is
10360 "this", but do not crash if it is not. RealView
10361 marks unnamed (and thus unused) parameters as
10362 artificial; there is no way to differentiate
10364 if (type
->num_fields () > 0
10365 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10366 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10367 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10369 buf
.puts (" const");
10373 const std::string
&intermediate_name
= buf
.string ();
10375 if (cu
->language
== language_cplus
)
10377 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10380 /* If we only computed INTERMEDIATE_NAME, or if
10381 INTERMEDIATE_NAME is already canonical, then we need to
10383 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10384 name
= objfile
->intern (intermediate_name
);
10386 name
= canonical_name
;
10393 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10394 If scope qualifiers are appropriate they will be added. The result
10395 will be allocated on the storage_obstack, or NULL if the DIE does
10396 not have a name. NAME may either be from a previous call to
10397 dwarf2_name or NULL.
10399 The output string will be canonicalized (if C++). */
10401 static const char *
10402 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10404 return dwarf2_compute_name (name
, die
, cu
, 0);
10407 /* Construct a physname for the given DIE in CU. NAME may either be
10408 from a previous call to dwarf2_name or NULL. The result will be
10409 allocated on the objfile_objstack or NULL if the DIE does not have a
10412 The output string will be canonicalized (if C++). */
10414 static const char *
10415 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10417 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10418 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10421 /* In this case dwarf2_compute_name is just a shortcut not building anything
10423 if (!die_needs_namespace (die
, cu
))
10424 return dwarf2_compute_name (name
, die
, cu
, 1);
10426 if (cu
->language
!= language_rust
)
10427 mangled
= dw2_linkage_name (die
, cu
);
10429 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10431 gdb::unique_xmalloc_ptr
<char> demangled
;
10432 if (mangled
!= NULL
)
10435 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10437 /* Do nothing (do not demangle the symbol name). */
10439 else if (cu
->language
== language_go
)
10441 /* This is a lie, but we already lie to the caller new_symbol.
10442 new_symbol assumes we return the mangled name.
10443 This just undoes that lie until things are cleaned up. */
10447 /* Use DMGL_RET_DROP for C++ template functions to suppress
10448 their return type. It is easier for GDB users to search
10449 for such functions as `name(params)' than `long name(params)'.
10450 In such case the minimal symbol names do not match the full
10451 symbol names but for template functions there is never a need
10452 to look up their definition from their declaration so
10453 the only disadvantage remains the minimal symbol variant
10454 `long name(params)' does not have the proper inferior type. */
10455 demangled
.reset (gdb_demangle (mangled
,
10456 (DMGL_PARAMS
| DMGL_ANSI
10457 | DMGL_RET_DROP
)));
10460 canon
= demangled
.get ();
10468 if (canon
== NULL
|| check_physname
)
10470 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10472 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10474 /* It may not mean a bug in GDB. The compiler could also
10475 compute DW_AT_linkage_name incorrectly. But in such case
10476 GDB would need to be bug-to-bug compatible. */
10478 complaint (_("Computed physname <%s> does not match demangled <%s> "
10479 "(from linkage <%s>) - DIE at %s [in module %s]"),
10480 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10481 objfile_name (objfile
));
10483 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10484 is available here - over computed PHYSNAME. It is safer
10485 against both buggy GDB and buggy compilers. */
10499 retval
= objfile
->intern (retval
);
10504 /* Inspect DIE in CU for a namespace alias. If one exists, record
10505 a new symbol for it.
10507 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10510 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10512 struct attribute
*attr
;
10514 /* If the die does not have a name, this is not a namespace
10516 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10520 struct die_info
*d
= die
;
10521 struct dwarf2_cu
*imported_cu
= cu
;
10523 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10524 keep inspecting DIEs until we hit the underlying import. */
10525 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10526 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10528 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10532 d
= follow_die_ref (d
, attr
, &imported_cu
);
10533 if (d
->tag
!= DW_TAG_imported_declaration
)
10537 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10539 complaint (_("DIE at %s has too many recursively imported "
10540 "declarations"), sect_offset_str (d
->sect_off
));
10547 sect_offset sect_off
= attr
->get_ref_die_offset ();
10549 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10550 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10552 /* This declaration is a global namespace alias. Add
10553 a symbol for it whose type is the aliased namespace. */
10554 new_symbol (die
, type
, cu
);
10563 /* Return the using directives repository (global or local?) to use in the
10564 current context for CU.
10566 For Ada, imported declarations can materialize renamings, which *may* be
10567 global. However it is impossible (for now?) in DWARF to distinguish
10568 "external" imported declarations and "static" ones. As all imported
10569 declarations seem to be static in all other languages, make them all CU-wide
10570 global only in Ada. */
10572 static struct using_direct
**
10573 using_directives (struct dwarf2_cu
*cu
)
10575 if (cu
->language
== language_ada
10576 && cu
->get_builder ()->outermost_context_p ())
10577 return cu
->get_builder ()->get_global_using_directives ();
10579 return cu
->get_builder ()->get_local_using_directives ();
10582 /* Read the import statement specified by the given die and record it. */
10585 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10587 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10588 struct attribute
*import_attr
;
10589 struct die_info
*imported_die
, *child_die
;
10590 struct dwarf2_cu
*imported_cu
;
10591 const char *imported_name
;
10592 const char *imported_name_prefix
;
10593 const char *canonical_name
;
10594 const char *import_alias
;
10595 const char *imported_declaration
= NULL
;
10596 const char *import_prefix
;
10597 std::vector
<const char *> excludes
;
10599 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10600 if (import_attr
== NULL
)
10602 complaint (_("Tag '%s' has no DW_AT_import"),
10603 dwarf_tag_name (die
->tag
));
10608 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10609 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10610 if (imported_name
== NULL
)
10612 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10614 The import in the following code:
10628 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10629 <52> DW_AT_decl_file : 1
10630 <53> DW_AT_decl_line : 6
10631 <54> DW_AT_import : <0x75>
10632 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10633 <59> DW_AT_name : B
10634 <5b> DW_AT_decl_file : 1
10635 <5c> DW_AT_decl_line : 2
10636 <5d> DW_AT_type : <0x6e>
10638 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10639 <76> DW_AT_byte_size : 4
10640 <77> DW_AT_encoding : 5 (signed)
10642 imports the wrong die ( 0x75 instead of 0x58 ).
10643 This case will be ignored until the gcc bug is fixed. */
10647 /* Figure out the local name after import. */
10648 import_alias
= dwarf2_name (die
, cu
);
10650 /* Figure out where the statement is being imported to. */
10651 import_prefix
= determine_prefix (die
, cu
);
10653 /* Figure out what the scope of the imported die is and prepend it
10654 to the name of the imported die. */
10655 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10657 if (imported_die
->tag
!= DW_TAG_namespace
10658 && imported_die
->tag
!= DW_TAG_module
)
10660 imported_declaration
= imported_name
;
10661 canonical_name
= imported_name_prefix
;
10663 else if (strlen (imported_name_prefix
) > 0)
10664 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10665 imported_name_prefix
,
10666 (cu
->language
== language_d
? "." : "::"),
10667 imported_name
, (char *) NULL
);
10669 canonical_name
= imported_name
;
10671 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10672 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10673 child_die
= child_die
->sibling
)
10675 /* DWARF-4: A Fortran use statement with a “rename list” may be
10676 represented by an imported module entry with an import attribute
10677 referring to the module and owned entries corresponding to those
10678 entities that are renamed as part of being imported. */
10680 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10682 complaint (_("child DW_TAG_imported_declaration expected "
10683 "- DIE at %s [in module %s]"),
10684 sect_offset_str (child_die
->sect_off
),
10685 objfile_name (objfile
));
10689 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10690 if (import_attr
== NULL
)
10692 complaint (_("Tag '%s' has no DW_AT_import"),
10693 dwarf_tag_name (child_die
->tag
));
10698 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10700 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10701 if (imported_name
== NULL
)
10703 complaint (_("child DW_TAG_imported_declaration has unknown "
10704 "imported name - DIE at %s [in module %s]"),
10705 sect_offset_str (child_die
->sect_off
),
10706 objfile_name (objfile
));
10710 excludes
.push_back (imported_name
);
10712 process_die (child_die
, cu
);
10715 add_using_directive (using_directives (cu
),
10719 imported_declaration
,
10722 &objfile
->objfile_obstack
);
10725 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10726 types, but gives them a size of zero. Starting with version 14,
10727 ICC is compatible with GCC. */
10730 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10732 if (!cu
->checked_producer
)
10733 check_producer (cu
);
10735 return cu
->producer_is_icc_lt_14
;
10738 /* ICC generates a DW_AT_type for C void functions. This was observed on
10739 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10740 which says that void functions should not have a DW_AT_type. */
10743 producer_is_icc (struct dwarf2_cu
*cu
)
10745 if (!cu
->checked_producer
)
10746 check_producer (cu
);
10748 return cu
->producer_is_icc
;
10751 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10752 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10753 this, it was first present in GCC release 4.3.0. */
10756 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10758 if (!cu
->checked_producer
)
10759 check_producer (cu
);
10761 return cu
->producer_is_gcc_lt_4_3
;
10764 static file_and_directory
10765 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10767 file_and_directory res
;
10769 /* Find the filename. Do not use dwarf2_name here, since the filename
10770 is not a source language identifier. */
10771 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10772 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10774 if (res
.comp_dir
== NULL
10775 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10776 && IS_ABSOLUTE_PATH (res
.name
))
10778 res
.comp_dir_storage
= ldirname (res
.name
);
10779 if (!res
.comp_dir_storage
.empty ())
10780 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10782 if (res
.comp_dir
!= NULL
)
10784 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10785 directory, get rid of it. */
10786 const char *cp
= strchr (res
.comp_dir
, ':');
10788 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10789 res
.comp_dir
= cp
+ 1;
10792 if (res
.name
== NULL
)
10793 res
.name
= "<unknown>";
10798 /* Handle DW_AT_stmt_list for a compilation unit.
10799 DIE is the DW_TAG_compile_unit die for CU.
10800 COMP_DIR is the compilation directory. LOWPC is passed to
10801 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10804 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10805 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10807 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10808 struct attribute
*attr
;
10809 struct line_header line_header_local
;
10810 hashval_t line_header_local_hash
;
10812 int decode_mapping
;
10814 gdb_assert (! cu
->per_cu
->is_debug_types
);
10816 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10820 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10822 /* The line header hash table is only created if needed (it exists to
10823 prevent redundant reading of the line table for partial_units).
10824 If we're given a partial_unit, we'll need it. If we're given a
10825 compile_unit, then use the line header hash table if it's already
10826 created, but don't create one just yet. */
10828 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
10829 && die
->tag
== DW_TAG_partial_unit
)
10831 dwarf2_per_objfile
->per_bfd
->line_header_hash
10832 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10833 line_header_eq_voidp
,
10834 free_line_header_voidp
,
10838 line_header_local
.sect_off
= line_offset
;
10839 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10840 line_header_local_hash
= line_header_hash (&line_header_local
);
10841 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
!= NULL
)
10843 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10844 &line_header_local
,
10845 line_header_local_hash
, NO_INSERT
);
10847 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10848 is not present in *SLOT (since if there is something in *SLOT then
10849 it will be for a partial_unit). */
10850 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10852 gdb_assert (*slot
!= NULL
);
10853 cu
->line_header
= (struct line_header
*) *slot
;
10858 /* dwarf_decode_line_header does not yet provide sufficient information.
10859 We always have to call also dwarf_decode_lines for it. */
10860 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10864 cu
->line_header
= lh
.release ();
10865 cu
->line_header_die_owner
= die
;
10867 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
)
10871 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10872 &line_header_local
,
10873 line_header_local_hash
, INSERT
);
10874 gdb_assert (slot
!= NULL
);
10876 if (slot
!= NULL
&& *slot
== NULL
)
10878 /* This newly decoded line number information unit will be owned
10879 by line_header_hash hash table. */
10880 *slot
= cu
->line_header
;
10881 cu
->line_header_die_owner
= NULL
;
10885 /* We cannot free any current entry in (*slot) as that struct line_header
10886 may be already used by multiple CUs. Create only temporary decoded
10887 line_header for this CU - it may happen at most once for each line
10888 number information unit. And if we're not using line_header_hash
10889 then this is what we want as well. */
10890 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10892 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10893 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10898 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10901 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10903 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10904 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10905 struct gdbarch
*gdbarch
= objfile
->arch ();
10906 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10907 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10908 struct attribute
*attr
;
10909 struct die_info
*child_die
;
10910 CORE_ADDR baseaddr
;
10912 prepare_one_comp_unit (cu
, die
, cu
->language
);
10913 baseaddr
= objfile
->text_section_offset ();
10915 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10917 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10918 from finish_block. */
10919 if (lowpc
== ((CORE_ADDR
) -1))
10921 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10923 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10925 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10926 standardised yet. As a workaround for the language detection we fall
10927 back to the DW_AT_producer string. */
10928 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10929 cu
->language
= language_opencl
;
10931 /* Similar hack for Go. */
10932 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10933 set_cu_language (DW_LANG_Go
, cu
);
10935 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10937 /* Decode line number information if present. We do this before
10938 processing child DIEs, so that the line header table is available
10939 for DW_AT_decl_file. */
10940 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10942 /* Process all dies in compilation unit. */
10943 if (die
->child
!= NULL
)
10945 child_die
= die
->child
;
10946 while (child_die
&& child_die
->tag
)
10948 process_die (child_die
, cu
);
10949 child_die
= child_die
->sibling
;
10953 /* Decode macro information, if present. Dwarf 2 macro information
10954 refers to information in the line number info statement program
10955 header, so we can only read it if we've read the header
10957 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10959 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10960 if (attr
&& cu
->line_header
)
10962 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10963 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10965 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10969 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10970 if (attr
&& cu
->line_header
)
10972 unsigned int macro_offset
= DW_UNSND (attr
);
10974 dwarf_decode_macros (cu
, macro_offset
, 0);
10980 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10982 struct type_unit_group
*tu_group
;
10984 struct attribute
*attr
;
10986 struct signatured_type
*sig_type
;
10988 gdb_assert (per_cu
->is_debug_types
);
10989 sig_type
= (struct signatured_type
*) per_cu
;
10991 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10993 /* If we're using .gdb_index (includes -readnow) then
10994 per_cu->type_unit_group may not have been set up yet. */
10995 if (sig_type
->type_unit_group
== NULL
)
10996 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10997 tu_group
= sig_type
->type_unit_group
;
10999 /* If we've already processed this stmt_list there's no real need to
11000 do it again, we could fake it and just recreate the part we need
11001 (file name,index -> symtab mapping). If data shows this optimization
11002 is useful we can do it then. */
11003 first_time
= tu_group
->compunit_symtab
== NULL
;
11005 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11010 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11011 lh
= dwarf_decode_line_header (line_offset
, this);
11016 start_symtab ("", NULL
, 0);
11019 gdb_assert (tu_group
->symtabs
== NULL
);
11020 gdb_assert (m_builder
== nullptr);
11021 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11022 m_builder
.reset (new struct buildsym_compunit
11023 (COMPUNIT_OBJFILE (cust
), "",
11024 COMPUNIT_DIRNAME (cust
),
11025 compunit_language (cust
),
11027 list_in_scope
= get_builder ()->get_file_symbols ();
11032 line_header
= lh
.release ();
11033 line_header_die_owner
= die
;
11037 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11039 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11040 still initializing it, and our caller (a few levels up)
11041 process_full_type_unit still needs to know if this is the first
11045 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11046 struct symtab
*, line_header
->file_names_size ());
11048 auto &file_names
= line_header
->file_names ();
11049 for (i
= 0; i
< file_names
.size (); ++i
)
11051 file_entry
&fe
= file_names
[i
];
11052 dwarf2_start_subfile (this, fe
.name
,
11053 fe
.include_dir (line_header
));
11054 buildsym_compunit
*b
= get_builder ();
11055 if (b
->get_current_subfile ()->symtab
== NULL
)
11057 /* NOTE: start_subfile will recognize when it's been
11058 passed a file it has already seen. So we can't
11059 assume there's a simple mapping from
11060 cu->line_header->file_names to subfiles, plus
11061 cu->line_header->file_names may contain dups. */
11062 b
->get_current_subfile ()->symtab
11063 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11066 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11067 tu_group
->symtabs
[i
] = fe
.symtab
;
11072 gdb_assert (m_builder
== nullptr);
11073 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11074 m_builder
.reset (new struct buildsym_compunit
11075 (COMPUNIT_OBJFILE (cust
), "",
11076 COMPUNIT_DIRNAME (cust
),
11077 compunit_language (cust
),
11079 list_in_scope
= get_builder ()->get_file_symbols ();
11081 auto &file_names
= line_header
->file_names ();
11082 for (i
= 0; i
< file_names
.size (); ++i
)
11084 file_entry
&fe
= file_names
[i
];
11085 fe
.symtab
= tu_group
->symtabs
[i
];
11089 /* The main symtab is allocated last. Type units don't have DW_AT_name
11090 so they don't have a "real" (so to speak) symtab anyway.
11091 There is later code that will assign the main symtab to all symbols
11092 that don't have one. We need to handle the case of a symbol with a
11093 missing symtab (DW_AT_decl_file) anyway. */
11096 /* Process DW_TAG_type_unit.
11097 For TUs we want to skip the first top level sibling if it's not the
11098 actual type being defined by this TU. In this case the first top
11099 level sibling is there to provide context only. */
11102 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11104 struct die_info
*child_die
;
11106 prepare_one_comp_unit (cu
, die
, language_minimal
);
11108 /* Initialize (or reinitialize) the machinery for building symtabs.
11109 We do this before processing child DIEs, so that the line header table
11110 is available for DW_AT_decl_file. */
11111 cu
->setup_type_unit_groups (die
);
11113 if (die
->child
!= NULL
)
11115 child_die
= die
->child
;
11116 while (child_die
&& child_die
->tag
)
11118 process_die (child_die
, cu
);
11119 child_die
= child_die
->sibling
;
11126 http://gcc.gnu.org/wiki/DebugFission
11127 http://gcc.gnu.org/wiki/DebugFissionDWP
11129 To simplify handling of both DWO files ("object" files with the DWARF info)
11130 and DWP files (a file with the DWOs packaged up into one file), we treat
11131 DWP files as having a collection of virtual DWO files. */
11134 hash_dwo_file (const void *item
)
11136 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11139 hash
= htab_hash_string (dwo_file
->dwo_name
);
11140 if (dwo_file
->comp_dir
!= NULL
)
11141 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11146 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11148 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11149 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11151 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11153 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11154 return lhs
->comp_dir
== rhs
->comp_dir
;
11155 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11158 /* Allocate a hash table for DWO files. */
11161 allocate_dwo_file_hash_table ()
11163 auto delete_dwo_file
= [] (void *item
)
11165 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11170 return htab_up (htab_create_alloc (41,
11177 /* Lookup DWO file DWO_NAME. */
11180 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11181 const char *dwo_name
,
11182 const char *comp_dir
)
11184 struct dwo_file find_entry
;
11187 if (dwarf2_per_objfile
->per_bfd
->dwo_files
== NULL
)
11188 dwarf2_per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11190 find_entry
.dwo_name
= dwo_name
;
11191 find_entry
.comp_dir
= comp_dir
;
11192 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11199 hash_dwo_unit (const void *item
)
11201 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11203 /* This drops the top 32 bits of the id, but is ok for a hash. */
11204 return dwo_unit
->signature
;
11208 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11210 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11211 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11213 /* The signature is assumed to be unique within the DWO file.
11214 So while object file CU dwo_id's always have the value zero,
11215 that's OK, assuming each object file DWO file has only one CU,
11216 and that's the rule for now. */
11217 return lhs
->signature
== rhs
->signature
;
11220 /* Allocate a hash table for DWO CUs,TUs.
11221 There is one of these tables for each of CUs,TUs for each DWO file. */
11224 allocate_dwo_unit_table ()
11226 /* Start out with a pretty small number.
11227 Generally DWO files contain only one CU and maybe some TUs. */
11228 return htab_up (htab_create_alloc (3,
11231 NULL
, xcalloc
, xfree
));
11234 /* die_reader_func for create_dwo_cu. */
11237 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11238 const gdb_byte
*info_ptr
,
11239 struct die_info
*comp_unit_die
,
11240 struct dwo_file
*dwo_file
,
11241 struct dwo_unit
*dwo_unit
)
11243 struct dwarf2_cu
*cu
= reader
->cu
;
11244 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11245 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11247 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11248 if (!signature
.has_value ())
11250 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11251 " its dwo_id [in module %s]"),
11252 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11256 dwo_unit
->dwo_file
= dwo_file
;
11257 dwo_unit
->signature
= *signature
;
11258 dwo_unit
->section
= section
;
11259 dwo_unit
->sect_off
= sect_off
;
11260 dwo_unit
->length
= cu
->per_cu
->length
;
11262 if (dwarf_read_debug
)
11263 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11264 sect_offset_str (sect_off
),
11265 hex_string (dwo_unit
->signature
));
11268 /* Create the dwo_units for the CUs in a DWO_FILE.
11269 Note: This function processes DWO files only, not DWP files. */
11272 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11273 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11274 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11276 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11277 const gdb_byte
*info_ptr
, *end_ptr
;
11279 section
.read (objfile
);
11280 info_ptr
= section
.buffer
;
11282 if (info_ptr
== NULL
)
11285 if (dwarf_read_debug
)
11287 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11288 section
.get_name (),
11289 section
.get_file_name ());
11292 end_ptr
= info_ptr
+ section
.size
;
11293 while (info_ptr
< end_ptr
)
11295 struct dwarf2_per_cu_data per_cu
;
11296 struct dwo_unit read_unit
{};
11297 struct dwo_unit
*dwo_unit
;
11299 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11301 memset (&per_cu
, 0, sizeof (per_cu
));
11302 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11303 per_cu
.is_debug_types
= 0;
11304 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11305 per_cu
.section
= §ion
;
11307 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11308 if (!reader
.dummy_p
)
11309 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11310 &dwo_file
, &read_unit
);
11311 info_ptr
+= per_cu
.length
;
11313 // If the unit could not be parsed, skip it.
11314 if (read_unit
.dwo_file
== NULL
)
11317 if (cus_htab
== NULL
)
11318 cus_htab
= allocate_dwo_unit_table ();
11320 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
11322 *dwo_unit
= read_unit
;
11323 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11324 gdb_assert (slot
!= NULL
);
11327 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11328 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11330 complaint (_("debug cu entry at offset %s is duplicate to"
11331 " the entry at offset %s, signature %s"),
11332 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11333 hex_string (dwo_unit
->signature
));
11335 *slot
= (void *)dwo_unit
;
11339 /* DWP file .debug_{cu,tu}_index section format:
11340 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11344 Both index sections have the same format, and serve to map a 64-bit
11345 signature to a set of section numbers. Each section begins with a header,
11346 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11347 indexes, and a pool of 32-bit section numbers. The index sections will be
11348 aligned at 8-byte boundaries in the file.
11350 The index section header consists of:
11352 V, 32 bit version number
11354 N, 32 bit number of compilation units or type units in the index
11355 M, 32 bit number of slots in the hash table
11357 Numbers are recorded using the byte order of the application binary.
11359 The hash table begins at offset 16 in the section, and consists of an array
11360 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11361 order of the application binary). Unused slots in the hash table are 0.
11362 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11364 The parallel table begins immediately after the hash table
11365 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11366 array of 32-bit indexes (using the byte order of the application binary),
11367 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11368 table contains a 32-bit index into the pool of section numbers. For unused
11369 hash table slots, the corresponding entry in the parallel table will be 0.
11371 The pool of section numbers begins immediately following the hash table
11372 (at offset 16 + 12 * M from the beginning of the section). The pool of
11373 section numbers consists of an array of 32-bit words (using the byte order
11374 of the application binary). Each item in the array is indexed starting
11375 from 0. The hash table entry provides the index of the first section
11376 number in the set. Additional section numbers in the set follow, and the
11377 set is terminated by a 0 entry (section number 0 is not used in ELF).
11379 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11380 section must be the first entry in the set, and the .debug_abbrev.dwo must
11381 be the second entry. Other members of the set may follow in any order.
11387 DWP Version 2 combines all the .debug_info, etc. sections into one,
11388 and the entries in the index tables are now offsets into these sections.
11389 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11392 Index Section Contents:
11394 Hash Table of Signatures dwp_hash_table.hash_table
11395 Parallel Table of Indices dwp_hash_table.unit_table
11396 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11397 Table of Section Sizes dwp_hash_table.v2.sizes
11399 The index section header consists of:
11401 V, 32 bit version number
11402 L, 32 bit number of columns in the table of section offsets
11403 N, 32 bit number of compilation units or type units in the index
11404 M, 32 bit number of slots in the hash table
11406 Numbers are recorded using the byte order of the application binary.
11408 The hash table has the same format as version 1.
11409 The parallel table of indices has the same format as version 1,
11410 except that the entries are origin-1 indices into the table of sections
11411 offsets and the table of section sizes.
11413 The table of offsets begins immediately following the parallel table
11414 (at offset 16 + 12 * M from the beginning of the section). The table is
11415 a two-dimensional array of 32-bit words (using the byte order of the
11416 application binary), with L columns and N+1 rows, in row-major order.
11417 Each row in the array is indexed starting from 0. The first row provides
11418 a key to the remaining rows: each column in this row provides an identifier
11419 for a debug section, and the offsets in the same column of subsequent rows
11420 refer to that section. The section identifiers are:
11422 DW_SECT_INFO 1 .debug_info.dwo
11423 DW_SECT_TYPES 2 .debug_types.dwo
11424 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11425 DW_SECT_LINE 4 .debug_line.dwo
11426 DW_SECT_LOC 5 .debug_loc.dwo
11427 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11428 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11429 DW_SECT_MACRO 8 .debug_macro.dwo
11431 The offsets provided by the CU and TU index sections are the base offsets
11432 for the contributions made by each CU or TU to the corresponding section
11433 in the package file. Each CU and TU header contains an abbrev_offset
11434 field, used to find the abbreviations table for that CU or TU within the
11435 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11436 be interpreted as relative to the base offset given in the index section.
11437 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11438 should be interpreted as relative to the base offset for .debug_line.dwo,
11439 and offsets into other debug sections obtained from DWARF attributes should
11440 also be interpreted as relative to the corresponding base offset.
11442 The table of sizes begins immediately following the table of offsets.
11443 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11444 with L columns and N rows, in row-major order. Each row in the array is
11445 indexed starting from 1 (row 0 is shared by the two tables).
11449 Hash table lookup is handled the same in version 1 and 2:
11451 We assume that N and M will not exceed 2^32 - 1.
11452 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11454 Given a 64-bit compilation unit signature or a type signature S, an entry
11455 in the hash table is located as follows:
11457 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11458 the low-order k bits all set to 1.
11460 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11462 3) If the hash table entry at index H matches the signature, use that
11463 entry. If the hash table entry at index H is unused (all zeroes),
11464 terminate the search: the signature is not present in the table.
11466 4) Let H = (H + H') modulo M. Repeat at Step 3.
11468 Because M > N and H' and M are relatively prime, the search is guaranteed
11469 to stop at an unused slot or find the match. */
11471 /* Create a hash table to map DWO IDs to their CU/TU entry in
11472 .debug_{info,types}.dwo in DWP_FILE.
11473 Returns NULL if there isn't one.
11474 Note: This function processes DWP files only, not DWO files. */
11476 static struct dwp_hash_table
*
11477 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11478 struct dwp_file
*dwp_file
, int is_debug_types
)
11480 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11481 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11482 const gdb_byte
*index_ptr
, *index_end
;
11483 struct dwarf2_section_info
*index
;
11484 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11485 struct dwp_hash_table
*htab
;
11487 if (is_debug_types
)
11488 index
= &dwp_file
->sections
.tu_index
;
11490 index
= &dwp_file
->sections
.cu_index
;
11492 if (index
->empty ())
11494 index
->read (objfile
);
11496 index_ptr
= index
->buffer
;
11497 index_end
= index_ptr
+ index
->size
;
11499 version
= read_4_bytes (dbfd
, index_ptr
);
11502 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11506 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11508 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11511 if (version
!= 1 && version
!= 2)
11513 error (_("Dwarf Error: unsupported DWP file version (%s)"
11514 " [in module %s]"),
11515 pulongest (version
), dwp_file
->name
);
11517 if (nr_slots
!= (nr_slots
& -nr_slots
))
11519 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11520 " is not power of 2 [in module %s]"),
11521 pulongest (nr_slots
), dwp_file
->name
);
11524 htab
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11525 htab
->version
= version
;
11526 htab
->nr_columns
= nr_columns
;
11527 htab
->nr_units
= nr_units
;
11528 htab
->nr_slots
= nr_slots
;
11529 htab
->hash_table
= index_ptr
;
11530 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11532 /* Exit early if the table is empty. */
11533 if (nr_slots
== 0 || nr_units
== 0
11534 || (version
== 2 && nr_columns
== 0))
11536 /* All must be zero. */
11537 if (nr_slots
!= 0 || nr_units
!= 0
11538 || (version
== 2 && nr_columns
!= 0))
11540 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11541 " all zero [in modules %s]"),
11549 htab
->section_pool
.v1
.indices
=
11550 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11551 /* It's harder to decide whether the section is too small in v1.
11552 V1 is deprecated anyway so we punt. */
11556 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11557 int *ids
= htab
->section_pool
.v2
.section_ids
;
11558 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11559 /* Reverse map for error checking. */
11560 int ids_seen
[DW_SECT_MAX
+ 1];
11563 if (nr_columns
< 2)
11565 error (_("Dwarf Error: bad DWP hash table, too few columns"
11566 " in section table [in module %s]"),
11569 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11571 error (_("Dwarf Error: bad DWP hash table, too many columns"
11572 " in section table [in module %s]"),
11575 memset (ids
, 255, sizeof_ids
);
11576 memset (ids_seen
, 255, sizeof (ids_seen
));
11577 for (i
= 0; i
< nr_columns
; ++i
)
11579 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11581 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11583 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11584 " in section table [in module %s]"),
11585 id
, dwp_file
->name
);
11587 if (ids_seen
[id
] != -1)
11589 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11590 " id %d in section table [in module %s]"),
11591 id
, dwp_file
->name
);
11596 /* Must have exactly one info or types section. */
11597 if (((ids_seen
[DW_SECT_INFO
] != -1)
11598 + (ids_seen
[DW_SECT_TYPES
] != -1))
11601 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11602 " DWO info/types section [in module %s]"),
11605 /* Must have an abbrev section. */
11606 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11608 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11609 " section [in module %s]"),
11612 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11613 htab
->section_pool
.v2
.sizes
=
11614 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11615 * nr_units
* nr_columns
);
11616 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11617 * nr_units
* nr_columns
))
11620 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11621 " [in module %s]"),
11629 /* Update SECTIONS with the data from SECTP.
11631 This function is like the other "locate" section routines that are
11632 passed to bfd_map_over_sections, but in this context the sections to
11633 read comes from the DWP V1 hash table, not the full ELF section table.
11635 The result is non-zero for success, or zero if an error was found. */
11638 locate_v1_virtual_dwo_sections (asection
*sectp
,
11639 struct virtual_v1_dwo_sections
*sections
)
11641 const struct dwop_section_names
*names
= &dwop_section_names
;
11643 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11645 /* There can be only one. */
11646 if (sections
->abbrev
.s
.section
!= NULL
)
11648 sections
->abbrev
.s
.section
= sectp
;
11649 sections
->abbrev
.size
= bfd_section_size (sectp
);
11651 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11652 || section_is_p (sectp
->name
, &names
->types_dwo
))
11654 /* There can be only one. */
11655 if (sections
->info_or_types
.s
.section
!= NULL
)
11657 sections
->info_or_types
.s
.section
= sectp
;
11658 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11660 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11662 /* There can be only one. */
11663 if (sections
->line
.s
.section
!= NULL
)
11665 sections
->line
.s
.section
= sectp
;
11666 sections
->line
.size
= bfd_section_size (sectp
);
11668 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11670 /* There can be only one. */
11671 if (sections
->loc
.s
.section
!= NULL
)
11673 sections
->loc
.s
.section
= sectp
;
11674 sections
->loc
.size
= bfd_section_size (sectp
);
11676 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11678 /* There can be only one. */
11679 if (sections
->macinfo
.s
.section
!= NULL
)
11681 sections
->macinfo
.s
.section
= sectp
;
11682 sections
->macinfo
.size
= bfd_section_size (sectp
);
11684 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11686 /* There can be only one. */
11687 if (sections
->macro
.s
.section
!= NULL
)
11689 sections
->macro
.s
.section
= sectp
;
11690 sections
->macro
.size
= bfd_section_size (sectp
);
11692 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11694 /* There can be only one. */
11695 if (sections
->str_offsets
.s
.section
!= NULL
)
11697 sections
->str_offsets
.s
.section
= sectp
;
11698 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11702 /* No other kind of section is valid. */
11709 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11710 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11711 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11712 This is for DWP version 1 files. */
11714 static struct dwo_unit
*
11715 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11716 struct dwp_file
*dwp_file
,
11717 uint32_t unit_index
,
11718 const char *comp_dir
,
11719 ULONGEST signature
, int is_debug_types
)
11721 const struct dwp_hash_table
*dwp_htab
=
11722 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11723 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11724 const char *kind
= is_debug_types
? "TU" : "CU";
11725 struct dwo_file
*dwo_file
;
11726 struct dwo_unit
*dwo_unit
;
11727 struct virtual_v1_dwo_sections sections
;
11728 void **dwo_file_slot
;
11731 gdb_assert (dwp_file
->version
== 1);
11733 if (dwarf_read_debug
)
11735 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11737 pulongest (unit_index
), hex_string (signature
),
11741 /* Fetch the sections of this DWO unit.
11742 Put a limit on the number of sections we look for so that bad data
11743 doesn't cause us to loop forever. */
11745 #define MAX_NR_V1_DWO_SECTIONS \
11746 (1 /* .debug_info or .debug_types */ \
11747 + 1 /* .debug_abbrev */ \
11748 + 1 /* .debug_line */ \
11749 + 1 /* .debug_loc */ \
11750 + 1 /* .debug_str_offsets */ \
11751 + 1 /* .debug_macro or .debug_macinfo */ \
11752 + 1 /* trailing zero */)
11754 memset (§ions
, 0, sizeof (sections
));
11756 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11759 uint32_t section_nr
=
11760 read_4_bytes (dbfd
,
11761 dwp_htab
->section_pool
.v1
.indices
11762 + (unit_index
+ i
) * sizeof (uint32_t));
11764 if (section_nr
== 0)
11766 if (section_nr
>= dwp_file
->num_sections
)
11768 error (_("Dwarf Error: bad DWP hash table, section number too large"
11769 " [in module %s]"),
11773 sectp
= dwp_file
->elf_sections
[section_nr
];
11774 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11776 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11777 " [in module %s]"),
11783 || sections
.info_or_types
.empty ()
11784 || sections
.abbrev
.empty ())
11786 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11787 " [in module %s]"),
11790 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11792 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11793 " [in module %s]"),
11797 /* It's easier for the rest of the code if we fake a struct dwo_file and
11798 have dwo_unit "live" in that. At least for now.
11800 The DWP file can be made up of a random collection of CUs and TUs.
11801 However, for each CU + set of TUs that came from the same original DWO
11802 file, we can combine them back into a virtual DWO file to save space
11803 (fewer struct dwo_file objects to allocate). Remember that for really
11804 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11806 std::string virtual_dwo_name
=
11807 string_printf ("virtual-dwo/%d-%d-%d-%d",
11808 sections
.abbrev
.get_id (),
11809 sections
.line
.get_id (),
11810 sections
.loc
.get_id (),
11811 sections
.str_offsets
.get_id ());
11812 /* Can we use an existing virtual DWO file? */
11813 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11814 virtual_dwo_name
.c_str (),
11816 /* Create one if necessary. */
11817 if (*dwo_file_slot
== NULL
)
11819 if (dwarf_read_debug
)
11821 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11822 virtual_dwo_name
.c_str ());
11824 dwo_file
= new struct dwo_file
;
11825 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
11826 dwo_file
->comp_dir
= comp_dir
;
11827 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11828 dwo_file
->sections
.line
= sections
.line
;
11829 dwo_file
->sections
.loc
= sections
.loc
;
11830 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11831 dwo_file
->sections
.macro
= sections
.macro
;
11832 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11833 /* The "str" section is global to the entire DWP file. */
11834 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11835 /* The info or types section is assigned below to dwo_unit,
11836 there's no need to record it in dwo_file.
11837 Also, we can't simply record type sections in dwo_file because
11838 we record a pointer into the vector in dwo_unit. As we collect more
11839 types we'll grow the vector and eventually have to reallocate space
11840 for it, invalidating all copies of pointers into the previous
11842 *dwo_file_slot
= dwo_file
;
11846 if (dwarf_read_debug
)
11848 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11849 virtual_dwo_name
.c_str ());
11851 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11854 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11855 dwo_unit
->dwo_file
= dwo_file
;
11856 dwo_unit
->signature
= signature
;
11857 dwo_unit
->section
=
11858 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11859 *dwo_unit
->section
= sections
.info_or_types
;
11860 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11865 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11866 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11867 piece within that section used by a TU/CU, return a virtual section
11868 of just that piece. */
11870 static struct dwarf2_section_info
11871 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11872 struct dwarf2_section_info
*section
,
11873 bfd_size_type offset
, bfd_size_type size
)
11875 struct dwarf2_section_info result
;
11878 gdb_assert (section
!= NULL
);
11879 gdb_assert (!section
->is_virtual
);
11881 memset (&result
, 0, sizeof (result
));
11882 result
.s
.containing_section
= section
;
11883 result
.is_virtual
= true;
11888 sectp
= section
->get_bfd_section ();
11890 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11891 bounds of the real section. This is a pretty-rare event, so just
11892 flag an error (easier) instead of a warning and trying to cope. */
11894 || offset
+ size
> bfd_section_size (sectp
))
11896 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11897 " in section %s [in module %s]"),
11898 sectp
? bfd_section_name (sectp
) : "<unknown>",
11899 objfile_name (dwarf2_per_objfile
->objfile
));
11902 result
.virtual_offset
= offset
;
11903 result
.size
= size
;
11907 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11908 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11909 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11910 This is for DWP version 2 files. */
11912 static struct dwo_unit
*
11913 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11914 struct dwp_file
*dwp_file
,
11915 uint32_t unit_index
,
11916 const char *comp_dir
,
11917 ULONGEST signature
, int is_debug_types
)
11919 const struct dwp_hash_table
*dwp_htab
=
11920 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11921 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11922 const char *kind
= is_debug_types
? "TU" : "CU";
11923 struct dwo_file
*dwo_file
;
11924 struct dwo_unit
*dwo_unit
;
11925 struct virtual_v2_dwo_sections sections
;
11926 void **dwo_file_slot
;
11929 gdb_assert (dwp_file
->version
== 2);
11931 if (dwarf_read_debug
)
11933 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11935 pulongest (unit_index
), hex_string (signature
),
11939 /* Fetch the section offsets of this DWO unit. */
11941 memset (§ions
, 0, sizeof (sections
));
11943 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11945 uint32_t offset
= read_4_bytes (dbfd
,
11946 dwp_htab
->section_pool
.v2
.offsets
11947 + (((unit_index
- 1) * dwp_htab
->nr_columns
11949 * sizeof (uint32_t)));
11950 uint32_t size
= read_4_bytes (dbfd
,
11951 dwp_htab
->section_pool
.v2
.sizes
11952 + (((unit_index
- 1) * dwp_htab
->nr_columns
11954 * sizeof (uint32_t)));
11956 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11959 case DW_SECT_TYPES
:
11960 sections
.info_or_types_offset
= offset
;
11961 sections
.info_or_types_size
= size
;
11963 case DW_SECT_ABBREV
:
11964 sections
.abbrev_offset
= offset
;
11965 sections
.abbrev_size
= size
;
11968 sections
.line_offset
= offset
;
11969 sections
.line_size
= size
;
11972 sections
.loc_offset
= offset
;
11973 sections
.loc_size
= size
;
11975 case DW_SECT_STR_OFFSETS
:
11976 sections
.str_offsets_offset
= offset
;
11977 sections
.str_offsets_size
= size
;
11979 case DW_SECT_MACINFO
:
11980 sections
.macinfo_offset
= offset
;
11981 sections
.macinfo_size
= size
;
11983 case DW_SECT_MACRO
:
11984 sections
.macro_offset
= offset
;
11985 sections
.macro_size
= size
;
11990 /* It's easier for the rest of the code if we fake a struct dwo_file and
11991 have dwo_unit "live" in that. At least for now.
11993 The DWP file can be made up of a random collection of CUs and TUs.
11994 However, for each CU + set of TUs that came from the same original DWO
11995 file, we can combine them back into a virtual DWO file to save space
11996 (fewer struct dwo_file objects to allocate). Remember that for really
11997 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11999 std::string virtual_dwo_name
=
12000 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12001 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12002 (long) (sections
.line_size
? sections
.line_offset
: 0),
12003 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12004 (long) (sections
.str_offsets_size
12005 ? sections
.str_offsets_offset
: 0));
12006 /* Can we use an existing virtual DWO file? */
12007 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12008 virtual_dwo_name
.c_str (),
12010 /* Create one if necessary. */
12011 if (*dwo_file_slot
== NULL
)
12013 if (dwarf_read_debug
)
12015 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12016 virtual_dwo_name
.c_str ());
12018 dwo_file
= new struct dwo_file
;
12019 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
12020 dwo_file
->comp_dir
= comp_dir
;
12021 dwo_file
->sections
.abbrev
=
12022 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12023 sections
.abbrev_offset
, sections
.abbrev_size
);
12024 dwo_file
->sections
.line
=
12025 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12026 sections
.line_offset
, sections
.line_size
);
12027 dwo_file
->sections
.loc
=
12028 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12029 sections
.loc_offset
, sections
.loc_size
);
12030 dwo_file
->sections
.macinfo
=
12031 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12032 sections
.macinfo_offset
, sections
.macinfo_size
);
12033 dwo_file
->sections
.macro
=
12034 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12035 sections
.macro_offset
, sections
.macro_size
);
12036 dwo_file
->sections
.str_offsets
=
12037 create_dwp_v2_section (dwarf2_per_objfile
,
12038 &dwp_file
->sections
.str_offsets
,
12039 sections
.str_offsets_offset
,
12040 sections
.str_offsets_size
);
12041 /* The "str" section is global to the entire DWP file. */
12042 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12043 /* The info or types section is assigned below to dwo_unit,
12044 there's no need to record it in dwo_file.
12045 Also, we can't simply record type sections in dwo_file because
12046 we record a pointer into the vector in dwo_unit. As we collect more
12047 types we'll grow the vector and eventually have to reallocate space
12048 for it, invalidating all copies of pointers into the previous
12050 *dwo_file_slot
= dwo_file
;
12054 if (dwarf_read_debug
)
12056 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12057 virtual_dwo_name
.c_str ());
12059 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12062 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12063 dwo_unit
->dwo_file
= dwo_file
;
12064 dwo_unit
->signature
= signature
;
12065 dwo_unit
->section
=
12066 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12067 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12069 ? &dwp_file
->sections
.types
12070 : &dwp_file
->sections
.info
,
12071 sections
.info_or_types_offset
,
12072 sections
.info_or_types_size
);
12073 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12078 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12079 Returns NULL if the signature isn't found. */
12081 static struct dwo_unit
*
12082 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12083 struct dwp_file
*dwp_file
, const char *comp_dir
,
12084 ULONGEST signature
, int is_debug_types
)
12086 const struct dwp_hash_table
*dwp_htab
=
12087 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12088 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12089 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12090 uint32_t hash
= signature
& mask
;
12091 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12094 struct dwo_unit find_dwo_cu
;
12096 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12097 find_dwo_cu
.signature
= signature
;
12098 slot
= htab_find_slot (is_debug_types
12099 ? dwp_file
->loaded_tus
.get ()
12100 : dwp_file
->loaded_cus
.get (),
12101 &find_dwo_cu
, INSERT
);
12104 return (struct dwo_unit
*) *slot
;
12106 /* Use a for loop so that we don't loop forever on bad debug info. */
12107 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12109 ULONGEST signature_in_table
;
12111 signature_in_table
=
12112 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12113 if (signature_in_table
== signature
)
12115 uint32_t unit_index
=
12116 read_4_bytes (dbfd
,
12117 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12119 if (dwp_file
->version
== 1)
12121 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12122 dwp_file
, unit_index
,
12123 comp_dir
, signature
,
12128 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12129 dwp_file
, unit_index
,
12130 comp_dir
, signature
,
12133 return (struct dwo_unit
*) *slot
;
12135 if (signature_in_table
== 0)
12137 hash
= (hash
+ hash2
) & mask
;
12140 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12141 " [in module %s]"),
12145 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12146 Open the file specified by FILE_NAME and hand it off to BFD for
12147 preliminary analysis. Return a newly initialized bfd *, which
12148 includes a canonicalized copy of FILE_NAME.
12149 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12150 SEARCH_CWD is true if the current directory is to be searched.
12151 It will be searched before debug-file-directory.
12152 If successful, the file is added to the bfd include table of the
12153 objfile's bfd (see gdb_bfd_record_inclusion).
12154 If unable to find/open the file, return NULL.
12155 NOTE: This function is derived from symfile_bfd_open. */
12157 static gdb_bfd_ref_ptr
12158 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12159 const char *file_name
, int is_dwp
, int search_cwd
)
12162 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12163 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12164 to debug_file_directory. */
12165 const char *search_path
;
12166 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12168 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12171 if (*debug_file_directory
!= '\0')
12173 search_path_holder
.reset (concat (".", dirname_separator_string
,
12174 debug_file_directory
,
12176 search_path
= search_path_holder
.get ();
12182 search_path
= debug_file_directory
;
12184 openp_flags flags
= OPF_RETURN_REALPATH
;
12186 flags
|= OPF_SEARCH_IN_PATH
;
12188 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12189 desc
= openp (search_path
, flags
, file_name
,
12190 O_RDONLY
| O_BINARY
, &absolute_name
);
12194 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12196 if (sym_bfd
== NULL
)
12198 bfd_set_cacheable (sym_bfd
.get (), 1);
12200 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12203 /* Success. Record the bfd as having been included by the objfile's bfd.
12204 This is important because things like demangled_names_hash lives in the
12205 objfile's per_bfd space and may have references to things like symbol
12206 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12207 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12212 /* Try to open DWO file FILE_NAME.
12213 COMP_DIR is the DW_AT_comp_dir attribute.
12214 The result is the bfd handle of the file.
12215 If there is a problem finding or opening the file, return NULL.
12216 Upon success, the canonicalized path of the file is stored in the bfd,
12217 same as symfile_bfd_open. */
12219 static gdb_bfd_ref_ptr
12220 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12221 const char *file_name
, const char *comp_dir
)
12223 if (IS_ABSOLUTE_PATH (file_name
))
12224 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12225 0 /*is_dwp*/, 0 /*search_cwd*/);
12227 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12229 if (comp_dir
!= NULL
)
12231 gdb::unique_xmalloc_ptr
<char> path_to_try
12232 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12234 /* NOTE: If comp_dir is a relative path, this will also try the
12235 search path, which seems useful. */
12236 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12237 path_to_try
.get (),
12239 1 /*search_cwd*/));
12244 /* That didn't work, try debug-file-directory, which, despite its name,
12245 is a list of paths. */
12247 if (*debug_file_directory
== '\0')
12250 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12251 0 /*is_dwp*/, 1 /*search_cwd*/);
12254 /* This function is mapped across the sections and remembers the offset and
12255 size of each of the DWO debugging sections we are interested in. */
12258 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12260 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12261 const struct dwop_section_names
*names
= &dwop_section_names
;
12263 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12265 dwo_sections
->abbrev
.s
.section
= sectp
;
12266 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12268 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12270 dwo_sections
->info
.s
.section
= sectp
;
12271 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12273 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12275 dwo_sections
->line
.s
.section
= sectp
;
12276 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12278 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12280 dwo_sections
->loc
.s
.section
= sectp
;
12281 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12283 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12285 dwo_sections
->loclists
.s
.section
= sectp
;
12286 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12288 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12290 dwo_sections
->macinfo
.s
.section
= sectp
;
12291 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12293 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12295 dwo_sections
->macro
.s
.section
= sectp
;
12296 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12298 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12300 dwo_sections
->str
.s
.section
= sectp
;
12301 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12303 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12305 dwo_sections
->str_offsets
.s
.section
= sectp
;
12306 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12308 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12310 struct dwarf2_section_info type_section
;
12312 memset (&type_section
, 0, sizeof (type_section
));
12313 type_section
.s
.section
= sectp
;
12314 type_section
.size
= bfd_section_size (sectp
);
12315 dwo_sections
->types
.push_back (type_section
);
12319 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12320 by PER_CU. This is for the non-DWP case.
12321 The result is NULL if DWO_NAME can't be found. */
12323 static struct dwo_file
*
12324 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12325 const char *dwo_name
, const char *comp_dir
)
12327 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12329 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12332 if (dwarf_read_debug
)
12333 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12337 dwo_file_up
dwo_file (new struct dwo_file
);
12338 dwo_file
->dwo_name
= dwo_name
;
12339 dwo_file
->comp_dir
= comp_dir
;
12340 dwo_file
->dbfd
= std::move (dbfd
);
12342 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12343 &dwo_file
->sections
);
12345 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12346 dwo_file
->sections
.info
, dwo_file
->cus
);
12348 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12349 dwo_file
->sections
.types
, dwo_file
->tus
);
12351 if (dwarf_read_debug
)
12352 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12354 return dwo_file
.release ();
12357 /* This function is mapped across the sections and remembers the offset and
12358 size of each of the DWP debugging sections common to version 1 and 2 that
12359 we are interested in. */
12362 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12363 void *dwp_file_ptr
)
12365 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12366 const struct dwop_section_names
*names
= &dwop_section_names
;
12367 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12369 /* Record the ELF section number for later lookup: this is what the
12370 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12371 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12372 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12374 /* Look for specific sections that we need. */
12375 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12377 dwp_file
->sections
.str
.s
.section
= sectp
;
12378 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12380 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12382 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12383 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12385 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12387 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12388 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12392 /* This function is mapped across the sections and remembers the offset and
12393 size of each of the DWP version 2 debugging sections that we are interested
12394 in. This is split into a separate function because we don't know if we
12395 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12398 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12400 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12401 const struct dwop_section_names
*names
= &dwop_section_names
;
12402 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12404 /* Record the ELF section number for later lookup: this is what the
12405 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12406 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12407 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12409 /* Look for specific sections that we need. */
12410 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12412 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12413 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12415 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12417 dwp_file
->sections
.info
.s
.section
= sectp
;
12418 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12420 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12422 dwp_file
->sections
.line
.s
.section
= sectp
;
12423 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12425 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12427 dwp_file
->sections
.loc
.s
.section
= sectp
;
12428 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12430 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12432 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12433 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12435 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12437 dwp_file
->sections
.macro
.s
.section
= sectp
;
12438 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12440 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12442 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12443 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12445 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12447 dwp_file
->sections
.types
.s
.section
= sectp
;
12448 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12452 /* Hash function for dwp_file loaded CUs/TUs. */
12455 hash_dwp_loaded_cutus (const void *item
)
12457 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12459 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12460 return dwo_unit
->signature
;
12463 /* Equality function for dwp_file loaded CUs/TUs. */
12466 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12468 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12469 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12471 return dua
->signature
== dub
->signature
;
12474 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12477 allocate_dwp_loaded_cutus_table ()
12479 return htab_up (htab_create_alloc (3,
12480 hash_dwp_loaded_cutus
,
12481 eq_dwp_loaded_cutus
,
12482 NULL
, xcalloc
, xfree
));
12485 /* Try to open DWP file FILE_NAME.
12486 The result is the bfd handle of the file.
12487 If there is a problem finding or opening the file, return NULL.
12488 Upon success, the canonicalized path of the file is stored in the bfd,
12489 same as symfile_bfd_open. */
12491 static gdb_bfd_ref_ptr
12492 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12493 const char *file_name
)
12495 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12497 1 /*search_cwd*/));
12501 /* Work around upstream bug 15652.
12502 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12503 [Whether that's a "bug" is debatable, but it is getting in our way.]
12504 We have no real idea where the dwp file is, because gdb's realpath-ing
12505 of the executable's path may have discarded the needed info.
12506 [IWBN if the dwp file name was recorded in the executable, akin to
12507 .gnu_debuglink, but that doesn't exist yet.]
12508 Strip the directory from FILE_NAME and search again. */
12509 if (*debug_file_directory
!= '\0')
12511 /* Don't implicitly search the current directory here.
12512 If the user wants to search "." to handle this case,
12513 it must be added to debug-file-directory. */
12514 return try_open_dwop_file (dwarf2_per_objfile
,
12515 lbasename (file_name
), 1 /*is_dwp*/,
12522 /* Initialize the use of the DWP file for the current objfile.
12523 By convention the name of the DWP file is ${objfile}.dwp.
12524 The result is NULL if it can't be found. */
12526 static std::unique_ptr
<struct dwp_file
>
12527 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12529 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12531 /* Try to find first .dwp for the binary file before any symbolic links
12534 /* If the objfile is a debug file, find the name of the real binary
12535 file and get the name of dwp file from there. */
12536 std::string dwp_name
;
12537 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12539 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12540 const char *backlink_basename
= lbasename (backlink
->original_name
);
12542 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12545 dwp_name
= objfile
->original_name
;
12547 dwp_name
+= ".dwp";
12549 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12551 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12553 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12554 dwp_name
= objfile_name (objfile
);
12555 dwp_name
+= ".dwp";
12556 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12561 if (dwarf_read_debug
)
12562 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12563 return std::unique_ptr
<dwp_file
> ();
12566 const char *name
= bfd_get_filename (dbfd
.get ());
12567 std::unique_ptr
<struct dwp_file
> dwp_file
12568 (new struct dwp_file (name
, std::move (dbfd
)));
12570 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12571 dwp_file
->elf_sections
=
12572 OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
12573 dwp_file
->num_sections
, asection
*);
12575 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12576 dwarf2_locate_common_dwp_sections
,
12579 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12582 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12585 /* The DWP file version is stored in the hash table. Oh well. */
12586 if (dwp_file
->cus
&& dwp_file
->tus
12587 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12589 /* Technically speaking, we should try to limp along, but this is
12590 pretty bizarre. We use pulongest here because that's the established
12591 portability solution (e.g, we cannot use %u for uint32_t). */
12592 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12593 " TU version %s [in DWP file %s]"),
12594 pulongest (dwp_file
->cus
->version
),
12595 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12599 dwp_file
->version
= dwp_file
->cus
->version
;
12600 else if (dwp_file
->tus
)
12601 dwp_file
->version
= dwp_file
->tus
->version
;
12603 dwp_file
->version
= 2;
12605 if (dwp_file
->version
== 2)
12606 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12607 dwarf2_locate_v2_dwp_sections
,
12610 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12611 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12613 if (dwarf_read_debug
)
12615 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12616 fprintf_unfiltered (gdb_stdlog
,
12617 " %s CUs, %s TUs\n",
12618 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12619 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12625 /* Wrapper around open_and_init_dwp_file, only open it once. */
12627 static struct dwp_file
*
12628 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12630 if (! dwarf2_per_objfile
->per_bfd
->dwp_checked
)
12632 dwarf2_per_objfile
->per_bfd
->dwp_file
12633 = open_and_init_dwp_file (dwarf2_per_objfile
);
12634 dwarf2_per_objfile
->per_bfd
->dwp_checked
= 1;
12636 return dwarf2_per_objfile
->per_bfd
->dwp_file
.get ();
12639 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12640 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12641 or in the DWP file for the objfile, referenced by THIS_UNIT.
12642 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12643 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12645 This is called, for example, when wanting to read a variable with a
12646 complex location. Therefore we don't want to do file i/o for every call.
12647 Therefore we don't want to look for a DWO file on every call.
12648 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12649 then we check if we've already seen DWO_NAME, and only THEN do we check
12652 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12653 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12655 static struct dwo_unit
*
12656 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12657 const char *dwo_name
, const char *comp_dir
,
12658 ULONGEST signature
, int is_debug_types
)
12660 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12661 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12662 const char *kind
= is_debug_types
? "TU" : "CU";
12663 void **dwo_file_slot
;
12664 struct dwo_file
*dwo_file
;
12665 struct dwp_file
*dwp_file
;
12667 /* First see if there's a DWP file.
12668 If we have a DWP file but didn't find the DWO inside it, don't
12669 look for the original DWO file. It makes gdb behave differently
12670 depending on whether one is debugging in the build tree. */
12672 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12673 if (dwp_file
!= NULL
)
12675 const struct dwp_hash_table
*dwp_htab
=
12676 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12678 if (dwp_htab
!= NULL
)
12680 struct dwo_unit
*dwo_cutu
=
12681 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12682 signature
, is_debug_types
);
12684 if (dwo_cutu
!= NULL
)
12686 if (dwarf_read_debug
)
12688 fprintf_unfiltered (gdb_stdlog
,
12689 "Virtual DWO %s %s found: @%s\n",
12690 kind
, hex_string (signature
),
12691 host_address_to_string (dwo_cutu
));
12699 /* No DWP file, look for the DWO file. */
12701 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12702 dwo_name
, comp_dir
);
12703 if (*dwo_file_slot
== NULL
)
12705 /* Read in the file and build a table of the CUs/TUs it contains. */
12706 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12708 /* NOTE: This will be NULL if unable to open the file. */
12709 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12711 if (dwo_file
!= NULL
)
12713 struct dwo_unit
*dwo_cutu
= NULL
;
12715 if (is_debug_types
&& dwo_file
->tus
)
12717 struct dwo_unit find_dwo_cutu
;
12719 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12720 find_dwo_cutu
.signature
= signature
;
12722 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12725 else if (!is_debug_types
&& dwo_file
->cus
)
12727 struct dwo_unit find_dwo_cutu
;
12729 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12730 find_dwo_cutu
.signature
= signature
;
12731 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12735 if (dwo_cutu
!= NULL
)
12737 if (dwarf_read_debug
)
12739 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12740 kind
, dwo_name
, hex_string (signature
),
12741 host_address_to_string (dwo_cutu
));
12748 /* We didn't find it. This could mean a dwo_id mismatch, or
12749 someone deleted the DWO/DWP file, or the search path isn't set up
12750 correctly to find the file. */
12752 if (dwarf_read_debug
)
12754 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12755 kind
, dwo_name
, hex_string (signature
));
12758 /* This is a warning and not a complaint because it can be caused by
12759 pilot error (e.g., user accidentally deleting the DWO). */
12761 /* Print the name of the DWP file if we looked there, helps the user
12762 better diagnose the problem. */
12763 std::string dwp_text
;
12765 if (dwp_file
!= NULL
)
12766 dwp_text
= string_printf (" [in DWP file %s]",
12767 lbasename (dwp_file
->name
));
12769 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12770 " [in module %s]"),
12771 kind
, dwo_name
, hex_string (signature
),
12773 this_unit
->is_debug_types
? "TU" : "CU",
12774 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12779 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12780 See lookup_dwo_cutu_unit for details. */
12782 static struct dwo_unit
*
12783 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12784 const char *dwo_name
, const char *comp_dir
,
12785 ULONGEST signature
)
12787 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12790 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12791 See lookup_dwo_cutu_unit for details. */
12793 static struct dwo_unit
*
12794 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12795 const char *dwo_name
, const char *comp_dir
)
12797 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12800 /* Traversal function for queue_and_load_all_dwo_tus. */
12803 queue_and_load_dwo_tu (void **slot
, void *info
)
12805 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12806 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12807 ULONGEST signature
= dwo_unit
->signature
;
12808 struct signatured_type
*sig_type
=
12809 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12811 if (sig_type
!= NULL
)
12813 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12815 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12816 a real dependency of PER_CU on SIG_TYPE. That is detected later
12817 while processing PER_CU. */
12818 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12819 load_full_type_unit (sig_cu
);
12820 per_cu
->imported_symtabs_push (sig_cu
);
12826 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12827 The DWO may have the only definition of the type, though it may not be
12828 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12829 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12832 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12834 struct dwo_unit
*dwo_unit
;
12835 struct dwo_file
*dwo_file
;
12837 gdb_assert (!per_cu
->is_debug_types
);
12838 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12839 gdb_assert (per_cu
->cu
!= NULL
);
12841 dwo_unit
= per_cu
->cu
->dwo_unit
;
12842 gdb_assert (dwo_unit
!= NULL
);
12844 dwo_file
= dwo_unit
->dwo_file
;
12845 if (dwo_file
->tus
!= NULL
)
12846 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12850 /* Read in various DIEs. */
12852 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12853 Inherit only the children of the DW_AT_abstract_origin DIE not being
12854 already referenced by DW_AT_abstract_origin from the children of the
12858 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12860 struct die_info
*child_die
;
12861 sect_offset
*offsetp
;
12862 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12863 struct die_info
*origin_die
;
12864 /* Iterator of the ORIGIN_DIE children. */
12865 struct die_info
*origin_child_die
;
12866 struct attribute
*attr
;
12867 struct dwarf2_cu
*origin_cu
;
12868 struct pending
**origin_previous_list_in_scope
;
12870 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12874 /* Note that following die references may follow to a die in a
12878 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12880 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12882 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12883 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12885 if (die
->tag
!= origin_die
->tag
12886 && !(die
->tag
== DW_TAG_inlined_subroutine
12887 && origin_die
->tag
== DW_TAG_subprogram
))
12888 complaint (_("DIE %s and its abstract origin %s have different tags"),
12889 sect_offset_str (die
->sect_off
),
12890 sect_offset_str (origin_die
->sect_off
));
12892 std::vector
<sect_offset
> offsets
;
12894 for (child_die
= die
->child
;
12895 child_die
&& child_die
->tag
;
12896 child_die
= child_die
->sibling
)
12898 struct die_info
*child_origin_die
;
12899 struct dwarf2_cu
*child_origin_cu
;
12901 /* We are trying to process concrete instance entries:
12902 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12903 it's not relevant to our analysis here. i.e. detecting DIEs that are
12904 present in the abstract instance but not referenced in the concrete
12906 if (child_die
->tag
== DW_TAG_call_site
12907 || child_die
->tag
== DW_TAG_GNU_call_site
)
12910 /* For each CHILD_DIE, find the corresponding child of
12911 ORIGIN_DIE. If there is more than one layer of
12912 DW_AT_abstract_origin, follow them all; there shouldn't be,
12913 but GCC versions at least through 4.4 generate this (GCC PR
12915 child_origin_die
= child_die
;
12916 child_origin_cu
= cu
;
12919 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12923 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12927 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12928 counterpart may exist. */
12929 if (child_origin_die
!= child_die
)
12931 if (child_die
->tag
!= child_origin_die
->tag
12932 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12933 && child_origin_die
->tag
== DW_TAG_subprogram
))
12934 complaint (_("Child DIE %s and its abstract origin %s have "
12936 sect_offset_str (child_die
->sect_off
),
12937 sect_offset_str (child_origin_die
->sect_off
));
12938 if (child_origin_die
->parent
!= origin_die
)
12939 complaint (_("Child DIE %s and its abstract origin %s have "
12940 "different parents"),
12941 sect_offset_str (child_die
->sect_off
),
12942 sect_offset_str (child_origin_die
->sect_off
));
12944 offsets
.push_back (child_origin_die
->sect_off
);
12947 std::sort (offsets
.begin (), offsets
.end ());
12948 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12949 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12950 if (offsetp
[-1] == *offsetp
)
12951 complaint (_("Multiple children of DIE %s refer "
12952 "to DIE %s as their abstract origin"),
12953 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12955 offsetp
= offsets
.data ();
12956 origin_child_die
= origin_die
->child
;
12957 while (origin_child_die
&& origin_child_die
->tag
)
12959 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12960 while (offsetp
< offsets_end
12961 && *offsetp
< origin_child_die
->sect_off
)
12963 if (offsetp
>= offsets_end
12964 || *offsetp
> origin_child_die
->sect_off
)
12966 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12967 Check whether we're already processing ORIGIN_CHILD_DIE.
12968 This can happen with mutually referenced abstract_origins.
12970 if (!origin_child_die
->in_process
)
12971 process_die (origin_child_die
, origin_cu
);
12973 origin_child_die
= origin_child_die
->sibling
;
12975 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12977 if (cu
!= origin_cu
)
12978 compute_delayed_physnames (origin_cu
);
12982 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12984 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12985 struct gdbarch
*gdbarch
= objfile
->arch ();
12986 struct context_stack
*newobj
;
12989 struct die_info
*child_die
;
12990 struct attribute
*attr
, *call_line
, *call_file
;
12992 CORE_ADDR baseaddr
;
12993 struct block
*block
;
12994 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12995 std::vector
<struct symbol
*> template_args
;
12996 struct template_symbol
*templ_func
= NULL
;
13000 /* If we do not have call site information, we can't show the
13001 caller of this inlined function. That's too confusing, so
13002 only use the scope for local variables. */
13003 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13004 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13005 if (call_line
== NULL
|| call_file
== NULL
)
13007 read_lexical_block_scope (die
, cu
);
13012 baseaddr
= objfile
->text_section_offset ();
13014 name
= dwarf2_name (die
, cu
);
13016 /* Ignore functions with missing or empty names. These are actually
13017 illegal according to the DWARF standard. */
13020 complaint (_("missing name for subprogram DIE at %s"),
13021 sect_offset_str (die
->sect_off
));
13025 /* Ignore functions with missing or invalid low and high pc attributes. */
13026 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13027 <= PC_BOUNDS_INVALID
)
13029 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13030 if (!attr
|| !DW_UNSND (attr
))
13031 complaint (_("cannot get low and high bounds "
13032 "for subprogram DIE at %s"),
13033 sect_offset_str (die
->sect_off
));
13037 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13038 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13040 /* If we have any template arguments, then we must allocate a
13041 different sort of symbol. */
13042 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13044 if (child_die
->tag
== DW_TAG_template_type_param
13045 || child_die
->tag
== DW_TAG_template_value_param
)
13047 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13048 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13053 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13054 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13055 (struct symbol
*) templ_func
);
13057 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13058 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13061 /* If there is a location expression for DW_AT_frame_base, record
13063 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13064 if (attr
!= nullptr)
13065 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13067 /* If there is a location for the static link, record it. */
13068 newobj
->static_link
= NULL
;
13069 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13070 if (attr
!= nullptr)
13072 newobj
->static_link
13073 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13074 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13075 cu
->per_cu
->addr_type ());
13078 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13080 if (die
->child
!= NULL
)
13082 child_die
= die
->child
;
13083 while (child_die
&& child_die
->tag
)
13085 if (child_die
->tag
== DW_TAG_template_type_param
13086 || child_die
->tag
== DW_TAG_template_value_param
)
13088 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13091 template_args
.push_back (arg
);
13094 process_die (child_die
, cu
);
13095 child_die
= child_die
->sibling
;
13099 inherit_abstract_dies (die
, cu
);
13101 /* If we have a DW_AT_specification, we might need to import using
13102 directives from the context of the specification DIE. See the
13103 comment in determine_prefix. */
13104 if (cu
->language
== language_cplus
13105 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13107 struct dwarf2_cu
*spec_cu
= cu
;
13108 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13112 child_die
= spec_die
->child
;
13113 while (child_die
&& child_die
->tag
)
13115 if (child_die
->tag
== DW_TAG_imported_module
)
13116 process_die (child_die
, spec_cu
);
13117 child_die
= child_die
->sibling
;
13120 /* In some cases, GCC generates specification DIEs that
13121 themselves contain DW_AT_specification attributes. */
13122 spec_die
= die_specification (spec_die
, &spec_cu
);
13126 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13127 /* Make a block for the local symbols within. */
13128 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13129 cstk
.static_link
, lowpc
, highpc
);
13131 /* For C++, set the block's scope. */
13132 if ((cu
->language
== language_cplus
13133 || cu
->language
== language_fortran
13134 || cu
->language
== language_d
13135 || cu
->language
== language_rust
)
13136 && cu
->processing_has_namespace_info
)
13137 block_set_scope (block
, determine_prefix (die
, cu
),
13138 &objfile
->objfile_obstack
);
13140 /* If we have address ranges, record them. */
13141 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13143 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13145 /* Attach template arguments to function. */
13146 if (!template_args
.empty ())
13148 gdb_assert (templ_func
!= NULL
);
13150 templ_func
->n_template_arguments
= template_args
.size ();
13151 templ_func
->template_arguments
13152 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13153 templ_func
->n_template_arguments
);
13154 memcpy (templ_func
->template_arguments
,
13155 template_args
.data (),
13156 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13158 /* Make sure that the symtab is set on the new symbols. Even
13159 though they don't appear in this symtab directly, other parts
13160 of gdb assume that symbols do, and this is reasonably
13162 for (symbol
*sym
: template_args
)
13163 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13166 /* In C++, we can have functions nested inside functions (e.g., when
13167 a function declares a class that has methods). This means that
13168 when we finish processing a function scope, we may need to go
13169 back to building a containing block's symbol lists. */
13170 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13171 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13173 /* If we've finished processing a top-level function, subsequent
13174 symbols go in the file symbol list. */
13175 if (cu
->get_builder ()->outermost_context_p ())
13176 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13179 /* Process all the DIES contained within a lexical block scope. Start
13180 a new scope, process the dies, and then close the scope. */
13183 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13185 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13186 struct gdbarch
*gdbarch
= objfile
->arch ();
13187 CORE_ADDR lowpc
, highpc
;
13188 struct die_info
*child_die
;
13189 CORE_ADDR baseaddr
;
13191 baseaddr
= objfile
->text_section_offset ();
13193 /* Ignore blocks with missing or invalid low and high pc attributes. */
13194 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13195 as multiple lexical blocks? Handling children in a sane way would
13196 be nasty. Might be easier to properly extend generic blocks to
13197 describe ranges. */
13198 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13200 case PC_BOUNDS_NOT_PRESENT
:
13201 /* DW_TAG_lexical_block has no attributes, process its children as if
13202 there was no wrapping by that DW_TAG_lexical_block.
13203 GCC does no longer produces such DWARF since GCC r224161. */
13204 for (child_die
= die
->child
;
13205 child_die
!= NULL
&& child_die
->tag
;
13206 child_die
= child_die
->sibling
)
13208 /* We might already be processing this DIE. This can happen
13209 in an unusual circumstance -- where a subroutine A
13210 appears lexically in another subroutine B, but A actually
13211 inlines B. The recursion is broken here, rather than in
13212 inherit_abstract_dies, because it seems better to simply
13213 drop concrete children here. */
13214 if (!child_die
->in_process
)
13215 process_die (child_die
, cu
);
13218 case PC_BOUNDS_INVALID
:
13221 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13222 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13224 cu
->get_builder ()->push_context (0, lowpc
);
13225 if (die
->child
!= NULL
)
13227 child_die
= die
->child
;
13228 while (child_die
&& child_die
->tag
)
13230 process_die (child_die
, cu
);
13231 child_die
= child_die
->sibling
;
13234 inherit_abstract_dies (die
, cu
);
13235 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13237 if (*cu
->get_builder ()->get_local_symbols () != NULL
13238 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13240 struct block
*block
13241 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13242 cstk
.start_addr
, highpc
);
13244 /* Note that recording ranges after traversing children, as we
13245 do here, means that recording a parent's ranges entails
13246 walking across all its children's ranges as they appear in
13247 the address map, which is quadratic behavior.
13249 It would be nicer to record the parent's ranges before
13250 traversing its children, simply overriding whatever you find
13251 there. But since we don't even decide whether to create a
13252 block until after we've traversed its children, that's hard
13254 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13256 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13257 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13260 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13263 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13265 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13266 struct objfile
*objfile
= per_objfile
->objfile
;
13267 struct gdbarch
*gdbarch
= objfile
->arch ();
13268 CORE_ADDR pc
, baseaddr
;
13269 struct attribute
*attr
;
13270 struct call_site
*call_site
, call_site_local
;
13273 struct die_info
*child_die
;
13275 baseaddr
= objfile
->text_section_offset ();
13277 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13280 /* This was a pre-DWARF-5 GNU extension alias
13281 for DW_AT_call_return_pc. */
13282 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13286 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13287 "DIE %s [in module %s]"),
13288 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13291 pc
= attr
->value_as_address () + baseaddr
;
13292 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13294 if (cu
->call_site_htab
== NULL
)
13295 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13296 NULL
, &objfile
->objfile_obstack
,
13297 hashtab_obstack_allocate
, NULL
);
13298 call_site_local
.pc
= pc
;
13299 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13302 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13303 "DIE %s [in module %s]"),
13304 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13305 objfile_name (objfile
));
13309 /* Count parameters at the caller. */
13312 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13313 child_die
= child_die
->sibling
)
13315 if (child_die
->tag
!= DW_TAG_call_site_parameter
13316 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13318 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13319 "DW_TAG_call_site child DIE %s [in module %s]"),
13320 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13321 objfile_name (objfile
));
13329 = ((struct call_site
*)
13330 obstack_alloc (&objfile
->objfile_obstack
,
13331 sizeof (*call_site
)
13332 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13334 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13335 call_site
->pc
= pc
;
13337 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13338 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13340 struct die_info
*func_die
;
13342 /* Skip also over DW_TAG_inlined_subroutine. */
13343 for (func_die
= die
->parent
;
13344 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13345 && func_die
->tag
!= DW_TAG_subroutine_type
;
13346 func_die
= func_die
->parent
);
13348 /* DW_AT_call_all_calls is a superset
13349 of DW_AT_call_all_tail_calls. */
13351 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13352 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13353 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13354 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13356 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13357 not complete. But keep CALL_SITE for look ups via call_site_htab,
13358 both the initial caller containing the real return address PC and
13359 the final callee containing the current PC of a chain of tail
13360 calls do not need to have the tail call list complete. But any
13361 function candidate for a virtual tail call frame searched via
13362 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13363 determined unambiguously. */
13367 struct type
*func_type
= NULL
;
13370 func_type
= get_die_type (func_die
, cu
);
13371 if (func_type
!= NULL
)
13373 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13375 /* Enlist this call site to the function. */
13376 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13377 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13380 complaint (_("Cannot find function owning DW_TAG_call_site "
13381 "DIE %s [in module %s]"),
13382 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13386 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13388 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13390 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13393 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13394 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13396 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13397 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13398 /* Keep NULL DWARF_BLOCK. */;
13399 else if (attr
->form_is_block ())
13401 struct dwarf2_locexpr_baton
*dlbaton
;
13403 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13404 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13405 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13406 dlbaton
->per_objfile
= per_objfile
;
13407 dlbaton
->per_cu
= cu
->per_cu
;
13409 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13411 else if (attr
->form_is_ref ())
13413 struct dwarf2_cu
*target_cu
= cu
;
13414 struct die_info
*target_die
;
13416 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13417 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13418 if (die_is_declaration (target_die
, target_cu
))
13420 const char *target_physname
;
13422 /* Prefer the mangled name; otherwise compute the demangled one. */
13423 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13424 if (target_physname
== NULL
)
13425 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13426 if (target_physname
== NULL
)
13427 complaint (_("DW_AT_call_target target DIE has invalid "
13428 "physname, for referencing DIE %s [in module %s]"),
13429 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13431 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13437 /* DW_AT_entry_pc should be preferred. */
13438 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13439 <= PC_BOUNDS_INVALID
)
13440 complaint (_("DW_AT_call_target target DIE has invalid "
13441 "low pc, for referencing DIE %s [in module %s]"),
13442 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13445 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13446 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13451 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13452 "block nor reference, for DIE %s [in module %s]"),
13453 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13455 call_site
->per_cu
= cu
->per_cu
;
13457 for (child_die
= die
->child
;
13458 child_die
&& child_die
->tag
;
13459 child_die
= child_die
->sibling
)
13461 struct call_site_parameter
*parameter
;
13462 struct attribute
*loc
, *origin
;
13464 if (child_die
->tag
!= DW_TAG_call_site_parameter
13465 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13467 /* Already printed the complaint above. */
13471 gdb_assert (call_site
->parameter_count
< nparams
);
13472 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13474 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13475 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13476 register is contained in DW_AT_call_value. */
13478 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13479 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13480 if (origin
== NULL
)
13482 /* This was a pre-DWARF-5 GNU extension alias
13483 for DW_AT_call_parameter. */
13484 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13486 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13488 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13490 sect_offset sect_off
= origin
->get_ref_die_offset ();
13491 if (!cu
->header
.offset_in_cu_p (sect_off
))
13493 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13494 binding can be done only inside one CU. Such referenced DIE
13495 therefore cannot be even moved to DW_TAG_partial_unit. */
13496 complaint (_("DW_AT_call_parameter offset is not in CU for "
13497 "DW_TAG_call_site child DIE %s [in module %s]"),
13498 sect_offset_str (child_die
->sect_off
),
13499 objfile_name (objfile
));
13502 parameter
->u
.param_cu_off
13503 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13505 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13507 complaint (_("No DW_FORM_block* DW_AT_location for "
13508 "DW_TAG_call_site child DIE %s [in module %s]"),
13509 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13514 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13515 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13516 if (parameter
->u
.dwarf_reg
!= -1)
13517 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13518 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13519 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13520 ¶meter
->u
.fb_offset
))
13521 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13524 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13525 "for DW_FORM_block* DW_AT_location is supported for "
13526 "DW_TAG_call_site child DIE %s "
13528 sect_offset_str (child_die
->sect_off
),
13529 objfile_name (objfile
));
13534 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13536 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13537 if (attr
== NULL
|| !attr
->form_is_block ())
13539 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13540 "DW_TAG_call_site child DIE %s [in module %s]"),
13541 sect_offset_str (child_die
->sect_off
),
13542 objfile_name (objfile
));
13545 parameter
->value
= DW_BLOCK (attr
)->data
;
13546 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13548 /* Parameters are not pre-cleared by memset above. */
13549 parameter
->data_value
= NULL
;
13550 parameter
->data_value_size
= 0;
13551 call_site
->parameter_count
++;
13553 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13555 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13556 if (attr
!= nullptr)
13558 if (!attr
->form_is_block ())
13559 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13560 "DW_TAG_call_site child DIE %s [in module %s]"),
13561 sect_offset_str (child_die
->sect_off
),
13562 objfile_name (objfile
));
13565 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13566 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13572 /* Helper function for read_variable. If DIE represents a virtual
13573 table, then return the type of the concrete object that is
13574 associated with the virtual table. Otherwise, return NULL. */
13576 static struct type
*
13577 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13579 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13583 /* Find the type DIE. */
13584 struct die_info
*type_die
= NULL
;
13585 struct dwarf2_cu
*type_cu
= cu
;
13587 if (attr
->form_is_ref ())
13588 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13589 if (type_die
== NULL
)
13592 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13594 return die_containing_type (type_die
, type_cu
);
13597 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13600 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13602 struct rust_vtable_symbol
*storage
= NULL
;
13604 if (cu
->language
== language_rust
)
13606 struct type
*containing_type
= rust_containing_type (die
, cu
);
13608 if (containing_type
!= NULL
)
13610 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13612 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13613 storage
->concrete_type
= containing_type
;
13614 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13618 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13619 struct attribute
*abstract_origin
13620 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13621 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13622 if (res
== NULL
&& loc
&& abstract_origin
)
13624 /* We have a variable without a name, but with a location and an abstract
13625 origin. This may be a concrete instance of an abstract variable
13626 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13628 struct dwarf2_cu
*origin_cu
= cu
;
13629 struct die_info
*origin_die
13630 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13631 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13632 per_objfile
->per_bfd
->abstract_to_concrete
13633 [origin_die
->sect_off
].push_back (die
->sect_off
);
13637 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13638 reading .debug_rnglists.
13639 Callback's type should be:
13640 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13641 Return true if the attributes are present and valid, otherwise,
13644 template <typename Callback
>
13646 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13647 Callback
&&callback
)
13649 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
13650 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13651 bfd
*obfd
= objfile
->obfd
;
13652 /* Base address selection entry. */
13653 gdb::optional
<CORE_ADDR
> base
;
13654 const gdb_byte
*buffer
;
13655 CORE_ADDR baseaddr
;
13656 bool overflow
= false;
13658 base
= cu
->base_address
;
13660 dwarf2_per_objfile
->per_bfd
->rnglists
.read (objfile
);
13661 if (offset
>= dwarf2_per_objfile
->per_bfd
->rnglists
.size
)
13663 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13667 buffer
= dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13669 baseaddr
= objfile
->text_section_offset ();
13673 /* Initialize it due to a false compiler warning. */
13674 CORE_ADDR range_beginning
= 0, range_end
= 0;
13675 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
13676 + dwarf2_per_objfile
->per_bfd
->rnglists
.size
);
13677 unsigned int bytes_read
;
13679 if (buffer
== buf_end
)
13684 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13687 case DW_RLE_end_of_list
:
13689 case DW_RLE_base_address
:
13690 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13695 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13696 buffer
+= bytes_read
;
13698 case DW_RLE_start_length
:
13699 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13704 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13706 buffer
+= bytes_read
;
13707 range_end
= (range_beginning
13708 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13709 buffer
+= bytes_read
;
13710 if (buffer
> buf_end
)
13716 case DW_RLE_offset_pair
:
13717 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13718 buffer
+= bytes_read
;
13719 if (buffer
> buf_end
)
13724 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13725 buffer
+= bytes_read
;
13726 if (buffer
> buf_end
)
13732 case DW_RLE_start_end
:
13733 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13738 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13740 buffer
+= bytes_read
;
13741 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13742 buffer
+= bytes_read
;
13745 complaint (_("Invalid .debug_rnglists data (no base address)"));
13748 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13750 if (rlet
== DW_RLE_base_address
)
13753 if (!base
.has_value ())
13755 /* We have no valid base address for the ranges
13757 complaint (_("Invalid .debug_rnglists data (no base address)"));
13761 if (range_beginning
> range_end
)
13763 /* Inverted range entries are invalid. */
13764 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13768 /* Empty range entries have no effect. */
13769 if (range_beginning
== range_end
)
13772 range_beginning
+= *base
;
13773 range_end
+= *base
;
13775 /* A not-uncommon case of bad debug info.
13776 Don't pollute the addrmap with bad data. */
13777 if (range_beginning
+ baseaddr
== 0
13778 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
13780 complaint (_(".debug_rnglists entry has start address of zero"
13781 " [in module %s]"), objfile_name (objfile
));
13785 callback (range_beginning
, range_end
);
13790 complaint (_("Offset %d is not terminated "
13791 "for DW_AT_ranges attribute"),
13799 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13800 Callback's type should be:
13801 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13802 Return 1 if the attributes are present and valid, otherwise, return 0. */
13804 template <typename Callback
>
13806 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13807 Callback
&&callback
)
13809 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13810 struct objfile
*objfile
= per_objfile
->objfile
;
13811 struct comp_unit_head
*cu_header
= &cu
->header
;
13812 bfd
*obfd
= objfile
->obfd
;
13813 unsigned int addr_size
= cu_header
->addr_size
;
13814 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13815 /* Base address selection entry. */
13816 gdb::optional
<CORE_ADDR
> base
;
13817 unsigned int dummy
;
13818 const gdb_byte
*buffer
;
13819 CORE_ADDR baseaddr
;
13821 if (cu_header
->version
>= 5)
13822 return dwarf2_rnglists_process (offset
, cu
, callback
);
13824 base
= cu
->base_address
;
13826 per_objfile
->per_bfd
->ranges
.read (objfile
);
13827 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13829 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13833 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13835 baseaddr
= objfile
->text_section_offset ();
13839 CORE_ADDR range_beginning
, range_end
;
13841 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13842 buffer
+= addr_size
;
13843 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13844 buffer
+= addr_size
;
13845 offset
+= 2 * addr_size
;
13847 /* An end of list marker is a pair of zero addresses. */
13848 if (range_beginning
== 0 && range_end
== 0)
13849 /* Found the end of list entry. */
13852 /* Each base address selection entry is a pair of 2 values.
13853 The first is the largest possible address, the second is
13854 the base address. Check for a base address here. */
13855 if ((range_beginning
& mask
) == mask
)
13857 /* If we found the largest possible address, then we already
13858 have the base address in range_end. */
13863 if (!base
.has_value ())
13865 /* We have no valid base address for the ranges
13867 complaint (_("Invalid .debug_ranges data (no base address)"));
13871 if (range_beginning
> range_end
)
13873 /* Inverted range entries are invalid. */
13874 complaint (_("Invalid .debug_ranges data (inverted range)"));
13878 /* Empty range entries have no effect. */
13879 if (range_beginning
== range_end
)
13882 range_beginning
+= *base
;
13883 range_end
+= *base
;
13885 /* A not-uncommon case of bad debug info.
13886 Don't pollute the addrmap with bad data. */
13887 if (range_beginning
+ baseaddr
== 0
13888 && !per_objfile
->per_bfd
->has_section_at_zero
)
13890 complaint (_(".debug_ranges entry has start address of zero"
13891 " [in module %s]"), objfile_name (objfile
));
13895 callback (range_beginning
, range_end
);
13901 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13902 Return 1 if the attributes are present and valid, otherwise, return 0.
13903 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13906 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13907 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13908 dwarf2_psymtab
*ranges_pst
)
13910 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13911 struct gdbarch
*gdbarch
= objfile
->arch ();
13912 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13915 CORE_ADDR high
= 0;
13918 retval
= dwarf2_ranges_process (offset
, cu
,
13919 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13921 if (ranges_pst
!= NULL
)
13926 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13927 range_beginning
+ baseaddr
)
13929 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13930 range_end
+ baseaddr
)
13932 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13933 lowpc
, highpc
- 1, ranges_pst
);
13936 /* FIXME: This is recording everything as a low-high
13937 segment of consecutive addresses. We should have a
13938 data structure for discontiguous block ranges
13942 low
= range_beginning
;
13948 if (range_beginning
< low
)
13949 low
= range_beginning
;
13950 if (range_end
> high
)
13958 /* If the first entry is an end-of-list marker, the range
13959 describes an empty scope, i.e. no instructions. */
13965 *high_return
= high
;
13969 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13970 definition for the return value. *LOWPC and *HIGHPC are set iff
13971 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13973 static enum pc_bounds_kind
13974 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13975 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13976 dwarf2_psymtab
*pst
)
13978 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
13979 struct attribute
*attr
;
13980 struct attribute
*attr_high
;
13982 CORE_ADDR high
= 0;
13983 enum pc_bounds_kind ret
;
13985 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13988 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13989 if (attr
!= nullptr)
13991 low
= attr
->value_as_address ();
13992 high
= attr_high
->value_as_address ();
13993 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13997 /* Found high w/o low attribute. */
13998 return PC_BOUNDS_INVALID
;
14000 /* Found consecutive range of addresses. */
14001 ret
= PC_BOUNDS_HIGH_LOW
;
14005 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14008 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14009 We take advantage of the fact that DW_AT_ranges does not appear
14010 in DW_TAG_compile_unit of DWO files. */
14011 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14012 unsigned int ranges_offset
= (DW_UNSND (attr
)
14013 + (need_ranges_base
14017 /* Value of the DW_AT_ranges attribute is the offset in the
14018 .debug_ranges section. */
14019 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14020 return PC_BOUNDS_INVALID
;
14021 /* Found discontinuous range of addresses. */
14022 ret
= PC_BOUNDS_RANGES
;
14025 return PC_BOUNDS_NOT_PRESENT
;
14028 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14030 return PC_BOUNDS_INVALID
;
14032 /* When using the GNU linker, .gnu.linkonce. sections are used to
14033 eliminate duplicate copies of functions and vtables and such.
14034 The linker will arbitrarily choose one and discard the others.
14035 The AT_*_pc values for such functions refer to local labels in
14036 these sections. If the section from that file was discarded, the
14037 labels are not in the output, so the relocs get a value of 0.
14038 If this is a discarded function, mark the pc bounds as invalid,
14039 so that GDB will ignore it. */
14040 if (low
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
14041 return PC_BOUNDS_INVALID
;
14049 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14050 its low and high PC addresses. Do nothing if these addresses could not
14051 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14052 and HIGHPC to the high address if greater than HIGHPC. */
14055 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14056 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14057 struct dwarf2_cu
*cu
)
14059 CORE_ADDR low
, high
;
14060 struct die_info
*child
= die
->child
;
14062 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14064 *lowpc
= std::min (*lowpc
, low
);
14065 *highpc
= std::max (*highpc
, high
);
14068 /* If the language does not allow nested subprograms (either inside
14069 subprograms or lexical blocks), we're done. */
14070 if (cu
->language
!= language_ada
)
14073 /* Check all the children of the given DIE. If it contains nested
14074 subprograms, then check their pc bounds. Likewise, we need to
14075 check lexical blocks as well, as they may also contain subprogram
14077 while (child
&& child
->tag
)
14079 if (child
->tag
== DW_TAG_subprogram
14080 || child
->tag
== DW_TAG_lexical_block
)
14081 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14082 child
= child
->sibling
;
14086 /* Get the low and high pc's represented by the scope DIE, and store
14087 them in *LOWPC and *HIGHPC. If the correct values can't be
14088 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14091 get_scope_pc_bounds (struct die_info
*die
,
14092 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14093 struct dwarf2_cu
*cu
)
14095 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14096 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14097 CORE_ADDR current_low
, current_high
;
14099 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14100 >= PC_BOUNDS_RANGES
)
14102 best_low
= current_low
;
14103 best_high
= current_high
;
14107 struct die_info
*child
= die
->child
;
14109 while (child
&& child
->tag
)
14111 switch (child
->tag
) {
14112 case DW_TAG_subprogram
:
14113 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14115 case DW_TAG_namespace
:
14116 case DW_TAG_module
:
14117 /* FIXME: carlton/2004-01-16: Should we do this for
14118 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14119 that current GCC's always emit the DIEs corresponding
14120 to definitions of methods of classes as children of a
14121 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14122 the DIEs giving the declarations, which could be
14123 anywhere). But I don't see any reason why the
14124 standards says that they have to be there. */
14125 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14127 if (current_low
!= ((CORE_ADDR
) -1))
14129 best_low
= std::min (best_low
, current_low
);
14130 best_high
= std::max (best_high
, current_high
);
14138 child
= child
->sibling
;
14143 *highpc
= best_high
;
14146 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14150 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14151 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14153 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14154 struct gdbarch
*gdbarch
= objfile
->arch ();
14155 struct attribute
*attr
;
14156 struct attribute
*attr_high
;
14158 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14161 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14162 if (attr
!= nullptr)
14164 CORE_ADDR low
= attr
->value_as_address ();
14165 CORE_ADDR high
= attr_high
->value_as_address ();
14167 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14170 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14171 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14172 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14176 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14177 if (attr
!= nullptr)
14179 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14180 We take advantage of the fact that DW_AT_ranges does not appear
14181 in DW_TAG_compile_unit of DWO files. */
14182 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14184 /* The value of the DW_AT_ranges attribute is the offset of the
14185 address range list in the .debug_ranges section. */
14186 unsigned long offset
= (DW_UNSND (attr
)
14187 + (need_ranges_base
? cu
->ranges_base
: 0));
14189 std::vector
<blockrange
> blockvec
;
14190 dwarf2_ranges_process (offset
, cu
,
14191 [&] (CORE_ADDR start
, CORE_ADDR end
)
14195 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14196 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14197 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14198 blockvec
.emplace_back (start
, end
);
14201 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14205 /* Check whether the producer field indicates either of GCC < 4.6, or the
14206 Intel C/C++ compiler, and cache the result in CU. */
14209 check_producer (struct dwarf2_cu
*cu
)
14213 if (cu
->producer
== NULL
)
14215 /* For unknown compilers expect their behavior is DWARF version
14218 GCC started to support .debug_types sections by -gdwarf-4 since
14219 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14220 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14221 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14222 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14224 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14226 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14227 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14229 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14231 cu
->producer_is_icc
= true;
14232 cu
->producer_is_icc_lt_14
= major
< 14;
14234 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14235 cu
->producer_is_codewarrior
= true;
14238 /* For other non-GCC compilers, expect their behavior is DWARF version
14242 cu
->checked_producer
= true;
14245 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14246 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14247 during 4.6.0 experimental. */
14250 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14252 if (!cu
->checked_producer
)
14253 check_producer (cu
);
14255 return cu
->producer_is_gxx_lt_4_6
;
14259 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14260 with incorrect is_stmt attributes. */
14263 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14265 if (!cu
->checked_producer
)
14266 check_producer (cu
);
14268 return cu
->producer_is_codewarrior
;
14271 /* Return the default accessibility type if it is not overridden by
14272 DW_AT_accessibility. */
14274 static enum dwarf_access_attribute
14275 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14277 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14279 /* The default DWARF 2 accessibility for members is public, the default
14280 accessibility for inheritance is private. */
14282 if (die
->tag
!= DW_TAG_inheritance
)
14283 return DW_ACCESS_public
;
14285 return DW_ACCESS_private
;
14289 /* DWARF 3+ defines the default accessibility a different way. The same
14290 rules apply now for DW_TAG_inheritance as for the members and it only
14291 depends on the container kind. */
14293 if (die
->parent
->tag
== DW_TAG_class_type
)
14294 return DW_ACCESS_private
;
14296 return DW_ACCESS_public
;
14300 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14301 offset. If the attribute was not found return 0, otherwise return
14302 1. If it was found but could not properly be handled, set *OFFSET
14306 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14309 struct attribute
*attr
;
14311 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14316 /* Note that we do not check for a section offset first here.
14317 This is because DW_AT_data_member_location is new in DWARF 4,
14318 so if we see it, we can assume that a constant form is really
14319 a constant and not a section offset. */
14320 if (attr
->form_is_constant ())
14321 *offset
= attr
->constant_value (0);
14322 else if (attr
->form_is_section_offset ())
14323 dwarf2_complex_location_expr_complaint ();
14324 else if (attr
->form_is_block ())
14325 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14327 dwarf2_complex_location_expr_complaint ();
14335 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14338 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14339 struct field
*field
)
14341 struct attribute
*attr
;
14343 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14346 if (attr
->form_is_constant ())
14348 LONGEST offset
= attr
->constant_value (0);
14349 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14351 else if (attr
->form_is_section_offset ())
14352 dwarf2_complex_location_expr_complaint ();
14353 else if (attr
->form_is_block ())
14356 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14358 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14361 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14362 struct objfile
*objfile
= per_objfile
->objfile
;
14363 struct dwarf2_locexpr_baton
*dlbaton
14364 = XOBNEW (&objfile
->objfile_obstack
,
14365 struct dwarf2_locexpr_baton
);
14366 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14367 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14368 /* When using this baton, we want to compute the address
14369 of the field, not the value. This is why
14370 is_reference is set to false here. */
14371 dlbaton
->is_reference
= false;
14372 dlbaton
->per_objfile
= per_objfile
;
14373 dlbaton
->per_cu
= cu
->per_cu
;
14375 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14379 dwarf2_complex_location_expr_complaint ();
14383 /* Add an aggregate field to the field list. */
14386 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14387 struct dwarf2_cu
*cu
)
14389 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14390 struct gdbarch
*gdbarch
= objfile
->arch ();
14391 struct nextfield
*new_field
;
14392 struct attribute
*attr
;
14394 const char *fieldname
= "";
14396 if (die
->tag
== DW_TAG_inheritance
)
14398 fip
->baseclasses
.emplace_back ();
14399 new_field
= &fip
->baseclasses
.back ();
14403 fip
->fields
.emplace_back ();
14404 new_field
= &fip
->fields
.back ();
14407 new_field
->offset
= die
->sect_off
;
14409 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14410 if (attr
!= nullptr)
14411 new_field
->accessibility
= DW_UNSND (attr
);
14413 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14414 if (new_field
->accessibility
!= DW_ACCESS_public
)
14415 fip
->non_public_fields
= 1;
14417 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14418 if (attr
!= nullptr)
14419 new_field
->virtuality
= DW_UNSND (attr
);
14421 new_field
->virtuality
= DW_VIRTUALITY_none
;
14423 fp
= &new_field
->field
;
14425 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14427 /* Data member other than a C++ static data member. */
14429 /* Get type of field. */
14430 fp
->type
= die_type (die
, cu
);
14432 SET_FIELD_BITPOS (*fp
, 0);
14434 /* Get bit size of field (zero if none). */
14435 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14436 if (attr
!= nullptr)
14438 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14442 FIELD_BITSIZE (*fp
) = 0;
14445 /* Get bit offset of field. */
14446 handle_data_member_location (die
, cu
, fp
);
14447 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14448 if (attr
!= nullptr)
14450 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14452 /* For big endian bits, the DW_AT_bit_offset gives the
14453 additional bit offset from the MSB of the containing
14454 anonymous object to the MSB of the field. We don't
14455 have to do anything special since we don't need to
14456 know the size of the anonymous object. */
14457 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14461 /* For little endian bits, compute the bit offset to the
14462 MSB of the anonymous object, subtract off the number of
14463 bits from the MSB of the field to the MSB of the
14464 object, and then subtract off the number of bits of
14465 the field itself. The result is the bit offset of
14466 the LSB of the field. */
14467 int anonymous_size
;
14468 int bit_offset
= DW_UNSND (attr
);
14470 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14471 if (attr
!= nullptr)
14473 /* The size of the anonymous object containing
14474 the bit field is explicit, so use the
14475 indicated size (in bytes). */
14476 anonymous_size
= DW_UNSND (attr
);
14480 /* The size of the anonymous object containing
14481 the bit field must be inferred from the type
14482 attribute of the data member containing the
14484 anonymous_size
= TYPE_LENGTH (fp
->type
);
14486 SET_FIELD_BITPOS (*fp
,
14487 (FIELD_BITPOS (*fp
)
14488 + anonymous_size
* bits_per_byte
14489 - bit_offset
- FIELD_BITSIZE (*fp
)));
14492 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14494 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14495 + attr
->constant_value (0)));
14497 /* Get name of field. */
14498 fieldname
= dwarf2_name (die
, cu
);
14499 if (fieldname
== NULL
)
14502 /* The name is already allocated along with this objfile, so we don't
14503 need to duplicate it for the type. */
14504 fp
->name
= fieldname
;
14506 /* Change accessibility for artificial fields (e.g. virtual table
14507 pointer or virtual base class pointer) to private. */
14508 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14510 FIELD_ARTIFICIAL (*fp
) = 1;
14511 new_field
->accessibility
= DW_ACCESS_private
;
14512 fip
->non_public_fields
= 1;
14515 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14517 /* C++ static member. */
14519 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14520 is a declaration, but all versions of G++ as of this writing
14521 (so through at least 3.2.1) incorrectly generate
14522 DW_TAG_variable tags. */
14524 const char *physname
;
14526 /* Get name of field. */
14527 fieldname
= dwarf2_name (die
, cu
);
14528 if (fieldname
== NULL
)
14531 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14533 /* Only create a symbol if this is an external value.
14534 new_symbol checks this and puts the value in the global symbol
14535 table, which we want. If it is not external, new_symbol
14536 will try to put the value in cu->list_in_scope which is wrong. */
14537 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14539 /* A static const member, not much different than an enum as far as
14540 we're concerned, except that we can support more types. */
14541 new_symbol (die
, NULL
, cu
);
14544 /* Get physical name. */
14545 physname
= dwarf2_physname (fieldname
, die
, cu
);
14547 /* The name is already allocated along with this objfile, so we don't
14548 need to duplicate it for the type. */
14549 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14550 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14551 FIELD_NAME (*fp
) = fieldname
;
14553 else if (die
->tag
== DW_TAG_inheritance
)
14555 /* C++ base class field. */
14556 handle_data_member_location (die
, cu
, fp
);
14557 FIELD_BITSIZE (*fp
) = 0;
14558 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14559 FIELD_NAME (*fp
) = fp
->type
->name ();
14562 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14565 /* Can the type given by DIE define another type? */
14568 type_can_define_types (const struct die_info
*die
)
14572 case DW_TAG_typedef
:
14573 case DW_TAG_class_type
:
14574 case DW_TAG_structure_type
:
14575 case DW_TAG_union_type
:
14576 case DW_TAG_enumeration_type
:
14584 /* Add a type definition defined in the scope of the FIP's class. */
14587 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14588 struct dwarf2_cu
*cu
)
14590 struct decl_field fp
;
14591 memset (&fp
, 0, sizeof (fp
));
14593 gdb_assert (type_can_define_types (die
));
14595 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14596 fp
.name
= dwarf2_name (die
, cu
);
14597 fp
.type
= read_type_die (die
, cu
);
14599 /* Save accessibility. */
14600 enum dwarf_access_attribute accessibility
;
14601 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14603 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14605 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14606 switch (accessibility
)
14608 case DW_ACCESS_public
:
14609 /* The assumed value if neither private nor protected. */
14611 case DW_ACCESS_private
:
14614 case DW_ACCESS_protected
:
14615 fp
.is_protected
= 1;
14618 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14621 if (die
->tag
== DW_TAG_typedef
)
14622 fip
->typedef_field_list
.push_back (fp
);
14624 fip
->nested_types_list
.push_back (fp
);
14627 /* A convenience typedef that's used when finding the discriminant
14628 field for a variant part. */
14629 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14632 /* Compute the discriminant range for a given variant. OBSTACK is
14633 where the results will be stored. VARIANT is the variant to
14634 process. IS_UNSIGNED indicates whether the discriminant is signed
14637 static const gdb::array_view
<discriminant_range
>
14638 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14641 std::vector
<discriminant_range
> ranges
;
14643 if (variant
.default_branch
)
14646 if (variant
.discr_list_data
== nullptr)
14648 discriminant_range r
14649 = {variant
.discriminant_value
, variant
.discriminant_value
};
14650 ranges
.push_back (r
);
14654 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14655 variant
.discr_list_data
->size
);
14656 while (!data
.empty ())
14658 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14660 complaint (_("invalid discriminant marker: %d"), data
[0]);
14663 bool is_range
= data
[0] == DW_DSC_range
;
14664 data
= data
.slice (1);
14666 ULONGEST low
, high
;
14667 unsigned int bytes_read
;
14671 complaint (_("DW_AT_discr_list missing low value"));
14675 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14677 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14679 data
= data
.slice (bytes_read
);
14685 complaint (_("DW_AT_discr_list missing high value"));
14689 high
= read_unsigned_leb128 (nullptr, data
.data (),
14692 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14694 data
= data
.slice (bytes_read
);
14699 ranges
.push_back ({ low
, high
});
14703 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14705 std::copy (ranges
.begin (), ranges
.end (), result
);
14706 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14709 static const gdb::array_view
<variant_part
> create_variant_parts
14710 (struct obstack
*obstack
,
14711 const offset_map_type
&offset_map
,
14712 struct field_info
*fi
,
14713 const std::vector
<variant_part_builder
> &variant_parts
);
14715 /* Fill in a "struct variant" for a given variant field. RESULT is
14716 the variant to fill in. OBSTACK is where any needed allocations
14717 will be done. OFFSET_MAP holds the mapping from section offsets to
14718 fields for the type. FI describes the fields of the type we're
14719 processing. FIELD is the variant field we're converting. */
14722 create_one_variant (variant
&result
, struct obstack
*obstack
,
14723 const offset_map_type
&offset_map
,
14724 struct field_info
*fi
, const variant_field
&field
)
14726 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14727 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14728 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14729 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14730 field
.variant_parts
);
14733 /* Fill in a "struct variant_part" for a given variant part. RESULT
14734 is the variant part to fill in. OBSTACK is where any needed
14735 allocations will be done. OFFSET_MAP holds the mapping from
14736 section offsets to fields for the type. FI describes the fields of
14737 the type we're processing. BUILDER is the variant part to be
14741 create_one_variant_part (variant_part
&result
,
14742 struct obstack
*obstack
,
14743 const offset_map_type
&offset_map
,
14744 struct field_info
*fi
,
14745 const variant_part_builder
&builder
)
14747 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14748 if (iter
== offset_map
.end ())
14750 result
.discriminant_index
= -1;
14751 /* Doesn't matter. */
14752 result
.is_unsigned
= false;
14756 result
.discriminant_index
= iter
->second
;
14758 = TYPE_UNSIGNED (FIELD_TYPE
14759 (fi
->fields
[result
.discriminant_index
].field
));
14762 size_t n
= builder
.variants
.size ();
14763 variant
*output
= new (obstack
) variant
[n
];
14764 for (size_t i
= 0; i
< n
; ++i
)
14765 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14766 builder
.variants
[i
]);
14768 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14771 /* Create a vector of variant parts that can be attached to a type.
14772 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14773 holds the mapping from section offsets to fields for the type. FI
14774 describes the fields of the type we're processing. VARIANT_PARTS
14775 is the vector to convert. */
14777 static const gdb::array_view
<variant_part
>
14778 create_variant_parts (struct obstack
*obstack
,
14779 const offset_map_type
&offset_map
,
14780 struct field_info
*fi
,
14781 const std::vector
<variant_part_builder
> &variant_parts
)
14783 if (variant_parts
.empty ())
14786 size_t n
= variant_parts
.size ();
14787 variant_part
*result
= new (obstack
) variant_part
[n
];
14788 for (size_t i
= 0; i
< n
; ++i
)
14789 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14792 return gdb::array_view
<variant_part
> (result
, n
);
14795 /* Compute the variant part vector for FIP, attaching it to TYPE when
14799 add_variant_property (struct field_info
*fip
, struct type
*type
,
14800 struct dwarf2_cu
*cu
)
14802 /* Map section offsets of fields to their field index. Note the
14803 field index here does not take the number of baseclasses into
14805 offset_map_type offset_map
;
14806 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14807 offset_map
[fip
->fields
[i
].offset
] = i
;
14809 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14810 gdb::array_view
<variant_part
> parts
14811 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14812 fip
->variant_parts
);
14814 struct dynamic_prop prop
;
14815 prop
.kind
= PROP_VARIANT_PARTS
;
14816 prop
.data
.variant_parts
14817 = ((gdb::array_view
<variant_part
> *)
14818 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14820 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14823 /* Create the vector of fields, and attach it to the type. */
14826 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14827 struct dwarf2_cu
*cu
)
14829 int nfields
= fip
->nfields ();
14831 /* Record the field count, allocate space for the array of fields,
14832 and create blank accessibility bitfields if necessary. */
14833 type
->set_num_fields (nfields
);
14835 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14837 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14839 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14841 TYPE_FIELD_PRIVATE_BITS (type
) =
14842 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14843 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14845 TYPE_FIELD_PROTECTED_BITS (type
) =
14846 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14847 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14849 TYPE_FIELD_IGNORE_BITS (type
) =
14850 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14851 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14854 /* If the type has baseclasses, allocate and clear a bit vector for
14855 TYPE_FIELD_VIRTUAL_BITS. */
14856 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14858 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14859 unsigned char *pointer
;
14861 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14862 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14863 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14864 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14865 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14868 if (!fip
->variant_parts
.empty ())
14869 add_variant_property (fip
, type
, cu
);
14871 /* Copy the saved-up fields into the field vector. */
14872 for (int i
= 0; i
< nfields
; ++i
)
14874 struct nextfield
&field
14875 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14876 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14878 type
->field (i
) = field
.field
;
14879 switch (field
.accessibility
)
14881 case DW_ACCESS_private
:
14882 if (cu
->language
!= language_ada
)
14883 SET_TYPE_FIELD_PRIVATE (type
, i
);
14886 case DW_ACCESS_protected
:
14887 if (cu
->language
!= language_ada
)
14888 SET_TYPE_FIELD_PROTECTED (type
, i
);
14891 case DW_ACCESS_public
:
14895 /* Unknown accessibility. Complain and treat it as public. */
14897 complaint (_("unsupported accessibility %d"),
14898 field
.accessibility
);
14902 if (i
< fip
->baseclasses
.size ())
14904 switch (field
.virtuality
)
14906 case DW_VIRTUALITY_virtual
:
14907 case DW_VIRTUALITY_pure_virtual
:
14908 if (cu
->language
== language_ada
)
14909 error (_("unexpected virtuality in component of Ada type"));
14910 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14917 /* Return true if this member function is a constructor, false
14921 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14923 const char *fieldname
;
14924 const char *type_name
;
14927 if (die
->parent
== NULL
)
14930 if (die
->parent
->tag
!= DW_TAG_structure_type
14931 && die
->parent
->tag
!= DW_TAG_union_type
14932 && die
->parent
->tag
!= DW_TAG_class_type
)
14935 fieldname
= dwarf2_name (die
, cu
);
14936 type_name
= dwarf2_name (die
->parent
, cu
);
14937 if (fieldname
== NULL
|| type_name
== NULL
)
14940 len
= strlen (fieldname
);
14941 return (strncmp (fieldname
, type_name
, len
) == 0
14942 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14945 /* Check if the given VALUE is a recognized enum
14946 dwarf_defaulted_attribute constant according to DWARF5 spec,
14950 is_valid_DW_AT_defaulted (ULONGEST value
)
14954 case DW_DEFAULTED_no
:
14955 case DW_DEFAULTED_in_class
:
14956 case DW_DEFAULTED_out_of_class
:
14960 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14964 /* Add a member function to the proper fieldlist. */
14967 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14968 struct type
*type
, struct dwarf2_cu
*cu
)
14970 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14971 struct attribute
*attr
;
14973 struct fnfieldlist
*flp
= nullptr;
14974 struct fn_field
*fnp
;
14975 const char *fieldname
;
14976 struct type
*this_type
;
14977 enum dwarf_access_attribute accessibility
;
14979 if (cu
->language
== language_ada
)
14980 error (_("unexpected member function in Ada type"));
14982 /* Get name of member function. */
14983 fieldname
= dwarf2_name (die
, cu
);
14984 if (fieldname
== NULL
)
14987 /* Look up member function name in fieldlist. */
14988 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14990 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14992 flp
= &fip
->fnfieldlists
[i
];
14997 /* Create a new fnfieldlist if necessary. */
14998 if (flp
== nullptr)
15000 fip
->fnfieldlists
.emplace_back ();
15001 flp
= &fip
->fnfieldlists
.back ();
15002 flp
->name
= fieldname
;
15003 i
= fip
->fnfieldlists
.size () - 1;
15006 /* Create a new member function field and add it to the vector of
15008 flp
->fnfields
.emplace_back ();
15009 fnp
= &flp
->fnfields
.back ();
15011 /* Delay processing of the physname until later. */
15012 if (cu
->language
== language_cplus
)
15013 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15017 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15018 fnp
->physname
= physname
? physname
: "";
15021 fnp
->type
= alloc_type (objfile
);
15022 this_type
= read_type_die (die
, cu
);
15023 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15025 int nparams
= this_type
->num_fields ();
15027 /* TYPE is the domain of this method, and THIS_TYPE is the type
15028 of the method itself (TYPE_CODE_METHOD). */
15029 smash_to_method_type (fnp
->type
, type
,
15030 TYPE_TARGET_TYPE (this_type
),
15031 this_type
->fields (),
15032 this_type
->num_fields (),
15033 TYPE_VARARGS (this_type
));
15035 /* Handle static member functions.
15036 Dwarf2 has no clean way to discern C++ static and non-static
15037 member functions. G++ helps GDB by marking the first
15038 parameter for non-static member functions (which is the this
15039 pointer) as artificial. We obtain this information from
15040 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15041 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15042 fnp
->voffset
= VOFFSET_STATIC
;
15045 complaint (_("member function type missing for '%s'"),
15046 dwarf2_full_name (fieldname
, die
, cu
));
15048 /* Get fcontext from DW_AT_containing_type if present. */
15049 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15050 fnp
->fcontext
= die_containing_type (die
, cu
);
15052 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15053 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15055 /* Get accessibility. */
15056 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15057 if (attr
!= nullptr)
15058 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15060 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15061 switch (accessibility
)
15063 case DW_ACCESS_private
:
15064 fnp
->is_private
= 1;
15066 case DW_ACCESS_protected
:
15067 fnp
->is_protected
= 1;
15071 /* Check for artificial methods. */
15072 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15073 if (attr
&& DW_UNSND (attr
) != 0)
15074 fnp
->is_artificial
= 1;
15076 /* Check for defaulted methods. */
15077 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15078 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15079 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15081 /* Check for deleted methods. */
15082 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15083 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15084 fnp
->is_deleted
= 1;
15086 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15088 /* Get index in virtual function table if it is a virtual member
15089 function. For older versions of GCC, this is an offset in the
15090 appropriate virtual table, as specified by DW_AT_containing_type.
15091 For everyone else, it is an expression to be evaluated relative
15092 to the object address. */
15094 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15095 if (attr
!= nullptr)
15097 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15099 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15101 /* Old-style GCC. */
15102 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15104 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15105 || (DW_BLOCK (attr
)->size
> 1
15106 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15107 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15109 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15110 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15111 dwarf2_complex_location_expr_complaint ();
15113 fnp
->voffset
/= cu
->header
.addr_size
;
15117 dwarf2_complex_location_expr_complaint ();
15119 if (!fnp
->fcontext
)
15121 /* If there is no `this' field and no DW_AT_containing_type,
15122 we cannot actually find a base class context for the
15124 if (this_type
->num_fields () == 0
15125 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15127 complaint (_("cannot determine context for virtual member "
15128 "function \"%s\" (offset %s)"),
15129 fieldname
, sect_offset_str (die
->sect_off
));
15134 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15138 else if (attr
->form_is_section_offset ())
15140 dwarf2_complex_location_expr_complaint ();
15144 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15150 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15151 if (attr
&& DW_UNSND (attr
))
15153 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15154 complaint (_("Member function \"%s\" (offset %s) is virtual "
15155 "but the vtable offset is not specified"),
15156 fieldname
, sect_offset_str (die
->sect_off
));
15157 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15158 TYPE_CPLUS_DYNAMIC (type
) = 1;
15163 /* Create the vector of member function fields, and attach it to the type. */
15166 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15167 struct dwarf2_cu
*cu
)
15169 if (cu
->language
== language_ada
)
15170 error (_("unexpected member functions in Ada type"));
15172 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15173 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15175 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15177 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15179 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15180 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15182 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15183 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15184 fn_flp
->fn_fields
= (struct fn_field
*)
15185 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15187 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15188 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15191 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15194 /* Returns non-zero if NAME is the name of a vtable member in CU's
15195 language, zero otherwise. */
15197 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15199 static const char vptr
[] = "_vptr";
15201 /* Look for the C++ form of the vtable. */
15202 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15208 /* GCC outputs unnamed structures that are really pointers to member
15209 functions, with the ABI-specified layout. If TYPE describes
15210 such a structure, smash it into a member function type.
15212 GCC shouldn't do this; it should just output pointer to member DIEs.
15213 This is GCC PR debug/28767. */
15216 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15218 struct type
*pfn_type
, *self_type
, *new_type
;
15220 /* Check for a structure with no name and two children. */
15221 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15224 /* Check for __pfn and __delta members. */
15225 if (TYPE_FIELD_NAME (type
, 0) == NULL
15226 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15227 || TYPE_FIELD_NAME (type
, 1) == NULL
15228 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15231 /* Find the type of the method. */
15232 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15233 if (pfn_type
== NULL
15234 || pfn_type
->code () != TYPE_CODE_PTR
15235 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15238 /* Look for the "this" argument. */
15239 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15240 if (pfn_type
->num_fields () == 0
15241 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15242 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15245 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15246 new_type
= alloc_type (objfile
);
15247 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15248 pfn_type
->fields (), pfn_type
->num_fields (),
15249 TYPE_VARARGS (pfn_type
));
15250 smash_to_methodptr_type (type
, new_type
);
15253 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15254 appropriate error checking and issuing complaints if there is a
15258 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15260 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15262 if (attr
== nullptr)
15265 if (!attr
->form_is_constant ())
15267 complaint (_("DW_AT_alignment must have constant form"
15268 " - DIE at %s [in module %s]"),
15269 sect_offset_str (die
->sect_off
),
15270 objfile_name (cu
->per_objfile
->objfile
));
15275 if (attr
->form
== DW_FORM_sdata
)
15277 LONGEST val
= DW_SND (attr
);
15280 complaint (_("DW_AT_alignment value must not be negative"
15281 " - DIE at %s [in module %s]"),
15282 sect_offset_str (die
->sect_off
),
15283 objfile_name (cu
->per_objfile
->objfile
));
15289 align
= DW_UNSND (attr
);
15293 complaint (_("DW_AT_alignment value must not be zero"
15294 " - DIE at %s [in module %s]"),
15295 sect_offset_str (die
->sect_off
),
15296 objfile_name (cu
->per_objfile
->objfile
));
15299 if ((align
& (align
- 1)) != 0)
15301 complaint (_("DW_AT_alignment value must be a power of 2"
15302 " - DIE at %s [in module %s]"),
15303 sect_offset_str (die
->sect_off
),
15304 objfile_name (cu
->per_objfile
->objfile
));
15311 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15312 the alignment for TYPE. */
15315 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15318 if (!set_type_align (type
, get_alignment (cu
, die
)))
15319 complaint (_("DW_AT_alignment value too large"
15320 " - DIE at %s [in module %s]"),
15321 sect_offset_str (die
->sect_off
),
15322 objfile_name (cu
->per_objfile
->objfile
));
15325 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15326 constant for a type, according to DWARF5 spec, Table 5.5. */
15329 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15334 case DW_CC_pass_by_reference
:
15335 case DW_CC_pass_by_value
:
15339 complaint (_("unrecognized DW_AT_calling_convention value "
15340 "(%s) for a type"), pulongest (value
));
15345 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15346 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15347 also according to GNU-specific values (see include/dwarf2.h). */
15350 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15355 case DW_CC_program
:
15359 case DW_CC_GNU_renesas_sh
:
15360 case DW_CC_GNU_borland_fastcall_i386
:
15361 case DW_CC_GDB_IBM_OpenCL
:
15365 complaint (_("unrecognized DW_AT_calling_convention value "
15366 "(%s) for a subroutine"), pulongest (value
));
15371 /* Called when we find the DIE that starts a structure or union scope
15372 (definition) to create a type for the structure or union. Fill in
15373 the type's name and general properties; the members will not be
15374 processed until process_structure_scope. A symbol table entry for
15375 the type will also not be done until process_structure_scope (assuming
15376 the type has a name).
15378 NOTE: we need to call these functions regardless of whether or not the
15379 DIE has a DW_AT_name attribute, since it might be an anonymous
15380 structure or union. This gets the type entered into our set of
15381 user defined types. */
15383 static struct type
*
15384 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15386 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15388 struct attribute
*attr
;
15391 /* If the definition of this type lives in .debug_types, read that type.
15392 Don't follow DW_AT_specification though, that will take us back up
15393 the chain and we want to go down. */
15394 attr
= die
->attr (DW_AT_signature
);
15395 if (attr
!= nullptr)
15397 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15399 /* The type's CU may not be the same as CU.
15400 Ensure TYPE is recorded with CU in die_type_hash. */
15401 return set_die_type (die
, type
, cu
);
15404 type
= alloc_type (objfile
);
15405 INIT_CPLUS_SPECIFIC (type
);
15407 name
= dwarf2_name (die
, cu
);
15410 if (cu
->language
== language_cplus
15411 || cu
->language
== language_d
15412 || cu
->language
== language_rust
)
15414 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15416 /* dwarf2_full_name might have already finished building the DIE's
15417 type. If so, there is no need to continue. */
15418 if (get_die_type (die
, cu
) != NULL
)
15419 return get_die_type (die
, cu
);
15421 type
->set_name (full_name
);
15425 /* The name is already allocated along with this objfile, so
15426 we don't need to duplicate it for the type. */
15427 type
->set_name (name
);
15431 if (die
->tag
== DW_TAG_structure_type
)
15433 type
->set_code (TYPE_CODE_STRUCT
);
15435 else if (die
->tag
== DW_TAG_union_type
)
15437 type
->set_code (TYPE_CODE_UNION
);
15441 type
->set_code (TYPE_CODE_STRUCT
);
15444 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15445 TYPE_DECLARED_CLASS (type
) = 1;
15447 /* Store the calling convention in the type if it's available in
15448 the die. Otherwise the calling convention remains set to
15449 the default value DW_CC_normal. */
15450 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15451 if (attr
!= nullptr
15452 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15454 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15455 TYPE_CPLUS_CALLING_CONVENTION (type
)
15456 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15459 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15460 if (attr
!= nullptr)
15462 if (attr
->form_is_constant ())
15463 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15466 struct dynamic_prop prop
;
15467 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
15468 cu
->per_cu
->addr_type ()))
15469 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15470 TYPE_LENGTH (type
) = 0;
15475 TYPE_LENGTH (type
) = 0;
15478 maybe_set_alignment (cu
, die
, type
);
15480 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15482 /* ICC<14 does not output the required DW_AT_declaration on
15483 incomplete types, but gives them a size of zero. */
15484 TYPE_STUB (type
) = 1;
15487 TYPE_STUB_SUPPORTED (type
) = 1;
15489 if (die_is_declaration (die
, cu
))
15490 TYPE_STUB (type
) = 1;
15491 else if (attr
== NULL
&& die
->child
== NULL
15492 && producer_is_realview (cu
->producer
))
15493 /* RealView does not output the required DW_AT_declaration
15494 on incomplete types. */
15495 TYPE_STUB (type
) = 1;
15497 /* We need to add the type field to the die immediately so we don't
15498 infinitely recurse when dealing with pointers to the structure
15499 type within the structure itself. */
15500 set_die_type (die
, type
, cu
);
15502 /* set_die_type should be already done. */
15503 set_descriptive_type (type
, die
, cu
);
15508 static void handle_struct_member_die
15509 (struct die_info
*child_die
,
15511 struct field_info
*fi
,
15512 std::vector
<struct symbol
*> *template_args
,
15513 struct dwarf2_cu
*cu
);
15515 /* A helper for handle_struct_member_die that handles
15516 DW_TAG_variant_part. */
15519 handle_variant_part (struct die_info
*die
, struct type
*type
,
15520 struct field_info
*fi
,
15521 std::vector
<struct symbol
*> *template_args
,
15522 struct dwarf2_cu
*cu
)
15524 variant_part_builder
*new_part
;
15525 if (fi
->current_variant_part
== nullptr)
15527 fi
->variant_parts
.emplace_back ();
15528 new_part
= &fi
->variant_parts
.back ();
15530 else if (!fi
->current_variant_part
->processing_variant
)
15532 complaint (_("nested DW_TAG_variant_part seen "
15533 "- DIE at %s [in module %s]"),
15534 sect_offset_str (die
->sect_off
),
15535 objfile_name (cu
->per_objfile
->objfile
));
15540 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15541 current
.variant_parts
.emplace_back ();
15542 new_part
= ¤t
.variant_parts
.back ();
15545 /* When we recurse, we want callees to add to this new variant
15547 scoped_restore save_current_variant_part
15548 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15550 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15553 /* It's a univariant form, an extension we support. */
15555 else if (discr
->form_is_ref ())
15557 struct dwarf2_cu
*target_cu
= cu
;
15558 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15560 new_part
->discriminant_offset
= target_die
->sect_off
;
15564 complaint (_("DW_AT_discr does not have DIE reference form"
15565 " - DIE at %s [in module %s]"),
15566 sect_offset_str (die
->sect_off
),
15567 objfile_name (cu
->per_objfile
->objfile
));
15570 for (die_info
*child_die
= die
->child
;
15572 child_die
= child_die
->sibling
)
15573 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15576 /* A helper for handle_struct_member_die that handles
15580 handle_variant (struct die_info
*die
, struct type
*type
,
15581 struct field_info
*fi
,
15582 std::vector
<struct symbol
*> *template_args
,
15583 struct dwarf2_cu
*cu
)
15585 if (fi
->current_variant_part
== nullptr)
15587 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15588 "- DIE at %s [in module %s]"),
15589 sect_offset_str (die
->sect_off
),
15590 objfile_name (cu
->per_objfile
->objfile
));
15593 if (fi
->current_variant_part
->processing_variant
)
15595 complaint (_("nested DW_TAG_variant seen "
15596 "- DIE at %s [in module %s]"),
15597 sect_offset_str (die
->sect_off
),
15598 objfile_name (cu
->per_objfile
->objfile
));
15602 scoped_restore save_processing_variant
15603 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15606 fi
->current_variant_part
->variants
.emplace_back ();
15607 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15608 variant
.first_field
= fi
->fields
.size ();
15610 /* In a variant we want to get the discriminant and also add a
15611 field for our sole member child. */
15612 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15613 if (discr
== nullptr)
15615 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15616 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15617 variant
.default_branch
= true;
15619 variant
.discr_list_data
= DW_BLOCK (discr
);
15622 variant
.discriminant_value
= DW_UNSND (discr
);
15624 for (die_info
*variant_child
= die
->child
;
15625 variant_child
!= NULL
;
15626 variant_child
= variant_child
->sibling
)
15627 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15629 variant
.last_field
= fi
->fields
.size ();
15632 /* A helper for process_structure_scope that handles a single member
15636 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15637 struct field_info
*fi
,
15638 std::vector
<struct symbol
*> *template_args
,
15639 struct dwarf2_cu
*cu
)
15641 if (child_die
->tag
== DW_TAG_member
15642 || child_die
->tag
== DW_TAG_variable
)
15644 /* NOTE: carlton/2002-11-05: A C++ static data member
15645 should be a DW_TAG_member that is a declaration, but
15646 all versions of G++ as of this writing (so through at
15647 least 3.2.1) incorrectly generate DW_TAG_variable
15648 tags for them instead. */
15649 dwarf2_add_field (fi
, child_die
, cu
);
15651 else if (child_die
->tag
== DW_TAG_subprogram
)
15653 /* Rust doesn't have member functions in the C++ sense.
15654 However, it does emit ordinary functions as children
15655 of a struct DIE. */
15656 if (cu
->language
== language_rust
)
15657 read_func_scope (child_die
, cu
);
15660 /* C++ member function. */
15661 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15664 else if (child_die
->tag
== DW_TAG_inheritance
)
15666 /* C++ base class field. */
15667 dwarf2_add_field (fi
, child_die
, cu
);
15669 else if (type_can_define_types (child_die
))
15670 dwarf2_add_type_defn (fi
, child_die
, cu
);
15671 else if (child_die
->tag
== DW_TAG_template_type_param
15672 || child_die
->tag
== DW_TAG_template_value_param
)
15674 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15677 template_args
->push_back (arg
);
15679 else if (child_die
->tag
== DW_TAG_variant_part
)
15680 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15681 else if (child_die
->tag
== DW_TAG_variant
)
15682 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15685 /* Finish creating a structure or union type, including filling in
15686 its members and creating a symbol for it. */
15689 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15691 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15692 struct die_info
*child_die
;
15695 type
= get_die_type (die
, cu
);
15697 type
= read_structure_type (die
, cu
);
15699 bool has_template_parameters
= false;
15700 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15702 struct field_info fi
;
15703 std::vector
<struct symbol
*> template_args
;
15705 child_die
= die
->child
;
15707 while (child_die
&& child_die
->tag
)
15709 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15710 child_die
= child_die
->sibling
;
15713 /* Attach template arguments to type. */
15714 if (!template_args
.empty ())
15716 has_template_parameters
= true;
15717 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15718 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15719 TYPE_TEMPLATE_ARGUMENTS (type
)
15720 = XOBNEWVEC (&objfile
->objfile_obstack
,
15722 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15723 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15724 template_args
.data (),
15725 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15726 * sizeof (struct symbol
*)));
15729 /* Attach fields and member functions to the type. */
15730 if (fi
.nfields () > 0)
15731 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15732 if (!fi
.fnfieldlists
.empty ())
15734 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15736 /* Get the type which refers to the base class (possibly this
15737 class itself) which contains the vtable pointer for the current
15738 class from the DW_AT_containing_type attribute. This use of
15739 DW_AT_containing_type is a GNU extension. */
15741 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15743 struct type
*t
= die_containing_type (die
, cu
);
15745 set_type_vptr_basetype (type
, t
);
15750 /* Our own class provides vtbl ptr. */
15751 for (i
= t
->num_fields () - 1;
15752 i
>= TYPE_N_BASECLASSES (t
);
15755 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15757 if (is_vtable_name (fieldname
, cu
))
15759 set_type_vptr_fieldno (type
, i
);
15764 /* Complain if virtual function table field not found. */
15765 if (i
< TYPE_N_BASECLASSES (t
))
15766 complaint (_("virtual function table pointer "
15767 "not found when defining class '%s'"),
15768 type
->name () ? type
->name () : "");
15772 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15775 else if (cu
->producer
15776 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15778 /* The IBM XLC compiler does not provide direct indication
15779 of the containing type, but the vtable pointer is
15780 always named __vfp. */
15784 for (i
= type
->num_fields () - 1;
15785 i
>= TYPE_N_BASECLASSES (type
);
15788 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15790 set_type_vptr_fieldno (type
, i
);
15791 set_type_vptr_basetype (type
, type
);
15798 /* Copy fi.typedef_field_list linked list elements content into the
15799 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15800 if (!fi
.typedef_field_list
.empty ())
15802 int count
= fi
.typedef_field_list
.size ();
15804 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15805 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15806 = ((struct decl_field
*)
15808 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15809 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15811 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15812 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15815 /* Copy fi.nested_types_list linked list elements content into the
15816 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15817 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15819 int count
= fi
.nested_types_list
.size ();
15821 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15822 TYPE_NESTED_TYPES_ARRAY (type
)
15823 = ((struct decl_field
*)
15824 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15825 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15827 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15828 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15832 quirk_gcc_member_function_pointer (type
, objfile
);
15833 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15834 cu
->rust_unions
.push_back (type
);
15836 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15837 snapshots) has been known to create a die giving a declaration
15838 for a class that has, as a child, a die giving a definition for a
15839 nested class. So we have to process our children even if the
15840 current die is a declaration. Normally, of course, a declaration
15841 won't have any children at all. */
15843 child_die
= die
->child
;
15845 while (child_die
!= NULL
&& child_die
->tag
)
15847 if (child_die
->tag
== DW_TAG_member
15848 || child_die
->tag
== DW_TAG_variable
15849 || child_die
->tag
== DW_TAG_inheritance
15850 || child_die
->tag
== DW_TAG_template_value_param
15851 || child_die
->tag
== DW_TAG_template_type_param
)
15856 process_die (child_die
, cu
);
15858 child_die
= child_die
->sibling
;
15861 /* Do not consider external references. According to the DWARF standard,
15862 these DIEs are identified by the fact that they have no byte_size
15863 attribute, and a declaration attribute. */
15864 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15865 || !die_is_declaration (die
, cu
)
15866 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15868 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15870 if (has_template_parameters
)
15872 struct symtab
*symtab
;
15873 if (sym
!= nullptr)
15874 symtab
= symbol_symtab (sym
);
15875 else if (cu
->line_header
!= nullptr)
15877 /* Any related symtab will do. */
15879 = cu
->line_header
->file_names ()[0].symtab
;
15884 complaint (_("could not find suitable "
15885 "symtab for template parameter"
15886 " - DIE at %s [in module %s]"),
15887 sect_offset_str (die
->sect_off
),
15888 objfile_name (objfile
));
15891 if (symtab
!= nullptr)
15893 /* Make sure that the symtab is set on the new symbols.
15894 Even though they don't appear in this symtab directly,
15895 other parts of gdb assume that symbols do, and this is
15896 reasonably true. */
15897 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15898 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15904 /* Assuming DIE is an enumeration type, and TYPE is its associated
15905 type, update TYPE using some information only available in DIE's
15906 children. In particular, the fields are computed. */
15909 update_enumeration_type_from_children (struct die_info
*die
,
15911 struct dwarf2_cu
*cu
)
15913 struct die_info
*child_die
;
15914 int unsigned_enum
= 1;
15917 auto_obstack obstack
;
15918 std::vector
<struct field
> fields
;
15920 for (child_die
= die
->child
;
15921 child_die
!= NULL
&& child_die
->tag
;
15922 child_die
= child_die
->sibling
)
15924 struct attribute
*attr
;
15926 const gdb_byte
*bytes
;
15927 struct dwarf2_locexpr_baton
*baton
;
15930 if (child_die
->tag
!= DW_TAG_enumerator
)
15933 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15937 name
= dwarf2_name (child_die
, cu
);
15939 name
= "<anonymous enumerator>";
15941 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15942 &value
, &bytes
, &baton
);
15950 if (count_one_bits_ll (value
) >= 2)
15954 fields
.emplace_back ();
15955 struct field
&field
= fields
.back ();
15956 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
15957 SET_FIELD_ENUMVAL (field
, value
);
15960 if (!fields
.empty ())
15962 type
->set_num_fields (fields
.size ());
15965 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
15966 memcpy (type
->fields (), fields
.data (),
15967 sizeof (struct field
) * fields
.size ());
15971 TYPE_UNSIGNED (type
) = 1;
15973 TYPE_FLAG_ENUM (type
) = 1;
15976 /* Given a DW_AT_enumeration_type die, set its type. We do not
15977 complete the type's fields yet, or create any symbols. */
15979 static struct type
*
15980 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15982 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15984 struct attribute
*attr
;
15987 /* If the definition of this type lives in .debug_types, read that type.
15988 Don't follow DW_AT_specification though, that will take us back up
15989 the chain and we want to go down. */
15990 attr
= die
->attr (DW_AT_signature
);
15991 if (attr
!= nullptr)
15993 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15995 /* The type's CU may not be the same as CU.
15996 Ensure TYPE is recorded with CU in die_type_hash. */
15997 return set_die_type (die
, type
, cu
);
16000 type
= alloc_type (objfile
);
16002 type
->set_code (TYPE_CODE_ENUM
);
16003 name
= dwarf2_full_name (NULL
, die
, cu
);
16005 type
->set_name (name
);
16007 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16010 struct type
*underlying_type
= die_type (die
, cu
);
16012 TYPE_TARGET_TYPE (type
) = underlying_type
;
16015 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16016 if (attr
!= nullptr)
16018 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16022 TYPE_LENGTH (type
) = 0;
16025 maybe_set_alignment (cu
, die
, type
);
16027 /* The enumeration DIE can be incomplete. In Ada, any type can be
16028 declared as private in the package spec, and then defined only
16029 inside the package body. Such types are known as Taft Amendment
16030 Types. When another package uses such a type, an incomplete DIE
16031 may be generated by the compiler. */
16032 if (die_is_declaration (die
, cu
))
16033 TYPE_STUB (type
) = 1;
16035 /* If this type has an underlying type that is not a stub, then we
16036 may use its attributes. We always use the "unsigned" attribute
16037 in this situation, because ordinarily we guess whether the type
16038 is unsigned -- but the guess can be wrong and the underlying type
16039 can tell us the reality. However, we defer to a local size
16040 attribute if one exists, because this lets the compiler override
16041 the underlying type if needed. */
16042 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16044 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16045 underlying_type
= check_typedef (underlying_type
);
16046 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16047 if (TYPE_LENGTH (type
) == 0)
16048 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16049 if (TYPE_RAW_ALIGN (type
) == 0
16050 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16051 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16054 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16056 set_die_type (die
, type
, cu
);
16058 /* Finish the creation of this type by using the enum's children.
16059 Note that, as usual, this must come after set_die_type to avoid
16060 infinite recursion when trying to compute the names of the
16062 update_enumeration_type_from_children (die
, type
, cu
);
16067 /* Given a pointer to a die which begins an enumeration, process all
16068 the dies that define the members of the enumeration, and create the
16069 symbol for the enumeration type.
16071 NOTE: We reverse the order of the element list. */
16074 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16076 struct type
*this_type
;
16078 this_type
= get_die_type (die
, cu
);
16079 if (this_type
== NULL
)
16080 this_type
= read_enumeration_type (die
, cu
);
16082 if (die
->child
!= NULL
)
16084 struct die_info
*child_die
;
16087 child_die
= die
->child
;
16088 while (child_die
&& child_die
->tag
)
16090 if (child_die
->tag
!= DW_TAG_enumerator
)
16092 process_die (child_die
, cu
);
16096 name
= dwarf2_name (child_die
, cu
);
16098 new_symbol (child_die
, this_type
, cu
);
16101 child_die
= child_die
->sibling
;
16105 /* If we are reading an enum from a .debug_types unit, and the enum
16106 is a declaration, and the enum is not the signatured type in the
16107 unit, then we do not want to add a symbol for it. Adding a
16108 symbol would in some cases obscure the true definition of the
16109 enum, giving users an incomplete type when the definition is
16110 actually available. Note that we do not want to do this for all
16111 enums which are just declarations, because C++0x allows forward
16112 enum declarations. */
16113 if (cu
->per_cu
->is_debug_types
16114 && die_is_declaration (die
, cu
))
16116 struct signatured_type
*sig_type
;
16118 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16119 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16120 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16124 new_symbol (die
, this_type
, cu
);
16127 /* Extract all information from a DW_TAG_array_type DIE and put it in
16128 the DIE's type field. For now, this only handles one dimensional
16131 static struct type
*
16132 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16134 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16135 struct die_info
*child_die
;
16137 struct type
*element_type
, *range_type
, *index_type
;
16138 struct attribute
*attr
;
16140 struct dynamic_prop
*byte_stride_prop
= NULL
;
16141 unsigned int bit_stride
= 0;
16143 element_type
= die_type (die
, cu
);
16145 /* The die_type call above may have already set the type for this DIE. */
16146 type
= get_die_type (die
, cu
);
16150 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16154 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
16157 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16158 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16162 complaint (_("unable to read array DW_AT_byte_stride "
16163 " - DIE at %s [in module %s]"),
16164 sect_offset_str (die
->sect_off
),
16165 objfile_name (cu
->per_objfile
->objfile
));
16166 /* Ignore this attribute. We will likely not be able to print
16167 arrays of this type correctly, but there is little we can do
16168 to help if we cannot read the attribute's value. */
16169 byte_stride_prop
= NULL
;
16173 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16175 bit_stride
= DW_UNSND (attr
);
16177 /* Irix 6.2 native cc creates array types without children for
16178 arrays with unspecified length. */
16179 if (die
->child
== NULL
)
16181 index_type
= objfile_type (objfile
)->builtin_int
;
16182 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16183 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16184 byte_stride_prop
, bit_stride
);
16185 return set_die_type (die
, type
, cu
);
16188 std::vector
<struct type
*> range_types
;
16189 child_die
= die
->child
;
16190 while (child_die
&& child_die
->tag
)
16192 if (child_die
->tag
== DW_TAG_subrange_type
)
16194 struct type
*child_type
= read_type_die (child_die
, cu
);
16196 if (child_type
!= NULL
)
16198 /* The range type was succesfully read. Save it for the
16199 array type creation. */
16200 range_types
.push_back (child_type
);
16203 child_die
= child_die
->sibling
;
16206 /* Dwarf2 dimensions are output from left to right, create the
16207 necessary array types in backwards order. */
16209 type
= element_type
;
16211 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16215 while (i
< range_types
.size ())
16216 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16217 byte_stride_prop
, bit_stride
);
16221 size_t ndim
= range_types
.size ();
16223 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16224 byte_stride_prop
, bit_stride
);
16227 /* Understand Dwarf2 support for vector types (like they occur on
16228 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16229 array type. This is not part of the Dwarf2/3 standard yet, but a
16230 custom vendor extension. The main difference between a regular
16231 array and the vector variant is that vectors are passed by value
16233 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16234 if (attr
!= nullptr)
16235 make_vector_type (type
);
16237 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16238 implementation may choose to implement triple vectors using this
16240 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16241 if (attr
!= nullptr)
16243 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16244 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16246 complaint (_("DW_AT_byte_size for array type smaller "
16247 "than the total size of elements"));
16250 name
= dwarf2_name (die
, cu
);
16252 type
->set_name (name
);
16254 maybe_set_alignment (cu
, die
, type
);
16256 /* Install the type in the die. */
16257 set_die_type (die
, type
, cu
);
16259 /* set_die_type should be already done. */
16260 set_descriptive_type (type
, die
, cu
);
16265 static enum dwarf_array_dim_ordering
16266 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16268 struct attribute
*attr
;
16270 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16272 if (attr
!= nullptr)
16273 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16275 /* GNU F77 is a special case, as at 08/2004 array type info is the
16276 opposite order to the dwarf2 specification, but data is still
16277 laid out as per normal fortran.
16279 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16280 version checking. */
16282 if (cu
->language
== language_fortran
16283 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16285 return DW_ORD_row_major
;
16288 switch (cu
->language_defn
->la_array_ordering
)
16290 case array_column_major
:
16291 return DW_ORD_col_major
;
16292 case array_row_major
:
16294 return DW_ORD_row_major
;
16298 /* Extract all information from a DW_TAG_set_type DIE and put it in
16299 the DIE's type field. */
16301 static struct type
*
16302 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16304 struct type
*domain_type
, *set_type
;
16305 struct attribute
*attr
;
16307 domain_type
= die_type (die
, cu
);
16309 /* The die_type call above may have already set the type for this DIE. */
16310 set_type
= get_die_type (die
, cu
);
16314 set_type
= create_set_type (NULL
, domain_type
);
16316 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16317 if (attr
!= nullptr)
16318 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16320 maybe_set_alignment (cu
, die
, set_type
);
16322 return set_die_type (die
, set_type
, cu
);
16325 /* A helper for read_common_block that creates a locexpr baton.
16326 SYM is the symbol which we are marking as computed.
16327 COMMON_DIE is the DIE for the common block.
16328 COMMON_LOC is the location expression attribute for the common
16330 MEMBER_LOC is the location expression attribute for the particular
16331 member of the common block that we are processing.
16332 CU is the CU from which the above come. */
16335 mark_common_block_symbol_computed (struct symbol
*sym
,
16336 struct die_info
*common_die
,
16337 struct attribute
*common_loc
,
16338 struct attribute
*member_loc
,
16339 struct dwarf2_cu
*cu
)
16341 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16342 struct objfile
*objfile
= per_objfile
->objfile
;
16343 struct dwarf2_locexpr_baton
*baton
;
16345 unsigned int cu_off
;
16346 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16347 LONGEST offset
= 0;
16349 gdb_assert (common_loc
&& member_loc
);
16350 gdb_assert (common_loc
->form_is_block ());
16351 gdb_assert (member_loc
->form_is_block ()
16352 || member_loc
->form_is_constant ());
16354 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16355 baton
->per_objfile
= per_objfile
;
16356 baton
->per_cu
= cu
->per_cu
;
16357 gdb_assert (baton
->per_cu
);
16359 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16361 if (member_loc
->form_is_constant ())
16363 offset
= member_loc
->constant_value (0);
16364 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16367 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16369 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16372 *ptr
++ = DW_OP_call4
;
16373 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16374 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16377 if (member_loc
->form_is_constant ())
16379 *ptr
++ = DW_OP_addr
;
16380 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16381 ptr
+= cu
->header
.addr_size
;
16385 /* We have to copy the data here, because DW_OP_call4 will only
16386 use a DW_AT_location attribute. */
16387 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16388 ptr
+= DW_BLOCK (member_loc
)->size
;
16391 *ptr
++ = DW_OP_plus
;
16392 gdb_assert (ptr
- baton
->data
== baton
->size
);
16394 SYMBOL_LOCATION_BATON (sym
) = baton
;
16395 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16398 /* Create appropriate locally-scoped variables for all the
16399 DW_TAG_common_block entries. Also create a struct common_block
16400 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16401 is used to separate the common blocks name namespace from regular
16405 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16407 struct attribute
*attr
;
16409 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16410 if (attr
!= nullptr)
16412 /* Support the .debug_loc offsets. */
16413 if (attr
->form_is_block ())
16417 else if (attr
->form_is_section_offset ())
16419 dwarf2_complex_location_expr_complaint ();
16424 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16425 "common block member");
16430 if (die
->child
!= NULL
)
16432 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16433 struct die_info
*child_die
;
16434 size_t n_entries
= 0, size
;
16435 struct common_block
*common_block
;
16436 struct symbol
*sym
;
16438 for (child_die
= die
->child
;
16439 child_die
&& child_die
->tag
;
16440 child_die
= child_die
->sibling
)
16443 size
= (sizeof (struct common_block
)
16444 + (n_entries
- 1) * sizeof (struct symbol
*));
16446 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16448 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16449 common_block
->n_entries
= 0;
16451 for (child_die
= die
->child
;
16452 child_die
&& child_die
->tag
;
16453 child_die
= child_die
->sibling
)
16455 /* Create the symbol in the DW_TAG_common_block block in the current
16457 sym
= new_symbol (child_die
, NULL
, cu
);
16460 struct attribute
*member_loc
;
16462 common_block
->contents
[common_block
->n_entries
++] = sym
;
16464 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16468 /* GDB has handled this for a long time, but it is
16469 not specified by DWARF. It seems to have been
16470 emitted by gfortran at least as recently as:
16471 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16472 complaint (_("Variable in common block has "
16473 "DW_AT_data_member_location "
16474 "- DIE at %s [in module %s]"),
16475 sect_offset_str (child_die
->sect_off
),
16476 objfile_name (objfile
));
16478 if (member_loc
->form_is_section_offset ())
16479 dwarf2_complex_location_expr_complaint ();
16480 else if (member_loc
->form_is_constant ()
16481 || member_loc
->form_is_block ())
16483 if (attr
!= nullptr)
16484 mark_common_block_symbol_computed (sym
, die
, attr
,
16488 dwarf2_complex_location_expr_complaint ();
16493 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16494 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16498 /* Create a type for a C++ namespace. */
16500 static struct type
*
16501 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16503 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16504 const char *previous_prefix
, *name
;
16508 /* For extensions, reuse the type of the original namespace. */
16509 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16511 struct die_info
*ext_die
;
16512 struct dwarf2_cu
*ext_cu
= cu
;
16514 ext_die
= dwarf2_extension (die
, &ext_cu
);
16515 type
= read_type_die (ext_die
, ext_cu
);
16517 /* EXT_CU may not be the same as CU.
16518 Ensure TYPE is recorded with CU in die_type_hash. */
16519 return set_die_type (die
, type
, cu
);
16522 name
= namespace_name (die
, &is_anonymous
, cu
);
16524 /* Now build the name of the current namespace. */
16526 previous_prefix
= determine_prefix (die
, cu
);
16527 if (previous_prefix
[0] != '\0')
16528 name
= typename_concat (&objfile
->objfile_obstack
,
16529 previous_prefix
, name
, 0, cu
);
16531 /* Create the type. */
16532 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16534 return set_die_type (die
, type
, cu
);
16537 /* Read a namespace scope. */
16540 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16542 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16545 /* Add a symbol associated to this if we haven't seen the namespace
16546 before. Also, add a using directive if it's an anonymous
16549 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16553 type
= read_type_die (die
, cu
);
16554 new_symbol (die
, type
, cu
);
16556 namespace_name (die
, &is_anonymous
, cu
);
16559 const char *previous_prefix
= determine_prefix (die
, cu
);
16561 std::vector
<const char *> excludes
;
16562 add_using_directive (using_directives (cu
),
16563 previous_prefix
, type
->name (), NULL
,
16564 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16568 if (die
->child
!= NULL
)
16570 struct die_info
*child_die
= die
->child
;
16572 while (child_die
&& child_die
->tag
)
16574 process_die (child_die
, cu
);
16575 child_die
= child_die
->sibling
;
16580 /* Read a Fortran module as type. This DIE can be only a declaration used for
16581 imported module. Still we need that type as local Fortran "use ... only"
16582 declaration imports depend on the created type in determine_prefix. */
16584 static struct type
*
16585 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16587 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16588 const char *module_name
;
16591 module_name
= dwarf2_name (die
, cu
);
16592 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16594 return set_die_type (die
, type
, cu
);
16597 /* Read a Fortran module. */
16600 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16602 struct die_info
*child_die
= die
->child
;
16605 type
= read_type_die (die
, cu
);
16606 new_symbol (die
, type
, cu
);
16608 while (child_die
&& child_die
->tag
)
16610 process_die (child_die
, cu
);
16611 child_die
= child_die
->sibling
;
16615 /* Return the name of the namespace represented by DIE. Set
16616 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16619 static const char *
16620 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16622 struct die_info
*current_die
;
16623 const char *name
= NULL
;
16625 /* Loop through the extensions until we find a name. */
16627 for (current_die
= die
;
16628 current_die
!= NULL
;
16629 current_die
= dwarf2_extension (die
, &cu
))
16631 /* We don't use dwarf2_name here so that we can detect the absence
16632 of a name -> anonymous namespace. */
16633 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16639 /* Is it an anonymous namespace? */
16641 *is_anonymous
= (name
== NULL
);
16643 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16648 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16649 the user defined type vector. */
16651 static struct type
*
16652 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16654 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16655 struct comp_unit_head
*cu_header
= &cu
->header
;
16657 struct attribute
*attr_byte_size
;
16658 struct attribute
*attr_address_class
;
16659 int byte_size
, addr_class
;
16660 struct type
*target_type
;
16662 target_type
= die_type (die
, cu
);
16664 /* The die_type call above may have already set the type for this DIE. */
16665 type
= get_die_type (die
, cu
);
16669 type
= lookup_pointer_type (target_type
);
16671 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16672 if (attr_byte_size
)
16673 byte_size
= DW_UNSND (attr_byte_size
);
16675 byte_size
= cu_header
->addr_size
;
16677 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16678 if (attr_address_class
)
16679 addr_class
= DW_UNSND (attr_address_class
);
16681 addr_class
= DW_ADDR_none
;
16683 ULONGEST alignment
= get_alignment (cu
, die
);
16685 /* If the pointer size, alignment, or address class is different
16686 than the default, create a type variant marked as such and set
16687 the length accordingly. */
16688 if (TYPE_LENGTH (type
) != byte_size
16689 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16690 && alignment
!= TYPE_RAW_ALIGN (type
))
16691 || addr_class
!= DW_ADDR_none
)
16693 if (gdbarch_address_class_type_flags_p (gdbarch
))
16697 type_flags
= gdbarch_address_class_type_flags
16698 (gdbarch
, byte_size
, addr_class
);
16699 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16701 type
= make_type_with_address_space (type
, type_flags
);
16703 else if (TYPE_LENGTH (type
) != byte_size
)
16705 complaint (_("invalid pointer size %d"), byte_size
);
16707 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16709 complaint (_("Invalid DW_AT_alignment"
16710 " - DIE at %s [in module %s]"),
16711 sect_offset_str (die
->sect_off
),
16712 objfile_name (cu
->per_objfile
->objfile
));
16716 /* Should we also complain about unhandled address classes? */
16720 TYPE_LENGTH (type
) = byte_size
;
16721 set_type_align (type
, alignment
);
16722 return set_die_type (die
, type
, cu
);
16725 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16726 the user defined type vector. */
16728 static struct type
*
16729 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16732 struct type
*to_type
;
16733 struct type
*domain
;
16735 to_type
= die_type (die
, cu
);
16736 domain
= die_containing_type (die
, cu
);
16738 /* The calls above may have already set the type for this DIE. */
16739 type
= get_die_type (die
, cu
);
16743 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16744 type
= lookup_methodptr_type (to_type
);
16745 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16747 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16749 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16750 to_type
->fields (), to_type
->num_fields (),
16751 TYPE_VARARGS (to_type
));
16752 type
= lookup_methodptr_type (new_type
);
16755 type
= lookup_memberptr_type (to_type
, domain
);
16757 return set_die_type (die
, type
, cu
);
16760 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16761 the user defined type vector. */
16763 static struct type
*
16764 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16765 enum type_code refcode
)
16767 struct comp_unit_head
*cu_header
= &cu
->header
;
16768 struct type
*type
, *target_type
;
16769 struct attribute
*attr
;
16771 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16773 target_type
= die_type (die
, cu
);
16775 /* The die_type call above may have already set the type for this DIE. */
16776 type
= get_die_type (die
, cu
);
16780 type
= lookup_reference_type (target_type
, refcode
);
16781 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16782 if (attr
!= nullptr)
16784 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16788 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16790 maybe_set_alignment (cu
, die
, type
);
16791 return set_die_type (die
, type
, cu
);
16794 /* Add the given cv-qualifiers to the element type of the array. GCC
16795 outputs DWARF type qualifiers that apply to an array, not the
16796 element type. But GDB relies on the array element type to carry
16797 the cv-qualifiers. This mimics section 6.7.3 of the C99
16800 static struct type
*
16801 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16802 struct type
*base_type
, int cnst
, int voltl
)
16804 struct type
*el_type
, *inner_array
;
16806 base_type
= copy_type (base_type
);
16807 inner_array
= base_type
;
16809 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16811 TYPE_TARGET_TYPE (inner_array
) =
16812 copy_type (TYPE_TARGET_TYPE (inner_array
));
16813 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16816 el_type
= TYPE_TARGET_TYPE (inner_array
);
16817 cnst
|= TYPE_CONST (el_type
);
16818 voltl
|= TYPE_VOLATILE (el_type
);
16819 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16821 return set_die_type (die
, base_type
, cu
);
16824 static struct type
*
16825 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16827 struct type
*base_type
, *cv_type
;
16829 base_type
= die_type (die
, cu
);
16831 /* The die_type call above may have already set the type for this DIE. */
16832 cv_type
= get_die_type (die
, cu
);
16836 /* In case the const qualifier is applied to an array type, the element type
16837 is so qualified, not the array type (section 6.7.3 of C99). */
16838 if (base_type
->code () == TYPE_CODE_ARRAY
)
16839 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16841 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16842 return set_die_type (die
, cv_type
, cu
);
16845 static struct type
*
16846 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16848 struct type
*base_type
, *cv_type
;
16850 base_type
= die_type (die
, cu
);
16852 /* The die_type call above may have already set the type for this DIE. */
16853 cv_type
= get_die_type (die
, cu
);
16857 /* In case the volatile qualifier is applied to an array type, the
16858 element type is so qualified, not the array type (section 6.7.3
16860 if (base_type
->code () == TYPE_CODE_ARRAY
)
16861 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16863 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16864 return set_die_type (die
, cv_type
, cu
);
16867 /* Handle DW_TAG_restrict_type. */
16869 static struct type
*
16870 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16872 struct type
*base_type
, *cv_type
;
16874 base_type
= die_type (die
, cu
);
16876 /* The die_type call above may have already set the type for this DIE. */
16877 cv_type
= get_die_type (die
, cu
);
16881 cv_type
= make_restrict_type (base_type
);
16882 return set_die_type (die
, cv_type
, cu
);
16885 /* Handle DW_TAG_atomic_type. */
16887 static struct type
*
16888 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16890 struct type
*base_type
, *cv_type
;
16892 base_type
= die_type (die
, cu
);
16894 /* The die_type call above may have already set the type for this DIE. */
16895 cv_type
= get_die_type (die
, cu
);
16899 cv_type
= make_atomic_type (base_type
);
16900 return set_die_type (die
, cv_type
, cu
);
16903 /* Extract all information from a DW_TAG_string_type DIE and add to
16904 the user defined type vector. It isn't really a user defined type,
16905 but it behaves like one, with other DIE's using an AT_user_def_type
16906 attribute to reference it. */
16908 static struct type
*
16909 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16911 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16912 struct gdbarch
*gdbarch
= objfile
->arch ();
16913 struct type
*type
, *range_type
, *index_type
, *char_type
;
16914 struct attribute
*attr
;
16915 struct dynamic_prop prop
;
16916 bool length_is_constant
= true;
16919 /* There are a couple of places where bit sizes might be made use of
16920 when parsing a DW_TAG_string_type, however, no producer that we know
16921 of make use of these. Handling bit sizes that are a multiple of the
16922 byte size is easy enough, but what about other bit sizes? Lets deal
16923 with that problem when we have to. Warn about these attributes being
16924 unsupported, then parse the type and ignore them like we always
16926 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16927 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16929 static bool warning_printed
= false;
16930 if (!warning_printed
)
16932 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16933 "currently supported on DW_TAG_string_type."));
16934 warning_printed
= true;
16938 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16939 if (attr
!= nullptr && !attr
->form_is_constant ())
16941 /* The string length describes the location at which the length of
16942 the string can be found. The size of the length field can be
16943 specified with one of the attributes below. */
16944 struct type
*prop_type
;
16945 struct attribute
*len
16946 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16947 if (len
== nullptr)
16948 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16949 if (len
!= nullptr && len
->form_is_constant ())
16951 /* Pass 0 as the default as we know this attribute is constant
16952 and the default value will not be returned. */
16953 LONGEST sz
= len
->constant_value (0);
16954 prop_type
= cu
->per_cu
->int_type (sz
, true);
16958 /* If the size is not specified then we assume it is the size of
16959 an address on this target. */
16960 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16963 /* Convert the attribute into a dynamic property. */
16964 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16967 length_is_constant
= false;
16969 else if (attr
!= nullptr)
16971 /* This DW_AT_string_length just contains the length with no
16972 indirection. There's no need to create a dynamic property in this
16973 case. Pass 0 for the default value as we know it will not be
16974 returned in this case. */
16975 length
= attr
->constant_value (0);
16977 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16979 /* We don't currently support non-constant byte sizes for strings. */
16980 length
= attr
->constant_value (1);
16984 /* Use 1 as a fallback length if we have nothing else. */
16988 index_type
= objfile_type (objfile
)->builtin_int
;
16989 if (length_is_constant
)
16990 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16993 struct dynamic_prop low_bound
;
16995 low_bound
.kind
= PROP_CONST
;
16996 low_bound
.data
.const_val
= 1;
16997 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16999 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17000 type
= create_string_type (NULL
, char_type
, range_type
);
17002 return set_die_type (die
, type
, cu
);
17005 /* Assuming that DIE corresponds to a function, returns nonzero
17006 if the function is prototyped. */
17009 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17011 struct attribute
*attr
;
17013 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17014 if (attr
&& (DW_UNSND (attr
) != 0))
17017 /* The DWARF standard implies that the DW_AT_prototyped attribute
17018 is only meaningful for C, but the concept also extends to other
17019 languages that allow unprototyped functions (Eg: Objective C).
17020 For all other languages, assume that functions are always
17022 if (cu
->language
!= language_c
17023 && cu
->language
!= language_objc
17024 && cu
->language
!= language_opencl
)
17027 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17028 prototyped and unprototyped functions; default to prototyped,
17029 since that is more common in modern code (and RealView warns
17030 about unprototyped functions). */
17031 if (producer_is_realview (cu
->producer
))
17037 /* Handle DIES due to C code like:
17041 int (*funcp)(int a, long l);
17045 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17047 static struct type
*
17048 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17050 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17051 struct type
*type
; /* Type that this function returns. */
17052 struct type
*ftype
; /* Function that returns above type. */
17053 struct attribute
*attr
;
17055 type
= die_type (die
, cu
);
17057 /* The die_type call above may have already set the type for this DIE. */
17058 ftype
= get_die_type (die
, cu
);
17062 ftype
= lookup_function_type (type
);
17064 if (prototyped_function_p (die
, cu
))
17065 TYPE_PROTOTYPED (ftype
) = 1;
17067 /* Store the calling convention in the type if it's available in
17068 the subroutine die. Otherwise set the calling convention to
17069 the default value DW_CC_normal. */
17070 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17071 if (attr
!= nullptr
17072 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17073 TYPE_CALLING_CONVENTION (ftype
)
17074 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17075 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17076 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17078 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17080 /* Record whether the function returns normally to its caller or not
17081 if the DWARF producer set that information. */
17082 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17083 if (attr
&& (DW_UNSND (attr
) != 0))
17084 TYPE_NO_RETURN (ftype
) = 1;
17086 /* We need to add the subroutine type to the die immediately so
17087 we don't infinitely recurse when dealing with parameters
17088 declared as the same subroutine type. */
17089 set_die_type (die
, ftype
, cu
);
17091 if (die
->child
!= NULL
)
17093 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17094 struct die_info
*child_die
;
17095 int nparams
, iparams
;
17097 /* Count the number of parameters.
17098 FIXME: GDB currently ignores vararg functions, but knows about
17099 vararg member functions. */
17101 child_die
= die
->child
;
17102 while (child_die
&& child_die
->tag
)
17104 if (child_die
->tag
== DW_TAG_formal_parameter
)
17106 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17107 TYPE_VARARGS (ftype
) = 1;
17108 child_die
= child_die
->sibling
;
17111 /* Allocate storage for parameters and fill them in. */
17112 ftype
->set_num_fields (nparams
);
17114 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17116 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17117 even if we error out during the parameters reading below. */
17118 for (iparams
= 0; iparams
< nparams
; iparams
++)
17119 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17122 child_die
= die
->child
;
17123 while (child_die
&& child_die
->tag
)
17125 if (child_die
->tag
== DW_TAG_formal_parameter
)
17127 struct type
*arg_type
;
17129 /* DWARF version 2 has no clean way to discern C++
17130 static and non-static member functions. G++ helps
17131 GDB by marking the first parameter for non-static
17132 member functions (which is the this pointer) as
17133 artificial. We pass this information to
17134 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17136 DWARF version 3 added DW_AT_object_pointer, which GCC
17137 4.5 does not yet generate. */
17138 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17139 if (attr
!= nullptr)
17140 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17142 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17143 arg_type
= die_type (child_die
, cu
);
17145 /* RealView does not mark THIS as const, which the testsuite
17146 expects. GCC marks THIS as const in method definitions,
17147 but not in the class specifications (GCC PR 43053). */
17148 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17149 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17152 struct dwarf2_cu
*arg_cu
= cu
;
17153 const char *name
= dwarf2_name (child_die
, cu
);
17155 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17156 if (attr
!= nullptr)
17158 /* If the compiler emits this, use it. */
17159 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17162 else if (name
&& strcmp (name
, "this") == 0)
17163 /* Function definitions will have the argument names. */
17165 else if (name
== NULL
&& iparams
== 0)
17166 /* Declarations may not have the names, so like
17167 elsewhere in GDB, assume an artificial first
17168 argument is "this". */
17172 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17176 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17179 child_die
= child_die
->sibling
;
17186 static struct type
*
17187 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17189 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17190 const char *name
= NULL
;
17191 struct type
*this_type
, *target_type
;
17193 name
= dwarf2_full_name (NULL
, die
, cu
);
17194 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17195 TYPE_TARGET_STUB (this_type
) = 1;
17196 set_die_type (die
, this_type
, cu
);
17197 target_type
= die_type (die
, cu
);
17198 if (target_type
!= this_type
)
17199 TYPE_TARGET_TYPE (this_type
) = target_type
;
17202 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17203 spec and cause infinite loops in GDB. */
17204 complaint (_("Self-referential DW_TAG_typedef "
17205 "- DIE at %s [in module %s]"),
17206 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17207 TYPE_TARGET_TYPE (this_type
) = NULL
;
17211 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17212 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17213 Handle these by just returning the target type, rather than
17214 constructing an anonymous typedef type and trying to handle this
17216 set_die_type (die
, target_type
, cu
);
17217 return target_type
;
17222 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17223 (which may be different from NAME) to the architecture back-end to allow
17224 it to guess the correct format if necessary. */
17226 static struct type
*
17227 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17228 const char *name_hint
, enum bfd_endian byte_order
)
17230 struct gdbarch
*gdbarch
= objfile
->arch ();
17231 const struct floatformat
**format
;
17234 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17236 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17238 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17243 /* Allocate an integer type of size BITS and name NAME. */
17245 static struct type
*
17246 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17247 int bits
, int unsigned_p
, const char *name
)
17251 /* Versions of Intel's C Compiler generate an integer type called "void"
17252 instead of using DW_TAG_unspecified_type. This has been seen on
17253 at least versions 14, 17, and 18. */
17254 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17255 && strcmp (name
, "void") == 0)
17256 type
= objfile_type (objfile
)->builtin_void
;
17258 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17263 /* Initialise and return a floating point type of size BITS suitable for
17264 use as a component of a complex number. The NAME_HINT is passed through
17265 when initialising the floating point type and is the name of the complex
17268 As DWARF doesn't currently provide an explicit name for the components
17269 of a complex number, but it can be helpful to have these components
17270 named, we try to select a suitable name based on the size of the
17272 static struct type
*
17273 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17274 struct objfile
*objfile
,
17275 int bits
, const char *name_hint
,
17276 enum bfd_endian byte_order
)
17278 gdbarch
*gdbarch
= objfile
->arch ();
17279 struct type
*tt
= nullptr;
17281 /* Try to find a suitable floating point builtin type of size BITS.
17282 We're going to use the name of this type as the name for the complex
17283 target type that we are about to create. */
17284 switch (cu
->language
)
17286 case language_fortran
:
17290 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17293 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17295 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17297 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17305 tt
= builtin_type (gdbarch
)->builtin_float
;
17308 tt
= builtin_type (gdbarch
)->builtin_double
;
17310 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17312 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17318 /* If the type we found doesn't match the size we were looking for, then
17319 pretend we didn't find a type at all, the complex target type we
17320 create will then be nameless. */
17321 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17324 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17325 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17328 /* Find a representation of a given base type and install
17329 it in the TYPE field of the die. */
17331 static struct type
*
17332 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17334 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17336 struct attribute
*attr
;
17337 int encoding
= 0, bits
= 0;
17341 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17342 if (attr
!= nullptr)
17343 encoding
= DW_UNSND (attr
);
17344 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17345 if (attr
!= nullptr)
17346 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17347 name
= dwarf2_name (die
, cu
);
17349 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17351 arch
= objfile
->arch ();
17352 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17354 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17357 int endianity
= DW_UNSND (attr
);
17362 byte_order
= BFD_ENDIAN_BIG
;
17364 case DW_END_little
:
17365 byte_order
= BFD_ENDIAN_LITTLE
;
17368 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17375 case DW_ATE_address
:
17376 /* Turn DW_ATE_address into a void * pointer. */
17377 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17378 type
= init_pointer_type (objfile
, bits
, name
, type
);
17380 case DW_ATE_boolean
:
17381 type
= init_boolean_type (objfile
, bits
, 1, name
);
17383 case DW_ATE_complex_float
:
17384 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17386 if (type
->code () == TYPE_CODE_ERROR
)
17388 if (name
== nullptr)
17390 struct obstack
*obstack
17391 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17392 name
= obconcat (obstack
, "_Complex ", type
->name (),
17395 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17398 type
= init_complex_type (name
, type
);
17400 case DW_ATE_decimal_float
:
17401 type
= init_decfloat_type (objfile
, bits
, name
);
17404 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17406 case DW_ATE_signed
:
17407 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17409 case DW_ATE_unsigned
:
17410 if (cu
->language
== language_fortran
17412 && startswith (name
, "character("))
17413 type
= init_character_type (objfile
, bits
, 1, name
);
17415 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17417 case DW_ATE_signed_char
:
17418 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17419 || cu
->language
== language_pascal
17420 || cu
->language
== language_fortran
)
17421 type
= init_character_type (objfile
, bits
, 0, name
);
17423 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17425 case DW_ATE_unsigned_char
:
17426 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17427 || cu
->language
== language_pascal
17428 || cu
->language
== language_fortran
17429 || cu
->language
== language_rust
)
17430 type
= init_character_type (objfile
, bits
, 1, name
);
17432 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17437 type
= builtin_type (arch
)->builtin_char16
;
17438 else if (bits
== 32)
17439 type
= builtin_type (arch
)->builtin_char32
;
17442 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17444 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17446 return set_die_type (die
, type
, cu
);
17451 complaint (_("unsupported DW_AT_encoding: '%s'"),
17452 dwarf_type_encoding_name (encoding
));
17453 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17457 if (name
&& strcmp (name
, "char") == 0)
17458 TYPE_NOSIGN (type
) = 1;
17460 maybe_set_alignment (cu
, die
, type
);
17462 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17464 return set_die_type (die
, type
, cu
);
17467 /* Parse dwarf attribute if it's a block, reference or constant and put the
17468 resulting value of the attribute into struct bound_prop.
17469 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17472 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17473 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17474 struct type
*default_type
)
17476 struct dwarf2_property_baton
*baton
;
17477 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17478 struct objfile
*objfile
= per_objfile
->objfile
;
17479 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17481 gdb_assert (default_type
!= NULL
);
17483 if (attr
== NULL
|| prop
== NULL
)
17486 if (attr
->form_is_block ())
17488 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17489 baton
->property_type
= default_type
;
17490 baton
->locexpr
.per_cu
= cu
->per_cu
;
17491 baton
->locexpr
.per_objfile
= per_objfile
;
17492 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17493 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17494 switch (attr
->name
)
17496 case DW_AT_string_length
:
17497 baton
->locexpr
.is_reference
= true;
17500 baton
->locexpr
.is_reference
= false;
17503 prop
->data
.baton
= baton
;
17504 prop
->kind
= PROP_LOCEXPR
;
17505 gdb_assert (prop
->data
.baton
!= NULL
);
17507 else if (attr
->form_is_ref ())
17509 struct dwarf2_cu
*target_cu
= cu
;
17510 struct die_info
*target_die
;
17511 struct attribute
*target_attr
;
17513 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17514 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17515 if (target_attr
== NULL
)
17516 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17518 if (target_attr
== NULL
)
17521 switch (target_attr
->name
)
17523 case DW_AT_location
:
17524 if (target_attr
->form_is_section_offset ())
17526 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17527 baton
->property_type
= die_type (target_die
, target_cu
);
17528 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17529 prop
->data
.baton
= baton
;
17530 prop
->kind
= PROP_LOCLIST
;
17531 gdb_assert (prop
->data
.baton
!= NULL
);
17533 else if (target_attr
->form_is_block ())
17535 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17536 baton
->property_type
= die_type (target_die
, target_cu
);
17537 baton
->locexpr
.per_cu
= cu
->per_cu
;
17538 baton
->locexpr
.per_objfile
= per_objfile
;
17539 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17540 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17541 baton
->locexpr
.is_reference
= true;
17542 prop
->data
.baton
= baton
;
17543 prop
->kind
= PROP_LOCEXPR
;
17544 gdb_assert (prop
->data
.baton
!= NULL
);
17548 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17549 "dynamic property");
17553 case DW_AT_data_member_location
:
17557 if (!handle_data_member_location (target_die
, target_cu
,
17561 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17562 baton
->property_type
= read_type_die (target_die
->parent
,
17564 baton
->offset_info
.offset
= offset
;
17565 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17566 prop
->data
.baton
= baton
;
17567 prop
->kind
= PROP_ADDR_OFFSET
;
17572 else if (attr
->form_is_constant ())
17574 prop
->data
.const_val
= attr
->constant_value (0);
17575 prop
->kind
= PROP_CONST
;
17579 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17580 dwarf2_name (die
, cu
));
17590 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17592 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17593 struct type
*int_type
;
17595 /* Helper macro to examine the various builtin types. */
17596 #define TRY_TYPE(F) \
17597 int_type = (unsigned_p \
17598 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17599 : objfile_type (objfile)->builtin_ ## F); \
17600 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17607 TRY_TYPE (long_long
);
17611 gdb_assert_not_reached ("unable to find suitable integer type");
17617 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17619 int addr_size
= this->addr_size ();
17620 return int_type (addr_size
, unsigned_p
);
17623 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17624 present (which is valid) then compute the default type based on the
17625 compilation units address size. */
17627 static struct type
*
17628 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17630 struct type
*index_type
= die_type (die
, cu
);
17632 /* Dwarf-2 specifications explicitly allows to create subrange types
17633 without specifying a base type.
17634 In that case, the base type must be set to the type of
17635 the lower bound, upper bound or count, in that order, if any of these
17636 three attributes references an object that has a type.
17637 If no base type is found, the Dwarf-2 specifications say that
17638 a signed integer type of size equal to the size of an address should
17640 For the following C code: `extern char gdb_int [];'
17641 GCC produces an empty range DIE.
17642 FIXME: muller/2010-05-28: Possible references to object for low bound,
17643 high bound or count are not yet handled by this code. */
17644 if (index_type
->code () == TYPE_CODE_VOID
)
17645 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17650 /* Read the given DW_AT_subrange DIE. */
17652 static struct type
*
17653 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17655 struct type
*base_type
, *orig_base_type
;
17656 struct type
*range_type
;
17657 struct attribute
*attr
;
17658 struct dynamic_prop low
, high
;
17659 int low_default_is_valid
;
17660 int high_bound_is_count
= 0;
17662 ULONGEST negative_mask
;
17664 orig_base_type
= read_subrange_index_type (die
, cu
);
17666 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17667 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17668 creating the range type, but we use the result of check_typedef
17669 when examining properties of the type. */
17670 base_type
= check_typedef (orig_base_type
);
17672 /* The die_type call above may have already set the type for this DIE. */
17673 range_type
= get_die_type (die
, cu
);
17677 low
.kind
= PROP_CONST
;
17678 high
.kind
= PROP_CONST
;
17679 high
.data
.const_val
= 0;
17681 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17682 omitting DW_AT_lower_bound. */
17683 switch (cu
->language
)
17686 case language_cplus
:
17687 low
.data
.const_val
= 0;
17688 low_default_is_valid
= 1;
17690 case language_fortran
:
17691 low
.data
.const_val
= 1;
17692 low_default_is_valid
= 1;
17695 case language_objc
:
17696 case language_rust
:
17697 low
.data
.const_val
= 0;
17698 low_default_is_valid
= (cu
->header
.version
>= 4);
17702 case language_pascal
:
17703 low
.data
.const_val
= 1;
17704 low_default_is_valid
= (cu
->header
.version
>= 4);
17707 low
.data
.const_val
= 0;
17708 low_default_is_valid
= 0;
17712 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17713 if (attr
!= nullptr)
17714 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17715 else if (!low_default_is_valid
)
17716 complaint (_("Missing DW_AT_lower_bound "
17717 "- DIE at %s [in module %s]"),
17718 sect_offset_str (die
->sect_off
),
17719 objfile_name (cu
->per_objfile
->objfile
));
17721 struct attribute
*attr_ub
, *attr_count
;
17722 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17723 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17725 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17726 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17728 /* If bounds are constant do the final calculation here. */
17729 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17730 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17732 high_bound_is_count
= 1;
17736 if (attr_ub
!= NULL
)
17737 complaint (_("Unresolved DW_AT_upper_bound "
17738 "- DIE at %s [in module %s]"),
17739 sect_offset_str (die
->sect_off
),
17740 objfile_name (cu
->per_objfile
->objfile
));
17741 if (attr_count
!= NULL
)
17742 complaint (_("Unresolved DW_AT_count "
17743 "- DIE at %s [in module %s]"),
17744 sect_offset_str (die
->sect_off
),
17745 objfile_name (cu
->per_objfile
->objfile
));
17750 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17751 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17752 bias
= bias_attr
->constant_value (0);
17754 /* Normally, the DWARF producers are expected to use a signed
17755 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17756 But this is unfortunately not always the case, as witnessed
17757 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17758 is used instead. To work around that ambiguity, we treat
17759 the bounds as signed, and thus sign-extend their values, when
17760 the base type is signed. */
17762 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17763 if (low
.kind
== PROP_CONST
17764 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17765 low
.data
.const_val
|= negative_mask
;
17766 if (high
.kind
== PROP_CONST
17767 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17768 high
.data
.const_val
|= negative_mask
;
17770 /* Check for bit and byte strides. */
17771 struct dynamic_prop byte_stride_prop
;
17772 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17773 if (attr_byte_stride
!= nullptr)
17775 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17776 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17780 struct dynamic_prop bit_stride_prop
;
17781 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17782 if (attr_bit_stride
!= nullptr)
17784 /* It only makes sense to have either a bit or byte stride. */
17785 if (attr_byte_stride
!= nullptr)
17787 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17788 "- DIE at %s [in module %s]"),
17789 sect_offset_str (die
->sect_off
),
17790 objfile_name (cu
->per_objfile
->objfile
));
17791 attr_bit_stride
= nullptr;
17795 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17796 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17801 if (attr_byte_stride
!= nullptr
17802 || attr_bit_stride
!= nullptr)
17804 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17805 struct dynamic_prop
*stride
17806 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17809 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17810 &high
, bias
, stride
, byte_stride_p
);
17813 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17815 if (high_bound_is_count
)
17816 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17818 /* Ada expects an empty array on no boundary attributes. */
17819 if (attr
== NULL
&& cu
->language
!= language_ada
)
17820 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17822 name
= dwarf2_name (die
, cu
);
17824 range_type
->set_name (name
);
17826 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17827 if (attr
!= nullptr)
17828 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17830 maybe_set_alignment (cu
, die
, range_type
);
17832 set_die_type (die
, range_type
, cu
);
17834 /* set_die_type should be already done. */
17835 set_descriptive_type (range_type
, die
, cu
);
17840 static struct type
*
17841 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17845 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17846 type
->set_name (dwarf2_name (die
, cu
));
17848 /* In Ada, an unspecified type is typically used when the description
17849 of the type is deferred to a different unit. When encountering
17850 such a type, we treat it as a stub, and try to resolve it later on,
17852 if (cu
->language
== language_ada
)
17853 TYPE_STUB (type
) = 1;
17855 return set_die_type (die
, type
, cu
);
17858 /* Read a single die and all its descendents. Set the die's sibling
17859 field to NULL; set other fields in the die correctly, and set all
17860 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17861 location of the info_ptr after reading all of those dies. PARENT
17862 is the parent of the die in question. */
17864 static struct die_info
*
17865 read_die_and_children (const struct die_reader_specs
*reader
,
17866 const gdb_byte
*info_ptr
,
17867 const gdb_byte
**new_info_ptr
,
17868 struct die_info
*parent
)
17870 struct die_info
*die
;
17871 const gdb_byte
*cur_ptr
;
17873 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17876 *new_info_ptr
= cur_ptr
;
17879 store_in_ref_table (die
, reader
->cu
);
17881 if (die
->has_children
)
17882 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17886 *new_info_ptr
= cur_ptr
;
17889 die
->sibling
= NULL
;
17890 die
->parent
= parent
;
17894 /* Read a die, all of its descendents, and all of its siblings; set
17895 all of the fields of all of the dies correctly. Arguments are as
17896 in read_die_and_children. */
17898 static struct die_info
*
17899 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17900 const gdb_byte
*info_ptr
,
17901 const gdb_byte
**new_info_ptr
,
17902 struct die_info
*parent
)
17904 struct die_info
*first_die
, *last_sibling
;
17905 const gdb_byte
*cur_ptr
;
17907 cur_ptr
= info_ptr
;
17908 first_die
= last_sibling
= NULL
;
17912 struct die_info
*die
17913 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17917 *new_info_ptr
= cur_ptr
;
17924 last_sibling
->sibling
= die
;
17926 last_sibling
= die
;
17930 /* Read a die, all of its descendents, and all of its siblings; set
17931 all of the fields of all of the dies correctly. Arguments are as
17932 in read_die_and_children.
17933 This the main entry point for reading a DIE and all its children. */
17935 static struct die_info
*
17936 read_die_and_siblings (const struct die_reader_specs
*reader
,
17937 const gdb_byte
*info_ptr
,
17938 const gdb_byte
**new_info_ptr
,
17939 struct die_info
*parent
)
17941 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17942 new_info_ptr
, parent
);
17944 if (dwarf_die_debug
)
17946 fprintf_unfiltered (gdb_stdlog
,
17947 "Read die from %s@0x%x of %s:\n",
17948 reader
->die_section
->get_name (),
17949 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17950 bfd_get_filename (reader
->abfd
));
17951 dump_die (die
, dwarf_die_debug
);
17957 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17959 The caller is responsible for filling in the extra attributes
17960 and updating (*DIEP)->num_attrs.
17961 Set DIEP to point to a newly allocated die with its information,
17962 except for its child, sibling, and parent fields. */
17964 static const gdb_byte
*
17965 read_full_die_1 (const struct die_reader_specs
*reader
,
17966 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17967 int num_extra_attrs
)
17969 unsigned int abbrev_number
, bytes_read
, i
;
17970 struct abbrev_info
*abbrev
;
17971 struct die_info
*die
;
17972 struct dwarf2_cu
*cu
= reader
->cu
;
17973 bfd
*abfd
= reader
->abfd
;
17975 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17976 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17977 info_ptr
+= bytes_read
;
17978 if (!abbrev_number
)
17984 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17986 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17988 bfd_get_filename (abfd
));
17990 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17991 die
->sect_off
= sect_off
;
17992 die
->tag
= abbrev
->tag
;
17993 die
->abbrev
= abbrev_number
;
17994 die
->has_children
= abbrev
->has_children
;
17996 /* Make the result usable.
17997 The caller needs to update num_attrs after adding the extra
17999 die
->num_attrs
= abbrev
->num_attrs
;
18001 std::vector
<int> indexes_that_need_reprocess
;
18002 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18004 bool need_reprocess
;
18006 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18007 info_ptr
, &need_reprocess
);
18008 if (need_reprocess
)
18009 indexes_that_need_reprocess
.push_back (i
);
18012 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18013 if (attr
!= nullptr)
18014 cu
->str_offsets_base
= DW_UNSND (attr
);
18016 attr
= die
->attr (DW_AT_loclists_base
);
18017 if (attr
!= nullptr)
18018 cu
->loclist_base
= DW_UNSND (attr
);
18020 auto maybe_addr_base
= die
->addr_base ();
18021 if (maybe_addr_base
.has_value ())
18022 cu
->addr_base
= *maybe_addr_base
;
18023 for (int index
: indexes_that_need_reprocess
)
18024 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18029 /* Read a die and all its attributes.
18030 Set DIEP to point to a newly allocated die with its information,
18031 except for its child, sibling, and parent fields. */
18033 static const gdb_byte
*
18034 read_full_die (const struct die_reader_specs
*reader
,
18035 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18037 const gdb_byte
*result
;
18039 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18041 if (dwarf_die_debug
)
18043 fprintf_unfiltered (gdb_stdlog
,
18044 "Read die from %s@0x%x of %s:\n",
18045 reader
->die_section
->get_name (),
18046 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18047 bfd_get_filename (reader
->abfd
));
18048 dump_die (*diep
, dwarf_die_debug
);
18055 /* Returns nonzero if TAG represents a type that we might generate a partial
18059 is_type_tag_for_partial (int tag
)
18064 /* Some types that would be reasonable to generate partial symbols for,
18065 that we don't at present. */
18066 case DW_TAG_array_type
:
18067 case DW_TAG_file_type
:
18068 case DW_TAG_ptr_to_member_type
:
18069 case DW_TAG_set_type
:
18070 case DW_TAG_string_type
:
18071 case DW_TAG_subroutine_type
:
18073 case DW_TAG_base_type
:
18074 case DW_TAG_class_type
:
18075 case DW_TAG_interface_type
:
18076 case DW_TAG_enumeration_type
:
18077 case DW_TAG_structure_type
:
18078 case DW_TAG_subrange_type
:
18079 case DW_TAG_typedef
:
18080 case DW_TAG_union_type
:
18087 /* Load all DIEs that are interesting for partial symbols into memory. */
18089 static struct partial_die_info
*
18090 load_partial_dies (const struct die_reader_specs
*reader
,
18091 const gdb_byte
*info_ptr
, int building_psymtab
)
18093 struct dwarf2_cu
*cu
= reader
->cu
;
18094 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18095 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18096 unsigned int bytes_read
;
18097 unsigned int load_all
= 0;
18098 int nesting_level
= 1;
18103 gdb_assert (cu
->per_cu
!= NULL
);
18104 if (cu
->per_cu
->load_all_dies
)
18108 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18112 &cu
->comp_unit_obstack
,
18113 hashtab_obstack_allocate
,
18114 dummy_obstack_deallocate
);
18118 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18120 /* A NULL abbrev means the end of a series of children. */
18121 if (abbrev
== NULL
)
18123 if (--nesting_level
== 0)
18126 info_ptr
+= bytes_read
;
18127 last_die
= parent_die
;
18128 parent_die
= parent_die
->die_parent
;
18132 /* Check for template arguments. We never save these; if
18133 they're seen, we just mark the parent, and go on our way. */
18134 if (parent_die
!= NULL
18135 && cu
->language
== language_cplus
18136 && (abbrev
->tag
== DW_TAG_template_type_param
18137 || abbrev
->tag
== DW_TAG_template_value_param
))
18139 parent_die
->has_template_arguments
= 1;
18143 /* We don't need a partial DIE for the template argument. */
18144 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18149 /* We only recurse into c++ subprograms looking for template arguments.
18150 Skip their other children. */
18152 && cu
->language
== language_cplus
18153 && parent_die
!= NULL
18154 && parent_die
->tag
== DW_TAG_subprogram
)
18156 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18160 /* Check whether this DIE is interesting enough to save. Normally
18161 we would not be interested in members here, but there may be
18162 later variables referencing them via DW_AT_specification (for
18163 static members). */
18165 && !is_type_tag_for_partial (abbrev
->tag
)
18166 && abbrev
->tag
!= DW_TAG_constant
18167 && abbrev
->tag
!= DW_TAG_enumerator
18168 && abbrev
->tag
!= DW_TAG_subprogram
18169 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18170 && abbrev
->tag
!= DW_TAG_lexical_block
18171 && abbrev
->tag
!= DW_TAG_variable
18172 && abbrev
->tag
!= DW_TAG_namespace
18173 && abbrev
->tag
!= DW_TAG_module
18174 && abbrev
->tag
!= DW_TAG_member
18175 && abbrev
->tag
!= DW_TAG_imported_unit
18176 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18178 /* Otherwise we skip to the next sibling, if any. */
18179 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18183 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18186 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18188 /* This two-pass algorithm for processing partial symbols has a
18189 high cost in cache pressure. Thus, handle some simple cases
18190 here which cover the majority of C partial symbols. DIEs
18191 which neither have specification tags in them, nor could have
18192 specification tags elsewhere pointing at them, can simply be
18193 processed and discarded.
18195 This segment is also optional; scan_partial_symbols and
18196 add_partial_symbol will handle these DIEs if we chain
18197 them in normally. When compilers which do not emit large
18198 quantities of duplicate debug information are more common,
18199 this code can probably be removed. */
18201 /* Any complete simple types at the top level (pretty much all
18202 of them, for a language without namespaces), can be processed
18204 if (parent_die
== NULL
18205 && pdi
.has_specification
== 0
18206 && pdi
.is_declaration
== 0
18207 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18208 || pdi
.tag
== DW_TAG_base_type
18209 || pdi
.tag
== DW_TAG_subrange_type
))
18211 if (building_psymtab
&& pdi
.name
!= NULL
)
18212 add_psymbol_to_list (pdi
.name
, false,
18213 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18214 psymbol_placement::STATIC
,
18215 0, cu
->language
, objfile
);
18216 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18220 /* The exception for DW_TAG_typedef with has_children above is
18221 a workaround of GCC PR debug/47510. In the case of this complaint
18222 type_name_or_error will error on such types later.
18224 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18225 it could not find the child DIEs referenced later, this is checked
18226 above. In correct DWARF DW_TAG_typedef should have no children. */
18228 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18229 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18230 "- DIE at %s [in module %s]"),
18231 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18233 /* If we're at the second level, and we're an enumerator, and
18234 our parent has no specification (meaning possibly lives in a
18235 namespace elsewhere), then we can add the partial symbol now
18236 instead of queueing it. */
18237 if (pdi
.tag
== DW_TAG_enumerator
18238 && parent_die
!= NULL
18239 && parent_die
->die_parent
== NULL
18240 && parent_die
->tag
== DW_TAG_enumeration_type
18241 && parent_die
->has_specification
== 0)
18243 if (pdi
.name
== NULL
)
18244 complaint (_("malformed enumerator DIE ignored"));
18245 else if (building_psymtab
)
18246 add_psymbol_to_list (pdi
.name
, false,
18247 VAR_DOMAIN
, LOC_CONST
, -1,
18248 cu
->language
== language_cplus
18249 ? psymbol_placement::GLOBAL
18250 : psymbol_placement::STATIC
,
18251 0, cu
->language
, objfile
);
18253 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18257 struct partial_die_info
*part_die
18258 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18260 /* We'll save this DIE so link it in. */
18261 part_die
->die_parent
= parent_die
;
18262 part_die
->die_sibling
= NULL
;
18263 part_die
->die_child
= NULL
;
18265 if (last_die
&& last_die
== parent_die
)
18266 last_die
->die_child
= part_die
;
18268 last_die
->die_sibling
= part_die
;
18270 last_die
= part_die
;
18272 if (first_die
== NULL
)
18273 first_die
= part_die
;
18275 /* Maybe add the DIE to the hash table. Not all DIEs that we
18276 find interesting need to be in the hash table, because we
18277 also have the parent/sibling/child chains; only those that we
18278 might refer to by offset later during partial symbol reading.
18280 For now this means things that might have be the target of a
18281 DW_AT_specification, DW_AT_abstract_origin, or
18282 DW_AT_extension. DW_AT_extension will refer only to
18283 namespaces; DW_AT_abstract_origin refers to functions (and
18284 many things under the function DIE, but we do not recurse
18285 into function DIEs during partial symbol reading) and
18286 possibly variables as well; DW_AT_specification refers to
18287 declarations. Declarations ought to have the DW_AT_declaration
18288 flag. It happens that GCC forgets to put it in sometimes, but
18289 only for functions, not for types.
18291 Adding more things than necessary to the hash table is harmless
18292 except for the performance cost. Adding too few will result in
18293 wasted time in find_partial_die, when we reread the compilation
18294 unit with load_all_dies set. */
18297 || abbrev
->tag
== DW_TAG_constant
18298 || abbrev
->tag
== DW_TAG_subprogram
18299 || abbrev
->tag
== DW_TAG_variable
18300 || abbrev
->tag
== DW_TAG_namespace
18301 || part_die
->is_declaration
)
18305 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18306 to_underlying (part_die
->sect_off
),
18311 /* For some DIEs we want to follow their children (if any). For C
18312 we have no reason to follow the children of structures; for other
18313 languages we have to, so that we can get at method physnames
18314 to infer fully qualified class names, for DW_AT_specification,
18315 and for C++ template arguments. For C++, we also look one level
18316 inside functions to find template arguments (if the name of the
18317 function does not already contain the template arguments).
18319 For Ada and Fortran, we need to scan the children of subprograms
18320 and lexical blocks as well because these languages allow the
18321 definition of nested entities that could be interesting for the
18322 debugger, such as nested subprograms for instance. */
18323 if (last_die
->has_children
18325 || last_die
->tag
== DW_TAG_namespace
18326 || last_die
->tag
== DW_TAG_module
18327 || last_die
->tag
== DW_TAG_enumeration_type
18328 || (cu
->language
== language_cplus
18329 && last_die
->tag
== DW_TAG_subprogram
18330 && (last_die
->name
== NULL
18331 || strchr (last_die
->name
, '<') == NULL
))
18332 || (cu
->language
!= language_c
18333 && (last_die
->tag
== DW_TAG_class_type
18334 || last_die
->tag
== DW_TAG_interface_type
18335 || last_die
->tag
== DW_TAG_structure_type
18336 || last_die
->tag
== DW_TAG_union_type
))
18337 || ((cu
->language
== language_ada
18338 || cu
->language
== language_fortran
)
18339 && (last_die
->tag
== DW_TAG_subprogram
18340 || last_die
->tag
== DW_TAG_lexical_block
))))
18343 parent_die
= last_die
;
18347 /* Otherwise we skip to the next sibling, if any. */
18348 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18350 /* Back to the top, do it again. */
18354 partial_die_info::partial_die_info (sect_offset sect_off_
,
18355 struct abbrev_info
*abbrev
)
18356 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18360 /* Read a minimal amount of information into the minimal die structure.
18361 INFO_PTR should point just after the initial uleb128 of a DIE. */
18364 partial_die_info::read (const struct die_reader_specs
*reader
,
18365 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18367 struct dwarf2_cu
*cu
= reader
->cu
;
18368 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18370 int has_low_pc_attr
= 0;
18371 int has_high_pc_attr
= 0;
18372 int high_pc_relative
= 0;
18374 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18377 bool need_reprocess
;
18378 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18379 info_ptr
, &need_reprocess
);
18380 /* String and address offsets that need to do the reprocessing have
18381 already been read at this point, so there is no need to wait until
18382 the loop terminates to do the reprocessing. */
18383 if (need_reprocess
)
18384 read_attribute_reprocess (reader
, &attr
);
18385 /* Store the data if it is of an attribute we want to keep in a
18386 partial symbol table. */
18392 case DW_TAG_compile_unit
:
18393 case DW_TAG_partial_unit
:
18394 case DW_TAG_type_unit
:
18395 /* Compilation units have a DW_AT_name that is a filename, not
18396 a source language identifier. */
18397 case DW_TAG_enumeration_type
:
18398 case DW_TAG_enumerator
:
18399 /* These tags always have simple identifiers already; no need
18400 to canonicalize them. */
18401 name
= DW_STRING (&attr
);
18405 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18408 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18413 case DW_AT_linkage_name
:
18414 case DW_AT_MIPS_linkage_name
:
18415 /* Note that both forms of linkage name might appear. We
18416 assume they will be the same, and we only store the last
18418 linkage_name
= attr
.value_as_string ();
18419 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18420 See https://github.com/rust-lang/rust/issues/32925. */
18421 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18422 && strchr (linkage_name
, '{') != NULL
)
18423 linkage_name
= NULL
;
18426 has_low_pc_attr
= 1;
18427 lowpc
= attr
.value_as_address ();
18429 case DW_AT_high_pc
:
18430 has_high_pc_attr
= 1;
18431 highpc
= attr
.value_as_address ();
18432 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18433 high_pc_relative
= 1;
18435 case DW_AT_location
:
18436 /* Support the .debug_loc offsets. */
18437 if (attr
.form_is_block ())
18439 d
.locdesc
= DW_BLOCK (&attr
);
18441 else if (attr
.form_is_section_offset ())
18443 dwarf2_complex_location_expr_complaint ();
18447 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18448 "partial symbol information");
18451 case DW_AT_external
:
18452 is_external
= DW_UNSND (&attr
);
18454 case DW_AT_declaration
:
18455 is_declaration
= DW_UNSND (&attr
);
18460 case DW_AT_abstract_origin
:
18461 case DW_AT_specification
:
18462 case DW_AT_extension
:
18463 has_specification
= 1;
18464 spec_offset
= attr
.get_ref_die_offset ();
18465 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18466 || cu
->per_cu
->is_dwz
);
18468 case DW_AT_sibling
:
18469 /* Ignore absolute siblings, they might point outside of
18470 the current compile unit. */
18471 if (attr
.form
== DW_FORM_ref_addr
)
18472 complaint (_("ignoring absolute DW_AT_sibling"));
18475 const gdb_byte
*buffer
= reader
->buffer
;
18476 sect_offset off
= attr
.get_ref_die_offset ();
18477 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18479 if (sibling_ptr
< info_ptr
)
18480 complaint (_("DW_AT_sibling points backwards"));
18481 else if (sibling_ptr
> reader
->buffer_end
)
18482 reader
->die_section
->overflow_complaint ();
18484 sibling
= sibling_ptr
;
18487 case DW_AT_byte_size
:
18490 case DW_AT_const_value
:
18491 has_const_value
= 1;
18493 case DW_AT_calling_convention
:
18494 /* DWARF doesn't provide a way to identify a program's source-level
18495 entry point. DW_AT_calling_convention attributes are only meant
18496 to describe functions' calling conventions.
18498 However, because it's a necessary piece of information in
18499 Fortran, and before DWARF 4 DW_CC_program was the only
18500 piece of debugging information whose definition refers to
18501 a 'main program' at all, several compilers marked Fortran
18502 main programs with DW_CC_program --- even when those
18503 functions use the standard calling conventions.
18505 Although DWARF now specifies a way to provide this
18506 information, we support this practice for backward
18508 if (DW_UNSND (&attr
) == DW_CC_program
18509 && cu
->language
== language_fortran
)
18510 main_subprogram
= 1;
18513 if (DW_UNSND (&attr
) == DW_INL_inlined
18514 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18515 may_be_inlined
= 1;
18519 if (tag
== DW_TAG_imported_unit
)
18521 d
.sect_off
= attr
.get_ref_die_offset ();
18522 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18523 || cu
->per_cu
->is_dwz
);
18527 case DW_AT_main_subprogram
:
18528 main_subprogram
= DW_UNSND (&attr
);
18533 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18534 but that requires a full DIE, so instead we just
18536 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18537 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18538 + (need_ranges_base
18542 /* Value of the DW_AT_ranges attribute is the offset in the
18543 .debug_ranges section. */
18544 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18555 /* For Ada, if both the name and the linkage name appear, we prefer
18556 the latter. This lets "catch exception" work better, regardless
18557 of the order in which the name and linkage name were emitted.
18558 Really, though, this is just a workaround for the fact that gdb
18559 doesn't store both the name and the linkage name. */
18560 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18561 name
= linkage_name
;
18563 if (high_pc_relative
)
18566 if (has_low_pc_attr
&& has_high_pc_attr
)
18568 /* When using the GNU linker, .gnu.linkonce. sections are used to
18569 eliminate duplicate copies of functions and vtables and such.
18570 The linker will arbitrarily choose one and discard the others.
18571 The AT_*_pc values for such functions refer to local labels in
18572 these sections. If the section from that file was discarded, the
18573 labels are not in the output, so the relocs get a value of 0.
18574 If this is a discarded function, mark the pc bounds as invalid,
18575 so that GDB will ignore it. */
18576 if (lowpc
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
18578 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18579 struct gdbarch
*gdbarch
= objfile
->arch ();
18581 complaint (_("DW_AT_low_pc %s is zero "
18582 "for DIE at %s [in module %s]"),
18583 paddress (gdbarch
, lowpc
),
18584 sect_offset_str (sect_off
),
18585 objfile_name (objfile
));
18587 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18588 else if (lowpc
>= highpc
)
18590 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18591 struct gdbarch
*gdbarch
= objfile
->arch ();
18593 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18594 "for DIE at %s [in module %s]"),
18595 paddress (gdbarch
, lowpc
),
18596 paddress (gdbarch
, highpc
),
18597 sect_offset_str (sect_off
),
18598 objfile_name (objfile
));
18607 /* Find a cached partial DIE at OFFSET in CU. */
18609 struct partial_die_info
*
18610 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18612 struct partial_die_info
*lookup_die
= NULL
;
18613 struct partial_die_info
part_die (sect_off
);
18615 lookup_die
= ((struct partial_die_info
*)
18616 htab_find_with_hash (partial_dies
, &part_die
,
18617 to_underlying (sect_off
)));
18622 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18623 except in the case of .debug_types DIEs which do not reference
18624 outside their CU (they do however referencing other types via
18625 DW_FORM_ref_sig8). */
18627 static const struct cu_partial_die_info
18628 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18630 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18631 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18632 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18633 struct partial_die_info
*pd
= NULL
;
18635 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18636 && cu
->header
.offset_in_cu_p (sect_off
))
18638 pd
= cu
->find_partial_die (sect_off
);
18641 /* We missed recording what we needed.
18642 Load all dies and try again. */
18643 per_cu
= cu
->per_cu
;
18647 /* TUs don't reference other CUs/TUs (except via type signatures). */
18648 if (cu
->per_cu
->is_debug_types
)
18650 error (_("Dwarf Error: Type Unit at offset %s contains"
18651 " external reference to offset %s [in module %s].\n"),
18652 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18653 bfd_get_filename (objfile
->obfd
));
18655 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18656 dwarf2_per_objfile
);
18658 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18659 load_partial_comp_unit (per_cu
);
18661 per_cu
->cu
->last_used
= 0;
18662 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18665 /* If we didn't find it, and not all dies have been loaded,
18666 load them all and try again. */
18668 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18670 per_cu
->load_all_dies
= 1;
18672 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18673 THIS_CU->cu may already be in use. So we can't just free it and
18674 replace its DIEs with the ones we read in. Instead, we leave those
18675 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18676 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18678 load_partial_comp_unit (per_cu
);
18680 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18684 internal_error (__FILE__
, __LINE__
,
18685 _("could not find partial DIE %s "
18686 "in cache [from module %s]\n"),
18687 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18688 return { per_cu
->cu
, pd
};
18691 /* See if we can figure out if the class lives in a namespace. We do
18692 this by looking for a member function; its demangled name will
18693 contain namespace info, if there is any. */
18696 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18697 struct dwarf2_cu
*cu
)
18699 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18700 what template types look like, because the demangler
18701 frequently doesn't give the same name as the debug info. We
18702 could fix this by only using the demangled name to get the
18703 prefix (but see comment in read_structure_type). */
18705 struct partial_die_info
*real_pdi
;
18706 struct partial_die_info
*child_pdi
;
18708 /* If this DIE (this DIE's specification, if any) has a parent, then
18709 we should not do this. We'll prepend the parent's fully qualified
18710 name when we create the partial symbol. */
18712 real_pdi
= struct_pdi
;
18713 while (real_pdi
->has_specification
)
18715 auto res
= find_partial_die (real_pdi
->spec_offset
,
18716 real_pdi
->spec_is_dwz
, cu
);
18717 real_pdi
= res
.pdi
;
18721 if (real_pdi
->die_parent
!= NULL
)
18724 for (child_pdi
= struct_pdi
->die_child
;
18726 child_pdi
= child_pdi
->die_sibling
)
18728 if (child_pdi
->tag
== DW_TAG_subprogram
18729 && child_pdi
->linkage_name
!= NULL
)
18731 gdb::unique_xmalloc_ptr
<char> actual_class_name
18732 (language_class_name_from_physname (cu
->language_defn
,
18733 child_pdi
->linkage_name
));
18734 if (actual_class_name
!= NULL
)
18736 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18737 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18744 /* Return true if a DIE with TAG may have the DW_AT_const_value
18748 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18752 case DW_TAG_constant
:
18753 case DW_TAG_enumerator
:
18754 case DW_TAG_formal_parameter
:
18755 case DW_TAG_template_value_param
:
18756 case DW_TAG_variable
:
18764 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18766 /* Once we've fixed up a die, there's no point in doing so again.
18767 This also avoids a memory leak if we were to call
18768 guess_partial_die_structure_name multiple times. */
18772 /* If we found a reference attribute and the DIE has no name, try
18773 to find a name in the referred to DIE. */
18775 if (name
== NULL
&& has_specification
)
18777 struct partial_die_info
*spec_die
;
18779 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18780 spec_die
= res
.pdi
;
18783 spec_die
->fixup (cu
);
18785 if (spec_die
->name
)
18787 name
= spec_die
->name
;
18789 /* Copy DW_AT_external attribute if it is set. */
18790 if (spec_die
->is_external
)
18791 is_external
= spec_die
->is_external
;
18795 if (!has_const_value
&& has_specification
18796 && can_have_DW_AT_const_value_p (tag
))
18798 struct partial_die_info
*spec_die
;
18800 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18801 spec_die
= res
.pdi
;
18804 spec_die
->fixup (cu
);
18806 if (spec_die
->has_const_value
)
18808 /* Copy DW_AT_const_value attribute if it is set. */
18809 has_const_value
= spec_die
->has_const_value
;
18813 /* Set default names for some unnamed DIEs. */
18815 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18816 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18818 /* If there is no parent die to provide a namespace, and there are
18819 children, see if we can determine the namespace from their linkage
18821 if (cu
->language
== language_cplus
18822 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18823 && die_parent
== NULL
18825 && (tag
== DW_TAG_class_type
18826 || tag
== DW_TAG_structure_type
18827 || tag
== DW_TAG_union_type
))
18828 guess_partial_die_structure_name (this, cu
);
18830 /* GCC might emit a nameless struct or union that has a linkage
18831 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18833 && (tag
== DW_TAG_class_type
18834 || tag
== DW_TAG_interface_type
18835 || tag
== DW_TAG_structure_type
18836 || tag
== DW_TAG_union_type
)
18837 && linkage_name
!= NULL
)
18839 gdb::unique_xmalloc_ptr
<char> demangled
18840 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18841 if (demangled
!= nullptr)
18845 /* Strip any leading namespaces/classes, keep only the base name.
18846 DW_AT_name for named DIEs does not contain the prefixes. */
18847 base
= strrchr (demangled
.get (), ':');
18848 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18851 base
= demangled
.get ();
18853 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18854 name
= objfile
->intern (base
);
18861 /* Read the .debug_loclists header contents from the given SECTION in the
18864 read_loclist_header (struct loclist_header
*header
,
18865 struct dwarf2_section_info
*section
)
18867 unsigned int bytes_read
;
18868 bfd
*abfd
= section
->get_bfd_owner ();
18869 const gdb_byte
*info_ptr
= section
->buffer
;
18870 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18871 info_ptr
+= bytes_read
;
18872 header
->version
= read_2_bytes (abfd
, info_ptr
);
18874 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18876 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18878 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18881 /* Return the DW_AT_loclists_base value for the CU. */
18883 lookup_loclist_base (struct dwarf2_cu
*cu
)
18885 /* For the .dwo unit, the loclist_base points to the first offset following
18886 the header. The header consists of the following entities-
18887 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18889 2. version (2 bytes)
18890 3. address size (1 byte)
18891 4. segment selector size (1 byte)
18892 5. offset entry count (4 bytes)
18893 These sizes are derived as per the DWARFv5 standard. */
18894 if (cu
->dwo_unit
!= nullptr)
18896 if (cu
->header
.initial_length_size
== 4)
18897 return LOCLIST_HEADER_SIZE32
;
18898 return LOCLIST_HEADER_SIZE64
;
18900 return cu
->loclist_base
;
18903 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18904 array of offsets in the .debug_loclists section. */
18906 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18908 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18909 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18910 bfd
*abfd
= objfile
->obfd
;
18911 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18912 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18914 section
->read (objfile
);
18915 if (section
->buffer
== NULL
)
18916 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18917 "section [in module %s]"), objfile_name (objfile
));
18918 struct loclist_header header
;
18919 read_loclist_header (&header
, section
);
18920 if (loclist_index
>= header
.offset_entry_count
)
18921 complaint (_("DW_FORM_loclistx pointing outside of "
18922 ".debug_loclists offset array [in module %s]"),
18923 objfile_name (objfile
));
18924 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18926 complaint (_("DW_FORM_loclistx pointing outside of "
18927 ".debug_loclists section [in module %s]"),
18928 objfile_name (objfile
));
18929 const gdb_byte
*info_ptr
18930 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18932 if (cu
->header
.offset_size
== 4)
18933 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18935 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18938 /* Process the attributes that had to be skipped in the first round. These
18939 attributes are the ones that need str_offsets_base or addr_base attributes.
18940 They could not have been processed in the first round, because at the time
18941 the values of str_offsets_base or addr_base may not have been known. */
18943 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18944 struct attribute
*attr
)
18946 struct dwarf2_cu
*cu
= reader
->cu
;
18947 switch (attr
->form
)
18949 case DW_FORM_addrx
:
18950 case DW_FORM_GNU_addr_index
:
18951 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18953 case DW_FORM_loclistx
:
18954 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
18957 case DW_FORM_strx1
:
18958 case DW_FORM_strx2
:
18959 case DW_FORM_strx3
:
18960 case DW_FORM_strx4
:
18961 case DW_FORM_GNU_str_index
:
18963 unsigned int str_index
= DW_UNSND (attr
);
18964 if (reader
->dwo_file
!= NULL
)
18966 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18967 DW_STRING_IS_CANONICAL (attr
) = 0;
18971 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18972 DW_STRING_IS_CANONICAL (attr
) = 0;
18977 gdb_assert_not_reached (_("Unexpected DWARF form."));
18981 /* Read an attribute value described by an attribute form. */
18983 static const gdb_byte
*
18984 read_attribute_value (const struct die_reader_specs
*reader
,
18985 struct attribute
*attr
, unsigned form
,
18986 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18987 bool *need_reprocess
)
18989 struct dwarf2_cu
*cu
= reader
->cu
;
18990 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18991 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18992 bfd
*abfd
= reader
->abfd
;
18993 struct comp_unit_head
*cu_header
= &cu
->header
;
18994 unsigned int bytes_read
;
18995 struct dwarf_block
*blk
;
18996 *need_reprocess
= false;
18998 attr
->form
= (enum dwarf_form
) form
;
19001 case DW_FORM_ref_addr
:
19002 if (cu
->header
.version
== 2)
19003 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19006 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19008 info_ptr
+= bytes_read
;
19010 case DW_FORM_GNU_ref_alt
:
19011 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19012 info_ptr
+= bytes_read
;
19016 struct gdbarch
*gdbarch
= objfile
->arch ();
19017 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19018 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19019 info_ptr
+= bytes_read
;
19022 case DW_FORM_block2
:
19023 blk
= dwarf_alloc_block (cu
);
19024 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19026 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19027 info_ptr
+= blk
->size
;
19028 DW_BLOCK (attr
) = blk
;
19030 case DW_FORM_block4
:
19031 blk
= dwarf_alloc_block (cu
);
19032 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19034 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19035 info_ptr
+= blk
->size
;
19036 DW_BLOCK (attr
) = blk
;
19038 case DW_FORM_data2
:
19039 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19042 case DW_FORM_data4
:
19043 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19046 case DW_FORM_data8
:
19047 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19050 case DW_FORM_data16
:
19051 blk
= dwarf_alloc_block (cu
);
19053 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19055 DW_BLOCK (attr
) = blk
;
19057 case DW_FORM_sec_offset
:
19058 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19059 info_ptr
+= bytes_read
;
19061 case DW_FORM_loclistx
:
19063 *need_reprocess
= true;
19064 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19065 info_ptr
+= bytes_read
;
19068 case DW_FORM_string
:
19069 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19070 DW_STRING_IS_CANONICAL (attr
) = 0;
19071 info_ptr
+= bytes_read
;
19074 if (!cu
->per_cu
->is_dwz
)
19076 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19077 abfd
, info_ptr
, cu_header
,
19079 DW_STRING_IS_CANONICAL (attr
) = 0;
19080 info_ptr
+= bytes_read
;
19084 case DW_FORM_line_strp
:
19085 if (!cu
->per_cu
->is_dwz
)
19088 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
19090 DW_STRING_IS_CANONICAL (attr
) = 0;
19091 info_ptr
+= bytes_read
;
19095 case DW_FORM_GNU_strp_alt
:
19097 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19098 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19101 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19102 DW_STRING_IS_CANONICAL (attr
) = 0;
19103 info_ptr
+= bytes_read
;
19106 case DW_FORM_exprloc
:
19107 case DW_FORM_block
:
19108 blk
= dwarf_alloc_block (cu
);
19109 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19110 info_ptr
+= bytes_read
;
19111 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19112 info_ptr
+= blk
->size
;
19113 DW_BLOCK (attr
) = blk
;
19115 case DW_FORM_block1
:
19116 blk
= dwarf_alloc_block (cu
);
19117 blk
->size
= read_1_byte (abfd
, info_ptr
);
19119 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19120 info_ptr
+= blk
->size
;
19121 DW_BLOCK (attr
) = blk
;
19123 case DW_FORM_data1
:
19124 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19128 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19131 case DW_FORM_flag_present
:
19132 DW_UNSND (attr
) = 1;
19134 case DW_FORM_sdata
:
19135 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19136 info_ptr
+= bytes_read
;
19138 case DW_FORM_udata
:
19139 case DW_FORM_rnglistx
:
19140 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19141 info_ptr
+= bytes_read
;
19144 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19145 + read_1_byte (abfd
, info_ptr
));
19149 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19150 + read_2_bytes (abfd
, info_ptr
));
19154 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19155 + read_4_bytes (abfd
, info_ptr
));
19159 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19160 + read_8_bytes (abfd
, info_ptr
));
19163 case DW_FORM_ref_sig8
:
19164 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19167 case DW_FORM_ref_udata
:
19168 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19169 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19170 info_ptr
+= bytes_read
;
19172 case DW_FORM_indirect
:
19173 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19174 info_ptr
+= bytes_read
;
19175 if (form
== DW_FORM_implicit_const
)
19177 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19178 info_ptr
+= bytes_read
;
19180 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19181 info_ptr
, need_reprocess
);
19183 case DW_FORM_implicit_const
:
19184 DW_SND (attr
) = implicit_const
;
19186 case DW_FORM_addrx
:
19187 case DW_FORM_GNU_addr_index
:
19188 *need_reprocess
= true;
19189 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19190 info_ptr
+= bytes_read
;
19193 case DW_FORM_strx1
:
19194 case DW_FORM_strx2
:
19195 case DW_FORM_strx3
:
19196 case DW_FORM_strx4
:
19197 case DW_FORM_GNU_str_index
:
19199 ULONGEST str_index
;
19200 if (form
== DW_FORM_strx1
)
19202 str_index
= read_1_byte (abfd
, info_ptr
);
19205 else if (form
== DW_FORM_strx2
)
19207 str_index
= read_2_bytes (abfd
, info_ptr
);
19210 else if (form
== DW_FORM_strx3
)
19212 str_index
= read_3_bytes (abfd
, info_ptr
);
19215 else if (form
== DW_FORM_strx4
)
19217 str_index
= read_4_bytes (abfd
, info_ptr
);
19222 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19223 info_ptr
+= bytes_read
;
19225 *need_reprocess
= true;
19226 DW_UNSND (attr
) = str_index
;
19230 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19231 dwarf_form_name (form
),
19232 bfd_get_filename (abfd
));
19236 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19237 attr
->form
= DW_FORM_GNU_ref_alt
;
19239 /* We have seen instances where the compiler tried to emit a byte
19240 size attribute of -1 which ended up being encoded as an unsigned
19241 0xffffffff. Although 0xffffffff is technically a valid size value,
19242 an object of this size seems pretty unlikely so we can relatively
19243 safely treat these cases as if the size attribute was invalid and
19244 treat them as zero by default. */
19245 if (attr
->name
== DW_AT_byte_size
19246 && form
== DW_FORM_data4
19247 && DW_UNSND (attr
) >= 0xffffffff)
19250 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19251 hex_string (DW_UNSND (attr
)));
19252 DW_UNSND (attr
) = 0;
19258 /* Read an attribute described by an abbreviated attribute. */
19260 static const gdb_byte
*
19261 read_attribute (const struct die_reader_specs
*reader
,
19262 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19263 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19265 attr
->name
= abbrev
->name
;
19266 return read_attribute_value (reader
, attr
, abbrev
->form
,
19267 abbrev
->implicit_const
, info_ptr
,
19271 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19273 static const char *
19274 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19275 LONGEST str_offset
)
19277 return dwarf2_per_objfile
->per_bfd
->str
.read_string
19278 (dwarf2_per_objfile
->objfile
, str_offset
, "DW_FORM_strp");
19281 /* Return pointer to string at .debug_str offset as read from BUF.
19282 BUF is assumed to be in a compilation unit described by CU_HEADER.
19283 Return *BYTES_READ_PTR count of bytes read from BUF. */
19285 static const char *
19286 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19287 const gdb_byte
*buf
,
19288 const struct comp_unit_head
*cu_header
,
19289 unsigned int *bytes_read_ptr
)
19291 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19293 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
19299 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19300 const struct comp_unit_head
*cu_header
,
19301 unsigned int *bytes_read_ptr
)
19303 bfd
*abfd
= objfile
->obfd
;
19304 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19306 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19309 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19310 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19311 ADDR_SIZE is the size of addresses from the CU header. */
19314 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19315 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19318 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19319 bfd
*abfd
= objfile
->obfd
;
19320 const gdb_byte
*info_ptr
;
19321 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19323 dwarf2_per_objfile
->per_bfd
->addr
.read (objfile
);
19324 if (dwarf2_per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19325 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19326 objfile_name (objfile
));
19327 if (addr_base_or_zero
+ addr_index
* addr_size
19328 >= dwarf2_per_objfile
->per_bfd
->addr
.size
)
19329 error (_("DW_FORM_addr_index pointing outside of "
19330 ".debug_addr section [in module %s]"),
19331 objfile_name (objfile
));
19332 info_ptr
= (dwarf2_per_objfile
->per_bfd
->addr
.buffer
19333 + addr_base_or_zero
+ addr_index
* addr_size
);
19334 if (addr_size
== 4)
19335 return bfd_get_32 (abfd
, info_ptr
);
19337 return bfd_get_64 (abfd
, info_ptr
);
19340 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19343 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19345 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19346 cu
->addr_base
, cu
->header
.addr_size
);
19349 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19352 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19353 unsigned int *bytes_read
)
19355 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19356 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19358 return read_addr_index (cu
, addr_index
);
19364 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
19366 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19367 struct dwarf2_cu
*cu
= per_cu
->cu
;
19368 gdb::optional
<ULONGEST
> addr_base
;
19371 /* We need addr_base and addr_size.
19372 If we don't have PER_CU->cu, we have to get it.
19373 Nasty, but the alternative is storing the needed info in PER_CU,
19374 which at this point doesn't seem justified: it's not clear how frequently
19375 it would get used and it would increase the size of every PER_CU.
19376 Entry points like dwarf2_per_cu_addr_size do a similar thing
19377 so we're not in uncharted territory here.
19378 Alas we need to be a bit more complicated as addr_base is contained
19381 We don't need to read the entire CU(/TU).
19382 We just need the header and top level die.
19384 IWBN to use the aging mechanism to let us lazily later discard the CU.
19385 For now we skip this optimization. */
19389 addr_base
= cu
->addr_base
;
19390 addr_size
= cu
->header
.addr_size
;
19394 cutu_reader
reader (per_cu
, NULL
, 0, false);
19395 addr_base
= reader
.cu
->addr_base
;
19396 addr_size
= reader
.cu
->header
.addr_size
;
19399 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19403 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19404 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19407 static const char *
19408 read_str_index (struct dwarf2_cu
*cu
,
19409 struct dwarf2_section_info
*str_section
,
19410 struct dwarf2_section_info
*str_offsets_section
,
19411 ULONGEST str_offsets_base
, ULONGEST str_index
)
19413 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19414 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19415 const char *objf_name
= objfile_name (objfile
);
19416 bfd
*abfd
= objfile
->obfd
;
19417 const gdb_byte
*info_ptr
;
19418 ULONGEST str_offset
;
19419 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19421 str_section
->read (objfile
);
19422 str_offsets_section
->read (objfile
);
19423 if (str_section
->buffer
== NULL
)
19424 error (_("%s used without %s section"
19425 " in CU at offset %s [in module %s]"),
19426 form_name
, str_section
->get_name (),
19427 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19428 if (str_offsets_section
->buffer
== NULL
)
19429 error (_("%s used without %s section"
19430 " in CU at offset %s [in module %s]"),
19431 form_name
, str_section
->get_name (),
19432 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19433 info_ptr
= (str_offsets_section
->buffer
19435 + str_index
* cu
->header
.offset_size
);
19436 if (cu
->header
.offset_size
== 4)
19437 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19439 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19440 if (str_offset
>= str_section
->size
)
19441 error (_("Offset from %s pointing outside of"
19442 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19443 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19444 return (const char *) (str_section
->buffer
+ str_offset
);
19447 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19449 static const char *
19450 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19452 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19453 ? reader
->cu
->header
.addr_size
: 0;
19454 return read_str_index (reader
->cu
,
19455 &reader
->dwo_file
->sections
.str
,
19456 &reader
->dwo_file
->sections
.str_offsets
,
19457 str_offsets_base
, str_index
);
19460 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19462 static const char *
19463 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19465 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19466 const char *objf_name
= objfile_name (objfile
);
19467 static const char form_name
[] = "DW_FORM_GNU_str_index";
19468 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19470 if (!cu
->str_offsets_base
.has_value ())
19471 error (_("%s used in Fission stub without %s"
19472 " in CU at offset 0x%lx [in module %s]"),
19473 form_name
, str_offsets_attr_name
,
19474 (long) cu
->header
.offset_size
, objf_name
);
19476 return read_str_index (cu
,
19477 &cu
->per_objfile
->per_bfd
->str
,
19478 &cu
->per_objfile
->per_bfd
->str_offsets
,
19479 *cu
->str_offsets_base
, str_index
);
19482 /* Return the length of an LEB128 number in BUF. */
19485 leb128_size (const gdb_byte
*buf
)
19487 const gdb_byte
*begin
= buf
;
19493 if ((byte
& 128) == 0)
19494 return buf
- begin
;
19499 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19508 cu
->language
= language_c
;
19511 case DW_LANG_C_plus_plus
:
19512 case DW_LANG_C_plus_plus_11
:
19513 case DW_LANG_C_plus_plus_14
:
19514 cu
->language
= language_cplus
;
19517 cu
->language
= language_d
;
19519 case DW_LANG_Fortran77
:
19520 case DW_LANG_Fortran90
:
19521 case DW_LANG_Fortran95
:
19522 case DW_LANG_Fortran03
:
19523 case DW_LANG_Fortran08
:
19524 cu
->language
= language_fortran
;
19527 cu
->language
= language_go
;
19529 case DW_LANG_Mips_Assembler
:
19530 cu
->language
= language_asm
;
19532 case DW_LANG_Ada83
:
19533 case DW_LANG_Ada95
:
19534 cu
->language
= language_ada
;
19536 case DW_LANG_Modula2
:
19537 cu
->language
= language_m2
;
19539 case DW_LANG_Pascal83
:
19540 cu
->language
= language_pascal
;
19543 cu
->language
= language_objc
;
19546 case DW_LANG_Rust_old
:
19547 cu
->language
= language_rust
;
19549 case DW_LANG_Cobol74
:
19550 case DW_LANG_Cobol85
:
19552 cu
->language
= language_minimal
;
19555 cu
->language_defn
= language_def (cu
->language
);
19558 /* Return the named attribute or NULL if not there. */
19560 static struct attribute
*
19561 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19566 struct attribute
*spec
= NULL
;
19568 for (i
= 0; i
< die
->num_attrs
; ++i
)
19570 if (die
->attrs
[i
].name
== name
)
19571 return &die
->attrs
[i
];
19572 if (die
->attrs
[i
].name
== DW_AT_specification
19573 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19574 spec
= &die
->attrs
[i
];
19580 die
= follow_die_ref (die
, spec
, &cu
);
19586 /* Return the string associated with a string-typed attribute, or NULL if it
19587 is either not found or is of an incorrect type. */
19589 static const char *
19590 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19592 struct attribute
*attr
;
19593 const char *str
= NULL
;
19595 attr
= dwarf2_attr (die
, name
, cu
);
19599 str
= attr
->value_as_string ();
19600 if (str
== nullptr)
19601 complaint (_("string type expected for attribute %s for "
19602 "DIE at %s in module %s"),
19603 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19604 objfile_name (cu
->per_objfile
->objfile
));
19610 /* Return the dwo name or NULL if not present. If present, it is in either
19611 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19612 static const char *
19613 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19615 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19616 if (dwo_name
== nullptr)
19617 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19621 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19622 and holds a non-zero value. This function should only be used for
19623 DW_FORM_flag or DW_FORM_flag_present attributes. */
19626 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19628 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19630 return (attr
&& DW_UNSND (attr
));
19634 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19636 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19637 which value is non-zero. However, we have to be careful with
19638 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19639 (via dwarf2_flag_true_p) follows this attribute. So we may
19640 end up accidently finding a declaration attribute that belongs
19641 to a different DIE referenced by the specification attribute,
19642 even though the given DIE does not have a declaration attribute. */
19643 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19644 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19647 /* Return the die giving the specification for DIE, if there is
19648 one. *SPEC_CU is the CU containing DIE on input, and the CU
19649 containing the return value on output. If there is no
19650 specification, but there is an abstract origin, that is
19653 static struct die_info
*
19654 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19656 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19659 if (spec_attr
== NULL
)
19660 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19662 if (spec_attr
== NULL
)
19665 return follow_die_ref (die
, spec_attr
, spec_cu
);
19668 /* Stub for free_line_header to match void * callback types. */
19671 free_line_header_voidp (void *arg
)
19673 struct line_header
*lh
= (struct line_header
*) arg
;
19678 /* A convenience function to find the proper .debug_line section for a CU. */
19680 static struct dwarf2_section_info
*
19681 get_debug_line_section (struct dwarf2_cu
*cu
)
19683 struct dwarf2_section_info
*section
;
19684 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19686 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19688 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19689 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19690 else if (cu
->per_cu
->is_dwz
)
19692 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19694 section
= &dwz
->line
;
19697 section
= &dwarf2_per_objfile
->per_bfd
->line
;
19702 /* Read the statement program header starting at OFFSET in
19703 .debug_line, or .debug_line.dwo. Return a pointer
19704 to a struct line_header, allocated using xmalloc.
19705 Returns NULL if there is a problem reading the header, e.g., if it
19706 has a version we don't understand.
19708 NOTE: the strings in the include directory and file name tables of
19709 the returned object point into the dwarf line section buffer,
19710 and must not be freed. */
19712 static line_header_up
19713 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19715 struct dwarf2_section_info
*section
;
19716 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19718 section
= get_debug_line_section (cu
);
19719 section
->read (dwarf2_per_objfile
->objfile
);
19720 if (section
->buffer
== NULL
)
19722 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19723 complaint (_("missing .debug_line.dwo section"));
19725 complaint (_("missing .debug_line section"));
19729 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19730 dwarf2_per_objfile
, section
,
19734 /* Subroutine of dwarf_decode_lines to simplify it.
19735 Return the file name of the psymtab for the given file_entry.
19736 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19737 If space for the result is malloc'd, *NAME_HOLDER will be set.
19738 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19740 static const char *
19741 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19742 const dwarf2_psymtab
*pst
,
19743 const char *comp_dir
,
19744 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19746 const char *include_name
= fe
.name
;
19747 const char *include_name_to_compare
= include_name
;
19748 const char *pst_filename
;
19751 const char *dir_name
= fe
.include_dir (lh
);
19753 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19754 if (!IS_ABSOLUTE_PATH (include_name
)
19755 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19757 /* Avoid creating a duplicate psymtab for PST.
19758 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19759 Before we do the comparison, however, we need to account
19760 for DIR_NAME and COMP_DIR.
19761 First prepend dir_name (if non-NULL). If we still don't
19762 have an absolute path prepend comp_dir (if non-NULL).
19763 However, the directory we record in the include-file's
19764 psymtab does not contain COMP_DIR (to match the
19765 corresponding symtab(s)).
19770 bash$ gcc -g ./hello.c
19771 include_name = "hello.c"
19773 DW_AT_comp_dir = comp_dir = "/tmp"
19774 DW_AT_name = "./hello.c"
19778 if (dir_name
!= NULL
)
19780 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19781 include_name
, (char *) NULL
));
19782 include_name
= name_holder
->get ();
19783 include_name_to_compare
= include_name
;
19785 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19787 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19788 include_name
, (char *) NULL
));
19789 include_name_to_compare
= hold_compare
.get ();
19793 pst_filename
= pst
->filename
;
19794 gdb::unique_xmalloc_ptr
<char> copied_name
;
19795 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19797 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19798 pst_filename
, (char *) NULL
));
19799 pst_filename
= copied_name
.get ();
19802 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19806 return include_name
;
19809 /* State machine to track the state of the line number program. */
19811 class lnp_state_machine
19814 /* Initialize a machine state for the start of a line number
19816 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19817 bool record_lines_p
);
19819 file_entry
*current_file ()
19821 /* lh->file_names is 0-based, but the file name numbers in the
19822 statement program are 1-based. */
19823 return m_line_header
->file_name_at (m_file
);
19826 /* Record the line in the state machine. END_SEQUENCE is true if
19827 we're processing the end of a sequence. */
19828 void record_line (bool end_sequence
);
19830 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19831 nop-out rest of the lines in this sequence. */
19832 void check_line_address (struct dwarf2_cu
*cu
,
19833 const gdb_byte
*line_ptr
,
19834 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19836 void handle_set_discriminator (unsigned int discriminator
)
19838 m_discriminator
= discriminator
;
19839 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19842 /* Handle DW_LNE_set_address. */
19843 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19846 address
+= baseaddr
;
19847 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19850 /* Handle DW_LNS_advance_pc. */
19851 void handle_advance_pc (CORE_ADDR adjust
);
19853 /* Handle a special opcode. */
19854 void handle_special_opcode (unsigned char op_code
);
19856 /* Handle DW_LNS_advance_line. */
19857 void handle_advance_line (int line_delta
)
19859 advance_line (line_delta
);
19862 /* Handle DW_LNS_set_file. */
19863 void handle_set_file (file_name_index file
);
19865 /* Handle DW_LNS_negate_stmt. */
19866 void handle_negate_stmt ()
19868 m_is_stmt
= !m_is_stmt
;
19871 /* Handle DW_LNS_const_add_pc. */
19872 void handle_const_add_pc ();
19874 /* Handle DW_LNS_fixed_advance_pc. */
19875 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19877 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19881 /* Handle DW_LNS_copy. */
19882 void handle_copy ()
19884 record_line (false);
19885 m_discriminator
= 0;
19888 /* Handle DW_LNE_end_sequence. */
19889 void handle_end_sequence ()
19891 m_currently_recording_lines
= true;
19895 /* Advance the line by LINE_DELTA. */
19896 void advance_line (int line_delta
)
19898 m_line
+= line_delta
;
19900 if (line_delta
!= 0)
19901 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19904 struct dwarf2_cu
*m_cu
;
19906 gdbarch
*m_gdbarch
;
19908 /* True if we're recording lines.
19909 Otherwise we're building partial symtabs and are just interested in
19910 finding include files mentioned by the line number program. */
19911 bool m_record_lines_p
;
19913 /* The line number header. */
19914 line_header
*m_line_header
;
19916 /* These are part of the standard DWARF line number state machine,
19917 and initialized according to the DWARF spec. */
19919 unsigned char m_op_index
= 0;
19920 /* The line table index of the current file. */
19921 file_name_index m_file
= 1;
19922 unsigned int m_line
= 1;
19924 /* These are initialized in the constructor. */
19926 CORE_ADDR m_address
;
19928 unsigned int m_discriminator
;
19930 /* Additional bits of state we need to track. */
19932 /* The last file that we called dwarf2_start_subfile for.
19933 This is only used for TLLs. */
19934 unsigned int m_last_file
= 0;
19935 /* The last file a line number was recorded for. */
19936 struct subfile
*m_last_subfile
= NULL
;
19938 /* When true, record the lines we decode. */
19939 bool m_currently_recording_lines
= false;
19941 /* The last line number that was recorded, used to coalesce
19942 consecutive entries for the same line. This can happen, for
19943 example, when discriminators are present. PR 17276. */
19944 unsigned int m_last_line
= 0;
19945 bool m_line_has_non_zero_discriminator
= false;
19949 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19951 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19952 / m_line_header
->maximum_ops_per_instruction
)
19953 * m_line_header
->minimum_instruction_length
);
19954 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19955 m_op_index
= ((m_op_index
+ adjust
)
19956 % m_line_header
->maximum_ops_per_instruction
);
19960 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19962 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19963 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19964 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19965 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19966 / m_line_header
->maximum_ops_per_instruction
)
19967 * m_line_header
->minimum_instruction_length
);
19968 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19969 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19970 % m_line_header
->maximum_ops_per_instruction
);
19972 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19973 advance_line (line_delta
);
19974 record_line (false);
19975 m_discriminator
= 0;
19979 lnp_state_machine::handle_set_file (file_name_index file
)
19983 const file_entry
*fe
= current_file ();
19985 dwarf2_debug_line_missing_file_complaint ();
19986 else if (m_record_lines_p
)
19988 const char *dir
= fe
->include_dir (m_line_header
);
19990 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19991 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19992 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19997 lnp_state_machine::handle_const_add_pc ()
20000 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20003 = (((m_op_index
+ adjust
)
20004 / m_line_header
->maximum_ops_per_instruction
)
20005 * m_line_header
->minimum_instruction_length
);
20007 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20008 m_op_index
= ((m_op_index
+ adjust
)
20009 % m_line_header
->maximum_ops_per_instruction
);
20012 /* Return non-zero if we should add LINE to the line number table.
20013 LINE is the line to add, LAST_LINE is the last line that was added,
20014 LAST_SUBFILE is the subfile for LAST_LINE.
20015 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20016 had a non-zero discriminator.
20018 We have to be careful in the presence of discriminators.
20019 E.g., for this line:
20021 for (i = 0; i < 100000; i++);
20023 clang can emit four line number entries for that one line,
20024 each with a different discriminator.
20025 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20027 However, we want gdb to coalesce all four entries into one.
20028 Otherwise the user could stepi into the middle of the line and
20029 gdb would get confused about whether the pc really was in the
20030 middle of the line.
20032 Things are further complicated by the fact that two consecutive
20033 line number entries for the same line is a heuristic used by gcc
20034 to denote the end of the prologue. So we can't just discard duplicate
20035 entries, we have to be selective about it. The heuristic we use is
20036 that we only collapse consecutive entries for the same line if at least
20037 one of those entries has a non-zero discriminator. PR 17276.
20039 Note: Addresses in the line number state machine can never go backwards
20040 within one sequence, thus this coalescing is ok. */
20043 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20044 unsigned int line
, unsigned int last_line
,
20045 int line_has_non_zero_discriminator
,
20046 struct subfile
*last_subfile
)
20048 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20050 if (line
!= last_line
)
20052 /* Same line for the same file that we've seen already.
20053 As a last check, for pr 17276, only record the line if the line
20054 has never had a non-zero discriminator. */
20055 if (!line_has_non_zero_discriminator
)
20060 /* Use the CU's builder to record line number LINE beginning at
20061 address ADDRESS in the line table of subfile SUBFILE. */
20064 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20065 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20066 struct dwarf2_cu
*cu
)
20068 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20070 if (dwarf_line_debug
)
20072 fprintf_unfiltered (gdb_stdlog
,
20073 "Recording line %u, file %s, address %s\n",
20074 line
, lbasename (subfile
->name
),
20075 paddress (gdbarch
, address
));
20079 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20082 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20083 Mark the end of a set of line number records.
20084 The arguments are the same as for dwarf_record_line_1.
20085 If SUBFILE is NULL the request is ignored. */
20088 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20089 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20091 if (subfile
== NULL
)
20094 if (dwarf_line_debug
)
20096 fprintf_unfiltered (gdb_stdlog
,
20097 "Finishing current line, file %s, address %s\n",
20098 lbasename (subfile
->name
),
20099 paddress (gdbarch
, address
));
20102 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20106 lnp_state_machine::record_line (bool end_sequence
)
20108 if (dwarf_line_debug
)
20110 fprintf_unfiltered (gdb_stdlog
,
20111 "Processing actual line %u: file %u,"
20112 " address %s, is_stmt %u, discrim %u%s\n",
20114 paddress (m_gdbarch
, m_address
),
20115 m_is_stmt
, m_discriminator
,
20116 (end_sequence
? "\t(end sequence)" : ""));
20119 file_entry
*fe
= current_file ();
20122 dwarf2_debug_line_missing_file_complaint ();
20123 /* For now we ignore lines not starting on an instruction boundary.
20124 But not when processing end_sequence for compatibility with the
20125 previous version of the code. */
20126 else if (m_op_index
== 0 || end_sequence
)
20128 fe
->included_p
= 1;
20129 if (m_record_lines_p
)
20131 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20134 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20135 m_currently_recording_lines
? m_cu
: nullptr);
20140 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20142 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20143 m_line_has_non_zero_discriminator
,
20146 buildsym_compunit
*builder
= m_cu
->get_builder ();
20147 dwarf_record_line_1 (m_gdbarch
,
20148 builder
->get_current_subfile (),
20149 m_line
, m_address
, is_stmt
,
20150 m_currently_recording_lines
? m_cu
: nullptr);
20152 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20153 m_last_line
= m_line
;
20159 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20160 line_header
*lh
, bool record_lines_p
)
20164 m_record_lines_p
= record_lines_p
;
20165 m_line_header
= lh
;
20167 m_currently_recording_lines
= true;
20169 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20170 was a line entry for it so that the backend has a chance to adjust it
20171 and also record it in case it needs it. This is currently used by MIPS
20172 code, cf. `mips_adjust_dwarf2_line'. */
20173 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20174 m_is_stmt
= lh
->default_is_stmt
;
20175 m_discriminator
= 0;
20179 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20180 const gdb_byte
*line_ptr
,
20181 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20183 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20184 the pc range of the CU. However, we restrict the test to only ADDRESS
20185 values of zero to preserve GDB's previous behaviour which is to handle
20186 the specific case of a function being GC'd by the linker. */
20188 if (address
== 0 && address
< unrelocated_lowpc
)
20190 /* This line table is for a function which has been
20191 GCd by the linker. Ignore it. PR gdb/12528 */
20193 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20194 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20196 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20197 line_offset
, objfile_name (objfile
));
20198 m_currently_recording_lines
= false;
20199 /* Note: m_currently_recording_lines is left as false until we see
20200 DW_LNE_end_sequence. */
20204 /* Subroutine of dwarf_decode_lines to simplify it.
20205 Process the line number information in LH.
20206 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20207 program in order to set included_p for every referenced header. */
20210 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20211 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20213 const gdb_byte
*line_ptr
, *extended_end
;
20214 const gdb_byte
*line_end
;
20215 unsigned int bytes_read
, extended_len
;
20216 unsigned char op_code
, extended_op
;
20217 CORE_ADDR baseaddr
;
20218 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20219 bfd
*abfd
= objfile
->obfd
;
20220 struct gdbarch
*gdbarch
= objfile
->arch ();
20221 /* True if we're recording line info (as opposed to building partial
20222 symtabs and just interested in finding include files mentioned by
20223 the line number program). */
20224 bool record_lines_p
= !decode_for_pst_p
;
20226 baseaddr
= objfile
->text_section_offset ();
20228 line_ptr
= lh
->statement_program_start
;
20229 line_end
= lh
->statement_program_end
;
20231 /* Read the statement sequences until there's nothing left. */
20232 while (line_ptr
< line_end
)
20234 /* The DWARF line number program state machine. Reset the state
20235 machine at the start of each sequence. */
20236 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20237 bool end_sequence
= false;
20239 if (record_lines_p
)
20241 /* Start a subfile for the current file of the state
20243 const file_entry
*fe
= state_machine
.current_file ();
20246 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20249 /* Decode the table. */
20250 while (line_ptr
< line_end
&& !end_sequence
)
20252 op_code
= read_1_byte (abfd
, line_ptr
);
20255 if (op_code
>= lh
->opcode_base
)
20257 /* Special opcode. */
20258 state_machine
.handle_special_opcode (op_code
);
20260 else switch (op_code
)
20262 case DW_LNS_extended_op
:
20263 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20265 line_ptr
+= bytes_read
;
20266 extended_end
= line_ptr
+ extended_len
;
20267 extended_op
= read_1_byte (abfd
, line_ptr
);
20269 switch (extended_op
)
20271 case DW_LNE_end_sequence
:
20272 state_machine
.handle_end_sequence ();
20273 end_sequence
= true;
20275 case DW_LNE_set_address
:
20278 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20279 line_ptr
+= bytes_read
;
20281 state_machine
.check_line_address (cu
, line_ptr
,
20282 lowpc
- baseaddr
, address
);
20283 state_machine
.handle_set_address (baseaddr
, address
);
20286 case DW_LNE_define_file
:
20288 const char *cur_file
;
20289 unsigned int mod_time
, length
;
20292 cur_file
= read_direct_string (abfd
, line_ptr
,
20294 line_ptr
+= bytes_read
;
20295 dindex
= (dir_index
)
20296 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20297 line_ptr
+= bytes_read
;
20299 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20300 line_ptr
+= bytes_read
;
20302 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20303 line_ptr
+= bytes_read
;
20304 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20307 case DW_LNE_set_discriminator
:
20309 /* The discriminator is not interesting to the
20310 debugger; just ignore it. We still need to
20311 check its value though:
20312 if there are consecutive entries for the same
20313 (non-prologue) line we want to coalesce them.
20316 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20317 line_ptr
+= bytes_read
;
20319 state_machine
.handle_set_discriminator (discr
);
20323 complaint (_("mangled .debug_line section"));
20326 /* Make sure that we parsed the extended op correctly. If e.g.
20327 we expected a different address size than the producer used,
20328 we may have read the wrong number of bytes. */
20329 if (line_ptr
!= extended_end
)
20331 complaint (_("mangled .debug_line section"));
20336 state_machine
.handle_copy ();
20338 case DW_LNS_advance_pc
:
20341 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20342 line_ptr
+= bytes_read
;
20344 state_machine
.handle_advance_pc (adjust
);
20347 case DW_LNS_advance_line
:
20350 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20351 line_ptr
+= bytes_read
;
20353 state_machine
.handle_advance_line (line_delta
);
20356 case DW_LNS_set_file
:
20358 file_name_index file
20359 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20361 line_ptr
+= bytes_read
;
20363 state_machine
.handle_set_file (file
);
20366 case DW_LNS_set_column
:
20367 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20368 line_ptr
+= bytes_read
;
20370 case DW_LNS_negate_stmt
:
20371 state_machine
.handle_negate_stmt ();
20373 case DW_LNS_set_basic_block
:
20375 /* Add to the address register of the state machine the
20376 address increment value corresponding to special opcode
20377 255. I.e., this value is scaled by the minimum
20378 instruction length since special opcode 255 would have
20379 scaled the increment. */
20380 case DW_LNS_const_add_pc
:
20381 state_machine
.handle_const_add_pc ();
20383 case DW_LNS_fixed_advance_pc
:
20385 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20388 state_machine
.handle_fixed_advance_pc (addr_adj
);
20393 /* Unknown standard opcode, ignore it. */
20396 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20398 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20399 line_ptr
+= bytes_read
;
20406 dwarf2_debug_line_missing_end_sequence_complaint ();
20408 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20409 in which case we still finish recording the last line). */
20410 state_machine
.record_line (true);
20414 /* Decode the Line Number Program (LNP) for the given line_header
20415 structure and CU. The actual information extracted and the type
20416 of structures created from the LNP depends on the value of PST.
20418 1. If PST is NULL, then this procedure uses the data from the program
20419 to create all necessary symbol tables, and their linetables.
20421 2. If PST is not NULL, this procedure reads the program to determine
20422 the list of files included by the unit represented by PST, and
20423 builds all the associated partial symbol tables.
20425 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20426 It is used for relative paths in the line table.
20427 NOTE: When processing partial symtabs (pst != NULL),
20428 comp_dir == pst->dirname.
20430 NOTE: It is important that psymtabs have the same file name (via strcmp)
20431 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20432 symtab we don't use it in the name of the psymtabs we create.
20433 E.g. expand_line_sal requires this when finding psymtabs to expand.
20434 A good testcase for this is mb-inline.exp.
20436 LOWPC is the lowest address in CU (or 0 if not known).
20438 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20439 for its PC<->lines mapping information. Otherwise only the filename
20440 table is read in. */
20443 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20444 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20445 CORE_ADDR lowpc
, int decode_mapping
)
20447 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20448 const int decode_for_pst_p
= (pst
!= NULL
);
20450 if (decode_mapping
)
20451 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20453 if (decode_for_pst_p
)
20455 /* Now that we're done scanning the Line Header Program, we can
20456 create the psymtab of each included file. */
20457 for (auto &file_entry
: lh
->file_names ())
20458 if (file_entry
.included_p
== 1)
20460 gdb::unique_xmalloc_ptr
<char> name_holder
;
20461 const char *include_name
=
20462 psymtab_include_file_name (lh
, file_entry
, pst
,
20463 comp_dir
, &name_holder
);
20464 if (include_name
!= NULL
)
20465 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20470 /* Make sure a symtab is created for every file, even files
20471 which contain only variables (i.e. no code with associated
20473 buildsym_compunit
*builder
= cu
->get_builder ();
20474 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20476 for (auto &fe
: lh
->file_names ())
20478 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20479 if (builder
->get_current_subfile ()->symtab
== NULL
)
20481 builder
->get_current_subfile ()->symtab
20482 = allocate_symtab (cust
,
20483 builder
->get_current_subfile ()->name
);
20485 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20490 /* Start a subfile for DWARF. FILENAME is the name of the file and
20491 DIRNAME the name of the source directory which contains FILENAME
20492 or NULL if not known.
20493 This routine tries to keep line numbers from identical absolute and
20494 relative file names in a common subfile.
20496 Using the `list' example from the GDB testsuite, which resides in
20497 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20498 of /srcdir/list0.c yields the following debugging information for list0.c:
20500 DW_AT_name: /srcdir/list0.c
20501 DW_AT_comp_dir: /compdir
20502 files.files[0].name: list0.h
20503 files.files[0].dir: /srcdir
20504 files.files[1].name: list0.c
20505 files.files[1].dir: /srcdir
20507 The line number information for list0.c has to end up in a single
20508 subfile, so that `break /srcdir/list0.c:1' works as expected.
20509 start_subfile will ensure that this happens provided that we pass the
20510 concatenation of files.files[1].dir and files.files[1].name as the
20514 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20515 const char *dirname
)
20517 gdb::unique_xmalloc_ptr
<char> copy
;
20519 /* In order not to lose the line information directory,
20520 we concatenate it to the filename when it makes sense.
20521 Note that the Dwarf3 standard says (speaking of filenames in line
20522 information): ``The directory index is ignored for file names
20523 that represent full path names''. Thus ignoring dirname in the
20524 `else' branch below isn't an issue. */
20526 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20528 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20529 filename
= copy
.get ();
20532 cu
->get_builder ()->start_subfile (filename
);
20535 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20536 buildsym_compunit constructor. */
20538 struct compunit_symtab
*
20539 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20542 gdb_assert (m_builder
== nullptr);
20544 m_builder
.reset (new struct buildsym_compunit
20545 (per_cu
->dwarf2_per_objfile
->objfile
,
20546 name
, comp_dir
, language
, low_pc
));
20548 list_in_scope
= get_builder ()->get_file_symbols ();
20550 get_builder ()->record_debugformat ("DWARF 2");
20551 get_builder ()->record_producer (producer
);
20553 processing_has_namespace_info
= false;
20555 return get_builder ()->get_compunit_symtab ();
20559 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20560 struct dwarf2_cu
*cu
)
20562 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20563 struct comp_unit_head
*cu_header
= &cu
->header
;
20565 /* NOTE drow/2003-01-30: There used to be a comment and some special
20566 code here to turn a symbol with DW_AT_external and a
20567 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20568 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20569 with some versions of binutils) where shared libraries could have
20570 relocations against symbols in their debug information - the
20571 minimal symbol would have the right address, but the debug info
20572 would not. It's no longer necessary, because we will explicitly
20573 apply relocations when we read in the debug information now. */
20575 /* A DW_AT_location attribute with no contents indicates that a
20576 variable has been optimized away. */
20577 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20579 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20583 /* Handle one degenerate form of location expression specially, to
20584 preserve GDB's previous behavior when section offsets are
20585 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20586 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20588 if (attr
->form_is_block ()
20589 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20590 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20591 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20592 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20593 && (DW_BLOCK (attr
)->size
20594 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20596 unsigned int dummy
;
20598 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20599 SET_SYMBOL_VALUE_ADDRESS
20600 (sym
, cu
->header
.read_address (objfile
->obfd
,
20601 DW_BLOCK (attr
)->data
+ 1,
20604 SET_SYMBOL_VALUE_ADDRESS
20605 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20607 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20608 fixup_symbol_section (sym
, objfile
);
20609 SET_SYMBOL_VALUE_ADDRESS
20611 SYMBOL_VALUE_ADDRESS (sym
)
20612 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20616 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20617 expression evaluator, and use LOC_COMPUTED only when necessary
20618 (i.e. when the value of a register or memory location is
20619 referenced, or a thread-local block, etc.). Then again, it might
20620 not be worthwhile. I'm assuming that it isn't unless performance
20621 or memory numbers show me otherwise. */
20623 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20625 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20626 cu
->has_loclist
= true;
20629 /* Given a pointer to a DWARF information entry, figure out if we need
20630 to make a symbol table entry for it, and if so, create a new entry
20631 and return a pointer to it.
20632 If TYPE is NULL, determine symbol type from the die, otherwise
20633 used the passed type.
20634 If SPACE is not NULL, use it to hold the new symbol. If it is
20635 NULL, allocate a new symbol on the objfile's obstack. */
20637 static struct symbol
*
20638 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20639 struct symbol
*space
)
20641 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20642 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20643 struct gdbarch
*gdbarch
= objfile
->arch ();
20644 struct symbol
*sym
= NULL
;
20646 struct attribute
*attr
= NULL
;
20647 struct attribute
*attr2
= NULL
;
20648 CORE_ADDR baseaddr
;
20649 struct pending
**list_to_add
= NULL
;
20651 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20653 baseaddr
= objfile
->text_section_offset ();
20655 name
= dwarf2_name (die
, cu
);
20658 int suppress_add
= 0;
20663 sym
= new (&objfile
->objfile_obstack
) symbol
;
20664 OBJSTAT (objfile
, n_syms
++);
20666 /* Cache this symbol's name and the name's demangled form (if any). */
20667 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20668 /* Fortran does not have mangling standard and the mangling does differ
20669 between gfortran, iFort etc. */
20670 const char *physname
20671 = (cu
->language
== language_fortran
20672 ? dwarf2_full_name (name
, die
, cu
)
20673 : dwarf2_physname (name
, die
, cu
));
20674 const char *linkagename
= dw2_linkage_name (die
, cu
);
20676 if (linkagename
== nullptr || cu
->language
== language_ada
)
20677 sym
->set_linkage_name (physname
);
20680 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20681 sym
->set_linkage_name (linkagename
);
20684 /* Default assumptions.
20685 Use the passed type or decode it from the die. */
20686 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20687 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20689 SYMBOL_TYPE (sym
) = type
;
20691 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20692 attr
= dwarf2_attr (die
,
20693 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20695 if (attr
!= nullptr)
20697 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20700 attr
= dwarf2_attr (die
,
20701 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20703 if (attr
!= nullptr)
20705 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20706 struct file_entry
*fe
;
20708 if (cu
->line_header
!= NULL
)
20709 fe
= cu
->line_header
->file_name_at (file_index
);
20714 complaint (_("file index out of range"));
20716 symbol_set_symtab (sym
, fe
->symtab
);
20722 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20723 if (attr
!= nullptr)
20727 addr
= attr
->value_as_address ();
20728 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20729 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20731 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20732 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20733 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20734 add_symbol_to_list (sym
, cu
->list_in_scope
);
20736 case DW_TAG_subprogram
:
20737 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20739 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20740 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20741 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20742 || cu
->language
== language_ada
20743 || cu
->language
== language_fortran
)
20745 /* Subprograms marked external are stored as a global symbol.
20746 Ada and Fortran subprograms, whether marked external or
20747 not, are always stored as a global symbol, because we want
20748 to be able to access them globally. For instance, we want
20749 to be able to break on a nested subprogram without having
20750 to specify the context. */
20751 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20755 list_to_add
= cu
->list_in_scope
;
20758 case DW_TAG_inlined_subroutine
:
20759 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20761 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20762 SYMBOL_INLINED (sym
) = 1;
20763 list_to_add
= cu
->list_in_scope
;
20765 case DW_TAG_template_value_param
:
20767 /* Fall through. */
20768 case DW_TAG_constant
:
20769 case DW_TAG_variable
:
20770 case DW_TAG_member
:
20771 /* Compilation with minimal debug info may result in
20772 variables with missing type entries. Change the
20773 misleading `void' type to something sensible. */
20774 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20775 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20777 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20778 /* In the case of DW_TAG_member, we should only be called for
20779 static const members. */
20780 if (die
->tag
== DW_TAG_member
)
20782 /* dwarf2_add_field uses die_is_declaration,
20783 so we do the same. */
20784 gdb_assert (die_is_declaration (die
, cu
));
20787 if (attr
!= nullptr)
20789 dwarf2_const_value (attr
, sym
, cu
);
20790 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20793 if (attr2
&& (DW_UNSND (attr2
) != 0))
20794 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20796 list_to_add
= cu
->list_in_scope
;
20800 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20801 if (attr
!= nullptr)
20803 var_decode_location (attr
, sym
, cu
);
20804 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20806 /* Fortran explicitly imports any global symbols to the local
20807 scope by DW_TAG_common_block. */
20808 if (cu
->language
== language_fortran
&& die
->parent
20809 && die
->parent
->tag
== DW_TAG_common_block
)
20812 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20813 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20814 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
20816 /* When a static variable is eliminated by the linker,
20817 the corresponding debug information is not stripped
20818 out, but the variable address is set to null;
20819 do not add such variables into symbol table. */
20821 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20823 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20824 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20825 && dwarf2_per_objfile
->per_bfd
->can_copy
)
20827 /* A global static variable might be subject to
20828 copy relocation. We first check for a local
20829 minsym, though, because maybe the symbol was
20830 marked hidden, in which case this would not
20832 bound_minimal_symbol found
20833 = (lookup_minimal_symbol_linkage
20834 (sym
->linkage_name (), objfile
));
20835 if (found
.minsym
!= nullptr)
20836 sym
->maybe_copied
= 1;
20839 /* A variable with DW_AT_external is never static,
20840 but it may be block-scoped. */
20842 = ((cu
->list_in_scope
20843 == cu
->get_builder ()->get_file_symbols ())
20844 ? cu
->get_builder ()->get_global_symbols ()
20845 : cu
->list_in_scope
);
20848 list_to_add
= cu
->list_in_scope
;
20852 /* We do not know the address of this symbol.
20853 If it is an external symbol and we have type information
20854 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20855 The address of the variable will then be determined from
20856 the minimal symbol table whenever the variable is
20858 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20860 /* Fortran explicitly imports any global symbols to the local
20861 scope by DW_TAG_common_block. */
20862 if (cu
->language
== language_fortran
&& die
->parent
20863 && die
->parent
->tag
== DW_TAG_common_block
)
20865 /* SYMBOL_CLASS doesn't matter here because
20866 read_common_block is going to reset it. */
20868 list_to_add
= cu
->list_in_scope
;
20870 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20871 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20873 /* A variable with DW_AT_external is never static, but it
20874 may be block-scoped. */
20876 = ((cu
->list_in_scope
20877 == cu
->get_builder ()->get_file_symbols ())
20878 ? cu
->get_builder ()->get_global_symbols ()
20879 : cu
->list_in_scope
);
20881 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20883 else if (!die_is_declaration (die
, cu
))
20885 /* Use the default LOC_OPTIMIZED_OUT class. */
20886 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20888 list_to_add
= cu
->list_in_scope
;
20892 case DW_TAG_formal_parameter
:
20894 /* If we are inside a function, mark this as an argument. If
20895 not, we might be looking at an argument to an inlined function
20896 when we do not have enough information to show inlined frames;
20897 pretend it's a local variable in that case so that the user can
20899 struct context_stack
*curr
20900 = cu
->get_builder ()->get_current_context_stack ();
20901 if (curr
!= nullptr && curr
->name
!= nullptr)
20902 SYMBOL_IS_ARGUMENT (sym
) = 1;
20903 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20904 if (attr
!= nullptr)
20906 var_decode_location (attr
, sym
, cu
);
20908 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20909 if (attr
!= nullptr)
20911 dwarf2_const_value (attr
, sym
, cu
);
20914 list_to_add
= cu
->list_in_scope
;
20917 case DW_TAG_unspecified_parameters
:
20918 /* From varargs functions; gdb doesn't seem to have any
20919 interest in this information, so just ignore it for now.
20922 case DW_TAG_template_type_param
:
20924 /* Fall through. */
20925 case DW_TAG_class_type
:
20926 case DW_TAG_interface_type
:
20927 case DW_TAG_structure_type
:
20928 case DW_TAG_union_type
:
20929 case DW_TAG_set_type
:
20930 case DW_TAG_enumeration_type
:
20931 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20932 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20935 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20936 really ever be static objects: otherwise, if you try
20937 to, say, break of a class's method and you're in a file
20938 which doesn't mention that class, it won't work unless
20939 the check for all static symbols in lookup_symbol_aux
20940 saves you. See the OtherFileClass tests in
20941 gdb.c++/namespace.exp. */
20945 buildsym_compunit
*builder
= cu
->get_builder ();
20947 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20948 && cu
->language
== language_cplus
20949 ? builder
->get_global_symbols ()
20950 : cu
->list_in_scope
);
20952 /* The semantics of C++ state that "struct foo {
20953 ... }" also defines a typedef for "foo". */
20954 if (cu
->language
== language_cplus
20955 || cu
->language
== language_ada
20956 || cu
->language
== language_d
20957 || cu
->language
== language_rust
)
20959 /* The symbol's name is already allocated along
20960 with this objfile, so we don't need to
20961 duplicate it for the type. */
20962 if (SYMBOL_TYPE (sym
)->name () == 0)
20963 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
20968 case DW_TAG_typedef
:
20969 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20970 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20971 list_to_add
= cu
->list_in_scope
;
20973 case DW_TAG_base_type
:
20974 case DW_TAG_subrange_type
:
20975 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20976 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20977 list_to_add
= cu
->list_in_scope
;
20979 case DW_TAG_enumerator
:
20980 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20981 if (attr
!= nullptr)
20983 dwarf2_const_value (attr
, sym
, cu
);
20986 /* NOTE: carlton/2003-11-10: See comment above in the
20987 DW_TAG_class_type, etc. block. */
20990 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20991 && cu
->language
== language_cplus
20992 ? cu
->get_builder ()->get_global_symbols ()
20993 : cu
->list_in_scope
);
20996 case DW_TAG_imported_declaration
:
20997 case DW_TAG_namespace
:
20998 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20999 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21001 case DW_TAG_module
:
21002 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21003 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21004 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21006 case DW_TAG_common_block
:
21007 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21008 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21009 add_symbol_to_list (sym
, cu
->list_in_scope
);
21012 /* Not a tag we recognize. Hopefully we aren't processing
21013 trash data, but since we must specifically ignore things
21014 we don't recognize, there is nothing else we should do at
21016 complaint (_("unsupported tag: '%s'"),
21017 dwarf_tag_name (die
->tag
));
21023 sym
->hash_next
= objfile
->template_symbols
;
21024 objfile
->template_symbols
= sym
;
21025 list_to_add
= NULL
;
21028 if (list_to_add
!= NULL
)
21029 add_symbol_to_list (sym
, list_to_add
);
21031 /* For the benefit of old versions of GCC, check for anonymous
21032 namespaces based on the demangled name. */
21033 if (!cu
->processing_has_namespace_info
21034 && cu
->language
== language_cplus
)
21035 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21040 /* Given an attr with a DW_FORM_dataN value in host byte order,
21041 zero-extend it as appropriate for the symbol's type. The DWARF
21042 standard (v4) is not entirely clear about the meaning of using
21043 DW_FORM_dataN for a constant with a signed type, where the type is
21044 wider than the data. The conclusion of a discussion on the DWARF
21045 list was that this is unspecified. We choose to always zero-extend
21046 because that is the interpretation long in use by GCC. */
21049 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21050 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21052 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21053 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21054 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21055 LONGEST l
= DW_UNSND (attr
);
21057 if (bits
< sizeof (*value
) * 8)
21059 l
&= ((LONGEST
) 1 << bits
) - 1;
21062 else if (bits
== sizeof (*value
) * 8)
21066 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21067 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21074 /* Read a constant value from an attribute. Either set *VALUE, or if
21075 the value does not fit in *VALUE, set *BYTES - either already
21076 allocated on the objfile obstack, or newly allocated on OBSTACK,
21077 or, set *BATON, if we translated the constant to a location
21081 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21082 const char *name
, struct obstack
*obstack
,
21083 struct dwarf2_cu
*cu
,
21084 LONGEST
*value
, const gdb_byte
**bytes
,
21085 struct dwarf2_locexpr_baton
**baton
)
21087 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21088 struct objfile
*objfile
= per_objfile
->objfile
;
21089 struct comp_unit_head
*cu_header
= &cu
->header
;
21090 struct dwarf_block
*blk
;
21091 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21092 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21098 switch (attr
->form
)
21101 case DW_FORM_addrx
:
21102 case DW_FORM_GNU_addr_index
:
21106 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21107 dwarf2_const_value_length_mismatch_complaint (name
,
21108 cu_header
->addr_size
,
21109 TYPE_LENGTH (type
));
21110 /* Symbols of this form are reasonably rare, so we just
21111 piggyback on the existing location code rather than writing
21112 a new implementation of symbol_computed_ops. */
21113 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21114 (*baton
)->per_objfile
= per_objfile
;
21115 (*baton
)->per_cu
= cu
->per_cu
;
21116 gdb_assert ((*baton
)->per_cu
);
21118 (*baton
)->size
= 2 + cu_header
->addr_size
;
21119 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21120 (*baton
)->data
= data
;
21122 data
[0] = DW_OP_addr
;
21123 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21124 byte_order
, DW_ADDR (attr
));
21125 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21128 case DW_FORM_string
:
21131 case DW_FORM_GNU_str_index
:
21132 case DW_FORM_GNU_strp_alt
:
21133 /* DW_STRING is already allocated on the objfile obstack, point
21135 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21137 case DW_FORM_block1
:
21138 case DW_FORM_block2
:
21139 case DW_FORM_block4
:
21140 case DW_FORM_block
:
21141 case DW_FORM_exprloc
:
21142 case DW_FORM_data16
:
21143 blk
= DW_BLOCK (attr
);
21144 if (TYPE_LENGTH (type
) != blk
->size
)
21145 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21146 TYPE_LENGTH (type
));
21147 *bytes
= blk
->data
;
21150 /* The DW_AT_const_value attributes are supposed to carry the
21151 symbol's value "represented as it would be on the target
21152 architecture." By the time we get here, it's already been
21153 converted to host endianness, so we just need to sign- or
21154 zero-extend it as appropriate. */
21155 case DW_FORM_data1
:
21156 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21158 case DW_FORM_data2
:
21159 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21161 case DW_FORM_data4
:
21162 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21164 case DW_FORM_data8
:
21165 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21168 case DW_FORM_sdata
:
21169 case DW_FORM_implicit_const
:
21170 *value
= DW_SND (attr
);
21173 case DW_FORM_udata
:
21174 *value
= DW_UNSND (attr
);
21178 complaint (_("unsupported const value attribute form: '%s'"),
21179 dwarf_form_name (attr
->form
));
21186 /* Copy constant value from an attribute to a symbol. */
21189 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21190 struct dwarf2_cu
*cu
)
21192 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21194 const gdb_byte
*bytes
;
21195 struct dwarf2_locexpr_baton
*baton
;
21197 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21198 sym
->print_name (),
21199 &objfile
->objfile_obstack
, cu
,
21200 &value
, &bytes
, &baton
);
21204 SYMBOL_LOCATION_BATON (sym
) = baton
;
21205 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21207 else if (bytes
!= NULL
)
21209 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21210 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21214 SYMBOL_VALUE (sym
) = value
;
21215 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21219 /* Return the type of the die in question using its DW_AT_type attribute. */
21221 static struct type
*
21222 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21224 struct attribute
*type_attr
;
21226 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21229 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21230 /* A missing DW_AT_type represents a void type. */
21231 return objfile_type (objfile
)->builtin_void
;
21234 return lookup_die_type (die
, type_attr
, cu
);
21237 /* True iff CU's producer generates GNAT Ada auxiliary information
21238 that allows to find parallel types through that information instead
21239 of having to do expensive parallel lookups by type name. */
21242 need_gnat_info (struct dwarf2_cu
*cu
)
21244 /* Assume that the Ada compiler was GNAT, which always produces
21245 the auxiliary information. */
21246 return (cu
->language
== language_ada
);
21249 /* Return the auxiliary type of the die in question using its
21250 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21251 attribute is not present. */
21253 static struct type
*
21254 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21256 struct attribute
*type_attr
;
21258 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21262 return lookup_die_type (die
, type_attr
, cu
);
21265 /* If DIE has a descriptive_type attribute, then set the TYPE's
21266 descriptive type accordingly. */
21269 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21270 struct dwarf2_cu
*cu
)
21272 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21274 if (descriptive_type
)
21276 ALLOCATE_GNAT_AUX_TYPE (type
);
21277 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21281 /* Return the containing type of the die in question using its
21282 DW_AT_containing_type attribute. */
21284 static struct type
*
21285 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21287 struct attribute
*type_attr
;
21288 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21290 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21292 error (_("Dwarf Error: Problem turning containing type into gdb type "
21293 "[in module %s]"), objfile_name (objfile
));
21295 return lookup_die_type (die
, type_attr
, cu
);
21298 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21300 static struct type
*
21301 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21303 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21304 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21307 std::string message
21308 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21309 objfile_name (objfile
),
21310 sect_offset_str (cu
->header
.sect_off
),
21311 sect_offset_str (die
->sect_off
));
21312 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21314 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21317 /* Look up the type of DIE in CU using its type attribute ATTR.
21318 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21319 DW_AT_containing_type.
21320 If there is no type substitute an error marker. */
21322 static struct type
*
21323 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21324 struct dwarf2_cu
*cu
)
21326 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21327 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21328 struct type
*this_type
;
21330 gdb_assert (attr
->name
== DW_AT_type
21331 || attr
->name
== DW_AT_GNAT_descriptive_type
21332 || attr
->name
== DW_AT_containing_type
);
21334 /* First see if we have it cached. */
21336 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21338 struct dwarf2_per_cu_data
*per_cu
;
21339 sect_offset sect_off
= attr
->get_ref_die_offset ();
21341 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21342 dwarf2_per_objfile
);
21343 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21345 else if (attr
->form_is_ref ())
21347 sect_offset sect_off
= attr
->get_ref_die_offset ();
21349 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21351 else if (attr
->form
== DW_FORM_ref_sig8
)
21353 ULONGEST signature
= DW_SIGNATURE (attr
);
21355 return get_signatured_type (die
, signature
, cu
);
21359 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21360 " at %s [in module %s]"),
21361 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21362 objfile_name (objfile
));
21363 return build_error_marker_type (cu
, die
);
21366 /* If not cached we need to read it in. */
21368 if (this_type
== NULL
)
21370 struct die_info
*type_die
= NULL
;
21371 struct dwarf2_cu
*type_cu
= cu
;
21373 if (attr
->form_is_ref ())
21374 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21375 if (type_die
== NULL
)
21376 return build_error_marker_type (cu
, die
);
21377 /* If we find the type now, it's probably because the type came
21378 from an inter-CU reference and the type's CU got expanded before
21380 this_type
= read_type_die (type_die
, type_cu
);
21383 /* If we still don't have a type use an error marker. */
21385 if (this_type
== NULL
)
21386 return build_error_marker_type (cu
, die
);
21391 /* Return the type in DIE, CU.
21392 Returns NULL for invalid types.
21394 This first does a lookup in die_type_hash,
21395 and only reads the die in if necessary.
21397 NOTE: This can be called when reading in partial or full symbols. */
21399 static struct type
*
21400 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21402 struct type
*this_type
;
21404 this_type
= get_die_type (die
, cu
);
21408 return read_type_die_1 (die
, cu
);
21411 /* Read the type in DIE, CU.
21412 Returns NULL for invalid types. */
21414 static struct type
*
21415 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21417 struct type
*this_type
= NULL
;
21421 case DW_TAG_class_type
:
21422 case DW_TAG_interface_type
:
21423 case DW_TAG_structure_type
:
21424 case DW_TAG_union_type
:
21425 this_type
= read_structure_type (die
, cu
);
21427 case DW_TAG_enumeration_type
:
21428 this_type
= read_enumeration_type (die
, cu
);
21430 case DW_TAG_subprogram
:
21431 case DW_TAG_subroutine_type
:
21432 case DW_TAG_inlined_subroutine
:
21433 this_type
= read_subroutine_type (die
, cu
);
21435 case DW_TAG_array_type
:
21436 this_type
= read_array_type (die
, cu
);
21438 case DW_TAG_set_type
:
21439 this_type
= read_set_type (die
, cu
);
21441 case DW_TAG_pointer_type
:
21442 this_type
= read_tag_pointer_type (die
, cu
);
21444 case DW_TAG_ptr_to_member_type
:
21445 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21447 case DW_TAG_reference_type
:
21448 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21450 case DW_TAG_rvalue_reference_type
:
21451 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21453 case DW_TAG_const_type
:
21454 this_type
= read_tag_const_type (die
, cu
);
21456 case DW_TAG_volatile_type
:
21457 this_type
= read_tag_volatile_type (die
, cu
);
21459 case DW_TAG_restrict_type
:
21460 this_type
= read_tag_restrict_type (die
, cu
);
21462 case DW_TAG_string_type
:
21463 this_type
= read_tag_string_type (die
, cu
);
21465 case DW_TAG_typedef
:
21466 this_type
= read_typedef (die
, cu
);
21468 case DW_TAG_subrange_type
:
21469 this_type
= read_subrange_type (die
, cu
);
21471 case DW_TAG_base_type
:
21472 this_type
= read_base_type (die
, cu
);
21474 case DW_TAG_unspecified_type
:
21475 this_type
= read_unspecified_type (die
, cu
);
21477 case DW_TAG_namespace
:
21478 this_type
= read_namespace_type (die
, cu
);
21480 case DW_TAG_module
:
21481 this_type
= read_module_type (die
, cu
);
21483 case DW_TAG_atomic_type
:
21484 this_type
= read_tag_atomic_type (die
, cu
);
21487 complaint (_("unexpected tag in read_type_die: '%s'"),
21488 dwarf_tag_name (die
->tag
));
21495 /* See if we can figure out if the class lives in a namespace. We do
21496 this by looking for a member function; its demangled name will
21497 contain namespace info, if there is any.
21498 Return the computed name or NULL.
21499 Space for the result is allocated on the objfile's obstack.
21500 This is the full-die version of guess_partial_die_structure_name.
21501 In this case we know DIE has no useful parent. */
21503 static const char *
21504 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21506 struct die_info
*spec_die
;
21507 struct dwarf2_cu
*spec_cu
;
21508 struct die_info
*child
;
21509 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21512 spec_die
= die_specification (die
, &spec_cu
);
21513 if (spec_die
!= NULL
)
21519 for (child
= die
->child
;
21521 child
= child
->sibling
)
21523 if (child
->tag
== DW_TAG_subprogram
)
21525 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21527 if (linkage_name
!= NULL
)
21529 gdb::unique_xmalloc_ptr
<char> actual_name
21530 (language_class_name_from_physname (cu
->language_defn
,
21532 const char *name
= NULL
;
21534 if (actual_name
!= NULL
)
21536 const char *die_name
= dwarf2_name (die
, cu
);
21538 if (die_name
!= NULL
21539 && strcmp (die_name
, actual_name
.get ()) != 0)
21541 /* Strip off the class name from the full name.
21542 We want the prefix. */
21543 int die_name_len
= strlen (die_name
);
21544 int actual_name_len
= strlen (actual_name
.get ());
21545 const char *ptr
= actual_name
.get ();
21547 /* Test for '::' as a sanity check. */
21548 if (actual_name_len
> die_name_len
+ 2
21549 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21550 name
= obstack_strndup (
21551 &objfile
->per_bfd
->storage_obstack
,
21552 ptr
, actual_name_len
- die_name_len
- 2);
21563 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21564 prefix part in such case. See
21565 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21567 static const char *
21568 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21570 struct attribute
*attr
;
21573 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21574 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21577 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21580 attr
= dw2_linkage_name_attr (die
, cu
);
21581 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21584 /* dwarf2_name had to be already called. */
21585 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21587 /* Strip the base name, keep any leading namespaces/classes. */
21588 base
= strrchr (DW_STRING (attr
), ':');
21589 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21592 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21593 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21595 &base
[-1] - DW_STRING (attr
));
21598 /* Return the name of the namespace/class that DIE is defined within,
21599 or "" if we can't tell. The caller should not xfree the result.
21601 For example, if we're within the method foo() in the following
21611 then determine_prefix on foo's die will return "N::C". */
21613 static const char *
21614 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21616 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21617 struct die_info
*parent
, *spec_die
;
21618 struct dwarf2_cu
*spec_cu
;
21619 struct type
*parent_type
;
21620 const char *retval
;
21622 if (cu
->language
!= language_cplus
21623 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21624 && cu
->language
!= language_rust
)
21627 retval
= anonymous_struct_prefix (die
, cu
);
21631 /* We have to be careful in the presence of DW_AT_specification.
21632 For example, with GCC 3.4, given the code
21636 // Definition of N::foo.
21640 then we'll have a tree of DIEs like this:
21642 1: DW_TAG_compile_unit
21643 2: DW_TAG_namespace // N
21644 3: DW_TAG_subprogram // declaration of N::foo
21645 4: DW_TAG_subprogram // definition of N::foo
21646 DW_AT_specification // refers to die #3
21648 Thus, when processing die #4, we have to pretend that we're in
21649 the context of its DW_AT_specification, namely the contex of die
21652 spec_die
= die_specification (die
, &spec_cu
);
21653 if (spec_die
== NULL
)
21654 parent
= die
->parent
;
21657 parent
= spec_die
->parent
;
21661 if (parent
== NULL
)
21663 else if (parent
->building_fullname
)
21666 const char *parent_name
;
21668 /* It has been seen on RealView 2.2 built binaries,
21669 DW_TAG_template_type_param types actually _defined_ as
21670 children of the parent class:
21673 template class <class Enum> Class{};
21674 Class<enum E> class_e;
21676 1: DW_TAG_class_type (Class)
21677 2: DW_TAG_enumeration_type (E)
21678 3: DW_TAG_enumerator (enum1:0)
21679 3: DW_TAG_enumerator (enum2:1)
21681 2: DW_TAG_template_type_param
21682 DW_AT_type DW_FORM_ref_udata (E)
21684 Besides being broken debug info, it can put GDB into an
21685 infinite loop. Consider:
21687 When we're building the full name for Class<E>, we'll start
21688 at Class, and go look over its template type parameters,
21689 finding E. We'll then try to build the full name of E, and
21690 reach here. We're now trying to build the full name of E,
21691 and look over the parent DIE for containing scope. In the
21692 broken case, if we followed the parent DIE of E, we'd again
21693 find Class, and once again go look at its template type
21694 arguments, etc., etc. Simply don't consider such parent die
21695 as source-level parent of this die (it can't be, the language
21696 doesn't allow it), and break the loop here. */
21697 name
= dwarf2_name (die
, cu
);
21698 parent_name
= dwarf2_name (parent
, cu
);
21699 complaint (_("template param type '%s' defined within parent '%s'"),
21700 name
? name
: "<unknown>",
21701 parent_name
? parent_name
: "<unknown>");
21705 switch (parent
->tag
)
21707 case DW_TAG_namespace
:
21708 parent_type
= read_type_die (parent
, cu
);
21709 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21710 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21711 Work around this problem here. */
21712 if (cu
->language
== language_cplus
21713 && strcmp (parent_type
->name (), "::") == 0)
21715 /* We give a name to even anonymous namespaces. */
21716 return parent_type
->name ();
21717 case DW_TAG_class_type
:
21718 case DW_TAG_interface_type
:
21719 case DW_TAG_structure_type
:
21720 case DW_TAG_union_type
:
21721 case DW_TAG_module
:
21722 parent_type
= read_type_die (parent
, cu
);
21723 if (parent_type
->name () != NULL
)
21724 return parent_type
->name ();
21726 /* An anonymous structure is only allowed non-static data
21727 members; no typedefs, no member functions, et cetera.
21728 So it does not need a prefix. */
21730 case DW_TAG_compile_unit
:
21731 case DW_TAG_partial_unit
:
21732 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21733 if (cu
->language
== language_cplus
21734 && !dwarf2_per_objfile
->per_bfd
->types
.empty ()
21735 && die
->child
!= NULL
21736 && (die
->tag
== DW_TAG_class_type
21737 || die
->tag
== DW_TAG_structure_type
21738 || die
->tag
== DW_TAG_union_type
))
21740 const char *name
= guess_full_die_structure_name (die
, cu
);
21745 case DW_TAG_subprogram
:
21746 /* Nested subroutines in Fortran get a prefix with the name
21747 of the parent's subroutine. */
21748 if (cu
->language
== language_fortran
)
21750 if ((die
->tag
== DW_TAG_subprogram
)
21751 && (dwarf2_name (parent
, cu
) != NULL
))
21752 return dwarf2_name (parent
, cu
);
21754 return determine_prefix (parent
, cu
);
21755 case DW_TAG_enumeration_type
:
21756 parent_type
= read_type_die (parent
, cu
);
21757 if (TYPE_DECLARED_CLASS (parent_type
))
21759 if (parent_type
->name () != NULL
)
21760 return parent_type
->name ();
21763 /* Fall through. */
21765 return determine_prefix (parent
, cu
);
21769 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21770 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21771 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21772 an obconcat, otherwise allocate storage for the result. The CU argument is
21773 used to determine the language and hence, the appropriate separator. */
21775 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21778 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21779 int physname
, struct dwarf2_cu
*cu
)
21781 const char *lead
= "";
21784 if (suffix
== NULL
|| suffix
[0] == '\0'
21785 || prefix
== NULL
|| prefix
[0] == '\0')
21787 else if (cu
->language
== language_d
)
21789 /* For D, the 'main' function could be defined in any module, but it
21790 should never be prefixed. */
21791 if (strcmp (suffix
, "D main") == 0)
21799 else if (cu
->language
== language_fortran
&& physname
)
21801 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21802 DW_AT_MIPS_linkage_name is preferred and used instead. */
21810 if (prefix
== NULL
)
21812 if (suffix
== NULL
)
21819 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21821 strcpy (retval
, lead
);
21822 strcat (retval
, prefix
);
21823 strcat (retval
, sep
);
21824 strcat (retval
, suffix
);
21829 /* We have an obstack. */
21830 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21834 /* Get name of a die, return NULL if not found. */
21836 static const char *
21837 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21838 struct objfile
*objfile
)
21840 if (name
&& cu
->language
== language_cplus
)
21842 gdb::unique_xmalloc_ptr
<char> canon_name
21843 = cp_canonicalize_string (name
);
21845 if (canon_name
!= nullptr)
21846 name
= objfile
->intern (canon_name
.get ());
21852 /* Get name of a die, return NULL if not found.
21853 Anonymous namespaces are converted to their magic string. */
21855 static const char *
21856 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21858 struct attribute
*attr
;
21859 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21861 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21862 if ((!attr
|| !DW_STRING (attr
))
21863 && die
->tag
!= DW_TAG_namespace
21864 && die
->tag
!= DW_TAG_class_type
21865 && die
->tag
!= DW_TAG_interface_type
21866 && die
->tag
!= DW_TAG_structure_type
21867 && die
->tag
!= DW_TAG_union_type
)
21872 case DW_TAG_compile_unit
:
21873 case DW_TAG_partial_unit
:
21874 /* Compilation units have a DW_AT_name that is a filename, not
21875 a source language identifier. */
21876 case DW_TAG_enumeration_type
:
21877 case DW_TAG_enumerator
:
21878 /* These tags always have simple identifiers already; no need
21879 to canonicalize them. */
21880 return DW_STRING (attr
);
21882 case DW_TAG_namespace
:
21883 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21884 return DW_STRING (attr
);
21885 return CP_ANONYMOUS_NAMESPACE_STR
;
21887 case DW_TAG_class_type
:
21888 case DW_TAG_interface_type
:
21889 case DW_TAG_structure_type
:
21890 case DW_TAG_union_type
:
21891 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21892 structures or unions. These were of the form "._%d" in GCC 4.1,
21893 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21894 and GCC 4.4. We work around this problem by ignoring these. */
21895 if (attr
&& DW_STRING (attr
)
21896 && (startswith (DW_STRING (attr
), "._")
21897 || startswith (DW_STRING (attr
), "<anonymous")))
21900 /* GCC might emit a nameless typedef that has a linkage name. See
21901 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21902 if (!attr
|| DW_STRING (attr
) == NULL
)
21904 attr
= dw2_linkage_name_attr (die
, cu
);
21905 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21908 /* Avoid demangling DW_STRING (attr) the second time on a second
21909 call for the same DIE. */
21910 if (!DW_STRING_IS_CANONICAL (attr
))
21912 gdb::unique_xmalloc_ptr
<char> demangled
21913 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21914 if (demangled
== nullptr)
21917 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21918 DW_STRING_IS_CANONICAL (attr
) = 1;
21921 /* Strip any leading namespaces/classes, keep only the base name.
21922 DW_AT_name for named DIEs does not contain the prefixes. */
21923 const char *base
= strrchr (DW_STRING (attr
), ':');
21924 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21927 return DW_STRING (attr
);
21935 if (!DW_STRING_IS_CANONICAL (attr
))
21937 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21939 DW_STRING_IS_CANONICAL (attr
) = 1;
21941 return DW_STRING (attr
);
21944 /* Return the die that this die in an extension of, or NULL if there
21945 is none. *EXT_CU is the CU containing DIE on input, and the CU
21946 containing the return value on output. */
21948 static struct die_info
*
21949 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21951 struct attribute
*attr
;
21953 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21957 return follow_die_ref (die
, attr
, ext_cu
);
21961 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21965 print_spaces (indent
, f
);
21966 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21967 dwarf_tag_name (die
->tag
), die
->abbrev
,
21968 sect_offset_str (die
->sect_off
));
21970 if (die
->parent
!= NULL
)
21972 print_spaces (indent
, f
);
21973 fprintf_unfiltered (f
, " parent at offset: %s\n",
21974 sect_offset_str (die
->parent
->sect_off
));
21977 print_spaces (indent
, f
);
21978 fprintf_unfiltered (f
, " has children: %s\n",
21979 dwarf_bool_name (die
->child
!= NULL
));
21981 print_spaces (indent
, f
);
21982 fprintf_unfiltered (f
, " attributes:\n");
21984 for (i
= 0; i
< die
->num_attrs
; ++i
)
21986 print_spaces (indent
, f
);
21987 fprintf_unfiltered (f
, " %s (%s) ",
21988 dwarf_attr_name (die
->attrs
[i
].name
),
21989 dwarf_form_name (die
->attrs
[i
].form
));
21991 switch (die
->attrs
[i
].form
)
21994 case DW_FORM_addrx
:
21995 case DW_FORM_GNU_addr_index
:
21996 fprintf_unfiltered (f
, "address: ");
21997 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21999 case DW_FORM_block2
:
22000 case DW_FORM_block4
:
22001 case DW_FORM_block
:
22002 case DW_FORM_block1
:
22003 fprintf_unfiltered (f
, "block: size %s",
22004 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22006 case DW_FORM_exprloc
:
22007 fprintf_unfiltered (f
, "expression: size %s",
22008 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22010 case DW_FORM_data16
:
22011 fprintf_unfiltered (f
, "constant of 16 bytes");
22013 case DW_FORM_ref_addr
:
22014 fprintf_unfiltered (f
, "ref address: ");
22015 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22017 case DW_FORM_GNU_ref_alt
:
22018 fprintf_unfiltered (f
, "alt ref address: ");
22019 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22025 case DW_FORM_ref_udata
:
22026 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22027 (long) (DW_UNSND (&die
->attrs
[i
])));
22029 case DW_FORM_data1
:
22030 case DW_FORM_data2
:
22031 case DW_FORM_data4
:
22032 case DW_FORM_data8
:
22033 case DW_FORM_udata
:
22034 case DW_FORM_sdata
:
22035 fprintf_unfiltered (f
, "constant: %s",
22036 pulongest (DW_UNSND (&die
->attrs
[i
])));
22038 case DW_FORM_sec_offset
:
22039 fprintf_unfiltered (f
, "section offset: %s",
22040 pulongest (DW_UNSND (&die
->attrs
[i
])));
22042 case DW_FORM_ref_sig8
:
22043 fprintf_unfiltered (f
, "signature: %s",
22044 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22046 case DW_FORM_string
:
22048 case DW_FORM_line_strp
:
22050 case DW_FORM_GNU_str_index
:
22051 case DW_FORM_GNU_strp_alt
:
22052 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22053 DW_STRING (&die
->attrs
[i
])
22054 ? DW_STRING (&die
->attrs
[i
]) : "",
22055 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22058 if (DW_UNSND (&die
->attrs
[i
]))
22059 fprintf_unfiltered (f
, "flag: TRUE");
22061 fprintf_unfiltered (f
, "flag: FALSE");
22063 case DW_FORM_flag_present
:
22064 fprintf_unfiltered (f
, "flag: TRUE");
22066 case DW_FORM_indirect
:
22067 /* The reader will have reduced the indirect form to
22068 the "base form" so this form should not occur. */
22069 fprintf_unfiltered (f
,
22070 "unexpected attribute form: DW_FORM_indirect");
22072 case DW_FORM_implicit_const
:
22073 fprintf_unfiltered (f
, "constant: %s",
22074 plongest (DW_SND (&die
->attrs
[i
])));
22077 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22078 die
->attrs
[i
].form
);
22081 fprintf_unfiltered (f
, "\n");
22086 dump_die_for_error (struct die_info
*die
)
22088 dump_die_shallow (gdb_stderr
, 0, die
);
22092 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22094 int indent
= level
* 4;
22096 gdb_assert (die
!= NULL
);
22098 if (level
>= max_level
)
22101 dump_die_shallow (f
, indent
, die
);
22103 if (die
->child
!= NULL
)
22105 print_spaces (indent
, f
);
22106 fprintf_unfiltered (f
, " Children:");
22107 if (level
+ 1 < max_level
)
22109 fprintf_unfiltered (f
, "\n");
22110 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22114 fprintf_unfiltered (f
,
22115 " [not printed, max nesting level reached]\n");
22119 if (die
->sibling
!= NULL
&& level
> 0)
22121 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22125 /* This is called from the pdie macro in gdbinit.in.
22126 It's not static so gcc will keep a copy callable from gdb. */
22129 dump_die (struct die_info
*die
, int max_level
)
22131 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22135 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22139 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22140 to_underlying (die
->sect_off
),
22146 /* Follow reference or signature attribute ATTR of SRC_DIE.
22147 On entry *REF_CU is the CU of SRC_DIE.
22148 On exit *REF_CU is the CU of the result. */
22150 static struct die_info
*
22151 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22152 struct dwarf2_cu
**ref_cu
)
22154 struct die_info
*die
;
22156 if (attr
->form_is_ref ())
22157 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22158 else if (attr
->form
== DW_FORM_ref_sig8
)
22159 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22162 dump_die_for_error (src_die
);
22163 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22164 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22170 /* Follow reference OFFSET.
22171 On entry *REF_CU is the CU of the source die referencing OFFSET.
22172 On exit *REF_CU is the CU of the result.
22173 Returns NULL if OFFSET is invalid. */
22175 static struct die_info
*
22176 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22177 struct dwarf2_cu
**ref_cu
)
22179 struct die_info temp_die
;
22180 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22181 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22183 gdb_assert (cu
->per_cu
!= NULL
);
22187 if (cu
->per_cu
->is_debug_types
)
22189 /* .debug_types CUs cannot reference anything outside their CU.
22190 If they need to, they have to reference a signatured type via
22191 DW_FORM_ref_sig8. */
22192 if (!cu
->header
.offset_in_cu_p (sect_off
))
22195 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22196 || !cu
->header
.offset_in_cu_p (sect_off
))
22198 struct dwarf2_per_cu_data
*per_cu
;
22200 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22201 dwarf2_per_objfile
);
22203 /* If necessary, add it to the queue and load its DIEs. */
22204 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22205 load_full_comp_unit (per_cu
, false, cu
->language
);
22207 target_cu
= per_cu
->cu
;
22209 else if (cu
->dies
== NULL
)
22211 /* We're loading full DIEs during partial symbol reading. */
22212 gdb_assert (dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
);
22213 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22216 *ref_cu
= target_cu
;
22217 temp_die
.sect_off
= sect_off
;
22219 if (target_cu
!= cu
)
22220 target_cu
->ancestor
= cu
;
22222 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22224 to_underlying (sect_off
));
22227 /* Follow reference attribute ATTR of SRC_DIE.
22228 On entry *REF_CU is the CU of SRC_DIE.
22229 On exit *REF_CU is the CU of the result. */
22231 static struct die_info
*
22232 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22233 struct dwarf2_cu
**ref_cu
)
22235 sect_offset sect_off
= attr
->get_ref_die_offset ();
22236 struct dwarf2_cu
*cu
= *ref_cu
;
22237 struct die_info
*die
;
22239 die
= follow_die_offset (sect_off
,
22240 (attr
->form
== DW_FORM_GNU_ref_alt
22241 || cu
->per_cu
->is_dwz
),
22244 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22245 "at %s [in module %s]"),
22246 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22247 objfile_name (cu
->per_objfile
->objfile
));
22254 struct dwarf2_locexpr_baton
22255 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22256 dwarf2_per_cu_data
*per_cu
,
22257 CORE_ADDR (*get_frame_pc
) (void *baton
),
22258 void *baton
, bool resolve_abstract_p
)
22260 struct dwarf2_cu
*cu
;
22261 struct die_info
*die
;
22262 struct attribute
*attr
;
22263 struct dwarf2_locexpr_baton retval
;
22264 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22265 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22267 if (per_cu
->cu
== NULL
)
22268 load_cu (per_cu
, false);
22272 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22273 Instead just throw an error, not much else we can do. */
22274 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22275 sect_offset_str (sect_off
), objfile_name (objfile
));
22278 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22280 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22281 sect_offset_str (sect_off
), objfile_name (objfile
));
22283 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22284 if (!attr
&& resolve_abstract_p
22285 && (dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22286 != dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22288 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22289 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22290 struct gdbarch
*gdbarch
= objfile
->arch ();
22292 for (const auto &cand_off
22293 : dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22295 struct dwarf2_cu
*cand_cu
= cu
;
22296 struct die_info
*cand
22297 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22300 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22303 CORE_ADDR pc_low
, pc_high
;
22304 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22305 if (pc_low
== ((CORE_ADDR
) -1))
22307 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22308 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22309 if (!(pc_low
<= pc
&& pc
< pc_high
))
22313 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22320 /* DWARF: "If there is no such attribute, then there is no effect.".
22321 DATA is ignored if SIZE is 0. */
22323 retval
.data
= NULL
;
22326 else if (attr
->form_is_section_offset ())
22328 struct dwarf2_loclist_baton loclist_baton
;
22329 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22332 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22334 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22336 retval
.size
= size
;
22340 if (!attr
->form_is_block ())
22341 error (_("Dwarf Error: DIE at %s referenced in module %s "
22342 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22343 sect_offset_str (sect_off
), objfile_name (objfile
));
22345 retval
.data
= DW_BLOCK (attr
)->data
;
22346 retval
.size
= DW_BLOCK (attr
)->size
;
22348 retval
.per_objfile
= dwarf2_per_objfile
;
22349 retval
.per_cu
= cu
->per_cu
;
22351 age_cached_comp_units (dwarf2_per_objfile
);
22358 struct dwarf2_locexpr_baton
22359 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22360 dwarf2_per_cu_data
*per_cu
,
22361 CORE_ADDR (*get_frame_pc
) (void *baton
),
22364 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22366 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22369 /* Write a constant of a given type as target-ordered bytes into
22372 static const gdb_byte
*
22373 write_constant_as_bytes (struct obstack
*obstack
,
22374 enum bfd_endian byte_order
,
22381 *len
= TYPE_LENGTH (type
);
22382 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22383 store_unsigned_integer (result
, *len
, byte_order
, value
);
22391 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22392 dwarf2_per_cu_data
*per_cu
,
22396 struct dwarf2_cu
*cu
;
22397 struct die_info
*die
;
22398 struct attribute
*attr
;
22399 const gdb_byte
*result
= NULL
;
22402 enum bfd_endian byte_order
;
22403 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22405 if (per_cu
->cu
== NULL
)
22406 load_cu (per_cu
, false);
22410 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22411 Instead just throw an error, not much else we can do. */
22412 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22413 sect_offset_str (sect_off
), objfile_name (objfile
));
22416 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22418 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22419 sect_offset_str (sect_off
), objfile_name (objfile
));
22421 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22425 byte_order
= (bfd_big_endian (objfile
->obfd
)
22426 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22428 switch (attr
->form
)
22431 case DW_FORM_addrx
:
22432 case DW_FORM_GNU_addr_index
:
22436 *len
= cu
->header
.addr_size
;
22437 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22438 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22442 case DW_FORM_string
:
22445 case DW_FORM_GNU_str_index
:
22446 case DW_FORM_GNU_strp_alt
:
22447 /* DW_STRING is already allocated on the objfile obstack, point
22449 result
= (const gdb_byte
*) DW_STRING (attr
);
22450 *len
= strlen (DW_STRING (attr
));
22452 case DW_FORM_block1
:
22453 case DW_FORM_block2
:
22454 case DW_FORM_block4
:
22455 case DW_FORM_block
:
22456 case DW_FORM_exprloc
:
22457 case DW_FORM_data16
:
22458 result
= DW_BLOCK (attr
)->data
;
22459 *len
= DW_BLOCK (attr
)->size
;
22462 /* The DW_AT_const_value attributes are supposed to carry the
22463 symbol's value "represented as it would be on the target
22464 architecture." By the time we get here, it's already been
22465 converted to host endianness, so we just need to sign- or
22466 zero-extend it as appropriate. */
22467 case DW_FORM_data1
:
22468 type
= die_type (die
, cu
);
22469 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22470 if (result
== NULL
)
22471 result
= write_constant_as_bytes (obstack
, byte_order
,
22474 case DW_FORM_data2
:
22475 type
= die_type (die
, cu
);
22476 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22477 if (result
== NULL
)
22478 result
= write_constant_as_bytes (obstack
, byte_order
,
22481 case DW_FORM_data4
:
22482 type
= die_type (die
, cu
);
22483 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22484 if (result
== NULL
)
22485 result
= write_constant_as_bytes (obstack
, byte_order
,
22488 case DW_FORM_data8
:
22489 type
= die_type (die
, cu
);
22490 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22491 if (result
== NULL
)
22492 result
= write_constant_as_bytes (obstack
, byte_order
,
22496 case DW_FORM_sdata
:
22497 case DW_FORM_implicit_const
:
22498 type
= die_type (die
, cu
);
22499 result
= write_constant_as_bytes (obstack
, byte_order
,
22500 type
, DW_SND (attr
), len
);
22503 case DW_FORM_udata
:
22504 type
= die_type (die
, cu
);
22505 result
= write_constant_as_bytes (obstack
, byte_order
,
22506 type
, DW_UNSND (attr
), len
);
22510 complaint (_("unsupported const value attribute form: '%s'"),
22511 dwarf_form_name (attr
->form
));
22521 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22522 dwarf2_per_cu_data
*per_cu
)
22524 struct dwarf2_cu
*cu
;
22525 struct die_info
*die
;
22527 if (per_cu
->cu
== NULL
)
22528 load_cu (per_cu
, false);
22533 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22537 return die_type (die
, cu
);
22543 dwarf2_get_die_type (cu_offset die_offset
,
22544 struct dwarf2_per_cu_data
*per_cu
)
22546 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22547 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22550 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22551 On entry *REF_CU is the CU of SRC_DIE.
22552 On exit *REF_CU is the CU of the result.
22553 Returns NULL if the referenced DIE isn't found. */
22555 static struct die_info
*
22556 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22557 struct dwarf2_cu
**ref_cu
)
22559 struct die_info temp_die
;
22560 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22561 struct die_info
*die
;
22563 /* While it might be nice to assert sig_type->type == NULL here,
22564 we can get here for DW_AT_imported_declaration where we need
22565 the DIE not the type. */
22567 /* If necessary, add it to the queue and load its DIEs. */
22569 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22570 read_signatured_type (sig_type
);
22572 sig_cu
= sig_type
->per_cu
.cu
;
22573 gdb_assert (sig_cu
!= NULL
);
22574 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22575 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22576 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22577 to_underlying (temp_die
.sect_off
));
22580 struct dwarf2_per_objfile
*dwarf2_per_objfile
= (*ref_cu
)->per_objfile
;
22582 /* For .gdb_index version 7 keep track of included TUs.
22583 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22584 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
22585 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7)
22587 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22592 sig_cu
->ancestor
= cu
;
22600 /* Follow signatured type referenced by ATTR in SRC_DIE.
22601 On entry *REF_CU is the CU of SRC_DIE.
22602 On exit *REF_CU is the CU of the result.
22603 The result is the DIE of the type.
22604 If the referenced type cannot be found an error is thrown. */
22606 static struct die_info
*
22607 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22608 struct dwarf2_cu
**ref_cu
)
22610 ULONGEST signature
= DW_SIGNATURE (attr
);
22611 struct signatured_type
*sig_type
;
22612 struct die_info
*die
;
22614 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22616 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22617 /* sig_type will be NULL if the signatured type is missing from
22619 if (sig_type
== NULL
)
22621 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22622 " from DIE at %s [in module %s]"),
22623 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22624 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22627 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22630 dump_die_for_error (src_die
);
22631 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22632 " from DIE at %s [in module %s]"),
22633 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22634 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22640 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22641 reading in and processing the type unit if necessary. */
22643 static struct type
*
22644 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22645 struct dwarf2_cu
*cu
)
22647 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22648 struct signatured_type
*sig_type
;
22649 struct dwarf2_cu
*type_cu
;
22650 struct die_info
*type_die
;
22653 sig_type
= lookup_signatured_type (cu
, signature
);
22654 /* sig_type will be NULL if the signatured type is missing from
22656 if (sig_type
== NULL
)
22658 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22659 " from DIE at %s [in module %s]"),
22660 hex_string (signature
), sect_offset_str (die
->sect_off
),
22661 objfile_name (dwarf2_per_objfile
->objfile
));
22662 return build_error_marker_type (cu
, die
);
22665 /* If we already know the type we're done. */
22666 if (sig_type
->type
!= NULL
)
22667 return sig_type
->type
;
22670 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22671 if (type_die
!= NULL
)
22673 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22674 is created. This is important, for example, because for c++ classes
22675 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22676 type
= read_type_die (type_die
, type_cu
);
22679 complaint (_("Dwarf Error: Cannot build signatured type %s"
22680 " referenced from DIE at %s [in module %s]"),
22681 hex_string (signature
), sect_offset_str (die
->sect_off
),
22682 objfile_name (dwarf2_per_objfile
->objfile
));
22683 type
= build_error_marker_type (cu
, die
);
22688 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22689 " from DIE at %s [in module %s]"),
22690 hex_string (signature
), sect_offset_str (die
->sect_off
),
22691 objfile_name (dwarf2_per_objfile
->objfile
));
22692 type
= build_error_marker_type (cu
, die
);
22694 sig_type
->type
= type
;
22699 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22700 reading in and processing the type unit if necessary. */
22702 static struct type
*
22703 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22704 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22706 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22707 if (attr
->form_is_ref ())
22709 struct dwarf2_cu
*type_cu
= cu
;
22710 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22712 return read_type_die (type_die
, type_cu
);
22714 else if (attr
->form
== DW_FORM_ref_sig8
)
22716 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22720 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22722 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22723 " at %s [in module %s]"),
22724 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22725 objfile_name (dwarf2_per_objfile
->objfile
));
22726 return build_error_marker_type (cu
, die
);
22730 /* Load the DIEs associated with type unit PER_CU into memory. */
22733 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22735 struct signatured_type
*sig_type
;
22737 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22738 gdb_assert (! per_cu
->type_unit_group_p ());
22740 /* We have the per_cu, but we need the signatured_type.
22741 Fortunately this is an easy translation. */
22742 gdb_assert (per_cu
->is_debug_types
);
22743 sig_type
= (struct signatured_type
*) per_cu
;
22745 gdb_assert (per_cu
->cu
== NULL
);
22747 read_signatured_type (sig_type
);
22749 gdb_assert (per_cu
->cu
!= NULL
);
22752 /* Read in a signatured type and build its CU and DIEs.
22753 If the type is a stub for the real type in a DWO file,
22754 read in the real type from the DWO file as well. */
22757 read_signatured_type (struct signatured_type
*sig_type
)
22759 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22761 gdb_assert (per_cu
->is_debug_types
);
22762 gdb_assert (per_cu
->cu
== NULL
);
22764 cutu_reader
reader (per_cu
, NULL
, 0, false);
22766 if (!reader
.dummy_p
)
22768 struct dwarf2_cu
*cu
= reader
.cu
;
22769 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22771 gdb_assert (cu
->die_hash
== NULL
);
22773 htab_create_alloc_ex (cu
->header
.length
/ 12,
22777 &cu
->comp_unit_obstack
,
22778 hashtab_obstack_allocate
,
22779 dummy_obstack_deallocate
);
22781 if (reader
.comp_unit_die
->has_children
)
22782 reader
.comp_unit_die
->child
22783 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22784 reader
.comp_unit_die
);
22785 cu
->dies
= reader
.comp_unit_die
;
22786 /* comp_unit_die is not stored in die_hash, no need. */
22788 /* We try not to read any attributes in this function, because
22789 not all CUs needed for references have been loaded yet, and
22790 symbol table processing isn't initialized. But we have to
22791 set the CU language, or we won't be able to build types
22792 correctly. Similarly, if we do not read the producer, we can
22793 not apply producer-specific interpretation. */
22794 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22799 sig_type
->per_cu
.tu_read
= 1;
22802 /* Decode simple location descriptions.
22803 Given a pointer to a dwarf block that defines a location, compute
22804 the location and return the value. If COMPUTED is non-null, it is
22805 set to true to indicate that decoding was successful, and false
22806 otherwise. If COMPUTED is null, then this function may emit a
22810 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22812 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22814 size_t size
= blk
->size
;
22815 const gdb_byte
*data
= blk
->data
;
22816 CORE_ADDR stack
[64];
22818 unsigned int bytes_read
, unsnd
;
22821 if (computed
!= nullptr)
22827 stack
[++stacki
] = 0;
22866 stack
[++stacki
] = op
- DW_OP_lit0
;
22901 stack
[++stacki
] = op
- DW_OP_reg0
;
22904 if (computed
== nullptr)
22905 dwarf2_complex_location_expr_complaint ();
22912 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22914 stack
[++stacki
] = unsnd
;
22917 if (computed
== nullptr)
22918 dwarf2_complex_location_expr_complaint ();
22925 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22930 case DW_OP_const1u
:
22931 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22935 case DW_OP_const1s
:
22936 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22940 case DW_OP_const2u
:
22941 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22945 case DW_OP_const2s
:
22946 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22950 case DW_OP_const4u
:
22951 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22955 case DW_OP_const4s
:
22956 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22960 case DW_OP_const8u
:
22961 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22966 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22972 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22977 stack
[stacki
+ 1] = stack
[stacki
];
22982 stack
[stacki
- 1] += stack
[stacki
];
22986 case DW_OP_plus_uconst
:
22987 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22993 stack
[stacki
- 1] -= stack
[stacki
];
22998 /* If we're not the last op, then we definitely can't encode
22999 this using GDB's address_class enum. This is valid for partial
23000 global symbols, although the variable's address will be bogus
23004 if (computed
== nullptr)
23005 dwarf2_complex_location_expr_complaint ();
23011 case DW_OP_GNU_push_tls_address
:
23012 case DW_OP_form_tls_address
:
23013 /* The top of the stack has the offset from the beginning
23014 of the thread control block at which the variable is located. */
23015 /* Nothing should follow this operator, so the top of stack would
23017 /* This is valid for partial global symbols, but the variable's
23018 address will be bogus in the psymtab. Make it always at least
23019 non-zero to not look as a variable garbage collected by linker
23020 which have DW_OP_addr 0. */
23023 if (computed
== nullptr)
23024 dwarf2_complex_location_expr_complaint ();
23031 case DW_OP_GNU_uninit
:
23032 if (computed
!= nullptr)
23037 case DW_OP_GNU_addr_index
:
23038 case DW_OP_GNU_const_index
:
23039 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23045 if (computed
== nullptr)
23047 const char *name
= get_DW_OP_name (op
);
23050 complaint (_("unsupported stack op: '%s'"),
23053 complaint (_("unsupported stack op: '%02x'"),
23057 return (stack
[stacki
]);
23060 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23061 outside of the allocated space. Also enforce minimum>0. */
23062 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23064 if (computed
== nullptr)
23065 complaint (_("location description stack overflow"));
23071 if (computed
== nullptr)
23072 complaint (_("location description stack underflow"));
23077 if (computed
!= nullptr)
23079 return (stack
[stacki
]);
23082 /* memory allocation interface */
23084 static struct dwarf_block
*
23085 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23087 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23090 static struct die_info
*
23091 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23093 struct die_info
*die
;
23094 size_t size
= sizeof (struct die_info
);
23097 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23099 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23100 memset (die
, 0, sizeof (struct die_info
));
23106 /* Macro support. */
23108 /* An overload of dwarf_decode_macros that finds the correct section
23109 and ensures it is read in before calling the other overload. */
23112 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23113 int section_is_gnu
)
23115 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23116 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23117 const struct line_header
*lh
= cu
->line_header
;
23118 unsigned int offset_size
= cu
->header
.offset_size
;
23119 struct dwarf2_section_info
*section
;
23120 const char *section_name
;
23122 if (cu
->dwo_unit
!= nullptr)
23124 if (section_is_gnu
)
23126 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23127 section_name
= ".debug_macro.dwo";
23131 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23132 section_name
= ".debug_macinfo.dwo";
23137 if (section_is_gnu
)
23139 section
= &dwarf2_per_objfile
->per_bfd
->macro
;
23140 section_name
= ".debug_macro";
23144 section
= &dwarf2_per_objfile
->per_bfd
->macinfo
;
23145 section_name
= ".debug_macinfo";
23149 section
->read (objfile
);
23150 if (section
->buffer
== nullptr)
23152 complaint (_("missing %s section"), section_name
);
23156 buildsym_compunit
*builder
= cu
->get_builder ();
23158 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23159 offset_size
, offset
, section_is_gnu
);
23162 /* Return the .debug_loc section to use for CU.
23163 For DWO files use .debug_loc.dwo. */
23165 static struct dwarf2_section_info
*
23166 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23168 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23172 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23174 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23176 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->per_bfd
->loclists
23177 : &dwarf2_per_objfile
->per_bfd
->loc
);
23180 /* A helper function that fills in a dwarf2_loclist_baton. */
23183 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23184 struct dwarf2_loclist_baton
*baton
,
23185 const struct attribute
*attr
)
23187 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23188 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23190 section
->read (dwarf2_per_objfile
->objfile
);
23192 baton
->per_objfile
= dwarf2_per_objfile
;
23193 baton
->per_cu
= cu
->per_cu
;
23194 gdb_assert (baton
->per_cu
);
23195 /* We don't know how long the location list is, but make sure we
23196 don't run off the edge of the section. */
23197 baton
->size
= section
->size
- DW_UNSND (attr
);
23198 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23199 if (cu
->base_address
.has_value ())
23200 baton
->base_address
= *cu
->base_address
;
23202 baton
->base_address
= 0;
23203 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23207 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23208 struct dwarf2_cu
*cu
, int is_block
)
23210 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23211 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23212 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23214 if (attr
->form_is_section_offset ()
23215 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23216 the section. If so, fall through to the complaint in the
23218 && DW_UNSND (attr
) < section
->get_size (objfile
))
23220 struct dwarf2_loclist_baton
*baton
;
23222 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23224 fill_in_loclist_baton (cu
, baton
, attr
);
23226 if (!cu
->base_address
.has_value ())
23227 complaint (_("Location list used without "
23228 "specifying the CU base address."));
23230 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23231 ? dwarf2_loclist_block_index
23232 : dwarf2_loclist_index
);
23233 SYMBOL_LOCATION_BATON (sym
) = baton
;
23237 struct dwarf2_locexpr_baton
*baton
;
23239 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23240 baton
->per_objfile
= dwarf2_per_objfile
;
23241 baton
->per_cu
= cu
->per_cu
;
23242 gdb_assert (baton
->per_cu
);
23244 if (attr
->form_is_block ())
23246 /* Note that we're just copying the block's data pointer
23247 here, not the actual data. We're still pointing into the
23248 info_buffer for SYM's objfile; right now we never release
23249 that buffer, but when we do clean up properly this may
23251 baton
->size
= DW_BLOCK (attr
)->size
;
23252 baton
->data
= DW_BLOCK (attr
)->data
;
23256 dwarf2_invalid_attrib_class_complaint ("location description",
23257 sym
->natural_name ());
23261 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23262 ? dwarf2_locexpr_block_index
23263 : dwarf2_locexpr_index
);
23264 SYMBOL_LOCATION_BATON (sym
) = baton
;
23271 dwarf2_per_cu_data::objfile () const
23273 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23275 /* Return the master objfile, so that we can report and look up the
23276 correct file containing this variable. */
23277 if (objfile
->separate_debug_objfile_backlink
)
23278 objfile
= objfile
->separate_debug_objfile_backlink
;
23283 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
23284 (CU_HEADERP is unused in such case) or prepare a temporary copy at
23285 CU_HEADERP first. */
23287 static const struct comp_unit_head
*
23288 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
23289 const struct dwarf2_per_cu_data
*per_cu
)
23291 const gdb_byte
*info_ptr
;
23294 return &per_cu
->cu
->header
;
23296 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
23298 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
23299 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
23300 rcuh_kind::COMPILE
);
23308 dwarf2_per_cu_data::addr_size () const
23310 struct comp_unit_head cu_header_local
;
23311 const struct comp_unit_head
*cu_headerp
;
23313 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23315 return cu_headerp
->addr_size
;
23321 dwarf2_per_cu_data::offset_size () const
23323 struct comp_unit_head cu_header_local
;
23324 const struct comp_unit_head
*cu_headerp
;
23326 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23328 return cu_headerp
->offset_size
;
23334 dwarf2_per_cu_data::ref_addr_size () const
23336 struct comp_unit_head cu_header_local
;
23337 const struct comp_unit_head
*cu_headerp
;
23339 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23341 if (cu_headerp
->version
== 2)
23342 return cu_headerp
->addr_size
;
23344 return cu_headerp
->offset_size
;
23350 dwarf2_per_cu_data::text_offset () const
23352 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23354 return objfile
->text_section_offset ();
23360 dwarf2_per_cu_data::addr_type () const
23362 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23363 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23364 struct type
*addr_type
= lookup_pointer_type (void_type
);
23365 int addr_size
= this->addr_size ();
23367 if (TYPE_LENGTH (addr_type
) == addr_size
)
23370 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23374 /* A helper function for dwarf2_find_containing_comp_unit that returns
23375 the index of the result, and that searches a vector. It will
23376 return a result even if the offset in question does not actually
23377 occur in any CU. This is separate so that it can be unit
23381 dwarf2_find_containing_comp_unit
23382 (sect_offset sect_off
,
23383 unsigned int offset_in_dwz
,
23384 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23389 high
= all_comp_units
.size () - 1;
23392 struct dwarf2_per_cu_data
*mid_cu
;
23393 int mid
= low
+ (high
- low
) / 2;
23395 mid_cu
= all_comp_units
[mid
];
23396 if (mid_cu
->is_dwz
> offset_in_dwz
23397 || (mid_cu
->is_dwz
== offset_in_dwz
23398 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23403 gdb_assert (low
== high
);
23407 /* Locate the .debug_info compilation unit from CU's objfile which contains
23408 the DIE at OFFSET. Raises an error on failure. */
23410 static struct dwarf2_per_cu_data
*
23411 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23412 unsigned int offset_in_dwz
,
23413 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23416 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23417 dwarf2_per_objfile
->per_bfd
->all_comp_units
);
23418 struct dwarf2_per_cu_data
*this_cu
23419 = dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
];
23421 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23423 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23424 error (_("Dwarf Error: could not find partial DIE containing "
23425 "offset %s [in module %s]"),
23426 sect_offset_str (sect_off
),
23427 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23429 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23431 return dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1];
23435 if (low
== dwarf2_per_objfile
->per_bfd
->all_comp_units
.size () - 1
23436 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23437 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23438 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23445 namespace selftests
{
23446 namespace find_containing_comp_unit
{
23451 struct dwarf2_per_cu_data one
{};
23452 struct dwarf2_per_cu_data two
{};
23453 struct dwarf2_per_cu_data three
{};
23454 struct dwarf2_per_cu_data four
{};
23457 two
.sect_off
= sect_offset (one
.length
);
23462 four
.sect_off
= sect_offset (three
.length
);
23466 std::vector
<dwarf2_per_cu_data
*> units
;
23467 units
.push_back (&one
);
23468 units
.push_back (&two
);
23469 units
.push_back (&three
);
23470 units
.push_back (&four
);
23474 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23475 SELF_CHECK (units
[result
] == &one
);
23476 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23477 SELF_CHECK (units
[result
] == &one
);
23478 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23479 SELF_CHECK (units
[result
] == &two
);
23481 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23482 SELF_CHECK (units
[result
] == &three
);
23483 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23484 SELF_CHECK (units
[result
] == &three
);
23485 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23486 SELF_CHECK (units
[result
] == &four
);
23492 #endif /* GDB_SELF_TEST */
23494 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23496 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23497 dwarf2_per_objfile
*per_objfile
)
23499 per_objfile (per_objfile
),
23501 has_loclist (false),
23502 checked_producer (false),
23503 producer_is_gxx_lt_4_6 (false),
23504 producer_is_gcc_lt_4_3 (false),
23505 producer_is_icc (false),
23506 producer_is_icc_lt_14 (false),
23507 producer_is_codewarrior (false),
23508 processing_has_namespace_info (false)
23513 /* Destroy a dwarf2_cu. */
23515 dwarf2_cu::~dwarf2_cu ()
23520 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23523 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23524 enum language pretend_language
)
23526 struct attribute
*attr
;
23528 /* Set the language we're debugging. */
23529 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23530 if (attr
!= nullptr)
23531 set_cu_language (DW_UNSND (attr
), cu
);
23534 cu
->language
= pretend_language
;
23535 cu
->language_defn
= language_def (cu
->language
);
23538 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23541 /* Increase the age counter on each cached compilation unit, and free
23542 any that are too old. */
23545 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23547 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23549 dwarf2_clear_marks (dwarf2_per_objfile
->per_bfd
->read_in_chain
);
23550 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23551 while (per_cu
!= NULL
)
23553 per_cu
->cu
->last_used
++;
23554 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23555 dwarf2_mark (per_cu
->cu
);
23556 per_cu
= per_cu
->cu
->read_in_chain
;
23559 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23560 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23561 while (per_cu
!= NULL
)
23563 struct dwarf2_per_cu_data
*next_cu
;
23565 next_cu
= per_cu
->cu
->read_in_chain
;
23567 if (!per_cu
->cu
->mark
)
23570 *last_chain
= next_cu
;
23573 last_chain
= &per_cu
->cu
->read_in_chain
;
23579 /* Remove a single compilation unit from the cache. */
23582 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23584 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23585 struct dwarf2_per_objfile
*dwarf2_per_objfile
23586 = target_per_cu
->dwarf2_per_objfile
;
23588 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23589 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23590 while (per_cu
!= NULL
)
23592 struct dwarf2_per_cu_data
*next_cu
;
23594 next_cu
= per_cu
->cu
->read_in_chain
;
23596 if (per_cu
== target_per_cu
)
23600 *last_chain
= next_cu
;
23604 last_chain
= &per_cu
->cu
->read_in_chain
;
23610 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23611 We store these in a hash table separate from the DIEs, and preserve them
23612 when the DIEs are flushed out of cache.
23614 The CU "per_cu" pointer is needed because offset alone is not enough to
23615 uniquely identify the type. A file may have multiple .debug_types sections,
23616 or the type may come from a DWO file. Furthermore, while it's more logical
23617 to use per_cu->section+offset, with Fission the section with the data is in
23618 the DWO file but we don't know that section at the point we need it.
23619 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23620 because we can enter the lookup routine, get_die_type_at_offset, from
23621 outside this file, and thus won't necessarily have PER_CU->cu.
23622 Fortunately, PER_CU is stable for the life of the objfile. */
23624 struct dwarf2_per_cu_offset_and_type
23626 const struct dwarf2_per_cu_data
*per_cu
;
23627 sect_offset sect_off
;
23631 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23634 per_cu_offset_and_type_hash (const void *item
)
23636 const struct dwarf2_per_cu_offset_and_type
*ofs
23637 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23639 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23642 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23645 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23647 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23648 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23649 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23650 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23652 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23653 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23656 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23657 table if necessary. For convenience, return TYPE.
23659 The DIEs reading must have careful ordering to:
23660 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23661 reading current DIE.
23662 * Not trying to dereference contents of still incompletely read in types
23663 while reading in other DIEs.
23664 * Enable referencing still incompletely read in types just by a pointer to
23665 the type without accessing its fields.
23667 Therefore caller should follow these rules:
23668 * Try to fetch any prerequisite types we may need to build this DIE type
23669 before building the type and calling set_die_type.
23670 * After building type call set_die_type for current DIE as soon as
23671 possible before fetching more types to complete the current type.
23672 * Make the type as complete as possible before fetching more types. */
23674 static struct type
*
23675 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23677 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23678 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23679 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23680 struct attribute
*attr
;
23681 struct dynamic_prop prop
;
23683 /* For Ada types, make sure that the gnat-specific data is always
23684 initialized (if not already set). There are a few types where
23685 we should not be doing so, because the type-specific area is
23686 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23687 where the type-specific area is used to store the floatformat).
23688 But this is not a problem, because the gnat-specific information
23689 is actually not needed for these types. */
23690 if (need_gnat_info (cu
)
23691 && type
->code () != TYPE_CODE_FUNC
23692 && type
->code () != TYPE_CODE_FLT
23693 && type
->code () != TYPE_CODE_METHODPTR
23694 && type
->code () != TYPE_CODE_MEMBERPTR
23695 && type
->code () != TYPE_CODE_METHOD
23696 && !HAVE_GNAT_AUX_INFO (type
))
23697 INIT_GNAT_SPECIFIC (type
);
23699 /* Read DW_AT_allocated and set in type. */
23700 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23701 if (attr
!= NULL
&& attr
->form_is_block ())
23703 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23704 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23705 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23707 else if (attr
!= NULL
)
23709 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23710 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23711 sect_offset_str (die
->sect_off
));
23714 /* Read DW_AT_associated and set in type. */
23715 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23716 if (attr
!= NULL
&& attr
->form_is_block ())
23718 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23719 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23720 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23722 else if (attr
!= NULL
)
23724 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23725 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23726 sect_offset_str (die
->sect_off
));
23729 /* Read DW_AT_data_location and set in type. */
23730 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23731 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23732 cu
->per_cu
->addr_type ()))
23733 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23735 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23736 dwarf2_per_objfile
->die_type_hash
23737 = htab_up (htab_create_alloc (127,
23738 per_cu_offset_and_type_hash
,
23739 per_cu_offset_and_type_eq
,
23740 NULL
, xcalloc
, xfree
));
23742 ofs
.per_cu
= cu
->per_cu
;
23743 ofs
.sect_off
= die
->sect_off
;
23745 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23746 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23748 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23749 sect_offset_str (die
->sect_off
));
23750 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23751 struct dwarf2_per_cu_offset_and_type
);
23756 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23757 or return NULL if the die does not have a saved type. */
23759 static struct type
*
23760 get_die_type_at_offset (sect_offset sect_off
,
23761 struct dwarf2_per_cu_data
*per_cu
)
23763 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23764 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23766 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23769 ofs
.per_cu
= per_cu
;
23770 ofs
.sect_off
= sect_off
;
23771 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23772 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23779 /* Look up the type for DIE in CU in die_type_hash,
23780 or return NULL if DIE does not have a saved type. */
23782 static struct type
*
23783 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23785 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23788 /* Add a dependence relationship from CU to REF_PER_CU. */
23791 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23792 struct dwarf2_per_cu_data
*ref_per_cu
)
23796 if (cu
->dependencies
== NULL
)
23798 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23799 NULL
, &cu
->comp_unit_obstack
,
23800 hashtab_obstack_allocate
,
23801 dummy_obstack_deallocate
);
23803 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23805 *slot
= ref_per_cu
;
23808 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23809 Set the mark field in every compilation unit in the
23810 cache that we must keep because we are keeping CU. */
23813 dwarf2_mark_helper (void **slot
, void *data
)
23815 struct dwarf2_per_cu_data
*per_cu
;
23817 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23819 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23820 reading of the chain. As such dependencies remain valid it is not much
23821 useful to track and undo them during QUIT cleanups. */
23822 if (per_cu
->cu
== NULL
)
23825 if (per_cu
->cu
->mark
)
23827 per_cu
->cu
->mark
= true;
23829 if (per_cu
->cu
->dependencies
!= NULL
)
23830 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23835 /* Set the mark field in CU and in every other compilation unit in the
23836 cache that we must keep because we are keeping CU. */
23839 dwarf2_mark (struct dwarf2_cu
*cu
)
23844 if (cu
->dependencies
!= NULL
)
23845 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23849 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23853 per_cu
->cu
->mark
= false;
23854 per_cu
= per_cu
->cu
->read_in_chain
;
23858 /* Trivial hash function for partial_die_info: the hash value of a DIE
23859 is its offset in .debug_info for this objfile. */
23862 partial_die_hash (const void *item
)
23864 const struct partial_die_info
*part_die
23865 = (const struct partial_die_info
*) item
;
23867 return to_underlying (part_die
->sect_off
);
23870 /* Trivial comparison function for partial_die_info structures: two DIEs
23871 are equal if they have the same offset. */
23874 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23876 const struct partial_die_info
*part_die_lhs
23877 = (const struct partial_die_info
*) item_lhs
;
23878 const struct partial_die_info
*part_die_rhs
23879 = (const struct partial_die_info
*) item_rhs
;
23881 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23884 struct cmd_list_element
*set_dwarf_cmdlist
;
23885 struct cmd_list_element
*show_dwarf_cmdlist
;
23888 show_check_physname (struct ui_file
*file
, int from_tty
,
23889 struct cmd_list_element
*c
, const char *value
)
23891 fprintf_filtered (file
,
23892 _("Whether to check \"physname\" is %s.\n"),
23896 void _initialize_dwarf2_read ();
23898 _initialize_dwarf2_read ()
23900 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
23901 Set DWARF specific variables.\n\
23902 Configure DWARF variables such as the cache size."),
23903 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23904 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23906 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
23907 Show DWARF specific variables.\n\
23908 Show DWARF variables such as the cache size."),
23909 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23910 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23912 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23913 &dwarf_max_cache_age
, _("\
23914 Set the upper bound on the age of cached DWARF compilation units."), _("\
23915 Show the upper bound on the age of cached DWARF compilation units."), _("\
23916 A higher limit means that cached compilation units will be stored\n\
23917 in memory longer, and more total memory will be used. Zero disables\n\
23918 caching, which can slow down startup."),
23920 show_dwarf_max_cache_age
,
23921 &set_dwarf_cmdlist
,
23922 &show_dwarf_cmdlist
);
23924 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23925 Set debugging of the DWARF reader."), _("\
23926 Show debugging of the DWARF reader."), _("\
23927 When enabled (non-zero), debugging messages are printed during DWARF\n\
23928 reading and symtab expansion. A value of 1 (one) provides basic\n\
23929 information. A value greater than 1 provides more verbose information."),
23932 &setdebuglist
, &showdebuglist
);
23934 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23935 Set debugging of the DWARF DIE reader."), _("\
23936 Show debugging of the DWARF DIE reader."), _("\
23937 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23938 The value is the maximum depth to print."),
23941 &setdebuglist
, &showdebuglist
);
23943 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23944 Set debugging of the dwarf line reader."), _("\
23945 Show debugging of the dwarf line reader."), _("\
23946 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23947 A value of 1 (one) provides basic information.\n\
23948 A value greater than 1 provides more verbose information."),
23951 &setdebuglist
, &showdebuglist
);
23953 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23954 Set cross-checking of \"physname\" code against demangler."), _("\
23955 Show cross-checking of \"physname\" code against demangler."), _("\
23956 When enabled, GDB's internal \"physname\" code is checked against\n\
23958 NULL
, show_check_physname
,
23959 &setdebuglist
, &showdebuglist
);
23961 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23962 no_class
, &use_deprecated_index_sections
, _("\
23963 Set whether to use deprecated gdb_index sections."), _("\
23964 Show whether to use deprecated gdb_index sections."), _("\
23965 When enabled, deprecated .gdb_index sections are used anyway.\n\
23966 Normally they are ignored either because of a missing feature or\n\
23967 performance issue.\n\
23968 Warning: This option must be enabled before gdb reads the file."),
23971 &setlist
, &showlist
);
23973 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23974 &dwarf2_locexpr_funcs
);
23975 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23976 &dwarf2_loclist_funcs
);
23978 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23979 &dwarf2_block_frame_base_locexpr_funcs
);
23980 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23981 &dwarf2_block_frame_base_loclist_funcs
);
23984 selftests::register_test ("dw2_expand_symtabs_matching",
23985 selftests::dw2_expand_symtabs_matching::run_test
);
23986 selftests::register_test ("dwarf2_find_containing_comp_unit",
23987 selftests::find_containing_comp_unit::run_test
);