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
;
3072 gdb::array_view
<const gdb_byte
> main_index_contents
3073 = get_gdb_index_contents (objfile
, per_objfile
->per_bfd
);
3075 if (main_index_contents
.empty ())
3078 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3079 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3080 use_deprecated_index_sections
,
3081 main_index_contents
, map
.get (), &cu_list
,
3082 &cu_list_elements
, &types_list
,
3083 &types_list_elements
))
3086 /* Don't use the index if it's empty. */
3087 if (map
->symbol_table
.empty ())
3090 /* If there is a .dwz file, read it so we can get its CU list as
3092 dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
3095 struct mapped_index dwz_map
;
3096 const gdb_byte
*dwz_types_ignore
;
3097 offset_type dwz_types_elements_ignore
;
3099 gdb::array_view
<const gdb_byte
> dwz_index_content
3100 = get_gdb_index_contents_dwz (objfile
, dwz
);
3102 if (dwz_index_content
.empty ())
3105 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3106 1, dwz_index_content
, &dwz_map
,
3107 &dwz_list
, &dwz_list_elements
,
3109 &dwz_types_elements_ignore
))
3111 warning (_("could not read '.gdb_index' section from %s; skipping"),
3112 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3117 create_cus_from_index (per_objfile
->per_bfd
, cu_list
, cu_list_elements
,
3118 dwz_list
, dwz_list_elements
);
3120 if (types_list_elements
)
3122 /* We can only handle a single .debug_types when we have an
3124 if (per_objfile
->per_bfd
->types
.size () != 1)
3127 dwarf2_section_info
*section
= &per_objfile
->per_bfd
->types
[0];
3129 create_signatured_type_table_from_index (per_objfile
->per_bfd
,
3130 section
, types_list
,
3131 types_list_elements
);
3134 create_addrmap_from_index (per_objfile
, map
.get ());
3136 per_objfile
->per_bfd
->index_table
= std::move (map
);
3137 per_objfile
->per_bfd
->using_index
= 1;
3138 per_objfile
->per_bfd
->quick_file_names_table
=
3139 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
3144 /* die_reader_func for dw2_get_file_names. */
3147 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3148 const gdb_byte
*info_ptr
,
3149 struct die_info
*comp_unit_die
)
3151 struct dwarf2_cu
*cu
= reader
->cu
;
3152 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3153 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3154 struct dwarf2_per_cu_data
*lh_cu
;
3155 struct attribute
*attr
;
3157 struct quick_file_names
*qfn
;
3159 gdb_assert (! this_cu
->is_debug_types
);
3161 /* Our callers never want to match partial units -- instead they
3162 will match the enclosing full CU. */
3163 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3165 this_cu
->v
.quick
->no_file_data
= 1;
3173 sect_offset line_offset
{};
3175 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3176 if (attr
!= nullptr)
3178 struct quick_file_names find_entry
;
3180 line_offset
= (sect_offset
) DW_UNSND (attr
);
3182 /* We may have already read in this line header (TU line header sharing).
3183 If we have we're done. */
3184 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3185 find_entry
.hash
.line_sect_off
= line_offset
;
3186 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3187 &find_entry
, INSERT
);
3190 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3194 lh
= dwarf_decode_line_header (line_offset
, cu
);
3198 lh_cu
->v
.quick
->no_file_data
= 1;
3202 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3203 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3204 qfn
->hash
.line_sect_off
= line_offset
;
3205 gdb_assert (slot
!= NULL
);
3208 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3211 if (strcmp (fnd
.name
, "<unknown>") != 0)
3214 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3216 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3217 qfn
->num_file_names
);
3219 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3220 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3221 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3222 fnd
.comp_dir
).release ();
3223 qfn
->real_names
= NULL
;
3225 lh_cu
->v
.quick
->file_names
= qfn
;
3228 /* A helper for the "quick" functions which attempts to read the line
3229 table for THIS_CU. */
3231 static struct quick_file_names
*
3232 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3233 dwarf2_per_objfile
*per_objfile
)
3235 /* This should never be called for TUs. */
3236 gdb_assert (! this_cu
->is_debug_types
);
3237 /* Nor type unit groups. */
3238 gdb_assert (! this_cu
->type_unit_group_p ());
3240 if (this_cu
->v
.quick
->file_names
!= NULL
)
3241 return this_cu
->v
.quick
->file_names
;
3242 /* If we know there is no line data, no point in looking again. */
3243 if (this_cu
->v
.quick
->no_file_data
)
3246 cutu_reader
reader (this_cu
, per_objfile
);
3247 if (!reader
.dummy_p
)
3248 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3250 if (this_cu
->v
.quick
->no_file_data
)
3252 return this_cu
->v
.quick
->file_names
;
3255 /* A helper for the "quick" functions which computes and caches the
3256 real path for a given file name from the line table. */
3259 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3260 struct quick_file_names
*qfn
, int index
)
3262 if (qfn
->real_names
== NULL
)
3263 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3264 qfn
->num_file_names
, const char *);
3266 if (qfn
->real_names
[index
] == NULL
)
3267 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3269 return qfn
->real_names
[index
];
3272 static struct symtab
*
3273 dw2_find_last_source_symtab (struct objfile
*objfile
)
3275 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3276 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3277 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3282 return compunit_primary_filetab (cust
);
3285 /* Traversal function for dw2_forget_cached_source_info. */
3288 dw2_free_cached_file_names (void **slot
, void *info
)
3290 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3292 if (file_data
->real_names
)
3296 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3298 xfree ((void*) file_data
->real_names
[i
]);
3299 file_data
->real_names
[i
] = NULL
;
3307 dw2_forget_cached_source_info (struct objfile
*objfile
)
3309 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3311 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3312 dw2_free_cached_file_names
, NULL
);
3315 /* Helper function for dw2_map_symtabs_matching_filename that expands
3316 the symtabs and calls the iterator. */
3319 dw2_map_expand_apply (struct objfile
*objfile
,
3320 struct dwarf2_per_cu_data
*per_cu
,
3321 const char *name
, const char *real_path
,
3322 gdb::function_view
<bool (symtab
*)> callback
)
3324 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3326 /* Don't visit already-expanded CUs. */
3327 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3328 if (per_objfile
->symtab_set_p (per_cu
))
3331 /* This may expand more than one symtab, and we want to iterate over
3333 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3335 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3336 last_made
, callback
);
3339 /* Implementation of the map_symtabs_matching_filename method. */
3342 dw2_map_symtabs_matching_filename
3343 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3344 gdb::function_view
<bool (symtab
*)> callback
)
3346 const char *name_basename
= lbasename (name
);
3347 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3349 /* The rule is CUs specify all the files, including those used by
3350 any TU, so there's no need to scan TUs here. */
3352 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3354 /* We only need to look at symtabs not already expanded. */
3355 if (per_objfile
->symtab_set_p (per_cu
))
3358 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3359 if (file_data
== NULL
)
3362 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3364 const char *this_name
= file_data
->file_names
[j
];
3365 const char *this_real_name
;
3367 if (compare_filenames_for_search (this_name
, name
))
3369 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3375 /* Before we invoke realpath, which can get expensive when many
3376 files are involved, do a quick comparison of the basenames. */
3377 if (! basenames_may_differ
3378 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3381 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3382 if (compare_filenames_for_search (this_real_name
, name
))
3384 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3390 if (real_path
!= NULL
)
3392 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3393 gdb_assert (IS_ABSOLUTE_PATH (name
));
3394 if (this_real_name
!= NULL
3395 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3397 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3409 /* Struct used to manage iterating over all CUs looking for a symbol. */
3411 struct dw2_symtab_iterator
3413 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3414 dwarf2_per_objfile
*per_objfile
;
3415 /* If set, only look for symbols that match that block. Valid values are
3416 GLOBAL_BLOCK and STATIC_BLOCK. */
3417 gdb::optional
<block_enum
> block_index
;
3418 /* The kind of symbol we're looking for. */
3420 /* The list of CUs from the index entry of the symbol,
3421 or NULL if not found. */
3423 /* The next element in VEC to look at. */
3425 /* The number of elements in VEC, or zero if there is no match. */
3427 /* Have we seen a global version of the symbol?
3428 If so we can ignore all further global instances.
3429 This is to work around gold/15646, inefficient gold-generated
3434 /* Initialize the index symtab iterator ITER. */
3437 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3438 dwarf2_per_objfile
*per_objfile
,
3439 gdb::optional
<block_enum
> block_index
,
3443 iter
->per_objfile
= per_objfile
;
3444 iter
->block_index
= block_index
;
3445 iter
->domain
= domain
;
3447 iter
->global_seen
= 0;
3449 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3451 /* index is NULL if OBJF_READNOW. */
3452 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3453 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3461 /* Return the next matching CU or NULL if there are no more. */
3463 static struct dwarf2_per_cu_data
*
3464 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3466 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3468 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3470 offset_type cu_index_and_attrs
=
3471 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3472 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3473 gdb_index_symbol_kind symbol_kind
=
3474 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3475 /* Only check the symbol attributes if they're present.
3476 Indices prior to version 7 don't record them,
3477 and indices >= 7 may elide them for certain symbols
3478 (gold does this). */
3480 (per_objfile
->per_bfd
->index_table
->version
>= 7
3481 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3483 /* Don't crash on bad data. */
3484 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3485 + per_objfile
->per_bfd
->all_type_units
.size ()))
3487 complaint (_(".gdb_index entry has bad CU index"
3488 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3492 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3494 /* Skip if already read in. */
3495 if (per_objfile
->symtab_set_p (per_cu
))
3498 /* Check static vs global. */
3501 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3503 if (iter
->block_index
.has_value ())
3505 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3507 if (is_static
!= want_static
)
3511 /* Work around gold/15646. */
3513 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3515 if (iter
->global_seen
)
3518 iter
->global_seen
= 1;
3522 /* Only check the symbol's kind if it has one. */
3525 switch (iter
->domain
)
3528 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3529 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3530 /* Some types are also in VAR_DOMAIN. */
3531 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3535 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3539 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3543 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3558 static struct compunit_symtab
*
3559 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3560 const char *name
, domain_enum domain
)
3562 struct compunit_symtab
*stab_best
= NULL
;
3563 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3565 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3567 struct dw2_symtab_iterator iter
;
3568 struct dwarf2_per_cu_data
*per_cu
;
3570 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3572 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3574 struct symbol
*sym
, *with_opaque
= NULL
;
3575 struct compunit_symtab
*stab
3576 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3577 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3578 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3580 sym
= block_find_symbol (block
, name
, domain
,
3581 block_find_non_opaque_type_preferred
,
3584 /* Some caution must be observed with overloaded functions
3585 and methods, since the index will not contain any overload
3586 information (but NAME might contain it). */
3589 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3591 if (with_opaque
!= NULL
3592 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3595 /* Keep looking through other CUs. */
3602 dw2_print_stats (struct objfile
*objfile
)
3604 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3605 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3606 + per_objfile
->per_bfd
->all_type_units
.size ());
3609 for (int i
= 0; i
< total
; ++i
)
3611 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3613 if (!per_objfile
->symtab_set_p (per_cu
))
3616 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3617 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3620 /* This dumps minimal information about the index.
3621 It is called via "mt print objfiles".
3622 One use is to verify .gdb_index has been loaded by the
3623 gdb.dwarf2/gdb-index.exp testcase. */
3626 dw2_dump (struct objfile
*objfile
)
3628 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3630 gdb_assert (per_objfile
->per_bfd
->using_index
);
3631 printf_filtered (".gdb_index:");
3632 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3634 printf_filtered (" version %d\n",
3635 per_objfile
->per_bfd
->index_table
->version
);
3638 printf_filtered (" faked for \"readnow\"\n");
3639 printf_filtered ("\n");
3643 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3644 const char *func_name
)
3646 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3648 struct dw2_symtab_iterator iter
;
3649 struct dwarf2_per_cu_data
*per_cu
;
3651 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3653 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3654 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3659 dw2_expand_all_symtabs (struct objfile
*objfile
)
3661 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3662 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3663 + per_objfile
->per_bfd
->all_type_units
.size ());
3665 for (int i
= 0; i
< total_units
; ++i
)
3667 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3669 /* We don't want to directly expand a partial CU, because if we
3670 read it with the wrong language, then assertion failures can
3671 be triggered later on. See PR symtab/23010. So, tell
3672 dw2_instantiate_symtab to skip partial CUs -- any important
3673 partial CU will be read via DW_TAG_imported_unit anyway. */
3674 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3679 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3680 const char *fullname
)
3682 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3684 /* We don't need to consider type units here.
3685 This is only called for examining code, e.g. expand_line_sal.
3686 There can be an order of magnitude (or more) more type units
3687 than comp units, and we avoid them if we can. */
3689 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3691 /* We only need to look at symtabs not already expanded. */
3692 if (per_objfile
->symtab_set_p (per_cu
))
3695 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3696 if (file_data
== NULL
)
3699 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3701 const char *this_fullname
= file_data
->file_names
[j
];
3703 if (filename_cmp (this_fullname
, fullname
) == 0)
3705 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3713 dw2_expand_symtabs_matching_symbol
3714 (mapped_index_base
&index
,
3715 const lookup_name_info
&lookup_name_in
,
3716 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3717 enum search_domain kind
,
3718 gdb::function_view
<bool (offset_type
)> match_callback
,
3719 dwarf2_per_objfile
*per_objfile
);
3722 dw2_expand_symtabs_matching_one
3723 (dwarf2_per_cu_data
*per_cu
,
3724 dwarf2_per_objfile
*per_objfile
,
3725 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3726 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3729 dw2_map_matching_symbols
3730 (struct objfile
*objfile
,
3731 const lookup_name_info
&name
, domain_enum domain
,
3733 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3734 symbol_compare_ftype
*ordered_compare
)
3737 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3739 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3741 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3743 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3744 here though if the current language is Ada for a non-Ada objfile
3746 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3748 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3749 auto matcher
= [&] (const char *symname
)
3751 if (ordered_compare
== nullptr)
3753 return ordered_compare (symname
, match_name
) == 0;
3756 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3757 [&] (offset_type namei
)
3759 struct dw2_symtab_iterator iter
;
3760 struct dwarf2_per_cu_data
*per_cu
;
3762 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3764 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3765 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3772 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3773 proceed assuming all symtabs have been read in. */
3776 for (compunit_symtab
*cust
: objfile
->compunits ())
3778 const struct block
*block
;
3782 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3783 if (!iterate_over_symbols_terminated (block
, name
,
3789 /* Starting from a search name, return the string that finds the upper
3790 bound of all strings that start with SEARCH_NAME in a sorted name
3791 list. Returns the empty string to indicate that the upper bound is
3792 the end of the list. */
3795 make_sort_after_prefix_name (const char *search_name
)
3797 /* When looking to complete "func", we find the upper bound of all
3798 symbols that start with "func" by looking for where we'd insert
3799 the closest string that would follow "func" in lexicographical
3800 order. Usually, that's "func"-with-last-character-incremented,
3801 i.e. "fund". Mind non-ASCII characters, though. Usually those
3802 will be UTF-8 multi-byte sequences, but we can't be certain.
3803 Especially mind the 0xff character, which is a valid character in
3804 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3805 rule out compilers allowing it in identifiers. Note that
3806 conveniently, strcmp/strcasecmp are specified to compare
3807 characters interpreted as unsigned char. So what we do is treat
3808 the whole string as a base 256 number composed of a sequence of
3809 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3810 to 0, and carries 1 to the following more-significant position.
3811 If the very first character in SEARCH_NAME ends up incremented
3812 and carries/overflows, then the upper bound is the end of the
3813 list. The string after the empty string is also the empty
3816 Some examples of this operation:
3818 SEARCH_NAME => "+1" RESULT
3822 "\xff" "a" "\xff" => "\xff" "b"
3827 Then, with these symbols for example:
3833 completing "func" looks for symbols between "func" and
3834 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3835 which finds "func" and "func1", but not "fund".
3839 funcÿ (Latin1 'ÿ' [0xff])
3843 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3844 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3848 ÿÿ (Latin1 'ÿ' [0xff])
3851 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3852 the end of the list.
3854 std::string after
= search_name
;
3855 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3857 if (!after
.empty ())
3858 after
.back () = (unsigned char) after
.back () + 1;
3862 /* See declaration. */
3864 std::pair
<std::vector
<name_component
>::const_iterator
,
3865 std::vector
<name_component
>::const_iterator
>
3866 mapped_index_base::find_name_components_bounds
3867 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3868 dwarf2_per_objfile
*per_objfile
) const
3871 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3873 const char *lang_name
3874 = lookup_name_without_params
.language_lookup_name (lang
);
3876 /* Comparison function object for lower_bound that matches against a
3877 given symbol name. */
3878 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3881 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3882 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3883 return name_cmp (elem_name
, name
) < 0;
3886 /* Comparison function object for upper_bound that matches against a
3887 given symbol name. */
3888 auto lookup_compare_upper
= [&] (const char *name
,
3889 const name_component
&elem
)
3891 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3892 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3893 return name_cmp (name
, elem_name
) < 0;
3896 auto begin
= this->name_components
.begin ();
3897 auto end
= this->name_components
.end ();
3899 /* Find the lower bound. */
3902 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3905 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3908 /* Find the upper bound. */
3911 if (lookup_name_without_params
.completion_mode ())
3913 /* In completion mode, we want UPPER to point past all
3914 symbols names that have the same prefix. I.e., with
3915 these symbols, and completing "func":
3917 function << lower bound
3919 other_function << upper bound
3921 We find the upper bound by looking for the insertion
3922 point of "func"-with-last-character-incremented,
3924 std::string after
= make_sort_after_prefix_name (lang_name
);
3927 return std::lower_bound (lower
, end
, after
.c_str (),
3928 lookup_compare_lower
);
3931 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3934 return {lower
, upper
};
3937 /* See declaration. */
3940 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3942 if (!this->name_components
.empty ())
3945 this->name_components_casing
= case_sensitivity
;
3947 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3949 /* The code below only knows how to break apart components of C++
3950 symbol names (and other languages that use '::' as
3951 namespace/module separator) and Ada symbol names. */
3952 auto count
= this->symbol_name_count ();
3953 for (offset_type idx
= 0; idx
< count
; idx
++)
3955 if (this->symbol_name_slot_invalid (idx
))
3958 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3960 /* Add each name component to the name component table. */
3961 unsigned int previous_len
= 0;
3963 if (strstr (name
, "::") != nullptr)
3965 for (unsigned int current_len
= cp_find_first_component (name
);
3966 name
[current_len
] != '\0';
3967 current_len
+= cp_find_first_component (name
+ current_len
))
3969 gdb_assert (name
[current_len
] == ':');
3970 this->name_components
.push_back ({previous_len
, idx
});
3971 /* Skip the '::'. */
3973 previous_len
= current_len
;
3978 /* Handle the Ada encoded (aka mangled) form here. */
3979 for (const char *iter
= strstr (name
, "__");
3981 iter
= strstr (iter
, "__"))
3983 this->name_components
.push_back ({previous_len
, idx
});
3985 previous_len
= iter
- name
;
3989 this->name_components
.push_back ({previous_len
, idx
});
3992 /* Sort name_components elements by name. */
3993 auto name_comp_compare
= [&] (const name_component
&left
,
3994 const name_component
&right
)
3996 const char *left_qualified
3997 = this->symbol_name_at (left
.idx
, per_objfile
);
3998 const char *right_qualified
3999 = this->symbol_name_at (right
.idx
, per_objfile
);
4001 const char *left_name
= left_qualified
+ left
.name_offset
;
4002 const char *right_name
= right_qualified
+ right
.name_offset
;
4004 return name_cmp (left_name
, right_name
) < 0;
4007 std::sort (this->name_components
.begin (),
4008 this->name_components
.end (),
4012 /* Helper for dw2_expand_symtabs_matching that works with a
4013 mapped_index_base instead of the containing objfile. This is split
4014 to a separate function in order to be able to unit test the
4015 name_components matching using a mock mapped_index_base. For each
4016 symbol name that matches, calls MATCH_CALLBACK, passing it the
4017 symbol's index in the mapped_index_base symbol table. */
4020 dw2_expand_symtabs_matching_symbol
4021 (mapped_index_base
&index
,
4022 const lookup_name_info
&lookup_name_in
,
4023 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4024 enum search_domain kind
,
4025 gdb::function_view
<bool (offset_type
)> match_callback
,
4026 dwarf2_per_objfile
*per_objfile
)
4028 lookup_name_info lookup_name_without_params
4029 = lookup_name_in
.make_ignore_params ();
4031 /* Build the symbol name component sorted vector, if we haven't
4033 index
.build_name_components (per_objfile
);
4035 /* The same symbol may appear more than once in the range though.
4036 E.g., if we're looking for symbols that complete "w", and we have
4037 a symbol named "w1::w2", we'll find the two name components for
4038 that same symbol in the range. To be sure we only call the
4039 callback once per symbol, we first collect the symbol name
4040 indexes that matched in a temporary vector and ignore
4042 std::vector
<offset_type
> matches
;
4044 struct name_and_matcher
4046 symbol_name_matcher_ftype
*matcher
;
4049 bool operator== (const name_and_matcher
&other
) const
4051 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4055 /* A vector holding all the different symbol name matchers, for all
4057 std::vector
<name_and_matcher
> matchers
;
4059 for (int i
= 0; i
< nr_languages
; i
++)
4061 enum language lang_e
= (enum language
) i
;
4063 const language_defn
*lang
= language_def (lang_e
);
4064 symbol_name_matcher_ftype
*name_matcher
4065 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4067 name_and_matcher key
{
4069 lookup_name_without_params
.language_lookup_name (lang_e
)
4072 /* Don't insert the same comparison routine more than once.
4073 Note that we do this linear walk. This is not a problem in
4074 practice because the number of supported languages is
4076 if (std::find (matchers
.begin (), matchers
.end (), key
)
4079 matchers
.push_back (std::move (key
));
4082 = index
.find_name_components_bounds (lookup_name_without_params
,
4083 lang_e
, per_objfile
);
4085 /* Now for each symbol name in range, check to see if we have a name
4086 match, and if so, call the MATCH_CALLBACK callback. */
4088 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4090 const char *qualified
4091 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4093 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4094 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4097 matches
.push_back (bounds
.first
->idx
);
4101 std::sort (matches
.begin (), matches
.end ());
4103 /* Finally call the callback, once per match. */
4105 for (offset_type idx
: matches
)
4109 if (!match_callback (idx
))
4115 /* Above we use a type wider than idx's for 'prev', since 0 and
4116 (offset_type)-1 are both possible values. */
4117 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4122 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4124 /* A mock .gdb_index/.debug_names-like name index table, enough to
4125 exercise dw2_expand_symtabs_matching_symbol, which works with the
4126 mapped_index_base interface. Builds an index from the symbol list
4127 passed as parameter to the constructor. */
4128 class mock_mapped_index
: public mapped_index_base
4131 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4132 : m_symbol_table (symbols
)
4135 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4137 /* Return the number of names in the symbol table. */
4138 size_t symbol_name_count () const override
4140 return m_symbol_table
.size ();
4143 /* Get the name of the symbol at IDX in the symbol table. */
4144 const char *symbol_name_at
4145 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4147 return m_symbol_table
[idx
];
4151 gdb::array_view
<const char *> m_symbol_table
;
4154 /* Convenience function that converts a NULL pointer to a "<null>"
4155 string, to pass to print routines. */
4158 string_or_null (const char *str
)
4160 return str
!= NULL
? str
: "<null>";
4163 /* Check if a lookup_name_info built from
4164 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4165 index. EXPECTED_LIST is the list of expected matches, in expected
4166 matching order. If no match expected, then an empty list is
4167 specified. Returns true on success. On failure prints a warning
4168 indicating the file:line that failed, and returns false. */
4171 check_match (const char *file
, int line
,
4172 mock_mapped_index
&mock_index
,
4173 const char *name
, symbol_name_match_type match_type
,
4174 bool completion_mode
,
4175 std::initializer_list
<const char *> expected_list
,
4176 dwarf2_per_objfile
*per_objfile
)
4178 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4180 bool matched
= true;
4182 auto mismatch
= [&] (const char *expected_str
,
4185 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4186 "expected=\"%s\", got=\"%s\"\n"),
4188 (match_type
== symbol_name_match_type::FULL
4190 name
, string_or_null (expected_str
), string_or_null (got
));
4194 auto expected_it
= expected_list
.begin ();
4195 auto expected_end
= expected_list
.end ();
4197 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4199 [&] (offset_type idx
)
4201 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4202 const char *expected_str
4203 = expected_it
== expected_end
? NULL
: *expected_it
++;
4205 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4206 mismatch (expected_str
, matched_name
);
4210 const char *expected_str
4211 = expected_it
== expected_end
? NULL
: *expected_it
++;
4212 if (expected_str
!= NULL
)
4213 mismatch (expected_str
, NULL
);
4218 /* The symbols added to the mock mapped_index for testing (in
4220 static const char *test_symbols
[] = {
4229 "ns2::tmpl<int>::foo2",
4230 "(anonymous namespace)::A::B::C",
4232 /* These are used to check that the increment-last-char in the
4233 matching algorithm for completion doesn't match "t1_fund" when
4234 completing "t1_func". */
4240 /* A UTF-8 name with multi-byte sequences to make sure that
4241 cp-name-parser understands this as a single identifier ("função"
4242 is "function" in PT). */
4245 /* \377 (0xff) is Latin1 'ÿ'. */
4248 /* \377 (0xff) is Latin1 'ÿ'. */
4252 /* A name with all sorts of complications. Starts with "z" to make
4253 it easier for the completion tests below. */
4254 #define Z_SYM_NAME \
4255 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4256 "::tuple<(anonymous namespace)::ui*, " \
4257 "std::default_delete<(anonymous namespace)::ui>, void>"
4262 /* Returns true if the mapped_index_base::find_name_component_bounds
4263 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4264 in completion mode. */
4267 check_find_bounds_finds (mapped_index_base
&index
,
4268 const char *search_name
,
4269 gdb::array_view
<const char *> expected_syms
,
4270 dwarf2_per_objfile
*per_objfile
)
4272 lookup_name_info
lookup_name (search_name
,
4273 symbol_name_match_type::FULL
, true);
4275 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4279 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4280 if (distance
!= expected_syms
.size ())
4283 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4285 auto nc_elem
= bounds
.first
+ exp_elem
;
4286 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4287 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4294 /* Test the lower-level mapped_index::find_name_component_bounds
4298 test_mapped_index_find_name_component_bounds ()
4300 mock_mapped_index
mock_index (test_symbols
);
4302 mock_index
.build_name_components (NULL
/* per_objfile */);
4304 /* Test the lower-level mapped_index::find_name_component_bounds
4305 method in completion mode. */
4307 static const char *expected_syms
[] = {
4312 SELF_CHECK (check_find_bounds_finds
4313 (mock_index
, "t1_func", expected_syms
,
4314 NULL
/* per_objfile */));
4317 /* Check that the increment-last-char in the name matching algorithm
4318 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4320 static const char *expected_syms1
[] = {
4324 SELF_CHECK (check_find_bounds_finds
4325 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4327 static const char *expected_syms2
[] = {
4330 SELF_CHECK (check_find_bounds_finds
4331 (mock_index
, "\377\377", expected_syms2
,
4332 NULL
/* per_objfile */));
4336 /* Test dw2_expand_symtabs_matching_symbol. */
4339 test_dw2_expand_symtabs_matching_symbol ()
4341 mock_mapped_index
mock_index (test_symbols
);
4343 /* We let all tests run until the end even if some fails, for debug
4345 bool any_mismatch
= false;
4347 /* Create the expected symbols list (an initializer_list). Needed
4348 because lists have commas, and we need to pass them to CHECK,
4349 which is a macro. */
4350 #define EXPECT(...) { __VA_ARGS__ }
4352 /* Wrapper for check_match that passes down the current
4353 __FILE__/__LINE__. */
4354 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4355 any_mismatch |= !check_match (__FILE__, __LINE__, \
4357 NAME, MATCH_TYPE, COMPLETION_MODE, \
4358 EXPECTED_LIST, NULL)
4360 /* Identity checks. */
4361 for (const char *sym
: test_symbols
)
4363 /* Should be able to match all existing symbols. */
4364 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4367 /* Should be able to match all existing symbols with
4369 std::string with_params
= std::string (sym
) + "(int)";
4370 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4373 /* Should be able to match all existing symbols with
4374 parameters and qualifiers. */
4375 with_params
= std::string (sym
) + " ( int ) const";
4376 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4379 /* This should really find sym, but cp-name-parser.y doesn't
4380 know about lvalue/rvalue qualifiers yet. */
4381 with_params
= std::string (sym
) + " ( int ) &&";
4382 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4386 /* Check that the name matching algorithm for completion doesn't get
4387 confused with Latin1 'ÿ' / 0xff. */
4389 static const char str
[] = "\377";
4390 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4391 EXPECT ("\377", "\377\377123"));
4394 /* Check that the increment-last-char in the matching algorithm for
4395 completion doesn't match "t1_fund" when completing "t1_func". */
4397 static const char str
[] = "t1_func";
4398 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4399 EXPECT ("t1_func", "t1_func1"));
4402 /* Check that completion mode works at each prefix of the expected
4405 static const char str
[] = "function(int)";
4406 size_t len
= strlen (str
);
4409 for (size_t i
= 1; i
< len
; i
++)
4411 lookup
.assign (str
, i
);
4412 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4413 EXPECT ("function"));
4417 /* While "w" is a prefix of both components, the match function
4418 should still only be called once. */
4420 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4422 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4426 /* Same, with a "complicated" symbol. */
4428 static const char str
[] = Z_SYM_NAME
;
4429 size_t len
= strlen (str
);
4432 for (size_t i
= 1; i
< len
; i
++)
4434 lookup
.assign (str
, i
);
4435 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4436 EXPECT (Z_SYM_NAME
));
4440 /* In FULL mode, an incomplete symbol doesn't match. */
4442 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4446 /* A complete symbol with parameters matches any overload, since the
4447 index has no overload info. */
4449 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4450 EXPECT ("std::zfunction", "std::zfunction2"));
4451 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4452 EXPECT ("std::zfunction", "std::zfunction2"));
4453 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4454 EXPECT ("std::zfunction", "std::zfunction2"));
4457 /* Check that whitespace is ignored appropriately. A symbol with a
4458 template argument list. */
4460 static const char expected
[] = "ns::foo<int>";
4461 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4463 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4467 /* Check that whitespace is ignored appropriately. A symbol with a
4468 template argument list that includes a pointer. */
4470 static const char expected
[] = "ns::foo<char*>";
4471 /* Try both completion and non-completion modes. */
4472 static const bool completion_mode
[2] = {false, true};
4473 for (size_t i
= 0; i
< 2; i
++)
4475 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4476 completion_mode
[i
], EXPECT (expected
));
4477 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4478 completion_mode
[i
], EXPECT (expected
));
4480 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4481 completion_mode
[i
], EXPECT (expected
));
4482 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4483 completion_mode
[i
], EXPECT (expected
));
4488 /* Check method qualifiers are ignored. */
4489 static const char expected
[] = "ns::foo<char*>";
4490 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4491 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4492 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4493 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4494 CHECK_MATCH ("foo < char * > ( int ) const",
4495 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4496 CHECK_MATCH ("foo < char * > ( int ) &&",
4497 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4500 /* Test lookup names that don't match anything. */
4502 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4505 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4509 /* Some wild matching tests, exercising "(anonymous namespace)",
4510 which should not be confused with a parameter list. */
4512 static const char *syms
[] = {
4516 "A :: B :: C ( int )",
4521 for (const char *s
: syms
)
4523 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4524 EXPECT ("(anonymous namespace)::A::B::C"));
4529 static const char expected
[] = "ns2::tmpl<int>::foo2";
4530 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4532 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4536 SELF_CHECK (!any_mismatch
);
4545 test_mapped_index_find_name_component_bounds ();
4546 test_dw2_expand_symtabs_matching_symbol ();
4549 }} // namespace selftests::dw2_expand_symtabs_matching
4551 #endif /* GDB_SELF_TEST */
4553 /* If FILE_MATCHER is NULL or if PER_CU has
4554 dwarf2_per_cu_quick_data::MARK set (see
4555 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4556 EXPANSION_NOTIFY on it. */
4559 dw2_expand_symtabs_matching_one
4560 (dwarf2_per_cu_data
*per_cu
,
4561 dwarf2_per_objfile
*per_objfile
,
4562 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4563 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4565 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4567 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4569 compunit_symtab
*symtab
4570 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4571 gdb_assert (symtab
!= nullptr);
4573 if (expansion_notify
!= NULL
&& symtab_was_null
)
4574 expansion_notify (symtab
);
4578 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4579 matched, to expand corresponding CUs that were marked. IDX is the
4580 index of the symbol name that matched. */
4583 dw2_expand_marked_cus
4584 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4585 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4586 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4589 offset_type
*vec
, vec_len
, vec_idx
;
4590 bool global_seen
= false;
4591 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4593 vec
= (offset_type
*) (index
.constant_pool
4594 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4595 vec_len
= MAYBE_SWAP (vec
[0]);
4596 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4598 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4599 /* This value is only valid for index versions >= 7. */
4600 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4601 gdb_index_symbol_kind symbol_kind
=
4602 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4603 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4604 /* Only check the symbol attributes if they're present.
4605 Indices prior to version 7 don't record them,
4606 and indices >= 7 may elide them for certain symbols
4607 (gold does this). */
4610 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4612 /* Work around gold/15646. */
4615 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4623 /* Only check the symbol's kind if it has one. */
4628 case VARIABLES_DOMAIN
:
4629 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4632 case FUNCTIONS_DOMAIN
:
4633 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4637 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4640 case MODULES_DOMAIN
:
4641 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4649 /* Don't crash on bad data. */
4650 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4651 + per_objfile
->per_bfd
->all_type_units
.size ()))
4653 complaint (_(".gdb_index entry has bad CU index"
4654 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4658 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4659 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4664 /* If FILE_MATCHER is non-NULL, set all the
4665 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4666 that match FILE_MATCHER. */
4669 dw_expand_symtabs_matching_file_matcher
4670 (dwarf2_per_objfile
*per_objfile
,
4671 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4673 if (file_matcher
== NULL
)
4676 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4678 NULL
, xcalloc
, xfree
));
4679 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4681 NULL
, xcalloc
, xfree
));
4683 /* The rule is CUs specify all the files, including those used by
4684 any TU, so there's no need to scan TUs here. */
4686 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4690 per_cu
->v
.quick
->mark
= 0;
4692 /* We only need to look at symtabs not already expanded. */
4693 if (per_objfile
->symtab_set_p (per_cu
))
4696 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4697 if (file_data
== NULL
)
4700 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4702 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4704 per_cu
->v
.quick
->mark
= 1;
4708 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4710 const char *this_real_name
;
4712 if (file_matcher (file_data
->file_names
[j
], false))
4714 per_cu
->v
.quick
->mark
= 1;
4718 /* Before we invoke realpath, which can get expensive when many
4719 files are involved, do a quick comparison of the basenames. */
4720 if (!basenames_may_differ
4721 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4725 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4726 if (file_matcher (this_real_name
, false))
4728 per_cu
->v
.quick
->mark
= 1;
4733 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4734 ? visited_found
.get ()
4735 : visited_not_found
.get (),
4742 dw2_expand_symtabs_matching
4743 (struct objfile
*objfile
,
4744 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4745 const lookup_name_info
*lookup_name
,
4746 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4747 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4748 enum search_domain kind
)
4750 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4752 /* index_table is NULL if OBJF_READNOW. */
4753 if (!per_objfile
->per_bfd
->index_table
)
4756 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4758 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4760 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4764 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4765 file_matcher
, expansion_notify
);
4770 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4772 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4774 kind
, [&] (offset_type idx
)
4776 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4782 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4785 static struct compunit_symtab
*
4786 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4791 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4792 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4795 if (cust
->includes
== NULL
)
4798 for (i
= 0; cust
->includes
[i
]; ++i
)
4800 struct compunit_symtab
*s
= cust
->includes
[i
];
4802 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4810 static struct compunit_symtab
*
4811 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4812 struct bound_minimal_symbol msymbol
,
4814 struct obj_section
*section
,
4817 struct dwarf2_per_cu_data
*data
;
4818 struct compunit_symtab
*result
;
4820 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4823 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4824 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4825 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4829 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4830 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4831 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4832 paddress (objfile
->arch (), pc
));
4834 result
= recursively_find_pc_sect_compunit_symtab
4835 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4837 gdb_assert (result
!= NULL
);
4842 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4843 void *data
, int need_fullname
)
4845 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4847 if (!per_objfile
->per_bfd
->filenames_cache
)
4849 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4851 htab_up
visited (htab_create_alloc (10,
4852 htab_hash_pointer
, htab_eq_pointer
,
4853 NULL
, xcalloc
, xfree
));
4855 /* The rule is CUs specify all the files, including those used
4856 by any TU, so there's no need to scan TUs here. We can
4857 ignore file names coming from already-expanded CUs. */
4859 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4861 if (per_objfile
->symtab_set_p (per_cu
))
4863 void **slot
= htab_find_slot (visited
.get (),
4864 per_cu
->v
.quick
->file_names
,
4867 *slot
= per_cu
->v
.quick
->file_names
;
4871 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4873 /* We only need to look at symtabs not already expanded. */
4874 if (per_objfile
->symtab_set_p (per_cu
))
4877 quick_file_names
*file_data
4878 = dw2_get_file_names (per_cu
, per_objfile
);
4879 if (file_data
== NULL
)
4882 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4885 /* Already visited. */
4890 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4892 const char *filename
= file_data
->file_names
[j
];
4893 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4898 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4900 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4903 this_real_name
= gdb_realpath (filename
);
4904 (*fun
) (filename
, this_real_name
.get (), data
);
4909 dw2_has_symbols (struct objfile
*objfile
)
4914 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4917 dw2_find_last_source_symtab
,
4918 dw2_forget_cached_source_info
,
4919 dw2_map_symtabs_matching_filename
,
4924 dw2_expand_symtabs_for_function
,
4925 dw2_expand_all_symtabs
,
4926 dw2_expand_symtabs_with_fullname
,
4927 dw2_map_matching_symbols
,
4928 dw2_expand_symtabs_matching
,
4929 dw2_find_pc_sect_compunit_symtab
,
4931 dw2_map_symbol_filenames
4934 /* DWARF-5 debug_names reader. */
4936 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4937 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4939 /* A helper function that reads the .debug_names section in SECTION
4940 and fills in MAP. FILENAME is the name of the file containing the
4941 section; it is used for error reporting.
4943 Returns true if all went well, false otherwise. */
4946 read_debug_names_from_section (struct objfile
*objfile
,
4947 const char *filename
,
4948 struct dwarf2_section_info
*section
,
4949 mapped_debug_names
&map
)
4951 if (section
->empty ())
4954 /* Older elfutils strip versions could keep the section in the main
4955 executable while splitting it for the separate debug info file. */
4956 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4959 section
->read (objfile
);
4961 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4963 const gdb_byte
*addr
= section
->buffer
;
4965 bfd
*const abfd
= section
->get_bfd_owner ();
4967 unsigned int bytes_read
;
4968 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4971 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4972 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4973 if (bytes_read
+ length
!= section
->size
)
4975 /* There may be multiple per-CU indices. */
4976 warning (_("Section .debug_names in %s length %s does not match "
4977 "section length %s, ignoring .debug_names."),
4978 filename
, plongest (bytes_read
+ length
),
4979 pulongest (section
->size
));
4983 /* The version number. */
4984 uint16_t version
= read_2_bytes (abfd
, addr
);
4988 warning (_("Section .debug_names in %s has unsupported version %d, "
4989 "ignoring .debug_names."),
4995 uint16_t padding
= read_2_bytes (abfd
, addr
);
4999 warning (_("Section .debug_names in %s has unsupported padding %d, "
5000 "ignoring .debug_names."),
5005 /* comp_unit_count - The number of CUs in the CU list. */
5006 map
.cu_count
= read_4_bytes (abfd
, addr
);
5009 /* local_type_unit_count - The number of TUs in the local TU
5011 map
.tu_count
= read_4_bytes (abfd
, addr
);
5014 /* foreign_type_unit_count - The number of TUs in the foreign TU
5016 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5018 if (foreign_tu_count
!= 0)
5020 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5021 "ignoring .debug_names."),
5022 filename
, static_cast<unsigned long> (foreign_tu_count
));
5026 /* bucket_count - The number of hash buckets in the hash lookup
5028 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5031 /* name_count - The number of unique names in the index. */
5032 map
.name_count
= read_4_bytes (abfd
, addr
);
5035 /* abbrev_table_size - The size in bytes of the abbreviations
5037 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5040 /* augmentation_string_size - The size in bytes of the augmentation
5041 string. This value is rounded up to a multiple of 4. */
5042 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5044 map
.augmentation_is_gdb
= ((augmentation_string_size
5045 == sizeof (dwarf5_augmentation
))
5046 && memcmp (addr
, dwarf5_augmentation
,
5047 sizeof (dwarf5_augmentation
)) == 0);
5048 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5049 addr
+= augmentation_string_size
;
5052 map
.cu_table_reordered
= addr
;
5053 addr
+= map
.cu_count
* map
.offset_size
;
5055 /* List of Local TUs */
5056 map
.tu_table_reordered
= addr
;
5057 addr
+= map
.tu_count
* map
.offset_size
;
5059 /* Hash Lookup Table */
5060 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5061 addr
+= map
.bucket_count
* 4;
5062 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5063 addr
+= map
.name_count
* 4;
5066 map
.name_table_string_offs_reordered
= addr
;
5067 addr
+= map
.name_count
* map
.offset_size
;
5068 map
.name_table_entry_offs_reordered
= addr
;
5069 addr
+= map
.name_count
* map
.offset_size
;
5071 const gdb_byte
*abbrev_table_start
= addr
;
5074 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5079 const auto insertpair
5080 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5081 if (!insertpair
.second
)
5083 warning (_("Section .debug_names in %s has duplicate index %s, "
5084 "ignoring .debug_names."),
5085 filename
, pulongest (index_num
));
5088 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5089 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5094 mapped_debug_names::index_val::attr attr
;
5095 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5097 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5099 if (attr
.form
== DW_FORM_implicit_const
)
5101 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5105 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5107 indexval
.attr_vec
.push_back (std::move (attr
));
5110 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5112 warning (_("Section .debug_names in %s has abbreviation_table "
5113 "of size %s vs. written as %u, ignoring .debug_names."),
5114 filename
, plongest (addr
- abbrev_table_start
),
5118 map
.entry_pool
= addr
;
5123 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5127 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5128 const mapped_debug_names
&map
,
5129 dwarf2_section_info
§ion
,
5132 if (!map
.augmentation_is_gdb
)
5134 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5136 sect_offset sect_off
5137 = (sect_offset
) (extract_unsigned_integer
5138 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5140 map
.dwarf5_byte_order
));
5141 /* We don't know the length of the CU, because the CU list in a
5142 .debug_names index can be incomplete, so we can't use the start of
5143 the next CU as end of this CU. We create the CUs here with length 0,
5144 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5145 dwarf2_per_cu_data
*per_cu
5146 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5147 per_bfd
->all_comp_units
.push_back (per_cu
);
5151 sect_offset sect_off_prev
;
5152 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5154 sect_offset sect_off_next
;
5155 if (i
< map
.cu_count
)
5158 = (sect_offset
) (extract_unsigned_integer
5159 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5161 map
.dwarf5_byte_order
));
5164 sect_off_next
= (sect_offset
) section
.size
;
5167 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5168 dwarf2_per_cu_data
*per_cu
5169 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5170 sect_off_prev
, length
);
5171 per_bfd
->all_comp_units
.push_back (per_cu
);
5173 sect_off_prev
= sect_off_next
;
5177 /* Read the CU list from the mapped index, and use it to create all
5178 the CU objects for this dwarf2_per_objfile. */
5181 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5182 const mapped_debug_names
&map
,
5183 const mapped_debug_names
&dwz_map
)
5185 gdb_assert (per_bfd
->all_comp_units
.empty ());
5186 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5188 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5189 false /* is_dwz */);
5191 if (dwz_map
.cu_count
== 0)
5194 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5195 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5199 /* Read .debug_names. If everything went ok, initialize the "quick"
5200 elements of all the CUs and return true. Otherwise, return false. */
5203 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5205 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5206 mapped_debug_names dwz_map
;
5207 struct objfile
*objfile
= per_objfile
->objfile
;
5209 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5210 &per_objfile
->per_bfd
->debug_names
, *map
))
5213 /* Don't use the index if it's empty. */
5214 if (map
->name_count
== 0)
5217 /* If there is a .dwz file, read it so we can get its CU list as
5219 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
5222 if (!read_debug_names_from_section (objfile
,
5223 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5224 &dwz
->debug_names
, dwz_map
))
5226 warning (_("could not read '.debug_names' section from %s; skipping"),
5227 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5232 create_cus_from_debug_names (per_objfile
->per_bfd
, *map
, dwz_map
);
5234 if (map
->tu_count
!= 0)
5236 /* We can only handle a single .debug_types when we have an
5238 if (per_objfile
->per_bfd
->types
.size () != 1)
5241 dwarf2_section_info
*section
= &per_objfile
->per_bfd
->types
[0];
5243 create_signatured_type_table_from_debug_names
5244 (per_objfile
, *map
, section
, &per_objfile
->per_bfd
->abbrev
);
5247 create_addrmap_from_aranges (per_objfile
,
5248 &per_objfile
->per_bfd
->debug_aranges
);
5250 per_objfile
->per_bfd
->debug_names_table
= std::move (map
);
5251 per_objfile
->per_bfd
->using_index
= 1;
5252 per_objfile
->per_bfd
->quick_file_names_table
=
5253 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5258 /* Type used to manage iterating over all CUs looking for a symbol for
5261 class dw2_debug_names_iterator
5264 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5265 gdb::optional
<block_enum
> block_index
,
5267 const char *name
, dwarf2_per_objfile
*per_objfile
)
5268 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5269 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5270 m_per_objfile (per_objfile
)
5273 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5274 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5277 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5278 m_per_objfile (per_objfile
)
5281 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5282 block_enum block_index
, domain_enum domain
,
5283 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5284 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5285 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5286 m_per_objfile (per_objfile
)
5289 /* Return the next matching CU or NULL if there are no more. */
5290 dwarf2_per_cu_data
*next ();
5293 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5295 dwarf2_per_objfile
*per_objfile
);
5296 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5298 dwarf2_per_objfile
*per_objfile
);
5300 /* The internalized form of .debug_names. */
5301 const mapped_debug_names
&m_map
;
5303 /* If set, only look for symbols that match that block. Valid values are
5304 GLOBAL_BLOCK and STATIC_BLOCK. */
5305 const gdb::optional
<block_enum
> m_block_index
;
5307 /* The kind of symbol we're looking for. */
5308 const domain_enum m_domain
= UNDEF_DOMAIN
;
5309 const search_domain m_search
= ALL_DOMAIN
;
5311 /* The list of CUs from the index entry of the symbol, or NULL if
5313 const gdb_byte
*m_addr
;
5315 dwarf2_per_objfile
*m_per_objfile
;
5319 mapped_debug_names::namei_to_name
5320 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5322 const ULONGEST namei_string_offs
5323 = extract_unsigned_integer ((name_table_string_offs_reordered
5324 + namei
* offset_size
),
5327 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5330 /* Find a slot in .debug_names for the object named NAME. If NAME is
5331 found, return pointer to its pool data. If NAME cannot be found,
5335 dw2_debug_names_iterator::find_vec_in_debug_names
5336 (const mapped_debug_names
&map
, const char *name
,
5337 dwarf2_per_objfile
*per_objfile
)
5339 int (*cmp
) (const char *, const char *);
5341 gdb::unique_xmalloc_ptr
<char> without_params
;
5342 if (current_language
->la_language
== language_cplus
5343 || current_language
->la_language
== language_fortran
5344 || current_language
->la_language
== language_d
)
5346 /* NAME is already canonical. Drop any qualifiers as
5347 .debug_names does not contain any. */
5349 if (strchr (name
, '(') != NULL
)
5351 without_params
= cp_remove_params (name
);
5352 if (without_params
!= NULL
)
5353 name
= without_params
.get ();
5357 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5359 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5361 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5362 (map
.bucket_table_reordered
5363 + (full_hash
% map
.bucket_count
)), 4,
5364 map
.dwarf5_byte_order
);
5368 if (namei
>= map
.name_count
)
5370 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5372 namei
, map
.name_count
,
5373 objfile_name (per_objfile
->objfile
));
5379 const uint32_t namei_full_hash
5380 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5381 (map
.hash_table_reordered
+ namei
), 4,
5382 map
.dwarf5_byte_order
);
5383 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5386 if (full_hash
== namei_full_hash
)
5388 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5390 #if 0 /* An expensive sanity check. */
5391 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5393 complaint (_("Wrong .debug_names hash for string at index %u "
5395 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5400 if (cmp (namei_string
, name
) == 0)
5402 const ULONGEST namei_entry_offs
5403 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5404 + namei
* map
.offset_size
),
5405 map
.offset_size
, map
.dwarf5_byte_order
);
5406 return map
.entry_pool
+ namei_entry_offs
;
5411 if (namei
>= map
.name_count
)
5417 dw2_debug_names_iterator::find_vec_in_debug_names
5418 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5420 if (namei
>= map
.name_count
)
5422 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5424 namei
, map
.name_count
,
5425 objfile_name (per_objfile
->objfile
));
5429 const ULONGEST namei_entry_offs
5430 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5431 + namei
* map
.offset_size
),
5432 map
.offset_size
, map
.dwarf5_byte_order
);
5433 return map
.entry_pool
+ namei_entry_offs
;
5436 /* See dw2_debug_names_iterator. */
5438 dwarf2_per_cu_data
*
5439 dw2_debug_names_iterator::next ()
5444 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5445 struct objfile
*objfile
= m_per_objfile
->objfile
;
5446 bfd
*const abfd
= objfile
->obfd
;
5450 unsigned int bytes_read
;
5451 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5452 m_addr
+= bytes_read
;
5456 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5457 if (indexval_it
== m_map
.abbrev_map
.cend ())
5459 complaint (_("Wrong .debug_names undefined abbrev code %s "
5461 pulongest (abbrev
), objfile_name (objfile
));
5464 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5465 enum class symbol_linkage
{
5469 } symbol_linkage_
= symbol_linkage::unknown
;
5470 dwarf2_per_cu_data
*per_cu
= NULL
;
5471 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5476 case DW_FORM_implicit_const
:
5477 ull
= attr
.implicit_const
;
5479 case DW_FORM_flag_present
:
5483 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5484 m_addr
+= bytes_read
;
5487 ull
= read_4_bytes (abfd
, m_addr
);
5491 ull
= read_8_bytes (abfd
, m_addr
);
5494 case DW_FORM_ref_sig8
:
5495 ull
= read_8_bytes (abfd
, m_addr
);
5499 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5500 dwarf_form_name (attr
.form
),
5501 objfile_name (objfile
));
5504 switch (attr
.dw_idx
)
5506 case DW_IDX_compile_unit
:
5507 /* Don't crash on bad data. */
5508 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5510 complaint (_(".debug_names entry has bad CU index %s"
5513 objfile_name (objfile
));
5516 per_cu
= per_bfd
->get_cutu (ull
);
5518 case DW_IDX_type_unit
:
5519 /* Don't crash on bad data. */
5520 if (ull
>= per_bfd
->all_type_units
.size ())
5522 complaint (_(".debug_names entry has bad TU index %s"
5525 objfile_name (objfile
));
5528 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5530 case DW_IDX_die_offset
:
5531 /* In a per-CU index (as opposed to a per-module index), index
5532 entries without CU attribute implicitly refer to the single CU. */
5534 per_cu
= per_bfd
->get_cu (0);
5536 case DW_IDX_GNU_internal
:
5537 if (!m_map
.augmentation_is_gdb
)
5539 symbol_linkage_
= symbol_linkage::static_
;
5541 case DW_IDX_GNU_external
:
5542 if (!m_map
.augmentation_is_gdb
)
5544 symbol_linkage_
= symbol_linkage::extern_
;
5549 /* Skip if already read in. */
5550 if (m_per_objfile
->symtab_set_p (per_cu
))
5553 /* Check static vs global. */
5554 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5556 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5557 const bool symbol_is_static
=
5558 symbol_linkage_
== symbol_linkage::static_
;
5559 if (want_static
!= symbol_is_static
)
5563 /* Match dw2_symtab_iter_next, symbol_kind
5564 and debug_names::psymbol_tag. */
5568 switch (indexval
.dwarf_tag
)
5570 case DW_TAG_variable
:
5571 case DW_TAG_subprogram
:
5572 /* Some types are also in VAR_DOMAIN. */
5573 case DW_TAG_typedef
:
5574 case DW_TAG_structure_type
:
5581 switch (indexval
.dwarf_tag
)
5583 case DW_TAG_typedef
:
5584 case DW_TAG_structure_type
:
5591 switch (indexval
.dwarf_tag
)
5594 case DW_TAG_variable
:
5601 switch (indexval
.dwarf_tag
)
5613 /* Match dw2_expand_symtabs_matching, symbol_kind and
5614 debug_names::psymbol_tag. */
5617 case VARIABLES_DOMAIN
:
5618 switch (indexval
.dwarf_tag
)
5620 case DW_TAG_variable
:
5626 case FUNCTIONS_DOMAIN
:
5627 switch (indexval
.dwarf_tag
)
5629 case DW_TAG_subprogram
:
5636 switch (indexval
.dwarf_tag
)
5638 case DW_TAG_typedef
:
5639 case DW_TAG_structure_type
:
5645 case MODULES_DOMAIN
:
5646 switch (indexval
.dwarf_tag
)
5660 static struct compunit_symtab
*
5661 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5662 const char *name
, domain_enum domain
)
5664 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5666 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5669 /* index is NULL if OBJF_READNOW. */
5672 const auto &map
= *mapp
;
5674 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5676 struct compunit_symtab
*stab_best
= NULL
;
5677 struct dwarf2_per_cu_data
*per_cu
;
5678 while ((per_cu
= iter
.next ()) != NULL
)
5680 struct symbol
*sym
, *with_opaque
= NULL
;
5681 compunit_symtab
*stab
5682 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5683 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5684 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5686 sym
= block_find_symbol (block
, name
, domain
,
5687 block_find_non_opaque_type_preferred
,
5690 /* Some caution must be observed with overloaded functions and
5691 methods, since the index will not contain any overload
5692 information (but NAME might contain it). */
5695 && strcmp_iw (sym
->search_name (), name
) == 0)
5697 if (with_opaque
!= NULL
5698 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5701 /* Keep looking through other CUs. */
5707 /* This dumps minimal information about .debug_names. It is called
5708 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5709 uses this to verify that .debug_names has been loaded. */
5712 dw2_debug_names_dump (struct objfile
*objfile
)
5714 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5716 gdb_assert (per_objfile
->per_bfd
->using_index
);
5717 printf_filtered (".debug_names:");
5718 if (per_objfile
->per_bfd
->debug_names_table
)
5719 printf_filtered (" exists\n");
5721 printf_filtered (" faked for \"readnow\"\n");
5722 printf_filtered ("\n");
5726 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5727 const char *func_name
)
5729 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5731 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5732 if (per_objfile
->per_bfd
->debug_names_table
)
5734 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5736 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5739 struct dwarf2_per_cu_data
*per_cu
;
5740 while ((per_cu
= iter
.next ()) != NULL
)
5741 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5746 dw2_debug_names_map_matching_symbols
5747 (struct objfile
*objfile
,
5748 const lookup_name_info
&name
, domain_enum domain
,
5750 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5751 symbol_compare_ftype
*ordered_compare
)
5753 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5755 /* debug_names_table is NULL if OBJF_READNOW. */
5756 if (!per_objfile
->per_bfd
->debug_names_table
)
5759 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5760 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5762 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5763 auto matcher
= [&] (const char *symname
)
5765 if (ordered_compare
== nullptr)
5767 return ordered_compare (symname
, match_name
) == 0;
5770 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5771 [&] (offset_type namei
)
5773 /* The name was matched, now expand corresponding CUs that were
5775 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5778 struct dwarf2_per_cu_data
*per_cu
;
5779 while ((per_cu
= iter
.next ()) != NULL
)
5780 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5785 /* It's a shame we couldn't do this inside the
5786 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5787 that have already been expanded. Instead, this loop matches what
5788 the psymtab code does. */
5789 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5791 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5792 if (symtab
!= nullptr)
5794 const struct block
*block
5795 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5796 if (!iterate_over_symbols_terminated (block
, name
,
5804 dw2_debug_names_expand_symtabs_matching
5805 (struct objfile
*objfile
,
5806 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5807 const lookup_name_info
*lookup_name
,
5808 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5809 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5810 enum search_domain kind
)
5812 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5814 /* debug_names_table is NULL if OBJF_READNOW. */
5815 if (!per_objfile
->per_bfd
->debug_names_table
)
5818 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5820 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5822 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5826 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5832 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5834 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5836 kind
, [&] (offset_type namei
)
5838 /* The name was matched, now expand corresponding CUs that were
5840 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5842 struct dwarf2_per_cu_data
*per_cu
;
5843 while ((per_cu
= iter
.next ()) != NULL
)
5844 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5850 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5853 dw2_find_last_source_symtab
,
5854 dw2_forget_cached_source_info
,
5855 dw2_map_symtabs_matching_filename
,
5856 dw2_debug_names_lookup_symbol
,
5859 dw2_debug_names_dump
,
5860 dw2_debug_names_expand_symtabs_for_function
,
5861 dw2_expand_all_symtabs
,
5862 dw2_expand_symtabs_with_fullname
,
5863 dw2_debug_names_map_matching_symbols
,
5864 dw2_debug_names_expand_symtabs_matching
,
5865 dw2_find_pc_sect_compunit_symtab
,
5867 dw2_map_symbol_filenames
5870 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5871 to either a dwarf2_per_bfd or dwz_file object. */
5873 template <typename T
>
5874 static gdb::array_view
<const gdb_byte
>
5875 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5877 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5879 if (section
->empty ())
5882 /* Older elfutils strip versions could keep the section in the main
5883 executable while splitting it for the separate debug info file. */
5884 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5887 section
->read (obj
);
5889 /* dwarf2_section_info::size is a bfd_size_type, while
5890 gdb::array_view works with size_t. On 32-bit hosts, with
5891 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5892 is 32-bit. So we need an explicit narrowing conversion here.
5893 This is fine, because it's impossible to allocate or mmap an
5894 array/buffer larger than what size_t can represent. */
5895 return gdb::make_array_view (section
->buffer
, section
->size
);
5898 /* Lookup the index cache for the contents of the index associated to
5901 static gdb::array_view
<const gdb_byte
>
5902 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5904 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5905 if (build_id
== nullptr)
5908 return global_index_cache
.lookup_gdb_index (build_id
,
5909 &dwarf2_per_bfd
->index_cache_res
);
5912 /* Same as the above, but for DWZ. */
5914 static gdb::array_view
<const gdb_byte
>
5915 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5917 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5918 if (build_id
== nullptr)
5921 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5924 /* See symfile.h. */
5927 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5929 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5930 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5932 /* If we're about to read full symbols, don't bother with the
5933 indices. In this case we also don't care if some other debug
5934 format is making psymtabs, because they are all about to be
5936 if ((objfile
->flags
& OBJF_READNOW
))
5938 /* When using READNOW, the using_index flag (set below) indicates that
5939 PER_BFD was already initialized, when we loaded some other objfile. */
5940 if (per_bfd
->using_index
)
5942 *index_kind
= dw_index_kind::GDB_INDEX
;
5943 per_objfile
->resize_symtabs ();
5947 per_bfd
->using_index
= 1;
5948 create_all_comp_units (per_objfile
);
5949 create_all_type_units (per_objfile
);
5950 per_bfd
->quick_file_names_table
5951 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5952 per_objfile
->resize_symtabs ();
5954 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
5955 + per_bfd
->all_type_units
.size ()); ++i
)
5957 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
5959 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5960 struct dwarf2_per_cu_quick_data
);
5963 /* Return 1 so that gdb sees the "quick" functions. However,
5964 these functions will be no-ops because we will have expanded
5966 *index_kind
= dw_index_kind::GDB_INDEX
;
5970 /* Was a debug names index already read when we processed an objfile sharing
5972 if (per_bfd
->debug_names_table
!= nullptr)
5974 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5975 per_objfile
->resize_symtabs ();
5979 /* Was a GDB index already read when we processed an objfile sharing
5981 if (per_bfd
->index_table
!= nullptr)
5983 *index_kind
= dw_index_kind::GDB_INDEX
;
5984 per_objfile
->resize_symtabs ();
5988 if (dwarf2_read_debug_names (per_objfile
))
5990 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5991 per_objfile
->resize_symtabs ();
5995 if (dwarf2_read_gdb_index (per_objfile
,
5996 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5997 get_gdb_index_contents_from_section
<dwz_file
>))
5999 *index_kind
= dw_index_kind::GDB_INDEX
;
6000 per_objfile
->resize_symtabs ();
6004 /* ... otherwise, try to find the index in the index cache. */
6005 if (dwarf2_read_gdb_index (per_objfile
,
6006 get_gdb_index_contents_from_cache
,
6007 get_gdb_index_contents_from_cache_dwz
))
6009 global_index_cache
.hit ();
6010 *index_kind
= dw_index_kind::GDB_INDEX
;
6011 per_objfile
->resize_symtabs ();
6015 global_index_cache
.miss ();
6021 /* Build a partial symbol table. */
6024 dwarf2_build_psymtabs (struct objfile
*objfile
)
6026 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6027 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6029 if (per_bfd
->partial_symtabs
!= nullptr)
6031 /* Partial symbols were already read, so now we can simply
6033 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6034 per_objfile
->resize_symtabs ();
6038 init_psymbol_list (objfile
, 1024);
6042 /* This isn't really ideal: all the data we allocate on the
6043 objfile's obstack is still uselessly kept around. However,
6044 freeing it seems unsafe. */
6045 psymtab_discarder
psymtabs (objfile
);
6046 dwarf2_build_psymtabs_hard (per_objfile
);
6049 per_objfile
->resize_symtabs ();
6051 /* (maybe) store an index in the cache. */
6052 global_index_cache
.store (per_objfile
);
6054 catch (const gdb_exception_error
&except
)
6056 exception_print (gdb_stderr
, except
);
6059 /* Finish by setting the local reference to partial symtabs, so that
6060 we don't try to read them again if reading another objfile with the same
6061 BFD. If we can't in fact share, this won't make a difference anyway as
6062 the dwarf2_per_bfd object won't be shared. */
6063 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6066 /* Find the base address of the compilation unit for range lists and
6067 location lists. It will normally be specified by DW_AT_low_pc.
6068 In DWARF-3 draft 4, the base address could be overridden by
6069 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6070 compilation units with discontinuous ranges. */
6073 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6075 struct attribute
*attr
;
6077 cu
->base_address
.reset ();
6079 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6080 if (attr
!= nullptr)
6081 cu
->base_address
= attr
->value_as_address ();
6084 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6085 if (attr
!= nullptr)
6086 cu
->base_address
= attr
->value_as_address ();
6090 /* Helper function that returns the proper abbrev section for
6093 static struct dwarf2_section_info
*
6094 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6096 struct dwarf2_section_info
*abbrev
;
6097 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6099 if (this_cu
->is_dwz
)
6100 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6102 abbrev
= &per_bfd
->abbrev
;
6107 /* Fetch the abbreviation table offset from a comp or type unit header. */
6110 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6111 struct dwarf2_section_info
*section
,
6112 sect_offset sect_off
)
6114 bfd
*abfd
= section
->get_bfd_owner ();
6115 const gdb_byte
*info_ptr
;
6116 unsigned int initial_length_size
, offset_size
;
6119 section
->read (per_objfile
->objfile
);
6120 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6121 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6122 offset_size
= initial_length_size
== 4 ? 4 : 8;
6123 info_ptr
+= initial_length_size
;
6125 version
= read_2_bytes (abfd
, info_ptr
);
6129 /* Skip unit type and address size. */
6133 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6136 /* A partial symtab that is used only for include files. */
6137 struct dwarf2_include_psymtab
: public partial_symtab
6139 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6140 : partial_symtab (filename
, objfile
)
6144 void read_symtab (struct objfile
*objfile
) override
6146 /* It's an include file, no symbols to read for it.
6147 Everything is in the includer symtab. */
6149 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6150 expansion of the includer psymtab. We use the dependencies[0] field to
6151 model the includer. But if we go the regular route of calling
6152 expand_psymtab here, and having expand_psymtab call expand_dependencies
6153 to expand the includer, we'll only use expand_psymtab on the includer
6154 (making it a non-toplevel psymtab), while if we expand the includer via
6155 another path, we'll use read_symtab (making it a toplevel psymtab).
6156 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6157 psymtab, and trigger read_symtab on the includer here directly. */
6158 includer ()->read_symtab (objfile
);
6161 void expand_psymtab (struct objfile
*objfile
) override
6163 /* This is not called by read_symtab, and should not be called by any
6164 expand_dependencies. */
6168 bool readin_p (struct objfile
*objfile
) const override
6170 return includer ()->readin_p (objfile
);
6173 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6179 partial_symtab
*includer () const
6181 /* An include psymtab has exactly one dependency: the psymtab that
6183 gdb_assert (this->number_of_dependencies
== 1);
6184 return this->dependencies
[0];
6188 /* Allocate a new partial symtab for file named NAME and mark this new
6189 partial symtab as being an include of PST. */
6192 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6193 struct objfile
*objfile
)
6195 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6197 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6198 subpst
->dirname
= pst
->dirname
;
6200 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6201 subpst
->dependencies
[0] = pst
;
6202 subpst
->number_of_dependencies
= 1;
6205 /* Read the Line Number Program data and extract the list of files
6206 included by the source file represented by PST. Build an include
6207 partial symtab for each of these included files. */
6210 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6211 struct die_info
*die
,
6212 dwarf2_psymtab
*pst
)
6215 struct attribute
*attr
;
6217 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6218 if (attr
!= nullptr)
6219 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6221 return; /* No linetable, so no includes. */
6223 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6224 that we pass in the raw text_low here; that is ok because we're
6225 only decoding the line table to make include partial symtabs, and
6226 so the addresses aren't really used. */
6227 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6228 pst
->raw_text_low (), 1);
6232 hash_signatured_type (const void *item
)
6234 const struct signatured_type
*sig_type
6235 = (const struct signatured_type
*) item
;
6237 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6238 return sig_type
->signature
;
6242 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6244 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6245 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6247 return lhs
->signature
== rhs
->signature
;
6250 /* Allocate a hash table for signatured types. */
6253 allocate_signatured_type_table ()
6255 return htab_up (htab_create_alloc (41,
6256 hash_signatured_type
,
6258 NULL
, xcalloc
, xfree
));
6261 /* A helper function to add a signatured type CU to a table. */
6264 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6266 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6267 std::vector
<signatured_type
*> *all_type_units
6268 = (std::vector
<signatured_type
*> *) datum
;
6270 all_type_units
->push_back (sigt
);
6275 /* A helper for create_debug_types_hash_table. Read types from SECTION
6276 and fill them into TYPES_HTAB. It will process only type units,
6277 therefore DW_UT_type. */
6280 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6281 struct dwo_file
*dwo_file
,
6282 dwarf2_section_info
*section
, htab_up
&types_htab
,
6283 rcuh_kind section_kind
)
6285 struct objfile
*objfile
= per_objfile
->objfile
;
6286 struct dwarf2_section_info
*abbrev_section
;
6288 const gdb_byte
*info_ptr
, *end_ptr
;
6290 abbrev_section
= (dwo_file
!= NULL
6291 ? &dwo_file
->sections
.abbrev
6292 : &per_objfile
->per_bfd
->abbrev
);
6294 if (dwarf_read_debug
)
6295 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6296 section
->get_name (),
6297 abbrev_section
->get_file_name ());
6299 section
->read (objfile
);
6300 info_ptr
= section
->buffer
;
6302 if (info_ptr
== NULL
)
6305 /* We can't set abfd until now because the section may be empty or
6306 not present, in which case the bfd is unknown. */
6307 abfd
= section
->get_bfd_owner ();
6309 /* We don't use cutu_reader here because we don't need to read
6310 any dies: the signature is in the header. */
6312 end_ptr
= info_ptr
+ section
->size
;
6313 while (info_ptr
< end_ptr
)
6315 struct signatured_type
*sig_type
;
6316 struct dwo_unit
*dwo_tu
;
6318 const gdb_byte
*ptr
= info_ptr
;
6319 struct comp_unit_head header
;
6320 unsigned int length
;
6322 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6324 /* Initialize it due to a false compiler warning. */
6325 header
.signature
= -1;
6326 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6328 /* We need to read the type's signature in order to build the hash
6329 table, but we don't need anything else just yet. */
6331 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6332 abbrev_section
, ptr
, section_kind
);
6334 length
= header
.get_length ();
6336 /* Skip dummy type units. */
6337 if (ptr
>= info_ptr
+ length
6338 || peek_abbrev_code (abfd
, ptr
) == 0
6339 || header
.unit_type
!= DW_UT_type
)
6345 if (types_htab
== NULL
)
6348 types_htab
= allocate_dwo_unit_table ();
6350 types_htab
= allocate_signatured_type_table ();
6356 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6357 dwo_tu
->dwo_file
= dwo_file
;
6358 dwo_tu
->signature
= header
.signature
;
6359 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6360 dwo_tu
->section
= section
;
6361 dwo_tu
->sect_off
= sect_off
;
6362 dwo_tu
->length
= length
;
6366 /* N.B.: type_offset is not usable if this type uses a DWO file.
6367 The real type_offset is in the DWO file. */
6369 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6370 sig_type
->signature
= header
.signature
;
6371 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6372 sig_type
->per_cu
.is_debug_types
= 1;
6373 sig_type
->per_cu
.section
= section
;
6374 sig_type
->per_cu
.sect_off
= sect_off
;
6375 sig_type
->per_cu
.length
= length
;
6378 slot
= htab_find_slot (types_htab
.get (),
6379 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6381 gdb_assert (slot
!= NULL
);
6384 sect_offset dup_sect_off
;
6388 const struct dwo_unit
*dup_tu
6389 = (const struct dwo_unit
*) *slot
;
6391 dup_sect_off
= dup_tu
->sect_off
;
6395 const struct signatured_type
*dup_tu
6396 = (const struct signatured_type
*) *slot
;
6398 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6401 complaint (_("debug type entry at offset %s is duplicate to"
6402 " the entry at offset %s, signature %s"),
6403 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6404 hex_string (header
.signature
));
6406 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6408 if (dwarf_read_debug
> 1)
6409 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6410 sect_offset_str (sect_off
),
6411 hex_string (header
.signature
));
6417 /* Create the hash table of all entries in the .debug_types
6418 (or .debug_types.dwo) section(s).
6419 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6420 otherwise it is NULL.
6422 The result is a pointer to the hash table or NULL if there are no types.
6424 Note: This function processes DWO files only, not DWP files. */
6427 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6428 struct dwo_file
*dwo_file
,
6429 gdb::array_view
<dwarf2_section_info
> type_sections
,
6430 htab_up
&types_htab
)
6432 for (dwarf2_section_info
§ion
: type_sections
)
6433 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6437 /* Create the hash table of all entries in the .debug_types section,
6438 and initialize all_type_units.
6439 The result is zero if there is an error (e.g. missing .debug_types section),
6440 otherwise non-zero. */
6443 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6447 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6448 types_htab
, rcuh_kind::COMPILE
);
6449 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6451 if (types_htab
== NULL
)
6453 per_objfile
->per_bfd
->signatured_types
= NULL
;
6457 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6459 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6460 per_objfile
->per_bfd
->all_type_units
.reserve
6461 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6463 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6464 add_signatured_type_cu_to_table
,
6465 &per_objfile
->per_bfd
->all_type_units
);
6470 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6471 If SLOT is non-NULL, it is the entry to use in the hash table.
6472 Otherwise we find one. */
6474 static struct signatured_type
*
6475 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6477 if (per_objfile
->per_bfd
->all_type_units
.size ()
6478 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6479 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6481 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6483 per_objfile
->resize_symtabs ();
6485 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6486 sig_type
->signature
= sig
;
6487 sig_type
->per_cu
.is_debug_types
= 1;
6488 if (per_objfile
->per_bfd
->using_index
)
6490 sig_type
->per_cu
.v
.quick
=
6491 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6492 struct dwarf2_per_cu_quick_data
);
6497 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6500 gdb_assert (*slot
== NULL
);
6502 /* The rest of sig_type must be filled in by the caller. */
6506 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6507 Fill in SIG_ENTRY with DWO_ENTRY. */
6510 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6511 struct signatured_type
*sig_entry
,
6512 struct dwo_unit
*dwo_entry
)
6514 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6516 /* Make sure we're not clobbering something we don't expect to. */
6517 gdb_assert (! sig_entry
->per_cu
.queued
);
6518 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6519 if (per_bfd
->using_index
)
6521 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6522 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6525 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6526 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6527 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6528 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6529 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6531 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6532 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6533 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6534 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6535 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6536 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6537 sig_entry
->dwo_unit
= dwo_entry
;
6540 /* Subroutine of lookup_signatured_type.
6541 If we haven't read the TU yet, create the signatured_type data structure
6542 for a TU to be read in directly from a DWO file, bypassing the stub.
6543 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6544 using .gdb_index, then when reading a CU we want to stay in the DWO file
6545 containing that CU. Otherwise we could end up reading several other DWO
6546 files (due to comdat folding) to process the transitive closure of all the
6547 mentioned TUs, and that can be slow. The current DWO file will have every
6548 type signature that it needs.
6549 We only do this for .gdb_index because in the psymtab case we already have
6550 to read all the DWOs to build the type unit groups. */
6552 static struct signatured_type
*
6553 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6555 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6556 struct dwo_file
*dwo_file
;
6557 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6558 struct signatured_type find_sig_entry
, *sig_entry
;
6561 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6563 /* If TU skeletons have been removed then we may not have read in any
6565 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6566 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6568 /* We only ever need to read in one copy of a signatured type.
6569 Use the global signatured_types array to do our own comdat-folding
6570 of types. If this is the first time we're reading this TU, and
6571 the TU has an entry in .gdb_index, replace the recorded data from
6572 .gdb_index with this TU. */
6574 find_sig_entry
.signature
= sig
;
6575 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6576 &find_sig_entry
, INSERT
);
6577 sig_entry
= (struct signatured_type
*) *slot
;
6579 /* We can get here with the TU already read, *or* in the process of being
6580 read. Don't reassign the global entry to point to this DWO if that's
6581 the case. Also note that if the TU is already being read, it may not
6582 have come from a DWO, the program may be a mix of Fission-compiled
6583 code and non-Fission-compiled code. */
6585 /* Have we already tried to read this TU?
6586 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6587 needn't exist in the global table yet). */
6588 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6591 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6592 dwo_unit of the TU itself. */
6593 dwo_file
= cu
->dwo_unit
->dwo_file
;
6595 /* Ok, this is the first time we're reading this TU. */
6596 if (dwo_file
->tus
== NULL
)
6598 find_dwo_entry
.signature
= sig
;
6599 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6601 if (dwo_entry
== NULL
)
6604 /* If the global table doesn't have an entry for this TU, add one. */
6605 if (sig_entry
== NULL
)
6606 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6608 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6609 sig_entry
->per_cu
.tu_read
= 1;
6613 /* Subroutine of lookup_signatured_type.
6614 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6615 then try the DWP file. If the TU stub (skeleton) has been removed then
6616 it won't be in .gdb_index. */
6618 static struct signatured_type
*
6619 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6621 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6622 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6623 struct dwo_unit
*dwo_entry
;
6624 struct signatured_type find_sig_entry
, *sig_entry
;
6627 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6628 gdb_assert (dwp_file
!= NULL
);
6630 /* If TU skeletons have been removed then we may not have read in any
6632 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6633 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6635 find_sig_entry
.signature
= sig
;
6636 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6637 &find_sig_entry
, INSERT
);
6638 sig_entry
= (struct signatured_type
*) *slot
;
6640 /* Have we already tried to read this TU?
6641 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6642 needn't exist in the global table yet). */
6643 if (sig_entry
!= NULL
)
6646 if (dwp_file
->tus
== NULL
)
6648 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6649 1 /* is_debug_types */);
6650 if (dwo_entry
== NULL
)
6653 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6654 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6659 /* Lookup a signature based type for DW_FORM_ref_sig8.
6660 Returns NULL if signature SIG is not present in the table.
6661 It is up to the caller to complain about this. */
6663 static struct signatured_type
*
6664 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6666 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6668 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6670 /* We're in a DWO/DWP file, and we're using .gdb_index.
6671 These cases require special processing. */
6672 if (get_dwp_file (per_objfile
) == NULL
)
6673 return lookup_dwo_signatured_type (cu
, sig
);
6675 return lookup_dwp_signatured_type (cu
, sig
);
6679 struct signatured_type find_entry
, *entry
;
6681 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6683 find_entry
.signature
= sig
;
6684 entry
= ((struct signatured_type
*)
6685 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6691 /* Low level DIE reading support. */
6693 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6696 init_cu_die_reader (struct die_reader_specs
*reader
,
6697 struct dwarf2_cu
*cu
,
6698 struct dwarf2_section_info
*section
,
6699 struct dwo_file
*dwo_file
,
6700 struct abbrev_table
*abbrev_table
)
6702 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6703 reader
->abfd
= section
->get_bfd_owner ();
6705 reader
->dwo_file
= dwo_file
;
6706 reader
->die_section
= section
;
6707 reader
->buffer
= section
->buffer
;
6708 reader
->buffer_end
= section
->buffer
+ section
->size
;
6709 reader
->abbrev_table
= abbrev_table
;
6712 /* Subroutine of cutu_reader to simplify it.
6713 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6714 There's just a lot of work to do, and cutu_reader is big enough
6717 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6718 from it to the DIE in the DWO. If NULL we are skipping the stub.
6719 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6720 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6721 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6722 STUB_COMP_DIR may be non-NULL.
6723 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6724 are filled in with the info of the DIE from the DWO file.
6725 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6726 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6727 kept around for at least as long as *RESULT_READER.
6729 The result is non-zero if a valid (non-dummy) DIE was found. */
6732 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6733 struct dwo_unit
*dwo_unit
,
6734 struct die_info
*stub_comp_unit_die
,
6735 const char *stub_comp_dir
,
6736 struct die_reader_specs
*result_reader
,
6737 const gdb_byte
**result_info_ptr
,
6738 struct die_info
**result_comp_unit_die
,
6739 abbrev_table_up
*result_dwo_abbrev_table
)
6741 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6742 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6743 struct objfile
*objfile
= per_objfile
->objfile
;
6745 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6746 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6747 int i
,num_extra_attrs
;
6748 struct dwarf2_section_info
*dwo_abbrev_section
;
6749 struct die_info
*comp_unit_die
;
6751 /* At most one of these may be provided. */
6752 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6754 /* These attributes aren't processed until later:
6755 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6756 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6757 referenced later. However, these attributes are found in the stub
6758 which we won't have later. In order to not impose this complication
6759 on the rest of the code, we read them here and copy them to the
6768 if (stub_comp_unit_die
!= NULL
)
6770 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6772 if (!per_cu
->is_debug_types
)
6773 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6774 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6775 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6776 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6777 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6779 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6781 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6782 here (if needed). We need the value before we can process
6784 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6786 else if (stub_comp_dir
!= NULL
)
6788 /* Reconstruct the comp_dir attribute to simplify the code below. */
6789 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6790 comp_dir
->name
= DW_AT_comp_dir
;
6791 comp_dir
->form
= DW_FORM_string
;
6792 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6793 DW_STRING (comp_dir
) = stub_comp_dir
;
6796 /* Set up for reading the DWO CU/TU. */
6797 cu
->dwo_unit
= dwo_unit
;
6798 dwarf2_section_info
*section
= dwo_unit
->section
;
6799 section
->read (objfile
);
6800 abfd
= section
->get_bfd_owner ();
6801 begin_info_ptr
= info_ptr
= (section
->buffer
6802 + to_underlying (dwo_unit
->sect_off
));
6803 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6805 if (per_cu
->is_debug_types
)
6807 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6809 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6810 section
, dwo_abbrev_section
,
6811 info_ptr
, rcuh_kind::TYPE
);
6812 /* This is not an assert because it can be caused by bad debug info. */
6813 if (sig_type
->signature
!= cu
->header
.signature
)
6815 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6816 " TU at offset %s [in module %s]"),
6817 hex_string (sig_type
->signature
),
6818 hex_string (cu
->header
.signature
),
6819 sect_offset_str (dwo_unit
->sect_off
),
6820 bfd_get_filename (abfd
));
6822 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6823 /* For DWOs coming from DWP files, we don't know the CU length
6824 nor the type's offset in the TU until now. */
6825 dwo_unit
->length
= cu
->header
.get_length ();
6826 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6828 /* Establish the type offset that can be used to lookup the type.
6829 For DWO files, we don't know it until now. */
6830 sig_type
->type_offset_in_section
6831 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6835 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6836 section
, dwo_abbrev_section
,
6837 info_ptr
, rcuh_kind::COMPILE
);
6838 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6839 /* For DWOs coming from DWP files, we don't know the CU length
6841 dwo_unit
->length
= cu
->header
.get_length ();
6844 *result_dwo_abbrev_table
6845 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6846 cu
->header
.abbrev_sect_off
);
6847 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6848 result_dwo_abbrev_table
->get ());
6850 /* Read in the die, but leave space to copy over the attributes
6851 from the stub. This has the benefit of simplifying the rest of
6852 the code - all the work to maintain the illusion of a single
6853 DW_TAG_{compile,type}_unit DIE is done here. */
6854 num_extra_attrs
= ((stmt_list
!= NULL
)
6858 + (comp_dir
!= NULL
));
6859 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6862 /* Copy over the attributes from the stub to the DIE we just read in. */
6863 comp_unit_die
= *result_comp_unit_die
;
6864 i
= comp_unit_die
->num_attrs
;
6865 if (stmt_list
!= NULL
)
6866 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6868 comp_unit_die
->attrs
[i
++] = *low_pc
;
6869 if (high_pc
!= NULL
)
6870 comp_unit_die
->attrs
[i
++] = *high_pc
;
6872 comp_unit_die
->attrs
[i
++] = *ranges
;
6873 if (comp_dir
!= NULL
)
6874 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6875 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6877 if (dwarf_die_debug
)
6879 fprintf_unfiltered (gdb_stdlog
,
6880 "Read die from %s@0x%x of %s:\n",
6881 section
->get_name (),
6882 (unsigned) (begin_info_ptr
- section
->buffer
),
6883 bfd_get_filename (abfd
));
6884 dump_die (comp_unit_die
, dwarf_die_debug
);
6887 /* Skip dummy compilation units. */
6888 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6889 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6892 *result_info_ptr
= info_ptr
;
6896 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6897 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6898 signature is part of the header. */
6899 static gdb::optional
<ULONGEST
>
6900 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6902 if (cu
->header
.version
>= 5)
6903 return cu
->header
.signature
;
6904 struct attribute
*attr
;
6905 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6906 if (attr
== nullptr)
6907 return gdb::optional
<ULONGEST
> ();
6908 return DW_UNSND (attr
);
6911 /* Subroutine of cutu_reader to simplify it.
6912 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6913 Returns NULL if the specified DWO unit cannot be found. */
6915 static struct dwo_unit
*
6916 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6918 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6919 struct dwo_unit
*dwo_unit
;
6920 const char *comp_dir
;
6922 gdb_assert (cu
!= NULL
);
6924 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6925 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6926 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6928 if (per_cu
->is_debug_types
)
6929 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6932 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6934 if (!signature
.has_value ())
6935 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6937 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6939 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6945 /* Subroutine of cutu_reader to simplify it.
6946 See it for a description of the parameters.
6947 Read a TU directly from a DWO file, bypassing the stub. */
6950 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6951 dwarf2_per_objfile
*per_objfile
,
6952 dwarf2_cu
*existing_cu
)
6954 struct signatured_type
*sig_type
;
6956 /* Verify we can do the following downcast, and that we have the
6958 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6959 sig_type
= (struct signatured_type
*) this_cu
;
6960 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6964 if (existing_cu
!= nullptr)
6967 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6968 /* There's no need to do the rereading_dwo_cu handling that
6969 cutu_reader does since we don't read the stub. */
6973 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6974 in per_objfile yet. */
6975 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6976 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6977 cu
= m_new_cu
.get ();
6980 /* A future optimization, if needed, would be to use an existing
6981 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6982 could share abbrev tables. */
6984 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6985 NULL
/* stub_comp_unit_die */,
6986 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6989 &m_dwo_abbrev_table
) == 0)
6996 /* Initialize a CU (or TU) and read its DIEs.
6997 If the CU defers to a DWO file, read the DWO file as well.
6999 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7000 Otherwise the table specified in the comp unit header is read in and used.
7001 This is an optimization for when we already have the abbrev table.
7003 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7006 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7007 dwarf2_per_objfile
*per_objfile
,
7008 struct abbrev_table
*abbrev_table
,
7009 dwarf2_cu
*existing_cu
,
7011 : die_reader_specs
{},
7014 struct objfile
*objfile
= per_objfile
->objfile
;
7015 struct dwarf2_section_info
*section
= this_cu
->section
;
7016 bfd
*abfd
= section
->get_bfd_owner ();
7017 const gdb_byte
*begin_info_ptr
;
7018 struct signatured_type
*sig_type
= NULL
;
7019 struct dwarf2_section_info
*abbrev_section
;
7020 /* Non-zero if CU currently points to a DWO file and we need to
7021 reread it. When this happens we need to reread the skeleton die
7022 before we can reread the DWO file (this only applies to CUs, not TUs). */
7023 int rereading_dwo_cu
= 0;
7025 if (dwarf_die_debug
)
7026 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7027 this_cu
->is_debug_types
? "type" : "comp",
7028 sect_offset_str (this_cu
->sect_off
));
7030 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7031 file (instead of going through the stub), short-circuit all of this. */
7032 if (this_cu
->reading_dwo_directly
)
7034 /* Narrow down the scope of possibilities to have to understand. */
7035 gdb_assert (this_cu
->is_debug_types
);
7036 gdb_assert (abbrev_table
== NULL
);
7037 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7041 /* This is cheap if the section is already read in. */
7042 section
->read (objfile
);
7044 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7046 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7050 if (existing_cu
!= nullptr)
7053 /* If this CU is from a DWO file we need to start over, we need to
7054 refetch the attributes from the skeleton CU.
7055 This could be optimized by retrieving those attributes from when we
7056 were here the first time: the previous comp_unit_die was stored in
7057 comp_unit_obstack. But there's no data yet that we need this
7059 if (cu
->dwo_unit
!= NULL
)
7060 rereading_dwo_cu
= 1;
7064 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7065 in per_objfile yet. */
7066 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7067 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7068 cu
= m_new_cu
.get ();
7071 /* Get the header. */
7072 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7074 /* We already have the header, there's no need to read it in again. */
7075 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7079 if (this_cu
->is_debug_types
)
7081 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7082 section
, abbrev_section
,
7083 info_ptr
, rcuh_kind::TYPE
);
7085 /* Since per_cu is the first member of struct signatured_type,
7086 we can go from a pointer to one to a pointer to the other. */
7087 sig_type
= (struct signatured_type
*) this_cu
;
7088 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7089 gdb_assert (sig_type
->type_offset_in_tu
7090 == cu
->header
.type_cu_offset_in_tu
);
7091 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7093 /* LENGTH has not been set yet for type units if we're
7094 using .gdb_index. */
7095 this_cu
->length
= cu
->header
.get_length ();
7097 /* Establish the type offset that can be used to lookup the type. */
7098 sig_type
->type_offset_in_section
=
7099 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7101 this_cu
->dwarf_version
= cu
->header
.version
;
7105 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7106 section
, abbrev_section
,
7108 rcuh_kind::COMPILE
);
7110 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7111 if (this_cu
->length
== 0)
7112 this_cu
->length
= cu
->header
.get_length ();
7114 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7115 this_cu
->dwarf_version
= cu
->header
.version
;
7119 /* Skip dummy compilation units. */
7120 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7121 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7127 /* If we don't have them yet, read the abbrevs for this compilation unit.
7128 And if we need to read them now, make sure they're freed when we're
7130 if (abbrev_table
!= NULL
)
7131 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7134 m_abbrev_table_holder
7135 = abbrev_table::read (objfile
, abbrev_section
,
7136 cu
->header
.abbrev_sect_off
);
7137 abbrev_table
= m_abbrev_table_holder
.get ();
7140 /* Read the top level CU/TU die. */
7141 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7142 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7144 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7150 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7151 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7152 table from the DWO file and pass the ownership over to us. It will be
7153 referenced from READER, so we must make sure to free it after we're done
7156 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7157 DWO CU, that this test will fail (the attribute will not be present). */
7158 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7159 if (dwo_name
!= nullptr)
7161 struct dwo_unit
*dwo_unit
;
7162 struct die_info
*dwo_comp_unit_die
;
7164 if (comp_unit_die
->has_children
)
7166 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7167 " has children (offset %s) [in module %s]"),
7168 sect_offset_str (this_cu
->sect_off
),
7169 bfd_get_filename (abfd
));
7171 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7172 if (dwo_unit
!= NULL
)
7174 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7175 comp_unit_die
, NULL
,
7178 &m_dwo_abbrev_table
) == 0)
7184 comp_unit_die
= dwo_comp_unit_die
;
7188 /* Yikes, we couldn't find the rest of the DIE, we only have
7189 the stub. A complaint has already been logged. There's
7190 not much more we can do except pass on the stub DIE to
7191 die_reader_func. We don't want to throw an error on bad
7198 cutu_reader::keep ()
7200 /* Done, clean up. */
7201 gdb_assert (!dummy_p
);
7202 if (m_new_cu
!= NULL
)
7204 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7206 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7207 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7211 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7212 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7213 assumed to have already done the lookup to find the DWO file).
7215 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7216 THIS_CU->is_debug_types, but nothing else.
7218 We fill in THIS_CU->length.
7220 THIS_CU->cu is always freed when done.
7221 This is done in order to not leave THIS_CU->cu in a state where we have
7222 to care whether it refers to the "main" CU or the DWO CU.
7224 When parent_cu is passed, it is used to provide a default value for
7225 str_offsets_base and addr_base from the parent. */
7227 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7228 dwarf2_per_objfile
*per_objfile
,
7229 struct dwarf2_cu
*parent_cu
,
7230 struct dwo_file
*dwo_file
)
7231 : die_reader_specs
{},
7234 struct objfile
*objfile
= per_objfile
->objfile
;
7235 struct dwarf2_section_info
*section
= this_cu
->section
;
7236 bfd
*abfd
= section
->get_bfd_owner ();
7237 struct dwarf2_section_info
*abbrev_section
;
7238 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7240 if (dwarf_die_debug
)
7241 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7242 this_cu
->is_debug_types
? "type" : "comp",
7243 sect_offset_str (this_cu
->sect_off
));
7245 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7247 abbrev_section
= (dwo_file
!= NULL
7248 ? &dwo_file
->sections
.abbrev
7249 : get_abbrev_section_for_cu (this_cu
));
7251 /* This is cheap if the section is already read in. */
7252 section
->read (objfile
);
7254 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7256 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7257 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7258 section
, abbrev_section
, info_ptr
,
7259 (this_cu
->is_debug_types
7261 : rcuh_kind::COMPILE
));
7263 if (parent_cu
!= nullptr)
7265 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7266 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7268 this_cu
->length
= m_new_cu
->header
.get_length ();
7270 /* Skip dummy compilation units. */
7271 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7272 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7278 m_abbrev_table_holder
7279 = abbrev_table::read (objfile
, abbrev_section
,
7280 m_new_cu
->header
.abbrev_sect_off
);
7282 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7283 m_abbrev_table_holder
.get ());
7284 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7288 /* Type Unit Groups.
7290 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7291 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7292 so that all types coming from the same compilation (.o file) are grouped
7293 together. A future step could be to put the types in the same symtab as
7294 the CU the types ultimately came from. */
7297 hash_type_unit_group (const void *item
)
7299 const struct type_unit_group
*tu_group
7300 = (const struct type_unit_group
*) item
;
7302 return hash_stmt_list_entry (&tu_group
->hash
);
7306 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7308 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7309 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7311 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7314 /* Allocate a hash table for type unit groups. */
7317 allocate_type_unit_groups_table ()
7319 return htab_up (htab_create_alloc (3,
7320 hash_type_unit_group
,
7322 NULL
, xcalloc
, xfree
));
7325 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7326 partial symtabs. We combine several TUs per psymtab to not let the size
7327 of any one psymtab grow too big. */
7328 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7329 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7331 /* Helper routine for get_type_unit_group.
7332 Create the type_unit_group object used to hold one or more TUs. */
7334 static struct type_unit_group
*
7335 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7337 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7338 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7339 struct dwarf2_per_cu_data
*per_cu
;
7340 struct type_unit_group
*tu_group
;
7342 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7343 per_cu
= &tu_group
->per_cu
;
7344 per_cu
->per_bfd
= per_bfd
;
7346 if (per_bfd
->using_index
)
7348 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7349 struct dwarf2_per_cu_quick_data
);
7353 unsigned int line_offset
= to_underlying (line_offset_struct
);
7354 dwarf2_psymtab
*pst
;
7357 /* Give the symtab a useful name for debug purposes. */
7358 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7359 name
= string_printf ("<type_units_%d>",
7360 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7362 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7364 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7365 pst
->anonymous
= true;
7368 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7369 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7374 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7375 STMT_LIST is a DW_AT_stmt_list attribute. */
7377 static struct type_unit_group
*
7378 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7380 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7381 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7382 struct type_unit_group
*tu_group
;
7384 unsigned int line_offset
;
7385 struct type_unit_group type_unit_group_for_lookup
;
7387 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7388 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7390 /* Do we need to create a new group, or can we use an existing one? */
7394 line_offset
= DW_UNSND (stmt_list
);
7395 ++tu_stats
->nr_symtab_sharers
;
7399 /* Ugh, no stmt_list. Rare, but we have to handle it.
7400 We can do various things here like create one group per TU or
7401 spread them over multiple groups to split up the expansion work.
7402 To avoid worst case scenarios (too many groups or too large groups)
7403 we, umm, group them in bunches. */
7404 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7405 | (tu_stats
->nr_stmt_less_type_units
7406 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7407 ++tu_stats
->nr_stmt_less_type_units
;
7410 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7411 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7412 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7413 &type_unit_group_for_lookup
, INSERT
);
7416 tu_group
= (struct type_unit_group
*) *slot
;
7417 gdb_assert (tu_group
!= NULL
);
7421 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7422 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7424 ++tu_stats
->nr_symtabs
;
7430 /* Partial symbol tables. */
7432 /* Create a psymtab named NAME and assign it to PER_CU.
7434 The caller must fill in the following details:
7435 dirname, textlow, texthigh. */
7437 static dwarf2_psymtab
*
7438 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7439 dwarf2_per_objfile
*per_objfile
,
7442 struct objfile
*objfile
= per_objfile
->objfile
;
7443 dwarf2_psymtab
*pst
;
7445 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7447 pst
->psymtabs_addrmap_supported
= true;
7449 /* This is the glue that links PST into GDB's symbol API. */
7450 per_cu
->v
.psymtab
= pst
;
7455 /* DIE reader function for process_psymtab_comp_unit. */
7458 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7459 const gdb_byte
*info_ptr
,
7460 struct die_info
*comp_unit_die
,
7461 enum language pretend_language
)
7463 struct dwarf2_cu
*cu
= reader
->cu
;
7464 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7465 struct objfile
*objfile
= per_objfile
->objfile
;
7466 struct gdbarch
*gdbarch
= objfile
->arch ();
7467 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7469 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7470 dwarf2_psymtab
*pst
;
7471 enum pc_bounds_kind cu_bounds_kind
;
7472 const char *filename
;
7474 gdb_assert (! per_cu
->is_debug_types
);
7476 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7478 /* Allocate a new partial symbol table structure. */
7479 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7480 static const char artificial
[] = "<artificial>";
7481 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7482 if (filename
== NULL
)
7484 else if (strcmp (filename
, artificial
) == 0)
7486 debug_filename
.reset (concat (artificial
, "@",
7487 sect_offset_str (per_cu
->sect_off
),
7489 filename
= debug_filename
.get ();
7492 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7494 /* This must be done before calling dwarf2_build_include_psymtabs. */
7495 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7497 baseaddr
= objfile
->text_section_offset ();
7499 dwarf2_find_base_address (comp_unit_die
, cu
);
7501 /* Possibly set the default values of LOWPC and HIGHPC from
7503 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7504 &best_highpc
, cu
, pst
);
7505 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7508 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7511 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7513 /* Store the contiguous range if it is not empty; it can be
7514 empty for CUs with no code. */
7515 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7519 /* Check if comp unit has_children.
7520 If so, read the rest of the partial symbols from this comp unit.
7521 If not, there's no more debug_info for this comp unit. */
7522 if (comp_unit_die
->has_children
)
7524 struct partial_die_info
*first_die
;
7525 CORE_ADDR lowpc
, highpc
;
7527 lowpc
= ((CORE_ADDR
) -1);
7528 highpc
= ((CORE_ADDR
) 0);
7530 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7532 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7533 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7535 /* If we didn't find a lowpc, set it to highpc to avoid
7536 complaints from `maint check'. */
7537 if (lowpc
== ((CORE_ADDR
) -1))
7540 /* If the compilation unit didn't have an explicit address range,
7541 then use the information extracted from its child dies. */
7542 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7545 best_highpc
= highpc
;
7548 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7549 best_lowpc
+ baseaddr
)
7551 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7552 best_highpc
+ baseaddr
)
7555 end_psymtab_common (objfile
, pst
);
7557 if (!cu
->per_cu
->imported_symtabs_empty ())
7560 int len
= cu
->per_cu
->imported_symtabs_size ();
7562 /* Fill in 'dependencies' here; we fill in 'users' in a
7564 pst
->number_of_dependencies
= len
;
7566 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7567 for (i
= 0; i
< len
; ++i
)
7569 pst
->dependencies
[i
]
7570 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7573 cu
->per_cu
->imported_symtabs_free ();
7576 /* Get the list of files included in the current compilation unit,
7577 and build a psymtab for each of them. */
7578 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7580 if (dwarf_read_debug
)
7581 fprintf_unfiltered (gdb_stdlog
,
7582 "Psymtab for %s unit @%s: %s - %s"
7583 ", %d global, %d static syms\n",
7584 per_cu
->is_debug_types
? "type" : "comp",
7585 sect_offset_str (per_cu
->sect_off
),
7586 paddress (gdbarch
, pst
->text_low (objfile
)),
7587 paddress (gdbarch
, pst
->text_high (objfile
)),
7588 pst
->n_global_syms
, pst
->n_static_syms
);
7591 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7592 Process compilation unit THIS_CU for a psymtab. */
7595 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7596 dwarf2_per_objfile
*per_objfile
,
7597 bool want_partial_unit
,
7598 enum language pretend_language
)
7600 /* If this compilation unit was already read in, free the
7601 cached copy in order to read it in again. This is
7602 necessary because we skipped some symbols when we first
7603 read in the compilation unit (see load_partial_dies).
7604 This problem could be avoided, but the benefit is unclear. */
7605 per_objfile
->remove_cu (this_cu
);
7607 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7609 switch (reader
.comp_unit_die
->tag
)
7611 case DW_TAG_compile_unit
:
7612 this_cu
->unit_type
= DW_UT_compile
;
7614 case DW_TAG_partial_unit
:
7615 this_cu
->unit_type
= DW_UT_partial
;
7625 else if (this_cu
->is_debug_types
)
7626 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7627 reader
.comp_unit_die
);
7628 else if (want_partial_unit
7629 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7630 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7631 reader
.comp_unit_die
,
7634 this_cu
->lang
= reader
.cu
->language
;
7636 /* Age out any secondary CUs. */
7637 per_objfile
->age_comp_units ();
7640 /* Reader function for build_type_psymtabs. */
7643 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7644 const gdb_byte
*info_ptr
,
7645 struct die_info
*type_unit_die
)
7647 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7648 struct objfile
*objfile
= per_objfile
->objfile
;
7649 struct dwarf2_cu
*cu
= reader
->cu
;
7650 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7651 struct signatured_type
*sig_type
;
7652 struct type_unit_group
*tu_group
;
7653 struct attribute
*attr
;
7654 struct partial_die_info
*first_die
;
7655 CORE_ADDR lowpc
, highpc
;
7656 dwarf2_psymtab
*pst
;
7658 gdb_assert (per_cu
->is_debug_types
);
7659 sig_type
= (struct signatured_type
*) per_cu
;
7661 if (! type_unit_die
->has_children
)
7664 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7665 tu_group
= get_type_unit_group (cu
, attr
);
7667 if (tu_group
->tus
== nullptr)
7668 tu_group
->tus
= new std::vector
<signatured_type
*>;
7669 tu_group
->tus
->push_back (sig_type
);
7671 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7672 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7673 pst
->anonymous
= true;
7675 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7677 lowpc
= (CORE_ADDR
) -1;
7678 highpc
= (CORE_ADDR
) 0;
7679 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7681 end_psymtab_common (objfile
, pst
);
7684 /* Struct used to sort TUs by their abbreviation table offset. */
7686 struct tu_abbrev_offset
7688 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7689 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7692 signatured_type
*sig_type
;
7693 sect_offset abbrev_offset
;
7696 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7699 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7700 const struct tu_abbrev_offset
&b
)
7702 return a
.abbrev_offset
< b
.abbrev_offset
;
7705 /* Efficiently read all the type units.
7706 This does the bulk of the work for build_type_psymtabs.
7708 The efficiency is because we sort TUs by the abbrev table they use and
7709 only read each abbrev table once. In one program there are 200K TUs
7710 sharing 8K abbrev tables.
7712 The main purpose of this function is to support building the
7713 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7714 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7715 can collapse the search space by grouping them by stmt_list.
7716 The savings can be significant, in the same program from above the 200K TUs
7717 share 8K stmt_list tables.
7719 FUNC is expected to call get_type_unit_group, which will create the
7720 struct type_unit_group if necessary and add it to
7721 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7724 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7726 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7727 abbrev_table_up abbrev_table
;
7728 sect_offset abbrev_offset
;
7730 /* It's up to the caller to not call us multiple times. */
7731 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7733 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7736 /* TUs typically share abbrev tables, and there can be way more TUs than
7737 abbrev tables. Sort by abbrev table to reduce the number of times we
7738 read each abbrev table in.
7739 Alternatives are to punt or to maintain a cache of abbrev tables.
7740 This is simpler and efficient enough for now.
7742 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7743 symtab to use). Typically TUs with the same abbrev offset have the same
7744 stmt_list value too so in practice this should work well.
7746 The basic algorithm here is:
7748 sort TUs by abbrev table
7749 for each TU with same abbrev table:
7750 read abbrev table if first user
7751 read TU top level DIE
7752 [IWBN if DWO skeletons had DW_AT_stmt_list]
7755 if (dwarf_read_debug
)
7756 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7758 /* Sort in a separate table to maintain the order of all_type_units
7759 for .gdb_index: TU indices directly index all_type_units. */
7760 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7761 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7763 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7764 sorted_by_abbrev
.emplace_back
7765 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7766 sig_type
->per_cu
.sect_off
));
7768 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7769 sort_tu_by_abbrev_offset
);
7771 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7773 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7775 /* Switch to the next abbrev table if necessary. */
7776 if (abbrev_table
== NULL
7777 || tu
.abbrev_offset
!= abbrev_offset
)
7779 abbrev_offset
= tu
.abbrev_offset
;
7781 abbrev_table::read (per_objfile
->objfile
,
7782 &per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7783 ++tu_stats
->nr_uniq_abbrev_tables
;
7786 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7787 abbrev_table
.get (), nullptr, false);
7788 if (!reader
.dummy_p
)
7789 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7790 reader
.comp_unit_die
);
7794 /* Print collected type unit statistics. */
7797 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7799 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7801 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7802 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7803 per_objfile
->per_bfd
->all_type_units
.size ());
7804 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7805 tu_stats
->nr_uniq_abbrev_tables
);
7806 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7807 tu_stats
->nr_symtabs
);
7808 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7809 tu_stats
->nr_symtab_sharers
);
7810 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7811 tu_stats
->nr_stmt_less_type_units
);
7812 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7813 tu_stats
->nr_all_type_units_reallocs
);
7816 /* Traversal function for build_type_psymtabs. */
7819 build_type_psymtab_dependencies (void **slot
, void *info
)
7821 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7822 struct objfile
*objfile
= per_objfile
->objfile
;
7823 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7824 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7825 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7826 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7829 gdb_assert (len
> 0);
7830 gdb_assert (per_cu
->type_unit_group_p ());
7832 pst
->number_of_dependencies
= len
;
7833 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7834 for (i
= 0; i
< len
; ++i
)
7836 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7837 gdb_assert (iter
->per_cu
.is_debug_types
);
7838 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7839 iter
->type_unit_group
= tu_group
;
7842 delete tu_group
->tus
;
7843 tu_group
->tus
= nullptr;
7848 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7849 Build partial symbol tables for the .debug_types comp-units. */
7852 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7854 if (! create_all_type_units (per_objfile
))
7857 build_type_psymtabs_1 (per_objfile
);
7860 /* Traversal function for process_skeletonless_type_unit.
7861 Read a TU in a DWO file and build partial symbols for it. */
7864 process_skeletonless_type_unit (void **slot
, void *info
)
7866 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7867 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7868 struct signatured_type find_entry
, *entry
;
7870 /* If this TU doesn't exist in the global table, add it and read it in. */
7872 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7873 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7875 find_entry
.signature
= dwo_unit
->signature
;
7876 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7877 &find_entry
, INSERT
);
7878 /* If we've already seen this type there's nothing to do. What's happening
7879 is we're doing our own version of comdat-folding here. */
7883 /* This does the job that create_all_type_units would have done for
7885 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7886 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7889 /* This does the job that build_type_psymtabs_1 would have done. */
7890 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7891 if (!reader
.dummy_p
)
7892 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7893 reader
.comp_unit_die
);
7898 /* Traversal function for process_skeletonless_type_units. */
7901 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7903 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7905 if (dwo_file
->tus
!= NULL
)
7906 htab_traverse_noresize (dwo_file
->tus
.get (),
7907 process_skeletonless_type_unit
, info
);
7912 /* Scan all TUs of DWO files, verifying we've processed them.
7913 This is needed in case a TU was emitted without its skeleton.
7914 Note: This can't be done until we know what all the DWO files are. */
7917 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7919 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7920 if (get_dwp_file (per_objfile
) == NULL
7921 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7923 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7924 process_dwo_file_for_skeletonless_type_units
,
7929 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7932 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7934 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7936 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7941 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7943 /* Set the 'user' field only if it is not already set. */
7944 if (pst
->dependencies
[j
]->user
== NULL
)
7945 pst
->dependencies
[j
]->user
= pst
;
7950 /* Build the partial symbol table by doing a quick pass through the
7951 .debug_info and .debug_abbrev sections. */
7954 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7956 struct objfile
*objfile
= per_objfile
->objfile
;
7958 if (dwarf_read_debug
)
7960 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7961 objfile_name (objfile
));
7964 scoped_restore restore_reading_psyms
7965 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
7968 per_objfile
->per_bfd
->info
.read (objfile
);
7970 /* Any cached compilation units will be linked by the per-objfile
7971 read_in_chain. Make sure to free them when we're done. */
7972 free_cached_comp_units
freer (per_objfile
);
7974 build_type_psymtabs (per_objfile
);
7976 create_all_comp_units (per_objfile
);
7978 /* Create a temporary address map on a temporary obstack. We later
7979 copy this to the final obstack. */
7980 auto_obstack temp_obstack
;
7982 scoped_restore save_psymtabs_addrmap
7983 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7984 addrmap_create_mutable (&temp_obstack
));
7986 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7988 if (per_cu
->v
.psymtab
!= NULL
)
7989 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7991 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
7995 /* This has to wait until we read the CUs, we need the list of DWOs. */
7996 process_skeletonless_type_units (per_objfile
);
7998 /* Now that all TUs have been processed we can fill in the dependencies. */
7999 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8001 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8002 build_type_psymtab_dependencies
, per_objfile
);
8005 if (dwarf_read_debug
)
8006 print_tu_stats (per_objfile
);
8008 set_partial_user (per_objfile
);
8010 objfile
->partial_symtabs
->psymtabs_addrmap
8011 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8012 objfile
->partial_symtabs
->obstack ());
8013 /* At this point we want to keep the address map. */
8014 save_psymtabs_addrmap
.release ();
8016 if (dwarf_read_debug
)
8017 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8018 objfile_name (objfile
));
8021 /* Load the partial DIEs for a secondary CU into memory.
8022 This is also used when rereading a primary CU with load_all_dies. */
8025 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8026 dwarf2_per_objfile
*per_objfile
,
8027 dwarf2_cu
*existing_cu
)
8029 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8031 if (!reader
.dummy_p
)
8033 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8036 /* Check if comp unit has_children.
8037 If so, read the rest of the partial symbols from this comp unit.
8038 If not, there's no more debug_info for this comp unit. */
8039 if (reader
.comp_unit_die
->has_children
)
8040 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8047 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8048 struct dwarf2_section_info
*section
,
8049 struct dwarf2_section_info
*abbrev_section
,
8050 unsigned int is_dwz
)
8052 const gdb_byte
*info_ptr
;
8053 struct objfile
*objfile
= per_objfile
->objfile
;
8055 if (dwarf_read_debug
)
8056 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8057 section
->get_name (),
8058 section
->get_file_name ());
8060 section
->read (objfile
);
8062 info_ptr
= section
->buffer
;
8064 while (info_ptr
< section
->buffer
+ section
->size
)
8066 struct dwarf2_per_cu_data
*this_cu
;
8068 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8070 comp_unit_head cu_header
;
8071 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8072 abbrev_section
, info_ptr
,
8073 rcuh_kind::COMPILE
);
8075 /* Save the compilation unit for later lookup. */
8076 if (cu_header
.unit_type
!= DW_UT_type
)
8077 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8080 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8081 sig_type
->signature
= cu_header
.signature
;
8082 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8083 this_cu
= &sig_type
->per_cu
;
8085 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8086 this_cu
->sect_off
= sect_off
;
8087 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8088 this_cu
->is_dwz
= is_dwz
;
8089 this_cu
->section
= section
;
8091 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8093 info_ptr
= info_ptr
+ this_cu
->length
;
8097 /* Create a list of all compilation units in OBJFILE.
8098 This is only done for -readnow and building partial symtabs. */
8101 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8103 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8104 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8105 &per_objfile
->per_bfd
->abbrev
, 0);
8107 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8109 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8112 /* Process all loaded DIEs for compilation unit CU, starting at
8113 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8114 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8115 DW_AT_ranges). See the comments of add_partial_subprogram on how
8116 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8119 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8120 CORE_ADDR
*highpc
, int set_addrmap
,
8121 struct dwarf2_cu
*cu
)
8123 struct partial_die_info
*pdi
;
8125 /* Now, march along the PDI's, descending into ones which have
8126 interesting children but skipping the children of the other ones,
8127 until we reach the end of the compilation unit. */
8135 /* Anonymous namespaces or modules have no name but have interesting
8136 children, so we need to look at them. Ditto for anonymous
8139 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8140 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8141 || pdi
->tag
== DW_TAG_imported_unit
8142 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8146 case DW_TAG_subprogram
:
8147 case DW_TAG_inlined_subroutine
:
8148 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8149 if (cu
->language
== language_cplus
)
8150 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8153 case DW_TAG_constant
:
8154 case DW_TAG_variable
:
8155 case DW_TAG_typedef
:
8156 case DW_TAG_union_type
:
8157 if (!pdi
->is_declaration
8158 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8160 add_partial_symbol (pdi
, cu
);
8163 case DW_TAG_class_type
:
8164 case DW_TAG_interface_type
:
8165 case DW_TAG_structure_type
:
8166 if (!pdi
->is_declaration
)
8168 add_partial_symbol (pdi
, cu
);
8170 if ((cu
->language
== language_rust
8171 || cu
->language
== language_cplus
) && pdi
->has_children
)
8172 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8175 case DW_TAG_enumeration_type
:
8176 if (!pdi
->is_declaration
)
8177 add_partial_enumeration (pdi
, cu
);
8179 case DW_TAG_base_type
:
8180 case DW_TAG_subrange_type
:
8181 /* File scope base type definitions are added to the partial
8183 add_partial_symbol (pdi
, cu
);
8185 case DW_TAG_namespace
:
8186 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8189 if (!pdi
->is_declaration
)
8190 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8192 case DW_TAG_imported_unit
:
8194 struct dwarf2_per_cu_data
*per_cu
;
8196 /* For now we don't handle imported units in type units. */
8197 if (cu
->per_cu
->is_debug_types
)
8199 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8200 " supported in type units [in module %s]"),
8201 objfile_name (cu
->per_objfile
->objfile
));
8204 per_cu
= dwarf2_find_containing_comp_unit
8205 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8207 /* Go read the partial unit, if needed. */
8208 if (per_cu
->v
.psymtab
== NULL
)
8209 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8212 cu
->per_cu
->imported_symtabs_push (per_cu
);
8215 case DW_TAG_imported_declaration
:
8216 add_partial_symbol (pdi
, cu
);
8223 /* If the die has a sibling, skip to the sibling. */
8225 pdi
= pdi
->die_sibling
;
8229 /* Functions used to compute the fully scoped name of a partial DIE.
8231 Normally, this is simple. For C++, the parent DIE's fully scoped
8232 name is concatenated with "::" and the partial DIE's name.
8233 Enumerators are an exception; they use the scope of their parent
8234 enumeration type, i.e. the name of the enumeration type is not
8235 prepended to the enumerator.
8237 There are two complexities. One is DW_AT_specification; in this
8238 case "parent" means the parent of the target of the specification,
8239 instead of the direct parent of the DIE. The other is compilers
8240 which do not emit DW_TAG_namespace; in this case we try to guess
8241 the fully qualified name of structure types from their members'
8242 linkage names. This must be done using the DIE's children rather
8243 than the children of any DW_AT_specification target. We only need
8244 to do this for structures at the top level, i.e. if the target of
8245 any DW_AT_specification (if any; otherwise the DIE itself) does not
8248 /* Compute the scope prefix associated with PDI's parent, in
8249 compilation unit CU. The result will be allocated on CU's
8250 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8251 field. NULL is returned if no prefix is necessary. */
8253 partial_die_parent_scope (struct partial_die_info
*pdi
,
8254 struct dwarf2_cu
*cu
)
8256 const char *grandparent_scope
;
8257 struct partial_die_info
*parent
, *real_pdi
;
8259 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8260 then this means the parent of the specification DIE. */
8263 while (real_pdi
->has_specification
)
8265 auto res
= find_partial_die (real_pdi
->spec_offset
,
8266 real_pdi
->spec_is_dwz
, cu
);
8271 parent
= real_pdi
->die_parent
;
8275 if (parent
->scope_set
)
8276 return parent
->scope
;
8280 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8282 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8283 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8284 Work around this problem here. */
8285 if (cu
->language
== language_cplus
8286 && parent
->tag
== DW_TAG_namespace
8287 && strcmp (parent
->name (cu
), "::") == 0
8288 && grandparent_scope
== NULL
)
8290 parent
->scope
= NULL
;
8291 parent
->scope_set
= 1;
8295 /* Nested subroutines in Fortran get a prefix. */
8296 if (pdi
->tag
== DW_TAG_enumerator
)
8297 /* Enumerators should not get the name of the enumeration as a prefix. */
8298 parent
->scope
= grandparent_scope
;
8299 else if (parent
->tag
== DW_TAG_namespace
8300 || parent
->tag
== DW_TAG_module
8301 || parent
->tag
== DW_TAG_structure_type
8302 || parent
->tag
== DW_TAG_class_type
8303 || parent
->tag
== DW_TAG_interface_type
8304 || parent
->tag
== DW_TAG_union_type
8305 || parent
->tag
== DW_TAG_enumeration_type
8306 || (cu
->language
== language_fortran
8307 && parent
->tag
== DW_TAG_subprogram
8308 && pdi
->tag
== DW_TAG_subprogram
))
8310 if (grandparent_scope
== NULL
)
8311 parent
->scope
= parent
->name (cu
);
8313 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8315 parent
->name (cu
), 0, cu
);
8319 /* FIXME drow/2004-04-01: What should we be doing with
8320 function-local names? For partial symbols, we should probably be
8322 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8323 dwarf_tag_name (parent
->tag
),
8324 sect_offset_str (pdi
->sect_off
));
8325 parent
->scope
= grandparent_scope
;
8328 parent
->scope_set
= 1;
8329 return parent
->scope
;
8332 /* Return the fully scoped name associated with PDI, from compilation unit
8333 CU. The result will be allocated with malloc. */
8335 static gdb::unique_xmalloc_ptr
<char>
8336 partial_die_full_name (struct partial_die_info
*pdi
,
8337 struct dwarf2_cu
*cu
)
8339 const char *parent_scope
;
8341 /* If this is a template instantiation, we can not work out the
8342 template arguments from partial DIEs. So, unfortunately, we have
8343 to go through the full DIEs. At least any work we do building
8344 types here will be reused if full symbols are loaded later. */
8345 if (pdi
->has_template_arguments
)
8349 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8351 struct die_info
*die
;
8352 struct attribute attr
;
8353 struct dwarf2_cu
*ref_cu
= cu
;
8355 /* DW_FORM_ref_addr is using section offset. */
8356 attr
.name
= (enum dwarf_attribute
) 0;
8357 attr
.form
= DW_FORM_ref_addr
;
8358 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8359 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8361 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8365 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8366 if (parent_scope
== NULL
)
8369 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8375 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8377 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8378 struct objfile
*objfile
= per_objfile
->objfile
;
8379 struct gdbarch
*gdbarch
= objfile
->arch ();
8381 const char *actual_name
= NULL
;
8384 baseaddr
= objfile
->text_section_offset ();
8386 gdb::unique_xmalloc_ptr
<char> built_actual_name
8387 = partial_die_full_name (pdi
, cu
);
8388 if (built_actual_name
!= NULL
)
8389 actual_name
= built_actual_name
.get ();
8391 if (actual_name
== NULL
)
8392 actual_name
= pdi
->name (cu
);
8394 partial_symbol psymbol
;
8395 memset (&psymbol
, 0, sizeof (psymbol
));
8396 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8397 psymbol
.ginfo
.section
= -1;
8399 /* The code below indicates that the psymbol should be installed by
8401 gdb::optional
<psymbol_placement
> where
;
8405 case DW_TAG_inlined_subroutine
:
8406 case DW_TAG_subprogram
:
8407 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8409 if (pdi
->is_external
8410 || cu
->language
== language_ada
8411 || (cu
->language
== language_fortran
8412 && pdi
->die_parent
!= NULL
8413 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8415 /* Normally, only "external" DIEs are part of the global scope.
8416 But in Ada and Fortran, we want to be able to access nested
8417 procedures globally. So all Ada and Fortran subprograms are
8418 stored in the global scope. */
8419 where
= psymbol_placement::GLOBAL
;
8422 where
= psymbol_placement::STATIC
;
8424 psymbol
.domain
= VAR_DOMAIN
;
8425 psymbol
.aclass
= LOC_BLOCK
;
8426 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8427 psymbol
.ginfo
.value
.address
= addr
;
8429 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8430 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8432 case DW_TAG_constant
:
8433 psymbol
.domain
= VAR_DOMAIN
;
8434 psymbol
.aclass
= LOC_STATIC
;
8435 where
= (pdi
->is_external
8436 ? psymbol_placement::GLOBAL
8437 : psymbol_placement::STATIC
);
8439 case DW_TAG_variable
:
8441 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8445 && !per_objfile
->per_bfd
->has_section_at_zero
)
8447 /* A global or static variable may also have been stripped
8448 out by the linker if unused, in which case its address
8449 will be nullified; do not add such variables into partial
8450 symbol table then. */
8452 else if (pdi
->is_external
)
8455 Don't enter into the minimal symbol tables as there is
8456 a minimal symbol table entry from the ELF symbols already.
8457 Enter into partial symbol table if it has a location
8458 descriptor or a type.
8459 If the location descriptor is missing, new_symbol will create
8460 a LOC_UNRESOLVED symbol, the address of the variable will then
8461 be determined from the minimal symbol table whenever the variable
8463 The address for the partial symbol table entry is not
8464 used by GDB, but it comes in handy for debugging partial symbol
8467 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8469 psymbol
.domain
= VAR_DOMAIN
;
8470 psymbol
.aclass
= LOC_STATIC
;
8471 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8472 psymbol
.ginfo
.value
.address
= addr
;
8473 where
= psymbol_placement::GLOBAL
;
8478 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8480 /* Static Variable. Skip symbols whose value we cannot know (those
8481 without location descriptors or constant values). */
8482 if (!has_loc
&& !pdi
->has_const_value
)
8485 psymbol
.domain
= VAR_DOMAIN
;
8486 psymbol
.aclass
= LOC_STATIC
;
8487 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8489 psymbol
.ginfo
.value
.address
= addr
;
8490 where
= psymbol_placement::STATIC
;
8493 case DW_TAG_typedef
:
8494 case DW_TAG_base_type
:
8495 case DW_TAG_subrange_type
:
8496 psymbol
.domain
= VAR_DOMAIN
;
8497 psymbol
.aclass
= LOC_TYPEDEF
;
8498 where
= psymbol_placement::STATIC
;
8500 case DW_TAG_imported_declaration
:
8501 case DW_TAG_namespace
:
8502 psymbol
.domain
= VAR_DOMAIN
;
8503 psymbol
.aclass
= LOC_TYPEDEF
;
8504 where
= psymbol_placement::GLOBAL
;
8507 /* With Fortran 77 there might be a "BLOCK DATA" module
8508 available without any name. If so, we skip the module as it
8509 doesn't bring any value. */
8510 if (actual_name
!= nullptr)
8512 psymbol
.domain
= MODULE_DOMAIN
;
8513 psymbol
.aclass
= LOC_TYPEDEF
;
8514 where
= psymbol_placement::GLOBAL
;
8517 case DW_TAG_class_type
:
8518 case DW_TAG_interface_type
:
8519 case DW_TAG_structure_type
:
8520 case DW_TAG_union_type
:
8521 case DW_TAG_enumeration_type
:
8522 /* Skip external references. The DWARF standard says in the section
8523 about "Structure, Union, and Class Type Entries": "An incomplete
8524 structure, union or class type is represented by a structure,
8525 union or class entry that does not have a byte size attribute
8526 and that has a DW_AT_declaration attribute." */
8527 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8530 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8531 static vs. global. */
8532 psymbol
.domain
= STRUCT_DOMAIN
;
8533 psymbol
.aclass
= LOC_TYPEDEF
;
8534 where
= (cu
->language
== language_cplus
8535 ? psymbol_placement::GLOBAL
8536 : psymbol_placement::STATIC
);
8538 case DW_TAG_enumerator
:
8539 psymbol
.domain
= VAR_DOMAIN
;
8540 psymbol
.aclass
= LOC_CONST
;
8541 where
= (cu
->language
== language_cplus
8542 ? psymbol_placement::GLOBAL
8543 : psymbol_placement::STATIC
);
8549 if (where
.has_value ())
8551 if (built_actual_name
!= nullptr)
8552 actual_name
= objfile
->intern (actual_name
);
8553 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8554 psymbol
.ginfo
.set_linkage_name (actual_name
);
8557 psymbol
.ginfo
.set_demangled_name (actual_name
,
8558 &objfile
->objfile_obstack
);
8559 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8561 add_psymbol_to_list (psymbol
, *where
, objfile
);
8565 /* Read a partial die corresponding to a namespace; also, add a symbol
8566 corresponding to that namespace to the symbol table. NAMESPACE is
8567 the name of the enclosing namespace. */
8570 add_partial_namespace (struct partial_die_info
*pdi
,
8571 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8572 int set_addrmap
, struct dwarf2_cu
*cu
)
8574 /* Add a symbol for the namespace. */
8576 add_partial_symbol (pdi
, cu
);
8578 /* Now scan partial symbols in that namespace. */
8580 if (pdi
->has_children
)
8581 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8584 /* Read a partial die corresponding to a Fortran module. */
8587 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8588 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8590 /* Add a symbol for the namespace. */
8592 add_partial_symbol (pdi
, cu
);
8594 /* Now scan partial symbols in that module. */
8596 if (pdi
->has_children
)
8597 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8600 /* Read a partial die corresponding to a subprogram or an inlined
8601 subprogram and create a partial symbol for that subprogram.
8602 When the CU language allows it, this routine also defines a partial
8603 symbol for each nested subprogram that this subprogram contains.
8604 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8605 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8607 PDI may also be a lexical block, in which case we simply search
8608 recursively for subprograms defined inside that lexical block.
8609 Again, this is only performed when the CU language allows this
8610 type of definitions. */
8613 add_partial_subprogram (struct partial_die_info
*pdi
,
8614 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8615 int set_addrmap
, struct dwarf2_cu
*cu
)
8617 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8619 if (pdi
->has_pc_info
)
8621 if (pdi
->lowpc
< *lowpc
)
8622 *lowpc
= pdi
->lowpc
;
8623 if (pdi
->highpc
> *highpc
)
8624 *highpc
= pdi
->highpc
;
8627 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8628 struct gdbarch
*gdbarch
= objfile
->arch ();
8630 CORE_ADDR this_highpc
;
8631 CORE_ADDR this_lowpc
;
8633 baseaddr
= objfile
->text_section_offset ();
8635 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8636 pdi
->lowpc
+ baseaddr
)
8639 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8640 pdi
->highpc
+ baseaddr
)
8642 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8643 this_lowpc
, this_highpc
- 1,
8644 cu
->per_cu
->v
.psymtab
);
8648 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8650 if (!pdi
->is_declaration
)
8651 /* Ignore subprogram DIEs that do not have a name, they are
8652 illegal. Do not emit a complaint at this point, we will
8653 do so when we convert this psymtab into a symtab. */
8655 add_partial_symbol (pdi
, cu
);
8659 if (! pdi
->has_children
)
8662 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8664 pdi
= pdi
->die_child
;
8668 if (pdi
->tag
== DW_TAG_subprogram
8669 || pdi
->tag
== DW_TAG_inlined_subroutine
8670 || pdi
->tag
== DW_TAG_lexical_block
)
8671 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8672 pdi
= pdi
->die_sibling
;
8677 /* Read a partial die corresponding to an enumeration type. */
8680 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8681 struct dwarf2_cu
*cu
)
8683 struct partial_die_info
*pdi
;
8685 if (enum_pdi
->name (cu
) != NULL
)
8686 add_partial_symbol (enum_pdi
, cu
);
8688 pdi
= enum_pdi
->die_child
;
8691 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8692 complaint (_("malformed enumerator DIE ignored"));
8694 add_partial_symbol (pdi
, cu
);
8695 pdi
= pdi
->die_sibling
;
8699 /* Return the initial uleb128 in the die at INFO_PTR. */
8702 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8704 unsigned int bytes_read
;
8706 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8709 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8710 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8712 Return the corresponding abbrev, or NULL if the number is zero (indicating
8713 an empty DIE). In either case *BYTES_READ will be set to the length of
8714 the initial number. */
8716 static struct abbrev_info
*
8717 peek_die_abbrev (const die_reader_specs
&reader
,
8718 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8720 dwarf2_cu
*cu
= reader
.cu
;
8721 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8722 unsigned int abbrev_number
8723 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8725 if (abbrev_number
== 0)
8728 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8731 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8732 " at offset %s [in module %s]"),
8733 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8734 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8740 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8741 Returns a pointer to the end of a series of DIEs, terminated by an empty
8742 DIE. Any children of the skipped DIEs will also be skipped. */
8744 static const gdb_byte
*
8745 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8749 unsigned int bytes_read
;
8750 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8753 return info_ptr
+ bytes_read
;
8755 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8759 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8760 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8761 abbrev corresponding to that skipped uleb128 should be passed in
8762 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8765 static const gdb_byte
*
8766 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8767 struct abbrev_info
*abbrev
)
8769 unsigned int bytes_read
;
8770 struct attribute attr
;
8771 bfd
*abfd
= reader
->abfd
;
8772 struct dwarf2_cu
*cu
= reader
->cu
;
8773 const gdb_byte
*buffer
= reader
->buffer
;
8774 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8775 unsigned int form
, i
;
8777 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8779 /* The only abbrev we care about is DW_AT_sibling. */
8780 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8783 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8785 if (attr
.form
== DW_FORM_ref_addr
)
8786 complaint (_("ignoring absolute DW_AT_sibling"));
8789 sect_offset off
= attr
.get_ref_die_offset ();
8790 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8792 if (sibling_ptr
< info_ptr
)
8793 complaint (_("DW_AT_sibling points backwards"));
8794 else if (sibling_ptr
> reader
->buffer_end
)
8795 reader
->die_section
->overflow_complaint ();
8801 /* If it isn't DW_AT_sibling, skip this attribute. */
8802 form
= abbrev
->attrs
[i
].form
;
8806 case DW_FORM_ref_addr
:
8807 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8808 and later it is offset sized. */
8809 if (cu
->header
.version
== 2)
8810 info_ptr
+= cu
->header
.addr_size
;
8812 info_ptr
+= cu
->header
.offset_size
;
8814 case DW_FORM_GNU_ref_alt
:
8815 info_ptr
+= cu
->header
.offset_size
;
8818 info_ptr
+= cu
->header
.addr_size
;
8826 case DW_FORM_flag_present
:
8827 case DW_FORM_implicit_const
:
8844 case DW_FORM_ref_sig8
:
8847 case DW_FORM_data16
:
8850 case DW_FORM_string
:
8851 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8852 info_ptr
+= bytes_read
;
8854 case DW_FORM_sec_offset
:
8856 case DW_FORM_GNU_strp_alt
:
8857 info_ptr
+= cu
->header
.offset_size
;
8859 case DW_FORM_exprloc
:
8861 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8862 info_ptr
+= bytes_read
;
8864 case DW_FORM_block1
:
8865 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8867 case DW_FORM_block2
:
8868 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8870 case DW_FORM_block4
:
8871 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8877 case DW_FORM_ref_udata
:
8878 case DW_FORM_GNU_addr_index
:
8879 case DW_FORM_GNU_str_index
:
8880 case DW_FORM_rnglistx
:
8881 case DW_FORM_loclistx
:
8882 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8884 case DW_FORM_indirect
:
8885 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8886 info_ptr
+= bytes_read
;
8887 /* We need to continue parsing from here, so just go back to
8889 goto skip_attribute
;
8892 error (_("Dwarf Error: Cannot handle %s "
8893 "in DWARF reader [in module %s]"),
8894 dwarf_form_name (form
),
8895 bfd_get_filename (abfd
));
8899 if (abbrev
->has_children
)
8900 return skip_children (reader
, info_ptr
);
8905 /* Locate ORIG_PDI's sibling.
8906 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8908 static const gdb_byte
*
8909 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8910 struct partial_die_info
*orig_pdi
,
8911 const gdb_byte
*info_ptr
)
8913 /* Do we know the sibling already? */
8915 if (orig_pdi
->sibling
)
8916 return orig_pdi
->sibling
;
8918 /* Are there any children to deal with? */
8920 if (!orig_pdi
->has_children
)
8923 /* Skip the children the long way. */
8925 return skip_children (reader
, info_ptr
);
8928 /* Expand this partial symbol table into a full symbol table. SELF is
8932 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8934 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8936 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8938 /* If this psymtab is constructed from a debug-only objfile, the
8939 has_section_at_zero flag will not necessarily be correct. We
8940 can get the correct value for this flag by looking at the data
8941 associated with the (presumably stripped) associated objfile. */
8942 if (objfile
->separate_debug_objfile_backlink
)
8944 dwarf2_per_objfile
*per_objfile_backlink
8945 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8947 per_objfile
->per_bfd
->has_section_at_zero
8948 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8951 expand_psymtab (objfile
);
8953 process_cu_includes (per_objfile
);
8956 /* Reading in full CUs. */
8958 /* Add PER_CU to the queue. */
8961 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8962 dwarf2_per_objfile
*per_objfile
,
8963 enum language pretend_language
)
8966 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
8969 /* If PER_CU is not yet queued, add it to the queue.
8970 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8972 The result is non-zero if PER_CU was queued, otherwise the result is zero
8973 meaning either PER_CU is already queued or it is already loaded.
8975 N.B. There is an invariant here that if a CU is queued then it is loaded.
8976 The caller is required to load PER_CU if we return non-zero. */
8979 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8980 dwarf2_per_cu_data
*per_cu
,
8981 dwarf2_per_objfile
*per_objfile
,
8982 enum language pretend_language
)
8984 /* We may arrive here during partial symbol reading, if we need full
8985 DIEs to process an unusual case (e.g. template arguments). Do
8986 not queue PER_CU, just tell our caller to load its DIEs. */
8987 if (per_cu
->per_bfd
->reading_partial_symbols
)
8989 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8991 if (cu
== NULL
|| cu
->dies
== NULL
)
8996 /* Mark the dependence relation so that we don't flush PER_CU
8998 if (dependent_cu
!= NULL
)
8999 dwarf2_add_dependence (dependent_cu
, per_cu
);
9001 /* If it's already on the queue, we have nothing to do. */
9005 /* If the compilation unit is already loaded, just mark it as
9007 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9014 /* Add it to the queue. */
9015 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9020 /* Process the queue. */
9023 process_queue (dwarf2_per_objfile
*per_objfile
)
9025 if (dwarf_read_debug
)
9027 fprintf_unfiltered (gdb_stdlog
,
9028 "Expanding one or more symtabs of objfile %s ...\n",
9029 objfile_name (per_objfile
->objfile
));
9032 /* The queue starts out with one item, but following a DIE reference
9033 may load a new CU, adding it to the end of the queue. */
9034 while (!per_objfile
->per_bfd
->queue
.empty ())
9036 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
.front ();
9037 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9039 if (!per_objfile
->symtab_set_p (per_cu
))
9041 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9043 /* Skip dummy CUs. */
9046 unsigned int debug_print_threshold
;
9049 if (per_cu
->is_debug_types
)
9051 struct signatured_type
*sig_type
=
9052 (struct signatured_type
*) per_cu
;
9054 sprintf (buf
, "TU %s at offset %s",
9055 hex_string (sig_type
->signature
),
9056 sect_offset_str (per_cu
->sect_off
));
9057 /* There can be 100s of TUs.
9058 Only print them in verbose mode. */
9059 debug_print_threshold
= 2;
9063 sprintf (buf
, "CU at offset %s",
9064 sect_offset_str (per_cu
->sect_off
));
9065 debug_print_threshold
= 1;
9068 if (dwarf_read_debug
>= debug_print_threshold
)
9069 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9071 if (per_cu
->is_debug_types
)
9072 process_full_type_unit (cu
, item
.pretend_language
);
9074 process_full_comp_unit (cu
, item
.pretend_language
);
9076 if (dwarf_read_debug
>= debug_print_threshold
)
9077 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9082 per_objfile
->per_bfd
->queue
.pop ();
9085 if (dwarf_read_debug
)
9087 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9088 objfile_name (per_objfile
->objfile
));
9092 /* Read in full symbols for PST, and anything it depends on. */
9095 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9097 gdb_assert (!readin_p (objfile
));
9099 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9100 free_cached_comp_units
freer (per_objfile
);
9101 expand_dependencies (objfile
);
9103 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9104 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9107 /* See psympriv.h. */
9110 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9112 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9113 return per_objfile
->symtab_set_p (per_cu_data
);
9116 /* See psympriv.h. */
9119 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9121 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9122 return per_objfile
->get_symtab (per_cu_data
);
9125 /* Trivial hash function for die_info: the hash value of a DIE
9126 is its offset in .debug_info for this objfile. */
9129 die_hash (const void *item
)
9131 const struct die_info
*die
= (const struct die_info
*) item
;
9133 return to_underlying (die
->sect_off
);
9136 /* Trivial comparison function for die_info structures: two DIEs
9137 are equal if they have the same offset. */
9140 die_eq (const void *item_lhs
, const void *item_rhs
)
9142 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9143 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9145 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9148 /* Load the DIEs associated with PER_CU into memory. */
9151 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9152 dwarf2_per_objfile
*per_objfile
,
9154 enum language pretend_language
)
9156 gdb_assert (! this_cu
->is_debug_types
);
9158 dwarf2_cu
*existing_cu
= per_objfile
->get_cu (this_cu
);
9159 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9163 struct dwarf2_cu
*cu
= reader
.cu
;
9164 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9166 gdb_assert (cu
->die_hash
== NULL
);
9168 htab_create_alloc_ex (cu
->header
.length
/ 12,
9172 &cu
->comp_unit_obstack
,
9173 hashtab_obstack_allocate
,
9174 dummy_obstack_deallocate
);
9176 if (reader
.comp_unit_die
->has_children
)
9177 reader
.comp_unit_die
->child
9178 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9179 &info_ptr
, reader
.comp_unit_die
);
9180 cu
->dies
= reader
.comp_unit_die
;
9181 /* comp_unit_die is not stored in die_hash, no need. */
9183 /* We try not to read any attributes in this function, because not
9184 all CUs needed for references have been loaded yet, and symbol
9185 table processing isn't initialized. But we have to set the CU language,
9186 or we won't be able to build types correctly.
9187 Similarly, if we do not read the producer, we can not apply
9188 producer-specific interpretation. */
9189 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9194 /* Add a DIE to the delayed physname list. */
9197 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9198 const char *name
, struct die_info
*die
,
9199 struct dwarf2_cu
*cu
)
9201 struct delayed_method_info mi
;
9203 mi
.fnfield_index
= fnfield_index
;
9207 cu
->method_list
.push_back (mi
);
9210 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9211 "const" / "volatile". If so, decrements LEN by the length of the
9212 modifier and return true. Otherwise return false. */
9216 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9218 size_t mod_len
= sizeof (mod
) - 1;
9219 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9227 /* Compute the physnames of any methods on the CU's method list.
9229 The computation of method physnames is delayed in order to avoid the
9230 (bad) condition that one of the method's formal parameters is of an as yet
9234 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9236 /* Only C++ delays computing physnames. */
9237 if (cu
->method_list
.empty ())
9239 gdb_assert (cu
->language
== language_cplus
);
9241 for (const delayed_method_info
&mi
: cu
->method_list
)
9243 const char *physname
;
9244 struct fn_fieldlist
*fn_flp
9245 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9246 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9247 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9248 = physname
? physname
: "";
9250 /* Since there's no tag to indicate whether a method is a
9251 const/volatile overload, extract that information out of the
9253 if (physname
!= NULL
)
9255 size_t len
= strlen (physname
);
9259 if (physname
[len
] == ')') /* shortcut */
9261 else if (check_modifier (physname
, len
, " const"))
9262 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9263 else if (check_modifier (physname
, len
, " volatile"))
9264 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9271 /* The list is no longer needed. */
9272 cu
->method_list
.clear ();
9275 /* Go objects should be embedded in a DW_TAG_module DIE,
9276 and it's not clear if/how imported objects will appear.
9277 To keep Go support simple until that's worked out,
9278 go back through what we've read and create something usable.
9279 We could do this while processing each DIE, and feels kinda cleaner,
9280 but that way is more invasive.
9281 This is to, for example, allow the user to type "p var" or "b main"
9282 without having to specify the package name, and allow lookups
9283 of module.object to work in contexts that use the expression
9287 fixup_go_packaging (struct dwarf2_cu
*cu
)
9289 gdb::unique_xmalloc_ptr
<char> package_name
;
9290 struct pending
*list
;
9293 for (list
= *cu
->get_builder ()->get_global_symbols ();
9297 for (i
= 0; i
< list
->nsyms
; ++i
)
9299 struct symbol
*sym
= list
->symbol
[i
];
9301 if (sym
->language () == language_go
9302 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9304 gdb::unique_xmalloc_ptr
<char> this_package_name
9305 (go_symbol_package_name (sym
));
9307 if (this_package_name
== NULL
)
9309 if (package_name
== NULL
)
9310 package_name
= std::move (this_package_name
);
9313 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9314 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9315 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9316 (symbol_symtab (sym
) != NULL
9317 ? symtab_to_filename_for_display
9318 (symbol_symtab (sym
))
9319 : objfile_name (objfile
)),
9320 this_package_name
.get (), package_name
.get ());
9326 if (package_name
!= NULL
)
9328 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9329 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9330 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9331 saved_package_name
);
9334 sym
= new (&objfile
->objfile_obstack
) symbol
;
9335 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9336 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9337 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9338 e.g., "main" finds the "main" module and not C's main(). */
9339 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9340 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9341 SYMBOL_TYPE (sym
) = type
;
9343 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9347 /* Allocate a fully-qualified name consisting of the two parts on the
9351 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9353 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9356 /* A helper that allocates a variant part to attach to a Rust enum
9357 type. OBSTACK is where the results should be allocated. TYPE is
9358 the type we're processing. DISCRIMINANT_INDEX is the index of the
9359 discriminant. It must be the index of one of the fields of TYPE.
9360 DEFAULT_INDEX is the index of the default field; or -1 if there is
9361 no default. RANGES is indexed by "effective" field number (the
9362 field index, but omitting the discriminant and default fields) and
9363 must hold the discriminant values used by the variants. Note that
9364 RANGES must have a lifetime at least as long as OBSTACK -- either
9365 already allocated on it, or static. */
9368 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9369 int discriminant_index
, int default_index
,
9370 gdb::array_view
<discriminant_range
> ranges
)
9372 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9373 must be handled by the caller. */
9374 gdb_assert (discriminant_index
>= 0
9375 && discriminant_index
< type
->num_fields ());
9376 gdb_assert (default_index
== -1
9377 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9379 /* We have one variant for each non-discriminant field. */
9380 int n_variants
= type
->num_fields () - 1;
9382 variant
*variants
= new (obstack
) variant
[n_variants
];
9385 for (int i
= 0; i
< type
->num_fields (); ++i
)
9387 if (i
== discriminant_index
)
9390 variants
[var_idx
].first_field
= i
;
9391 variants
[var_idx
].last_field
= i
+ 1;
9393 /* The default field does not need a range, but other fields do.
9394 We skipped the discriminant above. */
9395 if (i
!= default_index
)
9397 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9404 gdb_assert (range_idx
== ranges
.size ());
9405 gdb_assert (var_idx
== n_variants
);
9407 variant_part
*part
= new (obstack
) variant_part
;
9408 part
->discriminant_index
= discriminant_index
;
9409 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9410 discriminant_index
));
9411 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9413 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9414 gdb::array_view
<variant_part
> *prop_value
9415 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9417 struct dynamic_prop prop
;
9418 prop
.kind
= PROP_VARIANT_PARTS
;
9419 prop
.data
.variant_parts
= prop_value
;
9421 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9424 /* Some versions of rustc emitted enums in an unusual way.
9426 Ordinary enums were emitted as unions. The first element of each
9427 structure in the union was named "RUST$ENUM$DISR". This element
9428 held the discriminant.
9430 These versions of Rust also implemented the "non-zero"
9431 optimization. When the enum had two values, and one is empty and
9432 the other holds a pointer that cannot be zero, the pointer is used
9433 as the discriminant, with a zero value meaning the empty variant.
9434 Here, the union's first member is of the form
9435 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9436 where the fieldnos are the indices of the fields that should be
9437 traversed in order to find the field (which may be several fields deep)
9438 and the variantname is the name of the variant of the case when the
9441 This function recognizes whether TYPE is of one of these forms,
9442 and, if so, smashes it to be a variant type. */
9445 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9447 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9449 /* We don't need to deal with empty enums. */
9450 if (type
->num_fields () == 0)
9453 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9454 if (type
->num_fields () == 1
9455 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9457 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9459 /* Decode the field name to find the offset of the
9461 ULONGEST bit_offset
= 0;
9462 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9463 while (name
[0] >= '0' && name
[0] <= '9')
9466 unsigned long index
= strtoul (name
, &tail
, 10);
9469 || index
>= field_type
->num_fields ()
9470 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9471 != FIELD_LOC_KIND_BITPOS
))
9473 complaint (_("Could not parse Rust enum encoding string \"%s\""
9475 TYPE_FIELD_NAME (type
, 0),
9476 objfile_name (objfile
));
9481 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9482 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9485 /* Smash this type to be a structure type. We have to do this
9486 because the type has already been recorded. */
9487 type
->set_code (TYPE_CODE_STRUCT
);
9488 type
->set_num_fields (3);
9489 /* Save the field we care about. */
9490 struct field saved_field
= type
->field (0);
9492 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9494 /* Put the discriminant at index 0. */
9495 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9496 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9497 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9498 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9500 /* The order of fields doesn't really matter, so put the real
9501 field at index 1 and the data-less field at index 2. */
9502 type
->field (1) = saved_field
;
9503 TYPE_FIELD_NAME (type
, 1)
9504 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9505 TYPE_FIELD_TYPE (type
, 1)->set_name
9506 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9507 TYPE_FIELD_NAME (type
, 1)));
9509 const char *dataless_name
9510 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9512 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9514 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9515 /* NAME points into the original discriminant name, which
9516 already has the correct lifetime. */
9517 TYPE_FIELD_NAME (type
, 2) = name
;
9518 SET_FIELD_BITPOS (type
->field (2), 0);
9520 /* Indicate that this is a variant type. */
9521 static discriminant_range ranges
[1] = { { 0, 0 } };
9522 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9524 /* A union with a single anonymous field is probably an old-style
9526 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9528 /* Smash this type to be a structure type. We have to do this
9529 because the type has already been recorded. */
9530 type
->set_code (TYPE_CODE_STRUCT
);
9532 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9533 const char *variant_name
9534 = rust_last_path_segment (field_type
->name ());
9535 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9536 field_type
->set_name
9537 (rust_fully_qualify (&objfile
->objfile_obstack
,
9538 type
->name (), variant_name
));
9542 struct type
*disr_type
= nullptr;
9543 for (int i
= 0; i
< type
->num_fields (); ++i
)
9545 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9547 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9549 /* All fields of a true enum will be structs. */
9552 else if (disr_type
->num_fields () == 0)
9554 /* Could be data-less variant, so keep going. */
9555 disr_type
= nullptr;
9557 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9558 "RUST$ENUM$DISR") != 0)
9560 /* Not a Rust enum. */
9570 /* If we got here without a discriminant, then it's probably
9572 if (disr_type
== nullptr)
9575 /* Smash this type to be a structure type. We have to do this
9576 because the type has already been recorded. */
9577 type
->set_code (TYPE_CODE_STRUCT
);
9579 /* Make space for the discriminant field. */
9580 struct field
*disr_field
= &disr_type
->field (0);
9582 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9583 * sizeof (struct field
)));
9584 memcpy (new_fields
+ 1, type
->fields (),
9585 type
->num_fields () * sizeof (struct field
));
9586 type
->set_fields (new_fields
);
9587 type
->set_num_fields (type
->num_fields () + 1);
9589 /* Install the discriminant at index 0 in the union. */
9590 type
->field (0) = *disr_field
;
9591 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9592 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9594 /* We need a way to find the correct discriminant given a
9595 variant name. For convenience we build a map here. */
9596 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9597 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9598 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9600 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9603 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9604 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9608 int n_fields
= type
->num_fields ();
9609 /* We don't need a range entry for the discriminant, but we do
9610 need one for every other field, as there is no default
9612 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9615 /* Skip the discriminant here. */
9616 for (int i
= 1; i
< n_fields
; ++i
)
9618 /* Find the final word in the name of this variant's type.
9619 That name can be used to look up the correct
9621 const char *variant_name
9622 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9624 auto iter
= discriminant_map
.find (variant_name
);
9625 if (iter
!= discriminant_map
.end ())
9627 ranges
[i
].low
= iter
->second
;
9628 ranges
[i
].high
= iter
->second
;
9631 /* Remove the discriminant field, if it exists. */
9632 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9633 if (sub_type
->num_fields () > 0)
9635 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9636 sub_type
->set_fields (sub_type
->fields () + 1);
9638 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9640 (rust_fully_qualify (&objfile
->objfile_obstack
,
9641 type
->name (), variant_name
));
9644 /* Indicate that this is a variant type. */
9645 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9646 gdb::array_view
<discriminant_range
> (ranges
,
9651 /* Rewrite some Rust unions to be structures with variants parts. */
9654 rust_union_quirks (struct dwarf2_cu
*cu
)
9656 gdb_assert (cu
->language
== language_rust
);
9657 for (type
*type_
: cu
->rust_unions
)
9658 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9659 /* We don't need this any more. */
9660 cu
->rust_unions
.clear ();
9665 type_unit_group_unshareable
*
9666 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9668 auto iter
= this->m_type_units
.find (tu_group
);
9669 if (iter
!= this->m_type_units
.end ())
9670 return iter
->second
.get ();
9672 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9673 type_unit_group_unshareable
*result
= uniq
.get ();
9674 this->m_type_units
[tu_group
] = std::move (uniq
);
9679 dwarf2_per_objfile::get_type_for_signatured_type
9680 (signatured_type
*sig_type
) const
9682 auto iter
= this->m_type_map
.find (sig_type
);
9683 if (iter
== this->m_type_map
.end ())
9686 return iter
->second
;
9689 void dwarf2_per_objfile::set_type_for_signatured_type
9690 (signatured_type
*sig_type
, struct type
*type
)
9692 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9694 this->m_type_map
[sig_type
] = type
;
9697 /* A helper function for computing the list of all symbol tables
9698 included by PER_CU. */
9701 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9702 htab_t all_children
, htab_t all_type_symtabs
,
9703 dwarf2_per_cu_data
*per_cu
,
9704 dwarf2_per_objfile
*per_objfile
,
9705 struct compunit_symtab
*immediate_parent
)
9707 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9710 /* This inclusion and its children have been processed. */
9716 /* Only add a CU if it has a symbol table. */
9717 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9720 /* If this is a type unit only add its symbol table if we haven't
9721 seen it yet (type unit per_cu's can share symtabs). */
9722 if (per_cu
->is_debug_types
)
9724 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9728 result
->push_back (cust
);
9729 if (cust
->user
== NULL
)
9730 cust
->user
= immediate_parent
;
9735 result
->push_back (cust
);
9736 if (cust
->user
== NULL
)
9737 cust
->user
= immediate_parent
;
9741 if (!per_cu
->imported_symtabs_empty ())
9742 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9744 recursively_compute_inclusions (result
, all_children
,
9745 all_type_symtabs
, ptr
, per_objfile
,
9750 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9754 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9755 dwarf2_per_objfile
*per_objfile
)
9757 gdb_assert (! per_cu
->is_debug_types
);
9759 if (!per_cu
->imported_symtabs_empty ())
9762 std::vector
<compunit_symtab
*> result_symtabs
;
9763 htab_t all_children
, all_type_symtabs
;
9764 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9766 /* If we don't have a symtab, we can just skip this case. */
9770 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9771 NULL
, xcalloc
, xfree
);
9772 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9773 NULL
, xcalloc
, xfree
);
9775 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9777 recursively_compute_inclusions (&result_symtabs
, all_children
,
9778 all_type_symtabs
, ptr
, per_objfile
,
9782 /* Now we have a transitive closure of all the included symtabs. */
9783 len
= result_symtabs
.size ();
9785 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9786 struct compunit_symtab
*, len
+ 1);
9787 memcpy (cust
->includes
, result_symtabs
.data (),
9788 len
* sizeof (compunit_symtab
*));
9789 cust
->includes
[len
] = NULL
;
9791 htab_delete (all_children
);
9792 htab_delete (all_type_symtabs
);
9796 /* Compute the 'includes' field for the symtabs of all the CUs we just
9800 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9802 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9804 if (! iter
->is_debug_types
)
9805 compute_compunit_symtab_includes (iter
, per_objfile
);
9808 per_objfile
->per_bfd
->just_read_cus
.clear ();
9811 /* Generate full symbol information for CU, whose DIEs have
9812 already been loaded into memory. */
9815 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9817 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9818 struct objfile
*objfile
= per_objfile
->objfile
;
9819 struct gdbarch
*gdbarch
= objfile
->arch ();
9820 CORE_ADDR lowpc
, highpc
;
9821 struct compunit_symtab
*cust
;
9823 struct block
*static_block
;
9826 baseaddr
= objfile
->text_section_offset ();
9828 /* Clear the list here in case something was left over. */
9829 cu
->method_list
.clear ();
9831 cu
->language
= pretend_language
;
9832 cu
->language_defn
= language_def (cu
->language
);
9834 /* Do line number decoding in read_file_scope () */
9835 process_die (cu
->dies
, cu
);
9837 /* For now fudge the Go package. */
9838 if (cu
->language
== language_go
)
9839 fixup_go_packaging (cu
);
9841 /* Now that we have processed all the DIEs in the CU, all the types
9842 should be complete, and it should now be safe to compute all of the
9844 compute_delayed_physnames (cu
);
9846 if (cu
->language
== language_rust
)
9847 rust_union_quirks (cu
);
9849 /* Some compilers don't define a DW_AT_high_pc attribute for the
9850 compilation unit. If the DW_AT_high_pc is missing, synthesize
9851 it, by scanning the DIE's below the compilation unit. */
9852 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9854 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9855 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9857 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9858 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9859 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9860 addrmap to help ensure it has an accurate map of pc values belonging to
9862 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9864 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9865 SECT_OFF_TEXT (objfile
),
9870 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9872 /* Set symtab language to language from DW_AT_language. If the
9873 compilation is from a C file generated by language preprocessors, do
9874 not set the language if it was already deduced by start_subfile. */
9875 if (!(cu
->language
== language_c
9876 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9877 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9879 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9880 produce DW_AT_location with location lists but it can be possibly
9881 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9882 there were bugs in prologue debug info, fixed later in GCC-4.5
9883 by "unwind info for epilogues" patch (which is not directly related).
9885 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9886 needed, it would be wrong due to missing DW_AT_producer there.
9888 Still one can confuse GDB by using non-standard GCC compilation
9889 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9891 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9892 cust
->locations_valid
= 1;
9894 if (gcc_4_minor
>= 5)
9895 cust
->epilogue_unwind_valid
= 1;
9897 cust
->call_site_htab
= cu
->call_site_htab
;
9900 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9902 /* Push it for inclusion processing later. */
9903 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9905 /* Not needed any more. */
9906 cu
->reset_builder ();
9909 /* Generate full symbol information for type unit CU, whose DIEs have
9910 already been loaded into memory. */
9913 process_full_type_unit (dwarf2_cu
*cu
,
9914 enum language pretend_language
)
9916 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9917 struct objfile
*objfile
= per_objfile
->objfile
;
9918 struct compunit_symtab
*cust
;
9919 struct signatured_type
*sig_type
;
9921 gdb_assert (cu
->per_cu
->is_debug_types
);
9922 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9924 /* Clear the list here in case something was left over. */
9925 cu
->method_list
.clear ();
9927 cu
->language
= pretend_language
;
9928 cu
->language_defn
= language_def (cu
->language
);
9930 /* The symbol tables are set up in read_type_unit_scope. */
9931 process_die (cu
->dies
, cu
);
9933 /* For now fudge the Go package. */
9934 if (cu
->language
== language_go
)
9935 fixup_go_packaging (cu
);
9937 /* Now that we have processed all the DIEs in the CU, all the types
9938 should be complete, and it should now be safe to compute all of the
9940 compute_delayed_physnames (cu
);
9942 if (cu
->language
== language_rust
)
9943 rust_union_quirks (cu
);
9945 /* TUs share symbol tables.
9946 If this is the first TU to use this symtab, complete the construction
9947 of it with end_expandable_symtab. Otherwise, complete the addition of
9948 this TU's symbols to the existing symtab. */
9949 type_unit_group_unshareable
*tug_unshare
=
9950 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9951 if (tug_unshare
->compunit_symtab
== NULL
)
9953 buildsym_compunit
*builder
= cu
->get_builder ();
9954 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9955 tug_unshare
->compunit_symtab
= cust
;
9959 /* Set symtab language to language from DW_AT_language. If the
9960 compilation is from a C file generated by language preprocessors,
9961 do not set the language if it was already deduced by
9963 if (!(cu
->language
== language_c
9964 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9965 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9970 cu
->get_builder ()->augment_type_symtab ();
9971 cust
= tug_unshare
->compunit_symtab
;
9974 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9976 /* Not needed any more. */
9977 cu
->reset_builder ();
9980 /* Process an imported unit DIE. */
9983 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9985 struct attribute
*attr
;
9987 /* For now we don't handle imported units in type units. */
9988 if (cu
->per_cu
->is_debug_types
)
9990 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9991 " supported in type units [in module %s]"),
9992 objfile_name (cu
->per_objfile
->objfile
));
9995 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9998 sect_offset sect_off
= attr
->get_ref_die_offset ();
9999 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10000 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10001 dwarf2_per_cu_data
*per_cu
10002 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10004 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10005 into another compilation unit, at root level. Regard this as a hint,
10007 if (die
->parent
&& die
->parent
->parent
== NULL
10008 && per_cu
->unit_type
== DW_UT_compile
10009 && per_cu
->lang
== language_cplus
)
10012 /* If necessary, add it to the queue and load its DIEs. */
10013 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10014 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
10016 cu
->per_cu
->imported_symtabs_push (per_cu
);
10020 /* RAII object that represents a process_die scope: i.e.,
10021 starts/finishes processing a DIE. */
10022 class process_die_scope
10025 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10026 : m_die (die
), m_cu (cu
)
10028 /* We should only be processing DIEs not already in process. */
10029 gdb_assert (!m_die
->in_process
);
10030 m_die
->in_process
= true;
10033 ~process_die_scope ()
10035 m_die
->in_process
= false;
10037 /* If we're done processing the DIE for the CU that owns the line
10038 header, we don't need the line header anymore. */
10039 if (m_cu
->line_header_die_owner
== m_die
)
10041 delete m_cu
->line_header
;
10042 m_cu
->line_header
= NULL
;
10043 m_cu
->line_header_die_owner
= NULL
;
10052 /* Process a die and its children. */
10055 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10057 process_die_scope
scope (die
, cu
);
10061 case DW_TAG_padding
:
10063 case DW_TAG_compile_unit
:
10064 case DW_TAG_partial_unit
:
10065 read_file_scope (die
, cu
);
10067 case DW_TAG_type_unit
:
10068 read_type_unit_scope (die
, cu
);
10070 case DW_TAG_subprogram
:
10071 /* Nested subprograms in Fortran get a prefix. */
10072 if (cu
->language
== language_fortran
10073 && die
->parent
!= NULL
10074 && die
->parent
->tag
== DW_TAG_subprogram
)
10075 cu
->processing_has_namespace_info
= true;
10076 /* Fall through. */
10077 case DW_TAG_inlined_subroutine
:
10078 read_func_scope (die
, cu
);
10080 case DW_TAG_lexical_block
:
10081 case DW_TAG_try_block
:
10082 case DW_TAG_catch_block
:
10083 read_lexical_block_scope (die
, cu
);
10085 case DW_TAG_call_site
:
10086 case DW_TAG_GNU_call_site
:
10087 read_call_site_scope (die
, cu
);
10089 case DW_TAG_class_type
:
10090 case DW_TAG_interface_type
:
10091 case DW_TAG_structure_type
:
10092 case DW_TAG_union_type
:
10093 process_structure_scope (die
, cu
);
10095 case DW_TAG_enumeration_type
:
10096 process_enumeration_scope (die
, cu
);
10099 /* These dies have a type, but processing them does not create
10100 a symbol or recurse to process the children. Therefore we can
10101 read them on-demand through read_type_die. */
10102 case DW_TAG_subroutine_type
:
10103 case DW_TAG_set_type
:
10104 case DW_TAG_array_type
:
10105 case DW_TAG_pointer_type
:
10106 case DW_TAG_ptr_to_member_type
:
10107 case DW_TAG_reference_type
:
10108 case DW_TAG_rvalue_reference_type
:
10109 case DW_TAG_string_type
:
10112 case DW_TAG_base_type
:
10113 case DW_TAG_subrange_type
:
10114 case DW_TAG_typedef
:
10115 /* Add a typedef symbol for the type definition, if it has a
10117 new_symbol (die
, read_type_die (die
, cu
), cu
);
10119 case DW_TAG_common_block
:
10120 read_common_block (die
, cu
);
10122 case DW_TAG_common_inclusion
:
10124 case DW_TAG_namespace
:
10125 cu
->processing_has_namespace_info
= true;
10126 read_namespace (die
, cu
);
10128 case DW_TAG_module
:
10129 cu
->processing_has_namespace_info
= true;
10130 read_module (die
, cu
);
10132 case DW_TAG_imported_declaration
:
10133 cu
->processing_has_namespace_info
= true;
10134 if (read_namespace_alias (die
, cu
))
10136 /* The declaration is not a global namespace alias. */
10137 /* Fall through. */
10138 case DW_TAG_imported_module
:
10139 cu
->processing_has_namespace_info
= true;
10140 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10141 || cu
->language
!= language_fortran
))
10142 complaint (_("Tag '%s' has unexpected children"),
10143 dwarf_tag_name (die
->tag
));
10144 read_import_statement (die
, cu
);
10147 case DW_TAG_imported_unit
:
10148 process_imported_unit_die (die
, cu
);
10151 case DW_TAG_variable
:
10152 read_variable (die
, cu
);
10156 new_symbol (die
, NULL
, cu
);
10161 /* DWARF name computation. */
10163 /* A helper function for dwarf2_compute_name which determines whether DIE
10164 needs to have the name of the scope prepended to the name listed in the
10168 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10170 struct attribute
*attr
;
10174 case DW_TAG_namespace
:
10175 case DW_TAG_typedef
:
10176 case DW_TAG_class_type
:
10177 case DW_TAG_interface_type
:
10178 case DW_TAG_structure_type
:
10179 case DW_TAG_union_type
:
10180 case DW_TAG_enumeration_type
:
10181 case DW_TAG_enumerator
:
10182 case DW_TAG_subprogram
:
10183 case DW_TAG_inlined_subroutine
:
10184 case DW_TAG_member
:
10185 case DW_TAG_imported_declaration
:
10188 case DW_TAG_variable
:
10189 case DW_TAG_constant
:
10190 /* We only need to prefix "globally" visible variables. These include
10191 any variable marked with DW_AT_external or any variable that
10192 lives in a namespace. [Variables in anonymous namespaces
10193 require prefixing, but they are not DW_AT_external.] */
10195 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10197 struct dwarf2_cu
*spec_cu
= cu
;
10199 return die_needs_namespace (die_specification (die
, &spec_cu
),
10203 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10204 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10205 && die
->parent
->tag
!= DW_TAG_module
)
10207 /* A variable in a lexical block of some kind does not need a
10208 namespace, even though in C++ such variables may be external
10209 and have a mangled name. */
10210 if (die
->parent
->tag
== DW_TAG_lexical_block
10211 || die
->parent
->tag
== DW_TAG_try_block
10212 || die
->parent
->tag
== DW_TAG_catch_block
10213 || die
->parent
->tag
== DW_TAG_subprogram
)
10222 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10223 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10224 defined for the given DIE. */
10226 static struct attribute
*
10227 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10229 struct attribute
*attr
;
10231 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10233 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10238 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10239 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10240 defined for the given DIE. */
10242 static const char *
10243 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10245 const char *linkage_name
;
10247 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10248 if (linkage_name
== NULL
)
10249 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10251 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10252 See https://github.com/rust-lang/rust/issues/32925. */
10253 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10254 && strchr (linkage_name
, '{') != NULL
)
10255 linkage_name
= NULL
;
10257 return linkage_name
;
10260 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10261 compute the physname for the object, which include a method's:
10262 - formal parameters (C++),
10263 - receiver type (Go),
10265 The term "physname" is a bit confusing.
10266 For C++, for example, it is the demangled name.
10267 For Go, for example, it's the mangled name.
10269 For Ada, return the DIE's linkage name rather than the fully qualified
10270 name. PHYSNAME is ignored..
10272 The result is allocated on the objfile->per_bfd's obstack and
10275 static const char *
10276 dwarf2_compute_name (const char *name
,
10277 struct die_info
*die
, struct dwarf2_cu
*cu
,
10280 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10283 name
= dwarf2_name (die
, cu
);
10285 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10286 but otherwise compute it by typename_concat inside GDB.
10287 FIXME: Actually this is not really true, or at least not always true.
10288 It's all very confusing. compute_and_set_names doesn't try to demangle
10289 Fortran names because there is no mangling standard. So new_symbol
10290 will set the demangled name to the result of dwarf2_full_name, and it is
10291 the demangled name that GDB uses if it exists. */
10292 if (cu
->language
== language_ada
10293 || (cu
->language
== language_fortran
&& physname
))
10295 /* For Ada unit, we prefer the linkage name over the name, as
10296 the former contains the exported name, which the user expects
10297 to be able to reference. Ideally, we want the user to be able
10298 to reference this entity using either natural or linkage name,
10299 but we haven't started looking at this enhancement yet. */
10300 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10302 if (linkage_name
!= NULL
)
10303 return linkage_name
;
10306 /* These are the only languages we know how to qualify names in. */
10308 && (cu
->language
== language_cplus
10309 || cu
->language
== language_fortran
|| cu
->language
== language_d
10310 || cu
->language
== language_rust
))
10312 if (die_needs_namespace (die
, cu
))
10314 const char *prefix
;
10315 const char *canonical_name
= NULL
;
10319 prefix
= determine_prefix (die
, cu
);
10320 if (*prefix
!= '\0')
10322 gdb::unique_xmalloc_ptr
<char> prefixed_name
10323 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10325 buf
.puts (prefixed_name
.get ());
10330 /* Template parameters may be specified in the DIE's DW_AT_name, or
10331 as children with DW_TAG_template_type_param or
10332 DW_TAG_value_type_param. If the latter, add them to the name
10333 here. If the name already has template parameters, then
10334 skip this step; some versions of GCC emit both, and
10335 it is more efficient to use the pre-computed name.
10337 Something to keep in mind about this process: it is very
10338 unlikely, or in some cases downright impossible, to produce
10339 something that will match the mangled name of a function.
10340 If the definition of the function has the same debug info,
10341 we should be able to match up with it anyway. But fallbacks
10342 using the minimal symbol, for instance to find a method
10343 implemented in a stripped copy of libstdc++, will not work.
10344 If we do not have debug info for the definition, we will have to
10345 match them up some other way.
10347 When we do name matching there is a related problem with function
10348 templates; two instantiated function templates are allowed to
10349 differ only by their return types, which we do not add here. */
10351 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10353 struct attribute
*attr
;
10354 struct die_info
*child
;
10357 die
->building_fullname
= 1;
10359 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10363 const gdb_byte
*bytes
;
10364 struct dwarf2_locexpr_baton
*baton
;
10367 if (child
->tag
!= DW_TAG_template_type_param
10368 && child
->tag
!= DW_TAG_template_value_param
)
10379 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10382 complaint (_("template parameter missing DW_AT_type"));
10383 buf
.puts ("UNKNOWN_TYPE");
10386 type
= die_type (child
, cu
);
10388 if (child
->tag
== DW_TAG_template_type_param
)
10390 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10391 &type_print_raw_options
);
10395 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10398 complaint (_("template parameter missing "
10399 "DW_AT_const_value"));
10400 buf
.puts ("UNKNOWN_VALUE");
10404 dwarf2_const_value_attr (attr
, type
, name
,
10405 &cu
->comp_unit_obstack
, cu
,
10406 &value
, &bytes
, &baton
);
10408 if (TYPE_NOSIGN (type
))
10409 /* GDB prints characters as NUMBER 'CHAR'. If that's
10410 changed, this can use value_print instead. */
10411 c_printchar (value
, type
, &buf
);
10414 struct value_print_options opts
;
10417 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10421 baton
->per_objfile
);
10422 else if (bytes
!= NULL
)
10424 v
= allocate_value (type
);
10425 memcpy (value_contents_writeable (v
), bytes
,
10426 TYPE_LENGTH (type
));
10429 v
= value_from_longest (type
, value
);
10431 /* Specify decimal so that we do not depend on
10433 get_formatted_print_options (&opts
, 'd');
10435 value_print (v
, &buf
, &opts
);
10440 die
->building_fullname
= 0;
10444 /* Close the argument list, with a space if necessary
10445 (nested templates). */
10446 if (!buf
.empty () && buf
.string ().back () == '>')
10453 /* For C++ methods, append formal parameter type
10454 information, if PHYSNAME. */
10456 if (physname
&& die
->tag
== DW_TAG_subprogram
10457 && cu
->language
== language_cplus
)
10459 struct type
*type
= read_type_die (die
, cu
);
10461 c_type_print_args (type
, &buf
, 1, cu
->language
,
10462 &type_print_raw_options
);
10464 if (cu
->language
== language_cplus
)
10466 /* Assume that an artificial first parameter is
10467 "this", but do not crash if it is not. RealView
10468 marks unnamed (and thus unused) parameters as
10469 artificial; there is no way to differentiate
10471 if (type
->num_fields () > 0
10472 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10473 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10474 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10476 buf
.puts (" const");
10480 const std::string
&intermediate_name
= buf
.string ();
10482 if (cu
->language
== language_cplus
)
10484 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10487 /* If we only computed INTERMEDIATE_NAME, or if
10488 INTERMEDIATE_NAME is already canonical, then we need to
10490 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10491 name
= objfile
->intern (intermediate_name
);
10493 name
= canonical_name
;
10500 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10501 If scope qualifiers are appropriate they will be added. The result
10502 will be allocated on the storage_obstack, or NULL if the DIE does
10503 not have a name. NAME may either be from a previous call to
10504 dwarf2_name or NULL.
10506 The output string will be canonicalized (if C++). */
10508 static const char *
10509 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10511 return dwarf2_compute_name (name
, die
, cu
, 0);
10514 /* Construct a physname for the given DIE in CU. NAME may either be
10515 from a previous call to dwarf2_name or NULL. The result will be
10516 allocated on the objfile_objstack or NULL if the DIE does not have a
10519 The output string will be canonicalized (if C++). */
10521 static const char *
10522 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10524 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10525 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10528 /* In this case dwarf2_compute_name is just a shortcut not building anything
10530 if (!die_needs_namespace (die
, cu
))
10531 return dwarf2_compute_name (name
, die
, cu
, 1);
10533 if (cu
->language
!= language_rust
)
10534 mangled
= dw2_linkage_name (die
, cu
);
10536 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10538 gdb::unique_xmalloc_ptr
<char> demangled
;
10539 if (mangled
!= NULL
)
10542 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10544 /* Do nothing (do not demangle the symbol name). */
10546 else if (cu
->language
== language_go
)
10548 /* This is a lie, but we already lie to the caller new_symbol.
10549 new_symbol assumes we return the mangled name.
10550 This just undoes that lie until things are cleaned up. */
10554 /* Use DMGL_RET_DROP for C++ template functions to suppress
10555 their return type. It is easier for GDB users to search
10556 for such functions as `name(params)' than `long name(params)'.
10557 In such case the minimal symbol names do not match the full
10558 symbol names but for template functions there is never a need
10559 to look up their definition from their declaration so
10560 the only disadvantage remains the minimal symbol variant
10561 `long name(params)' does not have the proper inferior type. */
10562 demangled
.reset (gdb_demangle (mangled
,
10563 (DMGL_PARAMS
| DMGL_ANSI
10564 | DMGL_RET_DROP
)));
10567 canon
= demangled
.get ();
10575 if (canon
== NULL
|| check_physname
)
10577 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10579 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10581 /* It may not mean a bug in GDB. The compiler could also
10582 compute DW_AT_linkage_name incorrectly. But in such case
10583 GDB would need to be bug-to-bug compatible. */
10585 complaint (_("Computed physname <%s> does not match demangled <%s> "
10586 "(from linkage <%s>) - DIE at %s [in module %s]"),
10587 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10588 objfile_name (objfile
));
10590 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10591 is available here - over computed PHYSNAME. It is safer
10592 against both buggy GDB and buggy compilers. */
10606 retval
= objfile
->intern (retval
);
10611 /* Inspect DIE in CU for a namespace alias. If one exists, record
10612 a new symbol for it.
10614 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10617 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10619 struct attribute
*attr
;
10621 /* If the die does not have a name, this is not a namespace
10623 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10627 struct die_info
*d
= die
;
10628 struct dwarf2_cu
*imported_cu
= cu
;
10630 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10631 keep inspecting DIEs until we hit the underlying import. */
10632 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10633 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10635 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10639 d
= follow_die_ref (d
, attr
, &imported_cu
);
10640 if (d
->tag
!= DW_TAG_imported_declaration
)
10644 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10646 complaint (_("DIE at %s has too many recursively imported "
10647 "declarations"), sect_offset_str (d
->sect_off
));
10654 sect_offset sect_off
= attr
->get_ref_die_offset ();
10656 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10657 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10659 /* This declaration is a global namespace alias. Add
10660 a symbol for it whose type is the aliased namespace. */
10661 new_symbol (die
, type
, cu
);
10670 /* Return the using directives repository (global or local?) to use in the
10671 current context for CU.
10673 For Ada, imported declarations can materialize renamings, which *may* be
10674 global. However it is impossible (for now?) in DWARF to distinguish
10675 "external" imported declarations and "static" ones. As all imported
10676 declarations seem to be static in all other languages, make them all CU-wide
10677 global only in Ada. */
10679 static struct using_direct
**
10680 using_directives (struct dwarf2_cu
*cu
)
10682 if (cu
->language
== language_ada
10683 && cu
->get_builder ()->outermost_context_p ())
10684 return cu
->get_builder ()->get_global_using_directives ();
10686 return cu
->get_builder ()->get_local_using_directives ();
10689 /* Read the import statement specified by the given die and record it. */
10692 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10694 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10695 struct attribute
*import_attr
;
10696 struct die_info
*imported_die
, *child_die
;
10697 struct dwarf2_cu
*imported_cu
;
10698 const char *imported_name
;
10699 const char *imported_name_prefix
;
10700 const char *canonical_name
;
10701 const char *import_alias
;
10702 const char *imported_declaration
= NULL
;
10703 const char *import_prefix
;
10704 std::vector
<const char *> excludes
;
10706 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10707 if (import_attr
== NULL
)
10709 complaint (_("Tag '%s' has no DW_AT_import"),
10710 dwarf_tag_name (die
->tag
));
10715 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10716 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10717 if (imported_name
== NULL
)
10719 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10721 The import in the following code:
10735 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10736 <52> DW_AT_decl_file : 1
10737 <53> DW_AT_decl_line : 6
10738 <54> DW_AT_import : <0x75>
10739 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10740 <59> DW_AT_name : B
10741 <5b> DW_AT_decl_file : 1
10742 <5c> DW_AT_decl_line : 2
10743 <5d> DW_AT_type : <0x6e>
10745 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10746 <76> DW_AT_byte_size : 4
10747 <77> DW_AT_encoding : 5 (signed)
10749 imports the wrong die ( 0x75 instead of 0x58 ).
10750 This case will be ignored until the gcc bug is fixed. */
10754 /* Figure out the local name after import. */
10755 import_alias
= dwarf2_name (die
, cu
);
10757 /* Figure out where the statement is being imported to. */
10758 import_prefix
= determine_prefix (die
, cu
);
10760 /* Figure out what the scope of the imported die is and prepend it
10761 to the name of the imported die. */
10762 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10764 if (imported_die
->tag
!= DW_TAG_namespace
10765 && imported_die
->tag
!= DW_TAG_module
)
10767 imported_declaration
= imported_name
;
10768 canonical_name
= imported_name_prefix
;
10770 else if (strlen (imported_name_prefix
) > 0)
10771 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10772 imported_name_prefix
,
10773 (cu
->language
== language_d
? "." : "::"),
10774 imported_name
, (char *) NULL
);
10776 canonical_name
= imported_name
;
10778 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10779 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10780 child_die
= child_die
->sibling
)
10782 /* DWARF-4: A Fortran use statement with a “rename list” may be
10783 represented by an imported module entry with an import attribute
10784 referring to the module and owned entries corresponding to those
10785 entities that are renamed as part of being imported. */
10787 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10789 complaint (_("child DW_TAG_imported_declaration expected "
10790 "- DIE at %s [in module %s]"),
10791 sect_offset_str (child_die
->sect_off
),
10792 objfile_name (objfile
));
10796 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10797 if (import_attr
== NULL
)
10799 complaint (_("Tag '%s' has no DW_AT_import"),
10800 dwarf_tag_name (child_die
->tag
));
10805 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10807 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10808 if (imported_name
== NULL
)
10810 complaint (_("child DW_TAG_imported_declaration has unknown "
10811 "imported name - DIE at %s [in module %s]"),
10812 sect_offset_str (child_die
->sect_off
),
10813 objfile_name (objfile
));
10817 excludes
.push_back (imported_name
);
10819 process_die (child_die
, cu
);
10822 add_using_directive (using_directives (cu
),
10826 imported_declaration
,
10829 &objfile
->objfile_obstack
);
10832 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10833 types, but gives them a size of zero. Starting with version 14,
10834 ICC is compatible with GCC. */
10837 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10839 if (!cu
->checked_producer
)
10840 check_producer (cu
);
10842 return cu
->producer_is_icc_lt_14
;
10845 /* ICC generates a DW_AT_type for C void functions. This was observed on
10846 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10847 which says that void functions should not have a DW_AT_type. */
10850 producer_is_icc (struct dwarf2_cu
*cu
)
10852 if (!cu
->checked_producer
)
10853 check_producer (cu
);
10855 return cu
->producer_is_icc
;
10858 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10859 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10860 this, it was first present in GCC release 4.3.0. */
10863 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10865 if (!cu
->checked_producer
)
10866 check_producer (cu
);
10868 return cu
->producer_is_gcc_lt_4_3
;
10871 static file_and_directory
10872 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10874 file_and_directory res
;
10876 /* Find the filename. Do not use dwarf2_name here, since the filename
10877 is not a source language identifier. */
10878 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10879 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10881 if (res
.comp_dir
== NULL
10882 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10883 && IS_ABSOLUTE_PATH (res
.name
))
10885 res
.comp_dir_storage
= ldirname (res
.name
);
10886 if (!res
.comp_dir_storage
.empty ())
10887 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10889 if (res
.comp_dir
!= NULL
)
10891 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10892 directory, get rid of it. */
10893 const char *cp
= strchr (res
.comp_dir
, ':');
10895 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10896 res
.comp_dir
= cp
+ 1;
10899 if (res
.name
== NULL
)
10900 res
.name
= "<unknown>";
10905 /* Handle DW_AT_stmt_list for a compilation unit.
10906 DIE is the DW_TAG_compile_unit die for CU.
10907 COMP_DIR is the compilation directory. LOWPC is passed to
10908 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10911 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10912 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10914 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10915 struct attribute
*attr
;
10916 struct line_header line_header_local
;
10917 hashval_t line_header_local_hash
;
10919 int decode_mapping
;
10921 gdb_assert (! cu
->per_cu
->is_debug_types
);
10923 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10927 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10929 /* The line header hash table is only created if needed (it exists to
10930 prevent redundant reading of the line table for partial_units).
10931 If we're given a partial_unit, we'll need it. If we're given a
10932 compile_unit, then use the line header hash table if it's already
10933 created, but don't create one just yet. */
10935 if (per_objfile
->line_header_hash
== NULL
10936 && die
->tag
== DW_TAG_partial_unit
)
10938 per_objfile
->line_header_hash
10939 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10940 line_header_eq_voidp
,
10941 free_line_header_voidp
,
10945 line_header_local
.sect_off
= line_offset
;
10946 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10947 line_header_local_hash
= line_header_hash (&line_header_local
);
10948 if (per_objfile
->line_header_hash
!= NULL
)
10950 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10951 &line_header_local
,
10952 line_header_local_hash
, NO_INSERT
);
10954 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10955 is not present in *SLOT (since if there is something in *SLOT then
10956 it will be for a partial_unit). */
10957 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10959 gdb_assert (*slot
!= NULL
);
10960 cu
->line_header
= (struct line_header
*) *slot
;
10965 /* dwarf_decode_line_header does not yet provide sufficient information.
10966 We always have to call also dwarf_decode_lines for it. */
10967 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10971 cu
->line_header
= lh
.release ();
10972 cu
->line_header_die_owner
= die
;
10974 if (per_objfile
->line_header_hash
== NULL
)
10978 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10979 &line_header_local
,
10980 line_header_local_hash
, INSERT
);
10981 gdb_assert (slot
!= NULL
);
10983 if (slot
!= NULL
&& *slot
== NULL
)
10985 /* This newly decoded line number information unit will be owned
10986 by line_header_hash hash table. */
10987 *slot
= cu
->line_header
;
10988 cu
->line_header_die_owner
= NULL
;
10992 /* We cannot free any current entry in (*slot) as that struct line_header
10993 may be already used by multiple CUs. Create only temporary decoded
10994 line_header for this CU - it may happen at most once for each line
10995 number information unit. And if we're not using line_header_hash
10996 then this is what we want as well. */
10997 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10999 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11000 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11005 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11008 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11010 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11011 struct objfile
*objfile
= per_objfile
->objfile
;
11012 struct gdbarch
*gdbarch
= objfile
->arch ();
11013 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11014 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11015 struct attribute
*attr
;
11016 struct die_info
*child_die
;
11017 CORE_ADDR baseaddr
;
11019 prepare_one_comp_unit (cu
, die
, cu
->language
);
11020 baseaddr
= objfile
->text_section_offset ();
11022 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11024 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11025 from finish_block. */
11026 if (lowpc
== ((CORE_ADDR
) -1))
11028 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11030 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11032 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11033 standardised yet. As a workaround for the language detection we fall
11034 back to the DW_AT_producer string. */
11035 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11036 cu
->language
= language_opencl
;
11038 /* Similar hack for Go. */
11039 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11040 set_cu_language (DW_LANG_Go
, cu
);
11042 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11044 /* Decode line number information if present. We do this before
11045 processing child DIEs, so that the line header table is available
11046 for DW_AT_decl_file. */
11047 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11049 /* Process all dies in compilation unit. */
11050 if (die
->child
!= NULL
)
11052 child_die
= die
->child
;
11053 while (child_die
&& child_die
->tag
)
11055 process_die (child_die
, cu
);
11056 child_die
= child_die
->sibling
;
11060 /* Decode macro information, if present. Dwarf 2 macro information
11061 refers to information in the line number info statement program
11062 header, so we can only read it if we've read the header
11064 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11066 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11067 if (attr
&& cu
->line_header
)
11069 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11070 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11072 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11076 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11077 if (attr
&& cu
->line_header
)
11079 unsigned int macro_offset
= DW_UNSND (attr
);
11081 dwarf_decode_macros (cu
, macro_offset
, 0);
11087 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11089 struct type_unit_group
*tu_group
;
11091 struct attribute
*attr
;
11093 struct signatured_type
*sig_type
;
11095 gdb_assert (per_cu
->is_debug_types
);
11096 sig_type
= (struct signatured_type
*) per_cu
;
11098 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11100 /* If we're using .gdb_index (includes -readnow) then
11101 per_cu->type_unit_group may not have been set up yet. */
11102 if (sig_type
->type_unit_group
== NULL
)
11103 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11104 tu_group
= sig_type
->type_unit_group
;
11106 /* If we've already processed this stmt_list there's no real need to
11107 do it again, we could fake it and just recreate the part we need
11108 (file name,index -> symtab mapping). If data shows this optimization
11109 is useful we can do it then. */
11110 type_unit_group_unshareable
*tug_unshare
11111 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11112 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11114 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11119 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11120 lh
= dwarf_decode_line_header (line_offset
, this);
11125 start_symtab ("", NULL
, 0);
11128 gdb_assert (tug_unshare
->symtabs
== NULL
);
11129 gdb_assert (m_builder
== nullptr);
11130 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11131 m_builder
.reset (new struct buildsym_compunit
11132 (COMPUNIT_OBJFILE (cust
), "",
11133 COMPUNIT_DIRNAME (cust
),
11134 compunit_language (cust
),
11136 list_in_scope
= get_builder ()->get_file_symbols ();
11141 line_header
= lh
.release ();
11142 line_header_die_owner
= die
;
11146 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11148 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11149 still initializing it, and our caller (a few levels up)
11150 process_full_type_unit still needs to know if this is the first
11153 tug_unshare
->symtabs
11154 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11155 struct symtab
*, line_header
->file_names_size ());
11157 auto &file_names
= line_header
->file_names ();
11158 for (i
= 0; i
< file_names
.size (); ++i
)
11160 file_entry
&fe
= file_names
[i
];
11161 dwarf2_start_subfile (this, fe
.name
,
11162 fe
.include_dir (line_header
));
11163 buildsym_compunit
*b
= get_builder ();
11164 if (b
->get_current_subfile ()->symtab
== NULL
)
11166 /* NOTE: start_subfile will recognize when it's been
11167 passed a file it has already seen. So we can't
11168 assume there's a simple mapping from
11169 cu->line_header->file_names to subfiles, plus
11170 cu->line_header->file_names may contain dups. */
11171 b
->get_current_subfile ()->symtab
11172 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11175 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11176 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11181 gdb_assert (m_builder
== nullptr);
11182 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11183 m_builder
.reset (new struct buildsym_compunit
11184 (COMPUNIT_OBJFILE (cust
), "",
11185 COMPUNIT_DIRNAME (cust
),
11186 compunit_language (cust
),
11188 list_in_scope
= get_builder ()->get_file_symbols ();
11190 auto &file_names
= line_header
->file_names ();
11191 for (i
= 0; i
< file_names
.size (); ++i
)
11193 file_entry
&fe
= file_names
[i
];
11194 fe
.symtab
= tug_unshare
->symtabs
[i
];
11198 /* The main symtab is allocated last. Type units don't have DW_AT_name
11199 so they don't have a "real" (so to speak) symtab anyway.
11200 There is later code that will assign the main symtab to all symbols
11201 that don't have one. We need to handle the case of a symbol with a
11202 missing symtab (DW_AT_decl_file) anyway. */
11205 /* Process DW_TAG_type_unit.
11206 For TUs we want to skip the first top level sibling if it's not the
11207 actual type being defined by this TU. In this case the first top
11208 level sibling is there to provide context only. */
11211 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11213 struct die_info
*child_die
;
11215 prepare_one_comp_unit (cu
, die
, language_minimal
);
11217 /* Initialize (or reinitialize) the machinery for building symtabs.
11218 We do this before processing child DIEs, so that the line header table
11219 is available for DW_AT_decl_file. */
11220 cu
->setup_type_unit_groups (die
);
11222 if (die
->child
!= NULL
)
11224 child_die
= die
->child
;
11225 while (child_die
&& child_die
->tag
)
11227 process_die (child_die
, cu
);
11228 child_die
= child_die
->sibling
;
11235 http://gcc.gnu.org/wiki/DebugFission
11236 http://gcc.gnu.org/wiki/DebugFissionDWP
11238 To simplify handling of both DWO files ("object" files with the DWARF info)
11239 and DWP files (a file with the DWOs packaged up into one file), we treat
11240 DWP files as having a collection of virtual DWO files. */
11243 hash_dwo_file (const void *item
)
11245 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11248 hash
= htab_hash_string (dwo_file
->dwo_name
);
11249 if (dwo_file
->comp_dir
!= NULL
)
11250 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11255 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11257 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11258 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11260 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11262 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11263 return lhs
->comp_dir
== rhs
->comp_dir
;
11264 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11267 /* Allocate a hash table for DWO files. */
11270 allocate_dwo_file_hash_table ()
11272 auto delete_dwo_file
= [] (void *item
)
11274 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11279 return htab_up (htab_create_alloc (41,
11286 /* Lookup DWO file DWO_NAME. */
11289 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11290 const char *dwo_name
,
11291 const char *comp_dir
)
11293 struct dwo_file find_entry
;
11296 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11297 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11299 find_entry
.dwo_name
= dwo_name
;
11300 find_entry
.comp_dir
= comp_dir
;
11301 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11308 hash_dwo_unit (const void *item
)
11310 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11312 /* This drops the top 32 bits of the id, but is ok for a hash. */
11313 return dwo_unit
->signature
;
11317 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11319 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11320 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11322 /* The signature is assumed to be unique within the DWO file.
11323 So while object file CU dwo_id's always have the value zero,
11324 that's OK, assuming each object file DWO file has only one CU,
11325 and that's the rule for now. */
11326 return lhs
->signature
== rhs
->signature
;
11329 /* Allocate a hash table for DWO CUs,TUs.
11330 There is one of these tables for each of CUs,TUs for each DWO file. */
11333 allocate_dwo_unit_table ()
11335 /* Start out with a pretty small number.
11336 Generally DWO files contain only one CU and maybe some TUs. */
11337 return htab_up (htab_create_alloc (3,
11340 NULL
, xcalloc
, xfree
));
11343 /* die_reader_func for create_dwo_cu. */
11346 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11347 const gdb_byte
*info_ptr
,
11348 struct die_info
*comp_unit_die
,
11349 struct dwo_file
*dwo_file
,
11350 struct dwo_unit
*dwo_unit
)
11352 struct dwarf2_cu
*cu
= reader
->cu
;
11353 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11354 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11356 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11357 if (!signature
.has_value ())
11359 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11360 " its dwo_id [in module %s]"),
11361 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11365 dwo_unit
->dwo_file
= dwo_file
;
11366 dwo_unit
->signature
= *signature
;
11367 dwo_unit
->section
= section
;
11368 dwo_unit
->sect_off
= sect_off
;
11369 dwo_unit
->length
= cu
->per_cu
->length
;
11371 if (dwarf_read_debug
)
11372 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11373 sect_offset_str (sect_off
),
11374 hex_string (dwo_unit
->signature
));
11377 /* Create the dwo_units for the CUs in a DWO_FILE.
11378 Note: This function processes DWO files only, not DWP files. */
11381 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11382 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11383 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11385 struct objfile
*objfile
= per_objfile
->objfile
;
11386 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11387 const gdb_byte
*info_ptr
, *end_ptr
;
11389 section
.read (objfile
);
11390 info_ptr
= section
.buffer
;
11392 if (info_ptr
== NULL
)
11395 if (dwarf_read_debug
)
11397 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11398 section
.get_name (),
11399 section
.get_file_name ());
11402 end_ptr
= info_ptr
+ section
.size
;
11403 while (info_ptr
< end_ptr
)
11405 struct dwarf2_per_cu_data per_cu
;
11406 struct dwo_unit read_unit
{};
11407 struct dwo_unit
*dwo_unit
;
11409 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11411 memset (&per_cu
, 0, sizeof (per_cu
));
11412 per_cu
.per_bfd
= per_bfd
;
11413 per_cu
.is_debug_types
= 0;
11414 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11415 per_cu
.section
= §ion
;
11417 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11418 if (!reader
.dummy_p
)
11419 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11420 &dwo_file
, &read_unit
);
11421 info_ptr
+= per_cu
.length
;
11423 // If the unit could not be parsed, skip it.
11424 if (read_unit
.dwo_file
== NULL
)
11427 if (cus_htab
== NULL
)
11428 cus_htab
= allocate_dwo_unit_table ();
11430 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11432 *dwo_unit
= read_unit
;
11433 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11434 gdb_assert (slot
!= NULL
);
11437 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11438 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11440 complaint (_("debug cu entry at offset %s is duplicate to"
11441 " the entry at offset %s, signature %s"),
11442 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11443 hex_string (dwo_unit
->signature
));
11445 *slot
= (void *)dwo_unit
;
11449 /* DWP file .debug_{cu,tu}_index section format:
11450 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11454 Both index sections have the same format, and serve to map a 64-bit
11455 signature to a set of section numbers. Each section begins with a header,
11456 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11457 indexes, and a pool of 32-bit section numbers. The index sections will be
11458 aligned at 8-byte boundaries in the file.
11460 The index section header consists of:
11462 V, 32 bit version number
11464 N, 32 bit number of compilation units or type units in the index
11465 M, 32 bit number of slots in the hash table
11467 Numbers are recorded using the byte order of the application binary.
11469 The hash table begins at offset 16 in the section, and consists of an array
11470 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11471 order of the application binary). Unused slots in the hash table are 0.
11472 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11474 The parallel table begins immediately after the hash table
11475 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11476 array of 32-bit indexes (using the byte order of the application binary),
11477 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11478 table contains a 32-bit index into the pool of section numbers. For unused
11479 hash table slots, the corresponding entry in the parallel table will be 0.
11481 The pool of section numbers begins immediately following the hash table
11482 (at offset 16 + 12 * M from the beginning of the section). The pool of
11483 section numbers consists of an array of 32-bit words (using the byte order
11484 of the application binary). Each item in the array is indexed starting
11485 from 0. The hash table entry provides the index of the first section
11486 number in the set. Additional section numbers in the set follow, and the
11487 set is terminated by a 0 entry (section number 0 is not used in ELF).
11489 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11490 section must be the first entry in the set, and the .debug_abbrev.dwo must
11491 be the second entry. Other members of the set may follow in any order.
11497 DWP Version 2 combines all the .debug_info, etc. sections into one,
11498 and the entries in the index tables are now offsets into these sections.
11499 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11502 Index Section Contents:
11504 Hash Table of Signatures dwp_hash_table.hash_table
11505 Parallel Table of Indices dwp_hash_table.unit_table
11506 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11507 Table of Section Sizes dwp_hash_table.v2.sizes
11509 The index section header consists of:
11511 V, 32 bit version number
11512 L, 32 bit number of columns in the table of section offsets
11513 N, 32 bit number of compilation units or type units in the index
11514 M, 32 bit number of slots in the hash table
11516 Numbers are recorded using the byte order of the application binary.
11518 The hash table has the same format as version 1.
11519 The parallel table of indices has the same format as version 1,
11520 except that the entries are origin-1 indices into the table of sections
11521 offsets and the table of section sizes.
11523 The table of offsets begins immediately following the parallel table
11524 (at offset 16 + 12 * M from the beginning of the section). The table is
11525 a two-dimensional array of 32-bit words (using the byte order of the
11526 application binary), with L columns and N+1 rows, in row-major order.
11527 Each row in the array is indexed starting from 0. The first row provides
11528 a key to the remaining rows: each column in this row provides an identifier
11529 for a debug section, and the offsets in the same column of subsequent rows
11530 refer to that section. The section identifiers are:
11532 DW_SECT_INFO 1 .debug_info.dwo
11533 DW_SECT_TYPES 2 .debug_types.dwo
11534 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11535 DW_SECT_LINE 4 .debug_line.dwo
11536 DW_SECT_LOC 5 .debug_loc.dwo
11537 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11538 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11539 DW_SECT_MACRO 8 .debug_macro.dwo
11541 The offsets provided by the CU and TU index sections are the base offsets
11542 for the contributions made by each CU or TU to the corresponding section
11543 in the package file. Each CU and TU header contains an abbrev_offset
11544 field, used to find the abbreviations table for that CU or TU within the
11545 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11546 be interpreted as relative to the base offset given in the index section.
11547 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11548 should be interpreted as relative to the base offset for .debug_line.dwo,
11549 and offsets into other debug sections obtained from DWARF attributes should
11550 also be interpreted as relative to the corresponding base offset.
11552 The table of sizes begins immediately following the table of offsets.
11553 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11554 with L columns and N rows, in row-major order. Each row in the array is
11555 indexed starting from 1 (row 0 is shared by the two tables).
11559 Hash table lookup is handled the same in version 1 and 2:
11561 We assume that N and M will not exceed 2^32 - 1.
11562 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11564 Given a 64-bit compilation unit signature or a type signature S, an entry
11565 in the hash table is located as follows:
11567 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11568 the low-order k bits all set to 1.
11570 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11572 3) If the hash table entry at index H matches the signature, use that
11573 entry. If the hash table entry at index H is unused (all zeroes),
11574 terminate the search: the signature is not present in the table.
11576 4) Let H = (H + H') modulo M. Repeat at Step 3.
11578 Because M > N and H' and M are relatively prime, the search is guaranteed
11579 to stop at an unused slot or find the match. */
11581 /* Create a hash table to map DWO IDs to their CU/TU entry in
11582 .debug_{info,types}.dwo in DWP_FILE.
11583 Returns NULL if there isn't one.
11584 Note: This function processes DWP files only, not DWO files. */
11586 static struct dwp_hash_table
*
11587 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11588 struct dwp_file
*dwp_file
, int is_debug_types
)
11590 struct objfile
*objfile
= per_objfile
->objfile
;
11591 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11592 const gdb_byte
*index_ptr
, *index_end
;
11593 struct dwarf2_section_info
*index
;
11594 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11595 struct dwp_hash_table
*htab
;
11597 if (is_debug_types
)
11598 index
= &dwp_file
->sections
.tu_index
;
11600 index
= &dwp_file
->sections
.cu_index
;
11602 if (index
->empty ())
11604 index
->read (objfile
);
11606 index_ptr
= index
->buffer
;
11607 index_end
= index_ptr
+ index
->size
;
11609 version
= read_4_bytes (dbfd
, index_ptr
);
11612 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11616 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11618 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11621 if (version
!= 1 && version
!= 2)
11623 error (_("Dwarf Error: unsupported DWP file version (%s)"
11624 " [in module %s]"),
11625 pulongest (version
), dwp_file
->name
);
11627 if (nr_slots
!= (nr_slots
& -nr_slots
))
11629 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11630 " is not power of 2 [in module %s]"),
11631 pulongest (nr_slots
), dwp_file
->name
);
11634 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11635 htab
->version
= version
;
11636 htab
->nr_columns
= nr_columns
;
11637 htab
->nr_units
= nr_units
;
11638 htab
->nr_slots
= nr_slots
;
11639 htab
->hash_table
= index_ptr
;
11640 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11642 /* Exit early if the table is empty. */
11643 if (nr_slots
== 0 || nr_units
== 0
11644 || (version
== 2 && nr_columns
== 0))
11646 /* All must be zero. */
11647 if (nr_slots
!= 0 || nr_units
!= 0
11648 || (version
== 2 && nr_columns
!= 0))
11650 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11651 " all zero [in modules %s]"),
11659 htab
->section_pool
.v1
.indices
=
11660 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11661 /* It's harder to decide whether the section is too small in v1.
11662 V1 is deprecated anyway so we punt. */
11666 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11667 int *ids
= htab
->section_pool
.v2
.section_ids
;
11668 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11669 /* Reverse map for error checking. */
11670 int ids_seen
[DW_SECT_MAX
+ 1];
11673 if (nr_columns
< 2)
11675 error (_("Dwarf Error: bad DWP hash table, too few columns"
11676 " in section table [in module %s]"),
11679 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11681 error (_("Dwarf Error: bad DWP hash table, too many columns"
11682 " in section table [in module %s]"),
11685 memset (ids
, 255, sizeof_ids
);
11686 memset (ids_seen
, 255, sizeof (ids_seen
));
11687 for (i
= 0; i
< nr_columns
; ++i
)
11689 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11691 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11693 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11694 " in section table [in module %s]"),
11695 id
, dwp_file
->name
);
11697 if (ids_seen
[id
] != -1)
11699 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11700 " id %d in section table [in module %s]"),
11701 id
, dwp_file
->name
);
11706 /* Must have exactly one info or types section. */
11707 if (((ids_seen
[DW_SECT_INFO
] != -1)
11708 + (ids_seen
[DW_SECT_TYPES
] != -1))
11711 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11712 " DWO info/types section [in module %s]"),
11715 /* Must have an abbrev section. */
11716 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11718 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11719 " section [in module %s]"),
11722 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11723 htab
->section_pool
.v2
.sizes
=
11724 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11725 * nr_units
* nr_columns
);
11726 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11727 * nr_units
* nr_columns
))
11730 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11731 " [in module %s]"),
11739 /* Update SECTIONS with the data from SECTP.
11741 This function is like the other "locate" section routines that are
11742 passed to bfd_map_over_sections, but in this context the sections to
11743 read comes from the DWP V1 hash table, not the full ELF section table.
11745 The result is non-zero for success, or zero if an error was found. */
11748 locate_v1_virtual_dwo_sections (asection
*sectp
,
11749 struct virtual_v1_dwo_sections
*sections
)
11751 const struct dwop_section_names
*names
= &dwop_section_names
;
11753 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11755 /* There can be only one. */
11756 if (sections
->abbrev
.s
.section
!= NULL
)
11758 sections
->abbrev
.s
.section
= sectp
;
11759 sections
->abbrev
.size
= bfd_section_size (sectp
);
11761 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11762 || section_is_p (sectp
->name
, &names
->types_dwo
))
11764 /* There can be only one. */
11765 if (sections
->info_or_types
.s
.section
!= NULL
)
11767 sections
->info_or_types
.s
.section
= sectp
;
11768 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11770 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11772 /* There can be only one. */
11773 if (sections
->line
.s
.section
!= NULL
)
11775 sections
->line
.s
.section
= sectp
;
11776 sections
->line
.size
= bfd_section_size (sectp
);
11778 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11780 /* There can be only one. */
11781 if (sections
->loc
.s
.section
!= NULL
)
11783 sections
->loc
.s
.section
= sectp
;
11784 sections
->loc
.size
= bfd_section_size (sectp
);
11786 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11788 /* There can be only one. */
11789 if (sections
->macinfo
.s
.section
!= NULL
)
11791 sections
->macinfo
.s
.section
= sectp
;
11792 sections
->macinfo
.size
= bfd_section_size (sectp
);
11794 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11796 /* There can be only one. */
11797 if (sections
->macro
.s
.section
!= NULL
)
11799 sections
->macro
.s
.section
= sectp
;
11800 sections
->macro
.size
= bfd_section_size (sectp
);
11802 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11804 /* There can be only one. */
11805 if (sections
->str_offsets
.s
.section
!= NULL
)
11807 sections
->str_offsets
.s
.section
= sectp
;
11808 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11812 /* No other kind of section is valid. */
11819 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11820 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11821 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11822 This is for DWP version 1 files. */
11824 static struct dwo_unit
*
11825 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11826 struct dwp_file
*dwp_file
,
11827 uint32_t unit_index
,
11828 const char *comp_dir
,
11829 ULONGEST signature
, int is_debug_types
)
11831 const struct dwp_hash_table
*dwp_htab
=
11832 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11833 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11834 const char *kind
= is_debug_types
? "TU" : "CU";
11835 struct dwo_file
*dwo_file
;
11836 struct dwo_unit
*dwo_unit
;
11837 struct virtual_v1_dwo_sections sections
;
11838 void **dwo_file_slot
;
11841 gdb_assert (dwp_file
->version
== 1);
11843 if (dwarf_read_debug
)
11845 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11847 pulongest (unit_index
), hex_string (signature
),
11851 /* Fetch the sections of this DWO unit.
11852 Put a limit on the number of sections we look for so that bad data
11853 doesn't cause us to loop forever. */
11855 #define MAX_NR_V1_DWO_SECTIONS \
11856 (1 /* .debug_info or .debug_types */ \
11857 + 1 /* .debug_abbrev */ \
11858 + 1 /* .debug_line */ \
11859 + 1 /* .debug_loc */ \
11860 + 1 /* .debug_str_offsets */ \
11861 + 1 /* .debug_macro or .debug_macinfo */ \
11862 + 1 /* trailing zero */)
11864 memset (§ions
, 0, sizeof (sections
));
11866 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11869 uint32_t section_nr
=
11870 read_4_bytes (dbfd
,
11871 dwp_htab
->section_pool
.v1
.indices
11872 + (unit_index
+ i
) * sizeof (uint32_t));
11874 if (section_nr
== 0)
11876 if (section_nr
>= dwp_file
->num_sections
)
11878 error (_("Dwarf Error: bad DWP hash table, section number too large"
11879 " [in module %s]"),
11883 sectp
= dwp_file
->elf_sections
[section_nr
];
11884 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11886 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11887 " [in module %s]"),
11893 || sections
.info_or_types
.empty ()
11894 || sections
.abbrev
.empty ())
11896 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11897 " [in module %s]"),
11900 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11902 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11903 " [in module %s]"),
11907 /* It's easier for the rest of the code if we fake a struct dwo_file and
11908 have dwo_unit "live" in that. At least for now.
11910 The DWP file can be made up of a random collection of CUs and TUs.
11911 However, for each CU + set of TUs that came from the same original DWO
11912 file, we can combine them back into a virtual DWO file to save space
11913 (fewer struct dwo_file objects to allocate). Remember that for really
11914 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11916 std::string virtual_dwo_name
=
11917 string_printf ("virtual-dwo/%d-%d-%d-%d",
11918 sections
.abbrev
.get_id (),
11919 sections
.line
.get_id (),
11920 sections
.loc
.get_id (),
11921 sections
.str_offsets
.get_id ());
11922 /* Can we use an existing virtual DWO file? */
11923 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11925 /* Create one if necessary. */
11926 if (*dwo_file_slot
== NULL
)
11928 if (dwarf_read_debug
)
11930 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11931 virtual_dwo_name
.c_str ());
11933 dwo_file
= new struct dwo_file
;
11934 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11935 dwo_file
->comp_dir
= comp_dir
;
11936 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11937 dwo_file
->sections
.line
= sections
.line
;
11938 dwo_file
->sections
.loc
= sections
.loc
;
11939 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11940 dwo_file
->sections
.macro
= sections
.macro
;
11941 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11942 /* The "str" section is global to the entire DWP file. */
11943 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11944 /* The info or types section is assigned below to dwo_unit,
11945 there's no need to record it in dwo_file.
11946 Also, we can't simply record type sections in dwo_file because
11947 we record a pointer into the vector in dwo_unit. As we collect more
11948 types we'll grow the vector and eventually have to reallocate space
11949 for it, invalidating all copies of pointers into the previous
11951 *dwo_file_slot
= dwo_file
;
11955 if (dwarf_read_debug
)
11957 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11958 virtual_dwo_name
.c_str ());
11960 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11963 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11964 dwo_unit
->dwo_file
= dwo_file
;
11965 dwo_unit
->signature
= signature
;
11966 dwo_unit
->section
=
11967 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11968 *dwo_unit
->section
= sections
.info_or_types
;
11969 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11974 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11975 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11976 piece within that section used by a TU/CU, return a virtual section
11977 of just that piece. */
11979 static struct dwarf2_section_info
11980 create_dwp_v2_section (dwarf2_per_objfile
*per_objfile
,
11981 struct dwarf2_section_info
*section
,
11982 bfd_size_type offset
, bfd_size_type size
)
11984 struct dwarf2_section_info result
;
11987 gdb_assert (section
!= NULL
);
11988 gdb_assert (!section
->is_virtual
);
11990 memset (&result
, 0, sizeof (result
));
11991 result
.s
.containing_section
= section
;
11992 result
.is_virtual
= true;
11997 sectp
= section
->get_bfd_section ();
11999 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12000 bounds of the real section. This is a pretty-rare event, so just
12001 flag an error (easier) instead of a warning and trying to cope. */
12003 || offset
+ size
> bfd_section_size (sectp
))
12005 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12006 " in section %s [in module %s]"),
12007 sectp
? bfd_section_name (sectp
) : "<unknown>",
12008 objfile_name (per_objfile
->objfile
));
12011 result
.virtual_offset
= offset
;
12012 result
.size
= size
;
12016 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12017 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12018 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12019 This is for DWP version 2 files. */
12021 static struct dwo_unit
*
12022 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12023 struct dwp_file
*dwp_file
,
12024 uint32_t unit_index
,
12025 const char *comp_dir
,
12026 ULONGEST signature
, int is_debug_types
)
12028 const struct dwp_hash_table
*dwp_htab
=
12029 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12030 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12031 const char *kind
= is_debug_types
? "TU" : "CU";
12032 struct dwo_file
*dwo_file
;
12033 struct dwo_unit
*dwo_unit
;
12034 struct virtual_v2_dwo_sections sections
;
12035 void **dwo_file_slot
;
12038 gdb_assert (dwp_file
->version
== 2);
12040 if (dwarf_read_debug
)
12042 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12044 pulongest (unit_index
), hex_string (signature
),
12048 /* Fetch the section offsets of this DWO unit. */
12050 memset (§ions
, 0, sizeof (sections
));
12052 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12054 uint32_t offset
= read_4_bytes (dbfd
,
12055 dwp_htab
->section_pool
.v2
.offsets
12056 + (((unit_index
- 1) * dwp_htab
->nr_columns
12058 * sizeof (uint32_t)));
12059 uint32_t size
= read_4_bytes (dbfd
,
12060 dwp_htab
->section_pool
.v2
.sizes
12061 + (((unit_index
- 1) * dwp_htab
->nr_columns
12063 * sizeof (uint32_t)));
12065 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12068 case DW_SECT_TYPES
:
12069 sections
.info_or_types_offset
= offset
;
12070 sections
.info_or_types_size
= size
;
12072 case DW_SECT_ABBREV
:
12073 sections
.abbrev_offset
= offset
;
12074 sections
.abbrev_size
= size
;
12077 sections
.line_offset
= offset
;
12078 sections
.line_size
= size
;
12081 sections
.loc_offset
= offset
;
12082 sections
.loc_size
= size
;
12084 case DW_SECT_STR_OFFSETS
:
12085 sections
.str_offsets_offset
= offset
;
12086 sections
.str_offsets_size
= size
;
12088 case DW_SECT_MACINFO
:
12089 sections
.macinfo_offset
= offset
;
12090 sections
.macinfo_size
= size
;
12092 case DW_SECT_MACRO
:
12093 sections
.macro_offset
= offset
;
12094 sections
.macro_size
= size
;
12099 /* It's easier for the rest of the code if we fake a struct dwo_file and
12100 have dwo_unit "live" in that. At least for now.
12102 The DWP file can be made up of a random collection of CUs and TUs.
12103 However, for each CU + set of TUs that came from the same original DWO
12104 file, we can combine them back into a virtual DWO file to save space
12105 (fewer struct dwo_file objects to allocate). Remember that for really
12106 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12108 std::string virtual_dwo_name
=
12109 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12110 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12111 (long) (sections
.line_size
? sections
.line_offset
: 0),
12112 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12113 (long) (sections
.str_offsets_size
12114 ? sections
.str_offsets_offset
: 0));
12115 /* Can we use an existing virtual DWO file? */
12116 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12118 /* Create one if necessary. */
12119 if (*dwo_file_slot
== NULL
)
12121 if (dwarf_read_debug
)
12123 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12124 virtual_dwo_name
.c_str ());
12126 dwo_file
= new struct dwo_file
;
12127 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12128 dwo_file
->comp_dir
= comp_dir
;
12129 dwo_file
->sections
.abbrev
=
12130 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12131 sections
.abbrev_offset
, sections
.abbrev_size
);
12132 dwo_file
->sections
.line
=
12133 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.line
,
12134 sections
.line_offset
, sections
.line_size
);
12135 dwo_file
->sections
.loc
=
12136 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.loc
,
12137 sections
.loc_offset
, sections
.loc_size
);
12138 dwo_file
->sections
.macinfo
=
12139 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12140 sections
.macinfo_offset
, sections
.macinfo_size
);
12141 dwo_file
->sections
.macro
=
12142 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macro
,
12143 sections
.macro_offset
, sections
.macro_size
);
12144 dwo_file
->sections
.str_offsets
=
12145 create_dwp_v2_section (per_objfile
,
12146 &dwp_file
->sections
.str_offsets
,
12147 sections
.str_offsets_offset
,
12148 sections
.str_offsets_size
);
12149 /* The "str" section is global to the entire DWP file. */
12150 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12151 /* The info or types section is assigned below to dwo_unit,
12152 there's no need to record it in dwo_file.
12153 Also, we can't simply record type sections in dwo_file because
12154 we record a pointer into the vector in dwo_unit. As we collect more
12155 types we'll grow the vector and eventually have to reallocate space
12156 for it, invalidating all copies of pointers into the previous
12158 *dwo_file_slot
= dwo_file
;
12162 if (dwarf_read_debug
)
12164 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12165 virtual_dwo_name
.c_str ());
12167 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12170 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12171 dwo_unit
->dwo_file
= dwo_file
;
12172 dwo_unit
->signature
= signature
;
12173 dwo_unit
->section
=
12174 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12175 *dwo_unit
->section
= create_dwp_v2_section (per_objfile
,
12177 ? &dwp_file
->sections
.types
12178 : &dwp_file
->sections
.info
,
12179 sections
.info_or_types_offset
,
12180 sections
.info_or_types_size
);
12181 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12186 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12187 Returns NULL if the signature isn't found. */
12189 static struct dwo_unit
*
12190 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12191 struct dwp_file
*dwp_file
, const char *comp_dir
,
12192 ULONGEST signature
, int is_debug_types
)
12194 const struct dwp_hash_table
*dwp_htab
=
12195 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12196 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12197 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12198 uint32_t hash
= signature
& mask
;
12199 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12202 struct dwo_unit find_dwo_cu
;
12204 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12205 find_dwo_cu
.signature
= signature
;
12206 slot
= htab_find_slot (is_debug_types
12207 ? dwp_file
->loaded_tus
.get ()
12208 : dwp_file
->loaded_cus
.get (),
12209 &find_dwo_cu
, INSERT
);
12212 return (struct dwo_unit
*) *slot
;
12214 /* Use a for loop so that we don't loop forever on bad debug info. */
12215 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12217 ULONGEST signature_in_table
;
12219 signature_in_table
=
12220 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12221 if (signature_in_table
== signature
)
12223 uint32_t unit_index
=
12224 read_4_bytes (dbfd
,
12225 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12227 if (dwp_file
->version
== 1)
12229 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12230 unit_index
, comp_dir
,
12231 signature
, is_debug_types
);
12235 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12236 unit_index
, comp_dir
,
12237 signature
, is_debug_types
);
12239 return (struct dwo_unit
*) *slot
;
12241 if (signature_in_table
== 0)
12243 hash
= (hash
+ hash2
) & mask
;
12246 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12247 " [in module %s]"),
12251 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12252 Open the file specified by FILE_NAME and hand it off to BFD for
12253 preliminary analysis. Return a newly initialized bfd *, which
12254 includes a canonicalized copy of FILE_NAME.
12255 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12256 SEARCH_CWD is true if the current directory is to be searched.
12257 It will be searched before debug-file-directory.
12258 If successful, the file is added to the bfd include table of the
12259 objfile's bfd (see gdb_bfd_record_inclusion).
12260 If unable to find/open the file, return NULL.
12261 NOTE: This function is derived from symfile_bfd_open. */
12263 static gdb_bfd_ref_ptr
12264 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12265 const char *file_name
, int is_dwp
, int search_cwd
)
12268 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12269 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12270 to debug_file_directory. */
12271 const char *search_path
;
12272 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12274 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12277 if (*debug_file_directory
!= '\0')
12279 search_path_holder
.reset (concat (".", dirname_separator_string
,
12280 debug_file_directory
,
12282 search_path
= search_path_holder
.get ();
12288 search_path
= debug_file_directory
;
12290 openp_flags flags
= OPF_RETURN_REALPATH
;
12292 flags
|= OPF_SEARCH_IN_PATH
;
12294 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12295 desc
= openp (search_path
, flags
, file_name
,
12296 O_RDONLY
| O_BINARY
, &absolute_name
);
12300 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12302 if (sym_bfd
== NULL
)
12304 bfd_set_cacheable (sym_bfd
.get (), 1);
12306 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12309 /* Success. Record the bfd as having been included by the objfile's bfd.
12310 This is important because things like demangled_names_hash lives in the
12311 objfile's per_bfd space and may have references to things like symbol
12312 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12313 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12318 /* Try to open DWO file FILE_NAME.
12319 COMP_DIR is the DW_AT_comp_dir attribute.
12320 The result is the bfd handle of the file.
12321 If there is a problem finding or opening the file, return NULL.
12322 Upon success, the canonicalized path of the file is stored in the bfd,
12323 same as symfile_bfd_open. */
12325 static gdb_bfd_ref_ptr
12326 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12327 const char *file_name
, const char *comp_dir
)
12329 if (IS_ABSOLUTE_PATH (file_name
))
12330 return try_open_dwop_file (per_objfile
, file_name
,
12331 0 /*is_dwp*/, 0 /*search_cwd*/);
12333 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12335 if (comp_dir
!= NULL
)
12337 gdb::unique_xmalloc_ptr
<char> path_to_try
12338 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12340 /* NOTE: If comp_dir is a relative path, this will also try the
12341 search path, which seems useful. */
12342 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12344 1 /*search_cwd*/));
12349 /* That didn't work, try debug-file-directory, which, despite its name,
12350 is a list of paths. */
12352 if (*debug_file_directory
== '\0')
12355 return try_open_dwop_file (per_objfile
, file_name
,
12356 0 /*is_dwp*/, 1 /*search_cwd*/);
12359 /* This function is mapped across the sections and remembers the offset and
12360 size of each of the DWO debugging sections we are interested in. */
12363 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12365 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12366 const struct dwop_section_names
*names
= &dwop_section_names
;
12368 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12370 dwo_sections
->abbrev
.s
.section
= sectp
;
12371 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12373 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12375 dwo_sections
->info
.s
.section
= sectp
;
12376 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12378 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12380 dwo_sections
->line
.s
.section
= sectp
;
12381 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12383 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12385 dwo_sections
->loc
.s
.section
= sectp
;
12386 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12388 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12390 dwo_sections
->loclists
.s
.section
= sectp
;
12391 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12393 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12395 dwo_sections
->macinfo
.s
.section
= sectp
;
12396 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12398 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12400 dwo_sections
->macro
.s
.section
= sectp
;
12401 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12403 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12405 dwo_sections
->str
.s
.section
= sectp
;
12406 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12408 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12410 dwo_sections
->str_offsets
.s
.section
= sectp
;
12411 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12413 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12415 struct dwarf2_section_info type_section
;
12417 memset (&type_section
, 0, sizeof (type_section
));
12418 type_section
.s
.section
= sectp
;
12419 type_section
.size
= bfd_section_size (sectp
);
12420 dwo_sections
->types
.push_back (type_section
);
12424 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12425 by PER_CU. This is for the non-DWP case.
12426 The result is NULL if DWO_NAME can't be found. */
12428 static struct dwo_file
*
12429 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12430 const char *comp_dir
)
12432 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12434 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12437 if (dwarf_read_debug
)
12438 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12442 dwo_file_up
dwo_file (new struct dwo_file
);
12443 dwo_file
->dwo_name
= dwo_name
;
12444 dwo_file
->comp_dir
= comp_dir
;
12445 dwo_file
->dbfd
= std::move (dbfd
);
12447 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12448 &dwo_file
->sections
);
12450 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12453 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12454 dwo_file
->sections
.types
, dwo_file
->tus
);
12456 if (dwarf_read_debug
)
12457 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12459 return dwo_file
.release ();
12462 /* This function is mapped across the sections and remembers the offset and
12463 size of each of the DWP debugging sections common to version 1 and 2 that
12464 we are interested in. */
12467 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12468 void *dwp_file_ptr
)
12470 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12471 const struct dwop_section_names
*names
= &dwop_section_names
;
12472 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12474 /* Record the ELF section number for later lookup: this is what the
12475 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12476 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12477 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12479 /* Look for specific sections that we need. */
12480 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12482 dwp_file
->sections
.str
.s
.section
= sectp
;
12483 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12485 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12487 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12488 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12490 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12492 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12493 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12497 /* This function is mapped across the sections and remembers the offset and
12498 size of each of the DWP version 2 debugging sections that we are interested
12499 in. This is split into a separate function because we don't know if we
12500 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12503 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12505 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12506 const struct dwop_section_names
*names
= &dwop_section_names
;
12507 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12509 /* Record the ELF section number for later lookup: this is what the
12510 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12511 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12512 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12514 /* Look for specific sections that we need. */
12515 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12517 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12518 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12520 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12522 dwp_file
->sections
.info
.s
.section
= sectp
;
12523 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12525 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12527 dwp_file
->sections
.line
.s
.section
= sectp
;
12528 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12530 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12532 dwp_file
->sections
.loc
.s
.section
= sectp
;
12533 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12535 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12537 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12538 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12540 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12542 dwp_file
->sections
.macro
.s
.section
= sectp
;
12543 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12545 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12547 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12548 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12550 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12552 dwp_file
->sections
.types
.s
.section
= sectp
;
12553 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12557 /* Hash function for dwp_file loaded CUs/TUs. */
12560 hash_dwp_loaded_cutus (const void *item
)
12562 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12564 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12565 return dwo_unit
->signature
;
12568 /* Equality function for dwp_file loaded CUs/TUs. */
12571 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12573 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12574 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12576 return dua
->signature
== dub
->signature
;
12579 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12582 allocate_dwp_loaded_cutus_table ()
12584 return htab_up (htab_create_alloc (3,
12585 hash_dwp_loaded_cutus
,
12586 eq_dwp_loaded_cutus
,
12587 NULL
, xcalloc
, xfree
));
12590 /* Try to open DWP file FILE_NAME.
12591 The result is the bfd handle of the file.
12592 If there is a problem finding or opening the file, return NULL.
12593 Upon success, the canonicalized path of the file is stored in the bfd,
12594 same as symfile_bfd_open. */
12596 static gdb_bfd_ref_ptr
12597 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12599 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12601 1 /*search_cwd*/));
12605 /* Work around upstream bug 15652.
12606 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12607 [Whether that's a "bug" is debatable, but it is getting in our way.]
12608 We have no real idea where the dwp file is, because gdb's realpath-ing
12609 of the executable's path may have discarded the needed info.
12610 [IWBN if the dwp file name was recorded in the executable, akin to
12611 .gnu_debuglink, but that doesn't exist yet.]
12612 Strip the directory from FILE_NAME and search again. */
12613 if (*debug_file_directory
!= '\0')
12615 /* Don't implicitly search the current directory here.
12616 If the user wants to search "." to handle this case,
12617 it must be added to debug-file-directory. */
12618 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12626 /* Initialize the use of the DWP file for the current objfile.
12627 By convention the name of the DWP file is ${objfile}.dwp.
12628 The result is NULL if it can't be found. */
12630 static std::unique_ptr
<struct dwp_file
>
12631 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12633 struct objfile
*objfile
= per_objfile
->objfile
;
12635 /* Try to find first .dwp for the binary file before any symbolic links
12638 /* If the objfile is a debug file, find the name of the real binary
12639 file and get the name of dwp file from there. */
12640 std::string dwp_name
;
12641 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12643 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12644 const char *backlink_basename
= lbasename (backlink
->original_name
);
12646 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12649 dwp_name
= objfile
->original_name
;
12651 dwp_name
+= ".dwp";
12653 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12655 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12657 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12658 dwp_name
= objfile_name (objfile
);
12659 dwp_name
+= ".dwp";
12660 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12665 if (dwarf_read_debug
)
12666 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12667 return std::unique_ptr
<dwp_file
> ();
12670 const char *name
= bfd_get_filename (dbfd
.get ());
12671 std::unique_ptr
<struct dwp_file
> dwp_file
12672 (new struct dwp_file (name
, std::move (dbfd
)));
12674 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12675 dwp_file
->elf_sections
=
12676 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12677 dwp_file
->num_sections
, asection
*);
12679 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12680 dwarf2_locate_common_dwp_sections
,
12683 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12685 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12687 /* The DWP file version is stored in the hash table. Oh well. */
12688 if (dwp_file
->cus
&& dwp_file
->tus
12689 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12691 /* Technically speaking, we should try to limp along, but this is
12692 pretty bizarre. We use pulongest here because that's the established
12693 portability solution (e.g, we cannot use %u for uint32_t). */
12694 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12695 " TU version %s [in DWP file %s]"),
12696 pulongest (dwp_file
->cus
->version
),
12697 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12701 dwp_file
->version
= dwp_file
->cus
->version
;
12702 else if (dwp_file
->tus
)
12703 dwp_file
->version
= dwp_file
->tus
->version
;
12705 dwp_file
->version
= 2;
12707 if (dwp_file
->version
== 2)
12708 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12709 dwarf2_locate_v2_dwp_sections
,
12712 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12713 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12715 if (dwarf_read_debug
)
12717 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12718 fprintf_unfiltered (gdb_stdlog
,
12719 " %s CUs, %s TUs\n",
12720 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12721 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12727 /* Wrapper around open_and_init_dwp_file, only open it once. */
12729 static struct dwp_file
*
12730 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12732 if (!per_objfile
->per_bfd
->dwp_checked
)
12734 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12735 per_objfile
->per_bfd
->dwp_checked
= 1;
12737 return per_objfile
->per_bfd
->dwp_file
.get ();
12740 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12741 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12742 or in the DWP file for the objfile, referenced by THIS_UNIT.
12743 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12744 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12746 This is called, for example, when wanting to read a variable with a
12747 complex location. Therefore we don't want to do file i/o for every call.
12748 Therefore we don't want to look for a DWO file on every call.
12749 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12750 then we check if we've already seen DWO_NAME, and only THEN do we check
12753 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12754 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12756 static struct dwo_unit
*
12757 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12758 ULONGEST signature
, int is_debug_types
)
12760 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12761 struct objfile
*objfile
= per_objfile
->objfile
;
12762 const char *kind
= is_debug_types
? "TU" : "CU";
12763 void **dwo_file_slot
;
12764 struct dwo_file
*dwo_file
;
12765 struct dwp_file
*dwp_file
;
12767 /* First see if there's a DWP file.
12768 If we have a DWP file but didn't find the DWO inside it, don't
12769 look for the original DWO file. It makes gdb behave differently
12770 depending on whether one is debugging in the build tree. */
12772 dwp_file
= get_dwp_file (per_objfile
);
12773 if (dwp_file
!= NULL
)
12775 const struct dwp_hash_table
*dwp_htab
=
12776 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12778 if (dwp_htab
!= NULL
)
12780 struct dwo_unit
*dwo_cutu
=
12781 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12784 if (dwo_cutu
!= NULL
)
12786 if (dwarf_read_debug
)
12788 fprintf_unfiltered (gdb_stdlog
,
12789 "Virtual DWO %s %s found: @%s\n",
12790 kind
, hex_string (signature
),
12791 host_address_to_string (dwo_cutu
));
12799 /* No DWP file, look for the DWO file. */
12801 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12802 if (*dwo_file_slot
== NULL
)
12804 /* Read in the file and build a table of the CUs/TUs it contains. */
12805 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12807 /* NOTE: This will be NULL if unable to open the file. */
12808 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12810 if (dwo_file
!= NULL
)
12812 struct dwo_unit
*dwo_cutu
= NULL
;
12814 if (is_debug_types
&& dwo_file
->tus
)
12816 struct dwo_unit find_dwo_cutu
;
12818 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12819 find_dwo_cutu
.signature
= signature
;
12821 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12824 else if (!is_debug_types
&& dwo_file
->cus
)
12826 struct dwo_unit find_dwo_cutu
;
12828 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12829 find_dwo_cutu
.signature
= signature
;
12830 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12834 if (dwo_cutu
!= NULL
)
12836 if (dwarf_read_debug
)
12838 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12839 kind
, dwo_name
, hex_string (signature
),
12840 host_address_to_string (dwo_cutu
));
12847 /* We didn't find it. This could mean a dwo_id mismatch, or
12848 someone deleted the DWO/DWP file, or the search path isn't set up
12849 correctly to find the file. */
12851 if (dwarf_read_debug
)
12853 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12854 kind
, dwo_name
, hex_string (signature
));
12857 /* This is a warning and not a complaint because it can be caused by
12858 pilot error (e.g., user accidentally deleting the DWO). */
12860 /* Print the name of the DWP file if we looked there, helps the user
12861 better diagnose the problem. */
12862 std::string dwp_text
;
12864 if (dwp_file
!= NULL
)
12865 dwp_text
= string_printf (" [in DWP file %s]",
12866 lbasename (dwp_file
->name
));
12868 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12869 " [in module %s]"),
12870 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12871 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12876 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12877 See lookup_dwo_cutu_unit for details. */
12879 static struct dwo_unit
*
12880 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12881 ULONGEST signature
)
12883 gdb_assert (!cu
->per_cu
->is_debug_types
);
12885 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12888 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12889 See lookup_dwo_cutu_unit for details. */
12891 static struct dwo_unit
*
12892 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12894 gdb_assert (cu
->per_cu
->is_debug_types
);
12896 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12898 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12901 /* Traversal function for queue_and_load_all_dwo_tus. */
12904 queue_and_load_dwo_tu (void **slot
, void *info
)
12906 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12907 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12908 ULONGEST signature
= dwo_unit
->signature
;
12909 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12911 if (sig_type
!= NULL
)
12913 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12915 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12916 a real dependency of PER_CU on SIG_TYPE. That is detected later
12917 while processing PER_CU. */
12918 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
12919 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12920 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12926 /* Queue all TUs contained in the DWO of CU to be read in.
12927 The DWO may have the only definition of the type, though it may not be
12928 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12929 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12932 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12934 struct dwo_unit
*dwo_unit
;
12935 struct dwo_file
*dwo_file
;
12937 gdb_assert (cu
!= nullptr);
12938 gdb_assert (!cu
->per_cu
->is_debug_types
);
12939 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12941 dwo_unit
= cu
->dwo_unit
;
12942 gdb_assert (dwo_unit
!= NULL
);
12944 dwo_file
= dwo_unit
->dwo_file
;
12945 if (dwo_file
->tus
!= NULL
)
12946 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12949 /* Read in various DIEs. */
12951 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12952 Inherit only the children of the DW_AT_abstract_origin DIE not being
12953 already referenced by DW_AT_abstract_origin from the children of the
12957 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12959 struct die_info
*child_die
;
12960 sect_offset
*offsetp
;
12961 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12962 struct die_info
*origin_die
;
12963 /* Iterator of the ORIGIN_DIE children. */
12964 struct die_info
*origin_child_die
;
12965 struct attribute
*attr
;
12966 struct dwarf2_cu
*origin_cu
;
12967 struct pending
**origin_previous_list_in_scope
;
12969 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12973 /* Note that following die references may follow to a die in a
12977 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12979 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12981 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12982 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12984 if (die
->tag
!= origin_die
->tag
12985 && !(die
->tag
== DW_TAG_inlined_subroutine
12986 && origin_die
->tag
== DW_TAG_subprogram
))
12987 complaint (_("DIE %s and its abstract origin %s have different tags"),
12988 sect_offset_str (die
->sect_off
),
12989 sect_offset_str (origin_die
->sect_off
));
12991 std::vector
<sect_offset
> offsets
;
12993 for (child_die
= die
->child
;
12994 child_die
&& child_die
->tag
;
12995 child_die
= child_die
->sibling
)
12997 struct die_info
*child_origin_die
;
12998 struct dwarf2_cu
*child_origin_cu
;
13000 /* We are trying to process concrete instance entries:
13001 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13002 it's not relevant to our analysis here. i.e. detecting DIEs that are
13003 present in the abstract instance but not referenced in the concrete
13005 if (child_die
->tag
== DW_TAG_call_site
13006 || child_die
->tag
== DW_TAG_GNU_call_site
)
13009 /* For each CHILD_DIE, find the corresponding child of
13010 ORIGIN_DIE. If there is more than one layer of
13011 DW_AT_abstract_origin, follow them all; there shouldn't be,
13012 but GCC versions at least through 4.4 generate this (GCC PR
13014 child_origin_die
= child_die
;
13015 child_origin_cu
= cu
;
13018 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13022 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13026 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13027 counterpart may exist. */
13028 if (child_origin_die
!= child_die
)
13030 if (child_die
->tag
!= child_origin_die
->tag
13031 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13032 && child_origin_die
->tag
== DW_TAG_subprogram
))
13033 complaint (_("Child DIE %s and its abstract origin %s have "
13035 sect_offset_str (child_die
->sect_off
),
13036 sect_offset_str (child_origin_die
->sect_off
));
13037 if (child_origin_die
->parent
!= origin_die
)
13038 complaint (_("Child DIE %s and its abstract origin %s have "
13039 "different parents"),
13040 sect_offset_str (child_die
->sect_off
),
13041 sect_offset_str (child_origin_die
->sect_off
));
13043 offsets
.push_back (child_origin_die
->sect_off
);
13046 std::sort (offsets
.begin (), offsets
.end ());
13047 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13048 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13049 if (offsetp
[-1] == *offsetp
)
13050 complaint (_("Multiple children of DIE %s refer "
13051 "to DIE %s as their abstract origin"),
13052 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13054 offsetp
= offsets
.data ();
13055 origin_child_die
= origin_die
->child
;
13056 while (origin_child_die
&& origin_child_die
->tag
)
13058 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13059 while (offsetp
< offsets_end
13060 && *offsetp
< origin_child_die
->sect_off
)
13062 if (offsetp
>= offsets_end
13063 || *offsetp
> origin_child_die
->sect_off
)
13065 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13066 Check whether we're already processing ORIGIN_CHILD_DIE.
13067 This can happen with mutually referenced abstract_origins.
13069 if (!origin_child_die
->in_process
)
13070 process_die (origin_child_die
, origin_cu
);
13072 origin_child_die
= origin_child_die
->sibling
;
13074 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13076 if (cu
!= origin_cu
)
13077 compute_delayed_physnames (origin_cu
);
13081 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13083 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13084 struct gdbarch
*gdbarch
= objfile
->arch ();
13085 struct context_stack
*newobj
;
13088 struct die_info
*child_die
;
13089 struct attribute
*attr
, *call_line
, *call_file
;
13091 CORE_ADDR baseaddr
;
13092 struct block
*block
;
13093 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13094 std::vector
<struct symbol
*> template_args
;
13095 struct template_symbol
*templ_func
= NULL
;
13099 /* If we do not have call site information, we can't show the
13100 caller of this inlined function. That's too confusing, so
13101 only use the scope for local variables. */
13102 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13103 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13104 if (call_line
== NULL
|| call_file
== NULL
)
13106 read_lexical_block_scope (die
, cu
);
13111 baseaddr
= objfile
->text_section_offset ();
13113 name
= dwarf2_name (die
, cu
);
13115 /* Ignore functions with missing or empty names. These are actually
13116 illegal according to the DWARF standard. */
13119 complaint (_("missing name for subprogram DIE at %s"),
13120 sect_offset_str (die
->sect_off
));
13124 /* Ignore functions with missing or invalid low and high pc attributes. */
13125 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13126 <= PC_BOUNDS_INVALID
)
13128 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13129 if (!attr
|| !DW_UNSND (attr
))
13130 complaint (_("cannot get low and high bounds "
13131 "for subprogram DIE at %s"),
13132 sect_offset_str (die
->sect_off
));
13136 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13137 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13139 /* If we have any template arguments, then we must allocate a
13140 different sort of symbol. */
13141 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13143 if (child_die
->tag
== DW_TAG_template_type_param
13144 || child_die
->tag
== DW_TAG_template_value_param
)
13146 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13147 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13152 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13153 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13154 (struct symbol
*) templ_func
);
13156 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13157 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13160 /* If there is a location expression for DW_AT_frame_base, record
13162 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13163 if (attr
!= nullptr)
13164 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13166 /* If there is a location for the static link, record it. */
13167 newobj
->static_link
= NULL
;
13168 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13169 if (attr
!= nullptr)
13171 newobj
->static_link
13172 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13173 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13177 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13179 if (die
->child
!= NULL
)
13181 child_die
= die
->child
;
13182 while (child_die
&& child_die
->tag
)
13184 if (child_die
->tag
== DW_TAG_template_type_param
13185 || child_die
->tag
== DW_TAG_template_value_param
)
13187 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13190 template_args
.push_back (arg
);
13193 process_die (child_die
, cu
);
13194 child_die
= child_die
->sibling
;
13198 inherit_abstract_dies (die
, cu
);
13200 /* If we have a DW_AT_specification, we might need to import using
13201 directives from the context of the specification DIE. See the
13202 comment in determine_prefix. */
13203 if (cu
->language
== language_cplus
13204 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13206 struct dwarf2_cu
*spec_cu
= cu
;
13207 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13211 child_die
= spec_die
->child
;
13212 while (child_die
&& child_die
->tag
)
13214 if (child_die
->tag
== DW_TAG_imported_module
)
13215 process_die (child_die
, spec_cu
);
13216 child_die
= child_die
->sibling
;
13219 /* In some cases, GCC generates specification DIEs that
13220 themselves contain DW_AT_specification attributes. */
13221 spec_die
= die_specification (spec_die
, &spec_cu
);
13225 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13226 /* Make a block for the local symbols within. */
13227 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13228 cstk
.static_link
, lowpc
, highpc
);
13230 /* For C++, set the block's scope. */
13231 if ((cu
->language
== language_cplus
13232 || cu
->language
== language_fortran
13233 || cu
->language
== language_d
13234 || cu
->language
== language_rust
)
13235 && cu
->processing_has_namespace_info
)
13236 block_set_scope (block
, determine_prefix (die
, cu
),
13237 &objfile
->objfile_obstack
);
13239 /* If we have address ranges, record them. */
13240 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13242 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13244 /* Attach template arguments to function. */
13245 if (!template_args
.empty ())
13247 gdb_assert (templ_func
!= NULL
);
13249 templ_func
->n_template_arguments
= template_args
.size ();
13250 templ_func
->template_arguments
13251 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13252 templ_func
->n_template_arguments
);
13253 memcpy (templ_func
->template_arguments
,
13254 template_args
.data (),
13255 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13257 /* Make sure that the symtab is set on the new symbols. Even
13258 though they don't appear in this symtab directly, other parts
13259 of gdb assume that symbols do, and this is reasonably
13261 for (symbol
*sym
: template_args
)
13262 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13265 /* In C++, we can have functions nested inside functions (e.g., when
13266 a function declares a class that has methods). This means that
13267 when we finish processing a function scope, we may need to go
13268 back to building a containing block's symbol lists. */
13269 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13270 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13272 /* If we've finished processing a top-level function, subsequent
13273 symbols go in the file symbol list. */
13274 if (cu
->get_builder ()->outermost_context_p ())
13275 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13278 /* Process all the DIES contained within a lexical block scope. Start
13279 a new scope, process the dies, and then close the scope. */
13282 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13284 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13285 struct gdbarch
*gdbarch
= objfile
->arch ();
13286 CORE_ADDR lowpc
, highpc
;
13287 struct die_info
*child_die
;
13288 CORE_ADDR baseaddr
;
13290 baseaddr
= objfile
->text_section_offset ();
13292 /* Ignore blocks with missing or invalid low and high pc attributes. */
13293 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13294 as multiple lexical blocks? Handling children in a sane way would
13295 be nasty. Might be easier to properly extend generic blocks to
13296 describe ranges. */
13297 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13299 case PC_BOUNDS_NOT_PRESENT
:
13300 /* DW_TAG_lexical_block has no attributes, process its children as if
13301 there was no wrapping by that DW_TAG_lexical_block.
13302 GCC does no longer produces such DWARF since GCC r224161. */
13303 for (child_die
= die
->child
;
13304 child_die
!= NULL
&& child_die
->tag
;
13305 child_die
= child_die
->sibling
)
13307 /* We might already be processing this DIE. This can happen
13308 in an unusual circumstance -- where a subroutine A
13309 appears lexically in another subroutine B, but A actually
13310 inlines B. The recursion is broken here, rather than in
13311 inherit_abstract_dies, because it seems better to simply
13312 drop concrete children here. */
13313 if (!child_die
->in_process
)
13314 process_die (child_die
, cu
);
13317 case PC_BOUNDS_INVALID
:
13320 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13321 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13323 cu
->get_builder ()->push_context (0, lowpc
);
13324 if (die
->child
!= NULL
)
13326 child_die
= die
->child
;
13327 while (child_die
&& child_die
->tag
)
13329 process_die (child_die
, cu
);
13330 child_die
= child_die
->sibling
;
13333 inherit_abstract_dies (die
, cu
);
13334 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13336 if (*cu
->get_builder ()->get_local_symbols () != NULL
13337 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13339 struct block
*block
13340 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13341 cstk
.start_addr
, highpc
);
13343 /* Note that recording ranges after traversing children, as we
13344 do here, means that recording a parent's ranges entails
13345 walking across all its children's ranges as they appear in
13346 the address map, which is quadratic behavior.
13348 It would be nicer to record the parent's ranges before
13349 traversing its children, simply overriding whatever you find
13350 there. But since we don't even decide whether to create a
13351 block until after we've traversed its children, that's hard
13353 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13355 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13356 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13359 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13362 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13364 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13365 struct objfile
*objfile
= per_objfile
->objfile
;
13366 struct gdbarch
*gdbarch
= objfile
->arch ();
13367 CORE_ADDR pc
, baseaddr
;
13368 struct attribute
*attr
;
13369 struct call_site
*call_site
, call_site_local
;
13372 struct die_info
*child_die
;
13374 baseaddr
= objfile
->text_section_offset ();
13376 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13379 /* This was a pre-DWARF-5 GNU extension alias
13380 for DW_AT_call_return_pc. */
13381 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13385 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13386 "DIE %s [in module %s]"),
13387 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13390 pc
= attr
->value_as_address () + baseaddr
;
13391 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13393 if (cu
->call_site_htab
== NULL
)
13394 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13395 NULL
, &objfile
->objfile_obstack
,
13396 hashtab_obstack_allocate
, NULL
);
13397 call_site_local
.pc
= pc
;
13398 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13401 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13402 "DIE %s [in module %s]"),
13403 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13404 objfile_name (objfile
));
13408 /* Count parameters at the caller. */
13411 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13412 child_die
= child_die
->sibling
)
13414 if (child_die
->tag
!= DW_TAG_call_site_parameter
13415 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13417 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13418 "DW_TAG_call_site child DIE %s [in module %s]"),
13419 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13420 objfile_name (objfile
));
13428 = ((struct call_site
*)
13429 obstack_alloc (&objfile
->objfile_obstack
,
13430 sizeof (*call_site
)
13431 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13433 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13434 call_site
->pc
= pc
;
13436 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13437 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13439 struct die_info
*func_die
;
13441 /* Skip also over DW_TAG_inlined_subroutine. */
13442 for (func_die
= die
->parent
;
13443 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13444 && func_die
->tag
!= DW_TAG_subroutine_type
;
13445 func_die
= func_die
->parent
);
13447 /* DW_AT_call_all_calls is a superset
13448 of DW_AT_call_all_tail_calls. */
13450 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13451 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13452 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13453 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13455 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13456 not complete. But keep CALL_SITE for look ups via call_site_htab,
13457 both the initial caller containing the real return address PC and
13458 the final callee containing the current PC of a chain of tail
13459 calls do not need to have the tail call list complete. But any
13460 function candidate for a virtual tail call frame searched via
13461 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13462 determined unambiguously. */
13466 struct type
*func_type
= NULL
;
13469 func_type
= get_die_type (func_die
, cu
);
13470 if (func_type
!= NULL
)
13472 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13474 /* Enlist this call site to the function. */
13475 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13476 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13479 complaint (_("Cannot find function owning DW_TAG_call_site "
13480 "DIE %s [in module %s]"),
13481 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13485 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13487 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13489 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13492 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13493 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13495 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13496 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13497 /* Keep NULL DWARF_BLOCK. */;
13498 else if (attr
->form_is_block ())
13500 struct dwarf2_locexpr_baton
*dlbaton
;
13502 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13503 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13504 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13505 dlbaton
->per_objfile
= per_objfile
;
13506 dlbaton
->per_cu
= cu
->per_cu
;
13508 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13510 else if (attr
->form_is_ref ())
13512 struct dwarf2_cu
*target_cu
= cu
;
13513 struct die_info
*target_die
;
13515 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13516 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13517 if (die_is_declaration (target_die
, target_cu
))
13519 const char *target_physname
;
13521 /* Prefer the mangled name; otherwise compute the demangled one. */
13522 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13523 if (target_physname
== NULL
)
13524 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13525 if (target_physname
== NULL
)
13526 complaint (_("DW_AT_call_target target DIE has invalid "
13527 "physname, for referencing DIE %s [in module %s]"),
13528 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13530 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13536 /* DW_AT_entry_pc should be preferred. */
13537 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13538 <= PC_BOUNDS_INVALID
)
13539 complaint (_("DW_AT_call_target target DIE has invalid "
13540 "low pc, for referencing DIE %s [in module %s]"),
13541 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13544 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13545 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13550 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13551 "block nor reference, for DIE %s [in module %s]"),
13552 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13554 call_site
->per_cu
= cu
->per_cu
;
13555 call_site
->per_objfile
= per_objfile
;
13557 for (child_die
= die
->child
;
13558 child_die
&& child_die
->tag
;
13559 child_die
= child_die
->sibling
)
13561 struct call_site_parameter
*parameter
;
13562 struct attribute
*loc
, *origin
;
13564 if (child_die
->tag
!= DW_TAG_call_site_parameter
13565 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13567 /* Already printed the complaint above. */
13571 gdb_assert (call_site
->parameter_count
< nparams
);
13572 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13574 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13575 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13576 register is contained in DW_AT_call_value. */
13578 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13579 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13580 if (origin
== NULL
)
13582 /* This was a pre-DWARF-5 GNU extension alias
13583 for DW_AT_call_parameter. */
13584 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13586 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13588 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13590 sect_offset sect_off
= origin
->get_ref_die_offset ();
13591 if (!cu
->header
.offset_in_cu_p (sect_off
))
13593 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13594 binding can be done only inside one CU. Such referenced DIE
13595 therefore cannot be even moved to DW_TAG_partial_unit. */
13596 complaint (_("DW_AT_call_parameter offset is not in CU for "
13597 "DW_TAG_call_site child DIE %s [in module %s]"),
13598 sect_offset_str (child_die
->sect_off
),
13599 objfile_name (objfile
));
13602 parameter
->u
.param_cu_off
13603 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13605 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13607 complaint (_("No DW_FORM_block* DW_AT_location for "
13608 "DW_TAG_call_site child DIE %s [in module %s]"),
13609 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13614 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13615 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13616 if (parameter
->u
.dwarf_reg
!= -1)
13617 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13618 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13619 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13620 ¶meter
->u
.fb_offset
))
13621 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13624 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13625 "for DW_FORM_block* DW_AT_location is supported for "
13626 "DW_TAG_call_site child DIE %s "
13628 sect_offset_str (child_die
->sect_off
),
13629 objfile_name (objfile
));
13634 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13636 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13637 if (attr
== NULL
|| !attr
->form_is_block ())
13639 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13640 "DW_TAG_call_site child DIE %s [in module %s]"),
13641 sect_offset_str (child_die
->sect_off
),
13642 objfile_name (objfile
));
13645 parameter
->value
= DW_BLOCK (attr
)->data
;
13646 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13648 /* Parameters are not pre-cleared by memset above. */
13649 parameter
->data_value
= NULL
;
13650 parameter
->data_value_size
= 0;
13651 call_site
->parameter_count
++;
13653 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13655 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13656 if (attr
!= nullptr)
13658 if (!attr
->form_is_block ())
13659 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13660 "DW_TAG_call_site child DIE %s [in module %s]"),
13661 sect_offset_str (child_die
->sect_off
),
13662 objfile_name (objfile
));
13665 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13666 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13672 /* Helper function for read_variable. If DIE represents a virtual
13673 table, then return the type of the concrete object that is
13674 associated with the virtual table. Otherwise, return NULL. */
13676 static struct type
*
13677 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13679 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13683 /* Find the type DIE. */
13684 struct die_info
*type_die
= NULL
;
13685 struct dwarf2_cu
*type_cu
= cu
;
13687 if (attr
->form_is_ref ())
13688 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13689 if (type_die
== NULL
)
13692 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13694 return die_containing_type (type_die
, type_cu
);
13697 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13700 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13702 struct rust_vtable_symbol
*storage
= NULL
;
13704 if (cu
->language
== language_rust
)
13706 struct type
*containing_type
= rust_containing_type (die
, cu
);
13708 if (containing_type
!= NULL
)
13710 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13712 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13713 storage
->concrete_type
= containing_type
;
13714 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13718 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13719 struct attribute
*abstract_origin
13720 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13721 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13722 if (res
== NULL
&& loc
&& abstract_origin
)
13724 /* We have a variable without a name, but with a location and an abstract
13725 origin. This may be a concrete instance of an abstract variable
13726 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13728 struct dwarf2_cu
*origin_cu
= cu
;
13729 struct die_info
*origin_die
13730 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13731 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13732 per_objfile
->per_bfd
->abstract_to_concrete
13733 [origin_die
->sect_off
].push_back (die
->sect_off
);
13737 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13738 reading .debug_rnglists.
13739 Callback's type should be:
13740 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13741 Return true if the attributes are present and valid, otherwise,
13744 template <typename Callback
>
13746 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13747 Callback
&&callback
)
13749 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13750 struct objfile
*objfile
= per_objfile
->objfile
;
13751 bfd
*obfd
= objfile
->obfd
;
13752 /* Base address selection entry. */
13753 gdb::optional
<CORE_ADDR
> base
;
13754 const gdb_byte
*buffer
;
13755 CORE_ADDR baseaddr
;
13756 bool overflow
= false;
13758 base
= cu
->base_address
;
13760 per_objfile
->per_bfd
->rnglists
.read (objfile
);
13761 if (offset
>= per_objfile
->per_bfd
->rnglists
.size
)
13763 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13767 buffer
= per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13769 baseaddr
= objfile
->text_section_offset ();
13773 /* Initialize it due to a false compiler warning. */
13774 CORE_ADDR range_beginning
= 0, range_end
= 0;
13775 const gdb_byte
*buf_end
= (per_objfile
->per_bfd
->rnglists
.buffer
13776 + per_objfile
->per_bfd
->rnglists
.size
);
13777 unsigned int bytes_read
;
13779 if (buffer
== buf_end
)
13784 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13787 case DW_RLE_end_of_list
:
13789 case DW_RLE_base_address
:
13790 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13795 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13796 buffer
+= bytes_read
;
13798 case DW_RLE_start_length
:
13799 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13804 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13806 buffer
+= bytes_read
;
13807 range_end
= (range_beginning
13808 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13809 buffer
+= bytes_read
;
13810 if (buffer
> buf_end
)
13816 case DW_RLE_offset_pair
:
13817 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13818 buffer
+= bytes_read
;
13819 if (buffer
> buf_end
)
13824 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13825 buffer
+= bytes_read
;
13826 if (buffer
> buf_end
)
13832 case DW_RLE_start_end
:
13833 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13838 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13840 buffer
+= bytes_read
;
13841 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13842 buffer
+= bytes_read
;
13845 complaint (_("Invalid .debug_rnglists data (no base address)"));
13848 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13850 if (rlet
== DW_RLE_base_address
)
13853 if (!base
.has_value ())
13855 /* We have no valid base address for the ranges
13857 complaint (_("Invalid .debug_rnglists data (no base address)"));
13861 if (range_beginning
> range_end
)
13863 /* Inverted range entries are invalid. */
13864 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13868 /* Empty range entries have no effect. */
13869 if (range_beginning
== range_end
)
13872 range_beginning
+= *base
;
13873 range_end
+= *base
;
13875 /* A not-uncommon case of bad debug info.
13876 Don't pollute the addrmap with bad data. */
13877 if (range_beginning
+ baseaddr
== 0
13878 && !per_objfile
->per_bfd
->has_section_at_zero
)
13880 complaint (_(".debug_rnglists entry has start address of zero"
13881 " [in module %s]"), objfile_name (objfile
));
13885 callback (range_beginning
, range_end
);
13890 complaint (_("Offset %d is not terminated "
13891 "for DW_AT_ranges attribute"),
13899 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13900 Callback's type should be:
13901 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13902 Return 1 if the attributes are present and valid, otherwise, return 0. */
13904 template <typename Callback
>
13906 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13907 Callback
&&callback
)
13909 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13910 struct objfile
*objfile
= per_objfile
->objfile
;
13911 struct comp_unit_head
*cu_header
= &cu
->header
;
13912 bfd
*obfd
= objfile
->obfd
;
13913 unsigned int addr_size
= cu_header
->addr_size
;
13914 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13915 /* Base address selection entry. */
13916 gdb::optional
<CORE_ADDR
> base
;
13917 unsigned int dummy
;
13918 const gdb_byte
*buffer
;
13919 CORE_ADDR baseaddr
;
13921 if (cu_header
->version
>= 5)
13922 return dwarf2_rnglists_process (offset
, cu
, callback
);
13924 base
= cu
->base_address
;
13926 per_objfile
->per_bfd
->ranges
.read (objfile
);
13927 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13929 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13933 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13935 baseaddr
= objfile
->text_section_offset ();
13939 CORE_ADDR range_beginning
, range_end
;
13941 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13942 buffer
+= addr_size
;
13943 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13944 buffer
+= addr_size
;
13945 offset
+= 2 * addr_size
;
13947 /* An end of list marker is a pair of zero addresses. */
13948 if (range_beginning
== 0 && range_end
== 0)
13949 /* Found the end of list entry. */
13952 /* Each base address selection entry is a pair of 2 values.
13953 The first is the largest possible address, the second is
13954 the base address. Check for a base address here. */
13955 if ((range_beginning
& mask
) == mask
)
13957 /* If we found the largest possible address, then we already
13958 have the base address in range_end. */
13963 if (!base
.has_value ())
13965 /* We have no valid base address for the ranges
13967 complaint (_("Invalid .debug_ranges data (no base address)"));
13971 if (range_beginning
> range_end
)
13973 /* Inverted range entries are invalid. */
13974 complaint (_("Invalid .debug_ranges data (inverted range)"));
13978 /* Empty range entries have no effect. */
13979 if (range_beginning
== range_end
)
13982 range_beginning
+= *base
;
13983 range_end
+= *base
;
13985 /* A not-uncommon case of bad debug info.
13986 Don't pollute the addrmap with bad data. */
13987 if (range_beginning
+ baseaddr
== 0
13988 && !per_objfile
->per_bfd
->has_section_at_zero
)
13990 complaint (_(".debug_ranges entry has start address of zero"
13991 " [in module %s]"), objfile_name (objfile
));
13995 callback (range_beginning
, range_end
);
14001 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14002 Return 1 if the attributes are present and valid, otherwise, return 0.
14003 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14006 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14007 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14008 dwarf2_psymtab
*ranges_pst
)
14010 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14011 struct gdbarch
*gdbarch
= objfile
->arch ();
14012 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14015 CORE_ADDR high
= 0;
14018 retval
= dwarf2_ranges_process (offset
, cu
,
14019 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14021 if (ranges_pst
!= NULL
)
14026 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14027 range_beginning
+ baseaddr
)
14029 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14030 range_end
+ baseaddr
)
14032 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14033 lowpc
, highpc
- 1, ranges_pst
);
14036 /* FIXME: This is recording everything as a low-high
14037 segment of consecutive addresses. We should have a
14038 data structure for discontiguous block ranges
14042 low
= range_beginning
;
14048 if (range_beginning
< low
)
14049 low
= range_beginning
;
14050 if (range_end
> high
)
14058 /* If the first entry is an end-of-list marker, the range
14059 describes an empty scope, i.e. no instructions. */
14065 *high_return
= high
;
14069 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14070 definition for the return value. *LOWPC and *HIGHPC are set iff
14071 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14073 static enum pc_bounds_kind
14074 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14075 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14076 dwarf2_psymtab
*pst
)
14078 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14079 struct attribute
*attr
;
14080 struct attribute
*attr_high
;
14082 CORE_ADDR high
= 0;
14083 enum pc_bounds_kind ret
;
14085 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14088 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14089 if (attr
!= nullptr)
14091 low
= attr
->value_as_address ();
14092 high
= attr_high
->value_as_address ();
14093 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14097 /* Found high w/o low attribute. */
14098 return PC_BOUNDS_INVALID
;
14100 /* Found consecutive range of addresses. */
14101 ret
= PC_BOUNDS_HIGH_LOW
;
14105 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14108 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14109 We take advantage of the fact that DW_AT_ranges does not appear
14110 in DW_TAG_compile_unit of DWO files. */
14111 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14112 unsigned int ranges_offset
= (DW_UNSND (attr
)
14113 + (need_ranges_base
14117 /* Value of the DW_AT_ranges attribute is the offset in the
14118 .debug_ranges section. */
14119 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14120 return PC_BOUNDS_INVALID
;
14121 /* Found discontinuous range of addresses. */
14122 ret
= PC_BOUNDS_RANGES
;
14125 return PC_BOUNDS_NOT_PRESENT
;
14128 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14130 return PC_BOUNDS_INVALID
;
14132 /* When using the GNU linker, .gnu.linkonce. sections are used to
14133 eliminate duplicate copies of functions and vtables and such.
14134 The linker will arbitrarily choose one and discard the others.
14135 The AT_*_pc values for such functions refer to local labels in
14136 these sections. If the section from that file was discarded, the
14137 labels are not in the output, so the relocs get a value of 0.
14138 If this is a discarded function, mark the pc bounds as invalid,
14139 so that GDB will ignore it. */
14140 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14141 return PC_BOUNDS_INVALID
;
14149 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14150 its low and high PC addresses. Do nothing if these addresses could not
14151 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14152 and HIGHPC to the high address if greater than HIGHPC. */
14155 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14156 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14157 struct dwarf2_cu
*cu
)
14159 CORE_ADDR low
, high
;
14160 struct die_info
*child
= die
->child
;
14162 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14164 *lowpc
= std::min (*lowpc
, low
);
14165 *highpc
= std::max (*highpc
, high
);
14168 /* If the language does not allow nested subprograms (either inside
14169 subprograms or lexical blocks), we're done. */
14170 if (cu
->language
!= language_ada
)
14173 /* Check all the children of the given DIE. If it contains nested
14174 subprograms, then check their pc bounds. Likewise, we need to
14175 check lexical blocks as well, as they may also contain subprogram
14177 while (child
&& child
->tag
)
14179 if (child
->tag
== DW_TAG_subprogram
14180 || child
->tag
== DW_TAG_lexical_block
)
14181 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14182 child
= child
->sibling
;
14186 /* Get the low and high pc's represented by the scope DIE, and store
14187 them in *LOWPC and *HIGHPC. If the correct values can't be
14188 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14191 get_scope_pc_bounds (struct die_info
*die
,
14192 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14193 struct dwarf2_cu
*cu
)
14195 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14196 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14197 CORE_ADDR current_low
, current_high
;
14199 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14200 >= PC_BOUNDS_RANGES
)
14202 best_low
= current_low
;
14203 best_high
= current_high
;
14207 struct die_info
*child
= die
->child
;
14209 while (child
&& child
->tag
)
14211 switch (child
->tag
) {
14212 case DW_TAG_subprogram
:
14213 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14215 case DW_TAG_namespace
:
14216 case DW_TAG_module
:
14217 /* FIXME: carlton/2004-01-16: Should we do this for
14218 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14219 that current GCC's always emit the DIEs corresponding
14220 to definitions of methods of classes as children of a
14221 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14222 the DIEs giving the declarations, which could be
14223 anywhere). But I don't see any reason why the
14224 standards says that they have to be there. */
14225 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14227 if (current_low
!= ((CORE_ADDR
) -1))
14229 best_low
= std::min (best_low
, current_low
);
14230 best_high
= std::max (best_high
, current_high
);
14238 child
= child
->sibling
;
14243 *highpc
= best_high
;
14246 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14250 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14251 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14253 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14254 struct gdbarch
*gdbarch
= objfile
->arch ();
14255 struct attribute
*attr
;
14256 struct attribute
*attr_high
;
14258 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14261 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14262 if (attr
!= nullptr)
14264 CORE_ADDR low
= attr
->value_as_address ();
14265 CORE_ADDR high
= attr_high
->value_as_address ();
14267 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14270 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14271 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14272 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14276 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14277 if (attr
!= nullptr)
14279 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14280 We take advantage of the fact that DW_AT_ranges does not appear
14281 in DW_TAG_compile_unit of DWO files. */
14282 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14284 /* The value of the DW_AT_ranges attribute is the offset of the
14285 address range list in the .debug_ranges section. */
14286 unsigned long offset
= (DW_UNSND (attr
)
14287 + (need_ranges_base
? cu
->ranges_base
: 0));
14289 std::vector
<blockrange
> blockvec
;
14290 dwarf2_ranges_process (offset
, cu
,
14291 [&] (CORE_ADDR start
, CORE_ADDR end
)
14295 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14296 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14297 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14298 blockvec
.emplace_back (start
, end
);
14301 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14305 /* Check whether the producer field indicates either of GCC < 4.6, or the
14306 Intel C/C++ compiler, and cache the result in CU. */
14309 check_producer (struct dwarf2_cu
*cu
)
14313 if (cu
->producer
== NULL
)
14315 /* For unknown compilers expect their behavior is DWARF version
14318 GCC started to support .debug_types sections by -gdwarf-4 since
14319 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14320 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14321 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14322 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14324 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14326 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14327 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14329 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14331 cu
->producer_is_icc
= true;
14332 cu
->producer_is_icc_lt_14
= major
< 14;
14334 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14335 cu
->producer_is_codewarrior
= true;
14338 /* For other non-GCC compilers, expect their behavior is DWARF version
14342 cu
->checked_producer
= true;
14345 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14346 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14347 during 4.6.0 experimental. */
14350 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14352 if (!cu
->checked_producer
)
14353 check_producer (cu
);
14355 return cu
->producer_is_gxx_lt_4_6
;
14359 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14360 with incorrect is_stmt attributes. */
14363 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14365 if (!cu
->checked_producer
)
14366 check_producer (cu
);
14368 return cu
->producer_is_codewarrior
;
14371 /* Return the default accessibility type if it is not overridden by
14372 DW_AT_accessibility. */
14374 static enum dwarf_access_attribute
14375 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14377 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14379 /* The default DWARF 2 accessibility for members is public, the default
14380 accessibility for inheritance is private. */
14382 if (die
->tag
!= DW_TAG_inheritance
)
14383 return DW_ACCESS_public
;
14385 return DW_ACCESS_private
;
14389 /* DWARF 3+ defines the default accessibility a different way. The same
14390 rules apply now for DW_TAG_inheritance as for the members and it only
14391 depends on the container kind. */
14393 if (die
->parent
->tag
== DW_TAG_class_type
)
14394 return DW_ACCESS_private
;
14396 return DW_ACCESS_public
;
14400 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14401 offset. If the attribute was not found return 0, otherwise return
14402 1. If it was found but could not properly be handled, set *OFFSET
14406 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14409 struct attribute
*attr
;
14411 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14416 /* Note that we do not check for a section offset first here.
14417 This is because DW_AT_data_member_location is new in DWARF 4,
14418 so if we see it, we can assume that a constant form is really
14419 a constant and not a section offset. */
14420 if (attr
->form_is_constant ())
14421 *offset
= attr
->constant_value (0);
14422 else if (attr
->form_is_section_offset ())
14423 dwarf2_complex_location_expr_complaint ();
14424 else if (attr
->form_is_block ())
14425 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14427 dwarf2_complex_location_expr_complaint ();
14435 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14438 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14439 struct field
*field
)
14441 struct attribute
*attr
;
14443 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14446 if (attr
->form_is_constant ())
14448 LONGEST offset
= attr
->constant_value (0);
14449 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14451 else if (attr
->form_is_section_offset ())
14452 dwarf2_complex_location_expr_complaint ();
14453 else if (attr
->form_is_block ())
14456 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14458 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14461 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14462 struct objfile
*objfile
= per_objfile
->objfile
;
14463 struct dwarf2_locexpr_baton
*dlbaton
14464 = XOBNEW (&objfile
->objfile_obstack
,
14465 struct dwarf2_locexpr_baton
);
14466 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14467 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14468 /* When using this baton, we want to compute the address
14469 of the field, not the value. This is why
14470 is_reference is set to false here. */
14471 dlbaton
->is_reference
= false;
14472 dlbaton
->per_objfile
= per_objfile
;
14473 dlbaton
->per_cu
= cu
->per_cu
;
14475 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14479 dwarf2_complex_location_expr_complaint ();
14483 /* Add an aggregate field to the field list. */
14486 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14487 struct dwarf2_cu
*cu
)
14489 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14490 struct gdbarch
*gdbarch
= objfile
->arch ();
14491 struct nextfield
*new_field
;
14492 struct attribute
*attr
;
14494 const char *fieldname
= "";
14496 if (die
->tag
== DW_TAG_inheritance
)
14498 fip
->baseclasses
.emplace_back ();
14499 new_field
= &fip
->baseclasses
.back ();
14503 fip
->fields
.emplace_back ();
14504 new_field
= &fip
->fields
.back ();
14507 new_field
->offset
= die
->sect_off
;
14509 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14510 if (attr
!= nullptr)
14511 new_field
->accessibility
= DW_UNSND (attr
);
14513 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14514 if (new_field
->accessibility
!= DW_ACCESS_public
)
14515 fip
->non_public_fields
= 1;
14517 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14518 if (attr
!= nullptr)
14519 new_field
->virtuality
= DW_UNSND (attr
);
14521 new_field
->virtuality
= DW_VIRTUALITY_none
;
14523 fp
= &new_field
->field
;
14525 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14527 /* Data member other than a C++ static data member. */
14529 /* Get type of field. */
14530 fp
->type
= die_type (die
, cu
);
14532 SET_FIELD_BITPOS (*fp
, 0);
14534 /* Get bit size of field (zero if none). */
14535 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14536 if (attr
!= nullptr)
14538 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14542 FIELD_BITSIZE (*fp
) = 0;
14545 /* Get bit offset of field. */
14546 handle_data_member_location (die
, cu
, fp
);
14547 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14548 if (attr
!= nullptr)
14550 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14552 /* For big endian bits, the DW_AT_bit_offset gives the
14553 additional bit offset from the MSB of the containing
14554 anonymous object to the MSB of the field. We don't
14555 have to do anything special since we don't need to
14556 know the size of the anonymous object. */
14557 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14561 /* For little endian bits, compute the bit offset to the
14562 MSB of the anonymous object, subtract off the number of
14563 bits from the MSB of the field to the MSB of the
14564 object, and then subtract off the number of bits of
14565 the field itself. The result is the bit offset of
14566 the LSB of the field. */
14567 int anonymous_size
;
14568 int bit_offset
= DW_UNSND (attr
);
14570 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14571 if (attr
!= nullptr)
14573 /* The size of the anonymous object containing
14574 the bit field is explicit, so use the
14575 indicated size (in bytes). */
14576 anonymous_size
= DW_UNSND (attr
);
14580 /* The size of the anonymous object containing
14581 the bit field must be inferred from the type
14582 attribute of the data member containing the
14584 anonymous_size
= TYPE_LENGTH (fp
->type
);
14586 SET_FIELD_BITPOS (*fp
,
14587 (FIELD_BITPOS (*fp
)
14588 + anonymous_size
* bits_per_byte
14589 - bit_offset
- FIELD_BITSIZE (*fp
)));
14592 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14594 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14595 + attr
->constant_value (0)));
14597 /* Get name of field. */
14598 fieldname
= dwarf2_name (die
, cu
);
14599 if (fieldname
== NULL
)
14602 /* The name is already allocated along with this objfile, so we don't
14603 need to duplicate it for the type. */
14604 fp
->name
= fieldname
;
14606 /* Change accessibility for artificial fields (e.g. virtual table
14607 pointer or virtual base class pointer) to private. */
14608 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14610 FIELD_ARTIFICIAL (*fp
) = 1;
14611 new_field
->accessibility
= DW_ACCESS_private
;
14612 fip
->non_public_fields
= 1;
14615 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14617 /* C++ static member. */
14619 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14620 is a declaration, but all versions of G++ as of this writing
14621 (so through at least 3.2.1) incorrectly generate
14622 DW_TAG_variable tags. */
14624 const char *physname
;
14626 /* Get name of field. */
14627 fieldname
= dwarf2_name (die
, cu
);
14628 if (fieldname
== NULL
)
14631 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14633 /* Only create a symbol if this is an external value.
14634 new_symbol checks this and puts the value in the global symbol
14635 table, which we want. If it is not external, new_symbol
14636 will try to put the value in cu->list_in_scope which is wrong. */
14637 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14639 /* A static const member, not much different than an enum as far as
14640 we're concerned, except that we can support more types. */
14641 new_symbol (die
, NULL
, cu
);
14644 /* Get physical name. */
14645 physname
= dwarf2_physname (fieldname
, die
, cu
);
14647 /* The name is already allocated along with this objfile, so we don't
14648 need to duplicate it for the type. */
14649 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14650 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14651 FIELD_NAME (*fp
) = fieldname
;
14653 else if (die
->tag
== DW_TAG_inheritance
)
14655 /* C++ base class field. */
14656 handle_data_member_location (die
, cu
, fp
);
14657 FIELD_BITSIZE (*fp
) = 0;
14658 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14659 FIELD_NAME (*fp
) = fp
->type
->name ();
14662 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14665 /* Can the type given by DIE define another type? */
14668 type_can_define_types (const struct die_info
*die
)
14672 case DW_TAG_typedef
:
14673 case DW_TAG_class_type
:
14674 case DW_TAG_structure_type
:
14675 case DW_TAG_union_type
:
14676 case DW_TAG_enumeration_type
:
14684 /* Add a type definition defined in the scope of the FIP's class. */
14687 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14688 struct dwarf2_cu
*cu
)
14690 struct decl_field fp
;
14691 memset (&fp
, 0, sizeof (fp
));
14693 gdb_assert (type_can_define_types (die
));
14695 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14696 fp
.name
= dwarf2_name (die
, cu
);
14697 fp
.type
= read_type_die (die
, cu
);
14699 /* Save accessibility. */
14700 enum dwarf_access_attribute accessibility
;
14701 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14703 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14705 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14706 switch (accessibility
)
14708 case DW_ACCESS_public
:
14709 /* The assumed value if neither private nor protected. */
14711 case DW_ACCESS_private
:
14714 case DW_ACCESS_protected
:
14715 fp
.is_protected
= 1;
14718 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14721 if (die
->tag
== DW_TAG_typedef
)
14722 fip
->typedef_field_list
.push_back (fp
);
14724 fip
->nested_types_list
.push_back (fp
);
14727 /* A convenience typedef that's used when finding the discriminant
14728 field for a variant part. */
14729 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14732 /* Compute the discriminant range for a given variant. OBSTACK is
14733 where the results will be stored. VARIANT is the variant to
14734 process. IS_UNSIGNED indicates whether the discriminant is signed
14737 static const gdb::array_view
<discriminant_range
>
14738 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14741 std::vector
<discriminant_range
> ranges
;
14743 if (variant
.default_branch
)
14746 if (variant
.discr_list_data
== nullptr)
14748 discriminant_range r
14749 = {variant
.discriminant_value
, variant
.discriminant_value
};
14750 ranges
.push_back (r
);
14754 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14755 variant
.discr_list_data
->size
);
14756 while (!data
.empty ())
14758 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14760 complaint (_("invalid discriminant marker: %d"), data
[0]);
14763 bool is_range
= data
[0] == DW_DSC_range
;
14764 data
= data
.slice (1);
14766 ULONGEST low
, high
;
14767 unsigned int bytes_read
;
14771 complaint (_("DW_AT_discr_list missing low value"));
14775 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14777 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14779 data
= data
.slice (bytes_read
);
14785 complaint (_("DW_AT_discr_list missing high value"));
14789 high
= read_unsigned_leb128 (nullptr, data
.data (),
14792 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14794 data
= data
.slice (bytes_read
);
14799 ranges
.push_back ({ low
, high
});
14803 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14805 std::copy (ranges
.begin (), ranges
.end (), result
);
14806 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14809 static const gdb::array_view
<variant_part
> create_variant_parts
14810 (struct obstack
*obstack
,
14811 const offset_map_type
&offset_map
,
14812 struct field_info
*fi
,
14813 const std::vector
<variant_part_builder
> &variant_parts
);
14815 /* Fill in a "struct variant" for a given variant field. RESULT is
14816 the variant to fill in. OBSTACK is where any needed allocations
14817 will be done. OFFSET_MAP holds the mapping from section offsets to
14818 fields for the type. FI describes the fields of the type we're
14819 processing. FIELD is the variant field we're converting. */
14822 create_one_variant (variant
&result
, struct obstack
*obstack
,
14823 const offset_map_type
&offset_map
,
14824 struct field_info
*fi
, const variant_field
&field
)
14826 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14827 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14828 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14829 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14830 field
.variant_parts
);
14833 /* Fill in a "struct variant_part" for a given variant part. RESULT
14834 is the variant part to fill in. OBSTACK is where any needed
14835 allocations will be done. OFFSET_MAP holds the mapping from
14836 section offsets to fields for the type. FI describes the fields of
14837 the type we're processing. BUILDER is the variant part to be
14841 create_one_variant_part (variant_part
&result
,
14842 struct obstack
*obstack
,
14843 const offset_map_type
&offset_map
,
14844 struct field_info
*fi
,
14845 const variant_part_builder
&builder
)
14847 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14848 if (iter
== offset_map
.end ())
14850 result
.discriminant_index
= -1;
14851 /* Doesn't matter. */
14852 result
.is_unsigned
= false;
14856 result
.discriminant_index
= iter
->second
;
14858 = TYPE_UNSIGNED (FIELD_TYPE
14859 (fi
->fields
[result
.discriminant_index
].field
));
14862 size_t n
= builder
.variants
.size ();
14863 variant
*output
= new (obstack
) variant
[n
];
14864 for (size_t i
= 0; i
< n
; ++i
)
14865 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14866 builder
.variants
[i
]);
14868 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14871 /* Create a vector of variant parts that can be attached to a type.
14872 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14873 holds the mapping from section offsets to fields for the type. FI
14874 describes the fields of the type we're processing. VARIANT_PARTS
14875 is the vector to convert. */
14877 static const gdb::array_view
<variant_part
>
14878 create_variant_parts (struct obstack
*obstack
,
14879 const offset_map_type
&offset_map
,
14880 struct field_info
*fi
,
14881 const std::vector
<variant_part_builder
> &variant_parts
)
14883 if (variant_parts
.empty ())
14886 size_t n
= variant_parts
.size ();
14887 variant_part
*result
= new (obstack
) variant_part
[n
];
14888 for (size_t i
= 0; i
< n
; ++i
)
14889 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14892 return gdb::array_view
<variant_part
> (result
, n
);
14895 /* Compute the variant part vector for FIP, attaching it to TYPE when
14899 add_variant_property (struct field_info
*fip
, struct type
*type
,
14900 struct dwarf2_cu
*cu
)
14902 /* Map section offsets of fields to their field index. Note the
14903 field index here does not take the number of baseclasses into
14905 offset_map_type offset_map
;
14906 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14907 offset_map
[fip
->fields
[i
].offset
] = i
;
14909 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14910 gdb::array_view
<variant_part
> parts
14911 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14912 fip
->variant_parts
);
14914 struct dynamic_prop prop
;
14915 prop
.kind
= PROP_VARIANT_PARTS
;
14916 prop
.data
.variant_parts
14917 = ((gdb::array_view
<variant_part
> *)
14918 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14920 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14923 /* Create the vector of fields, and attach it to the type. */
14926 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14927 struct dwarf2_cu
*cu
)
14929 int nfields
= fip
->nfields ();
14931 /* Record the field count, allocate space for the array of fields,
14932 and create blank accessibility bitfields if necessary. */
14933 type
->set_num_fields (nfields
);
14935 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14937 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14939 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14941 TYPE_FIELD_PRIVATE_BITS (type
) =
14942 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14943 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14945 TYPE_FIELD_PROTECTED_BITS (type
) =
14946 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14947 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14949 TYPE_FIELD_IGNORE_BITS (type
) =
14950 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14951 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14954 /* If the type has baseclasses, allocate and clear a bit vector for
14955 TYPE_FIELD_VIRTUAL_BITS. */
14956 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14958 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14959 unsigned char *pointer
;
14961 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14962 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14963 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14964 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14965 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14968 if (!fip
->variant_parts
.empty ())
14969 add_variant_property (fip
, type
, cu
);
14971 /* Copy the saved-up fields into the field vector. */
14972 for (int i
= 0; i
< nfields
; ++i
)
14974 struct nextfield
&field
14975 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14976 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14978 type
->field (i
) = field
.field
;
14979 switch (field
.accessibility
)
14981 case DW_ACCESS_private
:
14982 if (cu
->language
!= language_ada
)
14983 SET_TYPE_FIELD_PRIVATE (type
, i
);
14986 case DW_ACCESS_protected
:
14987 if (cu
->language
!= language_ada
)
14988 SET_TYPE_FIELD_PROTECTED (type
, i
);
14991 case DW_ACCESS_public
:
14995 /* Unknown accessibility. Complain and treat it as public. */
14997 complaint (_("unsupported accessibility %d"),
14998 field
.accessibility
);
15002 if (i
< fip
->baseclasses
.size ())
15004 switch (field
.virtuality
)
15006 case DW_VIRTUALITY_virtual
:
15007 case DW_VIRTUALITY_pure_virtual
:
15008 if (cu
->language
== language_ada
)
15009 error (_("unexpected virtuality in component of Ada type"));
15010 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15017 /* Return true if this member function is a constructor, false
15021 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15023 const char *fieldname
;
15024 const char *type_name
;
15027 if (die
->parent
== NULL
)
15030 if (die
->parent
->tag
!= DW_TAG_structure_type
15031 && die
->parent
->tag
!= DW_TAG_union_type
15032 && die
->parent
->tag
!= DW_TAG_class_type
)
15035 fieldname
= dwarf2_name (die
, cu
);
15036 type_name
= dwarf2_name (die
->parent
, cu
);
15037 if (fieldname
== NULL
|| type_name
== NULL
)
15040 len
= strlen (fieldname
);
15041 return (strncmp (fieldname
, type_name
, len
) == 0
15042 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15045 /* Check if the given VALUE is a recognized enum
15046 dwarf_defaulted_attribute constant according to DWARF5 spec,
15050 is_valid_DW_AT_defaulted (ULONGEST value
)
15054 case DW_DEFAULTED_no
:
15055 case DW_DEFAULTED_in_class
:
15056 case DW_DEFAULTED_out_of_class
:
15060 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15064 /* Add a member function to the proper fieldlist. */
15067 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15068 struct type
*type
, struct dwarf2_cu
*cu
)
15070 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15071 struct attribute
*attr
;
15073 struct fnfieldlist
*flp
= nullptr;
15074 struct fn_field
*fnp
;
15075 const char *fieldname
;
15076 struct type
*this_type
;
15077 enum dwarf_access_attribute accessibility
;
15079 if (cu
->language
== language_ada
)
15080 error (_("unexpected member function in Ada type"));
15082 /* Get name of member function. */
15083 fieldname
= dwarf2_name (die
, cu
);
15084 if (fieldname
== NULL
)
15087 /* Look up member function name in fieldlist. */
15088 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15090 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15092 flp
= &fip
->fnfieldlists
[i
];
15097 /* Create a new fnfieldlist if necessary. */
15098 if (flp
== nullptr)
15100 fip
->fnfieldlists
.emplace_back ();
15101 flp
= &fip
->fnfieldlists
.back ();
15102 flp
->name
= fieldname
;
15103 i
= fip
->fnfieldlists
.size () - 1;
15106 /* Create a new member function field and add it to the vector of
15108 flp
->fnfields
.emplace_back ();
15109 fnp
= &flp
->fnfields
.back ();
15111 /* Delay processing of the physname until later. */
15112 if (cu
->language
== language_cplus
)
15113 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15117 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15118 fnp
->physname
= physname
? physname
: "";
15121 fnp
->type
= alloc_type (objfile
);
15122 this_type
= read_type_die (die
, cu
);
15123 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15125 int nparams
= this_type
->num_fields ();
15127 /* TYPE is the domain of this method, and THIS_TYPE is the type
15128 of the method itself (TYPE_CODE_METHOD). */
15129 smash_to_method_type (fnp
->type
, type
,
15130 TYPE_TARGET_TYPE (this_type
),
15131 this_type
->fields (),
15132 this_type
->num_fields (),
15133 TYPE_VARARGS (this_type
));
15135 /* Handle static member functions.
15136 Dwarf2 has no clean way to discern C++ static and non-static
15137 member functions. G++ helps GDB by marking the first
15138 parameter for non-static member functions (which is the this
15139 pointer) as artificial. We obtain this information from
15140 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15141 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15142 fnp
->voffset
= VOFFSET_STATIC
;
15145 complaint (_("member function type missing for '%s'"),
15146 dwarf2_full_name (fieldname
, die
, cu
));
15148 /* Get fcontext from DW_AT_containing_type if present. */
15149 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15150 fnp
->fcontext
= die_containing_type (die
, cu
);
15152 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15153 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15155 /* Get accessibility. */
15156 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15157 if (attr
!= nullptr)
15158 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15160 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15161 switch (accessibility
)
15163 case DW_ACCESS_private
:
15164 fnp
->is_private
= 1;
15166 case DW_ACCESS_protected
:
15167 fnp
->is_protected
= 1;
15171 /* Check for artificial methods. */
15172 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15173 if (attr
&& DW_UNSND (attr
) != 0)
15174 fnp
->is_artificial
= 1;
15176 /* Check for defaulted methods. */
15177 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15178 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15179 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15181 /* Check for deleted methods. */
15182 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15183 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15184 fnp
->is_deleted
= 1;
15186 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15188 /* Get index in virtual function table if it is a virtual member
15189 function. For older versions of GCC, this is an offset in the
15190 appropriate virtual table, as specified by DW_AT_containing_type.
15191 For everyone else, it is an expression to be evaluated relative
15192 to the object address. */
15194 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15195 if (attr
!= nullptr)
15197 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15199 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15201 /* Old-style GCC. */
15202 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15204 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15205 || (DW_BLOCK (attr
)->size
> 1
15206 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15207 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15209 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15210 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15211 dwarf2_complex_location_expr_complaint ();
15213 fnp
->voffset
/= cu
->header
.addr_size
;
15217 dwarf2_complex_location_expr_complaint ();
15219 if (!fnp
->fcontext
)
15221 /* If there is no `this' field and no DW_AT_containing_type,
15222 we cannot actually find a base class context for the
15224 if (this_type
->num_fields () == 0
15225 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15227 complaint (_("cannot determine context for virtual member "
15228 "function \"%s\" (offset %s)"),
15229 fieldname
, sect_offset_str (die
->sect_off
));
15234 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15238 else if (attr
->form_is_section_offset ())
15240 dwarf2_complex_location_expr_complaint ();
15244 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15250 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15251 if (attr
&& DW_UNSND (attr
))
15253 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15254 complaint (_("Member function \"%s\" (offset %s) is virtual "
15255 "but the vtable offset is not specified"),
15256 fieldname
, sect_offset_str (die
->sect_off
));
15257 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15258 TYPE_CPLUS_DYNAMIC (type
) = 1;
15263 /* Create the vector of member function fields, and attach it to the type. */
15266 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15267 struct dwarf2_cu
*cu
)
15269 if (cu
->language
== language_ada
)
15270 error (_("unexpected member functions in Ada type"));
15272 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15273 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15275 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15277 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15279 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15280 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15282 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15283 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15284 fn_flp
->fn_fields
= (struct fn_field
*)
15285 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15287 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15288 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15291 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15294 /* Returns non-zero if NAME is the name of a vtable member in CU's
15295 language, zero otherwise. */
15297 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15299 static const char vptr
[] = "_vptr";
15301 /* Look for the C++ form of the vtable. */
15302 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15308 /* GCC outputs unnamed structures that are really pointers to member
15309 functions, with the ABI-specified layout. If TYPE describes
15310 such a structure, smash it into a member function type.
15312 GCC shouldn't do this; it should just output pointer to member DIEs.
15313 This is GCC PR debug/28767. */
15316 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15318 struct type
*pfn_type
, *self_type
, *new_type
;
15320 /* Check for a structure with no name and two children. */
15321 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15324 /* Check for __pfn and __delta members. */
15325 if (TYPE_FIELD_NAME (type
, 0) == NULL
15326 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15327 || TYPE_FIELD_NAME (type
, 1) == NULL
15328 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15331 /* Find the type of the method. */
15332 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15333 if (pfn_type
== NULL
15334 || pfn_type
->code () != TYPE_CODE_PTR
15335 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15338 /* Look for the "this" argument. */
15339 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15340 if (pfn_type
->num_fields () == 0
15341 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15342 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15345 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15346 new_type
= alloc_type (objfile
);
15347 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15348 pfn_type
->fields (), pfn_type
->num_fields (),
15349 TYPE_VARARGS (pfn_type
));
15350 smash_to_methodptr_type (type
, new_type
);
15353 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15354 appropriate error checking and issuing complaints if there is a
15358 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15360 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15362 if (attr
== nullptr)
15365 if (!attr
->form_is_constant ())
15367 complaint (_("DW_AT_alignment must have constant form"
15368 " - DIE at %s [in module %s]"),
15369 sect_offset_str (die
->sect_off
),
15370 objfile_name (cu
->per_objfile
->objfile
));
15375 if (attr
->form
== DW_FORM_sdata
)
15377 LONGEST val
= DW_SND (attr
);
15380 complaint (_("DW_AT_alignment value must not be negative"
15381 " - DIE at %s [in module %s]"),
15382 sect_offset_str (die
->sect_off
),
15383 objfile_name (cu
->per_objfile
->objfile
));
15389 align
= DW_UNSND (attr
);
15393 complaint (_("DW_AT_alignment value must not be zero"
15394 " - DIE at %s [in module %s]"),
15395 sect_offset_str (die
->sect_off
),
15396 objfile_name (cu
->per_objfile
->objfile
));
15399 if ((align
& (align
- 1)) != 0)
15401 complaint (_("DW_AT_alignment value must be a power of 2"
15402 " - DIE at %s [in module %s]"),
15403 sect_offset_str (die
->sect_off
),
15404 objfile_name (cu
->per_objfile
->objfile
));
15411 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15412 the alignment for TYPE. */
15415 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15418 if (!set_type_align (type
, get_alignment (cu
, die
)))
15419 complaint (_("DW_AT_alignment value too large"
15420 " - DIE at %s [in module %s]"),
15421 sect_offset_str (die
->sect_off
),
15422 objfile_name (cu
->per_objfile
->objfile
));
15425 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15426 constant for a type, according to DWARF5 spec, Table 5.5. */
15429 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15434 case DW_CC_pass_by_reference
:
15435 case DW_CC_pass_by_value
:
15439 complaint (_("unrecognized DW_AT_calling_convention value "
15440 "(%s) for a type"), pulongest (value
));
15445 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15446 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15447 also according to GNU-specific values (see include/dwarf2.h). */
15450 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15455 case DW_CC_program
:
15459 case DW_CC_GNU_renesas_sh
:
15460 case DW_CC_GNU_borland_fastcall_i386
:
15461 case DW_CC_GDB_IBM_OpenCL
:
15465 complaint (_("unrecognized DW_AT_calling_convention value "
15466 "(%s) for a subroutine"), pulongest (value
));
15471 /* Called when we find the DIE that starts a structure or union scope
15472 (definition) to create a type for the structure or union. Fill in
15473 the type's name and general properties; the members will not be
15474 processed until process_structure_scope. A symbol table entry for
15475 the type will also not be done until process_structure_scope (assuming
15476 the type has a name).
15478 NOTE: we need to call these functions regardless of whether or not the
15479 DIE has a DW_AT_name attribute, since it might be an anonymous
15480 structure or union. This gets the type entered into our set of
15481 user defined types. */
15483 static struct type
*
15484 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15486 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15488 struct attribute
*attr
;
15491 /* If the definition of this type lives in .debug_types, read that type.
15492 Don't follow DW_AT_specification though, that will take us back up
15493 the chain and we want to go down. */
15494 attr
= die
->attr (DW_AT_signature
);
15495 if (attr
!= nullptr)
15497 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15499 /* The type's CU may not be the same as CU.
15500 Ensure TYPE is recorded with CU in die_type_hash. */
15501 return set_die_type (die
, type
, cu
);
15504 type
= alloc_type (objfile
);
15505 INIT_CPLUS_SPECIFIC (type
);
15507 name
= dwarf2_name (die
, cu
);
15510 if (cu
->language
== language_cplus
15511 || cu
->language
== language_d
15512 || cu
->language
== language_rust
)
15514 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15516 /* dwarf2_full_name might have already finished building the DIE's
15517 type. If so, there is no need to continue. */
15518 if (get_die_type (die
, cu
) != NULL
)
15519 return get_die_type (die
, cu
);
15521 type
->set_name (full_name
);
15525 /* The name is already allocated along with this objfile, so
15526 we don't need to duplicate it for the type. */
15527 type
->set_name (name
);
15531 if (die
->tag
== DW_TAG_structure_type
)
15533 type
->set_code (TYPE_CODE_STRUCT
);
15535 else if (die
->tag
== DW_TAG_union_type
)
15537 type
->set_code (TYPE_CODE_UNION
);
15541 type
->set_code (TYPE_CODE_STRUCT
);
15544 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15545 TYPE_DECLARED_CLASS (type
) = 1;
15547 /* Store the calling convention in the type if it's available in
15548 the die. Otherwise the calling convention remains set to
15549 the default value DW_CC_normal. */
15550 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15551 if (attr
!= nullptr
15552 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15554 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15555 TYPE_CPLUS_CALLING_CONVENTION (type
)
15556 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15559 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15560 if (attr
!= nullptr)
15562 if (attr
->form_is_constant ())
15563 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15566 struct dynamic_prop prop
;
15567 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15568 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15569 TYPE_LENGTH (type
) = 0;
15574 TYPE_LENGTH (type
) = 0;
15577 maybe_set_alignment (cu
, die
, type
);
15579 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15581 /* ICC<14 does not output the required DW_AT_declaration on
15582 incomplete types, but gives them a size of zero. */
15583 TYPE_STUB (type
) = 1;
15586 TYPE_STUB_SUPPORTED (type
) = 1;
15588 if (die_is_declaration (die
, cu
))
15589 TYPE_STUB (type
) = 1;
15590 else if (attr
== NULL
&& die
->child
== NULL
15591 && producer_is_realview (cu
->producer
))
15592 /* RealView does not output the required DW_AT_declaration
15593 on incomplete types. */
15594 TYPE_STUB (type
) = 1;
15596 /* We need to add the type field to the die immediately so we don't
15597 infinitely recurse when dealing with pointers to the structure
15598 type within the structure itself. */
15599 set_die_type (die
, type
, cu
);
15601 /* set_die_type should be already done. */
15602 set_descriptive_type (type
, die
, cu
);
15607 static void handle_struct_member_die
15608 (struct die_info
*child_die
,
15610 struct field_info
*fi
,
15611 std::vector
<struct symbol
*> *template_args
,
15612 struct dwarf2_cu
*cu
);
15614 /* A helper for handle_struct_member_die that handles
15615 DW_TAG_variant_part. */
15618 handle_variant_part (struct die_info
*die
, struct type
*type
,
15619 struct field_info
*fi
,
15620 std::vector
<struct symbol
*> *template_args
,
15621 struct dwarf2_cu
*cu
)
15623 variant_part_builder
*new_part
;
15624 if (fi
->current_variant_part
== nullptr)
15626 fi
->variant_parts
.emplace_back ();
15627 new_part
= &fi
->variant_parts
.back ();
15629 else if (!fi
->current_variant_part
->processing_variant
)
15631 complaint (_("nested DW_TAG_variant_part seen "
15632 "- DIE at %s [in module %s]"),
15633 sect_offset_str (die
->sect_off
),
15634 objfile_name (cu
->per_objfile
->objfile
));
15639 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15640 current
.variant_parts
.emplace_back ();
15641 new_part
= ¤t
.variant_parts
.back ();
15644 /* When we recurse, we want callees to add to this new variant
15646 scoped_restore save_current_variant_part
15647 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15649 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15652 /* It's a univariant form, an extension we support. */
15654 else if (discr
->form_is_ref ())
15656 struct dwarf2_cu
*target_cu
= cu
;
15657 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15659 new_part
->discriminant_offset
= target_die
->sect_off
;
15663 complaint (_("DW_AT_discr does not have DIE reference form"
15664 " - DIE at %s [in module %s]"),
15665 sect_offset_str (die
->sect_off
),
15666 objfile_name (cu
->per_objfile
->objfile
));
15669 for (die_info
*child_die
= die
->child
;
15671 child_die
= child_die
->sibling
)
15672 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15675 /* A helper for handle_struct_member_die that handles
15679 handle_variant (struct die_info
*die
, struct type
*type
,
15680 struct field_info
*fi
,
15681 std::vector
<struct symbol
*> *template_args
,
15682 struct dwarf2_cu
*cu
)
15684 if (fi
->current_variant_part
== nullptr)
15686 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15687 "- DIE at %s [in module %s]"),
15688 sect_offset_str (die
->sect_off
),
15689 objfile_name (cu
->per_objfile
->objfile
));
15692 if (fi
->current_variant_part
->processing_variant
)
15694 complaint (_("nested DW_TAG_variant seen "
15695 "- DIE at %s [in module %s]"),
15696 sect_offset_str (die
->sect_off
),
15697 objfile_name (cu
->per_objfile
->objfile
));
15701 scoped_restore save_processing_variant
15702 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15705 fi
->current_variant_part
->variants
.emplace_back ();
15706 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15707 variant
.first_field
= fi
->fields
.size ();
15709 /* In a variant we want to get the discriminant and also add a
15710 field for our sole member child. */
15711 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15712 if (discr
== nullptr)
15714 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15715 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15716 variant
.default_branch
= true;
15718 variant
.discr_list_data
= DW_BLOCK (discr
);
15721 variant
.discriminant_value
= DW_UNSND (discr
);
15723 for (die_info
*variant_child
= die
->child
;
15724 variant_child
!= NULL
;
15725 variant_child
= variant_child
->sibling
)
15726 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15728 variant
.last_field
= fi
->fields
.size ();
15731 /* A helper for process_structure_scope that handles a single member
15735 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15736 struct field_info
*fi
,
15737 std::vector
<struct symbol
*> *template_args
,
15738 struct dwarf2_cu
*cu
)
15740 if (child_die
->tag
== DW_TAG_member
15741 || child_die
->tag
== DW_TAG_variable
)
15743 /* NOTE: carlton/2002-11-05: A C++ static data member
15744 should be a DW_TAG_member that is a declaration, but
15745 all versions of G++ as of this writing (so through at
15746 least 3.2.1) incorrectly generate DW_TAG_variable
15747 tags for them instead. */
15748 dwarf2_add_field (fi
, child_die
, cu
);
15750 else if (child_die
->tag
== DW_TAG_subprogram
)
15752 /* Rust doesn't have member functions in the C++ sense.
15753 However, it does emit ordinary functions as children
15754 of a struct DIE. */
15755 if (cu
->language
== language_rust
)
15756 read_func_scope (child_die
, cu
);
15759 /* C++ member function. */
15760 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15763 else if (child_die
->tag
== DW_TAG_inheritance
)
15765 /* C++ base class field. */
15766 dwarf2_add_field (fi
, child_die
, cu
);
15768 else if (type_can_define_types (child_die
))
15769 dwarf2_add_type_defn (fi
, child_die
, cu
);
15770 else if (child_die
->tag
== DW_TAG_template_type_param
15771 || child_die
->tag
== DW_TAG_template_value_param
)
15773 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15776 template_args
->push_back (arg
);
15778 else if (child_die
->tag
== DW_TAG_variant_part
)
15779 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15780 else if (child_die
->tag
== DW_TAG_variant
)
15781 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15784 /* Finish creating a structure or union type, including filling in
15785 its members and creating a symbol for it. */
15788 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15790 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15791 struct die_info
*child_die
;
15794 type
= get_die_type (die
, cu
);
15796 type
= read_structure_type (die
, cu
);
15798 bool has_template_parameters
= false;
15799 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15801 struct field_info fi
;
15802 std::vector
<struct symbol
*> template_args
;
15804 child_die
= die
->child
;
15806 while (child_die
&& child_die
->tag
)
15808 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15809 child_die
= child_die
->sibling
;
15812 /* Attach template arguments to type. */
15813 if (!template_args
.empty ())
15815 has_template_parameters
= true;
15816 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15817 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15818 TYPE_TEMPLATE_ARGUMENTS (type
)
15819 = XOBNEWVEC (&objfile
->objfile_obstack
,
15821 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15822 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15823 template_args
.data (),
15824 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15825 * sizeof (struct symbol
*)));
15828 /* Attach fields and member functions to the type. */
15829 if (fi
.nfields () > 0)
15830 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15831 if (!fi
.fnfieldlists
.empty ())
15833 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15835 /* Get the type which refers to the base class (possibly this
15836 class itself) which contains the vtable pointer for the current
15837 class from the DW_AT_containing_type attribute. This use of
15838 DW_AT_containing_type is a GNU extension. */
15840 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15842 struct type
*t
= die_containing_type (die
, cu
);
15844 set_type_vptr_basetype (type
, t
);
15849 /* Our own class provides vtbl ptr. */
15850 for (i
= t
->num_fields () - 1;
15851 i
>= TYPE_N_BASECLASSES (t
);
15854 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15856 if (is_vtable_name (fieldname
, cu
))
15858 set_type_vptr_fieldno (type
, i
);
15863 /* Complain if virtual function table field not found. */
15864 if (i
< TYPE_N_BASECLASSES (t
))
15865 complaint (_("virtual function table pointer "
15866 "not found when defining class '%s'"),
15867 type
->name () ? type
->name () : "");
15871 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15874 else if (cu
->producer
15875 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15877 /* The IBM XLC compiler does not provide direct indication
15878 of the containing type, but the vtable pointer is
15879 always named __vfp. */
15883 for (i
= type
->num_fields () - 1;
15884 i
>= TYPE_N_BASECLASSES (type
);
15887 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15889 set_type_vptr_fieldno (type
, i
);
15890 set_type_vptr_basetype (type
, type
);
15897 /* Copy fi.typedef_field_list linked list elements content into the
15898 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15899 if (!fi
.typedef_field_list
.empty ())
15901 int count
= fi
.typedef_field_list
.size ();
15903 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15904 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15905 = ((struct decl_field
*)
15907 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15908 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15910 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15911 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15914 /* Copy fi.nested_types_list linked list elements content into the
15915 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15916 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15918 int count
= fi
.nested_types_list
.size ();
15920 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15921 TYPE_NESTED_TYPES_ARRAY (type
)
15922 = ((struct decl_field
*)
15923 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15924 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15926 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15927 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15931 quirk_gcc_member_function_pointer (type
, objfile
);
15932 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15933 cu
->rust_unions
.push_back (type
);
15935 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15936 snapshots) has been known to create a die giving a declaration
15937 for a class that has, as a child, a die giving a definition for a
15938 nested class. So we have to process our children even if the
15939 current die is a declaration. Normally, of course, a declaration
15940 won't have any children at all. */
15942 child_die
= die
->child
;
15944 while (child_die
!= NULL
&& child_die
->tag
)
15946 if (child_die
->tag
== DW_TAG_member
15947 || child_die
->tag
== DW_TAG_variable
15948 || child_die
->tag
== DW_TAG_inheritance
15949 || child_die
->tag
== DW_TAG_template_value_param
15950 || child_die
->tag
== DW_TAG_template_type_param
)
15955 process_die (child_die
, cu
);
15957 child_die
= child_die
->sibling
;
15960 /* Do not consider external references. According to the DWARF standard,
15961 these DIEs are identified by the fact that they have no byte_size
15962 attribute, and a declaration attribute. */
15963 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15964 || !die_is_declaration (die
, cu
)
15965 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15967 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15969 if (has_template_parameters
)
15971 struct symtab
*symtab
;
15972 if (sym
!= nullptr)
15973 symtab
= symbol_symtab (sym
);
15974 else if (cu
->line_header
!= nullptr)
15976 /* Any related symtab will do. */
15978 = cu
->line_header
->file_names ()[0].symtab
;
15983 complaint (_("could not find suitable "
15984 "symtab for template parameter"
15985 " - DIE at %s [in module %s]"),
15986 sect_offset_str (die
->sect_off
),
15987 objfile_name (objfile
));
15990 if (symtab
!= nullptr)
15992 /* Make sure that the symtab is set on the new symbols.
15993 Even though they don't appear in this symtab directly,
15994 other parts of gdb assume that symbols do, and this is
15995 reasonably true. */
15996 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15997 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16003 /* Assuming DIE is an enumeration type, and TYPE is its associated
16004 type, update TYPE using some information only available in DIE's
16005 children. In particular, the fields are computed. */
16008 update_enumeration_type_from_children (struct die_info
*die
,
16010 struct dwarf2_cu
*cu
)
16012 struct die_info
*child_die
;
16013 int unsigned_enum
= 1;
16016 auto_obstack obstack
;
16017 std::vector
<struct field
> fields
;
16019 for (child_die
= die
->child
;
16020 child_die
!= NULL
&& child_die
->tag
;
16021 child_die
= child_die
->sibling
)
16023 struct attribute
*attr
;
16025 const gdb_byte
*bytes
;
16026 struct dwarf2_locexpr_baton
*baton
;
16029 if (child_die
->tag
!= DW_TAG_enumerator
)
16032 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16036 name
= dwarf2_name (child_die
, cu
);
16038 name
= "<anonymous enumerator>";
16040 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16041 &value
, &bytes
, &baton
);
16049 if (count_one_bits_ll (value
) >= 2)
16053 fields
.emplace_back ();
16054 struct field
&field
= fields
.back ();
16055 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16056 SET_FIELD_ENUMVAL (field
, value
);
16059 if (!fields
.empty ())
16061 type
->set_num_fields (fields
.size ());
16064 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16065 memcpy (type
->fields (), fields
.data (),
16066 sizeof (struct field
) * fields
.size ());
16070 TYPE_UNSIGNED (type
) = 1;
16072 TYPE_FLAG_ENUM (type
) = 1;
16075 /* Given a DW_AT_enumeration_type die, set its type. We do not
16076 complete the type's fields yet, or create any symbols. */
16078 static struct type
*
16079 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16081 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16083 struct attribute
*attr
;
16086 /* If the definition of this type lives in .debug_types, read that type.
16087 Don't follow DW_AT_specification though, that will take us back up
16088 the chain and we want to go down. */
16089 attr
= die
->attr (DW_AT_signature
);
16090 if (attr
!= nullptr)
16092 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16094 /* The type's CU may not be the same as CU.
16095 Ensure TYPE is recorded with CU in die_type_hash. */
16096 return set_die_type (die
, type
, cu
);
16099 type
= alloc_type (objfile
);
16101 type
->set_code (TYPE_CODE_ENUM
);
16102 name
= dwarf2_full_name (NULL
, die
, cu
);
16104 type
->set_name (name
);
16106 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16109 struct type
*underlying_type
= die_type (die
, cu
);
16111 TYPE_TARGET_TYPE (type
) = underlying_type
;
16114 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16115 if (attr
!= nullptr)
16117 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16121 TYPE_LENGTH (type
) = 0;
16124 maybe_set_alignment (cu
, die
, type
);
16126 /* The enumeration DIE can be incomplete. In Ada, any type can be
16127 declared as private in the package spec, and then defined only
16128 inside the package body. Such types are known as Taft Amendment
16129 Types. When another package uses such a type, an incomplete DIE
16130 may be generated by the compiler. */
16131 if (die_is_declaration (die
, cu
))
16132 TYPE_STUB (type
) = 1;
16134 /* If this type has an underlying type that is not a stub, then we
16135 may use its attributes. We always use the "unsigned" attribute
16136 in this situation, because ordinarily we guess whether the type
16137 is unsigned -- but the guess can be wrong and the underlying type
16138 can tell us the reality. However, we defer to a local size
16139 attribute if one exists, because this lets the compiler override
16140 the underlying type if needed. */
16141 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16143 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16144 underlying_type
= check_typedef (underlying_type
);
16145 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16146 if (TYPE_LENGTH (type
) == 0)
16147 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16148 if (TYPE_RAW_ALIGN (type
) == 0
16149 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16150 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16153 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16155 set_die_type (die
, type
, cu
);
16157 /* Finish the creation of this type by using the enum's children.
16158 Note that, as usual, this must come after set_die_type to avoid
16159 infinite recursion when trying to compute the names of the
16161 update_enumeration_type_from_children (die
, type
, cu
);
16166 /* Given a pointer to a die which begins an enumeration, process all
16167 the dies that define the members of the enumeration, and create the
16168 symbol for the enumeration type.
16170 NOTE: We reverse the order of the element list. */
16173 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16175 struct type
*this_type
;
16177 this_type
= get_die_type (die
, cu
);
16178 if (this_type
== NULL
)
16179 this_type
= read_enumeration_type (die
, cu
);
16181 if (die
->child
!= NULL
)
16183 struct die_info
*child_die
;
16186 child_die
= die
->child
;
16187 while (child_die
&& child_die
->tag
)
16189 if (child_die
->tag
!= DW_TAG_enumerator
)
16191 process_die (child_die
, cu
);
16195 name
= dwarf2_name (child_die
, cu
);
16197 new_symbol (child_die
, this_type
, cu
);
16200 child_die
= child_die
->sibling
;
16204 /* If we are reading an enum from a .debug_types unit, and the enum
16205 is a declaration, and the enum is not the signatured type in the
16206 unit, then we do not want to add a symbol for it. Adding a
16207 symbol would in some cases obscure the true definition of the
16208 enum, giving users an incomplete type when the definition is
16209 actually available. Note that we do not want to do this for all
16210 enums which are just declarations, because C++0x allows forward
16211 enum declarations. */
16212 if (cu
->per_cu
->is_debug_types
16213 && die_is_declaration (die
, cu
))
16215 struct signatured_type
*sig_type
;
16217 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16218 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16219 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16223 new_symbol (die
, this_type
, cu
);
16226 /* Extract all information from a DW_TAG_array_type DIE and put it in
16227 the DIE's type field. For now, this only handles one dimensional
16230 static struct type
*
16231 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16233 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16234 struct die_info
*child_die
;
16236 struct type
*element_type
, *range_type
, *index_type
;
16237 struct attribute
*attr
;
16239 struct dynamic_prop
*byte_stride_prop
= NULL
;
16240 unsigned int bit_stride
= 0;
16242 element_type
= die_type (die
, cu
);
16244 /* The die_type call above may have already set the type for this DIE. */
16245 type
= get_die_type (die
, cu
);
16249 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16253 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16256 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16257 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16261 complaint (_("unable to read array DW_AT_byte_stride "
16262 " - DIE at %s [in module %s]"),
16263 sect_offset_str (die
->sect_off
),
16264 objfile_name (cu
->per_objfile
->objfile
));
16265 /* Ignore this attribute. We will likely not be able to print
16266 arrays of this type correctly, but there is little we can do
16267 to help if we cannot read the attribute's value. */
16268 byte_stride_prop
= NULL
;
16272 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16274 bit_stride
= DW_UNSND (attr
);
16276 /* Irix 6.2 native cc creates array types without children for
16277 arrays with unspecified length. */
16278 if (die
->child
== NULL
)
16280 index_type
= objfile_type (objfile
)->builtin_int
;
16281 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16282 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16283 byte_stride_prop
, bit_stride
);
16284 return set_die_type (die
, type
, cu
);
16287 std::vector
<struct type
*> range_types
;
16288 child_die
= die
->child
;
16289 while (child_die
&& child_die
->tag
)
16291 if (child_die
->tag
== DW_TAG_subrange_type
)
16293 struct type
*child_type
= read_type_die (child_die
, cu
);
16295 if (child_type
!= NULL
)
16297 /* The range type was succesfully read. Save it for the
16298 array type creation. */
16299 range_types
.push_back (child_type
);
16302 child_die
= child_die
->sibling
;
16305 /* Dwarf2 dimensions are output from left to right, create the
16306 necessary array types in backwards order. */
16308 type
= element_type
;
16310 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16314 while (i
< range_types
.size ())
16315 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16316 byte_stride_prop
, bit_stride
);
16320 size_t ndim
= range_types
.size ();
16322 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16323 byte_stride_prop
, bit_stride
);
16326 /* Understand Dwarf2 support for vector types (like they occur on
16327 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16328 array type. This is not part of the Dwarf2/3 standard yet, but a
16329 custom vendor extension. The main difference between a regular
16330 array and the vector variant is that vectors are passed by value
16332 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16333 if (attr
!= nullptr)
16334 make_vector_type (type
);
16336 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16337 implementation may choose to implement triple vectors using this
16339 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16340 if (attr
!= nullptr)
16342 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16343 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16345 complaint (_("DW_AT_byte_size for array type smaller "
16346 "than the total size of elements"));
16349 name
= dwarf2_name (die
, cu
);
16351 type
->set_name (name
);
16353 maybe_set_alignment (cu
, die
, type
);
16355 /* Install the type in the die. */
16356 set_die_type (die
, type
, cu
);
16358 /* set_die_type should be already done. */
16359 set_descriptive_type (type
, die
, cu
);
16364 static enum dwarf_array_dim_ordering
16365 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16367 struct attribute
*attr
;
16369 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16371 if (attr
!= nullptr)
16372 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16374 /* GNU F77 is a special case, as at 08/2004 array type info is the
16375 opposite order to the dwarf2 specification, but data is still
16376 laid out as per normal fortran.
16378 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16379 version checking. */
16381 if (cu
->language
== language_fortran
16382 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16384 return DW_ORD_row_major
;
16387 switch (cu
->language_defn
->la_array_ordering
)
16389 case array_column_major
:
16390 return DW_ORD_col_major
;
16391 case array_row_major
:
16393 return DW_ORD_row_major
;
16397 /* Extract all information from a DW_TAG_set_type DIE and put it in
16398 the DIE's type field. */
16400 static struct type
*
16401 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16403 struct type
*domain_type
, *set_type
;
16404 struct attribute
*attr
;
16406 domain_type
= die_type (die
, cu
);
16408 /* The die_type call above may have already set the type for this DIE. */
16409 set_type
= get_die_type (die
, cu
);
16413 set_type
= create_set_type (NULL
, domain_type
);
16415 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16416 if (attr
!= nullptr)
16417 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16419 maybe_set_alignment (cu
, die
, set_type
);
16421 return set_die_type (die
, set_type
, cu
);
16424 /* A helper for read_common_block that creates a locexpr baton.
16425 SYM is the symbol which we are marking as computed.
16426 COMMON_DIE is the DIE for the common block.
16427 COMMON_LOC is the location expression attribute for the common
16429 MEMBER_LOC is the location expression attribute for the particular
16430 member of the common block that we are processing.
16431 CU is the CU from which the above come. */
16434 mark_common_block_symbol_computed (struct symbol
*sym
,
16435 struct die_info
*common_die
,
16436 struct attribute
*common_loc
,
16437 struct attribute
*member_loc
,
16438 struct dwarf2_cu
*cu
)
16440 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16441 struct objfile
*objfile
= per_objfile
->objfile
;
16442 struct dwarf2_locexpr_baton
*baton
;
16444 unsigned int cu_off
;
16445 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16446 LONGEST offset
= 0;
16448 gdb_assert (common_loc
&& member_loc
);
16449 gdb_assert (common_loc
->form_is_block ());
16450 gdb_assert (member_loc
->form_is_block ()
16451 || member_loc
->form_is_constant ());
16453 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16454 baton
->per_objfile
= per_objfile
;
16455 baton
->per_cu
= cu
->per_cu
;
16456 gdb_assert (baton
->per_cu
);
16458 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16460 if (member_loc
->form_is_constant ())
16462 offset
= member_loc
->constant_value (0);
16463 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16466 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16468 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16471 *ptr
++ = DW_OP_call4
;
16472 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16473 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16476 if (member_loc
->form_is_constant ())
16478 *ptr
++ = DW_OP_addr
;
16479 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16480 ptr
+= cu
->header
.addr_size
;
16484 /* We have to copy the data here, because DW_OP_call4 will only
16485 use a DW_AT_location attribute. */
16486 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16487 ptr
+= DW_BLOCK (member_loc
)->size
;
16490 *ptr
++ = DW_OP_plus
;
16491 gdb_assert (ptr
- baton
->data
== baton
->size
);
16493 SYMBOL_LOCATION_BATON (sym
) = baton
;
16494 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16497 /* Create appropriate locally-scoped variables for all the
16498 DW_TAG_common_block entries. Also create a struct common_block
16499 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16500 is used to separate the common blocks name namespace from regular
16504 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16506 struct attribute
*attr
;
16508 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16509 if (attr
!= nullptr)
16511 /* Support the .debug_loc offsets. */
16512 if (attr
->form_is_block ())
16516 else if (attr
->form_is_section_offset ())
16518 dwarf2_complex_location_expr_complaint ();
16523 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16524 "common block member");
16529 if (die
->child
!= NULL
)
16531 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16532 struct die_info
*child_die
;
16533 size_t n_entries
= 0, size
;
16534 struct common_block
*common_block
;
16535 struct symbol
*sym
;
16537 for (child_die
= die
->child
;
16538 child_die
&& child_die
->tag
;
16539 child_die
= child_die
->sibling
)
16542 size
= (sizeof (struct common_block
)
16543 + (n_entries
- 1) * sizeof (struct symbol
*));
16545 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16547 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16548 common_block
->n_entries
= 0;
16550 for (child_die
= die
->child
;
16551 child_die
&& child_die
->tag
;
16552 child_die
= child_die
->sibling
)
16554 /* Create the symbol in the DW_TAG_common_block block in the current
16556 sym
= new_symbol (child_die
, NULL
, cu
);
16559 struct attribute
*member_loc
;
16561 common_block
->contents
[common_block
->n_entries
++] = sym
;
16563 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16567 /* GDB has handled this for a long time, but it is
16568 not specified by DWARF. It seems to have been
16569 emitted by gfortran at least as recently as:
16570 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16571 complaint (_("Variable in common block has "
16572 "DW_AT_data_member_location "
16573 "- DIE at %s [in module %s]"),
16574 sect_offset_str (child_die
->sect_off
),
16575 objfile_name (objfile
));
16577 if (member_loc
->form_is_section_offset ())
16578 dwarf2_complex_location_expr_complaint ();
16579 else if (member_loc
->form_is_constant ()
16580 || member_loc
->form_is_block ())
16582 if (attr
!= nullptr)
16583 mark_common_block_symbol_computed (sym
, die
, attr
,
16587 dwarf2_complex_location_expr_complaint ();
16592 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16593 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16597 /* Create a type for a C++ namespace. */
16599 static struct type
*
16600 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16602 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16603 const char *previous_prefix
, *name
;
16607 /* For extensions, reuse the type of the original namespace. */
16608 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16610 struct die_info
*ext_die
;
16611 struct dwarf2_cu
*ext_cu
= cu
;
16613 ext_die
= dwarf2_extension (die
, &ext_cu
);
16614 type
= read_type_die (ext_die
, ext_cu
);
16616 /* EXT_CU may not be the same as CU.
16617 Ensure TYPE is recorded with CU in die_type_hash. */
16618 return set_die_type (die
, type
, cu
);
16621 name
= namespace_name (die
, &is_anonymous
, cu
);
16623 /* Now build the name of the current namespace. */
16625 previous_prefix
= determine_prefix (die
, cu
);
16626 if (previous_prefix
[0] != '\0')
16627 name
= typename_concat (&objfile
->objfile_obstack
,
16628 previous_prefix
, name
, 0, cu
);
16630 /* Create the type. */
16631 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16633 return set_die_type (die
, type
, cu
);
16636 /* Read a namespace scope. */
16639 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16641 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16644 /* Add a symbol associated to this if we haven't seen the namespace
16645 before. Also, add a using directive if it's an anonymous
16648 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16652 type
= read_type_die (die
, cu
);
16653 new_symbol (die
, type
, cu
);
16655 namespace_name (die
, &is_anonymous
, cu
);
16658 const char *previous_prefix
= determine_prefix (die
, cu
);
16660 std::vector
<const char *> excludes
;
16661 add_using_directive (using_directives (cu
),
16662 previous_prefix
, type
->name (), NULL
,
16663 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16667 if (die
->child
!= NULL
)
16669 struct die_info
*child_die
= die
->child
;
16671 while (child_die
&& child_die
->tag
)
16673 process_die (child_die
, cu
);
16674 child_die
= child_die
->sibling
;
16679 /* Read a Fortran module as type. This DIE can be only a declaration used for
16680 imported module. Still we need that type as local Fortran "use ... only"
16681 declaration imports depend on the created type in determine_prefix. */
16683 static struct type
*
16684 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16686 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16687 const char *module_name
;
16690 module_name
= dwarf2_name (die
, cu
);
16691 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16693 return set_die_type (die
, type
, cu
);
16696 /* Read a Fortran module. */
16699 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16701 struct die_info
*child_die
= die
->child
;
16704 type
= read_type_die (die
, cu
);
16705 new_symbol (die
, type
, cu
);
16707 while (child_die
&& child_die
->tag
)
16709 process_die (child_die
, cu
);
16710 child_die
= child_die
->sibling
;
16714 /* Return the name of the namespace represented by DIE. Set
16715 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16718 static const char *
16719 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16721 struct die_info
*current_die
;
16722 const char *name
= NULL
;
16724 /* Loop through the extensions until we find a name. */
16726 for (current_die
= die
;
16727 current_die
!= NULL
;
16728 current_die
= dwarf2_extension (die
, &cu
))
16730 /* We don't use dwarf2_name here so that we can detect the absence
16731 of a name -> anonymous namespace. */
16732 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16738 /* Is it an anonymous namespace? */
16740 *is_anonymous
= (name
== NULL
);
16742 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16747 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16748 the user defined type vector. */
16750 static struct type
*
16751 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16753 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16754 struct comp_unit_head
*cu_header
= &cu
->header
;
16756 struct attribute
*attr_byte_size
;
16757 struct attribute
*attr_address_class
;
16758 int byte_size
, addr_class
;
16759 struct type
*target_type
;
16761 target_type
= die_type (die
, cu
);
16763 /* The die_type call above may have already set the type for this DIE. */
16764 type
= get_die_type (die
, cu
);
16768 type
= lookup_pointer_type (target_type
);
16770 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16771 if (attr_byte_size
)
16772 byte_size
= DW_UNSND (attr_byte_size
);
16774 byte_size
= cu_header
->addr_size
;
16776 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16777 if (attr_address_class
)
16778 addr_class
= DW_UNSND (attr_address_class
);
16780 addr_class
= DW_ADDR_none
;
16782 ULONGEST alignment
= get_alignment (cu
, die
);
16784 /* If the pointer size, alignment, or address class is different
16785 than the default, create a type variant marked as such and set
16786 the length accordingly. */
16787 if (TYPE_LENGTH (type
) != byte_size
16788 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16789 && alignment
!= TYPE_RAW_ALIGN (type
))
16790 || addr_class
!= DW_ADDR_none
)
16792 if (gdbarch_address_class_type_flags_p (gdbarch
))
16796 type_flags
= gdbarch_address_class_type_flags
16797 (gdbarch
, byte_size
, addr_class
);
16798 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16800 type
= make_type_with_address_space (type
, type_flags
);
16802 else if (TYPE_LENGTH (type
) != byte_size
)
16804 complaint (_("invalid pointer size %d"), byte_size
);
16806 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16808 complaint (_("Invalid DW_AT_alignment"
16809 " - DIE at %s [in module %s]"),
16810 sect_offset_str (die
->sect_off
),
16811 objfile_name (cu
->per_objfile
->objfile
));
16815 /* Should we also complain about unhandled address classes? */
16819 TYPE_LENGTH (type
) = byte_size
;
16820 set_type_align (type
, alignment
);
16821 return set_die_type (die
, type
, cu
);
16824 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16825 the user defined type vector. */
16827 static struct type
*
16828 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16831 struct type
*to_type
;
16832 struct type
*domain
;
16834 to_type
= die_type (die
, cu
);
16835 domain
= die_containing_type (die
, cu
);
16837 /* The calls above may have already set the type for this DIE. */
16838 type
= get_die_type (die
, cu
);
16842 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16843 type
= lookup_methodptr_type (to_type
);
16844 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16846 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16848 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16849 to_type
->fields (), to_type
->num_fields (),
16850 TYPE_VARARGS (to_type
));
16851 type
= lookup_methodptr_type (new_type
);
16854 type
= lookup_memberptr_type (to_type
, domain
);
16856 return set_die_type (die
, type
, cu
);
16859 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16860 the user defined type vector. */
16862 static struct type
*
16863 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16864 enum type_code refcode
)
16866 struct comp_unit_head
*cu_header
= &cu
->header
;
16867 struct type
*type
, *target_type
;
16868 struct attribute
*attr
;
16870 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16872 target_type
= die_type (die
, cu
);
16874 /* The die_type call above may have already set the type for this DIE. */
16875 type
= get_die_type (die
, cu
);
16879 type
= lookup_reference_type (target_type
, refcode
);
16880 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16881 if (attr
!= nullptr)
16883 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16887 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16889 maybe_set_alignment (cu
, die
, type
);
16890 return set_die_type (die
, type
, cu
);
16893 /* Add the given cv-qualifiers to the element type of the array. GCC
16894 outputs DWARF type qualifiers that apply to an array, not the
16895 element type. But GDB relies on the array element type to carry
16896 the cv-qualifiers. This mimics section 6.7.3 of the C99
16899 static struct type
*
16900 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16901 struct type
*base_type
, int cnst
, int voltl
)
16903 struct type
*el_type
, *inner_array
;
16905 base_type
= copy_type (base_type
);
16906 inner_array
= base_type
;
16908 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16910 TYPE_TARGET_TYPE (inner_array
) =
16911 copy_type (TYPE_TARGET_TYPE (inner_array
));
16912 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16915 el_type
= TYPE_TARGET_TYPE (inner_array
);
16916 cnst
|= TYPE_CONST (el_type
);
16917 voltl
|= TYPE_VOLATILE (el_type
);
16918 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16920 return set_die_type (die
, base_type
, cu
);
16923 static struct type
*
16924 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16926 struct type
*base_type
, *cv_type
;
16928 base_type
= die_type (die
, cu
);
16930 /* The die_type call above may have already set the type for this DIE. */
16931 cv_type
= get_die_type (die
, cu
);
16935 /* In case the const qualifier is applied to an array type, the element type
16936 is so qualified, not the array type (section 6.7.3 of C99). */
16937 if (base_type
->code () == TYPE_CODE_ARRAY
)
16938 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16940 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16941 return set_die_type (die
, cv_type
, cu
);
16944 static struct type
*
16945 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16947 struct type
*base_type
, *cv_type
;
16949 base_type
= die_type (die
, cu
);
16951 /* The die_type call above may have already set the type for this DIE. */
16952 cv_type
= get_die_type (die
, cu
);
16956 /* In case the volatile qualifier is applied to an array type, the
16957 element type is so qualified, not the array type (section 6.7.3
16959 if (base_type
->code () == TYPE_CODE_ARRAY
)
16960 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16962 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16963 return set_die_type (die
, cv_type
, cu
);
16966 /* Handle DW_TAG_restrict_type. */
16968 static struct type
*
16969 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16971 struct type
*base_type
, *cv_type
;
16973 base_type
= die_type (die
, cu
);
16975 /* The die_type call above may have already set the type for this DIE. */
16976 cv_type
= get_die_type (die
, cu
);
16980 cv_type
= make_restrict_type (base_type
);
16981 return set_die_type (die
, cv_type
, cu
);
16984 /* Handle DW_TAG_atomic_type. */
16986 static struct type
*
16987 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16989 struct type
*base_type
, *cv_type
;
16991 base_type
= die_type (die
, cu
);
16993 /* The die_type call above may have already set the type for this DIE. */
16994 cv_type
= get_die_type (die
, cu
);
16998 cv_type
= make_atomic_type (base_type
);
16999 return set_die_type (die
, cv_type
, cu
);
17002 /* Extract all information from a DW_TAG_string_type DIE and add to
17003 the user defined type vector. It isn't really a user defined type,
17004 but it behaves like one, with other DIE's using an AT_user_def_type
17005 attribute to reference it. */
17007 static struct type
*
17008 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17010 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17011 struct gdbarch
*gdbarch
= objfile
->arch ();
17012 struct type
*type
, *range_type
, *index_type
, *char_type
;
17013 struct attribute
*attr
;
17014 struct dynamic_prop prop
;
17015 bool length_is_constant
= true;
17018 /* There are a couple of places where bit sizes might be made use of
17019 when parsing a DW_TAG_string_type, however, no producer that we know
17020 of make use of these. Handling bit sizes that are a multiple of the
17021 byte size is easy enough, but what about other bit sizes? Lets deal
17022 with that problem when we have to. Warn about these attributes being
17023 unsupported, then parse the type and ignore them like we always
17025 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17026 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17028 static bool warning_printed
= false;
17029 if (!warning_printed
)
17031 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17032 "currently supported on DW_TAG_string_type."));
17033 warning_printed
= true;
17037 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17038 if (attr
!= nullptr && !attr
->form_is_constant ())
17040 /* The string length describes the location at which the length of
17041 the string can be found. The size of the length field can be
17042 specified with one of the attributes below. */
17043 struct type
*prop_type
;
17044 struct attribute
*len
17045 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17046 if (len
== nullptr)
17047 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17048 if (len
!= nullptr && len
->form_is_constant ())
17050 /* Pass 0 as the default as we know this attribute is constant
17051 and the default value will not be returned. */
17052 LONGEST sz
= len
->constant_value (0);
17053 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17057 /* If the size is not specified then we assume it is the size of
17058 an address on this target. */
17059 prop_type
= cu
->addr_sized_int_type (true);
17062 /* Convert the attribute into a dynamic property. */
17063 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17066 length_is_constant
= false;
17068 else if (attr
!= nullptr)
17070 /* This DW_AT_string_length just contains the length with no
17071 indirection. There's no need to create a dynamic property in this
17072 case. Pass 0 for the default value as we know it will not be
17073 returned in this case. */
17074 length
= attr
->constant_value (0);
17076 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17078 /* We don't currently support non-constant byte sizes for strings. */
17079 length
= attr
->constant_value (1);
17083 /* Use 1 as a fallback length if we have nothing else. */
17087 index_type
= objfile_type (objfile
)->builtin_int
;
17088 if (length_is_constant
)
17089 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17092 struct dynamic_prop low_bound
;
17094 low_bound
.kind
= PROP_CONST
;
17095 low_bound
.data
.const_val
= 1;
17096 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17098 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17099 type
= create_string_type (NULL
, char_type
, range_type
);
17101 return set_die_type (die
, type
, cu
);
17104 /* Assuming that DIE corresponds to a function, returns nonzero
17105 if the function is prototyped. */
17108 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17110 struct attribute
*attr
;
17112 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17113 if (attr
&& (DW_UNSND (attr
) != 0))
17116 /* The DWARF standard implies that the DW_AT_prototyped attribute
17117 is only meaningful for C, but the concept also extends to other
17118 languages that allow unprototyped functions (Eg: Objective C).
17119 For all other languages, assume that functions are always
17121 if (cu
->language
!= language_c
17122 && cu
->language
!= language_objc
17123 && cu
->language
!= language_opencl
)
17126 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17127 prototyped and unprototyped functions; default to prototyped,
17128 since that is more common in modern code (and RealView warns
17129 about unprototyped functions). */
17130 if (producer_is_realview (cu
->producer
))
17136 /* Handle DIES due to C code like:
17140 int (*funcp)(int a, long l);
17144 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17146 static struct type
*
17147 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17149 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17150 struct type
*type
; /* Type that this function returns. */
17151 struct type
*ftype
; /* Function that returns above type. */
17152 struct attribute
*attr
;
17154 type
= die_type (die
, cu
);
17156 /* The die_type call above may have already set the type for this DIE. */
17157 ftype
= get_die_type (die
, cu
);
17161 ftype
= lookup_function_type (type
);
17163 if (prototyped_function_p (die
, cu
))
17164 TYPE_PROTOTYPED (ftype
) = 1;
17166 /* Store the calling convention in the type if it's available in
17167 the subroutine die. Otherwise set the calling convention to
17168 the default value DW_CC_normal. */
17169 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17170 if (attr
!= nullptr
17171 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17172 TYPE_CALLING_CONVENTION (ftype
)
17173 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17174 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17175 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17177 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17179 /* Record whether the function returns normally to its caller or not
17180 if the DWARF producer set that information. */
17181 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17182 if (attr
&& (DW_UNSND (attr
) != 0))
17183 TYPE_NO_RETURN (ftype
) = 1;
17185 /* We need to add the subroutine type to the die immediately so
17186 we don't infinitely recurse when dealing with parameters
17187 declared as the same subroutine type. */
17188 set_die_type (die
, ftype
, cu
);
17190 if (die
->child
!= NULL
)
17192 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17193 struct die_info
*child_die
;
17194 int nparams
, iparams
;
17196 /* Count the number of parameters.
17197 FIXME: GDB currently ignores vararg functions, but knows about
17198 vararg member functions. */
17200 child_die
= die
->child
;
17201 while (child_die
&& child_die
->tag
)
17203 if (child_die
->tag
== DW_TAG_formal_parameter
)
17205 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17206 TYPE_VARARGS (ftype
) = 1;
17207 child_die
= child_die
->sibling
;
17210 /* Allocate storage for parameters and fill them in. */
17211 ftype
->set_num_fields (nparams
);
17213 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17215 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17216 even if we error out during the parameters reading below. */
17217 for (iparams
= 0; iparams
< nparams
; iparams
++)
17218 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17221 child_die
= die
->child
;
17222 while (child_die
&& child_die
->tag
)
17224 if (child_die
->tag
== DW_TAG_formal_parameter
)
17226 struct type
*arg_type
;
17228 /* DWARF version 2 has no clean way to discern C++
17229 static and non-static member functions. G++ helps
17230 GDB by marking the first parameter for non-static
17231 member functions (which is the this pointer) as
17232 artificial. We pass this information to
17233 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17235 DWARF version 3 added DW_AT_object_pointer, which GCC
17236 4.5 does not yet generate. */
17237 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17238 if (attr
!= nullptr)
17239 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17241 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17242 arg_type
= die_type (child_die
, cu
);
17244 /* RealView does not mark THIS as const, which the testsuite
17245 expects. GCC marks THIS as const in method definitions,
17246 but not in the class specifications (GCC PR 43053). */
17247 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17248 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17251 struct dwarf2_cu
*arg_cu
= cu
;
17252 const char *name
= dwarf2_name (child_die
, cu
);
17254 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17255 if (attr
!= nullptr)
17257 /* If the compiler emits this, use it. */
17258 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17261 else if (name
&& strcmp (name
, "this") == 0)
17262 /* Function definitions will have the argument names. */
17264 else if (name
== NULL
&& iparams
== 0)
17265 /* Declarations may not have the names, so like
17266 elsewhere in GDB, assume an artificial first
17267 argument is "this". */
17271 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17275 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17278 child_die
= child_die
->sibling
;
17285 static struct type
*
17286 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17288 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17289 const char *name
= NULL
;
17290 struct type
*this_type
, *target_type
;
17292 name
= dwarf2_full_name (NULL
, die
, cu
);
17293 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17294 TYPE_TARGET_STUB (this_type
) = 1;
17295 set_die_type (die
, this_type
, cu
);
17296 target_type
= die_type (die
, cu
);
17297 if (target_type
!= this_type
)
17298 TYPE_TARGET_TYPE (this_type
) = target_type
;
17301 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17302 spec and cause infinite loops in GDB. */
17303 complaint (_("Self-referential DW_TAG_typedef "
17304 "- DIE at %s [in module %s]"),
17305 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17306 TYPE_TARGET_TYPE (this_type
) = NULL
;
17310 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17311 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17312 Handle these by just returning the target type, rather than
17313 constructing an anonymous typedef type and trying to handle this
17315 set_die_type (die
, target_type
, cu
);
17316 return target_type
;
17321 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17322 (which may be different from NAME) to the architecture back-end to allow
17323 it to guess the correct format if necessary. */
17325 static struct type
*
17326 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17327 const char *name_hint
, enum bfd_endian byte_order
)
17329 struct gdbarch
*gdbarch
= objfile
->arch ();
17330 const struct floatformat
**format
;
17333 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17335 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17337 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17342 /* Allocate an integer type of size BITS and name NAME. */
17344 static struct type
*
17345 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17346 int bits
, int unsigned_p
, const char *name
)
17350 /* Versions of Intel's C Compiler generate an integer type called "void"
17351 instead of using DW_TAG_unspecified_type. This has been seen on
17352 at least versions 14, 17, and 18. */
17353 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17354 && strcmp (name
, "void") == 0)
17355 type
= objfile_type (objfile
)->builtin_void
;
17357 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17362 /* Initialise and return a floating point type of size BITS suitable for
17363 use as a component of a complex number. The NAME_HINT is passed through
17364 when initialising the floating point type and is the name of the complex
17367 As DWARF doesn't currently provide an explicit name for the components
17368 of a complex number, but it can be helpful to have these components
17369 named, we try to select a suitable name based on the size of the
17371 static struct type
*
17372 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17373 struct objfile
*objfile
,
17374 int bits
, const char *name_hint
,
17375 enum bfd_endian byte_order
)
17377 gdbarch
*gdbarch
= objfile
->arch ();
17378 struct type
*tt
= nullptr;
17380 /* Try to find a suitable floating point builtin type of size BITS.
17381 We're going to use the name of this type as the name for the complex
17382 target type that we are about to create. */
17383 switch (cu
->language
)
17385 case language_fortran
:
17389 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17392 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17394 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17396 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17404 tt
= builtin_type (gdbarch
)->builtin_float
;
17407 tt
= builtin_type (gdbarch
)->builtin_double
;
17409 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17411 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17417 /* If the type we found doesn't match the size we were looking for, then
17418 pretend we didn't find a type at all, the complex target type we
17419 create will then be nameless. */
17420 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17423 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17424 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17427 /* Find a representation of a given base type and install
17428 it in the TYPE field of the die. */
17430 static struct type
*
17431 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17433 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17435 struct attribute
*attr
;
17436 int encoding
= 0, bits
= 0;
17440 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17441 if (attr
!= nullptr)
17442 encoding
= DW_UNSND (attr
);
17443 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17444 if (attr
!= nullptr)
17445 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17446 name
= dwarf2_name (die
, cu
);
17448 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17450 arch
= objfile
->arch ();
17451 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17453 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17456 int endianity
= DW_UNSND (attr
);
17461 byte_order
= BFD_ENDIAN_BIG
;
17463 case DW_END_little
:
17464 byte_order
= BFD_ENDIAN_LITTLE
;
17467 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17474 case DW_ATE_address
:
17475 /* Turn DW_ATE_address into a void * pointer. */
17476 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17477 type
= init_pointer_type (objfile
, bits
, name
, type
);
17479 case DW_ATE_boolean
:
17480 type
= init_boolean_type (objfile
, bits
, 1, name
);
17482 case DW_ATE_complex_float
:
17483 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17485 if (type
->code () == TYPE_CODE_ERROR
)
17487 if (name
== nullptr)
17489 struct obstack
*obstack
17490 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17491 name
= obconcat (obstack
, "_Complex ", type
->name (),
17494 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17497 type
= init_complex_type (name
, type
);
17499 case DW_ATE_decimal_float
:
17500 type
= init_decfloat_type (objfile
, bits
, name
);
17503 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17505 case DW_ATE_signed
:
17506 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17508 case DW_ATE_unsigned
:
17509 if (cu
->language
== language_fortran
17511 && startswith (name
, "character("))
17512 type
= init_character_type (objfile
, bits
, 1, name
);
17514 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17516 case DW_ATE_signed_char
:
17517 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17518 || cu
->language
== language_pascal
17519 || cu
->language
== language_fortran
)
17520 type
= init_character_type (objfile
, bits
, 0, name
);
17522 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17524 case DW_ATE_unsigned_char
:
17525 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17526 || cu
->language
== language_pascal
17527 || cu
->language
== language_fortran
17528 || cu
->language
== language_rust
)
17529 type
= init_character_type (objfile
, bits
, 1, name
);
17531 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17536 type
= builtin_type (arch
)->builtin_char16
;
17537 else if (bits
== 32)
17538 type
= builtin_type (arch
)->builtin_char32
;
17541 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17543 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17545 return set_die_type (die
, type
, cu
);
17550 complaint (_("unsupported DW_AT_encoding: '%s'"),
17551 dwarf_type_encoding_name (encoding
));
17552 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17556 if (name
&& strcmp (name
, "char") == 0)
17557 TYPE_NOSIGN (type
) = 1;
17559 maybe_set_alignment (cu
, die
, type
);
17561 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17563 return set_die_type (die
, type
, cu
);
17566 /* Parse dwarf attribute if it's a block, reference or constant and put the
17567 resulting value of the attribute into struct bound_prop.
17568 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17571 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17572 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17573 struct type
*default_type
)
17575 struct dwarf2_property_baton
*baton
;
17576 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17577 struct objfile
*objfile
= per_objfile
->objfile
;
17578 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17580 gdb_assert (default_type
!= NULL
);
17582 if (attr
== NULL
|| prop
== NULL
)
17585 if (attr
->form_is_block ())
17587 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17588 baton
->property_type
= default_type
;
17589 baton
->locexpr
.per_cu
= cu
->per_cu
;
17590 baton
->locexpr
.per_objfile
= per_objfile
;
17591 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17592 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17593 switch (attr
->name
)
17595 case DW_AT_string_length
:
17596 baton
->locexpr
.is_reference
= true;
17599 baton
->locexpr
.is_reference
= false;
17602 prop
->data
.baton
= baton
;
17603 prop
->kind
= PROP_LOCEXPR
;
17604 gdb_assert (prop
->data
.baton
!= NULL
);
17606 else if (attr
->form_is_ref ())
17608 struct dwarf2_cu
*target_cu
= cu
;
17609 struct die_info
*target_die
;
17610 struct attribute
*target_attr
;
17612 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17613 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17614 if (target_attr
== NULL
)
17615 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17617 if (target_attr
== NULL
)
17620 switch (target_attr
->name
)
17622 case DW_AT_location
:
17623 if (target_attr
->form_is_section_offset ())
17625 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17626 baton
->property_type
= die_type (target_die
, target_cu
);
17627 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17628 prop
->data
.baton
= baton
;
17629 prop
->kind
= PROP_LOCLIST
;
17630 gdb_assert (prop
->data
.baton
!= NULL
);
17632 else if (target_attr
->form_is_block ())
17634 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17635 baton
->property_type
= die_type (target_die
, target_cu
);
17636 baton
->locexpr
.per_cu
= cu
->per_cu
;
17637 baton
->locexpr
.per_objfile
= per_objfile
;
17638 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17639 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17640 baton
->locexpr
.is_reference
= true;
17641 prop
->data
.baton
= baton
;
17642 prop
->kind
= PROP_LOCEXPR
;
17643 gdb_assert (prop
->data
.baton
!= NULL
);
17647 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17648 "dynamic property");
17652 case DW_AT_data_member_location
:
17656 if (!handle_data_member_location (target_die
, target_cu
,
17660 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17661 baton
->property_type
= read_type_die (target_die
->parent
,
17663 baton
->offset_info
.offset
= offset
;
17664 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17665 prop
->data
.baton
= baton
;
17666 prop
->kind
= PROP_ADDR_OFFSET
;
17671 else if (attr
->form_is_constant ())
17673 prop
->data
.const_val
= attr
->constant_value (0);
17674 prop
->kind
= PROP_CONST
;
17678 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17679 dwarf2_name (die
, cu
));
17689 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17691 struct type
*int_type
;
17693 /* Helper macro to examine the various builtin types. */
17694 #define TRY_TYPE(F) \
17695 int_type = (unsigned_p \
17696 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17697 : objfile_type (objfile)->builtin_ ## F); \
17698 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17705 TRY_TYPE (long_long
);
17709 gdb_assert_not_reached ("unable to find suitable integer type");
17715 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17717 int addr_size
= this->per_cu
->addr_size ();
17718 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17721 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17722 present (which is valid) then compute the default type based on the
17723 compilation units address size. */
17725 static struct type
*
17726 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17728 struct type
*index_type
= die_type (die
, cu
);
17730 /* Dwarf-2 specifications explicitly allows to create subrange types
17731 without specifying a base type.
17732 In that case, the base type must be set to the type of
17733 the lower bound, upper bound or count, in that order, if any of these
17734 three attributes references an object that has a type.
17735 If no base type is found, the Dwarf-2 specifications say that
17736 a signed integer type of size equal to the size of an address should
17738 For the following C code: `extern char gdb_int [];'
17739 GCC produces an empty range DIE.
17740 FIXME: muller/2010-05-28: Possible references to object for low bound,
17741 high bound or count are not yet handled by this code. */
17742 if (index_type
->code () == TYPE_CODE_VOID
)
17743 index_type
= cu
->addr_sized_int_type (false);
17748 /* Read the given DW_AT_subrange DIE. */
17750 static struct type
*
17751 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17753 struct type
*base_type
, *orig_base_type
;
17754 struct type
*range_type
;
17755 struct attribute
*attr
;
17756 struct dynamic_prop low
, high
;
17757 int low_default_is_valid
;
17758 int high_bound_is_count
= 0;
17760 ULONGEST negative_mask
;
17762 orig_base_type
= read_subrange_index_type (die
, cu
);
17764 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17765 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17766 creating the range type, but we use the result of check_typedef
17767 when examining properties of the type. */
17768 base_type
= check_typedef (orig_base_type
);
17770 /* The die_type call above may have already set the type for this DIE. */
17771 range_type
= get_die_type (die
, cu
);
17775 low
.kind
= PROP_CONST
;
17776 high
.kind
= PROP_CONST
;
17777 high
.data
.const_val
= 0;
17779 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17780 omitting DW_AT_lower_bound. */
17781 switch (cu
->language
)
17784 case language_cplus
:
17785 low
.data
.const_val
= 0;
17786 low_default_is_valid
= 1;
17788 case language_fortran
:
17789 low
.data
.const_val
= 1;
17790 low_default_is_valid
= 1;
17793 case language_objc
:
17794 case language_rust
:
17795 low
.data
.const_val
= 0;
17796 low_default_is_valid
= (cu
->header
.version
>= 4);
17800 case language_pascal
:
17801 low
.data
.const_val
= 1;
17802 low_default_is_valid
= (cu
->header
.version
>= 4);
17805 low
.data
.const_val
= 0;
17806 low_default_is_valid
= 0;
17810 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17811 if (attr
!= nullptr)
17812 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17813 else if (!low_default_is_valid
)
17814 complaint (_("Missing DW_AT_lower_bound "
17815 "- DIE at %s [in module %s]"),
17816 sect_offset_str (die
->sect_off
),
17817 objfile_name (cu
->per_objfile
->objfile
));
17819 struct attribute
*attr_ub
, *attr_count
;
17820 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17821 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17823 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17824 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17826 /* If bounds are constant do the final calculation here. */
17827 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17828 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17830 high_bound_is_count
= 1;
17834 if (attr_ub
!= NULL
)
17835 complaint (_("Unresolved DW_AT_upper_bound "
17836 "- DIE at %s [in module %s]"),
17837 sect_offset_str (die
->sect_off
),
17838 objfile_name (cu
->per_objfile
->objfile
));
17839 if (attr_count
!= NULL
)
17840 complaint (_("Unresolved DW_AT_count "
17841 "- DIE at %s [in module %s]"),
17842 sect_offset_str (die
->sect_off
),
17843 objfile_name (cu
->per_objfile
->objfile
));
17848 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17849 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17850 bias
= bias_attr
->constant_value (0);
17852 /* Normally, the DWARF producers are expected to use a signed
17853 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17854 But this is unfortunately not always the case, as witnessed
17855 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17856 is used instead. To work around that ambiguity, we treat
17857 the bounds as signed, and thus sign-extend their values, when
17858 the base type is signed. */
17860 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17861 if (low
.kind
== PROP_CONST
17862 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17863 low
.data
.const_val
|= negative_mask
;
17864 if (high
.kind
== PROP_CONST
17865 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17866 high
.data
.const_val
|= negative_mask
;
17868 /* Check for bit and byte strides. */
17869 struct dynamic_prop byte_stride_prop
;
17870 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17871 if (attr_byte_stride
!= nullptr)
17873 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17874 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17878 struct dynamic_prop bit_stride_prop
;
17879 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17880 if (attr_bit_stride
!= nullptr)
17882 /* It only makes sense to have either a bit or byte stride. */
17883 if (attr_byte_stride
!= nullptr)
17885 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17886 "- DIE at %s [in module %s]"),
17887 sect_offset_str (die
->sect_off
),
17888 objfile_name (cu
->per_objfile
->objfile
));
17889 attr_bit_stride
= nullptr;
17893 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17894 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17899 if (attr_byte_stride
!= nullptr
17900 || attr_bit_stride
!= nullptr)
17902 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17903 struct dynamic_prop
*stride
17904 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17907 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17908 &high
, bias
, stride
, byte_stride_p
);
17911 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17913 if (high_bound_is_count
)
17914 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17916 /* Ada expects an empty array on no boundary attributes. */
17917 if (attr
== NULL
&& cu
->language
!= language_ada
)
17918 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17920 name
= dwarf2_name (die
, cu
);
17922 range_type
->set_name (name
);
17924 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17925 if (attr
!= nullptr)
17926 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17928 maybe_set_alignment (cu
, die
, range_type
);
17930 set_die_type (die
, range_type
, cu
);
17932 /* set_die_type should be already done. */
17933 set_descriptive_type (range_type
, die
, cu
);
17938 static struct type
*
17939 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17943 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17944 type
->set_name (dwarf2_name (die
, cu
));
17946 /* In Ada, an unspecified type is typically used when the description
17947 of the type is deferred to a different unit. When encountering
17948 such a type, we treat it as a stub, and try to resolve it later on,
17950 if (cu
->language
== language_ada
)
17951 TYPE_STUB (type
) = 1;
17953 return set_die_type (die
, type
, cu
);
17956 /* Read a single die and all its descendents. Set the die's sibling
17957 field to NULL; set other fields in the die correctly, and set all
17958 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17959 location of the info_ptr after reading all of those dies. PARENT
17960 is the parent of the die in question. */
17962 static struct die_info
*
17963 read_die_and_children (const struct die_reader_specs
*reader
,
17964 const gdb_byte
*info_ptr
,
17965 const gdb_byte
**new_info_ptr
,
17966 struct die_info
*parent
)
17968 struct die_info
*die
;
17969 const gdb_byte
*cur_ptr
;
17971 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17974 *new_info_ptr
= cur_ptr
;
17977 store_in_ref_table (die
, reader
->cu
);
17979 if (die
->has_children
)
17980 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17984 *new_info_ptr
= cur_ptr
;
17987 die
->sibling
= NULL
;
17988 die
->parent
= parent
;
17992 /* Read a die, all of its descendents, and all of its siblings; set
17993 all of the fields of all of the dies correctly. Arguments are as
17994 in read_die_and_children. */
17996 static struct die_info
*
17997 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17998 const gdb_byte
*info_ptr
,
17999 const gdb_byte
**new_info_ptr
,
18000 struct die_info
*parent
)
18002 struct die_info
*first_die
, *last_sibling
;
18003 const gdb_byte
*cur_ptr
;
18005 cur_ptr
= info_ptr
;
18006 first_die
= last_sibling
= NULL
;
18010 struct die_info
*die
18011 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18015 *new_info_ptr
= cur_ptr
;
18022 last_sibling
->sibling
= die
;
18024 last_sibling
= die
;
18028 /* Read a die, all of its descendents, and all of its siblings; set
18029 all of the fields of all of the dies correctly. Arguments are as
18030 in read_die_and_children.
18031 This the main entry point for reading a DIE and all its children. */
18033 static struct die_info
*
18034 read_die_and_siblings (const struct die_reader_specs
*reader
,
18035 const gdb_byte
*info_ptr
,
18036 const gdb_byte
**new_info_ptr
,
18037 struct die_info
*parent
)
18039 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18040 new_info_ptr
, parent
);
18042 if (dwarf_die_debug
)
18044 fprintf_unfiltered (gdb_stdlog
,
18045 "Read die from %s@0x%x of %s:\n",
18046 reader
->die_section
->get_name (),
18047 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18048 bfd_get_filename (reader
->abfd
));
18049 dump_die (die
, dwarf_die_debug
);
18055 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18057 The caller is responsible for filling in the extra attributes
18058 and updating (*DIEP)->num_attrs.
18059 Set DIEP to point to a newly allocated die with its information,
18060 except for its child, sibling, and parent fields. */
18062 static const gdb_byte
*
18063 read_full_die_1 (const struct die_reader_specs
*reader
,
18064 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18065 int num_extra_attrs
)
18067 unsigned int abbrev_number
, bytes_read
, i
;
18068 struct abbrev_info
*abbrev
;
18069 struct die_info
*die
;
18070 struct dwarf2_cu
*cu
= reader
->cu
;
18071 bfd
*abfd
= reader
->abfd
;
18073 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18074 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18075 info_ptr
+= bytes_read
;
18076 if (!abbrev_number
)
18082 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18084 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18086 bfd_get_filename (abfd
));
18088 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18089 die
->sect_off
= sect_off
;
18090 die
->tag
= abbrev
->tag
;
18091 die
->abbrev
= abbrev_number
;
18092 die
->has_children
= abbrev
->has_children
;
18094 /* Make the result usable.
18095 The caller needs to update num_attrs after adding the extra
18097 die
->num_attrs
= abbrev
->num_attrs
;
18099 std::vector
<int> indexes_that_need_reprocess
;
18100 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18102 bool need_reprocess
;
18104 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18105 info_ptr
, &need_reprocess
);
18106 if (need_reprocess
)
18107 indexes_that_need_reprocess
.push_back (i
);
18110 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18111 if (attr
!= nullptr)
18112 cu
->str_offsets_base
= DW_UNSND (attr
);
18114 attr
= die
->attr (DW_AT_loclists_base
);
18115 if (attr
!= nullptr)
18116 cu
->loclist_base
= DW_UNSND (attr
);
18118 auto maybe_addr_base
= die
->addr_base ();
18119 if (maybe_addr_base
.has_value ())
18120 cu
->addr_base
= *maybe_addr_base
;
18121 for (int index
: indexes_that_need_reprocess
)
18122 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18127 /* Read a die and all its attributes.
18128 Set DIEP to point to a newly allocated die with its information,
18129 except for its child, sibling, and parent fields. */
18131 static const gdb_byte
*
18132 read_full_die (const struct die_reader_specs
*reader
,
18133 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18135 const gdb_byte
*result
;
18137 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18139 if (dwarf_die_debug
)
18141 fprintf_unfiltered (gdb_stdlog
,
18142 "Read die from %s@0x%x of %s:\n",
18143 reader
->die_section
->get_name (),
18144 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18145 bfd_get_filename (reader
->abfd
));
18146 dump_die (*diep
, dwarf_die_debug
);
18153 /* Returns nonzero if TAG represents a type that we might generate a partial
18157 is_type_tag_for_partial (int tag
)
18162 /* Some types that would be reasonable to generate partial symbols for,
18163 that we don't at present. */
18164 case DW_TAG_array_type
:
18165 case DW_TAG_file_type
:
18166 case DW_TAG_ptr_to_member_type
:
18167 case DW_TAG_set_type
:
18168 case DW_TAG_string_type
:
18169 case DW_TAG_subroutine_type
:
18171 case DW_TAG_base_type
:
18172 case DW_TAG_class_type
:
18173 case DW_TAG_interface_type
:
18174 case DW_TAG_enumeration_type
:
18175 case DW_TAG_structure_type
:
18176 case DW_TAG_subrange_type
:
18177 case DW_TAG_typedef
:
18178 case DW_TAG_union_type
:
18185 /* Load all DIEs that are interesting for partial symbols into memory. */
18187 static struct partial_die_info
*
18188 load_partial_dies (const struct die_reader_specs
*reader
,
18189 const gdb_byte
*info_ptr
, int building_psymtab
)
18191 struct dwarf2_cu
*cu
= reader
->cu
;
18192 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18193 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18194 unsigned int bytes_read
;
18195 unsigned int load_all
= 0;
18196 int nesting_level
= 1;
18201 gdb_assert (cu
->per_cu
!= NULL
);
18202 if (cu
->per_cu
->load_all_dies
)
18206 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18210 &cu
->comp_unit_obstack
,
18211 hashtab_obstack_allocate
,
18212 dummy_obstack_deallocate
);
18216 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18218 /* A NULL abbrev means the end of a series of children. */
18219 if (abbrev
== NULL
)
18221 if (--nesting_level
== 0)
18224 info_ptr
+= bytes_read
;
18225 last_die
= parent_die
;
18226 parent_die
= parent_die
->die_parent
;
18230 /* Check for template arguments. We never save these; if
18231 they're seen, we just mark the parent, and go on our way. */
18232 if (parent_die
!= NULL
18233 && cu
->language
== language_cplus
18234 && (abbrev
->tag
== DW_TAG_template_type_param
18235 || abbrev
->tag
== DW_TAG_template_value_param
))
18237 parent_die
->has_template_arguments
= 1;
18241 /* We don't need a partial DIE for the template argument. */
18242 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18247 /* We only recurse into c++ subprograms looking for template arguments.
18248 Skip their other children. */
18250 && cu
->language
== language_cplus
18251 && parent_die
!= NULL
18252 && parent_die
->tag
== DW_TAG_subprogram
18253 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18255 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18259 /* Check whether this DIE is interesting enough to save. Normally
18260 we would not be interested in members here, but there may be
18261 later variables referencing them via DW_AT_specification (for
18262 static members). */
18264 && !is_type_tag_for_partial (abbrev
->tag
)
18265 && abbrev
->tag
!= DW_TAG_constant
18266 && abbrev
->tag
!= DW_TAG_enumerator
18267 && abbrev
->tag
!= DW_TAG_subprogram
18268 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18269 && abbrev
->tag
!= DW_TAG_lexical_block
18270 && abbrev
->tag
!= DW_TAG_variable
18271 && abbrev
->tag
!= DW_TAG_namespace
18272 && abbrev
->tag
!= DW_TAG_module
18273 && abbrev
->tag
!= DW_TAG_member
18274 && abbrev
->tag
!= DW_TAG_imported_unit
18275 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18277 /* Otherwise we skip to the next sibling, if any. */
18278 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18282 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18285 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18287 /* This two-pass algorithm for processing partial symbols has a
18288 high cost in cache pressure. Thus, handle some simple cases
18289 here which cover the majority of C partial symbols. DIEs
18290 which neither have specification tags in them, nor could have
18291 specification tags elsewhere pointing at them, can simply be
18292 processed and discarded.
18294 This segment is also optional; scan_partial_symbols and
18295 add_partial_symbol will handle these DIEs if we chain
18296 them in normally. When compilers which do not emit large
18297 quantities of duplicate debug information are more common,
18298 this code can probably be removed. */
18300 /* Any complete simple types at the top level (pretty much all
18301 of them, for a language without namespaces), can be processed
18303 if (parent_die
== NULL
18304 && pdi
.has_specification
== 0
18305 && pdi
.is_declaration
== 0
18306 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18307 || pdi
.tag
== DW_TAG_base_type
18308 || pdi
.tag
== DW_TAG_subrange_type
))
18310 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18311 add_partial_symbol (&pdi
, cu
);
18313 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18317 /* The exception for DW_TAG_typedef with has_children above is
18318 a workaround of GCC PR debug/47510. In the case of this complaint
18319 type_name_or_error will error on such types later.
18321 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18322 it could not find the child DIEs referenced later, this is checked
18323 above. In correct DWARF DW_TAG_typedef should have no children. */
18325 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18326 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18327 "- DIE at %s [in module %s]"),
18328 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18330 /* If we're at the second level, and we're an enumerator, and
18331 our parent has no specification (meaning possibly lives in a
18332 namespace elsewhere), then we can add the partial symbol now
18333 instead of queueing it. */
18334 if (pdi
.tag
== DW_TAG_enumerator
18335 && parent_die
!= NULL
18336 && parent_die
->die_parent
== NULL
18337 && parent_die
->tag
== DW_TAG_enumeration_type
18338 && parent_die
->has_specification
== 0)
18340 if (pdi
.raw_name
== NULL
)
18341 complaint (_("malformed enumerator DIE ignored"));
18342 else if (building_psymtab
)
18343 add_partial_symbol (&pdi
, cu
);
18345 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18349 struct partial_die_info
*part_die
18350 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18352 /* We'll save this DIE so link it in. */
18353 part_die
->die_parent
= parent_die
;
18354 part_die
->die_sibling
= NULL
;
18355 part_die
->die_child
= NULL
;
18357 if (last_die
&& last_die
== parent_die
)
18358 last_die
->die_child
= part_die
;
18360 last_die
->die_sibling
= part_die
;
18362 last_die
= part_die
;
18364 if (first_die
== NULL
)
18365 first_die
= part_die
;
18367 /* Maybe add the DIE to the hash table. Not all DIEs that we
18368 find interesting need to be in the hash table, because we
18369 also have the parent/sibling/child chains; only those that we
18370 might refer to by offset later during partial symbol reading.
18372 For now this means things that might have be the target of a
18373 DW_AT_specification, DW_AT_abstract_origin, or
18374 DW_AT_extension. DW_AT_extension will refer only to
18375 namespaces; DW_AT_abstract_origin refers to functions (and
18376 many things under the function DIE, but we do not recurse
18377 into function DIEs during partial symbol reading) and
18378 possibly variables as well; DW_AT_specification refers to
18379 declarations. Declarations ought to have the DW_AT_declaration
18380 flag. It happens that GCC forgets to put it in sometimes, but
18381 only for functions, not for types.
18383 Adding more things than necessary to the hash table is harmless
18384 except for the performance cost. Adding too few will result in
18385 wasted time in find_partial_die, when we reread the compilation
18386 unit with load_all_dies set. */
18389 || abbrev
->tag
== DW_TAG_constant
18390 || abbrev
->tag
== DW_TAG_subprogram
18391 || abbrev
->tag
== DW_TAG_variable
18392 || abbrev
->tag
== DW_TAG_namespace
18393 || part_die
->is_declaration
)
18397 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18398 to_underlying (part_die
->sect_off
),
18403 /* For some DIEs we want to follow their children (if any). For C
18404 we have no reason to follow the children of structures; for other
18405 languages we have to, so that we can get at method physnames
18406 to infer fully qualified class names, for DW_AT_specification,
18407 and for C++ template arguments. For C++, we also look one level
18408 inside functions to find template arguments (if the name of the
18409 function does not already contain the template arguments).
18411 For Ada and Fortran, we need to scan the children of subprograms
18412 and lexical blocks as well because these languages allow the
18413 definition of nested entities that could be interesting for the
18414 debugger, such as nested subprograms for instance. */
18415 if (last_die
->has_children
18417 || last_die
->tag
== DW_TAG_namespace
18418 || last_die
->tag
== DW_TAG_module
18419 || last_die
->tag
== DW_TAG_enumeration_type
18420 || (cu
->language
== language_cplus
18421 && last_die
->tag
== DW_TAG_subprogram
18422 && (last_die
->raw_name
== NULL
18423 || strchr (last_die
->raw_name
, '<') == NULL
))
18424 || (cu
->language
!= language_c
18425 && (last_die
->tag
== DW_TAG_class_type
18426 || last_die
->tag
== DW_TAG_interface_type
18427 || last_die
->tag
== DW_TAG_structure_type
18428 || last_die
->tag
== DW_TAG_union_type
))
18429 || ((cu
->language
== language_ada
18430 || cu
->language
== language_fortran
)
18431 && (last_die
->tag
== DW_TAG_subprogram
18432 || last_die
->tag
== DW_TAG_lexical_block
))))
18435 parent_die
= last_die
;
18439 /* Otherwise we skip to the next sibling, if any. */
18440 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18442 /* Back to the top, do it again. */
18446 partial_die_info::partial_die_info (sect_offset sect_off_
,
18447 struct abbrev_info
*abbrev
)
18448 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18452 /* See class definition. */
18455 partial_die_info::name (dwarf2_cu
*cu
)
18457 if (!canonical_name
&& raw_name
!= nullptr)
18459 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18460 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
18461 canonical_name
= 1;
18467 /* Read a minimal amount of information into the minimal die structure.
18468 INFO_PTR should point just after the initial uleb128 of a DIE. */
18471 partial_die_info::read (const struct die_reader_specs
*reader
,
18472 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18474 struct dwarf2_cu
*cu
= reader
->cu
;
18475 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18477 int has_low_pc_attr
= 0;
18478 int has_high_pc_attr
= 0;
18479 int high_pc_relative
= 0;
18481 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18484 bool need_reprocess
;
18485 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18486 info_ptr
, &need_reprocess
);
18487 /* String and address offsets that need to do the reprocessing have
18488 already been read at this point, so there is no need to wait until
18489 the loop terminates to do the reprocessing. */
18490 if (need_reprocess
)
18491 read_attribute_reprocess (reader
, &attr
);
18492 /* Store the data if it is of an attribute we want to keep in a
18493 partial symbol table. */
18499 case DW_TAG_compile_unit
:
18500 case DW_TAG_partial_unit
:
18501 case DW_TAG_type_unit
:
18502 /* Compilation units have a DW_AT_name that is a filename, not
18503 a source language identifier. */
18504 case DW_TAG_enumeration_type
:
18505 case DW_TAG_enumerator
:
18506 /* These tags always have simple identifiers already; no need
18507 to canonicalize them. */
18508 canonical_name
= 1;
18509 raw_name
= DW_STRING (&attr
);
18512 canonical_name
= 0;
18513 raw_name
= DW_STRING (&attr
);
18517 case DW_AT_linkage_name
:
18518 case DW_AT_MIPS_linkage_name
:
18519 /* Note that both forms of linkage name might appear. We
18520 assume they will be the same, and we only store the last
18522 linkage_name
= attr
.value_as_string ();
18523 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18524 See https://github.com/rust-lang/rust/issues/32925. */
18525 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18526 && strchr (linkage_name
, '{') != NULL
)
18527 linkage_name
= NULL
;
18530 has_low_pc_attr
= 1;
18531 lowpc
= attr
.value_as_address ();
18533 case DW_AT_high_pc
:
18534 has_high_pc_attr
= 1;
18535 highpc
= attr
.value_as_address ();
18536 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18537 high_pc_relative
= 1;
18539 case DW_AT_location
:
18540 /* Support the .debug_loc offsets. */
18541 if (attr
.form_is_block ())
18543 d
.locdesc
= DW_BLOCK (&attr
);
18545 else if (attr
.form_is_section_offset ())
18547 dwarf2_complex_location_expr_complaint ();
18551 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18552 "partial symbol information");
18555 case DW_AT_external
:
18556 is_external
= DW_UNSND (&attr
);
18558 case DW_AT_declaration
:
18559 is_declaration
= DW_UNSND (&attr
);
18564 case DW_AT_abstract_origin
:
18565 case DW_AT_specification
:
18566 case DW_AT_extension
:
18567 has_specification
= 1;
18568 spec_offset
= attr
.get_ref_die_offset ();
18569 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18570 || cu
->per_cu
->is_dwz
);
18572 case DW_AT_sibling
:
18573 /* Ignore absolute siblings, they might point outside of
18574 the current compile unit. */
18575 if (attr
.form
== DW_FORM_ref_addr
)
18576 complaint (_("ignoring absolute DW_AT_sibling"));
18579 const gdb_byte
*buffer
= reader
->buffer
;
18580 sect_offset off
= attr
.get_ref_die_offset ();
18581 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18583 if (sibling_ptr
< info_ptr
)
18584 complaint (_("DW_AT_sibling points backwards"));
18585 else if (sibling_ptr
> reader
->buffer_end
)
18586 reader
->die_section
->overflow_complaint ();
18588 sibling
= sibling_ptr
;
18591 case DW_AT_byte_size
:
18594 case DW_AT_const_value
:
18595 has_const_value
= 1;
18597 case DW_AT_calling_convention
:
18598 /* DWARF doesn't provide a way to identify a program's source-level
18599 entry point. DW_AT_calling_convention attributes are only meant
18600 to describe functions' calling conventions.
18602 However, because it's a necessary piece of information in
18603 Fortran, and before DWARF 4 DW_CC_program was the only
18604 piece of debugging information whose definition refers to
18605 a 'main program' at all, several compilers marked Fortran
18606 main programs with DW_CC_program --- even when those
18607 functions use the standard calling conventions.
18609 Although DWARF now specifies a way to provide this
18610 information, we support this practice for backward
18612 if (DW_UNSND (&attr
) == DW_CC_program
18613 && cu
->language
== language_fortran
)
18614 main_subprogram
= 1;
18617 if (DW_UNSND (&attr
) == DW_INL_inlined
18618 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18619 may_be_inlined
= 1;
18623 if (tag
== DW_TAG_imported_unit
)
18625 d
.sect_off
= attr
.get_ref_die_offset ();
18626 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18627 || cu
->per_cu
->is_dwz
);
18631 case DW_AT_main_subprogram
:
18632 main_subprogram
= DW_UNSND (&attr
);
18637 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18638 but that requires a full DIE, so instead we just
18640 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18641 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18642 + (need_ranges_base
18646 /* Value of the DW_AT_ranges attribute is the offset in the
18647 .debug_ranges section. */
18648 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18659 /* For Ada, if both the name and the linkage name appear, we prefer
18660 the latter. This lets "catch exception" work better, regardless
18661 of the order in which the name and linkage name were emitted.
18662 Really, though, this is just a workaround for the fact that gdb
18663 doesn't store both the name and the linkage name. */
18664 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18665 raw_name
= linkage_name
;
18667 if (high_pc_relative
)
18670 if (has_low_pc_attr
&& has_high_pc_attr
)
18672 /* When using the GNU linker, .gnu.linkonce. sections are used to
18673 eliminate duplicate copies of functions and vtables and such.
18674 The linker will arbitrarily choose one and discard the others.
18675 The AT_*_pc values for such functions refer to local labels in
18676 these sections. If the section from that file was discarded, the
18677 labels are not in the output, so the relocs get a value of 0.
18678 If this is a discarded function, mark the pc bounds as invalid,
18679 so that GDB will ignore it. */
18680 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
18682 struct objfile
*objfile
= per_objfile
->objfile
;
18683 struct gdbarch
*gdbarch
= objfile
->arch ();
18685 complaint (_("DW_AT_low_pc %s is zero "
18686 "for DIE at %s [in module %s]"),
18687 paddress (gdbarch
, lowpc
),
18688 sect_offset_str (sect_off
),
18689 objfile_name (objfile
));
18691 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18692 else if (lowpc
>= highpc
)
18694 struct objfile
*objfile
= per_objfile
->objfile
;
18695 struct gdbarch
*gdbarch
= objfile
->arch ();
18697 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18698 "for DIE at %s [in module %s]"),
18699 paddress (gdbarch
, lowpc
),
18700 paddress (gdbarch
, highpc
),
18701 sect_offset_str (sect_off
),
18702 objfile_name (objfile
));
18711 /* Find a cached partial DIE at OFFSET in CU. */
18713 struct partial_die_info
*
18714 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18716 struct partial_die_info
*lookup_die
= NULL
;
18717 struct partial_die_info
part_die (sect_off
);
18719 lookup_die
= ((struct partial_die_info
*)
18720 htab_find_with_hash (partial_dies
, &part_die
,
18721 to_underlying (sect_off
)));
18726 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18727 except in the case of .debug_types DIEs which do not reference
18728 outside their CU (they do however referencing other types via
18729 DW_FORM_ref_sig8). */
18731 static const struct cu_partial_die_info
18732 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18734 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18735 struct objfile
*objfile
= per_objfile
->objfile
;
18736 struct partial_die_info
*pd
= NULL
;
18738 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18739 && cu
->header
.offset_in_cu_p (sect_off
))
18741 pd
= cu
->find_partial_die (sect_off
);
18744 /* We missed recording what we needed.
18745 Load all dies and try again. */
18749 /* TUs don't reference other CUs/TUs (except via type signatures). */
18750 if (cu
->per_cu
->is_debug_types
)
18752 error (_("Dwarf Error: Type Unit at offset %s contains"
18753 " external reference to offset %s [in module %s].\n"),
18754 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18755 bfd_get_filename (objfile
->obfd
));
18757 dwarf2_per_cu_data
*per_cu
18758 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18761 cu
= per_objfile
->get_cu (per_cu
);
18762 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
18763 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
18765 cu
= per_objfile
->get_cu (per_cu
);
18768 pd
= cu
->find_partial_die (sect_off
);
18771 /* If we didn't find it, and not all dies have been loaded,
18772 load them all and try again. */
18774 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
18776 cu
->per_cu
->load_all_dies
= 1;
18778 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18779 THIS_CU->cu may already be in use. So we can't just free it and
18780 replace its DIEs with the ones we read in. Instead, we leave those
18781 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18782 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18784 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
18786 pd
= cu
->find_partial_die (sect_off
);
18790 internal_error (__FILE__
, __LINE__
,
18791 _("could not find partial DIE %s "
18792 "in cache [from module %s]\n"),
18793 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18797 /* See if we can figure out if the class lives in a namespace. We do
18798 this by looking for a member function; its demangled name will
18799 contain namespace info, if there is any. */
18802 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18803 struct dwarf2_cu
*cu
)
18805 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18806 what template types look like, because the demangler
18807 frequently doesn't give the same name as the debug info. We
18808 could fix this by only using the demangled name to get the
18809 prefix (but see comment in read_structure_type). */
18811 struct partial_die_info
*real_pdi
;
18812 struct partial_die_info
*child_pdi
;
18814 /* If this DIE (this DIE's specification, if any) has a parent, then
18815 we should not do this. We'll prepend the parent's fully qualified
18816 name when we create the partial symbol. */
18818 real_pdi
= struct_pdi
;
18819 while (real_pdi
->has_specification
)
18821 auto res
= find_partial_die (real_pdi
->spec_offset
,
18822 real_pdi
->spec_is_dwz
, cu
);
18823 real_pdi
= res
.pdi
;
18827 if (real_pdi
->die_parent
!= NULL
)
18830 for (child_pdi
= struct_pdi
->die_child
;
18832 child_pdi
= child_pdi
->die_sibling
)
18834 if (child_pdi
->tag
== DW_TAG_subprogram
18835 && child_pdi
->linkage_name
!= NULL
)
18837 gdb::unique_xmalloc_ptr
<char> actual_class_name
18838 (language_class_name_from_physname (cu
->language_defn
,
18839 child_pdi
->linkage_name
));
18840 if (actual_class_name
!= NULL
)
18842 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18843 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
18844 struct_pdi
->canonical_name
= 1;
18851 /* Return true if a DIE with TAG may have the DW_AT_const_value
18855 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18859 case DW_TAG_constant
:
18860 case DW_TAG_enumerator
:
18861 case DW_TAG_formal_parameter
:
18862 case DW_TAG_template_value_param
:
18863 case DW_TAG_variable
:
18871 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18873 /* Once we've fixed up a die, there's no point in doing so again.
18874 This also avoids a memory leak if we were to call
18875 guess_partial_die_structure_name multiple times. */
18879 /* If we found a reference attribute and the DIE has no name, try
18880 to find a name in the referred to DIE. */
18882 if (raw_name
== NULL
&& has_specification
)
18884 struct partial_die_info
*spec_die
;
18886 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18887 spec_die
= res
.pdi
;
18890 spec_die
->fixup (cu
);
18892 if (spec_die
->raw_name
)
18894 raw_name
= spec_die
->raw_name
;
18895 canonical_name
= spec_die
->canonical_name
;
18897 /* Copy DW_AT_external attribute if it is set. */
18898 if (spec_die
->is_external
)
18899 is_external
= spec_die
->is_external
;
18903 if (!has_const_value
&& has_specification
18904 && can_have_DW_AT_const_value_p (tag
))
18906 struct partial_die_info
*spec_die
;
18908 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18909 spec_die
= res
.pdi
;
18912 spec_die
->fixup (cu
);
18914 if (spec_die
->has_const_value
)
18916 /* Copy DW_AT_const_value attribute if it is set. */
18917 has_const_value
= spec_die
->has_const_value
;
18921 /* Set default names for some unnamed DIEs. */
18923 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
18925 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
18926 canonical_name
= 1;
18929 /* If there is no parent die to provide a namespace, and there are
18930 children, see if we can determine the namespace from their linkage
18932 if (cu
->language
== language_cplus
18933 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18934 && die_parent
== NULL
18936 && (tag
== DW_TAG_class_type
18937 || tag
== DW_TAG_structure_type
18938 || tag
== DW_TAG_union_type
))
18939 guess_partial_die_structure_name (this, cu
);
18941 /* GCC might emit a nameless struct or union that has a linkage
18942 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18943 if (raw_name
== NULL
18944 && (tag
== DW_TAG_class_type
18945 || tag
== DW_TAG_interface_type
18946 || tag
== DW_TAG_structure_type
18947 || tag
== DW_TAG_union_type
)
18948 && linkage_name
!= NULL
)
18950 gdb::unique_xmalloc_ptr
<char> demangled
18951 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18952 if (demangled
!= nullptr)
18956 /* Strip any leading namespaces/classes, keep only the base name.
18957 DW_AT_name for named DIEs does not contain the prefixes. */
18958 base
= strrchr (demangled
.get (), ':');
18959 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18962 base
= demangled
.get ();
18964 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18965 raw_name
= objfile
->intern (base
);
18966 canonical_name
= 1;
18973 /* Read the .debug_loclists header contents from the given SECTION in the
18976 read_loclist_header (struct loclist_header
*header
,
18977 struct dwarf2_section_info
*section
)
18979 unsigned int bytes_read
;
18980 bfd
*abfd
= section
->get_bfd_owner ();
18981 const gdb_byte
*info_ptr
= section
->buffer
;
18982 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18983 info_ptr
+= bytes_read
;
18984 header
->version
= read_2_bytes (abfd
, info_ptr
);
18986 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18988 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18990 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18993 /* Return the DW_AT_loclists_base value for the CU. */
18995 lookup_loclist_base (struct dwarf2_cu
*cu
)
18997 /* For the .dwo unit, the loclist_base points to the first offset following
18998 the header. The header consists of the following entities-
18999 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19001 2. version (2 bytes)
19002 3. address size (1 byte)
19003 4. segment selector size (1 byte)
19004 5. offset entry count (4 bytes)
19005 These sizes are derived as per the DWARFv5 standard. */
19006 if (cu
->dwo_unit
!= nullptr)
19008 if (cu
->header
.initial_length_size
== 4)
19009 return LOCLIST_HEADER_SIZE32
;
19010 return LOCLIST_HEADER_SIZE64
;
19012 return cu
->loclist_base
;
19015 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19016 array of offsets in the .debug_loclists section. */
19018 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19020 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19021 struct objfile
*objfile
= per_objfile
->objfile
;
19022 bfd
*abfd
= objfile
->obfd
;
19023 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19024 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19026 section
->read (objfile
);
19027 if (section
->buffer
== NULL
)
19028 complaint (_("DW_FORM_loclistx used without .debug_loclists "
19029 "section [in module %s]"), objfile_name (objfile
));
19030 struct loclist_header header
;
19031 read_loclist_header (&header
, section
);
19032 if (loclist_index
>= header
.offset_entry_count
)
19033 complaint (_("DW_FORM_loclistx pointing outside of "
19034 ".debug_loclists offset array [in module %s]"),
19035 objfile_name (objfile
));
19036 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
19038 complaint (_("DW_FORM_loclistx pointing outside of "
19039 ".debug_loclists section [in module %s]"),
19040 objfile_name (objfile
));
19041 const gdb_byte
*info_ptr
19042 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19044 if (cu
->header
.offset_size
== 4)
19045 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
19047 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
19050 /* Process the attributes that had to be skipped in the first round. These
19051 attributes are the ones that need str_offsets_base or addr_base attributes.
19052 They could not have been processed in the first round, because at the time
19053 the values of str_offsets_base or addr_base may not have been known. */
19055 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19056 struct attribute
*attr
)
19058 struct dwarf2_cu
*cu
= reader
->cu
;
19059 switch (attr
->form
)
19061 case DW_FORM_addrx
:
19062 case DW_FORM_GNU_addr_index
:
19063 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19065 case DW_FORM_loclistx
:
19066 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19069 case DW_FORM_strx1
:
19070 case DW_FORM_strx2
:
19071 case DW_FORM_strx3
:
19072 case DW_FORM_strx4
:
19073 case DW_FORM_GNU_str_index
:
19075 unsigned int str_index
= DW_UNSND (attr
);
19076 if (reader
->dwo_file
!= NULL
)
19078 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19079 DW_STRING_IS_CANONICAL (attr
) = 0;
19083 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19084 DW_STRING_IS_CANONICAL (attr
) = 0;
19089 gdb_assert_not_reached (_("Unexpected DWARF form."));
19093 /* Read an attribute value described by an attribute form. */
19095 static const gdb_byte
*
19096 read_attribute_value (const struct die_reader_specs
*reader
,
19097 struct attribute
*attr
, unsigned form
,
19098 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19099 bool *need_reprocess
)
19101 struct dwarf2_cu
*cu
= reader
->cu
;
19102 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19103 struct objfile
*objfile
= per_objfile
->objfile
;
19104 bfd
*abfd
= reader
->abfd
;
19105 struct comp_unit_head
*cu_header
= &cu
->header
;
19106 unsigned int bytes_read
;
19107 struct dwarf_block
*blk
;
19108 *need_reprocess
= false;
19110 attr
->form
= (enum dwarf_form
) form
;
19113 case DW_FORM_ref_addr
:
19114 if (cu
->header
.version
== 2)
19115 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19118 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19120 info_ptr
+= bytes_read
;
19122 case DW_FORM_GNU_ref_alt
:
19123 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19124 info_ptr
+= bytes_read
;
19128 struct gdbarch
*gdbarch
= objfile
->arch ();
19129 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19130 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19131 info_ptr
+= bytes_read
;
19134 case DW_FORM_block2
:
19135 blk
= dwarf_alloc_block (cu
);
19136 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19138 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19139 info_ptr
+= blk
->size
;
19140 DW_BLOCK (attr
) = blk
;
19142 case DW_FORM_block4
:
19143 blk
= dwarf_alloc_block (cu
);
19144 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19146 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19147 info_ptr
+= blk
->size
;
19148 DW_BLOCK (attr
) = blk
;
19150 case DW_FORM_data2
:
19151 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19154 case DW_FORM_data4
:
19155 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19158 case DW_FORM_data8
:
19159 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19162 case DW_FORM_data16
:
19163 blk
= dwarf_alloc_block (cu
);
19165 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19167 DW_BLOCK (attr
) = blk
;
19169 case DW_FORM_sec_offset
:
19170 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19171 info_ptr
+= bytes_read
;
19173 case DW_FORM_loclistx
:
19175 *need_reprocess
= true;
19176 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19177 info_ptr
+= bytes_read
;
19180 case DW_FORM_string
:
19181 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19182 DW_STRING_IS_CANONICAL (attr
) = 0;
19183 info_ptr
+= bytes_read
;
19186 if (!cu
->per_cu
->is_dwz
)
19188 DW_STRING (attr
) = read_indirect_string (per_objfile
,
19189 abfd
, info_ptr
, cu_header
,
19191 DW_STRING_IS_CANONICAL (attr
) = 0;
19192 info_ptr
+= bytes_read
;
19196 case DW_FORM_line_strp
:
19197 if (!cu
->per_cu
->is_dwz
)
19199 DW_STRING (attr
) = per_objfile
->read_line_string (info_ptr
, cu_header
,
19201 DW_STRING_IS_CANONICAL (attr
) = 0;
19202 info_ptr
+= bytes_read
;
19206 case DW_FORM_GNU_strp_alt
:
19208 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19209 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19212 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19213 DW_STRING_IS_CANONICAL (attr
) = 0;
19214 info_ptr
+= bytes_read
;
19217 case DW_FORM_exprloc
:
19218 case DW_FORM_block
:
19219 blk
= dwarf_alloc_block (cu
);
19220 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19221 info_ptr
+= bytes_read
;
19222 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19223 info_ptr
+= blk
->size
;
19224 DW_BLOCK (attr
) = blk
;
19226 case DW_FORM_block1
:
19227 blk
= dwarf_alloc_block (cu
);
19228 blk
->size
= read_1_byte (abfd
, info_ptr
);
19230 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19231 info_ptr
+= blk
->size
;
19232 DW_BLOCK (attr
) = blk
;
19234 case DW_FORM_data1
:
19235 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19239 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19242 case DW_FORM_flag_present
:
19243 DW_UNSND (attr
) = 1;
19245 case DW_FORM_sdata
:
19246 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19247 info_ptr
+= bytes_read
;
19249 case DW_FORM_udata
:
19250 case DW_FORM_rnglistx
:
19251 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19252 info_ptr
+= bytes_read
;
19255 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19256 + read_1_byte (abfd
, info_ptr
));
19260 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19261 + read_2_bytes (abfd
, info_ptr
));
19265 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19266 + read_4_bytes (abfd
, info_ptr
));
19270 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19271 + read_8_bytes (abfd
, info_ptr
));
19274 case DW_FORM_ref_sig8
:
19275 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19278 case DW_FORM_ref_udata
:
19279 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19280 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19281 info_ptr
+= bytes_read
;
19283 case DW_FORM_indirect
:
19284 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19285 info_ptr
+= bytes_read
;
19286 if (form
== DW_FORM_implicit_const
)
19288 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19289 info_ptr
+= bytes_read
;
19291 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19292 info_ptr
, need_reprocess
);
19294 case DW_FORM_implicit_const
:
19295 DW_SND (attr
) = implicit_const
;
19297 case DW_FORM_addrx
:
19298 case DW_FORM_GNU_addr_index
:
19299 *need_reprocess
= true;
19300 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19301 info_ptr
+= bytes_read
;
19304 case DW_FORM_strx1
:
19305 case DW_FORM_strx2
:
19306 case DW_FORM_strx3
:
19307 case DW_FORM_strx4
:
19308 case DW_FORM_GNU_str_index
:
19310 ULONGEST str_index
;
19311 if (form
== DW_FORM_strx1
)
19313 str_index
= read_1_byte (abfd
, info_ptr
);
19316 else if (form
== DW_FORM_strx2
)
19318 str_index
= read_2_bytes (abfd
, info_ptr
);
19321 else if (form
== DW_FORM_strx3
)
19323 str_index
= read_3_bytes (abfd
, info_ptr
);
19326 else if (form
== DW_FORM_strx4
)
19328 str_index
= read_4_bytes (abfd
, info_ptr
);
19333 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19334 info_ptr
+= bytes_read
;
19336 *need_reprocess
= true;
19337 DW_UNSND (attr
) = str_index
;
19341 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19342 dwarf_form_name (form
),
19343 bfd_get_filename (abfd
));
19347 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19348 attr
->form
= DW_FORM_GNU_ref_alt
;
19350 /* We have seen instances where the compiler tried to emit a byte
19351 size attribute of -1 which ended up being encoded as an unsigned
19352 0xffffffff. Although 0xffffffff is technically a valid size value,
19353 an object of this size seems pretty unlikely so we can relatively
19354 safely treat these cases as if the size attribute was invalid and
19355 treat them as zero by default. */
19356 if (attr
->name
== DW_AT_byte_size
19357 && form
== DW_FORM_data4
19358 && DW_UNSND (attr
) >= 0xffffffff)
19361 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19362 hex_string (DW_UNSND (attr
)));
19363 DW_UNSND (attr
) = 0;
19369 /* Read an attribute described by an abbreviated attribute. */
19371 static const gdb_byte
*
19372 read_attribute (const struct die_reader_specs
*reader
,
19373 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19374 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19376 attr
->name
= abbrev
->name
;
19377 return read_attribute_value (reader
, attr
, abbrev
->form
,
19378 abbrev
->implicit_const
, info_ptr
,
19382 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19384 static const char *
19385 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
19386 LONGEST str_offset
)
19388 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
19389 str_offset
, "DW_FORM_strp");
19392 /* Return pointer to string at .debug_str offset as read from BUF.
19393 BUF is assumed to be in a compilation unit described by CU_HEADER.
19394 Return *BYTES_READ_PTR count of bytes read from BUF. */
19396 static const char *
19397 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
19398 const gdb_byte
*buf
,
19399 const struct comp_unit_head
*cu_header
,
19400 unsigned int *bytes_read_ptr
)
19402 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19404 return read_indirect_string_at_offset (per_objfile
, str_offset
);
19410 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19411 const struct comp_unit_head
*cu_header
,
19412 unsigned int *bytes_read_ptr
)
19414 bfd
*abfd
= objfile
->obfd
;
19415 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19417 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19420 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19421 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19422 ADDR_SIZE is the size of addresses from the CU header. */
19425 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
19426 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
19428 struct objfile
*objfile
= per_objfile
->objfile
;
19429 bfd
*abfd
= objfile
->obfd
;
19430 const gdb_byte
*info_ptr
;
19431 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19433 per_objfile
->per_bfd
->addr
.read (objfile
);
19434 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19435 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19436 objfile_name (objfile
));
19437 if (addr_base_or_zero
+ addr_index
* addr_size
19438 >= per_objfile
->per_bfd
->addr
.size
)
19439 error (_("DW_FORM_addr_index pointing outside of "
19440 ".debug_addr section [in module %s]"),
19441 objfile_name (objfile
));
19442 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
19443 + addr_index
* addr_size
);
19444 if (addr_size
== 4)
19445 return bfd_get_32 (abfd
, info_ptr
);
19447 return bfd_get_64 (abfd
, info_ptr
);
19450 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19453 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19455 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19456 cu
->addr_base
, cu
->header
.addr_size
);
19459 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19462 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19463 unsigned int *bytes_read
)
19465 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19466 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19468 return read_addr_index (cu
, addr_index
);
19474 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19475 dwarf2_per_objfile
*per_objfile
,
19476 unsigned int addr_index
)
19478 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
19479 gdb::optional
<ULONGEST
> addr_base
;
19482 /* We need addr_base and addr_size.
19483 If we don't have PER_CU->cu, we have to get it.
19484 Nasty, but the alternative is storing the needed info in PER_CU,
19485 which at this point doesn't seem justified: it's not clear how frequently
19486 it would get used and it would increase the size of every PER_CU.
19487 Entry points like dwarf2_per_cu_addr_size do a similar thing
19488 so we're not in uncharted territory here.
19489 Alas we need to be a bit more complicated as addr_base is contained
19492 We don't need to read the entire CU(/TU).
19493 We just need the header and top level die.
19495 IWBN to use the aging mechanism to let us lazily later discard the CU.
19496 For now we skip this optimization. */
19500 addr_base
= cu
->addr_base
;
19501 addr_size
= cu
->header
.addr_size
;
19505 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
19506 addr_base
= reader
.cu
->addr_base
;
19507 addr_size
= reader
.cu
->header
.addr_size
;
19510 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
19513 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19514 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19517 static const char *
19518 read_str_index (struct dwarf2_cu
*cu
,
19519 struct dwarf2_section_info
*str_section
,
19520 struct dwarf2_section_info
*str_offsets_section
,
19521 ULONGEST str_offsets_base
, ULONGEST str_index
)
19523 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19524 struct objfile
*objfile
= per_objfile
->objfile
;
19525 const char *objf_name
= objfile_name (objfile
);
19526 bfd
*abfd
= objfile
->obfd
;
19527 const gdb_byte
*info_ptr
;
19528 ULONGEST str_offset
;
19529 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19531 str_section
->read (objfile
);
19532 str_offsets_section
->read (objfile
);
19533 if (str_section
->buffer
== NULL
)
19534 error (_("%s used without %s section"
19535 " in CU at offset %s [in module %s]"),
19536 form_name
, str_section
->get_name (),
19537 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19538 if (str_offsets_section
->buffer
== NULL
)
19539 error (_("%s used without %s section"
19540 " in CU at offset %s [in module %s]"),
19541 form_name
, str_section
->get_name (),
19542 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19543 info_ptr
= (str_offsets_section
->buffer
19545 + str_index
* cu
->header
.offset_size
);
19546 if (cu
->header
.offset_size
== 4)
19547 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19549 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19550 if (str_offset
>= str_section
->size
)
19551 error (_("Offset from %s pointing outside of"
19552 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19553 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19554 return (const char *) (str_section
->buffer
+ str_offset
);
19557 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19559 static const char *
19560 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19562 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19563 ? reader
->cu
->header
.addr_size
: 0;
19564 return read_str_index (reader
->cu
,
19565 &reader
->dwo_file
->sections
.str
,
19566 &reader
->dwo_file
->sections
.str_offsets
,
19567 str_offsets_base
, str_index
);
19570 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19572 static const char *
19573 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19575 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19576 const char *objf_name
= objfile_name (objfile
);
19577 static const char form_name
[] = "DW_FORM_GNU_str_index";
19578 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19580 if (!cu
->str_offsets_base
.has_value ())
19581 error (_("%s used in Fission stub without %s"
19582 " in CU at offset 0x%lx [in module %s]"),
19583 form_name
, str_offsets_attr_name
,
19584 (long) cu
->header
.offset_size
, objf_name
);
19586 return read_str_index (cu
,
19587 &cu
->per_objfile
->per_bfd
->str
,
19588 &cu
->per_objfile
->per_bfd
->str_offsets
,
19589 *cu
->str_offsets_base
, str_index
);
19592 /* Return the length of an LEB128 number in BUF. */
19595 leb128_size (const gdb_byte
*buf
)
19597 const gdb_byte
*begin
= buf
;
19603 if ((byte
& 128) == 0)
19604 return buf
- begin
;
19609 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19618 cu
->language
= language_c
;
19621 case DW_LANG_C_plus_plus
:
19622 case DW_LANG_C_plus_plus_11
:
19623 case DW_LANG_C_plus_plus_14
:
19624 cu
->language
= language_cplus
;
19627 cu
->language
= language_d
;
19629 case DW_LANG_Fortran77
:
19630 case DW_LANG_Fortran90
:
19631 case DW_LANG_Fortran95
:
19632 case DW_LANG_Fortran03
:
19633 case DW_LANG_Fortran08
:
19634 cu
->language
= language_fortran
;
19637 cu
->language
= language_go
;
19639 case DW_LANG_Mips_Assembler
:
19640 cu
->language
= language_asm
;
19642 case DW_LANG_Ada83
:
19643 case DW_LANG_Ada95
:
19644 cu
->language
= language_ada
;
19646 case DW_LANG_Modula2
:
19647 cu
->language
= language_m2
;
19649 case DW_LANG_Pascal83
:
19650 cu
->language
= language_pascal
;
19653 cu
->language
= language_objc
;
19656 case DW_LANG_Rust_old
:
19657 cu
->language
= language_rust
;
19659 case DW_LANG_Cobol74
:
19660 case DW_LANG_Cobol85
:
19662 cu
->language
= language_minimal
;
19665 cu
->language_defn
= language_def (cu
->language
);
19668 /* Return the named attribute or NULL if not there. */
19670 static struct attribute
*
19671 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19676 struct attribute
*spec
= NULL
;
19678 for (i
= 0; i
< die
->num_attrs
; ++i
)
19680 if (die
->attrs
[i
].name
== name
)
19681 return &die
->attrs
[i
];
19682 if (die
->attrs
[i
].name
== DW_AT_specification
19683 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19684 spec
= &die
->attrs
[i
];
19690 die
= follow_die_ref (die
, spec
, &cu
);
19696 /* Return the string associated with a string-typed attribute, or NULL if it
19697 is either not found or is of an incorrect type. */
19699 static const char *
19700 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19702 struct attribute
*attr
;
19703 const char *str
= NULL
;
19705 attr
= dwarf2_attr (die
, name
, cu
);
19709 str
= attr
->value_as_string ();
19710 if (str
== nullptr)
19711 complaint (_("string type expected for attribute %s for "
19712 "DIE at %s in module %s"),
19713 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19714 objfile_name (cu
->per_objfile
->objfile
));
19720 /* Return the dwo name or NULL if not present. If present, it is in either
19721 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19722 static const char *
19723 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19725 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19726 if (dwo_name
== nullptr)
19727 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19731 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19732 and holds a non-zero value. This function should only be used for
19733 DW_FORM_flag or DW_FORM_flag_present attributes. */
19736 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19738 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19740 return (attr
&& DW_UNSND (attr
));
19744 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19746 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19747 which value is non-zero. However, we have to be careful with
19748 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19749 (via dwarf2_flag_true_p) follows this attribute. So we may
19750 end up accidently finding a declaration attribute that belongs
19751 to a different DIE referenced by the specification attribute,
19752 even though the given DIE does not have a declaration attribute. */
19753 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19754 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19757 /* Return the die giving the specification for DIE, if there is
19758 one. *SPEC_CU is the CU containing DIE on input, and the CU
19759 containing the return value on output. If there is no
19760 specification, but there is an abstract origin, that is
19763 static struct die_info
*
19764 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19766 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19769 if (spec_attr
== NULL
)
19770 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19772 if (spec_attr
== NULL
)
19775 return follow_die_ref (die
, spec_attr
, spec_cu
);
19778 /* Stub for free_line_header to match void * callback types. */
19781 free_line_header_voidp (void *arg
)
19783 struct line_header
*lh
= (struct line_header
*) arg
;
19788 /* A convenience function to find the proper .debug_line section for a CU. */
19790 static struct dwarf2_section_info
*
19791 get_debug_line_section (struct dwarf2_cu
*cu
)
19793 struct dwarf2_section_info
*section
;
19794 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19796 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19798 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19799 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19800 else if (cu
->per_cu
->is_dwz
)
19802 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19804 section
= &dwz
->line
;
19807 section
= &per_objfile
->per_bfd
->line
;
19812 /* Read the statement program header starting at OFFSET in
19813 .debug_line, or .debug_line.dwo. Return a pointer
19814 to a struct line_header, allocated using xmalloc.
19815 Returns NULL if there is a problem reading the header, e.g., if it
19816 has a version we don't understand.
19818 NOTE: the strings in the include directory and file name tables of
19819 the returned object point into the dwarf line section buffer,
19820 and must not be freed. */
19822 static line_header_up
19823 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19825 struct dwarf2_section_info
*section
;
19826 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19828 section
= get_debug_line_section (cu
);
19829 section
->read (per_objfile
->objfile
);
19830 if (section
->buffer
== NULL
)
19832 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19833 complaint (_("missing .debug_line.dwo section"));
19835 complaint (_("missing .debug_line section"));
19839 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19840 per_objfile
, section
, &cu
->header
);
19843 /* Subroutine of dwarf_decode_lines to simplify it.
19844 Return the file name of the psymtab for the given file_entry.
19845 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19846 If space for the result is malloc'd, *NAME_HOLDER will be set.
19847 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19849 static const char *
19850 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19851 const dwarf2_psymtab
*pst
,
19852 const char *comp_dir
,
19853 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19855 const char *include_name
= fe
.name
;
19856 const char *include_name_to_compare
= include_name
;
19857 const char *pst_filename
;
19860 const char *dir_name
= fe
.include_dir (lh
);
19862 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19863 if (!IS_ABSOLUTE_PATH (include_name
)
19864 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19866 /* Avoid creating a duplicate psymtab for PST.
19867 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19868 Before we do the comparison, however, we need to account
19869 for DIR_NAME and COMP_DIR.
19870 First prepend dir_name (if non-NULL). If we still don't
19871 have an absolute path prepend comp_dir (if non-NULL).
19872 However, the directory we record in the include-file's
19873 psymtab does not contain COMP_DIR (to match the
19874 corresponding symtab(s)).
19879 bash$ gcc -g ./hello.c
19880 include_name = "hello.c"
19882 DW_AT_comp_dir = comp_dir = "/tmp"
19883 DW_AT_name = "./hello.c"
19887 if (dir_name
!= NULL
)
19889 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19890 include_name
, (char *) NULL
));
19891 include_name
= name_holder
->get ();
19892 include_name_to_compare
= include_name
;
19894 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19896 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19897 include_name
, (char *) NULL
));
19898 include_name_to_compare
= hold_compare
.get ();
19902 pst_filename
= pst
->filename
;
19903 gdb::unique_xmalloc_ptr
<char> copied_name
;
19904 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19906 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19907 pst_filename
, (char *) NULL
));
19908 pst_filename
= copied_name
.get ();
19911 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19915 return include_name
;
19918 /* State machine to track the state of the line number program. */
19920 class lnp_state_machine
19923 /* Initialize a machine state for the start of a line number
19925 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19926 bool record_lines_p
);
19928 file_entry
*current_file ()
19930 /* lh->file_names is 0-based, but the file name numbers in the
19931 statement program are 1-based. */
19932 return m_line_header
->file_name_at (m_file
);
19935 /* Record the line in the state machine. END_SEQUENCE is true if
19936 we're processing the end of a sequence. */
19937 void record_line (bool end_sequence
);
19939 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19940 nop-out rest of the lines in this sequence. */
19941 void check_line_address (struct dwarf2_cu
*cu
,
19942 const gdb_byte
*line_ptr
,
19943 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19945 void handle_set_discriminator (unsigned int discriminator
)
19947 m_discriminator
= discriminator
;
19948 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19951 /* Handle DW_LNE_set_address. */
19952 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19955 address
+= baseaddr
;
19956 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19959 /* Handle DW_LNS_advance_pc. */
19960 void handle_advance_pc (CORE_ADDR adjust
);
19962 /* Handle a special opcode. */
19963 void handle_special_opcode (unsigned char op_code
);
19965 /* Handle DW_LNS_advance_line. */
19966 void handle_advance_line (int line_delta
)
19968 advance_line (line_delta
);
19971 /* Handle DW_LNS_set_file. */
19972 void handle_set_file (file_name_index file
);
19974 /* Handle DW_LNS_negate_stmt. */
19975 void handle_negate_stmt ()
19977 m_is_stmt
= !m_is_stmt
;
19980 /* Handle DW_LNS_const_add_pc. */
19981 void handle_const_add_pc ();
19983 /* Handle DW_LNS_fixed_advance_pc. */
19984 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19986 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19990 /* Handle DW_LNS_copy. */
19991 void handle_copy ()
19993 record_line (false);
19994 m_discriminator
= 0;
19997 /* Handle DW_LNE_end_sequence. */
19998 void handle_end_sequence ()
20000 m_currently_recording_lines
= true;
20004 /* Advance the line by LINE_DELTA. */
20005 void advance_line (int line_delta
)
20007 m_line
+= line_delta
;
20009 if (line_delta
!= 0)
20010 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20013 struct dwarf2_cu
*m_cu
;
20015 gdbarch
*m_gdbarch
;
20017 /* True if we're recording lines.
20018 Otherwise we're building partial symtabs and are just interested in
20019 finding include files mentioned by the line number program. */
20020 bool m_record_lines_p
;
20022 /* The line number header. */
20023 line_header
*m_line_header
;
20025 /* These are part of the standard DWARF line number state machine,
20026 and initialized according to the DWARF spec. */
20028 unsigned char m_op_index
= 0;
20029 /* The line table index of the current file. */
20030 file_name_index m_file
= 1;
20031 unsigned int m_line
= 1;
20033 /* These are initialized in the constructor. */
20035 CORE_ADDR m_address
;
20037 unsigned int m_discriminator
;
20039 /* Additional bits of state we need to track. */
20041 /* The last file that we called dwarf2_start_subfile for.
20042 This is only used for TLLs. */
20043 unsigned int m_last_file
= 0;
20044 /* The last file a line number was recorded for. */
20045 struct subfile
*m_last_subfile
= NULL
;
20047 /* The address of the last line entry. */
20048 CORE_ADDR m_last_address
;
20050 /* Set to true when a previous line at the same address (using
20051 m_last_address) had m_is_stmt true. This is reset to false when a
20052 line entry at a new address (m_address different to m_last_address) is
20054 bool m_stmt_at_address
= false;
20056 /* When true, record the lines we decode. */
20057 bool m_currently_recording_lines
= false;
20059 /* The last line number that was recorded, used to coalesce
20060 consecutive entries for the same line. This can happen, for
20061 example, when discriminators are present. PR 17276. */
20062 unsigned int m_last_line
= 0;
20063 bool m_line_has_non_zero_discriminator
= false;
20067 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20069 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20070 / m_line_header
->maximum_ops_per_instruction
)
20071 * m_line_header
->minimum_instruction_length
);
20072 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20073 m_op_index
= ((m_op_index
+ adjust
)
20074 % m_line_header
->maximum_ops_per_instruction
);
20078 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20080 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20081 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20082 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20083 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20084 / m_line_header
->maximum_ops_per_instruction
)
20085 * m_line_header
->minimum_instruction_length
);
20086 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20087 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20088 % m_line_header
->maximum_ops_per_instruction
);
20090 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20091 advance_line (line_delta
);
20092 record_line (false);
20093 m_discriminator
= 0;
20097 lnp_state_machine::handle_set_file (file_name_index file
)
20101 const file_entry
*fe
= current_file ();
20103 dwarf2_debug_line_missing_file_complaint ();
20104 else if (m_record_lines_p
)
20106 const char *dir
= fe
->include_dir (m_line_header
);
20108 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20109 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20110 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20115 lnp_state_machine::handle_const_add_pc ()
20118 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20121 = (((m_op_index
+ adjust
)
20122 / m_line_header
->maximum_ops_per_instruction
)
20123 * 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
+ adjust
)
20127 % m_line_header
->maximum_ops_per_instruction
);
20130 /* Return non-zero if we should add LINE to the line number table.
20131 LINE is the line to add, LAST_LINE is the last line that was added,
20132 LAST_SUBFILE is the subfile for LAST_LINE.
20133 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20134 had a non-zero discriminator.
20136 We have to be careful in the presence of discriminators.
20137 E.g., for this line:
20139 for (i = 0; i < 100000; i++);
20141 clang can emit four line number entries for that one line,
20142 each with a different discriminator.
20143 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20145 However, we want gdb to coalesce all four entries into one.
20146 Otherwise the user could stepi into the middle of the line and
20147 gdb would get confused about whether the pc really was in the
20148 middle of the line.
20150 Things are further complicated by the fact that two consecutive
20151 line number entries for the same line is a heuristic used by gcc
20152 to denote the end of the prologue. So we can't just discard duplicate
20153 entries, we have to be selective about it. The heuristic we use is
20154 that we only collapse consecutive entries for the same line if at least
20155 one of those entries has a non-zero discriminator. PR 17276.
20157 Note: Addresses in the line number state machine can never go backwards
20158 within one sequence, thus this coalescing is ok. */
20161 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20162 unsigned int line
, unsigned int last_line
,
20163 int line_has_non_zero_discriminator
,
20164 struct subfile
*last_subfile
)
20166 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20168 if (line
!= last_line
)
20170 /* Same line for the same file that we've seen already.
20171 As a last check, for pr 17276, only record the line if the line
20172 has never had a non-zero discriminator. */
20173 if (!line_has_non_zero_discriminator
)
20178 /* Use the CU's builder to record line number LINE beginning at
20179 address ADDRESS in the line table of subfile SUBFILE. */
20182 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20183 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20184 struct dwarf2_cu
*cu
)
20186 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20188 if (dwarf_line_debug
)
20190 fprintf_unfiltered (gdb_stdlog
,
20191 "Recording line %u, file %s, address %s\n",
20192 line
, lbasename (subfile
->name
),
20193 paddress (gdbarch
, address
));
20197 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20200 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20201 Mark the end of a set of line number records.
20202 The arguments are the same as for dwarf_record_line_1.
20203 If SUBFILE is NULL the request is ignored. */
20206 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20207 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20209 if (subfile
== NULL
)
20212 if (dwarf_line_debug
)
20214 fprintf_unfiltered (gdb_stdlog
,
20215 "Finishing current line, file %s, address %s\n",
20216 lbasename (subfile
->name
),
20217 paddress (gdbarch
, address
));
20220 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20224 lnp_state_machine::record_line (bool end_sequence
)
20226 if (dwarf_line_debug
)
20228 fprintf_unfiltered (gdb_stdlog
,
20229 "Processing actual line %u: file %u,"
20230 " address %s, is_stmt %u, discrim %u%s\n",
20232 paddress (m_gdbarch
, m_address
),
20233 m_is_stmt
, m_discriminator
,
20234 (end_sequence
? "\t(end sequence)" : ""));
20237 file_entry
*fe
= current_file ();
20240 dwarf2_debug_line_missing_file_complaint ();
20241 /* For now we ignore lines not starting on an instruction boundary.
20242 But not when processing end_sequence for compatibility with the
20243 previous version of the code. */
20244 else if (m_op_index
== 0 || end_sequence
)
20246 fe
->included_p
= 1;
20247 if (m_record_lines_p
)
20249 /* When we switch files we insert an end maker in the first file,
20250 switch to the second file and add a new line entry. The
20251 problem is that the end marker inserted in the first file will
20252 discard any previous line entries at the same address. If the
20253 line entries in the first file are marked as is-stmt, while
20254 the new line in the second file is non-stmt, then this means
20255 the end marker will discard is-stmt lines so we can have a
20256 non-stmt line. This means that there are less addresses at
20257 which the user can insert a breakpoint.
20259 To improve this we track the last address in m_last_address,
20260 and whether we have seen an is-stmt at this address. Then
20261 when switching files, if we have seen a stmt at the current
20262 address, and we are switching to create a non-stmt line, then
20263 discard the new line. */
20265 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
20266 bool ignore_this_line
20267 = (file_changed
&& !end_sequence
&& m_last_address
== m_address
20268 && !m_is_stmt
&& m_stmt_at_address
);
20270 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
20272 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20273 m_currently_recording_lines
? m_cu
: nullptr);
20276 if (!end_sequence
&& !ignore_this_line
)
20278 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20280 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20281 m_line_has_non_zero_discriminator
,
20284 buildsym_compunit
*builder
= m_cu
->get_builder ();
20285 dwarf_record_line_1 (m_gdbarch
,
20286 builder
->get_current_subfile (),
20287 m_line
, m_address
, is_stmt
,
20288 m_currently_recording_lines
? m_cu
: nullptr);
20290 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20291 m_last_line
= m_line
;
20296 /* Track whether we have seen any m_is_stmt true at m_address in case we
20297 have multiple line table entries all at m_address. */
20298 if (m_last_address
!= m_address
)
20300 m_stmt_at_address
= false;
20301 m_last_address
= m_address
;
20303 m_stmt_at_address
|= m_is_stmt
;
20306 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20307 line_header
*lh
, bool record_lines_p
)
20311 m_record_lines_p
= record_lines_p
;
20312 m_line_header
= lh
;
20314 m_currently_recording_lines
= true;
20316 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20317 was a line entry for it so that the backend has a chance to adjust it
20318 and also record it in case it needs it. This is currently used by MIPS
20319 code, cf. `mips_adjust_dwarf2_line'. */
20320 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20321 m_is_stmt
= lh
->default_is_stmt
;
20322 m_discriminator
= 0;
20324 m_last_address
= m_address
;
20325 m_stmt_at_address
= false;
20329 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20330 const gdb_byte
*line_ptr
,
20331 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20333 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20334 the pc range of the CU. However, we restrict the test to only ADDRESS
20335 values of zero to preserve GDB's previous behaviour which is to handle
20336 the specific case of a function being GC'd by the linker. */
20338 if (address
== 0 && address
< unrelocated_lowpc
)
20340 /* This line table is for a function which has been
20341 GCd by the linker. Ignore it. PR gdb/12528 */
20343 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20344 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20346 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20347 line_offset
, objfile_name (objfile
));
20348 m_currently_recording_lines
= false;
20349 /* Note: m_currently_recording_lines is left as false until we see
20350 DW_LNE_end_sequence. */
20354 /* Subroutine of dwarf_decode_lines to simplify it.
20355 Process the line number information in LH.
20356 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20357 program in order to set included_p for every referenced header. */
20360 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20361 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20363 const gdb_byte
*line_ptr
, *extended_end
;
20364 const gdb_byte
*line_end
;
20365 unsigned int bytes_read
, extended_len
;
20366 unsigned char op_code
, extended_op
;
20367 CORE_ADDR baseaddr
;
20368 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20369 bfd
*abfd
= objfile
->obfd
;
20370 struct gdbarch
*gdbarch
= objfile
->arch ();
20371 /* True if we're recording line info (as opposed to building partial
20372 symtabs and just interested in finding include files mentioned by
20373 the line number program). */
20374 bool record_lines_p
= !decode_for_pst_p
;
20376 baseaddr
= objfile
->text_section_offset ();
20378 line_ptr
= lh
->statement_program_start
;
20379 line_end
= lh
->statement_program_end
;
20381 /* Read the statement sequences until there's nothing left. */
20382 while (line_ptr
< line_end
)
20384 /* The DWARF line number program state machine. Reset the state
20385 machine at the start of each sequence. */
20386 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20387 bool end_sequence
= false;
20389 if (record_lines_p
)
20391 /* Start a subfile for the current file of the state
20393 const file_entry
*fe
= state_machine
.current_file ();
20396 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20399 /* Decode the table. */
20400 while (line_ptr
< line_end
&& !end_sequence
)
20402 op_code
= read_1_byte (abfd
, line_ptr
);
20405 if (op_code
>= lh
->opcode_base
)
20407 /* Special opcode. */
20408 state_machine
.handle_special_opcode (op_code
);
20410 else switch (op_code
)
20412 case DW_LNS_extended_op
:
20413 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20415 line_ptr
+= bytes_read
;
20416 extended_end
= line_ptr
+ extended_len
;
20417 extended_op
= read_1_byte (abfd
, line_ptr
);
20419 switch (extended_op
)
20421 case DW_LNE_end_sequence
:
20422 state_machine
.handle_end_sequence ();
20423 end_sequence
= true;
20425 case DW_LNE_set_address
:
20428 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20429 line_ptr
+= bytes_read
;
20431 state_machine
.check_line_address (cu
, line_ptr
,
20432 lowpc
- baseaddr
, address
);
20433 state_machine
.handle_set_address (baseaddr
, address
);
20436 case DW_LNE_define_file
:
20438 const char *cur_file
;
20439 unsigned int mod_time
, length
;
20442 cur_file
= read_direct_string (abfd
, line_ptr
,
20444 line_ptr
+= bytes_read
;
20445 dindex
= (dir_index
)
20446 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20447 line_ptr
+= bytes_read
;
20449 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20450 line_ptr
+= bytes_read
;
20452 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20453 line_ptr
+= bytes_read
;
20454 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20457 case DW_LNE_set_discriminator
:
20459 /* The discriminator is not interesting to the
20460 debugger; just ignore it. We still need to
20461 check its value though:
20462 if there are consecutive entries for the same
20463 (non-prologue) line we want to coalesce them.
20466 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20467 line_ptr
+= bytes_read
;
20469 state_machine
.handle_set_discriminator (discr
);
20473 complaint (_("mangled .debug_line section"));
20476 /* Make sure that we parsed the extended op correctly. If e.g.
20477 we expected a different address size than the producer used,
20478 we may have read the wrong number of bytes. */
20479 if (line_ptr
!= extended_end
)
20481 complaint (_("mangled .debug_line section"));
20486 state_machine
.handle_copy ();
20488 case DW_LNS_advance_pc
:
20491 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20492 line_ptr
+= bytes_read
;
20494 state_machine
.handle_advance_pc (adjust
);
20497 case DW_LNS_advance_line
:
20500 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20501 line_ptr
+= bytes_read
;
20503 state_machine
.handle_advance_line (line_delta
);
20506 case DW_LNS_set_file
:
20508 file_name_index file
20509 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20511 line_ptr
+= bytes_read
;
20513 state_machine
.handle_set_file (file
);
20516 case DW_LNS_set_column
:
20517 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20518 line_ptr
+= bytes_read
;
20520 case DW_LNS_negate_stmt
:
20521 state_machine
.handle_negate_stmt ();
20523 case DW_LNS_set_basic_block
:
20525 /* Add to the address register of the state machine the
20526 address increment value corresponding to special opcode
20527 255. I.e., this value is scaled by the minimum
20528 instruction length since special opcode 255 would have
20529 scaled the increment. */
20530 case DW_LNS_const_add_pc
:
20531 state_machine
.handle_const_add_pc ();
20533 case DW_LNS_fixed_advance_pc
:
20535 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20538 state_machine
.handle_fixed_advance_pc (addr_adj
);
20543 /* Unknown standard opcode, ignore it. */
20546 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20548 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20549 line_ptr
+= bytes_read
;
20556 dwarf2_debug_line_missing_end_sequence_complaint ();
20558 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20559 in which case we still finish recording the last line). */
20560 state_machine
.record_line (true);
20564 /* Decode the Line Number Program (LNP) for the given line_header
20565 structure and CU. The actual information extracted and the type
20566 of structures created from the LNP depends on the value of PST.
20568 1. If PST is NULL, then this procedure uses the data from the program
20569 to create all necessary symbol tables, and their linetables.
20571 2. If PST is not NULL, this procedure reads the program to determine
20572 the list of files included by the unit represented by PST, and
20573 builds all the associated partial symbol tables.
20575 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20576 It is used for relative paths in the line table.
20577 NOTE: When processing partial symtabs (pst != NULL),
20578 comp_dir == pst->dirname.
20580 NOTE: It is important that psymtabs have the same file name (via strcmp)
20581 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20582 symtab we don't use it in the name of the psymtabs we create.
20583 E.g. expand_line_sal requires this when finding psymtabs to expand.
20584 A good testcase for this is mb-inline.exp.
20586 LOWPC is the lowest address in CU (or 0 if not known).
20588 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20589 for its PC<->lines mapping information. Otherwise only the filename
20590 table is read in. */
20593 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20594 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20595 CORE_ADDR lowpc
, int decode_mapping
)
20597 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20598 const int decode_for_pst_p
= (pst
!= NULL
);
20600 if (decode_mapping
)
20601 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20603 if (decode_for_pst_p
)
20605 /* Now that we're done scanning the Line Header Program, we can
20606 create the psymtab of each included file. */
20607 for (auto &file_entry
: lh
->file_names ())
20608 if (file_entry
.included_p
== 1)
20610 gdb::unique_xmalloc_ptr
<char> name_holder
;
20611 const char *include_name
=
20612 psymtab_include_file_name (lh
, file_entry
, pst
,
20613 comp_dir
, &name_holder
);
20614 if (include_name
!= NULL
)
20615 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20620 /* Make sure a symtab is created for every file, even files
20621 which contain only variables (i.e. no code with associated
20623 buildsym_compunit
*builder
= cu
->get_builder ();
20624 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20626 for (auto &fe
: lh
->file_names ())
20628 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20629 if (builder
->get_current_subfile ()->symtab
== NULL
)
20631 builder
->get_current_subfile ()->symtab
20632 = allocate_symtab (cust
,
20633 builder
->get_current_subfile ()->name
);
20635 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20640 /* Start a subfile for DWARF. FILENAME is the name of the file and
20641 DIRNAME the name of the source directory which contains FILENAME
20642 or NULL if not known.
20643 This routine tries to keep line numbers from identical absolute and
20644 relative file names in a common subfile.
20646 Using the `list' example from the GDB testsuite, which resides in
20647 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20648 of /srcdir/list0.c yields the following debugging information for list0.c:
20650 DW_AT_name: /srcdir/list0.c
20651 DW_AT_comp_dir: /compdir
20652 files.files[0].name: list0.h
20653 files.files[0].dir: /srcdir
20654 files.files[1].name: list0.c
20655 files.files[1].dir: /srcdir
20657 The line number information for list0.c has to end up in a single
20658 subfile, so that `break /srcdir/list0.c:1' works as expected.
20659 start_subfile will ensure that this happens provided that we pass the
20660 concatenation of files.files[1].dir and files.files[1].name as the
20664 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20665 const char *dirname
)
20667 gdb::unique_xmalloc_ptr
<char> copy
;
20669 /* In order not to lose the line information directory,
20670 we concatenate it to the filename when it makes sense.
20671 Note that the Dwarf3 standard says (speaking of filenames in line
20672 information): ``The directory index is ignored for file names
20673 that represent full path names''. Thus ignoring dirname in the
20674 `else' branch below isn't an issue. */
20676 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20678 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20679 filename
= copy
.get ();
20682 cu
->get_builder ()->start_subfile (filename
);
20685 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20686 buildsym_compunit constructor. */
20688 struct compunit_symtab
*
20689 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20692 gdb_assert (m_builder
== nullptr);
20694 m_builder
.reset (new struct buildsym_compunit
20695 (this->per_objfile
->objfile
,
20696 name
, comp_dir
, language
, low_pc
));
20698 list_in_scope
= get_builder ()->get_file_symbols ();
20700 get_builder ()->record_debugformat ("DWARF 2");
20701 get_builder ()->record_producer (producer
);
20703 processing_has_namespace_info
= false;
20705 return get_builder ()->get_compunit_symtab ();
20709 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20710 struct dwarf2_cu
*cu
)
20712 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20713 struct comp_unit_head
*cu_header
= &cu
->header
;
20715 /* NOTE drow/2003-01-30: There used to be a comment and some special
20716 code here to turn a symbol with DW_AT_external and a
20717 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20718 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20719 with some versions of binutils) where shared libraries could have
20720 relocations against symbols in their debug information - the
20721 minimal symbol would have the right address, but the debug info
20722 would not. It's no longer necessary, because we will explicitly
20723 apply relocations when we read in the debug information now. */
20725 /* A DW_AT_location attribute with no contents indicates that a
20726 variable has been optimized away. */
20727 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20729 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20733 /* Handle one degenerate form of location expression specially, to
20734 preserve GDB's previous behavior when section offsets are
20735 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20736 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20738 if (attr
->form_is_block ()
20739 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20740 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20741 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20742 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20743 && (DW_BLOCK (attr
)->size
20744 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20746 unsigned int dummy
;
20748 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20749 SET_SYMBOL_VALUE_ADDRESS
20750 (sym
, cu
->header
.read_address (objfile
->obfd
,
20751 DW_BLOCK (attr
)->data
+ 1,
20754 SET_SYMBOL_VALUE_ADDRESS
20755 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20757 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20758 fixup_symbol_section (sym
, objfile
);
20759 SET_SYMBOL_VALUE_ADDRESS
20761 SYMBOL_VALUE_ADDRESS (sym
)
20762 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20766 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20767 expression evaluator, and use LOC_COMPUTED only when necessary
20768 (i.e. when the value of a register or memory location is
20769 referenced, or a thread-local block, etc.). Then again, it might
20770 not be worthwhile. I'm assuming that it isn't unless performance
20771 or memory numbers show me otherwise. */
20773 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20775 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20776 cu
->has_loclist
= true;
20779 /* Given a pointer to a DWARF information entry, figure out if we need
20780 to make a symbol table entry for it, and if so, create a new entry
20781 and return a pointer to it.
20782 If TYPE is NULL, determine symbol type from the die, otherwise
20783 used the passed type.
20784 If SPACE is not NULL, use it to hold the new symbol. If it is
20785 NULL, allocate a new symbol on the objfile's obstack. */
20787 static struct symbol
*
20788 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20789 struct symbol
*space
)
20791 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20792 struct objfile
*objfile
= per_objfile
->objfile
;
20793 struct gdbarch
*gdbarch
= objfile
->arch ();
20794 struct symbol
*sym
= NULL
;
20796 struct attribute
*attr
= NULL
;
20797 struct attribute
*attr2
= NULL
;
20798 CORE_ADDR baseaddr
;
20799 struct pending
**list_to_add
= NULL
;
20801 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20803 baseaddr
= objfile
->text_section_offset ();
20805 name
= dwarf2_name (die
, cu
);
20808 int suppress_add
= 0;
20813 sym
= new (&objfile
->objfile_obstack
) symbol
;
20814 OBJSTAT (objfile
, n_syms
++);
20816 /* Cache this symbol's name and the name's demangled form (if any). */
20817 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20818 /* Fortran does not have mangling standard and the mangling does differ
20819 between gfortran, iFort etc. */
20820 const char *physname
20821 = (cu
->language
== language_fortran
20822 ? dwarf2_full_name (name
, die
, cu
)
20823 : dwarf2_physname (name
, die
, cu
));
20824 const char *linkagename
= dw2_linkage_name (die
, cu
);
20826 if (linkagename
== nullptr || cu
->language
== language_ada
)
20827 sym
->set_linkage_name (physname
);
20830 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20831 sym
->set_linkage_name (linkagename
);
20834 /* Default assumptions.
20835 Use the passed type or decode it from the die. */
20836 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20837 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20839 SYMBOL_TYPE (sym
) = type
;
20841 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20842 attr
= dwarf2_attr (die
,
20843 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20845 if (attr
!= nullptr)
20847 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20850 attr
= dwarf2_attr (die
,
20851 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20853 if (attr
!= nullptr)
20855 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20856 struct file_entry
*fe
;
20858 if (cu
->line_header
!= NULL
)
20859 fe
= cu
->line_header
->file_name_at (file_index
);
20864 complaint (_("file index out of range"));
20866 symbol_set_symtab (sym
, fe
->symtab
);
20872 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20873 if (attr
!= nullptr)
20877 addr
= attr
->value_as_address ();
20878 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20879 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20881 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20882 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20883 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20884 add_symbol_to_list (sym
, cu
->list_in_scope
);
20886 case DW_TAG_subprogram
:
20887 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20889 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20890 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20891 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20892 || cu
->language
== language_ada
20893 || cu
->language
== language_fortran
)
20895 /* Subprograms marked external are stored as a global symbol.
20896 Ada and Fortran subprograms, whether marked external or
20897 not, are always stored as a global symbol, because we want
20898 to be able to access them globally. For instance, we want
20899 to be able to break on a nested subprogram without having
20900 to specify the context. */
20901 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20905 list_to_add
= cu
->list_in_scope
;
20908 case DW_TAG_inlined_subroutine
:
20909 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20911 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20912 SYMBOL_INLINED (sym
) = 1;
20913 list_to_add
= cu
->list_in_scope
;
20915 case DW_TAG_template_value_param
:
20917 /* Fall through. */
20918 case DW_TAG_constant
:
20919 case DW_TAG_variable
:
20920 case DW_TAG_member
:
20921 /* Compilation with minimal debug info may result in
20922 variables with missing type entries. Change the
20923 misleading `void' type to something sensible. */
20924 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20925 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20927 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20928 /* In the case of DW_TAG_member, we should only be called for
20929 static const members. */
20930 if (die
->tag
== DW_TAG_member
)
20932 /* dwarf2_add_field uses die_is_declaration,
20933 so we do the same. */
20934 gdb_assert (die_is_declaration (die
, cu
));
20937 if (attr
!= nullptr)
20939 dwarf2_const_value (attr
, sym
, cu
);
20940 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20943 if (attr2
&& (DW_UNSND (attr2
) != 0))
20944 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20946 list_to_add
= cu
->list_in_scope
;
20950 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20951 if (attr
!= nullptr)
20953 var_decode_location (attr
, sym
, cu
);
20954 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20956 /* Fortran explicitly imports any global symbols to the local
20957 scope by DW_TAG_common_block. */
20958 if (cu
->language
== language_fortran
&& die
->parent
20959 && die
->parent
->tag
== DW_TAG_common_block
)
20962 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20963 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20964 && !per_objfile
->per_bfd
->has_section_at_zero
)
20966 /* When a static variable is eliminated by the linker,
20967 the corresponding debug information is not stripped
20968 out, but the variable address is set to null;
20969 do not add such variables into symbol table. */
20971 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20973 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20974 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20975 && per_objfile
->per_bfd
->can_copy
)
20977 /* A global static variable might be subject to
20978 copy relocation. We first check for a local
20979 minsym, though, because maybe the symbol was
20980 marked hidden, in which case this would not
20982 bound_minimal_symbol found
20983 = (lookup_minimal_symbol_linkage
20984 (sym
->linkage_name (), objfile
));
20985 if (found
.minsym
!= nullptr)
20986 sym
->maybe_copied
= 1;
20989 /* A variable with DW_AT_external is never static,
20990 but it may be block-scoped. */
20992 = ((cu
->list_in_scope
20993 == cu
->get_builder ()->get_file_symbols ())
20994 ? cu
->get_builder ()->get_global_symbols ()
20995 : cu
->list_in_scope
);
20998 list_to_add
= cu
->list_in_scope
;
21002 /* We do not know the address of this symbol.
21003 If it is an external symbol and we have type information
21004 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21005 The address of the variable will then be determined from
21006 the minimal symbol table whenever the variable is
21008 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21010 /* Fortran explicitly imports any global symbols to the local
21011 scope by DW_TAG_common_block. */
21012 if (cu
->language
== language_fortran
&& die
->parent
21013 && die
->parent
->tag
== DW_TAG_common_block
)
21015 /* SYMBOL_CLASS doesn't matter here because
21016 read_common_block is going to reset it. */
21018 list_to_add
= cu
->list_in_scope
;
21020 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21021 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21023 /* A variable with DW_AT_external is never static, but it
21024 may be block-scoped. */
21026 = ((cu
->list_in_scope
21027 == cu
->get_builder ()->get_file_symbols ())
21028 ? cu
->get_builder ()->get_global_symbols ()
21029 : cu
->list_in_scope
);
21031 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21033 else if (!die_is_declaration (die
, cu
))
21035 /* Use the default LOC_OPTIMIZED_OUT class. */
21036 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21038 list_to_add
= cu
->list_in_scope
;
21042 case DW_TAG_formal_parameter
:
21044 /* If we are inside a function, mark this as an argument. If
21045 not, we might be looking at an argument to an inlined function
21046 when we do not have enough information to show inlined frames;
21047 pretend it's a local variable in that case so that the user can
21049 struct context_stack
*curr
21050 = cu
->get_builder ()->get_current_context_stack ();
21051 if (curr
!= nullptr && curr
->name
!= nullptr)
21052 SYMBOL_IS_ARGUMENT (sym
) = 1;
21053 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21054 if (attr
!= nullptr)
21056 var_decode_location (attr
, sym
, cu
);
21058 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21059 if (attr
!= nullptr)
21061 dwarf2_const_value (attr
, sym
, cu
);
21064 list_to_add
= cu
->list_in_scope
;
21067 case DW_TAG_unspecified_parameters
:
21068 /* From varargs functions; gdb doesn't seem to have any
21069 interest in this information, so just ignore it for now.
21072 case DW_TAG_template_type_param
:
21074 /* Fall through. */
21075 case DW_TAG_class_type
:
21076 case DW_TAG_interface_type
:
21077 case DW_TAG_structure_type
:
21078 case DW_TAG_union_type
:
21079 case DW_TAG_set_type
:
21080 case DW_TAG_enumeration_type
:
21081 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21082 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21085 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21086 really ever be static objects: otherwise, if you try
21087 to, say, break of a class's method and you're in a file
21088 which doesn't mention that class, it won't work unless
21089 the check for all static symbols in lookup_symbol_aux
21090 saves you. See the OtherFileClass tests in
21091 gdb.c++/namespace.exp. */
21095 buildsym_compunit
*builder
= cu
->get_builder ();
21097 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21098 && cu
->language
== language_cplus
21099 ? builder
->get_global_symbols ()
21100 : cu
->list_in_scope
);
21102 /* The semantics of C++ state that "struct foo {
21103 ... }" also defines a typedef for "foo". */
21104 if (cu
->language
== language_cplus
21105 || cu
->language
== language_ada
21106 || cu
->language
== language_d
21107 || cu
->language
== language_rust
)
21109 /* The symbol's name is already allocated along
21110 with this objfile, so we don't need to
21111 duplicate it for the type. */
21112 if (SYMBOL_TYPE (sym
)->name () == 0)
21113 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21118 case DW_TAG_typedef
:
21119 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21120 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21121 list_to_add
= cu
->list_in_scope
;
21123 case DW_TAG_base_type
:
21124 case DW_TAG_subrange_type
:
21125 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21126 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21127 list_to_add
= cu
->list_in_scope
;
21129 case DW_TAG_enumerator
:
21130 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21131 if (attr
!= nullptr)
21133 dwarf2_const_value (attr
, sym
, cu
);
21136 /* NOTE: carlton/2003-11-10: See comment above in the
21137 DW_TAG_class_type, etc. block. */
21140 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21141 && cu
->language
== language_cplus
21142 ? cu
->get_builder ()->get_global_symbols ()
21143 : cu
->list_in_scope
);
21146 case DW_TAG_imported_declaration
:
21147 case DW_TAG_namespace
:
21148 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21149 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21151 case DW_TAG_module
:
21152 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21153 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21154 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21156 case DW_TAG_common_block
:
21157 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21158 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21159 add_symbol_to_list (sym
, cu
->list_in_scope
);
21162 /* Not a tag we recognize. Hopefully we aren't processing
21163 trash data, but since we must specifically ignore things
21164 we don't recognize, there is nothing else we should do at
21166 complaint (_("unsupported tag: '%s'"),
21167 dwarf_tag_name (die
->tag
));
21173 sym
->hash_next
= objfile
->template_symbols
;
21174 objfile
->template_symbols
= sym
;
21175 list_to_add
= NULL
;
21178 if (list_to_add
!= NULL
)
21179 add_symbol_to_list (sym
, list_to_add
);
21181 /* For the benefit of old versions of GCC, check for anonymous
21182 namespaces based on the demangled name. */
21183 if (!cu
->processing_has_namespace_info
21184 && cu
->language
== language_cplus
)
21185 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21190 /* Given an attr with a DW_FORM_dataN value in host byte order,
21191 zero-extend it as appropriate for the symbol's type. The DWARF
21192 standard (v4) is not entirely clear about the meaning of using
21193 DW_FORM_dataN for a constant with a signed type, where the type is
21194 wider than the data. The conclusion of a discussion on the DWARF
21195 list was that this is unspecified. We choose to always zero-extend
21196 because that is the interpretation long in use by GCC. */
21199 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21200 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21202 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21203 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21204 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21205 LONGEST l
= DW_UNSND (attr
);
21207 if (bits
< sizeof (*value
) * 8)
21209 l
&= ((LONGEST
) 1 << bits
) - 1;
21212 else if (bits
== sizeof (*value
) * 8)
21216 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21217 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21224 /* Read a constant value from an attribute. Either set *VALUE, or if
21225 the value does not fit in *VALUE, set *BYTES - either already
21226 allocated on the objfile obstack, or newly allocated on OBSTACK,
21227 or, set *BATON, if we translated the constant to a location
21231 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21232 const char *name
, struct obstack
*obstack
,
21233 struct dwarf2_cu
*cu
,
21234 LONGEST
*value
, const gdb_byte
**bytes
,
21235 struct dwarf2_locexpr_baton
**baton
)
21237 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21238 struct objfile
*objfile
= per_objfile
->objfile
;
21239 struct comp_unit_head
*cu_header
= &cu
->header
;
21240 struct dwarf_block
*blk
;
21241 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21242 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21248 switch (attr
->form
)
21251 case DW_FORM_addrx
:
21252 case DW_FORM_GNU_addr_index
:
21256 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21257 dwarf2_const_value_length_mismatch_complaint (name
,
21258 cu_header
->addr_size
,
21259 TYPE_LENGTH (type
));
21260 /* Symbols of this form are reasonably rare, so we just
21261 piggyback on the existing location code rather than writing
21262 a new implementation of symbol_computed_ops. */
21263 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21264 (*baton
)->per_objfile
= per_objfile
;
21265 (*baton
)->per_cu
= cu
->per_cu
;
21266 gdb_assert ((*baton
)->per_cu
);
21268 (*baton
)->size
= 2 + cu_header
->addr_size
;
21269 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21270 (*baton
)->data
= data
;
21272 data
[0] = DW_OP_addr
;
21273 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21274 byte_order
, DW_ADDR (attr
));
21275 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21278 case DW_FORM_string
:
21281 case DW_FORM_GNU_str_index
:
21282 case DW_FORM_GNU_strp_alt
:
21283 /* DW_STRING is already allocated on the objfile obstack, point
21285 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21287 case DW_FORM_block1
:
21288 case DW_FORM_block2
:
21289 case DW_FORM_block4
:
21290 case DW_FORM_block
:
21291 case DW_FORM_exprloc
:
21292 case DW_FORM_data16
:
21293 blk
= DW_BLOCK (attr
);
21294 if (TYPE_LENGTH (type
) != blk
->size
)
21295 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21296 TYPE_LENGTH (type
));
21297 *bytes
= blk
->data
;
21300 /* The DW_AT_const_value attributes are supposed to carry the
21301 symbol's value "represented as it would be on the target
21302 architecture." By the time we get here, it's already been
21303 converted to host endianness, so we just need to sign- or
21304 zero-extend it as appropriate. */
21305 case DW_FORM_data1
:
21306 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21308 case DW_FORM_data2
:
21309 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21311 case DW_FORM_data4
:
21312 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21314 case DW_FORM_data8
:
21315 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21318 case DW_FORM_sdata
:
21319 case DW_FORM_implicit_const
:
21320 *value
= DW_SND (attr
);
21323 case DW_FORM_udata
:
21324 *value
= DW_UNSND (attr
);
21328 complaint (_("unsupported const value attribute form: '%s'"),
21329 dwarf_form_name (attr
->form
));
21336 /* Copy constant value from an attribute to a symbol. */
21339 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21340 struct dwarf2_cu
*cu
)
21342 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21344 const gdb_byte
*bytes
;
21345 struct dwarf2_locexpr_baton
*baton
;
21347 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21348 sym
->print_name (),
21349 &objfile
->objfile_obstack
, cu
,
21350 &value
, &bytes
, &baton
);
21354 SYMBOL_LOCATION_BATON (sym
) = baton
;
21355 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21357 else if (bytes
!= NULL
)
21359 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21360 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21364 SYMBOL_VALUE (sym
) = value
;
21365 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21369 /* Return the type of the die in question using its DW_AT_type attribute. */
21371 static struct type
*
21372 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21374 struct attribute
*type_attr
;
21376 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21379 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21380 /* A missing DW_AT_type represents a void type. */
21381 return objfile_type (objfile
)->builtin_void
;
21384 return lookup_die_type (die
, type_attr
, cu
);
21387 /* True iff CU's producer generates GNAT Ada auxiliary information
21388 that allows to find parallel types through that information instead
21389 of having to do expensive parallel lookups by type name. */
21392 need_gnat_info (struct dwarf2_cu
*cu
)
21394 /* Assume that the Ada compiler was GNAT, which always produces
21395 the auxiliary information. */
21396 return (cu
->language
== language_ada
);
21399 /* Return the auxiliary type of the die in question using its
21400 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21401 attribute is not present. */
21403 static struct type
*
21404 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21406 struct attribute
*type_attr
;
21408 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21412 return lookup_die_type (die
, type_attr
, cu
);
21415 /* If DIE has a descriptive_type attribute, then set the TYPE's
21416 descriptive type accordingly. */
21419 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21420 struct dwarf2_cu
*cu
)
21422 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21424 if (descriptive_type
)
21426 ALLOCATE_GNAT_AUX_TYPE (type
);
21427 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21431 /* Return the containing type of the die in question using its
21432 DW_AT_containing_type attribute. */
21434 static struct type
*
21435 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21437 struct attribute
*type_attr
;
21438 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21440 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21442 error (_("Dwarf Error: Problem turning containing type into gdb type "
21443 "[in module %s]"), objfile_name (objfile
));
21445 return lookup_die_type (die
, type_attr
, cu
);
21448 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21450 static struct type
*
21451 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21453 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21454 struct objfile
*objfile
= per_objfile
->objfile
;
21457 std::string message
21458 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21459 objfile_name (objfile
),
21460 sect_offset_str (cu
->header
.sect_off
),
21461 sect_offset_str (die
->sect_off
));
21462 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21464 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21467 /* Look up the type of DIE in CU using its type attribute ATTR.
21468 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21469 DW_AT_containing_type.
21470 If there is no type substitute an error marker. */
21472 static struct type
*
21473 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21474 struct dwarf2_cu
*cu
)
21476 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21477 struct objfile
*objfile
= per_objfile
->objfile
;
21478 struct type
*this_type
;
21480 gdb_assert (attr
->name
== DW_AT_type
21481 || attr
->name
== DW_AT_GNAT_descriptive_type
21482 || attr
->name
== DW_AT_containing_type
);
21484 /* First see if we have it cached. */
21486 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21488 struct dwarf2_per_cu_data
*per_cu
;
21489 sect_offset sect_off
= attr
->get_ref_die_offset ();
21491 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
21492 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
21494 else if (attr
->form_is_ref ())
21496 sect_offset sect_off
= attr
->get_ref_die_offset ();
21498 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
21500 else if (attr
->form
== DW_FORM_ref_sig8
)
21502 ULONGEST signature
= DW_SIGNATURE (attr
);
21504 return get_signatured_type (die
, signature
, cu
);
21508 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21509 " at %s [in module %s]"),
21510 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21511 objfile_name (objfile
));
21512 return build_error_marker_type (cu
, die
);
21515 /* If not cached we need to read it in. */
21517 if (this_type
== NULL
)
21519 struct die_info
*type_die
= NULL
;
21520 struct dwarf2_cu
*type_cu
= cu
;
21522 if (attr
->form_is_ref ())
21523 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21524 if (type_die
== NULL
)
21525 return build_error_marker_type (cu
, die
);
21526 /* If we find the type now, it's probably because the type came
21527 from an inter-CU reference and the type's CU got expanded before
21529 this_type
= read_type_die (type_die
, type_cu
);
21532 /* If we still don't have a type use an error marker. */
21534 if (this_type
== NULL
)
21535 return build_error_marker_type (cu
, die
);
21540 /* Return the type in DIE, CU.
21541 Returns NULL for invalid types.
21543 This first does a lookup in die_type_hash,
21544 and only reads the die in if necessary.
21546 NOTE: This can be called when reading in partial or full symbols. */
21548 static struct type
*
21549 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21551 struct type
*this_type
;
21553 this_type
= get_die_type (die
, cu
);
21557 return read_type_die_1 (die
, cu
);
21560 /* Read the type in DIE, CU.
21561 Returns NULL for invalid types. */
21563 static struct type
*
21564 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21566 struct type
*this_type
= NULL
;
21570 case DW_TAG_class_type
:
21571 case DW_TAG_interface_type
:
21572 case DW_TAG_structure_type
:
21573 case DW_TAG_union_type
:
21574 this_type
= read_structure_type (die
, cu
);
21576 case DW_TAG_enumeration_type
:
21577 this_type
= read_enumeration_type (die
, cu
);
21579 case DW_TAG_subprogram
:
21580 case DW_TAG_subroutine_type
:
21581 case DW_TAG_inlined_subroutine
:
21582 this_type
= read_subroutine_type (die
, cu
);
21584 case DW_TAG_array_type
:
21585 this_type
= read_array_type (die
, cu
);
21587 case DW_TAG_set_type
:
21588 this_type
= read_set_type (die
, cu
);
21590 case DW_TAG_pointer_type
:
21591 this_type
= read_tag_pointer_type (die
, cu
);
21593 case DW_TAG_ptr_to_member_type
:
21594 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21596 case DW_TAG_reference_type
:
21597 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21599 case DW_TAG_rvalue_reference_type
:
21600 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21602 case DW_TAG_const_type
:
21603 this_type
= read_tag_const_type (die
, cu
);
21605 case DW_TAG_volatile_type
:
21606 this_type
= read_tag_volatile_type (die
, cu
);
21608 case DW_TAG_restrict_type
:
21609 this_type
= read_tag_restrict_type (die
, cu
);
21611 case DW_TAG_string_type
:
21612 this_type
= read_tag_string_type (die
, cu
);
21614 case DW_TAG_typedef
:
21615 this_type
= read_typedef (die
, cu
);
21617 case DW_TAG_subrange_type
:
21618 this_type
= read_subrange_type (die
, cu
);
21620 case DW_TAG_base_type
:
21621 this_type
= read_base_type (die
, cu
);
21623 case DW_TAG_unspecified_type
:
21624 this_type
= read_unspecified_type (die
, cu
);
21626 case DW_TAG_namespace
:
21627 this_type
= read_namespace_type (die
, cu
);
21629 case DW_TAG_module
:
21630 this_type
= read_module_type (die
, cu
);
21632 case DW_TAG_atomic_type
:
21633 this_type
= read_tag_atomic_type (die
, cu
);
21636 complaint (_("unexpected tag in read_type_die: '%s'"),
21637 dwarf_tag_name (die
->tag
));
21644 /* See if we can figure out if the class lives in a namespace. We do
21645 this by looking for a member function; its demangled name will
21646 contain namespace info, if there is any.
21647 Return the computed name or NULL.
21648 Space for the result is allocated on the objfile's obstack.
21649 This is the full-die version of guess_partial_die_structure_name.
21650 In this case we know DIE has no useful parent. */
21652 static const char *
21653 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21655 struct die_info
*spec_die
;
21656 struct dwarf2_cu
*spec_cu
;
21657 struct die_info
*child
;
21658 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21661 spec_die
= die_specification (die
, &spec_cu
);
21662 if (spec_die
!= NULL
)
21668 for (child
= die
->child
;
21670 child
= child
->sibling
)
21672 if (child
->tag
== DW_TAG_subprogram
)
21674 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21676 if (linkage_name
!= NULL
)
21678 gdb::unique_xmalloc_ptr
<char> actual_name
21679 (language_class_name_from_physname (cu
->language_defn
,
21681 const char *name
= NULL
;
21683 if (actual_name
!= NULL
)
21685 const char *die_name
= dwarf2_name (die
, cu
);
21687 if (die_name
!= NULL
21688 && strcmp (die_name
, actual_name
.get ()) != 0)
21690 /* Strip off the class name from the full name.
21691 We want the prefix. */
21692 int die_name_len
= strlen (die_name
);
21693 int actual_name_len
= strlen (actual_name
.get ());
21694 const char *ptr
= actual_name
.get ();
21696 /* Test for '::' as a sanity check. */
21697 if (actual_name_len
> die_name_len
+ 2
21698 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21699 name
= obstack_strndup (
21700 &objfile
->per_bfd
->storage_obstack
,
21701 ptr
, actual_name_len
- die_name_len
- 2);
21712 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21713 prefix part in such case. See
21714 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21716 static const char *
21717 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21719 struct attribute
*attr
;
21722 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21723 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21726 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21729 attr
= dw2_linkage_name_attr (die
, cu
);
21730 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21733 /* dwarf2_name had to be already called. */
21734 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21736 /* Strip the base name, keep any leading namespaces/classes. */
21737 base
= strrchr (DW_STRING (attr
), ':');
21738 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21741 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21742 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21744 &base
[-1] - DW_STRING (attr
));
21747 /* Return the name of the namespace/class that DIE is defined within,
21748 or "" if we can't tell. The caller should not xfree the result.
21750 For example, if we're within the method foo() in the following
21760 then determine_prefix on foo's die will return "N::C". */
21762 static const char *
21763 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21765 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21766 struct die_info
*parent
, *spec_die
;
21767 struct dwarf2_cu
*spec_cu
;
21768 struct type
*parent_type
;
21769 const char *retval
;
21771 if (cu
->language
!= language_cplus
21772 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21773 && cu
->language
!= language_rust
)
21776 retval
= anonymous_struct_prefix (die
, cu
);
21780 /* We have to be careful in the presence of DW_AT_specification.
21781 For example, with GCC 3.4, given the code
21785 // Definition of N::foo.
21789 then we'll have a tree of DIEs like this:
21791 1: DW_TAG_compile_unit
21792 2: DW_TAG_namespace // N
21793 3: DW_TAG_subprogram // declaration of N::foo
21794 4: DW_TAG_subprogram // definition of N::foo
21795 DW_AT_specification // refers to die #3
21797 Thus, when processing die #4, we have to pretend that we're in
21798 the context of its DW_AT_specification, namely the contex of die
21801 spec_die
= die_specification (die
, &spec_cu
);
21802 if (spec_die
== NULL
)
21803 parent
= die
->parent
;
21806 parent
= spec_die
->parent
;
21810 if (parent
== NULL
)
21812 else if (parent
->building_fullname
)
21815 const char *parent_name
;
21817 /* It has been seen on RealView 2.2 built binaries,
21818 DW_TAG_template_type_param types actually _defined_ as
21819 children of the parent class:
21822 template class <class Enum> Class{};
21823 Class<enum E> class_e;
21825 1: DW_TAG_class_type (Class)
21826 2: DW_TAG_enumeration_type (E)
21827 3: DW_TAG_enumerator (enum1:0)
21828 3: DW_TAG_enumerator (enum2:1)
21830 2: DW_TAG_template_type_param
21831 DW_AT_type DW_FORM_ref_udata (E)
21833 Besides being broken debug info, it can put GDB into an
21834 infinite loop. Consider:
21836 When we're building the full name for Class<E>, we'll start
21837 at Class, and go look over its template type parameters,
21838 finding E. We'll then try to build the full name of E, and
21839 reach here. We're now trying to build the full name of E,
21840 and look over the parent DIE for containing scope. In the
21841 broken case, if we followed the parent DIE of E, we'd again
21842 find Class, and once again go look at its template type
21843 arguments, etc., etc. Simply don't consider such parent die
21844 as source-level parent of this die (it can't be, the language
21845 doesn't allow it), and break the loop here. */
21846 name
= dwarf2_name (die
, cu
);
21847 parent_name
= dwarf2_name (parent
, cu
);
21848 complaint (_("template param type '%s' defined within parent '%s'"),
21849 name
? name
: "<unknown>",
21850 parent_name
? parent_name
: "<unknown>");
21854 switch (parent
->tag
)
21856 case DW_TAG_namespace
:
21857 parent_type
= read_type_die (parent
, cu
);
21858 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21859 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21860 Work around this problem here. */
21861 if (cu
->language
== language_cplus
21862 && strcmp (parent_type
->name (), "::") == 0)
21864 /* We give a name to even anonymous namespaces. */
21865 return parent_type
->name ();
21866 case DW_TAG_class_type
:
21867 case DW_TAG_interface_type
:
21868 case DW_TAG_structure_type
:
21869 case DW_TAG_union_type
:
21870 case DW_TAG_module
:
21871 parent_type
= read_type_die (parent
, cu
);
21872 if (parent_type
->name () != NULL
)
21873 return parent_type
->name ();
21875 /* An anonymous structure is only allowed non-static data
21876 members; no typedefs, no member functions, et cetera.
21877 So it does not need a prefix. */
21879 case DW_TAG_compile_unit
:
21880 case DW_TAG_partial_unit
:
21881 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21882 if (cu
->language
== language_cplus
21883 && !per_objfile
->per_bfd
->types
.empty ()
21884 && die
->child
!= NULL
21885 && (die
->tag
== DW_TAG_class_type
21886 || die
->tag
== DW_TAG_structure_type
21887 || die
->tag
== DW_TAG_union_type
))
21889 const char *name
= guess_full_die_structure_name (die
, cu
);
21894 case DW_TAG_subprogram
:
21895 /* Nested subroutines in Fortran get a prefix with the name
21896 of the parent's subroutine. */
21897 if (cu
->language
== language_fortran
)
21899 if ((die
->tag
== DW_TAG_subprogram
)
21900 && (dwarf2_name (parent
, cu
) != NULL
))
21901 return dwarf2_name (parent
, cu
);
21903 return determine_prefix (parent
, cu
);
21904 case DW_TAG_enumeration_type
:
21905 parent_type
= read_type_die (parent
, cu
);
21906 if (TYPE_DECLARED_CLASS (parent_type
))
21908 if (parent_type
->name () != NULL
)
21909 return parent_type
->name ();
21912 /* Fall through. */
21914 return determine_prefix (parent
, cu
);
21918 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21919 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21920 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21921 an obconcat, otherwise allocate storage for the result. The CU argument is
21922 used to determine the language and hence, the appropriate separator. */
21924 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21927 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21928 int physname
, struct dwarf2_cu
*cu
)
21930 const char *lead
= "";
21933 if (suffix
== NULL
|| suffix
[0] == '\0'
21934 || prefix
== NULL
|| prefix
[0] == '\0')
21936 else if (cu
->language
== language_d
)
21938 /* For D, the 'main' function could be defined in any module, but it
21939 should never be prefixed. */
21940 if (strcmp (suffix
, "D main") == 0)
21948 else if (cu
->language
== language_fortran
&& physname
)
21950 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21951 DW_AT_MIPS_linkage_name is preferred and used instead. */
21959 if (prefix
== NULL
)
21961 if (suffix
== NULL
)
21968 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21970 strcpy (retval
, lead
);
21971 strcat (retval
, prefix
);
21972 strcat (retval
, sep
);
21973 strcat (retval
, suffix
);
21978 /* We have an obstack. */
21979 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21983 /* Get name of a die, return NULL if not found. */
21985 static const char *
21986 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21987 struct objfile
*objfile
)
21989 if (name
&& cu
->language
== language_cplus
)
21991 gdb::unique_xmalloc_ptr
<char> canon_name
21992 = cp_canonicalize_string (name
);
21994 if (canon_name
!= nullptr)
21995 name
= objfile
->intern (canon_name
.get ());
22001 /* Get name of a die, return NULL if not found.
22002 Anonymous namespaces are converted to their magic string. */
22004 static const char *
22005 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22007 struct attribute
*attr
;
22008 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22010 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22011 if ((!attr
|| !DW_STRING (attr
))
22012 && die
->tag
!= DW_TAG_namespace
22013 && die
->tag
!= DW_TAG_class_type
22014 && die
->tag
!= DW_TAG_interface_type
22015 && die
->tag
!= DW_TAG_structure_type
22016 && die
->tag
!= DW_TAG_union_type
)
22021 case DW_TAG_compile_unit
:
22022 case DW_TAG_partial_unit
:
22023 /* Compilation units have a DW_AT_name that is a filename, not
22024 a source language identifier. */
22025 case DW_TAG_enumeration_type
:
22026 case DW_TAG_enumerator
:
22027 /* These tags always have simple identifiers already; no need
22028 to canonicalize them. */
22029 return DW_STRING (attr
);
22031 case DW_TAG_namespace
:
22032 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22033 return DW_STRING (attr
);
22034 return CP_ANONYMOUS_NAMESPACE_STR
;
22036 case DW_TAG_class_type
:
22037 case DW_TAG_interface_type
:
22038 case DW_TAG_structure_type
:
22039 case DW_TAG_union_type
:
22040 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22041 structures or unions. These were of the form "._%d" in GCC 4.1,
22042 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22043 and GCC 4.4. We work around this problem by ignoring these. */
22044 if (attr
&& DW_STRING (attr
)
22045 && (startswith (DW_STRING (attr
), "._")
22046 || startswith (DW_STRING (attr
), "<anonymous")))
22049 /* GCC might emit a nameless typedef that has a linkage name. See
22050 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22051 if (!attr
|| DW_STRING (attr
) == NULL
)
22053 attr
= dw2_linkage_name_attr (die
, cu
);
22054 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22057 /* Avoid demangling DW_STRING (attr) the second time on a second
22058 call for the same DIE. */
22059 if (!DW_STRING_IS_CANONICAL (attr
))
22061 gdb::unique_xmalloc_ptr
<char> demangled
22062 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22063 if (demangled
== nullptr)
22066 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
22067 DW_STRING_IS_CANONICAL (attr
) = 1;
22070 /* Strip any leading namespaces/classes, keep only the base name.
22071 DW_AT_name for named DIEs does not contain the prefixes. */
22072 const char *base
= strrchr (DW_STRING (attr
), ':');
22073 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22076 return DW_STRING (attr
);
22084 if (!DW_STRING_IS_CANONICAL (attr
))
22086 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22088 DW_STRING_IS_CANONICAL (attr
) = 1;
22090 return DW_STRING (attr
);
22093 /* Return the die that this die in an extension of, or NULL if there
22094 is none. *EXT_CU is the CU containing DIE on input, and the CU
22095 containing the return value on output. */
22097 static struct die_info
*
22098 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22100 struct attribute
*attr
;
22102 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22106 return follow_die_ref (die
, attr
, ext_cu
);
22110 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22114 print_spaces (indent
, f
);
22115 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22116 dwarf_tag_name (die
->tag
), die
->abbrev
,
22117 sect_offset_str (die
->sect_off
));
22119 if (die
->parent
!= NULL
)
22121 print_spaces (indent
, f
);
22122 fprintf_unfiltered (f
, " parent at offset: %s\n",
22123 sect_offset_str (die
->parent
->sect_off
));
22126 print_spaces (indent
, f
);
22127 fprintf_unfiltered (f
, " has children: %s\n",
22128 dwarf_bool_name (die
->child
!= NULL
));
22130 print_spaces (indent
, f
);
22131 fprintf_unfiltered (f
, " attributes:\n");
22133 for (i
= 0; i
< die
->num_attrs
; ++i
)
22135 print_spaces (indent
, f
);
22136 fprintf_unfiltered (f
, " %s (%s) ",
22137 dwarf_attr_name (die
->attrs
[i
].name
),
22138 dwarf_form_name (die
->attrs
[i
].form
));
22140 switch (die
->attrs
[i
].form
)
22143 case DW_FORM_addrx
:
22144 case DW_FORM_GNU_addr_index
:
22145 fprintf_unfiltered (f
, "address: ");
22146 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22148 case DW_FORM_block2
:
22149 case DW_FORM_block4
:
22150 case DW_FORM_block
:
22151 case DW_FORM_block1
:
22152 fprintf_unfiltered (f
, "block: size %s",
22153 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22155 case DW_FORM_exprloc
:
22156 fprintf_unfiltered (f
, "expression: size %s",
22157 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22159 case DW_FORM_data16
:
22160 fprintf_unfiltered (f
, "constant of 16 bytes");
22162 case DW_FORM_ref_addr
:
22163 fprintf_unfiltered (f
, "ref address: ");
22164 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22166 case DW_FORM_GNU_ref_alt
:
22167 fprintf_unfiltered (f
, "alt ref address: ");
22168 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22174 case DW_FORM_ref_udata
:
22175 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22176 (long) (DW_UNSND (&die
->attrs
[i
])));
22178 case DW_FORM_data1
:
22179 case DW_FORM_data2
:
22180 case DW_FORM_data4
:
22181 case DW_FORM_data8
:
22182 case DW_FORM_udata
:
22183 case DW_FORM_sdata
:
22184 fprintf_unfiltered (f
, "constant: %s",
22185 pulongest (DW_UNSND (&die
->attrs
[i
])));
22187 case DW_FORM_sec_offset
:
22188 fprintf_unfiltered (f
, "section offset: %s",
22189 pulongest (DW_UNSND (&die
->attrs
[i
])));
22191 case DW_FORM_ref_sig8
:
22192 fprintf_unfiltered (f
, "signature: %s",
22193 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22195 case DW_FORM_string
:
22197 case DW_FORM_line_strp
:
22199 case DW_FORM_GNU_str_index
:
22200 case DW_FORM_GNU_strp_alt
:
22201 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22202 DW_STRING (&die
->attrs
[i
])
22203 ? DW_STRING (&die
->attrs
[i
]) : "",
22204 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22207 if (DW_UNSND (&die
->attrs
[i
]))
22208 fprintf_unfiltered (f
, "flag: TRUE");
22210 fprintf_unfiltered (f
, "flag: FALSE");
22212 case DW_FORM_flag_present
:
22213 fprintf_unfiltered (f
, "flag: TRUE");
22215 case DW_FORM_indirect
:
22216 /* The reader will have reduced the indirect form to
22217 the "base form" so this form should not occur. */
22218 fprintf_unfiltered (f
,
22219 "unexpected attribute form: DW_FORM_indirect");
22221 case DW_FORM_implicit_const
:
22222 fprintf_unfiltered (f
, "constant: %s",
22223 plongest (DW_SND (&die
->attrs
[i
])));
22226 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22227 die
->attrs
[i
].form
);
22230 fprintf_unfiltered (f
, "\n");
22235 dump_die_for_error (struct die_info
*die
)
22237 dump_die_shallow (gdb_stderr
, 0, die
);
22241 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22243 int indent
= level
* 4;
22245 gdb_assert (die
!= NULL
);
22247 if (level
>= max_level
)
22250 dump_die_shallow (f
, indent
, die
);
22252 if (die
->child
!= NULL
)
22254 print_spaces (indent
, f
);
22255 fprintf_unfiltered (f
, " Children:");
22256 if (level
+ 1 < max_level
)
22258 fprintf_unfiltered (f
, "\n");
22259 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22263 fprintf_unfiltered (f
,
22264 " [not printed, max nesting level reached]\n");
22268 if (die
->sibling
!= NULL
&& level
> 0)
22270 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22274 /* This is called from the pdie macro in gdbinit.in.
22275 It's not static so gcc will keep a copy callable from gdb. */
22278 dump_die (struct die_info
*die
, int max_level
)
22280 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22284 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22288 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22289 to_underlying (die
->sect_off
),
22295 /* Follow reference or signature attribute ATTR of SRC_DIE.
22296 On entry *REF_CU is the CU of SRC_DIE.
22297 On exit *REF_CU is the CU of the result. */
22299 static struct die_info
*
22300 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22301 struct dwarf2_cu
**ref_cu
)
22303 struct die_info
*die
;
22305 if (attr
->form_is_ref ())
22306 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22307 else if (attr
->form
== DW_FORM_ref_sig8
)
22308 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22311 dump_die_for_error (src_die
);
22312 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22313 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22319 /* Follow reference OFFSET.
22320 On entry *REF_CU is the CU of the source die referencing OFFSET.
22321 On exit *REF_CU is the CU of the result.
22322 Returns NULL if OFFSET is invalid. */
22324 static struct die_info
*
22325 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22326 struct dwarf2_cu
**ref_cu
)
22328 struct die_info temp_die
;
22329 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22330 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22332 gdb_assert (cu
->per_cu
!= NULL
);
22336 if (cu
->per_cu
->is_debug_types
)
22338 /* .debug_types CUs cannot reference anything outside their CU.
22339 If they need to, they have to reference a signatured type via
22340 DW_FORM_ref_sig8. */
22341 if (!cu
->header
.offset_in_cu_p (sect_off
))
22344 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22345 || !cu
->header
.offset_in_cu_p (sect_off
))
22347 struct dwarf2_per_cu_data
*per_cu
;
22349 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22352 /* If necessary, add it to the queue and load its DIEs. */
22353 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
22354 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
22356 target_cu
= per_objfile
->get_cu (per_cu
);
22358 else if (cu
->dies
== NULL
)
22360 /* We're loading full DIEs during partial symbol reading. */
22361 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
22362 load_full_comp_unit (cu
->per_cu
, per_objfile
, false, language_minimal
);
22365 *ref_cu
= target_cu
;
22366 temp_die
.sect_off
= sect_off
;
22368 if (target_cu
!= cu
)
22369 target_cu
->ancestor
= cu
;
22371 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22373 to_underlying (sect_off
));
22376 /* Follow reference attribute ATTR of SRC_DIE.
22377 On entry *REF_CU is the CU of SRC_DIE.
22378 On exit *REF_CU is the CU of the result. */
22380 static struct die_info
*
22381 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22382 struct dwarf2_cu
**ref_cu
)
22384 sect_offset sect_off
= attr
->get_ref_die_offset ();
22385 struct dwarf2_cu
*cu
= *ref_cu
;
22386 struct die_info
*die
;
22388 die
= follow_die_offset (sect_off
,
22389 (attr
->form
== DW_FORM_GNU_ref_alt
22390 || cu
->per_cu
->is_dwz
),
22393 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22394 "at %s [in module %s]"),
22395 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22396 objfile_name (cu
->per_objfile
->objfile
));
22403 struct dwarf2_locexpr_baton
22404 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22405 dwarf2_per_cu_data
*per_cu
,
22406 dwarf2_per_objfile
*per_objfile
,
22407 CORE_ADDR (*get_frame_pc
) (void *baton
),
22408 void *baton
, bool resolve_abstract_p
)
22410 struct die_info
*die
;
22411 struct attribute
*attr
;
22412 struct dwarf2_locexpr_baton retval
;
22413 struct objfile
*objfile
= per_objfile
->objfile
;
22415 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22417 cu
= load_cu (per_cu
, per_objfile
, false);
22421 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22422 Instead just throw an error, not much else we can do. */
22423 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22424 sect_offset_str (sect_off
), objfile_name (objfile
));
22427 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22429 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22430 sect_offset_str (sect_off
), objfile_name (objfile
));
22432 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22433 if (!attr
&& resolve_abstract_p
22434 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22435 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22437 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22438 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22439 struct gdbarch
*gdbarch
= objfile
->arch ();
22441 for (const auto &cand_off
22442 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22444 struct dwarf2_cu
*cand_cu
= cu
;
22445 struct die_info
*cand
22446 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22449 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22452 CORE_ADDR pc_low
, pc_high
;
22453 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22454 if (pc_low
== ((CORE_ADDR
) -1))
22456 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22457 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22458 if (!(pc_low
<= pc
&& pc
< pc_high
))
22462 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22469 /* DWARF: "If there is no such attribute, then there is no effect.".
22470 DATA is ignored if SIZE is 0. */
22472 retval
.data
= NULL
;
22475 else if (attr
->form_is_section_offset ())
22477 struct dwarf2_loclist_baton loclist_baton
;
22478 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22481 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22483 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22485 retval
.size
= size
;
22489 if (!attr
->form_is_block ())
22490 error (_("Dwarf Error: DIE at %s referenced in module %s "
22491 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22492 sect_offset_str (sect_off
), objfile_name (objfile
));
22494 retval
.data
= DW_BLOCK (attr
)->data
;
22495 retval
.size
= DW_BLOCK (attr
)->size
;
22497 retval
.per_objfile
= per_objfile
;
22498 retval
.per_cu
= cu
->per_cu
;
22500 per_objfile
->age_comp_units ();
22507 struct dwarf2_locexpr_baton
22508 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22509 dwarf2_per_cu_data
*per_cu
,
22510 dwarf2_per_objfile
*per_objfile
,
22511 CORE_ADDR (*get_frame_pc
) (void *baton
),
22514 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22516 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22517 get_frame_pc
, baton
);
22520 /* Write a constant of a given type as target-ordered bytes into
22523 static const gdb_byte
*
22524 write_constant_as_bytes (struct obstack
*obstack
,
22525 enum bfd_endian byte_order
,
22532 *len
= TYPE_LENGTH (type
);
22533 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22534 store_unsigned_integer (result
, *len
, byte_order
, value
);
22542 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22543 dwarf2_per_cu_data
*per_cu
,
22544 dwarf2_per_objfile
*per_objfile
,
22548 struct die_info
*die
;
22549 struct attribute
*attr
;
22550 const gdb_byte
*result
= NULL
;
22553 enum bfd_endian byte_order
;
22554 struct objfile
*objfile
= per_objfile
->objfile
;
22556 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22558 cu
= load_cu (per_cu
, per_objfile
, false);
22562 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22563 Instead just throw an error, not much else we can do. */
22564 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22565 sect_offset_str (sect_off
), objfile_name (objfile
));
22568 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22570 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22571 sect_offset_str (sect_off
), objfile_name (objfile
));
22573 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22577 byte_order
= (bfd_big_endian (objfile
->obfd
)
22578 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22580 switch (attr
->form
)
22583 case DW_FORM_addrx
:
22584 case DW_FORM_GNU_addr_index
:
22588 *len
= cu
->header
.addr_size
;
22589 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22590 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22594 case DW_FORM_string
:
22597 case DW_FORM_GNU_str_index
:
22598 case DW_FORM_GNU_strp_alt
:
22599 /* DW_STRING is already allocated on the objfile obstack, point
22601 result
= (const gdb_byte
*) DW_STRING (attr
);
22602 *len
= strlen (DW_STRING (attr
));
22604 case DW_FORM_block1
:
22605 case DW_FORM_block2
:
22606 case DW_FORM_block4
:
22607 case DW_FORM_block
:
22608 case DW_FORM_exprloc
:
22609 case DW_FORM_data16
:
22610 result
= DW_BLOCK (attr
)->data
;
22611 *len
= DW_BLOCK (attr
)->size
;
22614 /* The DW_AT_const_value attributes are supposed to carry the
22615 symbol's value "represented as it would be on the target
22616 architecture." By the time we get here, it's already been
22617 converted to host endianness, so we just need to sign- or
22618 zero-extend it as appropriate. */
22619 case DW_FORM_data1
:
22620 type
= die_type (die
, cu
);
22621 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22622 if (result
== NULL
)
22623 result
= write_constant_as_bytes (obstack
, byte_order
,
22626 case DW_FORM_data2
:
22627 type
= die_type (die
, cu
);
22628 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22629 if (result
== NULL
)
22630 result
= write_constant_as_bytes (obstack
, byte_order
,
22633 case DW_FORM_data4
:
22634 type
= die_type (die
, cu
);
22635 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22636 if (result
== NULL
)
22637 result
= write_constant_as_bytes (obstack
, byte_order
,
22640 case DW_FORM_data8
:
22641 type
= die_type (die
, cu
);
22642 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22643 if (result
== NULL
)
22644 result
= write_constant_as_bytes (obstack
, byte_order
,
22648 case DW_FORM_sdata
:
22649 case DW_FORM_implicit_const
:
22650 type
= die_type (die
, cu
);
22651 result
= write_constant_as_bytes (obstack
, byte_order
,
22652 type
, DW_SND (attr
), len
);
22655 case DW_FORM_udata
:
22656 type
= die_type (die
, cu
);
22657 result
= write_constant_as_bytes (obstack
, byte_order
,
22658 type
, DW_UNSND (attr
), len
);
22662 complaint (_("unsupported const value attribute form: '%s'"),
22663 dwarf_form_name (attr
->form
));
22673 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22674 dwarf2_per_cu_data
*per_cu
,
22675 dwarf2_per_objfile
*per_objfile
)
22677 struct die_info
*die
;
22679 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22681 cu
= load_cu (per_cu
, per_objfile
, false);
22686 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22690 return die_type (die
, cu
);
22696 dwarf2_get_die_type (cu_offset die_offset
,
22697 dwarf2_per_cu_data
*per_cu
,
22698 dwarf2_per_objfile
*per_objfile
)
22700 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22701 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
22704 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22705 On entry *REF_CU is the CU of SRC_DIE.
22706 On exit *REF_CU is the CU of the result.
22707 Returns NULL if the referenced DIE isn't found. */
22709 static struct die_info
*
22710 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22711 struct dwarf2_cu
**ref_cu
)
22713 struct die_info temp_die
;
22714 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22715 struct die_info
*die
;
22716 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
22719 /* While it might be nice to assert sig_type->type == NULL here,
22720 we can get here for DW_AT_imported_declaration where we need
22721 the DIE not the type. */
22723 /* If necessary, add it to the queue and load its DIEs. */
22725 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
22727 read_signatured_type (sig_type
, per_objfile
);
22729 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
22730 gdb_assert (sig_cu
!= NULL
);
22731 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22732 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22733 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22734 to_underlying (temp_die
.sect_off
));
22737 /* For .gdb_index version 7 keep track of included TUs.
22738 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22739 if (per_objfile
->per_bfd
->index_table
!= NULL
22740 && per_objfile
->per_bfd
->index_table
->version
<= 7)
22742 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22747 sig_cu
->ancestor
= cu
;
22755 /* Follow signatured type referenced by ATTR in SRC_DIE.
22756 On entry *REF_CU is the CU of SRC_DIE.
22757 On exit *REF_CU is the CU of the result.
22758 The result is the DIE of the type.
22759 If the referenced type cannot be found an error is thrown. */
22761 static struct die_info
*
22762 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22763 struct dwarf2_cu
**ref_cu
)
22765 ULONGEST signature
= DW_SIGNATURE (attr
);
22766 struct signatured_type
*sig_type
;
22767 struct die_info
*die
;
22769 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22771 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22772 /* sig_type will be NULL if the signatured type is missing from
22774 if (sig_type
== NULL
)
22776 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22777 " from DIE at %s [in module %s]"),
22778 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22779 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22782 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22785 dump_die_for_error (src_die
);
22786 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22787 " from DIE at %s [in module %s]"),
22788 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22789 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22795 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22796 reading in and processing the type unit if necessary. */
22798 static struct type
*
22799 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22800 struct dwarf2_cu
*cu
)
22802 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22803 struct signatured_type
*sig_type
;
22804 struct dwarf2_cu
*type_cu
;
22805 struct die_info
*type_die
;
22808 sig_type
= lookup_signatured_type (cu
, signature
);
22809 /* sig_type will be NULL if the signatured type is missing from
22811 if (sig_type
== NULL
)
22813 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22814 " from DIE at %s [in module %s]"),
22815 hex_string (signature
), sect_offset_str (die
->sect_off
),
22816 objfile_name (per_objfile
->objfile
));
22817 return build_error_marker_type (cu
, die
);
22820 /* If we already know the type we're done. */
22821 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
22822 if (type
!= nullptr)
22826 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22827 if (type_die
!= NULL
)
22829 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22830 is created. This is important, for example, because for c++ classes
22831 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22832 type
= read_type_die (type_die
, type_cu
);
22835 complaint (_("Dwarf Error: Cannot build signatured type %s"
22836 " referenced from DIE at %s [in module %s]"),
22837 hex_string (signature
), sect_offset_str (die
->sect_off
),
22838 objfile_name (per_objfile
->objfile
));
22839 type
= build_error_marker_type (cu
, die
);
22844 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22845 " from DIE at %s [in module %s]"),
22846 hex_string (signature
), sect_offset_str (die
->sect_off
),
22847 objfile_name (per_objfile
->objfile
));
22848 type
= build_error_marker_type (cu
, die
);
22851 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
22856 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22857 reading in and processing the type unit if necessary. */
22859 static struct type
*
22860 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22861 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22863 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22864 if (attr
->form_is_ref ())
22866 struct dwarf2_cu
*type_cu
= cu
;
22867 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22869 return read_type_die (type_die
, type_cu
);
22871 else if (attr
->form
== DW_FORM_ref_sig8
)
22873 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22877 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22879 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22880 " at %s [in module %s]"),
22881 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22882 objfile_name (per_objfile
->objfile
));
22883 return build_error_marker_type (cu
, die
);
22887 /* Load the DIEs associated with type unit PER_CU into memory. */
22890 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22891 dwarf2_per_objfile
*per_objfile
)
22893 struct signatured_type
*sig_type
;
22895 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22896 gdb_assert (! per_cu
->type_unit_group_p ());
22898 /* We have the per_cu, but we need the signatured_type.
22899 Fortunately this is an easy translation. */
22900 gdb_assert (per_cu
->is_debug_types
);
22901 sig_type
= (struct signatured_type
*) per_cu
;
22903 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22905 read_signatured_type (sig_type
, per_objfile
);
22907 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
22910 /* Read in a signatured type and build its CU and DIEs.
22911 If the type is a stub for the real type in a DWO file,
22912 read in the real type from the DWO file as well. */
22915 read_signatured_type (signatured_type
*sig_type
,
22916 dwarf2_per_objfile
*per_objfile
)
22918 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22920 gdb_assert (per_cu
->is_debug_types
);
22921 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22923 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
22925 if (!reader
.dummy_p
)
22927 struct dwarf2_cu
*cu
= reader
.cu
;
22928 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22930 gdb_assert (cu
->die_hash
== NULL
);
22932 htab_create_alloc_ex (cu
->header
.length
/ 12,
22936 &cu
->comp_unit_obstack
,
22937 hashtab_obstack_allocate
,
22938 dummy_obstack_deallocate
);
22940 if (reader
.comp_unit_die
->has_children
)
22941 reader
.comp_unit_die
->child
22942 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22943 reader
.comp_unit_die
);
22944 cu
->dies
= reader
.comp_unit_die
;
22945 /* comp_unit_die is not stored in die_hash, no need. */
22947 /* We try not to read any attributes in this function, because
22948 not all CUs needed for references have been loaded yet, and
22949 symbol table processing isn't initialized. But we have to
22950 set the CU language, or we won't be able to build types
22951 correctly. Similarly, if we do not read the producer, we can
22952 not apply producer-specific interpretation. */
22953 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22958 sig_type
->per_cu
.tu_read
= 1;
22961 /* Decode simple location descriptions.
22962 Given a pointer to a dwarf block that defines a location, compute
22963 the location and return the value. If COMPUTED is non-null, it is
22964 set to true to indicate that decoding was successful, and false
22965 otherwise. If COMPUTED is null, then this function may emit a
22969 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22971 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22973 size_t size
= blk
->size
;
22974 const gdb_byte
*data
= blk
->data
;
22975 CORE_ADDR stack
[64];
22977 unsigned int bytes_read
, unsnd
;
22980 if (computed
!= nullptr)
22986 stack
[++stacki
] = 0;
23025 stack
[++stacki
] = op
- DW_OP_lit0
;
23060 stack
[++stacki
] = op
- DW_OP_reg0
;
23063 if (computed
== nullptr)
23064 dwarf2_complex_location_expr_complaint ();
23071 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23073 stack
[++stacki
] = unsnd
;
23076 if (computed
== nullptr)
23077 dwarf2_complex_location_expr_complaint ();
23084 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23089 case DW_OP_const1u
:
23090 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23094 case DW_OP_const1s
:
23095 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23099 case DW_OP_const2u
:
23100 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23104 case DW_OP_const2s
:
23105 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23109 case DW_OP_const4u
:
23110 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23114 case DW_OP_const4s
:
23115 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23119 case DW_OP_const8u
:
23120 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23125 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23131 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23136 stack
[stacki
+ 1] = stack
[stacki
];
23141 stack
[stacki
- 1] += stack
[stacki
];
23145 case DW_OP_plus_uconst
:
23146 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23152 stack
[stacki
- 1] -= stack
[stacki
];
23157 /* If we're not the last op, then we definitely can't encode
23158 this using GDB's address_class enum. This is valid for partial
23159 global symbols, although the variable's address will be bogus
23163 if (computed
== nullptr)
23164 dwarf2_complex_location_expr_complaint ();
23170 case DW_OP_GNU_push_tls_address
:
23171 case DW_OP_form_tls_address
:
23172 /* The top of the stack has the offset from the beginning
23173 of the thread control block at which the variable is located. */
23174 /* Nothing should follow this operator, so the top of stack would
23176 /* This is valid for partial global symbols, but the variable's
23177 address will be bogus in the psymtab. Make it always at least
23178 non-zero to not look as a variable garbage collected by linker
23179 which have DW_OP_addr 0. */
23182 if (computed
== nullptr)
23183 dwarf2_complex_location_expr_complaint ();
23190 case DW_OP_GNU_uninit
:
23191 if (computed
!= nullptr)
23196 case DW_OP_GNU_addr_index
:
23197 case DW_OP_GNU_const_index
:
23198 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23204 if (computed
== nullptr)
23206 const char *name
= get_DW_OP_name (op
);
23209 complaint (_("unsupported stack op: '%s'"),
23212 complaint (_("unsupported stack op: '%02x'"),
23216 return (stack
[stacki
]);
23219 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23220 outside of the allocated space. Also enforce minimum>0. */
23221 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23223 if (computed
== nullptr)
23224 complaint (_("location description stack overflow"));
23230 if (computed
== nullptr)
23231 complaint (_("location description stack underflow"));
23236 if (computed
!= nullptr)
23238 return (stack
[stacki
]);
23241 /* memory allocation interface */
23243 static struct dwarf_block
*
23244 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23246 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23249 static struct die_info
*
23250 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23252 struct die_info
*die
;
23253 size_t size
= sizeof (struct die_info
);
23256 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23258 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23259 memset (die
, 0, sizeof (struct die_info
));
23265 /* Macro support. */
23267 /* An overload of dwarf_decode_macros that finds the correct section
23268 and ensures it is read in before calling the other overload. */
23271 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23272 int section_is_gnu
)
23274 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23275 struct objfile
*objfile
= per_objfile
->objfile
;
23276 const struct line_header
*lh
= cu
->line_header
;
23277 unsigned int offset_size
= cu
->header
.offset_size
;
23278 struct dwarf2_section_info
*section
;
23279 const char *section_name
;
23281 if (cu
->dwo_unit
!= nullptr)
23283 if (section_is_gnu
)
23285 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23286 section_name
= ".debug_macro.dwo";
23290 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23291 section_name
= ".debug_macinfo.dwo";
23296 if (section_is_gnu
)
23298 section
= &per_objfile
->per_bfd
->macro
;
23299 section_name
= ".debug_macro";
23303 section
= &per_objfile
->per_bfd
->macinfo
;
23304 section_name
= ".debug_macinfo";
23308 section
->read (objfile
);
23309 if (section
->buffer
== nullptr)
23311 complaint (_("missing %s section"), section_name
);
23315 buildsym_compunit
*builder
= cu
->get_builder ();
23317 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
23318 offset_size
, offset
, section_is_gnu
);
23321 /* Return the .debug_loc section to use for CU.
23322 For DWO files use .debug_loc.dwo. */
23324 static struct dwarf2_section_info
*
23325 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23327 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23331 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23333 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23335 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
23336 : &per_objfile
->per_bfd
->loc
);
23339 /* A helper function that fills in a dwarf2_loclist_baton. */
23342 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23343 struct dwarf2_loclist_baton
*baton
,
23344 const struct attribute
*attr
)
23346 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23347 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23349 section
->read (per_objfile
->objfile
);
23351 baton
->per_objfile
= per_objfile
;
23352 baton
->per_cu
= cu
->per_cu
;
23353 gdb_assert (baton
->per_cu
);
23354 /* We don't know how long the location list is, but make sure we
23355 don't run off the edge of the section. */
23356 baton
->size
= section
->size
- DW_UNSND (attr
);
23357 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23358 if (cu
->base_address
.has_value ())
23359 baton
->base_address
= *cu
->base_address
;
23361 baton
->base_address
= 0;
23362 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23366 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23367 struct dwarf2_cu
*cu
, int is_block
)
23369 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23370 struct objfile
*objfile
= per_objfile
->objfile
;
23371 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23373 if (attr
->form_is_section_offset ()
23374 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23375 the section. If so, fall through to the complaint in the
23377 && DW_UNSND (attr
) < section
->get_size (objfile
))
23379 struct dwarf2_loclist_baton
*baton
;
23381 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23383 fill_in_loclist_baton (cu
, baton
, attr
);
23385 if (!cu
->base_address
.has_value ())
23386 complaint (_("Location list used without "
23387 "specifying the CU base address."));
23389 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23390 ? dwarf2_loclist_block_index
23391 : dwarf2_loclist_index
);
23392 SYMBOL_LOCATION_BATON (sym
) = baton
;
23396 struct dwarf2_locexpr_baton
*baton
;
23398 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23399 baton
->per_objfile
= per_objfile
;
23400 baton
->per_cu
= cu
->per_cu
;
23401 gdb_assert (baton
->per_cu
);
23403 if (attr
->form_is_block ())
23405 /* Note that we're just copying the block's data pointer
23406 here, not the actual data. We're still pointing into the
23407 info_buffer for SYM's objfile; right now we never release
23408 that buffer, but when we do clean up properly this may
23410 baton
->size
= DW_BLOCK (attr
)->size
;
23411 baton
->data
= DW_BLOCK (attr
)->data
;
23415 dwarf2_invalid_attrib_class_complaint ("location description",
23416 sym
->natural_name ());
23420 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23421 ? dwarf2_locexpr_block_index
23422 : dwarf2_locexpr_index
);
23423 SYMBOL_LOCATION_BATON (sym
) = baton
;
23429 const comp_unit_head
*
23430 dwarf2_per_cu_data::get_header () const
23432 if (!m_header_read_in
)
23434 const gdb_byte
*info_ptr
23435 = this->section
->buffer
+ to_underlying (this->sect_off
);
23437 memset (&m_header
, 0, sizeof (m_header
));
23439 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
23440 rcuh_kind::COMPILE
);
23449 dwarf2_per_cu_data::addr_size () const
23451 return this->get_header ()->addr_size
;
23457 dwarf2_per_cu_data::offset_size () const
23459 return this->get_header ()->offset_size
;
23465 dwarf2_per_cu_data::ref_addr_size () const
23467 const comp_unit_head
*header
= this->get_header ();
23469 if (header
->version
== 2)
23470 return header
->addr_size
;
23472 return header
->offset_size
;
23478 dwarf2_cu::addr_type () const
23480 struct objfile
*objfile
= this->per_objfile
->objfile
;
23481 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23482 struct type
*addr_type
= lookup_pointer_type (void_type
);
23483 int addr_size
= this->per_cu
->addr_size ();
23485 if (TYPE_LENGTH (addr_type
) == addr_size
)
23488 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23492 /* A helper function for dwarf2_find_containing_comp_unit that returns
23493 the index of the result, and that searches a vector. It will
23494 return a result even if the offset in question does not actually
23495 occur in any CU. This is separate so that it can be unit
23499 dwarf2_find_containing_comp_unit
23500 (sect_offset sect_off
,
23501 unsigned int offset_in_dwz
,
23502 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23507 high
= all_comp_units
.size () - 1;
23510 struct dwarf2_per_cu_data
*mid_cu
;
23511 int mid
= low
+ (high
- low
) / 2;
23513 mid_cu
= all_comp_units
[mid
];
23514 if (mid_cu
->is_dwz
> offset_in_dwz
23515 || (mid_cu
->is_dwz
== offset_in_dwz
23516 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23521 gdb_assert (low
== high
);
23525 /* Locate the .debug_info compilation unit from CU's objfile which contains
23526 the DIE at OFFSET. Raises an error on failure. */
23528 static struct dwarf2_per_cu_data
*
23529 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23530 unsigned int offset_in_dwz
,
23531 dwarf2_per_objfile
*per_objfile
)
23533 int low
= dwarf2_find_containing_comp_unit
23534 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
23535 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
23537 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23539 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23540 error (_("Dwarf Error: could not find partial DIE containing "
23541 "offset %s [in module %s]"),
23542 sect_offset_str (sect_off
),
23543 bfd_get_filename (per_objfile
->objfile
->obfd
));
23545 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23547 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
23551 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
23552 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23553 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23554 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23561 namespace selftests
{
23562 namespace find_containing_comp_unit
{
23567 struct dwarf2_per_cu_data one
{};
23568 struct dwarf2_per_cu_data two
{};
23569 struct dwarf2_per_cu_data three
{};
23570 struct dwarf2_per_cu_data four
{};
23573 two
.sect_off
= sect_offset (one
.length
);
23578 four
.sect_off
= sect_offset (three
.length
);
23582 std::vector
<dwarf2_per_cu_data
*> units
;
23583 units
.push_back (&one
);
23584 units
.push_back (&two
);
23585 units
.push_back (&three
);
23586 units
.push_back (&four
);
23590 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23591 SELF_CHECK (units
[result
] == &one
);
23592 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23593 SELF_CHECK (units
[result
] == &one
);
23594 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23595 SELF_CHECK (units
[result
] == &two
);
23597 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23598 SELF_CHECK (units
[result
] == &three
);
23599 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23600 SELF_CHECK (units
[result
] == &three
);
23601 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23602 SELF_CHECK (units
[result
] == &four
);
23608 #endif /* GDB_SELF_TEST */
23610 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23612 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23613 dwarf2_per_objfile
*per_objfile
)
23615 per_objfile (per_objfile
),
23617 has_loclist (false),
23618 checked_producer (false),
23619 producer_is_gxx_lt_4_6 (false),
23620 producer_is_gcc_lt_4_3 (false),
23621 producer_is_icc (false),
23622 producer_is_icc_lt_14 (false),
23623 producer_is_codewarrior (false),
23624 processing_has_namespace_info (false)
23628 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23631 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23632 enum language pretend_language
)
23634 struct attribute
*attr
;
23636 /* Set the language we're debugging. */
23637 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23638 if (attr
!= nullptr)
23639 set_cu_language (DW_UNSND (attr
), cu
);
23642 cu
->language
= pretend_language
;
23643 cu
->language_defn
= language_def (cu
->language
);
23646 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23652 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
23654 auto it
= m_dwarf2_cus
.find (per_cu
);
23655 if (it
== m_dwarf2_cus
.end ())
23664 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
23666 gdb_assert (this->get_cu (per_cu
) == nullptr);
23668 m_dwarf2_cus
[per_cu
] = cu
;
23674 dwarf2_per_objfile::age_comp_units ()
23676 /* Start by clearing all marks. */
23677 for (auto pair
: m_dwarf2_cus
)
23678 pair
.second
->mark
= false;
23680 /* Traverse all CUs, mark them and their dependencies if used recently
23682 for (auto pair
: m_dwarf2_cus
)
23684 dwarf2_cu
*cu
= pair
.second
;
23687 if (cu
->last_used
<= dwarf_max_cache_age
)
23691 /* Delete all CUs still not marked. */
23692 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
23694 dwarf2_cu
*cu
= it
->second
;
23699 it
= m_dwarf2_cus
.erase (it
);
23709 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
23711 auto it
= m_dwarf2_cus
.find (per_cu
);
23712 if (it
== m_dwarf2_cus
.end ())
23717 m_dwarf2_cus
.erase (it
);
23720 dwarf2_per_objfile::~dwarf2_per_objfile ()
23725 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23726 We store these in a hash table separate from the DIEs, and preserve them
23727 when the DIEs are flushed out of cache.
23729 The CU "per_cu" pointer is needed because offset alone is not enough to
23730 uniquely identify the type. A file may have multiple .debug_types sections,
23731 or the type may come from a DWO file. Furthermore, while it's more logical
23732 to use per_cu->section+offset, with Fission the section with the data is in
23733 the DWO file but we don't know that section at the point we need it.
23734 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23735 because we can enter the lookup routine, get_die_type_at_offset, from
23736 outside this file, and thus won't necessarily have PER_CU->cu.
23737 Fortunately, PER_CU is stable for the life of the objfile. */
23739 struct dwarf2_per_cu_offset_and_type
23741 const struct dwarf2_per_cu_data
*per_cu
;
23742 sect_offset sect_off
;
23746 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23749 per_cu_offset_and_type_hash (const void *item
)
23751 const struct dwarf2_per_cu_offset_and_type
*ofs
23752 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23754 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23757 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23760 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23762 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23763 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23764 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23765 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23767 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23768 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23771 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23772 table if necessary. For convenience, return TYPE.
23774 The DIEs reading must have careful ordering to:
23775 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23776 reading current DIE.
23777 * Not trying to dereference contents of still incompletely read in types
23778 while reading in other DIEs.
23779 * Enable referencing still incompletely read in types just by a pointer to
23780 the type without accessing its fields.
23782 Therefore caller should follow these rules:
23783 * Try to fetch any prerequisite types we may need to build this DIE type
23784 before building the type and calling set_die_type.
23785 * After building type call set_die_type for current DIE as soon as
23786 possible before fetching more types to complete the current type.
23787 * Make the type as complete as possible before fetching more types. */
23789 static struct type
*
23790 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23792 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23793 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23794 struct objfile
*objfile
= per_objfile
->objfile
;
23795 struct attribute
*attr
;
23796 struct dynamic_prop prop
;
23798 /* For Ada types, make sure that the gnat-specific data is always
23799 initialized (if not already set). There are a few types where
23800 we should not be doing so, because the type-specific area is
23801 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23802 where the type-specific area is used to store the floatformat).
23803 But this is not a problem, because the gnat-specific information
23804 is actually not needed for these types. */
23805 if (need_gnat_info (cu
)
23806 && type
->code () != TYPE_CODE_FUNC
23807 && type
->code () != TYPE_CODE_FLT
23808 && type
->code () != TYPE_CODE_METHODPTR
23809 && type
->code () != TYPE_CODE_MEMBERPTR
23810 && type
->code () != TYPE_CODE_METHOD
23811 && !HAVE_GNAT_AUX_INFO (type
))
23812 INIT_GNAT_SPECIFIC (type
);
23814 /* Read DW_AT_allocated and set in type. */
23815 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23816 if (attr
!= NULL
&& attr
->form_is_block ())
23818 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23819 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23820 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23822 else if (attr
!= NULL
)
23824 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23825 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23826 sect_offset_str (die
->sect_off
));
23829 /* Read DW_AT_associated and set in type. */
23830 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23831 if (attr
!= NULL
&& attr
->form_is_block ())
23833 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23834 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23835 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23837 else if (attr
!= NULL
)
23839 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23840 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23841 sect_offset_str (die
->sect_off
));
23844 /* Read DW_AT_data_location and set in type. */
23845 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23846 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23847 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23849 if (per_objfile
->die_type_hash
== NULL
)
23850 per_objfile
->die_type_hash
23851 = htab_up (htab_create_alloc (127,
23852 per_cu_offset_and_type_hash
,
23853 per_cu_offset_and_type_eq
,
23854 NULL
, xcalloc
, xfree
));
23856 ofs
.per_cu
= cu
->per_cu
;
23857 ofs
.sect_off
= die
->sect_off
;
23859 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23860 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23862 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23863 sect_offset_str (die
->sect_off
));
23864 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23865 struct dwarf2_per_cu_offset_and_type
);
23870 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23871 or return NULL if the die does not have a saved type. */
23873 static struct type
*
23874 get_die_type_at_offset (sect_offset sect_off
,
23875 dwarf2_per_cu_data
*per_cu
,
23876 dwarf2_per_objfile
*per_objfile
)
23878 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23880 if (per_objfile
->die_type_hash
== NULL
)
23883 ofs
.per_cu
= per_cu
;
23884 ofs
.sect_off
= sect_off
;
23885 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23886 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
23893 /* Look up the type for DIE in CU in die_type_hash,
23894 or return NULL if DIE does not have a saved type. */
23896 static struct type
*
23897 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23899 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
23902 /* Add a dependence relationship from CU to REF_PER_CU. */
23905 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23906 struct dwarf2_per_cu_data
*ref_per_cu
)
23910 if (cu
->dependencies
== NULL
)
23912 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23913 NULL
, &cu
->comp_unit_obstack
,
23914 hashtab_obstack_allocate
,
23915 dummy_obstack_deallocate
);
23917 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23919 *slot
= ref_per_cu
;
23922 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23923 Set the mark field in every compilation unit in the
23924 cache that we must keep because we are keeping CU.
23926 DATA is the dwarf2_per_objfile object in which to look up CUs. */
23929 dwarf2_mark_helper (void **slot
, void *data
)
23931 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
23932 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
23933 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23935 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23936 reading of the chain. As such dependencies remain valid it is not much
23937 useful to track and undo them during QUIT cleanups. */
23946 if (cu
->dependencies
!= nullptr)
23947 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
23952 /* Set the mark field in CU and in every other compilation unit in the
23953 cache that we must keep because we are keeping CU. */
23956 dwarf2_mark (struct dwarf2_cu
*cu
)
23963 if (cu
->dependencies
!= nullptr)
23964 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
23967 /* Trivial hash function for partial_die_info: the hash value of a DIE
23968 is its offset in .debug_info for this objfile. */
23971 partial_die_hash (const void *item
)
23973 const struct partial_die_info
*part_die
23974 = (const struct partial_die_info
*) item
;
23976 return to_underlying (part_die
->sect_off
);
23979 /* Trivial comparison function for partial_die_info structures: two DIEs
23980 are equal if they have the same offset. */
23983 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23985 const struct partial_die_info
*part_die_lhs
23986 = (const struct partial_die_info
*) item_lhs
;
23987 const struct partial_die_info
*part_die_rhs
23988 = (const struct partial_die_info
*) item_rhs
;
23990 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23993 struct cmd_list_element
*set_dwarf_cmdlist
;
23994 struct cmd_list_element
*show_dwarf_cmdlist
;
23997 show_check_physname (struct ui_file
*file
, int from_tty
,
23998 struct cmd_list_element
*c
, const char *value
)
24000 fprintf_filtered (file
,
24001 _("Whether to check \"physname\" is %s.\n"),
24005 void _initialize_dwarf2_read ();
24007 _initialize_dwarf2_read ()
24009 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24010 Set DWARF specific variables.\n\
24011 Configure DWARF variables such as the cache size."),
24012 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24013 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24015 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24016 Show DWARF specific variables.\n\
24017 Show DWARF variables such as the cache size."),
24018 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24019 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24021 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24022 &dwarf_max_cache_age
, _("\
24023 Set the upper bound on the age of cached DWARF compilation units."), _("\
24024 Show the upper bound on the age of cached DWARF compilation units."), _("\
24025 A higher limit means that cached compilation units will be stored\n\
24026 in memory longer, and more total memory will be used. Zero disables\n\
24027 caching, which can slow down startup."),
24029 show_dwarf_max_cache_age
,
24030 &set_dwarf_cmdlist
,
24031 &show_dwarf_cmdlist
);
24033 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24034 Set debugging of the DWARF reader."), _("\
24035 Show debugging of the DWARF reader."), _("\
24036 When enabled (non-zero), debugging messages are printed during DWARF\n\
24037 reading and symtab expansion. A value of 1 (one) provides basic\n\
24038 information. A value greater than 1 provides more verbose information."),
24041 &setdebuglist
, &showdebuglist
);
24043 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24044 Set debugging of the DWARF DIE reader."), _("\
24045 Show debugging of the DWARF DIE reader."), _("\
24046 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24047 The value is the maximum depth to print."),
24050 &setdebuglist
, &showdebuglist
);
24052 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24053 Set debugging of the dwarf line reader."), _("\
24054 Show debugging of the dwarf line reader."), _("\
24055 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24056 A value of 1 (one) provides basic information.\n\
24057 A value greater than 1 provides more verbose information."),
24060 &setdebuglist
, &showdebuglist
);
24062 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24063 Set cross-checking of \"physname\" code against demangler."), _("\
24064 Show cross-checking of \"physname\" code against demangler."), _("\
24065 When enabled, GDB's internal \"physname\" code is checked against\n\
24067 NULL
, show_check_physname
,
24068 &setdebuglist
, &showdebuglist
);
24070 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24071 no_class
, &use_deprecated_index_sections
, _("\
24072 Set whether to use deprecated gdb_index sections."), _("\
24073 Show whether to use deprecated gdb_index sections."), _("\
24074 When enabled, deprecated .gdb_index sections are used anyway.\n\
24075 Normally they are ignored either because of a missing feature or\n\
24076 performance issue.\n\
24077 Warning: This option must be enabled before gdb reads the file."),
24080 &setlist
, &showlist
);
24082 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24083 &dwarf2_locexpr_funcs
);
24084 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24085 &dwarf2_loclist_funcs
);
24087 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24088 &dwarf2_block_frame_base_locexpr_funcs
);
24089 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24090 &dwarf2_block_frame_base_loclist_funcs
);
24093 selftests::register_test ("dw2_expand_symtabs_matching",
24094 selftests::dw2_expand_symtabs_matching::run_test
);
24095 selftests::register_test ("dwarf2_find_containing_comp_unit",
24096 selftests::find_containing_comp_unit::run_test
);