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 struct 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
1224 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1226 static void scan_partial_symbols (struct partial_die_info
*,
1227 CORE_ADDR
*, CORE_ADDR
*,
1228 int, struct dwarf2_cu
*);
1230 static void add_partial_symbol (struct partial_die_info
*,
1231 struct dwarf2_cu
*);
1233 static void add_partial_namespace (struct partial_die_info
*pdi
,
1234 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1235 int set_addrmap
, struct dwarf2_cu
*cu
);
1237 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1238 CORE_ADDR
*highpc
, int set_addrmap
,
1239 struct dwarf2_cu
*cu
);
1241 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1242 struct dwarf2_cu
*cu
);
1244 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1245 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1246 int need_pc
, struct dwarf2_cu
*cu
);
1248 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1250 static struct partial_die_info
*load_partial_dies
1251 (const struct die_reader_specs
*, const gdb_byte
*, int);
1253 /* A pair of partial_die_info and compilation unit. */
1254 struct cu_partial_die_info
1256 /* The compilation unit of the partial_die_info. */
1257 struct dwarf2_cu
*cu
;
1258 /* A partial_die_info. */
1259 struct partial_die_info
*pdi
;
1261 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1267 cu_partial_die_info () = delete;
1270 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1271 struct dwarf2_cu
*);
1273 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1274 struct attribute
*, struct attr_abbrev
*,
1275 const gdb_byte
*, bool *need_reprocess
);
1277 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1278 struct attribute
*attr
);
1280 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1282 static sect_offset read_abbrev_offset
1283 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1284 struct dwarf2_section_info
*, sect_offset
);
1286 static const char *read_indirect_string
1287 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1288 const struct comp_unit_head
*, unsigned int *);
1290 static const char *read_indirect_string_at_offset
1291 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1293 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1297 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1298 ULONGEST str_index
);
1300 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1301 ULONGEST str_index
);
1303 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1305 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1306 struct dwarf2_cu
*);
1308 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1309 struct dwarf2_cu
*cu
);
1311 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1313 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1314 struct dwarf2_cu
*cu
);
1316 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1318 static struct die_info
*die_specification (struct die_info
*die
,
1319 struct dwarf2_cu
**);
1321 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1322 struct dwarf2_cu
*cu
);
1324 static void dwarf_decode_lines (struct line_header
*, const char *,
1325 struct dwarf2_cu
*, dwarf2_psymtab
*,
1326 CORE_ADDR
, int decode_mapping
);
1328 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1331 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1332 struct dwarf2_cu
*, struct symbol
* = NULL
);
1334 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1335 struct dwarf2_cu
*);
1337 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1340 struct obstack
*obstack
,
1341 struct dwarf2_cu
*cu
, LONGEST
*value
,
1342 const gdb_byte
**bytes
,
1343 struct dwarf2_locexpr_baton
**baton
);
1345 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1347 static int need_gnat_info (struct dwarf2_cu
*);
1349 static struct type
*die_descriptive_type (struct die_info
*,
1350 struct dwarf2_cu
*);
1352 static void set_descriptive_type (struct type
*, struct die_info
*,
1353 struct dwarf2_cu
*);
1355 static struct type
*die_containing_type (struct die_info
*,
1356 struct dwarf2_cu
*);
1358 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1359 struct dwarf2_cu
*);
1361 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1363 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1365 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1367 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1368 const char *suffix
, int physname
,
1369 struct dwarf2_cu
*cu
);
1371 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1373 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1375 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1377 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1379 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1381 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1383 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1384 struct dwarf2_cu
*, dwarf2_psymtab
*);
1386 /* Return the .debug_loclists section to use for cu. */
1387 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1389 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1390 values. Keep the items ordered with increasing constraints compliance. */
1393 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1394 PC_BOUNDS_NOT_PRESENT
,
1396 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1397 were present but they do not form a valid range of PC addresses. */
1400 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1403 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1407 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1408 CORE_ADDR
*, CORE_ADDR
*,
1412 static void get_scope_pc_bounds (struct die_info
*,
1413 CORE_ADDR
*, CORE_ADDR
*,
1414 struct dwarf2_cu
*);
1416 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1417 CORE_ADDR
, struct dwarf2_cu
*);
1419 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1420 struct dwarf2_cu
*);
1422 static void dwarf2_attach_fields_to_type (struct field_info
*,
1423 struct type
*, struct dwarf2_cu
*);
1425 static void dwarf2_add_member_fn (struct field_info
*,
1426 struct die_info
*, struct type
*,
1427 struct dwarf2_cu
*);
1429 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1431 struct dwarf2_cu
*);
1433 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1435 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1437 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1439 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1441 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1443 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1445 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1447 static struct type
*read_module_type (struct die_info
*die
,
1448 struct dwarf2_cu
*cu
);
1450 static const char *namespace_name (struct die_info
*die
,
1451 int *is_anonymous
, struct dwarf2_cu
*);
1453 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1455 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1458 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1459 struct dwarf2_cu
*);
1461 static struct die_info
*read_die_and_siblings_1
1462 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1465 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1466 const gdb_byte
*info_ptr
,
1467 const gdb_byte
**new_info_ptr
,
1468 struct die_info
*parent
);
1470 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1471 struct die_info
**, const gdb_byte
*,
1474 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1475 struct die_info
**, const gdb_byte
*);
1477 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1479 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1482 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1484 static const char *dwarf2_full_name (const char *name
,
1485 struct die_info
*die
,
1486 struct dwarf2_cu
*cu
);
1488 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1489 struct dwarf2_cu
*cu
);
1491 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1492 struct dwarf2_cu
**);
1494 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1496 static void dump_die_for_error (struct die_info
*);
1498 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1501 /*static*/ void dump_die (struct die_info
*, int max_level
);
1503 static void store_in_ref_table (struct die_info
*,
1504 struct dwarf2_cu
*);
1506 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1507 const struct attribute
*,
1508 struct dwarf2_cu
**);
1510 static struct die_info
*follow_die_ref (struct die_info
*,
1511 const struct attribute
*,
1512 struct dwarf2_cu
**);
1514 static struct die_info
*follow_die_sig (struct die_info
*,
1515 const struct attribute
*,
1516 struct dwarf2_cu
**);
1518 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1519 struct dwarf2_cu
*);
1521 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1522 const struct attribute
*,
1523 struct dwarf2_cu
*);
1525 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1526 dwarf2_per_objfile
*per_objfile
);
1528 static void read_signatured_type (signatured_type
*sig_type
,
1529 dwarf2_per_objfile
*per_objfile
);
1531 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1532 struct die_info
*die
, struct dwarf2_cu
*cu
,
1533 struct dynamic_prop
*prop
, struct type
*type
);
1535 /* memory allocation interface */
1537 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1539 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1541 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1543 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1544 struct dwarf2_loclist_baton
*baton
,
1545 const struct attribute
*attr
);
1547 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1549 struct dwarf2_cu
*cu
,
1552 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1553 const gdb_byte
*info_ptr
,
1554 struct abbrev_info
*abbrev
);
1556 static hashval_t
partial_die_hash (const void *item
);
1558 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1560 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1561 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1562 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1564 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1565 struct die_info
*comp_unit_die
,
1566 enum language pretend_language
);
1568 static struct type
*set_die_type (struct die_info
*, struct type
*,
1569 struct dwarf2_cu
*);
1571 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1573 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1575 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1576 dwarf2_per_objfile
*per_objfile
,
1578 enum language pretend_language
);
1580 static void process_full_comp_unit (dwarf2_cu
*cu
,
1581 enum language pretend_language
);
1583 static void process_full_type_unit (dwarf2_cu
*cu
,
1584 enum language pretend_language
);
1586 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1587 struct dwarf2_per_cu_data
*);
1589 static void dwarf2_mark (struct dwarf2_cu
*);
1591 static struct type
*get_die_type_at_offset (sect_offset
,
1592 dwarf2_per_cu_data
*per_cu
,
1593 dwarf2_per_objfile
*per_objfile
);
1595 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1597 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1598 dwarf2_per_objfile
*per_objfile
,
1599 enum language pretend_language
);
1601 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1603 /* Class, the destructor of which frees all allocated queue entries. This
1604 will only have work to do if an error was thrown while processing the
1605 dwarf. If no error was thrown then the queue entries should have all
1606 been processed, and freed, as we went along. */
1608 class dwarf2_queue_guard
1611 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1612 : m_per_objfile (per_objfile
)
1616 /* Free any entries remaining on the queue. There should only be
1617 entries left if we hit an error while processing the dwarf. */
1618 ~dwarf2_queue_guard ()
1620 /* Ensure that no memory is allocated by the queue. */
1621 std::queue
<dwarf2_queue_item
> empty
;
1622 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1625 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1628 dwarf2_per_objfile
*m_per_objfile
;
1631 dwarf2_queue_item::~dwarf2_queue_item ()
1633 /* Anything still marked queued is likely to be in an
1634 inconsistent state, so discard it. */
1637 per_objfile
->remove_cu (per_cu
);
1642 /* The return type of find_file_and_directory. Note, the enclosed
1643 string pointers are only valid while this object is valid. */
1645 struct file_and_directory
1647 /* The filename. This is never NULL. */
1650 /* The compilation directory. NULL if not known. If we needed to
1651 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1652 points directly to the DW_AT_comp_dir string attribute owned by
1653 the obstack that owns the DIE. */
1654 const char *comp_dir
;
1656 /* If we needed to build a new string for comp_dir, this is what
1657 owns the storage. */
1658 std::string comp_dir_storage
;
1661 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1662 struct dwarf2_cu
*cu
);
1664 static htab_up
allocate_signatured_type_table ();
1666 static htab_up
allocate_dwo_unit_table ();
1668 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1669 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1670 struct dwp_file
*dwp_file
, const char *comp_dir
,
1671 ULONGEST signature
, int is_debug_types
);
1673 static struct dwp_file
*get_dwp_file
1674 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1676 static struct dwo_unit
*lookup_dwo_comp_unit
1677 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1678 ULONGEST signature
);
1680 static struct dwo_unit
*lookup_dwo_type_unit
1681 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1683 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1685 /* A unique pointer to a dwo_file. */
1687 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1689 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1691 static void check_producer (struct dwarf2_cu
*cu
);
1693 static void free_line_header_voidp (void *arg
);
1695 /* Various complaints about symbol reading that don't abort the process. */
1698 dwarf2_debug_line_missing_file_complaint (void)
1700 complaint (_(".debug_line section has line data without a file"));
1704 dwarf2_debug_line_missing_end_sequence_complaint (void)
1706 complaint (_(".debug_line section has line "
1707 "program sequence without an end"));
1711 dwarf2_complex_location_expr_complaint (void)
1713 complaint (_("location expression too complex"));
1717 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1720 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1725 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1727 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1731 /* Hash function for line_header_hash. */
1734 line_header_hash (const struct line_header
*ofs
)
1736 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1739 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1742 line_header_hash_voidp (const void *item
)
1744 const struct line_header
*ofs
= (const struct line_header
*) item
;
1746 return line_header_hash (ofs
);
1749 /* Equality function for line_header_hash. */
1752 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1754 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1755 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1757 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1758 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1763 /* See declaration. */
1765 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1768 can_copy (can_copy_
)
1771 names
= &dwarf2_elf_names
;
1773 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1774 locate_sections (obfd
, sec
, *names
);
1777 dwarf2_per_bfd::~dwarf2_per_bfd ()
1779 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1780 per_cu
->imported_symtabs_free ();
1782 for (signatured_type
*sig_type
: all_type_units
)
1783 sig_type
->per_cu
.imported_symtabs_free ();
1785 /* Everything else should be on this->obstack. */
1791 dwarf2_per_objfile::remove_all_cus ()
1793 for (auto pair
: m_dwarf2_cus
)
1796 m_dwarf2_cus
.clear ();
1799 /* A helper class that calls free_cached_comp_units on
1802 class free_cached_comp_units
1806 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1807 : m_per_objfile (per_objfile
)
1811 ~free_cached_comp_units ()
1813 m_per_objfile
->remove_all_cus ();
1816 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1820 dwarf2_per_objfile
*m_per_objfile
;
1826 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1828 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1830 return this->m_symtabs
[per_cu
->index
] != nullptr;
1836 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1838 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1840 return this->m_symtabs
[per_cu
->index
];
1846 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1847 compunit_symtab
*symtab
)
1849 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1850 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1852 this->m_symtabs
[per_cu
->index
] = symtab
;
1855 /* Try to locate the sections we need for DWARF 2 debugging
1856 information and return true if we have enough to do something.
1857 NAMES points to the dwarf2 section names, or is NULL if the standard
1858 ELF names are used. CAN_COPY is true for formats where symbol
1859 interposition is possible and so symbol values must follow copy
1860 relocation rules. */
1863 dwarf2_has_info (struct objfile
*objfile
,
1864 const struct dwarf2_debug_sections
*names
,
1867 if (objfile
->flags
& OBJF_READNEVER
)
1870 struct dwarf2_per_objfile
*dwarf2_per_objfile
1871 = get_dwarf2_per_objfile (objfile
);
1873 if (dwarf2_per_objfile
== NULL
)
1875 dwarf2_per_bfd
*per_bfd
;
1877 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1878 doesn't require relocations and if there aren't partial symbols
1879 from some other reader. */
1880 if (!objfile_has_partial_symbols (objfile
)
1881 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1883 /* See if one has been created for this BFD yet. */
1884 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1886 if (per_bfd
== nullptr)
1888 /* No, create it now. */
1889 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1890 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1895 /* No sharing possible, create one specifically for this objfile. */
1896 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1897 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1900 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1903 return (!dwarf2_per_objfile
->per_bfd
->info
.is_virtual
1904 && dwarf2_per_objfile
->per_bfd
->info
.s
.section
!= NULL
1905 && !dwarf2_per_objfile
->per_bfd
->abbrev
.is_virtual
1906 && dwarf2_per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1909 /* When loading sections, we look either for uncompressed section or for
1910 compressed section names. */
1913 section_is_p (const char *section_name
,
1914 const struct dwarf2_section_names
*names
)
1916 if (names
->normal
!= NULL
1917 && strcmp (section_name
, names
->normal
) == 0)
1919 if (names
->compressed
!= NULL
1920 && strcmp (section_name
, names
->compressed
) == 0)
1925 /* See declaration. */
1928 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1929 const dwarf2_debug_sections
&names
)
1931 flagword aflag
= bfd_section_flags (sectp
);
1933 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1936 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1937 > bfd_get_file_size (abfd
))
1939 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1940 warning (_("Discarding section %s which has a section size (%s"
1941 ") larger than the file size [in module %s]"),
1942 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1943 bfd_get_filename (abfd
));
1945 else if (section_is_p (sectp
->name
, &names
.info
))
1947 this->info
.s
.section
= sectp
;
1948 this->info
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1952 this->abbrev
.s
.section
= sectp
;
1953 this->abbrev
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.line
))
1957 this->line
.s
.section
= sectp
;
1958 this->line
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.loc
))
1962 this->loc
.s
.section
= sectp
;
1963 this->loc
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.loclists
))
1967 this->loclists
.s
.section
= sectp
;
1968 this->loclists
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1972 this->macinfo
.s
.section
= sectp
;
1973 this->macinfo
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.macro
))
1977 this->macro
.s
.section
= sectp
;
1978 this->macro
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.str
))
1982 this->str
.s
.section
= sectp
;
1983 this->str
.size
= bfd_section_size (sectp
);
1985 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1987 this->str_offsets
.s
.section
= sectp
;
1988 this->str_offsets
.size
= bfd_section_size (sectp
);
1990 else if (section_is_p (sectp
->name
, &names
.line_str
))
1992 this->line_str
.s
.section
= sectp
;
1993 this->line_str
.size
= bfd_section_size (sectp
);
1995 else if (section_is_p (sectp
->name
, &names
.addr
))
1997 this->addr
.s
.section
= sectp
;
1998 this->addr
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.frame
))
2002 this->frame
.s
.section
= sectp
;
2003 this->frame
.size
= bfd_section_size (sectp
);
2005 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2007 this->eh_frame
.s
.section
= sectp
;
2008 this->eh_frame
.size
= bfd_section_size (sectp
);
2010 else if (section_is_p (sectp
->name
, &names
.ranges
))
2012 this->ranges
.s
.section
= sectp
;
2013 this->ranges
.size
= bfd_section_size (sectp
);
2015 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2017 this->rnglists
.s
.section
= sectp
;
2018 this->rnglists
.size
= bfd_section_size (sectp
);
2020 else if (section_is_p (sectp
->name
, &names
.types
))
2022 struct dwarf2_section_info type_section
;
2024 memset (&type_section
, 0, sizeof (type_section
));
2025 type_section
.s
.section
= sectp
;
2026 type_section
.size
= bfd_section_size (sectp
);
2028 this->types
.push_back (type_section
);
2030 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2032 this->gdb_index
.s
.section
= sectp
;
2033 this->gdb_index
.size
= bfd_section_size (sectp
);
2035 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2037 this->debug_names
.s
.section
= sectp
;
2038 this->debug_names
.size
= bfd_section_size (sectp
);
2040 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2042 this->debug_aranges
.s
.section
= sectp
;
2043 this->debug_aranges
.size
= bfd_section_size (sectp
);
2046 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2047 && bfd_section_vma (sectp
) == 0)
2048 this->has_section_at_zero
= true;
2051 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2055 dwarf2_get_section_info (struct objfile
*objfile
,
2056 enum dwarf2_section_enum sect
,
2057 asection
**sectp
, const gdb_byte
**bufp
,
2058 bfd_size_type
*sizep
)
2060 struct dwarf2_per_objfile
*data
= get_dwarf2_per_objfile (objfile
);
2061 struct dwarf2_section_info
*info
;
2063 /* We may see an objfile without any DWARF, in which case we just
2074 case DWARF2_DEBUG_FRAME
:
2075 info
= &data
->per_bfd
->frame
;
2077 case DWARF2_EH_FRAME
:
2078 info
= &data
->per_bfd
->eh_frame
;
2081 gdb_assert_not_reached ("unexpected section");
2084 info
->read (objfile
);
2086 *sectp
= info
->get_bfd_section ();
2087 *bufp
= info
->buffer
;
2088 *sizep
= info
->size
;
2091 /* A helper function to find the sections for a .dwz file. */
2094 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2096 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2098 /* Note that we only support the standard ELF names, because .dwz
2099 is ELF-only (at the time of writing). */
2100 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2102 dwz_file
->abbrev
.s
.section
= sectp
;
2103 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2105 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2107 dwz_file
->info
.s
.section
= sectp
;
2108 dwz_file
->info
.size
= bfd_section_size (sectp
);
2110 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2112 dwz_file
->str
.s
.section
= sectp
;
2113 dwz_file
->str
.size
= bfd_section_size (sectp
);
2115 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2117 dwz_file
->line
.s
.section
= sectp
;
2118 dwz_file
->line
.size
= bfd_section_size (sectp
);
2120 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2122 dwz_file
->macro
.s
.section
= sectp
;
2123 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2125 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2127 dwz_file
->gdb_index
.s
.section
= sectp
;
2128 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2130 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2132 dwz_file
->debug_names
.s
.section
= sectp
;
2133 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2137 /* See dwarf2read.h. */
2140 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2142 const char *filename
;
2143 bfd_size_type buildid_len_arg
;
2147 if (per_bfd
->dwz_file
!= NULL
)
2148 return per_bfd
->dwz_file
.get ();
2150 bfd_set_error (bfd_error_no_error
);
2151 gdb::unique_xmalloc_ptr
<char> data
2152 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2153 &buildid_len_arg
, &buildid
));
2156 if (bfd_get_error () == bfd_error_no_error
)
2158 error (_("could not read '.gnu_debugaltlink' section: %s"),
2159 bfd_errmsg (bfd_get_error ()));
2162 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2164 buildid_len
= (size_t) buildid_len_arg
;
2166 filename
= data
.get ();
2168 std::string abs_storage
;
2169 if (!IS_ABSOLUTE_PATH (filename
))
2171 gdb::unique_xmalloc_ptr
<char> abs
2172 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2174 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2175 filename
= abs_storage
.c_str ();
2178 /* First try the file name given in the section. If that doesn't
2179 work, try to use the build-id instead. */
2180 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2181 if (dwz_bfd
!= NULL
)
2183 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2184 dwz_bfd
.reset (nullptr);
2187 if (dwz_bfd
== NULL
)
2188 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2190 if (dwz_bfd
== nullptr)
2192 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2193 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2195 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2202 /* File successfully retrieved from server. */
2203 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2205 if (dwz_bfd
== nullptr)
2206 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2207 alt_filename
.get ());
2208 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2209 dwz_bfd
.reset (nullptr);
2213 if (dwz_bfd
== NULL
)
2214 error (_("could not find '.gnu_debugaltlink' file for %s"),
2215 bfd_get_filename (per_bfd
->obfd
));
2217 std::unique_ptr
<struct dwz_file
> result
2218 (new struct dwz_file (std::move (dwz_bfd
)));
2220 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2223 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2224 per_bfd
->dwz_file
= std::move (result
);
2225 return per_bfd
->dwz_file
.get ();
2228 /* DWARF quick_symbols_functions support. */
2230 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2231 unique line tables, so we maintain a separate table of all .debug_line
2232 derived entries to support the sharing.
2233 All the quick functions need is the list of file names. We discard the
2234 line_header when we're done and don't need to record it here. */
2235 struct quick_file_names
2237 /* The data used to construct the hash key. */
2238 struct stmt_list_hash hash
;
2240 /* The number of entries in file_names, real_names. */
2241 unsigned int num_file_names
;
2243 /* The file names from the line table, after being run through
2245 const char **file_names
;
2247 /* The file names from the line table after being run through
2248 gdb_realpath. These are computed lazily. */
2249 const char **real_names
;
2252 /* When using the index (and thus not using psymtabs), each CU has an
2253 object of this type. This is used to hold information needed by
2254 the various "quick" methods. */
2255 struct dwarf2_per_cu_quick_data
2257 /* The file table. This can be NULL if there was no file table
2258 or it's currently not read in.
2259 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2260 struct quick_file_names
*file_names
;
2262 /* A temporary mark bit used when iterating over all CUs in
2263 expand_symtabs_matching. */
2264 unsigned int mark
: 1;
2266 /* True if we've tried to read the file table and found there isn't one.
2267 There will be no point in trying to read it again next time. */
2268 unsigned int no_file_data
: 1;
2271 /* Utility hash function for a stmt_list_hash. */
2274 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2278 if (stmt_list_hash
->dwo_unit
!= NULL
)
2279 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2280 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2284 /* Utility equality function for a stmt_list_hash. */
2287 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2288 const struct stmt_list_hash
*rhs
)
2290 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2292 if (lhs
->dwo_unit
!= NULL
2293 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2296 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2299 /* Hash function for a quick_file_names. */
2302 hash_file_name_entry (const void *e
)
2304 const struct quick_file_names
*file_data
2305 = (const struct quick_file_names
*) e
;
2307 return hash_stmt_list_entry (&file_data
->hash
);
2310 /* Equality function for a quick_file_names. */
2313 eq_file_name_entry (const void *a
, const void *b
)
2315 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2316 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2318 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2321 /* Delete function for a quick_file_names. */
2324 delete_file_name_entry (void *e
)
2326 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2329 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2331 xfree ((void*) file_data
->file_names
[i
]);
2332 if (file_data
->real_names
)
2333 xfree ((void*) file_data
->real_names
[i
]);
2336 /* The space for the struct itself lives on the obstack, so we don't
2340 /* Create a quick_file_names hash table. */
2343 create_quick_file_names_table (unsigned int nr_initial_entries
)
2345 return htab_up (htab_create_alloc (nr_initial_entries
,
2346 hash_file_name_entry
, eq_file_name_entry
,
2347 delete_file_name_entry
, xcalloc
, xfree
));
2350 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2351 function is unrelated to symtabs, symtab would have to be created afterwards.
2352 You should call age_cached_comp_units after processing the CU. */
2355 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2358 if (per_cu
->is_debug_types
)
2359 load_full_type_unit (per_cu
, per_objfile
);
2361 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2363 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2365 return nullptr; /* Dummy CU. */
2367 dwarf2_find_base_address (cu
->dies
, cu
);
2372 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2375 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2376 dwarf2_per_objfile
*dwarf2_per_objfile
,
2379 /* Skip type_unit_groups, reading the type units they contain
2380 is handled elsewhere. */
2381 if (per_cu
->type_unit_group_p ())
2384 /* The destructor of dwarf2_queue_guard frees any entries left on
2385 the queue. After this point we're guaranteed to leave this function
2386 with the dwarf queue empty. */
2387 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2389 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2391 queue_comp_unit (per_cu
, dwarf2_per_objfile
, language_minimal
);
2392 dwarf2_cu
*cu
= load_cu (per_cu
, dwarf2_per_objfile
, skip_partial
);
2394 /* If we just loaded a CU from a DWO, and we're working with an index
2395 that may badly handle TUs, load all the TUs in that DWO as well.
2396 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2397 if (!per_cu
->is_debug_types
2399 && cu
->dwo_unit
!= NULL
2400 && dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
2401 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7
2402 /* DWP files aren't supported yet. */
2403 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2404 queue_and_load_all_dwo_tus (cu
);
2407 process_queue (dwarf2_per_objfile
);
2409 /* Age the cache, releasing compilation units that have not
2410 been used recently. */
2411 dwarf2_per_objfile
->age_comp_units ();
2414 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2415 the per-objfile for which this symtab is instantiated.
2417 Returns the resulting symbol table. */
2419 static struct compunit_symtab
*
2420 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2421 dwarf2_per_objfile
*dwarf2_per_objfile
,
2424 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
2426 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2428 free_cached_comp_units
freer (dwarf2_per_objfile
);
2429 scoped_restore decrementer
= increment_reading_symtab ();
2430 dw2_do_instantiate_symtab (per_cu
, dwarf2_per_objfile
, skip_partial
);
2431 process_cu_includes (dwarf2_per_objfile
);
2434 return dwarf2_per_objfile
->get_symtab (per_cu
);
2437 /* See declaration. */
2439 dwarf2_per_cu_data
*
2440 dwarf2_per_bfd::get_cutu (int index
)
2442 if (index
>= this->all_comp_units
.size ())
2444 index
-= this->all_comp_units
.size ();
2445 gdb_assert (index
< this->all_type_units
.size ());
2446 return &this->all_type_units
[index
]->per_cu
;
2449 return this->all_comp_units
[index
];
2452 /* See declaration. */
2454 dwarf2_per_cu_data
*
2455 dwarf2_per_bfd::get_cu (int index
)
2457 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2459 return this->all_comp_units
[index
];
2462 /* See declaration. */
2465 dwarf2_per_bfd::get_tu (int index
)
2467 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2469 return this->all_type_units
[index
];
2474 dwarf2_per_cu_data
*
2475 dwarf2_per_bfd::allocate_per_cu ()
2477 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2478 result
->per_bfd
= this;
2479 result
->index
= m_num_psymtabs
++;
2486 dwarf2_per_bfd::allocate_signatured_type ()
2488 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2489 result
->per_cu
.per_bfd
= this;
2490 result
->per_cu
.index
= m_num_psymtabs
++;
2494 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2495 obstack, and constructed with the specified field values. */
2497 static dwarf2_per_cu_data
*
2498 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2499 struct dwarf2_section_info
*section
,
2501 sect_offset sect_off
, ULONGEST length
)
2503 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2504 the_cu
->sect_off
= sect_off
;
2505 the_cu
->length
= length
;
2506 the_cu
->section
= section
;
2507 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2508 struct dwarf2_per_cu_quick_data
);
2509 the_cu
->is_dwz
= is_dwz
;
2513 /* A helper for create_cus_from_index that handles a given list of
2517 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2518 const gdb_byte
*cu_list
, offset_type n_elements
,
2519 struct dwarf2_section_info
*section
,
2522 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2524 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2526 sect_offset sect_off
2527 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2528 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2531 dwarf2_per_cu_data
*per_cu
2532 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2534 per_bfd
->all_comp_units
.push_back (per_cu
);
2538 /* Read the CU list from the mapped index, and use it to create all
2539 the CU objects for PER_BFD. */
2542 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2543 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2544 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2546 gdb_assert (per_bfd
->all_comp_units
.empty ());
2547 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2549 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2552 if (dwz_elements
== 0)
2555 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2556 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2560 /* Create the signatured type hash table from the index. */
2563 create_signatured_type_table_from_index
2564 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2565 const gdb_byte
*bytes
, offset_type elements
)
2567 gdb_assert (per_bfd
->all_type_units
.empty ());
2568 per_bfd
->all_type_units
.reserve (elements
/ 3);
2570 htab_up sig_types_hash
= allocate_signatured_type_table ();
2572 for (offset_type i
= 0; i
< elements
; i
+= 3)
2574 struct signatured_type
*sig_type
;
2577 cu_offset type_offset_in_tu
;
2579 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2580 sect_offset sect_off
2581 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2583 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2585 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2588 sig_type
= per_bfd
->allocate_signatured_type ();
2589 sig_type
->signature
= signature
;
2590 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2591 sig_type
->per_cu
.is_debug_types
= 1;
2592 sig_type
->per_cu
.section
= section
;
2593 sig_type
->per_cu
.sect_off
= sect_off
;
2594 sig_type
->per_cu
.v
.quick
2595 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2596 struct dwarf2_per_cu_quick_data
);
2598 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2601 per_bfd
->all_type_units
.push_back (sig_type
);
2604 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2607 /* Create the signatured type hash table from .debug_names. */
2610 create_signatured_type_table_from_debug_names
2611 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2612 const mapped_debug_names
&map
,
2613 struct dwarf2_section_info
*section
,
2614 struct dwarf2_section_info
*abbrev_section
)
2616 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2618 section
->read (objfile
);
2619 abbrev_section
->read (objfile
);
2621 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2622 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2624 htab_up sig_types_hash
= allocate_signatured_type_table ();
2626 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2628 struct signatured_type
*sig_type
;
2631 sect_offset sect_off
2632 = (sect_offset
) (extract_unsigned_integer
2633 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2635 map
.dwarf5_byte_order
));
2637 comp_unit_head cu_header
;
2638 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2640 section
->buffer
+ to_underlying (sect_off
),
2643 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2644 sig_type
->signature
= cu_header
.signature
;
2645 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2646 sig_type
->per_cu
.is_debug_types
= 1;
2647 sig_type
->per_cu
.section
= section
;
2648 sig_type
->per_cu
.sect_off
= sect_off
;
2649 sig_type
->per_cu
.v
.quick
2650 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2651 struct dwarf2_per_cu_quick_data
);
2653 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2656 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2659 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2662 /* Read the address map data from the mapped index, and use it to
2663 populate the objfile's psymtabs_addrmap. */
2666 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2667 struct mapped_index
*index
)
2669 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2670 struct gdbarch
*gdbarch
= objfile
->arch ();
2671 const gdb_byte
*iter
, *end
;
2672 struct addrmap
*mutable_map
;
2675 auto_obstack temp_obstack
;
2677 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2679 iter
= index
->address_table
.data ();
2680 end
= iter
+ index
->address_table
.size ();
2682 baseaddr
= objfile
->text_section_offset ();
2686 ULONGEST hi
, lo
, cu_index
;
2687 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2689 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2691 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2696 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2697 hex_string (lo
), hex_string (hi
));
2701 if (cu_index
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
2703 complaint (_(".gdb_index address table has invalid CU number %u"),
2704 (unsigned) cu_index
);
2708 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2709 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2710 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2711 dwarf2_per_objfile
->per_bfd
->get_cu (cu_index
));
2714 objfile
->partial_symtabs
->psymtabs_addrmap
2715 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2718 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2719 populate the objfile's psymtabs_addrmap. */
2722 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2723 struct dwarf2_section_info
*section
)
2725 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2726 bfd
*abfd
= objfile
->obfd
;
2727 struct gdbarch
*gdbarch
= objfile
->arch ();
2728 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2730 auto_obstack temp_obstack
;
2731 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2733 std::unordered_map
<sect_offset
,
2734 dwarf2_per_cu_data
*,
2735 gdb::hash_enum
<sect_offset
>>
2736 debug_info_offset_to_per_cu
;
2737 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
2739 const auto insertpair
2740 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2741 if (!insertpair
.second
)
2743 warning (_("Section .debug_aranges in %s has duplicate "
2744 "debug_info_offset %s, ignoring .debug_aranges."),
2745 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2750 section
->read (objfile
);
2752 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2754 const gdb_byte
*addr
= section
->buffer
;
2756 while (addr
< section
->buffer
+ section
->size
)
2758 const gdb_byte
*const entry_addr
= addr
;
2759 unsigned int bytes_read
;
2761 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2765 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2766 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2767 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2768 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2770 warning (_("Section .debug_aranges in %s entry at offset %s "
2771 "length %s exceeds section length %s, "
2772 "ignoring .debug_aranges."),
2773 objfile_name (objfile
),
2774 plongest (entry_addr
- section
->buffer
),
2775 plongest (bytes_read
+ entry_length
),
2776 pulongest (section
->size
));
2780 /* The version number. */
2781 const uint16_t version
= read_2_bytes (abfd
, addr
);
2785 warning (_("Section .debug_aranges in %s entry at offset %s "
2786 "has unsupported version %d, ignoring .debug_aranges."),
2787 objfile_name (objfile
),
2788 plongest (entry_addr
- section
->buffer
), version
);
2792 const uint64_t debug_info_offset
2793 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2794 addr
+= offset_size
;
2795 const auto per_cu_it
2796 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2797 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2799 warning (_("Section .debug_aranges in %s entry at offset %s "
2800 "debug_info_offset %s does not exists, "
2801 "ignoring .debug_aranges."),
2802 objfile_name (objfile
),
2803 plongest (entry_addr
- section
->buffer
),
2804 pulongest (debug_info_offset
));
2807 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2809 const uint8_t address_size
= *addr
++;
2810 if (address_size
< 1 || address_size
> 8)
2812 warning (_("Section .debug_aranges in %s entry at offset %s "
2813 "address_size %u is invalid, ignoring .debug_aranges."),
2814 objfile_name (objfile
),
2815 plongest (entry_addr
- section
->buffer
), address_size
);
2819 const uint8_t segment_selector_size
= *addr
++;
2820 if (segment_selector_size
!= 0)
2822 warning (_("Section .debug_aranges in %s entry at offset %s "
2823 "segment_selector_size %u is not supported, "
2824 "ignoring .debug_aranges."),
2825 objfile_name (objfile
),
2826 plongest (entry_addr
- section
->buffer
),
2827 segment_selector_size
);
2831 /* Must pad to an alignment boundary that is twice the address
2832 size. It is undocumented by the DWARF standard but GCC does
2834 for (size_t padding
= ((-(addr
- section
->buffer
))
2835 & (2 * address_size
- 1));
2836 padding
> 0; padding
--)
2839 warning (_("Section .debug_aranges in %s entry at offset %s "
2840 "padding is not zero, ignoring .debug_aranges."),
2841 objfile_name (objfile
),
2842 plongest (entry_addr
- section
->buffer
));
2848 if (addr
+ 2 * address_size
> entry_end
)
2850 warning (_("Section .debug_aranges in %s entry at offset %s "
2851 "address list is not properly terminated, "
2852 "ignoring .debug_aranges."),
2853 objfile_name (objfile
),
2854 plongest (entry_addr
- section
->buffer
));
2857 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2859 addr
+= address_size
;
2860 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2862 addr
+= address_size
;
2863 if (start
== 0 && length
== 0)
2865 if (start
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
2867 /* Symbol was eliminated due to a COMDAT group. */
2870 ULONGEST end
= start
+ length
;
2871 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2873 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2875 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2879 objfile
->partial_symtabs
->psymtabs_addrmap
2880 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2883 /* Find a slot in the mapped index INDEX for the object named NAME.
2884 If NAME is found, set *VEC_OUT to point to the CU vector in the
2885 constant pool and return true. If NAME cannot be found, return
2889 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2890 offset_type
**vec_out
)
2893 offset_type slot
, step
;
2894 int (*cmp
) (const char *, const char *);
2896 gdb::unique_xmalloc_ptr
<char> without_params
;
2897 if (current_language
->la_language
== language_cplus
2898 || current_language
->la_language
== language_fortran
2899 || current_language
->la_language
== language_d
)
2901 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2904 if (strchr (name
, '(') != NULL
)
2906 without_params
= cp_remove_params (name
);
2908 if (without_params
!= NULL
)
2909 name
= without_params
.get ();
2913 /* Index version 4 did not support case insensitive searches. But the
2914 indices for case insensitive languages are built in lowercase, therefore
2915 simulate our NAME being searched is also lowercased. */
2916 hash
= mapped_index_string_hash ((index
->version
== 4
2917 && case_sensitivity
== case_sensitive_off
2918 ? 5 : index
->version
),
2921 slot
= hash
& (index
->symbol_table
.size () - 1);
2922 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2923 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2929 const auto &bucket
= index
->symbol_table
[slot
];
2930 if (bucket
.name
== 0 && bucket
.vec
== 0)
2933 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2934 if (!cmp (name
, str
))
2936 *vec_out
= (offset_type
*) (index
->constant_pool
2937 + MAYBE_SWAP (bucket
.vec
));
2941 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2945 /* A helper function that reads the .gdb_index from BUFFER and fills
2946 in MAP. FILENAME is the name of the file containing the data;
2947 it is used for error reporting. DEPRECATED_OK is true if it is
2948 ok to use deprecated sections.
2950 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2951 out parameters that are filled in with information about the CU and
2952 TU lists in the section.
2954 Returns true if all went well, false otherwise. */
2957 read_gdb_index_from_buffer (const char *filename
,
2959 gdb::array_view
<const gdb_byte
> buffer
,
2960 struct mapped_index
*map
,
2961 const gdb_byte
**cu_list
,
2962 offset_type
*cu_list_elements
,
2963 const gdb_byte
**types_list
,
2964 offset_type
*types_list_elements
)
2966 const gdb_byte
*addr
= &buffer
[0];
2968 /* Version check. */
2969 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2970 /* Versions earlier than 3 emitted every copy of a psymbol. This
2971 causes the index to behave very poorly for certain requests. Version 3
2972 contained incomplete addrmap. So, it seems better to just ignore such
2976 static int warning_printed
= 0;
2977 if (!warning_printed
)
2979 warning (_("Skipping obsolete .gdb_index section in %s."),
2981 warning_printed
= 1;
2985 /* Index version 4 uses a different hash function than index version
2988 Versions earlier than 6 did not emit psymbols for inlined
2989 functions. Using these files will cause GDB not to be able to
2990 set breakpoints on inlined functions by name, so we ignore these
2991 indices unless the user has done
2992 "set use-deprecated-index-sections on". */
2993 if (version
< 6 && !deprecated_ok
)
2995 static int warning_printed
= 0;
2996 if (!warning_printed
)
2999 Skipping deprecated .gdb_index section in %s.\n\
3000 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3001 to use the section anyway."),
3003 warning_printed
= 1;
3007 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3008 of the TU (for symbols coming from TUs),
3009 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3010 Plus gold-generated indices can have duplicate entries for global symbols,
3011 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3012 These are just performance bugs, and we can't distinguish gdb-generated
3013 indices from gold-generated ones, so issue no warning here. */
3015 /* Indexes with higher version than the one supported by GDB may be no
3016 longer backward compatible. */
3020 map
->version
= version
;
3022 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3025 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3026 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3030 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3031 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3032 - MAYBE_SWAP (metadata
[i
]))
3036 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3037 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3039 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3042 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3043 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3045 = gdb::array_view
<mapped_index::symbol_table_slot
>
3046 ((mapped_index::symbol_table_slot
*) symbol_table
,
3047 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3050 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3055 /* Callback types for dwarf2_read_gdb_index. */
3057 typedef gdb::function_view
3058 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3059 get_gdb_index_contents_ftype
;
3060 typedef gdb::function_view
3061 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3062 get_gdb_index_contents_dwz_ftype
;
3064 /* Read .gdb_index. If everything went ok, initialize the "quick"
3065 elements of all the CUs and return 1. Otherwise, return 0. */
3068 dwarf2_read_gdb_index
3069 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3070 get_gdb_index_contents_ftype get_gdb_index_contents
,
3071 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3073 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3074 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3075 struct dwz_file
*dwz
;
3076 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3078 gdb::array_view
<const gdb_byte
> main_index_contents
3079 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
->per_bfd
);
3081 if (main_index_contents
.empty ())
3084 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3085 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3086 use_deprecated_index_sections
,
3087 main_index_contents
, map
.get (), &cu_list
,
3088 &cu_list_elements
, &types_list
,
3089 &types_list_elements
))
3092 /* Don't use the index if it's empty. */
3093 if (map
->symbol_table
.empty ())
3096 /* If there is a .dwz file, read it so we can get its CU list as
3098 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
3101 struct mapped_index dwz_map
;
3102 const gdb_byte
*dwz_types_ignore
;
3103 offset_type dwz_types_elements_ignore
;
3105 gdb::array_view
<const gdb_byte
> dwz_index_content
3106 = get_gdb_index_contents_dwz (objfile
, dwz
);
3108 if (dwz_index_content
.empty ())
3111 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3112 1, dwz_index_content
, &dwz_map
,
3113 &dwz_list
, &dwz_list_elements
,
3115 &dwz_types_elements_ignore
))
3117 warning (_("could not read '.gdb_index' section from %s; skipping"),
3118 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3123 create_cus_from_index (dwarf2_per_objfile
->per_bfd
, cu_list
, cu_list_elements
,
3124 dwz_list
, dwz_list_elements
);
3126 if (types_list_elements
)
3128 /* We can only handle a single .debug_types when we have an
3130 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
3133 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
3135 create_signatured_type_table_from_index (dwarf2_per_objfile
->per_bfd
,
3136 section
, types_list
,
3137 types_list_elements
);
3140 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3142 dwarf2_per_objfile
->per_bfd
->index_table
= std::move (map
);
3143 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
3144 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
3145 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
3150 /* die_reader_func for dw2_get_file_names. */
3153 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3154 const gdb_byte
*info_ptr
,
3155 struct die_info
*comp_unit_die
)
3157 struct dwarf2_cu
*cu
= reader
->cu
;
3158 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3159 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
3160 struct dwarf2_per_cu_data
*lh_cu
;
3161 struct attribute
*attr
;
3163 struct quick_file_names
*qfn
;
3165 gdb_assert (! this_cu
->is_debug_types
);
3167 /* Our callers never want to match partial units -- instead they
3168 will match the enclosing full CU. */
3169 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3171 this_cu
->v
.quick
->no_file_data
= 1;
3179 sect_offset line_offset
{};
3181 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3182 if (attr
!= nullptr)
3184 struct quick_file_names find_entry
;
3186 line_offset
= (sect_offset
) DW_UNSND (attr
);
3188 /* We may have already read in this line header (TU line header sharing).
3189 If we have we're done. */
3190 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3191 find_entry
.hash
.line_sect_off
= line_offset
;
3192 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3193 &find_entry
, INSERT
);
3196 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3200 lh
= dwarf_decode_line_header (line_offset
, cu
);
3204 lh_cu
->v
.quick
->no_file_data
= 1;
3208 qfn
= XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3209 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3210 qfn
->hash
.line_sect_off
= line_offset
;
3211 gdb_assert (slot
!= NULL
);
3214 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3217 if (strcmp (fnd
.name
, "<unknown>") != 0)
3220 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3222 XOBNEWVEC (&dwarf2_per_objfile
->per_bfd
->obstack
, const char *,
3223 qfn
->num_file_names
);
3225 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3226 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3227 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3228 fnd
.comp_dir
).release ();
3229 qfn
->real_names
= NULL
;
3231 lh_cu
->v
.quick
->file_names
= qfn
;
3234 /* A helper for the "quick" functions which attempts to read the line
3235 table for THIS_CU. */
3237 static struct quick_file_names
*
3238 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3239 dwarf2_per_objfile
*per_objfile
)
3241 /* This should never be called for TUs. */
3242 gdb_assert (! this_cu
->is_debug_types
);
3243 /* Nor type unit groups. */
3244 gdb_assert (! this_cu
->type_unit_group_p ());
3246 if (this_cu
->v
.quick
->file_names
!= NULL
)
3247 return this_cu
->v
.quick
->file_names
;
3248 /* If we know there is no line data, no point in looking again. */
3249 if (this_cu
->v
.quick
->no_file_data
)
3252 cutu_reader
reader (this_cu
, per_objfile
);
3253 if (!reader
.dummy_p
)
3254 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3256 if (this_cu
->v
.quick
->no_file_data
)
3258 return this_cu
->v
.quick
->file_names
;
3261 /* A helper for the "quick" functions which computes and caches the
3262 real path for a given file name from the line table. */
3265 dw2_get_real_path (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3266 struct quick_file_names
*qfn
, int index
)
3268 if (qfn
->real_names
== NULL
)
3269 qfn
->real_names
= OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
3270 qfn
->num_file_names
, const char *);
3272 if (qfn
->real_names
[index
] == NULL
)
3273 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3275 return qfn
->real_names
[index
];
3278 static struct symtab
*
3279 dw2_find_last_source_symtab (struct objfile
*objfile
)
3281 struct dwarf2_per_objfile
*dwarf2_per_objfile
3282 = get_dwarf2_per_objfile (objfile
);
3283 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->per_bfd
->all_comp_units
.back ();
3284 compunit_symtab
*cust
3285 = dw2_instantiate_symtab (dwarf_cu
, dwarf2_per_objfile
, false);
3290 return compunit_primary_filetab (cust
);
3293 /* Traversal function for dw2_forget_cached_source_info. */
3296 dw2_free_cached_file_names (void **slot
, void *info
)
3298 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3300 if (file_data
->real_names
)
3304 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3306 xfree ((void*) file_data
->real_names
[i
]);
3307 file_data
->real_names
[i
] = NULL
;
3315 dw2_forget_cached_source_info (struct objfile
*objfile
)
3317 struct dwarf2_per_objfile
*dwarf2_per_objfile
3318 = get_dwarf2_per_objfile (objfile
);
3320 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3321 dw2_free_cached_file_names
, NULL
);
3324 /* Helper function for dw2_map_symtabs_matching_filename that expands
3325 the symtabs and calls the iterator. */
3328 dw2_map_expand_apply (struct objfile
*objfile
,
3329 struct dwarf2_per_cu_data
*per_cu
,
3330 const char *name
, const char *real_path
,
3331 gdb::function_view
<bool (symtab
*)> callback
)
3333 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3335 /* Don't visit already-expanded CUs. */
3336 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3337 if (per_objfile
->symtab_set_p (per_cu
))
3340 /* This may expand more than one symtab, and we want to iterate over
3342 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3344 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3345 last_made
, callback
);
3348 /* Implementation of the map_symtabs_matching_filename method. */
3351 dw2_map_symtabs_matching_filename
3352 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3353 gdb::function_view
<bool (symtab
*)> callback
)
3355 const char *name_basename
= lbasename (name
);
3356 struct dwarf2_per_objfile
*dwarf2_per_objfile
3357 = get_dwarf2_per_objfile (objfile
);
3359 /* The rule is CUs specify all the files, including those used by
3360 any TU, so there's no need to scan TUs here. */
3362 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3364 /* We only need to look at symtabs not already expanded. */
3365 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3368 quick_file_names
*file_data
3369 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3370 if (file_data
== NULL
)
3373 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3375 const char *this_name
= file_data
->file_names
[j
];
3376 const char *this_real_name
;
3378 if (compare_filenames_for_search (this_name
, name
))
3380 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3386 /* Before we invoke realpath, which can get expensive when many
3387 files are involved, do a quick comparison of the basenames. */
3388 if (! basenames_may_differ
3389 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3392 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
3394 if (compare_filenames_for_search (this_real_name
, name
))
3396 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3402 if (real_path
!= NULL
)
3404 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3405 gdb_assert (IS_ABSOLUTE_PATH (name
));
3406 if (this_real_name
!= NULL
3407 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3409 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3421 /* Struct used to manage iterating over all CUs looking for a symbol. */
3423 struct dw2_symtab_iterator
3425 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3426 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3427 /* If set, only look for symbols that match that block. Valid values are
3428 GLOBAL_BLOCK and STATIC_BLOCK. */
3429 gdb::optional
<block_enum
> block_index
;
3430 /* The kind of symbol we're looking for. */
3432 /* The list of CUs from the index entry of the symbol,
3433 or NULL if not found. */
3435 /* The next element in VEC to look at. */
3437 /* The number of elements in VEC, or zero if there is no match. */
3439 /* Have we seen a global version of the symbol?
3440 If so we can ignore all further global instances.
3441 This is to work around gold/15646, inefficient gold-generated
3446 /* Initialize the index symtab iterator ITER. */
3449 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3450 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3451 gdb::optional
<block_enum
> block_index
,
3455 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3456 iter
->block_index
= block_index
;
3457 iter
->domain
= domain
;
3459 iter
->global_seen
= 0;
3461 mapped_index
*index
= dwarf2_per_objfile
->per_bfd
->index_table
.get ();
3463 /* index is NULL if OBJF_READNOW. */
3464 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3465 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3473 /* Return the next matching CU or NULL if there are no more. */
3475 static struct dwarf2_per_cu_data
*
3476 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3478 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3480 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3482 offset_type cu_index_and_attrs
=
3483 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3484 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3485 gdb_index_symbol_kind symbol_kind
=
3486 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3487 /* Only check the symbol attributes if they're present.
3488 Indices prior to version 7 don't record them,
3489 and indices >= 7 may elide them for certain symbols
3490 (gold does this). */
3492 (dwarf2_per_objfile
->per_bfd
->index_table
->version
>= 7
3493 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3495 /* Don't crash on bad data. */
3496 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3497 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
3499 complaint (_(".gdb_index entry has bad CU index"
3501 objfile_name (dwarf2_per_objfile
->objfile
));
3505 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
3507 /* Skip if already read in. */
3508 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3511 /* Check static vs global. */
3514 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3516 if (iter
->block_index
.has_value ())
3518 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3520 if (is_static
!= want_static
)
3524 /* Work around gold/15646. */
3525 if (!is_static
&& iter
->global_seen
)
3528 iter
->global_seen
= 1;
3531 /* Only check the symbol's kind if it has one. */
3534 switch (iter
->domain
)
3537 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3538 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3539 /* Some types are also in VAR_DOMAIN. */
3540 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3544 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3548 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3552 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3567 static struct compunit_symtab
*
3568 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3569 const char *name
, domain_enum domain
)
3571 struct compunit_symtab
*stab_best
= NULL
;
3572 struct dwarf2_per_objfile
*dwarf2_per_objfile
3573 = get_dwarf2_per_objfile (objfile
);
3575 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3577 struct dw2_symtab_iterator iter
;
3578 struct dwarf2_per_cu_data
*per_cu
;
3580 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3582 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3584 struct symbol
*sym
, *with_opaque
= NULL
;
3585 struct compunit_symtab
*stab
3586 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3587 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3588 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3590 sym
= block_find_symbol (block
, name
, domain
,
3591 block_find_non_opaque_type_preferred
,
3594 /* Some caution must be observed with overloaded functions
3595 and methods, since the index will not contain any overload
3596 information (but NAME might contain it). */
3599 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3601 if (with_opaque
!= NULL
3602 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3605 /* Keep looking through other CUs. */
3612 dw2_print_stats (struct objfile
*objfile
)
3614 struct dwarf2_per_objfile
*dwarf2_per_objfile
3615 = get_dwarf2_per_objfile (objfile
);
3616 int total
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3617 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3620 for (int i
= 0; i
< total
; ++i
)
3622 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3624 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
3627 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3628 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3631 /* This dumps minimal information about the index.
3632 It is called via "mt print objfiles".
3633 One use is to verify .gdb_index has been loaded by the
3634 gdb.dwarf2/gdb-index.exp testcase. */
3637 dw2_dump (struct objfile
*objfile
)
3639 struct dwarf2_per_objfile
*dwarf2_per_objfile
3640 = get_dwarf2_per_objfile (objfile
);
3642 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
3643 printf_filtered (".gdb_index:");
3644 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
)
3646 printf_filtered (" version %d\n",
3647 dwarf2_per_objfile
->per_bfd
->index_table
->version
);
3650 printf_filtered (" faked for \"readnow\"\n");
3651 printf_filtered ("\n");
3655 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3656 const char *func_name
)
3658 struct dwarf2_per_objfile
*dwarf2_per_objfile
3659 = get_dwarf2_per_objfile (objfile
);
3661 struct dw2_symtab_iterator iter
;
3662 struct dwarf2_per_cu_data
*per_cu
;
3664 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3666 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3667 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3672 dw2_expand_all_symtabs (struct objfile
*objfile
)
3674 struct dwarf2_per_objfile
*dwarf2_per_objfile
3675 = get_dwarf2_per_objfile (objfile
);
3676 int total_units
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3677 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3679 for (int i
= 0; i
< total_units
; ++i
)
3681 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3683 /* We don't want to directly expand a partial CU, because if we
3684 read it with the wrong language, then assertion failures can
3685 be triggered later on. See PR symtab/23010. So, tell
3686 dw2_instantiate_symtab to skip partial CUs -- any important
3687 partial CU will be read via DW_TAG_imported_unit anyway. */
3688 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, true);
3693 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3694 const char *fullname
)
3696 struct dwarf2_per_objfile
*dwarf2_per_objfile
3697 = get_dwarf2_per_objfile (objfile
);
3699 /* We don't need to consider type units here.
3700 This is only called for examining code, e.g. expand_line_sal.
3701 There can be an order of magnitude (or more) more type units
3702 than comp units, and we avoid them if we can. */
3704 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3706 /* We only need to look at symtabs not already expanded. */
3707 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3710 quick_file_names
*file_data
3711 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3712 if (file_data
== NULL
)
3715 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3717 const char *this_fullname
= file_data
->file_names
[j
];
3719 if (filename_cmp (this_fullname
, fullname
) == 0)
3721 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3729 dw2_expand_symtabs_matching_symbol
3730 (mapped_index_base
&index
,
3731 const lookup_name_info
&lookup_name_in
,
3732 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3733 enum search_domain kind
,
3734 gdb::function_view
<bool (offset_type
)> match_callback
,
3735 dwarf2_per_objfile
*per_objfile
);
3738 dw2_expand_symtabs_matching_one
3739 (dwarf2_per_cu_data
*per_cu
,
3740 dwarf2_per_objfile
*per_objfile
,
3741 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3742 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3745 dw2_map_matching_symbols
3746 (struct objfile
*objfile
,
3747 const lookup_name_info
&name
, domain_enum domain
,
3749 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3750 symbol_compare_ftype
*ordered_compare
)
3753 struct dwarf2_per_objfile
*dwarf2_per_objfile
3754 = get_dwarf2_per_objfile (objfile
);
3756 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3758 if (dwarf2_per_objfile
->per_bfd
->index_table
!= nullptr)
3760 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3761 here though if the current language is Ada for a non-Ada objfile
3763 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
3765 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3766 auto matcher
= [&] (const char *symname
)
3768 if (ordered_compare
== nullptr)
3770 return ordered_compare (symname
, match_name
) == 0;
3773 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3774 [&] (offset_type namei
)
3776 struct dw2_symtab_iterator iter
;
3777 struct dwarf2_per_cu_data
*per_cu
;
3779 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_kind
, domain
,
3781 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3782 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
3785 }, dwarf2_per_objfile
);
3789 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3790 proceed assuming all symtabs have been read in. */
3793 for (compunit_symtab
*cust
: objfile
->compunits ())
3795 const struct block
*block
;
3799 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3800 if (!iterate_over_symbols_terminated (block
, name
,
3806 /* Starting from a search name, return the string that finds the upper
3807 bound of all strings that start with SEARCH_NAME in a sorted name
3808 list. Returns the empty string to indicate that the upper bound is
3809 the end of the list. */
3812 make_sort_after_prefix_name (const char *search_name
)
3814 /* When looking to complete "func", we find the upper bound of all
3815 symbols that start with "func" by looking for where we'd insert
3816 the closest string that would follow "func" in lexicographical
3817 order. Usually, that's "func"-with-last-character-incremented,
3818 i.e. "fund". Mind non-ASCII characters, though. Usually those
3819 will be UTF-8 multi-byte sequences, but we can't be certain.
3820 Especially mind the 0xff character, which is a valid character in
3821 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3822 rule out compilers allowing it in identifiers. Note that
3823 conveniently, strcmp/strcasecmp are specified to compare
3824 characters interpreted as unsigned char. So what we do is treat
3825 the whole string as a base 256 number composed of a sequence of
3826 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3827 to 0, and carries 1 to the following more-significant position.
3828 If the very first character in SEARCH_NAME ends up incremented
3829 and carries/overflows, then the upper bound is the end of the
3830 list. The string after the empty string is also the empty
3833 Some examples of this operation:
3835 SEARCH_NAME => "+1" RESULT
3839 "\xff" "a" "\xff" => "\xff" "b"
3844 Then, with these symbols for example:
3850 completing "func" looks for symbols between "func" and
3851 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3852 which finds "func" and "func1", but not "fund".
3856 funcÿ (Latin1 'ÿ' [0xff])
3860 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3861 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3865 ÿÿ (Latin1 'ÿ' [0xff])
3868 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3869 the end of the list.
3871 std::string after
= search_name
;
3872 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3874 if (!after
.empty ())
3875 after
.back () = (unsigned char) after
.back () + 1;
3879 /* See declaration. */
3881 std::pair
<std::vector
<name_component
>::const_iterator
,
3882 std::vector
<name_component
>::const_iterator
>
3883 mapped_index_base::find_name_components_bounds
3884 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3885 dwarf2_per_objfile
*per_objfile
) const
3888 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3890 const char *lang_name
3891 = lookup_name_without_params
.language_lookup_name (lang
);
3893 /* Comparison function object for lower_bound that matches against a
3894 given symbol name. */
3895 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3898 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3899 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3900 return name_cmp (elem_name
, name
) < 0;
3903 /* Comparison function object for upper_bound that matches against a
3904 given symbol name. */
3905 auto lookup_compare_upper
= [&] (const char *name
,
3906 const name_component
&elem
)
3908 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3909 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3910 return name_cmp (name
, elem_name
) < 0;
3913 auto begin
= this->name_components
.begin ();
3914 auto end
= this->name_components
.end ();
3916 /* Find the lower bound. */
3919 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3922 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3925 /* Find the upper bound. */
3928 if (lookup_name_without_params
.completion_mode ())
3930 /* In completion mode, we want UPPER to point past all
3931 symbols names that have the same prefix. I.e., with
3932 these symbols, and completing "func":
3934 function << lower bound
3936 other_function << upper bound
3938 We find the upper bound by looking for the insertion
3939 point of "func"-with-last-character-incremented,
3941 std::string after
= make_sort_after_prefix_name (lang_name
);
3944 return std::lower_bound (lower
, end
, after
.c_str (),
3945 lookup_compare_lower
);
3948 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3951 return {lower
, upper
};
3954 /* See declaration. */
3957 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3959 if (!this->name_components
.empty ())
3962 this->name_components_casing
= case_sensitivity
;
3964 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3966 /* The code below only knows how to break apart components of C++
3967 symbol names (and other languages that use '::' as
3968 namespace/module separator) and Ada symbol names. */
3969 auto count
= this->symbol_name_count ();
3970 for (offset_type idx
= 0; idx
< count
; idx
++)
3972 if (this->symbol_name_slot_invalid (idx
))
3975 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3977 /* Add each name component to the name component table. */
3978 unsigned int previous_len
= 0;
3980 if (strstr (name
, "::") != nullptr)
3982 for (unsigned int current_len
= cp_find_first_component (name
);
3983 name
[current_len
] != '\0';
3984 current_len
+= cp_find_first_component (name
+ current_len
))
3986 gdb_assert (name
[current_len
] == ':');
3987 this->name_components
.push_back ({previous_len
, idx
});
3988 /* Skip the '::'. */
3990 previous_len
= current_len
;
3995 /* Handle the Ada encoded (aka mangled) form here. */
3996 for (const char *iter
= strstr (name
, "__");
3998 iter
= strstr (iter
, "__"))
4000 this->name_components
.push_back ({previous_len
, idx
});
4002 previous_len
= iter
- name
;
4006 this->name_components
.push_back ({previous_len
, idx
});
4009 /* Sort name_components elements by name. */
4010 auto name_comp_compare
= [&] (const name_component
&left
,
4011 const name_component
&right
)
4013 const char *left_qualified
4014 = this->symbol_name_at (left
.idx
, per_objfile
);
4015 const char *right_qualified
4016 = this->symbol_name_at (right
.idx
, per_objfile
);
4018 const char *left_name
= left_qualified
+ left
.name_offset
;
4019 const char *right_name
= right_qualified
+ right
.name_offset
;
4021 return name_cmp (left_name
, right_name
) < 0;
4024 std::sort (this->name_components
.begin (),
4025 this->name_components
.end (),
4029 /* Helper for dw2_expand_symtabs_matching that works with a
4030 mapped_index_base instead of the containing objfile. This is split
4031 to a separate function in order to be able to unit test the
4032 name_components matching using a mock mapped_index_base. For each
4033 symbol name that matches, calls MATCH_CALLBACK, passing it the
4034 symbol's index in the mapped_index_base symbol table. */
4037 dw2_expand_symtabs_matching_symbol
4038 (mapped_index_base
&index
,
4039 const lookup_name_info
&lookup_name_in
,
4040 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4041 enum search_domain kind
,
4042 gdb::function_view
<bool (offset_type
)> match_callback
,
4043 dwarf2_per_objfile
*per_objfile
)
4045 lookup_name_info lookup_name_without_params
4046 = lookup_name_in
.make_ignore_params ();
4048 /* Build the symbol name component sorted vector, if we haven't
4050 index
.build_name_components (per_objfile
);
4052 /* The same symbol may appear more than once in the range though.
4053 E.g., if we're looking for symbols that complete "w", and we have
4054 a symbol named "w1::w2", we'll find the two name components for
4055 that same symbol in the range. To be sure we only call the
4056 callback once per symbol, we first collect the symbol name
4057 indexes that matched in a temporary vector and ignore
4059 std::vector
<offset_type
> matches
;
4061 struct name_and_matcher
4063 symbol_name_matcher_ftype
*matcher
;
4066 bool operator== (const name_and_matcher
&other
) const
4068 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4072 /* A vector holding all the different symbol name matchers, for all
4074 std::vector
<name_and_matcher
> matchers
;
4076 for (int i
= 0; i
< nr_languages
; i
++)
4078 enum language lang_e
= (enum language
) i
;
4080 const language_defn
*lang
= language_def (lang_e
);
4081 symbol_name_matcher_ftype
*name_matcher
4082 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4084 name_and_matcher key
{
4086 lookup_name_without_params
.language_lookup_name (lang_e
)
4089 /* Don't insert the same comparison routine more than once.
4090 Note that we do this linear walk. This is not a problem in
4091 practice because the number of supported languages is
4093 if (std::find (matchers
.begin (), matchers
.end (), key
)
4096 matchers
.push_back (std::move (key
));
4099 = index
.find_name_components_bounds (lookup_name_without_params
,
4100 lang_e
, per_objfile
);
4102 /* Now for each symbol name in range, check to see if we have a name
4103 match, and if so, call the MATCH_CALLBACK callback. */
4105 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4107 const char *qualified
4108 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4110 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4111 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4114 matches
.push_back (bounds
.first
->idx
);
4118 std::sort (matches
.begin (), matches
.end ());
4120 /* Finally call the callback, once per match. */
4122 for (offset_type idx
: matches
)
4126 if (!match_callback (idx
))
4132 /* Above we use a type wider than idx's for 'prev', since 0 and
4133 (offset_type)-1 are both possible values. */
4134 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4139 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4141 /* A mock .gdb_index/.debug_names-like name index table, enough to
4142 exercise dw2_expand_symtabs_matching_symbol, which works with the
4143 mapped_index_base interface. Builds an index from the symbol list
4144 passed as parameter to the constructor. */
4145 class mock_mapped_index
: public mapped_index_base
4148 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4149 : m_symbol_table (symbols
)
4152 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4154 /* Return the number of names in the symbol table. */
4155 size_t symbol_name_count () const override
4157 return m_symbol_table
.size ();
4160 /* Get the name of the symbol at IDX in the symbol table. */
4161 const char *symbol_name_at
4162 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4164 return m_symbol_table
[idx
];
4168 gdb::array_view
<const char *> m_symbol_table
;
4171 /* Convenience function that converts a NULL pointer to a "<null>"
4172 string, to pass to print routines. */
4175 string_or_null (const char *str
)
4177 return str
!= NULL
? str
: "<null>";
4180 /* Check if a lookup_name_info built from
4181 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4182 index. EXPECTED_LIST is the list of expected matches, in expected
4183 matching order. If no match expected, then an empty list is
4184 specified. Returns true on success. On failure prints a warning
4185 indicating the file:line that failed, and returns false. */
4188 check_match (const char *file
, int line
,
4189 mock_mapped_index
&mock_index
,
4190 const char *name
, symbol_name_match_type match_type
,
4191 bool completion_mode
,
4192 std::initializer_list
<const char *> expected_list
,
4193 dwarf2_per_objfile
*per_objfile
)
4195 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4197 bool matched
= true;
4199 auto mismatch
= [&] (const char *expected_str
,
4202 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4203 "expected=\"%s\", got=\"%s\"\n"),
4205 (match_type
== symbol_name_match_type::FULL
4207 name
, string_or_null (expected_str
), string_or_null (got
));
4211 auto expected_it
= expected_list
.begin ();
4212 auto expected_end
= expected_list
.end ();
4214 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4216 [&] (offset_type idx
)
4218 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4219 const char *expected_str
4220 = expected_it
== expected_end
? NULL
: *expected_it
++;
4222 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4223 mismatch (expected_str
, matched_name
);
4227 const char *expected_str
4228 = expected_it
== expected_end
? NULL
: *expected_it
++;
4229 if (expected_str
!= NULL
)
4230 mismatch (expected_str
, NULL
);
4235 /* The symbols added to the mock mapped_index for testing (in
4237 static const char *test_symbols
[] = {
4246 "ns2::tmpl<int>::foo2",
4247 "(anonymous namespace)::A::B::C",
4249 /* These are used to check that the increment-last-char in the
4250 matching algorithm for completion doesn't match "t1_fund" when
4251 completing "t1_func". */
4257 /* A UTF-8 name with multi-byte sequences to make sure that
4258 cp-name-parser understands this as a single identifier ("função"
4259 is "function" in PT). */
4262 /* \377 (0xff) is Latin1 'ÿ'. */
4265 /* \377 (0xff) is Latin1 'ÿ'. */
4269 /* A name with all sorts of complications. Starts with "z" to make
4270 it easier for the completion tests below. */
4271 #define Z_SYM_NAME \
4272 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4273 "::tuple<(anonymous namespace)::ui*, " \
4274 "std::default_delete<(anonymous namespace)::ui>, void>"
4279 /* Returns true if the mapped_index_base::find_name_component_bounds
4280 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4281 in completion mode. */
4284 check_find_bounds_finds (mapped_index_base
&index
,
4285 const char *search_name
,
4286 gdb::array_view
<const char *> expected_syms
,
4287 dwarf2_per_objfile
*per_objfile
)
4289 lookup_name_info
lookup_name (search_name
,
4290 symbol_name_match_type::FULL
, true);
4292 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4296 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4297 if (distance
!= expected_syms
.size ())
4300 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4302 auto nc_elem
= bounds
.first
+ exp_elem
;
4303 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4304 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4311 /* Test the lower-level mapped_index::find_name_component_bounds
4315 test_mapped_index_find_name_component_bounds ()
4317 mock_mapped_index
mock_index (test_symbols
);
4319 mock_index
.build_name_components (NULL
/* per_objfile */);
4321 /* Test the lower-level mapped_index::find_name_component_bounds
4322 method in completion mode. */
4324 static const char *expected_syms
[] = {
4329 SELF_CHECK (check_find_bounds_finds
4330 (mock_index
, "t1_func", expected_syms
,
4331 NULL
/* per_objfile */));
4334 /* Check that the increment-last-char in the name matching algorithm
4335 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4337 static const char *expected_syms1
[] = {
4341 SELF_CHECK (check_find_bounds_finds
4342 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4344 static const char *expected_syms2
[] = {
4347 SELF_CHECK (check_find_bounds_finds
4348 (mock_index
, "\377\377", expected_syms2
,
4349 NULL
/* per_objfile */));
4353 /* Test dw2_expand_symtabs_matching_symbol. */
4356 test_dw2_expand_symtabs_matching_symbol ()
4358 mock_mapped_index
mock_index (test_symbols
);
4360 /* We let all tests run until the end even if some fails, for debug
4362 bool any_mismatch
= false;
4364 /* Create the expected symbols list (an initializer_list). Needed
4365 because lists have commas, and we need to pass them to CHECK,
4366 which is a macro. */
4367 #define EXPECT(...) { __VA_ARGS__ }
4369 /* Wrapper for check_match that passes down the current
4370 __FILE__/__LINE__. */
4371 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4372 any_mismatch |= !check_match (__FILE__, __LINE__, \
4374 NAME, MATCH_TYPE, COMPLETION_MODE, \
4375 EXPECTED_LIST, NULL)
4377 /* Identity checks. */
4378 for (const char *sym
: test_symbols
)
4380 /* Should be able to match all existing symbols. */
4381 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4384 /* Should be able to match all existing symbols with
4386 std::string with_params
= std::string (sym
) + "(int)";
4387 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4390 /* Should be able to match all existing symbols with
4391 parameters and qualifiers. */
4392 with_params
= std::string (sym
) + " ( int ) const";
4393 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4396 /* This should really find sym, but cp-name-parser.y doesn't
4397 know about lvalue/rvalue qualifiers yet. */
4398 with_params
= std::string (sym
) + " ( int ) &&";
4399 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4403 /* Check that the name matching algorithm for completion doesn't get
4404 confused with Latin1 'ÿ' / 0xff. */
4406 static const char str
[] = "\377";
4407 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4408 EXPECT ("\377", "\377\377123"));
4411 /* Check that the increment-last-char in the matching algorithm for
4412 completion doesn't match "t1_fund" when completing "t1_func". */
4414 static const char str
[] = "t1_func";
4415 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4416 EXPECT ("t1_func", "t1_func1"));
4419 /* Check that completion mode works at each prefix of the expected
4422 static const char str
[] = "function(int)";
4423 size_t len
= strlen (str
);
4426 for (size_t i
= 1; i
< len
; i
++)
4428 lookup
.assign (str
, i
);
4429 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4430 EXPECT ("function"));
4434 /* While "w" is a prefix of both components, the match function
4435 should still only be called once. */
4437 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4439 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4443 /* Same, with a "complicated" symbol. */
4445 static const char str
[] = Z_SYM_NAME
;
4446 size_t len
= strlen (str
);
4449 for (size_t i
= 1; i
< len
; i
++)
4451 lookup
.assign (str
, i
);
4452 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4453 EXPECT (Z_SYM_NAME
));
4457 /* In FULL mode, an incomplete symbol doesn't match. */
4459 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4463 /* A complete symbol with parameters matches any overload, since the
4464 index has no overload info. */
4466 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4467 EXPECT ("std::zfunction", "std::zfunction2"));
4468 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4469 EXPECT ("std::zfunction", "std::zfunction2"));
4470 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4471 EXPECT ("std::zfunction", "std::zfunction2"));
4474 /* Check that whitespace is ignored appropriately. A symbol with a
4475 template argument list. */
4477 static const char expected
[] = "ns::foo<int>";
4478 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4480 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4484 /* Check that whitespace is ignored appropriately. A symbol with a
4485 template argument list that includes a pointer. */
4487 static const char expected
[] = "ns::foo<char*>";
4488 /* Try both completion and non-completion modes. */
4489 static const bool completion_mode
[2] = {false, true};
4490 for (size_t i
= 0; i
< 2; i
++)
4492 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4493 completion_mode
[i
], EXPECT (expected
));
4494 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4495 completion_mode
[i
], EXPECT (expected
));
4497 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4498 completion_mode
[i
], EXPECT (expected
));
4499 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4500 completion_mode
[i
], EXPECT (expected
));
4505 /* Check method qualifiers are ignored. */
4506 static const char expected
[] = "ns::foo<char*>";
4507 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4508 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4509 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4510 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4511 CHECK_MATCH ("foo < char * > ( int ) const",
4512 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4513 CHECK_MATCH ("foo < char * > ( int ) &&",
4514 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4517 /* Test lookup names that don't match anything. */
4519 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4522 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4526 /* Some wild matching tests, exercising "(anonymous namespace)",
4527 which should not be confused with a parameter list. */
4529 static const char *syms
[] = {
4533 "A :: B :: C ( int )",
4538 for (const char *s
: syms
)
4540 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4541 EXPECT ("(anonymous namespace)::A::B::C"));
4546 static const char expected
[] = "ns2::tmpl<int>::foo2";
4547 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4549 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4553 SELF_CHECK (!any_mismatch
);
4562 test_mapped_index_find_name_component_bounds ();
4563 test_dw2_expand_symtabs_matching_symbol ();
4566 }} // namespace selftests::dw2_expand_symtabs_matching
4568 #endif /* GDB_SELF_TEST */
4570 /* If FILE_MATCHER is NULL or if PER_CU has
4571 dwarf2_per_cu_quick_data::MARK set (see
4572 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4573 EXPANSION_NOTIFY on it. */
4576 dw2_expand_symtabs_matching_one
4577 (dwarf2_per_cu_data
*per_cu
,
4578 dwarf2_per_objfile
*per_objfile
,
4579 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4580 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4582 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4584 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4586 compunit_symtab
*symtab
4587 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4588 gdb_assert (symtab
!= nullptr);
4590 if (expansion_notify
!= NULL
&& symtab_was_null
)
4591 expansion_notify (symtab
);
4595 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4596 matched, to expand corresponding CUs that were marked. IDX is the
4597 index of the symbol name that matched. */
4600 dw2_expand_marked_cus
4601 (dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4602 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4603 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4606 offset_type
*vec
, vec_len
, vec_idx
;
4607 bool global_seen
= false;
4608 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4610 vec
= (offset_type
*) (index
.constant_pool
4611 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4612 vec_len
= MAYBE_SWAP (vec
[0]);
4613 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4615 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4616 /* This value is only valid for index versions >= 7. */
4617 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4618 gdb_index_symbol_kind symbol_kind
=
4619 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4620 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4621 /* Only check the symbol attributes if they're present.
4622 Indices prior to version 7 don't record them,
4623 and indices >= 7 may elide them for certain symbols
4624 (gold does this). */
4627 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4629 /* Work around gold/15646. */
4632 if (!is_static
&& global_seen
)
4638 /* Only check the symbol's kind if it has one. */
4643 case VARIABLES_DOMAIN
:
4644 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4647 case FUNCTIONS_DOMAIN
:
4648 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4652 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4655 case MODULES_DOMAIN
:
4656 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4664 /* Don't crash on bad data. */
4665 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
4666 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
4668 complaint (_(".gdb_index entry has bad CU index"
4670 objfile_name (dwarf2_per_objfile
->objfile
));
4674 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
4675 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, file_matcher
,
4680 /* If FILE_MATCHER is non-NULL, set all the
4681 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4682 that match FILE_MATCHER. */
4685 dw_expand_symtabs_matching_file_matcher
4686 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4687 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4689 if (file_matcher
== NULL
)
4692 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4694 NULL
, xcalloc
, xfree
));
4695 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4697 NULL
, xcalloc
, xfree
));
4699 /* The rule is CUs specify all the files, including those used by
4700 any TU, so there's no need to scan TUs here. */
4702 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4706 per_cu
->v
.quick
->mark
= 0;
4708 /* We only need to look at symtabs not already expanded. */
4709 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4712 quick_file_names
*file_data
4713 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4714 if (file_data
== NULL
)
4717 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4719 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4721 per_cu
->v
.quick
->mark
= 1;
4725 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4727 const char *this_real_name
;
4729 if (file_matcher (file_data
->file_names
[j
], false))
4731 per_cu
->v
.quick
->mark
= 1;
4735 /* Before we invoke realpath, which can get expensive when many
4736 files are involved, do a quick comparison of the basenames. */
4737 if (!basenames_may_differ
4738 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4742 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
4744 if (file_matcher (this_real_name
, false))
4746 per_cu
->v
.quick
->mark
= 1;
4751 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4752 ? visited_found
.get ()
4753 : visited_not_found
.get (),
4760 dw2_expand_symtabs_matching
4761 (struct objfile
*objfile
,
4762 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4763 const lookup_name_info
*lookup_name
,
4764 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4765 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4766 enum search_domain kind
)
4768 struct dwarf2_per_objfile
*dwarf2_per_objfile
4769 = get_dwarf2_per_objfile (objfile
);
4771 /* index_table is NULL if OBJF_READNOW. */
4772 if (!dwarf2_per_objfile
->per_bfd
->index_table
)
4775 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4777 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4779 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4783 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
4784 file_matcher
, expansion_notify
);
4789 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4791 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4793 kind
, [&] (offset_type idx
)
4795 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4796 expansion_notify
, kind
);
4798 }, dwarf2_per_objfile
);
4801 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4804 static struct compunit_symtab
*
4805 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4810 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4811 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4814 if (cust
->includes
== NULL
)
4817 for (i
= 0; cust
->includes
[i
]; ++i
)
4819 struct compunit_symtab
*s
= cust
->includes
[i
];
4821 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4829 static struct compunit_symtab
*
4830 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4831 struct bound_minimal_symbol msymbol
,
4833 struct obj_section
*section
,
4836 struct dwarf2_per_cu_data
*data
;
4837 struct compunit_symtab
*result
;
4839 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4842 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4843 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4844 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4848 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4849 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4850 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4851 paddress (objfile
->arch (), pc
));
4853 result
= recursively_find_pc_sect_compunit_symtab
4854 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4856 gdb_assert (result
!= NULL
);
4861 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4862 void *data
, int need_fullname
)
4864 struct dwarf2_per_objfile
*dwarf2_per_objfile
4865 = get_dwarf2_per_objfile (objfile
);
4867 if (!dwarf2_per_objfile
->per_bfd
->filenames_cache
)
4869 dwarf2_per_objfile
->per_bfd
->filenames_cache
.emplace ();
4871 htab_up
visited (htab_create_alloc (10,
4872 htab_hash_pointer
, htab_eq_pointer
,
4873 NULL
, xcalloc
, xfree
));
4875 /* The rule is CUs specify all the files, including those used
4876 by any TU, so there's no need to scan TUs here. We can
4877 ignore file names coming from already-expanded CUs. */
4879 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4881 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4883 void **slot
= htab_find_slot (visited
.get (),
4884 per_cu
->v
.quick
->file_names
,
4887 *slot
= per_cu
->v
.quick
->file_names
;
4891 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4893 /* We only need to look at symtabs not already expanded. */
4894 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4897 quick_file_names
*file_data
4898 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4899 if (file_data
== NULL
)
4902 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4905 /* Already visited. */
4910 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4912 const char *filename
= file_data
->file_names
[j
];
4913 dwarf2_per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4918 dwarf2_per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4920 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4923 this_real_name
= gdb_realpath (filename
);
4924 (*fun
) (filename
, this_real_name
.get (), data
);
4929 dw2_has_symbols (struct objfile
*objfile
)
4934 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4937 dw2_find_last_source_symtab
,
4938 dw2_forget_cached_source_info
,
4939 dw2_map_symtabs_matching_filename
,
4944 dw2_expand_symtabs_for_function
,
4945 dw2_expand_all_symtabs
,
4946 dw2_expand_symtabs_with_fullname
,
4947 dw2_map_matching_symbols
,
4948 dw2_expand_symtabs_matching
,
4949 dw2_find_pc_sect_compunit_symtab
,
4951 dw2_map_symbol_filenames
4954 /* DWARF-5 debug_names reader. */
4956 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4957 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4959 /* A helper function that reads the .debug_names section in SECTION
4960 and fills in MAP. FILENAME is the name of the file containing the
4961 section; it is used for error reporting.
4963 Returns true if all went well, false otherwise. */
4966 read_debug_names_from_section (struct objfile
*objfile
,
4967 const char *filename
,
4968 struct dwarf2_section_info
*section
,
4969 mapped_debug_names
&map
)
4971 if (section
->empty ())
4974 /* Older elfutils strip versions could keep the section in the main
4975 executable while splitting it for the separate debug info file. */
4976 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4979 section
->read (objfile
);
4981 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4983 const gdb_byte
*addr
= section
->buffer
;
4985 bfd
*const abfd
= section
->get_bfd_owner ();
4987 unsigned int bytes_read
;
4988 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4991 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4992 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4993 if (bytes_read
+ length
!= section
->size
)
4995 /* There may be multiple per-CU indices. */
4996 warning (_("Section .debug_names in %s length %s does not match "
4997 "section length %s, ignoring .debug_names."),
4998 filename
, plongest (bytes_read
+ length
),
4999 pulongest (section
->size
));
5003 /* The version number. */
5004 uint16_t version
= read_2_bytes (abfd
, addr
);
5008 warning (_("Section .debug_names in %s has unsupported version %d, "
5009 "ignoring .debug_names."),
5015 uint16_t padding
= read_2_bytes (abfd
, addr
);
5019 warning (_("Section .debug_names in %s has unsupported padding %d, "
5020 "ignoring .debug_names."),
5025 /* comp_unit_count - The number of CUs in the CU list. */
5026 map
.cu_count
= read_4_bytes (abfd
, addr
);
5029 /* local_type_unit_count - The number of TUs in the local TU
5031 map
.tu_count
= read_4_bytes (abfd
, addr
);
5034 /* foreign_type_unit_count - The number of TUs in the foreign TU
5036 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5038 if (foreign_tu_count
!= 0)
5040 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5041 "ignoring .debug_names."),
5042 filename
, static_cast<unsigned long> (foreign_tu_count
));
5046 /* bucket_count - The number of hash buckets in the hash lookup
5048 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5051 /* name_count - The number of unique names in the index. */
5052 map
.name_count
= read_4_bytes (abfd
, addr
);
5055 /* abbrev_table_size - The size in bytes of the abbreviations
5057 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5060 /* augmentation_string_size - The size in bytes of the augmentation
5061 string. This value is rounded up to a multiple of 4. */
5062 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5064 map
.augmentation_is_gdb
= ((augmentation_string_size
5065 == sizeof (dwarf5_augmentation
))
5066 && memcmp (addr
, dwarf5_augmentation
,
5067 sizeof (dwarf5_augmentation
)) == 0);
5068 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5069 addr
+= augmentation_string_size
;
5072 map
.cu_table_reordered
= addr
;
5073 addr
+= map
.cu_count
* map
.offset_size
;
5075 /* List of Local TUs */
5076 map
.tu_table_reordered
= addr
;
5077 addr
+= map
.tu_count
* map
.offset_size
;
5079 /* Hash Lookup Table */
5080 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5081 addr
+= map
.bucket_count
* 4;
5082 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5083 addr
+= map
.name_count
* 4;
5086 map
.name_table_string_offs_reordered
= addr
;
5087 addr
+= map
.name_count
* map
.offset_size
;
5088 map
.name_table_entry_offs_reordered
= addr
;
5089 addr
+= map
.name_count
* map
.offset_size
;
5091 const gdb_byte
*abbrev_table_start
= addr
;
5094 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5099 const auto insertpair
5100 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5101 if (!insertpair
.second
)
5103 warning (_("Section .debug_names in %s has duplicate index %s, "
5104 "ignoring .debug_names."),
5105 filename
, pulongest (index_num
));
5108 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5109 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5114 mapped_debug_names::index_val::attr attr
;
5115 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5117 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5119 if (attr
.form
== DW_FORM_implicit_const
)
5121 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5125 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5127 indexval
.attr_vec
.push_back (std::move (attr
));
5130 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5132 warning (_("Section .debug_names in %s has abbreviation_table "
5133 "of size %s vs. written as %u, ignoring .debug_names."),
5134 filename
, plongest (addr
- abbrev_table_start
),
5138 map
.entry_pool
= addr
;
5143 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5147 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5148 const mapped_debug_names
&map
,
5149 dwarf2_section_info
§ion
,
5152 if (!map
.augmentation_is_gdb
)
5154 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5156 sect_offset sect_off
5157 = (sect_offset
) (extract_unsigned_integer
5158 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5160 map
.dwarf5_byte_order
));
5161 /* We don't know the length of the CU, because the CU list in a
5162 .debug_names index can be incomplete, so we can't use the start of
5163 the next CU as end of this CU. We create the CUs here with length 0,
5164 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5165 dwarf2_per_cu_data
*per_cu
5166 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5167 per_bfd
->all_comp_units
.push_back (per_cu
);
5171 sect_offset sect_off_prev
;
5172 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5174 sect_offset sect_off_next
;
5175 if (i
< map
.cu_count
)
5178 = (sect_offset
) (extract_unsigned_integer
5179 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5181 map
.dwarf5_byte_order
));
5184 sect_off_next
= (sect_offset
) section
.size
;
5187 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5188 dwarf2_per_cu_data
*per_cu
5189 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5190 sect_off_prev
, length
);
5191 per_bfd
->all_comp_units
.push_back (per_cu
);
5193 sect_off_prev
= sect_off_next
;
5197 /* Read the CU list from the mapped index, and use it to create all
5198 the CU objects for this dwarf2_per_objfile. */
5201 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5202 const mapped_debug_names
&map
,
5203 const mapped_debug_names
&dwz_map
)
5205 gdb_assert (per_bfd
->all_comp_units
.empty ());
5206 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5208 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5209 false /* is_dwz */);
5211 if (dwz_map
.cu_count
== 0)
5214 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5215 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5219 /* Read .debug_names. If everything went ok, initialize the "quick"
5220 elements of all the CUs and return true. Otherwise, return false. */
5223 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5225 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5226 mapped_debug_names dwz_map
;
5227 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5229 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5230 &dwarf2_per_objfile
->per_bfd
->debug_names
,
5234 /* Don't use the index if it's empty. */
5235 if (map
->name_count
== 0)
5238 /* If there is a .dwz file, read it so we can get its CU list as
5240 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
5243 if (!read_debug_names_from_section (objfile
,
5244 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5245 &dwz
->debug_names
, dwz_map
))
5247 warning (_("could not read '.debug_names' section from %s; skipping"),
5248 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5253 create_cus_from_debug_names (dwarf2_per_objfile
->per_bfd
, *map
, dwz_map
);
5255 if (map
->tu_count
!= 0)
5257 /* We can only handle a single .debug_types when we have an
5259 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
5262 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
5264 create_signatured_type_table_from_debug_names
5265 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->per_bfd
->abbrev
);
5268 create_addrmap_from_aranges (dwarf2_per_objfile
,
5269 &dwarf2_per_objfile
->per_bfd
->debug_aranges
);
5271 dwarf2_per_objfile
->per_bfd
->debug_names_table
= std::move (map
);
5272 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5273 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
5274 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5279 /* Type used to manage iterating over all CUs looking for a symbol for
5282 class dw2_debug_names_iterator
5285 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5286 gdb::optional
<block_enum
> block_index
,
5288 const char *name
, dwarf2_per_objfile
*per_objfile
)
5289 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5290 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5291 m_per_objfile (per_objfile
)
5294 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5295 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5298 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5299 m_per_objfile (per_objfile
)
5302 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5303 block_enum block_index
, domain_enum domain
,
5304 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5305 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5306 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5307 m_per_objfile (per_objfile
)
5310 /* Return the next matching CU or NULL if there are no more. */
5311 dwarf2_per_cu_data
*next ();
5314 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5315 const char *name
, dwarf2_per_objfile
*per_objfile
);
5316 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5317 uint32_t namei
, dwarf2_per_objfile
*per_objfile
);
5319 /* The internalized form of .debug_names. */
5320 const mapped_debug_names
&m_map
;
5322 /* If set, only look for symbols that match that block. Valid values are
5323 GLOBAL_BLOCK and STATIC_BLOCK. */
5324 const gdb::optional
<block_enum
> m_block_index
;
5326 /* The kind of symbol we're looking for. */
5327 const domain_enum m_domain
= UNDEF_DOMAIN
;
5328 const search_domain m_search
= ALL_DOMAIN
;
5330 /* The list of CUs from the index entry of the symbol, or NULL if
5332 const gdb_byte
*m_addr
;
5334 dwarf2_per_objfile
*m_per_objfile
;
5338 mapped_debug_names::namei_to_name
5339 (uint32_t namei
, dwarf2_per_objfile
*dwarf2_per_objfile
) const
5341 const ULONGEST namei_string_offs
5342 = extract_unsigned_integer ((name_table_string_offs_reordered
5343 + namei
* offset_size
),
5346 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5350 /* Find a slot in .debug_names for the object named NAME. If NAME is
5351 found, return pointer to its pool data. If NAME cannot be found,
5355 dw2_debug_names_iterator::find_vec_in_debug_names
5356 (const mapped_debug_names
&map
, const char *name
, dwarf2_per_objfile
*per_objfile
)
5358 int (*cmp
) (const char *, const char *);
5360 gdb::unique_xmalloc_ptr
<char> without_params
;
5361 if (current_language
->la_language
== language_cplus
5362 || current_language
->la_language
== language_fortran
5363 || current_language
->la_language
== language_d
)
5365 /* NAME is already canonical. Drop any qualifiers as
5366 .debug_names does not contain any. */
5368 if (strchr (name
, '(') != NULL
)
5370 without_params
= cp_remove_params (name
);
5371 if (without_params
!= NULL
)
5372 name
= without_params
.get ();
5376 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5378 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5380 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5381 (map
.bucket_table_reordered
5382 + (full_hash
% map
.bucket_count
)), 4,
5383 map
.dwarf5_byte_order
);
5387 if (namei
>= map
.name_count
)
5389 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5391 namei
, map
.name_count
,
5392 objfile_name (per_objfile
->objfile
));
5398 const uint32_t namei_full_hash
5399 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5400 (map
.hash_table_reordered
+ namei
), 4,
5401 map
.dwarf5_byte_order
);
5402 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5405 if (full_hash
== namei_full_hash
)
5407 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5409 #if 0 /* An expensive sanity check. */
5410 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5412 complaint (_("Wrong .debug_names hash for string at index %u "
5414 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5419 if (cmp (namei_string
, name
) == 0)
5421 const ULONGEST namei_entry_offs
5422 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5423 + namei
* map
.offset_size
),
5424 map
.offset_size
, map
.dwarf5_byte_order
);
5425 return map
.entry_pool
+ namei_entry_offs
;
5430 if (namei
>= map
.name_count
)
5436 dw2_debug_names_iterator::find_vec_in_debug_names
5437 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5439 if (namei
>= map
.name_count
)
5441 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5443 namei
, map
.name_count
,
5444 objfile_name (per_objfile
->objfile
));
5448 const ULONGEST namei_entry_offs
5449 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5450 + namei
* map
.offset_size
),
5451 map
.offset_size
, map
.dwarf5_byte_order
);
5452 return map
.entry_pool
+ namei_entry_offs
;
5455 /* See dw2_debug_names_iterator. */
5457 dwarf2_per_cu_data
*
5458 dw2_debug_names_iterator::next ()
5463 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5464 struct objfile
*objfile
= m_per_objfile
->objfile
;
5465 bfd
*const abfd
= objfile
->obfd
;
5469 unsigned int bytes_read
;
5470 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5471 m_addr
+= bytes_read
;
5475 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5476 if (indexval_it
== m_map
.abbrev_map
.cend ())
5478 complaint (_("Wrong .debug_names undefined abbrev code %s "
5480 pulongest (abbrev
), objfile_name (objfile
));
5483 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5484 enum class symbol_linkage
{
5488 } symbol_linkage_
= symbol_linkage::unknown
;
5489 dwarf2_per_cu_data
*per_cu
= NULL
;
5490 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5495 case DW_FORM_implicit_const
:
5496 ull
= attr
.implicit_const
;
5498 case DW_FORM_flag_present
:
5502 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5503 m_addr
+= bytes_read
;
5506 ull
= read_4_bytes (abfd
, m_addr
);
5510 ull
= read_8_bytes (abfd
, m_addr
);
5513 case DW_FORM_ref_sig8
:
5514 ull
= read_8_bytes (abfd
, m_addr
);
5518 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5519 dwarf_form_name (attr
.form
),
5520 objfile_name (objfile
));
5523 switch (attr
.dw_idx
)
5525 case DW_IDX_compile_unit
:
5526 /* Don't crash on bad data. */
5527 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5529 complaint (_(".debug_names entry has bad CU index %s"
5532 objfile_name (objfile
));
5535 per_cu
= per_bfd
->get_cutu (ull
);
5537 case DW_IDX_type_unit
:
5538 /* Don't crash on bad data. */
5539 if (ull
>= per_bfd
->all_type_units
.size ())
5541 complaint (_(".debug_names entry has bad TU index %s"
5544 objfile_name (objfile
));
5547 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5549 case DW_IDX_die_offset
:
5550 /* In a per-CU index (as opposed to a per-module index), index
5551 entries without CU attribute implicitly refer to the single CU. */
5553 per_cu
= per_bfd
->get_cu (0);
5555 case DW_IDX_GNU_internal
:
5556 if (!m_map
.augmentation_is_gdb
)
5558 symbol_linkage_
= symbol_linkage::static_
;
5560 case DW_IDX_GNU_external
:
5561 if (!m_map
.augmentation_is_gdb
)
5563 symbol_linkage_
= symbol_linkage::extern_
;
5568 /* Skip if already read in. */
5569 if (m_per_objfile
->symtab_set_p (per_cu
))
5572 /* Check static vs global. */
5573 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5575 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5576 const bool symbol_is_static
=
5577 symbol_linkage_
== symbol_linkage::static_
;
5578 if (want_static
!= symbol_is_static
)
5582 /* Match dw2_symtab_iter_next, symbol_kind
5583 and debug_names::psymbol_tag. */
5587 switch (indexval
.dwarf_tag
)
5589 case DW_TAG_variable
:
5590 case DW_TAG_subprogram
:
5591 /* Some types are also in VAR_DOMAIN. */
5592 case DW_TAG_typedef
:
5593 case DW_TAG_structure_type
:
5600 switch (indexval
.dwarf_tag
)
5602 case DW_TAG_typedef
:
5603 case DW_TAG_structure_type
:
5610 switch (indexval
.dwarf_tag
)
5613 case DW_TAG_variable
:
5620 switch (indexval
.dwarf_tag
)
5632 /* Match dw2_expand_symtabs_matching, symbol_kind and
5633 debug_names::psymbol_tag. */
5636 case VARIABLES_DOMAIN
:
5637 switch (indexval
.dwarf_tag
)
5639 case DW_TAG_variable
:
5645 case FUNCTIONS_DOMAIN
:
5646 switch (indexval
.dwarf_tag
)
5648 case DW_TAG_subprogram
:
5655 switch (indexval
.dwarf_tag
)
5657 case DW_TAG_typedef
:
5658 case DW_TAG_structure_type
:
5664 case MODULES_DOMAIN
:
5665 switch (indexval
.dwarf_tag
)
5679 static struct compunit_symtab
*
5680 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5681 const char *name
, domain_enum domain
)
5683 struct dwarf2_per_objfile
*dwarf2_per_objfile
5684 = get_dwarf2_per_objfile (objfile
);
5686 const auto &mapp
= dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5689 /* index is NULL if OBJF_READNOW. */
5692 const auto &map
= *mapp
;
5694 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
,
5695 dwarf2_per_objfile
);
5697 struct compunit_symtab
*stab_best
= NULL
;
5698 struct dwarf2_per_cu_data
*per_cu
;
5699 while ((per_cu
= iter
.next ()) != NULL
)
5701 struct symbol
*sym
, *with_opaque
= NULL
;
5702 compunit_symtab
*stab
5703 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5704 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5705 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5707 sym
= block_find_symbol (block
, name
, domain
,
5708 block_find_non_opaque_type_preferred
,
5711 /* Some caution must be observed with overloaded functions and
5712 methods, since the index will not contain any overload
5713 information (but NAME might contain it). */
5716 && strcmp_iw (sym
->search_name (), name
) == 0)
5718 if (with_opaque
!= NULL
5719 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5722 /* Keep looking through other CUs. */
5728 /* This dumps minimal information about .debug_names. It is called
5729 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5730 uses this to verify that .debug_names has been loaded. */
5733 dw2_debug_names_dump (struct objfile
*objfile
)
5735 struct dwarf2_per_objfile
*dwarf2_per_objfile
5736 = get_dwarf2_per_objfile (objfile
);
5738 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
5739 printf_filtered (".debug_names:");
5740 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5741 printf_filtered (" exists\n");
5743 printf_filtered (" faked for \"readnow\"\n");
5744 printf_filtered ("\n");
5748 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5749 const char *func_name
)
5751 struct dwarf2_per_objfile
*dwarf2_per_objfile
5752 = get_dwarf2_per_objfile (objfile
);
5754 /* dwarf2_per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5755 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5757 const mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5759 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5760 dwarf2_per_objfile
);
5762 struct dwarf2_per_cu_data
*per_cu
;
5763 while ((per_cu
= iter
.next ()) != NULL
)
5764 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5769 dw2_debug_names_map_matching_symbols
5770 (struct objfile
*objfile
,
5771 const lookup_name_info
&name
, domain_enum domain
,
5773 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5774 symbol_compare_ftype
*ordered_compare
)
5776 struct dwarf2_per_objfile
*dwarf2_per_objfile
5777 = get_dwarf2_per_objfile (objfile
);
5779 /* debug_names_table is NULL if OBJF_READNOW. */
5780 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5783 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5784 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5786 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5787 auto matcher
= [&] (const char *symname
)
5789 if (ordered_compare
== nullptr)
5791 return ordered_compare (symname
, match_name
) == 0;
5794 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5795 [&] (offset_type namei
)
5797 /* The name was matched, now expand corresponding CUs that were
5799 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5800 dwarf2_per_objfile
);
5802 struct dwarf2_per_cu_data
*per_cu
;
5803 while ((per_cu
= iter
.next ()) != NULL
)
5804 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
5807 }, dwarf2_per_objfile
);
5809 /* It's a shame we couldn't do this inside the
5810 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5811 that have already been expanded. Instead, this loop matches what
5812 the psymtab code does. */
5813 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5815 compunit_symtab
*symtab
= dwarf2_per_objfile
->get_symtab (per_cu
);
5816 if (symtab
!= nullptr)
5818 const struct block
*block
5819 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5820 if (!iterate_over_symbols_terminated (block
, name
,
5828 dw2_debug_names_expand_symtabs_matching
5829 (struct objfile
*objfile
,
5830 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5831 const lookup_name_info
*lookup_name
,
5832 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5833 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5834 enum search_domain kind
)
5836 struct dwarf2_per_objfile
*dwarf2_per_objfile
5837 = get_dwarf2_per_objfile (objfile
);
5839 /* debug_names_table is NULL if OBJF_READNOW. */
5840 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5843 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5845 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5847 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5851 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5852 file_matcher
, expansion_notify
);
5857 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5859 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5861 kind
, [&] (offset_type namei
)
5863 /* The name was matched, now expand corresponding CUs that were
5865 dw2_debug_names_iterator
iter (map
, kind
, namei
, dwarf2_per_objfile
);
5867 struct dwarf2_per_cu_data
*per_cu
;
5868 while ((per_cu
= iter
.next ()) != NULL
)
5869 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5870 file_matcher
, expansion_notify
);
5872 }, dwarf2_per_objfile
);
5875 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5878 dw2_find_last_source_symtab
,
5879 dw2_forget_cached_source_info
,
5880 dw2_map_symtabs_matching_filename
,
5881 dw2_debug_names_lookup_symbol
,
5884 dw2_debug_names_dump
,
5885 dw2_debug_names_expand_symtabs_for_function
,
5886 dw2_expand_all_symtabs
,
5887 dw2_expand_symtabs_with_fullname
,
5888 dw2_debug_names_map_matching_symbols
,
5889 dw2_debug_names_expand_symtabs_matching
,
5890 dw2_find_pc_sect_compunit_symtab
,
5892 dw2_map_symbol_filenames
5895 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5896 to either a dwarf2_per_bfd or dwz_file object. */
5898 template <typename T
>
5899 static gdb::array_view
<const gdb_byte
>
5900 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5902 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5904 if (section
->empty ())
5907 /* Older elfutils strip versions could keep the section in the main
5908 executable while splitting it for the separate debug info file. */
5909 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5912 section
->read (obj
);
5914 /* dwarf2_section_info::size is a bfd_size_type, while
5915 gdb::array_view works with size_t. On 32-bit hosts, with
5916 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5917 is 32-bit. So we need an explicit narrowing conversion here.
5918 This is fine, because it's impossible to allocate or mmap an
5919 array/buffer larger than what size_t can represent. */
5920 return gdb::make_array_view (section
->buffer
, section
->size
);
5923 /* Lookup the index cache for the contents of the index associated to
5926 static gdb::array_view
<const gdb_byte
>
5927 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5929 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5930 if (build_id
== nullptr)
5933 return global_index_cache
.lookup_gdb_index (build_id
,
5934 &dwarf2_per_bfd
->index_cache_res
);
5937 /* Same as the above, but for DWZ. */
5939 static gdb::array_view
<const gdb_byte
>
5940 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5942 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5943 if (build_id
== nullptr)
5946 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5949 /* See symfile.h. */
5952 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5954 struct dwarf2_per_objfile
*dwarf2_per_objfile
5955 = get_dwarf2_per_objfile (objfile
);
5956 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
5958 /* If we're about to read full symbols, don't bother with the
5959 indices. In this case we also don't care if some other debug
5960 format is making psymtabs, because they are all about to be
5962 if ((objfile
->flags
& OBJF_READNOW
))
5964 /* When using READNOW, the using_index flag (set below) indicates that
5965 PER_BFD was already initialized, when we loaded some other objfile. */
5966 if (per_bfd
->using_index
)
5968 *index_kind
= dw_index_kind::GDB_INDEX
;
5969 dwarf2_per_objfile
->resize_symtabs ();
5973 per_bfd
->using_index
= 1;
5974 create_all_comp_units (dwarf2_per_objfile
);
5975 create_all_type_units (dwarf2_per_objfile
);
5976 per_bfd
->quick_file_names_table
5977 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5978 dwarf2_per_objfile
->resize_symtabs ();
5980 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
5981 + per_bfd
->all_type_units
.size ()); ++i
)
5983 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
5985 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5986 struct dwarf2_per_cu_quick_data
);
5989 /* Return 1 so that gdb sees the "quick" functions. However,
5990 these functions will be no-ops because we will have expanded
5992 *index_kind
= dw_index_kind::GDB_INDEX
;
5996 /* Was a debug names index already read when we processed an objfile sharing
5998 if (per_bfd
->debug_names_table
!= nullptr)
6000 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6001 dwarf2_per_objfile
->resize_symtabs ();
6005 /* Was a GDB index already read when we processed an objfile sharing
6007 if (per_bfd
->index_table
!= nullptr)
6009 *index_kind
= dw_index_kind::GDB_INDEX
;
6010 dwarf2_per_objfile
->resize_symtabs ();
6014 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6016 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6017 dwarf2_per_objfile
->resize_symtabs ();
6021 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6022 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6023 get_gdb_index_contents_from_section
<dwz_file
>))
6025 *index_kind
= dw_index_kind::GDB_INDEX
;
6026 dwarf2_per_objfile
->resize_symtabs ();
6030 /* ... otherwise, try to find the index in the index cache. */
6031 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6032 get_gdb_index_contents_from_cache
,
6033 get_gdb_index_contents_from_cache_dwz
))
6035 global_index_cache
.hit ();
6036 *index_kind
= dw_index_kind::GDB_INDEX
;
6037 dwarf2_per_objfile
->resize_symtabs ();
6041 global_index_cache
.miss ();
6047 /* Build a partial symbol table. */
6050 dwarf2_build_psymtabs (struct objfile
*objfile
)
6052 struct dwarf2_per_objfile
*dwarf2_per_objfile
6053 = get_dwarf2_per_objfile (objfile
);
6054 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
6056 if (per_bfd
->partial_symtabs
!= nullptr)
6058 /* Partial symbols were already read, so now we can simply
6060 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6061 dwarf2_per_objfile
->resize_symtabs ();
6065 init_psymbol_list (objfile
, 1024);
6069 /* This isn't really ideal: all the data we allocate on the
6070 objfile's obstack is still uselessly kept around. However,
6071 freeing it seems unsafe. */
6072 psymtab_discarder
psymtabs (objfile
);
6073 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6076 dwarf2_per_objfile
->resize_symtabs ();
6078 /* (maybe) store an index in the cache. */
6079 global_index_cache
.store (dwarf2_per_objfile
);
6081 catch (const gdb_exception_error
&except
)
6083 exception_print (gdb_stderr
, except
);
6086 /* Finish by setting the local reference to partial symtabs, so that
6087 we don't try to read them again if reading another objfile with the same
6088 BFD. If we can't in fact share, this won't make a difference anyway as
6089 the dwarf2_per_bfd object won't be shared. */
6090 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6093 /* Find the base address of the compilation unit for range lists and
6094 location lists. It will normally be specified by DW_AT_low_pc.
6095 In DWARF-3 draft 4, the base address could be overridden by
6096 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6097 compilation units with discontinuous ranges. */
6100 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6102 struct attribute
*attr
;
6104 cu
->base_address
.reset ();
6106 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6107 if (attr
!= nullptr)
6108 cu
->base_address
= attr
->value_as_address ();
6111 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6112 if (attr
!= nullptr)
6113 cu
->base_address
= attr
->value_as_address ();
6117 /* Helper function that returns the proper abbrev section for
6120 static struct dwarf2_section_info
*
6121 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6123 struct dwarf2_section_info
*abbrev
;
6124 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6126 if (this_cu
->is_dwz
)
6127 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6129 abbrev
= &per_bfd
->abbrev
;
6134 /* Fetch the abbreviation table offset from a comp or type unit header. */
6137 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6138 struct dwarf2_section_info
*section
,
6139 sect_offset sect_off
)
6141 bfd
*abfd
= section
->get_bfd_owner ();
6142 const gdb_byte
*info_ptr
;
6143 unsigned int initial_length_size
, offset_size
;
6146 section
->read (dwarf2_per_objfile
->objfile
);
6147 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6148 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6149 offset_size
= initial_length_size
== 4 ? 4 : 8;
6150 info_ptr
+= initial_length_size
;
6152 version
= read_2_bytes (abfd
, info_ptr
);
6156 /* Skip unit type and address size. */
6160 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6163 /* A partial symtab that is used only for include files. */
6164 struct dwarf2_include_psymtab
: public partial_symtab
6166 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6167 : partial_symtab (filename
, objfile
)
6171 void read_symtab (struct objfile
*objfile
) override
6173 /* It's an include file, no symbols to read for it.
6174 Everything is in the includer symtab. */
6176 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6177 expansion of the includer psymtab. We use the dependencies[0] field to
6178 model the includer. But if we go the regular route of calling
6179 expand_psymtab here, and having expand_psymtab call expand_dependencies
6180 to expand the includer, we'll only use expand_psymtab on the includer
6181 (making it a non-toplevel psymtab), while if we expand the includer via
6182 another path, we'll use read_symtab (making it a toplevel psymtab).
6183 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6184 psymtab, and trigger read_symtab on the includer here directly. */
6185 includer ()->read_symtab (objfile
);
6188 void expand_psymtab (struct objfile
*objfile
) override
6190 /* This is not called by read_symtab, and should not be called by any
6191 expand_dependencies. */
6195 bool readin_p (struct objfile
*objfile
) const override
6197 return includer ()->readin_p (objfile
);
6200 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6206 partial_symtab
*includer () const
6208 /* An include psymtab has exactly one dependency: the psymtab that
6210 gdb_assert (this->number_of_dependencies
== 1);
6211 return this->dependencies
[0];
6215 /* Allocate a new partial symtab for file named NAME and mark this new
6216 partial symtab as being an include of PST. */
6219 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6220 struct objfile
*objfile
)
6222 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6224 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6225 subpst
->dirname
= pst
->dirname
;
6227 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6228 subpst
->dependencies
[0] = pst
;
6229 subpst
->number_of_dependencies
= 1;
6232 /* Read the Line Number Program data and extract the list of files
6233 included by the source file represented by PST. Build an include
6234 partial symtab for each of these included files. */
6237 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6238 struct die_info
*die
,
6239 dwarf2_psymtab
*pst
)
6242 struct attribute
*attr
;
6244 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6245 if (attr
!= nullptr)
6246 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6248 return; /* No linetable, so no includes. */
6250 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6251 that we pass in the raw text_low here; that is ok because we're
6252 only decoding the line table to make include partial symtabs, and
6253 so the addresses aren't really used. */
6254 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6255 pst
->raw_text_low (), 1);
6259 hash_signatured_type (const void *item
)
6261 const struct signatured_type
*sig_type
6262 = (const struct signatured_type
*) item
;
6264 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6265 return sig_type
->signature
;
6269 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6271 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6272 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6274 return lhs
->signature
== rhs
->signature
;
6277 /* Allocate a hash table for signatured types. */
6280 allocate_signatured_type_table ()
6282 return htab_up (htab_create_alloc (41,
6283 hash_signatured_type
,
6285 NULL
, xcalloc
, xfree
));
6288 /* A helper function to add a signatured type CU to a table. */
6291 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6293 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6294 std::vector
<signatured_type
*> *all_type_units
6295 = (std::vector
<signatured_type
*> *) datum
;
6297 all_type_units
->push_back (sigt
);
6302 /* A helper for create_debug_types_hash_table. Read types from SECTION
6303 and fill them into TYPES_HTAB. It will process only type units,
6304 therefore DW_UT_type. */
6307 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6308 struct dwo_file
*dwo_file
,
6309 dwarf2_section_info
*section
, htab_up
&types_htab
,
6310 rcuh_kind section_kind
)
6312 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6313 struct dwarf2_section_info
*abbrev_section
;
6315 const gdb_byte
*info_ptr
, *end_ptr
;
6317 abbrev_section
= (dwo_file
!= NULL
6318 ? &dwo_file
->sections
.abbrev
6319 : &dwarf2_per_objfile
->per_bfd
->abbrev
);
6321 if (dwarf_read_debug
)
6322 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6323 section
->get_name (),
6324 abbrev_section
->get_file_name ());
6326 section
->read (objfile
);
6327 info_ptr
= section
->buffer
;
6329 if (info_ptr
== NULL
)
6332 /* We can't set abfd until now because the section may be empty or
6333 not present, in which case the bfd is unknown. */
6334 abfd
= section
->get_bfd_owner ();
6336 /* We don't use cutu_reader here because we don't need to read
6337 any dies: the signature is in the header. */
6339 end_ptr
= info_ptr
+ section
->size
;
6340 while (info_ptr
< end_ptr
)
6342 struct signatured_type
*sig_type
;
6343 struct dwo_unit
*dwo_tu
;
6345 const gdb_byte
*ptr
= info_ptr
;
6346 struct comp_unit_head header
;
6347 unsigned int length
;
6349 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6351 /* Initialize it due to a false compiler warning. */
6352 header
.signature
= -1;
6353 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6355 /* We need to read the type's signature in order to build the hash
6356 table, but we don't need anything else just yet. */
6358 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6359 abbrev_section
, ptr
, section_kind
);
6361 length
= header
.get_length ();
6363 /* Skip dummy type units. */
6364 if (ptr
>= info_ptr
+ length
6365 || peek_abbrev_code (abfd
, ptr
) == 0
6366 || header
.unit_type
!= DW_UT_type
)
6372 if (types_htab
== NULL
)
6375 types_htab
= allocate_dwo_unit_table ();
6377 types_htab
= allocate_signatured_type_table ();
6383 dwo_tu
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6385 dwo_tu
->dwo_file
= dwo_file
;
6386 dwo_tu
->signature
= header
.signature
;
6387 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6388 dwo_tu
->section
= section
;
6389 dwo_tu
->sect_off
= sect_off
;
6390 dwo_tu
->length
= length
;
6394 /* N.B.: type_offset is not usable if this type uses a DWO file.
6395 The real type_offset is in the DWO file. */
6397 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6398 sig_type
->signature
= header
.signature
;
6399 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6400 sig_type
->per_cu
.is_debug_types
= 1;
6401 sig_type
->per_cu
.section
= section
;
6402 sig_type
->per_cu
.sect_off
= sect_off
;
6403 sig_type
->per_cu
.length
= length
;
6406 slot
= htab_find_slot (types_htab
.get (),
6407 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6409 gdb_assert (slot
!= NULL
);
6412 sect_offset dup_sect_off
;
6416 const struct dwo_unit
*dup_tu
6417 = (const struct dwo_unit
*) *slot
;
6419 dup_sect_off
= dup_tu
->sect_off
;
6423 const struct signatured_type
*dup_tu
6424 = (const struct signatured_type
*) *slot
;
6426 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6429 complaint (_("debug type entry at offset %s is duplicate to"
6430 " the entry at offset %s, signature %s"),
6431 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6432 hex_string (header
.signature
));
6434 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6436 if (dwarf_read_debug
> 1)
6437 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6438 sect_offset_str (sect_off
),
6439 hex_string (header
.signature
));
6445 /* Create the hash table of all entries in the .debug_types
6446 (or .debug_types.dwo) section(s).
6447 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6448 otherwise it is NULL.
6450 The result is a pointer to the hash table or NULL if there are no types.
6452 Note: This function processes DWO files only, not DWP files. */
6455 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6456 struct dwo_file
*dwo_file
,
6457 gdb::array_view
<dwarf2_section_info
> type_sections
,
6458 htab_up
&types_htab
)
6460 for (dwarf2_section_info
§ion
: type_sections
)
6461 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6462 types_htab
, rcuh_kind::TYPE
);
6465 /* Create the hash table of all entries in the .debug_types section,
6466 and initialize all_type_units.
6467 The result is zero if there is an error (e.g. missing .debug_types section),
6468 otherwise non-zero. */
6471 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6475 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6476 &dwarf2_per_objfile
->per_bfd
->info
, types_htab
,
6477 rcuh_kind::COMPILE
);
6478 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6479 dwarf2_per_objfile
->per_bfd
->types
, types_htab
);
6480 if (types_htab
== NULL
)
6482 dwarf2_per_objfile
->per_bfd
->signatured_types
= NULL
;
6486 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6488 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
6489 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve
6490 (htab_elements (dwarf2_per_objfile
->per_bfd
->signatured_types
.get ()));
6492 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6493 add_signatured_type_cu_to_table
,
6494 &dwarf2_per_objfile
->per_bfd
->all_type_units
);
6499 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6500 If SLOT is non-NULL, it is the entry to use in the hash table.
6501 Otherwise we find one. */
6503 static struct signatured_type
*
6504 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6507 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()
6508 == dwarf2_per_objfile
->per_bfd
->all_type_units
.capacity ())
6509 ++dwarf2_per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6511 signatured_type
*sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6513 dwarf2_per_objfile
->resize_symtabs ();
6515 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6516 sig_type
->signature
= sig
;
6517 sig_type
->per_cu
.is_debug_types
= 1;
6518 if (dwarf2_per_objfile
->per_bfd
->using_index
)
6520 sig_type
->per_cu
.v
.quick
=
6521 OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6522 struct dwarf2_per_cu_quick_data
);
6527 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6530 gdb_assert (*slot
== NULL
);
6532 /* The rest of sig_type must be filled in by the caller. */
6536 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6537 Fill in SIG_ENTRY with DWO_ENTRY. */
6540 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6541 struct signatured_type
*sig_entry
,
6542 struct dwo_unit
*dwo_entry
)
6544 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
6546 /* Make sure we're not clobbering something we don't expect to. */
6547 gdb_assert (! sig_entry
->per_cu
.queued
);
6548 gdb_assert (dwarf2_per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6549 if (per_bfd
->using_index
)
6551 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6552 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6555 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6556 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6557 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6558 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6559 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6561 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6562 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6563 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6564 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6565 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6566 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6567 sig_entry
->dwo_unit
= dwo_entry
;
6570 /* Subroutine of lookup_signatured_type.
6571 If we haven't read the TU yet, create the signatured_type data structure
6572 for a TU to be read in directly from a DWO file, bypassing the stub.
6573 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6574 using .gdb_index, then when reading a CU we want to stay in the DWO file
6575 containing that CU. Otherwise we could end up reading several other DWO
6576 files (due to comdat folding) to process the transitive closure of all the
6577 mentioned TUs, and that can be slow. The current DWO file will have every
6578 type signature that it needs.
6579 We only do this for .gdb_index because in the psymtab case we already have
6580 to read all the DWOs to build the type unit groups. */
6582 static struct signatured_type
*
6583 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6585 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6586 struct dwo_file
*dwo_file
;
6587 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6588 struct signatured_type find_sig_entry
, *sig_entry
;
6591 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6593 /* If TU skeletons have been removed then we may not have read in any
6595 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6596 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6598 /* We only ever need to read in one copy of a signatured type.
6599 Use the global signatured_types array to do our own comdat-folding
6600 of types. If this is the first time we're reading this TU, and
6601 the TU has an entry in .gdb_index, replace the recorded data from
6602 .gdb_index with this TU. */
6604 find_sig_entry
.signature
= sig
;
6605 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6606 &find_sig_entry
, INSERT
);
6607 sig_entry
= (struct signatured_type
*) *slot
;
6609 /* We can get here with the TU already read, *or* in the process of being
6610 read. Don't reassign the global entry to point to this DWO if that's
6611 the case. Also note that if the TU is already being read, it may not
6612 have come from a DWO, the program may be a mix of Fission-compiled
6613 code and non-Fission-compiled code. */
6615 /* Have we already tried to read this TU?
6616 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6617 needn't exist in the global table yet). */
6618 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6621 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6622 dwo_unit of the TU itself. */
6623 dwo_file
= cu
->dwo_unit
->dwo_file
;
6625 /* Ok, this is the first time we're reading this TU. */
6626 if (dwo_file
->tus
== NULL
)
6628 find_dwo_entry
.signature
= sig
;
6629 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6631 if (dwo_entry
== NULL
)
6634 /* If the global table doesn't have an entry for this TU, add one. */
6635 if (sig_entry
== NULL
)
6636 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6638 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6639 sig_entry
->per_cu
.tu_read
= 1;
6643 /* Subroutine of lookup_signatured_type.
6644 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6645 then try the DWP file. If the TU stub (skeleton) has been removed then
6646 it won't be in .gdb_index. */
6648 static struct signatured_type
*
6649 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6651 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6652 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6653 struct dwo_unit
*dwo_entry
;
6654 struct signatured_type find_sig_entry
, *sig_entry
;
6657 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6658 gdb_assert (dwp_file
!= NULL
);
6660 /* If TU skeletons have been removed then we may not have read in any
6662 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6663 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6665 find_sig_entry
.signature
= sig
;
6666 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6667 &find_sig_entry
, INSERT
);
6668 sig_entry
= (struct signatured_type
*) *slot
;
6670 /* Have we already tried to read this TU?
6671 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6672 needn't exist in the global table yet). */
6673 if (sig_entry
!= NULL
)
6676 if (dwp_file
->tus
== NULL
)
6678 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6679 sig
, 1 /* is_debug_types */);
6680 if (dwo_entry
== NULL
)
6683 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6684 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6689 /* Lookup a signature based type for DW_FORM_ref_sig8.
6690 Returns NULL if signature SIG is not present in the table.
6691 It is up to the caller to complain about this. */
6693 static struct signatured_type
*
6694 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6696 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6699 && dwarf2_per_objfile
->per_bfd
->using_index
)
6701 /* We're in a DWO/DWP file, and we're using .gdb_index.
6702 These cases require special processing. */
6703 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6704 return lookup_dwo_signatured_type (cu
, sig
);
6706 return lookup_dwp_signatured_type (cu
, sig
);
6710 struct signatured_type find_entry
, *entry
;
6712 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6714 find_entry
.signature
= sig
;
6715 entry
= ((struct signatured_type
*)
6716 htab_find (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6722 /* Low level DIE reading support. */
6724 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6727 init_cu_die_reader (struct die_reader_specs
*reader
,
6728 struct dwarf2_cu
*cu
,
6729 struct dwarf2_section_info
*section
,
6730 struct dwo_file
*dwo_file
,
6731 struct abbrev_table
*abbrev_table
)
6733 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6734 reader
->abfd
= section
->get_bfd_owner ();
6736 reader
->dwo_file
= dwo_file
;
6737 reader
->die_section
= section
;
6738 reader
->buffer
= section
->buffer
;
6739 reader
->buffer_end
= section
->buffer
+ section
->size
;
6740 reader
->abbrev_table
= abbrev_table
;
6743 /* Subroutine of cutu_reader to simplify it.
6744 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6745 There's just a lot of work to do, and cutu_reader is big enough
6748 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6749 from it to the DIE in the DWO. If NULL we are skipping the stub.
6750 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6751 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6752 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6753 STUB_COMP_DIR may be non-NULL.
6754 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6755 are filled in with the info of the DIE from the DWO file.
6756 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6757 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6758 kept around for at least as long as *RESULT_READER.
6760 The result is non-zero if a valid (non-dummy) DIE was found. */
6763 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6764 struct dwo_unit
*dwo_unit
,
6765 struct die_info
*stub_comp_unit_die
,
6766 const char *stub_comp_dir
,
6767 struct die_reader_specs
*result_reader
,
6768 const gdb_byte
**result_info_ptr
,
6769 struct die_info
**result_comp_unit_die
,
6770 abbrev_table_up
*result_dwo_abbrev_table
)
6772 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6773 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6774 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6776 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6777 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6778 int i
,num_extra_attrs
;
6779 struct dwarf2_section_info
*dwo_abbrev_section
;
6780 struct die_info
*comp_unit_die
;
6782 /* At most one of these may be provided. */
6783 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6785 /* These attributes aren't processed until later:
6786 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6787 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6788 referenced later. However, these attributes are found in the stub
6789 which we won't have later. In order to not impose this complication
6790 on the rest of the code, we read them here and copy them to the
6799 if (stub_comp_unit_die
!= NULL
)
6801 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6803 if (!per_cu
->is_debug_types
)
6804 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6805 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6806 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6807 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6808 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6810 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6812 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6813 here (if needed). We need the value before we can process
6815 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6817 else if (stub_comp_dir
!= NULL
)
6819 /* Reconstruct the comp_dir attribute to simplify the code below. */
6820 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6821 comp_dir
->name
= DW_AT_comp_dir
;
6822 comp_dir
->form
= DW_FORM_string
;
6823 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6824 DW_STRING (comp_dir
) = stub_comp_dir
;
6827 /* Set up for reading the DWO CU/TU. */
6828 cu
->dwo_unit
= dwo_unit
;
6829 dwarf2_section_info
*section
= dwo_unit
->section
;
6830 section
->read (objfile
);
6831 abfd
= section
->get_bfd_owner ();
6832 begin_info_ptr
= info_ptr
= (section
->buffer
6833 + to_underlying (dwo_unit
->sect_off
));
6834 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6836 if (per_cu
->is_debug_types
)
6838 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6840 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6841 &cu
->header
, section
,
6843 info_ptr
, rcuh_kind::TYPE
);
6844 /* This is not an assert because it can be caused by bad debug info. */
6845 if (sig_type
->signature
!= cu
->header
.signature
)
6847 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6848 " TU at offset %s [in module %s]"),
6849 hex_string (sig_type
->signature
),
6850 hex_string (cu
->header
.signature
),
6851 sect_offset_str (dwo_unit
->sect_off
),
6852 bfd_get_filename (abfd
));
6854 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6855 /* For DWOs coming from DWP files, we don't know the CU length
6856 nor the type's offset in the TU until now. */
6857 dwo_unit
->length
= cu
->header
.get_length ();
6858 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6860 /* Establish the type offset that can be used to lookup the type.
6861 For DWO files, we don't know it until now. */
6862 sig_type
->type_offset_in_section
6863 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6867 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6868 &cu
->header
, section
,
6870 info_ptr
, rcuh_kind::COMPILE
);
6871 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6872 /* For DWOs coming from DWP files, we don't know the CU length
6874 dwo_unit
->length
= cu
->header
.get_length ();
6877 *result_dwo_abbrev_table
6878 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6879 cu
->header
.abbrev_sect_off
);
6880 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6881 result_dwo_abbrev_table
->get ());
6883 /* Read in the die, but leave space to copy over the attributes
6884 from the stub. This has the benefit of simplifying the rest of
6885 the code - all the work to maintain the illusion of a single
6886 DW_TAG_{compile,type}_unit DIE is done here. */
6887 num_extra_attrs
= ((stmt_list
!= NULL
)
6891 + (comp_dir
!= NULL
));
6892 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6895 /* Copy over the attributes from the stub to the DIE we just read in. */
6896 comp_unit_die
= *result_comp_unit_die
;
6897 i
= comp_unit_die
->num_attrs
;
6898 if (stmt_list
!= NULL
)
6899 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6901 comp_unit_die
->attrs
[i
++] = *low_pc
;
6902 if (high_pc
!= NULL
)
6903 comp_unit_die
->attrs
[i
++] = *high_pc
;
6905 comp_unit_die
->attrs
[i
++] = *ranges
;
6906 if (comp_dir
!= NULL
)
6907 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6908 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6910 if (dwarf_die_debug
)
6912 fprintf_unfiltered (gdb_stdlog
,
6913 "Read die from %s@0x%x of %s:\n",
6914 section
->get_name (),
6915 (unsigned) (begin_info_ptr
- section
->buffer
),
6916 bfd_get_filename (abfd
));
6917 dump_die (comp_unit_die
, dwarf_die_debug
);
6920 /* Skip dummy compilation units. */
6921 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6922 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6925 *result_info_ptr
= info_ptr
;
6929 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6930 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6931 signature is part of the header. */
6932 static gdb::optional
<ULONGEST
>
6933 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6935 if (cu
->header
.version
>= 5)
6936 return cu
->header
.signature
;
6937 struct attribute
*attr
;
6938 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6939 if (attr
== nullptr)
6940 return gdb::optional
<ULONGEST
> ();
6941 return DW_UNSND (attr
);
6944 /* Subroutine of cutu_reader to simplify it.
6945 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6946 Returns NULL if the specified DWO unit cannot be found. */
6948 static struct dwo_unit
*
6949 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6951 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6952 struct dwo_unit
*dwo_unit
;
6953 const char *comp_dir
;
6955 gdb_assert (cu
!= NULL
);
6957 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6958 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6959 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6961 if (per_cu
->is_debug_types
)
6962 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6965 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6967 if (!signature
.has_value ())
6968 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6970 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6972 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6978 /* Subroutine of cutu_reader to simplify it.
6979 See it for a description of the parameters.
6980 Read a TU directly from a DWO file, bypassing the stub. */
6983 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6984 dwarf2_per_objfile
*per_objfile
,
6985 dwarf2_cu
*existing_cu
)
6987 struct signatured_type
*sig_type
;
6989 /* Verify we can do the following downcast, and that we have the
6991 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6992 sig_type
= (struct signatured_type
*) this_cu
;
6993 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6997 if (existing_cu
!= nullptr)
7000 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7001 /* There's no need to do the rereading_dwo_cu handling that
7002 cutu_reader does since we don't read the stub. */
7006 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7007 in per_objfile yet. */
7008 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7009 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7010 cu
= m_new_cu
.get ();
7013 /* A future optimization, if needed, would be to use an existing
7014 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7015 could share abbrev tables. */
7017 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7018 NULL
/* stub_comp_unit_die */,
7019 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7022 &m_dwo_abbrev_table
) == 0)
7029 /* Initialize a CU (or TU) and read its DIEs.
7030 If the CU defers to a DWO file, read the DWO file as well.
7032 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7033 Otherwise the table specified in the comp unit header is read in and used.
7034 This is an optimization for when we already have the abbrev table.
7036 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7039 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7040 dwarf2_per_objfile
*dwarf2_per_objfile
,
7041 struct abbrev_table
*abbrev_table
,
7042 dwarf2_cu
*existing_cu
,
7044 : die_reader_specs
{},
7047 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7048 struct dwarf2_section_info
*section
= this_cu
->section
;
7049 bfd
*abfd
= section
->get_bfd_owner ();
7050 const gdb_byte
*begin_info_ptr
;
7051 struct signatured_type
*sig_type
= NULL
;
7052 struct dwarf2_section_info
*abbrev_section
;
7053 /* Non-zero if CU currently points to a DWO file and we need to
7054 reread it. When this happens we need to reread the skeleton die
7055 before we can reread the DWO file (this only applies to CUs, not TUs). */
7056 int rereading_dwo_cu
= 0;
7058 if (dwarf_die_debug
)
7059 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7060 this_cu
->is_debug_types
? "type" : "comp",
7061 sect_offset_str (this_cu
->sect_off
));
7063 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7064 file (instead of going through the stub), short-circuit all of this. */
7065 if (this_cu
->reading_dwo_directly
)
7067 /* Narrow down the scope of possibilities to have to understand. */
7068 gdb_assert (this_cu
->is_debug_types
);
7069 gdb_assert (abbrev_table
== NULL
);
7070 init_tu_and_read_dwo_dies (this_cu
, dwarf2_per_objfile
, existing_cu
);
7074 /* This is cheap if the section is already read in. */
7075 section
->read (objfile
);
7077 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7079 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7083 if (existing_cu
!= nullptr)
7086 /* If this CU is from a DWO file we need to start over, we need to
7087 refetch the attributes from the skeleton CU.
7088 This could be optimized by retrieving those attributes from when we
7089 were here the first time: the previous comp_unit_die was stored in
7090 comp_unit_obstack. But there's no data yet that we need this
7092 if (cu
->dwo_unit
!= NULL
)
7093 rereading_dwo_cu
= 1;
7097 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7098 in per_objfile yet. */
7099 gdb_assert (dwarf2_per_objfile
->get_cu (this_cu
) == nullptr);
7100 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7101 cu
= m_new_cu
.get ();
7104 /* Get the header. */
7105 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7107 /* We already have the header, there's no need to read it in again. */
7108 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7112 if (this_cu
->is_debug_types
)
7114 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7115 &cu
->header
, section
,
7116 abbrev_section
, info_ptr
,
7119 /* Since per_cu is the first member of struct signatured_type,
7120 we can go from a pointer to one to a pointer to the other. */
7121 sig_type
= (struct signatured_type
*) this_cu
;
7122 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7123 gdb_assert (sig_type
->type_offset_in_tu
7124 == cu
->header
.type_cu_offset_in_tu
);
7125 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7127 /* LENGTH has not been set yet for type units if we're
7128 using .gdb_index. */
7129 this_cu
->length
= cu
->header
.get_length ();
7131 /* Establish the type offset that can be used to lookup the type. */
7132 sig_type
->type_offset_in_section
=
7133 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7135 this_cu
->dwarf_version
= cu
->header
.version
;
7139 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7140 &cu
->header
, section
,
7143 rcuh_kind::COMPILE
);
7145 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7146 if (this_cu
->length
== 0)
7147 this_cu
->length
= cu
->header
.get_length ();
7149 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7150 this_cu
->dwarf_version
= cu
->header
.version
;
7154 /* Skip dummy compilation units. */
7155 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7156 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7162 /* If we don't have them yet, read the abbrevs for this compilation unit.
7163 And if we need to read them now, make sure they're freed when we're
7165 if (abbrev_table
!= NULL
)
7166 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7169 m_abbrev_table_holder
7170 = abbrev_table::read (objfile
, abbrev_section
,
7171 cu
->header
.abbrev_sect_off
);
7172 abbrev_table
= m_abbrev_table_holder
.get ();
7175 /* Read the top level CU/TU die. */
7176 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7177 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7179 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7185 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7186 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7187 table from the DWO file and pass the ownership over to us. It will be
7188 referenced from READER, so we must make sure to free it after we're done
7191 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7192 DWO CU, that this test will fail (the attribute will not be present). */
7193 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7194 if (dwo_name
!= nullptr)
7196 struct dwo_unit
*dwo_unit
;
7197 struct die_info
*dwo_comp_unit_die
;
7199 if (comp_unit_die
->has_children
)
7201 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7202 " has children (offset %s) [in module %s]"),
7203 sect_offset_str (this_cu
->sect_off
),
7204 bfd_get_filename (abfd
));
7206 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7207 if (dwo_unit
!= NULL
)
7209 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7210 comp_unit_die
, NULL
,
7213 &m_dwo_abbrev_table
) == 0)
7219 comp_unit_die
= dwo_comp_unit_die
;
7223 /* Yikes, we couldn't find the rest of the DIE, we only have
7224 the stub. A complaint has already been logged. There's
7225 not much more we can do except pass on the stub DIE to
7226 die_reader_func. We don't want to throw an error on bad
7233 cutu_reader::keep ()
7235 /* Done, clean up. */
7236 gdb_assert (!dummy_p
);
7237 if (m_new_cu
!= NULL
)
7239 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7241 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7242 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7246 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7247 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7248 assumed to have already done the lookup to find the DWO file).
7250 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7251 THIS_CU->is_debug_types, but nothing else.
7253 We fill in THIS_CU->length.
7255 THIS_CU->cu is always freed when done.
7256 This is done in order to not leave THIS_CU->cu in a state where we have
7257 to care whether it refers to the "main" CU or the DWO CU.
7259 When parent_cu is passed, it is used to provide a default value for
7260 str_offsets_base and addr_base from the parent. */
7262 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7263 dwarf2_per_objfile
*dwarf2_per_objfile
,
7264 struct dwarf2_cu
*parent_cu
,
7265 struct dwo_file
*dwo_file
)
7266 : die_reader_specs
{},
7269 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7270 struct dwarf2_section_info
*section
= this_cu
->section
;
7271 bfd
*abfd
= section
->get_bfd_owner ();
7272 struct dwarf2_section_info
*abbrev_section
;
7273 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7275 if (dwarf_die_debug
)
7276 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7277 this_cu
->is_debug_types
? "type" : "comp",
7278 sect_offset_str (this_cu
->sect_off
));
7280 gdb_assert (dwarf2_per_objfile
->get_cu (this_cu
) == nullptr);
7282 abbrev_section
= (dwo_file
!= NULL
7283 ? &dwo_file
->sections
.abbrev
7284 : get_abbrev_section_for_cu (this_cu
));
7286 /* This is cheap if the section is already read in. */
7287 section
->read (objfile
);
7289 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7291 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7292 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7293 &m_new_cu
->header
, section
,
7294 abbrev_section
, info_ptr
,
7295 (this_cu
->is_debug_types
7297 : rcuh_kind::COMPILE
));
7299 if (parent_cu
!= nullptr)
7301 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7302 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7304 this_cu
->length
= m_new_cu
->header
.get_length ();
7306 /* Skip dummy compilation units. */
7307 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7308 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7314 m_abbrev_table_holder
7315 = abbrev_table::read (objfile
, abbrev_section
,
7316 m_new_cu
->header
.abbrev_sect_off
);
7318 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7319 m_abbrev_table_holder
.get ());
7320 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7324 /* Type Unit Groups.
7326 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7327 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7328 so that all types coming from the same compilation (.o file) are grouped
7329 together. A future step could be to put the types in the same symtab as
7330 the CU the types ultimately came from. */
7333 hash_type_unit_group (const void *item
)
7335 const struct type_unit_group
*tu_group
7336 = (const struct type_unit_group
*) item
;
7338 return hash_stmt_list_entry (&tu_group
->hash
);
7342 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7344 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7345 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7347 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7350 /* Allocate a hash table for type unit groups. */
7353 allocate_type_unit_groups_table ()
7355 return htab_up (htab_create_alloc (3,
7356 hash_type_unit_group
,
7358 NULL
, xcalloc
, xfree
));
7361 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7362 partial symtabs. We combine several TUs per psymtab to not let the size
7363 of any one psymtab grow too big. */
7364 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7365 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7367 /* Helper routine for get_type_unit_group.
7368 Create the type_unit_group object used to hold one or more TUs. */
7370 static struct type_unit_group
*
7371 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7373 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7374 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
7375 struct dwarf2_per_cu_data
*per_cu
;
7376 struct type_unit_group
*tu_group
;
7378 tu_group
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
7379 struct type_unit_group
);
7380 per_cu
= &tu_group
->per_cu
;
7381 per_cu
->per_bfd
= per_bfd
;
7383 if (per_bfd
->using_index
)
7385 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7386 struct dwarf2_per_cu_quick_data
);
7390 unsigned int line_offset
= to_underlying (line_offset_struct
);
7391 dwarf2_psymtab
*pst
;
7394 /* Give the symtab a useful name for debug purposes. */
7395 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7396 name
= string_printf ("<type_units_%d>",
7397 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7399 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7401 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, name
.c_str ());
7402 pst
->anonymous
= true;
7405 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7406 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7411 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7412 STMT_LIST is a DW_AT_stmt_list attribute. */
7414 static struct type_unit_group
*
7415 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7417 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7418 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7419 struct type_unit_group
*tu_group
;
7421 unsigned int line_offset
;
7422 struct type_unit_group type_unit_group_for_lookup
;
7424 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7425 dwarf2_per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7427 /* Do we need to create a new group, or can we use an existing one? */
7431 line_offset
= DW_UNSND (stmt_list
);
7432 ++tu_stats
->nr_symtab_sharers
;
7436 /* Ugh, no stmt_list. Rare, but we have to handle it.
7437 We can do various things here like create one group per TU or
7438 spread them over multiple groups to split up the expansion work.
7439 To avoid worst case scenarios (too many groups or too large groups)
7440 we, umm, group them in bunches. */
7441 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7442 | (tu_stats
->nr_stmt_less_type_units
7443 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7444 ++tu_stats
->nr_stmt_less_type_units
;
7447 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7448 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7449 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7450 &type_unit_group_for_lookup
, INSERT
);
7453 tu_group
= (struct type_unit_group
*) *slot
;
7454 gdb_assert (tu_group
!= NULL
);
7458 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7459 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7461 ++tu_stats
->nr_symtabs
;
7467 /* Partial symbol tables. */
7469 /* Create a psymtab named NAME and assign it to PER_CU.
7471 The caller must fill in the following details:
7472 dirname, textlow, texthigh. */
7474 static dwarf2_psymtab
*
7475 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7476 dwarf2_per_objfile
*per_objfile
,
7479 struct objfile
*objfile
= per_objfile
->objfile
;
7480 dwarf2_psymtab
*pst
;
7482 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7484 pst
->psymtabs_addrmap_supported
= true;
7486 /* This is the glue that links PST into GDB's symbol API. */
7487 per_cu
->v
.psymtab
= pst
;
7492 /* DIE reader function for process_psymtab_comp_unit. */
7495 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7496 const gdb_byte
*info_ptr
,
7497 struct die_info
*comp_unit_die
,
7498 enum language pretend_language
)
7500 struct dwarf2_cu
*cu
= reader
->cu
;
7501 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7502 struct objfile
*objfile
= per_objfile
->objfile
;
7503 struct gdbarch
*gdbarch
= objfile
->arch ();
7504 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7506 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7507 dwarf2_psymtab
*pst
;
7508 enum pc_bounds_kind cu_bounds_kind
;
7509 const char *filename
;
7511 gdb_assert (! per_cu
->is_debug_types
);
7513 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7515 /* Allocate a new partial symbol table structure. */
7516 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7517 static const char artificial
[] = "<artificial>";
7518 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7519 if (filename
== NULL
)
7521 else if (strcmp (filename
, artificial
) == 0)
7523 debug_filename
.reset (concat (artificial
, "@",
7524 sect_offset_str (per_cu
->sect_off
),
7526 filename
= debug_filename
.get ();
7529 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7531 /* This must be done before calling dwarf2_build_include_psymtabs. */
7532 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7534 baseaddr
= objfile
->text_section_offset ();
7536 dwarf2_find_base_address (comp_unit_die
, cu
);
7538 /* Possibly set the default values of LOWPC and HIGHPC from
7540 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7541 &best_highpc
, cu
, pst
);
7542 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7545 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7548 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7550 /* Store the contiguous range if it is not empty; it can be
7551 empty for CUs with no code. */
7552 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7556 /* Check if comp unit has_children.
7557 If so, read the rest of the partial symbols from this comp unit.
7558 If not, there's no more debug_info for this comp unit. */
7559 if (comp_unit_die
->has_children
)
7561 struct partial_die_info
*first_die
;
7562 CORE_ADDR lowpc
, highpc
;
7564 lowpc
= ((CORE_ADDR
) -1);
7565 highpc
= ((CORE_ADDR
) 0);
7567 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7569 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7570 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7572 /* If we didn't find a lowpc, set it to highpc to avoid
7573 complaints from `maint check'. */
7574 if (lowpc
== ((CORE_ADDR
) -1))
7577 /* If the compilation unit didn't have an explicit address range,
7578 then use the information extracted from its child dies. */
7579 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7582 best_highpc
= highpc
;
7585 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7586 best_lowpc
+ baseaddr
)
7588 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7589 best_highpc
+ baseaddr
)
7592 end_psymtab_common (objfile
, pst
);
7594 if (!cu
->per_cu
->imported_symtabs_empty ())
7597 int len
= cu
->per_cu
->imported_symtabs_size ();
7599 /* Fill in 'dependencies' here; we fill in 'users' in a
7601 pst
->number_of_dependencies
= len
;
7603 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7604 for (i
= 0; i
< len
; ++i
)
7606 pst
->dependencies
[i
]
7607 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7610 cu
->per_cu
->imported_symtabs_free ();
7613 /* Get the list of files included in the current compilation unit,
7614 and build a psymtab for each of them. */
7615 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7617 if (dwarf_read_debug
)
7618 fprintf_unfiltered (gdb_stdlog
,
7619 "Psymtab for %s unit @%s: %s - %s"
7620 ", %d global, %d static syms\n",
7621 per_cu
->is_debug_types
? "type" : "comp",
7622 sect_offset_str (per_cu
->sect_off
),
7623 paddress (gdbarch
, pst
->text_low (objfile
)),
7624 paddress (gdbarch
, pst
->text_high (objfile
)),
7625 pst
->n_global_syms
, pst
->n_static_syms
);
7628 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7629 Process compilation unit THIS_CU for a psymtab. */
7632 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7633 dwarf2_per_objfile
*per_objfile
,
7634 bool want_partial_unit
,
7635 enum language pretend_language
)
7637 /* If this compilation unit was already read in, free the
7638 cached copy in order to read it in again. This is
7639 necessary because we skipped some symbols when we first
7640 read in the compilation unit (see load_partial_dies).
7641 This problem could be avoided, but the benefit is unclear. */
7642 per_objfile
->remove_cu (this_cu
);
7644 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7646 switch (reader
.comp_unit_die
->tag
)
7648 case DW_TAG_compile_unit
:
7649 this_cu
->unit_type
= DW_UT_compile
;
7651 case DW_TAG_partial_unit
:
7652 this_cu
->unit_type
= DW_UT_partial
;
7662 else if (this_cu
->is_debug_types
)
7663 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7664 reader
.comp_unit_die
);
7665 else if (want_partial_unit
7666 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7667 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7668 reader
.comp_unit_die
,
7671 this_cu
->lang
= reader
.cu
->language
;
7673 /* Age out any secondary CUs. */
7674 per_objfile
->age_comp_units ();
7677 /* Reader function for build_type_psymtabs. */
7680 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7681 const gdb_byte
*info_ptr
,
7682 struct die_info
*type_unit_die
)
7684 struct dwarf2_per_objfile
*dwarf2_per_objfile
= reader
->cu
->per_objfile
;
7685 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7686 struct dwarf2_cu
*cu
= reader
->cu
;
7687 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7688 struct signatured_type
*sig_type
;
7689 struct type_unit_group
*tu_group
;
7690 struct attribute
*attr
;
7691 struct partial_die_info
*first_die
;
7692 CORE_ADDR lowpc
, highpc
;
7693 dwarf2_psymtab
*pst
;
7695 gdb_assert (per_cu
->is_debug_types
);
7696 sig_type
= (struct signatured_type
*) per_cu
;
7698 if (! type_unit_die
->has_children
)
7701 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7702 tu_group
= get_type_unit_group (cu
, attr
);
7704 if (tu_group
->tus
== nullptr)
7705 tu_group
->tus
= new std::vector
<signatured_type
*>;
7706 tu_group
->tus
->push_back (sig_type
);
7708 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7709 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, "");
7710 pst
->anonymous
= true;
7712 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7714 lowpc
= (CORE_ADDR
) -1;
7715 highpc
= (CORE_ADDR
) 0;
7716 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7718 end_psymtab_common (objfile
, pst
);
7721 /* Struct used to sort TUs by their abbreviation table offset. */
7723 struct tu_abbrev_offset
7725 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7726 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7729 signatured_type
*sig_type
;
7730 sect_offset abbrev_offset
;
7733 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7736 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7737 const struct tu_abbrev_offset
&b
)
7739 return a
.abbrev_offset
< b
.abbrev_offset
;
7742 /* Efficiently read all the type units.
7743 This does the bulk of the work for build_type_psymtabs.
7745 The efficiency is because we sort TUs by the abbrev table they use and
7746 only read each abbrev table once. In one program there are 200K TUs
7747 sharing 8K abbrev tables.
7749 The main purpose of this function is to support building the
7750 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7751 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7752 can collapse the search space by grouping them by stmt_list.
7753 The savings can be significant, in the same program from above the 200K TUs
7754 share 8K stmt_list tables.
7756 FUNC is expected to call get_type_unit_group, which will create the
7757 struct type_unit_group if necessary and add it to
7758 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7761 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7763 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7764 abbrev_table_up abbrev_table
;
7765 sect_offset abbrev_offset
;
7767 /* It's up to the caller to not call us multiple times. */
7768 gdb_assert (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7770 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ())
7773 /* TUs typically share abbrev tables, and there can be way more TUs than
7774 abbrev tables. Sort by abbrev table to reduce the number of times we
7775 read each abbrev table in.
7776 Alternatives are to punt or to maintain a cache of abbrev tables.
7777 This is simpler and efficient enough for now.
7779 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7780 symtab to use). Typically TUs with the same abbrev offset have the same
7781 stmt_list value too so in practice this should work well.
7783 The basic algorithm here is:
7785 sort TUs by abbrev table
7786 for each TU with same abbrev table:
7787 read abbrev table if first user
7788 read TU top level DIE
7789 [IWBN if DWO skeletons had DW_AT_stmt_list]
7792 if (dwarf_read_debug
)
7793 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7795 /* Sort in a separate table to maintain the order of all_type_units
7796 for .gdb_index: TU indices directly index all_type_units. */
7797 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7798 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7800 for (signatured_type
*sig_type
: dwarf2_per_objfile
->per_bfd
->all_type_units
)
7801 sorted_by_abbrev
.emplace_back
7802 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7803 sig_type
->per_cu
.section
,
7804 sig_type
->per_cu
.sect_off
));
7806 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7807 sort_tu_by_abbrev_offset
);
7809 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7811 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7813 /* Switch to the next abbrev table if necessary. */
7814 if (abbrev_table
== NULL
7815 || tu
.abbrev_offset
!= abbrev_offset
)
7817 abbrev_offset
= tu
.abbrev_offset
;
7819 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7820 &dwarf2_per_objfile
->per_bfd
->abbrev
,
7822 ++tu_stats
->nr_uniq_abbrev_tables
;
7825 cutu_reader
reader (&tu
.sig_type
->per_cu
, dwarf2_per_objfile
,
7826 abbrev_table
.get (), nullptr, false);
7827 if (!reader
.dummy_p
)
7828 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7829 reader
.comp_unit_die
);
7833 /* Print collected type unit statistics. */
7836 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7838 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7840 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7841 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7842 dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7843 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7844 tu_stats
->nr_uniq_abbrev_tables
);
7845 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7846 tu_stats
->nr_symtabs
);
7847 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7848 tu_stats
->nr_symtab_sharers
);
7849 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7850 tu_stats
->nr_stmt_less_type_units
);
7851 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7852 tu_stats
->nr_all_type_units_reallocs
);
7855 /* Traversal function for build_type_psymtabs. */
7858 build_type_psymtab_dependencies (void **slot
, void *info
)
7860 struct dwarf2_per_objfile
*dwarf2_per_objfile
7861 = (struct dwarf2_per_objfile
*) info
;
7862 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7863 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7864 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7865 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7866 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7869 gdb_assert (len
> 0);
7870 gdb_assert (per_cu
->type_unit_group_p ());
7872 pst
->number_of_dependencies
= len
;
7873 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7874 for (i
= 0; i
< len
; ++i
)
7876 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7877 gdb_assert (iter
->per_cu
.is_debug_types
);
7878 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7879 iter
->type_unit_group
= tu_group
;
7882 delete tu_group
->tus
;
7883 tu_group
->tus
= nullptr;
7888 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7889 Build partial symbol tables for the .debug_types comp-units. */
7892 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7894 if (! create_all_type_units (dwarf2_per_objfile
))
7897 build_type_psymtabs_1 (dwarf2_per_objfile
);
7900 /* Traversal function for process_skeletonless_type_unit.
7901 Read a TU in a DWO file and build partial symbols for it. */
7904 process_skeletonless_type_unit (void **slot
, void *info
)
7906 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7907 struct dwarf2_per_objfile
*dwarf2_per_objfile
7908 = (struct dwarf2_per_objfile
*) info
;
7909 struct signatured_type find_entry
, *entry
;
7911 /* If this TU doesn't exist in the global table, add it and read it in. */
7913 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
7914 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7916 find_entry
.signature
= dwo_unit
->signature
;
7917 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
7918 &find_entry
, INSERT
);
7919 /* If we've already seen this type there's nothing to do. What's happening
7920 is we're doing our own version of comdat-folding here. */
7924 /* This does the job that create_all_type_units would have done for
7926 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7927 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7930 /* This does the job that build_type_psymtabs_1 would have done. */
7931 cutu_reader
reader (&entry
->per_cu
, dwarf2_per_objfile
, nullptr, nullptr,
7933 if (!reader
.dummy_p
)
7934 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7935 reader
.comp_unit_die
);
7940 /* Traversal function for process_skeletonless_type_units. */
7943 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7945 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7947 if (dwo_file
->tus
!= NULL
)
7948 htab_traverse_noresize (dwo_file
->tus
.get (),
7949 process_skeletonless_type_unit
, info
);
7954 /* Scan all TUs of DWO files, verifying we've processed them.
7955 This is needed in case a TU was emitted without its skeleton.
7956 Note: This can't be done until we know what all the DWO files are. */
7959 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7961 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7962 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7963 && dwarf2_per_objfile
->per_bfd
->dwo_files
!= NULL
)
7965 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (),
7966 process_dwo_file_for_skeletonless_type_units
,
7967 dwarf2_per_objfile
);
7971 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7974 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7976 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7978 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7983 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7985 /* Set the 'user' field only if it is not already set. */
7986 if (pst
->dependencies
[j
]->user
== NULL
)
7987 pst
->dependencies
[j
]->user
= pst
;
7992 /* Build the partial symbol table by doing a quick pass through the
7993 .debug_info and .debug_abbrev sections. */
7996 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7998 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8000 if (dwarf_read_debug
)
8002 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8003 objfile_name (objfile
));
8006 scoped_restore restore_reading_psyms
8007 = make_scoped_restore (&dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
,
8010 dwarf2_per_objfile
->per_bfd
->info
.read (objfile
);
8012 /* Any cached compilation units will be linked by the per-objfile
8013 read_in_chain. Make sure to free them when we're done. */
8014 free_cached_comp_units
freer (dwarf2_per_objfile
);
8016 build_type_psymtabs (dwarf2_per_objfile
);
8018 create_all_comp_units (dwarf2_per_objfile
);
8020 /* Create a temporary address map on a temporary obstack. We later
8021 copy this to the final obstack. */
8022 auto_obstack temp_obstack
;
8024 scoped_restore save_psymtabs_addrmap
8025 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8026 addrmap_create_mutable (&temp_obstack
));
8028 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
8030 if (per_cu
->v
.psymtab
!= NULL
)
8031 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8033 process_psymtab_comp_unit (per_cu
, dwarf2_per_objfile
, false,
8037 /* This has to wait until we read the CUs, we need the list of DWOs. */
8038 process_skeletonless_type_units (dwarf2_per_objfile
);
8040 /* Now that all TUs have been processed we can fill in the dependencies. */
8041 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8043 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
8044 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8047 if (dwarf_read_debug
)
8048 print_tu_stats (dwarf2_per_objfile
);
8050 set_partial_user (dwarf2_per_objfile
);
8052 objfile
->partial_symtabs
->psymtabs_addrmap
8053 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8054 objfile
->partial_symtabs
->obstack ());
8055 /* At this point we want to keep the address map. */
8056 save_psymtabs_addrmap
.release ();
8058 if (dwarf_read_debug
)
8059 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8060 objfile_name (objfile
));
8063 /* Load the partial DIEs for a secondary CU into memory.
8064 This is also used when rereading a primary CU with load_all_dies. */
8067 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8068 dwarf2_per_objfile
*per_objfile
,
8069 dwarf2_cu
*existing_cu
)
8071 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8073 if (!reader
.dummy_p
)
8075 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8078 /* Check if comp unit has_children.
8079 If so, read the rest of the partial symbols from this comp unit.
8080 If not, there's no more debug_info for this comp unit. */
8081 if (reader
.comp_unit_die
->has_children
)
8082 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8089 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8090 struct dwarf2_section_info
*section
,
8091 struct dwarf2_section_info
*abbrev_section
,
8092 unsigned int is_dwz
)
8094 const gdb_byte
*info_ptr
;
8095 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8097 if (dwarf_read_debug
)
8098 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8099 section
->get_name (),
8100 section
->get_file_name ());
8102 section
->read (objfile
);
8104 info_ptr
= section
->buffer
;
8106 while (info_ptr
< section
->buffer
+ section
->size
)
8108 struct dwarf2_per_cu_data
*this_cu
;
8110 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8112 comp_unit_head cu_header
;
8113 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8114 abbrev_section
, info_ptr
,
8115 rcuh_kind::COMPILE
);
8117 /* Save the compilation unit for later lookup. */
8118 if (cu_header
.unit_type
!= DW_UT_type
)
8119 this_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
8122 auto sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
8123 sig_type
->signature
= cu_header
.signature
;
8124 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8125 this_cu
= &sig_type
->per_cu
;
8127 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8128 this_cu
->sect_off
= sect_off
;
8129 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8130 this_cu
->is_dwz
= is_dwz
;
8131 this_cu
->section
= section
;
8133 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8135 info_ptr
= info_ptr
+ this_cu
->length
;
8139 /* Create a list of all compilation units in OBJFILE.
8140 This is only done for -readnow and building partial symtabs. */
8143 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8145 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
8146 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->per_bfd
->info
,
8147 &dwarf2_per_objfile
->per_bfd
->abbrev
, 0);
8149 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
8151 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8155 /* Process all loaded DIEs for compilation unit CU, starting at
8156 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8157 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8158 DW_AT_ranges). See the comments of add_partial_subprogram on how
8159 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8162 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8163 CORE_ADDR
*highpc
, int set_addrmap
,
8164 struct dwarf2_cu
*cu
)
8166 struct partial_die_info
*pdi
;
8168 /* Now, march along the PDI's, descending into ones which have
8169 interesting children but skipping the children of the other ones,
8170 until we reach the end of the compilation unit. */
8178 /* Anonymous namespaces or modules have no name but have interesting
8179 children, so we need to look at them. Ditto for anonymous
8182 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8183 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8184 || pdi
->tag
== DW_TAG_imported_unit
8185 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8189 case DW_TAG_subprogram
:
8190 case DW_TAG_inlined_subroutine
:
8191 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8193 case DW_TAG_constant
:
8194 case DW_TAG_variable
:
8195 case DW_TAG_typedef
:
8196 case DW_TAG_union_type
:
8197 if (!pdi
->is_declaration
8198 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8200 add_partial_symbol (pdi
, cu
);
8203 case DW_TAG_class_type
:
8204 case DW_TAG_interface_type
:
8205 case DW_TAG_structure_type
:
8206 if (!pdi
->is_declaration
)
8208 add_partial_symbol (pdi
, cu
);
8210 if ((cu
->language
== language_rust
8211 || cu
->language
== language_cplus
) && pdi
->has_children
)
8212 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8215 case DW_TAG_enumeration_type
:
8216 if (!pdi
->is_declaration
)
8217 add_partial_enumeration (pdi
, cu
);
8219 case DW_TAG_base_type
:
8220 case DW_TAG_subrange_type
:
8221 /* File scope base type definitions are added to the partial
8223 add_partial_symbol (pdi
, cu
);
8225 case DW_TAG_namespace
:
8226 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8229 if (!pdi
->is_declaration
)
8230 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8232 case DW_TAG_imported_unit
:
8234 struct dwarf2_per_cu_data
*per_cu
;
8236 /* For now we don't handle imported units in type units. */
8237 if (cu
->per_cu
->is_debug_types
)
8239 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8240 " supported in type units [in module %s]"),
8241 objfile_name (cu
->per_objfile
->objfile
));
8244 per_cu
= dwarf2_find_containing_comp_unit
8245 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8247 /* Go read the partial unit, if needed. */
8248 if (per_cu
->v
.psymtab
== NULL
)
8249 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8252 cu
->per_cu
->imported_symtabs_push (per_cu
);
8255 case DW_TAG_imported_declaration
:
8256 add_partial_symbol (pdi
, cu
);
8263 /* If the die has a sibling, skip to the sibling. */
8265 pdi
= pdi
->die_sibling
;
8269 /* Functions used to compute the fully scoped name of a partial DIE.
8271 Normally, this is simple. For C++, the parent DIE's fully scoped
8272 name is concatenated with "::" and the partial DIE's name.
8273 Enumerators are an exception; they use the scope of their parent
8274 enumeration type, i.e. the name of the enumeration type is not
8275 prepended to the enumerator.
8277 There are two complexities. One is DW_AT_specification; in this
8278 case "parent" means the parent of the target of the specification,
8279 instead of the direct parent of the DIE. The other is compilers
8280 which do not emit DW_TAG_namespace; in this case we try to guess
8281 the fully qualified name of structure types from their members'
8282 linkage names. This must be done using the DIE's children rather
8283 than the children of any DW_AT_specification target. We only need
8284 to do this for structures at the top level, i.e. if the target of
8285 any DW_AT_specification (if any; otherwise the DIE itself) does not
8288 /* Compute the scope prefix associated with PDI's parent, in
8289 compilation unit CU. The result will be allocated on CU's
8290 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8291 field. NULL is returned if no prefix is necessary. */
8293 partial_die_parent_scope (struct partial_die_info
*pdi
,
8294 struct dwarf2_cu
*cu
)
8296 const char *grandparent_scope
;
8297 struct partial_die_info
*parent
, *real_pdi
;
8299 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8300 then this means the parent of the specification DIE. */
8303 while (real_pdi
->has_specification
)
8305 auto res
= find_partial_die (real_pdi
->spec_offset
,
8306 real_pdi
->spec_is_dwz
, cu
);
8311 parent
= real_pdi
->die_parent
;
8315 if (parent
->scope_set
)
8316 return parent
->scope
;
8320 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8322 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8323 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8324 Work around this problem here. */
8325 if (cu
->language
== language_cplus
8326 && parent
->tag
== DW_TAG_namespace
8327 && strcmp (parent
->name (cu
), "::") == 0
8328 && grandparent_scope
== NULL
)
8330 parent
->scope
= NULL
;
8331 parent
->scope_set
= 1;
8335 /* Nested subroutines in Fortran get a prefix. */
8336 if (pdi
->tag
== DW_TAG_enumerator
)
8337 /* Enumerators should not get the name of the enumeration as a prefix. */
8338 parent
->scope
= grandparent_scope
;
8339 else if (parent
->tag
== DW_TAG_namespace
8340 || parent
->tag
== DW_TAG_module
8341 || parent
->tag
== DW_TAG_structure_type
8342 || parent
->tag
== DW_TAG_class_type
8343 || parent
->tag
== DW_TAG_interface_type
8344 || parent
->tag
== DW_TAG_union_type
8345 || parent
->tag
== DW_TAG_enumeration_type
8346 || (cu
->language
== language_fortran
8347 && parent
->tag
== DW_TAG_subprogram
8348 && pdi
->tag
== DW_TAG_subprogram
))
8350 if (grandparent_scope
== NULL
)
8351 parent
->scope
= parent
->name (cu
);
8353 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8355 parent
->name (cu
), 0, cu
);
8359 /* FIXME drow/2004-04-01: What should we be doing with
8360 function-local names? For partial symbols, we should probably be
8362 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8363 dwarf_tag_name (parent
->tag
),
8364 sect_offset_str (pdi
->sect_off
));
8365 parent
->scope
= grandparent_scope
;
8368 parent
->scope_set
= 1;
8369 return parent
->scope
;
8372 /* Return the fully scoped name associated with PDI, from compilation unit
8373 CU. The result will be allocated with malloc. */
8375 static gdb::unique_xmalloc_ptr
<char>
8376 partial_die_full_name (struct partial_die_info
*pdi
,
8377 struct dwarf2_cu
*cu
)
8379 const char *parent_scope
;
8381 /* If this is a template instantiation, we can not work out the
8382 template arguments from partial DIEs. So, unfortunately, we have
8383 to go through the full DIEs. At least any work we do building
8384 types here will be reused if full symbols are loaded later. */
8385 if (pdi
->has_template_arguments
)
8389 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8391 struct die_info
*die
;
8392 struct attribute attr
;
8393 struct dwarf2_cu
*ref_cu
= cu
;
8395 /* DW_FORM_ref_addr is using section offset. */
8396 attr
.name
= (enum dwarf_attribute
) 0;
8397 attr
.form
= DW_FORM_ref_addr
;
8398 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8399 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8401 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8405 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8406 if (parent_scope
== NULL
)
8409 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8415 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8417 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
8418 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8419 struct gdbarch
*gdbarch
= objfile
->arch ();
8421 const char *actual_name
= NULL
;
8424 baseaddr
= objfile
->text_section_offset ();
8426 gdb::unique_xmalloc_ptr
<char> built_actual_name
8427 = partial_die_full_name (pdi
, cu
);
8428 if (built_actual_name
!= NULL
)
8429 actual_name
= built_actual_name
.get ();
8431 if (actual_name
== NULL
)
8432 actual_name
= pdi
->name (cu
);
8434 partial_symbol psymbol
;
8435 memset (&psymbol
, 0, sizeof (psymbol
));
8436 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8437 psymbol
.ginfo
.section
= -1;
8439 /* The code below indicates that the psymbol should be installed by
8441 gdb::optional
<psymbol_placement
> where
;
8445 case DW_TAG_inlined_subroutine
:
8446 case DW_TAG_subprogram
:
8447 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8449 if (pdi
->is_external
8450 || cu
->language
== language_ada
8451 || (cu
->language
== language_fortran
8452 && pdi
->die_parent
!= NULL
8453 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8455 /* Normally, only "external" DIEs are part of the global scope.
8456 But in Ada and Fortran, we want to be able to access nested
8457 procedures globally. So all Ada and Fortran subprograms are
8458 stored in the global scope. */
8459 where
= psymbol_placement::GLOBAL
;
8462 where
= psymbol_placement::STATIC
;
8464 psymbol
.domain
= VAR_DOMAIN
;
8465 psymbol
.aclass
= LOC_BLOCK
;
8466 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8467 psymbol
.ginfo
.value
.address
= addr
;
8469 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8470 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8472 case DW_TAG_constant
:
8473 psymbol
.domain
= VAR_DOMAIN
;
8474 psymbol
.aclass
= LOC_STATIC
;
8475 where
= (pdi
->is_external
8476 ? psymbol_placement::GLOBAL
8477 : psymbol_placement::STATIC
);
8479 case DW_TAG_variable
:
8481 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8485 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
8487 /* A global or static variable may also have been stripped
8488 out by the linker if unused, in which case its address
8489 will be nullified; do not add such variables into partial
8490 symbol table then. */
8492 else if (pdi
->is_external
)
8495 Don't enter into the minimal symbol tables as there is
8496 a minimal symbol table entry from the ELF symbols already.
8497 Enter into partial symbol table if it has a location
8498 descriptor or a type.
8499 If the location descriptor is missing, new_symbol will create
8500 a LOC_UNRESOLVED symbol, the address of the variable will then
8501 be determined from the minimal symbol table whenever the variable
8503 The address for the partial symbol table entry is not
8504 used by GDB, but it comes in handy for debugging partial symbol
8507 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8509 psymbol
.domain
= VAR_DOMAIN
;
8510 psymbol
.aclass
= LOC_STATIC
;
8511 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8512 psymbol
.ginfo
.value
.address
= addr
;
8513 where
= psymbol_placement::GLOBAL
;
8518 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8520 /* Static Variable. Skip symbols whose value we cannot know (those
8521 without location descriptors or constant values). */
8522 if (!has_loc
&& !pdi
->has_const_value
)
8525 psymbol
.domain
= VAR_DOMAIN
;
8526 psymbol
.aclass
= LOC_STATIC
;
8527 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8529 psymbol
.ginfo
.value
.address
= addr
;
8530 where
= psymbol_placement::STATIC
;
8533 case DW_TAG_typedef
:
8534 case DW_TAG_base_type
:
8535 case DW_TAG_subrange_type
:
8536 psymbol
.domain
= VAR_DOMAIN
;
8537 psymbol
.aclass
= LOC_TYPEDEF
;
8538 where
= psymbol_placement::STATIC
;
8540 case DW_TAG_imported_declaration
:
8541 case DW_TAG_namespace
:
8542 psymbol
.domain
= VAR_DOMAIN
;
8543 psymbol
.aclass
= LOC_TYPEDEF
;
8544 where
= psymbol_placement::GLOBAL
;
8547 /* With Fortran 77 there might be a "BLOCK DATA" module
8548 available without any name. If so, we skip the module as it
8549 doesn't bring any value. */
8550 if (actual_name
!= nullptr)
8552 psymbol
.domain
= MODULE_DOMAIN
;
8553 psymbol
.aclass
= LOC_TYPEDEF
;
8554 where
= psymbol_placement::GLOBAL
;
8557 case DW_TAG_class_type
:
8558 case DW_TAG_interface_type
:
8559 case DW_TAG_structure_type
:
8560 case DW_TAG_union_type
:
8561 case DW_TAG_enumeration_type
:
8562 /* Skip external references. The DWARF standard says in the section
8563 about "Structure, Union, and Class Type Entries": "An incomplete
8564 structure, union or class type is represented by a structure,
8565 union or class entry that does not have a byte size attribute
8566 and that has a DW_AT_declaration attribute." */
8567 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8570 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8571 static vs. global. */
8572 psymbol
.domain
= STRUCT_DOMAIN
;
8573 psymbol
.aclass
= LOC_TYPEDEF
;
8574 where
= (cu
->language
== language_cplus
8575 ? psymbol_placement::GLOBAL
8576 : psymbol_placement::STATIC
);
8578 case DW_TAG_enumerator
:
8579 psymbol
.domain
= VAR_DOMAIN
;
8580 psymbol
.aclass
= LOC_CONST
;
8581 where
= (cu
->language
== language_cplus
8582 ? psymbol_placement::GLOBAL
8583 : psymbol_placement::STATIC
);
8589 if (where
.has_value ())
8591 if (built_actual_name
!= nullptr)
8592 actual_name
= objfile
->intern (actual_name
);
8593 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8594 psymbol
.ginfo
.set_linkage_name (actual_name
);
8597 psymbol
.ginfo
.set_demangled_name (actual_name
,
8598 &objfile
->objfile_obstack
);
8599 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8601 add_psymbol_to_list (psymbol
, *where
, objfile
);
8605 /* Read a partial die corresponding to a namespace; also, add a symbol
8606 corresponding to that namespace to the symbol table. NAMESPACE is
8607 the name of the enclosing namespace. */
8610 add_partial_namespace (struct partial_die_info
*pdi
,
8611 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8612 int set_addrmap
, struct dwarf2_cu
*cu
)
8614 /* Add a symbol for the namespace. */
8616 add_partial_symbol (pdi
, cu
);
8618 /* Now scan partial symbols in that namespace. */
8620 if (pdi
->has_children
)
8621 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8624 /* Read a partial die corresponding to a Fortran module. */
8627 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8628 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8630 /* Add a symbol for the namespace. */
8632 add_partial_symbol (pdi
, cu
);
8634 /* Now scan partial symbols in that module. */
8636 if (pdi
->has_children
)
8637 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8640 /* Read a partial die corresponding to a subprogram or an inlined
8641 subprogram and create a partial symbol for that subprogram.
8642 When the CU language allows it, this routine also defines a partial
8643 symbol for each nested subprogram that this subprogram contains.
8644 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8645 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8647 PDI may also be a lexical block, in which case we simply search
8648 recursively for subprograms defined inside that lexical block.
8649 Again, this is only performed when the CU language allows this
8650 type of definitions. */
8653 add_partial_subprogram (struct partial_die_info
*pdi
,
8654 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8655 int set_addrmap
, struct dwarf2_cu
*cu
)
8657 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8659 if (pdi
->has_pc_info
)
8661 if (pdi
->lowpc
< *lowpc
)
8662 *lowpc
= pdi
->lowpc
;
8663 if (pdi
->highpc
> *highpc
)
8664 *highpc
= pdi
->highpc
;
8667 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8668 struct gdbarch
*gdbarch
= objfile
->arch ();
8670 CORE_ADDR this_highpc
;
8671 CORE_ADDR this_lowpc
;
8673 baseaddr
= objfile
->text_section_offset ();
8675 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8676 pdi
->lowpc
+ baseaddr
)
8679 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8680 pdi
->highpc
+ baseaddr
)
8682 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8683 this_lowpc
, this_highpc
- 1,
8684 cu
->per_cu
->v
.psymtab
);
8688 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8690 if (!pdi
->is_declaration
)
8691 /* Ignore subprogram DIEs that do not have a name, they are
8692 illegal. Do not emit a complaint at this point, we will
8693 do so when we convert this psymtab into a symtab. */
8695 add_partial_symbol (pdi
, cu
);
8699 if (! pdi
->has_children
)
8702 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8704 pdi
= pdi
->die_child
;
8708 if (pdi
->tag
== DW_TAG_subprogram
8709 || pdi
->tag
== DW_TAG_inlined_subroutine
8710 || pdi
->tag
== DW_TAG_lexical_block
)
8711 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8712 pdi
= pdi
->die_sibling
;
8717 /* Read a partial die corresponding to an enumeration type. */
8720 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8721 struct dwarf2_cu
*cu
)
8723 struct partial_die_info
*pdi
;
8725 if (enum_pdi
->name (cu
) != NULL
)
8726 add_partial_symbol (enum_pdi
, cu
);
8728 pdi
= enum_pdi
->die_child
;
8731 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8732 complaint (_("malformed enumerator DIE ignored"));
8734 add_partial_symbol (pdi
, cu
);
8735 pdi
= pdi
->die_sibling
;
8739 /* Return the initial uleb128 in the die at INFO_PTR. */
8742 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8744 unsigned int bytes_read
;
8746 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8749 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8750 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8752 Return the corresponding abbrev, or NULL if the number is zero (indicating
8753 an empty DIE). In either case *BYTES_READ will be set to the length of
8754 the initial number. */
8756 static struct abbrev_info
*
8757 peek_die_abbrev (const die_reader_specs
&reader
,
8758 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8760 dwarf2_cu
*cu
= reader
.cu
;
8761 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8762 unsigned int abbrev_number
8763 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8765 if (abbrev_number
== 0)
8768 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8771 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8772 " at offset %s [in module %s]"),
8773 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8774 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8780 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8781 Returns a pointer to the end of a series of DIEs, terminated by an empty
8782 DIE. Any children of the skipped DIEs will also be skipped. */
8784 static const gdb_byte
*
8785 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8789 unsigned int bytes_read
;
8790 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8793 return info_ptr
+ bytes_read
;
8795 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8799 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8800 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8801 abbrev corresponding to that skipped uleb128 should be passed in
8802 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8805 static const gdb_byte
*
8806 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8807 struct abbrev_info
*abbrev
)
8809 unsigned int bytes_read
;
8810 struct attribute attr
;
8811 bfd
*abfd
= reader
->abfd
;
8812 struct dwarf2_cu
*cu
= reader
->cu
;
8813 const gdb_byte
*buffer
= reader
->buffer
;
8814 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8815 unsigned int form
, i
;
8817 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8819 /* The only abbrev we care about is DW_AT_sibling. */
8820 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8823 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8825 if (attr
.form
== DW_FORM_ref_addr
)
8826 complaint (_("ignoring absolute DW_AT_sibling"));
8829 sect_offset off
= attr
.get_ref_die_offset ();
8830 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8832 if (sibling_ptr
< info_ptr
)
8833 complaint (_("DW_AT_sibling points backwards"));
8834 else if (sibling_ptr
> reader
->buffer_end
)
8835 reader
->die_section
->overflow_complaint ();
8841 /* If it isn't DW_AT_sibling, skip this attribute. */
8842 form
= abbrev
->attrs
[i
].form
;
8846 case DW_FORM_ref_addr
:
8847 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8848 and later it is offset sized. */
8849 if (cu
->header
.version
== 2)
8850 info_ptr
+= cu
->header
.addr_size
;
8852 info_ptr
+= cu
->header
.offset_size
;
8854 case DW_FORM_GNU_ref_alt
:
8855 info_ptr
+= cu
->header
.offset_size
;
8858 info_ptr
+= cu
->header
.addr_size
;
8866 case DW_FORM_flag_present
:
8867 case DW_FORM_implicit_const
:
8884 case DW_FORM_ref_sig8
:
8887 case DW_FORM_data16
:
8890 case DW_FORM_string
:
8891 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8892 info_ptr
+= bytes_read
;
8894 case DW_FORM_sec_offset
:
8896 case DW_FORM_GNU_strp_alt
:
8897 info_ptr
+= cu
->header
.offset_size
;
8899 case DW_FORM_exprloc
:
8901 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8902 info_ptr
+= bytes_read
;
8904 case DW_FORM_block1
:
8905 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8907 case DW_FORM_block2
:
8908 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8910 case DW_FORM_block4
:
8911 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8917 case DW_FORM_ref_udata
:
8918 case DW_FORM_GNU_addr_index
:
8919 case DW_FORM_GNU_str_index
:
8920 case DW_FORM_rnglistx
:
8921 case DW_FORM_loclistx
:
8922 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8924 case DW_FORM_indirect
:
8925 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8926 info_ptr
+= bytes_read
;
8927 /* We need to continue parsing from here, so just go back to
8929 goto skip_attribute
;
8932 error (_("Dwarf Error: Cannot handle %s "
8933 "in DWARF reader [in module %s]"),
8934 dwarf_form_name (form
),
8935 bfd_get_filename (abfd
));
8939 if (abbrev
->has_children
)
8940 return skip_children (reader
, info_ptr
);
8945 /* Locate ORIG_PDI's sibling.
8946 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8948 static const gdb_byte
*
8949 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8950 struct partial_die_info
*orig_pdi
,
8951 const gdb_byte
*info_ptr
)
8953 /* Do we know the sibling already? */
8955 if (orig_pdi
->sibling
)
8956 return orig_pdi
->sibling
;
8958 /* Are there any children to deal with? */
8960 if (!orig_pdi
->has_children
)
8963 /* Skip the children the long way. */
8965 return skip_children (reader
, info_ptr
);
8968 /* Expand this partial symbol table into a full symbol table. SELF is
8972 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8974 struct dwarf2_per_objfile
*dwarf2_per_objfile
8975 = get_dwarf2_per_objfile (objfile
);
8977 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (per_cu_data
));
8979 /* If this psymtab is constructed from a debug-only objfile, the
8980 has_section_at_zero flag will not necessarily be correct. We
8981 can get the correct value for this flag by looking at the data
8982 associated with the (presumably stripped) associated objfile. */
8983 if (objfile
->separate_debug_objfile_backlink
)
8985 struct dwarf2_per_objfile
*dpo_backlink
8986 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8988 dwarf2_per_objfile
->per_bfd
->has_section_at_zero
8989 = dpo_backlink
->per_bfd
->has_section_at_zero
;
8992 expand_psymtab (objfile
);
8994 process_cu_includes (dwarf2_per_objfile
);
8997 /* Reading in full CUs. */
8999 /* Add PER_CU to the queue. */
9002 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9003 dwarf2_per_objfile
*per_objfile
,
9004 enum language pretend_language
)
9007 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
9010 /* If PER_CU is not yet queued, add it to the queue.
9011 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9013 The result is non-zero if PER_CU was queued, otherwise the result is zero
9014 meaning either PER_CU is already queued or it is already loaded.
9016 N.B. There is an invariant here that if a CU is queued then it is loaded.
9017 The caller is required to load PER_CU if we return non-zero. */
9020 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9021 dwarf2_per_cu_data
*per_cu
,
9022 dwarf2_per_objfile
*per_objfile
,
9023 enum language pretend_language
)
9025 /* We may arrive here during partial symbol reading, if we need full
9026 DIEs to process an unusual case (e.g. template arguments). Do
9027 not queue PER_CU, just tell our caller to load its DIEs. */
9028 if (per_cu
->per_bfd
->reading_partial_symbols
)
9030 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9032 if (cu
== NULL
|| cu
->dies
== NULL
)
9037 /* Mark the dependence relation so that we don't flush PER_CU
9039 if (dependent_cu
!= NULL
)
9040 dwarf2_add_dependence (dependent_cu
, per_cu
);
9042 /* If it's already on the queue, we have nothing to do. */
9046 /* If the compilation unit is already loaded, just mark it as
9048 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9055 /* Add it to the queue. */
9056 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9061 /* Process the queue. */
9064 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9066 if (dwarf_read_debug
)
9068 fprintf_unfiltered (gdb_stdlog
,
9069 "Expanding one or more symtabs of objfile %s ...\n",
9070 objfile_name (dwarf2_per_objfile
->objfile
));
9073 /* The queue starts out with one item, but following a DIE reference
9074 may load a new CU, adding it to the end of the queue. */
9075 while (!dwarf2_per_objfile
->per_bfd
->queue
.empty ())
9077 dwarf2_queue_item
&item
= dwarf2_per_objfile
->per_bfd
->queue
.front ();
9078 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9080 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
9082 dwarf2_cu
*cu
= dwarf2_per_objfile
->get_cu (per_cu
);
9084 /* Skip dummy CUs. */
9087 unsigned int debug_print_threshold
;
9090 if (per_cu
->is_debug_types
)
9092 struct signatured_type
*sig_type
=
9093 (struct signatured_type
*) per_cu
;
9095 sprintf (buf
, "TU %s at offset %s",
9096 hex_string (sig_type
->signature
),
9097 sect_offset_str (per_cu
->sect_off
));
9098 /* There can be 100s of TUs.
9099 Only print them in verbose mode. */
9100 debug_print_threshold
= 2;
9104 sprintf (buf
, "CU at offset %s",
9105 sect_offset_str (per_cu
->sect_off
));
9106 debug_print_threshold
= 1;
9109 if (dwarf_read_debug
>= debug_print_threshold
)
9110 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9112 if (per_cu
->is_debug_types
)
9113 process_full_type_unit (cu
, item
.pretend_language
);
9115 process_full_comp_unit (cu
, item
.pretend_language
);
9117 if (dwarf_read_debug
>= debug_print_threshold
)
9118 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9123 dwarf2_per_objfile
->per_bfd
->queue
.pop ();
9126 if (dwarf_read_debug
)
9128 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9129 objfile_name (dwarf2_per_objfile
->objfile
));
9133 /* Read in full symbols for PST, and anything it depends on. */
9136 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9138 gdb_assert (!readin_p (objfile
));
9140 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9141 free_cached_comp_units
freer (per_objfile
);
9142 expand_dependencies (objfile
);
9144 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9145 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9148 /* See psympriv.h. */
9151 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9153 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9154 return per_objfile
->symtab_set_p (per_cu_data
);
9157 /* See psympriv.h. */
9160 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9162 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9163 return per_objfile
->get_symtab (per_cu_data
);
9166 /* Trivial hash function for die_info: the hash value of a DIE
9167 is its offset in .debug_info for this objfile. */
9170 die_hash (const void *item
)
9172 const struct die_info
*die
= (const struct die_info
*) item
;
9174 return to_underlying (die
->sect_off
);
9177 /* Trivial comparison function for die_info structures: two DIEs
9178 are equal if they have the same offset. */
9181 die_eq (const void *item_lhs
, const void *item_rhs
)
9183 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9184 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9186 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9189 /* Load the DIEs associated with PER_CU into memory. */
9192 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9193 dwarf2_per_objfile
*per_objfile
,
9195 enum language pretend_language
)
9197 gdb_assert (! this_cu
->is_debug_types
);
9199 dwarf2_cu
*existing_cu
= per_objfile
->get_cu (this_cu
);
9200 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9204 struct dwarf2_cu
*cu
= reader
.cu
;
9205 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9207 gdb_assert (cu
->die_hash
== NULL
);
9209 htab_create_alloc_ex (cu
->header
.length
/ 12,
9213 &cu
->comp_unit_obstack
,
9214 hashtab_obstack_allocate
,
9215 dummy_obstack_deallocate
);
9217 if (reader
.comp_unit_die
->has_children
)
9218 reader
.comp_unit_die
->child
9219 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9220 &info_ptr
, reader
.comp_unit_die
);
9221 cu
->dies
= reader
.comp_unit_die
;
9222 /* comp_unit_die is not stored in die_hash, no need. */
9224 /* We try not to read any attributes in this function, because not
9225 all CUs needed for references have been loaded yet, and symbol
9226 table processing isn't initialized. But we have to set the CU language,
9227 or we won't be able to build types correctly.
9228 Similarly, if we do not read the producer, we can not apply
9229 producer-specific interpretation. */
9230 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9235 /* Add a DIE to the delayed physname list. */
9238 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9239 const char *name
, struct die_info
*die
,
9240 struct dwarf2_cu
*cu
)
9242 struct delayed_method_info mi
;
9244 mi
.fnfield_index
= fnfield_index
;
9248 cu
->method_list
.push_back (mi
);
9251 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9252 "const" / "volatile". If so, decrements LEN by the length of the
9253 modifier and return true. Otherwise return false. */
9257 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9259 size_t mod_len
= sizeof (mod
) - 1;
9260 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9268 /* Compute the physnames of any methods on the CU's method list.
9270 The computation of method physnames is delayed in order to avoid the
9271 (bad) condition that one of the method's formal parameters is of an as yet
9275 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9277 /* Only C++ delays computing physnames. */
9278 if (cu
->method_list
.empty ())
9280 gdb_assert (cu
->language
== language_cplus
);
9282 for (const delayed_method_info
&mi
: cu
->method_list
)
9284 const char *physname
;
9285 struct fn_fieldlist
*fn_flp
9286 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9287 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9288 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9289 = physname
? physname
: "";
9291 /* Since there's no tag to indicate whether a method is a
9292 const/volatile overload, extract that information out of the
9294 if (physname
!= NULL
)
9296 size_t len
= strlen (physname
);
9300 if (physname
[len
] == ')') /* shortcut */
9302 else if (check_modifier (physname
, len
, " const"))
9303 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9304 else if (check_modifier (physname
, len
, " volatile"))
9305 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9312 /* The list is no longer needed. */
9313 cu
->method_list
.clear ();
9316 /* Go objects should be embedded in a DW_TAG_module DIE,
9317 and it's not clear if/how imported objects will appear.
9318 To keep Go support simple until that's worked out,
9319 go back through what we've read and create something usable.
9320 We could do this while processing each DIE, and feels kinda cleaner,
9321 but that way is more invasive.
9322 This is to, for example, allow the user to type "p var" or "b main"
9323 without having to specify the package name, and allow lookups
9324 of module.object to work in contexts that use the expression
9328 fixup_go_packaging (struct dwarf2_cu
*cu
)
9330 gdb::unique_xmalloc_ptr
<char> package_name
;
9331 struct pending
*list
;
9334 for (list
= *cu
->get_builder ()->get_global_symbols ();
9338 for (i
= 0; i
< list
->nsyms
; ++i
)
9340 struct symbol
*sym
= list
->symbol
[i
];
9342 if (sym
->language () == language_go
9343 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9345 gdb::unique_xmalloc_ptr
<char> this_package_name
9346 (go_symbol_package_name (sym
));
9348 if (this_package_name
== NULL
)
9350 if (package_name
== NULL
)
9351 package_name
= std::move (this_package_name
);
9354 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9355 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9356 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9357 (symbol_symtab (sym
) != NULL
9358 ? symtab_to_filename_for_display
9359 (symbol_symtab (sym
))
9360 : objfile_name (objfile
)),
9361 this_package_name
.get (), package_name
.get ());
9367 if (package_name
!= NULL
)
9369 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9370 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9371 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9372 saved_package_name
);
9375 sym
= new (&objfile
->objfile_obstack
) symbol
;
9376 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9377 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9378 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9379 e.g., "main" finds the "main" module and not C's main(). */
9380 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9381 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9382 SYMBOL_TYPE (sym
) = type
;
9384 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9388 /* Allocate a fully-qualified name consisting of the two parts on the
9392 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9394 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9397 /* A helper that allocates a variant part to attach to a Rust enum
9398 type. OBSTACK is where the results should be allocated. TYPE is
9399 the type we're processing. DISCRIMINANT_INDEX is the index of the
9400 discriminant. It must be the index of one of the fields of TYPE.
9401 DEFAULT_INDEX is the index of the default field; or -1 if there is
9402 no default. RANGES is indexed by "effective" field number (the
9403 field index, but omitting the discriminant and default fields) and
9404 must hold the discriminant values used by the variants. Note that
9405 RANGES must have a lifetime at least as long as OBSTACK -- either
9406 already allocated on it, or static. */
9409 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9410 int discriminant_index
, int default_index
,
9411 gdb::array_view
<discriminant_range
> ranges
)
9413 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9414 must be handled by the caller. */
9415 gdb_assert (discriminant_index
>= 0
9416 && discriminant_index
< type
->num_fields ());
9417 gdb_assert (default_index
== -1
9418 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9420 /* We have one variant for each non-discriminant field. */
9421 int n_variants
= type
->num_fields () - 1;
9423 variant
*variants
= new (obstack
) variant
[n_variants
];
9426 for (int i
= 0; i
< type
->num_fields (); ++i
)
9428 if (i
== discriminant_index
)
9431 variants
[var_idx
].first_field
= i
;
9432 variants
[var_idx
].last_field
= i
+ 1;
9434 /* The default field does not need a range, but other fields do.
9435 We skipped the discriminant above. */
9436 if (i
!= default_index
)
9438 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9445 gdb_assert (range_idx
== ranges
.size ());
9446 gdb_assert (var_idx
== n_variants
);
9448 variant_part
*part
= new (obstack
) variant_part
;
9449 part
->discriminant_index
= discriminant_index
;
9450 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9451 discriminant_index
));
9452 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9454 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9455 gdb::array_view
<variant_part
> *prop_value
9456 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9458 struct dynamic_prop prop
;
9459 prop
.kind
= PROP_VARIANT_PARTS
;
9460 prop
.data
.variant_parts
= prop_value
;
9462 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9465 /* Some versions of rustc emitted enums in an unusual way.
9467 Ordinary enums were emitted as unions. The first element of each
9468 structure in the union was named "RUST$ENUM$DISR". This element
9469 held the discriminant.
9471 These versions of Rust also implemented the "non-zero"
9472 optimization. When the enum had two values, and one is empty and
9473 the other holds a pointer that cannot be zero, the pointer is used
9474 as the discriminant, with a zero value meaning the empty variant.
9475 Here, the union's first member is of the form
9476 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9477 where the fieldnos are the indices of the fields that should be
9478 traversed in order to find the field (which may be several fields deep)
9479 and the variantname is the name of the variant of the case when the
9482 This function recognizes whether TYPE is of one of these forms,
9483 and, if so, smashes it to be a variant type. */
9486 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9488 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9490 /* We don't need to deal with empty enums. */
9491 if (type
->num_fields () == 0)
9494 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9495 if (type
->num_fields () == 1
9496 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9498 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9500 /* Decode the field name to find the offset of the
9502 ULONGEST bit_offset
= 0;
9503 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9504 while (name
[0] >= '0' && name
[0] <= '9')
9507 unsigned long index
= strtoul (name
, &tail
, 10);
9510 || index
>= field_type
->num_fields ()
9511 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9512 != FIELD_LOC_KIND_BITPOS
))
9514 complaint (_("Could not parse Rust enum encoding string \"%s\""
9516 TYPE_FIELD_NAME (type
, 0),
9517 objfile_name (objfile
));
9522 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9523 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9526 /* Smash this type to be a structure type. We have to do this
9527 because the type has already been recorded. */
9528 type
->set_code (TYPE_CODE_STRUCT
);
9529 type
->set_num_fields (3);
9530 /* Save the field we care about. */
9531 struct field saved_field
= type
->field (0);
9533 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9535 /* Put the discriminant at index 0. */
9536 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9537 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9538 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9539 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9541 /* The order of fields doesn't really matter, so put the real
9542 field at index 1 and the data-less field at index 2. */
9543 type
->field (1) = saved_field
;
9544 TYPE_FIELD_NAME (type
, 1)
9545 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9546 TYPE_FIELD_TYPE (type
, 1)->set_name
9547 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9548 TYPE_FIELD_NAME (type
, 1)));
9550 const char *dataless_name
9551 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9553 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9555 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9556 /* NAME points into the original discriminant name, which
9557 already has the correct lifetime. */
9558 TYPE_FIELD_NAME (type
, 2) = name
;
9559 SET_FIELD_BITPOS (type
->field (2), 0);
9561 /* Indicate that this is a variant type. */
9562 static discriminant_range ranges
[1] = { { 0, 0 } };
9563 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9565 /* A union with a single anonymous field is probably an old-style
9567 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9569 /* Smash this type to be a structure type. We have to do this
9570 because the type has already been recorded. */
9571 type
->set_code (TYPE_CODE_STRUCT
);
9573 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9574 const char *variant_name
9575 = rust_last_path_segment (field_type
->name ());
9576 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9577 field_type
->set_name
9578 (rust_fully_qualify (&objfile
->objfile_obstack
,
9579 type
->name (), variant_name
));
9583 struct type
*disr_type
= nullptr;
9584 for (int i
= 0; i
< type
->num_fields (); ++i
)
9586 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9588 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9590 /* All fields of a true enum will be structs. */
9593 else if (disr_type
->num_fields () == 0)
9595 /* Could be data-less variant, so keep going. */
9596 disr_type
= nullptr;
9598 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9599 "RUST$ENUM$DISR") != 0)
9601 /* Not a Rust enum. */
9611 /* If we got here without a discriminant, then it's probably
9613 if (disr_type
== nullptr)
9616 /* Smash this type to be a structure type. We have to do this
9617 because the type has already been recorded. */
9618 type
->set_code (TYPE_CODE_STRUCT
);
9620 /* Make space for the discriminant field. */
9621 struct field
*disr_field
= &disr_type
->field (0);
9623 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9624 * sizeof (struct field
)));
9625 memcpy (new_fields
+ 1, type
->fields (),
9626 type
->num_fields () * sizeof (struct field
));
9627 type
->set_fields (new_fields
);
9628 type
->set_num_fields (type
->num_fields () + 1);
9630 /* Install the discriminant at index 0 in the union. */
9631 type
->field (0) = *disr_field
;
9632 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9633 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9635 /* We need a way to find the correct discriminant given a
9636 variant name. For convenience we build a map here. */
9637 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9638 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9639 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9641 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9644 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9645 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9649 int n_fields
= type
->num_fields ();
9650 /* We don't need a range entry for the discriminant, but we do
9651 need one for every other field, as there is no default
9653 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9656 /* Skip the discriminant here. */
9657 for (int i
= 1; i
< n_fields
; ++i
)
9659 /* Find the final word in the name of this variant's type.
9660 That name can be used to look up the correct
9662 const char *variant_name
9663 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9665 auto iter
= discriminant_map
.find (variant_name
);
9666 if (iter
!= discriminant_map
.end ())
9668 ranges
[i
].low
= iter
->second
;
9669 ranges
[i
].high
= iter
->second
;
9672 /* Remove the discriminant field, if it exists. */
9673 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9674 if (sub_type
->num_fields () > 0)
9676 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9677 sub_type
->set_fields (sub_type
->fields () + 1);
9679 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9681 (rust_fully_qualify (&objfile
->objfile_obstack
,
9682 type
->name (), variant_name
));
9685 /* Indicate that this is a variant type. */
9686 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9687 gdb::array_view
<discriminant_range
> (ranges
,
9692 /* Rewrite some Rust unions to be structures with variants parts. */
9695 rust_union_quirks (struct dwarf2_cu
*cu
)
9697 gdb_assert (cu
->language
== language_rust
);
9698 for (type
*type_
: cu
->rust_unions
)
9699 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9700 /* We don't need this any more. */
9701 cu
->rust_unions
.clear ();
9706 type_unit_group_unshareable
*
9707 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9709 auto iter
= this->m_type_units
.find (tu_group
);
9710 if (iter
!= this->m_type_units
.end ())
9711 return iter
->second
.get ();
9713 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9714 type_unit_group_unshareable
*result
= uniq
.get ();
9715 this->m_type_units
[tu_group
] = std::move (uniq
);
9720 dwarf2_per_objfile::get_type_for_signatured_type
9721 (signatured_type
*sig_type
) const
9723 auto iter
= this->m_type_map
.find (sig_type
);
9724 if (iter
== this->m_type_map
.end ())
9727 return iter
->second
;
9730 void dwarf2_per_objfile::set_type_for_signatured_type
9731 (signatured_type
*sig_type
, struct type
*type
)
9733 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9735 this->m_type_map
[sig_type
] = type
;
9738 /* A helper function for computing the list of all symbol tables
9739 included by PER_CU. */
9742 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9743 htab_t all_children
, htab_t all_type_symtabs
,
9744 dwarf2_per_cu_data
*per_cu
,
9745 dwarf2_per_objfile
*per_objfile
,
9746 struct compunit_symtab
*immediate_parent
)
9748 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9751 /* This inclusion and its children have been processed. */
9757 /* Only add a CU if it has a symbol table. */
9758 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9761 /* If this is a type unit only add its symbol table if we haven't
9762 seen it yet (type unit per_cu's can share symtabs). */
9763 if (per_cu
->is_debug_types
)
9765 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9769 result
->push_back (cust
);
9770 if (cust
->user
== NULL
)
9771 cust
->user
= immediate_parent
;
9776 result
->push_back (cust
);
9777 if (cust
->user
== NULL
)
9778 cust
->user
= immediate_parent
;
9782 if (!per_cu
->imported_symtabs_empty ())
9783 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9785 recursively_compute_inclusions (result
, all_children
,
9786 all_type_symtabs
, ptr
, per_objfile
,
9791 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9795 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9796 dwarf2_per_objfile
*per_objfile
)
9798 gdb_assert (! per_cu
->is_debug_types
);
9800 if (!per_cu
->imported_symtabs_empty ())
9803 std::vector
<compunit_symtab
*> result_symtabs
;
9804 htab_t all_children
, all_type_symtabs
;
9805 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9807 /* If we don't have a symtab, we can just skip this case. */
9811 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9812 NULL
, xcalloc
, xfree
);
9813 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9814 NULL
, xcalloc
, xfree
);
9816 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9818 recursively_compute_inclusions (&result_symtabs
, all_children
,
9819 all_type_symtabs
, ptr
, per_objfile
,
9823 /* Now we have a transitive closure of all the included symtabs. */
9824 len
= result_symtabs
.size ();
9826 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9827 struct compunit_symtab
*, len
+ 1);
9828 memcpy (cust
->includes
, result_symtabs
.data (),
9829 len
* sizeof (compunit_symtab
*));
9830 cust
->includes
[len
] = NULL
;
9832 htab_delete (all_children
);
9833 htab_delete (all_type_symtabs
);
9837 /* Compute the 'includes' field for the symtabs of all the CUs we just
9841 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9843 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->per_bfd
->just_read_cus
)
9845 if (! iter
->is_debug_types
)
9846 compute_compunit_symtab_includes (iter
, dwarf2_per_objfile
);
9849 dwarf2_per_objfile
->per_bfd
->just_read_cus
.clear ();
9852 /* Generate full symbol information for CU, whose DIEs have
9853 already been loaded into memory. */
9856 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9858 dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
9859 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9860 struct gdbarch
*gdbarch
= objfile
->arch ();
9861 CORE_ADDR lowpc
, highpc
;
9862 struct compunit_symtab
*cust
;
9864 struct block
*static_block
;
9867 baseaddr
= objfile
->text_section_offset ();
9869 /* Clear the list here in case something was left over. */
9870 cu
->method_list
.clear ();
9872 cu
->language
= pretend_language
;
9873 cu
->language_defn
= language_def (cu
->language
);
9875 /* Do line number decoding in read_file_scope () */
9876 process_die (cu
->dies
, cu
);
9878 /* For now fudge the Go package. */
9879 if (cu
->language
== language_go
)
9880 fixup_go_packaging (cu
);
9882 /* Now that we have processed all the DIEs in the CU, all the types
9883 should be complete, and it should now be safe to compute all of the
9885 compute_delayed_physnames (cu
);
9887 if (cu
->language
== language_rust
)
9888 rust_union_quirks (cu
);
9890 /* Some compilers don't define a DW_AT_high_pc attribute for the
9891 compilation unit. If the DW_AT_high_pc is missing, synthesize
9892 it, by scanning the DIE's below the compilation unit. */
9893 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9895 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9896 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9898 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9899 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9900 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9901 addrmap to help ensure it has an accurate map of pc values belonging to
9903 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9905 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9906 SECT_OFF_TEXT (objfile
),
9911 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9913 /* Set symtab language to language from DW_AT_language. If the
9914 compilation is from a C file generated by language preprocessors, do
9915 not set the language if it was already deduced by start_subfile. */
9916 if (!(cu
->language
== language_c
9917 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9918 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9920 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9921 produce DW_AT_location with location lists but it can be possibly
9922 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9923 there were bugs in prologue debug info, fixed later in GCC-4.5
9924 by "unwind info for epilogues" patch (which is not directly related).
9926 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9927 needed, it would be wrong due to missing DW_AT_producer there.
9929 Still one can confuse GDB by using non-standard GCC compilation
9930 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9932 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9933 cust
->locations_valid
= 1;
9935 if (gcc_4_minor
>= 5)
9936 cust
->epilogue_unwind_valid
= 1;
9938 cust
->call_site_htab
= cu
->call_site_htab
;
9941 dwarf2_per_objfile
->set_symtab (cu
->per_cu
, cust
);
9943 /* Push it for inclusion processing later. */
9944 dwarf2_per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9946 /* Not needed any more. */
9947 cu
->reset_builder ();
9950 /* Generate full symbol information for type unit CU, whose DIEs have
9951 already been loaded into memory. */
9954 process_full_type_unit (dwarf2_cu
*cu
,
9955 enum language pretend_language
)
9957 dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
9958 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9959 struct compunit_symtab
*cust
;
9960 struct signatured_type
*sig_type
;
9962 gdb_assert (cu
->per_cu
->is_debug_types
);
9963 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9965 /* Clear the list here in case something was left over. */
9966 cu
->method_list
.clear ();
9968 cu
->language
= pretend_language
;
9969 cu
->language_defn
= language_def (cu
->language
);
9971 /* The symbol tables are set up in read_type_unit_scope. */
9972 process_die (cu
->dies
, cu
);
9974 /* For now fudge the Go package. */
9975 if (cu
->language
== language_go
)
9976 fixup_go_packaging (cu
);
9978 /* Now that we have processed all the DIEs in the CU, all the types
9979 should be complete, and it should now be safe to compute all of the
9981 compute_delayed_physnames (cu
);
9983 if (cu
->language
== language_rust
)
9984 rust_union_quirks (cu
);
9986 /* TUs share symbol tables.
9987 If this is the first TU to use this symtab, complete the construction
9988 of it with end_expandable_symtab. Otherwise, complete the addition of
9989 this TU's symbols to the existing symtab. */
9990 type_unit_group_unshareable
*tug_unshare
=
9991 dwarf2_per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9992 if (tug_unshare
->compunit_symtab
== NULL
)
9994 buildsym_compunit
*builder
= cu
->get_builder ();
9995 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9996 tug_unshare
->compunit_symtab
= cust
;
10000 /* Set symtab language to language from DW_AT_language. If the
10001 compilation is from a C file generated by language preprocessors,
10002 do not set the language if it was already deduced by
10004 if (!(cu
->language
== language_c
10005 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10006 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10011 cu
->get_builder ()->augment_type_symtab ();
10012 cust
= tug_unshare
->compunit_symtab
;
10015 dwarf2_per_objfile
->set_symtab (cu
->per_cu
, cust
);
10017 /* Not needed any more. */
10018 cu
->reset_builder ();
10021 /* Process an imported unit DIE. */
10024 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10026 struct attribute
*attr
;
10028 /* For now we don't handle imported units in type units. */
10029 if (cu
->per_cu
->is_debug_types
)
10031 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10032 " supported in type units [in module %s]"),
10033 objfile_name (cu
->per_objfile
->objfile
));
10036 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10039 sect_offset sect_off
= attr
->get_ref_die_offset ();
10040 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10041 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10042 dwarf2_per_cu_data
*per_cu
10043 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10045 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10046 into another compilation unit, at root level. Regard this as a hint,
10048 if (die
->parent
&& die
->parent
->parent
== NULL
10049 && per_cu
->unit_type
== DW_UT_compile
10050 && per_cu
->lang
== language_cplus
)
10053 /* If necessary, add it to the queue and load its DIEs. */
10054 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10055 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
10057 cu
->per_cu
->imported_symtabs_push (per_cu
);
10061 /* RAII object that represents a process_die scope: i.e.,
10062 starts/finishes processing a DIE. */
10063 class process_die_scope
10066 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10067 : m_die (die
), m_cu (cu
)
10069 /* We should only be processing DIEs not already in process. */
10070 gdb_assert (!m_die
->in_process
);
10071 m_die
->in_process
= true;
10074 ~process_die_scope ()
10076 m_die
->in_process
= false;
10078 /* If we're done processing the DIE for the CU that owns the line
10079 header, we don't need the line header anymore. */
10080 if (m_cu
->line_header_die_owner
== m_die
)
10082 delete m_cu
->line_header
;
10083 m_cu
->line_header
= NULL
;
10084 m_cu
->line_header_die_owner
= NULL
;
10093 /* Process a die and its children. */
10096 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10098 process_die_scope
scope (die
, cu
);
10102 case DW_TAG_padding
:
10104 case DW_TAG_compile_unit
:
10105 case DW_TAG_partial_unit
:
10106 read_file_scope (die
, cu
);
10108 case DW_TAG_type_unit
:
10109 read_type_unit_scope (die
, cu
);
10111 case DW_TAG_subprogram
:
10112 /* Nested subprograms in Fortran get a prefix. */
10113 if (cu
->language
== language_fortran
10114 && die
->parent
!= NULL
10115 && die
->parent
->tag
== DW_TAG_subprogram
)
10116 cu
->processing_has_namespace_info
= true;
10117 /* Fall through. */
10118 case DW_TAG_inlined_subroutine
:
10119 read_func_scope (die
, cu
);
10121 case DW_TAG_lexical_block
:
10122 case DW_TAG_try_block
:
10123 case DW_TAG_catch_block
:
10124 read_lexical_block_scope (die
, cu
);
10126 case DW_TAG_call_site
:
10127 case DW_TAG_GNU_call_site
:
10128 read_call_site_scope (die
, cu
);
10130 case DW_TAG_class_type
:
10131 case DW_TAG_interface_type
:
10132 case DW_TAG_structure_type
:
10133 case DW_TAG_union_type
:
10134 process_structure_scope (die
, cu
);
10136 case DW_TAG_enumeration_type
:
10137 process_enumeration_scope (die
, cu
);
10140 /* These dies have a type, but processing them does not create
10141 a symbol or recurse to process the children. Therefore we can
10142 read them on-demand through read_type_die. */
10143 case DW_TAG_subroutine_type
:
10144 case DW_TAG_set_type
:
10145 case DW_TAG_array_type
:
10146 case DW_TAG_pointer_type
:
10147 case DW_TAG_ptr_to_member_type
:
10148 case DW_TAG_reference_type
:
10149 case DW_TAG_rvalue_reference_type
:
10150 case DW_TAG_string_type
:
10153 case DW_TAG_base_type
:
10154 case DW_TAG_subrange_type
:
10155 case DW_TAG_typedef
:
10156 /* Add a typedef symbol for the type definition, if it has a
10158 new_symbol (die
, read_type_die (die
, cu
), cu
);
10160 case DW_TAG_common_block
:
10161 read_common_block (die
, cu
);
10163 case DW_TAG_common_inclusion
:
10165 case DW_TAG_namespace
:
10166 cu
->processing_has_namespace_info
= true;
10167 read_namespace (die
, cu
);
10169 case DW_TAG_module
:
10170 cu
->processing_has_namespace_info
= true;
10171 read_module (die
, cu
);
10173 case DW_TAG_imported_declaration
:
10174 cu
->processing_has_namespace_info
= true;
10175 if (read_namespace_alias (die
, cu
))
10177 /* The declaration is not a global namespace alias. */
10178 /* Fall through. */
10179 case DW_TAG_imported_module
:
10180 cu
->processing_has_namespace_info
= true;
10181 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10182 || cu
->language
!= language_fortran
))
10183 complaint (_("Tag '%s' has unexpected children"),
10184 dwarf_tag_name (die
->tag
));
10185 read_import_statement (die
, cu
);
10188 case DW_TAG_imported_unit
:
10189 process_imported_unit_die (die
, cu
);
10192 case DW_TAG_variable
:
10193 read_variable (die
, cu
);
10197 new_symbol (die
, NULL
, cu
);
10202 /* DWARF name computation. */
10204 /* A helper function for dwarf2_compute_name which determines whether DIE
10205 needs to have the name of the scope prepended to the name listed in the
10209 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10211 struct attribute
*attr
;
10215 case DW_TAG_namespace
:
10216 case DW_TAG_typedef
:
10217 case DW_TAG_class_type
:
10218 case DW_TAG_interface_type
:
10219 case DW_TAG_structure_type
:
10220 case DW_TAG_union_type
:
10221 case DW_TAG_enumeration_type
:
10222 case DW_TAG_enumerator
:
10223 case DW_TAG_subprogram
:
10224 case DW_TAG_inlined_subroutine
:
10225 case DW_TAG_member
:
10226 case DW_TAG_imported_declaration
:
10229 case DW_TAG_variable
:
10230 case DW_TAG_constant
:
10231 /* We only need to prefix "globally" visible variables. These include
10232 any variable marked with DW_AT_external or any variable that
10233 lives in a namespace. [Variables in anonymous namespaces
10234 require prefixing, but they are not DW_AT_external.] */
10236 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10238 struct dwarf2_cu
*spec_cu
= cu
;
10240 return die_needs_namespace (die_specification (die
, &spec_cu
),
10244 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10245 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10246 && die
->parent
->tag
!= DW_TAG_module
)
10248 /* A variable in a lexical block of some kind does not need a
10249 namespace, even though in C++ such variables may be external
10250 and have a mangled name. */
10251 if (die
->parent
->tag
== DW_TAG_lexical_block
10252 || die
->parent
->tag
== DW_TAG_try_block
10253 || die
->parent
->tag
== DW_TAG_catch_block
10254 || die
->parent
->tag
== DW_TAG_subprogram
)
10263 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10264 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10265 defined for the given DIE. */
10267 static struct attribute
*
10268 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10270 struct attribute
*attr
;
10272 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10274 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10279 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10280 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10281 defined for the given DIE. */
10283 static const char *
10284 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10286 const char *linkage_name
;
10288 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10289 if (linkage_name
== NULL
)
10290 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10292 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10293 See https://github.com/rust-lang/rust/issues/32925. */
10294 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10295 && strchr (linkage_name
, '{') != NULL
)
10296 linkage_name
= NULL
;
10298 return linkage_name
;
10301 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10302 compute the physname for the object, which include a method's:
10303 - formal parameters (C++),
10304 - receiver type (Go),
10306 The term "physname" is a bit confusing.
10307 For C++, for example, it is the demangled name.
10308 For Go, for example, it's the mangled name.
10310 For Ada, return the DIE's linkage name rather than the fully qualified
10311 name. PHYSNAME is ignored..
10313 The result is allocated on the objfile->per_bfd's obstack and
10316 static const char *
10317 dwarf2_compute_name (const char *name
,
10318 struct die_info
*die
, struct dwarf2_cu
*cu
,
10321 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10324 name
= dwarf2_name (die
, cu
);
10326 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10327 but otherwise compute it by typename_concat inside GDB.
10328 FIXME: Actually this is not really true, or at least not always true.
10329 It's all very confusing. compute_and_set_names doesn't try to demangle
10330 Fortran names because there is no mangling standard. So new_symbol
10331 will set the demangled name to the result of dwarf2_full_name, and it is
10332 the demangled name that GDB uses if it exists. */
10333 if (cu
->language
== language_ada
10334 || (cu
->language
== language_fortran
&& physname
))
10336 /* For Ada unit, we prefer the linkage name over the name, as
10337 the former contains the exported name, which the user expects
10338 to be able to reference. Ideally, we want the user to be able
10339 to reference this entity using either natural or linkage name,
10340 but we haven't started looking at this enhancement yet. */
10341 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10343 if (linkage_name
!= NULL
)
10344 return linkage_name
;
10347 /* These are the only languages we know how to qualify names in. */
10349 && (cu
->language
== language_cplus
10350 || cu
->language
== language_fortran
|| cu
->language
== language_d
10351 || cu
->language
== language_rust
))
10353 if (die_needs_namespace (die
, cu
))
10355 const char *prefix
;
10356 const char *canonical_name
= NULL
;
10360 prefix
= determine_prefix (die
, cu
);
10361 if (*prefix
!= '\0')
10363 gdb::unique_xmalloc_ptr
<char> prefixed_name
10364 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10366 buf
.puts (prefixed_name
.get ());
10371 /* Template parameters may be specified in the DIE's DW_AT_name, or
10372 as children with DW_TAG_template_type_param or
10373 DW_TAG_value_type_param. If the latter, add them to the name
10374 here. If the name already has template parameters, then
10375 skip this step; some versions of GCC emit both, and
10376 it is more efficient to use the pre-computed name.
10378 Something to keep in mind about this process: it is very
10379 unlikely, or in some cases downright impossible, to produce
10380 something that will match the mangled name of a function.
10381 If the definition of the function has the same debug info,
10382 we should be able to match up with it anyway. But fallbacks
10383 using the minimal symbol, for instance to find a method
10384 implemented in a stripped copy of libstdc++, will not work.
10385 If we do not have debug info for the definition, we will have to
10386 match them up some other way.
10388 When we do name matching there is a related problem with function
10389 templates; two instantiated function templates are allowed to
10390 differ only by their return types, which we do not add here. */
10392 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10394 struct attribute
*attr
;
10395 struct die_info
*child
;
10398 die
->building_fullname
= 1;
10400 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10404 const gdb_byte
*bytes
;
10405 struct dwarf2_locexpr_baton
*baton
;
10408 if (child
->tag
!= DW_TAG_template_type_param
10409 && child
->tag
!= DW_TAG_template_value_param
)
10420 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10423 complaint (_("template parameter missing DW_AT_type"));
10424 buf
.puts ("UNKNOWN_TYPE");
10427 type
= die_type (child
, cu
);
10429 if (child
->tag
== DW_TAG_template_type_param
)
10431 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10432 &type_print_raw_options
);
10436 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10439 complaint (_("template parameter missing "
10440 "DW_AT_const_value"));
10441 buf
.puts ("UNKNOWN_VALUE");
10445 dwarf2_const_value_attr (attr
, type
, name
,
10446 &cu
->comp_unit_obstack
, cu
,
10447 &value
, &bytes
, &baton
);
10449 if (TYPE_NOSIGN (type
))
10450 /* GDB prints characters as NUMBER 'CHAR'. If that's
10451 changed, this can use value_print instead. */
10452 c_printchar (value
, type
, &buf
);
10455 struct value_print_options opts
;
10458 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10462 baton
->per_objfile
);
10463 else if (bytes
!= NULL
)
10465 v
= allocate_value (type
);
10466 memcpy (value_contents_writeable (v
), bytes
,
10467 TYPE_LENGTH (type
));
10470 v
= value_from_longest (type
, value
);
10472 /* Specify decimal so that we do not depend on
10474 get_formatted_print_options (&opts
, 'd');
10476 value_print (v
, &buf
, &opts
);
10481 die
->building_fullname
= 0;
10485 /* Close the argument list, with a space if necessary
10486 (nested templates). */
10487 if (!buf
.empty () && buf
.string ().back () == '>')
10494 /* For C++ methods, append formal parameter type
10495 information, if PHYSNAME. */
10497 if (physname
&& die
->tag
== DW_TAG_subprogram
10498 && cu
->language
== language_cplus
)
10500 struct type
*type
= read_type_die (die
, cu
);
10502 c_type_print_args (type
, &buf
, 1, cu
->language
,
10503 &type_print_raw_options
);
10505 if (cu
->language
== language_cplus
)
10507 /* Assume that an artificial first parameter is
10508 "this", but do not crash if it is not. RealView
10509 marks unnamed (and thus unused) parameters as
10510 artificial; there is no way to differentiate
10512 if (type
->num_fields () > 0
10513 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10514 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10515 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10517 buf
.puts (" const");
10521 const std::string
&intermediate_name
= buf
.string ();
10523 if (cu
->language
== language_cplus
)
10525 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10528 /* If we only computed INTERMEDIATE_NAME, or if
10529 INTERMEDIATE_NAME is already canonical, then we need to
10531 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10532 name
= objfile
->intern (intermediate_name
);
10534 name
= canonical_name
;
10541 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10542 If scope qualifiers are appropriate they will be added. The result
10543 will be allocated on the storage_obstack, or NULL if the DIE does
10544 not have a name. NAME may either be from a previous call to
10545 dwarf2_name or NULL.
10547 The output string will be canonicalized (if C++). */
10549 static const char *
10550 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10552 return dwarf2_compute_name (name
, die
, cu
, 0);
10555 /* Construct a physname for the given DIE in CU. NAME may either be
10556 from a previous call to dwarf2_name or NULL. The result will be
10557 allocated on the objfile_objstack or NULL if the DIE does not have a
10560 The output string will be canonicalized (if C++). */
10562 static const char *
10563 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10565 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10566 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10569 /* In this case dwarf2_compute_name is just a shortcut not building anything
10571 if (!die_needs_namespace (die
, cu
))
10572 return dwarf2_compute_name (name
, die
, cu
, 1);
10574 if (cu
->language
!= language_rust
)
10575 mangled
= dw2_linkage_name (die
, cu
);
10577 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10579 gdb::unique_xmalloc_ptr
<char> demangled
;
10580 if (mangled
!= NULL
)
10583 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10585 /* Do nothing (do not demangle the symbol name). */
10587 else if (cu
->language
== language_go
)
10589 /* This is a lie, but we already lie to the caller new_symbol.
10590 new_symbol assumes we return the mangled name.
10591 This just undoes that lie until things are cleaned up. */
10595 /* Use DMGL_RET_DROP for C++ template functions to suppress
10596 their return type. It is easier for GDB users to search
10597 for such functions as `name(params)' than `long name(params)'.
10598 In such case the minimal symbol names do not match the full
10599 symbol names but for template functions there is never a need
10600 to look up their definition from their declaration so
10601 the only disadvantage remains the minimal symbol variant
10602 `long name(params)' does not have the proper inferior type. */
10603 demangled
.reset (gdb_demangle (mangled
,
10604 (DMGL_PARAMS
| DMGL_ANSI
10605 | DMGL_RET_DROP
)));
10608 canon
= demangled
.get ();
10616 if (canon
== NULL
|| check_physname
)
10618 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10620 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10622 /* It may not mean a bug in GDB. The compiler could also
10623 compute DW_AT_linkage_name incorrectly. But in such case
10624 GDB would need to be bug-to-bug compatible. */
10626 complaint (_("Computed physname <%s> does not match demangled <%s> "
10627 "(from linkage <%s>) - DIE at %s [in module %s]"),
10628 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10629 objfile_name (objfile
));
10631 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10632 is available here - over computed PHYSNAME. It is safer
10633 against both buggy GDB and buggy compilers. */
10647 retval
= objfile
->intern (retval
);
10652 /* Inspect DIE in CU for a namespace alias. If one exists, record
10653 a new symbol for it.
10655 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10658 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10660 struct attribute
*attr
;
10662 /* If the die does not have a name, this is not a namespace
10664 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10668 struct die_info
*d
= die
;
10669 struct dwarf2_cu
*imported_cu
= cu
;
10671 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10672 keep inspecting DIEs until we hit the underlying import. */
10673 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10674 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10676 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10680 d
= follow_die_ref (d
, attr
, &imported_cu
);
10681 if (d
->tag
!= DW_TAG_imported_declaration
)
10685 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10687 complaint (_("DIE at %s has too many recursively imported "
10688 "declarations"), sect_offset_str (d
->sect_off
));
10695 sect_offset sect_off
= attr
->get_ref_die_offset ();
10697 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10698 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10700 /* This declaration is a global namespace alias. Add
10701 a symbol for it whose type is the aliased namespace. */
10702 new_symbol (die
, type
, cu
);
10711 /* Return the using directives repository (global or local?) to use in the
10712 current context for CU.
10714 For Ada, imported declarations can materialize renamings, which *may* be
10715 global. However it is impossible (for now?) in DWARF to distinguish
10716 "external" imported declarations and "static" ones. As all imported
10717 declarations seem to be static in all other languages, make them all CU-wide
10718 global only in Ada. */
10720 static struct using_direct
**
10721 using_directives (struct dwarf2_cu
*cu
)
10723 if (cu
->language
== language_ada
10724 && cu
->get_builder ()->outermost_context_p ())
10725 return cu
->get_builder ()->get_global_using_directives ();
10727 return cu
->get_builder ()->get_local_using_directives ();
10730 /* Read the import statement specified by the given die and record it. */
10733 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10735 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10736 struct attribute
*import_attr
;
10737 struct die_info
*imported_die
, *child_die
;
10738 struct dwarf2_cu
*imported_cu
;
10739 const char *imported_name
;
10740 const char *imported_name_prefix
;
10741 const char *canonical_name
;
10742 const char *import_alias
;
10743 const char *imported_declaration
= NULL
;
10744 const char *import_prefix
;
10745 std::vector
<const char *> excludes
;
10747 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10748 if (import_attr
== NULL
)
10750 complaint (_("Tag '%s' has no DW_AT_import"),
10751 dwarf_tag_name (die
->tag
));
10756 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10757 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10758 if (imported_name
== NULL
)
10760 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10762 The import in the following code:
10776 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10777 <52> DW_AT_decl_file : 1
10778 <53> DW_AT_decl_line : 6
10779 <54> DW_AT_import : <0x75>
10780 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10781 <59> DW_AT_name : B
10782 <5b> DW_AT_decl_file : 1
10783 <5c> DW_AT_decl_line : 2
10784 <5d> DW_AT_type : <0x6e>
10786 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10787 <76> DW_AT_byte_size : 4
10788 <77> DW_AT_encoding : 5 (signed)
10790 imports the wrong die ( 0x75 instead of 0x58 ).
10791 This case will be ignored until the gcc bug is fixed. */
10795 /* Figure out the local name after import. */
10796 import_alias
= dwarf2_name (die
, cu
);
10798 /* Figure out where the statement is being imported to. */
10799 import_prefix
= determine_prefix (die
, cu
);
10801 /* Figure out what the scope of the imported die is and prepend it
10802 to the name of the imported die. */
10803 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10805 if (imported_die
->tag
!= DW_TAG_namespace
10806 && imported_die
->tag
!= DW_TAG_module
)
10808 imported_declaration
= imported_name
;
10809 canonical_name
= imported_name_prefix
;
10811 else if (strlen (imported_name_prefix
) > 0)
10812 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10813 imported_name_prefix
,
10814 (cu
->language
== language_d
? "." : "::"),
10815 imported_name
, (char *) NULL
);
10817 canonical_name
= imported_name
;
10819 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10820 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10821 child_die
= child_die
->sibling
)
10823 /* DWARF-4: A Fortran use statement with a “rename list” may be
10824 represented by an imported module entry with an import attribute
10825 referring to the module and owned entries corresponding to those
10826 entities that are renamed as part of being imported. */
10828 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10830 complaint (_("child DW_TAG_imported_declaration expected "
10831 "- DIE at %s [in module %s]"),
10832 sect_offset_str (child_die
->sect_off
),
10833 objfile_name (objfile
));
10837 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10838 if (import_attr
== NULL
)
10840 complaint (_("Tag '%s' has no DW_AT_import"),
10841 dwarf_tag_name (child_die
->tag
));
10846 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10848 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10849 if (imported_name
== NULL
)
10851 complaint (_("child DW_TAG_imported_declaration has unknown "
10852 "imported name - DIE at %s [in module %s]"),
10853 sect_offset_str (child_die
->sect_off
),
10854 objfile_name (objfile
));
10858 excludes
.push_back (imported_name
);
10860 process_die (child_die
, cu
);
10863 add_using_directive (using_directives (cu
),
10867 imported_declaration
,
10870 &objfile
->objfile_obstack
);
10873 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10874 types, but gives them a size of zero. Starting with version 14,
10875 ICC is compatible with GCC. */
10878 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10880 if (!cu
->checked_producer
)
10881 check_producer (cu
);
10883 return cu
->producer_is_icc_lt_14
;
10886 /* ICC generates a DW_AT_type for C void functions. This was observed on
10887 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10888 which says that void functions should not have a DW_AT_type. */
10891 producer_is_icc (struct dwarf2_cu
*cu
)
10893 if (!cu
->checked_producer
)
10894 check_producer (cu
);
10896 return cu
->producer_is_icc
;
10899 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10900 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10901 this, it was first present in GCC release 4.3.0. */
10904 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10906 if (!cu
->checked_producer
)
10907 check_producer (cu
);
10909 return cu
->producer_is_gcc_lt_4_3
;
10912 static file_and_directory
10913 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10915 file_and_directory res
;
10917 /* Find the filename. Do not use dwarf2_name here, since the filename
10918 is not a source language identifier. */
10919 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10920 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10922 if (res
.comp_dir
== NULL
10923 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10924 && IS_ABSOLUTE_PATH (res
.name
))
10926 res
.comp_dir_storage
= ldirname (res
.name
);
10927 if (!res
.comp_dir_storage
.empty ())
10928 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10930 if (res
.comp_dir
!= NULL
)
10932 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10933 directory, get rid of it. */
10934 const char *cp
= strchr (res
.comp_dir
, ':');
10936 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10937 res
.comp_dir
= cp
+ 1;
10940 if (res
.name
== NULL
)
10941 res
.name
= "<unknown>";
10946 /* Handle DW_AT_stmt_list for a compilation unit.
10947 DIE is the DW_TAG_compile_unit die for CU.
10948 COMP_DIR is the compilation directory. LOWPC is passed to
10949 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10952 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10953 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10955 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10956 struct attribute
*attr
;
10957 struct line_header line_header_local
;
10958 hashval_t line_header_local_hash
;
10960 int decode_mapping
;
10962 gdb_assert (! cu
->per_cu
->is_debug_types
);
10964 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10968 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10970 /* The line header hash table is only created if needed (it exists to
10971 prevent redundant reading of the line table for partial_units).
10972 If we're given a partial_unit, we'll need it. If we're given a
10973 compile_unit, then use the line header hash table if it's already
10974 created, but don't create one just yet. */
10976 if (dwarf2_per_objfile
->line_header_hash
== NULL
10977 && die
->tag
== DW_TAG_partial_unit
)
10979 dwarf2_per_objfile
->line_header_hash
10980 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10981 line_header_eq_voidp
,
10982 free_line_header_voidp
,
10986 line_header_local
.sect_off
= line_offset
;
10987 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10988 line_header_local_hash
= line_header_hash (&line_header_local
);
10989 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10991 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10992 &line_header_local
,
10993 line_header_local_hash
, NO_INSERT
);
10995 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10996 is not present in *SLOT (since if there is something in *SLOT then
10997 it will be for a partial_unit). */
10998 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11000 gdb_assert (*slot
!= NULL
);
11001 cu
->line_header
= (struct line_header
*) *slot
;
11006 /* dwarf_decode_line_header does not yet provide sufficient information.
11007 We always have to call also dwarf_decode_lines for it. */
11008 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11012 cu
->line_header
= lh
.release ();
11013 cu
->line_header_die_owner
= die
;
11015 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11019 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
11020 &line_header_local
,
11021 line_header_local_hash
, INSERT
);
11022 gdb_assert (slot
!= NULL
);
11024 if (slot
!= NULL
&& *slot
== NULL
)
11026 /* This newly decoded line number information unit will be owned
11027 by line_header_hash hash table. */
11028 *slot
= cu
->line_header
;
11029 cu
->line_header_die_owner
= NULL
;
11033 /* We cannot free any current entry in (*slot) as that struct line_header
11034 may be already used by multiple CUs. Create only temporary decoded
11035 line_header for this CU - it may happen at most once for each line
11036 number information unit. And if we're not using line_header_hash
11037 then this is what we want as well. */
11038 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11040 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11041 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11046 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11049 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11051 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
11052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11053 struct gdbarch
*gdbarch
= objfile
->arch ();
11054 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11055 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11056 struct attribute
*attr
;
11057 struct die_info
*child_die
;
11058 CORE_ADDR baseaddr
;
11060 prepare_one_comp_unit (cu
, die
, cu
->language
);
11061 baseaddr
= objfile
->text_section_offset ();
11063 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11065 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11066 from finish_block. */
11067 if (lowpc
== ((CORE_ADDR
) -1))
11069 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11071 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11073 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11074 standardised yet. As a workaround for the language detection we fall
11075 back to the DW_AT_producer string. */
11076 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11077 cu
->language
= language_opencl
;
11079 /* Similar hack for Go. */
11080 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11081 set_cu_language (DW_LANG_Go
, cu
);
11083 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11085 /* Decode line number information if present. We do this before
11086 processing child DIEs, so that the line header table is available
11087 for DW_AT_decl_file. */
11088 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11090 /* Process all dies in compilation unit. */
11091 if (die
->child
!= NULL
)
11093 child_die
= die
->child
;
11094 while (child_die
&& child_die
->tag
)
11096 process_die (child_die
, cu
);
11097 child_die
= child_die
->sibling
;
11101 /* Decode macro information, if present. Dwarf 2 macro information
11102 refers to information in the line number info statement program
11103 header, so we can only read it if we've read the header
11105 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11107 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11108 if (attr
&& cu
->line_header
)
11110 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11111 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11113 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11117 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11118 if (attr
&& cu
->line_header
)
11120 unsigned int macro_offset
= DW_UNSND (attr
);
11122 dwarf_decode_macros (cu
, macro_offset
, 0);
11128 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11130 struct type_unit_group
*tu_group
;
11132 struct attribute
*attr
;
11134 struct signatured_type
*sig_type
;
11136 gdb_assert (per_cu
->is_debug_types
);
11137 sig_type
= (struct signatured_type
*) per_cu
;
11139 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11141 /* If we're using .gdb_index (includes -readnow) then
11142 per_cu->type_unit_group may not have been set up yet. */
11143 if (sig_type
->type_unit_group
== NULL
)
11144 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11145 tu_group
= sig_type
->type_unit_group
;
11147 /* If we've already processed this stmt_list there's no real need to
11148 do it again, we could fake it and just recreate the part we need
11149 (file name,index -> symtab mapping). If data shows this optimization
11150 is useful we can do it then. */
11151 type_unit_group_unshareable
*tug_unshare
11152 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11153 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11155 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11160 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11161 lh
= dwarf_decode_line_header (line_offset
, this);
11166 start_symtab ("", NULL
, 0);
11169 gdb_assert (tug_unshare
->symtabs
== NULL
);
11170 gdb_assert (m_builder
== nullptr);
11171 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11172 m_builder
.reset (new struct buildsym_compunit
11173 (COMPUNIT_OBJFILE (cust
), "",
11174 COMPUNIT_DIRNAME (cust
),
11175 compunit_language (cust
),
11177 list_in_scope
= get_builder ()->get_file_symbols ();
11182 line_header
= lh
.release ();
11183 line_header_die_owner
= die
;
11187 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11189 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11190 still initializing it, and our caller (a few levels up)
11191 process_full_type_unit still needs to know if this is the first
11194 tug_unshare
->symtabs
11195 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11196 struct symtab
*, line_header
->file_names_size ());
11198 auto &file_names
= line_header
->file_names ();
11199 for (i
= 0; i
< file_names
.size (); ++i
)
11201 file_entry
&fe
= file_names
[i
];
11202 dwarf2_start_subfile (this, fe
.name
,
11203 fe
.include_dir (line_header
));
11204 buildsym_compunit
*b
= get_builder ();
11205 if (b
->get_current_subfile ()->symtab
== NULL
)
11207 /* NOTE: start_subfile will recognize when it's been
11208 passed a file it has already seen. So we can't
11209 assume there's a simple mapping from
11210 cu->line_header->file_names to subfiles, plus
11211 cu->line_header->file_names may contain dups. */
11212 b
->get_current_subfile ()->symtab
11213 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11216 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11217 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11222 gdb_assert (m_builder
== nullptr);
11223 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11224 m_builder
.reset (new struct buildsym_compunit
11225 (COMPUNIT_OBJFILE (cust
), "",
11226 COMPUNIT_DIRNAME (cust
),
11227 compunit_language (cust
),
11229 list_in_scope
= get_builder ()->get_file_symbols ();
11231 auto &file_names
= line_header
->file_names ();
11232 for (i
= 0; i
< file_names
.size (); ++i
)
11234 file_entry
&fe
= file_names
[i
];
11235 fe
.symtab
= tug_unshare
->symtabs
[i
];
11239 /* The main symtab is allocated last. Type units don't have DW_AT_name
11240 so they don't have a "real" (so to speak) symtab anyway.
11241 There is later code that will assign the main symtab to all symbols
11242 that don't have one. We need to handle the case of a symbol with a
11243 missing symtab (DW_AT_decl_file) anyway. */
11246 /* Process DW_TAG_type_unit.
11247 For TUs we want to skip the first top level sibling if it's not the
11248 actual type being defined by this TU. In this case the first top
11249 level sibling is there to provide context only. */
11252 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11254 struct die_info
*child_die
;
11256 prepare_one_comp_unit (cu
, die
, language_minimal
);
11258 /* Initialize (or reinitialize) the machinery for building symtabs.
11259 We do this before processing child DIEs, so that the line header table
11260 is available for DW_AT_decl_file. */
11261 cu
->setup_type_unit_groups (die
);
11263 if (die
->child
!= NULL
)
11265 child_die
= die
->child
;
11266 while (child_die
&& child_die
->tag
)
11268 process_die (child_die
, cu
);
11269 child_die
= child_die
->sibling
;
11276 http://gcc.gnu.org/wiki/DebugFission
11277 http://gcc.gnu.org/wiki/DebugFissionDWP
11279 To simplify handling of both DWO files ("object" files with the DWARF info)
11280 and DWP files (a file with the DWOs packaged up into one file), we treat
11281 DWP files as having a collection of virtual DWO files. */
11284 hash_dwo_file (const void *item
)
11286 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11289 hash
= htab_hash_string (dwo_file
->dwo_name
);
11290 if (dwo_file
->comp_dir
!= NULL
)
11291 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11296 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11298 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11299 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11301 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11303 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11304 return lhs
->comp_dir
== rhs
->comp_dir
;
11305 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11308 /* Allocate a hash table for DWO files. */
11311 allocate_dwo_file_hash_table ()
11313 auto delete_dwo_file
= [] (void *item
)
11315 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11320 return htab_up (htab_create_alloc (41,
11327 /* Lookup DWO file DWO_NAME. */
11330 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11331 const char *dwo_name
,
11332 const char *comp_dir
)
11334 struct dwo_file find_entry
;
11337 if (dwarf2_per_objfile
->per_bfd
->dwo_files
== NULL
)
11338 dwarf2_per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11340 find_entry
.dwo_name
= dwo_name
;
11341 find_entry
.comp_dir
= comp_dir
;
11342 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11349 hash_dwo_unit (const void *item
)
11351 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11353 /* This drops the top 32 bits of the id, but is ok for a hash. */
11354 return dwo_unit
->signature
;
11358 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11360 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11361 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11363 /* The signature is assumed to be unique within the DWO file.
11364 So while object file CU dwo_id's always have the value zero,
11365 that's OK, assuming each object file DWO file has only one CU,
11366 and that's the rule for now. */
11367 return lhs
->signature
== rhs
->signature
;
11370 /* Allocate a hash table for DWO CUs,TUs.
11371 There is one of these tables for each of CUs,TUs for each DWO file. */
11374 allocate_dwo_unit_table ()
11376 /* Start out with a pretty small number.
11377 Generally DWO files contain only one CU and maybe some TUs. */
11378 return htab_up (htab_create_alloc (3,
11381 NULL
, xcalloc
, xfree
));
11384 /* die_reader_func for create_dwo_cu. */
11387 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11388 const gdb_byte
*info_ptr
,
11389 struct die_info
*comp_unit_die
,
11390 struct dwo_file
*dwo_file
,
11391 struct dwo_unit
*dwo_unit
)
11393 struct dwarf2_cu
*cu
= reader
->cu
;
11394 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11395 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11397 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11398 if (!signature
.has_value ())
11400 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11401 " its dwo_id [in module %s]"),
11402 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11406 dwo_unit
->dwo_file
= dwo_file
;
11407 dwo_unit
->signature
= *signature
;
11408 dwo_unit
->section
= section
;
11409 dwo_unit
->sect_off
= sect_off
;
11410 dwo_unit
->length
= cu
->per_cu
->length
;
11412 if (dwarf_read_debug
)
11413 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11414 sect_offset_str (sect_off
),
11415 hex_string (dwo_unit
->signature
));
11418 /* Create the dwo_units for the CUs in a DWO_FILE.
11419 Note: This function processes DWO files only, not DWP files. */
11422 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11423 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11424 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11426 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11427 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
11428 const gdb_byte
*info_ptr
, *end_ptr
;
11430 section
.read (objfile
);
11431 info_ptr
= section
.buffer
;
11433 if (info_ptr
== NULL
)
11436 if (dwarf_read_debug
)
11438 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11439 section
.get_name (),
11440 section
.get_file_name ());
11443 end_ptr
= info_ptr
+ section
.size
;
11444 while (info_ptr
< end_ptr
)
11446 struct dwarf2_per_cu_data per_cu
;
11447 struct dwo_unit read_unit
{};
11448 struct dwo_unit
*dwo_unit
;
11450 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11452 memset (&per_cu
, 0, sizeof (per_cu
));
11453 per_cu
.per_bfd
= per_bfd
;
11454 per_cu
.is_debug_types
= 0;
11455 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11456 per_cu
.section
= §ion
;
11458 cutu_reader
reader (&per_cu
, dwarf2_per_objfile
, cu
, &dwo_file
);
11459 if (!reader
.dummy_p
)
11460 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11461 &dwo_file
, &read_unit
);
11462 info_ptr
+= per_cu
.length
;
11464 // If the unit could not be parsed, skip it.
11465 if (read_unit
.dwo_file
== NULL
)
11468 if (cus_htab
== NULL
)
11469 cus_htab
= allocate_dwo_unit_table ();
11471 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11473 *dwo_unit
= read_unit
;
11474 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11475 gdb_assert (slot
!= NULL
);
11478 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11479 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11481 complaint (_("debug cu entry at offset %s is duplicate to"
11482 " the entry at offset %s, signature %s"),
11483 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11484 hex_string (dwo_unit
->signature
));
11486 *slot
= (void *)dwo_unit
;
11490 /* DWP file .debug_{cu,tu}_index section format:
11491 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11495 Both index sections have the same format, and serve to map a 64-bit
11496 signature to a set of section numbers. Each section begins with a header,
11497 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11498 indexes, and a pool of 32-bit section numbers. The index sections will be
11499 aligned at 8-byte boundaries in the file.
11501 The index section header consists of:
11503 V, 32 bit version number
11505 N, 32 bit number of compilation units or type units in the index
11506 M, 32 bit number of slots in the hash table
11508 Numbers are recorded using the byte order of the application binary.
11510 The hash table begins at offset 16 in the section, and consists of an array
11511 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11512 order of the application binary). Unused slots in the hash table are 0.
11513 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11515 The parallel table begins immediately after the hash table
11516 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11517 array of 32-bit indexes (using the byte order of the application binary),
11518 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11519 table contains a 32-bit index into the pool of section numbers. For unused
11520 hash table slots, the corresponding entry in the parallel table will be 0.
11522 The pool of section numbers begins immediately following the hash table
11523 (at offset 16 + 12 * M from the beginning of the section). The pool of
11524 section numbers consists of an array of 32-bit words (using the byte order
11525 of the application binary). Each item in the array is indexed starting
11526 from 0. The hash table entry provides the index of the first section
11527 number in the set. Additional section numbers in the set follow, and the
11528 set is terminated by a 0 entry (section number 0 is not used in ELF).
11530 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11531 section must be the first entry in the set, and the .debug_abbrev.dwo must
11532 be the second entry. Other members of the set may follow in any order.
11538 DWP Version 2 combines all the .debug_info, etc. sections into one,
11539 and the entries in the index tables are now offsets into these sections.
11540 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11543 Index Section Contents:
11545 Hash Table of Signatures dwp_hash_table.hash_table
11546 Parallel Table of Indices dwp_hash_table.unit_table
11547 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11548 Table of Section Sizes dwp_hash_table.v2.sizes
11550 The index section header consists of:
11552 V, 32 bit version number
11553 L, 32 bit number of columns in the table of section offsets
11554 N, 32 bit number of compilation units or type units in the index
11555 M, 32 bit number of slots in the hash table
11557 Numbers are recorded using the byte order of the application binary.
11559 The hash table has the same format as version 1.
11560 The parallel table of indices has the same format as version 1,
11561 except that the entries are origin-1 indices into the table of sections
11562 offsets and the table of section sizes.
11564 The table of offsets begins immediately following the parallel table
11565 (at offset 16 + 12 * M from the beginning of the section). The table is
11566 a two-dimensional array of 32-bit words (using the byte order of the
11567 application binary), with L columns and N+1 rows, in row-major order.
11568 Each row in the array is indexed starting from 0. The first row provides
11569 a key to the remaining rows: each column in this row provides an identifier
11570 for a debug section, and the offsets in the same column of subsequent rows
11571 refer to that section. The section identifiers are:
11573 DW_SECT_INFO 1 .debug_info.dwo
11574 DW_SECT_TYPES 2 .debug_types.dwo
11575 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11576 DW_SECT_LINE 4 .debug_line.dwo
11577 DW_SECT_LOC 5 .debug_loc.dwo
11578 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11579 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11580 DW_SECT_MACRO 8 .debug_macro.dwo
11582 The offsets provided by the CU and TU index sections are the base offsets
11583 for the contributions made by each CU or TU to the corresponding section
11584 in the package file. Each CU and TU header contains an abbrev_offset
11585 field, used to find the abbreviations table for that CU or TU within the
11586 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11587 be interpreted as relative to the base offset given in the index section.
11588 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11589 should be interpreted as relative to the base offset for .debug_line.dwo,
11590 and offsets into other debug sections obtained from DWARF attributes should
11591 also be interpreted as relative to the corresponding base offset.
11593 The table of sizes begins immediately following the table of offsets.
11594 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11595 with L columns and N rows, in row-major order. Each row in the array is
11596 indexed starting from 1 (row 0 is shared by the two tables).
11600 Hash table lookup is handled the same in version 1 and 2:
11602 We assume that N and M will not exceed 2^32 - 1.
11603 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11605 Given a 64-bit compilation unit signature or a type signature S, an entry
11606 in the hash table is located as follows:
11608 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11609 the low-order k bits all set to 1.
11611 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11613 3) If the hash table entry at index H matches the signature, use that
11614 entry. If the hash table entry at index H is unused (all zeroes),
11615 terminate the search: the signature is not present in the table.
11617 4) Let H = (H + H') modulo M. Repeat at Step 3.
11619 Because M > N and H' and M are relatively prime, the search is guaranteed
11620 to stop at an unused slot or find the match. */
11622 /* Create a hash table to map DWO IDs to their CU/TU entry in
11623 .debug_{info,types}.dwo in DWP_FILE.
11624 Returns NULL if there isn't one.
11625 Note: This function processes DWP files only, not DWO files. */
11627 static struct dwp_hash_table
*
11628 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11629 struct dwp_file
*dwp_file
, int is_debug_types
)
11631 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11632 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11633 const gdb_byte
*index_ptr
, *index_end
;
11634 struct dwarf2_section_info
*index
;
11635 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11636 struct dwp_hash_table
*htab
;
11638 if (is_debug_types
)
11639 index
= &dwp_file
->sections
.tu_index
;
11641 index
= &dwp_file
->sections
.cu_index
;
11643 if (index
->empty ())
11645 index
->read (objfile
);
11647 index_ptr
= index
->buffer
;
11648 index_end
= index_ptr
+ index
->size
;
11650 version
= read_4_bytes (dbfd
, index_ptr
);
11653 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11657 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11659 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11662 if (version
!= 1 && version
!= 2)
11664 error (_("Dwarf Error: unsupported DWP file version (%s)"
11665 " [in module %s]"),
11666 pulongest (version
), dwp_file
->name
);
11668 if (nr_slots
!= (nr_slots
& -nr_slots
))
11670 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11671 " is not power of 2 [in module %s]"),
11672 pulongest (nr_slots
), dwp_file
->name
);
11675 htab
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11676 htab
->version
= version
;
11677 htab
->nr_columns
= nr_columns
;
11678 htab
->nr_units
= nr_units
;
11679 htab
->nr_slots
= nr_slots
;
11680 htab
->hash_table
= index_ptr
;
11681 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11683 /* Exit early if the table is empty. */
11684 if (nr_slots
== 0 || nr_units
== 0
11685 || (version
== 2 && nr_columns
== 0))
11687 /* All must be zero. */
11688 if (nr_slots
!= 0 || nr_units
!= 0
11689 || (version
== 2 && nr_columns
!= 0))
11691 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11692 " all zero [in modules %s]"),
11700 htab
->section_pool
.v1
.indices
=
11701 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11702 /* It's harder to decide whether the section is too small in v1.
11703 V1 is deprecated anyway so we punt. */
11707 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11708 int *ids
= htab
->section_pool
.v2
.section_ids
;
11709 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11710 /* Reverse map for error checking. */
11711 int ids_seen
[DW_SECT_MAX
+ 1];
11714 if (nr_columns
< 2)
11716 error (_("Dwarf Error: bad DWP hash table, too few columns"
11717 " in section table [in module %s]"),
11720 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11722 error (_("Dwarf Error: bad DWP hash table, too many columns"
11723 " in section table [in module %s]"),
11726 memset (ids
, 255, sizeof_ids
);
11727 memset (ids_seen
, 255, sizeof (ids_seen
));
11728 for (i
= 0; i
< nr_columns
; ++i
)
11730 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11732 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11734 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11735 " in section table [in module %s]"),
11736 id
, dwp_file
->name
);
11738 if (ids_seen
[id
] != -1)
11740 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11741 " id %d in section table [in module %s]"),
11742 id
, dwp_file
->name
);
11747 /* Must have exactly one info or types section. */
11748 if (((ids_seen
[DW_SECT_INFO
] != -1)
11749 + (ids_seen
[DW_SECT_TYPES
] != -1))
11752 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11753 " DWO info/types section [in module %s]"),
11756 /* Must have an abbrev section. */
11757 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11759 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11760 " section [in module %s]"),
11763 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11764 htab
->section_pool
.v2
.sizes
=
11765 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11766 * nr_units
* nr_columns
);
11767 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11768 * nr_units
* nr_columns
))
11771 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11772 " [in module %s]"),
11780 /* Update SECTIONS with the data from SECTP.
11782 This function is like the other "locate" section routines that are
11783 passed to bfd_map_over_sections, but in this context the sections to
11784 read comes from the DWP V1 hash table, not the full ELF section table.
11786 The result is non-zero for success, or zero if an error was found. */
11789 locate_v1_virtual_dwo_sections (asection
*sectp
,
11790 struct virtual_v1_dwo_sections
*sections
)
11792 const struct dwop_section_names
*names
= &dwop_section_names
;
11794 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11796 /* There can be only one. */
11797 if (sections
->abbrev
.s
.section
!= NULL
)
11799 sections
->abbrev
.s
.section
= sectp
;
11800 sections
->abbrev
.size
= bfd_section_size (sectp
);
11802 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11803 || section_is_p (sectp
->name
, &names
->types_dwo
))
11805 /* There can be only one. */
11806 if (sections
->info_or_types
.s
.section
!= NULL
)
11808 sections
->info_or_types
.s
.section
= sectp
;
11809 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11811 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11813 /* There can be only one. */
11814 if (sections
->line
.s
.section
!= NULL
)
11816 sections
->line
.s
.section
= sectp
;
11817 sections
->line
.size
= bfd_section_size (sectp
);
11819 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11821 /* There can be only one. */
11822 if (sections
->loc
.s
.section
!= NULL
)
11824 sections
->loc
.s
.section
= sectp
;
11825 sections
->loc
.size
= bfd_section_size (sectp
);
11827 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11829 /* There can be only one. */
11830 if (sections
->macinfo
.s
.section
!= NULL
)
11832 sections
->macinfo
.s
.section
= sectp
;
11833 sections
->macinfo
.size
= bfd_section_size (sectp
);
11835 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11837 /* There can be only one. */
11838 if (sections
->macro
.s
.section
!= NULL
)
11840 sections
->macro
.s
.section
= sectp
;
11841 sections
->macro
.size
= bfd_section_size (sectp
);
11843 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11845 /* There can be only one. */
11846 if (sections
->str_offsets
.s
.section
!= NULL
)
11848 sections
->str_offsets
.s
.section
= sectp
;
11849 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11853 /* No other kind of section is valid. */
11860 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11861 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11862 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11863 This is for DWP version 1 files. */
11865 static struct dwo_unit
*
11866 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11867 struct dwp_file
*dwp_file
,
11868 uint32_t unit_index
,
11869 const char *comp_dir
,
11870 ULONGEST signature
, int is_debug_types
)
11872 const struct dwp_hash_table
*dwp_htab
=
11873 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11874 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11875 const char *kind
= is_debug_types
? "TU" : "CU";
11876 struct dwo_file
*dwo_file
;
11877 struct dwo_unit
*dwo_unit
;
11878 struct virtual_v1_dwo_sections sections
;
11879 void **dwo_file_slot
;
11882 gdb_assert (dwp_file
->version
== 1);
11884 if (dwarf_read_debug
)
11886 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11888 pulongest (unit_index
), hex_string (signature
),
11892 /* Fetch the sections of this DWO unit.
11893 Put a limit on the number of sections we look for so that bad data
11894 doesn't cause us to loop forever. */
11896 #define MAX_NR_V1_DWO_SECTIONS \
11897 (1 /* .debug_info or .debug_types */ \
11898 + 1 /* .debug_abbrev */ \
11899 + 1 /* .debug_line */ \
11900 + 1 /* .debug_loc */ \
11901 + 1 /* .debug_str_offsets */ \
11902 + 1 /* .debug_macro or .debug_macinfo */ \
11903 + 1 /* trailing zero */)
11905 memset (§ions
, 0, sizeof (sections
));
11907 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11910 uint32_t section_nr
=
11911 read_4_bytes (dbfd
,
11912 dwp_htab
->section_pool
.v1
.indices
11913 + (unit_index
+ i
) * sizeof (uint32_t));
11915 if (section_nr
== 0)
11917 if (section_nr
>= dwp_file
->num_sections
)
11919 error (_("Dwarf Error: bad DWP hash table, section number too large"
11920 " [in module %s]"),
11924 sectp
= dwp_file
->elf_sections
[section_nr
];
11925 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11927 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11928 " [in module %s]"),
11934 || sections
.info_or_types
.empty ()
11935 || sections
.abbrev
.empty ())
11937 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11938 " [in module %s]"),
11941 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11943 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11944 " [in module %s]"),
11948 /* It's easier for the rest of the code if we fake a struct dwo_file and
11949 have dwo_unit "live" in that. At least for now.
11951 The DWP file can be made up of a random collection of CUs and TUs.
11952 However, for each CU + set of TUs that came from the same original DWO
11953 file, we can combine them back into a virtual DWO file to save space
11954 (fewer struct dwo_file objects to allocate). Remember that for really
11955 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11957 std::string virtual_dwo_name
=
11958 string_printf ("virtual-dwo/%d-%d-%d-%d",
11959 sections
.abbrev
.get_id (),
11960 sections
.line
.get_id (),
11961 sections
.loc
.get_id (),
11962 sections
.str_offsets
.get_id ());
11963 /* Can we use an existing virtual DWO file? */
11964 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11965 virtual_dwo_name
.c_str (),
11967 /* Create one if necessary. */
11968 if (*dwo_file_slot
== NULL
)
11970 if (dwarf_read_debug
)
11972 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11973 virtual_dwo_name
.c_str ());
11975 dwo_file
= new struct dwo_file
;
11976 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
11977 dwo_file
->comp_dir
= comp_dir
;
11978 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11979 dwo_file
->sections
.line
= sections
.line
;
11980 dwo_file
->sections
.loc
= sections
.loc
;
11981 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11982 dwo_file
->sections
.macro
= sections
.macro
;
11983 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11984 /* The "str" section is global to the entire DWP file. */
11985 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11986 /* The info or types section is assigned below to dwo_unit,
11987 there's no need to record it in dwo_file.
11988 Also, we can't simply record type sections in dwo_file because
11989 we record a pointer into the vector in dwo_unit. As we collect more
11990 types we'll grow the vector and eventually have to reallocate space
11991 for it, invalidating all copies of pointers into the previous
11993 *dwo_file_slot
= dwo_file
;
11997 if (dwarf_read_debug
)
11999 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12000 virtual_dwo_name
.c_str ());
12002 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12005 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12006 dwo_unit
->dwo_file
= dwo_file
;
12007 dwo_unit
->signature
= signature
;
12008 dwo_unit
->section
=
12009 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12010 *dwo_unit
->section
= sections
.info_or_types
;
12011 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12016 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12017 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12018 piece within that section used by a TU/CU, return a virtual section
12019 of just that piece. */
12021 static struct dwarf2_section_info
12022 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12023 struct dwarf2_section_info
*section
,
12024 bfd_size_type offset
, bfd_size_type size
)
12026 struct dwarf2_section_info result
;
12029 gdb_assert (section
!= NULL
);
12030 gdb_assert (!section
->is_virtual
);
12032 memset (&result
, 0, sizeof (result
));
12033 result
.s
.containing_section
= section
;
12034 result
.is_virtual
= true;
12039 sectp
= section
->get_bfd_section ();
12041 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12042 bounds of the real section. This is a pretty-rare event, so just
12043 flag an error (easier) instead of a warning and trying to cope. */
12045 || offset
+ size
> bfd_section_size (sectp
))
12047 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12048 " in section %s [in module %s]"),
12049 sectp
? bfd_section_name (sectp
) : "<unknown>",
12050 objfile_name (dwarf2_per_objfile
->objfile
));
12053 result
.virtual_offset
= offset
;
12054 result
.size
= size
;
12058 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12059 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12060 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12061 This is for DWP version 2 files. */
12063 static struct dwo_unit
*
12064 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12065 struct dwp_file
*dwp_file
,
12066 uint32_t unit_index
,
12067 const char *comp_dir
,
12068 ULONGEST signature
, int is_debug_types
)
12070 const struct dwp_hash_table
*dwp_htab
=
12071 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12072 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12073 const char *kind
= is_debug_types
? "TU" : "CU";
12074 struct dwo_file
*dwo_file
;
12075 struct dwo_unit
*dwo_unit
;
12076 struct virtual_v2_dwo_sections sections
;
12077 void **dwo_file_slot
;
12080 gdb_assert (dwp_file
->version
== 2);
12082 if (dwarf_read_debug
)
12084 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12086 pulongest (unit_index
), hex_string (signature
),
12090 /* Fetch the section offsets of this DWO unit. */
12092 memset (§ions
, 0, sizeof (sections
));
12094 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12096 uint32_t offset
= read_4_bytes (dbfd
,
12097 dwp_htab
->section_pool
.v2
.offsets
12098 + (((unit_index
- 1) * dwp_htab
->nr_columns
12100 * sizeof (uint32_t)));
12101 uint32_t size
= read_4_bytes (dbfd
,
12102 dwp_htab
->section_pool
.v2
.sizes
12103 + (((unit_index
- 1) * dwp_htab
->nr_columns
12105 * sizeof (uint32_t)));
12107 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12110 case DW_SECT_TYPES
:
12111 sections
.info_or_types_offset
= offset
;
12112 sections
.info_or_types_size
= size
;
12114 case DW_SECT_ABBREV
:
12115 sections
.abbrev_offset
= offset
;
12116 sections
.abbrev_size
= size
;
12119 sections
.line_offset
= offset
;
12120 sections
.line_size
= size
;
12123 sections
.loc_offset
= offset
;
12124 sections
.loc_size
= size
;
12126 case DW_SECT_STR_OFFSETS
:
12127 sections
.str_offsets_offset
= offset
;
12128 sections
.str_offsets_size
= size
;
12130 case DW_SECT_MACINFO
:
12131 sections
.macinfo_offset
= offset
;
12132 sections
.macinfo_size
= size
;
12134 case DW_SECT_MACRO
:
12135 sections
.macro_offset
= offset
;
12136 sections
.macro_size
= size
;
12141 /* It's easier for the rest of the code if we fake a struct dwo_file and
12142 have dwo_unit "live" in that. At least for now.
12144 The DWP file can be made up of a random collection of CUs and TUs.
12145 However, for each CU + set of TUs that came from the same original DWO
12146 file, we can combine them back into a virtual DWO file to save space
12147 (fewer struct dwo_file objects to allocate). Remember that for really
12148 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12150 std::string virtual_dwo_name
=
12151 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12152 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12153 (long) (sections
.line_size
? sections
.line_offset
: 0),
12154 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12155 (long) (sections
.str_offsets_size
12156 ? sections
.str_offsets_offset
: 0));
12157 /* Can we use an existing virtual DWO file? */
12158 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12159 virtual_dwo_name
.c_str (),
12161 /* Create one if necessary. */
12162 if (*dwo_file_slot
== NULL
)
12164 if (dwarf_read_debug
)
12166 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12167 virtual_dwo_name
.c_str ());
12169 dwo_file
= new struct dwo_file
;
12170 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
12171 dwo_file
->comp_dir
= comp_dir
;
12172 dwo_file
->sections
.abbrev
=
12173 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12174 sections
.abbrev_offset
, sections
.abbrev_size
);
12175 dwo_file
->sections
.line
=
12176 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12177 sections
.line_offset
, sections
.line_size
);
12178 dwo_file
->sections
.loc
=
12179 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12180 sections
.loc_offset
, sections
.loc_size
);
12181 dwo_file
->sections
.macinfo
=
12182 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12183 sections
.macinfo_offset
, sections
.macinfo_size
);
12184 dwo_file
->sections
.macro
=
12185 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12186 sections
.macro_offset
, sections
.macro_size
);
12187 dwo_file
->sections
.str_offsets
=
12188 create_dwp_v2_section (dwarf2_per_objfile
,
12189 &dwp_file
->sections
.str_offsets
,
12190 sections
.str_offsets_offset
,
12191 sections
.str_offsets_size
);
12192 /* The "str" section is global to the entire DWP file. */
12193 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12194 /* The info or types section is assigned below to dwo_unit,
12195 there's no need to record it in dwo_file.
12196 Also, we can't simply record type sections in dwo_file because
12197 we record a pointer into the vector in dwo_unit. As we collect more
12198 types we'll grow the vector and eventually have to reallocate space
12199 for it, invalidating all copies of pointers into the previous
12201 *dwo_file_slot
= dwo_file
;
12205 if (dwarf_read_debug
)
12207 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12208 virtual_dwo_name
.c_str ());
12210 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12213 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12214 dwo_unit
->dwo_file
= dwo_file
;
12215 dwo_unit
->signature
= signature
;
12216 dwo_unit
->section
=
12217 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12218 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12220 ? &dwp_file
->sections
.types
12221 : &dwp_file
->sections
.info
,
12222 sections
.info_or_types_offset
,
12223 sections
.info_or_types_size
);
12224 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12229 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12230 Returns NULL if the signature isn't found. */
12232 static struct dwo_unit
*
12233 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12234 struct dwp_file
*dwp_file
, const char *comp_dir
,
12235 ULONGEST signature
, int is_debug_types
)
12237 const struct dwp_hash_table
*dwp_htab
=
12238 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12239 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12240 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12241 uint32_t hash
= signature
& mask
;
12242 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12245 struct dwo_unit find_dwo_cu
;
12247 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12248 find_dwo_cu
.signature
= signature
;
12249 slot
= htab_find_slot (is_debug_types
12250 ? dwp_file
->loaded_tus
.get ()
12251 : dwp_file
->loaded_cus
.get (),
12252 &find_dwo_cu
, INSERT
);
12255 return (struct dwo_unit
*) *slot
;
12257 /* Use a for loop so that we don't loop forever on bad debug info. */
12258 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12260 ULONGEST signature_in_table
;
12262 signature_in_table
=
12263 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12264 if (signature_in_table
== signature
)
12266 uint32_t unit_index
=
12267 read_4_bytes (dbfd
,
12268 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12270 if (dwp_file
->version
== 1)
12272 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12273 dwp_file
, unit_index
,
12274 comp_dir
, signature
,
12279 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12280 dwp_file
, unit_index
,
12281 comp_dir
, signature
,
12284 return (struct dwo_unit
*) *slot
;
12286 if (signature_in_table
== 0)
12288 hash
= (hash
+ hash2
) & mask
;
12291 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12292 " [in module %s]"),
12296 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12297 Open the file specified by FILE_NAME and hand it off to BFD for
12298 preliminary analysis. Return a newly initialized bfd *, which
12299 includes a canonicalized copy of FILE_NAME.
12300 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12301 SEARCH_CWD is true if the current directory is to be searched.
12302 It will be searched before debug-file-directory.
12303 If successful, the file is added to the bfd include table of the
12304 objfile's bfd (see gdb_bfd_record_inclusion).
12305 If unable to find/open the file, return NULL.
12306 NOTE: This function is derived from symfile_bfd_open. */
12308 static gdb_bfd_ref_ptr
12309 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12310 const char *file_name
, int is_dwp
, int search_cwd
)
12313 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12314 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12315 to debug_file_directory. */
12316 const char *search_path
;
12317 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12319 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12322 if (*debug_file_directory
!= '\0')
12324 search_path_holder
.reset (concat (".", dirname_separator_string
,
12325 debug_file_directory
,
12327 search_path
= search_path_holder
.get ();
12333 search_path
= debug_file_directory
;
12335 openp_flags flags
= OPF_RETURN_REALPATH
;
12337 flags
|= OPF_SEARCH_IN_PATH
;
12339 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12340 desc
= openp (search_path
, flags
, file_name
,
12341 O_RDONLY
| O_BINARY
, &absolute_name
);
12345 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12347 if (sym_bfd
== NULL
)
12349 bfd_set_cacheable (sym_bfd
.get (), 1);
12351 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12354 /* Success. Record the bfd as having been included by the objfile's bfd.
12355 This is important because things like demangled_names_hash lives in the
12356 objfile's per_bfd space and may have references to things like symbol
12357 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12358 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12363 /* Try to open DWO file FILE_NAME.
12364 COMP_DIR is the DW_AT_comp_dir attribute.
12365 The result is the bfd handle of the file.
12366 If there is a problem finding or opening the file, return NULL.
12367 Upon success, the canonicalized path of the file is stored in the bfd,
12368 same as symfile_bfd_open. */
12370 static gdb_bfd_ref_ptr
12371 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12372 const char *file_name
, const char *comp_dir
)
12374 if (IS_ABSOLUTE_PATH (file_name
))
12375 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12376 0 /*is_dwp*/, 0 /*search_cwd*/);
12378 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12380 if (comp_dir
!= NULL
)
12382 gdb::unique_xmalloc_ptr
<char> path_to_try
12383 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12385 /* NOTE: If comp_dir is a relative path, this will also try the
12386 search path, which seems useful. */
12387 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12388 path_to_try
.get (),
12390 1 /*search_cwd*/));
12395 /* That didn't work, try debug-file-directory, which, despite its name,
12396 is a list of paths. */
12398 if (*debug_file_directory
== '\0')
12401 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12402 0 /*is_dwp*/, 1 /*search_cwd*/);
12405 /* This function is mapped across the sections and remembers the offset and
12406 size of each of the DWO debugging sections we are interested in. */
12409 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12411 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12412 const struct dwop_section_names
*names
= &dwop_section_names
;
12414 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12416 dwo_sections
->abbrev
.s
.section
= sectp
;
12417 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12419 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12421 dwo_sections
->info
.s
.section
= sectp
;
12422 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12424 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12426 dwo_sections
->line
.s
.section
= sectp
;
12427 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12429 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12431 dwo_sections
->loc
.s
.section
= sectp
;
12432 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12434 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12436 dwo_sections
->loclists
.s
.section
= sectp
;
12437 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12439 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12441 dwo_sections
->macinfo
.s
.section
= sectp
;
12442 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12444 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12446 dwo_sections
->macro
.s
.section
= sectp
;
12447 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12449 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12451 dwo_sections
->str
.s
.section
= sectp
;
12452 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12454 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12456 dwo_sections
->str_offsets
.s
.section
= sectp
;
12457 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12459 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12461 struct dwarf2_section_info type_section
;
12463 memset (&type_section
, 0, sizeof (type_section
));
12464 type_section
.s
.section
= sectp
;
12465 type_section
.size
= bfd_section_size (sectp
);
12466 dwo_sections
->types
.push_back (type_section
);
12470 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12471 by PER_CU. This is for the non-DWP case.
12472 The result is NULL if DWO_NAME can't be found. */
12474 static struct dwo_file
*
12475 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12476 const char *comp_dir
)
12478 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12480 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12483 if (dwarf_read_debug
)
12484 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12488 dwo_file_up
dwo_file (new struct dwo_file
);
12489 dwo_file
->dwo_name
= dwo_name
;
12490 dwo_file
->comp_dir
= comp_dir
;
12491 dwo_file
->dbfd
= std::move (dbfd
);
12493 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12494 &dwo_file
->sections
);
12496 create_cus_hash_table (dwarf2_per_objfile
, cu
, *dwo_file
,
12497 dwo_file
->sections
.info
, dwo_file
->cus
);
12499 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12500 dwo_file
->sections
.types
, dwo_file
->tus
);
12502 if (dwarf_read_debug
)
12503 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12505 return dwo_file
.release ();
12508 /* This function is mapped across the sections and remembers the offset and
12509 size of each of the DWP debugging sections common to version 1 and 2 that
12510 we are interested in. */
12513 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12514 void *dwp_file_ptr
)
12516 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12517 const struct dwop_section_names
*names
= &dwop_section_names
;
12518 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12520 /* Record the ELF section number for later lookup: this is what the
12521 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12522 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12523 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12525 /* Look for specific sections that we need. */
12526 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12528 dwp_file
->sections
.str
.s
.section
= sectp
;
12529 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12531 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12533 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12534 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12536 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12538 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12539 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12543 /* This function is mapped across the sections and remembers the offset and
12544 size of each of the DWP version 2 debugging sections that we are interested
12545 in. This is split into a separate function because we don't know if we
12546 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12549 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12551 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12552 const struct dwop_section_names
*names
= &dwop_section_names
;
12553 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12555 /* Record the ELF section number for later lookup: this is what the
12556 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12557 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12558 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12560 /* Look for specific sections that we need. */
12561 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12563 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12564 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12566 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12568 dwp_file
->sections
.info
.s
.section
= sectp
;
12569 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12571 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12573 dwp_file
->sections
.line
.s
.section
= sectp
;
12574 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12576 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12578 dwp_file
->sections
.loc
.s
.section
= sectp
;
12579 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12581 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12583 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12584 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12586 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12588 dwp_file
->sections
.macro
.s
.section
= sectp
;
12589 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12591 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12593 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12594 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12596 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12598 dwp_file
->sections
.types
.s
.section
= sectp
;
12599 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12603 /* Hash function for dwp_file loaded CUs/TUs. */
12606 hash_dwp_loaded_cutus (const void *item
)
12608 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12610 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12611 return dwo_unit
->signature
;
12614 /* Equality function for dwp_file loaded CUs/TUs. */
12617 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12619 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12620 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12622 return dua
->signature
== dub
->signature
;
12625 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12628 allocate_dwp_loaded_cutus_table ()
12630 return htab_up (htab_create_alloc (3,
12631 hash_dwp_loaded_cutus
,
12632 eq_dwp_loaded_cutus
,
12633 NULL
, xcalloc
, xfree
));
12636 /* Try to open DWP file FILE_NAME.
12637 The result is the bfd handle of the file.
12638 If there is a problem finding or opening the file, return NULL.
12639 Upon success, the canonicalized path of the file is stored in the bfd,
12640 same as symfile_bfd_open. */
12642 static gdb_bfd_ref_ptr
12643 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12644 const char *file_name
)
12646 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12648 1 /*search_cwd*/));
12652 /* Work around upstream bug 15652.
12653 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12654 [Whether that's a "bug" is debatable, but it is getting in our way.]
12655 We have no real idea where the dwp file is, because gdb's realpath-ing
12656 of the executable's path may have discarded the needed info.
12657 [IWBN if the dwp file name was recorded in the executable, akin to
12658 .gnu_debuglink, but that doesn't exist yet.]
12659 Strip the directory from FILE_NAME and search again. */
12660 if (*debug_file_directory
!= '\0')
12662 /* Don't implicitly search the current directory here.
12663 If the user wants to search "." to handle this case,
12664 it must be added to debug-file-directory. */
12665 return try_open_dwop_file (dwarf2_per_objfile
,
12666 lbasename (file_name
), 1 /*is_dwp*/,
12673 /* Initialize the use of the DWP file for the current objfile.
12674 By convention the name of the DWP file is ${objfile}.dwp.
12675 The result is NULL if it can't be found. */
12677 static std::unique_ptr
<struct dwp_file
>
12678 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12680 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12682 /* Try to find first .dwp for the binary file before any symbolic links
12685 /* If the objfile is a debug file, find the name of the real binary
12686 file and get the name of dwp file from there. */
12687 std::string dwp_name
;
12688 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12690 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12691 const char *backlink_basename
= lbasename (backlink
->original_name
);
12693 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12696 dwp_name
= objfile
->original_name
;
12698 dwp_name
+= ".dwp";
12700 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12702 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12704 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12705 dwp_name
= objfile_name (objfile
);
12706 dwp_name
+= ".dwp";
12707 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12712 if (dwarf_read_debug
)
12713 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12714 return std::unique_ptr
<dwp_file
> ();
12717 const char *name
= bfd_get_filename (dbfd
.get ());
12718 std::unique_ptr
<struct dwp_file
> dwp_file
12719 (new struct dwp_file (name
, std::move (dbfd
)));
12721 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12722 dwp_file
->elf_sections
=
12723 OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
12724 dwp_file
->num_sections
, asection
*);
12726 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12727 dwarf2_locate_common_dwp_sections
,
12730 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12733 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12736 /* The DWP file version is stored in the hash table. Oh well. */
12737 if (dwp_file
->cus
&& dwp_file
->tus
12738 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12740 /* Technically speaking, we should try to limp along, but this is
12741 pretty bizarre. We use pulongest here because that's the established
12742 portability solution (e.g, we cannot use %u for uint32_t). */
12743 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12744 " TU version %s [in DWP file %s]"),
12745 pulongest (dwp_file
->cus
->version
),
12746 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12750 dwp_file
->version
= dwp_file
->cus
->version
;
12751 else if (dwp_file
->tus
)
12752 dwp_file
->version
= dwp_file
->tus
->version
;
12754 dwp_file
->version
= 2;
12756 if (dwp_file
->version
== 2)
12757 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12758 dwarf2_locate_v2_dwp_sections
,
12761 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12762 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12764 if (dwarf_read_debug
)
12766 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12767 fprintf_unfiltered (gdb_stdlog
,
12768 " %s CUs, %s TUs\n",
12769 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12770 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12776 /* Wrapper around open_and_init_dwp_file, only open it once. */
12778 static struct dwp_file
*
12779 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12781 if (! dwarf2_per_objfile
->per_bfd
->dwp_checked
)
12783 dwarf2_per_objfile
->per_bfd
->dwp_file
12784 = open_and_init_dwp_file (dwarf2_per_objfile
);
12785 dwarf2_per_objfile
->per_bfd
->dwp_checked
= 1;
12787 return dwarf2_per_objfile
->per_bfd
->dwp_file
.get ();
12790 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12791 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12792 or in the DWP file for the objfile, referenced by THIS_UNIT.
12793 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12794 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12796 This is called, for example, when wanting to read a variable with a
12797 complex location. Therefore we don't want to do file i/o for every call.
12798 Therefore we don't want to look for a DWO file on every call.
12799 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12800 then we check if we've already seen DWO_NAME, and only THEN do we check
12803 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12804 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12806 static struct dwo_unit
*
12807 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12808 ULONGEST signature
, int is_debug_types
)
12810 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12811 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12812 const char *kind
= is_debug_types
? "TU" : "CU";
12813 void **dwo_file_slot
;
12814 struct dwo_file
*dwo_file
;
12815 struct dwp_file
*dwp_file
;
12817 /* First see if there's a DWP file.
12818 If we have a DWP file but didn't find the DWO inside it, don't
12819 look for the original DWO file. It makes gdb behave differently
12820 depending on whether one is debugging in the build tree. */
12822 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12823 if (dwp_file
!= NULL
)
12825 const struct dwp_hash_table
*dwp_htab
=
12826 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12828 if (dwp_htab
!= NULL
)
12830 struct dwo_unit
*dwo_cutu
=
12831 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12832 signature
, is_debug_types
);
12834 if (dwo_cutu
!= NULL
)
12836 if (dwarf_read_debug
)
12838 fprintf_unfiltered (gdb_stdlog
,
12839 "Virtual DWO %s %s found: @%s\n",
12840 kind
, hex_string (signature
),
12841 host_address_to_string (dwo_cutu
));
12849 /* No DWP file, look for the DWO file. */
12851 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12852 dwo_name
, comp_dir
);
12853 if (*dwo_file_slot
== NULL
)
12855 /* Read in the file and build a table of the CUs/TUs it contains. */
12856 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12858 /* NOTE: This will be NULL if unable to open the file. */
12859 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12861 if (dwo_file
!= NULL
)
12863 struct dwo_unit
*dwo_cutu
= NULL
;
12865 if (is_debug_types
&& dwo_file
->tus
)
12867 struct dwo_unit find_dwo_cutu
;
12869 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12870 find_dwo_cutu
.signature
= signature
;
12872 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12875 else if (!is_debug_types
&& dwo_file
->cus
)
12877 struct dwo_unit find_dwo_cutu
;
12879 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12880 find_dwo_cutu
.signature
= signature
;
12881 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12885 if (dwo_cutu
!= NULL
)
12887 if (dwarf_read_debug
)
12889 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12890 kind
, dwo_name
, hex_string (signature
),
12891 host_address_to_string (dwo_cutu
));
12898 /* We didn't find it. This could mean a dwo_id mismatch, or
12899 someone deleted the DWO/DWP file, or the search path isn't set up
12900 correctly to find the file. */
12902 if (dwarf_read_debug
)
12904 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12905 kind
, dwo_name
, hex_string (signature
));
12908 /* This is a warning and not a complaint because it can be caused by
12909 pilot error (e.g., user accidentally deleting the DWO). */
12911 /* Print the name of the DWP file if we looked there, helps the user
12912 better diagnose the problem. */
12913 std::string dwp_text
;
12915 if (dwp_file
!= NULL
)
12916 dwp_text
= string_printf (" [in DWP file %s]",
12917 lbasename (dwp_file
->name
));
12919 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12920 " [in module %s]"),
12921 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12922 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12927 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12928 See lookup_dwo_cutu_unit for details. */
12930 static struct dwo_unit
*
12931 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12932 ULONGEST signature
)
12934 gdb_assert (!cu
->per_cu
->is_debug_types
);
12936 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12939 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12940 See lookup_dwo_cutu_unit for details. */
12942 static struct dwo_unit
*
12943 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12945 gdb_assert (cu
->per_cu
->is_debug_types
);
12947 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12949 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12952 /* Traversal function for queue_and_load_all_dwo_tus. */
12955 queue_and_load_dwo_tu (void **slot
, void *info
)
12957 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12958 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12959 ULONGEST signature
= dwo_unit
->signature
;
12960 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12962 if (sig_type
!= NULL
)
12964 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12966 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12967 a real dependency of PER_CU on SIG_TYPE. That is detected later
12968 while processing PER_CU. */
12969 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
12970 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12971 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12977 /* Queue all TUs contained in the DWO of CU to be read in.
12978 The DWO may have the only definition of the type, though it may not be
12979 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12980 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12983 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12985 struct dwo_unit
*dwo_unit
;
12986 struct dwo_file
*dwo_file
;
12988 gdb_assert (cu
!= nullptr);
12989 gdb_assert (!cu
->per_cu
->is_debug_types
);
12990 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12992 dwo_unit
= cu
->dwo_unit
;
12993 gdb_assert (dwo_unit
!= NULL
);
12995 dwo_file
= dwo_unit
->dwo_file
;
12996 if (dwo_file
->tus
!= NULL
)
12997 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13000 /* Read in various DIEs. */
13002 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13003 Inherit only the children of the DW_AT_abstract_origin DIE not being
13004 already referenced by DW_AT_abstract_origin from the children of the
13008 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13010 struct die_info
*child_die
;
13011 sect_offset
*offsetp
;
13012 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13013 struct die_info
*origin_die
;
13014 /* Iterator of the ORIGIN_DIE children. */
13015 struct die_info
*origin_child_die
;
13016 struct attribute
*attr
;
13017 struct dwarf2_cu
*origin_cu
;
13018 struct pending
**origin_previous_list_in_scope
;
13020 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13024 /* Note that following die references may follow to a die in a
13028 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13030 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13032 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13033 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13035 if (die
->tag
!= origin_die
->tag
13036 && !(die
->tag
== DW_TAG_inlined_subroutine
13037 && origin_die
->tag
== DW_TAG_subprogram
))
13038 complaint (_("DIE %s and its abstract origin %s have different tags"),
13039 sect_offset_str (die
->sect_off
),
13040 sect_offset_str (origin_die
->sect_off
));
13042 std::vector
<sect_offset
> offsets
;
13044 for (child_die
= die
->child
;
13045 child_die
&& child_die
->tag
;
13046 child_die
= child_die
->sibling
)
13048 struct die_info
*child_origin_die
;
13049 struct dwarf2_cu
*child_origin_cu
;
13051 /* We are trying to process concrete instance entries:
13052 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13053 it's not relevant to our analysis here. i.e. detecting DIEs that are
13054 present in the abstract instance but not referenced in the concrete
13056 if (child_die
->tag
== DW_TAG_call_site
13057 || child_die
->tag
== DW_TAG_GNU_call_site
)
13060 /* For each CHILD_DIE, find the corresponding child of
13061 ORIGIN_DIE. If there is more than one layer of
13062 DW_AT_abstract_origin, follow them all; there shouldn't be,
13063 but GCC versions at least through 4.4 generate this (GCC PR
13065 child_origin_die
= child_die
;
13066 child_origin_cu
= cu
;
13069 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13073 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13077 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13078 counterpart may exist. */
13079 if (child_origin_die
!= child_die
)
13081 if (child_die
->tag
!= child_origin_die
->tag
13082 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13083 && child_origin_die
->tag
== DW_TAG_subprogram
))
13084 complaint (_("Child DIE %s and its abstract origin %s have "
13086 sect_offset_str (child_die
->sect_off
),
13087 sect_offset_str (child_origin_die
->sect_off
));
13088 if (child_origin_die
->parent
!= origin_die
)
13089 complaint (_("Child DIE %s and its abstract origin %s have "
13090 "different parents"),
13091 sect_offset_str (child_die
->sect_off
),
13092 sect_offset_str (child_origin_die
->sect_off
));
13094 offsets
.push_back (child_origin_die
->sect_off
);
13097 std::sort (offsets
.begin (), offsets
.end ());
13098 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13099 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13100 if (offsetp
[-1] == *offsetp
)
13101 complaint (_("Multiple children of DIE %s refer "
13102 "to DIE %s as their abstract origin"),
13103 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13105 offsetp
= offsets
.data ();
13106 origin_child_die
= origin_die
->child
;
13107 while (origin_child_die
&& origin_child_die
->tag
)
13109 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13110 while (offsetp
< offsets_end
13111 && *offsetp
< origin_child_die
->sect_off
)
13113 if (offsetp
>= offsets_end
13114 || *offsetp
> origin_child_die
->sect_off
)
13116 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13117 Check whether we're already processing ORIGIN_CHILD_DIE.
13118 This can happen with mutually referenced abstract_origins.
13120 if (!origin_child_die
->in_process
)
13121 process_die (origin_child_die
, origin_cu
);
13123 origin_child_die
= origin_child_die
->sibling
;
13125 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13127 if (cu
!= origin_cu
)
13128 compute_delayed_physnames (origin_cu
);
13132 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13134 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13135 struct gdbarch
*gdbarch
= objfile
->arch ();
13136 struct context_stack
*newobj
;
13139 struct die_info
*child_die
;
13140 struct attribute
*attr
, *call_line
, *call_file
;
13142 CORE_ADDR baseaddr
;
13143 struct block
*block
;
13144 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13145 std::vector
<struct symbol
*> template_args
;
13146 struct template_symbol
*templ_func
= NULL
;
13150 /* If we do not have call site information, we can't show the
13151 caller of this inlined function. That's too confusing, so
13152 only use the scope for local variables. */
13153 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13154 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13155 if (call_line
== NULL
|| call_file
== NULL
)
13157 read_lexical_block_scope (die
, cu
);
13162 baseaddr
= objfile
->text_section_offset ();
13164 name
= dwarf2_name (die
, cu
);
13166 /* Ignore functions with missing or empty names. These are actually
13167 illegal according to the DWARF standard. */
13170 complaint (_("missing name for subprogram DIE at %s"),
13171 sect_offset_str (die
->sect_off
));
13175 /* Ignore functions with missing or invalid low and high pc attributes. */
13176 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13177 <= PC_BOUNDS_INVALID
)
13179 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13180 if (!attr
|| !DW_UNSND (attr
))
13181 complaint (_("cannot get low and high bounds "
13182 "for subprogram DIE at %s"),
13183 sect_offset_str (die
->sect_off
));
13187 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13188 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13190 /* If we have any template arguments, then we must allocate a
13191 different sort of symbol. */
13192 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13194 if (child_die
->tag
== DW_TAG_template_type_param
13195 || child_die
->tag
== DW_TAG_template_value_param
)
13197 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13198 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13203 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13204 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13205 (struct symbol
*) templ_func
);
13207 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13208 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13211 /* If there is a location expression for DW_AT_frame_base, record
13213 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13214 if (attr
!= nullptr)
13215 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13217 /* If there is a location for the static link, record it. */
13218 newobj
->static_link
= NULL
;
13219 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13220 if (attr
!= nullptr)
13222 newobj
->static_link
13223 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13224 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13228 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13230 if (die
->child
!= NULL
)
13232 child_die
= die
->child
;
13233 while (child_die
&& child_die
->tag
)
13235 if (child_die
->tag
== DW_TAG_template_type_param
13236 || child_die
->tag
== DW_TAG_template_value_param
)
13238 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13241 template_args
.push_back (arg
);
13244 process_die (child_die
, cu
);
13245 child_die
= child_die
->sibling
;
13249 inherit_abstract_dies (die
, cu
);
13251 /* If we have a DW_AT_specification, we might need to import using
13252 directives from the context of the specification DIE. See the
13253 comment in determine_prefix. */
13254 if (cu
->language
== language_cplus
13255 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13257 struct dwarf2_cu
*spec_cu
= cu
;
13258 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13262 child_die
= spec_die
->child
;
13263 while (child_die
&& child_die
->tag
)
13265 if (child_die
->tag
== DW_TAG_imported_module
)
13266 process_die (child_die
, spec_cu
);
13267 child_die
= child_die
->sibling
;
13270 /* In some cases, GCC generates specification DIEs that
13271 themselves contain DW_AT_specification attributes. */
13272 spec_die
= die_specification (spec_die
, &spec_cu
);
13276 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13277 /* Make a block for the local symbols within. */
13278 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13279 cstk
.static_link
, lowpc
, highpc
);
13281 /* For C++, set the block's scope. */
13282 if ((cu
->language
== language_cplus
13283 || cu
->language
== language_fortran
13284 || cu
->language
== language_d
13285 || cu
->language
== language_rust
)
13286 && cu
->processing_has_namespace_info
)
13287 block_set_scope (block
, determine_prefix (die
, cu
),
13288 &objfile
->objfile_obstack
);
13290 /* If we have address ranges, record them. */
13291 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13293 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13295 /* Attach template arguments to function. */
13296 if (!template_args
.empty ())
13298 gdb_assert (templ_func
!= NULL
);
13300 templ_func
->n_template_arguments
= template_args
.size ();
13301 templ_func
->template_arguments
13302 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13303 templ_func
->n_template_arguments
);
13304 memcpy (templ_func
->template_arguments
,
13305 template_args
.data (),
13306 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13308 /* Make sure that the symtab is set on the new symbols. Even
13309 though they don't appear in this symtab directly, other parts
13310 of gdb assume that symbols do, and this is reasonably
13312 for (symbol
*sym
: template_args
)
13313 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13316 /* In C++, we can have functions nested inside functions (e.g., when
13317 a function declares a class that has methods). This means that
13318 when we finish processing a function scope, we may need to go
13319 back to building a containing block's symbol lists. */
13320 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13321 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13323 /* If we've finished processing a top-level function, subsequent
13324 symbols go in the file symbol list. */
13325 if (cu
->get_builder ()->outermost_context_p ())
13326 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13329 /* Process all the DIES contained within a lexical block scope. Start
13330 a new scope, process the dies, and then close the scope. */
13333 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13335 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13336 struct gdbarch
*gdbarch
= objfile
->arch ();
13337 CORE_ADDR lowpc
, highpc
;
13338 struct die_info
*child_die
;
13339 CORE_ADDR baseaddr
;
13341 baseaddr
= objfile
->text_section_offset ();
13343 /* Ignore blocks with missing or invalid low and high pc attributes. */
13344 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13345 as multiple lexical blocks? Handling children in a sane way would
13346 be nasty. Might be easier to properly extend generic blocks to
13347 describe ranges. */
13348 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13350 case PC_BOUNDS_NOT_PRESENT
:
13351 /* DW_TAG_lexical_block has no attributes, process its children as if
13352 there was no wrapping by that DW_TAG_lexical_block.
13353 GCC does no longer produces such DWARF since GCC r224161. */
13354 for (child_die
= die
->child
;
13355 child_die
!= NULL
&& child_die
->tag
;
13356 child_die
= child_die
->sibling
)
13358 /* We might already be processing this DIE. This can happen
13359 in an unusual circumstance -- where a subroutine A
13360 appears lexically in another subroutine B, but A actually
13361 inlines B. The recursion is broken here, rather than in
13362 inherit_abstract_dies, because it seems better to simply
13363 drop concrete children here. */
13364 if (!child_die
->in_process
)
13365 process_die (child_die
, cu
);
13368 case PC_BOUNDS_INVALID
:
13371 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13372 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13374 cu
->get_builder ()->push_context (0, lowpc
);
13375 if (die
->child
!= NULL
)
13377 child_die
= die
->child
;
13378 while (child_die
&& child_die
->tag
)
13380 process_die (child_die
, cu
);
13381 child_die
= child_die
->sibling
;
13384 inherit_abstract_dies (die
, cu
);
13385 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13387 if (*cu
->get_builder ()->get_local_symbols () != NULL
13388 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13390 struct block
*block
13391 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13392 cstk
.start_addr
, highpc
);
13394 /* Note that recording ranges after traversing children, as we
13395 do here, means that recording a parent's ranges entails
13396 walking across all its children's ranges as they appear in
13397 the address map, which is quadratic behavior.
13399 It would be nicer to record the parent's ranges before
13400 traversing its children, simply overriding whatever you find
13401 there. But since we don't even decide whether to create a
13402 block until after we've traversed its children, that's hard
13404 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13406 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13407 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13410 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13413 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13415 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13416 struct objfile
*objfile
= per_objfile
->objfile
;
13417 struct gdbarch
*gdbarch
= objfile
->arch ();
13418 CORE_ADDR pc
, baseaddr
;
13419 struct attribute
*attr
;
13420 struct call_site
*call_site
, call_site_local
;
13423 struct die_info
*child_die
;
13425 baseaddr
= objfile
->text_section_offset ();
13427 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13430 /* This was a pre-DWARF-5 GNU extension alias
13431 for DW_AT_call_return_pc. */
13432 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13436 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13437 "DIE %s [in module %s]"),
13438 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13441 pc
= attr
->value_as_address () + baseaddr
;
13442 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13444 if (cu
->call_site_htab
== NULL
)
13445 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13446 NULL
, &objfile
->objfile_obstack
,
13447 hashtab_obstack_allocate
, NULL
);
13448 call_site_local
.pc
= pc
;
13449 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13452 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13453 "DIE %s [in module %s]"),
13454 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13455 objfile_name (objfile
));
13459 /* Count parameters at the caller. */
13462 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13463 child_die
= child_die
->sibling
)
13465 if (child_die
->tag
!= DW_TAG_call_site_parameter
13466 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13468 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13469 "DW_TAG_call_site child DIE %s [in module %s]"),
13470 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13471 objfile_name (objfile
));
13479 = ((struct call_site
*)
13480 obstack_alloc (&objfile
->objfile_obstack
,
13481 sizeof (*call_site
)
13482 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13484 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13485 call_site
->pc
= pc
;
13487 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13488 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13490 struct die_info
*func_die
;
13492 /* Skip also over DW_TAG_inlined_subroutine. */
13493 for (func_die
= die
->parent
;
13494 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13495 && func_die
->tag
!= DW_TAG_subroutine_type
;
13496 func_die
= func_die
->parent
);
13498 /* DW_AT_call_all_calls is a superset
13499 of DW_AT_call_all_tail_calls. */
13501 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13502 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13503 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13504 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13506 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13507 not complete. But keep CALL_SITE for look ups via call_site_htab,
13508 both the initial caller containing the real return address PC and
13509 the final callee containing the current PC of a chain of tail
13510 calls do not need to have the tail call list complete. But any
13511 function candidate for a virtual tail call frame searched via
13512 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13513 determined unambiguously. */
13517 struct type
*func_type
= NULL
;
13520 func_type
= get_die_type (func_die
, cu
);
13521 if (func_type
!= NULL
)
13523 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13525 /* Enlist this call site to the function. */
13526 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13527 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13530 complaint (_("Cannot find function owning DW_TAG_call_site "
13531 "DIE %s [in module %s]"),
13532 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13536 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13538 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13540 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13543 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13544 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13546 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13547 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13548 /* Keep NULL DWARF_BLOCK. */;
13549 else if (attr
->form_is_block ())
13551 struct dwarf2_locexpr_baton
*dlbaton
;
13553 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13554 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13555 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13556 dlbaton
->per_objfile
= per_objfile
;
13557 dlbaton
->per_cu
= cu
->per_cu
;
13559 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13561 else if (attr
->form_is_ref ())
13563 struct dwarf2_cu
*target_cu
= cu
;
13564 struct die_info
*target_die
;
13566 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13567 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13568 if (die_is_declaration (target_die
, target_cu
))
13570 const char *target_physname
;
13572 /* Prefer the mangled name; otherwise compute the demangled one. */
13573 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13574 if (target_physname
== NULL
)
13575 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13576 if (target_physname
== NULL
)
13577 complaint (_("DW_AT_call_target target DIE has invalid "
13578 "physname, for referencing DIE %s [in module %s]"),
13579 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13581 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13587 /* DW_AT_entry_pc should be preferred. */
13588 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13589 <= PC_BOUNDS_INVALID
)
13590 complaint (_("DW_AT_call_target target DIE has invalid "
13591 "low pc, for referencing DIE %s [in module %s]"),
13592 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13595 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13596 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13601 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13602 "block nor reference, for DIE %s [in module %s]"),
13603 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13605 call_site
->per_cu
= cu
->per_cu
;
13606 call_site
->per_objfile
= per_objfile
;
13608 for (child_die
= die
->child
;
13609 child_die
&& child_die
->tag
;
13610 child_die
= child_die
->sibling
)
13612 struct call_site_parameter
*parameter
;
13613 struct attribute
*loc
, *origin
;
13615 if (child_die
->tag
!= DW_TAG_call_site_parameter
13616 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13618 /* Already printed the complaint above. */
13622 gdb_assert (call_site
->parameter_count
< nparams
);
13623 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13625 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13626 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13627 register is contained in DW_AT_call_value. */
13629 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13630 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13631 if (origin
== NULL
)
13633 /* This was a pre-DWARF-5 GNU extension alias
13634 for DW_AT_call_parameter. */
13635 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13637 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13639 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13641 sect_offset sect_off
= origin
->get_ref_die_offset ();
13642 if (!cu
->header
.offset_in_cu_p (sect_off
))
13644 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13645 binding can be done only inside one CU. Such referenced DIE
13646 therefore cannot be even moved to DW_TAG_partial_unit. */
13647 complaint (_("DW_AT_call_parameter offset is not in CU for "
13648 "DW_TAG_call_site child DIE %s [in module %s]"),
13649 sect_offset_str (child_die
->sect_off
),
13650 objfile_name (objfile
));
13653 parameter
->u
.param_cu_off
13654 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13656 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13658 complaint (_("No DW_FORM_block* DW_AT_location for "
13659 "DW_TAG_call_site child DIE %s [in module %s]"),
13660 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13665 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13666 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13667 if (parameter
->u
.dwarf_reg
!= -1)
13668 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13669 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13670 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13671 ¶meter
->u
.fb_offset
))
13672 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13675 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13676 "for DW_FORM_block* DW_AT_location is supported for "
13677 "DW_TAG_call_site child DIE %s "
13679 sect_offset_str (child_die
->sect_off
),
13680 objfile_name (objfile
));
13685 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13687 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13688 if (attr
== NULL
|| !attr
->form_is_block ())
13690 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13691 "DW_TAG_call_site child DIE %s [in module %s]"),
13692 sect_offset_str (child_die
->sect_off
),
13693 objfile_name (objfile
));
13696 parameter
->value
= DW_BLOCK (attr
)->data
;
13697 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13699 /* Parameters are not pre-cleared by memset above. */
13700 parameter
->data_value
= NULL
;
13701 parameter
->data_value_size
= 0;
13702 call_site
->parameter_count
++;
13704 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13706 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13707 if (attr
!= nullptr)
13709 if (!attr
->form_is_block ())
13710 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13711 "DW_TAG_call_site child DIE %s [in module %s]"),
13712 sect_offset_str (child_die
->sect_off
),
13713 objfile_name (objfile
));
13716 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13717 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13723 /* Helper function for read_variable. If DIE represents a virtual
13724 table, then return the type of the concrete object that is
13725 associated with the virtual table. Otherwise, return NULL. */
13727 static struct type
*
13728 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13730 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13734 /* Find the type DIE. */
13735 struct die_info
*type_die
= NULL
;
13736 struct dwarf2_cu
*type_cu
= cu
;
13738 if (attr
->form_is_ref ())
13739 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13740 if (type_die
== NULL
)
13743 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13745 return die_containing_type (type_die
, type_cu
);
13748 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13751 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13753 struct rust_vtable_symbol
*storage
= NULL
;
13755 if (cu
->language
== language_rust
)
13757 struct type
*containing_type
= rust_containing_type (die
, cu
);
13759 if (containing_type
!= NULL
)
13761 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13763 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13764 storage
->concrete_type
= containing_type
;
13765 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13769 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13770 struct attribute
*abstract_origin
13771 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13772 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13773 if (res
== NULL
&& loc
&& abstract_origin
)
13775 /* We have a variable without a name, but with a location and an abstract
13776 origin. This may be a concrete instance of an abstract variable
13777 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13779 struct dwarf2_cu
*origin_cu
= cu
;
13780 struct die_info
*origin_die
13781 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13782 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13783 per_objfile
->per_bfd
->abstract_to_concrete
13784 [origin_die
->sect_off
].push_back (die
->sect_off
);
13788 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13789 reading .debug_rnglists.
13790 Callback's type should be:
13791 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13792 Return true if the attributes are present and valid, otherwise,
13795 template <typename Callback
>
13797 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13798 Callback
&&callback
)
13800 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
13801 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13802 bfd
*obfd
= objfile
->obfd
;
13803 /* Base address selection entry. */
13804 gdb::optional
<CORE_ADDR
> base
;
13805 const gdb_byte
*buffer
;
13806 CORE_ADDR baseaddr
;
13807 bool overflow
= false;
13809 base
= cu
->base_address
;
13811 dwarf2_per_objfile
->per_bfd
->rnglists
.read (objfile
);
13812 if (offset
>= dwarf2_per_objfile
->per_bfd
->rnglists
.size
)
13814 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13818 buffer
= dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13820 baseaddr
= objfile
->text_section_offset ();
13824 /* Initialize it due to a false compiler warning. */
13825 CORE_ADDR range_beginning
= 0, range_end
= 0;
13826 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
13827 + dwarf2_per_objfile
->per_bfd
->rnglists
.size
);
13828 unsigned int bytes_read
;
13830 if (buffer
== buf_end
)
13835 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13838 case DW_RLE_end_of_list
:
13840 case DW_RLE_base_address
:
13841 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13846 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13847 buffer
+= bytes_read
;
13849 case DW_RLE_start_length
:
13850 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13855 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13857 buffer
+= bytes_read
;
13858 range_end
= (range_beginning
13859 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13860 buffer
+= bytes_read
;
13861 if (buffer
> buf_end
)
13867 case DW_RLE_offset_pair
:
13868 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13869 buffer
+= bytes_read
;
13870 if (buffer
> buf_end
)
13875 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13876 buffer
+= bytes_read
;
13877 if (buffer
> buf_end
)
13883 case DW_RLE_start_end
:
13884 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13889 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13891 buffer
+= bytes_read
;
13892 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13893 buffer
+= bytes_read
;
13896 complaint (_("Invalid .debug_rnglists data (no base address)"));
13899 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13901 if (rlet
== DW_RLE_base_address
)
13904 if (!base
.has_value ())
13906 /* We have no valid base address for the ranges
13908 complaint (_("Invalid .debug_rnglists data (no base address)"));
13912 if (range_beginning
> range_end
)
13914 /* Inverted range entries are invalid. */
13915 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13919 /* Empty range entries have no effect. */
13920 if (range_beginning
== range_end
)
13923 range_beginning
+= *base
;
13924 range_end
+= *base
;
13926 /* A not-uncommon case of bad debug info.
13927 Don't pollute the addrmap with bad data. */
13928 if (range_beginning
+ baseaddr
== 0
13929 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
13931 complaint (_(".debug_rnglists entry has start address of zero"
13932 " [in module %s]"), objfile_name (objfile
));
13936 callback (range_beginning
, range_end
);
13941 complaint (_("Offset %d is not terminated "
13942 "for DW_AT_ranges attribute"),
13950 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13951 Callback's type should be:
13952 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13953 Return 1 if the attributes are present and valid, otherwise, return 0. */
13955 template <typename Callback
>
13957 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13958 Callback
&&callback
)
13960 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13961 struct objfile
*objfile
= per_objfile
->objfile
;
13962 struct comp_unit_head
*cu_header
= &cu
->header
;
13963 bfd
*obfd
= objfile
->obfd
;
13964 unsigned int addr_size
= cu_header
->addr_size
;
13965 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13966 /* Base address selection entry. */
13967 gdb::optional
<CORE_ADDR
> base
;
13968 unsigned int dummy
;
13969 const gdb_byte
*buffer
;
13970 CORE_ADDR baseaddr
;
13972 if (cu_header
->version
>= 5)
13973 return dwarf2_rnglists_process (offset
, cu
, callback
);
13975 base
= cu
->base_address
;
13977 per_objfile
->per_bfd
->ranges
.read (objfile
);
13978 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13980 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13984 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13986 baseaddr
= objfile
->text_section_offset ();
13990 CORE_ADDR range_beginning
, range_end
;
13992 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13993 buffer
+= addr_size
;
13994 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13995 buffer
+= addr_size
;
13996 offset
+= 2 * addr_size
;
13998 /* An end of list marker is a pair of zero addresses. */
13999 if (range_beginning
== 0 && range_end
== 0)
14000 /* Found the end of list entry. */
14003 /* Each base address selection entry is a pair of 2 values.
14004 The first is the largest possible address, the second is
14005 the base address. Check for a base address here. */
14006 if ((range_beginning
& mask
) == mask
)
14008 /* If we found the largest possible address, then we already
14009 have the base address in range_end. */
14014 if (!base
.has_value ())
14016 /* We have no valid base address for the ranges
14018 complaint (_("Invalid .debug_ranges data (no base address)"));
14022 if (range_beginning
> range_end
)
14024 /* Inverted range entries are invalid. */
14025 complaint (_("Invalid .debug_ranges data (inverted range)"));
14029 /* Empty range entries have no effect. */
14030 if (range_beginning
== range_end
)
14033 range_beginning
+= *base
;
14034 range_end
+= *base
;
14036 /* A not-uncommon case of bad debug info.
14037 Don't pollute the addrmap with bad data. */
14038 if (range_beginning
+ baseaddr
== 0
14039 && !per_objfile
->per_bfd
->has_section_at_zero
)
14041 complaint (_(".debug_ranges entry has start address of zero"
14042 " [in module %s]"), objfile_name (objfile
));
14046 callback (range_beginning
, range_end
);
14052 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14053 Return 1 if the attributes are present and valid, otherwise, return 0.
14054 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14057 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14058 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14059 dwarf2_psymtab
*ranges_pst
)
14061 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14062 struct gdbarch
*gdbarch
= objfile
->arch ();
14063 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14066 CORE_ADDR high
= 0;
14069 retval
= dwarf2_ranges_process (offset
, cu
,
14070 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14072 if (ranges_pst
!= NULL
)
14077 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14078 range_beginning
+ baseaddr
)
14080 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14081 range_end
+ baseaddr
)
14083 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14084 lowpc
, highpc
- 1, ranges_pst
);
14087 /* FIXME: This is recording everything as a low-high
14088 segment of consecutive addresses. We should have a
14089 data structure for discontiguous block ranges
14093 low
= range_beginning
;
14099 if (range_beginning
< low
)
14100 low
= range_beginning
;
14101 if (range_end
> high
)
14109 /* If the first entry is an end-of-list marker, the range
14110 describes an empty scope, i.e. no instructions. */
14116 *high_return
= high
;
14120 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14121 definition for the return value. *LOWPC and *HIGHPC are set iff
14122 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14124 static enum pc_bounds_kind
14125 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14126 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14127 dwarf2_psymtab
*pst
)
14129 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
14130 struct attribute
*attr
;
14131 struct attribute
*attr_high
;
14133 CORE_ADDR high
= 0;
14134 enum pc_bounds_kind ret
;
14136 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14139 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14140 if (attr
!= nullptr)
14142 low
= attr
->value_as_address ();
14143 high
= attr_high
->value_as_address ();
14144 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14148 /* Found high w/o low attribute. */
14149 return PC_BOUNDS_INVALID
;
14151 /* Found consecutive range of addresses. */
14152 ret
= PC_BOUNDS_HIGH_LOW
;
14156 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14159 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14160 We take advantage of the fact that DW_AT_ranges does not appear
14161 in DW_TAG_compile_unit of DWO files. */
14162 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14163 unsigned int ranges_offset
= (DW_UNSND (attr
)
14164 + (need_ranges_base
14168 /* Value of the DW_AT_ranges attribute is the offset in the
14169 .debug_ranges section. */
14170 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14171 return PC_BOUNDS_INVALID
;
14172 /* Found discontinuous range of addresses. */
14173 ret
= PC_BOUNDS_RANGES
;
14176 return PC_BOUNDS_NOT_PRESENT
;
14179 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14181 return PC_BOUNDS_INVALID
;
14183 /* When using the GNU linker, .gnu.linkonce. sections are used to
14184 eliminate duplicate copies of functions and vtables and such.
14185 The linker will arbitrarily choose one and discard the others.
14186 The AT_*_pc values for such functions refer to local labels in
14187 these sections. If the section from that file was discarded, the
14188 labels are not in the output, so the relocs get a value of 0.
14189 If this is a discarded function, mark the pc bounds as invalid,
14190 so that GDB will ignore it. */
14191 if (low
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
14192 return PC_BOUNDS_INVALID
;
14200 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14201 its low and high PC addresses. Do nothing if these addresses could not
14202 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14203 and HIGHPC to the high address if greater than HIGHPC. */
14206 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14207 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14208 struct dwarf2_cu
*cu
)
14210 CORE_ADDR low
, high
;
14211 struct die_info
*child
= die
->child
;
14213 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14215 *lowpc
= std::min (*lowpc
, low
);
14216 *highpc
= std::max (*highpc
, high
);
14219 /* If the language does not allow nested subprograms (either inside
14220 subprograms or lexical blocks), we're done. */
14221 if (cu
->language
!= language_ada
)
14224 /* Check all the children of the given DIE. If it contains nested
14225 subprograms, then check their pc bounds. Likewise, we need to
14226 check lexical blocks as well, as they may also contain subprogram
14228 while (child
&& child
->tag
)
14230 if (child
->tag
== DW_TAG_subprogram
14231 || child
->tag
== DW_TAG_lexical_block
)
14232 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14233 child
= child
->sibling
;
14237 /* Get the low and high pc's represented by the scope DIE, and store
14238 them in *LOWPC and *HIGHPC. If the correct values can't be
14239 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14242 get_scope_pc_bounds (struct die_info
*die
,
14243 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14244 struct dwarf2_cu
*cu
)
14246 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14247 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14248 CORE_ADDR current_low
, current_high
;
14250 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14251 >= PC_BOUNDS_RANGES
)
14253 best_low
= current_low
;
14254 best_high
= current_high
;
14258 struct die_info
*child
= die
->child
;
14260 while (child
&& child
->tag
)
14262 switch (child
->tag
) {
14263 case DW_TAG_subprogram
:
14264 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14266 case DW_TAG_namespace
:
14267 case DW_TAG_module
:
14268 /* FIXME: carlton/2004-01-16: Should we do this for
14269 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14270 that current GCC's always emit the DIEs corresponding
14271 to definitions of methods of classes as children of a
14272 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14273 the DIEs giving the declarations, which could be
14274 anywhere). But I don't see any reason why the
14275 standards says that they have to be there. */
14276 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14278 if (current_low
!= ((CORE_ADDR
) -1))
14280 best_low
= std::min (best_low
, current_low
);
14281 best_high
= std::max (best_high
, current_high
);
14289 child
= child
->sibling
;
14294 *highpc
= best_high
;
14297 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14301 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14302 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14304 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14305 struct gdbarch
*gdbarch
= objfile
->arch ();
14306 struct attribute
*attr
;
14307 struct attribute
*attr_high
;
14309 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14312 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14313 if (attr
!= nullptr)
14315 CORE_ADDR low
= attr
->value_as_address ();
14316 CORE_ADDR high
= attr_high
->value_as_address ();
14318 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14321 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14322 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14323 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14327 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14328 if (attr
!= nullptr)
14330 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14331 We take advantage of the fact that DW_AT_ranges does not appear
14332 in DW_TAG_compile_unit of DWO files. */
14333 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14335 /* The value of the DW_AT_ranges attribute is the offset of the
14336 address range list in the .debug_ranges section. */
14337 unsigned long offset
= (DW_UNSND (attr
)
14338 + (need_ranges_base
? cu
->ranges_base
: 0));
14340 std::vector
<blockrange
> blockvec
;
14341 dwarf2_ranges_process (offset
, cu
,
14342 [&] (CORE_ADDR start
, CORE_ADDR end
)
14346 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14347 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14348 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14349 blockvec
.emplace_back (start
, end
);
14352 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14356 /* Check whether the producer field indicates either of GCC < 4.6, or the
14357 Intel C/C++ compiler, and cache the result in CU. */
14360 check_producer (struct dwarf2_cu
*cu
)
14364 if (cu
->producer
== NULL
)
14366 /* For unknown compilers expect their behavior is DWARF version
14369 GCC started to support .debug_types sections by -gdwarf-4 since
14370 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14371 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14372 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14373 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14375 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14377 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14378 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14380 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14382 cu
->producer_is_icc
= true;
14383 cu
->producer_is_icc_lt_14
= major
< 14;
14385 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14386 cu
->producer_is_codewarrior
= true;
14389 /* For other non-GCC compilers, expect their behavior is DWARF version
14393 cu
->checked_producer
= true;
14396 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14397 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14398 during 4.6.0 experimental. */
14401 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14403 if (!cu
->checked_producer
)
14404 check_producer (cu
);
14406 return cu
->producer_is_gxx_lt_4_6
;
14410 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14411 with incorrect is_stmt attributes. */
14414 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14416 if (!cu
->checked_producer
)
14417 check_producer (cu
);
14419 return cu
->producer_is_codewarrior
;
14422 /* Return the default accessibility type if it is not overridden by
14423 DW_AT_accessibility. */
14425 static enum dwarf_access_attribute
14426 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14428 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14430 /* The default DWARF 2 accessibility for members is public, the default
14431 accessibility for inheritance is private. */
14433 if (die
->tag
!= DW_TAG_inheritance
)
14434 return DW_ACCESS_public
;
14436 return DW_ACCESS_private
;
14440 /* DWARF 3+ defines the default accessibility a different way. The same
14441 rules apply now for DW_TAG_inheritance as for the members and it only
14442 depends on the container kind. */
14444 if (die
->parent
->tag
== DW_TAG_class_type
)
14445 return DW_ACCESS_private
;
14447 return DW_ACCESS_public
;
14451 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14452 offset. If the attribute was not found return 0, otherwise return
14453 1. If it was found but could not properly be handled, set *OFFSET
14457 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14460 struct attribute
*attr
;
14462 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14467 /* Note that we do not check for a section offset first here.
14468 This is because DW_AT_data_member_location is new in DWARF 4,
14469 so if we see it, we can assume that a constant form is really
14470 a constant and not a section offset. */
14471 if (attr
->form_is_constant ())
14472 *offset
= attr
->constant_value (0);
14473 else if (attr
->form_is_section_offset ())
14474 dwarf2_complex_location_expr_complaint ();
14475 else if (attr
->form_is_block ())
14476 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14478 dwarf2_complex_location_expr_complaint ();
14486 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14489 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14490 struct field
*field
)
14492 struct attribute
*attr
;
14494 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14497 if (attr
->form_is_constant ())
14499 LONGEST offset
= attr
->constant_value (0);
14500 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14502 else if (attr
->form_is_section_offset ())
14503 dwarf2_complex_location_expr_complaint ();
14504 else if (attr
->form_is_block ())
14507 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14509 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14512 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14513 struct objfile
*objfile
= per_objfile
->objfile
;
14514 struct dwarf2_locexpr_baton
*dlbaton
14515 = XOBNEW (&objfile
->objfile_obstack
,
14516 struct dwarf2_locexpr_baton
);
14517 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14518 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14519 /* When using this baton, we want to compute the address
14520 of the field, not the value. This is why
14521 is_reference is set to false here. */
14522 dlbaton
->is_reference
= false;
14523 dlbaton
->per_objfile
= per_objfile
;
14524 dlbaton
->per_cu
= cu
->per_cu
;
14526 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14530 dwarf2_complex_location_expr_complaint ();
14534 /* Add an aggregate field to the field list. */
14537 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14538 struct dwarf2_cu
*cu
)
14540 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14541 struct gdbarch
*gdbarch
= objfile
->arch ();
14542 struct nextfield
*new_field
;
14543 struct attribute
*attr
;
14545 const char *fieldname
= "";
14547 if (die
->tag
== DW_TAG_inheritance
)
14549 fip
->baseclasses
.emplace_back ();
14550 new_field
= &fip
->baseclasses
.back ();
14554 fip
->fields
.emplace_back ();
14555 new_field
= &fip
->fields
.back ();
14558 new_field
->offset
= die
->sect_off
;
14560 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14561 if (attr
!= nullptr)
14562 new_field
->accessibility
= DW_UNSND (attr
);
14564 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14565 if (new_field
->accessibility
!= DW_ACCESS_public
)
14566 fip
->non_public_fields
= 1;
14568 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14569 if (attr
!= nullptr)
14570 new_field
->virtuality
= DW_UNSND (attr
);
14572 new_field
->virtuality
= DW_VIRTUALITY_none
;
14574 fp
= &new_field
->field
;
14576 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14578 /* Data member other than a C++ static data member. */
14580 /* Get type of field. */
14581 fp
->type
= die_type (die
, cu
);
14583 SET_FIELD_BITPOS (*fp
, 0);
14585 /* Get bit size of field (zero if none). */
14586 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14587 if (attr
!= nullptr)
14589 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14593 FIELD_BITSIZE (*fp
) = 0;
14596 /* Get bit offset of field. */
14597 handle_data_member_location (die
, cu
, fp
);
14598 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14599 if (attr
!= nullptr)
14601 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14603 /* For big endian bits, the DW_AT_bit_offset gives the
14604 additional bit offset from the MSB of the containing
14605 anonymous object to the MSB of the field. We don't
14606 have to do anything special since we don't need to
14607 know the size of the anonymous object. */
14608 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14612 /* For little endian bits, compute the bit offset to the
14613 MSB of the anonymous object, subtract off the number of
14614 bits from the MSB of the field to the MSB of the
14615 object, and then subtract off the number of bits of
14616 the field itself. The result is the bit offset of
14617 the LSB of the field. */
14618 int anonymous_size
;
14619 int bit_offset
= DW_UNSND (attr
);
14621 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14622 if (attr
!= nullptr)
14624 /* The size of the anonymous object containing
14625 the bit field is explicit, so use the
14626 indicated size (in bytes). */
14627 anonymous_size
= DW_UNSND (attr
);
14631 /* The size of the anonymous object containing
14632 the bit field must be inferred from the type
14633 attribute of the data member containing the
14635 anonymous_size
= TYPE_LENGTH (fp
->type
);
14637 SET_FIELD_BITPOS (*fp
,
14638 (FIELD_BITPOS (*fp
)
14639 + anonymous_size
* bits_per_byte
14640 - bit_offset
- FIELD_BITSIZE (*fp
)));
14643 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14645 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14646 + attr
->constant_value (0)));
14648 /* Get name of field. */
14649 fieldname
= dwarf2_name (die
, cu
);
14650 if (fieldname
== NULL
)
14653 /* The name is already allocated along with this objfile, so we don't
14654 need to duplicate it for the type. */
14655 fp
->name
= fieldname
;
14657 /* Change accessibility for artificial fields (e.g. virtual table
14658 pointer or virtual base class pointer) to private. */
14659 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14661 FIELD_ARTIFICIAL (*fp
) = 1;
14662 new_field
->accessibility
= DW_ACCESS_private
;
14663 fip
->non_public_fields
= 1;
14666 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14668 /* C++ static member. */
14670 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14671 is a declaration, but all versions of G++ as of this writing
14672 (so through at least 3.2.1) incorrectly generate
14673 DW_TAG_variable tags. */
14675 const char *physname
;
14677 /* Get name of field. */
14678 fieldname
= dwarf2_name (die
, cu
);
14679 if (fieldname
== NULL
)
14682 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14684 /* Only create a symbol if this is an external value.
14685 new_symbol checks this and puts the value in the global symbol
14686 table, which we want. If it is not external, new_symbol
14687 will try to put the value in cu->list_in_scope which is wrong. */
14688 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14690 /* A static const member, not much different than an enum as far as
14691 we're concerned, except that we can support more types. */
14692 new_symbol (die
, NULL
, cu
);
14695 /* Get physical name. */
14696 physname
= dwarf2_physname (fieldname
, die
, cu
);
14698 /* The name is already allocated along with this objfile, so we don't
14699 need to duplicate it for the type. */
14700 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14701 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14702 FIELD_NAME (*fp
) = fieldname
;
14704 else if (die
->tag
== DW_TAG_inheritance
)
14706 /* C++ base class field. */
14707 handle_data_member_location (die
, cu
, fp
);
14708 FIELD_BITSIZE (*fp
) = 0;
14709 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14710 FIELD_NAME (*fp
) = fp
->type
->name ();
14713 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14716 /* Can the type given by DIE define another type? */
14719 type_can_define_types (const struct die_info
*die
)
14723 case DW_TAG_typedef
:
14724 case DW_TAG_class_type
:
14725 case DW_TAG_structure_type
:
14726 case DW_TAG_union_type
:
14727 case DW_TAG_enumeration_type
:
14735 /* Add a type definition defined in the scope of the FIP's class. */
14738 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14739 struct dwarf2_cu
*cu
)
14741 struct decl_field fp
;
14742 memset (&fp
, 0, sizeof (fp
));
14744 gdb_assert (type_can_define_types (die
));
14746 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14747 fp
.name
= dwarf2_name (die
, cu
);
14748 fp
.type
= read_type_die (die
, cu
);
14750 /* Save accessibility. */
14751 enum dwarf_access_attribute accessibility
;
14752 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14754 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14756 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14757 switch (accessibility
)
14759 case DW_ACCESS_public
:
14760 /* The assumed value if neither private nor protected. */
14762 case DW_ACCESS_private
:
14765 case DW_ACCESS_protected
:
14766 fp
.is_protected
= 1;
14769 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14772 if (die
->tag
== DW_TAG_typedef
)
14773 fip
->typedef_field_list
.push_back (fp
);
14775 fip
->nested_types_list
.push_back (fp
);
14778 /* A convenience typedef that's used when finding the discriminant
14779 field for a variant part. */
14780 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14783 /* Compute the discriminant range for a given variant. OBSTACK is
14784 where the results will be stored. VARIANT is the variant to
14785 process. IS_UNSIGNED indicates whether the discriminant is signed
14788 static const gdb::array_view
<discriminant_range
>
14789 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14792 std::vector
<discriminant_range
> ranges
;
14794 if (variant
.default_branch
)
14797 if (variant
.discr_list_data
== nullptr)
14799 discriminant_range r
14800 = {variant
.discriminant_value
, variant
.discriminant_value
};
14801 ranges
.push_back (r
);
14805 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14806 variant
.discr_list_data
->size
);
14807 while (!data
.empty ())
14809 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14811 complaint (_("invalid discriminant marker: %d"), data
[0]);
14814 bool is_range
= data
[0] == DW_DSC_range
;
14815 data
= data
.slice (1);
14817 ULONGEST low
, high
;
14818 unsigned int bytes_read
;
14822 complaint (_("DW_AT_discr_list missing low value"));
14826 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14828 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14830 data
= data
.slice (bytes_read
);
14836 complaint (_("DW_AT_discr_list missing high value"));
14840 high
= read_unsigned_leb128 (nullptr, data
.data (),
14843 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14845 data
= data
.slice (bytes_read
);
14850 ranges
.push_back ({ low
, high
});
14854 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14856 std::copy (ranges
.begin (), ranges
.end (), result
);
14857 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14860 static const gdb::array_view
<variant_part
> create_variant_parts
14861 (struct obstack
*obstack
,
14862 const offset_map_type
&offset_map
,
14863 struct field_info
*fi
,
14864 const std::vector
<variant_part_builder
> &variant_parts
);
14866 /* Fill in a "struct variant" for a given variant field. RESULT is
14867 the variant to fill in. OBSTACK is where any needed allocations
14868 will be done. OFFSET_MAP holds the mapping from section offsets to
14869 fields for the type. FI describes the fields of the type we're
14870 processing. FIELD is the variant field we're converting. */
14873 create_one_variant (variant
&result
, struct obstack
*obstack
,
14874 const offset_map_type
&offset_map
,
14875 struct field_info
*fi
, const variant_field
&field
)
14877 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14878 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14879 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14880 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14881 field
.variant_parts
);
14884 /* Fill in a "struct variant_part" for a given variant part. RESULT
14885 is the variant part to fill in. OBSTACK is where any needed
14886 allocations will be done. OFFSET_MAP holds the mapping from
14887 section offsets to fields for the type. FI describes the fields of
14888 the type we're processing. BUILDER is the variant part to be
14892 create_one_variant_part (variant_part
&result
,
14893 struct obstack
*obstack
,
14894 const offset_map_type
&offset_map
,
14895 struct field_info
*fi
,
14896 const variant_part_builder
&builder
)
14898 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14899 if (iter
== offset_map
.end ())
14901 result
.discriminant_index
= -1;
14902 /* Doesn't matter. */
14903 result
.is_unsigned
= false;
14907 result
.discriminant_index
= iter
->second
;
14909 = TYPE_UNSIGNED (FIELD_TYPE
14910 (fi
->fields
[result
.discriminant_index
].field
));
14913 size_t n
= builder
.variants
.size ();
14914 variant
*output
= new (obstack
) variant
[n
];
14915 for (size_t i
= 0; i
< n
; ++i
)
14916 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14917 builder
.variants
[i
]);
14919 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14922 /* Create a vector of variant parts that can be attached to a type.
14923 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14924 holds the mapping from section offsets to fields for the type. FI
14925 describes the fields of the type we're processing. VARIANT_PARTS
14926 is the vector to convert. */
14928 static const gdb::array_view
<variant_part
>
14929 create_variant_parts (struct obstack
*obstack
,
14930 const offset_map_type
&offset_map
,
14931 struct field_info
*fi
,
14932 const std::vector
<variant_part_builder
> &variant_parts
)
14934 if (variant_parts
.empty ())
14937 size_t n
= variant_parts
.size ();
14938 variant_part
*result
= new (obstack
) variant_part
[n
];
14939 for (size_t i
= 0; i
< n
; ++i
)
14940 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14943 return gdb::array_view
<variant_part
> (result
, n
);
14946 /* Compute the variant part vector for FIP, attaching it to TYPE when
14950 add_variant_property (struct field_info
*fip
, struct type
*type
,
14951 struct dwarf2_cu
*cu
)
14953 /* Map section offsets of fields to their field index. Note the
14954 field index here does not take the number of baseclasses into
14956 offset_map_type offset_map
;
14957 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14958 offset_map
[fip
->fields
[i
].offset
] = i
;
14960 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14961 gdb::array_view
<variant_part
> parts
14962 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14963 fip
->variant_parts
);
14965 struct dynamic_prop prop
;
14966 prop
.kind
= PROP_VARIANT_PARTS
;
14967 prop
.data
.variant_parts
14968 = ((gdb::array_view
<variant_part
> *)
14969 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14971 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14974 /* Create the vector of fields, and attach it to the type. */
14977 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14978 struct dwarf2_cu
*cu
)
14980 int nfields
= fip
->nfields ();
14982 /* Record the field count, allocate space for the array of fields,
14983 and create blank accessibility bitfields if necessary. */
14984 type
->set_num_fields (nfields
);
14986 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14988 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14990 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14992 TYPE_FIELD_PRIVATE_BITS (type
) =
14993 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14994 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14996 TYPE_FIELD_PROTECTED_BITS (type
) =
14997 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14998 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15000 TYPE_FIELD_IGNORE_BITS (type
) =
15001 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15002 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15005 /* If the type has baseclasses, allocate and clear a bit vector for
15006 TYPE_FIELD_VIRTUAL_BITS. */
15007 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15009 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15010 unsigned char *pointer
;
15012 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15013 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15014 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15015 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15016 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15019 if (!fip
->variant_parts
.empty ())
15020 add_variant_property (fip
, type
, cu
);
15022 /* Copy the saved-up fields into the field vector. */
15023 for (int i
= 0; i
< nfields
; ++i
)
15025 struct nextfield
&field
15026 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15027 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15029 type
->field (i
) = field
.field
;
15030 switch (field
.accessibility
)
15032 case DW_ACCESS_private
:
15033 if (cu
->language
!= language_ada
)
15034 SET_TYPE_FIELD_PRIVATE (type
, i
);
15037 case DW_ACCESS_protected
:
15038 if (cu
->language
!= language_ada
)
15039 SET_TYPE_FIELD_PROTECTED (type
, i
);
15042 case DW_ACCESS_public
:
15046 /* Unknown accessibility. Complain and treat it as public. */
15048 complaint (_("unsupported accessibility %d"),
15049 field
.accessibility
);
15053 if (i
< fip
->baseclasses
.size ())
15055 switch (field
.virtuality
)
15057 case DW_VIRTUALITY_virtual
:
15058 case DW_VIRTUALITY_pure_virtual
:
15059 if (cu
->language
== language_ada
)
15060 error (_("unexpected virtuality in component of Ada type"));
15061 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15068 /* Return true if this member function is a constructor, false
15072 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15074 const char *fieldname
;
15075 const char *type_name
;
15078 if (die
->parent
== NULL
)
15081 if (die
->parent
->tag
!= DW_TAG_structure_type
15082 && die
->parent
->tag
!= DW_TAG_union_type
15083 && die
->parent
->tag
!= DW_TAG_class_type
)
15086 fieldname
= dwarf2_name (die
, cu
);
15087 type_name
= dwarf2_name (die
->parent
, cu
);
15088 if (fieldname
== NULL
|| type_name
== NULL
)
15091 len
= strlen (fieldname
);
15092 return (strncmp (fieldname
, type_name
, len
) == 0
15093 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15096 /* Check if the given VALUE is a recognized enum
15097 dwarf_defaulted_attribute constant according to DWARF5 spec,
15101 is_valid_DW_AT_defaulted (ULONGEST value
)
15105 case DW_DEFAULTED_no
:
15106 case DW_DEFAULTED_in_class
:
15107 case DW_DEFAULTED_out_of_class
:
15111 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15115 /* Add a member function to the proper fieldlist. */
15118 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15119 struct type
*type
, struct dwarf2_cu
*cu
)
15121 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15122 struct attribute
*attr
;
15124 struct fnfieldlist
*flp
= nullptr;
15125 struct fn_field
*fnp
;
15126 const char *fieldname
;
15127 struct type
*this_type
;
15128 enum dwarf_access_attribute accessibility
;
15130 if (cu
->language
== language_ada
)
15131 error (_("unexpected member function in Ada type"));
15133 /* Get name of member function. */
15134 fieldname
= dwarf2_name (die
, cu
);
15135 if (fieldname
== NULL
)
15138 /* Look up member function name in fieldlist. */
15139 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15141 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15143 flp
= &fip
->fnfieldlists
[i
];
15148 /* Create a new fnfieldlist if necessary. */
15149 if (flp
== nullptr)
15151 fip
->fnfieldlists
.emplace_back ();
15152 flp
= &fip
->fnfieldlists
.back ();
15153 flp
->name
= fieldname
;
15154 i
= fip
->fnfieldlists
.size () - 1;
15157 /* Create a new member function field and add it to the vector of
15159 flp
->fnfields
.emplace_back ();
15160 fnp
= &flp
->fnfields
.back ();
15162 /* Delay processing of the physname until later. */
15163 if (cu
->language
== language_cplus
)
15164 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15168 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15169 fnp
->physname
= physname
? physname
: "";
15172 fnp
->type
= alloc_type (objfile
);
15173 this_type
= read_type_die (die
, cu
);
15174 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15176 int nparams
= this_type
->num_fields ();
15178 /* TYPE is the domain of this method, and THIS_TYPE is the type
15179 of the method itself (TYPE_CODE_METHOD). */
15180 smash_to_method_type (fnp
->type
, type
,
15181 TYPE_TARGET_TYPE (this_type
),
15182 this_type
->fields (),
15183 this_type
->num_fields (),
15184 TYPE_VARARGS (this_type
));
15186 /* Handle static member functions.
15187 Dwarf2 has no clean way to discern C++ static and non-static
15188 member functions. G++ helps GDB by marking the first
15189 parameter for non-static member functions (which is the this
15190 pointer) as artificial. We obtain this information from
15191 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15192 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15193 fnp
->voffset
= VOFFSET_STATIC
;
15196 complaint (_("member function type missing for '%s'"),
15197 dwarf2_full_name (fieldname
, die
, cu
));
15199 /* Get fcontext from DW_AT_containing_type if present. */
15200 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15201 fnp
->fcontext
= die_containing_type (die
, cu
);
15203 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15204 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15206 /* Get accessibility. */
15207 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15208 if (attr
!= nullptr)
15209 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15211 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15212 switch (accessibility
)
15214 case DW_ACCESS_private
:
15215 fnp
->is_private
= 1;
15217 case DW_ACCESS_protected
:
15218 fnp
->is_protected
= 1;
15222 /* Check for artificial methods. */
15223 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15224 if (attr
&& DW_UNSND (attr
) != 0)
15225 fnp
->is_artificial
= 1;
15227 /* Check for defaulted methods. */
15228 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15229 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15230 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15232 /* Check for deleted methods. */
15233 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15234 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15235 fnp
->is_deleted
= 1;
15237 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15239 /* Get index in virtual function table if it is a virtual member
15240 function. For older versions of GCC, this is an offset in the
15241 appropriate virtual table, as specified by DW_AT_containing_type.
15242 For everyone else, it is an expression to be evaluated relative
15243 to the object address. */
15245 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15246 if (attr
!= nullptr)
15248 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15250 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15252 /* Old-style GCC. */
15253 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15255 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15256 || (DW_BLOCK (attr
)->size
> 1
15257 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15258 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15260 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15261 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15262 dwarf2_complex_location_expr_complaint ();
15264 fnp
->voffset
/= cu
->header
.addr_size
;
15268 dwarf2_complex_location_expr_complaint ();
15270 if (!fnp
->fcontext
)
15272 /* If there is no `this' field and no DW_AT_containing_type,
15273 we cannot actually find a base class context for the
15275 if (this_type
->num_fields () == 0
15276 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15278 complaint (_("cannot determine context for virtual member "
15279 "function \"%s\" (offset %s)"),
15280 fieldname
, sect_offset_str (die
->sect_off
));
15285 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15289 else if (attr
->form_is_section_offset ())
15291 dwarf2_complex_location_expr_complaint ();
15295 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15301 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15302 if (attr
&& DW_UNSND (attr
))
15304 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15305 complaint (_("Member function \"%s\" (offset %s) is virtual "
15306 "but the vtable offset is not specified"),
15307 fieldname
, sect_offset_str (die
->sect_off
));
15308 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15309 TYPE_CPLUS_DYNAMIC (type
) = 1;
15314 /* Create the vector of member function fields, and attach it to the type. */
15317 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15318 struct dwarf2_cu
*cu
)
15320 if (cu
->language
== language_ada
)
15321 error (_("unexpected member functions in Ada type"));
15323 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15324 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15326 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15328 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15330 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15331 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15333 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15334 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15335 fn_flp
->fn_fields
= (struct fn_field
*)
15336 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15338 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15339 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15342 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15345 /* Returns non-zero if NAME is the name of a vtable member in CU's
15346 language, zero otherwise. */
15348 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15350 static const char vptr
[] = "_vptr";
15352 /* Look for the C++ form of the vtable. */
15353 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15359 /* GCC outputs unnamed structures that are really pointers to member
15360 functions, with the ABI-specified layout. If TYPE describes
15361 such a structure, smash it into a member function type.
15363 GCC shouldn't do this; it should just output pointer to member DIEs.
15364 This is GCC PR debug/28767. */
15367 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15369 struct type
*pfn_type
, *self_type
, *new_type
;
15371 /* Check for a structure with no name and two children. */
15372 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15375 /* Check for __pfn and __delta members. */
15376 if (TYPE_FIELD_NAME (type
, 0) == NULL
15377 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15378 || TYPE_FIELD_NAME (type
, 1) == NULL
15379 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15382 /* Find the type of the method. */
15383 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15384 if (pfn_type
== NULL
15385 || pfn_type
->code () != TYPE_CODE_PTR
15386 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15389 /* Look for the "this" argument. */
15390 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15391 if (pfn_type
->num_fields () == 0
15392 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15393 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15396 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15397 new_type
= alloc_type (objfile
);
15398 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15399 pfn_type
->fields (), pfn_type
->num_fields (),
15400 TYPE_VARARGS (pfn_type
));
15401 smash_to_methodptr_type (type
, new_type
);
15404 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15405 appropriate error checking and issuing complaints if there is a
15409 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15411 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15413 if (attr
== nullptr)
15416 if (!attr
->form_is_constant ())
15418 complaint (_("DW_AT_alignment must have constant form"
15419 " - DIE at %s [in module %s]"),
15420 sect_offset_str (die
->sect_off
),
15421 objfile_name (cu
->per_objfile
->objfile
));
15426 if (attr
->form
== DW_FORM_sdata
)
15428 LONGEST val
= DW_SND (attr
);
15431 complaint (_("DW_AT_alignment value must not be negative"
15432 " - DIE at %s [in module %s]"),
15433 sect_offset_str (die
->sect_off
),
15434 objfile_name (cu
->per_objfile
->objfile
));
15440 align
= DW_UNSND (attr
);
15444 complaint (_("DW_AT_alignment value must not be zero"
15445 " - DIE at %s [in module %s]"),
15446 sect_offset_str (die
->sect_off
),
15447 objfile_name (cu
->per_objfile
->objfile
));
15450 if ((align
& (align
- 1)) != 0)
15452 complaint (_("DW_AT_alignment value must be a power of 2"
15453 " - DIE at %s [in module %s]"),
15454 sect_offset_str (die
->sect_off
),
15455 objfile_name (cu
->per_objfile
->objfile
));
15462 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15463 the alignment for TYPE. */
15466 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15469 if (!set_type_align (type
, get_alignment (cu
, die
)))
15470 complaint (_("DW_AT_alignment value too large"
15471 " - DIE at %s [in module %s]"),
15472 sect_offset_str (die
->sect_off
),
15473 objfile_name (cu
->per_objfile
->objfile
));
15476 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15477 constant for a type, according to DWARF5 spec, Table 5.5. */
15480 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15485 case DW_CC_pass_by_reference
:
15486 case DW_CC_pass_by_value
:
15490 complaint (_("unrecognized DW_AT_calling_convention value "
15491 "(%s) for a type"), pulongest (value
));
15496 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15497 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15498 also according to GNU-specific values (see include/dwarf2.h). */
15501 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15506 case DW_CC_program
:
15510 case DW_CC_GNU_renesas_sh
:
15511 case DW_CC_GNU_borland_fastcall_i386
:
15512 case DW_CC_GDB_IBM_OpenCL
:
15516 complaint (_("unrecognized DW_AT_calling_convention value "
15517 "(%s) for a subroutine"), pulongest (value
));
15522 /* Called when we find the DIE that starts a structure or union scope
15523 (definition) to create a type for the structure or union. Fill in
15524 the type's name and general properties; the members will not be
15525 processed until process_structure_scope. A symbol table entry for
15526 the type will also not be done until process_structure_scope (assuming
15527 the type has a name).
15529 NOTE: we need to call these functions regardless of whether or not the
15530 DIE has a DW_AT_name attribute, since it might be an anonymous
15531 structure or union. This gets the type entered into our set of
15532 user defined types. */
15534 static struct type
*
15535 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15537 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15539 struct attribute
*attr
;
15542 /* If the definition of this type lives in .debug_types, read that type.
15543 Don't follow DW_AT_specification though, that will take us back up
15544 the chain and we want to go down. */
15545 attr
= die
->attr (DW_AT_signature
);
15546 if (attr
!= nullptr)
15548 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15550 /* The type's CU may not be the same as CU.
15551 Ensure TYPE is recorded with CU in die_type_hash. */
15552 return set_die_type (die
, type
, cu
);
15555 type
= alloc_type (objfile
);
15556 INIT_CPLUS_SPECIFIC (type
);
15558 name
= dwarf2_name (die
, cu
);
15561 if (cu
->language
== language_cplus
15562 || cu
->language
== language_d
15563 || cu
->language
== language_rust
)
15565 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15567 /* dwarf2_full_name might have already finished building the DIE's
15568 type. If so, there is no need to continue. */
15569 if (get_die_type (die
, cu
) != NULL
)
15570 return get_die_type (die
, cu
);
15572 type
->set_name (full_name
);
15576 /* The name is already allocated along with this objfile, so
15577 we don't need to duplicate it for the type. */
15578 type
->set_name (name
);
15582 if (die
->tag
== DW_TAG_structure_type
)
15584 type
->set_code (TYPE_CODE_STRUCT
);
15586 else if (die
->tag
== DW_TAG_union_type
)
15588 type
->set_code (TYPE_CODE_UNION
);
15592 type
->set_code (TYPE_CODE_STRUCT
);
15595 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15596 TYPE_DECLARED_CLASS (type
) = 1;
15598 /* Store the calling convention in the type if it's available in
15599 the die. Otherwise the calling convention remains set to
15600 the default value DW_CC_normal. */
15601 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15602 if (attr
!= nullptr
15603 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15605 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15606 TYPE_CPLUS_CALLING_CONVENTION (type
)
15607 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15610 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15611 if (attr
!= nullptr)
15613 if (attr
->form_is_constant ())
15614 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15617 struct dynamic_prop prop
;
15618 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15619 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15620 TYPE_LENGTH (type
) = 0;
15625 TYPE_LENGTH (type
) = 0;
15628 maybe_set_alignment (cu
, die
, type
);
15630 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15632 /* ICC<14 does not output the required DW_AT_declaration on
15633 incomplete types, but gives them a size of zero. */
15634 TYPE_STUB (type
) = 1;
15637 TYPE_STUB_SUPPORTED (type
) = 1;
15639 if (die_is_declaration (die
, cu
))
15640 TYPE_STUB (type
) = 1;
15641 else if (attr
== NULL
&& die
->child
== NULL
15642 && producer_is_realview (cu
->producer
))
15643 /* RealView does not output the required DW_AT_declaration
15644 on incomplete types. */
15645 TYPE_STUB (type
) = 1;
15647 /* We need to add the type field to the die immediately so we don't
15648 infinitely recurse when dealing with pointers to the structure
15649 type within the structure itself. */
15650 set_die_type (die
, type
, cu
);
15652 /* set_die_type should be already done. */
15653 set_descriptive_type (type
, die
, cu
);
15658 static void handle_struct_member_die
15659 (struct die_info
*child_die
,
15661 struct field_info
*fi
,
15662 std::vector
<struct symbol
*> *template_args
,
15663 struct dwarf2_cu
*cu
);
15665 /* A helper for handle_struct_member_die that handles
15666 DW_TAG_variant_part. */
15669 handle_variant_part (struct die_info
*die
, struct type
*type
,
15670 struct field_info
*fi
,
15671 std::vector
<struct symbol
*> *template_args
,
15672 struct dwarf2_cu
*cu
)
15674 variant_part_builder
*new_part
;
15675 if (fi
->current_variant_part
== nullptr)
15677 fi
->variant_parts
.emplace_back ();
15678 new_part
= &fi
->variant_parts
.back ();
15680 else if (!fi
->current_variant_part
->processing_variant
)
15682 complaint (_("nested DW_TAG_variant_part seen "
15683 "- DIE at %s [in module %s]"),
15684 sect_offset_str (die
->sect_off
),
15685 objfile_name (cu
->per_objfile
->objfile
));
15690 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15691 current
.variant_parts
.emplace_back ();
15692 new_part
= ¤t
.variant_parts
.back ();
15695 /* When we recurse, we want callees to add to this new variant
15697 scoped_restore save_current_variant_part
15698 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15700 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15703 /* It's a univariant form, an extension we support. */
15705 else if (discr
->form_is_ref ())
15707 struct dwarf2_cu
*target_cu
= cu
;
15708 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15710 new_part
->discriminant_offset
= target_die
->sect_off
;
15714 complaint (_("DW_AT_discr does not have DIE reference form"
15715 " - DIE at %s [in module %s]"),
15716 sect_offset_str (die
->sect_off
),
15717 objfile_name (cu
->per_objfile
->objfile
));
15720 for (die_info
*child_die
= die
->child
;
15722 child_die
= child_die
->sibling
)
15723 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15726 /* A helper for handle_struct_member_die that handles
15730 handle_variant (struct die_info
*die
, struct type
*type
,
15731 struct field_info
*fi
,
15732 std::vector
<struct symbol
*> *template_args
,
15733 struct dwarf2_cu
*cu
)
15735 if (fi
->current_variant_part
== nullptr)
15737 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15738 "- DIE at %s [in module %s]"),
15739 sect_offset_str (die
->sect_off
),
15740 objfile_name (cu
->per_objfile
->objfile
));
15743 if (fi
->current_variant_part
->processing_variant
)
15745 complaint (_("nested DW_TAG_variant seen "
15746 "- DIE at %s [in module %s]"),
15747 sect_offset_str (die
->sect_off
),
15748 objfile_name (cu
->per_objfile
->objfile
));
15752 scoped_restore save_processing_variant
15753 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15756 fi
->current_variant_part
->variants
.emplace_back ();
15757 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15758 variant
.first_field
= fi
->fields
.size ();
15760 /* In a variant we want to get the discriminant and also add a
15761 field for our sole member child. */
15762 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15763 if (discr
== nullptr)
15765 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15766 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15767 variant
.default_branch
= true;
15769 variant
.discr_list_data
= DW_BLOCK (discr
);
15772 variant
.discriminant_value
= DW_UNSND (discr
);
15774 for (die_info
*variant_child
= die
->child
;
15775 variant_child
!= NULL
;
15776 variant_child
= variant_child
->sibling
)
15777 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15779 variant
.last_field
= fi
->fields
.size ();
15782 /* A helper for process_structure_scope that handles a single member
15786 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15787 struct field_info
*fi
,
15788 std::vector
<struct symbol
*> *template_args
,
15789 struct dwarf2_cu
*cu
)
15791 if (child_die
->tag
== DW_TAG_member
15792 || child_die
->tag
== DW_TAG_variable
)
15794 /* NOTE: carlton/2002-11-05: A C++ static data member
15795 should be a DW_TAG_member that is a declaration, but
15796 all versions of G++ as of this writing (so through at
15797 least 3.2.1) incorrectly generate DW_TAG_variable
15798 tags for them instead. */
15799 dwarf2_add_field (fi
, child_die
, cu
);
15801 else if (child_die
->tag
== DW_TAG_subprogram
)
15803 /* Rust doesn't have member functions in the C++ sense.
15804 However, it does emit ordinary functions as children
15805 of a struct DIE. */
15806 if (cu
->language
== language_rust
)
15807 read_func_scope (child_die
, cu
);
15810 /* C++ member function. */
15811 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15814 else if (child_die
->tag
== DW_TAG_inheritance
)
15816 /* C++ base class field. */
15817 dwarf2_add_field (fi
, child_die
, cu
);
15819 else if (type_can_define_types (child_die
))
15820 dwarf2_add_type_defn (fi
, child_die
, cu
);
15821 else if (child_die
->tag
== DW_TAG_template_type_param
15822 || child_die
->tag
== DW_TAG_template_value_param
)
15824 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15827 template_args
->push_back (arg
);
15829 else if (child_die
->tag
== DW_TAG_variant_part
)
15830 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15831 else if (child_die
->tag
== DW_TAG_variant
)
15832 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15835 /* Finish creating a structure or union type, including filling in
15836 its members and creating a symbol for it. */
15839 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15841 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15842 struct die_info
*child_die
;
15845 type
= get_die_type (die
, cu
);
15847 type
= read_structure_type (die
, cu
);
15849 bool has_template_parameters
= false;
15850 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15852 struct field_info fi
;
15853 std::vector
<struct symbol
*> template_args
;
15855 child_die
= die
->child
;
15857 while (child_die
&& child_die
->tag
)
15859 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15860 child_die
= child_die
->sibling
;
15863 /* Attach template arguments to type. */
15864 if (!template_args
.empty ())
15866 has_template_parameters
= true;
15867 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15868 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15869 TYPE_TEMPLATE_ARGUMENTS (type
)
15870 = XOBNEWVEC (&objfile
->objfile_obstack
,
15872 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15873 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15874 template_args
.data (),
15875 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15876 * sizeof (struct symbol
*)));
15879 /* Attach fields and member functions to the type. */
15880 if (fi
.nfields () > 0)
15881 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15882 if (!fi
.fnfieldlists
.empty ())
15884 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15886 /* Get the type which refers to the base class (possibly this
15887 class itself) which contains the vtable pointer for the current
15888 class from the DW_AT_containing_type attribute. This use of
15889 DW_AT_containing_type is a GNU extension. */
15891 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15893 struct type
*t
= die_containing_type (die
, cu
);
15895 set_type_vptr_basetype (type
, t
);
15900 /* Our own class provides vtbl ptr. */
15901 for (i
= t
->num_fields () - 1;
15902 i
>= TYPE_N_BASECLASSES (t
);
15905 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15907 if (is_vtable_name (fieldname
, cu
))
15909 set_type_vptr_fieldno (type
, i
);
15914 /* Complain if virtual function table field not found. */
15915 if (i
< TYPE_N_BASECLASSES (t
))
15916 complaint (_("virtual function table pointer "
15917 "not found when defining class '%s'"),
15918 type
->name () ? type
->name () : "");
15922 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15925 else if (cu
->producer
15926 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15928 /* The IBM XLC compiler does not provide direct indication
15929 of the containing type, but the vtable pointer is
15930 always named __vfp. */
15934 for (i
= type
->num_fields () - 1;
15935 i
>= TYPE_N_BASECLASSES (type
);
15938 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15940 set_type_vptr_fieldno (type
, i
);
15941 set_type_vptr_basetype (type
, type
);
15948 /* Copy fi.typedef_field_list linked list elements content into the
15949 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15950 if (!fi
.typedef_field_list
.empty ())
15952 int count
= fi
.typedef_field_list
.size ();
15954 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15955 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15956 = ((struct decl_field
*)
15958 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15959 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15961 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15962 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15965 /* Copy fi.nested_types_list linked list elements content into the
15966 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15967 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15969 int count
= fi
.nested_types_list
.size ();
15971 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15972 TYPE_NESTED_TYPES_ARRAY (type
)
15973 = ((struct decl_field
*)
15974 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15975 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15977 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15978 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15982 quirk_gcc_member_function_pointer (type
, objfile
);
15983 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15984 cu
->rust_unions
.push_back (type
);
15986 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15987 snapshots) has been known to create a die giving a declaration
15988 for a class that has, as a child, a die giving a definition for a
15989 nested class. So we have to process our children even if the
15990 current die is a declaration. Normally, of course, a declaration
15991 won't have any children at all. */
15993 child_die
= die
->child
;
15995 while (child_die
!= NULL
&& child_die
->tag
)
15997 if (child_die
->tag
== DW_TAG_member
15998 || child_die
->tag
== DW_TAG_variable
15999 || child_die
->tag
== DW_TAG_inheritance
16000 || child_die
->tag
== DW_TAG_template_value_param
16001 || child_die
->tag
== DW_TAG_template_type_param
)
16006 process_die (child_die
, cu
);
16008 child_die
= child_die
->sibling
;
16011 /* Do not consider external references. According to the DWARF standard,
16012 these DIEs are identified by the fact that they have no byte_size
16013 attribute, and a declaration attribute. */
16014 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16015 || !die_is_declaration (die
, cu
)
16016 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16018 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16020 if (has_template_parameters
)
16022 struct symtab
*symtab
;
16023 if (sym
!= nullptr)
16024 symtab
= symbol_symtab (sym
);
16025 else if (cu
->line_header
!= nullptr)
16027 /* Any related symtab will do. */
16029 = cu
->line_header
->file_names ()[0].symtab
;
16034 complaint (_("could not find suitable "
16035 "symtab for template parameter"
16036 " - DIE at %s [in module %s]"),
16037 sect_offset_str (die
->sect_off
),
16038 objfile_name (objfile
));
16041 if (symtab
!= nullptr)
16043 /* Make sure that the symtab is set on the new symbols.
16044 Even though they don't appear in this symtab directly,
16045 other parts of gdb assume that symbols do, and this is
16046 reasonably true. */
16047 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16048 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16054 /* Assuming DIE is an enumeration type, and TYPE is its associated
16055 type, update TYPE using some information only available in DIE's
16056 children. In particular, the fields are computed. */
16059 update_enumeration_type_from_children (struct die_info
*die
,
16061 struct dwarf2_cu
*cu
)
16063 struct die_info
*child_die
;
16064 int unsigned_enum
= 1;
16067 auto_obstack obstack
;
16068 std::vector
<struct field
> fields
;
16070 for (child_die
= die
->child
;
16071 child_die
!= NULL
&& child_die
->tag
;
16072 child_die
= child_die
->sibling
)
16074 struct attribute
*attr
;
16076 const gdb_byte
*bytes
;
16077 struct dwarf2_locexpr_baton
*baton
;
16080 if (child_die
->tag
!= DW_TAG_enumerator
)
16083 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16087 name
= dwarf2_name (child_die
, cu
);
16089 name
= "<anonymous enumerator>";
16091 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16092 &value
, &bytes
, &baton
);
16100 if (count_one_bits_ll (value
) >= 2)
16104 fields
.emplace_back ();
16105 struct field
&field
= fields
.back ();
16106 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16107 SET_FIELD_ENUMVAL (field
, value
);
16110 if (!fields
.empty ())
16112 type
->set_num_fields (fields
.size ());
16115 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16116 memcpy (type
->fields (), fields
.data (),
16117 sizeof (struct field
) * fields
.size ());
16121 TYPE_UNSIGNED (type
) = 1;
16123 TYPE_FLAG_ENUM (type
) = 1;
16126 /* Given a DW_AT_enumeration_type die, set its type. We do not
16127 complete the type's fields yet, or create any symbols. */
16129 static struct type
*
16130 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16132 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16134 struct attribute
*attr
;
16137 /* If the definition of this type lives in .debug_types, read that type.
16138 Don't follow DW_AT_specification though, that will take us back up
16139 the chain and we want to go down. */
16140 attr
= die
->attr (DW_AT_signature
);
16141 if (attr
!= nullptr)
16143 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16145 /* The type's CU may not be the same as CU.
16146 Ensure TYPE is recorded with CU in die_type_hash. */
16147 return set_die_type (die
, type
, cu
);
16150 type
= alloc_type (objfile
);
16152 type
->set_code (TYPE_CODE_ENUM
);
16153 name
= dwarf2_full_name (NULL
, die
, cu
);
16155 type
->set_name (name
);
16157 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16160 struct type
*underlying_type
= die_type (die
, cu
);
16162 TYPE_TARGET_TYPE (type
) = underlying_type
;
16165 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16166 if (attr
!= nullptr)
16168 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16172 TYPE_LENGTH (type
) = 0;
16175 maybe_set_alignment (cu
, die
, type
);
16177 /* The enumeration DIE can be incomplete. In Ada, any type can be
16178 declared as private in the package spec, and then defined only
16179 inside the package body. Such types are known as Taft Amendment
16180 Types. When another package uses such a type, an incomplete DIE
16181 may be generated by the compiler. */
16182 if (die_is_declaration (die
, cu
))
16183 TYPE_STUB (type
) = 1;
16185 /* If this type has an underlying type that is not a stub, then we
16186 may use its attributes. We always use the "unsigned" attribute
16187 in this situation, because ordinarily we guess whether the type
16188 is unsigned -- but the guess can be wrong and the underlying type
16189 can tell us the reality. However, we defer to a local size
16190 attribute if one exists, because this lets the compiler override
16191 the underlying type if needed. */
16192 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16194 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16195 underlying_type
= check_typedef (underlying_type
);
16196 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16197 if (TYPE_LENGTH (type
) == 0)
16198 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16199 if (TYPE_RAW_ALIGN (type
) == 0
16200 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16201 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16204 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16206 set_die_type (die
, type
, cu
);
16208 /* Finish the creation of this type by using the enum's children.
16209 Note that, as usual, this must come after set_die_type to avoid
16210 infinite recursion when trying to compute the names of the
16212 update_enumeration_type_from_children (die
, type
, cu
);
16217 /* Given a pointer to a die which begins an enumeration, process all
16218 the dies that define the members of the enumeration, and create the
16219 symbol for the enumeration type.
16221 NOTE: We reverse the order of the element list. */
16224 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16226 struct type
*this_type
;
16228 this_type
= get_die_type (die
, cu
);
16229 if (this_type
== NULL
)
16230 this_type
= read_enumeration_type (die
, cu
);
16232 if (die
->child
!= NULL
)
16234 struct die_info
*child_die
;
16237 child_die
= die
->child
;
16238 while (child_die
&& child_die
->tag
)
16240 if (child_die
->tag
!= DW_TAG_enumerator
)
16242 process_die (child_die
, cu
);
16246 name
= dwarf2_name (child_die
, cu
);
16248 new_symbol (child_die
, this_type
, cu
);
16251 child_die
= child_die
->sibling
;
16255 /* If we are reading an enum from a .debug_types unit, and the enum
16256 is a declaration, and the enum is not the signatured type in the
16257 unit, then we do not want to add a symbol for it. Adding a
16258 symbol would in some cases obscure the true definition of the
16259 enum, giving users an incomplete type when the definition is
16260 actually available. Note that we do not want to do this for all
16261 enums which are just declarations, because C++0x allows forward
16262 enum declarations. */
16263 if (cu
->per_cu
->is_debug_types
16264 && die_is_declaration (die
, cu
))
16266 struct signatured_type
*sig_type
;
16268 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16269 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16270 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16274 new_symbol (die
, this_type
, cu
);
16277 /* Extract all information from a DW_TAG_array_type DIE and put it in
16278 the DIE's type field. For now, this only handles one dimensional
16281 static struct type
*
16282 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16284 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16285 struct die_info
*child_die
;
16287 struct type
*element_type
, *range_type
, *index_type
;
16288 struct attribute
*attr
;
16290 struct dynamic_prop
*byte_stride_prop
= NULL
;
16291 unsigned int bit_stride
= 0;
16293 element_type
= die_type (die
, cu
);
16295 /* The die_type call above may have already set the type for this DIE. */
16296 type
= get_die_type (die
, cu
);
16300 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16304 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16307 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16308 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16312 complaint (_("unable to read array DW_AT_byte_stride "
16313 " - DIE at %s [in module %s]"),
16314 sect_offset_str (die
->sect_off
),
16315 objfile_name (cu
->per_objfile
->objfile
));
16316 /* Ignore this attribute. We will likely not be able to print
16317 arrays of this type correctly, but there is little we can do
16318 to help if we cannot read the attribute's value. */
16319 byte_stride_prop
= NULL
;
16323 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16325 bit_stride
= DW_UNSND (attr
);
16327 /* Irix 6.2 native cc creates array types without children for
16328 arrays with unspecified length. */
16329 if (die
->child
== NULL
)
16331 index_type
= objfile_type (objfile
)->builtin_int
;
16332 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16333 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16334 byte_stride_prop
, bit_stride
);
16335 return set_die_type (die
, type
, cu
);
16338 std::vector
<struct type
*> range_types
;
16339 child_die
= die
->child
;
16340 while (child_die
&& child_die
->tag
)
16342 if (child_die
->tag
== DW_TAG_subrange_type
)
16344 struct type
*child_type
= read_type_die (child_die
, cu
);
16346 if (child_type
!= NULL
)
16348 /* The range type was succesfully read. Save it for the
16349 array type creation. */
16350 range_types
.push_back (child_type
);
16353 child_die
= child_die
->sibling
;
16356 /* Dwarf2 dimensions are output from left to right, create the
16357 necessary array types in backwards order. */
16359 type
= element_type
;
16361 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16365 while (i
< range_types
.size ())
16366 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16367 byte_stride_prop
, bit_stride
);
16371 size_t ndim
= range_types
.size ();
16373 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16374 byte_stride_prop
, bit_stride
);
16377 /* Understand Dwarf2 support for vector types (like they occur on
16378 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16379 array type. This is not part of the Dwarf2/3 standard yet, but a
16380 custom vendor extension. The main difference between a regular
16381 array and the vector variant is that vectors are passed by value
16383 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16384 if (attr
!= nullptr)
16385 make_vector_type (type
);
16387 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16388 implementation may choose to implement triple vectors using this
16390 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16391 if (attr
!= nullptr)
16393 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16394 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16396 complaint (_("DW_AT_byte_size for array type smaller "
16397 "than the total size of elements"));
16400 name
= dwarf2_name (die
, cu
);
16402 type
->set_name (name
);
16404 maybe_set_alignment (cu
, die
, type
);
16406 /* Install the type in the die. */
16407 set_die_type (die
, type
, cu
);
16409 /* set_die_type should be already done. */
16410 set_descriptive_type (type
, die
, cu
);
16415 static enum dwarf_array_dim_ordering
16416 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16418 struct attribute
*attr
;
16420 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16422 if (attr
!= nullptr)
16423 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16425 /* GNU F77 is a special case, as at 08/2004 array type info is the
16426 opposite order to the dwarf2 specification, but data is still
16427 laid out as per normal fortran.
16429 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16430 version checking. */
16432 if (cu
->language
== language_fortran
16433 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16435 return DW_ORD_row_major
;
16438 switch (cu
->language_defn
->la_array_ordering
)
16440 case array_column_major
:
16441 return DW_ORD_col_major
;
16442 case array_row_major
:
16444 return DW_ORD_row_major
;
16448 /* Extract all information from a DW_TAG_set_type DIE and put it in
16449 the DIE's type field. */
16451 static struct type
*
16452 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16454 struct type
*domain_type
, *set_type
;
16455 struct attribute
*attr
;
16457 domain_type
= die_type (die
, cu
);
16459 /* The die_type call above may have already set the type for this DIE. */
16460 set_type
= get_die_type (die
, cu
);
16464 set_type
= create_set_type (NULL
, domain_type
);
16466 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16467 if (attr
!= nullptr)
16468 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16470 maybe_set_alignment (cu
, die
, set_type
);
16472 return set_die_type (die
, set_type
, cu
);
16475 /* A helper for read_common_block that creates a locexpr baton.
16476 SYM is the symbol which we are marking as computed.
16477 COMMON_DIE is the DIE for the common block.
16478 COMMON_LOC is the location expression attribute for the common
16480 MEMBER_LOC is the location expression attribute for the particular
16481 member of the common block that we are processing.
16482 CU is the CU from which the above come. */
16485 mark_common_block_symbol_computed (struct symbol
*sym
,
16486 struct die_info
*common_die
,
16487 struct attribute
*common_loc
,
16488 struct attribute
*member_loc
,
16489 struct dwarf2_cu
*cu
)
16491 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16492 struct objfile
*objfile
= per_objfile
->objfile
;
16493 struct dwarf2_locexpr_baton
*baton
;
16495 unsigned int cu_off
;
16496 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16497 LONGEST offset
= 0;
16499 gdb_assert (common_loc
&& member_loc
);
16500 gdb_assert (common_loc
->form_is_block ());
16501 gdb_assert (member_loc
->form_is_block ()
16502 || member_loc
->form_is_constant ());
16504 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16505 baton
->per_objfile
= per_objfile
;
16506 baton
->per_cu
= cu
->per_cu
;
16507 gdb_assert (baton
->per_cu
);
16509 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16511 if (member_loc
->form_is_constant ())
16513 offset
= member_loc
->constant_value (0);
16514 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16517 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16519 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16522 *ptr
++ = DW_OP_call4
;
16523 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16524 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16527 if (member_loc
->form_is_constant ())
16529 *ptr
++ = DW_OP_addr
;
16530 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16531 ptr
+= cu
->header
.addr_size
;
16535 /* We have to copy the data here, because DW_OP_call4 will only
16536 use a DW_AT_location attribute. */
16537 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16538 ptr
+= DW_BLOCK (member_loc
)->size
;
16541 *ptr
++ = DW_OP_plus
;
16542 gdb_assert (ptr
- baton
->data
== baton
->size
);
16544 SYMBOL_LOCATION_BATON (sym
) = baton
;
16545 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16548 /* Create appropriate locally-scoped variables for all the
16549 DW_TAG_common_block entries. Also create a struct common_block
16550 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16551 is used to separate the common blocks name namespace from regular
16555 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16557 struct attribute
*attr
;
16559 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16560 if (attr
!= nullptr)
16562 /* Support the .debug_loc offsets. */
16563 if (attr
->form_is_block ())
16567 else if (attr
->form_is_section_offset ())
16569 dwarf2_complex_location_expr_complaint ();
16574 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16575 "common block member");
16580 if (die
->child
!= NULL
)
16582 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16583 struct die_info
*child_die
;
16584 size_t n_entries
= 0, size
;
16585 struct common_block
*common_block
;
16586 struct symbol
*sym
;
16588 for (child_die
= die
->child
;
16589 child_die
&& child_die
->tag
;
16590 child_die
= child_die
->sibling
)
16593 size
= (sizeof (struct common_block
)
16594 + (n_entries
- 1) * sizeof (struct symbol
*));
16596 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16598 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16599 common_block
->n_entries
= 0;
16601 for (child_die
= die
->child
;
16602 child_die
&& child_die
->tag
;
16603 child_die
= child_die
->sibling
)
16605 /* Create the symbol in the DW_TAG_common_block block in the current
16607 sym
= new_symbol (child_die
, NULL
, cu
);
16610 struct attribute
*member_loc
;
16612 common_block
->contents
[common_block
->n_entries
++] = sym
;
16614 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16618 /* GDB has handled this for a long time, but it is
16619 not specified by DWARF. It seems to have been
16620 emitted by gfortran at least as recently as:
16621 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16622 complaint (_("Variable in common block has "
16623 "DW_AT_data_member_location "
16624 "- DIE at %s [in module %s]"),
16625 sect_offset_str (child_die
->sect_off
),
16626 objfile_name (objfile
));
16628 if (member_loc
->form_is_section_offset ())
16629 dwarf2_complex_location_expr_complaint ();
16630 else if (member_loc
->form_is_constant ()
16631 || member_loc
->form_is_block ())
16633 if (attr
!= nullptr)
16634 mark_common_block_symbol_computed (sym
, die
, attr
,
16638 dwarf2_complex_location_expr_complaint ();
16643 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16644 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16648 /* Create a type for a C++ namespace. */
16650 static struct type
*
16651 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16653 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16654 const char *previous_prefix
, *name
;
16658 /* For extensions, reuse the type of the original namespace. */
16659 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16661 struct die_info
*ext_die
;
16662 struct dwarf2_cu
*ext_cu
= cu
;
16664 ext_die
= dwarf2_extension (die
, &ext_cu
);
16665 type
= read_type_die (ext_die
, ext_cu
);
16667 /* EXT_CU may not be the same as CU.
16668 Ensure TYPE is recorded with CU in die_type_hash. */
16669 return set_die_type (die
, type
, cu
);
16672 name
= namespace_name (die
, &is_anonymous
, cu
);
16674 /* Now build the name of the current namespace. */
16676 previous_prefix
= determine_prefix (die
, cu
);
16677 if (previous_prefix
[0] != '\0')
16678 name
= typename_concat (&objfile
->objfile_obstack
,
16679 previous_prefix
, name
, 0, cu
);
16681 /* Create the type. */
16682 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16684 return set_die_type (die
, type
, cu
);
16687 /* Read a namespace scope. */
16690 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16692 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16695 /* Add a symbol associated to this if we haven't seen the namespace
16696 before. Also, add a using directive if it's an anonymous
16699 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16703 type
= read_type_die (die
, cu
);
16704 new_symbol (die
, type
, cu
);
16706 namespace_name (die
, &is_anonymous
, cu
);
16709 const char *previous_prefix
= determine_prefix (die
, cu
);
16711 std::vector
<const char *> excludes
;
16712 add_using_directive (using_directives (cu
),
16713 previous_prefix
, type
->name (), NULL
,
16714 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16718 if (die
->child
!= NULL
)
16720 struct die_info
*child_die
= die
->child
;
16722 while (child_die
&& child_die
->tag
)
16724 process_die (child_die
, cu
);
16725 child_die
= child_die
->sibling
;
16730 /* Read a Fortran module as type. This DIE can be only a declaration used for
16731 imported module. Still we need that type as local Fortran "use ... only"
16732 declaration imports depend on the created type in determine_prefix. */
16734 static struct type
*
16735 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16737 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16738 const char *module_name
;
16741 module_name
= dwarf2_name (die
, cu
);
16742 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16744 return set_die_type (die
, type
, cu
);
16747 /* Read a Fortran module. */
16750 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16752 struct die_info
*child_die
= die
->child
;
16755 type
= read_type_die (die
, cu
);
16756 new_symbol (die
, type
, cu
);
16758 while (child_die
&& child_die
->tag
)
16760 process_die (child_die
, cu
);
16761 child_die
= child_die
->sibling
;
16765 /* Return the name of the namespace represented by DIE. Set
16766 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16769 static const char *
16770 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16772 struct die_info
*current_die
;
16773 const char *name
= NULL
;
16775 /* Loop through the extensions until we find a name. */
16777 for (current_die
= die
;
16778 current_die
!= NULL
;
16779 current_die
= dwarf2_extension (die
, &cu
))
16781 /* We don't use dwarf2_name here so that we can detect the absence
16782 of a name -> anonymous namespace. */
16783 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16789 /* Is it an anonymous namespace? */
16791 *is_anonymous
= (name
== NULL
);
16793 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16798 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16799 the user defined type vector. */
16801 static struct type
*
16802 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16804 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16805 struct comp_unit_head
*cu_header
= &cu
->header
;
16807 struct attribute
*attr_byte_size
;
16808 struct attribute
*attr_address_class
;
16809 int byte_size
, addr_class
;
16810 struct type
*target_type
;
16812 target_type
= die_type (die
, cu
);
16814 /* The die_type call above may have already set the type for this DIE. */
16815 type
= get_die_type (die
, cu
);
16819 type
= lookup_pointer_type (target_type
);
16821 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16822 if (attr_byte_size
)
16823 byte_size
= DW_UNSND (attr_byte_size
);
16825 byte_size
= cu_header
->addr_size
;
16827 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16828 if (attr_address_class
)
16829 addr_class
= DW_UNSND (attr_address_class
);
16831 addr_class
= DW_ADDR_none
;
16833 ULONGEST alignment
= get_alignment (cu
, die
);
16835 /* If the pointer size, alignment, or address class is different
16836 than the default, create a type variant marked as such and set
16837 the length accordingly. */
16838 if (TYPE_LENGTH (type
) != byte_size
16839 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16840 && alignment
!= TYPE_RAW_ALIGN (type
))
16841 || addr_class
!= DW_ADDR_none
)
16843 if (gdbarch_address_class_type_flags_p (gdbarch
))
16847 type_flags
= gdbarch_address_class_type_flags
16848 (gdbarch
, byte_size
, addr_class
);
16849 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16851 type
= make_type_with_address_space (type
, type_flags
);
16853 else if (TYPE_LENGTH (type
) != byte_size
)
16855 complaint (_("invalid pointer size %d"), byte_size
);
16857 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16859 complaint (_("Invalid DW_AT_alignment"
16860 " - DIE at %s [in module %s]"),
16861 sect_offset_str (die
->sect_off
),
16862 objfile_name (cu
->per_objfile
->objfile
));
16866 /* Should we also complain about unhandled address classes? */
16870 TYPE_LENGTH (type
) = byte_size
;
16871 set_type_align (type
, alignment
);
16872 return set_die_type (die
, type
, cu
);
16875 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16876 the user defined type vector. */
16878 static struct type
*
16879 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16882 struct type
*to_type
;
16883 struct type
*domain
;
16885 to_type
= die_type (die
, cu
);
16886 domain
= die_containing_type (die
, cu
);
16888 /* The calls above may have already set the type for this DIE. */
16889 type
= get_die_type (die
, cu
);
16893 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16894 type
= lookup_methodptr_type (to_type
);
16895 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16897 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16899 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16900 to_type
->fields (), to_type
->num_fields (),
16901 TYPE_VARARGS (to_type
));
16902 type
= lookup_methodptr_type (new_type
);
16905 type
= lookup_memberptr_type (to_type
, domain
);
16907 return set_die_type (die
, type
, cu
);
16910 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16911 the user defined type vector. */
16913 static struct type
*
16914 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16915 enum type_code refcode
)
16917 struct comp_unit_head
*cu_header
= &cu
->header
;
16918 struct type
*type
, *target_type
;
16919 struct attribute
*attr
;
16921 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16923 target_type
= die_type (die
, cu
);
16925 /* The die_type call above may have already set the type for this DIE. */
16926 type
= get_die_type (die
, cu
);
16930 type
= lookup_reference_type (target_type
, refcode
);
16931 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16932 if (attr
!= nullptr)
16934 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16938 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16940 maybe_set_alignment (cu
, die
, type
);
16941 return set_die_type (die
, type
, cu
);
16944 /* Add the given cv-qualifiers to the element type of the array. GCC
16945 outputs DWARF type qualifiers that apply to an array, not the
16946 element type. But GDB relies on the array element type to carry
16947 the cv-qualifiers. This mimics section 6.7.3 of the C99
16950 static struct type
*
16951 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16952 struct type
*base_type
, int cnst
, int voltl
)
16954 struct type
*el_type
, *inner_array
;
16956 base_type
= copy_type (base_type
);
16957 inner_array
= base_type
;
16959 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16961 TYPE_TARGET_TYPE (inner_array
) =
16962 copy_type (TYPE_TARGET_TYPE (inner_array
));
16963 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16966 el_type
= TYPE_TARGET_TYPE (inner_array
);
16967 cnst
|= TYPE_CONST (el_type
);
16968 voltl
|= TYPE_VOLATILE (el_type
);
16969 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16971 return set_die_type (die
, base_type
, cu
);
16974 static struct type
*
16975 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16977 struct type
*base_type
, *cv_type
;
16979 base_type
= die_type (die
, cu
);
16981 /* The die_type call above may have already set the type for this DIE. */
16982 cv_type
= get_die_type (die
, cu
);
16986 /* In case the const qualifier is applied to an array type, the element type
16987 is so qualified, not the array type (section 6.7.3 of C99). */
16988 if (base_type
->code () == TYPE_CODE_ARRAY
)
16989 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16991 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16992 return set_die_type (die
, cv_type
, cu
);
16995 static struct type
*
16996 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16998 struct type
*base_type
, *cv_type
;
17000 base_type
= die_type (die
, cu
);
17002 /* The die_type call above may have already set the type for this DIE. */
17003 cv_type
= get_die_type (die
, cu
);
17007 /* In case the volatile qualifier is applied to an array type, the
17008 element type is so qualified, not the array type (section 6.7.3
17010 if (base_type
->code () == TYPE_CODE_ARRAY
)
17011 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17013 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17014 return set_die_type (die
, cv_type
, cu
);
17017 /* Handle DW_TAG_restrict_type. */
17019 static struct type
*
17020 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17022 struct type
*base_type
, *cv_type
;
17024 base_type
= die_type (die
, cu
);
17026 /* The die_type call above may have already set the type for this DIE. */
17027 cv_type
= get_die_type (die
, cu
);
17031 cv_type
= make_restrict_type (base_type
);
17032 return set_die_type (die
, cv_type
, cu
);
17035 /* Handle DW_TAG_atomic_type. */
17037 static struct type
*
17038 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17040 struct type
*base_type
, *cv_type
;
17042 base_type
= die_type (die
, cu
);
17044 /* The die_type call above may have already set the type for this DIE. */
17045 cv_type
= get_die_type (die
, cu
);
17049 cv_type
= make_atomic_type (base_type
);
17050 return set_die_type (die
, cv_type
, cu
);
17053 /* Extract all information from a DW_TAG_string_type DIE and add to
17054 the user defined type vector. It isn't really a user defined type,
17055 but it behaves like one, with other DIE's using an AT_user_def_type
17056 attribute to reference it. */
17058 static struct type
*
17059 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17061 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17062 struct gdbarch
*gdbarch
= objfile
->arch ();
17063 struct type
*type
, *range_type
, *index_type
, *char_type
;
17064 struct attribute
*attr
;
17065 struct dynamic_prop prop
;
17066 bool length_is_constant
= true;
17069 /* There are a couple of places where bit sizes might be made use of
17070 when parsing a DW_TAG_string_type, however, no producer that we know
17071 of make use of these. Handling bit sizes that are a multiple of the
17072 byte size is easy enough, but what about other bit sizes? Lets deal
17073 with that problem when we have to. Warn about these attributes being
17074 unsupported, then parse the type and ignore them like we always
17076 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17077 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17079 static bool warning_printed
= false;
17080 if (!warning_printed
)
17082 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17083 "currently supported on DW_TAG_string_type."));
17084 warning_printed
= true;
17088 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17089 if (attr
!= nullptr && !attr
->form_is_constant ())
17091 /* The string length describes the location at which the length of
17092 the string can be found. The size of the length field can be
17093 specified with one of the attributes below. */
17094 struct type
*prop_type
;
17095 struct attribute
*len
17096 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17097 if (len
== nullptr)
17098 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17099 if (len
!= nullptr && len
->form_is_constant ())
17101 /* Pass 0 as the default as we know this attribute is constant
17102 and the default value will not be returned. */
17103 LONGEST sz
= len
->constant_value (0);
17104 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17108 /* If the size is not specified then we assume it is the size of
17109 an address on this target. */
17110 prop_type
= cu
->addr_sized_int_type (true);
17113 /* Convert the attribute into a dynamic property. */
17114 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17117 length_is_constant
= false;
17119 else if (attr
!= nullptr)
17121 /* This DW_AT_string_length just contains the length with no
17122 indirection. There's no need to create a dynamic property in this
17123 case. Pass 0 for the default value as we know it will not be
17124 returned in this case. */
17125 length
= attr
->constant_value (0);
17127 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17129 /* We don't currently support non-constant byte sizes for strings. */
17130 length
= attr
->constant_value (1);
17134 /* Use 1 as a fallback length if we have nothing else. */
17138 index_type
= objfile_type (objfile
)->builtin_int
;
17139 if (length_is_constant
)
17140 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17143 struct dynamic_prop low_bound
;
17145 low_bound
.kind
= PROP_CONST
;
17146 low_bound
.data
.const_val
= 1;
17147 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17149 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17150 type
= create_string_type (NULL
, char_type
, range_type
);
17152 return set_die_type (die
, type
, cu
);
17155 /* Assuming that DIE corresponds to a function, returns nonzero
17156 if the function is prototyped. */
17159 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17161 struct attribute
*attr
;
17163 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17164 if (attr
&& (DW_UNSND (attr
) != 0))
17167 /* The DWARF standard implies that the DW_AT_prototyped attribute
17168 is only meaningful for C, but the concept also extends to other
17169 languages that allow unprototyped functions (Eg: Objective C).
17170 For all other languages, assume that functions are always
17172 if (cu
->language
!= language_c
17173 && cu
->language
!= language_objc
17174 && cu
->language
!= language_opencl
)
17177 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17178 prototyped and unprototyped functions; default to prototyped,
17179 since that is more common in modern code (and RealView warns
17180 about unprototyped functions). */
17181 if (producer_is_realview (cu
->producer
))
17187 /* Handle DIES due to C code like:
17191 int (*funcp)(int a, long l);
17195 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17197 static struct type
*
17198 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17200 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17201 struct type
*type
; /* Type that this function returns. */
17202 struct type
*ftype
; /* Function that returns above type. */
17203 struct attribute
*attr
;
17205 type
= die_type (die
, cu
);
17207 /* The die_type call above may have already set the type for this DIE. */
17208 ftype
= get_die_type (die
, cu
);
17212 ftype
= lookup_function_type (type
);
17214 if (prototyped_function_p (die
, cu
))
17215 TYPE_PROTOTYPED (ftype
) = 1;
17217 /* Store the calling convention in the type if it's available in
17218 the subroutine die. Otherwise set the calling convention to
17219 the default value DW_CC_normal. */
17220 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17221 if (attr
!= nullptr
17222 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17223 TYPE_CALLING_CONVENTION (ftype
)
17224 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17225 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17226 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17228 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17230 /* Record whether the function returns normally to its caller or not
17231 if the DWARF producer set that information. */
17232 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17233 if (attr
&& (DW_UNSND (attr
) != 0))
17234 TYPE_NO_RETURN (ftype
) = 1;
17236 /* We need to add the subroutine type to the die immediately so
17237 we don't infinitely recurse when dealing with parameters
17238 declared as the same subroutine type. */
17239 set_die_type (die
, ftype
, cu
);
17241 if (die
->child
!= NULL
)
17243 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17244 struct die_info
*child_die
;
17245 int nparams
, iparams
;
17247 /* Count the number of parameters.
17248 FIXME: GDB currently ignores vararg functions, but knows about
17249 vararg member functions. */
17251 child_die
= die
->child
;
17252 while (child_die
&& child_die
->tag
)
17254 if (child_die
->tag
== DW_TAG_formal_parameter
)
17256 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17257 TYPE_VARARGS (ftype
) = 1;
17258 child_die
= child_die
->sibling
;
17261 /* Allocate storage for parameters and fill them in. */
17262 ftype
->set_num_fields (nparams
);
17264 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17266 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17267 even if we error out during the parameters reading below. */
17268 for (iparams
= 0; iparams
< nparams
; iparams
++)
17269 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17272 child_die
= die
->child
;
17273 while (child_die
&& child_die
->tag
)
17275 if (child_die
->tag
== DW_TAG_formal_parameter
)
17277 struct type
*arg_type
;
17279 /* DWARF version 2 has no clean way to discern C++
17280 static and non-static member functions. G++ helps
17281 GDB by marking the first parameter for non-static
17282 member functions (which is the this pointer) as
17283 artificial. We pass this information to
17284 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17286 DWARF version 3 added DW_AT_object_pointer, which GCC
17287 4.5 does not yet generate. */
17288 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17289 if (attr
!= nullptr)
17290 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17292 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17293 arg_type
= die_type (child_die
, cu
);
17295 /* RealView does not mark THIS as const, which the testsuite
17296 expects. GCC marks THIS as const in method definitions,
17297 but not in the class specifications (GCC PR 43053). */
17298 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17299 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17302 struct dwarf2_cu
*arg_cu
= cu
;
17303 const char *name
= dwarf2_name (child_die
, cu
);
17305 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17306 if (attr
!= nullptr)
17308 /* If the compiler emits this, use it. */
17309 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17312 else if (name
&& strcmp (name
, "this") == 0)
17313 /* Function definitions will have the argument names. */
17315 else if (name
== NULL
&& iparams
== 0)
17316 /* Declarations may not have the names, so like
17317 elsewhere in GDB, assume an artificial first
17318 argument is "this". */
17322 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17326 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17329 child_die
= child_die
->sibling
;
17336 static struct type
*
17337 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17339 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17340 const char *name
= NULL
;
17341 struct type
*this_type
, *target_type
;
17343 name
= dwarf2_full_name (NULL
, die
, cu
);
17344 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17345 TYPE_TARGET_STUB (this_type
) = 1;
17346 set_die_type (die
, this_type
, cu
);
17347 target_type
= die_type (die
, cu
);
17348 if (target_type
!= this_type
)
17349 TYPE_TARGET_TYPE (this_type
) = target_type
;
17352 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17353 spec and cause infinite loops in GDB. */
17354 complaint (_("Self-referential DW_TAG_typedef "
17355 "- DIE at %s [in module %s]"),
17356 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17357 TYPE_TARGET_TYPE (this_type
) = NULL
;
17361 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17362 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17363 Handle these by just returning the target type, rather than
17364 constructing an anonymous typedef type and trying to handle this
17366 set_die_type (die
, target_type
, cu
);
17367 return target_type
;
17372 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17373 (which may be different from NAME) to the architecture back-end to allow
17374 it to guess the correct format if necessary. */
17376 static struct type
*
17377 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17378 const char *name_hint
, enum bfd_endian byte_order
)
17380 struct gdbarch
*gdbarch
= objfile
->arch ();
17381 const struct floatformat
**format
;
17384 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17386 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17388 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17393 /* Allocate an integer type of size BITS and name NAME. */
17395 static struct type
*
17396 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17397 int bits
, int unsigned_p
, const char *name
)
17401 /* Versions of Intel's C Compiler generate an integer type called "void"
17402 instead of using DW_TAG_unspecified_type. This has been seen on
17403 at least versions 14, 17, and 18. */
17404 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17405 && strcmp (name
, "void") == 0)
17406 type
= objfile_type (objfile
)->builtin_void
;
17408 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17413 /* Initialise and return a floating point type of size BITS suitable for
17414 use as a component of a complex number. The NAME_HINT is passed through
17415 when initialising the floating point type and is the name of the complex
17418 As DWARF doesn't currently provide an explicit name for the components
17419 of a complex number, but it can be helpful to have these components
17420 named, we try to select a suitable name based on the size of the
17422 static struct type
*
17423 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17424 struct objfile
*objfile
,
17425 int bits
, const char *name_hint
,
17426 enum bfd_endian byte_order
)
17428 gdbarch
*gdbarch
= objfile
->arch ();
17429 struct type
*tt
= nullptr;
17431 /* Try to find a suitable floating point builtin type of size BITS.
17432 We're going to use the name of this type as the name for the complex
17433 target type that we are about to create. */
17434 switch (cu
->language
)
17436 case language_fortran
:
17440 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17443 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17445 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17447 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17455 tt
= builtin_type (gdbarch
)->builtin_float
;
17458 tt
= builtin_type (gdbarch
)->builtin_double
;
17460 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17462 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17468 /* If the type we found doesn't match the size we were looking for, then
17469 pretend we didn't find a type at all, the complex target type we
17470 create will then be nameless. */
17471 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17474 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17475 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17478 /* Find a representation of a given base type and install
17479 it in the TYPE field of the die. */
17481 static struct type
*
17482 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17484 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17486 struct attribute
*attr
;
17487 int encoding
= 0, bits
= 0;
17491 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17492 if (attr
!= nullptr)
17493 encoding
= DW_UNSND (attr
);
17494 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17495 if (attr
!= nullptr)
17496 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17497 name
= dwarf2_name (die
, cu
);
17499 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17501 arch
= objfile
->arch ();
17502 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17504 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17507 int endianity
= DW_UNSND (attr
);
17512 byte_order
= BFD_ENDIAN_BIG
;
17514 case DW_END_little
:
17515 byte_order
= BFD_ENDIAN_LITTLE
;
17518 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17525 case DW_ATE_address
:
17526 /* Turn DW_ATE_address into a void * pointer. */
17527 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17528 type
= init_pointer_type (objfile
, bits
, name
, type
);
17530 case DW_ATE_boolean
:
17531 type
= init_boolean_type (objfile
, bits
, 1, name
);
17533 case DW_ATE_complex_float
:
17534 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17536 if (type
->code () == TYPE_CODE_ERROR
)
17538 if (name
== nullptr)
17540 struct obstack
*obstack
17541 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17542 name
= obconcat (obstack
, "_Complex ", type
->name (),
17545 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17548 type
= init_complex_type (name
, type
);
17550 case DW_ATE_decimal_float
:
17551 type
= init_decfloat_type (objfile
, bits
, name
);
17554 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17556 case DW_ATE_signed
:
17557 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17559 case DW_ATE_unsigned
:
17560 if (cu
->language
== language_fortran
17562 && startswith (name
, "character("))
17563 type
= init_character_type (objfile
, bits
, 1, name
);
17565 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17567 case DW_ATE_signed_char
:
17568 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17569 || cu
->language
== language_pascal
17570 || cu
->language
== language_fortran
)
17571 type
= init_character_type (objfile
, bits
, 0, name
);
17573 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17575 case DW_ATE_unsigned_char
:
17576 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17577 || cu
->language
== language_pascal
17578 || cu
->language
== language_fortran
17579 || cu
->language
== language_rust
)
17580 type
= init_character_type (objfile
, bits
, 1, name
);
17582 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17587 type
= builtin_type (arch
)->builtin_char16
;
17588 else if (bits
== 32)
17589 type
= builtin_type (arch
)->builtin_char32
;
17592 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17594 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17596 return set_die_type (die
, type
, cu
);
17601 complaint (_("unsupported DW_AT_encoding: '%s'"),
17602 dwarf_type_encoding_name (encoding
));
17603 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17607 if (name
&& strcmp (name
, "char") == 0)
17608 TYPE_NOSIGN (type
) = 1;
17610 maybe_set_alignment (cu
, die
, type
);
17612 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17614 return set_die_type (die
, type
, cu
);
17617 /* Parse dwarf attribute if it's a block, reference or constant and put the
17618 resulting value of the attribute into struct bound_prop.
17619 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17622 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17623 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17624 struct type
*default_type
)
17626 struct dwarf2_property_baton
*baton
;
17627 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17628 struct objfile
*objfile
= per_objfile
->objfile
;
17629 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17631 gdb_assert (default_type
!= NULL
);
17633 if (attr
== NULL
|| prop
== NULL
)
17636 if (attr
->form_is_block ())
17638 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17639 baton
->property_type
= default_type
;
17640 baton
->locexpr
.per_cu
= cu
->per_cu
;
17641 baton
->locexpr
.per_objfile
= per_objfile
;
17642 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17643 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17644 switch (attr
->name
)
17646 case DW_AT_string_length
:
17647 baton
->locexpr
.is_reference
= true;
17650 baton
->locexpr
.is_reference
= false;
17653 prop
->data
.baton
= baton
;
17654 prop
->kind
= PROP_LOCEXPR
;
17655 gdb_assert (prop
->data
.baton
!= NULL
);
17657 else if (attr
->form_is_ref ())
17659 struct dwarf2_cu
*target_cu
= cu
;
17660 struct die_info
*target_die
;
17661 struct attribute
*target_attr
;
17663 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17664 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17665 if (target_attr
== NULL
)
17666 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17668 if (target_attr
== NULL
)
17671 switch (target_attr
->name
)
17673 case DW_AT_location
:
17674 if (target_attr
->form_is_section_offset ())
17676 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17677 baton
->property_type
= die_type (target_die
, target_cu
);
17678 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17679 prop
->data
.baton
= baton
;
17680 prop
->kind
= PROP_LOCLIST
;
17681 gdb_assert (prop
->data
.baton
!= NULL
);
17683 else if (target_attr
->form_is_block ())
17685 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17686 baton
->property_type
= die_type (target_die
, target_cu
);
17687 baton
->locexpr
.per_cu
= cu
->per_cu
;
17688 baton
->locexpr
.per_objfile
= per_objfile
;
17689 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17690 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17691 baton
->locexpr
.is_reference
= true;
17692 prop
->data
.baton
= baton
;
17693 prop
->kind
= PROP_LOCEXPR
;
17694 gdb_assert (prop
->data
.baton
!= NULL
);
17698 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17699 "dynamic property");
17703 case DW_AT_data_member_location
:
17707 if (!handle_data_member_location (target_die
, target_cu
,
17711 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17712 baton
->property_type
= read_type_die (target_die
->parent
,
17714 baton
->offset_info
.offset
= offset
;
17715 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17716 prop
->data
.baton
= baton
;
17717 prop
->kind
= PROP_ADDR_OFFSET
;
17722 else if (attr
->form_is_constant ())
17724 prop
->data
.const_val
= attr
->constant_value (0);
17725 prop
->kind
= PROP_CONST
;
17729 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17730 dwarf2_name (die
, cu
));
17740 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17742 struct type
*int_type
;
17744 /* Helper macro to examine the various builtin types. */
17745 #define TRY_TYPE(F) \
17746 int_type = (unsigned_p \
17747 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17748 : objfile_type (objfile)->builtin_ ## F); \
17749 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17756 TRY_TYPE (long_long
);
17760 gdb_assert_not_reached ("unable to find suitable integer type");
17766 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17768 int addr_size
= this->per_cu
->addr_size ();
17769 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17772 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17773 present (which is valid) then compute the default type based on the
17774 compilation units address size. */
17776 static struct type
*
17777 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17779 struct type
*index_type
= die_type (die
, cu
);
17781 /* Dwarf-2 specifications explicitly allows to create subrange types
17782 without specifying a base type.
17783 In that case, the base type must be set to the type of
17784 the lower bound, upper bound or count, in that order, if any of these
17785 three attributes references an object that has a type.
17786 If no base type is found, the Dwarf-2 specifications say that
17787 a signed integer type of size equal to the size of an address should
17789 For the following C code: `extern char gdb_int [];'
17790 GCC produces an empty range DIE.
17791 FIXME: muller/2010-05-28: Possible references to object for low bound,
17792 high bound or count are not yet handled by this code. */
17793 if (index_type
->code () == TYPE_CODE_VOID
)
17794 index_type
= cu
->addr_sized_int_type (false);
17799 /* Read the given DW_AT_subrange DIE. */
17801 static struct type
*
17802 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17804 struct type
*base_type
, *orig_base_type
;
17805 struct type
*range_type
;
17806 struct attribute
*attr
;
17807 struct dynamic_prop low
, high
;
17808 int low_default_is_valid
;
17809 int high_bound_is_count
= 0;
17811 ULONGEST negative_mask
;
17813 orig_base_type
= read_subrange_index_type (die
, cu
);
17815 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17816 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17817 creating the range type, but we use the result of check_typedef
17818 when examining properties of the type. */
17819 base_type
= check_typedef (orig_base_type
);
17821 /* The die_type call above may have already set the type for this DIE. */
17822 range_type
= get_die_type (die
, cu
);
17826 low
.kind
= PROP_CONST
;
17827 high
.kind
= PROP_CONST
;
17828 high
.data
.const_val
= 0;
17830 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17831 omitting DW_AT_lower_bound. */
17832 switch (cu
->language
)
17835 case language_cplus
:
17836 low
.data
.const_val
= 0;
17837 low_default_is_valid
= 1;
17839 case language_fortran
:
17840 low
.data
.const_val
= 1;
17841 low_default_is_valid
= 1;
17844 case language_objc
:
17845 case language_rust
:
17846 low
.data
.const_val
= 0;
17847 low_default_is_valid
= (cu
->header
.version
>= 4);
17851 case language_pascal
:
17852 low
.data
.const_val
= 1;
17853 low_default_is_valid
= (cu
->header
.version
>= 4);
17856 low
.data
.const_val
= 0;
17857 low_default_is_valid
= 0;
17861 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17862 if (attr
!= nullptr)
17863 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17864 else if (!low_default_is_valid
)
17865 complaint (_("Missing DW_AT_lower_bound "
17866 "- DIE at %s [in module %s]"),
17867 sect_offset_str (die
->sect_off
),
17868 objfile_name (cu
->per_objfile
->objfile
));
17870 struct attribute
*attr_ub
, *attr_count
;
17871 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17872 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17874 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17875 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17877 /* If bounds are constant do the final calculation here. */
17878 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17879 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17881 high_bound_is_count
= 1;
17885 if (attr_ub
!= NULL
)
17886 complaint (_("Unresolved DW_AT_upper_bound "
17887 "- DIE at %s [in module %s]"),
17888 sect_offset_str (die
->sect_off
),
17889 objfile_name (cu
->per_objfile
->objfile
));
17890 if (attr_count
!= NULL
)
17891 complaint (_("Unresolved DW_AT_count "
17892 "- DIE at %s [in module %s]"),
17893 sect_offset_str (die
->sect_off
),
17894 objfile_name (cu
->per_objfile
->objfile
));
17899 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17900 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17901 bias
= bias_attr
->constant_value (0);
17903 /* Normally, the DWARF producers are expected to use a signed
17904 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17905 But this is unfortunately not always the case, as witnessed
17906 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17907 is used instead. To work around that ambiguity, we treat
17908 the bounds as signed, and thus sign-extend their values, when
17909 the base type is signed. */
17911 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17912 if (low
.kind
== PROP_CONST
17913 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17914 low
.data
.const_val
|= negative_mask
;
17915 if (high
.kind
== PROP_CONST
17916 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17917 high
.data
.const_val
|= negative_mask
;
17919 /* Check for bit and byte strides. */
17920 struct dynamic_prop byte_stride_prop
;
17921 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17922 if (attr_byte_stride
!= nullptr)
17924 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17925 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17929 struct dynamic_prop bit_stride_prop
;
17930 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17931 if (attr_bit_stride
!= nullptr)
17933 /* It only makes sense to have either a bit or byte stride. */
17934 if (attr_byte_stride
!= nullptr)
17936 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17937 "- DIE at %s [in module %s]"),
17938 sect_offset_str (die
->sect_off
),
17939 objfile_name (cu
->per_objfile
->objfile
));
17940 attr_bit_stride
= nullptr;
17944 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17945 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17950 if (attr_byte_stride
!= nullptr
17951 || attr_bit_stride
!= nullptr)
17953 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17954 struct dynamic_prop
*stride
17955 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17958 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17959 &high
, bias
, stride
, byte_stride_p
);
17962 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17964 if (high_bound_is_count
)
17965 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17967 /* Ada expects an empty array on no boundary attributes. */
17968 if (attr
== NULL
&& cu
->language
!= language_ada
)
17969 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17971 name
= dwarf2_name (die
, cu
);
17973 range_type
->set_name (name
);
17975 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17976 if (attr
!= nullptr)
17977 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17979 maybe_set_alignment (cu
, die
, range_type
);
17981 set_die_type (die
, range_type
, cu
);
17983 /* set_die_type should be already done. */
17984 set_descriptive_type (range_type
, die
, cu
);
17989 static struct type
*
17990 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17994 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17995 type
->set_name (dwarf2_name (die
, cu
));
17997 /* In Ada, an unspecified type is typically used when the description
17998 of the type is deferred to a different unit. When encountering
17999 such a type, we treat it as a stub, and try to resolve it later on,
18001 if (cu
->language
== language_ada
)
18002 TYPE_STUB (type
) = 1;
18004 return set_die_type (die
, type
, cu
);
18007 /* Read a single die and all its descendents. Set the die's sibling
18008 field to NULL; set other fields in the die correctly, and set all
18009 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18010 location of the info_ptr after reading all of those dies. PARENT
18011 is the parent of the die in question. */
18013 static struct die_info
*
18014 read_die_and_children (const struct die_reader_specs
*reader
,
18015 const gdb_byte
*info_ptr
,
18016 const gdb_byte
**new_info_ptr
,
18017 struct die_info
*parent
)
18019 struct die_info
*die
;
18020 const gdb_byte
*cur_ptr
;
18022 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18025 *new_info_ptr
= cur_ptr
;
18028 store_in_ref_table (die
, reader
->cu
);
18030 if (die
->has_children
)
18031 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18035 *new_info_ptr
= cur_ptr
;
18038 die
->sibling
= NULL
;
18039 die
->parent
= parent
;
18043 /* Read a die, all of its descendents, and all of its siblings; set
18044 all of the fields of all of the dies correctly. Arguments are as
18045 in read_die_and_children. */
18047 static struct die_info
*
18048 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18049 const gdb_byte
*info_ptr
,
18050 const gdb_byte
**new_info_ptr
,
18051 struct die_info
*parent
)
18053 struct die_info
*first_die
, *last_sibling
;
18054 const gdb_byte
*cur_ptr
;
18056 cur_ptr
= info_ptr
;
18057 first_die
= last_sibling
= NULL
;
18061 struct die_info
*die
18062 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18066 *new_info_ptr
= cur_ptr
;
18073 last_sibling
->sibling
= die
;
18075 last_sibling
= die
;
18079 /* Read a die, all of its descendents, and all of its siblings; set
18080 all of the fields of all of the dies correctly. Arguments are as
18081 in read_die_and_children.
18082 This the main entry point for reading a DIE and all its children. */
18084 static struct die_info
*
18085 read_die_and_siblings (const struct die_reader_specs
*reader
,
18086 const gdb_byte
*info_ptr
,
18087 const gdb_byte
**new_info_ptr
,
18088 struct die_info
*parent
)
18090 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18091 new_info_ptr
, parent
);
18093 if (dwarf_die_debug
)
18095 fprintf_unfiltered (gdb_stdlog
,
18096 "Read die from %s@0x%x of %s:\n",
18097 reader
->die_section
->get_name (),
18098 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18099 bfd_get_filename (reader
->abfd
));
18100 dump_die (die
, dwarf_die_debug
);
18106 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18108 The caller is responsible for filling in the extra attributes
18109 and updating (*DIEP)->num_attrs.
18110 Set DIEP to point to a newly allocated die with its information,
18111 except for its child, sibling, and parent fields. */
18113 static const gdb_byte
*
18114 read_full_die_1 (const struct die_reader_specs
*reader
,
18115 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18116 int num_extra_attrs
)
18118 unsigned int abbrev_number
, bytes_read
, i
;
18119 struct abbrev_info
*abbrev
;
18120 struct die_info
*die
;
18121 struct dwarf2_cu
*cu
= reader
->cu
;
18122 bfd
*abfd
= reader
->abfd
;
18124 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18125 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18126 info_ptr
+= bytes_read
;
18127 if (!abbrev_number
)
18133 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18135 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18137 bfd_get_filename (abfd
));
18139 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18140 die
->sect_off
= sect_off
;
18141 die
->tag
= abbrev
->tag
;
18142 die
->abbrev
= abbrev_number
;
18143 die
->has_children
= abbrev
->has_children
;
18145 /* Make the result usable.
18146 The caller needs to update num_attrs after adding the extra
18148 die
->num_attrs
= abbrev
->num_attrs
;
18150 std::vector
<int> indexes_that_need_reprocess
;
18151 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18153 bool need_reprocess
;
18155 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18156 info_ptr
, &need_reprocess
);
18157 if (need_reprocess
)
18158 indexes_that_need_reprocess
.push_back (i
);
18161 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18162 if (attr
!= nullptr)
18163 cu
->str_offsets_base
= DW_UNSND (attr
);
18165 attr
= die
->attr (DW_AT_loclists_base
);
18166 if (attr
!= nullptr)
18167 cu
->loclist_base
= DW_UNSND (attr
);
18169 auto maybe_addr_base
= die
->addr_base ();
18170 if (maybe_addr_base
.has_value ())
18171 cu
->addr_base
= *maybe_addr_base
;
18172 for (int index
: indexes_that_need_reprocess
)
18173 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18178 /* Read a die and all its attributes.
18179 Set DIEP to point to a newly allocated die with its information,
18180 except for its child, sibling, and parent fields. */
18182 static const gdb_byte
*
18183 read_full_die (const struct die_reader_specs
*reader
,
18184 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18186 const gdb_byte
*result
;
18188 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18190 if (dwarf_die_debug
)
18192 fprintf_unfiltered (gdb_stdlog
,
18193 "Read die from %s@0x%x of %s:\n",
18194 reader
->die_section
->get_name (),
18195 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18196 bfd_get_filename (reader
->abfd
));
18197 dump_die (*diep
, dwarf_die_debug
);
18204 /* Returns nonzero if TAG represents a type that we might generate a partial
18208 is_type_tag_for_partial (int tag
)
18213 /* Some types that would be reasonable to generate partial symbols for,
18214 that we don't at present. */
18215 case DW_TAG_array_type
:
18216 case DW_TAG_file_type
:
18217 case DW_TAG_ptr_to_member_type
:
18218 case DW_TAG_set_type
:
18219 case DW_TAG_string_type
:
18220 case DW_TAG_subroutine_type
:
18222 case DW_TAG_base_type
:
18223 case DW_TAG_class_type
:
18224 case DW_TAG_interface_type
:
18225 case DW_TAG_enumeration_type
:
18226 case DW_TAG_structure_type
:
18227 case DW_TAG_subrange_type
:
18228 case DW_TAG_typedef
:
18229 case DW_TAG_union_type
:
18236 /* Load all DIEs that are interesting for partial symbols into memory. */
18238 static struct partial_die_info
*
18239 load_partial_dies (const struct die_reader_specs
*reader
,
18240 const gdb_byte
*info_ptr
, int building_psymtab
)
18242 struct dwarf2_cu
*cu
= reader
->cu
;
18243 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18244 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18245 unsigned int bytes_read
;
18246 unsigned int load_all
= 0;
18247 int nesting_level
= 1;
18252 gdb_assert (cu
->per_cu
!= NULL
);
18253 if (cu
->per_cu
->load_all_dies
)
18257 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18261 &cu
->comp_unit_obstack
,
18262 hashtab_obstack_allocate
,
18263 dummy_obstack_deallocate
);
18267 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18269 /* A NULL abbrev means the end of a series of children. */
18270 if (abbrev
== NULL
)
18272 if (--nesting_level
== 0)
18275 info_ptr
+= bytes_read
;
18276 last_die
= parent_die
;
18277 parent_die
= parent_die
->die_parent
;
18281 /* Check for template arguments. We never save these; if
18282 they're seen, we just mark the parent, and go on our way. */
18283 if (parent_die
!= NULL
18284 && cu
->language
== language_cplus
18285 && (abbrev
->tag
== DW_TAG_template_type_param
18286 || abbrev
->tag
== DW_TAG_template_value_param
))
18288 parent_die
->has_template_arguments
= 1;
18292 /* We don't need a partial DIE for the template argument. */
18293 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18298 /* We only recurse into c++ subprograms looking for template arguments.
18299 Skip their other children. */
18301 && cu
->language
== language_cplus
18302 && parent_die
!= NULL
18303 && parent_die
->tag
== DW_TAG_subprogram
)
18305 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18309 /* Check whether this DIE is interesting enough to save. Normally
18310 we would not be interested in members here, but there may be
18311 later variables referencing them via DW_AT_specification (for
18312 static members). */
18314 && !is_type_tag_for_partial (abbrev
->tag
)
18315 && abbrev
->tag
!= DW_TAG_constant
18316 && abbrev
->tag
!= DW_TAG_enumerator
18317 && abbrev
->tag
!= DW_TAG_subprogram
18318 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18319 && abbrev
->tag
!= DW_TAG_lexical_block
18320 && abbrev
->tag
!= DW_TAG_variable
18321 && abbrev
->tag
!= DW_TAG_namespace
18322 && abbrev
->tag
!= DW_TAG_module
18323 && abbrev
->tag
!= DW_TAG_member
18324 && abbrev
->tag
!= DW_TAG_imported_unit
18325 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18327 /* Otherwise we skip to the next sibling, if any. */
18328 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18332 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18335 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18337 /* This two-pass algorithm for processing partial symbols has a
18338 high cost in cache pressure. Thus, handle some simple cases
18339 here which cover the majority of C partial symbols. DIEs
18340 which neither have specification tags in them, nor could have
18341 specification tags elsewhere pointing at them, can simply be
18342 processed and discarded.
18344 This segment is also optional; scan_partial_symbols and
18345 add_partial_symbol will handle these DIEs if we chain
18346 them in normally. When compilers which do not emit large
18347 quantities of duplicate debug information are more common,
18348 this code can probably be removed. */
18350 /* Any complete simple types at the top level (pretty much all
18351 of them, for a language without namespaces), can be processed
18353 if (parent_die
== NULL
18354 && pdi
.has_specification
== 0
18355 && pdi
.is_declaration
== 0
18356 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18357 || pdi
.tag
== DW_TAG_base_type
18358 || pdi
.tag
== DW_TAG_subrange_type
))
18360 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18361 add_psymbol_to_list (pdi
.name (cu
), false,
18362 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18363 psymbol_placement::STATIC
,
18364 0, cu
->language
, objfile
);
18365 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18369 /* The exception for DW_TAG_typedef with has_children above is
18370 a workaround of GCC PR debug/47510. In the case of this complaint
18371 type_name_or_error will error on such types later.
18373 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18374 it could not find the child DIEs referenced later, this is checked
18375 above. In correct DWARF DW_TAG_typedef should have no children. */
18377 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18378 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18379 "- DIE at %s [in module %s]"),
18380 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18382 /* If we're at the second level, and we're an enumerator, and
18383 our parent has no specification (meaning possibly lives in a
18384 namespace elsewhere), then we can add the partial symbol now
18385 instead of queueing it. */
18386 if (pdi
.tag
== DW_TAG_enumerator
18387 && parent_die
!= NULL
18388 && parent_die
->die_parent
== NULL
18389 && parent_die
->tag
== DW_TAG_enumeration_type
18390 && parent_die
->has_specification
== 0)
18392 if (pdi
.raw_name
== NULL
)
18393 complaint (_("malformed enumerator DIE ignored"));
18394 else if (building_psymtab
)
18395 add_psymbol_to_list (pdi
.name (cu
), false,
18396 VAR_DOMAIN
, LOC_CONST
, -1,
18397 cu
->language
== language_cplus
18398 ? psymbol_placement::GLOBAL
18399 : psymbol_placement::STATIC
,
18400 0, cu
->language
, objfile
);
18402 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18406 struct partial_die_info
*part_die
18407 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18409 /* We'll save this DIE so link it in. */
18410 part_die
->die_parent
= parent_die
;
18411 part_die
->die_sibling
= NULL
;
18412 part_die
->die_child
= NULL
;
18414 if (last_die
&& last_die
== parent_die
)
18415 last_die
->die_child
= part_die
;
18417 last_die
->die_sibling
= part_die
;
18419 last_die
= part_die
;
18421 if (first_die
== NULL
)
18422 first_die
= part_die
;
18424 /* Maybe add the DIE to the hash table. Not all DIEs that we
18425 find interesting need to be in the hash table, because we
18426 also have the parent/sibling/child chains; only those that we
18427 might refer to by offset later during partial symbol reading.
18429 For now this means things that might have be the target of a
18430 DW_AT_specification, DW_AT_abstract_origin, or
18431 DW_AT_extension. DW_AT_extension will refer only to
18432 namespaces; DW_AT_abstract_origin refers to functions (and
18433 many things under the function DIE, but we do not recurse
18434 into function DIEs during partial symbol reading) and
18435 possibly variables as well; DW_AT_specification refers to
18436 declarations. Declarations ought to have the DW_AT_declaration
18437 flag. It happens that GCC forgets to put it in sometimes, but
18438 only for functions, not for types.
18440 Adding more things than necessary to the hash table is harmless
18441 except for the performance cost. Adding too few will result in
18442 wasted time in find_partial_die, when we reread the compilation
18443 unit with load_all_dies set. */
18446 || abbrev
->tag
== DW_TAG_constant
18447 || abbrev
->tag
== DW_TAG_subprogram
18448 || abbrev
->tag
== DW_TAG_variable
18449 || abbrev
->tag
== DW_TAG_namespace
18450 || part_die
->is_declaration
)
18454 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18455 to_underlying (part_die
->sect_off
),
18460 /* For some DIEs we want to follow their children (if any). For C
18461 we have no reason to follow the children of structures; for other
18462 languages we have to, so that we can get at method physnames
18463 to infer fully qualified class names, for DW_AT_specification,
18464 and for C++ template arguments. For C++, we also look one level
18465 inside functions to find template arguments (if the name of the
18466 function does not already contain the template arguments).
18468 For Ada and Fortran, we need to scan the children of subprograms
18469 and lexical blocks as well because these languages allow the
18470 definition of nested entities that could be interesting for the
18471 debugger, such as nested subprograms for instance. */
18472 if (last_die
->has_children
18474 || last_die
->tag
== DW_TAG_namespace
18475 || last_die
->tag
== DW_TAG_module
18476 || last_die
->tag
== DW_TAG_enumeration_type
18477 || (cu
->language
== language_cplus
18478 && last_die
->tag
== DW_TAG_subprogram
18479 && (last_die
->raw_name
== NULL
18480 || strchr (last_die
->raw_name
, '<') == NULL
))
18481 || (cu
->language
!= language_c
18482 && (last_die
->tag
== DW_TAG_class_type
18483 || last_die
->tag
== DW_TAG_interface_type
18484 || last_die
->tag
== DW_TAG_structure_type
18485 || last_die
->tag
== DW_TAG_union_type
))
18486 || ((cu
->language
== language_ada
18487 || cu
->language
== language_fortran
)
18488 && (last_die
->tag
== DW_TAG_subprogram
18489 || last_die
->tag
== DW_TAG_lexical_block
))))
18492 parent_die
= last_die
;
18496 /* Otherwise we skip to the next sibling, if any. */
18497 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18499 /* Back to the top, do it again. */
18503 partial_die_info::partial_die_info (sect_offset sect_off_
,
18504 struct abbrev_info
*abbrev
)
18505 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18509 /* See class definition. */
18512 partial_die_info::name (dwarf2_cu
*cu
)
18514 if (!canonical_name
&& raw_name
!= nullptr)
18516 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18517 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
18518 canonical_name
= 1;
18524 /* Read a minimal amount of information into the minimal die structure.
18525 INFO_PTR should point just after the initial uleb128 of a DIE. */
18528 partial_die_info::read (const struct die_reader_specs
*reader
,
18529 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18531 struct dwarf2_cu
*cu
= reader
->cu
;
18532 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18534 int has_low_pc_attr
= 0;
18535 int has_high_pc_attr
= 0;
18536 int high_pc_relative
= 0;
18538 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18541 bool need_reprocess
;
18542 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18543 info_ptr
, &need_reprocess
);
18544 /* String and address offsets that need to do the reprocessing have
18545 already been read at this point, so there is no need to wait until
18546 the loop terminates to do the reprocessing. */
18547 if (need_reprocess
)
18548 read_attribute_reprocess (reader
, &attr
);
18549 /* Store the data if it is of an attribute we want to keep in a
18550 partial symbol table. */
18556 case DW_TAG_compile_unit
:
18557 case DW_TAG_partial_unit
:
18558 case DW_TAG_type_unit
:
18559 /* Compilation units have a DW_AT_name that is a filename, not
18560 a source language identifier. */
18561 case DW_TAG_enumeration_type
:
18562 case DW_TAG_enumerator
:
18563 /* These tags always have simple identifiers already; no need
18564 to canonicalize them. */
18565 canonical_name
= 1;
18566 raw_name
= DW_STRING (&attr
);
18569 canonical_name
= 0;
18570 raw_name
= DW_STRING (&attr
);
18574 case DW_AT_linkage_name
:
18575 case DW_AT_MIPS_linkage_name
:
18576 /* Note that both forms of linkage name might appear. We
18577 assume they will be the same, and we only store the last
18579 linkage_name
= attr
.value_as_string ();
18580 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18581 See https://github.com/rust-lang/rust/issues/32925. */
18582 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18583 && strchr (linkage_name
, '{') != NULL
)
18584 linkage_name
= NULL
;
18587 has_low_pc_attr
= 1;
18588 lowpc
= attr
.value_as_address ();
18590 case DW_AT_high_pc
:
18591 has_high_pc_attr
= 1;
18592 highpc
= attr
.value_as_address ();
18593 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18594 high_pc_relative
= 1;
18596 case DW_AT_location
:
18597 /* Support the .debug_loc offsets. */
18598 if (attr
.form_is_block ())
18600 d
.locdesc
= DW_BLOCK (&attr
);
18602 else if (attr
.form_is_section_offset ())
18604 dwarf2_complex_location_expr_complaint ();
18608 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18609 "partial symbol information");
18612 case DW_AT_external
:
18613 is_external
= DW_UNSND (&attr
);
18615 case DW_AT_declaration
:
18616 is_declaration
= DW_UNSND (&attr
);
18621 case DW_AT_abstract_origin
:
18622 case DW_AT_specification
:
18623 case DW_AT_extension
:
18624 has_specification
= 1;
18625 spec_offset
= attr
.get_ref_die_offset ();
18626 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18627 || cu
->per_cu
->is_dwz
);
18629 case DW_AT_sibling
:
18630 /* Ignore absolute siblings, they might point outside of
18631 the current compile unit. */
18632 if (attr
.form
== DW_FORM_ref_addr
)
18633 complaint (_("ignoring absolute DW_AT_sibling"));
18636 const gdb_byte
*buffer
= reader
->buffer
;
18637 sect_offset off
= attr
.get_ref_die_offset ();
18638 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18640 if (sibling_ptr
< info_ptr
)
18641 complaint (_("DW_AT_sibling points backwards"));
18642 else if (sibling_ptr
> reader
->buffer_end
)
18643 reader
->die_section
->overflow_complaint ();
18645 sibling
= sibling_ptr
;
18648 case DW_AT_byte_size
:
18651 case DW_AT_const_value
:
18652 has_const_value
= 1;
18654 case DW_AT_calling_convention
:
18655 /* DWARF doesn't provide a way to identify a program's source-level
18656 entry point. DW_AT_calling_convention attributes are only meant
18657 to describe functions' calling conventions.
18659 However, because it's a necessary piece of information in
18660 Fortran, and before DWARF 4 DW_CC_program was the only
18661 piece of debugging information whose definition refers to
18662 a 'main program' at all, several compilers marked Fortran
18663 main programs with DW_CC_program --- even when those
18664 functions use the standard calling conventions.
18666 Although DWARF now specifies a way to provide this
18667 information, we support this practice for backward
18669 if (DW_UNSND (&attr
) == DW_CC_program
18670 && cu
->language
== language_fortran
)
18671 main_subprogram
= 1;
18674 if (DW_UNSND (&attr
) == DW_INL_inlined
18675 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18676 may_be_inlined
= 1;
18680 if (tag
== DW_TAG_imported_unit
)
18682 d
.sect_off
= attr
.get_ref_die_offset ();
18683 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18684 || cu
->per_cu
->is_dwz
);
18688 case DW_AT_main_subprogram
:
18689 main_subprogram
= DW_UNSND (&attr
);
18694 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18695 but that requires a full DIE, so instead we just
18697 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18698 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18699 + (need_ranges_base
18703 /* Value of the DW_AT_ranges attribute is the offset in the
18704 .debug_ranges section. */
18705 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18716 /* For Ada, if both the name and the linkage name appear, we prefer
18717 the latter. This lets "catch exception" work better, regardless
18718 of the order in which the name and linkage name were emitted.
18719 Really, though, this is just a workaround for the fact that gdb
18720 doesn't store both the name and the linkage name. */
18721 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18722 raw_name
= linkage_name
;
18724 if (high_pc_relative
)
18727 if (has_low_pc_attr
&& has_high_pc_attr
)
18729 /* When using the GNU linker, .gnu.linkonce. sections are used to
18730 eliminate duplicate copies of functions and vtables and such.
18731 The linker will arbitrarily choose one and discard the others.
18732 The AT_*_pc values for such functions refer to local labels in
18733 these sections. If the section from that file was discarded, the
18734 labels are not in the output, so the relocs get a value of 0.
18735 If this is a discarded function, mark the pc bounds as invalid,
18736 so that GDB will ignore it. */
18737 if (lowpc
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
18739 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18740 struct gdbarch
*gdbarch
= objfile
->arch ();
18742 complaint (_("DW_AT_low_pc %s is zero "
18743 "for DIE at %s [in module %s]"),
18744 paddress (gdbarch
, lowpc
),
18745 sect_offset_str (sect_off
),
18746 objfile_name (objfile
));
18748 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18749 else if (lowpc
>= highpc
)
18751 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18752 struct gdbarch
*gdbarch
= objfile
->arch ();
18754 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18755 "for DIE at %s [in module %s]"),
18756 paddress (gdbarch
, lowpc
),
18757 paddress (gdbarch
, highpc
),
18758 sect_offset_str (sect_off
),
18759 objfile_name (objfile
));
18768 /* Find a cached partial DIE at OFFSET in CU. */
18770 struct partial_die_info
*
18771 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18773 struct partial_die_info
*lookup_die
= NULL
;
18774 struct partial_die_info
part_die (sect_off
);
18776 lookup_die
= ((struct partial_die_info
*)
18777 htab_find_with_hash (partial_dies
, &part_die
,
18778 to_underlying (sect_off
)));
18783 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18784 except in the case of .debug_types DIEs which do not reference
18785 outside their CU (they do however referencing other types via
18786 DW_FORM_ref_sig8). */
18788 static const struct cu_partial_die_info
18789 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18791 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18792 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18793 struct partial_die_info
*pd
= NULL
;
18795 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18796 && cu
->header
.offset_in_cu_p (sect_off
))
18798 pd
= cu
->find_partial_die (sect_off
);
18801 /* We missed recording what we needed.
18802 Load all dies and try again. */
18806 /* TUs don't reference other CUs/TUs (except via type signatures). */
18807 if (cu
->per_cu
->is_debug_types
)
18809 error (_("Dwarf Error: Type Unit at offset %s contains"
18810 " external reference to offset %s [in module %s].\n"),
18811 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18812 bfd_get_filename (objfile
->obfd
));
18814 dwarf2_per_cu_data
*per_cu
18815 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18816 dwarf2_per_objfile
);
18818 cu
= dwarf2_per_objfile
->get_cu (per_cu
);
18819 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
18820 load_partial_comp_unit (per_cu
, dwarf2_per_objfile
, nullptr);
18822 cu
= dwarf2_per_objfile
->get_cu (per_cu
);
18825 pd
= cu
->find_partial_die (sect_off
);
18828 /* If we didn't find it, and not all dies have been loaded,
18829 load them all and try again. */
18831 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
18833 cu
->per_cu
->load_all_dies
= 1;
18835 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18836 THIS_CU->cu may already be in use. So we can't just free it and
18837 replace its DIEs with the ones we read in. Instead, we leave those
18838 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18839 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18841 load_partial_comp_unit (cu
->per_cu
, dwarf2_per_objfile
, cu
);
18843 pd
= cu
->find_partial_die (sect_off
);
18847 internal_error (__FILE__
, __LINE__
,
18848 _("could not find partial DIE %s "
18849 "in cache [from module %s]\n"),
18850 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18854 /* See if we can figure out if the class lives in a namespace. We do
18855 this by looking for a member function; its demangled name will
18856 contain namespace info, if there is any. */
18859 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18860 struct dwarf2_cu
*cu
)
18862 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18863 what template types look like, because the demangler
18864 frequently doesn't give the same name as the debug info. We
18865 could fix this by only using the demangled name to get the
18866 prefix (but see comment in read_structure_type). */
18868 struct partial_die_info
*real_pdi
;
18869 struct partial_die_info
*child_pdi
;
18871 /* If this DIE (this DIE's specification, if any) has a parent, then
18872 we should not do this. We'll prepend the parent's fully qualified
18873 name when we create the partial symbol. */
18875 real_pdi
= struct_pdi
;
18876 while (real_pdi
->has_specification
)
18878 auto res
= find_partial_die (real_pdi
->spec_offset
,
18879 real_pdi
->spec_is_dwz
, cu
);
18880 real_pdi
= res
.pdi
;
18884 if (real_pdi
->die_parent
!= NULL
)
18887 for (child_pdi
= struct_pdi
->die_child
;
18889 child_pdi
= child_pdi
->die_sibling
)
18891 if (child_pdi
->tag
== DW_TAG_subprogram
18892 && child_pdi
->linkage_name
!= NULL
)
18894 gdb::unique_xmalloc_ptr
<char> actual_class_name
18895 (language_class_name_from_physname (cu
->language_defn
,
18896 child_pdi
->linkage_name
));
18897 if (actual_class_name
!= NULL
)
18899 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18900 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
18901 struct_pdi
->canonical_name
= 1;
18908 /* Return true if a DIE with TAG may have the DW_AT_const_value
18912 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18916 case DW_TAG_constant
:
18917 case DW_TAG_enumerator
:
18918 case DW_TAG_formal_parameter
:
18919 case DW_TAG_template_value_param
:
18920 case DW_TAG_variable
:
18928 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18930 /* Once we've fixed up a die, there's no point in doing so again.
18931 This also avoids a memory leak if we were to call
18932 guess_partial_die_structure_name multiple times. */
18936 /* If we found a reference attribute and the DIE has no name, try
18937 to find a name in the referred to DIE. */
18939 if (raw_name
== NULL
&& has_specification
)
18941 struct partial_die_info
*spec_die
;
18943 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18944 spec_die
= res
.pdi
;
18947 spec_die
->fixup (cu
);
18949 if (spec_die
->raw_name
)
18951 raw_name
= spec_die
->raw_name
;
18952 canonical_name
= spec_die
->canonical_name
;
18954 /* Copy DW_AT_external attribute if it is set. */
18955 if (spec_die
->is_external
)
18956 is_external
= spec_die
->is_external
;
18960 if (!has_const_value
&& has_specification
18961 && can_have_DW_AT_const_value_p (tag
))
18963 struct partial_die_info
*spec_die
;
18965 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18966 spec_die
= res
.pdi
;
18969 spec_die
->fixup (cu
);
18971 if (spec_die
->has_const_value
)
18973 /* Copy DW_AT_const_value attribute if it is set. */
18974 has_const_value
= spec_die
->has_const_value
;
18978 /* Set default names for some unnamed DIEs. */
18980 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
18982 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
18983 canonical_name
= 1;
18986 /* If there is no parent die to provide a namespace, and there are
18987 children, see if we can determine the namespace from their linkage
18989 if (cu
->language
== language_cplus
18990 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18991 && die_parent
== NULL
18993 && (tag
== DW_TAG_class_type
18994 || tag
== DW_TAG_structure_type
18995 || tag
== DW_TAG_union_type
))
18996 guess_partial_die_structure_name (this, cu
);
18998 /* GCC might emit a nameless struct or union that has a linkage
18999 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19000 if (raw_name
== NULL
19001 && (tag
== DW_TAG_class_type
19002 || tag
== DW_TAG_interface_type
19003 || tag
== DW_TAG_structure_type
19004 || tag
== DW_TAG_union_type
)
19005 && linkage_name
!= NULL
)
19007 gdb::unique_xmalloc_ptr
<char> demangled
19008 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19009 if (demangled
!= nullptr)
19013 /* Strip any leading namespaces/classes, keep only the base name.
19014 DW_AT_name for named DIEs does not contain the prefixes. */
19015 base
= strrchr (demangled
.get (), ':');
19016 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19019 base
= demangled
.get ();
19021 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19022 raw_name
= objfile
->intern (base
);
19023 canonical_name
= 1;
19030 /* Read the .debug_loclists header contents from the given SECTION in the
19033 read_loclist_header (struct loclist_header
*header
,
19034 struct dwarf2_section_info
*section
)
19036 unsigned int bytes_read
;
19037 bfd
*abfd
= section
->get_bfd_owner ();
19038 const gdb_byte
*info_ptr
= section
->buffer
;
19039 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19040 info_ptr
+= bytes_read
;
19041 header
->version
= read_2_bytes (abfd
, info_ptr
);
19043 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19045 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19047 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19050 /* Return the DW_AT_loclists_base value for the CU. */
19052 lookup_loclist_base (struct dwarf2_cu
*cu
)
19054 /* For the .dwo unit, the loclist_base points to the first offset following
19055 the header. The header consists of the following entities-
19056 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19058 2. version (2 bytes)
19059 3. address size (1 byte)
19060 4. segment selector size (1 byte)
19061 5. offset entry count (4 bytes)
19062 These sizes are derived as per the DWARFv5 standard. */
19063 if (cu
->dwo_unit
!= nullptr)
19065 if (cu
->header
.initial_length_size
== 4)
19066 return LOCLIST_HEADER_SIZE32
;
19067 return LOCLIST_HEADER_SIZE64
;
19069 return cu
->loclist_base
;
19072 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19073 array of offsets in the .debug_loclists section. */
19075 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19077 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19078 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19079 bfd
*abfd
= objfile
->obfd
;
19080 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19081 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19083 section
->read (objfile
);
19084 if (section
->buffer
== NULL
)
19085 complaint (_("DW_FORM_loclistx used without .debug_loclists "
19086 "section [in module %s]"), objfile_name (objfile
));
19087 struct loclist_header header
;
19088 read_loclist_header (&header
, section
);
19089 if (loclist_index
>= header
.offset_entry_count
)
19090 complaint (_("DW_FORM_loclistx pointing outside of "
19091 ".debug_loclists offset array [in module %s]"),
19092 objfile_name (objfile
));
19093 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
19095 complaint (_("DW_FORM_loclistx pointing outside of "
19096 ".debug_loclists section [in module %s]"),
19097 objfile_name (objfile
));
19098 const gdb_byte
*info_ptr
19099 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19101 if (cu
->header
.offset_size
== 4)
19102 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
19104 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
19107 /* Process the attributes that had to be skipped in the first round. These
19108 attributes are the ones that need str_offsets_base or addr_base attributes.
19109 They could not have been processed in the first round, because at the time
19110 the values of str_offsets_base or addr_base may not have been known. */
19112 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19113 struct attribute
*attr
)
19115 struct dwarf2_cu
*cu
= reader
->cu
;
19116 switch (attr
->form
)
19118 case DW_FORM_addrx
:
19119 case DW_FORM_GNU_addr_index
:
19120 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19122 case DW_FORM_loclistx
:
19123 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19126 case DW_FORM_strx1
:
19127 case DW_FORM_strx2
:
19128 case DW_FORM_strx3
:
19129 case DW_FORM_strx4
:
19130 case DW_FORM_GNU_str_index
:
19132 unsigned int str_index
= DW_UNSND (attr
);
19133 if (reader
->dwo_file
!= NULL
)
19135 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19136 DW_STRING_IS_CANONICAL (attr
) = 0;
19140 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19141 DW_STRING_IS_CANONICAL (attr
) = 0;
19146 gdb_assert_not_reached (_("Unexpected DWARF form."));
19150 /* Read an attribute value described by an attribute form. */
19152 static const gdb_byte
*
19153 read_attribute_value (const struct die_reader_specs
*reader
,
19154 struct attribute
*attr
, unsigned form
,
19155 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19156 bool *need_reprocess
)
19158 struct dwarf2_cu
*cu
= reader
->cu
;
19159 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19160 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19161 bfd
*abfd
= reader
->abfd
;
19162 struct comp_unit_head
*cu_header
= &cu
->header
;
19163 unsigned int bytes_read
;
19164 struct dwarf_block
*blk
;
19165 *need_reprocess
= false;
19167 attr
->form
= (enum dwarf_form
) form
;
19170 case DW_FORM_ref_addr
:
19171 if (cu
->header
.version
== 2)
19172 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19175 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19177 info_ptr
+= bytes_read
;
19179 case DW_FORM_GNU_ref_alt
:
19180 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19181 info_ptr
+= bytes_read
;
19185 struct gdbarch
*gdbarch
= objfile
->arch ();
19186 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19187 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19188 info_ptr
+= bytes_read
;
19191 case DW_FORM_block2
:
19192 blk
= dwarf_alloc_block (cu
);
19193 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19195 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19196 info_ptr
+= blk
->size
;
19197 DW_BLOCK (attr
) = blk
;
19199 case DW_FORM_block4
:
19200 blk
= dwarf_alloc_block (cu
);
19201 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19203 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19204 info_ptr
+= blk
->size
;
19205 DW_BLOCK (attr
) = blk
;
19207 case DW_FORM_data2
:
19208 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19211 case DW_FORM_data4
:
19212 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19215 case DW_FORM_data8
:
19216 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19219 case DW_FORM_data16
:
19220 blk
= dwarf_alloc_block (cu
);
19222 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19224 DW_BLOCK (attr
) = blk
;
19226 case DW_FORM_sec_offset
:
19227 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19228 info_ptr
+= bytes_read
;
19230 case DW_FORM_loclistx
:
19232 *need_reprocess
= true;
19233 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19234 info_ptr
+= bytes_read
;
19237 case DW_FORM_string
:
19238 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19239 DW_STRING_IS_CANONICAL (attr
) = 0;
19240 info_ptr
+= bytes_read
;
19243 if (!cu
->per_cu
->is_dwz
)
19245 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19246 abfd
, info_ptr
, cu_header
,
19248 DW_STRING_IS_CANONICAL (attr
) = 0;
19249 info_ptr
+= bytes_read
;
19253 case DW_FORM_line_strp
:
19254 if (!cu
->per_cu
->is_dwz
)
19257 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
19259 DW_STRING_IS_CANONICAL (attr
) = 0;
19260 info_ptr
+= bytes_read
;
19264 case DW_FORM_GNU_strp_alt
:
19266 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19267 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19270 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19271 DW_STRING_IS_CANONICAL (attr
) = 0;
19272 info_ptr
+= bytes_read
;
19275 case DW_FORM_exprloc
:
19276 case DW_FORM_block
:
19277 blk
= dwarf_alloc_block (cu
);
19278 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19279 info_ptr
+= bytes_read
;
19280 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19281 info_ptr
+= blk
->size
;
19282 DW_BLOCK (attr
) = blk
;
19284 case DW_FORM_block1
:
19285 blk
= dwarf_alloc_block (cu
);
19286 blk
->size
= read_1_byte (abfd
, info_ptr
);
19288 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19289 info_ptr
+= blk
->size
;
19290 DW_BLOCK (attr
) = blk
;
19292 case DW_FORM_data1
:
19293 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19297 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19300 case DW_FORM_flag_present
:
19301 DW_UNSND (attr
) = 1;
19303 case DW_FORM_sdata
:
19304 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19305 info_ptr
+= bytes_read
;
19307 case DW_FORM_udata
:
19308 case DW_FORM_rnglistx
:
19309 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19310 info_ptr
+= bytes_read
;
19313 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19314 + read_1_byte (abfd
, info_ptr
));
19318 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19319 + read_2_bytes (abfd
, info_ptr
));
19323 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19324 + read_4_bytes (abfd
, info_ptr
));
19328 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19329 + read_8_bytes (abfd
, info_ptr
));
19332 case DW_FORM_ref_sig8
:
19333 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19336 case DW_FORM_ref_udata
:
19337 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19338 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19339 info_ptr
+= bytes_read
;
19341 case DW_FORM_indirect
:
19342 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19343 info_ptr
+= bytes_read
;
19344 if (form
== DW_FORM_implicit_const
)
19346 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19347 info_ptr
+= bytes_read
;
19349 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19350 info_ptr
, need_reprocess
);
19352 case DW_FORM_implicit_const
:
19353 DW_SND (attr
) = implicit_const
;
19355 case DW_FORM_addrx
:
19356 case DW_FORM_GNU_addr_index
:
19357 *need_reprocess
= true;
19358 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19359 info_ptr
+= bytes_read
;
19362 case DW_FORM_strx1
:
19363 case DW_FORM_strx2
:
19364 case DW_FORM_strx3
:
19365 case DW_FORM_strx4
:
19366 case DW_FORM_GNU_str_index
:
19368 ULONGEST str_index
;
19369 if (form
== DW_FORM_strx1
)
19371 str_index
= read_1_byte (abfd
, info_ptr
);
19374 else if (form
== DW_FORM_strx2
)
19376 str_index
= read_2_bytes (abfd
, info_ptr
);
19379 else if (form
== DW_FORM_strx3
)
19381 str_index
= read_3_bytes (abfd
, info_ptr
);
19384 else if (form
== DW_FORM_strx4
)
19386 str_index
= read_4_bytes (abfd
, info_ptr
);
19391 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19392 info_ptr
+= bytes_read
;
19394 *need_reprocess
= true;
19395 DW_UNSND (attr
) = str_index
;
19399 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19400 dwarf_form_name (form
),
19401 bfd_get_filename (abfd
));
19405 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19406 attr
->form
= DW_FORM_GNU_ref_alt
;
19408 /* We have seen instances where the compiler tried to emit a byte
19409 size attribute of -1 which ended up being encoded as an unsigned
19410 0xffffffff. Although 0xffffffff is technically a valid size value,
19411 an object of this size seems pretty unlikely so we can relatively
19412 safely treat these cases as if the size attribute was invalid and
19413 treat them as zero by default. */
19414 if (attr
->name
== DW_AT_byte_size
19415 && form
== DW_FORM_data4
19416 && DW_UNSND (attr
) >= 0xffffffff)
19419 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19420 hex_string (DW_UNSND (attr
)));
19421 DW_UNSND (attr
) = 0;
19427 /* Read an attribute described by an abbreviated attribute. */
19429 static const gdb_byte
*
19430 read_attribute (const struct die_reader_specs
*reader
,
19431 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19432 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19434 attr
->name
= abbrev
->name
;
19435 return read_attribute_value (reader
, attr
, abbrev
->form
,
19436 abbrev
->implicit_const
, info_ptr
,
19440 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19442 static const char *
19443 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19444 LONGEST str_offset
)
19446 return dwarf2_per_objfile
->per_bfd
->str
.read_string
19447 (dwarf2_per_objfile
->objfile
, str_offset
, "DW_FORM_strp");
19450 /* Return pointer to string at .debug_str offset as read from BUF.
19451 BUF is assumed to be in a compilation unit described by CU_HEADER.
19452 Return *BYTES_READ_PTR count of bytes read from BUF. */
19454 static const char *
19455 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19456 const gdb_byte
*buf
,
19457 const struct comp_unit_head
*cu_header
,
19458 unsigned int *bytes_read_ptr
)
19460 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19462 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
19468 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19469 const struct comp_unit_head
*cu_header
,
19470 unsigned int *bytes_read_ptr
)
19472 bfd
*abfd
= objfile
->obfd
;
19473 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19475 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19478 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19479 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19480 ADDR_SIZE is the size of addresses from the CU header. */
19483 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19484 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19487 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19488 bfd
*abfd
= objfile
->obfd
;
19489 const gdb_byte
*info_ptr
;
19490 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19492 dwarf2_per_objfile
->per_bfd
->addr
.read (objfile
);
19493 if (dwarf2_per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19494 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19495 objfile_name (objfile
));
19496 if (addr_base_or_zero
+ addr_index
* addr_size
19497 >= dwarf2_per_objfile
->per_bfd
->addr
.size
)
19498 error (_("DW_FORM_addr_index pointing outside of "
19499 ".debug_addr section [in module %s]"),
19500 objfile_name (objfile
));
19501 info_ptr
= (dwarf2_per_objfile
->per_bfd
->addr
.buffer
19502 + addr_base_or_zero
+ addr_index
* addr_size
);
19503 if (addr_size
== 4)
19504 return bfd_get_32 (abfd
, info_ptr
);
19506 return bfd_get_64 (abfd
, info_ptr
);
19509 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19512 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19514 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19515 cu
->addr_base
, cu
->header
.addr_size
);
19518 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19521 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19522 unsigned int *bytes_read
)
19524 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19525 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19527 return read_addr_index (cu
, addr_index
);
19533 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19534 dwarf2_per_objfile
*dwarf2_per_objfile
,
19535 unsigned int addr_index
)
19537 struct dwarf2_cu
*cu
= dwarf2_per_objfile
->get_cu (per_cu
);
19538 gdb::optional
<ULONGEST
> addr_base
;
19541 /* We need addr_base and addr_size.
19542 If we don't have PER_CU->cu, we have to get it.
19543 Nasty, but the alternative is storing the needed info in PER_CU,
19544 which at this point doesn't seem justified: it's not clear how frequently
19545 it would get used and it would increase the size of every PER_CU.
19546 Entry points like dwarf2_per_cu_addr_size do a similar thing
19547 so we're not in uncharted territory here.
19548 Alas we need to be a bit more complicated as addr_base is contained
19551 We don't need to read the entire CU(/TU).
19552 We just need the header and top level die.
19554 IWBN to use the aging mechanism to let us lazily later discard the CU.
19555 For now we skip this optimization. */
19559 addr_base
= cu
->addr_base
;
19560 addr_size
= cu
->header
.addr_size
;
19564 cutu_reader
reader (per_cu
, dwarf2_per_objfile
, nullptr, nullptr, false);
19565 addr_base
= reader
.cu
->addr_base
;
19566 addr_size
= reader
.cu
->header
.addr_size
;
19569 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19573 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19574 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19577 static const char *
19578 read_str_index (struct dwarf2_cu
*cu
,
19579 struct dwarf2_section_info
*str_section
,
19580 struct dwarf2_section_info
*str_offsets_section
,
19581 ULONGEST str_offsets_base
, ULONGEST str_index
)
19583 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19584 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19585 const char *objf_name
= objfile_name (objfile
);
19586 bfd
*abfd
= objfile
->obfd
;
19587 const gdb_byte
*info_ptr
;
19588 ULONGEST str_offset
;
19589 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19591 str_section
->read (objfile
);
19592 str_offsets_section
->read (objfile
);
19593 if (str_section
->buffer
== NULL
)
19594 error (_("%s used without %s section"
19595 " in CU at offset %s [in module %s]"),
19596 form_name
, str_section
->get_name (),
19597 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19598 if (str_offsets_section
->buffer
== NULL
)
19599 error (_("%s used without %s section"
19600 " in CU at offset %s [in module %s]"),
19601 form_name
, str_section
->get_name (),
19602 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19603 info_ptr
= (str_offsets_section
->buffer
19605 + str_index
* cu
->header
.offset_size
);
19606 if (cu
->header
.offset_size
== 4)
19607 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19609 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19610 if (str_offset
>= str_section
->size
)
19611 error (_("Offset from %s pointing outside of"
19612 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19613 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19614 return (const char *) (str_section
->buffer
+ str_offset
);
19617 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19619 static const char *
19620 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19622 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19623 ? reader
->cu
->header
.addr_size
: 0;
19624 return read_str_index (reader
->cu
,
19625 &reader
->dwo_file
->sections
.str
,
19626 &reader
->dwo_file
->sections
.str_offsets
,
19627 str_offsets_base
, str_index
);
19630 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19632 static const char *
19633 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19635 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19636 const char *objf_name
= objfile_name (objfile
);
19637 static const char form_name
[] = "DW_FORM_GNU_str_index";
19638 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19640 if (!cu
->str_offsets_base
.has_value ())
19641 error (_("%s used in Fission stub without %s"
19642 " in CU at offset 0x%lx [in module %s]"),
19643 form_name
, str_offsets_attr_name
,
19644 (long) cu
->header
.offset_size
, objf_name
);
19646 return read_str_index (cu
,
19647 &cu
->per_objfile
->per_bfd
->str
,
19648 &cu
->per_objfile
->per_bfd
->str_offsets
,
19649 *cu
->str_offsets_base
, str_index
);
19652 /* Return the length of an LEB128 number in BUF. */
19655 leb128_size (const gdb_byte
*buf
)
19657 const gdb_byte
*begin
= buf
;
19663 if ((byte
& 128) == 0)
19664 return buf
- begin
;
19669 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19678 cu
->language
= language_c
;
19681 case DW_LANG_C_plus_plus
:
19682 case DW_LANG_C_plus_plus_11
:
19683 case DW_LANG_C_plus_plus_14
:
19684 cu
->language
= language_cplus
;
19687 cu
->language
= language_d
;
19689 case DW_LANG_Fortran77
:
19690 case DW_LANG_Fortran90
:
19691 case DW_LANG_Fortran95
:
19692 case DW_LANG_Fortran03
:
19693 case DW_LANG_Fortran08
:
19694 cu
->language
= language_fortran
;
19697 cu
->language
= language_go
;
19699 case DW_LANG_Mips_Assembler
:
19700 cu
->language
= language_asm
;
19702 case DW_LANG_Ada83
:
19703 case DW_LANG_Ada95
:
19704 cu
->language
= language_ada
;
19706 case DW_LANG_Modula2
:
19707 cu
->language
= language_m2
;
19709 case DW_LANG_Pascal83
:
19710 cu
->language
= language_pascal
;
19713 cu
->language
= language_objc
;
19716 case DW_LANG_Rust_old
:
19717 cu
->language
= language_rust
;
19719 case DW_LANG_Cobol74
:
19720 case DW_LANG_Cobol85
:
19722 cu
->language
= language_minimal
;
19725 cu
->language_defn
= language_def (cu
->language
);
19728 /* Return the named attribute or NULL if not there. */
19730 static struct attribute
*
19731 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19736 struct attribute
*spec
= NULL
;
19738 for (i
= 0; i
< die
->num_attrs
; ++i
)
19740 if (die
->attrs
[i
].name
== name
)
19741 return &die
->attrs
[i
];
19742 if (die
->attrs
[i
].name
== DW_AT_specification
19743 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19744 spec
= &die
->attrs
[i
];
19750 die
= follow_die_ref (die
, spec
, &cu
);
19756 /* Return the string associated with a string-typed attribute, or NULL if it
19757 is either not found or is of an incorrect type. */
19759 static const char *
19760 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19762 struct attribute
*attr
;
19763 const char *str
= NULL
;
19765 attr
= dwarf2_attr (die
, name
, cu
);
19769 str
= attr
->value_as_string ();
19770 if (str
== nullptr)
19771 complaint (_("string type expected for attribute %s for "
19772 "DIE at %s in module %s"),
19773 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19774 objfile_name (cu
->per_objfile
->objfile
));
19780 /* Return the dwo name or NULL if not present. If present, it is in either
19781 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19782 static const char *
19783 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19785 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19786 if (dwo_name
== nullptr)
19787 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19791 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19792 and holds a non-zero value. This function should only be used for
19793 DW_FORM_flag or DW_FORM_flag_present attributes. */
19796 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19798 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19800 return (attr
&& DW_UNSND (attr
));
19804 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19806 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19807 which value is non-zero. However, we have to be careful with
19808 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19809 (via dwarf2_flag_true_p) follows this attribute. So we may
19810 end up accidently finding a declaration attribute that belongs
19811 to a different DIE referenced by the specification attribute,
19812 even though the given DIE does not have a declaration attribute. */
19813 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19814 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19817 /* Return the die giving the specification for DIE, if there is
19818 one. *SPEC_CU is the CU containing DIE on input, and the CU
19819 containing the return value on output. If there is no
19820 specification, but there is an abstract origin, that is
19823 static struct die_info
*
19824 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19826 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19829 if (spec_attr
== NULL
)
19830 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19832 if (spec_attr
== NULL
)
19835 return follow_die_ref (die
, spec_attr
, spec_cu
);
19838 /* Stub for free_line_header to match void * callback types. */
19841 free_line_header_voidp (void *arg
)
19843 struct line_header
*lh
= (struct line_header
*) arg
;
19848 /* A convenience function to find the proper .debug_line section for a CU. */
19850 static struct dwarf2_section_info
*
19851 get_debug_line_section (struct dwarf2_cu
*cu
)
19853 struct dwarf2_section_info
*section
;
19854 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19856 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19858 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19859 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19860 else if (cu
->per_cu
->is_dwz
)
19862 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19864 section
= &dwz
->line
;
19867 section
= &dwarf2_per_objfile
->per_bfd
->line
;
19872 /* Read the statement program header starting at OFFSET in
19873 .debug_line, or .debug_line.dwo. Return a pointer
19874 to a struct line_header, allocated using xmalloc.
19875 Returns NULL if there is a problem reading the header, e.g., if it
19876 has a version we don't understand.
19878 NOTE: the strings in the include directory and file name tables of
19879 the returned object point into the dwarf line section buffer,
19880 and must not be freed. */
19882 static line_header_up
19883 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19885 struct dwarf2_section_info
*section
;
19886 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19888 section
= get_debug_line_section (cu
);
19889 section
->read (dwarf2_per_objfile
->objfile
);
19890 if (section
->buffer
== NULL
)
19892 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19893 complaint (_("missing .debug_line.dwo section"));
19895 complaint (_("missing .debug_line section"));
19899 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19900 dwarf2_per_objfile
, section
,
19904 /* Subroutine of dwarf_decode_lines to simplify it.
19905 Return the file name of the psymtab for the given file_entry.
19906 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19907 If space for the result is malloc'd, *NAME_HOLDER will be set.
19908 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19910 static const char *
19911 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19912 const dwarf2_psymtab
*pst
,
19913 const char *comp_dir
,
19914 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19916 const char *include_name
= fe
.name
;
19917 const char *include_name_to_compare
= include_name
;
19918 const char *pst_filename
;
19921 const char *dir_name
= fe
.include_dir (lh
);
19923 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19924 if (!IS_ABSOLUTE_PATH (include_name
)
19925 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19927 /* Avoid creating a duplicate psymtab for PST.
19928 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19929 Before we do the comparison, however, we need to account
19930 for DIR_NAME and COMP_DIR.
19931 First prepend dir_name (if non-NULL). If we still don't
19932 have an absolute path prepend comp_dir (if non-NULL).
19933 However, the directory we record in the include-file's
19934 psymtab does not contain COMP_DIR (to match the
19935 corresponding symtab(s)).
19940 bash$ gcc -g ./hello.c
19941 include_name = "hello.c"
19943 DW_AT_comp_dir = comp_dir = "/tmp"
19944 DW_AT_name = "./hello.c"
19948 if (dir_name
!= NULL
)
19950 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19951 include_name
, (char *) NULL
));
19952 include_name
= name_holder
->get ();
19953 include_name_to_compare
= include_name
;
19955 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19957 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19958 include_name
, (char *) NULL
));
19959 include_name_to_compare
= hold_compare
.get ();
19963 pst_filename
= pst
->filename
;
19964 gdb::unique_xmalloc_ptr
<char> copied_name
;
19965 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19967 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19968 pst_filename
, (char *) NULL
));
19969 pst_filename
= copied_name
.get ();
19972 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19976 return include_name
;
19979 /* State machine to track the state of the line number program. */
19981 class lnp_state_machine
19984 /* Initialize a machine state for the start of a line number
19986 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19987 bool record_lines_p
);
19989 file_entry
*current_file ()
19991 /* lh->file_names is 0-based, but the file name numbers in the
19992 statement program are 1-based. */
19993 return m_line_header
->file_name_at (m_file
);
19996 /* Record the line in the state machine. END_SEQUENCE is true if
19997 we're processing the end of a sequence. */
19998 void record_line (bool end_sequence
);
20000 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20001 nop-out rest of the lines in this sequence. */
20002 void check_line_address (struct dwarf2_cu
*cu
,
20003 const gdb_byte
*line_ptr
,
20004 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20006 void handle_set_discriminator (unsigned int discriminator
)
20008 m_discriminator
= discriminator
;
20009 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20012 /* Handle DW_LNE_set_address. */
20013 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20016 address
+= baseaddr
;
20017 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20020 /* Handle DW_LNS_advance_pc. */
20021 void handle_advance_pc (CORE_ADDR adjust
);
20023 /* Handle a special opcode. */
20024 void handle_special_opcode (unsigned char op_code
);
20026 /* Handle DW_LNS_advance_line. */
20027 void handle_advance_line (int line_delta
)
20029 advance_line (line_delta
);
20032 /* Handle DW_LNS_set_file. */
20033 void handle_set_file (file_name_index file
);
20035 /* Handle DW_LNS_negate_stmt. */
20036 void handle_negate_stmt ()
20038 m_is_stmt
= !m_is_stmt
;
20041 /* Handle DW_LNS_const_add_pc. */
20042 void handle_const_add_pc ();
20044 /* Handle DW_LNS_fixed_advance_pc. */
20045 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20047 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20051 /* Handle DW_LNS_copy. */
20052 void handle_copy ()
20054 record_line (false);
20055 m_discriminator
= 0;
20058 /* Handle DW_LNE_end_sequence. */
20059 void handle_end_sequence ()
20061 m_currently_recording_lines
= true;
20065 /* Advance the line by LINE_DELTA. */
20066 void advance_line (int line_delta
)
20068 m_line
+= line_delta
;
20070 if (line_delta
!= 0)
20071 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20074 struct dwarf2_cu
*m_cu
;
20076 gdbarch
*m_gdbarch
;
20078 /* True if we're recording lines.
20079 Otherwise we're building partial symtabs and are just interested in
20080 finding include files mentioned by the line number program. */
20081 bool m_record_lines_p
;
20083 /* The line number header. */
20084 line_header
*m_line_header
;
20086 /* These are part of the standard DWARF line number state machine,
20087 and initialized according to the DWARF spec. */
20089 unsigned char m_op_index
= 0;
20090 /* The line table index of the current file. */
20091 file_name_index m_file
= 1;
20092 unsigned int m_line
= 1;
20094 /* These are initialized in the constructor. */
20096 CORE_ADDR m_address
;
20098 unsigned int m_discriminator
;
20100 /* Additional bits of state we need to track. */
20102 /* The last file that we called dwarf2_start_subfile for.
20103 This is only used for TLLs. */
20104 unsigned int m_last_file
= 0;
20105 /* The last file a line number was recorded for. */
20106 struct subfile
*m_last_subfile
= NULL
;
20108 /* When true, record the lines we decode. */
20109 bool m_currently_recording_lines
= false;
20111 /* The last line number that was recorded, used to coalesce
20112 consecutive entries for the same line. This can happen, for
20113 example, when discriminators are present. PR 17276. */
20114 unsigned int m_last_line
= 0;
20115 bool m_line_has_non_zero_discriminator
= false;
20119 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20121 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20122 / m_line_header
->maximum_ops_per_instruction
)
20123 * m_line_header
->minimum_instruction_length
);
20124 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20125 m_op_index
= ((m_op_index
+ adjust
)
20126 % m_line_header
->maximum_ops_per_instruction
);
20130 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20132 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20133 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20134 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20135 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20136 / m_line_header
->maximum_ops_per_instruction
)
20137 * m_line_header
->minimum_instruction_length
);
20138 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20139 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20140 % m_line_header
->maximum_ops_per_instruction
);
20142 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20143 advance_line (line_delta
);
20144 record_line (false);
20145 m_discriminator
= 0;
20149 lnp_state_machine::handle_set_file (file_name_index file
)
20153 const file_entry
*fe
= current_file ();
20155 dwarf2_debug_line_missing_file_complaint ();
20156 else if (m_record_lines_p
)
20158 const char *dir
= fe
->include_dir (m_line_header
);
20160 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20161 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20162 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20167 lnp_state_machine::handle_const_add_pc ()
20170 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20173 = (((m_op_index
+ adjust
)
20174 / m_line_header
->maximum_ops_per_instruction
)
20175 * m_line_header
->minimum_instruction_length
);
20177 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20178 m_op_index
= ((m_op_index
+ adjust
)
20179 % m_line_header
->maximum_ops_per_instruction
);
20182 /* Return non-zero if we should add LINE to the line number table.
20183 LINE is the line to add, LAST_LINE is the last line that was added,
20184 LAST_SUBFILE is the subfile for LAST_LINE.
20185 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20186 had a non-zero discriminator.
20188 We have to be careful in the presence of discriminators.
20189 E.g., for this line:
20191 for (i = 0; i < 100000; i++);
20193 clang can emit four line number entries for that one line,
20194 each with a different discriminator.
20195 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20197 However, we want gdb to coalesce all four entries into one.
20198 Otherwise the user could stepi into the middle of the line and
20199 gdb would get confused about whether the pc really was in the
20200 middle of the line.
20202 Things are further complicated by the fact that two consecutive
20203 line number entries for the same line is a heuristic used by gcc
20204 to denote the end of the prologue. So we can't just discard duplicate
20205 entries, we have to be selective about it. The heuristic we use is
20206 that we only collapse consecutive entries for the same line if at least
20207 one of those entries has a non-zero discriminator. PR 17276.
20209 Note: Addresses in the line number state machine can never go backwards
20210 within one sequence, thus this coalescing is ok. */
20213 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20214 unsigned int line
, unsigned int last_line
,
20215 int line_has_non_zero_discriminator
,
20216 struct subfile
*last_subfile
)
20218 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20220 if (line
!= last_line
)
20222 /* Same line for the same file that we've seen already.
20223 As a last check, for pr 17276, only record the line if the line
20224 has never had a non-zero discriminator. */
20225 if (!line_has_non_zero_discriminator
)
20230 /* Use the CU's builder to record line number LINE beginning at
20231 address ADDRESS in the line table of subfile SUBFILE. */
20234 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20235 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20236 struct dwarf2_cu
*cu
)
20238 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20240 if (dwarf_line_debug
)
20242 fprintf_unfiltered (gdb_stdlog
,
20243 "Recording line %u, file %s, address %s\n",
20244 line
, lbasename (subfile
->name
),
20245 paddress (gdbarch
, address
));
20249 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20252 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20253 Mark the end of a set of line number records.
20254 The arguments are the same as for dwarf_record_line_1.
20255 If SUBFILE is NULL the request is ignored. */
20258 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20259 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20261 if (subfile
== NULL
)
20264 if (dwarf_line_debug
)
20266 fprintf_unfiltered (gdb_stdlog
,
20267 "Finishing current line, file %s, address %s\n",
20268 lbasename (subfile
->name
),
20269 paddress (gdbarch
, address
));
20272 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20276 lnp_state_machine::record_line (bool end_sequence
)
20278 if (dwarf_line_debug
)
20280 fprintf_unfiltered (gdb_stdlog
,
20281 "Processing actual line %u: file %u,"
20282 " address %s, is_stmt %u, discrim %u%s\n",
20284 paddress (m_gdbarch
, m_address
),
20285 m_is_stmt
, m_discriminator
,
20286 (end_sequence
? "\t(end sequence)" : ""));
20289 file_entry
*fe
= current_file ();
20292 dwarf2_debug_line_missing_file_complaint ();
20293 /* For now we ignore lines not starting on an instruction boundary.
20294 But not when processing end_sequence for compatibility with the
20295 previous version of the code. */
20296 else if (m_op_index
== 0 || end_sequence
)
20298 fe
->included_p
= 1;
20299 if (m_record_lines_p
)
20301 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20304 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20305 m_currently_recording_lines
? m_cu
: nullptr);
20310 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20312 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20313 m_line_has_non_zero_discriminator
,
20316 buildsym_compunit
*builder
= m_cu
->get_builder ();
20317 dwarf_record_line_1 (m_gdbarch
,
20318 builder
->get_current_subfile (),
20319 m_line
, m_address
, is_stmt
,
20320 m_currently_recording_lines
? m_cu
: nullptr);
20322 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20323 m_last_line
= m_line
;
20329 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20330 line_header
*lh
, bool record_lines_p
)
20334 m_record_lines_p
= record_lines_p
;
20335 m_line_header
= lh
;
20337 m_currently_recording_lines
= true;
20339 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20340 was a line entry for it so that the backend has a chance to adjust it
20341 and also record it in case it needs it. This is currently used by MIPS
20342 code, cf. `mips_adjust_dwarf2_line'. */
20343 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20344 m_is_stmt
= lh
->default_is_stmt
;
20345 m_discriminator
= 0;
20349 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20350 const gdb_byte
*line_ptr
,
20351 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20353 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20354 the pc range of the CU. However, we restrict the test to only ADDRESS
20355 values of zero to preserve GDB's previous behaviour which is to handle
20356 the specific case of a function being GC'd by the linker. */
20358 if (address
== 0 && address
< unrelocated_lowpc
)
20360 /* This line table is for a function which has been
20361 GCd by the linker. Ignore it. PR gdb/12528 */
20363 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20364 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20366 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20367 line_offset
, objfile_name (objfile
));
20368 m_currently_recording_lines
= false;
20369 /* Note: m_currently_recording_lines is left as false until we see
20370 DW_LNE_end_sequence. */
20374 /* Subroutine of dwarf_decode_lines to simplify it.
20375 Process the line number information in LH.
20376 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20377 program in order to set included_p for every referenced header. */
20380 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20381 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20383 const gdb_byte
*line_ptr
, *extended_end
;
20384 const gdb_byte
*line_end
;
20385 unsigned int bytes_read
, extended_len
;
20386 unsigned char op_code
, extended_op
;
20387 CORE_ADDR baseaddr
;
20388 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20389 bfd
*abfd
= objfile
->obfd
;
20390 struct gdbarch
*gdbarch
= objfile
->arch ();
20391 /* True if we're recording line info (as opposed to building partial
20392 symtabs and just interested in finding include files mentioned by
20393 the line number program). */
20394 bool record_lines_p
= !decode_for_pst_p
;
20396 baseaddr
= objfile
->text_section_offset ();
20398 line_ptr
= lh
->statement_program_start
;
20399 line_end
= lh
->statement_program_end
;
20401 /* Read the statement sequences until there's nothing left. */
20402 while (line_ptr
< line_end
)
20404 /* The DWARF line number program state machine. Reset the state
20405 machine at the start of each sequence. */
20406 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20407 bool end_sequence
= false;
20409 if (record_lines_p
)
20411 /* Start a subfile for the current file of the state
20413 const file_entry
*fe
= state_machine
.current_file ();
20416 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20419 /* Decode the table. */
20420 while (line_ptr
< line_end
&& !end_sequence
)
20422 op_code
= read_1_byte (abfd
, line_ptr
);
20425 if (op_code
>= lh
->opcode_base
)
20427 /* Special opcode. */
20428 state_machine
.handle_special_opcode (op_code
);
20430 else switch (op_code
)
20432 case DW_LNS_extended_op
:
20433 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20435 line_ptr
+= bytes_read
;
20436 extended_end
= line_ptr
+ extended_len
;
20437 extended_op
= read_1_byte (abfd
, line_ptr
);
20439 switch (extended_op
)
20441 case DW_LNE_end_sequence
:
20442 state_machine
.handle_end_sequence ();
20443 end_sequence
= true;
20445 case DW_LNE_set_address
:
20448 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20449 line_ptr
+= bytes_read
;
20451 state_machine
.check_line_address (cu
, line_ptr
,
20452 lowpc
- baseaddr
, address
);
20453 state_machine
.handle_set_address (baseaddr
, address
);
20456 case DW_LNE_define_file
:
20458 const char *cur_file
;
20459 unsigned int mod_time
, length
;
20462 cur_file
= read_direct_string (abfd
, line_ptr
,
20464 line_ptr
+= bytes_read
;
20465 dindex
= (dir_index
)
20466 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20467 line_ptr
+= bytes_read
;
20469 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20470 line_ptr
+= bytes_read
;
20472 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20473 line_ptr
+= bytes_read
;
20474 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20477 case DW_LNE_set_discriminator
:
20479 /* The discriminator is not interesting to the
20480 debugger; just ignore it. We still need to
20481 check its value though:
20482 if there are consecutive entries for the same
20483 (non-prologue) line we want to coalesce them.
20486 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20487 line_ptr
+= bytes_read
;
20489 state_machine
.handle_set_discriminator (discr
);
20493 complaint (_("mangled .debug_line section"));
20496 /* Make sure that we parsed the extended op correctly. If e.g.
20497 we expected a different address size than the producer used,
20498 we may have read the wrong number of bytes. */
20499 if (line_ptr
!= extended_end
)
20501 complaint (_("mangled .debug_line section"));
20506 state_machine
.handle_copy ();
20508 case DW_LNS_advance_pc
:
20511 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20512 line_ptr
+= bytes_read
;
20514 state_machine
.handle_advance_pc (adjust
);
20517 case DW_LNS_advance_line
:
20520 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20521 line_ptr
+= bytes_read
;
20523 state_machine
.handle_advance_line (line_delta
);
20526 case DW_LNS_set_file
:
20528 file_name_index file
20529 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20531 line_ptr
+= bytes_read
;
20533 state_machine
.handle_set_file (file
);
20536 case DW_LNS_set_column
:
20537 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20538 line_ptr
+= bytes_read
;
20540 case DW_LNS_negate_stmt
:
20541 state_machine
.handle_negate_stmt ();
20543 case DW_LNS_set_basic_block
:
20545 /* Add to the address register of the state machine the
20546 address increment value corresponding to special opcode
20547 255. I.e., this value is scaled by the minimum
20548 instruction length since special opcode 255 would have
20549 scaled the increment. */
20550 case DW_LNS_const_add_pc
:
20551 state_machine
.handle_const_add_pc ();
20553 case DW_LNS_fixed_advance_pc
:
20555 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20558 state_machine
.handle_fixed_advance_pc (addr_adj
);
20563 /* Unknown standard opcode, ignore it. */
20566 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20568 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20569 line_ptr
+= bytes_read
;
20576 dwarf2_debug_line_missing_end_sequence_complaint ();
20578 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20579 in which case we still finish recording the last line). */
20580 state_machine
.record_line (true);
20584 /* Decode the Line Number Program (LNP) for the given line_header
20585 structure and CU. The actual information extracted and the type
20586 of structures created from the LNP depends on the value of PST.
20588 1. If PST is NULL, then this procedure uses the data from the program
20589 to create all necessary symbol tables, and their linetables.
20591 2. If PST is not NULL, this procedure reads the program to determine
20592 the list of files included by the unit represented by PST, and
20593 builds all the associated partial symbol tables.
20595 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20596 It is used for relative paths in the line table.
20597 NOTE: When processing partial symtabs (pst != NULL),
20598 comp_dir == pst->dirname.
20600 NOTE: It is important that psymtabs have the same file name (via strcmp)
20601 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20602 symtab we don't use it in the name of the psymtabs we create.
20603 E.g. expand_line_sal requires this when finding psymtabs to expand.
20604 A good testcase for this is mb-inline.exp.
20606 LOWPC is the lowest address in CU (or 0 if not known).
20608 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20609 for its PC<->lines mapping information. Otherwise only the filename
20610 table is read in. */
20613 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20614 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20615 CORE_ADDR lowpc
, int decode_mapping
)
20617 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20618 const int decode_for_pst_p
= (pst
!= NULL
);
20620 if (decode_mapping
)
20621 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20623 if (decode_for_pst_p
)
20625 /* Now that we're done scanning the Line Header Program, we can
20626 create the psymtab of each included file. */
20627 for (auto &file_entry
: lh
->file_names ())
20628 if (file_entry
.included_p
== 1)
20630 gdb::unique_xmalloc_ptr
<char> name_holder
;
20631 const char *include_name
=
20632 psymtab_include_file_name (lh
, file_entry
, pst
,
20633 comp_dir
, &name_holder
);
20634 if (include_name
!= NULL
)
20635 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20640 /* Make sure a symtab is created for every file, even files
20641 which contain only variables (i.e. no code with associated
20643 buildsym_compunit
*builder
= cu
->get_builder ();
20644 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20646 for (auto &fe
: lh
->file_names ())
20648 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20649 if (builder
->get_current_subfile ()->symtab
== NULL
)
20651 builder
->get_current_subfile ()->symtab
20652 = allocate_symtab (cust
,
20653 builder
->get_current_subfile ()->name
);
20655 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20660 /* Start a subfile for DWARF. FILENAME is the name of the file and
20661 DIRNAME the name of the source directory which contains FILENAME
20662 or NULL if not known.
20663 This routine tries to keep line numbers from identical absolute and
20664 relative file names in a common subfile.
20666 Using the `list' example from the GDB testsuite, which resides in
20667 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20668 of /srcdir/list0.c yields the following debugging information for list0.c:
20670 DW_AT_name: /srcdir/list0.c
20671 DW_AT_comp_dir: /compdir
20672 files.files[0].name: list0.h
20673 files.files[0].dir: /srcdir
20674 files.files[1].name: list0.c
20675 files.files[1].dir: /srcdir
20677 The line number information for list0.c has to end up in a single
20678 subfile, so that `break /srcdir/list0.c:1' works as expected.
20679 start_subfile will ensure that this happens provided that we pass the
20680 concatenation of files.files[1].dir and files.files[1].name as the
20684 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20685 const char *dirname
)
20687 gdb::unique_xmalloc_ptr
<char> copy
;
20689 /* In order not to lose the line information directory,
20690 we concatenate it to the filename when it makes sense.
20691 Note that the Dwarf3 standard says (speaking of filenames in line
20692 information): ``The directory index is ignored for file names
20693 that represent full path names''. Thus ignoring dirname in the
20694 `else' branch below isn't an issue. */
20696 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20698 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20699 filename
= copy
.get ();
20702 cu
->get_builder ()->start_subfile (filename
);
20705 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20706 buildsym_compunit constructor. */
20708 struct compunit_symtab
*
20709 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20712 gdb_assert (m_builder
== nullptr);
20714 m_builder
.reset (new struct buildsym_compunit
20715 (this->per_objfile
->objfile
,
20716 name
, comp_dir
, language
, low_pc
));
20718 list_in_scope
= get_builder ()->get_file_symbols ();
20720 get_builder ()->record_debugformat ("DWARF 2");
20721 get_builder ()->record_producer (producer
);
20723 processing_has_namespace_info
= false;
20725 return get_builder ()->get_compunit_symtab ();
20729 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20730 struct dwarf2_cu
*cu
)
20732 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20733 struct comp_unit_head
*cu_header
= &cu
->header
;
20735 /* NOTE drow/2003-01-30: There used to be a comment and some special
20736 code here to turn a symbol with DW_AT_external and a
20737 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20738 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20739 with some versions of binutils) where shared libraries could have
20740 relocations against symbols in their debug information - the
20741 minimal symbol would have the right address, but the debug info
20742 would not. It's no longer necessary, because we will explicitly
20743 apply relocations when we read in the debug information now. */
20745 /* A DW_AT_location attribute with no contents indicates that a
20746 variable has been optimized away. */
20747 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20749 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20753 /* Handle one degenerate form of location expression specially, to
20754 preserve GDB's previous behavior when section offsets are
20755 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20756 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20758 if (attr
->form_is_block ()
20759 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20760 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20761 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20762 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20763 && (DW_BLOCK (attr
)->size
20764 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20766 unsigned int dummy
;
20768 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20769 SET_SYMBOL_VALUE_ADDRESS
20770 (sym
, cu
->header
.read_address (objfile
->obfd
,
20771 DW_BLOCK (attr
)->data
+ 1,
20774 SET_SYMBOL_VALUE_ADDRESS
20775 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20777 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20778 fixup_symbol_section (sym
, objfile
);
20779 SET_SYMBOL_VALUE_ADDRESS
20781 SYMBOL_VALUE_ADDRESS (sym
)
20782 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20786 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20787 expression evaluator, and use LOC_COMPUTED only when necessary
20788 (i.e. when the value of a register or memory location is
20789 referenced, or a thread-local block, etc.). Then again, it might
20790 not be worthwhile. I'm assuming that it isn't unless performance
20791 or memory numbers show me otherwise. */
20793 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20795 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20796 cu
->has_loclist
= true;
20799 /* Given a pointer to a DWARF information entry, figure out if we need
20800 to make a symbol table entry for it, and if so, create a new entry
20801 and return a pointer to it.
20802 If TYPE is NULL, determine symbol type from the die, otherwise
20803 used the passed type.
20804 If SPACE is not NULL, use it to hold the new symbol. If it is
20805 NULL, allocate a new symbol on the objfile's obstack. */
20807 static struct symbol
*
20808 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20809 struct symbol
*space
)
20811 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20812 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20813 struct gdbarch
*gdbarch
= objfile
->arch ();
20814 struct symbol
*sym
= NULL
;
20816 struct attribute
*attr
= NULL
;
20817 struct attribute
*attr2
= NULL
;
20818 CORE_ADDR baseaddr
;
20819 struct pending
**list_to_add
= NULL
;
20821 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20823 baseaddr
= objfile
->text_section_offset ();
20825 name
= dwarf2_name (die
, cu
);
20828 int suppress_add
= 0;
20833 sym
= new (&objfile
->objfile_obstack
) symbol
;
20834 OBJSTAT (objfile
, n_syms
++);
20836 /* Cache this symbol's name and the name's demangled form (if any). */
20837 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20838 /* Fortran does not have mangling standard and the mangling does differ
20839 between gfortran, iFort etc. */
20840 const char *physname
20841 = (cu
->language
== language_fortran
20842 ? dwarf2_full_name (name
, die
, cu
)
20843 : dwarf2_physname (name
, die
, cu
));
20844 const char *linkagename
= dw2_linkage_name (die
, cu
);
20846 if (linkagename
== nullptr || cu
->language
== language_ada
)
20847 sym
->set_linkage_name (physname
);
20850 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20851 sym
->set_linkage_name (linkagename
);
20854 /* Default assumptions.
20855 Use the passed type or decode it from the die. */
20856 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20857 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20859 SYMBOL_TYPE (sym
) = type
;
20861 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20862 attr
= dwarf2_attr (die
,
20863 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20865 if (attr
!= nullptr)
20867 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20870 attr
= dwarf2_attr (die
,
20871 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20873 if (attr
!= nullptr)
20875 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20876 struct file_entry
*fe
;
20878 if (cu
->line_header
!= NULL
)
20879 fe
= cu
->line_header
->file_name_at (file_index
);
20884 complaint (_("file index out of range"));
20886 symbol_set_symtab (sym
, fe
->symtab
);
20892 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20893 if (attr
!= nullptr)
20897 addr
= attr
->value_as_address ();
20898 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20899 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20901 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20902 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20903 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20904 add_symbol_to_list (sym
, cu
->list_in_scope
);
20906 case DW_TAG_subprogram
:
20907 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20909 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20910 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20911 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20912 || cu
->language
== language_ada
20913 || cu
->language
== language_fortran
)
20915 /* Subprograms marked external are stored as a global symbol.
20916 Ada and Fortran subprograms, whether marked external or
20917 not, are always stored as a global symbol, because we want
20918 to be able to access them globally. For instance, we want
20919 to be able to break on a nested subprogram without having
20920 to specify the context. */
20921 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20925 list_to_add
= cu
->list_in_scope
;
20928 case DW_TAG_inlined_subroutine
:
20929 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20931 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20932 SYMBOL_INLINED (sym
) = 1;
20933 list_to_add
= cu
->list_in_scope
;
20935 case DW_TAG_template_value_param
:
20937 /* Fall through. */
20938 case DW_TAG_constant
:
20939 case DW_TAG_variable
:
20940 case DW_TAG_member
:
20941 /* Compilation with minimal debug info may result in
20942 variables with missing type entries. Change the
20943 misleading `void' type to something sensible. */
20944 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20945 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20947 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20948 /* In the case of DW_TAG_member, we should only be called for
20949 static const members. */
20950 if (die
->tag
== DW_TAG_member
)
20952 /* dwarf2_add_field uses die_is_declaration,
20953 so we do the same. */
20954 gdb_assert (die_is_declaration (die
, cu
));
20957 if (attr
!= nullptr)
20959 dwarf2_const_value (attr
, sym
, cu
);
20960 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20963 if (attr2
&& (DW_UNSND (attr2
) != 0))
20964 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20966 list_to_add
= cu
->list_in_scope
;
20970 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20971 if (attr
!= nullptr)
20973 var_decode_location (attr
, sym
, cu
);
20974 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20976 /* Fortran explicitly imports any global symbols to the local
20977 scope by DW_TAG_common_block. */
20978 if (cu
->language
== language_fortran
&& die
->parent
20979 && die
->parent
->tag
== DW_TAG_common_block
)
20982 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20983 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20984 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
20986 /* When a static variable is eliminated by the linker,
20987 the corresponding debug information is not stripped
20988 out, but the variable address is set to null;
20989 do not add such variables into symbol table. */
20991 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20993 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20994 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20995 && dwarf2_per_objfile
->per_bfd
->can_copy
)
20997 /* A global static variable might be subject to
20998 copy relocation. We first check for a local
20999 minsym, though, because maybe the symbol was
21000 marked hidden, in which case this would not
21002 bound_minimal_symbol found
21003 = (lookup_minimal_symbol_linkage
21004 (sym
->linkage_name (), objfile
));
21005 if (found
.minsym
!= nullptr)
21006 sym
->maybe_copied
= 1;
21009 /* A variable with DW_AT_external is never static,
21010 but it may be block-scoped. */
21012 = ((cu
->list_in_scope
21013 == cu
->get_builder ()->get_file_symbols ())
21014 ? cu
->get_builder ()->get_global_symbols ()
21015 : cu
->list_in_scope
);
21018 list_to_add
= cu
->list_in_scope
;
21022 /* We do not know the address of this symbol.
21023 If it is an external symbol and we have type information
21024 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21025 The address of the variable will then be determined from
21026 the minimal symbol table whenever the variable is
21028 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21030 /* Fortran explicitly imports any global symbols to the local
21031 scope by DW_TAG_common_block. */
21032 if (cu
->language
== language_fortran
&& die
->parent
21033 && die
->parent
->tag
== DW_TAG_common_block
)
21035 /* SYMBOL_CLASS doesn't matter here because
21036 read_common_block is going to reset it. */
21038 list_to_add
= cu
->list_in_scope
;
21040 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21041 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21043 /* A variable with DW_AT_external is never static, but it
21044 may be block-scoped. */
21046 = ((cu
->list_in_scope
21047 == cu
->get_builder ()->get_file_symbols ())
21048 ? cu
->get_builder ()->get_global_symbols ()
21049 : cu
->list_in_scope
);
21051 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21053 else if (!die_is_declaration (die
, cu
))
21055 /* Use the default LOC_OPTIMIZED_OUT class. */
21056 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21058 list_to_add
= cu
->list_in_scope
;
21062 case DW_TAG_formal_parameter
:
21064 /* If we are inside a function, mark this as an argument. If
21065 not, we might be looking at an argument to an inlined function
21066 when we do not have enough information to show inlined frames;
21067 pretend it's a local variable in that case so that the user can
21069 struct context_stack
*curr
21070 = cu
->get_builder ()->get_current_context_stack ();
21071 if (curr
!= nullptr && curr
->name
!= nullptr)
21072 SYMBOL_IS_ARGUMENT (sym
) = 1;
21073 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21074 if (attr
!= nullptr)
21076 var_decode_location (attr
, sym
, cu
);
21078 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21079 if (attr
!= nullptr)
21081 dwarf2_const_value (attr
, sym
, cu
);
21084 list_to_add
= cu
->list_in_scope
;
21087 case DW_TAG_unspecified_parameters
:
21088 /* From varargs functions; gdb doesn't seem to have any
21089 interest in this information, so just ignore it for now.
21092 case DW_TAG_template_type_param
:
21094 /* Fall through. */
21095 case DW_TAG_class_type
:
21096 case DW_TAG_interface_type
:
21097 case DW_TAG_structure_type
:
21098 case DW_TAG_union_type
:
21099 case DW_TAG_set_type
:
21100 case DW_TAG_enumeration_type
:
21101 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21102 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21105 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21106 really ever be static objects: otherwise, if you try
21107 to, say, break of a class's method and you're in a file
21108 which doesn't mention that class, it won't work unless
21109 the check for all static symbols in lookup_symbol_aux
21110 saves you. See the OtherFileClass tests in
21111 gdb.c++/namespace.exp. */
21115 buildsym_compunit
*builder
= cu
->get_builder ();
21117 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21118 && cu
->language
== language_cplus
21119 ? builder
->get_global_symbols ()
21120 : cu
->list_in_scope
);
21122 /* The semantics of C++ state that "struct foo {
21123 ... }" also defines a typedef for "foo". */
21124 if (cu
->language
== language_cplus
21125 || cu
->language
== language_ada
21126 || cu
->language
== language_d
21127 || cu
->language
== language_rust
)
21129 /* The symbol's name is already allocated along
21130 with this objfile, so we don't need to
21131 duplicate it for the type. */
21132 if (SYMBOL_TYPE (sym
)->name () == 0)
21133 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21138 case DW_TAG_typedef
:
21139 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21140 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21141 list_to_add
= cu
->list_in_scope
;
21143 case DW_TAG_base_type
:
21144 case DW_TAG_subrange_type
:
21145 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21146 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21147 list_to_add
= cu
->list_in_scope
;
21149 case DW_TAG_enumerator
:
21150 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21151 if (attr
!= nullptr)
21153 dwarf2_const_value (attr
, sym
, cu
);
21156 /* NOTE: carlton/2003-11-10: See comment above in the
21157 DW_TAG_class_type, etc. block. */
21160 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21161 && cu
->language
== language_cplus
21162 ? cu
->get_builder ()->get_global_symbols ()
21163 : cu
->list_in_scope
);
21166 case DW_TAG_imported_declaration
:
21167 case DW_TAG_namespace
:
21168 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21169 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21171 case DW_TAG_module
:
21172 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21173 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21174 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21176 case DW_TAG_common_block
:
21177 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21178 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21179 add_symbol_to_list (sym
, cu
->list_in_scope
);
21182 /* Not a tag we recognize. Hopefully we aren't processing
21183 trash data, but since we must specifically ignore things
21184 we don't recognize, there is nothing else we should do at
21186 complaint (_("unsupported tag: '%s'"),
21187 dwarf_tag_name (die
->tag
));
21193 sym
->hash_next
= objfile
->template_symbols
;
21194 objfile
->template_symbols
= sym
;
21195 list_to_add
= NULL
;
21198 if (list_to_add
!= NULL
)
21199 add_symbol_to_list (sym
, list_to_add
);
21201 /* For the benefit of old versions of GCC, check for anonymous
21202 namespaces based on the demangled name. */
21203 if (!cu
->processing_has_namespace_info
21204 && cu
->language
== language_cplus
)
21205 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21210 /* Given an attr with a DW_FORM_dataN value in host byte order,
21211 zero-extend it as appropriate for the symbol's type. The DWARF
21212 standard (v4) is not entirely clear about the meaning of using
21213 DW_FORM_dataN for a constant with a signed type, where the type is
21214 wider than the data. The conclusion of a discussion on the DWARF
21215 list was that this is unspecified. We choose to always zero-extend
21216 because that is the interpretation long in use by GCC. */
21219 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21220 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21222 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21223 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21224 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21225 LONGEST l
= DW_UNSND (attr
);
21227 if (bits
< sizeof (*value
) * 8)
21229 l
&= ((LONGEST
) 1 << bits
) - 1;
21232 else if (bits
== sizeof (*value
) * 8)
21236 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21237 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21244 /* Read a constant value from an attribute. Either set *VALUE, or if
21245 the value does not fit in *VALUE, set *BYTES - either already
21246 allocated on the objfile obstack, or newly allocated on OBSTACK,
21247 or, set *BATON, if we translated the constant to a location
21251 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21252 const char *name
, struct obstack
*obstack
,
21253 struct dwarf2_cu
*cu
,
21254 LONGEST
*value
, const gdb_byte
**bytes
,
21255 struct dwarf2_locexpr_baton
**baton
)
21257 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21258 struct objfile
*objfile
= per_objfile
->objfile
;
21259 struct comp_unit_head
*cu_header
= &cu
->header
;
21260 struct dwarf_block
*blk
;
21261 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21262 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21268 switch (attr
->form
)
21271 case DW_FORM_addrx
:
21272 case DW_FORM_GNU_addr_index
:
21276 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21277 dwarf2_const_value_length_mismatch_complaint (name
,
21278 cu_header
->addr_size
,
21279 TYPE_LENGTH (type
));
21280 /* Symbols of this form are reasonably rare, so we just
21281 piggyback on the existing location code rather than writing
21282 a new implementation of symbol_computed_ops. */
21283 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21284 (*baton
)->per_objfile
= per_objfile
;
21285 (*baton
)->per_cu
= cu
->per_cu
;
21286 gdb_assert ((*baton
)->per_cu
);
21288 (*baton
)->size
= 2 + cu_header
->addr_size
;
21289 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21290 (*baton
)->data
= data
;
21292 data
[0] = DW_OP_addr
;
21293 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21294 byte_order
, DW_ADDR (attr
));
21295 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21298 case DW_FORM_string
:
21301 case DW_FORM_GNU_str_index
:
21302 case DW_FORM_GNU_strp_alt
:
21303 /* DW_STRING is already allocated on the objfile obstack, point
21305 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21307 case DW_FORM_block1
:
21308 case DW_FORM_block2
:
21309 case DW_FORM_block4
:
21310 case DW_FORM_block
:
21311 case DW_FORM_exprloc
:
21312 case DW_FORM_data16
:
21313 blk
= DW_BLOCK (attr
);
21314 if (TYPE_LENGTH (type
) != blk
->size
)
21315 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21316 TYPE_LENGTH (type
));
21317 *bytes
= blk
->data
;
21320 /* The DW_AT_const_value attributes are supposed to carry the
21321 symbol's value "represented as it would be on the target
21322 architecture." By the time we get here, it's already been
21323 converted to host endianness, so we just need to sign- or
21324 zero-extend it as appropriate. */
21325 case DW_FORM_data1
:
21326 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21328 case DW_FORM_data2
:
21329 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21331 case DW_FORM_data4
:
21332 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21334 case DW_FORM_data8
:
21335 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21338 case DW_FORM_sdata
:
21339 case DW_FORM_implicit_const
:
21340 *value
= DW_SND (attr
);
21343 case DW_FORM_udata
:
21344 *value
= DW_UNSND (attr
);
21348 complaint (_("unsupported const value attribute form: '%s'"),
21349 dwarf_form_name (attr
->form
));
21356 /* Copy constant value from an attribute to a symbol. */
21359 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21360 struct dwarf2_cu
*cu
)
21362 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21364 const gdb_byte
*bytes
;
21365 struct dwarf2_locexpr_baton
*baton
;
21367 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21368 sym
->print_name (),
21369 &objfile
->objfile_obstack
, cu
,
21370 &value
, &bytes
, &baton
);
21374 SYMBOL_LOCATION_BATON (sym
) = baton
;
21375 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21377 else if (bytes
!= NULL
)
21379 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21380 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21384 SYMBOL_VALUE (sym
) = value
;
21385 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21389 /* Return the type of the die in question using its DW_AT_type attribute. */
21391 static struct type
*
21392 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21394 struct attribute
*type_attr
;
21396 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21399 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21400 /* A missing DW_AT_type represents a void type. */
21401 return objfile_type (objfile
)->builtin_void
;
21404 return lookup_die_type (die
, type_attr
, cu
);
21407 /* True iff CU's producer generates GNAT Ada auxiliary information
21408 that allows to find parallel types through that information instead
21409 of having to do expensive parallel lookups by type name. */
21412 need_gnat_info (struct dwarf2_cu
*cu
)
21414 /* Assume that the Ada compiler was GNAT, which always produces
21415 the auxiliary information. */
21416 return (cu
->language
== language_ada
);
21419 /* Return the auxiliary type of the die in question using its
21420 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21421 attribute is not present. */
21423 static struct type
*
21424 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21426 struct attribute
*type_attr
;
21428 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21432 return lookup_die_type (die
, type_attr
, cu
);
21435 /* If DIE has a descriptive_type attribute, then set the TYPE's
21436 descriptive type accordingly. */
21439 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21440 struct dwarf2_cu
*cu
)
21442 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21444 if (descriptive_type
)
21446 ALLOCATE_GNAT_AUX_TYPE (type
);
21447 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21451 /* Return the containing type of the die in question using its
21452 DW_AT_containing_type attribute. */
21454 static struct type
*
21455 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21457 struct attribute
*type_attr
;
21458 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21460 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21462 error (_("Dwarf Error: Problem turning containing type into gdb type "
21463 "[in module %s]"), objfile_name (objfile
));
21465 return lookup_die_type (die
, type_attr
, cu
);
21468 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21470 static struct type
*
21471 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21473 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21474 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21477 std::string message
21478 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21479 objfile_name (objfile
),
21480 sect_offset_str (cu
->header
.sect_off
),
21481 sect_offset_str (die
->sect_off
));
21482 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21484 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21487 /* Look up the type of DIE in CU using its type attribute ATTR.
21488 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21489 DW_AT_containing_type.
21490 If there is no type substitute an error marker. */
21492 static struct type
*
21493 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21494 struct dwarf2_cu
*cu
)
21496 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21497 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21498 struct type
*this_type
;
21500 gdb_assert (attr
->name
== DW_AT_type
21501 || attr
->name
== DW_AT_GNAT_descriptive_type
21502 || attr
->name
== DW_AT_containing_type
);
21504 /* First see if we have it cached. */
21506 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21508 struct dwarf2_per_cu_data
*per_cu
;
21509 sect_offset sect_off
= attr
->get_ref_die_offset ();
21511 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21512 dwarf2_per_objfile
);
21513 this_type
= get_die_type_at_offset (sect_off
, per_cu
, dwarf2_per_objfile
);
21515 else if (attr
->form_is_ref ())
21517 sect_offset sect_off
= attr
->get_ref_die_offset ();
21519 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
,
21520 dwarf2_per_objfile
);
21522 else if (attr
->form
== DW_FORM_ref_sig8
)
21524 ULONGEST signature
= DW_SIGNATURE (attr
);
21526 return get_signatured_type (die
, signature
, cu
);
21530 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21531 " at %s [in module %s]"),
21532 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21533 objfile_name (objfile
));
21534 return build_error_marker_type (cu
, die
);
21537 /* If not cached we need to read it in. */
21539 if (this_type
== NULL
)
21541 struct die_info
*type_die
= NULL
;
21542 struct dwarf2_cu
*type_cu
= cu
;
21544 if (attr
->form_is_ref ())
21545 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21546 if (type_die
== NULL
)
21547 return build_error_marker_type (cu
, die
);
21548 /* If we find the type now, it's probably because the type came
21549 from an inter-CU reference and the type's CU got expanded before
21551 this_type
= read_type_die (type_die
, type_cu
);
21554 /* If we still don't have a type use an error marker. */
21556 if (this_type
== NULL
)
21557 return build_error_marker_type (cu
, die
);
21562 /* Return the type in DIE, CU.
21563 Returns NULL for invalid types.
21565 This first does a lookup in die_type_hash,
21566 and only reads the die in if necessary.
21568 NOTE: This can be called when reading in partial or full symbols. */
21570 static struct type
*
21571 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21573 struct type
*this_type
;
21575 this_type
= get_die_type (die
, cu
);
21579 return read_type_die_1 (die
, cu
);
21582 /* Read the type in DIE, CU.
21583 Returns NULL for invalid types. */
21585 static struct type
*
21586 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21588 struct type
*this_type
= NULL
;
21592 case DW_TAG_class_type
:
21593 case DW_TAG_interface_type
:
21594 case DW_TAG_structure_type
:
21595 case DW_TAG_union_type
:
21596 this_type
= read_structure_type (die
, cu
);
21598 case DW_TAG_enumeration_type
:
21599 this_type
= read_enumeration_type (die
, cu
);
21601 case DW_TAG_subprogram
:
21602 case DW_TAG_subroutine_type
:
21603 case DW_TAG_inlined_subroutine
:
21604 this_type
= read_subroutine_type (die
, cu
);
21606 case DW_TAG_array_type
:
21607 this_type
= read_array_type (die
, cu
);
21609 case DW_TAG_set_type
:
21610 this_type
= read_set_type (die
, cu
);
21612 case DW_TAG_pointer_type
:
21613 this_type
= read_tag_pointer_type (die
, cu
);
21615 case DW_TAG_ptr_to_member_type
:
21616 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21618 case DW_TAG_reference_type
:
21619 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21621 case DW_TAG_rvalue_reference_type
:
21622 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21624 case DW_TAG_const_type
:
21625 this_type
= read_tag_const_type (die
, cu
);
21627 case DW_TAG_volatile_type
:
21628 this_type
= read_tag_volatile_type (die
, cu
);
21630 case DW_TAG_restrict_type
:
21631 this_type
= read_tag_restrict_type (die
, cu
);
21633 case DW_TAG_string_type
:
21634 this_type
= read_tag_string_type (die
, cu
);
21636 case DW_TAG_typedef
:
21637 this_type
= read_typedef (die
, cu
);
21639 case DW_TAG_subrange_type
:
21640 this_type
= read_subrange_type (die
, cu
);
21642 case DW_TAG_base_type
:
21643 this_type
= read_base_type (die
, cu
);
21645 case DW_TAG_unspecified_type
:
21646 this_type
= read_unspecified_type (die
, cu
);
21648 case DW_TAG_namespace
:
21649 this_type
= read_namespace_type (die
, cu
);
21651 case DW_TAG_module
:
21652 this_type
= read_module_type (die
, cu
);
21654 case DW_TAG_atomic_type
:
21655 this_type
= read_tag_atomic_type (die
, cu
);
21658 complaint (_("unexpected tag in read_type_die: '%s'"),
21659 dwarf_tag_name (die
->tag
));
21666 /* See if we can figure out if the class lives in a namespace. We do
21667 this by looking for a member function; its demangled name will
21668 contain namespace info, if there is any.
21669 Return the computed name or NULL.
21670 Space for the result is allocated on the objfile's obstack.
21671 This is the full-die version of guess_partial_die_structure_name.
21672 In this case we know DIE has no useful parent. */
21674 static const char *
21675 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21677 struct die_info
*spec_die
;
21678 struct dwarf2_cu
*spec_cu
;
21679 struct die_info
*child
;
21680 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21683 spec_die
= die_specification (die
, &spec_cu
);
21684 if (spec_die
!= NULL
)
21690 for (child
= die
->child
;
21692 child
= child
->sibling
)
21694 if (child
->tag
== DW_TAG_subprogram
)
21696 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21698 if (linkage_name
!= NULL
)
21700 gdb::unique_xmalloc_ptr
<char> actual_name
21701 (language_class_name_from_physname (cu
->language_defn
,
21703 const char *name
= NULL
;
21705 if (actual_name
!= NULL
)
21707 const char *die_name
= dwarf2_name (die
, cu
);
21709 if (die_name
!= NULL
21710 && strcmp (die_name
, actual_name
.get ()) != 0)
21712 /* Strip off the class name from the full name.
21713 We want the prefix. */
21714 int die_name_len
= strlen (die_name
);
21715 int actual_name_len
= strlen (actual_name
.get ());
21716 const char *ptr
= actual_name
.get ();
21718 /* Test for '::' as a sanity check. */
21719 if (actual_name_len
> die_name_len
+ 2
21720 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21721 name
= obstack_strndup (
21722 &objfile
->per_bfd
->storage_obstack
,
21723 ptr
, actual_name_len
- die_name_len
- 2);
21734 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21735 prefix part in such case. See
21736 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21738 static const char *
21739 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21741 struct attribute
*attr
;
21744 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21745 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21748 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21751 attr
= dw2_linkage_name_attr (die
, cu
);
21752 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21755 /* dwarf2_name had to be already called. */
21756 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21758 /* Strip the base name, keep any leading namespaces/classes. */
21759 base
= strrchr (DW_STRING (attr
), ':');
21760 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21763 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21764 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21766 &base
[-1] - DW_STRING (attr
));
21769 /* Return the name of the namespace/class that DIE is defined within,
21770 or "" if we can't tell. The caller should not xfree the result.
21772 For example, if we're within the method foo() in the following
21782 then determine_prefix on foo's die will return "N::C". */
21784 static const char *
21785 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21787 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21788 struct die_info
*parent
, *spec_die
;
21789 struct dwarf2_cu
*spec_cu
;
21790 struct type
*parent_type
;
21791 const char *retval
;
21793 if (cu
->language
!= language_cplus
21794 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21795 && cu
->language
!= language_rust
)
21798 retval
= anonymous_struct_prefix (die
, cu
);
21802 /* We have to be careful in the presence of DW_AT_specification.
21803 For example, with GCC 3.4, given the code
21807 // Definition of N::foo.
21811 then we'll have a tree of DIEs like this:
21813 1: DW_TAG_compile_unit
21814 2: DW_TAG_namespace // N
21815 3: DW_TAG_subprogram // declaration of N::foo
21816 4: DW_TAG_subprogram // definition of N::foo
21817 DW_AT_specification // refers to die #3
21819 Thus, when processing die #4, we have to pretend that we're in
21820 the context of its DW_AT_specification, namely the contex of die
21823 spec_die
= die_specification (die
, &spec_cu
);
21824 if (spec_die
== NULL
)
21825 parent
= die
->parent
;
21828 parent
= spec_die
->parent
;
21832 if (parent
== NULL
)
21834 else if (parent
->building_fullname
)
21837 const char *parent_name
;
21839 /* It has been seen on RealView 2.2 built binaries,
21840 DW_TAG_template_type_param types actually _defined_ as
21841 children of the parent class:
21844 template class <class Enum> Class{};
21845 Class<enum E> class_e;
21847 1: DW_TAG_class_type (Class)
21848 2: DW_TAG_enumeration_type (E)
21849 3: DW_TAG_enumerator (enum1:0)
21850 3: DW_TAG_enumerator (enum2:1)
21852 2: DW_TAG_template_type_param
21853 DW_AT_type DW_FORM_ref_udata (E)
21855 Besides being broken debug info, it can put GDB into an
21856 infinite loop. Consider:
21858 When we're building the full name for Class<E>, we'll start
21859 at Class, and go look over its template type parameters,
21860 finding E. We'll then try to build the full name of E, and
21861 reach here. We're now trying to build the full name of E,
21862 and look over the parent DIE for containing scope. In the
21863 broken case, if we followed the parent DIE of E, we'd again
21864 find Class, and once again go look at its template type
21865 arguments, etc., etc. Simply don't consider such parent die
21866 as source-level parent of this die (it can't be, the language
21867 doesn't allow it), and break the loop here. */
21868 name
= dwarf2_name (die
, cu
);
21869 parent_name
= dwarf2_name (parent
, cu
);
21870 complaint (_("template param type '%s' defined within parent '%s'"),
21871 name
? name
: "<unknown>",
21872 parent_name
? parent_name
: "<unknown>");
21876 switch (parent
->tag
)
21878 case DW_TAG_namespace
:
21879 parent_type
= read_type_die (parent
, cu
);
21880 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21881 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21882 Work around this problem here. */
21883 if (cu
->language
== language_cplus
21884 && strcmp (parent_type
->name (), "::") == 0)
21886 /* We give a name to even anonymous namespaces. */
21887 return parent_type
->name ();
21888 case DW_TAG_class_type
:
21889 case DW_TAG_interface_type
:
21890 case DW_TAG_structure_type
:
21891 case DW_TAG_union_type
:
21892 case DW_TAG_module
:
21893 parent_type
= read_type_die (parent
, cu
);
21894 if (parent_type
->name () != NULL
)
21895 return parent_type
->name ();
21897 /* An anonymous structure is only allowed non-static data
21898 members; no typedefs, no member functions, et cetera.
21899 So it does not need a prefix. */
21901 case DW_TAG_compile_unit
:
21902 case DW_TAG_partial_unit
:
21903 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21904 if (cu
->language
== language_cplus
21905 && !dwarf2_per_objfile
->per_bfd
->types
.empty ()
21906 && die
->child
!= NULL
21907 && (die
->tag
== DW_TAG_class_type
21908 || die
->tag
== DW_TAG_structure_type
21909 || die
->tag
== DW_TAG_union_type
))
21911 const char *name
= guess_full_die_structure_name (die
, cu
);
21916 case DW_TAG_subprogram
:
21917 /* Nested subroutines in Fortran get a prefix with the name
21918 of the parent's subroutine. */
21919 if (cu
->language
== language_fortran
)
21921 if ((die
->tag
== DW_TAG_subprogram
)
21922 && (dwarf2_name (parent
, cu
) != NULL
))
21923 return dwarf2_name (parent
, cu
);
21925 return determine_prefix (parent
, cu
);
21926 case DW_TAG_enumeration_type
:
21927 parent_type
= read_type_die (parent
, cu
);
21928 if (TYPE_DECLARED_CLASS (parent_type
))
21930 if (parent_type
->name () != NULL
)
21931 return parent_type
->name ();
21934 /* Fall through. */
21936 return determine_prefix (parent
, cu
);
21940 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21941 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21942 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21943 an obconcat, otherwise allocate storage for the result. The CU argument is
21944 used to determine the language and hence, the appropriate separator. */
21946 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21949 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21950 int physname
, struct dwarf2_cu
*cu
)
21952 const char *lead
= "";
21955 if (suffix
== NULL
|| suffix
[0] == '\0'
21956 || prefix
== NULL
|| prefix
[0] == '\0')
21958 else if (cu
->language
== language_d
)
21960 /* For D, the 'main' function could be defined in any module, but it
21961 should never be prefixed. */
21962 if (strcmp (suffix
, "D main") == 0)
21970 else if (cu
->language
== language_fortran
&& physname
)
21972 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21973 DW_AT_MIPS_linkage_name is preferred and used instead. */
21981 if (prefix
== NULL
)
21983 if (suffix
== NULL
)
21990 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21992 strcpy (retval
, lead
);
21993 strcat (retval
, prefix
);
21994 strcat (retval
, sep
);
21995 strcat (retval
, suffix
);
22000 /* We have an obstack. */
22001 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22005 /* Get name of a die, return NULL if not found. */
22007 static const char *
22008 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22009 struct objfile
*objfile
)
22011 if (name
&& cu
->language
== language_cplus
)
22013 gdb::unique_xmalloc_ptr
<char> canon_name
22014 = cp_canonicalize_string (name
);
22016 if (canon_name
!= nullptr)
22017 name
= objfile
->intern (canon_name
.get ());
22023 /* Get name of a die, return NULL if not found.
22024 Anonymous namespaces are converted to their magic string. */
22026 static const char *
22027 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22029 struct attribute
*attr
;
22030 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22032 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22033 if ((!attr
|| !DW_STRING (attr
))
22034 && die
->tag
!= DW_TAG_namespace
22035 && die
->tag
!= DW_TAG_class_type
22036 && die
->tag
!= DW_TAG_interface_type
22037 && die
->tag
!= DW_TAG_structure_type
22038 && die
->tag
!= DW_TAG_union_type
)
22043 case DW_TAG_compile_unit
:
22044 case DW_TAG_partial_unit
:
22045 /* Compilation units have a DW_AT_name that is a filename, not
22046 a source language identifier. */
22047 case DW_TAG_enumeration_type
:
22048 case DW_TAG_enumerator
:
22049 /* These tags always have simple identifiers already; no need
22050 to canonicalize them. */
22051 return DW_STRING (attr
);
22053 case DW_TAG_namespace
:
22054 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22055 return DW_STRING (attr
);
22056 return CP_ANONYMOUS_NAMESPACE_STR
;
22058 case DW_TAG_class_type
:
22059 case DW_TAG_interface_type
:
22060 case DW_TAG_structure_type
:
22061 case DW_TAG_union_type
:
22062 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22063 structures or unions. These were of the form "._%d" in GCC 4.1,
22064 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22065 and GCC 4.4. We work around this problem by ignoring these. */
22066 if (attr
&& DW_STRING (attr
)
22067 && (startswith (DW_STRING (attr
), "._")
22068 || startswith (DW_STRING (attr
), "<anonymous")))
22071 /* GCC might emit a nameless typedef that has a linkage name. See
22072 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22073 if (!attr
|| DW_STRING (attr
) == NULL
)
22075 attr
= dw2_linkage_name_attr (die
, cu
);
22076 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22079 /* Avoid demangling DW_STRING (attr) the second time on a second
22080 call for the same DIE. */
22081 if (!DW_STRING_IS_CANONICAL (attr
))
22083 gdb::unique_xmalloc_ptr
<char> demangled
22084 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22085 if (demangled
== nullptr)
22088 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
22089 DW_STRING_IS_CANONICAL (attr
) = 1;
22092 /* Strip any leading namespaces/classes, keep only the base name.
22093 DW_AT_name for named DIEs does not contain the prefixes. */
22094 const char *base
= strrchr (DW_STRING (attr
), ':');
22095 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22098 return DW_STRING (attr
);
22106 if (!DW_STRING_IS_CANONICAL (attr
))
22108 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22110 DW_STRING_IS_CANONICAL (attr
) = 1;
22112 return DW_STRING (attr
);
22115 /* Return the die that this die in an extension of, or NULL if there
22116 is none. *EXT_CU is the CU containing DIE on input, and the CU
22117 containing the return value on output. */
22119 static struct die_info
*
22120 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22122 struct attribute
*attr
;
22124 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22128 return follow_die_ref (die
, attr
, ext_cu
);
22132 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22136 print_spaces (indent
, f
);
22137 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22138 dwarf_tag_name (die
->tag
), die
->abbrev
,
22139 sect_offset_str (die
->sect_off
));
22141 if (die
->parent
!= NULL
)
22143 print_spaces (indent
, f
);
22144 fprintf_unfiltered (f
, " parent at offset: %s\n",
22145 sect_offset_str (die
->parent
->sect_off
));
22148 print_spaces (indent
, f
);
22149 fprintf_unfiltered (f
, " has children: %s\n",
22150 dwarf_bool_name (die
->child
!= NULL
));
22152 print_spaces (indent
, f
);
22153 fprintf_unfiltered (f
, " attributes:\n");
22155 for (i
= 0; i
< die
->num_attrs
; ++i
)
22157 print_spaces (indent
, f
);
22158 fprintf_unfiltered (f
, " %s (%s) ",
22159 dwarf_attr_name (die
->attrs
[i
].name
),
22160 dwarf_form_name (die
->attrs
[i
].form
));
22162 switch (die
->attrs
[i
].form
)
22165 case DW_FORM_addrx
:
22166 case DW_FORM_GNU_addr_index
:
22167 fprintf_unfiltered (f
, "address: ");
22168 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22170 case DW_FORM_block2
:
22171 case DW_FORM_block4
:
22172 case DW_FORM_block
:
22173 case DW_FORM_block1
:
22174 fprintf_unfiltered (f
, "block: size %s",
22175 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22177 case DW_FORM_exprloc
:
22178 fprintf_unfiltered (f
, "expression: size %s",
22179 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22181 case DW_FORM_data16
:
22182 fprintf_unfiltered (f
, "constant of 16 bytes");
22184 case DW_FORM_ref_addr
:
22185 fprintf_unfiltered (f
, "ref address: ");
22186 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22188 case DW_FORM_GNU_ref_alt
:
22189 fprintf_unfiltered (f
, "alt ref address: ");
22190 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22196 case DW_FORM_ref_udata
:
22197 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22198 (long) (DW_UNSND (&die
->attrs
[i
])));
22200 case DW_FORM_data1
:
22201 case DW_FORM_data2
:
22202 case DW_FORM_data4
:
22203 case DW_FORM_data8
:
22204 case DW_FORM_udata
:
22205 case DW_FORM_sdata
:
22206 fprintf_unfiltered (f
, "constant: %s",
22207 pulongest (DW_UNSND (&die
->attrs
[i
])));
22209 case DW_FORM_sec_offset
:
22210 fprintf_unfiltered (f
, "section offset: %s",
22211 pulongest (DW_UNSND (&die
->attrs
[i
])));
22213 case DW_FORM_ref_sig8
:
22214 fprintf_unfiltered (f
, "signature: %s",
22215 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22217 case DW_FORM_string
:
22219 case DW_FORM_line_strp
:
22221 case DW_FORM_GNU_str_index
:
22222 case DW_FORM_GNU_strp_alt
:
22223 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22224 DW_STRING (&die
->attrs
[i
])
22225 ? DW_STRING (&die
->attrs
[i
]) : "",
22226 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22229 if (DW_UNSND (&die
->attrs
[i
]))
22230 fprintf_unfiltered (f
, "flag: TRUE");
22232 fprintf_unfiltered (f
, "flag: FALSE");
22234 case DW_FORM_flag_present
:
22235 fprintf_unfiltered (f
, "flag: TRUE");
22237 case DW_FORM_indirect
:
22238 /* The reader will have reduced the indirect form to
22239 the "base form" so this form should not occur. */
22240 fprintf_unfiltered (f
,
22241 "unexpected attribute form: DW_FORM_indirect");
22243 case DW_FORM_implicit_const
:
22244 fprintf_unfiltered (f
, "constant: %s",
22245 plongest (DW_SND (&die
->attrs
[i
])));
22248 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22249 die
->attrs
[i
].form
);
22252 fprintf_unfiltered (f
, "\n");
22257 dump_die_for_error (struct die_info
*die
)
22259 dump_die_shallow (gdb_stderr
, 0, die
);
22263 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22265 int indent
= level
* 4;
22267 gdb_assert (die
!= NULL
);
22269 if (level
>= max_level
)
22272 dump_die_shallow (f
, indent
, die
);
22274 if (die
->child
!= NULL
)
22276 print_spaces (indent
, f
);
22277 fprintf_unfiltered (f
, " Children:");
22278 if (level
+ 1 < max_level
)
22280 fprintf_unfiltered (f
, "\n");
22281 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22285 fprintf_unfiltered (f
,
22286 " [not printed, max nesting level reached]\n");
22290 if (die
->sibling
!= NULL
&& level
> 0)
22292 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22296 /* This is called from the pdie macro in gdbinit.in.
22297 It's not static so gcc will keep a copy callable from gdb. */
22300 dump_die (struct die_info
*die
, int max_level
)
22302 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22306 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22310 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22311 to_underlying (die
->sect_off
),
22317 /* Follow reference or signature attribute ATTR of SRC_DIE.
22318 On entry *REF_CU is the CU of SRC_DIE.
22319 On exit *REF_CU is the CU of the result. */
22321 static struct die_info
*
22322 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22323 struct dwarf2_cu
**ref_cu
)
22325 struct die_info
*die
;
22327 if (attr
->form_is_ref ())
22328 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22329 else if (attr
->form
== DW_FORM_ref_sig8
)
22330 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22333 dump_die_for_error (src_die
);
22334 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22335 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22341 /* Follow reference OFFSET.
22342 On entry *REF_CU is the CU of the source die referencing OFFSET.
22343 On exit *REF_CU is the CU of the result.
22344 Returns NULL if OFFSET is invalid. */
22346 static struct die_info
*
22347 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22348 struct dwarf2_cu
**ref_cu
)
22350 struct die_info temp_die
;
22351 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22352 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22354 gdb_assert (cu
->per_cu
!= NULL
);
22358 if (cu
->per_cu
->is_debug_types
)
22360 /* .debug_types CUs cannot reference anything outside their CU.
22361 If they need to, they have to reference a signatured type via
22362 DW_FORM_ref_sig8. */
22363 if (!cu
->header
.offset_in_cu_p (sect_off
))
22366 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22367 || !cu
->header
.offset_in_cu_p (sect_off
))
22369 struct dwarf2_per_cu_data
*per_cu
;
22371 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22372 dwarf2_per_objfile
);
22374 /* If necessary, add it to the queue and load its DIEs. */
22375 if (maybe_queue_comp_unit (cu
, per_cu
, dwarf2_per_objfile
, cu
->language
))
22376 load_full_comp_unit (per_cu
, dwarf2_per_objfile
, false, cu
->language
);
22378 target_cu
= dwarf2_per_objfile
->get_cu (per_cu
);
22380 else if (cu
->dies
== NULL
)
22382 /* We're loading full DIEs during partial symbol reading. */
22383 gdb_assert (dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
);
22384 load_full_comp_unit (cu
->per_cu
, dwarf2_per_objfile
, false,
22388 *ref_cu
= target_cu
;
22389 temp_die
.sect_off
= sect_off
;
22391 if (target_cu
!= cu
)
22392 target_cu
->ancestor
= cu
;
22394 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22396 to_underlying (sect_off
));
22399 /* Follow reference attribute ATTR of SRC_DIE.
22400 On entry *REF_CU is the CU of SRC_DIE.
22401 On exit *REF_CU is the CU of the result. */
22403 static struct die_info
*
22404 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22405 struct dwarf2_cu
**ref_cu
)
22407 sect_offset sect_off
= attr
->get_ref_die_offset ();
22408 struct dwarf2_cu
*cu
= *ref_cu
;
22409 struct die_info
*die
;
22411 die
= follow_die_offset (sect_off
,
22412 (attr
->form
== DW_FORM_GNU_ref_alt
22413 || cu
->per_cu
->is_dwz
),
22416 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22417 "at %s [in module %s]"),
22418 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22419 objfile_name (cu
->per_objfile
->objfile
));
22426 struct dwarf2_locexpr_baton
22427 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22428 dwarf2_per_cu_data
*per_cu
,
22429 dwarf2_per_objfile
*dwarf2_per_objfile
,
22430 CORE_ADDR (*get_frame_pc
) (void *baton
),
22431 void *baton
, bool resolve_abstract_p
)
22433 struct die_info
*die
;
22434 struct attribute
*attr
;
22435 struct dwarf2_locexpr_baton retval
;
22436 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22438 dwarf2_cu
*cu
= dwarf2_per_objfile
->get_cu (per_cu
);
22440 cu
= load_cu (per_cu
, dwarf2_per_objfile
, false);
22444 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22445 Instead just throw an error, not much else we can do. */
22446 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22447 sect_offset_str (sect_off
), objfile_name (objfile
));
22450 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22452 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22453 sect_offset_str (sect_off
), objfile_name (objfile
));
22455 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22456 if (!attr
&& resolve_abstract_p
22457 && (dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22458 != dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22460 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22461 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22462 struct gdbarch
*gdbarch
= objfile
->arch ();
22464 for (const auto &cand_off
22465 : dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22467 struct dwarf2_cu
*cand_cu
= cu
;
22468 struct die_info
*cand
22469 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22472 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22475 CORE_ADDR pc_low
, pc_high
;
22476 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22477 if (pc_low
== ((CORE_ADDR
) -1))
22479 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22480 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22481 if (!(pc_low
<= pc
&& pc
< pc_high
))
22485 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22492 /* DWARF: "If there is no such attribute, then there is no effect.".
22493 DATA is ignored if SIZE is 0. */
22495 retval
.data
= NULL
;
22498 else if (attr
->form_is_section_offset ())
22500 struct dwarf2_loclist_baton loclist_baton
;
22501 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22504 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22506 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22508 retval
.size
= size
;
22512 if (!attr
->form_is_block ())
22513 error (_("Dwarf Error: DIE at %s referenced in module %s "
22514 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22515 sect_offset_str (sect_off
), objfile_name (objfile
));
22517 retval
.data
= DW_BLOCK (attr
)->data
;
22518 retval
.size
= DW_BLOCK (attr
)->size
;
22520 retval
.per_objfile
= dwarf2_per_objfile
;
22521 retval
.per_cu
= cu
->per_cu
;
22523 dwarf2_per_objfile
->age_comp_units ();
22530 struct dwarf2_locexpr_baton
22531 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22532 dwarf2_per_cu_data
*per_cu
,
22533 dwarf2_per_objfile
*per_objfile
,
22534 CORE_ADDR (*get_frame_pc
) (void *baton
),
22537 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22539 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22540 get_frame_pc
, baton
);
22543 /* Write a constant of a given type as target-ordered bytes into
22546 static const gdb_byte
*
22547 write_constant_as_bytes (struct obstack
*obstack
,
22548 enum bfd_endian byte_order
,
22555 *len
= TYPE_LENGTH (type
);
22556 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22557 store_unsigned_integer (result
, *len
, byte_order
, value
);
22565 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22566 dwarf2_per_cu_data
*per_cu
,
22567 dwarf2_per_objfile
*per_objfile
,
22571 struct die_info
*die
;
22572 struct attribute
*attr
;
22573 const gdb_byte
*result
= NULL
;
22576 enum bfd_endian byte_order
;
22577 struct objfile
*objfile
= per_objfile
->objfile
;
22579 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22581 cu
= load_cu (per_cu
, per_objfile
, false);
22585 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22586 Instead just throw an error, not much else we can do. */
22587 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22588 sect_offset_str (sect_off
), objfile_name (objfile
));
22591 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22593 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22594 sect_offset_str (sect_off
), objfile_name (objfile
));
22596 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22600 byte_order
= (bfd_big_endian (objfile
->obfd
)
22601 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22603 switch (attr
->form
)
22606 case DW_FORM_addrx
:
22607 case DW_FORM_GNU_addr_index
:
22611 *len
= cu
->header
.addr_size
;
22612 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22613 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22617 case DW_FORM_string
:
22620 case DW_FORM_GNU_str_index
:
22621 case DW_FORM_GNU_strp_alt
:
22622 /* DW_STRING is already allocated on the objfile obstack, point
22624 result
= (const gdb_byte
*) DW_STRING (attr
);
22625 *len
= strlen (DW_STRING (attr
));
22627 case DW_FORM_block1
:
22628 case DW_FORM_block2
:
22629 case DW_FORM_block4
:
22630 case DW_FORM_block
:
22631 case DW_FORM_exprloc
:
22632 case DW_FORM_data16
:
22633 result
= DW_BLOCK (attr
)->data
;
22634 *len
= DW_BLOCK (attr
)->size
;
22637 /* The DW_AT_const_value attributes are supposed to carry the
22638 symbol's value "represented as it would be on the target
22639 architecture." By the time we get here, it's already been
22640 converted to host endianness, so we just need to sign- or
22641 zero-extend it as appropriate. */
22642 case DW_FORM_data1
:
22643 type
= die_type (die
, cu
);
22644 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22645 if (result
== NULL
)
22646 result
= write_constant_as_bytes (obstack
, byte_order
,
22649 case DW_FORM_data2
:
22650 type
= die_type (die
, cu
);
22651 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22652 if (result
== NULL
)
22653 result
= write_constant_as_bytes (obstack
, byte_order
,
22656 case DW_FORM_data4
:
22657 type
= die_type (die
, cu
);
22658 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22659 if (result
== NULL
)
22660 result
= write_constant_as_bytes (obstack
, byte_order
,
22663 case DW_FORM_data8
:
22664 type
= die_type (die
, cu
);
22665 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22666 if (result
== NULL
)
22667 result
= write_constant_as_bytes (obstack
, byte_order
,
22671 case DW_FORM_sdata
:
22672 case DW_FORM_implicit_const
:
22673 type
= die_type (die
, cu
);
22674 result
= write_constant_as_bytes (obstack
, byte_order
,
22675 type
, DW_SND (attr
), len
);
22678 case DW_FORM_udata
:
22679 type
= die_type (die
, cu
);
22680 result
= write_constant_as_bytes (obstack
, byte_order
,
22681 type
, DW_UNSND (attr
), len
);
22685 complaint (_("unsupported const value attribute form: '%s'"),
22686 dwarf_form_name (attr
->form
));
22696 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22697 dwarf2_per_cu_data
*per_cu
,
22698 dwarf2_per_objfile
*per_objfile
)
22700 struct die_info
*die
;
22702 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22704 cu
= load_cu (per_cu
, per_objfile
, false);
22709 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22713 return die_type (die
, cu
);
22719 dwarf2_get_die_type (cu_offset die_offset
,
22720 dwarf2_per_cu_data
*per_cu
,
22721 dwarf2_per_objfile
*per_objfile
)
22723 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22724 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
22727 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22728 On entry *REF_CU is the CU of SRC_DIE.
22729 On exit *REF_CU is the CU of the result.
22730 Returns NULL if the referenced DIE isn't found. */
22732 static struct die_info
*
22733 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22734 struct dwarf2_cu
**ref_cu
)
22736 struct die_info temp_die
;
22737 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22738 struct die_info
*die
;
22739 dwarf2_per_objfile
*dwarf2_per_objfile
= (*ref_cu
)->per_objfile
;
22742 /* While it might be nice to assert sig_type->type == NULL here,
22743 we can get here for DW_AT_imported_declaration where we need
22744 the DIE not the type. */
22746 /* If necessary, add it to the queue and load its DIEs. */
22748 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, dwarf2_per_objfile
,
22750 read_signatured_type (sig_type
, dwarf2_per_objfile
);
22752 sig_cu
= dwarf2_per_objfile
->get_cu (&sig_type
->per_cu
);
22753 gdb_assert (sig_cu
!= NULL
);
22754 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22755 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22756 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22757 to_underlying (temp_die
.sect_off
));
22760 /* For .gdb_index version 7 keep track of included TUs.
22761 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22762 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
22763 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7)
22765 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22770 sig_cu
->ancestor
= cu
;
22778 /* Follow signatured type referenced by ATTR in SRC_DIE.
22779 On entry *REF_CU is the CU of SRC_DIE.
22780 On exit *REF_CU is the CU of the result.
22781 The result is the DIE of the type.
22782 If the referenced type cannot be found an error is thrown. */
22784 static struct die_info
*
22785 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22786 struct dwarf2_cu
**ref_cu
)
22788 ULONGEST signature
= DW_SIGNATURE (attr
);
22789 struct signatured_type
*sig_type
;
22790 struct die_info
*die
;
22792 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22794 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22795 /* sig_type will be NULL if the signatured type is missing from
22797 if (sig_type
== NULL
)
22799 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22800 " from DIE at %s [in module %s]"),
22801 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22802 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22805 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22808 dump_die_for_error (src_die
);
22809 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22810 " from DIE at %s [in module %s]"),
22811 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22812 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22818 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22819 reading in and processing the type unit if necessary. */
22821 static struct type
*
22822 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22823 struct dwarf2_cu
*cu
)
22825 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22826 struct signatured_type
*sig_type
;
22827 struct dwarf2_cu
*type_cu
;
22828 struct die_info
*type_die
;
22831 sig_type
= lookup_signatured_type (cu
, signature
);
22832 /* sig_type will be NULL if the signatured type is missing from
22834 if (sig_type
== NULL
)
22836 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22837 " from DIE at %s [in module %s]"),
22838 hex_string (signature
), sect_offset_str (die
->sect_off
),
22839 objfile_name (dwarf2_per_objfile
->objfile
));
22840 return build_error_marker_type (cu
, die
);
22843 /* If we already know the type we're done. */
22844 type
= dwarf2_per_objfile
->get_type_for_signatured_type (sig_type
);
22845 if (type
!= nullptr)
22849 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22850 if (type_die
!= NULL
)
22852 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22853 is created. This is important, for example, because for c++ classes
22854 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22855 type
= read_type_die (type_die
, type_cu
);
22858 complaint (_("Dwarf Error: Cannot build signatured type %s"
22859 " referenced from DIE at %s [in module %s]"),
22860 hex_string (signature
), sect_offset_str (die
->sect_off
),
22861 objfile_name (dwarf2_per_objfile
->objfile
));
22862 type
= build_error_marker_type (cu
, die
);
22867 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22868 " from DIE at %s [in module %s]"),
22869 hex_string (signature
), sect_offset_str (die
->sect_off
),
22870 objfile_name (dwarf2_per_objfile
->objfile
));
22871 type
= build_error_marker_type (cu
, die
);
22874 dwarf2_per_objfile
->set_type_for_signatured_type (sig_type
, type
);
22879 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22880 reading in and processing the type unit if necessary. */
22882 static struct type
*
22883 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22884 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22886 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22887 if (attr
->form_is_ref ())
22889 struct dwarf2_cu
*type_cu
= cu
;
22890 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22892 return read_type_die (type_die
, type_cu
);
22894 else if (attr
->form
== DW_FORM_ref_sig8
)
22896 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22900 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22902 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22903 " at %s [in module %s]"),
22904 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22905 objfile_name (dwarf2_per_objfile
->objfile
));
22906 return build_error_marker_type (cu
, die
);
22910 /* Load the DIEs associated with type unit PER_CU into memory. */
22913 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22914 dwarf2_per_objfile
*per_objfile
)
22916 struct signatured_type
*sig_type
;
22918 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22919 gdb_assert (! per_cu
->type_unit_group_p ());
22921 /* We have the per_cu, but we need the signatured_type.
22922 Fortunately this is an easy translation. */
22923 gdb_assert (per_cu
->is_debug_types
);
22924 sig_type
= (struct signatured_type
*) per_cu
;
22926 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22928 read_signatured_type (sig_type
, per_objfile
);
22930 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
22933 /* Read in a signatured type and build its CU and DIEs.
22934 If the type is a stub for the real type in a DWO file,
22935 read in the real type from the DWO file as well. */
22938 read_signatured_type (signatured_type
*sig_type
,
22939 dwarf2_per_objfile
*per_objfile
)
22941 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22943 gdb_assert (per_cu
->is_debug_types
);
22944 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22946 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
22948 if (!reader
.dummy_p
)
22950 struct dwarf2_cu
*cu
= reader
.cu
;
22951 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22953 gdb_assert (cu
->die_hash
== NULL
);
22955 htab_create_alloc_ex (cu
->header
.length
/ 12,
22959 &cu
->comp_unit_obstack
,
22960 hashtab_obstack_allocate
,
22961 dummy_obstack_deallocate
);
22963 if (reader
.comp_unit_die
->has_children
)
22964 reader
.comp_unit_die
->child
22965 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22966 reader
.comp_unit_die
);
22967 cu
->dies
= reader
.comp_unit_die
;
22968 /* comp_unit_die is not stored in die_hash, no need. */
22970 /* We try not to read any attributes in this function, because
22971 not all CUs needed for references have been loaded yet, and
22972 symbol table processing isn't initialized. But we have to
22973 set the CU language, or we won't be able to build types
22974 correctly. Similarly, if we do not read the producer, we can
22975 not apply producer-specific interpretation. */
22976 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22981 sig_type
->per_cu
.tu_read
= 1;
22984 /* Decode simple location descriptions.
22985 Given a pointer to a dwarf block that defines a location, compute
22986 the location and return the value. If COMPUTED is non-null, it is
22987 set to true to indicate that decoding was successful, and false
22988 otherwise. If COMPUTED is null, then this function may emit a
22992 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22994 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22996 size_t size
= blk
->size
;
22997 const gdb_byte
*data
= blk
->data
;
22998 CORE_ADDR stack
[64];
23000 unsigned int bytes_read
, unsnd
;
23003 if (computed
!= nullptr)
23009 stack
[++stacki
] = 0;
23048 stack
[++stacki
] = op
- DW_OP_lit0
;
23083 stack
[++stacki
] = op
- DW_OP_reg0
;
23086 if (computed
== nullptr)
23087 dwarf2_complex_location_expr_complaint ();
23094 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23096 stack
[++stacki
] = unsnd
;
23099 if (computed
== nullptr)
23100 dwarf2_complex_location_expr_complaint ();
23107 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23112 case DW_OP_const1u
:
23113 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23117 case DW_OP_const1s
:
23118 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23122 case DW_OP_const2u
:
23123 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23127 case DW_OP_const2s
:
23128 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23132 case DW_OP_const4u
:
23133 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23137 case DW_OP_const4s
:
23138 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23142 case DW_OP_const8u
:
23143 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23148 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23154 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23159 stack
[stacki
+ 1] = stack
[stacki
];
23164 stack
[stacki
- 1] += stack
[stacki
];
23168 case DW_OP_plus_uconst
:
23169 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23175 stack
[stacki
- 1] -= stack
[stacki
];
23180 /* If we're not the last op, then we definitely can't encode
23181 this using GDB's address_class enum. This is valid for partial
23182 global symbols, although the variable's address will be bogus
23186 if (computed
== nullptr)
23187 dwarf2_complex_location_expr_complaint ();
23193 case DW_OP_GNU_push_tls_address
:
23194 case DW_OP_form_tls_address
:
23195 /* The top of the stack has the offset from the beginning
23196 of the thread control block at which the variable is located. */
23197 /* Nothing should follow this operator, so the top of stack would
23199 /* This is valid for partial global symbols, but the variable's
23200 address will be bogus in the psymtab. Make it always at least
23201 non-zero to not look as a variable garbage collected by linker
23202 which have DW_OP_addr 0. */
23205 if (computed
== nullptr)
23206 dwarf2_complex_location_expr_complaint ();
23213 case DW_OP_GNU_uninit
:
23214 if (computed
!= nullptr)
23219 case DW_OP_GNU_addr_index
:
23220 case DW_OP_GNU_const_index
:
23221 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23227 if (computed
== nullptr)
23229 const char *name
= get_DW_OP_name (op
);
23232 complaint (_("unsupported stack op: '%s'"),
23235 complaint (_("unsupported stack op: '%02x'"),
23239 return (stack
[stacki
]);
23242 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23243 outside of the allocated space. Also enforce minimum>0. */
23244 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23246 if (computed
== nullptr)
23247 complaint (_("location description stack overflow"));
23253 if (computed
== nullptr)
23254 complaint (_("location description stack underflow"));
23259 if (computed
!= nullptr)
23261 return (stack
[stacki
]);
23264 /* memory allocation interface */
23266 static struct dwarf_block
*
23267 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23269 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23272 static struct die_info
*
23273 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23275 struct die_info
*die
;
23276 size_t size
= sizeof (struct die_info
);
23279 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23281 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23282 memset (die
, 0, sizeof (struct die_info
));
23288 /* Macro support. */
23290 /* An overload of dwarf_decode_macros that finds the correct section
23291 and ensures it is read in before calling the other overload. */
23294 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23295 int section_is_gnu
)
23297 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23298 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23299 const struct line_header
*lh
= cu
->line_header
;
23300 unsigned int offset_size
= cu
->header
.offset_size
;
23301 struct dwarf2_section_info
*section
;
23302 const char *section_name
;
23304 if (cu
->dwo_unit
!= nullptr)
23306 if (section_is_gnu
)
23308 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23309 section_name
= ".debug_macro.dwo";
23313 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23314 section_name
= ".debug_macinfo.dwo";
23319 if (section_is_gnu
)
23321 section
= &dwarf2_per_objfile
->per_bfd
->macro
;
23322 section_name
= ".debug_macro";
23326 section
= &dwarf2_per_objfile
->per_bfd
->macinfo
;
23327 section_name
= ".debug_macinfo";
23331 section
->read (objfile
);
23332 if (section
->buffer
== nullptr)
23334 complaint (_("missing %s section"), section_name
);
23338 buildsym_compunit
*builder
= cu
->get_builder ();
23340 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23341 offset_size
, offset
, section_is_gnu
);
23344 /* Return the .debug_loc section to use for CU.
23345 For DWO files use .debug_loc.dwo. */
23347 static struct dwarf2_section_info
*
23348 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23350 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23354 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23356 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23358 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->per_bfd
->loclists
23359 : &dwarf2_per_objfile
->per_bfd
->loc
);
23362 /* A helper function that fills in a dwarf2_loclist_baton. */
23365 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23366 struct dwarf2_loclist_baton
*baton
,
23367 const struct attribute
*attr
)
23369 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23370 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23372 section
->read (dwarf2_per_objfile
->objfile
);
23374 baton
->per_objfile
= dwarf2_per_objfile
;
23375 baton
->per_cu
= cu
->per_cu
;
23376 gdb_assert (baton
->per_cu
);
23377 /* We don't know how long the location list is, but make sure we
23378 don't run off the edge of the section. */
23379 baton
->size
= section
->size
- DW_UNSND (attr
);
23380 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23381 if (cu
->base_address
.has_value ())
23382 baton
->base_address
= *cu
->base_address
;
23384 baton
->base_address
= 0;
23385 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23389 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23390 struct dwarf2_cu
*cu
, int is_block
)
23392 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23393 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23394 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23396 if (attr
->form_is_section_offset ()
23397 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23398 the section. If so, fall through to the complaint in the
23400 && DW_UNSND (attr
) < section
->get_size (objfile
))
23402 struct dwarf2_loclist_baton
*baton
;
23404 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23406 fill_in_loclist_baton (cu
, baton
, attr
);
23408 if (!cu
->base_address
.has_value ())
23409 complaint (_("Location list used without "
23410 "specifying the CU base address."));
23412 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23413 ? dwarf2_loclist_block_index
23414 : dwarf2_loclist_index
);
23415 SYMBOL_LOCATION_BATON (sym
) = baton
;
23419 struct dwarf2_locexpr_baton
*baton
;
23421 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23422 baton
->per_objfile
= dwarf2_per_objfile
;
23423 baton
->per_cu
= cu
->per_cu
;
23424 gdb_assert (baton
->per_cu
);
23426 if (attr
->form_is_block ())
23428 /* Note that we're just copying the block's data pointer
23429 here, not the actual data. We're still pointing into the
23430 info_buffer for SYM's objfile; right now we never release
23431 that buffer, but when we do clean up properly this may
23433 baton
->size
= DW_BLOCK (attr
)->size
;
23434 baton
->data
= DW_BLOCK (attr
)->data
;
23438 dwarf2_invalid_attrib_class_complaint ("location description",
23439 sym
->natural_name ());
23443 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23444 ? dwarf2_locexpr_block_index
23445 : dwarf2_locexpr_index
);
23446 SYMBOL_LOCATION_BATON (sym
) = baton
;
23452 const comp_unit_head
*
23453 dwarf2_per_cu_data::get_header () const
23455 if (!m_header_read_in
)
23457 const gdb_byte
*info_ptr
23458 = this->section
->buffer
+ to_underlying (this->sect_off
);
23460 memset (&m_header
, 0, sizeof (m_header
));
23462 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
23463 rcuh_kind::COMPILE
);
23472 dwarf2_per_cu_data::addr_size () const
23474 return this->get_header ()->addr_size
;
23480 dwarf2_per_cu_data::offset_size () const
23482 return this->get_header ()->offset_size
;
23488 dwarf2_per_cu_data::ref_addr_size () const
23490 const comp_unit_head
*header
= this->get_header ();
23492 if (header
->version
== 2)
23493 return header
->addr_size
;
23495 return header
->offset_size
;
23501 dwarf2_cu::addr_type () const
23503 struct objfile
*objfile
= this->per_objfile
->objfile
;
23504 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23505 struct type
*addr_type
= lookup_pointer_type (void_type
);
23506 int addr_size
= this->per_cu
->addr_size ();
23508 if (TYPE_LENGTH (addr_type
) == addr_size
)
23511 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23515 /* A helper function for dwarf2_find_containing_comp_unit that returns
23516 the index of the result, and that searches a vector. It will
23517 return a result even if the offset in question does not actually
23518 occur in any CU. This is separate so that it can be unit
23522 dwarf2_find_containing_comp_unit
23523 (sect_offset sect_off
,
23524 unsigned int offset_in_dwz
,
23525 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23530 high
= all_comp_units
.size () - 1;
23533 struct dwarf2_per_cu_data
*mid_cu
;
23534 int mid
= low
+ (high
- low
) / 2;
23536 mid_cu
= all_comp_units
[mid
];
23537 if (mid_cu
->is_dwz
> offset_in_dwz
23538 || (mid_cu
->is_dwz
== offset_in_dwz
23539 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23544 gdb_assert (low
== high
);
23548 /* Locate the .debug_info compilation unit from CU's objfile which contains
23549 the DIE at OFFSET. Raises an error on failure. */
23551 static struct dwarf2_per_cu_data
*
23552 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23553 unsigned int offset_in_dwz
,
23554 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23557 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23558 dwarf2_per_objfile
->per_bfd
->all_comp_units
);
23559 struct dwarf2_per_cu_data
*this_cu
23560 = dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
];
23562 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23564 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23565 error (_("Dwarf Error: could not find partial DIE containing "
23566 "offset %s [in module %s]"),
23567 sect_offset_str (sect_off
),
23568 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23570 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23572 return dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1];
23576 if (low
== dwarf2_per_objfile
->per_bfd
->all_comp_units
.size () - 1
23577 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23578 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23579 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23586 namespace selftests
{
23587 namespace find_containing_comp_unit
{
23592 struct dwarf2_per_cu_data one
{};
23593 struct dwarf2_per_cu_data two
{};
23594 struct dwarf2_per_cu_data three
{};
23595 struct dwarf2_per_cu_data four
{};
23598 two
.sect_off
= sect_offset (one
.length
);
23603 four
.sect_off
= sect_offset (three
.length
);
23607 std::vector
<dwarf2_per_cu_data
*> units
;
23608 units
.push_back (&one
);
23609 units
.push_back (&two
);
23610 units
.push_back (&three
);
23611 units
.push_back (&four
);
23615 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23616 SELF_CHECK (units
[result
] == &one
);
23617 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23618 SELF_CHECK (units
[result
] == &one
);
23619 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23620 SELF_CHECK (units
[result
] == &two
);
23622 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23623 SELF_CHECK (units
[result
] == &three
);
23624 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23625 SELF_CHECK (units
[result
] == &three
);
23626 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23627 SELF_CHECK (units
[result
] == &four
);
23633 #endif /* GDB_SELF_TEST */
23635 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23637 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23638 dwarf2_per_objfile
*per_objfile
)
23640 per_objfile (per_objfile
),
23642 has_loclist (false),
23643 checked_producer (false),
23644 producer_is_gxx_lt_4_6 (false),
23645 producer_is_gcc_lt_4_3 (false),
23646 producer_is_icc (false),
23647 producer_is_icc_lt_14 (false),
23648 producer_is_codewarrior (false),
23649 processing_has_namespace_info (false)
23653 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23656 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23657 enum language pretend_language
)
23659 struct attribute
*attr
;
23661 /* Set the language we're debugging. */
23662 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23663 if (attr
!= nullptr)
23664 set_cu_language (DW_UNSND (attr
), cu
);
23667 cu
->language
= pretend_language
;
23668 cu
->language_defn
= language_def (cu
->language
);
23671 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23677 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
23679 auto it
= m_dwarf2_cus
.find (per_cu
);
23680 if (it
== m_dwarf2_cus
.end ())
23689 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
23691 gdb_assert (this->get_cu (per_cu
) == nullptr);
23693 m_dwarf2_cus
[per_cu
] = cu
;
23699 dwarf2_per_objfile::age_comp_units ()
23701 /* Start by clearing all marks. */
23702 for (auto pair
: m_dwarf2_cus
)
23703 pair
.second
->mark
= false;
23705 /* Traverse all CUs, mark them and their dependencies if used recently
23707 for (auto pair
: m_dwarf2_cus
)
23709 dwarf2_cu
*cu
= pair
.second
;
23712 if (cu
->last_used
<= dwarf_max_cache_age
)
23716 /* Delete all CUs still not marked. */
23717 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
23719 dwarf2_cu
*cu
= it
->second
;
23724 it
= m_dwarf2_cus
.erase (it
);
23734 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
23736 auto it
= m_dwarf2_cus
.find (per_cu
);
23737 if (it
== m_dwarf2_cus
.end ())
23742 m_dwarf2_cus
.erase (it
);
23745 dwarf2_per_objfile::~dwarf2_per_objfile ()
23750 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23751 We store these in a hash table separate from the DIEs, and preserve them
23752 when the DIEs are flushed out of cache.
23754 The CU "per_cu" pointer is needed because offset alone is not enough to
23755 uniquely identify the type. A file may have multiple .debug_types sections,
23756 or the type may come from a DWO file. Furthermore, while it's more logical
23757 to use per_cu->section+offset, with Fission the section with the data is in
23758 the DWO file but we don't know that section at the point we need it.
23759 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23760 because we can enter the lookup routine, get_die_type_at_offset, from
23761 outside this file, and thus won't necessarily have PER_CU->cu.
23762 Fortunately, PER_CU is stable for the life of the objfile. */
23764 struct dwarf2_per_cu_offset_and_type
23766 const struct dwarf2_per_cu_data
*per_cu
;
23767 sect_offset sect_off
;
23771 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23774 per_cu_offset_and_type_hash (const void *item
)
23776 const struct dwarf2_per_cu_offset_and_type
*ofs
23777 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23779 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23782 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23785 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23787 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23788 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23789 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23790 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23792 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23793 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23796 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23797 table if necessary. For convenience, return TYPE.
23799 The DIEs reading must have careful ordering to:
23800 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23801 reading current DIE.
23802 * Not trying to dereference contents of still incompletely read in types
23803 while reading in other DIEs.
23804 * Enable referencing still incompletely read in types just by a pointer to
23805 the type without accessing its fields.
23807 Therefore caller should follow these rules:
23808 * Try to fetch any prerequisite types we may need to build this DIE type
23809 before building the type and calling set_die_type.
23810 * After building type call set_die_type for current DIE as soon as
23811 possible before fetching more types to complete the current type.
23812 * Make the type as complete as possible before fetching more types. */
23814 static struct type
*
23815 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23817 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23818 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23819 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23820 struct attribute
*attr
;
23821 struct dynamic_prop prop
;
23823 /* For Ada types, make sure that the gnat-specific data is always
23824 initialized (if not already set). There are a few types where
23825 we should not be doing so, because the type-specific area is
23826 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23827 where the type-specific area is used to store the floatformat).
23828 But this is not a problem, because the gnat-specific information
23829 is actually not needed for these types. */
23830 if (need_gnat_info (cu
)
23831 && type
->code () != TYPE_CODE_FUNC
23832 && type
->code () != TYPE_CODE_FLT
23833 && type
->code () != TYPE_CODE_METHODPTR
23834 && type
->code () != TYPE_CODE_MEMBERPTR
23835 && type
->code () != TYPE_CODE_METHOD
23836 && !HAVE_GNAT_AUX_INFO (type
))
23837 INIT_GNAT_SPECIFIC (type
);
23839 /* Read DW_AT_allocated and set in type. */
23840 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23841 if (attr
!= NULL
&& attr
->form_is_block ())
23843 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23844 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23845 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23847 else if (attr
!= NULL
)
23849 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23850 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23851 sect_offset_str (die
->sect_off
));
23854 /* Read DW_AT_associated and set in type. */
23855 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23856 if (attr
!= NULL
&& attr
->form_is_block ())
23858 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23859 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23860 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23862 else if (attr
!= NULL
)
23864 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23865 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23866 sect_offset_str (die
->sect_off
));
23869 /* Read DW_AT_data_location and set in type. */
23870 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23871 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23872 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23874 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23875 dwarf2_per_objfile
->die_type_hash
23876 = htab_up (htab_create_alloc (127,
23877 per_cu_offset_and_type_hash
,
23878 per_cu_offset_and_type_eq
,
23879 NULL
, xcalloc
, xfree
));
23881 ofs
.per_cu
= cu
->per_cu
;
23882 ofs
.sect_off
= die
->sect_off
;
23884 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23885 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23887 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23888 sect_offset_str (die
->sect_off
));
23889 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23890 struct dwarf2_per_cu_offset_and_type
);
23895 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23896 or return NULL if the die does not have a saved type. */
23898 static struct type
*
23899 get_die_type_at_offset (sect_offset sect_off
,
23900 dwarf2_per_cu_data
*per_cu
,
23901 dwarf2_per_objfile
*dwarf2_per_objfile
)
23903 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23905 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23908 ofs
.per_cu
= per_cu
;
23909 ofs
.sect_off
= sect_off
;
23910 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23911 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23918 /* Look up the type for DIE in CU in die_type_hash,
23919 or return NULL if DIE does not have a saved type. */
23921 static struct type
*
23922 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23924 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
23927 /* Add a dependence relationship from CU to REF_PER_CU. */
23930 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23931 struct dwarf2_per_cu_data
*ref_per_cu
)
23935 if (cu
->dependencies
== NULL
)
23937 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23938 NULL
, &cu
->comp_unit_obstack
,
23939 hashtab_obstack_allocate
,
23940 dummy_obstack_deallocate
);
23942 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23944 *slot
= ref_per_cu
;
23947 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23948 Set the mark field in every compilation unit in the
23949 cache that we must keep because we are keeping CU.
23951 DATA is the dwarf2_per_objfile object in which to look up CUs. */
23954 dwarf2_mark_helper (void **slot
, void *data
)
23956 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
23957 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
23958 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23960 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23961 reading of the chain. As such dependencies remain valid it is not much
23962 useful to track and undo them during QUIT cleanups. */
23971 if (cu
->dependencies
!= nullptr)
23972 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
23977 /* Set the mark field in CU and in every other compilation unit in the
23978 cache that we must keep because we are keeping CU. */
23981 dwarf2_mark (struct dwarf2_cu
*cu
)
23988 if (cu
->dependencies
!= nullptr)
23989 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
23992 /* Trivial hash function for partial_die_info: the hash value of a DIE
23993 is its offset in .debug_info for this objfile. */
23996 partial_die_hash (const void *item
)
23998 const struct partial_die_info
*part_die
23999 = (const struct partial_die_info
*) item
;
24001 return to_underlying (part_die
->sect_off
);
24004 /* Trivial comparison function for partial_die_info structures: two DIEs
24005 are equal if they have the same offset. */
24008 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24010 const struct partial_die_info
*part_die_lhs
24011 = (const struct partial_die_info
*) item_lhs
;
24012 const struct partial_die_info
*part_die_rhs
24013 = (const struct partial_die_info
*) item_rhs
;
24015 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24018 struct cmd_list_element
*set_dwarf_cmdlist
;
24019 struct cmd_list_element
*show_dwarf_cmdlist
;
24022 show_check_physname (struct ui_file
*file
, int from_tty
,
24023 struct cmd_list_element
*c
, const char *value
)
24025 fprintf_filtered (file
,
24026 _("Whether to check \"physname\" is %s.\n"),
24030 void _initialize_dwarf2_read ();
24032 _initialize_dwarf2_read ()
24034 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24035 Set DWARF specific variables.\n\
24036 Configure DWARF variables such as the cache size."),
24037 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24038 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24040 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24041 Show DWARF specific variables.\n\
24042 Show DWARF variables such as the cache size."),
24043 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24044 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24046 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24047 &dwarf_max_cache_age
, _("\
24048 Set the upper bound on the age of cached DWARF compilation units."), _("\
24049 Show the upper bound on the age of cached DWARF compilation units."), _("\
24050 A higher limit means that cached compilation units will be stored\n\
24051 in memory longer, and more total memory will be used. Zero disables\n\
24052 caching, which can slow down startup."),
24054 show_dwarf_max_cache_age
,
24055 &set_dwarf_cmdlist
,
24056 &show_dwarf_cmdlist
);
24058 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24059 Set debugging of the DWARF reader."), _("\
24060 Show debugging of the DWARF reader."), _("\
24061 When enabled (non-zero), debugging messages are printed during DWARF\n\
24062 reading and symtab expansion. A value of 1 (one) provides basic\n\
24063 information. A value greater than 1 provides more verbose information."),
24066 &setdebuglist
, &showdebuglist
);
24068 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24069 Set debugging of the DWARF DIE reader."), _("\
24070 Show debugging of the DWARF DIE reader."), _("\
24071 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24072 The value is the maximum depth to print."),
24075 &setdebuglist
, &showdebuglist
);
24077 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24078 Set debugging of the dwarf line reader."), _("\
24079 Show debugging of the dwarf line reader."), _("\
24080 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24081 A value of 1 (one) provides basic information.\n\
24082 A value greater than 1 provides more verbose information."),
24085 &setdebuglist
, &showdebuglist
);
24087 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24088 Set cross-checking of \"physname\" code against demangler."), _("\
24089 Show cross-checking of \"physname\" code against demangler."), _("\
24090 When enabled, GDB's internal \"physname\" code is checked against\n\
24092 NULL
, show_check_physname
,
24093 &setdebuglist
, &showdebuglist
);
24095 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24096 no_class
, &use_deprecated_index_sections
, _("\
24097 Set whether to use deprecated gdb_index sections."), _("\
24098 Show whether to use deprecated gdb_index sections."), _("\
24099 When enabled, deprecated .gdb_index sections are used anyway.\n\
24100 Normally they are ignored either because of a missing feature or\n\
24101 performance issue.\n\
24102 Warning: This option must be enabled before gdb reads the file."),
24105 &setlist
, &showlist
);
24107 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24108 &dwarf2_locexpr_funcs
);
24109 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24110 &dwarf2_loclist_funcs
);
24112 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24113 &dwarf2_block_frame_base_locexpr_funcs
);
24114 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24115 &dwarf2_block_frame_base_loclist_funcs
);
24118 selftests::register_test ("dw2_expand_symtabs_matching",
24119 selftests::dw2_expand_symtabs_matching::run_test
);
24120 selftests::register_test ("dwarf2_find_containing_comp_unit",
24121 selftests::find_containing_comp_unit::run_test
);