1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
43 #include "dwarf2/stringify.h"
52 #include "gdb-demangle.h"
53 #include "filenames.h" /* for DOSish file names */
55 #include "complaints.h"
56 #include "dwarf2/expr.h"
57 #include "dwarf2/loc.h"
58 #include "cp-support.h"
64 #include "typeprint.h"
69 #include "gdbcore.h" /* for gnutarget */
70 #include "gdb/gdb-index.h"
75 #include "namespace.h"
76 #include "gdbsupport/function-view.h"
77 #include "gdbsupport/gdb_optional.h"
78 #include "gdbsupport/underlying.h"
79 #include "gdbsupport/hash_enum.h"
80 #include "filename-seen-cache.h"
84 #include <unordered_map>
85 #include "gdbsupport/selftest.h"
86 #include "rust-lang.h"
87 #include "gdbsupport/pathstuff.h"
88 #include "count-one-bits.h"
89 #include "debuginfod-support.h"
91 /* When == 1, print basic high level tracing messages.
92 When > 1, be more verbose.
93 This is in contrast to the low level DIE reading of dwarf_die_debug. */
94 static unsigned int dwarf_read_debug
= 0;
96 /* When non-zero, dump DIEs after they are read in. */
97 static unsigned int dwarf_die_debug
= 0;
99 /* When non-zero, dump line number entries as they are read in. */
100 unsigned int dwarf_line_debug
= 0;
102 /* When true, cross-check physname against demangler. */
103 static bool check_physname
= false;
105 /* When true, do not reject deprecated .gdb_index sections. */
106 static bool use_deprecated_index_sections
= false;
108 /* This is used to store the data that is always per objfile. */
109 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
111 /* These are used to store the dwarf2_per_bfd objects.
113 objfiles having the same BFD, which doesn't require relocations, are going to
114 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
116 Other objfiles are not going to share a dwarf2_per_bfd with any other
117 objfiles, so they'll have their own version kept in the _objfile_data_key
119 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
120 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
122 /* The "aclass" indices for various kinds of computed DWARF symbols. */
124 static int dwarf2_locexpr_index
;
125 static int dwarf2_loclist_index
;
126 static int dwarf2_locexpr_block_index
;
127 static int dwarf2_loclist_block_index
;
129 /* Size of .debug_loclists section header for 32-bit DWARF format. */
130 #define LOCLIST_HEADER_SIZE32 12
132 /* Size of .debug_loclists section header for 64-bit DWARF format. */
133 #define LOCLIST_HEADER_SIZE64 20
135 /* An index into a (C++) symbol name component in a symbol name as
136 recorded in the mapped_index's symbol table. For each C++ symbol
137 in the symbol table, we record one entry for the start of each
138 component in the symbol in a table of name components, and then
139 sort the table, in order to be able to binary search symbol names,
140 ignoring leading namespaces, both completion and regular look up.
141 For example, for symbol "A::B::C", we'll have an entry that points
142 to "A::B::C", another that points to "B::C", and another for "C".
143 Note that function symbols in GDB index have no parameter
144 information, just the function/method names. You can convert a
145 name_component to a "const char *" using the
146 'mapped_index::symbol_name_at(offset_type)' method. */
148 struct name_component
150 /* Offset in the symbol name where the component starts. Stored as
151 a (32-bit) offset instead of a pointer to save memory and improve
152 locality on 64-bit architectures. */
153 offset_type name_offset
;
155 /* The symbol's index in the symbol and constant pool tables of a
160 /* Base class containing bits shared by both .gdb_index and
161 .debug_name indexes. */
163 struct mapped_index_base
165 mapped_index_base () = default;
166 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
168 /* The name_component table (a sorted vector). See name_component's
169 description above. */
170 std::vector
<name_component
> name_components
;
172 /* How NAME_COMPONENTS is sorted. */
173 enum case_sensitivity name_components_casing
;
175 /* Return the number of names in the symbol table. */
176 virtual size_t symbol_name_count () const = 0;
178 /* Get the name of the symbol at IDX in the symbol table. */
179 virtual const char *symbol_name_at
180 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
182 /* Return whether the name at IDX in the symbol table should be
184 virtual bool symbol_name_slot_invalid (offset_type idx
) const
189 /* Build the symbol name component sorted vector, if we haven't
191 void build_name_components (dwarf2_per_objfile
*per_objfile
);
193 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
194 possible matches for LN_NO_PARAMS in the name component
196 std::pair
<std::vector
<name_component
>::const_iterator
,
197 std::vector
<name_component
>::const_iterator
>
198 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
200 dwarf2_per_objfile
*per_objfile
) const;
202 /* Prevent deleting/destroying via a base class pointer. */
204 ~mapped_index_base() = default;
207 /* A description of the mapped index. The file format is described in
208 a comment by the code that writes the index. */
209 struct mapped_index final
: public mapped_index_base
211 /* A slot/bucket in the symbol table hash. */
212 struct symbol_table_slot
214 const offset_type name
;
215 const offset_type vec
;
218 /* Index data format version. */
221 /* The address table data. */
222 gdb::array_view
<const gdb_byte
> address_table
;
224 /* The symbol table, implemented as a hash table. */
225 gdb::array_view
<symbol_table_slot
> symbol_table
;
227 /* A pointer to the constant pool. */
228 const char *constant_pool
= nullptr;
230 bool symbol_name_slot_invalid (offset_type idx
) const override
232 const auto &bucket
= this->symbol_table
[idx
];
233 return bucket
.name
== 0 && bucket
.vec
== 0;
236 /* Convenience method to get at the name of the symbol at IDX in the
238 const char *symbol_name_at
239 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
240 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
242 size_t symbol_name_count () const override
243 { return this->symbol_table
.size (); }
246 /* A description of the mapped .debug_names.
247 Uninitialized map has CU_COUNT 0. */
248 struct mapped_debug_names final
: public mapped_index_base
250 bfd_endian dwarf5_byte_order
;
251 bool dwarf5_is_dwarf64
;
252 bool augmentation_is_gdb
;
254 uint32_t cu_count
= 0;
255 uint32_t tu_count
, bucket_count
, name_count
;
256 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
257 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
258 const gdb_byte
*name_table_string_offs_reordered
;
259 const gdb_byte
*name_table_entry_offs_reordered
;
260 const gdb_byte
*entry_pool
;
267 /* Attribute name DW_IDX_*. */
270 /* Attribute form DW_FORM_*. */
273 /* Value if FORM is DW_FORM_implicit_const. */
274 LONGEST implicit_const
;
276 std::vector
<attr
> attr_vec
;
279 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
281 const char *namei_to_name
282 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
284 /* Implementation of the mapped_index_base virtual interface, for
285 the name_components cache. */
287 const char *symbol_name_at
288 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
289 { return namei_to_name (idx
, per_objfile
); }
291 size_t symbol_name_count () const override
292 { return this->name_count
; }
295 /* See dwarf2read.h. */
298 get_dwarf2_per_objfile (struct objfile
*objfile
)
300 return dwarf2_objfile_data_key
.get (objfile
);
303 /* Default names of the debugging sections. */
305 /* Note that if the debugging section has been compressed, it might
306 have a name like .zdebug_info. */
308 static const struct dwarf2_debug_sections dwarf2_elf_names
=
310 { ".debug_info", ".zdebug_info" },
311 { ".debug_abbrev", ".zdebug_abbrev" },
312 { ".debug_line", ".zdebug_line" },
313 { ".debug_loc", ".zdebug_loc" },
314 { ".debug_loclists", ".zdebug_loclists" },
315 { ".debug_macinfo", ".zdebug_macinfo" },
316 { ".debug_macro", ".zdebug_macro" },
317 { ".debug_str", ".zdebug_str" },
318 { ".debug_str_offsets", ".zdebug_str_offsets" },
319 { ".debug_line_str", ".zdebug_line_str" },
320 { ".debug_ranges", ".zdebug_ranges" },
321 { ".debug_rnglists", ".zdebug_rnglists" },
322 { ".debug_types", ".zdebug_types" },
323 { ".debug_addr", ".zdebug_addr" },
324 { ".debug_frame", ".zdebug_frame" },
325 { ".eh_frame", NULL
},
326 { ".gdb_index", ".zgdb_index" },
327 { ".debug_names", ".zdebug_names" },
328 { ".debug_aranges", ".zdebug_aranges" },
332 /* List of DWO/DWP sections. */
334 static const struct dwop_section_names
336 struct dwarf2_section_names abbrev_dwo
;
337 struct dwarf2_section_names info_dwo
;
338 struct dwarf2_section_names line_dwo
;
339 struct dwarf2_section_names loc_dwo
;
340 struct dwarf2_section_names loclists_dwo
;
341 struct dwarf2_section_names macinfo_dwo
;
342 struct dwarf2_section_names macro_dwo
;
343 struct dwarf2_section_names str_dwo
;
344 struct dwarf2_section_names str_offsets_dwo
;
345 struct dwarf2_section_names types_dwo
;
346 struct dwarf2_section_names cu_index
;
347 struct dwarf2_section_names tu_index
;
351 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
352 { ".debug_info.dwo", ".zdebug_info.dwo" },
353 { ".debug_line.dwo", ".zdebug_line.dwo" },
354 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
355 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
356 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
357 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
358 { ".debug_str.dwo", ".zdebug_str.dwo" },
359 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
360 { ".debug_types.dwo", ".zdebug_types.dwo" },
361 { ".debug_cu_index", ".zdebug_cu_index" },
362 { ".debug_tu_index", ".zdebug_tu_index" },
365 /* local data types */
367 /* The location list section (.debug_loclists) begins with a header,
368 which contains the following information. */
369 struct loclist_header
371 /* A 4-byte or 12-byte length containing the length of the
372 set of entries for this compilation unit, not including the
373 length field itself. */
376 /* A 2-byte version identifier. */
379 /* A 1-byte unsigned integer containing the size in bytes of an address on
380 the target system. */
381 unsigned char addr_size
;
383 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
384 on the target system. */
385 unsigned char segment_collector_size
;
387 /* A 4-byte count of the number of offsets that follow the header. */
388 unsigned int offset_entry_count
;
391 /* Type used for delaying computation of method physnames.
392 See comments for compute_delayed_physnames. */
393 struct delayed_method_info
395 /* The type to which the method is attached, i.e., its parent class. */
398 /* The index of the method in the type's function fieldlists. */
401 /* The index of the method in the fieldlist. */
404 /* The name of the DIE. */
407 /* The DIE associated with this method. */
408 struct die_info
*die
;
411 /* Internal state when decoding a particular compilation unit. */
414 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
415 dwarf2_per_objfile
*per_objfile
);
417 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
419 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
420 Create the set of symtabs used by this TU, or if this TU is sharing
421 symtabs with another TU and the symtabs have already been created
422 then restore those symtabs in the line header.
423 We don't need the pc/line-number mapping for type units. */
424 void setup_type_unit_groups (struct die_info
*die
);
426 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
427 buildsym_compunit constructor. */
428 struct compunit_symtab
*start_symtab (const char *name
,
429 const char *comp_dir
,
432 /* Reset the builder. */
433 void reset_builder () { m_builder
.reset (); }
435 /* Return a type that is a generic pointer type, the size of which
436 matches the address size given in the compilation unit header for
438 struct type
*addr_type () const;
440 /* Find an integer type the same size as the address size given in
441 the compilation unit header for this CU. UNSIGNED_P controls if
442 the integer is unsigned or not. */
443 struct type
*addr_sized_int_type (bool unsigned_p
) const;
445 /* The header of the compilation unit. */
446 struct comp_unit_head header
{};
448 /* Base address of this compilation unit. */
449 gdb::optional
<CORE_ADDR
> base_address
;
451 /* The language we are debugging. */
452 enum language language
= language_unknown
;
453 const struct language_defn
*language_defn
= nullptr;
455 const char *producer
= nullptr;
458 /* The symtab builder for this CU. This is only non-NULL when full
459 symbols are being read. */
460 std::unique_ptr
<buildsym_compunit
> m_builder
;
463 /* The generic symbol table building routines have separate lists for
464 file scope symbols and all all other scopes (local scopes). So
465 we need to select the right one to pass to add_symbol_to_list().
466 We do it by keeping a pointer to the correct list in list_in_scope.
468 FIXME: The original dwarf code just treated the file scope as the
469 first local scope, and all other local scopes as nested local
470 scopes, and worked fine. Check to see if we really need to
471 distinguish these in buildsym.c. */
472 struct pending
**list_in_scope
= nullptr;
474 /* Hash table holding all the loaded partial DIEs
475 with partial_die->offset.SECT_OFF as hash. */
476 htab_t partial_dies
= nullptr;
478 /* Storage for things with the same lifetime as this read-in compilation
479 unit, including partial DIEs. */
480 auto_obstack comp_unit_obstack
;
482 /* Backlink to our per_cu entry. */
483 struct dwarf2_per_cu_data
*per_cu
;
485 /* The dwarf2_per_objfile that owns this. */
486 dwarf2_per_objfile
*per_objfile
;
488 /* How many compilation units ago was this CU last referenced? */
491 /* A hash table of DIE cu_offset for following references with
492 die_info->offset.sect_off as hash. */
493 htab_t die_hash
= nullptr;
495 /* Full DIEs if read in. */
496 struct die_info
*dies
= nullptr;
498 /* A set of pointers to dwarf2_per_cu_data objects for compilation
499 units referenced by this one. Only set during full symbol processing;
500 partial symbol tables do not have dependencies. */
501 htab_t dependencies
= nullptr;
503 /* Header data from the line table, during full symbol processing. */
504 struct line_header
*line_header
= nullptr;
505 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
506 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
507 this is the DW_TAG_compile_unit die for this CU. We'll hold on
508 to the line header as long as this DIE is being processed. See
509 process_die_scope. */
510 die_info
*line_header_die_owner
= nullptr;
512 /* A list of methods which need to have physnames computed
513 after all type information has been read. */
514 std::vector
<delayed_method_info
> method_list
;
516 /* To be copied to symtab->call_site_htab. */
517 htab_t call_site_htab
= nullptr;
519 /* Non-NULL if this CU came from a DWO file.
520 There is an invariant here that is important to remember:
521 Except for attributes copied from the top level DIE in the "main"
522 (or "stub") file in preparation for reading the DWO file
523 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
524 Either there isn't a DWO file (in which case this is NULL and the point
525 is moot), or there is and either we're not going to read it (in which
526 case this is NULL) or there is and we are reading it (in which case this
528 struct dwo_unit
*dwo_unit
= nullptr;
530 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
531 Note this value comes from the Fission stub CU/TU's DIE. */
532 gdb::optional
<ULONGEST
> addr_base
;
534 /* The DW_AT_rnglists_base attribute if present.
535 Note this value comes from the Fission stub CU/TU's DIE.
536 Also note that the value is zero in the non-DWO case so this value can
537 be used without needing to know whether DWO files are in use or not.
538 N.B. This does not apply to DW_AT_ranges appearing in
539 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
540 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
541 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
542 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
543 ULONGEST ranges_base
= 0;
545 /* The DW_AT_loclists_base attribute if present. */
546 ULONGEST loclist_base
= 0;
548 /* When reading debug info generated by older versions of rustc, we
549 have to rewrite some union types to be struct types with a
550 variant part. This rewriting must be done after the CU is fully
551 read in, because otherwise at the point of rewriting some struct
552 type might not have been fully processed. So, we keep a list of
553 all such types here and process them after expansion. */
554 std::vector
<struct type
*> rust_unions
;
556 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
557 files, the value is implicitly zero. For DWARF 5 version DWO files, the
558 value is often implicit and is the size of the header of
559 .debug_str_offsets section (8 or 4, depending on the address size). */
560 gdb::optional
<ULONGEST
> str_offsets_base
;
562 /* Mark used when releasing cached dies. */
565 /* This CU references .debug_loc. See the symtab->locations_valid field.
566 This test is imperfect as there may exist optimized debug code not using
567 any location list and still facing inlining issues if handled as
568 unoptimized code. For a future better test see GCC PR other/32998. */
569 bool has_loclist
: 1;
571 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
572 if all the producer_is_* fields are valid. This information is cached
573 because profiling CU expansion showed excessive time spent in
574 producer_is_gxx_lt_4_6. */
575 bool checked_producer
: 1;
576 bool producer_is_gxx_lt_4_6
: 1;
577 bool producer_is_gcc_lt_4_3
: 1;
578 bool producer_is_icc
: 1;
579 bool producer_is_icc_lt_14
: 1;
580 bool producer_is_codewarrior
: 1;
582 /* When true, the file that we're processing is known to have
583 debugging info for C++ namespaces. GCC 3.3.x did not produce
584 this information, but later versions do. */
586 bool processing_has_namespace_info
: 1;
588 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
590 /* If this CU was inherited by another CU (via specification,
591 abstract_origin, etc), this is the ancestor CU. */
594 /* Get the buildsym_compunit for this CU. */
595 buildsym_compunit
*get_builder ()
597 /* If this CU has a builder associated with it, use that. */
598 if (m_builder
!= nullptr)
599 return m_builder
.get ();
601 /* Otherwise, search ancestors for a valid builder. */
602 if (ancestor
!= nullptr)
603 return ancestor
->get_builder ();
609 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
610 This includes type_unit_group and quick_file_names. */
612 struct stmt_list_hash
614 /* The DWO unit this table is from or NULL if there is none. */
615 struct dwo_unit
*dwo_unit
;
617 /* Offset in .debug_line or .debug_line.dwo. */
618 sect_offset line_sect_off
;
621 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
622 an object of this type. This contains elements of type unit groups
623 that can be shared across objfiles. The non-shareable parts are in
624 type_unit_group_unshareable. */
626 struct type_unit_group
628 /* dwarf2read.c's main "handle" on a TU symtab.
629 To simplify things we create an artificial CU that "includes" all the
630 type units using this stmt_list so that the rest of the code still has
631 a "per_cu" handle on the symtab. */
632 struct dwarf2_per_cu_data per_cu
;
634 /* The TUs that share this DW_AT_stmt_list entry.
635 This is added to while parsing type units to build partial symtabs,
636 and is deleted afterwards and not used again. */
637 std::vector
<signatured_type
*> *tus
;
639 /* The data used to construct the hash key. */
640 struct stmt_list_hash hash
;
643 /* These sections are what may appear in a (real or virtual) DWO file. */
647 struct dwarf2_section_info abbrev
;
648 struct dwarf2_section_info line
;
649 struct dwarf2_section_info loc
;
650 struct dwarf2_section_info loclists
;
651 struct dwarf2_section_info macinfo
;
652 struct dwarf2_section_info macro
;
653 struct dwarf2_section_info str
;
654 struct dwarf2_section_info str_offsets
;
655 /* In the case of a virtual DWO file, these two are unused. */
656 struct dwarf2_section_info info
;
657 std::vector
<dwarf2_section_info
> types
;
660 /* CUs/TUs in DWP/DWO files. */
664 /* Backlink to the containing struct dwo_file. */
665 struct dwo_file
*dwo_file
;
667 /* The "id" that distinguishes this CU/TU.
668 .debug_info calls this "dwo_id", .debug_types calls this "signature".
669 Since signatures came first, we stick with it for consistency. */
672 /* The section this CU/TU lives in, in the DWO file. */
673 struct dwarf2_section_info
*section
;
675 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
676 sect_offset sect_off
;
679 /* For types, offset in the type's DIE of the type defined by this TU. */
680 cu_offset type_offset_in_tu
;
683 /* include/dwarf2.h defines the DWP section codes.
684 It defines a max value but it doesn't define a min value, which we
685 use for error checking, so provide one. */
687 enum dwp_v2_section_ids
692 /* Data for one DWO file.
694 This includes virtual DWO files (a virtual DWO file is a DWO file as it
695 appears in a DWP file). DWP files don't really have DWO files per se -
696 comdat folding of types "loses" the DWO file they came from, and from
697 a high level view DWP files appear to contain a mass of random types.
698 However, to maintain consistency with the non-DWP case we pretend DWP
699 files contain virtual DWO files, and we assign each TU with one virtual
700 DWO file (generally based on the line and abbrev section offsets -
701 a heuristic that seems to work in practice). */
705 dwo_file () = default;
706 DISABLE_COPY_AND_ASSIGN (dwo_file
);
708 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
709 For virtual DWO files the name is constructed from the section offsets
710 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
711 from related CU+TUs. */
712 const char *dwo_name
= nullptr;
714 /* The DW_AT_comp_dir attribute. */
715 const char *comp_dir
= nullptr;
717 /* The bfd, when the file is open. Otherwise this is NULL.
718 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
719 gdb_bfd_ref_ptr dbfd
;
721 /* The sections that make up this DWO file.
722 Remember that for virtual DWO files in DWP V2, these are virtual
723 sections (for lack of a better name). */
724 struct dwo_sections sections
{};
726 /* The CUs in the file.
727 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
728 an extension to handle LLVM's Link Time Optimization output (where
729 multiple source files may be compiled into a single object/dwo pair). */
732 /* Table of TUs in the file.
733 Each element is a struct dwo_unit. */
737 /* These sections are what may appear in a DWP file. */
741 /* These are used by both DWP version 1 and 2. */
742 struct dwarf2_section_info str
;
743 struct dwarf2_section_info cu_index
;
744 struct dwarf2_section_info tu_index
;
746 /* These are only used by DWP version 2 files.
747 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
748 sections are referenced by section number, and are not recorded here.
749 In DWP version 2 there is at most one copy of all these sections, each
750 section being (effectively) comprised of the concatenation of all of the
751 individual sections that exist in the version 1 format.
752 To keep the code simple we treat each of these concatenated pieces as a
753 section itself (a virtual section?). */
754 struct dwarf2_section_info abbrev
;
755 struct dwarf2_section_info info
;
756 struct dwarf2_section_info line
;
757 struct dwarf2_section_info loc
;
758 struct dwarf2_section_info macinfo
;
759 struct dwarf2_section_info macro
;
760 struct dwarf2_section_info str_offsets
;
761 struct dwarf2_section_info types
;
764 /* These sections are what may appear in a virtual DWO file in DWP version 1.
765 A virtual DWO file is a DWO file as it appears in a DWP file. */
767 struct virtual_v1_dwo_sections
769 struct dwarf2_section_info abbrev
;
770 struct dwarf2_section_info line
;
771 struct dwarf2_section_info loc
;
772 struct dwarf2_section_info macinfo
;
773 struct dwarf2_section_info macro
;
774 struct dwarf2_section_info str_offsets
;
775 /* Each DWP hash table entry records one CU or one TU.
776 That is recorded here, and copied to dwo_unit.section. */
777 struct dwarf2_section_info info_or_types
;
780 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
781 In version 2, the sections of the DWO files are concatenated together
782 and stored in one section of that name. Thus each ELF section contains
783 several "virtual" sections. */
785 struct virtual_v2_dwo_sections
787 bfd_size_type abbrev_offset
;
788 bfd_size_type abbrev_size
;
790 bfd_size_type line_offset
;
791 bfd_size_type line_size
;
793 bfd_size_type loc_offset
;
794 bfd_size_type loc_size
;
796 bfd_size_type macinfo_offset
;
797 bfd_size_type macinfo_size
;
799 bfd_size_type macro_offset
;
800 bfd_size_type macro_size
;
802 bfd_size_type str_offsets_offset
;
803 bfd_size_type str_offsets_size
;
805 /* Each DWP hash table entry records one CU or one TU.
806 That is recorded here, and copied to dwo_unit.section. */
807 bfd_size_type info_or_types_offset
;
808 bfd_size_type info_or_types_size
;
811 /* Contents of DWP hash tables. */
813 struct dwp_hash_table
815 uint32_t version
, nr_columns
;
816 uint32_t nr_units
, nr_slots
;
817 const gdb_byte
*hash_table
, *unit_table
;
822 const gdb_byte
*indices
;
826 /* This is indexed by column number and gives the id of the section
828 #define MAX_NR_V2_DWO_SECTIONS \
829 (1 /* .debug_info or .debug_types */ \
830 + 1 /* .debug_abbrev */ \
831 + 1 /* .debug_line */ \
832 + 1 /* .debug_loc */ \
833 + 1 /* .debug_str_offsets */ \
834 + 1 /* .debug_macro or .debug_macinfo */)
835 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
836 const gdb_byte
*offsets
;
837 const gdb_byte
*sizes
;
842 /* Data for one DWP file. */
846 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
848 dbfd (std::move (abfd
))
852 /* Name of the file. */
855 /* File format version. */
859 gdb_bfd_ref_ptr dbfd
;
861 /* Section info for this file. */
862 struct dwp_sections sections
{};
864 /* Table of CUs in the file. */
865 const struct dwp_hash_table
*cus
= nullptr;
867 /* Table of TUs in the file. */
868 const struct dwp_hash_table
*tus
= nullptr;
870 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
874 /* Table to map ELF section numbers to their sections.
875 This is only needed for the DWP V1 file format. */
876 unsigned int num_sections
= 0;
877 asection
**elf_sections
= nullptr;
880 /* Struct used to pass misc. parameters to read_die_and_children, et
881 al. which are used for both .debug_info and .debug_types dies.
882 All parameters here are unchanging for the life of the call. This
883 struct exists to abstract away the constant parameters of die reading. */
885 struct die_reader_specs
887 /* The bfd of die_section. */
890 /* The CU of the DIE we are parsing. */
891 struct dwarf2_cu
*cu
;
893 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
894 struct dwo_file
*dwo_file
;
896 /* The section the die comes from.
897 This is either .debug_info or .debug_types, or the .dwo variants. */
898 struct dwarf2_section_info
*die_section
;
900 /* die_section->buffer. */
901 const gdb_byte
*buffer
;
903 /* The end of the buffer. */
904 const gdb_byte
*buffer_end
;
906 /* The abbreviation table to use when reading the DIEs. */
907 struct abbrev_table
*abbrev_table
;
910 /* A subclass of die_reader_specs that holds storage and has complex
911 constructor and destructor behavior. */
913 class cutu_reader
: public die_reader_specs
917 cutu_reader (dwarf2_per_cu_data
*this_cu
,
918 dwarf2_per_objfile
*per_objfile
,
919 struct abbrev_table
*abbrev_table
,
920 dwarf2_cu
*existing_cu
,
923 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
924 dwarf2_per_objfile
*per_objfile
,
925 struct dwarf2_cu
*parent_cu
= nullptr,
926 struct dwo_file
*dwo_file
= nullptr);
928 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
930 const gdb_byte
*info_ptr
= nullptr;
931 struct die_info
*comp_unit_die
= nullptr;
932 bool dummy_p
= false;
934 /* Release the new CU, putting it on the chain. This cannot be done
939 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
940 dwarf2_per_objfile
*per_objfile
,
941 dwarf2_cu
*existing_cu
);
943 struct dwarf2_per_cu_data
*m_this_cu
;
944 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
946 /* The ordinary abbreviation table. */
947 abbrev_table_up m_abbrev_table_holder
;
949 /* The DWO abbreviation table. */
950 abbrev_table_up m_dwo_abbrev_table
;
953 /* When we construct a partial symbol table entry we only
954 need this much information. */
955 struct partial_die_info
: public allocate_on_obstack
957 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
959 /* Disable assign but still keep copy ctor, which is needed
960 load_partial_dies. */
961 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
963 /* Adjust the partial die before generating a symbol for it. This
964 function may set the is_external flag or change the DIE's
966 void fixup (struct dwarf2_cu
*cu
);
968 /* Read a minimal amount of information into the minimal die
970 const gdb_byte
*read (const struct die_reader_specs
*reader
,
971 const struct abbrev_info
&abbrev
,
972 const gdb_byte
*info_ptr
);
974 /* Compute the name of this partial DIE. This memoizes the
975 result, so it is safe to call multiple times. */
976 const char *name (dwarf2_cu
*cu
);
978 /* Offset of this DIE. */
979 const sect_offset sect_off
;
981 /* DWARF-2 tag for this DIE. */
982 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
984 /* Assorted flags describing the data found in this DIE. */
985 const unsigned int has_children
: 1;
987 unsigned int is_external
: 1;
988 unsigned int is_declaration
: 1;
989 unsigned int has_type
: 1;
990 unsigned int has_specification
: 1;
991 unsigned int has_pc_info
: 1;
992 unsigned int may_be_inlined
: 1;
994 /* This DIE has been marked DW_AT_main_subprogram. */
995 unsigned int main_subprogram
: 1;
997 /* Flag set if the SCOPE field of this structure has been
999 unsigned int scope_set
: 1;
1001 /* Flag set if the DIE has a byte_size attribute. */
1002 unsigned int has_byte_size
: 1;
1004 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1005 unsigned int has_const_value
: 1;
1007 /* Flag set if any of the DIE's children are template arguments. */
1008 unsigned int has_template_arguments
: 1;
1010 /* Flag set if fixup has been called on this die. */
1011 unsigned int fixup_called
: 1;
1013 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1014 unsigned int is_dwz
: 1;
1016 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1017 unsigned int spec_is_dwz
: 1;
1019 unsigned int canonical_name
: 1;
1021 /* The name of this DIE. Normally the value of DW_AT_name, but
1022 sometimes a default name for unnamed DIEs. */
1023 const char *raw_name
= nullptr;
1025 /* The linkage name, if present. */
1026 const char *linkage_name
= nullptr;
1028 /* The scope to prepend to our children. This is generally
1029 allocated on the comp_unit_obstack, so will disappear
1030 when this compilation unit leaves the cache. */
1031 const char *scope
= nullptr;
1033 /* Some data associated with the partial DIE. The tag determines
1034 which field is live. */
1037 /* The location description associated with this DIE, if any. */
1038 struct dwarf_block
*locdesc
;
1039 /* The offset of an import, for DW_TAG_imported_unit. */
1040 sect_offset sect_off
;
1043 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1044 CORE_ADDR lowpc
= 0;
1045 CORE_ADDR highpc
= 0;
1047 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1048 DW_AT_sibling, if any. */
1049 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1050 could return DW_AT_sibling values to its caller load_partial_dies. */
1051 const gdb_byte
*sibling
= nullptr;
1053 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1054 DW_AT_specification (or DW_AT_abstract_origin or
1055 DW_AT_extension). */
1056 sect_offset spec_offset
{};
1058 /* Pointers to this DIE's parent, first child, and next sibling,
1060 struct partial_die_info
*die_parent
= nullptr;
1061 struct partial_die_info
*die_child
= nullptr;
1062 struct partial_die_info
*die_sibling
= nullptr;
1064 friend struct partial_die_info
*
1065 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1068 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1069 partial_die_info (sect_offset sect_off
)
1070 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1074 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1076 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1081 has_specification
= 0;
1084 main_subprogram
= 0;
1087 has_const_value
= 0;
1088 has_template_arguments
= 0;
1096 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1097 but this would require a corresponding change in unpack_field_as_long
1099 static int bits_per_byte
= 8;
1101 struct variant_part_builder
;
1103 /* When reading a variant, we track a bit more information about the
1104 field, and store it in an object of this type. */
1106 struct variant_field
1108 int first_field
= -1;
1109 int last_field
= -1;
1111 /* A variant can contain other variant parts. */
1112 std::vector
<variant_part_builder
> variant_parts
;
1114 /* If we see a DW_TAG_variant, then this will be set if this is the
1116 bool default_branch
= false;
1117 /* If we see a DW_AT_discr_value, then this will be the discriminant
1119 ULONGEST discriminant_value
= 0;
1120 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1122 struct dwarf_block
*discr_list_data
= nullptr;
1125 /* This represents a DW_TAG_variant_part. */
1127 struct variant_part_builder
1129 /* The offset of the discriminant field. */
1130 sect_offset discriminant_offset
{};
1132 /* Variants that are direct children of this variant part. */
1133 std::vector
<variant_field
> variants
;
1135 /* True if we're currently reading a variant. */
1136 bool processing_variant
= false;
1141 int accessibility
= 0;
1143 /* Variant parts need to find the discriminant, which is a DIE
1144 reference. We track the section offset of each field to make
1147 struct field field
{};
1152 const char *name
= nullptr;
1153 std::vector
<struct fn_field
> fnfields
;
1156 /* The routines that read and process dies for a C struct or C++ class
1157 pass lists of data member fields and lists of member function fields
1158 in an instance of a field_info structure, as defined below. */
1161 /* List of data member and baseclasses fields. */
1162 std::vector
<struct nextfield
> fields
;
1163 std::vector
<struct nextfield
> baseclasses
;
1165 /* Set if the accessibility of one of the fields is not public. */
1166 int non_public_fields
= 0;
1168 /* Member function fieldlist array, contains name of possibly overloaded
1169 member function, number of overloaded member functions and a pointer
1170 to the head of the member function field chain. */
1171 std::vector
<struct fnfieldlist
> fnfieldlists
;
1173 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1174 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1175 std::vector
<struct decl_field
> typedef_field_list
;
1177 /* Nested types defined by this class and the number of elements in this
1179 std::vector
<struct decl_field
> nested_types_list
;
1181 /* If non-null, this is the variant part we are currently
1183 variant_part_builder
*current_variant_part
= nullptr;
1184 /* This holds all the top-level variant parts attached to the type
1186 std::vector
<variant_part_builder
> variant_parts
;
1188 /* Return the total number of fields (including baseclasses). */
1189 int nfields () const
1191 return fields
.size () + baseclasses
.size ();
1195 /* Loaded secondary compilation units are kept in memory until they
1196 have not been referenced for the processing of this many
1197 compilation units. Set this to zero to disable caching. Cache
1198 sizes of up to at least twenty will improve startup time for
1199 typical inter-CU-reference binaries, at an obvious memory cost. */
1200 static int dwarf_max_cache_age
= 5;
1202 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1203 struct cmd_list_element
*c
, const char *value
)
1205 fprintf_filtered (file
, _("The upper bound on the age of cached "
1206 "DWARF compilation units is %s.\n"),
1210 /* local function prototypes */
1212 static void dwarf2_find_base_address (struct die_info
*die
,
1213 struct dwarf2_cu
*cu
);
1215 static dwarf2_psymtab
*create_partial_symtab
1216 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1219 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1220 const gdb_byte
*info_ptr
,
1221 struct die_info
*type_unit_die
);
1223 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1225 static void scan_partial_symbols (struct partial_die_info
*,
1226 CORE_ADDR
*, CORE_ADDR
*,
1227 int, struct dwarf2_cu
*);
1229 static void add_partial_symbol (struct partial_die_info
*,
1230 struct dwarf2_cu
*);
1232 static void add_partial_namespace (struct partial_die_info
*pdi
,
1233 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1234 int set_addrmap
, struct dwarf2_cu
*cu
);
1236 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1237 CORE_ADDR
*highpc
, int set_addrmap
,
1238 struct dwarf2_cu
*cu
);
1240 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1241 struct dwarf2_cu
*cu
);
1243 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1244 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1245 int need_pc
, struct dwarf2_cu
*cu
);
1247 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1249 static struct partial_die_info
*load_partial_dies
1250 (const struct die_reader_specs
*, const gdb_byte
*, int);
1252 /* A pair of partial_die_info and compilation unit. */
1253 struct cu_partial_die_info
1255 /* The compilation unit of the partial_die_info. */
1256 struct dwarf2_cu
*cu
;
1257 /* A partial_die_info. */
1258 struct partial_die_info
*pdi
;
1260 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1266 cu_partial_die_info () = delete;
1269 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1270 struct dwarf2_cu
*);
1272 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1273 struct attribute
*, struct attr_abbrev
*,
1274 const gdb_byte
*, bool *need_reprocess
);
1276 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1277 struct attribute
*attr
);
1279 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1281 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1282 dwarf2_section_info
*, sect_offset
);
1284 static const char *read_indirect_string
1285 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1286 const struct comp_unit_head
*, unsigned int *);
1288 static const char *read_indirect_string_at_offset
1289 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1291 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1295 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1296 ULONGEST str_index
);
1298 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1299 ULONGEST str_index
);
1301 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1303 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1304 struct dwarf2_cu
*);
1306 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1307 struct dwarf2_cu
*cu
);
1309 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1311 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1312 struct dwarf2_cu
*cu
);
1314 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1316 static struct die_info
*die_specification (struct die_info
*die
,
1317 struct dwarf2_cu
**);
1319 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1320 struct dwarf2_cu
*cu
);
1322 static void dwarf_decode_lines (struct line_header
*, const char *,
1323 struct dwarf2_cu
*, dwarf2_psymtab
*,
1324 CORE_ADDR
, int decode_mapping
);
1326 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1329 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1330 struct dwarf2_cu
*, struct symbol
* = NULL
);
1332 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1333 struct dwarf2_cu
*);
1335 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1338 struct obstack
*obstack
,
1339 struct dwarf2_cu
*cu
, LONGEST
*value
,
1340 const gdb_byte
**bytes
,
1341 struct dwarf2_locexpr_baton
**baton
);
1343 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1345 static int need_gnat_info (struct dwarf2_cu
*);
1347 static struct type
*die_descriptive_type (struct die_info
*,
1348 struct dwarf2_cu
*);
1350 static void set_descriptive_type (struct type
*, struct die_info
*,
1351 struct dwarf2_cu
*);
1353 static struct type
*die_containing_type (struct die_info
*,
1354 struct dwarf2_cu
*);
1356 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1357 struct dwarf2_cu
*);
1359 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1361 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1363 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1365 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1366 const char *suffix
, int physname
,
1367 struct dwarf2_cu
*cu
);
1369 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1371 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1373 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1375 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1377 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1379 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1381 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1382 struct dwarf2_cu
*, dwarf2_psymtab
*);
1384 /* Return the .debug_loclists section to use for cu. */
1385 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1387 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1388 values. Keep the items ordered with increasing constraints compliance. */
1391 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1392 PC_BOUNDS_NOT_PRESENT
,
1394 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1395 were present but they do not form a valid range of PC addresses. */
1398 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1401 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1405 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1406 CORE_ADDR
*, CORE_ADDR
*,
1410 static void get_scope_pc_bounds (struct die_info
*,
1411 CORE_ADDR
*, CORE_ADDR
*,
1412 struct dwarf2_cu
*);
1414 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1415 CORE_ADDR
, struct dwarf2_cu
*);
1417 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1418 struct dwarf2_cu
*);
1420 static void dwarf2_attach_fields_to_type (struct field_info
*,
1421 struct type
*, struct dwarf2_cu
*);
1423 static void dwarf2_add_member_fn (struct field_info
*,
1424 struct die_info
*, struct type
*,
1425 struct dwarf2_cu
*);
1427 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1429 struct dwarf2_cu
*);
1431 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1433 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1435 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1437 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1439 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1441 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1443 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1445 static struct type
*read_module_type (struct die_info
*die
,
1446 struct dwarf2_cu
*cu
);
1448 static const char *namespace_name (struct die_info
*die
,
1449 int *is_anonymous
, struct dwarf2_cu
*);
1451 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1453 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1456 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1457 struct dwarf2_cu
*);
1459 static struct die_info
*read_die_and_siblings_1
1460 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1463 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1464 const gdb_byte
*info_ptr
,
1465 const gdb_byte
**new_info_ptr
,
1466 struct die_info
*parent
);
1468 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1469 struct die_info
**, const gdb_byte
*,
1472 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1473 struct die_info
**, const gdb_byte
*);
1475 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1477 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1480 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1482 static const char *dwarf2_full_name (const char *name
,
1483 struct die_info
*die
,
1484 struct dwarf2_cu
*cu
);
1486 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1487 struct dwarf2_cu
*cu
);
1489 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1490 struct dwarf2_cu
**);
1492 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1494 static void dump_die_for_error (struct die_info
*);
1496 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1499 /*static*/ void dump_die (struct die_info
*, int max_level
);
1501 static void store_in_ref_table (struct die_info
*,
1502 struct dwarf2_cu
*);
1504 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1505 const struct attribute
*,
1506 struct dwarf2_cu
**);
1508 static struct die_info
*follow_die_ref (struct die_info
*,
1509 const struct attribute
*,
1510 struct dwarf2_cu
**);
1512 static struct die_info
*follow_die_sig (struct die_info
*,
1513 const struct attribute
*,
1514 struct dwarf2_cu
**);
1516 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1517 struct dwarf2_cu
*);
1519 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1520 const struct attribute
*,
1521 struct dwarf2_cu
*);
1523 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1524 dwarf2_per_objfile
*per_objfile
);
1526 static void read_signatured_type (signatured_type
*sig_type
,
1527 dwarf2_per_objfile
*per_objfile
);
1529 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1530 struct die_info
*die
, struct dwarf2_cu
*cu
,
1531 struct dynamic_prop
*prop
, struct type
*type
);
1533 /* memory allocation interface */
1535 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1537 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1539 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1541 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1542 struct dwarf2_loclist_baton
*baton
,
1543 const struct attribute
*attr
);
1545 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1547 struct dwarf2_cu
*cu
,
1550 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1551 const gdb_byte
*info_ptr
,
1552 struct abbrev_info
*abbrev
);
1554 static hashval_t
partial_die_hash (const void *item
);
1556 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1558 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1559 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1560 dwarf2_per_objfile
*per_objfile
);
1562 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1563 struct die_info
*comp_unit_die
,
1564 enum language pretend_language
);
1566 static struct type
*set_die_type (struct die_info
*, struct type
*,
1567 struct dwarf2_cu
*);
1569 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1571 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1573 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1574 dwarf2_per_objfile
*per_objfile
,
1576 enum language pretend_language
);
1578 static void process_full_comp_unit (dwarf2_cu
*cu
,
1579 enum language pretend_language
);
1581 static void process_full_type_unit (dwarf2_cu
*cu
,
1582 enum language pretend_language
);
1584 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1585 struct dwarf2_per_cu_data
*);
1587 static void dwarf2_mark (struct dwarf2_cu
*);
1589 static struct type
*get_die_type_at_offset (sect_offset
,
1590 dwarf2_per_cu_data
*per_cu
,
1591 dwarf2_per_objfile
*per_objfile
);
1593 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1595 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1596 dwarf2_per_objfile
*per_objfile
,
1597 enum language pretend_language
);
1599 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1601 /* Class, the destructor of which frees all allocated queue entries. This
1602 will only have work to do if an error was thrown while processing the
1603 dwarf. If no error was thrown then the queue entries should have all
1604 been processed, and freed, as we went along. */
1606 class dwarf2_queue_guard
1609 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1610 : m_per_objfile (per_objfile
)
1614 /* Free any entries remaining on the queue. There should only be
1615 entries left if we hit an error while processing the dwarf. */
1616 ~dwarf2_queue_guard ()
1618 /* Ensure that no memory is allocated by the queue. */
1619 std::queue
<dwarf2_queue_item
> empty
;
1620 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1623 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1626 dwarf2_per_objfile
*m_per_objfile
;
1629 dwarf2_queue_item::~dwarf2_queue_item ()
1631 /* Anything still marked queued is likely to be in an
1632 inconsistent state, so discard it. */
1635 per_objfile
->remove_cu (per_cu
);
1640 /* The return type of find_file_and_directory. Note, the enclosed
1641 string pointers are only valid while this object is valid. */
1643 struct file_and_directory
1645 /* The filename. This is never NULL. */
1648 /* The compilation directory. NULL if not known. If we needed to
1649 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1650 points directly to the DW_AT_comp_dir string attribute owned by
1651 the obstack that owns the DIE. */
1652 const char *comp_dir
;
1654 /* If we needed to build a new string for comp_dir, this is what
1655 owns the storage. */
1656 std::string comp_dir_storage
;
1659 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1660 struct dwarf2_cu
*cu
);
1662 static htab_up
allocate_signatured_type_table ();
1664 static htab_up
allocate_dwo_unit_table ();
1666 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1667 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1668 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1670 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1672 static struct dwo_unit
*lookup_dwo_comp_unit
1673 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1674 ULONGEST signature
);
1676 static struct dwo_unit
*lookup_dwo_type_unit
1677 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1679 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1681 /* A unique pointer to a dwo_file. */
1683 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1685 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1687 static void check_producer (struct dwarf2_cu
*cu
);
1689 static void free_line_header_voidp (void *arg
);
1691 /* Various complaints about symbol reading that don't abort the process. */
1694 dwarf2_debug_line_missing_file_complaint (void)
1696 complaint (_(".debug_line section has line data without a file"));
1700 dwarf2_debug_line_missing_end_sequence_complaint (void)
1702 complaint (_(".debug_line section has line "
1703 "program sequence without an end"));
1707 dwarf2_complex_location_expr_complaint (void)
1709 complaint (_("location expression too complex"));
1713 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1716 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1721 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1723 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1727 /* Hash function for line_header_hash. */
1730 line_header_hash (const struct line_header
*ofs
)
1732 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1735 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1738 line_header_hash_voidp (const void *item
)
1740 const struct line_header
*ofs
= (const struct line_header
*) item
;
1742 return line_header_hash (ofs
);
1745 /* Equality function for line_header_hash. */
1748 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1750 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1751 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1753 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1754 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1759 /* See declaration. */
1761 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1764 can_copy (can_copy_
)
1767 names
= &dwarf2_elf_names
;
1769 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1770 locate_sections (obfd
, sec
, *names
);
1773 dwarf2_per_bfd::~dwarf2_per_bfd ()
1775 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1776 per_cu
->imported_symtabs_free ();
1778 for (signatured_type
*sig_type
: all_type_units
)
1779 sig_type
->per_cu
.imported_symtabs_free ();
1781 /* Everything else should be on this->obstack. */
1787 dwarf2_per_objfile::remove_all_cus ()
1789 for (auto pair
: m_dwarf2_cus
)
1792 m_dwarf2_cus
.clear ();
1795 /* A helper class that calls free_cached_comp_units on
1798 class free_cached_comp_units
1802 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1803 : m_per_objfile (per_objfile
)
1807 ~free_cached_comp_units ()
1809 m_per_objfile
->remove_all_cus ();
1812 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1816 dwarf2_per_objfile
*m_per_objfile
;
1822 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1824 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1826 return this->m_symtabs
[per_cu
->index
] != nullptr;
1832 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1834 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1836 return this->m_symtabs
[per_cu
->index
];
1842 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1843 compunit_symtab
*symtab
)
1845 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1846 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1848 this->m_symtabs
[per_cu
->index
] = symtab
;
1851 /* Try to locate the sections we need for DWARF 2 debugging
1852 information and return true if we have enough to do something.
1853 NAMES points to the dwarf2 section names, or is NULL if the standard
1854 ELF names are used. CAN_COPY is true for formats where symbol
1855 interposition is possible and so symbol values must follow copy
1856 relocation rules. */
1859 dwarf2_has_info (struct objfile
*objfile
,
1860 const struct dwarf2_debug_sections
*names
,
1863 if (objfile
->flags
& OBJF_READNEVER
)
1866 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1868 if (per_objfile
== NULL
)
1870 dwarf2_per_bfd
*per_bfd
;
1872 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1873 doesn't require relocations and if there aren't partial symbols
1874 from some other reader. */
1875 if (!objfile_has_partial_symbols (objfile
)
1876 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1878 /* See if one has been created for this BFD yet. */
1879 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1881 if (per_bfd
== nullptr)
1883 /* No, create it now. */
1884 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1885 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1890 /* No sharing possible, create one specifically for this objfile. */
1891 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1892 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1895 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1898 return (!per_objfile
->per_bfd
->info
.is_virtual
1899 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1900 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1901 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1904 /* When loading sections, we look either for uncompressed section or for
1905 compressed section names. */
1908 section_is_p (const char *section_name
,
1909 const struct dwarf2_section_names
*names
)
1911 if (names
->normal
!= NULL
1912 && strcmp (section_name
, names
->normal
) == 0)
1914 if (names
->compressed
!= NULL
1915 && strcmp (section_name
, names
->compressed
) == 0)
1920 /* See declaration. */
1923 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1924 const dwarf2_debug_sections
&names
)
1926 flagword aflag
= bfd_section_flags (sectp
);
1928 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1931 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1932 > bfd_get_file_size (abfd
))
1934 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1935 warning (_("Discarding section %s which has a section size (%s"
1936 ") larger than the file size [in module %s]"),
1937 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1938 bfd_get_filename (abfd
));
1940 else if (section_is_p (sectp
->name
, &names
.info
))
1942 this->info
.s
.section
= sectp
;
1943 this->info
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1947 this->abbrev
.s
.section
= sectp
;
1948 this->abbrev
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.line
))
1952 this->line
.s
.section
= sectp
;
1953 this->line
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.loc
))
1957 this->loc
.s
.section
= sectp
;
1958 this->loc
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.loclists
))
1962 this->loclists
.s
.section
= sectp
;
1963 this->loclists
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1967 this->macinfo
.s
.section
= sectp
;
1968 this->macinfo
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.macro
))
1972 this->macro
.s
.section
= sectp
;
1973 this->macro
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.str
))
1977 this->str
.s
.section
= sectp
;
1978 this->str
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1982 this->str_offsets
.s
.section
= sectp
;
1983 this->str_offsets
.size
= bfd_section_size (sectp
);
1985 else if (section_is_p (sectp
->name
, &names
.line_str
))
1987 this->line_str
.s
.section
= sectp
;
1988 this->line_str
.size
= bfd_section_size (sectp
);
1990 else if (section_is_p (sectp
->name
, &names
.addr
))
1992 this->addr
.s
.section
= sectp
;
1993 this->addr
.size
= bfd_section_size (sectp
);
1995 else if (section_is_p (sectp
->name
, &names
.frame
))
1997 this->frame
.s
.section
= sectp
;
1998 this->frame
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2002 this->eh_frame
.s
.section
= sectp
;
2003 this->eh_frame
.size
= bfd_section_size (sectp
);
2005 else if (section_is_p (sectp
->name
, &names
.ranges
))
2007 this->ranges
.s
.section
= sectp
;
2008 this->ranges
.size
= bfd_section_size (sectp
);
2010 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2012 this->rnglists
.s
.section
= sectp
;
2013 this->rnglists
.size
= bfd_section_size (sectp
);
2015 else if (section_is_p (sectp
->name
, &names
.types
))
2017 struct dwarf2_section_info type_section
;
2019 memset (&type_section
, 0, sizeof (type_section
));
2020 type_section
.s
.section
= sectp
;
2021 type_section
.size
= bfd_section_size (sectp
);
2023 this->types
.push_back (type_section
);
2025 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2027 this->gdb_index
.s
.section
= sectp
;
2028 this->gdb_index
.size
= bfd_section_size (sectp
);
2030 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2032 this->debug_names
.s
.section
= sectp
;
2033 this->debug_names
.size
= bfd_section_size (sectp
);
2035 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2037 this->debug_aranges
.s
.section
= sectp
;
2038 this->debug_aranges
.size
= bfd_section_size (sectp
);
2041 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2042 && bfd_section_vma (sectp
) == 0)
2043 this->has_section_at_zero
= true;
2046 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2050 dwarf2_get_section_info (struct objfile
*objfile
,
2051 enum dwarf2_section_enum sect
,
2052 asection
**sectp
, const gdb_byte
**bufp
,
2053 bfd_size_type
*sizep
)
2055 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2056 struct dwarf2_section_info
*info
;
2058 /* We may see an objfile without any DWARF, in which case we just
2060 if (per_objfile
== NULL
)
2069 case DWARF2_DEBUG_FRAME
:
2070 info
= &per_objfile
->per_bfd
->frame
;
2072 case DWARF2_EH_FRAME
:
2073 info
= &per_objfile
->per_bfd
->eh_frame
;
2076 gdb_assert_not_reached ("unexpected section");
2079 info
->read (objfile
);
2081 *sectp
= info
->get_bfd_section ();
2082 *bufp
= info
->buffer
;
2083 *sizep
= info
->size
;
2086 /* A helper function to find the sections for a .dwz file. */
2089 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2091 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2093 /* Note that we only support the standard ELF names, because .dwz
2094 is ELF-only (at the time of writing). */
2095 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2097 dwz_file
->abbrev
.s
.section
= sectp
;
2098 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2100 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2102 dwz_file
->info
.s
.section
= sectp
;
2103 dwz_file
->info
.size
= bfd_section_size (sectp
);
2105 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2107 dwz_file
->str
.s
.section
= sectp
;
2108 dwz_file
->str
.size
= bfd_section_size (sectp
);
2110 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2112 dwz_file
->line
.s
.section
= sectp
;
2113 dwz_file
->line
.size
= bfd_section_size (sectp
);
2115 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2117 dwz_file
->macro
.s
.section
= sectp
;
2118 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2120 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2122 dwz_file
->gdb_index
.s
.section
= sectp
;
2123 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2125 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2127 dwz_file
->debug_names
.s
.section
= sectp
;
2128 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2132 /* See dwarf2read.h. */
2135 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2137 const char *filename
;
2138 bfd_size_type buildid_len_arg
;
2142 if (per_bfd
->dwz_file
!= NULL
)
2143 return per_bfd
->dwz_file
.get ();
2145 bfd_set_error (bfd_error_no_error
);
2146 gdb::unique_xmalloc_ptr
<char> data
2147 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2148 &buildid_len_arg
, &buildid
));
2151 if (bfd_get_error () == bfd_error_no_error
)
2153 error (_("could not read '.gnu_debugaltlink' section: %s"),
2154 bfd_errmsg (bfd_get_error ()));
2157 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2159 buildid_len
= (size_t) buildid_len_arg
;
2161 filename
= data
.get ();
2163 std::string abs_storage
;
2164 if (!IS_ABSOLUTE_PATH (filename
))
2166 gdb::unique_xmalloc_ptr
<char> abs
2167 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2169 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2170 filename
= abs_storage
.c_str ();
2173 /* First try the file name given in the section. If that doesn't
2174 work, try to use the build-id instead. */
2175 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2176 if (dwz_bfd
!= NULL
)
2178 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2179 dwz_bfd
.reset (nullptr);
2182 if (dwz_bfd
== NULL
)
2183 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2185 if (dwz_bfd
== nullptr)
2187 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2188 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2190 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2197 /* File successfully retrieved from server. */
2198 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2200 if (dwz_bfd
== nullptr)
2201 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2202 alt_filename
.get ());
2203 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2204 dwz_bfd
.reset (nullptr);
2208 if (dwz_bfd
== NULL
)
2209 error (_("could not find '.gnu_debugaltlink' file for %s"),
2210 bfd_get_filename (per_bfd
->obfd
));
2212 std::unique_ptr
<struct dwz_file
> result
2213 (new struct dwz_file (std::move (dwz_bfd
)));
2215 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2218 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2219 per_bfd
->dwz_file
= std::move (result
);
2220 return per_bfd
->dwz_file
.get ();
2223 /* DWARF quick_symbols_functions support. */
2225 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2226 unique line tables, so we maintain a separate table of all .debug_line
2227 derived entries to support the sharing.
2228 All the quick functions need is the list of file names. We discard the
2229 line_header when we're done and don't need to record it here. */
2230 struct quick_file_names
2232 /* The data used to construct the hash key. */
2233 struct stmt_list_hash hash
;
2235 /* The number of entries in file_names, real_names. */
2236 unsigned int num_file_names
;
2238 /* The file names from the line table, after being run through
2240 const char **file_names
;
2242 /* The file names from the line table after being run through
2243 gdb_realpath. These are computed lazily. */
2244 const char **real_names
;
2247 /* When using the index (and thus not using psymtabs), each CU has an
2248 object of this type. This is used to hold information needed by
2249 the various "quick" methods. */
2250 struct dwarf2_per_cu_quick_data
2252 /* The file table. This can be NULL if there was no file table
2253 or it's currently not read in.
2254 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2255 struct quick_file_names
*file_names
;
2257 /* A temporary mark bit used when iterating over all CUs in
2258 expand_symtabs_matching. */
2259 unsigned int mark
: 1;
2261 /* True if we've tried to read the file table and found there isn't one.
2262 There will be no point in trying to read it again next time. */
2263 unsigned int no_file_data
: 1;
2266 /* Utility hash function for a stmt_list_hash. */
2269 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2273 if (stmt_list_hash
->dwo_unit
!= NULL
)
2274 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2275 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2279 /* Utility equality function for a stmt_list_hash. */
2282 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2283 const struct stmt_list_hash
*rhs
)
2285 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2287 if (lhs
->dwo_unit
!= NULL
2288 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2291 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2294 /* Hash function for a quick_file_names. */
2297 hash_file_name_entry (const void *e
)
2299 const struct quick_file_names
*file_data
2300 = (const struct quick_file_names
*) e
;
2302 return hash_stmt_list_entry (&file_data
->hash
);
2305 /* Equality function for a quick_file_names. */
2308 eq_file_name_entry (const void *a
, const void *b
)
2310 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2311 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2313 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2316 /* Delete function for a quick_file_names. */
2319 delete_file_name_entry (void *e
)
2321 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2324 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2326 xfree ((void*) file_data
->file_names
[i
]);
2327 if (file_data
->real_names
)
2328 xfree ((void*) file_data
->real_names
[i
]);
2331 /* The space for the struct itself lives on the obstack, so we don't
2335 /* Create a quick_file_names hash table. */
2338 create_quick_file_names_table (unsigned int nr_initial_entries
)
2340 return htab_up (htab_create_alloc (nr_initial_entries
,
2341 hash_file_name_entry
, eq_file_name_entry
,
2342 delete_file_name_entry
, xcalloc
, xfree
));
2345 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2346 function is unrelated to symtabs, symtab would have to be created afterwards.
2347 You should call age_cached_comp_units after processing the CU. */
2350 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2353 if (per_cu
->is_debug_types
)
2354 load_full_type_unit (per_cu
, per_objfile
);
2356 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2358 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2360 return nullptr; /* Dummy CU. */
2362 dwarf2_find_base_address (cu
->dies
, cu
);
2367 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2370 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2371 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2373 /* Skip type_unit_groups, reading the type units they contain
2374 is handled elsewhere. */
2375 if (per_cu
->type_unit_group_p ())
2378 /* The destructor of dwarf2_queue_guard frees any entries left on
2379 the queue. After this point we're guaranteed to leave this function
2380 with the dwarf queue empty. */
2381 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2383 if (!per_objfile
->symtab_set_p (per_cu
))
2385 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2386 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2388 /* If we just loaded a CU from a DWO, and we're working with an index
2389 that may badly handle TUs, load all the TUs in that DWO as well.
2390 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2391 if (!per_cu
->is_debug_types
2393 && cu
->dwo_unit
!= NULL
2394 && per_objfile
->per_bfd
->index_table
!= NULL
2395 && per_objfile
->per_bfd
->index_table
->version
<= 7
2396 /* DWP files aren't supported yet. */
2397 && get_dwp_file (per_objfile
) == NULL
)
2398 queue_and_load_all_dwo_tus (cu
);
2401 process_queue (per_objfile
);
2403 /* Age the cache, releasing compilation units that have not
2404 been used recently. */
2405 per_objfile
->age_comp_units ();
2408 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2409 the per-objfile for which this symtab is instantiated.
2411 Returns the resulting symbol table. */
2413 static struct compunit_symtab
*
2414 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2415 dwarf2_per_objfile
*per_objfile
,
2418 gdb_assert (per_objfile
->per_bfd
->using_index
);
2420 if (!per_objfile
->symtab_set_p (per_cu
))
2422 free_cached_comp_units
freer (per_objfile
);
2423 scoped_restore decrementer
= increment_reading_symtab ();
2424 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2425 process_cu_includes (per_objfile
);
2428 return per_objfile
->get_symtab (per_cu
);
2431 /* See declaration. */
2433 dwarf2_per_cu_data
*
2434 dwarf2_per_bfd::get_cutu (int index
)
2436 if (index
>= this->all_comp_units
.size ())
2438 index
-= this->all_comp_units
.size ();
2439 gdb_assert (index
< this->all_type_units
.size ());
2440 return &this->all_type_units
[index
]->per_cu
;
2443 return this->all_comp_units
[index
];
2446 /* See declaration. */
2448 dwarf2_per_cu_data
*
2449 dwarf2_per_bfd::get_cu (int index
)
2451 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2453 return this->all_comp_units
[index
];
2456 /* See declaration. */
2459 dwarf2_per_bfd::get_tu (int index
)
2461 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2463 return this->all_type_units
[index
];
2468 dwarf2_per_cu_data
*
2469 dwarf2_per_bfd::allocate_per_cu ()
2471 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2472 result
->per_bfd
= this;
2473 result
->index
= m_num_psymtabs
++;
2480 dwarf2_per_bfd::allocate_signatured_type ()
2482 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2483 result
->per_cu
.per_bfd
= this;
2484 result
->per_cu
.index
= m_num_psymtabs
++;
2488 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2489 obstack, and constructed with the specified field values. */
2491 static dwarf2_per_cu_data
*
2492 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2493 struct dwarf2_section_info
*section
,
2495 sect_offset sect_off
, ULONGEST length
)
2497 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2498 the_cu
->sect_off
= sect_off
;
2499 the_cu
->length
= length
;
2500 the_cu
->section
= section
;
2501 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2502 struct dwarf2_per_cu_quick_data
);
2503 the_cu
->is_dwz
= is_dwz
;
2507 /* A helper for create_cus_from_index that handles a given list of
2511 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2512 const gdb_byte
*cu_list
, offset_type n_elements
,
2513 struct dwarf2_section_info
*section
,
2516 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2518 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2520 sect_offset sect_off
2521 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2522 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2525 dwarf2_per_cu_data
*per_cu
2526 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2528 per_bfd
->all_comp_units
.push_back (per_cu
);
2532 /* Read the CU list from the mapped index, and use it to create all
2533 the CU objects for PER_BFD. */
2536 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2537 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2538 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2540 gdb_assert (per_bfd
->all_comp_units
.empty ());
2541 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2543 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2546 if (dwz_elements
== 0)
2549 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2550 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2554 /* Create the signatured type hash table from the index. */
2557 create_signatured_type_table_from_index
2558 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2559 const gdb_byte
*bytes
, offset_type elements
)
2561 gdb_assert (per_bfd
->all_type_units
.empty ());
2562 per_bfd
->all_type_units
.reserve (elements
/ 3);
2564 htab_up sig_types_hash
= allocate_signatured_type_table ();
2566 for (offset_type i
= 0; i
< elements
; i
+= 3)
2568 struct signatured_type
*sig_type
;
2571 cu_offset type_offset_in_tu
;
2573 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2574 sect_offset sect_off
2575 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2577 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2579 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2582 sig_type
= per_bfd
->allocate_signatured_type ();
2583 sig_type
->signature
= signature
;
2584 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2585 sig_type
->per_cu
.is_debug_types
= 1;
2586 sig_type
->per_cu
.section
= section
;
2587 sig_type
->per_cu
.sect_off
= sect_off
;
2588 sig_type
->per_cu
.v
.quick
2589 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2590 struct dwarf2_per_cu_quick_data
);
2592 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2595 per_bfd
->all_type_units
.push_back (sig_type
);
2598 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2601 /* Create the signatured type hash table from .debug_names. */
2604 create_signatured_type_table_from_debug_names
2605 (dwarf2_per_objfile
*per_objfile
,
2606 const mapped_debug_names
&map
,
2607 struct dwarf2_section_info
*section
,
2608 struct dwarf2_section_info
*abbrev_section
)
2610 struct objfile
*objfile
= per_objfile
->objfile
;
2612 section
->read (objfile
);
2613 abbrev_section
->read (objfile
);
2615 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2616 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2618 htab_up sig_types_hash
= allocate_signatured_type_table ();
2620 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2622 struct signatured_type
*sig_type
;
2625 sect_offset sect_off
2626 = (sect_offset
) (extract_unsigned_integer
2627 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2629 map
.dwarf5_byte_order
));
2631 comp_unit_head cu_header
;
2632 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2634 section
->buffer
+ to_underlying (sect_off
),
2637 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2638 sig_type
->signature
= cu_header
.signature
;
2639 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2640 sig_type
->per_cu
.is_debug_types
= 1;
2641 sig_type
->per_cu
.section
= section
;
2642 sig_type
->per_cu
.sect_off
= sect_off
;
2643 sig_type
->per_cu
.v
.quick
2644 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2645 struct dwarf2_per_cu_quick_data
);
2647 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2650 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2653 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2656 /* Read the address map data from the mapped index, and use it to
2657 populate the objfile's psymtabs_addrmap. */
2660 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2661 struct mapped_index
*index
)
2663 struct objfile
*objfile
= per_objfile
->objfile
;
2664 struct gdbarch
*gdbarch
= objfile
->arch ();
2665 const gdb_byte
*iter
, *end
;
2666 struct addrmap
*mutable_map
;
2669 auto_obstack temp_obstack
;
2671 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2673 iter
= index
->address_table
.data ();
2674 end
= iter
+ index
->address_table
.size ();
2676 baseaddr
= objfile
->text_section_offset ();
2680 ULONGEST hi
, lo
, cu_index
;
2681 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2683 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2685 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2690 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2691 hex_string (lo
), hex_string (hi
));
2695 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2697 complaint (_(".gdb_index address table has invalid CU number %u"),
2698 (unsigned) cu_index
);
2702 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2703 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2704 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2705 per_objfile
->per_bfd
->get_cu (cu_index
));
2708 objfile
->partial_symtabs
->psymtabs_addrmap
2709 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2712 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2713 populate the objfile's psymtabs_addrmap. */
2716 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2717 struct dwarf2_section_info
*section
)
2719 struct objfile
*objfile
= per_objfile
->objfile
;
2720 bfd
*abfd
= objfile
->obfd
;
2721 struct gdbarch
*gdbarch
= objfile
->arch ();
2722 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2724 auto_obstack temp_obstack
;
2725 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2727 std::unordered_map
<sect_offset
,
2728 dwarf2_per_cu_data
*,
2729 gdb::hash_enum
<sect_offset
>>
2730 debug_info_offset_to_per_cu
;
2731 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2733 const auto insertpair
2734 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2735 if (!insertpair
.second
)
2737 warning (_("Section .debug_aranges in %s has duplicate "
2738 "debug_info_offset %s, ignoring .debug_aranges."),
2739 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2744 section
->read (objfile
);
2746 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2748 const gdb_byte
*addr
= section
->buffer
;
2750 while (addr
< section
->buffer
+ section
->size
)
2752 const gdb_byte
*const entry_addr
= addr
;
2753 unsigned int bytes_read
;
2755 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2759 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2760 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2761 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2762 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2764 warning (_("Section .debug_aranges in %s entry at offset %s "
2765 "length %s exceeds section length %s, "
2766 "ignoring .debug_aranges."),
2767 objfile_name (objfile
),
2768 plongest (entry_addr
- section
->buffer
),
2769 plongest (bytes_read
+ entry_length
),
2770 pulongest (section
->size
));
2774 /* The version number. */
2775 const uint16_t version
= read_2_bytes (abfd
, addr
);
2779 warning (_("Section .debug_aranges in %s entry at offset %s "
2780 "has unsupported version %d, ignoring .debug_aranges."),
2781 objfile_name (objfile
),
2782 plongest (entry_addr
- section
->buffer
), version
);
2786 const uint64_t debug_info_offset
2787 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2788 addr
+= offset_size
;
2789 const auto per_cu_it
2790 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2791 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2793 warning (_("Section .debug_aranges in %s entry at offset %s "
2794 "debug_info_offset %s does not exists, "
2795 "ignoring .debug_aranges."),
2796 objfile_name (objfile
),
2797 plongest (entry_addr
- section
->buffer
),
2798 pulongest (debug_info_offset
));
2801 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2803 const uint8_t address_size
= *addr
++;
2804 if (address_size
< 1 || address_size
> 8)
2806 warning (_("Section .debug_aranges in %s entry at offset %s "
2807 "address_size %u is invalid, ignoring .debug_aranges."),
2808 objfile_name (objfile
),
2809 plongest (entry_addr
- section
->buffer
), address_size
);
2813 const uint8_t segment_selector_size
= *addr
++;
2814 if (segment_selector_size
!= 0)
2816 warning (_("Section .debug_aranges in %s entry at offset %s "
2817 "segment_selector_size %u is not supported, "
2818 "ignoring .debug_aranges."),
2819 objfile_name (objfile
),
2820 plongest (entry_addr
- section
->buffer
),
2821 segment_selector_size
);
2825 /* Must pad to an alignment boundary that is twice the address
2826 size. It is undocumented by the DWARF standard but GCC does
2828 for (size_t padding
= ((-(addr
- section
->buffer
))
2829 & (2 * address_size
- 1));
2830 padding
> 0; padding
--)
2833 warning (_("Section .debug_aranges in %s entry at offset %s "
2834 "padding is not zero, ignoring .debug_aranges."),
2835 objfile_name (objfile
),
2836 plongest (entry_addr
- section
->buffer
));
2842 if (addr
+ 2 * address_size
> entry_end
)
2844 warning (_("Section .debug_aranges in %s entry at offset %s "
2845 "address list is not properly terminated, "
2846 "ignoring .debug_aranges."),
2847 objfile_name (objfile
),
2848 plongest (entry_addr
- section
->buffer
));
2851 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2853 addr
+= address_size
;
2854 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2856 addr
+= address_size
;
2857 if (start
== 0 && length
== 0)
2859 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
2861 /* Symbol was eliminated due to a COMDAT group. */
2864 ULONGEST end
= start
+ length
;
2865 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2867 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2869 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2873 objfile
->partial_symtabs
->psymtabs_addrmap
2874 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2877 /* Find a slot in the mapped index INDEX for the object named NAME.
2878 If NAME is found, set *VEC_OUT to point to the CU vector in the
2879 constant pool and return true. If NAME cannot be found, return
2883 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2884 offset_type
**vec_out
)
2887 offset_type slot
, step
;
2888 int (*cmp
) (const char *, const char *);
2890 gdb::unique_xmalloc_ptr
<char> without_params
;
2891 if (current_language
->la_language
== language_cplus
2892 || current_language
->la_language
== language_fortran
2893 || current_language
->la_language
== language_d
)
2895 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2898 if (strchr (name
, '(') != NULL
)
2900 without_params
= cp_remove_params (name
);
2902 if (without_params
!= NULL
)
2903 name
= without_params
.get ();
2907 /* Index version 4 did not support case insensitive searches. But the
2908 indices for case insensitive languages are built in lowercase, therefore
2909 simulate our NAME being searched is also lowercased. */
2910 hash
= mapped_index_string_hash ((index
->version
== 4
2911 && case_sensitivity
== case_sensitive_off
2912 ? 5 : index
->version
),
2915 slot
= hash
& (index
->symbol_table
.size () - 1);
2916 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2917 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2923 const auto &bucket
= index
->symbol_table
[slot
];
2924 if (bucket
.name
== 0 && bucket
.vec
== 0)
2927 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2928 if (!cmp (name
, str
))
2930 *vec_out
= (offset_type
*) (index
->constant_pool
2931 + MAYBE_SWAP (bucket
.vec
));
2935 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2939 /* A helper function that reads the .gdb_index from BUFFER and fills
2940 in MAP. FILENAME is the name of the file containing the data;
2941 it is used for error reporting. DEPRECATED_OK is true if it is
2942 ok to use deprecated sections.
2944 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2945 out parameters that are filled in with information about the CU and
2946 TU lists in the section.
2948 Returns true if all went well, false otherwise. */
2951 read_gdb_index_from_buffer (const char *filename
,
2953 gdb::array_view
<const gdb_byte
> buffer
,
2954 struct mapped_index
*map
,
2955 const gdb_byte
**cu_list
,
2956 offset_type
*cu_list_elements
,
2957 const gdb_byte
**types_list
,
2958 offset_type
*types_list_elements
)
2960 const gdb_byte
*addr
= &buffer
[0];
2962 /* Version check. */
2963 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2964 /* Versions earlier than 3 emitted every copy of a psymbol. This
2965 causes the index to behave very poorly for certain requests. Version 3
2966 contained incomplete addrmap. So, it seems better to just ignore such
2970 static int warning_printed
= 0;
2971 if (!warning_printed
)
2973 warning (_("Skipping obsolete .gdb_index section in %s."),
2975 warning_printed
= 1;
2979 /* Index version 4 uses a different hash function than index version
2982 Versions earlier than 6 did not emit psymbols for inlined
2983 functions. Using these files will cause GDB not to be able to
2984 set breakpoints on inlined functions by name, so we ignore these
2985 indices unless the user has done
2986 "set use-deprecated-index-sections on". */
2987 if (version
< 6 && !deprecated_ok
)
2989 static int warning_printed
= 0;
2990 if (!warning_printed
)
2993 Skipping deprecated .gdb_index section in %s.\n\
2994 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2995 to use the section anyway."),
2997 warning_printed
= 1;
3001 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3002 of the TU (for symbols coming from TUs),
3003 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3004 Plus gold-generated indices can have duplicate entries for global symbols,
3005 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3006 These are just performance bugs, and we can't distinguish gdb-generated
3007 indices from gold-generated ones, so issue no warning here. */
3009 /* Indexes with higher version than the one supported by GDB may be no
3010 longer backward compatible. */
3014 map
->version
= version
;
3016 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3019 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3020 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3024 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3025 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3026 - MAYBE_SWAP (metadata
[i
]))
3030 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3031 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3033 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3036 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3037 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3039 = gdb::array_view
<mapped_index::symbol_table_slot
>
3040 ((mapped_index::symbol_table_slot
*) symbol_table
,
3041 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3044 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3049 /* Callback types for dwarf2_read_gdb_index. */
3051 typedef gdb::function_view
3052 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3053 get_gdb_index_contents_ftype
;
3054 typedef gdb::function_view
3055 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3056 get_gdb_index_contents_dwz_ftype
;
3058 /* Read .gdb_index. If everything went ok, initialize the "quick"
3059 elements of all the CUs and return 1. Otherwise, return 0. */
3062 dwarf2_read_gdb_index
3063 (dwarf2_per_objfile
*per_objfile
,
3064 get_gdb_index_contents_ftype get_gdb_index_contents
,
3065 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3067 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3068 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3069 struct dwz_file
*dwz
;
3070 struct objfile
*objfile
= per_objfile
->objfile
;
3071 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3073 gdb::array_view
<const gdb_byte
> main_index_contents
3074 = get_gdb_index_contents (objfile
, per_bfd
);
3076 if (main_index_contents
.empty ())
3079 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3080 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3081 use_deprecated_index_sections
,
3082 main_index_contents
, map
.get (), &cu_list
,
3083 &cu_list_elements
, &types_list
,
3084 &types_list_elements
))
3087 /* Don't use the index if it's empty. */
3088 if (map
->symbol_table
.empty ())
3091 /* If there is a .dwz file, read it so we can get its CU list as
3093 dwz
= dwarf2_get_dwz_file (per_bfd
);
3096 struct mapped_index dwz_map
;
3097 const gdb_byte
*dwz_types_ignore
;
3098 offset_type dwz_types_elements_ignore
;
3100 gdb::array_view
<const gdb_byte
> dwz_index_content
3101 = get_gdb_index_contents_dwz (objfile
, dwz
);
3103 if (dwz_index_content
.empty ())
3106 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3107 1, dwz_index_content
, &dwz_map
,
3108 &dwz_list
, &dwz_list_elements
,
3110 &dwz_types_elements_ignore
))
3112 warning (_("could not read '.gdb_index' section from %s; skipping"),
3113 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3118 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3121 if (types_list_elements
)
3123 /* We can only handle a single .debug_types when we have an
3125 if (per_bfd
->types
.size () != 1)
3128 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3130 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3131 types_list_elements
);
3134 create_addrmap_from_index (per_objfile
, map
.get ());
3136 per_bfd
->index_table
= std::move (map
);
3137 per_bfd
->using_index
= 1;
3138 per_bfd
->quick_file_names_table
=
3139 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3141 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3142 objfiles using the same BFD. */
3143 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3144 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3149 /* die_reader_func for dw2_get_file_names. */
3152 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3153 const gdb_byte
*info_ptr
,
3154 struct die_info
*comp_unit_die
)
3156 struct dwarf2_cu
*cu
= reader
->cu
;
3157 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3158 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3159 struct dwarf2_per_cu_data
*lh_cu
;
3160 struct attribute
*attr
;
3162 struct quick_file_names
*qfn
;
3164 gdb_assert (! this_cu
->is_debug_types
);
3166 /* Our callers never want to match partial units -- instead they
3167 will match the enclosing full CU. */
3168 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3170 this_cu
->v
.quick
->no_file_data
= 1;
3178 sect_offset line_offset
{};
3180 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3181 if (attr
!= nullptr)
3183 struct quick_file_names find_entry
;
3185 line_offset
= (sect_offset
) DW_UNSND (attr
);
3187 /* We may have already read in this line header (TU line header sharing).
3188 If we have we're done. */
3189 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3190 find_entry
.hash
.line_sect_off
= line_offset
;
3191 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3192 &find_entry
, INSERT
);
3195 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3199 lh
= dwarf_decode_line_header (line_offset
, cu
);
3203 lh_cu
->v
.quick
->no_file_data
= 1;
3207 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3208 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3209 qfn
->hash
.line_sect_off
= line_offset
;
3210 gdb_assert (slot
!= NULL
);
3213 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3216 if (strcmp (fnd
.name
, "<unknown>") != 0)
3219 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3221 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3222 qfn
->num_file_names
);
3224 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3225 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3226 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3227 fnd
.comp_dir
).release ();
3228 qfn
->real_names
= NULL
;
3230 lh_cu
->v
.quick
->file_names
= qfn
;
3233 /* A helper for the "quick" functions which attempts to read the line
3234 table for THIS_CU. */
3236 static struct quick_file_names
*
3237 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3238 dwarf2_per_objfile
*per_objfile
)
3240 /* This should never be called for TUs. */
3241 gdb_assert (! this_cu
->is_debug_types
);
3242 /* Nor type unit groups. */
3243 gdb_assert (! this_cu
->type_unit_group_p ());
3245 if (this_cu
->v
.quick
->file_names
!= NULL
)
3246 return this_cu
->v
.quick
->file_names
;
3247 /* If we know there is no line data, no point in looking again. */
3248 if (this_cu
->v
.quick
->no_file_data
)
3251 cutu_reader
reader (this_cu
, per_objfile
);
3252 if (!reader
.dummy_p
)
3253 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3255 if (this_cu
->v
.quick
->no_file_data
)
3257 return this_cu
->v
.quick
->file_names
;
3260 /* A helper for the "quick" functions which computes and caches the
3261 real path for a given file name from the line table. */
3264 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3265 struct quick_file_names
*qfn
, int index
)
3267 if (qfn
->real_names
== NULL
)
3268 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3269 qfn
->num_file_names
, const char *);
3271 if (qfn
->real_names
[index
] == NULL
)
3272 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3274 return qfn
->real_names
[index
];
3277 static struct symtab
*
3278 dw2_find_last_source_symtab (struct objfile
*objfile
)
3280 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3281 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3282 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3287 return compunit_primary_filetab (cust
);
3290 /* Traversal function for dw2_forget_cached_source_info. */
3293 dw2_free_cached_file_names (void **slot
, void *info
)
3295 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3297 if (file_data
->real_names
)
3301 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3303 xfree ((void*) file_data
->real_names
[i
]);
3304 file_data
->real_names
[i
] = NULL
;
3312 dw2_forget_cached_source_info (struct objfile
*objfile
)
3314 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3316 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3317 dw2_free_cached_file_names
, NULL
);
3320 /* Helper function for dw2_map_symtabs_matching_filename that expands
3321 the symtabs and calls the iterator. */
3324 dw2_map_expand_apply (struct objfile
*objfile
,
3325 struct dwarf2_per_cu_data
*per_cu
,
3326 const char *name
, const char *real_path
,
3327 gdb::function_view
<bool (symtab
*)> callback
)
3329 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3331 /* Don't visit already-expanded CUs. */
3332 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3333 if (per_objfile
->symtab_set_p (per_cu
))
3336 /* This may expand more than one symtab, and we want to iterate over
3338 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3340 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3341 last_made
, callback
);
3344 /* Implementation of the map_symtabs_matching_filename method. */
3347 dw2_map_symtabs_matching_filename
3348 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3349 gdb::function_view
<bool (symtab
*)> callback
)
3351 const char *name_basename
= lbasename (name
);
3352 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3354 /* The rule is CUs specify all the files, including those used by
3355 any TU, so there's no need to scan TUs here. */
3357 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3359 /* We only need to look at symtabs not already expanded. */
3360 if (per_objfile
->symtab_set_p (per_cu
))
3363 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3364 if (file_data
== NULL
)
3367 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3369 const char *this_name
= file_data
->file_names
[j
];
3370 const char *this_real_name
;
3372 if (compare_filenames_for_search (this_name
, name
))
3374 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3380 /* Before we invoke realpath, which can get expensive when many
3381 files are involved, do a quick comparison of the basenames. */
3382 if (! basenames_may_differ
3383 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3386 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3387 if (compare_filenames_for_search (this_real_name
, name
))
3389 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3395 if (real_path
!= NULL
)
3397 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3398 gdb_assert (IS_ABSOLUTE_PATH (name
));
3399 if (this_real_name
!= NULL
3400 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3402 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3414 /* Struct used to manage iterating over all CUs looking for a symbol. */
3416 struct dw2_symtab_iterator
3418 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3419 dwarf2_per_objfile
*per_objfile
;
3420 /* If set, only look for symbols that match that block. Valid values are
3421 GLOBAL_BLOCK and STATIC_BLOCK. */
3422 gdb::optional
<block_enum
> block_index
;
3423 /* The kind of symbol we're looking for. */
3425 /* The list of CUs from the index entry of the symbol,
3426 or NULL if not found. */
3428 /* The next element in VEC to look at. */
3430 /* The number of elements in VEC, or zero if there is no match. */
3432 /* Have we seen a global version of the symbol?
3433 If so we can ignore all further global instances.
3434 This is to work around gold/15646, inefficient gold-generated
3439 /* Initialize the index symtab iterator ITER. */
3442 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3443 dwarf2_per_objfile
*per_objfile
,
3444 gdb::optional
<block_enum
> block_index
,
3448 iter
->per_objfile
= per_objfile
;
3449 iter
->block_index
= block_index
;
3450 iter
->domain
= domain
;
3452 iter
->global_seen
= 0;
3454 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3456 /* index is NULL if OBJF_READNOW. */
3457 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3458 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3466 /* Return the next matching CU or NULL if there are no more. */
3468 static struct dwarf2_per_cu_data
*
3469 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3471 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3473 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3475 offset_type cu_index_and_attrs
=
3476 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3477 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3478 gdb_index_symbol_kind symbol_kind
=
3479 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3480 /* Only check the symbol attributes if they're present.
3481 Indices prior to version 7 don't record them,
3482 and indices >= 7 may elide them for certain symbols
3483 (gold does this). */
3485 (per_objfile
->per_bfd
->index_table
->version
>= 7
3486 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3488 /* Don't crash on bad data. */
3489 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3490 + per_objfile
->per_bfd
->all_type_units
.size ()))
3492 complaint (_(".gdb_index entry has bad CU index"
3493 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3497 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3499 /* Skip if already read in. */
3500 if (per_objfile
->symtab_set_p (per_cu
))
3503 /* Check static vs global. */
3506 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3508 if (iter
->block_index
.has_value ())
3510 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3512 if (is_static
!= want_static
)
3516 /* Work around gold/15646. */
3518 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3520 if (iter
->global_seen
)
3523 iter
->global_seen
= 1;
3527 /* Only check the symbol's kind if it has one. */
3530 switch (iter
->domain
)
3533 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3534 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3535 /* Some types are also in VAR_DOMAIN. */
3536 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3540 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3544 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3548 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3563 static struct compunit_symtab
*
3564 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3565 const char *name
, domain_enum domain
)
3567 struct compunit_symtab
*stab_best
= NULL
;
3568 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3570 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3572 struct dw2_symtab_iterator iter
;
3573 struct dwarf2_per_cu_data
*per_cu
;
3575 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3577 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3579 struct symbol
*sym
, *with_opaque
= NULL
;
3580 struct compunit_symtab
*stab
3581 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3582 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3583 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3585 sym
= block_find_symbol (block
, name
, domain
,
3586 block_find_non_opaque_type_preferred
,
3589 /* Some caution must be observed with overloaded functions
3590 and methods, since the index will not contain any overload
3591 information (but NAME might contain it). */
3594 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3596 if (with_opaque
!= NULL
3597 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3600 /* Keep looking through other CUs. */
3607 dw2_print_stats (struct objfile
*objfile
)
3609 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3610 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3611 + per_objfile
->per_bfd
->all_type_units
.size ());
3614 for (int i
= 0; i
< total
; ++i
)
3616 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3618 if (!per_objfile
->symtab_set_p (per_cu
))
3621 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3622 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3625 /* This dumps minimal information about the index.
3626 It is called via "mt print objfiles".
3627 One use is to verify .gdb_index has been loaded by the
3628 gdb.dwarf2/gdb-index.exp testcase. */
3631 dw2_dump (struct objfile
*objfile
)
3633 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3635 gdb_assert (per_objfile
->per_bfd
->using_index
);
3636 printf_filtered (".gdb_index:");
3637 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3639 printf_filtered (" version %d\n",
3640 per_objfile
->per_bfd
->index_table
->version
);
3643 printf_filtered (" faked for \"readnow\"\n");
3644 printf_filtered ("\n");
3648 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3649 const char *func_name
)
3651 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3653 struct dw2_symtab_iterator iter
;
3654 struct dwarf2_per_cu_data
*per_cu
;
3656 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3658 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3659 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3664 dw2_expand_all_symtabs (struct objfile
*objfile
)
3666 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3667 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3668 + per_objfile
->per_bfd
->all_type_units
.size ());
3670 for (int i
= 0; i
< total_units
; ++i
)
3672 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3674 /* We don't want to directly expand a partial CU, because if we
3675 read it with the wrong language, then assertion failures can
3676 be triggered later on. See PR symtab/23010. So, tell
3677 dw2_instantiate_symtab to skip partial CUs -- any important
3678 partial CU will be read via DW_TAG_imported_unit anyway. */
3679 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3684 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3685 const char *fullname
)
3687 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3689 /* We don't need to consider type units here.
3690 This is only called for examining code, e.g. expand_line_sal.
3691 There can be an order of magnitude (or more) more type units
3692 than comp units, and we avoid them if we can. */
3694 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3696 /* We only need to look at symtabs not already expanded. */
3697 if (per_objfile
->symtab_set_p (per_cu
))
3700 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3701 if (file_data
== NULL
)
3704 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3706 const char *this_fullname
= file_data
->file_names
[j
];
3708 if (filename_cmp (this_fullname
, fullname
) == 0)
3710 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3718 dw2_expand_symtabs_matching_symbol
3719 (mapped_index_base
&index
,
3720 const lookup_name_info
&lookup_name_in
,
3721 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3722 enum search_domain kind
,
3723 gdb::function_view
<bool (offset_type
)> match_callback
,
3724 dwarf2_per_objfile
*per_objfile
);
3727 dw2_expand_symtabs_matching_one
3728 (dwarf2_per_cu_data
*per_cu
,
3729 dwarf2_per_objfile
*per_objfile
,
3730 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3731 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3734 dw2_map_matching_symbols
3735 (struct objfile
*objfile
,
3736 const lookup_name_info
&name
, domain_enum domain
,
3738 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3739 symbol_compare_ftype
*ordered_compare
)
3742 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3744 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3746 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3748 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3749 here though if the current language is Ada for a non-Ada objfile
3751 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3753 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3754 auto matcher
= [&] (const char *symname
)
3756 if (ordered_compare
== nullptr)
3758 return ordered_compare (symname
, match_name
) == 0;
3761 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3762 [&] (offset_type namei
)
3764 struct dw2_symtab_iterator iter
;
3765 struct dwarf2_per_cu_data
*per_cu
;
3767 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3769 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3770 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3777 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3778 proceed assuming all symtabs have been read in. */
3781 for (compunit_symtab
*cust
: objfile
->compunits ())
3783 const struct block
*block
;
3787 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3788 if (!iterate_over_symbols_terminated (block
, name
,
3794 /* Starting from a search name, return the string that finds the upper
3795 bound of all strings that start with SEARCH_NAME in a sorted name
3796 list. Returns the empty string to indicate that the upper bound is
3797 the end of the list. */
3800 make_sort_after_prefix_name (const char *search_name
)
3802 /* When looking to complete "func", we find the upper bound of all
3803 symbols that start with "func" by looking for where we'd insert
3804 the closest string that would follow "func" in lexicographical
3805 order. Usually, that's "func"-with-last-character-incremented,
3806 i.e. "fund". Mind non-ASCII characters, though. Usually those
3807 will be UTF-8 multi-byte sequences, but we can't be certain.
3808 Especially mind the 0xff character, which is a valid character in
3809 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3810 rule out compilers allowing it in identifiers. Note that
3811 conveniently, strcmp/strcasecmp are specified to compare
3812 characters interpreted as unsigned char. So what we do is treat
3813 the whole string as a base 256 number composed of a sequence of
3814 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3815 to 0, and carries 1 to the following more-significant position.
3816 If the very first character in SEARCH_NAME ends up incremented
3817 and carries/overflows, then the upper bound is the end of the
3818 list. The string after the empty string is also the empty
3821 Some examples of this operation:
3823 SEARCH_NAME => "+1" RESULT
3827 "\xff" "a" "\xff" => "\xff" "b"
3832 Then, with these symbols for example:
3838 completing "func" looks for symbols between "func" and
3839 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3840 which finds "func" and "func1", but not "fund".
3844 funcÿ (Latin1 'ÿ' [0xff])
3848 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3849 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3853 ÿÿ (Latin1 'ÿ' [0xff])
3856 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3857 the end of the list.
3859 std::string after
= search_name
;
3860 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3862 if (!after
.empty ())
3863 after
.back () = (unsigned char) after
.back () + 1;
3867 /* See declaration. */
3869 std::pair
<std::vector
<name_component
>::const_iterator
,
3870 std::vector
<name_component
>::const_iterator
>
3871 mapped_index_base::find_name_components_bounds
3872 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3873 dwarf2_per_objfile
*per_objfile
) const
3876 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3878 const char *lang_name
3879 = lookup_name_without_params
.language_lookup_name (lang
);
3881 /* Comparison function object for lower_bound that matches against a
3882 given symbol name. */
3883 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3886 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3887 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3888 return name_cmp (elem_name
, name
) < 0;
3891 /* Comparison function object for upper_bound that matches against a
3892 given symbol name. */
3893 auto lookup_compare_upper
= [&] (const char *name
,
3894 const name_component
&elem
)
3896 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3897 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3898 return name_cmp (name
, elem_name
) < 0;
3901 auto begin
= this->name_components
.begin ();
3902 auto end
= this->name_components
.end ();
3904 /* Find the lower bound. */
3907 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3910 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3913 /* Find the upper bound. */
3916 if (lookup_name_without_params
.completion_mode ())
3918 /* In completion mode, we want UPPER to point past all
3919 symbols names that have the same prefix. I.e., with
3920 these symbols, and completing "func":
3922 function << lower bound
3924 other_function << upper bound
3926 We find the upper bound by looking for the insertion
3927 point of "func"-with-last-character-incremented,
3929 std::string after
= make_sort_after_prefix_name (lang_name
);
3932 return std::lower_bound (lower
, end
, after
.c_str (),
3933 lookup_compare_lower
);
3936 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3939 return {lower
, upper
};
3942 /* See declaration. */
3945 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3947 if (!this->name_components
.empty ())
3950 this->name_components_casing
= case_sensitivity
;
3952 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3954 /* The code below only knows how to break apart components of C++
3955 symbol names (and other languages that use '::' as
3956 namespace/module separator) and Ada symbol names. */
3957 auto count
= this->symbol_name_count ();
3958 for (offset_type idx
= 0; idx
< count
; idx
++)
3960 if (this->symbol_name_slot_invalid (idx
))
3963 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3965 /* Add each name component to the name component table. */
3966 unsigned int previous_len
= 0;
3968 if (strstr (name
, "::") != nullptr)
3970 for (unsigned int current_len
= cp_find_first_component (name
);
3971 name
[current_len
] != '\0';
3972 current_len
+= cp_find_first_component (name
+ current_len
))
3974 gdb_assert (name
[current_len
] == ':');
3975 this->name_components
.push_back ({previous_len
, idx
});
3976 /* Skip the '::'. */
3978 previous_len
= current_len
;
3983 /* Handle the Ada encoded (aka mangled) form here. */
3984 for (const char *iter
= strstr (name
, "__");
3986 iter
= strstr (iter
, "__"))
3988 this->name_components
.push_back ({previous_len
, idx
});
3990 previous_len
= iter
- name
;
3994 this->name_components
.push_back ({previous_len
, idx
});
3997 /* Sort name_components elements by name. */
3998 auto name_comp_compare
= [&] (const name_component
&left
,
3999 const name_component
&right
)
4001 const char *left_qualified
4002 = this->symbol_name_at (left
.idx
, per_objfile
);
4003 const char *right_qualified
4004 = this->symbol_name_at (right
.idx
, per_objfile
);
4006 const char *left_name
= left_qualified
+ left
.name_offset
;
4007 const char *right_name
= right_qualified
+ right
.name_offset
;
4009 return name_cmp (left_name
, right_name
) < 0;
4012 std::sort (this->name_components
.begin (),
4013 this->name_components
.end (),
4017 /* Helper for dw2_expand_symtabs_matching that works with a
4018 mapped_index_base instead of the containing objfile. This is split
4019 to a separate function in order to be able to unit test the
4020 name_components matching using a mock mapped_index_base. For each
4021 symbol name that matches, calls MATCH_CALLBACK, passing it the
4022 symbol's index in the mapped_index_base symbol table. */
4025 dw2_expand_symtabs_matching_symbol
4026 (mapped_index_base
&index
,
4027 const lookup_name_info
&lookup_name_in
,
4028 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4029 enum search_domain kind
,
4030 gdb::function_view
<bool (offset_type
)> match_callback
,
4031 dwarf2_per_objfile
*per_objfile
)
4033 lookup_name_info lookup_name_without_params
4034 = lookup_name_in
.make_ignore_params ();
4036 /* Build the symbol name component sorted vector, if we haven't
4038 index
.build_name_components (per_objfile
);
4040 /* The same symbol may appear more than once in the range though.
4041 E.g., if we're looking for symbols that complete "w", and we have
4042 a symbol named "w1::w2", we'll find the two name components for
4043 that same symbol in the range. To be sure we only call the
4044 callback once per symbol, we first collect the symbol name
4045 indexes that matched in a temporary vector and ignore
4047 std::vector
<offset_type
> matches
;
4049 struct name_and_matcher
4051 symbol_name_matcher_ftype
*matcher
;
4054 bool operator== (const name_and_matcher
&other
) const
4056 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4060 /* A vector holding all the different symbol name matchers, for all
4062 std::vector
<name_and_matcher
> matchers
;
4064 for (int i
= 0; i
< nr_languages
; i
++)
4066 enum language lang_e
= (enum language
) i
;
4068 const language_defn
*lang
= language_def (lang_e
);
4069 symbol_name_matcher_ftype
*name_matcher
4070 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4072 name_and_matcher key
{
4074 lookup_name_without_params
.language_lookup_name (lang_e
)
4077 /* Don't insert the same comparison routine more than once.
4078 Note that we do this linear walk. This is not a problem in
4079 practice because the number of supported languages is
4081 if (std::find (matchers
.begin (), matchers
.end (), key
)
4084 matchers
.push_back (std::move (key
));
4087 = index
.find_name_components_bounds (lookup_name_without_params
,
4088 lang_e
, per_objfile
);
4090 /* Now for each symbol name in range, check to see if we have a name
4091 match, and if so, call the MATCH_CALLBACK callback. */
4093 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4095 const char *qualified
4096 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4098 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4099 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4102 matches
.push_back (bounds
.first
->idx
);
4106 std::sort (matches
.begin (), matches
.end ());
4108 /* Finally call the callback, once per match. */
4110 for (offset_type idx
: matches
)
4114 if (!match_callback (idx
))
4120 /* Above we use a type wider than idx's for 'prev', since 0 and
4121 (offset_type)-1 are both possible values. */
4122 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4127 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4129 /* A mock .gdb_index/.debug_names-like name index table, enough to
4130 exercise dw2_expand_symtabs_matching_symbol, which works with the
4131 mapped_index_base interface. Builds an index from the symbol list
4132 passed as parameter to the constructor. */
4133 class mock_mapped_index
: public mapped_index_base
4136 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4137 : m_symbol_table (symbols
)
4140 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4142 /* Return the number of names in the symbol table. */
4143 size_t symbol_name_count () const override
4145 return m_symbol_table
.size ();
4148 /* Get the name of the symbol at IDX in the symbol table. */
4149 const char *symbol_name_at
4150 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4152 return m_symbol_table
[idx
];
4156 gdb::array_view
<const char *> m_symbol_table
;
4159 /* Convenience function that converts a NULL pointer to a "<null>"
4160 string, to pass to print routines. */
4163 string_or_null (const char *str
)
4165 return str
!= NULL
? str
: "<null>";
4168 /* Check if a lookup_name_info built from
4169 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4170 index. EXPECTED_LIST is the list of expected matches, in expected
4171 matching order. If no match expected, then an empty list is
4172 specified. Returns true on success. On failure prints a warning
4173 indicating the file:line that failed, and returns false. */
4176 check_match (const char *file
, int line
,
4177 mock_mapped_index
&mock_index
,
4178 const char *name
, symbol_name_match_type match_type
,
4179 bool completion_mode
,
4180 std::initializer_list
<const char *> expected_list
,
4181 dwarf2_per_objfile
*per_objfile
)
4183 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4185 bool matched
= true;
4187 auto mismatch
= [&] (const char *expected_str
,
4190 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4191 "expected=\"%s\", got=\"%s\"\n"),
4193 (match_type
== symbol_name_match_type::FULL
4195 name
, string_or_null (expected_str
), string_or_null (got
));
4199 auto expected_it
= expected_list
.begin ();
4200 auto expected_end
= expected_list
.end ();
4202 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4204 [&] (offset_type idx
)
4206 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4207 const char *expected_str
4208 = expected_it
== expected_end
? NULL
: *expected_it
++;
4210 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4211 mismatch (expected_str
, matched_name
);
4215 const char *expected_str
4216 = expected_it
== expected_end
? NULL
: *expected_it
++;
4217 if (expected_str
!= NULL
)
4218 mismatch (expected_str
, NULL
);
4223 /* The symbols added to the mock mapped_index for testing (in
4225 static const char *test_symbols
[] = {
4234 "ns2::tmpl<int>::foo2",
4235 "(anonymous namespace)::A::B::C",
4237 /* These are used to check that the increment-last-char in the
4238 matching algorithm for completion doesn't match "t1_fund" when
4239 completing "t1_func". */
4245 /* A UTF-8 name with multi-byte sequences to make sure that
4246 cp-name-parser understands this as a single identifier ("função"
4247 is "function" in PT). */
4250 /* \377 (0xff) is Latin1 'ÿ'. */
4253 /* \377 (0xff) is Latin1 'ÿ'. */
4257 /* A name with all sorts of complications. Starts with "z" to make
4258 it easier for the completion tests below. */
4259 #define Z_SYM_NAME \
4260 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4261 "::tuple<(anonymous namespace)::ui*, " \
4262 "std::default_delete<(anonymous namespace)::ui>, void>"
4267 /* Returns true if the mapped_index_base::find_name_component_bounds
4268 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4269 in completion mode. */
4272 check_find_bounds_finds (mapped_index_base
&index
,
4273 const char *search_name
,
4274 gdb::array_view
<const char *> expected_syms
,
4275 dwarf2_per_objfile
*per_objfile
)
4277 lookup_name_info
lookup_name (search_name
,
4278 symbol_name_match_type::FULL
, true);
4280 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4284 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4285 if (distance
!= expected_syms
.size ())
4288 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4290 auto nc_elem
= bounds
.first
+ exp_elem
;
4291 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4292 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4299 /* Test the lower-level mapped_index::find_name_component_bounds
4303 test_mapped_index_find_name_component_bounds ()
4305 mock_mapped_index
mock_index (test_symbols
);
4307 mock_index
.build_name_components (NULL
/* per_objfile */);
4309 /* Test the lower-level mapped_index::find_name_component_bounds
4310 method in completion mode. */
4312 static const char *expected_syms
[] = {
4317 SELF_CHECK (check_find_bounds_finds
4318 (mock_index
, "t1_func", expected_syms
,
4319 NULL
/* per_objfile */));
4322 /* Check that the increment-last-char in the name matching algorithm
4323 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4325 static const char *expected_syms1
[] = {
4329 SELF_CHECK (check_find_bounds_finds
4330 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4332 static const char *expected_syms2
[] = {
4335 SELF_CHECK (check_find_bounds_finds
4336 (mock_index
, "\377\377", expected_syms2
,
4337 NULL
/* per_objfile */));
4341 /* Test dw2_expand_symtabs_matching_symbol. */
4344 test_dw2_expand_symtabs_matching_symbol ()
4346 mock_mapped_index
mock_index (test_symbols
);
4348 /* We let all tests run until the end even if some fails, for debug
4350 bool any_mismatch
= false;
4352 /* Create the expected symbols list (an initializer_list). Needed
4353 because lists have commas, and we need to pass them to CHECK,
4354 which is a macro. */
4355 #define EXPECT(...) { __VA_ARGS__ }
4357 /* Wrapper for check_match that passes down the current
4358 __FILE__/__LINE__. */
4359 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4360 any_mismatch |= !check_match (__FILE__, __LINE__, \
4362 NAME, MATCH_TYPE, COMPLETION_MODE, \
4363 EXPECTED_LIST, NULL)
4365 /* Identity checks. */
4366 for (const char *sym
: test_symbols
)
4368 /* Should be able to match all existing symbols. */
4369 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4372 /* Should be able to match all existing symbols with
4374 std::string with_params
= std::string (sym
) + "(int)";
4375 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4378 /* Should be able to match all existing symbols with
4379 parameters and qualifiers. */
4380 with_params
= std::string (sym
) + " ( int ) const";
4381 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4384 /* This should really find sym, but cp-name-parser.y doesn't
4385 know about lvalue/rvalue qualifiers yet. */
4386 with_params
= std::string (sym
) + " ( int ) &&";
4387 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4391 /* Check that the name matching algorithm for completion doesn't get
4392 confused with Latin1 'ÿ' / 0xff. */
4394 static const char str
[] = "\377";
4395 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4396 EXPECT ("\377", "\377\377123"));
4399 /* Check that the increment-last-char in the matching algorithm for
4400 completion doesn't match "t1_fund" when completing "t1_func". */
4402 static const char str
[] = "t1_func";
4403 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4404 EXPECT ("t1_func", "t1_func1"));
4407 /* Check that completion mode works at each prefix of the expected
4410 static const char str
[] = "function(int)";
4411 size_t len
= strlen (str
);
4414 for (size_t i
= 1; i
< len
; i
++)
4416 lookup
.assign (str
, i
);
4417 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4418 EXPECT ("function"));
4422 /* While "w" is a prefix of both components, the match function
4423 should still only be called once. */
4425 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4427 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4431 /* Same, with a "complicated" symbol. */
4433 static const char str
[] = Z_SYM_NAME
;
4434 size_t len
= strlen (str
);
4437 for (size_t i
= 1; i
< len
; i
++)
4439 lookup
.assign (str
, i
);
4440 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4441 EXPECT (Z_SYM_NAME
));
4445 /* In FULL mode, an incomplete symbol doesn't match. */
4447 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4451 /* A complete symbol with parameters matches any overload, since the
4452 index has no overload info. */
4454 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4455 EXPECT ("std::zfunction", "std::zfunction2"));
4456 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4457 EXPECT ("std::zfunction", "std::zfunction2"));
4458 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4459 EXPECT ("std::zfunction", "std::zfunction2"));
4462 /* Check that whitespace is ignored appropriately. A symbol with a
4463 template argument list. */
4465 static const char expected
[] = "ns::foo<int>";
4466 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4468 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4472 /* Check that whitespace is ignored appropriately. A symbol with a
4473 template argument list that includes a pointer. */
4475 static const char expected
[] = "ns::foo<char*>";
4476 /* Try both completion and non-completion modes. */
4477 static const bool completion_mode
[2] = {false, true};
4478 for (size_t i
= 0; i
< 2; i
++)
4480 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4481 completion_mode
[i
], EXPECT (expected
));
4482 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4483 completion_mode
[i
], EXPECT (expected
));
4485 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4486 completion_mode
[i
], EXPECT (expected
));
4487 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4488 completion_mode
[i
], EXPECT (expected
));
4493 /* Check method qualifiers are ignored. */
4494 static const char expected
[] = "ns::foo<char*>";
4495 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4496 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4497 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4498 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4499 CHECK_MATCH ("foo < char * > ( int ) const",
4500 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4501 CHECK_MATCH ("foo < char * > ( int ) &&",
4502 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4505 /* Test lookup names that don't match anything. */
4507 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4510 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4514 /* Some wild matching tests, exercising "(anonymous namespace)",
4515 which should not be confused with a parameter list. */
4517 static const char *syms
[] = {
4521 "A :: B :: C ( int )",
4526 for (const char *s
: syms
)
4528 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4529 EXPECT ("(anonymous namespace)::A::B::C"));
4534 static const char expected
[] = "ns2::tmpl<int>::foo2";
4535 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4537 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4541 SELF_CHECK (!any_mismatch
);
4550 test_mapped_index_find_name_component_bounds ();
4551 test_dw2_expand_symtabs_matching_symbol ();
4554 }} // namespace selftests::dw2_expand_symtabs_matching
4556 #endif /* GDB_SELF_TEST */
4558 /* If FILE_MATCHER is NULL or if PER_CU has
4559 dwarf2_per_cu_quick_data::MARK set (see
4560 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4561 EXPANSION_NOTIFY on it. */
4564 dw2_expand_symtabs_matching_one
4565 (dwarf2_per_cu_data
*per_cu
,
4566 dwarf2_per_objfile
*per_objfile
,
4567 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4568 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4570 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4572 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4574 compunit_symtab
*symtab
4575 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4576 gdb_assert (symtab
!= nullptr);
4578 if (expansion_notify
!= NULL
&& symtab_was_null
)
4579 expansion_notify (symtab
);
4583 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4584 matched, to expand corresponding CUs that were marked. IDX is the
4585 index of the symbol name that matched. */
4588 dw2_expand_marked_cus
4589 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4590 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4591 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4594 offset_type
*vec
, vec_len
, vec_idx
;
4595 bool global_seen
= false;
4596 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4598 vec
= (offset_type
*) (index
.constant_pool
4599 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4600 vec_len
= MAYBE_SWAP (vec
[0]);
4601 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4603 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4604 /* This value is only valid for index versions >= 7. */
4605 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4606 gdb_index_symbol_kind symbol_kind
=
4607 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4608 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4609 /* Only check the symbol attributes if they're present.
4610 Indices prior to version 7 don't record them,
4611 and indices >= 7 may elide them for certain symbols
4612 (gold does this). */
4615 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4617 /* Work around gold/15646. */
4620 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4628 /* Only check the symbol's kind if it has one. */
4633 case VARIABLES_DOMAIN
:
4634 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4637 case FUNCTIONS_DOMAIN
:
4638 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4642 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4645 case MODULES_DOMAIN
:
4646 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4654 /* Don't crash on bad data. */
4655 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4656 + per_objfile
->per_bfd
->all_type_units
.size ()))
4658 complaint (_(".gdb_index entry has bad CU index"
4659 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4663 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4664 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4669 /* If FILE_MATCHER is non-NULL, set all the
4670 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4671 that match FILE_MATCHER. */
4674 dw_expand_symtabs_matching_file_matcher
4675 (dwarf2_per_objfile
*per_objfile
,
4676 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4678 if (file_matcher
== NULL
)
4681 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4683 NULL
, xcalloc
, xfree
));
4684 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4686 NULL
, xcalloc
, xfree
));
4688 /* The rule is CUs specify all the files, including those used by
4689 any TU, so there's no need to scan TUs here. */
4691 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4695 per_cu
->v
.quick
->mark
= 0;
4697 /* We only need to look at symtabs not already expanded. */
4698 if (per_objfile
->symtab_set_p (per_cu
))
4701 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4702 if (file_data
== NULL
)
4705 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4707 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4709 per_cu
->v
.quick
->mark
= 1;
4713 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4715 const char *this_real_name
;
4717 if (file_matcher (file_data
->file_names
[j
], false))
4719 per_cu
->v
.quick
->mark
= 1;
4723 /* Before we invoke realpath, which can get expensive when many
4724 files are involved, do a quick comparison of the basenames. */
4725 if (!basenames_may_differ
4726 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4730 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4731 if (file_matcher (this_real_name
, false))
4733 per_cu
->v
.quick
->mark
= 1;
4738 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4739 ? visited_found
.get ()
4740 : visited_not_found
.get (),
4747 dw2_expand_symtabs_matching
4748 (struct objfile
*objfile
,
4749 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4750 const lookup_name_info
*lookup_name
,
4751 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4752 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4753 enum search_domain kind
)
4755 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4757 /* index_table is NULL if OBJF_READNOW. */
4758 if (!per_objfile
->per_bfd
->index_table
)
4761 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4763 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4765 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4769 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4770 file_matcher
, expansion_notify
);
4775 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4777 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4779 kind
, [&] (offset_type idx
)
4781 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4787 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4790 static struct compunit_symtab
*
4791 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4796 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4797 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4800 if (cust
->includes
== NULL
)
4803 for (i
= 0; cust
->includes
[i
]; ++i
)
4805 struct compunit_symtab
*s
= cust
->includes
[i
];
4807 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4815 static struct compunit_symtab
*
4816 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4817 struct bound_minimal_symbol msymbol
,
4819 struct obj_section
*section
,
4822 struct dwarf2_per_cu_data
*data
;
4823 struct compunit_symtab
*result
;
4825 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4828 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4829 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4830 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4834 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4835 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4836 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4837 paddress (objfile
->arch (), pc
));
4839 result
= recursively_find_pc_sect_compunit_symtab
4840 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4842 gdb_assert (result
!= NULL
);
4847 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4848 void *data
, int need_fullname
)
4850 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4852 if (!per_objfile
->per_bfd
->filenames_cache
)
4854 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4856 htab_up
visited (htab_create_alloc (10,
4857 htab_hash_pointer
, htab_eq_pointer
,
4858 NULL
, xcalloc
, xfree
));
4860 /* The rule is CUs specify all the files, including those used
4861 by any TU, so there's no need to scan TUs here. We can
4862 ignore file names coming from already-expanded CUs. */
4864 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4866 if (per_objfile
->symtab_set_p (per_cu
))
4868 void **slot
= htab_find_slot (visited
.get (),
4869 per_cu
->v
.quick
->file_names
,
4872 *slot
= per_cu
->v
.quick
->file_names
;
4876 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4878 /* We only need to look at symtabs not already expanded. */
4879 if (per_objfile
->symtab_set_p (per_cu
))
4882 quick_file_names
*file_data
4883 = dw2_get_file_names (per_cu
, per_objfile
);
4884 if (file_data
== NULL
)
4887 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4890 /* Already visited. */
4895 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4897 const char *filename
= file_data
->file_names
[j
];
4898 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4903 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4905 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4908 this_real_name
= gdb_realpath (filename
);
4909 (*fun
) (filename
, this_real_name
.get (), data
);
4914 dw2_has_symbols (struct objfile
*objfile
)
4919 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4922 dw2_find_last_source_symtab
,
4923 dw2_forget_cached_source_info
,
4924 dw2_map_symtabs_matching_filename
,
4929 dw2_expand_symtabs_for_function
,
4930 dw2_expand_all_symtabs
,
4931 dw2_expand_symtabs_with_fullname
,
4932 dw2_map_matching_symbols
,
4933 dw2_expand_symtabs_matching
,
4934 dw2_find_pc_sect_compunit_symtab
,
4936 dw2_map_symbol_filenames
4939 /* DWARF-5 debug_names reader. */
4941 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4942 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4944 /* A helper function that reads the .debug_names section in SECTION
4945 and fills in MAP. FILENAME is the name of the file containing the
4946 section; it is used for error reporting.
4948 Returns true if all went well, false otherwise. */
4951 read_debug_names_from_section (struct objfile
*objfile
,
4952 const char *filename
,
4953 struct dwarf2_section_info
*section
,
4954 mapped_debug_names
&map
)
4956 if (section
->empty ())
4959 /* Older elfutils strip versions could keep the section in the main
4960 executable while splitting it for the separate debug info file. */
4961 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4964 section
->read (objfile
);
4966 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4968 const gdb_byte
*addr
= section
->buffer
;
4970 bfd
*const abfd
= section
->get_bfd_owner ();
4972 unsigned int bytes_read
;
4973 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4976 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4977 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4978 if (bytes_read
+ length
!= section
->size
)
4980 /* There may be multiple per-CU indices. */
4981 warning (_("Section .debug_names in %s length %s does not match "
4982 "section length %s, ignoring .debug_names."),
4983 filename
, plongest (bytes_read
+ length
),
4984 pulongest (section
->size
));
4988 /* The version number. */
4989 uint16_t version
= read_2_bytes (abfd
, addr
);
4993 warning (_("Section .debug_names in %s has unsupported version %d, "
4994 "ignoring .debug_names."),
5000 uint16_t padding
= read_2_bytes (abfd
, addr
);
5004 warning (_("Section .debug_names in %s has unsupported padding %d, "
5005 "ignoring .debug_names."),
5010 /* comp_unit_count - The number of CUs in the CU list. */
5011 map
.cu_count
= read_4_bytes (abfd
, addr
);
5014 /* local_type_unit_count - The number of TUs in the local TU
5016 map
.tu_count
= read_4_bytes (abfd
, addr
);
5019 /* foreign_type_unit_count - The number of TUs in the foreign TU
5021 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5023 if (foreign_tu_count
!= 0)
5025 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5026 "ignoring .debug_names."),
5027 filename
, static_cast<unsigned long> (foreign_tu_count
));
5031 /* bucket_count - The number of hash buckets in the hash lookup
5033 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5036 /* name_count - The number of unique names in the index. */
5037 map
.name_count
= read_4_bytes (abfd
, addr
);
5040 /* abbrev_table_size - The size in bytes of the abbreviations
5042 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5045 /* augmentation_string_size - The size in bytes of the augmentation
5046 string. This value is rounded up to a multiple of 4. */
5047 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5049 map
.augmentation_is_gdb
= ((augmentation_string_size
5050 == sizeof (dwarf5_augmentation
))
5051 && memcmp (addr
, dwarf5_augmentation
,
5052 sizeof (dwarf5_augmentation
)) == 0);
5053 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5054 addr
+= augmentation_string_size
;
5057 map
.cu_table_reordered
= addr
;
5058 addr
+= map
.cu_count
* map
.offset_size
;
5060 /* List of Local TUs */
5061 map
.tu_table_reordered
= addr
;
5062 addr
+= map
.tu_count
* map
.offset_size
;
5064 /* Hash Lookup Table */
5065 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5066 addr
+= map
.bucket_count
* 4;
5067 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5068 addr
+= map
.name_count
* 4;
5071 map
.name_table_string_offs_reordered
= addr
;
5072 addr
+= map
.name_count
* map
.offset_size
;
5073 map
.name_table_entry_offs_reordered
= addr
;
5074 addr
+= map
.name_count
* map
.offset_size
;
5076 const gdb_byte
*abbrev_table_start
= addr
;
5079 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5084 const auto insertpair
5085 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5086 if (!insertpair
.second
)
5088 warning (_("Section .debug_names in %s has duplicate index %s, "
5089 "ignoring .debug_names."),
5090 filename
, pulongest (index_num
));
5093 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5094 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5099 mapped_debug_names::index_val::attr attr
;
5100 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5102 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5104 if (attr
.form
== DW_FORM_implicit_const
)
5106 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5110 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5112 indexval
.attr_vec
.push_back (std::move (attr
));
5115 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5117 warning (_("Section .debug_names in %s has abbreviation_table "
5118 "of size %s vs. written as %u, ignoring .debug_names."),
5119 filename
, plongest (addr
- abbrev_table_start
),
5123 map
.entry_pool
= addr
;
5128 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5132 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5133 const mapped_debug_names
&map
,
5134 dwarf2_section_info
§ion
,
5137 if (!map
.augmentation_is_gdb
)
5139 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5141 sect_offset sect_off
5142 = (sect_offset
) (extract_unsigned_integer
5143 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5145 map
.dwarf5_byte_order
));
5146 /* We don't know the length of the CU, because the CU list in a
5147 .debug_names index can be incomplete, so we can't use the start of
5148 the next CU as end of this CU. We create the CUs here with length 0,
5149 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5150 dwarf2_per_cu_data
*per_cu
5151 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5152 per_bfd
->all_comp_units
.push_back (per_cu
);
5156 sect_offset sect_off_prev
;
5157 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5159 sect_offset sect_off_next
;
5160 if (i
< map
.cu_count
)
5163 = (sect_offset
) (extract_unsigned_integer
5164 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5166 map
.dwarf5_byte_order
));
5169 sect_off_next
= (sect_offset
) section
.size
;
5172 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5173 dwarf2_per_cu_data
*per_cu
5174 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5175 sect_off_prev
, length
);
5176 per_bfd
->all_comp_units
.push_back (per_cu
);
5178 sect_off_prev
= sect_off_next
;
5182 /* Read the CU list from the mapped index, and use it to create all
5183 the CU objects for this dwarf2_per_objfile. */
5186 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5187 const mapped_debug_names
&map
,
5188 const mapped_debug_names
&dwz_map
)
5190 gdb_assert (per_bfd
->all_comp_units
.empty ());
5191 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5193 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5194 false /* is_dwz */);
5196 if (dwz_map
.cu_count
== 0)
5199 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5200 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5204 /* Read .debug_names. If everything went ok, initialize the "quick"
5205 elements of all the CUs and return true. Otherwise, return false. */
5208 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5210 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5211 mapped_debug_names dwz_map
;
5212 struct objfile
*objfile
= per_objfile
->objfile
;
5213 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5215 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5216 &per_objfile
->per_bfd
->debug_names
, *map
))
5219 /* Don't use the index if it's empty. */
5220 if (map
->name_count
== 0)
5223 /* If there is a .dwz file, read it so we can get its CU list as
5225 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5228 if (!read_debug_names_from_section (objfile
,
5229 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5230 &dwz
->debug_names
, dwz_map
))
5232 warning (_("could not read '.debug_names' section from %s; skipping"),
5233 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5238 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5240 if (map
->tu_count
!= 0)
5242 /* We can only handle a single .debug_types when we have an
5244 if (per_bfd
->types
.size () != 1)
5247 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5249 create_signatured_type_table_from_debug_names
5250 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5253 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5255 per_bfd
->debug_names_table
= std::move (map
);
5256 per_bfd
->using_index
= 1;
5257 per_bfd
->quick_file_names_table
=
5258 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5260 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5261 objfiles using the same BFD. */
5262 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5263 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5268 /* Type used to manage iterating over all CUs looking for a symbol for
5271 class dw2_debug_names_iterator
5274 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5275 gdb::optional
<block_enum
> block_index
,
5277 const char *name
, dwarf2_per_objfile
*per_objfile
)
5278 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5279 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5280 m_per_objfile (per_objfile
)
5283 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5284 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5287 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5288 m_per_objfile (per_objfile
)
5291 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5292 block_enum block_index
, domain_enum domain
,
5293 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5294 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5295 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5296 m_per_objfile (per_objfile
)
5299 /* Return the next matching CU or NULL if there are no more. */
5300 dwarf2_per_cu_data
*next ();
5303 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5305 dwarf2_per_objfile
*per_objfile
);
5306 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5308 dwarf2_per_objfile
*per_objfile
);
5310 /* The internalized form of .debug_names. */
5311 const mapped_debug_names
&m_map
;
5313 /* If set, only look for symbols that match that block. Valid values are
5314 GLOBAL_BLOCK and STATIC_BLOCK. */
5315 const gdb::optional
<block_enum
> m_block_index
;
5317 /* The kind of symbol we're looking for. */
5318 const domain_enum m_domain
= UNDEF_DOMAIN
;
5319 const search_domain m_search
= ALL_DOMAIN
;
5321 /* The list of CUs from the index entry of the symbol, or NULL if
5323 const gdb_byte
*m_addr
;
5325 dwarf2_per_objfile
*m_per_objfile
;
5329 mapped_debug_names::namei_to_name
5330 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5332 const ULONGEST namei_string_offs
5333 = extract_unsigned_integer ((name_table_string_offs_reordered
5334 + namei
* offset_size
),
5337 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5340 /* Find a slot in .debug_names for the object named NAME. If NAME is
5341 found, return pointer to its pool data. If NAME cannot be found,
5345 dw2_debug_names_iterator::find_vec_in_debug_names
5346 (const mapped_debug_names
&map
, const char *name
,
5347 dwarf2_per_objfile
*per_objfile
)
5349 int (*cmp
) (const char *, const char *);
5351 gdb::unique_xmalloc_ptr
<char> without_params
;
5352 if (current_language
->la_language
== language_cplus
5353 || current_language
->la_language
== language_fortran
5354 || current_language
->la_language
== language_d
)
5356 /* NAME is already canonical. Drop any qualifiers as
5357 .debug_names does not contain any. */
5359 if (strchr (name
, '(') != NULL
)
5361 without_params
= cp_remove_params (name
);
5362 if (without_params
!= NULL
)
5363 name
= without_params
.get ();
5367 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5369 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5371 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5372 (map
.bucket_table_reordered
5373 + (full_hash
% map
.bucket_count
)), 4,
5374 map
.dwarf5_byte_order
);
5378 if (namei
>= map
.name_count
)
5380 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5382 namei
, map
.name_count
,
5383 objfile_name (per_objfile
->objfile
));
5389 const uint32_t namei_full_hash
5390 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5391 (map
.hash_table_reordered
+ namei
), 4,
5392 map
.dwarf5_byte_order
);
5393 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5396 if (full_hash
== namei_full_hash
)
5398 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5400 #if 0 /* An expensive sanity check. */
5401 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5403 complaint (_("Wrong .debug_names hash for string at index %u "
5405 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5410 if (cmp (namei_string
, name
) == 0)
5412 const ULONGEST namei_entry_offs
5413 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5414 + namei
* map
.offset_size
),
5415 map
.offset_size
, map
.dwarf5_byte_order
);
5416 return map
.entry_pool
+ namei_entry_offs
;
5421 if (namei
>= map
.name_count
)
5427 dw2_debug_names_iterator::find_vec_in_debug_names
5428 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5430 if (namei
>= map
.name_count
)
5432 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5434 namei
, map
.name_count
,
5435 objfile_name (per_objfile
->objfile
));
5439 const ULONGEST namei_entry_offs
5440 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5441 + namei
* map
.offset_size
),
5442 map
.offset_size
, map
.dwarf5_byte_order
);
5443 return map
.entry_pool
+ namei_entry_offs
;
5446 /* See dw2_debug_names_iterator. */
5448 dwarf2_per_cu_data
*
5449 dw2_debug_names_iterator::next ()
5454 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5455 struct objfile
*objfile
= m_per_objfile
->objfile
;
5456 bfd
*const abfd
= objfile
->obfd
;
5460 unsigned int bytes_read
;
5461 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5462 m_addr
+= bytes_read
;
5466 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5467 if (indexval_it
== m_map
.abbrev_map
.cend ())
5469 complaint (_("Wrong .debug_names undefined abbrev code %s "
5471 pulongest (abbrev
), objfile_name (objfile
));
5474 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5475 enum class symbol_linkage
{
5479 } symbol_linkage_
= symbol_linkage::unknown
;
5480 dwarf2_per_cu_data
*per_cu
= NULL
;
5481 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5486 case DW_FORM_implicit_const
:
5487 ull
= attr
.implicit_const
;
5489 case DW_FORM_flag_present
:
5493 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5494 m_addr
+= bytes_read
;
5497 ull
= read_4_bytes (abfd
, m_addr
);
5501 ull
= read_8_bytes (abfd
, m_addr
);
5504 case DW_FORM_ref_sig8
:
5505 ull
= read_8_bytes (abfd
, m_addr
);
5509 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5510 dwarf_form_name (attr
.form
),
5511 objfile_name (objfile
));
5514 switch (attr
.dw_idx
)
5516 case DW_IDX_compile_unit
:
5517 /* Don't crash on bad data. */
5518 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5520 complaint (_(".debug_names entry has bad CU index %s"
5523 objfile_name (objfile
));
5526 per_cu
= per_bfd
->get_cutu (ull
);
5528 case DW_IDX_type_unit
:
5529 /* Don't crash on bad data. */
5530 if (ull
>= per_bfd
->all_type_units
.size ())
5532 complaint (_(".debug_names entry has bad TU index %s"
5535 objfile_name (objfile
));
5538 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5540 case DW_IDX_die_offset
:
5541 /* In a per-CU index (as opposed to a per-module index), index
5542 entries without CU attribute implicitly refer to the single CU. */
5544 per_cu
= per_bfd
->get_cu (0);
5546 case DW_IDX_GNU_internal
:
5547 if (!m_map
.augmentation_is_gdb
)
5549 symbol_linkage_
= symbol_linkage::static_
;
5551 case DW_IDX_GNU_external
:
5552 if (!m_map
.augmentation_is_gdb
)
5554 symbol_linkage_
= symbol_linkage::extern_
;
5559 /* Skip if already read in. */
5560 if (m_per_objfile
->symtab_set_p (per_cu
))
5563 /* Check static vs global. */
5564 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5566 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5567 const bool symbol_is_static
=
5568 symbol_linkage_
== symbol_linkage::static_
;
5569 if (want_static
!= symbol_is_static
)
5573 /* Match dw2_symtab_iter_next, symbol_kind
5574 and debug_names::psymbol_tag. */
5578 switch (indexval
.dwarf_tag
)
5580 case DW_TAG_variable
:
5581 case DW_TAG_subprogram
:
5582 /* Some types are also in VAR_DOMAIN. */
5583 case DW_TAG_typedef
:
5584 case DW_TAG_structure_type
:
5591 switch (indexval
.dwarf_tag
)
5593 case DW_TAG_typedef
:
5594 case DW_TAG_structure_type
:
5601 switch (indexval
.dwarf_tag
)
5604 case DW_TAG_variable
:
5611 switch (indexval
.dwarf_tag
)
5623 /* Match dw2_expand_symtabs_matching, symbol_kind and
5624 debug_names::psymbol_tag. */
5627 case VARIABLES_DOMAIN
:
5628 switch (indexval
.dwarf_tag
)
5630 case DW_TAG_variable
:
5636 case FUNCTIONS_DOMAIN
:
5637 switch (indexval
.dwarf_tag
)
5639 case DW_TAG_subprogram
:
5646 switch (indexval
.dwarf_tag
)
5648 case DW_TAG_typedef
:
5649 case DW_TAG_structure_type
:
5655 case MODULES_DOMAIN
:
5656 switch (indexval
.dwarf_tag
)
5670 static struct compunit_symtab
*
5671 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5672 const char *name
, domain_enum domain
)
5674 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5676 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5679 /* index is NULL if OBJF_READNOW. */
5682 const auto &map
= *mapp
;
5684 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5686 struct compunit_symtab
*stab_best
= NULL
;
5687 struct dwarf2_per_cu_data
*per_cu
;
5688 while ((per_cu
= iter
.next ()) != NULL
)
5690 struct symbol
*sym
, *with_opaque
= NULL
;
5691 compunit_symtab
*stab
5692 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5693 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5694 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5696 sym
= block_find_symbol (block
, name
, domain
,
5697 block_find_non_opaque_type_preferred
,
5700 /* Some caution must be observed with overloaded functions and
5701 methods, since the index will not contain any overload
5702 information (but NAME might contain it). */
5705 && strcmp_iw (sym
->search_name (), name
) == 0)
5707 if (with_opaque
!= NULL
5708 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5711 /* Keep looking through other CUs. */
5717 /* This dumps minimal information about .debug_names. It is called
5718 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5719 uses this to verify that .debug_names has been loaded. */
5722 dw2_debug_names_dump (struct objfile
*objfile
)
5724 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5726 gdb_assert (per_objfile
->per_bfd
->using_index
);
5727 printf_filtered (".debug_names:");
5728 if (per_objfile
->per_bfd
->debug_names_table
)
5729 printf_filtered (" exists\n");
5731 printf_filtered (" faked for \"readnow\"\n");
5732 printf_filtered ("\n");
5736 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5737 const char *func_name
)
5739 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5741 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5742 if (per_objfile
->per_bfd
->debug_names_table
)
5744 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5746 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5749 struct dwarf2_per_cu_data
*per_cu
;
5750 while ((per_cu
= iter
.next ()) != NULL
)
5751 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5756 dw2_debug_names_map_matching_symbols
5757 (struct objfile
*objfile
,
5758 const lookup_name_info
&name
, domain_enum domain
,
5760 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5761 symbol_compare_ftype
*ordered_compare
)
5763 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5765 /* debug_names_table is NULL if OBJF_READNOW. */
5766 if (!per_objfile
->per_bfd
->debug_names_table
)
5769 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5770 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5772 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5773 auto matcher
= [&] (const char *symname
)
5775 if (ordered_compare
== nullptr)
5777 return ordered_compare (symname
, match_name
) == 0;
5780 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5781 [&] (offset_type namei
)
5783 /* The name was matched, now expand corresponding CUs that were
5785 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5788 struct dwarf2_per_cu_data
*per_cu
;
5789 while ((per_cu
= iter
.next ()) != NULL
)
5790 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5795 /* It's a shame we couldn't do this inside the
5796 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5797 that have already been expanded. Instead, this loop matches what
5798 the psymtab code does. */
5799 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5801 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5802 if (symtab
!= nullptr)
5804 const struct block
*block
5805 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5806 if (!iterate_over_symbols_terminated (block
, name
,
5814 dw2_debug_names_expand_symtabs_matching
5815 (struct objfile
*objfile
,
5816 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5817 const lookup_name_info
*lookup_name
,
5818 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5819 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5820 enum search_domain kind
)
5822 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5824 /* debug_names_table is NULL if OBJF_READNOW. */
5825 if (!per_objfile
->per_bfd
->debug_names_table
)
5828 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5830 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5832 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5836 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5842 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5844 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5846 kind
, [&] (offset_type namei
)
5848 /* The name was matched, now expand corresponding CUs that were
5850 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5852 struct dwarf2_per_cu_data
*per_cu
;
5853 while ((per_cu
= iter
.next ()) != NULL
)
5854 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5860 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5863 dw2_find_last_source_symtab
,
5864 dw2_forget_cached_source_info
,
5865 dw2_map_symtabs_matching_filename
,
5866 dw2_debug_names_lookup_symbol
,
5869 dw2_debug_names_dump
,
5870 dw2_debug_names_expand_symtabs_for_function
,
5871 dw2_expand_all_symtabs
,
5872 dw2_expand_symtabs_with_fullname
,
5873 dw2_debug_names_map_matching_symbols
,
5874 dw2_debug_names_expand_symtabs_matching
,
5875 dw2_find_pc_sect_compunit_symtab
,
5877 dw2_map_symbol_filenames
5880 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5881 to either a dwarf2_per_bfd or dwz_file object. */
5883 template <typename T
>
5884 static gdb::array_view
<const gdb_byte
>
5885 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5887 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5889 if (section
->empty ())
5892 /* Older elfutils strip versions could keep the section in the main
5893 executable while splitting it for the separate debug info file. */
5894 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5897 section
->read (obj
);
5899 /* dwarf2_section_info::size is a bfd_size_type, while
5900 gdb::array_view works with size_t. On 32-bit hosts, with
5901 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5902 is 32-bit. So we need an explicit narrowing conversion here.
5903 This is fine, because it's impossible to allocate or mmap an
5904 array/buffer larger than what size_t can represent. */
5905 return gdb::make_array_view (section
->buffer
, section
->size
);
5908 /* Lookup the index cache for the contents of the index associated to
5911 static gdb::array_view
<const gdb_byte
>
5912 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5914 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5915 if (build_id
== nullptr)
5918 return global_index_cache
.lookup_gdb_index (build_id
,
5919 &dwarf2_per_bfd
->index_cache_res
);
5922 /* Same as the above, but for DWZ. */
5924 static gdb::array_view
<const gdb_byte
>
5925 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5927 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5928 if (build_id
== nullptr)
5931 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5934 /* See symfile.h. */
5937 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5939 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5940 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5942 /* If we're about to read full symbols, don't bother with the
5943 indices. In this case we also don't care if some other debug
5944 format is making psymtabs, because they are all about to be
5946 if ((objfile
->flags
& OBJF_READNOW
))
5948 /* When using READNOW, the using_index flag (set below) indicates that
5949 PER_BFD was already initialized, when we loaded some other objfile. */
5950 if (per_bfd
->using_index
)
5952 *index_kind
= dw_index_kind::GDB_INDEX
;
5953 per_objfile
->resize_symtabs ();
5957 per_bfd
->using_index
= 1;
5958 create_all_comp_units (per_objfile
);
5959 create_all_type_units (per_objfile
);
5960 per_bfd
->quick_file_names_table
5961 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5962 per_objfile
->resize_symtabs ();
5964 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
5965 + per_bfd
->all_type_units
.size ()); ++i
)
5967 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
5969 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5970 struct dwarf2_per_cu_quick_data
);
5973 /* Return 1 so that gdb sees the "quick" functions. However,
5974 these functions will be no-ops because we will have expanded
5976 *index_kind
= dw_index_kind::GDB_INDEX
;
5980 /* Was a debug names index already read when we processed an objfile sharing
5982 if (per_bfd
->debug_names_table
!= nullptr)
5984 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5985 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
5986 per_objfile
->resize_symtabs ();
5990 /* Was a GDB index already read when we processed an objfile sharing
5992 if (per_bfd
->index_table
!= nullptr)
5994 *index_kind
= dw_index_kind::GDB_INDEX
;
5995 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
5996 per_objfile
->resize_symtabs ();
6000 if (dwarf2_read_debug_names (per_objfile
))
6002 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6003 per_objfile
->resize_symtabs ();
6007 if (dwarf2_read_gdb_index (per_objfile
,
6008 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6009 get_gdb_index_contents_from_section
<dwz_file
>))
6011 *index_kind
= dw_index_kind::GDB_INDEX
;
6012 per_objfile
->resize_symtabs ();
6016 /* ... otherwise, try to find the index in the index cache. */
6017 if (dwarf2_read_gdb_index (per_objfile
,
6018 get_gdb_index_contents_from_cache
,
6019 get_gdb_index_contents_from_cache_dwz
))
6021 global_index_cache
.hit ();
6022 *index_kind
= dw_index_kind::GDB_INDEX
;
6023 per_objfile
->resize_symtabs ();
6027 global_index_cache
.miss ();
6033 /* Build a partial symbol table. */
6036 dwarf2_build_psymtabs (struct objfile
*objfile
)
6038 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6039 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6041 if (per_bfd
->partial_symtabs
!= nullptr)
6043 /* Partial symbols were already read, so now we can simply
6045 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6046 per_objfile
->resize_symtabs ();
6050 init_psymbol_list (objfile
, 1024);
6054 /* This isn't really ideal: all the data we allocate on the
6055 objfile's obstack is still uselessly kept around. However,
6056 freeing it seems unsafe. */
6057 psymtab_discarder
psymtabs (objfile
);
6058 dwarf2_build_psymtabs_hard (per_objfile
);
6061 per_objfile
->resize_symtabs ();
6063 /* (maybe) store an index in the cache. */
6064 global_index_cache
.store (per_objfile
);
6066 catch (const gdb_exception_error
&except
)
6068 exception_print (gdb_stderr
, except
);
6071 /* Finish by setting the local reference to partial symtabs, so that
6072 we don't try to read them again if reading another objfile with the same
6073 BFD. If we can't in fact share, this won't make a difference anyway as
6074 the dwarf2_per_bfd object won't be shared. */
6075 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6078 /* Find the base address of the compilation unit for range lists and
6079 location lists. It will normally be specified by DW_AT_low_pc.
6080 In DWARF-3 draft 4, the base address could be overridden by
6081 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6082 compilation units with discontinuous ranges. */
6085 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6087 struct attribute
*attr
;
6089 cu
->base_address
.reset ();
6091 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6092 if (attr
!= nullptr)
6093 cu
->base_address
= attr
->value_as_address ();
6096 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6097 if (attr
!= nullptr)
6098 cu
->base_address
= attr
->value_as_address ();
6102 /* Helper function that returns the proper abbrev section for
6105 static struct dwarf2_section_info
*
6106 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6108 struct dwarf2_section_info
*abbrev
;
6109 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6111 if (this_cu
->is_dwz
)
6112 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6114 abbrev
= &per_bfd
->abbrev
;
6119 /* Fetch the abbreviation table offset from a comp or type unit header. */
6122 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6123 struct dwarf2_section_info
*section
,
6124 sect_offset sect_off
)
6126 bfd
*abfd
= section
->get_bfd_owner ();
6127 const gdb_byte
*info_ptr
;
6128 unsigned int initial_length_size
, offset_size
;
6131 section
->read (per_objfile
->objfile
);
6132 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6133 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6134 offset_size
= initial_length_size
== 4 ? 4 : 8;
6135 info_ptr
+= initial_length_size
;
6137 version
= read_2_bytes (abfd
, info_ptr
);
6141 /* Skip unit type and address size. */
6145 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6148 /* A partial symtab that is used only for include files. */
6149 struct dwarf2_include_psymtab
: public partial_symtab
6151 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6152 : partial_symtab (filename
, objfile
)
6156 void read_symtab (struct objfile
*objfile
) override
6158 /* It's an include file, no symbols to read for it.
6159 Everything is in the includer symtab. */
6161 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6162 expansion of the includer psymtab. We use the dependencies[0] field to
6163 model the includer. But if we go the regular route of calling
6164 expand_psymtab here, and having expand_psymtab call expand_dependencies
6165 to expand the includer, we'll only use expand_psymtab on the includer
6166 (making it a non-toplevel psymtab), while if we expand the includer via
6167 another path, we'll use read_symtab (making it a toplevel psymtab).
6168 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6169 psymtab, and trigger read_symtab on the includer here directly. */
6170 includer ()->read_symtab (objfile
);
6173 void expand_psymtab (struct objfile
*objfile
) override
6175 /* This is not called by read_symtab, and should not be called by any
6176 expand_dependencies. */
6180 bool readin_p (struct objfile
*objfile
) const override
6182 return includer ()->readin_p (objfile
);
6185 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6191 partial_symtab
*includer () const
6193 /* An include psymtab has exactly one dependency: the psymtab that
6195 gdb_assert (this->number_of_dependencies
== 1);
6196 return this->dependencies
[0];
6200 /* Allocate a new partial symtab for file named NAME and mark this new
6201 partial symtab as being an include of PST. */
6204 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6205 struct objfile
*objfile
)
6207 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6209 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6210 subpst
->dirname
= pst
->dirname
;
6212 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6213 subpst
->dependencies
[0] = pst
;
6214 subpst
->number_of_dependencies
= 1;
6217 /* Read the Line Number Program data and extract the list of files
6218 included by the source file represented by PST. Build an include
6219 partial symtab for each of these included files. */
6222 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6223 struct die_info
*die
,
6224 dwarf2_psymtab
*pst
)
6227 struct attribute
*attr
;
6229 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6230 if (attr
!= nullptr)
6231 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6233 return; /* No linetable, so no includes. */
6235 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6236 that we pass in the raw text_low here; that is ok because we're
6237 only decoding the line table to make include partial symtabs, and
6238 so the addresses aren't really used. */
6239 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6240 pst
->raw_text_low (), 1);
6244 hash_signatured_type (const void *item
)
6246 const struct signatured_type
*sig_type
6247 = (const struct signatured_type
*) item
;
6249 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6250 return sig_type
->signature
;
6254 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6256 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6257 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6259 return lhs
->signature
== rhs
->signature
;
6262 /* Allocate a hash table for signatured types. */
6265 allocate_signatured_type_table ()
6267 return htab_up (htab_create_alloc (41,
6268 hash_signatured_type
,
6270 NULL
, xcalloc
, xfree
));
6273 /* A helper function to add a signatured type CU to a table. */
6276 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6278 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6279 std::vector
<signatured_type
*> *all_type_units
6280 = (std::vector
<signatured_type
*> *) datum
;
6282 all_type_units
->push_back (sigt
);
6287 /* A helper for create_debug_types_hash_table. Read types from SECTION
6288 and fill them into TYPES_HTAB. It will process only type units,
6289 therefore DW_UT_type. */
6292 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6293 struct dwo_file
*dwo_file
,
6294 dwarf2_section_info
*section
, htab_up
&types_htab
,
6295 rcuh_kind section_kind
)
6297 struct objfile
*objfile
= per_objfile
->objfile
;
6298 struct dwarf2_section_info
*abbrev_section
;
6300 const gdb_byte
*info_ptr
, *end_ptr
;
6302 abbrev_section
= (dwo_file
!= NULL
6303 ? &dwo_file
->sections
.abbrev
6304 : &per_objfile
->per_bfd
->abbrev
);
6306 if (dwarf_read_debug
)
6307 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6308 section
->get_name (),
6309 abbrev_section
->get_file_name ());
6311 section
->read (objfile
);
6312 info_ptr
= section
->buffer
;
6314 if (info_ptr
== NULL
)
6317 /* We can't set abfd until now because the section may be empty or
6318 not present, in which case the bfd is unknown. */
6319 abfd
= section
->get_bfd_owner ();
6321 /* We don't use cutu_reader here because we don't need to read
6322 any dies: the signature is in the header. */
6324 end_ptr
= info_ptr
+ section
->size
;
6325 while (info_ptr
< end_ptr
)
6327 struct signatured_type
*sig_type
;
6328 struct dwo_unit
*dwo_tu
;
6330 const gdb_byte
*ptr
= info_ptr
;
6331 struct comp_unit_head header
;
6332 unsigned int length
;
6334 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6336 /* Initialize it due to a false compiler warning. */
6337 header
.signature
= -1;
6338 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6340 /* We need to read the type's signature in order to build the hash
6341 table, but we don't need anything else just yet. */
6343 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6344 abbrev_section
, ptr
, section_kind
);
6346 length
= header
.get_length ();
6348 /* Skip dummy type units. */
6349 if (ptr
>= info_ptr
+ length
6350 || peek_abbrev_code (abfd
, ptr
) == 0
6351 || header
.unit_type
!= DW_UT_type
)
6357 if (types_htab
== NULL
)
6360 types_htab
= allocate_dwo_unit_table ();
6362 types_htab
= allocate_signatured_type_table ();
6368 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6369 dwo_tu
->dwo_file
= dwo_file
;
6370 dwo_tu
->signature
= header
.signature
;
6371 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6372 dwo_tu
->section
= section
;
6373 dwo_tu
->sect_off
= sect_off
;
6374 dwo_tu
->length
= length
;
6378 /* N.B.: type_offset is not usable if this type uses a DWO file.
6379 The real type_offset is in the DWO file. */
6381 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6382 sig_type
->signature
= header
.signature
;
6383 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6384 sig_type
->per_cu
.is_debug_types
= 1;
6385 sig_type
->per_cu
.section
= section
;
6386 sig_type
->per_cu
.sect_off
= sect_off
;
6387 sig_type
->per_cu
.length
= length
;
6390 slot
= htab_find_slot (types_htab
.get (),
6391 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6393 gdb_assert (slot
!= NULL
);
6396 sect_offset dup_sect_off
;
6400 const struct dwo_unit
*dup_tu
6401 = (const struct dwo_unit
*) *slot
;
6403 dup_sect_off
= dup_tu
->sect_off
;
6407 const struct signatured_type
*dup_tu
6408 = (const struct signatured_type
*) *slot
;
6410 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6413 complaint (_("debug type entry at offset %s is duplicate to"
6414 " the entry at offset %s, signature %s"),
6415 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6416 hex_string (header
.signature
));
6418 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6420 if (dwarf_read_debug
> 1)
6421 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6422 sect_offset_str (sect_off
),
6423 hex_string (header
.signature
));
6429 /* Create the hash table of all entries in the .debug_types
6430 (or .debug_types.dwo) section(s).
6431 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6432 otherwise it is NULL.
6434 The result is a pointer to the hash table or NULL if there are no types.
6436 Note: This function processes DWO files only, not DWP files. */
6439 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6440 struct dwo_file
*dwo_file
,
6441 gdb::array_view
<dwarf2_section_info
> type_sections
,
6442 htab_up
&types_htab
)
6444 for (dwarf2_section_info
§ion
: type_sections
)
6445 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6449 /* Create the hash table of all entries in the .debug_types section,
6450 and initialize all_type_units.
6451 The result is zero if there is an error (e.g. missing .debug_types section),
6452 otherwise non-zero. */
6455 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6459 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6460 types_htab
, rcuh_kind::COMPILE
);
6461 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6463 if (types_htab
== NULL
)
6465 per_objfile
->per_bfd
->signatured_types
= NULL
;
6469 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6471 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6472 per_objfile
->per_bfd
->all_type_units
.reserve
6473 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6475 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6476 add_signatured_type_cu_to_table
,
6477 &per_objfile
->per_bfd
->all_type_units
);
6482 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6483 If SLOT is non-NULL, it is the entry to use in the hash table.
6484 Otherwise we find one. */
6486 static struct signatured_type
*
6487 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6489 if (per_objfile
->per_bfd
->all_type_units
.size ()
6490 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6491 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6493 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6495 per_objfile
->resize_symtabs ();
6497 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6498 sig_type
->signature
= sig
;
6499 sig_type
->per_cu
.is_debug_types
= 1;
6500 if (per_objfile
->per_bfd
->using_index
)
6502 sig_type
->per_cu
.v
.quick
=
6503 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6504 struct dwarf2_per_cu_quick_data
);
6509 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6512 gdb_assert (*slot
== NULL
);
6514 /* The rest of sig_type must be filled in by the caller. */
6518 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6519 Fill in SIG_ENTRY with DWO_ENTRY. */
6522 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6523 struct signatured_type
*sig_entry
,
6524 struct dwo_unit
*dwo_entry
)
6526 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6528 /* Make sure we're not clobbering something we don't expect to. */
6529 gdb_assert (! sig_entry
->per_cu
.queued
);
6530 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6531 if (per_bfd
->using_index
)
6533 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6534 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6537 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6538 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6539 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6540 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6541 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6543 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6544 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6545 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6546 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6547 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6548 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6549 sig_entry
->dwo_unit
= dwo_entry
;
6552 /* Subroutine of lookup_signatured_type.
6553 If we haven't read the TU yet, create the signatured_type data structure
6554 for a TU to be read in directly from a DWO file, bypassing the stub.
6555 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6556 using .gdb_index, then when reading a CU we want to stay in the DWO file
6557 containing that CU. Otherwise we could end up reading several other DWO
6558 files (due to comdat folding) to process the transitive closure of all the
6559 mentioned TUs, and that can be slow. The current DWO file will have every
6560 type signature that it needs.
6561 We only do this for .gdb_index because in the psymtab case we already have
6562 to read all the DWOs to build the type unit groups. */
6564 static struct signatured_type
*
6565 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6567 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6568 struct dwo_file
*dwo_file
;
6569 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6570 struct signatured_type find_sig_entry
, *sig_entry
;
6573 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6575 /* If TU skeletons have been removed then we may not have read in any
6577 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6578 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6580 /* We only ever need to read in one copy of a signatured type.
6581 Use the global signatured_types array to do our own comdat-folding
6582 of types. If this is the first time we're reading this TU, and
6583 the TU has an entry in .gdb_index, replace the recorded data from
6584 .gdb_index with this TU. */
6586 find_sig_entry
.signature
= sig
;
6587 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6588 &find_sig_entry
, INSERT
);
6589 sig_entry
= (struct signatured_type
*) *slot
;
6591 /* We can get here with the TU already read, *or* in the process of being
6592 read. Don't reassign the global entry to point to this DWO if that's
6593 the case. Also note that if the TU is already being read, it may not
6594 have come from a DWO, the program may be a mix of Fission-compiled
6595 code and non-Fission-compiled code. */
6597 /* Have we already tried to read this TU?
6598 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6599 needn't exist in the global table yet). */
6600 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6603 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6604 dwo_unit of the TU itself. */
6605 dwo_file
= cu
->dwo_unit
->dwo_file
;
6607 /* Ok, this is the first time we're reading this TU. */
6608 if (dwo_file
->tus
== NULL
)
6610 find_dwo_entry
.signature
= sig
;
6611 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6613 if (dwo_entry
== NULL
)
6616 /* If the global table doesn't have an entry for this TU, add one. */
6617 if (sig_entry
== NULL
)
6618 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6620 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6621 sig_entry
->per_cu
.tu_read
= 1;
6625 /* Subroutine of lookup_signatured_type.
6626 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6627 then try the DWP file. If the TU stub (skeleton) has been removed then
6628 it won't be in .gdb_index. */
6630 static struct signatured_type
*
6631 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6633 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6634 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6635 struct dwo_unit
*dwo_entry
;
6636 struct signatured_type find_sig_entry
, *sig_entry
;
6639 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6640 gdb_assert (dwp_file
!= NULL
);
6642 /* If TU skeletons have been removed then we may not have read in any
6644 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6645 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6647 find_sig_entry
.signature
= sig
;
6648 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6649 &find_sig_entry
, INSERT
);
6650 sig_entry
= (struct signatured_type
*) *slot
;
6652 /* Have we already tried to read this TU?
6653 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6654 needn't exist in the global table yet). */
6655 if (sig_entry
!= NULL
)
6658 if (dwp_file
->tus
== NULL
)
6660 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6661 1 /* is_debug_types */);
6662 if (dwo_entry
== NULL
)
6665 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6666 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6671 /* Lookup a signature based type for DW_FORM_ref_sig8.
6672 Returns NULL if signature SIG is not present in the table.
6673 It is up to the caller to complain about this. */
6675 static struct signatured_type
*
6676 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6678 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6680 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6682 /* We're in a DWO/DWP file, and we're using .gdb_index.
6683 These cases require special processing. */
6684 if (get_dwp_file (per_objfile
) == NULL
)
6685 return lookup_dwo_signatured_type (cu
, sig
);
6687 return lookup_dwp_signatured_type (cu
, sig
);
6691 struct signatured_type find_entry
, *entry
;
6693 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6695 find_entry
.signature
= sig
;
6696 entry
= ((struct signatured_type
*)
6697 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6703 /* Low level DIE reading support. */
6705 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6708 init_cu_die_reader (struct die_reader_specs
*reader
,
6709 struct dwarf2_cu
*cu
,
6710 struct dwarf2_section_info
*section
,
6711 struct dwo_file
*dwo_file
,
6712 struct abbrev_table
*abbrev_table
)
6714 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6715 reader
->abfd
= section
->get_bfd_owner ();
6717 reader
->dwo_file
= dwo_file
;
6718 reader
->die_section
= section
;
6719 reader
->buffer
= section
->buffer
;
6720 reader
->buffer_end
= section
->buffer
+ section
->size
;
6721 reader
->abbrev_table
= abbrev_table
;
6724 /* Subroutine of cutu_reader to simplify it.
6725 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6726 There's just a lot of work to do, and cutu_reader is big enough
6729 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6730 from it to the DIE in the DWO. If NULL we are skipping the stub.
6731 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6732 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6733 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6734 STUB_COMP_DIR may be non-NULL.
6735 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6736 are filled in with the info of the DIE from the DWO file.
6737 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6738 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6739 kept around for at least as long as *RESULT_READER.
6741 The result is non-zero if a valid (non-dummy) DIE was found. */
6744 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6745 struct dwo_unit
*dwo_unit
,
6746 struct die_info
*stub_comp_unit_die
,
6747 const char *stub_comp_dir
,
6748 struct die_reader_specs
*result_reader
,
6749 const gdb_byte
**result_info_ptr
,
6750 struct die_info
**result_comp_unit_die
,
6751 abbrev_table_up
*result_dwo_abbrev_table
)
6753 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6754 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6755 struct objfile
*objfile
= per_objfile
->objfile
;
6757 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6758 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6759 int i
,num_extra_attrs
;
6760 struct dwarf2_section_info
*dwo_abbrev_section
;
6761 struct die_info
*comp_unit_die
;
6763 /* At most one of these may be provided. */
6764 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6766 /* These attributes aren't processed until later:
6767 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6768 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6769 referenced later. However, these attributes are found in the stub
6770 which we won't have later. In order to not impose this complication
6771 on the rest of the code, we read them here and copy them to the
6780 if (stub_comp_unit_die
!= NULL
)
6782 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6784 if (!per_cu
->is_debug_types
)
6785 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6786 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6787 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6788 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6789 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6791 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6793 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6794 here (if needed). We need the value before we can process
6796 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6798 else if (stub_comp_dir
!= NULL
)
6800 /* Reconstruct the comp_dir attribute to simplify the code below. */
6801 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6802 comp_dir
->name
= DW_AT_comp_dir
;
6803 comp_dir
->form
= DW_FORM_string
;
6804 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6805 DW_STRING (comp_dir
) = stub_comp_dir
;
6808 /* Set up for reading the DWO CU/TU. */
6809 cu
->dwo_unit
= dwo_unit
;
6810 dwarf2_section_info
*section
= dwo_unit
->section
;
6811 section
->read (objfile
);
6812 abfd
= section
->get_bfd_owner ();
6813 begin_info_ptr
= info_ptr
= (section
->buffer
6814 + to_underlying (dwo_unit
->sect_off
));
6815 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6817 if (per_cu
->is_debug_types
)
6819 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6821 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6822 section
, dwo_abbrev_section
,
6823 info_ptr
, rcuh_kind::TYPE
);
6824 /* This is not an assert because it can be caused by bad debug info. */
6825 if (sig_type
->signature
!= cu
->header
.signature
)
6827 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6828 " TU at offset %s [in module %s]"),
6829 hex_string (sig_type
->signature
),
6830 hex_string (cu
->header
.signature
),
6831 sect_offset_str (dwo_unit
->sect_off
),
6832 bfd_get_filename (abfd
));
6834 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6835 /* For DWOs coming from DWP files, we don't know the CU length
6836 nor the type's offset in the TU until now. */
6837 dwo_unit
->length
= cu
->header
.get_length ();
6838 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6840 /* Establish the type offset that can be used to lookup the type.
6841 For DWO files, we don't know it until now. */
6842 sig_type
->type_offset_in_section
6843 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6847 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6848 section
, dwo_abbrev_section
,
6849 info_ptr
, rcuh_kind::COMPILE
);
6850 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6851 /* For DWOs coming from DWP files, we don't know the CU length
6853 dwo_unit
->length
= cu
->header
.get_length ();
6856 *result_dwo_abbrev_table
6857 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6858 cu
->header
.abbrev_sect_off
);
6859 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6860 result_dwo_abbrev_table
->get ());
6862 /* Read in the die, but leave space to copy over the attributes
6863 from the stub. This has the benefit of simplifying the rest of
6864 the code - all the work to maintain the illusion of a single
6865 DW_TAG_{compile,type}_unit DIE is done here. */
6866 num_extra_attrs
= ((stmt_list
!= NULL
)
6870 + (comp_dir
!= NULL
));
6871 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6874 /* Copy over the attributes from the stub to the DIE we just read in. */
6875 comp_unit_die
= *result_comp_unit_die
;
6876 i
= comp_unit_die
->num_attrs
;
6877 if (stmt_list
!= NULL
)
6878 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6880 comp_unit_die
->attrs
[i
++] = *low_pc
;
6881 if (high_pc
!= NULL
)
6882 comp_unit_die
->attrs
[i
++] = *high_pc
;
6884 comp_unit_die
->attrs
[i
++] = *ranges
;
6885 if (comp_dir
!= NULL
)
6886 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6887 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6889 if (dwarf_die_debug
)
6891 fprintf_unfiltered (gdb_stdlog
,
6892 "Read die from %s@0x%x of %s:\n",
6893 section
->get_name (),
6894 (unsigned) (begin_info_ptr
- section
->buffer
),
6895 bfd_get_filename (abfd
));
6896 dump_die (comp_unit_die
, dwarf_die_debug
);
6899 /* Skip dummy compilation units. */
6900 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6901 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6904 *result_info_ptr
= info_ptr
;
6908 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6909 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6910 signature is part of the header. */
6911 static gdb::optional
<ULONGEST
>
6912 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6914 if (cu
->header
.version
>= 5)
6915 return cu
->header
.signature
;
6916 struct attribute
*attr
;
6917 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6918 if (attr
== nullptr)
6919 return gdb::optional
<ULONGEST
> ();
6920 return DW_UNSND (attr
);
6923 /* Subroutine of cutu_reader to simplify it.
6924 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6925 Returns NULL if the specified DWO unit cannot be found. */
6927 static struct dwo_unit
*
6928 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6930 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6931 struct dwo_unit
*dwo_unit
;
6932 const char *comp_dir
;
6934 gdb_assert (cu
!= NULL
);
6936 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6937 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6938 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6940 if (per_cu
->is_debug_types
)
6941 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6944 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6946 if (!signature
.has_value ())
6947 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6949 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6951 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6957 /* Subroutine of cutu_reader to simplify it.
6958 See it for a description of the parameters.
6959 Read a TU directly from a DWO file, bypassing the stub. */
6962 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6963 dwarf2_per_objfile
*per_objfile
,
6964 dwarf2_cu
*existing_cu
)
6966 struct signatured_type
*sig_type
;
6968 /* Verify we can do the following downcast, and that we have the
6970 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6971 sig_type
= (struct signatured_type
*) this_cu
;
6972 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6976 if (existing_cu
!= nullptr)
6979 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6980 /* There's no need to do the rereading_dwo_cu handling that
6981 cutu_reader does since we don't read the stub. */
6985 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6986 in per_objfile yet. */
6987 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6988 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6989 cu
= m_new_cu
.get ();
6992 /* A future optimization, if needed, would be to use an existing
6993 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6994 could share abbrev tables. */
6996 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6997 NULL
/* stub_comp_unit_die */,
6998 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7001 &m_dwo_abbrev_table
) == 0)
7008 /* Initialize a CU (or TU) and read its DIEs.
7009 If the CU defers to a DWO file, read the DWO file as well.
7011 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7012 Otherwise the table specified in the comp unit header is read in and used.
7013 This is an optimization for when we already have the abbrev table.
7015 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7018 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7019 dwarf2_per_objfile
*per_objfile
,
7020 struct abbrev_table
*abbrev_table
,
7021 dwarf2_cu
*existing_cu
,
7023 : die_reader_specs
{},
7026 struct objfile
*objfile
= per_objfile
->objfile
;
7027 struct dwarf2_section_info
*section
= this_cu
->section
;
7028 bfd
*abfd
= section
->get_bfd_owner ();
7029 const gdb_byte
*begin_info_ptr
;
7030 struct signatured_type
*sig_type
= NULL
;
7031 struct dwarf2_section_info
*abbrev_section
;
7032 /* Non-zero if CU currently points to a DWO file and we need to
7033 reread it. When this happens we need to reread the skeleton die
7034 before we can reread the DWO file (this only applies to CUs, not TUs). */
7035 int rereading_dwo_cu
= 0;
7037 if (dwarf_die_debug
)
7038 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7039 this_cu
->is_debug_types
? "type" : "comp",
7040 sect_offset_str (this_cu
->sect_off
));
7042 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7043 file (instead of going through the stub), short-circuit all of this. */
7044 if (this_cu
->reading_dwo_directly
)
7046 /* Narrow down the scope of possibilities to have to understand. */
7047 gdb_assert (this_cu
->is_debug_types
);
7048 gdb_assert (abbrev_table
== NULL
);
7049 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7053 /* This is cheap if the section is already read in. */
7054 section
->read (objfile
);
7056 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7058 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7062 if (existing_cu
!= nullptr)
7065 /* If this CU is from a DWO file we need to start over, we need to
7066 refetch the attributes from the skeleton CU.
7067 This could be optimized by retrieving those attributes from when we
7068 were here the first time: the previous comp_unit_die was stored in
7069 comp_unit_obstack. But there's no data yet that we need this
7071 if (cu
->dwo_unit
!= NULL
)
7072 rereading_dwo_cu
= 1;
7076 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7077 in per_objfile yet. */
7078 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7079 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7080 cu
= m_new_cu
.get ();
7083 /* Get the header. */
7084 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7086 /* We already have the header, there's no need to read it in again. */
7087 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7091 if (this_cu
->is_debug_types
)
7093 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7094 section
, abbrev_section
,
7095 info_ptr
, rcuh_kind::TYPE
);
7097 /* Since per_cu is the first member of struct signatured_type,
7098 we can go from a pointer to one to a pointer to the other. */
7099 sig_type
= (struct signatured_type
*) this_cu
;
7100 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7101 gdb_assert (sig_type
->type_offset_in_tu
7102 == cu
->header
.type_cu_offset_in_tu
);
7103 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7105 /* LENGTH has not been set yet for type units if we're
7106 using .gdb_index. */
7107 this_cu
->length
= cu
->header
.get_length ();
7109 /* Establish the type offset that can be used to lookup the type. */
7110 sig_type
->type_offset_in_section
=
7111 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7113 this_cu
->dwarf_version
= cu
->header
.version
;
7117 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7118 section
, abbrev_section
,
7120 rcuh_kind::COMPILE
);
7122 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7123 if (this_cu
->length
== 0)
7124 this_cu
->length
= cu
->header
.get_length ();
7126 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7127 this_cu
->dwarf_version
= cu
->header
.version
;
7131 /* Skip dummy compilation units. */
7132 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7133 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7139 /* If we don't have them yet, read the abbrevs for this compilation unit.
7140 And if we need to read them now, make sure they're freed when we're
7142 if (abbrev_table
!= NULL
)
7143 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7146 m_abbrev_table_holder
7147 = abbrev_table::read (objfile
, abbrev_section
,
7148 cu
->header
.abbrev_sect_off
);
7149 abbrev_table
= m_abbrev_table_holder
.get ();
7152 /* Read the top level CU/TU die. */
7153 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7154 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7156 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7162 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7163 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7164 table from the DWO file and pass the ownership over to us. It will be
7165 referenced from READER, so we must make sure to free it after we're done
7168 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7169 DWO CU, that this test will fail (the attribute will not be present). */
7170 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7171 if (dwo_name
!= nullptr)
7173 struct dwo_unit
*dwo_unit
;
7174 struct die_info
*dwo_comp_unit_die
;
7176 if (comp_unit_die
->has_children
)
7178 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7179 " has children (offset %s) [in module %s]"),
7180 sect_offset_str (this_cu
->sect_off
),
7181 bfd_get_filename (abfd
));
7183 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7184 if (dwo_unit
!= NULL
)
7186 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7187 comp_unit_die
, NULL
,
7190 &m_dwo_abbrev_table
) == 0)
7196 comp_unit_die
= dwo_comp_unit_die
;
7200 /* Yikes, we couldn't find the rest of the DIE, we only have
7201 the stub. A complaint has already been logged. There's
7202 not much more we can do except pass on the stub DIE to
7203 die_reader_func. We don't want to throw an error on bad
7210 cutu_reader::keep ()
7212 /* Done, clean up. */
7213 gdb_assert (!dummy_p
);
7214 if (m_new_cu
!= NULL
)
7216 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7218 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7219 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7223 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7224 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7225 assumed to have already done the lookup to find the DWO file).
7227 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7228 THIS_CU->is_debug_types, but nothing else.
7230 We fill in THIS_CU->length.
7232 THIS_CU->cu is always freed when done.
7233 This is done in order to not leave THIS_CU->cu in a state where we have
7234 to care whether it refers to the "main" CU or the DWO CU.
7236 When parent_cu is passed, it is used to provide a default value for
7237 str_offsets_base and addr_base from the parent. */
7239 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7240 dwarf2_per_objfile
*per_objfile
,
7241 struct dwarf2_cu
*parent_cu
,
7242 struct dwo_file
*dwo_file
)
7243 : die_reader_specs
{},
7246 struct objfile
*objfile
= per_objfile
->objfile
;
7247 struct dwarf2_section_info
*section
= this_cu
->section
;
7248 bfd
*abfd
= section
->get_bfd_owner ();
7249 struct dwarf2_section_info
*abbrev_section
;
7250 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7252 if (dwarf_die_debug
)
7253 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7254 this_cu
->is_debug_types
? "type" : "comp",
7255 sect_offset_str (this_cu
->sect_off
));
7257 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7259 abbrev_section
= (dwo_file
!= NULL
7260 ? &dwo_file
->sections
.abbrev
7261 : get_abbrev_section_for_cu (this_cu
));
7263 /* This is cheap if the section is already read in. */
7264 section
->read (objfile
);
7266 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7268 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7269 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7270 section
, abbrev_section
, info_ptr
,
7271 (this_cu
->is_debug_types
7273 : rcuh_kind::COMPILE
));
7275 if (parent_cu
!= nullptr)
7277 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7278 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7280 this_cu
->length
= m_new_cu
->header
.get_length ();
7282 /* Skip dummy compilation units. */
7283 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7284 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7290 m_abbrev_table_holder
7291 = abbrev_table::read (objfile
, abbrev_section
,
7292 m_new_cu
->header
.abbrev_sect_off
);
7294 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7295 m_abbrev_table_holder
.get ());
7296 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7300 /* Type Unit Groups.
7302 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7303 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7304 so that all types coming from the same compilation (.o file) are grouped
7305 together. A future step could be to put the types in the same symtab as
7306 the CU the types ultimately came from. */
7309 hash_type_unit_group (const void *item
)
7311 const struct type_unit_group
*tu_group
7312 = (const struct type_unit_group
*) item
;
7314 return hash_stmt_list_entry (&tu_group
->hash
);
7318 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7320 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7321 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7323 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7326 /* Allocate a hash table for type unit groups. */
7329 allocate_type_unit_groups_table ()
7331 return htab_up (htab_create_alloc (3,
7332 hash_type_unit_group
,
7334 NULL
, xcalloc
, xfree
));
7337 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7338 partial symtabs. We combine several TUs per psymtab to not let the size
7339 of any one psymtab grow too big. */
7340 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7341 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7343 /* Helper routine for get_type_unit_group.
7344 Create the type_unit_group object used to hold one or more TUs. */
7346 static struct type_unit_group
*
7347 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7349 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7350 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7351 struct dwarf2_per_cu_data
*per_cu
;
7352 struct type_unit_group
*tu_group
;
7354 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7355 per_cu
= &tu_group
->per_cu
;
7356 per_cu
->per_bfd
= per_bfd
;
7358 if (per_bfd
->using_index
)
7360 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7361 struct dwarf2_per_cu_quick_data
);
7365 unsigned int line_offset
= to_underlying (line_offset_struct
);
7366 dwarf2_psymtab
*pst
;
7369 /* Give the symtab a useful name for debug purposes. */
7370 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7371 name
= string_printf ("<type_units_%d>",
7372 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7374 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7376 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7377 pst
->anonymous
= true;
7380 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7381 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7386 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7387 STMT_LIST is a DW_AT_stmt_list attribute. */
7389 static struct type_unit_group
*
7390 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7392 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7393 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7394 struct type_unit_group
*tu_group
;
7396 unsigned int line_offset
;
7397 struct type_unit_group type_unit_group_for_lookup
;
7399 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7400 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7402 /* Do we need to create a new group, or can we use an existing one? */
7406 line_offset
= DW_UNSND (stmt_list
);
7407 ++tu_stats
->nr_symtab_sharers
;
7411 /* Ugh, no stmt_list. Rare, but we have to handle it.
7412 We can do various things here like create one group per TU or
7413 spread them over multiple groups to split up the expansion work.
7414 To avoid worst case scenarios (too many groups or too large groups)
7415 we, umm, group them in bunches. */
7416 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7417 | (tu_stats
->nr_stmt_less_type_units
7418 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7419 ++tu_stats
->nr_stmt_less_type_units
;
7422 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7423 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7424 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7425 &type_unit_group_for_lookup
, INSERT
);
7428 tu_group
= (struct type_unit_group
*) *slot
;
7429 gdb_assert (tu_group
!= NULL
);
7433 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7434 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7436 ++tu_stats
->nr_symtabs
;
7442 /* Partial symbol tables. */
7444 /* Create a psymtab named NAME and assign it to PER_CU.
7446 The caller must fill in the following details:
7447 dirname, textlow, texthigh. */
7449 static dwarf2_psymtab
*
7450 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7451 dwarf2_per_objfile
*per_objfile
,
7454 struct objfile
*objfile
= per_objfile
->objfile
;
7455 dwarf2_psymtab
*pst
;
7457 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7459 pst
->psymtabs_addrmap_supported
= true;
7461 /* This is the glue that links PST into GDB's symbol API. */
7462 per_cu
->v
.psymtab
= pst
;
7467 /* DIE reader function for process_psymtab_comp_unit. */
7470 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7471 const gdb_byte
*info_ptr
,
7472 struct die_info
*comp_unit_die
,
7473 enum language pretend_language
)
7475 struct dwarf2_cu
*cu
= reader
->cu
;
7476 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7477 struct objfile
*objfile
= per_objfile
->objfile
;
7478 struct gdbarch
*gdbarch
= objfile
->arch ();
7479 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7481 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7482 dwarf2_psymtab
*pst
;
7483 enum pc_bounds_kind cu_bounds_kind
;
7484 const char *filename
;
7486 gdb_assert (! per_cu
->is_debug_types
);
7488 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7490 /* Allocate a new partial symbol table structure. */
7491 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7492 static const char artificial
[] = "<artificial>";
7493 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7494 if (filename
== NULL
)
7496 else if (strcmp (filename
, artificial
) == 0)
7498 debug_filename
.reset (concat (artificial
, "@",
7499 sect_offset_str (per_cu
->sect_off
),
7501 filename
= debug_filename
.get ();
7504 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7506 /* This must be done before calling dwarf2_build_include_psymtabs. */
7507 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7509 baseaddr
= objfile
->text_section_offset ();
7511 dwarf2_find_base_address (comp_unit_die
, cu
);
7513 /* Possibly set the default values of LOWPC and HIGHPC from
7515 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7516 &best_highpc
, cu
, pst
);
7517 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7520 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7523 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7525 /* Store the contiguous range if it is not empty; it can be
7526 empty for CUs with no code. */
7527 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7531 /* Check if comp unit has_children.
7532 If so, read the rest of the partial symbols from this comp unit.
7533 If not, there's no more debug_info for this comp unit. */
7534 if (comp_unit_die
->has_children
)
7536 struct partial_die_info
*first_die
;
7537 CORE_ADDR lowpc
, highpc
;
7539 lowpc
= ((CORE_ADDR
) -1);
7540 highpc
= ((CORE_ADDR
) 0);
7542 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7544 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7545 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7547 /* If we didn't find a lowpc, set it to highpc to avoid
7548 complaints from `maint check'. */
7549 if (lowpc
== ((CORE_ADDR
) -1))
7552 /* If the compilation unit didn't have an explicit address range,
7553 then use the information extracted from its child dies. */
7554 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7557 best_highpc
= highpc
;
7560 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7561 best_lowpc
+ baseaddr
)
7563 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7564 best_highpc
+ baseaddr
)
7567 end_psymtab_common (objfile
, pst
);
7569 if (!cu
->per_cu
->imported_symtabs_empty ())
7572 int len
= cu
->per_cu
->imported_symtabs_size ();
7574 /* Fill in 'dependencies' here; we fill in 'users' in a
7576 pst
->number_of_dependencies
= len
;
7578 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7579 for (i
= 0; i
< len
; ++i
)
7581 pst
->dependencies
[i
]
7582 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7585 cu
->per_cu
->imported_symtabs_free ();
7588 /* Get the list of files included in the current compilation unit,
7589 and build a psymtab for each of them. */
7590 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7592 if (dwarf_read_debug
)
7593 fprintf_unfiltered (gdb_stdlog
,
7594 "Psymtab for %s unit @%s: %s - %s"
7595 ", %d global, %d static syms\n",
7596 per_cu
->is_debug_types
? "type" : "comp",
7597 sect_offset_str (per_cu
->sect_off
),
7598 paddress (gdbarch
, pst
->text_low (objfile
)),
7599 paddress (gdbarch
, pst
->text_high (objfile
)),
7600 pst
->n_global_syms
, pst
->n_static_syms
);
7603 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7604 Process compilation unit THIS_CU for a psymtab. */
7607 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7608 dwarf2_per_objfile
*per_objfile
,
7609 bool want_partial_unit
,
7610 enum language pretend_language
)
7612 /* If this compilation unit was already read in, free the
7613 cached copy in order to read it in again. This is
7614 necessary because we skipped some symbols when we first
7615 read in the compilation unit (see load_partial_dies).
7616 This problem could be avoided, but the benefit is unclear. */
7617 per_objfile
->remove_cu (this_cu
);
7619 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7621 switch (reader
.comp_unit_die
->tag
)
7623 case DW_TAG_compile_unit
:
7624 this_cu
->unit_type
= DW_UT_compile
;
7626 case DW_TAG_partial_unit
:
7627 this_cu
->unit_type
= DW_UT_partial
;
7637 else if (this_cu
->is_debug_types
)
7638 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7639 reader
.comp_unit_die
);
7640 else if (want_partial_unit
7641 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7642 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7643 reader
.comp_unit_die
,
7646 this_cu
->lang
= reader
.cu
->language
;
7648 /* Age out any secondary CUs. */
7649 per_objfile
->age_comp_units ();
7652 /* Reader function for build_type_psymtabs. */
7655 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7656 const gdb_byte
*info_ptr
,
7657 struct die_info
*type_unit_die
)
7659 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7660 struct objfile
*objfile
= per_objfile
->objfile
;
7661 struct dwarf2_cu
*cu
= reader
->cu
;
7662 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7663 struct signatured_type
*sig_type
;
7664 struct type_unit_group
*tu_group
;
7665 struct attribute
*attr
;
7666 struct partial_die_info
*first_die
;
7667 CORE_ADDR lowpc
, highpc
;
7668 dwarf2_psymtab
*pst
;
7670 gdb_assert (per_cu
->is_debug_types
);
7671 sig_type
= (struct signatured_type
*) per_cu
;
7673 if (! type_unit_die
->has_children
)
7676 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7677 tu_group
= get_type_unit_group (cu
, attr
);
7679 if (tu_group
->tus
== nullptr)
7680 tu_group
->tus
= new std::vector
<signatured_type
*>;
7681 tu_group
->tus
->push_back (sig_type
);
7683 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7684 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7685 pst
->anonymous
= true;
7687 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7689 lowpc
= (CORE_ADDR
) -1;
7690 highpc
= (CORE_ADDR
) 0;
7691 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7693 end_psymtab_common (objfile
, pst
);
7696 /* Struct used to sort TUs by their abbreviation table offset. */
7698 struct tu_abbrev_offset
7700 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7701 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7704 signatured_type
*sig_type
;
7705 sect_offset abbrev_offset
;
7708 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7711 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7712 const struct tu_abbrev_offset
&b
)
7714 return a
.abbrev_offset
< b
.abbrev_offset
;
7717 /* Efficiently read all the type units.
7718 This does the bulk of the work for build_type_psymtabs.
7720 The efficiency is because we sort TUs by the abbrev table they use and
7721 only read each abbrev table once. In one program there are 200K TUs
7722 sharing 8K abbrev tables.
7724 The main purpose of this function is to support building the
7725 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7726 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7727 can collapse the search space by grouping them by stmt_list.
7728 The savings can be significant, in the same program from above the 200K TUs
7729 share 8K stmt_list tables.
7731 FUNC is expected to call get_type_unit_group, which will create the
7732 struct type_unit_group if necessary and add it to
7733 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7736 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7738 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7739 abbrev_table_up abbrev_table
;
7740 sect_offset abbrev_offset
;
7742 /* It's up to the caller to not call us multiple times. */
7743 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7745 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7748 /* TUs typically share abbrev tables, and there can be way more TUs than
7749 abbrev tables. Sort by abbrev table to reduce the number of times we
7750 read each abbrev table in.
7751 Alternatives are to punt or to maintain a cache of abbrev tables.
7752 This is simpler and efficient enough for now.
7754 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7755 symtab to use). Typically TUs with the same abbrev offset have the same
7756 stmt_list value too so in practice this should work well.
7758 The basic algorithm here is:
7760 sort TUs by abbrev table
7761 for each TU with same abbrev table:
7762 read abbrev table if first user
7763 read TU top level DIE
7764 [IWBN if DWO skeletons had DW_AT_stmt_list]
7767 if (dwarf_read_debug
)
7768 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7770 /* Sort in a separate table to maintain the order of all_type_units
7771 for .gdb_index: TU indices directly index all_type_units. */
7772 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7773 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7775 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7776 sorted_by_abbrev
.emplace_back
7777 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7778 sig_type
->per_cu
.sect_off
));
7780 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7781 sort_tu_by_abbrev_offset
);
7783 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7785 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7787 /* Switch to the next abbrev table if necessary. */
7788 if (abbrev_table
== NULL
7789 || tu
.abbrev_offset
!= abbrev_offset
)
7791 abbrev_offset
= tu
.abbrev_offset
;
7793 abbrev_table::read (per_objfile
->objfile
,
7794 &per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7795 ++tu_stats
->nr_uniq_abbrev_tables
;
7798 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7799 abbrev_table
.get (), nullptr, false);
7800 if (!reader
.dummy_p
)
7801 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7802 reader
.comp_unit_die
);
7806 /* Print collected type unit statistics. */
7809 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7811 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7813 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7814 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7815 per_objfile
->per_bfd
->all_type_units
.size ());
7816 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7817 tu_stats
->nr_uniq_abbrev_tables
);
7818 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7819 tu_stats
->nr_symtabs
);
7820 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7821 tu_stats
->nr_symtab_sharers
);
7822 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7823 tu_stats
->nr_stmt_less_type_units
);
7824 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7825 tu_stats
->nr_all_type_units_reallocs
);
7828 /* Traversal function for build_type_psymtabs. */
7831 build_type_psymtab_dependencies (void **slot
, void *info
)
7833 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7834 struct objfile
*objfile
= per_objfile
->objfile
;
7835 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7836 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7837 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7838 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7841 gdb_assert (len
> 0);
7842 gdb_assert (per_cu
->type_unit_group_p ());
7844 pst
->number_of_dependencies
= len
;
7845 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7846 for (i
= 0; i
< len
; ++i
)
7848 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7849 gdb_assert (iter
->per_cu
.is_debug_types
);
7850 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7851 iter
->type_unit_group
= tu_group
;
7854 delete tu_group
->tus
;
7855 tu_group
->tus
= nullptr;
7860 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7861 Build partial symbol tables for the .debug_types comp-units. */
7864 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7866 if (! create_all_type_units (per_objfile
))
7869 build_type_psymtabs_1 (per_objfile
);
7872 /* Traversal function for process_skeletonless_type_unit.
7873 Read a TU in a DWO file and build partial symbols for it. */
7876 process_skeletonless_type_unit (void **slot
, void *info
)
7878 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7879 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7880 struct signatured_type find_entry
, *entry
;
7882 /* If this TU doesn't exist in the global table, add it and read it in. */
7884 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7885 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7887 find_entry
.signature
= dwo_unit
->signature
;
7888 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7889 &find_entry
, INSERT
);
7890 /* If we've already seen this type there's nothing to do. What's happening
7891 is we're doing our own version of comdat-folding here. */
7895 /* This does the job that create_all_type_units would have done for
7897 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7898 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7901 /* This does the job that build_type_psymtabs_1 would have done. */
7902 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7903 if (!reader
.dummy_p
)
7904 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7905 reader
.comp_unit_die
);
7910 /* Traversal function for process_skeletonless_type_units. */
7913 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7915 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7917 if (dwo_file
->tus
!= NULL
)
7918 htab_traverse_noresize (dwo_file
->tus
.get (),
7919 process_skeletonless_type_unit
, info
);
7924 /* Scan all TUs of DWO files, verifying we've processed them.
7925 This is needed in case a TU was emitted without its skeleton.
7926 Note: This can't be done until we know what all the DWO files are. */
7929 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7931 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7932 if (get_dwp_file (per_objfile
) == NULL
7933 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7935 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7936 process_dwo_file_for_skeletonless_type_units
,
7941 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7944 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7946 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7948 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7953 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7955 /* Set the 'user' field only if it is not already set. */
7956 if (pst
->dependencies
[j
]->user
== NULL
)
7957 pst
->dependencies
[j
]->user
= pst
;
7962 /* Build the partial symbol table by doing a quick pass through the
7963 .debug_info and .debug_abbrev sections. */
7966 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7968 struct objfile
*objfile
= per_objfile
->objfile
;
7970 if (dwarf_read_debug
)
7972 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7973 objfile_name (objfile
));
7976 scoped_restore restore_reading_psyms
7977 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
7980 per_objfile
->per_bfd
->info
.read (objfile
);
7982 /* Any cached compilation units will be linked by the per-objfile
7983 read_in_chain. Make sure to free them when we're done. */
7984 free_cached_comp_units
freer (per_objfile
);
7986 build_type_psymtabs (per_objfile
);
7988 create_all_comp_units (per_objfile
);
7990 /* Create a temporary address map on a temporary obstack. We later
7991 copy this to the final obstack. */
7992 auto_obstack temp_obstack
;
7994 scoped_restore save_psymtabs_addrmap
7995 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7996 addrmap_create_mutable (&temp_obstack
));
7998 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8000 if (per_cu
->v
.psymtab
!= NULL
)
8001 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8003 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8007 /* This has to wait until we read the CUs, we need the list of DWOs. */
8008 process_skeletonless_type_units (per_objfile
);
8010 /* Now that all TUs have been processed we can fill in the dependencies. */
8011 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8013 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8014 build_type_psymtab_dependencies
, per_objfile
);
8017 if (dwarf_read_debug
)
8018 print_tu_stats (per_objfile
);
8020 set_partial_user (per_objfile
);
8022 objfile
->partial_symtabs
->psymtabs_addrmap
8023 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8024 objfile
->partial_symtabs
->obstack ());
8025 /* At this point we want to keep the address map. */
8026 save_psymtabs_addrmap
.release ();
8028 if (dwarf_read_debug
)
8029 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8030 objfile_name (objfile
));
8033 /* Load the partial DIEs for a secondary CU into memory.
8034 This is also used when rereading a primary CU with load_all_dies. */
8037 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8038 dwarf2_per_objfile
*per_objfile
,
8039 dwarf2_cu
*existing_cu
)
8041 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8043 if (!reader
.dummy_p
)
8045 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8048 /* Check if comp unit has_children.
8049 If so, read the rest of the partial symbols from this comp unit.
8050 If not, there's no more debug_info for this comp unit. */
8051 if (reader
.comp_unit_die
->has_children
)
8052 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8059 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8060 struct dwarf2_section_info
*section
,
8061 struct dwarf2_section_info
*abbrev_section
,
8062 unsigned int is_dwz
)
8064 const gdb_byte
*info_ptr
;
8065 struct objfile
*objfile
= per_objfile
->objfile
;
8067 if (dwarf_read_debug
)
8068 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8069 section
->get_name (),
8070 section
->get_file_name ());
8072 section
->read (objfile
);
8074 info_ptr
= section
->buffer
;
8076 while (info_ptr
< section
->buffer
+ section
->size
)
8078 struct dwarf2_per_cu_data
*this_cu
;
8080 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8082 comp_unit_head cu_header
;
8083 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8084 abbrev_section
, info_ptr
,
8085 rcuh_kind::COMPILE
);
8087 /* Save the compilation unit for later lookup. */
8088 if (cu_header
.unit_type
!= DW_UT_type
)
8089 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8092 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8093 sig_type
->signature
= cu_header
.signature
;
8094 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8095 this_cu
= &sig_type
->per_cu
;
8097 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8098 this_cu
->sect_off
= sect_off
;
8099 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8100 this_cu
->is_dwz
= is_dwz
;
8101 this_cu
->section
= section
;
8103 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8105 info_ptr
= info_ptr
+ this_cu
->length
;
8109 /* Create a list of all compilation units in OBJFILE.
8110 This is only done for -readnow and building partial symtabs. */
8113 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8115 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8116 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8117 &per_objfile
->per_bfd
->abbrev
, 0);
8119 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8121 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8124 /* Process all loaded DIEs for compilation unit CU, starting at
8125 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8126 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8127 DW_AT_ranges). See the comments of add_partial_subprogram on how
8128 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8131 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8132 CORE_ADDR
*highpc
, int set_addrmap
,
8133 struct dwarf2_cu
*cu
)
8135 struct partial_die_info
*pdi
;
8137 /* Now, march along the PDI's, descending into ones which have
8138 interesting children but skipping the children of the other ones,
8139 until we reach the end of the compilation unit. */
8147 /* Anonymous namespaces or modules have no name but have interesting
8148 children, so we need to look at them. Ditto for anonymous
8151 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8152 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8153 || pdi
->tag
== DW_TAG_imported_unit
8154 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8158 case DW_TAG_subprogram
:
8159 case DW_TAG_inlined_subroutine
:
8160 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8161 if (cu
->language
== language_cplus
)
8162 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8165 case DW_TAG_constant
:
8166 case DW_TAG_variable
:
8167 case DW_TAG_typedef
:
8168 case DW_TAG_union_type
:
8169 if (!pdi
->is_declaration
8170 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8172 add_partial_symbol (pdi
, cu
);
8175 case DW_TAG_class_type
:
8176 case DW_TAG_interface_type
:
8177 case DW_TAG_structure_type
:
8178 if (!pdi
->is_declaration
)
8180 add_partial_symbol (pdi
, cu
);
8182 if ((cu
->language
== language_rust
8183 || cu
->language
== language_cplus
) && pdi
->has_children
)
8184 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8187 case DW_TAG_enumeration_type
:
8188 if (!pdi
->is_declaration
)
8189 add_partial_enumeration (pdi
, cu
);
8191 case DW_TAG_base_type
:
8192 case DW_TAG_subrange_type
:
8193 /* File scope base type definitions are added to the partial
8195 add_partial_symbol (pdi
, cu
);
8197 case DW_TAG_namespace
:
8198 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8201 if (!pdi
->is_declaration
)
8202 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8204 case DW_TAG_imported_unit
:
8206 struct dwarf2_per_cu_data
*per_cu
;
8208 /* For now we don't handle imported units in type units. */
8209 if (cu
->per_cu
->is_debug_types
)
8211 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8212 " supported in type units [in module %s]"),
8213 objfile_name (cu
->per_objfile
->objfile
));
8216 per_cu
= dwarf2_find_containing_comp_unit
8217 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8219 /* Go read the partial unit, if needed. */
8220 if (per_cu
->v
.psymtab
== NULL
)
8221 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8224 cu
->per_cu
->imported_symtabs_push (per_cu
);
8227 case DW_TAG_imported_declaration
:
8228 add_partial_symbol (pdi
, cu
);
8235 /* If the die has a sibling, skip to the sibling. */
8237 pdi
= pdi
->die_sibling
;
8241 /* Functions used to compute the fully scoped name of a partial DIE.
8243 Normally, this is simple. For C++, the parent DIE's fully scoped
8244 name is concatenated with "::" and the partial DIE's name.
8245 Enumerators are an exception; they use the scope of their parent
8246 enumeration type, i.e. the name of the enumeration type is not
8247 prepended to the enumerator.
8249 There are two complexities. One is DW_AT_specification; in this
8250 case "parent" means the parent of the target of the specification,
8251 instead of the direct parent of the DIE. The other is compilers
8252 which do not emit DW_TAG_namespace; in this case we try to guess
8253 the fully qualified name of structure types from their members'
8254 linkage names. This must be done using the DIE's children rather
8255 than the children of any DW_AT_specification target. We only need
8256 to do this for structures at the top level, i.e. if the target of
8257 any DW_AT_specification (if any; otherwise the DIE itself) does not
8260 /* Compute the scope prefix associated with PDI's parent, in
8261 compilation unit CU. The result will be allocated on CU's
8262 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8263 field. NULL is returned if no prefix is necessary. */
8265 partial_die_parent_scope (struct partial_die_info
*pdi
,
8266 struct dwarf2_cu
*cu
)
8268 const char *grandparent_scope
;
8269 struct partial_die_info
*parent
, *real_pdi
;
8271 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8272 then this means the parent of the specification DIE. */
8275 while (real_pdi
->has_specification
)
8277 auto res
= find_partial_die (real_pdi
->spec_offset
,
8278 real_pdi
->spec_is_dwz
, cu
);
8283 parent
= real_pdi
->die_parent
;
8287 if (parent
->scope_set
)
8288 return parent
->scope
;
8292 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8294 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8295 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8296 Work around this problem here. */
8297 if (cu
->language
== language_cplus
8298 && parent
->tag
== DW_TAG_namespace
8299 && strcmp (parent
->name (cu
), "::") == 0
8300 && grandparent_scope
== NULL
)
8302 parent
->scope
= NULL
;
8303 parent
->scope_set
= 1;
8307 /* Nested subroutines in Fortran get a prefix. */
8308 if (pdi
->tag
== DW_TAG_enumerator
)
8309 /* Enumerators should not get the name of the enumeration as a prefix. */
8310 parent
->scope
= grandparent_scope
;
8311 else if (parent
->tag
== DW_TAG_namespace
8312 || parent
->tag
== DW_TAG_module
8313 || parent
->tag
== DW_TAG_structure_type
8314 || parent
->tag
== DW_TAG_class_type
8315 || parent
->tag
== DW_TAG_interface_type
8316 || parent
->tag
== DW_TAG_union_type
8317 || parent
->tag
== DW_TAG_enumeration_type
8318 || (cu
->language
== language_fortran
8319 && parent
->tag
== DW_TAG_subprogram
8320 && pdi
->tag
== DW_TAG_subprogram
))
8322 if (grandparent_scope
== NULL
)
8323 parent
->scope
= parent
->name (cu
);
8325 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8327 parent
->name (cu
), 0, cu
);
8331 /* FIXME drow/2004-04-01: What should we be doing with
8332 function-local names? For partial symbols, we should probably be
8334 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8335 dwarf_tag_name (parent
->tag
),
8336 sect_offset_str (pdi
->sect_off
));
8337 parent
->scope
= grandparent_scope
;
8340 parent
->scope_set
= 1;
8341 return parent
->scope
;
8344 /* Return the fully scoped name associated with PDI, from compilation unit
8345 CU. The result will be allocated with malloc. */
8347 static gdb::unique_xmalloc_ptr
<char>
8348 partial_die_full_name (struct partial_die_info
*pdi
,
8349 struct dwarf2_cu
*cu
)
8351 const char *parent_scope
;
8353 /* If this is a template instantiation, we can not work out the
8354 template arguments from partial DIEs. So, unfortunately, we have
8355 to go through the full DIEs. At least any work we do building
8356 types here will be reused if full symbols are loaded later. */
8357 if (pdi
->has_template_arguments
)
8361 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8363 struct die_info
*die
;
8364 struct attribute attr
;
8365 struct dwarf2_cu
*ref_cu
= cu
;
8367 /* DW_FORM_ref_addr is using section offset. */
8368 attr
.name
= (enum dwarf_attribute
) 0;
8369 attr
.form
= DW_FORM_ref_addr
;
8370 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8371 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8373 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8377 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8378 if (parent_scope
== NULL
)
8381 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8387 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8389 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8390 struct objfile
*objfile
= per_objfile
->objfile
;
8391 struct gdbarch
*gdbarch
= objfile
->arch ();
8393 const char *actual_name
= NULL
;
8396 baseaddr
= objfile
->text_section_offset ();
8398 gdb::unique_xmalloc_ptr
<char> built_actual_name
8399 = partial_die_full_name (pdi
, cu
);
8400 if (built_actual_name
!= NULL
)
8401 actual_name
= built_actual_name
.get ();
8403 if (actual_name
== NULL
)
8404 actual_name
= pdi
->name (cu
);
8406 partial_symbol psymbol
;
8407 memset (&psymbol
, 0, sizeof (psymbol
));
8408 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8409 psymbol
.ginfo
.section
= -1;
8411 /* The code below indicates that the psymbol should be installed by
8413 gdb::optional
<psymbol_placement
> where
;
8417 case DW_TAG_inlined_subroutine
:
8418 case DW_TAG_subprogram
:
8419 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8421 if (pdi
->is_external
8422 || cu
->language
== language_ada
8423 || (cu
->language
== language_fortran
8424 && pdi
->die_parent
!= NULL
8425 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8427 /* Normally, only "external" DIEs are part of the global scope.
8428 But in Ada and Fortran, we want to be able to access nested
8429 procedures globally. So all Ada and Fortran subprograms are
8430 stored in the global scope. */
8431 where
= psymbol_placement::GLOBAL
;
8434 where
= psymbol_placement::STATIC
;
8436 psymbol
.domain
= VAR_DOMAIN
;
8437 psymbol
.aclass
= LOC_BLOCK
;
8438 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8439 psymbol
.ginfo
.value
.address
= addr
;
8441 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8442 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8444 case DW_TAG_constant
:
8445 psymbol
.domain
= VAR_DOMAIN
;
8446 psymbol
.aclass
= LOC_STATIC
;
8447 where
= (pdi
->is_external
8448 ? psymbol_placement::GLOBAL
8449 : psymbol_placement::STATIC
);
8451 case DW_TAG_variable
:
8453 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8457 && !per_objfile
->per_bfd
->has_section_at_zero
)
8459 /* A global or static variable may also have been stripped
8460 out by the linker if unused, in which case its address
8461 will be nullified; do not add such variables into partial
8462 symbol table then. */
8464 else if (pdi
->is_external
)
8467 Don't enter into the minimal symbol tables as there is
8468 a minimal symbol table entry from the ELF symbols already.
8469 Enter into partial symbol table if it has a location
8470 descriptor or a type.
8471 If the location descriptor is missing, new_symbol will create
8472 a LOC_UNRESOLVED symbol, the address of the variable will then
8473 be determined from the minimal symbol table whenever the variable
8475 The address for the partial symbol table entry is not
8476 used by GDB, but it comes in handy for debugging partial symbol
8479 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8481 psymbol
.domain
= VAR_DOMAIN
;
8482 psymbol
.aclass
= LOC_STATIC
;
8483 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8484 psymbol
.ginfo
.value
.address
= addr
;
8485 where
= psymbol_placement::GLOBAL
;
8490 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8492 /* Static Variable. Skip symbols whose value we cannot know (those
8493 without location descriptors or constant values). */
8494 if (!has_loc
&& !pdi
->has_const_value
)
8497 psymbol
.domain
= VAR_DOMAIN
;
8498 psymbol
.aclass
= LOC_STATIC
;
8499 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8501 psymbol
.ginfo
.value
.address
= addr
;
8502 where
= psymbol_placement::STATIC
;
8505 case DW_TAG_typedef
:
8506 case DW_TAG_base_type
:
8507 case DW_TAG_subrange_type
:
8508 psymbol
.domain
= VAR_DOMAIN
;
8509 psymbol
.aclass
= LOC_TYPEDEF
;
8510 where
= psymbol_placement::STATIC
;
8512 case DW_TAG_imported_declaration
:
8513 case DW_TAG_namespace
:
8514 psymbol
.domain
= VAR_DOMAIN
;
8515 psymbol
.aclass
= LOC_TYPEDEF
;
8516 where
= psymbol_placement::GLOBAL
;
8519 /* With Fortran 77 there might be a "BLOCK DATA" module
8520 available without any name. If so, we skip the module as it
8521 doesn't bring any value. */
8522 if (actual_name
!= nullptr)
8524 psymbol
.domain
= MODULE_DOMAIN
;
8525 psymbol
.aclass
= LOC_TYPEDEF
;
8526 where
= psymbol_placement::GLOBAL
;
8529 case DW_TAG_class_type
:
8530 case DW_TAG_interface_type
:
8531 case DW_TAG_structure_type
:
8532 case DW_TAG_union_type
:
8533 case DW_TAG_enumeration_type
:
8534 /* Skip external references. The DWARF standard says in the section
8535 about "Structure, Union, and Class Type Entries": "An incomplete
8536 structure, union or class type is represented by a structure,
8537 union or class entry that does not have a byte size attribute
8538 and that has a DW_AT_declaration attribute." */
8539 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8542 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8543 static vs. global. */
8544 psymbol
.domain
= STRUCT_DOMAIN
;
8545 psymbol
.aclass
= LOC_TYPEDEF
;
8546 where
= (cu
->language
== language_cplus
8547 ? psymbol_placement::GLOBAL
8548 : psymbol_placement::STATIC
);
8550 case DW_TAG_enumerator
:
8551 psymbol
.domain
= VAR_DOMAIN
;
8552 psymbol
.aclass
= LOC_CONST
;
8553 where
= (cu
->language
== language_cplus
8554 ? psymbol_placement::GLOBAL
8555 : psymbol_placement::STATIC
);
8561 if (where
.has_value ())
8563 if (built_actual_name
!= nullptr)
8564 actual_name
= objfile
->intern (actual_name
);
8565 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8566 psymbol
.ginfo
.set_linkage_name (actual_name
);
8569 psymbol
.ginfo
.set_demangled_name (actual_name
,
8570 &objfile
->objfile_obstack
);
8571 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8573 add_psymbol_to_list (psymbol
, *where
, objfile
);
8577 /* Read a partial die corresponding to a namespace; also, add a symbol
8578 corresponding to that namespace to the symbol table. NAMESPACE is
8579 the name of the enclosing namespace. */
8582 add_partial_namespace (struct partial_die_info
*pdi
,
8583 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8584 int set_addrmap
, struct dwarf2_cu
*cu
)
8586 /* Add a symbol for the namespace. */
8588 add_partial_symbol (pdi
, cu
);
8590 /* Now scan partial symbols in that namespace. */
8592 if (pdi
->has_children
)
8593 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8596 /* Read a partial die corresponding to a Fortran module. */
8599 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8600 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8602 /* Add a symbol for the namespace. */
8604 add_partial_symbol (pdi
, cu
);
8606 /* Now scan partial symbols in that module. */
8608 if (pdi
->has_children
)
8609 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8612 /* Read a partial die corresponding to a subprogram or an inlined
8613 subprogram and create a partial symbol for that subprogram.
8614 When the CU language allows it, this routine also defines a partial
8615 symbol for each nested subprogram that this subprogram contains.
8616 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8617 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8619 PDI may also be a lexical block, in which case we simply search
8620 recursively for subprograms defined inside that lexical block.
8621 Again, this is only performed when the CU language allows this
8622 type of definitions. */
8625 add_partial_subprogram (struct partial_die_info
*pdi
,
8626 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8627 int set_addrmap
, struct dwarf2_cu
*cu
)
8629 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8631 if (pdi
->has_pc_info
)
8633 if (pdi
->lowpc
< *lowpc
)
8634 *lowpc
= pdi
->lowpc
;
8635 if (pdi
->highpc
> *highpc
)
8636 *highpc
= pdi
->highpc
;
8639 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8640 struct gdbarch
*gdbarch
= objfile
->arch ();
8642 CORE_ADDR this_highpc
;
8643 CORE_ADDR this_lowpc
;
8645 baseaddr
= objfile
->text_section_offset ();
8647 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8648 pdi
->lowpc
+ baseaddr
)
8651 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8652 pdi
->highpc
+ baseaddr
)
8654 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8655 this_lowpc
, this_highpc
- 1,
8656 cu
->per_cu
->v
.psymtab
);
8660 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8662 if (!pdi
->is_declaration
)
8663 /* Ignore subprogram DIEs that do not have a name, they are
8664 illegal. Do not emit a complaint at this point, we will
8665 do so when we convert this psymtab into a symtab. */
8667 add_partial_symbol (pdi
, cu
);
8671 if (! pdi
->has_children
)
8674 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8676 pdi
= pdi
->die_child
;
8680 if (pdi
->tag
== DW_TAG_subprogram
8681 || pdi
->tag
== DW_TAG_inlined_subroutine
8682 || pdi
->tag
== DW_TAG_lexical_block
)
8683 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8684 pdi
= pdi
->die_sibling
;
8689 /* Read a partial die corresponding to an enumeration type. */
8692 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8693 struct dwarf2_cu
*cu
)
8695 struct partial_die_info
*pdi
;
8697 if (enum_pdi
->name (cu
) != NULL
)
8698 add_partial_symbol (enum_pdi
, cu
);
8700 pdi
= enum_pdi
->die_child
;
8703 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8704 complaint (_("malformed enumerator DIE ignored"));
8706 add_partial_symbol (pdi
, cu
);
8707 pdi
= pdi
->die_sibling
;
8711 /* Return the initial uleb128 in the die at INFO_PTR. */
8714 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8716 unsigned int bytes_read
;
8718 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8721 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8722 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8724 Return the corresponding abbrev, or NULL if the number is zero (indicating
8725 an empty DIE). In either case *BYTES_READ will be set to the length of
8726 the initial number. */
8728 static struct abbrev_info
*
8729 peek_die_abbrev (const die_reader_specs
&reader
,
8730 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8732 dwarf2_cu
*cu
= reader
.cu
;
8733 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8734 unsigned int abbrev_number
8735 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8737 if (abbrev_number
== 0)
8740 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8743 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8744 " at offset %s [in module %s]"),
8745 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8746 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8752 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8753 Returns a pointer to the end of a series of DIEs, terminated by an empty
8754 DIE. Any children of the skipped DIEs will also be skipped. */
8756 static const gdb_byte
*
8757 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8761 unsigned int bytes_read
;
8762 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8765 return info_ptr
+ bytes_read
;
8767 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8771 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8772 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8773 abbrev corresponding to that skipped uleb128 should be passed in
8774 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8777 static const gdb_byte
*
8778 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8779 struct abbrev_info
*abbrev
)
8781 unsigned int bytes_read
;
8782 struct attribute attr
;
8783 bfd
*abfd
= reader
->abfd
;
8784 struct dwarf2_cu
*cu
= reader
->cu
;
8785 const gdb_byte
*buffer
= reader
->buffer
;
8786 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8787 unsigned int form
, i
;
8789 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8791 /* The only abbrev we care about is DW_AT_sibling. */
8792 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8795 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8797 if (attr
.form
== DW_FORM_ref_addr
)
8798 complaint (_("ignoring absolute DW_AT_sibling"));
8801 sect_offset off
= attr
.get_ref_die_offset ();
8802 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8804 if (sibling_ptr
< info_ptr
)
8805 complaint (_("DW_AT_sibling points backwards"));
8806 else if (sibling_ptr
> reader
->buffer_end
)
8807 reader
->die_section
->overflow_complaint ();
8813 /* If it isn't DW_AT_sibling, skip this attribute. */
8814 form
= abbrev
->attrs
[i
].form
;
8818 case DW_FORM_ref_addr
:
8819 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8820 and later it is offset sized. */
8821 if (cu
->header
.version
== 2)
8822 info_ptr
+= cu
->header
.addr_size
;
8824 info_ptr
+= cu
->header
.offset_size
;
8826 case DW_FORM_GNU_ref_alt
:
8827 info_ptr
+= cu
->header
.offset_size
;
8830 info_ptr
+= cu
->header
.addr_size
;
8838 case DW_FORM_flag_present
:
8839 case DW_FORM_implicit_const
:
8856 case DW_FORM_ref_sig8
:
8859 case DW_FORM_data16
:
8862 case DW_FORM_string
:
8863 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8864 info_ptr
+= bytes_read
;
8866 case DW_FORM_sec_offset
:
8868 case DW_FORM_GNU_strp_alt
:
8869 info_ptr
+= cu
->header
.offset_size
;
8871 case DW_FORM_exprloc
:
8873 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8874 info_ptr
+= bytes_read
;
8876 case DW_FORM_block1
:
8877 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8879 case DW_FORM_block2
:
8880 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8882 case DW_FORM_block4
:
8883 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8889 case DW_FORM_ref_udata
:
8890 case DW_FORM_GNU_addr_index
:
8891 case DW_FORM_GNU_str_index
:
8892 case DW_FORM_rnglistx
:
8893 case DW_FORM_loclistx
:
8894 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8896 case DW_FORM_indirect
:
8897 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8898 info_ptr
+= bytes_read
;
8899 /* We need to continue parsing from here, so just go back to
8901 goto skip_attribute
;
8904 error (_("Dwarf Error: Cannot handle %s "
8905 "in DWARF reader [in module %s]"),
8906 dwarf_form_name (form
),
8907 bfd_get_filename (abfd
));
8911 if (abbrev
->has_children
)
8912 return skip_children (reader
, info_ptr
);
8917 /* Locate ORIG_PDI's sibling.
8918 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8920 static const gdb_byte
*
8921 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8922 struct partial_die_info
*orig_pdi
,
8923 const gdb_byte
*info_ptr
)
8925 /* Do we know the sibling already? */
8927 if (orig_pdi
->sibling
)
8928 return orig_pdi
->sibling
;
8930 /* Are there any children to deal with? */
8932 if (!orig_pdi
->has_children
)
8935 /* Skip the children the long way. */
8937 return skip_children (reader
, info_ptr
);
8940 /* Expand this partial symbol table into a full symbol table. SELF is
8944 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8946 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8948 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8950 /* If this psymtab is constructed from a debug-only objfile, the
8951 has_section_at_zero flag will not necessarily be correct. We
8952 can get the correct value for this flag by looking at the data
8953 associated with the (presumably stripped) associated objfile. */
8954 if (objfile
->separate_debug_objfile_backlink
)
8956 dwarf2_per_objfile
*per_objfile_backlink
8957 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8959 per_objfile
->per_bfd
->has_section_at_zero
8960 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8963 expand_psymtab (objfile
);
8965 process_cu_includes (per_objfile
);
8968 /* Reading in full CUs. */
8970 /* Add PER_CU to the queue. */
8973 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8974 dwarf2_per_objfile
*per_objfile
,
8975 enum language pretend_language
)
8978 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
8981 /* If PER_CU is not yet queued, add it to the queue.
8982 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8984 The result is non-zero if PER_CU was queued, otherwise the result is zero
8985 meaning either PER_CU is already queued or it is already loaded.
8987 N.B. There is an invariant here that if a CU is queued then it is loaded.
8988 The caller is required to load PER_CU if we return non-zero. */
8991 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8992 dwarf2_per_cu_data
*per_cu
,
8993 dwarf2_per_objfile
*per_objfile
,
8994 enum language pretend_language
)
8996 /* We may arrive here during partial symbol reading, if we need full
8997 DIEs to process an unusual case (e.g. template arguments). Do
8998 not queue PER_CU, just tell our caller to load its DIEs. */
8999 if (per_cu
->per_bfd
->reading_partial_symbols
)
9001 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9003 if (cu
== NULL
|| cu
->dies
== NULL
)
9008 /* Mark the dependence relation so that we don't flush PER_CU
9010 if (dependent_cu
!= NULL
)
9011 dwarf2_add_dependence (dependent_cu
, per_cu
);
9013 /* If it's already on the queue, we have nothing to do. */
9017 /* If the compilation unit is already loaded, just mark it as
9019 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9026 /* Add it to the queue. */
9027 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9032 /* Process the queue. */
9035 process_queue (dwarf2_per_objfile
*per_objfile
)
9037 if (dwarf_read_debug
)
9039 fprintf_unfiltered (gdb_stdlog
,
9040 "Expanding one or more symtabs of objfile %s ...\n",
9041 objfile_name (per_objfile
->objfile
));
9044 /* The queue starts out with one item, but following a DIE reference
9045 may load a new CU, adding it to the end of the queue. */
9046 while (!per_objfile
->per_bfd
->queue
.empty ())
9048 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
.front ();
9049 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9051 if (!per_objfile
->symtab_set_p (per_cu
))
9053 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9055 /* Skip dummy CUs. */
9058 unsigned int debug_print_threshold
;
9061 if (per_cu
->is_debug_types
)
9063 struct signatured_type
*sig_type
=
9064 (struct signatured_type
*) per_cu
;
9066 sprintf (buf
, "TU %s at offset %s",
9067 hex_string (sig_type
->signature
),
9068 sect_offset_str (per_cu
->sect_off
));
9069 /* There can be 100s of TUs.
9070 Only print them in verbose mode. */
9071 debug_print_threshold
= 2;
9075 sprintf (buf
, "CU at offset %s",
9076 sect_offset_str (per_cu
->sect_off
));
9077 debug_print_threshold
= 1;
9080 if (dwarf_read_debug
>= debug_print_threshold
)
9081 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9083 if (per_cu
->is_debug_types
)
9084 process_full_type_unit (cu
, item
.pretend_language
);
9086 process_full_comp_unit (cu
, item
.pretend_language
);
9088 if (dwarf_read_debug
>= debug_print_threshold
)
9089 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9094 per_objfile
->per_bfd
->queue
.pop ();
9097 if (dwarf_read_debug
)
9099 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9100 objfile_name (per_objfile
->objfile
));
9104 /* Read in full symbols for PST, and anything it depends on. */
9107 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9109 gdb_assert (!readin_p (objfile
));
9111 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9112 free_cached_comp_units
freer (per_objfile
);
9113 expand_dependencies (objfile
);
9115 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9116 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9119 /* See psympriv.h. */
9122 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9124 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9125 return per_objfile
->symtab_set_p (per_cu_data
);
9128 /* See psympriv.h. */
9131 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9133 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9134 return per_objfile
->get_symtab (per_cu_data
);
9137 /* Trivial hash function for die_info: the hash value of a DIE
9138 is its offset in .debug_info for this objfile. */
9141 die_hash (const void *item
)
9143 const struct die_info
*die
= (const struct die_info
*) item
;
9145 return to_underlying (die
->sect_off
);
9148 /* Trivial comparison function for die_info structures: two DIEs
9149 are equal if they have the same offset. */
9152 die_eq (const void *item_lhs
, const void *item_rhs
)
9154 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9155 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9157 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9160 /* Load the DIEs associated with PER_CU into memory. */
9163 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9164 dwarf2_per_objfile
*per_objfile
,
9166 enum language pretend_language
)
9168 gdb_assert (! this_cu
->is_debug_types
);
9170 dwarf2_cu
*existing_cu
= per_objfile
->get_cu (this_cu
);
9171 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9175 struct dwarf2_cu
*cu
= reader
.cu
;
9176 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9178 gdb_assert (cu
->die_hash
== NULL
);
9180 htab_create_alloc_ex (cu
->header
.length
/ 12,
9184 &cu
->comp_unit_obstack
,
9185 hashtab_obstack_allocate
,
9186 dummy_obstack_deallocate
);
9188 if (reader
.comp_unit_die
->has_children
)
9189 reader
.comp_unit_die
->child
9190 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9191 &info_ptr
, reader
.comp_unit_die
);
9192 cu
->dies
= reader
.comp_unit_die
;
9193 /* comp_unit_die is not stored in die_hash, no need. */
9195 /* We try not to read any attributes in this function, because not
9196 all CUs needed for references have been loaded yet, and symbol
9197 table processing isn't initialized. But we have to set the CU language,
9198 or we won't be able to build types correctly.
9199 Similarly, if we do not read the producer, we can not apply
9200 producer-specific interpretation. */
9201 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9206 /* Add a DIE to the delayed physname list. */
9209 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9210 const char *name
, struct die_info
*die
,
9211 struct dwarf2_cu
*cu
)
9213 struct delayed_method_info mi
;
9215 mi
.fnfield_index
= fnfield_index
;
9219 cu
->method_list
.push_back (mi
);
9222 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9223 "const" / "volatile". If so, decrements LEN by the length of the
9224 modifier and return true. Otherwise return false. */
9228 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9230 size_t mod_len
= sizeof (mod
) - 1;
9231 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9239 /* Compute the physnames of any methods on the CU's method list.
9241 The computation of method physnames is delayed in order to avoid the
9242 (bad) condition that one of the method's formal parameters is of an as yet
9246 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9248 /* Only C++ delays computing physnames. */
9249 if (cu
->method_list
.empty ())
9251 gdb_assert (cu
->language
== language_cplus
);
9253 for (const delayed_method_info
&mi
: cu
->method_list
)
9255 const char *physname
;
9256 struct fn_fieldlist
*fn_flp
9257 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9258 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9259 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9260 = physname
? physname
: "";
9262 /* Since there's no tag to indicate whether a method is a
9263 const/volatile overload, extract that information out of the
9265 if (physname
!= NULL
)
9267 size_t len
= strlen (physname
);
9271 if (physname
[len
] == ')') /* shortcut */
9273 else if (check_modifier (physname
, len
, " const"))
9274 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9275 else if (check_modifier (physname
, len
, " volatile"))
9276 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9283 /* The list is no longer needed. */
9284 cu
->method_list
.clear ();
9287 /* Go objects should be embedded in a DW_TAG_module DIE,
9288 and it's not clear if/how imported objects will appear.
9289 To keep Go support simple until that's worked out,
9290 go back through what we've read and create something usable.
9291 We could do this while processing each DIE, and feels kinda cleaner,
9292 but that way is more invasive.
9293 This is to, for example, allow the user to type "p var" or "b main"
9294 without having to specify the package name, and allow lookups
9295 of module.object to work in contexts that use the expression
9299 fixup_go_packaging (struct dwarf2_cu
*cu
)
9301 gdb::unique_xmalloc_ptr
<char> package_name
;
9302 struct pending
*list
;
9305 for (list
= *cu
->get_builder ()->get_global_symbols ();
9309 for (i
= 0; i
< list
->nsyms
; ++i
)
9311 struct symbol
*sym
= list
->symbol
[i
];
9313 if (sym
->language () == language_go
9314 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9316 gdb::unique_xmalloc_ptr
<char> this_package_name
9317 (go_symbol_package_name (sym
));
9319 if (this_package_name
== NULL
)
9321 if (package_name
== NULL
)
9322 package_name
= std::move (this_package_name
);
9325 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9326 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9327 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9328 (symbol_symtab (sym
) != NULL
9329 ? symtab_to_filename_for_display
9330 (symbol_symtab (sym
))
9331 : objfile_name (objfile
)),
9332 this_package_name
.get (), package_name
.get ());
9338 if (package_name
!= NULL
)
9340 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9341 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9342 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9343 saved_package_name
);
9346 sym
= new (&objfile
->objfile_obstack
) symbol
;
9347 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9348 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9349 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9350 e.g., "main" finds the "main" module and not C's main(). */
9351 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9352 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9353 SYMBOL_TYPE (sym
) = type
;
9355 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9359 /* Allocate a fully-qualified name consisting of the two parts on the
9363 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9365 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9368 /* A helper that allocates a variant part to attach to a Rust enum
9369 type. OBSTACK is where the results should be allocated. TYPE is
9370 the type we're processing. DISCRIMINANT_INDEX is the index of the
9371 discriminant. It must be the index of one of the fields of TYPE.
9372 DEFAULT_INDEX is the index of the default field; or -1 if there is
9373 no default. RANGES is indexed by "effective" field number (the
9374 field index, but omitting the discriminant and default fields) and
9375 must hold the discriminant values used by the variants. Note that
9376 RANGES must have a lifetime at least as long as OBSTACK -- either
9377 already allocated on it, or static. */
9380 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9381 int discriminant_index
, int default_index
,
9382 gdb::array_view
<discriminant_range
> ranges
)
9384 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9385 must be handled by the caller. */
9386 gdb_assert (discriminant_index
>= 0
9387 && discriminant_index
< type
->num_fields ());
9388 gdb_assert (default_index
== -1
9389 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9391 /* We have one variant for each non-discriminant field. */
9392 int n_variants
= type
->num_fields () - 1;
9394 variant
*variants
= new (obstack
) variant
[n_variants
];
9397 for (int i
= 0; i
< type
->num_fields (); ++i
)
9399 if (i
== discriminant_index
)
9402 variants
[var_idx
].first_field
= i
;
9403 variants
[var_idx
].last_field
= i
+ 1;
9405 /* The default field does not need a range, but other fields do.
9406 We skipped the discriminant above. */
9407 if (i
!= default_index
)
9409 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9416 gdb_assert (range_idx
== ranges
.size ());
9417 gdb_assert (var_idx
== n_variants
);
9419 variant_part
*part
= new (obstack
) variant_part
;
9420 part
->discriminant_index
= discriminant_index
;
9421 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9422 discriminant_index
));
9423 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9425 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9426 gdb::array_view
<variant_part
> *prop_value
9427 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9429 struct dynamic_prop prop
;
9430 prop
.kind
= PROP_VARIANT_PARTS
;
9431 prop
.data
.variant_parts
= prop_value
;
9433 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9436 /* Some versions of rustc emitted enums in an unusual way.
9438 Ordinary enums were emitted as unions. The first element of each
9439 structure in the union was named "RUST$ENUM$DISR". This element
9440 held the discriminant.
9442 These versions of Rust also implemented the "non-zero"
9443 optimization. When the enum had two values, and one is empty and
9444 the other holds a pointer that cannot be zero, the pointer is used
9445 as the discriminant, with a zero value meaning the empty variant.
9446 Here, the union's first member is of the form
9447 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9448 where the fieldnos are the indices of the fields that should be
9449 traversed in order to find the field (which may be several fields deep)
9450 and the variantname is the name of the variant of the case when the
9453 This function recognizes whether TYPE is of one of these forms,
9454 and, if so, smashes it to be a variant type. */
9457 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9459 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9461 /* We don't need to deal with empty enums. */
9462 if (type
->num_fields () == 0)
9465 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9466 if (type
->num_fields () == 1
9467 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9469 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9471 /* Decode the field name to find the offset of the
9473 ULONGEST bit_offset
= 0;
9474 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9475 while (name
[0] >= '0' && name
[0] <= '9')
9478 unsigned long index
= strtoul (name
, &tail
, 10);
9481 || index
>= field_type
->num_fields ()
9482 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9483 != FIELD_LOC_KIND_BITPOS
))
9485 complaint (_("Could not parse Rust enum encoding string \"%s\""
9487 TYPE_FIELD_NAME (type
, 0),
9488 objfile_name (objfile
));
9493 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9494 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9497 /* Smash this type to be a structure type. We have to do this
9498 because the type has already been recorded. */
9499 type
->set_code (TYPE_CODE_STRUCT
);
9500 type
->set_num_fields (3);
9501 /* Save the field we care about. */
9502 struct field saved_field
= type
->field (0);
9504 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9506 /* Put the discriminant at index 0. */
9507 type
->field (0).set_type (field_type
);
9508 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9509 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9510 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9512 /* The order of fields doesn't really matter, so put the real
9513 field at index 1 and the data-less field at index 2. */
9514 type
->field (1) = saved_field
;
9515 TYPE_FIELD_NAME (type
, 1)
9516 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9517 TYPE_FIELD_TYPE (type
, 1)->set_name
9518 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9519 TYPE_FIELD_NAME (type
, 1)));
9521 const char *dataless_name
9522 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9524 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9526 type
->field (2).set_type (dataless_type
);
9527 /* NAME points into the original discriminant name, which
9528 already has the correct lifetime. */
9529 TYPE_FIELD_NAME (type
, 2) = name
;
9530 SET_FIELD_BITPOS (type
->field (2), 0);
9532 /* Indicate that this is a variant type. */
9533 static discriminant_range ranges
[1] = { { 0, 0 } };
9534 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9536 /* A union with a single anonymous field is probably an old-style
9538 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9540 /* Smash this type to be a structure type. We have to do this
9541 because the type has already been recorded. */
9542 type
->set_code (TYPE_CODE_STRUCT
);
9544 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9545 const char *variant_name
9546 = rust_last_path_segment (field_type
->name ());
9547 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9548 field_type
->set_name
9549 (rust_fully_qualify (&objfile
->objfile_obstack
,
9550 type
->name (), variant_name
));
9554 struct type
*disr_type
= nullptr;
9555 for (int i
= 0; i
< type
->num_fields (); ++i
)
9557 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9559 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9561 /* All fields of a true enum will be structs. */
9564 else if (disr_type
->num_fields () == 0)
9566 /* Could be data-less variant, so keep going. */
9567 disr_type
= nullptr;
9569 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9570 "RUST$ENUM$DISR") != 0)
9572 /* Not a Rust enum. */
9582 /* If we got here without a discriminant, then it's probably
9584 if (disr_type
== nullptr)
9587 /* Smash this type to be a structure type. We have to do this
9588 because the type has already been recorded. */
9589 type
->set_code (TYPE_CODE_STRUCT
);
9591 /* Make space for the discriminant field. */
9592 struct field
*disr_field
= &disr_type
->field (0);
9594 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9595 * sizeof (struct field
)));
9596 memcpy (new_fields
+ 1, type
->fields (),
9597 type
->num_fields () * sizeof (struct field
));
9598 type
->set_fields (new_fields
);
9599 type
->set_num_fields (type
->num_fields () + 1);
9601 /* Install the discriminant at index 0 in the union. */
9602 type
->field (0) = *disr_field
;
9603 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9604 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9606 /* We need a way to find the correct discriminant given a
9607 variant name. For convenience we build a map here. */
9608 struct type
*enum_type
= disr_field
->type ();
9609 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9610 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9612 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9615 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9616 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9620 int n_fields
= type
->num_fields ();
9621 /* We don't need a range entry for the discriminant, but we do
9622 need one for every other field, as there is no default
9624 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9627 /* Skip the discriminant here. */
9628 for (int i
= 1; i
< n_fields
; ++i
)
9630 /* Find the final word in the name of this variant's type.
9631 That name can be used to look up the correct
9633 const char *variant_name
9634 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9636 auto iter
= discriminant_map
.find (variant_name
);
9637 if (iter
!= discriminant_map
.end ())
9639 ranges
[i
].low
= iter
->second
;
9640 ranges
[i
].high
= iter
->second
;
9643 /* Remove the discriminant field, if it exists. */
9644 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9645 if (sub_type
->num_fields () > 0)
9647 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9648 sub_type
->set_fields (sub_type
->fields () + 1);
9650 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9652 (rust_fully_qualify (&objfile
->objfile_obstack
,
9653 type
->name (), variant_name
));
9656 /* Indicate that this is a variant type. */
9657 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9658 gdb::array_view
<discriminant_range
> (ranges
,
9663 /* Rewrite some Rust unions to be structures with variants parts. */
9666 rust_union_quirks (struct dwarf2_cu
*cu
)
9668 gdb_assert (cu
->language
== language_rust
);
9669 for (type
*type_
: cu
->rust_unions
)
9670 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9671 /* We don't need this any more. */
9672 cu
->rust_unions
.clear ();
9677 type_unit_group_unshareable
*
9678 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9680 auto iter
= this->m_type_units
.find (tu_group
);
9681 if (iter
!= this->m_type_units
.end ())
9682 return iter
->second
.get ();
9684 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9685 type_unit_group_unshareable
*result
= uniq
.get ();
9686 this->m_type_units
[tu_group
] = std::move (uniq
);
9691 dwarf2_per_objfile::get_type_for_signatured_type
9692 (signatured_type
*sig_type
) const
9694 auto iter
= this->m_type_map
.find (sig_type
);
9695 if (iter
== this->m_type_map
.end ())
9698 return iter
->second
;
9701 void dwarf2_per_objfile::set_type_for_signatured_type
9702 (signatured_type
*sig_type
, struct type
*type
)
9704 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9706 this->m_type_map
[sig_type
] = type
;
9709 /* A helper function for computing the list of all symbol tables
9710 included by PER_CU. */
9713 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9714 htab_t all_children
, htab_t all_type_symtabs
,
9715 dwarf2_per_cu_data
*per_cu
,
9716 dwarf2_per_objfile
*per_objfile
,
9717 struct compunit_symtab
*immediate_parent
)
9719 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9722 /* This inclusion and its children have been processed. */
9728 /* Only add a CU if it has a symbol table. */
9729 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9732 /* If this is a type unit only add its symbol table if we haven't
9733 seen it yet (type unit per_cu's can share symtabs). */
9734 if (per_cu
->is_debug_types
)
9736 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9740 result
->push_back (cust
);
9741 if (cust
->user
== NULL
)
9742 cust
->user
= immediate_parent
;
9747 result
->push_back (cust
);
9748 if (cust
->user
== NULL
)
9749 cust
->user
= immediate_parent
;
9753 if (!per_cu
->imported_symtabs_empty ())
9754 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9756 recursively_compute_inclusions (result
, all_children
,
9757 all_type_symtabs
, ptr
, per_objfile
,
9762 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9766 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9767 dwarf2_per_objfile
*per_objfile
)
9769 gdb_assert (! per_cu
->is_debug_types
);
9771 if (!per_cu
->imported_symtabs_empty ())
9774 std::vector
<compunit_symtab
*> result_symtabs
;
9775 htab_t all_children
, all_type_symtabs
;
9776 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9778 /* If we don't have a symtab, we can just skip this case. */
9782 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9783 NULL
, xcalloc
, xfree
);
9784 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9785 NULL
, xcalloc
, xfree
);
9787 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9789 recursively_compute_inclusions (&result_symtabs
, all_children
,
9790 all_type_symtabs
, ptr
, per_objfile
,
9794 /* Now we have a transitive closure of all the included symtabs. */
9795 len
= result_symtabs
.size ();
9797 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9798 struct compunit_symtab
*, len
+ 1);
9799 memcpy (cust
->includes
, result_symtabs
.data (),
9800 len
* sizeof (compunit_symtab
*));
9801 cust
->includes
[len
] = NULL
;
9803 htab_delete (all_children
);
9804 htab_delete (all_type_symtabs
);
9808 /* Compute the 'includes' field for the symtabs of all the CUs we just
9812 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9814 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9816 if (! iter
->is_debug_types
)
9817 compute_compunit_symtab_includes (iter
, per_objfile
);
9820 per_objfile
->per_bfd
->just_read_cus
.clear ();
9823 /* Generate full symbol information for CU, whose DIEs have
9824 already been loaded into memory. */
9827 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9829 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9830 struct objfile
*objfile
= per_objfile
->objfile
;
9831 struct gdbarch
*gdbarch
= objfile
->arch ();
9832 CORE_ADDR lowpc
, highpc
;
9833 struct compunit_symtab
*cust
;
9835 struct block
*static_block
;
9838 baseaddr
= objfile
->text_section_offset ();
9840 /* Clear the list here in case something was left over. */
9841 cu
->method_list
.clear ();
9843 cu
->language
= pretend_language
;
9844 cu
->language_defn
= language_def (cu
->language
);
9846 /* Do line number decoding in read_file_scope () */
9847 process_die (cu
->dies
, cu
);
9849 /* For now fudge the Go package. */
9850 if (cu
->language
== language_go
)
9851 fixup_go_packaging (cu
);
9853 /* Now that we have processed all the DIEs in the CU, all the types
9854 should be complete, and it should now be safe to compute all of the
9856 compute_delayed_physnames (cu
);
9858 if (cu
->language
== language_rust
)
9859 rust_union_quirks (cu
);
9861 /* Some compilers don't define a DW_AT_high_pc attribute for the
9862 compilation unit. If the DW_AT_high_pc is missing, synthesize
9863 it, by scanning the DIE's below the compilation unit. */
9864 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9866 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9867 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9869 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9870 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9871 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9872 addrmap to help ensure it has an accurate map of pc values belonging to
9874 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9876 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9877 SECT_OFF_TEXT (objfile
),
9882 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9884 /* Set symtab language to language from DW_AT_language. If the
9885 compilation is from a C file generated by language preprocessors, do
9886 not set the language if it was already deduced by start_subfile. */
9887 if (!(cu
->language
== language_c
9888 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9889 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9891 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9892 produce DW_AT_location with location lists but it can be possibly
9893 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9894 there were bugs in prologue debug info, fixed later in GCC-4.5
9895 by "unwind info for epilogues" patch (which is not directly related).
9897 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9898 needed, it would be wrong due to missing DW_AT_producer there.
9900 Still one can confuse GDB by using non-standard GCC compilation
9901 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9903 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9904 cust
->locations_valid
= 1;
9906 if (gcc_4_minor
>= 5)
9907 cust
->epilogue_unwind_valid
= 1;
9909 cust
->call_site_htab
= cu
->call_site_htab
;
9912 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9914 /* Push it for inclusion processing later. */
9915 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9917 /* Not needed any more. */
9918 cu
->reset_builder ();
9921 /* Generate full symbol information for type unit CU, whose DIEs have
9922 already been loaded into memory. */
9925 process_full_type_unit (dwarf2_cu
*cu
,
9926 enum language pretend_language
)
9928 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9929 struct objfile
*objfile
= per_objfile
->objfile
;
9930 struct compunit_symtab
*cust
;
9931 struct signatured_type
*sig_type
;
9933 gdb_assert (cu
->per_cu
->is_debug_types
);
9934 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9936 /* Clear the list here in case something was left over. */
9937 cu
->method_list
.clear ();
9939 cu
->language
= pretend_language
;
9940 cu
->language_defn
= language_def (cu
->language
);
9942 /* The symbol tables are set up in read_type_unit_scope. */
9943 process_die (cu
->dies
, cu
);
9945 /* For now fudge the Go package. */
9946 if (cu
->language
== language_go
)
9947 fixup_go_packaging (cu
);
9949 /* Now that we have processed all the DIEs in the CU, all the types
9950 should be complete, and it should now be safe to compute all of the
9952 compute_delayed_physnames (cu
);
9954 if (cu
->language
== language_rust
)
9955 rust_union_quirks (cu
);
9957 /* TUs share symbol tables.
9958 If this is the first TU to use this symtab, complete the construction
9959 of it with end_expandable_symtab. Otherwise, complete the addition of
9960 this TU's symbols to the existing symtab. */
9961 type_unit_group_unshareable
*tug_unshare
=
9962 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9963 if (tug_unshare
->compunit_symtab
== NULL
)
9965 buildsym_compunit
*builder
= cu
->get_builder ();
9966 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9967 tug_unshare
->compunit_symtab
= cust
;
9971 /* Set symtab language to language from DW_AT_language. If the
9972 compilation is from a C file generated by language preprocessors,
9973 do not set the language if it was already deduced by
9975 if (!(cu
->language
== language_c
9976 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9977 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9982 cu
->get_builder ()->augment_type_symtab ();
9983 cust
= tug_unshare
->compunit_symtab
;
9986 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9988 /* Not needed any more. */
9989 cu
->reset_builder ();
9992 /* Process an imported unit DIE. */
9995 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9997 struct attribute
*attr
;
9999 /* For now we don't handle imported units in type units. */
10000 if (cu
->per_cu
->is_debug_types
)
10002 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10003 " supported in type units [in module %s]"),
10004 objfile_name (cu
->per_objfile
->objfile
));
10007 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10010 sect_offset sect_off
= attr
->get_ref_die_offset ();
10011 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10012 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10013 dwarf2_per_cu_data
*per_cu
10014 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10016 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10017 into another compilation unit, at root level. Regard this as a hint,
10019 if (die
->parent
&& die
->parent
->parent
== NULL
10020 && per_cu
->unit_type
== DW_UT_compile
10021 && per_cu
->lang
== language_cplus
)
10024 /* If necessary, add it to the queue and load its DIEs. */
10025 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10026 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
10028 cu
->per_cu
->imported_symtabs_push (per_cu
);
10032 /* RAII object that represents a process_die scope: i.e.,
10033 starts/finishes processing a DIE. */
10034 class process_die_scope
10037 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10038 : m_die (die
), m_cu (cu
)
10040 /* We should only be processing DIEs not already in process. */
10041 gdb_assert (!m_die
->in_process
);
10042 m_die
->in_process
= true;
10045 ~process_die_scope ()
10047 m_die
->in_process
= false;
10049 /* If we're done processing the DIE for the CU that owns the line
10050 header, we don't need the line header anymore. */
10051 if (m_cu
->line_header_die_owner
== m_die
)
10053 delete m_cu
->line_header
;
10054 m_cu
->line_header
= NULL
;
10055 m_cu
->line_header_die_owner
= NULL
;
10064 /* Process a die and its children. */
10067 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10069 process_die_scope
scope (die
, cu
);
10073 case DW_TAG_padding
:
10075 case DW_TAG_compile_unit
:
10076 case DW_TAG_partial_unit
:
10077 read_file_scope (die
, cu
);
10079 case DW_TAG_type_unit
:
10080 read_type_unit_scope (die
, cu
);
10082 case DW_TAG_subprogram
:
10083 /* Nested subprograms in Fortran get a prefix. */
10084 if (cu
->language
== language_fortran
10085 && die
->parent
!= NULL
10086 && die
->parent
->tag
== DW_TAG_subprogram
)
10087 cu
->processing_has_namespace_info
= true;
10088 /* Fall through. */
10089 case DW_TAG_inlined_subroutine
:
10090 read_func_scope (die
, cu
);
10092 case DW_TAG_lexical_block
:
10093 case DW_TAG_try_block
:
10094 case DW_TAG_catch_block
:
10095 read_lexical_block_scope (die
, cu
);
10097 case DW_TAG_call_site
:
10098 case DW_TAG_GNU_call_site
:
10099 read_call_site_scope (die
, cu
);
10101 case DW_TAG_class_type
:
10102 case DW_TAG_interface_type
:
10103 case DW_TAG_structure_type
:
10104 case DW_TAG_union_type
:
10105 process_structure_scope (die
, cu
);
10107 case DW_TAG_enumeration_type
:
10108 process_enumeration_scope (die
, cu
);
10111 /* These dies have a type, but processing them does not create
10112 a symbol or recurse to process the children. Therefore we can
10113 read them on-demand through read_type_die. */
10114 case DW_TAG_subroutine_type
:
10115 case DW_TAG_set_type
:
10116 case DW_TAG_array_type
:
10117 case DW_TAG_pointer_type
:
10118 case DW_TAG_ptr_to_member_type
:
10119 case DW_TAG_reference_type
:
10120 case DW_TAG_rvalue_reference_type
:
10121 case DW_TAG_string_type
:
10124 case DW_TAG_base_type
:
10125 case DW_TAG_subrange_type
:
10126 case DW_TAG_typedef
:
10127 /* Add a typedef symbol for the type definition, if it has a
10129 new_symbol (die
, read_type_die (die
, cu
), cu
);
10131 case DW_TAG_common_block
:
10132 read_common_block (die
, cu
);
10134 case DW_TAG_common_inclusion
:
10136 case DW_TAG_namespace
:
10137 cu
->processing_has_namespace_info
= true;
10138 read_namespace (die
, cu
);
10140 case DW_TAG_module
:
10141 cu
->processing_has_namespace_info
= true;
10142 read_module (die
, cu
);
10144 case DW_TAG_imported_declaration
:
10145 cu
->processing_has_namespace_info
= true;
10146 if (read_namespace_alias (die
, cu
))
10148 /* The declaration is not a global namespace alias. */
10149 /* Fall through. */
10150 case DW_TAG_imported_module
:
10151 cu
->processing_has_namespace_info
= true;
10152 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10153 || cu
->language
!= language_fortran
))
10154 complaint (_("Tag '%s' has unexpected children"),
10155 dwarf_tag_name (die
->tag
));
10156 read_import_statement (die
, cu
);
10159 case DW_TAG_imported_unit
:
10160 process_imported_unit_die (die
, cu
);
10163 case DW_TAG_variable
:
10164 read_variable (die
, cu
);
10168 new_symbol (die
, NULL
, cu
);
10173 /* DWARF name computation. */
10175 /* A helper function for dwarf2_compute_name which determines whether DIE
10176 needs to have the name of the scope prepended to the name listed in the
10180 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10182 struct attribute
*attr
;
10186 case DW_TAG_namespace
:
10187 case DW_TAG_typedef
:
10188 case DW_TAG_class_type
:
10189 case DW_TAG_interface_type
:
10190 case DW_TAG_structure_type
:
10191 case DW_TAG_union_type
:
10192 case DW_TAG_enumeration_type
:
10193 case DW_TAG_enumerator
:
10194 case DW_TAG_subprogram
:
10195 case DW_TAG_inlined_subroutine
:
10196 case DW_TAG_member
:
10197 case DW_TAG_imported_declaration
:
10200 case DW_TAG_variable
:
10201 case DW_TAG_constant
:
10202 /* We only need to prefix "globally" visible variables. These include
10203 any variable marked with DW_AT_external or any variable that
10204 lives in a namespace. [Variables in anonymous namespaces
10205 require prefixing, but they are not DW_AT_external.] */
10207 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10209 struct dwarf2_cu
*spec_cu
= cu
;
10211 return die_needs_namespace (die_specification (die
, &spec_cu
),
10215 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10216 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10217 && die
->parent
->tag
!= DW_TAG_module
)
10219 /* A variable in a lexical block of some kind does not need a
10220 namespace, even though in C++ such variables may be external
10221 and have a mangled name. */
10222 if (die
->parent
->tag
== DW_TAG_lexical_block
10223 || die
->parent
->tag
== DW_TAG_try_block
10224 || die
->parent
->tag
== DW_TAG_catch_block
10225 || die
->parent
->tag
== DW_TAG_subprogram
)
10234 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10235 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10236 defined for the given DIE. */
10238 static struct attribute
*
10239 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10241 struct attribute
*attr
;
10243 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10245 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10250 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10251 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10252 defined for the given DIE. */
10254 static const char *
10255 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10257 const char *linkage_name
;
10259 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10260 if (linkage_name
== NULL
)
10261 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10263 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10264 See https://github.com/rust-lang/rust/issues/32925. */
10265 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10266 && strchr (linkage_name
, '{') != NULL
)
10267 linkage_name
= NULL
;
10269 return linkage_name
;
10272 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10273 compute the physname for the object, which include a method's:
10274 - formal parameters (C++),
10275 - receiver type (Go),
10277 The term "physname" is a bit confusing.
10278 For C++, for example, it is the demangled name.
10279 For Go, for example, it's the mangled name.
10281 For Ada, return the DIE's linkage name rather than the fully qualified
10282 name. PHYSNAME is ignored..
10284 The result is allocated on the objfile->per_bfd's obstack and
10287 static const char *
10288 dwarf2_compute_name (const char *name
,
10289 struct die_info
*die
, struct dwarf2_cu
*cu
,
10292 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10295 name
= dwarf2_name (die
, cu
);
10297 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10298 but otherwise compute it by typename_concat inside GDB.
10299 FIXME: Actually this is not really true, or at least not always true.
10300 It's all very confusing. compute_and_set_names doesn't try to demangle
10301 Fortran names because there is no mangling standard. So new_symbol
10302 will set the demangled name to the result of dwarf2_full_name, and it is
10303 the demangled name that GDB uses if it exists. */
10304 if (cu
->language
== language_ada
10305 || (cu
->language
== language_fortran
&& physname
))
10307 /* For Ada unit, we prefer the linkage name over the name, as
10308 the former contains the exported name, which the user expects
10309 to be able to reference. Ideally, we want the user to be able
10310 to reference this entity using either natural or linkage name,
10311 but we haven't started looking at this enhancement yet. */
10312 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10314 if (linkage_name
!= NULL
)
10315 return linkage_name
;
10318 /* These are the only languages we know how to qualify names in. */
10320 && (cu
->language
== language_cplus
10321 || cu
->language
== language_fortran
|| cu
->language
== language_d
10322 || cu
->language
== language_rust
))
10324 if (die_needs_namespace (die
, cu
))
10326 const char *prefix
;
10327 const char *canonical_name
= NULL
;
10331 prefix
= determine_prefix (die
, cu
);
10332 if (*prefix
!= '\0')
10334 gdb::unique_xmalloc_ptr
<char> prefixed_name
10335 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10337 buf
.puts (prefixed_name
.get ());
10342 /* Template parameters may be specified in the DIE's DW_AT_name, or
10343 as children with DW_TAG_template_type_param or
10344 DW_TAG_value_type_param. If the latter, add them to the name
10345 here. If the name already has template parameters, then
10346 skip this step; some versions of GCC emit both, and
10347 it is more efficient to use the pre-computed name.
10349 Something to keep in mind about this process: it is very
10350 unlikely, or in some cases downright impossible, to produce
10351 something that will match the mangled name of a function.
10352 If the definition of the function has the same debug info,
10353 we should be able to match up with it anyway. But fallbacks
10354 using the minimal symbol, for instance to find a method
10355 implemented in a stripped copy of libstdc++, will not work.
10356 If we do not have debug info for the definition, we will have to
10357 match them up some other way.
10359 When we do name matching there is a related problem with function
10360 templates; two instantiated function templates are allowed to
10361 differ only by their return types, which we do not add here. */
10363 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10365 struct attribute
*attr
;
10366 struct die_info
*child
;
10369 die
->building_fullname
= 1;
10371 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10375 const gdb_byte
*bytes
;
10376 struct dwarf2_locexpr_baton
*baton
;
10379 if (child
->tag
!= DW_TAG_template_type_param
10380 && child
->tag
!= DW_TAG_template_value_param
)
10391 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10394 complaint (_("template parameter missing DW_AT_type"));
10395 buf
.puts ("UNKNOWN_TYPE");
10398 type
= die_type (child
, cu
);
10400 if (child
->tag
== DW_TAG_template_type_param
)
10402 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10403 &type_print_raw_options
);
10407 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10410 complaint (_("template parameter missing "
10411 "DW_AT_const_value"));
10412 buf
.puts ("UNKNOWN_VALUE");
10416 dwarf2_const_value_attr (attr
, type
, name
,
10417 &cu
->comp_unit_obstack
, cu
,
10418 &value
, &bytes
, &baton
);
10420 if (TYPE_NOSIGN (type
))
10421 /* GDB prints characters as NUMBER 'CHAR'. If that's
10422 changed, this can use value_print instead. */
10423 c_printchar (value
, type
, &buf
);
10426 struct value_print_options opts
;
10429 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10433 baton
->per_objfile
);
10434 else if (bytes
!= NULL
)
10436 v
= allocate_value (type
);
10437 memcpy (value_contents_writeable (v
), bytes
,
10438 TYPE_LENGTH (type
));
10441 v
= value_from_longest (type
, value
);
10443 /* Specify decimal so that we do not depend on
10445 get_formatted_print_options (&opts
, 'd');
10447 value_print (v
, &buf
, &opts
);
10452 die
->building_fullname
= 0;
10456 /* Close the argument list, with a space if necessary
10457 (nested templates). */
10458 if (!buf
.empty () && buf
.string ().back () == '>')
10465 /* For C++ methods, append formal parameter type
10466 information, if PHYSNAME. */
10468 if (physname
&& die
->tag
== DW_TAG_subprogram
10469 && cu
->language
== language_cplus
)
10471 struct type
*type
= read_type_die (die
, cu
);
10473 c_type_print_args (type
, &buf
, 1, cu
->language
,
10474 &type_print_raw_options
);
10476 if (cu
->language
== language_cplus
)
10478 /* Assume that an artificial first parameter is
10479 "this", but do not crash if it is not. RealView
10480 marks unnamed (and thus unused) parameters as
10481 artificial; there is no way to differentiate
10483 if (type
->num_fields () > 0
10484 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10485 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10486 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10488 buf
.puts (" const");
10492 const std::string
&intermediate_name
= buf
.string ();
10494 if (cu
->language
== language_cplus
)
10496 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10499 /* If we only computed INTERMEDIATE_NAME, or if
10500 INTERMEDIATE_NAME is already canonical, then we need to
10502 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10503 name
= objfile
->intern (intermediate_name
);
10505 name
= canonical_name
;
10512 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10513 If scope qualifiers are appropriate they will be added. The result
10514 will be allocated on the storage_obstack, or NULL if the DIE does
10515 not have a name. NAME may either be from a previous call to
10516 dwarf2_name or NULL.
10518 The output string will be canonicalized (if C++). */
10520 static const char *
10521 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10523 return dwarf2_compute_name (name
, die
, cu
, 0);
10526 /* Construct a physname for the given DIE in CU. NAME may either be
10527 from a previous call to dwarf2_name or NULL. The result will be
10528 allocated on the objfile_objstack or NULL if the DIE does not have a
10531 The output string will be canonicalized (if C++). */
10533 static const char *
10534 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10536 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10537 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10540 /* In this case dwarf2_compute_name is just a shortcut not building anything
10542 if (!die_needs_namespace (die
, cu
))
10543 return dwarf2_compute_name (name
, die
, cu
, 1);
10545 if (cu
->language
!= language_rust
)
10546 mangled
= dw2_linkage_name (die
, cu
);
10548 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10550 gdb::unique_xmalloc_ptr
<char> demangled
;
10551 if (mangled
!= NULL
)
10554 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10556 /* Do nothing (do not demangle the symbol name). */
10558 else if (cu
->language
== language_go
)
10560 /* This is a lie, but we already lie to the caller new_symbol.
10561 new_symbol assumes we return the mangled name.
10562 This just undoes that lie until things are cleaned up. */
10566 /* Use DMGL_RET_DROP for C++ template functions to suppress
10567 their return type. It is easier for GDB users to search
10568 for such functions as `name(params)' than `long name(params)'.
10569 In such case the minimal symbol names do not match the full
10570 symbol names but for template functions there is never a need
10571 to look up their definition from their declaration so
10572 the only disadvantage remains the minimal symbol variant
10573 `long name(params)' does not have the proper inferior type. */
10574 demangled
.reset (gdb_demangle (mangled
,
10575 (DMGL_PARAMS
| DMGL_ANSI
10576 | DMGL_RET_DROP
)));
10579 canon
= demangled
.get ();
10587 if (canon
== NULL
|| check_physname
)
10589 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10591 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10593 /* It may not mean a bug in GDB. The compiler could also
10594 compute DW_AT_linkage_name incorrectly. But in such case
10595 GDB would need to be bug-to-bug compatible. */
10597 complaint (_("Computed physname <%s> does not match demangled <%s> "
10598 "(from linkage <%s>) - DIE at %s [in module %s]"),
10599 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10600 objfile_name (objfile
));
10602 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10603 is available here - over computed PHYSNAME. It is safer
10604 against both buggy GDB and buggy compilers. */
10618 retval
= objfile
->intern (retval
);
10623 /* Inspect DIE in CU for a namespace alias. If one exists, record
10624 a new symbol for it.
10626 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10629 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10631 struct attribute
*attr
;
10633 /* If the die does not have a name, this is not a namespace
10635 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10639 struct die_info
*d
= die
;
10640 struct dwarf2_cu
*imported_cu
= cu
;
10642 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10643 keep inspecting DIEs until we hit the underlying import. */
10644 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10645 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10647 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10651 d
= follow_die_ref (d
, attr
, &imported_cu
);
10652 if (d
->tag
!= DW_TAG_imported_declaration
)
10656 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10658 complaint (_("DIE at %s has too many recursively imported "
10659 "declarations"), sect_offset_str (d
->sect_off
));
10666 sect_offset sect_off
= attr
->get_ref_die_offset ();
10668 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10669 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10671 /* This declaration is a global namespace alias. Add
10672 a symbol for it whose type is the aliased namespace. */
10673 new_symbol (die
, type
, cu
);
10682 /* Return the using directives repository (global or local?) to use in the
10683 current context for CU.
10685 For Ada, imported declarations can materialize renamings, which *may* be
10686 global. However it is impossible (for now?) in DWARF to distinguish
10687 "external" imported declarations and "static" ones. As all imported
10688 declarations seem to be static in all other languages, make them all CU-wide
10689 global only in Ada. */
10691 static struct using_direct
**
10692 using_directives (struct dwarf2_cu
*cu
)
10694 if (cu
->language
== language_ada
10695 && cu
->get_builder ()->outermost_context_p ())
10696 return cu
->get_builder ()->get_global_using_directives ();
10698 return cu
->get_builder ()->get_local_using_directives ();
10701 /* Read the import statement specified by the given die and record it. */
10704 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10706 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10707 struct attribute
*import_attr
;
10708 struct die_info
*imported_die
, *child_die
;
10709 struct dwarf2_cu
*imported_cu
;
10710 const char *imported_name
;
10711 const char *imported_name_prefix
;
10712 const char *canonical_name
;
10713 const char *import_alias
;
10714 const char *imported_declaration
= NULL
;
10715 const char *import_prefix
;
10716 std::vector
<const char *> excludes
;
10718 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10719 if (import_attr
== NULL
)
10721 complaint (_("Tag '%s' has no DW_AT_import"),
10722 dwarf_tag_name (die
->tag
));
10727 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10728 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10729 if (imported_name
== NULL
)
10731 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10733 The import in the following code:
10747 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10748 <52> DW_AT_decl_file : 1
10749 <53> DW_AT_decl_line : 6
10750 <54> DW_AT_import : <0x75>
10751 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10752 <59> DW_AT_name : B
10753 <5b> DW_AT_decl_file : 1
10754 <5c> DW_AT_decl_line : 2
10755 <5d> DW_AT_type : <0x6e>
10757 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10758 <76> DW_AT_byte_size : 4
10759 <77> DW_AT_encoding : 5 (signed)
10761 imports the wrong die ( 0x75 instead of 0x58 ).
10762 This case will be ignored until the gcc bug is fixed. */
10766 /* Figure out the local name after import. */
10767 import_alias
= dwarf2_name (die
, cu
);
10769 /* Figure out where the statement is being imported to. */
10770 import_prefix
= determine_prefix (die
, cu
);
10772 /* Figure out what the scope of the imported die is and prepend it
10773 to the name of the imported die. */
10774 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10776 if (imported_die
->tag
!= DW_TAG_namespace
10777 && imported_die
->tag
!= DW_TAG_module
)
10779 imported_declaration
= imported_name
;
10780 canonical_name
= imported_name_prefix
;
10782 else if (strlen (imported_name_prefix
) > 0)
10783 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10784 imported_name_prefix
,
10785 (cu
->language
== language_d
? "." : "::"),
10786 imported_name
, (char *) NULL
);
10788 canonical_name
= imported_name
;
10790 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10791 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10792 child_die
= child_die
->sibling
)
10794 /* DWARF-4: A Fortran use statement with a “rename list” may be
10795 represented by an imported module entry with an import attribute
10796 referring to the module and owned entries corresponding to those
10797 entities that are renamed as part of being imported. */
10799 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10801 complaint (_("child DW_TAG_imported_declaration expected "
10802 "- DIE at %s [in module %s]"),
10803 sect_offset_str (child_die
->sect_off
),
10804 objfile_name (objfile
));
10808 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10809 if (import_attr
== NULL
)
10811 complaint (_("Tag '%s' has no DW_AT_import"),
10812 dwarf_tag_name (child_die
->tag
));
10817 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10819 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10820 if (imported_name
== NULL
)
10822 complaint (_("child DW_TAG_imported_declaration has unknown "
10823 "imported name - DIE at %s [in module %s]"),
10824 sect_offset_str (child_die
->sect_off
),
10825 objfile_name (objfile
));
10829 excludes
.push_back (imported_name
);
10831 process_die (child_die
, cu
);
10834 add_using_directive (using_directives (cu
),
10838 imported_declaration
,
10841 &objfile
->objfile_obstack
);
10844 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10845 types, but gives them a size of zero. Starting with version 14,
10846 ICC is compatible with GCC. */
10849 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10851 if (!cu
->checked_producer
)
10852 check_producer (cu
);
10854 return cu
->producer_is_icc_lt_14
;
10857 /* ICC generates a DW_AT_type for C void functions. This was observed on
10858 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10859 which says that void functions should not have a DW_AT_type. */
10862 producer_is_icc (struct dwarf2_cu
*cu
)
10864 if (!cu
->checked_producer
)
10865 check_producer (cu
);
10867 return cu
->producer_is_icc
;
10870 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10871 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10872 this, it was first present in GCC release 4.3.0. */
10875 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10877 if (!cu
->checked_producer
)
10878 check_producer (cu
);
10880 return cu
->producer_is_gcc_lt_4_3
;
10883 static file_and_directory
10884 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10886 file_and_directory res
;
10888 /* Find the filename. Do not use dwarf2_name here, since the filename
10889 is not a source language identifier. */
10890 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10891 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10893 if (res
.comp_dir
== NULL
10894 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10895 && IS_ABSOLUTE_PATH (res
.name
))
10897 res
.comp_dir_storage
= ldirname (res
.name
);
10898 if (!res
.comp_dir_storage
.empty ())
10899 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10901 if (res
.comp_dir
!= NULL
)
10903 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10904 directory, get rid of it. */
10905 const char *cp
= strchr (res
.comp_dir
, ':');
10907 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10908 res
.comp_dir
= cp
+ 1;
10911 if (res
.name
== NULL
)
10912 res
.name
= "<unknown>";
10917 /* Handle DW_AT_stmt_list for a compilation unit.
10918 DIE is the DW_TAG_compile_unit die for CU.
10919 COMP_DIR is the compilation directory. LOWPC is passed to
10920 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10923 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10924 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10926 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10927 struct attribute
*attr
;
10928 struct line_header line_header_local
;
10929 hashval_t line_header_local_hash
;
10931 int decode_mapping
;
10933 gdb_assert (! cu
->per_cu
->is_debug_types
);
10935 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10939 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10941 /* The line header hash table is only created if needed (it exists to
10942 prevent redundant reading of the line table for partial_units).
10943 If we're given a partial_unit, we'll need it. If we're given a
10944 compile_unit, then use the line header hash table if it's already
10945 created, but don't create one just yet. */
10947 if (per_objfile
->line_header_hash
== NULL
10948 && die
->tag
== DW_TAG_partial_unit
)
10950 per_objfile
->line_header_hash
10951 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10952 line_header_eq_voidp
,
10953 free_line_header_voidp
,
10957 line_header_local
.sect_off
= line_offset
;
10958 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10959 line_header_local_hash
= line_header_hash (&line_header_local
);
10960 if (per_objfile
->line_header_hash
!= NULL
)
10962 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10963 &line_header_local
,
10964 line_header_local_hash
, NO_INSERT
);
10966 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10967 is not present in *SLOT (since if there is something in *SLOT then
10968 it will be for a partial_unit). */
10969 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10971 gdb_assert (*slot
!= NULL
);
10972 cu
->line_header
= (struct line_header
*) *slot
;
10977 /* dwarf_decode_line_header does not yet provide sufficient information.
10978 We always have to call also dwarf_decode_lines for it. */
10979 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10983 cu
->line_header
= lh
.release ();
10984 cu
->line_header_die_owner
= die
;
10986 if (per_objfile
->line_header_hash
== NULL
)
10990 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10991 &line_header_local
,
10992 line_header_local_hash
, INSERT
);
10993 gdb_assert (slot
!= NULL
);
10995 if (slot
!= NULL
&& *slot
== NULL
)
10997 /* This newly decoded line number information unit will be owned
10998 by line_header_hash hash table. */
10999 *slot
= cu
->line_header
;
11000 cu
->line_header_die_owner
= NULL
;
11004 /* We cannot free any current entry in (*slot) as that struct line_header
11005 may be already used by multiple CUs. Create only temporary decoded
11006 line_header for this CU - it may happen at most once for each line
11007 number information unit. And if we're not using line_header_hash
11008 then this is what we want as well. */
11009 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11011 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11012 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11017 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11020 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11022 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11023 struct objfile
*objfile
= per_objfile
->objfile
;
11024 struct gdbarch
*gdbarch
= objfile
->arch ();
11025 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11026 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11027 struct attribute
*attr
;
11028 struct die_info
*child_die
;
11029 CORE_ADDR baseaddr
;
11031 prepare_one_comp_unit (cu
, die
, cu
->language
);
11032 baseaddr
= objfile
->text_section_offset ();
11034 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11036 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11037 from finish_block. */
11038 if (lowpc
== ((CORE_ADDR
) -1))
11040 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11042 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11044 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11045 standardised yet. As a workaround for the language detection we fall
11046 back to the DW_AT_producer string. */
11047 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11048 cu
->language
= language_opencl
;
11050 /* Similar hack for Go. */
11051 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11052 set_cu_language (DW_LANG_Go
, cu
);
11054 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11056 /* Decode line number information if present. We do this before
11057 processing child DIEs, so that the line header table is available
11058 for DW_AT_decl_file. */
11059 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11061 /* Process all dies in compilation unit. */
11062 if (die
->child
!= NULL
)
11064 child_die
= die
->child
;
11065 while (child_die
&& child_die
->tag
)
11067 process_die (child_die
, cu
);
11068 child_die
= child_die
->sibling
;
11072 /* Decode macro information, if present. Dwarf 2 macro information
11073 refers to information in the line number info statement program
11074 header, so we can only read it if we've read the header
11076 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11078 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11079 if (attr
&& cu
->line_header
)
11081 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11082 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11084 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11088 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11089 if (attr
&& cu
->line_header
)
11091 unsigned int macro_offset
= DW_UNSND (attr
);
11093 dwarf_decode_macros (cu
, macro_offset
, 0);
11099 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11101 struct type_unit_group
*tu_group
;
11103 struct attribute
*attr
;
11105 struct signatured_type
*sig_type
;
11107 gdb_assert (per_cu
->is_debug_types
);
11108 sig_type
= (struct signatured_type
*) per_cu
;
11110 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11112 /* If we're using .gdb_index (includes -readnow) then
11113 per_cu->type_unit_group may not have been set up yet. */
11114 if (sig_type
->type_unit_group
== NULL
)
11115 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11116 tu_group
= sig_type
->type_unit_group
;
11118 /* If we've already processed this stmt_list there's no real need to
11119 do it again, we could fake it and just recreate the part we need
11120 (file name,index -> symtab mapping). If data shows this optimization
11121 is useful we can do it then. */
11122 type_unit_group_unshareable
*tug_unshare
11123 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11124 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11126 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11131 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11132 lh
= dwarf_decode_line_header (line_offset
, this);
11137 start_symtab ("", NULL
, 0);
11140 gdb_assert (tug_unshare
->symtabs
== NULL
);
11141 gdb_assert (m_builder
== nullptr);
11142 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11143 m_builder
.reset (new struct buildsym_compunit
11144 (COMPUNIT_OBJFILE (cust
), "",
11145 COMPUNIT_DIRNAME (cust
),
11146 compunit_language (cust
),
11148 list_in_scope
= get_builder ()->get_file_symbols ();
11153 line_header
= lh
.release ();
11154 line_header_die_owner
= die
;
11158 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11160 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11161 still initializing it, and our caller (a few levels up)
11162 process_full_type_unit still needs to know if this is the first
11165 tug_unshare
->symtabs
11166 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11167 struct symtab
*, line_header
->file_names_size ());
11169 auto &file_names
= line_header
->file_names ();
11170 for (i
= 0; i
< file_names
.size (); ++i
)
11172 file_entry
&fe
= file_names
[i
];
11173 dwarf2_start_subfile (this, fe
.name
,
11174 fe
.include_dir (line_header
));
11175 buildsym_compunit
*b
= get_builder ();
11176 if (b
->get_current_subfile ()->symtab
== NULL
)
11178 /* NOTE: start_subfile will recognize when it's been
11179 passed a file it has already seen. So we can't
11180 assume there's a simple mapping from
11181 cu->line_header->file_names to subfiles, plus
11182 cu->line_header->file_names may contain dups. */
11183 b
->get_current_subfile ()->symtab
11184 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11187 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11188 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11193 gdb_assert (m_builder
== nullptr);
11194 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11195 m_builder
.reset (new struct buildsym_compunit
11196 (COMPUNIT_OBJFILE (cust
), "",
11197 COMPUNIT_DIRNAME (cust
),
11198 compunit_language (cust
),
11200 list_in_scope
= get_builder ()->get_file_symbols ();
11202 auto &file_names
= line_header
->file_names ();
11203 for (i
= 0; i
< file_names
.size (); ++i
)
11205 file_entry
&fe
= file_names
[i
];
11206 fe
.symtab
= tug_unshare
->symtabs
[i
];
11210 /* The main symtab is allocated last. Type units don't have DW_AT_name
11211 so they don't have a "real" (so to speak) symtab anyway.
11212 There is later code that will assign the main symtab to all symbols
11213 that don't have one. We need to handle the case of a symbol with a
11214 missing symtab (DW_AT_decl_file) anyway. */
11217 /* Process DW_TAG_type_unit.
11218 For TUs we want to skip the first top level sibling if it's not the
11219 actual type being defined by this TU. In this case the first top
11220 level sibling is there to provide context only. */
11223 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11225 struct die_info
*child_die
;
11227 prepare_one_comp_unit (cu
, die
, language_minimal
);
11229 /* Initialize (or reinitialize) the machinery for building symtabs.
11230 We do this before processing child DIEs, so that the line header table
11231 is available for DW_AT_decl_file. */
11232 cu
->setup_type_unit_groups (die
);
11234 if (die
->child
!= NULL
)
11236 child_die
= die
->child
;
11237 while (child_die
&& child_die
->tag
)
11239 process_die (child_die
, cu
);
11240 child_die
= child_die
->sibling
;
11247 http://gcc.gnu.org/wiki/DebugFission
11248 http://gcc.gnu.org/wiki/DebugFissionDWP
11250 To simplify handling of both DWO files ("object" files with the DWARF info)
11251 and DWP files (a file with the DWOs packaged up into one file), we treat
11252 DWP files as having a collection of virtual DWO files. */
11255 hash_dwo_file (const void *item
)
11257 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11260 hash
= htab_hash_string (dwo_file
->dwo_name
);
11261 if (dwo_file
->comp_dir
!= NULL
)
11262 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11267 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11269 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11270 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11272 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11274 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11275 return lhs
->comp_dir
== rhs
->comp_dir
;
11276 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11279 /* Allocate a hash table for DWO files. */
11282 allocate_dwo_file_hash_table ()
11284 auto delete_dwo_file
= [] (void *item
)
11286 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11291 return htab_up (htab_create_alloc (41,
11298 /* Lookup DWO file DWO_NAME. */
11301 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11302 const char *dwo_name
,
11303 const char *comp_dir
)
11305 struct dwo_file find_entry
;
11308 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11309 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11311 find_entry
.dwo_name
= dwo_name
;
11312 find_entry
.comp_dir
= comp_dir
;
11313 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11320 hash_dwo_unit (const void *item
)
11322 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11324 /* This drops the top 32 bits of the id, but is ok for a hash. */
11325 return dwo_unit
->signature
;
11329 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11331 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11332 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11334 /* The signature is assumed to be unique within the DWO file.
11335 So while object file CU dwo_id's always have the value zero,
11336 that's OK, assuming each object file DWO file has only one CU,
11337 and that's the rule for now. */
11338 return lhs
->signature
== rhs
->signature
;
11341 /* Allocate a hash table for DWO CUs,TUs.
11342 There is one of these tables for each of CUs,TUs for each DWO file. */
11345 allocate_dwo_unit_table ()
11347 /* Start out with a pretty small number.
11348 Generally DWO files contain only one CU and maybe some TUs. */
11349 return htab_up (htab_create_alloc (3,
11352 NULL
, xcalloc
, xfree
));
11355 /* die_reader_func for create_dwo_cu. */
11358 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11359 const gdb_byte
*info_ptr
,
11360 struct die_info
*comp_unit_die
,
11361 struct dwo_file
*dwo_file
,
11362 struct dwo_unit
*dwo_unit
)
11364 struct dwarf2_cu
*cu
= reader
->cu
;
11365 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11366 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11368 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11369 if (!signature
.has_value ())
11371 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11372 " its dwo_id [in module %s]"),
11373 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11377 dwo_unit
->dwo_file
= dwo_file
;
11378 dwo_unit
->signature
= *signature
;
11379 dwo_unit
->section
= section
;
11380 dwo_unit
->sect_off
= sect_off
;
11381 dwo_unit
->length
= cu
->per_cu
->length
;
11383 if (dwarf_read_debug
)
11384 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11385 sect_offset_str (sect_off
),
11386 hex_string (dwo_unit
->signature
));
11389 /* Create the dwo_units for the CUs in a DWO_FILE.
11390 Note: This function processes DWO files only, not DWP files. */
11393 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11394 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11395 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11397 struct objfile
*objfile
= per_objfile
->objfile
;
11398 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11399 const gdb_byte
*info_ptr
, *end_ptr
;
11401 section
.read (objfile
);
11402 info_ptr
= section
.buffer
;
11404 if (info_ptr
== NULL
)
11407 if (dwarf_read_debug
)
11409 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11410 section
.get_name (),
11411 section
.get_file_name ());
11414 end_ptr
= info_ptr
+ section
.size
;
11415 while (info_ptr
< end_ptr
)
11417 struct dwarf2_per_cu_data per_cu
;
11418 struct dwo_unit read_unit
{};
11419 struct dwo_unit
*dwo_unit
;
11421 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11423 memset (&per_cu
, 0, sizeof (per_cu
));
11424 per_cu
.per_bfd
= per_bfd
;
11425 per_cu
.is_debug_types
= 0;
11426 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11427 per_cu
.section
= §ion
;
11429 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11430 if (!reader
.dummy_p
)
11431 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11432 &dwo_file
, &read_unit
);
11433 info_ptr
+= per_cu
.length
;
11435 // If the unit could not be parsed, skip it.
11436 if (read_unit
.dwo_file
== NULL
)
11439 if (cus_htab
== NULL
)
11440 cus_htab
= allocate_dwo_unit_table ();
11442 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11444 *dwo_unit
= read_unit
;
11445 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11446 gdb_assert (slot
!= NULL
);
11449 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11450 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11452 complaint (_("debug cu entry at offset %s is duplicate to"
11453 " the entry at offset %s, signature %s"),
11454 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11455 hex_string (dwo_unit
->signature
));
11457 *slot
= (void *)dwo_unit
;
11461 /* DWP file .debug_{cu,tu}_index section format:
11462 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11466 Both index sections have the same format, and serve to map a 64-bit
11467 signature to a set of section numbers. Each section begins with a header,
11468 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11469 indexes, and a pool of 32-bit section numbers. The index sections will be
11470 aligned at 8-byte boundaries in the file.
11472 The index section header consists of:
11474 V, 32 bit version number
11476 N, 32 bit number of compilation units or type units in the index
11477 M, 32 bit number of slots in the hash table
11479 Numbers are recorded using the byte order of the application binary.
11481 The hash table begins at offset 16 in the section, and consists of an array
11482 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11483 order of the application binary). Unused slots in the hash table are 0.
11484 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11486 The parallel table begins immediately after the hash table
11487 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11488 array of 32-bit indexes (using the byte order of the application binary),
11489 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11490 table contains a 32-bit index into the pool of section numbers. For unused
11491 hash table slots, the corresponding entry in the parallel table will be 0.
11493 The pool of section numbers begins immediately following the hash table
11494 (at offset 16 + 12 * M from the beginning of the section). The pool of
11495 section numbers consists of an array of 32-bit words (using the byte order
11496 of the application binary). Each item in the array is indexed starting
11497 from 0. The hash table entry provides the index of the first section
11498 number in the set. Additional section numbers in the set follow, and the
11499 set is terminated by a 0 entry (section number 0 is not used in ELF).
11501 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11502 section must be the first entry in the set, and the .debug_abbrev.dwo must
11503 be the second entry. Other members of the set may follow in any order.
11509 DWP Version 2 combines all the .debug_info, etc. sections into one,
11510 and the entries in the index tables are now offsets into these sections.
11511 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11514 Index Section Contents:
11516 Hash Table of Signatures dwp_hash_table.hash_table
11517 Parallel Table of Indices dwp_hash_table.unit_table
11518 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11519 Table of Section Sizes dwp_hash_table.v2.sizes
11521 The index section header consists of:
11523 V, 32 bit version number
11524 L, 32 bit number of columns in the table of section offsets
11525 N, 32 bit number of compilation units or type units in the index
11526 M, 32 bit number of slots in the hash table
11528 Numbers are recorded using the byte order of the application binary.
11530 The hash table has the same format as version 1.
11531 The parallel table of indices has the same format as version 1,
11532 except that the entries are origin-1 indices into the table of sections
11533 offsets and the table of section sizes.
11535 The table of offsets begins immediately following the parallel table
11536 (at offset 16 + 12 * M from the beginning of the section). The table is
11537 a two-dimensional array of 32-bit words (using the byte order of the
11538 application binary), with L columns and N+1 rows, in row-major order.
11539 Each row in the array is indexed starting from 0. The first row provides
11540 a key to the remaining rows: each column in this row provides an identifier
11541 for a debug section, and the offsets in the same column of subsequent rows
11542 refer to that section. The section identifiers are:
11544 DW_SECT_INFO 1 .debug_info.dwo
11545 DW_SECT_TYPES 2 .debug_types.dwo
11546 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11547 DW_SECT_LINE 4 .debug_line.dwo
11548 DW_SECT_LOC 5 .debug_loc.dwo
11549 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11550 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11551 DW_SECT_MACRO 8 .debug_macro.dwo
11553 The offsets provided by the CU and TU index sections are the base offsets
11554 for the contributions made by each CU or TU to the corresponding section
11555 in the package file. Each CU and TU header contains an abbrev_offset
11556 field, used to find the abbreviations table for that CU or TU within the
11557 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11558 be interpreted as relative to the base offset given in the index section.
11559 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11560 should be interpreted as relative to the base offset for .debug_line.dwo,
11561 and offsets into other debug sections obtained from DWARF attributes should
11562 also be interpreted as relative to the corresponding base offset.
11564 The table of sizes begins immediately following the table of offsets.
11565 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11566 with L columns and N rows, in row-major order. Each row in the array is
11567 indexed starting from 1 (row 0 is shared by the two tables).
11571 Hash table lookup is handled the same in version 1 and 2:
11573 We assume that N and M will not exceed 2^32 - 1.
11574 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11576 Given a 64-bit compilation unit signature or a type signature S, an entry
11577 in the hash table is located as follows:
11579 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11580 the low-order k bits all set to 1.
11582 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11584 3) If the hash table entry at index H matches the signature, use that
11585 entry. If the hash table entry at index H is unused (all zeroes),
11586 terminate the search: the signature is not present in the table.
11588 4) Let H = (H + H') modulo M. Repeat at Step 3.
11590 Because M > N and H' and M are relatively prime, the search is guaranteed
11591 to stop at an unused slot or find the match. */
11593 /* Create a hash table to map DWO IDs to their CU/TU entry in
11594 .debug_{info,types}.dwo in DWP_FILE.
11595 Returns NULL if there isn't one.
11596 Note: This function processes DWP files only, not DWO files. */
11598 static struct dwp_hash_table
*
11599 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11600 struct dwp_file
*dwp_file
, int is_debug_types
)
11602 struct objfile
*objfile
= per_objfile
->objfile
;
11603 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11604 const gdb_byte
*index_ptr
, *index_end
;
11605 struct dwarf2_section_info
*index
;
11606 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11607 struct dwp_hash_table
*htab
;
11609 if (is_debug_types
)
11610 index
= &dwp_file
->sections
.tu_index
;
11612 index
= &dwp_file
->sections
.cu_index
;
11614 if (index
->empty ())
11616 index
->read (objfile
);
11618 index_ptr
= index
->buffer
;
11619 index_end
= index_ptr
+ index
->size
;
11621 version
= read_4_bytes (dbfd
, index_ptr
);
11624 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11628 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11630 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11633 if (version
!= 1 && version
!= 2)
11635 error (_("Dwarf Error: unsupported DWP file version (%s)"
11636 " [in module %s]"),
11637 pulongest (version
), dwp_file
->name
);
11639 if (nr_slots
!= (nr_slots
& -nr_slots
))
11641 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11642 " is not power of 2 [in module %s]"),
11643 pulongest (nr_slots
), dwp_file
->name
);
11646 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11647 htab
->version
= version
;
11648 htab
->nr_columns
= nr_columns
;
11649 htab
->nr_units
= nr_units
;
11650 htab
->nr_slots
= nr_slots
;
11651 htab
->hash_table
= index_ptr
;
11652 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11654 /* Exit early if the table is empty. */
11655 if (nr_slots
== 0 || nr_units
== 0
11656 || (version
== 2 && nr_columns
== 0))
11658 /* All must be zero. */
11659 if (nr_slots
!= 0 || nr_units
!= 0
11660 || (version
== 2 && nr_columns
!= 0))
11662 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11663 " all zero [in modules %s]"),
11671 htab
->section_pool
.v1
.indices
=
11672 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11673 /* It's harder to decide whether the section is too small in v1.
11674 V1 is deprecated anyway so we punt. */
11678 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11679 int *ids
= htab
->section_pool
.v2
.section_ids
;
11680 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11681 /* Reverse map for error checking. */
11682 int ids_seen
[DW_SECT_MAX
+ 1];
11685 if (nr_columns
< 2)
11687 error (_("Dwarf Error: bad DWP hash table, too few columns"
11688 " in section table [in module %s]"),
11691 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11693 error (_("Dwarf Error: bad DWP hash table, too many columns"
11694 " in section table [in module %s]"),
11697 memset (ids
, 255, sizeof_ids
);
11698 memset (ids_seen
, 255, sizeof (ids_seen
));
11699 for (i
= 0; i
< nr_columns
; ++i
)
11701 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11703 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11705 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11706 " in section table [in module %s]"),
11707 id
, dwp_file
->name
);
11709 if (ids_seen
[id
] != -1)
11711 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11712 " id %d in section table [in module %s]"),
11713 id
, dwp_file
->name
);
11718 /* Must have exactly one info or types section. */
11719 if (((ids_seen
[DW_SECT_INFO
] != -1)
11720 + (ids_seen
[DW_SECT_TYPES
] != -1))
11723 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11724 " DWO info/types section [in module %s]"),
11727 /* Must have an abbrev section. */
11728 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11730 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11731 " section [in module %s]"),
11734 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11735 htab
->section_pool
.v2
.sizes
=
11736 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11737 * nr_units
* nr_columns
);
11738 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11739 * nr_units
* nr_columns
))
11742 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11743 " [in module %s]"),
11751 /* Update SECTIONS with the data from SECTP.
11753 This function is like the other "locate" section routines that are
11754 passed to bfd_map_over_sections, but in this context the sections to
11755 read comes from the DWP V1 hash table, not the full ELF section table.
11757 The result is non-zero for success, or zero if an error was found. */
11760 locate_v1_virtual_dwo_sections (asection
*sectp
,
11761 struct virtual_v1_dwo_sections
*sections
)
11763 const struct dwop_section_names
*names
= &dwop_section_names
;
11765 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11767 /* There can be only one. */
11768 if (sections
->abbrev
.s
.section
!= NULL
)
11770 sections
->abbrev
.s
.section
= sectp
;
11771 sections
->abbrev
.size
= bfd_section_size (sectp
);
11773 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11774 || section_is_p (sectp
->name
, &names
->types_dwo
))
11776 /* There can be only one. */
11777 if (sections
->info_or_types
.s
.section
!= NULL
)
11779 sections
->info_or_types
.s
.section
= sectp
;
11780 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11782 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11784 /* There can be only one. */
11785 if (sections
->line
.s
.section
!= NULL
)
11787 sections
->line
.s
.section
= sectp
;
11788 sections
->line
.size
= bfd_section_size (sectp
);
11790 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11792 /* There can be only one. */
11793 if (sections
->loc
.s
.section
!= NULL
)
11795 sections
->loc
.s
.section
= sectp
;
11796 sections
->loc
.size
= bfd_section_size (sectp
);
11798 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11800 /* There can be only one. */
11801 if (sections
->macinfo
.s
.section
!= NULL
)
11803 sections
->macinfo
.s
.section
= sectp
;
11804 sections
->macinfo
.size
= bfd_section_size (sectp
);
11806 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11808 /* There can be only one. */
11809 if (sections
->macro
.s
.section
!= NULL
)
11811 sections
->macro
.s
.section
= sectp
;
11812 sections
->macro
.size
= bfd_section_size (sectp
);
11814 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11816 /* There can be only one. */
11817 if (sections
->str_offsets
.s
.section
!= NULL
)
11819 sections
->str_offsets
.s
.section
= sectp
;
11820 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11824 /* No other kind of section is valid. */
11831 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11832 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11833 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11834 This is for DWP version 1 files. */
11836 static struct dwo_unit
*
11837 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11838 struct dwp_file
*dwp_file
,
11839 uint32_t unit_index
,
11840 const char *comp_dir
,
11841 ULONGEST signature
, int is_debug_types
)
11843 const struct dwp_hash_table
*dwp_htab
=
11844 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11845 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11846 const char *kind
= is_debug_types
? "TU" : "CU";
11847 struct dwo_file
*dwo_file
;
11848 struct dwo_unit
*dwo_unit
;
11849 struct virtual_v1_dwo_sections sections
;
11850 void **dwo_file_slot
;
11853 gdb_assert (dwp_file
->version
== 1);
11855 if (dwarf_read_debug
)
11857 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11859 pulongest (unit_index
), hex_string (signature
),
11863 /* Fetch the sections of this DWO unit.
11864 Put a limit on the number of sections we look for so that bad data
11865 doesn't cause us to loop forever. */
11867 #define MAX_NR_V1_DWO_SECTIONS \
11868 (1 /* .debug_info or .debug_types */ \
11869 + 1 /* .debug_abbrev */ \
11870 + 1 /* .debug_line */ \
11871 + 1 /* .debug_loc */ \
11872 + 1 /* .debug_str_offsets */ \
11873 + 1 /* .debug_macro or .debug_macinfo */ \
11874 + 1 /* trailing zero */)
11876 memset (§ions
, 0, sizeof (sections
));
11878 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11881 uint32_t section_nr
=
11882 read_4_bytes (dbfd
,
11883 dwp_htab
->section_pool
.v1
.indices
11884 + (unit_index
+ i
) * sizeof (uint32_t));
11886 if (section_nr
== 0)
11888 if (section_nr
>= dwp_file
->num_sections
)
11890 error (_("Dwarf Error: bad DWP hash table, section number too large"
11891 " [in module %s]"),
11895 sectp
= dwp_file
->elf_sections
[section_nr
];
11896 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11898 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11899 " [in module %s]"),
11905 || sections
.info_or_types
.empty ()
11906 || sections
.abbrev
.empty ())
11908 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11909 " [in module %s]"),
11912 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11914 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11915 " [in module %s]"),
11919 /* It's easier for the rest of the code if we fake a struct dwo_file and
11920 have dwo_unit "live" in that. At least for now.
11922 The DWP file can be made up of a random collection of CUs and TUs.
11923 However, for each CU + set of TUs that came from the same original DWO
11924 file, we can combine them back into a virtual DWO file to save space
11925 (fewer struct dwo_file objects to allocate). Remember that for really
11926 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11928 std::string virtual_dwo_name
=
11929 string_printf ("virtual-dwo/%d-%d-%d-%d",
11930 sections
.abbrev
.get_id (),
11931 sections
.line
.get_id (),
11932 sections
.loc
.get_id (),
11933 sections
.str_offsets
.get_id ());
11934 /* Can we use an existing virtual DWO file? */
11935 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11937 /* Create one if necessary. */
11938 if (*dwo_file_slot
== NULL
)
11940 if (dwarf_read_debug
)
11942 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11943 virtual_dwo_name
.c_str ());
11945 dwo_file
= new struct dwo_file
;
11946 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11947 dwo_file
->comp_dir
= comp_dir
;
11948 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11949 dwo_file
->sections
.line
= sections
.line
;
11950 dwo_file
->sections
.loc
= sections
.loc
;
11951 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11952 dwo_file
->sections
.macro
= sections
.macro
;
11953 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11954 /* The "str" section is global to the entire DWP file. */
11955 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11956 /* The info or types section is assigned below to dwo_unit,
11957 there's no need to record it in dwo_file.
11958 Also, we can't simply record type sections in dwo_file because
11959 we record a pointer into the vector in dwo_unit. As we collect more
11960 types we'll grow the vector and eventually have to reallocate space
11961 for it, invalidating all copies of pointers into the previous
11963 *dwo_file_slot
= dwo_file
;
11967 if (dwarf_read_debug
)
11969 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11970 virtual_dwo_name
.c_str ());
11972 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11975 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11976 dwo_unit
->dwo_file
= dwo_file
;
11977 dwo_unit
->signature
= signature
;
11978 dwo_unit
->section
=
11979 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11980 *dwo_unit
->section
= sections
.info_or_types
;
11981 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11986 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11987 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11988 piece within that section used by a TU/CU, return a virtual section
11989 of just that piece. */
11991 static struct dwarf2_section_info
11992 create_dwp_v2_section (dwarf2_per_objfile
*per_objfile
,
11993 struct dwarf2_section_info
*section
,
11994 bfd_size_type offset
, bfd_size_type size
)
11996 struct dwarf2_section_info result
;
11999 gdb_assert (section
!= NULL
);
12000 gdb_assert (!section
->is_virtual
);
12002 memset (&result
, 0, sizeof (result
));
12003 result
.s
.containing_section
= section
;
12004 result
.is_virtual
= true;
12009 sectp
= section
->get_bfd_section ();
12011 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12012 bounds of the real section. This is a pretty-rare event, so just
12013 flag an error (easier) instead of a warning and trying to cope. */
12015 || offset
+ size
> bfd_section_size (sectp
))
12017 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12018 " in section %s [in module %s]"),
12019 sectp
? bfd_section_name (sectp
) : "<unknown>",
12020 objfile_name (per_objfile
->objfile
));
12023 result
.virtual_offset
= offset
;
12024 result
.size
= size
;
12028 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12029 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12030 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12031 This is for DWP version 2 files. */
12033 static struct dwo_unit
*
12034 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12035 struct dwp_file
*dwp_file
,
12036 uint32_t unit_index
,
12037 const char *comp_dir
,
12038 ULONGEST signature
, int is_debug_types
)
12040 const struct dwp_hash_table
*dwp_htab
=
12041 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12042 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12043 const char *kind
= is_debug_types
? "TU" : "CU";
12044 struct dwo_file
*dwo_file
;
12045 struct dwo_unit
*dwo_unit
;
12046 struct virtual_v2_dwo_sections sections
;
12047 void **dwo_file_slot
;
12050 gdb_assert (dwp_file
->version
== 2);
12052 if (dwarf_read_debug
)
12054 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12056 pulongest (unit_index
), hex_string (signature
),
12060 /* Fetch the section offsets of this DWO unit. */
12062 memset (§ions
, 0, sizeof (sections
));
12064 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12066 uint32_t offset
= read_4_bytes (dbfd
,
12067 dwp_htab
->section_pool
.v2
.offsets
12068 + (((unit_index
- 1) * dwp_htab
->nr_columns
12070 * sizeof (uint32_t)));
12071 uint32_t size
= read_4_bytes (dbfd
,
12072 dwp_htab
->section_pool
.v2
.sizes
12073 + (((unit_index
- 1) * dwp_htab
->nr_columns
12075 * sizeof (uint32_t)));
12077 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12080 case DW_SECT_TYPES
:
12081 sections
.info_or_types_offset
= offset
;
12082 sections
.info_or_types_size
= size
;
12084 case DW_SECT_ABBREV
:
12085 sections
.abbrev_offset
= offset
;
12086 sections
.abbrev_size
= size
;
12089 sections
.line_offset
= offset
;
12090 sections
.line_size
= size
;
12093 sections
.loc_offset
= offset
;
12094 sections
.loc_size
= size
;
12096 case DW_SECT_STR_OFFSETS
:
12097 sections
.str_offsets_offset
= offset
;
12098 sections
.str_offsets_size
= size
;
12100 case DW_SECT_MACINFO
:
12101 sections
.macinfo_offset
= offset
;
12102 sections
.macinfo_size
= size
;
12104 case DW_SECT_MACRO
:
12105 sections
.macro_offset
= offset
;
12106 sections
.macro_size
= size
;
12111 /* It's easier for the rest of the code if we fake a struct dwo_file and
12112 have dwo_unit "live" in that. At least for now.
12114 The DWP file can be made up of a random collection of CUs and TUs.
12115 However, for each CU + set of TUs that came from the same original DWO
12116 file, we can combine them back into a virtual DWO file to save space
12117 (fewer struct dwo_file objects to allocate). Remember that for really
12118 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12120 std::string virtual_dwo_name
=
12121 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12122 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12123 (long) (sections
.line_size
? sections
.line_offset
: 0),
12124 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12125 (long) (sections
.str_offsets_size
12126 ? sections
.str_offsets_offset
: 0));
12127 /* Can we use an existing virtual DWO file? */
12128 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12130 /* Create one if necessary. */
12131 if (*dwo_file_slot
== NULL
)
12133 if (dwarf_read_debug
)
12135 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12136 virtual_dwo_name
.c_str ());
12138 dwo_file
= new struct dwo_file
;
12139 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12140 dwo_file
->comp_dir
= comp_dir
;
12141 dwo_file
->sections
.abbrev
=
12142 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12143 sections
.abbrev_offset
, sections
.abbrev_size
);
12144 dwo_file
->sections
.line
=
12145 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.line
,
12146 sections
.line_offset
, sections
.line_size
);
12147 dwo_file
->sections
.loc
=
12148 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.loc
,
12149 sections
.loc_offset
, sections
.loc_size
);
12150 dwo_file
->sections
.macinfo
=
12151 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12152 sections
.macinfo_offset
, sections
.macinfo_size
);
12153 dwo_file
->sections
.macro
=
12154 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macro
,
12155 sections
.macro_offset
, sections
.macro_size
);
12156 dwo_file
->sections
.str_offsets
=
12157 create_dwp_v2_section (per_objfile
,
12158 &dwp_file
->sections
.str_offsets
,
12159 sections
.str_offsets_offset
,
12160 sections
.str_offsets_size
);
12161 /* The "str" section is global to the entire DWP file. */
12162 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12163 /* The info or types section is assigned below to dwo_unit,
12164 there's no need to record it in dwo_file.
12165 Also, we can't simply record type sections in dwo_file because
12166 we record a pointer into the vector in dwo_unit. As we collect more
12167 types we'll grow the vector and eventually have to reallocate space
12168 for it, invalidating all copies of pointers into the previous
12170 *dwo_file_slot
= dwo_file
;
12174 if (dwarf_read_debug
)
12176 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12177 virtual_dwo_name
.c_str ());
12179 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12182 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12183 dwo_unit
->dwo_file
= dwo_file
;
12184 dwo_unit
->signature
= signature
;
12185 dwo_unit
->section
=
12186 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12187 *dwo_unit
->section
= create_dwp_v2_section (per_objfile
,
12189 ? &dwp_file
->sections
.types
12190 : &dwp_file
->sections
.info
,
12191 sections
.info_or_types_offset
,
12192 sections
.info_or_types_size
);
12193 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12198 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12199 Returns NULL if the signature isn't found. */
12201 static struct dwo_unit
*
12202 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12203 struct dwp_file
*dwp_file
, const char *comp_dir
,
12204 ULONGEST signature
, int is_debug_types
)
12206 const struct dwp_hash_table
*dwp_htab
=
12207 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12208 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12209 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12210 uint32_t hash
= signature
& mask
;
12211 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12214 struct dwo_unit find_dwo_cu
;
12216 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12217 find_dwo_cu
.signature
= signature
;
12218 slot
= htab_find_slot (is_debug_types
12219 ? dwp_file
->loaded_tus
.get ()
12220 : dwp_file
->loaded_cus
.get (),
12221 &find_dwo_cu
, INSERT
);
12224 return (struct dwo_unit
*) *slot
;
12226 /* Use a for loop so that we don't loop forever on bad debug info. */
12227 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12229 ULONGEST signature_in_table
;
12231 signature_in_table
=
12232 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12233 if (signature_in_table
== signature
)
12235 uint32_t unit_index
=
12236 read_4_bytes (dbfd
,
12237 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12239 if (dwp_file
->version
== 1)
12241 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12242 unit_index
, comp_dir
,
12243 signature
, is_debug_types
);
12247 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12248 unit_index
, comp_dir
,
12249 signature
, is_debug_types
);
12251 return (struct dwo_unit
*) *slot
;
12253 if (signature_in_table
== 0)
12255 hash
= (hash
+ hash2
) & mask
;
12258 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12259 " [in module %s]"),
12263 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12264 Open the file specified by FILE_NAME and hand it off to BFD for
12265 preliminary analysis. Return a newly initialized bfd *, which
12266 includes a canonicalized copy of FILE_NAME.
12267 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12268 SEARCH_CWD is true if the current directory is to be searched.
12269 It will be searched before debug-file-directory.
12270 If successful, the file is added to the bfd include table of the
12271 objfile's bfd (see gdb_bfd_record_inclusion).
12272 If unable to find/open the file, return NULL.
12273 NOTE: This function is derived from symfile_bfd_open. */
12275 static gdb_bfd_ref_ptr
12276 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12277 const char *file_name
, int is_dwp
, int search_cwd
)
12280 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12281 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12282 to debug_file_directory. */
12283 const char *search_path
;
12284 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12286 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12289 if (*debug_file_directory
!= '\0')
12291 search_path_holder
.reset (concat (".", dirname_separator_string
,
12292 debug_file_directory
,
12294 search_path
= search_path_holder
.get ();
12300 search_path
= debug_file_directory
;
12302 openp_flags flags
= OPF_RETURN_REALPATH
;
12304 flags
|= OPF_SEARCH_IN_PATH
;
12306 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12307 desc
= openp (search_path
, flags
, file_name
,
12308 O_RDONLY
| O_BINARY
, &absolute_name
);
12312 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12314 if (sym_bfd
== NULL
)
12316 bfd_set_cacheable (sym_bfd
.get (), 1);
12318 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12321 /* Success. Record the bfd as having been included by the objfile's bfd.
12322 This is important because things like demangled_names_hash lives in the
12323 objfile's per_bfd space and may have references to things like symbol
12324 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12325 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12330 /* Try to open DWO file FILE_NAME.
12331 COMP_DIR is the DW_AT_comp_dir attribute.
12332 The result is the bfd handle of the file.
12333 If there is a problem finding or opening the file, return NULL.
12334 Upon success, the canonicalized path of the file is stored in the bfd,
12335 same as symfile_bfd_open. */
12337 static gdb_bfd_ref_ptr
12338 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12339 const char *file_name
, const char *comp_dir
)
12341 if (IS_ABSOLUTE_PATH (file_name
))
12342 return try_open_dwop_file (per_objfile
, file_name
,
12343 0 /*is_dwp*/, 0 /*search_cwd*/);
12345 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12347 if (comp_dir
!= NULL
)
12349 gdb::unique_xmalloc_ptr
<char> path_to_try
12350 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12352 /* NOTE: If comp_dir is a relative path, this will also try the
12353 search path, which seems useful. */
12354 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12356 1 /*search_cwd*/));
12361 /* That didn't work, try debug-file-directory, which, despite its name,
12362 is a list of paths. */
12364 if (*debug_file_directory
== '\0')
12367 return try_open_dwop_file (per_objfile
, file_name
,
12368 0 /*is_dwp*/, 1 /*search_cwd*/);
12371 /* This function is mapped across the sections and remembers the offset and
12372 size of each of the DWO debugging sections we are interested in. */
12375 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12377 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12378 const struct dwop_section_names
*names
= &dwop_section_names
;
12380 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12382 dwo_sections
->abbrev
.s
.section
= sectp
;
12383 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12385 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12387 dwo_sections
->info
.s
.section
= sectp
;
12388 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12390 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12392 dwo_sections
->line
.s
.section
= sectp
;
12393 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12395 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12397 dwo_sections
->loc
.s
.section
= sectp
;
12398 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12400 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12402 dwo_sections
->loclists
.s
.section
= sectp
;
12403 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12405 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12407 dwo_sections
->macinfo
.s
.section
= sectp
;
12408 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12410 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12412 dwo_sections
->macro
.s
.section
= sectp
;
12413 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12415 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12417 dwo_sections
->str
.s
.section
= sectp
;
12418 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12420 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12422 dwo_sections
->str_offsets
.s
.section
= sectp
;
12423 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12425 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12427 struct dwarf2_section_info type_section
;
12429 memset (&type_section
, 0, sizeof (type_section
));
12430 type_section
.s
.section
= sectp
;
12431 type_section
.size
= bfd_section_size (sectp
);
12432 dwo_sections
->types
.push_back (type_section
);
12436 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12437 by PER_CU. This is for the non-DWP case.
12438 The result is NULL if DWO_NAME can't be found. */
12440 static struct dwo_file
*
12441 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12442 const char *comp_dir
)
12444 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12446 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12449 if (dwarf_read_debug
)
12450 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12454 dwo_file_up
dwo_file (new struct dwo_file
);
12455 dwo_file
->dwo_name
= dwo_name
;
12456 dwo_file
->comp_dir
= comp_dir
;
12457 dwo_file
->dbfd
= std::move (dbfd
);
12459 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12460 &dwo_file
->sections
);
12462 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12465 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12466 dwo_file
->sections
.types
, dwo_file
->tus
);
12468 if (dwarf_read_debug
)
12469 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12471 return dwo_file
.release ();
12474 /* This function is mapped across the sections and remembers the offset and
12475 size of each of the DWP debugging sections common to version 1 and 2 that
12476 we are interested in. */
12479 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12480 void *dwp_file_ptr
)
12482 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12483 const struct dwop_section_names
*names
= &dwop_section_names
;
12484 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12486 /* Record the ELF section number for later lookup: this is what the
12487 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12488 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12489 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12491 /* Look for specific sections that we need. */
12492 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12494 dwp_file
->sections
.str
.s
.section
= sectp
;
12495 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12497 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12499 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12500 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12502 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12504 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12505 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12509 /* This function is mapped across the sections and remembers the offset and
12510 size of each of the DWP version 2 debugging sections that we are interested
12511 in. This is split into a separate function because we don't know if we
12512 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12515 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12517 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12518 const struct dwop_section_names
*names
= &dwop_section_names
;
12519 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12521 /* Record the ELF section number for later lookup: this is what the
12522 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12523 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12524 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12526 /* Look for specific sections that we need. */
12527 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12529 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12530 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12532 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12534 dwp_file
->sections
.info
.s
.section
= sectp
;
12535 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12537 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12539 dwp_file
->sections
.line
.s
.section
= sectp
;
12540 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12542 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12544 dwp_file
->sections
.loc
.s
.section
= sectp
;
12545 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12547 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12549 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12550 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12552 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12554 dwp_file
->sections
.macro
.s
.section
= sectp
;
12555 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12557 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12559 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12560 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12562 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12564 dwp_file
->sections
.types
.s
.section
= sectp
;
12565 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12569 /* Hash function for dwp_file loaded CUs/TUs. */
12572 hash_dwp_loaded_cutus (const void *item
)
12574 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12576 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12577 return dwo_unit
->signature
;
12580 /* Equality function for dwp_file loaded CUs/TUs. */
12583 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12585 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12586 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12588 return dua
->signature
== dub
->signature
;
12591 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12594 allocate_dwp_loaded_cutus_table ()
12596 return htab_up (htab_create_alloc (3,
12597 hash_dwp_loaded_cutus
,
12598 eq_dwp_loaded_cutus
,
12599 NULL
, xcalloc
, xfree
));
12602 /* Try to open DWP file FILE_NAME.
12603 The result is the bfd handle of the file.
12604 If there is a problem finding or opening the file, return NULL.
12605 Upon success, the canonicalized path of the file is stored in the bfd,
12606 same as symfile_bfd_open. */
12608 static gdb_bfd_ref_ptr
12609 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12611 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12613 1 /*search_cwd*/));
12617 /* Work around upstream bug 15652.
12618 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12619 [Whether that's a "bug" is debatable, but it is getting in our way.]
12620 We have no real idea where the dwp file is, because gdb's realpath-ing
12621 of the executable's path may have discarded the needed info.
12622 [IWBN if the dwp file name was recorded in the executable, akin to
12623 .gnu_debuglink, but that doesn't exist yet.]
12624 Strip the directory from FILE_NAME and search again. */
12625 if (*debug_file_directory
!= '\0')
12627 /* Don't implicitly search the current directory here.
12628 If the user wants to search "." to handle this case,
12629 it must be added to debug-file-directory. */
12630 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12638 /* Initialize the use of the DWP file for the current objfile.
12639 By convention the name of the DWP file is ${objfile}.dwp.
12640 The result is NULL if it can't be found. */
12642 static std::unique_ptr
<struct dwp_file
>
12643 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12645 struct objfile
*objfile
= per_objfile
->objfile
;
12647 /* Try to find first .dwp for the binary file before any symbolic links
12650 /* If the objfile is a debug file, find the name of the real binary
12651 file and get the name of dwp file from there. */
12652 std::string dwp_name
;
12653 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12655 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12656 const char *backlink_basename
= lbasename (backlink
->original_name
);
12658 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12661 dwp_name
= objfile
->original_name
;
12663 dwp_name
+= ".dwp";
12665 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12667 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12669 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12670 dwp_name
= objfile_name (objfile
);
12671 dwp_name
+= ".dwp";
12672 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12677 if (dwarf_read_debug
)
12678 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12679 return std::unique_ptr
<dwp_file
> ();
12682 const char *name
= bfd_get_filename (dbfd
.get ());
12683 std::unique_ptr
<struct dwp_file
> dwp_file
12684 (new struct dwp_file (name
, std::move (dbfd
)));
12686 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12687 dwp_file
->elf_sections
=
12688 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12689 dwp_file
->num_sections
, asection
*);
12691 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12692 dwarf2_locate_common_dwp_sections
,
12695 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12697 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12699 /* The DWP file version is stored in the hash table. Oh well. */
12700 if (dwp_file
->cus
&& dwp_file
->tus
12701 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12703 /* Technically speaking, we should try to limp along, but this is
12704 pretty bizarre. We use pulongest here because that's the established
12705 portability solution (e.g, we cannot use %u for uint32_t). */
12706 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12707 " TU version %s [in DWP file %s]"),
12708 pulongest (dwp_file
->cus
->version
),
12709 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12713 dwp_file
->version
= dwp_file
->cus
->version
;
12714 else if (dwp_file
->tus
)
12715 dwp_file
->version
= dwp_file
->tus
->version
;
12717 dwp_file
->version
= 2;
12719 if (dwp_file
->version
== 2)
12720 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12721 dwarf2_locate_v2_dwp_sections
,
12724 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12725 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12727 if (dwarf_read_debug
)
12729 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12730 fprintf_unfiltered (gdb_stdlog
,
12731 " %s CUs, %s TUs\n",
12732 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12733 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12739 /* Wrapper around open_and_init_dwp_file, only open it once. */
12741 static struct dwp_file
*
12742 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12744 if (!per_objfile
->per_bfd
->dwp_checked
)
12746 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12747 per_objfile
->per_bfd
->dwp_checked
= 1;
12749 return per_objfile
->per_bfd
->dwp_file
.get ();
12752 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12753 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12754 or in the DWP file for the objfile, referenced by THIS_UNIT.
12755 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12756 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12758 This is called, for example, when wanting to read a variable with a
12759 complex location. Therefore we don't want to do file i/o for every call.
12760 Therefore we don't want to look for a DWO file on every call.
12761 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12762 then we check if we've already seen DWO_NAME, and only THEN do we check
12765 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12766 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12768 static struct dwo_unit
*
12769 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12770 ULONGEST signature
, int is_debug_types
)
12772 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12773 struct objfile
*objfile
= per_objfile
->objfile
;
12774 const char *kind
= is_debug_types
? "TU" : "CU";
12775 void **dwo_file_slot
;
12776 struct dwo_file
*dwo_file
;
12777 struct dwp_file
*dwp_file
;
12779 /* First see if there's a DWP file.
12780 If we have a DWP file but didn't find the DWO inside it, don't
12781 look for the original DWO file. It makes gdb behave differently
12782 depending on whether one is debugging in the build tree. */
12784 dwp_file
= get_dwp_file (per_objfile
);
12785 if (dwp_file
!= NULL
)
12787 const struct dwp_hash_table
*dwp_htab
=
12788 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12790 if (dwp_htab
!= NULL
)
12792 struct dwo_unit
*dwo_cutu
=
12793 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12796 if (dwo_cutu
!= NULL
)
12798 if (dwarf_read_debug
)
12800 fprintf_unfiltered (gdb_stdlog
,
12801 "Virtual DWO %s %s found: @%s\n",
12802 kind
, hex_string (signature
),
12803 host_address_to_string (dwo_cutu
));
12811 /* No DWP file, look for the DWO file. */
12813 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12814 if (*dwo_file_slot
== NULL
)
12816 /* Read in the file and build a table of the CUs/TUs it contains. */
12817 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12819 /* NOTE: This will be NULL if unable to open the file. */
12820 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12822 if (dwo_file
!= NULL
)
12824 struct dwo_unit
*dwo_cutu
= NULL
;
12826 if (is_debug_types
&& dwo_file
->tus
)
12828 struct dwo_unit find_dwo_cutu
;
12830 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12831 find_dwo_cutu
.signature
= signature
;
12833 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12836 else if (!is_debug_types
&& dwo_file
->cus
)
12838 struct dwo_unit find_dwo_cutu
;
12840 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12841 find_dwo_cutu
.signature
= signature
;
12842 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12846 if (dwo_cutu
!= NULL
)
12848 if (dwarf_read_debug
)
12850 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12851 kind
, dwo_name
, hex_string (signature
),
12852 host_address_to_string (dwo_cutu
));
12859 /* We didn't find it. This could mean a dwo_id mismatch, or
12860 someone deleted the DWO/DWP file, or the search path isn't set up
12861 correctly to find the file. */
12863 if (dwarf_read_debug
)
12865 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12866 kind
, dwo_name
, hex_string (signature
));
12869 /* This is a warning and not a complaint because it can be caused by
12870 pilot error (e.g., user accidentally deleting the DWO). */
12872 /* Print the name of the DWP file if we looked there, helps the user
12873 better diagnose the problem. */
12874 std::string dwp_text
;
12876 if (dwp_file
!= NULL
)
12877 dwp_text
= string_printf (" [in DWP file %s]",
12878 lbasename (dwp_file
->name
));
12880 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12881 " [in module %s]"),
12882 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12883 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12888 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12889 See lookup_dwo_cutu_unit for details. */
12891 static struct dwo_unit
*
12892 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12893 ULONGEST signature
)
12895 gdb_assert (!cu
->per_cu
->is_debug_types
);
12897 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12900 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12901 See lookup_dwo_cutu_unit for details. */
12903 static struct dwo_unit
*
12904 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12906 gdb_assert (cu
->per_cu
->is_debug_types
);
12908 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12910 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12913 /* Traversal function for queue_and_load_all_dwo_tus. */
12916 queue_and_load_dwo_tu (void **slot
, void *info
)
12918 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12919 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12920 ULONGEST signature
= dwo_unit
->signature
;
12921 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12923 if (sig_type
!= NULL
)
12925 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12927 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12928 a real dependency of PER_CU on SIG_TYPE. That is detected later
12929 while processing PER_CU. */
12930 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
12931 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12932 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12938 /* Queue all TUs contained in the DWO of CU to be read in.
12939 The DWO may have the only definition of the type, though it may not be
12940 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12941 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12944 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12946 struct dwo_unit
*dwo_unit
;
12947 struct dwo_file
*dwo_file
;
12949 gdb_assert (cu
!= nullptr);
12950 gdb_assert (!cu
->per_cu
->is_debug_types
);
12951 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12953 dwo_unit
= cu
->dwo_unit
;
12954 gdb_assert (dwo_unit
!= NULL
);
12956 dwo_file
= dwo_unit
->dwo_file
;
12957 if (dwo_file
->tus
!= NULL
)
12958 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12961 /* Read in various DIEs. */
12963 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12964 Inherit only the children of the DW_AT_abstract_origin DIE not being
12965 already referenced by DW_AT_abstract_origin from the children of the
12969 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12971 struct die_info
*child_die
;
12972 sect_offset
*offsetp
;
12973 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12974 struct die_info
*origin_die
;
12975 /* Iterator of the ORIGIN_DIE children. */
12976 struct die_info
*origin_child_die
;
12977 struct attribute
*attr
;
12978 struct dwarf2_cu
*origin_cu
;
12979 struct pending
**origin_previous_list_in_scope
;
12981 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12985 /* Note that following die references may follow to a die in a
12989 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12991 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12993 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12994 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12996 if (die
->tag
!= origin_die
->tag
12997 && !(die
->tag
== DW_TAG_inlined_subroutine
12998 && origin_die
->tag
== DW_TAG_subprogram
))
12999 complaint (_("DIE %s and its abstract origin %s have different tags"),
13000 sect_offset_str (die
->sect_off
),
13001 sect_offset_str (origin_die
->sect_off
));
13003 std::vector
<sect_offset
> offsets
;
13005 for (child_die
= die
->child
;
13006 child_die
&& child_die
->tag
;
13007 child_die
= child_die
->sibling
)
13009 struct die_info
*child_origin_die
;
13010 struct dwarf2_cu
*child_origin_cu
;
13012 /* We are trying to process concrete instance entries:
13013 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13014 it's not relevant to our analysis here. i.e. detecting DIEs that are
13015 present in the abstract instance but not referenced in the concrete
13017 if (child_die
->tag
== DW_TAG_call_site
13018 || child_die
->tag
== DW_TAG_GNU_call_site
)
13021 /* For each CHILD_DIE, find the corresponding child of
13022 ORIGIN_DIE. If there is more than one layer of
13023 DW_AT_abstract_origin, follow them all; there shouldn't be,
13024 but GCC versions at least through 4.4 generate this (GCC PR
13026 child_origin_die
= child_die
;
13027 child_origin_cu
= cu
;
13030 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13034 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13038 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13039 counterpart may exist. */
13040 if (child_origin_die
!= child_die
)
13042 if (child_die
->tag
!= child_origin_die
->tag
13043 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13044 && child_origin_die
->tag
== DW_TAG_subprogram
))
13045 complaint (_("Child DIE %s and its abstract origin %s have "
13047 sect_offset_str (child_die
->sect_off
),
13048 sect_offset_str (child_origin_die
->sect_off
));
13049 if (child_origin_die
->parent
!= origin_die
)
13050 complaint (_("Child DIE %s and its abstract origin %s have "
13051 "different parents"),
13052 sect_offset_str (child_die
->sect_off
),
13053 sect_offset_str (child_origin_die
->sect_off
));
13055 offsets
.push_back (child_origin_die
->sect_off
);
13058 std::sort (offsets
.begin (), offsets
.end ());
13059 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13060 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13061 if (offsetp
[-1] == *offsetp
)
13062 complaint (_("Multiple children of DIE %s refer "
13063 "to DIE %s as their abstract origin"),
13064 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13066 offsetp
= offsets
.data ();
13067 origin_child_die
= origin_die
->child
;
13068 while (origin_child_die
&& origin_child_die
->tag
)
13070 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13071 while (offsetp
< offsets_end
13072 && *offsetp
< origin_child_die
->sect_off
)
13074 if (offsetp
>= offsets_end
13075 || *offsetp
> origin_child_die
->sect_off
)
13077 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13078 Check whether we're already processing ORIGIN_CHILD_DIE.
13079 This can happen with mutually referenced abstract_origins.
13081 if (!origin_child_die
->in_process
)
13082 process_die (origin_child_die
, origin_cu
);
13084 origin_child_die
= origin_child_die
->sibling
;
13086 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13088 if (cu
!= origin_cu
)
13089 compute_delayed_physnames (origin_cu
);
13093 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13095 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13096 struct gdbarch
*gdbarch
= objfile
->arch ();
13097 struct context_stack
*newobj
;
13100 struct die_info
*child_die
;
13101 struct attribute
*attr
, *call_line
, *call_file
;
13103 CORE_ADDR baseaddr
;
13104 struct block
*block
;
13105 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13106 std::vector
<struct symbol
*> template_args
;
13107 struct template_symbol
*templ_func
= NULL
;
13111 /* If we do not have call site information, we can't show the
13112 caller of this inlined function. That's too confusing, so
13113 only use the scope for local variables. */
13114 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13115 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13116 if (call_line
== NULL
|| call_file
== NULL
)
13118 read_lexical_block_scope (die
, cu
);
13123 baseaddr
= objfile
->text_section_offset ();
13125 name
= dwarf2_name (die
, cu
);
13127 /* Ignore functions with missing or empty names. These are actually
13128 illegal according to the DWARF standard. */
13131 complaint (_("missing name for subprogram DIE at %s"),
13132 sect_offset_str (die
->sect_off
));
13136 /* Ignore functions with missing or invalid low and high pc attributes. */
13137 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13138 <= PC_BOUNDS_INVALID
)
13140 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13141 if (!attr
|| !DW_UNSND (attr
))
13142 complaint (_("cannot get low and high bounds "
13143 "for subprogram DIE at %s"),
13144 sect_offset_str (die
->sect_off
));
13148 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13149 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13151 /* If we have any template arguments, then we must allocate a
13152 different sort of symbol. */
13153 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13155 if (child_die
->tag
== DW_TAG_template_type_param
13156 || child_die
->tag
== DW_TAG_template_value_param
)
13158 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13159 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13164 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13165 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13166 (struct symbol
*) templ_func
);
13168 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13169 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13172 /* If there is a location expression for DW_AT_frame_base, record
13174 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13175 if (attr
!= nullptr)
13176 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13178 /* If there is a location for the static link, record it. */
13179 newobj
->static_link
= NULL
;
13180 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13181 if (attr
!= nullptr)
13183 newobj
->static_link
13184 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13185 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13189 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13191 if (die
->child
!= NULL
)
13193 child_die
= die
->child
;
13194 while (child_die
&& child_die
->tag
)
13196 if (child_die
->tag
== DW_TAG_template_type_param
13197 || child_die
->tag
== DW_TAG_template_value_param
)
13199 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13202 template_args
.push_back (arg
);
13205 process_die (child_die
, cu
);
13206 child_die
= child_die
->sibling
;
13210 inherit_abstract_dies (die
, cu
);
13212 /* If we have a DW_AT_specification, we might need to import using
13213 directives from the context of the specification DIE. See the
13214 comment in determine_prefix. */
13215 if (cu
->language
== language_cplus
13216 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13218 struct dwarf2_cu
*spec_cu
= cu
;
13219 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13223 child_die
= spec_die
->child
;
13224 while (child_die
&& child_die
->tag
)
13226 if (child_die
->tag
== DW_TAG_imported_module
)
13227 process_die (child_die
, spec_cu
);
13228 child_die
= child_die
->sibling
;
13231 /* In some cases, GCC generates specification DIEs that
13232 themselves contain DW_AT_specification attributes. */
13233 spec_die
= die_specification (spec_die
, &spec_cu
);
13237 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13238 /* Make a block for the local symbols within. */
13239 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13240 cstk
.static_link
, lowpc
, highpc
);
13242 /* For C++, set the block's scope. */
13243 if ((cu
->language
== language_cplus
13244 || cu
->language
== language_fortran
13245 || cu
->language
== language_d
13246 || cu
->language
== language_rust
)
13247 && cu
->processing_has_namespace_info
)
13248 block_set_scope (block
, determine_prefix (die
, cu
),
13249 &objfile
->objfile_obstack
);
13251 /* If we have address ranges, record them. */
13252 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13254 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13256 /* Attach template arguments to function. */
13257 if (!template_args
.empty ())
13259 gdb_assert (templ_func
!= NULL
);
13261 templ_func
->n_template_arguments
= template_args
.size ();
13262 templ_func
->template_arguments
13263 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13264 templ_func
->n_template_arguments
);
13265 memcpy (templ_func
->template_arguments
,
13266 template_args
.data (),
13267 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13269 /* Make sure that the symtab is set on the new symbols. Even
13270 though they don't appear in this symtab directly, other parts
13271 of gdb assume that symbols do, and this is reasonably
13273 for (symbol
*sym
: template_args
)
13274 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13277 /* In C++, we can have functions nested inside functions (e.g., when
13278 a function declares a class that has methods). This means that
13279 when we finish processing a function scope, we may need to go
13280 back to building a containing block's symbol lists. */
13281 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13282 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13284 /* If we've finished processing a top-level function, subsequent
13285 symbols go in the file symbol list. */
13286 if (cu
->get_builder ()->outermost_context_p ())
13287 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13290 /* Process all the DIES contained within a lexical block scope. Start
13291 a new scope, process the dies, and then close the scope. */
13294 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13296 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13297 struct gdbarch
*gdbarch
= objfile
->arch ();
13298 CORE_ADDR lowpc
, highpc
;
13299 struct die_info
*child_die
;
13300 CORE_ADDR baseaddr
;
13302 baseaddr
= objfile
->text_section_offset ();
13304 /* Ignore blocks with missing or invalid low and high pc attributes. */
13305 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13306 as multiple lexical blocks? Handling children in a sane way would
13307 be nasty. Might be easier to properly extend generic blocks to
13308 describe ranges. */
13309 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13311 case PC_BOUNDS_NOT_PRESENT
:
13312 /* DW_TAG_lexical_block has no attributes, process its children as if
13313 there was no wrapping by that DW_TAG_lexical_block.
13314 GCC does no longer produces such DWARF since GCC r224161. */
13315 for (child_die
= die
->child
;
13316 child_die
!= NULL
&& child_die
->tag
;
13317 child_die
= child_die
->sibling
)
13319 /* We might already be processing this DIE. This can happen
13320 in an unusual circumstance -- where a subroutine A
13321 appears lexically in another subroutine B, but A actually
13322 inlines B. The recursion is broken here, rather than in
13323 inherit_abstract_dies, because it seems better to simply
13324 drop concrete children here. */
13325 if (!child_die
->in_process
)
13326 process_die (child_die
, cu
);
13329 case PC_BOUNDS_INVALID
:
13332 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13333 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13335 cu
->get_builder ()->push_context (0, lowpc
);
13336 if (die
->child
!= NULL
)
13338 child_die
= die
->child
;
13339 while (child_die
&& child_die
->tag
)
13341 process_die (child_die
, cu
);
13342 child_die
= child_die
->sibling
;
13345 inherit_abstract_dies (die
, cu
);
13346 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13348 if (*cu
->get_builder ()->get_local_symbols () != NULL
13349 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13351 struct block
*block
13352 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13353 cstk
.start_addr
, highpc
);
13355 /* Note that recording ranges after traversing children, as we
13356 do here, means that recording a parent's ranges entails
13357 walking across all its children's ranges as they appear in
13358 the address map, which is quadratic behavior.
13360 It would be nicer to record the parent's ranges before
13361 traversing its children, simply overriding whatever you find
13362 there. But since we don't even decide whether to create a
13363 block until after we've traversed its children, that's hard
13365 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13367 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13368 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13371 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13374 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13376 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13377 struct objfile
*objfile
= per_objfile
->objfile
;
13378 struct gdbarch
*gdbarch
= objfile
->arch ();
13379 CORE_ADDR pc
, baseaddr
;
13380 struct attribute
*attr
;
13381 struct call_site
*call_site
, call_site_local
;
13384 struct die_info
*child_die
;
13386 baseaddr
= objfile
->text_section_offset ();
13388 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13391 /* This was a pre-DWARF-5 GNU extension alias
13392 for DW_AT_call_return_pc. */
13393 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13397 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13398 "DIE %s [in module %s]"),
13399 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13402 pc
= attr
->value_as_address () + baseaddr
;
13403 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13405 if (cu
->call_site_htab
== NULL
)
13406 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13407 NULL
, &objfile
->objfile_obstack
,
13408 hashtab_obstack_allocate
, NULL
);
13409 call_site_local
.pc
= pc
;
13410 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13413 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13414 "DIE %s [in module %s]"),
13415 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13416 objfile_name (objfile
));
13420 /* Count parameters at the caller. */
13423 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13424 child_die
= child_die
->sibling
)
13426 if (child_die
->tag
!= DW_TAG_call_site_parameter
13427 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13429 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13430 "DW_TAG_call_site child DIE %s [in module %s]"),
13431 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13432 objfile_name (objfile
));
13440 = ((struct call_site
*)
13441 obstack_alloc (&objfile
->objfile_obstack
,
13442 sizeof (*call_site
)
13443 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13445 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13446 call_site
->pc
= pc
;
13448 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13449 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13451 struct die_info
*func_die
;
13453 /* Skip also over DW_TAG_inlined_subroutine. */
13454 for (func_die
= die
->parent
;
13455 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13456 && func_die
->tag
!= DW_TAG_subroutine_type
;
13457 func_die
= func_die
->parent
);
13459 /* DW_AT_call_all_calls is a superset
13460 of DW_AT_call_all_tail_calls. */
13462 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13463 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13464 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13465 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13467 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13468 not complete. But keep CALL_SITE for look ups via call_site_htab,
13469 both the initial caller containing the real return address PC and
13470 the final callee containing the current PC of a chain of tail
13471 calls do not need to have the tail call list complete. But any
13472 function candidate for a virtual tail call frame searched via
13473 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13474 determined unambiguously. */
13478 struct type
*func_type
= NULL
;
13481 func_type
= get_die_type (func_die
, cu
);
13482 if (func_type
!= NULL
)
13484 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13486 /* Enlist this call site to the function. */
13487 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13488 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13491 complaint (_("Cannot find function owning DW_TAG_call_site "
13492 "DIE %s [in module %s]"),
13493 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13497 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13499 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13501 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13504 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13505 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13507 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13508 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13509 /* Keep NULL DWARF_BLOCK. */;
13510 else if (attr
->form_is_block ())
13512 struct dwarf2_locexpr_baton
*dlbaton
;
13514 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13515 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13516 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13517 dlbaton
->per_objfile
= per_objfile
;
13518 dlbaton
->per_cu
= cu
->per_cu
;
13520 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13522 else if (attr
->form_is_ref ())
13524 struct dwarf2_cu
*target_cu
= cu
;
13525 struct die_info
*target_die
;
13527 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13528 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13529 if (die_is_declaration (target_die
, target_cu
))
13531 const char *target_physname
;
13533 /* Prefer the mangled name; otherwise compute the demangled one. */
13534 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13535 if (target_physname
== NULL
)
13536 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13537 if (target_physname
== NULL
)
13538 complaint (_("DW_AT_call_target target DIE has invalid "
13539 "physname, for referencing DIE %s [in module %s]"),
13540 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13542 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13548 /* DW_AT_entry_pc should be preferred. */
13549 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13550 <= PC_BOUNDS_INVALID
)
13551 complaint (_("DW_AT_call_target target DIE has invalid "
13552 "low pc, for referencing DIE %s [in module %s]"),
13553 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13556 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13557 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13562 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13563 "block nor reference, for DIE %s [in module %s]"),
13564 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13566 call_site
->per_cu
= cu
->per_cu
;
13567 call_site
->per_objfile
= per_objfile
;
13569 for (child_die
= die
->child
;
13570 child_die
&& child_die
->tag
;
13571 child_die
= child_die
->sibling
)
13573 struct call_site_parameter
*parameter
;
13574 struct attribute
*loc
, *origin
;
13576 if (child_die
->tag
!= DW_TAG_call_site_parameter
13577 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13579 /* Already printed the complaint above. */
13583 gdb_assert (call_site
->parameter_count
< nparams
);
13584 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13586 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13587 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13588 register is contained in DW_AT_call_value. */
13590 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13591 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13592 if (origin
== NULL
)
13594 /* This was a pre-DWARF-5 GNU extension alias
13595 for DW_AT_call_parameter. */
13596 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13598 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13600 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13602 sect_offset sect_off
= origin
->get_ref_die_offset ();
13603 if (!cu
->header
.offset_in_cu_p (sect_off
))
13605 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13606 binding can be done only inside one CU. Such referenced DIE
13607 therefore cannot be even moved to DW_TAG_partial_unit. */
13608 complaint (_("DW_AT_call_parameter offset is not in CU for "
13609 "DW_TAG_call_site child DIE %s [in module %s]"),
13610 sect_offset_str (child_die
->sect_off
),
13611 objfile_name (objfile
));
13614 parameter
->u
.param_cu_off
13615 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13617 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13619 complaint (_("No DW_FORM_block* DW_AT_location for "
13620 "DW_TAG_call_site child DIE %s [in module %s]"),
13621 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13626 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13627 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13628 if (parameter
->u
.dwarf_reg
!= -1)
13629 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13630 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13631 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13632 ¶meter
->u
.fb_offset
))
13633 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13636 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13637 "for DW_FORM_block* DW_AT_location is supported for "
13638 "DW_TAG_call_site child DIE %s "
13640 sect_offset_str (child_die
->sect_off
),
13641 objfile_name (objfile
));
13646 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13648 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13649 if (attr
== NULL
|| !attr
->form_is_block ())
13651 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13652 "DW_TAG_call_site child DIE %s [in module %s]"),
13653 sect_offset_str (child_die
->sect_off
),
13654 objfile_name (objfile
));
13657 parameter
->value
= DW_BLOCK (attr
)->data
;
13658 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13660 /* Parameters are not pre-cleared by memset above. */
13661 parameter
->data_value
= NULL
;
13662 parameter
->data_value_size
= 0;
13663 call_site
->parameter_count
++;
13665 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13667 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13668 if (attr
!= nullptr)
13670 if (!attr
->form_is_block ())
13671 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13672 "DW_TAG_call_site child DIE %s [in module %s]"),
13673 sect_offset_str (child_die
->sect_off
),
13674 objfile_name (objfile
));
13677 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13678 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13684 /* Helper function for read_variable. If DIE represents a virtual
13685 table, then return the type of the concrete object that is
13686 associated with the virtual table. Otherwise, return NULL. */
13688 static struct type
*
13689 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13691 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13695 /* Find the type DIE. */
13696 struct die_info
*type_die
= NULL
;
13697 struct dwarf2_cu
*type_cu
= cu
;
13699 if (attr
->form_is_ref ())
13700 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13701 if (type_die
== NULL
)
13704 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13706 return die_containing_type (type_die
, type_cu
);
13709 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13712 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13714 struct rust_vtable_symbol
*storage
= NULL
;
13716 if (cu
->language
== language_rust
)
13718 struct type
*containing_type
= rust_containing_type (die
, cu
);
13720 if (containing_type
!= NULL
)
13722 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13724 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13725 storage
->concrete_type
= containing_type
;
13726 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13730 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13731 struct attribute
*abstract_origin
13732 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13733 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13734 if (res
== NULL
&& loc
&& abstract_origin
)
13736 /* We have a variable without a name, but with a location and an abstract
13737 origin. This may be a concrete instance of an abstract variable
13738 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13740 struct dwarf2_cu
*origin_cu
= cu
;
13741 struct die_info
*origin_die
13742 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13743 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13744 per_objfile
->per_bfd
->abstract_to_concrete
13745 [origin_die
->sect_off
].push_back (die
->sect_off
);
13749 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13750 reading .debug_rnglists.
13751 Callback's type should be:
13752 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13753 Return true if the attributes are present and valid, otherwise,
13756 template <typename Callback
>
13758 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13759 Callback
&&callback
)
13761 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13762 struct objfile
*objfile
= per_objfile
->objfile
;
13763 bfd
*obfd
= objfile
->obfd
;
13764 /* Base address selection entry. */
13765 gdb::optional
<CORE_ADDR
> base
;
13766 const gdb_byte
*buffer
;
13767 CORE_ADDR baseaddr
;
13768 bool overflow
= false;
13770 base
= cu
->base_address
;
13772 per_objfile
->per_bfd
->rnglists
.read (objfile
);
13773 if (offset
>= per_objfile
->per_bfd
->rnglists
.size
)
13775 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13779 buffer
= per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13781 baseaddr
= objfile
->text_section_offset ();
13785 /* Initialize it due to a false compiler warning. */
13786 CORE_ADDR range_beginning
= 0, range_end
= 0;
13787 const gdb_byte
*buf_end
= (per_objfile
->per_bfd
->rnglists
.buffer
13788 + per_objfile
->per_bfd
->rnglists
.size
);
13789 unsigned int bytes_read
;
13791 if (buffer
== buf_end
)
13796 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13799 case DW_RLE_end_of_list
:
13801 case DW_RLE_base_address
:
13802 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13807 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13808 buffer
+= bytes_read
;
13810 case DW_RLE_start_length
:
13811 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13816 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13818 buffer
+= bytes_read
;
13819 range_end
= (range_beginning
13820 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13821 buffer
+= bytes_read
;
13822 if (buffer
> buf_end
)
13828 case DW_RLE_offset_pair
:
13829 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13830 buffer
+= bytes_read
;
13831 if (buffer
> buf_end
)
13836 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13837 buffer
+= bytes_read
;
13838 if (buffer
> buf_end
)
13844 case DW_RLE_start_end
:
13845 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13850 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13852 buffer
+= bytes_read
;
13853 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13854 buffer
+= bytes_read
;
13857 complaint (_("Invalid .debug_rnglists data (no base address)"));
13860 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13862 if (rlet
== DW_RLE_base_address
)
13865 if (!base
.has_value ())
13867 /* We have no valid base address for the ranges
13869 complaint (_("Invalid .debug_rnglists data (no base address)"));
13873 if (range_beginning
> range_end
)
13875 /* Inverted range entries are invalid. */
13876 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13880 /* Empty range entries have no effect. */
13881 if (range_beginning
== range_end
)
13884 range_beginning
+= *base
;
13885 range_end
+= *base
;
13887 /* A not-uncommon case of bad debug info.
13888 Don't pollute the addrmap with bad data. */
13889 if (range_beginning
+ baseaddr
== 0
13890 && !per_objfile
->per_bfd
->has_section_at_zero
)
13892 complaint (_(".debug_rnglists entry has start address of zero"
13893 " [in module %s]"), objfile_name (objfile
));
13897 callback (range_beginning
, range_end
);
13902 complaint (_("Offset %d is not terminated "
13903 "for DW_AT_ranges attribute"),
13911 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13912 Callback's type should be:
13913 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13914 Return 1 if the attributes are present and valid, otherwise, return 0. */
13916 template <typename Callback
>
13918 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13919 Callback
&&callback
)
13921 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13922 struct objfile
*objfile
= per_objfile
->objfile
;
13923 struct comp_unit_head
*cu_header
= &cu
->header
;
13924 bfd
*obfd
= objfile
->obfd
;
13925 unsigned int addr_size
= cu_header
->addr_size
;
13926 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13927 /* Base address selection entry. */
13928 gdb::optional
<CORE_ADDR
> base
;
13929 unsigned int dummy
;
13930 const gdb_byte
*buffer
;
13931 CORE_ADDR baseaddr
;
13933 if (cu_header
->version
>= 5)
13934 return dwarf2_rnglists_process (offset
, cu
, callback
);
13936 base
= cu
->base_address
;
13938 per_objfile
->per_bfd
->ranges
.read (objfile
);
13939 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13941 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13945 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13947 baseaddr
= objfile
->text_section_offset ();
13951 CORE_ADDR range_beginning
, range_end
;
13953 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13954 buffer
+= addr_size
;
13955 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13956 buffer
+= addr_size
;
13957 offset
+= 2 * addr_size
;
13959 /* An end of list marker is a pair of zero addresses. */
13960 if (range_beginning
== 0 && range_end
== 0)
13961 /* Found the end of list entry. */
13964 /* Each base address selection entry is a pair of 2 values.
13965 The first is the largest possible address, the second is
13966 the base address. Check for a base address here. */
13967 if ((range_beginning
& mask
) == mask
)
13969 /* If we found the largest possible address, then we already
13970 have the base address in range_end. */
13975 if (!base
.has_value ())
13977 /* We have no valid base address for the ranges
13979 complaint (_("Invalid .debug_ranges data (no base address)"));
13983 if (range_beginning
> range_end
)
13985 /* Inverted range entries are invalid. */
13986 complaint (_("Invalid .debug_ranges data (inverted range)"));
13990 /* Empty range entries have no effect. */
13991 if (range_beginning
== range_end
)
13994 range_beginning
+= *base
;
13995 range_end
+= *base
;
13997 /* A not-uncommon case of bad debug info.
13998 Don't pollute the addrmap with bad data. */
13999 if (range_beginning
+ baseaddr
== 0
14000 && !per_objfile
->per_bfd
->has_section_at_zero
)
14002 complaint (_(".debug_ranges entry has start address of zero"
14003 " [in module %s]"), objfile_name (objfile
));
14007 callback (range_beginning
, range_end
);
14013 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14014 Return 1 if the attributes are present and valid, otherwise, return 0.
14015 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14018 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14019 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14020 dwarf2_psymtab
*ranges_pst
)
14022 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14023 struct gdbarch
*gdbarch
= objfile
->arch ();
14024 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14027 CORE_ADDR high
= 0;
14030 retval
= dwarf2_ranges_process (offset
, cu
,
14031 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14033 if (ranges_pst
!= NULL
)
14038 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14039 range_beginning
+ baseaddr
)
14041 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14042 range_end
+ baseaddr
)
14044 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14045 lowpc
, highpc
- 1, ranges_pst
);
14048 /* FIXME: This is recording everything as a low-high
14049 segment of consecutive addresses. We should have a
14050 data structure for discontiguous block ranges
14054 low
= range_beginning
;
14060 if (range_beginning
< low
)
14061 low
= range_beginning
;
14062 if (range_end
> high
)
14070 /* If the first entry is an end-of-list marker, the range
14071 describes an empty scope, i.e. no instructions. */
14077 *high_return
= high
;
14081 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14082 definition for the return value. *LOWPC and *HIGHPC are set iff
14083 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14085 static enum pc_bounds_kind
14086 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14087 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14088 dwarf2_psymtab
*pst
)
14090 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14091 struct attribute
*attr
;
14092 struct attribute
*attr_high
;
14094 CORE_ADDR high
= 0;
14095 enum pc_bounds_kind ret
;
14097 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14100 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14101 if (attr
!= nullptr)
14103 low
= attr
->value_as_address ();
14104 high
= attr_high
->value_as_address ();
14105 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14109 /* Found high w/o low attribute. */
14110 return PC_BOUNDS_INVALID
;
14112 /* Found consecutive range of addresses. */
14113 ret
= PC_BOUNDS_HIGH_LOW
;
14117 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14120 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14121 We take advantage of the fact that DW_AT_ranges does not appear
14122 in DW_TAG_compile_unit of DWO files. */
14123 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14124 unsigned int ranges_offset
= (DW_UNSND (attr
)
14125 + (need_ranges_base
14129 /* Value of the DW_AT_ranges attribute is the offset in the
14130 .debug_ranges section. */
14131 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14132 return PC_BOUNDS_INVALID
;
14133 /* Found discontinuous range of addresses. */
14134 ret
= PC_BOUNDS_RANGES
;
14137 return PC_BOUNDS_NOT_PRESENT
;
14140 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14142 return PC_BOUNDS_INVALID
;
14144 /* When using the GNU linker, .gnu.linkonce. sections are used to
14145 eliminate duplicate copies of functions and vtables and such.
14146 The linker will arbitrarily choose one and discard the others.
14147 The AT_*_pc values for such functions refer to local labels in
14148 these sections. If the section from that file was discarded, the
14149 labels are not in the output, so the relocs get a value of 0.
14150 If this is a discarded function, mark the pc bounds as invalid,
14151 so that GDB will ignore it. */
14152 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14153 return PC_BOUNDS_INVALID
;
14161 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14162 its low and high PC addresses. Do nothing if these addresses could not
14163 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14164 and HIGHPC to the high address if greater than HIGHPC. */
14167 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14168 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14169 struct dwarf2_cu
*cu
)
14171 CORE_ADDR low
, high
;
14172 struct die_info
*child
= die
->child
;
14174 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14176 *lowpc
= std::min (*lowpc
, low
);
14177 *highpc
= std::max (*highpc
, high
);
14180 /* If the language does not allow nested subprograms (either inside
14181 subprograms or lexical blocks), we're done. */
14182 if (cu
->language
!= language_ada
)
14185 /* Check all the children of the given DIE. If it contains nested
14186 subprograms, then check their pc bounds. Likewise, we need to
14187 check lexical blocks as well, as they may also contain subprogram
14189 while (child
&& child
->tag
)
14191 if (child
->tag
== DW_TAG_subprogram
14192 || child
->tag
== DW_TAG_lexical_block
)
14193 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14194 child
= child
->sibling
;
14198 /* Get the low and high pc's represented by the scope DIE, and store
14199 them in *LOWPC and *HIGHPC. If the correct values can't be
14200 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14203 get_scope_pc_bounds (struct die_info
*die
,
14204 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14205 struct dwarf2_cu
*cu
)
14207 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14208 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14209 CORE_ADDR current_low
, current_high
;
14211 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14212 >= PC_BOUNDS_RANGES
)
14214 best_low
= current_low
;
14215 best_high
= current_high
;
14219 struct die_info
*child
= die
->child
;
14221 while (child
&& child
->tag
)
14223 switch (child
->tag
) {
14224 case DW_TAG_subprogram
:
14225 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14227 case DW_TAG_namespace
:
14228 case DW_TAG_module
:
14229 /* FIXME: carlton/2004-01-16: Should we do this for
14230 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14231 that current GCC's always emit the DIEs corresponding
14232 to definitions of methods of classes as children of a
14233 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14234 the DIEs giving the declarations, which could be
14235 anywhere). But I don't see any reason why the
14236 standards says that they have to be there. */
14237 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14239 if (current_low
!= ((CORE_ADDR
) -1))
14241 best_low
= std::min (best_low
, current_low
);
14242 best_high
= std::max (best_high
, current_high
);
14250 child
= child
->sibling
;
14255 *highpc
= best_high
;
14258 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14262 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14263 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14265 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14266 struct gdbarch
*gdbarch
= objfile
->arch ();
14267 struct attribute
*attr
;
14268 struct attribute
*attr_high
;
14270 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14273 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14274 if (attr
!= nullptr)
14276 CORE_ADDR low
= attr
->value_as_address ();
14277 CORE_ADDR high
= attr_high
->value_as_address ();
14279 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14282 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14283 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14284 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14288 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14289 if (attr
!= nullptr)
14291 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14292 We take advantage of the fact that DW_AT_ranges does not appear
14293 in DW_TAG_compile_unit of DWO files. */
14294 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14296 /* The value of the DW_AT_ranges attribute is the offset of the
14297 address range list in the .debug_ranges section. */
14298 unsigned long offset
= (DW_UNSND (attr
)
14299 + (need_ranges_base
? cu
->ranges_base
: 0));
14301 std::vector
<blockrange
> blockvec
;
14302 dwarf2_ranges_process (offset
, cu
,
14303 [&] (CORE_ADDR start
, CORE_ADDR end
)
14307 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14308 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14309 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14310 blockvec
.emplace_back (start
, end
);
14313 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14317 /* Check whether the producer field indicates either of GCC < 4.6, or the
14318 Intel C/C++ compiler, and cache the result in CU. */
14321 check_producer (struct dwarf2_cu
*cu
)
14325 if (cu
->producer
== NULL
)
14327 /* For unknown compilers expect their behavior is DWARF version
14330 GCC started to support .debug_types sections by -gdwarf-4 since
14331 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14332 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14333 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14334 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14336 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14338 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14339 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14341 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14343 cu
->producer_is_icc
= true;
14344 cu
->producer_is_icc_lt_14
= major
< 14;
14346 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14347 cu
->producer_is_codewarrior
= true;
14350 /* For other non-GCC compilers, expect their behavior is DWARF version
14354 cu
->checked_producer
= true;
14357 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14358 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14359 during 4.6.0 experimental. */
14362 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14364 if (!cu
->checked_producer
)
14365 check_producer (cu
);
14367 return cu
->producer_is_gxx_lt_4_6
;
14371 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14372 with incorrect is_stmt attributes. */
14375 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14377 if (!cu
->checked_producer
)
14378 check_producer (cu
);
14380 return cu
->producer_is_codewarrior
;
14383 /* Return the default accessibility type if it is not overridden by
14384 DW_AT_accessibility. */
14386 static enum dwarf_access_attribute
14387 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14389 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14391 /* The default DWARF 2 accessibility for members is public, the default
14392 accessibility for inheritance is private. */
14394 if (die
->tag
!= DW_TAG_inheritance
)
14395 return DW_ACCESS_public
;
14397 return DW_ACCESS_private
;
14401 /* DWARF 3+ defines the default accessibility a different way. The same
14402 rules apply now for DW_TAG_inheritance as for the members and it only
14403 depends on the container kind. */
14405 if (die
->parent
->tag
== DW_TAG_class_type
)
14406 return DW_ACCESS_private
;
14408 return DW_ACCESS_public
;
14412 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14413 offset. If the attribute was not found return 0, otherwise return
14414 1. If it was found but could not properly be handled, set *OFFSET
14418 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14421 struct attribute
*attr
;
14423 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14428 /* Note that we do not check for a section offset first here.
14429 This is because DW_AT_data_member_location is new in DWARF 4,
14430 so if we see it, we can assume that a constant form is really
14431 a constant and not a section offset. */
14432 if (attr
->form_is_constant ())
14433 *offset
= attr
->constant_value (0);
14434 else if (attr
->form_is_section_offset ())
14435 dwarf2_complex_location_expr_complaint ();
14436 else if (attr
->form_is_block ())
14437 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14439 dwarf2_complex_location_expr_complaint ();
14447 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14450 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14451 struct field
*field
)
14453 struct attribute
*attr
;
14455 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14458 if (attr
->form_is_constant ())
14460 LONGEST offset
= attr
->constant_value (0);
14461 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14463 else if (attr
->form_is_section_offset ())
14464 dwarf2_complex_location_expr_complaint ();
14465 else if (attr
->form_is_block ())
14468 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14470 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14473 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14474 struct objfile
*objfile
= per_objfile
->objfile
;
14475 struct dwarf2_locexpr_baton
*dlbaton
14476 = XOBNEW (&objfile
->objfile_obstack
,
14477 struct dwarf2_locexpr_baton
);
14478 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14479 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14480 /* When using this baton, we want to compute the address
14481 of the field, not the value. This is why
14482 is_reference is set to false here. */
14483 dlbaton
->is_reference
= false;
14484 dlbaton
->per_objfile
= per_objfile
;
14485 dlbaton
->per_cu
= cu
->per_cu
;
14487 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14491 dwarf2_complex_location_expr_complaint ();
14495 /* Add an aggregate field to the field list. */
14498 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14499 struct dwarf2_cu
*cu
)
14501 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14502 struct gdbarch
*gdbarch
= objfile
->arch ();
14503 struct nextfield
*new_field
;
14504 struct attribute
*attr
;
14506 const char *fieldname
= "";
14508 if (die
->tag
== DW_TAG_inheritance
)
14510 fip
->baseclasses
.emplace_back ();
14511 new_field
= &fip
->baseclasses
.back ();
14515 fip
->fields
.emplace_back ();
14516 new_field
= &fip
->fields
.back ();
14519 new_field
->offset
= die
->sect_off
;
14521 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14522 if (attr
!= nullptr)
14523 new_field
->accessibility
= DW_UNSND (attr
);
14525 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14526 if (new_field
->accessibility
!= DW_ACCESS_public
)
14527 fip
->non_public_fields
= 1;
14529 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14530 if (attr
!= nullptr)
14531 new_field
->virtuality
= DW_UNSND (attr
);
14533 new_field
->virtuality
= DW_VIRTUALITY_none
;
14535 fp
= &new_field
->field
;
14537 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14539 /* Data member other than a C++ static data member. */
14541 /* Get type of field. */
14542 fp
->set_type (die_type (die
, cu
));
14544 SET_FIELD_BITPOS (*fp
, 0);
14546 /* Get bit size of field (zero if none). */
14547 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14548 if (attr
!= nullptr)
14550 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14554 FIELD_BITSIZE (*fp
) = 0;
14557 /* Get bit offset of field. */
14558 handle_data_member_location (die
, cu
, fp
);
14559 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14560 if (attr
!= nullptr)
14562 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14564 /* For big endian bits, the DW_AT_bit_offset gives the
14565 additional bit offset from the MSB of the containing
14566 anonymous object to the MSB of the field. We don't
14567 have to do anything special since we don't need to
14568 know the size of the anonymous object. */
14569 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14573 /* For little endian bits, compute the bit offset to the
14574 MSB of the anonymous object, subtract off the number of
14575 bits from the MSB of the field to the MSB of the
14576 object, and then subtract off the number of bits of
14577 the field itself. The result is the bit offset of
14578 the LSB of the field. */
14579 int anonymous_size
;
14580 int bit_offset
= DW_UNSND (attr
);
14582 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14583 if (attr
!= nullptr)
14585 /* The size of the anonymous object containing
14586 the bit field is explicit, so use the
14587 indicated size (in bytes). */
14588 anonymous_size
= DW_UNSND (attr
);
14592 /* The size of the anonymous object containing
14593 the bit field must be inferred from the type
14594 attribute of the data member containing the
14596 anonymous_size
= TYPE_LENGTH (fp
->type ());
14598 SET_FIELD_BITPOS (*fp
,
14599 (FIELD_BITPOS (*fp
)
14600 + anonymous_size
* bits_per_byte
14601 - bit_offset
- FIELD_BITSIZE (*fp
)));
14604 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14606 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14607 + attr
->constant_value (0)));
14609 /* Get name of field. */
14610 fieldname
= dwarf2_name (die
, cu
);
14611 if (fieldname
== NULL
)
14614 /* The name is already allocated along with this objfile, so we don't
14615 need to duplicate it for the type. */
14616 fp
->name
= fieldname
;
14618 /* Change accessibility for artificial fields (e.g. virtual table
14619 pointer or virtual base class pointer) to private. */
14620 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14622 FIELD_ARTIFICIAL (*fp
) = 1;
14623 new_field
->accessibility
= DW_ACCESS_private
;
14624 fip
->non_public_fields
= 1;
14627 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14629 /* C++ static member. */
14631 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14632 is a declaration, but all versions of G++ as of this writing
14633 (so through at least 3.2.1) incorrectly generate
14634 DW_TAG_variable tags. */
14636 const char *physname
;
14638 /* Get name of field. */
14639 fieldname
= dwarf2_name (die
, cu
);
14640 if (fieldname
== NULL
)
14643 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14645 /* Only create a symbol if this is an external value.
14646 new_symbol checks this and puts the value in the global symbol
14647 table, which we want. If it is not external, new_symbol
14648 will try to put the value in cu->list_in_scope which is wrong. */
14649 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14651 /* A static const member, not much different than an enum as far as
14652 we're concerned, except that we can support more types. */
14653 new_symbol (die
, NULL
, cu
);
14656 /* Get physical name. */
14657 physname
= dwarf2_physname (fieldname
, die
, cu
);
14659 /* The name is already allocated along with this objfile, so we don't
14660 need to duplicate it for the type. */
14661 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14662 fp
->set_type (die_type (die
, cu
));
14663 FIELD_NAME (*fp
) = fieldname
;
14665 else if (die
->tag
== DW_TAG_inheritance
)
14667 /* C++ base class field. */
14668 handle_data_member_location (die
, cu
, fp
);
14669 FIELD_BITSIZE (*fp
) = 0;
14670 fp
->set_type (die_type (die
, cu
));
14671 FIELD_NAME (*fp
) = fp
->type ()->name ();
14674 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14677 /* Can the type given by DIE define another type? */
14680 type_can_define_types (const struct die_info
*die
)
14684 case DW_TAG_typedef
:
14685 case DW_TAG_class_type
:
14686 case DW_TAG_structure_type
:
14687 case DW_TAG_union_type
:
14688 case DW_TAG_enumeration_type
:
14696 /* Add a type definition defined in the scope of the FIP's class. */
14699 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14700 struct dwarf2_cu
*cu
)
14702 struct decl_field fp
;
14703 memset (&fp
, 0, sizeof (fp
));
14705 gdb_assert (type_can_define_types (die
));
14707 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14708 fp
.name
= dwarf2_name (die
, cu
);
14709 fp
.type
= read_type_die (die
, cu
);
14711 /* Save accessibility. */
14712 enum dwarf_access_attribute accessibility
;
14713 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14715 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14717 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14718 switch (accessibility
)
14720 case DW_ACCESS_public
:
14721 /* The assumed value if neither private nor protected. */
14723 case DW_ACCESS_private
:
14726 case DW_ACCESS_protected
:
14727 fp
.is_protected
= 1;
14730 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14733 if (die
->tag
== DW_TAG_typedef
)
14734 fip
->typedef_field_list
.push_back (fp
);
14736 fip
->nested_types_list
.push_back (fp
);
14739 /* A convenience typedef that's used when finding the discriminant
14740 field for a variant part. */
14741 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14744 /* Compute the discriminant range for a given variant. OBSTACK is
14745 where the results will be stored. VARIANT is the variant to
14746 process. IS_UNSIGNED indicates whether the discriminant is signed
14749 static const gdb::array_view
<discriminant_range
>
14750 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14753 std::vector
<discriminant_range
> ranges
;
14755 if (variant
.default_branch
)
14758 if (variant
.discr_list_data
== nullptr)
14760 discriminant_range r
14761 = {variant
.discriminant_value
, variant
.discriminant_value
};
14762 ranges
.push_back (r
);
14766 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14767 variant
.discr_list_data
->size
);
14768 while (!data
.empty ())
14770 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14772 complaint (_("invalid discriminant marker: %d"), data
[0]);
14775 bool is_range
= data
[0] == DW_DSC_range
;
14776 data
= data
.slice (1);
14778 ULONGEST low
, high
;
14779 unsigned int bytes_read
;
14783 complaint (_("DW_AT_discr_list missing low value"));
14787 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14789 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14791 data
= data
.slice (bytes_read
);
14797 complaint (_("DW_AT_discr_list missing high value"));
14801 high
= read_unsigned_leb128 (nullptr, data
.data (),
14804 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14806 data
= data
.slice (bytes_read
);
14811 ranges
.push_back ({ low
, high
});
14815 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14817 std::copy (ranges
.begin (), ranges
.end (), result
);
14818 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14821 static const gdb::array_view
<variant_part
> create_variant_parts
14822 (struct obstack
*obstack
,
14823 const offset_map_type
&offset_map
,
14824 struct field_info
*fi
,
14825 const std::vector
<variant_part_builder
> &variant_parts
);
14827 /* Fill in a "struct variant" for a given variant field. RESULT is
14828 the variant to fill in. OBSTACK is where any needed allocations
14829 will be done. OFFSET_MAP holds the mapping from section offsets to
14830 fields for the type. FI describes the fields of the type we're
14831 processing. FIELD is the variant field we're converting. */
14834 create_one_variant (variant
&result
, struct obstack
*obstack
,
14835 const offset_map_type
&offset_map
,
14836 struct field_info
*fi
, const variant_field
&field
)
14838 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14839 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14840 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14841 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14842 field
.variant_parts
);
14845 /* Fill in a "struct variant_part" for a given variant part. RESULT
14846 is the variant part to fill in. OBSTACK is where any needed
14847 allocations will be done. OFFSET_MAP holds the mapping from
14848 section offsets to fields for the type. FI describes the fields of
14849 the type we're processing. BUILDER is the variant part to be
14853 create_one_variant_part (variant_part
&result
,
14854 struct obstack
*obstack
,
14855 const offset_map_type
&offset_map
,
14856 struct field_info
*fi
,
14857 const variant_part_builder
&builder
)
14859 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14860 if (iter
== offset_map
.end ())
14862 result
.discriminant_index
= -1;
14863 /* Doesn't matter. */
14864 result
.is_unsigned
= false;
14868 result
.discriminant_index
= iter
->second
;
14870 = TYPE_UNSIGNED (fi
->fields
[result
.discriminant_index
].field
.type ());
14873 size_t n
= builder
.variants
.size ();
14874 variant
*output
= new (obstack
) variant
[n
];
14875 for (size_t i
= 0; i
< n
; ++i
)
14876 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14877 builder
.variants
[i
]);
14879 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14882 /* Create a vector of variant parts that can be attached to a type.
14883 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14884 holds the mapping from section offsets to fields for the type. FI
14885 describes the fields of the type we're processing. VARIANT_PARTS
14886 is the vector to convert. */
14888 static const gdb::array_view
<variant_part
>
14889 create_variant_parts (struct obstack
*obstack
,
14890 const offset_map_type
&offset_map
,
14891 struct field_info
*fi
,
14892 const std::vector
<variant_part_builder
> &variant_parts
)
14894 if (variant_parts
.empty ())
14897 size_t n
= variant_parts
.size ();
14898 variant_part
*result
= new (obstack
) variant_part
[n
];
14899 for (size_t i
= 0; i
< n
; ++i
)
14900 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14903 return gdb::array_view
<variant_part
> (result
, n
);
14906 /* Compute the variant part vector for FIP, attaching it to TYPE when
14910 add_variant_property (struct field_info
*fip
, struct type
*type
,
14911 struct dwarf2_cu
*cu
)
14913 /* Map section offsets of fields to their field index. Note the
14914 field index here does not take the number of baseclasses into
14916 offset_map_type offset_map
;
14917 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14918 offset_map
[fip
->fields
[i
].offset
] = i
;
14920 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14921 gdb::array_view
<variant_part
> parts
14922 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14923 fip
->variant_parts
);
14925 struct dynamic_prop prop
;
14926 prop
.kind
= PROP_VARIANT_PARTS
;
14927 prop
.data
.variant_parts
14928 = ((gdb::array_view
<variant_part
> *)
14929 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14931 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14934 /* Create the vector of fields, and attach it to the type. */
14937 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14938 struct dwarf2_cu
*cu
)
14940 int nfields
= fip
->nfields ();
14942 /* Record the field count, allocate space for the array of fields,
14943 and create blank accessibility bitfields if necessary. */
14944 type
->set_num_fields (nfields
);
14946 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14948 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14950 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14952 TYPE_FIELD_PRIVATE_BITS (type
) =
14953 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14954 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14956 TYPE_FIELD_PROTECTED_BITS (type
) =
14957 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14958 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14960 TYPE_FIELD_IGNORE_BITS (type
) =
14961 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14962 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14965 /* If the type has baseclasses, allocate and clear a bit vector for
14966 TYPE_FIELD_VIRTUAL_BITS. */
14967 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14969 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14970 unsigned char *pointer
;
14972 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14973 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14974 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14975 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14976 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14979 if (!fip
->variant_parts
.empty ())
14980 add_variant_property (fip
, type
, cu
);
14982 /* Copy the saved-up fields into the field vector. */
14983 for (int i
= 0; i
< nfields
; ++i
)
14985 struct nextfield
&field
14986 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14987 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14989 type
->field (i
) = field
.field
;
14990 switch (field
.accessibility
)
14992 case DW_ACCESS_private
:
14993 if (cu
->language
!= language_ada
)
14994 SET_TYPE_FIELD_PRIVATE (type
, i
);
14997 case DW_ACCESS_protected
:
14998 if (cu
->language
!= language_ada
)
14999 SET_TYPE_FIELD_PROTECTED (type
, i
);
15002 case DW_ACCESS_public
:
15006 /* Unknown accessibility. Complain and treat it as public. */
15008 complaint (_("unsupported accessibility %d"),
15009 field
.accessibility
);
15013 if (i
< fip
->baseclasses
.size ())
15015 switch (field
.virtuality
)
15017 case DW_VIRTUALITY_virtual
:
15018 case DW_VIRTUALITY_pure_virtual
:
15019 if (cu
->language
== language_ada
)
15020 error (_("unexpected virtuality in component of Ada type"));
15021 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15028 /* Return true if this member function is a constructor, false
15032 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15034 const char *fieldname
;
15035 const char *type_name
;
15038 if (die
->parent
== NULL
)
15041 if (die
->parent
->tag
!= DW_TAG_structure_type
15042 && die
->parent
->tag
!= DW_TAG_union_type
15043 && die
->parent
->tag
!= DW_TAG_class_type
)
15046 fieldname
= dwarf2_name (die
, cu
);
15047 type_name
= dwarf2_name (die
->parent
, cu
);
15048 if (fieldname
== NULL
|| type_name
== NULL
)
15051 len
= strlen (fieldname
);
15052 return (strncmp (fieldname
, type_name
, len
) == 0
15053 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15056 /* Check if the given VALUE is a recognized enum
15057 dwarf_defaulted_attribute constant according to DWARF5 spec,
15061 is_valid_DW_AT_defaulted (ULONGEST value
)
15065 case DW_DEFAULTED_no
:
15066 case DW_DEFAULTED_in_class
:
15067 case DW_DEFAULTED_out_of_class
:
15071 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15075 /* Add a member function to the proper fieldlist. */
15078 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15079 struct type
*type
, struct dwarf2_cu
*cu
)
15081 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15082 struct attribute
*attr
;
15084 struct fnfieldlist
*flp
= nullptr;
15085 struct fn_field
*fnp
;
15086 const char *fieldname
;
15087 struct type
*this_type
;
15088 enum dwarf_access_attribute accessibility
;
15090 if (cu
->language
== language_ada
)
15091 error (_("unexpected member function in Ada type"));
15093 /* Get name of member function. */
15094 fieldname
= dwarf2_name (die
, cu
);
15095 if (fieldname
== NULL
)
15098 /* Look up member function name in fieldlist. */
15099 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15101 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15103 flp
= &fip
->fnfieldlists
[i
];
15108 /* Create a new fnfieldlist if necessary. */
15109 if (flp
== nullptr)
15111 fip
->fnfieldlists
.emplace_back ();
15112 flp
= &fip
->fnfieldlists
.back ();
15113 flp
->name
= fieldname
;
15114 i
= fip
->fnfieldlists
.size () - 1;
15117 /* Create a new member function field and add it to the vector of
15119 flp
->fnfields
.emplace_back ();
15120 fnp
= &flp
->fnfields
.back ();
15122 /* Delay processing of the physname until later. */
15123 if (cu
->language
== language_cplus
)
15124 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15128 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15129 fnp
->physname
= physname
? physname
: "";
15132 fnp
->type
= alloc_type (objfile
);
15133 this_type
= read_type_die (die
, cu
);
15134 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15136 int nparams
= this_type
->num_fields ();
15138 /* TYPE is the domain of this method, and THIS_TYPE is the type
15139 of the method itself (TYPE_CODE_METHOD). */
15140 smash_to_method_type (fnp
->type
, type
,
15141 TYPE_TARGET_TYPE (this_type
),
15142 this_type
->fields (),
15143 this_type
->num_fields (),
15144 TYPE_VARARGS (this_type
));
15146 /* Handle static member functions.
15147 Dwarf2 has no clean way to discern C++ static and non-static
15148 member functions. G++ helps GDB by marking the first
15149 parameter for non-static member functions (which is the this
15150 pointer) as artificial. We obtain this information from
15151 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15152 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15153 fnp
->voffset
= VOFFSET_STATIC
;
15156 complaint (_("member function type missing for '%s'"),
15157 dwarf2_full_name (fieldname
, die
, cu
));
15159 /* Get fcontext from DW_AT_containing_type if present. */
15160 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15161 fnp
->fcontext
= die_containing_type (die
, cu
);
15163 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15164 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15166 /* Get accessibility. */
15167 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15168 if (attr
!= nullptr)
15169 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15171 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15172 switch (accessibility
)
15174 case DW_ACCESS_private
:
15175 fnp
->is_private
= 1;
15177 case DW_ACCESS_protected
:
15178 fnp
->is_protected
= 1;
15182 /* Check for artificial methods. */
15183 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15184 if (attr
&& DW_UNSND (attr
) != 0)
15185 fnp
->is_artificial
= 1;
15187 /* Check for defaulted methods. */
15188 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15189 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15190 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15192 /* Check for deleted methods. */
15193 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15194 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15195 fnp
->is_deleted
= 1;
15197 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15199 /* Get index in virtual function table if it is a virtual member
15200 function. For older versions of GCC, this is an offset in the
15201 appropriate virtual table, as specified by DW_AT_containing_type.
15202 For everyone else, it is an expression to be evaluated relative
15203 to the object address. */
15205 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15206 if (attr
!= nullptr)
15208 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15210 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15212 /* Old-style GCC. */
15213 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15215 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15216 || (DW_BLOCK (attr
)->size
> 1
15217 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15218 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15220 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15221 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15222 dwarf2_complex_location_expr_complaint ();
15224 fnp
->voffset
/= cu
->header
.addr_size
;
15228 dwarf2_complex_location_expr_complaint ();
15230 if (!fnp
->fcontext
)
15232 /* If there is no `this' field and no DW_AT_containing_type,
15233 we cannot actually find a base class context for the
15235 if (this_type
->num_fields () == 0
15236 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15238 complaint (_("cannot determine context for virtual member "
15239 "function \"%s\" (offset %s)"),
15240 fieldname
, sect_offset_str (die
->sect_off
));
15245 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15249 else if (attr
->form_is_section_offset ())
15251 dwarf2_complex_location_expr_complaint ();
15255 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15261 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15262 if (attr
&& DW_UNSND (attr
))
15264 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15265 complaint (_("Member function \"%s\" (offset %s) is virtual "
15266 "but the vtable offset is not specified"),
15267 fieldname
, sect_offset_str (die
->sect_off
));
15268 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15269 TYPE_CPLUS_DYNAMIC (type
) = 1;
15274 /* Create the vector of member function fields, and attach it to the type. */
15277 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15278 struct dwarf2_cu
*cu
)
15280 if (cu
->language
== language_ada
)
15281 error (_("unexpected member functions in Ada type"));
15283 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15284 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15286 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15288 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15290 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15291 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15293 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15294 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15295 fn_flp
->fn_fields
= (struct fn_field
*)
15296 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15298 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15299 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15302 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15305 /* Returns non-zero if NAME is the name of a vtable member in CU's
15306 language, zero otherwise. */
15308 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15310 static const char vptr
[] = "_vptr";
15312 /* Look for the C++ form of the vtable. */
15313 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15319 /* GCC outputs unnamed structures that are really pointers to member
15320 functions, with the ABI-specified layout. If TYPE describes
15321 such a structure, smash it into a member function type.
15323 GCC shouldn't do this; it should just output pointer to member DIEs.
15324 This is GCC PR debug/28767. */
15327 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15329 struct type
*pfn_type
, *self_type
, *new_type
;
15331 /* Check for a structure with no name and two children. */
15332 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15335 /* Check for __pfn and __delta members. */
15336 if (TYPE_FIELD_NAME (type
, 0) == NULL
15337 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15338 || TYPE_FIELD_NAME (type
, 1) == NULL
15339 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15342 /* Find the type of the method. */
15343 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15344 if (pfn_type
== NULL
15345 || pfn_type
->code () != TYPE_CODE_PTR
15346 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15349 /* Look for the "this" argument. */
15350 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15351 if (pfn_type
->num_fields () == 0
15352 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15353 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15356 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15357 new_type
= alloc_type (objfile
);
15358 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15359 pfn_type
->fields (), pfn_type
->num_fields (),
15360 TYPE_VARARGS (pfn_type
));
15361 smash_to_methodptr_type (type
, new_type
);
15364 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15365 appropriate error checking and issuing complaints if there is a
15369 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15371 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15373 if (attr
== nullptr)
15376 if (!attr
->form_is_constant ())
15378 complaint (_("DW_AT_alignment must have constant form"
15379 " - DIE at %s [in module %s]"),
15380 sect_offset_str (die
->sect_off
),
15381 objfile_name (cu
->per_objfile
->objfile
));
15386 if (attr
->form
== DW_FORM_sdata
)
15388 LONGEST val
= DW_SND (attr
);
15391 complaint (_("DW_AT_alignment value must not be negative"
15392 " - DIE at %s [in module %s]"),
15393 sect_offset_str (die
->sect_off
),
15394 objfile_name (cu
->per_objfile
->objfile
));
15400 align
= DW_UNSND (attr
);
15404 complaint (_("DW_AT_alignment value must not be zero"
15405 " - DIE at %s [in module %s]"),
15406 sect_offset_str (die
->sect_off
),
15407 objfile_name (cu
->per_objfile
->objfile
));
15410 if ((align
& (align
- 1)) != 0)
15412 complaint (_("DW_AT_alignment value must be a power of 2"
15413 " - DIE at %s [in module %s]"),
15414 sect_offset_str (die
->sect_off
),
15415 objfile_name (cu
->per_objfile
->objfile
));
15422 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15423 the alignment for TYPE. */
15426 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15429 if (!set_type_align (type
, get_alignment (cu
, die
)))
15430 complaint (_("DW_AT_alignment value too large"
15431 " - DIE at %s [in module %s]"),
15432 sect_offset_str (die
->sect_off
),
15433 objfile_name (cu
->per_objfile
->objfile
));
15436 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15437 constant for a type, according to DWARF5 spec, Table 5.5. */
15440 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15445 case DW_CC_pass_by_reference
:
15446 case DW_CC_pass_by_value
:
15450 complaint (_("unrecognized DW_AT_calling_convention value "
15451 "(%s) for a type"), pulongest (value
));
15456 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15457 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15458 also according to GNU-specific values (see include/dwarf2.h). */
15461 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15466 case DW_CC_program
:
15470 case DW_CC_GNU_renesas_sh
:
15471 case DW_CC_GNU_borland_fastcall_i386
:
15472 case DW_CC_GDB_IBM_OpenCL
:
15476 complaint (_("unrecognized DW_AT_calling_convention value "
15477 "(%s) for a subroutine"), pulongest (value
));
15482 /* Called when we find the DIE that starts a structure or union scope
15483 (definition) to create a type for the structure or union. Fill in
15484 the type's name and general properties; the members will not be
15485 processed until process_structure_scope. A symbol table entry for
15486 the type will also not be done until process_structure_scope (assuming
15487 the type has a name).
15489 NOTE: we need to call these functions regardless of whether or not the
15490 DIE has a DW_AT_name attribute, since it might be an anonymous
15491 structure or union. This gets the type entered into our set of
15492 user defined types. */
15494 static struct type
*
15495 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15497 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15499 struct attribute
*attr
;
15502 /* If the definition of this type lives in .debug_types, read that type.
15503 Don't follow DW_AT_specification though, that will take us back up
15504 the chain and we want to go down. */
15505 attr
= die
->attr (DW_AT_signature
);
15506 if (attr
!= nullptr)
15508 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15510 /* The type's CU may not be the same as CU.
15511 Ensure TYPE is recorded with CU in die_type_hash. */
15512 return set_die_type (die
, type
, cu
);
15515 type
= alloc_type (objfile
);
15516 INIT_CPLUS_SPECIFIC (type
);
15518 name
= dwarf2_name (die
, cu
);
15521 if (cu
->language
== language_cplus
15522 || cu
->language
== language_d
15523 || cu
->language
== language_rust
)
15525 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15527 /* dwarf2_full_name might have already finished building the DIE's
15528 type. If so, there is no need to continue. */
15529 if (get_die_type (die
, cu
) != NULL
)
15530 return get_die_type (die
, cu
);
15532 type
->set_name (full_name
);
15536 /* The name is already allocated along with this objfile, so
15537 we don't need to duplicate it for the type. */
15538 type
->set_name (name
);
15542 if (die
->tag
== DW_TAG_structure_type
)
15544 type
->set_code (TYPE_CODE_STRUCT
);
15546 else if (die
->tag
== DW_TAG_union_type
)
15548 type
->set_code (TYPE_CODE_UNION
);
15552 type
->set_code (TYPE_CODE_STRUCT
);
15555 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15556 TYPE_DECLARED_CLASS (type
) = 1;
15558 /* Store the calling convention in the type if it's available in
15559 the die. Otherwise the calling convention remains set to
15560 the default value DW_CC_normal. */
15561 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15562 if (attr
!= nullptr
15563 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15565 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15566 TYPE_CPLUS_CALLING_CONVENTION (type
)
15567 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15570 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15571 if (attr
!= nullptr)
15573 if (attr
->form_is_constant ())
15574 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15577 struct dynamic_prop prop
;
15578 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15579 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15580 TYPE_LENGTH (type
) = 0;
15585 TYPE_LENGTH (type
) = 0;
15588 maybe_set_alignment (cu
, die
, type
);
15590 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15592 /* ICC<14 does not output the required DW_AT_declaration on
15593 incomplete types, but gives them a size of zero. */
15594 TYPE_STUB (type
) = 1;
15597 TYPE_STUB_SUPPORTED (type
) = 1;
15599 if (die_is_declaration (die
, cu
))
15600 TYPE_STUB (type
) = 1;
15601 else if (attr
== NULL
&& die
->child
== NULL
15602 && producer_is_realview (cu
->producer
))
15603 /* RealView does not output the required DW_AT_declaration
15604 on incomplete types. */
15605 TYPE_STUB (type
) = 1;
15607 /* We need to add the type field to the die immediately so we don't
15608 infinitely recurse when dealing with pointers to the structure
15609 type within the structure itself. */
15610 set_die_type (die
, type
, cu
);
15612 /* set_die_type should be already done. */
15613 set_descriptive_type (type
, die
, cu
);
15618 static void handle_struct_member_die
15619 (struct die_info
*child_die
,
15621 struct field_info
*fi
,
15622 std::vector
<struct symbol
*> *template_args
,
15623 struct dwarf2_cu
*cu
);
15625 /* A helper for handle_struct_member_die that handles
15626 DW_TAG_variant_part. */
15629 handle_variant_part (struct die_info
*die
, struct type
*type
,
15630 struct field_info
*fi
,
15631 std::vector
<struct symbol
*> *template_args
,
15632 struct dwarf2_cu
*cu
)
15634 variant_part_builder
*new_part
;
15635 if (fi
->current_variant_part
== nullptr)
15637 fi
->variant_parts
.emplace_back ();
15638 new_part
= &fi
->variant_parts
.back ();
15640 else if (!fi
->current_variant_part
->processing_variant
)
15642 complaint (_("nested DW_TAG_variant_part seen "
15643 "- DIE at %s [in module %s]"),
15644 sect_offset_str (die
->sect_off
),
15645 objfile_name (cu
->per_objfile
->objfile
));
15650 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15651 current
.variant_parts
.emplace_back ();
15652 new_part
= ¤t
.variant_parts
.back ();
15655 /* When we recurse, we want callees to add to this new variant
15657 scoped_restore save_current_variant_part
15658 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15660 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15663 /* It's a univariant form, an extension we support. */
15665 else if (discr
->form_is_ref ())
15667 struct dwarf2_cu
*target_cu
= cu
;
15668 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15670 new_part
->discriminant_offset
= target_die
->sect_off
;
15674 complaint (_("DW_AT_discr does not have DIE reference form"
15675 " - DIE at %s [in module %s]"),
15676 sect_offset_str (die
->sect_off
),
15677 objfile_name (cu
->per_objfile
->objfile
));
15680 for (die_info
*child_die
= die
->child
;
15682 child_die
= child_die
->sibling
)
15683 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15686 /* A helper for handle_struct_member_die that handles
15690 handle_variant (struct die_info
*die
, struct type
*type
,
15691 struct field_info
*fi
,
15692 std::vector
<struct symbol
*> *template_args
,
15693 struct dwarf2_cu
*cu
)
15695 if (fi
->current_variant_part
== nullptr)
15697 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15698 "- DIE at %s [in module %s]"),
15699 sect_offset_str (die
->sect_off
),
15700 objfile_name (cu
->per_objfile
->objfile
));
15703 if (fi
->current_variant_part
->processing_variant
)
15705 complaint (_("nested DW_TAG_variant seen "
15706 "- DIE at %s [in module %s]"),
15707 sect_offset_str (die
->sect_off
),
15708 objfile_name (cu
->per_objfile
->objfile
));
15712 scoped_restore save_processing_variant
15713 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15716 fi
->current_variant_part
->variants
.emplace_back ();
15717 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15718 variant
.first_field
= fi
->fields
.size ();
15720 /* In a variant we want to get the discriminant and also add a
15721 field for our sole member child. */
15722 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15723 if (discr
== nullptr)
15725 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15726 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15727 variant
.default_branch
= true;
15729 variant
.discr_list_data
= DW_BLOCK (discr
);
15732 variant
.discriminant_value
= DW_UNSND (discr
);
15734 for (die_info
*variant_child
= die
->child
;
15735 variant_child
!= NULL
;
15736 variant_child
= variant_child
->sibling
)
15737 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15739 variant
.last_field
= fi
->fields
.size ();
15742 /* A helper for process_structure_scope that handles a single member
15746 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15747 struct field_info
*fi
,
15748 std::vector
<struct symbol
*> *template_args
,
15749 struct dwarf2_cu
*cu
)
15751 if (child_die
->tag
== DW_TAG_member
15752 || child_die
->tag
== DW_TAG_variable
)
15754 /* NOTE: carlton/2002-11-05: A C++ static data member
15755 should be a DW_TAG_member that is a declaration, but
15756 all versions of G++ as of this writing (so through at
15757 least 3.2.1) incorrectly generate DW_TAG_variable
15758 tags for them instead. */
15759 dwarf2_add_field (fi
, child_die
, cu
);
15761 else if (child_die
->tag
== DW_TAG_subprogram
)
15763 /* Rust doesn't have member functions in the C++ sense.
15764 However, it does emit ordinary functions as children
15765 of a struct DIE. */
15766 if (cu
->language
== language_rust
)
15767 read_func_scope (child_die
, cu
);
15770 /* C++ member function. */
15771 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15774 else if (child_die
->tag
== DW_TAG_inheritance
)
15776 /* C++ base class field. */
15777 dwarf2_add_field (fi
, child_die
, cu
);
15779 else if (type_can_define_types (child_die
))
15780 dwarf2_add_type_defn (fi
, child_die
, cu
);
15781 else if (child_die
->tag
== DW_TAG_template_type_param
15782 || child_die
->tag
== DW_TAG_template_value_param
)
15784 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15787 template_args
->push_back (arg
);
15789 else if (child_die
->tag
== DW_TAG_variant_part
)
15790 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15791 else if (child_die
->tag
== DW_TAG_variant
)
15792 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15795 /* Finish creating a structure or union type, including filling in
15796 its members and creating a symbol for it. */
15799 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15801 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15802 struct die_info
*child_die
;
15805 type
= get_die_type (die
, cu
);
15807 type
= read_structure_type (die
, cu
);
15809 bool has_template_parameters
= false;
15810 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15812 struct field_info fi
;
15813 std::vector
<struct symbol
*> template_args
;
15815 child_die
= die
->child
;
15817 while (child_die
&& child_die
->tag
)
15819 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15820 child_die
= child_die
->sibling
;
15823 /* Attach template arguments to type. */
15824 if (!template_args
.empty ())
15826 has_template_parameters
= true;
15827 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15828 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15829 TYPE_TEMPLATE_ARGUMENTS (type
)
15830 = XOBNEWVEC (&objfile
->objfile_obstack
,
15832 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15833 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15834 template_args
.data (),
15835 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15836 * sizeof (struct symbol
*)));
15839 /* Attach fields and member functions to the type. */
15840 if (fi
.nfields () > 0)
15841 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15842 if (!fi
.fnfieldlists
.empty ())
15844 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15846 /* Get the type which refers to the base class (possibly this
15847 class itself) which contains the vtable pointer for the current
15848 class from the DW_AT_containing_type attribute. This use of
15849 DW_AT_containing_type is a GNU extension. */
15851 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15853 struct type
*t
= die_containing_type (die
, cu
);
15855 set_type_vptr_basetype (type
, t
);
15860 /* Our own class provides vtbl ptr. */
15861 for (i
= t
->num_fields () - 1;
15862 i
>= TYPE_N_BASECLASSES (t
);
15865 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15867 if (is_vtable_name (fieldname
, cu
))
15869 set_type_vptr_fieldno (type
, i
);
15874 /* Complain if virtual function table field not found. */
15875 if (i
< TYPE_N_BASECLASSES (t
))
15876 complaint (_("virtual function table pointer "
15877 "not found when defining class '%s'"),
15878 type
->name () ? type
->name () : "");
15882 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15885 else if (cu
->producer
15886 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15888 /* The IBM XLC compiler does not provide direct indication
15889 of the containing type, but the vtable pointer is
15890 always named __vfp. */
15894 for (i
= type
->num_fields () - 1;
15895 i
>= TYPE_N_BASECLASSES (type
);
15898 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15900 set_type_vptr_fieldno (type
, i
);
15901 set_type_vptr_basetype (type
, type
);
15908 /* Copy fi.typedef_field_list linked list elements content into the
15909 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15910 if (!fi
.typedef_field_list
.empty ())
15912 int count
= fi
.typedef_field_list
.size ();
15914 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15915 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15916 = ((struct decl_field
*)
15918 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15919 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15921 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15922 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15925 /* Copy fi.nested_types_list linked list elements content into the
15926 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15927 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15929 int count
= fi
.nested_types_list
.size ();
15931 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15932 TYPE_NESTED_TYPES_ARRAY (type
)
15933 = ((struct decl_field
*)
15934 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15935 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15937 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15938 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15942 quirk_gcc_member_function_pointer (type
, objfile
);
15943 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15944 cu
->rust_unions
.push_back (type
);
15946 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15947 snapshots) has been known to create a die giving a declaration
15948 for a class that has, as a child, a die giving a definition for a
15949 nested class. So we have to process our children even if the
15950 current die is a declaration. Normally, of course, a declaration
15951 won't have any children at all. */
15953 child_die
= die
->child
;
15955 while (child_die
!= NULL
&& child_die
->tag
)
15957 if (child_die
->tag
== DW_TAG_member
15958 || child_die
->tag
== DW_TAG_variable
15959 || child_die
->tag
== DW_TAG_inheritance
15960 || child_die
->tag
== DW_TAG_template_value_param
15961 || child_die
->tag
== DW_TAG_template_type_param
)
15966 process_die (child_die
, cu
);
15968 child_die
= child_die
->sibling
;
15971 /* Do not consider external references. According to the DWARF standard,
15972 these DIEs are identified by the fact that they have no byte_size
15973 attribute, and a declaration attribute. */
15974 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15975 || !die_is_declaration (die
, cu
)
15976 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15978 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15980 if (has_template_parameters
)
15982 struct symtab
*symtab
;
15983 if (sym
!= nullptr)
15984 symtab
= symbol_symtab (sym
);
15985 else if (cu
->line_header
!= nullptr)
15987 /* Any related symtab will do. */
15989 = cu
->line_header
->file_names ()[0].symtab
;
15994 complaint (_("could not find suitable "
15995 "symtab for template parameter"
15996 " - DIE at %s [in module %s]"),
15997 sect_offset_str (die
->sect_off
),
15998 objfile_name (objfile
));
16001 if (symtab
!= nullptr)
16003 /* Make sure that the symtab is set on the new symbols.
16004 Even though they don't appear in this symtab directly,
16005 other parts of gdb assume that symbols do, and this is
16006 reasonably true. */
16007 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16008 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16014 /* Assuming DIE is an enumeration type, and TYPE is its associated
16015 type, update TYPE using some information only available in DIE's
16016 children. In particular, the fields are computed. */
16019 update_enumeration_type_from_children (struct die_info
*die
,
16021 struct dwarf2_cu
*cu
)
16023 struct die_info
*child_die
;
16024 int unsigned_enum
= 1;
16027 auto_obstack obstack
;
16028 std::vector
<struct field
> fields
;
16030 for (child_die
= die
->child
;
16031 child_die
!= NULL
&& child_die
->tag
;
16032 child_die
= child_die
->sibling
)
16034 struct attribute
*attr
;
16036 const gdb_byte
*bytes
;
16037 struct dwarf2_locexpr_baton
*baton
;
16040 if (child_die
->tag
!= DW_TAG_enumerator
)
16043 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16047 name
= dwarf2_name (child_die
, cu
);
16049 name
= "<anonymous enumerator>";
16051 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16052 &value
, &bytes
, &baton
);
16060 if (count_one_bits_ll (value
) >= 2)
16064 fields
.emplace_back ();
16065 struct field
&field
= fields
.back ();
16066 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16067 SET_FIELD_ENUMVAL (field
, value
);
16070 if (!fields
.empty ())
16072 type
->set_num_fields (fields
.size ());
16075 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16076 memcpy (type
->fields (), fields
.data (),
16077 sizeof (struct field
) * fields
.size ());
16081 TYPE_UNSIGNED (type
) = 1;
16083 TYPE_FLAG_ENUM (type
) = 1;
16086 /* Given a DW_AT_enumeration_type die, set its type. We do not
16087 complete the type's fields yet, or create any symbols. */
16089 static struct type
*
16090 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16092 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16094 struct attribute
*attr
;
16097 /* If the definition of this type lives in .debug_types, read that type.
16098 Don't follow DW_AT_specification though, that will take us back up
16099 the chain and we want to go down. */
16100 attr
= die
->attr (DW_AT_signature
);
16101 if (attr
!= nullptr)
16103 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16105 /* The type's CU may not be the same as CU.
16106 Ensure TYPE is recorded with CU in die_type_hash. */
16107 return set_die_type (die
, type
, cu
);
16110 type
= alloc_type (objfile
);
16112 type
->set_code (TYPE_CODE_ENUM
);
16113 name
= dwarf2_full_name (NULL
, die
, cu
);
16115 type
->set_name (name
);
16117 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16120 struct type
*underlying_type
= die_type (die
, cu
);
16122 TYPE_TARGET_TYPE (type
) = underlying_type
;
16125 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16126 if (attr
!= nullptr)
16128 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16132 TYPE_LENGTH (type
) = 0;
16135 maybe_set_alignment (cu
, die
, type
);
16137 /* The enumeration DIE can be incomplete. In Ada, any type can be
16138 declared as private in the package spec, and then defined only
16139 inside the package body. Such types are known as Taft Amendment
16140 Types. When another package uses such a type, an incomplete DIE
16141 may be generated by the compiler. */
16142 if (die_is_declaration (die
, cu
))
16143 TYPE_STUB (type
) = 1;
16145 /* If this type has an underlying type that is not a stub, then we
16146 may use its attributes. We always use the "unsigned" attribute
16147 in this situation, because ordinarily we guess whether the type
16148 is unsigned -- but the guess can be wrong and the underlying type
16149 can tell us the reality. However, we defer to a local size
16150 attribute if one exists, because this lets the compiler override
16151 the underlying type if needed. */
16152 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16154 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16155 underlying_type
= check_typedef (underlying_type
);
16156 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16157 if (TYPE_LENGTH (type
) == 0)
16158 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16159 if (TYPE_RAW_ALIGN (type
) == 0
16160 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16161 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16164 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16166 set_die_type (die
, type
, cu
);
16168 /* Finish the creation of this type by using the enum's children.
16169 Note that, as usual, this must come after set_die_type to avoid
16170 infinite recursion when trying to compute the names of the
16172 update_enumeration_type_from_children (die
, type
, cu
);
16177 /* Given a pointer to a die which begins an enumeration, process all
16178 the dies that define the members of the enumeration, and create the
16179 symbol for the enumeration type.
16181 NOTE: We reverse the order of the element list. */
16184 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16186 struct type
*this_type
;
16188 this_type
= get_die_type (die
, cu
);
16189 if (this_type
== NULL
)
16190 this_type
= read_enumeration_type (die
, cu
);
16192 if (die
->child
!= NULL
)
16194 struct die_info
*child_die
;
16197 child_die
= die
->child
;
16198 while (child_die
&& child_die
->tag
)
16200 if (child_die
->tag
!= DW_TAG_enumerator
)
16202 process_die (child_die
, cu
);
16206 name
= dwarf2_name (child_die
, cu
);
16208 new_symbol (child_die
, this_type
, cu
);
16211 child_die
= child_die
->sibling
;
16215 /* If we are reading an enum from a .debug_types unit, and the enum
16216 is a declaration, and the enum is not the signatured type in the
16217 unit, then we do not want to add a symbol for it. Adding a
16218 symbol would in some cases obscure the true definition of the
16219 enum, giving users an incomplete type when the definition is
16220 actually available. Note that we do not want to do this for all
16221 enums which are just declarations, because C++0x allows forward
16222 enum declarations. */
16223 if (cu
->per_cu
->is_debug_types
16224 && die_is_declaration (die
, cu
))
16226 struct signatured_type
*sig_type
;
16228 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16229 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16230 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16234 new_symbol (die
, this_type
, cu
);
16237 /* Extract all information from a DW_TAG_array_type DIE and put it in
16238 the DIE's type field. For now, this only handles one dimensional
16241 static struct type
*
16242 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16244 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16245 struct die_info
*child_die
;
16247 struct type
*element_type
, *range_type
, *index_type
;
16248 struct attribute
*attr
;
16250 struct dynamic_prop
*byte_stride_prop
= NULL
;
16251 unsigned int bit_stride
= 0;
16253 element_type
= die_type (die
, cu
);
16255 /* The die_type call above may have already set the type for this DIE. */
16256 type
= get_die_type (die
, cu
);
16260 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16264 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16267 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16268 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16272 complaint (_("unable to read array DW_AT_byte_stride "
16273 " - DIE at %s [in module %s]"),
16274 sect_offset_str (die
->sect_off
),
16275 objfile_name (cu
->per_objfile
->objfile
));
16276 /* Ignore this attribute. We will likely not be able to print
16277 arrays of this type correctly, but there is little we can do
16278 to help if we cannot read the attribute's value. */
16279 byte_stride_prop
= NULL
;
16283 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16285 bit_stride
= DW_UNSND (attr
);
16287 /* Irix 6.2 native cc creates array types without children for
16288 arrays with unspecified length. */
16289 if (die
->child
== NULL
)
16291 index_type
= objfile_type (objfile
)->builtin_int
;
16292 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16293 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16294 byte_stride_prop
, bit_stride
);
16295 return set_die_type (die
, type
, cu
);
16298 std::vector
<struct type
*> range_types
;
16299 child_die
= die
->child
;
16300 while (child_die
&& child_die
->tag
)
16302 if (child_die
->tag
== DW_TAG_subrange_type
)
16304 struct type
*child_type
= read_type_die (child_die
, cu
);
16306 if (child_type
!= NULL
)
16308 /* The range type was succesfully read. Save it for the
16309 array type creation. */
16310 range_types
.push_back (child_type
);
16313 child_die
= child_die
->sibling
;
16316 /* Dwarf2 dimensions are output from left to right, create the
16317 necessary array types in backwards order. */
16319 type
= element_type
;
16321 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16325 while (i
< range_types
.size ())
16326 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16327 byte_stride_prop
, bit_stride
);
16331 size_t ndim
= range_types
.size ();
16333 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16334 byte_stride_prop
, bit_stride
);
16337 /* Understand Dwarf2 support for vector types (like they occur on
16338 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16339 array type. This is not part of the Dwarf2/3 standard yet, but a
16340 custom vendor extension. The main difference between a regular
16341 array and the vector variant is that vectors are passed by value
16343 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16344 if (attr
!= nullptr)
16345 make_vector_type (type
);
16347 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16348 implementation may choose to implement triple vectors using this
16350 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16351 if (attr
!= nullptr)
16353 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16354 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16356 complaint (_("DW_AT_byte_size for array type smaller "
16357 "than the total size of elements"));
16360 name
= dwarf2_name (die
, cu
);
16362 type
->set_name (name
);
16364 maybe_set_alignment (cu
, die
, type
);
16366 /* Install the type in the die. */
16367 set_die_type (die
, type
, cu
);
16369 /* set_die_type should be already done. */
16370 set_descriptive_type (type
, die
, cu
);
16375 static enum dwarf_array_dim_ordering
16376 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16378 struct attribute
*attr
;
16380 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16382 if (attr
!= nullptr)
16383 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16385 /* GNU F77 is a special case, as at 08/2004 array type info is the
16386 opposite order to the dwarf2 specification, but data is still
16387 laid out as per normal fortran.
16389 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16390 version checking. */
16392 if (cu
->language
== language_fortran
16393 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16395 return DW_ORD_row_major
;
16398 switch (cu
->language_defn
->la_array_ordering
)
16400 case array_column_major
:
16401 return DW_ORD_col_major
;
16402 case array_row_major
:
16404 return DW_ORD_row_major
;
16408 /* Extract all information from a DW_TAG_set_type DIE and put it in
16409 the DIE's type field. */
16411 static struct type
*
16412 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16414 struct type
*domain_type
, *set_type
;
16415 struct attribute
*attr
;
16417 domain_type
= die_type (die
, cu
);
16419 /* The die_type call above may have already set the type for this DIE. */
16420 set_type
= get_die_type (die
, cu
);
16424 set_type
= create_set_type (NULL
, domain_type
);
16426 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16427 if (attr
!= nullptr)
16428 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16430 maybe_set_alignment (cu
, die
, set_type
);
16432 return set_die_type (die
, set_type
, cu
);
16435 /* A helper for read_common_block that creates a locexpr baton.
16436 SYM is the symbol which we are marking as computed.
16437 COMMON_DIE is the DIE for the common block.
16438 COMMON_LOC is the location expression attribute for the common
16440 MEMBER_LOC is the location expression attribute for the particular
16441 member of the common block that we are processing.
16442 CU is the CU from which the above come. */
16445 mark_common_block_symbol_computed (struct symbol
*sym
,
16446 struct die_info
*common_die
,
16447 struct attribute
*common_loc
,
16448 struct attribute
*member_loc
,
16449 struct dwarf2_cu
*cu
)
16451 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16452 struct objfile
*objfile
= per_objfile
->objfile
;
16453 struct dwarf2_locexpr_baton
*baton
;
16455 unsigned int cu_off
;
16456 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16457 LONGEST offset
= 0;
16459 gdb_assert (common_loc
&& member_loc
);
16460 gdb_assert (common_loc
->form_is_block ());
16461 gdb_assert (member_loc
->form_is_block ()
16462 || member_loc
->form_is_constant ());
16464 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16465 baton
->per_objfile
= per_objfile
;
16466 baton
->per_cu
= cu
->per_cu
;
16467 gdb_assert (baton
->per_cu
);
16469 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16471 if (member_loc
->form_is_constant ())
16473 offset
= member_loc
->constant_value (0);
16474 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16477 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16479 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16482 *ptr
++ = DW_OP_call4
;
16483 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16484 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16487 if (member_loc
->form_is_constant ())
16489 *ptr
++ = DW_OP_addr
;
16490 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16491 ptr
+= cu
->header
.addr_size
;
16495 /* We have to copy the data here, because DW_OP_call4 will only
16496 use a DW_AT_location attribute. */
16497 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16498 ptr
+= DW_BLOCK (member_loc
)->size
;
16501 *ptr
++ = DW_OP_plus
;
16502 gdb_assert (ptr
- baton
->data
== baton
->size
);
16504 SYMBOL_LOCATION_BATON (sym
) = baton
;
16505 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16508 /* Create appropriate locally-scoped variables for all the
16509 DW_TAG_common_block entries. Also create a struct common_block
16510 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16511 is used to separate the common blocks name namespace from regular
16515 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16517 struct attribute
*attr
;
16519 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16520 if (attr
!= nullptr)
16522 /* Support the .debug_loc offsets. */
16523 if (attr
->form_is_block ())
16527 else if (attr
->form_is_section_offset ())
16529 dwarf2_complex_location_expr_complaint ();
16534 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16535 "common block member");
16540 if (die
->child
!= NULL
)
16542 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16543 struct die_info
*child_die
;
16544 size_t n_entries
= 0, size
;
16545 struct common_block
*common_block
;
16546 struct symbol
*sym
;
16548 for (child_die
= die
->child
;
16549 child_die
&& child_die
->tag
;
16550 child_die
= child_die
->sibling
)
16553 size
= (sizeof (struct common_block
)
16554 + (n_entries
- 1) * sizeof (struct symbol
*));
16556 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16558 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16559 common_block
->n_entries
= 0;
16561 for (child_die
= die
->child
;
16562 child_die
&& child_die
->tag
;
16563 child_die
= child_die
->sibling
)
16565 /* Create the symbol in the DW_TAG_common_block block in the current
16567 sym
= new_symbol (child_die
, NULL
, cu
);
16570 struct attribute
*member_loc
;
16572 common_block
->contents
[common_block
->n_entries
++] = sym
;
16574 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16578 /* GDB has handled this for a long time, but it is
16579 not specified by DWARF. It seems to have been
16580 emitted by gfortran at least as recently as:
16581 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16582 complaint (_("Variable in common block has "
16583 "DW_AT_data_member_location "
16584 "- DIE at %s [in module %s]"),
16585 sect_offset_str (child_die
->sect_off
),
16586 objfile_name (objfile
));
16588 if (member_loc
->form_is_section_offset ())
16589 dwarf2_complex_location_expr_complaint ();
16590 else if (member_loc
->form_is_constant ()
16591 || member_loc
->form_is_block ())
16593 if (attr
!= nullptr)
16594 mark_common_block_symbol_computed (sym
, die
, attr
,
16598 dwarf2_complex_location_expr_complaint ();
16603 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16604 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16608 /* Create a type for a C++ namespace. */
16610 static struct type
*
16611 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16613 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16614 const char *previous_prefix
, *name
;
16618 /* For extensions, reuse the type of the original namespace. */
16619 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16621 struct die_info
*ext_die
;
16622 struct dwarf2_cu
*ext_cu
= cu
;
16624 ext_die
= dwarf2_extension (die
, &ext_cu
);
16625 type
= read_type_die (ext_die
, ext_cu
);
16627 /* EXT_CU may not be the same as CU.
16628 Ensure TYPE is recorded with CU in die_type_hash. */
16629 return set_die_type (die
, type
, cu
);
16632 name
= namespace_name (die
, &is_anonymous
, cu
);
16634 /* Now build the name of the current namespace. */
16636 previous_prefix
= determine_prefix (die
, cu
);
16637 if (previous_prefix
[0] != '\0')
16638 name
= typename_concat (&objfile
->objfile_obstack
,
16639 previous_prefix
, name
, 0, cu
);
16641 /* Create the type. */
16642 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16644 return set_die_type (die
, type
, cu
);
16647 /* Read a namespace scope. */
16650 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16652 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16655 /* Add a symbol associated to this if we haven't seen the namespace
16656 before. Also, add a using directive if it's an anonymous
16659 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16663 type
= read_type_die (die
, cu
);
16664 new_symbol (die
, type
, cu
);
16666 namespace_name (die
, &is_anonymous
, cu
);
16669 const char *previous_prefix
= determine_prefix (die
, cu
);
16671 std::vector
<const char *> excludes
;
16672 add_using_directive (using_directives (cu
),
16673 previous_prefix
, type
->name (), NULL
,
16674 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16678 if (die
->child
!= NULL
)
16680 struct die_info
*child_die
= die
->child
;
16682 while (child_die
&& child_die
->tag
)
16684 process_die (child_die
, cu
);
16685 child_die
= child_die
->sibling
;
16690 /* Read a Fortran module as type. This DIE can be only a declaration used for
16691 imported module. Still we need that type as local Fortran "use ... only"
16692 declaration imports depend on the created type in determine_prefix. */
16694 static struct type
*
16695 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16697 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16698 const char *module_name
;
16701 module_name
= dwarf2_name (die
, cu
);
16702 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16704 return set_die_type (die
, type
, cu
);
16707 /* Read a Fortran module. */
16710 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16712 struct die_info
*child_die
= die
->child
;
16715 type
= read_type_die (die
, cu
);
16716 new_symbol (die
, type
, cu
);
16718 while (child_die
&& child_die
->tag
)
16720 process_die (child_die
, cu
);
16721 child_die
= child_die
->sibling
;
16725 /* Return the name of the namespace represented by DIE. Set
16726 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16729 static const char *
16730 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16732 struct die_info
*current_die
;
16733 const char *name
= NULL
;
16735 /* Loop through the extensions until we find a name. */
16737 for (current_die
= die
;
16738 current_die
!= NULL
;
16739 current_die
= dwarf2_extension (die
, &cu
))
16741 /* We don't use dwarf2_name here so that we can detect the absence
16742 of a name -> anonymous namespace. */
16743 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16749 /* Is it an anonymous namespace? */
16751 *is_anonymous
= (name
== NULL
);
16753 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16758 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16759 the user defined type vector. */
16761 static struct type
*
16762 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16764 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16765 struct comp_unit_head
*cu_header
= &cu
->header
;
16767 struct attribute
*attr_byte_size
;
16768 struct attribute
*attr_address_class
;
16769 int byte_size
, addr_class
;
16770 struct type
*target_type
;
16772 target_type
= die_type (die
, cu
);
16774 /* The die_type call above may have already set the type for this DIE. */
16775 type
= get_die_type (die
, cu
);
16779 type
= lookup_pointer_type (target_type
);
16781 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16782 if (attr_byte_size
)
16783 byte_size
= DW_UNSND (attr_byte_size
);
16785 byte_size
= cu_header
->addr_size
;
16787 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16788 if (attr_address_class
)
16789 addr_class
= DW_UNSND (attr_address_class
);
16791 addr_class
= DW_ADDR_none
;
16793 ULONGEST alignment
= get_alignment (cu
, die
);
16795 /* If the pointer size, alignment, or address class is different
16796 than the default, create a type variant marked as such and set
16797 the length accordingly. */
16798 if (TYPE_LENGTH (type
) != byte_size
16799 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16800 && alignment
!= TYPE_RAW_ALIGN (type
))
16801 || addr_class
!= DW_ADDR_none
)
16803 if (gdbarch_address_class_type_flags_p (gdbarch
))
16807 type_flags
= gdbarch_address_class_type_flags
16808 (gdbarch
, byte_size
, addr_class
);
16809 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16811 type
= make_type_with_address_space (type
, type_flags
);
16813 else if (TYPE_LENGTH (type
) != byte_size
)
16815 complaint (_("invalid pointer size %d"), byte_size
);
16817 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16819 complaint (_("Invalid DW_AT_alignment"
16820 " - DIE at %s [in module %s]"),
16821 sect_offset_str (die
->sect_off
),
16822 objfile_name (cu
->per_objfile
->objfile
));
16826 /* Should we also complain about unhandled address classes? */
16830 TYPE_LENGTH (type
) = byte_size
;
16831 set_type_align (type
, alignment
);
16832 return set_die_type (die
, type
, cu
);
16835 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16836 the user defined type vector. */
16838 static struct type
*
16839 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16842 struct type
*to_type
;
16843 struct type
*domain
;
16845 to_type
= die_type (die
, cu
);
16846 domain
= die_containing_type (die
, cu
);
16848 /* The calls above may have already set the type for this DIE. */
16849 type
= get_die_type (die
, cu
);
16853 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16854 type
= lookup_methodptr_type (to_type
);
16855 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16857 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16859 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16860 to_type
->fields (), to_type
->num_fields (),
16861 TYPE_VARARGS (to_type
));
16862 type
= lookup_methodptr_type (new_type
);
16865 type
= lookup_memberptr_type (to_type
, domain
);
16867 return set_die_type (die
, type
, cu
);
16870 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16871 the user defined type vector. */
16873 static struct type
*
16874 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16875 enum type_code refcode
)
16877 struct comp_unit_head
*cu_header
= &cu
->header
;
16878 struct type
*type
, *target_type
;
16879 struct attribute
*attr
;
16881 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16883 target_type
= die_type (die
, cu
);
16885 /* The die_type call above may have already set the type for this DIE. */
16886 type
= get_die_type (die
, cu
);
16890 type
= lookup_reference_type (target_type
, refcode
);
16891 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16892 if (attr
!= nullptr)
16894 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16898 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16900 maybe_set_alignment (cu
, die
, type
);
16901 return set_die_type (die
, type
, cu
);
16904 /* Add the given cv-qualifiers to the element type of the array. GCC
16905 outputs DWARF type qualifiers that apply to an array, not the
16906 element type. But GDB relies on the array element type to carry
16907 the cv-qualifiers. This mimics section 6.7.3 of the C99
16910 static struct type
*
16911 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16912 struct type
*base_type
, int cnst
, int voltl
)
16914 struct type
*el_type
, *inner_array
;
16916 base_type
= copy_type (base_type
);
16917 inner_array
= base_type
;
16919 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16921 TYPE_TARGET_TYPE (inner_array
) =
16922 copy_type (TYPE_TARGET_TYPE (inner_array
));
16923 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16926 el_type
= TYPE_TARGET_TYPE (inner_array
);
16927 cnst
|= TYPE_CONST (el_type
);
16928 voltl
|= TYPE_VOLATILE (el_type
);
16929 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16931 return set_die_type (die
, base_type
, cu
);
16934 static struct type
*
16935 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16937 struct type
*base_type
, *cv_type
;
16939 base_type
= die_type (die
, cu
);
16941 /* The die_type call above may have already set the type for this DIE. */
16942 cv_type
= get_die_type (die
, cu
);
16946 /* In case the const qualifier is applied to an array type, the element type
16947 is so qualified, not the array type (section 6.7.3 of C99). */
16948 if (base_type
->code () == TYPE_CODE_ARRAY
)
16949 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16951 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16952 return set_die_type (die
, cv_type
, cu
);
16955 static struct type
*
16956 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16958 struct type
*base_type
, *cv_type
;
16960 base_type
= die_type (die
, cu
);
16962 /* The die_type call above may have already set the type for this DIE. */
16963 cv_type
= get_die_type (die
, cu
);
16967 /* In case the volatile qualifier is applied to an array type, the
16968 element type is so qualified, not the array type (section 6.7.3
16970 if (base_type
->code () == TYPE_CODE_ARRAY
)
16971 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16973 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16974 return set_die_type (die
, cv_type
, cu
);
16977 /* Handle DW_TAG_restrict_type. */
16979 static struct type
*
16980 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16982 struct type
*base_type
, *cv_type
;
16984 base_type
= die_type (die
, cu
);
16986 /* The die_type call above may have already set the type for this DIE. */
16987 cv_type
= get_die_type (die
, cu
);
16991 cv_type
= make_restrict_type (base_type
);
16992 return set_die_type (die
, cv_type
, cu
);
16995 /* Handle DW_TAG_atomic_type. */
16997 static struct type
*
16998 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17000 struct type
*base_type
, *cv_type
;
17002 base_type
= die_type (die
, cu
);
17004 /* The die_type call above may have already set the type for this DIE. */
17005 cv_type
= get_die_type (die
, cu
);
17009 cv_type
= make_atomic_type (base_type
);
17010 return set_die_type (die
, cv_type
, cu
);
17013 /* Extract all information from a DW_TAG_string_type DIE and add to
17014 the user defined type vector. It isn't really a user defined type,
17015 but it behaves like one, with other DIE's using an AT_user_def_type
17016 attribute to reference it. */
17018 static struct type
*
17019 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17021 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17022 struct gdbarch
*gdbarch
= objfile
->arch ();
17023 struct type
*type
, *range_type
, *index_type
, *char_type
;
17024 struct attribute
*attr
;
17025 struct dynamic_prop prop
;
17026 bool length_is_constant
= true;
17029 /* There are a couple of places where bit sizes might be made use of
17030 when parsing a DW_TAG_string_type, however, no producer that we know
17031 of make use of these. Handling bit sizes that are a multiple of the
17032 byte size is easy enough, but what about other bit sizes? Lets deal
17033 with that problem when we have to. Warn about these attributes being
17034 unsupported, then parse the type and ignore them like we always
17036 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17037 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17039 static bool warning_printed
= false;
17040 if (!warning_printed
)
17042 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17043 "currently supported on DW_TAG_string_type."));
17044 warning_printed
= true;
17048 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17049 if (attr
!= nullptr && !attr
->form_is_constant ())
17051 /* The string length describes the location at which the length of
17052 the string can be found. The size of the length field can be
17053 specified with one of the attributes below. */
17054 struct type
*prop_type
;
17055 struct attribute
*len
17056 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17057 if (len
== nullptr)
17058 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17059 if (len
!= nullptr && len
->form_is_constant ())
17061 /* Pass 0 as the default as we know this attribute is constant
17062 and the default value will not be returned. */
17063 LONGEST sz
= len
->constant_value (0);
17064 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17068 /* If the size is not specified then we assume it is the size of
17069 an address on this target. */
17070 prop_type
= cu
->addr_sized_int_type (true);
17073 /* Convert the attribute into a dynamic property. */
17074 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17077 length_is_constant
= false;
17079 else if (attr
!= nullptr)
17081 /* This DW_AT_string_length just contains the length with no
17082 indirection. There's no need to create a dynamic property in this
17083 case. Pass 0 for the default value as we know it will not be
17084 returned in this case. */
17085 length
= attr
->constant_value (0);
17087 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17089 /* We don't currently support non-constant byte sizes for strings. */
17090 length
= attr
->constant_value (1);
17094 /* Use 1 as a fallback length if we have nothing else. */
17098 index_type
= objfile_type (objfile
)->builtin_int
;
17099 if (length_is_constant
)
17100 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17103 struct dynamic_prop low_bound
;
17105 low_bound
.kind
= PROP_CONST
;
17106 low_bound
.data
.const_val
= 1;
17107 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17109 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17110 type
= create_string_type (NULL
, char_type
, range_type
);
17112 return set_die_type (die
, type
, cu
);
17115 /* Assuming that DIE corresponds to a function, returns nonzero
17116 if the function is prototyped. */
17119 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17121 struct attribute
*attr
;
17123 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17124 if (attr
&& (DW_UNSND (attr
) != 0))
17127 /* The DWARF standard implies that the DW_AT_prototyped attribute
17128 is only meaningful for C, but the concept also extends to other
17129 languages that allow unprototyped functions (Eg: Objective C).
17130 For all other languages, assume that functions are always
17132 if (cu
->language
!= language_c
17133 && cu
->language
!= language_objc
17134 && cu
->language
!= language_opencl
)
17137 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17138 prototyped and unprototyped functions; default to prototyped,
17139 since that is more common in modern code (and RealView warns
17140 about unprototyped functions). */
17141 if (producer_is_realview (cu
->producer
))
17147 /* Handle DIES due to C code like:
17151 int (*funcp)(int a, long l);
17155 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17157 static struct type
*
17158 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17160 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17161 struct type
*type
; /* Type that this function returns. */
17162 struct type
*ftype
; /* Function that returns above type. */
17163 struct attribute
*attr
;
17165 type
= die_type (die
, cu
);
17167 /* The die_type call above may have already set the type for this DIE. */
17168 ftype
= get_die_type (die
, cu
);
17172 ftype
= lookup_function_type (type
);
17174 if (prototyped_function_p (die
, cu
))
17175 TYPE_PROTOTYPED (ftype
) = 1;
17177 /* Store the calling convention in the type if it's available in
17178 the subroutine die. Otherwise set the calling convention to
17179 the default value DW_CC_normal. */
17180 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17181 if (attr
!= nullptr
17182 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17183 TYPE_CALLING_CONVENTION (ftype
)
17184 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17185 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17186 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17188 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17190 /* Record whether the function returns normally to its caller or not
17191 if the DWARF producer set that information. */
17192 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17193 if (attr
&& (DW_UNSND (attr
) != 0))
17194 TYPE_NO_RETURN (ftype
) = 1;
17196 /* We need to add the subroutine type to the die immediately so
17197 we don't infinitely recurse when dealing with parameters
17198 declared as the same subroutine type. */
17199 set_die_type (die
, ftype
, cu
);
17201 if (die
->child
!= NULL
)
17203 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17204 struct die_info
*child_die
;
17205 int nparams
, iparams
;
17207 /* Count the number of parameters.
17208 FIXME: GDB currently ignores vararg functions, but knows about
17209 vararg member functions. */
17211 child_die
= die
->child
;
17212 while (child_die
&& child_die
->tag
)
17214 if (child_die
->tag
== DW_TAG_formal_parameter
)
17216 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17217 TYPE_VARARGS (ftype
) = 1;
17218 child_die
= child_die
->sibling
;
17221 /* Allocate storage for parameters and fill them in. */
17222 ftype
->set_num_fields (nparams
);
17224 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17226 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17227 even if we error out during the parameters reading below. */
17228 for (iparams
= 0; iparams
< nparams
; iparams
++)
17229 ftype
->field (iparams
).set_type (void_type
);
17232 child_die
= die
->child
;
17233 while (child_die
&& child_die
->tag
)
17235 if (child_die
->tag
== DW_TAG_formal_parameter
)
17237 struct type
*arg_type
;
17239 /* DWARF version 2 has no clean way to discern C++
17240 static and non-static member functions. G++ helps
17241 GDB by marking the first parameter for non-static
17242 member functions (which is the this pointer) as
17243 artificial. We pass this information to
17244 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17246 DWARF version 3 added DW_AT_object_pointer, which GCC
17247 4.5 does not yet generate. */
17248 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17249 if (attr
!= nullptr)
17250 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17252 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17253 arg_type
= die_type (child_die
, cu
);
17255 /* RealView does not mark THIS as const, which the testsuite
17256 expects. GCC marks THIS as const in method definitions,
17257 but not in the class specifications (GCC PR 43053). */
17258 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17259 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17262 struct dwarf2_cu
*arg_cu
= cu
;
17263 const char *name
= dwarf2_name (child_die
, cu
);
17265 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17266 if (attr
!= nullptr)
17268 /* If the compiler emits this, use it. */
17269 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17272 else if (name
&& strcmp (name
, "this") == 0)
17273 /* Function definitions will have the argument names. */
17275 else if (name
== NULL
&& iparams
== 0)
17276 /* Declarations may not have the names, so like
17277 elsewhere in GDB, assume an artificial first
17278 argument is "this". */
17282 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17286 ftype
->field (iparams
).set_type (arg_type
);
17289 child_die
= child_die
->sibling
;
17296 static struct type
*
17297 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17299 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17300 const char *name
= NULL
;
17301 struct type
*this_type
, *target_type
;
17303 name
= dwarf2_full_name (NULL
, die
, cu
);
17304 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17305 TYPE_TARGET_STUB (this_type
) = 1;
17306 set_die_type (die
, this_type
, cu
);
17307 target_type
= die_type (die
, cu
);
17308 if (target_type
!= this_type
)
17309 TYPE_TARGET_TYPE (this_type
) = target_type
;
17312 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17313 spec and cause infinite loops in GDB. */
17314 complaint (_("Self-referential DW_TAG_typedef "
17315 "- DIE at %s [in module %s]"),
17316 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17317 TYPE_TARGET_TYPE (this_type
) = NULL
;
17321 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17322 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17323 Handle these by just returning the target type, rather than
17324 constructing an anonymous typedef type and trying to handle this
17326 set_die_type (die
, target_type
, cu
);
17327 return target_type
;
17332 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17333 (which may be different from NAME) to the architecture back-end to allow
17334 it to guess the correct format if necessary. */
17336 static struct type
*
17337 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17338 const char *name_hint
, enum bfd_endian byte_order
)
17340 struct gdbarch
*gdbarch
= objfile
->arch ();
17341 const struct floatformat
**format
;
17344 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17346 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17348 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17353 /* Allocate an integer type of size BITS and name NAME. */
17355 static struct type
*
17356 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17357 int bits
, int unsigned_p
, const char *name
)
17361 /* Versions of Intel's C Compiler generate an integer type called "void"
17362 instead of using DW_TAG_unspecified_type. This has been seen on
17363 at least versions 14, 17, and 18. */
17364 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17365 && strcmp (name
, "void") == 0)
17366 type
= objfile_type (objfile
)->builtin_void
;
17368 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17373 /* Initialise and return a floating point type of size BITS suitable for
17374 use as a component of a complex number. The NAME_HINT is passed through
17375 when initialising the floating point type and is the name of the complex
17378 As DWARF doesn't currently provide an explicit name for the components
17379 of a complex number, but it can be helpful to have these components
17380 named, we try to select a suitable name based on the size of the
17382 static struct type
*
17383 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17384 struct objfile
*objfile
,
17385 int bits
, const char *name_hint
,
17386 enum bfd_endian byte_order
)
17388 gdbarch
*gdbarch
= objfile
->arch ();
17389 struct type
*tt
= nullptr;
17391 /* Try to find a suitable floating point builtin type of size BITS.
17392 We're going to use the name of this type as the name for the complex
17393 target type that we are about to create. */
17394 switch (cu
->language
)
17396 case language_fortran
:
17400 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17403 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17405 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17407 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17415 tt
= builtin_type (gdbarch
)->builtin_float
;
17418 tt
= builtin_type (gdbarch
)->builtin_double
;
17420 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17422 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17428 /* If the type we found doesn't match the size we were looking for, then
17429 pretend we didn't find a type at all, the complex target type we
17430 create will then be nameless. */
17431 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17434 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17435 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17438 /* Find a representation of a given base type and install
17439 it in the TYPE field of the die. */
17441 static struct type
*
17442 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17444 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17446 struct attribute
*attr
;
17447 int encoding
= 0, bits
= 0;
17451 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17452 if (attr
!= nullptr)
17453 encoding
= DW_UNSND (attr
);
17454 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17455 if (attr
!= nullptr)
17456 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17457 name
= dwarf2_name (die
, cu
);
17459 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17461 arch
= objfile
->arch ();
17462 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17464 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17467 int endianity
= DW_UNSND (attr
);
17472 byte_order
= BFD_ENDIAN_BIG
;
17474 case DW_END_little
:
17475 byte_order
= BFD_ENDIAN_LITTLE
;
17478 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17485 case DW_ATE_address
:
17486 /* Turn DW_ATE_address into a void * pointer. */
17487 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17488 type
= init_pointer_type (objfile
, bits
, name
, type
);
17490 case DW_ATE_boolean
:
17491 type
= init_boolean_type (objfile
, bits
, 1, name
);
17493 case DW_ATE_complex_float
:
17494 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17496 if (type
->code () == TYPE_CODE_ERROR
)
17498 if (name
== nullptr)
17500 struct obstack
*obstack
17501 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17502 name
= obconcat (obstack
, "_Complex ", type
->name (),
17505 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17508 type
= init_complex_type (name
, type
);
17510 case DW_ATE_decimal_float
:
17511 type
= init_decfloat_type (objfile
, bits
, name
);
17514 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17516 case DW_ATE_signed
:
17517 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17519 case DW_ATE_unsigned
:
17520 if (cu
->language
== language_fortran
17522 && startswith (name
, "character("))
17523 type
= init_character_type (objfile
, bits
, 1, name
);
17525 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17527 case DW_ATE_signed_char
:
17528 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17529 || cu
->language
== language_pascal
17530 || cu
->language
== language_fortran
)
17531 type
= init_character_type (objfile
, bits
, 0, name
);
17533 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17535 case DW_ATE_unsigned_char
:
17536 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17537 || cu
->language
== language_pascal
17538 || cu
->language
== language_fortran
17539 || cu
->language
== language_rust
)
17540 type
= init_character_type (objfile
, bits
, 1, name
);
17542 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17547 type
= builtin_type (arch
)->builtin_char16
;
17548 else if (bits
== 32)
17549 type
= builtin_type (arch
)->builtin_char32
;
17552 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17554 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17556 return set_die_type (die
, type
, cu
);
17561 complaint (_("unsupported DW_AT_encoding: '%s'"),
17562 dwarf_type_encoding_name (encoding
));
17563 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17567 if (name
&& strcmp (name
, "char") == 0)
17568 TYPE_NOSIGN (type
) = 1;
17570 maybe_set_alignment (cu
, die
, type
);
17572 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17574 return set_die_type (die
, type
, cu
);
17577 /* Parse dwarf attribute if it's a block, reference or constant and put the
17578 resulting value of the attribute into struct bound_prop.
17579 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17582 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17583 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17584 struct type
*default_type
)
17586 struct dwarf2_property_baton
*baton
;
17587 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17588 struct objfile
*objfile
= per_objfile
->objfile
;
17589 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17591 gdb_assert (default_type
!= NULL
);
17593 if (attr
== NULL
|| prop
== NULL
)
17596 if (attr
->form_is_block ())
17598 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17599 baton
->property_type
= default_type
;
17600 baton
->locexpr
.per_cu
= cu
->per_cu
;
17601 baton
->locexpr
.per_objfile
= per_objfile
;
17602 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17603 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17604 switch (attr
->name
)
17606 case DW_AT_string_length
:
17607 baton
->locexpr
.is_reference
= true;
17610 baton
->locexpr
.is_reference
= false;
17613 prop
->data
.baton
= baton
;
17614 prop
->kind
= PROP_LOCEXPR
;
17615 gdb_assert (prop
->data
.baton
!= NULL
);
17617 else if (attr
->form_is_ref ())
17619 struct dwarf2_cu
*target_cu
= cu
;
17620 struct die_info
*target_die
;
17621 struct attribute
*target_attr
;
17623 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17624 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17625 if (target_attr
== NULL
)
17626 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17628 if (target_attr
== NULL
)
17631 switch (target_attr
->name
)
17633 case DW_AT_location
:
17634 if (target_attr
->form_is_section_offset ())
17636 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17637 baton
->property_type
= die_type (target_die
, target_cu
);
17638 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17639 prop
->data
.baton
= baton
;
17640 prop
->kind
= PROP_LOCLIST
;
17641 gdb_assert (prop
->data
.baton
!= NULL
);
17643 else if (target_attr
->form_is_block ())
17645 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17646 baton
->property_type
= die_type (target_die
, target_cu
);
17647 baton
->locexpr
.per_cu
= cu
->per_cu
;
17648 baton
->locexpr
.per_objfile
= per_objfile
;
17649 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17650 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17651 baton
->locexpr
.is_reference
= true;
17652 prop
->data
.baton
= baton
;
17653 prop
->kind
= PROP_LOCEXPR
;
17654 gdb_assert (prop
->data
.baton
!= NULL
);
17658 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17659 "dynamic property");
17663 case DW_AT_data_member_location
:
17667 if (!handle_data_member_location (target_die
, target_cu
,
17671 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17672 baton
->property_type
= read_type_die (target_die
->parent
,
17674 baton
->offset_info
.offset
= offset
;
17675 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17676 prop
->data
.baton
= baton
;
17677 prop
->kind
= PROP_ADDR_OFFSET
;
17682 else if (attr
->form_is_constant ())
17684 prop
->data
.const_val
= attr
->constant_value (0);
17685 prop
->kind
= PROP_CONST
;
17689 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17690 dwarf2_name (die
, cu
));
17700 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17702 struct type
*int_type
;
17704 /* Helper macro to examine the various builtin types. */
17705 #define TRY_TYPE(F) \
17706 int_type = (unsigned_p \
17707 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17708 : objfile_type (objfile)->builtin_ ## F); \
17709 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17716 TRY_TYPE (long_long
);
17720 gdb_assert_not_reached ("unable to find suitable integer type");
17726 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17728 int addr_size
= this->per_cu
->addr_size ();
17729 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17732 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17733 present (which is valid) then compute the default type based on the
17734 compilation units address size. */
17736 static struct type
*
17737 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17739 struct type
*index_type
= die_type (die
, cu
);
17741 /* Dwarf-2 specifications explicitly allows to create subrange types
17742 without specifying a base type.
17743 In that case, the base type must be set to the type of
17744 the lower bound, upper bound or count, in that order, if any of these
17745 three attributes references an object that has a type.
17746 If no base type is found, the Dwarf-2 specifications say that
17747 a signed integer type of size equal to the size of an address should
17749 For the following C code: `extern char gdb_int [];'
17750 GCC produces an empty range DIE.
17751 FIXME: muller/2010-05-28: Possible references to object for low bound,
17752 high bound or count are not yet handled by this code. */
17753 if (index_type
->code () == TYPE_CODE_VOID
)
17754 index_type
= cu
->addr_sized_int_type (false);
17759 /* Read the given DW_AT_subrange DIE. */
17761 static struct type
*
17762 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17764 struct type
*base_type
, *orig_base_type
;
17765 struct type
*range_type
;
17766 struct attribute
*attr
;
17767 struct dynamic_prop low
, high
;
17768 int low_default_is_valid
;
17769 int high_bound_is_count
= 0;
17771 ULONGEST negative_mask
;
17773 orig_base_type
= read_subrange_index_type (die
, cu
);
17775 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17776 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17777 creating the range type, but we use the result of check_typedef
17778 when examining properties of the type. */
17779 base_type
= check_typedef (orig_base_type
);
17781 /* The die_type call above may have already set the type for this DIE. */
17782 range_type
= get_die_type (die
, cu
);
17786 low
.kind
= PROP_CONST
;
17787 high
.kind
= PROP_CONST
;
17788 high
.data
.const_val
= 0;
17790 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17791 omitting DW_AT_lower_bound. */
17792 switch (cu
->language
)
17795 case language_cplus
:
17796 low
.data
.const_val
= 0;
17797 low_default_is_valid
= 1;
17799 case language_fortran
:
17800 low
.data
.const_val
= 1;
17801 low_default_is_valid
= 1;
17804 case language_objc
:
17805 case language_rust
:
17806 low
.data
.const_val
= 0;
17807 low_default_is_valid
= (cu
->header
.version
>= 4);
17811 case language_pascal
:
17812 low
.data
.const_val
= 1;
17813 low_default_is_valid
= (cu
->header
.version
>= 4);
17816 low
.data
.const_val
= 0;
17817 low_default_is_valid
= 0;
17821 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17822 if (attr
!= nullptr)
17823 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17824 else if (!low_default_is_valid
)
17825 complaint (_("Missing DW_AT_lower_bound "
17826 "- DIE at %s [in module %s]"),
17827 sect_offset_str (die
->sect_off
),
17828 objfile_name (cu
->per_objfile
->objfile
));
17830 struct attribute
*attr_ub
, *attr_count
;
17831 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17832 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17834 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17835 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17837 /* If bounds are constant do the final calculation here. */
17838 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17839 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17841 high_bound_is_count
= 1;
17845 if (attr_ub
!= NULL
)
17846 complaint (_("Unresolved DW_AT_upper_bound "
17847 "- DIE at %s [in module %s]"),
17848 sect_offset_str (die
->sect_off
),
17849 objfile_name (cu
->per_objfile
->objfile
));
17850 if (attr_count
!= NULL
)
17851 complaint (_("Unresolved DW_AT_count "
17852 "- DIE at %s [in module %s]"),
17853 sect_offset_str (die
->sect_off
),
17854 objfile_name (cu
->per_objfile
->objfile
));
17859 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17860 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17861 bias
= bias_attr
->constant_value (0);
17863 /* Normally, the DWARF producers are expected to use a signed
17864 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17865 But this is unfortunately not always the case, as witnessed
17866 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17867 is used instead. To work around that ambiguity, we treat
17868 the bounds as signed, and thus sign-extend their values, when
17869 the base type is signed. */
17871 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17872 if (low
.kind
== PROP_CONST
17873 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17874 low
.data
.const_val
|= negative_mask
;
17875 if (high
.kind
== PROP_CONST
17876 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17877 high
.data
.const_val
|= negative_mask
;
17879 /* Check for bit and byte strides. */
17880 struct dynamic_prop byte_stride_prop
;
17881 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17882 if (attr_byte_stride
!= nullptr)
17884 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17885 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17889 struct dynamic_prop bit_stride_prop
;
17890 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17891 if (attr_bit_stride
!= nullptr)
17893 /* It only makes sense to have either a bit or byte stride. */
17894 if (attr_byte_stride
!= nullptr)
17896 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17897 "- DIE at %s [in module %s]"),
17898 sect_offset_str (die
->sect_off
),
17899 objfile_name (cu
->per_objfile
->objfile
));
17900 attr_bit_stride
= nullptr;
17904 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17905 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17910 if (attr_byte_stride
!= nullptr
17911 || attr_bit_stride
!= nullptr)
17913 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17914 struct dynamic_prop
*stride
17915 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17918 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17919 &high
, bias
, stride
, byte_stride_p
);
17922 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17924 if (high_bound_is_count
)
17925 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17927 /* Ada expects an empty array on no boundary attributes. */
17928 if (attr
== NULL
&& cu
->language
!= language_ada
)
17929 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17931 name
= dwarf2_name (die
, cu
);
17933 range_type
->set_name (name
);
17935 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17936 if (attr
!= nullptr)
17937 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17939 maybe_set_alignment (cu
, die
, range_type
);
17941 set_die_type (die
, range_type
, cu
);
17943 /* set_die_type should be already done. */
17944 set_descriptive_type (range_type
, die
, cu
);
17949 static struct type
*
17950 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17954 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17955 type
->set_name (dwarf2_name (die
, cu
));
17957 /* In Ada, an unspecified type is typically used when the description
17958 of the type is deferred to a different unit. When encountering
17959 such a type, we treat it as a stub, and try to resolve it later on,
17961 if (cu
->language
== language_ada
)
17962 TYPE_STUB (type
) = 1;
17964 return set_die_type (die
, type
, cu
);
17967 /* Read a single die and all its descendents. Set the die's sibling
17968 field to NULL; set other fields in the die correctly, and set all
17969 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17970 location of the info_ptr after reading all of those dies. PARENT
17971 is the parent of the die in question. */
17973 static struct die_info
*
17974 read_die_and_children (const struct die_reader_specs
*reader
,
17975 const gdb_byte
*info_ptr
,
17976 const gdb_byte
**new_info_ptr
,
17977 struct die_info
*parent
)
17979 struct die_info
*die
;
17980 const gdb_byte
*cur_ptr
;
17982 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17985 *new_info_ptr
= cur_ptr
;
17988 store_in_ref_table (die
, reader
->cu
);
17990 if (die
->has_children
)
17991 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17995 *new_info_ptr
= cur_ptr
;
17998 die
->sibling
= NULL
;
17999 die
->parent
= parent
;
18003 /* Read a die, all of its descendents, and all of its siblings; set
18004 all of the fields of all of the dies correctly. Arguments are as
18005 in read_die_and_children. */
18007 static struct die_info
*
18008 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18009 const gdb_byte
*info_ptr
,
18010 const gdb_byte
**new_info_ptr
,
18011 struct die_info
*parent
)
18013 struct die_info
*first_die
, *last_sibling
;
18014 const gdb_byte
*cur_ptr
;
18016 cur_ptr
= info_ptr
;
18017 first_die
= last_sibling
= NULL
;
18021 struct die_info
*die
18022 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18026 *new_info_ptr
= cur_ptr
;
18033 last_sibling
->sibling
= die
;
18035 last_sibling
= die
;
18039 /* Read a die, all of its descendents, and all of its siblings; set
18040 all of the fields of all of the dies correctly. Arguments are as
18041 in read_die_and_children.
18042 This the main entry point for reading a DIE and all its children. */
18044 static struct die_info
*
18045 read_die_and_siblings (const struct die_reader_specs
*reader
,
18046 const gdb_byte
*info_ptr
,
18047 const gdb_byte
**new_info_ptr
,
18048 struct die_info
*parent
)
18050 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18051 new_info_ptr
, parent
);
18053 if (dwarf_die_debug
)
18055 fprintf_unfiltered (gdb_stdlog
,
18056 "Read die from %s@0x%x of %s:\n",
18057 reader
->die_section
->get_name (),
18058 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18059 bfd_get_filename (reader
->abfd
));
18060 dump_die (die
, dwarf_die_debug
);
18066 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18068 The caller is responsible for filling in the extra attributes
18069 and updating (*DIEP)->num_attrs.
18070 Set DIEP to point to a newly allocated die with its information,
18071 except for its child, sibling, and parent fields. */
18073 static const gdb_byte
*
18074 read_full_die_1 (const struct die_reader_specs
*reader
,
18075 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18076 int num_extra_attrs
)
18078 unsigned int abbrev_number
, bytes_read
, i
;
18079 struct abbrev_info
*abbrev
;
18080 struct die_info
*die
;
18081 struct dwarf2_cu
*cu
= reader
->cu
;
18082 bfd
*abfd
= reader
->abfd
;
18084 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18085 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18086 info_ptr
+= bytes_read
;
18087 if (!abbrev_number
)
18093 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18095 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18097 bfd_get_filename (abfd
));
18099 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18100 die
->sect_off
= sect_off
;
18101 die
->tag
= abbrev
->tag
;
18102 die
->abbrev
= abbrev_number
;
18103 die
->has_children
= abbrev
->has_children
;
18105 /* Make the result usable.
18106 The caller needs to update num_attrs after adding the extra
18108 die
->num_attrs
= abbrev
->num_attrs
;
18110 std::vector
<int> indexes_that_need_reprocess
;
18111 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18113 bool need_reprocess
;
18115 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18116 info_ptr
, &need_reprocess
);
18117 if (need_reprocess
)
18118 indexes_that_need_reprocess
.push_back (i
);
18121 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18122 if (attr
!= nullptr)
18123 cu
->str_offsets_base
= DW_UNSND (attr
);
18125 attr
= die
->attr (DW_AT_loclists_base
);
18126 if (attr
!= nullptr)
18127 cu
->loclist_base
= DW_UNSND (attr
);
18129 auto maybe_addr_base
= die
->addr_base ();
18130 if (maybe_addr_base
.has_value ())
18131 cu
->addr_base
= *maybe_addr_base
;
18132 for (int index
: indexes_that_need_reprocess
)
18133 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18138 /* Read a die and all its attributes.
18139 Set DIEP to point to a newly allocated die with its information,
18140 except for its child, sibling, and parent fields. */
18142 static const gdb_byte
*
18143 read_full_die (const struct die_reader_specs
*reader
,
18144 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18146 const gdb_byte
*result
;
18148 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18150 if (dwarf_die_debug
)
18152 fprintf_unfiltered (gdb_stdlog
,
18153 "Read die from %s@0x%x of %s:\n",
18154 reader
->die_section
->get_name (),
18155 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18156 bfd_get_filename (reader
->abfd
));
18157 dump_die (*diep
, dwarf_die_debug
);
18164 /* Returns nonzero if TAG represents a type that we might generate a partial
18168 is_type_tag_for_partial (int tag
)
18173 /* Some types that would be reasonable to generate partial symbols for,
18174 that we don't at present. */
18175 case DW_TAG_array_type
:
18176 case DW_TAG_file_type
:
18177 case DW_TAG_ptr_to_member_type
:
18178 case DW_TAG_set_type
:
18179 case DW_TAG_string_type
:
18180 case DW_TAG_subroutine_type
:
18182 case DW_TAG_base_type
:
18183 case DW_TAG_class_type
:
18184 case DW_TAG_interface_type
:
18185 case DW_TAG_enumeration_type
:
18186 case DW_TAG_structure_type
:
18187 case DW_TAG_subrange_type
:
18188 case DW_TAG_typedef
:
18189 case DW_TAG_union_type
:
18196 /* Load all DIEs that are interesting for partial symbols into memory. */
18198 static struct partial_die_info
*
18199 load_partial_dies (const struct die_reader_specs
*reader
,
18200 const gdb_byte
*info_ptr
, int building_psymtab
)
18202 struct dwarf2_cu
*cu
= reader
->cu
;
18203 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18204 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18205 unsigned int bytes_read
;
18206 unsigned int load_all
= 0;
18207 int nesting_level
= 1;
18212 gdb_assert (cu
->per_cu
!= NULL
);
18213 if (cu
->per_cu
->load_all_dies
)
18217 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18221 &cu
->comp_unit_obstack
,
18222 hashtab_obstack_allocate
,
18223 dummy_obstack_deallocate
);
18227 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18229 /* A NULL abbrev means the end of a series of children. */
18230 if (abbrev
== NULL
)
18232 if (--nesting_level
== 0)
18235 info_ptr
+= bytes_read
;
18236 last_die
= parent_die
;
18237 parent_die
= parent_die
->die_parent
;
18241 /* Check for template arguments. We never save these; if
18242 they're seen, we just mark the parent, and go on our way. */
18243 if (parent_die
!= NULL
18244 && cu
->language
== language_cplus
18245 && (abbrev
->tag
== DW_TAG_template_type_param
18246 || abbrev
->tag
== DW_TAG_template_value_param
))
18248 parent_die
->has_template_arguments
= 1;
18252 /* We don't need a partial DIE for the template argument. */
18253 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18258 /* We only recurse into c++ subprograms looking for template arguments.
18259 Skip their other children. */
18261 && cu
->language
== language_cplus
18262 && parent_die
!= NULL
18263 && parent_die
->tag
== DW_TAG_subprogram
18264 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18266 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18270 /* Check whether this DIE is interesting enough to save. Normally
18271 we would not be interested in members here, but there may be
18272 later variables referencing them via DW_AT_specification (for
18273 static members). */
18275 && !is_type_tag_for_partial (abbrev
->tag
)
18276 && abbrev
->tag
!= DW_TAG_constant
18277 && abbrev
->tag
!= DW_TAG_enumerator
18278 && abbrev
->tag
!= DW_TAG_subprogram
18279 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18280 && abbrev
->tag
!= DW_TAG_lexical_block
18281 && abbrev
->tag
!= DW_TAG_variable
18282 && abbrev
->tag
!= DW_TAG_namespace
18283 && abbrev
->tag
!= DW_TAG_module
18284 && abbrev
->tag
!= DW_TAG_member
18285 && abbrev
->tag
!= DW_TAG_imported_unit
18286 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18288 /* Otherwise we skip to the next sibling, if any. */
18289 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18293 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18296 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18298 /* This two-pass algorithm for processing partial symbols has a
18299 high cost in cache pressure. Thus, handle some simple cases
18300 here which cover the majority of C partial symbols. DIEs
18301 which neither have specification tags in them, nor could have
18302 specification tags elsewhere pointing at them, can simply be
18303 processed and discarded.
18305 This segment is also optional; scan_partial_symbols and
18306 add_partial_symbol will handle these DIEs if we chain
18307 them in normally. When compilers which do not emit large
18308 quantities of duplicate debug information are more common,
18309 this code can probably be removed. */
18311 /* Any complete simple types at the top level (pretty much all
18312 of them, for a language without namespaces), can be processed
18314 if (parent_die
== NULL
18315 && pdi
.has_specification
== 0
18316 && pdi
.is_declaration
== 0
18317 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18318 || pdi
.tag
== DW_TAG_base_type
18319 || pdi
.tag
== DW_TAG_subrange_type
))
18321 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18322 add_partial_symbol (&pdi
, cu
);
18324 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18328 /* The exception for DW_TAG_typedef with has_children above is
18329 a workaround of GCC PR debug/47510. In the case of this complaint
18330 type_name_or_error will error on such types later.
18332 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18333 it could not find the child DIEs referenced later, this is checked
18334 above. In correct DWARF DW_TAG_typedef should have no children. */
18336 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18337 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18338 "- DIE at %s [in module %s]"),
18339 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18341 /* If we're at the second level, and we're an enumerator, and
18342 our parent has no specification (meaning possibly lives in a
18343 namespace elsewhere), then we can add the partial symbol now
18344 instead of queueing it. */
18345 if (pdi
.tag
== DW_TAG_enumerator
18346 && parent_die
!= NULL
18347 && parent_die
->die_parent
== NULL
18348 && parent_die
->tag
== DW_TAG_enumeration_type
18349 && parent_die
->has_specification
== 0)
18351 if (pdi
.raw_name
== NULL
)
18352 complaint (_("malformed enumerator DIE ignored"));
18353 else if (building_psymtab
)
18354 add_partial_symbol (&pdi
, cu
);
18356 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18360 struct partial_die_info
*part_die
18361 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18363 /* We'll save this DIE so link it in. */
18364 part_die
->die_parent
= parent_die
;
18365 part_die
->die_sibling
= NULL
;
18366 part_die
->die_child
= NULL
;
18368 if (last_die
&& last_die
== parent_die
)
18369 last_die
->die_child
= part_die
;
18371 last_die
->die_sibling
= part_die
;
18373 last_die
= part_die
;
18375 if (first_die
== NULL
)
18376 first_die
= part_die
;
18378 /* Maybe add the DIE to the hash table. Not all DIEs that we
18379 find interesting need to be in the hash table, because we
18380 also have the parent/sibling/child chains; only those that we
18381 might refer to by offset later during partial symbol reading.
18383 For now this means things that might have be the target of a
18384 DW_AT_specification, DW_AT_abstract_origin, or
18385 DW_AT_extension. DW_AT_extension will refer only to
18386 namespaces; DW_AT_abstract_origin refers to functions (and
18387 many things under the function DIE, but we do not recurse
18388 into function DIEs during partial symbol reading) and
18389 possibly variables as well; DW_AT_specification refers to
18390 declarations. Declarations ought to have the DW_AT_declaration
18391 flag. It happens that GCC forgets to put it in sometimes, but
18392 only for functions, not for types.
18394 Adding more things than necessary to the hash table is harmless
18395 except for the performance cost. Adding too few will result in
18396 wasted time in find_partial_die, when we reread the compilation
18397 unit with load_all_dies set. */
18400 || abbrev
->tag
== DW_TAG_constant
18401 || abbrev
->tag
== DW_TAG_subprogram
18402 || abbrev
->tag
== DW_TAG_variable
18403 || abbrev
->tag
== DW_TAG_namespace
18404 || part_die
->is_declaration
)
18408 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18409 to_underlying (part_die
->sect_off
),
18414 /* For some DIEs we want to follow their children (if any). For C
18415 we have no reason to follow the children of structures; for other
18416 languages we have to, so that we can get at method physnames
18417 to infer fully qualified class names, for DW_AT_specification,
18418 and for C++ template arguments. For C++, we also look one level
18419 inside functions to find template arguments (if the name of the
18420 function does not already contain the template arguments).
18422 For Ada and Fortran, we need to scan the children of subprograms
18423 and lexical blocks as well because these languages allow the
18424 definition of nested entities that could be interesting for the
18425 debugger, such as nested subprograms for instance. */
18426 if (last_die
->has_children
18428 || last_die
->tag
== DW_TAG_namespace
18429 || last_die
->tag
== DW_TAG_module
18430 || last_die
->tag
== DW_TAG_enumeration_type
18431 || (cu
->language
== language_cplus
18432 && last_die
->tag
== DW_TAG_subprogram
18433 && (last_die
->raw_name
== NULL
18434 || strchr (last_die
->raw_name
, '<') == NULL
))
18435 || (cu
->language
!= language_c
18436 && (last_die
->tag
== DW_TAG_class_type
18437 || last_die
->tag
== DW_TAG_interface_type
18438 || last_die
->tag
== DW_TAG_structure_type
18439 || last_die
->tag
== DW_TAG_union_type
))
18440 || ((cu
->language
== language_ada
18441 || cu
->language
== language_fortran
)
18442 && (last_die
->tag
== DW_TAG_subprogram
18443 || last_die
->tag
== DW_TAG_lexical_block
))))
18446 parent_die
= last_die
;
18450 /* Otherwise we skip to the next sibling, if any. */
18451 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18453 /* Back to the top, do it again. */
18457 partial_die_info::partial_die_info (sect_offset sect_off_
,
18458 struct abbrev_info
*abbrev
)
18459 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18463 /* See class definition. */
18466 partial_die_info::name (dwarf2_cu
*cu
)
18468 if (!canonical_name
&& raw_name
!= nullptr)
18470 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18471 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
18472 canonical_name
= 1;
18478 /* Read a minimal amount of information into the minimal die structure.
18479 INFO_PTR should point just after the initial uleb128 of a DIE. */
18482 partial_die_info::read (const struct die_reader_specs
*reader
,
18483 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18485 struct dwarf2_cu
*cu
= reader
->cu
;
18486 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18488 int has_low_pc_attr
= 0;
18489 int has_high_pc_attr
= 0;
18490 int high_pc_relative
= 0;
18492 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18495 bool need_reprocess
;
18496 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18497 info_ptr
, &need_reprocess
);
18498 /* String and address offsets that need to do the reprocessing have
18499 already been read at this point, so there is no need to wait until
18500 the loop terminates to do the reprocessing. */
18501 if (need_reprocess
)
18502 read_attribute_reprocess (reader
, &attr
);
18503 /* Store the data if it is of an attribute we want to keep in a
18504 partial symbol table. */
18510 case DW_TAG_compile_unit
:
18511 case DW_TAG_partial_unit
:
18512 case DW_TAG_type_unit
:
18513 /* Compilation units have a DW_AT_name that is a filename, not
18514 a source language identifier. */
18515 case DW_TAG_enumeration_type
:
18516 case DW_TAG_enumerator
:
18517 /* These tags always have simple identifiers already; no need
18518 to canonicalize them. */
18519 canonical_name
= 1;
18520 raw_name
= DW_STRING (&attr
);
18523 canonical_name
= 0;
18524 raw_name
= DW_STRING (&attr
);
18528 case DW_AT_linkage_name
:
18529 case DW_AT_MIPS_linkage_name
:
18530 /* Note that both forms of linkage name might appear. We
18531 assume they will be the same, and we only store the last
18533 linkage_name
= attr
.value_as_string ();
18534 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18535 See https://github.com/rust-lang/rust/issues/32925. */
18536 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18537 && strchr (linkage_name
, '{') != NULL
)
18538 linkage_name
= NULL
;
18541 has_low_pc_attr
= 1;
18542 lowpc
= attr
.value_as_address ();
18544 case DW_AT_high_pc
:
18545 has_high_pc_attr
= 1;
18546 highpc
= attr
.value_as_address ();
18547 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18548 high_pc_relative
= 1;
18550 case DW_AT_location
:
18551 /* Support the .debug_loc offsets. */
18552 if (attr
.form_is_block ())
18554 d
.locdesc
= DW_BLOCK (&attr
);
18556 else if (attr
.form_is_section_offset ())
18558 dwarf2_complex_location_expr_complaint ();
18562 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18563 "partial symbol information");
18566 case DW_AT_external
:
18567 is_external
= DW_UNSND (&attr
);
18569 case DW_AT_declaration
:
18570 is_declaration
= DW_UNSND (&attr
);
18575 case DW_AT_abstract_origin
:
18576 case DW_AT_specification
:
18577 case DW_AT_extension
:
18578 has_specification
= 1;
18579 spec_offset
= attr
.get_ref_die_offset ();
18580 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18581 || cu
->per_cu
->is_dwz
);
18583 case DW_AT_sibling
:
18584 /* Ignore absolute siblings, they might point outside of
18585 the current compile unit. */
18586 if (attr
.form
== DW_FORM_ref_addr
)
18587 complaint (_("ignoring absolute DW_AT_sibling"));
18590 const gdb_byte
*buffer
= reader
->buffer
;
18591 sect_offset off
= attr
.get_ref_die_offset ();
18592 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18594 if (sibling_ptr
< info_ptr
)
18595 complaint (_("DW_AT_sibling points backwards"));
18596 else if (sibling_ptr
> reader
->buffer_end
)
18597 reader
->die_section
->overflow_complaint ();
18599 sibling
= sibling_ptr
;
18602 case DW_AT_byte_size
:
18605 case DW_AT_const_value
:
18606 has_const_value
= 1;
18608 case DW_AT_calling_convention
:
18609 /* DWARF doesn't provide a way to identify a program's source-level
18610 entry point. DW_AT_calling_convention attributes are only meant
18611 to describe functions' calling conventions.
18613 However, because it's a necessary piece of information in
18614 Fortran, and before DWARF 4 DW_CC_program was the only
18615 piece of debugging information whose definition refers to
18616 a 'main program' at all, several compilers marked Fortran
18617 main programs with DW_CC_program --- even when those
18618 functions use the standard calling conventions.
18620 Although DWARF now specifies a way to provide this
18621 information, we support this practice for backward
18623 if (DW_UNSND (&attr
) == DW_CC_program
18624 && cu
->language
== language_fortran
)
18625 main_subprogram
= 1;
18628 if (DW_UNSND (&attr
) == DW_INL_inlined
18629 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18630 may_be_inlined
= 1;
18634 if (tag
== DW_TAG_imported_unit
)
18636 d
.sect_off
= attr
.get_ref_die_offset ();
18637 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18638 || cu
->per_cu
->is_dwz
);
18642 case DW_AT_main_subprogram
:
18643 main_subprogram
= DW_UNSND (&attr
);
18648 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18649 but that requires a full DIE, so instead we just
18651 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18652 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18653 + (need_ranges_base
18657 /* Value of the DW_AT_ranges attribute is the offset in the
18658 .debug_ranges section. */
18659 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18670 /* For Ada, if both the name and the linkage name appear, we prefer
18671 the latter. This lets "catch exception" work better, regardless
18672 of the order in which the name and linkage name were emitted.
18673 Really, though, this is just a workaround for the fact that gdb
18674 doesn't store both the name and the linkage name. */
18675 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18676 raw_name
= linkage_name
;
18678 if (high_pc_relative
)
18681 if (has_low_pc_attr
&& has_high_pc_attr
)
18683 /* When using the GNU linker, .gnu.linkonce. sections are used to
18684 eliminate duplicate copies of functions and vtables and such.
18685 The linker will arbitrarily choose one and discard the others.
18686 The AT_*_pc values for such functions refer to local labels in
18687 these sections. If the section from that file was discarded, the
18688 labels are not in the output, so the relocs get a value of 0.
18689 If this is a discarded function, mark the pc bounds as invalid,
18690 so that GDB will ignore it. */
18691 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
18693 struct objfile
*objfile
= per_objfile
->objfile
;
18694 struct gdbarch
*gdbarch
= objfile
->arch ();
18696 complaint (_("DW_AT_low_pc %s is zero "
18697 "for DIE at %s [in module %s]"),
18698 paddress (gdbarch
, lowpc
),
18699 sect_offset_str (sect_off
),
18700 objfile_name (objfile
));
18702 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18703 else if (lowpc
>= highpc
)
18705 struct objfile
*objfile
= per_objfile
->objfile
;
18706 struct gdbarch
*gdbarch
= objfile
->arch ();
18708 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18709 "for DIE at %s [in module %s]"),
18710 paddress (gdbarch
, lowpc
),
18711 paddress (gdbarch
, highpc
),
18712 sect_offset_str (sect_off
),
18713 objfile_name (objfile
));
18722 /* Find a cached partial DIE at OFFSET in CU. */
18724 struct partial_die_info
*
18725 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18727 struct partial_die_info
*lookup_die
= NULL
;
18728 struct partial_die_info
part_die (sect_off
);
18730 lookup_die
= ((struct partial_die_info
*)
18731 htab_find_with_hash (partial_dies
, &part_die
,
18732 to_underlying (sect_off
)));
18737 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18738 except in the case of .debug_types DIEs which do not reference
18739 outside their CU (they do however referencing other types via
18740 DW_FORM_ref_sig8). */
18742 static const struct cu_partial_die_info
18743 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18745 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18746 struct objfile
*objfile
= per_objfile
->objfile
;
18747 struct partial_die_info
*pd
= NULL
;
18749 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18750 && cu
->header
.offset_in_cu_p (sect_off
))
18752 pd
= cu
->find_partial_die (sect_off
);
18755 /* We missed recording what we needed.
18756 Load all dies and try again. */
18760 /* TUs don't reference other CUs/TUs (except via type signatures). */
18761 if (cu
->per_cu
->is_debug_types
)
18763 error (_("Dwarf Error: Type Unit at offset %s contains"
18764 " external reference to offset %s [in module %s].\n"),
18765 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18766 bfd_get_filename (objfile
->obfd
));
18768 dwarf2_per_cu_data
*per_cu
18769 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18772 cu
= per_objfile
->get_cu (per_cu
);
18773 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
18774 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
18776 cu
= per_objfile
->get_cu (per_cu
);
18779 pd
= cu
->find_partial_die (sect_off
);
18782 /* If we didn't find it, and not all dies have been loaded,
18783 load them all and try again. */
18785 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
18787 cu
->per_cu
->load_all_dies
= 1;
18789 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18790 THIS_CU->cu may already be in use. So we can't just free it and
18791 replace its DIEs with the ones we read in. Instead, we leave those
18792 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18793 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18795 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
18797 pd
= cu
->find_partial_die (sect_off
);
18801 internal_error (__FILE__
, __LINE__
,
18802 _("could not find partial DIE %s "
18803 "in cache [from module %s]\n"),
18804 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18808 /* See if we can figure out if the class lives in a namespace. We do
18809 this by looking for a member function; its demangled name will
18810 contain namespace info, if there is any. */
18813 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18814 struct dwarf2_cu
*cu
)
18816 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18817 what template types look like, because the demangler
18818 frequently doesn't give the same name as the debug info. We
18819 could fix this by only using the demangled name to get the
18820 prefix (but see comment in read_structure_type). */
18822 struct partial_die_info
*real_pdi
;
18823 struct partial_die_info
*child_pdi
;
18825 /* If this DIE (this DIE's specification, if any) has a parent, then
18826 we should not do this. We'll prepend the parent's fully qualified
18827 name when we create the partial symbol. */
18829 real_pdi
= struct_pdi
;
18830 while (real_pdi
->has_specification
)
18832 auto res
= find_partial_die (real_pdi
->spec_offset
,
18833 real_pdi
->spec_is_dwz
, cu
);
18834 real_pdi
= res
.pdi
;
18838 if (real_pdi
->die_parent
!= NULL
)
18841 for (child_pdi
= struct_pdi
->die_child
;
18843 child_pdi
= child_pdi
->die_sibling
)
18845 if (child_pdi
->tag
== DW_TAG_subprogram
18846 && child_pdi
->linkage_name
!= NULL
)
18848 gdb::unique_xmalloc_ptr
<char> actual_class_name
18849 (language_class_name_from_physname (cu
->language_defn
,
18850 child_pdi
->linkage_name
));
18851 if (actual_class_name
!= NULL
)
18853 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18854 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
18855 struct_pdi
->canonical_name
= 1;
18862 /* Return true if a DIE with TAG may have the DW_AT_const_value
18866 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18870 case DW_TAG_constant
:
18871 case DW_TAG_enumerator
:
18872 case DW_TAG_formal_parameter
:
18873 case DW_TAG_template_value_param
:
18874 case DW_TAG_variable
:
18882 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18884 /* Once we've fixed up a die, there's no point in doing so again.
18885 This also avoids a memory leak if we were to call
18886 guess_partial_die_structure_name multiple times. */
18890 /* If we found a reference attribute and the DIE has no name, try
18891 to find a name in the referred to DIE. */
18893 if (raw_name
== NULL
&& has_specification
)
18895 struct partial_die_info
*spec_die
;
18897 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18898 spec_die
= res
.pdi
;
18901 spec_die
->fixup (cu
);
18903 if (spec_die
->raw_name
)
18905 raw_name
= spec_die
->raw_name
;
18906 canonical_name
= spec_die
->canonical_name
;
18908 /* Copy DW_AT_external attribute if it is set. */
18909 if (spec_die
->is_external
)
18910 is_external
= spec_die
->is_external
;
18914 if (!has_const_value
&& has_specification
18915 && can_have_DW_AT_const_value_p (tag
))
18917 struct partial_die_info
*spec_die
;
18919 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18920 spec_die
= res
.pdi
;
18923 spec_die
->fixup (cu
);
18925 if (spec_die
->has_const_value
)
18927 /* Copy DW_AT_const_value attribute if it is set. */
18928 has_const_value
= spec_die
->has_const_value
;
18932 /* Set default names for some unnamed DIEs. */
18934 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
18936 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
18937 canonical_name
= 1;
18940 /* If there is no parent die to provide a namespace, and there are
18941 children, see if we can determine the namespace from their linkage
18943 if (cu
->language
== language_cplus
18944 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18945 && die_parent
== NULL
18947 && (tag
== DW_TAG_class_type
18948 || tag
== DW_TAG_structure_type
18949 || tag
== DW_TAG_union_type
))
18950 guess_partial_die_structure_name (this, cu
);
18952 /* GCC might emit a nameless struct or union that has a linkage
18953 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18954 if (raw_name
== NULL
18955 && (tag
== DW_TAG_class_type
18956 || tag
== DW_TAG_interface_type
18957 || tag
== DW_TAG_structure_type
18958 || tag
== DW_TAG_union_type
)
18959 && linkage_name
!= NULL
)
18961 gdb::unique_xmalloc_ptr
<char> demangled
18962 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18963 if (demangled
!= nullptr)
18967 /* Strip any leading namespaces/classes, keep only the base name.
18968 DW_AT_name for named DIEs does not contain the prefixes. */
18969 base
= strrchr (demangled
.get (), ':');
18970 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18973 base
= demangled
.get ();
18975 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18976 raw_name
= objfile
->intern (base
);
18977 canonical_name
= 1;
18984 /* Read the .debug_loclists header contents from the given SECTION in the
18987 read_loclist_header (struct loclist_header
*header
,
18988 struct dwarf2_section_info
*section
)
18990 unsigned int bytes_read
;
18991 bfd
*abfd
= section
->get_bfd_owner ();
18992 const gdb_byte
*info_ptr
= section
->buffer
;
18993 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18994 info_ptr
+= bytes_read
;
18995 header
->version
= read_2_bytes (abfd
, info_ptr
);
18997 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18999 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19001 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19004 /* Return the DW_AT_loclists_base value for the CU. */
19006 lookup_loclist_base (struct dwarf2_cu
*cu
)
19008 /* For the .dwo unit, the loclist_base points to the first offset following
19009 the header. The header consists of the following entities-
19010 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19012 2. version (2 bytes)
19013 3. address size (1 byte)
19014 4. segment selector size (1 byte)
19015 5. offset entry count (4 bytes)
19016 These sizes are derived as per the DWARFv5 standard. */
19017 if (cu
->dwo_unit
!= nullptr)
19019 if (cu
->header
.initial_length_size
== 4)
19020 return LOCLIST_HEADER_SIZE32
;
19021 return LOCLIST_HEADER_SIZE64
;
19023 return cu
->loclist_base
;
19026 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19027 array of offsets in the .debug_loclists section. */
19029 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19031 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19032 struct objfile
*objfile
= per_objfile
->objfile
;
19033 bfd
*abfd
= objfile
->obfd
;
19034 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19035 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19037 section
->read (objfile
);
19038 if (section
->buffer
== NULL
)
19039 complaint (_("DW_FORM_loclistx used without .debug_loclists "
19040 "section [in module %s]"), objfile_name (objfile
));
19041 struct loclist_header header
;
19042 read_loclist_header (&header
, section
);
19043 if (loclist_index
>= header
.offset_entry_count
)
19044 complaint (_("DW_FORM_loclistx pointing outside of "
19045 ".debug_loclists offset array [in module %s]"),
19046 objfile_name (objfile
));
19047 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
19049 complaint (_("DW_FORM_loclistx pointing outside of "
19050 ".debug_loclists section [in module %s]"),
19051 objfile_name (objfile
));
19052 const gdb_byte
*info_ptr
19053 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19055 if (cu
->header
.offset_size
== 4)
19056 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
19058 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
19061 /* Process the attributes that had to be skipped in the first round. These
19062 attributes are the ones that need str_offsets_base or addr_base attributes.
19063 They could not have been processed in the first round, because at the time
19064 the values of str_offsets_base or addr_base may not have been known. */
19066 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19067 struct attribute
*attr
)
19069 struct dwarf2_cu
*cu
= reader
->cu
;
19070 switch (attr
->form
)
19072 case DW_FORM_addrx
:
19073 case DW_FORM_GNU_addr_index
:
19074 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19076 case DW_FORM_loclistx
:
19077 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19080 case DW_FORM_strx1
:
19081 case DW_FORM_strx2
:
19082 case DW_FORM_strx3
:
19083 case DW_FORM_strx4
:
19084 case DW_FORM_GNU_str_index
:
19086 unsigned int str_index
= DW_UNSND (attr
);
19087 if (reader
->dwo_file
!= NULL
)
19089 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19090 DW_STRING_IS_CANONICAL (attr
) = 0;
19094 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19095 DW_STRING_IS_CANONICAL (attr
) = 0;
19100 gdb_assert_not_reached (_("Unexpected DWARF form."));
19104 /* Read an attribute value described by an attribute form. */
19106 static const gdb_byte
*
19107 read_attribute_value (const struct die_reader_specs
*reader
,
19108 struct attribute
*attr
, unsigned form
,
19109 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19110 bool *need_reprocess
)
19112 struct dwarf2_cu
*cu
= reader
->cu
;
19113 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19114 struct objfile
*objfile
= per_objfile
->objfile
;
19115 bfd
*abfd
= reader
->abfd
;
19116 struct comp_unit_head
*cu_header
= &cu
->header
;
19117 unsigned int bytes_read
;
19118 struct dwarf_block
*blk
;
19119 *need_reprocess
= false;
19121 attr
->form
= (enum dwarf_form
) form
;
19124 case DW_FORM_ref_addr
:
19125 if (cu
->header
.version
== 2)
19126 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19129 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19131 info_ptr
+= bytes_read
;
19133 case DW_FORM_GNU_ref_alt
:
19134 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19135 info_ptr
+= bytes_read
;
19139 struct gdbarch
*gdbarch
= objfile
->arch ();
19140 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19141 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19142 info_ptr
+= bytes_read
;
19145 case DW_FORM_block2
:
19146 blk
= dwarf_alloc_block (cu
);
19147 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19149 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19150 info_ptr
+= blk
->size
;
19151 DW_BLOCK (attr
) = blk
;
19153 case DW_FORM_block4
:
19154 blk
= dwarf_alloc_block (cu
);
19155 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19157 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19158 info_ptr
+= blk
->size
;
19159 DW_BLOCK (attr
) = blk
;
19161 case DW_FORM_data2
:
19162 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19165 case DW_FORM_data4
:
19166 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19169 case DW_FORM_data8
:
19170 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19173 case DW_FORM_data16
:
19174 blk
= dwarf_alloc_block (cu
);
19176 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19178 DW_BLOCK (attr
) = blk
;
19180 case DW_FORM_sec_offset
:
19181 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19182 info_ptr
+= bytes_read
;
19184 case DW_FORM_loclistx
:
19186 *need_reprocess
= true;
19187 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19188 info_ptr
+= bytes_read
;
19191 case DW_FORM_string
:
19192 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19193 DW_STRING_IS_CANONICAL (attr
) = 0;
19194 info_ptr
+= bytes_read
;
19197 if (!cu
->per_cu
->is_dwz
)
19199 DW_STRING (attr
) = read_indirect_string (per_objfile
,
19200 abfd
, info_ptr
, cu_header
,
19202 DW_STRING_IS_CANONICAL (attr
) = 0;
19203 info_ptr
+= bytes_read
;
19207 case DW_FORM_line_strp
:
19208 if (!cu
->per_cu
->is_dwz
)
19210 DW_STRING (attr
) = per_objfile
->read_line_string (info_ptr
, cu_header
,
19212 DW_STRING_IS_CANONICAL (attr
) = 0;
19213 info_ptr
+= bytes_read
;
19217 case DW_FORM_GNU_strp_alt
:
19219 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19220 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19223 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19224 DW_STRING_IS_CANONICAL (attr
) = 0;
19225 info_ptr
+= bytes_read
;
19228 case DW_FORM_exprloc
:
19229 case DW_FORM_block
:
19230 blk
= dwarf_alloc_block (cu
);
19231 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19232 info_ptr
+= bytes_read
;
19233 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19234 info_ptr
+= blk
->size
;
19235 DW_BLOCK (attr
) = blk
;
19237 case DW_FORM_block1
:
19238 blk
= dwarf_alloc_block (cu
);
19239 blk
->size
= read_1_byte (abfd
, info_ptr
);
19241 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19242 info_ptr
+= blk
->size
;
19243 DW_BLOCK (attr
) = blk
;
19245 case DW_FORM_data1
:
19246 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19250 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19253 case DW_FORM_flag_present
:
19254 DW_UNSND (attr
) = 1;
19256 case DW_FORM_sdata
:
19257 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19258 info_ptr
+= bytes_read
;
19260 case DW_FORM_udata
:
19261 case DW_FORM_rnglistx
:
19262 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19263 info_ptr
+= bytes_read
;
19266 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19267 + read_1_byte (abfd
, info_ptr
));
19271 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19272 + read_2_bytes (abfd
, info_ptr
));
19276 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19277 + read_4_bytes (abfd
, info_ptr
));
19281 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19282 + read_8_bytes (abfd
, info_ptr
));
19285 case DW_FORM_ref_sig8
:
19286 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19289 case DW_FORM_ref_udata
:
19290 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19291 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19292 info_ptr
+= bytes_read
;
19294 case DW_FORM_indirect
:
19295 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19296 info_ptr
+= bytes_read
;
19297 if (form
== DW_FORM_implicit_const
)
19299 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19300 info_ptr
+= bytes_read
;
19302 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19303 info_ptr
, need_reprocess
);
19305 case DW_FORM_implicit_const
:
19306 DW_SND (attr
) = implicit_const
;
19308 case DW_FORM_addrx
:
19309 case DW_FORM_GNU_addr_index
:
19310 *need_reprocess
= true;
19311 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19312 info_ptr
+= bytes_read
;
19315 case DW_FORM_strx1
:
19316 case DW_FORM_strx2
:
19317 case DW_FORM_strx3
:
19318 case DW_FORM_strx4
:
19319 case DW_FORM_GNU_str_index
:
19321 ULONGEST str_index
;
19322 if (form
== DW_FORM_strx1
)
19324 str_index
= read_1_byte (abfd
, info_ptr
);
19327 else if (form
== DW_FORM_strx2
)
19329 str_index
= read_2_bytes (abfd
, info_ptr
);
19332 else if (form
== DW_FORM_strx3
)
19334 str_index
= read_3_bytes (abfd
, info_ptr
);
19337 else if (form
== DW_FORM_strx4
)
19339 str_index
= read_4_bytes (abfd
, info_ptr
);
19344 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19345 info_ptr
+= bytes_read
;
19347 *need_reprocess
= true;
19348 DW_UNSND (attr
) = str_index
;
19352 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19353 dwarf_form_name (form
),
19354 bfd_get_filename (abfd
));
19358 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19359 attr
->form
= DW_FORM_GNU_ref_alt
;
19361 /* We have seen instances where the compiler tried to emit a byte
19362 size attribute of -1 which ended up being encoded as an unsigned
19363 0xffffffff. Although 0xffffffff is technically a valid size value,
19364 an object of this size seems pretty unlikely so we can relatively
19365 safely treat these cases as if the size attribute was invalid and
19366 treat them as zero by default. */
19367 if (attr
->name
== DW_AT_byte_size
19368 && form
== DW_FORM_data4
19369 && DW_UNSND (attr
) >= 0xffffffff)
19372 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19373 hex_string (DW_UNSND (attr
)));
19374 DW_UNSND (attr
) = 0;
19380 /* Read an attribute described by an abbreviated attribute. */
19382 static const gdb_byte
*
19383 read_attribute (const struct die_reader_specs
*reader
,
19384 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19385 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19387 attr
->name
= abbrev
->name
;
19388 return read_attribute_value (reader
, attr
, abbrev
->form
,
19389 abbrev
->implicit_const
, info_ptr
,
19393 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19395 static const char *
19396 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
19397 LONGEST str_offset
)
19399 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
19400 str_offset
, "DW_FORM_strp");
19403 /* Return pointer to string at .debug_str offset as read from BUF.
19404 BUF is assumed to be in a compilation unit described by CU_HEADER.
19405 Return *BYTES_READ_PTR count of bytes read from BUF. */
19407 static const char *
19408 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
19409 const gdb_byte
*buf
,
19410 const struct comp_unit_head
*cu_header
,
19411 unsigned int *bytes_read_ptr
)
19413 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19415 return read_indirect_string_at_offset (per_objfile
, str_offset
);
19421 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19422 const struct comp_unit_head
*cu_header
,
19423 unsigned int *bytes_read_ptr
)
19425 bfd
*abfd
= objfile
->obfd
;
19426 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19428 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19431 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19432 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19433 ADDR_SIZE is the size of addresses from the CU header. */
19436 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
19437 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
19439 struct objfile
*objfile
= per_objfile
->objfile
;
19440 bfd
*abfd
= objfile
->obfd
;
19441 const gdb_byte
*info_ptr
;
19442 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19444 per_objfile
->per_bfd
->addr
.read (objfile
);
19445 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19446 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19447 objfile_name (objfile
));
19448 if (addr_base_or_zero
+ addr_index
* addr_size
19449 >= per_objfile
->per_bfd
->addr
.size
)
19450 error (_("DW_FORM_addr_index pointing outside of "
19451 ".debug_addr section [in module %s]"),
19452 objfile_name (objfile
));
19453 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
19454 + addr_index
* addr_size
);
19455 if (addr_size
== 4)
19456 return bfd_get_32 (abfd
, info_ptr
);
19458 return bfd_get_64 (abfd
, info_ptr
);
19461 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19464 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19466 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19467 cu
->addr_base
, cu
->header
.addr_size
);
19470 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19473 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19474 unsigned int *bytes_read
)
19476 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19477 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19479 return read_addr_index (cu
, addr_index
);
19485 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19486 dwarf2_per_objfile
*per_objfile
,
19487 unsigned int addr_index
)
19489 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
19490 gdb::optional
<ULONGEST
> addr_base
;
19493 /* We need addr_base and addr_size.
19494 If we don't have PER_CU->cu, we have to get it.
19495 Nasty, but the alternative is storing the needed info in PER_CU,
19496 which at this point doesn't seem justified: it's not clear how frequently
19497 it would get used and it would increase the size of every PER_CU.
19498 Entry points like dwarf2_per_cu_addr_size do a similar thing
19499 so we're not in uncharted territory here.
19500 Alas we need to be a bit more complicated as addr_base is contained
19503 We don't need to read the entire CU(/TU).
19504 We just need the header and top level die.
19506 IWBN to use the aging mechanism to let us lazily later discard the CU.
19507 For now we skip this optimization. */
19511 addr_base
= cu
->addr_base
;
19512 addr_size
= cu
->header
.addr_size
;
19516 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
19517 addr_base
= reader
.cu
->addr_base
;
19518 addr_size
= reader
.cu
->header
.addr_size
;
19521 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
19524 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19525 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19528 static const char *
19529 read_str_index (struct dwarf2_cu
*cu
,
19530 struct dwarf2_section_info
*str_section
,
19531 struct dwarf2_section_info
*str_offsets_section
,
19532 ULONGEST str_offsets_base
, ULONGEST str_index
)
19534 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19535 struct objfile
*objfile
= per_objfile
->objfile
;
19536 const char *objf_name
= objfile_name (objfile
);
19537 bfd
*abfd
= objfile
->obfd
;
19538 const gdb_byte
*info_ptr
;
19539 ULONGEST str_offset
;
19540 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19542 str_section
->read (objfile
);
19543 str_offsets_section
->read (objfile
);
19544 if (str_section
->buffer
== NULL
)
19545 error (_("%s used without %s section"
19546 " in CU at offset %s [in module %s]"),
19547 form_name
, str_section
->get_name (),
19548 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19549 if (str_offsets_section
->buffer
== NULL
)
19550 error (_("%s used without %s section"
19551 " in CU at offset %s [in module %s]"),
19552 form_name
, str_section
->get_name (),
19553 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19554 info_ptr
= (str_offsets_section
->buffer
19556 + str_index
* cu
->header
.offset_size
);
19557 if (cu
->header
.offset_size
== 4)
19558 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19560 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19561 if (str_offset
>= str_section
->size
)
19562 error (_("Offset from %s pointing outside of"
19563 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19564 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19565 return (const char *) (str_section
->buffer
+ str_offset
);
19568 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19570 static const char *
19571 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19573 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19574 ? reader
->cu
->header
.addr_size
: 0;
19575 return read_str_index (reader
->cu
,
19576 &reader
->dwo_file
->sections
.str
,
19577 &reader
->dwo_file
->sections
.str_offsets
,
19578 str_offsets_base
, str_index
);
19581 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19583 static const char *
19584 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19586 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19587 const char *objf_name
= objfile_name (objfile
);
19588 static const char form_name
[] = "DW_FORM_GNU_str_index";
19589 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19591 if (!cu
->str_offsets_base
.has_value ())
19592 error (_("%s used in Fission stub without %s"
19593 " in CU at offset 0x%lx [in module %s]"),
19594 form_name
, str_offsets_attr_name
,
19595 (long) cu
->header
.offset_size
, objf_name
);
19597 return read_str_index (cu
,
19598 &cu
->per_objfile
->per_bfd
->str
,
19599 &cu
->per_objfile
->per_bfd
->str_offsets
,
19600 *cu
->str_offsets_base
, str_index
);
19603 /* Return the length of an LEB128 number in BUF. */
19606 leb128_size (const gdb_byte
*buf
)
19608 const gdb_byte
*begin
= buf
;
19614 if ((byte
& 128) == 0)
19615 return buf
- begin
;
19620 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19629 cu
->language
= language_c
;
19632 case DW_LANG_C_plus_plus
:
19633 case DW_LANG_C_plus_plus_11
:
19634 case DW_LANG_C_plus_plus_14
:
19635 cu
->language
= language_cplus
;
19638 cu
->language
= language_d
;
19640 case DW_LANG_Fortran77
:
19641 case DW_LANG_Fortran90
:
19642 case DW_LANG_Fortran95
:
19643 case DW_LANG_Fortran03
:
19644 case DW_LANG_Fortran08
:
19645 cu
->language
= language_fortran
;
19648 cu
->language
= language_go
;
19650 case DW_LANG_Mips_Assembler
:
19651 cu
->language
= language_asm
;
19653 case DW_LANG_Ada83
:
19654 case DW_LANG_Ada95
:
19655 cu
->language
= language_ada
;
19657 case DW_LANG_Modula2
:
19658 cu
->language
= language_m2
;
19660 case DW_LANG_Pascal83
:
19661 cu
->language
= language_pascal
;
19664 cu
->language
= language_objc
;
19667 case DW_LANG_Rust_old
:
19668 cu
->language
= language_rust
;
19670 case DW_LANG_Cobol74
:
19671 case DW_LANG_Cobol85
:
19673 cu
->language
= language_minimal
;
19676 cu
->language_defn
= language_def (cu
->language
);
19679 /* Return the named attribute or NULL if not there. */
19681 static struct attribute
*
19682 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19687 struct attribute
*spec
= NULL
;
19689 for (i
= 0; i
< die
->num_attrs
; ++i
)
19691 if (die
->attrs
[i
].name
== name
)
19692 return &die
->attrs
[i
];
19693 if (die
->attrs
[i
].name
== DW_AT_specification
19694 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19695 spec
= &die
->attrs
[i
];
19701 die
= follow_die_ref (die
, spec
, &cu
);
19707 /* Return the string associated with a string-typed attribute, or NULL if it
19708 is either not found or is of an incorrect type. */
19710 static const char *
19711 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19713 struct attribute
*attr
;
19714 const char *str
= NULL
;
19716 attr
= dwarf2_attr (die
, name
, cu
);
19720 str
= attr
->value_as_string ();
19721 if (str
== nullptr)
19722 complaint (_("string type expected for attribute %s for "
19723 "DIE at %s in module %s"),
19724 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19725 objfile_name (cu
->per_objfile
->objfile
));
19731 /* Return the dwo name or NULL if not present. If present, it is in either
19732 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19733 static const char *
19734 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19736 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19737 if (dwo_name
== nullptr)
19738 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19742 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19743 and holds a non-zero value. This function should only be used for
19744 DW_FORM_flag or DW_FORM_flag_present attributes. */
19747 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19749 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19751 return (attr
&& DW_UNSND (attr
));
19755 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19757 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19758 which value is non-zero. However, we have to be careful with
19759 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19760 (via dwarf2_flag_true_p) follows this attribute. So we may
19761 end up accidently finding a declaration attribute that belongs
19762 to a different DIE referenced by the specification attribute,
19763 even though the given DIE does not have a declaration attribute. */
19764 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19765 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19768 /* Return the die giving the specification for DIE, if there is
19769 one. *SPEC_CU is the CU containing DIE on input, and the CU
19770 containing the return value on output. If there is no
19771 specification, but there is an abstract origin, that is
19774 static struct die_info
*
19775 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19777 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19780 if (spec_attr
== NULL
)
19781 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19783 if (spec_attr
== NULL
)
19786 return follow_die_ref (die
, spec_attr
, spec_cu
);
19789 /* Stub for free_line_header to match void * callback types. */
19792 free_line_header_voidp (void *arg
)
19794 struct line_header
*lh
= (struct line_header
*) arg
;
19799 /* A convenience function to find the proper .debug_line section for a CU. */
19801 static struct dwarf2_section_info
*
19802 get_debug_line_section (struct dwarf2_cu
*cu
)
19804 struct dwarf2_section_info
*section
;
19805 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19807 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19809 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19810 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19811 else if (cu
->per_cu
->is_dwz
)
19813 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19815 section
= &dwz
->line
;
19818 section
= &per_objfile
->per_bfd
->line
;
19823 /* Read the statement program header starting at OFFSET in
19824 .debug_line, or .debug_line.dwo. Return a pointer
19825 to a struct line_header, allocated using xmalloc.
19826 Returns NULL if there is a problem reading the header, e.g., if it
19827 has a version we don't understand.
19829 NOTE: the strings in the include directory and file name tables of
19830 the returned object point into the dwarf line section buffer,
19831 and must not be freed. */
19833 static line_header_up
19834 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19836 struct dwarf2_section_info
*section
;
19837 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19839 section
= get_debug_line_section (cu
);
19840 section
->read (per_objfile
->objfile
);
19841 if (section
->buffer
== NULL
)
19843 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19844 complaint (_("missing .debug_line.dwo section"));
19846 complaint (_("missing .debug_line section"));
19850 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19851 per_objfile
, section
, &cu
->header
);
19854 /* Subroutine of dwarf_decode_lines to simplify it.
19855 Return the file name of the psymtab for the given file_entry.
19856 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19857 If space for the result is malloc'd, *NAME_HOLDER will be set.
19858 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19860 static const char *
19861 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19862 const dwarf2_psymtab
*pst
,
19863 const char *comp_dir
,
19864 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19866 const char *include_name
= fe
.name
;
19867 const char *include_name_to_compare
= include_name
;
19868 const char *pst_filename
;
19871 const char *dir_name
= fe
.include_dir (lh
);
19873 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19874 if (!IS_ABSOLUTE_PATH (include_name
)
19875 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19877 /* Avoid creating a duplicate psymtab for PST.
19878 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19879 Before we do the comparison, however, we need to account
19880 for DIR_NAME and COMP_DIR.
19881 First prepend dir_name (if non-NULL). If we still don't
19882 have an absolute path prepend comp_dir (if non-NULL).
19883 However, the directory we record in the include-file's
19884 psymtab does not contain COMP_DIR (to match the
19885 corresponding symtab(s)).
19890 bash$ gcc -g ./hello.c
19891 include_name = "hello.c"
19893 DW_AT_comp_dir = comp_dir = "/tmp"
19894 DW_AT_name = "./hello.c"
19898 if (dir_name
!= NULL
)
19900 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19901 include_name
, (char *) NULL
));
19902 include_name
= name_holder
->get ();
19903 include_name_to_compare
= include_name
;
19905 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19907 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19908 include_name
, (char *) NULL
));
19909 include_name_to_compare
= hold_compare
.get ();
19913 pst_filename
= pst
->filename
;
19914 gdb::unique_xmalloc_ptr
<char> copied_name
;
19915 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19917 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19918 pst_filename
, (char *) NULL
));
19919 pst_filename
= copied_name
.get ();
19922 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19926 return include_name
;
19929 /* State machine to track the state of the line number program. */
19931 class lnp_state_machine
19934 /* Initialize a machine state for the start of a line number
19936 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19937 bool record_lines_p
);
19939 file_entry
*current_file ()
19941 /* lh->file_names is 0-based, but the file name numbers in the
19942 statement program are 1-based. */
19943 return m_line_header
->file_name_at (m_file
);
19946 /* Record the line in the state machine. END_SEQUENCE is true if
19947 we're processing the end of a sequence. */
19948 void record_line (bool end_sequence
);
19950 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19951 nop-out rest of the lines in this sequence. */
19952 void check_line_address (struct dwarf2_cu
*cu
,
19953 const gdb_byte
*line_ptr
,
19954 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19956 void handle_set_discriminator (unsigned int discriminator
)
19958 m_discriminator
= discriminator
;
19959 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19962 /* Handle DW_LNE_set_address. */
19963 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19966 address
+= baseaddr
;
19967 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19970 /* Handle DW_LNS_advance_pc. */
19971 void handle_advance_pc (CORE_ADDR adjust
);
19973 /* Handle a special opcode. */
19974 void handle_special_opcode (unsigned char op_code
);
19976 /* Handle DW_LNS_advance_line. */
19977 void handle_advance_line (int line_delta
)
19979 advance_line (line_delta
);
19982 /* Handle DW_LNS_set_file. */
19983 void handle_set_file (file_name_index file
);
19985 /* Handle DW_LNS_negate_stmt. */
19986 void handle_negate_stmt ()
19988 m_is_stmt
= !m_is_stmt
;
19991 /* Handle DW_LNS_const_add_pc. */
19992 void handle_const_add_pc ();
19994 /* Handle DW_LNS_fixed_advance_pc. */
19995 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19997 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20001 /* Handle DW_LNS_copy. */
20002 void handle_copy ()
20004 record_line (false);
20005 m_discriminator
= 0;
20008 /* Handle DW_LNE_end_sequence. */
20009 void handle_end_sequence ()
20011 m_currently_recording_lines
= true;
20015 /* Advance the line by LINE_DELTA. */
20016 void advance_line (int line_delta
)
20018 m_line
+= line_delta
;
20020 if (line_delta
!= 0)
20021 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20024 struct dwarf2_cu
*m_cu
;
20026 gdbarch
*m_gdbarch
;
20028 /* True if we're recording lines.
20029 Otherwise we're building partial symtabs and are just interested in
20030 finding include files mentioned by the line number program. */
20031 bool m_record_lines_p
;
20033 /* The line number header. */
20034 line_header
*m_line_header
;
20036 /* These are part of the standard DWARF line number state machine,
20037 and initialized according to the DWARF spec. */
20039 unsigned char m_op_index
= 0;
20040 /* The line table index of the current file. */
20041 file_name_index m_file
= 1;
20042 unsigned int m_line
= 1;
20044 /* These are initialized in the constructor. */
20046 CORE_ADDR m_address
;
20048 unsigned int m_discriminator
;
20050 /* Additional bits of state we need to track. */
20052 /* The last file that we called dwarf2_start_subfile for.
20053 This is only used for TLLs. */
20054 unsigned int m_last_file
= 0;
20055 /* The last file a line number was recorded for. */
20056 struct subfile
*m_last_subfile
= NULL
;
20058 /* The address of the last line entry. */
20059 CORE_ADDR m_last_address
;
20061 /* Set to true when a previous line at the same address (using
20062 m_last_address) had m_is_stmt true. This is reset to false when a
20063 line entry at a new address (m_address different to m_last_address) is
20065 bool m_stmt_at_address
= false;
20067 /* When true, record the lines we decode. */
20068 bool m_currently_recording_lines
= false;
20070 /* The last line number that was recorded, used to coalesce
20071 consecutive entries for the same line. This can happen, for
20072 example, when discriminators are present. PR 17276. */
20073 unsigned int m_last_line
= 0;
20074 bool m_line_has_non_zero_discriminator
= false;
20078 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20080 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20081 / m_line_header
->maximum_ops_per_instruction
)
20082 * m_line_header
->minimum_instruction_length
);
20083 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20084 m_op_index
= ((m_op_index
+ adjust
)
20085 % m_line_header
->maximum_ops_per_instruction
);
20089 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20091 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20092 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20093 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20094 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20095 / m_line_header
->maximum_ops_per_instruction
)
20096 * m_line_header
->minimum_instruction_length
);
20097 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20098 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20099 % m_line_header
->maximum_ops_per_instruction
);
20101 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20102 advance_line (line_delta
);
20103 record_line (false);
20104 m_discriminator
= 0;
20108 lnp_state_machine::handle_set_file (file_name_index file
)
20112 const file_entry
*fe
= current_file ();
20114 dwarf2_debug_line_missing_file_complaint ();
20115 else if (m_record_lines_p
)
20117 const char *dir
= fe
->include_dir (m_line_header
);
20119 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20120 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20121 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20126 lnp_state_machine::handle_const_add_pc ()
20129 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20132 = (((m_op_index
+ adjust
)
20133 / m_line_header
->maximum_ops_per_instruction
)
20134 * m_line_header
->minimum_instruction_length
);
20136 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20137 m_op_index
= ((m_op_index
+ adjust
)
20138 % m_line_header
->maximum_ops_per_instruction
);
20141 /* Return non-zero if we should add LINE to the line number table.
20142 LINE is the line to add, LAST_LINE is the last line that was added,
20143 LAST_SUBFILE is the subfile for LAST_LINE.
20144 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20145 had a non-zero discriminator.
20147 We have to be careful in the presence of discriminators.
20148 E.g., for this line:
20150 for (i = 0; i < 100000; i++);
20152 clang can emit four line number entries for that one line,
20153 each with a different discriminator.
20154 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20156 However, we want gdb to coalesce all four entries into one.
20157 Otherwise the user could stepi into the middle of the line and
20158 gdb would get confused about whether the pc really was in the
20159 middle of the line.
20161 Things are further complicated by the fact that two consecutive
20162 line number entries for the same line is a heuristic used by gcc
20163 to denote the end of the prologue. So we can't just discard duplicate
20164 entries, we have to be selective about it. The heuristic we use is
20165 that we only collapse consecutive entries for the same line if at least
20166 one of those entries has a non-zero discriminator. PR 17276.
20168 Note: Addresses in the line number state machine can never go backwards
20169 within one sequence, thus this coalescing is ok. */
20172 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20173 unsigned int line
, unsigned int last_line
,
20174 int line_has_non_zero_discriminator
,
20175 struct subfile
*last_subfile
)
20177 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20179 if (line
!= last_line
)
20181 /* Same line for the same file that we've seen already.
20182 As a last check, for pr 17276, only record the line if the line
20183 has never had a non-zero discriminator. */
20184 if (!line_has_non_zero_discriminator
)
20189 /* Use the CU's builder to record line number LINE beginning at
20190 address ADDRESS in the line table of subfile SUBFILE. */
20193 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20194 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20195 struct dwarf2_cu
*cu
)
20197 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20199 if (dwarf_line_debug
)
20201 fprintf_unfiltered (gdb_stdlog
,
20202 "Recording line %u, file %s, address %s\n",
20203 line
, lbasename (subfile
->name
),
20204 paddress (gdbarch
, address
));
20208 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20211 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20212 Mark the end of a set of line number records.
20213 The arguments are the same as for dwarf_record_line_1.
20214 If SUBFILE is NULL the request is ignored. */
20217 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20218 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20220 if (subfile
== NULL
)
20223 if (dwarf_line_debug
)
20225 fprintf_unfiltered (gdb_stdlog
,
20226 "Finishing current line, file %s, address %s\n",
20227 lbasename (subfile
->name
),
20228 paddress (gdbarch
, address
));
20231 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20235 lnp_state_machine::record_line (bool end_sequence
)
20237 if (dwarf_line_debug
)
20239 fprintf_unfiltered (gdb_stdlog
,
20240 "Processing actual line %u: file %u,"
20241 " address %s, is_stmt %u, discrim %u%s\n",
20243 paddress (m_gdbarch
, m_address
),
20244 m_is_stmt
, m_discriminator
,
20245 (end_sequence
? "\t(end sequence)" : ""));
20248 file_entry
*fe
= current_file ();
20251 dwarf2_debug_line_missing_file_complaint ();
20252 /* For now we ignore lines not starting on an instruction boundary.
20253 But not when processing end_sequence for compatibility with the
20254 previous version of the code. */
20255 else if (m_op_index
== 0 || end_sequence
)
20257 fe
->included_p
= 1;
20258 if (m_record_lines_p
)
20260 /* When we switch files we insert an end maker in the first file,
20261 switch to the second file and add a new line entry. The
20262 problem is that the end marker inserted in the first file will
20263 discard any previous line entries at the same address. If the
20264 line entries in the first file are marked as is-stmt, while
20265 the new line in the second file is non-stmt, then this means
20266 the end marker will discard is-stmt lines so we can have a
20267 non-stmt line. This means that there are less addresses at
20268 which the user can insert a breakpoint.
20270 To improve this we track the last address in m_last_address,
20271 and whether we have seen an is-stmt at this address. Then
20272 when switching files, if we have seen a stmt at the current
20273 address, and we are switching to create a non-stmt line, then
20274 discard the new line. */
20276 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
20277 bool ignore_this_line
20278 = (file_changed
&& !end_sequence
&& m_last_address
== m_address
20279 && !m_is_stmt
&& m_stmt_at_address
);
20281 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
20283 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20284 m_currently_recording_lines
? m_cu
: nullptr);
20287 if (!end_sequence
&& !ignore_this_line
)
20289 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20291 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20292 m_line_has_non_zero_discriminator
,
20295 buildsym_compunit
*builder
= m_cu
->get_builder ();
20296 dwarf_record_line_1 (m_gdbarch
,
20297 builder
->get_current_subfile (),
20298 m_line
, m_address
, is_stmt
,
20299 m_currently_recording_lines
? m_cu
: nullptr);
20301 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20302 m_last_line
= m_line
;
20307 /* Track whether we have seen any m_is_stmt true at m_address in case we
20308 have multiple line table entries all at m_address. */
20309 if (m_last_address
!= m_address
)
20311 m_stmt_at_address
= false;
20312 m_last_address
= m_address
;
20314 m_stmt_at_address
|= m_is_stmt
;
20317 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20318 line_header
*lh
, bool record_lines_p
)
20322 m_record_lines_p
= record_lines_p
;
20323 m_line_header
= lh
;
20325 m_currently_recording_lines
= true;
20327 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20328 was a line entry for it so that the backend has a chance to adjust it
20329 and also record it in case it needs it. This is currently used by MIPS
20330 code, cf. `mips_adjust_dwarf2_line'. */
20331 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20332 m_is_stmt
= lh
->default_is_stmt
;
20333 m_discriminator
= 0;
20335 m_last_address
= m_address
;
20336 m_stmt_at_address
= false;
20340 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20341 const gdb_byte
*line_ptr
,
20342 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20344 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20345 the pc range of the CU. However, we restrict the test to only ADDRESS
20346 values of zero to preserve GDB's previous behaviour which is to handle
20347 the specific case of a function being GC'd by the linker. */
20349 if (address
== 0 && address
< unrelocated_lowpc
)
20351 /* This line table is for a function which has been
20352 GCd by the linker. Ignore it. PR gdb/12528 */
20354 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20355 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20357 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20358 line_offset
, objfile_name (objfile
));
20359 m_currently_recording_lines
= false;
20360 /* Note: m_currently_recording_lines is left as false until we see
20361 DW_LNE_end_sequence. */
20365 /* Subroutine of dwarf_decode_lines to simplify it.
20366 Process the line number information in LH.
20367 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20368 program in order to set included_p for every referenced header. */
20371 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20372 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20374 const gdb_byte
*line_ptr
, *extended_end
;
20375 const gdb_byte
*line_end
;
20376 unsigned int bytes_read
, extended_len
;
20377 unsigned char op_code
, extended_op
;
20378 CORE_ADDR baseaddr
;
20379 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20380 bfd
*abfd
= objfile
->obfd
;
20381 struct gdbarch
*gdbarch
= objfile
->arch ();
20382 /* True if we're recording line info (as opposed to building partial
20383 symtabs and just interested in finding include files mentioned by
20384 the line number program). */
20385 bool record_lines_p
= !decode_for_pst_p
;
20387 baseaddr
= objfile
->text_section_offset ();
20389 line_ptr
= lh
->statement_program_start
;
20390 line_end
= lh
->statement_program_end
;
20392 /* Read the statement sequences until there's nothing left. */
20393 while (line_ptr
< line_end
)
20395 /* The DWARF line number program state machine. Reset the state
20396 machine at the start of each sequence. */
20397 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20398 bool end_sequence
= false;
20400 if (record_lines_p
)
20402 /* Start a subfile for the current file of the state
20404 const file_entry
*fe
= state_machine
.current_file ();
20407 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20410 /* Decode the table. */
20411 while (line_ptr
< line_end
&& !end_sequence
)
20413 op_code
= read_1_byte (abfd
, line_ptr
);
20416 if (op_code
>= lh
->opcode_base
)
20418 /* Special opcode. */
20419 state_machine
.handle_special_opcode (op_code
);
20421 else switch (op_code
)
20423 case DW_LNS_extended_op
:
20424 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20426 line_ptr
+= bytes_read
;
20427 extended_end
= line_ptr
+ extended_len
;
20428 extended_op
= read_1_byte (abfd
, line_ptr
);
20430 switch (extended_op
)
20432 case DW_LNE_end_sequence
:
20433 state_machine
.handle_end_sequence ();
20434 end_sequence
= true;
20436 case DW_LNE_set_address
:
20439 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20440 line_ptr
+= bytes_read
;
20442 state_machine
.check_line_address (cu
, line_ptr
,
20443 lowpc
- baseaddr
, address
);
20444 state_machine
.handle_set_address (baseaddr
, address
);
20447 case DW_LNE_define_file
:
20449 const char *cur_file
;
20450 unsigned int mod_time
, length
;
20453 cur_file
= read_direct_string (abfd
, line_ptr
,
20455 line_ptr
+= bytes_read
;
20456 dindex
= (dir_index
)
20457 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20458 line_ptr
+= bytes_read
;
20460 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20461 line_ptr
+= bytes_read
;
20463 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20464 line_ptr
+= bytes_read
;
20465 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20468 case DW_LNE_set_discriminator
:
20470 /* The discriminator is not interesting to the
20471 debugger; just ignore it. We still need to
20472 check its value though:
20473 if there are consecutive entries for the same
20474 (non-prologue) line we want to coalesce them.
20477 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20478 line_ptr
+= bytes_read
;
20480 state_machine
.handle_set_discriminator (discr
);
20484 complaint (_("mangled .debug_line section"));
20487 /* Make sure that we parsed the extended op correctly. If e.g.
20488 we expected a different address size than the producer used,
20489 we may have read the wrong number of bytes. */
20490 if (line_ptr
!= extended_end
)
20492 complaint (_("mangled .debug_line section"));
20497 state_machine
.handle_copy ();
20499 case DW_LNS_advance_pc
:
20502 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20503 line_ptr
+= bytes_read
;
20505 state_machine
.handle_advance_pc (adjust
);
20508 case DW_LNS_advance_line
:
20511 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20512 line_ptr
+= bytes_read
;
20514 state_machine
.handle_advance_line (line_delta
);
20517 case DW_LNS_set_file
:
20519 file_name_index file
20520 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20522 line_ptr
+= bytes_read
;
20524 state_machine
.handle_set_file (file
);
20527 case DW_LNS_set_column
:
20528 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20529 line_ptr
+= bytes_read
;
20531 case DW_LNS_negate_stmt
:
20532 state_machine
.handle_negate_stmt ();
20534 case DW_LNS_set_basic_block
:
20536 /* Add to the address register of the state machine the
20537 address increment value corresponding to special opcode
20538 255. I.e., this value is scaled by the minimum
20539 instruction length since special opcode 255 would have
20540 scaled the increment. */
20541 case DW_LNS_const_add_pc
:
20542 state_machine
.handle_const_add_pc ();
20544 case DW_LNS_fixed_advance_pc
:
20546 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20549 state_machine
.handle_fixed_advance_pc (addr_adj
);
20554 /* Unknown standard opcode, ignore it. */
20557 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20559 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20560 line_ptr
+= bytes_read
;
20567 dwarf2_debug_line_missing_end_sequence_complaint ();
20569 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20570 in which case we still finish recording the last line). */
20571 state_machine
.record_line (true);
20575 /* Decode the Line Number Program (LNP) for the given line_header
20576 structure and CU. The actual information extracted and the type
20577 of structures created from the LNP depends on the value of PST.
20579 1. If PST is NULL, then this procedure uses the data from the program
20580 to create all necessary symbol tables, and their linetables.
20582 2. If PST is not NULL, this procedure reads the program to determine
20583 the list of files included by the unit represented by PST, and
20584 builds all the associated partial symbol tables.
20586 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20587 It is used for relative paths in the line table.
20588 NOTE: When processing partial symtabs (pst != NULL),
20589 comp_dir == pst->dirname.
20591 NOTE: It is important that psymtabs have the same file name (via strcmp)
20592 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20593 symtab we don't use it in the name of the psymtabs we create.
20594 E.g. expand_line_sal requires this when finding psymtabs to expand.
20595 A good testcase for this is mb-inline.exp.
20597 LOWPC is the lowest address in CU (or 0 if not known).
20599 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20600 for its PC<->lines mapping information. Otherwise only the filename
20601 table is read in. */
20604 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20605 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20606 CORE_ADDR lowpc
, int decode_mapping
)
20608 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20609 const int decode_for_pst_p
= (pst
!= NULL
);
20611 if (decode_mapping
)
20612 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20614 if (decode_for_pst_p
)
20616 /* Now that we're done scanning the Line Header Program, we can
20617 create the psymtab of each included file. */
20618 for (auto &file_entry
: lh
->file_names ())
20619 if (file_entry
.included_p
== 1)
20621 gdb::unique_xmalloc_ptr
<char> name_holder
;
20622 const char *include_name
=
20623 psymtab_include_file_name (lh
, file_entry
, pst
,
20624 comp_dir
, &name_holder
);
20625 if (include_name
!= NULL
)
20626 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20631 /* Make sure a symtab is created for every file, even files
20632 which contain only variables (i.e. no code with associated
20634 buildsym_compunit
*builder
= cu
->get_builder ();
20635 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20637 for (auto &fe
: lh
->file_names ())
20639 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20640 if (builder
->get_current_subfile ()->symtab
== NULL
)
20642 builder
->get_current_subfile ()->symtab
20643 = allocate_symtab (cust
,
20644 builder
->get_current_subfile ()->name
);
20646 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20651 /* Start a subfile for DWARF. FILENAME is the name of the file and
20652 DIRNAME the name of the source directory which contains FILENAME
20653 or NULL if not known.
20654 This routine tries to keep line numbers from identical absolute and
20655 relative file names in a common subfile.
20657 Using the `list' example from the GDB testsuite, which resides in
20658 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20659 of /srcdir/list0.c yields the following debugging information for list0.c:
20661 DW_AT_name: /srcdir/list0.c
20662 DW_AT_comp_dir: /compdir
20663 files.files[0].name: list0.h
20664 files.files[0].dir: /srcdir
20665 files.files[1].name: list0.c
20666 files.files[1].dir: /srcdir
20668 The line number information for list0.c has to end up in a single
20669 subfile, so that `break /srcdir/list0.c:1' works as expected.
20670 start_subfile will ensure that this happens provided that we pass the
20671 concatenation of files.files[1].dir and files.files[1].name as the
20675 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20676 const char *dirname
)
20678 gdb::unique_xmalloc_ptr
<char> copy
;
20680 /* In order not to lose the line information directory,
20681 we concatenate it to the filename when it makes sense.
20682 Note that the Dwarf3 standard says (speaking of filenames in line
20683 information): ``The directory index is ignored for file names
20684 that represent full path names''. Thus ignoring dirname in the
20685 `else' branch below isn't an issue. */
20687 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20689 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20690 filename
= copy
.get ();
20693 cu
->get_builder ()->start_subfile (filename
);
20696 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20697 buildsym_compunit constructor. */
20699 struct compunit_symtab
*
20700 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20703 gdb_assert (m_builder
== nullptr);
20705 m_builder
.reset (new struct buildsym_compunit
20706 (this->per_objfile
->objfile
,
20707 name
, comp_dir
, language
, low_pc
));
20709 list_in_scope
= get_builder ()->get_file_symbols ();
20711 get_builder ()->record_debugformat ("DWARF 2");
20712 get_builder ()->record_producer (producer
);
20714 processing_has_namespace_info
= false;
20716 return get_builder ()->get_compunit_symtab ();
20720 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20721 struct dwarf2_cu
*cu
)
20723 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20724 struct comp_unit_head
*cu_header
= &cu
->header
;
20726 /* NOTE drow/2003-01-30: There used to be a comment and some special
20727 code here to turn a symbol with DW_AT_external and a
20728 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20729 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20730 with some versions of binutils) where shared libraries could have
20731 relocations against symbols in their debug information - the
20732 minimal symbol would have the right address, but the debug info
20733 would not. It's no longer necessary, because we will explicitly
20734 apply relocations when we read in the debug information now. */
20736 /* A DW_AT_location attribute with no contents indicates that a
20737 variable has been optimized away. */
20738 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20740 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20744 /* Handle one degenerate form of location expression specially, to
20745 preserve GDB's previous behavior when section offsets are
20746 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20747 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20749 if (attr
->form_is_block ()
20750 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20751 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20752 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20753 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20754 && (DW_BLOCK (attr
)->size
20755 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20757 unsigned int dummy
;
20759 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20760 SET_SYMBOL_VALUE_ADDRESS
20761 (sym
, cu
->header
.read_address (objfile
->obfd
,
20762 DW_BLOCK (attr
)->data
+ 1,
20765 SET_SYMBOL_VALUE_ADDRESS
20766 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20768 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20769 fixup_symbol_section (sym
, objfile
);
20770 SET_SYMBOL_VALUE_ADDRESS
20772 SYMBOL_VALUE_ADDRESS (sym
)
20773 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20777 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20778 expression evaluator, and use LOC_COMPUTED only when necessary
20779 (i.e. when the value of a register or memory location is
20780 referenced, or a thread-local block, etc.). Then again, it might
20781 not be worthwhile. I'm assuming that it isn't unless performance
20782 or memory numbers show me otherwise. */
20784 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20786 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20787 cu
->has_loclist
= true;
20790 /* Given a pointer to a DWARF information entry, figure out if we need
20791 to make a symbol table entry for it, and if so, create a new entry
20792 and return a pointer to it.
20793 If TYPE is NULL, determine symbol type from the die, otherwise
20794 used the passed type.
20795 If SPACE is not NULL, use it to hold the new symbol. If it is
20796 NULL, allocate a new symbol on the objfile's obstack. */
20798 static struct symbol
*
20799 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20800 struct symbol
*space
)
20802 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20803 struct objfile
*objfile
= per_objfile
->objfile
;
20804 struct gdbarch
*gdbarch
= objfile
->arch ();
20805 struct symbol
*sym
= NULL
;
20807 struct attribute
*attr
= NULL
;
20808 struct attribute
*attr2
= NULL
;
20809 CORE_ADDR baseaddr
;
20810 struct pending
**list_to_add
= NULL
;
20812 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20814 baseaddr
= objfile
->text_section_offset ();
20816 name
= dwarf2_name (die
, cu
);
20819 int suppress_add
= 0;
20824 sym
= new (&objfile
->objfile_obstack
) symbol
;
20825 OBJSTAT (objfile
, n_syms
++);
20827 /* Cache this symbol's name and the name's demangled form (if any). */
20828 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20829 /* Fortran does not have mangling standard and the mangling does differ
20830 between gfortran, iFort etc. */
20831 const char *physname
20832 = (cu
->language
== language_fortran
20833 ? dwarf2_full_name (name
, die
, cu
)
20834 : dwarf2_physname (name
, die
, cu
));
20835 const char *linkagename
= dw2_linkage_name (die
, cu
);
20837 if (linkagename
== nullptr || cu
->language
== language_ada
)
20838 sym
->set_linkage_name (physname
);
20841 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20842 sym
->set_linkage_name (linkagename
);
20845 /* Default assumptions.
20846 Use the passed type or decode it from the die. */
20847 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20848 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20850 SYMBOL_TYPE (sym
) = type
;
20852 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20853 attr
= dwarf2_attr (die
,
20854 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20856 if (attr
!= nullptr)
20858 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20861 attr
= dwarf2_attr (die
,
20862 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20864 if (attr
!= nullptr)
20866 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20867 struct file_entry
*fe
;
20869 if (cu
->line_header
!= NULL
)
20870 fe
= cu
->line_header
->file_name_at (file_index
);
20875 complaint (_("file index out of range"));
20877 symbol_set_symtab (sym
, fe
->symtab
);
20883 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20884 if (attr
!= nullptr)
20888 addr
= attr
->value_as_address ();
20889 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20890 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20892 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20893 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20894 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20895 add_symbol_to_list (sym
, cu
->list_in_scope
);
20897 case DW_TAG_subprogram
:
20898 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20900 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20901 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20902 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20903 || cu
->language
== language_ada
20904 || cu
->language
== language_fortran
)
20906 /* Subprograms marked external are stored as a global symbol.
20907 Ada and Fortran subprograms, whether marked external or
20908 not, are always stored as a global symbol, because we want
20909 to be able to access them globally. For instance, we want
20910 to be able to break on a nested subprogram without having
20911 to specify the context. */
20912 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20916 list_to_add
= cu
->list_in_scope
;
20919 case DW_TAG_inlined_subroutine
:
20920 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20922 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20923 SYMBOL_INLINED (sym
) = 1;
20924 list_to_add
= cu
->list_in_scope
;
20926 case DW_TAG_template_value_param
:
20928 /* Fall through. */
20929 case DW_TAG_constant
:
20930 case DW_TAG_variable
:
20931 case DW_TAG_member
:
20932 /* Compilation with minimal debug info may result in
20933 variables with missing type entries. Change the
20934 misleading `void' type to something sensible. */
20935 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20936 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20938 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20939 /* In the case of DW_TAG_member, we should only be called for
20940 static const members. */
20941 if (die
->tag
== DW_TAG_member
)
20943 /* dwarf2_add_field uses die_is_declaration,
20944 so we do the same. */
20945 gdb_assert (die_is_declaration (die
, cu
));
20948 if (attr
!= nullptr)
20950 dwarf2_const_value (attr
, sym
, cu
);
20951 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20954 if (attr2
&& (DW_UNSND (attr2
) != 0))
20955 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20957 list_to_add
= cu
->list_in_scope
;
20961 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20962 if (attr
!= nullptr)
20964 var_decode_location (attr
, sym
, cu
);
20965 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20967 /* Fortran explicitly imports any global symbols to the local
20968 scope by DW_TAG_common_block. */
20969 if (cu
->language
== language_fortran
&& die
->parent
20970 && die
->parent
->tag
== DW_TAG_common_block
)
20973 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20974 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20975 && !per_objfile
->per_bfd
->has_section_at_zero
)
20977 /* When a static variable is eliminated by the linker,
20978 the corresponding debug information is not stripped
20979 out, but the variable address is set to null;
20980 do not add such variables into symbol table. */
20982 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20984 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20985 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20986 && per_objfile
->per_bfd
->can_copy
)
20988 /* A global static variable might be subject to
20989 copy relocation. We first check for a local
20990 minsym, though, because maybe the symbol was
20991 marked hidden, in which case this would not
20993 bound_minimal_symbol found
20994 = (lookup_minimal_symbol_linkage
20995 (sym
->linkage_name (), objfile
));
20996 if (found
.minsym
!= nullptr)
20997 sym
->maybe_copied
= 1;
21000 /* A variable with DW_AT_external is never static,
21001 but it may be block-scoped. */
21003 = ((cu
->list_in_scope
21004 == cu
->get_builder ()->get_file_symbols ())
21005 ? cu
->get_builder ()->get_global_symbols ()
21006 : cu
->list_in_scope
);
21009 list_to_add
= cu
->list_in_scope
;
21013 /* We do not know the address of this symbol.
21014 If it is an external symbol and we have type information
21015 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21016 The address of the variable will then be determined from
21017 the minimal symbol table whenever the variable is
21019 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21021 /* Fortran explicitly imports any global symbols to the local
21022 scope by DW_TAG_common_block. */
21023 if (cu
->language
== language_fortran
&& die
->parent
21024 && die
->parent
->tag
== DW_TAG_common_block
)
21026 /* SYMBOL_CLASS doesn't matter here because
21027 read_common_block is going to reset it. */
21029 list_to_add
= cu
->list_in_scope
;
21031 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21032 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21034 /* A variable with DW_AT_external is never static, but it
21035 may be block-scoped. */
21037 = ((cu
->list_in_scope
21038 == cu
->get_builder ()->get_file_symbols ())
21039 ? cu
->get_builder ()->get_global_symbols ()
21040 : cu
->list_in_scope
);
21042 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21044 else if (!die_is_declaration (die
, cu
))
21046 /* Use the default LOC_OPTIMIZED_OUT class. */
21047 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21049 list_to_add
= cu
->list_in_scope
;
21053 case DW_TAG_formal_parameter
:
21055 /* If we are inside a function, mark this as an argument. If
21056 not, we might be looking at an argument to an inlined function
21057 when we do not have enough information to show inlined frames;
21058 pretend it's a local variable in that case so that the user can
21060 struct context_stack
*curr
21061 = cu
->get_builder ()->get_current_context_stack ();
21062 if (curr
!= nullptr && curr
->name
!= nullptr)
21063 SYMBOL_IS_ARGUMENT (sym
) = 1;
21064 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21065 if (attr
!= nullptr)
21067 var_decode_location (attr
, sym
, cu
);
21069 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21070 if (attr
!= nullptr)
21072 dwarf2_const_value (attr
, sym
, cu
);
21075 list_to_add
= cu
->list_in_scope
;
21078 case DW_TAG_unspecified_parameters
:
21079 /* From varargs functions; gdb doesn't seem to have any
21080 interest in this information, so just ignore it for now.
21083 case DW_TAG_template_type_param
:
21085 /* Fall through. */
21086 case DW_TAG_class_type
:
21087 case DW_TAG_interface_type
:
21088 case DW_TAG_structure_type
:
21089 case DW_TAG_union_type
:
21090 case DW_TAG_set_type
:
21091 case DW_TAG_enumeration_type
:
21092 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21093 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21096 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21097 really ever be static objects: otherwise, if you try
21098 to, say, break of a class's method and you're in a file
21099 which doesn't mention that class, it won't work unless
21100 the check for all static symbols in lookup_symbol_aux
21101 saves you. See the OtherFileClass tests in
21102 gdb.c++/namespace.exp. */
21106 buildsym_compunit
*builder
= cu
->get_builder ();
21108 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21109 && cu
->language
== language_cplus
21110 ? builder
->get_global_symbols ()
21111 : cu
->list_in_scope
);
21113 /* The semantics of C++ state that "struct foo {
21114 ... }" also defines a typedef for "foo". */
21115 if (cu
->language
== language_cplus
21116 || cu
->language
== language_ada
21117 || cu
->language
== language_d
21118 || cu
->language
== language_rust
)
21120 /* The symbol's name is already allocated along
21121 with this objfile, so we don't need to
21122 duplicate it for the type. */
21123 if (SYMBOL_TYPE (sym
)->name () == 0)
21124 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21129 case DW_TAG_typedef
:
21130 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21131 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21132 list_to_add
= cu
->list_in_scope
;
21134 case DW_TAG_base_type
:
21135 case DW_TAG_subrange_type
:
21136 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21137 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21138 list_to_add
= cu
->list_in_scope
;
21140 case DW_TAG_enumerator
:
21141 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21142 if (attr
!= nullptr)
21144 dwarf2_const_value (attr
, sym
, cu
);
21147 /* NOTE: carlton/2003-11-10: See comment above in the
21148 DW_TAG_class_type, etc. block. */
21151 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21152 && cu
->language
== language_cplus
21153 ? cu
->get_builder ()->get_global_symbols ()
21154 : cu
->list_in_scope
);
21157 case DW_TAG_imported_declaration
:
21158 case DW_TAG_namespace
:
21159 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21160 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21162 case DW_TAG_module
:
21163 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21164 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21165 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21167 case DW_TAG_common_block
:
21168 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21169 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21170 add_symbol_to_list (sym
, cu
->list_in_scope
);
21173 /* Not a tag we recognize. Hopefully we aren't processing
21174 trash data, but since we must specifically ignore things
21175 we don't recognize, there is nothing else we should do at
21177 complaint (_("unsupported tag: '%s'"),
21178 dwarf_tag_name (die
->tag
));
21184 sym
->hash_next
= objfile
->template_symbols
;
21185 objfile
->template_symbols
= sym
;
21186 list_to_add
= NULL
;
21189 if (list_to_add
!= NULL
)
21190 add_symbol_to_list (sym
, list_to_add
);
21192 /* For the benefit of old versions of GCC, check for anonymous
21193 namespaces based on the demangled name. */
21194 if (!cu
->processing_has_namespace_info
21195 && cu
->language
== language_cplus
)
21196 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21201 /* Given an attr with a DW_FORM_dataN value in host byte order,
21202 zero-extend it as appropriate for the symbol's type. The DWARF
21203 standard (v4) is not entirely clear about the meaning of using
21204 DW_FORM_dataN for a constant with a signed type, where the type is
21205 wider than the data. The conclusion of a discussion on the DWARF
21206 list was that this is unspecified. We choose to always zero-extend
21207 because that is the interpretation long in use by GCC. */
21210 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21211 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21213 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21214 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21215 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21216 LONGEST l
= DW_UNSND (attr
);
21218 if (bits
< sizeof (*value
) * 8)
21220 l
&= ((LONGEST
) 1 << bits
) - 1;
21223 else if (bits
== sizeof (*value
) * 8)
21227 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21228 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21235 /* Read a constant value from an attribute. Either set *VALUE, or if
21236 the value does not fit in *VALUE, set *BYTES - either already
21237 allocated on the objfile obstack, or newly allocated on OBSTACK,
21238 or, set *BATON, if we translated the constant to a location
21242 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21243 const char *name
, struct obstack
*obstack
,
21244 struct dwarf2_cu
*cu
,
21245 LONGEST
*value
, const gdb_byte
**bytes
,
21246 struct dwarf2_locexpr_baton
**baton
)
21248 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21249 struct objfile
*objfile
= per_objfile
->objfile
;
21250 struct comp_unit_head
*cu_header
= &cu
->header
;
21251 struct dwarf_block
*blk
;
21252 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21253 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21259 switch (attr
->form
)
21262 case DW_FORM_addrx
:
21263 case DW_FORM_GNU_addr_index
:
21267 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21268 dwarf2_const_value_length_mismatch_complaint (name
,
21269 cu_header
->addr_size
,
21270 TYPE_LENGTH (type
));
21271 /* Symbols of this form are reasonably rare, so we just
21272 piggyback on the existing location code rather than writing
21273 a new implementation of symbol_computed_ops. */
21274 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21275 (*baton
)->per_objfile
= per_objfile
;
21276 (*baton
)->per_cu
= cu
->per_cu
;
21277 gdb_assert ((*baton
)->per_cu
);
21279 (*baton
)->size
= 2 + cu_header
->addr_size
;
21280 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21281 (*baton
)->data
= data
;
21283 data
[0] = DW_OP_addr
;
21284 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21285 byte_order
, DW_ADDR (attr
));
21286 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21289 case DW_FORM_string
:
21292 case DW_FORM_GNU_str_index
:
21293 case DW_FORM_GNU_strp_alt
:
21294 /* DW_STRING is already allocated on the objfile obstack, point
21296 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21298 case DW_FORM_block1
:
21299 case DW_FORM_block2
:
21300 case DW_FORM_block4
:
21301 case DW_FORM_block
:
21302 case DW_FORM_exprloc
:
21303 case DW_FORM_data16
:
21304 blk
= DW_BLOCK (attr
);
21305 if (TYPE_LENGTH (type
) != blk
->size
)
21306 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21307 TYPE_LENGTH (type
));
21308 *bytes
= blk
->data
;
21311 /* The DW_AT_const_value attributes are supposed to carry the
21312 symbol's value "represented as it would be on the target
21313 architecture." By the time we get here, it's already been
21314 converted to host endianness, so we just need to sign- or
21315 zero-extend it as appropriate. */
21316 case DW_FORM_data1
:
21317 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21319 case DW_FORM_data2
:
21320 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21322 case DW_FORM_data4
:
21323 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21325 case DW_FORM_data8
:
21326 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21329 case DW_FORM_sdata
:
21330 case DW_FORM_implicit_const
:
21331 *value
= DW_SND (attr
);
21334 case DW_FORM_udata
:
21335 *value
= DW_UNSND (attr
);
21339 complaint (_("unsupported const value attribute form: '%s'"),
21340 dwarf_form_name (attr
->form
));
21347 /* Copy constant value from an attribute to a symbol. */
21350 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21351 struct dwarf2_cu
*cu
)
21353 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21355 const gdb_byte
*bytes
;
21356 struct dwarf2_locexpr_baton
*baton
;
21358 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21359 sym
->print_name (),
21360 &objfile
->objfile_obstack
, cu
,
21361 &value
, &bytes
, &baton
);
21365 SYMBOL_LOCATION_BATON (sym
) = baton
;
21366 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21368 else if (bytes
!= NULL
)
21370 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21371 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21375 SYMBOL_VALUE (sym
) = value
;
21376 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21380 /* Return the type of the die in question using its DW_AT_type attribute. */
21382 static struct type
*
21383 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21385 struct attribute
*type_attr
;
21387 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21390 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21391 /* A missing DW_AT_type represents a void type. */
21392 return objfile_type (objfile
)->builtin_void
;
21395 return lookup_die_type (die
, type_attr
, cu
);
21398 /* True iff CU's producer generates GNAT Ada auxiliary information
21399 that allows to find parallel types through that information instead
21400 of having to do expensive parallel lookups by type name. */
21403 need_gnat_info (struct dwarf2_cu
*cu
)
21405 /* Assume that the Ada compiler was GNAT, which always produces
21406 the auxiliary information. */
21407 return (cu
->language
== language_ada
);
21410 /* Return the auxiliary type of the die in question using its
21411 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21412 attribute is not present. */
21414 static struct type
*
21415 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21417 struct attribute
*type_attr
;
21419 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21423 return lookup_die_type (die
, type_attr
, cu
);
21426 /* If DIE has a descriptive_type attribute, then set the TYPE's
21427 descriptive type accordingly. */
21430 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21431 struct dwarf2_cu
*cu
)
21433 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21435 if (descriptive_type
)
21437 ALLOCATE_GNAT_AUX_TYPE (type
);
21438 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21442 /* Return the containing type of the die in question using its
21443 DW_AT_containing_type attribute. */
21445 static struct type
*
21446 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21448 struct attribute
*type_attr
;
21449 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21451 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21453 error (_("Dwarf Error: Problem turning containing type into gdb type "
21454 "[in module %s]"), objfile_name (objfile
));
21456 return lookup_die_type (die
, type_attr
, cu
);
21459 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21461 static struct type
*
21462 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21464 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21465 struct objfile
*objfile
= per_objfile
->objfile
;
21468 std::string message
21469 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21470 objfile_name (objfile
),
21471 sect_offset_str (cu
->header
.sect_off
),
21472 sect_offset_str (die
->sect_off
));
21473 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21475 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21478 /* Look up the type of DIE in CU using its type attribute ATTR.
21479 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21480 DW_AT_containing_type.
21481 If there is no type substitute an error marker. */
21483 static struct type
*
21484 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21485 struct dwarf2_cu
*cu
)
21487 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21488 struct objfile
*objfile
= per_objfile
->objfile
;
21489 struct type
*this_type
;
21491 gdb_assert (attr
->name
== DW_AT_type
21492 || attr
->name
== DW_AT_GNAT_descriptive_type
21493 || attr
->name
== DW_AT_containing_type
);
21495 /* First see if we have it cached. */
21497 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21499 struct dwarf2_per_cu_data
*per_cu
;
21500 sect_offset sect_off
= attr
->get_ref_die_offset ();
21502 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
21503 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
21505 else if (attr
->form_is_ref ())
21507 sect_offset sect_off
= attr
->get_ref_die_offset ();
21509 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
21511 else if (attr
->form
== DW_FORM_ref_sig8
)
21513 ULONGEST signature
= DW_SIGNATURE (attr
);
21515 return get_signatured_type (die
, signature
, cu
);
21519 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21520 " at %s [in module %s]"),
21521 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21522 objfile_name (objfile
));
21523 return build_error_marker_type (cu
, die
);
21526 /* If not cached we need to read it in. */
21528 if (this_type
== NULL
)
21530 struct die_info
*type_die
= NULL
;
21531 struct dwarf2_cu
*type_cu
= cu
;
21533 if (attr
->form_is_ref ())
21534 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21535 if (type_die
== NULL
)
21536 return build_error_marker_type (cu
, die
);
21537 /* If we find the type now, it's probably because the type came
21538 from an inter-CU reference and the type's CU got expanded before
21540 this_type
= read_type_die (type_die
, type_cu
);
21543 /* If we still don't have a type use an error marker. */
21545 if (this_type
== NULL
)
21546 return build_error_marker_type (cu
, die
);
21551 /* Return the type in DIE, CU.
21552 Returns NULL for invalid types.
21554 This first does a lookup in die_type_hash,
21555 and only reads the die in if necessary.
21557 NOTE: This can be called when reading in partial or full symbols. */
21559 static struct type
*
21560 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21562 struct type
*this_type
;
21564 this_type
= get_die_type (die
, cu
);
21568 return read_type_die_1 (die
, cu
);
21571 /* Read the type in DIE, CU.
21572 Returns NULL for invalid types. */
21574 static struct type
*
21575 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21577 struct type
*this_type
= NULL
;
21581 case DW_TAG_class_type
:
21582 case DW_TAG_interface_type
:
21583 case DW_TAG_structure_type
:
21584 case DW_TAG_union_type
:
21585 this_type
= read_structure_type (die
, cu
);
21587 case DW_TAG_enumeration_type
:
21588 this_type
= read_enumeration_type (die
, cu
);
21590 case DW_TAG_subprogram
:
21591 case DW_TAG_subroutine_type
:
21592 case DW_TAG_inlined_subroutine
:
21593 this_type
= read_subroutine_type (die
, cu
);
21595 case DW_TAG_array_type
:
21596 this_type
= read_array_type (die
, cu
);
21598 case DW_TAG_set_type
:
21599 this_type
= read_set_type (die
, cu
);
21601 case DW_TAG_pointer_type
:
21602 this_type
= read_tag_pointer_type (die
, cu
);
21604 case DW_TAG_ptr_to_member_type
:
21605 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21607 case DW_TAG_reference_type
:
21608 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21610 case DW_TAG_rvalue_reference_type
:
21611 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21613 case DW_TAG_const_type
:
21614 this_type
= read_tag_const_type (die
, cu
);
21616 case DW_TAG_volatile_type
:
21617 this_type
= read_tag_volatile_type (die
, cu
);
21619 case DW_TAG_restrict_type
:
21620 this_type
= read_tag_restrict_type (die
, cu
);
21622 case DW_TAG_string_type
:
21623 this_type
= read_tag_string_type (die
, cu
);
21625 case DW_TAG_typedef
:
21626 this_type
= read_typedef (die
, cu
);
21628 case DW_TAG_subrange_type
:
21629 this_type
= read_subrange_type (die
, cu
);
21631 case DW_TAG_base_type
:
21632 this_type
= read_base_type (die
, cu
);
21634 case DW_TAG_unspecified_type
:
21635 this_type
= read_unspecified_type (die
, cu
);
21637 case DW_TAG_namespace
:
21638 this_type
= read_namespace_type (die
, cu
);
21640 case DW_TAG_module
:
21641 this_type
= read_module_type (die
, cu
);
21643 case DW_TAG_atomic_type
:
21644 this_type
= read_tag_atomic_type (die
, cu
);
21647 complaint (_("unexpected tag in read_type_die: '%s'"),
21648 dwarf_tag_name (die
->tag
));
21655 /* See if we can figure out if the class lives in a namespace. We do
21656 this by looking for a member function; its demangled name will
21657 contain namespace info, if there is any.
21658 Return the computed name or NULL.
21659 Space for the result is allocated on the objfile's obstack.
21660 This is the full-die version of guess_partial_die_structure_name.
21661 In this case we know DIE has no useful parent. */
21663 static const char *
21664 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21666 struct die_info
*spec_die
;
21667 struct dwarf2_cu
*spec_cu
;
21668 struct die_info
*child
;
21669 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21672 spec_die
= die_specification (die
, &spec_cu
);
21673 if (spec_die
!= NULL
)
21679 for (child
= die
->child
;
21681 child
= child
->sibling
)
21683 if (child
->tag
== DW_TAG_subprogram
)
21685 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21687 if (linkage_name
!= NULL
)
21689 gdb::unique_xmalloc_ptr
<char> actual_name
21690 (language_class_name_from_physname (cu
->language_defn
,
21692 const char *name
= NULL
;
21694 if (actual_name
!= NULL
)
21696 const char *die_name
= dwarf2_name (die
, cu
);
21698 if (die_name
!= NULL
21699 && strcmp (die_name
, actual_name
.get ()) != 0)
21701 /* Strip off the class name from the full name.
21702 We want the prefix. */
21703 int die_name_len
= strlen (die_name
);
21704 int actual_name_len
= strlen (actual_name
.get ());
21705 const char *ptr
= actual_name
.get ();
21707 /* Test for '::' as a sanity check. */
21708 if (actual_name_len
> die_name_len
+ 2
21709 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21710 name
= obstack_strndup (
21711 &objfile
->per_bfd
->storage_obstack
,
21712 ptr
, actual_name_len
- die_name_len
- 2);
21723 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21724 prefix part in such case. See
21725 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21727 static const char *
21728 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21730 struct attribute
*attr
;
21733 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21734 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21737 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21740 attr
= dw2_linkage_name_attr (die
, cu
);
21741 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21744 /* dwarf2_name had to be already called. */
21745 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21747 /* Strip the base name, keep any leading namespaces/classes. */
21748 base
= strrchr (DW_STRING (attr
), ':');
21749 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21752 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21753 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21755 &base
[-1] - DW_STRING (attr
));
21758 /* Return the name of the namespace/class that DIE is defined within,
21759 or "" if we can't tell. The caller should not xfree the result.
21761 For example, if we're within the method foo() in the following
21771 then determine_prefix on foo's die will return "N::C". */
21773 static const char *
21774 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21776 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21777 struct die_info
*parent
, *spec_die
;
21778 struct dwarf2_cu
*spec_cu
;
21779 struct type
*parent_type
;
21780 const char *retval
;
21782 if (cu
->language
!= language_cplus
21783 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21784 && cu
->language
!= language_rust
)
21787 retval
= anonymous_struct_prefix (die
, cu
);
21791 /* We have to be careful in the presence of DW_AT_specification.
21792 For example, with GCC 3.4, given the code
21796 // Definition of N::foo.
21800 then we'll have a tree of DIEs like this:
21802 1: DW_TAG_compile_unit
21803 2: DW_TAG_namespace // N
21804 3: DW_TAG_subprogram // declaration of N::foo
21805 4: DW_TAG_subprogram // definition of N::foo
21806 DW_AT_specification // refers to die #3
21808 Thus, when processing die #4, we have to pretend that we're in
21809 the context of its DW_AT_specification, namely the contex of die
21812 spec_die
= die_specification (die
, &spec_cu
);
21813 if (spec_die
== NULL
)
21814 parent
= die
->parent
;
21817 parent
= spec_die
->parent
;
21821 if (parent
== NULL
)
21823 else if (parent
->building_fullname
)
21826 const char *parent_name
;
21828 /* It has been seen on RealView 2.2 built binaries,
21829 DW_TAG_template_type_param types actually _defined_ as
21830 children of the parent class:
21833 template class <class Enum> Class{};
21834 Class<enum E> class_e;
21836 1: DW_TAG_class_type (Class)
21837 2: DW_TAG_enumeration_type (E)
21838 3: DW_TAG_enumerator (enum1:0)
21839 3: DW_TAG_enumerator (enum2:1)
21841 2: DW_TAG_template_type_param
21842 DW_AT_type DW_FORM_ref_udata (E)
21844 Besides being broken debug info, it can put GDB into an
21845 infinite loop. Consider:
21847 When we're building the full name for Class<E>, we'll start
21848 at Class, and go look over its template type parameters,
21849 finding E. We'll then try to build the full name of E, and
21850 reach here. We're now trying to build the full name of E,
21851 and look over the parent DIE for containing scope. In the
21852 broken case, if we followed the parent DIE of E, we'd again
21853 find Class, and once again go look at its template type
21854 arguments, etc., etc. Simply don't consider such parent die
21855 as source-level parent of this die (it can't be, the language
21856 doesn't allow it), and break the loop here. */
21857 name
= dwarf2_name (die
, cu
);
21858 parent_name
= dwarf2_name (parent
, cu
);
21859 complaint (_("template param type '%s' defined within parent '%s'"),
21860 name
? name
: "<unknown>",
21861 parent_name
? parent_name
: "<unknown>");
21865 switch (parent
->tag
)
21867 case DW_TAG_namespace
:
21868 parent_type
= read_type_die (parent
, cu
);
21869 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21870 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21871 Work around this problem here. */
21872 if (cu
->language
== language_cplus
21873 && strcmp (parent_type
->name (), "::") == 0)
21875 /* We give a name to even anonymous namespaces. */
21876 return parent_type
->name ();
21877 case DW_TAG_class_type
:
21878 case DW_TAG_interface_type
:
21879 case DW_TAG_structure_type
:
21880 case DW_TAG_union_type
:
21881 case DW_TAG_module
:
21882 parent_type
= read_type_die (parent
, cu
);
21883 if (parent_type
->name () != NULL
)
21884 return parent_type
->name ();
21886 /* An anonymous structure is only allowed non-static data
21887 members; no typedefs, no member functions, et cetera.
21888 So it does not need a prefix. */
21890 case DW_TAG_compile_unit
:
21891 case DW_TAG_partial_unit
:
21892 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21893 if (cu
->language
== language_cplus
21894 && !per_objfile
->per_bfd
->types
.empty ()
21895 && die
->child
!= NULL
21896 && (die
->tag
== DW_TAG_class_type
21897 || die
->tag
== DW_TAG_structure_type
21898 || die
->tag
== DW_TAG_union_type
))
21900 const char *name
= guess_full_die_structure_name (die
, cu
);
21905 case DW_TAG_subprogram
:
21906 /* Nested subroutines in Fortran get a prefix with the name
21907 of the parent's subroutine. */
21908 if (cu
->language
== language_fortran
)
21910 if ((die
->tag
== DW_TAG_subprogram
)
21911 && (dwarf2_name (parent
, cu
) != NULL
))
21912 return dwarf2_name (parent
, cu
);
21914 return determine_prefix (parent
, cu
);
21915 case DW_TAG_enumeration_type
:
21916 parent_type
= read_type_die (parent
, cu
);
21917 if (TYPE_DECLARED_CLASS (parent_type
))
21919 if (parent_type
->name () != NULL
)
21920 return parent_type
->name ();
21923 /* Fall through. */
21925 return determine_prefix (parent
, cu
);
21929 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21930 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21931 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21932 an obconcat, otherwise allocate storage for the result. The CU argument is
21933 used to determine the language and hence, the appropriate separator. */
21935 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21938 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21939 int physname
, struct dwarf2_cu
*cu
)
21941 const char *lead
= "";
21944 if (suffix
== NULL
|| suffix
[0] == '\0'
21945 || prefix
== NULL
|| prefix
[0] == '\0')
21947 else if (cu
->language
== language_d
)
21949 /* For D, the 'main' function could be defined in any module, but it
21950 should never be prefixed. */
21951 if (strcmp (suffix
, "D main") == 0)
21959 else if (cu
->language
== language_fortran
&& physname
)
21961 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21962 DW_AT_MIPS_linkage_name is preferred and used instead. */
21970 if (prefix
== NULL
)
21972 if (suffix
== NULL
)
21979 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21981 strcpy (retval
, lead
);
21982 strcat (retval
, prefix
);
21983 strcat (retval
, sep
);
21984 strcat (retval
, suffix
);
21989 /* We have an obstack. */
21990 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21994 /* Get name of a die, return NULL if not found. */
21996 static const char *
21997 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21998 struct objfile
*objfile
)
22000 if (name
&& cu
->language
== language_cplus
)
22002 gdb::unique_xmalloc_ptr
<char> canon_name
22003 = cp_canonicalize_string (name
);
22005 if (canon_name
!= nullptr)
22006 name
= objfile
->intern (canon_name
.get ());
22012 /* Get name of a die, return NULL if not found.
22013 Anonymous namespaces are converted to their magic string. */
22015 static const char *
22016 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22018 struct attribute
*attr
;
22019 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22021 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22022 if ((!attr
|| !DW_STRING (attr
))
22023 && die
->tag
!= DW_TAG_namespace
22024 && die
->tag
!= DW_TAG_class_type
22025 && die
->tag
!= DW_TAG_interface_type
22026 && die
->tag
!= DW_TAG_structure_type
22027 && die
->tag
!= DW_TAG_union_type
)
22032 case DW_TAG_compile_unit
:
22033 case DW_TAG_partial_unit
:
22034 /* Compilation units have a DW_AT_name that is a filename, not
22035 a source language identifier. */
22036 case DW_TAG_enumeration_type
:
22037 case DW_TAG_enumerator
:
22038 /* These tags always have simple identifiers already; no need
22039 to canonicalize them. */
22040 return DW_STRING (attr
);
22042 case DW_TAG_namespace
:
22043 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22044 return DW_STRING (attr
);
22045 return CP_ANONYMOUS_NAMESPACE_STR
;
22047 case DW_TAG_class_type
:
22048 case DW_TAG_interface_type
:
22049 case DW_TAG_structure_type
:
22050 case DW_TAG_union_type
:
22051 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22052 structures or unions. These were of the form "._%d" in GCC 4.1,
22053 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22054 and GCC 4.4. We work around this problem by ignoring these. */
22055 if (attr
&& DW_STRING (attr
)
22056 && (startswith (DW_STRING (attr
), "._")
22057 || startswith (DW_STRING (attr
), "<anonymous")))
22060 /* GCC might emit a nameless typedef that has a linkage name. See
22061 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22062 if (!attr
|| DW_STRING (attr
) == NULL
)
22064 attr
= dw2_linkage_name_attr (die
, cu
);
22065 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22068 /* Avoid demangling DW_STRING (attr) the second time on a second
22069 call for the same DIE. */
22070 if (!DW_STRING_IS_CANONICAL (attr
))
22072 gdb::unique_xmalloc_ptr
<char> demangled
22073 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22074 if (demangled
== nullptr)
22077 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
22078 DW_STRING_IS_CANONICAL (attr
) = 1;
22081 /* Strip any leading namespaces/classes, keep only the base name.
22082 DW_AT_name for named DIEs does not contain the prefixes. */
22083 const char *base
= strrchr (DW_STRING (attr
), ':');
22084 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22087 return DW_STRING (attr
);
22095 if (!DW_STRING_IS_CANONICAL (attr
))
22097 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22099 DW_STRING_IS_CANONICAL (attr
) = 1;
22101 return DW_STRING (attr
);
22104 /* Return the die that this die in an extension of, or NULL if there
22105 is none. *EXT_CU is the CU containing DIE on input, and the CU
22106 containing the return value on output. */
22108 static struct die_info
*
22109 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22111 struct attribute
*attr
;
22113 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22117 return follow_die_ref (die
, attr
, ext_cu
);
22121 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22125 print_spaces (indent
, f
);
22126 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22127 dwarf_tag_name (die
->tag
), die
->abbrev
,
22128 sect_offset_str (die
->sect_off
));
22130 if (die
->parent
!= NULL
)
22132 print_spaces (indent
, f
);
22133 fprintf_unfiltered (f
, " parent at offset: %s\n",
22134 sect_offset_str (die
->parent
->sect_off
));
22137 print_spaces (indent
, f
);
22138 fprintf_unfiltered (f
, " has children: %s\n",
22139 dwarf_bool_name (die
->child
!= NULL
));
22141 print_spaces (indent
, f
);
22142 fprintf_unfiltered (f
, " attributes:\n");
22144 for (i
= 0; i
< die
->num_attrs
; ++i
)
22146 print_spaces (indent
, f
);
22147 fprintf_unfiltered (f
, " %s (%s) ",
22148 dwarf_attr_name (die
->attrs
[i
].name
),
22149 dwarf_form_name (die
->attrs
[i
].form
));
22151 switch (die
->attrs
[i
].form
)
22154 case DW_FORM_addrx
:
22155 case DW_FORM_GNU_addr_index
:
22156 fprintf_unfiltered (f
, "address: ");
22157 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22159 case DW_FORM_block2
:
22160 case DW_FORM_block4
:
22161 case DW_FORM_block
:
22162 case DW_FORM_block1
:
22163 fprintf_unfiltered (f
, "block: size %s",
22164 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22166 case DW_FORM_exprloc
:
22167 fprintf_unfiltered (f
, "expression: size %s",
22168 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22170 case DW_FORM_data16
:
22171 fprintf_unfiltered (f
, "constant of 16 bytes");
22173 case DW_FORM_ref_addr
:
22174 fprintf_unfiltered (f
, "ref address: ");
22175 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22177 case DW_FORM_GNU_ref_alt
:
22178 fprintf_unfiltered (f
, "alt ref address: ");
22179 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22185 case DW_FORM_ref_udata
:
22186 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22187 (long) (DW_UNSND (&die
->attrs
[i
])));
22189 case DW_FORM_data1
:
22190 case DW_FORM_data2
:
22191 case DW_FORM_data4
:
22192 case DW_FORM_data8
:
22193 case DW_FORM_udata
:
22194 case DW_FORM_sdata
:
22195 fprintf_unfiltered (f
, "constant: %s",
22196 pulongest (DW_UNSND (&die
->attrs
[i
])));
22198 case DW_FORM_sec_offset
:
22199 fprintf_unfiltered (f
, "section offset: %s",
22200 pulongest (DW_UNSND (&die
->attrs
[i
])));
22202 case DW_FORM_ref_sig8
:
22203 fprintf_unfiltered (f
, "signature: %s",
22204 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22206 case DW_FORM_string
:
22208 case DW_FORM_line_strp
:
22210 case DW_FORM_GNU_str_index
:
22211 case DW_FORM_GNU_strp_alt
:
22212 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22213 DW_STRING (&die
->attrs
[i
])
22214 ? DW_STRING (&die
->attrs
[i
]) : "",
22215 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22218 if (DW_UNSND (&die
->attrs
[i
]))
22219 fprintf_unfiltered (f
, "flag: TRUE");
22221 fprintf_unfiltered (f
, "flag: FALSE");
22223 case DW_FORM_flag_present
:
22224 fprintf_unfiltered (f
, "flag: TRUE");
22226 case DW_FORM_indirect
:
22227 /* The reader will have reduced the indirect form to
22228 the "base form" so this form should not occur. */
22229 fprintf_unfiltered (f
,
22230 "unexpected attribute form: DW_FORM_indirect");
22232 case DW_FORM_implicit_const
:
22233 fprintf_unfiltered (f
, "constant: %s",
22234 plongest (DW_SND (&die
->attrs
[i
])));
22237 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22238 die
->attrs
[i
].form
);
22241 fprintf_unfiltered (f
, "\n");
22246 dump_die_for_error (struct die_info
*die
)
22248 dump_die_shallow (gdb_stderr
, 0, die
);
22252 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22254 int indent
= level
* 4;
22256 gdb_assert (die
!= NULL
);
22258 if (level
>= max_level
)
22261 dump_die_shallow (f
, indent
, die
);
22263 if (die
->child
!= NULL
)
22265 print_spaces (indent
, f
);
22266 fprintf_unfiltered (f
, " Children:");
22267 if (level
+ 1 < max_level
)
22269 fprintf_unfiltered (f
, "\n");
22270 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22274 fprintf_unfiltered (f
,
22275 " [not printed, max nesting level reached]\n");
22279 if (die
->sibling
!= NULL
&& level
> 0)
22281 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22285 /* This is called from the pdie macro in gdbinit.in.
22286 It's not static so gcc will keep a copy callable from gdb. */
22289 dump_die (struct die_info
*die
, int max_level
)
22291 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22295 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22299 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22300 to_underlying (die
->sect_off
),
22306 /* Follow reference or signature attribute ATTR of SRC_DIE.
22307 On entry *REF_CU is the CU of SRC_DIE.
22308 On exit *REF_CU is the CU of the result. */
22310 static struct die_info
*
22311 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22312 struct dwarf2_cu
**ref_cu
)
22314 struct die_info
*die
;
22316 if (attr
->form_is_ref ())
22317 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22318 else if (attr
->form
== DW_FORM_ref_sig8
)
22319 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22322 dump_die_for_error (src_die
);
22323 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22324 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22330 /* Follow reference OFFSET.
22331 On entry *REF_CU is the CU of the source die referencing OFFSET.
22332 On exit *REF_CU is the CU of the result.
22333 Returns NULL if OFFSET is invalid. */
22335 static struct die_info
*
22336 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22337 struct dwarf2_cu
**ref_cu
)
22339 struct die_info temp_die
;
22340 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22341 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22343 gdb_assert (cu
->per_cu
!= NULL
);
22347 if (cu
->per_cu
->is_debug_types
)
22349 /* .debug_types CUs cannot reference anything outside their CU.
22350 If they need to, they have to reference a signatured type via
22351 DW_FORM_ref_sig8. */
22352 if (!cu
->header
.offset_in_cu_p (sect_off
))
22355 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22356 || !cu
->header
.offset_in_cu_p (sect_off
))
22358 struct dwarf2_per_cu_data
*per_cu
;
22360 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22363 /* If necessary, add it to the queue and load its DIEs. */
22364 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
22365 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
22367 target_cu
= per_objfile
->get_cu (per_cu
);
22369 else if (cu
->dies
== NULL
)
22371 /* We're loading full DIEs during partial symbol reading. */
22372 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
22373 load_full_comp_unit (cu
->per_cu
, per_objfile
, false, language_minimal
);
22376 *ref_cu
= target_cu
;
22377 temp_die
.sect_off
= sect_off
;
22379 if (target_cu
!= cu
)
22380 target_cu
->ancestor
= cu
;
22382 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22384 to_underlying (sect_off
));
22387 /* Follow reference attribute ATTR of SRC_DIE.
22388 On entry *REF_CU is the CU of SRC_DIE.
22389 On exit *REF_CU is the CU of the result. */
22391 static struct die_info
*
22392 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22393 struct dwarf2_cu
**ref_cu
)
22395 sect_offset sect_off
= attr
->get_ref_die_offset ();
22396 struct dwarf2_cu
*cu
= *ref_cu
;
22397 struct die_info
*die
;
22399 die
= follow_die_offset (sect_off
,
22400 (attr
->form
== DW_FORM_GNU_ref_alt
22401 || cu
->per_cu
->is_dwz
),
22404 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22405 "at %s [in module %s]"),
22406 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22407 objfile_name (cu
->per_objfile
->objfile
));
22414 struct dwarf2_locexpr_baton
22415 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22416 dwarf2_per_cu_data
*per_cu
,
22417 dwarf2_per_objfile
*per_objfile
,
22418 CORE_ADDR (*get_frame_pc
) (void *baton
),
22419 void *baton
, bool resolve_abstract_p
)
22421 struct die_info
*die
;
22422 struct attribute
*attr
;
22423 struct dwarf2_locexpr_baton retval
;
22424 struct objfile
*objfile
= per_objfile
->objfile
;
22426 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22428 cu
= load_cu (per_cu
, per_objfile
, false);
22432 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22433 Instead just throw an error, not much else we can do. */
22434 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22435 sect_offset_str (sect_off
), objfile_name (objfile
));
22438 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22440 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22441 sect_offset_str (sect_off
), objfile_name (objfile
));
22443 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22444 if (!attr
&& resolve_abstract_p
22445 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22446 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22448 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22449 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22450 struct gdbarch
*gdbarch
= objfile
->arch ();
22452 for (const auto &cand_off
22453 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22455 struct dwarf2_cu
*cand_cu
= cu
;
22456 struct die_info
*cand
22457 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22460 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22463 CORE_ADDR pc_low
, pc_high
;
22464 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22465 if (pc_low
== ((CORE_ADDR
) -1))
22467 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22468 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22469 if (!(pc_low
<= pc
&& pc
< pc_high
))
22473 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22480 /* DWARF: "If there is no such attribute, then there is no effect.".
22481 DATA is ignored if SIZE is 0. */
22483 retval
.data
= NULL
;
22486 else if (attr
->form_is_section_offset ())
22488 struct dwarf2_loclist_baton loclist_baton
;
22489 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22492 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22494 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22496 retval
.size
= size
;
22500 if (!attr
->form_is_block ())
22501 error (_("Dwarf Error: DIE at %s referenced in module %s "
22502 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22503 sect_offset_str (sect_off
), objfile_name (objfile
));
22505 retval
.data
= DW_BLOCK (attr
)->data
;
22506 retval
.size
= DW_BLOCK (attr
)->size
;
22508 retval
.per_objfile
= per_objfile
;
22509 retval
.per_cu
= cu
->per_cu
;
22511 per_objfile
->age_comp_units ();
22518 struct dwarf2_locexpr_baton
22519 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22520 dwarf2_per_cu_data
*per_cu
,
22521 dwarf2_per_objfile
*per_objfile
,
22522 CORE_ADDR (*get_frame_pc
) (void *baton
),
22525 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22527 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22528 get_frame_pc
, baton
);
22531 /* Write a constant of a given type as target-ordered bytes into
22534 static const gdb_byte
*
22535 write_constant_as_bytes (struct obstack
*obstack
,
22536 enum bfd_endian byte_order
,
22543 *len
= TYPE_LENGTH (type
);
22544 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22545 store_unsigned_integer (result
, *len
, byte_order
, value
);
22553 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22554 dwarf2_per_cu_data
*per_cu
,
22555 dwarf2_per_objfile
*per_objfile
,
22559 struct die_info
*die
;
22560 struct attribute
*attr
;
22561 const gdb_byte
*result
= NULL
;
22564 enum bfd_endian byte_order
;
22565 struct objfile
*objfile
= per_objfile
->objfile
;
22567 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22569 cu
= load_cu (per_cu
, per_objfile
, false);
22573 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22574 Instead just throw an error, not much else we can do. */
22575 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22576 sect_offset_str (sect_off
), objfile_name (objfile
));
22579 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22581 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22582 sect_offset_str (sect_off
), objfile_name (objfile
));
22584 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22588 byte_order
= (bfd_big_endian (objfile
->obfd
)
22589 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22591 switch (attr
->form
)
22594 case DW_FORM_addrx
:
22595 case DW_FORM_GNU_addr_index
:
22599 *len
= cu
->header
.addr_size
;
22600 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22601 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22605 case DW_FORM_string
:
22608 case DW_FORM_GNU_str_index
:
22609 case DW_FORM_GNU_strp_alt
:
22610 /* DW_STRING is already allocated on the objfile obstack, point
22612 result
= (const gdb_byte
*) DW_STRING (attr
);
22613 *len
= strlen (DW_STRING (attr
));
22615 case DW_FORM_block1
:
22616 case DW_FORM_block2
:
22617 case DW_FORM_block4
:
22618 case DW_FORM_block
:
22619 case DW_FORM_exprloc
:
22620 case DW_FORM_data16
:
22621 result
= DW_BLOCK (attr
)->data
;
22622 *len
= DW_BLOCK (attr
)->size
;
22625 /* The DW_AT_const_value attributes are supposed to carry the
22626 symbol's value "represented as it would be on the target
22627 architecture." By the time we get here, it's already been
22628 converted to host endianness, so we just need to sign- or
22629 zero-extend it as appropriate. */
22630 case DW_FORM_data1
:
22631 type
= die_type (die
, cu
);
22632 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22633 if (result
== NULL
)
22634 result
= write_constant_as_bytes (obstack
, byte_order
,
22637 case DW_FORM_data2
:
22638 type
= die_type (die
, cu
);
22639 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22640 if (result
== NULL
)
22641 result
= write_constant_as_bytes (obstack
, byte_order
,
22644 case DW_FORM_data4
:
22645 type
= die_type (die
, cu
);
22646 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22647 if (result
== NULL
)
22648 result
= write_constant_as_bytes (obstack
, byte_order
,
22651 case DW_FORM_data8
:
22652 type
= die_type (die
, cu
);
22653 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22654 if (result
== NULL
)
22655 result
= write_constant_as_bytes (obstack
, byte_order
,
22659 case DW_FORM_sdata
:
22660 case DW_FORM_implicit_const
:
22661 type
= die_type (die
, cu
);
22662 result
= write_constant_as_bytes (obstack
, byte_order
,
22663 type
, DW_SND (attr
), len
);
22666 case DW_FORM_udata
:
22667 type
= die_type (die
, cu
);
22668 result
= write_constant_as_bytes (obstack
, byte_order
,
22669 type
, DW_UNSND (attr
), len
);
22673 complaint (_("unsupported const value attribute form: '%s'"),
22674 dwarf_form_name (attr
->form
));
22684 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22685 dwarf2_per_cu_data
*per_cu
,
22686 dwarf2_per_objfile
*per_objfile
)
22688 struct die_info
*die
;
22690 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22692 cu
= load_cu (per_cu
, per_objfile
, false);
22697 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22701 return die_type (die
, cu
);
22707 dwarf2_get_die_type (cu_offset die_offset
,
22708 dwarf2_per_cu_data
*per_cu
,
22709 dwarf2_per_objfile
*per_objfile
)
22711 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22712 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
22715 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22716 On entry *REF_CU is the CU of SRC_DIE.
22717 On exit *REF_CU is the CU of the result.
22718 Returns NULL if the referenced DIE isn't found. */
22720 static struct die_info
*
22721 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22722 struct dwarf2_cu
**ref_cu
)
22724 struct die_info temp_die
;
22725 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22726 struct die_info
*die
;
22727 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
22730 /* While it might be nice to assert sig_type->type == NULL here,
22731 we can get here for DW_AT_imported_declaration where we need
22732 the DIE not the type. */
22734 /* If necessary, add it to the queue and load its DIEs. */
22736 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
22738 read_signatured_type (sig_type
, per_objfile
);
22740 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
22741 gdb_assert (sig_cu
!= NULL
);
22742 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22743 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22744 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22745 to_underlying (temp_die
.sect_off
));
22748 /* For .gdb_index version 7 keep track of included TUs.
22749 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22750 if (per_objfile
->per_bfd
->index_table
!= NULL
22751 && per_objfile
->per_bfd
->index_table
->version
<= 7)
22753 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22758 sig_cu
->ancestor
= cu
;
22766 /* Follow signatured type referenced by ATTR in SRC_DIE.
22767 On entry *REF_CU is the CU of SRC_DIE.
22768 On exit *REF_CU is the CU of the result.
22769 The result is the DIE of the type.
22770 If the referenced type cannot be found an error is thrown. */
22772 static struct die_info
*
22773 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22774 struct dwarf2_cu
**ref_cu
)
22776 ULONGEST signature
= DW_SIGNATURE (attr
);
22777 struct signatured_type
*sig_type
;
22778 struct die_info
*die
;
22780 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22782 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22783 /* sig_type will be NULL if the signatured type is missing from
22785 if (sig_type
== NULL
)
22787 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22788 " from DIE at %s [in module %s]"),
22789 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22790 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22793 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22796 dump_die_for_error (src_die
);
22797 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22798 " from DIE at %s [in module %s]"),
22799 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22800 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22806 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22807 reading in and processing the type unit if necessary. */
22809 static struct type
*
22810 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22811 struct dwarf2_cu
*cu
)
22813 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22814 struct signatured_type
*sig_type
;
22815 struct dwarf2_cu
*type_cu
;
22816 struct die_info
*type_die
;
22819 sig_type
= lookup_signatured_type (cu
, signature
);
22820 /* sig_type will be NULL if the signatured type is missing from
22822 if (sig_type
== NULL
)
22824 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22825 " from DIE at %s [in module %s]"),
22826 hex_string (signature
), sect_offset_str (die
->sect_off
),
22827 objfile_name (per_objfile
->objfile
));
22828 return build_error_marker_type (cu
, die
);
22831 /* If we already know the type we're done. */
22832 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
22833 if (type
!= nullptr)
22837 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22838 if (type_die
!= NULL
)
22840 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22841 is created. This is important, for example, because for c++ classes
22842 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22843 type
= read_type_die (type_die
, type_cu
);
22846 complaint (_("Dwarf Error: Cannot build signatured type %s"
22847 " referenced from DIE at %s [in module %s]"),
22848 hex_string (signature
), sect_offset_str (die
->sect_off
),
22849 objfile_name (per_objfile
->objfile
));
22850 type
= build_error_marker_type (cu
, die
);
22855 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22856 " from DIE at %s [in module %s]"),
22857 hex_string (signature
), sect_offset_str (die
->sect_off
),
22858 objfile_name (per_objfile
->objfile
));
22859 type
= build_error_marker_type (cu
, die
);
22862 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
22867 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22868 reading in and processing the type unit if necessary. */
22870 static struct type
*
22871 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22872 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22874 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22875 if (attr
->form_is_ref ())
22877 struct dwarf2_cu
*type_cu
= cu
;
22878 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22880 return read_type_die (type_die
, type_cu
);
22882 else if (attr
->form
== DW_FORM_ref_sig8
)
22884 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22888 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22890 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22891 " at %s [in module %s]"),
22892 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22893 objfile_name (per_objfile
->objfile
));
22894 return build_error_marker_type (cu
, die
);
22898 /* Load the DIEs associated with type unit PER_CU into memory. */
22901 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22902 dwarf2_per_objfile
*per_objfile
)
22904 struct signatured_type
*sig_type
;
22906 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22907 gdb_assert (! per_cu
->type_unit_group_p ());
22909 /* We have the per_cu, but we need the signatured_type.
22910 Fortunately this is an easy translation. */
22911 gdb_assert (per_cu
->is_debug_types
);
22912 sig_type
= (struct signatured_type
*) per_cu
;
22914 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22916 read_signatured_type (sig_type
, per_objfile
);
22918 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
22921 /* Read in a signatured type and build its CU and DIEs.
22922 If the type is a stub for the real type in a DWO file,
22923 read in the real type from the DWO file as well. */
22926 read_signatured_type (signatured_type
*sig_type
,
22927 dwarf2_per_objfile
*per_objfile
)
22929 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22931 gdb_assert (per_cu
->is_debug_types
);
22932 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22934 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
22936 if (!reader
.dummy_p
)
22938 struct dwarf2_cu
*cu
= reader
.cu
;
22939 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22941 gdb_assert (cu
->die_hash
== NULL
);
22943 htab_create_alloc_ex (cu
->header
.length
/ 12,
22947 &cu
->comp_unit_obstack
,
22948 hashtab_obstack_allocate
,
22949 dummy_obstack_deallocate
);
22951 if (reader
.comp_unit_die
->has_children
)
22952 reader
.comp_unit_die
->child
22953 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22954 reader
.comp_unit_die
);
22955 cu
->dies
= reader
.comp_unit_die
;
22956 /* comp_unit_die is not stored in die_hash, no need. */
22958 /* We try not to read any attributes in this function, because
22959 not all CUs needed for references have been loaded yet, and
22960 symbol table processing isn't initialized. But we have to
22961 set the CU language, or we won't be able to build types
22962 correctly. Similarly, if we do not read the producer, we can
22963 not apply producer-specific interpretation. */
22964 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22969 sig_type
->per_cu
.tu_read
= 1;
22972 /* Decode simple location descriptions.
22973 Given a pointer to a dwarf block that defines a location, compute
22974 the location and return the value. If COMPUTED is non-null, it is
22975 set to true to indicate that decoding was successful, and false
22976 otherwise. If COMPUTED is null, then this function may emit a
22980 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22982 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22984 size_t size
= blk
->size
;
22985 const gdb_byte
*data
= blk
->data
;
22986 CORE_ADDR stack
[64];
22988 unsigned int bytes_read
, unsnd
;
22991 if (computed
!= nullptr)
22997 stack
[++stacki
] = 0;
23036 stack
[++stacki
] = op
- DW_OP_lit0
;
23071 stack
[++stacki
] = op
- DW_OP_reg0
;
23074 if (computed
== nullptr)
23075 dwarf2_complex_location_expr_complaint ();
23082 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23084 stack
[++stacki
] = unsnd
;
23087 if (computed
== nullptr)
23088 dwarf2_complex_location_expr_complaint ();
23095 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23100 case DW_OP_const1u
:
23101 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23105 case DW_OP_const1s
:
23106 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23110 case DW_OP_const2u
:
23111 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23115 case DW_OP_const2s
:
23116 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23120 case DW_OP_const4u
:
23121 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23125 case DW_OP_const4s
:
23126 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23130 case DW_OP_const8u
:
23131 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23136 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23142 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23147 stack
[stacki
+ 1] = stack
[stacki
];
23152 stack
[stacki
- 1] += stack
[stacki
];
23156 case DW_OP_plus_uconst
:
23157 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23163 stack
[stacki
- 1] -= stack
[stacki
];
23168 /* If we're not the last op, then we definitely can't encode
23169 this using GDB's address_class enum. This is valid for partial
23170 global symbols, although the variable's address will be bogus
23174 if (computed
== nullptr)
23175 dwarf2_complex_location_expr_complaint ();
23181 case DW_OP_GNU_push_tls_address
:
23182 case DW_OP_form_tls_address
:
23183 /* The top of the stack has the offset from the beginning
23184 of the thread control block at which the variable is located. */
23185 /* Nothing should follow this operator, so the top of stack would
23187 /* This is valid for partial global symbols, but the variable's
23188 address will be bogus in the psymtab. Make it always at least
23189 non-zero to not look as a variable garbage collected by linker
23190 which have DW_OP_addr 0. */
23193 if (computed
== nullptr)
23194 dwarf2_complex_location_expr_complaint ();
23201 case DW_OP_GNU_uninit
:
23202 if (computed
!= nullptr)
23207 case DW_OP_GNU_addr_index
:
23208 case DW_OP_GNU_const_index
:
23209 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23215 if (computed
== nullptr)
23217 const char *name
= get_DW_OP_name (op
);
23220 complaint (_("unsupported stack op: '%s'"),
23223 complaint (_("unsupported stack op: '%02x'"),
23227 return (stack
[stacki
]);
23230 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23231 outside of the allocated space. Also enforce minimum>0. */
23232 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23234 if (computed
== nullptr)
23235 complaint (_("location description stack overflow"));
23241 if (computed
== nullptr)
23242 complaint (_("location description stack underflow"));
23247 if (computed
!= nullptr)
23249 return (stack
[stacki
]);
23252 /* memory allocation interface */
23254 static struct dwarf_block
*
23255 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23257 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23260 static struct die_info
*
23261 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23263 struct die_info
*die
;
23264 size_t size
= sizeof (struct die_info
);
23267 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23269 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23270 memset (die
, 0, sizeof (struct die_info
));
23276 /* Macro support. */
23278 /* An overload of dwarf_decode_macros that finds the correct section
23279 and ensures it is read in before calling the other overload. */
23282 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23283 int section_is_gnu
)
23285 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23286 struct objfile
*objfile
= per_objfile
->objfile
;
23287 const struct line_header
*lh
= cu
->line_header
;
23288 unsigned int offset_size
= cu
->header
.offset_size
;
23289 struct dwarf2_section_info
*section
;
23290 const char *section_name
;
23292 if (cu
->dwo_unit
!= nullptr)
23294 if (section_is_gnu
)
23296 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23297 section_name
= ".debug_macro.dwo";
23301 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23302 section_name
= ".debug_macinfo.dwo";
23307 if (section_is_gnu
)
23309 section
= &per_objfile
->per_bfd
->macro
;
23310 section_name
= ".debug_macro";
23314 section
= &per_objfile
->per_bfd
->macinfo
;
23315 section_name
= ".debug_macinfo";
23319 section
->read (objfile
);
23320 if (section
->buffer
== nullptr)
23322 complaint (_("missing %s section"), section_name
);
23326 buildsym_compunit
*builder
= cu
->get_builder ();
23328 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
23329 offset_size
, offset
, section_is_gnu
);
23332 /* Return the .debug_loc section to use for CU.
23333 For DWO files use .debug_loc.dwo. */
23335 static struct dwarf2_section_info
*
23336 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23338 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23342 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23344 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23346 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
23347 : &per_objfile
->per_bfd
->loc
);
23350 /* A helper function that fills in a dwarf2_loclist_baton. */
23353 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23354 struct dwarf2_loclist_baton
*baton
,
23355 const struct attribute
*attr
)
23357 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23358 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23360 section
->read (per_objfile
->objfile
);
23362 baton
->per_objfile
= per_objfile
;
23363 baton
->per_cu
= cu
->per_cu
;
23364 gdb_assert (baton
->per_cu
);
23365 /* We don't know how long the location list is, but make sure we
23366 don't run off the edge of the section. */
23367 baton
->size
= section
->size
- DW_UNSND (attr
);
23368 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23369 if (cu
->base_address
.has_value ())
23370 baton
->base_address
= *cu
->base_address
;
23372 baton
->base_address
= 0;
23373 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23377 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23378 struct dwarf2_cu
*cu
, int is_block
)
23380 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23381 struct objfile
*objfile
= per_objfile
->objfile
;
23382 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23384 if (attr
->form_is_section_offset ()
23385 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23386 the section. If so, fall through to the complaint in the
23388 && DW_UNSND (attr
) < section
->get_size (objfile
))
23390 struct dwarf2_loclist_baton
*baton
;
23392 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23394 fill_in_loclist_baton (cu
, baton
, attr
);
23396 if (!cu
->base_address
.has_value ())
23397 complaint (_("Location list used without "
23398 "specifying the CU base address."));
23400 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23401 ? dwarf2_loclist_block_index
23402 : dwarf2_loclist_index
);
23403 SYMBOL_LOCATION_BATON (sym
) = baton
;
23407 struct dwarf2_locexpr_baton
*baton
;
23409 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23410 baton
->per_objfile
= per_objfile
;
23411 baton
->per_cu
= cu
->per_cu
;
23412 gdb_assert (baton
->per_cu
);
23414 if (attr
->form_is_block ())
23416 /* Note that we're just copying the block's data pointer
23417 here, not the actual data. We're still pointing into the
23418 info_buffer for SYM's objfile; right now we never release
23419 that buffer, but when we do clean up properly this may
23421 baton
->size
= DW_BLOCK (attr
)->size
;
23422 baton
->data
= DW_BLOCK (attr
)->data
;
23426 dwarf2_invalid_attrib_class_complaint ("location description",
23427 sym
->natural_name ());
23431 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23432 ? dwarf2_locexpr_block_index
23433 : dwarf2_locexpr_index
);
23434 SYMBOL_LOCATION_BATON (sym
) = baton
;
23440 const comp_unit_head
*
23441 dwarf2_per_cu_data::get_header () const
23443 if (!m_header_read_in
)
23445 const gdb_byte
*info_ptr
23446 = this->section
->buffer
+ to_underlying (this->sect_off
);
23448 memset (&m_header
, 0, sizeof (m_header
));
23450 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
23451 rcuh_kind::COMPILE
);
23460 dwarf2_per_cu_data::addr_size () const
23462 return this->get_header ()->addr_size
;
23468 dwarf2_per_cu_data::offset_size () const
23470 return this->get_header ()->offset_size
;
23476 dwarf2_per_cu_data::ref_addr_size () const
23478 const comp_unit_head
*header
= this->get_header ();
23480 if (header
->version
== 2)
23481 return header
->addr_size
;
23483 return header
->offset_size
;
23489 dwarf2_cu::addr_type () const
23491 struct objfile
*objfile
= this->per_objfile
->objfile
;
23492 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23493 struct type
*addr_type
= lookup_pointer_type (void_type
);
23494 int addr_size
= this->per_cu
->addr_size ();
23496 if (TYPE_LENGTH (addr_type
) == addr_size
)
23499 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23503 /* A helper function for dwarf2_find_containing_comp_unit that returns
23504 the index of the result, and that searches a vector. It will
23505 return a result even if the offset in question does not actually
23506 occur in any CU. This is separate so that it can be unit
23510 dwarf2_find_containing_comp_unit
23511 (sect_offset sect_off
,
23512 unsigned int offset_in_dwz
,
23513 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23518 high
= all_comp_units
.size () - 1;
23521 struct dwarf2_per_cu_data
*mid_cu
;
23522 int mid
= low
+ (high
- low
) / 2;
23524 mid_cu
= all_comp_units
[mid
];
23525 if (mid_cu
->is_dwz
> offset_in_dwz
23526 || (mid_cu
->is_dwz
== offset_in_dwz
23527 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23532 gdb_assert (low
== high
);
23536 /* Locate the .debug_info compilation unit from CU's objfile which contains
23537 the DIE at OFFSET. Raises an error on failure. */
23539 static struct dwarf2_per_cu_data
*
23540 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23541 unsigned int offset_in_dwz
,
23542 dwarf2_per_objfile
*per_objfile
)
23544 int low
= dwarf2_find_containing_comp_unit
23545 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
23546 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
23548 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23550 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23551 error (_("Dwarf Error: could not find partial DIE containing "
23552 "offset %s [in module %s]"),
23553 sect_offset_str (sect_off
),
23554 bfd_get_filename (per_objfile
->objfile
->obfd
));
23556 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23558 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
23562 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
23563 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23564 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23565 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23572 namespace selftests
{
23573 namespace find_containing_comp_unit
{
23578 struct dwarf2_per_cu_data one
{};
23579 struct dwarf2_per_cu_data two
{};
23580 struct dwarf2_per_cu_data three
{};
23581 struct dwarf2_per_cu_data four
{};
23584 two
.sect_off
= sect_offset (one
.length
);
23589 four
.sect_off
= sect_offset (three
.length
);
23593 std::vector
<dwarf2_per_cu_data
*> units
;
23594 units
.push_back (&one
);
23595 units
.push_back (&two
);
23596 units
.push_back (&three
);
23597 units
.push_back (&four
);
23601 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23602 SELF_CHECK (units
[result
] == &one
);
23603 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23604 SELF_CHECK (units
[result
] == &one
);
23605 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23606 SELF_CHECK (units
[result
] == &two
);
23608 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23609 SELF_CHECK (units
[result
] == &three
);
23610 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23611 SELF_CHECK (units
[result
] == &three
);
23612 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23613 SELF_CHECK (units
[result
] == &four
);
23619 #endif /* GDB_SELF_TEST */
23621 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23623 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23624 dwarf2_per_objfile
*per_objfile
)
23626 per_objfile (per_objfile
),
23628 has_loclist (false),
23629 checked_producer (false),
23630 producer_is_gxx_lt_4_6 (false),
23631 producer_is_gcc_lt_4_3 (false),
23632 producer_is_icc (false),
23633 producer_is_icc_lt_14 (false),
23634 producer_is_codewarrior (false),
23635 processing_has_namespace_info (false)
23639 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23642 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23643 enum language pretend_language
)
23645 struct attribute
*attr
;
23647 /* Set the language we're debugging. */
23648 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23649 if (attr
!= nullptr)
23650 set_cu_language (DW_UNSND (attr
), cu
);
23653 cu
->language
= pretend_language
;
23654 cu
->language_defn
= language_def (cu
->language
);
23657 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23663 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
23665 auto it
= m_dwarf2_cus
.find (per_cu
);
23666 if (it
== m_dwarf2_cus
.end ())
23675 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
23677 gdb_assert (this->get_cu (per_cu
) == nullptr);
23679 m_dwarf2_cus
[per_cu
] = cu
;
23685 dwarf2_per_objfile::age_comp_units ()
23687 /* Start by clearing all marks. */
23688 for (auto pair
: m_dwarf2_cus
)
23689 pair
.second
->mark
= false;
23691 /* Traverse all CUs, mark them and their dependencies if used recently
23693 for (auto pair
: m_dwarf2_cus
)
23695 dwarf2_cu
*cu
= pair
.second
;
23698 if (cu
->last_used
<= dwarf_max_cache_age
)
23702 /* Delete all CUs still not marked. */
23703 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
23705 dwarf2_cu
*cu
= it
->second
;
23710 it
= m_dwarf2_cus
.erase (it
);
23720 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
23722 auto it
= m_dwarf2_cus
.find (per_cu
);
23723 if (it
== m_dwarf2_cus
.end ())
23728 m_dwarf2_cus
.erase (it
);
23731 dwarf2_per_objfile::~dwarf2_per_objfile ()
23736 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23737 We store these in a hash table separate from the DIEs, and preserve them
23738 when the DIEs are flushed out of cache.
23740 The CU "per_cu" pointer is needed because offset alone is not enough to
23741 uniquely identify the type. A file may have multiple .debug_types sections,
23742 or the type may come from a DWO file. Furthermore, while it's more logical
23743 to use per_cu->section+offset, with Fission the section with the data is in
23744 the DWO file but we don't know that section at the point we need it.
23745 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23746 because we can enter the lookup routine, get_die_type_at_offset, from
23747 outside this file, and thus won't necessarily have PER_CU->cu.
23748 Fortunately, PER_CU is stable for the life of the objfile. */
23750 struct dwarf2_per_cu_offset_and_type
23752 const struct dwarf2_per_cu_data
*per_cu
;
23753 sect_offset sect_off
;
23757 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23760 per_cu_offset_and_type_hash (const void *item
)
23762 const struct dwarf2_per_cu_offset_and_type
*ofs
23763 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23765 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23768 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23771 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23773 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23774 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23775 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23776 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23778 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23779 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23782 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23783 table if necessary. For convenience, return TYPE.
23785 The DIEs reading must have careful ordering to:
23786 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23787 reading current DIE.
23788 * Not trying to dereference contents of still incompletely read in types
23789 while reading in other DIEs.
23790 * Enable referencing still incompletely read in types just by a pointer to
23791 the type without accessing its fields.
23793 Therefore caller should follow these rules:
23794 * Try to fetch any prerequisite types we may need to build this DIE type
23795 before building the type and calling set_die_type.
23796 * After building type call set_die_type for current DIE as soon as
23797 possible before fetching more types to complete the current type.
23798 * Make the type as complete as possible before fetching more types. */
23800 static struct type
*
23801 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23803 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23804 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23805 struct objfile
*objfile
= per_objfile
->objfile
;
23806 struct attribute
*attr
;
23807 struct dynamic_prop prop
;
23809 /* For Ada types, make sure that the gnat-specific data is always
23810 initialized (if not already set). There are a few types where
23811 we should not be doing so, because the type-specific area is
23812 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23813 where the type-specific area is used to store the floatformat).
23814 But this is not a problem, because the gnat-specific information
23815 is actually not needed for these types. */
23816 if (need_gnat_info (cu
)
23817 && type
->code () != TYPE_CODE_FUNC
23818 && type
->code () != TYPE_CODE_FLT
23819 && type
->code () != TYPE_CODE_METHODPTR
23820 && type
->code () != TYPE_CODE_MEMBERPTR
23821 && type
->code () != TYPE_CODE_METHOD
23822 && !HAVE_GNAT_AUX_INFO (type
))
23823 INIT_GNAT_SPECIFIC (type
);
23825 /* Read DW_AT_allocated and set in type. */
23826 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23827 if (attr
!= NULL
&& attr
->form_is_block ())
23829 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23830 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23831 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23833 else if (attr
!= NULL
)
23835 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23836 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23837 sect_offset_str (die
->sect_off
));
23840 /* Read DW_AT_associated and set in type. */
23841 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23842 if (attr
!= NULL
&& attr
->form_is_block ())
23844 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23845 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23846 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23848 else if (attr
!= NULL
)
23850 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23851 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23852 sect_offset_str (die
->sect_off
));
23855 /* Read DW_AT_data_location and set in type. */
23856 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23857 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23858 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23860 if (per_objfile
->die_type_hash
== NULL
)
23861 per_objfile
->die_type_hash
23862 = htab_up (htab_create_alloc (127,
23863 per_cu_offset_and_type_hash
,
23864 per_cu_offset_and_type_eq
,
23865 NULL
, xcalloc
, xfree
));
23867 ofs
.per_cu
= cu
->per_cu
;
23868 ofs
.sect_off
= die
->sect_off
;
23870 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23871 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23873 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23874 sect_offset_str (die
->sect_off
));
23875 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23876 struct dwarf2_per_cu_offset_and_type
);
23881 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23882 or return NULL if the die does not have a saved type. */
23884 static struct type
*
23885 get_die_type_at_offset (sect_offset sect_off
,
23886 dwarf2_per_cu_data
*per_cu
,
23887 dwarf2_per_objfile
*per_objfile
)
23889 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23891 if (per_objfile
->die_type_hash
== NULL
)
23894 ofs
.per_cu
= per_cu
;
23895 ofs
.sect_off
= sect_off
;
23896 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23897 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
23904 /* Look up the type for DIE in CU in die_type_hash,
23905 or return NULL if DIE does not have a saved type. */
23907 static struct type
*
23908 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23910 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
23913 /* Add a dependence relationship from CU to REF_PER_CU. */
23916 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23917 struct dwarf2_per_cu_data
*ref_per_cu
)
23921 if (cu
->dependencies
== NULL
)
23923 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23924 NULL
, &cu
->comp_unit_obstack
,
23925 hashtab_obstack_allocate
,
23926 dummy_obstack_deallocate
);
23928 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23930 *slot
= ref_per_cu
;
23933 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23934 Set the mark field in every compilation unit in the
23935 cache that we must keep because we are keeping CU.
23937 DATA is the dwarf2_per_objfile object in which to look up CUs. */
23940 dwarf2_mark_helper (void **slot
, void *data
)
23942 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
23943 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
23944 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23946 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23947 reading of the chain. As such dependencies remain valid it is not much
23948 useful to track and undo them during QUIT cleanups. */
23957 if (cu
->dependencies
!= nullptr)
23958 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
23963 /* Set the mark field in CU and in every other compilation unit in the
23964 cache that we must keep because we are keeping CU. */
23967 dwarf2_mark (struct dwarf2_cu
*cu
)
23974 if (cu
->dependencies
!= nullptr)
23975 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
23978 /* Trivial hash function for partial_die_info: the hash value of a DIE
23979 is its offset in .debug_info for this objfile. */
23982 partial_die_hash (const void *item
)
23984 const struct partial_die_info
*part_die
23985 = (const struct partial_die_info
*) item
;
23987 return to_underlying (part_die
->sect_off
);
23990 /* Trivial comparison function for partial_die_info structures: two DIEs
23991 are equal if they have the same offset. */
23994 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23996 const struct partial_die_info
*part_die_lhs
23997 = (const struct partial_die_info
*) item_lhs
;
23998 const struct partial_die_info
*part_die_rhs
23999 = (const struct partial_die_info
*) item_rhs
;
24001 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24004 struct cmd_list_element
*set_dwarf_cmdlist
;
24005 struct cmd_list_element
*show_dwarf_cmdlist
;
24008 show_check_physname (struct ui_file
*file
, int from_tty
,
24009 struct cmd_list_element
*c
, const char *value
)
24011 fprintf_filtered (file
,
24012 _("Whether to check \"physname\" is %s.\n"),
24016 void _initialize_dwarf2_read ();
24018 _initialize_dwarf2_read ()
24020 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24021 Set DWARF specific variables.\n\
24022 Configure DWARF variables such as the cache size."),
24023 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24024 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24026 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24027 Show DWARF specific variables.\n\
24028 Show DWARF variables such as the cache size."),
24029 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24030 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24032 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24033 &dwarf_max_cache_age
, _("\
24034 Set the upper bound on the age of cached DWARF compilation units."), _("\
24035 Show the upper bound on the age of cached DWARF compilation units."), _("\
24036 A higher limit means that cached compilation units will be stored\n\
24037 in memory longer, and more total memory will be used. Zero disables\n\
24038 caching, which can slow down startup."),
24040 show_dwarf_max_cache_age
,
24041 &set_dwarf_cmdlist
,
24042 &show_dwarf_cmdlist
);
24044 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24045 Set debugging of the DWARF reader."), _("\
24046 Show debugging of the DWARF reader."), _("\
24047 When enabled (non-zero), debugging messages are printed during DWARF\n\
24048 reading and symtab expansion. A value of 1 (one) provides basic\n\
24049 information. A value greater than 1 provides more verbose information."),
24052 &setdebuglist
, &showdebuglist
);
24054 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24055 Set debugging of the DWARF DIE reader."), _("\
24056 Show debugging of the DWARF DIE reader."), _("\
24057 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24058 The value is the maximum depth to print."),
24061 &setdebuglist
, &showdebuglist
);
24063 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24064 Set debugging of the dwarf line reader."), _("\
24065 Show debugging of the dwarf line reader."), _("\
24066 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24067 A value of 1 (one) provides basic information.\n\
24068 A value greater than 1 provides more verbose information."),
24071 &setdebuglist
, &showdebuglist
);
24073 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24074 Set cross-checking of \"physname\" code against demangler."), _("\
24075 Show cross-checking of \"physname\" code against demangler."), _("\
24076 When enabled, GDB's internal \"physname\" code is checked against\n\
24078 NULL
, show_check_physname
,
24079 &setdebuglist
, &showdebuglist
);
24081 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24082 no_class
, &use_deprecated_index_sections
, _("\
24083 Set whether to use deprecated gdb_index sections."), _("\
24084 Show whether to use deprecated gdb_index sections."), _("\
24085 When enabled, deprecated .gdb_index sections are used anyway.\n\
24086 Normally they are ignored either because of a missing feature or\n\
24087 performance issue.\n\
24088 Warning: This option must be enabled before gdb reads the file."),
24091 &setlist
, &showlist
);
24093 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24094 &dwarf2_locexpr_funcs
);
24095 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24096 &dwarf2_loclist_funcs
);
24098 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24099 &dwarf2_block_frame_base_locexpr_funcs
);
24100 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24101 &dwarf2_block_frame_base_loclist_funcs
);
24104 selftests::register_test ("dw2_expand_symtabs_matching",
24105 selftests::dw2_expand_symtabs_matching::run_test
);
24106 selftests::register_test ("dwarf2_find_containing_comp_unit",
24107 selftests::find_containing_comp_unit::run_test
);