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 (dwarf2_per_cu_data
*this_cu
,
916 dwarf2_per_objfile
*per_objfile
,
917 struct abbrev_table
*abbrev_table
,
921 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
922 dwarf2_per_objfile
*per_objfile
,
923 struct dwarf2_cu
*parent_cu
= nullptr,
924 struct dwo_file
*dwo_file
= nullptr);
926 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
928 const gdb_byte
*info_ptr
= nullptr;
929 struct die_info
*comp_unit_die
= nullptr;
930 bool dummy_p
= false;
932 /* Release the new CU, putting it on the chain. This cannot be done
937 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
938 dwarf2_per_objfile
*per_objfile
,
939 int use_existing_cu
);
941 struct dwarf2_per_cu_data
*m_this_cu
;
942 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
944 /* The ordinary abbreviation table. */
945 abbrev_table_up m_abbrev_table_holder
;
947 /* The DWO abbreviation table. */
948 abbrev_table_up m_dwo_abbrev_table
;
951 /* When we construct a partial symbol table entry we only
952 need this much information. */
953 struct partial_die_info
: public allocate_on_obstack
955 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
957 /* Disable assign but still keep copy ctor, which is needed
958 load_partial_dies. */
959 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
961 /* Adjust the partial die before generating a symbol for it. This
962 function may set the is_external flag or change the DIE's
964 void fixup (struct dwarf2_cu
*cu
);
966 /* Read a minimal amount of information into the minimal die
968 const gdb_byte
*read (const struct die_reader_specs
*reader
,
969 const struct abbrev_info
&abbrev
,
970 const gdb_byte
*info_ptr
);
972 /* Offset of this DIE. */
973 const sect_offset sect_off
;
975 /* DWARF-2 tag for this DIE. */
976 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
978 /* Assorted flags describing the data found in this DIE. */
979 const unsigned int has_children
: 1;
981 unsigned int is_external
: 1;
982 unsigned int is_declaration
: 1;
983 unsigned int has_type
: 1;
984 unsigned int has_specification
: 1;
985 unsigned int has_pc_info
: 1;
986 unsigned int may_be_inlined
: 1;
988 /* This DIE has been marked DW_AT_main_subprogram. */
989 unsigned int main_subprogram
: 1;
991 /* Flag set if the SCOPE field of this structure has been
993 unsigned int scope_set
: 1;
995 /* Flag set if the DIE has a byte_size attribute. */
996 unsigned int has_byte_size
: 1;
998 /* Flag set if the DIE has a DW_AT_const_value attribute. */
999 unsigned int has_const_value
: 1;
1001 /* Flag set if any of the DIE's children are template arguments. */
1002 unsigned int has_template_arguments
: 1;
1004 /* Flag set if fixup has been called on this die. */
1005 unsigned int fixup_called
: 1;
1007 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1008 unsigned int is_dwz
: 1;
1010 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1011 unsigned int spec_is_dwz
: 1;
1013 /* The name of this DIE. Normally the value of DW_AT_name, but
1014 sometimes a default name for unnamed DIEs. */
1015 const char *name
= nullptr;
1017 /* The linkage name, if present. */
1018 const char *linkage_name
= nullptr;
1020 /* The scope to prepend to our children. This is generally
1021 allocated on the comp_unit_obstack, so will disappear
1022 when this compilation unit leaves the cache. */
1023 const char *scope
= nullptr;
1025 /* Some data associated with the partial DIE. The tag determines
1026 which field is live. */
1029 /* The location description associated with this DIE, if any. */
1030 struct dwarf_block
*locdesc
;
1031 /* The offset of an import, for DW_TAG_imported_unit. */
1032 sect_offset sect_off
;
1035 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1036 CORE_ADDR lowpc
= 0;
1037 CORE_ADDR highpc
= 0;
1039 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1040 DW_AT_sibling, if any. */
1041 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1042 could return DW_AT_sibling values to its caller load_partial_dies. */
1043 const gdb_byte
*sibling
= nullptr;
1045 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1046 DW_AT_specification (or DW_AT_abstract_origin or
1047 DW_AT_extension). */
1048 sect_offset spec_offset
{};
1050 /* Pointers to this DIE's parent, first child, and next sibling,
1052 struct partial_die_info
*die_parent
= nullptr;
1053 struct partial_die_info
*die_child
= nullptr;
1054 struct partial_die_info
*die_sibling
= nullptr;
1056 friend struct partial_die_info
*
1057 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1060 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1061 partial_die_info (sect_offset sect_off
)
1062 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1066 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1068 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1073 has_specification
= 0;
1076 main_subprogram
= 0;
1079 has_const_value
= 0;
1080 has_template_arguments
= 0;
1087 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1088 but this would require a corresponding change in unpack_field_as_long
1090 static int bits_per_byte
= 8;
1092 struct variant_part_builder
;
1094 /* When reading a variant, we track a bit more information about the
1095 field, and store it in an object of this type. */
1097 struct variant_field
1099 int first_field
= -1;
1100 int last_field
= -1;
1102 /* A variant can contain other variant parts. */
1103 std::vector
<variant_part_builder
> variant_parts
;
1105 /* If we see a DW_TAG_variant, then this will be set if this is the
1107 bool default_branch
= false;
1108 /* If we see a DW_AT_discr_value, then this will be the discriminant
1110 ULONGEST discriminant_value
= 0;
1111 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1113 struct dwarf_block
*discr_list_data
= nullptr;
1116 /* This represents a DW_TAG_variant_part. */
1118 struct variant_part_builder
1120 /* The offset of the discriminant field. */
1121 sect_offset discriminant_offset
{};
1123 /* Variants that are direct children of this variant part. */
1124 std::vector
<variant_field
> variants
;
1126 /* True if we're currently reading a variant. */
1127 bool processing_variant
= false;
1132 int accessibility
= 0;
1134 /* Variant parts need to find the discriminant, which is a DIE
1135 reference. We track the section offset of each field to make
1138 struct field field
{};
1143 const char *name
= nullptr;
1144 std::vector
<struct fn_field
> fnfields
;
1147 /* The routines that read and process dies for a C struct or C++ class
1148 pass lists of data member fields and lists of member function fields
1149 in an instance of a field_info structure, as defined below. */
1152 /* List of data member and baseclasses fields. */
1153 std::vector
<struct nextfield
> fields
;
1154 std::vector
<struct nextfield
> baseclasses
;
1156 /* Set if the accessibility of one of the fields is not public. */
1157 int non_public_fields
= 0;
1159 /* Member function fieldlist array, contains name of possibly overloaded
1160 member function, number of overloaded member functions and a pointer
1161 to the head of the member function field chain. */
1162 std::vector
<struct fnfieldlist
> fnfieldlists
;
1164 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1165 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1166 std::vector
<struct decl_field
> typedef_field_list
;
1168 /* Nested types defined by this class and the number of elements in this
1170 std::vector
<struct decl_field
> nested_types_list
;
1172 /* If non-null, this is the variant part we are currently
1174 variant_part_builder
*current_variant_part
= nullptr;
1175 /* This holds all the top-level variant parts attached to the type
1177 std::vector
<variant_part_builder
> variant_parts
;
1179 /* Return the total number of fields (including baseclasses). */
1180 int nfields () const
1182 return fields
.size () + baseclasses
.size ();
1186 /* Loaded secondary compilation units are kept in memory until they
1187 have not been referenced for the processing of this many
1188 compilation units. Set this to zero to disable caching. Cache
1189 sizes of up to at least twenty will improve startup time for
1190 typical inter-CU-reference binaries, at an obvious memory cost. */
1191 static int dwarf_max_cache_age
= 5;
1193 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1194 struct cmd_list_element
*c
, const char *value
)
1196 fprintf_filtered (file
, _("The upper bound on the age of cached "
1197 "DWARF compilation units is %s.\n"),
1201 /* local function prototypes */
1203 static void dwarf2_find_base_address (struct die_info
*die
,
1204 struct dwarf2_cu
*cu
);
1206 static dwarf2_psymtab
*create_partial_symtab
1207 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1210 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1211 const gdb_byte
*info_ptr
,
1212 struct die_info
*type_unit_die
);
1214 static void dwarf2_build_psymtabs_hard
1215 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1217 static void scan_partial_symbols (struct partial_die_info
*,
1218 CORE_ADDR
*, CORE_ADDR
*,
1219 int, struct dwarf2_cu
*);
1221 static void add_partial_symbol (struct partial_die_info
*,
1222 struct dwarf2_cu
*);
1224 static void add_partial_namespace (struct partial_die_info
*pdi
,
1225 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1226 int set_addrmap
, struct dwarf2_cu
*cu
);
1228 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1229 CORE_ADDR
*highpc
, int set_addrmap
,
1230 struct dwarf2_cu
*cu
);
1232 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1233 struct dwarf2_cu
*cu
);
1235 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1236 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1237 int need_pc
, struct dwarf2_cu
*cu
);
1239 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1241 static struct partial_die_info
*load_partial_dies
1242 (const struct die_reader_specs
*, const gdb_byte
*, int);
1244 /* A pair of partial_die_info and compilation unit. */
1245 struct cu_partial_die_info
1247 /* The compilation unit of the partial_die_info. */
1248 struct dwarf2_cu
*cu
;
1249 /* A partial_die_info. */
1250 struct partial_die_info
*pdi
;
1252 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1258 cu_partial_die_info () = delete;
1261 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1262 struct dwarf2_cu
*);
1264 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1265 struct attribute
*, struct attr_abbrev
*,
1266 const gdb_byte
*, bool *need_reprocess
);
1268 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1269 struct attribute
*attr
);
1271 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1273 static sect_offset read_abbrev_offset
1274 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1275 struct dwarf2_section_info
*, sect_offset
);
1277 static const char *read_indirect_string
1278 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1279 const struct comp_unit_head
*, unsigned int *);
1281 static const char *read_indirect_string_at_offset
1282 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1284 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1288 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1289 ULONGEST str_index
);
1291 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1292 ULONGEST str_index
);
1294 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1296 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1297 struct dwarf2_cu
*);
1299 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1300 struct dwarf2_cu
*cu
);
1302 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1304 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1305 struct dwarf2_cu
*cu
);
1307 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1309 static struct die_info
*die_specification (struct die_info
*die
,
1310 struct dwarf2_cu
**);
1312 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1313 struct dwarf2_cu
*cu
);
1315 static void dwarf_decode_lines (struct line_header
*, const char *,
1316 struct dwarf2_cu
*, dwarf2_psymtab
*,
1317 CORE_ADDR
, int decode_mapping
);
1319 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1322 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1323 struct dwarf2_cu
*, struct symbol
* = NULL
);
1325 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1326 struct dwarf2_cu
*);
1328 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1331 struct obstack
*obstack
,
1332 struct dwarf2_cu
*cu
, LONGEST
*value
,
1333 const gdb_byte
**bytes
,
1334 struct dwarf2_locexpr_baton
**baton
);
1336 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1338 static int need_gnat_info (struct dwarf2_cu
*);
1340 static struct type
*die_descriptive_type (struct die_info
*,
1341 struct dwarf2_cu
*);
1343 static void set_descriptive_type (struct type
*, struct die_info
*,
1344 struct dwarf2_cu
*);
1346 static struct type
*die_containing_type (struct die_info
*,
1347 struct dwarf2_cu
*);
1349 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1350 struct dwarf2_cu
*);
1352 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1354 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1356 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1358 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1359 const char *suffix
, int physname
,
1360 struct dwarf2_cu
*cu
);
1362 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1364 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1366 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1368 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1370 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1372 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1374 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1375 struct dwarf2_cu
*, dwarf2_psymtab
*);
1377 /* Return the .debug_loclists section to use for cu. */
1378 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1380 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1381 values. Keep the items ordered with increasing constraints compliance. */
1384 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1385 PC_BOUNDS_NOT_PRESENT
,
1387 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1388 were present but they do not form a valid range of PC addresses. */
1391 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1394 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1398 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1399 CORE_ADDR
*, CORE_ADDR
*,
1403 static void get_scope_pc_bounds (struct die_info
*,
1404 CORE_ADDR
*, CORE_ADDR
*,
1405 struct dwarf2_cu
*);
1407 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1408 CORE_ADDR
, struct dwarf2_cu
*);
1410 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1411 struct dwarf2_cu
*);
1413 static void dwarf2_attach_fields_to_type (struct field_info
*,
1414 struct type
*, struct dwarf2_cu
*);
1416 static void dwarf2_add_member_fn (struct field_info
*,
1417 struct die_info
*, struct type
*,
1418 struct dwarf2_cu
*);
1420 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1422 struct dwarf2_cu
*);
1424 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1426 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1428 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1430 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1432 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1434 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1436 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1438 static struct type
*read_module_type (struct die_info
*die
,
1439 struct dwarf2_cu
*cu
);
1441 static const char *namespace_name (struct die_info
*die
,
1442 int *is_anonymous
, struct dwarf2_cu
*);
1444 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1446 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1449 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1450 struct dwarf2_cu
*);
1452 static struct die_info
*read_die_and_siblings_1
1453 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1456 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1457 const gdb_byte
*info_ptr
,
1458 const gdb_byte
**new_info_ptr
,
1459 struct die_info
*parent
);
1461 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1462 struct die_info
**, const gdb_byte
*,
1465 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1466 struct die_info
**, const gdb_byte
*);
1468 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1470 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1473 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1475 static const char *dwarf2_full_name (const char *name
,
1476 struct die_info
*die
,
1477 struct dwarf2_cu
*cu
);
1479 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1480 struct dwarf2_cu
*cu
);
1482 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1483 struct dwarf2_cu
**);
1485 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1487 static void dump_die_for_error (struct die_info
*);
1489 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1492 /*static*/ void dump_die (struct die_info
*, int max_level
);
1494 static void store_in_ref_table (struct die_info
*,
1495 struct dwarf2_cu
*);
1497 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1498 const struct attribute
*,
1499 struct dwarf2_cu
**);
1501 static struct die_info
*follow_die_ref (struct die_info
*,
1502 const struct attribute
*,
1503 struct dwarf2_cu
**);
1505 static struct die_info
*follow_die_sig (struct die_info
*,
1506 const struct attribute
*,
1507 struct dwarf2_cu
**);
1509 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1510 struct dwarf2_cu
*);
1512 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1513 const struct attribute
*,
1514 struct dwarf2_cu
*);
1516 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1517 dwarf2_per_objfile
*per_objfile
);
1519 static void read_signatured_type (signatured_type
*sig_type
,
1520 dwarf2_per_objfile
*per_objfile
);
1522 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1523 struct die_info
*die
, struct dwarf2_cu
*cu
,
1524 struct dynamic_prop
*prop
, struct type
*type
);
1526 /* memory allocation interface */
1528 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1530 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1532 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1534 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1535 struct dwarf2_loclist_baton
*baton
,
1536 const struct attribute
*attr
);
1538 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1540 struct dwarf2_cu
*cu
,
1543 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1544 const gdb_byte
*info_ptr
,
1545 struct abbrev_info
*abbrev
);
1547 static hashval_t
partial_die_hash (const void *item
);
1549 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1551 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1552 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1553 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1555 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1556 struct die_info
*comp_unit_die
,
1557 enum language pretend_language
);
1559 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1561 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1563 static struct type
*set_die_type (struct die_info
*, struct type
*,
1564 struct dwarf2_cu
*);
1566 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1568 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1570 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1571 dwarf2_per_objfile
*per_objfile
,
1573 enum language pretend_language
);
1575 static void process_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1576 dwarf2_per_objfile
*per_objfile
,
1577 enum language pretend_language
);
1579 static void process_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1580 dwarf2_per_objfile
*per_objfile
,
1581 enum language pretend_language
);
1583 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1584 struct dwarf2_per_cu_data
*);
1586 static void dwarf2_mark (struct dwarf2_cu
*);
1588 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1590 static struct type
*get_die_type_at_offset (sect_offset
,
1591 struct dwarf2_per_cu_data
*);
1593 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1595 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1596 enum language pretend_language
);
1598 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1600 /* Class, the destructor of which frees all allocated queue entries. This
1601 will only have work to do if an error was thrown while processing the
1602 dwarf. If no error was thrown then the queue entries should have all
1603 been processed, and freed, as we went along. */
1605 class dwarf2_queue_guard
1608 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1609 : m_per_objfile (per_objfile
)
1613 /* Free any entries remaining on the queue. There should only be
1614 entries left if we hit an error while processing the dwarf. */
1615 ~dwarf2_queue_guard ()
1617 /* Ensure that no memory is allocated by the queue. */
1618 std::queue
<dwarf2_queue_item
> empty
;
1619 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1622 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1625 dwarf2_per_objfile
*m_per_objfile
;
1628 dwarf2_queue_item::~dwarf2_queue_item ()
1630 /* Anything still marked queued is likely to be in an
1631 inconsistent state, so discard it. */
1634 if (per_cu
->cu
!= NULL
)
1635 free_one_cached_comp_unit (per_cu
);
1640 /* The return type of find_file_and_directory. Note, the enclosed
1641 string pointers are only valid while this object is valid. */
1643 struct file_and_directory
1645 /* The filename. This is never NULL. */
1648 /* The compilation directory. NULL if not known. If we needed to
1649 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1650 points directly to the DW_AT_comp_dir string attribute owned by
1651 the obstack that owns the DIE. */
1652 const char *comp_dir
;
1654 /* If we needed to build a new string for comp_dir, this is what
1655 owns the storage. */
1656 std::string comp_dir_storage
;
1659 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1660 struct dwarf2_cu
*cu
);
1662 static htab_up
allocate_signatured_type_table ();
1664 static htab_up
allocate_dwo_unit_table ();
1666 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1667 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1668 struct dwp_file
*dwp_file
, const char *comp_dir
,
1669 ULONGEST signature
, int is_debug_types
);
1671 static struct dwp_file
*get_dwp_file
1672 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1674 static struct dwo_unit
*lookup_dwo_comp_unit
1675 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1676 ULONGEST signature
);
1678 static struct dwo_unit
*lookup_dwo_type_unit
1679 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1681 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1683 /* A unique pointer to a dwo_file. */
1685 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1687 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1689 static void check_producer (struct dwarf2_cu
*cu
);
1691 static void free_line_header_voidp (void *arg
);
1693 /* Various complaints about symbol reading that don't abort the process. */
1696 dwarf2_debug_line_missing_file_complaint (void)
1698 complaint (_(".debug_line section has line data without a file"));
1702 dwarf2_debug_line_missing_end_sequence_complaint (void)
1704 complaint (_(".debug_line section has line "
1705 "program sequence without an end"));
1709 dwarf2_complex_location_expr_complaint (void)
1711 complaint (_("location expression too complex"));
1715 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1718 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1723 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1725 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1729 /* Hash function for line_header_hash. */
1732 line_header_hash (const struct line_header
*ofs
)
1734 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1737 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1740 line_header_hash_voidp (const void *item
)
1742 const struct line_header
*ofs
= (const struct line_header
*) item
;
1744 return line_header_hash (ofs
);
1747 /* Equality function for line_header_hash. */
1750 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1752 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1753 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1755 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1756 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1761 /* See declaration. */
1763 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1766 can_copy (can_copy_
)
1769 names
= &dwarf2_elf_names
;
1771 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1772 locate_sections (obfd
, sec
, *names
);
1775 dwarf2_per_bfd::~dwarf2_per_bfd ()
1777 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1778 free_cached_comp_units ();
1780 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1781 per_cu
->imported_symtabs_free ();
1783 for (signatured_type
*sig_type
: all_type_units
)
1784 sig_type
->per_cu
.imported_symtabs_free ();
1786 /* Everything else should be on this->obstack. */
1789 /* See declaration. */
1792 dwarf2_per_bfd::free_cached_comp_units ()
1794 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1795 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1796 while (per_cu
!= NULL
)
1798 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1801 *last_chain
= next_cu
;
1806 /* A helper class that calls free_cached_comp_units on
1809 class free_cached_comp_units
1813 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1814 : m_per_objfile (per_objfile
)
1818 ~free_cached_comp_units ()
1820 m_per_objfile
->per_bfd
->free_cached_comp_units ();
1823 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1827 dwarf2_per_objfile
*m_per_objfile
;
1833 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1835 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1837 return this->m_symtabs
[per_cu
->index
] != nullptr;
1843 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1845 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1847 return this->m_symtabs
[per_cu
->index
];
1853 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1854 compunit_symtab
*symtab
)
1856 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1857 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1859 this->m_symtabs
[per_cu
->index
] = symtab
;
1862 /* Try to locate the sections we need for DWARF 2 debugging
1863 information and return true if we have enough to do something.
1864 NAMES points to the dwarf2 section names, or is NULL if the standard
1865 ELF names are used. CAN_COPY is true for formats where symbol
1866 interposition is possible and so symbol values must follow copy
1867 relocation rules. */
1870 dwarf2_has_info (struct objfile
*objfile
,
1871 const struct dwarf2_debug_sections
*names
,
1874 if (objfile
->flags
& OBJF_READNEVER
)
1877 struct dwarf2_per_objfile
*dwarf2_per_objfile
1878 = get_dwarf2_per_objfile (objfile
);
1880 if (dwarf2_per_objfile
== NULL
)
1882 /* For now, each dwarf2_per_objfile owns its own dwarf2_per_bfd (no
1884 dwarf2_per_bfd
*per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1886 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1889 return (!dwarf2_per_objfile
->per_bfd
->info
.is_virtual
1890 && dwarf2_per_objfile
->per_bfd
->info
.s
.section
!= NULL
1891 && !dwarf2_per_objfile
->per_bfd
->abbrev
.is_virtual
1892 && dwarf2_per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1895 /* When loading sections, we look either for uncompressed section or for
1896 compressed section names. */
1899 section_is_p (const char *section_name
,
1900 const struct dwarf2_section_names
*names
)
1902 if (names
->normal
!= NULL
1903 && strcmp (section_name
, names
->normal
) == 0)
1905 if (names
->compressed
!= NULL
1906 && strcmp (section_name
, names
->compressed
) == 0)
1911 /* See declaration. */
1914 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1915 const dwarf2_debug_sections
&names
)
1917 flagword aflag
= bfd_section_flags (sectp
);
1919 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1922 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1923 > bfd_get_file_size (abfd
))
1925 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1926 warning (_("Discarding section %s which has a section size (%s"
1927 ") larger than the file size [in module %s]"),
1928 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1929 bfd_get_filename (abfd
));
1931 else if (section_is_p (sectp
->name
, &names
.info
))
1933 this->info
.s
.section
= sectp
;
1934 this->info
.size
= bfd_section_size (sectp
);
1936 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1938 this->abbrev
.s
.section
= sectp
;
1939 this->abbrev
.size
= bfd_section_size (sectp
);
1941 else if (section_is_p (sectp
->name
, &names
.line
))
1943 this->line
.s
.section
= sectp
;
1944 this->line
.size
= bfd_section_size (sectp
);
1946 else if (section_is_p (sectp
->name
, &names
.loc
))
1948 this->loc
.s
.section
= sectp
;
1949 this->loc
.size
= bfd_section_size (sectp
);
1951 else if (section_is_p (sectp
->name
, &names
.loclists
))
1953 this->loclists
.s
.section
= sectp
;
1954 this->loclists
.size
= bfd_section_size (sectp
);
1956 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1958 this->macinfo
.s
.section
= sectp
;
1959 this->macinfo
.size
= bfd_section_size (sectp
);
1961 else if (section_is_p (sectp
->name
, &names
.macro
))
1963 this->macro
.s
.section
= sectp
;
1964 this->macro
.size
= bfd_section_size (sectp
);
1966 else if (section_is_p (sectp
->name
, &names
.str
))
1968 this->str
.s
.section
= sectp
;
1969 this->str
.size
= bfd_section_size (sectp
);
1971 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1973 this->str_offsets
.s
.section
= sectp
;
1974 this->str_offsets
.size
= bfd_section_size (sectp
);
1976 else if (section_is_p (sectp
->name
, &names
.line_str
))
1978 this->line_str
.s
.section
= sectp
;
1979 this->line_str
.size
= bfd_section_size (sectp
);
1981 else if (section_is_p (sectp
->name
, &names
.addr
))
1983 this->addr
.s
.section
= sectp
;
1984 this->addr
.size
= bfd_section_size (sectp
);
1986 else if (section_is_p (sectp
->name
, &names
.frame
))
1988 this->frame
.s
.section
= sectp
;
1989 this->frame
.size
= bfd_section_size (sectp
);
1991 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1993 this->eh_frame
.s
.section
= sectp
;
1994 this->eh_frame
.size
= bfd_section_size (sectp
);
1996 else if (section_is_p (sectp
->name
, &names
.ranges
))
1998 this->ranges
.s
.section
= sectp
;
1999 this->ranges
.size
= bfd_section_size (sectp
);
2001 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2003 this->rnglists
.s
.section
= sectp
;
2004 this->rnglists
.size
= bfd_section_size (sectp
);
2006 else if (section_is_p (sectp
->name
, &names
.types
))
2008 struct dwarf2_section_info type_section
;
2010 memset (&type_section
, 0, sizeof (type_section
));
2011 type_section
.s
.section
= sectp
;
2012 type_section
.size
= bfd_section_size (sectp
);
2014 this->types
.push_back (type_section
);
2016 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2018 this->gdb_index
.s
.section
= sectp
;
2019 this->gdb_index
.size
= bfd_section_size (sectp
);
2021 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2023 this->debug_names
.s
.section
= sectp
;
2024 this->debug_names
.size
= bfd_section_size (sectp
);
2026 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2028 this->debug_aranges
.s
.section
= sectp
;
2029 this->debug_aranges
.size
= bfd_section_size (sectp
);
2032 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2033 && bfd_section_vma (sectp
) == 0)
2034 this->has_section_at_zero
= true;
2037 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2041 dwarf2_get_section_info (struct objfile
*objfile
,
2042 enum dwarf2_section_enum sect
,
2043 asection
**sectp
, const gdb_byte
**bufp
,
2044 bfd_size_type
*sizep
)
2046 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2047 struct dwarf2_section_info
*info
;
2049 /* We may see an objfile without any DWARF, in which case we just
2060 case DWARF2_DEBUG_FRAME
:
2061 info
= &data
->per_bfd
->frame
;
2063 case DWARF2_EH_FRAME
:
2064 info
= &data
->per_bfd
->eh_frame
;
2067 gdb_assert_not_reached ("unexpected section");
2070 info
->read (objfile
);
2072 *sectp
= info
->get_bfd_section ();
2073 *bufp
= info
->buffer
;
2074 *sizep
= info
->size
;
2077 /* A helper function to find the sections for a .dwz file. */
2080 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2082 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2084 /* Note that we only support the standard ELF names, because .dwz
2085 is ELF-only (at the time of writing). */
2086 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2088 dwz_file
->abbrev
.s
.section
= sectp
;
2089 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2091 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2093 dwz_file
->info
.s
.section
= sectp
;
2094 dwz_file
->info
.size
= bfd_section_size (sectp
);
2096 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2098 dwz_file
->str
.s
.section
= sectp
;
2099 dwz_file
->str
.size
= bfd_section_size (sectp
);
2101 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2103 dwz_file
->line
.s
.section
= sectp
;
2104 dwz_file
->line
.size
= bfd_section_size (sectp
);
2106 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2108 dwz_file
->macro
.s
.section
= sectp
;
2109 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2111 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2113 dwz_file
->gdb_index
.s
.section
= sectp
;
2114 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2116 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2118 dwz_file
->debug_names
.s
.section
= sectp
;
2119 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2123 /* See dwarf2read.h. */
2126 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2128 const char *filename
;
2129 bfd_size_type buildid_len_arg
;
2133 if (per_bfd
->dwz_file
!= NULL
)
2134 return per_bfd
->dwz_file
.get ();
2136 bfd_set_error (bfd_error_no_error
);
2137 gdb::unique_xmalloc_ptr
<char> data
2138 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2139 &buildid_len_arg
, &buildid
));
2142 if (bfd_get_error () == bfd_error_no_error
)
2144 error (_("could not read '.gnu_debugaltlink' section: %s"),
2145 bfd_errmsg (bfd_get_error ()));
2148 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2150 buildid_len
= (size_t) buildid_len_arg
;
2152 filename
= data
.get ();
2154 std::string abs_storage
;
2155 if (!IS_ABSOLUTE_PATH (filename
))
2157 gdb::unique_xmalloc_ptr
<char> abs
2158 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2160 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2161 filename
= abs_storage
.c_str ();
2164 /* First try the file name given in the section. If that doesn't
2165 work, try to use the build-id instead. */
2166 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2167 if (dwz_bfd
!= NULL
)
2169 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2170 dwz_bfd
.reset (nullptr);
2173 if (dwz_bfd
== NULL
)
2174 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2176 if (dwz_bfd
== nullptr)
2178 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2179 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2181 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2188 /* File successfully retrieved from server. */
2189 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2191 if (dwz_bfd
== nullptr)
2192 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2193 alt_filename
.get ());
2194 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2195 dwz_bfd
.reset (nullptr);
2199 if (dwz_bfd
== NULL
)
2200 error (_("could not find '.gnu_debugaltlink' file for %s"),
2201 bfd_get_filename (per_bfd
->obfd
));
2203 std::unique_ptr
<struct dwz_file
> result
2204 (new struct dwz_file (std::move (dwz_bfd
)));
2206 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2209 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2210 per_bfd
->dwz_file
= std::move (result
);
2211 return per_bfd
->dwz_file
.get ();
2214 /* DWARF quick_symbols_functions support. */
2216 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2217 unique line tables, so we maintain a separate table of all .debug_line
2218 derived entries to support the sharing.
2219 All the quick functions need is the list of file names. We discard the
2220 line_header when we're done and don't need to record it here. */
2221 struct quick_file_names
2223 /* The data used to construct the hash key. */
2224 struct stmt_list_hash hash
;
2226 /* The number of entries in file_names, real_names. */
2227 unsigned int num_file_names
;
2229 /* The file names from the line table, after being run through
2231 const char **file_names
;
2233 /* The file names from the line table after being run through
2234 gdb_realpath. These are computed lazily. */
2235 const char **real_names
;
2238 /* When using the index (and thus not using psymtabs), each CU has an
2239 object of this type. This is used to hold information needed by
2240 the various "quick" methods. */
2241 struct dwarf2_per_cu_quick_data
2243 /* The file table. This can be NULL if there was no file table
2244 or it's currently not read in.
2245 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2246 struct quick_file_names
*file_names
;
2248 /* A temporary mark bit used when iterating over all CUs in
2249 expand_symtabs_matching. */
2250 unsigned int mark
: 1;
2252 /* True if we've tried to read the file table and found there isn't one.
2253 There will be no point in trying to read it again next time. */
2254 unsigned int no_file_data
: 1;
2257 /* Utility hash function for a stmt_list_hash. */
2260 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2264 if (stmt_list_hash
->dwo_unit
!= NULL
)
2265 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2266 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2270 /* Utility equality function for a stmt_list_hash. */
2273 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2274 const struct stmt_list_hash
*rhs
)
2276 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2278 if (lhs
->dwo_unit
!= NULL
2279 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2282 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2285 /* Hash function for a quick_file_names. */
2288 hash_file_name_entry (const void *e
)
2290 const struct quick_file_names
*file_data
2291 = (const struct quick_file_names
*) e
;
2293 return hash_stmt_list_entry (&file_data
->hash
);
2296 /* Equality function for a quick_file_names. */
2299 eq_file_name_entry (const void *a
, const void *b
)
2301 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2302 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2304 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2307 /* Delete function for a quick_file_names. */
2310 delete_file_name_entry (void *e
)
2312 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2315 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2317 xfree ((void*) file_data
->file_names
[i
]);
2318 if (file_data
->real_names
)
2319 xfree ((void*) file_data
->real_names
[i
]);
2322 /* The space for the struct itself lives on the obstack, so we don't
2326 /* Create a quick_file_names hash table. */
2329 create_quick_file_names_table (unsigned int nr_initial_entries
)
2331 return htab_up (htab_create_alloc (nr_initial_entries
,
2332 hash_file_name_entry
, eq_file_name_entry
,
2333 delete_file_name_entry
, xcalloc
, xfree
));
2336 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2337 function is unrelated to symtabs, symtab would have to be created afterwards.
2338 You should call age_cached_comp_units after processing the CU. */
2341 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2344 if (per_cu
->is_debug_types
)
2345 load_full_type_unit (per_cu
, per_objfile
);
2347 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2349 if (per_cu
->cu
== NULL
)
2350 return; /* Dummy CU. */
2352 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2355 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2358 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2359 dwarf2_per_objfile
*dwarf2_per_objfile
,
2362 /* Skip type_unit_groups, reading the type units they contain
2363 is handled elsewhere. */
2364 if (per_cu
->type_unit_group_p ())
2367 /* The destructor of dwarf2_queue_guard frees any entries left on
2368 the queue. After this point we're guaranteed to leave this function
2369 with the dwarf queue empty. */
2370 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2372 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2374 queue_comp_unit (per_cu
, language_minimal
);
2375 load_cu (per_cu
, dwarf2_per_objfile
, skip_partial
);
2377 /* If we just loaded a CU from a DWO, and we're working with an index
2378 that may badly handle TUs, load all the TUs in that DWO as well.
2379 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2380 if (!per_cu
->is_debug_types
2381 && per_cu
->cu
!= NULL
2382 && per_cu
->cu
->dwo_unit
!= NULL
2383 && dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
2384 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7
2385 /* DWP files aren't supported yet. */
2386 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2387 queue_and_load_all_dwo_tus (per_cu
);
2390 process_queue (dwarf2_per_objfile
);
2392 /* Age the cache, releasing compilation units that have not
2393 been used recently. */
2394 age_cached_comp_units (dwarf2_per_objfile
);
2397 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2398 the per-objfile for which this symtab is instantiated.
2400 Returns the resulting symbol table. */
2402 static struct compunit_symtab
*
2403 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2404 dwarf2_per_objfile
*dwarf2_per_objfile
,
2407 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
2409 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2411 free_cached_comp_units
freer (dwarf2_per_objfile
);
2412 scoped_restore decrementer
= increment_reading_symtab ();
2413 dw2_do_instantiate_symtab (per_cu
, dwarf2_per_objfile
, skip_partial
);
2414 process_cu_includes (dwarf2_per_objfile
);
2417 return dwarf2_per_objfile
->get_symtab (per_cu
);
2420 /* See declaration. */
2422 dwarf2_per_cu_data
*
2423 dwarf2_per_bfd::get_cutu (int index
)
2425 if (index
>= this->all_comp_units
.size ())
2427 index
-= this->all_comp_units
.size ();
2428 gdb_assert (index
< this->all_type_units
.size ());
2429 return &this->all_type_units
[index
]->per_cu
;
2432 return this->all_comp_units
[index
];
2435 /* See declaration. */
2437 dwarf2_per_cu_data
*
2438 dwarf2_per_bfd::get_cu (int index
)
2440 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2442 return this->all_comp_units
[index
];
2445 /* See declaration. */
2448 dwarf2_per_bfd::get_tu (int index
)
2450 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2452 return this->all_type_units
[index
];
2457 dwarf2_per_cu_data
*
2458 dwarf2_per_bfd::allocate_per_cu ()
2460 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2461 result
->per_bfd
= this;
2462 result
->index
= m_num_psymtabs
++;
2469 dwarf2_per_bfd::allocate_signatured_type ()
2471 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2472 result
->per_cu
.per_bfd
= this;
2473 result
->per_cu
.index
= m_num_psymtabs
++;
2477 /* Return a new dwarf2_per_cu_data allocated on the dwarf2_per_objfile
2478 obstack, and constructed with the specified field values. */
2480 static dwarf2_per_cu_data
*
2481 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2482 struct dwarf2_section_info
*section
,
2484 sect_offset sect_off
, ULONGEST length
)
2486 dwarf2_per_cu_data
*the_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
2487 the_cu
->sect_off
= sect_off
;
2488 the_cu
->length
= length
;
2489 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2490 the_cu
->section
= section
;
2491 the_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2492 struct dwarf2_per_cu_quick_data
);
2493 the_cu
->is_dwz
= is_dwz
;
2497 /* A helper for create_cus_from_index that handles a given list of
2501 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2502 const gdb_byte
*cu_list
, offset_type n_elements
,
2503 struct dwarf2_section_info
*section
,
2506 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2508 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2510 sect_offset sect_off
2511 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2512 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2515 dwarf2_per_cu_data
*per_cu
2516 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2518 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
2522 /* Read the CU list from the mapped index, and use it to create all
2523 the CU objects for this objfile. */
2526 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2527 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2528 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2530 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
2531 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve
2532 ((cu_list_elements
+ dwz_elements
) / 2);
2534 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2535 &dwarf2_per_objfile
->per_bfd
->info
, 0);
2537 if (dwz_elements
== 0)
2540 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
2541 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2545 /* Create the signatured type hash table from the index. */
2548 create_signatured_type_table_from_index
2549 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2550 struct dwarf2_section_info
*section
,
2551 const gdb_byte
*bytes
,
2552 offset_type elements
)
2554 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2555 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (elements
/ 3);
2557 htab_up sig_types_hash
= allocate_signatured_type_table ();
2559 for (offset_type i
= 0; i
< elements
; i
+= 3)
2561 struct signatured_type
*sig_type
;
2564 cu_offset type_offset_in_tu
;
2566 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2567 sect_offset sect_off
2568 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2570 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2572 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2575 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2576 sig_type
->signature
= signature
;
2577 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2578 sig_type
->per_cu
.is_debug_types
= 1;
2579 sig_type
->per_cu
.section
= section
;
2580 sig_type
->per_cu
.sect_off
= sect_off
;
2581 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2582 sig_type
->per_cu
.v
.quick
2583 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2584 struct dwarf2_per_cu_quick_data
);
2586 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2589 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2592 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2595 /* Create the signatured type hash table from .debug_names. */
2598 create_signatured_type_table_from_debug_names
2599 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2600 const mapped_debug_names
&map
,
2601 struct dwarf2_section_info
*section
,
2602 struct dwarf2_section_info
*abbrev_section
)
2604 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2606 section
->read (objfile
);
2607 abbrev_section
->read (objfile
);
2609 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2610 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2612 htab_up sig_types_hash
= allocate_signatured_type_table ();
2614 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2616 struct signatured_type
*sig_type
;
2619 sect_offset sect_off
2620 = (sect_offset
) (extract_unsigned_integer
2621 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2623 map
.dwarf5_byte_order
));
2625 comp_unit_head cu_header
;
2626 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2628 section
->buffer
+ to_underlying (sect_off
),
2631 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2632 sig_type
->signature
= cu_header
.signature
;
2633 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2634 sig_type
->per_cu
.is_debug_types
= 1;
2635 sig_type
->per_cu
.section
= section
;
2636 sig_type
->per_cu
.sect_off
= sect_off
;
2637 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2638 sig_type
->per_cu
.v
.quick
2639 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2640 struct dwarf2_per_cu_quick_data
);
2642 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2645 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2648 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2651 /* Read the address map data from the mapped index, and use it to
2652 populate the objfile's psymtabs_addrmap. */
2655 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2656 struct mapped_index
*index
)
2658 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2659 struct gdbarch
*gdbarch
= objfile
->arch ();
2660 const gdb_byte
*iter
, *end
;
2661 struct addrmap
*mutable_map
;
2664 auto_obstack temp_obstack
;
2666 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2668 iter
= index
->address_table
.data ();
2669 end
= iter
+ index
->address_table
.size ();
2671 baseaddr
= objfile
->text_section_offset ();
2675 ULONGEST hi
, lo
, cu_index
;
2676 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2678 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2680 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2685 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2686 hex_string (lo
), hex_string (hi
));
2690 if (cu_index
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
2692 complaint (_(".gdb_index address table has invalid CU number %u"),
2693 (unsigned) cu_index
);
2697 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2698 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2699 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2700 dwarf2_per_objfile
->per_bfd
->get_cu (cu_index
));
2703 objfile
->partial_symtabs
->psymtabs_addrmap
2704 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2707 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2708 populate the objfile's psymtabs_addrmap. */
2711 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2712 struct dwarf2_section_info
*section
)
2714 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2715 bfd
*abfd
= objfile
->obfd
;
2716 struct gdbarch
*gdbarch
= objfile
->arch ();
2717 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2719 auto_obstack temp_obstack
;
2720 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2722 std::unordered_map
<sect_offset
,
2723 dwarf2_per_cu_data
*,
2724 gdb::hash_enum
<sect_offset
>>
2725 debug_info_offset_to_per_cu
;
2726 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
2728 const auto insertpair
2729 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2730 if (!insertpair
.second
)
2732 warning (_("Section .debug_aranges in %s has duplicate "
2733 "debug_info_offset %s, ignoring .debug_aranges."),
2734 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2739 section
->read (objfile
);
2741 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2743 const gdb_byte
*addr
= section
->buffer
;
2745 while (addr
< section
->buffer
+ section
->size
)
2747 const gdb_byte
*const entry_addr
= addr
;
2748 unsigned int bytes_read
;
2750 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2754 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2755 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2756 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2757 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2759 warning (_("Section .debug_aranges in %s entry at offset %s "
2760 "length %s exceeds section length %s, "
2761 "ignoring .debug_aranges."),
2762 objfile_name (objfile
),
2763 plongest (entry_addr
- section
->buffer
),
2764 plongest (bytes_read
+ entry_length
),
2765 pulongest (section
->size
));
2769 /* The version number. */
2770 const uint16_t version
= read_2_bytes (abfd
, addr
);
2774 warning (_("Section .debug_aranges in %s entry at offset %s "
2775 "has unsupported version %d, ignoring .debug_aranges."),
2776 objfile_name (objfile
),
2777 plongest (entry_addr
- section
->buffer
), version
);
2781 const uint64_t debug_info_offset
2782 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2783 addr
+= offset_size
;
2784 const auto per_cu_it
2785 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2786 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2788 warning (_("Section .debug_aranges in %s entry at offset %s "
2789 "debug_info_offset %s does not exists, "
2790 "ignoring .debug_aranges."),
2791 objfile_name (objfile
),
2792 plongest (entry_addr
- section
->buffer
),
2793 pulongest (debug_info_offset
));
2796 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2798 const uint8_t address_size
= *addr
++;
2799 if (address_size
< 1 || address_size
> 8)
2801 warning (_("Section .debug_aranges in %s entry at offset %s "
2802 "address_size %u is invalid, ignoring .debug_aranges."),
2803 objfile_name (objfile
),
2804 plongest (entry_addr
- section
->buffer
), address_size
);
2808 const uint8_t segment_selector_size
= *addr
++;
2809 if (segment_selector_size
!= 0)
2811 warning (_("Section .debug_aranges in %s entry at offset %s "
2812 "segment_selector_size %u is not supported, "
2813 "ignoring .debug_aranges."),
2814 objfile_name (objfile
),
2815 plongest (entry_addr
- section
->buffer
),
2816 segment_selector_size
);
2820 /* Must pad to an alignment boundary that is twice the address
2821 size. It is undocumented by the DWARF standard but GCC does
2823 for (size_t padding
= ((-(addr
- section
->buffer
))
2824 & (2 * address_size
- 1));
2825 padding
> 0; padding
--)
2828 warning (_("Section .debug_aranges in %s entry at offset %s "
2829 "padding is not zero, ignoring .debug_aranges."),
2830 objfile_name (objfile
),
2831 plongest (entry_addr
- section
->buffer
));
2837 if (addr
+ 2 * address_size
> entry_end
)
2839 warning (_("Section .debug_aranges in %s entry at offset %s "
2840 "address list is not properly terminated, "
2841 "ignoring .debug_aranges."),
2842 objfile_name (objfile
),
2843 plongest (entry_addr
- section
->buffer
));
2846 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2848 addr
+= address_size
;
2849 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2851 addr
+= address_size
;
2852 if (start
== 0 && length
== 0)
2854 if (start
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
2856 /* Symbol was eliminated due to a COMDAT group. */
2859 ULONGEST end
= start
+ length
;
2860 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2862 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2864 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2868 objfile
->partial_symtabs
->psymtabs_addrmap
2869 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2872 /* Find a slot in the mapped index INDEX for the object named NAME.
2873 If NAME is found, set *VEC_OUT to point to the CU vector in the
2874 constant pool and return true. If NAME cannot be found, return
2878 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2879 offset_type
**vec_out
)
2882 offset_type slot
, step
;
2883 int (*cmp
) (const char *, const char *);
2885 gdb::unique_xmalloc_ptr
<char> without_params
;
2886 if (current_language
->la_language
== language_cplus
2887 || current_language
->la_language
== language_fortran
2888 || current_language
->la_language
== language_d
)
2890 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2893 if (strchr (name
, '(') != NULL
)
2895 without_params
= cp_remove_params (name
);
2897 if (without_params
!= NULL
)
2898 name
= without_params
.get ();
2902 /* Index version 4 did not support case insensitive searches. But the
2903 indices for case insensitive languages are built in lowercase, therefore
2904 simulate our NAME being searched is also lowercased. */
2905 hash
= mapped_index_string_hash ((index
->version
== 4
2906 && case_sensitivity
== case_sensitive_off
2907 ? 5 : index
->version
),
2910 slot
= hash
& (index
->symbol_table
.size () - 1);
2911 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2912 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2918 const auto &bucket
= index
->symbol_table
[slot
];
2919 if (bucket
.name
== 0 && bucket
.vec
== 0)
2922 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2923 if (!cmp (name
, str
))
2925 *vec_out
= (offset_type
*) (index
->constant_pool
2926 + MAYBE_SWAP (bucket
.vec
));
2930 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2934 /* A helper function that reads the .gdb_index from BUFFER and fills
2935 in MAP. FILENAME is the name of the file containing the data;
2936 it is used for error reporting. DEPRECATED_OK is true if it is
2937 ok to use deprecated sections.
2939 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2940 out parameters that are filled in with information about the CU and
2941 TU lists in the section.
2943 Returns true if all went well, false otherwise. */
2946 read_gdb_index_from_buffer (const char *filename
,
2948 gdb::array_view
<const gdb_byte
> buffer
,
2949 struct mapped_index
*map
,
2950 const gdb_byte
**cu_list
,
2951 offset_type
*cu_list_elements
,
2952 const gdb_byte
**types_list
,
2953 offset_type
*types_list_elements
)
2955 const gdb_byte
*addr
= &buffer
[0];
2957 /* Version check. */
2958 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2959 /* Versions earlier than 3 emitted every copy of a psymbol. This
2960 causes the index to behave very poorly for certain requests. Version 3
2961 contained incomplete addrmap. So, it seems better to just ignore such
2965 static int warning_printed
= 0;
2966 if (!warning_printed
)
2968 warning (_("Skipping obsolete .gdb_index section in %s."),
2970 warning_printed
= 1;
2974 /* Index version 4 uses a different hash function than index version
2977 Versions earlier than 6 did not emit psymbols for inlined
2978 functions. Using these files will cause GDB not to be able to
2979 set breakpoints on inlined functions by name, so we ignore these
2980 indices unless the user has done
2981 "set use-deprecated-index-sections on". */
2982 if (version
< 6 && !deprecated_ok
)
2984 static int warning_printed
= 0;
2985 if (!warning_printed
)
2988 Skipping deprecated .gdb_index section in %s.\n\
2989 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2990 to use the section anyway."),
2992 warning_printed
= 1;
2996 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2997 of the TU (for symbols coming from TUs),
2998 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2999 Plus gold-generated indices can have duplicate entries for global symbols,
3000 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3001 These are just performance bugs, and we can't distinguish gdb-generated
3002 indices from gold-generated ones, so issue no warning here. */
3004 /* Indexes with higher version than the one supported by GDB may be no
3005 longer backward compatible. */
3009 map
->version
= version
;
3011 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3014 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3015 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3019 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3020 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3021 - MAYBE_SWAP (metadata
[i
]))
3025 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3026 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3028 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3031 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3032 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3034 = gdb::array_view
<mapped_index::symbol_table_slot
>
3035 ((mapped_index::symbol_table_slot
*) symbol_table
,
3036 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3039 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3044 /* Callback types for dwarf2_read_gdb_index. */
3046 typedef gdb::function_view
3047 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3048 get_gdb_index_contents_ftype
;
3049 typedef gdb::function_view
3050 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3051 get_gdb_index_contents_dwz_ftype
;
3053 /* Read .gdb_index. If everything went ok, initialize the "quick"
3054 elements of all the CUs and return 1. Otherwise, return 0. */
3057 dwarf2_read_gdb_index
3058 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3059 get_gdb_index_contents_ftype get_gdb_index_contents
,
3060 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3062 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3063 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3064 struct dwz_file
*dwz
;
3065 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3067 gdb::array_view
<const gdb_byte
> main_index_contents
3068 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
->per_bfd
);
3070 if (main_index_contents
.empty ())
3073 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3074 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3075 use_deprecated_index_sections
,
3076 main_index_contents
, map
.get (), &cu_list
,
3077 &cu_list_elements
, &types_list
,
3078 &types_list_elements
))
3081 /* Don't use the index if it's empty. */
3082 if (map
->symbol_table
.empty ())
3085 /* If there is a .dwz file, read it so we can get its CU list as
3087 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
3090 struct mapped_index dwz_map
;
3091 const gdb_byte
*dwz_types_ignore
;
3092 offset_type dwz_types_elements_ignore
;
3094 gdb::array_view
<const gdb_byte
> dwz_index_content
3095 = get_gdb_index_contents_dwz (objfile
, dwz
);
3097 if (dwz_index_content
.empty ())
3100 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3101 1, dwz_index_content
, &dwz_map
,
3102 &dwz_list
, &dwz_list_elements
,
3104 &dwz_types_elements_ignore
))
3106 warning (_("could not read '.gdb_index' section from %s; skipping"),
3107 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3112 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3113 dwz_list
, dwz_list_elements
);
3115 if (types_list_elements
)
3117 /* We can only handle a single .debug_types when we have an
3119 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
3122 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
3124 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3125 types_list
, types_list_elements
);
3128 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3130 dwarf2_per_objfile
->per_bfd
->index_table
= std::move (map
);
3131 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
3132 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
3133 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
3138 /* die_reader_func for dw2_get_file_names. */
3141 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3142 const gdb_byte
*info_ptr
,
3143 struct die_info
*comp_unit_die
)
3145 struct dwarf2_cu
*cu
= reader
->cu
;
3146 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3147 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
3148 struct dwarf2_per_cu_data
*lh_cu
;
3149 struct attribute
*attr
;
3151 struct quick_file_names
*qfn
;
3153 gdb_assert (! this_cu
->is_debug_types
);
3155 /* Our callers never want to match partial units -- instead they
3156 will match the enclosing full CU. */
3157 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3159 this_cu
->v
.quick
->no_file_data
= 1;
3167 sect_offset line_offset
{};
3169 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3170 if (attr
!= nullptr)
3172 struct quick_file_names find_entry
;
3174 line_offset
= (sect_offset
) DW_UNSND (attr
);
3176 /* We may have already read in this line header (TU line header sharing).
3177 If we have we're done. */
3178 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3179 find_entry
.hash
.line_sect_off
= line_offset
;
3180 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3181 &find_entry
, INSERT
);
3184 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3188 lh
= dwarf_decode_line_header (line_offset
, cu
);
3192 lh_cu
->v
.quick
->no_file_data
= 1;
3196 qfn
= XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3197 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3198 qfn
->hash
.line_sect_off
= line_offset
;
3199 gdb_assert (slot
!= NULL
);
3202 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3205 if (strcmp (fnd
.name
, "<unknown>") != 0)
3208 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3210 XOBNEWVEC (&dwarf2_per_objfile
->per_bfd
->obstack
, const char *,
3211 qfn
->num_file_names
);
3213 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3214 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3215 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3216 fnd
.comp_dir
).release ();
3217 qfn
->real_names
= NULL
;
3219 lh_cu
->v
.quick
->file_names
= qfn
;
3222 /* A helper for the "quick" functions which attempts to read the line
3223 table for THIS_CU. */
3225 static struct quick_file_names
*
3226 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3227 dwarf2_per_objfile
*per_objfile
)
3229 /* This should never be called for TUs. */
3230 gdb_assert (! this_cu
->is_debug_types
);
3231 /* Nor type unit groups. */
3232 gdb_assert (! this_cu
->type_unit_group_p ());
3234 if (this_cu
->v
.quick
->file_names
!= NULL
)
3235 return this_cu
->v
.quick
->file_names
;
3236 /* If we know there is no line data, no point in looking again. */
3237 if (this_cu
->v
.quick
->no_file_data
)
3240 cutu_reader
reader (this_cu
, per_objfile
);
3241 if (!reader
.dummy_p
)
3242 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3244 if (this_cu
->v
.quick
->no_file_data
)
3246 return this_cu
->v
.quick
->file_names
;
3249 /* A helper for the "quick" functions which computes and caches the
3250 real path for a given file name from the line table. */
3253 dw2_get_real_path (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3254 struct quick_file_names
*qfn
, int index
)
3256 if (qfn
->real_names
== NULL
)
3257 qfn
->real_names
= OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
3258 qfn
->num_file_names
, const char *);
3260 if (qfn
->real_names
[index
] == NULL
)
3261 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3263 return qfn
->real_names
[index
];
3266 static struct symtab
*
3267 dw2_find_last_source_symtab (struct objfile
*objfile
)
3269 struct dwarf2_per_objfile
*dwarf2_per_objfile
3270 = get_dwarf2_per_objfile (objfile
);
3271 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->per_bfd
->all_comp_units
.back ();
3272 compunit_symtab
*cust
3273 = dw2_instantiate_symtab (dwarf_cu
, dwarf2_per_objfile
, false);
3278 return compunit_primary_filetab (cust
);
3281 /* Traversal function for dw2_forget_cached_source_info. */
3284 dw2_free_cached_file_names (void **slot
, void *info
)
3286 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3288 if (file_data
->real_names
)
3292 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3294 xfree ((void*) file_data
->real_names
[i
]);
3295 file_data
->real_names
[i
] = NULL
;
3303 dw2_forget_cached_source_info (struct objfile
*objfile
)
3305 struct dwarf2_per_objfile
*dwarf2_per_objfile
3306 = get_dwarf2_per_objfile (objfile
);
3308 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3309 dw2_free_cached_file_names
, NULL
);
3312 /* Helper function for dw2_map_symtabs_matching_filename that expands
3313 the symtabs and calls the iterator. */
3316 dw2_map_expand_apply (struct objfile
*objfile
,
3317 struct dwarf2_per_cu_data
*per_cu
,
3318 const char *name
, const char *real_path
,
3319 gdb::function_view
<bool (symtab
*)> callback
)
3321 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3323 /* Don't visit already-expanded CUs. */
3324 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3325 if (per_objfile
->symtab_set_p (per_cu
))
3328 /* This may expand more than one symtab, and we want to iterate over
3330 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3332 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3333 last_made
, callback
);
3336 /* Implementation of the map_symtabs_matching_filename method. */
3339 dw2_map_symtabs_matching_filename
3340 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3341 gdb::function_view
<bool (symtab
*)> callback
)
3343 const char *name_basename
= lbasename (name
);
3344 struct dwarf2_per_objfile
*dwarf2_per_objfile
3345 = get_dwarf2_per_objfile (objfile
);
3347 /* The rule is CUs specify all the files, including those used by
3348 any TU, so there's no need to scan TUs here. */
3350 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3352 /* We only need to look at symtabs not already expanded. */
3353 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3356 quick_file_names
*file_data
3357 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3358 if (file_data
== NULL
)
3361 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3363 const char *this_name
= file_data
->file_names
[j
];
3364 const char *this_real_name
;
3366 if (compare_filenames_for_search (this_name
, name
))
3368 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3374 /* Before we invoke realpath, which can get expensive when many
3375 files are involved, do a quick comparison of the basenames. */
3376 if (! basenames_may_differ
3377 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3380 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
3382 if (compare_filenames_for_search (this_real_name
, name
))
3384 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3390 if (real_path
!= NULL
)
3392 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3393 gdb_assert (IS_ABSOLUTE_PATH (name
));
3394 if (this_real_name
!= NULL
3395 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3397 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3409 /* Struct used to manage iterating over all CUs looking for a symbol. */
3411 struct dw2_symtab_iterator
3413 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3414 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3415 /* If set, only look for symbols that match that block. Valid values are
3416 GLOBAL_BLOCK and STATIC_BLOCK. */
3417 gdb::optional
<block_enum
> block_index
;
3418 /* The kind of symbol we're looking for. */
3420 /* The list of CUs from the index entry of the symbol,
3421 or NULL if not found. */
3423 /* The next element in VEC to look at. */
3425 /* The number of elements in VEC, or zero if there is no match. */
3427 /* Have we seen a global version of the symbol?
3428 If so we can ignore all further global instances.
3429 This is to work around gold/15646, inefficient gold-generated
3434 /* Initialize the index symtab iterator ITER. */
3437 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3438 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3439 gdb::optional
<block_enum
> block_index
,
3443 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3444 iter
->block_index
= block_index
;
3445 iter
->domain
= domain
;
3447 iter
->global_seen
= 0;
3449 mapped_index
*index
= dwarf2_per_objfile
->per_bfd
->index_table
.get ();
3451 /* index is NULL if OBJF_READNOW. */
3452 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3453 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3461 /* Return the next matching CU or NULL if there are no more. */
3463 static struct dwarf2_per_cu_data
*
3464 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3466 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3468 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3470 offset_type cu_index_and_attrs
=
3471 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3472 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3473 gdb_index_symbol_kind symbol_kind
=
3474 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3475 /* Only check the symbol attributes if they're present.
3476 Indices prior to version 7 don't record them,
3477 and indices >= 7 may elide them for certain symbols
3478 (gold does this). */
3480 (dwarf2_per_objfile
->per_bfd
->index_table
->version
>= 7
3481 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3483 /* Don't crash on bad data. */
3484 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3485 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
3487 complaint (_(".gdb_index entry has bad CU index"
3489 objfile_name (dwarf2_per_objfile
->objfile
));
3493 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
3495 /* Skip if already read in. */
3496 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3499 /* Check static vs global. */
3502 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3504 if (iter
->block_index
.has_value ())
3506 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3508 if (is_static
!= want_static
)
3512 /* Work around gold/15646. */
3513 if (!is_static
&& iter
->global_seen
)
3516 iter
->global_seen
= 1;
3519 /* Only check the symbol's kind if it has one. */
3522 switch (iter
->domain
)
3525 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3526 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3527 /* Some types are also in VAR_DOMAIN. */
3528 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3532 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3536 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3540 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3555 static struct compunit_symtab
*
3556 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3557 const char *name
, domain_enum domain
)
3559 struct compunit_symtab
*stab_best
= NULL
;
3560 struct dwarf2_per_objfile
*dwarf2_per_objfile
3561 = get_dwarf2_per_objfile (objfile
);
3563 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3565 struct dw2_symtab_iterator iter
;
3566 struct dwarf2_per_cu_data
*per_cu
;
3568 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3570 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3572 struct symbol
*sym
, *with_opaque
= NULL
;
3573 struct compunit_symtab
*stab
3574 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3575 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3576 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3578 sym
= block_find_symbol (block
, name
, domain
,
3579 block_find_non_opaque_type_preferred
,
3582 /* Some caution must be observed with overloaded functions
3583 and methods, since the index will not contain any overload
3584 information (but NAME might contain it). */
3587 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3589 if (with_opaque
!= NULL
3590 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3593 /* Keep looking through other CUs. */
3600 dw2_print_stats (struct objfile
*objfile
)
3602 struct dwarf2_per_objfile
*dwarf2_per_objfile
3603 = get_dwarf2_per_objfile (objfile
);
3604 int total
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3605 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3608 for (int i
= 0; i
< total
; ++i
)
3610 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3612 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
3615 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3616 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3619 /* This dumps minimal information about the index.
3620 It is called via "mt print objfiles".
3621 One use is to verify .gdb_index has been loaded by the
3622 gdb.dwarf2/gdb-index.exp testcase. */
3625 dw2_dump (struct objfile
*objfile
)
3627 struct dwarf2_per_objfile
*dwarf2_per_objfile
3628 = get_dwarf2_per_objfile (objfile
);
3630 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
3631 printf_filtered (".gdb_index:");
3632 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
)
3634 printf_filtered (" version %d\n",
3635 dwarf2_per_objfile
->per_bfd
->index_table
->version
);
3638 printf_filtered (" faked for \"readnow\"\n");
3639 printf_filtered ("\n");
3643 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3644 const char *func_name
)
3646 struct dwarf2_per_objfile
*dwarf2_per_objfile
3647 = get_dwarf2_per_objfile (objfile
);
3649 struct dw2_symtab_iterator iter
;
3650 struct dwarf2_per_cu_data
*per_cu
;
3652 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3654 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3655 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3660 dw2_expand_all_symtabs (struct objfile
*objfile
)
3662 struct dwarf2_per_objfile
*dwarf2_per_objfile
3663 = get_dwarf2_per_objfile (objfile
);
3664 int total_units
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3665 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3667 for (int i
= 0; i
< total_units
; ++i
)
3669 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3671 /* We don't want to directly expand a partial CU, because if we
3672 read it with the wrong language, then assertion failures can
3673 be triggered later on. See PR symtab/23010. So, tell
3674 dw2_instantiate_symtab to skip partial CUs -- any important
3675 partial CU will be read via DW_TAG_imported_unit anyway. */
3676 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, true);
3681 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3682 const char *fullname
)
3684 struct dwarf2_per_objfile
*dwarf2_per_objfile
3685 = get_dwarf2_per_objfile (objfile
);
3687 /* We don't need to consider type units here.
3688 This is only called for examining code, e.g. expand_line_sal.
3689 There can be an order of magnitude (or more) more type units
3690 than comp units, and we avoid them if we can. */
3692 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3694 /* We only need to look at symtabs not already expanded. */
3695 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3698 quick_file_names
*file_data
3699 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3700 if (file_data
== NULL
)
3703 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3705 const char *this_fullname
= file_data
->file_names
[j
];
3707 if (filename_cmp (this_fullname
, fullname
) == 0)
3709 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3717 dw2_expand_symtabs_matching_symbol
3718 (mapped_index_base
&index
,
3719 const lookup_name_info
&lookup_name_in
,
3720 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3721 enum search_domain kind
,
3722 gdb::function_view
<bool (offset_type
)> match_callback
);
3725 dw2_expand_symtabs_matching_one
3726 (dwarf2_per_cu_data
*per_cu
,
3727 dwarf2_per_objfile
*per_objfile
,
3728 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3729 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3732 dw2_map_matching_symbols
3733 (struct objfile
*objfile
,
3734 const lookup_name_info
&name
, domain_enum domain
,
3736 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3737 symbol_compare_ftype
*ordered_compare
)
3740 struct dwarf2_per_objfile
*dwarf2_per_objfile
3741 = get_dwarf2_per_objfile (objfile
);
3743 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3745 if (dwarf2_per_objfile
->per_bfd
->index_table
!= nullptr)
3747 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3748 here though if the current language is Ada for a non-Ada objfile
3750 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
3752 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3753 auto matcher
= [&] (const char *symname
)
3755 if (ordered_compare
== nullptr)
3757 return ordered_compare (symname
, match_name
) == 0;
3760 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3761 [&] (offset_type namei
)
3763 struct dw2_symtab_iterator iter
;
3764 struct dwarf2_per_cu_data
*per_cu
;
3766 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_kind
, domain
,
3768 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3769 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
3776 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3777 proceed assuming all symtabs have been read in. */
3780 for (compunit_symtab
*cust
: objfile
->compunits ())
3782 const struct block
*block
;
3786 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3787 if (!iterate_over_symbols_terminated (block
, name
,
3793 /* Starting from a search name, return the string that finds the upper
3794 bound of all strings that start with SEARCH_NAME in a sorted name
3795 list. Returns the empty string to indicate that the upper bound is
3796 the end of the list. */
3799 make_sort_after_prefix_name (const char *search_name
)
3801 /* When looking to complete "func", we find the upper bound of all
3802 symbols that start with "func" by looking for where we'd insert
3803 the closest string that would follow "func" in lexicographical
3804 order. Usually, that's "func"-with-last-character-incremented,
3805 i.e. "fund". Mind non-ASCII characters, though. Usually those
3806 will be UTF-8 multi-byte sequences, but we can't be certain.
3807 Especially mind the 0xff character, which is a valid character in
3808 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3809 rule out compilers allowing it in identifiers. Note that
3810 conveniently, strcmp/strcasecmp are specified to compare
3811 characters interpreted as unsigned char. So what we do is treat
3812 the whole string as a base 256 number composed of a sequence of
3813 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3814 to 0, and carries 1 to the following more-significant position.
3815 If the very first character in SEARCH_NAME ends up incremented
3816 and carries/overflows, then the upper bound is the end of the
3817 list. The string after the empty string is also the empty
3820 Some examples of this operation:
3822 SEARCH_NAME => "+1" RESULT
3826 "\xff" "a" "\xff" => "\xff" "b"
3831 Then, with these symbols for example:
3837 completing "func" looks for symbols between "func" and
3838 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3839 which finds "func" and "func1", but not "fund".
3843 funcÿ (Latin1 'ÿ' [0xff])
3847 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3848 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3852 ÿÿ (Latin1 'ÿ' [0xff])
3855 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3856 the end of the list.
3858 std::string after
= search_name
;
3859 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3861 if (!after
.empty ())
3862 after
.back () = (unsigned char) after
.back () + 1;
3866 /* See declaration. */
3868 std::pair
<std::vector
<name_component
>::const_iterator
,
3869 std::vector
<name_component
>::const_iterator
>
3870 mapped_index_base::find_name_components_bounds
3871 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3874 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3876 const char *lang_name
3877 = lookup_name_without_params
.language_lookup_name (lang
);
3879 /* Comparison function object for lower_bound that matches against a
3880 given symbol name. */
3881 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3884 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3885 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3886 return name_cmp (elem_name
, name
) < 0;
3889 /* Comparison function object for upper_bound that matches against a
3890 given symbol name. */
3891 auto lookup_compare_upper
= [&] (const char *name
,
3892 const name_component
&elem
)
3894 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3895 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3896 return name_cmp (name
, elem_name
) < 0;
3899 auto begin
= this->name_components
.begin ();
3900 auto end
= this->name_components
.end ();
3902 /* Find the lower bound. */
3905 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3908 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3911 /* Find the upper bound. */
3914 if (lookup_name_without_params
.completion_mode ())
3916 /* In completion mode, we want UPPER to point past all
3917 symbols names that have the same prefix. I.e., with
3918 these symbols, and completing "func":
3920 function << lower bound
3922 other_function << upper bound
3924 We find the upper bound by looking for the insertion
3925 point of "func"-with-last-character-incremented,
3927 std::string after
= make_sort_after_prefix_name (lang_name
);
3930 return std::lower_bound (lower
, end
, after
.c_str (),
3931 lookup_compare_lower
);
3934 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3937 return {lower
, upper
};
3940 /* See declaration. */
3943 mapped_index_base::build_name_components ()
3945 if (!this->name_components
.empty ())
3948 this->name_components_casing
= case_sensitivity
;
3950 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3952 /* The code below only knows how to break apart components of C++
3953 symbol names (and other languages that use '::' as
3954 namespace/module separator) and Ada symbol names. */
3955 auto count
= this->symbol_name_count ();
3956 for (offset_type idx
= 0; idx
< count
; idx
++)
3958 if (this->symbol_name_slot_invalid (idx
))
3961 const char *name
= this->symbol_name_at (idx
);
3963 /* Add each name component to the name component table. */
3964 unsigned int previous_len
= 0;
3966 if (strstr (name
, "::") != nullptr)
3968 for (unsigned int current_len
= cp_find_first_component (name
);
3969 name
[current_len
] != '\0';
3970 current_len
+= cp_find_first_component (name
+ current_len
))
3972 gdb_assert (name
[current_len
] == ':');
3973 this->name_components
.push_back ({previous_len
, idx
});
3974 /* Skip the '::'. */
3976 previous_len
= current_len
;
3981 /* Handle the Ada encoded (aka mangled) form here. */
3982 for (const char *iter
= strstr (name
, "__");
3984 iter
= strstr (iter
, "__"))
3986 this->name_components
.push_back ({previous_len
, idx
});
3988 previous_len
= iter
- name
;
3992 this->name_components
.push_back ({previous_len
, idx
});
3995 /* Sort name_components elements by name. */
3996 auto name_comp_compare
= [&] (const name_component
&left
,
3997 const name_component
&right
)
3999 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4000 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4002 const char *left_name
= left_qualified
+ left
.name_offset
;
4003 const char *right_name
= right_qualified
+ right
.name_offset
;
4005 return name_cmp (left_name
, right_name
) < 0;
4008 std::sort (this->name_components
.begin (),
4009 this->name_components
.end (),
4013 /* Helper for dw2_expand_symtabs_matching that works with a
4014 mapped_index_base instead of the containing objfile. This is split
4015 to a separate function in order to be able to unit test the
4016 name_components matching using a mock mapped_index_base. For each
4017 symbol name that matches, calls MATCH_CALLBACK, passing it the
4018 symbol's index in the mapped_index_base symbol table. */
4021 dw2_expand_symtabs_matching_symbol
4022 (mapped_index_base
&index
,
4023 const lookup_name_info
&lookup_name_in
,
4024 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4025 enum search_domain kind
,
4026 gdb::function_view
<bool (offset_type
)> match_callback
)
4028 lookup_name_info lookup_name_without_params
4029 = lookup_name_in
.make_ignore_params ();
4031 /* Build the symbol name component sorted vector, if we haven't
4033 index
.build_name_components ();
4035 /* The same symbol may appear more than once in the range though.
4036 E.g., if we're looking for symbols that complete "w", and we have
4037 a symbol named "w1::w2", we'll find the two name components for
4038 that same symbol in the range. To be sure we only call the
4039 callback once per symbol, we first collect the symbol name
4040 indexes that matched in a temporary vector and ignore
4042 std::vector
<offset_type
> matches
;
4044 struct name_and_matcher
4046 symbol_name_matcher_ftype
*matcher
;
4049 bool operator== (const name_and_matcher
&other
) const
4051 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4055 /* A vector holding all the different symbol name matchers, for all
4057 std::vector
<name_and_matcher
> matchers
;
4059 for (int i
= 0; i
< nr_languages
; i
++)
4061 enum language lang_e
= (enum language
) i
;
4063 const language_defn
*lang
= language_def (lang_e
);
4064 symbol_name_matcher_ftype
*name_matcher
4065 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4067 name_and_matcher key
{
4069 lookup_name_without_params
.language_lookup_name (lang_e
)
4072 /* Don't insert the same comparison routine more than once.
4073 Note that we do this linear walk. This is not a problem in
4074 practice because the number of supported languages is
4076 if (std::find (matchers
.begin (), matchers
.end (), key
)
4079 matchers
.push_back (std::move (key
));
4082 = index
.find_name_components_bounds (lookup_name_without_params
,
4085 /* Now for each symbol name in range, check to see if we have a name
4086 match, and if so, call the MATCH_CALLBACK callback. */
4088 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4090 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4092 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4093 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4096 matches
.push_back (bounds
.first
->idx
);
4100 std::sort (matches
.begin (), matches
.end ());
4102 /* Finally call the callback, once per match. */
4104 for (offset_type idx
: matches
)
4108 if (!match_callback (idx
))
4114 /* Above we use a type wider than idx's for 'prev', since 0 and
4115 (offset_type)-1 are both possible values. */
4116 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4121 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4123 /* A mock .gdb_index/.debug_names-like name index table, enough to
4124 exercise dw2_expand_symtabs_matching_symbol, which works with the
4125 mapped_index_base interface. Builds an index from the symbol list
4126 passed as parameter to the constructor. */
4127 class mock_mapped_index
: public mapped_index_base
4130 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4131 : m_symbol_table (symbols
)
4134 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4136 /* Return the number of names in the symbol table. */
4137 size_t symbol_name_count () const override
4139 return m_symbol_table
.size ();
4142 /* Get the name of the symbol at IDX in the symbol table. */
4143 const char *symbol_name_at (offset_type idx
) const override
4145 return m_symbol_table
[idx
];
4149 gdb::array_view
<const char *> m_symbol_table
;
4152 /* Convenience function that converts a NULL pointer to a "<null>"
4153 string, to pass to print routines. */
4156 string_or_null (const char *str
)
4158 return str
!= NULL
? str
: "<null>";
4161 /* Check if a lookup_name_info built from
4162 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4163 index. EXPECTED_LIST is the list of expected matches, in expected
4164 matching order. If no match expected, then an empty list is
4165 specified. Returns true on success. On failure prints a warning
4166 indicating the file:line that failed, and returns false. */
4169 check_match (const char *file
, int line
,
4170 mock_mapped_index
&mock_index
,
4171 const char *name
, symbol_name_match_type match_type
,
4172 bool completion_mode
,
4173 std::initializer_list
<const char *> expected_list
)
4175 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4177 bool matched
= true;
4179 auto mismatch
= [&] (const char *expected_str
,
4182 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4183 "expected=\"%s\", got=\"%s\"\n"),
4185 (match_type
== symbol_name_match_type::FULL
4187 name
, string_or_null (expected_str
), string_or_null (got
));
4191 auto expected_it
= expected_list
.begin ();
4192 auto expected_end
= expected_list
.end ();
4194 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4196 [&] (offset_type idx
)
4198 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4199 const char *expected_str
4200 = expected_it
== expected_end
? NULL
: *expected_it
++;
4202 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4203 mismatch (expected_str
, matched_name
);
4207 const char *expected_str
4208 = expected_it
== expected_end
? NULL
: *expected_it
++;
4209 if (expected_str
!= NULL
)
4210 mismatch (expected_str
, NULL
);
4215 /* The symbols added to the mock mapped_index for testing (in
4217 static const char *test_symbols
[] = {
4226 "ns2::tmpl<int>::foo2",
4227 "(anonymous namespace)::A::B::C",
4229 /* These are used to check that the increment-last-char in the
4230 matching algorithm for completion doesn't match "t1_fund" when
4231 completing "t1_func". */
4237 /* A UTF-8 name with multi-byte sequences to make sure that
4238 cp-name-parser understands this as a single identifier ("função"
4239 is "function" in PT). */
4242 /* \377 (0xff) is Latin1 'ÿ'. */
4245 /* \377 (0xff) is Latin1 'ÿ'. */
4249 /* A name with all sorts of complications. Starts with "z" to make
4250 it easier for the completion tests below. */
4251 #define Z_SYM_NAME \
4252 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4253 "::tuple<(anonymous namespace)::ui*, " \
4254 "std::default_delete<(anonymous namespace)::ui>, void>"
4259 /* Returns true if the mapped_index_base::find_name_component_bounds
4260 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4261 in completion mode. */
4264 check_find_bounds_finds (mapped_index_base
&index
,
4265 const char *search_name
,
4266 gdb::array_view
<const char *> expected_syms
)
4268 lookup_name_info
lookup_name (search_name
,
4269 symbol_name_match_type::FULL
, true);
4271 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4274 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4275 if (distance
!= expected_syms
.size ())
4278 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4280 auto nc_elem
= bounds
.first
+ exp_elem
;
4281 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4282 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4289 /* Test the lower-level mapped_index::find_name_component_bounds
4293 test_mapped_index_find_name_component_bounds ()
4295 mock_mapped_index
mock_index (test_symbols
);
4297 mock_index
.build_name_components ();
4299 /* Test the lower-level mapped_index::find_name_component_bounds
4300 method in completion mode. */
4302 static const char *expected_syms
[] = {
4307 SELF_CHECK (check_find_bounds_finds (mock_index
,
4308 "t1_func", expected_syms
));
4311 /* Check that the increment-last-char in the name matching algorithm
4312 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4314 static const char *expected_syms1
[] = {
4318 SELF_CHECK (check_find_bounds_finds (mock_index
,
4319 "\377", expected_syms1
));
4321 static const char *expected_syms2
[] = {
4324 SELF_CHECK (check_find_bounds_finds (mock_index
,
4325 "\377\377", expected_syms2
));
4329 /* Test dw2_expand_symtabs_matching_symbol. */
4332 test_dw2_expand_symtabs_matching_symbol ()
4334 mock_mapped_index
mock_index (test_symbols
);
4336 /* We let all tests run until the end even if some fails, for debug
4338 bool any_mismatch
= false;
4340 /* Create the expected symbols list (an initializer_list). Needed
4341 because lists have commas, and we need to pass them to CHECK,
4342 which is a macro. */
4343 #define EXPECT(...) { __VA_ARGS__ }
4345 /* Wrapper for check_match that passes down the current
4346 __FILE__/__LINE__. */
4347 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4348 any_mismatch |= !check_match (__FILE__, __LINE__, \
4350 NAME, MATCH_TYPE, COMPLETION_MODE, \
4353 /* Identity checks. */
4354 for (const char *sym
: test_symbols
)
4356 /* Should be able to match all existing symbols. */
4357 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4360 /* Should be able to match all existing symbols with
4362 std::string with_params
= std::string (sym
) + "(int)";
4363 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4366 /* Should be able to match all existing symbols with
4367 parameters and qualifiers. */
4368 with_params
= std::string (sym
) + " ( int ) const";
4369 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4372 /* This should really find sym, but cp-name-parser.y doesn't
4373 know about lvalue/rvalue qualifiers yet. */
4374 with_params
= std::string (sym
) + " ( int ) &&";
4375 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4379 /* Check that the name matching algorithm for completion doesn't get
4380 confused with Latin1 'ÿ' / 0xff. */
4382 static const char str
[] = "\377";
4383 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4384 EXPECT ("\377", "\377\377123"));
4387 /* Check that the increment-last-char in the matching algorithm for
4388 completion doesn't match "t1_fund" when completing "t1_func". */
4390 static const char str
[] = "t1_func";
4391 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4392 EXPECT ("t1_func", "t1_func1"));
4395 /* Check that completion mode works at each prefix of the expected
4398 static const char str
[] = "function(int)";
4399 size_t len
= strlen (str
);
4402 for (size_t i
= 1; i
< len
; i
++)
4404 lookup
.assign (str
, i
);
4405 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4406 EXPECT ("function"));
4410 /* While "w" is a prefix of both components, the match function
4411 should still only be called once. */
4413 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4415 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4419 /* Same, with a "complicated" symbol. */
4421 static const char str
[] = Z_SYM_NAME
;
4422 size_t len
= strlen (str
);
4425 for (size_t i
= 1; i
< len
; i
++)
4427 lookup
.assign (str
, i
);
4428 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4429 EXPECT (Z_SYM_NAME
));
4433 /* In FULL mode, an incomplete symbol doesn't match. */
4435 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4439 /* A complete symbol with parameters matches any overload, since the
4440 index has no overload info. */
4442 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4443 EXPECT ("std::zfunction", "std::zfunction2"));
4444 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4445 EXPECT ("std::zfunction", "std::zfunction2"));
4446 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4447 EXPECT ("std::zfunction", "std::zfunction2"));
4450 /* Check that whitespace is ignored appropriately. A symbol with a
4451 template argument list. */
4453 static const char expected
[] = "ns::foo<int>";
4454 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4456 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4460 /* Check that whitespace is ignored appropriately. A symbol with a
4461 template argument list that includes a pointer. */
4463 static const char expected
[] = "ns::foo<char*>";
4464 /* Try both completion and non-completion modes. */
4465 static const bool completion_mode
[2] = {false, true};
4466 for (size_t i
= 0; i
< 2; i
++)
4468 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4469 completion_mode
[i
], EXPECT (expected
));
4470 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4471 completion_mode
[i
], EXPECT (expected
));
4473 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4474 completion_mode
[i
], EXPECT (expected
));
4475 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4476 completion_mode
[i
], EXPECT (expected
));
4481 /* Check method qualifiers are ignored. */
4482 static const char expected
[] = "ns::foo<char*>";
4483 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4484 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4485 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4486 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4487 CHECK_MATCH ("foo < char * > ( int ) const",
4488 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4489 CHECK_MATCH ("foo < char * > ( int ) &&",
4490 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4493 /* Test lookup names that don't match anything. */
4495 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4498 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4502 /* Some wild matching tests, exercising "(anonymous namespace)",
4503 which should not be confused with a parameter list. */
4505 static const char *syms
[] = {
4509 "A :: B :: C ( int )",
4514 for (const char *s
: syms
)
4516 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4517 EXPECT ("(anonymous namespace)::A::B::C"));
4522 static const char expected
[] = "ns2::tmpl<int>::foo2";
4523 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4525 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4529 SELF_CHECK (!any_mismatch
);
4538 test_mapped_index_find_name_component_bounds ();
4539 test_dw2_expand_symtabs_matching_symbol ();
4542 }} // namespace selftests::dw2_expand_symtabs_matching
4544 #endif /* GDB_SELF_TEST */
4546 /* If FILE_MATCHER is NULL or if PER_CU has
4547 dwarf2_per_cu_quick_data::MARK set (see
4548 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4549 EXPANSION_NOTIFY on it. */
4552 dw2_expand_symtabs_matching_one
4553 (dwarf2_per_cu_data
*per_cu
,
4554 dwarf2_per_objfile
*per_objfile
,
4555 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4556 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4558 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4560 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4562 compunit_symtab
*symtab
4563 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4564 gdb_assert (symtab
!= nullptr);
4566 if (expansion_notify
!= NULL
&& symtab_was_null
)
4567 expansion_notify (symtab
);
4571 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4572 matched, to expand corresponding CUs that were marked. IDX is the
4573 index of the symbol name that matched. */
4576 dw2_expand_marked_cus
4577 (dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4578 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4579 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4582 offset_type
*vec
, vec_len
, vec_idx
;
4583 bool global_seen
= false;
4584 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4586 vec
= (offset_type
*) (index
.constant_pool
4587 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4588 vec_len
= MAYBE_SWAP (vec
[0]);
4589 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4591 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4592 /* This value is only valid for index versions >= 7. */
4593 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4594 gdb_index_symbol_kind symbol_kind
=
4595 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4596 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4597 /* Only check the symbol attributes if they're present.
4598 Indices prior to version 7 don't record them,
4599 and indices >= 7 may elide them for certain symbols
4600 (gold does this). */
4603 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4605 /* Work around gold/15646. */
4608 if (!is_static
&& global_seen
)
4614 /* Only check the symbol's kind if it has one. */
4619 case VARIABLES_DOMAIN
:
4620 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4623 case FUNCTIONS_DOMAIN
:
4624 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4628 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4631 case MODULES_DOMAIN
:
4632 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4640 /* Don't crash on bad data. */
4641 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
4642 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
4644 complaint (_(".gdb_index entry has bad CU index"
4646 objfile_name (dwarf2_per_objfile
->objfile
));
4650 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
4651 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, file_matcher
,
4656 /* If FILE_MATCHER is non-NULL, set all the
4657 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4658 that match FILE_MATCHER. */
4661 dw_expand_symtabs_matching_file_matcher
4662 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4663 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4665 if (file_matcher
== NULL
)
4668 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4670 NULL
, xcalloc
, xfree
));
4671 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4673 NULL
, xcalloc
, xfree
));
4675 /* The rule is CUs specify all the files, including those used by
4676 any TU, so there's no need to scan TUs here. */
4678 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4682 per_cu
->v
.quick
->mark
= 0;
4684 /* We only need to look at symtabs not already expanded. */
4685 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4688 quick_file_names
*file_data
4689 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4690 if (file_data
== NULL
)
4693 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4695 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4697 per_cu
->v
.quick
->mark
= 1;
4701 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4703 const char *this_real_name
;
4705 if (file_matcher (file_data
->file_names
[j
], false))
4707 per_cu
->v
.quick
->mark
= 1;
4711 /* Before we invoke realpath, which can get expensive when many
4712 files are involved, do a quick comparison of the basenames. */
4713 if (!basenames_may_differ
4714 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4718 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
4720 if (file_matcher (this_real_name
, false))
4722 per_cu
->v
.quick
->mark
= 1;
4727 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4728 ? visited_found
.get ()
4729 : visited_not_found
.get (),
4736 dw2_expand_symtabs_matching
4737 (struct objfile
*objfile
,
4738 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4739 const lookup_name_info
*lookup_name
,
4740 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4741 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4742 enum search_domain kind
)
4744 struct dwarf2_per_objfile
*dwarf2_per_objfile
4745 = get_dwarf2_per_objfile (objfile
);
4747 /* index_table is NULL if OBJF_READNOW. */
4748 if (!dwarf2_per_objfile
->per_bfd
->index_table
)
4751 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4753 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4755 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4759 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
4760 file_matcher
, expansion_notify
);
4765 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4767 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4769 kind
, [&] (offset_type idx
)
4771 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4772 expansion_notify
, kind
);
4777 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4780 static struct compunit_symtab
*
4781 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4786 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4787 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4790 if (cust
->includes
== NULL
)
4793 for (i
= 0; cust
->includes
[i
]; ++i
)
4795 struct compunit_symtab
*s
= cust
->includes
[i
];
4797 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4805 static struct compunit_symtab
*
4806 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4807 struct bound_minimal_symbol msymbol
,
4809 struct obj_section
*section
,
4812 struct dwarf2_per_cu_data
*data
;
4813 struct compunit_symtab
*result
;
4815 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4818 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4819 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4820 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4824 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4825 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4826 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4827 paddress (objfile
->arch (), pc
));
4829 result
= recursively_find_pc_sect_compunit_symtab
4830 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4832 gdb_assert (result
!= NULL
);
4837 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4838 void *data
, int need_fullname
)
4840 struct dwarf2_per_objfile
*dwarf2_per_objfile
4841 = get_dwarf2_per_objfile (objfile
);
4843 if (!dwarf2_per_objfile
->per_bfd
->filenames_cache
)
4845 dwarf2_per_objfile
->per_bfd
->filenames_cache
.emplace ();
4847 htab_up
visited (htab_create_alloc (10,
4848 htab_hash_pointer
, htab_eq_pointer
,
4849 NULL
, xcalloc
, xfree
));
4851 /* The rule is CUs specify all the files, including those used
4852 by any TU, so there's no need to scan TUs here. We can
4853 ignore file names coming from already-expanded CUs. */
4855 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4857 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4859 void **slot
= htab_find_slot (visited
.get (),
4860 per_cu
->v
.quick
->file_names
,
4863 *slot
= per_cu
->v
.quick
->file_names
;
4867 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4869 /* We only need to look at symtabs not already expanded. */
4870 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4873 quick_file_names
*file_data
4874 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4875 if (file_data
== NULL
)
4878 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4881 /* Already visited. */
4886 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4888 const char *filename
= file_data
->file_names
[j
];
4889 dwarf2_per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4894 dwarf2_per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4896 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4899 this_real_name
= gdb_realpath (filename
);
4900 (*fun
) (filename
, this_real_name
.get (), data
);
4905 dw2_has_symbols (struct objfile
*objfile
)
4910 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4913 dw2_find_last_source_symtab
,
4914 dw2_forget_cached_source_info
,
4915 dw2_map_symtabs_matching_filename
,
4920 dw2_expand_symtabs_for_function
,
4921 dw2_expand_all_symtabs
,
4922 dw2_expand_symtabs_with_fullname
,
4923 dw2_map_matching_symbols
,
4924 dw2_expand_symtabs_matching
,
4925 dw2_find_pc_sect_compunit_symtab
,
4927 dw2_map_symbol_filenames
4930 /* DWARF-5 debug_names reader. */
4932 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4933 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4935 /* A helper function that reads the .debug_names section in SECTION
4936 and fills in MAP. FILENAME is the name of the file containing the
4937 section; it is used for error reporting.
4939 Returns true if all went well, false otherwise. */
4942 read_debug_names_from_section (struct objfile
*objfile
,
4943 const char *filename
,
4944 struct dwarf2_section_info
*section
,
4945 mapped_debug_names
&map
)
4947 if (section
->empty ())
4950 /* Older elfutils strip versions could keep the section in the main
4951 executable while splitting it for the separate debug info file. */
4952 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4955 section
->read (objfile
);
4957 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4959 const gdb_byte
*addr
= section
->buffer
;
4961 bfd
*const abfd
= section
->get_bfd_owner ();
4963 unsigned int bytes_read
;
4964 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4967 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4968 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4969 if (bytes_read
+ length
!= section
->size
)
4971 /* There may be multiple per-CU indices. */
4972 warning (_("Section .debug_names in %s length %s does not match "
4973 "section length %s, ignoring .debug_names."),
4974 filename
, plongest (bytes_read
+ length
),
4975 pulongest (section
->size
));
4979 /* The version number. */
4980 uint16_t version
= read_2_bytes (abfd
, addr
);
4984 warning (_("Section .debug_names in %s has unsupported version %d, "
4985 "ignoring .debug_names."),
4991 uint16_t padding
= read_2_bytes (abfd
, addr
);
4995 warning (_("Section .debug_names in %s has unsupported padding %d, "
4996 "ignoring .debug_names."),
5001 /* comp_unit_count - The number of CUs in the CU list. */
5002 map
.cu_count
= read_4_bytes (abfd
, addr
);
5005 /* local_type_unit_count - The number of TUs in the local TU
5007 map
.tu_count
= read_4_bytes (abfd
, addr
);
5010 /* foreign_type_unit_count - The number of TUs in the foreign TU
5012 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5014 if (foreign_tu_count
!= 0)
5016 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5017 "ignoring .debug_names."),
5018 filename
, static_cast<unsigned long> (foreign_tu_count
));
5022 /* bucket_count - The number of hash buckets in the hash lookup
5024 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5027 /* name_count - The number of unique names in the index. */
5028 map
.name_count
= read_4_bytes (abfd
, addr
);
5031 /* abbrev_table_size - The size in bytes of the abbreviations
5033 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5036 /* augmentation_string_size - The size in bytes of the augmentation
5037 string. This value is rounded up to a multiple of 4. */
5038 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5040 map
.augmentation_is_gdb
= ((augmentation_string_size
5041 == sizeof (dwarf5_augmentation
))
5042 && memcmp (addr
, dwarf5_augmentation
,
5043 sizeof (dwarf5_augmentation
)) == 0);
5044 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5045 addr
+= augmentation_string_size
;
5048 map
.cu_table_reordered
= addr
;
5049 addr
+= map
.cu_count
* map
.offset_size
;
5051 /* List of Local TUs */
5052 map
.tu_table_reordered
= addr
;
5053 addr
+= map
.tu_count
* map
.offset_size
;
5055 /* Hash Lookup Table */
5056 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5057 addr
+= map
.bucket_count
* 4;
5058 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5059 addr
+= map
.name_count
* 4;
5062 map
.name_table_string_offs_reordered
= addr
;
5063 addr
+= map
.name_count
* map
.offset_size
;
5064 map
.name_table_entry_offs_reordered
= addr
;
5065 addr
+= map
.name_count
* map
.offset_size
;
5067 const gdb_byte
*abbrev_table_start
= addr
;
5070 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5075 const auto insertpair
5076 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5077 if (!insertpair
.second
)
5079 warning (_("Section .debug_names in %s has duplicate index %s, "
5080 "ignoring .debug_names."),
5081 filename
, pulongest (index_num
));
5084 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5085 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5090 mapped_debug_names::index_val::attr attr
;
5091 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5093 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5095 if (attr
.form
== DW_FORM_implicit_const
)
5097 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5101 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5103 indexval
.attr_vec
.push_back (std::move (attr
));
5106 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5108 warning (_("Section .debug_names in %s has abbreviation_table "
5109 "of size %s vs. written as %u, ignoring .debug_names."),
5110 filename
, plongest (addr
- abbrev_table_start
),
5114 map
.entry_pool
= addr
;
5119 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5123 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5124 const mapped_debug_names
&map
,
5125 dwarf2_section_info
§ion
,
5128 if (!map
.augmentation_is_gdb
)
5130 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5132 sect_offset sect_off
5133 = (sect_offset
) (extract_unsigned_integer
5134 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5136 map
.dwarf5_byte_order
));
5137 /* We don't know the length of the CU, because the CU list in a
5138 .debug_names index can be incomplete, so we can't use the start of
5139 the next CU as end of this CU. We create the CUs here with length 0,
5140 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5141 dwarf2_per_cu_data
*per_cu
5142 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5144 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5148 sect_offset sect_off_prev
;
5149 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5151 sect_offset sect_off_next
;
5152 if (i
< map
.cu_count
)
5155 = (sect_offset
) (extract_unsigned_integer
5156 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5158 map
.dwarf5_byte_order
));
5161 sect_off_next
= (sect_offset
) section
.size
;
5164 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5165 dwarf2_per_cu_data
*per_cu
5166 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5167 sect_off_prev
, length
);
5168 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5170 sect_off_prev
= sect_off_next
;
5174 /* Read the CU list from the mapped index, and use it to create all
5175 the CU objects for this dwarf2_per_objfile. */
5178 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5179 const mapped_debug_names
&map
,
5180 const mapped_debug_names
&dwz_map
)
5182 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
5183 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5185 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5186 dwarf2_per_objfile
->per_bfd
->info
,
5187 false /* is_dwz */);
5189 if (dwz_map
.cu_count
== 0)
5192 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
5193 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5197 /* Read .debug_names. If everything went ok, initialize the "quick"
5198 elements of all the CUs and return true. Otherwise, return false. */
5201 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5203 std::unique_ptr
<mapped_debug_names
> map
5204 (new mapped_debug_names (dwarf2_per_objfile
));
5205 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5206 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5208 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5209 &dwarf2_per_objfile
->per_bfd
->debug_names
,
5213 /* Don't use the index if it's empty. */
5214 if (map
->name_count
== 0)
5217 /* If there is a .dwz file, read it so we can get its CU list as
5219 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
5222 if (!read_debug_names_from_section (objfile
,
5223 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5224 &dwz
->debug_names
, dwz_map
))
5226 warning (_("could not read '.debug_names' section from %s; skipping"),
5227 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5232 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5234 if (map
->tu_count
!= 0)
5236 /* We can only handle a single .debug_types when we have an
5238 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
5241 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
5243 create_signatured_type_table_from_debug_names
5244 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->per_bfd
->abbrev
);
5247 create_addrmap_from_aranges (dwarf2_per_objfile
,
5248 &dwarf2_per_objfile
->per_bfd
->debug_aranges
);
5250 dwarf2_per_objfile
->per_bfd
->debug_names_table
= std::move (map
);
5251 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5252 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
5253 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5258 /* Type used to manage iterating over all CUs looking for a symbol for
5261 class dw2_debug_names_iterator
5264 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5265 gdb::optional
<block_enum
> block_index
,
5268 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5269 m_addr (find_vec_in_debug_names (map
, name
))
5272 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5273 search_domain search
, uint32_t namei
)
5276 m_addr (find_vec_in_debug_names (map
, namei
))
5279 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5280 block_enum block_index
, domain_enum domain
,
5282 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5283 m_addr (find_vec_in_debug_names (map
, namei
))
5286 /* Return the next matching CU or NULL if there are no more. */
5287 dwarf2_per_cu_data
*next ();
5290 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5292 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5295 /* The internalized form of .debug_names. */
5296 const mapped_debug_names
&m_map
;
5298 /* If set, only look for symbols that match that block. Valid values are
5299 GLOBAL_BLOCK and STATIC_BLOCK. */
5300 const gdb::optional
<block_enum
> m_block_index
;
5302 /* The kind of symbol we're looking for. */
5303 const domain_enum m_domain
= UNDEF_DOMAIN
;
5304 const search_domain m_search
= ALL_DOMAIN
;
5306 /* The list of CUs from the index entry of the symbol, or NULL if
5308 const gdb_byte
*m_addr
;
5312 mapped_debug_names::namei_to_name (uint32_t namei
) const
5314 const ULONGEST namei_string_offs
5315 = extract_unsigned_integer ((name_table_string_offs_reordered
5316 + namei
* offset_size
),
5319 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5323 /* Find a slot in .debug_names for the object named NAME. If NAME is
5324 found, return pointer to its pool data. If NAME cannot be found,
5328 dw2_debug_names_iterator::find_vec_in_debug_names
5329 (const mapped_debug_names
&map
, const char *name
)
5331 int (*cmp
) (const char *, const char *);
5333 gdb::unique_xmalloc_ptr
<char> without_params
;
5334 if (current_language
->la_language
== language_cplus
5335 || current_language
->la_language
== language_fortran
5336 || current_language
->la_language
== language_d
)
5338 /* NAME is already canonical. Drop any qualifiers as
5339 .debug_names does not contain any. */
5341 if (strchr (name
, '(') != NULL
)
5343 without_params
= cp_remove_params (name
);
5344 if (without_params
!= NULL
)
5345 name
= without_params
.get ();
5349 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5351 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5353 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5354 (map
.bucket_table_reordered
5355 + (full_hash
% map
.bucket_count
)), 4,
5356 map
.dwarf5_byte_order
);
5360 if (namei
>= map
.name_count
)
5362 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5364 namei
, map
.name_count
,
5365 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5371 const uint32_t namei_full_hash
5372 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5373 (map
.hash_table_reordered
+ namei
), 4,
5374 map
.dwarf5_byte_order
);
5375 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5378 if (full_hash
== namei_full_hash
)
5380 const char *const namei_string
= map
.namei_to_name (namei
);
5382 #if 0 /* An expensive sanity check. */
5383 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5385 complaint (_("Wrong .debug_names hash for string at index %u "
5387 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5392 if (cmp (namei_string
, name
) == 0)
5394 const ULONGEST namei_entry_offs
5395 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5396 + namei
* map
.offset_size
),
5397 map
.offset_size
, map
.dwarf5_byte_order
);
5398 return map
.entry_pool
+ namei_entry_offs
;
5403 if (namei
>= map
.name_count
)
5409 dw2_debug_names_iterator::find_vec_in_debug_names
5410 (const mapped_debug_names
&map
, uint32_t namei
)
5412 if (namei
>= map
.name_count
)
5414 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5416 namei
, map
.name_count
,
5417 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5421 const ULONGEST namei_entry_offs
5422 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5423 + namei
* map
.offset_size
),
5424 map
.offset_size
, map
.dwarf5_byte_order
);
5425 return map
.entry_pool
+ namei_entry_offs
;
5428 /* See dw2_debug_names_iterator. */
5430 dwarf2_per_cu_data
*
5431 dw2_debug_names_iterator::next ()
5436 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5437 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5438 bfd
*const abfd
= objfile
->obfd
;
5442 unsigned int bytes_read
;
5443 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5444 m_addr
+= bytes_read
;
5448 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5449 if (indexval_it
== m_map
.abbrev_map
.cend ())
5451 complaint (_("Wrong .debug_names undefined abbrev code %s "
5453 pulongest (abbrev
), objfile_name (objfile
));
5456 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5457 enum class symbol_linkage
{
5461 } symbol_linkage_
= symbol_linkage::unknown
;
5462 dwarf2_per_cu_data
*per_cu
= NULL
;
5463 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5468 case DW_FORM_implicit_const
:
5469 ull
= attr
.implicit_const
;
5471 case DW_FORM_flag_present
:
5475 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5476 m_addr
+= bytes_read
;
5479 ull
= read_4_bytes (abfd
, m_addr
);
5483 ull
= read_8_bytes (abfd
, m_addr
);
5486 case DW_FORM_ref_sig8
:
5487 ull
= read_8_bytes (abfd
, m_addr
);
5491 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5492 dwarf_form_name (attr
.form
),
5493 objfile_name (objfile
));
5496 switch (attr
.dw_idx
)
5498 case DW_IDX_compile_unit
:
5499 /* Don't crash on bad data. */
5500 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
5502 complaint (_(".debug_names entry has bad CU index %s"
5505 objfile_name (dwarf2_per_objfile
->objfile
));
5508 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (ull
);
5510 case DW_IDX_type_unit
:
5511 /* Don't crash on bad data. */
5512 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_type_units
.size ())
5514 complaint (_(".debug_names entry has bad TU index %s"
5517 objfile_name (dwarf2_per_objfile
->objfile
));
5520 per_cu
= &dwarf2_per_objfile
->per_bfd
->get_tu (ull
)->per_cu
;
5522 case DW_IDX_die_offset
:
5523 /* In a per-CU index (as opposed to a per-module index), index
5524 entries without CU attribute implicitly refer to the single CU. */
5526 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cu (0);
5528 case DW_IDX_GNU_internal
:
5529 if (!m_map
.augmentation_is_gdb
)
5531 symbol_linkage_
= symbol_linkage::static_
;
5533 case DW_IDX_GNU_external
:
5534 if (!m_map
.augmentation_is_gdb
)
5536 symbol_linkage_
= symbol_linkage::extern_
;
5541 /* Skip if already read in. */
5542 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
5545 /* Check static vs global. */
5546 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5548 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5549 const bool symbol_is_static
=
5550 symbol_linkage_
== symbol_linkage::static_
;
5551 if (want_static
!= symbol_is_static
)
5555 /* Match dw2_symtab_iter_next, symbol_kind
5556 and debug_names::psymbol_tag. */
5560 switch (indexval
.dwarf_tag
)
5562 case DW_TAG_variable
:
5563 case DW_TAG_subprogram
:
5564 /* Some types are also in VAR_DOMAIN. */
5565 case DW_TAG_typedef
:
5566 case DW_TAG_structure_type
:
5573 switch (indexval
.dwarf_tag
)
5575 case DW_TAG_typedef
:
5576 case DW_TAG_structure_type
:
5583 switch (indexval
.dwarf_tag
)
5586 case DW_TAG_variable
:
5593 switch (indexval
.dwarf_tag
)
5605 /* Match dw2_expand_symtabs_matching, symbol_kind and
5606 debug_names::psymbol_tag. */
5609 case VARIABLES_DOMAIN
:
5610 switch (indexval
.dwarf_tag
)
5612 case DW_TAG_variable
:
5618 case FUNCTIONS_DOMAIN
:
5619 switch (indexval
.dwarf_tag
)
5621 case DW_TAG_subprogram
:
5628 switch (indexval
.dwarf_tag
)
5630 case DW_TAG_typedef
:
5631 case DW_TAG_structure_type
:
5637 case MODULES_DOMAIN
:
5638 switch (indexval
.dwarf_tag
)
5652 static struct compunit_symtab
*
5653 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5654 const char *name
, domain_enum domain
)
5656 struct dwarf2_per_objfile
*dwarf2_per_objfile
5657 = get_dwarf2_per_objfile (objfile
);
5659 const auto &mapp
= dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5662 /* index is NULL if OBJF_READNOW. */
5665 const auto &map
= *mapp
;
5667 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5669 struct compunit_symtab
*stab_best
= NULL
;
5670 struct dwarf2_per_cu_data
*per_cu
;
5671 while ((per_cu
= iter
.next ()) != NULL
)
5673 struct symbol
*sym
, *with_opaque
= NULL
;
5674 compunit_symtab
*stab
5675 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5676 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5677 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5679 sym
= block_find_symbol (block
, name
, domain
,
5680 block_find_non_opaque_type_preferred
,
5683 /* Some caution must be observed with overloaded functions and
5684 methods, since the index will not contain any overload
5685 information (but NAME might contain it). */
5688 && strcmp_iw (sym
->search_name (), name
) == 0)
5690 if (with_opaque
!= NULL
5691 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5694 /* Keep looking through other CUs. */
5700 /* This dumps minimal information about .debug_names. It is called
5701 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5702 uses this to verify that .debug_names has been loaded. */
5705 dw2_debug_names_dump (struct objfile
*objfile
)
5707 struct dwarf2_per_objfile
*dwarf2_per_objfile
5708 = get_dwarf2_per_objfile (objfile
);
5710 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
5711 printf_filtered (".debug_names:");
5712 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5713 printf_filtered (" exists\n");
5715 printf_filtered (" faked for \"readnow\"\n");
5716 printf_filtered ("\n");
5720 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5721 const char *func_name
)
5723 struct dwarf2_per_objfile
*dwarf2_per_objfile
5724 = get_dwarf2_per_objfile (objfile
);
5726 /* dwarf2_per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5727 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5729 const mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5731 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5733 struct dwarf2_per_cu_data
*per_cu
;
5734 while ((per_cu
= iter
.next ()) != NULL
)
5735 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5740 dw2_debug_names_map_matching_symbols
5741 (struct objfile
*objfile
,
5742 const lookup_name_info
&name
, domain_enum domain
,
5744 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5745 symbol_compare_ftype
*ordered_compare
)
5747 struct dwarf2_per_objfile
*dwarf2_per_objfile
5748 = get_dwarf2_per_objfile (objfile
);
5750 /* debug_names_table is NULL if OBJF_READNOW. */
5751 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5754 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5755 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5757 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5758 auto matcher
= [&] (const char *symname
)
5760 if (ordered_compare
== nullptr)
5762 return ordered_compare (symname
, match_name
) == 0;
5765 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5766 [&] (offset_type namei
)
5768 /* The name was matched, now expand corresponding CUs that were
5770 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5772 struct dwarf2_per_cu_data
*per_cu
;
5773 while ((per_cu
= iter
.next ()) != NULL
)
5774 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
5779 /* It's a shame we couldn't do this inside the
5780 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5781 that have already been expanded. Instead, this loop matches what
5782 the psymtab code does. */
5783 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5785 compunit_symtab
*symtab
= dwarf2_per_objfile
->get_symtab (per_cu
);
5786 if (symtab
!= nullptr)
5788 const struct block
*block
5789 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5790 if (!iterate_over_symbols_terminated (block
, name
,
5798 dw2_debug_names_expand_symtabs_matching
5799 (struct objfile
*objfile
,
5800 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5801 const lookup_name_info
*lookup_name
,
5802 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5803 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5804 enum search_domain kind
)
5806 struct dwarf2_per_objfile
*dwarf2_per_objfile
5807 = get_dwarf2_per_objfile (objfile
);
5809 /* debug_names_table is NULL if OBJF_READNOW. */
5810 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5813 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5815 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5817 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5821 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5822 file_matcher
, expansion_notify
);
5827 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5829 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5831 kind
, [&] (offset_type namei
)
5833 /* The name was matched, now expand corresponding CUs that were
5835 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5837 struct dwarf2_per_cu_data
*per_cu
;
5838 while ((per_cu
= iter
.next ()) != NULL
)
5839 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5840 file_matcher
, expansion_notify
);
5845 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5848 dw2_find_last_source_symtab
,
5849 dw2_forget_cached_source_info
,
5850 dw2_map_symtabs_matching_filename
,
5851 dw2_debug_names_lookup_symbol
,
5854 dw2_debug_names_dump
,
5855 dw2_debug_names_expand_symtabs_for_function
,
5856 dw2_expand_all_symtabs
,
5857 dw2_expand_symtabs_with_fullname
,
5858 dw2_debug_names_map_matching_symbols
,
5859 dw2_debug_names_expand_symtabs_matching
,
5860 dw2_find_pc_sect_compunit_symtab
,
5862 dw2_map_symbol_filenames
5865 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5866 to either a dwarf2_per_bfd or dwz_file object. */
5868 template <typename T
>
5869 static gdb::array_view
<const gdb_byte
>
5870 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5872 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5874 if (section
->empty ())
5877 /* Older elfutils strip versions could keep the section in the main
5878 executable while splitting it for the separate debug info file. */
5879 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5882 section
->read (obj
);
5884 /* dwarf2_section_info::size is a bfd_size_type, while
5885 gdb::array_view works with size_t. On 32-bit hosts, with
5886 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5887 is 32-bit. So we need an explicit narrowing conversion here.
5888 This is fine, because it's impossible to allocate or mmap an
5889 array/buffer larger than what size_t can represent. */
5890 return gdb::make_array_view (section
->buffer
, section
->size
);
5893 /* Lookup the index cache for the contents of the index associated to
5896 static gdb::array_view
<const gdb_byte
>
5897 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5899 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5900 if (build_id
== nullptr)
5903 return global_index_cache
.lookup_gdb_index (build_id
,
5904 &dwarf2_per_bfd
->index_cache_res
);
5907 /* Same as the above, but for DWZ. */
5909 static gdb::array_view
<const gdb_byte
>
5910 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5912 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5913 if (build_id
== nullptr)
5916 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5919 /* See symfile.h. */
5922 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5924 struct dwarf2_per_objfile
*dwarf2_per_objfile
5925 = get_dwarf2_per_objfile (objfile
);
5927 /* If we're about to read full symbols, don't bother with the
5928 indices. In this case we also don't care if some other debug
5929 format is making psymtabs, because they are all about to be
5931 if ((objfile
->flags
& OBJF_READNOW
))
5933 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5934 create_all_comp_units (dwarf2_per_objfile
);
5935 create_all_type_units (dwarf2_per_objfile
);
5936 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
5937 = create_quick_file_names_table
5938 (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5939 dwarf2_per_objfile
->resize_symtabs ();
5941 for (int i
= 0; i
< (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
5942 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()); ++i
)
5944 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
5946 per_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
5947 struct dwarf2_per_cu_quick_data
);
5950 /* Return 1 so that gdb sees the "quick" functions. However,
5951 these functions will be no-ops because we will have expanded
5953 *index_kind
= dw_index_kind::GDB_INDEX
;
5957 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5959 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5960 dwarf2_per_objfile
->resize_symtabs ();
5964 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5965 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5966 get_gdb_index_contents_from_section
<dwz_file
>))
5968 *index_kind
= dw_index_kind::GDB_INDEX
;
5969 dwarf2_per_objfile
->resize_symtabs ();
5973 /* ... otherwise, try to find the index in the index cache. */
5974 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5975 get_gdb_index_contents_from_cache
,
5976 get_gdb_index_contents_from_cache_dwz
))
5978 global_index_cache
.hit ();
5979 *index_kind
= dw_index_kind::GDB_INDEX
;
5980 dwarf2_per_objfile
->resize_symtabs ();
5984 global_index_cache
.miss ();
5990 /* Build a partial symbol table. */
5993 dwarf2_build_psymtabs (struct objfile
*objfile
)
5995 struct dwarf2_per_objfile
*dwarf2_per_objfile
5996 = get_dwarf2_per_objfile (objfile
);
5998 init_psymbol_list (objfile
, 1024);
6002 /* This isn't really ideal: all the data we allocate on the
6003 objfile's obstack is still uselessly kept around. However,
6004 freeing it seems unsafe. */
6005 psymtab_discarder
psymtabs (objfile
);
6006 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6009 dwarf2_per_objfile
->resize_symtabs ();
6011 /* (maybe) store an index in the cache. */
6012 global_index_cache
.store (dwarf2_per_objfile
);
6014 catch (const gdb_exception_error
&except
)
6016 exception_print (gdb_stderr
, except
);
6020 /* Find the base address of the compilation unit for range lists and
6021 location lists. It will normally be specified by DW_AT_low_pc.
6022 In DWARF-3 draft 4, the base address could be overridden by
6023 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6024 compilation units with discontinuous ranges. */
6027 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6029 struct attribute
*attr
;
6031 cu
->base_address
.reset ();
6033 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6034 if (attr
!= nullptr)
6035 cu
->base_address
= attr
->value_as_address ();
6038 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6039 if (attr
!= nullptr)
6040 cu
->base_address
= attr
->value_as_address ();
6044 /* Helper function that returns the proper abbrev section for
6047 static struct dwarf2_section_info
*
6048 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6050 struct dwarf2_section_info
*abbrev
;
6051 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6053 if (this_cu
->is_dwz
)
6054 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6056 abbrev
= &per_bfd
->abbrev
;
6061 /* Fetch the abbreviation table offset from a comp or type unit header. */
6064 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6065 struct dwarf2_section_info
*section
,
6066 sect_offset sect_off
)
6068 bfd
*abfd
= section
->get_bfd_owner ();
6069 const gdb_byte
*info_ptr
;
6070 unsigned int initial_length_size
, offset_size
;
6073 section
->read (dwarf2_per_objfile
->objfile
);
6074 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6075 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6076 offset_size
= initial_length_size
== 4 ? 4 : 8;
6077 info_ptr
+= initial_length_size
;
6079 version
= read_2_bytes (abfd
, info_ptr
);
6083 /* Skip unit type and address size. */
6087 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6090 /* A partial symtab that is used only for include files. */
6091 struct dwarf2_include_psymtab
: public partial_symtab
6093 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6094 : partial_symtab (filename
, objfile
)
6098 void read_symtab (struct objfile
*objfile
) override
6100 /* It's an include file, no symbols to read for it.
6101 Everything is in the includer symtab. */
6103 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6104 expansion of the includer psymtab. We use the dependencies[0] field to
6105 model the includer. But if we go the regular route of calling
6106 expand_psymtab here, and having expand_psymtab call expand_dependencies
6107 to expand the includer, we'll only use expand_psymtab on the includer
6108 (making it a non-toplevel psymtab), while if we expand the includer via
6109 another path, we'll use read_symtab (making it a toplevel psymtab).
6110 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6111 psymtab, and trigger read_symtab on the includer here directly. */
6112 includer ()->read_symtab (objfile
);
6115 void expand_psymtab (struct objfile
*objfile
) override
6117 /* This is not called by read_symtab, and should not be called by any
6118 expand_dependencies. */
6122 bool readin_p (struct objfile
*objfile
) const override
6124 return includer ()->readin_p (objfile
);
6127 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6133 partial_symtab
*includer () const
6135 /* An include psymtab has exactly one dependency: the psymtab that
6137 gdb_assert (this->number_of_dependencies
== 1);
6138 return this->dependencies
[0];
6142 /* Allocate a new partial symtab for file named NAME and mark this new
6143 partial symtab as being an include of PST. */
6146 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6147 struct objfile
*objfile
)
6149 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6151 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6152 subpst
->dirname
= pst
->dirname
;
6154 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6155 subpst
->dependencies
[0] = pst
;
6156 subpst
->number_of_dependencies
= 1;
6159 /* Read the Line Number Program data and extract the list of files
6160 included by the source file represented by PST. Build an include
6161 partial symtab for each of these included files. */
6164 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6165 struct die_info
*die
,
6166 dwarf2_psymtab
*pst
)
6169 struct attribute
*attr
;
6171 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6172 if (attr
!= nullptr)
6173 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6175 return; /* No linetable, so no includes. */
6177 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6178 that we pass in the raw text_low here; that is ok because we're
6179 only decoding the line table to make include partial symtabs, and
6180 so the addresses aren't really used. */
6181 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6182 pst
->raw_text_low (), 1);
6186 hash_signatured_type (const void *item
)
6188 const struct signatured_type
*sig_type
6189 = (const struct signatured_type
*) item
;
6191 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6192 return sig_type
->signature
;
6196 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6198 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6199 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6201 return lhs
->signature
== rhs
->signature
;
6204 /* Allocate a hash table for signatured types. */
6207 allocate_signatured_type_table ()
6209 return htab_up (htab_create_alloc (41,
6210 hash_signatured_type
,
6212 NULL
, xcalloc
, xfree
));
6215 /* A helper function to add a signatured type CU to a table. */
6218 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6220 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6221 std::vector
<signatured_type
*> *all_type_units
6222 = (std::vector
<signatured_type
*> *) datum
;
6224 all_type_units
->push_back (sigt
);
6229 /* A helper for create_debug_types_hash_table. Read types from SECTION
6230 and fill them into TYPES_HTAB. It will process only type units,
6231 therefore DW_UT_type. */
6234 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6235 struct dwo_file
*dwo_file
,
6236 dwarf2_section_info
*section
, htab_up
&types_htab
,
6237 rcuh_kind section_kind
)
6239 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6240 struct dwarf2_section_info
*abbrev_section
;
6242 const gdb_byte
*info_ptr
, *end_ptr
;
6244 abbrev_section
= (dwo_file
!= NULL
6245 ? &dwo_file
->sections
.abbrev
6246 : &dwarf2_per_objfile
->per_bfd
->abbrev
);
6248 if (dwarf_read_debug
)
6249 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6250 section
->get_name (),
6251 abbrev_section
->get_file_name ());
6253 section
->read (objfile
);
6254 info_ptr
= section
->buffer
;
6256 if (info_ptr
== NULL
)
6259 /* We can't set abfd until now because the section may be empty or
6260 not present, in which case the bfd is unknown. */
6261 abfd
= section
->get_bfd_owner ();
6263 /* We don't use cutu_reader here because we don't need to read
6264 any dies: the signature is in the header. */
6266 end_ptr
= info_ptr
+ section
->size
;
6267 while (info_ptr
< end_ptr
)
6269 struct signatured_type
*sig_type
;
6270 struct dwo_unit
*dwo_tu
;
6272 const gdb_byte
*ptr
= info_ptr
;
6273 struct comp_unit_head header
;
6274 unsigned int length
;
6276 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6278 /* Initialize it due to a false compiler warning. */
6279 header
.signature
= -1;
6280 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6282 /* We need to read the type's signature in order to build the hash
6283 table, but we don't need anything else just yet. */
6285 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6286 abbrev_section
, ptr
, section_kind
);
6288 length
= header
.get_length ();
6290 /* Skip dummy type units. */
6291 if (ptr
>= info_ptr
+ length
6292 || peek_abbrev_code (abfd
, ptr
) == 0
6293 || header
.unit_type
!= DW_UT_type
)
6299 if (types_htab
== NULL
)
6302 types_htab
= allocate_dwo_unit_table ();
6304 types_htab
= allocate_signatured_type_table ();
6310 dwo_tu
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6312 dwo_tu
->dwo_file
= dwo_file
;
6313 dwo_tu
->signature
= header
.signature
;
6314 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6315 dwo_tu
->section
= section
;
6316 dwo_tu
->sect_off
= sect_off
;
6317 dwo_tu
->length
= length
;
6321 /* N.B.: type_offset is not usable if this type uses a DWO file.
6322 The real type_offset is in the DWO file. */
6324 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6325 sig_type
->signature
= header
.signature
;
6326 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6327 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6328 sig_type
->per_cu
.is_debug_types
= 1;
6329 sig_type
->per_cu
.section
= section
;
6330 sig_type
->per_cu
.sect_off
= sect_off
;
6331 sig_type
->per_cu
.length
= length
;
6334 slot
= htab_find_slot (types_htab
.get (),
6335 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6337 gdb_assert (slot
!= NULL
);
6340 sect_offset dup_sect_off
;
6344 const struct dwo_unit
*dup_tu
6345 = (const struct dwo_unit
*) *slot
;
6347 dup_sect_off
= dup_tu
->sect_off
;
6351 const struct signatured_type
*dup_tu
6352 = (const struct signatured_type
*) *slot
;
6354 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6357 complaint (_("debug type entry at offset %s is duplicate to"
6358 " the entry at offset %s, signature %s"),
6359 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6360 hex_string (header
.signature
));
6362 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6364 if (dwarf_read_debug
> 1)
6365 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6366 sect_offset_str (sect_off
),
6367 hex_string (header
.signature
));
6373 /* Create the hash table of all entries in the .debug_types
6374 (or .debug_types.dwo) section(s).
6375 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6376 otherwise it is NULL.
6378 The result is a pointer to the hash table or NULL if there are no types.
6380 Note: This function processes DWO files only, not DWP files. */
6383 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6384 struct dwo_file
*dwo_file
,
6385 gdb::array_view
<dwarf2_section_info
> type_sections
,
6386 htab_up
&types_htab
)
6388 for (dwarf2_section_info
§ion
: type_sections
)
6389 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6390 types_htab
, rcuh_kind::TYPE
);
6393 /* Create the hash table of all entries in the .debug_types section,
6394 and initialize all_type_units.
6395 The result is zero if there is an error (e.g. missing .debug_types section),
6396 otherwise non-zero. */
6399 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6403 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6404 &dwarf2_per_objfile
->per_bfd
->info
, types_htab
,
6405 rcuh_kind::COMPILE
);
6406 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6407 dwarf2_per_objfile
->per_bfd
->types
, types_htab
);
6408 if (types_htab
== NULL
)
6410 dwarf2_per_objfile
->per_bfd
->signatured_types
= NULL
;
6414 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6416 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
6417 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve
6418 (htab_elements (dwarf2_per_objfile
->per_bfd
->signatured_types
.get ()));
6420 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6421 add_signatured_type_cu_to_table
,
6422 &dwarf2_per_objfile
->per_bfd
->all_type_units
);
6427 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6428 If SLOT is non-NULL, it is the entry to use in the hash table.
6429 Otherwise we find one. */
6431 static struct signatured_type
*
6432 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6435 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()
6436 == dwarf2_per_objfile
->per_bfd
->all_type_units
.capacity ())
6437 ++dwarf2_per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6439 signatured_type
*sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6441 dwarf2_per_objfile
->resize_symtabs ();
6443 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6444 sig_type
->signature
= sig
;
6445 sig_type
->per_cu
.is_debug_types
= 1;
6446 if (dwarf2_per_objfile
->per_bfd
->using_index
)
6448 sig_type
->per_cu
.v
.quick
=
6449 OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6450 struct dwarf2_per_cu_quick_data
);
6455 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6458 gdb_assert (*slot
== NULL
);
6460 /* The rest of sig_type must be filled in by the caller. */
6464 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6465 Fill in SIG_ENTRY with DWO_ENTRY. */
6468 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6469 struct signatured_type
*sig_entry
,
6470 struct dwo_unit
*dwo_entry
)
6472 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
6474 /* Make sure we're not clobbering something we don't expect to. */
6475 gdb_assert (! sig_entry
->per_cu
.queued
);
6476 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6477 if (per_bfd
->using_index
)
6479 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6480 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6483 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6484 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6485 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6486 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6487 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6489 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6490 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6491 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6492 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6493 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6494 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6495 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6496 sig_entry
->dwo_unit
= dwo_entry
;
6499 /* Subroutine of lookup_signatured_type.
6500 If we haven't read the TU yet, create the signatured_type data structure
6501 for a TU to be read in directly from a DWO file, bypassing the stub.
6502 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6503 using .gdb_index, then when reading a CU we want to stay in the DWO file
6504 containing that CU. Otherwise we could end up reading several other DWO
6505 files (due to comdat folding) to process the transitive closure of all the
6506 mentioned TUs, and that can be slow. The current DWO file will have every
6507 type signature that it needs.
6508 We only do this for .gdb_index because in the psymtab case we already have
6509 to read all the DWOs to build the type unit groups. */
6511 static struct signatured_type
*
6512 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6514 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6515 struct dwo_file
*dwo_file
;
6516 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6517 struct signatured_type find_sig_entry
, *sig_entry
;
6520 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6522 /* If TU skeletons have been removed then we may not have read in any
6524 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6525 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6527 /* We only ever need to read in one copy of a signatured type.
6528 Use the global signatured_types array to do our own comdat-folding
6529 of types. If this is the first time we're reading this TU, and
6530 the TU has an entry in .gdb_index, replace the recorded data from
6531 .gdb_index with this TU. */
6533 find_sig_entry
.signature
= sig
;
6534 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6535 &find_sig_entry
, INSERT
);
6536 sig_entry
= (struct signatured_type
*) *slot
;
6538 /* We can get here with the TU already read, *or* in the process of being
6539 read. Don't reassign the global entry to point to this DWO if that's
6540 the case. Also note that if the TU is already being read, it may not
6541 have come from a DWO, the program may be a mix of Fission-compiled
6542 code and non-Fission-compiled code. */
6544 /* Have we already tried to read this TU?
6545 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6546 needn't exist in the global table yet). */
6547 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6550 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6551 dwo_unit of the TU itself. */
6552 dwo_file
= cu
->dwo_unit
->dwo_file
;
6554 /* Ok, this is the first time we're reading this TU. */
6555 if (dwo_file
->tus
== NULL
)
6557 find_dwo_entry
.signature
= sig
;
6558 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6560 if (dwo_entry
== NULL
)
6563 /* If the global table doesn't have an entry for this TU, add one. */
6564 if (sig_entry
== NULL
)
6565 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6567 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6568 sig_entry
->per_cu
.tu_read
= 1;
6572 /* Subroutine of lookup_signatured_type.
6573 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6574 then try the DWP file. If the TU stub (skeleton) has been removed then
6575 it won't be in .gdb_index. */
6577 static struct signatured_type
*
6578 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6580 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6581 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6582 struct dwo_unit
*dwo_entry
;
6583 struct signatured_type find_sig_entry
, *sig_entry
;
6586 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6587 gdb_assert (dwp_file
!= NULL
);
6589 /* If TU skeletons have been removed then we may not have read in any
6591 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6592 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6594 find_sig_entry
.signature
= sig
;
6595 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6596 &find_sig_entry
, INSERT
);
6597 sig_entry
= (struct signatured_type
*) *slot
;
6599 /* Have we already tried to read this TU?
6600 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6601 needn't exist in the global table yet). */
6602 if (sig_entry
!= NULL
)
6605 if (dwp_file
->tus
== NULL
)
6607 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6608 sig
, 1 /* is_debug_types */);
6609 if (dwo_entry
== NULL
)
6612 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6613 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6618 /* Lookup a signature based type for DW_FORM_ref_sig8.
6619 Returns NULL if signature SIG is not present in the table.
6620 It is up to the caller to complain about this. */
6622 static struct signatured_type
*
6623 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6625 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6628 && dwarf2_per_objfile
->per_bfd
->using_index
)
6630 /* We're in a DWO/DWP file, and we're using .gdb_index.
6631 These cases require special processing. */
6632 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6633 return lookup_dwo_signatured_type (cu
, sig
);
6635 return lookup_dwp_signatured_type (cu
, sig
);
6639 struct signatured_type find_entry
, *entry
;
6641 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6643 find_entry
.signature
= sig
;
6644 entry
= ((struct signatured_type
*)
6645 htab_find (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6651 /* Low level DIE reading support. */
6653 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6656 init_cu_die_reader (struct die_reader_specs
*reader
,
6657 struct dwarf2_cu
*cu
,
6658 struct dwarf2_section_info
*section
,
6659 struct dwo_file
*dwo_file
,
6660 struct abbrev_table
*abbrev_table
)
6662 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6663 reader
->abfd
= section
->get_bfd_owner ();
6665 reader
->dwo_file
= dwo_file
;
6666 reader
->die_section
= section
;
6667 reader
->buffer
= section
->buffer
;
6668 reader
->buffer_end
= section
->buffer
+ section
->size
;
6669 reader
->abbrev_table
= abbrev_table
;
6672 /* Subroutine of cutu_reader to simplify it.
6673 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6674 There's just a lot of work to do, and cutu_reader is big enough
6677 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6678 from it to the DIE in the DWO. If NULL we are skipping the stub.
6679 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6680 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6681 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6682 STUB_COMP_DIR may be non-NULL.
6683 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6684 are filled in with the info of the DIE from the DWO file.
6685 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6686 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6687 kept around for at least as long as *RESULT_READER.
6689 The result is non-zero if a valid (non-dummy) DIE was found. */
6692 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6693 struct dwo_unit
*dwo_unit
,
6694 struct die_info
*stub_comp_unit_die
,
6695 const char *stub_comp_dir
,
6696 struct die_reader_specs
*result_reader
,
6697 const gdb_byte
**result_info_ptr
,
6698 struct die_info
**result_comp_unit_die
,
6699 abbrev_table_up
*result_dwo_abbrev_table
)
6701 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6702 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6703 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6705 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6706 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6707 int i
,num_extra_attrs
;
6708 struct dwarf2_section_info
*dwo_abbrev_section
;
6709 struct die_info
*comp_unit_die
;
6711 /* At most one of these may be provided. */
6712 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6714 /* These attributes aren't processed until later:
6715 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6716 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6717 referenced later. However, these attributes are found in the stub
6718 which we won't have later. In order to not impose this complication
6719 on the rest of the code, we read them here and copy them to the
6728 if (stub_comp_unit_die
!= NULL
)
6730 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6732 if (!per_cu
->is_debug_types
)
6733 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6734 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6735 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6736 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6737 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6739 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6741 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6742 here (if needed). We need the value before we can process
6744 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6746 else if (stub_comp_dir
!= NULL
)
6748 /* Reconstruct the comp_dir attribute to simplify the code below. */
6749 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6750 comp_dir
->name
= DW_AT_comp_dir
;
6751 comp_dir
->form
= DW_FORM_string
;
6752 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6753 DW_STRING (comp_dir
) = stub_comp_dir
;
6756 /* Set up for reading the DWO CU/TU. */
6757 cu
->dwo_unit
= dwo_unit
;
6758 dwarf2_section_info
*section
= dwo_unit
->section
;
6759 section
->read (objfile
);
6760 abfd
= section
->get_bfd_owner ();
6761 begin_info_ptr
= info_ptr
= (section
->buffer
6762 + to_underlying (dwo_unit
->sect_off
));
6763 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6765 if (per_cu
->is_debug_types
)
6767 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6769 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6770 &cu
->header
, section
,
6772 info_ptr
, rcuh_kind::TYPE
);
6773 /* This is not an assert because it can be caused by bad debug info. */
6774 if (sig_type
->signature
!= cu
->header
.signature
)
6776 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6777 " TU at offset %s [in module %s]"),
6778 hex_string (sig_type
->signature
),
6779 hex_string (cu
->header
.signature
),
6780 sect_offset_str (dwo_unit
->sect_off
),
6781 bfd_get_filename (abfd
));
6783 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6784 /* For DWOs coming from DWP files, we don't know the CU length
6785 nor the type's offset in the TU until now. */
6786 dwo_unit
->length
= cu
->header
.get_length ();
6787 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6789 /* Establish the type offset that can be used to lookup the type.
6790 For DWO files, we don't know it until now. */
6791 sig_type
->type_offset_in_section
6792 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6796 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6797 &cu
->header
, section
,
6799 info_ptr
, rcuh_kind::COMPILE
);
6800 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6801 /* For DWOs coming from DWP files, we don't know the CU length
6803 dwo_unit
->length
= cu
->header
.get_length ();
6806 *result_dwo_abbrev_table
6807 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6808 cu
->header
.abbrev_sect_off
);
6809 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6810 result_dwo_abbrev_table
->get ());
6812 /* Read in the die, but leave space to copy over the attributes
6813 from the stub. This has the benefit of simplifying the rest of
6814 the code - all the work to maintain the illusion of a single
6815 DW_TAG_{compile,type}_unit DIE is done here. */
6816 num_extra_attrs
= ((stmt_list
!= NULL
)
6820 + (comp_dir
!= NULL
));
6821 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6824 /* Copy over the attributes from the stub to the DIE we just read in. */
6825 comp_unit_die
= *result_comp_unit_die
;
6826 i
= comp_unit_die
->num_attrs
;
6827 if (stmt_list
!= NULL
)
6828 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6830 comp_unit_die
->attrs
[i
++] = *low_pc
;
6831 if (high_pc
!= NULL
)
6832 comp_unit_die
->attrs
[i
++] = *high_pc
;
6834 comp_unit_die
->attrs
[i
++] = *ranges
;
6835 if (comp_dir
!= NULL
)
6836 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6837 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6839 if (dwarf_die_debug
)
6841 fprintf_unfiltered (gdb_stdlog
,
6842 "Read die from %s@0x%x of %s:\n",
6843 section
->get_name (),
6844 (unsigned) (begin_info_ptr
- section
->buffer
),
6845 bfd_get_filename (abfd
));
6846 dump_die (comp_unit_die
, dwarf_die_debug
);
6849 /* Skip dummy compilation units. */
6850 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6851 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6854 *result_info_ptr
= info_ptr
;
6858 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6859 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6860 signature is part of the header. */
6861 static gdb::optional
<ULONGEST
>
6862 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6864 if (cu
->header
.version
>= 5)
6865 return cu
->header
.signature
;
6866 struct attribute
*attr
;
6867 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6868 if (attr
== nullptr)
6869 return gdb::optional
<ULONGEST
> ();
6870 return DW_UNSND (attr
);
6873 /* Subroutine of cutu_reader to simplify it.
6874 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6875 Returns NULL if the specified DWO unit cannot be found. */
6877 static struct dwo_unit
*
6878 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6880 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6881 struct dwo_unit
*dwo_unit
;
6882 const char *comp_dir
;
6884 gdb_assert (cu
!= NULL
);
6886 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6887 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6888 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6890 if (per_cu
->is_debug_types
)
6891 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6894 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6896 if (!signature
.has_value ())
6897 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6899 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6901 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6907 /* Subroutine of cutu_reader to simplify it.
6908 See it for a description of the parameters.
6909 Read a TU directly from a DWO file, bypassing the stub. */
6912 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6913 dwarf2_per_objfile
*per_objfile
,
6914 int use_existing_cu
)
6916 struct signatured_type
*sig_type
;
6918 /* Verify we can do the following downcast, and that we have the
6920 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6921 sig_type
= (struct signatured_type
*) this_cu
;
6922 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6924 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6926 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6927 /* There's no need to do the rereading_dwo_cu handling that
6928 cutu_reader does since we don't read the stub. */
6932 /* If !use_existing_cu, this_cu->cu must be NULL. */
6933 gdb_assert (this_cu
->cu
== NULL
);
6934 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6937 /* A future optimization, if needed, would be to use an existing
6938 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6939 could share abbrev tables. */
6941 if (read_cutu_die_from_dwo (this_cu
->cu
, sig_type
->dwo_unit
,
6942 NULL
/* stub_comp_unit_die */,
6943 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6946 &m_dwo_abbrev_table
) == 0)
6953 /* Initialize a CU (or TU) and read its DIEs.
6954 If the CU defers to a DWO file, read the DWO file as well.
6956 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6957 Otherwise the table specified in the comp unit header is read in and used.
6958 This is an optimization for when we already have the abbrev table.
6960 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6961 Otherwise, a new CU is allocated with xmalloc. */
6963 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6964 dwarf2_per_objfile
*dwarf2_per_objfile
,
6965 struct abbrev_table
*abbrev_table
,
6966 int use_existing_cu
,
6968 : die_reader_specs
{},
6971 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6972 struct dwarf2_section_info
*section
= this_cu
->section
;
6973 bfd
*abfd
= section
->get_bfd_owner ();
6974 struct dwarf2_cu
*cu
;
6975 const gdb_byte
*begin_info_ptr
;
6976 struct signatured_type
*sig_type
= NULL
;
6977 struct dwarf2_section_info
*abbrev_section
;
6978 /* Non-zero if CU currently points to a DWO file and we need to
6979 reread it. When this happens we need to reread the skeleton die
6980 before we can reread the DWO file (this only applies to CUs, not TUs). */
6981 int rereading_dwo_cu
= 0;
6983 if (dwarf_die_debug
)
6984 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6985 this_cu
->is_debug_types
? "type" : "comp",
6986 sect_offset_str (this_cu
->sect_off
));
6988 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6989 file (instead of going through the stub), short-circuit all of this. */
6990 if (this_cu
->reading_dwo_directly
)
6992 /* Narrow down the scope of possibilities to have to understand. */
6993 gdb_assert (this_cu
->is_debug_types
);
6994 gdb_assert (abbrev_table
== NULL
);
6995 init_tu_and_read_dwo_dies (this_cu
, dwarf2_per_objfile
, use_existing_cu
);
6999 /* This is cheap if the section is already read in. */
7000 section
->read (objfile
);
7002 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7004 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7006 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7009 /* If this CU is from a DWO file we need to start over, we need to
7010 refetch the attributes from the skeleton CU.
7011 This could be optimized by retrieving those attributes from when we
7012 were here the first time: the previous comp_unit_die was stored in
7013 comp_unit_obstack. But there's no data yet that we need this
7015 if (cu
->dwo_unit
!= NULL
)
7016 rereading_dwo_cu
= 1;
7020 /* If !use_existing_cu, this_cu->cu must be NULL. */
7021 gdb_assert (this_cu
->cu
== NULL
);
7022 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7023 cu
= m_new_cu
.get ();
7026 /* Get the header. */
7027 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7029 /* We already have the header, there's no need to read it in again. */
7030 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7034 if (this_cu
->is_debug_types
)
7036 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7037 &cu
->header
, section
,
7038 abbrev_section
, info_ptr
,
7041 /* Since per_cu is the first member of struct signatured_type,
7042 we can go from a pointer to one to a pointer to the other. */
7043 sig_type
= (struct signatured_type
*) this_cu
;
7044 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7045 gdb_assert (sig_type
->type_offset_in_tu
7046 == cu
->header
.type_cu_offset_in_tu
);
7047 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7049 /* LENGTH has not been set yet for type units if we're
7050 using .gdb_index. */
7051 this_cu
->length
= cu
->header
.get_length ();
7053 /* Establish the type offset that can be used to lookup the type. */
7054 sig_type
->type_offset_in_section
=
7055 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7057 this_cu
->dwarf_version
= cu
->header
.version
;
7061 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7062 &cu
->header
, section
,
7065 rcuh_kind::COMPILE
);
7067 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7068 if (this_cu
->length
== 0)
7069 this_cu
->length
= cu
->header
.get_length ();
7071 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7072 this_cu
->dwarf_version
= cu
->header
.version
;
7076 /* Skip dummy compilation units. */
7077 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7078 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7084 /* If we don't have them yet, read the abbrevs for this compilation unit.
7085 And if we need to read them now, make sure they're freed when we're
7087 if (abbrev_table
!= NULL
)
7088 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7091 m_abbrev_table_holder
7092 = abbrev_table::read (objfile
, abbrev_section
,
7093 cu
->header
.abbrev_sect_off
);
7094 abbrev_table
= m_abbrev_table_holder
.get ();
7097 /* Read the top level CU/TU die. */
7098 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7099 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7101 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7107 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7108 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7109 table from the DWO file and pass the ownership over to us. It will be
7110 referenced from READER, so we must make sure to free it after we're done
7113 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7114 DWO CU, that this test will fail (the attribute will not be present). */
7115 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7116 if (dwo_name
!= nullptr)
7118 struct dwo_unit
*dwo_unit
;
7119 struct die_info
*dwo_comp_unit_die
;
7121 if (comp_unit_die
->has_children
)
7123 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7124 " has children (offset %s) [in module %s]"),
7125 sect_offset_str (this_cu
->sect_off
),
7126 bfd_get_filename (abfd
));
7128 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7129 if (dwo_unit
!= NULL
)
7131 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7132 comp_unit_die
, NULL
,
7135 &m_dwo_abbrev_table
) == 0)
7141 comp_unit_die
= dwo_comp_unit_die
;
7145 /* Yikes, we couldn't find the rest of the DIE, we only have
7146 the stub. A complaint has already been logged. There's
7147 not much more we can do except pass on the stub DIE to
7148 die_reader_func. We don't want to throw an error on bad
7155 cutu_reader::keep ()
7157 /* Done, clean up. */
7158 gdb_assert (!dummy_p
);
7159 if (m_new_cu
!= NULL
)
7161 /* We know that m_this_cu->cu is set, since we are in the process of
7163 gdb_assert (m_this_cu
->cu
!= nullptr);
7164 dwarf2_per_objfile
*dwarf2_per_objfile
= m_this_cu
->cu
->per_objfile
;
7166 /* Link this CU into read_in_chain. */
7167 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
7168 dwarf2_per_objfile
->per_bfd
->read_in_chain
= m_this_cu
;
7169 /* The chain owns it now. */
7170 m_new_cu
.release ();
7174 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7175 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7176 assumed to have already done the lookup to find the DWO file).
7178 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7179 THIS_CU->is_debug_types, but nothing else.
7181 We fill in THIS_CU->length.
7183 THIS_CU->cu is always freed when done.
7184 This is done in order to not leave THIS_CU->cu in a state where we have
7185 to care whether it refers to the "main" CU or the DWO CU.
7187 When parent_cu is passed, it is used to provide a default value for
7188 str_offsets_base and addr_base from the parent. */
7190 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7191 dwarf2_per_objfile
*dwarf2_per_objfile
,
7192 struct dwarf2_cu
*parent_cu
,
7193 struct dwo_file
*dwo_file
)
7194 : die_reader_specs
{},
7197 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7198 struct dwarf2_section_info
*section
= this_cu
->section
;
7199 bfd
*abfd
= section
->get_bfd_owner ();
7200 struct dwarf2_section_info
*abbrev_section
;
7201 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7203 if (dwarf_die_debug
)
7204 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7205 this_cu
->is_debug_types
? "type" : "comp",
7206 sect_offset_str (this_cu
->sect_off
));
7208 gdb_assert (this_cu
->cu
== NULL
);
7210 abbrev_section
= (dwo_file
!= NULL
7211 ? &dwo_file
->sections
.abbrev
7212 : get_abbrev_section_for_cu (this_cu
));
7214 /* This is cheap if the section is already read in. */
7215 section
->read (objfile
);
7217 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7219 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7220 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7221 &m_new_cu
->header
, section
,
7222 abbrev_section
, info_ptr
,
7223 (this_cu
->is_debug_types
7225 : rcuh_kind::COMPILE
));
7227 if (parent_cu
!= nullptr)
7229 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7230 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7232 this_cu
->length
= m_new_cu
->header
.get_length ();
7234 /* Skip dummy compilation units. */
7235 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7236 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7242 m_abbrev_table_holder
7243 = abbrev_table::read (objfile
, abbrev_section
,
7244 m_new_cu
->header
.abbrev_sect_off
);
7246 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7247 m_abbrev_table_holder
.get ());
7248 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7252 /* Type Unit Groups.
7254 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7255 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7256 so that all types coming from the same compilation (.o file) are grouped
7257 together. A future step could be to put the types in the same symtab as
7258 the CU the types ultimately came from. */
7261 hash_type_unit_group (const void *item
)
7263 const struct type_unit_group
*tu_group
7264 = (const struct type_unit_group
*) item
;
7266 return hash_stmt_list_entry (&tu_group
->hash
);
7270 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7272 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7273 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7275 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7278 /* Allocate a hash table for type unit groups. */
7281 allocate_type_unit_groups_table ()
7283 return htab_up (htab_create_alloc (3,
7284 hash_type_unit_group
,
7286 NULL
, xcalloc
, xfree
));
7289 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7290 partial symtabs. We combine several TUs per psymtab to not let the size
7291 of any one psymtab grow too big. */
7292 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7293 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7295 /* Helper routine for get_type_unit_group.
7296 Create the type_unit_group object used to hold one or more TUs. */
7298 static struct type_unit_group
*
7299 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7301 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7302 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
7303 struct dwarf2_per_cu_data
*per_cu
;
7304 struct type_unit_group
*tu_group
;
7306 tu_group
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
7307 struct type_unit_group
);
7308 per_cu
= &tu_group
->per_cu
;
7309 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7310 per_cu
->per_bfd
= per_bfd
;
7312 if (per_bfd
->using_index
)
7314 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7315 struct dwarf2_per_cu_quick_data
);
7319 unsigned int line_offset
= to_underlying (line_offset_struct
);
7320 dwarf2_psymtab
*pst
;
7323 /* Give the symtab a useful name for debug purposes. */
7324 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7325 name
= string_printf ("<type_units_%d>",
7326 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7328 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7330 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, name
.c_str ());
7331 pst
->anonymous
= true;
7334 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7335 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7340 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7341 STMT_LIST is a DW_AT_stmt_list attribute. */
7343 static struct type_unit_group
*
7344 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7346 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7347 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7348 struct type_unit_group
*tu_group
;
7350 unsigned int line_offset
;
7351 struct type_unit_group type_unit_group_for_lookup
;
7353 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7354 dwarf2_per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7356 /* Do we need to create a new group, or can we use an existing one? */
7360 line_offset
= DW_UNSND (stmt_list
);
7361 ++tu_stats
->nr_symtab_sharers
;
7365 /* Ugh, no stmt_list. Rare, but we have to handle it.
7366 We can do various things here like create one group per TU or
7367 spread them over multiple groups to split up the expansion work.
7368 To avoid worst case scenarios (too many groups or too large groups)
7369 we, umm, group them in bunches. */
7370 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7371 | (tu_stats
->nr_stmt_less_type_units
7372 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7373 ++tu_stats
->nr_stmt_less_type_units
;
7376 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7377 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7378 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7379 &type_unit_group_for_lookup
, INSERT
);
7382 tu_group
= (struct type_unit_group
*) *slot
;
7383 gdb_assert (tu_group
!= NULL
);
7387 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7388 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7390 ++tu_stats
->nr_symtabs
;
7396 /* Partial symbol tables. */
7398 /* Create a psymtab named NAME and assign it to PER_CU.
7400 The caller must fill in the following details:
7401 dirname, textlow, texthigh. */
7403 static dwarf2_psymtab
*
7404 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7405 dwarf2_per_objfile
*per_objfile
,
7408 struct objfile
*objfile
= per_objfile
->objfile
;
7409 dwarf2_psymtab
*pst
;
7411 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7413 pst
->psymtabs_addrmap_supported
= true;
7415 /* This is the glue that links PST into GDB's symbol API. */
7416 per_cu
->v
.psymtab
= pst
;
7421 /* DIE reader function for process_psymtab_comp_unit. */
7424 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7425 const gdb_byte
*info_ptr
,
7426 struct die_info
*comp_unit_die
,
7427 enum language pretend_language
)
7429 struct dwarf2_cu
*cu
= reader
->cu
;
7430 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7431 struct objfile
*objfile
= per_objfile
->objfile
;
7432 struct gdbarch
*gdbarch
= objfile
->arch ();
7433 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7435 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7436 dwarf2_psymtab
*pst
;
7437 enum pc_bounds_kind cu_bounds_kind
;
7438 const char *filename
;
7440 gdb_assert (! per_cu
->is_debug_types
);
7442 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7444 /* Allocate a new partial symbol table structure. */
7445 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7446 static const char artificial
[] = "<artificial>";
7447 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7448 if (filename
== NULL
)
7450 else if (strcmp (filename
, artificial
) == 0)
7452 debug_filename
.reset (concat (artificial
, "@",
7453 sect_offset_str (per_cu
->sect_off
),
7455 filename
= debug_filename
.get ();
7458 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7460 /* This must be done before calling dwarf2_build_include_psymtabs. */
7461 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7463 baseaddr
= objfile
->text_section_offset ();
7465 dwarf2_find_base_address (comp_unit_die
, cu
);
7467 /* Possibly set the default values of LOWPC and HIGHPC from
7469 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7470 &best_highpc
, cu
, pst
);
7471 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7474 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7477 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7479 /* Store the contiguous range if it is not empty; it can be
7480 empty for CUs with no code. */
7481 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7485 /* Check if comp unit has_children.
7486 If so, read the rest of the partial symbols from this comp unit.
7487 If not, there's no more debug_info for this comp unit. */
7488 if (comp_unit_die
->has_children
)
7490 struct partial_die_info
*first_die
;
7491 CORE_ADDR lowpc
, highpc
;
7493 lowpc
= ((CORE_ADDR
) -1);
7494 highpc
= ((CORE_ADDR
) 0);
7496 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7498 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7499 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7501 /* If we didn't find a lowpc, set it to highpc to avoid
7502 complaints from `maint check'. */
7503 if (lowpc
== ((CORE_ADDR
) -1))
7506 /* If the compilation unit didn't have an explicit address range,
7507 then use the information extracted from its child dies. */
7508 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7511 best_highpc
= highpc
;
7514 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7515 best_lowpc
+ baseaddr
)
7517 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7518 best_highpc
+ baseaddr
)
7521 end_psymtab_common (objfile
, pst
);
7523 if (!cu
->per_cu
->imported_symtabs_empty ())
7526 int len
= cu
->per_cu
->imported_symtabs_size ();
7528 /* Fill in 'dependencies' here; we fill in 'users' in a
7530 pst
->number_of_dependencies
= len
;
7532 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7533 for (i
= 0; i
< len
; ++i
)
7535 pst
->dependencies
[i
]
7536 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7539 cu
->per_cu
->imported_symtabs_free ();
7542 /* Get the list of files included in the current compilation unit,
7543 and build a psymtab for each of them. */
7544 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7546 if (dwarf_read_debug
)
7547 fprintf_unfiltered (gdb_stdlog
,
7548 "Psymtab for %s unit @%s: %s - %s"
7549 ", %d global, %d static syms\n",
7550 per_cu
->is_debug_types
? "type" : "comp",
7551 sect_offset_str (per_cu
->sect_off
),
7552 paddress (gdbarch
, pst
->text_low (objfile
)),
7553 paddress (gdbarch
, pst
->text_high (objfile
)),
7554 pst
->n_global_syms
, pst
->n_static_syms
);
7557 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7558 Process compilation unit THIS_CU for a psymtab. */
7561 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7562 dwarf2_per_objfile
*per_objfile
,
7563 bool want_partial_unit
,
7564 enum language pretend_language
)
7566 /* If this compilation unit was already read in, free the
7567 cached copy in order to read it in again. This is
7568 necessary because we skipped some symbols when we first
7569 read in the compilation unit (see load_partial_dies).
7570 This problem could be avoided, but the benefit is unclear. */
7571 if (this_cu
->cu
!= NULL
)
7572 free_one_cached_comp_unit (this_cu
);
7574 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 0, false);
7576 switch (reader
.comp_unit_die
->tag
)
7578 case DW_TAG_compile_unit
:
7579 this_cu
->unit_type
= DW_UT_compile
;
7581 case DW_TAG_partial_unit
:
7582 this_cu
->unit_type
= DW_UT_partial
;
7592 else if (this_cu
->is_debug_types
)
7593 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7594 reader
.comp_unit_die
);
7595 else if (want_partial_unit
7596 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7597 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7598 reader
.comp_unit_die
,
7601 this_cu
->lang
= this_cu
->cu
->language
;
7603 /* Age out any secondary CUs. */
7604 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7607 /* Reader function for build_type_psymtabs. */
7610 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7611 const gdb_byte
*info_ptr
,
7612 struct die_info
*type_unit_die
)
7614 struct dwarf2_per_objfile
*dwarf2_per_objfile
= reader
->cu
->per_objfile
;
7615 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7616 struct dwarf2_cu
*cu
= reader
->cu
;
7617 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7618 struct signatured_type
*sig_type
;
7619 struct type_unit_group
*tu_group
;
7620 struct attribute
*attr
;
7621 struct partial_die_info
*first_die
;
7622 CORE_ADDR lowpc
, highpc
;
7623 dwarf2_psymtab
*pst
;
7625 gdb_assert (per_cu
->is_debug_types
);
7626 sig_type
= (struct signatured_type
*) per_cu
;
7628 if (! type_unit_die
->has_children
)
7631 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7632 tu_group
= get_type_unit_group (cu
, attr
);
7634 if (tu_group
->tus
== nullptr)
7635 tu_group
->tus
= new std::vector
<signatured_type
*>;
7636 tu_group
->tus
->push_back (sig_type
);
7638 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7639 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, "");
7640 pst
->anonymous
= true;
7642 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7644 lowpc
= (CORE_ADDR
) -1;
7645 highpc
= (CORE_ADDR
) 0;
7646 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7648 end_psymtab_common (objfile
, pst
);
7651 /* Struct used to sort TUs by their abbreviation table offset. */
7653 struct tu_abbrev_offset
7655 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7656 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7659 signatured_type
*sig_type
;
7660 sect_offset abbrev_offset
;
7663 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7666 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7667 const struct tu_abbrev_offset
&b
)
7669 return a
.abbrev_offset
< b
.abbrev_offset
;
7672 /* Efficiently read all the type units.
7673 This does the bulk of the work for build_type_psymtabs.
7675 The efficiency is because we sort TUs by the abbrev table they use and
7676 only read each abbrev table once. In one program there are 200K TUs
7677 sharing 8K abbrev tables.
7679 The main purpose of this function is to support building the
7680 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7681 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7682 can collapse the search space by grouping them by stmt_list.
7683 The savings can be significant, in the same program from above the 200K TUs
7684 share 8K stmt_list tables.
7686 FUNC is expected to call get_type_unit_group, which will create the
7687 struct type_unit_group if necessary and add it to
7688 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7691 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7693 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7694 abbrev_table_up abbrev_table
;
7695 sect_offset abbrev_offset
;
7697 /* It's up to the caller to not call us multiple times. */
7698 gdb_assert (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7700 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ())
7703 /* TUs typically share abbrev tables, and there can be way more TUs than
7704 abbrev tables. Sort by abbrev table to reduce the number of times we
7705 read each abbrev table in.
7706 Alternatives are to punt or to maintain a cache of abbrev tables.
7707 This is simpler and efficient enough for now.
7709 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7710 symtab to use). Typically TUs with the same abbrev offset have the same
7711 stmt_list value too so in practice this should work well.
7713 The basic algorithm here is:
7715 sort TUs by abbrev table
7716 for each TU with same abbrev table:
7717 read abbrev table if first user
7718 read TU top level DIE
7719 [IWBN if DWO skeletons had DW_AT_stmt_list]
7722 if (dwarf_read_debug
)
7723 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7725 /* Sort in a separate table to maintain the order of all_type_units
7726 for .gdb_index: TU indices directly index all_type_units. */
7727 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7728 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7730 for (signatured_type
*sig_type
: dwarf2_per_objfile
->per_bfd
->all_type_units
)
7731 sorted_by_abbrev
.emplace_back
7732 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7733 sig_type
->per_cu
.section
,
7734 sig_type
->per_cu
.sect_off
));
7736 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7737 sort_tu_by_abbrev_offset
);
7739 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7741 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7743 /* Switch to the next abbrev table if necessary. */
7744 if (abbrev_table
== NULL
7745 || tu
.abbrev_offset
!= abbrev_offset
)
7747 abbrev_offset
= tu
.abbrev_offset
;
7749 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7750 &dwarf2_per_objfile
->per_bfd
->abbrev
,
7752 ++tu_stats
->nr_uniq_abbrev_tables
;
7755 cutu_reader
reader (&tu
.sig_type
->per_cu
, dwarf2_per_objfile
,
7756 abbrev_table
.get (), 0, false);
7757 if (!reader
.dummy_p
)
7758 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7759 reader
.comp_unit_die
);
7763 /* Print collected type unit statistics. */
7766 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7768 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7770 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7771 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7772 dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7773 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7774 tu_stats
->nr_uniq_abbrev_tables
);
7775 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7776 tu_stats
->nr_symtabs
);
7777 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7778 tu_stats
->nr_symtab_sharers
);
7779 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7780 tu_stats
->nr_stmt_less_type_units
);
7781 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7782 tu_stats
->nr_all_type_units_reallocs
);
7785 /* Traversal function for build_type_psymtabs. */
7788 build_type_psymtab_dependencies (void **slot
, void *info
)
7790 struct dwarf2_per_objfile
*dwarf2_per_objfile
7791 = (struct dwarf2_per_objfile
*) info
;
7792 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7793 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7794 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7795 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7796 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7799 gdb_assert (len
> 0);
7800 gdb_assert (per_cu
->type_unit_group_p ());
7802 pst
->number_of_dependencies
= len
;
7803 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7804 for (i
= 0; i
< len
; ++i
)
7806 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7807 gdb_assert (iter
->per_cu
.is_debug_types
);
7808 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7809 iter
->type_unit_group
= tu_group
;
7812 delete tu_group
->tus
;
7813 tu_group
->tus
= nullptr;
7818 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7819 Build partial symbol tables for the .debug_types comp-units. */
7822 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7824 if (! create_all_type_units (dwarf2_per_objfile
))
7827 build_type_psymtabs_1 (dwarf2_per_objfile
);
7830 /* Traversal function for process_skeletonless_type_unit.
7831 Read a TU in a DWO file and build partial symbols for it. */
7834 process_skeletonless_type_unit (void **slot
, void *info
)
7836 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7837 struct dwarf2_per_objfile
*dwarf2_per_objfile
7838 = (struct dwarf2_per_objfile
*) info
;
7839 struct signatured_type find_entry
, *entry
;
7841 /* If this TU doesn't exist in the global table, add it and read it in. */
7843 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
7844 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7846 find_entry
.signature
= dwo_unit
->signature
;
7847 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
7848 &find_entry
, INSERT
);
7849 /* If we've already seen this type there's nothing to do. What's happening
7850 is we're doing our own version of comdat-folding here. */
7854 /* This does the job that create_all_type_units would have done for
7856 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7857 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7860 /* This does the job that build_type_psymtabs_1 would have done. */
7861 cutu_reader
reader (&entry
->per_cu
, dwarf2_per_objfile
, NULL
, 0, false);
7862 if (!reader
.dummy_p
)
7863 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7864 reader
.comp_unit_die
);
7869 /* Traversal function for process_skeletonless_type_units. */
7872 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7874 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7876 if (dwo_file
->tus
!= NULL
)
7877 htab_traverse_noresize (dwo_file
->tus
.get (),
7878 process_skeletonless_type_unit
, info
);
7883 /* Scan all TUs of DWO files, verifying we've processed them.
7884 This is needed in case a TU was emitted without its skeleton.
7885 Note: This can't be done until we know what all the DWO files are. */
7888 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7890 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7891 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7892 && dwarf2_per_objfile
->per_bfd
->dwo_files
!= NULL
)
7894 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (),
7895 process_dwo_file_for_skeletonless_type_units
,
7896 dwarf2_per_objfile
);
7900 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7903 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7905 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7907 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7912 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7914 /* Set the 'user' field only if it is not already set. */
7915 if (pst
->dependencies
[j
]->user
== NULL
)
7916 pst
->dependencies
[j
]->user
= pst
;
7921 /* Build the partial symbol table by doing a quick pass through the
7922 .debug_info and .debug_abbrev sections. */
7925 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7927 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7929 if (dwarf_read_debug
)
7931 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7932 objfile_name (objfile
));
7935 scoped_restore restore_reading_psyms
7936 = make_scoped_restore (&dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
,
7939 dwarf2_per_objfile
->per_bfd
->info
.read (objfile
);
7941 /* Any cached compilation units will be linked by the per-objfile
7942 read_in_chain. Make sure to free them when we're done. */
7943 free_cached_comp_units
freer (dwarf2_per_objfile
);
7945 build_type_psymtabs (dwarf2_per_objfile
);
7947 create_all_comp_units (dwarf2_per_objfile
);
7949 /* Create a temporary address map on a temporary obstack. We later
7950 copy this to the final obstack. */
7951 auto_obstack temp_obstack
;
7953 scoped_restore save_psymtabs_addrmap
7954 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7955 addrmap_create_mutable (&temp_obstack
));
7957 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7959 if (per_cu
->v
.psymtab
!= NULL
)
7960 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7962 process_psymtab_comp_unit (per_cu
, dwarf2_per_objfile
, false,
7966 /* This has to wait until we read the CUs, we need the list of DWOs. */
7967 process_skeletonless_type_units (dwarf2_per_objfile
);
7969 /* Now that all TUs have been processed we can fill in the dependencies. */
7970 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
7972 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7973 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7976 if (dwarf_read_debug
)
7977 print_tu_stats (dwarf2_per_objfile
);
7979 set_partial_user (dwarf2_per_objfile
);
7981 objfile
->partial_symtabs
->psymtabs_addrmap
7982 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7983 objfile
->partial_symtabs
->obstack ());
7984 /* At this point we want to keep the address map. */
7985 save_psymtabs_addrmap
.release ();
7987 if (dwarf_read_debug
)
7988 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7989 objfile_name (objfile
));
7992 /* Load the partial DIEs for a secondary CU into memory.
7993 This is also used when rereading a primary CU with load_all_dies. */
7996 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7997 dwarf2_per_objfile
*per_objfile
)
7999 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 1, false);
8001 if (!reader
.dummy_p
)
8003 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8006 /* Check if comp unit has_children.
8007 If so, read the rest of the partial symbols from this comp unit.
8008 If not, there's no more debug_info for this comp unit. */
8009 if (reader
.comp_unit_die
->has_children
)
8010 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8017 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8018 struct dwarf2_section_info
*section
,
8019 struct dwarf2_section_info
*abbrev_section
,
8020 unsigned int is_dwz
)
8022 const gdb_byte
*info_ptr
;
8023 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8025 if (dwarf_read_debug
)
8026 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8027 section
->get_name (),
8028 section
->get_file_name ());
8030 section
->read (objfile
);
8032 info_ptr
= section
->buffer
;
8034 while (info_ptr
< section
->buffer
+ section
->size
)
8036 struct dwarf2_per_cu_data
*this_cu
;
8038 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8040 comp_unit_head cu_header
;
8041 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8042 abbrev_section
, info_ptr
,
8043 rcuh_kind::COMPILE
);
8045 /* Save the compilation unit for later lookup. */
8046 if (cu_header
.unit_type
!= DW_UT_type
)
8047 this_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
8050 auto sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
8051 sig_type
->signature
= cu_header
.signature
;
8052 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8053 this_cu
= &sig_type
->per_cu
;
8055 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8056 this_cu
->sect_off
= sect_off
;
8057 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8058 this_cu
->is_dwz
= is_dwz
;
8059 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8060 this_cu
->section
= section
;
8062 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8064 info_ptr
= info_ptr
+ this_cu
->length
;
8068 /* Create a list of all compilation units in OBJFILE.
8069 This is only done for -readnow and building partial symtabs. */
8072 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8074 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
8075 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->per_bfd
->info
,
8076 &dwarf2_per_objfile
->per_bfd
->abbrev
, 0);
8078 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
8080 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8084 /* Process all loaded DIEs for compilation unit CU, starting at
8085 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8086 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8087 DW_AT_ranges). See the comments of add_partial_subprogram on how
8088 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8091 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8092 CORE_ADDR
*highpc
, int set_addrmap
,
8093 struct dwarf2_cu
*cu
)
8095 struct partial_die_info
*pdi
;
8097 /* Now, march along the PDI's, descending into ones which have
8098 interesting children but skipping the children of the other ones,
8099 until we reach the end of the compilation unit. */
8107 /* Anonymous namespaces or modules have no name but have interesting
8108 children, so we need to look at them. Ditto for anonymous
8111 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8112 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8113 || pdi
->tag
== DW_TAG_imported_unit
8114 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8118 case DW_TAG_subprogram
:
8119 case DW_TAG_inlined_subroutine
:
8120 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8122 case DW_TAG_constant
:
8123 case DW_TAG_variable
:
8124 case DW_TAG_typedef
:
8125 case DW_TAG_union_type
:
8126 if (!pdi
->is_declaration
8127 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8129 add_partial_symbol (pdi
, cu
);
8132 case DW_TAG_class_type
:
8133 case DW_TAG_interface_type
:
8134 case DW_TAG_structure_type
:
8135 if (!pdi
->is_declaration
)
8137 add_partial_symbol (pdi
, cu
);
8139 if ((cu
->language
== language_rust
8140 || cu
->language
== language_cplus
) && pdi
->has_children
)
8141 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8144 case DW_TAG_enumeration_type
:
8145 if (!pdi
->is_declaration
)
8146 add_partial_enumeration (pdi
, cu
);
8148 case DW_TAG_base_type
:
8149 case DW_TAG_subrange_type
:
8150 /* File scope base type definitions are added to the partial
8152 add_partial_symbol (pdi
, cu
);
8154 case DW_TAG_namespace
:
8155 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8158 if (!pdi
->is_declaration
)
8159 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8161 case DW_TAG_imported_unit
:
8163 struct dwarf2_per_cu_data
*per_cu
;
8165 /* For now we don't handle imported units in type units. */
8166 if (cu
->per_cu
->is_debug_types
)
8168 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8169 " supported in type units [in module %s]"),
8170 objfile_name (cu
->per_objfile
->objfile
));
8173 per_cu
= dwarf2_find_containing_comp_unit
8174 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8176 /* Go read the partial unit, if needed. */
8177 if (per_cu
->v
.psymtab
== NULL
)
8178 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8181 cu
->per_cu
->imported_symtabs_push (per_cu
);
8184 case DW_TAG_imported_declaration
:
8185 add_partial_symbol (pdi
, cu
);
8192 /* If the die has a sibling, skip to the sibling. */
8194 pdi
= pdi
->die_sibling
;
8198 /* Functions used to compute the fully scoped name of a partial DIE.
8200 Normally, this is simple. For C++, the parent DIE's fully scoped
8201 name is concatenated with "::" and the partial DIE's name.
8202 Enumerators are an exception; they use the scope of their parent
8203 enumeration type, i.e. the name of the enumeration type is not
8204 prepended to the enumerator.
8206 There are two complexities. One is DW_AT_specification; in this
8207 case "parent" means the parent of the target of the specification,
8208 instead of the direct parent of the DIE. The other is compilers
8209 which do not emit DW_TAG_namespace; in this case we try to guess
8210 the fully qualified name of structure types from their members'
8211 linkage names. This must be done using the DIE's children rather
8212 than the children of any DW_AT_specification target. We only need
8213 to do this for structures at the top level, i.e. if the target of
8214 any DW_AT_specification (if any; otherwise the DIE itself) does not
8217 /* Compute the scope prefix associated with PDI's parent, in
8218 compilation unit CU. The result will be allocated on CU's
8219 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8220 field. NULL is returned if no prefix is necessary. */
8222 partial_die_parent_scope (struct partial_die_info
*pdi
,
8223 struct dwarf2_cu
*cu
)
8225 const char *grandparent_scope
;
8226 struct partial_die_info
*parent
, *real_pdi
;
8228 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8229 then this means the parent of the specification DIE. */
8232 while (real_pdi
->has_specification
)
8234 auto res
= find_partial_die (real_pdi
->spec_offset
,
8235 real_pdi
->spec_is_dwz
, cu
);
8240 parent
= real_pdi
->die_parent
;
8244 if (parent
->scope_set
)
8245 return parent
->scope
;
8249 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8251 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8252 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8253 Work around this problem here. */
8254 if (cu
->language
== language_cplus
8255 && parent
->tag
== DW_TAG_namespace
8256 && strcmp (parent
->name
, "::") == 0
8257 && grandparent_scope
== NULL
)
8259 parent
->scope
= NULL
;
8260 parent
->scope_set
= 1;
8264 /* Nested subroutines in Fortran get a prefix. */
8265 if (pdi
->tag
== DW_TAG_enumerator
)
8266 /* Enumerators should not get the name of the enumeration as a prefix. */
8267 parent
->scope
= grandparent_scope
;
8268 else if (parent
->tag
== DW_TAG_namespace
8269 || parent
->tag
== DW_TAG_module
8270 || parent
->tag
== DW_TAG_structure_type
8271 || parent
->tag
== DW_TAG_class_type
8272 || parent
->tag
== DW_TAG_interface_type
8273 || parent
->tag
== DW_TAG_union_type
8274 || parent
->tag
== DW_TAG_enumeration_type
8275 || (cu
->language
== language_fortran
8276 && parent
->tag
== DW_TAG_subprogram
8277 && pdi
->tag
== DW_TAG_subprogram
))
8279 if (grandparent_scope
== NULL
)
8280 parent
->scope
= parent
->name
;
8282 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8284 parent
->name
, 0, cu
);
8288 /* FIXME drow/2004-04-01: What should we be doing with
8289 function-local names? For partial symbols, we should probably be
8291 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8292 dwarf_tag_name (parent
->tag
),
8293 sect_offset_str (pdi
->sect_off
));
8294 parent
->scope
= grandparent_scope
;
8297 parent
->scope_set
= 1;
8298 return parent
->scope
;
8301 /* Return the fully scoped name associated with PDI, from compilation unit
8302 CU. The result will be allocated with malloc. */
8304 static gdb::unique_xmalloc_ptr
<char>
8305 partial_die_full_name (struct partial_die_info
*pdi
,
8306 struct dwarf2_cu
*cu
)
8308 const char *parent_scope
;
8310 /* If this is a template instantiation, we can not work out the
8311 template arguments from partial DIEs. So, unfortunately, we have
8312 to go through the full DIEs. At least any work we do building
8313 types here will be reused if full symbols are loaded later. */
8314 if (pdi
->has_template_arguments
)
8318 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8320 struct die_info
*die
;
8321 struct attribute attr
;
8322 struct dwarf2_cu
*ref_cu
= cu
;
8324 /* DW_FORM_ref_addr is using section offset. */
8325 attr
.name
= (enum dwarf_attribute
) 0;
8326 attr
.form
= DW_FORM_ref_addr
;
8327 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8328 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8330 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8334 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8335 if (parent_scope
== NULL
)
8338 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8343 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8345 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
8346 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8347 struct gdbarch
*gdbarch
= objfile
->arch ();
8349 const char *actual_name
= NULL
;
8352 baseaddr
= objfile
->text_section_offset ();
8354 gdb::unique_xmalloc_ptr
<char> built_actual_name
8355 = partial_die_full_name (pdi
, cu
);
8356 if (built_actual_name
!= NULL
)
8357 actual_name
= built_actual_name
.get ();
8359 if (actual_name
== NULL
)
8360 actual_name
= pdi
->name
;
8362 partial_symbol psymbol
;
8363 memset (&psymbol
, 0, sizeof (psymbol
));
8364 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8365 psymbol
.ginfo
.section
= -1;
8367 /* The code below indicates that the psymbol should be installed by
8369 gdb::optional
<psymbol_placement
> where
;
8373 case DW_TAG_inlined_subroutine
:
8374 case DW_TAG_subprogram
:
8375 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8377 if (pdi
->is_external
8378 || cu
->language
== language_ada
8379 || (cu
->language
== language_fortran
8380 && pdi
->die_parent
!= NULL
8381 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8383 /* Normally, only "external" DIEs are part of the global scope.
8384 But in Ada and Fortran, we want to be able to access nested
8385 procedures globally. So all Ada and Fortran subprograms are
8386 stored in the global scope. */
8387 where
= psymbol_placement::GLOBAL
;
8390 where
= psymbol_placement::STATIC
;
8392 psymbol
.domain
= VAR_DOMAIN
;
8393 psymbol
.aclass
= LOC_BLOCK
;
8394 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8395 psymbol
.ginfo
.value
.address
= addr
;
8397 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8398 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8400 case DW_TAG_constant
:
8401 psymbol
.domain
= VAR_DOMAIN
;
8402 psymbol
.aclass
= LOC_STATIC
;
8403 where
= (pdi
->is_external
8404 ? psymbol_placement::GLOBAL
8405 : psymbol_placement::STATIC
);
8407 case DW_TAG_variable
:
8409 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8413 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
8415 /* A global or static variable may also have been stripped
8416 out by the linker if unused, in which case its address
8417 will be nullified; do not add such variables into partial
8418 symbol table then. */
8420 else if (pdi
->is_external
)
8423 Don't enter into the minimal symbol tables as there is
8424 a minimal symbol table entry from the ELF symbols already.
8425 Enter into partial symbol table if it has a location
8426 descriptor or a type.
8427 If the location descriptor is missing, new_symbol will create
8428 a LOC_UNRESOLVED symbol, the address of the variable will then
8429 be determined from the minimal symbol table whenever the variable
8431 The address for the partial symbol table entry is not
8432 used by GDB, but it comes in handy for debugging partial symbol
8435 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8437 psymbol
.domain
= VAR_DOMAIN
;
8438 psymbol
.aclass
= LOC_STATIC
;
8439 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8440 psymbol
.ginfo
.value
.address
= addr
;
8441 where
= psymbol_placement::GLOBAL
;
8446 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8448 /* Static Variable. Skip symbols whose value we cannot know (those
8449 without location descriptors or constant values). */
8450 if (!has_loc
&& !pdi
->has_const_value
)
8453 psymbol
.domain
= VAR_DOMAIN
;
8454 psymbol
.aclass
= LOC_STATIC
;
8455 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8457 psymbol
.ginfo
.value
.address
= addr
;
8458 where
= psymbol_placement::STATIC
;
8461 case DW_TAG_typedef
:
8462 case DW_TAG_base_type
:
8463 case DW_TAG_subrange_type
:
8464 psymbol
.domain
= VAR_DOMAIN
;
8465 psymbol
.aclass
= LOC_TYPEDEF
;
8466 where
= psymbol_placement::STATIC
;
8468 case DW_TAG_imported_declaration
:
8469 case DW_TAG_namespace
:
8470 psymbol
.domain
= VAR_DOMAIN
;
8471 psymbol
.aclass
= LOC_TYPEDEF
;
8472 where
= psymbol_placement::GLOBAL
;
8475 /* With Fortran 77 there might be a "BLOCK DATA" module
8476 available without any name. If so, we skip the module as it
8477 doesn't bring any value. */
8478 if (actual_name
!= nullptr)
8480 psymbol
.domain
= MODULE_DOMAIN
;
8481 psymbol
.aclass
= LOC_TYPEDEF
;
8482 where
= psymbol_placement::GLOBAL
;
8485 case DW_TAG_class_type
:
8486 case DW_TAG_interface_type
:
8487 case DW_TAG_structure_type
:
8488 case DW_TAG_union_type
:
8489 case DW_TAG_enumeration_type
:
8490 /* Skip external references. The DWARF standard says in the section
8491 about "Structure, Union, and Class Type Entries": "An incomplete
8492 structure, union or class type is represented by a structure,
8493 union or class entry that does not have a byte size attribute
8494 and that has a DW_AT_declaration attribute." */
8495 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8498 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8499 static vs. global. */
8500 psymbol
.domain
= STRUCT_DOMAIN
;
8501 psymbol
.aclass
= LOC_TYPEDEF
;
8502 where
= (cu
->language
== language_cplus
8503 ? psymbol_placement::GLOBAL
8504 : psymbol_placement::STATIC
);
8506 case DW_TAG_enumerator
:
8507 psymbol
.domain
= VAR_DOMAIN
;
8508 psymbol
.aclass
= LOC_CONST
;
8509 where
= (cu
->language
== language_cplus
8510 ? psymbol_placement::GLOBAL
8511 : psymbol_placement::STATIC
);
8517 if (where
.has_value ())
8519 if (built_actual_name
!= nullptr)
8520 actual_name
= objfile
->intern (actual_name
);
8521 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8522 psymbol
.ginfo
.set_linkage_name (actual_name
);
8525 psymbol
.ginfo
.set_demangled_name (actual_name
,
8526 &objfile
->objfile_obstack
);
8527 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8529 add_psymbol_to_list (psymbol
, *where
, objfile
);
8533 /* Read a partial die corresponding to a namespace; also, add a symbol
8534 corresponding to that namespace to the symbol table. NAMESPACE is
8535 the name of the enclosing namespace. */
8538 add_partial_namespace (struct partial_die_info
*pdi
,
8539 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8540 int set_addrmap
, struct dwarf2_cu
*cu
)
8542 /* Add a symbol for the namespace. */
8544 add_partial_symbol (pdi
, cu
);
8546 /* Now scan partial symbols in that namespace. */
8548 if (pdi
->has_children
)
8549 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8552 /* Read a partial die corresponding to a Fortran module. */
8555 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8556 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8558 /* Add a symbol for the namespace. */
8560 add_partial_symbol (pdi
, cu
);
8562 /* Now scan partial symbols in that module. */
8564 if (pdi
->has_children
)
8565 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8568 /* Read a partial die corresponding to a subprogram or an inlined
8569 subprogram and create a partial symbol for that subprogram.
8570 When the CU language allows it, this routine also defines a partial
8571 symbol for each nested subprogram that this subprogram contains.
8572 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8573 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8575 PDI may also be a lexical block, in which case we simply search
8576 recursively for subprograms defined inside that lexical block.
8577 Again, this is only performed when the CU language allows this
8578 type of definitions. */
8581 add_partial_subprogram (struct partial_die_info
*pdi
,
8582 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8583 int set_addrmap
, struct dwarf2_cu
*cu
)
8585 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8587 if (pdi
->has_pc_info
)
8589 if (pdi
->lowpc
< *lowpc
)
8590 *lowpc
= pdi
->lowpc
;
8591 if (pdi
->highpc
> *highpc
)
8592 *highpc
= pdi
->highpc
;
8595 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8596 struct gdbarch
*gdbarch
= objfile
->arch ();
8598 CORE_ADDR this_highpc
;
8599 CORE_ADDR this_lowpc
;
8601 baseaddr
= objfile
->text_section_offset ();
8603 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8604 pdi
->lowpc
+ baseaddr
)
8607 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8608 pdi
->highpc
+ baseaddr
)
8610 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8611 this_lowpc
, this_highpc
- 1,
8612 cu
->per_cu
->v
.psymtab
);
8616 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8618 if (!pdi
->is_declaration
)
8619 /* Ignore subprogram DIEs that do not have a name, they are
8620 illegal. Do not emit a complaint at this point, we will
8621 do so when we convert this psymtab into a symtab. */
8623 add_partial_symbol (pdi
, cu
);
8627 if (! pdi
->has_children
)
8630 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8632 pdi
= pdi
->die_child
;
8636 if (pdi
->tag
== DW_TAG_subprogram
8637 || pdi
->tag
== DW_TAG_inlined_subroutine
8638 || pdi
->tag
== DW_TAG_lexical_block
)
8639 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8640 pdi
= pdi
->die_sibling
;
8645 /* Read a partial die corresponding to an enumeration type. */
8648 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8649 struct dwarf2_cu
*cu
)
8651 struct partial_die_info
*pdi
;
8653 if (enum_pdi
->name
!= NULL
)
8654 add_partial_symbol (enum_pdi
, cu
);
8656 pdi
= enum_pdi
->die_child
;
8659 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8660 complaint (_("malformed enumerator DIE ignored"));
8662 add_partial_symbol (pdi
, cu
);
8663 pdi
= pdi
->die_sibling
;
8667 /* Return the initial uleb128 in the die at INFO_PTR. */
8670 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8672 unsigned int bytes_read
;
8674 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8677 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8678 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8680 Return the corresponding abbrev, or NULL if the number is zero (indicating
8681 an empty DIE). In either case *BYTES_READ will be set to the length of
8682 the initial number. */
8684 static struct abbrev_info
*
8685 peek_die_abbrev (const die_reader_specs
&reader
,
8686 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8688 dwarf2_cu
*cu
= reader
.cu
;
8689 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8690 unsigned int abbrev_number
8691 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8693 if (abbrev_number
== 0)
8696 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8699 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8700 " at offset %s [in module %s]"),
8701 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8702 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8708 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8709 Returns a pointer to the end of a series of DIEs, terminated by an empty
8710 DIE. Any children of the skipped DIEs will also be skipped. */
8712 static const gdb_byte
*
8713 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8717 unsigned int bytes_read
;
8718 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8721 return info_ptr
+ bytes_read
;
8723 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8727 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8728 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8729 abbrev corresponding to that skipped uleb128 should be passed in
8730 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8733 static const gdb_byte
*
8734 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8735 struct abbrev_info
*abbrev
)
8737 unsigned int bytes_read
;
8738 struct attribute attr
;
8739 bfd
*abfd
= reader
->abfd
;
8740 struct dwarf2_cu
*cu
= reader
->cu
;
8741 const gdb_byte
*buffer
= reader
->buffer
;
8742 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8743 unsigned int form
, i
;
8745 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8747 /* The only abbrev we care about is DW_AT_sibling. */
8748 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8751 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8753 if (attr
.form
== DW_FORM_ref_addr
)
8754 complaint (_("ignoring absolute DW_AT_sibling"));
8757 sect_offset off
= attr
.get_ref_die_offset ();
8758 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8760 if (sibling_ptr
< info_ptr
)
8761 complaint (_("DW_AT_sibling points backwards"));
8762 else if (sibling_ptr
> reader
->buffer_end
)
8763 reader
->die_section
->overflow_complaint ();
8769 /* If it isn't DW_AT_sibling, skip this attribute. */
8770 form
= abbrev
->attrs
[i
].form
;
8774 case DW_FORM_ref_addr
:
8775 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8776 and later it is offset sized. */
8777 if (cu
->header
.version
== 2)
8778 info_ptr
+= cu
->header
.addr_size
;
8780 info_ptr
+= cu
->header
.offset_size
;
8782 case DW_FORM_GNU_ref_alt
:
8783 info_ptr
+= cu
->header
.offset_size
;
8786 info_ptr
+= cu
->header
.addr_size
;
8794 case DW_FORM_flag_present
:
8795 case DW_FORM_implicit_const
:
8812 case DW_FORM_ref_sig8
:
8815 case DW_FORM_data16
:
8818 case DW_FORM_string
:
8819 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8820 info_ptr
+= bytes_read
;
8822 case DW_FORM_sec_offset
:
8824 case DW_FORM_GNU_strp_alt
:
8825 info_ptr
+= cu
->header
.offset_size
;
8827 case DW_FORM_exprloc
:
8829 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8830 info_ptr
+= bytes_read
;
8832 case DW_FORM_block1
:
8833 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8835 case DW_FORM_block2
:
8836 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8838 case DW_FORM_block4
:
8839 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8845 case DW_FORM_ref_udata
:
8846 case DW_FORM_GNU_addr_index
:
8847 case DW_FORM_GNU_str_index
:
8848 case DW_FORM_rnglistx
:
8849 case DW_FORM_loclistx
:
8850 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8852 case DW_FORM_indirect
:
8853 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8854 info_ptr
+= bytes_read
;
8855 /* We need to continue parsing from here, so just go back to
8857 goto skip_attribute
;
8860 error (_("Dwarf Error: Cannot handle %s "
8861 "in DWARF reader [in module %s]"),
8862 dwarf_form_name (form
),
8863 bfd_get_filename (abfd
));
8867 if (abbrev
->has_children
)
8868 return skip_children (reader
, info_ptr
);
8873 /* Locate ORIG_PDI's sibling.
8874 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8876 static const gdb_byte
*
8877 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8878 struct partial_die_info
*orig_pdi
,
8879 const gdb_byte
*info_ptr
)
8881 /* Do we know the sibling already? */
8883 if (orig_pdi
->sibling
)
8884 return orig_pdi
->sibling
;
8886 /* Are there any children to deal with? */
8888 if (!orig_pdi
->has_children
)
8891 /* Skip the children the long way. */
8893 return skip_children (reader
, info_ptr
);
8896 /* Expand this partial symbol table into a full symbol table. SELF is
8900 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8902 struct dwarf2_per_objfile
*dwarf2_per_objfile
8903 = get_dwarf2_per_objfile (objfile
);
8905 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (per_cu_data
));
8907 /* If this psymtab is constructed from a debug-only objfile, the
8908 has_section_at_zero flag will not necessarily be correct. We
8909 can get the correct value for this flag by looking at the data
8910 associated with the (presumably stripped) associated objfile. */
8911 if (objfile
->separate_debug_objfile_backlink
)
8913 struct dwarf2_per_objfile
*dpo_backlink
8914 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8916 dwarf2_per_objfile
->per_bfd
->has_section_at_zero
8917 = dpo_backlink
->per_bfd
->has_section_at_zero
;
8920 expand_psymtab (objfile
);
8922 process_cu_includes (dwarf2_per_objfile
);
8925 /* Reading in full CUs. */
8927 /* Add PER_CU to the queue. */
8930 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8931 enum language pretend_language
)
8934 per_cu
->per_bfd
->queue
.emplace (per_cu
, pretend_language
);
8937 /* If PER_CU is not yet queued, add it to the queue.
8938 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8940 The result is non-zero if PER_CU was queued, otherwise the result is zero
8941 meaning either PER_CU is already queued or it is already loaded.
8943 N.B. There is an invariant here that if a CU is queued then it is loaded.
8944 The caller is required to load PER_CU if we return non-zero. */
8947 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8948 struct dwarf2_per_cu_data
*per_cu
,
8949 enum language pretend_language
)
8951 /* We may arrive here during partial symbol reading, if we need full
8952 DIEs to process an unusual case (e.g. template arguments). Do
8953 not queue PER_CU, just tell our caller to load its DIEs. */
8954 if (per_cu
->per_bfd
->reading_partial_symbols
)
8956 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8961 /* Mark the dependence relation so that we don't flush PER_CU
8963 if (dependent_cu
!= NULL
)
8964 dwarf2_add_dependence (dependent_cu
, per_cu
);
8966 /* If it's already on the queue, we have nothing to do. */
8970 /* If the compilation unit is already loaded, just mark it as
8972 if (per_cu
->cu
!= NULL
)
8974 per_cu
->cu
->last_used
= 0;
8978 /* Add it to the queue. */
8979 queue_comp_unit (per_cu
, pretend_language
);
8984 /* Process the queue. */
8987 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8989 if (dwarf_read_debug
)
8991 fprintf_unfiltered (gdb_stdlog
,
8992 "Expanding one or more symtabs of objfile %s ...\n",
8993 objfile_name (dwarf2_per_objfile
->objfile
));
8996 /* The queue starts out with one item, but following a DIE reference
8997 may load a new CU, adding it to the end of the queue. */
8998 while (!dwarf2_per_objfile
->per_bfd
->queue
.empty ())
9000 dwarf2_queue_item
&item
= dwarf2_per_objfile
->per_bfd
->queue
.front ();
9002 if (!dwarf2_per_objfile
->symtab_set_p (item
.per_cu
)
9003 /* Skip dummy CUs. */
9004 && item
.per_cu
->cu
!= NULL
)
9006 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9007 unsigned int debug_print_threshold
;
9010 if (per_cu
->is_debug_types
)
9012 struct signatured_type
*sig_type
=
9013 (struct signatured_type
*) per_cu
;
9015 sprintf (buf
, "TU %s at offset %s",
9016 hex_string (sig_type
->signature
),
9017 sect_offset_str (per_cu
->sect_off
));
9018 /* There can be 100s of TUs.
9019 Only print them in verbose mode. */
9020 debug_print_threshold
= 2;
9024 sprintf (buf
, "CU at offset %s",
9025 sect_offset_str (per_cu
->sect_off
));
9026 debug_print_threshold
= 1;
9029 if (dwarf_read_debug
>= debug_print_threshold
)
9030 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9032 if (per_cu
->is_debug_types
)
9033 process_full_type_unit (per_cu
, dwarf2_per_objfile
,
9034 item
.pretend_language
);
9036 process_full_comp_unit (per_cu
, dwarf2_per_objfile
,
9037 item
.pretend_language
);
9039 if (dwarf_read_debug
>= debug_print_threshold
)
9040 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9043 item
.per_cu
->queued
= 0;
9044 dwarf2_per_objfile
->per_bfd
->queue
.pop ();
9047 if (dwarf_read_debug
)
9049 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9050 objfile_name (dwarf2_per_objfile
->objfile
));
9054 /* Read in full symbols for PST, and anything it depends on. */
9057 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9059 gdb_assert (!readin_p (objfile
));
9061 expand_dependencies (objfile
);
9063 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9064 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9065 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9068 /* See psympriv.h. */
9071 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9073 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9074 return per_objfile
->symtab_set_p (per_cu_data
);
9077 /* See psympriv.h. */
9080 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9082 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9083 return per_objfile
->get_symtab (per_cu_data
);
9086 /* Trivial hash function for die_info: the hash value of a DIE
9087 is its offset in .debug_info for this objfile. */
9090 die_hash (const void *item
)
9092 const struct die_info
*die
= (const struct die_info
*) item
;
9094 return to_underlying (die
->sect_off
);
9097 /* Trivial comparison function for die_info structures: two DIEs
9098 are equal if they have the same offset. */
9101 die_eq (const void *item_lhs
, const void *item_rhs
)
9103 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9104 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9106 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9109 /* Load the DIEs associated with PER_CU into memory. */
9112 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9113 dwarf2_per_objfile
*per_objfile
,
9115 enum language pretend_language
)
9117 gdb_assert (! this_cu
->is_debug_types
);
9119 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 1, skip_partial
);
9123 struct dwarf2_cu
*cu
= reader
.cu
;
9124 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9126 gdb_assert (cu
->die_hash
== NULL
);
9128 htab_create_alloc_ex (cu
->header
.length
/ 12,
9132 &cu
->comp_unit_obstack
,
9133 hashtab_obstack_allocate
,
9134 dummy_obstack_deallocate
);
9136 if (reader
.comp_unit_die
->has_children
)
9137 reader
.comp_unit_die
->child
9138 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9139 &info_ptr
, reader
.comp_unit_die
);
9140 cu
->dies
= reader
.comp_unit_die
;
9141 /* comp_unit_die is not stored in die_hash, no need. */
9143 /* We try not to read any attributes in this function, because not
9144 all CUs needed for references have been loaded yet, and symbol
9145 table processing isn't initialized. But we have to set the CU language,
9146 or we won't be able to build types correctly.
9147 Similarly, if we do not read the producer, we can not apply
9148 producer-specific interpretation. */
9149 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9154 /* Add a DIE to the delayed physname list. */
9157 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9158 const char *name
, struct die_info
*die
,
9159 struct dwarf2_cu
*cu
)
9161 struct delayed_method_info mi
;
9163 mi
.fnfield_index
= fnfield_index
;
9167 cu
->method_list
.push_back (mi
);
9170 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9171 "const" / "volatile". If so, decrements LEN by the length of the
9172 modifier and return true. Otherwise return false. */
9176 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9178 size_t mod_len
= sizeof (mod
) - 1;
9179 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9187 /* Compute the physnames of any methods on the CU's method list.
9189 The computation of method physnames is delayed in order to avoid the
9190 (bad) condition that one of the method's formal parameters is of an as yet
9194 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9196 /* Only C++ delays computing physnames. */
9197 if (cu
->method_list
.empty ())
9199 gdb_assert (cu
->language
== language_cplus
);
9201 for (const delayed_method_info
&mi
: cu
->method_list
)
9203 const char *physname
;
9204 struct fn_fieldlist
*fn_flp
9205 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9206 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9207 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9208 = physname
? physname
: "";
9210 /* Since there's no tag to indicate whether a method is a
9211 const/volatile overload, extract that information out of the
9213 if (physname
!= NULL
)
9215 size_t len
= strlen (physname
);
9219 if (physname
[len
] == ')') /* shortcut */
9221 else if (check_modifier (physname
, len
, " const"))
9222 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9223 else if (check_modifier (physname
, len
, " volatile"))
9224 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9231 /* The list is no longer needed. */
9232 cu
->method_list
.clear ();
9235 /* Go objects should be embedded in a DW_TAG_module DIE,
9236 and it's not clear if/how imported objects will appear.
9237 To keep Go support simple until that's worked out,
9238 go back through what we've read and create something usable.
9239 We could do this while processing each DIE, and feels kinda cleaner,
9240 but that way is more invasive.
9241 This is to, for example, allow the user to type "p var" or "b main"
9242 without having to specify the package name, and allow lookups
9243 of module.object to work in contexts that use the expression
9247 fixup_go_packaging (struct dwarf2_cu
*cu
)
9249 gdb::unique_xmalloc_ptr
<char> package_name
;
9250 struct pending
*list
;
9253 for (list
= *cu
->get_builder ()->get_global_symbols ();
9257 for (i
= 0; i
< list
->nsyms
; ++i
)
9259 struct symbol
*sym
= list
->symbol
[i
];
9261 if (sym
->language () == language_go
9262 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9264 gdb::unique_xmalloc_ptr
<char> this_package_name
9265 (go_symbol_package_name (sym
));
9267 if (this_package_name
== NULL
)
9269 if (package_name
== NULL
)
9270 package_name
= std::move (this_package_name
);
9273 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9274 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9275 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9276 (symbol_symtab (sym
) != NULL
9277 ? symtab_to_filename_for_display
9278 (symbol_symtab (sym
))
9279 : objfile_name (objfile
)),
9280 this_package_name
.get (), package_name
.get ());
9286 if (package_name
!= NULL
)
9288 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9289 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9290 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9291 saved_package_name
);
9294 sym
= new (&objfile
->objfile_obstack
) symbol
;
9295 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9296 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9297 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9298 e.g., "main" finds the "main" module and not C's main(). */
9299 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9300 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9301 SYMBOL_TYPE (sym
) = type
;
9303 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9307 /* Allocate a fully-qualified name consisting of the two parts on the
9311 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9313 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9316 /* A helper that allocates a variant part to attach to a Rust enum
9317 type. OBSTACK is where the results should be allocated. TYPE is
9318 the type we're processing. DISCRIMINANT_INDEX is the index of the
9319 discriminant. It must be the index of one of the fields of TYPE.
9320 DEFAULT_INDEX is the index of the default field; or -1 if there is
9321 no default. RANGES is indexed by "effective" field number (the
9322 field index, but omitting the discriminant and default fields) and
9323 must hold the discriminant values used by the variants. Note that
9324 RANGES must have a lifetime at least as long as OBSTACK -- either
9325 already allocated on it, or static. */
9328 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9329 int discriminant_index
, int default_index
,
9330 gdb::array_view
<discriminant_range
> ranges
)
9332 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9333 must be handled by the caller. */
9334 gdb_assert (discriminant_index
>= 0
9335 && discriminant_index
< type
->num_fields ());
9336 gdb_assert (default_index
== -1
9337 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9339 /* We have one variant for each non-discriminant field. */
9340 int n_variants
= type
->num_fields () - 1;
9342 variant
*variants
= new (obstack
) variant
[n_variants
];
9345 for (int i
= 0; i
< type
->num_fields (); ++i
)
9347 if (i
== discriminant_index
)
9350 variants
[var_idx
].first_field
= i
;
9351 variants
[var_idx
].last_field
= i
+ 1;
9353 /* The default field does not need a range, but other fields do.
9354 We skipped the discriminant above. */
9355 if (i
!= default_index
)
9357 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9364 gdb_assert (range_idx
== ranges
.size ());
9365 gdb_assert (var_idx
== n_variants
);
9367 variant_part
*part
= new (obstack
) variant_part
;
9368 part
->discriminant_index
= discriminant_index
;
9369 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9370 discriminant_index
));
9371 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9373 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9374 gdb::array_view
<variant_part
> *prop_value
9375 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9377 struct dynamic_prop prop
;
9378 prop
.kind
= PROP_VARIANT_PARTS
;
9379 prop
.data
.variant_parts
= prop_value
;
9381 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9384 /* Some versions of rustc emitted enums in an unusual way.
9386 Ordinary enums were emitted as unions. The first element of each
9387 structure in the union was named "RUST$ENUM$DISR". This element
9388 held the discriminant.
9390 These versions of Rust also implemented the "non-zero"
9391 optimization. When the enum had two values, and one is empty and
9392 the other holds a pointer that cannot be zero, the pointer is used
9393 as the discriminant, with a zero value meaning the empty variant.
9394 Here, the union's first member is of the form
9395 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9396 where the fieldnos are the indices of the fields that should be
9397 traversed in order to find the field (which may be several fields deep)
9398 and the variantname is the name of the variant of the case when the
9401 This function recognizes whether TYPE is of one of these forms,
9402 and, if so, smashes it to be a variant type. */
9405 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9407 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9409 /* We don't need to deal with empty enums. */
9410 if (type
->num_fields () == 0)
9413 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9414 if (type
->num_fields () == 1
9415 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9417 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9419 /* Decode the field name to find the offset of the
9421 ULONGEST bit_offset
= 0;
9422 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9423 while (name
[0] >= '0' && name
[0] <= '9')
9426 unsigned long index
= strtoul (name
, &tail
, 10);
9429 || index
>= field_type
->num_fields ()
9430 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9431 != FIELD_LOC_KIND_BITPOS
))
9433 complaint (_("Could not parse Rust enum encoding string \"%s\""
9435 TYPE_FIELD_NAME (type
, 0),
9436 objfile_name (objfile
));
9441 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9442 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9445 /* Smash this type to be a structure type. We have to do this
9446 because the type has already been recorded. */
9447 type
->set_code (TYPE_CODE_STRUCT
);
9448 type
->set_num_fields (3);
9449 /* Save the field we care about. */
9450 struct field saved_field
= type
->field (0);
9452 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9454 /* Put the discriminant at index 0. */
9455 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9456 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9457 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9458 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9460 /* The order of fields doesn't really matter, so put the real
9461 field at index 1 and the data-less field at index 2. */
9462 type
->field (1) = saved_field
;
9463 TYPE_FIELD_NAME (type
, 1)
9464 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9465 TYPE_FIELD_TYPE (type
, 1)->set_name
9466 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9467 TYPE_FIELD_NAME (type
, 1)));
9469 const char *dataless_name
9470 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9472 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9474 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9475 /* NAME points into the original discriminant name, which
9476 already has the correct lifetime. */
9477 TYPE_FIELD_NAME (type
, 2) = name
;
9478 SET_FIELD_BITPOS (type
->field (2), 0);
9480 /* Indicate that this is a variant type. */
9481 static discriminant_range ranges
[1] = { { 0, 0 } };
9482 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9484 /* A union with a single anonymous field is probably an old-style
9486 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9488 /* Smash this type to be a structure type. We have to do this
9489 because the type has already been recorded. */
9490 type
->set_code (TYPE_CODE_STRUCT
);
9492 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9493 const char *variant_name
9494 = rust_last_path_segment (field_type
->name ());
9495 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9496 field_type
->set_name
9497 (rust_fully_qualify (&objfile
->objfile_obstack
,
9498 type
->name (), variant_name
));
9502 struct type
*disr_type
= nullptr;
9503 for (int i
= 0; i
< type
->num_fields (); ++i
)
9505 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9507 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9509 /* All fields of a true enum will be structs. */
9512 else if (disr_type
->num_fields () == 0)
9514 /* Could be data-less variant, so keep going. */
9515 disr_type
= nullptr;
9517 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9518 "RUST$ENUM$DISR") != 0)
9520 /* Not a Rust enum. */
9530 /* If we got here without a discriminant, then it's probably
9532 if (disr_type
== nullptr)
9535 /* Smash this type to be a structure type. We have to do this
9536 because the type has already been recorded. */
9537 type
->set_code (TYPE_CODE_STRUCT
);
9539 /* Make space for the discriminant field. */
9540 struct field
*disr_field
= &disr_type
->field (0);
9542 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9543 * sizeof (struct field
)));
9544 memcpy (new_fields
+ 1, type
->fields (),
9545 type
->num_fields () * sizeof (struct field
));
9546 type
->set_fields (new_fields
);
9547 type
->set_num_fields (type
->num_fields () + 1);
9549 /* Install the discriminant at index 0 in the union. */
9550 type
->field (0) = *disr_field
;
9551 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9552 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9554 /* We need a way to find the correct discriminant given a
9555 variant name. For convenience we build a map here. */
9556 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9557 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9558 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9560 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9563 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9564 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9568 int n_fields
= type
->num_fields ();
9569 /* We don't need a range entry for the discriminant, but we do
9570 need one for every other field, as there is no default
9572 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9575 /* Skip the discriminant here. */
9576 for (int i
= 1; i
< n_fields
; ++i
)
9578 /* Find the final word in the name of this variant's type.
9579 That name can be used to look up the correct
9581 const char *variant_name
9582 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9584 auto iter
= discriminant_map
.find (variant_name
);
9585 if (iter
!= discriminant_map
.end ())
9587 ranges
[i
].low
= iter
->second
;
9588 ranges
[i
].high
= iter
->second
;
9591 /* Remove the discriminant field, if it exists. */
9592 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9593 if (sub_type
->num_fields () > 0)
9595 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9596 sub_type
->set_fields (sub_type
->fields () + 1);
9598 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9600 (rust_fully_qualify (&objfile
->objfile_obstack
,
9601 type
->name (), variant_name
));
9604 /* Indicate that this is a variant type. */
9605 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9606 gdb::array_view
<discriminant_range
> (ranges
,
9611 /* Rewrite some Rust unions to be structures with variants parts. */
9614 rust_union_quirks (struct dwarf2_cu
*cu
)
9616 gdb_assert (cu
->language
== language_rust
);
9617 for (type
*type_
: cu
->rust_unions
)
9618 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9619 /* We don't need this any more. */
9620 cu
->rust_unions
.clear ();
9623 /* A helper function for computing the list of all symbol tables
9624 included by PER_CU. */
9627 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9628 htab_t all_children
, htab_t all_type_symtabs
,
9629 dwarf2_per_cu_data
*per_cu
,
9630 dwarf2_per_objfile
*per_objfile
,
9631 struct compunit_symtab
*immediate_parent
)
9633 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9636 /* This inclusion and its children have been processed. */
9642 /* Only add a CU if it has a symbol table. */
9643 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9646 /* If this is a type unit only add its symbol table if we haven't
9647 seen it yet (type unit per_cu's can share symtabs). */
9648 if (per_cu
->is_debug_types
)
9650 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9654 result
->push_back (cust
);
9655 if (cust
->user
== NULL
)
9656 cust
->user
= immediate_parent
;
9661 result
->push_back (cust
);
9662 if (cust
->user
== NULL
)
9663 cust
->user
= immediate_parent
;
9667 if (!per_cu
->imported_symtabs_empty ())
9668 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9670 recursively_compute_inclusions (result
, all_children
,
9671 all_type_symtabs
, ptr
, per_objfile
,
9676 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9680 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9681 dwarf2_per_objfile
*per_objfile
)
9683 gdb_assert (! per_cu
->is_debug_types
);
9685 if (!per_cu
->imported_symtabs_empty ())
9688 std::vector
<compunit_symtab
*> result_symtabs
;
9689 htab_t all_children
, all_type_symtabs
;
9690 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9692 /* If we don't have a symtab, we can just skip this case. */
9696 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9697 NULL
, xcalloc
, xfree
);
9698 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9699 NULL
, xcalloc
, xfree
);
9701 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9703 recursively_compute_inclusions (&result_symtabs
, all_children
,
9704 all_type_symtabs
, ptr
, per_objfile
,
9708 /* Now we have a transitive closure of all the included symtabs. */
9709 len
= result_symtabs
.size ();
9711 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9712 struct compunit_symtab
*, len
+ 1);
9713 memcpy (cust
->includes
, result_symtabs
.data (),
9714 len
* sizeof (compunit_symtab
*));
9715 cust
->includes
[len
] = NULL
;
9717 htab_delete (all_children
);
9718 htab_delete (all_type_symtabs
);
9722 /* Compute the 'includes' field for the symtabs of all the CUs we just
9726 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9728 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->per_bfd
->just_read_cus
)
9730 if (! iter
->is_debug_types
)
9731 compute_compunit_symtab_includes (iter
, dwarf2_per_objfile
);
9734 dwarf2_per_objfile
->per_bfd
->just_read_cus
.clear ();
9737 /* Generate full symbol information for PER_CU, whose DIEs have
9738 already been loaded into memory. */
9741 process_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
9742 dwarf2_per_objfile
*dwarf2_per_objfile
,
9743 enum language pretend_language
)
9745 struct dwarf2_cu
*cu
= per_cu
->cu
;
9746 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9747 struct gdbarch
*gdbarch
= objfile
->arch ();
9748 CORE_ADDR lowpc
, highpc
;
9749 struct compunit_symtab
*cust
;
9751 struct block
*static_block
;
9754 baseaddr
= objfile
->text_section_offset ();
9756 /* Clear the list here in case something was left over. */
9757 cu
->method_list
.clear ();
9759 cu
->language
= pretend_language
;
9760 cu
->language_defn
= language_def (cu
->language
);
9762 /* Do line number decoding in read_file_scope () */
9763 process_die (cu
->dies
, cu
);
9765 /* For now fudge the Go package. */
9766 if (cu
->language
== language_go
)
9767 fixup_go_packaging (cu
);
9769 /* Now that we have processed all the DIEs in the CU, all the types
9770 should be complete, and it should now be safe to compute all of the
9772 compute_delayed_physnames (cu
);
9774 if (cu
->language
== language_rust
)
9775 rust_union_quirks (cu
);
9777 /* Some compilers don't define a DW_AT_high_pc attribute for the
9778 compilation unit. If the DW_AT_high_pc is missing, synthesize
9779 it, by scanning the DIE's below the compilation unit. */
9780 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9782 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9783 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9785 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9786 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9787 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9788 addrmap to help ensure it has an accurate map of pc values belonging to
9790 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9792 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9793 SECT_OFF_TEXT (objfile
),
9798 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9800 /* Set symtab language to language from DW_AT_language. If the
9801 compilation is from a C file generated by language preprocessors, do
9802 not set the language if it was already deduced by start_subfile. */
9803 if (!(cu
->language
== language_c
9804 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9805 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9807 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9808 produce DW_AT_location with location lists but it can be possibly
9809 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9810 there were bugs in prologue debug info, fixed later in GCC-4.5
9811 by "unwind info for epilogues" patch (which is not directly related).
9813 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9814 needed, it would be wrong due to missing DW_AT_producer there.
9816 Still one can confuse GDB by using non-standard GCC compilation
9817 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9819 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9820 cust
->locations_valid
= 1;
9822 if (gcc_4_minor
>= 5)
9823 cust
->epilogue_unwind_valid
= 1;
9825 cust
->call_site_htab
= cu
->call_site_htab
;
9828 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9830 /* Push it for inclusion processing later. */
9831 dwarf2_per_objfile
->per_bfd
->just_read_cus
.push_back (per_cu
);
9833 /* Not needed any more. */
9834 cu
->reset_builder ();
9837 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9838 already been loaded into memory. */
9841 process_full_type_unit (dwarf2_per_cu_data
*per_cu
,
9842 dwarf2_per_objfile
*dwarf2_per_objfile
,
9843 enum language pretend_language
)
9845 struct dwarf2_cu
*cu
= per_cu
->cu
;
9846 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9847 struct compunit_symtab
*cust
;
9848 struct signatured_type
*sig_type
;
9850 gdb_assert (per_cu
->is_debug_types
);
9851 sig_type
= (struct signatured_type
*) per_cu
;
9853 /* Clear the list here in case something was left over. */
9854 cu
->method_list
.clear ();
9856 cu
->language
= pretend_language
;
9857 cu
->language_defn
= language_def (cu
->language
);
9859 /* The symbol tables are set up in read_type_unit_scope. */
9860 process_die (cu
->dies
, cu
);
9862 /* For now fudge the Go package. */
9863 if (cu
->language
== language_go
)
9864 fixup_go_packaging (cu
);
9866 /* Now that we have processed all the DIEs in the CU, all the types
9867 should be complete, and it should now be safe to compute all of the
9869 compute_delayed_physnames (cu
);
9871 if (cu
->language
== language_rust
)
9872 rust_union_quirks (cu
);
9874 /* TUs share symbol tables.
9875 If this is the first TU to use this symtab, complete the construction
9876 of it with end_expandable_symtab. Otherwise, complete the addition of
9877 this TU's symbols to the existing symtab. */
9878 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9880 buildsym_compunit
*builder
= cu
->get_builder ();
9881 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9882 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9886 /* Set symtab language to language from DW_AT_language. If the
9887 compilation is from a C file generated by language preprocessors,
9888 do not set the language if it was already deduced by
9890 if (!(cu
->language
== language_c
9891 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9892 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9897 cu
->get_builder ()->augment_type_symtab ();
9898 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9901 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9903 /* Not needed any more. */
9904 cu
->reset_builder ();
9907 /* Process an imported unit DIE. */
9910 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9912 struct attribute
*attr
;
9914 /* For now we don't handle imported units in type units. */
9915 if (cu
->per_cu
->is_debug_types
)
9917 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9918 " supported in type units [in module %s]"),
9919 objfile_name (cu
->per_objfile
->objfile
));
9922 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9925 sect_offset sect_off
= attr
->get_ref_die_offset ();
9926 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9927 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9928 dwarf2_per_cu_data
*per_cu
9929 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9931 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9932 into another compilation unit, at root level. Regard this as a hint,
9934 if (die
->parent
&& die
->parent
->parent
== NULL
9935 && per_cu
->unit_type
== DW_UT_compile
9936 && per_cu
->lang
== language_cplus
)
9939 /* If necessary, add it to the queue and load its DIEs. */
9940 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9941 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
9943 cu
->per_cu
->imported_symtabs_push (per_cu
);
9947 /* RAII object that represents a process_die scope: i.e.,
9948 starts/finishes processing a DIE. */
9949 class process_die_scope
9952 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9953 : m_die (die
), m_cu (cu
)
9955 /* We should only be processing DIEs not already in process. */
9956 gdb_assert (!m_die
->in_process
);
9957 m_die
->in_process
= true;
9960 ~process_die_scope ()
9962 m_die
->in_process
= false;
9964 /* If we're done processing the DIE for the CU that owns the line
9965 header, we don't need the line header anymore. */
9966 if (m_cu
->line_header_die_owner
== m_die
)
9968 delete m_cu
->line_header
;
9969 m_cu
->line_header
= NULL
;
9970 m_cu
->line_header_die_owner
= NULL
;
9979 /* Process a die and its children. */
9982 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9984 process_die_scope
scope (die
, cu
);
9988 case DW_TAG_padding
:
9990 case DW_TAG_compile_unit
:
9991 case DW_TAG_partial_unit
:
9992 read_file_scope (die
, cu
);
9994 case DW_TAG_type_unit
:
9995 read_type_unit_scope (die
, cu
);
9997 case DW_TAG_subprogram
:
9998 /* Nested subprograms in Fortran get a prefix. */
9999 if (cu
->language
== language_fortran
10000 && die
->parent
!= NULL
10001 && die
->parent
->tag
== DW_TAG_subprogram
)
10002 cu
->processing_has_namespace_info
= true;
10003 /* Fall through. */
10004 case DW_TAG_inlined_subroutine
:
10005 read_func_scope (die
, cu
);
10007 case DW_TAG_lexical_block
:
10008 case DW_TAG_try_block
:
10009 case DW_TAG_catch_block
:
10010 read_lexical_block_scope (die
, cu
);
10012 case DW_TAG_call_site
:
10013 case DW_TAG_GNU_call_site
:
10014 read_call_site_scope (die
, cu
);
10016 case DW_TAG_class_type
:
10017 case DW_TAG_interface_type
:
10018 case DW_TAG_structure_type
:
10019 case DW_TAG_union_type
:
10020 process_structure_scope (die
, cu
);
10022 case DW_TAG_enumeration_type
:
10023 process_enumeration_scope (die
, cu
);
10026 /* These dies have a type, but processing them does not create
10027 a symbol or recurse to process the children. Therefore we can
10028 read them on-demand through read_type_die. */
10029 case DW_TAG_subroutine_type
:
10030 case DW_TAG_set_type
:
10031 case DW_TAG_array_type
:
10032 case DW_TAG_pointer_type
:
10033 case DW_TAG_ptr_to_member_type
:
10034 case DW_TAG_reference_type
:
10035 case DW_TAG_rvalue_reference_type
:
10036 case DW_TAG_string_type
:
10039 case DW_TAG_base_type
:
10040 case DW_TAG_subrange_type
:
10041 case DW_TAG_typedef
:
10042 /* Add a typedef symbol for the type definition, if it has a
10044 new_symbol (die
, read_type_die (die
, cu
), cu
);
10046 case DW_TAG_common_block
:
10047 read_common_block (die
, cu
);
10049 case DW_TAG_common_inclusion
:
10051 case DW_TAG_namespace
:
10052 cu
->processing_has_namespace_info
= true;
10053 read_namespace (die
, cu
);
10055 case DW_TAG_module
:
10056 cu
->processing_has_namespace_info
= true;
10057 read_module (die
, cu
);
10059 case DW_TAG_imported_declaration
:
10060 cu
->processing_has_namespace_info
= true;
10061 if (read_namespace_alias (die
, cu
))
10063 /* The declaration is not a global namespace alias. */
10064 /* Fall through. */
10065 case DW_TAG_imported_module
:
10066 cu
->processing_has_namespace_info
= true;
10067 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10068 || cu
->language
!= language_fortran
))
10069 complaint (_("Tag '%s' has unexpected children"),
10070 dwarf_tag_name (die
->tag
));
10071 read_import_statement (die
, cu
);
10074 case DW_TAG_imported_unit
:
10075 process_imported_unit_die (die
, cu
);
10078 case DW_TAG_variable
:
10079 read_variable (die
, cu
);
10083 new_symbol (die
, NULL
, cu
);
10088 /* DWARF name computation. */
10090 /* A helper function for dwarf2_compute_name which determines whether DIE
10091 needs to have the name of the scope prepended to the name listed in the
10095 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10097 struct attribute
*attr
;
10101 case DW_TAG_namespace
:
10102 case DW_TAG_typedef
:
10103 case DW_TAG_class_type
:
10104 case DW_TAG_interface_type
:
10105 case DW_TAG_structure_type
:
10106 case DW_TAG_union_type
:
10107 case DW_TAG_enumeration_type
:
10108 case DW_TAG_enumerator
:
10109 case DW_TAG_subprogram
:
10110 case DW_TAG_inlined_subroutine
:
10111 case DW_TAG_member
:
10112 case DW_TAG_imported_declaration
:
10115 case DW_TAG_variable
:
10116 case DW_TAG_constant
:
10117 /* We only need to prefix "globally" visible variables. These include
10118 any variable marked with DW_AT_external or any variable that
10119 lives in a namespace. [Variables in anonymous namespaces
10120 require prefixing, but they are not DW_AT_external.] */
10122 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10124 struct dwarf2_cu
*spec_cu
= cu
;
10126 return die_needs_namespace (die_specification (die
, &spec_cu
),
10130 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10131 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10132 && die
->parent
->tag
!= DW_TAG_module
)
10134 /* A variable in a lexical block of some kind does not need a
10135 namespace, even though in C++ such variables may be external
10136 and have a mangled name. */
10137 if (die
->parent
->tag
== DW_TAG_lexical_block
10138 || die
->parent
->tag
== DW_TAG_try_block
10139 || die
->parent
->tag
== DW_TAG_catch_block
10140 || die
->parent
->tag
== DW_TAG_subprogram
)
10149 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10150 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10151 defined for the given DIE. */
10153 static struct attribute
*
10154 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10156 struct attribute
*attr
;
10158 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10160 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10165 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10166 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10167 defined for the given DIE. */
10169 static const char *
10170 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10172 const char *linkage_name
;
10174 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10175 if (linkage_name
== NULL
)
10176 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10178 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10179 See https://github.com/rust-lang/rust/issues/32925. */
10180 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10181 && strchr (linkage_name
, '{') != NULL
)
10182 linkage_name
= NULL
;
10184 return linkage_name
;
10187 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10188 compute the physname for the object, which include a method's:
10189 - formal parameters (C++),
10190 - receiver type (Go),
10192 The term "physname" is a bit confusing.
10193 For C++, for example, it is the demangled name.
10194 For Go, for example, it's the mangled name.
10196 For Ada, return the DIE's linkage name rather than the fully qualified
10197 name. PHYSNAME is ignored..
10199 The result is allocated on the objfile->per_bfd's obstack and
10202 static const char *
10203 dwarf2_compute_name (const char *name
,
10204 struct die_info
*die
, struct dwarf2_cu
*cu
,
10207 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10210 name
= dwarf2_name (die
, cu
);
10212 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10213 but otherwise compute it by typename_concat inside GDB.
10214 FIXME: Actually this is not really true, or at least not always true.
10215 It's all very confusing. compute_and_set_names doesn't try to demangle
10216 Fortran names because there is no mangling standard. So new_symbol
10217 will set the demangled name to the result of dwarf2_full_name, and it is
10218 the demangled name that GDB uses if it exists. */
10219 if (cu
->language
== language_ada
10220 || (cu
->language
== language_fortran
&& physname
))
10222 /* For Ada unit, we prefer the linkage name over the name, as
10223 the former contains the exported name, which the user expects
10224 to be able to reference. Ideally, we want the user to be able
10225 to reference this entity using either natural or linkage name,
10226 but we haven't started looking at this enhancement yet. */
10227 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10229 if (linkage_name
!= NULL
)
10230 return linkage_name
;
10233 /* These are the only languages we know how to qualify names in. */
10235 && (cu
->language
== language_cplus
10236 || cu
->language
== language_fortran
|| cu
->language
== language_d
10237 || cu
->language
== language_rust
))
10239 if (die_needs_namespace (die
, cu
))
10241 const char *prefix
;
10242 const char *canonical_name
= NULL
;
10246 prefix
= determine_prefix (die
, cu
);
10247 if (*prefix
!= '\0')
10249 gdb::unique_xmalloc_ptr
<char> prefixed_name
10250 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10252 buf
.puts (prefixed_name
.get ());
10257 /* Template parameters may be specified in the DIE's DW_AT_name, or
10258 as children with DW_TAG_template_type_param or
10259 DW_TAG_value_type_param. If the latter, add them to the name
10260 here. If the name already has template parameters, then
10261 skip this step; some versions of GCC emit both, and
10262 it is more efficient to use the pre-computed name.
10264 Something to keep in mind about this process: it is very
10265 unlikely, or in some cases downright impossible, to produce
10266 something that will match the mangled name of a function.
10267 If the definition of the function has the same debug info,
10268 we should be able to match up with it anyway. But fallbacks
10269 using the minimal symbol, for instance to find a method
10270 implemented in a stripped copy of libstdc++, will not work.
10271 If we do not have debug info for the definition, we will have to
10272 match them up some other way.
10274 When we do name matching there is a related problem with function
10275 templates; two instantiated function templates are allowed to
10276 differ only by their return types, which we do not add here. */
10278 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10280 struct attribute
*attr
;
10281 struct die_info
*child
;
10284 die
->building_fullname
= 1;
10286 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10290 const gdb_byte
*bytes
;
10291 struct dwarf2_locexpr_baton
*baton
;
10294 if (child
->tag
!= DW_TAG_template_type_param
10295 && child
->tag
!= DW_TAG_template_value_param
)
10306 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10309 complaint (_("template parameter missing DW_AT_type"));
10310 buf
.puts ("UNKNOWN_TYPE");
10313 type
= die_type (child
, cu
);
10315 if (child
->tag
== DW_TAG_template_type_param
)
10317 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10318 &type_print_raw_options
);
10322 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10325 complaint (_("template parameter missing "
10326 "DW_AT_const_value"));
10327 buf
.puts ("UNKNOWN_VALUE");
10331 dwarf2_const_value_attr (attr
, type
, name
,
10332 &cu
->comp_unit_obstack
, cu
,
10333 &value
, &bytes
, &baton
);
10335 if (TYPE_NOSIGN (type
))
10336 /* GDB prints characters as NUMBER 'CHAR'. If that's
10337 changed, this can use value_print instead. */
10338 c_printchar (value
, type
, &buf
);
10341 struct value_print_options opts
;
10344 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10348 else if (bytes
!= NULL
)
10350 v
= allocate_value (type
);
10351 memcpy (value_contents_writeable (v
), bytes
,
10352 TYPE_LENGTH (type
));
10355 v
= value_from_longest (type
, value
);
10357 /* Specify decimal so that we do not depend on
10359 get_formatted_print_options (&opts
, 'd');
10361 value_print (v
, &buf
, &opts
);
10366 die
->building_fullname
= 0;
10370 /* Close the argument list, with a space if necessary
10371 (nested templates). */
10372 if (!buf
.empty () && buf
.string ().back () == '>')
10379 /* For C++ methods, append formal parameter type
10380 information, if PHYSNAME. */
10382 if (physname
&& die
->tag
== DW_TAG_subprogram
10383 && cu
->language
== language_cplus
)
10385 struct type
*type
= read_type_die (die
, cu
);
10387 c_type_print_args (type
, &buf
, 1, cu
->language
,
10388 &type_print_raw_options
);
10390 if (cu
->language
== language_cplus
)
10392 /* Assume that an artificial first parameter is
10393 "this", but do not crash if it is not. RealView
10394 marks unnamed (and thus unused) parameters as
10395 artificial; there is no way to differentiate
10397 if (type
->num_fields () > 0
10398 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10399 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10400 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10402 buf
.puts (" const");
10406 const std::string
&intermediate_name
= buf
.string ();
10408 if (cu
->language
== language_cplus
)
10410 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10413 /* If we only computed INTERMEDIATE_NAME, or if
10414 INTERMEDIATE_NAME is already canonical, then we need to
10416 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10417 name
= objfile
->intern (intermediate_name
);
10419 name
= canonical_name
;
10426 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10427 If scope qualifiers are appropriate they will be added. The result
10428 will be allocated on the storage_obstack, or NULL if the DIE does
10429 not have a name. NAME may either be from a previous call to
10430 dwarf2_name or NULL.
10432 The output string will be canonicalized (if C++). */
10434 static const char *
10435 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10437 return dwarf2_compute_name (name
, die
, cu
, 0);
10440 /* Construct a physname for the given DIE in CU. NAME may either be
10441 from a previous call to dwarf2_name or NULL. The result will be
10442 allocated on the objfile_objstack or NULL if the DIE does not have a
10445 The output string will be canonicalized (if C++). */
10447 static const char *
10448 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10450 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10451 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10454 /* In this case dwarf2_compute_name is just a shortcut not building anything
10456 if (!die_needs_namespace (die
, cu
))
10457 return dwarf2_compute_name (name
, die
, cu
, 1);
10459 if (cu
->language
!= language_rust
)
10460 mangled
= dw2_linkage_name (die
, cu
);
10462 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10464 gdb::unique_xmalloc_ptr
<char> demangled
;
10465 if (mangled
!= NULL
)
10468 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10470 /* Do nothing (do not demangle the symbol name). */
10472 else if (cu
->language
== language_go
)
10474 /* This is a lie, but we already lie to the caller new_symbol.
10475 new_symbol assumes we return the mangled name.
10476 This just undoes that lie until things are cleaned up. */
10480 /* Use DMGL_RET_DROP for C++ template functions to suppress
10481 their return type. It is easier for GDB users to search
10482 for such functions as `name(params)' than `long name(params)'.
10483 In such case the minimal symbol names do not match the full
10484 symbol names but for template functions there is never a need
10485 to look up their definition from their declaration so
10486 the only disadvantage remains the minimal symbol variant
10487 `long name(params)' does not have the proper inferior type. */
10488 demangled
.reset (gdb_demangle (mangled
,
10489 (DMGL_PARAMS
| DMGL_ANSI
10490 | DMGL_RET_DROP
)));
10493 canon
= demangled
.get ();
10501 if (canon
== NULL
|| check_physname
)
10503 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10505 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10507 /* It may not mean a bug in GDB. The compiler could also
10508 compute DW_AT_linkage_name incorrectly. But in such case
10509 GDB would need to be bug-to-bug compatible. */
10511 complaint (_("Computed physname <%s> does not match demangled <%s> "
10512 "(from linkage <%s>) - DIE at %s [in module %s]"),
10513 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10514 objfile_name (objfile
));
10516 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10517 is available here - over computed PHYSNAME. It is safer
10518 against both buggy GDB and buggy compilers. */
10532 retval
= objfile
->intern (retval
);
10537 /* Inspect DIE in CU for a namespace alias. If one exists, record
10538 a new symbol for it.
10540 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10543 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10545 struct attribute
*attr
;
10547 /* If the die does not have a name, this is not a namespace
10549 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10553 struct die_info
*d
= die
;
10554 struct dwarf2_cu
*imported_cu
= cu
;
10556 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10557 keep inspecting DIEs until we hit the underlying import. */
10558 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10559 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10561 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10565 d
= follow_die_ref (d
, attr
, &imported_cu
);
10566 if (d
->tag
!= DW_TAG_imported_declaration
)
10570 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10572 complaint (_("DIE at %s has too many recursively imported "
10573 "declarations"), sect_offset_str (d
->sect_off
));
10580 sect_offset sect_off
= attr
->get_ref_die_offset ();
10582 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10583 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10585 /* This declaration is a global namespace alias. Add
10586 a symbol for it whose type is the aliased namespace. */
10587 new_symbol (die
, type
, cu
);
10596 /* Return the using directives repository (global or local?) to use in the
10597 current context for CU.
10599 For Ada, imported declarations can materialize renamings, which *may* be
10600 global. However it is impossible (for now?) in DWARF to distinguish
10601 "external" imported declarations and "static" ones. As all imported
10602 declarations seem to be static in all other languages, make them all CU-wide
10603 global only in Ada. */
10605 static struct using_direct
**
10606 using_directives (struct dwarf2_cu
*cu
)
10608 if (cu
->language
== language_ada
10609 && cu
->get_builder ()->outermost_context_p ())
10610 return cu
->get_builder ()->get_global_using_directives ();
10612 return cu
->get_builder ()->get_local_using_directives ();
10615 /* Read the import statement specified by the given die and record it. */
10618 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10620 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10621 struct attribute
*import_attr
;
10622 struct die_info
*imported_die
, *child_die
;
10623 struct dwarf2_cu
*imported_cu
;
10624 const char *imported_name
;
10625 const char *imported_name_prefix
;
10626 const char *canonical_name
;
10627 const char *import_alias
;
10628 const char *imported_declaration
= NULL
;
10629 const char *import_prefix
;
10630 std::vector
<const char *> excludes
;
10632 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10633 if (import_attr
== NULL
)
10635 complaint (_("Tag '%s' has no DW_AT_import"),
10636 dwarf_tag_name (die
->tag
));
10641 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10642 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10643 if (imported_name
== NULL
)
10645 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10647 The import in the following code:
10661 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10662 <52> DW_AT_decl_file : 1
10663 <53> DW_AT_decl_line : 6
10664 <54> DW_AT_import : <0x75>
10665 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10666 <59> DW_AT_name : B
10667 <5b> DW_AT_decl_file : 1
10668 <5c> DW_AT_decl_line : 2
10669 <5d> DW_AT_type : <0x6e>
10671 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10672 <76> DW_AT_byte_size : 4
10673 <77> DW_AT_encoding : 5 (signed)
10675 imports the wrong die ( 0x75 instead of 0x58 ).
10676 This case will be ignored until the gcc bug is fixed. */
10680 /* Figure out the local name after import. */
10681 import_alias
= dwarf2_name (die
, cu
);
10683 /* Figure out where the statement is being imported to. */
10684 import_prefix
= determine_prefix (die
, cu
);
10686 /* Figure out what the scope of the imported die is and prepend it
10687 to the name of the imported die. */
10688 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10690 if (imported_die
->tag
!= DW_TAG_namespace
10691 && imported_die
->tag
!= DW_TAG_module
)
10693 imported_declaration
= imported_name
;
10694 canonical_name
= imported_name_prefix
;
10696 else if (strlen (imported_name_prefix
) > 0)
10697 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10698 imported_name_prefix
,
10699 (cu
->language
== language_d
? "." : "::"),
10700 imported_name
, (char *) NULL
);
10702 canonical_name
= imported_name
;
10704 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10705 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10706 child_die
= child_die
->sibling
)
10708 /* DWARF-4: A Fortran use statement with a “rename list” may be
10709 represented by an imported module entry with an import attribute
10710 referring to the module and owned entries corresponding to those
10711 entities that are renamed as part of being imported. */
10713 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10715 complaint (_("child DW_TAG_imported_declaration expected "
10716 "- DIE at %s [in module %s]"),
10717 sect_offset_str (child_die
->sect_off
),
10718 objfile_name (objfile
));
10722 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10723 if (import_attr
== NULL
)
10725 complaint (_("Tag '%s' has no DW_AT_import"),
10726 dwarf_tag_name (child_die
->tag
));
10731 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10733 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10734 if (imported_name
== NULL
)
10736 complaint (_("child DW_TAG_imported_declaration has unknown "
10737 "imported name - DIE at %s [in module %s]"),
10738 sect_offset_str (child_die
->sect_off
),
10739 objfile_name (objfile
));
10743 excludes
.push_back (imported_name
);
10745 process_die (child_die
, cu
);
10748 add_using_directive (using_directives (cu
),
10752 imported_declaration
,
10755 &objfile
->objfile_obstack
);
10758 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10759 types, but gives them a size of zero. Starting with version 14,
10760 ICC is compatible with GCC. */
10763 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10765 if (!cu
->checked_producer
)
10766 check_producer (cu
);
10768 return cu
->producer_is_icc_lt_14
;
10771 /* ICC generates a DW_AT_type for C void functions. This was observed on
10772 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10773 which says that void functions should not have a DW_AT_type. */
10776 producer_is_icc (struct dwarf2_cu
*cu
)
10778 if (!cu
->checked_producer
)
10779 check_producer (cu
);
10781 return cu
->producer_is_icc
;
10784 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10785 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10786 this, it was first present in GCC release 4.3.0. */
10789 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10791 if (!cu
->checked_producer
)
10792 check_producer (cu
);
10794 return cu
->producer_is_gcc_lt_4_3
;
10797 static file_and_directory
10798 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10800 file_and_directory res
;
10802 /* Find the filename. Do not use dwarf2_name here, since the filename
10803 is not a source language identifier. */
10804 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10805 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10807 if (res
.comp_dir
== NULL
10808 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10809 && IS_ABSOLUTE_PATH (res
.name
))
10811 res
.comp_dir_storage
= ldirname (res
.name
);
10812 if (!res
.comp_dir_storage
.empty ())
10813 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10815 if (res
.comp_dir
!= NULL
)
10817 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10818 directory, get rid of it. */
10819 const char *cp
= strchr (res
.comp_dir
, ':');
10821 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10822 res
.comp_dir
= cp
+ 1;
10825 if (res
.name
== NULL
)
10826 res
.name
= "<unknown>";
10831 /* Handle DW_AT_stmt_list for a compilation unit.
10832 DIE is the DW_TAG_compile_unit die for CU.
10833 COMP_DIR is the compilation directory. LOWPC is passed to
10834 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10837 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10838 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10840 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10841 struct attribute
*attr
;
10842 struct line_header line_header_local
;
10843 hashval_t line_header_local_hash
;
10845 int decode_mapping
;
10847 gdb_assert (! cu
->per_cu
->is_debug_types
);
10849 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10853 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10855 /* The line header hash table is only created if needed (it exists to
10856 prevent redundant reading of the line table for partial_units).
10857 If we're given a partial_unit, we'll need it. If we're given a
10858 compile_unit, then use the line header hash table if it's already
10859 created, but don't create one just yet. */
10861 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
10862 && die
->tag
== DW_TAG_partial_unit
)
10864 dwarf2_per_objfile
->per_bfd
->line_header_hash
10865 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10866 line_header_eq_voidp
,
10867 free_line_header_voidp
,
10871 line_header_local
.sect_off
= line_offset
;
10872 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10873 line_header_local_hash
= line_header_hash (&line_header_local
);
10874 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
!= NULL
)
10876 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10877 &line_header_local
,
10878 line_header_local_hash
, NO_INSERT
);
10880 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10881 is not present in *SLOT (since if there is something in *SLOT then
10882 it will be for a partial_unit). */
10883 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10885 gdb_assert (*slot
!= NULL
);
10886 cu
->line_header
= (struct line_header
*) *slot
;
10891 /* dwarf_decode_line_header does not yet provide sufficient information.
10892 We always have to call also dwarf_decode_lines for it. */
10893 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10897 cu
->line_header
= lh
.release ();
10898 cu
->line_header_die_owner
= die
;
10900 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
)
10904 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10905 &line_header_local
,
10906 line_header_local_hash
, INSERT
);
10907 gdb_assert (slot
!= NULL
);
10909 if (slot
!= NULL
&& *slot
== NULL
)
10911 /* This newly decoded line number information unit will be owned
10912 by line_header_hash hash table. */
10913 *slot
= cu
->line_header
;
10914 cu
->line_header_die_owner
= NULL
;
10918 /* We cannot free any current entry in (*slot) as that struct line_header
10919 may be already used by multiple CUs. Create only temporary decoded
10920 line_header for this CU - it may happen at most once for each line
10921 number information unit. And if we're not using line_header_hash
10922 then this is what we want as well. */
10923 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10925 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10926 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10931 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10934 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10936 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10937 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10938 struct gdbarch
*gdbarch
= objfile
->arch ();
10939 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10940 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10941 struct attribute
*attr
;
10942 struct die_info
*child_die
;
10943 CORE_ADDR baseaddr
;
10945 prepare_one_comp_unit (cu
, die
, cu
->language
);
10946 baseaddr
= objfile
->text_section_offset ();
10948 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10950 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10951 from finish_block. */
10952 if (lowpc
== ((CORE_ADDR
) -1))
10954 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10956 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10958 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10959 standardised yet. As a workaround for the language detection we fall
10960 back to the DW_AT_producer string. */
10961 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10962 cu
->language
= language_opencl
;
10964 /* Similar hack for Go. */
10965 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10966 set_cu_language (DW_LANG_Go
, cu
);
10968 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10970 /* Decode line number information if present. We do this before
10971 processing child DIEs, so that the line header table is available
10972 for DW_AT_decl_file. */
10973 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10975 /* Process all dies in compilation unit. */
10976 if (die
->child
!= NULL
)
10978 child_die
= die
->child
;
10979 while (child_die
&& child_die
->tag
)
10981 process_die (child_die
, cu
);
10982 child_die
= child_die
->sibling
;
10986 /* Decode macro information, if present. Dwarf 2 macro information
10987 refers to information in the line number info statement program
10988 header, so we can only read it if we've read the header
10990 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10992 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10993 if (attr
&& cu
->line_header
)
10995 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10996 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10998 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11002 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11003 if (attr
&& cu
->line_header
)
11005 unsigned int macro_offset
= DW_UNSND (attr
);
11007 dwarf_decode_macros (cu
, macro_offset
, 0);
11013 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11015 struct type_unit_group
*tu_group
;
11017 struct attribute
*attr
;
11019 struct signatured_type
*sig_type
;
11021 gdb_assert (per_cu
->is_debug_types
);
11022 sig_type
= (struct signatured_type
*) per_cu
;
11024 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11026 /* If we're using .gdb_index (includes -readnow) then
11027 per_cu->type_unit_group may not have been set up yet. */
11028 if (sig_type
->type_unit_group
== NULL
)
11029 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11030 tu_group
= sig_type
->type_unit_group
;
11032 /* If we've already processed this stmt_list there's no real need to
11033 do it again, we could fake it and just recreate the part we need
11034 (file name,index -> symtab mapping). If data shows this optimization
11035 is useful we can do it then. */
11036 first_time
= tu_group
->compunit_symtab
== NULL
;
11038 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11043 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11044 lh
= dwarf_decode_line_header (line_offset
, this);
11049 start_symtab ("", NULL
, 0);
11052 gdb_assert (tu_group
->symtabs
== NULL
);
11053 gdb_assert (m_builder
== nullptr);
11054 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11055 m_builder
.reset (new struct buildsym_compunit
11056 (COMPUNIT_OBJFILE (cust
), "",
11057 COMPUNIT_DIRNAME (cust
),
11058 compunit_language (cust
),
11060 list_in_scope
= get_builder ()->get_file_symbols ();
11065 line_header
= lh
.release ();
11066 line_header_die_owner
= die
;
11070 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11072 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11073 still initializing it, and our caller (a few levels up)
11074 process_full_type_unit still needs to know if this is the first
11078 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11079 struct symtab
*, line_header
->file_names_size ());
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 dwarf2_start_subfile (this, fe
.name
,
11086 fe
.include_dir (line_header
));
11087 buildsym_compunit
*b
= get_builder ();
11088 if (b
->get_current_subfile ()->symtab
== NULL
)
11090 /* NOTE: start_subfile will recognize when it's been
11091 passed a file it has already seen. So we can't
11092 assume there's a simple mapping from
11093 cu->line_header->file_names to subfiles, plus
11094 cu->line_header->file_names may contain dups. */
11095 b
->get_current_subfile ()->symtab
11096 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11099 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11100 tu_group
->symtabs
[i
] = fe
.symtab
;
11105 gdb_assert (m_builder
== nullptr);
11106 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11107 m_builder
.reset (new struct buildsym_compunit
11108 (COMPUNIT_OBJFILE (cust
), "",
11109 COMPUNIT_DIRNAME (cust
),
11110 compunit_language (cust
),
11112 list_in_scope
= get_builder ()->get_file_symbols ();
11114 auto &file_names
= line_header
->file_names ();
11115 for (i
= 0; i
< file_names
.size (); ++i
)
11117 file_entry
&fe
= file_names
[i
];
11118 fe
.symtab
= tu_group
->symtabs
[i
];
11122 /* The main symtab is allocated last. Type units don't have DW_AT_name
11123 so they don't have a "real" (so to speak) symtab anyway.
11124 There is later code that will assign the main symtab to all symbols
11125 that don't have one. We need to handle the case of a symbol with a
11126 missing symtab (DW_AT_decl_file) anyway. */
11129 /* Process DW_TAG_type_unit.
11130 For TUs we want to skip the first top level sibling if it's not the
11131 actual type being defined by this TU. In this case the first top
11132 level sibling is there to provide context only. */
11135 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11137 struct die_info
*child_die
;
11139 prepare_one_comp_unit (cu
, die
, language_minimal
);
11141 /* Initialize (or reinitialize) the machinery for building symtabs.
11142 We do this before processing child DIEs, so that the line header table
11143 is available for DW_AT_decl_file. */
11144 cu
->setup_type_unit_groups (die
);
11146 if (die
->child
!= NULL
)
11148 child_die
= die
->child
;
11149 while (child_die
&& child_die
->tag
)
11151 process_die (child_die
, cu
);
11152 child_die
= child_die
->sibling
;
11159 http://gcc.gnu.org/wiki/DebugFission
11160 http://gcc.gnu.org/wiki/DebugFissionDWP
11162 To simplify handling of both DWO files ("object" files with the DWARF info)
11163 and DWP files (a file with the DWOs packaged up into one file), we treat
11164 DWP files as having a collection of virtual DWO files. */
11167 hash_dwo_file (const void *item
)
11169 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11172 hash
= htab_hash_string (dwo_file
->dwo_name
);
11173 if (dwo_file
->comp_dir
!= NULL
)
11174 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11179 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11181 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11182 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11184 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11186 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11187 return lhs
->comp_dir
== rhs
->comp_dir
;
11188 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11191 /* Allocate a hash table for DWO files. */
11194 allocate_dwo_file_hash_table ()
11196 auto delete_dwo_file
= [] (void *item
)
11198 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11203 return htab_up (htab_create_alloc (41,
11210 /* Lookup DWO file DWO_NAME. */
11213 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11214 const char *dwo_name
,
11215 const char *comp_dir
)
11217 struct dwo_file find_entry
;
11220 if (dwarf2_per_objfile
->per_bfd
->dwo_files
== NULL
)
11221 dwarf2_per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11223 find_entry
.dwo_name
= dwo_name
;
11224 find_entry
.comp_dir
= comp_dir
;
11225 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11232 hash_dwo_unit (const void *item
)
11234 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11236 /* This drops the top 32 bits of the id, but is ok for a hash. */
11237 return dwo_unit
->signature
;
11241 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11243 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11244 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11246 /* The signature is assumed to be unique within the DWO file.
11247 So while object file CU dwo_id's always have the value zero,
11248 that's OK, assuming each object file DWO file has only one CU,
11249 and that's the rule for now. */
11250 return lhs
->signature
== rhs
->signature
;
11253 /* Allocate a hash table for DWO CUs,TUs.
11254 There is one of these tables for each of CUs,TUs for each DWO file. */
11257 allocate_dwo_unit_table ()
11259 /* Start out with a pretty small number.
11260 Generally DWO files contain only one CU and maybe some TUs. */
11261 return htab_up (htab_create_alloc (3,
11264 NULL
, xcalloc
, xfree
));
11267 /* die_reader_func for create_dwo_cu. */
11270 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11271 const gdb_byte
*info_ptr
,
11272 struct die_info
*comp_unit_die
,
11273 struct dwo_file
*dwo_file
,
11274 struct dwo_unit
*dwo_unit
)
11276 struct dwarf2_cu
*cu
= reader
->cu
;
11277 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11278 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11280 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11281 if (!signature
.has_value ())
11283 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11284 " its dwo_id [in module %s]"),
11285 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11289 dwo_unit
->dwo_file
= dwo_file
;
11290 dwo_unit
->signature
= *signature
;
11291 dwo_unit
->section
= section
;
11292 dwo_unit
->sect_off
= sect_off
;
11293 dwo_unit
->length
= cu
->per_cu
->length
;
11295 if (dwarf_read_debug
)
11296 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11297 sect_offset_str (sect_off
),
11298 hex_string (dwo_unit
->signature
));
11301 /* Create the dwo_units for the CUs in a DWO_FILE.
11302 Note: This function processes DWO files only, not DWP files. */
11305 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11306 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11307 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11309 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11310 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
11311 const gdb_byte
*info_ptr
, *end_ptr
;
11313 section
.read (objfile
);
11314 info_ptr
= section
.buffer
;
11316 if (info_ptr
== NULL
)
11319 if (dwarf_read_debug
)
11321 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11322 section
.get_name (),
11323 section
.get_file_name ());
11326 end_ptr
= info_ptr
+ section
.size
;
11327 while (info_ptr
< end_ptr
)
11329 struct dwarf2_per_cu_data per_cu
;
11330 struct dwo_unit read_unit
{};
11331 struct dwo_unit
*dwo_unit
;
11333 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11335 memset (&per_cu
, 0, sizeof (per_cu
));
11336 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11337 per_cu
.per_bfd
= per_bfd
;
11338 per_cu
.is_debug_types
= 0;
11339 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11340 per_cu
.section
= §ion
;
11342 cutu_reader
reader (&per_cu
, dwarf2_per_objfile
, cu
, &dwo_file
);
11343 if (!reader
.dummy_p
)
11344 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11345 &dwo_file
, &read_unit
);
11346 info_ptr
+= per_cu
.length
;
11348 // If the unit could not be parsed, skip it.
11349 if (read_unit
.dwo_file
== NULL
)
11352 if (cus_htab
== NULL
)
11353 cus_htab
= allocate_dwo_unit_table ();
11355 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11357 *dwo_unit
= read_unit
;
11358 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11359 gdb_assert (slot
!= NULL
);
11362 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11363 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11365 complaint (_("debug cu entry at offset %s is duplicate to"
11366 " the entry at offset %s, signature %s"),
11367 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11368 hex_string (dwo_unit
->signature
));
11370 *slot
= (void *)dwo_unit
;
11374 /* DWP file .debug_{cu,tu}_index section format:
11375 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11379 Both index sections have the same format, and serve to map a 64-bit
11380 signature to a set of section numbers. Each section begins with a header,
11381 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11382 indexes, and a pool of 32-bit section numbers. The index sections will be
11383 aligned at 8-byte boundaries in the file.
11385 The index section header consists of:
11387 V, 32 bit version number
11389 N, 32 bit number of compilation units or type units in the index
11390 M, 32 bit number of slots in the hash table
11392 Numbers are recorded using the byte order of the application binary.
11394 The hash table begins at offset 16 in the section, and consists of an array
11395 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11396 order of the application binary). Unused slots in the hash table are 0.
11397 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11399 The parallel table begins immediately after the hash table
11400 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11401 array of 32-bit indexes (using the byte order of the application binary),
11402 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11403 table contains a 32-bit index into the pool of section numbers. For unused
11404 hash table slots, the corresponding entry in the parallel table will be 0.
11406 The pool of section numbers begins immediately following the hash table
11407 (at offset 16 + 12 * M from the beginning of the section). The pool of
11408 section numbers consists of an array of 32-bit words (using the byte order
11409 of the application binary). Each item in the array is indexed starting
11410 from 0. The hash table entry provides the index of the first section
11411 number in the set. Additional section numbers in the set follow, and the
11412 set is terminated by a 0 entry (section number 0 is not used in ELF).
11414 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11415 section must be the first entry in the set, and the .debug_abbrev.dwo must
11416 be the second entry. Other members of the set may follow in any order.
11422 DWP Version 2 combines all the .debug_info, etc. sections into one,
11423 and the entries in the index tables are now offsets into these sections.
11424 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11427 Index Section Contents:
11429 Hash Table of Signatures dwp_hash_table.hash_table
11430 Parallel Table of Indices dwp_hash_table.unit_table
11431 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11432 Table of Section Sizes dwp_hash_table.v2.sizes
11434 The index section header consists of:
11436 V, 32 bit version number
11437 L, 32 bit number of columns in the table of section offsets
11438 N, 32 bit number of compilation units or type units in the index
11439 M, 32 bit number of slots in the hash table
11441 Numbers are recorded using the byte order of the application binary.
11443 The hash table has the same format as version 1.
11444 The parallel table of indices has the same format as version 1,
11445 except that the entries are origin-1 indices into the table of sections
11446 offsets and the table of section sizes.
11448 The table of offsets begins immediately following the parallel table
11449 (at offset 16 + 12 * M from the beginning of the section). The table is
11450 a two-dimensional array of 32-bit words (using the byte order of the
11451 application binary), with L columns and N+1 rows, in row-major order.
11452 Each row in the array is indexed starting from 0. The first row provides
11453 a key to the remaining rows: each column in this row provides an identifier
11454 for a debug section, and the offsets in the same column of subsequent rows
11455 refer to that section. The section identifiers are:
11457 DW_SECT_INFO 1 .debug_info.dwo
11458 DW_SECT_TYPES 2 .debug_types.dwo
11459 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11460 DW_SECT_LINE 4 .debug_line.dwo
11461 DW_SECT_LOC 5 .debug_loc.dwo
11462 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11463 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11464 DW_SECT_MACRO 8 .debug_macro.dwo
11466 The offsets provided by the CU and TU index sections are the base offsets
11467 for the contributions made by each CU or TU to the corresponding section
11468 in the package file. Each CU and TU header contains an abbrev_offset
11469 field, used to find the abbreviations table for that CU or TU within the
11470 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11471 be interpreted as relative to the base offset given in the index section.
11472 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11473 should be interpreted as relative to the base offset for .debug_line.dwo,
11474 and offsets into other debug sections obtained from DWARF attributes should
11475 also be interpreted as relative to the corresponding base offset.
11477 The table of sizes begins immediately following the table of offsets.
11478 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11479 with L columns and N rows, in row-major order. Each row in the array is
11480 indexed starting from 1 (row 0 is shared by the two tables).
11484 Hash table lookup is handled the same in version 1 and 2:
11486 We assume that N and M will not exceed 2^32 - 1.
11487 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11489 Given a 64-bit compilation unit signature or a type signature S, an entry
11490 in the hash table is located as follows:
11492 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11493 the low-order k bits all set to 1.
11495 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11497 3) If the hash table entry at index H matches the signature, use that
11498 entry. If the hash table entry at index H is unused (all zeroes),
11499 terminate the search: the signature is not present in the table.
11501 4) Let H = (H + H') modulo M. Repeat at Step 3.
11503 Because M > N and H' and M are relatively prime, the search is guaranteed
11504 to stop at an unused slot or find the match. */
11506 /* Create a hash table to map DWO IDs to their CU/TU entry in
11507 .debug_{info,types}.dwo in DWP_FILE.
11508 Returns NULL if there isn't one.
11509 Note: This function processes DWP files only, not DWO files. */
11511 static struct dwp_hash_table
*
11512 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11513 struct dwp_file
*dwp_file
, int is_debug_types
)
11515 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11516 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11517 const gdb_byte
*index_ptr
, *index_end
;
11518 struct dwarf2_section_info
*index
;
11519 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11520 struct dwp_hash_table
*htab
;
11522 if (is_debug_types
)
11523 index
= &dwp_file
->sections
.tu_index
;
11525 index
= &dwp_file
->sections
.cu_index
;
11527 if (index
->empty ())
11529 index
->read (objfile
);
11531 index_ptr
= index
->buffer
;
11532 index_end
= index_ptr
+ index
->size
;
11534 version
= read_4_bytes (dbfd
, index_ptr
);
11537 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11541 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11543 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11546 if (version
!= 1 && version
!= 2)
11548 error (_("Dwarf Error: unsupported DWP file version (%s)"
11549 " [in module %s]"),
11550 pulongest (version
), dwp_file
->name
);
11552 if (nr_slots
!= (nr_slots
& -nr_slots
))
11554 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11555 " is not power of 2 [in module %s]"),
11556 pulongest (nr_slots
), dwp_file
->name
);
11559 htab
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11560 htab
->version
= version
;
11561 htab
->nr_columns
= nr_columns
;
11562 htab
->nr_units
= nr_units
;
11563 htab
->nr_slots
= nr_slots
;
11564 htab
->hash_table
= index_ptr
;
11565 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11567 /* Exit early if the table is empty. */
11568 if (nr_slots
== 0 || nr_units
== 0
11569 || (version
== 2 && nr_columns
== 0))
11571 /* All must be zero. */
11572 if (nr_slots
!= 0 || nr_units
!= 0
11573 || (version
== 2 && nr_columns
!= 0))
11575 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11576 " all zero [in modules %s]"),
11584 htab
->section_pool
.v1
.indices
=
11585 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11586 /* It's harder to decide whether the section is too small in v1.
11587 V1 is deprecated anyway so we punt. */
11591 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11592 int *ids
= htab
->section_pool
.v2
.section_ids
;
11593 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11594 /* Reverse map for error checking. */
11595 int ids_seen
[DW_SECT_MAX
+ 1];
11598 if (nr_columns
< 2)
11600 error (_("Dwarf Error: bad DWP hash table, too few columns"
11601 " in section table [in module %s]"),
11604 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11606 error (_("Dwarf Error: bad DWP hash table, too many columns"
11607 " in section table [in module %s]"),
11610 memset (ids
, 255, sizeof_ids
);
11611 memset (ids_seen
, 255, sizeof (ids_seen
));
11612 for (i
= 0; i
< nr_columns
; ++i
)
11614 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11616 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11618 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11619 " in section table [in module %s]"),
11620 id
, dwp_file
->name
);
11622 if (ids_seen
[id
] != -1)
11624 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11625 " id %d in section table [in module %s]"),
11626 id
, dwp_file
->name
);
11631 /* Must have exactly one info or types section. */
11632 if (((ids_seen
[DW_SECT_INFO
] != -1)
11633 + (ids_seen
[DW_SECT_TYPES
] != -1))
11636 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11637 " DWO info/types section [in module %s]"),
11640 /* Must have an abbrev section. */
11641 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11643 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11644 " section [in module %s]"),
11647 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11648 htab
->section_pool
.v2
.sizes
=
11649 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11650 * nr_units
* nr_columns
);
11651 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11652 * nr_units
* nr_columns
))
11655 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11656 " [in module %s]"),
11664 /* Update SECTIONS with the data from SECTP.
11666 This function is like the other "locate" section routines that are
11667 passed to bfd_map_over_sections, but in this context the sections to
11668 read comes from the DWP V1 hash table, not the full ELF section table.
11670 The result is non-zero for success, or zero if an error was found. */
11673 locate_v1_virtual_dwo_sections (asection
*sectp
,
11674 struct virtual_v1_dwo_sections
*sections
)
11676 const struct dwop_section_names
*names
= &dwop_section_names
;
11678 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11680 /* There can be only one. */
11681 if (sections
->abbrev
.s
.section
!= NULL
)
11683 sections
->abbrev
.s
.section
= sectp
;
11684 sections
->abbrev
.size
= bfd_section_size (sectp
);
11686 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11687 || section_is_p (sectp
->name
, &names
->types_dwo
))
11689 /* There can be only one. */
11690 if (sections
->info_or_types
.s
.section
!= NULL
)
11692 sections
->info_or_types
.s
.section
= sectp
;
11693 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11695 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11697 /* There can be only one. */
11698 if (sections
->line
.s
.section
!= NULL
)
11700 sections
->line
.s
.section
= sectp
;
11701 sections
->line
.size
= bfd_section_size (sectp
);
11703 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11705 /* There can be only one. */
11706 if (sections
->loc
.s
.section
!= NULL
)
11708 sections
->loc
.s
.section
= sectp
;
11709 sections
->loc
.size
= bfd_section_size (sectp
);
11711 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11713 /* There can be only one. */
11714 if (sections
->macinfo
.s
.section
!= NULL
)
11716 sections
->macinfo
.s
.section
= sectp
;
11717 sections
->macinfo
.size
= bfd_section_size (sectp
);
11719 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11721 /* There can be only one. */
11722 if (sections
->macro
.s
.section
!= NULL
)
11724 sections
->macro
.s
.section
= sectp
;
11725 sections
->macro
.size
= bfd_section_size (sectp
);
11727 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11729 /* There can be only one. */
11730 if (sections
->str_offsets
.s
.section
!= NULL
)
11732 sections
->str_offsets
.s
.section
= sectp
;
11733 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11737 /* No other kind of section is valid. */
11744 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11745 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11746 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11747 This is for DWP version 1 files. */
11749 static struct dwo_unit
*
11750 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11751 struct dwp_file
*dwp_file
,
11752 uint32_t unit_index
,
11753 const char *comp_dir
,
11754 ULONGEST signature
, int is_debug_types
)
11756 const struct dwp_hash_table
*dwp_htab
=
11757 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11758 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11759 const char *kind
= is_debug_types
? "TU" : "CU";
11760 struct dwo_file
*dwo_file
;
11761 struct dwo_unit
*dwo_unit
;
11762 struct virtual_v1_dwo_sections sections
;
11763 void **dwo_file_slot
;
11766 gdb_assert (dwp_file
->version
== 1);
11768 if (dwarf_read_debug
)
11770 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11772 pulongest (unit_index
), hex_string (signature
),
11776 /* Fetch the sections of this DWO unit.
11777 Put a limit on the number of sections we look for so that bad data
11778 doesn't cause us to loop forever. */
11780 #define MAX_NR_V1_DWO_SECTIONS \
11781 (1 /* .debug_info or .debug_types */ \
11782 + 1 /* .debug_abbrev */ \
11783 + 1 /* .debug_line */ \
11784 + 1 /* .debug_loc */ \
11785 + 1 /* .debug_str_offsets */ \
11786 + 1 /* .debug_macro or .debug_macinfo */ \
11787 + 1 /* trailing zero */)
11789 memset (§ions
, 0, sizeof (sections
));
11791 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11794 uint32_t section_nr
=
11795 read_4_bytes (dbfd
,
11796 dwp_htab
->section_pool
.v1
.indices
11797 + (unit_index
+ i
) * sizeof (uint32_t));
11799 if (section_nr
== 0)
11801 if (section_nr
>= dwp_file
->num_sections
)
11803 error (_("Dwarf Error: bad DWP hash table, section number too large"
11804 " [in module %s]"),
11808 sectp
= dwp_file
->elf_sections
[section_nr
];
11809 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11811 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11812 " [in module %s]"),
11818 || sections
.info_or_types
.empty ()
11819 || sections
.abbrev
.empty ())
11821 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11822 " [in module %s]"),
11825 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11827 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11828 " [in module %s]"),
11832 /* It's easier for the rest of the code if we fake a struct dwo_file and
11833 have dwo_unit "live" in that. At least for now.
11835 The DWP file can be made up of a random collection of CUs and TUs.
11836 However, for each CU + set of TUs that came from the same original DWO
11837 file, we can combine them back into a virtual DWO file to save space
11838 (fewer struct dwo_file objects to allocate). Remember that for really
11839 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11841 std::string virtual_dwo_name
=
11842 string_printf ("virtual-dwo/%d-%d-%d-%d",
11843 sections
.abbrev
.get_id (),
11844 sections
.line
.get_id (),
11845 sections
.loc
.get_id (),
11846 sections
.str_offsets
.get_id ());
11847 /* Can we use an existing virtual DWO file? */
11848 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11849 virtual_dwo_name
.c_str (),
11851 /* Create one if necessary. */
11852 if (*dwo_file_slot
== NULL
)
11854 if (dwarf_read_debug
)
11856 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11857 virtual_dwo_name
.c_str ());
11859 dwo_file
= new struct dwo_file
;
11860 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
11861 dwo_file
->comp_dir
= comp_dir
;
11862 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11863 dwo_file
->sections
.line
= sections
.line
;
11864 dwo_file
->sections
.loc
= sections
.loc
;
11865 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11866 dwo_file
->sections
.macro
= sections
.macro
;
11867 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11868 /* The "str" section is global to the entire DWP file. */
11869 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11870 /* The info or types section is assigned below to dwo_unit,
11871 there's no need to record it in dwo_file.
11872 Also, we can't simply record type sections in dwo_file because
11873 we record a pointer into the vector in dwo_unit. As we collect more
11874 types we'll grow the vector and eventually have to reallocate space
11875 for it, invalidating all copies of pointers into the previous
11877 *dwo_file_slot
= dwo_file
;
11881 if (dwarf_read_debug
)
11883 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11884 virtual_dwo_name
.c_str ());
11886 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11889 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11890 dwo_unit
->dwo_file
= dwo_file
;
11891 dwo_unit
->signature
= signature
;
11892 dwo_unit
->section
=
11893 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11894 *dwo_unit
->section
= sections
.info_or_types
;
11895 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11900 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11901 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11902 piece within that section used by a TU/CU, return a virtual section
11903 of just that piece. */
11905 static struct dwarf2_section_info
11906 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11907 struct dwarf2_section_info
*section
,
11908 bfd_size_type offset
, bfd_size_type size
)
11910 struct dwarf2_section_info result
;
11913 gdb_assert (section
!= NULL
);
11914 gdb_assert (!section
->is_virtual
);
11916 memset (&result
, 0, sizeof (result
));
11917 result
.s
.containing_section
= section
;
11918 result
.is_virtual
= true;
11923 sectp
= section
->get_bfd_section ();
11925 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11926 bounds of the real section. This is a pretty-rare event, so just
11927 flag an error (easier) instead of a warning and trying to cope. */
11929 || offset
+ size
> bfd_section_size (sectp
))
11931 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11932 " in section %s [in module %s]"),
11933 sectp
? bfd_section_name (sectp
) : "<unknown>",
11934 objfile_name (dwarf2_per_objfile
->objfile
));
11937 result
.virtual_offset
= offset
;
11938 result
.size
= size
;
11942 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11943 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11944 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11945 This is for DWP version 2 files. */
11947 static struct dwo_unit
*
11948 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11949 struct dwp_file
*dwp_file
,
11950 uint32_t unit_index
,
11951 const char *comp_dir
,
11952 ULONGEST signature
, int is_debug_types
)
11954 const struct dwp_hash_table
*dwp_htab
=
11955 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11956 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11957 const char *kind
= is_debug_types
? "TU" : "CU";
11958 struct dwo_file
*dwo_file
;
11959 struct dwo_unit
*dwo_unit
;
11960 struct virtual_v2_dwo_sections sections
;
11961 void **dwo_file_slot
;
11964 gdb_assert (dwp_file
->version
== 2);
11966 if (dwarf_read_debug
)
11968 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11970 pulongest (unit_index
), hex_string (signature
),
11974 /* Fetch the section offsets of this DWO unit. */
11976 memset (§ions
, 0, sizeof (sections
));
11978 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11980 uint32_t offset
= read_4_bytes (dbfd
,
11981 dwp_htab
->section_pool
.v2
.offsets
11982 + (((unit_index
- 1) * dwp_htab
->nr_columns
11984 * sizeof (uint32_t)));
11985 uint32_t size
= read_4_bytes (dbfd
,
11986 dwp_htab
->section_pool
.v2
.sizes
11987 + (((unit_index
- 1) * dwp_htab
->nr_columns
11989 * sizeof (uint32_t)));
11991 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11994 case DW_SECT_TYPES
:
11995 sections
.info_or_types_offset
= offset
;
11996 sections
.info_or_types_size
= size
;
11998 case DW_SECT_ABBREV
:
11999 sections
.abbrev_offset
= offset
;
12000 sections
.abbrev_size
= size
;
12003 sections
.line_offset
= offset
;
12004 sections
.line_size
= size
;
12007 sections
.loc_offset
= offset
;
12008 sections
.loc_size
= size
;
12010 case DW_SECT_STR_OFFSETS
:
12011 sections
.str_offsets_offset
= offset
;
12012 sections
.str_offsets_size
= size
;
12014 case DW_SECT_MACINFO
:
12015 sections
.macinfo_offset
= offset
;
12016 sections
.macinfo_size
= size
;
12018 case DW_SECT_MACRO
:
12019 sections
.macro_offset
= offset
;
12020 sections
.macro_size
= size
;
12025 /* It's easier for the rest of the code if we fake a struct dwo_file and
12026 have dwo_unit "live" in that. At least for now.
12028 The DWP file can be made up of a random collection of CUs and TUs.
12029 However, for each CU + set of TUs that came from the same original DWO
12030 file, we can combine them back into a virtual DWO file to save space
12031 (fewer struct dwo_file objects to allocate). Remember that for really
12032 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12034 std::string virtual_dwo_name
=
12035 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12036 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12037 (long) (sections
.line_size
? sections
.line_offset
: 0),
12038 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12039 (long) (sections
.str_offsets_size
12040 ? sections
.str_offsets_offset
: 0));
12041 /* Can we use an existing virtual DWO file? */
12042 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12043 virtual_dwo_name
.c_str (),
12045 /* Create one if necessary. */
12046 if (*dwo_file_slot
== NULL
)
12048 if (dwarf_read_debug
)
12050 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12051 virtual_dwo_name
.c_str ());
12053 dwo_file
= new struct dwo_file
;
12054 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
12055 dwo_file
->comp_dir
= comp_dir
;
12056 dwo_file
->sections
.abbrev
=
12057 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12058 sections
.abbrev_offset
, sections
.abbrev_size
);
12059 dwo_file
->sections
.line
=
12060 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12061 sections
.line_offset
, sections
.line_size
);
12062 dwo_file
->sections
.loc
=
12063 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12064 sections
.loc_offset
, sections
.loc_size
);
12065 dwo_file
->sections
.macinfo
=
12066 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12067 sections
.macinfo_offset
, sections
.macinfo_size
);
12068 dwo_file
->sections
.macro
=
12069 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12070 sections
.macro_offset
, sections
.macro_size
);
12071 dwo_file
->sections
.str_offsets
=
12072 create_dwp_v2_section (dwarf2_per_objfile
,
12073 &dwp_file
->sections
.str_offsets
,
12074 sections
.str_offsets_offset
,
12075 sections
.str_offsets_size
);
12076 /* The "str" section is global to the entire DWP file. */
12077 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12078 /* The info or types section is assigned below to dwo_unit,
12079 there's no need to record it in dwo_file.
12080 Also, we can't simply record type sections in dwo_file because
12081 we record a pointer into the vector in dwo_unit. As we collect more
12082 types we'll grow the vector and eventually have to reallocate space
12083 for it, invalidating all copies of pointers into the previous
12085 *dwo_file_slot
= dwo_file
;
12089 if (dwarf_read_debug
)
12091 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12092 virtual_dwo_name
.c_str ());
12094 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12097 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12098 dwo_unit
->dwo_file
= dwo_file
;
12099 dwo_unit
->signature
= signature
;
12100 dwo_unit
->section
=
12101 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12102 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12104 ? &dwp_file
->sections
.types
12105 : &dwp_file
->sections
.info
,
12106 sections
.info_or_types_offset
,
12107 sections
.info_or_types_size
);
12108 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12113 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12114 Returns NULL if the signature isn't found. */
12116 static struct dwo_unit
*
12117 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12118 struct dwp_file
*dwp_file
, const char *comp_dir
,
12119 ULONGEST signature
, int is_debug_types
)
12121 const struct dwp_hash_table
*dwp_htab
=
12122 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12123 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12124 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12125 uint32_t hash
= signature
& mask
;
12126 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12129 struct dwo_unit find_dwo_cu
;
12131 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12132 find_dwo_cu
.signature
= signature
;
12133 slot
= htab_find_slot (is_debug_types
12134 ? dwp_file
->loaded_tus
.get ()
12135 : dwp_file
->loaded_cus
.get (),
12136 &find_dwo_cu
, INSERT
);
12139 return (struct dwo_unit
*) *slot
;
12141 /* Use a for loop so that we don't loop forever on bad debug info. */
12142 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12144 ULONGEST signature_in_table
;
12146 signature_in_table
=
12147 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12148 if (signature_in_table
== signature
)
12150 uint32_t unit_index
=
12151 read_4_bytes (dbfd
,
12152 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12154 if (dwp_file
->version
== 1)
12156 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12157 dwp_file
, unit_index
,
12158 comp_dir
, signature
,
12163 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12164 dwp_file
, unit_index
,
12165 comp_dir
, signature
,
12168 return (struct dwo_unit
*) *slot
;
12170 if (signature_in_table
== 0)
12172 hash
= (hash
+ hash2
) & mask
;
12175 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12176 " [in module %s]"),
12180 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12181 Open the file specified by FILE_NAME and hand it off to BFD for
12182 preliminary analysis. Return a newly initialized bfd *, which
12183 includes a canonicalized copy of FILE_NAME.
12184 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12185 SEARCH_CWD is true if the current directory is to be searched.
12186 It will be searched before debug-file-directory.
12187 If successful, the file is added to the bfd include table of the
12188 objfile's bfd (see gdb_bfd_record_inclusion).
12189 If unable to find/open the file, return NULL.
12190 NOTE: This function is derived from symfile_bfd_open. */
12192 static gdb_bfd_ref_ptr
12193 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12194 const char *file_name
, int is_dwp
, int search_cwd
)
12197 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12198 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12199 to debug_file_directory. */
12200 const char *search_path
;
12201 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12203 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12206 if (*debug_file_directory
!= '\0')
12208 search_path_holder
.reset (concat (".", dirname_separator_string
,
12209 debug_file_directory
,
12211 search_path
= search_path_holder
.get ();
12217 search_path
= debug_file_directory
;
12219 openp_flags flags
= OPF_RETURN_REALPATH
;
12221 flags
|= OPF_SEARCH_IN_PATH
;
12223 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12224 desc
= openp (search_path
, flags
, file_name
,
12225 O_RDONLY
| O_BINARY
, &absolute_name
);
12229 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12231 if (sym_bfd
== NULL
)
12233 bfd_set_cacheable (sym_bfd
.get (), 1);
12235 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12238 /* Success. Record the bfd as having been included by the objfile's bfd.
12239 This is important because things like demangled_names_hash lives in the
12240 objfile's per_bfd space and may have references to things like symbol
12241 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12242 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12247 /* Try to open DWO file FILE_NAME.
12248 COMP_DIR is the DW_AT_comp_dir attribute.
12249 The result is the bfd handle of the file.
12250 If there is a problem finding or opening the file, return NULL.
12251 Upon success, the canonicalized path of the file is stored in the bfd,
12252 same as symfile_bfd_open. */
12254 static gdb_bfd_ref_ptr
12255 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12256 const char *file_name
, const char *comp_dir
)
12258 if (IS_ABSOLUTE_PATH (file_name
))
12259 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12260 0 /*is_dwp*/, 0 /*search_cwd*/);
12262 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12264 if (comp_dir
!= NULL
)
12266 gdb::unique_xmalloc_ptr
<char> path_to_try
12267 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12269 /* NOTE: If comp_dir is a relative path, this will also try the
12270 search path, which seems useful. */
12271 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12272 path_to_try
.get (),
12274 1 /*search_cwd*/));
12279 /* That didn't work, try debug-file-directory, which, despite its name,
12280 is a list of paths. */
12282 if (*debug_file_directory
== '\0')
12285 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12286 0 /*is_dwp*/, 1 /*search_cwd*/);
12289 /* This function is mapped across the sections and remembers the offset and
12290 size of each of the DWO debugging sections we are interested in. */
12293 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12295 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12296 const struct dwop_section_names
*names
= &dwop_section_names
;
12298 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12300 dwo_sections
->abbrev
.s
.section
= sectp
;
12301 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12303 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12305 dwo_sections
->info
.s
.section
= sectp
;
12306 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12308 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12310 dwo_sections
->line
.s
.section
= sectp
;
12311 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12313 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12315 dwo_sections
->loc
.s
.section
= sectp
;
12316 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12318 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12320 dwo_sections
->loclists
.s
.section
= sectp
;
12321 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12323 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12325 dwo_sections
->macinfo
.s
.section
= sectp
;
12326 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12328 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12330 dwo_sections
->macro
.s
.section
= sectp
;
12331 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12333 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12335 dwo_sections
->str
.s
.section
= sectp
;
12336 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12338 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12340 dwo_sections
->str_offsets
.s
.section
= sectp
;
12341 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12343 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12345 struct dwarf2_section_info type_section
;
12347 memset (&type_section
, 0, sizeof (type_section
));
12348 type_section
.s
.section
= sectp
;
12349 type_section
.size
= bfd_section_size (sectp
);
12350 dwo_sections
->types
.push_back (type_section
);
12354 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12355 by PER_CU. This is for the non-DWP case.
12356 The result is NULL if DWO_NAME can't be found. */
12358 static struct dwo_file
*
12359 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12360 const char *comp_dir
)
12362 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12364 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12367 if (dwarf_read_debug
)
12368 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12372 dwo_file_up
dwo_file (new struct dwo_file
);
12373 dwo_file
->dwo_name
= dwo_name
;
12374 dwo_file
->comp_dir
= comp_dir
;
12375 dwo_file
->dbfd
= std::move (dbfd
);
12377 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12378 &dwo_file
->sections
);
12380 create_cus_hash_table (dwarf2_per_objfile
, cu
, *dwo_file
,
12381 dwo_file
->sections
.info
, dwo_file
->cus
);
12383 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12384 dwo_file
->sections
.types
, dwo_file
->tus
);
12386 if (dwarf_read_debug
)
12387 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12389 return dwo_file
.release ();
12392 /* This function is mapped across the sections and remembers the offset and
12393 size of each of the DWP debugging sections common to version 1 and 2 that
12394 we are interested in. */
12397 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12398 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
->str_dwo
))
12412 dwp_file
->sections
.str
.s
.section
= sectp
;
12413 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12415 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12417 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12418 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12420 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12422 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12423 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12427 /* This function is mapped across the sections and remembers the offset and
12428 size of each of the DWP version 2 debugging sections that we are interested
12429 in. This is split into a separate function because we don't know if we
12430 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12433 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12435 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12436 const struct dwop_section_names
*names
= &dwop_section_names
;
12437 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12439 /* Record the ELF section number for later lookup: this is what the
12440 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12441 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12442 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12444 /* Look for specific sections that we need. */
12445 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12447 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12448 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12450 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12452 dwp_file
->sections
.info
.s
.section
= sectp
;
12453 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12455 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12457 dwp_file
->sections
.line
.s
.section
= sectp
;
12458 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12460 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12462 dwp_file
->sections
.loc
.s
.section
= sectp
;
12463 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12465 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12467 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12468 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12470 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12472 dwp_file
->sections
.macro
.s
.section
= sectp
;
12473 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12475 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12477 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12478 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12480 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12482 dwp_file
->sections
.types
.s
.section
= sectp
;
12483 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12487 /* Hash function for dwp_file loaded CUs/TUs. */
12490 hash_dwp_loaded_cutus (const void *item
)
12492 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12494 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12495 return dwo_unit
->signature
;
12498 /* Equality function for dwp_file loaded CUs/TUs. */
12501 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12503 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12504 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12506 return dua
->signature
== dub
->signature
;
12509 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12512 allocate_dwp_loaded_cutus_table ()
12514 return htab_up (htab_create_alloc (3,
12515 hash_dwp_loaded_cutus
,
12516 eq_dwp_loaded_cutus
,
12517 NULL
, xcalloc
, xfree
));
12520 /* Try to open DWP file FILE_NAME.
12521 The result is the bfd handle of the file.
12522 If there is a problem finding or opening the file, return NULL.
12523 Upon success, the canonicalized path of the file is stored in the bfd,
12524 same as symfile_bfd_open. */
12526 static gdb_bfd_ref_ptr
12527 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12528 const char *file_name
)
12530 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12532 1 /*search_cwd*/));
12536 /* Work around upstream bug 15652.
12537 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12538 [Whether that's a "bug" is debatable, but it is getting in our way.]
12539 We have no real idea where the dwp file is, because gdb's realpath-ing
12540 of the executable's path may have discarded the needed info.
12541 [IWBN if the dwp file name was recorded in the executable, akin to
12542 .gnu_debuglink, but that doesn't exist yet.]
12543 Strip the directory from FILE_NAME and search again. */
12544 if (*debug_file_directory
!= '\0')
12546 /* Don't implicitly search the current directory here.
12547 If the user wants to search "." to handle this case,
12548 it must be added to debug-file-directory. */
12549 return try_open_dwop_file (dwarf2_per_objfile
,
12550 lbasename (file_name
), 1 /*is_dwp*/,
12557 /* Initialize the use of the DWP file for the current objfile.
12558 By convention the name of the DWP file is ${objfile}.dwp.
12559 The result is NULL if it can't be found. */
12561 static std::unique_ptr
<struct dwp_file
>
12562 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12564 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12566 /* Try to find first .dwp for the binary file before any symbolic links
12569 /* If the objfile is a debug file, find the name of the real binary
12570 file and get the name of dwp file from there. */
12571 std::string dwp_name
;
12572 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12574 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12575 const char *backlink_basename
= lbasename (backlink
->original_name
);
12577 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12580 dwp_name
= objfile
->original_name
;
12582 dwp_name
+= ".dwp";
12584 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12586 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12588 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12589 dwp_name
= objfile_name (objfile
);
12590 dwp_name
+= ".dwp";
12591 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12596 if (dwarf_read_debug
)
12597 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12598 return std::unique_ptr
<dwp_file
> ();
12601 const char *name
= bfd_get_filename (dbfd
.get ());
12602 std::unique_ptr
<struct dwp_file
> dwp_file
12603 (new struct dwp_file (name
, std::move (dbfd
)));
12605 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12606 dwp_file
->elf_sections
=
12607 OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
12608 dwp_file
->num_sections
, asection
*);
12610 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12611 dwarf2_locate_common_dwp_sections
,
12614 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12617 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12620 /* The DWP file version is stored in the hash table. Oh well. */
12621 if (dwp_file
->cus
&& dwp_file
->tus
12622 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12624 /* Technically speaking, we should try to limp along, but this is
12625 pretty bizarre. We use pulongest here because that's the established
12626 portability solution (e.g, we cannot use %u for uint32_t). */
12627 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12628 " TU version %s [in DWP file %s]"),
12629 pulongest (dwp_file
->cus
->version
),
12630 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12634 dwp_file
->version
= dwp_file
->cus
->version
;
12635 else if (dwp_file
->tus
)
12636 dwp_file
->version
= dwp_file
->tus
->version
;
12638 dwp_file
->version
= 2;
12640 if (dwp_file
->version
== 2)
12641 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12642 dwarf2_locate_v2_dwp_sections
,
12645 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12646 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12648 if (dwarf_read_debug
)
12650 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12651 fprintf_unfiltered (gdb_stdlog
,
12652 " %s CUs, %s TUs\n",
12653 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12654 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12660 /* Wrapper around open_and_init_dwp_file, only open it once. */
12662 static struct dwp_file
*
12663 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12665 if (! dwarf2_per_objfile
->per_bfd
->dwp_checked
)
12667 dwarf2_per_objfile
->per_bfd
->dwp_file
12668 = open_and_init_dwp_file (dwarf2_per_objfile
);
12669 dwarf2_per_objfile
->per_bfd
->dwp_checked
= 1;
12671 return dwarf2_per_objfile
->per_bfd
->dwp_file
.get ();
12674 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12675 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12676 or in the DWP file for the objfile, referenced by THIS_UNIT.
12677 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12678 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12680 This is called, for example, when wanting to read a variable with a
12681 complex location. Therefore we don't want to do file i/o for every call.
12682 Therefore we don't want to look for a DWO file on every call.
12683 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12684 then we check if we've already seen DWO_NAME, and only THEN do we check
12687 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12688 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12690 static struct dwo_unit
*
12691 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12692 ULONGEST signature
, int is_debug_types
)
12694 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12695 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12696 const char *kind
= is_debug_types
? "TU" : "CU";
12697 void **dwo_file_slot
;
12698 struct dwo_file
*dwo_file
;
12699 struct dwp_file
*dwp_file
;
12701 /* First see if there's a DWP file.
12702 If we have a DWP file but didn't find the DWO inside it, don't
12703 look for the original DWO file. It makes gdb behave differently
12704 depending on whether one is debugging in the build tree. */
12706 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12707 if (dwp_file
!= NULL
)
12709 const struct dwp_hash_table
*dwp_htab
=
12710 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12712 if (dwp_htab
!= NULL
)
12714 struct dwo_unit
*dwo_cutu
=
12715 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12716 signature
, is_debug_types
);
12718 if (dwo_cutu
!= NULL
)
12720 if (dwarf_read_debug
)
12722 fprintf_unfiltered (gdb_stdlog
,
12723 "Virtual DWO %s %s found: @%s\n",
12724 kind
, hex_string (signature
),
12725 host_address_to_string (dwo_cutu
));
12733 /* No DWP file, look for the DWO file. */
12735 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12736 dwo_name
, comp_dir
);
12737 if (*dwo_file_slot
== NULL
)
12739 /* Read in the file and build a table of the CUs/TUs it contains. */
12740 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12742 /* NOTE: This will be NULL if unable to open the file. */
12743 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12745 if (dwo_file
!= NULL
)
12747 struct dwo_unit
*dwo_cutu
= NULL
;
12749 if (is_debug_types
&& dwo_file
->tus
)
12751 struct dwo_unit find_dwo_cutu
;
12753 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12754 find_dwo_cutu
.signature
= signature
;
12756 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12759 else if (!is_debug_types
&& dwo_file
->cus
)
12761 struct dwo_unit find_dwo_cutu
;
12763 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12764 find_dwo_cutu
.signature
= signature
;
12765 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12769 if (dwo_cutu
!= NULL
)
12771 if (dwarf_read_debug
)
12773 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12774 kind
, dwo_name
, hex_string (signature
),
12775 host_address_to_string (dwo_cutu
));
12782 /* We didn't find it. This could mean a dwo_id mismatch, or
12783 someone deleted the DWO/DWP file, or the search path isn't set up
12784 correctly to find the file. */
12786 if (dwarf_read_debug
)
12788 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12789 kind
, dwo_name
, hex_string (signature
));
12792 /* This is a warning and not a complaint because it can be caused by
12793 pilot error (e.g., user accidentally deleting the DWO). */
12795 /* Print the name of the DWP file if we looked there, helps the user
12796 better diagnose the problem. */
12797 std::string dwp_text
;
12799 if (dwp_file
!= NULL
)
12800 dwp_text
= string_printf (" [in DWP file %s]",
12801 lbasename (dwp_file
->name
));
12803 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12804 " [in module %s]"),
12805 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12806 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12811 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12812 See lookup_dwo_cutu_unit for details. */
12814 static struct dwo_unit
*
12815 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12816 ULONGEST signature
)
12818 gdb_assert (!cu
->per_cu
->is_debug_types
);
12820 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12823 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12824 See lookup_dwo_cutu_unit for details. */
12826 static struct dwo_unit
*
12827 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12829 gdb_assert (cu
->per_cu
->is_debug_types
);
12831 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12833 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12836 /* Traversal function for queue_and_load_all_dwo_tus. */
12839 queue_and_load_dwo_tu (void **slot
, void *info
)
12841 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12842 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12843 ULONGEST signature
= dwo_unit
->signature
;
12844 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12846 if (sig_type
!= NULL
)
12848 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12850 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12851 a real dependency of PER_CU on SIG_TYPE. That is detected later
12852 while processing PER_CU. */
12853 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->language
))
12854 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12855 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12861 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12862 The DWO may have the only definition of the type, though it may not be
12863 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12864 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12867 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12869 struct dwo_unit
*dwo_unit
;
12870 struct dwo_file
*dwo_file
;
12872 gdb_assert (!per_cu
->is_debug_types
);
12873 gdb_assert (per_cu
->cu
!= NULL
);
12874 gdb_assert (get_dwp_file (per_cu
->cu
->per_objfile
) == NULL
);
12876 dwo_unit
= per_cu
->cu
->dwo_unit
;
12877 gdb_assert (dwo_unit
!= NULL
);
12879 dwo_file
= dwo_unit
->dwo_file
;
12880 if (dwo_file
->tus
!= NULL
)
12881 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12885 /* Read in various DIEs. */
12887 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12888 Inherit only the children of the DW_AT_abstract_origin DIE not being
12889 already referenced by DW_AT_abstract_origin from the children of the
12893 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12895 struct die_info
*child_die
;
12896 sect_offset
*offsetp
;
12897 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12898 struct die_info
*origin_die
;
12899 /* Iterator of the ORIGIN_DIE children. */
12900 struct die_info
*origin_child_die
;
12901 struct attribute
*attr
;
12902 struct dwarf2_cu
*origin_cu
;
12903 struct pending
**origin_previous_list_in_scope
;
12905 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12909 /* Note that following die references may follow to a die in a
12913 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12915 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12917 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12918 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12920 if (die
->tag
!= origin_die
->tag
12921 && !(die
->tag
== DW_TAG_inlined_subroutine
12922 && origin_die
->tag
== DW_TAG_subprogram
))
12923 complaint (_("DIE %s and its abstract origin %s have different tags"),
12924 sect_offset_str (die
->sect_off
),
12925 sect_offset_str (origin_die
->sect_off
));
12927 std::vector
<sect_offset
> offsets
;
12929 for (child_die
= die
->child
;
12930 child_die
&& child_die
->tag
;
12931 child_die
= child_die
->sibling
)
12933 struct die_info
*child_origin_die
;
12934 struct dwarf2_cu
*child_origin_cu
;
12936 /* We are trying to process concrete instance entries:
12937 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12938 it's not relevant to our analysis here. i.e. detecting DIEs that are
12939 present in the abstract instance but not referenced in the concrete
12941 if (child_die
->tag
== DW_TAG_call_site
12942 || child_die
->tag
== DW_TAG_GNU_call_site
)
12945 /* For each CHILD_DIE, find the corresponding child of
12946 ORIGIN_DIE. If there is more than one layer of
12947 DW_AT_abstract_origin, follow them all; there shouldn't be,
12948 but GCC versions at least through 4.4 generate this (GCC PR
12950 child_origin_die
= child_die
;
12951 child_origin_cu
= cu
;
12954 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12958 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12962 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12963 counterpart may exist. */
12964 if (child_origin_die
!= child_die
)
12966 if (child_die
->tag
!= child_origin_die
->tag
12967 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12968 && child_origin_die
->tag
== DW_TAG_subprogram
))
12969 complaint (_("Child DIE %s and its abstract origin %s have "
12971 sect_offset_str (child_die
->sect_off
),
12972 sect_offset_str (child_origin_die
->sect_off
));
12973 if (child_origin_die
->parent
!= origin_die
)
12974 complaint (_("Child DIE %s and its abstract origin %s have "
12975 "different parents"),
12976 sect_offset_str (child_die
->sect_off
),
12977 sect_offset_str (child_origin_die
->sect_off
));
12979 offsets
.push_back (child_origin_die
->sect_off
);
12982 std::sort (offsets
.begin (), offsets
.end ());
12983 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12984 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12985 if (offsetp
[-1] == *offsetp
)
12986 complaint (_("Multiple children of DIE %s refer "
12987 "to DIE %s as their abstract origin"),
12988 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12990 offsetp
= offsets
.data ();
12991 origin_child_die
= origin_die
->child
;
12992 while (origin_child_die
&& origin_child_die
->tag
)
12994 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12995 while (offsetp
< offsets_end
12996 && *offsetp
< origin_child_die
->sect_off
)
12998 if (offsetp
>= offsets_end
12999 || *offsetp
> origin_child_die
->sect_off
)
13001 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13002 Check whether we're already processing ORIGIN_CHILD_DIE.
13003 This can happen with mutually referenced abstract_origins.
13005 if (!origin_child_die
->in_process
)
13006 process_die (origin_child_die
, origin_cu
);
13008 origin_child_die
= origin_child_die
->sibling
;
13010 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13012 if (cu
!= origin_cu
)
13013 compute_delayed_physnames (origin_cu
);
13017 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13019 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13020 struct gdbarch
*gdbarch
= objfile
->arch ();
13021 struct context_stack
*newobj
;
13024 struct die_info
*child_die
;
13025 struct attribute
*attr
, *call_line
, *call_file
;
13027 CORE_ADDR baseaddr
;
13028 struct block
*block
;
13029 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13030 std::vector
<struct symbol
*> template_args
;
13031 struct template_symbol
*templ_func
= NULL
;
13035 /* If we do not have call site information, we can't show the
13036 caller of this inlined function. That's too confusing, so
13037 only use the scope for local variables. */
13038 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13039 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13040 if (call_line
== NULL
|| call_file
== NULL
)
13042 read_lexical_block_scope (die
, cu
);
13047 baseaddr
= objfile
->text_section_offset ();
13049 name
= dwarf2_name (die
, cu
);
13051 /* Ignore functions with missing or empty names. These are actually
13052 illegal according to the DWARF standard. */
13055 complaint (_("missing name for subprogram DIE at %s"),
13056 sect_offset_str (die
->sect_off
));
13060 /* Ignore functions with missing or invalid low and high pc attributes. */
13061 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13062 <= PC_BOUNDS_INVALID
)
13064 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13065 if (!attr
|| !DW_UNSND (attr
))
13066 complaint (_("cannot get low and high bounds "
13067 "for subprogram DIE at %s"),
13068 sect_offset_str (die
->sect_off
));
13072 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13073 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13075 /* If we have any template arguments, then we must allocate a
13076 different sort of symbol. */
13077 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13079 if (child_die
->tag
== DW_TAG_template_type_param
13080 || child_die
->tag
== DW_TAG_template_value_param
)
13082 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13083 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13088 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13089 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13090 (struct symbol
*) templ_func
);
13092 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13093 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13096 /* If there is a location expression for DW_AT_frame_base, record
13098 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13099 if (attr
!= nullptr)
13100 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13102 /* If there is a location for the static link, record it. */
13103 newobj
->static_link
= NULL
;
13104 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13105 if (attr
!= nullptr)
13107 newobj
->static_link
13108 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13109 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13110 cu
->per_cu
->addr_type ());
13113 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13115 if (die
->child
!= NULL
)
13117 child_die
= die
->child
;
13118 while (child_die
&& child_die
->tag
)
13120 if (child_die
->tag
== DW_TAG_template_type_param
13121 || child_die
->tag
== DW_TAG_template_value_param
)
13123 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13126 template_args
.push_back (arg
);
13129 process_die (child_die
, cu
);
13130 child_die
= child_die
->sibling
;
13134 inherit_abstract_dies (die
, cu
);
13136 /* If we have a DW_AT_specification, we might need to import using
13137 directives from the context of the specification DIE. See the
13138 comment in determine_prefix. */
13139 if (cu
->language
== language_cplus
13140 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13142 struct dwarf2_cu
*spec_cu
= cu
;
13143 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13147 child_die
= spec_die
->child
;
13148 while (child_die
&& child_die
->tag
)
13150 if (child_die
->tag
== DW_TAG_imported_module
)
13151 process_die (child_die
, spec_cu
);
13152 child_die
= child_die
->sibling
;
13155 /* In some cases, GCC generates specification DIEs that
13156 themselves contain DW_AT_specification attributes. */
13157 spec_die
= die_specification (spec_die
, &spec_cu
);
13161 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13162 /* Make a block for the local symbols within. */
13163 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13164 cstk
.static_link
, lowpc
, highpc
);
13166 /* For C++, set the block's scope. */
13167 if ((cu
->language
== language_cplus
13168 || cu
->language
== language_fortran
13169 || cu
->language
== language_d
13170 || cu
->language
== language_rust
)
13171 && cu
->processing_has_namespace_info
)
13172 block_set_scope (block
, determine_prefix (die
, cu
),
13173 &objfile
->objfile_obstack
);
13175 /* If we have address ranges, record them. */
13176 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13178 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13180 /* Attach template arguments to function. */
13181 if (!template_args
.empty ())
13183 gdb_assert (templ_func
!= NULL
);
13185 templ_func
->n_template_arguments
= template_args
.size ();
13186 templ_func
->template_arguments
13187 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13188 templ_func
->n_template_arguments
);
13189 memcpy (templ_func
->template_arguments
,
13190 template_args
.data (),
13191 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13193 /* Make sure that the symtab is set on the new symbols. Even
13194 though they don't appear in this symtab directly, other parts
13195 of gdb assume that symbols do, and this is reasonably
13197 for (symbol
*sym
: template_args
)
13198 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13201 /* In C++, we can have functions nested inside functions (e.g., when
13202 a function declares a class that has methods). This means that
13203 when we finish processing a function scope, we may need to go
13204 back to building a containing block's symbol lists. */
13205 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13206 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13208 /* If we've finished processing a top-level function, subsequent
13209 symbols go in the file symbol list. */
13210 if (cu
->get_builder ()->outermost_context_p ())
13211 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13214 /* Process all the DIES contained within a lexical block scope. Start
13215 a new scope, process the dies, and then close the scope. */
13218 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13220 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13221 struct gdbarch
*gdbarch
= objfile
->arch ();
13222 CORE_ADDR lowpc
, highpc
;
13223 struct die_info
*child_die
;
13224 CORE_ADDR baseaddr
;
13226 baseaddr
= objfile
->text_section_offset ();
13228 /* Ignore blocks with missing or invalid low and high pc attributes. */
13229 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13230 as multiple lexical blocks? Handling children in a sane way would
13231 be nasty. Might be easier to properly extend generic blocks to
13232 describe ranges. */
13233 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13235 case PC_BOUNDS_NOT_PRESENT
:
13236 /* DW_TAG_lexical_block has no attributes, process its children as if
13237 there was no wrapping by that DW_TAG_lexical_block.
13238 GCC does no longer produces such DWARF since GCC r224161. */
13239 for (child_die
= die
->child
;
13240 child_die
!= NULL
&& child_die
->tag
;
13241 child_die
= child_die
->sibling
)
13243 /* We might already be processing this DIE. This can happen
13244 in an unusual circumstance -- where a subroutine A
13245 appears lexically in another subroutine B, but A actually
13246 inlines B. The recursion is broken here, rather than in
13247 inherit_abstract_dies, because it seems better to simply
13248 drop concrete children here. */
13249 if (!child_die
->in_process
)
13250 process_die (child_die
, cu
);
13253 case PC_BOUNDS_INVALID
:
13256 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13257 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13259 cu
->get_builder ()->push_context (0, lowpc
);
13260 if (die
->child
!= NULL
)
13262 child_die
= die
->child
;
13263 while (child_die
&& child_die
->tag
)
13265 process_die (child_die
, cu
);
13266 child_die
= child_die
->sibling
;
13269 inherit_abstract_dies (die
, cu
);
13270 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13272 if (*cu
->get_builder ()->get_local_symbols () != NULL
13273 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13275 struct block
*block
13276 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13277 cstk
.start_addr
, highpc
);
13279 /* Note that recording ranges after traversing children, as we
13280 do here, means that recording a parent's ranges entails
13281 walking across all its children's ranges as they appear in
13282 the address map, which is quadratic behavior.
13284 It would be nicer to record the parent's ranges before
13285 traversing its children, simply overriding whatever you find
13286 there. But since we don't even decide whether to create a
13287 block until after we've traversed its children, that's hard
13289 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13291 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13292 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13295 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13298 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13300 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13301 struct objfile
*objfile
= per_objfile
->objfile
;
13302 struct gdbarch
*gdbarch
= objfile
->arch ();
13303 CORE_ADDR pc
, baseaddr
;
13304 struct attribute
*attr
;
13305 struct call_site
*call_site
, call_site_local
;
13308 struct die_info
*child_die
;
13310 baseaddr
= objfile
->text_section_offset ();
13312 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13315 /* This was a pre-DWARF-5 GNU extension alias
13316 for DW_AT_call_return_pc. */
13317 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13321 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13322 "DIE %s [in module %s]"),
13323 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13326 pc
= attr
->value_as_address () + baseaddr
;
13327 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13329 if (cu
->call_site_htab
== NULL
)
13330 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13331 NULL
, &objfile
->objfile_obstack
,
13332 hashtab_obstack_allocate
, NULL
);
13333 call_site_local
.pc
= pc
;
13334 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13337 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13338 "DIE %s [in module %s]"),
13339 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13340 objfile_name (objfile
));
13344 /* Count parameters at the caller. */
13347 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13348 child_die
= child_die
->sibling
)
13350 if (child_die
->tag
!= DW_TAG_call_site_parameter
13351 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13353 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13354 "DW_TAG_call_site child DIE %s [in module %s]"),
13355 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13356 objfile_name (objfile
));
13364 = ((struct call_site
*)
13365 obstack_alloc (&objfile
->objfile_obstack
,
13366 sizeof (*call_site
)
13367 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13369 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13370 call_site
->pc
= pc
;
13372 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13373 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13375 struct die_info
*func_die
;
13377 /* Skip also over DW_TAG_inlined_subroutine. */
13378 for (func_die
= die
->parent
;
13379 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13380 && func_die
->tag
!= DW_TAG_subroutine_type
;
13381 func_die
= func_die
->parent
);
13383 /* DW_AT_call_all_calls is a superset
13384 of DW_AT_call_all_tail_calls. */
13386 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13387 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13388 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13389 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13391 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13392 not complete. But keep CALL_SITE for look ups via call_site_htab,
13393 both the initial caller containing the real return address PC and
13394 the final callee containing the current PC of a chain of tail
13395 calls do not need to have the tail call list complete. But any
13396 function candidate for a virtual tail call frame searched via
13397 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13398 determined unambiguously. */
13402 struct type
*func_type
= NULL
;
13405 func_type
= get_die_type (func_die
, cu
);
13406 if (func_type
!= NULL
)
13408 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13410 /* Enlist this call site to the function. */
13411 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13412 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13415 complaint (_("Cannot find function owning DW_TAG_call_site "
13416 "DIE %s [in module %s]"),
13417 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13421 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13423 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13425 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13428 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13429 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13431 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13432 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13433 /* Keep NULL DWARF_BLOCK. */;
13434 else if (attr
->form_is_block ())
13436 struct dwarf2_locexpr_baton
*dlbaton
;
13438 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13439 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13440 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13441 dlbaton
->per_objfile
= per_objfile
;
13442 dlbaton
->per_cu
= cu
->per_cu
;
13444 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13446 else if (attr
->form_is_ref ())
13448 struct dwarf2_cu
*target_cu
= cu
;
13449 struct die_info
*target_die
;
13451 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13452 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13453 if (die_is_declaration (target_die
, target_cu
))
13455 const char *target_physname
;
13457 /* Prefer the mangled name; otherwise compute the demangled one. */
13458 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13459 if (target_physname
== NULL
)
13460 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13461 if (target_physname
== NULL
)
13462 complaint (_("DW_AT_call_target target DIE has invalid "
13463 "physname, for referencing DIE %s [in module %s]"),
13464 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13466 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13472 /* DW_AT_entry_pc should be preferred. */
13473 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13474 <= PC_BOUNDS_INVALID
)
13475 complaint (_("DW_AT_call_target target DIE has invalid "
13476 "low pc, for referencing DIE %s [in module %s]"),
13477 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13480 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13481 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13486 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13487 "block nor reference, for DIE %s [in module %s]"),
13488 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13490 call_site
->per_cu
= cu
->per_cu
;
13492 for (child_die
= die
->child
;
13493 child_die
&& child_die
->tag
;
13494 child_die
= child_die
->sibling
)
13496 struct call_site_parameter
*parameter
;
13497 struct attribute
*loc
, *origin
;
13499 if (child_die
->tag
!= DW_TAG_call_site_parameter
13500 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13502 /* Already printed the complaint above. */
13506 gdb_assert (call_site
->parameter_count
< nparams
);
13507 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13509 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13510 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13511 register is contained in DW_AT_call_value. */
13513 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13514 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13515 if (origin
== NULL
)
13517 /* This was a pre-DWARF-5 GNU extension alias
13518 for DW_AT_call_parameter. */
13519 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13521 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13523 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13525 sect_offset sect_off
= origin
->get_ref_die_offset ();
13526 if (!cu
->header
.offset_in_cu_p (sect_off
))
13528 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13529 binding can be done only inside one CU. Such referenced DIE
13530 therefore cannot be even moved to DW_TAG_partial_unit. */
13531 complaint (_("DW_AT_call_parameter offset is not in CU for "
13532 "DW_TAG_call_site child DIE %s [in module %s]"),
13533 sect_offset_str (child_die
->sect_off
),
13534 objfile_name (objfile
));
13537 parameter
->u
.param_cu_off
13538 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13540 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13542 complaint (_("No DW_FORM_block* DW_AT_location for "
13543 "DW_TAG_call_site child DIE %s [in module %s]"),
13544 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13549 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13550 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13551 if (parameter
->u
.dwarf_reg
!= -1)
13552 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13553 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13554 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13555 ¶meter
->u
.fb_offset
))
13556 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13559 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13560 "for DW_FORM_block* DW_AT_location is supported for "
13561 "DW_TAG_call_site child DIE %s "
13563 sect_offset_str (child_die
->sect_off
),
13564 objfile_name (objfile
));
13569 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13571 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13572 if (attr
== NULL
|| !attr
->form_is_block ())
13574 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13575 "DW_TAG_call_site child DIE %s [in module %s]"),
13576 sect_offset_str (child_die
->sect_off
),
13577 objfile_name (objfile
));
13580 parameter
->value
= DW_BLOCK (attr
)->data
;
13581 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13583 /* Parameters are not pre-cleared by memset above. */
13584 parameter
->data_value
= NULL
;
13585 parameter
->data_value_size
= 0;
13586 call_site
->parameter_count
++;
13588 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13590 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13591 if (attr
!= nullptr)
13593 if (!attr
->form_is_block ())
13594 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13595 "DW_TAG_call_site child DIE %s [in module %s]"),
13596 sect_offset_str (child_die
->sect_off
),
13597 objfile_name (objfile
));
13600 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13601 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13607 /* Helper function for read_variable. If DIE represents a virtual
13608 table, then return the type of the concrete object that is
13609 associated with the virtual table. Otherwise, return NULL. */
13611 static struct type
*
13612 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13614 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13618 /* Find the type DIE. */
13619 struct die_info
*type_die
= NULL
;
13620 struct dwarf2_cu
*type_cu
= cu
;
13622 if (attr
->form_is_ref ())
13623 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13624 if (type_die
== NULL
)
13627 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13629 return die_containing_type (type_die
, type_cu
);
13632 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13635 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13637 struct rust_vtable_symbol
*storage
= NULL
;
13639 if (cu
->language
== language_rust
)
13641 struct type
*containing_type
= rust_containing_type (die
, cu
);
13643 if (containing_type
!= NULL
)
13645 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13647 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13648 storage
->concrete_type
= containing_type
;
13649 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13653 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13654 struct attribute
*abstract_origin
13655 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13656 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13657 if (res
== NULL
&& loc
&& abstract_origin
)
13659 /* We have a variable without a name, but with a location and an abstract
13660 origin. This may be a concrete instance of an abstract variable
13661 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13663 struct dwarf2_cu
*origin_cu
= cu
;
13664 struct die_info
*origin_die
13665 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13666 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13667 per_objfile
->per_bfd
->abstract_to_concrete
13668 [origin_die
->sect_off
].push_back (die
->sect_off
);
13672 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13673 reading .debug_rnglists.
13674 Callback's type should be:
13675 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13676 Return true if the attributes are present and valid, otherwise,
13679 template <typename Callback
>
13681 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13682 Callback
&&callback
)
13684 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
13685 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13686 bfd
*obfd
= objfile
->obfd
;
13687 /* Base address selection entry. */
13688 gdb::optional
<CORE_ADDR
> base
;
13689 const gdb_byte
*buffer
;
13690 CORE_ADDR baseaddr
;
13691 bool overflow
= false;
13693 base
= cu
->base_address
;
13695 dwarf2_per_objfile
->per_bfd
->rnglists
.read (objfile
);
13696 if (offset
>= dwarf2_per_objfile
->per_bfd
->rnglists
.size
)
13698 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13702 buffer
= dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13704 baseaddr
= objfile
->text_section_offset ();
13708 /* Initialize it due to a false compiler warning. */
13709 CORE_ADDR range_beginning
= 0, range_end
= 0;
13710 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
13711 + dwarf2_per_objfile
->per_bfd
->rnglists
.size
);
13712 unsigned int bytes_read
;
13714 if (buffer
== buf_end
)
13719 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13722 case DW_RLE_end_of_list
:
13724 case DW_RLE_base_address
:
13725 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13730 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13731 buffer
+= bytes_read
;
13733 case DW_RLE_start_length
:
13734 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13739 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13741 buffer
+= bytes_read
;
13742 range_end
= (range_beginning
13743 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13744 buffer
+= bytes_read
;
13745 if (buffer
> buf_end
)
13751 case DW_RLE_offset_pair
:
13752 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13753 buffer
+= bytes_read
;
13754 if (buffer
> buf_end
)
13759 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13760 buffer
+= bytes_read
;
13761 if (buffer
> buf_end
)
13767 case DW_RLE_start_end
:
13768 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13773 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13775 buffer
+= bytes_read
;
13776 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13777 buffer
+= bytes_read
;
13780 complaint (_("Invalid .debug_rnglists data (no base address)"));
13783 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13785 if (rlet
== DW_RLE_base_address
)
13788 if (!base
.has_value ())
13790 /* We have no valid base address for the ranges
13792 complaint (_("Invalid .debug_rnglists data (no base address)"));
13796 if (range_beginning
> range_end
)
13798 /* Inverted range entries are invalid. */
13799 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13803 /* Empty range entries have no effect. */
13804 if (range_beginning
== range_end
)
13807 range_beginning
+= *base
;
13808 range_end
+= *base
;
13810 /* A not-uncommon case of bad debug info.
13811 Don't pollute the addrmap with bad data. */
13812 if (range_beginning
+ baseaddr
== 0
13813 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
13815 complaint (_(".debug_rnglists entry has start address of zero"
13816 " [in module %s]"), objfile_name (objfile
));
13820 callback (range_beginning
, range_end
);
13825 complaint (_("Offset %d is not terminated "
13826 "for DW_AT_ranges attribute"),
13834 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13835 Callback's type should be:
13836 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13837 Return 1 if the attributes are present and valid, otherwise, return 0. */
13839 template <typename Callback
>
13841 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13842 Callback
&&callback
)
13844 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13845 struct objfile
*objfile
= per_objfile
->objfile
;
13846 struct comp_unit_head
*cu_header
= &cu
->header
;
13847 bfd
*obfd
= objfile
->obfd
;
13848 unsigned int addr_size
= cu_header
->addr_size
;
13849 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13850 /* Base address selection entry. */
13851 gdb::optional
<CORE_ADDR
> base
;
13852 unsigned int dummy
;
13853 const gdb_byte
*buffer
;
13854 CORE_ADDR baseaddr
;
13856 if (cu_header
->version
>= 5)
13857 return dwarf2_rnglists_process (offset
, cu
, callback
);
13859 base
= cu
->base_address
;
13861 per_objfile
->per_bfd
->ranges
.read (objfile
);
13862 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13864 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13868 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13870 baseaddr
= objfile
->text_section_offset ();
13874 CORE_ADDR range_beginning
, range_end
;
13876 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13877 buffer
+= addr_size
;
13878 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13879 buffer
+= addr_size
;
13880 offset
+= 2 * addr_size
;
13882 /* An end of list marker is a pair of zero addresses. */
13883 if (range_beginning
== 0 && range_end
== 0)
13884 /* Found the end of list entry. */
13887 /* Each base address selection entry is a pair of 2 values.
13888 The first is the largest possible address, the second is
13889 the base address. Check for a base address here. */
13890 if ((range_beginning
& mask
) == mask
)
13892 /* If we found the largest possible address, then we already
13893 have the base address in range_end. */
13898 if (!base
.has_value ())
13900 /* We have no valid base address for the ranges
13902 complaint (_("Invalid .debug_ranges data (no base address)"));
13906 if (range_beginning
> range_end
)
13908 /* Inverted range entries are invalid. */
13909 complaint (_("Invalid .debug_ranges data (inverted range)"));
13913 /* Empty range entries have no effect. */
13914 if (range_beginning
== range_end
)
13917 range_beginning
+= *base
;
13918 range_end
+= *base
;
13920 /* A not-uncommon case of bad debug info.
13921 Don't pollute the addrmap with bad data. */
13922 if (range_beginning
+ baseaddr
== 0
13923 && !per_objfile
->per_bfd
->has_section_at_zero
)
13925 complaint (_(".debug_ranges entry has start address of zero"
13926 " [in module %s]"), objfile_name (objfile
));
13930 callback (range_beginning
, range_end
);
13936 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13937 Return 1 if the attributes are present and valid, otherwise, return 0.
13938 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13941 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13942 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13943 dwarf2_psymtab
*ranges_pst
)
13945 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13946 struct gdbarch
*gdbarch
= objfile
->arch ();
13947 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13950 CORE_ADDR high
= 0;
13953 retval
= dwarf2_ranges_process (offset
, cu
,
13954 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13956 if (ranges_pst
!= NULL
)
13961 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13962 range_beginning
+ baseaddr
)
13964 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13965 range_end
+ baseaddr
)
13967 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13968 lowpc
, highpc
- 1, ranges_pst
);
13971 /* FIXME: This is recording everything as a low-high
13972 segment of consecutive addresses. We should have a
13973 data structure for discontiguous block ranges
13977 low
= range_beginning
;
13983 if (range_beginning
< low
)
13984 low
= range_beginning
;
13985 if (range_end
> high
)
13993 /* If the first entry is an end-of-list marker, the range
13994 describes an empty scope, i.e. no instructions. */
14000 *high_return
= high
;
14004 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14005 definition for the return value. *LOWPC and *HIGHPC are set iff
14006 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14008 static enum pc_bounds_kind
14009 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14010 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14011 dwarf2_psymtab
*pst
)
14013 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
14014 struct attribute
*attr
;
14015 struct attribute
*attr_high
;
14017 CORE_ADDR high
= 0;
14018 enum pc_bounds_kind ret
;
14020 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14023 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14024 if (attr
!= nullptr)
14026 low
= attr
->value_as_address ();
14027 high
= attr_high
->value_as_address ();
14028 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14032 /* Found high w/o low attribute. */
14033 return PC_BOUNDS_INVALID
;
14035 /* Found consecutive range of addresses. */
14036 ret
= PC_BOUNDS_HIGH_LOW
;
14040 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14043 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14044 We take advantage of the fact that DW_AT_ranges does not appear
14045 in DW_TAG_compile_unit of DWO files. */
14046 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14047 unsigned int ranges_offset
= (DW_UNSND (attr
)
14048 + (need_ranges_base
14052 /* Value of the DW_AT_ranges attribute is the offset in the
14053 .debug_ranges section. */
14054 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14055 return PC_BOUNDS_INVALID
;
14056 /* Found discontinuous range of addresses. */
14057 ret
= PC_BOUNDS_RANGES
;
14060 return PC_BOUNDS_NOT_PRESENT
;
14063 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14065 return PC_BOUNDS_INVALID
;
14067 /* When using the GNU linker, .gnu.linkonce. sections are used to
14068 eliminate duplicate copies of functions and vtables and such.
14069 The linker will arbitrarily choose one and discard the others.
14070 The AT_*_pc values for such functions refer to local labels in
14071 these sections. If the section from that file was discarded, the
14072 labels are not in the output, so the relocs get a value of 0.
14073 If this is a discarded function, mark the pc bounds as invalid,
14074 so that GDB will ignore it. */
14075 if (low
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
14076 return PC_BOUNDS_INVALID
;
14084 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14085 its low and high PC addresses. Do nothing if these addresses could not
14086 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14087 and HIGHPC to the high address if greater than HIGHPC. */
14090 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14091 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14092 struct dwarf2_cu
*cu
)
14094 CORE_ADDR low
, high
;
14095 struct die_info
*child
= die
->child
;
14097 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14099 *lowpc
= std::min (*lowpc
, low
);
14100 *highpc
= std::max (*highpc
, high
);
14103 /* If the language does not allow nested subprograms (either inside
14104 subprograms or lexical blocks), we're done. */
14105 if (cu
->language
!= language_ada
)
14108 /* Check all the children of the given DIE. If it contains nested
14109 subprograms, then check their pc bounds. Likewise, we need to
14110 check lexical blocks as well, as they may also contain subprogram
14112 while (child
&& child
->tag
)
14114 if (child
->tag
== DW_TAG_subprogram
14115 || child
->tag
== DW_TAG_lexical_block
)
14116 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14117 child
= child
->sibling
;
14121 /* Get the low and high pc's represented by the scope DIE, and store
14122 them in *LOWPC and *HIGHPC. If the correct values can't be
14123 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14126 get_scope_pc_bounds (struct die_info
*die
,
14127 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14128 struct dwarf2_cu
*cu
)
14130 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14131 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14132 CORE_ADDR current_low
, current_high
;
14134 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14135 >= PC_BOUNDS_RANGES
)
14137 best_low
= current_low
;
14138 best_high
= current_high
;
14142 struct die_info
*child
= die
->child
;
14144 while (child
&& child
->tag
)
14146 switch (child
->tag
) {
14147 case DW_TAG_subprogram
:
14148 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14150 case DW_TAG_namespace
:
14151 case DW_TAG_module
:
14152 /* FIXME: carlton/2004-01-16: Should we do this for
14153 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14154 that current GCC's always emit the DIEs corresponding
14155 to definitions of methods of classes as children of a
14156 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14157 the DIEs giving the declarations, which could be
14158 anywhere). But I don't see any reason why the
14159 standards says that they have to be there. */
14160 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14162 if (current_low
!= ((CORE_ADDR
) -1))
14164 best_low
= std::min (best_low
, current_low
);
14165 best_high
= std::max (best_high
, current_high
);
14173 child
= child
->sibling
;
14178 *highpc
= best_high
;
14181 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14185 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14186 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14188 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14189 struct gdbarch
*gdbarch
= objfile
->arch ();
14190 struct attribute
*attr
;
14191 struct attribute
*attr_high
;
14193 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14196 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14197 if (attr
!= nullptr)
14199 CORE_ADDR low
= attr
->value_as_address ();
14200 CORE_ADDR high
= attr_high
->value_as_address ();
14202 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14205 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14206 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14207 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14211 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14212 if (attr
!= nullptr)
14214 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14215 We take advantage of the fact that DW_AT_ranges does not appear
14216 in DW_TAG_compile_unit of DWO files. */
14217 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14219 /* The value of the DW_AT_ranges attribute is the offset of the
14220 address range list in the .debug_ranges section. */
14221 unsigned long offset
= (DW_UNSND (attr
)
14222 + (need_ranges_base
? cu
->ranges_base
: 0));
14224 std::vector
<blockrange
> blockvec
;
14225 dwarf2_ranges_process (offset
, cu
,
14226 [&] (CORE_ADDR start
, CORE_ADDR end
)
14230 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14231 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14232 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14233 blockvec
.emplace_back (start
, end
);
14236 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14240 /* Check whether the producer field indicates either of GCC < 4.6, or the
14241 Intel C/C++ compiler, and cache the result in CU. */
14244 check_producer (struct dwarf2_cu
*cu
)
14248 if (cu
->producer
== NULL
)
14250 /* For unknown compilers expect their behavior is DWARF version
14253 GCC started to support .debug_types sections by -gdwarf-4 since
14254 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14255 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14256 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14257 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14259 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14261 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14262 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14264 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14266 cu
->producer_is_icc
= true;
14267 cu
->producer_is_icc_lt_14
= major
< 14;
14269 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14270 cu
->producer_is_codewarrior
= true;
14273 /* For other non-GCC compilers, expect their behavior is DWARF version
14277 cu
->checked_producer
= true;
14280 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14281 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14282 during 4.6.0 experimental. */
14285 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14287 if (!cu
->checked_producer
)
14288 check_producer (cu
);
14290 return cu
->producer_is_gxx_lt_4_6
;
14294 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14295 with incorrect is_stmt attributes. */
14298 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14300 if (!cu
->checked_producer
)
14301 check_producer (cu
);
14303 return cu
->producer_is_codewarrior
;
14306 /* Return the default accessibility type if it is not overridden by
14307 DW_AT_accessibility. */
14309 static enum dwarf_access_attribute
14310 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14312 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14314 /* The default DWARF 2 accessibility for members is public, the default
14315 accessibility for inheritance is private. */
14317 if (die
->tag
!= DW_TAG_inheritance
)
14318 return DW_ACCESS_public
;
14320 return DW_ACCESS_private
;
14324 /* DWARF 3+ defines the default accessibility a different way. The same
14325 rules apply now for DW_TAG_inheritance as for the members and it only
14326 depends on the container kind. */
14328 if (die
->parent
->tag
== DW_TAG_class_type
)
14329 return DW_ACCESS_private
;
14331 return DW_ACCESS_public
;
14335 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14336 offset. If the attribute was not found return 0, otherwise return
14337 1. If it was found but could not properly be handled, set *OFFSET
14341 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14344 struct attribute
*attr
;
14346 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14351 /* Note that we do not check for a section offset first here.
14352 This is because DW_AT_data_member_location is new in DWARF 4,
14353 so if we see it, we can assume that a constant form is really
14354 a constant and not a section offset. */
14355 if (attr
->form_is_constant ())
14356 *offset
= attr
->constant_value (0);
14357 else if (attr
->form_is_section_offset ())
14358 dwarf2_complex_location_expr_complaint ();
14359 else if (attr
->form_is_block ())
14360 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14362 dwarf2_complex_location_expr_complaint ();
14370 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14373 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14374 struct field
*field
)
14376 struct attribute
*attr
;
14378 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14381 if (attr
->form_is_constant ())
14383 LONGEST offset
= attr
->constant_value (0);
14384 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14386 else if (attr
->form_is_section_offset ())
14387 dwarf2_complex_location_expr_complaint ();
14388 else if (attr
->form_is_block ())
14391 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14393 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14396 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14397 struct objfile
*objfile
= per_objfile
->objfile
;
14398 struct dwarf2_locexpr_baton
*dlbaton
14399 = XOBNEW (&objfile
->objfile_obstack
,
14400 struct dwarf2_locexpr_baton
);
14401 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14402 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14403 /* When using this baton, we want to compute the address
14404 of the field, not the value. This is why
14405 is_reference is set to false here. */
14406 dlbaton
->is_reference
= false;
14407 dlbaton
->per_objfile
= per_objfile
;
14408 dlbaton
->per_cu
= cu
->per_cu
;
14410 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14414 dwarf2_complex_location_expr_complaint ();
14418 /* Add an aggregate field to the field list. */
14421 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14422 struct dwarf2_cu
*cu
)
14424 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14425 struct gdbarch
*gdbarch
= objfile
->arch ();
14426 struct nextfield
*new_field
;
14427 struct attribute
*attr
;
14429 const char *fieldname
= "";
14431 if (die
->tag
== DW_TAG_inheritance
)
14433 fip
->baseclasses
.emplace_back ();
14434 new_field
= &fip
->baseclasses
.back ();
14438 fip
->fields
.emplace_back ();
14439 new_field
= &fip
->fields
.back ();
14442 new_field
->offset
= die
->sect_off
;
14444 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14445 if (attr
!= nullptr)
14446 new_field
->accessibility
= DW_UNSND (attr
);
14448 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14449 if (new_field
->accessibility
!= DW_ACCESS_public
)
14450 fip
->non_public_fields
= 1;
14452 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14453 if (attr
!= nullptr)
14454 new_field
->virtuality
= DW_UNSND (attr
);
14456 new_field
->virtuality
= DW_VIRTUALITY_none
;
14458 fp
= &new_field
->field
;
14460 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14462 /* Data member other than a C++ static data member. */
14464 /* Get type of field. */
14465 fp
->type
= die_type (die
, cu
);
14467 SET_FIELD_BITPOS (*fp
, 0);
14469 /* Get bit size of field (zero if none). */
14470 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14471 if (attr
!= nullptr)
14473 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14477 FIELD_BITSIZE (*fp
) = 0;
14480 /* Get bit offset of field. */
14481 handle_data_member_location (die
, cu
, fp
);
14482 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14483 if (attr
!= nullptr)
14485 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14487 /* For big endian bits, the DW_AT_bit_offset gives the
14488 additional bit offset from the MSB of the containing
14489 anonymous object to the MSB of the field. We don't
14490 have to do anything special since we don't need to
14491 know the size of the anonymous object. */
14492 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14496 /* For little endian bits, compute the bit offset to the
14497 MSB of the anonymous object, subtract off the number of
14498 bits from the MSB of the field to the MSB of the
14499 object, and then subtract off the number of bits of
14500 the field itself. The result is the bit offset of
14501 the LSB of the field. */
14502 int anonymous_size
;
14503 int bit_offset
= DW_UNSND (attr
);
14505 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14506 if (attr
!= nullptr)
14508 /* The size of the anonymous object containing
14509 the bit field is explicit, so use the
14510 indicated size (in bytes). */
14511 anonymous_size
= DW_UNSND (attr
);
14515 /* The size of the anonymous object containing
14516 the bit field must be inferred from the type
14517 attribute of the data member containing the
14519 anonymous_size
= TYPE_LENGTH (fp
->type
);
14521 SET_FIELD_BITPOS (*fp
,
14522 (FIELD_BITPOS (*fp
)
14523 + anonymous_size
* bits_per_byte
14524 - bit_offset
- FIELD_BITSIZE (*fp
)));
14527 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14529 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14530 + attr
->constant_value (0)));
14532 /* Get name of field. */
14533 fieldname
= dwarf2_name (die
, cu
);
14534 if (fieldname
== NULL
)
14537 /* The name is already allocated along with this objfile, so we don't
14538 need to duplicate it for the type. */
14539 fp
->name
= fieldname
;
14541 /* Change accessibility for artificial fields (e.g. virtual table
14542 pointer or virtual base class pointer) to private. */
14543 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14545 FIELD_ARTIFICIAL (*fp
) = 1;
14546 new_field
->accessibility
= DW_ACCESS_private
;
14547 fip
->non_public_fields
= 1;
14550 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14552 /* C++ static member. */
14554 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14555 is a declaration, but all versions of G++ as of this writing
14556 (so through at least 3.2.1) incorrectly generate
14557 DW_TAG_variable tags. */
14559 const char *physname
;
14561 /* Get name of field. */
14562 fieldname
= dwarf2_name (die
, cu
);
14563 if (fieldname
== NULL
)
14566 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14568 /* Only create a symbol if this is an external value.
14569 new_symbol checks this and puts the value in the global symbol
14570 table, which we want. If it is not external, new_symbol
14571 will try to put the value in cu->list_in_scope which is wrong. */
14572 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14574 /* A static const member, not much different than an enum as far as
14575 we're concerned, except that we can support more types. */
14576 new_symbol (die
, NULL
, cu
);
14579 /* Get physical name. */
14580 physname
= dwarf2_physname (fieldname
, die
, cu
);
14582 /* The name is already allocated along with this objfile, so we don't
14583 need to duplicate it for the type. */
14584 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14585 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14586 FIELD_NAME (*fp
) = fieldname
;
14588 else if (die
->tag
== DW_TAG_inheritance
)
14590 /* C++ base class field. */
14591 handle_data_member_location (die
, cu
, fp
);
14592 FIELD_BITSIZE (*fp
) = 0;
14593 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14594 FIELD_NAME (*fp
) = fp
->type
->name ();
14597 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14600 /* Can the type given by DIE define another type? */
14603 type_can_define_types (const struct die_info
*die
)
14607 case DW_TAG_typedef
:
14608 case DW_TAG_class_type
:
14609 case DW_TAG_structure_type
:
14610 case DW_TAG_union_type
:
14611 case DW_TAG_enumeration_type
:
14619 /* Add a type definition defined in the scope of the FIP's class. */
14622 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14623 struct dwarf2_cu
*cu
)
14625 struct decl_field fp
;
14626 memset (&fp
, 0, sizeof (fp
));
14628 gdb_assert (type_can_define_types (die
));
14630 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14631 fp
.name
= dwarf2_name (die
, cu
);
14632 fp
.type
= read_type_die (die
, cu
);
14634 /* Save accessibility. */
14635 enum dwarf_access_attribute accessibility
;
14636 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14638 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14640 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14641 switch (accessibility
)
14643 case DW_ACCESS_public
:
14644 /* The assumed value if neither private nor protected. */
14646 case DW_ACCESS_private
:
14649 case DW_ACCESS_protected
:
14650 fp
.is_protected
= 1;
14653 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14656 if (die
->tag
== DW_TAG_typedef
)
14657 fip
->typedef_field_list
.push_back (fp
);
14659 fip
->nested_types_list
.push_back (fp
);
14662 /* A convenience typedef that's used when finding the discriminant
14663 field for a variant part. */
14664 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14667 /* Compute the discriminant range for a given variant. OBSTACK is
14668 where the results will be stored. VARIANT is the variant to
14669 process. IS_UNSIGNED indicates whether the discriminant is signed
14672 static const gdb::array_view
<discriminant_range
>
14673 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14676 std::vector
<discriminant_range
> ranges
;
14678 if (variant
.default_branch
)
14681 if (variant
.discr_list_data
== nullptr)
14683 discriminant_range r
14684 = {variant
.discriminant_value
, variant
.discriminant_value
};
14685 ranges
.push_back (r
);
14689 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14690 variant
.discr_list_data
->size
);
14691 while (!data
.empty ())
14693 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14695 complaint (_("invalid discriminant marker: %d"), data
[0]);
14698 bool is_range
= data
[0] == DW_DSC_range
;
14699 data
= data
.slice (1);
14701 ULONGEST low
, high
;
14702 unsigned int bytes_read
;
14706 complaint (_("DW_AT_discr_list missing low value"));
14710 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14712 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14714 data
= data
.slice (bytes_read
);
14720 complaint (_("DW_AT_discr_list missing high value"));
14724 high
= read_unsigned_leb128 (nullptr, data
.data (),
14727 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14729 data
= data
.slice (bytes_read
);
14734 ranges
.push_back ({ low
, high
});
14738 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14740 std::copy (ranges
.begin (), ranges
.end (), result
);
14741 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14744 static const gdb::array_view
<variant_part
> create_variant_parts
14745 (struct obstack
*obstack
,
14746 const offset_map_type
&offset_map
,
14747 struct field_info
*fi
,
14748 const std::vector
<variant_part_builder
> &variant_parts
);
14750 /* Fill in a "struct variant" for a given variant field. RESULT is
14751 the variant to fill in. OBSTACK is where any needed allocations
14752 will be done. OFFSET_MAP holds the mapping from section offsets to
14753 fields for the type. FI describes the fields of the type we're
14754 processing. FIELD is the variant field we're converting. */
14757 create_one_variant (variant
&result
, struct obstack
*obstack
,
14758 const offset_map_type
&offset_map
,
14759 struct field_info
*fi
, const variant_field
&field
)
14761 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14762 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14763 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14764 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14765 field
.variant_parts
);
14768 /* Fill in a "struct variant_part" for a given variant part. RESULT
14769 is the variant part to fill in. OBSTACK is where any needed
14770 allocations will be done. OFFSET_MAP holds the mapping from
14771 section offsets to fields for the type. FI describes the fields of
14772 the type we're processing. BUILDER is the variant part to be
14776 create_one_variant_part (variant_part
&result
,
14777 struct obstack
*obstack
,
14778 const offset_map_type
&offset_map
,
14779 struct field_info
*fi
,
14780 const variant_part_builder
&builder
)
14782 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14783 if (iter
== offset_map
.end ())
14785 result
.discriminant_index
= -1;
14786 /* Doesn't matter. */
14787 result
.is_unsigned
= false;
14791 result
.discriminant_index
= iter
->second
;
14793 = TYPE_UNSIGNED (FIELD_TYPE
14794 (fi
->fields
[result
.discriminant_index
].field
));
14797 size_t n
= builder
.variants
.size ();
14798 variant
*output
= new (obstack
) variant
[n
];
14799 for (size_t i
= 0; i
< n
; ++i
)
14800 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14801 builder
.variants
[i
]);
14803 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14806 /* Create a vector of variant parts that can be attached to a type.
14807 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14808 holds the mapping from section offsets to fields for the type. FI
14809 describes the fields of the type we're processing. VARIANT_PARTS
14810 is the vector to convert. */
14812 static const gdb::array_view
<variant_part
>
14813 create_variant_parts (struct obstack
*obstack
,
14814 const offset_map_type
&offset_map
,
14815 struct field_info
*fi
,
14816 const std::vector
<variant_part_builder
> &variant_parts
)
14818 if (variant_parts
.empty ())
14821 size_t n
= variant_parts
.size ();
14822 variant_part
*result
= new (obstack
) variant_part
[n
];
14823 for (size_t i
= 0; i
< n
; ++i
)
14824 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14827 return gdb::array_view
<variant_part
> (result
, n
);
14830 /* Compute the variant part vector for FIP, attaching it to TYPE when
14834 add_variant_property (struct field_info
*fip
, struct type
*type
,
14835 struct dwarf2_cu
*cu
)
14837 /* Map section offsets of fields to their field index. Note the
14838 field index here does not take the number of baseclasses into
14840 offset_map_type offset_map
;
14841 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14842 offset_map
[fip
->fields
[i
].offset
] = i
;
14844 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14845 gdb::array_view
<variant_part
> parts
14846 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14847 fip
->variant_parts
);
14849 struct dynamic_prop prop
;
14850 prop
.kind
= PROP_VARIANT_PARTS
;
14851 prop
.data
.variant_parts
14852 = ((gdb::array_view
<variant_part
> *)
14853 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14855 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14858 /* Create the vector of fields, and attach it to the type. */
14861 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14862 struct dwarf2_cu
*cu
)
14864 int nfields
= fip
->nfields ();
14866 /* Record the field count, allocate space for the array of fields,
14867 and create blank accessibility bitfields if necessary. */
14868 type
->set_num_fields (nfields
);
14870 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14872 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14874 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14876 TYPE_FIELD_PRIVATE_BITS (type
) =
14877 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14878 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14880 TYPE_FIELD_PROTECTED_BITS (type
) =
14881 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14882 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14884 TYPE_FIELD_IGNORE_BITS (type
) =
14885 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14886 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14889 /* If the type has baseclasses, allocate and clear a bit vector for
14890 TYPE_FIELD_VIRTUAL_BITS. */
14891 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14893 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14894 unsigned char *pointer
;
14896 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14897 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14898 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14899 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14900 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14903 if (!fip
->variant_parts
.empty ())
14904 add_variant_property (fip
, type
, cu
);
14906 /* Copy the saved-up fields into the field vector. */
14907 for (int i
= 0; i
< nfields
; ++i
)
14909 struct nextfield
&field
14910 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14911 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14913 type
->field (i
) = field
.field
;
14914 switch (field
.accessibility
)
14916 case DW_ACCESS_private
:
14917 if (cu
->language
!= language_ada
)
14918 SET_TYPE_FIELD_PRIVATE (type
, i
);
14921 case DW_ACCESS_protected
:
14922 if (cu
->language
!= language_ada
)
14923 SET_TYPE_FIELD_PROTECTED (type
, i
);
14926 case DW_ACCESS_public
:
14930 /* Unknown accessibility. Complain and treat it as public. */
14932 complaint (_("unsupported accessibility %d"),
14933 field
.accessibility
);
14937 if (i
< fip
->baseclasses
.size ())
14939 switch (field
.virtuality
)
14941 case DW_VIRTUALITY_virtual
:
14942 case DW_VIRTUALITY_pure_virtual
:
14943 if (cu
->language
== language_ada
)
14944 error (_("unexpected virtuality in component of Ada type"));
14945 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14952 /* Return true if this member function is a constructor, false
14956 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14958 const char *fieldname
;
14959 const char *type_name
;
14962 if (die
->parent
== NULL
)
14965 if (die
->parent
->tag
!= DW_TAG_structure_type
14966 && die
->parent
->tag
!= DW_TAG_union_type
14967 && die
->parent
->tag
!= DW_TAG_class_type
)
14970 fieldname
= dwarf2_name (die
, cu
);
14971 type_name
= dwarf2_name (die
->parent
, cu
);
14972 if (fieldname
== NULL
|| type_name
== NULL
)
14975 len
= strlen (fieldname
);
14976 return (strncmp (fieldname
, type_name
, len
) == 0
14977 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14980 /* Check if the given VALUE is a recognized enum
14981 dwarf_defaulted_attribute constant according to DWARF5 spec,
14985 is_valid_DW_AT_defaulted (ULONGEST value
)
14989 case DW_DEFAULTED_no
:
14990 case DW_DEFAULTED_in_class
:
14991 case DW_DEFAULTED_out_of_class
:
14995 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14999 /* Add a member function to the proper fieldlist. */
15002 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15003 struct type
*type
, struct dwarf2_cu
*cu
)
15005 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15006 struct attribute
*attr
;
15008 struct fnfieldlist
*flp
= nullptr;
15009 struct fn_field
*fnp
;
15010 const char *fieldname
;
15011 struct type
*this_type
;
15012 enum dwarf_access_attribute accessibility
;
15014 if (cu
->language
== language_ada
)
15015 error (_("unexpected member function in Ada type"));
15017 /* Get name of member function. */
15018 fieldname
= dwarf2_name (die
, cu
);
15019 if (fieldname
== NULL
)
15022 /* Look up member function name in fieldlist. */
15023 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15025 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15027 flp
= &fip
->fnfieldlists
[i
];
15032 /* Create a new fnfieldlist if necessary. */
15033 if (flp
== nullptr)
15035 fip
->fnfieldlists
.emplace_back ();
15036 flp
= &fip
->fnfieldlists
.back ();
15037 flp
->name
= fieldname
;
15038 i
= fip
->fnfieldlists
.size () - 1;
15041 /* Create a new member function field and add it to the vector of
15043 flp
->fnfields
.emplace_back ();
15044 fnp
= &flp
->fnfields
.back ();
15046 /* Delay processing of the physname until later. */
15047 if (cu
->language
== language_cplus
)
15048 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15052 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15053 fnp
->physname
= physname
? physname
: "";
15056 fnp
->type
= alloc_type (objfile
);
15057 this_type
= read_type_die (die
, cu
);
15058 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15060 int nparams
= this_type
->num_fields ();
15062 /* TYPE is the domain of this method, and THIS_TYPE is the type
15063 of the method itself (TYPE_CODE_METHOD). */
15064 smash_to_method_type (fnp
->type
, type
,
15065 TYPE_TARGET_TYPE (this_type
),
15066 this_type
->fields (),
15067 this_type
->num_fields (),
15068 TYPE_VARARGS (this_type
));
15070 /* Handle static member functions.
15071 Dwarf2 has no clean way to discern C++ static and non-static
15072 member functions. G++ helps GDB by marking the first
15073 parameter for non-static member functions (which is the this
15074 pointer) as artificial. We obtain this information from
15075 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15076 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15077 fnp
->voffset
= VOFFSET_STATIC
;
15080 complaint (_("member function type missing for '%s'"),
15081 dwarf2_full_name (fieldname
, die
, cu
));
15083 /* Get fcontext from DW_AT_containing_type if present. */
15084 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15085 fnp
->fcontext
= die_containing_type (die
, cu
);
15087 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15088 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15090 /* Get accessibility. */
15091 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15092 if (attr
!= nullptr)
15093 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15095 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15096 switch (accessibility
)
15098 case DW_ACCESS_private
:
15099 fnp
->is_private
= 1;
15101 case DW_ACCESS_protected
:
15102 fnp
->is_protected
= 1;
15106 /* Check for artificial methods. */
15107 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15108 if (attr
&& DW_UNSND (attr
) != 0)
15109 fnp
->is_artificial
= 1;
15111 /* Check for defaulted methods. */
15112 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15113 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15114 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15116 /* Check for deleted methods. */
15117 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15118 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15119 fnp
->is_deleted
= 1;
15121 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15123 /* Get index in virtual function table if it is a virtual member
15124 function. For older versions of GCC, this is an offset in the
15125 appropriate virtual table, as specified by DW_AT_containing_type.
15126 For everyone else, it is an expression to be evaluated relative
15127 to the object address. */
15129 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15130 if (attr
!= nullptr)
15132 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15134 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15136 /* Old-style GCC. */
15137 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15139 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15140 || (DW_BLOCK (attr
)->size
> 1
15141 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15142 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15144 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15145 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15146 dwarf2_complex_location_expr_complaint ();
15148 fnp
->voffset
/= cu
->header
.addr_size
;
15152 dwarf2_complex_location_expr_complaint ();
15154 if (!fnp
->fcontext
)
15156 /* If there is no `this' field and no DW_AT_containing_type,
15157 we cannot actually find a base class context for the
15159 if (this_type
->num_fields () == 0
15160 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15162 complaint (_("cannot determine context for virtual member "
15163 "function \"%s\" (offset %s)"),
15164 fieldname
, sect_offset_str (die
->sect_off
));
15169 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15173 else if (attr
->form_is_section_offset ())
15175 dwarf2_complex_location_expr_complaint ();
15179 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15185 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15186 if (attr
&& DW_UNSND (attr
))
15188 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15189 complaint (_("Member function \"%s\" (offset %s) is virtual "
15190 "but the vtable offset is not specified"),
15191 fieldname
, sect_offset_str (die
->sect_off
));
15192 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15193 TYPE_CPLUS_DYNAMIC (type
) = 1;
15198 /* Create the vector of member function fields, and attach it to the type. */
15201 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15202 struct dwarf2_cu
*cu
)
15204 if (cu
->language
== language_ada
)
15205 error (_("unexpected member functions in Ada type"));
15207 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15208 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15210 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15212 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15214 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15215 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15217 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15218 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15219 fn_flp
->fn_fields
= (struct fn_field
*)
15220 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15222 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15223 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15226 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15229 /* Returns non-zero if NAME is the name of a vtable member in CU's
15230 language, zero otherwise. */
15232 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15234 static const char vptr
[] = "_vptr";
15236 /* Look for the C++ form of the vtable. */
15237 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15243 /* GCC outputs unnamed structures that are really pointers to member
15244 functions, with the ABI-specified layout. If TYPE describes
15245 such a structure, smash it into a member function type.
15247 GCC shouldn't do this; it should just output pointer to member DIEs.
15248 This is GCC PR debug/28767. */
15251 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15253 struct type
*pfn_type
, *self_type
, *new_type
;
15255 /* Check for a structure with no name and two children. */
15256 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15259 /* Check for __pfn and __delta members. */
15260 if (TYPE_FIELD_NAME (type
, 0) == NULL
15261 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15262 || TYPE_FIELD_NAME (type
, 1) == NULL
15263 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15266 /* Find the type of the method. */
15267 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15268 if (pfn_type
== NULL
15269 || pfn_type
->code () != TYPE_CODE_PTR
15270 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15273 /* Look for the "this" argument. */
15274 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15275 if (pfn_type
->num_fields () == 0
15276 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15277 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15280 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15281 new_type
= alloc_type (objfile
);
15282 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15283 pfn_type
->fields (), pfn_type
->num_fields (),
15284 TYPE_VARARGS (pfn_type
));
15285 smash_to_methodptr_type (type
, new_type
);
15288 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15289 appropriate error checking and issuing complaints if there is a
15293 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15295 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15297 if (attr
== nullptr)
15300 if (!attr
->form_is_constant ())
15302 complaint (_("DW_AT_alignment must have constant form"
15303 " - DIE at %s [in module %s]"),
15304 sect_offset_str (die
->sect_off
),
15305 objfile_name (cu
->per_objfile
->objfile
));
15310 if (attr
->form
== DW_FORM_sdata
)
15312 LONGEST val
= DW_SND (attr
);
15315 complaint (_("DW_AT_alignment value must not be negative"
15316 " - DIE at %s [in module %s]"),
15317 sect_offset_str (die
->sect_off
),
15318 objfile_name (cu
->per_objfile
->objfile
));
15324 align
= DW_UNSND (attr
);
15328 complaint (_("DW_AT_alignment value must not be zero"
15329 " - DIE at %s [in module %s]"),
15330 sect_offset_str (die
->sect_off
),
15331 objfile_name (cu
->per_objfile
->objfile
));
15334 if ((align
& (align
- 1)) != 0)
15336 complaint (_("DW_AT_alignment value must be a power of 2"
15337 " - DIE at %s [in module %s]"),
15338 sect_offset_str (die
->sect_off
),
15339 objfile_name (cu
->per_objfile
->objfile
));
15346 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15347 the alignment for TYPE. */
15350 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15353 if (!set_type_align (type
, get_alignment (cu
, die
)))
15354 complaint (_("DW_AT_alignment value too large"
15355 " - DIE at %s [in module %s]"),
15356 sect_offset_str (die
->sect_off
),
15357 objfile_name (cu
->per_objfile
->objfile
));
15360 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15361 constant for a type, according to DWARF5 spec, Table 5.5. */
15364 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15369 case DW_CC_pass_by_reference
:
15370 case DW_CC_pass_by_value
:
15374 complaint (_("unrecognized DW_AT_calling_convention value "
15375 "(%s) for a type"), pulongest (value
));
15380 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15381 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15382 also according to GNU-specific values (see include/dwarf2.h). */
15385 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15390 case DW_CC_program
:
15394 case DW_CC_GNU_renesas_sh
:
15395 case DW_CC_GNU_borland_fastcall_i386
:
15396 case DW_CC_GDB_IBM_OpenCL
:
15400 complaint (_("unrecognized DW_AT_calling_convention value "
15401 "(%s) for a subroutine"), pulongest (value
));
15406 /* Called when we find the DIE that starts a structure or union scope
15407 (definition) to create a type for the structure or union. Fill in
15408 the type's name and general properties; the members will not be
15409 processed until process_structure_scope. A symbol table entry for
15410 the type will also not be done until process_structure_scope (assuming
15411 the type has a name).
15413 NOTE: we need to call these functions regardless of whether or not the
15414 DIE has a DW_AT_name attribute, since it might be an anonymous
15415 structure or union. This gets the type entered into our set of
15416 user defined types. */
15418 static struct type
*
15419 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15421 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15423 struct attribute
*attr
;
15426 /* If the definition of this type lives in .debug_types, read that type.
15427 Don't follow DW_AT_specification though, that will take us back up
15428 the chain and we want to go down. */
15429 attr
= die
->attr (DW_AT_signature
);
15430 if (attr
!= nullptr)
15432 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15434 /* The type's CU may not be the same as CU.
15435 Ensure TYPE is recorded with CU in die_type_hash. */
15436 return set_die_type (die
, type
, cu
);
15439 type
= alloc_type (objfile
);
15440 INIT_CPLUS_SPECIFIC (type
);
15442 name
= dwarf2_name (die
, cu
);
15445 if (cu
->language
== language_cplus
15446 || cu
->language
== language_d
15447 || cu
->language
== language_rust
)
15449 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15451 /* dwarf2_full_name might have already finished building the DIE's
15452 type. If so, there is no need to continue. */
15453 if (get_die_type (die
, cu
) != NULL
)
15454 return get_die_type (die
, cu
);
15456 type
->set_name (full_name
);
15460 /* The name is already allocated along with this objfile, so
15461 we don't need to duplicate it for the type. */
15462 type
->set_name (name
);
15466 if (die
->tag
== DW_TAG_structure_type
)
15468 type
->set_code (TYPE_CODE_STRUCT
);
15470 else if (die
->tag
== DW_TAG_union_type
)
15472 type
->set_code (TYPE_CODE_UNION
);
15476 type
->set_code (TYPE_CODE_STRUCT
);
15479 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15480 TYPE_DECLARED_CLASS (type
) = 1;
15482 /* Store the calling convention in the type if it's available in
15483 the die. Otherwise the calling convention remains set to
15484 the default value DW_CC_normal. */
15485 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15486 if (attr
!= nullptr
15487 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15489 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15490 TYPE_CPLUS_CALLING_CONVENTION (type
)
15491 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15494 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15495 if (attr
!= nullptr)
15497 if (attr
->form_is_constant ())
15498 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15501 struct dynamic_prop prop
;
15502 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
15503 cu
->per_cu
->addr_type ()))
15504 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15505 TYPE_LENGTH (type
) = 0;
15510 TYPE_LENGTH (type
) = 0;
15513 maybe_set_alignment (cu
, die
, type
);
15515 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15517 /* ICC<14 does not output the required DW_AT_declaration on
15518 incomplete types, but gives them a size of zero. */
15519 TYPE_STUB (type
) = 1;
15522 TYPE_STUB_SUPPORTED (type
) = 1;
15524 if (die_is_declaration (die
, cu
))
15525 TYPE_STUB (type
) = 1;
15526 else if (attr
== NULL
&& die
->child
== NULL
15527 && producer_is_realview (cu
->producer
))
15528 /* RealView does not output the required DW_AT_declaration
15529 on incomplete types. */
15530 TYPE_STUB (type
) = 1;
15532 /* We need to add the type field to the die immediately so we don't
15533 infinitely recurse when dealing with pointers to the structure
15534 type within the structure itself. */
15535 set_die_type (die
, type
, cu
);
15537 /* set_die_type should be already done. */
15538 set_descriptive_type (type
, die
, cu
);
15543 static void handle_struct_member_die
15544 (struct die_info
*child_die
,
15546 struct field_info
*fi
,
15547 std::vector
<struct symbol
*> *template_args
,
15548 struct dwarf2_cu
*cu
);
15550 /* A helper for handle_struct_member_die that handles
15551 DW_TAG_variant_part. */
15554 handle_variant_part (struct die_info
*die
, struct type
*type
,
15555 struct field_info
*fi
,
15556 std::vector
<struct symbol
*> *template_args
,
15557 struct dwarf2_cu
*cu
)
15559 variant_part_builder
*new_part
;
15560 if (fi
->current_variant_part
== nullptr)
15562 fi
->variant_parts
.emplace_back ();
15563 new_part
= &fi
->variant_parts
.back ();
15565 else if (!fi
->current_variant_part
->processing_variant
)
15567 complaint (_("nested DW_TAG_variant_part seen "
15568 "- DIE at %s [in module %s]"),
15569 sect_offset_str (die
->sect_off
),
15570 objfile_name (cu
->per_objfile
->objfile
));
15575 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15576 current
.variant_parts
.emplace_back ();
15577 new_part
= ¤t
.variant_parts
.back ();
15580 /* When we recurse, we want callees to add to this new variant
15582 scoped_restore save_current_variant_part
15583 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15585 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15588 /* It's a univariant form, an extension we support. */
15590 else if (discr
->form_is_ref ())
15592 struct dwarf2_cu
*target_cu
= cu
;
15593 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15595 new_part
->discriminant_offset
= target_die
->sect_off
;
15599 complaint (_("DW_AT_discr does not have DIE reference form"
15600 " - DIE at %s [in module %s]"),
15601 sect_offset_str (die
->sect_off
),
15602 objfile_name (cu
->per_objfile
->objfile
));
15605 for (die_info
*child_die
= die
->child
;
15607 child_die
= child_die
->sibling
)
15608 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15611 /* A helper for handle_struct_member_die that handles
15615 handle_variant (struct die_info
*die
, struct type
*type
,
15616 struct field_info
*fi
,
15617 std::vector
<struct symbol
*> *template_args
,
15618 struct dwarf2_cu
*cu
)
15620 if (fi
->current_variant_part
== nullptr)
15622 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15623 "- DIE at %s [in module %s]"),
15624 sect_offset_str (die
->sect_off
),
15625 objfile_name (cu
->per_objfile
->objfile
));
15628 if (fi
->current_variant_part
->processing_variant
)
15630 complaint (_("nested DW_TAG_variant seen "
15631 "- DIE at %s [in module %s]"),
15632 sect_offset_str (die
->sect_off
),
15633 objfile_name (cu
->per_objfile
->objfile
));
15637 scoped_restore save_processing_variant
15638 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15641 fi
->current_variant_part
->variants
.emplace_back ();
15642 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15643 variant
.first_field
= fi
->fields
.size ();
15645 /* In a variant we want to get the discriminant and also add a
15646 field for our sole member child. */
15647 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15648 if (discr
== nullptr)
15650 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15651 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15652 variant
.default_branch
= true;
15654 variant
.discr_list_data
= DW_BLOCK (discr
);
15657 variant
.discriminant_value
= DW_UNSND (discr
);
15659 for (die_info
*variant_child
= die
->child
;
15660 variant_child
!= NULL
;
15661 variant_child
= variant_child
->sibling
)
15662 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15664 variant
.last_field
= fi
->fields
.size ();
15667 /* A helper for process_structure_scope that handles a single member
15671 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15672 struct field_info
*fi
,
15673 std::vector
<struct symbol
*> *template_args
,
15674 struct dwarf2_cu
*cu
)
15676 if (child_die
->tag
== DW_TAG_member
15677 || child_die
->tag
== DW_TAG_variable
)
15679 /* NOTE: carlton/2002-11-05: A C++ static data member
15680 should be a DW_TAG_member that is a declaration, but
15681 all versions of G++ as of this writing (so through at
15682 least 3.2.1) incorrectly generate DW_TAG_variable
15683 tags for them instead. */
15684 dwarf2_add_field (fi
, child_die
, cu
);
15686 else if (child_die
->tag
== DW_TAG_subprogram
)
15688 /* Rust doesn't have member functions in the C++ sense.
15689 However, it does emit ordinary functions as children
15690 of a struct DIE. */
15691 if (cu
->language
== language_rust
)
15692 read_func_scope (child_die
, cu
);
15695 /* C++ member function. */
15696 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15699 else if (child_die
->tag
== DW_TAG_inheritance
)
15701 /* C++ base class field. */
15702 dwarf2_add_field (fi
, child_die
, cu
);
15704 else if (type_can_define_types (child_die
))
15705 dwarf2_add_type_defn (fi
, child_die
, cu
);
15706 else if (child_die
->tag
== DW_TAG_template_type_param
15707 || child_die
->tag
== DW_TAG_template_value_param
)
15709 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15712 template_args
->push_back (arg
);
15714 else if (child_die
->tag
== DW_TAG_variant_part
)
15715 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15716 else if (child_die
->tag
== DW_TAG_variant
)
15717 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15720 /* Finish creating a structure or union type, including filling in
15721 its members and creating a symbol for it. */
15724 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15726 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15727 struct die_info
*child_die
;
15730 type
= get_die_type (die
, cu
);
15732 type
= read_structure_type (die
, cu
);
15734 bool has_template_parameters
= false;
15735 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15737 struct field_info fi
;
15738 std::vector
<struct symbol
*> template_args
;
15740 child_die
= die
->child
;
15742 while (child_die
&& child_die
->tag
)
15744 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15745 child_die
= child_die
->sibling
;
15748 /* Attach template arguments to type. */
15749 if (!template_args
.empty ())
15751 has_template_parameters
= true;
15752 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15753 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15754 TYPE_TEMPLATE_ARGUMENTS (type
)
15755 = XOBNEWVEC (&objfile
->objfile_obstack
,
15757 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15758 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15759 template_args
.data (),
15760 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15761 * sizeof (struct symbol
*)));
15764 /* Attach fields and member functions to the type. */
15765 if (fi
.nfields () > 0)
15766 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15767 if (!fi
.fnfieldlists
.empty ())
15769 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15771 /* Get the type which refers to the base class (possibly this
15772 class itself) which contains the vtable pointer for the current
15773 class from the DW_AT_containing_type attribute. This use of
15774 DW_AT_containing_type is a GNU extension. */
15776 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15778 struct type
*t
= die_containing_type (die
, cu
);
15780 set_type_vptr_basetype (type
, t
);
15785 /* Our own class provides vtbl ptr. */
15786 for (i
= t
->num_fields () - 1;
15787 i
>= TYPE_N_BASECLASSES (t
);
15790 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15792 if (is_vtable_name (fieldname
, cu
))
15794 set_type_vptr_fieldno (type
, i
);
15799 /* Complain if virtual function table field not found. */
15800 if (i
< TYPE_N_BASECLASSES (t
))
15801 complaint (_("virtual function table pointer "
15802 "not found when defining class '%s'"),
15803 type
->name () ? type
->name () : "");
15807 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15810 else if (cu
->producer
15811 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15813 /* The IBM XLC compiler does not provide direct indication
15814 of the containing type, but the vtable pointer is
15815 always named __vfp. */
15819 for (i
= type
->num_fields () - 1;
15820 i
>= TYPE_N_BASECLASSES (type
);
15823 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15825 set_type_vptr_fieldno (type
, i
);
15826 set_type_vptr_basetype (type
, type
);
15833 /* Copy fi.typedef_field_list linked list elements content into the
15834 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15835 if (!fi
.typedef_field_list
.empty ())
15837 int count
= fi
.typedef_field_list
.size ();
15839 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15840 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15841 = ((struct decl_field
*)
15843 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15844 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15846 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15847 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15850 /* Copy fi.nested_types_list linked list elements content into the
15851 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15852 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15854 int count
= fi
.nested_types_list
.size ();
15856 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15857 TYPE_NESTED_TYPES_ARRAY (type
)
15858 = ((struct decl_field
*)
15859 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15860 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15862 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15863 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15867 quirk_gcc_member_function_pointer (type
, objfile
);
15868 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15869 cu
->rust_unions
.push_back (type
);
15871 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15872 snapshots) has been known to create a die giving a declaration
15873 for a class that has, as a child, a die giving a definition for a
15874 nested class. So we have to process our children even if the
15875 current die is a declaration. Normally, of course, a declaration
15876 won't have any children at all. */
15878 child_die
= die
->child
;
15880 while (child_die
!= NULL
&& child_die
->tag
)
15882 if (child_die
->tag
== DW_TAG_member
15883 || child_die
->tag
== DW_TAG_variable
15884 || child_die
->tag
== DW_TAG_inheritance
15885 || child_die
->tag
== DW_TAG_template_value_param
15886 || child_die
->tag
== DW_TAG_template_type_param
)
15891 process_die (child_die
, cu
);
15893 child_die
= child_die
->sibling
;
15896 /* Do not consider external references. According to the DWARF standard,
15897 these DIEs are identified by the fact that they have no byte_size
15898 attribute, and a declaration attribute. */
15899 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15900 || !die_is_declaration (die
, cu
)
15901 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15903 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15905 if (has_template_parameters
)
15907 struct symtab
*symtab
;
15908 if (sym
!= nullptr)
15909 symtab
= symbol_symtab (sym
);
15910 else if (cu
->line_header
!= nullptr)
15912 /* Any related symtab will do. */
15914 = cu
->line_header
->file_names ()[0].symtab
;
15919 complaint (_("could not find suitable "
15920 "symtab for template parameter"
15921 " - DIE at %s [in module %s]"),
15922 sect_offset_str (die
->sect_off
),
15923 objfile_name (objfile
));
15926 if (symtab
!= nullptr)
15928 /* Make sure that the symtab is set on the new symbols.
15929 Even though they don't appear in this symtab directly,
15930 other parts of gdb assume that symbols do, and this is
15931 reasonably true. */
15932 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15933 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15939 /* Assuming DIE is an enumeration type, and TYPE is its associated
15940 type, update TYPE using some information only available in DIE's
15941 children. In particular, the fields are computed. */
15944 update_enumeration_type_from_children (struct die_info
*die
,
15946 struct dwarf2_cu
*cu
)
15948 struct die_info
*child_die
;
15949 int unsigned_enum
= 1;
15952 auto_obstack obstack
;
15953 std::vector
<struct field
> fields
;
15955 for (child_die
= die
->child
;
15956 child_die
!= NULL
&& child_die
->tag
;
15957 child_die
= child_die
->sibling
)
15959 struct attribute
*attr
;
15961 const gdb_byte
*bytes
;
15962 struct dwarf2_locexpr_baton
*baton
;
15965 if (child_die
->tag
!= DW_TAG_enumerator
)
15968 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15972 name
= dwarf2_name (child_die
, cu
);
15974 name
= "<anonymous enumerator>";
15976 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15977 &value
, &bytes
, &baton
);
15985 if (count_one_bits_ll (value
) >= 2)
15989 fields
.emplace_back ();
15990 struct field
&field
= fields
.back ();
15991 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
15992 SET_FIELD_ENUMVAL (field
, value
);
15995 if (!fields
.empty ())
15997 type
->set_num_fields (fields
.size ());
16000 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16001 memcpy (type
->fields (), fields
.data (),
16002 sizeof (struct field
) * fields
.size ());
16006 TYPE_UNSIGNED (type
) = 1;
16008 TYPE_FLAG_ENUM (type
) = 1;
16011 /* Given a DW_AT_enumeration_type die, set its type. We do not
16012 complete the type's fields yet, or create any symbols. */
16014 static struct type
*
16015 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16017 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16019 struct attribute
*attr
;
16022 /* If the definition of this type lives in .debug_types, read that type.
16023 Don't follow DW_AT_specification though, that will take us back up
16024 the chain and we want to go down. */
16025 attr
= die
->attr (DW_AT_signature
);
16026 if (attr
!= nullptr)
16028 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16030 /* The type's CU may not be the same as CU.
16031 Ensure TYPE is recorded with CU in die_type_hash. */
16032 return set_die_type (die
, type
, cu
);
16035 type
= alloc_type (objfile
);
16037 type
->set_code (TYPE_CODE_ENUM
);
16038 name
= dwarf2_full_name (NULL
, die
, cu
);
16040 type
->set_name (name
);
16042 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16045 struct type
*underlying_type
= die_type (die
, cu
);
16047 TYPE_TARGET_TYPE (type
) = underlying_type
;
16050 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16051 if (attr
!= nullptr)
16053 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16057 TYPE_LENGTH (type
) = 0;
16060 maybe_set_alignment (cu
, die
, type
);
16062 /* The enumeration DIE can be incomplete. In Ada, any type can be
16063 declared as private in the package spec, and then defined only
16064 inside the package body. Such types are known as Taft Amendment
16065 Types. When another package uses such a type, an incomplete DIE
16066 may be generated by the compiler. */
16067 if (die_is_declaration (die
, cu
))
16068 TYPE_STUB (type
) = 1;
16070 /* If this type has an underlying type that is not a stub, then we
16071 may use its attributes. We always use the "unsigned" attribute
16072 in this situation, because ordinarily we guess whether the type
16073 is unsigned -- but the guess can be wrong and the underlying type
16074 can tell us the reality. However, we defer to a local size
16075 attribute if one exists, because this lets the compiler override
16076 the underlying type if needed. */
16077 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16079 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16080 underlying_type
= check_typedef (underlying_type
);
16081 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16082 if (TYPE_LENGTH (type
) == 0)
16083 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16084 if (TYPE_RAW_ALIGN (type
) == 0
16085 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16086 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16089 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16091 set_die_type (die
, type
, cu
);
16093 /* Finish the creation of this type by using the enum's children.
16094 Note that, as usual, this must come after set_die_type to avoid
16095 infinite recursion when trying to compute the names of the
16097 update_enumeration_type_from_children (die
, type
, cu
);
16102 /* Given a pointer to a die which begins an enumeration, process all
16103 the dies that define the members of the enumeration, and create the
16104 symbol for the enumeration type.
16106 NOTE: We reverse the order of the element list. */
16109 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16111 struct type
*this_type
;
16113 this_type
= get_die_type (die
, cu
);
16114 if (this_type
== NULL
)
16115 this_type
= read_enumeration_type (die
, cu
);
16117 if (die
->child
!= NULL
)
16119 struct die_info
*child_die
;
16122 child_die
= die
->child
;
16123 while (child_die
&& child_die
->tag
)
16125 if (child_die
->tag
!= DW_TAG_enumerator
)
16127 process_die (child_die
, cu
);
16131 name
= dwarf2_name (child_die
, cu
);
16133 new_symbol (child_die
, this_type
, cu
);
16136 child_die
= child_die
->sibling
;
16140 /* If we are reading an enum from a .debug_types unit, and the enum
16141 is a declaration, and the enum is not the signatured type in the
16142 unit, then we do not want to add a symbol for it. Adding a
16143 symbol would in some cases obscure the true definition of the
16144 enum, giving users an incomplete type when the definition is
16145 actually available. Note that we do not want to do this for all
16146 enums which are just declarations, because C++0x allows forward
16147 enum declarations. */
16148 if (cu
->per_cu
->is_debug_types
16149 && die_is_declaration (die
, cu
))
16151 struct signatured_type
*sig_type
;
16153 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16154 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16155 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16159 new_symbol (die
, this_type
, cu
);
16162 /* Extract all information from a DW_TAG_array_type DIE and put it in
16163 the DIE's type field. For now, this only handles one dimensional
16166 static struct type
*
16167 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16169 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16170 struct die_info
*child_die
;
16172 struct type
*element_type
, *range_type
, *index_type
;
16173 struct attribute
*attr
;
16175 struct dynamic_prop
*byte_stride_prop
= NULL
;
16176 unsigned int bit_stride
= 0;
16178 element_type
= die_type (die
, cu
);
16180 /* The die_type call above may have already set the type for this DIE. */
16181 type
= get_die_type (die
, cu
);
16185 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16189 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
16192 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16193 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16197 complaint (_("unable to read array DW_AT_byte_stride "
16198 " - DIE at %s [in module %s]"),
16199 sect_offset_str (die
->sect_off
),
16200 objfile_name (cu
->per_objfile
->objfile
));
16201 /* Ignore this attribute. We will likely not be able to print
16202 arrays of this type correctly, but there is little we can do
16203 to help if we cannot read the attribute's value. */
16204 byte_stride_prop
= NULL
;
16208 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16210 bit_stride
= DW_UNSND (attr
);
16212 /* Irix 6.2 native cc creates array types without children for
16213 arrays with unspecified length. */
16214 if (die
->child
== NULL
)
16216 index_type
= objfile_type (objfile
)->builtin_int
;
16217 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16218 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16219 byte_stride_prop
, bit_stride
);
16220 return set_die_type (die
, type
, cu
);
16223 std::vector
<struct type
*> range_types
;
16224 child_die
= die
->child
;
16225 while (child_die
&& child_die
->tag
)
16227 if (child_die
->tag
== DW_TAG_subrange_type
)
16229 struct type
*child_type
= read_type_die (child_die
, cu
);
16231 if (child_type
!= NULL
)
16233 /* The range type was succesfully read. Save it for the
16234 array type creation. */
16235 range_types
.push_back (child_type
);
16238 child_die
= child_die
->sibling
;
16241 /* Dwarf2 dimensions are output from left to right, create the
16242 necessary array types in backwards order. */
16244 type
= element_type
;
16246 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16250 while (i
< range_types
.size ())
16251 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16252 byte_stride_prop
, bit_stride
);
16256 size_t ndim
= range_types
.size ();
16258 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16259 byte_stride_prop
, bit_stride
);
16262 /* Understand Dwarf2 support for vector types (like they occur on
16263 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16264 array type. This is not part of the Dwarf2/3 standard yet, but a
16265 custom vendor extension. The main difference between a regular
16266 array and the vector variant is that vectors are passed by value
16268 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16269 if (attr
!= nullptr)
16270 make_vector_type (type
);
16272 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16273 implementation may choose to implement triple vectors using this
16275 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16276 if (attr
!= nullptr)
16278 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16279 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16281 complaint (_("DW_AT_byte_size for array type smaller "
16282 "than the total size of elements"));
16285 name
= dwarf2_name (die
, cu
);
16287 type
->set_name (name
);
16289 maybe_set_alignment (cu
, die
, type
);
16291 /* Install the type in the die. */
16292 set_die_type (die
, type
, cu
);
16294 /* set_die_type should be already done. */
16295 set_descriptive_type (type
, die
, cu
);
16300 static enum dwarf_array_dim_ordering
16301 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16303 struct attribute
*attr
;
16305 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16307 if (attr
!= nullptr)
16308 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16310 /* GNU F77 is a special case, as at 08/2004 array type info is the
16311 opposite order to the dwarf2 specification, but data is still
16312 laid out as per normal fortran.
16314 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16315 version checking. */
16317 if (cu
->language
== language_fortran
16318 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16320 return DW_ORD_row_major
;
16323 switch (cu
->language_defn
->la_array_ordering
)
16325 case array_column_major
:
16326 return DW_ORD_col_major
;
16327 case array_row_major
:
16329 return DW_ORD_row_major
;
16333 /* Extract all information from a DW_TAG_set_type DIE and put it in
16334 the DIE's type field. */
16336 static struct type
*
16337 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16339 struct type
*domain_type
, *set_type
;
16340 struct attribute
*attr
;
16342 domain_type
= die_type (die
, cu
);
16344 /* The die_type call above may have already set the type for this DIE. */
16345 set_type
= get_die_type (die
, cu
);
16349 set_type
= create_set_type (NULL
, domain_type
);
16351 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16352 if (attr
!= nullptr)
16353 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16355 maybe_set_alignment (cu
, die
, set_type
);
16357 return set_die_type (die
, set_type
, cu
);
16360 /* A helper for read_common_block that creates a locexpr baton.
16361 SYM is the symbol which we are marking as computed.
16362 COMMON_DIE is the DIE for the common block.
16363 COMMON_LOC is the location expression attribute for the common
16365 MEMBER_LOC is the location expression attribute for the particular
16366 member of the common block that we are processing.
16367 CU is the CU from which the above come. */
16370 mark_common_block_symbol_computed (struct symbol
*sym
,
16371 struct die_info
*common_die
,
16372 struct attribute
*common_loc
,
16373 struct attribute
*member_loc
,
16374 struct dwarf2_cu
*cu
)
16376 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16377 struct objfile
*objfile
= per_objfile
->objfile
;
16378 struct dwarf2_locexpr_baton
*baton
;
16380 unsigned int cu_off
;
16381 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16382 LONGEST offset
= 0;
16384 gdb_assert (common_loc
&& member_loc
);
16385 gdb_assert (common_loc
->form_is_block ());
16386 gdb_assert (member_loc
->form_is_block ()
16387 || member_loc
->form_is_constant ());
16389 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16390 baton
->per_objfile
= per_objfile
;
16391 baton
->per_cu
= cu
->per_cu
;
16392 gdb_assert (baton
->per_cu
);
16394 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16396 if (member_loc
->form_is_constant ())
16398 offset
= member_loc
->constant_value (0);
16399 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16402 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16404 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16407 *ptr
++ = DW_OP_call4
;
16408 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16409 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16412 if (member_loc
->form_is_constant ())
16414 *ptr
++ = DW_OP_addr
;
16415 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16416 ptr
+= cu
->header
.addr_size
;
16420 /* We have to copy the data here, because DW_OP_call4 will only
16421 use a DW_AT_location attribute. */
16422 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16423 ptr
+= DW_BLOCK (member_loc
)->size
;
16426 *ptr
++ = DW_OP_plus
;
16427 gdb_assert (ptr
- baton
->data
== baton
->size
);
16429 SYMBOL_LOCATION_BATON (sym
) = baton
;
16430 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16433 /* Create appropriate locally-scoped variables for all the
16434 DW_TAG_common_block entries. Also create a struct common_block
16435 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16436 is used to separate the common blocks name namespace from regular
16440 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16442 struct attribute
*attr
;
16444 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16445 if (attr
!= nullptr)
16447 /* Support the .debug_loc offsets. */
16448 if (attr
->form_is_block ())
16452 else if (attr
->form_is_section_offset ())
16454 dwarf2_complex_location_expr_complaint ();
16459 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16460 "common block member");
16465 if (die
->child
!= NULL
)
16467 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16468 struct die_info
*child_die
;
16469 size_t n_entries
= 0, size
;
16470 struct common_block
*common_block
;
16471 struct symbol
*sym
;
16473 for (child_die
= die
->child
;
16474 child_die
&& child_die
->tag
;
16475 child_die
= child_die
->sibling
)
16478 size
= (sizeof (struct common_block
)
16479 + (n_entries
- 1) * sizeof (struct symbol
*));
16481 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16483 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16484 common_block
->n_entries
= 0;
16486 for (child_die
= die
->child
;
16487 child_die
&& child_die
->tag
;
16488 child_die
= child_die
->sibling
)
16490 /* Create the symbol in the DW_TAG_common_block block in the current
16492 sym
= new_symbol (child_die
, NULL
, cu
);
16495 struct attribute
*member_loc
;
16497 common_block
->contents
[common_block
->n_entries
++] = sym
;
16499 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16503 /* GDB has handled this for a long time, but it is
16504 not specified by DWARF. It seems to have been
16505 emitted by gfortran at least as recently as:
16506 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16507 complaint (_("Variable in common block has "
16508 "DW_AT_data_member_location "
16509 "- DIE at %s [in module %s]"),
16510 sect_offset_str (child_die
->sect_off
),
16511 objfile_name (objfile
));
16513 if (member_loc
->form_is_section_offset ())
16514 dwarf2_complex_location_expr_complaint ();
16515 else if (member_loc
->form_is_constant ()
16516 || member_loc
->form_is_block ())
16518 if (attr
!= nullptr)
16519 mark_common_block_symbol_computed (sym
, die
, attr
,
16523 dwarf2_complex_location_expr_complaint ();
16528 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16529 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16533 /* Create a type for a C++ namespace. */
16535 static struct type
*
16536 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16538 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16539 const char *previous_prefix
, *name
;
16543 /* For extensions, reuse the type of the original namespace. */
16544 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16546 struct die_info
*ext_die
;
16547 struct dwarf2_cu
*ext_cu
= cu
;
16549 ext_die
= dwarf2_extension (die
, &ext_cu
);
16550 type
= read_type_die (ext_die
, ext_cu
);
16552 /* EXT_CU may not be the same as CU.
16553 Ensure TYPE is recorded with CU in die_type_hash. */
16554 return set_die_type (die
, type
, cu
);
16557 name
= namespace_name (die
, &is_anonymous
, cu
);
16559 /* Now build the name of the current namespace. */
16561 previous_prefix
= determine_prefix (die
, cu
);
16562 if (previous_prefix
[0] != '\0')
16563 name
= typename_concat (&objfile
->objfile_obstack
,
16564 previous_prefix
, name
, 0, cu
);
16566 /* Create the type. */
16567 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16569 return set_die_type (die
, type
, cu
);
16572 /* Read a namespace scope. */
16575 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16577 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16580 /* Add a symbol associated to this if we haven't seen the namespace
16581 before. Also, add a using directive if it's an anonymous
16584 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16588 type
= read_type_die (die
, cu
);
16589 new_symbol (die
, type
, cu
);
16591 namespace_name (die
, &is_anonymous
, cu
);
16594 const char *previous_prefix
= determine_prefix (die
, cu
);
16596 std::vector
<const char *> excludes
;
16597 add_using_directive (using_directives (cu
),
16598 previous_prefix
, type
->name (), NULL
,
16599 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16603 if (die
->child
!= NULL
)
16605 struct die_info
*child_die
= die
->child
;
16607 while (child_die
&& child_die
->tag
)
16609 process_die (child_die
, cu
);
16610 child_die
= child_die
->sibling
;
16615 /* Read a Fortran module as type. This DIE can be only a declaration used for
16616 imported module. Still we need that type as local Fortran "use ... only"
16617 declaration imports depend on the created type in determine_prefix. */
16619 static struct type
*
16620 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16622 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16623 const char *module_name
;
16626 module_name
= dwarf2_name (die
, cu
);
16627 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16629 return set_die_type (die
, type
, cu
);
16632 /* Read a Fortran module. */
16635 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16637 struct die_info
*child_die
= die
->child
;
16640 type
= read_type_die (die
, cu
);
16641 new_symbol (die
, type
, cu
);
16643 while (child_die
&& child_die
->tag
)
16645 process_die (child_die
, cu
);
16646 child_die
= child_die
->sibling
;
16650 /* Return the name of the namespace represented by DIE. Set
16651 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16654 static const char *
16655 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16657 struct die_info
*current_die
;
16658 const char *name
= NULL
;
16660 /* Loop through the extensions until we find a name. */
16662 for (current_die
= die
;
16663 current_die
!= NULL
;
16664 current_die
= dwarf2_extension (die
, &cu
))
16666 /* We don't use dwarf2_name here so that we can detect the absence
16667 of a name -> anonymous namespace. */
16668 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16674 /* Is it an anonymous namespace? */
16676 *is_anonymous
= (name
== NULL
);
16678 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16683 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16684 the user defined type vector. */
16686 static struct type
*
16687 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16689 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16690 struct comp_unit_head
*cu_header
= &cu
->header
;
16692 struct attribute
*attr_byte_size
;
16693 struct attribute
*attr_address_class
;
16694 int byte_size
, addr_class
;
16695 struct type
*target_type
;
16697 target_type
= die_type (die
, cu
);
16699 /* The die_type call above may have already set the type for this DIE. */
16700 type
= get_die_type (die
, cu
);
16704 type
= lookup_pointer_type (target_type
);
16706 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16707 if (attr_byte_size
)
16708 byte_size
= DW_UNSND (attr_byte_size
);
16710 byte_size
= cu_header
->addr_size
;
16712 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16713 if (attr_address_class
)
16714 addr_class
= DW_UNSND (attr_address_class
);
16716 addr_class
= DW_ADDR_none
;
16718 ULONGEST alignment
= get_alignment (cu
, die
);
16720 /* If the pointer size, alignment, or address class is different
16721 than the default, create a type variant marked as such and set
16722 the length accordingly. */
16723 if (TYPE_LENGTH (type
) != byte_size
16724 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16725 && alignment
!= TYPE_RAW_ALIGN (type
))
16726 || addr_class
!= DW_ADDR_none
)
16728 if (gdbarch_address_class_type_flags_p (gdbarch
))
16732 type_flags
= gdbarch_address_class_type_flags
16733 (gdbarch
, byte_size
, addr_class
);
16734 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16736 type
= make_type_with_address_space (type
, type_flags
);
16738 else if (TYPE_LENGTH (type
) != byte_size
)
16740 complaint (_("invalid pointer size %d"), byte_size
);
16742 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16744 complaint (_("Invalid DW_AT_alignment"
16745 " - DIE at %s [in module %s]"),
16746 sect_offset_str (die
->sect_off
),
16747 objfile_name (cu
->per_objfile
->objfile
));
16751 /* Should we also complain about unhandled address classes? */
16755 TYPE_LENGTH (type
) = byte_size
;
16756 set_type_align (type
, alignment
);
16757 return set_die_type (die
, type
, cu
);
16760 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16761 the user defined type vector. */
16763 static struct type
*
16764 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16767 struct type
*to_type
;
16768 struct type
*domain
;
16770 to_type
= die_type (die
, cu
);
16771 domain
= die_containing_type (die
, cu
);
16773 /* The calls above may have already set the type for this DIE. */
16774 type
= get_die_type (die
, cu
);
16778 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16779 type
= lookup_methodptr_type (to_type
);
16780 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16782 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16784 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16785 to_type
->fields (), to_type
->num_fields (),
16786 TYPE_VARARGS (to_type
));
16787 type
= lookup_methodptr_type (new_type
);
16790 type
= lookup_memberptr_type (to_type
, domain
);
16792 return set_die_type (die
, type
, cu
);
16795 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16796 the user defined type vector. */
16798 static struct type
*
16799 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16800 enum type_code refcode
)
16802 struct comp_unit_head
*cu_header
= &cu
->header
;
16803 struct type
*type
, *target_type
;
16804 struct attribute
*attr
;
16806 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16808 target_type
= die_type (die
, cu
);
16810 /* The die_type call above may have already set the type for this DIE. */
16811 type
= get_die_type (die
, cu
);
16815 type
= lookup_reference_type (target_type
, refcode
);
16816 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16817 if (attr
!= nullptr)
16819 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16823 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16825 maybe_set_alignment (cu
, die
, type
);
16826 return set_die_type (die
, type
, cu
);
16829 /* Add the given cv-qualifiers to the element type of the array. GCC
16830 outputs DWARF type qualifiers that apply to an array, not the
16831 element type. But GDB relies on the array element type to carry
16832 the cv-qualifiers. This mimics section 6.7.3 of the C99
16835 static struct type
*
16836 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16837 struct type
*base_type
, int cnst
, int voltl
)
16839 struct type
*el_type
, *inner_array
;
16841 base_type
= copy_type (base_type
);
16842 inner_array
= base_type
;
16844 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16846 TYPE_TARGET_TYPE (inner_array
) =
16847 copy_type (TYPE_TARGET_TYPE (inner_array
));
16848 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16851 el_type
= TYPE_TARGET_TYPE (inner_array
);
16852 cnst
|= TYPE_CONST (el_type
);
16853 voltl
|= TYPE_VOLATILE (el_type
);
16854 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16856 return set_die_type (die
, base_type
, cu
);
16859 static struct type
*
16860 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16862 struct type
*base_type
, *cv_type
;
16864 base_type
= die_type (die
, cu
);
16866 /* The die_type call above may have already set the type for this DIE. */
16867 cv_type
= get_die_type (die
, cu
);
16871 /* In case the const qualifier is applied to an array type, the element type
16872 is so qualified, not the array type (section 6.7.3 of C99). */
16873 if (base_type
->code () == TYPE_CODE_ARRAY
)
16874 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16876 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16877 return set_die_type (die
, cv_type
, cu
);
16880 static struct type
*
16881 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16883 struct type
*base_type
, *cv_type
;
16885 base_type
= die_type (die
, cu
);
16887 /* The die_type call above may have already set the type for this DIE. */
16888 cv_type
= get_die_type (die
, cu
);
16892 /* In case the volatile qualifier is applied to an array type, the
16893 element type is so qualified, not the array type (section 6.7.3
16895 if (base_type
->code () == TYPE_CODE_ARRAY
)
16896 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16898 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16899 return set_die_type (die
, cv_type
, cu
);
16902 /* Handle DW_TAG_restrict_type. */
16904 static struct type
*
16905 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16907 struct type
*base_type
, *cv_type
;
16909 base_type
= die_type (die
, cu
);
16911 /* The die_type call above may have already set the type for this DIE. */
16912 cv_type
= get_die_type (die
, cu
);
16916 cv_type
= make_restrict_type (base_type
);
16917 return set_die_type (die
, cv_type
, cu
);
16920 /* Handle DW_TAG_atomic_type. */
16922 static struct type
*
16923 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16925 struct type
*base_type
, *cv_type
;
16927 base_type
= die_type (die
, cu
);
16929 /* The die_type call above may have already set the type for this DIE. */
16930 cv_type
= get_die_type (die
, cu
);
16934 cv_type
= make_atomic_type (base_type
);
16935 return set_die_type (die
, cv_type
, cu
);
16938 /* Extract all information from a DW_TAG_string_type DIE and add to
16939 the user defined type vector. It isn't really a user defined type,
16940 but it behaves like one, with other DIE's using an AT_user_def_type
16941 attribute to reference it. */
16943 static struct type
*
16944 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16946 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16947 struct gdbarch
*gdbarch
= objfile
->arch ();
16948 struct type
*type
, *range_type
, *index_type
, *char_type
;
16949 struct attribute
*attr
;
16950 struct dynamic_prop prop
;
16951 bool length_is_constant
= true;
16954 /* There are a couple of places where bit sizes might be made use of
16955 when parsing a DW_TAG_string_type, however, no producer that we know
16956 of make use of these. Handling bit sizes that are a multiple of the
16957 byte size is easy enough, but what about other bit sizes? Lets deal
16958 with that problem when we have to. Warn about these attributes being
16959 unsupported, then parse the type and ignore them like we always
16961 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16962 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16964 static bool warning_printed
= false;
16965 if (!warning_printed
)
16967 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16968 "currently supported on DW_TAG_string_type."));
16969 warning_printed
= true;
16973 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16974 if (attr
!= nullptr && !attr
->form_is_constant ())
16976 /* The string length describes the location at which the length of
16977 the string can be found. The size of the length field can be
16978 specified with one of the attributes below. */
16979 struct type
*prop_type
;
16980 struct attribute
*len
16981 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16982 if (len
== nullptr)
16983 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16984 if (len
!= nullptr && len
->form_is_constant ())
16986 /* Pass 0 as the default as we know this attribute is constant
16987 and the default value will not be returned. */
16988 LONGEST sz
= len
->constant_value (0);
16989 prop_type
= cu
->per_cu
->int_type (sz
, true);
16993 /* If the size is not specified then we assume it is the size of
16994 an address on this target. */
16995 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16998 /* Convert the attribute into a dynamic property. */
16999 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17002 length_is_constant
= false;
17004 else if (attr
!= nullptr)
17006 /* This DW_AT_string_length just contains the length with no
17007 indirection. There's no need to create a dynamic property in this
17008 case. Pass 0 for the default value as we know it will not be
17009 returned in this case. */
17010 length
= attr
->constant_value (0);
17012 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17014 /* We don't currently support non-constant byte sizes for strings. */
17015 length
= attr
->constant_value (1);
17019 /* Use 1 as a fallback length if we have nothing else. */
17023 index_type
= objfile_type (objfile
)->builtin_int
;
17024 if (length_is_constant
)
17025 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17028 struct dynamic_prop low_bound
;
17030 low_bound
.kind
= PROP_CONST
;
17031 low_bound
.data
.const_val
= 1;
17032 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17034 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17035 type
= create_string_type (NULL
, char_type
, range_type
);
17037 return set_die_type (die
, type
, cu
);
17040 /* Assuming that DIE corresponds to a function, returns nonzero
17041 if the function is prototyped. */
17044 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17046 struct attribute
*attr
;
17048 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17049 if (attr
&& (DW_UNSND (attr
) != 0))
17052 /* The DWARF standard implies that the DW_AT_prototyped attribute
17053 is only meaningful for C, but the concept also extends to other
17054 languages that allow unprototyped functions (Eg: Objective C).
17055 For all other languages, assume that functions are always
17057 if (cu
->language
!= language_c
17058 && cu
->language
!= language_objc
17059 && cu
->language
!= language_opencl
)
17062 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17063 prototyped and unprototyped functions; default to prototyped,
17064 since that is more common in modern code (and RealView warns
17065 about unprototyped functions). */
17066 if (producer_is_realview (cu
->producer
))
17072 /* Handle DIES due to C code like:
17076 int (*funcp)(int a, long l);
17080 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17082 static struct type
*
17083 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17085 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17086 struct type
*type
; /* Type that this function returns. */
17087 struct type
*ftype
; /* Function that returns above type. */
17088 struct attribute
*attr
;
17090 type
= die_type (die
, cu
);
17092 /* The die_type call above may have already set the type for this DIE. */
17093 ftype
= get_die_type (die
, cu
);
17097 ftype
= lookup_function_type (type
);
17099 if (prototyped_function_p (die
, cu
))
17100 TYPE_PROTOTYPED (ftype
) = 1;
17102 /* Store the calling convention in the type if it's available in
17103 the subroutine die. Otherwise set the calling convention to
17104 the default value DW_CC_normal. */
17105 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17106 if (attr
!= nullptr
17107 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17108 TYPE_CALLING_CONVENTION (ftype
)
17109 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17110 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17111 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17113 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17115 /* Record whether the function returns normally to its caller or not
17116 if the DWARF producer set that information. */
17117 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17118 if (attr
&& (DW_UNSND (attr
) != 0))
17119 TYPE_NO_RETURN (ftype
) = 1;
17121 /* We need to add the subroutine type to the die immediately so
17122 we don't infinitely recurse when dealing with parameters
17123 declared as the same subroutine type. */
17124 set_die_type (die
, ftype
, cu
);
17126 if (die
->child
!= NULL
)
17128 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17129 struct die_info
*child_die
;
17130 int nparams
, iparams
;
17132 /* Count the number of parameters.
17133 FIXME: GDB currently ignores vararg functions, but knows about
17134 vararg member functions. */
17136 child_die
= die
->child
;
17137 while (child_die
&& child_die
->tag
)
17139 if (child_die
->tag
== DW_TAG_formal_parameter
)
17141 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17142 TYPE_VARARGS (ftype
) = 1;
17143 child_die
= child_die
->sibling
;
17146 /* Allocate storage for parameters and fill them in. */
17147 ftype
->set_num_fields (nparams
);
17149 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17151 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17152 even if we error out during the parameters reading below. */
17153 for (iparams
= 0; iparams
< nparams
; iparams
++)
17154 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17157 child_die
= die
->child
;
17158 while (child_die
&& child_die
->tag
)
17160 if (child_die
->tag
== DW_TAG_formal_parameter
)
17162 struct type
*arg_type
;
17164 /* DWARF version 2 has no clean way to discern C++
17165 static and non-static member functions. G++ helps
17166 GDB by marking the first parameter for non-static
17167 member functions (which is the this pointer) as
17168 artificial. We pass this information to
17169 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17171 DWARF version 3 added DW_AT_object_pointer, which GCC
17172 4.5 does not yet generate. */
17173 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17174 if (attr
!= nullptr)
17175 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17177 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17178 arg_type
= die_type (child_die
, cu
);
17180 /* RealView does not mark THIS as const, which the testsuite
17181 expects. GCC marks THIS as const in method definitions,
17182 but not in the class specifications (GCC PR 43053). */
17183 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17184 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17187 struct dwarf2_cu
*arg_cu
= cu
;
17188 const char *name
= dwarf2_name (child_die
, cu
);
17190 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17191 if (attr
!= nullptr)
17193 /* If the compiler emits this, use it. */
17194 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17197 else if (name
&& strcmp (name
, "this") == 0)
17198 /* Function definitions will have the argument names. */
17200 else if (name
== NULL
&& iparams
== 0)
17201 /* Declarations may not have the names, so like
17202 elsewhere in GDB, assume an artificial first
17203 argument is "this". */
17207 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17211 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17214 child_die
= child_die
->sibling
;
17221 static struct type
*
17222 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17224 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17225 const char *name
= NULL
;
17226 struct type
*this_type
, *target_type
;
17228 name
= dwarf2_full_name (NULL
, die
, cu
);
17229 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17230 TYPE_TARGET_STUB (this_type
) = 1;
17231 set_die_type (die
, this_type
, cu
);
17232 target_type
= die_type (die
, cu
);
17233 if (target_type
!= this_type
)
17234 TYPE_TARGET_TYPE (this_type
) = target_type
;
17237 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17238 spec and cause infinite loops in GDB. */
17239 complaint (_("Self-referential DW_TAG_typedef "
17240 "- DIE at %s [in module %s]"),
17241 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17242 TYPE_TARGET_TYPE (this_type
) = NULL
;
17246 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17247 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17248 Handle these by just returning the target type, rather than
17249 constructing an anonymous typedef type and trying to handle this
17251 set_die_type (die
, target_type
, cu
);
17252 return target_type
;
17257 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17258 (which may be different from NAME) to the architecture back-end to allow
17259 it to guess the correct format if necessary. */
17261 static struct type
*
17262 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17263 const char *name_hint
, enum bfd_endian byte_order
)
17265 struct gdbarch
*gdbarch
= objfile
->arch ();
17266 const struct floatformat
**format
;
17269 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17271 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17273 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17278 /* Allocate an integer type of size BITS and name NAME. */
17280 static struct type
*
17281 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17282 int bits
, int unsigned_p
, const char *name
)
17286 /* Versions of Intel's C Compiler generate an integer type called "void"
17287 instead of using DW_TAG_unspecified_type. This has been seen on
17288 at least versions 14, 17, and 18. */
17289 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17290 && strcmp (name
, "void") == 0)
17291 type
= objfile_type (objfile
)->builtin_void
;
17293 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17298 /* Initialise and return a floating point type of size BITS suitable for
17299 use as a component of a complex number. The NAME_HINT is passed through
17300 when initialising the floating point type and is the name of the complex
17303 As DWARF doesn't currently provide an explicit name for the components
17304 of a complex number, but it can be helpful to have these components
17305 named, we try to select a suitable name based on the size of the
17307 static struct type
*
17308 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17309 struct objfile
*objfile
,
17310 int bits
, const char *name_hint
,
17311 enum bfd_endian byte_order
)
17313 gdbarch
*gdbarch
= objfile
->arch ();
17314 struct type
*tt
= nullptr;
17316 /* Try to find a suitable floating point builtin type of size BITS.
17317 We're going to use the name of this type as the name for the complex
17318 target type that we are about to create. */
17319 switch (cu
->language
)
17321 case language_fortran
:
17325 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17328 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17330 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17332 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17340 tt
= builtin_type (gdbarch
)->builtin_float
;
17343 tt
= builtin_type (gdbarch
)->builtin_double
;
17345 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17347 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17353 /* If the type we found doesn't match the size we were looking for, then
17354 pretend we didn't find a type at all, the complex target type we
17355 create will then be nameless. */
17356 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17359 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17360 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17363 /* Find a representation of a given base type and install
17364 it in the TYPE field of the die. */
17366 static struct type
*
17367 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17369 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17371 struct attribute
*attr
;
17372 int encoding
= 0, bits
= 0;
17376 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17377 if (attr
!= nullptr)
17378 encoding
= DW_UNSND (attr
);
17379 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17380 if (attr
!= nullptr)
17381 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17382 name
= dwarf2_name (die
, cu
);
17384 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17386 arch
= objfile
->arch ();
17387 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17389 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17392 int endianity
= DW_UNSND (attr
);
17397 byte_order
= BFD_ENDIAN_BIG
;
17399 case DW_END_little
:
17400 byte_order
= BFD_ENDIAN_LITTLE
;
17403 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17410 case DW_ATE_address
:
17411 /* Turn DW_ATE_address into a void * pointer. */
17412 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17413 type
= init_pointer_type (objfile
, bits
, name
, type
);
17415 case DW_ATE_boolean
:
17416 type
= init_boolean_type (objfile
, bits
, 1, name
);
17418 case DW_ATE_complex_float
:
17419 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17421 if (type
->code () == TYPE_CODE_ERROR
)
17423 if (name
== nullptr)
17425 struct obstack
*obstack
17426 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17427 name
= obconcat (obstack
, "_Complex ", type
->name (),
17430 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17433 type
= init_complex_type (name
, type
);
17435 case DW_ATE_decimal_float
:
17436 type
= init_decfloat_type (objfile
, bits
, name
);
17439 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17441 case DW_ATE_signed
:
17442 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17444 case DW_ATE_unsigned
:
17445 if (cu
->language
== language_fortran
17447 && startswith (name
, "character("))
17448 type
= init_character_type (objfile
, bits
, 1, name
);
17450 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17452 case DW_ATE_signed_char
:
17453 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17454 || cu
->language
== language_pascal
17455 || cu
->language
== language_fortran
)
17456 type
= init_character_type (objfile
, bits
, 0, name
);
17458 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17460 case DW_ATE_unsigned_char
:
17461 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17462 || cu
->language
== language_pascal
17463 || cu
->language
== language_fortran
17464 || cu
->language
== language_rust
)
17465 type
= init_character_type (objfile
, bits
, 1, name
);
17467 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17472 type
= builtin_type (arch
)->builtin_char16
;
17473 else if (bits
== 32)
17474 type
= builtin_type (arch
)->builtin_char32
;
17477 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17479 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17481 return set_die_type (die
, type
, cu
);
17486 complaint (_("unsupported DW_AT_encoding: '%s'"),
17487 dwarf_type_encoding_name (encoding
));
17488 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17492 if (name
&& strcmp (name
, "char") == 0)
17493 TYPE_NOSIGN (type
) = 1;
17495 maybe_set_alignment (cu
, die
, type
);
17497 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17499 return set_die_type (die
, type
, cu
);
17502 /* Parse dwarf attribute if it's a block, reference or constant and put the
17503 resulting value of the attribute into struct bound_prop.
17504 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17507 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17508 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17509 struct type
*default_type
)
17511 struct dwarf2_property_baton
*baton
;
17512 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17513 struct objfile
*objfile
= per_objfile
->objfile
;
17514 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17516 gdb_assert (default_type
!= NULL
);
17518 if (attr
== NULL
|| prop
== NULL
)
17521 if (attr
->form_is_block ())
17523 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17524 baton
->property_type
= default_type
;
17525 baton
->locexpr
.per_cu
= cu
->per_cu
;
17526 baton
->locexpr
.per_objfile
= per_objfile
;
17527 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17528 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17529 switch (attr
->name
)
17531 case DW_AT_string_length
:
17532 baton
->locexpr
.is_reference
= true;
17535 baton
->locexpr
.is_reference
= false;
17538 prop
->data
.baton
= baton
;
17539 prop
->kind
= PROP_LOCEXPR
;
17540 gdb_assert (prop
->data
.baton
!= NULL
);
17542 else if (attr
->form_is_ref ())
17544 struct dwarf2_cu
*target_cu
= cu
;
17545 struct die_info
*target_die
;
17546 struct attribute
*target_attr
;
17548 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17549 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17550 if (target_attr
== NULL
)
17551 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17553 if (target_attr
== NULL
)
17556 switch (target_attr
->name
)
17558 case DW_AT_location
:
17559 if (target_attr
->form_is_section_offset ())
17561 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17562 baton
->property_type
= die_type (target_die
, target_cu
);
17563 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17564 prop
->data
.baton
= baton
;
17565 prop
->kind
= PROP_LOCLIST
;
17566 gdb_assert (prop
->data
.baton
!= NULL
);
17568 else if (target_attr
->form_is_block ())
17570 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17571 baton
->property_type
= die_type (target_die
, target_cu
);
17572 baton
->locexpr
.per_cu
= cu
->per_cu
;
17573 baton
->locexpr
.per_objfile
= per_objfile
;
17574 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17575 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17576 baton
->locexpr
.is_reference
= true;
17577 prop
->data
.baton
= baton
;
17578 prop
->kind
= PROP_LOCEXPR
;
17579 gdb_assert (prop
->data
.baton
!= NULL
);
17583 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17584 "dynamic property");
17588 case DW_AT_data_member_location
:
17592 if (!handle_data_member_location (target_die
, target_cu
,
17596 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17597 baton
->property_type
= read_type_die (target_die
->parent
,
17599 baton
->offset_info
.offset
= offset
;
17600 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17601 prop
->data
.baton
= baton
;
17602 prop
->kind
= PROP_ADDR_OFFSET
;
17607 else if (attr
->form_is_constant ())
17609 prop
->data
.const_val
= attr
->constant_value (0);
17610 prop
->kind
= PROP_CONST
;
17614 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17615 dwarf2_name (die
, cu
));
17625 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17627 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17628 struct type
*int_type
;
17630 /* Helper macro to examine the various builtin types. */
17631 #define TRY_TYPE(F) \
17632 int_type = (unsigned_p \
17633 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17634 : objfile_type (objfile)->builtin_ ## F); \
17635 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17642 TRY_TYPE (long_long
);
17646 gdb_assert_not_reached ("unable to find suitable integer type");
17652 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17654 int addr_size
= this->addr_size ();
17655 return int_type (addr_size
, unsigned_p
);
17658 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17659 present (which is valid) then compute the default type based on the
17660 compilation units address size. */
17662 static struct type
*
17663 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17665 struct type
*index_type
= die_type (die
, cu
);
17667 /* Dwarf-2 specifications explicitly allows to create subrange types
17668 without specifying a base type.
17669 In that case, the base type must be set to the type of
17670 the lower bound, upper bound or count, in that order, if any of these
17671 three attributes references an object that has a type.
17672 If no base type is found, the Dwarf-2 specifications say that
17673 a signed integer type of size equal to the size of an address should
17675 For the following C code: `extern char gdb_int [];'
17676 GCC produces an empty range DIE.
17677 FIXME: muller/2010-05-28: Possible references to object for low bound,
17678 high bound or count are not yet handled by this code. */
17679 if (index_type
->code () == TYPE_CODE_VOID
)
17680 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17685 /* Read the given DW_AT_subrange DIE. */
17687 static struct type
*
17688 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17690 struct type
*base_type
, *orig_base_type
;
17691 struct type
*range_type
;
17692 struct attribute
*attr
;
17693 struct dynamic_prop low
, high
;
17694 int low_default_is_valid
;
17695 int high_bound_is_count
= 0;
17697 ULONGEST negative_mask
;
17699 orig_base_type
= read_subrange_index_type (die
, cu
);
17701 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17702 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17703 creating the range type, but we use the result of check_typedef
17704 when examining properties of the type. */
17705 base_type
= check_typedef (orig_base_type
);
17707 /* The die_type call above may have already set the type for this DIE. */
17708 range_type
= get_die_type (die
, cu
);
17712 low
.kind
= PROP_CONST
;
17713 high
.kind
= PROP_CONST
;
17714 high
.data
.const_val
= 0;
17716 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17717 omitting DW_AT_lower_bound. */
17718 switch (cu
->language
)
17721 case language_cplus
:
17722 low
.data
.const_val
= 0;
17723 low_default_is_valid
= 1;
17725 case language_fortran
:
17726 low
.data
.const_val
= 1;
17727 low_default_is_valid
= 1;
17730 case language_objc
:
17731 case language_rust
:
17732 low
.data
.const_val
= 0;
17733 low_default_is_valid
= (cu
->header
.version
>= 4);
17737 case language_pascal
:
17738 low
.data
.const_val
= 1;
17739 low_default_is_valid
= (cu
->header
.version
>= 4);
17742 low
.data
.const_val
= 0;
17743 low_default_is_valid
= 0;
17747 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17748 if (attr
!= nullptr)
17749 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17750 else if (!low_default_is_valid
)
17751 complaint (_("Missing DW_AT_lower_bound "
17752 "- DIE at %s [in module %s]"),
17753 sect_offset_str (die
->sect_off
),
17754 objfile_name (cu
->per_objfile
->objfile
));
17756 struct attribute
*attr_ub
, *attr_count
;
17757 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17758 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17760 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17761 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17763 /* If bounds are constant do the final calculation here. */
17764 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17765 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17767 high_bound_is_count
= 1;
17771 if (attr_ub
!= NULL
)
17772 complaint (_("Unresolved DW_AT_upper_bound "
17773 "- DIE at %s [in module %s]"),
17774 sect_offset_str (die
->sect_off
),
17775 objfile_name (cu
->per_objfile
->objfile
));
17776 if (attr_count
!= NULL
)
17777 complaint (_("Unresolved DW_AT_count "
17778 "- DIE at %s [in module %s]"),
17779 sect_offset_str (die
->sect_off
),
17780 objfile_name (cu
->per_objfile
->objfile
));
17785 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17786 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17787 bias
= bias_attr
->constant_value (0);
17789 /* Normally, the DWARF producers are expected to use a signed
17790 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17791 But this is unfortunately not always the case, as witnessed
17792 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17793 is used instead. To work around that ambiguity, we treat
17794 the bounds as signed, and thus sign-extend their values, when
17795 the base type is signed. */
17797 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17798 if (low
.kind
== PROP_CONST
17799 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17800 low
.data
.const_val
|= negative_mask
;
17801 if (high
.kind
== PROP_CONST
17802 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17803 high
.data
.const_val
|= negative_mask
;
17805 /* Check for bit and byte strides. */
17806 struct dynamic_prop byte_stride_prop
;
17807 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17808 if (attr_byte_stride
!= nullptr)
17810 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17811 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17815 struct dynamic_prop bit_stride_prop
;
17816 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17817 if (attr_bit_stride
!= nullptr)
17819 /* It only makes sense to have either a bit or byte stride. */
17820 if (attr_byte_stride
!= nullptr)
17822 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17823 "- DIE at %s [in module %s]"),
17824 sect_offset_str (die
->sect_off
),
17825 objfile_name (cu
->per_objfile
->objfile
));
17826 attr_bit_stride
= nullptr;
17830 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17831 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17836 if (attr_byte_stride
!= nullptr
17837 || attr_bit_stride
!= nullptr)
17839 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17840 struct dynamic_prop
*stride
17841 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17844 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17845 &high
, bias
, stride
, byte_stride_p
);
17848 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17850 if (high_bound_is_count
)
17851 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17853 /* Ada expects an empty array on no boundary attributes. */
17854 if (attr
== NULL
&& cu
->language
!= language_ada
)
17855 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17857 name
= dwarf2_name (die
, cu
);
17859 range_type
->set_name (name
);
17861 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17862 if (attr
!= nullptr)
17863 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17865 maybe_set_alignment (cu
, die
, range_type
);
17867 set_die_type (die
, range_type
, cu
);
17869 /* set_die_type should be already done. */
17870 set_descriptive_type (range_type
, die
, cu
);
17875 static struct type
*
17876 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17880 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17881 type
->set_name (dwarf2_name (die
, cu
));
17883 /* In Ada, an unspecified type is typically used when the description
17884 of the type is deferred to a different unit. When encountering
17885 such a type, we treat it as a stub, and try to resolve it later on,
17887 if (cu
->language
== language_ada
)
17888 TYPE_STUB (type
) = 1;
17890 return set_die_type (die
, type
, cu
);
17893 /* Read a single die and all its descendents. Set the die's sibling
17894 field to NULL; set other fields in the die correctly, and set all
17895 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17896 location of the info_ptr after reading all of those dies. PARENT
17897 is the parent of the die in question. */
17899 static struct die_info
*
17900 read_die_and_children (const struct die_reader_specs
*reader
,
17901 const gdb_byte
*info_ptr
,
17902 const gdb_byte
**new_info_ptr
,
17903 struct die_info
*parent
)
17905 struct die_info
*die
;
17906 const gdb_byte
*cur_ptr
;
17908 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17911 *new_info_ptr
= cur_ptr
;
17914 store_in_ref_table (die
, reader
->cu
);
17916 if (die
->has_children
)
17917 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17921 *new_info_ptr
= cur_ptr
;
17924 die
->sibling
= NULL
;
17925 die
->parent
= parent
;
17929 /* Read a die, all of its descendents, and all of its siblings; set
17930 all of the fields of all of the dies correctly. Arguments are as
17931 in read_die_and_children. */
17933 static struct die_info
*
17934 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17935 const gdb_byte
*info_ptr
,
17936 const gdb_byte
**new_info_ptr
,
17937 struct die_info
*parent
)
17939 struct die_info
*first_die
, *last_sibling
;
17940 const gdb_byte
*cur_ptr
;
17942 cur_ptr
= info_ptr
;
17943 first_die
= last_sibling
= NULL
;
17947 struct die_info
*die
17948 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17952 *new_info_ptr
= cur_ptr
;
17959 last_sibling
->sibling
= die
;
17961 last_sibling
= die
;
17965 /* Read a die, all of its descendents, and all of its siblings; set
17966 all of the fields of all of the dies correctly. Arguments are as
17967 in read_die_and_children.
17968 This the main entry point for reading a DIE and all its children. */
17970 static struct die_info
*
17971 read_die_and_siblings (const struct die_reader_specs
*reader
,
17972 const gdb_byte
*info_ptr
,
17973 const gdb_byte
**new_info_ptr
,
17974 struct die_info
*parent
)
17976 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17977 new_info_ptr
, parent
);
17979 if (dwarf_die_debug
)
17981 fprintf_unfiltered (gdb_stdlog
,
17982 "Read die from %s@0x%x of %s:\n",
17983 reader
->die_section
->get_name (),
17984 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17985 bfd_get_filename (reader
->abfd
));
17986 dump_die (die
, dwarf_die_debug
);
17992 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17994 The caller is responsible for filling in the extra attributes
17995 and updating (*DIEP)->num_attrs.
17996 Set DIEP to point to a newly allocated die with its information,
17997 except for its child, sibling, and parent fields. */
17999 static const gdb_byte
*
18000 read_full_die_1 (const struct die_reader_specs
*reader
,
18001 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18002 int num_extra_attrs
)
18004 unsigned int abbrev_number
, bytes_read
, i
;
18005 struct abbrev_info
*abbrev
;
18006 struct die_info
*die
;
18007 struct dwarf2_cu
*cu
= reader
->cu
;
18008 bfd
*abfd
= reader
->abfd
;
18010 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18011 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18012 info_ptr
+= bytes_read
;
18013 if (!abbrev_number
)
18019 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18021 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18023 bfd_get_filename (abfd
));
18025 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18026 die
->sect_off
= sect_off
;
18027 die
->tag
= abbrev
->tag
;
18028 die
->abbrev
= abbrev_number
;
18029 die
->has_children
= abbrev
->has_children
;
18031 /* Make the result usable.
18032 The caller needs to update num_attrs after adding the extra
18034 die
->num_attrs
= abbrev
->num_attrs
;
18036 std::vector
<int> indexes_that_need_reprocess
;
18037 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18039 bool need_reprocess
;
18041 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18042 info_ptr
, &need_reprocess
);
18043 if (need_reprocess
)
18044 indexes_that_need_reprocess
.push_back (i
);
18047 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18048 if (attr
!= nullptr)
18049 cu
->str_offsets_base
= DW_UNSND (attr
);
18051 attr
= die
->attr (DW_AT_loclists_base
);
18052 if (attr
!= nullptr)
18053 cu
->loclist_base
= DW_UNSND (attr
);
18055 auto maybe_addr_base
= die
->addr_base ();
18056 if (maybe_addr_base
.has_value ())
18057 cu
->addr_base
= *maybe_addr_base
;
18058 for (int index
: indexes_that_need_reprocess
)
18059 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18064 /* Read a die and all its attributes.
18065 Set DIEP to point to a newly allocated die with its information,
18066 except for its child, sibling, and parent fields. */
18068 static const gdb_byte
*
18069 read_full_die (const struct die_reader_specs
*reader
,
18070 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18072 const gdb_byte
*result
;
18074 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18076 if (dwarf_die_debug
)
18078 fprintf_unfiltered (gdb_stdlog
,
18079 "Read die from %s@0x%x of %s:\n",
18080 reader
->die_section
->get_name (),
18081 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18082 bfd_get_filename (reader
->abfd
));
18083 dump_die (*diep
, dwarf_die_debug
);
18090 /* Returns nonzero if TAG represents a type that we might generate a partial
18094 is_type_tag_for_partial (int tag
)
18099 /* Some types that would be reasonable to generate partial symbols for,
18100 that we don't at present. */
18101 case DW_TAG_array_type
:
18102 case DW_TAG_file_type
:
18103 case DW_TAG_ptr_to_member_type
:
18104 case DW_TAG_set_type
:
18105 case DW_TAG_string_type
:
18106 case DW_TAG_subroutine_type
:
18108 case DW_TAG_base_type
:
18109 case DW_TAG_class_type
:
18110 case DW_TAG_interface_type
:
18111 case DW_TAG_enumeration_type
:
18112 case DW_TAG_structure_type
:
18113 case DW_TAG_subrange_type
:
18114 case DW_TAG_typedef
:
18115 case DW_TAG_union_type
:
18122 /* Load all DIEs that are interesting for partial symbols into memory. */
18124 static struct partial_die_info
*
18125 load_partial_dies (const struct die_reader_specs
*reader
,
18126 const gdb_byte
*info_ptr
, int building_psymtab
)
18128 struct dwarf2_cu
*cu
= reader
->cu
;
18129 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18130 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18131 unsigned int bytes_read
;
18132 unsigned int load_all
= 0;
18133 int nesting_level
= 1;
18138 gdb_assert (cu
->per_cu
!= NULL
);
18139 if (cu
->per_cu
->load_all_dies
)
18143 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18147 &cu
->comp_unit_obstack
,
18148 hashtab_obstack_allocate
,
18149 dummy_obstack_deallocate
);
18153 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18155 /* A NULL abbrev means the end of a series of children. */
18156 if (abbrev
== NULL
)
18158 if (--nesting_level
== 0)
18161 info_ptr
+= bytes_read
;
18162 last_die
= parent_die
;
18163 parent_die
= parent_die
->die_parent
;
18167 /* Check for template arguments. We never save these; if
18168 they're seen, we just mark the parent, and go on our way. */
18169 if (parent_die
!= NULL
18170 && cu
->language
== language_cplus
18171 && (abbrev
->tag
== DW_TAG_template_type_param
18172 || abbrev
->tag
== DW_TAG_template_value_param
))
18174 parent_die
->has_template_arguments
= 1;
18178 /* We don't need a partial DIE for the template argument. */
18179 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18184 /* We only recurse into c++ subprograms looking for template arguments.
18185 Skip their other children. */
18187 && cu
->language
== language_cplus
18188 && parent_die
!= NULL
18189 && parent_die
->tag
== DW_TAG_subprogram
)
18191 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18195 /* Check whether this DIE is interesting enough to save. Normally
18196 we would not be interested in members here, but there may be
18197 later variables referencing them via DW_AT_specification (for
18198 static members). */
18200 && !is_type_tag_for_partial (abbrev
->tag
)
18201 && abbrev
->tag
!= DW_TAG_constant
18202 && abbrev
->tag
!= DW_TAG_enumerator
18203 && abbrev
->tag
!= DW_TAG_subprogram
18204 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18205 && abbrev
->tag
!= DW_TAG_lexical_block
18206 && abbrev
->tag
!= DW_TAG_variable
18207 && abbrev
->tag
!= DW_TAG_namespace
18208 && abbrev
->tag
!= DW_TAG_module
18209 && abbrev
->tag
!= DW_TAG_member
18210 && abbrev
->tag
!= DW_TAG_imported_unit
18211 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18213 /* Otherwise we skip to the next sibling, if any. */
18214 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18218 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18221 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18223 /* This two-pass algorithm for processing partial symbols has a
18224 high cost in cache pressure. Thus, handle some simple cases
18225 here which cover the majority of C partial symbols. DIEs
18226 which neither have specification tags in them, nor could have
18227 specification tags elsewhere pointing at them, can simply be
18228 processed and discarded.
18230 This segment is also optional; scan_partial_symbols and
18231 add_partial_symbol will handle these DIEs if we chain
18232 them in normally. When compilers which do not emit large
18233 quantities of duplicate debug information are more common,
18234 this code can probably be removed. */
18236 /* Any complete simple types at the top level (pretty much all
18237 of them, for a language without namespaces), can be processed
18239 if (parent_die
== NULL
18240 && pdi
.has_specification
== 0
18241 && pdi
.is_declaration
== 0
18242 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18243 || pdi
.tag
== DW_TAG_base_type
18244 || pdi
.tag
== DW_TAG_subrange_type
))
18246 if (building_psymtab
&& pdi
.name
!= NULL
)
18247 add_psymbol_to_list (pdi
.name
, false,
18248 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18249 psymbol_placement::STATIC
,
18250 0, cu
->language
, objfile
);
18251 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18255 /* The exception for DW_TAG_typedef with has_children above is
18256 a workaround of GCC PR debug/47510. In the case of this complaint
18257 type_name_or_error will error on such types later.
18259 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18260 it could not find the child DIEs referenced later, this is checked
18261 above. In correct DWARF DW_TAG_typedef should have no children. */
18263 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18264 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18265 "- DIE at %s [in module %s]"),
18266 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18268 /* If we're at the second level, and we're an enumerator, and
18269 our parent has no specification (meaning possibly lives in a
18270 namespace elsewhere), then we can add the partial symbol now
18271 instead of queueing it. */
18272 if (pdi
.tag
== DW_TAG_enumerator
18273 && parent_die
!= NULL
18274 && parent_die
->die_parent
== NULL
18275 && parent_die
->tag
== DW_TAG_enumeration_type
18276 && parent_die
->has_specification
== 0)
18278 if (pdi
.name
== NULL
)
18279 complaint (_("malformed enumerator DIE ignored"));
18280 else if (building_psymtab
)
18281 add_psymbol_to_list (pdi
.name
, false,
18282 VAR_DOMAIN
, LOC_CONST
, -1,
18283 cu
->language
== language_cplus
18284 ? psymbol_placement::GLOBAL
18285 : psymbol_placement::STATIC
,
18286 0, cu
->language
, objfile
);
18288 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18292 struct partial_die_info
*part_die
18293 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18295 /* We'll save this DIE so link it in. */
18296 part_die
->die_parent
= parent_die
;
18297 part_die
->die_sibling
= NULL
;
18298 part_die
->die_child
= NULL
;
18300 if (last_die
&& last_die
== parent_die
)
18301 last_die
->die_child
= part_die
;
18303 last_die
->die_sibling
= part_die
;
18305 last_die
= part_die
;
18307 if (first_die
== NULL
)
18308 first_die
= part_die
;
18310 /* Maybe add the DIE to the hash table. Not all DIEs that we
18311 find interesting need to be in the hash table, because we
18312 also have the parent/sibling/child chains; only those that we
18313 might refer to by offset later during partial symbol reading.
18315 For now this means things that might have be the target of a
18316 DW_AT_specification, DW_AT_abstract_origin, or
18317 DW_AT_extension. DW_AT_extension will refer only to
18318 namespaces; DW_AT_abstract_origin refers to functions (and
18319 many things under the function DIE, but we do not recurse
18320 into function DIEs during partial symbol reading) and
18321 possibly variables as well; DW_AT_specification refers to
18322 declarations. Declarations ought to have the DW_AT_declaration
18323 flag. It happens that GCC forgets to put it in sometimes, but
18324 only for functions, not for types.
18326 Adding more things than necessary to the hash table is harmless
18327 except for the performance cost. Adding too few will result in
18328 wasted time in find_partial_die, when we reread the compilation
18329 unit with load_all_dies set. */
18332 || abbrev
->tag
== DW_TAG_constant
18333 || abbrev
->tag
== DW_TAG_subprogram
18334 || abbrev
->tag
== DW_TAG_variable
18335 || abbrev
->tag
== DW_TAG_namespace
18336 || part_die
->is_declaration
)
18340 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18341 to_underlying (part_die
->sect_off
),
18346 /* For some DIEs we want to follow their children (if any). For C
18347 we have no reason to follow the children of structures; for other
18348 languages we have to, so that we can get at method physnames
18349 to infer fully qualified class names, for DW_AT_specification,
18350 and for C++ template arguments. For C++, we also look one level
18351 inside functions to find template arguments (if the name of the
18352 function does not already contain the template arguments).
18354 For Ada and Fortran, we need to scan the children of subprograms
18355 and lexical blocks as well because these languages allow the
18356 definition of nested entities that could be interesting for the
18357 debugger, such as nested subprograms for instance. */
18358 if (last_die
->has_children
18360 || last_die
->tag
== DW_TAG_namespace
18361 || last_die
->tag
== DW_TAG_module
18362 || last_die
->tag
== DW_TAG_enumeration_type
18363 || (cu
->language
== language_cplus
18364 && last_die
->tag
== DW_TAG_subprogram
18365 && (last_die
->name
== NULL
18366 || strchr (last_die
->name
, '<') == NULL
))
18367 || (cu
->language
!= language_c
18368 && (last_die
->tag
== DW_TAG_class_type
18369 || last_die
->tag
== DW_TAG_interface_type
18370 || last_die
->tag
== DW_TAG_structure_type
18371 || last_die
->tag
== DW_TAG_union_type
))
18372 || ((cu
->language
== language_ada
18373 || cu
->language
== language_fortran
)
18374 && (last_die
->tag
== DW_TAG_subprogram
18375 || last_die
->tag
== DW_TAG_lexical_block
))))
18378 parent_die
= last_die
;
18382 /* Otherwise we skip to the next sibling, if any. */
18383 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18385 /* Back to the top, do it again. */
18389 partial_die_info::partial_die_info (sect_offset sect_off_
,
18390 struct abbrev_info
*abbrev
)
18391 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18395 /* Read a minimal amount of information into the minimal die structure.
18396 INFO_PTR should point just after the initial uleb128 of a DIE. */
18399 partial_die_info::read (const struct die_reader_specs
*reader
,
18400 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18402 struct dwarf2_cu
*cu
= reader
->cu
;
18403 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18405 int has_low_pc_attr
= 0;
18406 int has_high_pc_attr
= 0;
18407 int high_pc_relative
= 0;
18409 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18412 bool need_reprocess
;
18413 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18414 info_ptr
, &need_reprocess
);
18415 /* String and address offsets that need to do the reprocessing have
18416 already been read at this point, so there is no need to wait until
18417 the loop terminates to do the reprocessing. */
18418 if (need_reprocess
)
18419 read_attribute_reprocess (reader
, &attr
);
18420 /* Store the data if it is of an attribute we want to keep in a
18421 partial symbol table. */
18427 case DW_TAG_compile_unit
:
18428 case DW_TAG_partial_unit
:
18429 case DW_TAG_type_unit
:
18430 /* Compilation units have a DW_AT_name that is a filename, not
18431 a source language identifier. */
18432 case DW_TAG_enumeration_type
:
18433 case DW_TAG_enumerator
:
18434 /* These tags always have simple identifiers already; no need
18435 to canonicalize them. */
18436 name
= DW_STRING (&attr
);
18440 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18443 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18448 case DW_AT_linkage_name
:
18449 case DW_AT_MIPS_linkage_name
:
18450 /* Note that both forms of linkage name might appear. We
18451 assume they will be the same, and we only store the last
18453 linkage_name
= attr
.value_as_string ();
18454 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18455 See https://github.com/rust-lang/rust/issues/32925. */
18456 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18457 && strchr (linkage_name
, '{') != NULL
)
18458 linkage_name
= NULL
;
18461 has_low_pc_attr
= 1;
18462 lowpc
= attr
.value_as_address ();
18464 case DW_AT_high_pc
:
18465 has_high_pc_attr
= 1;
18466 highpc
= attr
.value_as_address ();
18467 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18468 high_pc_relative
= 1;
18470 case DW_AT_location
:
18471 /* Support the .debug_loc offsets. */
18472 if (attr
.form_is_block ())
18474 d
.locdesc
= DW_BLOCK (&attr
);
18476 else if (attr
.form_is_section_offset ())
18478 dwarf2_complex_location_expr_complaint ();
18482 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18483 "partial symbol information");
18486 case DW_AT_external
:
18487 is_external
= DW_UNSND (&attr
);
18489 case DW_AT_declaration
:
18490 is_declaration
= DW_UNSND (&attr
);
18495 case DW_AT_abstract_origin
:
18496 case DW_AT_specification
:
18497 case DW_AT_extension
:
18498 has_specification
= 1;
18499 spec_offset
= attr
.get_ref_die_offset ();
18500 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18501 || cu
->per_cu
->is_dwz
);
18503 case DW_AT_sibling
:
18504 /* Ignore absolute siblings, they might point outside of
18505 the current compile unit. */
18506 if (attr
.form
== DW_FORM_ref_addr
)
18507 complaint (_("ignoring absolute DW_AT_sibling"));
18510 const gdb_byte
*buffer
= reader
->buffer
;
18511 sect_offset off
= attr
.get_ref_die_offset ();
18512 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18514 if (sibling_ptr
< info_ptr
)
18515 complaint (_("DW_AT_sibling points backwards"));
18516 else if (sibling_ptr
> reader
->buffer_end
)
18517 reader
->die_section
->overflow_complaint ();
18519 sibling
= sibling_ptr
;
18522 case DW_AT_byte_size
:
18525 case DW_AT_const_value
:
18526 has_const_value
= 1;
18528 case DW_AT_calling_convention
:
18529 /* DWARF doesn't provide a way to identify a program's source-level
18530 entry point. DW_AT_calling_convention attributes are only meant
18531 to describe functions' calling conventions.
18533 However, because it's a necessary piece of information in
18534 Fortran, and before DWARF 4 DW_CC_program was the only
18535 piece of debugging information whose definition refers to
18536 a 'main program' at all, several compilers marked Fortran
18537 main programs with DW_CC_program --- even when those
18538 functions use the standard calling conventions.
18540 Although DWARF now specifies a way to provide this
18541 information, we support this practice for backward
18543 if (DW_UNSND (&attr
) == DW_CC_program
18544 && cu
->language
== language_fortran
)
18545 main_subprogram
= 1;
18548 if (DW_UNSND (&attr
) == DW_INL_inlined
18549 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18550 may_be_inlined
= 1;
18554 if (tag
== DW_TAG_imported_unit
)
18556 d
.sect_off
= attr
.get_ref_die_offset ();
18557 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18558 || cu
->per_cu
->is_dwz
);
18562 case DW_AT_main_subprogram
:
18563 main_subprogram
= DW_UNSND (&attr
);
18568 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18569 but that requires a full DIE, so instead we just
18571 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18572 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18573 + (need_ranges_base
18577 /* Value of the DW_AT_ranges attribute is the offset in the
18578 .debug_ranges section. */
18579 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18590 /* For Ada, if both the name and the linkage name appear, we prefer
18591 the latter. This lets "catch exception" work better, regardless
18592 of the order in which the name and linkage name were emitted.
18593 Really, though, this is just a workaround for the fact that gdb
18594 doesn't store both the name and the linkage name. */
18595 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18596 name
= linkage_name
;
18598 if (high_pc_relative
)
18601 if (has_low_pc_attr
&& has_high_pc_attr
)
18603 /* When using the GNU linker, .gnu.linkonce. sections are used to
18604 eliminate duplicate copies of functions and vtables and such.
18605 The linker will arbitrarily choose one and discard the others.
18606 The AT_*_pc values for such functions refer to local labels in
18607 these sections. If the section from that file was discarded, the
18608 labels are not in the output, so the relocs get a value of 0.
18609 If this is a discarded function, mark the pc bounds as invalid,
18610 so that GDB will ignore it. */
18611 if (lowpc
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
18613 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18614 struct gdbarch
*gdbarch
= objfile
->arch ();
18616 complaint (_("DW_AT_low_pc %s is zero "
18617 "for DIE at %s [in module %s]"),
18618 paddress (gdbarch
, lowpc
),
18619 sect_offset_str (sect_off
),
18620 objfile_name (objfile
));
18622 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18623 else if (lowpc
>= highpc
)
18625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18626 struct gdbarch
*gdbarch
= objfile
->arch ();
18628 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18629 "for DIE at %s [in module %s]"),
18630 paddress (gdbarch
, lowpc
),
18631 paddress (gdbarch
, highpc
),
18632 sect_offset_str (sect_off
),
18633 objfile_name (objfile
));
18642 /* Find a cached partial DIE at OFFSET in CU. */
18644 struct partial_die_info
*
18645 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18647 struct partial_die_info
*lookup_die
= NULL
;
18648 struct partial_die_info
part_die (sect_off
);
18650 lookup_die
= ((struct partial_die_info
*)
18651 htab_find_with_hash (partial_dies
, &part_die
,
18652 to_underlying (sect_off
)));
18657 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18658 except in the case of .debug_types DIEs which do not reference
18659 outside their CU (they do however referencing other types via
18660 DW_FORM_ref_sig8). */
18662 static const struct cu_partial_die_info
18663 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18665 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18666 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18667 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18668 struct partial_die_info
*pd
= NULL
;
18670 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18671 && cu
->header
.offset_in_cu_p (sect_off
))
18673 pd
= cu
->find_partial_die (sect_off
);
18676 /* We missed recording what we needed.
18677 Load all dies and try again. */
18678 per_cu
= cu
->per_cu
;
18682 /* TUs don't reference other CUs/TUs (except via type signatures). */
18683 if (cu
->per_cu
->is_debug_types
)
18685 error (_("Dwarf Error: Type Unit at offset %s contains"
18686 " external reference to offset %s [in module %s].\n"),
18687 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18688 bfd_get_filename (objfile
->obfd
));
18690 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18691 dwarf2_per_objfile
);
18693 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18694 load_partial_comp_unit (per_cu
, cu
->per_objfile
);
18696 per_cu
->cu
->last_used
= 0;
18697 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18700 /* If we didn't find it, and not all dies have been loaded,
18701 load them all and try again. */
18703 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18705 per_cu
->load_all_dies
= 1;
18707 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18708 THIS_CU->cu may already be in use. So we can't just free it and
18709 replace its DIEs with the ones we read in. Instead, we leave those
18710 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18711 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18713 load_partial_comp_unit (per_cu
, cu
->per_objfile
);
18715 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18719 internal_error (__FILE__
, __LINE__
,
18720 _("could not find partial DIE %s "
18721 "in cache [from module %s]\n"),
18722 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18723 return { per_cu
->cu
, pd
};
18726 /* See if we can figure out if the class lives in a namespace. We do
18727 this by looking for a member function; its demangled name will
18728 contain namespace info, if there is any. */
18731 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18732 struct dwarf2_cu
*cu
)
18734 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18735 what template types look like, because the demangler
18736 frequently doesn't give the same name as the debug info. We
18737 could fix this by only using the demangled name to get the
18738 prefix (but see comment in read_structure_type). */
18740 struct partial_die_info
*real_pdi
;
18741 struct partial_die_info
*child_pdi
;
18743 /* If this DIE (this DIE's specification, if any) has a parent, then
18744 we should not do this. We'll prepend the parent's fully qualified
18745 name when we create the partial symbol. */
18747 real_pdi
= struct_pdi
;
18748 while (real_pdi
->has_specification
)
18750 auto res
= find_partial_die (real_pdi
->spec_offset
,
18751 real_pdi
->spec_is_dwz
, cu
);
18752 real_pdi
= res
.pdi
;
18756 if (real_pdi
->die_parent
!= NULL
)
18759 for (child_pdi
= struct_pdi
->die_child
;
18761 child_pdi
= child_pdi
->die_sibling
)
18763 if (child_pdi
->tag
== DW_TAG_subprogram
18764 && child_pdi
->linkage_name
!= NULL
)
18766 gdb::unique_xmalloc_ptr
<char> actual_class_name
18767 (language_class_name_from_physname (cu
->language_defn
,
18768 child_pdi
->linkage_name
));
18769 if (actual_class_name
!= NULL
)
18771 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18772 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18779 /* Return true if a DIE with TAG may have the DW_AT_const_value
18783 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18787 case DW_TAG_constant
:
18788 case DW_TAG_enumerator
:
18789 case DW_TAG_formal_parameter
:
18790 case DW_TAG_template_value_param
:
18791 case DW_TAG_variable
:
18799 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18801 /* Once we've fixed up a die, there's no point in doing so again.
18802 This also avoids a memory leak if we were to call
18803 guess_partial_die_structure_name multiple times. */
18807 /* If we found a reference attribute and the DIE has no name, try
18808 to find a name in the referred to DIE. */
18810 if (name
== NULL
&& has_specification
)
18812 struct partial_die_info
*spec_die
;
18814 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18815 spec_die
= res
.pdi
;
18818 spec_die
->fixup (cu
);
18820 if (spec_die
->name
)
18822 name
= spec_die
->name
;
18824 /* Copy DW_AT_external attribute if it is set. */
18825 if (spec_die
->is_external
)
18826 is_external
= spec_die
->is_external
;
18830 if (!has_const_value
&& has_specification
18831 && can_have_DW_AT_const_value_p (tag
))
18833 struct partial_die_info
*spec_die
;
18835 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18836 spec_die
= res
.pdi
;
18839 spec_die
->fixup (cu
);
18841 if (spec_die
->has_const_value
)
18843 /* Copy DW_AT_const_value attribute if it is set. */
18844 has_const_value
= spec_die
->has_const_value
;
18848 /* Set default names for some unnamed DIEs. */
18850 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18851 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18853 /* If there is no parent die to provide a namespace, and there are
18854 children, see if we can determine the namespace from their linkage
18856 if (cu
->language
== language_cplus
18857 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18858 && die_parent
== NULL
18860 && (tag
== DW_TAG_class_type
18861 || tag
== DW_TAG_structure_type
18862 || tag
== DW_TAG_union_type
))
18863 guess_partial_die_structure_name (this, cu
);
18865 /* GCC might emit a nameless struct or union that has a linkage
18866 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18868 && (tag
== DW_TAG_class_type
18869 || tag
== DW_TAG_interface_type
18870 || tag
== DW_TAG_structure_type
18871 || tag
== DW_TAG_union_type
)
18872 && linkage_name
!= NULL
)
18874 gdb::unique_xmalloc_ptr
<char> demangled
18875 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18876 if (demangled
!= nullptr)
18880 /* Strip any leading namespaces/classes, keep only the base name.
18881 DW_AT_name for named DIEs does not contain the prefixes. */
18882 base
= strrchr (demangled
.get (), ':');
18883 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18886 base
= demangled
.get ();
18888 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18889 name
= objfile
->intern (base
);
18896 /* Read the .debug_loclists header contents from the given SECTION in the
18899 read_loclist_header (struct loclist_header
*header
,
18900 struct dwarf2_section_info
*section
)
18902 unsigned int bytes_read
;
18903 bfd
*abfd
= section
->get_bfd_owner ();
18904 const gdb_byte
*info_ptr
= section
->buffer
;
18905 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18906 info_ptr
+= bytes_read
;
18907 header
->version
= read_2_bytes (abfd
, info_ptr
);
18909 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18911 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18913 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18916 /* Return the DW_AT_loclists_base value for the CU. */
18918 lookup_loclist_base (struct dwarf2_cu
*cu
)
18920 /* For the .dwo unit, the loclist_base points to the first offset following
18921 the header. The header consists of the following entities-
18922 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18924 2. version (2 bytes)
18925 3. address size (1 byte)
18926 4. segment selector size (1 byte)
18927 5. offset entry count (4 bytes)
18928 These sizes are derived as per the DWARFv5 standard. */
18929 if (cu
->dwo_unit
!= nullptr)
18931 if (cu
->header
.initial_length_size
== 4)
18932 return LOCLIST_HEADER_SIZE32
;
18933 return LOCLIST_HEADER_SIZE64
;
18935 return cu
->loclist_base
;
18938 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18939 array of offsets in the .debug_loclists section. */
18941 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18943 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18944 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18945 bfd
*abfd
= objfile
->obfd
;
18946 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18947 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18949 section
->read (objfile
);
18950 if (section
->buffer
== NULL
)
18951 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18952 "section [in module %s]"), objfile_name (objfile
));
18953 struct loclist_header header
;
18954 read_loclist_header (&header
, section
);
18955 if (loclist_index
>= header
.offset_entry_count
)
18956 complaint (_("DW_FORM_loclistx pointing outside of "
18957 ".debug_loclists offset array [in module %s]"),
18958 objfile_name (objfile
));
18959 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18961 complaint (_("DW_FORM_loclistx pointing outside of "
18962 ".debug_loclists section [in module %s]"),
18963 objfile_name (objfile
));
18964 const gdb_byte
*info_ptr
18965 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18967 if (cu
->header
.offset_size
== 4)
18968 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18970 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18973 /* Process the attributes that had to be skipped in the first round. These
18974 attributes are the ones that need str_offsets_base or addr_base attributes.
18975 They could not have been processed in the first round, because at the time
18976 the values of str_offsets_base or addr_base may not have been known. */
18978 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18979 struct attribute
*attr
)
18981 struct dwarf2_cu
*cu
= reader
->cu
;
18982 switch (attr
->form
)
18984 case DW_FORM_addrx
:
18985 case DW_FORM_GNU_addr_index
:
18986 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18988 case DW_FORM_loclistx
:
18989 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
18992 case DW_FORM_strx1
:
18993 case DW_FORM_strx2
:
18994 case DW_FORM_strx3
:
18995 case DW_FORM_strx4
:
18996 case DW_FORM_GNU_str_index
:
18998 unsigned int str_index
= DW_UNSND (attr
);
18999 if (reader
->dwo_file
!= NULL
)
19001 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19002 DW_STRING_IS_CANONICAL (attr
) = 0;
19006 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19007 DW_STRING_IS_CANONICAL (attr
) = 0;
19012 gdb_assert_not_reached (_("Unexpected DWARF form."));
19016 /* Read an attribute value described by an attribute form. */
19018 static const gdb_byte
*
19019 read_attribute_value (const struct die_reader_specs
*reader
,
19020 struct attribute
*attr
, unsigned form
,
19021 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19022 bool *need_reprocess
)
19024 struct dwarf2_cu
*cu
= reader
->cu
;
19025 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19026 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19027 bfd
*abfd
= reader
->abfd
;
19028 struct comp_unit_head
*cu_header
= &cu
->header
;
19029 unsigned int bytes_read
;
19030 struct dwarf_block
*blk
;
19031 *need_reprocess
= false;
19033 attr
->form
= (enum dwarf_form
) form
;
19036 case DW_FORM_ref_addr
:
19037 if (cu
->header
.version
== 2)
19038 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19041 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19043 info_ptr
+= bytes_read
;
19045 case DW_FORM_GNU_ref_alt
:
19046 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19047 info_ptr
+= bytes_read
;
19051 struct gdbarch
*gdbarch
= objfile
->arch ();
19052 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19053 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19054 info_ptr
+= bytes_read
;
19057 case DW_FORM_block2
:
19058 blk
= dwarf_alloc_block (cu
);
19059 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19061 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19062 info_ptr
+= blk
->size
;
19063 DW_BLOCK (attr
) = blk
;
19065 case DW_FORM_block4
:
19066 blk
= dwarf_alloc_block (cu
);
19067 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19069 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19070 info_ptr
+= blk
->size
;
19071 DW_BLOCK (attr
) = blk
;
19073 case DW_FORM_data2
:
19074 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19077 case DW_FORM_data4
:
19078 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19081 case DW_FORM_data8
:
19082 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19085 case DW_FORM_data16
:
19086 blk
= dwarf_alloc_block (cu
);
19088 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19090 DW_BLOCK (attr
) = blk
;
19092 case DW_FORM_sec_offset
:
19093 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19094 info_ptr
+= bytes_read
;
19096 case DW_FORM_loclistx
:
19098 *need_reprocess
= true;
19099 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19100 info_ptr
+= bytes_read
;
19103 case DW_FORM_string
:
19104 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19105 DW_STRING_IS_CANONICAL (attr
) = 0;
19106 info_ptr
+= bytes_read
;
19109 if (!cu
->per_cu
->is_dwz
)
19111 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19112 abfd
, info_ptr
, cu_header
,
19114 DW_STRING_IS_CANONICAL (attr
) = 0;
19115 info_ptr
+= bytes_read
;
19119 case DW_FORM_line_strp
:
19120 if (!cu
->per_cu
->is_dwz
)
19123 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
19125 DW_STRING_IS_CANONICAL (attr
) = 0;
19126 info_ptr
+= bytes_read
;
19130 case DW_FORM_GNU_strp_alt
:
19132 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19133 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19136 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19137 DW_STRING_IS_CANONICAL (attr
) = 0;
19138 info_ptr
+= bytes_read
;
19141 case DW_FORM_exprloc
:
19142 case DW_FORM_block
:
19143 blk
= dwarf_alloc_block (cu
);
19144 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19145 info_ptr
+= bytes_read
;
19146 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19147 info_ptr
+= blk
->size
;
19148 DW_BLOCK (attr
) = blk
;
19150 case DW_FORM_block1
:
19151 blk
= dwarf_alloc_block (cu
);
19152 blk
->size
= read_1_byte (abfd
, info_ptr
);
19154 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19155 info_ptr
+= blk
->size
;
19156 DW_BLOCK (attr
) = blk
;
19158 case DW_FORM_data1
:
19159 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19163 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19166 case DW_FORM_flag_present
:
19167 DW_UNSND (attr
) = 1;
19169 case DW_FORM_sdata
:
19170 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19171 info_ptr
+= bytes_read
;
19173 case DW_FORM_udata
:
19174 case DW_FORM_rnglistx
:
19175 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19176 info_ptr
+= bytes_read
;
19179 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19180 + read_1_byte (abfd
, info_ptr
));
19184 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19185 + read_2_bytes (abfd
, info_ptr
));
19189 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19190 + read_4_bytes (abfd
, info_ptr
));
19194 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19195 + read_8_bytes (abfd
, info_ptr
));
19198 case DW_FORM_ref_sig8
:
19199 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19202 case DW_FORM_ref_udata
:
19203 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19204 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19205 info_ptr
+= bytes_read
;
19207 case DW_FORM_indirect
:
19208 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19209 info_ptr
+= bytes_read
;
19210 if (form
== DW_FORM_implicit_const
)
19212 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19213 info_ptr
+= bytes_read
;
19215 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19216 info_ptr
, need_reprocess
);
19218 case DW_FORM_implicit_const
:
19219 DW_SND (attr
) = implicit_const
;
19221 case DW_FORM_addrx
:
19222 case DW_FORM_GNU_addr_index
:
19223 *need_reprocess
= true;
19224 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19225 info_ptr
+= bytes_read
;
19228 case DW_FORM_strx1
:
19229 case DW_FORM_strx2
:
19230 case DW_FORM_strx3
:
19231 case DW_FORM_strx4
:
19232 case DW_FORM_GNU_str_index
:
19234 ULONGEST str_index
;
19235 if (form
== DW_FORM_strx1
)
19237 str_index
= read_1_byte (abfd
, info_ptr
);
19240 else if (form
== DW_FORM_strx2
)
19242 str_index
= read_2_bytes (abfd
, info_ptr
);
19245 else if (form
== DW_FORM_strx3
)
19247 str_index
= read_3_bytes (abfd
, info_ptr
);
19250 else if (form
== DW_FORM_strx4
)
19252 str_index
= read_4_bytes (abfd
, info_ptr
);
19257 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19258 info_ptr
+= bytes_read
;
19260 *need_reprocess
= true;
19261 DW_UNSND (attr
) = str_index
;
19265 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19266 dwarf_form_name (form
),
19267 bfd_get_filename (abfd
));
19271 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19272 attr
->form
= DW_FORM_GNU_ref_alt
;
19274 /* We have seen instances where the compiler tried to emit a byte
19275 size attribute of -1 which ended up being encoded as an unsigned
19276 0xffffffff. Although 0xffffffff is technically a valid size value,
19277 an object of this size seems pretty unlikely so we can relatively
19278 safely treat these cases as if the size attribute was invalid and
19279 treat them as zero by default. */
19280 if (attr
->name
== DW_AT_byte_size
19281 && form
== DW_FORM_data4
19282 && DW_UNSND (attr
) >= 0xffffffff)
19285 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19286 hex_string (DW_UNSND (attr
)));
19287 DW_UNSND (attr
) = 0;
19293 /* Read an attribute described by an abbreviated attribute. */
19295 static const gdb_byte
*
19296 read_attribute (const struct die_reader_specs
*reader
,
19297 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19298 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19300 attr
->name
= abbrev
->name
;
19301 return read_attribute_value (reader
, attr
, abbrev
->form
,
19302 abbrev
->implicit_const
, info_ptr
,
19306 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19308 static const char *
19309 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19310 LONGEST str_offset
)
19312 return dwarf2_per_objfile
->per_bfd
->str
.read_string
19313 (dwarf2_per_objfile
->objfile
, str_offset
, "DW_FORM_strp");
19316 /* Return pointer to string at .debug_str offset as read from BUF.
19317 BUF is assumed to be in a compilation unit described by CU_HEADER.
19318 Return *BYTES_READ_PTR count of bytes read from BUF. */
19320 static const char *
19321 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19322 const gdb_byte
*buf
,
19323 const struct comp_unit_head
*cu_header
,
19324 unsigned int *bytes_read_ptr
)
19326 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19328 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
19334 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19335 const struct comp_unit_head
*cu_header
,
19336 unsigned int *bytes_read_ptr
)
19338 bfd
*abfd
= objfile
->obfd
;
19339 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19341 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19344 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19345 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19346 ADDR_SIZE is the size of addresses from the CU header. */
19349 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19350 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19353 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19354 bfd
*abfd
= objfile
->obfd
;
19355 const gdb_byte
*info_ptr
;
19356 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19358 dwarf2_per_objfile
->per_bfd
->addr
.read (objfile
);
19359 if (dwarf2_per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19360 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19361 objfile_name (objfile
));
19362 if (addr_base_or_zero
+ addr_index
* addr_size
19363 >= dwarf2_per_objfile
->per_bfd
->addr
.size
)
19364 error (_("DW_FORM_addr_index pointing outside of "
19365 ".debug_addr section [in module %s]"),
19366 objfile_name (objfile
));
19367 info_ptr
= (dwarf2_per_objfile
->per_bfd
->addr
.buffer
19368 + addr_base_or_zero
+ addr_index
* addr_size
);
19369 if (addr_size
== 4)
19370 return bfd_get_32 (abfd
, info_ptr
);
19372 return bfd_get_64 (abfd
, info_ptr
);
19375 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19378 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19380 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19381 cu
->addr_base
, cu
->header
.addr_size
);
19384 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19387 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19388 unsigned int *bytes_read
)
19390 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19391 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19393 return read_addr_index (cu
, addr_index
);
19399 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
19401 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19402 struct dwarf2_cu
*cu
= per_cu
->cu
;
19403 gdb::optional
<ULONGEST
> addr_base
;
19406 /* We need addr_base and addr_size.
19407 If we don't have PER_CU->cu, we have to get it.
19408 Nasty, but the alternative is storing the needed info in PER_CU,
19409 which at this point doesn't seem justified: it's not clear how frequently
19410 it would get used and it would increase the size of every PER_CU.
19411 Entry points like dwarf2_per_cu_addr_size do a similar thing
19412 so we're not in uncharted territory here.
19413 Alas we need to be a bit more complicated as addr_base is contained
19416 We don't need to read the entire CU(/TU).
19417 We just need the header and top level die.
19419 IWBN to use the aging mechanism to let us lazily later discard the CU.
19420 For now we skip this optimization. */
19424 addr_base
= cu
->addr_base
;
19425 addr_size
= cu
->header
.addr_size
;
19429 cutu_reader
reader (per_cu
, dwarf2_per_objfile
, NULL
, 0, false);
19430 addr_base
= reader
.cu
->addr_base
;
19431 addr_size
= reader
.cu
->header
.addr_size
;
19434 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19438 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19439 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19442 static const char *
19443 read_str_index (struct dwarf2_cu
*cu
,
19444 struct dwarf2_section_info
*str_section
,
19445 struct dwarf2_section_info
*str_offsets_section
,
19446 ULONGEST str_offsets_base
, ULONGEST str_index
)
19448 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19449 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19450 const char *objf_name
= objfile_name (objfile
);
19451 bfd
*abfd
= objfile
->obfd
;
19452 const gdb_byte
*info_ptr
;
19453 ULONGEST str_offset
;
19454 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19456 str_section
->read (objfile
);
19457 str_offsets_section
->read (objfile
);
19458 if (str_section
->buffer
== NULL
)
19459 error (_("%s used without %s section"
19460 " in CU at offset %s [in module %s]"),
19461 form_name
, str_section
->get_name (),
19462 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19463 if (str_offsets_section
->buffer
== NULL
)
19464 error (_("%s used without %s section"
19465 " in CU at offset %s [in module %s]"),
19466 form_name
, str_section
->get_name (),
19467 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19468 info_ptr
= (str_offsets_section
->buffer
19470 + str_index
* cu
->header
.offset_size
);
19471 if (cu
->header
.offset_size
== 4)
19472 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19474 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19475 if (str_offset
>= str_section
->size
)
19476 error (_("Offset from %s pointing outside of"
19477 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19478 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19479 return (const char *) (str_section
->buffer
+ str_offset
);
19482 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19484 static const char *
19485 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19487 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19488 ? reader
->cu
->header
.addr_size
: 0;
19489 return read_str_index (reader
->cu
,
19490 &reader
->dwo_file
->sections
.str
,
19491 &reader
->dwo_file
->sections
.str_offsets
,
19492 str_offsets_base
, str_index
);
19495 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19497 static const char *
19498 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19500 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19501 const char *objf_name
= objfile_name (objfile
);
19502 static const char form_name
[] = "DW_FORM_GNU_str_index";
19503 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19505 if (!cu
->str_offsets_base
.has_value ())
19506 error (_("%s used in Fission stub without %s"
19507 " in CU at offset 0x%lx [in module %s]"),
19508 form_name
, str_offsets_attr_name
,
19509 (long) cu
->header
.offset_size
, objf_name
);
19511 return read_str_index (cu
,
19512 &cu
->per_objfile
->per_bfd
->str
,
19513 &cu
->per_objfile
->per_bfd
->str_offsets
,
19514 *cu
->str_offsets_base
, str_index
);
19517 /* Return the length of an LEB128 number in BUF. */
19520 leb128_size (const gdb_byte
*buf
)
19522 const gdb_byte
*begin
= buf
;
19528 if ((byte
& 128) == 0)
19529 return buf
- begin
;
19534 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19543 cu
->language
= language_c
;
19546 case DW_LANG_C_plus_plus
:
19547 case DW_LANG_C_plus_plus_11
:
19548 case DW_LANG_C_plus_plus_14
:
19549 cu
->language
= language_cplus
;
19552 cu
->language
= language_d
;
19554 case DW_LANG_Fortran77
:
19555 case DW_LANG_Fortran90
:
19556 case DW_LANG_Fortran95
:
19557 case DW_LANG_Fortran03
:
19558 case DW_LANG_Fortran08
:
19559 cu
->language
= language_fortran
;
19562 cu
->language
= language_go
;
19564 case DW_LANG_Mips_Assembler
:
19565 cu
->language
= language_asm
;
19567 case DW_LANG_Ada83
:
19568 case DW_LANG_Ada95
:
19569 cu
->language
= language_ada
;
19571 case DW_LANG_Modula2
:
19572 cu
->language
= language_m2
;
19574 case DW_LANG_Pascal83
:
19575 cu
->language
= language_pascal
;
19578 cu
->language
= language_objc
;
19581 case DW_LANG_Rust_old
:
19582 cu
->language
= language_rust
;
19584 case DW_LANG_Cobol74
:
19585 case DW_LANG_Cobol85
:
19587 cu
->language
= language_minimal
;
19590 cu
->language_defn
= language_def (cu
->language
);
19593 /* Return the named attribute or NULL if not there. */
19595 static struct attribute
*
19596 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19601 struct attribute
*spec
= NULL
;
19603 for (i
= 0; i
< die
->num_attrs
; ++i
)
19605 if (die
->attrs
[i
].name
== name
)
19606 return &die
->attrs
[i
];
19607 if (die
->attrs
[i
].name
== DW_AT_specification
19608 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19609 spec
= &die
->attrs
[i
];
19615 die
= follow_die_ref (die
, spec
, &cu
);
19621 /* Return the string associated with a string-typed attribute, or NULL if it
19622 is either not found or is of an incorrect type. */
19624 static const char *
19625 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19627 struct attribute
*attr
;
19628 const char *str
= NULL
;
19630 attr
= dwarf2_attr (die
, name
, cu
);
19634 str
= attr
->value_as_string ();
19635 if (str
== nullptr)
19636 complaint (_("string type expected for attribute %s for "
19637 "DIE at %s in module %s"),
19638 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19639 objfile_name (cu
->per_objfile
->objfile
));
19645 /* Return the dwo name or NULL if not present. If present, it is in either
19646 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19647 static const char *
19648 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19650 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19651 if (dwo_name
== nullptr)
19652 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19656 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19657 and holds a non-zero value. This function should only be used for
19658 DW_FORM_flag or DW_FORM_flag_present attributes. */
19661 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19663 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19665 return (attr
&& DW_UNSND (attr
));
19669 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19671 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19672 which value is non-zero. However, we have to be careful with
19673 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19674 (via dwarf2_flag_true_p) follows this attribute. So we may
19675 end up accidently finding a declaration attribute that belongs
19676 to a different DIE referenced by the specification attribute,
19677 even though the given DIE does not have a declaration attribute. */
19678 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19679 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19682 /* Return the die giving the specification for DIE, if there is
19683 one. *SPEC_CU is the CU containing DIE on input, and the CU
19684 containing the return value on output. If there is no
19685 specification, but there is an abstract origin, that is
19688 static struct die_info
*
19689 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19691 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19694 if (spec_attr
== NULL
)
19695 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19697 if (spec_attr
== NULL
)
19700 return follow_die_ref (die
, spec_attr
, spec_cu
);
19703 /* Stub for free_line_header to match void * callback types. */
19706 free_line_header_voidp (void *arg
)
19708 struct line_header
*lh
= (struct line_header
*) arg
;
19713 /* A convenience function to find the proper .debug_line section for a CU. */
19715 static struct dwarf2_section_info
*
19716 get_debug_line_section (struct dwarf2_cu
*cu
)
19718 struct dwarf2_section_info
*section
;
19719 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19721 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19723 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19724 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19725 else if (cu
->per_cu
->is_dwz
)
19727 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19729 section
= &dwz
->line
;
19732 section
= &dwarf2_per_objfile
->per_bfd
->line
;
19737 /* Read the statement program header starting at OFFSET in
19738 .debug_line, or .debug_line.dwo. Return a pointer
19739 to a struct line_header, allocated using xmalloc.
19740 Returns NULL if there is a problem reading the header, e.g., if it
19741 has a version we don't understand.
19743 NOTE: the strings in the include directory and file name tables of
19744 the returned object point into the dwarf line section buffer,
19745 and must not be freed. */
19747 static line_header_up
19748 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19750 struct dwarf2_section_info
*section
;
19751 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19753 section
= get_debug_line_section (cu
);
19754 section
->read (dwarf2_per_objfile
->objfile
);
19755 if (section
->buffer
== NULL
)
19757 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19758 complaint (_("missing .debug_line.dwo section"));
19760 complaint (_("missing .debug_line section"));
19764 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19765 dwarf2_per_objfile
, section
,
19769 /* Subroutine of dwarf_decode_lines to simplify it.
19770 Return the file name of the psymtab for the given file_entry.
19771 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19772 If space for the result is malloc'd, *NAME_HOLDER will be set.
19773 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19775 static const char *
19776 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19777 const dwarf2_psymtab
*pst
,
19778 const char *comp_dir
,
19779 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19781 const char *include_name
= fe
.name
;
19782 const char *include_name_to_compare
= include_name
;
19783 const char *pst_filename
;
19786 const char *dir_name
= fe
.include_dir (lh
);
19788 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19789 if (!IS_ABSOLUTE_PATH (include_name
)
19790 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19792 /* Avoid creating a duplicate psymtab for PST.
19793 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19794 Before we do the comparison, however, we need to account
19795 for DIR_NAME and COMP_DIR.
19796 First prepend dir_name (if non-NULL). If we still don't
19797 have an absolute path prepend comp_dir (if non-NULL).
19798 However, the directory we record in the include-file's
19799 psymtab does not contain COMP_DIR (to match the
19800 corresponding symtab(s)).
19805 bash$ gcc -g ./hello.c
19806 include_name = "hello.c"
19808 DW_AT_comp_dir = comp_dir = "/tmp"
19809 DW_AT_name = "./hello.c"
19813 if (dir_name
!= NULL
)
19815 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19816 include_name
, (char *) NULL
));
19817 include_name
= name_holder
->get ();
19818 include_name_to_compare
= include_name
;
19820 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19822 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19823 include_name
, (char *) NULL
));
19824 include_name_to_compare
= hold_compare
.get ();
19828 pst_filename
= pst
->filename
;
19829 gdb::unique_xmalloc_ptr
<char> copied_name
;
19830 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19832 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19833 pst_filename
, (char *) NULL
));
19834 pst_filename
= copied_name
.get ();
19837 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19841 return include_name
;
19844 /* State machine to track the state of the line number program. */
19846 class lnp_state_machine
19849 /* Initialize a machine state for the start of a line number
19851 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19852 bool record_lines_p
);
19854 file_entry
*current_file ()
19856 /* lh->file_names is 0-based, but the file name numbers in the
19857 statement program are 1-based. */
19858 return m_line_header
->file_name_at (m_file
);
19861 /* Record the line in the state machine. END_SEQUENCE is true if
19862 we're processing the end of a sequence. */
19863 void record_line (bool end_sequence
);
19865 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19866 nop-out rest of the lines in this sequence. */
19867 void check_line_address (struct dwarf2_cu
*cu
,
19868 const gdb_byte
*line_ptr
,
19869 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19871 void handle_set_discriminator (unsigned int discriminator
)
19873 m_discriminator
= discriminator
;
19874 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19877 /* Handle DW_LNE_set_address. */
19878 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19881 address
+= baseaddr
;
19882 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19885 /* Handle DW_LNS_advance_pc. */
19886 void handle_advance_pc (CORE_ADDR adjust
);
19888 /* Handle a special opcode. */
19889 void handle_special_opcode (unsigned char op_code
);
19891 /* Handle DW_LNS_advance_line. */
19892 void handle_advance_line (int line_delta
)
19894 advance_line (line_delta
);
19897 /* Handle DW_LNS_set_file. */
19898 void handle_set_file (file_name_index file
);
19900 /* Handle DW_LNS_negate_stmt. */
19901 void handle_negate_stmt ()
19903 m_is_stmt
= !m_is_stmt
;
19906 /* Handle DW_LNS_const_add_pc. */
19907 void handle_const_add_pc ();
19909 /* Handle DW_LNS_fixed_advance_pc. */
19910 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19912 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19916 /* Handle DW_LNS_copy. */
19917 void handle_copy ()
19919 record_line (false);
19920 m_discriminator
= 0;
19923 /* Handle DW_LNE_end_sequence. */
19924 void handle_end_sequence ()
19926 m_currently_recording_lines
= true;
19930 /* Advance the line by LINE_DELTA. */
19931 void advance_line (int line_delta
)
19933 m_line
+= line_delta
;
19935 if (line_delta
!= 0)
19936 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19939 struct dwarf2_cu
*m_cu
;
19941 gdbarch
*m_gdbarch
;
19943 /* True if we're recording lines.
19944 Otherwise we're building partial symtabs and are just interested in
19945 finding include files mentioned by the line number program. */
19946 bool m_record_lines_p
;
19948 /* The line number header. */
19949 line_header
*m_line_header
;
19951 /* These are part of the standard DWARF line number state machine,
19952 and initialized according to the DWARF spec. */
19954 unsigned char m_op_index
= 0;
19955 /* The line table index of the current file. */
19956 file_name_index m_file
= 1;
19957 unsigned int m_line
= 1;
19959 /* These are initialized in the constructor. */
19961 CORE_ADDR m_address
;
19963 unsigned int m_discriminator
;
19965 /* Additional bits of state we need to track. */
19967 /* The last file that we called dwarf2_start_subfile for.
19968 This is only used for TLLs. */
19969 unsigned int m_last_file
= 0;
19970 /* The last file a line number was recorded for. */
19971 struct subfile
*m_last_subfile
= NULL
;
19973 /* When true, record the lines we decode. */
19974 bool m_currently_recording_lines
= false;
19976 /* The last line number that was recorded, used to coalesce
19977 consecutive entries for the same line. This can happen, for
19978 example, when discriminators are present. PR 17276. */
19979 unsigned int m_last_line
= 0;
19980 bool m_line_has_non_zero_discriminator
= false;
19984 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19986 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19987 / m_line_header
->maximum_ops_per_instruction
)
19988 * m_line_header
->minimum_instruction_length
);
19989 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19990 m_op_index
= ((m_op_index
+ adjust
)
19991 % m_line_header
->maximum_ops_per_instruction
);
19995 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19997 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19998 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19999 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20000 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20001 / m_line_header
->maximum_ops_per_instruction
)
20002 * m_line_header
->minimum_instruction_length
);
20003 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20004 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20005 % m_line_header
->maximum_ops_per_instruction
);
20007 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20008 advance_line (line_delta
);
20009 record_line (false);
20010 m_discriminator
= 0;
20014 lnp_state_machine::handle_set_file (file_name_index file
)
20018 const file_entry
*fe
= current_file ();
20020 dwarf2_debug_line_missing_file_complaint ();
20021 else if (m_record_lines_p
)
20023 const char *dir
= fe
->include_dir (m_line_header
);
20025 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20026 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20027 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20032 lnp_state_machine::handle_const_add_pc ()
20035 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20038 = (((m_op_index
+ adjust
)
20039 / m_line_header
->maximum_ops_per_instruction
)
20040 * m_line_header
->minimum_instruction_length
);
20042 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20043 m_op_index
= ((m_op_index
+ adjust
)
20044 % m_line_header
->maximum_ops_per_instruction
);
20047 /* Return non-zero if we should add LINE to the line number table.
20048 LINE is the line to add, LAST_LINE is the last line that was added,
20049 LAST_SUBFILE is the subfile for LAST_LINE.
20050 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20051 had a non-zero discriminator.
20053 We have to be careful in the presence of discriminators.
20054 E.g., for this line:
20056 for (i = 0; i < 100000; i++);
20058 clang can emit four line number entries for that one line,
20059 each with a different discriminator.
20060 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20062 However, we want gdb to coalesce all four entries into one.
20063 Otherwise the user could stepi into the middle of the line and
20064 gdb would get confused about whether the pc really was in the
20065 middle of the line.
20067 Things are further complicated by the fact that two consecutive
20068 line number entries for the same line is a heuristic used by gcc
20069 to denote the end of the prologue. So we can't just discard duplicate
20070 entries, we have to be selective about it. The heuristic we use is
20071 that we only collapse consecutive entries for the same line if at least
20072 one of those entries has a non-zero discriminator. PR 17276.
20074 Note: Addresses in the line number state machine can never go backwards
20075 within one sequence, thus this coalescing is ok. */
20078 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20079 unsigned int line
, unsigned int last_line
,
20080 int line_has_non_zero_discriminator
,
20081 struct subfile
*last_subfile
)
20083 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20085 if (line
!= last_line
)
20087 /* Same line for the same file that we've seen already.
20088 As a last check, for pr 17276, only record the line if the line
20089 has never had a non-zero discriminator. */
20090 if (!line_has_non_zero_discriminator
)
20095 /* Use the CU's builder to record line number LINE beginning at
20096 address ADDRESS in the line table of subfile SUBFILE. */
20099 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20100 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20101 struct dwarf2_cu
*cu
)
20103 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20105 if (dwarf_line_debug
)
20107 fprintf_unfiltered (gdb_stdlog
,
20108 "Recording line %u, file %s, address %s\n",
20109 line
, lbasename (subfile
->name
),
20110 paddress (gdbarch
, address
));
20114 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20117 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20118 Mark the end of a set of line number records.
20119 The arguments are the same as for dwarf_record_line_1.
20120 If SUBFILE is NULL the request is ignored. */
20123 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20124 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20126 if (subfile
== NULL
)
20129 if (dwarf_line_debug
)
20131 fprintf_unfiltered (gdb_stdlog
,
20132 "Finishing current line, file %s, address %s\n",
20133 lbasename (subfile
->name
),
20134 paddress (gdbarch
, address
));
20137 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20141 lnp_state_machine::record_line (bool end_sequence
)
20143 if (dwarf_line_debug
)
20145 fprintf_unfiltered (gdb_stdlog
,
20146 "Processing actual line %u: file %u,"
20147 " address %s, is_stmt %u, discrim %u%s\n",
20149 paddress (m_gdbarch
, m_address
),
20150 m_is_stmt
, m_discriminator
,
20151 (end_sequence
? "\t(end sequence)" : ""));
20154 file_entry
*fe
= current_file ();
20157 dwarf2_debug_line_missing_file_complaint ();
20158 /* For now we ignore lines not starting on an instruction boundary.
20159 But not when processing end_sequence for compatibility with the
20160 previous version of the code. */
20161 else if (m_op_index
== 0 || end_sequence
)
20163 fe
->included_p
= 1;
20164 if (m_record_lines_p
)
20166 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20169 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20170 m_currently_recording_lines
? m_cu
: nullptr);
20175 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20177 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20178 m_line_has_non_zero_discriminator
,
20181 buildsym_compunit
*builder
= m_cu
->get_builder ();
20182 dwarf_record_line_1 (m_gdbarch
,
20183 builder
->get_current_subfile (),
20184 m_line
, m_address
, is_stmt
,
20185 m_currently_recording_lines
? m_cu
: nullptr);
20187 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20188 m_last_line
= m_line
;
20194 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20195 line_header
*lh
, bool record_lines_p
)
20199 m_record_lines_p
= record_lines_p
;
20200 m_line_header
= lh
;
20202 m_currently_recording_lines
= true;
20204 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20205 was a line entry for it so that the backend has a chance to adjust it
20206 and also record it in case it needs it. This is currently used by MIPS
20207 code, cf. `mips_adjust_dwarf2_line'. */
20208 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20209 m_is_stmt
= lh
->default_is_stmt
;
20210 m_discriminator
= 0;
20214 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20215 const gdb_byte
*line_ptr
,
20216 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20218 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20219 the pc range of the CU. However, we restrict the test to only ADDRESS
20220 values of zero to preserve GDB's previous behaviour which is to handle
20221 the specific case of a function being GC'd by the linker. */
20223 if (address
== 0 && address
< unrelocated_lowpc
)
20225 /* This line table is for a function which has been
20226 GCd by the linker. Ignore it. PR gdb/12528 */
20228 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20229 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20231 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20232 line_offset
, objfile_name (objfile
));
20233 m_currently_recording_lines
= false;
20234 /* Note: m_currently_recording_lines is left as false until we see
20235 DW_LNE_end_sequence. */
20239 /* Subroutine of dwarf_decode_lines to simplify it.
20240 Process the line number information in LH.
20241 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20242 program in order to set included_p for every referenced header. */
20245 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20246 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20248 const gdb_byte
*line_ptr
, *extended_end
;
20249 const gdb_byte
*line_end
;
20250 unsigned int bytes_read
, extended_len
;
20251 unsigned char op_code
, extended_op
;
20252 CORE_ADDR baseaddr
;
20253 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20254 bfd
*abfd
= objfile
->obfd
;
20255 struct gdbarch
*gdbarch
= objfile
->arch ();
20256 /* True if we're recording line info (as opposed to building partial
20257 symtabs and just interested in finding include files mentioned by
20258 the line number program). */
20259 bool record_lines_p
= !decode_for_pst_p
;
20261 baseaddr
= objfile
->text_section_offset ();
20263 line_ptr
= lh
->statement_program_start
;
20264 line_end
= lh
->statement_program_end
;
20266 /* Read the statement sequences until there's nothing left. */
20267 while (line_ptr
< line_end
)
20269 /* The DWARF line number program state machine. Reset the state
20270 machine at the start of each sequence. */
20271 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20272 bool end_sequence
= false;
20274 if (record_lines_p
)
20276 /* Start a subfile for the current file of the state
20278 const file_entry
*fe
= state_machine
.current_file ();
20281 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20284 /* Decode the table. */
20285 while (line_ptr
< line_end
&& !end_sequence
)
20287 op_code
= read_1_byte (abfd
, line_ptr
);
20290 if (op_code
>= lh
->opcode_base
)
20292 /* Special opcode. */
20293 state_machine
.handle_special_opcode (op_code
);
20295 else switch (op_code
)
20297 case DW_LNS_extended_op
:
20298 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20300 line_ptr
+= bytes_read
;
20301 extended_end
= line_ptr
+ extended_len
;
20302 extended_op
= read_1_byte (abfd
, line_ptr
);
20304 switch (extended_op
)
20306 case DW_LNE_end_sequence
:
20307 state_machine
.handle_end_sequence ();
20308 end_sequence
= true;
20310 case DW_LNE_set_address
:
20313 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20314 line_ptr
+= bytes_read
;
20316 state_machine
.check_line_address (cu
, line_ptr
,
20317 lowpc
- baseaddr
, address
);
20318 state_machine
.handle_set_address (baseaddr
, address
);
20321 case DW_LNE_define_file
:
20323 const char *cur_file
;
20324 unsigned int mod_time
, length
;
20327 cur_file
= read_direct_string (abfd
, line_ptr
,
20329 line_ptr
+= bytes_read
;
20330 dindex
= (dir_index
)
20331 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20332 line_ptr
+= bytes_read
;
20334 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20335 line_ptr
+= bytes_read
;
20337 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20338 line_ptr
+= bytes_read
;
20339 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20342 case DW_LNE_set_discriminator
:
20344 /* The discriminator is not interesting to the
20345 debugger; just ignore it. We still need to
20346 check its value though:
20347 if there are consecutive entries for the same
20348 (non-prologue) line we want to coalesce them.
20351 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20352 line_ptr
+= bytes_read
;
20354 state_machine
.handle_set_discriminator (discr
);
20358 complaint (_("mangled .debug_line section"));
20361 /* Make sure that we parsed the extended op correctly. If e.g.
20362 we expected a different address size than the producer used,
20363 we may have read the wrong number of bytes. */
20364 if (line_ptr
!= extended_end
)
20366 complaint (_("mangled .debug_line section"));
20371 state_machine
.handle_copy ();
20373 case DW_LNS_advance_pc
:
20376 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20377 line_ptr
+= bytes_read
;
20379 state_machine
.handle_advance_pc (adjust
);
20382 case DW_LNS_advance_line
:
20385 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20386 line_ptr
+= bytes_read
;
20388 state_machine
.handle_advance_line (line_delta
);
20391 case DW_LNS_set_file
:
20393 file_name_index file
20394 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20396 line_ptr
+= bytes_read
;
20398 state_machine
.handle_set_file (file
);
20401 case DW_LNS_set_column
:
20402 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20403 line_ptr
+= bytes_read
;
20405 case DW_LNS_negate_stmt
:
20406 state_machine
.handle_negate_stmt ();
20408 case DW_LNS_set_basic_block
:
20410 /* Add to the address register of the state machine the
20411 address increment value corresponding to special opcode
20412 255. I.e., this value is scaled by the minimum
20413 instruction length since special opcode 255 would have
20414 scaled the increment. */
20415 case DW_LNS_const_add_pc
:
20416 state_machine
.handle_const_add_pc ();
20418 case DW_LNS_fixed_advance_pc
:
20420 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20423 state_machine
.handle_fixed_advance_pc (addr_adj
);
20428 /* Unknown standard opcode, ignore it. */
20431 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20433 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20434 line_ptr
+= bytes_read
;
20441 dwarf2_debug_line_missing_end_sequence_complaint ();
20443 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20444 in which case we still finish recording the last line). */
20445 state_machine
.record_line (true);
20449 /* Decode the Line Number Program (LNP) for the given line_header
20450 structure and CU. The actual information extracted and the type
20451 of structures created from the LNP depends on the value of PST.
20453 1. If PST is NULL, then this procedure uses the data from the program
20454 to create all necessary symbol tables, and their linetables.
20456 2. If PST is not NULL, this procedure reads the program to determine
20457 the list of files included by the unit represented by PST, and
20458 builds all the associated partial symbol tables.
20460 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20461 It is used for relative paths in the line table.
20462 NOTE: When processing partial symtabs (pst != NULL),
20463 comp_dir == pst->dirname.
20465 NOTE: It is important that psymtabs have the same file name (via strcmp)
20466 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20467 symtab we don't use it in the name of the psymtabs we create.
20468 E.g. expand_line_sal requires this when finding psymtabs to expand.
20469 A good testcase for this is mb-inline.exp.
20471 LOWPC is the lowest address in CU (or 0 if not known).
20473 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20474 for its PC<->lines mapping information. Otherwise only the filename
20475 table is read in. */
20478 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20479 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20480 CORE_ADDR lowpc
, int decode_mapping
)
20482 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20483 const int decode_for_pst_p
= (pst
!= NULL
);
20485 if (decode_mapping
)
20486 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20488 if (decode_for_pst_p
)
20490 /* Now that we're done scanning the Line Header Program, we can
20491 create the psymtab of each included file. */
20492 for (auto &file_entry
: lh
->file_names ())
20493 if (file_entry
.included_p
== 1)
20495 gdb::unique_xmalloc_ptr
<char> name_holder
;
20496 const char *include_name
=
20497 psymtab_include_file_name (lh
, file_entry
, pst
,
20498 comp_dir
, &name_holder
);
20499 if (include_name
!= NULL
)
20500 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20505 /* Make sure a symtab is created for every file, even files
20506 which contain only variables (i.e. no code with associated
20508 buildsym_compunit
*builder
= cu
->get_builder ();
20509 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20511 for (auto &fe
: lh
->file_names ())
20513 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20514 if (builder
->get_current_subfile ()->symtab
== NULL
)
20516 builder
->get_current_subfile ()->symtab
20517 = allocate_symtab (cust
,
20518 builder
->get_current_subfile ()->name
);
20520 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20525 /* Start a subfile for DWARF. FILENAME is the name of the file and
20526 DIRNAME the name of the source directory which contains FILENAME
20527 or NULL if not known.
20528 This routine tries to keep line numbers from identical absolute and
20529 relative file names in a common subfile.
20531 Using the `list' example from the GDB testsuite, which resides in
20532 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20533 of /srcdir/list0.c yields the following debugging information for list0.c:
20535 DW_AT_name: /srcdir/list0.c
20536 DW_AT_comp_dir: /compdir
20537 files.files[0].name: list0.h
20538 files.files[0].dir: /srcdir
20539 files.files[1].name: list0.c
20540 files.files[1].dir: /srcdir
20542 The line number information for list0.c has to end up in a single
20543 subfile, so that `break /srcdir/list0.c:1' works as expected.
20544 start_subfile will ensure that this happens provided that we pass the
20545 concatenation of files.files[1].dir and files.files[1].name as the
20549 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20550 const char *dirname
)
20552 gdb::unique_xmalloc_ptr
<char> copy
;
20554 /* In order not to lose the line information directory,
20555 we concatenate it to the filename when it makes sense.
20556 Note that the Dwarf3 standard says (speaking of filenames in line
20557 information): ``The directory index is ignored for file names
20558 that represent full path names''. Thus ignoring dirname in the
20559 `else' branch below isn't an issue. */
20561 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20563 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20564 filename
= copy
.get ();
20567 cu
->get_builder ()->start_subfile (filename
);
20570 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20571 buildsym_compunit constructor. */
20573 struct compunit_symtab
*
20574 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20577 gdb_assert (m_builder
== nullptr);
20579 m_builder
.reset (new struct buildsym_compunit
20580 (per_cu
->dwarf2_per_objfile
->objfile
,
20581 name
, comp_dir
, language
, low_pc
));
20583 list_in_scope
= get_builder ()->get_file_symbols ();
20585 get_builder ()->record_debugformat ("DWARF 2");
20586 get_builder ()->record_producer (producer
);
20588 processing_has_namespace_info
= false;
20590 return get_builder ()->get_compunit_symtab ();
20594 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20595 struct dwarf2_cu
*cu
)
20597 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20598 struct comp_unit_head
*cu_header
= &cu
->header
;
20600 /* NOTE drow/2003-01-30: There used to be a comment and some special
20601 code here to turn a symbol with DW_AT_external and a
20602 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20603 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20604 with some versions of binutils) where shared libraries could have
20605 relocations against symbols in their debug information - the
20606 minimal symbol would have the right address, but the debug info
20607 would not. It's no longer necessary, because we will explicitly
20608 apply relocations when we read in the debug information now. */
20610 /* A DW_AT_location attribute with no contents indicates that a
20611 variable has been optimized away. */
20612 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20614 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20618 /* Handle one degenerate form of location expression specially, to
20619 preserve GDB's previous behavior when section offsets are
20620 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20621 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20623 if (attr
->form_is_block ()
20624 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20625 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20626 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20627 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20628 && (DW_BLOCK (attr
)->size
20629 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20631 unsigned int dummy
;
20633 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20634 SET_SYMBOL_VALUE_ADDRESS
20635 (sym
, cu
->header
.read_address (objfile
->obfd
,
20636 DW_BLOCK (attr
)->data
+ 1,
20639 SET_SYMBOL_VALUE_ADDRESS
20640 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20642 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20643 fixup_symbol_section (sym
, objfile
);
20644 SET_SYMBOL_VALUE_ADDRESS
20646 SYMBOL_VALUE_ADDRESS (sym
)
20647 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20651 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20652 expression evaluator, and use LOC_COMPUTED only when necessary
20653 (i.e. when the value of a register or memory location is
20654 referenced, or a thread-local block, etc.). Then again, it might
20655 not be worthwhile. I'm assuming that it isn't unless performance
20656 or memory numbers show me otherwise. */
20658 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20660 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20661 cu
->has_loclist
= true;
20664 /* Given a pointer to a DWARF information entry, figure out if we need
20665 to make a symbol table entry for it, and if so, create a new entry
20666 and return a pointer to it.
20667 If TYPE is NULL, determine symbol type from the die, otherwise
20668 used the passed type.
20669 If SPACE is not NULL, use it to hold the new symbol. If it is
20670 NULL, allocate a new symbol on the objfile's obstack. */
20672 static struct symbol
*
20673 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20674 struct symbol
*space
)
20676 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20677 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20678 struct gdbarch
*gdbarch
= objfile
->arch ();
20679 struct symbol
*sym
= NULL
;
20681 struct attribute
*attr
= NULL
;
20682 struct attribute
*attr2
= NULL
;
20683 CORE_ADDR baseaddr
;
20684 struct pending
**list_to_add
= NULL
;
20686 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20688 baseaddr
= objfile
->text_section_offset ();
20690 name
= dwarf2_name (die
, cu
);
20693 int suppress_add
= 0;
20698 sym
= new (&objfile
->objfile_obstack
) symbol
;
20699 OBJSTAT (objfile
, n_syms
++);
20701 /* Cache this symbol's name and the name's demangled form (if any). */
20702 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20703 /* Fortran does not have mangling standard and the mangling does differ
20704 between gfortran, iFort etc. */
20705 const char *physname
20706 = (cu
->language
== language_fortran
20707 ? dwarf2_full_name (name
, die
, cu
)
20708 : dwarf2_physname (name
, die
, cu
));
20709 const char *linkagename
= dw2_linkage_name (die
, cu
);
20711 if (linkagename
== nullptr || cu
->language
== language_ada
)
20712 sym
->set_linkage_name (physname
);
20715 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20716 sym
->set_linkage_name (linkagename
);
20719 /* Default assumptions.
20720 Use the passed type or decode it from the die. */
20721 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20722 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20724 SYMBOL_TYPE (sym
) = type
;
20726 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20727 attr
= dwarf2_attr (die
,
20728 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20730 if (attr
!= nullptr)
20732 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20735 attr
= dwarf2_attr (die
,
20736 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20738 if (attr
!= nullptr)
20740 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20741 struct file_entry
*fe
;
20743 if (cu
->line_header
!= NULL
)
20744 fe
= cu
->line_header
->file_name_at (file_index
);
20749 complaint (_("file index out of range"));
20751 symbol_set_symtab (sym
, fe
->symtab
);
20757 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20758 if (attr
!= nullptr)
20762 addr
= attr
->value_as_address ();
20763 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20764 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20766 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20767 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20768 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20769 add_symbol_to_list (sym
, cu
->list_in_scope
);
20771 case DW_TAG_subprogram
:
20772 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20774 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20775 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20776 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20777 || cu
->language
== language_ada
20778 || cu
->language
== language_fortran
)
20780 /* Subprograms marked external are stored as a global symbol.
20781 Ada and Fortran subprograms, whether marked external or
20782 not, are always stored as a global symbol, because we want
20783 to be able to access them globally. For instance, we want
20784 to be able to break on a nested subprogram without having
20785 to specify the context. */
20786 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20790 list_to_add
= cu
->list_in_scope
;
20793 case DW_TAG_inlined_subroutine
:
20794 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20796 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20797 SYMBOL_INLINED (sym
) = 1;
20798 list_to_add
= cu
->list_in_scope
;
20800 case DW_TAG_template_value_param
:
20802 /* Fall through. */
20803 case DW_TAG_constant
:
20804 case DW_TAG_variable
:
20805 case DW_TAG_member
:
20806 /* Compilation with minimal debug info may result in
20807 variables with missing type entries. Change the
20808 misleading `void' type to something sensible. */
20809 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20810 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20812 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20813 /* In the case of DW_TAG_member, we should only be called for
20814 static const members. */
20815 if (die
->tag
== DW_TAG_member
)
20817 /* dwarf2_add_field uses die_is_declaration,
20818 so we do the same. */
20819 gdb_assert (die_is_declaration (die
, cu
));
20822 if (attr
!= nullptr)
20824 dwarf2_const_value (attr
, sym
, cu
);
20825 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20828 if (attr2
&& (DW_UNSND (attr2
) != 0))
20829 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20831 list_to_add
= cu
->list_in_scope
;
20835 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20836 if (attr
!= nullptr)
20838 var_decode_location (attr
, sym
, cu
);
20839 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20841 /* Fortran explicitly imports any global symbols to the local
20842 scope by DW_TAG_common_block. */
20843 if (cu
->language
== language_fortran
&& die
->parent
20844 && die
->parent
->tag
== DW_TAG_common_block
)
20847 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20848 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20849 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
20851 /* When a static variable is eliminated by the linker,
20852 the corresponding debug information is not stripped
20853 out, but the variable address is set to null;
20854 do not add such variables into symbol table. */
20856 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20858 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20859 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20860 && dwarf2_per_objfile
->per_bfd
->can_copy
)
20862 /* A global static variable might be subject to
20863 copy relocation. We first check for a local
20864 minsym, though, because maybe the symbol was
20865 marked hidden, in which case this would not
20867 bound_minimal_symbol found
20868 = (lookup_minimal_symbol_linkage
20869 (sym
->linkage_name (), objfile
));
20870 if (found
.minsym
!= nullptr)
20871 sym
->maybe_copied
= 1;
20874 /* A variable with DW_AT_external is never static,
20875 but it may be block-scoped. */
20877 = ((cu
->list_in_scope
20878 == cu
->get_builder ()->get_file_symbols ())
20879 ? cu
->get_builder ()->get_global_symbols ()
20880 : cu
->list_in_scope
);
20883 list_to_add
= cu
->list_in_scope
;
20887 /* We do not know the address of this symbol.
20888 If it is an external symbol and we have type information
20889 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20890 The address of the variable will then be determined from
20891 the minimal symbol table whenever the variable is
20893 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20895 /* Fortran explicitly imports any global symbols to the local
20896 scope by DW_TAG_common_block. */
20897 if (cu
->language
== language_fortran
&& die
->parent
20898 && die
->parent
->tag
== DW_TAG_common_block
)
20900 /* SYMBOL_CLASS doesn't matter here because
20901 read_common_block is going to reset it. */
20903 list_to_add
= cu
->list_in_scope
;
20905 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20906 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20908 /* A variable with DW_AT_external is never static, but it
20909 may be block-scoped. */
20911 = ((cu
->list_in_scope
20912 == cu
->get_builder ()->get_file_symbols ())
20913 ? cu
->get_builder ()->get_global_symbols ()
20914 : cu
->list_in_scope
);
20916 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20918 else if (!die_is_declaration (die
, cu
))
20920 /* Use the default LOC_OPTIMIZED_OUT class. */
20921 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20923 list_to_add
= cu
->list_in_scope
;
20927 case DW_TAG_formal_parameter
:
20929 /* If we are inside a function, mark this as an argument. If
20930 not, we might be looking at an argument to an inlined function
20931 when we do not have enough information to show inlined frames;
20932 pretend it's a local variable in that case so that the user can
20934 struct context_stack
*curr
20935 = cu
->get_builder ()->get_current_context_stack ();
20936 if (curr
!= nullptr && curr
->name
!= nullptr)
20937 SYMBOL_IS_ARGUMENT (sym
) = 1;
20938 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20939 if (attr
!= nullptr)
20941 var_decode_location (attr
, sym
, cu
);
20943 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20944 if (attr
!= nullptr)
20946 dwarf2_const_value (attr
, sym
, cu
);
20949 list_to_add
= cu
->list_in_scope
;
20952 case DW_TAG_unspecified_parameters
:
20953 /* From varargs functions; gdb doesn't seem to have any
20954 interest in this information, so just ignore it for now.
20957 case DW_TAG_template_type_param
:
20959 /* Fall through. */
20960 case DW_TAG_class_type
:
20961 case DW_TAG_interface_type
:
20962 case DW_TAG_structure_type
:
20963 case DW_TAG_union_type
:
20964 case DW_TAG_set_type
:
20965 case DW_TAG_enumeration_type
:
20966 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20967 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20970 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20971 really ever be static objects: otherwise, if you try
20972 to, say, break of a class's method and you're in a file
20973 which doesn't mention that class, it won't work unless
20974 the check for all static symbols in lookup_symbol_aux
20975 saves you. See the OtherFileClass tests in
20976 gdb.c++/namespace.exp. */
20980 buildsym_compunit
*builder
= cu
->get_builder ();
20982 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20983 && cu
->language
== language_cplus
20984 ? builder
->get_global_symbols ()
20985 : cu
->list_in_scope
);
20987 /* The semantics of C++ state that "struct foo {
20988 ... }" also defines a typedef for "foo". */
20989 if (cu
->language
== language_cplus
20990 || cu
->language
== language_ada
20991 || cu
->language
== language_d
20992 || cu
->language
== language_rust
)
20994 /* The symbol's name is already allocated along
20995 with this objfile, so we don't need to
20996 duplicate it for the type. */
20997 if (SYMBOL_TYPE (sym
)->name () == 0)
20998 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21003 case DW_TAG_typedef
:
21004 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21005 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21006 list_to_add
= cu
->list_in_scope
;
21008 case DW_TAG_base_type
:
21009 case DW_TAG_subrange_type
:
21010 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21011 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21012 list_to_add
= cu
->list_in_scope
;
21014 case DW_TAG_enumerator
:
21015 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21016 if (attr
!= nullptr)
21018 dwarf2_const_value (attr
, sym
, cu
);
21021 /* NOTE: carlton/2003-11-10: See comment above in the
21022 DW_TAG_class_type, etc. block. */
21025 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21026 && cu
->language
== language_cplus
21027 ? cu
->get_builder ()->get_global_symbols ()
21028 : cu
->list_in_scope
);
21031 case DW_TAG_imported_declaration
:
21032 case DW_TAG_namespace
:
21033 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21034 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21036 case DW_TAG_module
:
21037 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21038 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21039 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21041 case DW_TAG_common_block
:
21042 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21043 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21044 add_symbol_to_list (sym
, cu
->list_in_scope
);
21047 /* Not a tag we recognize. Hopefully we aren't processing
21048 trash data, but since we must specifically ignore things
21049 we don't recognize, there is nothing else we should do at
21051 complaint (_("unsupported tag: '%s'"),
21052 dwarf_tag_name (die
->tag
));
21058 sym
->hash_next
= objfile
->template_symbols
;
21059 objfile
->template_symbols
= sym
;
21060 list_to_add
= NULL
;
21063 if (list_to_add
!= NULL
)
21064 add_symbol_to_list (sym
, list_to_add
);
21066 /* For the benefit of old versions of GCC, check for anonymous
21067 namespaces based on the demangled name. */
21068 if (!cu
->processing_has_namespace_info
21069 && cu
->language
== language_cplus
)
21070 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21075 /* Given an attr with a DW_FORM_dataN value in host byte order,
21076 zero-extend it as appropriate for the symbol's type. The DWARF
21077 standard (v4) is not entirely clear about the meaning of using
21078 DW_FORM_dataN for a constant with a signed type, where the type is
21079 wider than the data. The conclusion of a discussion on the DWARF
21080 list was that this is unspecified. We choose to always zero-extend
21081 because that is the interpretation long in use by GCC. */
21084 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21085 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21087 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21088 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21089 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21090 LONGEST l
= DW_UNSND (attr
);
21092 if (bits
< sizeof (*value
) * 8)
21094 l
&= ((LONGEST
) 1 << bits
) - 1;
21097 else if (bits
== sizeof (*value
) * 8)
21101 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21102 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21109 /* Read a constant value from an attribute. Either set *VALUE, or if
21110 the value does not fit in *VALUE, set *BYTES - either already
21111 allocated on the objfile obstack, or newly allocated on OBSTACK,
21112 or, set *BATON, if we translated the constant to a location
21116 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21117 const char *name
, struct obstack
*obstack
,
21118 struct dwarf2_cu
*cu
,
21119 LONGEST
*value
, const gdb_byte
**bytes
,
21120 struct dwarf2_locexpr_baton
**baton
)
21122 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21123 struct objfile
*objfile
= per_objfile
->objfile
;
21124 struct comp_unit_head
*cu_header
= &cu
->header
;
21125 struct dwarf_block
*blk
;
21126 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21127 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21133 switch (attr
->form
)
21136 case DW_FORM_addrx
:
21137 case DW_FORM_GNU_addr_index
:
21141 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21142 dwarf2_const_value_length_mismatch_complaint (name
,
21143 cu_header
->addr_size
,
21144 TYPE_LENGTH (type
));
21145 /* Symbols of this form are reasonably rare, so we just
21146 piggyback on the existing location code rather than writing
21147 a new implementation of symbol_computed_ops. */
21148 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21149 (*baton
)->per_objfile
= per_objfile
;
21150 (*baton
)->per_cu
= cu
->per_cu
;
21151 gdb_assert ((*baton
)->per_cu
);
21153 (*baton
)->size
= 2 + cu_header
->addr_size
;
21154 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21155 (*baton
)->data
= data
;
21157 data
[0] = DW_OP_addr
;
21158 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21159 byte_order
, DW_ADDR (attr
));
21160 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21163 case DW_FORM_string
:
21166 case DW_FORM_GNU_str_index
:
21167 case DW_FORM_GNU_strp_alt
:
21168 /* DW_STRING is already allocated on the objfile obstack, point
21170 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21172 case DW_FORM_block1
:
21173 case DW_FORM_block2
:
21174 case DW_FORM_block4
:
21175 case DW_FORM_block
:
21176 case DW_FORM_exprloc
:
21177 case DW_FORM_data16
:
21178 blk
= DW_BLOCK (attr
);
21179 if (TYPE_LENGTH (type
) != blk
->size
)
21180 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21181 TYPE_LENGTH (type
));
21182 *bytes
= blk
->data
;
21185 /* The DW_AT_const_value attributes are supposed to carry the
21186 symbol's value "represented as it would be on the target
21187 architecture." By the time we get here, it's already been
21188 converted to host endianness, so we just need to sign- or
21189 zero-extend it as appropriate. */
21190 case DW_FORM_data1
:
21191 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21193 case DW_FORM_data2
:
21194 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21196 case DW_FORM_data4
:
21197 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21199 case DW_FORM_data8
:
21200 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21203 case DW_FORM_sdata
:
21204 case DW_FORM_implicit_const
:
21205 *value
= DW_SND (attr
);
21208 case DW_FORM_udata
:
21209 *value
= DW_UNSND (attr
);
21213 complaint (_("unsupported const value attribute form: '%s'"),
21214 dwarf_form_name (attr
->form
));
21221 /* Copy constant value from an attribute to a symbol. */
21224 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21225 struct dwarf2_cu
*cu
)
21227 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21229 const gdb_byte
*bytes
;
21230 struct dwarf2_locexpr_baton
*baton
;
21232 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21233 sym
->print_name (),
21234 &objfile
->objfile_obstack
, cu
,
21235 &value
, &bytes
, &baton
);
21239 SYMBOL_LOCATION_BATON (sym
) = baton
;
21240 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21242 else if (bytes
!= NULL
)
21244 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21245 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21249 SYMBOL_VALUE (sym
) = value
;
21250 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21254 /* Return the type of the die in question using its DW_AT_type attribute. */
21256 static struct type
*
21257 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21259 struct attribute
*type_attr
;
21261 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21264 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21265 /* A missing DW_AT_type represents a void type. */
21266 return objfile_type (objfile
)->builtin_void
;
21269 return lookup_die_type (die
, type_attr
, cu
);
21272 /* True iff CU's producer generates GNAT Ada auxiliary information
21273 that allows to find parallel types through that information instead
21274 of having to do expensive parallel lookups by type name. */
21277 need_gnat_info (struct dwarf2_cu
*cu
)
21279 /* Assume that the Ada compiler was GNAT, which always produces
21280 the auxiliary information. */
21281 return (cu
->language
== language_ada
);
21284 /* Return the auxiliary type of the die in question using its
21285 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21286 attribute is not present. */
21288 static struct type
*
21289 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21291 struct attribute
*type_attr
;
21293 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21297 return lookup_die_type (die
, type_attr
, cu
);
21300 /* If DIE has a descriptive_type attribute, then set the TYPE's
21301 descriptive type accordingly. */
21304 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21305 struct dwarf2_cu
*cu
)
21307 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21309 if (descriptive_type
)
21311 ALLOCATE_GNAT_AUX_TYPE (type
);
21312 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21316 /* Return the containing type of the die in question using its
21317 DW_AT_containing_type attribute. */
21319 static struct type
*
21320 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21322 struct attribute
*type_attr
;
21323 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21325 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21327 error (_("Dwarf Error: Problem turning containing type into gdb type "
21328 "[in module %s]"), objfile_name (objfile
));
21330 return lookup_die_type (die
, type_attr
, cu
);
21333 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21335 static struct type
*
21336 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21338 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21339 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21342 std::string message
21343 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21344 objfile_name (objfile
),
21345 sect_offset_str (cu
->header
.sect_off
),
21346 sect_offset_str (die
->sect_off
));
21347 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21349 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21352 /* Look up the type of DIE in CU using its type attribute ATTR.
21353 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21354 DW_AT_containing_type.
21355 If there is no type substitute an error marker. */
21357 static struct type
*
21358 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21359 struct dwarf2_cu
*cu
)
21361 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21362 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21363 struct type
*this_type
;
21365 gdb_assert (attr
->name
== DW_AT_type
21366 || attr
->name
== DW_AT_GNAT_descriptive_type
21367 || attr
->name
== DW_AT_containing_type
);
21369 /* First see if we have it cached. */
21371 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21373 struct dwarf2_per_cu_data
*per_cu
;
21374 sect_offset sect_off
= attr
->get_ref_die_offset ();
21376 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21377 dwarf2_per_objfile
);
21378 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21380 else if (attr
->form_is_ref ())
21382 sect_offset sect_off
= attr
->get_ref_die_offset ();
21384 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21386 else if (attr
->form
== DW_FORM_ref_sig8
)
21388 ULONGEST signature
= DW_SIGNATURE (attr
);
21390 return get_signatured_type (die
, signature
, cu
);
21394 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21395 " at %s [in module %s]"),
21396 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21397 objfile_name (objfile
));
21398 return build_error_marker_type (cu
, die
);
21401 /* If not cached we need to read it in. */
21403 if (this_type
== NULL
)
21405 struct die_info
*type_die
= NULL
;
21406 struct dwarf2_cu
*type_cu
= cu
;
21408 if (attr
->form_is_ref ())
21409 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21410 if (type_die
== NULL
)
21411 return build_error_marker_type (cu
, die
);
21412 /* If we find the type now, it's probably because the type came
21413 from an inter-CU reference and the type's CU got expanded before
21415 this_type
= read_type_die (type_die
, type_cu
);
21418 /* If we still don't have a type use an error marker. */
21420 if (this_type
== NULL
)
21421 return build_error_marker_type (cu
, die
);
21426 /* Return the type in DIE, CU.
21427 Returns NULL for invalid types.
21429 This first does a lookup in die_type_hash,
21430 and only reads the die in if necessary.
21432 NOTE: This can be called when reading in partial or full symbols. */
21434 static struct type
*
21435 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21437 struct type
*this_type
;
21439 this_type
= get_die_type (die
, cu
);
21443 return read_type_die_1 (die
, cu
);
21446 /* Read the type in DIE, CU.
21447 Returns NULL for invalid types. */
21449 static struct type
*
21450 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21452 struct type
*this_type
= NULL
;
21456 case DW_TAG_class_type
:
21457 case DW_TAG_interface_type
:
21458 case DW_TAG_structure_type
:
21459 case DW_TAG_union_type
:
21460 this_type
= read_structure_type (die
, cu
);
21462 case DW_TAG_enumeration_type
:
21463 this_type
= read_enumeration_type (die
, cu
);
21465 case DW_TAG_subprogram
:
21466 case DW_TAG_subroutine_type
:
21467 case DW_TAG_inlined_subroutine
:
21468 this_type
= read_subroutine_type (die
, cu
);
21470 case DW_TAG_array_type
:
21471 this_type
= read_array_type (die
, cu
);
21473 case DW_TAG_set_type
:
21474 this_type
= read_set_type (die
, cu
);
21476 case DW_TAG_pointer_type
:
21477 this_type
= read_tag_pointer_type (die
, cu
);
21479 case DW_TAG_ptr_to_member_type
:
21480 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21482 case DW_TAG_reference_type
:
21483 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21485 case DW_TAG_rvalue_reference_type
:
21486 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21488 case DW_TAG_const_type
:
21489 this_type
= read_tag_const_type (die
, cu
);
21491 case DW_TAG_volatile_type
:
21492 this_type
= read_tag_volatile_type (die
, cu
);
21494 case DW_TAG_restrict_type
:
21495 this_type
= read_tag_restrict_type (die
, cu
);
21497 case DW_TAG_string_type
:
21498 this_type
= read_tag_string_type (die
, cu
);
21500 case DW_TAG_typedef
:
21501 this_type
= read_typedef (die
, cu
);
21503 case DW_TAG_subrange_type
:
21504 this_type
= read_subrange_type (die
, cu
);
21506 case DW_TAG_base_type
:
21507 this_type
= read_base_type (die
, cu
);
21509 case DW_TAG_unspecified_type
:
21510 this_type
= read_unspecified_type (die
, cu
);
21512 case DW_TAG_namespace
:
21513 this_type
= read_namespace_type (die
, cu
);
21515 case DW_TAG_module
:
21516 this_type
= read_module_type (die
, cu
);
21518 case DW_TAG_atomic_type
:
21519 this_type
= read_tag_atomic_type (die
, cu
);
21522 complaint (_("unexpected tag in read_type_die: '%s'"),
21523 dwarf_tag_name (die
->tag
));
21530 /* See if we can figure out if the class lives in a namespace. We do
21531 this by looking for a member function; its demangled name will
21532 contain namespace info, if there is any.
21533 Return the computed name or NULL.
21534 Space for the result is allocated on the objfile's obstack.
21535 This is the full-die version of guess_partial_die_structure_name.
21536 In this case we know DIE has no useful parent. */
21538 static const char *
21539 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21541 struct die_info
*spec_die
;
21542 struct dwarf2_cu
*spec_cu
;
21543 struct die_info
*child
;
21544 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21547 spec_die
= die_specification (die
, &spec_cu
);
21548 if (spec_die
!= NULL
)
21554 for (child
= die
->child
;
21556 child
= child
->sibling
)
21558 if (child
->tag
== DW_TAG_subprogram
)
21560 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21562 if (linkage_name
!= NULL
)
21564 gdb::unique_xmalloc_ptr
<char> actual_name
21565 (language_class_name_from_physname (cu
->language_defn
,
21567 const char *name
= NULL
;
21569 if (actual_name
!= NULL
)
21571 const char *die_name
= dwarf2_name (die
, cu
);
21573 if (die_name
!= NULL
21574 && strcmp (die_name
, actual_name
.get ()) != 0)
21576 /* Strip off the class name from the full name.
21577 We want the prefix. */
21578 int die_name_len
= strlen (die_name
);
21579 int actual_name_len
= strlen (actual_name
.get ());
21580 const char *ptr
= actual_name
.get ();
21582 /* Test for '::' as a sanity check. */
21583 if (actual_name_len
> die_name_len
+ 2
21584 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21585 name
= obstack_strndup (
21586 &objfile
->per_bfd
->storage_obstack
,
21587 ptr
, actual_name_len
- die_name_len
- 2);
21598 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21599 prefix part in such case. See
21600 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21602 static const char *
21603 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21605 struct attribute
*attr
;
21608 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21609 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21612 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21615 attr
= dw2_linkage_name_attr (die
, cu
);
21616 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21619 /* dwarf2_name had to be already called. */
21620 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21622 /* Strip the base name, keep any leading namespaces/classes. */
21623 base
= strrchr (DW_STRING (attr
), ':');
21624 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21627 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21628 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21630 &base
[-1] - DW_STRING (attr
));
21633 /* Return the name of the namespace/class that DIE is defined within,
21634 or "" if we can't tell. The caller should not xfree the result.
21636 For example, if we're within the method foo() in the following
21646 then determine_prefix on foo's die will return "N::C". */
21648 static const char *
21649 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21651 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21652 struct die_info
*parent
, *spec_die
;
21653 struct dwarf2_cu
*spec_cu
;
21654 struct type
*parent_type
;
21655 const char *retval
;
21657 if (cu
->language
!= language_cplus
21658 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21659 && cu
->language
!= language_rust
)
21662 retval
= anonymous_struct_prefix (die
, cu
);
21666 /* We have to be careful in the presence of DW_AT_specification.
21667 For example, with GCC 3.4, given the code
21671 // Definition of N::foo.
21675 then we'll have a tree of DIEs like this:
21677 1: DW_TAG_compile_unit
21678 2: DW_TAG_namespace // N
21679 3: DW_TAG_subprogram // declaration of N::foo
21680 4: DW_TAG_subprogram // definition of N::foo
21681 DW_AT_specification // refers to die #3
21683 Thus, when processing die #4, we have to pretend that we're in
21684 the context of its DW_AT_specification, namely the contex of die
21687 spec_die
= die_specification (die
, &spec_cu
);
21688 if (spec_die
== NULL
)
21689 parent
= die
->parent
;
21692 parent
= spec_die
->parent
;
21696 if (parent
== NULL
)
21698 else if (parent
->building_fullname
)
21701 const char *parent_name
;
21703 /* It has been seen on RealView 2.2 built binaries,
21704 DW_TAG_template_type_param types actually _defined_ as
21705 children of the parent class:
21708 template class <class Enum> Class{};
21709 Class<enum E> class_e;
21711 1: DW_TAG_class_type (Class)
21712 2: DW_TAG_enumeration_type (E)
21713 3: DW_TAG_enumerator (enum1:0)
21714 3: DW_TAG_enumerator (enum2:1)
21716 2: DW_TAG_template_type_param
21717 DW_AT_type DW_FORM_ref_udata (E)
21719 Besides being broken debug info, it can put GDB into an
21720 infinite loop. Consider:
21722 When we're building the full name for Class<E>, we'll start
21723 at Class, and go look over its template type parameters,
21724 finding E. We'll then try to build the full name of E, and
21725 reach here. We're now trying to build the full name of E,
21726 and look over the parent DIE for containing scope. In the
21727 broken case, if we followed the parent DIE of E, we'd again
21728 find Class, and once again go look at its template type
21729 arguments, etc., etc. Simply don't consider such parent die
21730 as source-level parent of this die (it can't be, the language
21731 doesn't allow it), and break the loop here. */
21732 name
= dwarf2_name (die
, cu
);
21733 parent_name
= dwarf2_name (parent
, cu
);
21734 complaint (_("template param type '%s' defined within parent '%s'"),
21735 name
? name
: "<unknown>",
21736 parent_name
? parent_name
: "<unknown>");
21740 switch (parent
->tag
)
21742 case DW_TAG_namespace
:
21743 parent_type
= read_type_die (parent
, cu
);
21744 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21745 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21746 Work around this problem here. */
21747 if (cu
->language
== language_cplus
21748 && strcmp (parent_type
->name (), "::") == 0)
21750 /* We give a name to even anonymous namespaces. */
21751 return parent_type
->name ();
21752 case DW_TAG_class_type
:
21753 case DW_TAG_interface_type
:
21754 case DW_TAG_structure_type
:
21755 case DW_TAG_union_type
:
21756 case DW_TAG_module
:
21757 parent_type
= read_type_die (parent
, cu
);
21758 if (parent_type
->name () != NULL
)
21759 return parent_type
->name ();
21761 /* An anonymous structure is only allowed non-static data
21762 members; no typedefs, no member functions, et cetera.
21763 So it does not need a prefix. */
21765 case DW_TAG_compile_unit
:
21766 case DW_TAG_partial_unit
:
21767 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21768 if (cu
->language
== language_cplus
21769 && !dwarf2_per_objfile
->per_bfd
->types
.empty ()
21770 && die
->child
!= NULL
21771 && (die
->tag
== DW_TAG_class_type
21772 || die
->tag
== DW_TAG_structure_type
21773 || die
->tag
== DW_TAG_union_type
))
21775 const char *name
= guess_full_die_structure_name (die
, cu
);
21780 case DW_TAG_subprogram
:
21781 /* Nested subroutines in Fortran get a prefix with the name
21782 of the parent's subroutine. */
21783 if (cu
->language
== language_fortran
)
21785 if ((die
->tag
== DW_TAG_subprogram
)
21786 && (dwarf2_name (parent
, cu
) != NULL
))
21787 return dwarf2_name (parent
, cu
);
21789 return determine_prefix (parent
, cu
);
21790 case DW_TAG_enumeration_type
:
21791 parent_type
= read_type_die (parent
, cu
);
21792 if (TYPE_DECLARED_CLASS (parent_type
))
21794 if (parent_type
->name () != NULL
)
21795 return parent_type
->name ();
21798 /* Fall through. */
21800 return determine_prefix (parent
, cu
);
21804 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21805 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21806 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21807 an obconcat, otherwise allocate storage for the result. The CU argument is
21808 used to determine the language and hence, the appropriate separator. */
21810 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21813 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21814 int physname
, struct dwarf2_cu
*cu
)
21816 const char *lead
= "";
21819 if (suffix
== NULL
|| suffix
[0] == '\0'
21820 || prefix
== NULL
|| prefix
[0] == '\0')
21822 else if (cu
->language
== language_d
)
21824 /* For D, the 'main' function could be defined in any module, but it
21825 should never be prefixed. */
21826 if (strcmp (suffix
, "D main") == 0)
21834 else if (cu
->language
== language_fortran
&& physname
)
21836 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21837 DW_AT_MIPS_linkage_name is preferred and used instead. */
21845 if (prefix
== NULL
)
21847 if (suffix
== NULL
)
21854 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21856 strcpy (retval
, lead
);
21857 strcat (retval
, prefix
);
21858 strcat (retval
, sep
);
21859 strcat (retval
, suffix
);
21864 /* We have an obstack. */
21865 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21869 /* Get name of a die, return NULL if not found. */
21871 static const char *
21872 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21873 struct objfile
*objfile
)
21875 if (name
&& cu
->language
== language_cplus
)
21877 gdb::unique_xmalloc_ptr
<char> canon_name
21878 = cp_canonicalize_string (name
);
21880 if (canon_name
!= nullptr)
21881 name
= objfile
->intern (canon_name
.get ());
21887 /* Get name of a die, return NULL if not found.
21888 Anonymous namespaces are converted to their magic string. */
21890 static const char *
21891 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21893 struct attribute
*attr
;
21894 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21896 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21897 if ((!attr
|| !DW_STRING (attr
))
21898 && die
->tag
!= DW_TAG_namespace
21899 && die
->tag
!= DW_TAG_class_type
21900 && die
->tag
!= DW_TAG_interface_type
21901 && die
->tag
!= DW_TAG_structure_type
21902 && die
->tag
!= DW_TAG_union_type
)
21907 case DW_TAG_compile_unit
:
21908 case DW_TAG_partial_unit
:
21909 /* Compilation units have a DW_AT_name that is a filename, not
21910 a source language identifier. */
21911 case DW_TAG_enumeration_type
:
21912 case DW_TAG_enumerator
:
21913 /* These tags always have simple identifiers already; no need
21914 to canonicalize them. */
21915 return DW_STRING (attr
);
21917 case DW_TAG_namespace
:
21918 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21919 return DW_STRING (attr
);
21920 return CP_ANONYMOUS_NAMESPACE_STR
;
21922 case DW_TAG_class_type
:
21923 case DW_TAG_interface_type
:
21924 case DW_TAG_structure_type
:
21925 case DW_TAG_union_type
:
21926 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21927 structures or unions. These were of the form "._%d" in GCC 4.1,
21928 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21929 and GCC 4.4. We work around this problem by ignoring these. */
21930 if (attr
&& DW_STRING (attr
)
21931 && (startswith (DW_STRING (attr
), "._")
21932 || startswith (DW_STRING (attr
), "<anonymous")))
21935 /* GCC might emit a nameless typedef that has a linkage name. See
21936 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21937 if (!attr
|| DW_STRING (attr
) == NULL
)
21939 attr
= dw2_linkage_name_attr (die
, cu
);
21940 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21943 /* Avoid demangling DW_STRING (attr) the second time on a second
21944 call for the same DIE. */
21945 if (!DW_STRING_IS_CANONICAL (attr
))
21947 gdb::unique_xmalloc_ptr
<char> demangled
21948 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21949 if (demangled
== nullptr)
21952 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21953 DW_STRING_IS_CANONICAL (attr
) = 1;
21956 /* Strip any leading namespaces/classes, keep only the base name.
21957 DW_AT_name for named DIEs does not contain the prefixes. */
21958 const char *base
= strrchr (DW_STRING (attr
), ':');
21959 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21962 return DW_STRING (attr
);
21970 if (!DW_STRING_IS_CANONICAL (attr
))
21972 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21974 DW_STRING_IS_CANONICAL (attr
) = 1;
21976 return DW_STRING (attr
);
21979 /* Return the die that this die in an extension of, or NULL if there
21980 is none. *EXT_CU is the CU containing DIE on input, and the CU
21981 containing the return value on output. */
21983 static struct die_info
*
21984 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21986 struct attribute
*attr
;
21988 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21992 return follow_die_ref (die
, attr
, ext_cu
);
21996 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22000 print_spaces (indent
, f
);
22001 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22002 dwarf_tag_name (die
->tag
), die
->abbrev
,
22003 sect_offset_str (die
->sect_off
));
22005 if (die
->parent
!= NULL
)
22007 print_spaces (indent
, f
);
22008 fprintf_unfiltered (f
, " parent at offset: %s\n",
22009 sect_offset_str (die
->parent
->sect_off
));
22012 print_spaces (indent
, f
);
22013 fprintf_unfiltered (f
, " has children: %s\n",
22014 dwarf_bool_name (die
->child
!= NULL
));
22016 print_spaces (indent
, f
);
22017 fprintf_unfiltered (f
, " attributes:\n");
22019 for (i
= 0; i
< die
->num_attrs
; ++i
)
22021 print_spaces (indent
, f
);
22022 fprintf_unfiltered (f
, " %s (%s) ",
22023 dwarf_attr_name (die
->attrs
[i
].name
),
22024 dwarf_form_name (die
->attrs
[i
].form
));
22026 switch (die
->attrs
[i
].form
)
22029 case DW_FORM_addrx
:
22030 case DW_FORM_GNU_addr_index
:
22031 fprintf_unfiltered (f
, "address: ");
22032 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22034 case DW_FORM_block2
:
22035 case DW_FORM_block4
:
22036 case DW_FORM_block
:
22037 case DW_FORM_block1
:
22038 fprintf_unfiltered (f
, "block: size %s",
22039 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22041 case DW_FORM_exprloc
:
22042 fprintf_unfiltered (f
, "expression: size %s",
22043 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22045 case DW_FORM_data16
:
22046 fprintf_unfiltered (f
, "constant of 16 bytes");
22048 case DW_FORM_ref_addr
:
22049 fprintf_unfiltered (f
, "ref address: ");
22050 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22052 case DW_FORM_GNU_ref_alt
:
22053 fprintf_unfiltered (f
, "alt ref address: ");
22054 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22060 case DW_FORM_ref_udata
:
22061 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22062 (long) (DW_UNSND (&die
->attrs
[i
])));
22064 case DW_FORM_data1
:
22065 case DW_FORM_data2
:
22066 case DW_FORM_data4
:
22067 case DW_FORM_data8
:
22068 case DW_FORM_udata
:
22069 case DW_FORM_sdata
:
22070 fprintf_unfiltered (f
, "constant: %s",
22071 pulongest (DW_UNSND (&die
->attrs
[i
])));
22073 case DW_FORM_sec_offset
:
22074 fprintf_unfiltered (f
, "section offset: %s",
22075 pulongest (DW_UNSND (&die
->attrs
[i
])));
22077 case DW_FORM_ref_sig8
:
22078 fprintf_unfiltered (f
, "signature: %s",
22079 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22081 case DW_FORM_string
:
22083 case DW_FORM_line_strp
:
22085 case DW_FORM_GNU_str_index
:
22086 case DW_FORM_GNU_strp_alt
:
22087 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22088 DW_STRING (&die
->attrs
[i
])
22089 ? DW_STRING (&die
->attrs
[i
]) : "",
22090 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22093 if (DW_UNSND (&die
->attrs
[i
]))
22094 fprintf_unfiltered (f
, "flag: TRUE");
22096 fprintf_unfiltered (f
, "flag: FALSE");
22098 case DW_FORM_flag_present
:
22099 fprintf_unfiltered (f
, "flag: TRUE");
22101 case DW_FORM_indirect
:
22102 /* The reader will have reduced the indirect form to
22103 the "base form" so this form should not occur. */
22104 fprintf_unfiltered (f
,
22105 "unexpected attribute form: DW_FORM_indirect");
22107 case DW_FORM_implicit_const
:
22108 fprintf_unfiltered (f
, "constant: %s",
22109 plongest (DW_SND (&die
->attrs
[i
])));
22112 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22113 die
->attrs
[i
].form
);
22116 fprintf_unfiltered (f
, "\n");
22121 dump_die_for_error (struct die_info
*die
)
22123 dump_die_shallow (gdb_stderr
, 0, die
);
22127 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22129 int indent
= level
* 4;
22131 gdb_assert (die
!= NULL
);
22133 if (level
>= max_level
)
22136 dump_die_shallow (f
, indent
, die
);
22138 if (die
->child
!= NULL
)
22140 print_spaces (indent
, f
);
22141 fprintf_unfiltered (f
, " Children:");
22142 if (level
+ 1 < max_level
)
22144 fprintf_unfiltered (f
, "\n");
22145 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22149 fprintf_unfiltered (f
,
22150 " [not printed, max nesting level reached]\n");
22154 if (die
->sibling
!= NULL
&& level
> 0)
22156 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22160 /* This is called from the pdie macro in gdbinit.in.
22161 It's not static so gcc will keep a copy callable from gdb. */
22164 dump_die (struct die_info
*die
, int max_level
)
22166 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22170 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22174 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22175 to_underlying (die
->sect_off
),
22181 /* Follow reference or signature attribute ATTR of SRC_DIE.
22182 On entry *REF_CU is the CU of SRC_DIE.
22183 On exit *REF_CU is the CU of the result. */
22185 static struct die_info
*
22186 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22187 struct dwarf2_cu
**ref_cu
)
22189 struct die_info
*die
;
22191 if (attr
->form_is_ref ())
22192 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22193 else if (attr
->form
== DW_FORM_ref_sig8
)
22194 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22197 dump_die_for_error (src_die
);
22198 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22199 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22205 /* Follow reference OFFSET.
22206 On entry *REF_CU is the CU of the source die referencing OFFSET.
22207 On exit *REF_CU is the CU of the result.
22208 Returns NULL if OFFSET is invalid. */
22210 static struct die_info
*
22211 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22212 struct dwarf2_cu
**ref_cu
)
22214 struct die_info temp_die
;
22215 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22216 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22218 gdb_assert (cu
->per_cu
!= NULL
);
22222 if (cu
->per_cu
->is_debug_types
)
22224 /* .debug_types CUs cannot reference anything outside their CU.
22225 If they need to, they have to reference a signatured type via
22226 DW_FORM_ref_sig8. */
22227 if (!cu
->header
.offset_in_cu_p (sect_off
))
22230 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22231 || !cu
->header
.offset_in_cu_p (sect_off
))
22233 struct dwarf2_per_cu_data
*per_cu
;
22235 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22236 dwarf2_per_objfile
);
22238 /* If necessary, add it to the queue and load its DIEs. */
22239 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22240 load_full_comp_unit (per_cu
, dwarf2_per_objfile
, false, cu
->language
);
22242 target_cu
= per_cu
->cu
;
22244 else if (cu
->dies
== NULL
)
22246 /* We're loading full DIEs during partial symbol reading. */
22247 gdb_assert (dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
);
22248 load_full_comp_unit (cu
->per_cu
, dwarf2_per_objfile
, false,
22252 *ref_cu
= target_cu
;
22253 temp_die
.sect_off
= sect_off
;
22255 if (target_cu
!= cu
)
22256 target_cu
->ancestor
= cu
;
22258 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22260 to_underlying (sect_off
));
22263 /* Follow reference attribute ATTR of SRC_DIE.
22264 On entry *REF_CU is the CU of SRC_DIE.
22265 On exit *REF_CU is the CU of the result. */
22267 static struct die_info
*
22268 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22269 struct dwarf2_cu
**ref_cu
)
22271 sect_offset sect_off
= attr
->get_ref_die_offset ();
22272 struct dwarf2_cu
*cu
= *ref_cu
;
22273 struct die_info
*die
;
22275 die
= follow_die_offset (sect_off
,
22276 (attr
->form
== DW_FORM_GNU_ref_alt
22277 || cu
->per_cu
->is_dwz
),
22280 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22281 "at %s [in module %s]"),
22282 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22283 objfile_name (cu
->per_objfile
->objfile
));
22290 struct dwarf2_locexpr_baton
22291 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22292 dwarf2_per_cu_data
*per_cu
,
22293 CORE_ADDR (*get_frame_pc
) (void *baton
),
22294 void *baton
, bool resolve_abstract_p
)
22296 struct dwarf2_cu
*cu
;
22297 struct die_info
*die
;
22298 struct attribute
*attr
;
22299 struct dwarf2_locexpr_baton retval
;
22300 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22301 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22303 if (per_cu
->cu
== NULL
)
22304 load_cu (per_cu
, dwarf2_per_objfile
, false);
22308 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22309 Instead just throw an error, not much else we can do. */
22310 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22311 sect_offset_str (sect_off
), objfile_name (objfile
));
22314 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22316 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22317 sect_offset_str (sect_off
), objfile_name (objfile
));
22319 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22320 if (!attr
&& resolve_abstract_p
22321 && (dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22322 != dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22324 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22325 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22326 struct gdbarch
*gdbarch
= objfile
->arch ();
22328 for (const auto &cand_off
22329 : dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22331 struct dwarf2_cu
*cand_cu
= cu
;
22332 struct die_info
*cand
22333 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22336 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22339 CORE_ADDR pc_low
, pc_high
;
22340 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22341 if (pc_low
== ((CORE_ADDR
) -1))
22343 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22344 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22345 if (!(pc_low
<= pc
&& pc
< pc_high
))
22349 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22356 /* DWARF: "If there is no such attribute, then there is no effect.".
22357 DATA is ignored if SIZE is 0. */
22359 retval
.data
= NULL
;
22362 else if (attr
->form_is_section_offset ())
22364 struct dwarf2_loclist_baton loclist_baton
;
22365 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22368 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22370 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22372 retval
.size
= size
;
22376 if (!attr
->form_is_block ())
22377 error (_("Dwarf Error: DIE at %s referenced in module %s "
22378 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22379 sect_offset_str (sect_off
), objfile_name (objfile
));
22381 retval
.data
= DW_BLOCK (attr
)->data
;
22382 retval
.size
= DW_BLOCK (attr
)->size
;
22384 retval
.per_objfile
= dwarf2_per_objfile
;
22385 retval
.per_cu
= cu
->per_cu
;
22387 age_cached_comp_units (dwarf2_per_objfile
);
22394 struct dwarf2_locexpr_baton
22395 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22396 dwarf2_per_cu_data
*per_cu
,
22397 CORE_ADDR (*get_frame_pc
) (void *baton
),
22400 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22402 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22405 /* Write a constant of a given type as target-ordered bytes into
22408 static const gdb_byte
*
22409 write_constant_as_bytes (struct obstack
*obstack
,
22410 enum bfd_endian byte_order
,
22417 *len
= TYPE_LENGTH (type
);
22418 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22419 store_unsigned_integer (result
, *len
, byte_order
, value
);
22427 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22428 dwarf2_per_cu_data
*per_cu
,
22432 struct dwarf2_cu
*cu
;
22433 struct die_info
*die
;
22434 struct attribute
*attr
;
22435 const gdb_byte
*result
= NULL
;
22438 enum bfd_endian byte_order
;
22439 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22441 if (per_cu
->cu
== NULL
)
22442 load_cu (per_cu
, per_cu
->dwarf2_per_objfile
, false);
22446 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22447 Instead just throw an error, not much else we can do. */
22448 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22449 sect_offset_str (sect_off
), objfile_name (objfile
));
22452 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22454 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22455 sect_offset_str (sect_off
), objfile_name (objfile
));
22457 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22461 byte_order
= (bfd_big_endian (objfile
->obfd
)
22462 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22464 switch (attr
->form
)
22467 case DW_FORM_addrx
:
22468 case DW_FORM_GNU_addr_index
:
22472 *len
= cu
->header
.addr_size
;
22473 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22474 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22478 case DW_FORM_string
:
22481 case DW_FORM_GNU_str_index
:
22482 case DW_FORM_GNU_strp_alt
:
22483 /* DW_STRING is already allocated on the objfile obstack, point
22485 result
= (const gdb_byte
*) DW_STRING (attr
);
22486 *len
= strlen (DW_STRING (attr
));
22488 case DW_FORM_block1
:
22489 case DW_FORM_block2
:
22490 case DW_FORM_block4
:
22491 case DW_FORM_block
:
22492 case DW_FORM_exprloc
:
22493 case DW_FORM_data16
:
22494 result
= DW_BLOCK (attr
)->data
;
22495 *len
= DW_BLOCK (attr
)->size
;
22498 /* The DW_AT_const_value attributes are supposed to carry the
22499 symbol's value "represented as it would be on the target
22500 architecture." By the time we get here, it's already been
22501 converted to host endianness, so we just need to sign- or
22502 zero-extend it as appropriate. */
22503 case DW_FORM_data1
:
22504 type
= die_type (die
, cu
);
22505 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22506 if (result
== NULL
)
22507 result
= write_constant_as_bytes (obstack
, byte_order
,
22510 case DW_FORM_data2
:
22511 type
= die_type (die
, cu
);
22512 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22513 if (result
== NULL
)
22514 result
= write_constant_as_bytes (obstack
, byte_order
,
22517 case DW_FORM_data4
:
22518 type
= die_type (die
, cu
);
22519 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22520 if (result
== NULL
)
22521 result
= write_constant_as_bytes (obstack
, byte_order
,
22524 case DW_FORM_data8
:
22525 type
= die_type (die
, cu
);
22526 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22527 if (result
== NULL
)
22528 result
= write_constant_as_bytes (obstack
, byte_order
,
22532 case DW_FORM_sdata
:
22533 case DW_FORM_implicit_const
:
22534 type
= die_type (die
, cu
);
22535 result
= write_constant_as_bytes (obstack
, byte_order
,
22536 type
, DW_SND (attr
), len
);
22539 case DW_FORM_udata
:
22540 type
= die_type (die
, cu
);
22541 result
= write_constant_as_bytes (obstack
, byte_order
,
22542 type
, DW_UNSND (attr
), len
);
22546 complaint (_("unsupported const value attribute form: '%s'"),
22547 dwarf_form_name (attr
->form
));
22557 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22558 dwarf2_per_cu_data
*per_cu
)
22560 struct dwarf2_cu
*cu
;
22561 struct die_info
*die
;
22563 if (per_cu
->cu
== NULL
)
22564 load_cu (per_cu
, per_cu
->dwarf2_per_objfile
, false);
22569 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22573 return die_type (die
, cu
);
22579 dwarf2_get_die_type (cu_offset die_offset
,
22580 struct dwarf2_per_cu_data
*per_cu
)
22582 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22583 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22586 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22587 On entry *REF_CU is the CU of SRC_DIE.
22588 On exit *REF_CU is the CU of the result.
22589 Returns NULL if the referenced DIE isn't found. */
22591 static struct die_info
*
22592 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22593 struct dwarf2_cu
**ref_cu
)
22595 struct die_info temp_die
;
22596 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22597 struct die_info
*die
;
22599 /* While it might be nice to assert sig_type->type == NULL here,
22600 we can get here for DW_AT_imported_declaration where we need
22601 the DIE not the type. */
22603 /* If necessary, add it to the queue and load its DIEs. */
22605 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22606 read_signatured_type (sig_type
, (*ref_cu
)->per_objfile
);
22608 sig_cu
= sig_type
->per_cu
.cu
;
22609 gdb_assert (sig_cu
!= NULL
);
22610 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22611 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22612 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22613 to_underlying (temp_die
.sect_off
));
22616 struct dwarf2_per_objfile
*dwarf2_per_objfile
= (*ref_cu
)->per_objfile
;
22618 /* For .gdb_index version 7 keep track of included TUs.
22619 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22620 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
22621 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7)
22623 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22628 sig_cu
->ancestor
= cu
;
22636 /* Follow signatured type referenced by ATTR in SRC_DIE.
22637 On entry *REF_CU is the CU of SRC_DIE.
22638 On exit *REF_CU is the CU of the result.
22639 The result is the DIE of the type.
22640 If the referenced type cannot be found an error is thrown. */
22642 static struct die_info
*
22643 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22644 struct dwarf2_cu
**ref_cu
)
22646 ULONGEST signature
= DW_SIGNATURE (attr
);
22647 struct signatured_type
*sig_type
;
22648 struct die_info
*die
;
22650 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22652 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22653 /* sig_type will be NULL if the signatured type is missing from
22655 if (sig_type
== NULL
)
22657 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22658 " from DIE at %s [in module %s]"),
22659 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22660 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22663 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22666 dump_die_for_error (src_die
);
22667 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22668 " from DIE at %s [in module %s]"),
22669 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22670 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22676 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22677 reading in and processing the type unit if necessary. */
22679 static struct type
*
22680 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22681 struct dwarf2_cu
*cu
)
22683 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22684 struct signatured_type
*sig_type
;
22685 struct dwarf2_cu
*type_cu
;
22686 struct die_info
*type_die
;
22689 sig_type
= lookup_signatured_type (cu
, signature
);
22690 /* sig_type will be NULL if the signatured type is missing from
22692 if (sig_type
== NULL
)
22694 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22695 " from DIE at %s [in module %s]"),
22696 hex_string (signature
), sect_offset_str (die
->sect_off
),
22697 objfile_name (dwarf2_per_objfile
->objfile
));
22698 return build_error_marker_type (cu
, die
);
22701 /* If we already know the type we're done. */
22702 if (sig_type
->type
!= NULL
)
22703 return sig_type
->type
;
22706 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22707 if (type_die
!= NULL
)
22709 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22710 is created. This is important, for example, because for c++ classes
22711 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22712 type
= read_type_die (type_die
, type_cu
);
22715 complaint (_("Dwarf Error: Cannot build signatured type %s"
22716 " referenced from DIE at %s [in module %s]"),
22717 hex_string (signature
), sect_offset_str (die
->sect_off
),
22718 objfile_name (dwarf2_per_objfile
->objfile
));
22719 type
= build_error_marker_type (cu
, die
);
22724 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22725 " from DIE at %s [in module %s]"),
22726 hex_string (signature
), sect_offset_str (die
->sect_off
),
22727 objfile_name (dwarf2_per_objfile
->objfile
));
22728 type
= build_error_marker_type (cu
, die
);
22730 sig_type
->type
= type
;
22735 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22736 reading in and processing the type unit if necessary. */
22738 static struct type
*
22739 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22740 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22742 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22743 if (attr
->form_is_ref ())
22745 struct dwarf2_cu
*type_cu
= cu
;
22746 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22748 return read_type_die (type_die
, type_cu
);
22750 else if (attr
->form
== DW_FORM_ref_sig8
)
22752 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22756 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22758 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22759 " at %s [in module %s]"),
22760 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22761 objfile_name (dwarf2_per_objfile
->objfile
));
22762 return build_error_marker_type (cu
, die
);
22766 /* Load the DIEs associated with type unit PER_CU into memory. */
22769 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22770 dwarf2_per_objfile
*per_objfile
)
22772 struct signatured_type
*sig_type
;
22774 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22775 gdb_assert (! per_cu
->type_unit_group_p ());
22777 /* We have the per_cu, but we need the signatured_type.
22778 Fortunately this is an easy translation. */
22779 gdb_assert (per_cu
->is_debug_types
);
22780 sig_type
= (struct signatured_type
*) per_cu
;
22782 gdb_assert (per_cu
->cu
== NULL
);
22784 read_signatured_type (sig_type
, per_objfile
);
22786 gdb_assert (per_cu
->cu
!= NULL
);
22789 /* Read in a signatured type and build its CU and DIEs.
22790 If the type is a stub for the real type in a DWO file,
22791 read in the real type from the DWO file as well. */
22794 read_signatured_type (signatured_type
*sig_type
,
22795 dwarf2_per_objfile
*per_objfile
)
22797 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22799 gdb_assert (per_cu
->is_debug_types
);
22800 gdb_assert (per_cu
->cu
== NULL
);
22802 cutu_reader
reader (per_cu
, per_objfile
, NULL
, 0, false);
22804 if (!reader
.dummy_p
)
22806 struct dwarf2_cu
*cu
= reader
.cu
;
22807 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22809 gdb_assert (cu
->die_hash
== NULL
);
22811 htab_create_alloc_ex (cu
->header
.length
/ 12,
22815 &cu
->comp_unit_obstack
,
22816 hashtab_obstack_allocate
,
22817 dummy_obstack_deallocate
);
22819 if (reader
.comp_unit_die
->has_children
)
22820 reader
.comp_unit_die
->child
22821 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22822 reader
.comp_unit_die
);
22823 cu
->dies
= reader
.comp_unit_die
;
22824 /* comp_unit_die is not stored in die_hash, no need. */
22826 /* We try not to read any attributes in this function, because
22827 not all CUs needed for references have been loaded yet, and
22828 symbol table processing isn't initialized. But we have to
22829 set the CU language, or we won't be able to build types
22830 correctly. Similarly, if we do not read the producer, we can
22831 not apply producer-specific interpretation. */
22832 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22837 sig_type
->per_cu
.tu_read
= 1;
22840 /* Decode simple location descriptions.
22841 Given a pointer to a dwarf block that defines a location, compute
22842 the location and return the value. If COMPUTED is non-null, it is
22843 set to true to indicate that decoding was successful, and false
22844 otherwise. If COMPUTED is null, then this function may emit a
22848 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22850 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22852 size_t size
= blk
->size
;
22853 const gdb_byte
*data
= blk
->data
;
22854 CORE_ADDR stack
[64];
22856 unsigned int bytes_read
, unsnd
;
22859 if (computed
!= nullptr)
22865 stack
[++stacki
] = 0;
22904 stack
[++stacki
] = op
- DW_OP_lit0
;
22939 stack
[++stacki
] = op
- DW_OP_reg0
;
22942 if (computed
== nullptr)
22943 dwarf2_complex_location_expr_complaint ();
22950 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22952 stack
[++stacki
] = unsnd
;
22955 if (computed
== nullptr)
22956 dwarf2_complex_location_expr_complaint ();
22963 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22968 case DW_OP_const1u
:
22969 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22973 case DW_OP_const1s
:
22974 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22978 case DW_OP_const2u
:
22979 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22983 case DW_OP_const2s
:
22984 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22988 case DW_OP_const4u
:
22989 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22993 case DW_OP_const4s
:
22994 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22998 case DW_OP_const8u
:
22999 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23004 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23010 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23015 stack
[stacki
+ 1] = stack
[stacki
];
23020 stack
[stacki
- 1] += stack
[stacki
];
23024 case DW_OP_plus_uconst
:
23025 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23031 stack
[stacki
- 1] -= stack
[stacki
];
23036 /* If we're not the last op, then we definitely can't encode
23037 this using GDB's address_class enum. This is valid for partial
23038 global symbols, although the variable's address will be bogus
23042 if (computed
== nullptr)
23043 dwarf2_complex_location_expr_complaint ();
23049 case DW_OP_GNU_push_tls_address
:
23050 case DW_OP_form_tls_address
:
23051 /* The top of the stack has the offset from the beginning
23052 of the thread control block at which the variable is located. */
23053 /* Nothing should follow this operator, so the top of stack would
23055 /* This is valid for partial global symbols, but the variable's
23056 address will be bogus in the psymtab. Make it always at least
23057 non-zero to not look as a variable garbage collected by linker
23058 which have DW_OP_addr 0. */
23061 if (computed
== nullptr)
23062 dwarf2_complex_location_expr_complaint ();
23069 case DW_OP_GNU_uninit
:
23070 if (computed
!= nullptr)
23075 case DW_OP_GNU_addr_index
:
23076 case DW_OP_GNU_const_index
:
23077 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23083 if (computed
== nullptr)
23085 const char *name
= get_DW_OP_name (op
);
23088 complaint (_("unsupported stack op: '%s'"),
23091 complaint (_("unsupported stack op: '%02x'"),
23095 return (stack
[stacki
]);
23098 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23099 outside of the allocated space. Also enforce minimum>0. */
23100 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23102 if (computed
== nullptr)
23103 complaint (_("location description stack overflow"));
23109 if (computed
== nullptr)
23110 complaint (_("location description stack underflow"));
23115 if (computed
!= nullptr)
23117 return (stack
[stacki
]);
23120 /* memory allocation interface */
23122 static struct dwarf_block
*
23123 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23125 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23128 static struct die_info
*
23129 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23131 struct die_info
*die
;
23132 size_t size
= sizeof (struct die_info
);
23135 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23137 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23138 memset (die
, 0, sizeof (struct die_info
));
23144 /* Macro support. */
23146 /* An overload of dwarf_decode_macros that finds the correct section
23147 and ensures it is read in before calling the other overload. */
23150 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23151 int section_is_gnu
)
23153 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23154 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23155 const struct line_header
*lh
= cu
->line_header
;
23156 unsigned int offset_size
= cu
->header
.offset_size
;
23157 struct dwarf2_section_info
*section
;
23158 const char *section_name
;
23160 if (cu
->dwo_unit
!= nullptr)
23162 if (section_is_gnu
)
23164 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23165 section_name
= ".debug_macro.dwo";
23169 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23170 section_name
= ".debug_macinfo.dwo";
23175 if (section_is_gnu
)
23177 section
= &dwarf2_per_objfile
->per_bfd
->macro
;
23178 section_name
= ".debug_macro";
23182 section
= &dwarf2_per_objfile
->per_bfd
->macinfo
;
23183 section_name
= ".debug_macinfo";
23187 section
->read (objfile
);
23188 if (section
->buffer
== nullptr)
23190 complaint (_("missing %s section"), section_name
);
23194 buildsym_compunit
*builder
= cu
->get_builder ();
23196 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23197 offset_size
, offset
, section_is_gnu
);
23200 /* Return the .debug_loc section to use for CU.
23201 For DWO files use .debug_loc.dwo. */
23203 static struct dwarf2_section_info
*
23204 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23206 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23210 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23212 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23214 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->per_bfd
->loclists
23215 : &dwarf2_per_objfile
->per_bfd
->loc
);
23218 /* A helper function that fills in a dwarf2_loclist_baton. */
23221 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23222 struct dwarf2_loclist_baton
*baton
,
23223 const struct attribute
*attr
)
23225 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23226 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23228 section
->read (dwarf2_per_objfile
->objfile
);
23230 baton
->per_objfile
= dwarf2_per_objfile
;
23231 baton
->per_cu
= cu
->per_cu
;
23232 gdb_assert (baton
->per_cu
);
23233 /* We don't know how long the location list is, but make sure we
23234 don't run off the edge of the section. */
23235 baton
->size
= section
->size
- DW_UNSND (attr
);
23236 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23237 if (cu
->base_address
.has_value ())
23238 baton
->base_address
= *cu
->base_address
;
23240 baton
->base_address
= 0;
23241 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23245 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23246 struct dwarf2_cu
*cu
, int is_block
)
23248 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23249 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23250 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23252 if (attr
->form_is_section_offset ()
23253 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23254 the section. If so, fall through to the complaint in the
23256 && DW_UNSND (attr
) < section
->get_size (objfile
))
23258 struct dwarf2_loclist_baton
*baton
;
23260 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23262 fill_in_loclist_baton (cu
, baton
, attr
);
23264 if (!cu
->base_address
.has_value ())
23265 complaint (_("Location list used without "
23266 "specifying the CU base address."));
23268 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23269 ? dwarf2_loclist_block_index
23270 : dwarf2_loclist_index
);
23271 SYMBOL_LOCATION_BATON (sym
) = baton
;
23275 struct dwarf2_locexpr_baton
*baton
;
23277 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23278 baton
->per_objfile
= dwarf2_per_objfile
;
23279 baton
->per_cu
= cu
->per_cu
;
23280 gdb_assert (baton
->per_cu
);
23282 if (attr
->form_is_block ())
23284 /* Note that we're just copying the block's data pointer
23285 here, not the actual data. We're still pointing into the
23286 info_buffer for SYM's objfile; right now we never release
23287 that buffer, but when we do clean up properly this may
23289 baton
->size
= DW_BLOCK (attr
)->size
;
23290 baton
->data
= DW_BLOCK (attr
)->data
;
23294 dwarf2_invalid_attrib_class_complaint ("location description",
23295 sym
->natural_name ());
23299 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23300 ? dwarf2_locexpr_block_index
23301 : dwarf2_locexpr_index
);
23302 SYMBOL_LOCATION_BATON (sym
) = baton
;
23309 dwarf2_per_cu_data::objfile () const
23311 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23313 /* Return the master objfile, so that we can report and look up the
23314 correct file containing this variable. */
23315 if (objfile
->separate_debug_objfile_backlink
)
23316 objfile
= objfile
->separate_debug_objfile_backlink
;
23321 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
23322 (CU_HEADERP is unused in such case) or prepare a temporary copy at
23323 CU_HEADERP first. */
23325 static const struct comp_unit_head
*
23326 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
23327 const struct dwarf2_per_cu_data
*per_cu
)
23329 const gdb_byte
*info_ptr
;
23332 return &per_cu
->cu
->header
;
23334 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
23336 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
23337 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
23338 rcuh_kind::COMPILE
);
23346 dwarf2_per_cu_data::addr_size () const
23348 struct comp_unit_head cu_header_local
;
23349 const struct comp_unit_head
*cu_headerp
;
23351 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23353 return cu_headerp
->addr_size
;
23359 dwarf2_per_cu_data::offset_size () const
23361 struct comp_unit_head cu_header_local
;
23362 const struct comp_unit_head
*cu_headerp
;
23364 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23366 return cu_headerp
->offset_size
;
23372 dwarf2_per_cu_data::ref_addr_size () const
23374 struct comp_unit_head cu_header_local
;
23375 const struct comp_unit_head
*cu_headerp
;
23377 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23379 if (cu_headerp
->version
== 2)
23380 return cu_headerp
->addr_size
;
23382 return cu_headerp
->offset_size
;
23388 dwarf2_per_cu_data::text_offset () const
23390 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23392 return objfile
->text_section_offset ();
23398 dwarf2_per_cu_data::addr_type () const
23400 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23401 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23402 struct type
*addr_type
= lookup_pointer_type (void_type
);
23403 int addr_size
= this->addr_size ();
23405 if (TYPE_LENGTH (addr_type
) == addr_size
)
23408 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23412 /* A helper function for dwarf2_find_containing_comp_unit that returns
23413 the index of the result, and that searches a vector. It will
23414 return a result even if the offset in question does not actually
23415 occur in any CU. This is separate so that it can be unit
23419 dwarf2_find_containing_comp_unit
23420 (sect_offset sect_off
,
23421 unsigned int offset_in_dwz
,
23422 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23427 high
= all_comp_units
.size () - 1;
23430 struct dwarf2_per_cu_data
*mid_cu
;
23431 int mid
= low
+ (high
- low
) / 2;
23433 mid_cu
= all_comp_units
[mid
];
23434 if (mid_cu
->is_dwz
> offset_in_dwz
23435 || (mid_cu
->is_dwz
== offset_in_dwz
23436 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23441 gdb_assert (low
== high
);
23445 /* Locate the .debug_info compilation unit from CU's objfile which contains
23446 the DIE at OFFSET. Raises an error on failure. */
23448 static struct dwarf2_per_cu_data
*
23449 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23450 unsigned int offset_in_dwz
,
23451 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23454 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23455 dwarf2_per_objfile
->per_bfd
->all_comp_units
);
23456 struct dwarf2_per_cu_data
*this_cu
23457 = dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
];
23459 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23461 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23462 error (_("Dwarf Error: could not find partial DIE containing "
23463 "offset %s [in module %s]"),
23464 sect_offset_str (sect_off
),
23465 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23467 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23469 return dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1];
23473 if (low
== dwarf2_per_objfile
->per_bfd
->all_comp_units
.size () - 1
23474 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23475 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23476 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23483 namespace selftests
{
23484 namespace find_containing_comp_unit
{
23489 struct dwarf2_per_cu_data one
{};
23490 struct dwarf2_per_cu_data two
{};
23491 struct dwarf2_per_cu_data three
{};
23492 struct dwarf2_per_cu_data four
{};
23495 two
.sect_off
= sect_offset (one
.length
);
23500 four
.sect_off
= sect_offset (three
.length
);
23504 std::vector
<dwarf2_per_cu_data
*> units
;
23505 units
.push_back (&one
);
23506 units
.push_back (&two
);
23507 units
.push_back (&three
);
23508 units
.push_back (&four
);
23512 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23513 SELF_CHECK (units
[result
] == &one
);
23514 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23515 SELF_CHECK (units
[result
] == &one
);
23516 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23517 SELF_CHECK (units
[result
] == &two
);
23519 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23520 SELF_CHECK (units
[result
] == &three
);
23521 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23522 SELF_CHECK (units
[result
] == &three
);
23523 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23524 SELF_CHECK (units
[result
] == &four
);
23530 #endif /* GDB_SELF_TEST */
23532 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23534 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23535 dwarf2_per_objfile
*per_objfile
)
23537 per_objfile (per_objfile
),
23539 has_loclist (false),
23540 checked_producer (false),
23541 producer_is_gxx_lt_4_6 (false),
23542 producer_is_gcc_lt_4_3 (false),
23543 producer_is_icc (false),
23544 producer_is_icc_lt_14 (false),
23545 producer_is_codewarrior (false),
23546 processing_has_namespace_info (false)
23551 /* Destroy a dwarf2_cu. */
23553 dwarf2_cu::~dwarf2_cu ()
23558 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23561 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23562 enum language pretend_language
)
23564 struct attribute
*attr
;
23566 /* Set the language we're debugging. */
23567 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23568 if (attr
!= nullptr)
23569 set_cu_language (DW_UNSND (attr
), cu
);
23572 cu
->language
= pretend_language
;
23573 cu
->language_defn
= language_def (cu
->language
);
23576 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23579 /* Increase the age counter on each cached compilation unit, and free
23580 any that are too old. */
23583 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23585 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23587 dwarf2_clear_marks (dwarf2_per_objfile
->per_bfd
->read_in_chain
);
23588 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23589 while (per_cu
!= NULL
)
23591 per_cu
->cu
->last_used
++;
23592 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23593 dwarf2_mark (per_cu
->cu
);
23594 per_cu
= per_cu
->cu
->read_in_chain
;
23597 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23598 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23599 while (per_cu
!= NULL
)
23601 struct dwarf2_per_cu_data
*next_cu
;
23603 next_cu
= per_cu
->cu
->read_in_chain
;
23605 if (!per_cu
->cu
->mark
)
23608 *last_chain
= next_cu
;
23611 last_chain
= &per_cu
->cu
->read_in_chain
;
23617 /* Remove a single compilation unit from the cache. */
23620 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23622 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23623 struct dwarf2_per_objfile
*dwarf2_per_objfile
23624 = target_per_cu
->dwarf2_per_objfile
;
23626 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23627 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23628 while (per_cu
!= NULL
)
23630 struct dwarf2_per_cu_data
*next_cu
;
23632 next_cu
= per_cu
->cu
->read_in_chain
;
23634 if (per_cu
== target_per_cu
)
23638 *last_chain
= next_cu
;
23642 last_chain
= &per_cu
->cu
->read_in_chain
;
23648 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23649 We store these in a hash table separate from the DIEs, and preserve them
23650 when the DIEs are flushed out of cache.
23652 The CU "per_cu" pointer is needed because offset alone is not enough to
23653 uniquely identify the type. A file may have multiple .debug_types sections,
23654 or the type may come from a DWO file. Furthermore, while it's more logical
23655 to use per_cu->section+offset, with Fission the section with the data is in
23656 the DWO file but we don't know that section at the point we need it.
23657 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23658 because we can enter the lookup routine, get_die_type_at_offset, from
23659 outside this file, and thus won't necessarily have PER_CU->cu.
23660 Fortunately, PER_CU is stable for the life of the objfile. */
23662 struct dwarf2_per_cu_offset_and_type
23664 const struct dwarf2_per_cu_data
*per_cu
;
23665 sect_offset sect_off
;
23669 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23672 per_cu_offset_and_type_hash (const void *item
)
23674 const struct dwarf2_per_cu_offset_and_type
*ofs
23675 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23677 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23680 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23683 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23685 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23686 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23687 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23688 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23690 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23691 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23694 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23695 table if necessary. For convenience, return TYPE.
23697 The DIEs reading must have careful ordering to:
23698 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23699 reading current DIE.
23700 * Not trying to dereference contents of still incompletely read in types
23701 while reading in other DIEs.
23702 * Enable referencing still incompletely read in types just by a pointer to
23703 the type without accessing its fields.
23705 Therefore caller should follow these rules:
23706 * Try to fetch any prerequisite types we may need to build this DIE type
23707 before building the type and calling set_die_type.
23708 * After building type call set_die_type for current DIE as soon as
23709 possible before fetching more types to complete the current type.
23710 * Make the type as complete as possible before fetching more types. */
23712 static struct type
*
23713 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23715 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23716 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23717 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23718 struct attribute
*attr
;
23719 struct dynamic_prop prop
;
23721 /* For Ada types, make sure that the gnat-specific data is always
23722 initialized (if not already set). There are a few types where
23723 we should not be doing so, because the type-specific area is
23724 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23725 where the type-specific area is used to store the floatformat).
23726 But this is not a problem, because the gnat-specific information
23727 is actually not needed for these types. */
23728 if (need_gnat_info (cu
)
23729 && type
->code () != TYPE_CODE_FUNC
23730 && type
->code () != TYPE_CODE_FLT
23731 && type
->code () != TYPE_CODE_METHODPTR
23732 && type
->code () != TYPE_CODE_MEMBERPTR
23733 && type
->code () != TYPE_CODE_METHOD
23734 && !HAVE_GNAT_AUX_INFO (type
))
23735 INIT_GNAT_SPECIFIC (type
);
23737 /* Read DW_AT_allocated and set in type. */
23738 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23739 if (attr
!= NULL
&& attr
->form_is_block ())
23741 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23742 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23743 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23745 else if (attr
!= NULL
)
23747 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23748 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23749 sect_offset_str (die
->sect_off
));
23752 /* Read DW_AT_associated and set in type. */
23753 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23754 if (attr
!= NULL
&& attr
->form_is_block ())
23756 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23757 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23758 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23760 else if (attr
!= NULL
)
23762 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23763 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23764 sect_offset_str (die
->sect_off
));
23767 /* Read DW_AT_data_location and set in type. */
23768 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23769 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23770 cu
->per_cu
->addr_type ()))
23771 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23773 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23774 dwarf2_per_objfile
->die_type_hash
23775 = htab_up (htab_create_alloc (127,
23776 per_cu_offset_and_type_hash
,
23777 per_cu_offset_and_type_eq
,
23778 NULL
, xcalloc
, xfree
));
23780 ofs
.per_cu
= cu
->per_cu
;
23781 ofs
.sect_off
= die
->sect_off
;
23783 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23784 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23786 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23787 sect_offset_str (die
->sect_off
));
23788 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23789 struct dwarf2_per_cu_offset_and_type
);
23794 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23795 or return NULL if the die does not have a saved type. */
23797 static struct type
*
23798 get_die_type_at_offset (sect_offset sect_off
,
23799 struct dwarf2_per_cu_data
*per_cu
)
23801 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23802 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23804 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23807 ofs
.per_cu
= per_cu
;
23808 ofs
.sect_off
= sect_off
;
23809 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23810 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23817 /* Look up the type for DIE in CU in die_type_hash,
23818 or return NULL if DIE does not have a saved type. */
23820 static struct type
*
23821 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23823 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23826 /* Add a dependence relationship from CU to REF_PER_CU. */
23829 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23830 struct dwarf2_per_cu_data
*ref_per_cu
)
23834 if (cu
->dependencies
== NULL
)
23836 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23837 NULL
, &cu
->comp_unit_obstack
,
23838 hashtab_obstack_allocate
,
23839 dummy_obstack_deallocate
);
23841 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23843 *slot
= ref_per_cu
;
23846 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23847 Set the mark field in every compilation unit in the
23848 cache that we must keep because we are keeping CU. */
23851 dwarf2_mark_helper (void **slot
, void *data
)
23853 struct dwarf2_per_cu_data
*per_cu
;
23855 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23857 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23858 reading of the chain. As such dependencies remain valid it is not much
23859 useful to track and undo them during QUIT cleanups. */
23860 if (per_cu
->cu
== NULL
)
23863 if (per_cu
->cu
->mark
)
23865 per_cu
->cu
->mark
= true;
23867 if (per_cu
->cu
->dependencies
!= NULL
)
23868 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23873 /* Set the mark field in CU and in every other compilation unit in the
23874 cache that we must keep because we are keeping CU. */
23877 dwarf2_mark (struct dwarf2_cu
*cu
)
23882 if (cu
->dependencies
!= NULL
)
23883 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23887 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23891 per_cu
->cu
->mark
= false;
23892 per_cu
= per_cu
->cu
->read_in_chain
;
23896 /* Trivial hash function for partial_die_info: the hash value of a DIE
23897 is its offset in .debug_info for this objfile. */
23900 partial_die_hash (const void *item
)
23902 const struct partial_die_info
*part_die
23903 = (const struct partial_die_info
*) item
;
23905 return to_underlying (part_die
->sect_off
);
23908 /* Trivial comparison function for partial_die_info structures: two DIEs
23909 are equal if they have the same offset. */
23912 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23914 const struct partial_die_info
*part_die_lhs
23915 = (const struct partial_die_info
*) item_lhs
;
23916 const struct partial_die_info
*part_die_rhs
23917 = (const struct partial_die_info
*) item_rhs
;
23919 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23922 struct cmd_list_element
*set_dwarf_cmdlist
;
23923 struct cmd_list_element
*show_dwarf_cmdlist
;
23926 show_check_physname (struct ui_file
*file
, int from_tty
,
23927 struct cmd_list_element
*c
, const char *value
)
23929 fprintf_filtered (file
,
23930 _("Whether to check \"physname\" is %s.\n"),
23934 void _initialize_dwarf2_read ();
23936 _initialize_dwarf2_read ()
23938 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
23939 Set DWARF specific variables.\n\
23940 Configure DWARF variables such as the cache size."),
23941 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23942 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23944 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
23945 Show DWARF specific variables.\n\
23946 Show DWARF variables such as the cache size."),
23947 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23948 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23950 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23951 &dwarf_max_cache_age
, _("\
23952 Set the upper bound on the age of cached DWARF compilation units."), _("\
23953 Show the upper bound on the age of cached DWARF compilation units."), _("\
23954 A higher limit means that cached compilation units will be stored\n\
23955 in memory longer, and more total memory will be used. Zero disables\n\
23956 caching, which can slow down startup."),
23958 show_dwarf_max_cache_age
,
23959 &set_dwarf_cmdlist
,
23960 &show_dwarf_cmdlist
);
23962 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23963 Set debugging of the DWARF reader."), _("\
23964 Show debugging of the DWARF reader."), _("\
23965 When enabled (non-zero), debugging messages are printed during DWARF\n\
23966 reading and symtab expansion. A value of 1 (one) provides basic\n\
23967 information. A value greater than 1 provides more verbose information."),
23970 &setdebuglist
, &showdebuglist
);
23972 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23973 Set debugging of the DWARF DIE reader."), _("\
23974 Show debugging of the DWARF DIE reader."), _("\
23975 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23976 The value is the maximum depth to print."),
23979 &setdebuglist
, &showdebuglist
);
23981 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23982 Set debugging of the dwarf line reader."), _("\
23983 Show debugging of the dwarf line reader."), _("\
23984 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23985 A value of 1 (one) provides basic information.\n\
23986 A value greater than 1 provides more verbose information."),
23989 &setdebuglist
, &showdebuglist
);
23991 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23992 Set cross-checking of \"physname\" code against demangler."), _("\
23993 Show cross-checking of \"physname\" code against demangler."), _("\
23994 When enabled, GDB's internal \"physname\" code is checked against\n\
23996 NULL
, show_check_physname
,
23997 &setdebuglist
, &showdebuglist
);
23999 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24000 no_class
, &use_deprecated_index_sections
, _("\
24001 Set whether to use deprecated gdb_index sections."), _("\
24002 Show whether to use deprecated gdb_index sections."), _("\
24003 When enabled, deprecated .gdb_index sections are used anyway.\n\
24004 Normally they are ignored either because of a missing feature or\n\
24005 performance issue.\n\
24006 Warning: This option must be enabled before gdb reads the file."),
24009 &setlist
, &showlist
);
24011 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24012 &dwarf2_locexpr_funcs
);
24013 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24014 &dwarf2_loclist_funcs
);
24016 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24017 &dwarf2_block_frame_base_locexpr_funcs
);
24018 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24019 &dwarf2_block_frame_base_loclist_funcs
);
24022 selftests::register_test ("dw2_expand_symtabs_matching",
24023 selftests::dw2_expand_symtabs_matching::run_test
);
24024 selftests::register_test ("dwarf2_find_containing_comp_unit",
24025 selftests::find_containing_comp_unit::run_test
);