1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
43 #include "dwarf2/stringify.h"
52 #include "gdb-demangle.h"
53 #include "filenames.h" /* for DOSish file names */
55 #include "complaints.h"
56 #include "dwarf2/expr.h"
57 #include "dwarf2/loc.h"
58 #include "cp-support.h"
64 #include "typeprint.h"
69 #include "gdbcore.h" /* for gnutarget */
70 #include "gdb/gdb-index.h"
75 #include "namespace.h"
76 #include "gdbsupport/function-view.h"
77 #include "gdbsupport/gdb_optional.h"
78 #include "gdbsupport/underlying.h"
79 #include "gdbsupport/hash_enum.h"
80 #include "filename-seen-cache.h"
84 #include <unordered_map>
85 #include "gdbsupport/selftest.h"
86 #include "rust-lang.h"
87 #include "gdbsupport/pathstuff.h"
88 #include "count-one-bits.h"
89 #include "debuginfod-support.h"
91 /* When == 1, print basic high level tracing messages.
92 When > 1, be more verbose.
93 This is in contrast to the low level DIE reading of dwarf_die_debug. */
94 static unsigned int dwarf_read_debug
= 0;
96 /* When non-zero, dump DIEs after they are read in. */
97 static unsigned int dwarf_die_debug
= 0;
99 /* When non-zero, dump line number entries as they are read in. */
100 unsigned int dwarf_line_debug
= 0;
102 /* When true, cross-check physname against demangler. */
103 static bool check_physname
= false;
105 /* When true, do not reject deprecated .gdb_index sections. */
106 static bool use_deprecated_index_sections
= false;
108 /* This is used to store the data that is always per objfile. */
109 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
111 /* These are used to store the dwarf2_per_bfd objects.
113 objfiles having the same BFD, which doesn't require relocations, are going to
114 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
116 Other objfiles are not going to share a dwarf2_per_bfd with any other
117 objfiles, so they'll have their own version kept in the _objfile_data_key
119 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
120 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
122 /* The "aclass" indices for various kinds of computed DWARF symbols. */
124 static int dwarf2_locexpr_index
;
125 static int dwarf2_loclist_index
;
126 static int dwarf2_locexpr_block_index
;
127 static int dwarf2_loclist_block_index
;
129 /* Size of .debug_loclists section header for 32-bit DWARF format. */
130 #define LOCLIST_HEADER_SIZE32 12
132 /* Size of .debug_loclists section header for 64-bit DWARF format. */
133 #define LOCLIST_HEADER_SIZE64 20
135 /* An index into a (C++) symbol name component in a symbol name as
136 recorded in the mapped_index's symbol table. For each C++ symbol
137 in the symbol table, we record one entry for the start of each
138 component in the symbol in a table of name components, and then
139 sort the table, in order to be able to binary search symbol names,
140 ignoring leading namespaces, both completion and regular look up.
141 For example, for symbol "A::B::C", we'll have an entry that points
142 to "A::B::C", another that points to "B::C", and another for "C".
143 Note that function symbols in GDB index have no parameter
144 information, just the function/method names. You can convert a
145 name_component to a "const char *" using the
146 'mapped_index::symbol_name_at(offset_type)' method. */
148 struct name_component
150 /* Offset in the symbol name where the component starts. Stored as
151 a (32-bit) offset instead of a pointer to save memory and improve
152 locality on 64-bit architectures. */
153 offset_type name_offset
;
155 /* The symbol's index in the symbol and constant pool tables of a
160 /* Base class containing bits shared by both .gdb_index and
161 .debug_name indexes. */
163 struct mapped_index_base
165 mapped_index_base () = default;
166 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
168 /* The name_component table (a sorted vector). See name_component's
169 description above. */
170 std::vector
<name_component
> name_components
;
172 /* How NAME_COMPONENTS is sorted. */
173 enum case_sensitivity name_components_casing
;
175 /* Return the number of names in the symbol table. */
176 virtual size_t symbol_name_count () const = 0;
178 /* Get the name of the symbol at IDX in the symbol table. */
179 virtual const char *symbol_name_at
180 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
182 /* Return whether the name at IDX in the symbol table should be
184 virtual bool symbol_name_slot_invalid (offset_type idx
) const
189 /* Build the symbol name component sorted vector, if we haven't
191 void build_name_components (dwarf2_per_objfile
*per_objfile
);
193 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
194 possible matches for LN_NO_PARAMS in the name component
196 std::pair
<std::vector
<name_component
>::const_iterator
,
197 std::vector
<name_component
>::const_iterator
>
198 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
200 dwarf2_per_objfile
*per_objfile
) const;
202 /* Prevent deleting/destroying via a base class pointer. */
204 ~mapped_index_base() = default;
207 /* A description of the mapped index. The file format is described in
208 a comment by the code that writes the index. */
209 struct mapped_index final
: public mapped_index_base
211 /* A slot/bucket in the symbol table hash. */
212 struct symbol_table_slot
214 const offset_type name
;
215 const offset_type vec
;
218 /* Index data format version. */
221 /* The address table data. */
222 gdb::array_view
<const gdb_byte
> address_table
;
224 /* The symbol table, implemented as a hash table. */
225 gdb::array_view
<symbol_table_slot
> symbol_table
;
227 /* A pointer to the constant pool. */
228 const char *constant_pool
= nullptr;
230 bool symbol_name_slot_invalid (offset_type idx
) const override
232 const auto &bucket
= this->symbol_table
[idx
];
233 return bucket
.name
== 0 && bucket
.vec
== 0;
236 /* Convenience method to get at the name of the symbol at IDX in the
238 const char *symbol_name_at
239 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
240 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
242 size_t symbol_name_count () const override
243 { return this->symbol_table
.size (); }
246 /* A description of the mapped .debug_names.
247 Uninitialized map has CU_COUNT 0. */
248 struct mapped_debug_names final
: public mapped_index_base
250 bfd_endian dwarf5_byte_order
;
251 bool dwarf5_is_dwarf64
;
252 bool augmentation_is_gdb
;
254 uint32_t cu_count
= 0;
255 uint32_t tu_count
, bucket_count
, name_count
;
256 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
257 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
258 const gdb_byte
*name_table_string_offs_reordered
;
259 const gdb_byte
*name_table_entry_offs_reordered
;
260 const gdb_byte
*entry_pool
;
267 /* Attribute name DW_IDX_*. */
270 /* Attribute form DW_FORM_*. */
273 /* Value if FORM is DW_FORM_implicit_const. */
274 LONGEST implicit_const
;
276 std::vector
<attr
> attr_vec
;
279 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
281 const char *namei_to_name
282 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
284 /* Implementation of the mapped_index_base virtual interface, for
285 the name_components cache. */
287 const char *symbol_name_at
288 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
289 { return namei_to_name (idx
, per_objfile
); }
291 size_t symbol_name_count () const override
292 { return this->name_count
; }
295 /* See dwarf2read.h. */
298 get_dwarf2_per_objfile (struct objfile
*objfile
)
300 return dwarf2_objfile_data_key
.get (objfile
);
303 /* Default names of the debugging sections. */
305 /* Note that if the debugging section has been compressed, it might
306 have a name like .zdebug_info. */
308 static const struct dwarf2_debug_sections dwarf2_elf_names
=
310 { ".debug_info", ".zdebug_info" },
311 { ".debug_abbrev", ".zdebug_abbrev" },
312 { ".debug_line", ".zdebug_line" },
313 { ".debug_loc", ".zdebug_loc" },
314 { ".debug_loclists", ".zdebug_loclists" },
315 { ".debug_macinfo", ".zdebug_macinfo" },
316 { ".debug_macro", ".zdebug_macro" },
317 { ".debug_str", ".zdebug_str" },
318 { ".debug_str_offsets", ".zdebug_str_offsets" },
319 { ".debug_line_str", ".zdebug_line_str" },
320 { ".debug_ranges", ".zdebug_ranges" },
321 { ".debug_rnglists", ".zdebug_rnglists" },
322 { ".debug_types", ".zdebug_types" },
323 { ".debug_addr", ".zdebug_addr" },
324 { ".debug_frame", ".zdebug_frame" },
325 { ".eh_frame", NULL
},
326 { ".gdb_index", ".zgdb_index" },
327 { ".debug_names", ".zdebug_names" },
328 { ".debug_aranges", ".zdebug_aranges" },
332 /* List of DWO/DWP sections. */
334 static const struct dwop_section_names
336 struct dwarf2_section_names abbrev_dwo
;
337 struct dwarf2_section_names info_dwo
;
338 struct dwarf2_section_names line_dwo
;
339 struct dwarf2_section_names loc_dwo
;
340 struct dwarf2_section_names loclists_dwo
;
341 struct dwarf2_section_names macinfo_dwo
;
342 struct dwarf2_section_names macro_dwo
;
343 struct dwarf2_section_names str_dwo
;
344 struct dwarf2_section_names str_offsets_dwo
;
345 struct dwarf2_section_names types_dwo
;
346 struct dwarf2_section_names cu_index
;
347 struct dwarf2_section_names tu_index
;
351 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
352 { ".debug_info.dwo", ".zdebug_info.dwo" },
353 { ".debug_line.dwo", ".zdebug_line.dwo" },
354 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
355 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
356 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
357 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
358 { ".debug_str.dwo", ".zdebug_str.dwo" },
359 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
360 { ".debug_types.dwo", ".zdebug_types.dwo" },
361 { ".debug_cu_index", ".zdebug_cu_index" },
362 { ".debug_tu_index", ".zdebug_tu_index" },
365 /* local data types */
367 /* The location list section (.debug_loclists) begins with a header,
368 which contains the following information. */
369 struct loclist_header
371 /* A 4-byte or 12-byte length containing the length of the
372 set of entries for this compilation unit, not including the
373 length field itself. */
376 /* A 2-byte version identifier. */
379 /* A 1-byte unsigned integer containing the size in bytes of an address on
380 the target system. */
381 unsigned char addr_size
;
383 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
384 on the target system. */
385 unsigned char segment_collector_size
;
387 /* A 4-byte count of the number of offsets that follow the header. */
388 unsigned int offset_entry_count
;
391 /* Type used for delaying computation of method physnames.
392 See comments for compute_delayed_physnames. */
393 struct delayed_method_info
395 /* The type to which the method is attached, i.e., its parent class. */
398 /* The index of the method in the type's function fieldlists. */
401 /* The index of the method in the fieldlist. */
404 /* The name of the DIE. */
407 /* The DIE associated with this method. */
408 struct die_info
*die
;
411 /* Internal state when decoding a particular compilation unit. */
414 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
415 dwarf2_per_objfile
*per_objfile
);
417 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
419 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
420 Create the set of symtabs used by this TU, or if this TU is sharing
421 symtabs with another TU and the symtabs have already been created
422 then restore those symtabs in the line header.
423 We don't need the pc/line-number mapping for type units. */
424 void setup_type_unit_groups (struct die_info
*die
);
426 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
427 buildsym_compunit constructor. */
428 struct compunit_symtab
*start_symtab (const char *name
,
429 const char *comp_dir
,
432 /* Reset the builder. */
433 void reset_builder () { m_builder
.reset (); }
435 /* Return a type that is a generic pointer type, the size of which
436 matches the address size given in the compilation unit header for
438 struct type
*addr_type () const;
440 /* Find an integer type the same size as the address size given in
441 the compilation unit header for this CU. UNSIGNED_P controls if
442 the integer is unsigned or not. */
443 struct type
*addr_sized_int_type (bool unsigned_p
) const;
445 /* The header of the compilation unit. */
446 struct comp_unit_head header
{};
448 /* Base address of this compilation unit. */
449 gdb::optional
<CORE_ADDR
> base_address
;
451 /* The language we are debugging. */
452 enum language language
= language_unknown
;
453 const struct language_defn
*language_defn
= nullptr;
455 const char *producer
= nullptr;
458 /* The symtab builder for this CU. This is only non-NULL when full
459 symbols are being read. */
460 std::unique_ptr
<buildsym_compunit
> m_builder
;
463 /* The generic symbol table building routines have separate lists for
464 file scope symbols and all all other scopes (local scopes). So
465 we need to select the right one to pass to add_symbol_to_list().
466 We do it by keeping a pointer to the correct list in list_in_scope.
468 FIXME: The original dwarf code just treated the file scope as the
469 first local scope, and all other local scopes as nested local
470 scopes, and worked fine. Check to see if we really need to
471 distinguish these in buildsym.c. */
472 struct pending
**list_in_scope
= nullptr;
474 /* Hash table holding all the loaded partial DIEs
475 with partial_die->offset.SECT_OFF as hash. */
476 htab_t partial_dies
= nullptr;
478 /* Storage for things with the same lifetime as this read-in compilation
479 unit, including partial DIEs. */
480 auto_obstack comp_unit_obstack
;
482 /* Backlink to our per_cu entry. */
483 struct dwarf2_per_cu_data
*per_cu
;
485 /* The dwarf2_per_objfile that owns this. */
486 dwarf2_per_objfile
*per_objfile
;
488 /* How many compilation units ago was this CU last referenced? */
491 /* A hash table of DIE cu_offset for following references with
492 die_info->offset.sect_off as hash. */
493 htab_t die_hash
= nullptr;
495 /* Full DIEs if read in. */
496 struct die_info
*dies
= nullptr;
498 /* A set of pointers to dwarf2_per_cu_data objects for compilation
499 units referenced by this one. Only set during full symbol processing;
500 partial symbol tables do not have dependencies. */
501 htab_t dependencies
= nullptr;
503 /* Header data from the line table, during full symbol processing. */
504 struct line_header
*line_header
= nullptr;
505 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
506 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
507 this is the DW_TAG_compile_unit die for this CU. We'll hold on
508 to the line header as long as this DIE is being processed. See
509 process_die_scope. */
510 die_info
*line_header_die_owner
= nullptr;
512 /* A list of methods which need to have physnames computed
513 after all type information has been read. */
514 std::vector
<delayed_method_info
> method_list
;
516 /* To be copied to symtab->call_site_htab. */
517 htab_t call_site_htab
= nullptr;
519 /* Non-NULL if this CU came from a DWO file.
520 There is an invariant here that is important to remember:
521 Except for attributes copied from the top level DIE in the "main"
522 (or "stub") file in preparation for reading the DWO file
523 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
524 Either there isn't a DWO file (in which case this is NULL and the point
525 is moot), or there is and either we're not going to read it (in which
526 case this is NULL) or there is and we are reading it (in which case this
528 struct dwo_unit
*dwo_unit
= nullptr;
530 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
531 Note this value comes from the Fission stub CU/TU's DIE. */
532 gdb::optional
<ULONGEST
> addr_base
;
534 /* The DW_AT_rnglists_base attribute if present.
535 Note this value comes from the Fission stub CU/TU's DIE.
536 Also note that the value is zero in the non-DWO case so this value can
537 be used without needing to know whether DWO files are in use or not.
538 N.B. This does not apply to DW_AT_ranges appearing in
539 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
540 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
541 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
542 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
543 ULONGEST ranges_base
= 0;
545 /* The DW_AT_loclists_base attribute if present. */
546 ULONGEST loclist_base
= 0;
548 /* When reading debug info generated by older versions of rustc, we
549 have to rewrite some union types to be struct types with a
550 variant part. This rewriting must be done after the CU is fully
551 read in, because otherwise at the point of rewriting some struct
552 type might not have been fully processed. So, we keep a list of
553 all such types here and process them after expansion. */
554 std::vector
<struct type
*> rust_unions
;
556 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
557 files, the value is implicitly zero. For DWARF 5 version DWO files, the
558 value is often implicit and is the size of the header of
559 .debug_str_offsets section (8 or 4, depending on the address size). */
560 gdb::optional
<ULONGEST
> str_offsets_base
;
562 /* Mark used when releasing cached dies. */
565 /* This CU references .debug_loc. See the symtab->locations_valid field.
566 This test is imperfect as there may exist optimized debug code not using
567 any location list and still facing inlining issues if handled as
568 unoptimized code. For a future better test see GCC PR other/32998. */
569 bool has_loclist
: 1;
571 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
572 if all the producer_is_* fields are valid. This information is cached
573 because profiling CU expansion showed excessive time spent in
574 producer_is_gxx_lt_4_6. */
575 bool checked_producer
: 1;
576 bool producer_is_gxx_lt_4_6
: 1;
577 bool producer_is_gcc_lt_4_3
: 1;
578 bool producer_is_icc
: 1;
579 bool producer_is_icc_lt_14
: 1;
580 bool producer_is_codewarrior
: 1;
582 /* When true, the file that we're processing is known to have
583 debugging info for C++ namespaces. GCC 3.3.x did not produce
584 this information, but later versions do. */
586 bool processing_has_namespace_info
: 1;
588 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
590 /* If this CU was inherited by another CU (via specification,
591 abstract_origin, etc), this is the ancestor CU. */
594 /* Get the buildsym_compunit for this CU. */
595 buildsym_compunit
*get_builder ()
597 /* If this CU has a builder associated with it, use that. */
598 if (m_builder
!= nullptr)
599 return m_builder
.get ();
601 /* Otherwise, search ancestors for a valid builder. */
602 if (ancestor
!= nullptr)
603 return ancestor
->get_builder ();
609 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
610 This includes type_unit_group and quick_file_names. */
612 struct stmt_list_hash
614 /* The DWO unit this table is from or NULL if there is none. */
615 struct dwo_unit
*dwo_unit
;
617 /* Offset in .debug_line or .debug_line.dwo. */
618 sect_offset line_sect_off
;
621 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
622 an object of this type. This contains elements of type unit groups
623 that can be shared across objfiles. The non-shareable parts are in
624 type_unit_group_unshareable. */
626 struct type_unit_group
628 /* dwarf2read.c's main "handle" on a TU symtab.
629 To simplify things we create an artificial CU that "includes" all the
630 type units using this stmt_list so that the rest of the code still has
631 a "per_cu" handle on the symtab. */
632 struct dwarf2_per_cu_data per_cu
;
634 /* The TUs that share this DW_AT_stmt_list entry.
635 This is added to while parsing type units to build partial symtabs,
636 and is deleted afterwards and not used again. */
637 std::vector
<signatured_type
*> *tus
;
639 /* The data used to construct the hash key. */
640 struct stmt_list_hash hash
;
643 /* These sections are what may appear in a (real or virtual) DWO file. */
647 struct dwarf2_section_info abbrev
;
648 struct dwarf2_section_info line
;
649 struct dwarf2_section_info loc
;
650 struct dwarf2_section_info loclists
;
651 struct dwarf2_section_info macinfo
;
652 struct dwarf2_section_info macro
;
653 struct dwarf2_section_info str
;
654 struct dwarf2_section_info str_offsets
;
655 /* In the case of a virtual DWO file, these two are unused. */
656 struct dwarf2_section_info info
;
657 std::vector
<dwarf2_section_info
> types
;
660 /* CUs/TUs in DWP/DWO files. */
664 /* Backlink to the containing struct dwo_file. */
665 struct dwo_file
*dwo_file
;
667 /* The "id" that distinguishes this CU/TU.
668 .debug_info calls this "dwo_id", .debug_types calls this "signature".
669 Since signatures came first, we stick with it for consistency. */
672 /* The section this CU/TU lives in, in the DWO file. */
673 struct dwarf2_section_info
*section
;
675 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
676 sect_offset sect_off
;
679 /* For types, offset in the type's DIE of the type defined by this TU. */
680 cu_offset type_offset_in_tu
;
683 /* include/dwarf2.h defines the DWP section codes.
684 It defines a max value but it doesn't define a min value, which we
685 use for error checking, so provide one. */
687 enum dwp_v2_section_ids
692 /* Data for one DWO file.
694 This includes virtual DWO files (a virtual DWO file is a DWO file as it
695 appears in a DWP file). DWP files don't really have DWO files per se -
696 comdat folding of types "loses" the DWO file they came from, and from
697 a high level view DWP files appear to contain a mass of random types.
698 However, to maintain consistency with the non-DWP case we pretend DWP
699 files contain virtual DWO files, and we assign each TU with one virtual
700 DWO file (generally based on the line and abbrev section offsets -
701 a heuristic that seems to work in practice). */
705 dwo_file () = default;
706 DISABLE_COPY_AND_ASSIGN (dwo_file
);
708 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
709 For virtual DWO files the name is constructed from the section offsets
710 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
711 from related CU+TUs. */
712 const char *dwo_name
= nullptr;
714 /* The DW_AT_comp_dir attribute. */
715 const char *comp_dir
= nullptr;
717 /* The bfd, when the file is open. Otherwise this is NULL.
718 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
719 gdb_bfd_ref_ptr dbfd
;
721 /* The sections that make up this DWO file.
722 Remember that for virtual DWO files in DWP V2, these are virtual
723 sections (for lack of a better name). */
724 struct dwo_sections sections
{};
726 /* The CUs in the file.
727 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
728 an extension to handle LLVM's Link Time Optimization output (where
729 multiple source files may be compiled into a single object/dwo pair). */
732 /* Table of TUs in the file.
733 Each element is a struct dwo_unit. */
737 /* These sections are what may appear in a DWP file. */
741 /* These are used by both DWP version 1 and 2. */
742 struct dwarf2_section_info str
;
743 struct dwarf2_section_info cu_index
;
744 struct dwarf2_section_info tu_index
;
746 /* These are only used by DWP version 2 files.
747 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
748 sections are referenced by section number, and are not recorded here.
749 In DWP version 2 there is at most one copy of all these sections, each
750 section being (effectively) comprised of the concatenation of all of the
751 individual sections that exist in the version 1 format.
752 To keep the code simple we treat each of these concatenated pieces as a
753 section itself (a virtual section?). */
754 struct dwarf2_section_info abbrev
;
755 struct dwarf2_section_info info
;
756 struct dwarf2_section_info line
;
757 struct dwarf2_section_info loc
;
758 struct dwarf2_section_info macinfo
;
759 struct dwarf2_section_info macro
;
760 struct dwarf2_section_info str_offsets
;
761 struct dwarf2_section_info types
;
764 /* These sections are what may appear in a virtual DWO file in DWP version 1.
765 A virtual DWO file is a DWO file as it appears in a DWP file. */
767 struct virtual_v1_dwo_sections
769 struct dwarf2_section_info abbrev
;
770 struct dwarf2_section_info line
;
771 struct dwarf2_section_info loc
;
772 struct dwarf2_section_info macinfo
;
773 struct dwarf2_section_info macro
;
774 struct dwarf2_section_info str_offsets
;
775 /* Each DWP hash table entry records one CU or one TU.
776 That is recorded here, and copied to dwo_unit.section. */
777 struct dwarf2_section_info info_or_types
;
780 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
781 In version 2, the sections of the DWO files are concatenated together
782 and stored in one section of that name. Thus each ELF section contains
783 several "virtual" sections. */
785 struct virtual_v2_dwo_sections
787 bfd_size_type abbrev_offset
;
788 bfd_size_type abbrev_size
;
790 bfd_size_type line_offset
;
791 bfd_size_type line_size
;
793 bfd_size_type loc_offset
;
794 bfd_size_type loc_size
;
796 bfd_size_type macinfo_offset
;
797 bfd_size_type macinfo_size
;
799 bfd_size_type macro_offset
;
800 bfd_size_type macro_size
;
802 bfd_size_type str_offsets_offset
;
803 bfd_size_type str_offsets_size
;
805 /* Each DWP hash table entry records one CU or one TU.
806 That is recorded here, and copied to dwo_unit.section. */
807 bfd_size_type info_or_types_offset
;
808 bfd_size_type info_or_types_size
;
811 /* Contents of DWP hash tables. */
813 struct dwp_hash_table
815 uint32_t version
, nr_columns
;
816 uint32_t nr_units
, nr_slots
;
817 const gdb_byte
*hash_table
, *unit_table
;
822 const gdb_byte
*indices
;
826 /* This is indexed by column number and gives the id of the section
828 #define MAX_NR_V2_DWO_SECTIONS \
829 (1 /* .debug_info or .debug_types */ \
830 + 1 /* .debug_abbrev */ \
831 + 1 /* .debug_line */ \
832 + 1 /* .debug_loc */ \
833 + 1 /* .debug_str_offsets */ \
834 + 1 /* .debug_macro or .debug_macinfo */)
835 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
836 const gdb_byte
*offsets
;
837 const gdb_byte
*sizes
;
842 /* Data for one DWP file. */
846 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
848 dbfd (std::move (abfd
))
852 /* Name of the file. */
855 /* File format version. */
859 gdb_bfd_ref_ptr dbfd
;
861 /* Section info for this file. */
862 struct dwp_sections sections
{};
864 /* Table of CUs in the file. */
865 const struct dwp_hash_table
*cus
= nullptr;
867 /* Table of TUs in the file. */
868 const struct dwp_hash_table
*tus
= nullptr;
870 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
874 /* Table to map ELF section numbers to their sections.
875 This is only needed for the DWP V1 file format. */
876 unsigned int num_sections
= 0;
877 asection
**elf_sections
= nullptr;
880 /* Struct used to pass misc. parameters to read_die_and_children, et
881 al. which are used for both .debug_info and .debug_types dies.
882 All parameters here are unchanging for the life of the call. This
883 struct exists to abstract away the constant parameters of die reading. */
885 struct die_reader_specs
887 /* The bfd of die_section. */
890 /* The CU of the DIE we are parsing. */
891 struct dwarf2_cu
*cu
;
893 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
894 struct dwo_file
*dwo_file
;
896 /* The section the die comes from.
897 This is either .debug_info or .debug_types, or the .dwo variants. */
898 struct dwarf2_section_info
*die_section
;
900 /* die_section->buffer. */
901 const gdb_byte
*buffer
;
903 /* The end of the buffer. */
904 const gdb_byte
*buffer_end
;
906 /* The abbreviation table to use when reading the DIEs. */
907 struct abbrev_table
*abbrev_table
;
910 /* A subclass of die_reader_specs that holds storage and has complex
911 constructor and destructor behavior. */
913 class cutu_reader
: public die_reader_specs
917 cutu_reader (dwarf2_per_cu_data
*this_cu
,
918 dwarf2_per_objfile
*per_objfile
,
919 struct abbrev_table
*abbrev_table
,
920 dwarf2_cu
*existing_cu
,
923 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
924 dwarf2_per_objfile
*per_objfile
,
925 struct dwarf2_cu
*parent_cu
= nullptr,
926 struct dwo_file
*dwo_file
= nullptr);
928 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
930 const gdb_byte
*info_ptr
= nullptr;
931 struct die_info
*comp_unit_die
= nullptr;
932 bool dummy_p
= false;
934 /* Release the new CU, putting it on the chain. This cannot be done
939 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
940 dwarf2_per_objfile
*per_objfile
,
941 dwarf2_cu
*existing_cu
);
943 struct dwarf2_per_cu_data
*m_this_cu
;
944 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
946 /* The ordinary abbreviation table. */
947 abbrev_table_up m_abbrev_table_holder
;
949 /* The DWO abbreviation table. */
950 abbrev_table_up m_dwo_abbrev_table
;
953 /* When we construct a partial symbol table entry we only
954 need this much information. */
955 struct partial_die_info
: public allocate_on_obstack
957 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
959 /* Disable assign but still keep copy ctor, which is needed
960 load_partial_dies. */
961 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
963 /* Adjust the partial die before generating a symbol for it. This
964 function may set the is_external flag or change the DIE's
966 void fixup (struct dwarf2_cu
*cu
);
968 /* Read a minimal amount of information into the minimal die
970 const gdb_byte
*read (const struct die_reader_specs
*reader
,
971 const struct abbrev_info
&abbrev
,
972 const gdb_byte
*info_ptr
);
974 /* Compute the name of this partial DIE. This memoizes the
975 result, so it is safe to call multiple times. */
976 const char *name (dwarf2_cu
*cu
);
978 /* Offset of this DIE. */
979 const sect_offset sect_off
;
981 /* DWARF-2 tag for this DIE. */
982 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
984 /* Assorted flags describing the data found in this DIE. */
985 const unsigned int has_children
: 1;
987 unsigned int is_external
: 1;
988 unsigned int is_declaration
: 1;
989 unsigned int has_type
: 1;
990 unsigned int has_specification
: 1;
991 unsigned int has_pc_info
: 1;
992 unsigned int may_be_inlined
: 1;
994 /* This DIE has been marked DW_AT_main_subprogram. */
995 unsigned int main_subprogram
: 1;
997 /* Flag set if the SCOPE field of this structure has been
999 unsigned int scope_set
: 1;
1001 /* Flag set if the DIE has a byte_size attribute. */
1002 unsigned int has_byte_size
: 1;
1004 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1005 unsigned int has_const_value
: 1;
1007 /* Flag set if any of the DIE's children are template arguments. */
1008 unsigned int has_template_arguments
: 1;
1010 /* Flag set if fixup has been called on this die. */
1011 unsigned int fixup_called
: 1;
1013 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1014 unsigned int is_dwz
: 1;
1016 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1017 unsigned int spec_is_dwz
: 1;
1019 unsigned int canonical_name
: 1;
1021 /* The name of this DIE. Normally the value of DW_AT_name, but
1022 sometimes a default name for unnamed DIEs. */
1023 const char *raw_name
= nullptr;
1025 /* The linkage name, if present. */
1026 const char *linkage_name
= nullptr;
1028 /* The scope to prepend to our children. This is generally
1029 allocated on the comp_unit_obstack, so will disappear
1030 when this compilation unit leaves the cache. */
1031 const char *scope
= nullptr;
1033 /* Some data associated with the partial DIE. The tag determines
1034 which field is live. */
1037 /* The location description associated with this DIE, if any. */
1038 struct dwarf_block
*locdesc
;
1039 /* The offset of an import, for DW_TAG_imported_unit. */
1040 sect_offset sect_off
;
1043 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1044 CORE_ADDR lowpc
= 0;
1045 CORE_ADDR highpc
= 0;
1047 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1048 DW_AT_sibling, if any. */
1049 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1050 could return DW_AT_sibling values to its caller load_partial_dies. */
1051 const gdb_byte
*sibling
= nullptr;
1053 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1054 DW_AT_specification (or DW_AT_abstract_origin or
1055 DW_AT_extension). */
1056 sect_offset spec_offset
{};
1058 /* Pointers to this DIE's parent, first child, and next sibling,
1060 struct partial_die_info
*die_parent
= nullptr;
1061 struct partial_die_info
*die_child
= nullptr;
1062 struct partial_die_info
*die_sibling
= nullptr;
1064 friend struct partial_die_info
*
1065 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1068 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1069 partial_die_info (sect_offset sect_off
)
1070 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1074 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1076 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1081 has_specification
= 0;
1084 main_subprogram
= 0;
1087 has_const_value
= 0;
1088 has_template_arguments
= 0;
1096 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1097 but this would require a corresponding change in unpack_field_as_long
1099 static int bits_per_byte
= 8;
1101 struct variant_part_builder
;
1103 /* When reading a variant, we track a bit more information about the
1104 field, and store it in an object of this type. */
1106 struct variant_field
1108 int first_field
= -1;
1109 int last_field
= -1;
1111 /* A variant can contain other variant parts. */
1112 std::vector
<variant_part_builder
> variant_parts
;
1114 /* If we see a DW_TAG_variant, then this will be set if this is the
1116 bool default_branch
= false;
1117 /* If we see a DW_AT_discr_value, then this will be the discriminant
1119 ULONGEST discriminant_value
= 0;
1120 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1122 struct dwarf_block
*discr_list_data
= nullptr;
1125 /* This represents a DW_TAG_variant_part. */
1127 struct variant_part_builder
1129 /* The offset of the discriminant field. */
1130 sect_offset discriminant_offset
{};
1132 /* Variants that are direct children of this variant part. */
1133 std::vector
<variant_field
> variants
;
1135 /* True if we're currently reading a variant. */
1136 bool processing_variant
= false;
1141 int accessibility
= 0;
1143 /* Variant parts need to find the discriminant, which is a DIE
1144 reference. We track the section offset of each field to make
1147 struct field field
{};
1152 const char *name
= nullptr;
1153 std::vector
<struct fn_field
> fnfields
;
1156 /* The routines that read and process dies for a C struct or C++ class
1157 pass lists of data member fields and lists of member function fields
1158 in an instance of a field_info structure, as defined below. */
1161 /* List of data member and baseclasses fields. */
1162 std::vector
<struct nextfield
> fields
;
1163 std::vector
<struct nextfield
> baseclasses
;
1165 /* Set if the accessibility of one of the fields is not public. */
1166 int non_public_fields
= 0;
1168 /* Member function fieldlist array, contains name of possibly overloaded
1169 member function, number of overloaded member functions and a pointer
1170 to the head of the member function field chain. */
1171 std::vector
<struct fnfieldlist
> fnfieldlists
;
1173 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1174 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1175 std::vector
<struct decl_field
> typedef_field_list
;
1177 /* Nested types defined by this class and the number of elements in this
1179 std::vector
<struct decl_field
> nested_types_list
;
1181 /* If non-null, this is the variant part we are currently
1183 variant_part_builder
*current_variant_part
= nullptr;
1184 /* This holds all the top-level variant parts attached to the type
1186 std::vector
<variant_part_builder
> variant_parts
;
1188 /* Return the total number of fields (including baseclasses). */
1189 int nfields () const
1191 return fields
.size () + baseclasses
.size ();
1195 /* Loaded secondary compilation units are kept in memory until they
1196 have not been referenced for the processing of this many
1197 compilation units. Set this to zero to disable caching. Cache
1198 sizes of up to at least twenty will improve startup time for
1199 typical inter-CU-reference binaries, at an obvious memory cost. */
1200 static int dwarf_max_cache_age
= 5;
1202 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1203 struct cmd_list_element
*c
, const char *value
)
1205 fprintf_filtered (file
, _("The upper bound on the age of cached "
1206 "DWARF compilation units is %s.\n"),
1210 /* local function prototypes */
1212 static void dwarf2_find_base_address (struct die_info
*die
,
1213 struct dwarf2_cu
*cu
);
1215 static dwarf2_psymtab
*create_partial_symtab
1216 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1219 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1220 const gdb_byte
*info_ptr
,
1221 struct die_info
*type_unit_die
);
1223 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1225 static void scan_partial_symbols (struct partial_die_info
*,
1226 CORE_ADDR
*, CORE_ADDR
*,
1227 int, struct dwarf2_cu
*);
1229 static void add_partial_symbol (struct partial_die_info
*,
1230 struct dwarf2_cu
*);
1232 static void add_partial_namespace (struct partial_die_info
*pdi
,
1233 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1234 int set_addrmap
, struct dwarf2_cu
*cu
);
1236 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1237 CORE_ADDR
*highpc
, int set_addrmap
,
1238 struct dwarf2_cu
*cu
);
1240 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1241 struct dwarf2_cu
*cu
);
1243 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1244 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1245 int need_pc
, struct dwarf2_cu
*cu
);
1247 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1249 static struct partial_die_info
*load_partial_dies
1250 (const struct die_reader_specs
*, const gdb_byte
*, int);
1252 /* A pair of partial_die_info and compilation unit. */
1253 struct cu_partial_die_info
1255 /* The compilation unit of the partial_die_info. */
1256 struct dwarf2_cu
*cu
;
1257 /* A partial_die_info. */
1258 struct partial_die_info
*pdi
;
1260 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1266 cu_partial_die_info () = delete;
1269 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1270 struct dwarf2_cu
*);
1272 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1273 struct attribute
*, struct attr_abbrev
*,
1274 const gdb_byte
*, bool *need_reprocess
);
1276 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1277 struct attribute
*attr
);
1279 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1281 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1282 dwarf2_section_info
*, sect_offset
);
1284 static const char *read_indirect_string
1285 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1286 const struct comp_unit_head
*, unsigned int *);
1288 static const char *read_indirect_string_at_offset
1289 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1291 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1295 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1296 ULONGEST str_index
);
1298 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1299 ULONGEST str_index
);
1301 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1303 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1304 struct dwarf2_cu
*);
1306 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1307 struct dwarf2_cu
*cu
);
1309 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1311 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1312 struct dwarf2_cu
*cu
);
1314 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1316 static struct die_info
*die_specification (struct die_info
*die
,
1317 struct dwarf2_cu
**);
1319 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1320 struct dwarf2_cu
*cu
);
1322 static void dwarf_decode_lines (struct line_header
*, const char *,
1323 struct dwarf2_cu
*, dwarf2_psymtab
*,
1324 CORE_ADDR
, int decode_mapping
);
1326 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1329 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1330 struct dwarf2_cu
*, struct symbol
* = NULL
);
1332 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1333 struct dwarf2_cu
*);
1335 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1338 struct obstack
*obstack
,
1339 struct dwarf2_cu
*cu
, LONGEST
*value
,
1340 const gdb_byte
**bytes
,
1341 struct dwarf2_locexpr_baton
**baton
);
1343 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1345 static int need_gnat_info (struct dwarf2_cu
*);
1347 static struct type
*die_descriptive_type (struct die_info
*,
1348 struct dwarf2_cu
*);
1350 static void set_descriptive_type (struct type
*, struct die_info
*,
1351 struct dwarf2_cu
*);
1353 static struct type
*die_containing_type (struct die_info
*,
1354 struct dwarf2_cu
*);
1356 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1357 struct dwarf2_cu
*);
1359 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1361 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1363 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1365 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1366 const char *suffix
, int physname
,
1367 struct dwarf2_cu
*cu
);
1369 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1371 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1373 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1375 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1377 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1379 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1381 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1382 struct dwarf2_cu
*, dwarf2_psymtab
*);
1384 /* Return the .debug_loclists section to use for cu. */
1385 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1387 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1388 values. Keep the items ordered with increasing constraints compliance. */
1391 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1392 PC_BOUNDS_NOT_PRESENT
,
1394 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1395 were present but they do not form a valid range of PC addresses. */
1398 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1401 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1405 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1406 CORE_ADDR
*, CORE_ADDR
*,
1410 static void get_scope_pc_bounds (struct die_info
*,
1411 CORE_ADDR
*, CORE_ADDR
*,
1412 struct dwarf2_cu
*);
1414 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1415 CORE_ADDR
, struct dwarf2_cu
*);
1417 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1418 struct dwarf2_cu
*);
1420 static void dwarf2_attach_fields_to_type (struct field_info
*,
1421 struct type
*, struct dwarf2_cu
*);
1423 static void dwarf2_add_member_fn (struct field_info
*,
1424 struct die_info
*, struct type
*,
1425 struct dwarf2_cu
*);
1427 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1429 struct dwarf2_cu
*);
1431 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1433 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1435 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1437 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1439 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1441 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1443 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1445 static struct type
*read_module_type (struct die_info
*die
,
1446 struct dwarf2_cu
*cu
);
1448 static const char *namespace_name (struct die_info
*die
,
1449 int *is_anonymous
, struct dwarf2_cu
*);
1451 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1453 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1456 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1457 struct dwarf2_cu
*);
1459 static struct die_info
*read_die_and_siblings_1
1460 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1463 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1464 const gdb_byte
*info_ptr
,
1465 const gdb_byte
**new_info_ptr
,
1466 struct die_info
*parent
);
1468 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1469 struct die_info
**, const gdb_byte
*,
1472 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1473 struct die_info
**, const gdb_byte
*);
1475 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1477 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1480 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1482 static const char *dwarf2_full_name (const char *name
,
1483 struct die_info
*die
,
1484 struct dwarf2_cu
*cu
);
1486 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1487 struct dwarf2_cu
*cu
);
1489 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1490 struct dwarf2_cu
**);
1492 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1494 static void dump_die_for_error (struct die_info
*);
1496 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1499 /*static*/ void dump_die (struct die_info
*, int max_level
);
1501 static void store_in_ref_table (struct die_info
*,
1502 struct dwarf2_cu
*);
1504 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1505 const struct attribute
*,
1506 struct dwarf2_cu
**);
1508 static struct die_info
*follow_die_ref (struct die_info
*,
1509 const struct attribute
*,
1510 struct dwarf2_cu
**);
1512 static struct die_info
*follow_die_sig (struct die_info
*,
1513 const struct attribute
*,
1514 struct dwarf2_cu
**);
1516 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1517 struct dwarf2_cu
*);
1519 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1520 const struct attribute
*,
1521 struct dwarf2_cu
*);
1523 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1524 dwarf2_per_objfile
*per_objfile
);
1526 static void read_signatured_type (signatured_type
*sig_type
,
1527 dwarf2_per_objfile
*per_objfile
);
1529 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1530 struct die_info
*die
, struct dwarf2_cu
*cu
,
1531 struct dynamic_prop
*prop
, struct type
*type
);
1533 /* memory allocation interface */
1535 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1537 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1539 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1541 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1542 struct dwarf2_loclist_baton
*baton
,
1543 const struct attribute
*attr
);
1545 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1547 struct dwarf2_cu
*cu
,
1550 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1551 const gdb_byte
*info_ptr
,
1552 struct abbrev_info
*abbrev
);
1554 static hashval_t
partial_die_hash (const void *item
);
1556 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1558 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1559 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1560 dwarf2_per_objfile
*per_objfile
);
1562 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1563 struct die_info
*comp_unit_die
,
1564 enum language pretend_language
);
1566 static struct type
*set_die_type (struct die_info
*, struct type
*,
1567 struct dwarf2_cu
*);
1569 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1571 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1573 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1574 dwarf2_per_objfile
*per_objfile
,
1576 enum language pretend_language
);
1578 static void process_full_comp_unit (dwarf2_cu
*cu
,
1579 enum language pretend_language
);
1581 static void process_full_type_unit (dwarf2_cu
*cu
,
1582 enum language pretend_language
);
1584 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1585 struct dwarf2_per_cu_data
*);
1587 static void dwarf2_mark (struct dwarf2_cu
*);
1589 static struct type
*get_die_type_at_offset (sect_offset
,
1590 dwarf2_per_cu_data
*per_cu
,
1591 dwarf2_per_objfile
*per_objfile
);
1593 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1595 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1596 dwarf2_per_objfile
*per_objfile
,
1597 enum language pretend_language
);
1599 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1601 /* Class, the destructor of which frees all allocated queue entries. This
1602 will only have work to do if an error was thrown while processing the
1603 dwarf. If no error was thrown then the queue entries should have all
1604 been processed, and freed, as we went along. */
1606 class dwarf2_queue_guard
1609 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1610 : m_per_objfile (per_objfile
)
1614 /* Free any entries remaining on the queue. There should only be
1615 entries left if we hit an error while processing the dwarf. */
1616 ~dwarf2_queue_guard ()
1618 /* Ensure that no memory is allocated by the queue. */
1619 std::queue
<dwarf2_queue_item
> empty
;
1620 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1623 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1626 dwarf2_per_objfile
*m_per_objfile
;
1629 dwarf2_queue_item::~dwarf2_queue_item ()
1631 /* Anything still marked queued is likely to be in an
1632 inconsistent state, so discard it. */
1635 per_objfile
->remove_cu (per_cu
);
1640 /* The return type of find_file_and_directory. Note, the enclosed
1641 string pointers are only valid while this object is valid. */
1643 struct file_and_directory
1645 /* The filename. This is never NULL. */
1648 /* The compilation directory. NULL if not known. If we needed to
1649 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1650 points directly to the DW_AT_comp_dir string attribute owned by
1651 the obstack that owns the DIE. */
1652 const char *comp_dir
;
1654 /* If we needed to build a new string for comp_dir, this is what
1655 owns the storage. */
1656 std::string comp_dir_storage
;
1659 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1660 struct dwarf2_cu
*cu
);
1662 static htab_up
allocate_signatured_type_table ();
1664 static htab_up
allocate_dwo_unit_table ();
1666 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1667 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1668 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1670 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1672 static struct dwo_unit
*lookup_dwo_comp_unit
1673 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1674 ULONGEST signature
);
1676 static struct dwo_unit
*lookup_dwo_type_unit
1677 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1679 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1681 /* A unique pointer to a dwo_file. */
1683 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1685 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1687 static void check_producer (struct dwarf2_cu
*cu
);
1689 static void free_line_header_voidp (void *arg
);
1691 /* Various complaints about symbol reading that don't abort the process. */
1694 dwarf2_debug_line_missing_file_complaint (void)
1696 complaint (_(".debug_line section has line data without a file"));
1700 dwarf2_debug_line_missing_end_sequence_complaint (void)
1702 complaint (_(".debug_line section has line "
1703 "program sequence without an end"));
1707 dwarf2_complex_location_expr_complaint (void)
1709 complaint (_("location expression too complex"));
1713 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1716 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1721 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1723 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1727 /* Hash function for line_header_hash. */
1730 line_header_hash (const struct line_header
*ofs
)
1732 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1735 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1738 line_header_hash_voidp (const void *item
)
1740 const struct line_header
*ofs
= (const struct line_header
*) item
;
1742 return line_header_hash (ofs
);
1745 /* Equality function for line_header_hash. */
1748 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1750 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1751 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1753 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1754 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1759 /* See declaration. */
1761 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1764 can_copy (can_copy_
)
1767 names
= &dwarf2_elf_names
;
1769 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1770 locate_sections (obfd
, sec
, *names
);
1773 dwarf2_per_bfd::~dwarf2_per_bfd ()
1775 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1776 per_cu
->imported_symtabs_free ();
1778 for (signatured_type
*sig_type
: all_type_units
)
1779 sig_type
->per_cu
.imported_symtabs_free ();
1781 /* Everything else should be on this->obstack. */
1787 dwarf2_per_objfile::remove_all_cus ()
1789 for (auto pair
: m_dwarf2_cus
)
1792 m_dwarf2_cus
.clear ();
1795 /* A helper class that calls free_cached_comp_units on
1798 class free_cached_comp_units
1802 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1803 : m_per_objfile (per_objfile
)
1807 ~free_cached_comp_units ()
1809 m_per_objfile
->remove_all_cus ();
1812 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1816 dwarf2_per_objfile
*m_per_objfile
;
1822 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1824 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1826 return this->m_symtabs
[per_cu
->index
] != nullptr;
1832 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1834 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1836 return this->m_symtabs
[per_cu
->index
];
1842 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1843 compunit_symtab
*symtab
)
1845 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1846 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1848 this->m_symtabs
[per_cu
->index
] = symtab
;
1851 /* Try to locate the sections we need for DWARF 2 debugging
1852 information and return true if we have enough to do something.
1853 NAMES points to the dwarf2 section names, or is NULL if the standard
1854 ELF names are used. CAN_COPY is true for formats where symbol
1855 interposition is possible and so symbol values must follow copy
1856 relocation rules. */
1859 dwarf2_has_info (struct objfile
*objfile
,
1860 const struct dwarf2_debug_sections
*names
,
1863 if (objfile
->flags
& OBJF_READNEVER
)
1866 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1868 if (per_objfile
== NULL
)
1870 dwarf2_per_bfd
*per_bfd
;
1872 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1873 doesn't require relocations and if there aren't partial symbols
1874 from some other reader. */
1875 if (!objfile_has_partial_symbols (objfile
)
1876 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1878 /* See if one has been created for this BFD yet. */
1879 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1881 if (per_bfd
== nullptr)
1883 /* No, create it now. */
1884 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1885 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1890 /* No sharing possible, create one specifically for this objfile. */
1891 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1892 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1895 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1898 return (!per_objfile
->per_bfd
->info
.is_virtual
1899 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1900 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1901 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1904 /* When loading sections, we look either for uncompressed section or for
1905 compressed section names. */
1908 section_is_p (const char *section_name
,
1909 const struct dwarf2_section_names
*names
)
1911 if (names
->normal
!= NULL
1912 && strcmp (section_name
, names
->normal
) == 0)
1914 if (names
->compressed
!= NULL
1915 && strcmp (section_name
, names
->compressed
) == 0)
1920 /* See declaration. */
1923 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1924 const dwarf2_debug_sections
&names
)
1926 flagword aflag
= bfd_section_flags (sectp
);
1928 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1931 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1932 > bfd_get_file_size (abfd
))
1934 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1935 warning (_("Discarding section %s which has a section size (%s"
1936 ") larger than the file size [in module %s]"),
1937 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1938 bfd_get_filename (abfd
));
1940 else if (section_is_p (sectp
->name
, &names
.info
))
1942 this->info
.s
.section
= sectp
;
1943 this->info
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1947 this->abbrev
.s
.section
= sectp
;
1948 this->abbrev
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.line
))
1952 this->line
.s
.section
= sectp
;
1953 this->line
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.loc
))
1957 this->loc
.s
.section
= sectp
;
1958 this->loc
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.loclists
))
1962 this->loclists
.s
.section
= sectp
;
1963 this->loclists
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1967 this->macinfo
.s
.section
= sectp
;
1968 this->macinfo
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.macro
))
1972 this->macro
.s
.section
= sectp
;
1973 this->macro
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.str
))
1977 this->str
.s
.section
= sectp
;
1978 this->str
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1982 this->str_offsets
.s
.section
= sectp
;
1983 this->str_offsets
.size
= bfd_section_size (sectp
);
1985 else if (section_is_p (sectp
->name
, &names
.line_str
))
1987 this->line_str
.s
.section
= sectp
;
1988 this->line_str
.size
= bfd_section_size (sectp
);
1990 else if (section_is_p (sectp
->name
, &names
.addr
))
1992 this->addr
.s
.section
= sectp
;
1993 this->addr
.size
= bfd_section_size (sectp
);
1995 else if (section_is_p (sectp
->name
, &names
.frame
))
1997 this->frame
.s
.section
= sectp
;
1998 this->frame
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2002 this->eh_frame
.s
.section
= sectp
;
2003 this->eh_frame
.size
= bfd_section_size (sectp
);
2005 else if (section_is_p (sectp
->name
, &names
.ranges
))
2007 this->ranges
.s
.section
= sectp
;
2008 this->ranges
.size
= bfd_section_size (sectp
);
2010 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2012 this->rnglists
.s
.section
= sectp
;
2013 this->rnglists
.size
= bfd_section_size (sectp
);
2015 else if (section_is_p (sectp
->name
, &names
.types
))
2017 struct dwarf2_section_info type_section
;
2019 memset (&type_section
, 0, sizeof (type_section
));
2020 type_section
.s
.section
= sectp
;
2021 type_section
.size
= bfd_section_size (sectp
);
2023 this->types
.push_back (type_section
);
2025 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2027 this->gdb_index
.s
.section
= sectp
;
2028 this->gdb_index
.size
= bfd_section_size (sectp
);
2030 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2032 this->debug_names
.s
.section
= sectp
;
2033 this->debug_names
.size
= bfd_section_size (sectp
);
2035 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2037 this->debug_aranges
.s
.section
= sectp
;
2038 this->debug_aranges
.size
= bfd_section_size (sectp
);
2041 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2042 && bfd_section_vma (sectp
) == 0)
2043 this->has_section_at_zero
= true;
2046 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2050 dwarf2_get_section_info (struct objfile
*objfile
,
2051 enum dwarf2_section_enum sect
,
2052 asection
**sectp
, const gdb_byte
**bufp
,
2053 bfd_size_type
*sizep
)
2055 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2056 struct dwarf2_section_info
*info
;
2058 /* We may see an objfile without any DWARF, in which case we just
2060 if (per_objfile
== NULL
)
2069 case DWARF2_DEBUG_FRAME
:
2070 info
= &per_objfile
->per_bfd
->frame
;
2072 case DWARF2_EH_FRAME
:
2073 info
= &per_objfile
->per_bfd
->eh_frame
;
2076 gdb_assert_not_reached ("unexpected section");
2079 info
->read (objfile
);
2081 *sectp
= info
->get_bfd_section ();
2082 *bufp
= info
->buffer
;
2083 *sizep
= info
->size
;
2086 /* A helper function to find the sections for a .dwz file. */
2089 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2091 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2093 /* Note that we only support the standard ELF names, because .dwz
2094 is ELF-only (at the time of writing). */
2095 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2097 dwz_file
->abbrev
.s
.section
= sectp
;
2098 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2100 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2102 dwz_file
->info
.s
.section
= sectp
;
2103 dwz_file
->info
.size
= bfd_section_size (sectp
);
2105 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2107 dwz_file
->str
.s
.section
= sectp
;
2108 dwz_file
->str
.size
= bfd_section_size (sectp
);
2110 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2112 dwz_file
->line
.s
.section
= sectp
;
2113 dwz_file
->line
.size
= bfd_section_size (sectp
);
2115 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2117 dwz_file
->macro
.s
.section
= sectp
;
2118 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2120 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2122 dwz_file
->gdb_index
.s
.section
= sectp
;
2123 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2125 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2127 dwz_file
->debug_names
.s
.section
= sectp
;
2128 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2132 /* See dwarf2read.h. */
2135 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2137 const char *filename
;
2138 bfd_size_type buildid_len_arg
;
2142 if (per_bfd
->dwz_file
!= NULL
)
2143 return per_bfd
->dwz_file
.get ();
2145 bfd_set_error (bfd_error_no_error
);
2146 gdb::unique_xmalloc_ptr
<char> data
2147 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2148 &buildid_len_arg
, &buildid
));
2151 if (bfd_get_error () == bfd_error_no_error
)
2153 error (_("could not read '.gnu_debugaltlink' section: %s"),
2154 bfd_errmsg (bfd_get_error ()));
2157 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2159 buildid_len
= (size_t) buildid_len_arg
;
2161 filename
= data
.get ();
2163 std::string abs_storage
;
2164 if (!IS_ABSOLUTE_PATH (filename
))
2166 gdb::unique_xmalloc_ptr
<char> abs
2167 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2169 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2170 filename
= abs_storage
.c_str ();
2173 /* First try the file name given in the section. If that doesn't
2174 work, try to use the build-id instead. */
2175 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2176 if (dwz_bfd
!= NULL
)
2178 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2179 dwz_bfd
.reset (nullptr);
2182 if (dwz_bfd
== NULL
)
2183 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2185 if (dwz_bfd
== nullptr)
2187 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2188 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2190 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2197 /* File successfully retrieved from server. */
2198 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2200 if (dwz_bfd
== nullptr)
2201 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2202 alt_filename
.get ());
2203 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2204 dwz_bfd
.reset (nullptr);
2208 if (dwz_bfd
== NULL
)
2209 error (_("could not find '.gnu_debugaltlink' file for %s"),
2210 bfd_get_filename (per_bfd
->obfd
));
2212 std::unique_ptr
<struct dwz_file
> result
2213 (new struct dwz_file (std::move (dwz_bfd
)));
2215 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2218 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2219 per_bfd
->dwz_file
= std::move (result
);
2220 return per_bfd
->dwz_file
.get ();
2223 /* DWARF quick_symbols_functions support. */
2225 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2226 unique line tables, so we maintain a separate table of all .debug_line
2227 derived entries to support the sharing.
2228 All the quick functions need is the list of file names. We discard the
2229 line_header when we're done and don't need to record it here. */
2230 struct quick_file_names
2232 /* The data used to construct the hash key. */
2233 struct stmt_list_hash hash
;
2235 /* The number of entries in file_names, real_names. */
2236 unsigned int num_file_names
;
2238 /* The file names from the line table, after being run through
2240 const char **file_names
;
2242 /* The file names from the line table after being run through
2243 gdb_realpath. These are computed lazily. */
2244 const char **real_names
;
2247 /* When using the index (and thus not using psymtabs), each CU has an
2248 object of this type. This is used to hold information needed by
2249 the various "quick" methods. */
2250 struct dwarf2_per_cu_quick_data
2252 /* The file table. This can be NULL if there was no file table
2253 or it's currently not read in.
2254 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2255 struct quick_file_names
*file_names
;
2257 /* A temporary mark bit used when iterating over all CUs in
2258 expand_symtabs_matching. */
2259 unsigned int mark
: 1;
2261 /* True if we've tried to read the file table and found there isn't one.
2262 There will be no point in trying to read it again next time. */
2263 unsigned int no_file_data
: 1;
2266 /* Utility hash function for a stmt_list_hash. */
2269 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2273 if (stmt_list_hash
->dwo_unit
!= NULL
)
2274 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2275 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2279 /* Utility equality function for a stmt_list_hash. */
2282 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2283 const struct stmt_list_hash
*rhs
)
2285 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2287 if (lhs
->dwo_unit
!= NULL
2288 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2291 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2294 /* Hash function for a quick_file_names. */
2297 hash_file_name_entry (const void *e
)
2299 const struct quick_file_names
*file_data
2300 = (const struct quick_file_names
*) e
;
2302 return hash_stmt_list_entry (&file_data
->hash
);
2305 /* Equality function for a quick_file_names. */
2308 eq_file_name_entry (const void *a
, const void *b
)
2310 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2311 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2313 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2316 /* Delete function for a quick_file_names. */
2319 delete_file_name_entry (void *e
)
2321 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2324 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2326 xfree ((void*) file_data
->file_names
[i
]);
2327 if (file_data
->real_names
)
2328 xfree ((void*) file_data
->real_names
[i
]);
2331 /* The space for the struct itself lives on the obstack, so we don't
2335 /* Create a quick_file_names hash table. */
2338 create_quick_file_names_table (unsigned int nr_initial_entries
)
2340 return htab_up (htab_create_alloc (nr_initial_entries
,
2341 hash_file_name_entry
, eq_file_name_entry
,
2342 delete_file_name_entry
, xcalloc
, xfree
));
2345 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2346 function is unrelated to symtabs, symtab would have to be created afterwards.
2347 You should call age_cached_comp_units after processing the CU. */
2350 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2353 if (per_cu
->is_debug_types
)
2354 load_full_type_unit (per_cu
, per_objfile
);
2356 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2358 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2360 return nullptr; /* Dummy CU. */
2362 dwarf2_find_base_address (cu
->dies
, cu
);
2367 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2370 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2371 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2373 /* Skip type_unit_groups, reading the type units they contain
2374 is handled elsewhere. */
2375 if (per_cu
->type_unit_group_p ())
2378 /* The destructor of dwarf2_queue_guard frees any entries left on
2379 the queue. After this point we're guaranteed to leave this function
2380 with the dwarf queue empty. */
2381 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2383 if (!per_objfile
->symtab_set_p (per_cu
))
2385 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2386 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2388 /* If we just loaded a CU from a DWO, and we're working with an index
2389 that may badly handle TUs, load all the TUs in that DWO as well.
2390 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2391 if (!per_cu
->is_debug_types
2393 && cu
->dwo_unit
!= NULL
2394 && per_objfile
->per_bfd
->index_table
!= NULL
2395 && per_objfile
->per_bfd
->index_table
->version
<= 7
2396 /* DWP files aren't supported yet. */
2397 && get_dwp_file (per_objfile
) == NULL
)
2398 queue_and_load_all_dwo_tus (cu
);
2401 process_queue (per_objfile
);
2403 /* Age the cache, releasing compilation units that have not
2404 been used recently. */
2405 per_objfile
->age_comp_units ();
2408 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2409 the per-objfile for which this symtab is instantiated.
2411 Returns the resulting symbol table. */
2413 static struct compunit_symtab
*
2414 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2415 dwarf2_per_objfile
*per_objfile
,
2418 gdb_assert (per_objfile
->per_bfd
->using_index
);
2420 if (!per_objfile
->symtab_set_p (per_cu
))
2422 free_cached_comp_units
freer (per_objfile
);
2423 scoped_restore decrementer
= increment_reading_symtab ();
2424 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2425 process_cu_includes (per_objfile
);
2428 return per_objfile
->get_symtab (per_cu
);
2431 /* See declaration. */
2433 dwarf2_per_cu_data
*
2434 dwarf2_per_bfd::get_cutu (int index
)
2436 if (index
>= this->all_comp_units
.size ())
2438 index
-= this->all_comp_units
.size ();
2439 gdb_assert (index
< this->all_type_units
.size ());
2440 return &this->all_type_units
[index
]->per_cu
;
2443 return this->all_comp_units
[index
];
2446 /* See declaration. */
2448 dwarf2_per_cu_data
*
2449 dwarf2_per_bfd::get_cu (int index
)
2451 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2453 return this->all_comp_units
[index
];
2456 /* See declaration. */
2459 dwarf2_per_bfd::get_tu (int index
)
2461 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2463 return this->all_type_units
[index
];
2468 dwarf2_per_cu_data
*
2469 dwarf2_per_bfd::allocate_per_cu ()
2471 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2472 result
->per_bfd
= this;
2473 result
->index
= m_num_psymtabs
++;
2480 dwarf2_per_bfd::allocate_signatured_type ()
2482 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2483 result
->per_cu
.per_bfd
= this;
2484 result
->per_cu
.index
= m_num_psymtabs
++;
2488 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2489 obstack, and constructed with the specified field values. */
2491 static dwarf2_per_cu_data
*
2492 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2493 struct dwarf2_section_info
*section
,
2495 sect_offset sect_off
, ULONGEST length
)
2497 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2498 the_cu
->sect_off
= sect_off
;
2499 the_cu
->length
= length
;
2500 the_cu
->section
= section
;
2501 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2502 struct dwarf2_per_cu_quick_data
);
2503 the_cu
->is_dwz
= is_dwz
;
2507 /* A helper for create_cus_from_index that handles a given list of
2511 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2512 const gdb_byte
*cu_list
, offset_type n_elements
,
2513 struct dwarf2_section_info
*section
,
2516 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2518 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2520 sect_offset sect_off
2521 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2522 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2525 dwarf2_per_cu_data
*per_cu
2526 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2528 per_bfd
->all_comp_units
.push_back (per_cu
);
2532 /* Read the CU list from the mapped index, and use it to create all
2533 the CU objects for PER_BFD. */
2536 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2537 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2538 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2540 gdb_assert (per_bfd
->all_comp_units
.empty ());
2541 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2543 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2546 if (dwz_elements
== 0)
2549 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2550 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2554 /* Create the signatured type hash table from the index. */
2557 create_signatured_type_table_from_index
2558 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2559 const gdb_byte
*bytes
, offset_type elements
)
2561 gdb_assert (per_bfd
->all_type_units
.empty ());
2562 per_bfd
->all_type_units
.reserve (elements
/ 3);
2564 htab_up sig_types_hash
= allocate_signatured_type_table ();
2566 for (offset_type i
= 0; i
< elements
; i
+= 3)
2568 struct signatured_type
*sig_type
;
2571 cu_offset type_offset_in_tu
;
2573 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2574 sect_offset sect_off
2575 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2577 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2579 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2582 sig_type
= per_bfd
->allocate_signatured_type ();
2583 sig_type
->signature
= signature
;
2584 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2585 sig_type
->per_cu
.is_debug_types
= 1;
2586 sig_type
->per_cu
.section
= section
;
2587 sig_type
->per_cu
.sect_off
= sect_off
;
2588 sig_type
->per_cu
.v
.quick
2589 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2590 struct dwarf2_per_cu_quick_data
);
2592 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2595 per_bfd
->all_type_units
.push_back (sig_type
);
2598 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2601 /* Create the signatured type hash table from .debug_names. */
2604 create_signatured_type_table_from_debug_names
2605 (dwarf2_per_objfile
*per_objfile
,
2606 const mapped_debug_names
&map
,
2607 struct dwarf2_section_info
*section
,
2608 struct dwarf2_section_info
*abbrev_section
)
2610 struct objfile
*objfile
= per_objfile
->objfile
;
2612 section
->read (objfile
);
2613 abbrev_section
->read (objfile
);
2615 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2616 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2618 htab_up sig_types_hash
= allocate_signatured_type_table ();
2620 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2622 struct signatured_type
*sig_type
;
2625 sect_offset sect_off
2626 = (sect_offset
) (extract_unsigned_integer
2627 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2629 map
.dwarf5_byte_order
));
2631 comp_unit_head cu_header
;
2632 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2634 section
->buffer
+ to_underlying (sect_off
),
2637 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2638 sig_type
->signature
= cu_header
.signature
;
2639 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2640 sig_type
->per_cu
.is_debug_types
= 1;
2641 sig_type
->per_cu
.section
= section
;
2642 sig_type
->per_cu
.sect_off
= sect_off
;
2643 sig_type
->per_cu
.v
.quick
2644 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2645 struct dwarf2_per_cu_quick_data
);
2647 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2650 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2653 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2656 /* Read the address map data from the mapped index, and use it to
2657 populate the objfile's psymtabs_addrmap. */
2660 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2661 struct mapped_index
*index
)
2663 struct objfile
*objfile
= per_objfile
->objfile
;
2664 struct gdbarch
*gdbarch
= objfile
->arch ();
2665 const gdb_byte
*iter
, *end
;
2666 struct addrmap
*mutable_map
;
2669 auto_obstack temp_obstack
;
2671 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2673 iter
= index
->address_table
.data ();
2674 end
= iter
+ index
->address_table
.size ();
2676 baseaddr
= objfile
->text_section_offset ();
2680 ULONGEST hi
, lo
, cu_index
;
2681 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2683 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2685 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2690 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2691 hex_string (lo
), hex_string (hi
));
2695 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2697 complaint (_(".gdb_index address table has invalid CU number %u"),
2698 (unsigned) cu_index
);
2702 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2703 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2704 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2705 per_objfile
->per_bfd
->get_cu (cu_index
));
2708 objfile
->partial_symtabs
->psymtabs_addrmap
2709 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2712 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2713 populate the objfile's psymtabs_addrmap. */
2716 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2717 struct dwarf2_section_info
*section
)
2719 struct objfile
*objfile
= per_objfile
->objfile
;
2720 bfd
*abfd
= objfile
->obfd
;
2721 struct gdbarch
*gdbarch
= objfile
->arch ();
2722 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2724 auto_obstack temp_obstack
;
2725 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2727 std::unordered_map
<sect_offset
,
2728 dwarf2_per_cu_data
*,
2729 gdb::hash_enum
<sect_offset
>>
2730 debug_info_offset_to_per_cu
;
2731 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2733 const auto insertpair
2734 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2735 if (!insertpair
.second
)
2737 warning (_("Section .debug_aranges in %s has duplicate "
2738 "debug_info_offset %s, ignoring .debug_aranges."),
2739 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2744 section
->read (objfile
);
2746 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2748 const gdb_byte
*addr
= section
->buffer
;
2750 while (addr
< section
->buffer
+ section
->size
)
2752 const gdb_byte
*const entry_addr
= addr
;
2753 unsigned int bytes_read
;
2755 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2759 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2760 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2761 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2762 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2764 warning (_("Section .debug_aranges in %s entry at offset %s "
2765 "length %s exceeds section length %s, "
2766 "ignoring .debug_aranges."),
2767 objfile_name (objfile
),
2768 plongest (entry_addr
- section
->buffer
),
2769 plongest (bytes_read
+ entry_length
),
2770 pulongest (section
->size
));
2774 /* The version number. */
2775 const uint16_t version
= read_2_bytes (abfd
, addr
);
2779 warning (_("Section .debug_aranges in %s entry at offset %s "
2780 "has unsupported version %d, ignoring .debug_aranges."),
2781 objfile_name (objfile
),
2782 plongest (entry_addr
- section
->buffer
), version
);
2786 const uint64_t debug_info_offset
2787 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2788 addr
+= offset_size
;
2789 const auto per_cu_it
2790 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2791 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2793 warning (_("Section .debug_aranges in %s entry at offset %s "
2794 "debug_info_offset %s does not exists, "
2795 "ignoring .debug_aranges."),
2796 objfile_name (objfile
),
2797 plongest (entry_addr
- section
->buffer
),
2798 pulongest (debug_info_offset
));
2801 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2803 const uint8_t address_size
= *addr
++;
2804 if (address_size
< 1 || address_size
> 8)
2806 warning (_("Section .debug_aranges in %s entry at offset %s "
2807 "address_size %u is invalid, ignoring .debug_aranges."),
2808 objfile_name (objfile
),
2809 plongest (entry_addr
- section
->buffer
), address_size
);
2813 const uint8_t segment_selector_size
= *addr
++;
2814 if (segment_selector_size
!= 0)
2816 warning (_("Section .debug_aranges in %s entry at offset %s "
2817 "segment_selector_size %u is not supported, "
2818 "ignoring .debug_aranges."),
2819 objfile_name (objfile
),
2820 plongest (entry_addr
- section
->buffer
),
2821 segment_selector_size
);
2825 /* Must pad to an alignment boundary that is twice the address
2826 size. It is undocumented by the DWARF standard but GCC does
2828 for (size_t padding
= ((-(addr
- section
->buffer
))
2829 & (2 * address_size
- 1));
2830 padding
> 0; padding
--)
2833 warning (_("Section .debug_aranges in %s entry at offset %s "
2834 "padding is not zero, ignoring .debug_aranges."),
2835 objfile_name (objfile
),
2836 plongest (entry_addr
- section
->buffer
));
2842 if (addr
+ 2 * address_size
> entry_end
)
2844 warning (_("Section .debug_aranges in %s entry at offset %s "
2845 "address list is not properly terminated, "
2846 "ignoring .debug_aranges."),
2847 objfile_name (objfile
),
2848 plongest (entry_addr
- section
->buffer
));
2851 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2853 addr
+= address_size
;
2854 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2856 addr
+= address_size
;
2857 if (start
== 0 && length
== 0)
2859 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
2861 /* Symbol was eliminated due to a COMDAT group. */
2864 ULONGEST end
= start
+ length
;
2865 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2867 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2869 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2873 objfile
->partial_symtabs
->psymtabs_addrmap
2874 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2877 /* Find a slot in the mapped index INDEX for the object named NAME.
2878 If NAME is found, set *VEC_OUT to point to the CU vector in the
2879 constant pool and return true. If NAME cannot be found, return
2883 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2884 offset_type
**vec_out
)
2887 offset_type slot
, step
;
2888 int (*cmp
) (const char *, const char *);
2890 gdb::unique_xmalloc_ptr
<char> without_params
;
2891 if (current_language
->la_language
== language_cplus
2892 || current_language
->la_language
== language_fortran
2893 || current_language
->la_language
== language_d
)
2895 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2898 if (strchr (name
, '(') != NULL
)
2900 without_params
= cp_remove_params (name
);
2902 if (without_params
!= NULL
)
2903 name
= without_params
.get ();
2907 /* Index version 4 did not support case insensitive searches. But the
2908 indices for case insensitive languages are built in lowercase, therefore
2909 simulate our NAME being searched is also lowercased. */
2910 hash
= mapped_index_string_hash ((index
->version
== 4
2911 && case_sensitivity
== case_sensitive_off
2912 ? 5 : index
->version
),
2915 slot
= hash
& (index
->symbol_table
.size () - 1);
2916 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2917 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2923 const auto &bucket
= index
->symbol_table
[slot
];
2924 if (bucket
.name
== 0 && bucket
.vec
== 0)
2927 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2928 if (!cmp (name
, str
))
2930 *vec_out
= (offset_type
*) (index
->constant_pool
2931 + MAYBE_SWAP (bucket
.vec
));
2935 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2939 /* A helper function that reads the .gdb_index from BUFFER and fills
2940 in MAP. FILENAME is the name of the file containing the data;
2941 it is used for error reporting. DEPRECATED_OK is true if it is
2942 ok to use deprecated sections.
2944 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2945 out parameters that are filled in with information about the CU and
2946 TU lists in the section.
2948 Returns true if all went well, false otherwise. */
2951 read_gdb_index_from_buffer (const char *filename
,
2953 gdb::array_view
<const gdb_byte
> buffer
,
2954 struct mapped_index
*map
,
2955 const gdb_byte
**cu_list
,
2956 offset_type
*cu_list_elements
,
2957 const gdb_byte
**types_list
,
2958 offset_type
*types_list_elements
)
2960 const gdb_byte
*addr
= &buffer
[0];
2962 /* Version check. */
2963 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2964 /* Versions earlier than 3 emitted every copy of a psymbol. This
2965 causes the index to behave very poorly for certain requests. Version 3
2966 contained incomplete addrmap. So, it seems better to just ignore such
2970 static int warning_printed
= 0;
2971 if (!warning_printed
)
2973 warning (_("Skipping obsolete .gdb_index section in %s."),
2975 warning_printed
= 1;
2979 /* Index version 4 uses a different hash function than index version
2982 Versions earlier than 6 did not emit psymbols for inlined
2983 functions. Using these files will cause GDB not to be able to
2984 set breakpoints on inlined functions by name, so we ignore these
2985 indices unless the user has done
2986 "set use-deprecated-index-sections on". */
2987 if (version
< 6 && !deprecated_ok
)
2989 static int warning_printed
= 0;
2990 if (!warning_printed
)
2993 Skipping deprecated .gdb_index section in %s.\n\
2994 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2995 to use the section anyway."),
2997 warning_printed
= 1;
3001 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3002 of the TU (for symbols coming from TUs),
3003 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3004 Plus gold-generated indices can have duplicate entries for global symbols,
3005 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3006 These are just performance bugs, and we can't distinguish gdb-generated
3007 indices from gold-generated ones, so issue no warning here. */
3009 /* Indexes with higher version than the one supported by GDB may be no
3010 longer backward compatible. */
3014 map
->version
= version
;
3016 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3019 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3020 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3024 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3025 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3026 - MAYBE_SWAP (metadata
[i
]))
3030 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3031 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3033 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3036 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3037 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3039 = gdb::array_view
<mapped_index::symbol_table_slot
>
3040 ((mapped_index::symbol_table_slot
*) symbol_table
,
3041 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3044 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3049 /* Callback types for dwarf2_read_gdb_index. */
3051 typedef gdb::function_view
3052 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3053 get_gdb_index_contents_ftype
;
3054 typedef gdb::function_view
3055 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3056 get_gdb_index_contents_dwz_ftype
;
3058 /* Read .gdb_index. If everything went ok, initialize the "quick"
3059 elements of all the CUs and return 1. Otherwise, return 0. */
3062 dwarf2_read_gdb_index
3063 (dwarf2_per_objfile
*per_objfile
,
3064 get_gdb_index_contents_ftype get_gdb_index_contents
,
3065 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3067 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3068 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3069 struct dwz_file
*dwz
;
3070 struct objfile
*objfile
= per_objfile
->objfile
;
3071 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3073 gdb::array_view
<const gdb_byte
> main_index_contents
3074 = get_gdb_index_contents (objfile
, per_bfd
);
3076 if (main_index_contents
.empty ())
3079 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3080 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3081 use_deprecated_index_sections
,
3082 main_index_contents
, map
.get (), &cu_list
,
3083 &cu_list_elements
, &types_list
,
3084 &types_list_elements
))
3087 /* Don't use the index if it's empty. */
3088 if (map
->symbol_table
.empty ())
3091 /* If there is a .dwz file, read it so we can get its CU list as
3093 dwz
= dwarf2_get_dwz_file (per_bfd
);
3096 struct mapped_index dwz_map
;
3097 const gdb_byte
*dwz_types_ignore
;
3098 offset_type dwz_types_elements_ignore
;
3100 gdb::array_view
<const gdb_byte
> dwz_index_content
3101 = get_gdb_index_contents_dwz (objfile
, dwz
);
3103 if (dwz_index_content
.empty ())
3106 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3107 1, dwz_index_content
, &dwz_map
,
3108 &dwz_list
, &dwz_list_elements
,
3110 &dwz_types_elements_ignore
))
3112 warning (_("could not read '.gdb_index' section from %s; skipping"),
3113 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3118 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3121 if (types_list_elements
)
3123 /* We can only handle a single .debug_types when we have an
3125 if (per_bfd
->types
.size () != 1)
3128 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3130 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3131 types_list_elements
);
3134 create_addrmap_from_index (per_objfile
, map
.get ());
3136 per_bfd
->index_table
= std::move (map
);
3137 per_bfd
->using_index
= 1;
3138 per_bfd
->quick_file_names_table
=
3139 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3141 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3142 objfiles using the same BFD. */
3143 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3144 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3149 /* die_reader_func for dw2_get_file_names. */
3152 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3153 const gdb_byte
*info_ptr
,
3154 struct die_info
*comp_unit_die
)
3156 struct dwarf2_cu
*cu
= reader
->cu
;
3157 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3158 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3159 struct dwarf2_per_cu_data
*lh_cu
;
3160 struct attribute
*attr
;
3162 struct quick_file_names
*qfn
;
3164 gdb_assert (! this_cu
->is_debug_types
);
3166 /* Our callers never want to match partial units -- instead they
3167 will match the enclosing full CU. */
3168 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3170 this_cu
->v
.quick
->no_file_data
= 1;
3178 sect_offset line_offset
{};
3180 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3181 if (attr
!= nullptr)
3183 struct quick_file_names find_entry
;
3185 line_offset
= (sect_offset
) DW_UNSND (attr
);
3187 /* We may have already read in this line header (TU line header sharing).
3188 If we have we're done. */
3189 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3190 find_entry
.hash
.line_sect_off
= line_offset
;
3191 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3192 &find_entry
, INSERT
);
3195 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3199 lh
= dwarf_decode_line_header (line_offset
, cu
);
3203 lh_cu
->v
.quick
->no_file_data
= 1;
3207 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3208 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3209 qfn
->hash
.line_sect_off
= line_offset
;
3210 gdb_assert (slot
!= NULL
);
3213 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3216 if (strcmp (fnd
.name
, "<unknown>") != 0)
3219 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3221 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3222 qfn
->num_file_names
);
3224 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3225 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3226 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3227 fnd
.comp_dir
).release ();
3228 qfn
->real_names
= NULL
;
3230 lh_cu
->v
.quick
->file_names
= qfn
;
3233 /* A helper for the "quick" functions which attempts to read the line
3234 table for THIS_CU. */
3236 static struct quick_file_names
*
3237 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3238 dwarf2_per_objfile
*per_objfile
)
3240 /* This should never be called for TUs. */
3241 gdb_assert (! this_cu
->is_debug_types
);
3242 /* Nor type unit groups. */
3243 gdb_assert (! this_cu
->type_unit_group_p ());
3245 if (this_cu
->v
.quick
->file_names
!= NULL
)
3246 return this_cu
->v
.quick
->file_names
;
3247 /* If we know there is no line data, no point in looking again. */
3248 if (this_cu
->v
.quick
->no_file_data
)
3251 cutu_reader
reader (this_cu
, per_objfile
);
3252 if (!reader
.dummy_p
)
3253 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3255 if (this_cu
->v
.quick
->no_file_data
)
3257 return this_cu
->v
.quick
->file_names
;
3260 /* A helper for the "quick" functions which computes and caches the
3261 real path for a given file name from the line table. */
3264 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3265 struct quick_file_names
*qfn
, int index
)
3267 if (qfn
->real_names
== NULL
)
3268 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3269 qfn
->num_file_names
, const char *);
3271 if (qfn
->real_names
[index
] == NULL
)
3272 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3274 return qfn
->real_names
[index
];
3277 static struct symtab
*
3278 dw2_find_last_source_symtab (struct objfile
*objfile
)
3280 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3281 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3282 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3287 return compunit_primary_filetab (cust
);
3290 /* Traversal function for dw2_forget_cached_source_info. */
3293 dw2_free_cached_file_names (void **slot
, void *info
)
3295 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3297 if (file_data
->real_names
)
3301 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3303 xfree ((void*) file_data
->real_names
[i
]);
3304 file_data
->real_names
[i
] = NULL
;
3312 dw2_forget_cached_source_info (struct objfile
*objfile
)
3314 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3316 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3317 dw2_free_cached_file_names
, NULL
);
3320 /* Helper function for dw2_map_symtabs_matching_filename that expands
3321 the symtabs and calls the iterator. */
3324 dw2_map_expand_apply (struct objfile
*objfile
,
3325 struct dwarf2_per_cu_data
*per_cu
,
3326 const char *name
, const char *real_path
,
3327 gdb::function_view
<bool (symtab
*)> callback
)
3329 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3331 /* Don't visit already-expanded CUs. */
3332 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3333 if (per_objfile
->symtab_set_p (per_cu
))
3336 /* This may expand more than one symtab, and we want to iterate over
3338 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3340 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3341 last_made
, callback
);
3344 /* Implementation of the map_symtabs_matching_filename method. */
3347 dw2_map_symtabs_matching_filename
3348 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3349 gdb::function_view
<bool (symtab
*)> callback
)
3351 const char *name_basename
= lbasename (name
);
3352 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3354 /* The rule is CUs specify all the files, including those used by
3355 any TU, so there's no need to scan TUs here. */
3357 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3359 /* We only need to look at symtabs not already expanded. */
3360 if (per_objfile
->symtab_set_p (per_cu
))
3363 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3364 if (file_data
== NULL
)
3367 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3369 const char *this_name
= file_data
->file_names
[j
];
3370 const char *this_real_name
;
3372 if (compare_filenames_for_search (this_name
, name
))
3374 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3380 /* Before we invoke realpath, which can get expensive when many
3381 files are involved, do a quick comparison of the basenames. */
3382 if (! basenames_may_differ
3383 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3386 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3387 if (compare_filenames_for_search (this_real_name
, name
))
3389 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3395 if (real_path
!= NULL
)
3397 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3398 gdb_assert (IS_ABSOLUTE_PATH (name
));
3399 if (this_real_name
!= NULL
3400 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3402 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3414 /* Struct used to manage iterating over all CUs looking for a symbol. */
3416 struct dw2_symtab_iterator
3418 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3419 dwarf2_per_objfile
*per_objfile
;
3420 /* If set, only look for symbols that match that block. Valid values are
3421 GLOBAL_BLOCK and STATIC_BLOCK. */
3422 gdb::optional
<block_enum
> block_index
;
3423 /* The kind of symbol we're looking for. */
3425 /* The list of CUs from the index entry of the symbol,
3426 or NULL if not found. */
3428 /* The next element in VEC to look at. */
3430 /* The number of elements in VEC, or zero if there is no match. */
3432 /* Have we seen a global version of the symbol?
3433 If so we can ignore all further global instances.
3434 This is to work around gold/15646, inefficient gold-generated
3439 /* Initialize the index symtab iterator ITER, common part. */
3442 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3443 dwarf2_per_objfile
*per_objfile
,
3444 gdb::optional
<block_enum
> block_index
,
3447 iter
->per_objfile
= per_objfile
;
3448 iter
->block_index
= block_index
;
3449 iter
->domain
= domain
;
3451 iter
->global_seen
= 0;
3456 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3459 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3460 dwarf2_per_objfile
*per_objfile
,
3461 gdb::optional
<block_enum
> block_index
,
3465 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3467 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3468 /* index is NULL if OBJF_READNOW. */
3472 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3473 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3476 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3479 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3480 dwarf2_per_objfile
*per_objfile
,
3481 gdb::optional
<block_enum
> block_index
,
3482 domain_enum domain
, offset_type namei
)
3484 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3486 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3487 /* index is NULL if OBJF_READNOW. */
3491 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3492 const auto &bucket
= index
->symbol_table
[namei
];
3494 iter
->vec
= (offset_type
*) (index
->constant_pool
3495 + MAYBE_SWAP (bucket
.vec
));
3496 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3499 /* Return the next matching CU or NULL if there are no more. */
3501 static struct dwarf2_per_cu_data
*
3502 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3504 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3506 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3508 offset_type cu_index_and_attrs
=
3509 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3510 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3511 gdb_index_symbol_kind symbol_kind
=
3512 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3513 /* Only check the symbol attributes if they're present.
3514 Indices prior to version 7 don't record them,
3515 and indices >= 7 may elide them for certain symbols
3516 (gold does this). */
3518 (per_objfile
->per_bfd
->index_table
->version
>= 7
3519 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3521 /* Don't crash on bad data. */
3522 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3523 + per_objfile
->per_bfd
->all_type_units
.size ()))
3525 complaint (_(".gdb_index entry has bad CU index"
3526 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3530 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3532 /* Skip if already read in. */
3533 if (per_objfile
->symtab_set_p (per_cu
))
3536 /* Check static vs global. */
3539 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3541 if (iter
->block_index
.has_value ())
3543 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3545 if (is_static
!= want_static
)
3549 /* Work around gold/15646. */
3551 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3553 if (iter
->global_seen
)
3556 iter
->global_seen
= 1;
3560 /* Only check the symbol's kind if it has one. */
3563 switch (iter
->domain
)
3566 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3567 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3568 /* Some types are also in VAR_DOMAIN. */
3569 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3573 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3577 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3581 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3596 static struct compunit_symtab
*
3597 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3598 const char *name
, domain_enum domain
)
3600 struct compunit_symtab
*stab_best
= NULL
;
3601 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3603 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3605 struct dw2_symtab_iterator iter
;
3606 struct dwarf2_per_cu_data
*per_cu
;
3608 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3610 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3612 struct symbol
*sym
, *with_opaque
= NULL
;
3613 struct compunit_symtab
*stab
3614 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3615 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3616 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3618 sym
= block_find_symbol (block
, name
, domain
,
3619 block_find_non_opaque_type_preferred
,
3622 /* Some caution must be observed with overloaded functions
3623 and methods, since the index will not contain any overload
3624 information (but NAME might contain it). */
3627 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3629 if (with_opaque
!= NULL
3630 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3633 /* Keep looking through other CUs. */
3640 dw2_print_stats (struct objfile
*objfile
)
3642 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3643 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3644 + per_objfile
->per_bfd
->all_type_units
.size ());
3647 for (int i
= 0; i
< total
; ++i
)
3649 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3651 if (!per_objfile
->symtab_set_p (per_cu
))
3654 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3655 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3658 /* This dumps minimal information about the index.
3659 It is called via "mt print objfiles".
3660 One use is to verify .gdb_index has been loaded by the
3661 gdb.dwarf2/gdb-index.exp testcase. */
3664 dw2_dump (struct objfile
*objfile
)
3666 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3668 gdb_assert (per_objfile
->per_bfd
->using_index
);
3669 printf_filtered (".gdb_index:");
3670 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3672 printf_filtered (" version %d\n",
3673 per_objfile
->per_bfd
->index_table
->version
);
3676 printf_filtered (" faked for \"readnow\"\n");
3677 printf_filtered ("\n");
3681 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3682 const char *func_name
)
3684 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3686 struct dw2_symtab_iterator iter
;
3687 struct dwarf2_per_cu_data
*per_cu
;
3689 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3691 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3692 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3697 dw2_expand_all_symtabs (struct objfile
*objfile
)
3699 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3700 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3701 + per_objfile
->per_bfd
->all_type_units
.size ());
3703 for (int i
= 0; i
< total_units
; ++i
)
3705 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3707 /* We don't want to directly expand a partial CU, because if we
3708 read it with the wrong language, then assertion failures can
3709 be triggered later on. See PR symtab/23010. So, tell
3710 dw2_instantiate_symtab to skip partial CUs -- any important
3711 partial CU will be read via DW_TAG_imported_unit anyway. */
3712 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3717 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3718 const char *fullname
)
3720 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3722 /* We don't need to consider type units here.
3723 This is only called for examining code, e.g. expand_line_sal.
3724 There can be an order of magnitude (or more) more type units
3725 than comp units, and we avoid them if we can. */
3727 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3729 /* We only need to look at symtabs not already expanded. */
3730 if (per_objfile
->symtab_set_p (per_cu
))
3733 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3734 if (file_data
== NULL
)
3737 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3739 const char *this_fullname
= file_data
->file_names
[j
];
3741 if (filename_cmp (this_fullname
, fullname
) == 0)
3743 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3751 dw2_expand_symtabs_matching_symbol
3752 (mapped_index_base
&index
,
3753 const lookup_name_info
&lookup_name_in
,
3754 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3755 enum search_domain kind
,
3756 gdb::function_view
<bool (offset_type
)> match_callback
,
3757 dwarf2_per_objfile
*per_objfile
);
3760 dw2_expand_symtabs_matching_one
3761 (dwarf2_per_cu_data
*per_cu
,
3762 dwarf2_per_objfile
*per_objfile
,
3763 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3764 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3767 dw2_map_matching_symbols
3768 (struct objfile
*objfile
,
3769 const lookup_name_info
&name
, domain_enum domain
,
3771 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3772 symbol_compare_ftype
*ordered_compare
)
3775 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3777 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3779 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3781 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3783 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3784 auto matcher
= [&] (const char *symname
)
3786 if (ordered_compare
== nullptr)
3788 return ordered_compare (symname
, match_name
) == 0;
3791 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3792 [&] (offset_type namei
)
3794 struct dw2_symtab_iterator iter
;
3795 struct dwarf2_per_cu_data
*per_cu
;
3797 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3799 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3800 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3807 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3808 proceed assuming all symtabs have been read in. */
3811 for (compunit_symtab
*cust
: objfile
->compunits ())
3813 const struct block
*block
;
3817 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3818 if (!iterate_over_symbols_terminated (block
, name
,
3824 /* Starting from a search name, return the string that finds the upper
3825 bound of all strings that start with SEARCH_NAME in a sorted name
3826 list. Returns the empty string to indicate that the upper bound is
3827 the end of the list. */
3830 make_sort_after_prefix_name (const char *search_name
)
3832 /* When looking to complete "func", we find the upper bound of all
3833 symbols that start with "func" by looking for where we'd insert
3834 the closest string that would follow "func" in lexicographical
3835 order. Usually, that's "func"-with-last-character-incremented,
3836 i.e. "fund". Mind non-ASCII characters, though. Usually those
3837 will be UTF-8 multi-byte sequences, but we can't be certain.
3838 Especially mind the 0xff character, which is a valid character in
3839 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3840 rule out compilers allowing it in identifiers. Note that
3841 conveniently, strcmp/strcasecmp are specified to compare
3842 characters interpreted as unsigned char. So what we do is treat
3843 the whole string as a base 256 number composed of a sequence of
3844 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3845 to 0, and carries 1 to the following more-significant position.
3846 If the very first character in SEARCH_NAME ends up incremented
3847 and carries/overflows, then the upper bound is the end of the
3848 list. The string after the empty string is also the empty
3851 Some examples of this operation:
3853 SEARCH_NAME => "+1" RESULT
3857 "\xff" "a" "\xff" => "\xff" "b"
3862 Then, with these symbols for example:
3868 completing "func" looks for symbols between "func" and
3869 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3870 which finds "func" and "func1", but not "fund".
3874 funcÿ (Latin1 'ÿ' [0xff])
3878 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3879 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3883 ÿÿ (Latin1 'ÿ' [0xff])
3886 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3887 the end of the list.
3889 std::string after
= search_name
;
3890 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3892 if (!after
.empty ())
3893 after
.back () = (unsigned char) after
.back () + 1;
3897 /* See declaration. */
3899 std::pair
<std::vector
<name_component
>::const_iterator
,
3900 std::vector
<name_component
>::const_iterator
>
3901 mapped_index_base::find_name_components_bounds
3902 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3903 dwarf2_per_objfile
*per_objfile
) const
3906 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3908 const char *lang_name
3909 = lookup_name_without_params
.language_lookup_name (lang
);
3911 /* Comparison function object for lower_bound that matches against a
3912 given symbol name. */
3913 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3916 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3917 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3918 return name_cmp (elem_name
, name
) < 0;
3921 /* Comparison function object for upper_bound that matches against a
3922 given symbol name. */
3923 auto lookup_compare_upper
= [&] (const char *name
,
3924 const name_component
&elem
)
3926 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3927 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3928 return name_cmp (name
, elem_name
) < 0;
3931 auto begin
= this->name_components
.begin ();
3932 auto end
= this->name_components
.end ();
3934 /* Find the lower bound. */
3937 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3940 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3943 /* Find the upper bound. */
3946 if (lookup_name_without_params
.completion_mode ())
3948 /* In completion mode, we want UPPER to point past all
3949 symbols names that have the same prefix. I.e., with
3950 these symbols, and completing "func":
3952 function << lower bound
3954 other_function << upper bound
3956 We find the upper bound by looking for the insertion
3957 point of "func"-with-last-character-incremented,
3959 std::string after
= make_sort_after_prefix_name (lang_name
);
3962 return std::lower_bound (lower
, end
, after
.c_str (),
3963 lookup_compare_lower
);
3966 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3969 return {lower
, upper
};
3972 /* See declaration. */
3975 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3977 if (!this->name_components
.empty ())
3980 this->name_components_casing
= case_sensitivity
;
3982 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3984 /* The code below only knows how to break apart components of C++
3985 symbol names (and other languages that use '::' as
3986 namespace/module separator) and Ada symbol names. */
3987 auto count
= this->symbol_name_count ();
3988 for (offset_type idx
= 0; idx
< count
; idx
++)
3990 if (this->symbol_name_slot_invalid (idx
))
3993 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3995 /* Add each name component to the name component table. */
3996 unsigned int previous_len
= 0;
3998 if (strstr (name
, "::") != nullptr)
4000 for (unsigned int current_len
= cp_find_first_component (name
);
4001 name
[current_len
] != '\0';
4002 current_len
+= cp_find_first_component (name
+ current_len
))
4004 gdb_assert (name
[current_len
] == ':');
4005 this->name_components
.push_back ({previous_len
, idx
});
4006 /* Skip the '::'. */
4008 previous_len
= current_len
;
4013 /* Handle the Ada encoded (aka mangled) form here. */
4014 for (const char *iter
= strstr (name
, "__");
4016 iter
= strstr (iter
, "__"))
4018 this->name_components
.push_back ({previous_len
, idx
});
4020 previous_len
= iter
- name
;
4024 this->name_components
.push_back ({previous_len
, idx
});
4027 /* Sort name_components elements by name. */
4028 auto name_comp_compare
= [&] (const name_component
&left
,
4029 const name_component
&right
)
4031 const char *left_qualified
4032 = this->symbol_name_at (left
.idx
, per_objfile
);
4033 const char *right_qualified
4034 = this->symbol_name_at (right
.idx
, per_objfile
);
4036 const char *left_name
= left_qualified
+ left
.name_offset
;
4037 const char *right_name
= right_qualified
+ right
.name_offset
;
4039 return name_cmp (left_name
, right_name
) < 0;
4042 std::sort (this->name_components
.begin (),
4043 this->name_components
.end (),
4047 /* Helper for dw2_expand_symtabs_matching that works with a
4048 mapped_index_base instead of the containing objfile. This is split
4049 to a separate function in order to be able to unit test the
4050 name_components matching using a mock mapped_index_base. For each
4051 symbol name that matches, calls MATCH_CALLBACK, passing it the
4052 symbol's index in the mapped_index_base symbol table. */
4055 dw2_expand_symtabs_matching_symbol
4056 (mapped_index_base
&index
,
4057 const lookup_name_info
&lookup_name_in
,
4058 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4059 enum search_domain kind
,
4060 gdb::function_view
<bool (offset_type
)> match_callback
,
4061 dwarf2_per_objfile
*per_objfile
)
4063 lookup_name_info lookup_name_without_params
4064 = lookup_name_in
.make_ignore_params ();
4066 /* Build the symbol name component sorted vector, if we haven't
4068 index
.build_name_components (per_objfile
);
4070 /* The same symbol may appear more than once in the range though.
4071 E.g., if we're looking for symbols that complete "w", and we have
4072 a symbol named "w1::w2", we'll find the two name components for
4073 that same symbol in the range. To be sure we only call the
4074 callback once per symbol, we first collect the symbol name
4075 indexes that matched in a temporary vector and ignore
4077 std::vector
<offset_type
> matches
;
4079 struct name_and_matcher
4081 symbol_name_matcher_ftype
*matcher
;
4084 bool operator== (const name_and_matcher
&other
) const
4086 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4090 /* A vector holding all the different symbol name matchers, for all
4092 std::vector
<name_and_matcher
> matchers
;
4094 for (int i
= 0; i
< nr_languages
; i
++)
4096 enum language lang_e
= (enum language
) i
;
4098 const language_defn
*lang
= language_def (lang_e
);
4099 symbol_name_matcher_ftype
*name_matcher
4100 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4102 name_and_matcher key
{
4104 lookup_name_without_params
.language_lookup_name (lang_e
)
4107 /* Don't insert the same comparison routine more than once.
4108 Note that we do this linear walk. This is not a problem in
4109 practice because the number of supported languages is
4111 if (std::find (matchers
.begin (), matchers
.end (), key
)
4114 matchers
.push_back (std::move (key
));
4117 = index
.find_name_components_bounds (lookup_name_without_params
,
4118 lang_e
, per_objfile
);
4120 /* Now for each symbol name in range, check to see if we have a name
4121 match, and if so, call the MATCH_CALLBACK callback. */
4123 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4125 const char *qualified
4126 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4128 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4129 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4132 matches
.push_back (bounds
.first
->idx
);
4136 std::sort (matches
.begin (), matches
.end ());
4138 /* Finally call the callback, once per match. */
4140 for (offset_type idx
: matches
)
4144 if (!match_callback (idx
))
4150 /* Above we use a type wider than idx's for 'prev', since 0 and
4151 (offset_type)-1 are both possible values. */
4152 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4157 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4159 /* A mock .gdb_index/.debug_names-like name index table, enough to
4160 exercise dw2_expand_symtabs_matching_symbol, which works with the
4161 mapped_index_base interface. Builds an index from the symbol list
4162 passed as parameter to the constructor. */
4163 class mock_mapped_index
: public mapped_index_base
4166 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4167 : m_symbol_table (symbols
)
4170 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4172 /* Return the number of names in the symbol table. */
4173 size_t symbol_name_count () const override
4175 return m_symbol_table
.size ();
4178 /* Get the name of the symbol at IDX in the symbol table. */
4179 const char *symbol_name_at
4180 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4182 return m_symbol_table
[idx
];
4186 gdb::array_view
<const char *> m_symbol_table
;
4189 /* Convenience function that converts a NULL pointer to a "<null>"
4190 string, to pass to print routines. */
4193 string_or_null (const char *str
)
4195 return str
!= NULL
? str
: "<null>";
4198 /* Check if a lookup_name_info built from
4199 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4200 index. EXPECTED_LIST is the list of expected matches, in expected
4201 matching order. If no match expected, then an empty list is
4202 specified. Returns true on success. On failure prints a warning
4203 indicating the file:line that failed, and returns false. */
4206 check_match (const char *file
, int line
,
4207 mock_mapped_index
&mock_index
,
4208 const char *name
, symbol_name_match_type match_type
,
4209 bool completion_mode
,
4210 std::initializer_list
<const char *> expected_list
,
4211 dwarf2_per_objfile
*per_objfile
)
4213 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4215 bool matched
= true;
4217 auto mismatch
= [&] (const char *expected_str
,
4220 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4221 "expected=\"%s\", got=\"%s\"\n"),
4223 (match_type
== symbol_name_match_type::FULL
4225 name
, string_or_null (expected_str
), string_or_null (got
));
4229 auto expected_it
= expected_list
.begin ();
4230 auto expected_end
= expected_list
.end ();
4232 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4234 [&] (offset_type idx
)
4236 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4237 const char *expected_str
4238 = expected_it
== expected_end
? NULL
: *expected_it
++;
4240 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4241 mismatch (expected_str
, matched_name
);
4245 const char *expected_str
4246 = expected_it
== expected_end
? NULL
: *expected_it
++;
4247 if (expected_str
!= NULL
)
4248 mismatch (expected_str
, NULL
);
4253 /* The symbols added to the mock mapped_index for testing (in
4255 static const char *test_symbols
[] = {
4264 "ns2::tmpl<int>::foo2",
4265 "(anonymous namespace)::A::B::C",
4267 /* These are used to check that the increment-last-char in the
4268 matching algorithm for completion doesn't match "t1_fund" when
4269 completing "t1_func". */
4275 /* A UTF-8 name with multi-byte sequences to make sure that
4276 cp-name-parser understands this as a single identifier ("função"
4277 is "function" in PT). */
4280 /* \377 (0xff) is Latin1 'ÿ'. */
4283 /* \377 (0xff) is Latin1 'ÿ'. */
4287 /* A name with all sorts of complications. Starts with "z" to make
4288 it easier for the completion tests below. */
4289 #define Z_SYM_NAME \
4290 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4291 "::tuple<(anonymous namespace)::ui*, " \
4292 "std::default_delete<(anonymous namespace)::ui>, void>"
4297 /* Returns true if the mapped_index_base::find_name_component_bounds
4298 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4299 in completion mode. */
4302 check_find_bounds_finds (mapped_index_base
&index
,
4303 const char *search_name
,
4304 gdb::array_view
<const char *> expected_syms
,
4305 dwarf2_per_objfile
*per_objfile
)
4307 lookup_name_info
lookup_name (search_name
,
4308 symbol_name_match_type::FULL
, true);
4310 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4314 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4315 if (distance
!= expected_syms
.size ())
4318 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4320 auto nc_elem
= bounds
.first
+ exp_elem
;
4321 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4322 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4329 /* Test the lower-level mapped_index::find_name_component_bounds
4333 test_mapped_index_find_name_component_bounds ()
4335 mock_mapped_index
mock_index (test_symbols
);
4337 mock_index
.build_name_components (NULL
/* per_objfile */);
4339 /* Test the lower-level mapped_index::find_name_component_bounds
4340 method in completion mode. */
4342 static const char *expected_syms
[] = {
4347 SELF_CHECK (check_find_bounds_finds
4348 (mock_index
, "t1_func", expected_syms
,
4349 NULL
/* per_objfile */));
4352 /* Check that the increment-last-char in the name matching algorithm
4353 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4355 static const char *expected_syms1
[] = {
4359 SELF_CHECK (check_find_bounds_finds
4360 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4362 static const char *expected_syms2
[] = {
4365 SELF_CHECK (check_find_bounds_finds
4366 (mock_index
, "\377\377", expected_syms2
,
4367 NULL
/* per_objfile */));
4371 /* Test dw2_expand_symtabs_matching_symbol. */
4374 test_dw2_expand_symtabs_matching_symbol ()
4376 mock_mapped_index
mock_index (test_symbols
);
4378 /* We let all tests run until the end even if some fails, for debug
4380 bool any_mismatch
= false;
4382 /* Create the expected symbols list (an initializer_list). Needed
4383 because lists have commas, and we need to pass them to CHECK,
4384 which is a macro. */
4385 #define EXPECT(...) { __VA_ARGS__ }
4387 /* Wrapper for check_match that passes down the current
4388 __FILE__/__LINE__. */
4389 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4390 any_mismatch |= !check_match (__FILE__, __LINE__, \
4392 NAME, MATCH_TYPE, COMPLETION_MODE, \
4393 EXPECTED_LIST, NULL)
4395 /* Identity checks. */
4396 for (const char *sym
: test_symbols
)
4398 /* Should be able to match all existing symbols. */
4399 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4402 /* Should be able to match all existing symbols with
4404 std::string with_params
= std::string (sym
) + "(int)";
4405 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4408 /* Should be able to match all existing symbols with
4409 parameters and qualifiers. */
4410 with_params
= std::string (sym
) + " ( int ) const";
4411 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4414 /* This should really find sym, but cp-name-parser.y doesn't
4415 know about lvalue/rvalue qualifiers yet. */
4416 with_params
= std::string (sym
) + " ( int ) &&";
4417 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4421 /* Check that the name matching algorithm for completion doesn't get
4422 confused with Latin1 'ÿ' / 0xff. */
4424 static const char str
[] = "\377";
4425 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4426 EXPECT ("\377", "\377\377123"));
4429 /* Check that the increment-last-char in the matching algorithm for
4430 completion doesn't match "t1_fund" when completing "t1_func". */
4432 static const char str
[] = "t1_func";
4433 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4434 EXPECT ("t1_func", "t1_func1"));
4437 /* Check that completion mode works at each prefix of the expected
4440 static const char str
[] = "function(int)";
4441 size_t len
= strlen (str
);
4444 for (size_t i
= 1; i
< len
; i
++)
4446 lookup
.assign (str
, i
);
4447 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4448 EXPECT ("function"));
4452 /* While "w" is a prefix of both components, the match function
4453 should still only be called once. */
4455 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4457 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4461 /* Same, with a "complicated" symbol. */
4463 static const char str
[] = Z_SYM_NAME
;
4464 size_t len
= strlen (str
);
4467 for (size_t i
= 1; i
< len
; i
++)
4469 lookup
.assign (str
, i
);
4470 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4471 EXPECT (Z_SYM_NAME
));
4475 /* In FULL mode, an incomplete symbol doesn't match. */
4477 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4481 /* A complete symbol with parameters matches any overload, since the
4482 index has no overload info. */
4484 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4485 EXPECT ("std::zfunction", "std::zfunction2"));
4486 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4487 EXPECT ("std::zfunction", "std::zfunction2"));
4488 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4489 EXPECT ("std::zfunction", "std::zfunction2"));
4492 /* Check that whitespace is ignored appropriately. A symbol with a
4493 template argument list. */
4495 static const char expected
[] = "ns::foo<int>";
4496 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4498 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4502 /* Check that whitespace is ignored appropriately. A symbol with a
4503 template argument list that includes a pointer. */
4505 static const char expected
[] = "ns::foo<char*>";
4506 /* Try both completion and non-completion modes. */
4507 static const bool completion_mode
[2] = {false, true};
4508 for (size_t i
= 0; i
< 2; i
++)
4510 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4511 completion_mode
[i
], EXPECT (expected
));
4512 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4513 completion_mode
[i
], EXPECT (expected
));
4515 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4516 completion_mode
[i
], EXPECT (expected
));
4517 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4518 completion_mode
[i
], EXPECT (expected
));
4523 /* Check method qualifiers are ignored. */
4524 static const char expected
[] = "ns::foo<char*>";
4525 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4526 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4527 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4528 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4529 CHECK_MATCH ("foo < char * > ( int ) const",
4530 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4531 CHECK_MATCH ("foo < char * > ( int ) &&",
4532 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4535 /* Test lookup names that don't match anything. */
4537 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4540 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4544 /* Some wild matching tests, exercising "(anonymous namespace)",
4545 which should not be confused with a parameter list. */
4547 static const char *syms
[] = {
4551 "A :: B :: C ( int )",
4556 for (const char *s
: syms
)
4558 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4559 EXPECT ("(anonymous namespace)::A::B::C"));
4564 static const char expected
[] = "ns2::tmpl<int>::foo2";
4565 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4567 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4571 SELF_CHECK (!any_mismatch
);
4580 test_mapped_index_find_name_component_bounds ();
4581 test_dw2_expand_symtabs_matching_symbol ();
4584 }} // namespace selftests::dw2_expand_symtabs_matching
4586 #endif /* GDB_SELF_TEST */
4588 /* If FILE_MATCHER is NULL or if PER_CU has
4589 dwarf2_per_cu_quick_data::MARK set (see
4590 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4591 EXPANSION_NOTIFY on it. */
4594 dw2_expand_symtabs_matching_one
4595 (dwarf2_per_cu_data
*per_cu
,
4596 dwarf2_per_objfile
*per_objfile
,
4597 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4598 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4600 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4602 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4604 compunit_symtab
*symtab
4605 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4606 gdb_assert (symtab
!= nullptr);
4608 if (expansion_notify
!= NULL
&& symtab_was_null
)
4609 expansion_notify (symtab
);
4613 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4614 matched, to expand corresponding CUs that were marked. IDX is the
4615 index of the symbol name that matched. */
4618 dw2_expand_marked_cus
4619 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4620 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4621 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4624 offset_type
*vec
, vec_len
, vec_idx
;
4625 bool global_seen
= false;
4626 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4628 vec
= (offset_type
*) (index
.constant_pool
4629 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4630 vec_len
= MAYBE_SWAP (vec
[0]);
4631 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4633 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4634 /* This value is only valid for index versions >= 7. */
4635 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4636 gdb_index_symbol_kind symbol_kind
=
4637 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4638 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4639 /* Only check the symbol attributes if they're present.
4640 Indices prior to version 7 don't record them,
4641 and indices >= 7 may elide them for certain symbols
4642 (gold does this). */
4645 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4647 /* Work around gold/15646. */
4650 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4658 /* Only check the symbol's kind if it has one. */
4663 case VARIABLES_DOMAIN
:
4664 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4667 case FUNCTIONS_DOMAIN
:
4668 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4672 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4675 case MODULES_DOMAIN
:
4676 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4684 /* Don't crash on bad data. */
4685 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4686 + per_objfile
->per_bfd
->all_type_units
.size ()))
4688 complaint (_(".gdb_index entry has bad CU index"
4689 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4693 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4694 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4699 /* If FILE_MATCHER is non-NULL, set all the
4700 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4701 that match FILE_MATCHER. */
4704 dw_expand_symtabs_matching_file_matcher
4705 (dwarf2_per_objfile
*per_objfile
,
4706 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4708 if (file_matcher
== NULL
)
4711 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4713 NULL
, xcalloc
, xfree
));
4714 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4716 NULL
, xcalloc
, xfree
));
4718 /* The rule is CUs specify all the files, including those used by
4719 any TU, so there's no need to scan TUs here. */
4721 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4725 per_cu
->v
.quick
->mark
= 0;
4727 /* We only need to look at symtabs not already expanded. */
4728 if (per_objfile
->symtab_set_p (per_cu
))
4731 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4732 if (file_data
== NULL
)
4735 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4737 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4739 per_cu
->v
.quick
->mark
= 1;
4743 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4745 const char *this_real_name
;
4747 if (file_matcher (file_data
->file_names
[j
], false))
4749 per_cu
->v
.quick
->mark
= 1;
4753 /* Before we invoke realpath, which can get expensive when many
4754 files are involved, do a quick comparison of the basenames. */
4755 if (!basenames_may_differ
4756 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4760 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4761 if (file_matcher (this_real_name
, false))
4763 per_cu
->v
.quick
->mark
= 1;
4768 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4769 ? visited_found
.get ()
4770 : visited_not_found
.get (),
4777 dw2_expand_symtabs_matching
4778 (struct objfile
*objfile
,
4779 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4780 const lookup_name_info
*lookup_name
,
4781 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4782 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4783 enum search_domain kind
)
4785 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4787 /* index_table is NULL if OBJF_READNOW. */
4788 if (!per_objfile
->per_bfd
->index_table
)
4791 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4793 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4795 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4799 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4800 file_matcher
, expansion_notify
);
4805 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4807 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4809 kind
, [&] (offset_type idx
)
4811 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4817 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4820 static struct compunit_symtab
*
4821 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4826 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4827 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4830 if (cust
->includes
== NULL
)
4833 for (i
= 0; cust
->includes
[i
]; ++i
)
4835 struct compunit_symtab
*s
= cust
->includes
[i
];
4837 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4845 static struct compunit_symtab
*
4846 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4847 struct bound_minimal_symbol msymbol
,
4849 struct obj_section
*section
,
4852 struct dwarf2_per_cu_data
*data
;
4853 struct compunit_symtab
*result
;
4855 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4858 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4859 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4860 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4864 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4865 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4866 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4867 paddress (objfile
->arch (), pc
));
4869 result
= recursively_find_pc_sect_compunit_symtab
4870 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4872 gdb_assert (result
!= NULL
);
4877 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4878 void *data
, int need_fullname
)
4880 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4882 if (!per_objfile
->per_bfd
->filenames_cache
)
4884 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4886 htab_up
visited (htab_create_alloc (10,
4887 htab_hash_pointer
, htab_eq_pointer
,
4888 NULL
, xcalloc
, xfree
));
4890 /* The rule is CUs specify all the files, including those used
4891 by any TU, so there's no need to scan TUs here. We can
4892 ignore file names coming from already-expanded CUs. */
4894 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4896 if (per_objfile
->symtab_set_p (per_cu
))
4898 void **slot
= htab_find_slot (visited
.get (),
4899 per_cu
->v
.quick
->file_names
,
4902 *slot
= per_cu
->v
.quick
->file_names
;
4906 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4908 /* We only need to look at symtabs not already expanded. */
4909 if (per_objfile
->symtab_set_p (per_cu
))
4912 quick_file_names
*file_data
4913 = dw2_get_file_names (per_cu
, per_objfile
);
4914 if (file_data
== NULL
)
4917 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4920 /* Already visited. */
4925 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4927 const char *filename
= file_data
->file_names
[j
];
4928 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4933 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4935 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4938 this_real_name
= gdb_realpath (filename
);
4939 (*fun
) (filename
, this_real_name
.get (), data
);
4944 dw2_has_symbols (struct objfile
*objfile
)
4949 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4952 dw2_find_last_source_symtab
,
4953 dw2_forget_cached_source_info
,
4954 dw2_map_symtabs_matching_filename
,
4959 dw2_expand_symtabs_for_function
,
4960 dw2_expand_all_symtabs
,
4961 dw2_expand_symtabs_with_fullname
,
4962 dw2_map_matching_symbols
,
4963 dw2_expand_symtabs_matching
,
4964 dw2_find_pc_sect_compunit_symtab
,
4966 dw2_map_symbol_filenames
4969 /* DWARF-5 debug_names reader. */
4971 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4972 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4974 /* A helper function that reads the .debug_names section in SECTION
4975 and fills in MAP. FILENAME is the name of the file containing the
4976 section; it is used for error reporting.
4978 Returns true if all went well, false otherwise. */
4981 read_debug_names_from_section (struct objfile
*objfile
,
4982 const char *filename
,
4983 struct dwarf2_section_info
*section
,
4984 mapped_debug_names
&map
)
4986 if (section
->empty ())
4989 /* Older elfutils strip versions could keep the section in the main
4990 executable while splitting it for the separate debug info file. */
4991 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4994 section
->read (objfile
);
4996 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4998 const gdb_byte
*addr
= section
->buffer
;
5000 bfd
*const abfd
= section
->get_bfd_owner ();
5002 unsigned int bytes_read
;
5003 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5006 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5007 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5008 if (bytes_read
+ length
!= section
->size
)
5010 /* There may be multiple per-CU indices. */
5011 warning (_("Section .debug_names in %s length %s does not match "
5012 "section length %s, ignoring .debug_names."),
5013 filename
, plongest (bytes_read
+ length
),
5014 pulongest (section
->size
));
5018 /* The version number. */
5019 uint16_t version
= read_2_bytes (abfd
, addr
);
5023 warning (_("Section .debug_names in %s has unsupported version %d, "
5024 "ignoring .debug_names."),
5030 uint16_t padding
= read_2_bytes (abfd
, addr
);
5034 warning (_("Section .debug_names in %s has unsupported padding %d, "
5035 "ignoring .debug_names."),
5040 /* comp_unit_count - The number of CUs in the CU list. */
5041 map
.cu_count
= read_4_bytes (abfd
, addr
);
5044 /* local_type_unit_count - The number of TUs in the local TU
5046 map
.tu_count
= read_4_bytes (abfd
, addr
);
5049 /* foreign_type_unit_count - The number of TUs in the foreign TU
5051 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5053 if (foreign_tu_count
!= 0)
5055 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5056 "ignoring .debug_names."),
5057 filename
, static_cast<unsigned long> (foreign_tu_count
));
5061 /* bucket_count - The number of hash buckets in the hash lookup
5063 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5066 /* name_count - The number of unique names in the index. */
5067 map
.name_count
= read_4_bytes (abfd
, addr
);
5070 /* abbrev_table_size - The size in bytes of the abbreviations
5072 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5075 /* augmentation_string_size - The size in bytes of the augmentation
5076 string. This value is rounded up to a multiple of 4. */
5077 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5079 map
.augmentation_is_gdb
= ((augmentation_string_size
5080 == sizeof (dwarf5_augmentation
))
5081 && memcmp (addr
, dwarf5_augmentation
,
5082 sizeof (dwarf5_augmentation
)) == 0);
5083 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5084 addr
+= augmentation_string_size
;
5087 map
.cu_table_reordered
= addr
;
5088 addr
+= map
.cu_count
* map
.offset_size
;
5090 /* List of Local TUs */
5091 map
.tu_table_reordered
= addr
;
5092 addr
+= map
.tu_count
* map
.offset_size
;
5094 /* Hash Lookup Table */
5095 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5096 addr
+= map
.bucket_count
* 4;
5097 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5098 addr
+= map
.name_count
* 4;
5101 map
.name_table_string_offs_reordered
= addr
;
5102 addr
+= map
.name_count
* map
.offset_size
;
5103 map
.name_table_entry_offs_reordered
= addr
;
5104 addr
+= map
.name_count
* map
.offset_size
;
5106 const gdb_byte
*abbrev_table_start
= addr
;
5109 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5114 const auto insertpair
5115 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5116 if (!insertpair
.second
)
5118 warning (_("Section .debug_names in %s has duplicate index %s, "
5119 "ignoring .debug_names."),
5120 filename
, pulongest (index_num
));
5123 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5124 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5129 mapped_debug_names::index_val::attr attr
;
5130 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5132 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5134 if (attr
.form
== DW_FORM_implicit_const
)
5136 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5140 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5142 indexval
.attr_vec
.push_back (std::move (attr
));
5145 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5147 warning (_("Section .debug_names in %s has abbreviation_table "
5148 "of size %s vs. written as %u, ignoring .debug_names."),
5149 filename
, plongest (addr
- abbrev_table_start
),
5153 map
.entry_pool
= addr
;
5158 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5162 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5163 const mapped_debug_names
&map
,
5164 dwarf2_section_info
§ion
,
5167 if (!map
.augmentation_is_gdb
)
5169 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5171 sect_offset sect_off
5172 = (sect_offset
) (extract_unsigned_integer
5173 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5175 map
.dwarf5_byte_order
));
5176 /* We don't know the length of the CU, because the CU list in a
5177 .debug_names index can be incomplete, so we can't use the start of
5178 the next CU as end of this CU. We create the CUs here with length 0,
5179 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5180 dwarf2_per_cu_data
*per_cu
5181 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5182 per_bfd
->all_comp_units
.push_back (per_cu
);
5186 sect_offset sect_off_prev
;
5187 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5189 sect_offset sect_off_next
;
5190 if (i
< map
.cu_count
)
5193 = (sect_offset
) (extract_unsigned_integer
5194 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5196 map
.dwarf5_byte_order
));
5199 sect_off_next
= (sect_offset
) section
.size
;
5202 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5203 dwarf2_per_cu_data
*per_cu
5204 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5205 sect_off_prev
, length
);
5206 per_bfd
->all_comp_units
.push_back (per_cu
);
5208 sect_off_prev
= sect_off_next
;
5212 /* Read the CU list from the mapped index, and use it to create all
5213 the CU objects for this dwarf2_per_objfile. */
5216 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5217 const mapped_debug_names
&map
,
5218 const mapped_debug_names
&dwz_map
)
5220 gdb_assert (per_bfd
->all_comp_units
.empty ());
5221 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5223 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5224 false /* is_dwz */);
5226 if (dwz_map
.cu_count
== 0)
5229 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5230 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5234 /* Read .debug_names. If everything went ok, initialize the "quick"
5235 elements of all the CUs and return true. Otherwise, return false. */
5238 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5240 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5241 mapped_debug_names dwz_map
;
5242 struct objfile
*objfile
= per_objfile
->objfile
;
5243 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5245 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5246 &per_objfile
->per_bfd
->debug_names
, *map
))
5249 /* Don't use the index if it's empty. */
5250 if (map
->name_count
== 0)
5253 /* If there is a .dwz file, read it so we can get its CU list as
5255 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5258 if (!read_debug_names_from_section (objfile
,
5259 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5260 &dwz
->debug_names
, dwz_map
))
5262 warning (_("could not read '.debug_names' section from %s; skipping"),
5263 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5268 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5270 if (map
->tu_count
!= 0)
5272 /* We can only handle a single .debug_types when we have an
5274 if (per_bfd
->types
.size () != 1)
5277 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5279 create_signatured_type_table_from_debug_names
5280 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5283 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5285 per_bfd
->debug_names_table
= std::move (map
);
5286 per_bfd
->using_index
= 1;
5287 per_bfd
->quick_file_names_table
=
5288 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5290 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5291 objfiles using the same BFD. */
5292 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5293 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5298 /* Type used to manage iterating over all CUs looking for a symbol for
5301 class dw2_debug_names_iterator
5304 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5305 gdb::optional
<block_enum
> block_index
,
5307 const char *name
, dwarf2_per_objfile
*per_objfile
)
5308 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5309 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5310 m_per_objfile (per_objfile
)
5313 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5314 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5317 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5318 m_per_objfile (per_objfile
)
5321 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5322 block_enum block_index
, domain_enum domain
,
5323 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5324 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5325 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5326 m_per_objfile (per_objfile
)
5329 /* Return the next matching CU or NULL if there are no more. */
5330 dwarf2_per_cu_data
*next ();
5333 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5335 dwarf2_per_objfile
*per_objfile
);
5336 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5338 dwarf2_per_objfile
*per_objfile
);
5340 /* The internalized form of .debug_names. */
5341 const mapped_debug_names
&m_map
;
5343 /* If set, only look for symbols that match that block. Valid values are
5344 GLOBAL_BLOCK and STATIC_BLOCK. */
5345 const gdb::optional
<block_enum
> m_block_index
;
5347 /* The kind of symbol we're looking for. */
5348 const domain_enum m_domain
= UNDEF_DOMAIN
;
5349 const search_domain m_search
= ALL_DOMAIN
;
5351 /* The list of CUs from the index entry of the symbol, or NULL if
5353 const gdb_byte
*m_addr
;
5355 dwarf2_per_objfile
*m_per_objfile
;
5359 mapped_debug_names::namei_to_name
5360 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5362 const ULONGEST namei_string_offs
5363 = extract_unsigned_integer ((name_table_string_offs_reordered
5364 + namei
* offset_size
),
5367 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5370 /* Find a slot in .debug_names for the object named NAME. If NAME is
5371 found, return pointer to its pool data. If NAME cannot be found,
5375 dw2_debug_names_iterator::find_vec_in_debug_names
5376 (const mapped_debug_names
&map
, const char *name
,
5377 dwarf2_per_objfile
*per_objfile
)
5379 int (*cmp
) (const char *, const char *);
5381 gdb::unique_xmalloc_ptr
<char> without_params
;
5382 if (current_language
->la_language
== language_cplus
5383 || current_language
->la_language
== language_fortran
5384 || current_language
->la_language
== language_d
)
5386 /* NAME is already canonical. Drop any qualifiers as
5387 .debug_names does not contain any. */
5389 if (strchr (name
, '(') != NULL
)
5391 without_params
= cp_remove_params (name
);
5392 if (without_params
!= NULL
)
5393 name
= without_params
.get ();
5397 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5399 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5401 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5402 (map
.bucket_table_reordered
5403 + (full_hash
% map
.bucket_count
)), 4,
5404 map
.dwarf5_byte_order
);
5408 if (namei
>= map
.name_count
)
5410 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5412 namei
, map
.name_count
,
5413 objfile_name (per_objfile
->objfile
));
5419 const uint32_t namei_full_hash
5420 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5421 (map
.hash_table_reordered
+ namei
), 4,
5422 map
.dwarf5_byte_order
);
5423 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5426 if (full_hash
== namei_full_hash
)
5428 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5430 #if 0 /* An expensive sanity check. */
5431 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5433 complaint (_("Wrong .debug_names hash for string at index %u "
5435 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5440 if (cmp (namei_string
, name
) == 0)
5442 const ULONGEST namei_entry_offs
5443 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5444 + namei
* map
.offset_size
),
5445 map
.offset_size
, map
.dwarf5_byte_order
);
5446 return map
.entry_pool
+ namei_entry_offs
;
5451 if (namei
>= map
.name_count
)
5457 dw2_debug_names_iterator::find_vec_in_debug_names
5458 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5460 if (namei
>= map
.name_count
)
5462 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5464 namei
, map
.name_count
,
5465 objfile_name (per_objfile
->objfile
));
5469 const ULONGEST namei_entry_offs
5470 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5471 + namei
* map
.offset_size
),
5472 map
.offset_size
, map
.dwarf5_byte_order
);
5473 return map
.entry_pool
+ namei_entry_offs
;
5476 /* See dw2_debug_names_iterator. */
5478 dwarf2_per_cu_data
*
5479 dw2_debug_names_iterator::next ()
5484 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5485 struct objfile
*objfile
= m_per_objfile
->objfile
;
5486 bfd
*const abfd
= objfile
->obfd
;
5490 unsigned int bytes_read
;
5491 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5492 m_addr
+= bytes_read
;
5496 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5497 if (indexval_it
== m_map
.abbrev_map
.cend ())
5499 complaint (_("Wrong .debug_names undefined abbrev code %s "
5501 pulongest (abbrev
), objfile_name (objfile
));
5504 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5505 enum class symbol_linkage
{
5509 } symbol_linkage_
= symbol_linkage::unknown
;
5510 dwarf2_per_cu_data
*per_cu
= NULL
;
5511 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5516 case DW_FORM_implicit_const
:
5517 ull
= attr
.implicit_const
;
5519 case DW_FORM_flag_present
:
5523 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5524 m_addr
+= bytes_read
;
5527 ull
= read_4_bytes (abfd
, m_addr
);
5531 ull
= read_8_bytes (abfd
, m_addr
);
5534 case DW_FORM_ref_sig8
:
5535 ull
= read_8_bytes (abfd
, m_addr
);
5539 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5540 dwarf_form_name (attr
.form
),
5541 objfile_name (objfile
));
5544 switch (attr
.dw_idx
)
5546 case DW_IDX_compile_unit
:
5547 /* Don't crash on bad data. */
5548 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5550 complaint (_(".debug_names entry has bad CU index %s"
5553 objfile_name (objfile
));
5556 per_cu
= per_bfd
->get_cutu (ull
);
5558 case DW_IDX_type_unit
:
5559 /* Don't crash on bad data. */
5560 if (ull
>= per_bfd
->all_type_units
.size ())
5562 complaint (_(".debug_names entry has bad TU index %s"
5565 objfile_name (objfile
));
5568 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5570 case DW_IDX_die_offset
:
5571 /* In a per-CU index (as opposed to a per-module index), index
5572 entries without CU attribute implicitly refer to the single CU. */
5574 per_cu
= per_bfd
->get_cu (0);
5576 case DW_IDX_GNU_internal
:
5577 if (!m_map
.augmentation_is_gdb
)
5579 symbol_linkage_
= symbol_linkage::static_
;
5581 case DW_IDX_GNU_external
:
5582 if (!m_map
.augmentation_is_gdb
)
5584 symbol_linkage_
= symbol_linkage::extern_
;
5589 /* Skip if already read in. */
5590 if (m_per_objfile
->symtab_set_p (per_cu
))
5593 /* Check static vs global. */
5594 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5596 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5597 const bool symbol_is_static
=
5598 symbol_linkage_
== symbol_linkage::static_
;
5599 if (want_static
!= symbol_is_static
)
5603 /* Match dw2_symtab_iter_next, symbol_kind
5604 and debug_names::psymbol_tag. */
5608 switch (indexval
.dwarf_tag
)
5610 case DW_TAG_variable
:
5611 case DW_TAG_subprogram
:
5612 /* Some types are also in VAR_DOMAIN. */
5613 case DW_TAG_typedef
:
5614 case DW_TAG_structure_type
:
5621 switch (indexval
.dwarf_tag
)
5623 case DW_TAG_typedef
:
5624 case DW_TAG_structure_type
:
5631 switch (indexval
.dwarf_tag
)
5634 case DW_TAG_variable
:
5641 switch (indexval
.dwarf_tag
)
5653 /* Match dw2_expand_symtabs_matching, symbol_kind and
5654 debug_names::psymbol_tag. */
5657 case VARIABLES_DOMAIN
:
5658 switch (indexval
.dwarf_tag
)
5660 case DW_TAG_variable
:
5666 case FUNCTIONS_DOMAIN
:
5667 switch (indexval
.dwarf_tag
)
5669 case DW_TAG_subprogram
:
5676 switch (indexval
.dwarf_tag
)
5678 case DW_TAG_typedef
:
5679 case DW_TAG_structure_type
:
5685 case MODULES_DOMAIN
:
5686 switch (indexval
.dwarf_tag
)
5700 static struct compunit_symtab
*
5701 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5702 const char *name
, domain_enum domain
)
5704 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5706 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5709 /* index is NULL if OBJF_READNOW. */
5712 const auto &map
= *mapp
;
5714 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5716 struct compunit_symtab
*stab_best
= NULL
;
5717 struct dwarf2_per_cu_data
*per_cu
;
5718 while ((per_cu
= iter
.next ()) != NULL
)
5720 struct symbol
*sym
, *with_opaque
= NULL
;
5721 compunit_symtab
*stab
5722 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5723 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5724 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5726 sym
= block_find_symbol (block
, name
, domain
,
5727 block_find_non_opaque_type_preferred
,
5730 /* Some caution must be observed with overloaded functions and
5731 methods, since the index will not contain any overload
5732 information (but NAME might contain it). */
5735 && strcmp_iw (sym
->search_name (), name
) == 0)
5737 if (with_opaque
!= NULL
5738 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5741 /* Keep looking through other CUs. */
5747 /* This dumps minimal information about .debug_names. It is called
5748 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5749 uses this to verify that .debug_names has been loaded. */
5752 dw2_debug_names_dump (struct objfile
*objfile
)
5754 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5756 gdb_assert (per_objfile
->per_bfd
->using_index
);
5757 printf_filtered (".debug_names:");
5758 if (per_objfile
->per_bfd
->debug_names_table
)
5759 printf_filtered (" exists\n");
5761 printf_filtered (" faked for \"readnow\"\n");
5762 printf_filtered ("\n");
5766 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5767 const char *func_name
)
5769 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5771 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5772 if (per_objfile
->per_bfd
->debug_names_table
)
5774 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5776 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5779 struct dwarf2_per_cu_data
*per_cu
;
5780 while ((per_cu
= iter
.next ()) != NULL
)
5781 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5786 dw2_debug_names_map_matching_symbols
5787 (struct objfile
*objfile
,
5788 const lookup_name_info
&name
, domain_enum domain
,
5790 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5791 symbol_compare_ftype
*ordered_compare
)
5793 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5795 /* debug_names_table is NULL if OBJF_READNOW. */
5796 if (!per_objfile
->per_bfd
->debug_names_table
)
5799 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5800 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5802 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5803 auto matcher
= [&] (const char *symname
)
5805 if (ordered_compare
== nullptr)
5807 return ordered_compare (symname
, match_name
) == 0;
5810 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5811 [&] (offset_type namei
)
5813 /* The name was matched, now expand corresponding CUs that were
5815 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5818 struct dwarf2_per_cu_data
*per_cu
;
5819 while ((per_cu
= iter
.next ()) != NULL
)
5820 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5825 /* It's a shame we couldn't do this inside the
5826 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5827 that have already been expanded. Instead, this loop matches what
5828 the psymtab code does. */
5829 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5831 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5832 if (symtab
!= nullptr)
5834 const struct block
*block
5835 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5836 if (!iterate_over_symbols_terminated (block
, name
,
5844 dw2_debug_names_expand_symtabs_matching
5845 (struct objfile
*objfile
,
5846 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5847 const lookup_name_info
*lookup_name
,
5848 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5849 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5850 enum search_domain kind
)
5852 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5854 /* debug_names_table is NULL if OBJF_READNOW. */
5855 if (!per_objfile
->per_bfd
->debug_names_table
)
5858 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5860 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5862 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5866 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5872 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5874 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5876 kind
, [&] (offset_type namei
)
5878 /* The name was matched, now expand corresponding CUs that were
5880 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5882 struct dwarf2_per_cu_data
*per_cu
;
5883 while ((per_cu
= iter
.next ()) != NULL
)
5884 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5890 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5893 dw2_find_last_source_symtab
,
5894 dw2_forget_cached_source_info
,
5895 dw2_map_symtabs_matching_filename
,
5896 dw2_debug_names_lookup_symbol
,
5899 dw2_debug_names_dump
,
5900 dw2_debug_names_expand_symtabs_for_function
,
5901 dw2_expand_all_symtabs
,
5902 dw2_expand_symtabs_with_fullname
,
5903 dw2_debug_names_map_matching_symbols
,
5904 dw2_debug_names_expand_symtabs_matching
,
5905 dw2_find_pc_sect_compunit_symtab
,
5907 dw2_map_symbol_filenames
5910 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5911 to either a dwarf2_per_bfd or dwz_file object. */
5913 template <typename T
>
5914 static gdb::array_view
<const gdb_byte
>
5915 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5917 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5919 if (section
->empty ())
5922 /* Older elfutils strip versions could keep the section in the main
5923 executable while splitting it for the separate debug info file. */
5924 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5927 section
->read (obj
);
5929 /* dwarf2_section_info::size is a bfd_size_type, while
5930 gdb::array_view works with size_t. On 32-bit hosts, with
5931 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5932 is 32-bit. So we need an explicit narrowing conversion here.
5933 This is fine, because it's impossible to allocate or mmap an
5934 array/buffer larger than what size_t can represent. */
5935 return gdb::make_array_view (section
->buffer
, section
->size
);
5938 /* Lookup the index cache for the contents of the index associated to
5941 static gdb::array_view
<const gdb_byte
>
5942 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5944 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5945 if (build_id
== nullptr)
5948 return global_index_cache
.lookup_gdb_index (build_id
,
5949 &dwarf2_per_bfd
->index_cache_res
);
5952 /* Same as the above, but for DWZ. */
5954 static gdb::array_view
<const gdb_byte
>
5955 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5957 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5958 if (build_id
== nullptr)
5961 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5964 /* See symfile.h. */
5967 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5969 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5970 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5972 /* If we're about to read full symbols, don't bother with the
5973 indices. In this case we also don't care if some other debug
5974 format is making psymtabs, because they are all about to be
5976 if ((objfile
->flags
& OBJF_READNOW
))
5978 /* When using READNOW, the using_index flag (set below) indicates that
5979 PER_BFD was already initialized, when we loaded some other objfile. */
5980 if (per_bfd
->using_index
)
5982 *index_kind
= dw_index_kind::GDB_INDEX
;
5983 per_objfile
->resize_symtabs ();
5987 per_bfd
->using_index
= 1;
5988 create_all_comp_units (per_objfile
);
5989 create_all_type_units (per_objfile
);
5990 per_bfd
->quick_file_names_table
5991 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5992 per_objfile
->resize_symtabs ();
5994 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
5995 + per_bfd
->all_type_units
.size ()); ++i
)
5997 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
5999 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6000 struct dwarf2_per_cu_quick_data
);
6003 /* Return 1 so that gdb sees the "quick" functions. However,
6004 these functions will be no-ops because we will have expanded
6006 *index_kind
= dw_index_kind::GDB_INDEX
;
6010 /* Was a debug names index already read when we processed an objfile sharing
6012 if (per_bfd
->debug_names_table
!= nullptr)
6014 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6015 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6016 per_objfile
->resize_symtabs ();
6020 /* Was a GDB index already read when we processed an objfile sharing
6022 if (per_bfd
->index_table
!= nullptr)
6024 *index_kind
= dw_index_kind::GDB_INDEX
;
6025 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6026 per_objfile
->resize_symtabs ();
6030 if (dwarf2_read_debug_names (per_objfile
))
6032 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6033 per_objfile
->resize_symtabs ();
6037 if (dwarf2_read_gdb_index (per_objfile
,
6038 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6039 get_gdb_index_contents_from_section
<dwz_file
>))
6041 *index_kind
= dw_index_kind::GDB_INDEX
;
6042 per_objfile
->resize_symtabs ();
6046 /* ... otherwise, try to find the index in the index cache. */
6047 if (dwarf2_read_gdb_index (per_objfile
,
6048 get_gdb_index_contents_from_cache
,
6049 get_gdb_index_contents_from_cache_dwz
))
6051 global_index_cache
.hit ();
6052 *index_kind
= dw_index_kind::GDB_INDEX
;
6053 per_objfile
->resize_symtabs ();
6057 global_index_cache
.miss ();
6063 /* Build a partial symbol table. */
6066 dwarf2_build_psymtabs (struct objfile
*objfile
)
6068 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6069 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6071 if (per_bfd
->partial_symtabs
!= nullptr)
6073 /* Partial symbols were already read, so now we can simply
6075 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6076 per_objfile
->resize_symtabs ();
6080 init_psymbol_list (objfile
, 1024);
6084 /* This isn't really ideal: all the data we allocate on the
6085 objfile's obstack is still uselessly kept around. However,
6086 freeing it seems unsafe. */
6087 psymtab_discarder
psymtabs (objfile
);
6088 dwarf2_build_psymtabs_hard (per_objfile
);
6091 per_objfile
->resize_symtabs ();
6093 /* (maybe) store an index in the cache. */
6094 global_index_cache
.store (per_objfile
);
6096 catch (const gdb_exception_error
&except
)
6098 exception_print (gdb_stderr
, except
);
6101 /* Finish by setting the local reference to partial symtabs, so that
6102 we don't try to read them again if reading another objfile with the same
6103 BFD. If we can't in fact share, this won't make a difference anyway as
6104 the dwarf2_per_bfd object won't be shared. */
6105 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6108 /* Find the base address of the compilation unit for range lists and
6109 location lists. It will normally be specified by DW_AT_low_pc.
6110 In DWARF-3 draft 4, the base address could be overridden by
6111 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6112 compilation units with discontinuous ranges. */
6115 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6117 struct attribute
*attr
;
6119 cu
->base_address
.reset ();
6121 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6122 if (attr
!= nullptr)
6123 cu
->base_address
= attr
->value_as_address ();
6126 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6127 if (attr
!= nullptr)
6128 cu
->base_address
= attr
->value_as_address ();
6132 /* Helper function that returns the proper abbrev section for
6135 static struct dwarf2_section_info
*
6136 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6138 struct dwarf2_section_info
*abbrev
;
6139 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6141 if (this_cu
->is_dwz
)
6142 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6144 abbrev
= &per_bfd
->abbrev
;
6149 /* Fetch the abbreviation table offset from a comp or type unit header. */
6152 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6153 struct dwarf2_section_info
*section
,
6154 sect_offset sect_off
)
6156 bfd
*abfd
= section
->get_bfd_owner ();
6157 const gdb_byte
*info_ptr
;
6158 unsigned int initial_length_size
, offset_size
;
6161 section
->read (per_objfile
->objfile
);
6162 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6163 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6164 offset_size
= initial_length_size
== 4 ? 4 : 8;
6165 info_ptr
+= initial_length_size
;
6167 version
= read_2_bytes (abfd
, info_ptr
);
6171 /* Skip unit type and address size. */
6175 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6178 /* A partial symtab that is used only for include files. */
6179 struct dwarf2_include_psymtab
: public partial_symtab
6181 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6182 : partial_symtab (filename
, objfile
)
6186 void read_symtab (struct objfile
*objfile
) override
6188 /* It's an include file, no symbols to read for it.
6189 Everything is in the includer symtab. */
6191 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6192 expansion of the includer psymtab. We use the dependencies[0] field to
6193 model the includer. But if we go the regular route of calling
6194 expand_psymtab here, and having expand_psymtab call expand_dependencies
6195 to expand the includer, we'll only use expand_psymtab on the includer
6196 (making it a non-toplevel psymtab), while if we expand the includer via
6197 another path, we'll use read_symtab (making it a toplevel psymtab).
6198 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6199 psymtab, and trigger read_symtab on the includer here directly. */
6200 includer ()->read_symtab (objfile
);
6203 void expand_psymtab (struct objfile
*objfile
) override
6205 /* This is not called by read_symtab, and should not be called by any
6206 expand_dependencies. */
6210 bool readin_p (struct objfile
*objfile
) const override
6212 return includer ()->readin_p (objfile
);
6215 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6221 partial_symtab
*includer () const
6223 /* An include psymtab has exactly one dependency: the psymtab that
6225 gdb_assert (this->number_of_dependencies
== 1);
6226 return this->dependencies
[0];
6230 /* Allocate a new partial symtab for file named NAME and mark this new
6231 partial symtab as being an include of PST. */
6234 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6235 struct objfile
*objfile
)
6237 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6239 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6240 subpst
->dirname
= pst
->dirname
;
6242 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6243 subpst
->dependencies
[0] = pst
;
6244 subpst
->number_of_dependencies
= 1;
6247 /* Read the Line Number Program data and extract the list of files
6248 included by the source file represented by PST. Build an include
6249 partial symtab for each of these included files. */
6252 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6253 struct die_info
*die
,
6254 dwarf2_psymtab
*pst
)
6257 struct attribute
*attr
;
6259 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6260 if (attr
!= nullptr)
6261 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6263 return; /* No linetable, so no includes. */
6265 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6266 that we pass in the raw text_low here; that is ok because we're
6267 only decoding the line table to make include partial symtabs, and
6268 so the addresses aren't really used. */
6269 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6270 pst
->raw_text_low (), 1);
6274 hash_signatured_type (const void *item
)
6276 const struct signatured_type
*sig_type
6277 = (const struct signatured_type
*) item
;
6279 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6280 return sig_type
->signature
;
6284 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6286 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6287 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6289 return lhs
->signature
== rhs
->signature
;
6292 /* Allocate a hash table for signatured types. */
6295 allocate_signatured_type_table ()
6297 return htab_up (htab_create_alloc (41,
6298 hash_signatured_type
,
6300 NULL
, xcalloc
, xfree
));
6303 /* A helper function to add a signatured type CU to a table. */
6306 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6308 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6309 std::vector
<signatured_type
*> *all_type_units
6310 = (std::vector
<signatured_type
*> *) datum
;
6312 all_type_units
->push_back (sigt
);
6317 /* A helper for create_debug_types_hash_table. Read types from SECTION
6318 and fill them into TYPES_HTAB. It will process only type units,
6319 therefore DW_UT_type. */
6322 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6323 struct dwo_file
*dwo_file
,
6324 dwarf2_section_info
*section
, htab_up
&types_htab
,
6325 rcuh_kind section_kind
)
6327 struct objfile
*objfile
= per_objfile
->objfile
;
6328 struct dwarf2_section_info
*abbrev_section
;
6330 const gdb_byte
*info_ptr
, *end_ptr
;
6332 abbrev_section
= (dwo_file
!= NULL
6333 ? &dwo_file
->sections
.abbrev
6334 : &per_objfile
->per_bfd
->abbrev
);
6336 if (dwarf_read_debug
)
6337 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6338 section
->get_name (),
6339 abbrev_section
->get_file_name ());
6341 section
->read (objfile
);
6342 info_ptr
= section
->buffer
;
6344 if (info_ptr
== NULL
)
6347 /* We can't set abfd until now because the section may be empty or
6348 not present, in which case the bfd is unknown. */
6349 abfd
= section
->get_bfd_owner ();
6351 /* We don't use cutu_reader here because we don't need to read
6352 any dies: the signature is in the header. */
6354 end_ptr
= info_ptr
+ section
->size
;
6355 while (info_ptr
< end_ptr
)
6357 struct signatured_type
*sig_type
;
6358 struct dwo_unit
*dwo_tu
;
6360 const gdb_byte
*ptr
= info_ptr
;
6361 struct comp_unit_head header
;
6362 unsigned int length
;
6364 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6366 /* Initialize it due to a false compiler warning. */
6367 header
.signature
= -1;
6368 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6370 /* We need to read the type's signature in order to build the hash
6371 table, but we don't need anything else just yet. */
6373 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6374 abbrev_section
, ptr
, section_kind
);
6376 length
= header
.get_length ();
6378 /* Skip dummy type units. */
6379 if (ptr
>= info_ptr
+ length
6380 || peek_abbrev_code (abfd
, ptr
) == 0
6381 || header
.unit_type
!= DW_UT_type
)
6387 if (types_htab
== NULL
)
6390 types_htab
= allocate_dwo_unit_table ();
6392 types_htab
= allocate_signatured_type_table ();
6398 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6399 dwo_tu
->dwo_file
= dwo_file
;
6400 dwo_tu
->signature
= header
.signature
;
6401 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6402 dwo_tu
->section
= section
;
6403 dwo_tu
->sect_off
= sect_off
;
6404 dwo_tu
->length
= length
;
6408 /* N.B.: type_offset is not usable if this type uses a DWO file.
6409 The real type_offset is in the DWO file. */
6411 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6412 sig_type
->signature
= header
.signature
;
6413 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6414 sig_type
->per_cu
.is_debug_types
= 1;
6415 sig_type
->per_cu
.section
= section
;
6416 sig_type
->per_cu
.sect_off
= sect_off
;
6417 sig_type
->per_cu
.length
= length
;
6420 slot
= htab_find_slot (types_htab
.get (),
6421 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6423 gdb_assert (slot
!= NULL
);
6426 sect_offset dup_sect_off
;
6430 const struct dwo_unit
*dup_tu
6431 = (const struct dwo_unit
*) *slot
;
6433 dup_sect_off
= dup_tu
->sect_off
;
6437 const struct signatured_type
*dup_tu
6438 = (const struct signatured_type
*) *slot
;
6440 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6443 complaint (_("debug type entry at offset %s is duplicate to"
6444 " the entry at offset %s, signature %s"),
6445 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6446 hex_string (header
.signature
));
6448 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6450 if (dwarf_read_debug
> 1)
6451 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6452 sect_offset_str (sect_off
),
6453 hex_string (header
.signature
));
6459 /* Create the hash table of all entries in the .debug_types
6460 (or .debug_types.dwo) section(s).
6461 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6462 otherwise it is NULL.
6464 The result is a pointer to the hash table or NULL if there are no types.
6466 Note: This function processes DWO files only, not DWP files. */
6469 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6470 struct dwo_file
*dwo_file
,
6471 gdb::array_view
<dwarf2_section_info
> type_sections
,
6472 htab_up
&types_htab
)
6474 for (dwarf2_section_info
§ion
: type_sections
)
6475 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6479 /* Create the hash table of all entries in the .debug_types section,
6480 and initialize all_type_units.
6481 The result is zero if there is an error (e.g. missing .debug_types section),
6482 otherwise non-zero. */
6485 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6489 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6490 types_htab
, rcuh_kind::COMPILE
);
6491 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6493 if (types_htab
== NULL
)
6495 per_objfile
->per_bfd
->signatured_types
= NULL
;
6499 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6501 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6502 per_objfile
->per_bfd
->all_type_units
.reserve
6503 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6505 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6506 add_signatured_type_cu_to_table
,
6507 &per_objfile
->per_bfd
->all_type_units
);
6512 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6513 If SLOT is non-NULL, it is the entry to use in the hash table.
6514 Otherwise we find one. */
6516 static struct signatured_type
*
6517 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6519 if (per_objfile
->per_bfd
->all_type_units
.size ()
6520 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6521 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6523 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6525 per_objfile
->resize_symtabs ();
6527 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6528 sig_type
->signature
= sig
;
6529 sig_type
->per_cu
.is_debug_types
= 1;
6530 if (per_objfile
->per_bfd
->using_index
)
6532 sig_type
->per_cu
.v
.quick
=
6533 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6534 struct dwarf2_per_cu_quick_data
);
6539 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6542 gdb_assert (*slot
== NULL
);
6544 /* The rest of sig_type must be filled in by the caller. */
6548 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6549 Fill in SIG_ENTRY with DWO_ENTRY. */
6552 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6553 struct signatured_type
*sig_entry
,
6554 struct dwo_unit
*dwo_entry
)
6556 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6558 /* Make sure we're not clobbering something we don't expect to. */
6559 gdb_assert (! sig_entry
->per_cu
.queued
);
6560 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6561 if (per_bfd
->using_index
)
6563 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6564 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6567 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6568 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6569 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6570 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6571 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6573 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6574 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6575 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6576 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6577 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6578 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6579 sig_entry
->dwo_unit
= dwo_entry
;
6582 /* Subroutine of lookup_signatured_type.
6583 If we haven't read the TU yet, create the signatured_type data structure
6584 for a TU to be read in directly from a DWO file, bypassing the stub.
6585 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6586 using .gdb_index, then when reading a CU we want to stay in the DWO file
6587 containing that CU. Otherwise we could end up reading several other DWO
6588 files (due to comdat folding) to process the transitive closure of all the
6589 mentioned TUs, and that can be slow. The current DWO file will have every
6590 type signature that it needs.
6591 We only do this for .gdb_index because in the psymtab case we already have
6592 to read all the DWOs to build the type unit groups. */
6594 static struct signatured_type
*
6595 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6597 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6598 struct dwo_file
*dwo_file
;
6599 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6600 struct signatured_type find_sig_entry
, *sig_entry
;
6603 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6605 /* If TU skeletons have been removed then we may not have read in any
6607 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6608 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6610 /* We only ever need to read in one copy of a signatured type.
6611 Use the global signatured_types array to do our own comdat-folding
6612 of types. If this is the first time we're reading this TU, and
6613 the TU has an entry in .gdb_index, replace the recorded data from
6614 .gdb_index with this TU. */
6616 find_sig_entry
.signature
= sig
;
6617 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6618 &find_sig_entry
, INSERT
);
6619 sig_entry
= (struct signatured_type
*) *slot
;
6621 /* We can get here with the TU already read, *or* in the process of being
6622 read. Don't reassign the global entry to point to this DWO if that's
6623 the case. Also note that if the TU is already being read, it may not
6624 have come from a DWO, the program may be a mix of Fission-compiled
6625 code and non-Fission-compiled code. */
6627 /* Have we already tried to read this TU?
6628 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6629 needn't exist in the global table yet). */
6630 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6633 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6634 dwo_unit of the TU itself. */
6635 dwo_file
= cu
->dwo_unit
->dwo_file
;
6637 /* Ok, this is the first time we're reading this TU. */
6638 if (dwo_file
->tus
== NULL
)
6640 find_dwo_entry
.signature
= sig
;
6641 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6643 if (dwo_entry
== NULL
)
6646 /* If the global table doesn't have an entry for this TU, add one. */
6647 if (sig_entry
== NULL
)
6648 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6650 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6651 sig_entry
->per_cu
.tu_read
= 1;
6655 /* Subroutine of lookup_signatured_type.
6656 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6657 then try the DWP file. If the TU stub (skeleton) has been removed then
6658 it won't be in .gdb_index. */
6660 static struct signatured_type
*
6661 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6663 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6664 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6665 struct dwo_unit
*dwo_entry
;
6666 struct signatured_type find_sig_entry
, *sig_entry
;
6669 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6670 gdb_assert (dwp_file
!= NULL
);
6672 /* If TU skeletons have been removed then we may not have read in any
6674 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6675 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6677 find_sig_entry
.signature
= sig
;
6678 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6679 &find_sig_entry
, INSERT
);
6680 sig_entry
= (struct signatured_type
*) *slot
;
6682 /* Have we already tried to read this TU?
6683 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6684 needn't exist in the global table yet). */
6685 if (sig_entry
!= NULL
)
6688 if (dwp_file
->tus
== NULL
)
6690 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6691 1 /* is_debug_types */);
6692 if (dwo_entry
== NULL
)
6695 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6696 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6701 /* Lookup a signature based type for DW_FORM_ref_sig8.
6702 Returns NULL if signature SIG is not present in the table.
6703 It is up to the caller to complain about this. */
6705 static struct signatured_type
*
6706 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6708 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6710 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6712 /* We're in a DWO/DWP file, and we're using .gdb_index.
6713 These cases require special processing. */
6714 if (get_dwp_file (per_objfile
) == NULL
)
6715 return lookup_dwo_signatured_type (cu
, sig
);
6717 return lookup_dwp_signatured_type (cu
, sig
);
6721 struct signatured_type find_entry
, *entry
;
6723 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6725 find_entry
.signature
= sig
;
6726 entry
= ((struct signatured_type
*)
6727 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6733 /* Low level DIE reading support. */
6735 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6738 init_cu_die_reader (struct die_reader_specs
*reader
,
6739 struct dwarf2_cu
*cu
,
6740 struct dwarf2_section_info
*section
,
6741 struct dwo_file
*dwo_file
,
6742 struct abbrev_table
*abbrev_table
)
6744 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6745 reader
->abfd
= section
->get_bfd_owner ();
6747 reader
->dwo_file
= dwo_file
;
6748 reader
->die_section
= section
;
6749 reader
->buffer
= section
->buffer
;
6750 reader
->buffer_end
= section
->buffer
+ section
->size
;
6751 reader
->abbrev_table
= abbrev_table
;
6754 /* Subroutine of cutu_reader to simplify it.
6755 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6756 There's just a lot of work to do, and cutu_reader is big enough
6759 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6760 from it to the DIE in the DWO. If NULL we are skipping the stub.
6761 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6762 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6763 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6764 STUB_COMP_DIR may be non-NULL.
6765 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6766 are filled in with the info of the DIE from the DWO file.
6767 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6768 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6769 kept around for at least as long as *RESULT_READER.
6771 The result is non-zero if a valid (non-dummy) DIE was found. */
6774 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6775 struct dwo_unit
*dwo_unit
,
6776 struct die_info
*stub_comp_unit_die
,
6777 const char *stub_comp_dir
,
6778 struct die_reader_specs
*result_reader
,
6779 const gdb_byte
**result_info_ptr
,
6780 struct die_info
**result_comp_unit_die
,
6781 abbrev_table_up
*result_dwo_abbrev_table
)
6783 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6784 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6785 struct objfile
*objfile
= per_objfile
->objfile
;
6787 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6788 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6789 int i
,num_extra_attrs
;
6790 struct dwarf2_section_info
*dwo_abbrev_section
;
6791 struct die_info
*comp_unit_die
;
6793 /* At most one of these may be provided. */
6794 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6796 /* These attributes aren't processed until later:
6797 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6798 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6799 referenced later. However, these attributes are found in the stub
6800 which we won't have later. In order to not impose this complication
6801 on the rest of the code, we read them here and copy them to the
6810 if (stub_comp_unit_die
!= NULL
)
6812 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6814 if (!per_cu
->is_debug_types
)
6815 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6816 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6817 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6818 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6819 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6821 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6823 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6824 here (if needed). We need the value before we can process
6826 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6828 else if (stub_comp_dir
!= NULL
)
6830 /* Reconstruct the comp_dir attribute to simplify the code below. */
6831 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6832 comp_dir
->name
= DW_AT_comp_dir
;
6833 comp_dir
->form
= DW_FORM_string
;
6834 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6835 DW_STRING (comp_dir
) = stub_comp_dir
;
6838 /* Set up for reading the DWO CU/TU. */
6839 cu
->dwo_unit
= dwo_unit
;
6840 dwarf2_section_info
*section
= dwo_unit
->section
;
6841 section
->read (objfile
);
6842 abfd
= section
->get_bfd_owner ();
6843 begin_info_ptr
= info_ptr
= (section
->buffer
6844 + to_underlying (dwo_unit
->sect_off
));
6845 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6847 if (per_cu
->is_debug_types
)
6849 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6851 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6852 section
, dwo_abbrev_section
,
6853 info_ptr
, rcuh_kind::TYPE
);
6854 /* This is not an assert because it can be caused by bad debug info. */
6855 if (sig_type
->signature
!= cu
->header
.signature
)
6857 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6858 " TU at offset %s [in module %s]"),
6859 hex_string (sig_type
->signature
),
6860 hex_string (cu
->header
.signature
),
6861 sect_offset_str (dwo_unit
->sect_off
),
6862 bfd_get_filename (abfd
));
6864 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6865 /* For DWOs coming from DWP files, we don't know the CU length
6866 nor the type's offset in the TU until now. */
6867 dwo_unit
->length
= cu
->header
.get_length ();
6868 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6870 /* Establish the type offset that can be used to lookup the type.
6871 For DWO files, we don't know it until now. */
6872 sig_type
->type_offset_in_section
6873 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6877 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6878 section
, dwo_abbrev_section
,
6879 info_ptr
, rcuh_kind::COMPILE
);
6880 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6881 /* For DWOs coming from DWP files, we don't know the CU length
6883 dwo_unit
->length
= cu
->header
.get_length ();
6886 *result_dwo_abbrev_table
6887 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6888 cu
->header
.abbrev_sect_off
);
6889 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6890 result_dwo_abbrev_table
->get ());
6892 /* Read in the die, but leave space to copy over the attributes
6893 from the stub. This has the benefit of simplifying the rest of
6894 the code - all the work to maintain the illusion of a single
6895 DW_TAG_{compile,type}_unit DIE is done here. */
6896 num_extra_attrs
= ((stmt_list
!= NULL
)
6900 + (comp_dir
!= NULL
));
6901 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6904 /* Copy over the attributes from the stub to the DIE we just read in. */
6905 comp_unit_die
= *result_comp_unit_die
;
6906 i
= comp_unit_die
->num_attrs
;
6907 if (stmt_list
!= NULL
)
6908 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6910 comp_unit_die
->attrs
[i
++] = *low_pc
;
6911 if (high_pc
!= NULL
)
6912 comp_unit_die
->attrs
[i
++] = *high_pc
;
6914 comp_unit_die
->attrs
[i
++] = *ranges
;
6915 if (comp_dir
!= NULL
)
6916 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6917 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6919 if (dwarf_die_debug
)
6921 fprintf_unfiltered (gdb_stdlog
,
6922 "Read die from %s@0x%x of %s:\n",
6923 section
->get_name (),
6924 (unsigned) (begin_info_ptr
- section
->buffer
),
6925 bfd_get_filename (abfd
));
6926 dump_die (comp_unit_die
, dwarf_die_debug
);
6929 /* Skip dummy compilation units. */
6930 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6931 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6934 *result_info_ptr
= info_ptr
;
6938 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6939 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6940 signature is part of the header. */
6941 static gdb::optional
<ULONGEST
>
6942 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6944 if (cu
->header
.version
>= 5)
6945 return cu
->header
.signature
;
6946 struct attribute
*attr
;
6947 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6948 if (attr
== nullptr)
6949 return gdb::optional
<ULONGEST
> ();
6950 return DW_UNSND (attr
);
6953 /* Subroutine of cutu_reader to simplify it.
6954 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6955 Returns NULL if the specified DWO unit cannot be found. */
6957 static struct dwo_unit
*
6958 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6960 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6961 struct dwo_unit
*dwo_unit
;
6962 const char *comp_dir
;
6964 gdb_assert (cu
!= NULL
);
6966 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6967 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6968 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6970 if (per_cu
->is_debug_types
)
6971 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6974 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6976 if (!signature
.has_value ())
6977 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6979 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6981 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6987 /* Subroutine of cutu_reader to simplify it.
6988 See it for a description of the parameters.
6989 Read a TU directly from a DWO file, bypassing the stub. */
6992 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6993 dwarf2_per_objfile
*per_objfile
,
6994 dwarf2_cu
*existing_cu
)
6996 struct signatured_type
*sig_type
;
6998 /* Verify we can do the following downcast, and that we have the
7000 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7001 sig_type
= (struct signatured_type
*) this_cu
;
7002 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7006 if (existing_cu
!= nullptr)
7009 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7010 /* There's no need to do the rereading_dwo_cu handling that
7011 cutu_reader does since we don't read the stub. */
7015 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7016 in per_objfile yet. */
7017 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7018 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7019 cu
= m_new_cu
.get ();
7022 /* A future optimization, if needed, would be to use an existing
7023 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7024 could share abbrev tables. */
7026 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7027 NULL
/* stub_comp_unit_die */,
7028 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7031 &m_dwo_abbrev_table
) == 0)
7038 /* Initialize a CU (or TU) and read its DIEs.
7039 If the CU defers to a DWO file, read the DWO file as well.
7041 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7042 Otherwise the table specified in the comp unit header is read in and used.
7043 This is an optimization for when we already have the abbrev table.
7045 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7048 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7049 dwarf2_per_objfile
*per_objfile
,
7050 struct abbrev_table
*abbrev_table
,
7051 dwarf2_cu
*existing_cu
,
7053 : die_reader_specs
{},
7056 struct objfile
*objfile
= per_objfile
->objfile
;
7057 struct dwarf2_section_info
*section
= this_cu
->section
;
7058 bfd
*abfd
= section
->get_bfd_owner ();
7059 const gdb_byte
*begin_info_ptr
;
7060 struct signatured_type
*sig_type
= NULL
;
7061 struct dwarf2_section_info
*abbrev_section
;
7062 /* Non-zero if CU currently points to a DWO file and we need to
7063 reread it. When this happens we need to reread the skeleton die
7064 before we can reread the DWO file (this only applies to CUs, not TUs). */
7065 int rereading_dwo_cu
= 0;
7067 if (dwarf_die_debug
)
7068 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7069 this_cu
->is_debug_types
? "type" : "comp",
7070 sect_offset_str (this_cu
->sect_off
));
7072 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7073 file (instead of going through the stub), short-circuit all of this. */
7074 if (this_cu
->reading_dwo_directly
)
7076 /* Narrow down the scope of possibilities to have to understand. */
7077 gdb_assert (this_cu
->is_debug_types
);
7078 gdb_assert (abbrev_table
== NULL
);
7079 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7083 /* This is cheap if the section is already read in. */
7084 section
->read (objfile
);
7086 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7088 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7092 if (existing_cu
!= nullptr)
7095 /* If this CU is from a DWO file we need to start over, we need to
7096 refetch the attributes from the skeleton CU.
7097 This could be optimized by retrieving those attributes from when we
7098 were here the first time: the previous comp_unit_die was stored in
7099 comp_unit_obstack. But there's no data yet that we need this
7101 if (cu
->dwo_unit
!= NULL
)
7102 rereading_dwo_cu
= 1;
7106 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7107 in per_objfile yet. */
7108 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7109 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7110 cu
= m_new_cu
.get ();
7113 /* Get the header. */
7114 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7116 /* We already have the header, there's no need to read it in again. */
7117 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7121 if (this_cu
->is_debug_types
)
7123 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7124 section
, abbrev_section
,
7125 info_ptr
, rcuh_kind::TYPE
);
7127 /* Since per_cu is the first member of struct signatured_type,
7128 we can go from a pointer to one to a pointer to the other. */
7129 sig_type
= (struct signatured_type
*) this_cu
;
7130 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7131 gdb_assert (sig_type
->type_offset_in_tu
7132 == cu
->header
.type_cu_offset_in_tu
);
7133 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7135 /* LENGTH has not been set yet for type units if we're
7136 using .gdb_index. */
7137 this_cu
->length
= cu
->header
.get_length ();
7139 /* Establish the type offset that can be used to lookup the type. */
7140 sig_type
->type_offset_in_section
=
7141 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7143 this_cu
->dwarf_version
= cu
->header
.version
;
7147 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7148 section
, abbrev_section
,
7150 rcuh_kind::COMPILE
);
7152 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7153 if (this_cu
->length
== 0)
7154 this_cu
->length
= cu
->header
.get_length ();
7156 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7157 this_cu
->dwarf_version
= cu
->header
.version
;
7161 /* Skip dummy compilation units. */
7162 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7163 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7169 /* If we don't have them yet, read the abbrevs for this compilation unit.
7170 And if we need to read them now, make sure they're freed when we're
7172 if (abbrev_table
!= NULL
)
7173 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7176 m_abbrev_table_holder
7177 = abbrev_table::read (objfile
, abbrev_section
,
7178 cu
->header
.abbrev_sect_off
);
7179 abbrev_table
= m_abbrev_table_holder
.get ();
7182 /* Read the top level CU/TU die. */
7183 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7184 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7186 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7192 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7193 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7194 table from the DWO file and pass the ownership over to us. It will be
7195 referenced from READER, so we must make sure to free it after we're done
7198 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7199 DWO CU, that this test will fail (the attribute will not be present). */
7200 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7201 if (dwo_name
!= nullptr)
7203 struct dwo_unit
*dwo_unit
;
7204 struct die_info
*dwo_comp_unit_die
;
7206 if (comp_unit_die
->has_children
)
7208 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7209 " has children (offset %s) [in module %s]"),
7210 sect_offset_str (this_cu
->sect_off
),
7211 bfd_get_filename (abfd
));
7213 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7214 if (dwo_unit
!= NULL
)
7216 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7217 comp_unit_die
, NULL
,
7220 &m_dwo_abbrev_table
) == 0)
7226 comp_unit_die
= dwo_comp_unit_die
;
7230 /* Yikes, we couldn't find the rest of the DIE, we only have
7231 the stub. A complaint has already been logged. There's
7232 not much more we can do except pass on the stub DIE to
7233 die_reader_func. We don't want to throw an error on bad
7240 cutu_reader::keep ()
7242 /* Done, clean up. */
7243 gdb_assert (!dummy_p
);
7244 if (m_new_cu
!= NULL
)
7246 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7248 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7249 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7253 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7254 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7255 assumed to have already done the lookup to find the DWO file).
7257 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7258 THIS_CU->is_debug_types, but nothing else.
7260 We fill in THIS_CU->length.
7262 THIS_CU->cu is always freed when done.
7263 This is done in order to not leave THIS_CU->cu in a state where we have
7264 to care whether it refers to the "main" CU or the DWO CU.
7266 When parent_cu is passed, it is used to provide a default value for
7267 str_offsets_base and addr_base from the parent. */
7269 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7270 dwarf2_per_objfile
*per_objfile
,
7271 struct dwarf2_cu
*parent_cu
,
7272 struct dwo_file
*dwo_file
)
7273 : die_reader_specs
{},
7276 struct objfile
*objfile
= per_objfile
->objfile
;
7277 struct dwarf2_section_info
*section
= this_cu
->section
;
7278 bfd
*abfd
= section
->get_bfd_owner ();
7279 struct dwarf2_section_info
*abbrev_section
;
7280 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7282 if (dwarf_die_debug
)
7283 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7284 this_cu
->is_debug_types
? "type" : "comp",
7285 sect_offset_str (this_cu
->sect_off
));
7287 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7289 abbrev_section
= (dwo_file
!= NULL
7290 ? &dwo_file
->sections
.abbrev
7291 : get_abbrev_section_for_cu (this_cu
));
7293 /* This is cheap if the section is already read in. */
7294 section
->read (objfile
);
7296 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7298 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7299 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7300 section
, abbrev_section
, info_ptr
,
7301 (this_cu
->is_debug_types
7303 : rcuh_kind::COMPILE
));
7305 if (parent_cu
!= nullptr)
7307 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7308 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7310 this_cu
->length
= m_new_cu
->header
.get_length ();
7312 /* Skip dummy compilation units. */
7313 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7314 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7320 m_abbrev_table_holder
7321 = abbrev_table::read (objfile
, abbrev_section
,
7322 m_new_cu
->header
.abbrev_sect_off
);
7324 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7325 m_abbrev_table_holder
.get ());
7326 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7330 /* Type Unit Groups.
7332 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7333 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7334 so that all types coming from the same compilation (.o file) are grouped
7335 together. A future step could be to put the types in the same symtab as
7336 the CU the types ultimately came from. */
7339 hash_type_unit_group (const void *item
)
7341 const struct type_unit_group
*tu_group
7342 = (const struct type_unit_group
*) item
;
7344 return hash_stmt_list_entry (&tu_group
->hash
);
7348 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7350 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7351 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7353 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7356 /* Allocate a hash table for type unit groups. */
7359 allocate_type_unit_groups_table ()
7361 return htab_up (htab_create_alloc (3,
7362 hash_type_unit_group
,
7364 NULL
, xcalloc
, xfree
));
7367 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7368 partial symtabs. We combine several TUs per psymtab to not let the size
7369 of any one psymtab grow too big. */
7370 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7371 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7373 /* Helper routine for get_type_unit_group.
7374 Create the type_unit_group object used to hold one or more TUs. */
7376 static struct type_unit_group
*
7377 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7379 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7380 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7381 struct dwarf2_per_cu_data
*per_cu
;
7382 struct type_unit_group
*tu_group
;
7384 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7385 per_cu
= &tu_group
->per_cu
;
7386 per_cu
->per_bfd
= per_bfd
;
7388 if (per_bfd
->using_index
)
7390 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7391 struct dwarf2_per_cu_quick_data
);
7395 unsigned int line_offset
= to_underlying (line_offset_struct
);
7396 dwarf2_psymtab
*pst
;
7399 /* Give the symtab a useful name for debug purposes. */
7400 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7401 name
= string_printf ("<type_units_%d>",
7402 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7404 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7406 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7407 pst
->anonymous
= true;
7410 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7411 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7416 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7417 STMT_LIST is a DW_AT_stmt_list attribute. */
7419 static struct type_unit_group
*
7420 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7422 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7423 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7424 struct type_unit_group
*tu_group
;
7426 unsigned int line_offset
;
7427 struct type_unit_group type_unit_group_for_lookup
;
7429 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7430 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7432 /* Do we need to create a new group, or can we use an existing one? */
7436 line_offset
= DW_UNSND (stmt_list
);
7437 ++tu_stats
->nr_symtab_sharers
;
7441 /* Ugh, no stmt_list. Rare, but we have to handle it.
7442 We can do various things here like create one group per TU or
7443 spread them over multiple groups to split up the expansion work.
7444 To avoid worst case scenarios (too many groups or too large groups)
7445 we, umm, group them in bunches. */
7446 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7447 | (tu_stats
->nr_stmt_less_type_units
7448 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7449 ++tu_stats
->nr_stmt_less_type_units
;
7452 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7453 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7454 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7455 &type_unit_group_for_lookup
, INSERT
);
7458 tu_group
= (struct type_unit_group
*) *slot
;
7459 gdb_assert (tu_group
!= NULL
);
7463 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7464 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7466 ++tu_stats
->nr_symtabs
;
7472 /* Partial symbol tables. */
7474 /* Create a psymtab named NAME and assign it to PER_CU.
7476 The caller must fill in the following details:
7477 dirname, textlow, texthigh. */
7479 static dwarf2_psymtab
*
7480 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7481 dwarf2_per_objfile
*per_objfile
,
7484 struct objfile
*objfile
= per_objfile
->objfile
;
7485 dwarf2_psymtab
*pst
;
7487 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7489 pst
->psymtabs_addrmap_supported
= true;
7491 /* This is the glue that links PST into GDB's symbol API. */
7492 per_cu
->v
.psymtab
= pst
;
7497 /* DIE reader function for process_psymtab_comp_unit. */
7500 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7501 const gdb_byte
*info_ptr
,
7502 struct die_info
*comp_unit_die
,
7503 enum language pretend_language
)
7505 struct dwarf2_cu
*cu
= reader
->cu
;
7506 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7507 struct objfile
*objfile
= per_objfile
->objfile
;
7508 struct gdbarch
*gdbarch
= objfile
->arch ();
7509 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7511 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7512 dwarf2_psymtab
*pst
;
7513 enum pc_bounds_kind cu_bounds_kind
;
7514 const char *filename
;
7516 gdb_assert (! per_cu
->is_debug_types
);
7518 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7520 /* Allocate a new partial symbol table structure. */
7521 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7522 static const char artificial
[] = "<artificial>";
7523 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7524 if (filename
== NULL
)
7526 else if (strcmp (filename
, artificial
) == 0)
7528 debug_filename
.reset (concat (artificial
, "@",
7529 sect_offset_str (per_cu
->sect_off
),
7531 filename
= debug_filename
.get ();
7534 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7536 /* This must be done before calling dwarf2_build_include_psymtabs. */
7537 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7539 baseaddr
= objfile
->text_section_offset ();
7541 dwarf2_find_base_address (comp_unit_die
, cu
);
7543 /* Possibly set the default values of LOWPC and HIGHPC from
7545 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7546 &best_highpc
, cu
, pst
);
7547 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7550 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7553 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7555 /* Store the contiguous range if it is not empty; it can be
7556 empty for CUs with no code. */
7557 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7561 /* Check if comp unit has_children.
7562 If so, read the rest of the partial symbols from this comp unit.
7563 If not, there's no more debug_info for this comp unit. */
7564 if (comp_unit_die
->has_children
)
7566 struct partial_die_info
*first_die
;
7567 CORE_ADDR lowpc
, highpc
;
7569 lowpc
= ((CORE_ADDR
) -1);
7570 highpc
= ((CORE_ADDR
) 0);
7572 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7574 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7575 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7577 /* If we didn't find a lowpc, set it to highpc to avoid
7578 complaints from `maint check'. */
7579 if (lowpc
== ((CORE_ADDR
) -1))
7582 /* If the compilation unit didn't have an explicit address range,
7583 then use the information extracted from its child dies. */
7584 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7587 best_highpc
= highpc
;
7590 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7591 best_lowpc
+ baseaddr
)
7593 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7594 best_highpc
+ baseaddr
)
7597 end_psymtab_common (objfile
, pst
);
7599 if (!cu
->per_cu
->imported_symtabs_empty ())
7602 int len
= cu
->per_cu
->imported_symtabs_size ();
7604 /* Fill in 'dependencies' here; we fill in 'users' in a
7606 pst
->number_of_dependencies
= len
;
7608 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7609 for (i
= 0; i
< len
; ++i
)
7611 pst
->dependencies
[i
]
7612 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7615 cu
->per_cu
->imported_symtabs_free ();
7618 /* Get the list of files included in the current compilation unit,
7619 and build a psymtab for each of them. */
7620 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7622 if (dwarf_read_debug
)
7623 fprintf_unfiltered (gdb_stdlog
,
7624 "Psymtab for %s unit @%s: %s - %s"
7625 ", %d global, %d static syms\n",
7626 per_cu
->is_debug_types
? "type" : "comp",
7627 sect_offset_str (per_cu
->sect_off
),
7628 paddress (gdbarch
, pst
->text_low (objfile
)),
7629 paddress (gdbarch
, pst
->text_high (objfile
)),
7630 pst
->n_global_syms
, pst
->n_static_syms
);
7633 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7634 Process compilation unit THIS_CU for a psymtab. */
7637 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7638 dwarf2_per_objfile
*per_objfile
,
7639 bool want_partial_unit
,
7640 enum language pretend_language
)
7642 /* If this compilation unit was already read in, free the
7643 cached copy in order to read it in again. This is
7644 necessary because we skipped some symbols when we first
7645 read in the compilation unit (see load_partial_dies).
7646 This problem could be avoided, but the benefit is unclear. */
7647 per_objfile
->remove_cu (this_cu
);
7649 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7651 switch (reader
.comp_unit_die
->tag
)
7653 case DW_TAG_compile_unit
:
7654 this_cu
->unit_type
= DW_UT_compile
;
7656 case DW_TAG_partial_unit
:
7657 this_cu
->unit_type
= DW_UT_partial
;
7667 else if (this_cu
->is_debug_types
)
7668 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7669 reader
.comp_unit_die
);
7670 else if (want_partial_unit
7671 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7672 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7673 reader
.comp_unit_die
,
7676 this_cu
->lang
= reader
.cu
->language
;
7678 /* Age out any secondary CUs. */
7679 per_objfile
->age_comp_units ();
7682 /* Reader function for build_type_psymtabs. */
7685 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7686 const gdb_byte
*info_ptr
,
7687 struct die_info
*type_unit_die
)
7689 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7690 struct objfile
*objfile
= per_objfile
->objfile
;
7691 struct dwarf2_cu
*cu
= reader
->cu
;
7692 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7693 struct signatured_type
*sig_type
;
7694 struct type_unit_group
*tu_group
;
7695 struct attribute
*attr
;
7696 struct partial_die_info
*first_die
;
7697 CORE_ADDR lowpc
, highpc
;
7698 dwarf2_psymtab
*pst
;
7700 gdb_assert (per_cu
->is_debug_types
);
7701 sig_type
= (struct signatured_type
*) per_cu
;
7703 if (! type_unit_die
->has_children
)
7706 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7707 tu_group
= get_type_unit_group (cu
, attr
);
7709 if (tu_group
->tus
== nullptr)
7710 tu_group
->tus
= new std::vector
<signatured_type
*>;
7711 tu_group
->tus
->push_back (sig_type
);
7713 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7714 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7715 pst
->anonymous
= true;
7717 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7719 lowpc
= (CORE_ADDR
) -1;
7720 highpc
= (CORE_ADDR
) 0;
7721 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7723 end_psymtab_common (objfile
, pst
);
7726 /* Struct used to sort TUs by their abbreviation table offset. */
7728 struct tu_abbrev_offset
7730 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7731 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7734 signatured_type
*sig_type
;
7735 sect_offset abbrev_offset
;
7738 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7741 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7742 const struct tu_abbrev_offset
&b
)
7744 return a
.abbrev_offset
< b
.abbrev_offset
;
7747 /* Efficiently read all the type units.
7748 This does the bulk of the work for build_type_psymtabs.
7750 The efficiency is because we sort TUs by the abbrev table they use and
7751 only read each abbrev table once. In one program there are 200K TUs
7752 sharing 8K abbrev tables.
7754 The main purpose of this function is to support building the
7755 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7756 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7757 can collapse the search space by grouping them by stmt_list.
7758 The savings can be significant, in the same program from above the 200K TUs
7759 share 8K stmt_list tables.
7761 FUNC is expected to call get_type_unit_group, which will create the
7762 struct type_unit_group if necessary and add it to
7763 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7766 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7768 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7769 abbrev_table_up abbrev_table
;
7770 sect_offset abbrev_offset
;
7772 /* It's up to the caller to not call us multiple times. */
7773 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7775 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7778 /* TUs typically share abbrev tables, and there can be way more TUs than
7779 abbrev tables. Sort by abbrev table to reduce the number of times we
7780 read each abbrev table in.
7781 Alternatives are to punt or to maintain a cache of abbrev tables.
7782 This is simpler and efficient enough for now.
7784 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7785 symtab to use). Typically TUs with the same abbrev offset have the same
7786 stmt_list value too so in practice this should work well.
7788 The basic algorithm here is:
7790 sort TUs by abbrev table
7791 for each TU with same abbrev table:
7792 read abbrev table if first user
7793 read TU top level DIE
7794 [IWBN if DWO skeletons had DW_AT_stmt_list]
7797 if (dwarf_read_debug
)
7798 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7800 /* Sort in a separate table to maintain the order of all_type_units
7801 for .gdb_index: TU indices directly index all_type_units. */
7802 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7803 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7805 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7806 sorted_by_abbrev
.emplace_back
7807 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7808 sig_type
->per_cu
.sect_off
));
7810 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7811 sort_tu_by_abbrev_offset
);
7813 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7815 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7817 /* Switch to the next abbrev table if necessary. */
7818 if (abbrev_table
== NULL
7819 || tu
.abbrev_offset
!= abbrev_offset
)
7821 abbrev_offset
= tu
.abbrev_offset
;
7823 abbrev_table::read (per_objfile
->objfile
,
7824 &per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7825 ++tu_stats
->nr_uniq_abbrev_tables
;
7828 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7829 abbrev_table
.get (), nullptr, false);
7830 if (!reader
.dummy_p
)
7831 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7832 reader
.comp_unit_die
);
7836 /* Print collected type unit statistics. */
7839 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7841 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7843 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7844 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7845 per_objfile
->per_bfd
->all_type_units
.size ());
7846 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7847 tu_stats
->nr_uniq_abbrev_tables
);
7848 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7849 tu_stats
->nr_symtabs
);
7850 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7851 tu_stats
->nr_symtab_sharers
);
7852 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7853 tu_stats
->nr_stmt_less_type_units
);
7854 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7855 tu_stats
->nr_all_type_units_reallocs
);
7858 /* Traversal function for build_type_psymtabs. */
7861 build_type_psymtab_dependencies (void **slot
, void *info
)
7863 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7864 struct objfile
*objfile
= per_objfile
->objfile
;
7865 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7866 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7867 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7868 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7871 gdb_assert (len
> 0);
7872 gdb_assert (per_cu
->type_unit_group_p ());
7874 pst
->number_of_dependencies
= len
;
7875 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7876 for (i
= 0; i
< len
; ++i
)
7878 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7879 gdb_assert (iter
->per_cu
.is_debug_types
);
7880 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7881 iter
->type_unit_group
= tu_group
;
7884 delete tu_group
->tus
;
7885 tu_group
->tus
= nullptr;
7890 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7891 Build partial symbol tables for the .debug_types comp-units. */
7894 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7896 if (! create_all_type_units (per_objfile
))
7899 build_type_psymtabs_1 (per_objfile
);
7902 /* Traversal function for process_skeletonless_type_unit.
7903 Read a TU in a DWO file and build partial symbols for it. */
7906 process_skeletonless_type_unit (void **slot
, void *info
)
7908 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7909 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7910 struct signatured_type find_entry
, *entry
;
7912 /* If this TU doesn't exist in the global table, add it and read it in. */
7914 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7915 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7917 find_entry
.signature
= dwo_unit
->signature
;
7918 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7919 &find_entry
, INSERT
);
7920 /* If we've already seen this type there's nothing to do. What's happening
7921 is we're doing our own version of comdat-folding here. */
7925 /* This does the job that create_all_type_units would have done for
7927 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7928 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7931 /* This does the job that build_type_psymtabs_1 would have done. */
7932 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7933 if (!reader
.dummy_p
)
7934 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7935 reader
.comp_unit_die
);
7940 /* Traversal function for process_skeletonless_type_units. */
7943 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7945 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7947 if (dwo_file
->tus
!= NULL
)
7948 htab_traverse_noresize (dwo_file
->tus
.get (),
7949 process_skeletonless_type_unit
, info
);
7954 /* Scan all TUs of DWO files, verifying we've processed them.
7955 This is needed in case a TU was emitted without its skeleton.
7956 Note: This can't be done until we know what all the DWO files are. */
7959 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7961 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7962 if (get_dwp_file (per_objfile
) == NULL
7963 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7965 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7966 process_dwo_file_for_skeletonless_type_units
,
7971 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7974 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7976 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7978 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7983 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7985 /* Set the 'user' field only if it is not already set. */
7986 if (pst
->dependencies
[j
]->user
== NULL
)
7987 pst
->dependencies
[j
]->user
= pst
;
7992 /* Build the partial symbol table by doing a quick pass through the
7993 .debug_info and .debug_abbrev sections. */
7996 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7998 struct objfile
*objfile
= per_objfile
->objfile
;
8000 if (dwarf_read_debug
)
8002 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8003 objfile_name (objfile
));
8006 scoped_restore restore_reading_psyms
8007 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
8010 per_objfile
->per_bfd
->info
.read (objfile
);
8012 /* Any cached compilation units will be linked by the per-objfile
8013 read_in_chain. Make sure to free them when we're done. */
8014 free_cached_comp_units
freer (per_objfile
);
8016 build_type_psymtabs (per_objfile
);
8018 create_all_comp_units (per_objfile
);
8020 /* Create a temporary address map on a temporary obstack. We later
8021 copy this to the final obstack. */
8022 auto_obstack temp_obstack
;
8024 scoped_restore save_psymtabs_addrmap
8025 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8026 addrmap_create_mutable (&temp_obstack
));
8028 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8030 if (per_cu
->v
.psymtab
!= NULL
)
8031 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8033 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8037 /* This has to wait until we read the CUs, we need the list of DWOs. */
8038 process_skeletonless_type_units (per_objfile
);
8040 /* Now that all TUs have been processed we can fill in the dependencies. */
8041 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8043 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8044 build_type_psymtab_dependencies
, per_objfile
);
8047 if (dwarf_read_debug
)
8048 print_tu_stats (per_objfile
);
8050 set_partial_user (per_objfile
);
8052 objfile
->partial_symtabs
->psymtabs_addrmap
8053 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8054 objfile
->partial_symtabs
->obstack ());
8055 /* At this point we want to keep the address map. */
8056 save_psymtabs_addrmap
.release ();
8058 if (dwarf_read_debug
)
8059 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8060 objfile_name (objfile
));
8063 /* Load the partial DIEs for a secondary CU into memory.
8064 This is also used when rereading a primary CU with load_all_dies. */
8067 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8068 dwarf2_per_objfile
*per_objfile
,
8069 dwarf2_cu
*existing_cu
)
8071 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8073 if (!reader
.dummy_p
)
8075 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8078 /* Check if comp unit has_children.
8079 If so, read the rest of the partial symbols from this comp unit.
8080 If not, there's no more debug_info for this comp unit. */
8081 if (reader
.comp_unit_die
->has_children
)
8082 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8089 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8090 struct dwarf2_section_info
*section
,
8091 struct dwarf2_section_info
*abbrev_section
,
8092 unsigned int is_dwz
)
8094 const gdb_byte
*info_ptr
;
8095 struct objfile
*objfile
= per_objfile
->objfile
;
8097 if (dwarf_read_debug
)
8098 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8099 section
->get_name (),
8100 section
->get_file_name ());
8102 section
->read (objfile
);
8104 info_ptr
= section
->buffer
;
8106 while (info_ptr
< section
->buffer
+ section
->size
)
8108 struct dwarf2_per_cu_data
*this_cu
;
8110 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8112 comp_unit_head cu_header
;
8113 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8114 abbrev_section
, info_ptr
,
8115 rcuh_kind::COMPILE
);
8117 /* Save the compilation unit for later lookup. */
8118 if (cu_header
.unit_type
!= DW_UT_type
)
8119 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8122 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8123 sig_type
->signature
= cu_header
.signature
;
8124 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8125 this_cu
= &sig_type
->per_cu
;
8127 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8128 this_cu
->sect_off
= sect_off
;
8129 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8130 this_cu
->is_dwz
= is_dwz
;
8131 this_cu
->section
= section
;
8133 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8135 info_ptr
= info_ptr
+ this_cu
->length
;
8139 /* Create a list of all compilation units in OBJFILE.
8140 This is only done for -readnow and building partial symtabs. */
8143 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8145 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8146 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8147 &per_objfile
->per_bfd
->abbrev
, 0);
8149 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8151 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8154 /* Process all loaded DIEs for compilation unit CU, starting at
8155 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8156 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8157 DW_AT_ranges). See the comments of add_partial_subprogram on how
8158 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8161 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8162 CORE_ADDR
*highpc
, int set_addrmap
,
8163 struct dwarf2_cu
*cu
)
8165 struct partial_die_info
*pdi
;
8167 /* Now, march along the PDI's, descending into ones which have
8168 interesting children but skipping the children of the other ones,
8169 until we reach the end of the compilation unit. */
8177 /* Anonymous namespaces or modules have no name but have interesting
8178 children, so we need to look at them. Ditto for anonymous
8181 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8182 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8183 || pdi
->tag
== DW_TAG_imported_unit
8184 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8188 case DW_TAG_subprogram
:
8189 case DW_TAG_inlined_subroutine
:
8190 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8191 if (cu
->language
== language_cplus
)
8192 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8195 case DW_TAG_constant
:
8196 case DW_TAG_variable
:
8197 case DW_TAG_typedef
:
8198 case DW_TAG_union_type
:
8199 if (!pdi
->is_declaration
8200 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8202 add_partial_symbol (pdi
, cu
);
8205 case DW_TAG_class_type
:
8206 case DW_TAG_interface_type
:
8207 case DW_TAG_structure_type
:
8208 if (!pdi
->is_declaration
)
8210 add_partial_symbol (pdi
, cu
);
8212 if ((cu
->language
== language_rust
8213 || cu
->language
== language_cplus
) && pdi
->has_children
)
8214 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8217 case DW_TAG_enumeration_type
:
8218 if (!pdi
->is_declaration
)
8219 add_partial_enumeration (pdi
, cu
);
8221 case DW_TAG_base_type
:
8222 case DW_TAG_subrange_type
:
8223 /* File scope base type definitions are added to the partial
8225 add_partial_symbol (pdi
, cu
);
8227 case DW_TAG_namespace
:
8228 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8231 if (!pdi
->is_declaration
)
8232 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8234 case DW_TAG_imported_unit
:
8236 struct dwarf2_per_cu_data
*per_cu
;
8238 /* For now we don't handle imported units in type units. */
8239 if (cu
->per_cu
->is_debug_types
)
8241 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8242 " supported in type units [in module %s]"),
8243 objfile_name (cu
->per_objfile
->objfile
));
8246 per_cu
= dwarf2_find_containing_comp_unit
8247 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8249 /* Go read the partial unit, if needed. */
8250 if (per_cu
->v
.psymtab
== NULL
)
8251 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8254 cu
->per_cu
->imported_symtabs_push (per_cu
);
8257 case DW_TAG_imported_declaration
:
8258 add_partial_symbol (pdi
, cu
);
8265 /* If the die has a sibling, skip to the sibling. */
8267 pdi
= pdi
->die_sibling
;
8271 /* Functions used to compute the fully scoped name of a partial DIE.
8273 Normally, this is simple. For C++, the parent DIE's fully scoped
8274 name is concatenated with "::" and the partial DIE's name.
8275 Enumerators are an exception; they use the scope of their parent
8276 enumeration type, i.e. the name of the enumeration type is not
8277 prepended to the enumerator.
8279 There are two complexities. One is DW_AT_specification; in this
8280 case "parent" means the parent of the target of the specification,
8281 instead of the direct parent of the DIE. The other is compilers
8282 which do not emit DW_TAG_namespace; in this case we try to guess
8283 the fully qualified name of structure types from their members'
8284 linkage names. This must be done using the DIE's children rather
8285 than the children of any DW_AT_specification target. We only need
8286 to do this for structures at the top level, i.e. if the target of
8287 any DW_AT_specification (if any; otherwise the DIE itself) does not
8290 /* Compute the scope prefix associated with PDI's parent, in
8291 compilation unit CU. The result will be allocated on CU's
8292 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8293 field. NULL is returned if no prefix is necessary. */
8295 partial_die_parent_scope (struct partial_die_info
*pdi
,
8296 struct dwarf2_cu
*cu
)
8298 const char *grandparent_scope
;
8299 struct partial_die_info
*parent
, *real_pdi
;
8301 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8302 then this means the parent of the specification DIE. */
8305 while (real_pdi
->has_specification
)
8307 auto res
= find_partial_die (real_pdi
->spec_offset
,
8308 real_pdi
->spec_is_dwz
, cu
);
8313 parent
= real_pdi
->die_parent
;
8317 if (parent
->scope_set
)
8318 return parent
->scope
;
8322 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8324 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8325 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8326 Work around this problem here. */
8327 if (cu
->language
== language_cplus
8328 && parent
->tag
== DW_TAG_namespace
8329 && strcmp (parent
->name (cu
), "::") == 0
8330 && grandparent_scope
== NULL
)
8332 parent
->scope
= NULL
;
8333 parent
->scope_set
= 1;
8337 /* Nested subroutines in Fortran get a prefix. */
8338 if (pdi
->tag
== DW_TAG_enumerator
)
8339 /* Enumerators should not get the name of the enumeration as a prefix. */
8340 parent
->scope
= grandparent_scope
;
8341 else if (parent
->tag
== DW_TAG_namespace
8342 || parent
->tag
== DW_TAG_module
8343 || parent
->tag
== DW_TAG_structure_type
8344 || parent
->tag
== DW_TAG_class_type
8345 || parent
->tag
== DW_TAG_interface_type
8346 || parent
->tag
== DW_TAG_union_type
8347 || parent
->tag
== DW_TAG_enumeration_type
8348 || (cu
->language
== language_fortran
8349 && parent
->tag
== DW_TAG_subprogram
8350 && pdi
->tag
== DW_TAG_subprogram
))
8352 if (grandparent_scope
== NULL
)
8353 parent
->scope
= parent
->name (cu
);
8355 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8357 parent
->name (cu
), 0, cu
);
8361 /* FIXME drow/2004-04-01: What should we be doing with
8362 function-local names? For partial symbols, we should probably be
8364 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8365 dwarf_tag_name (parent
->tag
),
8366 sect_offset_str (pdi
->sect_off
));
8367 parent
->scope
= grandparent_scope
;
8370 parent
->scope_set
= 1;
8371 return parent
->scope
;
8374 /* Return the fully scoped name associated with PDI, from compilation unit
8375 CU. The result will be allocated with malloc. */
8377 static gdb::unique_xmalloc_ptr
<char>
8378 partial_die_full_name (struct partial_die_info
*pdi
,
8379 struct dwarf2_cu
*cu
)
8381 const char *parent_scope
;
8383 /* If this is a template instantiation, we can not work out the
8384 template arguments from partial DIEs. So, unfortunately, we have
8385 to go through the full DIEs. At least any work we do building
8386 types here will be reused if full symbols are loaded later. */
8387 if (pdi
->has_template_arguments
)
8391 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8393 struct die_info
*die
;
8394 struct attribute attr
;
8395 struct dwarf2_cu
*ref_cu
= cu
;
8397 /* DW_FORM_ref_addr is using section offset. */
8398 attr
.name
= (enum dwarf_attribute
) 0;
8399 attr
.form
= DW_FORM_ref_addr
;
8400 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8401 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8403 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8407 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8408 if (parent_scope
== NULL
)
8411 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8417 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8419 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8420 struct objfile
*objfile
= per_objfile
->objfile
;
8421 struct gdbarch
*gdbarch
= objfile
->arch ();
8423 const char *actual_name
= NULL
;
8426 baseaddr
= objfile
->text_section_offset ();
8428 gdb::unique_xmalloc_ptr
<char> built_actual_name
8429 = partial_die_full_name (pdi
, cu
);
8430 if (built_actual_name
!= NULL
)
8431 actual_name
= built_actual_name
.get ();
8433 if (actual_name
== NULL
)
8434 actual_name
= pdi
->name (cu
);
8436 partial_symbol psymbol
;
8437 memset (&psymbol
, 0, sizeof (psymbol
));
8438 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8439 psymbol
.ginfo
.section
= -1;
8441 /* The code below indicates that the psymbol should be installed by
8443 gdb::optional
<psymbol_placement
> where
;
8447 case DW_TAG_inlined_subroutine
:
8448 case DW_TAG_subprogram
:
8449 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8451 if (pdi
->is_external
8452 || cu
->language
== language_ada
8453 || (cu
->language
== language_fortran
8454 && pdi
->die_parent
!= NULL
8455 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8457 /* Normally, only "external" DIEs are part of the global scope.
8458 But in Ada and Fortran, we want to be able to access nested
8459 procedures globally. So all Ada and Fortran subprograms are
8460 stored in the global scope. */
8461 where
= psymbol_placement::GLOBAL
;
8464 where
= psymbol_placement::STATIC
;
8466 psymbol
.domain
= VAR_DOMAIN
;
8467 psymbol
.aclass
= LOC_BLOCK
;
8468 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8469 psymbol
.ginfo
.value
.address
= addr
;
8471 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8472 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8474 case DW_TAG_constant
:
8475 psymbol
.domain
= VAR_DOMAIN
;
8476 psymbol
.aclass
= LOC_STATIC
;
8477 where
= (pdi
->is_external
8478 ? psymbol_placement::GLOBAL
8479 : psymbol_placement::STATIC
);
8481 case DW_TAG_variable
:
8483 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8487 && !per_objfile
->per_bfd
->has_section_at_zero
)
8489 /* A global or static variable may also have been stripped
8490 out by the linker if unused, in which case its address
8491 will be nullified; do not add such variables into partial
8492 symbol table then. */
8494 else if (pdi
->is_external
)
8497 Don't enter into the minimal symbol tables as there is
8498 a minimal symbol table entry from the ELF symbols already.
8499 Enter into partial symbol table if it has a location
8500 descriptor or a type.
8501 If the location descriptor is missing, new_symbol will create
8502 a LOC_UNRESOLVED symbol, the address of the variable will then
8503 be determined from the minimal symbol table whenever the variable
8505 The address for the partial symbol table entry is not
8506 used by GDB, but it comes in handy for debugging partial symbol
8509 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8511 psymbol
.domain
= VAR_DOMAIN
;
8512 psymbol
.aclass
= LOC_STATIC
;
8513 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8514 psymbol
.ginfo
.value
.address
= addr
;
8515 where
= psymbol_placement::GLOBAL
;
8520 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8522 /* Static Variable. Skip symbols whose value we cannot know (those
8523 without location descriptors or constant values). */
8524 if (!has_loc
&& !pdi
->has_const_value
)
8527 psymbol
.domain
= VAR_DOMAIN
;
8528 psymbol
.aclass
= LOC_STATIC
;
8529 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8531 psymbol
.ginfo
.value
.address
= addr
;
8532 where
= psymbol_placement::STATIC
;
8535 case DW_TAG_typedef
:
8536 case DW_TAG_base_type
:
8537 case DW_TAG_subrange_type
:
8538 psymbol
.domain
= VAR_DOMAIN
;
8539 psymbol
.aclass
= LOC_TYPEDEF
;
8540 where
= psymbol_placement::STATIC
;
8542 case DW_TAG_imported_declaration
:
8543 case DW_TAG_namespace
:
8544 psymbol
.domain
= VAR_DOMAIN
;
8545 psymbol
.aclass
= LOC_TYPEDEF
;
8546 where
= psymbol_placement::GLOBAL
;
8549 /* With Fortran 77 there might be a "BLOCK DATA" module
8550 available without any name. If so, we skip the module as it
8551 doesn't bring any value. */
8552 if (actual_name
!= nullptr)
8554 psymbol
.domain
= MODULE_DOMAIN
;
8555 psymbol
.aclass
= LOC_TYPEDEF
;
8556 where
= psymbol_placement::GLOBAL
;
8559 case DW_TAG_class_type
:
8560 case DW_TAG_interface_type
:
8561 case DW_TAG_structure_type
:
8562 case DW_TAG_union_type
:
8563 case DW_TAG_enumeration_type
:
8564 /* Skip external references. The DWARF standard says in the section
8565 about "Structure, Union, and Class Type Entries": "An incomplete
8566 structure, union or class type is represented by a structure,
8567 union or class entry that does not have a byte size attribute
8568 and that has a DW_AT_declaration attribute." */
8569 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8572 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8573 static vs. global. */
8574 psymbol
.domain
= STRUCT_DOMAIN
;
8575 psymbol
.aclass
= LOC_TYPEDEF
;
8576 where
= (cu
->language
== language_cplus
8577 ? psymbol_placement::GLOBAL
8578 : psymbol_placement::STATIC
);
8580 case DW_TAG_enumerator
:
8581 psymbol
.domain
= VAR_DOMAIN
;
8582 psymbol
.aclass
= LOC_CONST
;
8583 where
= (cu
->language
== language_cplus
8584 ? psymbol_placement::GLOBAL
8585 : psymbol_placement::STATIC
);
8591 if (where
.has_value ())
8593 if (built_actual_name
!= nullptr)
8594 actual_name
= objfile
->intern (actual_name
);
8595 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8596 psymbol
.ginfo
.set_linkage_name (actual_name
);
8599 psymbol
.ginfo
.set_demangled_name (actual_name
,
8600 &objfile
->objfile_obstack
);
8601 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8603 add_psymbol_to_list (psymbol
, *where
, objfile
);
8607 /* Read a partial die corresponding to a namespace; also, add a symbol
8608 corresponding to that namespace to the symbol table. NAMESPACE is
8609 the name of the enclosing namespace. */
8612 add_partial_namespace (struct partial_die_info
*pdi
,
8613 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8614 int set_addrmap
, struct dwarf2_cu
*cu
)
8616 /* Add a symbol for the namespace. */
8618 add_partial_symbol (pdi
, cu
);
8620 /* Now scan partial symbols in that namespace. */
8622 if (pdi
->has_children
)
8623 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8626 /* Read a partial die corresponding to a Fortran module. */
8629 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8630 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8632 /* Add a symbol for the namespace. */
8634 add_partial_symbol (pdi
, cu
);
8636 /* Now scan partial symbols in that module. */
8638 if (pdi
->has_children
)
8639 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8642 /* Read a partial die corresponding to a subprogram or an inlined
8643 subprogram and create a partial symbol for that subprogram.
8644 When the CU language allows it, this routine also defines a partial
8645 symbol for each nested subprogram that this subprogram contains.
8646 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8647 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8649 PDI may also be a lexical block, in which case we simply search
8650 recursively for subprograms defined inside that lexical block.
8651 Again, this is only performed when the CU language allows this
8652 type of definitions. */
8655 add_partial_subprogram (struct partial_die_info
*pdi
,
8656 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8657 int set_addrmap
, struct dwarf2_cu
*cu
)
8659 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8661 if (pdi
->has_pc_info
)
8663 if (pdi
->lowpc
< *lowpc
)
8664 *lowpc
= pdi
->lowpc
;
8665 if (pdi
->highpc
> *highpc
)
8666 *highpc
= pdi
->highpc
;
8669 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8670 struct gdbarch
*gdbarch
= objfile
->arch ();
8672 CORE_ADDR this_highpc
;
8673 CORE_ADDR this_lowpc
;
8675 baseaddr
= objfile
->text_section_offset ();
8677 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8678 pdi
->lowpc
+ baseaddr
)
8681 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8682 pdi
->highpc
+ baseaddr
)
8684 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8685 this_lowpc
, this_highpc
- 1,
8686 cu
->per_cu
->v
.psymtab
);
8690 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8692 if (!pdi
->is_declaration
)
8693 /* Ignore subprogram DIEs that do not have a name, they are
8694 illegal. Do not emit a complaint at this point, we will
8695 do so when we convert this psymtab into a symtab. */
8697 add_partial_symbol (pdi
, cu
);
8701 if (! pdi
->has_children
)
8704 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8706 pdi
= pdi
->die_child
;
8710 if (pdi
->tag
== DW_TAG_subprogram
8711 || pdi
->tag
== DW_TAG_inlined_subroutine
8712 || pdi
->tag
== DW_TAG_lexical_block
)
8713 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8714 pdi
= pdi
->die_sibling
;
8719 /* Read a partial die corresponding to an enumeration type. */
8722 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8723 struct dwarf2_cu
*cu
)
8725 struct partial_die_info
*pdi
;
8727 if (enum_pdi
->name (cu
) != NULL
)
8728 add_partial_symbol (enum_pdi
, cu
);
8730 pdi
= enum_pdi
->die_child
;
8733 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8734 complaint (_("malformed enumerator DIE ignored"));
8736 add_partial_symbol (pdi
, cu
);
8737 pdi
= pdi
->die_sibling
;
8741 /* Return the initial uleb128 in the die at INFO_PTR. */
8744 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8746 unsigned int bytes_read
;
8748 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8751 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8752 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8754 Return the corresponding abbrev, or NULL if the number is zero (indicating
8755 an empty DIE). In either case *BYTES_READ will be set to the length of
8756 the initial number. */
8758 static struct abbrev_info
*
8759 peek_die_abbrev (const die_reader_specs
&reader
,
8760 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8762 dwarf2_cu
*cu
= reader
.cu
;
8763 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8764 unsigned int abbrev_number
8765 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8767 if (abbrev_number
== 0)
8770 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8773 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8774 " at offset %s [in module %s]"),
8775 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8776 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8782 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8783 Returns a pointer to the end of a series of DIEs, terminated by an empty
8784 DIE. Any children of the skipped DIEs will also be skipped. */
8786 static const gdb_byte
*
8787 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8791 unsigned int bytes_read
;
8792 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8795 return info_ptr
+ bytes_read
;
8797 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8801 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8802 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8803 abbrev corresponding to that skipped uleb128 should be passed in
8804 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8807 static const gdb_byte
*
8808 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8809 struct abbrev_info
*abbrev
)
8811 unsigned int bytes_read
;
8812 struct attribute attr
;
8813 bfd
*abfd
= reader
->abfd
;
8814 struct dwarf2_cu
*cu
= reader
->cu
;
8815 const gdb_byte
*buffer
= reader
->buffer
;
8816 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8817 unsigned int form
, i
;
8819 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8821 /* The only abbrev we care about is DW_AT_sibling. */
8822 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8825 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8827 if (attr
.form
== DW_FORM_ref_addr
)
8828 complaint (_("ignoring absolute DW_AT_sibling"));
8831 sect_offset off
= attr
.get_ref_die_offset ();
8832 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8834 if (sibling_ptr
< info_ptr
)
8835 complaint (_("DW_AT_sibling points backwards"));
8836 else if (sibling_ptr
> reader
->buffer_end
)
8837 reader
->die_section
->overflow_complaint ();
8843 /* If it isn't DW_AT_sibling, skip this attribute. */
8844 form
= abbrev
->attrs
[i
].form
;
8848 case DW_FORM_ref_addr
:
8849 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8850 and later it is offset sized. */
8851 if (cu
->header
.version
== 2)
8852 info_ptr
+= cu
->header
.addr_size
;
8854 info_ptr
+= cu
->header
.offset_size
;
8856 case DW_FORM_GNU_ref_alt
:
8857 info_ptr
+= cu
->header
.offset_size
;
8860 info_ptr
+= cu
->header
.addr_size
;
8868 case DW_FORM_flag_present
:
8869 case DW_FORM_implicit_const
:
8886 case DW_FORM_ref_sig8
:
8889 case DW_FORM_data16
:
8892 case DW_FORM_string
:
8893 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8894 info_ptr
+= bytes_read
;
8896 case DW_FORM_sec_offset
:
8898 case DW_FORM_GNU_strp_alt
:
8899 info_ptr
+= cu
->header
.offset_size
;
8901 case DW_FORM_exprloc
:
8903 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8904 info_ptr
+= bytes_read
;
8906 case DW_FORM_block1
:
8907 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8909 case DW_FORM_block2
:
8910 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8912 case DW_FORM_block4
:
8913 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8919 case DW_FORM_ref_udata
:
8920 case DW_FORM_GNU_addr_index
:
8921 case DW_FORM_GNU_str_index
:
8922 case DW_FORM_rnglistx
:
8923 case DW_FORM_loclistx
:
8924 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8926 case DW_FORM_indirect
:
8927 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8928 info_ptr
+= bytes_read
;
8929 /* We need to continue parsing from here, so just go back to
8931 goto skip_attribute
;
8934 error (_("Dwarf Error: Cannot handle %s "
8935 "in DWARF reader [in module %s]"),
8936 dwarf_form_name (form
),
8937 bfd_get_filename (abfd
));
8941 if (abbrev
->has_children
)
8942 return skip_children (reader
, info_ptr
);
8947 /* Locate ORIG_PDI's sibling.
8948 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8950 static const gdb_byte
*
8951 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8952 struct partial_die_info
*orig_pdi
,
8953 const gdb_byte
*info_ptr
)
8955 /* Do we know the sibling already? */
8957 if (orig_pdi
->sibling
)
8958 return orig_pdi
->sibling
;
8960 /* Are there any children to deal with? */
8962 if (!orig_pdi
->has_children
)
8965 /* Skip the children the long way. */
8967 return skip_children (reader
, info_ptr
);
8970 /* Expand this partial symbol table into a full symbol table. SELF is
8974 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8976 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8978 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8980 /* If this psymtab is constructed from a debug-only objfile, the
8981 has_section_at_zero flag will not necessarily be correct. We
8982 can get the correct value for this flag by looking at the data
8983 associated with the (presumably stripped) associated objfile. */
8984 if (objfile
->separate_debug_objfile_backlink
)
8986 dwarf2_per_objfile
*per_objfile_backlink
8987 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8989 per_objfile
->per_bfd
->has_section_at_zero
8990 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8993 expand_psymtab (objfile
);
8995 process_cu_includes (per_objfile
);
8998 /* Reading in full CUs. */
9000 /* Add PER_CU to the queue. */
9003 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9004 dwarf2_per_objfile
*per_objfile
,
9005 enum language pretend_language
)
9008 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
9011 /* If PER_CU is not yet queued, add it to the queue.
9012 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9014 The result is non-zero if PER_CU was queued, otherwise the result is zero
9015 meaning either PER_CU is already queued or it is already loaded.
9017 N.B. There is an invariant here that if a CU is queued then it is loaded.
9018 The caller is required to load PER_CU if we return non-zero. */
9021 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9022 dwarf2_per_cu_data
*per_cu
,
9023 dwarf2_per_objfile
*per_objfile
,
9024 enum language pretend_language
)
9026 /* We may arrive here during partial symbol reading, if we need full
9027 DIEs to process an unusual case (e.g. template arguments). Do
9028 not queue PER_CU, just tell our caller to load its DIEs. */
9029 if (per_cu
->per_bfd
->reading_partial_symbols
)
9031 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9033 if (cu
== NULL
|| cu
->dies
== NULL
)
9038 /* Mark the dependence relation so that we don't flush PER_CU
9040 if (dependent_cu
!= NULL
)
9041 dwarf2_add_dependence (dependent_cu
, per_cu
);
9043 /* If it's already on the queue, we have nothing to do. */
9047 /* If the compilation unit is already loaded, just mark it as
9049 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9056 /* Add it to the queue. */
9057 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9062 /* Process the queue. */
9065 process_queue (dwarf2_per_objfile
*per_objfile
)
9067 if (dwarf_read_debug
)
9069 fprintf_unfiltered (gdb_stdlog
,
9070 "Expanding one or more symtabs of objfile %s ...\n",
9071 objfile_name (per_objfile
->objfile
));
9074 /* The queue starts out with one item, but following a DIE reference
9075 may load a new CU, adding it to the end of the queue. */
9076 while (!per_objfile
->per_bfd
->queue
.empty ())
9078 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
.front ();
9079 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9081 if (!per_objfile
->symtab_set_p (per_cu
))
9083 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9085 /* Skip dummy CUs. */
9088 unsigned int debug_print_threshold
;
9091 if (per_cu
->is_debug_types
)
9093 struct signatured_type
*sig_type
=
9094 (struct signatured_type
*) per_cu
;
9096 sprintf (buf
, "TU %s at offset %s",
9097 hex_string (sig_type
->signature
),
9098 sect_offset_str (per_cu
->sect_off
));
9099 /* There can be 100s of TUs.
9100 Only print them in verbose mode. */
9101 debug_print_threshold
= 2;
9105 sprintf (buf
, "CU at offset %s",
9106 sect_offset_str (per_cu
->sect_off
));
9107 debug_print_threshold
= 1;
9110 if (dwarf_read_debug
>= debug_print_threshold
)
9111 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9113 if (per_cu
->is_debug_types
)
9114 process_full_type_unit (cu
, item
.pretend_language
);
9116 process_full_comp_unit (cu
, item
.pretend_language
);
9118 if (dwarf_read_debug
>= debug_print_threshold
)
9119 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9124 per_objfile
->per_bfd
->queue
.pop ();
9127 if (dwarf_read_debug
)
9129 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9130 objfile_name (per_objfile
->objfile
));
9134 /* Read in full symbols for PST, and anything it depends on. */
9137 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9139 gdb_assert (!readin_p (objfile
));
9141 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9142 free_cached_comp_units
freer (per_objfile
);
9143 expand_dependencies (objfile
);
9145 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9146 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9149 /* See psympriv.h. */
9152 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9154 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9155 return per_objfile
->symtab_set_p (per_cu_data
);
9158 /* See psympriv.h. */
9161 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9163 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9164 return per_objfile
->get_symtab (per_cu_data
);
9167 /* Trivial hash function for die_info: the hash value of a DIE
9168 is its offset in .debug_info for this objfile. */
9171 die_hash (const void *item
)
9173 const struct die_info
*die
= (const struct die_info
*) item
;
9175 return to_underlying (die
->sect_off
);
9178 /* Trivial comparison function for die_info structures: two DIEs
9179 are equal if they have the same offset. */
9182 die_eq (const void *item_lhs
, const void *item_rhs
)
9184 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9185 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9187 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9190 /* Load the DIEs associated with PER_CU into memory. */
9193 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9194 dwarf2_per_objfile
*per_objfile
,
9196 enum language pretend_language
)
9198 gdb_assert (! this_cu
->is_debug_types
);
9200 dwarf2_cu
*existing_cu
= per_objfile
->get_cu (this_cu
);
9201 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9205 struct dwarf2_cu
*cu
= reader
.cu
;
9206 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9208 gdb_assert (cu
->die_hash
== NULL
);
9210 htab_create_alloc_ex (cu
->header
.length
/ 12,
9214 &cu
->comp_unit_obstack
,
9215 hashtab_obstack_allocate
,
9216 dummy_obstack_deallocate
);
9218 if (reader
.comp_unit_die
->has_children
)
9219 reader
.comp_unit_die
->child
9220 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9221 &info_ptr
, reader
.comp_unit_die
);
9222 cu
->dies
= reader
.comp_unit_die
;
9223 /* comp_unit_die is not stored in die_hash, no need. */
9225 /* We try not to read any attributes in this function, because not
9226 all CUs needed for references have been loaded yet, and symbol
9227 table processing isn't initialized. But we have to set the CU language,
9228 or we won't be able to build types correctly.
9229 Similarly, if we do not read the producer, we can not apply
9230 producer-specific interpretation. */
9231 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9236 /* Add a DIE to the delayed physname list. */
9239 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9240 const char *name
, struct die_info
*die
,
9241 struct dwarf2_cu
*cu
)
9243 struct delayed_method_info mi
;
9245 mi
.fnfield_index
= fnfield_index
;
9249 cu
->method_list
.push_back (mi
);
9252 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9253 "const" / "volatile". If so, decrements LEN by the length of the
9254 modifier and return true. Otherwise return false. */
9258 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9260 size_t mod_len
= sizeof (mod
) - 1;
9261 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9269 /* Compute the physnames of any methods on the CU's method list.
9271 The computation of method physnames is delayed in order to avoid the
9272 (bad) condition that one of the method's formal parameters is of an as yet
9276 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9278 /* Only C++ delays computing physnames. */
9279 if (cu
->method_list
.empty ())
9281 gdb_assert (cu
->language
== language_cplus
);
9283 for (const delayed_method_info
&mi
: cu
->method_list
)
9285 const char *physname
;
9286 struct fn_fieldlist
*fn_flp
9287 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9288 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9289 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9290 = physname
? physname
: "";
9292 /* Since there's no tag to indicate whether a method is a
9293 const/volatile overload, extract that information out of the
9295 if (physname
!= NULL
)
9297 size_t len
= strlen (physname
);
9301 if (physname
[len
] == ')') /* shortcut */
9303 else if (check_modifier (physname
, len
, " const"))
9304 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9305 else if (check_modifier (physname
, len
, " volatile"))
9306 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9313 /* The list is no longer needed. */
9314 cu
->method_list
.clear ();
9317 /* Go objects should be embedded in a DW_TAG_module DIE,
9318 and it's not clear if/how imported objects will appear.
9319 To keep Go support simple until that's worked out,
9320 go back through what we've read and create something usable.
9321 We could do this while processing each DIE, and feels kinda cleaner,
9322 but that way is more invasive.
9323 This is to, for example, allow the user to type "p var" or "b main"
9324 without having to specify the package name, and allow lookups
9325 of module.object to work in contexts that use the expression
9329 fixup_go_packaging (struct dwarf2_cu
*cu
)
9331 gdb::unique_xmalloc_ptr
<char> package_name
;
9332 struct pending
*list
;
9335 for (list
= *cu
->get_builder ()->get_global_symbols ();
9339 for (i
= 0; i
< list
->nsyms
; ++i
)
9341 struct symbol
*sym
= list
->symbol
[i
];
9343 if (sym
->language () == language_go
9344 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9346 gdb::unique_xmalloc_ptr
<char> this_package_name
9347 (go_symbol_package_name (sym
));
9349 if (this_package_name
== NULL
)
9351 if (package_name
== NULL
)
9352 package_name
= std::move (this_package_name
);
9355 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9356 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9357 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9358 (symbol_symtab (sym
) != NULL
9359 ? symtab_to_filename_for_display
9360 (symbol_symtab (sym
))
9361 : objfile_name (objfile
)),
9362 this_package_name
.get (), package_name
.get ());
9368 if (package_name
!= NULL
)
9370 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9371 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9372 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9373 saved_package_name
);
9376 sym
= new (&objfile
->objfile_obstack
) symbol
;
9377 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9378 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9379 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9380 e.g., "main" finds the "main" module and not C's main(). */
9381 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9382 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9383 SYMBOL_TYPE (sym
) = type
;
9385 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9389 /* Allocate a fully-qualified name consisting of the two parts on the
9393 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9395 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9398 /* A helper that allocates a variant part to attach to a Rust enum
9399 type. OBSTACK is where the results should be allocated. TYPE is
9400 the type we're processing. DISCRIMINANT_INDEX is the index of the
9401 discriminant. It must be the index of one of the fields of TYPE.
9402 DEFAULT_INDEX is the index of the default field; or -1 if there is
9403 no default. RANGES is indexed by "effective" field number (the
9404 field index, but omitting the discriminant and default fields) and
9405 must hold the discriminant values used by the variants. Note that
9406 RANGES must have a lifetime at least as long as OBSTACK -- either
9407 already allocated on it, or static. */
9410 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9411 int discriminant_index
, int default_index
,
9412 gdb::array_view
<discriminant_range
> ranges
)
9414 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9415 must be handled by the caller. */
9416 gdb_assert (discriminant_index
>= 0
9417 && discriminant_index
< type
->num_fields ());
9418 gdb_assert (default_index
== -1
9419 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9421 /* We have one variant for each non-discriminant field. */
9422 int n_variants
= type
->num_fields () - 1;
9424 variant
*variants
= new (obstack
) variant
[n_variants
];
9427 for (int i
= 0; i
< type
->num_fields (); ++i
)
9429 if (i
== discriminant_index
)
9432 variants
[var_idx
].first_field
= i
;
9433 variants
[var_idx
].last_field
= i
+ 1;
9435 /* The default field does not need a range, but other fields do.
9436 We skipped the discriminant above. */
9437 if (i
!= default_index
)
9439 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9446 gdb_assert (range_idx
== ranges
.size ());
9447 gdb_assert (var_idx
== n_variants
);
9449 variant_part
*part
= new (obstack
) variant_part
;
9450 part
->discriminant_index
= discriminant_index
;
9451 part
->is_unsigned
= TYPE_UNSIGNED (type
->field (discriminant_index
).type ());
9452 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9454 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9455 gdb::array_view
<variant_part
> *prop_value
9456 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9458 struct dynamic_prop prop
;
9459 prop
.kind
= PROP_VARIANT_PARTS
;
9460 prop
.data
.variant_parts
= prop_value
;
9462 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9465 /* Some versions of rustc emitted enums in an unusual way.
9467 Ordinary enums were emitted as unions. The first element of each
9468 structure in the union was named "RUST$ENUM$DISR". This element
9469 held the discriminant.
9471 These versions of Rust also implemented the "non-zero"
9472 optimization. When the enum had two values, and one is empty and
9473 the other holds a pointer that cannot be zero, the pointer is used
9474 as the discriminant, with a zero value meaning the empty variant.
9475 Here, the union's first member is of the form
9476 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9477 where the fieldnos are the indices of the fields that should be
9478 traversed in order to find the field (which may be several fields deep)
9479 and the variantname is the name of the variant of the case when the
9482 This function recognizes whether TYPE is of one of these forms,
9483 and, if so, smashes it to be a variant type. */
9486 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9488 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9490 /* We don't need to deal with empty enums. */
9491 if (type
->num_fields () == 0)
9494 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9495 if (type
->num_fields () == 1
9496 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9498 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9500 /* Decode the field name to find the offset of the
9502 ULONGEST bit_offset
= 0;
9503 struct type
*field_type
= type
->field (0).type ();
9504 while (name
[0] >= '0' && name
[0] <= '9')
9507 unsigned long index
= strtoul (name
, &tail
, 10);
9510 || index
>= field_type
->num_fields ()
9511 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9512 != FIELD_LOC_KIND_BITPOS
))
9514 complaint (_("Could not parse Rust enum encoding string \"%s\""
9516 TYPE_FIELD_NAME (type
, 0),
9517 objfile_name (objfile
));
9522 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9523 field_type
= field_type
->field (index
).type ();
9526 /* Smash this type to be a structure type. We have to do this
9527 because the type has already been recorded. */
9528 type
->set_code (TYPE_CODE_STRUCT
);
9529 type
->set_num_fields (3);
9530 /* Save the field we care about. */
9531 struct field saved_field
= type
->field (0);
9533 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9535 /* Put the discriminant at index 0. */
9536 type
->field (0).set_type (field_type
);
9537 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9538 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9539 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9541 /* The order of fields doesn't really matter, so put the real
9542 field at index 1 and the data-less field at index 2. */
9543 type
->field (1) = saved_field
;
9544 TYPE_FIELD_NAME (type
, 1)
9545 = rust_last_path_segment (type
->field (1).type ()->name ());
9546 type
->field (1).type ()->set_name
9547 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9548 TYPE_FIELD_NAME (type
, 1)));
9550 const char *dataless_name
9551 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9553 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9555 type
->field (2).set_type (dataless_type
);
9556 /* NAME points into the original discriminant name, which
9557 already has the correct lifetime. */
9558 TYPE_FIELD_NAME (type
, 2) = name
;
9559 SET_FIELD_BITPOS (type
->field (2), 0);
9561 /* Indicate that this is a variant type. */
9562 static discriminant_range ranges
[1] = { { 0, 0 } };
9563 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9565 /* A union with a single anonymous field is probably an old-style
9567 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9569 /* Smash this type to be a structure type. We have to do this
9570 because the type has already been recorded. */
9571 type
->set_code (TYPE_CODE_STRUCT
);
9573 struct type
*field_type
= type
->field (0).type ();
9574 const char *variant_name
9575 = rust_last_path_segment (field_type
->name ());
9576 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9577 field_type
->set_name
9578 (rust_fully_qualify (&objfile
->objfile_obstack
,
9579 type
->name (), variant_name
));
9583 struct type
*disr_type
= nullptr;
9584 for (int i
= 0; i
< type
->num_fields (); ++i
)
9586 disr_type
= type
->field (i
).type ();
9588 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9590 /* All fields of a true enum will be structs. */
9593 else if (disr_type
->num_fields () == 0)
9595 /* Could be data-less variant, so keep going. */
9596 disr_type
= nullptr;
9598 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9599 "RUST$ENUM$DISR") != 0)
9601 /* Not a Rust enum. */
9611 /* If we got here without a discriminant, then it's probably
9613 if (disr_type
== nullptr)
9616 /* Smash this type to be a structure type. We have to do this
9617 because the type has already been recorded. */
9618 type
->set_code (TYPE_CODE_STRUCT
);
9620 /* Make space for the discriminant field. */
9621 struct field
*disr_field
= &disr_type
->field (0);
9623 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9624 * sizeof (struct field
)));
9625 memcpy (new_fields
+ 1, type
->fields (),
9626 type
->num_fields () * sizeof (struct field
));
9627 type
->set_fields (new_fields
);
9628 type
->set_num_fields (type
->num_fields () + 1);
9630 /* Install the discriminant at index 0 in the union. */
9631 type
->field (0) = *disr_field
;
9632 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9633 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9635 /* We need a way to find the correct discriminant given a
9636 variant name. For convenience we build a map here. */
9637 struct type
*enum_type
= disr_field
->type ();
9638 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9639 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9641 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9644 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9645 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9649 int n_fields
= type
->num_fields ();
9650 /* We don't need a range entry for the discriminant, but we do
9651 need one for every other field, as there is no default
9653 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9656 /* Skip the discriminant here. */
9657 for (int i
= 1; i
< n_fields
; ++i
)
9659 /* Find the final word in the name of this variant's type.
9660 That name can be used to look up the correct
9662 const char *variant_name
9663 = rust_last_path_segment (type
->field (i
).type ()->name ());
9665 auto iter
= discriminant_map
.find (variant_name
);
9666 if (iter
!= discriminant_map
.end ())
9668 ranges
[i
].low
= iter
->second
;
9669 ranges
[i
].high
= iter
->second
;
9672 /* Remove the discriminant field, if it exists. */
9673 struct type
*sub_type
= type
->field (i
).type ();
9674 if (sub_type
->num_fields () > 0)
9676 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9677 sub_type
->set_fields (sub_type
->fields () + 1);
9679 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9681 (rust_fully_qualify (&objfile
->objfile_obstack
,
9682 type
->name (), variant_name
));
9685 /* Indicate that this is a variant type. */
9686 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9687 gdb::array_view
<discriminant_range
> (ranges
,
9692 /* Rewrite some Rust unions to be structures with variants parts. */
9695 rust_union_quirks (struct dwarf2_cu
*cu
)
9697 gdb_assert (cu
->language
== language_rust
);
9698 for (type
*type_
: cu
->rust_unions
)
9699 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9700 /* We don't need this any more. */
9701 cu
->rust_unions
.clear ();
9706 type_unit_group_unshareable
*
9707 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9709 auto iter
= this->m_type_units
.find (tu_group
);
9710 if (iter
!= this->m_type_units
.end ())
9711 return iter
->second
.get ();
9713 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9714 type_unit_group_unshareable
*result
= uniq
.get ();
9715 this->m_type_units
[tu_group
] = std::move (uniq
);
9720 dwarf2_per_objfile::get_type_for_signatured_type
9721 (signatured_type
*sig_type
) const
9723 auto iter
= this->m_type_map
.find (sig_type
);
9724 if (iter
== this->m_type_map
.end ())
9727 return iter
->second
;
9730 void dwarf2_per_objfile::set_type_for_signatured_type
9731 (signatured_type
*sig_type
, struct type
*type
)
9733 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9735 this->m_type_map
[sig_type
] = type
;
9738 /* A helper function for computing the list of all symbol tables
9739 included by PER_CU. */
9742 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9743 htab_t all_children
, htab_t all_type_symtabs
,
9744 dwarf2_per_cu_data
*per_cu
,
9745 dwarf2_per_objfile
*per_objfile
,
9746 struct compunit_symtab
*immediate_parent
)
9748 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9751 /* This inclusion and its children have been processed. */
9757 /* Only add a CU if it has a symbol table. */
9758 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9761 /* If this is a type unit only add its symbol table if we haven't
9762 seen it yet (type unit per_cu's can share symtabs). */
9763 if (per_cu
->is_debug_types
)
9765 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9769 result
->push_back (cust
);
9770 if (cust
->user
== NULL
)
9771 cust
->user
= immediate_parent
;
9776 result
->push_back (cust
);
9777 if (cust
->user
== NULL
)
9778 cust
->user
= immediate_parent
;
9782 if (!per_cu
->imported_symtabs_empty ())
9783 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9785 recursively_compute_inclusions (result
, all_children
,
9786 all_type_symtabs
, ptr
, per_objfile
,
9791 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9795 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9796 dwarf2_per_objfile
*per_objfile
)
9798 gdb_assert (! per_cu
->is_debug_types
);
9800 if (!per_cu
->imported_symtabs_empty ())
9803 std::vector
<compunit_symtab
*> result_symtabs
;
9804 htab_t all_children
, all_type_symtabs
;
9805 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9807 /* If we don't have a symtab, we can just skip this case. */
9811 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9812 NULL
, xcalloc
, xfree
);
9813 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9814 NULL
, xcalloc
, xfree
);
9816 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9818 recursively_compute_inclusions (&result_symtabs
, all_children
,
9819 all_type_symtabs
, ptr
, per_objfile
,
9823 /* Now we have a transitive closure of all the included symtabs. */
9824 len
= result_symtabs
.size ();
9826 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9827 struct compunit_symtab
*, len
+ 1);
9828 memcpy (cust
->includes
, result_symtabs
.data (),
9829 len
* sizeof (compunit_symtab
*));
9830 cust
->includes
[len
] = NULL
;
9832 htab_delete (all_children
);
9833 htab_delete (all_type_symtabs
);
9837 /* Compute the 'includes' field for the symtabs of all the CUs we just
9841 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9843 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9845 if (! iter
->is_debug_types
)
9846 compute_compunit_symtab_includes (iter
, per_objfile
);
9849 per_objfile
->per_bfd
->just_read_cus
.clear ();
9852 /* Generate full symbol information for CU, whose DIEs have
9853 already been loaded into memory. */
9856 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9858 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9859 struct objfile
*objfile
= per_objfile
->objfile
;
9860 struct gdbarch
*gdbarch
= objfile
->arch ();
9861 CORE_ADDR lowpc
, highpc
;
9862 struct compunit_symtab
*cust
;
9864 struct block
*static_block
;
9867 baseaddr
= objfile
->text_section_offset ();
9869 /* Clear the list here in case something was left over. */
9870 cu
->method_list
.clear ();
9872 cu
->language
= pretend_language
;
9873 cu
->language_defn
= language_def (cu
->language
);
9875 /* Do line number decoding in read_file_scope () */
9876 process_die (cu
->dies
, cu
);
9878 /* For now fudge the Go package. */
9879 if (cu
->language
== language_go
)
9880 fixup_go_packaging (cu
);
9882 /* Now that we have processed all the DIEs in the CU, all the types
9883 should be complete, and it should now be safe to compute all of the
9885 compute_delayed_physnames (cu
);
9887 if (cu
->language
== language_rust
)
9888 rust_union_quirks (cu
);
9890 /* Some compilers don't define a DW_AT_high_pc attribute for the
9891 compilation unit. If the DW_AT_high_pc is missing, synthesize
9892 it, by scanning the DIE's below the compilation unit. */
9893 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9895 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9896 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9898 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9899 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9900 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9901 addrmap to help ensure it has an accurate map of pc values belonging to
9903 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9905 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9906 SECT_OFF_TEXT (objfile
),
9911 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9913 /* Set symtab language to language from DW_AT_language. If the
9914 compilation is from a C file generated by language preprocessors, do
9915 not set the language if it was already deduced by start_subfile. */
9916 if (!(cu
->language
== language_c
9917 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9918 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9920 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9921 produce DW_AT_location with location lists but it can be possibly
9922 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9923 there were bugs in prologue debug info, fixed later in GCC-4.5
9924 by "unwind info for epilogues" patch (which is not directly related).
9926 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9927 needed, it would be wrong due to missing DW_AT_producer there.
9929 Still one can confuse GDB by using non-standard GCC compilation
9930 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9932 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9933 cust
->locations_valid
= 1;
9935 if (gcc_4_minor
>= 5)
9936 cust
->epilogue_unwind_valid
= 1;
9938 cust
->call_site_htab
= cu
->call_site_htab
;
9941 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9943 /* Push it for inclusion processing later. */
9944 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9946 /* Not needed any more. */
9947 cu
->reset_builder ();
9950 /* Generate full symbol information for type unit CU, whose DIEs have
9951 already been loaded into memory. */
9954 process_full_type_unit (dwarf2_cu
*cu
,
9955 enum language pretend_language
)
9957 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9958 struct objfile
*objfile
= per_objfile
->objfile
;
9959 struct compunit_symtab
*cust
;
9960 struct signatured_type
*sig_type
;
9962 gdb_assert (cu
->per_cu
->is_debug_types
);
9963 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9965 /* Clear the list here in case something was left over. */
9966 cu
->method_list
.clear ();
9968 cu
->language
= pretend_language
;
9969 cu
->language_defn
= language_def (cu
->language
);
9971 /* The symbol tables are set up in read_type_unit_scope. */
9972 process_die (cu
->dies
, cu
);
9974 /* For now fudge the Go package. */
9975 if (cu
->language
== language_go
)
9976 fixup_go_packaging (cu
);
9978 /* Now that we have processed all the DIEs in the CU, all the types
9979 should be complete, and it should now be safe to compute all of the
9981 compute_delayed_physnames (cu
);
9983 if (cu
->language
== language_rust
)
9984 rust_union_quirks (cu
);
9986 /* TUs share symbol tables.
9987 If this is the first TU to use this symtab, complete the construction
9988 of it with end_expandable_symtab. Otherwise, complete the addition of
9989 this TU's symbols to the existing symtab. */
9990 type_unit_group_unshareable
*tug_unshare
=
9991 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9992 if (tug_unshare
->compunit_symtab
== NULL
)
9994 buildsym_compunit
*builder
= cu
->get_builder ();
9995 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9996 tug_unshare
->compunit_symtab
= cust
;
10000 /* Set symtab language to language from DW_AT_language. If the
10001 compilation is from a C file generated by language preprocessors,
10002 do not set the language if it was already deduced by
10004 if (!(cu
->language
== language_c
10005 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10006 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10011 cu
->get_builder ()->augment_type_symtab ();
10012 cust
= tug_unshare
->compunit_symtab
;
10015 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10017 /* Not needed any more. */
10018 cu
->reset_builder ();
10021 /* Process an imported unit DIE. */
10024 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10026 struct attribute
*attr
;
10028 /* For now we don't handle imported units in type units. */
10029 if (cu
->per_cu
->is_debug_types
)
10031 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10032 " supported in type units [in module %s]"),
10033 objfile_name (cu
->per_objfile
->objfile
));
10036 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10039 sect_offset sect_off
= attr
->get_ref_die_offset ();
10040 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10041 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10042 dwarf2_per_cu_data
*per_cu
10043 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10045 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10046 into another compilation unit, at root level. Regard this as a hint,
10048 if (die
->parent
&& die
->parent
->parent
== NULL
10049 && per_cu
->unit_type
== DW_UT_compile
10050 && per_cu
->lang
== language_cplus
)
10053 /* If necessary, add it to the queue and load its DIEs. */
10054 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10055 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
10057 cu
->per_cu
->imported_symtabs_push (per_cu
);
10061 /* RAII object that represents a process_die scope: i.e.,
10062 starts/finishes processing a DIE. */
10063 class process_die_scope
10066 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10067 : m_die (die
), m_cu (cu
)
10069 /* We should only be processing DIEs not already in process. */
10070 gdb_assert (!m_die
->in_process
);
10071 m_die
->in_process
= true;
10074 ~process_die_scope ()
10076 m_die
->in_process
= false;
10078 /* If we're done processing the DIE for the CU that owns the line
10079 header, we don't need the line header anymore. */
10080 if (m_cu
->line_header_die_owner
== m_die
)
10082 delete m_cu
->line_header
;
10083 m_cu
->line_header
= NULL
;
10084 m_cu
->line_header_die_owner
= NULL
;
10093 /* Process a die and its children. */
10096 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10098 process_die_scope
scope (die
, cu
);
10102 case DW_TAG_padding
:
10104 case DW_TAG_compile_unit
:
10105 case DW_TAG_partial_unit
:
10106 read_file_scope (die
, cu
);
10108 case DW_TAG_type_unit
:
10109 read_type_unit_scope (die
, cu
);
10111 case DW_TAG_subprogram
:
10112 /* Nested subprograms in Fortran get a prefix. */
10113 if (cu
->language
== language_fortran
10114 && die
->parent
!= NULL
10115 && die
->parent
->tag
== DW_TAG_subprogram
)
10116 cu
->processing_has_namespace_info
= true;
10117 /* Fall through. */
10118 case DW_TAG_inlined_subroutine
:
10119 read_func_scope (die
, cu
);
10121 case DW_TAG_lexical_block
:
10122 case DW_TAG_try_block
:
10123 case DW_TAG_catch_block
:
10124 read_lexical_block_scope (die
, cu
);
10126 case DW_TAG_call_site
:
10127 case DW_TAG_GNU_call_site
:
10128 read_call_site_scope (die
, cu
);
10130 case DW_TAG_class_type
:
10131 case DW_TAG_interface_type
:
10132 case DW_TAG_structure_type
:
10133 case DW_TAG_union_type
:
10134 process_structure_scope (die
, cu
);
10136 case DW_TAG_enumeration_type
:
10137 process_enumeration_scope (die
, cu
);
10140 /* These dies have a type, but processing them does not create
10141 a symbol or recurse to process the children. Therefore we can
10142 read them on-demand through read_type_die. */
10143 case DW_TAG_subroutine_type
:
10144 case DW_TAG_set_type
:
10145 case DW_TAG_array_type
:
10146 case DW_TAG_pointer_type
:
10147 case DW_TAG_ptr_to_member_type
:
10148 case DW_TAG_reference_type
:
10149 case DW_TAG_rvalue_reference_type
:
10150 case DW_TAG_string_type
:
10153 case DW_TAG_base_type
:
10154 case DW_TAG_subrange_type
:
10155 case DW_TAG_typedef
:
10156 /* Add a typedef symbol for the type definition, if it has a
10158 new_symbol (die
, read_type_die (die
, cu
), cu
);
10160 case DW_TAG_common_block
:
10161 read_common_block (die
, cu
);
10163 case DW_TAG_common_inclusion
:
10165 case DW_TAG_namespace
:
10166 cu
->processing_has_namespace_info
= true;
10167 read_namespace (die
, cu
);
10169 case DW_TAG_module
:
10170 cu
->processing_has_namespace_info
= true;
10171 read_module (die
, cu
);
10173 case DW_TAG_imported_declaration
:
10174 cu
->processing_has_namespace_info
= true;
10175 if (read_namespace_alias (die
, cu
))
10177 /* The declaration is not a global namespace alias. */
10178 /* Fall through. */
10179 case DW_TAG_imported_module
:
10180 cu
->processing_has_namespace_info
= true;
10181 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10182 || cu
->language
!= language_fortran
))
10183 complaint (_("Tag '%s' has unexpected children"),
10184 dwarf_tag_name (die
->tag
));
10185 read_import_statement (die
, cu
);
10188 case DW_TAG_imported_unit
:
10189 process_imported_unit_die (die
, cu
);
10192 case DW_TAG_variable
:
10193 read_variable (die
, cu
);
10197 new_symbol (die
, NULL
, cu
);
10202 /* DWARF name computation. */
10204 /* A helper function for dwarf2_compute_name which determines whether DIE
10205 needs to have the name of the scope prepended to the name listed in the
10209 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10211 struct attribute
*attr
;
10215 case DW_TAG_namespace
:
10216 case DW_TAG_typedef
:
10217 case DW_TAG_class_type
:
10218 case DW_TAG_interface_type
:
10219 case DW_TAG_structure_type
:
10220 case DW_TAG_union_type
:
10221 case DW_TAG_enumeration_type
:
10222 case DW_TAG_enumerator
:
10223 case DW_TAG_subprogram
:
10224 case DW_TAG_inlined_subroutine
:
10225 case DW_TAG_member
:
10226 case DW_TAG_imported_declaration
:
10229 case DW_TAG_variable
:
10230 case DW_TAG_constant
:
10231 /* We only need to prefix "globally" visible variables. These include
10232 any variable marked with DW_AT_external or any variable that
10233 lives in a namespace. [Variables in anonymous namespaces
10234 require prefixing, but they are not DW_AT_external.] */
10236 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10238 struct dwarf2_cu
*spec_cu
= cu
;
10240 return die_needs_namespace (die_specification (die
, &spec_cu
),
10244 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10245 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10246 && die
->parent
->tag
!= DW_TAG_module
)
10248 /* A variable in a lexical block of some kind does not need a
10249 namespace, even though in C++ such variables may be external
10250 and have a mangled name. */
10251 if (die
->parent
->tag
== DW_TAG_lexical_block
10252 || die
->parent
->tag
== DW_TAG_try_block
10253 || die
->parent
->tag
== DW_TAG_catch_block
10254 || die
->parent
->tag
== DW_TAG_subprogram
)
10263 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10264 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10265 defined for the given DIE. */
10267 static struct attribute
*
10268 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10270 struct attribute
*attr
;
10272 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10274 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10279 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10280 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10281 defined for the given DIE. */
10283 static const char *
10284 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10286 const char *linkage_name
;
10288 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10289 if (linkage_name
== NULL
)
10290 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10292 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10293 See https://github.com/rust-lang/rust/issues/32925. */
10294 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10295 && strchr (linkage_name
, '{') != NULL
)
10296 linkage_name
= NULL
;
10298 return linkage_name
;
10301 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10302 compute the physname for the object, which include a method's:
10303 - formal parameters (C++),
10304 - receiver type (Go),
10306 The term "physname" is a bit confusing.
10307 For C++, for example, it is the demangled name.
10308 For Go, for example, it's the mangled name.
10310 For Ada, return the DIE's linkage name rather than the fully qualified
10311 name. PHYSNAME is ignored..
10313 The result is allocated on the objfile->per_bfd's obstack and
10316 static const char *
10317 dwarf2_compute_name (const char *name
,
10318 struct die_info
*die
, struct dwarf2_cu
*cu
,
10321 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10324 name
= dwarf2_name (die
, cu
);
10326 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10327 but otherwise compute it by typename_concat inside GDB.
10328 FIXME: Actually this is not really true, or at least not always true.
10329 It's all very confusing. compute_and_set_names doesn't try to demangle
10330 Fortran names because there is no mangling standard. So new_symbol
10331 will set the demangled name to the result of dwarf2_full_name, and it is
10332 the demangled name that GDB uses if it exists. */
10333 if (cu
->language
== language_ada
10334 || (cu
->language
== language_fortran
&& physname
))
10336 /* For Ada unit, we prefer the linkage name over the name, as
10337 the former contains the exported name, which the user expects
10338 to be able to reference. Ideally, we want the user to be able
10339 to reference this entity using either natural or linkage name,
10340 but we haven't started looking at this enhancement yet. */
10341 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10343 if (linkage_name
!= NULL
)
10344 return linkage_name
;
10347 /* These are the only languages we know how to qualify names in. */
10349 && (cu
->language
== language_cplus
10350 || cu
->language
== language_fortran
|| cu
->language
== language_d
10351 || cu
->language
== language_rust
))
10353 if (die_needs_namespace (die
, cu
))
10355 const char *prefix
;
10356 const char *canonical_name
= NULL
;
10360 prefix
= determine_prefix (die
, cu
);
10361 if (*prefix
!= '\0')
10363 gdb::unique_xmalloc_ptr
<char> prefixed_name
10364 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10366 buf
.puts (prefixed_name
.get ());
10371 /* Template parameters may be specified in the DIE's DW_AT_name, or
10372 as children with DW_TAG_template_type_param or
10373 DW_TAG_value_type_param. If the latter, add them to the name
10374 here. If the name already has template parameters, then
10375 skip this step; some versions of GCC emit both, and
10376 it is more efficient to use the pre-computed name.
10378 Something to keep in mind about this process: it is very
10379 unlikely, or in some cases downright impossible, to produce
10380 something that will match the mangled name of a function.
10381 If the definition of the function has the same debug info,
10382 we should be able to match up with it anyway. But fallbacks
10383 using the minimal symbol, for instance to find a method
10384 implemented in a stripped copy of libstdc++, will not work.
10385 If we do not have debug info for the definition, we will have to
10386 match them up some other way.
10388 When we do name matching there is a related problem with function
10389 templates; two instantiated function templates are allowed to
10390 differ only by their return types, which we do not add here. */
10392 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10394 struct attribute
*attr
;
10395 struct die_info
*child
;
10398 die
->building_fullname
= 1;
10400 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10404 const gdb_byte
*bytes
;
10405 struct dwarf2_locexpr_baton
*baton
;
10408 if (child
->tag
!= DW_TAG_template_type_param
10409 && child
->tag
!= DW_TAG_template_value_param
)
10420 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10423 complaint (_("template parameter missing DW_AT_type"));
10424 buf
.puts ("UNKNOWN_TYPE");
10427 type
= die_type (child
, cu
);
10429 if (child
->tag
== DW_TAG_template_type_param
)
10431 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10432 &type_print_raw_options
);
10436 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10439 complaint (_("template parameter missing "
10440 "DW_AT_const_value"));
10441 buf
.puts ("UNKNOWN_VALUE");
10445 dwarf2_const_value_attr (attr
, type
, name
,
10446 &cu
->comp_unit_obstack
, cu
,
10447 &value
, &bytes
, &baton
);
10449 if (TYPE_NOSIGN (type
))
10450 /* GDB prints characters as NUMBER 'CHAR'. If that's
10451 changed, this can use value_print instead. */
10452 c_printchar (value
, type
, &buf
);
10455 struct value_print_options opts
;
10458 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10462 baton
->per_objfile
);
10463 else if (bytes
!= NULL
)
10465 v
= allocate_value (type
);
10466 memcpy (value_contents_writeable (v
), bytes
,
10467 TYPE_LENGTH (type
));
10470 v
= value_from_longest (type
, value
);
10472 /* Specify decimal so that we do not depend on
10474 get_formatted_print_options (&opts
, 'd');
10476 value_print (v
, &buf
, &opts
);
10481 die
->building_fullname
= 0;
10485 /* Close the argument list, with a space if necessary
10486 (nested templates). */
10487 if (!buf
.empty () && buf
.string ().back () == '>')
10494 /* For C++ methods, append formal parameter type
10495 information, if PHYSNAME. */
10497 if (physname
&& die
->tag
== DW_TAG_subprogram
10498 && cu
->language
== language_cplus
)
10500 struct type
*type
= read_type_die (die
, cu
);
10502 c_type_print_args (type
, &buf
, 1, cu
->language
,
10503 &type_print_raw_options
);
10505 if (cu
->language
== language_cplus
)
10507 /* Assume that an artificial first parameter is
10508 "this", but do not crash if it is not. RealView
10509 marks unnamed (and thus unused) parameters as
10510 artificial; there is no way to differentiate
10512 if (type
->num_fields () > 0
10513 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10514 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10515 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10516 buf
.puts (" const");
10520 const std::string
&intermediate_name
= buf
.string ();
10522 if (cu
->language
== language_cplus
)
10524 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10527 /* If we only computed INTERMEDIATE_NAME, or if
10528 INTERMEDIATE_NAME is already canonical, then we need to
10530 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10531 name
= objfile
->intern (intermediate_name
);
10533 name
= canonical_name
;
10540 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10541 If scope qualifiers are appropriate they will be added. The result
10542 will be allocated on the storage_obstack, or NULL if the DIE does
10543 not have a name. NAME may either be from a previous call to
10544 dwarf2_name or NULL.
10546 The output string will be canonicalized (if C++). */
10548 static const char *
10549 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10551 return dwarf2_compute_name (name
, die
, cu
, 0);
10554 /* Construct a physname for the given DIE in CU. NAME may either be
10555 from a previous call to dwarf2_name or NULL. The result will be
10556 allocated on the objfile_objstack or NULL if the DIE does not have a
10559 The output string will be canonicalized (if C++). */
10561 static const char *
10562 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10564 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10565 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10568 /* In this case dwarf2_compute_name is just a shortcut not building anything
10570 if (!die_needs_namespace (die
, cu
))
10571 return dwarf2_compute_name (name
, die
, cu
, 1);
10573 if (cu
->language
!= language_rust
)
10574 mangled
= dw2_linkage_name (die
, cu
);
10576 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10578 gdb::unique_xmalloc_ptr
<char> demangled
;
10579 if (mangled
!= NULL
)
10582 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10584 /* Do nothing (do not demangle the symbol name). */
10586 else if (cu
->language
== language_go
)
10588 /* This is a lie, but we already lie to the caller new_symbol.
10589 new_symbol assumes we return the mangled name.
10590 This just undoes that lie until things are cleaned up. */
10594 /* Use DMGL_RET_DROP for C++ template functions to suppress
10595 their return type. It is easier for GDB users to search
10596 for such functions as `name(params)' than `long name(params)'.
10597 In such case the minimal symbol names do not match the full
10598 symbol names but for template functions there is never a need
10599 to look up their definition from their declaration so
10600 the only disadvantage remains the minimal symbol variant
10601 `long name(params)' does not have the proper inferior type. */
10602 demangled
.reset (gdb_demangle (mangled
,
10603 (DMGL_PARAMS
| DMGL_ANSI
10604 | DMGL_RET_DROP
)));
10607 canon
= demangled
.get ();
10615 if (canon
== NULL
|| check_physname
)
10617 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10619 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10621 /* It may not mean a bug in GDB. The compiler could also
10622 compute DW_AT_linkage_name incorrectly. But in such case
10623 GDB would need to be bug-to-bug compatible. */
10625 complaint (_("Computed physname <%s> does not match demangled <%s> "
10626 "(from linkage <%s>) - DIE at %s [in module %s]"),
10627 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10628 objfile_name (objfile
));
10630 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10631 is available here - over computed PHYSNAME. It is safer
10632 against both buggy GDB and buggy compilers. */
10646 retval
= objfile
->intern (retval
);
10651 /* Inspect DIE in CU for a namespace alias. If one exists, record
10652 a new symbol for it.
10654 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10657 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10659 struct attribute
*attr
;
10661 /* If the die does not have a name, this is not a namespace
10663 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10667 struct die_info
*d
= die
;
10668 struct dwarf2_cu
*imported_cu
= cu
;
10670 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10671 keep inspecting DIEs until we hit the underlying import. */
10672 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10673 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10675 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10679 d
= follow_die_ref (d
, attr
, &imported_cu
);
10680 if (d
->tag
!= DW_TAG_imported_declaration
)
10684 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10686 complaint (_("DIE at %s has too many recursively imported "
10687 "declarations"), sect_offset_str (d
->sect_off
));
10694 sect_offset sect_off
= attr
->get_ref_die_offset ();
10696 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10697 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10699 /* This declaration is a global namespace alias. Add
10700 a symbol for it whose type is the aliased namespace. */
10701 new_symbol (die
, type
, cu
);
10710 /* Return the using directives repository (global or local?) to use in the
10711 current context for CU.
10713 For Ada, imported declarations can materialize renamings, which *may* be
10714 global. However it is impossible (for now?) in DWARF to distinguish
10715 "external" imported declarations and "static" ones. As all imported
10716 declarations seem to be static in all other languages, make them all CU-wide
10717 global only in Ada. */
10719 static struct using_direct
**
10720 using_directives (struct dwarf2_cu
*cu
)
10722 if (cu
->language
== language_ada
10723 && cu
->get_builder ()->outermost_context_p ())
10724 return cu
->get_builder ()->get_global_using_directives ();
10726 return cu
->get_builder ()->get_local_using_directives ();
10729 /* Read the import statement specified by the given die and record it. */
10732 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10734 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10735 struct attribute
*import_attr
;
10736 struct die_info
*imported_die
, *child_die
;
10737 struct dwarf2_cu
*imported_cu
;
10738 const char *imported_name
;
10739 const char *imported_name_prefix
;
10740 const char *canonical_name
;
10741 const char *import_alias
;
10742 const char *imported_declaration
= NULL
;
10743 const char *import_prefix
;
10744 std::vector
<const char *> excludes
;
10746 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10747 if (import_attr
== NULL
)
10749 complaint (_("Tag '%s' has no DW_AT_import"),
10750 dwarf_tag_name (die
->tag
));
10755 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10756 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10757 if (imported_name
== NULL
)
10759 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10761 The import in the following code:
10775 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10776 <52> DW_AT_decl_file : 1
10777 <53> DW_AT_decl_line : 6
10778 <54> DW_AT_import : <0x75>
10779 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10780 <59> DW_AT_name : B
10781 <5b> DW_AT_decl_file : 1
10782 <5c> DW_AT_decl_line : 2
10783 <5d> DW_AT_type : <0x6e>
10785 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10786 <76> DW_AT_byte_size : 4
10787 <77> DW_AT_encoding : 5 (signed)
10789 imports the wrong die ( 0x75 instead of 0x58 ).
10790 This case will be ignored until the gcc bug is fixed. */
10794 /* Figure out the local name after import. */
10795 import_alias
= dwarf2_name (die
, cu
);
10797 /* Figure out where the statement is being imported to. */
10798 import_prefix
= determine_prefix (die
, cu
);
10800 /* Figure out what the scope of the imported die is and prepend it
10801 to the name of the imported die. */
10802 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10804 if (imported_die
->tag
!= DW_TAG_namespace
10805 && imported_die
->tag
!= DW_TAG_module
)
10807 imported_declaration
= imported_name
;
10808 canonical_name
= imported_name_prefix
;
10810 else if (strlen (imported_name_prefix
) > 0)
10811 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10812 imported_name_prefix
,
10813 (cu
->language
== language_d
? "." : "::"),
10814 imported_name
, (char *) NULL
);
10816 canonical_name
= imported_name
;
10818 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10819 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10820 child_die
= child_die
->sibling
)
10822 /* DWARF-4: A Fortran use statement with a “rename list” may be
10823 represented by an imported module entry with an import attribute
10824 referring to the module and owned entries corresponding to those
10825 entities that are renamed as part of being imported. */
10827 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10829 complaint (_("child DW_TAG_imported_declaration expected "
10830 "- DIE at %s [in module %s]"),
10831 sect_offset_str (child_die
->sect_off
),
10832 objfile_name (objfile
));
10836 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10837 if (import_attr
== NULL
)
10839 complaint (_("Tag '%s' has no DW_AT_import"),
10840 dwarf_tag_name (child_die
->tag
));
10845 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10847 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10848 if (imported_name
== NULL
)
10850 complaint (_("child DW_TAG_imported_declaration has unknown "
10851 "imported name - DIE at %s [in module %s]"),
10852 sect_offset_str (child_die
->sect_off
),
10853 objfile_name (objfile
));
10857 excludes
.push_back (imported_name
);
10859 process_die (child_die
, cu
);
10862 add_using_directive (using_directives (cu
),
10866 imported_declaration
,
10869 &objfile
->objfile_obstack
);
10872 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10873 types, but gives them a size of zero. Starting with version 14,
10874 ICC is compatible with GCC. */
10877 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10879 if (!cu
->checked_producer
)
10880 check_producer (cu
);
10882 return cu
->producer_is_icc_lt_14
;
10885 /* ICC generates a DW_AT_type for C void functions. This was observed on
10886 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10887 which says that void functions should not have a DW_AT_type. */
10890 producer_is_icc (struct dwarf2_cu
*cu
)
10892 if (!cu
->checked_producer
)
10893 check_producer (cu
);
10895 return cu
->producer_is_icc
;
10898 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10899 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10900 this, it was first present in GCC release 4.3.0. */
10903 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10905 if (!cu
->checked_producer
)
10906 check_producer (cu
);
10908 return cu
->producer_is_gcc_lt_4_3
;
10911 static file_and_directory
10912 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10914 file_and_directory res
;
10916 /* Find the filename. Do not use dwarf2_name here, since the filename
10917 is not a source language identifier. */
10918 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10919 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10921 if (res
.comp_dir
== NULL
10922 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10923 && IS_ABSOLUTE_PATH (res
.name
))
10925 res
.comp_dir_storage
= ldirname (res
.name
);
10926 if (!res
.comp_dir_storage
.empty ())
10927 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10929 if (res
.comp_dir
!= NULL
)
10931 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10932 directory, get rid of it. */
10933 const char *cp
= strchr (res
.comp_dir
, ':');
10935 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10936 res
.comp_dir
= cp
+ 1;
10939 if (res
.name
== NULL
)
10940 res
.name
= "<unknown>";
10945 /* Handle DW_AT_stmt_list for a compilation unit.
10946 DIE is the DW_TAG_compile_unit die for CU.
10947 COMP_DIR is the compilation directory. LOWPC is passed to
10948 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10951 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10952 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10954 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10955 struct attribute
*attr
;
10956 struct line_header line_header_local
;
10957 hashval_t line_header_local_hash
;
10959 int decode_mapping
;
10961 gdb_assert (! cu
->per_cu
->is_debug_types
);
10963 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10967 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10969 /* The line header hash table is only created if needed (it exists to
10970 prevent redundant reading of the line table for partial_units).
10971 If we're given a partial_unit, we'll need it. If we're given a
10972 compile_unit, then use the line header hash table if it's already
10973 created, but don't create one just yet. */
10975 if (per_objfile
->line_header_hash
== NULL
10976 && die
->tag
== DW_TAG_partial_unit
)
10978 per_objfile
->line_header_hash
10979 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10980 line_header_eq_voidp
,
10981 free_line_header_voidp
,
10985 line_header_local
.sect_off
= line_offset
;
10986 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10987 line_header_local_hash
= line_header_hash (&line_header_local
);
10988 if (per_objfile
->line_header_hash
!= NULL
)
10990 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10991 &line_header_local
,
10992 line_header_local_hash
, NO_INSERT
);
10994 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10995 is not present in *SLOT (since if there is something in *SLOT then
10996 it will be for a partial_unit). */
10997 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10999 gdb_assert (*slot
!= NULL
);
11000 cu
->line_header
= (struct line_header
*) *slot
;
11005 /* dwarf_decode_line_header does not yet provide sufficient information.
11006 We always have to call also dwarf_decode_lines for it. */
11007 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11011 cu
->line_header
= lh
.release ();
11012 cu
->line_header_die_owner
= die
;
11014 if (per_objfile
->line_header_hash
== NULL
)
11018 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11019 &line_header_local
,
11020 line_header_local_hash
, INSERT
);
11021 gdb_assert (slot
!= NULL
);
11023 if (slot
!= NULL
&& *slot
== NULL
)
11025 /* This newly decoded line number information unit will be owned
11026 by line_header_hash hash table. */
11027 *slot
= cu
->line_header
;
11028 cu
->line_header_die_owner
= NULL
;
11032 /* We cannot free any current entry in (*slot) as that struct line_header
11033 may be already used by multiple CUs. Create only temporary decoded
11034 line_header for this CU - it may happen at most once for each line
11035 number information unit. And if we're not using line_header_hash
11036 then this is what we want as well. */
11037 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11039 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11040 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11045 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11048 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11050 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11051 struct objfile
*objfile
= per_objfile
->objfile
;
11052 struct gdbarch
*gdbarch
= objfile
->arch ();
11053 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11054 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11055 struct attribute
*attr
;
11056 struct die_info
*child_die
;
11057 CORE_ADDR baseaddr
;
11059 prepare_one_comp_unit (cu
, die
, cu
->language
);
11060 baseaddr
= objfile
->text_section_offset ();
11062 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11064 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11065 from finish_block. */
11066 if (lowpc
== ((CORE_ADDR
) -1))
11068 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11070 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11072 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11073 standardised yet. As a workaround for the language detection we fall
11074 back to the DW_AT_producer string. */
11075 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11076 cu
->language
= language_opencl
;
11078 /* Similar hack for Go. */
11079 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11080 set_cu_language (DW_LANG_Go
, cu
);
11082 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11084 /* Decode line number information if present. We do this before
11085 processing child DIEs, so that the line header table is available
11086 for DW_AT_decl_file. */
11087 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11089 /* Process all dies in compilation unit. */
11090 if (die
->child
!= NULL
)
11092 child_die
= die
->child
;
11093 while (child_die
&& child_die
->tag
)
11095 process_die (child_die
, cu
);
11096 child_die
= child_die
->sibling
;
11100 /* Decode macro information, if present. Dwarf 2 macro information
11101 refers to information in the line number info statement program
11102 header, so we can only read it if we've read the header
11104 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11106 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11107 if (attr
&& cu
->line_header
)
11109 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11110 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11112 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11116 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11117 if (attr
&& cu
->line_header
)
11119 unsigned int macro_offset
= DW_UNSND (attr
);
11121 dwarf_decode_macros (cu
, macro_offset
, 0);
11127 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11129 struct type_unit_group
*tu_group
;
11131 struct attribute
*attr
;
11133 struct signatured_type
*sig_type
;
11135 gdb_assert (per_cu
->is_debug_types
);
11136 sig_type
= (struct signatured_type
*) per_cu
;
11138 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11140 /* If we're using .gdb_index (includes -readnow) then
11141 per_cu->type_unit_group may not have been set up yet. */
11142 if (sig_type
->type_unit_group
== NULL
)
11143 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11144 tu_group
= sig_type
->type_unit_group
;
11146 /* If we've already processed this stmt_list there's no real need to
11147 do it again, we could fake it and just recreate the part we need
11148 (file name,index -> symtab mapping). If data shows this optimization
11149 is useful we can do it then. */
11150 type_unit_group_unshareable
*tug_unshare
11151 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11152 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11154 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11159 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11160 lh
= dwarf_decode_line_header (line_offset
, this);
11165 start_symtab ("", NULL
, 0);
11168 gdb_assert (tug_unshare
->symtabs
== NULL
);
11169 gdb_assert (m_builder
== nullptr);
11170 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11171 m_builder
.reset (new struct buildsym_compunit
11172 (COMPUNIT_OBJFILE (cust
), "",
11173 COMPUNIT_DIRNAME (cust
),
11174 compunit_language (cust
),
11176 list_in_scope
= get_builder ()->get_file_symbols ();
11181 line_header
= lh
.release ();
11182 line_header_die_owner
= die
;
11186 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11188 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11189 still initializing it, and our caller (a few levels up)
11190 process_full_type_unit still needs to know if this is the first
11193 tug_unshare
->symtabs
11194 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11195 struct symtab
*, line_header
->file_names_size ());
11197 auto &file_names
= line_header
->file_names ();
11198 for (i
= 0; i
< file_names
.size (); ++i
)
11200 file_entry
&fe
= file_names
[i
];
11201 dwarf2_start_subfile (this, fe
.name
,
11202 fe
.include_dir (line_header
));
11203 buildsym_compunit
*b
= get_builder ();
11204 if (b
->get_current_subfile ()->symtab
== NULL
)
11206 /* NOTE: start_subfile will recognize when it's been
11207 passed a file it has already seen. So we can't
11208 assume there's a simple mapping from
11209 cu->line_header->file_names to subfiles, plus
11210 cu->line_header->file_names may contain dups. */
11211 b
->get_current_subfile ()->symtab
11212 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11215 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11216 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11221 gdb_assert (m_builder
== nullptr);
11222 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11223 m_builder
.reset (new struct buildsym_compunit
11224 (COMPUNIT_OBJFILE (cust
), "",
11225 COMPUNIT_DIRNAME (cust
),
11226 compunit_language (cust
),
11228 list_in_scope
= get_builder ()->get_file_symbols ();
11230 auto &file_names
= line_header
->file_names ();
11231 for (i
= 0; i
< file_names
.size (); ++i
)
11233 file_entry
&fe
= file_names
[i
];
11234 fe
.symtab
= tug_unshare
->symtabs
[i
];
11238 /* The main symtab is allocated last. Type units don't have DW_AT_name
11239 so they don't have a "real" (so to speak) symtab anyway.
11240 There is later code that will assign the main symtab to all symbols
11241 that don't have one. We need to handle the case of a symbol with a
11242 missing symtab (DW_AT_decl_file) anyway. */
11245 /* Process DW_TAG_type_unit.
11246 For TUs we want to skip the first top level sibling if it's not the
11247 actual type being defined by this TU. In this case the first top
11248 level sibling is there to provide context only. */
11251 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11253 struct die_info
*child_die
;
11255 prepare_one_comp_unit (cu
, die
, language_minimal
);
11257 /* Initialize (or reinitialize) the machinery for building symtabs.
11258 We do this before processing child DIEs, so that the line header table
11259 is available for DW_AT_decl_file. */
11260 cu
->setup_type_unit_groups (die
);
11262 if (die
->child
!= NULL
)
11264 child_die
= die
->child
;
11265 while (child_die
&& child_die
->tag
)
11267 process_die (child_die
, cu
);
11268 child_die
= child_die
->sibling
;
11275 http://gcc.gnu.org/wiki/DebugFission
11276 http://gcc.gnu.org/wiki/DebugFissionDWP
11278 To simplify handling of both DWO files ("object" files with the DWARF info)
11279 and DWP files (a file with the DWOs packaged up into one file), we treat
11280 DWP files as having a collection of virtual DWO files. */
11283 hash_dwo_file (const void *item
)
11285 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11288 hash
= htab_hash_string (dwo_file
->dwo_name
);
11289 if (dwo_file
->comp_dir
!= NULL
)
11290 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11295 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11297 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11298 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11300 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11302 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11303 return lhs
->comp_dir
== rhs
->comp_dir
;
11304 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11307 /* Allocate a hash table for DWO files. */
11310 allocate_dwo_file_hash_table ()
11312 auto delete_dwo_file
= [] (void *item
)
11314 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11319 return htab_up (htab_create_alloc (41,
11326 /* Lookup DWO file DWO_NAME. */
11329 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11330 const char *dwo_name
,
11331 const char *comp_dir
)
11333 struct dwo_file find_entry
;
11336 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11337 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11339 find_entry
.dwo_name
= dwo_name
;
11340 find_entry
.comp_dir
= comp_dir
;
11341 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11348 hash_dwo_unit (const void *item
)
11350 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11352 /* This drops the top 32 bits of the id, but is ok for a hash. */
11353 return dwo_unit
->signature
;
11357 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11359 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11360 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11362 /* The signature is assumed to be unique within the DWO file.
11363 So while object file CU dwo_id's always have the value zero,
11364 that's OK, assuming each object file DWO file has only one CU,
11365 and that's the rule for now. */
11366 return lhs
->signature
== rhs
->signature
;
11369 /* Allocate a hash table for DWO CUs,TUs.
11370 There is one of these tables for each of CUs,TUs for each DWO file. */
11373 allocate_dwo_unit_table ()
11375 /* Start out with a pretty small number.
11376 Generally DWO files contain only one CU and maybe some TUs. */
11377 return htab_up (htab_create_alloc (3,
11380 NULL
, xcalloc
, xfree
));
11383 /* die_reader_func for create_dwo_cu. */
11386 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11387 const gdb_byte
*info_ptr
,
11388 struct die_info
*comp_unit_die
,
11389 struct dwo_file
*dwo_file
,
11390 struct dwo_unit
*dwo_unit
)
11392 struct dwarf2_cu
*cu
= reader
->cu
;
11393 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11394 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11396 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11397 if (!signature
.has_value ())
11399 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11400 " its dwo_id [in module %s]"),
11401 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11405 dwo_unit
->dwo_file
= dwo_file
;
11406 dwo_unit
->signature
= *signature
;
11407 dwo_unit
->section
= section
;
11408 dwo_unit
->sect_off
= sect_off
;
11409 dwo_unit
->length
= cu
->per_cu
->length
;
11411 if (dwarf_read_debug
)
11412 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11413 sect_offset_str (sect_off
),
11414 hex_string (dwo_unit
->signature
));
11417 /* Create the dwo_units for the CUs in a DWO_FILE.
11418 Note: This function processes DWO files only, not DWP files. */
11421 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11422 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11423 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11425 struct objfile
*objfile
= per_objfile
->objfile
;
11426 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11427 const gdb_byte
*info_ptr
, *end_ptr
;
11429 section
.read (objfile
);
11430 info_ptr
= section
.buffer
;
11432 if (info_ptr
== NULL
)
11435 if (dwarf_read_debug
)
11437 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11438 section
.get_name (),
11439 section
.get_file_name ());
11442 end_ptr
= info_ptr
+ section
.size
;
11443 while (info_ptr
< end_ptr
)
11445 struct dwarf2_per_cu_data per_cu
;
11446 struct dwo_unit read_unit
{};
11447 struct dwo_unit
*dwo_unit
;
11449 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11451 memset (&per_cu
, 0, sizeof (per_cu
));
11452 per_cu
.per_bfd
= per_bfd
;
11453 per_cu
.is_debug_types
= 0;
11454 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11455 per_cu
.section
= §ion
;
11457 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11458 if (!reader
.dummy_p
)
11459 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11460 &dwo_file
, &read_unit
);
11461 info_ptr
+= per_cu
.length
;
11463 // If the unit could not be parsed, skip it.
11464 if (read_unit
.dwo_file
== NULL
)
11467 if (cus_htab
== NULL
)
11468 cus_htab
= allocate_dwo_unit_table ();
11470 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11472 *dwo_unit
= read_unit
;
11473 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11474 gdb_assert (slot
!= NULL
);
11477 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11478 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11480 complaint (_("debug cu entry at offset %s is duplicate to"
11481 " the entry at offset %s, signature %s"),
11482 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11483 hex_string (dwo_unit
->signature
));
11485 *slot
= (void *)dwo_unit
;
11489 /* DWP file .debug_{cu,tu}_index section format:
11490 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11494 Both index sections have the same format, and serve to map a 64-bit
11495 signature to a set of section numbers. Each section begins with a header,
11496 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11497 indexes, and a pool of 32-bit section numbers. The index sections will be
11498 aligned at 8-byte boundaries in the file.
11500 The index section header consists of:
11502 V, 32 bit version number
11504 N, 32 bit number of compilation units or type units in the index
11505 M, 32 bit number of slots in the hash table
11507 Numbers are recorded using the byte order of the application binary.
11509 The hash table begins at offset 16 in the section, and consists of an array
11510 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11511 order of the application binary). Unused slots in the hash table are 0.
11512 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11514 The parallel table begins immediately after the hash table
11515 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11516 array of 32-bit indexes (using the byte order of the application binary),
11517 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11518 table contains a 32-bit index into the pool of section numbers. For unused
11519 hash table slots, the corresponding entry in the parallel table will be 0.
11521 The pool of section numbers begins immediately following the hash table
11522 (at offset 16 + 12 * M from the beginning of the section). The pool of
11523 section numbers consists of an array of 32-bit words (using the byte order
11524 of the application binary). Each item in the array is indexed starting
11525 from 0. The hash table entry provides the index of the first section
11526 number in the set. Additional section numbers in the set follow, and the
11527 set is terminated by a 0 entry (section number 0 is not used in ELF).
11529 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11530 section must be the first entry in the set, and the .debug_abbrev.dwo must
11531 be the second entry. Other members of the set may follow in any order.
11537 DWP Version 2 combines all the .debug_info, etc. sections into one,
11538 and the entries in the index tables are now offsets into these sections.
11539 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11542 Index Section Contents:
11544 Hash Table of Signatures dwp_hash_table.hash_table
11545 Parallel Table of Indices dwp_hash_table.unit_table
11546 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11547 Table of Section Sizes dwp_hash_table.v2.sizes
11549 The index section header consists of:
11551 V, 32 bit version number
11552 L, 32 bit number of columns in the table of section offsets
11553 N, 32 bit number of compilation units or type units in the index
11554 M, 32 bit number of slots in the hash table
11556 Numbers are recorded using the byte order of the application binary.
11558 The hash table has the same format as version 1.
11559 The parallel table of indices has the same format as version 1,
11560 except that the entries are origin-1 indices into the table of sections
11561 offsets and the table of section sizes.
11563 The table of offsets begins immediately following the parallel table
11564 (at offset 16 + 12 * M from the beginning of the section). The table is
11565 a two-dimensional array of 32-bit words (using the byte order of the
11566 application binary), with L columns and N+1 rows, in row-major order.
11567 Each row in the array is indexed starting from 0. The first row provides
11568 a key to the remaining rows: each column in this row provides an identifier
11569 for a debug section, and the offsets in the same column of subsequent rows
11570 refer to that section. The section identifiers are:
11572 DW_SECT_INFO 1 .debug_info.dwo
11573 DW_SECT_TYPES 2 .debug_types.dwo
11574 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11575 DW_SECT_LINE 4 .debug_line.dwo
11576 DW_SECT_LOC 5 .debug_loc.dwo
11577 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11578 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11579 DW_SECT_MACRO 8 .debug_macro.dwo
11581 The offsets provided by the CU and TU index sections are the base offsets
11582 for the contributions made by each CU or TU to the corresponding section
11583 in the package file. Each CU and TU header contains an abbrev_offset
11584 field, used to find the abbreviations table for that CU or TU within the
11585 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11586 be interpreted as relative to the base offset given in the index section.
11587 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11588 should be interpreted as relative to the base offset for .debug_line.dwo,
11589 and offsets into other debug sections obtained from DWARF attributes should
11590 also be interpreted as relative to the corresponding base offset.
11592 The table of sizes begins immediately following the table of offsets.
11593 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11594 with L columns and N rows, in row-major order. Each row in the array is
11595 indexed starting from 1 (row 0 is shared by the two tables).
11599 Hash table lookup is handled the same in version 1 and 2:
11601 We assume that N and M will not exceed 2^32 - 1.
11602 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11604 Given a 64-bit compilation unit signature or a type signature S, an entry
11605 in the hash table is located as follows:
11607 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11608 the low-order k bits all set to 1.
11610 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11612 3) If the hash table entry at index H matches the signature, use that
11613 entry. If the hash table entry at index H is unused (all zeroes),
11614 terminate the search: the signature is not present in the table.
11616 4) Let H = (H + H') modulo M. Repeat at Step 3.
11618 Because M > N and H' and M are relatively prime, the search is guaranteed
11619 to stop at an unused slot or find the match. */
11621 /* Create a hash table to map DWO IDs to their CU/TU entry in
11622 .debug_{info,types}.dwo in DWP_FILE.
11623 Returns NULL if there isn't one.
11624 Note: This function processes DWP files only, not DWO files. */
11626 static struct dwp_hash_table
*
11627 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11628 struct dwp_file
*dwp_file
, int is_debug_types
)
11630 struct objfile
*objfile
= per_objfile
->objfile
;
11631 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11632 const gdb_byte
*index_ptr
, *index_end
;
11633 struct dwarf2_section_info
*index
;
11634 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11635 struct dwp_hash_table
*htab
;
11637 if (is_debug_types
)
11638 index
= &dwp_file
->sections
.tu_index
;
11640 index
= &dwp_file
->sections
.cu_index
;
11642 if (index
->empty ())
11644 index
->read (objfile
);
11646 index_ptr
= index
->buffer
;
11647 index_end
= index_ptr
+ index
->size
;
11649 version
= read_4_bytes (dbfd
, index_ptr
);
11652 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11656 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11658 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11661 if (version
!= 1 && version
!= 2)
11663 error (_("Dwarf Error: unsupported DWP file version (%s)"
11664 " [in module %s]"),
11665 pulongest (version
), dwp_file
->name
);
11667 if (nr_slots
!= (nr_slots
& -nr_slots
))
11669 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11670 " is not power of 2 [in module %s]"),
11671 pulongest (nr_slots
), dwp_file
->name
);
11674 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11675 htab
->version
= version
;
11676 htab
->nr_columns
= nr_columns
;
11677 htab
->nr_units
= nr_units
;
11678 htab
->nr_slots
= nr_slots
;
11679 htab
->hash_table
= index_ptr
;
11680 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11682 /* Exit early if the table is empty. */
11683 if (nr_slots
== 0 || nr_units
== 0
11684 || (version
== 2 && nr_columns
== 0))
11686 /* All must be zero. */
11687 if (nr_slots
!= 0 || nr_units
!= 0
11688 || (version
== 2 && nr_columns
!= 0))
11690 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11691 " all zero [in modules %s]"),
11699 htab
->section_pool
.v1
.indices
=
11700 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11701 /* It's harder to decide whether the section is too small in v1.
11702 V1 is deprecated anyway so we punt. */
11706 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11707 int *ids
= htab
->section_pool
.v2
.section_ids
;
11708 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11709 /* Reverse map for error checking. */
11710 int ids_seen
[DW_SECT_MAX
+ 1];
11713 if (nr_columns
< 2)
11715 error (_("Dwarf Error: bad DWP hash table, too few columns"
11716 " in section table [in module %s]"),
11719 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11721 error (_("Dwarf Error: bad DWP hash table, too many columns"
11722 " in section table [in module %s]"),
11725 memset (ids
, 255, sizeof_ids
);
11726 memset (ids_seen
, 255, sizeof (ids_seen
));
11727 for (i
= 0; i
< nr_columns
; ++i
)
11729 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11731 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11733 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11734 " in section table [in module %s]"),
11735 id
, dwp_file
->name
);
11737 if (ids_seen
[id
] != -1)
11739 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11740 " id %d in section table [in module %s]"),
11741 id
, dwp_file
->name
);
11746 /* Must have exactly one info or types section. */
11747 if (((ids_seen
[DW_SECT_INFO
] != -1)
11748 + (ids_seen
[DW_SECT_TYPES
] != -1))
11751 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11752 " DWO info/types section [in module %s]"),
11755 /* Must have an abbrev section. */
11756 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11758 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11759 " section [in module %s]"),
11762 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11763 htab
->section_pool
.v2
.sizes
=
11764 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11765 * nr_units
* nr_columns
);
11766 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11767 * nr_units
* nr_columns
))
11770 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11771 " [in module %s]"),
11779 /* Update SECTIONS with the data from SECTP.
11781 This function is like the other "locate" section routines that are
11782 passed to bfd_map_over_sections, but in this context the sections to
11783 read comes from the DWP V1 hash table, not the full ELF section table.
11785 The result is non-zero for success, or zero if an error was found. */
11788 locate_v1_virtual_dwo_sections (asection
*sectp
,
11789 struct virtual_v1_dwo_sections
*sections
)
11791 const struct dwop_section_names
*names
= &dwop_section_names
;
11793 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11795 /* There can be only one. */
11796 if (sections
->abbrev
.s
.section
!= NULL
)
11798 sections
->abbrev
.s
.section
= sectp
;
11799 sections
->abbrev
.size
= bfd_section_size (sectp
);
11801 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11802 || section_is_p (sectp
->name
, &names
->types_dwo
))
11804 /* There can be only one. */
11805 if (sections
->info_or_types
.s
.section
!= NULL
)
11807 sections
->info_or_types
.s
.section
= sectp
;
11808 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11810 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11812 /* There can be only one. */
11813 if (sections
->line
.s
.section
!= NULL
)
11815 sections
->line
.s
.section
= sectp
;
11816 sections
->line
.size
= bfd_section_size (sectp
);
11818 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11820 /* There can be only one. */
11821 if (sections
->loc
.s
.section
!= NULL
)
11823 sections
->loc
.s
.section
= sectp
;
11824 sections
->loc
.size
= bfd_section_size (sectp
);
11826 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11828 /* There can be only one. */
11829 if (sections
->macinfo
.s
.section
!= NULL
)
11831 sections
->macinfo
.s
.section
= sectp
;
11832 sections
->macinfo
.size
= bfd_section_size (sectp
);
11834 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11836 /* There can be only one. */
11837 if (sections
->macro
.s
.section
!= NULL
)
11839 sections
->macro
.s
.section
= sectp
;
11840 sections
->macro
.size
= bfd_section_size (sectp
);
11842 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11844 /* There can be only one. */
11845 if (sections
->str_offsets
.s
.section
!= NULL
)
11847 sections
->str_offsets
.s
.section
= sectp
;
11848 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11852 /* No other kind of section is valid. */
11859 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11860 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11861 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11862 This is for DWP version 1 files. */
11864 static struct dwo_unit
*
11865 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11866 struct dwp_file
*dwp_file
,
11867 uint32_t unit_index
,
11868 const char *comp_dir
,
11869 ULONGEST signature
, int is_debug_types
)
11871 const struct dwp_hash_table
*dwp_htab
=
11872 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11873 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11874 const char *kind
= is_debug_types
? "TU" : "CU";
11875 struct dwo_file
*dwo_file
;
11876 struct dwo_unit
*dwo_unit
;
11877 struct virtual_v1_dwo_sections sections
;
11878 void **dwo_file_slot
;
11881 gdb_assert (dwp_file
->version
== 1);
11883 if (dwarf_read_debug
)
11885 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11887 pulongest (unit_index
), hex_string (signature
),
11891 /* Fetch the sections of this DWO unit.
11892 Put a limit on the number of sections we look for so that bad data
11893 doesn't cause us to loop forever. */
11895 #define MAX_NR_V1_DWO_SECTIONS \
11896 (1 /* .debug_info or .debug_types */ \
11897 + 1 /* .debug_abbrev */ \
11898 + 1 /* .debug_line */ \
11899 + 1 /* .debug_loc */ \
11900 + 1 /* .debug_str_offsets */ \
11901 + 1 /* .debug_macro or .debug_macinfo */ \
11902 + 1 /* trailing zero */)
11904 memset (§ions
, 0, sizeof (sections
));
11906 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11909 uint32_t section_nr
=
11910 read_4_bytes (dbfd
,
11911 dwp_htab
->section_pool
.v1
.indices
11912 + (unit_index
+ i
) * sizeof (uint32_t));
11914 if (section_nr
== 0)
11916 if (section_nr
>= dwp_file
->num_sections
)
11918 error (_("Dwarf Error: bad DWP hash table, section number too large"
11919 " [in module %s]"),
11923 sectp
= dwp_file
->elf_sections
[section_nr
];
11924 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11926 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11927 " [in module %s]"),
11933 || sections
.info_or_types
.empty ()
11934 || sections
.abbrev
.empty ())
11936 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11937 " [in module %s]"),
11940 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11942 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11943 " [in module %s]"),
11947 /* It's easier for the rest of the code if we fake a struct dwo_file and
11948 have dwo_unit "live" in that. At least for now.
11950 The DWP file can be made up of a random collection of CUs and TUs.
11951 However, for each CU + set of TUs that came from the same original DWO
11952 file, we can combine them back into a virtual DWO file to save space
11953 (fewer struct dwo_file objects to allocate). Remember that for really
11954 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11956 std::string virtual_dwo_name
=
11957 string_printf ("virtual-dwo/%d-%d-%d-%d",
11958 sections
.abbrev
.get_id (),
11959 sections
.line
.get_id (),
11960 sections
.loc
.get_id (),
11961 sections
.str_offsets
.get_id ());
11962 /* Can we use an existing virtual DWO file? */
11963 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11965 /* Create one if necessary. */
11966 if (*dwo_file_slot
== NULL
)
11968 if (dwarf_read_debug
)
11970 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11971 virtual_dwo_name
.c_str ());
11973 dwo_file
= new struct dwo_file
;
11974 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11975 dwo_file
->comp_dir
= comp_dir
;
11976 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11977 dwo_file
->sections
.line
= sections
.line
;
11978 dwo_file
->sections
.loc
= sections
.loc
;
11979 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11980 dwo_file
->sections
.macro
= sections
.macro
;
11981 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11982 /* The "str" section is global to the entire DWP file. */
11983 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11984 /* The info or types section is assigned below to dwo_unit,
11985 there's no need to record it in dwo_file.
11986 Also, we can't simply record type sections in dwo_file because
11987 we record a pointer into the vector in dwo_unit. As we collect more
11988 types we'll grow the vector and eventually have to reallocate space
11989 for it, invalidating all copies of pointers into the previous
11991 *dwo_file_slot
= dwo_file
;
11995 if (dwarf_read_debug
)
11997 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11998 virtual_dwo_name
.c_str ());
12000 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12003 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12004 dwo_unit
->dwo_file
= dwo_file
;
12005 dwo_unit
->signature
= signature
;
12006 dwo_unit
->section
=
12007 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12008 *dwo_unit
->section
= sections
.info_or_types
;
12009 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12014 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12015 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12016 piece within that section used by a TU/CU, return a virtual section
12017 of just that piece. */
12019 static struct dwarf2_section_info
12020 create_dwp_v2_section (dwarf2_per_objfile
*per_objfile
,
12021 struct dwarf2_section_info
*section
,
12022 bfd_size_type offset
, bfd_size_type size
)
12024 struct dwarf2_section_info result
;
12027 gdb_assert (section
!= NULL
);
12028 gdb_assert (!section
->is_virtual
);
12030 memset (&result
, 0, sizeof (result
));
12031 result
.s
.containing_section
= section
;
12032 result
.is_virtual
= true;
12037 sectp
= section
->get_bfd_section ();
12039 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12040 bounds of the real section. This is a pretty-rare event, so just
12041 flag an error (easier) instead of a warning and trying to cope. */
12043 || offset
+ size
> bfd_section_size (sectp
))
12045 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12046 " in section %s [in module %s]"),
12047 sectp
? bfd_section_name (sectp
) : "<unknown>",
12048 objfile_name (per_objfile
->objfile
));
12051 result
.virtual_offset
= offset
;
12052 result
.size
= size
;
12056 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12057 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12058 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12059 This is for DWP version 2 files. */
12061 static struct dwo_unit
*
12062 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12063 struct dwp_file
*dwp_file
,
12064 uint32_t unit_index
,
12065 const char *comp_dir
,
12066 ULONGEST signature
, int is_debug_types
)
12068 const struct dwp_hash_table
*dwp_htab
=
12069 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12070 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12071 const char *kind
= is_debug_types
? "TU" : "CU";
12072 struct dwo_file
*dwo_file
;
12073 struct dwo_unit
*dwo_unit
;
12074 struct virtual_v2_dwo_sections sections
;
12075 void **dwo_file_slot
;
12078 gdb_assert (dwp_file
->version
== 2);
12080 if (dwarf_read_debug
)
12082 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12084 pulongest (unit_index
), hex_string (signature
),
12088 /* Fetch the section offsets of this DWO unit. */
12090 memset (§ions
, 0, sizeof (sections
));
12092 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12094 uint32_t offset
= read_4_bytes (dbfd
,
12095 dwp_htab
->section_pool
.v2
.offsets
12096 + (((unit_index
- 1) * dwp_htab
->nr_columns
12098 * sizeof (uint32_t)));
12099 uint32_t size
= read_4_bytes (dbfd
,
12100 dwp_htab
->section_pool
.v2
.sizes
12101 + (((unit_index
- 1) * dwp_htab
->nr_columns
12103 * sizeof (uint32_t)));
12105 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12108 case DW_SECT_TYPES
:
12109 sections
.info_or_types_offset
= offset
;
12110 sections
.info_or_types_size
= size
;
12112 case DW_SECT_ABBREV
:
12113 sections
.abbrev_offset
= offset
;
12114 sections
.abbrev_size
= size
;
12117 sections
.line_offset
= offset
;
12118 sections
.line_size
= size
;
12121 sections
.loc_offset
= offset
;
12122 sections
.loc_size
= size
;
12124 case DW_SECT_STR_OFFSETS
:
12125 sections
.str_offsets_offset
= offset
;
12126 sections
.str_offsets_size
= size
;
12128 case DW_SECT_MACINFO
:
12129 sections
.macinfo_offset
= offset
;
12130 sections
.macinfo_size
= size
;
12132 case DW_SECT_MACRO
:
12133 sections
.macro_offset
= offset
;
12134 sections
.macro_size
= size
;
12139 /* It's easier for the rest of the code if we fake a struct dwo_file and
12140 have dwo_unit "live" in that. At least for now.
12142 The DWP file can be made up of a random collection of CUs and TUs.
12143 However, for each CU + set of TUs that came from the same original DWO
12144 file, we can combine them back into a virtual DWO file to save space
12145 (fewer struct dwo_file objects to allocate). Remember that for really
12146 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12148 std::string virtual_dwo_name
=
12149 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12150 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12151 (long) (sections
.line_size
? sections
.line_offset
: 0),
12152 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12153 (long) (sections
.str_offsets_size
12154 ? sections
.str_offsets_offset
: 0));
12155 /* Can we use an existing virtual DWO file? */
12156 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12158 /* Create one if necessary. */
12159 if (*dwo_file_slot
== NULL
)
12161 if (dwarf_read_debug
)
12163 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12164 virtual_dwo_name
.c_str ());
12166 dwo_file
= new struct dwo_file
;
12167 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12168 dwo_file
->comp_dir
= comp_dir
;
12169 dwo_file
->sections
.abbrev
=
12170 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12171 sections
.abbrev_offset
, sections
.abbrev_size
);
12172 dwo_file
->sections
.line
=
12173 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.line
,
12174 sections
.line_offset
, sections
.line_size
);
12175 dwo_file
->sections
.loc
=
12176 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.loc
,
12177 sections
.loc_offset
, sections
.loc_size
);
12178 dwo_file
->sections
.macinfo
=
12179 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12180 sections
.macinfo_offset
, sections
.macinfo_size
);
12181 dwo_file
->sections
.macro
=
12182 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macro
,
12183 sections
.macro_offset
, sections
.macro_size
);
12184 dwo_file
->sections
.str_offsets
=
12185 create_dwp_v2_section (per_objfile
,
12186 &dwp_file
->sections
.str_offsets
,
12187 sections
.str_offsets_offset
,
12188 sections
.str_offsets_size
);
12189 /* The "str" section is global to the entire DWP file. */
12190 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12191 /* The info or types section is assigned below to dwo_unit,
12192 there's no need to record it in dwo_file.
12193 Also, we can't simply record type sections in dwo_file because
12194 we record a pointer into the vector in dwo_unit. As we collect more
12195 types we'll grow the vector and eventually have to reallocate space
12196 for it, invalidating all copies of pointers into the previous
12198 *dwo_file_slot
= dwo_file
;
12202 if (dwarf_read_debug
)
12204 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12205 virtual_dwo_name
.c_str ());
12207 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12210 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12211 dwo_unit
->dwo_file
= dwo_file
;
12212 dwo_unit
->signature
= signature
;
12213 dwo_unit
->section
=
12214 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12215 *dwo_unit
->section
= create_dwp_v2_section (per_objfile
,
12217 ? &dwp_file
->sections
.types
12218 : &dwp_file
->sections
.info
,
12219 sections
.info_or_types_offset
,
12220 sections
.info_or_types_size
);
12221 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12226 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12227 Returns NULL if the signature isn't found. */
12229 static struct dwo_unit
*
12230 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12231 struct dwp_file
*dwp_file
, const char *comp_dir
,
12232 ULONGEST signature
, int is_debug_types
)
12234 const struct dwp_hash_table
*dwp_htab
=
12235 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12236 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12237 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12238 uint32_t hash
= signature
& mask
;
12239 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12242 struct dwo_unit find_dwo_cu
;
12244 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12245 find_dwo_cu
.signature
= signature
;
12246 slot
= htab_find_slot (is_debug_types
12247 ? dwp_file
->loaded_tus
.get ()
12248 : dwp_file
->loaded_cus
.get (),
12249 &find_dwo_cu
, INSERT
);
12252 return (struct dwo_unit
*) *slot
;
12254 /* Use a for loop so that we don't loop forever on bad debug info. */
12255 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12257 ULONGEST signature_in_table
;
12259 signature_in_table
=
12260 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12261 if (signature_in_table
== signature
)
12263 uint32_t unit_index
=
12264 read_4_bytes (dbfd
,
12265 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12267 if (dwp_file
->version
== 1)
12269 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12270 unit_index
, comp_dir
,
12271 signature
, is_debug_types
);
12275 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12276 unit_index
, comp_dir
,
12277 signature
, is_debug_types
);
12279 return (struct dwo_unit
*) *slot
;
12281 if (signature_in_table
== 0)
12283 hash
= (hash
+ hash2
) & mask
;
12286 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12287 " [in module %s]"),
12291 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12292 Open the file specified by FILE_NAME and hand it off to BFD for
12293 preliminary analysis. Return a newly initialized bfd *, which
12294 includes a canonicalized copy of FILE_NAME.
12295 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12296 SEARCH_CWD is true if the current directory is to be searched.
12297 It will be searched before debug-file-directory.
12298 If successful, the file is added to the bfd include table of the
12299 objfile's bfd (see gdb_bfd_record_inclusion).
12300 If unable to find/open the file, return NULL.
12301 NOTE: This function is derived from symfile_bfd_open. */
12303 static gdb_bfd_ref_ptr
12304 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12305 const char *file_name
, int is_dwp
, int search_cwd
)
12308 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12309 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12310 to debug_file_directory. */
12311 const char *search_path
;
12312 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12314 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12317 if (*debug_file_directory
!= '\0')
12319 search_path_holder
.reset (concat (".", dirname_separator_string
,
12320 debug_file_directory
,
12322 search_path
= search_path_holder
.get ();
12328 search_path
= debug_file_directory
;
12330 openp_flags flags
= OPF_RETURN_REALPATH
;
12332 flags
|= OPF_SEARCH_IN_PATH
;
12334 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12335 desc
= openp (search_path
, flags
, file_name
,
12336 O_RDONLY
| O_BINARY
, &absolute_name
);
12340 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12342 if (sym_bfd
== NULL
)
12344 bfd_set_cacheable (sym_bfd
.get (), 1);
12346 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12349 /* Success. Record the bfd as having been included by the objfile's bfd.
12350 This is important because things like demangled_names_hash lives in the
12351 objfile's per_bfd space and may have references to things like symbol
12352 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12353 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12358 /* Try to open DWO file FILE_NAME.
12359 COMP_DIR is the DW_AT_comp_dir attribute.
12360 The result is the bfd handle of the file.
12361 If there is a problem finding or opening the file, return NULL.
12362 Upon success, the canonicalized path of the file is stored in the bfd,
12363 same as symfile_bfd_open. */
12365 static gdb_bfd_ref_ptr
12366 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12367 const char *file_name
, const char *comp_dir
)
12369 if (IS_ABSOLUTE_PATH (file_name
))
12370 return try_open_dwop_file (per_objfile
, file_name
,
12371 0 /*is_dwp*/, 0 /*search_cwd*/);
12373 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12375 if (comp_dir
!= NULL
)
12377 gdb::unique_xmalloc_ptr
<char> path_to_try
12378 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12380 /* NOTE: If comp_dir is a relative path, this will also try the
12381 search path, which seems useful. */
12382 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12384 1 /*search_cwd*/));
12389 /* That didn't work, try debug-file-directory, which, despite its name,
12390 is a list of paths. */
12392 if (*debug_file_directory
== '\0')
12395 return try_open_dwop_file (per_objfile
, file_name
,
12396 0 /*is_dwp*/, 1 /*search_cwd*/);
12399 /* This function is mapped across the sections and remembers the offset and
12400 size of each of the DWO debugging sections we are interested in. */
12403 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12405 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12406 const struct dwop_section_names
*names
= &dwop_section_names
;
12408 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12410 dwo_sections
->abbrev
.s
.section
= sectp
;
12411 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12413 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12415 dwo_sections
->info
.s
.section
= sectp
;
12416 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12418 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12420 dwo_sections
->line
.s
.section
= sectp
;
12421 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12423 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12425 dwo_sections
->loc
.s
.section
= sectp
;
12426 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12428 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12430 dwo_sections
->loclists
.s
.section
= sectp
;
12431 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12433 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12435 dwo_sections
->macinfo
.s
.section
= sectp
;
12436 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12438 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12440 dwo_sections
->macro
.s
.section
= sectp
;
12441 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12443 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12445 dwo_sections
->str
.s
.section
= sectp
;
12446 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12448 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12450 dwo_sections
->str_offsets
.s
.section
= sectp
;
12451 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12453 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12455 struct dwarf2_section_info type_section
;
12457 memset (&type_section
, 0, sizeof (type_section
));
12458 type_section
.s
.section
= sectp
;
12459 type_section
.size
= bfd_section_size (sectp
);
12460 dwo_sections
->types
.push_back (type_section
);
12464 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12465 by PER_CU. This is for the non-DWP case.
12466 The result is NULL if DWO_NAME can't be found. */
12468 static struct dwo_file
*
12469 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12470 const char *comp_dir
)
12472 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12474 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12477 if (dwarf_read_debug
)
12478 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12482 dwo_file_up
dwo_file (new struct dwo_file
);
12483 dwo_file
->dwo_name
= dwo_name
;
12484 dwo_file
->comp_dir
= comp_dir
;
12485 dwo_file
->dbfd
= std::move (dbfd
);
12487 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12488 &dwo_file
->sections
);
12490 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12493 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12494 dwo_file
->sections
.types
, dwo_file
->tus
);
12496 if (dwarf_read_debug
)
12497 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12499 return dwo_file
.release ();
12502 /* This function is mapped across the sections and remembers the offset and
12503 size of each of the DWP debugging sections common to version 1 and 2 that
12504 we are interested in. */
12507 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12508 void *dwp_file_ptr
)
12510 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12511 const struct dwop_section_names
*names
= &dwop_section_names
;
12512 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12514 /* Record the ELF section number for later lookup: this is what the
12515 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12516 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12517 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12519 /* Look for specific sections that we need. */
12520 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12522 dwp_file
->sections
.str
.s
.section
= sectp
;
12523 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12525 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12527 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12528 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12530 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12532 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12533 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12537 /* This function is mapped across the sections and remembers the offset and
12538 size of each of the DWP version 2 debugging sections that we are interested
12539 in. This is split into a separate function because we don't know if we
12540 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12543 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12545 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12546 const struct dwop_section_names
*names
= &dwop_section_names
;
12547 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12549 /* Record the ELF section number for later lookup: this is what the
12550 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12551 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12552 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12554 /* Look for specific sections that we need. */
12555 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12557 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12558 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12560 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12562 dwp_file
->sections
.info
.s
.section
= sectp
;
12563 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12565 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12567 dwp_file
->sections
.line
.s
.section
= sectp
;
12568 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12570 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12572 dwp_file
->sections
.loc
.s
.section
= sectp
;
12573 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12575 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12577 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12578 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12580 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12582 dwp_file
->sections
.macro
.s
.section
= sectp
;
12583 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12585 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12587 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12588 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12590 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12592 dwp_file
->sections
.types
.s
.section
= sectp
;
12593 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12597 /* Hash function for dwp_file loaded CUs/TUs. */
12600 hash_dwp_loaded_cutus (const void *item
)
12602 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12604 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12605 return dwo_unit
->signature
;
12608 /* Equality function for dwp_file loaded CUs/TUs. */
12611 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12613 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12614 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12616 return dua
->signature
== dub
->signature
;
12619 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12622 allocate_dwp_loaded_cutus_table ()
12624 return htab_up (htab_create_alloc (3,
12625 hash_dwp_loaded_cutus
,
12626 eq_dwp_loaded_cutus
,
12627 NULL
, xcalloc
, xfree
));
12630 /* Try to open DWP file FILE_NAME.
12631 The result is the bfd handle of the file.
12632 If there is a problem finding or opening the file, return NULL.
12633 Upon success, the canonicalized path of the file is stored in the bfd,
12634 same as symfile_bfd_open. */
12636 static gdb_bfd_ref_ptr
12637 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12639 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12641 1 /*search_cwd*/));
12645 /* Work around upstream bug 15652.
12646 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12647 [Whether that's a "bug" is debatable, but it is getting in our way.]
12648 We have no real idea where the dwp file is, because gdb's realpath-ing
12649 of the executable's path may have discarded the needed info.
12650 [IWBN if the dwp file name was recorded in the executable, akin to
12651 .gnu_debuglink, but that doesn't exist yet.]
12652 Strip the directory from FILE_NAME and search again. */
12653 if (*debug_file_directory
!= '\0')
12655 /* Don't implicitly search the current directory here.
12656 If the user wants to search "." to handle this case,
12657 it must be added to debug-file-directory. */
12658 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12666 /* Initialize the use of the DWP file for the current objfile.
12667 By convention the name of the DWP file is ${objfile}.dwp.
12668 The result is NULL if it can't be found. */
12670 static std::unique_ptr
<struct dwp_file
>
12671 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12673 struct objfile
*objfile
= per_objfile
->objfile
;
12675 /* Try to find first .dwp for the binary file before any symbolic links
12678 /* If the objfile is a debug file, find the name of the real binary
12679 file and get the name of dwp file from there. */
12680 std::string dwp_name
;
12681 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12683 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12684 const char *backlink_basename
= lbasename (backlink
->original_name
);
12686 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12689 dwp_name
= objfile
->original_name
;
12691 dwp_name
+= ".dwp";
12693 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12695 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12697 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12698 dwp_name
= objfile_name (objfile
);
12699 dwp_name
+= ".dwp";
12700 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12705 if (dwarf_read_debug
)
12706 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12707 return std::unique_ptr
<dwp_file
> ();
12710 const char *name
= bfd_get_filename (dbfd
.get ());
12711 std::unique_ptr
<struct dwp_file
> dwp_file
12712 (new struct dwp_file (name
, std::move (dbfd
)));
12714 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12715 dwp_file
->elf_sections
=
12716 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12717 dwp_file
->num_sections
, asection
*);
12719 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12720 dwarf2_locate_common_dwp_sections
,
12723 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12725 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12727 /* The DWP file version is stored in the hash table. Oh well. */
12728 if (dwp_file
->cus
&& dwp_file
->tus
12729 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12731 /* Technically speaking, we should try to limp along, but this is
12732 pretty bizarre. We use pulongest here because that's the established
12733 portability solution (e.g, we cannot use %u for uint32_t). */
12734 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12735 " TU version %s [in DWP file %s]"),
12736 pulongest (dwp_file
->cus
->version
),
12737 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12741 dwp_file
->version
= dwp_file
->cus
->version
;
12742 else if (dwp_file
->tus
)
12743 dwp_file
->version
= dwp_file
->tus
->version
;
12745 dwp_file
->version
= 2;
12747 if (dwp_file
->version
== 2)
12748 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12749 dwarf2_locate_v2_dwp_sections
,
12752 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12753 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12755 if (dwarf_read_debug
)
12757 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12758 fprintf_unfiltered (gdb_stdlog
,
12759 " %s CUs, %s TUs\n",
12760 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12761 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12767 /* Wrapper around open_and_init_dwp_file, only open it once. */
12769 static struct dwp_file
*
12770 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12772 if (!per_objfile
->per_bfd
->dwp_checked
)
12774 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12775 per_objfile
->per_bfd
->dwp_checked
= 1;
12777 return per_objfile
->per_bfd
->dwp_file
.get ();
12780 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12781 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12782 or in the DWP file for the objfile, referenced by THIS_UNIT.
12783 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12784 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12786 This is called, for example, when wanting to read a variable with a
12787 complex location. Therefore we don't want to do file i/o for every call.
12788 Therefore we don't want to look for a DWO file on every call.
12789 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12790 then we check if we've already seen DWO_NAME, and only THEN do we check
12793 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12794 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12796 static struct dwo_unit
*
12797 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12798 ULONGEST signature
, int is_debug_types
)
12800 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12801 struct objfile
*objfile
= per_objfile
->objfile
;
12802 const char *kind
= is_debug_types
? "TU" : "CU";
12803 void **dwo_file_slot
;
12804 struct dwo_file
*dwo_file
;
12805 struct dwp_file
*dwp_file
;
12807 /* First see if there's a DWP file.
12808 If we have a DWP file but didn't find the DWO inside it, don't
12809 look for the original DWO file. It makes gdb behave differently
12810 depending on whether one is debugging in the build tree. */
12812 dwp_file
= get_dwp_file (per_objfile
);
12813 if (dwp_file
!= NULL
)
12815 const struct dwp_hash_table
*dwp_htab
=
12816 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12818 if (dwp_htab
!= NULL
)
12820 struct dwo_unit
*dwo_cutu
=
12821 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12824 if (dwo_cutu
!= NULL
)
12826 if (dwarf_read_debug
)
12828 fprintf_unfiltered (gdb_stdlog
,
12829 "Virtual DWO %s %s found: @%s\n",
12830 kind
, hex_string (signature
),
12831 host_address_to_string (dwo_cutu
));
12839 /* No DWP file, look for the DWO file. */
12841 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12842 if (*dwo_file_slot
== NULL
)
12844 /* Read in the file and build a table of the CUs/TUs it contains. */
12845 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12847 /* NOTE: This will be NULL if unable to open the file. */
12848 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12850 if (dwo_file
!= NULL
)
12852 struct dwo_unit
*dwo_cutu
= NULL
;
12854 if (is_debug_types
&& dwo_file
->tus
)
12856 struct dwo_unit find_dwo_cutu
;
12858 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12859 find_dwo_cutu
.signature
= signature
;
12861 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12864 else if (!is_debug_types
&& dwo_file
->cus
)
12866 struct dwo_unit find_dwo_cutu
;
12868 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12869 find_dwo_cutu
.signature
= signature
;
12870 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12874 if (dwo_cutu
!= NULL
)
12876 if (dwarf_read_debug
)
12878 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12879 kind
, dwo_name
, hex_string (signature
),
12880 host_address_to_string (dwo_cutu
));
12887 /* We didn't find it. This could mean a dwo_id mismatch, or
12888 someone deleted the DWO/DWP file, or the search path isn't set up
12889 correctly to find the file. */
12891 if (dwarf_read_debug
)
12893 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12894 kind
, dwo_name
, hex_string (signature
));
12897 /* This is a warning and not a complaint because it can be caused by
12898 pilot error (e.g., user accidentally deleting the DWO). */
12900 /* Print the name of the DWP file if we looked there, helps the user
12901 better diagnose the problem. */
12902 std::string dwp_text
;
12904 if (dwp_file
!= NULL
)
12905 dwp_text
= string_printf (" [in DWP file %s]",
12906 lbasename (dwp_file
->name
));
12908 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12909 " [in module %s]"),
12910 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12911 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12916 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12917 See lookup_dwo_cutu_unit for details. */
12919 static struct dwo_unit
*
12920 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12921 ULONGEST signature
)
12923 gdb_assert (!cu
->per_cu
->is_debug_types
);
12925 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12928 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12929 See lookup_dwo_cutu_unit for details. */
12931 static struct dwo_unit
*
12932 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12934 gdb_assert (cu
->per_cu
->is_debug_types
);
12936 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12938 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12941 /* Traversal function for queue_and_load_all_dwo_tus. */
12944 queue_and_load_dwo_tu (void **slot
, void *info
)
12946 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12947 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12948 ULONGEST signature
= dwo_unit
->signature
;
12949 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12951 if (sig_type
!= NULL
)
12953 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12955 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12956 a real dependency of PER_CU on SIG_TYPE. That is detected later
12957 while processing PER_CU. */
12958 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
12959 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12960 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12966 /* Queue all TUs contained in the DWO of CU to be read in.
12967 The DWO may have the only definition of the type, though it may not be
12968 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12969 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12972 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12974 struct dwo_unit
*dwo_unit
;
12975 struct dwo_file
*dwo_file
;
12977 gdb_assert (cu
!= nullptr);
12978 gdb_assert (!cu
->per_cu
->is_debug_types
);
12979 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12981 dwo_unit
= cu
->dwo_unit
;
12982 gdb_assert (dwo_unit
!= NULL
);
12984 dwo_file
= dwo_unit
->dwo_file
;
12985 if (dwo_file
->tus
!= NULL
)
12986 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12989 /* Read in various DIEs. */
12991 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12992 Inherit only the children of the DW_AT_abstract_origin DIE not being
12993 already referenced by DW_AT_abstract_origin from the children of the
12997 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12999 struct die_info
*child_die
;
13000 sect_offset
*offsetp
;
13001 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13002 struct die_info
*origin_die
;
13003 /* Iterator of the ORIGIN_DIE children. */
13004 struct die_info
*origin_child_die
;
13005 struct attribute
*attr
;
13006 struct dwarf2_cu
*origin_cu
;
13007 struct pending
**origin_previous_list_in_scope
;
13009 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13013 /* Note that following die references may follow to a die in a
13017 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13019 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13021 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13022 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13024 if (die
->tag
!= origin_die
->tag
13025 && !(die
->tag
== DW_TAG_inlined_subroutine
13026 && origin_die
->tag
== DW_TAG_subprogram
))
13027 complaint (_("DIE %s and its abstract origin %s have different tags"),
13028 sect_offset_str (die
->sect_off
),
13029 sect_offset_str (origin_die
->sect_off
));
13031 std::vector
<sect_offset
> offsets
;
13033 for (child_die
= die
->child
;
13034 child_die
&& child_die
->tag
;
13035 child_die
= child_die
->sibling
)
13037 struct die_info
*child_origin_die
;
13038 struct dwarf2_cu
*child_origin_cu
;
13040 /* We are trying to process concrete instance entries:
13041 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13042 it's not relevant to our analysis here. i.e. detecting DIEs that are
13043 present in the abstract instance but not referenced in the concrete
13045 if (child_die
->tag
== DW_TAG_call_site
13046 || child_die
->tag
== DW_TAG_GNU_call_site
)
13049 /* For each CHILD_DIE, find the corresponding child of
13050 ORIGIN_DIE. If there is more than one layer of
13051 DW_AT_abstract_origin, follow them all; there shouldn't be,
13052 but GCC versions at least through 4.4 generate this (GCC PR
13054 child_origin_die
= child_die
;
13055 child_origin_cu
= cu
;
13058 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13062 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13066 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13067 counterpart may exist. */
13068 if (child_origin_die
!= child_die
)
13070 if (child_die
->tag
!= child_origin_die
->tag
13071 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13072 && child_origin_die
->tag
== DW_TAG_subprogram
))
13073 complaint (_("Child DIE %s and its abstract origin %s have "
13075 sect_offset_str (child_die
->sect_off
),
13076 sect_offset_str (child_origin_die
->sect_off
));
13077 if (child_origin_die
->parent
!= origin_die
)
13078 complaint (_("Child DIE %s and its abstract origin %s have "
13079 "different parents"),
13080 sect_offset_str (child_die
->sect_off
),
13081 sect_offset_str (child_origin_die
->sect_off
));
13083 offsets
.push_back (child_origin_die
->sect_off
);
13086 std::sort (offsets
.begin (), offsets
.end ());
13087 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13088 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13089 if (offsetp
[-1] == *offsetp
)
13090 complaint (_("Multiple children of DIE %s refer "
13091 "to DIE %s as their abstract origin"),
13092 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13094 offsetp
= offsets
.data ();
13095 origin_child_die
= origin_die
->child
;
13096 while (origin_child_die
&& origin_child_die
->tag
)
13098 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13099 while (offsetp
< offsets_end
13100 && *offsetp
< origin_child_die
->sect_off
)
13102 if (offsetp
>= offsets_end
13103 || *offsetp
> origin_child_die
->sect_off
)
13105 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13106 Check whether we're already processing ORIGIN_CHILD_DIE.
13107 This can happen with mutually referenced abstract_origins.
13109 if (!origin_child_die
->in_process
)
13110 process_die (origin_child_die
, origin_cu
);
13112 origin_child_die
= origin_child_die
->sibling
;
13114 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13116 if (cu
!= origin_cu
)
13117 compute_delayed_physnames (origin_cu
);
13121 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13123 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13124 struct gdbarch
*gdbarch
= objfile
->arch ();
13125 struct context_stack
*newobj
;
13128 struct die_info
*child_die
;
13129 struct attribute
*attr
, *call_line
, *call_file
;
13131 CORE_ADDR baseaddr
;
13132 struct block
*block
;
13133 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13134 std::vector
<struct symbol
*> template_args
;
13135 struct template_symbol
*templ_func
= NULL
;
13139 /* If we do not have call site information, we can't show the
13140 caller of this inlined function. That's too confusing, so
13141 only use the scope for local variables. */
13142 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13143 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13144 if (call_line
== NULL
|| call_file
== NULL
)
13146 read_lexical_block_scope (die
, cu
);
13151 baseaddr
= objfile
->text_section_offset ();
13153 name
= dwarf2_name (die
, cu
);
13155 /* Ignore functions with missing or empty names. These are actually
13156 illegal according to the DWARF standard. */
13159 complaint (_("missing name for subprogram DIE at %s"),
13160 sect_offset_str (die
->sect_off
));
13164 /* Ignore functions with missing or invalid low and high pc attributes. */
13165 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13166 <= PC_BOUNDS_INVALID
)
13168 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13169 if (!attr
|| !DW_UNSND (attr
))
13170 complaint (_("cannot get low and high bounds "
13171 "for subprogram DIE at %s"),
13172 sect_offset_str (die
->sect_off
));
13176 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13177 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13179 /* If we have any template arguments, then we must allocate a
13180 different sort of symbol. */
13181 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13183 if (child_die
->tag
== DW_TAG_template_type_param
13184 || child_die
->tag
== DW_TAG_template_value_param
)
13186 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13187 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13192 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13193 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13194 (struct symbol
*) templ_func
);
13196 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13197 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13200 /* If there is a location expression for DW_AT_frame_base, record
13202 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13203 if (attr
!= nullptr)
13204 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13206 /* If there is a location for the static link, record it. */
13207 newobj
->static_link
= NULL
;
13208 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13209 if (attr
!= nullptr)
13211 newobj
->static_link
13212 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13213 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13217 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13219 if (die
->child
!= NULL
)
13221 child_die
= die
->child
;
13222 while (child_die
&& child_die
->tag
)
13224 if (child_die
->tag
== DW_TAG_template_type_param
13225 || child_die
->tag
== DW_TAG_template_value_param
)
13227 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13230 template_args
.push_back (arg
);
13233 process_die (child_die
, cu
);
13234 child_die
= child_die
->sibling
;
13238 inherit_abstract_dies (die
, cu
);
13240 /* If we have a DW_AT_specification, we might need to import using
13241 directives from the context of the specification DIE. See the
13242 comment in determine_prefix. */
13243 if (cu
->language
== language_cplus
13244 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13246 struct dwarf2_cu
*spec_cu
= cu
;
13247 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13251 child_die
= spec_die
->child
;
13252 while (child_die
&& child_die
->tag
)
13254 if (child_die
->tag
== DW_TAG_imported_module
)
13255 process_die (child_die
, spec_cu
);
13256 child_die
= child_die
->sibling
;
13259 /* In some cases, GCC generates specification DIEs that
13260 themselves contain DW_AT_specification attributes. */
13261 spec_die
= die_specification (spec_die
, &spec_cu
);
13265 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13266 /* Make a block for the local symbols within. */
13267 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13268 cstk
.static_link
, lowpc
, highpc
);
13270 /* For C++, set the block's scope. */
13271 if ((cu
->language
== language_cplus
13272 || cu
->language
== language_fortran
13273 || cu
->language
== language_d
13274 || cu
->language
== language_rust
)
13275 && cu
->processing_has_namespace_info
)
13276 block_set_scope (block
, determine_prefix (die
, cu
),
13277 &objfile
->objfile_obstack
);
13279 /* If we have address ranges, record them. */
13280 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13282 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13284 /* Attach template arguments to function. */
13285 if (!template_args
.empty ())
13287 gdb_assert (templ_func
!= NULL
);
13289 templ_func
->n_template_arguments
= template_args
.size ();
13290 templ_func
->template_arguments
13291 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13292 templ_func
->n_template_arguments
);
13293 memcpy (templ_func
->template_arguments
,
13294 template_args
.data (),
13295 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13297 /* Make sure that the symtab is set on the new symbols. Even
13298 though they don't appear in this symtab directly, other parts
13299 of gdb assume that symbols do, and this is reasonably
13301 for (symbol
*sym
: template_args
)
13302 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13305 /* In C++, we can have functions nested inside functions (e.g., when
13306 a function declares a class that has methods). This means that
13307 when we finish processing a function scope, we may need to go
13308 back to building a containing block's symbol lists. */
13309 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13310 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13312 /* If we've finished processing a top-level function, subsequent
13313 symbols go in the file symbol list. */
13314 if (cu
->get_builder ()->outermost_context_p ())
13315 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13318 /* Process all the DIES contained within a lexical block scope. Start
13319 a new scope, process the dies, and then close the scope. */
13322 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13324 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13325 struct gdbarch
*gdbarch
= objfile
->arch ();
13326 CORE_ADDR lowpc
, highpc
;
13327 struct die_info
*child_die
;
13328 CORE_ADDR baseaddr
;
13330 baseaddr
= objfile
->text_section_offset ();
13332 /* Ignore blocks with missing or invalid low and high pc attributes. */
13333 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13334 as multiple lexical blocks? Handling children in a sane way would
13335 be nasty. Might be easier to properly extend generic blocks to
13336 describe ranges. */
13337 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13339 case PC_BOUNDS_NOT_PRESENT
:
13340 /* DW_TAG_lexical_block has no attributes, process its children as if
13341 there was no wrapping by that DW_TAG_lexical_block.
13342 GCC does no longer produces such DWARF since GCC r224161. */
13343 for (child_die
= die
->child
;
13344 child_die
!= NULL
&& child_die
->tag
;
13345 child_die
= child_die
->sibling
)
13347 /* We might already be processing this DIE. This can happen
13348 in an unusual circumstance -- where a subroutine A
13349 appears lexically in another subroutine B, but A actually
13350 inlines B. The recursion is broken here, rather than in
13351 inherit_abstract_dies, because it seems better to simply
13352 drop concrete children here. */
13353 if (!child_die
->in_process
)
13354 process_die (child_die
, cu
);
13357 case PC_BOUNDS_INVALID
:
13360 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13361 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13363 cu
->get_builder ()->push_context (0, lowpc
);
13364 if (die
->child
!= NULL
)
13366 child_die
= die
->child
;
13367 while (child_die
&& child_die
->tag
)
13369 process_die (child_die
, cu
);
13370 child_die
= child_die
->sibling
;
13373 inherit_abstract_dies (die
, cu
);
13374 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13376 if (*cu
->get_builder ()->get_local_symbols () != NULL
13377 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13379 struct block
*block
13380 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13381 cstk
.start_addr
, highpc
);
13383 /* Note that recording ranges after traversing children, as we
13384 do here, means that recording a parent's ranges entails
13385 walking across all its children's ranges as they appear in
13386 the address map, which is quadratic behavior.
13388 It would be nicer to record the parent's ranges before
13389 traversing its children, simply overriding whatever you find
13390 there. But since we don't even decide whether to create a
13391 block until after we've traversed its children, that's hard
13393 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13395 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13396 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13399 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13402 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13404 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13405 struct objfile
*objfile
= per_objfile
->objfile
;
13406 struct gdbarch
*gdbarch
= objfile
->arch ();
13407 CORE_ADDR pc
, baseaddr
;
13408 struct attribute
*attr
;
13409 struct call_site
*call_site
, call_site_local
;
13412 struct die_info
*child_die
;
13414 baseaddr
= objfile
->text_section_offset ();
13416 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13419 /* This was a pre-DWARF-5 GNU extension alias
13420 for DW_AT_call_return_pc. */
13421 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13425 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13426 "DIE %s [in module %s]"),
13427 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13430 pc
= attr
->value_as_address () + baseaddr
;
13431 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13433 if (cu
->call_site_htab
== NULL
)
13434 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13435 NULL
, &objfile
->objfile_obstack
,
13436 hashtab_obstack_allocate
, NULL
);
13437 call_site_local
.pc
= pc
;
13438 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13441 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13442 "DIE %s [in module %s]"),
13443 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13444 objfile_name (objfile
));
13448 /* Count parameters at the caller. */
13451 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13452 child_die
= child_die
->sibling
)
13454 if (child_die
->tag
!= DW_TAG_call_site_parameter
13455 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13457 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13458 "DW_TAG_call_site child DIE %s [in module %s]"),
13459 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13460 objfile_name (objfile
));
13468 = ((struct call_site
*)
13469 obstack_alloc (&objfile
->objfile_obstack
,
13470 sizeof (*call_site
)
13471 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13473 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13474 call_site
->pc
= pc
;
13476 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13477 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13479 struct die_info
*func_die
;
13481 /* Skip also over DW_TAG_inlined_subroutine. */
13482 for (func_die
= die
->parent
;
13483 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13484 && func_die
->tag
!= DW_TAG_subroutine_type
;
13485 func_die
= func_die
->parent
);
13487 /* DW_AT_call_all_calls is a superset
13488 of DW_AT_call_all_tail_calls. */
13490 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13491 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13492 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13493 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13495 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13496 not complete. But keep CALL_SITE for look ups via call_site_htab,
13497 both the initial caller containing the real return address PC and
13498 the final callee containing the current PC of a chain of tail
13499 calls do not need to have the tail call list complete. But any
13500 function candidate for a virtual tail call frame searched via
13501 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13502 determined unambiguously. */
13506 struct type
*func_type
= NULL
;
13509 func_type
= get_die_type (func_die
, cu
);
13510 if (func_type
!= NULL
)
13512 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13514 /* Enlist this call site to the function. */
13515 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13516 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13519 complaint (_("Cannot find function owning DW_TAG_call_site "
13520 "DIE %s [in module %s]"),
13521 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13525 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13527 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13529 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13532 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13533 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13535 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13536 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13537 /* Keep NULL DWARF_BLOCK. */;
13538 else if (attr
->form_is_block ())
13540 struct dwarf2_locexpr_baton
*dlbaton
;
13542 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13543 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13544 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13545 dlbaton
->per_objfile
= per_objfile
;
13546 dlbaton
->per_cu
= cu
->per_cu
;
13548 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13550 else if (attr
->form_is_ref ())
13552 struct dwarf2_cu
*target_cu
= cu
;
13553 struct die_info
*target_die
;
13555 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13556 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13557 if (die_is_declaration (target_die
, target_cu
))
13559 const char *target_physname
;
13561 /* Prefer the mangled name; otherwise compute the demangled one. */
13562 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13563 if (target_physname
== NULL
)
13564 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13565 if (target_physname
== NULL
)
13566 complaint (_("DW_AT_call_target target DIE has invalid "
13567 "physname, for referencing DIE %s [in module %s]"),
13568 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13570 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13576 /* DW_AT_entry_pc should be preferred. */
13577 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13578 <= PC_BOUNDS_INVALID
)
13579 complaint (_("DW_AT_call_target target DIE has invalid "
13580 "low pc, for referencing DIE %s [in module %s]"),
13581 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13584 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13585 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13590 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13591 "block nor reference, for DIE %s [in module %s]"),
13592 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13594 call_site
->per_cu
= cu
->per_cu
;
13595 call_site
->per_objfile
= per_objfile
;
13597 for (child_die
= die
->child
;
13598 child_die
&& child_die
->tag
;
13599 child_die
= child_die
->sibling
)
13601 struct call_site_parameter
*parameter
;
13602 struct attribute
*loc
, *origin
;
13604 if (child_die
->tag
!= DW_TAG_call_site_parameter
13605 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13607 /* Already printed the complaint above. */
13611 gdb_assert (call_site
->parameter_count
< nparams
);
13612 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13614 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13615 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13616 register is contained in DW_AT_call_value. */
13618 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13619 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13620 if (origin
== NULL
)
13622 /* This was a pre-DWARF-5 GNU extension alias
13623 for DW_AT_call_parameter. */
13624 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13626 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13628 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13630 sect_offset sect_off
= origin
->get_ref_die_offset ();
13631 if (!cu
->header
.offset_in_cu_p (sect_off
))
13633 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13634 binding can be done only inside one CU. Such referenced DIE
13635 therefore cannot be even moved to DW_TAG_partial_unit. */
13636 complaint (_("DW_AT_call_parameter offset is not in CU for "
13637 "DW_TAG_call_site child DIE %s [in module %s]"),
13638 sect_offset_str (child_die
->sect_off
),
13639 objfile_name (objfile
));
13642 parameter
->u
.param_cu_off
13643 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13645 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13647 complaint (_("No DW_FORM_block* DW_AT_location for "
13648 "DW_TAG_call_site child DIE %s [in module %s]"),
13649 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13654 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13655 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13656 if (parameter
->u
.dwarf_reg
!= -1)
13657 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13658 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13659 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13660 ¶meter
->u
.fb_offset
))
13661 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13664 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13665 "for DW_FORM_block* DW_AT_location is supported for "
13666 "DW_TAG_call_site child DIE %s "
13668 sect_offset_str (child_die
->sect_off
),
13669 objfile_name (objfile
));
13674 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13676 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13677 if (attr
== NULL
|| !attr
->form_is_block ())
13679 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13680 "DW_TAG_call_site child DIE %s [in module %s]"),
13681 sect_offset_str (child_die
->sect_off
),
13682 objfile_name (objfile
));
13685 parameter
->value
= DW_BLOCK (attr
)->data
;
13686 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13688 /* Parameters are not pre-cleared by memset above. */
13689 parameter
->data_value
= NULL
;
13690 parameter
->data_value_size
= 0;
13691 call_site
->parameter_count
++;
13693 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13695 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13696 if (attr
!= nullptr)
13698 if (!attr
->form_is_block ())
13699 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13700 "DW_TAG_call_site child DIE %s [in module %s]"),
13701 sect_offset_str (child_die
->sect_off
),
13702 objfile_name (objfile
));
13705 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13706 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13712 /* Helper function for read_variable. If DIE represents a virtual
13713 table, then return the type of the concrete object that is
13714 associated with the virtual table. Otherwise, return NULL. */
13716 static struct type
*
13717 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13719 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13723 /* Find the type DIE. */
13724 struct die_info
*type_die
= NULL
;
13725 struct dwarf2_cu
*type_cu
= cu
;
13727 if (attr
->form_is_ref ())
13728 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13729 if (type_die
== NULL
)
13732 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13734 return die_containing_type (type_die
, type_cu
);
13737 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13740 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13742 struct rust_vtable_symbol
*storage
= NULL
;
13744 if (cu
->language
== language_rust
)
13746 struct type
*containing_type
= rust_containing_type (die
, cu
);
13748 if (containing_type
!= NULL
)
13750 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13752 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13753 storage
->concrete_type
= containing_type
;
13754 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13758 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13759 struct attribute
*abstract_origin
13760 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13761 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13762 if (res
== NULL
&& loc
&& abstract_origin
)
13764 /* We have a variable without a name, but with a location and an abstract
13765 origin. This may be a concrete instance of an abstract variable
13766 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13768 struct dwarf2_cu
*origin_cu
= cu
;
13769 struct die_info
*origin_die
13770 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13771 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13772 per_objfile
->per_bfd
->abstract_to_concrete
13773 [origin_die
->sect_off
].push_back (die
->sect_off
);
13777 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13778 reading .debug_rnglists.
13779 Callback's type should be:
13780 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13781 Return true if the attributes are present and valid, otherwise,
13784 template <typename Callback
>
13786 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13787 Callback
&&callback
)
13789 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13790 struct objfile
*objfile
= per_objfile
->objfile
;
13791 bfd
*obfd
= objfile
->obfd
;
13792 /* Base address selection entry. */
13793 gdb::optional
<CORE_ADDR
> base
;
13794 const gdb_byte
*buffer
;
13795 CORE_ADDR baseaddr
;
13796 bool overflow
= false;
13798 base
= cu
->base_address
;
13800 per_objfile
->per_bfd
->rnglists
.read (objfile
);
13801 if (offset
>= per_objfile
->per_bfd
->rnglists
.size
)
13803 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13807 buffer
= per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13809 baseaddr
= objfile
->text_section_offset ();
13813 /* Initialize it due to a false compiler warning. */
13814 CORE_ADDR range_beginning
= 0, range_end
= 0;
13815 const gdb_byte
*buf_end
= (per_objfile
->per_bfd
->rnglists
.buffer
13816 + per_objfile
->per_bfd
->rnglists
.size
);
13817 unsigned int bytes_read
;
13819 if (buffer
== buf_end
)
13824 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13827 case DW_RLE_end_of_list
:
13829 case DW_RLE_base_address
:
13830 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13835 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13836 buffer
+= bytes_read
;
13838 case DW_RLE_start_length
:
13839 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13844 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13846 buffer
+= bytes_read
;
13847 range_end
= (range_beginning
13848 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13849 buffer
+= bytes_read
;
13850 if (buffer
> buf_end
)
13856 case DW_RLE_offset_pair
:
13857 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13858 buffer
+= bytes_read
;
13859 if (buffer
> buf_end
)
13864 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13865 buffer
+= bytes_read
;
13866 if (buffer
> buf_end
)
13872 case DW_RLE_start_end
:
13873 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13878 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13880 buffer
+= bytes_read
;
13881 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13882 buffer
+= bytes_read
;
13885 complaint (_("Invalid .debug_rnglists data (no base address)"));
13888 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13890 if (rlet
== DW_RLE_base_address
)
13893 if (!base
.has_value ())
13895 /* We have no valid base address for the ranges
13897 complaint (_("Invalid .debug_rnglists data (no base address)"));
13901 if (range_beginning
> range_end
)
13903 /* Inverted range entries are invalid. */
13904 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13908 /* Empty range entries have no effect. */
13909 if (range_beginning
== range_end
)
13912 range_beginning
+= *base
;
13913 range_end
+= *base
;
13915 /* A not-uncommon case of bad debug info.
13916 Don't pollute the addrmap with bad data. */
13917 if (range_beginning
+ baseaddr
== 0
13918 && !per_objfile
->per_bfd
->has_section_at_zero
)
13920 complaint (_(".debug_rnglists entry has start address of zero"
13921 " [in module %s]"), objfile_name (objfile
));
13925 callback (range_beginning
, range_end
);
13930 complaint (_("Offset %d is not terminated "
13931 "for DW_AT_ranges attribute"),
13939 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13940 Callback's type should be:
13941 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13942 Return 1 if the attributes are present and valid, otherwise, return 0. */
13944 template <typename Callback
>
13946 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13947 Callback
&&callback
)
13949 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13950 struct objfile
*objfile
= per_objfile
->objfile
;
13951 struct comp_unit_head
*cu_header
= &cu
->header
;
13952 bfd
*obfd
= objfile
->obfd
;
13953 unsigned int addr_size
= cu_header
->addr_size
;
13954 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13955 /* Base address selection entry. */
13956 gdb::optional
<CORE_ADDR
> base
;
13957 unsigned int dummy
;
13958 const gdb_byte
*buffer
;
13959 CORE_ADDR baseaddr
;
13961 if (cu_header
->version
>= 5)
13962 return dwarf2_rnglists_process (offset
, cu
, callback
);
13964 base
= cu
->base_address
;
13966 per_objfile
->per_bfd
->ranges
.read (objfile
);
13967 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13969 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13973 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13975 baseaddr
= objfile
->text_section_offset ();
13979 CORE_ADDR range_beginning
, range_end
;
13981 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13982 buffer
+= addr_size
;
13983 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13984 buffer
+= addr_size
;
13985 offset
+= 2 * addr_size
;
13987 /* An end of list marker is a pair of zero addresses. */
13988 if (range_beginning
== 0 && range_end
== 0)
13989 /* Found the end of list entry. */
13992 /* Each base address selection entry is a pair of 2 values.
13993 The first is the largest possible address, the second is
13994 the base address. Check for a base address here. */
13995 if ((range_beginning
& mask
) == mask
)
13997 /* If we found the largest possible address, then we already
13998 have the base address in range_end. */
14003 if (!base
.has_value ())
14005 /* We have no valid base address for the ranges
14007 complaint (_("Invalid .debug_ranges data (no base address)"));
14011 if (range_beginning
> range_end
)
14013 /* Inverted range entries are invalid. */
14014 complaint (_("Invalid .debug_ranges data (inverted range)"));
14018 /* Empty range entries have no effect. */
14019 if (range_beginning
== range_end
)
14022 range_beginning
+= *base
;
14023 range_end
+= *base
;
14025 /* A not-uncommon case of bad debug info.
14026 Don't pollute the addrmap with bad data. */
14027 if (range_beginning
+ baseaddr
== 0
14028 && !per_objfile
->per_bfd
->has_section_at_zero
)
14030 complaint (_(".debug_ranges entry has start address of zero"
14031 " [in module %s]"), objfile_name (objfile
));
14035 callback (range_beginning
, range_end
);
14041 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14042 Return 1 if the attributes are present and valid, otherwise, return 0.
14043 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14046 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14047 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14048 dwarf2_psymtab
*ranges_pst
)
14050 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14051 struct gdbarch
*gdbarch
= objfile
->arch ();
14052 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14055 CORE_ADDR high
= 0;
14058 retval
= dwarf2_ranges_process (offset
, cu
,
14059 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14061 if (ranges_pst
!= NULL
)
14066 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14067 range_beginning
+ baseaddr
)
14069 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14070 range_end
+ baseaddr
)
14072 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14073 lowpc
, highpc
- 1, ranges_pst
);
14076 /* FIXME: This is recording everything as a low-high
14077 segment of consecutive addresses. We should have a
14078 data structure for discontiguous block ranges
14082 low
= range_beginning
;
14088 if (range_beginning
< low
)
14089 low
= range_beginning
;
14090 if (range_end
> high
)
14098 /* If the first entry is an end-of-list marker, the range
14099 describes an empty scope, i.e. no instructions. */
14105 *high_return
= high
;
14109 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14110 definition for the return value. *LOWPC and *HIGHPC are set iff
14111 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14113 static enum pc_bounds_kind
14114 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14115 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14116 dwarf2_psymtab
*pst
)
14118 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14119 struct attribute
*attr
;
14120 struct attribute
*attr_high
;
14122 CORE_ADDR high
= 0;
14123 enum pc_bounds_kind ret
;
14125 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14128 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14129 if (attr
!= nullptr)
14131 low
= attr
->value_as_address ();
14132 high
= attr_high
->value_as_address ();
14133 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14137 /* Found high w/o low attribute. */
14138 return PC_BOUNDS_INVALID
;
14140 /* Found consecutive range of addresses. */
14141 ret
= PC_BOUNDS_HIGH_LOW
;
14145 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14148 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14149 We take advantage of the fact that DW_AT_ranges does not appear
14150 in DW_TAG_compile_unit of DWO files. */
14151 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14152 unsigned int ranges_offset
= (DW_UNSND (attr
)
14153 + (need_ranges_base
14157 /* Value of the DW_AT_ranges attribute is the offset in the
14158 .debug_ranges section. */
14159 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14160 return PC_BOUNDS_INVALID
;
14161 /* Found discontinuous range of addresses. */
14162 ret
= PC_BOUNDS_RANGES
;
14165 return PC_BOUNDS_NOT_PRESENT
;
14168 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14170 return PC_BOUNDS_INVALID
;
14172 /* When using the GNU linker, .gnu.linkonce. sections are used to
14173 eliminate duplicate copies of functions and vtables and such.
14174 The linker will arbitrarily choose one and discard the others.
14175 The AT_*_pc values for such functions refer to local labels in
14176 these sections. If the section from that file was discarded, the
14177 labels are not in the output, so the relocs get a value of 0.
14178 If this is a discarded function, mark the pc bounds as invalid,
14179 so that GDB will ignore it. */
14180 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14181 return PC_BOUNDS_INVALID
;
14189 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14190 its low and high PC addresses. Do nothing if these addresses could not
14191 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14192 and HIGHPC to the high address if greater than HIGHPC. */
14195 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14196 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14197 struct dwarf2_cu
*cu
)
14199 CORE_ADDR low
, high
;
14200 struct die_info
*child
= die
->child
;
14202 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14204 *lowpc
= std::min (*lowpc
, low
);
14205 *highpc
= std::max (*highpc
, high
);
14208 /* If the language does not allow nested subprograms (either inside
14209 subprograms or lexical blocks), we're done. */
14210 if (cu
->language
!= language_ada
)
14213 /* Check all the children of the given DIE. If it contains nested
14214 subprograms, then check their pc bounds. Likewise, we need to
14215 check lexical blocks as well, as they may also contain subprogram
14217 while (child
&& child
->tag
)
14219 if (child
->tag
== DW_TAG_subprogram
14220 || child
->tag
== DW_TAG_lexical_block
)
14221 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14222 child
= child
->sibling
;
14226 /* Get the low and high pc's represented by the scope DIE, and store
14227 them in *LOWPC and *HIGHPC. If the correct values can't be
14228 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14231 get_scope_pc_bounds (struct die_info
*die
,
14232 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14233 struct dwarf2_cu
*cu
)
14235 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14236 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14237 CORE_ADDR current_low
, current_high
;
14239 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14240 >= PC_BOUNDS_RANGES
)
14242 best_low
= current_low
;
14243 best_high
= current_high
;
14247 struct die_info
*child
= die
->child
;
14249 while (child
&& child
->tag
)
14251 switch (child
->tag
) {
14252 case DW_TAG_subprogram
:
14253 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14255 case DW_TAG_namespace
:
14256 case DW_TAG_module
:
14257 /* FIXME: carlton/2004-01-16: Should we do this for
14258 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14259 that current GCC's always emit the DIEs corresponding
14260 to definitions of methods of classes as children of a
14261 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14262 the DIEs giving the declarations, which could be
14263 anywhere). But I don't see any reason why the
14264 standards says that they have to be there. */
14265 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14267 if (current_low
!= ((CORE_ADDR
) -1))
14269 best_low
= std::min (best_low
, current_low
);
14270 best_high
= std::max (best_high
, current_high
);
14278 child
= child
->sibling
;
14283 *highpc
= best_high
;
14286 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14290 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14291 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14293 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14294 struct gdbarch
*gdbarch
= objfile
->arch ();
14295 struct attribute
*attr
;
14296 struct attribute
*attr_high
;
14298 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14301 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14302 if (attr
!= nullptr)
14304 CORE_ADDR low
= attr
->value_as_address ();
14305 CORE_ADDR high
= attr_high
->value_as_address ();
14307 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14310 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14311 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14312 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14316 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14317 if (attr
!= nullptr)
14319 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14320 We take advantage of the fact that DW_AT_ranges does not appear
14321 in DW_TAG_compile_unit of DWO files. */
14322 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14324 /* The value of the DW_AT_ranges attribute is the offset of the
14325 address range list in the .debug_ranges section. */
14326 unsigned long offset
= (DW_UNSND (attr
)
14327 + (need_ranges_base
? cu
->ranges_base
: 0));
14329 std::vector
<blockrange
> blockvec
;
14330 dwarf2_ranges_process (offset
, cu
,
14331 [&] (CORE_ADDR start
, CORE_ADDR end
)
14335 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14336 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14337 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14338 blockvec
.emplace_back (start
, end
);
14341 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14345 /* Check whether the producer field indicates either of GCC < 4.6, or the
14346 Intel C/C++ compiler, and cache the result in CU. */
14349 check_producer (struct dwarf2_cu
*cu
)
14353 if (cu
->producer
== NULL
)
14355 /* For unknown compilers expect their behavior is DWARF version
14358 GCC started to support .debug_types sections by -gdwarf-4 since
14359 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14360 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14361 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14362 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14364 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14366 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14367 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14369 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14371 cu
->producer_is_icc
= true;
14372 cu
->producer_is_icc_lt_14
= major
< 14;
14374 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14375 cu
->producer_is_codewarrior
= true;
14378 /* For other non-GCC compilers, expect their behavior is DWARF version
14382 cu
->checked_producer
= true;
14385 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14386 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14387 during 4.6.0 experimental. */
14390 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14392 if (!cu
->checked_producer
)
14393 check_producer (cu
);
14395 return cu
->producer_is_gxx_lt_4_6
;
14399 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14400 with incorrect is_stmt attributes. */
14403 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14405 if (!cu
->checked_producer
)
14406 check_producer (cu
);
14408 return cu
->producer_is_codewarrior
;
14411 /* Return the default accessibility type if it is not overridden by
14412 DW_AT_accessibility. */
14414 static enum dwarf_access_attribute
14415 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14417 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14419 /* The default DWARF 2 accessibility for members is public, the default
14420 accessibility for inheritance is private. */
14422 if (die
->tag
!= DW_TAG_inheritance
)
14423 return DW_ACCESS_public
;
14425 return DW_ACCESS_private
;
14429 /* DWARF 3+ defines the default accessibility a different way. The same
14430 rules apply now for DW_TAG_inheritance as for the members and it only
14431 depends on the container kind. */
14433 if (die
->parent
->tag
== DW_TAG_class_type
)
14434 return DW_ACCESS_private
;
14436 return DW_ACCESS_public
;
14440 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14441 offset. If the attribute was not found return 0, otherwise return
14442 1. If it was found but could not properly be handled, set *OFFSET
14446 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14449 struct attribute
*attr
;
14451 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14456 /* Note that we do not check for a section offset first here.
14457 This is because DW_AT_data_member_location is new in DWARF 4,
14458 so if we see it, we can assume that a constant form is really
14459 a constant and not a section offset. */
14460 if (attr
->form_is_constant ())
14461 *offset
= attr
->constant_value (0);
14462 else if (attr
->form_is_section_offset ())
14463 dwarf2_complex_location_expr_complaint ();
14464 else if (attr
->form_is_block ())
14465 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14467 dwarf2_complex_location_expr_complaint ();
14475 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14478 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14479 struct field
*field
)
14481 struct attribute
*attr
;
14483 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14486 if (attr
->form_is_constant ())
14488 LONGEST offset
= attr
->constant_value (0);
14489 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14491 else if (attr
->form_is_section_offset ())
14492 dwarf2_complex_location_expr_complaint ();
14493 else if (attr
->form_is_block ())
14496 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14498 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14501 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14502 struct objfile
*objfile
= per_objfile
->objfile
;
14503 struct dwarf2_locexpr_baton
*dlbaton
14504 = XOBNEW (&objfile
->objfile_obstack
,
14505 struct dwarf2_locexpr_baton
);
14506 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14507 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14508 /* When using this baton, we want to compute the address
14509 of the field, not the value. This is why
14510 is_reference is set to false here. */
14511 dlbaton
->is_reference
= false;
14512 dlbaton
->per_objfile
= per_objfile
;
14513 dlbaton
->per_cu
= cu
->per_cu
;
14515 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14519 dwarf2_complex_location_expr_complaint ();
14523 /* Add an aggregate field to the field list. */
14526 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14527 struct dwarf2_cu
*cu
)
14529 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14530 struct gdbarch
*gdbarch
= objfile
->arch ();
14531 struct nextfield
*new_field
;
14532 struct attribute
*attr
;
14534 const char *fieldname
= "";
14536 if (die
->tag
== DW_TAG_inheritance
)
14538 fip
->baseclasses
.emplace_back ();
14539 new_field
= &fip
->baseclasses
.back ();
14543 fip
->fields
.emplace_back ();
14544 new_field
= &fip
->fields
.back ();
14547 new_field
->offset
= die
->sect_off
;
14549 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14550 if (attr
!= nullptr)
14551 new_field
->accessibility
= DW_UNSND (attr
);
14553 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14554 if (new_field
->accessibility
!= DW_ACCESS_public
)
14555 fip
->non_public_fields
= 1;
14557 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14558 if (attr
!= nullptr)
14559 new_field
->virtuality
= DW_UNSND (attr
);
14561 new_field
->virtuality
= DW_VIRTUALITY_none
;
14563 fp
= &new_field
->field
;
14565 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14567 /* Data member other than a C++ static data member. */
14569 /* Get type of field. */
14570 fp
->set_type (die_type (die
, cu
));
14572 SET_FIELD_BITPOS (*fp
, 0);
14574 /* Get bit size of field (zero if none). */
14575 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14576 if (attr
!= nullptr)
14578 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14582 FIELD_BITSIZE (*fp
) = 0;
14585 /* Get bit offset of field. */
14586 handle_data_member_location (die
, cu
, fp
);
14587 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14588 if (attr
!= nullptr)
14590 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14592 /* For big endian bits, the DW_AT_bit_offset gives the
14593 additional bit offset from the MSB of the containing
14594 anonymous object to the MSB of the field. We don't
14595 have to do anything special since we don't need to
14596 know the size of the anonymous object. */
14597 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14601 /* For little endian bits, compute the bit offset to the
14602 MSB of the anonymous object, subtract off the number of
14603 bits from the MSB of the field to the MSB of the
14604 object, and then subtract off the number of bits of
14605 the field itself. The result is the bit offset of
14606 the LSB of the field. */
14607 int anonymous_size
;
14608 int bit_offset
= DW_UNSND (attr
);
14610 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14611 if (attr
!= nullptr)
14613 /* The size of the anonymous object containing
14614 the bit field is explicit, so use the
14615 indicated size (in bytes). */
14616 anonymous_size
= DW_UNSND (attr
);
14620 /* The size of the anonymous object containing
14621 the bit field must be inferred from the type
14622 attribute of the data member containing the
14624 anonymous_size
= TYPE_LENGTH (fp
->type ());
14626 SET_FIELD_BITPOS (*fp
,
14627 (FIELD_BITPOS (*fp
)
14628 + anonymous_size
* bits_per_byte
14629 - bit_offset
- FIELD_BITSIZE (*fp
)));
14632 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14634 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14635 + attr
->constant_value (0)));
14637 /* Get name of field. */
14638 fieldname
= dwarf2_name (die
, cu
);
14639 if (fieldname
== NULL
)
14642 /* The name is already allocated along with this objfile, so we don't
14643 need to duplicate it for the type. */
14644 fp
->name
= fieldname
;
14646 /* Change accessibility for artificial fields (e.g. virtual table
14647 pointer or virtual base class pointer) to private. */
14648 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14650 FIELD_ARTIFICIAL (*fp
) = 1;
14651 new_field
->accessibility
= DW_ACCESS_private
;
14652 fip
->non_public_fields
= 1;
14655 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14657 /* C++ static member. */
14659 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14660 is a declaration, but all versions of G++ as of this writing
14661 (so through at least 3.2.1) incorrectly generate
14662 DW_TAG_variable tags. */
14664 const char *physname
;
14666 /* Get name of field. */
14667 fieldname
= dwarf2_name (die
, cu
);
14668 if (fieldname
== NULL
)
14671 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14673 /* Only create a symbol if this is an external value.
14674 new_symbol checks this and puts the value in the global symbol
14675 table, which we want. If it is not external, new_symbol
14676 will try to put the value in cu->list_in_scope which is wrong. */
14677 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14679 /* A static const member, not much different than an enum as far as
14680 we're concerned, except that we can support more types. */
14681 new_symbol (die
, NULL
, cu
);
14684 /* Get physical name. */
14685 physname
= dwarf2_physname (fieldname
, die
, cu
);
14687 /* The name is already allocated along with this objfile, so we don't
14688 need to duplicate it for the type. */
14689 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14690 fp
->set_type (die_type (die
, cu
));
14691 FIELD_NAME (*fp
) = fieldname
;
14693 else if (die
->tag
== DW_TAG_inheritance
)
14695 /* C++ base class field. */
14696 handle_data_member_location (die
, cu
, fp
);
14697 FIELD_BITSIZE (*fp
) = 0;
14698 fp
->set_type (die_type (die
, cu
));
14699 FIELD_NAME (*fp
) = fp
->type ()->name ();
14702 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14705 /* Can the type given by DIE define another type? */
14708 type_can_define_types (const struct die_info
*die
)
14712 case DW_TAG_typedef
:
14713 case DW_TAG_class_type
:
14714 case DW_TAG_structure_type
:
14715 case DW_TAG_union_type
:
14716 case DW_TAG_enumeration_type
:
14724 /* Add a type definition defined in the scope of the FIP's class. */
14727 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14728 struct dwarf2_cu
*cu
)
14730 struct decl_field fp
;
14731 memset (&fp
, 0, sizeof (fp
));
14733 gdb_assert (type_can_define_types (die
));
14735 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14736 fp
.name
= dwarf2_name (die
, cu
);
14737 fp
.type
= read_type_die (die
, cu
);
14739 /* Save accessibility. */
14740 enum dwarf_access_attribute accessibility
;
14741 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14743 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14745 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14746 switch (accessibility
)
14748 case DW_ACCESS_public
:
14749 /* The assumed value if neither private nor protected. */
14751 case DW_ACCESS_private
:
14754 case DW_ACCESS_protected
:
14755 fp
.is_protected
= 1;
14758 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14761 if (die
->tag
== DW_TAG_typedef
)
14762 fip
->typedef_field_list
.push_back (fp
);
14764 fip
->nested_types_list
.push_back (fp
);
14767 /* A convenience typedef that's used when finding the discriminant
14768 field for a variant part. */
14769 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14772 /* Compute the discriminant range for a given variant. OBSTACK is
14773 where the results will be stored. VARIANT is the variant to
14774 process. IS_UNSIGNED indicates whether the discriminant is signed
14777 static const gdb::array_view
<discriminant_range
>
14778 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14781 std::vector
<discriminant_range
> ranges
;
14783 if (variant
.default_branch
)
14786 if (variant
.discr_list_data
== nullptr)
14788 discriminant_range r
14789 = {variant
.discriminant_value
, variant
.discriminant_value
};
14790 ranges
.push_back (r
);
14794 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14795 variant
.discr_list_data
->size
);
14796 while (!data
.empty ())
14798 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14800 complaint (_("invalid discriminant marker: %d"), data
[0]);
14803 bool is_range
= data
[0] == DW_DSC_range
;
14804 data
= data
.slice (1);
14806 ULONGEST low
, high
;
14807 unsigned int bytes_read
;
14811 complaint (_("DW_AT_discr_list missing low value"));
14815 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14817 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14819 data
= data
.slice (bytes_read
);
14825 complaint (_("DW_AT_discr_list missing high value"));
14829 high
= read_unsigned_leb128 (nullptr, data
.data (),
14832 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14834 data
= data
.slice (bytes_read
);
14839 ranges
.push_back ({ low
, high
});
14843 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14845 std::copy (ranges
.begin (), ranges
.end (), result
);
14846 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14849 static const gdb::array_view
<variant_part
> create_variant_parts
14850 (struct obstack
*obstack
,
14851 const offset_map_type
&offset_map
,
14852 struct field_info
*fi
,
14853 const std::vector
<variant_part_builder
> &variant_parts
);
14855 /* Fill in a "struct variant" for a given variant field. RESULT is
14856 the variant to fill in. OBSTACK is where any needed allocations
14857 will be done. OFFSET_MAP holds the mapping from section offsets to
14858 fields for the type. FI describes the fields of the type we're
14859 processing. FIELD is the variant field we're converting. */
14862 create_one_variant (variant
&result
, struct obstack
*obstack
,
14863 const offset_map_type
&offset_map
,
14864 struct field_info
*fi
, const variant_field
&field
)
14866 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14867 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14868 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14869 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14870 field
.variant_parts
);
14873 /* Fill in a "struct variant_part" for a given variant part. RESULT
14874 is the variant part to fill in. OBSTACK is where any needed
14875 allocations will be done. OFFSET_MAP holds the mapping from
14876 section offsets to fields for the type. FI describes the fields of
14877 the type we're processing. BUILDER is the variant part to be
14881 create_one_variant_part (variant_part
&result
,
14882 struct obstack
*obstack
,
14883 const offset_map_type
&offset_map
,
14884 struct field_info
*fi
,
14885 const variant_part_builder
&builder
)
14887 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14888 if (iter
== offset_map
.end ())
14890 result
.discriminant_index
= -1;
14891 /* Doesn't matter. */
14892 result
.is_unsigned
= false;
14896 result
.discriminant_index
= iter
->second
;
14898 = TYPE_UNSIGNED (fi
->fields
[result
.discriminant_index
].field
.type ());
14901 size_t n
= builder
.variants
.size ();
14902 variant
*output
= new (obstack
) variant
[n
];
14903 for (size_t i
= 0; i
< n
; ++i
)
14904 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14905 builder
.variants
[i
]);
14907 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14910 /* Create a vector of variant parts that can be attached to a type.
14911 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14912 holds the mapping from section offsets to fields for the type. FI
14913 describes the fields of the type we're processing. VARIANT_PARTS
14914 is the vector to convert. */
14916 static const gdb::array_view
<variant_part
>
14917 create_variant_parts (struct obstack
*obstack
,
14918 const offset_map_type
&offset_map
,
14919 struct field_info
*fi
,
14920 const std::vector
<variant_part_builder
> &variant_parts
)
14922 if (variant_parts
.empty ())
14925 size_t n
= variant_parts
.size ();
14926 variant_part
*result
= new (obstack
) variant_part
[n
];
14927 for (size_t i
= 0; i
< n
; ++i
)
14928 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14931 return gdb::array_view
<variant_part
> (result
, n
);
14934 /* Compute the variant part vector for FIP, attaching it to TYPE when
14938 add_variant_property (struct field_info
*fip
, struct type
*type
,
14939 struct dwarf2_cu
*cu
)
14941 /* Map section offsets of fields to their field index. Note the
14942 field index here does not take the number of baseclasses into
14944 offset_map_type offset_map
;
14945 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14946 offset_map
[fip
->fields
[i
].offset
] = i
;
14948 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14949 gdb::array_view
<variant_part
> parts
14950 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14951 fip
->variant_parts
);
14953 struct dynamic_prop prop
;
14954 prop
.kind
= PROP_VARIANT_PARTS
;
14955 prop
.data
.variant_parts
14956 = ((gdb::array_view
<variant_part
> *)
14957 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14959 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14962 /* Create the vector of fields, and attach it to the type. */
14965 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14966 struct dwarf2_cu
*cu
)
14968 int nfields
= fip
->nfields ();
14970 /* Record the field count, allocate space for the array of fields,
14971 and create blank accessibility bitfields if necessary. */
14972 type
->set_num_fields (nfields
);
14974 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14976 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14978 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14980 TYPE_FIELD_PRIVATE_BITS (type
) =
14981 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14982 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14984 TYPE_FIELD_PROTECTED_BITS (type
) =
14985 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14986 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14988 TYPE_FIELD_IGNORE_BITS (type
) =
14989 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14990 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14993 /* If the type has baseclasses, allocate and clear a bit vector for
14994 TYPE_FIELD_VIRTUAL_BITS. */
14995 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14997 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14998 unsigned char *pointer
;
15000 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15001 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15002 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15003 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15004 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15007 if (!fip
->variant_parts
.empty ())
15008 add_variant_property (fip
, type
, cu
);
15010 /* Copy the saved-up fields into the field vector. */
15011 for (int i
= 0; i
< nfields
; ++i
)
15013 struct nextfield
&field
15014 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15015 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15017 type
->field (i
) = field
.field
;
15018 switch (field
.accessibility
)
15020 case DW_ACCESS_private
:
15021 if (cu
->language
!= language_ada
)
15022 SET_TYPE_FIELD_PRIVATE (type
, i
);
15025 case DW_ACCESS_protected
:
15026 if (cu
->language
!= language_ada
)
15027 SET_TYPE_FIELD_PROTECTED (type
, i
);
15030 case DW_ACCESS_public
:
15034 /* Unknown accessibility. Complain and treat it as public. */
15036 complaint (_("unsupported accessibility %d"),
15037 field
.accessibility
);
15041 if (i
< fip
->baseclasses
.size ())
15043 switch (field
.virtuality
)
15045 case DW_VIRTUALITY_virtual
:
15046 case DW_VIRTUALITY_pure_virtual
:
15047 if (cu
->language
== language_ada
)
15048 error (_("unexpected virtuality in component of Ada type"));
15049 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15056 /* Return true if this member function is a constructor, false
15060 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15062 const char *fieldname
;
15063 const char *type_name
;
15066 if (die
->parent
== NULL
)
15069 if (die
->parent
->tag
!= DW_TAG_structure_type
15070 && die
->parent
->tag
!= DW_TAG_union_type
15071 && die
->parent
->tag
!= DW_TAG_class_type
)
15074 fieldname
= dwarf2_name (die
, cu
);
15075 type_name
= dwarf2_name (die
->parent
, cu
);
15076 if (fieldname
== NULL
|| type_name
== NULL
)
15079 len
= strlen (fieldname
);
15080 return (strncmp (fieldname
, type_name
, len
) == 0
15081 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15084 /* Check if the given VALUE is a recognized enum
15085 dwarf_defaulted_attribute constant according to DWARF5 spec,
15089 is_valid_DW_AT_defaulted (ULONGEST value
)
15093 case DW_DEFAULTED_no
:
15094 case DW_DEFAULTED_in_class
:
15095 case DW_DEFAULTED_out_of_class
:
15099 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15103 /* Add a member function to the proper fieldlist. */
15106 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15107 struct type
*type
, struct dwarf2_cu
*cu
)
15109 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15110 struct attribute
*attr
;
15112 struct fnfieldlist
*flp
= nullptr;
15113 struct fn_field
*fnp
;
15114 const char *fieldname
;
15115 struct type
*this_type
;
15116 enum dwarf_access_attribute accessibility
;
15118 if (cu
->language
== language_ada
)
15119 error (_("unexpected member function in Ada type"));
15121 /* Get name of member function. */
15122 fieldname
= dwarf2_name (die
, cu
);
15123 if (fieldname
== NULL
)
15126 /* Look up member function name in fieldlist. */
15127 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15129 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15131 flp
= &fip
->fnfieldlists
[i
];
15136 /* Create a new fnfieldlist if necessary. */
15137 if (flp
== nullptr)
15139 fip
->fnfieldlists
.emplace_back ();
15140 flp
= &fip
->fnfieldlists
.back ();
15141 flp
->name
= fieldname
;
15142 i
= fip
->fnfieldlists
.size () - 1;
15145 /* Create a new member function field and add it to the vector of
15147 flp
->fnfields
.emplace_back ();
15148 fnp
= &flp
->fnfields
.back ();
15150 /* Delay processing of the physname until later. */
15151 if (cu
->language
== language_cplus
)
15152 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15156 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15157 fnp
->physname
= physname
? physname
: "";
15160 fnp
->type
= alloc_type (objfile
);
15161 this_type
= read_type_die (die
, cu
);
15162 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15164 int nparams
= this_type
->num_fields ();
15166 /* TYPE is the domain of this method, and THIS_TYPE is the type
15167 of the method itself (TYPE_CODE_METHOD). */
15168 smash_to_method_type (fnp
->type
, type
,
15169 TYPE_TARGET_TYPE (this_type
),
15170 this_type
->fields (),
15171 this_type
->num_fields (),
15172 TYPE_VARARGS (this_type
));
15174 /* Handle static member functions.
15175 Dwarf2 has no clean way to discern C++ static and non-static
15176 member functions. G++ helps GDB by marking the first
15177 parameter for non-static member functions (which is the this
15178 pointer) as artificial. We obtain this information from
15179 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15180 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15181 fnp
->voffset
= VOFFSET_STATIC
;
15184 complaint (_("member function type missing for '%s'"),
15185 dwarf2_full_name (fieldname
, die
, cu
));
15187 /* Get fcontext from DW_AT_containing_type if present. */
15188 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15189 fnp
->fcontext
= die_containing_type (die
, cu
);
15191 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15192 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15194 /* Get accessibility. */
15195 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15196 if (attr
!= nullptr)
15197 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15199 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15200 switch (accessibility
)
15202 case DW_ACCESS_private
:
15203 fnp
->is_private
= 1;
15205 case DW_ACCESS_protected
:
15206 fnp
->is_protected
= 1;
15210 /* Check for artificial methods. */
15211 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15212 if (attr
&& DW_UNSND (attr
) != 0)
15213 fnp
->is_artificial
= 1;
15215 /* Check for defaulted methods. */
15216 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15217 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15218 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15220 /* Check for deleted methods. */
15221 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15222 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15223 fnp
->is_deleted
= 1;
15225 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15227 /* Get index in virtual function table if it is a virtual member
15228 function. For older versions of GCC, this is an offset in the
15229 appropriate virtual table, as specified by DW_AT_containing_type.
15230 For everyone else, it is an expression to be evaluated relative
15231 to the object address. */
15233 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15234 if (attr
!= nullptr)
15236 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15238 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15240 /* Old-style GCC. */
15241 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15243 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15244 || (DW_BLOCK (attr
)->size
> 1
15245 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15246 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15248 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15249 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15250 dwarf2_complex_location_expr_complaint ();
15252 fnp
->voffset
/= cu
->header
.addr_size
;
15256 dwarf2_complex_location_expr_complaint ();
15258 if (!fnp
->fcontext
)
15260 /* If there is no `this' field and no DW_AT_containing_type,
15261 we cannot actually find a base class context for the
15263 if (this_type
->num_fields () == 0
15264 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15266 complaint (_("cannot determine context for virtual member "
15267 "function \"%s\" (offset %s)"),
15268 fieldname
, sect_offset_str (die
->sect_off
));
15273 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15277 else if (attr
->form_is_section_offset ())
15279 dwarf2_complex_location_expr_complaint ();
15283 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15289 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15290 if (attr
&& DW_UNSND (attr
))
15292 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15293 complaint (_("Member function \"%s\" (offset %s) is virtual "
15294 "but the vtable offset is not specified"),
15295 fieldname
, sect_offset_str (die
->sect_off
));
15296 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15297 TYPE_CPLUS_DYNAMIC (type
) = 1;
15302 /* Create the vector of member function fields, and attach it to the type. */
15305 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15306 struct dwarf2_cu
*cu
)
15308 if (cu
->language
== language_ada
)
15309 error (_("unexpected member functions in Ada type"));
15311 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15312 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15314 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15316 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15318 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15319 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15321 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15322 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15323 fn_flp
->fn_fields
= (struct fn_field
*)
15324 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15326 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15327 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15330 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15333 /* Returns non-zero if NAME is the name of a vtable member in CU's
15334 language, zero otherwise. */
15336 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15338 static const char vptr
[] = "_vptr";
15340 /* Look for the C++ form of the vtable. */
15341 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15347 /* GCC outputs unnamed structures that are really pointers to member
15348 functions, with the ABI-specified layout. If TYPE describes
15349 such a structure, smash it into a member function type.
15351 GCC shouldn't do this; it should just output pointer to member DIEs.
15352 This is GCC PR debug/28767. */
15355 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15357 struct type
*pfn_type
, *self_type
, *new_type
;
15359 /* Check for a structure with no name and two children. */
15360 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15363 /* Check for __pfn and __delta members. */
15364 if (TYPE_FIELD_NAME (type
, 0) == NULL
15365 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15366 || TYPE_FIELD_NAME (type
, 1) == NULL
15367 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15370 /* Find the type of the method. */
15371 pfn_type
= type
->field (0).type ();
15372 if (pfn_type
== NULL
15373 || pfn_type
->code () != TYPE_CODE_PTR
15374 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15377 /* Look for the "this" argument. */
15378 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15379 if (pfn_type
->num_fields () == 0
15380 /* || pfn_type->field (0).type () == NULL */
15381 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15384 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15385 new_type
= alloc_type (objfile
);
15386 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15387 pfn_type
->fields (), pfn_type
->num_fields (),
15388 TYPE_VARARGS (pfn_type
));
15389 smash_to_methodptr_type (type
, new_type
);
15392 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15393 appropriate error checking and issuing complaints if there is a
15397 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15399 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15401 if (attr
== nullptr)
15404 if (!attr
->form_is_constant ())
15406 complaint (_("DW_AT_alignment must have constant form"
15407 " - DIE at %s [in module %s]"),
15408 sect_offset_str (die
->sect_off
),
15409 objfile_name (cu
->per_objfile
->objfile
));
15414 if (attr
->form
== DW_FORM_sdata
)
15416 LONGEST val
= DW_SND (attr
);
15419 complaint (_("DW_AT_alignment value must not be negative"
15420 " - DIE at %s [in module %s]"),
15421 sect_offset_str (die
->sect_off
),
15422 objfile_name (cu
->per_objfile
->objfile
));
15428 align
= DW_UNSND (attr
);
15432 complaint (_("DW_AT_alignment value must not be zero"
15433 " - DIE at %s [in module %s]"),
15434 sect_offset_str (die
->sect_off
),
15435 objfile_name (cu
->per_objfile
->objfile
));
15438 if ((align
& (align
- 1)) != 0)
15440 complaint (_("DW_AT_alignment value must be a power of 2"
15441 " - DIE at %s [in module %s]"),
15442 sect_offset_str (die
->sect_off
),
15443 objfile_name (cu
->per_objfile
->objfile
));
15450 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15451 the alignment for TYPE. */
15454 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15457 if (!set_type_align (type
, get_alignment (cu
, die
)))
15458 complaint (_("DW_AT_alignment value too large"
15459 " - DIE at %s [in module %s]"),
15460 sect_offset_str (die
->sect_off
),
15461 objfile_name (cu
->per_objfile
->objfile
));
15464 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15465 constant for a type, according to DWARF5 spec, Table 5.5. */
15468 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15473 case DW_CC_pass_by_reference
:
15474 case DW_CC_pass_by_value
:
15478 complaint (_("unrecognized DW_AT_calling_convention value "
15479 "(%s) for a type"), pulongest (value
));
15484 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15485 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15486 also according to GNU-specific values (see include/dwarf2.h). */
15489 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15494 case DW_CC_program
:
15498 case DW_CC_GNU_renesas_sh
:
15499 case DW_CC_GNU_borland_fastcall_i386
:
15500 case DW_CC_GDB_IBM_OpenCL
:
15504 complaint (_("unrecognized DW_AT_calling_convention value "
15505 "(%s) for a subroutine"), pulongest (value
));
15510 /* Called when we find the DIE that starts a structure or union scope
15511 (definition) to create a type for the structure or union. Fill in
15512 the type's name and general properties; the members will not be
15513 processed until process_structure_scope. A symbol table entry for
15514 the type will also not be done until process_structure_scope (assuming
15515 the type has a name).
15517 NOTE: we need to call these functions regardless of whether or not the
15518 DIE has a DW_AT_name attribute, since it might be an anonymous
15519 structure or union. This gets the type entered into our set of
15520 user defined types. */
15522 static struct type
*
15523 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15525 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15527 struct attribute
*attr
;
15530 /* If the definition of this type lives in .debug_types, read that type.
15531 Don't follow DW_AT_specification though, that will take us back up
15532 the chain and we want to go down. */
15533 attr
= die
->attr (DW_AT_signature
);
15534 if (attr
!= nullptr)
15536 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15538 /* The type's CU may not be the same as CU.
15539 Ensure TYPE is recorded with CU in die_type_hash. */
15540 return set_die_type (die
, type
, cu
);
15543 type
= alloc_type (objfile
);
15544 INIT_CPLUS_SPECIFIC (type
);
15546 name
= dwarf2_name (die
, cu
);
15549 if (cu
->language
== language_cplus
15550 || cu
->language
== language_d
15551 || cu
->language
== language_rust
)
15553 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15555 /* dwarf2_full_name might have already finished building the DIE's
15556 type. If so, there is no need to continue. */
15557 if (get_die_type (die
, cu
) != NULL
)
15558 return get_die_type (die
, cu
);
15560 type
->set_name (full_name
);
15564 /* The name is already allocated along with this objfile, so
15565 we don't need to duplicate it for the type. */
15566 type
->set_name (name
);
15570 if (die
->tag
== DW_TAG_structure_type
)
15572 type
->set_code (TYPE_CODE_STRUCT
);
15574 else if (die
->tag
== DW_TAG_union_type
)
15576 type
->set_code (TYPE_CODE_UNION
);
15580 type
->set_code (TYPE_CODE_STRUCT
);
15583 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15584 TYPE_DECLARED_CLASS (type
) = 1;
15586 /* Store the calling convention in the type if it's available in
15587 the die. Otherwise the calling convention remains set to
15588 the default value DW_CC_normal. */
15589 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15590 if (attr
!= nullptr
15591 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15593 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15594 TYPE_CPLUS_CALLING_CONVENTION (type
)
15595 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15598 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15599 if (attr
!= nullptr)
15601 if (attr
->form_is_constant ())
15602 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15605 struct dynamic_prop prop
;
15606 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15607 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15608 TYPE_LENGTH (type
) = 0;
15613 TYPE_LENGTH (type
) = 0;
15616 maybe_set_alignment (cu
, die
, type
);
15618 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15620 /* ICC<14 does not output the required DW_AT_declaration on
15621 incomplete types, but gives them a size of zero. */
15622 TYPE_STUB (type
) = 1;
15625 TYPE_STUB_SUPPORTED (type
) = 1;
15627 if (die_is_declaration (die
, cu
))
15628 TYPE_STUB (type
) = 1;
15629 else if (attr
== NULL
&& die
->child
== NULL
15630 && producer_is_realview (cu
->producer
))
15631 /* RealView does not output the required DW_AT_declaration
15632 on incomplete types. */
15633 TYPE_STUB (type
) = 1;
15635 /* We need to add the type field to the die immediately so we don't
15636 infinitely recurse when dealing with pointers to the structure
15637 type within the structure itself. */
15638 set_die_type (die
, type
, cu
);
15640 /* set_die_type should be already done. */
15641 set_descriptive_type (type
, die
, cu
);
15646 static void handle_struct_member_die
15647 (struct die_info
*child_die
,
15649 struct field_info
*fi
,
15650 std::vector
<struct symbol
*> *template_args
,
15651 struct dwarf2_cu
*cu
);
15653 /* A helper for handle_struct_member_die that handles
15654 DW_TAG_variant_part. */
15657 handle_variant_part (struct die_info
*die
, struct type
*type
,
15658 struct field_info
*fi
,
15659 std::vector
<struct symbol
*> *template_args
,
15660 struct dwarf2_cu
*cu
)
15662 variant_part_builder
*new_part
;
15663 if (fi
->current_variant_part
== nullptr)
15665 fi
->variant_parts
.emplace_back ();
15666 new_part
= &fi
->variant_parts
.back ();
15668 else if (!fi
->current_variant_part
->processing_variant
)
15670 complaint (_("nested DW_TAG_variant_part seen "
15671 "- DIE at %s [in module %s]"),
15672 sect_offset_str (die
->sect_off
),
15673 objfile_name (cu
->per_objfile
->objfile
));
15678 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15679 current
.variant_parts
.emplace_back ();
15680 new_part
= ¤t
.variant_parts
.back ();
15683 /* When we recurse, we want callees to add to this new variant
15685 scoped_restore save_current_variant_part
15686 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15688 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15691 /* It's a univariant form, an extension we support. */
15693 else if (discr
->form_is_ref ())
15695 struct dwarf2_cu
*target_cu
= cu
;
15696 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15698 new_part
->discriminant_offset
= target_die
->sect_off
;
15702 complaint (_("DW_AT_discr does not have DIE reference form"
15703 " - DIE at %s [in module %s]"),
15704 sect_offset_str (die
->sect_off
),
15705 objfile_name (cu
->per_objfile
->objfile
));
15708 for (die_info
*child_die
= die
->child
;
15710 child_die
= child_die
->sibling
)
15711 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15714 /* A helper for handle_struct_member_die that handles
15718 handle_variant (struct die_info
*die
, struct type
*type
,
15719 struct field_info
*fi
,
15720 std::vector
<struct symbol
*> *template_args
,
15721 struct dwarf2_cu
*cu
)
15723 if (fi
->current_variant_part
== nullptr)
15725 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15726 "- DIE at %s [in module %s]"),
15727 sect_offset_str (die
->sect_off
),
15728 objfile_name (cu
->per_objfile
->objfile
));
15731 if (fi
->current_variant_part
->processing_variant
)
15733 complaint (_("nested DW_TAG_variant seen "
15734 "- DIE at %s [in module %s]"),
15735 sect_offset_str (die
->sect_off
),
15736 objfile_name (cu
->per_objfile
->objfile
));
15740 scoped_restore save_processing_variant
15741 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15744 fi
->current_variant_part
->variants
.emplace_back ();
15745 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15746 variant
.first_field
= fi
->fields
.size ();
15748 /* In a variant we want to get the discriminant and also add a
15749 field for our sole member child. */
15750 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15751 if (discr
== nullptr)
15753 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15754 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15755 variant
.default_branch
= true;
15757 variant
.discr_list_data
= DW_BLOCK (discr
);
15760 variant
.discriminant_value
= DW_UNSND (discr
);
15762 for (die_info
*variant_child
= die
->child
;
15763 variant_child
!= NULL
;
15764 variant_child
= variant_child
->sibling
)
15765 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15767 variant
.last_field
= fi
->fields
.size ();
15770 /* A helper for process_structure_scope that handles a single member
15774 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15775 struct field_info
*fi
,
15776 std::vector
<struct symbol
*> *template_args
,
15777 struct dwarf2_cu
*cu
)
15779 if (child_die
->tag
== DW_TAG_member
15780 || child_die
->tag
== DW_TAG_variable
)
15782 /* NOTE: carlton/2002-11-05: A C++ static data member
15783 should be a DW_TAG_member that is a declaration, but
15784 all versions of G++ as of this writing (so through at
15785 least 3.2.1) incorrectly generate DW_TAG_variable
15786 tags for them instead. */
15787 dwarf2_add_field (fi
, child_die
, cu
);
15789 else if (child_die
->tag
== DW_TAG_subprogram
)
15791 /* Rust doesn't have member functions in the C++ sense.
15792 However, it does emit ordinary functions as children
15793 of a struct DIE. */
15794 if (cu
->language
== language_rust
)
15795 read_func_scope (child_die
, cu
);
15798 /* C++ member function. */
15799 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15802 else if (child_die
->tag
== DW_TAG_inheritance
)
15804 /* C++ base class field. */
15805 dwarf2_add_field (fi
, child_die
, cu
);
15807 else if (type_can_define_types (child_die
))
15808 dwarf2_add_type_defn (fi
, child_die
, cu
);
15809 else if (child_die
->tag
== DW_TAG_template_type_param
15810 || child_die
->tag
== DW_TAG_template_value_param
)
15812 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15815 template_args
->push_back (arg
);
15817 else if (child_die
->tag
== DW_TAG_variant_part
)
15818 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15819 else if (child_die
->tag
== DW_TAG_variant
)
15820 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15823 /* Finish creating a structure or union type, including filling in
15824 its members and creating a symbol for it. */
15827 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15829 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15830 struct die_info
*child_die
;
15833 type
= get_die_type (die
, cu
);
15835 type
= read_structure_type (die
, cu
);
15837 bool has_template_parameters
= false;
15838 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15840 struct field_info fi
;
15841 std::vector
<struct symbol
*> template_args
;
15843 child_die
= die
->child
;
15845 while (child_die
&& child_die
->tag
)
15847 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15848 child_die
= child_die
->sibling
;
15851 /* Attach template arguments to type. */
15852 if (!template_args
.empty ())
15854 has_template_parameters
= true;
15855 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15856 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15857 TYPE_TEMPLATE_ARGUMENTS (type
)
15858 = XOBNEWVEC (&objfile
->objfile_obstack
,
15860 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15861 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15862 template_args
.data (),
15863 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15864 * sizeof (struct symbol
*)));
15867 /* Attach fields and member functions to the type. */
15868 if (fi
.nfields () > 0)
15869 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15870 if (!fi
.fnfieldlists
.empty ())
15872 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15874 /* Get the type which refers to the base class (possibly this
15875 class itself) which contains the vtable pointer for the current
15876 class from the DW_AT_containing_type attribute. This use of
15877 DW_AT_containing_type is a GNU extension. */
15879 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15881 struct type
*t
= die_containing_type (die
, cu
);
15883 set_type_vptr_basetype (type
, t
);
15888 /* Our own class provides vtbl ptr. */
15889 for (i
= t
->num_fields () - 1;
15890 i
>= TYPE_N_BASECLASSES (t
);
15893 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15895 if (is_vtable_name (fieldname
, cu
))
15897 set_type_vptr_fieldno (type
, i
);
15902 /* Complain if virtual function table field not found. */
15903 if (i
< TYPE_N_BASECLASSES (t
))
15904 complaint (_("virtual function table pointer "
15905 "not found when defining class '%s'"),
15906 type
->name () ? type
->name () : "");
15910 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15913 else if (cu
->producer
15914 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15916 /* The IBM XLC compiler does not provide direct indication
15917 of the containing type, but the vtable pointer is
15918 always named __vfp. */
15922 for (i
= type
->num_fields () - 1;
15923 i
>= TYPE_N_BASECLASSES (type
);
15926 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15928 set_type_vptr_fieldno (type
, i
);
15929 set_type_vptr_basetype (type
, type
);
15936 /* Copy fi.typedef_field_list linked list elements content into the
15937 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15938 if (!fi
.typedef_field_list
.empty ())
15940 int count
= fi
.typedef_field_list
.size ();
15942 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15943 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15944 = ((struct decl_field
*)
15946 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15947 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15949 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15950 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15953 /* Copy fi.nested_types_list linked list elements content into the
15954 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15955 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15957 int count
= fi
.nested_types_list
.size ();
15959 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15960 TYPE_NESTED_TYPES_ARRAY (type
)
15961 = ((struct decl_field
*)
15962 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15963 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15965 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15966 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15970 quirk_gcc_member_function_pointer (type
, objfile
);
15971 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15972 cu
->rust_unions
.push_back (type
);
15974 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15975 snapshots) has been known to create a die giving a declaration
15976 for a class that has, as a child, a die giving a definition for a
15977 nested class. So we have to process our children even if the
15978 current die is a declaration. Normally, of course, a declaration
15979 won't have any children at all. */
15981 child_die
= die
->child
;
15983 while (child_die
!= NULL
&& child_die
->tag
)
15985 if (child_die
->tag
== DW_TAG_member
15986 || child_die
->tag
== DW_TAG_variable
15987 || child_die
->tag
== DW_TAG_inheritance
15988 || child_die
->tag
== DW_TAG_template_value_param
15989 || child_die
->tag
== DW_TAG_template_type_param
)
15994 process_die (child_die
, cu
);
15996 child_die
= child_die
->sibling
;
15999 /* Do not consider external references. According to the DWARF standard,
16000 these DIEs are identified by the fact that they have no byte_size
16001 attribute, and a declaration attribute. */
16002 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16003 || !die_is_declaration (die
, cu
)
16004 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16006 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16008 if (has_template_parameters
)
16010 struct symtab
*symtab
;
16011 if (sym
!= nullptr)
16012 symtab
= symbol_symtab (sym
);
16013 else if (cu
->line_header
!= nullptr)
16015 /* Any related symtab will do. */
16017 = cu
->line_header
->file_names ()[0].symtab
;
16022 complaint (_("could not find suitable "
16023 "symtab for template parameter"
16024 " - DIE at %s [in module %s]"),
16025 sect_offset_str (die
->sect_off
),
16026 objfile_name (objfile
));
16029 if (symtab
!= nullptr)
16031 /* Make sure that the symtab is set on the new symbols.
16032 Even though they don't appear in this symtab directly,
16033 other parts of gdb assume that symbols do, and this is
16034 reasonably true. */
16035 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16036 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16042 /* Assuming DIE is an enumeration type, and TYPE is its associated
16043 type, update TYPE using some information only available in DIE's
16044 children. In particular, the fields are computed. */
16047 update_enumeration_type_from_children (struct die_info
*die
,
16049 struct dwarf2_cu
*cu
)
16051 struct die_info
*child_die
;
16052 int unsigned_enum
= 1;
16055 auto_obstack obstack
;
16056 std::vector
<struct field
> fields
;
16058 for (child_die
= die
->child
;
16059 child_die
!= NULL
&& child_die
->tag
;
16060 child_die
= child_die
->sibling
)
16062 struct attribute
*attr
;
16064 const gdb_byte
*bytes
;
16065 struct dwarf2_locexpr_baton
*baton
;
16068 if (child_die
->tag
!= DW_TAG_enumerator
)
16071 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16075 name
= dwarf2_name (child_die
, cu
);
16077 name
= "<anonymous enumerator>";
16079 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16080 &value
, &bytes
, &baton
);
16088 if (count_one_bits_ll (value
) >= 2)
16092 fields
.emplace_back ();
16093 struct field
&field
= fields
.back ();
16094 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16095 SET_FIELD_ENUMVAL (field
, value
);
16098 if (!fields
.empty ())
16100 type
->set_num_fields (fields
.size ());
16103 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16104 memcpy (type
->fields (), fields
.data (),
16105 sizeof (struct field
) * fields
.size ());
16109 TYPE_UNSIGNED (type
) = 1;
16111 TYPE_FLAG_ENUM (type
) = 1;
16114 /* Given a DW_AT_enumeration_type die, set its type. We do not
16115 complete the type's fields yet, or create any symbols. */
16117 static struct type
*
16118 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16120 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16122 struct attribute
*attr
;
16125 /* If the definition of this type lives in .debug_types, read that type.
16126 Don't follow DW_AT_specification though, that will take us back up
16127 the chain and we want to go down. */
16128 attr
= die
->attr (DW_AT_signature
);
16129 if (attr
!= nullptr)
16131 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16133 /* The type's CU may not be the same as CU.
16134 Ensure TYPE is recorded with CU in die_type_hash. */
16135 return set_die_type (die
, type
, cu
);
16138 type
= alloc_type (objfile
);
16140 type
->set_code (TYPE_CODE_ENUM
);
16141 name
= dwarf2_full_name (NULL
, die
, cu
);
16143 type
->set_name (name
);
16145 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16148 struct type
*underlying_type
= die_type (die
, cu
);
16150 TYPE_TARGET_TYPE (type
) = underlying_type
;
16153 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16154 if (attr
!= nullptr)
16156 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16160 TYPE_LENGTH (type
) = 0;
16163 maybe_set_alignment (cu
, die
, type
);
16165 /* The enumeration DIE can be incomplete. In Ada, any type can be
16166 declared as private in the package spec, and then defined only
16167 inside the package body. Such types are known as Taft Amendment
16168 Types. When another package uses such a type, an incomplete DIE
16169 may be generated by the compiler. */
16170 if (die_is_declaration (die
, cu
))
16171 TYPE_STUB (type
) = 1;
16173 /* If this type has an underlying type that is not a stub, then we
16174 may use its attributes. We always use the "unsigned" attribute
16175 in this situation, because ordinarily we guess whether the type
16176 is unsigned -- but the guess can be wrong and the underlying type
16177 can tell us the reality. However, we defer to a local size
16178 attribute if one exists, because this lets the compiler override
16179 the underlying type if needed. */
16180 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16182 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16183 underlying_type
= check_typedef (underlying_type
);
16184 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16185 if (TYPE_LENGTH (type
) == 0)
16186 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16187 if (TYPE_RAW_ALIGN (type
) == 0
16188 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16189 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16192 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16194 set_die_type (die
, type
, cu
);
16196 /* Finish the creation of this type by using the enum's children.
16197 Note that, as usual, this must come after set_die_type to avoid
16198 infinite recursion when trying to compute the names of the
16200 update_enumeration_type_from_children (die
, type
, cu
);
16205 /* Given a pointer to a die which begins an enumeration, process all
16206 the dies that define the members of the enumeration, and create the
16207 symbol for the enumeration type.
16209 NOTE: We reverse the order of the element list. */
16212 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16214 struct type
*this_type
;
16216 this_type
= get_die_type (die
, cu
);
16217 if (this_type
== NULL
)
16218 this_type
= read_enumeration_type (die
, cu
);
16220 if (die
->child
!= NULL
)
16222 struct die_info
*child_die
;
16225 child_die
= die
->child
;
16226 while (child_die
&& child_die
->tag
)
16228 if (child_die
->tag
!= DW_TAG_enumerator
)
16230 process_die (child_die
, cu
);
16234 name
= dwarf2_name (child_die
, cu
);
16236 new_symbol (child_die
, this_type
, cu
);
16239 child_die
= child_die
->sibling
;
16243 /* If we are reading an enum from a .debug_types unit, and the enum
16244 is a declaration, and the enum is not the signatured type in the
16245 unit, then we do not want to add a symbol for it. Adding a
16246 symbol would in some cases obscure the true definition of the
16247 enum, giving users an incomplete type when the definition is
16248 actually available. Note that we do not want to do this for all
16249 enums which are just declarations, because C++0x allows forward
16250 enum declarations. */
16251 if (cu
->per_cu
->is_debug_types
16252 && die_is_declaration (die
, cu
))
16254 struct signatured_type
*sig_type
;
16256 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16257 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16258 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16262 new_symbol (die
, this_type
, cu
);
16265 /* Extract all information from a DW_TAG_array_type DIE and put it in
16266 the DIE's type field. For now, this only handles one dimensional
16269 static struct type
*
16270 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16272 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16273 struct die_info
*child_die
;
16275 struct type
*element_type
, *range_type
, *index_type
;
16276 struct attribute
*attr
;
16278 struct dynamic_prop
*byte_stride_prop
= NULL
;
16279 unsigned int bit_stride
= 0;
16281 element_type
= die_type (die
, cu
);
16283 /* The die_type call above may have already set the type for this DIE. */
16284 type
= get_die_type (die
, cu
);
16288 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16292 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16295 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16296 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16300 complaint (_("unable to read array DW_AT_byte_stride "
16301 " - DIE at %s [in module %s]"),
16302 sect_offset_str (die
->sect_off
),
16303 objfile_name (cu
->per_objfile
->objfile
));
16304 /* Ignore this attribute. We will likely not be able to print
16305 arrays of this type correctly, but there is little we can do
16306 to help if we cannot read the attribute's value. */
16307 byte_stride_prop
= NULL
;
16311 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16313 bit_stride
= DW_UNSND (attr
);
16315 /* Irix 6.2 native cc creates array types without children for
16316 arrays with unspecified length. */
16317 if (die
->child
== NULL
)
16319 index_type
= objfile_type (objfile
)->builtin_int
;
16320 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16321 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16322 byte_stride_prop
, bit_stride
);
16323 return set_die_type (die
, type
, cu
);
16326 std::vector
<struct type
*> range_types
;
16327 child_die
= die
->child
;
16328 while (child_die
&& child_die
->tag
)
16330 if (child_die
->tag
== DW_TAG_subrange_type
)
16332 struct type
*child_type
= read_type_die (child_die
, cu
);
16334 if (child_type
!= NULL
)
16336 /* The range type was succesfully read. Save it for the
16337 array type creation. */
16338 range_types
.push_back (child_type
);
16341 child_die
= child_die
->sibling
;
16344 /* Dwarf2 dimensions are output from left to right, create the
16345 necessary array types in backwards order. */
16347 type
= element_type
;
16349 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16353 while (i
< range_types
.size ())
16354 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16355 byte_stride_prop
, bit_stride
);
16359 size_t ndim
= range_types
.size ();
16361 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16362 byte_stride_prop
, bit_stride
);
16365 /* Understand Dwarf2 support for vector types (like they occur on
16366 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16367 array type. This is not part of the Dwarf2/3 standard yet, but a
16368 custom vendor extension. The main difference between a regular
16369 array and the vector variant is that vectors are passed by value
16371 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16372 if (attr
!= nullptr)
16373 make_vector_type (type
);
16375 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16376 implementation may choose to implement triple vectors using this
16378 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16379 if (attr
!= nullptr)
16381 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16382 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16384 complaint (_("DW_AT_byte_size for array type smaller "
16385 "than the total size of elements"));
16388 name
= dwarf2_name (die
, cu
);
16390 type
->set_name (name
);
16392 maybe_set_alignment (cu
, die
, type
);
16394 /* Install the type in the die. */
16395 set_die_type (die
, type
, cu
);
16397 /* set_die_type should be already done. */
16398 set_descriptive_type (type
, die
, cu
);
16403 static enum dwarf_array_dim_ordering
16404 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16406 struct attribute
*attr
;
16408 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16410 if (attr
!= nullptr)
16411 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16413 /* GNU F77 is a special case, as at 08/2004 array type info is the
16414 opposite order to the dwarf2 specification, but data is still
16415 laid out as per normal fortran.
16417 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16418 version checking. */
16420 if (cu
->language
== language_fortran
16421 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16423 return DW_ORD_row_major
;
16426 switch (cu
->language_defn
->la_array_ordering
)
16428 case array_column_major
:
16429 return DW_ORD_col_major
;
16430 case array_row_major
:
16432 return DW_ORD_row_major
;
16436 /* Extract all information from a DW_TAG_set_type DIE and put it in
16437 the DIE's type field. */
16439 static struct type
*
16440 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16442 struct type
*domain_type
, *set_type
;
16443 struct attribute
*attr
;
16445 domain_type
= die_type (die
, cu
);
16447 /* The die_type call above may have already set the type for this DIE. */
16448 set_type
= get_die_type (die
, cu
);
16452 set_type
= create_set_type (NULL
, domain_type
);
16454 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16455 if (attr
!= nullptr)
16456 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16458 maybe_set_alignment (cu
, die
, set_type
);
16460 return set_die_type (die
, set_type
, cu
);
16463 /* A helper for read_common_block that creates a locexpr baton.
16464 SYM is the symbol which we are marking as computed.
16465 COMMON_DIE is the DIE for the common block.
16466 COMMON_LOC is the location expression attribute for the common
16468 MEMBER_LOC is the location expression attribute for the particular
16469 member of the common block that we are processing.
16470 CU is the CU from which the above come. */
16473 mark_common_block_symbol_computed (struct symbol
*sym
,
16474 struct die_info
*common_die
,
16475 struct attribute
*common_loc
,
16476 struct attribute
*member_loc
,
16477 struct dwarf2_cu
*cu
)
16479 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16480 struct objfile
*objfile
= per_objfile
->objfile
;
16481 struct dwarf2_locexpr_baton
*baton
;
16483 unsigned int cu_off
;
16484 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16485 LONGEST offset
= 0;
16487 gdb_assert (common_loc
&& member_loc
);
16488 gdb_assert (common_loc
->form_is_block ());
16489 gdb_assert (member_loc
->form_is_block ()
16490 || member_loc
->form_is_constant ());
16492 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16493 baton
->per_objfile
= per_objfile
;
16494 baton
->per_cu
= cu
->per_cu
;
16495 gdb_assert (baton
->per_cu
);
16497 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16499 if (member_loc
->form_is_constant ())
16501 offset
= member_loc
->constant_value (0);
16502 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16505 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16507 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16510 *ptr
++ = DW_OP_call4
;
16511 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16512 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16515 if (member_loc
->form_is_constant ())
16517 *ptr
++ = DW_OP_addr
;
16518 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16519 ptr
+= cu
->header
.addr_size
;
16523 /* We have to copy the data here, because DW_OP_call4 will only
16524 use a DW_AT_location attribute. */
16525 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16526 ptr
+= DW_BLOCK (member_loc
)->size
;
16529 *ptr
++ = DW_OP_plus
;
16530 gdb_assert (ptr
- baton
->data
== baton
->size
);
16532 SYMBOL_LOCATION_BATON (sym
) = baton
;
16533 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16536 /* Create appropriate locally-scoped variables for all the
16537 DW_TAG_common_block entries. Also create a struct common_block
16538 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16539 is used to separate the common blocks name namespace from regular
16543 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16545 struct attribute
*attr
;
16547 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16548 if (attr
!= nullptr)
16550 /* Support the .debug_loc offsets. */
16551 if (attr
->form_is_block ())
16555 else if (attr
->form_is_section_offset ())
16557 dwarf2_complex_location_expr_complaint ();
16562 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16563 "common block member");
16568 if (die
->child
!= NULL
)
16570 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16571 struct die_info
*child_die
;
16572 size_t n_entries
= 0, size
;
16573 struct common_block
*common_block
;
16574 struct symbol
*sym
;
16576 for (child_die
= die
->child
;
16577 child_die
&& child_die
->tag
;
16578 child_die
= child_die
->sibling
)
16581 size
= (sizeof (struct common_block
)
16582 + (n_entries
- 1) * sizeof (struct symbol
*));
16584 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16586 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16587 common_block
->n_entries
= 0;
16589 for (child_die
= die
->child
;
16590 child_die
&& child_die
->tag
;
16591 child_die
= child_die
->sibling
)
16593 /* Create the symbol in the DW_TAG_common_block block in the current
16595 sym
= new_symbol (child_die
, NULL
, cu
);
16598 struct attribute
*member_loc
;
16600 common_block
->contents
[common_block
->n_entries
++] = sym
;
16602 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16606 /* GDB has handled this for a long time, but it is
16607 not specified by DWARF. It seems to have been
16608 emitted by gfortran at least as recently as:
16609 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16610 complaint (_("Variable in common block has "
16611 "DW_AT_data_member_location "
16612 "- DIE at %s [in module %s]"),
16613 sect_offset_str (child_die
->sect_off
),
16614 objfile_name (objfile
));
16616 if (member_loc
->form_is_section_offset ())
16617 dwarf2_complex_location_expr_complaint ();
16618 else if (member_loc
->form_is_constant ()
16619 || member_loc
->form_is_block ())
16621 if (attr
!= nullptr)
16622 mark_common_block_symbol_computed (sym
, die
, attr
,
16626 dwarf2_complex_location_expr_complaint ();
16631 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16632 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16636 /* Create a type for a C++ namespace. */
16638 static struct type
*
16639 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16641 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16642 const char *previous_prefix
, *name
;
16646 /* For extensions, reuse the type of the original namespace. */
16647 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16649 struct die_info
*ext_die
;
16650 struct dwarf2_cu
*ext_cu
= cu
;
16652 ext_die
= dwarf2_extension (die
, &ext_cu
);
16653 type
= read_type_die (ext_die
, ext_cu
);
16655 /* EXT_CU may not be the same as CU.
16656 Ensure TYPE is recorded with CU in die_type_hash. */
16657 return set_die_type (die
, type
, cu
);
16660 name
= namespace_name (die
, &is_anonymous
, cu
);
16662 /* Now build the name of the current namespace. */
16664 previous_prefix
= determine_prefix (die
, cu
);
16665 if (previous_prefix
[0] != '\0')
16666 name
= typename_concat (&objfile
->objfile_obstack
,
16667 previous_prefix
, name
, 0, cu
);
16669 /* Create the type. */
16670 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16672 return set_die_type (die
, type
, cu
);
16675 /* Read a namespace scope. */
16678 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16680 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16683 /* Add a symbol associated to this if we haven't seen the namespace
16684 before. Also, add a using directive if it's an anonymous
16687 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16691 type
= read_type_die (die
, cu
);
16692 new_symbol (die
, type
, cu
);
16694 namespace_name (die
, &is_anonymous
, cu
);
16697 const char *previous_prefix
= determine_prefix (die
, cu
);
16699 std::vector
<const char *> excludes
;
16700 add_using_directive (using_directives (cu
),
16701 previous_prefix
, type
->name (), NULL
,
16702 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16706 if (die
->child
!= NULL
)
16708 struct die_info
*child_die
= die
->child
;
16710 while (child_die
&& child_die
->tag
)
16712 process_die (child_die
, cu
);
16713 child_die
= child_die
->sibling
;
16718 /* Read a Fortran module as type. This DIE can be only a declaration used for
16719 imported module. Still we need that type as local Fortran "use ... only"
16720 declaration imports depend on the created type in determine_prefix. */
16722 static struct type
*
16723 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16725 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16726 const char *module_name
;
16729 module_name
= dwarf2_name (die
, cu
);
16730 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16732 return set_die_type (die
, type
, cu
);
16735 /* Read a Fortran module. */
16738 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16740 struct die_info
*child_die
= die
->child
;
16743 type
= read_type_die (die
, cu
);
16744 new_symbol (die
, type
, cu
);
16746 while (child_die
&& child_die
->tag
)
16748 process_die (child_die
, cu
);
16749 child_die
= child_die
->sibling
;
16753 /* Return the name of the namespace represented by DIE. Set
16754 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16757 static const char *
16758 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16760 struct die_info
*current_die
;
16761 const char *name
= NULL
;
16763 /* Loop through the extensions until we find a name. */
16765 for (current_die
= die
;
16766 current_die
!= NULL
;
16767 current_die
= dwarf2_extension (die
, &cu
))
16769 /* We don't use dwarf2_name here so that we can detect the absence
16770 of a name -> anonymous namespace. */
16771 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16777 /* Is it an anonymous namespace? */
16779 *is_anonymous
= (name
== NULL
);
16781 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16786 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16787 the user defined type vector. */
16789 static struct type
*
16790 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16792 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16793 struct comp_unit_head
*cu_header
= &cu
->header
;
16795 struct attribute
*attr_byte_size
;
16796 struct attribute
*attr_address_class
;
16797 int byte_size
, addr_class
;
16798 struct type
*target_type
;
16800 target_type
= die_type (die
, cu
);
16802 /* The die_type call above may have already set the type for this DIE. */
16803 type
= get_die_type (die
, cu
);
16807 type
= lookup_pointer_type (target_type
);
16809 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16810 if (attr_byte_size
)
16811 byte_size
= DW_UNSND (attr_byte_size
);
16813 byte_size
= cu_header
->addr_size
;
16815 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16816 if (attr_address_class
)
16817 addr_class
= DW_UNSND (attr_address_class
);
16819 addr_class
= DW_ADDR_none
;
16821 ULONGEST alignment
= get_alignment (cu
, die
);
16823 /* If the pointer size, alignment, or address class is different
16824 than the default, create a type variant marked as such and set
16825 the length accordingly. */
16826 if (TYPE_LENGTH (type
) != byte_size
16827 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16828 && alignment
!= TYPE_RAW_ALIGN (type
))
16829 || addr_class
!= DW_ADDR_none
)
16831 if (gdbarch_address_class_type_flags_p (gdbarch
))
16835 type_flags
= gdbarch_address_class_type_flags
16836 (gdbarch
, byte_size
, addr_class
);
16837 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16839 type
= make_type_with_address_space (type
, type_flags
);
16841 else if (TYPE_LENGTH (type
) != byte_size
)
16843 complaint (_("invalid pointer size %d"), byte_size
);
16845 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16847 complaint (_("Invalid DW_AT_alignment"
16848 " - DIE at %s [in module %s]"),
16849 sect_offset_str (die
->sect_off
),
16850 objfile_name (cu
->per_objfile
->objfile
));
16854 /* Should we also complain about unhandled address classes? */
16858 TYPE_LENGTH (type
) = byte_size
;
16859 set_type_align (type
, alignment
);
16860 return set_die_type (die
, type
, cu
);
16863 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16864 the user defined type vector. */
16866 static struct type
*
16867 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16870 struct type
*to_type
;
16871 struct type
*domain
;
16873 to_type
= die_type (die
, cu
);
16874 domain
= die_containing_type (die
, cu
);
16876 /* The calls above may have already set the type for this DIE. */
16877 type
= get_die_type (die
, cu
);
16881 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16882 type
= lookup_methodptr_type (to_type
);
16883 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16885 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16887 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16888 to_type
->fields (), to_type
->num_fields (),
16889 TYPE_VARARGS (to_type
));
16890 type
= lookup_methodptr_type (new_type
);
16893 type
= lookup_memberptr_type (to_type
, domain
);
16895 return set_die_type (die
, type
, cu
);
16898 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16899 the user defined type vector. */
16901 static struct type
*
16902 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16903 enum type_code refcode
)
16905 struct comp_unit_head
*cu_header
= &cu
->header
;
16906 struct type
*type
, *target_type
;
16907 struct attribute
*attr
;
16909 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16911 target_type
= die_type (die
, cu
);
16913 /* The die_type call above may have already set the type for this DIE. */
16914 type
= get_die_type (die
, cu
);
16918 type
= lookup_reference_type (target_type
, refcode
);
16919 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16920 if (attr
!= nullptr)
16922 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16926 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16928 maybe_set_alignment (cu
, die
, type
);
16929 return set_die_type (die
, type
, cu
);
16932 /* Add the given cv-qualifiers to the element type of the array. GCC
16933 outputs DWARF type qualifiers that apply to an array, not the
16934 element type. But GDB relies on the array element type to carry
16935 the cv-qualifiers. This mimics section 6.7.3 of the C99
16938 static struct type
*
16939 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16940 struct type
*base_type
, int cnst
, int voltl
)
16942 struct type
*el_type
, *inner_array
;
16944 base_type
= copy_type (base_type
);
16945 inner_array
= base_type
;
16947 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16949 TYPE_TARGET_TYPE (inner_array
) =
16950 copy_type (TYPE_TARGET_TYPE (inner_array
));
16951 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16954 el_type
= TYPE_TARGET_TYPE (inner_array
);
16955 cnst
|= TYPE_CONST (el_type
);
16956 voltl
|= TYPE_VOLATILE (el_type
);
16957 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16959 return set_die_type (die
, base_type
, cu
);
16962 static struct type
*
16963 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16965 struct type
*base_type
, *cv_type
;
16967 base_type
= die_type (die
, cu
);
16969 /* The die_type call above may have already set the type for this DIE. */
16970 cv_type
= get_die_type (die
, cu
);
16974 /* In case the const qualifier is applied to an array type, the element type
16975 is so qualified, not the array type (section 6.7.3 of C99). */
16976 if (base_type
->code () == TYPE_CODE_ARRAY
)
16977 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16979 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16980 return set_die_type (die
, cv_type
, cu
);
16983 static struct type
*
16984 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16986 struct type
*base_type
, *cv_type
;
16988 base_type
= die_type (die
, cu
);
16990 /* The die_type call above may have already set the type for this DIE. */
16991 cv_type
= get_die_type (die
, cu
);
16995 /* In case the volatile qualifier is applied to an array type, the
16996 element type is so qualified, not the array type (section 6.7.3
16998 if (base_type
->code () == TYPE_CODE_ARRAY
)
16999 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17001 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17002 return set_die_type (die
, cv_type
, cu
);
17005 /* Handle DW_TAG_restrict_type. */
17007 static struct type
*
17008 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17010 struct type
*base_type
, *cv_type
;
17012 base_type
= die_type (die
, cu
);
17014 /* The die_type call above may have already set the type for this DIE. */
17015 cv_type
= get_die_type (die
, cu
);
17019 cv_type
= make_restrict_type (base_type
);
17020 return set_die_type (die
, cv_type
, cu
);
17023 /* Handle DW_TAG_atomic_type. */
17025 static struct type
*
17026 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17028 struct type
*base_type
, *cv_type
;
17030 base_type
= die_type (die
, cu
);
17032 /* The die_type call above may have already set the type for this DIE. */
17033 cv_type
= get_die_type (die
, cu
);
17037 cv_type
= make_atomic_type (base_type
);
17038 return set_die_type (die
, cv_type
, cu
);
17041 /* Extract all information from a DW_TAG_string_type DIE and add to
17042 the user defined type vector. It isn't really a user defined type,
17043 but it behaves like one, with other DIE's using an AT_user_def_type
17044 attribute to reference it. */
17046 static struct type
*
17047 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17049 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17050 struct gdbarch
*gdbarch
= objfile
->arch ();
17051 struct type
*type
, *range_type
, *index_type
, *char_type
;
17052 struct attribute
*attr
;
17053 struct dynamic_prop prop
;
17054 bool length_is_constant
= true;
17057 /* There are a couple of places where bit sizes might be made use of
17058 when parsing a DW_TAG_string_type, however, no producer that we know
17059 of make use of these. Handling bit sizes that are a multiple of the
17060 byte size is easy enough, but what about other bit sizes? Lets deal
17061 with that problem when we have to. Warn about these attributes being
17062 unsupported, then parse the type and ignore them like we always
17064 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17065 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17067 static bool warning_printed
= false;
17068 if (!warning_printed
)
17070 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17071 "currently supported on DW_TAG_string_type."));
17072 warning_printed
= true;
17076 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17077 if (attr
!= nullptr && !attr
->form_is_constant ())
17079 /* The string length describes the location at which the length of
17080 the string can be found. The size of the length field can be
17081 specified with one of the attributes below. */
17082 struct type
*prop_type
;
17083 struct attribute
*len
17084 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17085 if (len
== nullptr)
17086 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17087 if (len
!= nullptr && len
->form_is_constant ())
17089 /* Pass 0 as the default as we know this attribute is constant
17090 and the default value will not be returned. */
17091 LONGEST sz
= len
->constant_value (0);
17092 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17096 /* If the size is not specified then we assume it is the size of
17097 an address on this target. */
17098 prop_type
= cu
->addr_sized_int_type (true);
17101 /* Convert the attribute into a dynamic property. */
17102 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17105 length_is_constant
= false;
17107 else if (attr
!= nullptr)
17109 /* This DW_AT_string_length just contains the length with no
17110 indirection. There's no need to create a dynamic property in this
17111 case. Pass 0 for the default value as we know it will not be
17112 returned in this case. */
17113 length
= attr
->constant_value (0);
17115 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17117 /* We don't currently support non-constant byte sizes for strings. */
17118 length
= attr
->constant_value (1);
17122 /* Use 1 as a fallback length if we have nothing else. */
17126 index_type
= objfile_type (objfile
)->builtin_int
;
17127 if (length_is_constant
)
17128 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17131 struct dynamic_prop low_bound
;
17133 low_bound
.kind
= PROP_CONST
;
17134 low_bound
.data
.const_val
= 1;
17135 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17137 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17138 type
= create_string_type (NULL
, char_type
, range_type
);
17140 return set_die_type (die
, type
, cu
);
17143 /* Assuming that DIE corresponds to a function, returns nonzero
17144 if the function is prototyped. */
17147 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17149 struct attribute
*attr
;
17151 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17152 if (attr
&& (DW_UNSND (attr
) != 0))
17155 /* The DWARF standard implies that the DW_AT_prototyped attribute
17156 is only meaningful for C, but the concept also extends to other
17157 languages that allow unprototyped functions (Eg: Objective C).
17158 For all other languages, assume that functions are always
17160 if (cu
->language
!= language_c
17161 && cu
->language
!= language_objc
17162 && cu
->language
!= language_opencl
)
17165 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17166 prototyped and unprototyped functions; default to prototyped,
17167 since that is more common in modern code (and RealView warns
17168 about unprototyped functions). */
17169 if (producer_is_realview (cu
->producer
))
17175 /* Handle DIES due to C code like:
17179 int (*funcp)(int a, long l);
17183 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17185 static struct type
*
17186 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17188 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17189 struct type
*type
; /* Type that this function returns. */
17190 struct type
*ftype
; /* Function that returns above type. */
17191 struct attribute
*attr
;
17193 type
= die_type (die
, cu
);
17195 /* The die_type call above may have already set the type for this DIE. */
17196 ftype
= get_die_type (die
, cu
);
17200 ftype
= lookup_function_type (type
);
17202 if (prototyped_function_p (die
, cu
))
17203 TYPE_PROTOTYPED (ftype
) = 1;
17205 /* Store the calling convention in the type if it's available in
17206 the subroutine die. Otherwise set the calling convention to
17207 the default value DW_CC_normal. */
17208 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17209 if (attr
!= nullptr
17210 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17211 TYPE_CALLING_CONVENTION (ftype
)
17212 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17213 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17214 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17216 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17218 /* Record whether the function returns normally to its caller or not
17219 if the DWARF producer set that information. */
17220 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17221 if (attr
&& (DW_UNSND (attr
) != 0))
17222 TYPE_NO_RETURN (ftype
) = 1;
17224 /* We need to add the subroutine type to the die immediately so
17225 we don't infinitely recurse when dealing with parameters
17226 declared as the same subroutine type. */
17227 set_die_type (die
, ftype
, cu
);
17229 if (die
->child
!= NULL
)
17231 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17232 struct die_info
*child_die
;
17233 int nparams
, iparams
;
17235 /* Count the number of parameters.
17236 FIXME: GDB currently ignores vararg functions, but knows about
17237 vararg member functions. */
17239 child_die
= die
->child
;
17240 while (child_die
&& child_die
->tag
)
17242 if (child_die
->tag
== DW_TAG_formal_parameter
)
17244 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17245 TYPE_VARARGS (ftype
) = 1;
17246 child_die
= child_die
->sibling
;
17249 /* Allocate storage for parameters and fill them in. */
17250 ftype
->set_num_fields (nparams
);
17252 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17254 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17255 even if we error out during the parameters reading below. */
17256 for (iparams
= 0; iparams
< nparams
; iparams
++)
17257 ftype
->field (iparams
).set_type (void_type
);
17260 child_die
= die
->child
;
17261 while (child_die
&& child_die
->tag
)
17263 if (child_die
->tag
== DW_TAG_formal_parameter
)
17265 struct type
*arg_type
;
17267 /* DWARF version 2 has no clean way to discern C++
17268 static and non-static member functions. G++ helps
17269 GDB by marking the first parameter for non-static
17270 member functions (which is the this pointer) as
17271 artificial. We pass this information to
17272 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17274 DWARF version 3 added DW_AT_object_pointer, which GCC
17275 4.5 does not yet generate. */
17276 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17277 if (attr
!= nullptr)
17278 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17280 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17281 arg_type
= die_type (child_die
, cu
);
17283 /* RealView does not mark THIS as const, which the testsuite
17284 expects. GCC marks THIS as const in method definitions,
17285 but not in the class specifications (GCC PR 43053). */
17286 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17287 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17290 struct dwarf2_cu
*arg_cu
= cu
;
17291 const char *name
= dwarf2_name (child_die
, cu
);
17293 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17294 if (attr
!= nullptr)
17296 /* If the compiler emits this, use it. */
17297 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17300 else if (name
&& strcmp (name
, "this") == 0)
17301 /* Function definitions will have the argument names. */
17303 else if (name
== NULL
&& iparams
== 0)
17304 /* Declarations may not have the names, so like
17305 elsewhere in GDB, assume an artificial first
17306 argument is "this". */
17310 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17314 ftype
->field (iparams
).set_type (arg_type
);
17317 child_die
= child_die
->sibling
;
17324 static struct type
*
17325 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17327 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17328 const char *name
= NULL
;
17329 struct type
*this_type
, *target_type
;
17331 name
= dwarf2_full_name (NULL
, die
, cu
);
17332 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17333 TYPE_TARGET_STUB (this_type
) = 1;
17334 set_die_type (die
, this_type
, cu
);
17335 target_type
= die_type (die
, cu
);
17336 if (target_type
!= this_type
)
17337 TYPE_TARGET_TYPE (this_type
) = target_type
;
17340 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17341 spec and cause infinite loops in GDB. */
17342 complaint (_("Self-referential DW_TAG_typedef "
17343 "- DIE at %s [in module %s]"),
17344 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17345 TYPE_TARGET_TYPE (this_type
) = NULL
;
17349 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17350 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17351 Handle these by just returning the target type, rather than
17352 constructing an anonymous typedef type and trying to handle this
17354 set_die_type (die
, target_type
, cu
);
17355 return target_type
;
17360 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17361 (which may be different from NAME) to the architecture back-end to allow
17362 it to guess the correct format if necessary. */
17364 static struct type
*
17365 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17366 const char *name_hint
, enum bfd_endian byte_order
)
17368 struct gdbarch
*gdbarch
= objfile
->arch ();
17369 const struct floatformat
**format
;
17372 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17374 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17376 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17381 /* Allocate an integer type of size BITS and name NAME. */
17383 static struct type
*
17384 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17385 int bits
, int unsigned_p
, const char *name
)
17389 /* Versions of Intel's C Compiler generate an integer type called "void"
17390 instead of using DW_TAG_unspecified_type. This has been seen on
17391 at least versions 14, 17, and 18. */
17392 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17393 && strcmp (name
, "void") == 0)
17394 type
= objfile_type (objfile
)->builtin_void
;
17396 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17401 /* Initialise and return a floating point type of size BITS suitable for
17402 use as a component of a complex number. The NAME_HINT is passed through
17403 when initialising the floating point type and is the name of the complex
17406 As DWARF doesn't currently provide an explicit name for the components
17407 of a complex number, but it can be helpful to have these components
17408 named, we try to select a suitable name based on the size of the
17410 static struct type
*
17411 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17412 struct objfile
*objfile
,
17413 int bits
, const char *name_hint
,
17414 enum bfd_endian byte_order
)
17416 gdbarch
*gdbarch
= objfile
->arch ();
17417 struct type
*tt
= nullptr;
17419 /* Try to find a suitable floating point builtin type of size BITS.
17420 We're going to use the name of this type as the name for the complex
17421 target type that we are about to create. */
17422 switch (cu
->language
)
17424 case language_fortran
:
17428 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17431 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17433 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17435 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17443 tt
= builtin_type (gdbarch
)->builtin_float
;
17446 tt
= builtin_type (gdbarch
)->builtin_double
;
17448 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17450 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17456 /* If the type we found doesn't match the size we were looking for, then
17457 pretend we didn't find a type at all, the complex target type we
17458 create will then be nameless. */
17459 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17462 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17463 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17466 /* Find a representation of a given base type and install
17467 it in the TYPE field of the die. */
17469 static struct type
*
17470 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17472 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17474 struct attribute
*attr
;
17475 int encoding
= 0, bits
= 0;
17479 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17480 if (attr
!= nullptr)
17481 encoding
= DW_UNSND (attr
);
17482 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17483 if (attr
!= nullptr)
17484 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17485 name
= dwarf2_name (die
, cu
);
17487 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17489 arch
= objfile
->arch ();
17490 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17492 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17495 int endianity
= DW_UNSND (attr
);
17500 byte_order
= BFD_ENDIAN_BIG
;
17502 case DW_END_little
:
17503 byte_order
= BFD_ENDIAN_LITTLE
;
17506 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17513 case DW_ATE_address
:
17514 /* Turn DW_ATE_address into a void * pointer. */
17515 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17516 type
= init_pointer_type (objfile
, bits
, name
, type
);
17518 case DW_ATE_boolean
:
17519 type
= init_boolean_type (objfile
, bits
, 1, name
);
17521 case DW_ATE_complex_float
:
17522 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17524 if (type
->code () == TYPE_CODE_ERROR
)
17526 if (name
== nullptr)
17528 struct obstack
*obstack
17529 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17530 name
= obconcat (obstack
, "_Complex ", type
->name (),
17533 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17536 type
= init_complex_type (name
, type
);
17538 case DW_ATE_decimal_float
:
17539 type
= init_decfloat_type (objfile
, bits
, name
);
17542 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17544 case DW_ATE_signed
:
17545 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17547 case DW_ATE_unsigned
:
17548 if (cu
->language
== language_fortran
17550 && startswith (name
, "character("))
17551 type
= init_character_type (objfile
, bits
, 1, name
);
17553 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17555 case DW_ATE_signed_char
:
17556 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17557 || cu
->language
== language_pascal
17558 || cu
->language
== language_fortran
)
17559 type
= init_character_type (objfile
, bits
, 0, name
);
17561 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17563 case DW_ATE_unsigned_char
:
17564 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17565 || cu
->language
== language_pascal
17566 || cu
->language
== language_fortran
17567 || cu
->language
== language_rust
)
17568 type
= init_character_type (objfile
, bits
, 1, name
);
17570 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17575 type
= builtin_type (arch
)->builtin_char16
;
17576 else if (bits
== 32)
17577 type
= builtin_type (arch
)->builtin_char32
;
17580 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17582 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17584 return set_die_type (die
, type
, cu
);
17589 complaint (_("unsupported DW_AT_encoding: '%s'"),
17590 dwarf_type_encoding_name (encoding
));
17591 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17595 if (name
&& strcmp (name
, "char") == 0)
17596 TYPE_NOSIGN (type
) = 1;
17598 maybe_set_alignment (cu
, die
, type
);
17600 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17602 return set_die_type (die
, type
, cu
);
17605 /* Parse dwarf attribute if it's a block, reference or constant and put the
17606 resulting value of the attribute into struct bound_prop.
17607 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17610 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17611 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17612 struct type
*default_type
)
17614 struct dwarf2_property_baton
*baton
;
17615 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17616 struct objfile
*objfile
= per_objfile
->objfile
;
17617 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17619 gdb_assert (default_type
!= NULL
);
17621 if (attr
== NULL
|| prop
== NULL
)
17624 if (attr
->form_is_block ())
17626 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17627 baton
->property_type
= default_type
;
17628 baton
->locexpr
.per_cu
= cu
->per_cu
;
17629 baton
->locexpr
.per_objfile
= per_objfile
;
17630 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17631 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17632 switch (attr
->name
)
17634 case DW_AT_string_length
:
17635 baton
->locexpr
.is_reference
= true;
17638 baton
->locexpr
.is_reference
= false;
17641 prop
->data
.baton
= baton
;
17642 prop
->kind
= PROP_LOCEXPR
;
17643 gdb_assert (prop
->data
.baton
!= NULL
);
17645 else if (attr
->form_is_ref ())
17647 struct dwarf2_cu
*target_cu
= cu
;
17648 struct die_info
*target_die
;
17649 struct attribute
*target_attr
;
17651 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17652 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17653 if (target_attr
== NULL
)
17654 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17656 if (target_attr
== NULL
)
17659 switch (target_attr
->name
)
17661 case DW_AT_location
:
17662 if (target_attr
->form_is_section_offset ())
17664 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17665 baton
->property_type
= die_type (target_die
, target_cu
);
17666 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17667 prop
->data
.baton
= baton
;
17668 prop
->kind
= PROP_LOCLIST
;
17669 gdb_assert (prop
->data
.baton
!= NULL
);
17671 else if (target_attr
->form_is_block ())
17673 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17674 baton
->property_type
= die_type (target_die
, target_cu
);
17675 baton
->locexpr
.per_cu
= cu
->per_cu
;
17676 baton
->locexpr
.per_objfile
= per_objfile
;
17677 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17678 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17679 baton
->locexpr
.is_reference
= true;
17680 prop
->data
.baton
= baton
;
17681 prop
->kind
= PROP_LOCEXPR
;
17682 gdb_assert (prop
->data
.baton
!= NULL
);
17686 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17687 "dynamic property");
17691 case DW_AT_data_member_location
:
17695 if (!handle_data_member_location (target_die
, target_cu
,
17699 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17700 baton
->property_type
= read_type_die (target_die
->parent
,
17702 baton
->offset_info
.offset
= offset
;
17703 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17704 prop
->data
.baton
= baton
;
17705 prop
->kind
= PROP_ADDR_OFFSET
;
17710 else if (attr
->form_is_constant ())
17712 prop
->data
.const_val
= attr
->constant_value (0);
17713 prop
->kind
= PROP_CONST
;
17717 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17718 dwarf2_name (die
, cu
));
17728 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17730 struct type
*int_type
;
17732 /* Helper macro to examine the various builtin types. */
17733 #define TRY_TYPE(F) \
17734 int_type = (unsigned_p \
17735 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17736 : objfile_type (objfile)->builtin_ ## F); \
17737 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17744 TRY_TYPE (long_long
);
17748 gdb_assert_not_reached ("unable to find suitable integer type");
17754 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17756 int addr_size
= this->per_cu
->addr_size ();
17757 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17760 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17761 present (which is valid) then compute the default type based on the
17762 compilation units address size. */
17764 static struct type
*
17765 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17767 struct type
*index_type
= die_type (die
, cu
);
17769 /* Dwarf-2 specifications explicitly allows to create subrange types
17770 without specifying a base type.
17771 In that case, the base type must be set to the type of
17772 the lower bound, upper bound or count, in that order, if any of these
17773 three attributes references an object that has a type.
17774 If no base type is found, the Dwarf-2 specifications say that
17775 a signed integer type of size equal to the size of an address should
17777 For the following C code: `extern char gdb_int [];'
17778 GCC produces an empty range DIE.
17779 FIXME: muller/2010-05-28: Possible references to object for low bound,
17780 high bound or count are not yet handled by this code. */
17781 if (index_type
->code () == TYPE_CODE_VOID
)
17782 index_type
= cu
->addr_sized_int_type (false);
17787 /* Read the given DW_AT_subrange DIE. */
17789 static struct type
*
17790 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17792 struct type
*base_type
, *orig_base_type
;
17793 struct type
*range_type
;
17794 struct attribute
*attr
;
17795 struct dynamic_prop low
, high
;
17796 int low_default_is_valid
;
17797 int high_bound_is_count
= 0;
17799 ULONGEST negative_mask
;
17801 orig_base_type
= read_subrange_index_type (die
, cu
);
17803 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17804 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17805 creating the range type, but we use the result of check_typedef
17806 when examining properties of the type. */
17807 base_type
= check_typedef (orig_base_type
);
17809 /* The die_type call above may have already set the type for this DIE. */
17810 range_type
= get_die_type (die
, cu
);
17814 low
.kind
= PROP_CONST
;
17815 high
.kind
= PROP_CONST
;
17816 high
.data
.const_val
= 0;
17818 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17819 omitting DW_AT_lower_bound. */
17820 switch (cu
->language
)
17823 case language_cplus
:
17824 low
.data
.const_val
= 0;
17825 low_default_is_valid
= 1;
17827 case language_fortran
:
17828 low
.data
.const_val
= 1;
17829 low_default_is_valid
= 1;
17832 case language_objc
:
17833 case language_rust
:
17834 low
.data
.const_val
= 0;
17835 low_default_is_valid
= (cu
->header
.version
>= 4);
17839 case language_pascal
:
17840 low
.data
.const_val
= 1;
17841 low_default_is_valid
= (cu
->header
.version
>= 4);
17844 low
.data
.const_val
= 0;
17845 low_default_is_valid
= 0;
17849 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17850 if (attr
!= nullptr)
17851 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17852 else if (!low_default_is_valid
)
17853 complaint (_("Missing DW_AT_lower_bound "
17854 "- DIE at %s [in module %s]"),
17855 sect_offset_str (die
->sect_off
),
17856 objfile_name (cu
->per_objfile
->objfile
));
17858 struct attribute
*attr_ub
, *attr_count
;
17859 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17860 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17862 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17863 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17865 /* If bounds are constant do the final calculation here. */
17866 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17867 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17869 high_bound_is_count
= 1;
17873 if (attr_ub
!= NULL
)
17874 complaint (_("Unresolved DW_AT_upper_bound "
17875 "- DIE at %s [in module %s]"),
17876 sect_offset_str (die
->sect_off
),
17877 objfile_name (cu
->per_objfile
->objfile
));
17878 if (attr_count
!= NULL
)
17879 complaint (_("Unresolved DW_AT_count "
17880 "- DIE at %s [in module %s]"),
17881 sect_offset_str (die
->sect_off
),
17882 objfile_name (cu
->per_objfile
->objfile
));
17887 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17888 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17889 bias
= bias_attr
->constant_value (0);
17891 /* Normally, the DWARF producers are expected to use a signed
17892 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17893 But this is unfortunately not always the case, as witnessed
17894 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17895 is used instead. To work around that ambiguity, we treat
17896 the bounds as signed, and thus sign-extend their values, when
17897 the base type is signed. */
17899 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17900 if (low
.kind
== PROP_CONST
17901 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17902 low
.data
.const_val
|= negative_mask
;
17903 if (high
.kind
== PROP_CONST
17904 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17905 high
.data
.const_val
|= negative_mask
;
17907 /* Check for bit and byte strides. */
17908 struct dynamic_prop byte_stride_prop
;
17909 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17910 if (attr_byte_stride
!= nullptr)
17912 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17913 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17917 struct dynamic_prop bit_stride_prop
;
17918 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17919 if (attr_bit_stride
!= nullptr)
17921 /* It only makes sense to have either a bit or byte stride. */
17922 if (attr_byte_stride
!= nullptr)
17924 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17925 "- DIE at %s [in module %s]"),
17926 sect_offset_str (die
->sect_off
),
17927 objfile_name (cu
->per_objfile
->objfile
));
17928 attr_bit_stride
= nullptr;
17932 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17933 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17938 if (attr_byte_stride
!= nullptr
17939 || attr_bit_stride
!= nullptr)
17941 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17942 struct dynamic_prop
*stride
17943 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17946 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17947 &high
, bias
, stride
, byte_stride_p
);
17950 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17952 if (high_bound_is_count
)
17953 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17955 /* Ada expects an empty array on no boundary attributes. */
17956 if (attr
== NULL
&& cu
->language
!= language_ada
)
17957 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17959 name
= dwarf2_name (die
, cu
);
17961 range_type
->set_name (name
);
17963 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17964 if (attr
!= nullptr)
17965 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17967 maybe_set_alignment (cu
, die
, range_type
);
17969 set_die_type (die
, range_type
, cu
);
17971 /* set_die_type should be already done. */
17972 set_descriptive_type (range_type
, die
, cu
);
17977 static struct type
*
17978 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17982 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17983 type
->set_name (dwarf2_name (die
, cu
));
17985 /* In Ada, an unspecified type is typically used when the description
17986 of the type is deferred to a different unit. When encountering
17987 such a type, we treat it as a stub, and try to resolve it later on,
17989 if (cu
->language
== language_ada
)
17990 TYPE_STUB (type
) = 1;
17992 return set_die_type (die
, type
, cu
);
17995 /* Read a single die and all its descendents. Set the die's sibling
17996 field to NULL; set other fields in the die correctly, and set all
17997 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17998 location of the info_ptr after reading all of those dies. PARENT
17999 is the parent of the die in question. */
18001 static struct die_info
*
18002 read_die_and_children (const struct die_reader_specs
*reader
,
18003 const gdb_byte
*info_ptr
,
18004 const gdb_byte
**new_info_ptr
,
18005 struct die_info
*parent
)
18007 struct die_info
*die
;
18008 const gdb_byte
*cur_ptr
;
18010 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18013 *new_info_ptr
= cur_ptr
;
18016 store_in_ref_table (die
, reader
->cu
);
18018 if (die
->has_children
)
18019 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18023 *new_info_ptr
= cur_ptr
;
18026 die
->sibling
= NULL
;
18027 die
->parent
= parent
;
18031 /* Read a die, all of its descendents, and all of its siblings; set
18032 all of the fields of all of the dies correctly. Arguments are as
18033 in read_die_and_children. */
18035 static struct die_info
*
18036 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18037 const gdb_byte
*info_ptr
,
18038 const gdb_byte
**new_info_ptr
,
18039 struct die_info
*parent
)
18041 struct die_info
*first_die
, *last_sibling
;
18042 const gdb_byte
*cur_ptr
;
18044 cur_ptr
= info_ptr
;
18045 first_die
= last_sibling
= NULL
;
18049 struct die_info
*die
18050 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18054 *new_info_ptr
= cur_ptr
;
18061 last_sibling
->sibling
= die
;
18063 last_sibling
= die
;
18067 /* Read a die, all of its descendents, and all of its siblings; set
18068 all of the fields of all of the dies correctly. Arguments are as
18069 in read_die_and_children.
18070 This the main entry point for reading a DIE and all its children. */
18072 static struct die_info
*
18073 read_die_and_siblings (const struct die_reader_specs
*reader
,
18074 const gdb_byte
*info_ptr
,
18075 const gdb_byte
**new_info_ptr
,
18076 struct die_info
*parent
)
18078 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18079 new_info_ptr
, parent
);
18081 if (dwarf_die_debug
)
18083 fprintf_unfiltered (gdb_stdlog
,
18084 "Read die from %s@0x%x of %s:\n",
18085 reader
->die_section
->get_name (),
18086 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18087 bfd_get_filename (reader
->abfd
));
18088 dump_die (die
, dwarf_die_debug
);
18094 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18096 The caller is responsible for filling in the extra attributes
18097 and updating (*DIEP)->num_attrs.
18098 Set DIEP to point to a newly allocated die with its information,
18099 except for its child, sibling, and parent fields. */
18101 static const gdb_byte
*
18102 read_full_die_1 (const struct die_reader_specs
*reader
,
18103 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18104 int num_extra_attrs
)
18106 unsigned int abbrev_number
, bytes_read
, i
;
18107 struct abbrev_info
*abbrev
;
18108 struct die_info
*die
;
18109 struct dwarf2_cu
*cu
= reader
->cu
;
18110 bfd
*abfd
= reader
->abfd
;
18112 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18113 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18114 info_ptr
+= bytes_read
;
18115 if (!abbrev_number
)
18121 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18123 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18125 bfd_get_filename (abfd
));
18127 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18128 die
->sect_off
= sect_off
;
18129 die
->tag
= abbrev
->tag
;
18130 die
->abbrev
= abbrev_number
;
18131 die
->has_children
= abbrev
->has_children
;
18133 /* Make the result usable.
18134 The caller needs to update num_attrs after adding the extra
18136 die
->num_attrs
= abbrev
->num_attrs
;
18138 std::vector
<int> indexes_that_need_reprocess
;
18139 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18141 bool need_reprocess
;
18143 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18144 info_ptr
, &need_reprocess
);
18145 if (need_reprocess
)
18146 indexes_that_need_reprocess
.push_back (i
);
18149 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18150 if (attr
!= nullptr)
18151 cu
->str_offsets_base
= DW_UNSND (attr
);
18153 attr
= die
->attr (DW_AT_loclists_base
);
18154 if (attr
!= nullptr)
18155 cu
->loclist_base
= DW_UNSND (attr
);
18157 auto maybe_addr_base
= die
->addr_base ();
18158 if (maybe_addr_base
.has_value ())
18159 cu
->addr_base
= *maybe_addr_base
;
18160 for (int index
: indexes_that_need_reprocess
)
18161 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18166 /* Read a die and all its attributes.
18167 Set DIEP to point to a newly allocated die with its information,
18168 except for its child, sibling, and parent fields. */
18170 static const gdb_byte
*
18171 read_full_die (const struct die_reader_specs
*reader
,
18172 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18174 const gdb_byte
*result
;
18176 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18178 if (dwarf_die_debug
)
18180 fprintf_unfiltered (gdb_stdlog
,
18181 "Read die from %s@0x%x of %s:\n",
18182 reader
->die_section
->get_name (),
18183 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18184 bfd_get_filename (reader
->abfd
));
18185 dump_die (*diep
, dwarf_die_debug
);
18192 /* Returns nonzero if TAG represents a type that we might generate a partial
18196 is_type_tag_for_partial (int tag
)
18201 /* Some types that would be reasonable to generate partial symbols for,
18202 that we don't at present. */
18203 case DW_TAG_array_type
:
18204 case DW_TAG_file_type
:
18205 case DW_TAG_ptr_to_member_type
:
18206 case DW_TAG_set_type
:
18207 case DW_TAG_string_type
:
18208 case DW_TAG_subroutine_type
:
18210 case DW_TAG_base_type
:
18211 case DW_TAG_class_type
:
18212 case DW_TAG_interface_type
:
18213 case DW_TAG_enumeration_type
:
18214 case DW_TAG_structure_type
:
18215 case DW_TAG_subrange_type
:
18216 case DW_TAG_typedef
:
18217 case DW_TAG_union_type
:
18224 /* Load all DIEs that are interesting for partial symbols into memory. */
18226 static struct partial_die_info
*
18227 load_partial_dies (const struct die_reader_specs
*reader
,
18228 const gdb_byte
*info_ptr
, int building_psymtab
)
18230 struct dwarf2_cu
*cu
= reader
->cu
;
18231 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18232 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18233 unsigned int bytes_read
;
18234 unsigned int load_all
= 0;
18235 int nesting_level
= 1;
18240 gdb_assert (cu
->per_cu
!= NULL
);
18241 if (cu
->per_cu
->load_all_dies
)
18245 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18249 &cu
->comp_unit_obstack
,
18250 hashtab_obstack_allocate
,
18251 dummy_obstack_deallocate
);
18255 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18257 /* A NULL abbrev means the end of a series of children. */
18258 if (abbrev
== NULL
)
18260 if (--nesting_level
== 0)
18263 info_ptr
+= bytes_read
;
18264 last_die
= parent_die
;
18265 parent_die
= parent_die
->die_parent
;
18269 /* Check for template arguments. We never save these; if
18270 they're seen, we just mark the parent, and go on our way. */
18271 if (parent_die
!= NULL
18272 && cu
->language
== language_cplus
18273 && (abbrev
->tag
== DW_TAG_template_type_param
18274 || abbrev
->tag
== DW_TAG_template_value_param
))
18276 parent_die
->has_template_arguments
= 1;
18280 /* We don't need a partial DIE for the template argument. */
18281 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18286 /* We only recurse into c++ subprograms looking for template arguments.
18287 Skip their other children. */
18289 && cu
->language
== language_cplus
18290 && parent_die
!= NULL
18291 && parent_die
->tag
== DW_TAG_subprogram
18292 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18294 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18298 /* Check whether this DIE is interesting enough to save. Normally
18299 we would not be interested in members here, but there may be
18300 later variables referencing them via DW_AT_specification (for
18301 static members). */
18303 && !is_type_tag_for_partial (abbrev
->tag
)
18304 && abbrev
->tag
!= DW_TAG_constant
18305 && abbrev
->tag
!= DW_TAG_enumerator
18306 && abbrev
->tag
!= DW_TAG_subprogram
18307 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18308 && abbrev
->tag
!= DW_TAG_lexical_block
18309 && abbrev
->tag
!= DW_TAG_variable
18310 && abbrev
->tag
!= DW_TAG_namespace
18311 && abbrev
->tag
!= DW_TAG_module
18312 && abbrev
->tag
!= DW_TAG_member
18313 && abbrev
->tag
!= DW_TAG_imported_unit
18314 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18316 /* Otherwise we skip to the next sibling, if any. */
18317 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18321 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18324 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18326 /* This two-pass algorithm for processing partial symbols has a
18327 high cost in cache pressure. Thus, handle some simple cases
18328 here which cover the majority of C partial symbols. DIEs
18329 which neither have specification tags in them, nor could have
18330 specification tags elsewhere pointing at them, can simply be
18331 processed and discarded.
18333 This segment is also optional; scan_partial_symbols and
18334 add_partial_symbol will handle these DIEs if we chain
18335 them in normally. When compilers which do not emit large
18336 quantities of duplicate debug information are more common,
18337 this code can probably be removed. */
18339 /* Any complete simple types at the top level (pretty much all
18340 of them, for a language without namespaces), can be processed
18342 if (parent_die
== NULL
18343 && pdi
.has_specification
== 0
18344 && pdi
.is_declaration
== 0
18345 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18346 || pdi
.tag
== DW_TAG_base_type
18347 || pdi
.tag
== DW_TAG_subrange_type
))
18349 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18350 add_partial_symbol (&pdi
, cu
);
18352 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18356 /* The exception for DW_TAG_typedef with has_children above is
18357 a workaround of GCC PR debug/47510. In the case of this complaint
18358 type_name_or_error will error on such types later.
18360 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18361 it could not find the child DIEs referenced later, this is checked
18362 above. In correct DWARF DW_TAG_typedef should have no children. */
18364 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18365 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18366 "- DIE at %s [in module %s]"),
18367 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18369 /* If we're at the second level, and we're an enumerator, and
18370 our parent has no specification (meaning possibly lives in a
18371 namespace elsewhere), then we can add the partial symbol now
18372 instead of queueing it. */
18373 if (pdi
.tag
== DW_TAG_enumerator
18374 && parent_die
!= NULL
18375 && parent_die
->die_parent
== NULL
18376 && parent_die
->tag
== DW_TAG_enumeration_type
18377 && parent_die
->has_specification
== 0)
18379 if (pdi
.raw_name
== NULL
)
18380 complaint (_("malformed enumerator DIE ignored"));
18381 else if (building_psymtab
)
18382 add_partial_symbol (&pdi
, cu
);
18384 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18388 struct partial_die_info
*part_die
18389 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18391 /* We'll save this DIE so link it in. */
18392 part_die
->die_parent
= parent_die
;
18393 part_die
->die_sibling
= NULL
;
18394 part_die
->die_child
= NULL
;
18396 if (last_die
&& last_die
== parent_die
)
18397 last_die
->die_child
= part_die
;
18399 last_die
->die_sibling
= part_die
;
18401 last_die
= part_die
;
18403 if (first_die
== NULL
)
18404 first_die
= part_die
;
18406 /* Maybe add the DIE to the hash table. Not all DIEs that we
18407 find interesting need to be in the hash table, because we
18408 also have the parent/sibling/child chains; only those that we
18409 might refer to by offset later during partial symbol reading.
18411 For now this means things that might have be the target of a
18412 DW_AT_specification, DW_AT_abstract_origin, or
18413 DW_AT_extension. DW_AT_extension will refer only to
18414 namespaces; DW_AT_abstract_origin refers to functions (and
18415 many things under the function DIE, but we do not recurse
18416 into function DIEs during partial symbol reading) and
18417 possibly variables as well; DW_AT_specification refers to
18418 declarations. Declarations ought to have the DW_AT_declaration
18419 flag. It happens that GCC forgets to put it in sometimes, but
18420 only for functions, not for types.
18422 Adding more things than necessary to the hash table is harmless
18423 except for the performance cost. Adding too few will result in
18424 wasted time in find_partial_die, when we reread the compilation
18425 unit with load_all_dies set. */
18428 || abbrev
->tag
== DW_TAG_constant
18429 || abbrev
->tag
== DW_TAG_subprogram
18430 || abbrev
->tag
== DW_TAG_variable
18431 || abbrev
->tag
== DW_TAG_namespace
18432 || part_die
->is_declaration
)
18436 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18437 to_underlying (part_die
->sect_off
),
18442 /* For some DIEs we want to follow their children (if any). For C
18443 we have no reason to follow the children of structures; for other
18444 languages we have to, so that we can get at method physnames
18445 to infer fully qualified class names, for DW_AT_specification,
18446 and for C++ template arguments. For C++, we also look one level
18447 inside functions to find template arguments (if the name of the
18448 function does not already contain the template arguments).
18450 For Ada and Fortran, we need to scan the children of subprograms
18451 and lexical blocks as well because these languages allow the
18452 definition of nested entities that could be interesting for the
18453 debugger, such as nested subprograms for instance. */
18454 if (last_die
->has_children
18456 || last_die
->tag
== DW_TAG_namespace
18457 || last_die
->tag
== DW_TAG_module
18458 || last_die
->tag
== DW_TAG_enumeration_type
18459 || (cu
->language
== language_cplus
18460 && last_die
->tag
== DW_TAG_subprogram
18461 && (last_die
->raw_name
== NULL
18462 || strchr (last_die
->raw_name
, '<') == NULL
))
18463 || (cu
->language
!= language_c
18464 && (last_die
->tag
== DW_TAG_class_type
18465 || last_die
->tag
== DW_TAG_interface_type
18466 || last_die
->tag
== DW_TAG_structure_type
18467 || last_die
->tag
== DW_TAG_union_type
))
18468 || ((cu
->language
== language_ada
18469 || cu
->language
== language_fortran
)
18470 && (last_die
->tag
== DW_TAG_subprogram
18471 || last_die
->tag
== DW_TAG_lexical_block
))))
18474 parent_die
= last_die
;
18478 /* Otherwise we skip to the next sibling, if any. */
18479 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18481 /* Back to the top, do it again. */
18485 partial_die_info::partial_die_info (sect_offset sect_off_
,
18486 struct abbrev_info
*abbrev
)
18487 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18491 /* See class definition. */
18494 partial_die_info::name (dwarf2_cu
*cu
)
18496 if (!canonical_name
&& raw_name
!= nullptr)
18498 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18499 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
18500 canonical_name
= 1;
18506 /* Read a minimal amount of information into the minimal die structure.
18507 INFO_PTR should point just after the initial uleb128 of a DIE. */
18510 partial_die_info::read (const struct die_reader_specs
*reader
,
18511 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18513 struct dwarf2_cu
*cu
= reader
->cu
;
18514 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18516 int has_low_pc_attr
= 0;
18517 int has_high_pc_attr
= 0;
18518 int high_pc_relative
= 0;
18520 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18523 bool need_reprocess
;
18524 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18525 info_ptr
, &need_reprocess
);
18526 /* String and address offsets that need to do the reprocessing have
18527 already been read at this point, so there is no need to wait until
18528 the loop terminates to do the reprocessing. */
18529 if (need_reprocess
)
18530 read_attribute_reprocess (reader
, &attr
);
18531 /* Store the data if it is of an attribute we want to keep in a
18532 partial symbol table. */
18538 case DW_TAG_compile_unit
:
18539 case DW_TAG_partial_unit
:
18540 case DW_TAG_type_unit
:
18541 /* Compilation units have a DW_AT_name that is a filename, not
18542 a source language identifier. */
18543 case DW_TAG_enumeration_type
:
18544 case DW_TAG_enumerator
:
18545 /* These tags always have simple identifiers already; no need
18546 to canonicalize them. */
18547 canonical_name
= 1;
18548 raw_name
= DW_STRING (&attr
);
18551 canonical_name
= 0;
18552 raw_name
= DW_STRING (&attr
);
18556 case DW_AT_linkage_name
:
18557 case DW_AT_MIPS_linkage_name
:
18558 /* Note that both forms of linkage name might appear. We
18559 assume they will be the same, and we only store the last
18561 linkage_name
= attr
.value_as_string ();
18562 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18563 See https://github.com/rust-lang/rust/issues/32925. */
18564 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18565 && strchr (linkage_name
, '{') != NULL
)
18566 linkage_name
= NULL
;
18569 has_low_pc_attr
= 1;
18570 lowpc
= attr
.value_as_address ();
18572 case DW_AT_high_pc
:
18573 has_high_pc_attr
= 1;
18574 highpc
= attr
.value_as_address ();
18575 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18576 high_pc_relative
= 1;
18578 case DW_AT_location
:
18579 /* Support the .debug_loc offsets. */
18580 if (attr
.form_is_block ())
18582 d
.locdesc
= DW_BLOCK (&attr
);
18584 else if (attr
.form_is_section_offset ())
18586 dwarf2_complex_location_expr_complaint ();
18590 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18591 "partial symbol information");
18594 case DW_AT_external
:
18595 is_external
= DW_UNSND (&attr
);
18597 case DW_AT_declaration
:
18598 is_declaration
= DW_UNSND (&attr
);
18603 case DW_AT_abstract_origin
:
18604 case DW_AT_specification
:
18605 case DW_AT_extension
:
18606 has_specification
= 1;
18607 spec_offset
= attr
.get_ref_die_offset ();
18608 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18609 || cu
->per_cu
->is_dwz
);
18611 case DW_AT_sibling
:
18612 /* Ignore absolute siblings, they might point outside of
18613 the current compile unit. */
18614 if (attr
.form
== DW_FORM_ref_addr
)
18615 complaint (_("ignoring absolute DW_AT_sibling"));
18618 const gdb_byte
*buffer
= reader
->buffer
;
18619 sect_offset off
= attr
.get_ref_die_offset ();
18620 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18622 if (sibling_ptr
< info_ptr
)
18623 complaint (_("DW_AT_sibling points backwards"));
18624 else if (sibling_ptr
> reader
->buffer_end
)
18625 reader
->die_section
->overflow_complaint ();
18627 sibling
= sibling_ptr
;
18630 case DW_AT_byte_size
:
18633 case DW_AT_const_value
:
18634 has_const_value
= 1;
18636 case DW_AT_calling_convention
:
18637 /* DWARF doesn't provide a way to identify a program's source-level
18638 entry point. DW_AT_calling_convention attributes are only meant
18639 to describe functions' calling conventions.
18641 However, because it's a necessary piece of information in
18642 Fortran, and before DWARF 4 DW_CC_program was the only
18643 piece of debugging information whose definition refers to
18644 a 'main program' at all, several compilers marked Fortran
18645 main programs with DW_CC_program --- even when those
18646 functions use the standard calling conventions.
18648 Although DWARF now specifies a way to provide this
18649 information, we support this practice for backward
18651 if (DW_UNSND (&attr
) == DW_CC_program
18652 && cu
->language
== language_fortran
)
18653 main_subprogram
= 1;
18656 if (DW_UNSND (&attr
) == DW_INL_inlined
18657 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18658 may_be_inlined
= 1;
18662 if (tag
== DW_TAG_imported_unit
)
18664 d
.sect_off
= attr
.get_ref_die_offset ();
18665 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18666 || cu
->per_cu
->is_dwz
);
18670 case DW_AT_main_subprogram
:
18671 main_subprogram
= DW_UNSND (&attr
);
18676 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18677 but that requires a full DIE, so instead we just
18679 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18680 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18681 + (need_ranges_base
18685 /* Value of the DW_AT_ranges attribute is the offset in the
18686 .debug_ranges section. */
18687 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18698 /* For Ada, if both the name and the linkage name appear, we prefer
18699 the latter. This lets "catch exception" work better, regardless
18700 of the order in which the name and linkage name were emitted.
18701 Really, though, this is just a workaround for the fact that gdb
18702 doesn't store both the name and the linkage name. */
18703 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18704 raw_name
= linkage_name
;
18706 if (high_pc_relative
)
18709 if (has_low_pc_attr
&& has_high_pc_attr
)
18711 /* When using the GNU linker, .gnu.linkonce. sections are used to
18712 eliminate duplicate copies of functions and vtables and such.
18713 The linker will arbitrarily choose one and discard the others.
18714 The AT_*_pc values for such functions refer to local labels in
18715 these sections. If the section from that file was discarded, the
18716 labels are not in the output, so the relocs get a value of 0.
18717 If this is a discarded function, mark the pc bounds as invalid,
18718 so that GDB will ignore it. */
18719 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
18721 struct objfile
*objfile
= per_objfile
->objfile
;
18722 struct gdbarch
*gdbarch
= objfile
->arch ();
18724 complaint (_("DW_AT_low_pc %s is zero "
18725 "for DIE at %s [in module %s]"),
18726 paddress (gdbarch
, lowpc
),
18727 sect_offset_str (sect_off
),
18728 objfile_name (objfile
));
18730 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18731 else if (lowpc
>= highpc
)
18733 struct objfile
*objfile
= per_objfile
->objfile
;
18734 struct gdbarch
*gdbarch
= objfile
->arch ();
18736 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18737 "for DIE at %s [in module %s]"),
18738 paddress (gdbarch
, lowpc
),
18739 paddress (gdbarch
, highpc
),
18740 sect_offset_str (sect_off
),
18741 objfile_name (objfile
));
18750 /* Find a cached partial DIE at OFFSET in CU. */
18752 struct partial_die_info
*
18753 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18755 struct partial_die_info
*lookup_die
= NULL
;
18756 struct partial_die_info
part_die (sect_off
);
18758 lookup_die
= ((struct partial_die_info
*)
18759 htab_find_with_hash (partial_dies
, &part_die
,
18760 to_underlying (sect_off
)));
18765 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18766 except in the case of .debug_types DIEs which do not reference
18767 outside their CU (they do however referencing other types via
18768 DW_FORM_ref_sig8). */
18770 static const struct cu_partial_die_info
18771 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18773 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18774 struct objfile
*objfile
= per_objfile
->objfile
;
18775 struct partial_die_info
*pd
= NULL
;
18777 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18778 && cu
->header
.offset_in_cu_p (sect_off
))
18780 pd
= cu
->find_partial_die (sect_off
);
18783 /* We missed recording what we needed.
18784 Load all dies and try again. */
18788 /* TUs don't reference other CUs/TUs (except via type signatures). */
18789 if (cu
->per_cu
->is_debug_types
)
18791 error (_("Dwarf Error: Type Unit at offset %s contains"
18792 " external reference to offset %s [in module %s].\n"),
18793 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18794 bfd_get_filename (objfile
->obfd
));
18796 dwarf2_per_cu_data
*per_cu
18797 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18800 cu
= per_objfile
->get_cu (per_cu
);
18801 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
18802 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
18804 cu
= per_objfile
->get_cu (per_cu
);
18807 pd
= cu
->find_partial_die (sect_off
);
18810 /* If we didn't find it, and not all dies have been loaded,
18811 load them all and try again. */
18813 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
18815 cu
->per_cu
->load_all_dies
= 1;
18817 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18818 THIS_CU->cu may already be in use. So we can't just free it and
18819 replace its DIEs with the ones we read in. Instead, we leave those
18820 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18821 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18823 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
18825 pd
= cu
->find_partial_die (sect_off
);
18829 internal_error (__FILE__
, __LINE__
,
18830 _("could not find partial DIE %s "
18831 "in cache [from module %s]\n"),
18832 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18836 /* See if we can figure out if the class lives in a namespace. We do
18837 this by looking for a member function; its demangled name will
18838 contain namespace info, if there is any. */
18841 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18842 struct dwarf2_cu
*cu
)
18844 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18845 what template types look like, because the demangler
18846 frequently doesn't give the same name as the debug info. We
18847 could fix this by only using the demangled name to get the
18848 prefix (but see comment in read_structure_type). */
18850 struct partial_die_info
*real_pdi
;
18851 struct partial_die_info
*child_pdi
;
18853 /* If this DIE (this DIE's specification, if any) has a parent, then
18854 we should not do this. We'll prepend the parent's fully qualified
18855 name when we create the partial symbol. */
18857 real_pdi
= struct_pdi
;
18858 while (real_pdi
->has_specification
)
18860 auto res
= find_partial_die (real_pdi
->spec_offset
,
18861 real_pdi
->spec_is_dwz
, cu
);
18862 real_pdi
= res
.pdi
;
18866 if (real_pdi
->die_parent
!= NULL
)
18869 for (child_pdi
= struct_pdi
->die_child
;
18871 child_pdi
= child_pdi
->die_sibling
)
18873 if (child_pdi
->tag
== DW_TAG_subprogram
18874 && child_pdi
->linkage_name
!= NULL
)
18876 gdb::unique_xmalloc_ptr
<char> actual_class_name
18877 (cu
->language_defn
->class_name_from_physname
18878 (child_pdi
->linkage_name
));
18879 if (actual_class_name
!= NULL
)
18881 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18882 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
18883 struct_pdi
->canonical_name
= 1;
18890 /* Return true if a DIE with TAG may have the DW_AT_const_value
18894 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18898 case DW_TAG_constant
:
18899 case DW_TAG_enumerator
:
18900 case DW_TAG_formal_parameter
:
18901 case DW_TAG_template_value_param
:
18902 case DW_TAG_variable
:
18910 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18912 /* Once we've fixed up a die, there's no point in doing so again.
18913 This also avoids a memory leak if we were to call
18914 guess_partial_die_structure_name multiple times. */
18918 /* If we found a reference attribute and the DIE has no name, try
18919 to find a name in the referred to DIE. */
18921 if (raw_name
== NULL
&& has_specification
)
18923 struct partial_die_info
*spec_die
;
18925 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18926 spec_die
= res
.pdi
;
18929 spec_die
->fixup (cu
);
18931 if (spec_die
->raw_name
)
18933 raw_name
= spec_die
->raw_name
;
18934 canonical_name
= spec_die
->canonical_name
;
18936 /* Copy DW_AT_external attribute if it is set. */
18937 if (spec_die
->is_external
)
18938 is_external
= spec_die
->is_external
;
18942 if (!has_const_value
&& has_specification
18943 && can_have_DW_AT_const_value_p (tag
))
18945 struct partial_die_info
*spec_die
;
18947 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18948 spec_die
= res
.pdi
;
18951 spec_die
->fixup (cu
);
18953 if (spec_die
->has_const_value
)
18955 /* Copy DW_AT_const_value attribute if it is set. */
18956 has_const_value
= spec_die
->has_const_value
;
18960 /* Set default names for some unnamed DIEs. */
18962 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
18964 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
18965 canonical_name
= 1;
18968 /* If there is no parent die to provide a namespace, and there are
18969 children, see if we can determine the namespace from their linkage
18971 if (cu
->language
== language_cplus
18972 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18973 && die_parent
== NULL
18975 && (tag
== DW_TAG_class_type
18976 || tag
== DW_TAG_structure_type
18977 || tag
== DW_TAG_union_type
))
18978 guess_partial_die_structure_name (this, cu
);
18980 /* GCC might emit a nameless struct or union that has a linkage
18981 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18982 if (raw_name
== NULL
18983 && (tag
== DW_TAG_class_type
18984 || tag
== DW_TAG_interface_type
18985 || tag
== DW_TAG_structure_type
18986 || tag
== DW_TAG_union_type
)
18987 && linkage_name
!= NULL
)
18989 gdb::unique_xmalloc_ptr
<char> demangled
18990 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18991 if (demangled
!= nullptr)
18995 /* Strip any leading namespaces/classes, keep only the base name.
18996 DW_AT_name for named DIEs does not contain the prefixes. */
18997 base
= strrchr (demangled
.get (), ':');
18998 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19001 base
= demangled
.get ();
19003 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19004 raw_name
= objfile
->intern (base
);
19005 canonical_name
= 1;
19012 /* Read the .debug_loclists header contents from the given SECTION in the
19015 read_loclist_header (struct loclist_header
*header
,
19016 struct dwarf2_section_info
*section
)
19018 unsigned int bytes_read
;
19019 bfd
*abfd
= section
->get_bfd_owner ();
19020 const gdb_byte
*info_ptr
= section
->buffer
;
19021 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19022 info_ptr
+= bytes_read
;
19023 header
->version
= read_2_bytes (abfd
, info_ptr
);
19025 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19027 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19029 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19032 /* Return the DW_AT_loclists_base value for the CU. */
19034 lookup_loclist_base (struct dwarf2_cu
*cu
)
19036 /* For the .dwo unit, the loclist_base points to the first offset following
19037 the header. The header consists of the following entities-
19038 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19040 2. version (2 bytes)
19041 3. address size (1 byte)
19042 4. segment selector size (1 byte)
19043 5. offset entry count (4 bytes)
19044 These sizes are derived as per the DWARFv5 standard. */
19045 if (cu
->dwo_unit
!= nullptr)
19047 if (cu
->header
.initial_length_size
== 4)
19048 return LOCLIST_HEADER_SIZE32
;
19049 return LOCLIST_HEADER_SIZE64
;
19051 return cu
->loclist_base
;
19054 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19055 array of offsets in the .debug_loclists section. */
19057 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19059 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19060 struct objfile
*objfile
= per_objfile
->objfile
;
19061 bfd
*abfd
= objfile
->obfd
;
19062 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19063 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19065 section
->read (objfile
);
19066 if (section
->buffer
== NULL
)
19067 complaint (_("DW_FORM_loclistx used without .debug_loclists "
19068 "section [in module %s]"), objfile_name (objfile
));
19069 struct loclist_header header
;
19070 read_loclist_header (&header
, section
);
19071 if (loclist_index
>= header
.offset_entry_count
)
19072 complaint (_("DW_FORM_loclistx pointing outside of "
19073 ".debug_loclists offset array [in module %s]"),
19074 objfile_name (objfile
));
19075 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
19077 complaint (_("DW_FORM_loclistx pointing outside of "
19078 ".debug_loclists section [in module %s]"),
19079 objfile_name (objfile
));
19080 const gdb_byte
*info_ptr
19081 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19083 if (cu
->header
.offset_size
== 4)
19084 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
19086 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
19089 /* Process the attributes that had to be skipped in the first round. These
19090 attributes are the ones that need str_offsets_base or addr_base attributes.
19091 They could not have been processed in the first round, because at the time
19092 the values of str_offsets_base or addr_base may not have been known. */
19094 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19095 struct attribute
*attr
)
19097 struct dwarf2_cu
*cu
= reader
->cu
;
19098 switch (attr
->form
)
19100 case DW_FORM_addrx
:
19101 case DW_FORM_GNU_addr_index
:
19102 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19104 case DW_FORM_loclistx
:
19105 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19108 case DW_FORM_strx1
:
19109 case DW_FORM_strx2
:
19110 case DW_FORM_strx3
:
19111 case DW_FORM_strx4
:
19112 case DW_FORM_GNU_str_index
:
19114 unsigned int str_index
= DW_UNSND (attr
);
19115 if (reader
->dwo_file
!= NULL
)
19117 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19118 DW_STRING_IS_CANONICAL (attr
) = 0;
19122 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19123 DW_STRING_IS_CANONICAL (attr
) = 0;
19128 gdb_assert_not_reached (_("Unexpected DWARF form."));
19132 /* Read an attribute value described by an attribute form. */
19134 static const gdb_byte
*
19135 read_attribute_value (const struct die_reader_specs
*reader
,
19136 struct attribute
*attr
, unsigned form
,
19137 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19138 bool *need_reprocess
)
19140 struct dwarf2_cu
*cu
= reader
->cu
;
19141 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19142 struct objfile
*objfile
= per_objfile
->objfile
;
19143 bfd
*abfd
= reader
->abfd
;
19144 struct comp_unit_head
*cu_header
= &cu
->header
;
19145 unsigned int bytes_read
;
19146 struct dwarf_block
*blk
;
19147 *need_reprocess
= false;
19149 attr
->form
= (enum dwarf_form
) form
;
19152 case DW_FORM_ref_addr
:
19153 if (cu
->header
.version
== 2)
19154 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19157 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19159 info_ptr
+= bytes_read
;
19161 case DW_FORM_GNU_ref_alt
:
19162 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19163 info_ptr
+= bytes_read
;
19167 struct gdbarch
*gdbarch
= objfile
->arch ();
19168 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19169 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19170 info_ptr
+= bytes_read
;
19173 case DW_FORM_block2
:
19174 blk
= dwarf_alloc_block (cu
);
19175 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19177 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19178 info_ptr
+= blk
->size
;
19179 DW_BLOCK (attr
) = blk
;
19181 case DW_FORM_block4
:
19182 blk
= dwarf_alloc_block (cu
);
19183 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19185 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19186 info_ptr
+= blk
->size
;
19187 DW_BLOCK (attr
) = blk
;
19189 case DW_FORM_data2
:
19190 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19193 case DW_FORM_data4
:
19194 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19197 case DW_FORM_data8
:
19198 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19201 case DW_FORM_data16
:
19202 blk
= dwarf_alloc_block (cu
);
19204 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19206 DW_BLOCK (attr
) = blk
;
19208 case DW_FORM_sec_offset
:
19209 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19210 info_ptr
+= bytes_read
;
19212 case DW_FORM_loclistx
:
19214 *need_reprocess
= true;
19215 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19216 info_ptr
+= bytes_read
;
19219 case DW_FORM_string
:
19220 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19221 DW_STRING_IS_CANONICAL (attr
) = 0;
19222 info_ptr
+= bytes_read
;
19225 if (!cu
->per_cu
->is_dwz
)
19227 DW_STRING (attr
) = read_indirect_string (per_objfile
,
19228 abfd
, info_ptr
, cu_header
,
19230 DW_STRING_IS_CANONICAL (attr
) = 0;
19231 info_ptr
+= bytes_read
;
19235 case DW_FORM_line_strp
:
19236 if (!cu
->per_cu
->is_dwz
)
19238 DW_STRING (attr
) = per_objfile
->read_line_string (info_ptr
, cu_header
,
19240 DW_STRING_IS_CANONICAL (attr
) = 0;
19241 info_ptr
+= bytes_read
;
19245 case DW_FORM_GNU_strp_alt
:
19247 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19248 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19251 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19252 DW_STRING_IS_CANONICAL (attr
) = 0;
19253 info_ptr
+= bytes_read
;
19256 case DW_FORM_exprloc
:
19257 case DW_FORM_block
:
19258 blk
= dwarf_alloc_block (cu
);
19259 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19260 info_ptr
+= bytes_read
;
19261 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19262 info_ptr
+= blk
->size
;
19263 DW_BLOCK (attr
) = blk
;
19265 case DW_FORM_block1
:
19266 blk
= dwarf_alloc_block (cu
);
19267 blk
->size
= read_1_byte (abfd
, info_ptr
);
19269 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19270 info_ptr
+= blk
->size
;
19271 DW_BLOCK (attr
) = blk
;
19273 case DW_FORM_data1
:
19274 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19278 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19281 case DW_FORM_flag_present
:
19282 DW_UNSND (attr
) = 1;
19284 case DW_FORM_sdata
:
19285 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19286 info_ptr
+= bytes_read
;
19288 case DW_FORM_udata
:
19289 case DW_FORM_rnglistx
:
19290 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19291 info_ptr
+= bytes_read
;
19294 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19295 + read_1_byte (abfd
, info_ptr
));
19299 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19300 + read_2_bytes (abfd
, info_ptr
));
19304 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19305 + read_4_bytes (abfd
, info_ptr
));
19309 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19310 + read_8_bytes (abfd
, info_ptr
));
19313 case DW_FORM_ref_sig8
:
19314 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19317 case DW_FORM_ref_udata
:
19318 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19319 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19320 info_ptr
+= bytes_read
;
19322 case DW_FORM_indirect
:
19323 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19324 info_ptr
+= bytes_read
;
19325 if (form
== DW_FORM_implicit_const
)
19327 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19328 info_ptr
+= bytes_read
;
19330 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19331 info_ptr
, need_reprocess
);
19333 case DW_FORM_implicit_const
:
19334 DW_SND (attr
) = implicit_const
;
19336 case DW_FORM_addrx
:
19337 case DW_FORM_GNU_addr_index
:
19338 *need_reprocess
= true;
19339 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19340 info_ptr
+= bytes_read
;
19343 case DW_FORM_strx1
:
19344 case DW_FORM_strx2
:
19345 case DW_FORM_strx3
:
19346 case DW_FORM_strx4
:
19347 case DW_FORM_GNU_str_index
:
19349 ULONGEST str_index
;
19350 if (form
== DW_FORM_strx1
)
19352 str_index
= read_1_byte (abfd
, info_ptr
);
19355 else if (form
== DW_FORM_strx2
)
19357 str_index
= read_2_bytes (abfd
, info_ptr
);
19360 else if (form
== DW_FORM_strx3
)
19362 str_index
= read_3_bytes (abfd
, info_ptr
);
19365 else if (form
== DW_FORM_strx4
)
19367 str_index
= read_4_bytes (abfd
, info_ptr
);
19372 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19373 info_ptr
+= bytes_read
;
19375 *need_reprocess
= true;
19376 DW_UNSND (attr
) = str_index
;
19380 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19381 dwarf_form_name (form
),
19382 bfd_get_filename (abfd
));
19386 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19387 attr
->form
= DW_FORM_GNU_ref_alt
;
19389 /* We have seen instances where the compiler tried to emit a byte
19390 size attribute of -1 which ended up being encoded as an unsigned
19391 0xffffffff. Although 0xffffffff is technically a valid size value,
19392 an object of this size seems pretty unlikely so we can relatively
19393 safely treat these cases as if the size attribute was invalid and
19394 treat them as zero by default. */
19395 if (attr
->name
== DW_AT_byte_size
19396 && form
== DW_FORM_data4
19397 && DW_UNSND (attr
) >= 0xffffffff)
19400 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19401 hex_string (DW_UNSND (attr
)));
19402 DW_UNSND (attr
) = 0;
19408 /* Read an attribute described by an abbreviated attribute. */
19410 static const gdb_byte
*
19411 read_attribute (const struct die_reader_specs
*reader
,
19412 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19413 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19415 attr
->name
= abbrev
->name
;
19416 return read_attribute_value (reader
, attr
, abbrev
->form
,
19417 abbrev
->implicit_const
, info_ptr
,
19421 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19423 static const char *
19424 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
19425 LONGEST str_offset
)
19427 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
19428 str_offset
, "DW_FORM_strp");
19431 /* Return pointer to string at .debug_str offset as read from BUF.
19432 BUF is assumed to be in a compilation unit described by CU_HEADER.
19433 Return *BYTES_READ_PTR count of bytes read from BUF. */
19435 static const char *
19436 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
19437 const gdb_byte
*buf
,
19438 const struct comp_unit_head
*cu_header
,
19439 unsigned int *bytes_read_ptr
)
19441 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19443 return read_indirect_string_at_offset (per_objfile
, str_offset
);
19449 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19450 const struct comp_unit_head
*cu_header
,
19451 unsigned int *bytes_read_ptr
)
19453 bfd
*abfd
= objfile
->obfd
;
19454 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19456 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19459 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19460 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19461 ADDR_SIZE is the size of addresses from the CU header. */
19464 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
19465 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
19467 struct objfile
*objfile
= per_objfile
->objfile
;
19468 bfd
*abfd
= objfile
->obfd
;
19469 const gdb_byte
*info_ptr
;
19470 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19472 per_objfile
->per_bfd
->addr
.read (objfile
);
19473 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19474 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19475 objfile_name (objfile
));
19476 if (addr_base_or_zero
+ addr_index
* addr_size
19477 >= per_objfile
->per_bfd
->addr
.size
)
19478 error (_("DW_FORM_addr_index pointing outside of "
19479 ".debug_addr section [in module %s]"),
19480 objfile_name (objfile
));
19481 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
19482 + addr_index
* addr_size
);
19483 if (addr_size
== 4)
19484 return bfd_get_32 (abfd
, info_ptr
);
19486 return bfd_get_64 (abfd
, info_ptr
);
19489 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19492 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19494 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19495 cu
->addr_base
, cu
->header
.addr_size
);
19498 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19501 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19502 unsigned int *bytes_read
)
19504 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19505 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19507 return read_addr_index (cu
, addr_index
);
19513 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19514 dwarf2_per_objfile
*per_objfile
,
19515 unsigned int addr_index
)
19517 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
19518 gdb::optional
<ULONGEST
> addr_base
;
19521 /* We need addr_base and addr_size.
19522 If we don't have PER_CU->cu, we have to get it.
19523 Nasty, but the alternative is storing the needed info in PER_CU,
19524 which at this point doesn't seem justified: it's not clear how frequently
19525 it would get used and it would increase the size of every PER_CU.
19526 Entry points like dwarf2_per_cu_addr_size do a similar thing
19527 so we're not in uncharted territory here.
19528 Alas we need to be a bit more complicated as addr_base is contained
19531 We don't need to read the entire CU(/TU).
19532 We just need the header and top level die.
19534 IWBN to use the aging mechanism to let us lazily later discard the CU.
19535 For now we skip this optimization. */
19539 addr_base
= cu
->addr_base
;
19540 addr_size
= cu
->header
.addr_size
;
19544 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
19545 addr_base
= reader
.cu
->addr_base
;
19546 addr_size
= reader
.cu
->header
.addr_size
;
19549 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
19552 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19553 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19556 static const char *
19557 read_str_index (struct dwarf2_cu
*cu
,
19558 struct dwarf2_section_info
*str_section
,
19559 struct dwarf2_section_info
*str_offsets_section
,
19560 ULONGEST str_offsets_base
, ULONGEST str_index
)
19562 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19563 struct objfile
*objfile
= per_objfile
->objfile
;
19564 const char *objf_name
= objfile_name (objfile
);
19565 bfd
*abfd
= objfile
->obfd
;
19566 const gdb_byte
*info_ptr
;
19567 ULONGEST str_offset
;
19568 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19570 str_section
->read (objfile
);
19571 str_offsets_section
->read (objfile
);
19572 if (str_section
->buffer
== NULL
)
19573 error (_("%s used without %s section"
19574 " in CU at offset %s [in module %s]"),
19575 form_name
, str_section
->get_name (),
19576 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19577 if (str_offsets_section
->buffer
== NULL
)
19578 error (_("%s used without %s section"
19579 " in CU at offset %s [in module %s]"),
19580 form_name
, str_section
->get_name (),
19581 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19582 info_ptr
= (str_offsets_section
->buffer
19584 + str_index
* cu
->header
.offset_size
);
19585 if (cu
->header
.offset_size
== 4)
19586 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19588 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19589 if (str_offset
>= str_section
->size
)
19590 error (_("Offset from %s pointing outside of"
19591 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19592 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19593 return (const char *) (str_section
->buffer
+ str_offset
);
19596 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19598 static const char *
19599 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19601 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19602 ? reader
->cu
->header
.addr_size
: 0;
19603 return read_str_index (reader
->cu
,
19604 &reader
->dwo_file
->sections
.str
,
19605 &reader
->dwo_file
->sections
.str_offsets
,
19606 str_offsets_base
, str_index
);
19609 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19611 static const char *
19612 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19614 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19615 const char *objf_name
= objfile_name (objfile
);
19616 static const char form_name
[] = "DW_FORM_GNU_str_index";
19617 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19619 if (!cu
->str_offsets_base
.has_value ())
19620 error (_("%s used in Fission stub without %s"
19621 " in CU at offset 0x%lx [in module %s]"),
19622 form_name
, str_offsets_attr_name
,
19623 (long) cu
->header
.offset_size
, objf_name
);
19625 return read_str_index (cu
,
19626 &cu
->per_objfile
->per_bfd
->str
,
19627 &cu
->per_objfile
->per_bfd
->str_offsets
,
19628 *cu
->str_offsets_base
, str_index
);
19631 /* Return the length of an LEB128 number in BUF. */
19634 leb128_size (const gdb_byte
*buf
)
19636 const gdb_byte
*begin
= buf
;
19642 if ((byte
& 128) == 0)
19643 return buf
- begin
;
19648 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19657 cu
->language
= language_c
;
19660 case DW_LANG_C_plus_plus
:
19661 case DW_LANG_C_plus_plus_11
:
19662 case DW_LANG_C_plus_plus_14
:
19663 cu
->language
= language_cplus
;
19666 cu
->language
= language_d
;
19668 case DW_LANG_Fortran77
:
19669 case DW_LANG_Fortran90
:
19670 case DW_LANG_Fortran95
:
19671 case DW_LANG_Fortran03
:
19672 case DW_LANG_Fortran08
:
19673 cu
->language
= language_fortran
;
19676 cu
->language
= language_go
;
19678 case DW_LANG_Mips_Assembler
:
19679 cu
->language
= language_asm
;
19681 case DW_LANG_Ada83
:
19682 case DW_LANG_Ada95
:
19683 cu
->language
= language_ada
;
19685 case DW_LANG_Modula2
:
19686 cu
->language
= language_m2
;
19688 case DW_LANG_Pascal83
:
19689 cu
->language
= language_pascal
;
19692 cu
->language
= language_objc
;
19695 case DW_LANG_Rust_old
:
19696 cu
->language
= language_rust
;
19698 case DW_LANG_Cobol74
:
19699 case DW_LANG_Cobol85
:
19701 cu
->language
= language_minimal
;
19704 cu
->language_defn
= language_def (cu
->language
);
19707 /* Return the named attribute or NULL if not there. */
19709 static struct attribute
*
19710 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19715 struct attribute
*spec
= NULL
;
19717 for (i
= 0; i
< die
->num_attrs
; ++i
)
19719 if (die
->attrs
[i
].name
== name
)
19720 return &die
->attrs
[i
];
19721 if (die
->attrs
[i
].name
== DW_AT_specification
19722 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19723 spec
= &die
->attrs
[i
];
19729 die
= follow_die_ref (die
, spec
, &cu
);
19735 /* Return the string associated with a string-typed attribute, or NULL if it
19736 is either not found or is of an incorrect type. */
19738 static const char *
19739 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19741 struct attribute
*attr
;
19742 const char *str
= NULL
;
19744 attr
= dwarf2_attr (die
, name
, cu
);
19748 str
= attr
->value_as_string ();
19749 if (str
== nullptr)
19750 complaint (_("string type expected for attribute %s for "
19751 "DIE at %s in module %s"),
19752 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19753 objfile_name (cu
->per_objfile
->objfile
));
19759 /* Return the dwo name or NULL if not present. If present, it is in either
19760 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19761 static const char *
19762 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19764 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19765 if (dwo_name
== nullptr)
19766 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19770 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19771 and holds a non-zero value. This function should only be used for
19772 DW_FORM_flag or DW_FORM_flag_present attributes. */
19775 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19777 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19779 return (attr
&& DW_UNSND (attr
));
19783 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19785 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19786 which value is non-zero. However, we have to be careful with
19787 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19788 (via dwarf2_flag_true_p) follows this attribute. So we may
19789 end up accidently finding a declaration attribute that belongs
19790 to a different DIE referenced by the specification attribute,
19791 even though the given DIE does not have a declaration attribute. */
19792 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19793 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19796 /* Return the die giving the specification for DIE, if there is
19797 one. *SPEC_CU is the CU containing DIE on input, and the CU
19798 containing the return value on output. If there is no
19799 specification, but there is an abstract origin, that is
19802 static struct die_info
*
19803 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19805 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19808 if (spec_attr
== NULL
)
19809 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19811 if (spec_attr
== NULL
)
19814 return follow_die_ref (die
, spec_attr
, spec_cu
);
19817 /* Stub for free_line_header to match void * callback types. */
19820 free_line_header_voidp (void *arg
)
19822 struct line_header
*lh
= (struct line_header
*) arg
;
19827 /* A convenience function to find the proper .debug_line section for a CU. */
19829 static struct dwarf2_section_info
*
19830 get_debug_line_section (struct dwarf2_cu
*cu
)
19832 struct dwarf2_section_info
*section
;
19833 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19835 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19837 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19838 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19839 else if (cu
->per_cu
->is_dwz
)
19841 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19843 section
= &dwz
->line
;
19846 section
= &per_objfile
->per_bfd
->line
;
19851 /* Read the statement program header starting at OFFSET in
19852 .debug_line, or .debug_line.dwo. Return a pointer
19853 to a struct line_header, allocated using xmalloc.
19854 Returns NULL if there is a problem reading the header, e.g., if it
19855 has a version we don't understand.
19857 NOTE: the strings in the include directory and file name tables of
19858 the returned object point into the dwarf line section buffer,
19859 and must not be freed. */
19861 static line_header_up
19862 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19864 struct dwarf2_section_info
*section
;
19865 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19867 section
= get_debug_line_section (cu
);
19868 section
->read (per_objfile
->objfile
);
19869 if (section
->buffer
== NULL
)
19871 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19872 complaint (_("missing .debug_line.dwo section"));
19874 complaint (_("missing .debug_line section"));
19878 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19879 per_objfile
, section
, &cu
->header
);
19882 /* Subroutine of dwarf_decode_lines to simplify it.
19883 Return the file name of the psymtab for the given file_entry.
19884 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19885 If space for the result is malloc'd, *NAME_HOLDER will be set.
19886 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19888 static const char *
19889 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19890 const dwarf2_psymtab
*pst
,
19891 const char *comp_dir
,
19892 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19894 const char *include_name
= fe
.name
;
19895 const char *include_name_to_compare
= include_name
;
19896 const char *pst_filename
;
19899 const char *dir_name
= fe
.include_dir (lh
);
19901 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19902 if (!IS_ABSOLUTE_PATH (include_name
)
19903 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19905 /* Avoid creating a duplicate psymtab for PST.
19906 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19907 Before we do the comparison, however, we need to account
19908 for DIR_NAME and COMP_DIR.
19909 First prepend dir_name (if non-NULL). If we still don't
19910 have an absolute path prepend comp_dir (if non-NULL).
19911 However, the directory we record in the include-file's
19912 psymtab does not contain COMP_DIR (to match the
19913 corresponding symtab(s)).
19918 bash$ gcc -g ./hello.c
19919 include_name = "hello.c"
19921 DW_AT_comp_dir = comp_dir = "/tmp"
19922 DW_AT_name = "./hello.c"
19926 if (dir_name
!= NULL
)
19928 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19929 include_name
, (char *) NULL
));
19930 include_name
= name_holder
->get ();
19931 include_name_to_compare
= include_name
;
19933 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19935 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19936 include_name
, (char *) NULL
));
19937 include_name_to_compare
= hold_compare
.get ();
19941 pst_filename
= pst
->filename
;
19942 gdb::unique_xmalloc_ptr
<char> copied_name
;
19943 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19945 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19946 pst_filename
, (char *) NULL
));
19947 pst_filename
= copied_name
.get ();
19950 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19954 return include_name
;
19957 /* State machine to track the state of the line number program. */
19959 class lnp_state_machine
19962 /* Initialize a machine state for the start of a line number
19964 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19965 bool record_lines_p
);
19967 file_entry
*current_file ()
19969 /* lh->file_names is 0-based, but the file name numbers in the
19970 statement program are 1-based. */
19971 return m_line_header
->file_name_at (m_file
);
19974 /* Record the line in the state machine. END_SEQUENCE is true if
19975 we're processing the end of a sequence. */
19976 void record_line (bool end_sequence
);
19978 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19979 nop-out rest of the lines in this sequence. */
19980 void check_line_address (struct dwarf2_cu
*cu
,
19981 const gdb_byte
*line_ptr
,
19982 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19984 void handle_set_discriminator (unsigned int discriminator
)
19986 m_discriminator
= discriminator
;
19987 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19990 /* Handle DW_LNE_set_address. */
19991 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19994 address
+= baseaddr
;
19995 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19998 /* Handle DW_LNS_advance_pc. */
19999 void handle_advance_pc (CORE_ADDR adjust
);
20001 /* Handle a special opcode. */
20002 void handle_special_opcode (unsigned char op_code
);
20004 /* Handle DW_LNS_advance_line. */
20005 void handle_advance_line (int line_delta
)
20007 advance_line (line_delta
);
20010 /* Handle DW_LNS_set_file. */
20011 void handle_set_file (file_name_index file
);
20013 /* Handle DW_LNS_negate_stmt. */
20014 void handle_negate_stmt ()
20016 m_is_stmt
= !m_is_stmt
;
20019 /* Handle DW_LNS_const_add_pc. */
20020 void handle_const_add_pc ();
20022 /* Handle DW_LNS_fixed_advance_pc. */
20023 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20025 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20029 /* Handle DW_LNS_copy. */
20030 void handle_copy ()
20032 record_line (false);
20033 m_discriminator
= 0;
20036 /* Handle DW_LNE_end_sequence. */
20037 void handle_end_sequence ()
20039 m_currently_recording_lines
= true;
20043 /* Advance the line by LINE_DELTA. */
20044 void advance_line (int line_delta
)
20046 m_line
+= line_delta
;
20048 if (line_delta
!= 0)
20049 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20052 struct dwarf2_cu
*m_cu
;
20054 gdbarch
*m_gdbarch
;
20056 /* True if we're recording lines.
20057 Otherwise we're building partial symtabs and are just interested in
20058 finding include files mentioned by the line number program. */
20059 bool m_record_lines_p
;
20061 /* The line number header. */
20062 line_header
*m_line_header
;
20064 /* These are part of the standard DWARF line number state machine,
20065 and initialized according to the DWARF spec. */
20067 unsigned char m_op_index
= 0;
20068 /* The line table index of the current file. */
20069 file_name_index m_file
= 1;
20070 unsigned int m_line
= 1;
20072 /* These are initialized in the constructor. */
20074 CORE_ADDR m_address
;
20076 unsigned int m_discriminator
;
20078 /* Additional bits of state we need to track. */
20080 /* The last file that we called dwarf2_start_subfile for.
20081 This is only used for TLLs. */
20082 unsigned int m_last_file
= 0;
20083 /* The last file a line number was recorded for. */
20084 struct subfile
*m_last_subfile
= NULL
;
20086 /* The address of the last line entry. */
20087 CORE_ADDR m_last_address
;
20089 /* Set to true when a previous line at the same address (using
20090 m_last_address) had m_is_stmt true. This is reset to false when a
20091 line entry at a new address (m_address different to m_last_address) is
20093 bool m_stmt_at_address
= false;
20095 /* When true, record the lines we decode. */
20096 bool m_currently_recording_lines
= false;
20098 /* The last line number that was recorded, used to coalesce
20099 consecutive entries for the same line. This can happen, for
20100 example, when discriminators are present. PR 17276. */
20101 unsigned int m_last_line
= 0;
20102 bool m_line_has_non_zero_discriminator
= false;
20106 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20108 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20109 / m_line_header
->maximum_ops_per_instruction
)
20110 * m_line_header
->minimum_instruction_length
);
20111 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20112 m_op_index
= ((m_op_index
+ adjust
)
20113 % m_line_header
->maximum_ops_per_instruction
);
20117 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20119 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20120 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20121 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20122 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20123 / m_line_header
->maximum_ops_per_instruction
)
20124 * m_line_header
->minimum_instruction_length
);
20125 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20126 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20127 % m_line_header
->maximum_ops_per_instruction
);
20129 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20130 advance_line (line_delta
);
20131 record_line (false);
20132 m_discriminator
= 0;
20136 lnp_state_machine::handle_set_file (file_name_index file
)
20140 const file_entry
*fe
= current_file ();
20142 dwarf2_debug_line_missing_file_complaint ();
20143 else if (m_record_lines_p
)
20145 const char *dir
= fe
->include_dir (m_line_header
);
20147 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20148 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20149 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20154 lnp_state_machine::handle_const_add_pc ()
20157 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20160 = (((m_op_index
+ adjust
)
20161 / m_line_header
->maximum_ops_per_instruction
)
20162 * m_line_header
->minimum_instruction_length
);
20164 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20165 m_op_index
= ((m_op_index
+ adjust
)
20166 % m_line_header
->maximum_ops_per_instruction
);
20169 /* Return non-zero if we should add LINE to the line number table.
20170 LINE is the line to add, LAST_LINE is the last line that was added,
20171 LAST_SUBFILE is the subfile for LAST_LINE.
20172 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20173 had a non-zero discriminator.
20175 We have to be careful in the presence of discriminators.
20176 E.g., for this line:
20178 for (i = 0; i < 100000; i++);
20180 clang can emit four line number entries for that one line,
20181 each with a different discriminator.
20182 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20184 However, we want gdb to coalesce all four entries into one.
20185 Otherwise the user could stepi into the middle of the line and
20186 gdb would get confused about whether the pc really was in the
20187 middle of the line.
20189 Things are further complicated by the fact that two consecutive
20190 line number entries for the same line is a heuristic used by gcc
20191 to denote the end of the prologue. So we can't just discard duplicate
20192 entries, we have to be selective about it. The heuristic we use is
20193 that we only collapse consecutive entries for the same line if at least
20194 one of those entries has a non-zero discriminator. PR 17276.
20196 Note: Addresses in the line number state machine can never go backwards
20197 within one sequence, thus this coalescing is ok. */
20200 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20201 unsigned int line
, unsigned int last_line
,
20202 int line_has_non_zero_discriminator
,
20203 struct subfile
*last_subfile
)
20205 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20207 if (line
!= last_line
)
20209 /* Same line for the same file that we've seen already.
20210 As a last check, for pr 17276, only record the line if the line
20211 has never had a non-zero discriminator. */
20212 if (!line_has_non_zero_discriminator
)
20217 /* Use the CU's builder to record line number LINE beginning at
20218 address ADDRESS in the line table of subfile SUBFILE. */
20221 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20222 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20223 struct dwarf2_cu
*cu
)
20225 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20227 if (dwarf_line_debug
)
20229 fprintf_unfiltered (gdb_stdlog
,
20230 "Recording line %u, file %s, address %s\n",
20231 line
, lbasename (subfile
->name
),
20232 paddress (gdbarch
, address
));
20236 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20239 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20240 Mark the end of a set of line number records.
20241 The arguments are the same as for dwarf_record_line_1.
20242 If SUBFILE is NULL the request is ignored. */
20245 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20246 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20248 if (subfile
== NULL
)
20251 if (dwarf_line_debug
)
20253 fprintf_unfiltered (gdb_stdlog
,
20254 "Finishing current line, file %s, address %s\n",
20255 lbasename (subfile
->name
),
20256 paddress (gdbarch
, address
));
20259 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20263 lnp_state_machine::record_line (bool end_sequence
)
20265 if (dwarf_line_debug
)
20267 fprintf_unfiltered (gdb_stdlog
,
20268 "Processing actual line %u: file %u,"
20269 " address %s, is_stmt %u, discrim %u%s\n",
20271 paddress (m_gdbarch
, m_address
),
20272 m_is_stmt
, m_discriminator
,
20273 (end_sequence
? "\t(end sequence)" : ""));
20276 file_entry
*fe
= current_file ();
20279 dwarf2_debug_line_missing_file_complaint ();
20280 /* For now we ignore lines not starting on an instruction boundary.
20281 But not when processing end_sequence for compatibility with the
20282 previous version of the code. */
20283 else if (m_op_index
== 0 || end_sequence
)
20285 fe
->included_p
= 1;
20286 if (m_record_lines_p
)
20288 /* When we switch files we insert an end maker in the first file,
20289 switch to the second file and add a new line entry. The
20290 problem is that the end marker inserted in the first file will
20291 discard any previous line entries at the same address. If the
20292 line entries in the first file are marked as is-stmt, while
20293 the new line in the second file is non-stmt, then this means
20294 the end marker will discard is-stmt lines so we can have a
20295 non-stmt line. This means that there are less addresses at
20296 which the user can insert a breakpoint.
20298 To improve this we track the last address in m_last_address,
20299 and whether we have seen an is-stmt at this address. Then
20300 when switching files, if we have seen a stmt at the current
20301 address, and we are switching to create a non-stmt line, then
20302 discard the new line. */
20304 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
20305 bool ignore_this_line
20306 = (file_changed
&& !end_sequence
&& m_last_address
== m_address
20307 && !m_is_stmt
&& m_stmt_at_address
);
20309 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
20311 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20312 m_currently_recording_lines
? m_cu
: nullptr);
20315 if (!end_sequence
&& !ignore_this_line
)
20317 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20319 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20320 m_line_has_non_zero_discriminator
,
20323 buildsym_compunit
*builder
= m_cu
->get_builder ();
20324 dwarf_record_line_1 (m_gdbarch
,
20325 builder
->get_current_subfile (),
20326 m_line
, m_address
, is_stmt
,
20327 m_currently_recording_lines
? m_cu
: nullptr);
20329 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20330 m_last_line
= m_line
;
20335 /* Track whether we have seen any m_is_stmt true at m_address in case we
20336 have multiple line table entries all at m_address. */
20337 if (m_last_address
!= m_address
)
20339 m_stmt_at_address
= false;
20340 m_last_address
= m_address
;
20342 m_stmt_at_address
|= m_is_stmt
;
20345 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20346 line_header
*lh
, bool record_lines_p
)
20350 m_record_lines_p
= record_lines_p
;
20351 m_line_header
= lh
;
20353 m_currently_recording_lines
= true;
20355 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20356 was a line entry for it so that the backend has a chance to adjust it
20357 and also record it in case it needs it. This is currently used by MIPS
20358 code, cf. `mips_adjust_dwarf2_line'. */
20359 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20360 m_is_stmt
= lh
->default_is_stmt
;
20361 m_discriminator
= 0;
20363 m_last_address
= m_address
;
20364 m_stmt_at_address
= false;
20368 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20369 const gdb_byte
*line_ptr
,
20370 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20372 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20373 the pc range of the CU. However, we restrict the test to only ADDRESS
20374 values of zero to preserve GDB's previous behaviour which is to handle
20375 the specific case of a function being GC'd by the linker. */
20377 if (address
== 0 && address
< unrelocated_lowpc
)
20379 /* This line table is for a function which has been
20380 GCd by the linker. Ignore it. PR gdb/12528 */
20382 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20383 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20385 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20386 line_offset
, objfile_name (objfile
));
20387 m_currently_recording_lines
= false;
20388 /* Note: m_currently_recording_lines is left as false until we see
20389 DW_LNE_end_sequence. */
20393 /* Subroutine of dwarf_decode_lines to simplify it.
20394 Process the line number information in LH.
20395 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20396 program in order to set included_p for every referenced header. */
20399 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20400 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20402 const gdb_byte
*line_ptr
, *extended_end
;
20403 const gdb_byte
*line_end
;
20404 unsigned int bytes_read
, extended_len
;
20405 unsigned char op_code
, extended_op
;
20406 CORE_ADDR baseaddr
;
20407 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20408 bfd
*abfd
= objfile
->obfd
;
20409 struct gdbarch
*gdbarch
= objfile
->arch ();
20410 /* True if we're recording line info (as opposed to building partial
20411 symtabs and just interested in finding include files mentioned by
20412 the line number program). */
20413 bool record_lines_p
= !decode_for_pst_p
;
20415 baseaddr
= objfile
->text_section_offset ();
20417 line_ptr
= lh
->statement_program_start
;
20418 line_end
= lh
->statement_program_end
;
20420 /* Read the statement sequences until there's nothing left. */
20421 while (line_ptr
< line_end
)
20423 /* The DWARF line number program state machine. Reset the state
20424 machine at the start of each sequence. */
20425 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20426 bool end_sequence
= false;
20428 if (record_lines_p
)
20430 /* Start a subfile for the current file of the state
20432 const file_entry
*fe
= state_machine
.current_file ();
20435 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20438 /* Decode the table. */
20439 while (line_ptr
< line_end
&& !end_sequence
)
20441 op_code
= read_1_byte (abfd
, line_ptr
);
20444 if (op_code
>= lh
->opcode_base
)
20446 /* Special opcode. */
20447 state_machine
.handle_special_opcode (op_code
);
20449 else switch (op_code
)
20451 case DW_LNS_extended_op
:
20452 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20454 line_ptr
+= bytes_read
;
20455 extended_end
= line_ptr
+ extended_len
;
20456 extended_op
= read_1_byte (abfd
, line_ptr
);
20458 switch (extended_op
)
20460 case DW_LNE_end_sequence
:
20461 state_machine
.handle_end_sequence ();
20462 end_sequence
= true;
20464 case DW_LNE_set_address
:
20467 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20468 line_ptr
+= bytes_read
;
20470 state_machine
.check_line_address (cu
, line_ptr
,
20471 lowpc
- baseaddr
, address
);
20472 state_machine
.handle_set_address (baseaddr
, address
);
20475 case DW_LNE_define_file
:
20477 const char *cur_file
;
20478 unsigned int mod_time
, length
;
20481 cur_file
= read_direct_string (abfd
, line_ptr
,
20483 line_ptr
+= bytes_read
;
20484 dindex
= (dir_index
)
20485 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20486 line_ptr
+= bytes_read
;
20488 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20489 line_ptr
+= bytes_read
;
20491 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20492 line_ptr
+= bytes_read
;
20493 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20496 case DW_LNE_set_discriminator
:
20498 /* The discriminator is not interesting to the
20499 debugger; just ignore it. We still need to
20500 check its value though:
20501 if there are consecutive entries for the same
20502 (non-prologue) line we want to coalesce them.
20505 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20506 line_ptr
+= bytes_read
;
20508 state_machine
.handle_set_discriminator (discr
);
20512 complaint (_("mangled .debug_line section"));
20515 /* Make sure that we parsed the extended op correctly. If e.g.
20516 we expected a different address size than the producer used,
20517 we may have read the wrong number of bytes. */
20518 if (line_ptr
!= extended_end
)
20520 complaint (_("mangled .debug_line section"));
20525 state_machine
.handle_copy ();
20527 case DW_LNS_advance_pc
:
20530 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20531 line_ptr
+= bytes_read
;
20533 state_machine
.handle_advance_pc (adjust
);
20536 case DW_LNS_advance_line
:
20539 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20540 line_ptr
+= bytes_read
;
20542 state_machine
.handle_advance_line (line_delta
);
20545 case DW_LNS_set_file
:
20547 file_name_index file
20548 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20550 line_ptr
+= bytes_read
;
20552 state_machine
.handle_set_file (file
);
20555 case DW_LNS_set_column
:
20556 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20557 line_ptr
+= bytes_read
;
20559 case DW_LNS_negate_stmt
:
20560 state_machine
.handle_negate_stmt ();
20562 case DW_LNS_set_basic_block
:
20564 /* Add to the address register of the state machine the
20565 address increment value corresponding to special opcode
20566 255. I.e., this value is scaled by the minimum
20567 instruction length since special opcode 255 would have
20568 scaled the increment. */
20569 case DW_LNS_const_add_pc
:
20570 state_machine
.handle_const_add_pc ();
20572 case DW_LNS_fixed_advance_pc
:
20574 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20577 state_machine
.handle_fixed_advance_pc (addr_adj
);
20582 /* Unknown standard opcode, ignore it. */
20585 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20587 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20588 line_ptr
+= bytes_read
;
20595 dwarf2_debug_line_missing_end_sequence_complaint ();
20597 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20598 in which case we still finish recording the last line). */
20599 state_machine
.record_line (true);
20603 /* Decode the Line Number Program (LNP) for the given line_header
20604 structure and CU. The actual information extracted and the type
20605 of structures created from the LNP depends on the value of PST.
20607 1. If PST is NULL, then this procedure uses the data from the program
20608 to create all necessary symbol tables, and their linetables.
20610 2. If PST is not NULL, this procedure reads the program to determine
20611 the list of files included by the unit represented by PST, and
20612 builds all the associated partial symbol tables.
20614 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20615 It is used for relative paths in the line table.
20616 NOTE: When processing partial symtabs (pst != NULL),
20617 comp_dir == pst->dirname.
20619 NOTE: It is important that psymtabs have the same file name (via strcmp)
20620 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20621 symtab we don't use it in the name of the psymtabs we create.
20622 E.g. expand_line_sal requires this when finding psymtabs to expand.
20623 A good testcase for this is mb-inline.exp.
20625 LOWPC is the lowest address in CU (or 0 if not known).
20627 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20628 for its PC<->lines mapping information. Otherwise only the filename
20629 table is read in. */
20632 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20633 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20634 CORE_ADDR lowpc
, int decode_mapping
)
20636 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20637 const int decode_for_pst_p
= (pst
!= NULL
);
20639 if (decode_mapping
)
20640 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20642 if (decode_for_pst_p
)
20644 /* Now that we're done scanning the Line Header Program, we can
20645 create the psymtab of each included file. */
20646 for (auto &file_entry
: lh
->file_names ())
20647 if (file_entry
.included_p
== 1)
20649 gdb::unique_xmalloc_ptr
<char> name_holder
;
20650 const char *include_name
=
20651 psymtab_include_file_name (lh
, file_entry
, pst
,
20652 comp_dir
, &name_holder
);
20653 if (include_name
!= NULL
)
20654 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20659 /* Make sure a symtab is created for every file, even files
20660 which contain only variables (i.e. no code with associated
20662 buildsym_compunit
*builder
= cu
->get_builder ();
20663 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20665 for (auto &fe
: lh
->file_names ())
20667 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20668 if (builder
->get_current_subfile ()->symtab
== NULL
)
20670 builder
->get_current_subfile ()->symtab
20671 = allocate_symtab (cust
,
20672 builder
->get_current_subfile ()->name
);
20674 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20679 /* Start a subfile for DWARF. FILENAME is the name of the file and
20680 DIRNAME the name of the source directory which contains FILENAME
20681 or NULL if not known.
20682 This routine tries to keep line numbers from identical absolute and
20683 relative file names in a common subfile.
20685 Using the `list' example from the GDB testsuite, which resides in
20686 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20687 of /srcdir/list0.c yields the following debugging information for list0.c:
20689 DW_AT_name: /srcdir/list0.c
20690 DW_AT_comp_dir: /compdir
20691 files.files[0].name: list0.h
20692 files.files[0].dir: /srcdir
20693 files.files[1].name: list0.c
20694 files.files[1].dir: /srcdir
20696 The line number information for list0.c has to end up in a single
20697 subfile, so that `break /srcdir/list0.c:1' works as expected.
20698 start_subfile will ensure that this happens provided that we pass the
20699 concatenation of files.files[1].dir and files.files[1].name as the
20703 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20704 const char *dirname
)
20706 gdb::unique_xmalloc_ptr
<char> copy
;
20708 /* In order not to lose the line information directory,
20709 we concatenate it to the filename when it makes sense.
20710 Note that the Dwarf3 standard says (speaking of filenames in line
20711 information): ``The directory index is ignored for file names
20712 that represent full path names''. Thus ignoring dirname in the
20713 `else' branch below isn't an issue. */
20715 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20717 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20718 filename
= copy
.get ();
20721 cu
->get_builder ()->start_subfile (filename
);
20724 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20725 buildsym_compunit constructor. */
20727 struct compunit_symtab
*
20728 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20731 gdb_assert (m_builder
== nullptr);
20733 m_builder
.reset (new struct buildsym_compunit
20734 (this->per_objfile
->objfile
,
20735 name
, comp_dir
, language
, low_pc
));
20737 list_in_scope
= get_builder ()->get_file_symbols ();
20739 get_builder ()->record_debugformat ("DWARF 2");
20740 get_builder ()->record_producer (producer
);
20742 processing_has_namespace_info
= false;
20744 return get_builder ()->get_compunit_symtab ();
20748 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20749 struct dwarf2_cu
*cu
)
20751 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20752 struct comp_unit_head
*cu_header
= &cu
->header
;
20754 /* NOTE drow/2003-01-30: There used to be a comment and some special
20755 code here to turn a symbol with DW_AT_external and a
20756 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20757 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20758 with some versions of binutils) where shared libraries could have
20759 relocations against symbols in their debug information - the
20760 minimal symbol would have the right address, but the debug info
20761 would not. It's no longer necessary, because we will explicitly
20762 apply relocations when we read in the debug information now. */
20764 /* A DW_AT_location attribute with no contents indicates that a
20765 variable has been optimized away. */
20766 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20768 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20772 /* Handle one degenerate form of location expression specially, to
20773 preserve GDB's previous behavior when section offsets are
20774 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20775 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20777 if (attr
->form_is_block ()
20778 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20779 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20780 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20781 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20782 && (DW_BLOCK (attr
)->size
20783 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20785 unsigned int dummy
;
20787 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20788 SET_SYMBOL_VALUE_ADDRESS
20789 (sym
, cu
->header
.read_address (objfile
->obfd
,
20790 DW_BLOCK (attr
)->data
+ 1,
20793 SET_SYMBOL_VALUE_ADDRESS
20794 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20796 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20797 fixup_symbol_section (sym
, objfile
);
20798 SET_SYMBOL_VALUE_ADDRESS
20800 SYMBOL_VALUE_ADDRESS (sym
)
20801 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20805 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20806 expression evaluator, and use LOC_COMPUTED only when necessary
20807 (i.e. when the value of a register or memory location is
20808 referenced, or a thread-local block, etc.). Then again, it might
20809 not be worthwhile. I'm assuming that it isn't unless performance
20810 or memory numbers show me otherwise. */
20812 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20814 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20815 cu
->has_loclist
= true;
20818 /* Given a pointer to a DWARF information entry, figure out if we need
20819 to make a symbol table entry for it, and if so, create a new entry
20820 and return a pointer to it.
20821 If TYPE is NULL, determine symbol type from the die, otherwise
20822 used the passed type.
20823 If SPACE is not NULL, use it to hold the new symbol. If it is
20824 NULL, allocate a new symbol on the objfile's obstack. */
20826 static struct symbol
*
20827 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20828 struct symbol
*space
)
20830 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20831 struct objfile
*objfile
= per_objfile
->objfile
;
20832 struct gdbarch
*gdbarch
= objfile
->arch ();
20833 struct symbol
*sym
= NULL
;
20835 struct attribute
*attr
= NULL
;
20836 struct attribute
*attr2
= NULL
;
20837 CORE_ADDR baseaddr
;
20838 struct pending
**list_to_add
= NULL
;
20840 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20842 baseaddr
= objfile
->text_section_offset ();
20844 name
= dwarf2_name (die
, cu
);
20847 int suppress_add
= 0;
20852 sym
= new (&objfile
->objfile_obstack
) symbol
;
20853 OBJSTAT (objfile
, n_syms
++);
20855 /* Cache this symbol's name and the name's demangled form (if any). */
20856 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20857 /* Fortran does not have mangling standard and the mangling does differ
20858 between gfortran, iFort etc. */
20859 const char *physname
20860 = (cu
->language
== language_fortran
20861 ? dwarf2_full_name (name
, die
, cu
)
20862 : dwarf2_physname (name
, die
, cu
));
20863 const char *linkagename
= dw2_linkage_name (die
, cu
);
20865 if (linkagename
== nullptr || cu
->language
== language_ada
)
20866 sym
->set_linkage_name (physname
);
20869 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20870 sym
->set_linkage_name (linkagename
);
20873 /* Default assumptions.
20874 Use the passed type or decode it from the die. */
20875 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20876 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20878 SYMBOL_TYPE (sym
) = type
;
20880 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20881 attr
= dwarf2_attr (die
,
20882 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20884 if (attr
!= nullptr)
20886 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20889 attr
= dwarf2_attr (die
,
20890 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20892 if (attr
!= nullptr)
20894 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20895 struct file_entry
*fe
;
20897 if (cu
->line_header
!= NULL
)
20898 fe
= cu
->line_header
->file_name_at (file_index
);
20903 complaint (_("file index out of range"));
20905 symbol_set_symtab (sym
, fe
->symtab
);
20911 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20912 if (attr
!= nullptr)
20916 addr
= attr
->value_as_address ();
20917 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20918 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20920 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20921 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20922 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20923 add_symbol_to_list (sym
, cu
->list_in_scope
);
20925 case DW_TAG_subprogram
:
20926 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20928 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20929 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20930 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20931 || cu
->language
== language_ada
20932 || cu
->language
== language_fortran
)
20934 /* Subprograms marked external are stored as a global symbol.
20935 Ada and Fortran subprograms, whether marked external or
20936 not, are always stored as a global symbol, because we want
20937 to be able to access them globally. For instance, we want
20938 to be able to break on a nested subprogram without having
20939 to specify the context. */
20940 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20944 list_to_add
= cu
->list_in_scope
;
20947 case DW_TAG_inlined_subroutine
:
20948 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20950 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20951 SYMBOL_INLINED (sym
) = 1;
20952 list_to_add
= cu
->list_in_scope
;
20954 case DW_TAG_template_value_param
:
20956 /* Fall through. */
20957 case DW_TAG_constant
:
20958 case DW_TAG_variable
:
20959 case DW_TAG_member
:
20960 /* Compilation with minimal debug info may result in
20961 variables with missing type entries. Change the
20962 misleading `void' type to something sensible. */
20963 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20964 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20966 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20967 /* In the case of DW_TAG_member, we should only be called for
20968 static const members. */
20969 if (die
->tag
== DW_TAG_member
)
20971 /* dwarf2_add_field uses die_is_declaration,
20972 so we do the same. */
20973 gdb_assert (die_is_declaration (die
, cu
));
20976 if (attr
!= nullptr)
20978 dwarf2_const_value (attr
, sym
, cu
);
20979 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20982 if (attr2
&& (DW_UNSND (attr2
) != 0))
20983 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20985 list_to_add
= cu
->list_in_scope
;
20989 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20990 if (attr
!= nullptr)
20992 var_decode_location (attr
, sym
, cu
);
20993 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20995 /* Fortran explicitly imports any global symbols to the local
20996 scope by DW_TAG_common_block. */
20997 if (cu
->language
== language_fortran
&& die
->parent
20998 && die
->parent
->tag
== DW_TAG_common_block
)
21001 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21002 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21003 && !per_objfile
->per_bfd
->has_section_at_zero
)
21005 /* When a static variable is eliminated by the linker,
21006 the corresponding debug information is not stripped
21007 out, but the variable address is set to null;
21008 do not add such variables into symbol table. */
21010 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21012 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21013 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21014 && per_objfile
->per_bfd
->can_copy
)
21016 /* A global static variable might be subject to
21017 copy relocation. We first check for a local
21018 minsym, though, because maybe the symbol was
21019 marked hidden, in which case this would not
21021 bound_minimal_symbol found
21022 = (lookup_minimal_symbol_linkage
21023 (sym
->linkage_name (), objfile
));
21024 if (found
.minsym
!= nullptr)
21025 sym
->maybe_copied
= 1;
21028 /* A variable with DW_AT_external is never static,
21029 but it may be block-scoped. */
21031 = ((cu
->list_in_scope
21032 == cu
->get_builder ()->get_file_symbols ())
21033 ? cu
->get_builder ()->get_global_symbols ()
21034 : cu
->list_in_scope
);
21037 list_to_add
= cu
->list_in_scope
;
21041 /* We do not know the address of this symbol.
21042 If it is an external symbol and we have type information
21043 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21044 The address of the variable will then be determined from
21045 the minimal symbol table whenever the variable is
21047 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21049 /* Fortran explicitly imports any global symbols to the local
21050 scope by DW_TAG_common_block. */
21051 if (cu
->language
== language_fortran
&& die
->parent
21052 && die
->parent
->tag
== DW_TAG_common_block
)
21054 /* SYMBOL_CLASS doesn't matter here because
21055 read_common_block is going to reset it. */
21057 list_to_add
= cu
->list_in_scope
;
21059 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21060 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21062 /* A variable with DW_AT_external is never static, but it
21063 may be block-scoped. */
21065 = ((cu
->list_in_scope
21066 == cu
->get_builder ()->get_file_symbols ())
21067 ? cu
->get_builder ()->get_global_symbols ()
21068 : cu
->list_in_scope
);
21070 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21072 else if (!die_is_declaration (die
, cu
))
21074 /* Use the default LOC_OPTIMIZED_OUT class. */
21075 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21077 list_to_add
= cu
->list_in_scope
;
21081 case DW_TAG_formal_parameter
:
21083 /* If we are inside a function, mark this as an argument. If
21084 not, we might be looking at an argument to an inlined function
21085 when we do not have enough information to show inlined frames;
21086 pretend it's a local variable in that case so that the user can
21088 struct context_stack
*curr
21089 = cu
->get_builder ()->get_current_context_stack ();
21090 if (curr
!= nullptr && curr
->name
!= nullptr)
21091 SYMBOL_IS_ARGUMENT (sym
) = 1;
21092 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21093 if (attr
!= nullptr)
21095 var_decode_location (attr
, sym
, cu
);
21097 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21098 if (attr
!= nullptr)
21100 dwarf2_const_value (attr
, sym
, cu
);
21103 list_to_add
= cu
->list_in_scope
;
21106 case DW_TAG_unspecified_parameters
:
21107 /* From varargs functions; gdb doesn't seem to have any
21108 interest in this information, so just ignore it for now.
21111 case DW_TAG_template_type_param
:
21113 /* Fall through. */
21114 case DW_TAG_class_type
:
21115 case DW_TAG_interface_type
:
21116 case DW_TAG_structure_type
:
21117 case DW_TAG_union_type
:
21118 case DW_TAG_set_type
:
21119 case DW_TAG_enumeration_type
:
21120 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21121 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21124 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21125 really ever be static objects: otherwise, if you try
21126 to, say, break of a class's method and you're in a file
21127 which doesn't mention that class, it won't work unless
21128 the check for all static symbols in lookup_symbol_aux
21129 saves you. See the OtherFileClass tests in
21130 gdb.c++/namespace.exp. */
21134 buildsym_compunit
*builder
= cu
->get_builder ();
21136 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21137 && cu
->language
== language_cplus
21138 ? builder
->get_global_symbols ()
21139 : cu
->list_in_scope
);
21141 /* The semantics of C++ state that "struct foo {
21142 ... }" also defines a typedef for "foo". */
21143 if (cu
->language
== language_cplus
21144 || cu
->language
== language_ada
21145 || cu
->language
== language_d
21146 || cu
->language
== language_rust
)
21148 /* The symbol's name is already allocated along
21149 with this objfile, so we don't need to
21150 duplicate it for the type. */
21151 if (SYMBOL_TYPE (sym
)->name () == 0)
21152 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21157 case DW_TAG_typedef
:
21158 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21159 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21160 list_to_add
= cu
->list_in_scope
;
21162 case DW_TAG_base_type
:
21163 case DW_TAG_subrange_type
:
21164 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21165 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21166 list_to_add
= cu
->list_in_scope
;
21168 case DW_TAG_enumerator
:
21169 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21170 if (attr
!= nullptr)
21172 dwarf2_const_value (attr
, sym
, cu
);
21175 /* NOTE: carlton/2003-11-10: See comment above in the
21176 DW_TAG_class_type, etc. block. */
21179 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21180 && cu
->language
== language_cplus
21181 ? cu
->get_builder ()->get_global_symbols ()
21182 : cu
->list_in_scope
);
21185 case DW_TAG_imported_declaration
:
21186 case DW_TAG_namespace
:
21187 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21188 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21190 case DW_TAG_module
:
21191 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21192 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21193 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21195 case DW_TAG_common_block
:
21196 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21197 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21198 add_symbol_to_list (sym
, cu
->list_in_scope
);
21201 /* Not a tag we recognize. Hopefully we aren't processing
21202 trash data, but since we must specifically ignore things
21203 we don't recognize, there is nothing else we should do at
21205 complaint (_("unsupported tag: '%s'"),
21206 dwarf_tag_name (die
->tag
));
21212 sym
->hash_next
= objfile
->template_symbols
;
21213 objfile
->template_symbols
= sym
;
21214 list_to_add
= NULL
;
21217 if (list_to_add
!= NULL
)
21218 add_symbol_to_list (sym
, list_to_add
);
21220 /* For the benefit of old versions of GCC, check for anonymous
21221 namespaces based on the demangled name. */
21222 if (!cu
->processing_has_namespace_info
21223 && cu
->language
== language_cplus
)
21224 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21229 /* Given an attr with a DW_FORM_dataN value in host byte order,
21230 zero-extend it as appropriate for the symbol's type. The DWARF
21231 standard (v4) is not entirely clear about the meaning of using
21232 DW_FORM_dataN for a constant with a signed type, where the type is
21233 wider than the data. The conclusion of a discussion on the DWARF
21234 list was that this is unspecified. We choose to always zero-extend
21235 because that is the interpretation long in use by GCC. */
21238 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21239 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21241 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21242 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21243 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21244 LONGEST l
= DW_UNSND (attr
);
21246 if (bits
< sizeof (*value
) * 8)
21248 l
&= ((LONGEST
) 1 << bits
) - 1;
21251 else if (bits
== sizeof (*value
) * 8)
21255 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21256 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21263 /* Read a constant value from an attribute. Either set *VALUE, or if
21264 the value does not fit in *VALUE, set *BYTES - either already
21265 allocated on the objfile obstack, or newly allocated on OBSTACK,
21266 or, set *BATON, if we translated the constant to a location
21270 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21271 const char *name
, struct obstack
*obstack
,
21272 struct dwarf2_cu
*cu
,
21273 LONGEST
*value
, const gdb_byte
**bytes
,
21274 struct dwarf2_locexpr_baton
**baton
)
21276 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21277 struct objfile
*objfile
= per_objfile
->objfile
;
21278 struct comp_unit_head
*cu_header
= &cu
->header
;
21279 struct dwarf_block
*blk
;
21280 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21281 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21287 switch (attr
->form
)
21290 case DW_FORM_addrx
:
21291 case DW_FORM_GNU_addr_index
:
21295 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21296 dwarf2_const_value_length_mismatch_complaint (name
,
21297 cu_header
->addr_size
,
21298 TYPE_LENGTH (type
));
21299 /* Symbols of this form are reasonably rare, so we just
21300 piggyback on the existing location code rather than writing
21301 a new implementation of symbol_computed_ops. */
21302 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21303 (*baton
)->per_objfile
= per_objfile
;
21304 (*baton
)->per_cu
= cu
->per_cu
;
21305 gdb_assert ((*baton
)->per_cu
);
21307 (*baton
)->size
= 2 + cu_header
->addr_size
;
21308 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21309 (*baton
)->data
= data
;
21311 data
[0] = DW_OP_addr
;
21312 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21313 byte_order
, DW_ADDR (attr
));
21314 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21317 case DW_FORM_string
:
21320 case DW_FORM_GNU_str_index
:
21321 case DW_FORM_GNU_strp_alt
:
21322 /* DW_STRING is already allocated on the objfile obstack, point
21324 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21326 case DW_FORM_block1
:
21327 case DW_FORM_block2
:
21328 case DW_FORM_block4
:
21329 case DW_FORM_block
:
21330 case DW_FORM_exprloc
:
21331 case DW_FORM_data16
:
21332 blk
= DW_BLOCK (attr
);
21333 if (TYPE_LENGTH (type
) != blk
->size
)
21334 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21335 TYPE_LENGTH (type
));
21336 *bytes
= blk
->data
;
21339 /* The DW_AT_const_value attributes are supposed to carry the
21340 symbol's value "represented as it would be on the target
21341 architecture." By the time we get here, it's already been
21342 converted to host endianness, so we just need to sign- or
21343 zero-extend it as appropriate. */
21344 case DW_FORM_data1
:
21345 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21347 case DW_FORM_data2
:
21348 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21350 case DW_FORM_data4
:
21351 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21353 case DW_FORM_data8
:
21354 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21357 case DW_FORM_sdata
:
21358 case DW_FORM_implicit_const
:
21359 *value
= DW_SND (attr
);
21362 case DW_FORM_udata
:
21363 *value
= DW_UNSND (attr
);
21367 complaint (_("unsupported const value attribute form: '%s'"),
21368 dwarf_form_name (attr
->form
));
21375 /* Copy constant value from an attribute to a symbol. */
21378 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21379 struct dwarf2_cu
*cu
)
21381 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21383 const gdb_byte
*bytes
;
21384 struct dwarf2_locexpr_baton
*baton
;
21386 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21387 sym
->print_name (),
21388 &objfile
->objfile_obstack
, cu
,
21389 &value
, &bytes
, &baton
);
21393 SYMBOL_LOCATION_BATON (sym
) = baton
;
21394 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21396 else if (bytes
!= NULL
)
21398 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21399 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21403 SYMBOL_VALUE (sym
) = value
;
21404 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21408 /* Return the type of the die in question using its DW_AT_type attribute. */
21410 static struct type
*
21411 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21413 struct attribute
*type_attr
;
21415 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21418 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21419 /* A missing DW_AT_type represents a void type. */
21420 return objfile_type (objfile
)->builtin_void
;
21423 return lookup_die_type (die
, type_attr
, cu
);
21426 /* True iff CU's producer generates GNAT Ada auxiliary information
21427 that allows to find parallel types through that information instead
21428 of having to do expensive parallel lookups by type name. */
21431 need_gnat_info (struct dwarf2_cu
*cu
)
21433 /* Assume that the Ada compiler was GNAT, which always produces
21434 the auxiliary information. */
21435 return (cu
->language
== language_ada
);
21438 /* Return the auxiliary type of the die in question using its
21439 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21440 attribute is not present. */
21442 static struct type
*
21443 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21445 struct attribute
*type_attr
;
21447 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21451 return lookup_die_type (die
, type_attr
, cu
);
21454 /* If DIE has a descriptive_type attribute, then set the TYPE's
21455 descriptive type accordingly. */
21458 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21459 struct dwarf2_cu
*cu
)
21461 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21463 if (descriptive_type
)
21465 ALLOCATE_GNAT_AUX_TYPE (type
);
21466 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21470 /* Return the containing type of the die in question using its
21471 DW_AT_containing_type attribute. */
21473 static struct type
*
21474 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21476 struct attribute
*type_attr
;
21477 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21479 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21481 error (_("Dwarf Error: Problem turning containing type into gdb type "
21482 "[in module %s]"), objfile_name (objfile
));
21484 return lookup_die_type (die
, type_attr
, cu
);
21487 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21489 static struct type
*
21490 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21492 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21493 struct objfile
*objfile
= per_objfile
->objfile
;
21496 std::string message
21497 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21498 objfile_name (objfile
),
21499 sect_offset_str (cu
->header
.sect_off
),
21500 sect_offset_str (die
->sect_off
));
21501 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21503 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21506 /* Look up the type of DIE in CU using its type attribute ATTR.
21507 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21508 DW_AT_containing_type.
21509 If there is no type substitute an error marker. */
21511 static struct type
*
21512 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21513 struct dwarf2_cu
*cu
)
21515 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21516 struct objfile
*objfile
= per_objfile
->objfile
;
21517 struct type
*this_type
;
21519 gdb_assert (attr
->name
== DW_AT_type
21520 || attr
->name
== DW_AT_GNAT_descriptive_type
21521 || attr
->name
== DW_AT_containing_type
);
21523 /* First see if we have it cached. */
21525 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21527 struct dwarf2_per_cu_data
*per_cu
;
21528 sect_offset sect_off
= attr
->get_ref_die_offset ();
21530 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
21531 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
21533 else if (attr
->form_is_ref ())
21535 sect_offset sect_off
= attr
->get_ref_die_offset ();
21537 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
21539 else if (attr
->form
== DW_FORM_ref_sig8
)
21541 ULONGEST signature
= DW_SIGNATURE (attr
);
21543 return get_signatured_type (die
, signature
, cu
);
21547 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21548 " at %s [in module %s]"),
21549 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21550 objfile_name (objfile
));
21551 return build_error_marker_type (cu
, die
);
21554 /* If not cached we need to read it in. */
21556 if (this_type
== NULL
)
21558 struct die_info
*type_die
= NULL
;
21559 struct dwarf2_cu
*type_cu
= cu
;
21561 if (attr
->form_is_ref ())
21562 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21563 if (type_die
== NULL
)
21564 return build_error_marker_type (cu
, die
);
21565 /* If we find the type now, it's probably because the type came
21566 from an inter-CU reference and the type's CU got expanded before
21568 this_type
= read_type_die (type_die
, type_cu
);
21571 /* If we still don't have a type use an error marker. */
21573 if (this_type
== NULL
)
21574 return build_error_marker_type (cu
, die
);
21579 /* Return the type in DIE, CU.
21580 Returns NULL for invalid types.
21582 This first does a lookup in die_type_hash,
21583 and only reads the die in if necessary.
21585 NOTE: This can be called when reading in partial or full symbols. */
21587 static struct type
*
21588 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21590 struct type
*this_type
;
21592 this_type
= get_die_type (die
, cu
);
21596 return read_type_die_1 (die
, cu
);
21599 /* Read the type in DIE, CU.
21600 Returns NULL for invalid types. */
21602 static struct type
*
21603 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21605 struct type
*this_type
= NULL
;
21609 case DW_TAG_class_type
:
21610 case DW_TAG_interface_type
:
21611 case DW_TAG_structure_type
:
21612 case DW_TAG_union_type
:
21613 this_type
= read_structure_type (die
, cu
);
21615 case DW_TAG_enumeration_type
:
21616 this_type
= read_enumeration_type (die
, cu
);
21618 case DW_TAG_subprogram
:
21619 case DW_TAG_subroutine_type
:
21620 case DW_TAG_inlined_subroutine
:
21621 this_type
= read_subroutine_type (die
, cu
);
21623 case DW_TAG_array_type
:
21624 this_type
= read_array_type (die
, cu
);
21626 case DW_TAG_set_type
:
21627 this_type
= read_set_type (die
, cu
);
21629 case DW_TAG_pointer_type
:
21630 this_type
= read_tag_pointer_type (die
, cu
);
21632 case DW_TAG_ptr_to_member_type
:
21633 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21635 case DW_TAG_reference_type
:
21636 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21638 case DW_TAG_rvalue_reference_type
:
21639 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21641 case DW_TAG_const_type
:
21642 this_type
= read_tag_const_type (die
, cu
);
21644 case DW_TAG_volatile_type
:
21645 this_type
= read_tag_volatile_type (die
, cu
);
21647 case DW_TAG_restrict_type
:
21648 this_type
= read_tag_restrict_type (die
, cu
);
21650 case DW_TAG_string_type
:
21651 this_type
= read_tag_string_type (die
, cu
);
21653 case DW_TAG_typedef
:
21654 this_type
= read_typedef (die
, cu
);
21656 case DW_TAG_subrange_type
:
21657 this_type
= read_subrange_type (die
, cu
);
21659 case DW_TAG_base_type
:
21660 this_type
= read_base_type (die
, cu
);
21662 case DW_TAG_unspecified_type
:
21663 this_type
= read_unspecified_type (die
, cu
);
21665 case DW_TAG_namespace
:
21666 this_type
= read_namespace_type (die
, cu
);
21668 case DW_TAG_module
:
21669 this_type
= read_module_type (die
, cu
);
21671 case DW_TAG_atomic_type
:
21672 this_type
= read_tag_atomic_type (die
, cu
);
21675 complaint (_("unexpected tag in read_type_die: '%s'"),
21676 dwarf_tag_name (die
->tag
));
21683 /* See if we can figure out if the class lives in a namespace. We do
21684 this by looking for a member function; its demangled name will
21685 contain namespace info, if there is any.
21686 Return the computed name or NULL.
21687 Space for the result is allocated on the objfile's obstack.
21688 This is the full-die version of guess_partial_die_structure_name.
21689 In this case we know DIE has no useful parent. */
21691 static const char *
21692 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21694 struct die_info
*spec_die
;
21695 struct dwarf2_cu
*spec_cu
;
21696 struct die_info
*child
;
21697 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21700 spec_die
= die_specification (die
, &spec_cu
);
21701 if (spec_die
!= NULL
)
21707 for (child
= die
->child
;
21709 child
= child
->sibling
)
21711 if (child
->tag
== DW_TAG_subprogram
)
21713 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21715 if (linkage_name
!= NULL
)
21717 gdb::unique_xmalloc_ptr
<char> actual_name
21718 (cu
->language_defn
->class_name_from_physname (linkage_name
));
21719 const char *name
= NULL
;
21721 if (actual_name
!= NULL
)
21723 const char *die_name
= dwarf2_name (die
, cu
);
21725 if (die_name
!= NULL
21726 && strcmp (die_name
, actual_name
.get ()) != 0)
21728 /* Strip off the class name from the full name.
21729 We want the prefix. */
21730 int die_name_len
= strlen (die_name
);
21731 int actual_name_len
= strlen (actual_name
.get ());
21732 const char *ptr
= actual_name
.get ();
21734 /* Test for '::' as a sanity check. */
21735 if (actual_name_len
> die_name_len
+ 2
21736 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21737 name
= obstack_strndup (
21738 &objfile
->per_bfd
->storage_obstack
,
21739 ptr
, actual_name_len
- die_name_len
- 2);
21750 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21751 prefix part in such case. See
21752 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21754 static const char *
21755 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21757 struct attribute
*attr
;
21760 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21761 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21764 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21767 attr
= dw2_linkage_name_attr (die
, cu
);
21768 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21771 /* dwarf2_name had to be already called. */
21772 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21774 /* Strip the base name, keep any leading namespaces/classes. */
21775 base
= strrchr (DW_STRING (attr
), ':');
21776 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21779 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21780 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21782 &base
[-1] - DW_STRING (attr
));
21785 /* Return the name of the namespace/class that DIE is defined within,
21786 or "" if we can't tell. The caller should not xfree the result.
21788 For example, if we're within the method foo() in the following
21798 then determine_prefix on foo's die will return "N::C". */
21800 static const char *
21801 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21803 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21804 struct die_info
*parent
, *spec_die
;
21805 struct dwarf2_cu
*spec_cu
;
21806 struct type
*parent_type
;
21807 const char *retval
;
21809 if (cu
->language
!= language_cplus
21810 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21811 && cu
->language
!= language_rust
)
21814 retval
= anonymous_struct_prefix (die
, cu
);
21818 /* We have to be careful in the presence of DW_AT_specification.
21819 For example, with GCC 3.4, given the code
21823 // Definition of N::foo.
21827 then we'll have a tree of DIEs like this:
21829 1: DW_TAG_compile_unit
21830 2: DW_TAG_namespace // N
21831 3: DW_TAG_subprogram // declaration of N::foo
21832 4: DW_TAG_subprogram // definition of N::foo
21833 DW_AT_specification // refers to die #3
21835 Thus, when processing die #4, we have to pretend that we're in
21836 the context of its DW_AT_specification, namely the contex of die
21839 spec_die
= die_specification (die
, &spec_cu
);
21840 if (spec_die
== NULL
)
21841 parent
= die
->parent
;
21844 parent
= spec_die
->parent
;
21848 if (parent
== NULL
)
21850 else if (parent
->building_fullname
)
21853 const char *parent_name
;
21855 /* It has been seen on RealView 2.2 built binaries,
21856 DW_TAG_template_type_param types actually _defined_ as
21857 children of the parent class:
21860 template class <class Enum> Class{};
21861 Class<enum E> class_e;
21863 1: DW_TAG_class_type (Class)
21864 2: DW_TAG_enumeration_type (E)
21865 3: DW_TAG_enumerator (enum1:0)
21866 3: DW_TAG_enumerator (enum2:1)
21868 2: DW_TAG_template_type_param
21869 DW_AT_type DW_FORM_ref_udata (E)
21871 Besides being broken debug info, it can put GDB into an
21872 infinite loop. Consider:
21874 When we're building the full name for Class<E>, we'll start
21875 at Class, and go look over its template type parameters,
21876 finding E. We'll then try to build the full name of E, and
21877 reach here. We're now trying to build the full name of E,
21878 and look over the parent DIE for containing scope. In the
21879 broken case, if we followed the parent DIE of E, we'd again
21880 find Class, and once again go look at its template type
21881 arguments, etc., etc. Simply don't consider such parent die
21882 as source-level parent of this die (it can't be, the language
21883 doesn't allow it), and break the loop here. */
21884 name
= dwarf2_name (die
, cu
);
21885 parent_name
= dwarf2_name (parent
, cu
);
21886 complaint (_("template param type '%s' defined within parent '%s'"),
21887 name
? name
: "<unknown>",
21888 parent_name
? parent_name
: "<unknown>");
21892 switch (parent
->tag
)
21894 case DW_TAG_namespace
:
21895 parent_type
= read_type_die (parent
, cu
);
21896 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21897 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21898 Work around this problem here. */
21899 if (cu
->language
== language_cplus
21900 && strcmp (parent_type
->name (), "::") == 0)
21902 /* We give a name to even anonymous namespaces. */
21903 return parent_type
->name ();
21904 case DW_TAG_class_type
:
21905 case DW_TAG_interface_type
:
21906 case DW_TAG_structure_type
:
21907 case DW_TAG_union_type
:
21908 case DW_TAG_module
:
21909 parent_type
= read_type_die (parent
, cu
);
21910 if (parent_type
->name () != NULL
)
21911 return parent_type
->name ();
21913 /* An anonymous structure is only allowed non-static data
21914 members; no typedefs, no member functions, et cetera.
21915 So it does not need a prefix. */
21917 case DW_TAG_compile_unit
:
21918 case DW_TAG_partial_unit
:
21919 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21920 if (cu
->language
== language_cplus
21921 && !per_objfile
->per_bfd
->types
.empty ()
21922 && die
->child
!= NULL
21923 && (die
->tag
== DW_TAG_class_type
21924 || die
->tag
== DW_TAG_structure_type
21925 || die
->tag
== DW_TAG_union_type
))
21927 const char *name
= guess_full_die_structure_name (die
, cu
);
21932 case DW_TAG_subprogram
:
21933 /* Nested subroutines in Fortran get a prefix with the name
21934 of the parent's subroutine. */
21935 if (cu
->language
== language_fortran
)
21937 if ((die
->tag
== DW_TAG_subprogram
)
21938 && (dwarf2_name (parent
, cu
) != NULL
))
21939 return dwarf2_name (parent
, cu
);
21941 return determine_prefix (parent
, cu
);
21942 case DW_TAG_enumeration_type
:
21943 parent_type
= read_type_die (parent
, cu
);
21944 if (TYPE_DECLARED_CLASS (parent_type
))
21946 if (parent_type
->name () != NULL
)
21947 return parent_type
->name ();
21950 /* Fall through. */
21952 return determine_prefix (parent
, cu
);
21956 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21957 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21958 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21959 an obconcat, otherwise allocate storage for the result. The CU argument is
21960 used to determine the language and hence, the appropriate separator. */
21962 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21965 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21966 int physname
, struct dwarf2_cu
*cu
)
21968 const char *lead
= "";
21971 if (suffix
== NULL
|| suffix
[0] == '\0'
21972 || prefix
== NULL
|| prefix
[0] == '\0')
21974 else if (cu
->language
== language_d
)
21976 /* For D, the 'main' function could be defined in any module, but it
21977 should never be prefixed. */
21978 if (strcmp (suffix
, "D main") == 0)
21986 else if (cu
->language
== language_fortran
&& physname
)
21988 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21989 DW_AT_MIPS_linkage_name is preferred and used instead. */
21997 if (prefix
== NULL
)
21999 if (suffix
== NULL
)
22006 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22008 strcpy (retval
, lead
);
22009 strcat (retval
, prefix
);
22010 strcat (retval
, sep
);
22011 strcat (retval
, suffix
);
22016 /* We have an obstack. */
22017 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22021 /* Get name of a die, return NULL if not found. */
22023 static const char *
22024 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22025 struct objfile
*objfile
)
22027 if (name
&& cu
->language
== language_cplus
)
22029 gdb::unique_xmalloc_ptr
<char> canon_name
22030 = cp_canonicalize_string (name
);
22032 if (canon_name
!= nullptr)
22033 name
= objfile
->intern (canon_name
.get ());
22039 /* Get name of a die, return NULL if not found.
22040 Anonymous namespaces are converted to their magic string. */
22042 static const char *
22043 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22045 struct attribute
*attr
;
22046 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22048 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22049 if ((!attr
|| !DW_STRING (attr
))
22050 && die
->tag
!= DW_TAG_namespace
22051 && die
->tag
!= DW_TAG_class_type
22052 && die
->tag
!= DW_TAG_interface_type
22053 && die
->tag
!= DW_TAG_structure_type
22054 && die
->tag
!= DW_TAG_union_type
)
22059 case DW_TAG_compile_unit
:
22060 case DW_TAG_partial_unit
:
22061 /* Compilation units have a DW_AT_name that is a filename, not
22062 a source language identifier. */
22063 case DW_TAG_enumeration_type
:
22064 case DW_TAG_enumerator
:
22065 /* These tags always have simple identifiers already; no need
22066 to canonicalize them. */
22067 return DW_STRING (attr
);
22069 case DW_TAG_namespace
:
22070 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22071 return DW_STRING (attr
);
22072 return CP_ANONYMOUS_NAMESPACE_STR
;
22074 case DW_TAG_class_type
:
22075 case DW_TAG_interface_type
:
22076 case DW_TAG_structure_type
:
22077 case DW_TAG_union_type
:
22078 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22079 structures or unions. These were of the form "._%d" in GCC 4.1,
22080 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22081 and GCC 4.4. We work around this problem by ignoring these. */
22082 if (attr
&& DW_STRING (attr
)
22083 && (startswith (DW_STRING (attr
), "._")
22084 || startswith (DW_STRING (attr
), "<anonymous")))
22087 /* GCC might emit a nameless typedef that has a linkage name. See
22088 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22089 if (!attr
|| DW_STRING (attr
) == NULL
)
22091 attr
= dw2_linkage_name_attr (die
, cu
);
22092 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22095 /* Avoid demangling DW_STRING (attr) the second time on a second
22096 call for the same DIE. */
22097 if (!DW_STRING_IS_CANONICAL (attr
))
22099 gdb::unique_xmalloc_ptr
<char> demangled
22100 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22101 if (demangled
== nullptr)
22104 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
22105 DW_STRING_IS_CANONICAL (attr
) = 1;
22108 /* Strip any leading namespaces/classes, keep only the base name.
22109 DW_AT_name for named DIEs does not contain the prefixes. */
22110 const char *base
= strrchr (DW_STRING (attr
), ':');
22111 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22114 return DW_STRING (attr
);
22122 if (!DW_STRING_IS_CANONICAL (attr
))
22124 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22126 DW_STRING_IS_CANONICAL (attr
) = 1;
22128 return DW_STRING (attr
);
22131 /* Return the die that this die in an extension of, or NULL if there
22132 is none. *EXT_CU is the CU containing DIE on input, and the CU
22133 containing the return value on output. */
22135 static struct die_info
*
22136 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22138 struct attribute
*attr
;
22140 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22144 return follow_die_ref (die
, attr
, ext_cu
);
22148 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22152 print_spaces (indent
, f
);
22153 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22154 dwarf_tag_name (die
->tag
), die
->abbrev
,
22155 sect_offset_str (die
->sect_off
));
22157 if (die
->parent
!= NULL
)
22159 print_spaces (indent
, f
);
22160 fprintf_unfiltered (f
, " parent at offset: %s\n",
22161 sect_offset_str (die
->parent
->sect_off
));
22164 print_spaces (indent
, f
);
22165 fprintf_unfiltered (f
, " has children: %s\n",
22166 dwarf_bool_name (die
->child
!= NULL
));
22168 print_spaces (indent
, f
);
22169 fprintf_unfiltered (f
, " attributes:\n");
22171 for (i
= 0; i
< die
->num_attrs
; ++i
)
22173 print_spaces (indent
, f
);
22174 fprintf_unfiltered (f
, " %s (%s) ",
22175 dwarf_attr_name (die
->attrs
[i
].name
),
22176 dwarf_form_name (die
->attrs
[i
].form
));
22178 switch (die
->attrs
[i
].form
)
22181 case DW_FORM_addrx
:
22182 case DW_FORM_GNU_addr_index
:
22183 fprintf_unfiltered (f
, "address: ");
22184 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22186 case DW_FORM_block2
:
22187 case DW_FORM_block4
:
22188 case DW_FORM_block
:
22189 case DW_FORM_block1
:
22190 fprintf_unfiltered (f
, "block: size %s",
22191 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22193 case DW_FORM_exprloc
:
22194 fprintf_unfiltered (f
, "expression: size %s",
22195 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22197 case DW_FORM_data16
:
22198 fprintf_unfiltered (f
, "constant of 16 bytes");
22200 case DW_FORM_ref_addr
:
22201 fprintf_unfiltered (f
, "ref address: ");
22202 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22204 case DW_FORM_GNU_ref_alt
:
22205 fprintf_unfiltered (f
, "alt ref address: ");
22206 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22212 case DW_FORM_ref_udata
:
22213 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22214 (long) (DW_UNSND (&die
->attrs
[i
])));
22216 case DW_FORM_data1
:
22217 case DW_FORM_data2
:
22218 case DW_FORM_data4
:
22219 case DW_FORM_data8
:
22220 case DW_FORM_udata
:
22221 case DW_FORM_sdata
:
22222 fprintf_unfiltered (f
, "constant: %s",
22223 pulongest (DW_UNSND (&die
->attrs
[i
])));
22225 case DW_FORM_sec_offset
:
22226 fprintf_unfiltered (f
, "section offset: %s",
22227 pulongest (DW_UNSND (&die
->attrs
[i
])));
22229 case DW_FORM_ref_sig8
:
22230 fprintf_unfiltered (f
, "signature: %s",
22231 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22233 case DW_FORM_string
:
22235 case DW_FORM_line_strp
:
22237 case DW_FORM_GNU_str_index
:
22238 case DW_FORM_GNU_strp_alt
:
22239 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22240 DW_STRING (&die
->attrs
[i
])
22241 ? DW_STRING (&die
->attrs
[i
]) : "",
22242 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22245 if (DW_UNSND (&die
->attrs
[i
]))
22246 fprintf_unfiltered (f
, "flag: TRUE");
22248 fprintf_unfiltered (f
, "flag: FALSE");
22250 case DW_FORM_flag_present
:
22251 fprintf_unfiltered (f
, "flag: TRUE");
22253 case DW_FORM_indirect
:
22254 /* The reader will have reduced the indirect form to
22255 the "base form" so this form should not occur. */
22256 fprintf_unfiltered (f
,
22257 "unexpected attribute form: DW_FORM_indirect");
22259 case DW_FORM_implicit_const
:
22260 fprintf_unfiltered (f
, "constant: %s",
22261 plongest (DW_SND (&die
->attrs
[i
])));
22264 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22265 die
->attrs
[i
].form
);
22268 fprintf_unfiltered (f
, "\n");
22273 dump_die_for_error (struct die_info
*die
)
22275 dump_die_shallow (gdb_stderr
, 0, die
);
22279 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22281 int indent
= level
* 4;
22283 gdb_assert (die
!= NULL
);
22285 if (level
>= max_level
)
22288 dump_die_shallow (f
, indent
, die
);
22290 if (die
->child
!= NULL
)
22292 print_spaces (indent
, f
);
22293 fprintf_unfiltered (f
, " Children:");
22294 if (level
+ 1 < max_level
)
22296 fprintf_unfiltered (f
, "\n");
22297 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22301 fprintf_unfiltered (f
,
22302 " [not printed, max nesting level reached]\n");
22306 if (die
->sibling
!= NULL
&& level
> 0)
22308 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22312 /* This is called from the pdie macro in gdbinit.in.
22313 It's not static so gcc will keep a copy callable from gdb. */
22316 dump_die (struct die_info
*die
, int max_level
)
22318 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22322 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22326 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22327 to_underlying (die
->sect_off
),
22333 /* Follow reference or signature attribute ATTR of SRC_DIE.
22334 On entry *REF_CU is the CU of SRC_DIE.
22335 On exit *REF_CU is the CU of the result. */
22337 static struct die_info
*
22338 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22339 struct dwarf2_cu
**ref_cu
)
22341 struct die_info
*die
;
22343 if (attr
->form_is_ref ())
22344 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22345 else if (attr
->form
== DW_FORM_ref_sig8
)
22346 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22349 dump_die_for_error (src_die
);
22350 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22351 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22357 /* Follow reference OFFSET.
22358 On entry *REF_CU is the CU of the source die referencing OFFSET.
22359 On exit *REF_CU is the CU of the result.
22360 Returns NULL if OFFSET is invalid. */
22362 static struct die_info
*
22363 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22364 struct dwarf2_cu
**ref_cu
)
22366 struct die_info temp_die
;
22367 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22368 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22370 gdb_assert (cu
->per_cu
!= NULL
);
22374 if (cu
->per_cu
->is_debug_types
)
22376 /* .debug_types CUs cannot reference anything outside their CU.
22377 If they need to, they have to reference a signatured type via
22378 DW_FORM_ref_sig8. */
22379 if (!cu
->header
.offset_in_cu_p (sect_off
))
22382 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22383 || !cu
->header
.offset_in_cu_p (sect_off
))
22385 struct dwarf2_per_cu_data
*per_cu
;
22387 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22390 /* If necessary, add it to the queue and load its DIEs. */
22391 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
22392 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
22394 target_cu
= per_objfile
->get_cu (per_cu
);
22396 else if (cu
->dies
== NULL
)
22398 /* We're loading full DIEs during partial symbol reading. */
22399 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
22400 load_full_comp_unit (cu
->per_cu
, per_objfile
, false, language_minimal
);
22403 *ref_cu
= target_cu
;
22404 temp_die
.sect_off
= sect_off
;
22406 if (target_cu
!= cu
)
22407 target_cu
->ancestor
= cu
;
22409 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22411 to_underlying (sect_off
));
22414 /* Follow reference attribute ATTR of SRC_DIE.
22415 On entry *REF_CU is the CU of SRC_DIE.
22416 On exit *REF_CU is the CU of the result. */
22418 static struct die_info
*
22419 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22420 struct dwarf2_cu
**ref_cu
)
22422 sect_offset sect_off
= attr
->get_ref_die_offset ();
22423 struct dwarf2_cu
*cu
= *ref_cu
;
22424 struct die_info
*die
;
22426 die
= follow_die_offset (sect_off
,
22427 (attr
->form
== DW_FORM_GNU_ref_alt
22428 || cu
->per_cu
->is_dwz
),
22431 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22432 "at %s [in module %s]"),
22433 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22434 objfile_name (cu
->per_objfile
->objfile
));
22441 struct dwarf2_locexpr_baton
22442 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22443 dwarf2_per_cu_data
*per_cu
,
22444 dwarf2_per_objfile
*per_objfile
,
22445 CORE_ADDR (*get_frame_pc
) (void *baton
),
22446 void *baton
, bool resolve_abstract_p
)
22448 struct die_info
*die
;
22449 struct attribute
*attr
;
22450 struct dwarf2_locexpr_baton retval
;
22451 struct objfile
*objfile
= per_objfile
->objfile
;
22453 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22455 cu
= load_cu (per_cu
, per_objfile
, false);
22459 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22460 Instead just throw an error, not much else we can do. */
22461 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22462 sect_offset_str (sect_off
), objfile_name (objfile
));
22465 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22467 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22468 sect_offset_str (sect_off
), objfile_name (objfile
));
22470 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22471 if (!attr
&& resolve_abstract_p
22472 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22473 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22475 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22476 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22477 struct gdbarch
*gdbarch
= objfile
->arch ();
22479 for (const auto &cand_off
22480 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22482 struct dwarf2_cu
*cand_cu
= cu
;
22483 struct die_info
*cand
22484 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22487 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22490 CORE_ADDR pc_low
, pc_high
;
22491 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22492 if (pc_low
== ((CORE_ADDR
) -1))
22494 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22495 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22496 if (!(pc_low
<= pc
&& pc
< pc_high
))
22500 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22507 /* DWARF: "If there is no such attribute, then there is no effect.".
22508 DATA is ignored if SIZE is 0. */
22510 retval
.data
= NULL
;
22513 else if (attr
->form_is_section_offset ())
22515 struct dwarf2_loclist_baton loclist_baton
;
22516 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22519 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22521 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22523 retval
.size
= size
;
22527 if (!attr
->form_is_block ())
22528 error (_("Dwarf Error: DIE at %s referenced in module %s "
22529 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22530 sect_offset_str (sect_off
), objfile_name (objfile
));
22532 retval
.data
= DW_BLOCK (attr
)->data
;
22533 retval
.size
= DW_BLOCK (attr
)->size
;
22535 retval
.per_objfile
= per_objfile
;
22536 retval
.per_cu
= cu
->per_cu
;
22538 per_objfile
->age_comp_units ();
22545 struct dwarf2_locexpr_baton
22546 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22547 dwarf2_per_cu_data
*per_cu
,
22548 dwarf2_per_objfile
*per_objfile
,
22549 CORE_ADDR (*get_frame_pc
) (void *baton
),
22552 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22554 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22555 get_frame_pc
, baton
);
22558 /* Write a constant of a given type as target-ordered bytes into
22561 static const gdb_byte
*
22562 write_constant_as_bytes (struct obstack
*obstack
,
22563 enum bfd_endian byte_order
,
22570 *len
= TYPE_LENGTH (type
);
22571 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22572 store_unsigned_integer (result
, *len
, byte_order
, value
);
22580 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22581 dwarf2_per_cu_data
*per_cu
,
22582 dwarf2_per_objfile
*per_objfile
,
22586 struct die_info
*die
;
22587 struct attribute
*attr
;
22588 const gdb_byte
*result
= NULL
;
22591 enum bfd_endian byte_order
;
22592 struct objfile
*objfile
= per_objfile
->objfile
;
22594 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22596 cu
= load_cu (per_cu
, per_objfile
, false);
22600 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22601 Instead just throw an error, not much else we can do. */
22602 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22603 sect_offset_str (sect_off
), objfile_name (objfile
));
22606 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22608 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22609 sect_offset_str (sect_off
), objfile_name (objfile
));
22611 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22615 byte_order
= (bfd_big_endian (objfile
->obfd
)
22616 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22618 switch (attr
->form
)
22621 case DW_FORM_addrx
:
22622 case DW_FORM_GNU_addr_index
:
22626 *len
= cu
->header
.addr_size
;
22627 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22628 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22632 case DW_FORM_string
:
22635 case DW_FORM_GNU_str_index
:
22636 case DW_FORM_GNU_strp_alt
:
22637 /* DW_STRING is already allocated on the objfile obstack, point
22639 result
= (const gdb_byte
*) DW_STRING (attr
);
22640 *len
= strlen (DW_STRING (attr
));
22642 case DW_FORM_block1
:
22643 case DW_FORM_block2
:
22644 case DW_FORM_block4
:
22645 case DW_FORM_block
:
22646 case DW_FORM_exprloc
:
22647 case DW_FORM_data16
:
22648 result
= DW_BLOCK (attr
)->data
;
22649 *len
= DW_BLOCK (attr
)->size
;
22652 /* The DW_AT_const_value attributes are supposed to carry the
22653 symbol's value "represented as it would be on the target
22654 architecture." By the time we get here, it's already been
22655 converted to host endianness, so we just need to sign- or
22656 zero-extend it as appropriate. */
22657 case DW_FORM_data1
:
22658 type
= die_type (die
, cu
);
22659 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22660 if (result
== NULL
)
22661 result
= write_constant_as_bytes (obstack
, byte_order
,
22664 case DW_FORM_data2
:
22665 type
= die_type (die
, cu
);
22666 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22667 if (result
== NULL
)
22668 result
= write_constant_as_bytes (obstack
, byte_order
,
22671 case DW_FORM_data4
:
22672 type
= die_type (die
, cu
);
22673 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22674 if (result
== NULL
)
22675 result
= write_constant_as_bytes (obstack
, byte_order
,
22678 case DW_FORM_data8
:
22679 type
= die_type (die
, cu
);
22680 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22681 if (result
== NULL
)
22682 result
= write_constant_as_bytes (obstack
, byte_order
,
22686 case DW_FORM_sdata
:
22687 case DW_FORM_implicit_const
:
22688 type
= die_type (die
, cu
);
22689 result
= write_constant_as_bytes (obstack
, byte_order
,
22690 type
, DW_SND (attr
), len
);
22693 case DW_FORM_udata
:
22694 type
= die_type (die
, cu
);
22695 result
= write_constant_as_bytes (obstack
, byte_order
,
22696 type
, DW_UNSND (attr
), len
);
22700 complaint (_("unsupported const value attribute form: '%s'"),
22701 dwarf_form_name (attr
->form
));
22711 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22712 dwarf2_per_cu_data
*per_cu
,
22713 dwarf2_per_objfile
*per_objfile
)
22715 struct die_info
*die
;
22717 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22719 cu
= load_cu (per_cu
, per_objfile
, false);
22724 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22728 return die_type (die
, cu
);
22734 dwarf2_get_die_type (cu_offset die_offset
,
22735 dwarf2_per_cu_data
*per_cu
,
22736 dwarf2_per_objfile
*per_objfile
)
22738 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22739 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
22742 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22743 On entry *REF_CU is the CU of SRC_DIE.
22744 On exit *REF_CU is the CU of the result.
22745 Returns NULL if the referenced DIE isn't found. */
22747 static struct die_info
*
22748 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22749 struct dwarf2_cu
**ref_cu
)
22751 struct die_info temp_die
;
22752 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22753 struct die_info
*die
;
22754 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
22757 /* While it might be nice to assert sig_type->type == NULL here,
22758 we can get here for DW_AT_imported_declaration where we need
22759 the DIE not the type. */
22761 /* If necessary, add it to the queue and load its DIEs. */
22763 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
22765 read_signatured_type (sig_type
, per_objfile
);
22767 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
22768 gdb_assert (sig_cu
!= NULL
);
22769 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22770 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22771 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22772 to_underlying (temp_die
.sect_off
));
22775 /* For .gdb_index version 7 keep track of included TUs.
22776 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22777 if (per_objfile
->per_bfd
->index_table
!= NULL
22778 && per_objfile
->per_bfd
->index_table
->version
<= 7)
22780 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22785 sig_cu
->ancestor
= cu
;
22793 /* Follow signatured type referenced by ATTR in SRC_DIE.
22794 On entry *REF_CU is the CU of SRC_DIE.
22795 On exit *REF_CU is the CU of the result.
22796 The result is the DIE of the type.
22797 If the referenced type cannot be found an error is thrown. */
22799 static struct die_info
*
22800 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22801 struct dwarf2_cu
**ref_cu
)
22803 ULONGEST signature
= DW_SIGNATURE (attr
);
22804 struct signatured_type
*sig_type
;
22805 struct die_info
*die
;
22807 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22809 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22810 /* sig_type will be NULL if the signatured type is missing from
22812 if (sig_type
== NULL
)
22814 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22815 " from DIE at %s [in module %s]"),
22816 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22817 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22820 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22823 dump_die_for_error (src_die
);
22824 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22825 " from DIE at %s [in module %s]"),
22826 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22827 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22833 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22834 reading in and processing the type unit if necessary. */
22836 static struct type
*
22837 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22838 struct dwarf2_cu
*cu
)
22840 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22841 struct signatured_type
*sig_type
;
22842 struct dwarf2_cu
*type_cu
;
22843 struct die_info
*type_die
;
22846 sig_type
= lookup_signatured_type (cu
, signature
);
22847 /* sig_type will be NULL if the signatured type is missing from
22849 if (sig_type
== NULL
)
22851 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22852 " from DIE at %s [in module %s]"),
22853 hex_string (signature
), sect_offset_str (die
->sect_off
),
22854 objfile_name (per_objfile
->objfile
));
22855 return build_error_marker_type (cu
, die
);
22858 /* If we already know the type we're done. */
22859 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
22860 if (type
!= nullptr)
22864 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22865 if (type_die
!= NULL
)
22867 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22868 is created. This is important, for example, because for c++ classes
22869 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22870 type
= read_type_die (type_die
, type_cu
);
22873 complaint (_("Dwarf Error: Cannot build signatured type %s"
22874 " referenced from DIE at %s [in module %s]"),
22875 hex_string (signature
), sect_offset_str (die
->sect_off
),
22876 objfile_name (per_objfile
->objfile
));
22877 type
= build_error_marker_type (cu
, die
);
22882 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22883 " from DIE at %s [in module %s]"),
22884 hex_string (signature
), sect_offset_str (die
->sect_off
),
22885 objfile_name (per_objfile
->objfile
));
22886 type
= build_error_marker_type (cu
, die
);
22889 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
22894 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22895 reading in and processing the type unit if necessary. */
22897 static struct type
*
22898 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22899 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22901 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22902 if (attr
->form_is_ref ())
22904 struct dwarf2_cu
*type_cu
= cu
;
22905 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22907 return read_type_die (type_die
, type_cu
);
22909 else if (attr
->form
== DW_FORM_ref_sig8
)
22911 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22915 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22917 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22918 " at %s [in module %s]"),
22919 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22920 objfile_name (per_objfile
->objfile
));
22921 return build_error_marker_type (cu
, die
);
22925 /* Load the DIEs associated with type unit PER_CU into memory. */
22928 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22929 dwarf2_per_objfile
*per_objfile
)
22931 struct signatured_type
*sig_type
;
22933 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22934 gdb_assert (! per_cu
->type_unit_group_p ());
22936 /* We have the per_cu, but we need the signatured_type.
22937 Fortunately this is an easy translation. */
22938 gdb_assert (per_cu
->is_debug_types
);
22939 sig_type
= (struct signatured_type
*) per_cu
;
22941 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22943 read_signatured_type (sig_type
, per_objfile
);
22945 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
22948 /* Read in a signatured type and build its CU and DIEs.
22949 If the type is a stub for the real type in a DWO file,
22950 read in the real type from the DWO file as well. */
22953 read_signatured_type (signatured_type
*sig_type
,
22954 dwarf2_per_objfile
*per_objfile
)
22956 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22958 gdb_assert (per_cu
->is_debug_types
);
22959 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22961 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
22963 if (!reader
.dummy_p
)
22965 struct dwarf2_cu
*cu
= reader
.cu
;
22966 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22968 gdb_assert (cu
->die_hash
== NULL
);
22970 htab_create_alloc_ex (cu
->header
.length
/ 12,
22974 &cu
->comp_unit_obstack
,
22975 hashtab_obstack_allocate
,
22976 dummy_obstack_deallocate
);
22978 if (reader
.comp_unit_die
->has_children
)
22979 reader
.comp_unit_die
->child
22980 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22981 reader
.comp_unit_die
);
22982 cu
->dies
= reader
.comp_unit_die
;
22983 /* comp_unit_die is not stored in die_hash, no need. */
22985 /* We try not to read any attributes in this function, because
22986 not all CUs needed for references have been loaded yet, and
22987 symbol table processing isn't initialized. But we have to
22988 set the CU language, or we won't be able to build types
22989 correctly. Similarly, if we do not read the producer, we can
22990 not apply producer-specific interpretation. */
22991 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22996 sig_type
->per_cu
.tu_read
= 1;
22999 /* Decode simple location descriptions.
23000 Given a pointer to a dwarf block that defines a location, compute
23001 the location and return the value. If COMPUTED is non-null, it is
23002 set to true to indicate that decoding was successful, and false
23003 otherwise. If COMPUTED is null, then this function may emit a
23007 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23009 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23011 size_t size
= blk
->size
;
23012 const gdb_byte
*data
= blk
->data
;
23013 CORE_ADDR stack
[64];
23015 unsigned int bytes_read
, unsnd
;
23018 if (computed
!= nullptr)
23024 stack
[++stacki
] = 0;
23063 stack
[++stacki
] = op
- DW_OP_lit0
;
23098 stack
[++stacki
] = op
- DW_OP_reg0
;
23101 if (computed
== nullptr)
23102 dwarf2_complex_location_expr_complaint ();
23109 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23111 stack
[++stacki
] = unsnd
;
23114 if (computed
== nullptr)
23115 dwarf2_complex_location_expr_complaint ();
23122 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23127 case DW_OP_const1u
:
23128 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23132 case DW_OP_const1s
:
23133 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23137 case DW_OP_const2u
:
23138 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23142 case DW_OP_const2s
:
23143 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23147 case DW_OP_const4u
:
23148 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23152 case DW_OP_const4s
:
23153 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23157 case DW_OP_const8u
:
23158 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23163 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23169 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23174 stack
[stacki
+ 1] = stack
[stacki
];
23179 stack
[stacki
- 1] += stack
[stacki
];
23183 case DW_OP_plus_uconst
:
23184 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23190 stack
[stacki
- 1] -= stack
[stacki
];
23195 /* If we're not the last op, then we definitely can't encode
23196 this using GDB's address_class enum. This is valid for partial
23197 global symbols, although the variable's address will be bogus
23201 if (computed
== nullptr)
23202 dwarf2_complex_location_expr_complaint ();
23208 case DW_OP_GNU_push_tls_address
:
23209 case DW_OP_form_tls_address
:
23210 /* The top of the stack has the offset from the beginning
23211 of the thread control block at which the variable is located. */
23212 /* Nothing should follow this operator, so the top of stack would
23214 /* This is valid for partial global symbols, but the variable's
23215 address will be bogus in the psymtab. Make it always at least
23216 non-zero to not look as a variable garbage collected by linker
23217 which have DW_OP_addr 0. */
23220 if (computed
== nullptr)
23221 dwarf2_complex_location_expr_complaint ();
23228 case DW_OP_GNU_uninit
:
23229 if (computed
!= nullptr)
23234 case DW_OP_GNU_addr_index
:
23235 case DW_OP_GNU_const_index
:
23236 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23242 if (computed
== nullptr)
23244 const char *name
= get_DW_OP_name (op
);
23247 complaint (_("unsupported stack op: '%s'"),
23250 complaint (_("unsupported stack op: '%02x'"),
23254 return (stack
[stacki
]);
23257 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23258 outside of the allocated space. Also enforce minimum>0. */
23259 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23261 if (computed
== nullptr)
23262 complaint (_("location description stack overflow"));
23268 if (computed
== nullptr)
23269 complaint (_("location description stack underflow"));
23274 if (computed
!= nullptr)
23276 return (stack
[stacki
]);
23279 /* memory allocation interface */
23281 static struct dwarf_block
*
23282 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23284 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23287 static struct die_info
*
23288 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23290 struct die_info
*die
;
23291 size_t size
= sizeof (struct die_info
);
23294 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23296 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23297 memset (die
, 0, sizeof (struct die_info
));
23303 /* Macro support. */
23305 /* An overload of dwarf_decode_macros that finds the correct section
23306 and ensures it is read in before calling the other overload. */
23309 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23310 int section_is_gnu
)
23312 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23313 struct objfile
*objfile
= per_objfile
->objfile
;
23314 const struct line_header
*lh
= cu
->line_header
;
23315 unsigned int offset_size
= cu
->header
.offset_size
;
23316 struct dwarf2_section_info
*section
;
23317 const char *section_name
;
23319 if (cu
->dwo_unit
!= nullptr)
23321 if (section_is_gnu
)
23323 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23324 section_name
= ".debug_macro.dwo";
23328 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23329 section_name
= ".debug_macinfo.dwo";
23334 if (section_is_gnu
)
23336 section
= &per_objfile
->per_bfd
->macro
;
23337 section_name
= ".debug_macro";
23341 section
= &per_objfile
->per_bfd
->macinfo
;
23342 section_name
= ".debug_macinfo";
23346 section
->read (objfile
);
23347 if (section
->buffer
== nullptr)
23349 complaint (_("missing %s section"), section_name
);
23353 buildsym_compunit
*builder
= cu
->get_builder ();
23355 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
23356 offset_size
, offset
, section_is_gnu
);
23359 /* Return the .debug_loc section to use for CU.
23360 For DWO files use .debug_loc.dwo. */
23362 static struct dwarf2_section_info
*
23363 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23365 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23369 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23371 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23373 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
23374 : &per_objfile
->per_bfd
->loc
);
23377 /* A helper function that fills in a dwarf2_loclist_baton. */
23380 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23381 struct dwarf2_loclist_baton
*baton
,
23382 const struct attribute
*attr
)
23384 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23385 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23387 section
->read (per_objfile
->objfile
);
23389 baton
->per_objfile
= per_objfile
;
23390 baton
->per_cu
= cu
->per_cu
;
23391 gdb_assert (baton
->per_cu
);
23392 /* We don't know how long the location list is, but make sure we
23393 don't run off the edge of the section. */
23394 baton
->size
= section
->size
- DW_UNSND (attr
);
23395 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23396 if (cu
->base_address
.has_value ())
23397 baton
->base_address
= *cu
->base_address
;
23399 baton
->base_address
= 0;
23400 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23404 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23405 struct dwarf2_cu
*cu
, int is_block
)
23407 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23408 struct objfile
*objfile
= per_objfile
->objfile
;
23409 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23411 if (attr
->form_is_section_offset ()
23412 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23413 the section. If so, fall through to the complaint in the
23415 && DW_UNSND (attr
) < section
->get_size (objfile
))
23417 struct dwarf2_loclist_baton
*baton
;
23419 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23421 fill_in_loclist_baton (cu
, baton
, attr
);
23423 if (!cu
->base_address
.has_value ())
23424 complaint (_("Location list used without "
23425 "specifying the CU base address."));
23427 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23428 ? dwarf2_loclist_block_index
23429 : dwarf2_loclist_index
);
23430 SYMBOL_LOCATION_BATON (sym
) = baton
;
23434 struct dwarf2_locexpr_baton
*baton
;
23436 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23437 baton
->per_objfile
= per_objfile
;
23438 baton
->per_cu
= cu
->per_cu
;
23439 gdb_assert (baton
->per_cu
);
23441 if (attr
->form_is_block ())
23443 /* Note that we're just copying the block's data pointer
23444 here, not the actual data. We're still pointing into the
23445 info_buffer for SYM's objfile; right now we never release
23446 that buffer, but when we do clean up properly this may
23448 baton
->size
= DW_BLOCK (attr
)->size
;
23449 baton
->data
= DW_BLOCK (attr
)->data
;
23453 dwarf2_invalid_attrib_class_complaint ("location description",
23454 sym
->natural_name ());
23458 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23459 ? dwarf2_locexpr_block_index
23460 : dwarf2_locexpr_index
);
23461 SYMBOL_LOCATION_BATON (sym
) = baton
;
23467 const comp_unit_head
*
23468 dwarf2_per_cu_data::get_header () const
23470 if (!m_header_read_in
)
23472 const gdb_byte
*info_ptr
23473 = this->section
->buffer
+ to_underlying (this->sect_off
);
23475 memset (&m_header
, 0, sizeof (m_header
));
23477 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
23478 rcuh_kind::COMPILE
);
23487 dwarf2_per_cu_data::addr_size () const
23489 return this->get_header ()->addr_size
;
23495 dwarf2_per_cu_data::offset_size () const
23497 return this->get_header ()->offset_size
;
23503 dwarf2_per_cu_data::ref_addr_size () const
23505 const comp_unit_head
*header
= this->get_header ();
23507 if (header
->version
== 2)
23508 return header
->addr_size
;
23510 return header
->offset_size
;
23516 dwarf2_cu::addr_type () const
23518 struct objfile
*objfile
= this->per_objfile
->objfile
;
23519 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23520 struct type
*addr_type
= lookup_pointer_type (void_type
);
23521 int addr_size
= this->per_cu
->addr_size ();
23523 if (TYPE_LENGTH (addr_type
) == addr_size
)
23526 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23530 /* A helper function for dwarf2_find_containing_comp_unit that returns
23531 the index of the result, and that searches a vector. It will
23532 return a result even if the offset in question does not actually
23533 occur in any CU. This is separate so that it can be unit
23537 dwarf2_find_containing_comp_unit
23538 (sect_offset sect_off
,
23539 unsigned int offset_in_dwz
,
23540 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23545 high
= all_comp_units
.size () - 1;
23548 struct dwarf2_per_cu_data
*mid_cu
;
23549 int mid
= low
+ (high
- low
) / 2;
23551 mid_cu
= all_comp_units
[mid
];
23552 if (mid_cu
->is_dwz
> offset_in_dwz
23553 || (mid_cu
->is_dwz
== offset_in_dwz
23554 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23559 gdb_assert (low
== high
);
23563 /* Locate the .debug_info compilation unit from CU's objfile which contains
23564 the DIE at OFFSET. Raises an error on failure. */
23566 static struct dwarf2_per_cu_data
*
23567 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23568 unsigned int offset_in_dwz
,
23569 dwarf2_per_objfile
*per_objfile
)
23571 int low
= dwarf2_find_containing_comp_unit
23572 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
23573 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
23575 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23577 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23578 error (_("Dwarf Error: could not find partial DIE containing "
23579 "offset %s [in module %s]"),
23580 sect_offset_str (sect_off
),
23581 bfd_get_filename (per_objfile
->objfile
->obfd
));
23583 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23585 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
23589 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
23590 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23591 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23592 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23599 namespace selftests
{
23600 namespace find_containing_comp_unit
{
23605 struct dwarf2_per_cu_data one
{};
23606 struct dwarf2_per_cu_data two
{};
23607 struct dwarf2_per_cu_data three
{};
23608 struct dwarf2_per_cu_data four
{};
23611 two
.sect_off
= sect_offset (one
.length
);
23616 four
.sect_off
= sect_offset (three
.length
);
23620 std::vector
<dwarf2_per_cu_data
*> units
;
23621 units
.push_back (&one
);
23622 units
.push_back (&two
);
23623 units
.push_back (&three
);
23624 units
.push_back (&four
);
23628 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23629 SELF_CHECK (units
[result
] == &one
);
23630 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23631 SELF_CHECK (units
[result
] == &one
);
23632 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23633 SELF_CHECK (units
[result
] == &two
);
23635 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23636 SELF_CHECK (units
[result
] == &three
);
23637 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23638 SELF_CHECK (units
[result
] == &three
);
23639 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23640 SELF_CHECK (units
[result
] == &four
);
23646 #endif /* GDB_SELF_TEST */
23648 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23650 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23651 dwarf2_per_objfile
*per_objfile
)
23653 per_objfile (per_objfile
),
23655 has_loclist (false),
23656 checked_producer (false),
23657 producer_is_gxx_lt_4_6 (false),
23658 producer_is_gcc_lt_4_3 (false),
23659 producer_is_icc (false),
23660 producer_is_icc_lt_14 (false),
23661 producer_is_codewarrior (false),
23662 processing_has_namespace_info (false)
23666 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23669 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23670 enum language pretend_language
)
23672 struct attribute
*attr
;
23674 /* Set the language we're debugging. */
23675 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23676 if (attr
!= nullptr)
23677 set_cu_language (DW_UNSND (attr
), cu
);
23680 cu
->language
= pretend_language
;
23681 cu
->language_defn
= language_def (cu
->language
);
23684 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23690 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
23692 auto it
= m_dwarf2_cus
.find (per_cu
);
23693 if (it
== m_dwarf2_cus
.end ())
23702 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
23704 gdb_assert (this->get_cu (per_cu
) == nullptr);
23706 m_dwarf2_cus
[per_cu
] = cu
;
23712 dwarf2_per_objfile::age_comp_units ()
23714 /* Start by clearing all marks. */
23715 for (auto pair
: m_dwarf2_cus
)
23716 pair
.second
->mark
= false;
23718 /* Traverse all CUs, mark them and their dependencies if used recently
23720 for (auto pair
: m_dwarf2_cus
)
23722 dwarf2_cu
*cu
= pair
.second
;
23725 if (cu
->last_used
<= dwarf_max_cache_age
)
23729 /* Delete all CUs still not marked. */
23730 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
23732 dwarf2_cu
*cu
= it
->second
;
23737 it
= m_dwarf2_cus
.erase (it
);
23747 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
23749 auto it
= m_dwarf2_cus
.find (per_cu
);
23750 if (it
== m_dwarf2_cus
.end ())
23755 m_dwarf2_cus
.erase (it
);
23758 dwarf2_per_objfile::~dwarf2_per_objfile ()
23763 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23764 We store these in a hash table separate from the DIEs, and preserve them
23765 when the DIEs are flushed out of cache.
23767 The CU "per_cu" pointer is needed because offset alone is not enough to
23768 uniquely identify the type. A file may have multiple .debug_types sections,
23769 or the type may come from a DWO file. Furthermore, while it's more logical
23770 to use per_cu->section+offset, with Fission the section with the data is in
23771 the DWO file but we don't know that section at the point we need it.
23772 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23773 because we can enter the lookup routine, get_die_type_at_offset, from
23774 outside this file, and thus won't necessarily have PER_CU->cu.
23775 Fortunately, PER_CU is stable for the life of the objfile. */
23777 struct dwarf2_per_cu_offset_and_type
23779 const struct dwarf2_per_cu_data
*per_cu
;
23780 sect_offset sect_off
;
23784 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23787 per_cu_offset_and_type_hash (const void *item
)
23789 const struct dwarf2_per_cu_offset_and_type
*ofs
23790 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23792 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23795 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23798 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23800 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23801 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23802 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23803 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23805 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23806 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23809 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23810 table if necessary. For convenience, return TYPE.
23812 The DIEs reading must have careful ordering to:
23813 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23814 reading current DIE.
23815 * Not trying to dereference contents of still incompletely read in types
23816 while reading in other DIEs.
23817 * Enable referencing still incompletely read in types just by a pointer to
23818 the type without accessing its fields.
23820 Therefore caller should follow these rules:
23821 * Try to fetch any prerequisite types we may need to build this DIE type
23822 before building the type and calling set_die_type.
23823 * After building type call set_die_type for current DIE as soon as
23824 possible before fetching more types to complete the current type.
23825 * Make the type as complete as possible before fetching more types. */
23827 static struct type
*
23828 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23830 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23831 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23832 struct objfile
*objfile
= per_objfile
->objfile
;
23833 struct attribute
*attr
;
23834 struct dynamic_prop prop
;
23836 /* For Ada types, make sure that the gnat-specific data is always
23837 initialized (if not already set). There are a few types where
23838 we should not be doing so, because the type-specific area is
23839 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23840 where the type-specific area is used to store the floatformat).
23841 But this is not a problem, because the gnat-specific information
23842 is actually not needed for these types. */
23843 if (need_gnat_info (cu
)
23844 && type
->code () != TYPE_CODE_FUNC
23845 && type
->code () != TYPE_CODE_FLT
23846 && type
->code () != TYPE_CODE_METHODPTR
23847 && type
->code () != TYPE_CODE_MEMBERPTR
23848 && type
->code () != TYPE_CODE_METHOD
23849 && !HAVE_GNAT_AUX_INFO (type
))
23850 INIT_GNAT_SPECIFIC (type
);
23852 /* Read DW_AT_allocated and set in type. */
23853 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23854 if (attr
!= NULL
&& attr
->form_is_block ())
23856 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23857 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23858 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23860 else if (attr
!= NULL
)
23862 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23863 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23864 sect_offset_str (die
->sect_off
));
23867 /* Read DW_AT_associated and set in type. */
23868 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23869 if (attr
!= NULL
&& attr
->form_is_block ())
23871 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23872 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23873 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23875 else if (attr
!= NULL
)
23877 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23878 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23879 sect_offset_str (die
->sect_off
));
23882 /* Read DW_AT_data_location and set in type. */
23883 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23884 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23885 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23887 if (per_objfile
->die_type_hash
== NULL
)
23888 per_objfile
->die_type_hash
23889 = htab_up (htab_create_alloc (127,
23890 per_cu_offset_and_type_hash
,
23891 per_cu_offset_and_type_eq
,
23892 NULL
, xcalloc
, xfree
));
23894 ofs
.per_cu
= cu
->per_cu
;
23895 ofs
.sect_off
= die
->sect_off
;
23897 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23898 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23900 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23901 sect_offset_str (die
->sect_off
));
23902 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23903 struct dwarf2_per_cu_offset_and_type
);
23908 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23909 or return NULL if the die does not have a saved type. */
23911 static struct type
*
23912 get_die_type_at_offset (sect_offset sect_off
,
23913 dwarf2_per_cu_data
*per_cu
,
23914 dwarf2_per_objfile
*per_objfile
)
23916 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23918 if (per_objfile
->die_type_hash
== NULL
)
23921 ofs
.per_cu
= per_cu
;
23922 ofs
.sect_off
= sect_off
;
23923 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23924 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
23931 /* Look up the type for DIE in CU in die_type_hash,
23932 or return NULL if DIE does not have a saved type. */
23934 static struct type
*
23935 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23937 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
23940 /* Add a dependence relationship from CU to REF_PER_CU. */
23943 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23944 struct dwarf2_per_cu_data
*ref_per_cu
)
23948 if (cu
->dependencies
== NULL
)
23950 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23951 NULL
, &cu
->comp_unit_obstack
,
23952 hashtab_obstack_allocate
,
23953 dummy_obstack_deallocate
);
23955 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23957 *slot
= ref_per_cu
;
23960 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23961 Set the mark field in every compilation unit in the
23962 cache that we must keep because we are keeping CU.
23964 DATA is the dwarf2_per_objfile object in which to look up CUs. */
23967 dwarf2_mark_helper (void **slot
, void *data
)
23969 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
23970 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
23971 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23973 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23974 reading of the chain. As such dependencies remain valid it is not much
23975 useful to track and undo them during QUIT cleanups. */
23984 if (cu
->dependencies
!= nullptr)
23985 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
23990 /* Set the mark field in CU and in every other compilation unit in the
23991 cache that we must keep because we are keeping CU. */
23994 dwarf2_mark (struct dwarf2_cu
*cu
)
24001 if (cu
->dependencies
!= nullptr)
24002 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
24005 /* Trivial hash function for partial_die_info: the hash value of a DIE
24006 is its offset in .debug_info for this objfile. */
24009 partial_die_hash (const void *item
)
24011 const struct partial_die_info
*part_die
24012 = (const struct partial_die_info
*) item
;
24014 return to_underlying (part_die
->sect_off
);
24017 /* Trivial comparison function for partial_die_info structures: two DIEs
24018 are equal if they have the same offset. */
24021 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24023 const struct partial_die_info
*part_die_lhs
24024 = (const struct partial_die_info
*) item_lhs
;
24025 const struct partial_die_info
*part_die_rhs
24026 = (const struct partial_die_info
*) item_rhs
;
24028 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24031 struct cmd_list_element
*set_dwarf_cmdlist
;
24032 struct cmd_list_element
*show_dwarf_cmdlist
;
24035 show_check_physname (struct ui_file
*file
, int from_tty
,
24036 struct cmd_list_element
*c
, const char *value
)
24038 fprintf_filtered (file
,
24039 _("Whether to check \"physname\" is %s.\n"),
24043 void _initialize_dwarf2_read ();
24045 _initialize_dwarf2_read ()
24047 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24048 Set DWARF specific variables.\n\
24049 Configure DWARF variables such as the cache size."),
24050 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24051 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24053 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24054 Show DWARF specific variables.\n\
24055 Show DWARF variables such as the cache size."),
24056 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24057 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24059 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24060 &dwarf_max_cache_age
, _("\
24061 Set the upper bound on the age of cached DWARF compilation units."), _("\
24062 Show the upper bound on the age of cached DWARF compilation units."), _("\
24063 A higher limit means that cached compilation units will be stored\n\
24064 in memory longer, and more total memory will be used. Zero disables\n\
24065 caching, which can slow down startup."),
24067 show_dwarf_max_cache_age
,
24068 &set_dwarf_cmdlist
,
24069 &show_dwarf_cmdlist
);
24071 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24072 Set debugging of the DWARF reader."), _("\
24073 Show debugging of the DWARF reader."), _("\
24074 When enabled (non-zero), debugging messages are printed during DWARF\n\
24075 reading and symtab expansion. A value of 1 (one) provides basic\n\
24076 information. A value greater than 1 provides more verbose information."),
24079 &setdebuglist
, &showdebuglist
);
24081 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24082 Set debugging of the DWARF DIE reader."), _("\
24083 Show debugging of the DWARF DIE reader."), _("\
24084 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24085 The value is the maximum depth to print."),
24088 &setdebuglist
, &showdebuglist
);
24090 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24091 Set debugging of the dwarf line reader."), _("\
24092 Show debugging of the dwarf line reader."), _("\
24093 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24094 A value of 1 (one) provides basic information.\n\
24095 A value greater than 1 provides more verbose information."),
24098 &setdebuglist
, &showdebuglist
);
24100 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24101 Set cross-checking of \"physname\" code against demangler."), _("\
24102 Show cross-checking of \"physname\" code against demangler."), _("\
24103 When enabled, GDB's internal \"physname\" code is checked against\n\
24105 NULL
, show_check_physname
,
24106 &setdebuglist
, &showdebuglist
);
24108 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24109 no_class
, &use_deprecated_index_sections
, _("\
24110 Set whether to use deprecated gdb_index sections."), _("\
24111 Show whether to use deprecated gdb_index sections."), _("\
24112 When enabled, deprecated .gdb_index sections are used anyway.\n\
24113 Normally they are ignored either because of a missing feature or\n\
24114 performance issue.\n\
24115 Warning: This option must be enabled before gdb reads the file."),
24118 &setlist
, &showlist
);
24120 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24121 &dwarf2_locexpr_funcs
);
24122 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24123 &dwarf2_loclist_funcs
);
24125 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24126 &dwarf2_block_frame_base_locexpr_funcs
);
24127 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24128 &dwarf2_block_frame_base_loclist_funcs
);
24131 selftests::register_test ("dw2_expand_symtabs_matching",
24132 selftests::dw2_expand_symtabs_matching::run_test
);
24133 selftests::register_test ("dwarf2_find_containing_comp_unit",
24134 selftests::find_containing_comp_unit::run_test
);