1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
43 #include "dwarf2/stringify.h"
52 #include "gdb-demangle.h"
53 #include "filenames.h" /* for DOSish file names */
55 #include "complaints.h"
56 #include "dwarf2/expr.h"
57 #include "dwarf2/loc.h"
58 #include "cp-support.h"
64 #include "typeprint.h"
69 #include "gdbcore.h" /* for gnutarget */
70 #include "gdb/gdb-index.h"
75 #include "namespace.h"
76 #include "gdbsupport/function-view.h"
77 #include "gdbsupport/gdb_optional.h"
78 #include "gdbsupport/underlying.h"
79 #include "gdbsupport/hash_enum.h"
80 #include "filename-seen-cache.h"
84 #include <unordered_map>
85 #include "gdbsupport/selftest.h"
86 #include "rust-lang.h"
87 #include "gdbsupport/pathstuff.h"
88 #include "count-one-bits.h"
89 #include "debuginfod-support.h"
91 /* When == 1, print basic high level tracing messages.
92 When > 1, be more verbose.
93 This is in contrast to the low level DIE reading of dwarf_die_debug. */
94 static unsigned int dwarf_read_debug
= 0;
96 /* When non-zero, dump DIEs after they are read in. */
97 static unsigned int dwarf_die_debug
= 0;
99 /* When non-zero, dump line number entries as they are read in. */
100 unsigned int dwarf_line_debug
= 0;
102 /* When true, cross-check physname against demangler. */
103 static bool check_physname
= false;
105 /* When true, do not reject deprecated .gdb_index sections. */
106 static bool use_deprecated_index_sections
= false;
108 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
110 /* The "aclass" indices for various kinds of computed DWARF symbols. */
112 static int dwarf2_locexpr_index
;
113 static int dwarf2_loclist_index
;
114 static int dwarf2_locexpr_block_index
;
115 static int dwarf2_loclist_block_index
;
117 /* Size of .debug_loclists section header for 32-bit DWARF format. */
118 #define LOCLIST_HEADER_SIZE32 12
120 /* Size of .debug_loclists section header for 64-bit DWARF format. */
121 #define LOCLIST_HEADER_SIZE64 20
123 /* An index into a (C++) symbol name component in a symbol name as
124 recorded in the mapped_index's symbol table. For each C++ symbol
125 in the symbol table, we record one entry for the start of each
126 component in the symbol in a table of name components, and then
127 sort the table, in order to be able to binary search symbol names,
128 ignoring leading namespaces, both completion and regular look up.
129 For example, for symbol "A::B::C", we'll have an entry that points
130 to "A::B::C", another that points to "B::C", and another for "C".
131 Note that function symbols in GDB index have no parameter
132 information, just the function/method names. You can convert a
133 name_component to a "const char *" using the
134 'mapped_index::symbol_name_at(offset_type)' method. */
136 struct name_component
138 /* Offset in the symbol name where the component starts. Stored as
139 a (32-bit) offset instead of a pointer to save memory and improve
140 locality on 64-bit architectures. */
141 offset_type name_offset
;
143 /* The symbol's index in the symbol and constant pool tables of a
148 /* Base class containing bits shared by both .gdb_index and
149 .debug_name indexes. */
151 struct mapped_index_base
153 mapped_index_base () = default;
154 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
156 /* The name_component table (a sorted vector). See name_component's
157 description above. */
158 std::vector
<name_component
> name_components
;
160 /* How NAME_COMPONENTS is sorted. */
161 enum case_sensitivity name_components_casing
;
163 /* Return the number of names in the symbol table. */
164 virtual size_t symbol_name_count () const = 0;
166 /* Get the name of the symbol at IDX in the symbol table. */
167 virtual const char *symbol_name_at (offset_type idx
) const = 0;
169 /* Return whether the name at IDX in the symbol table should be
171 virtual bool symbol_name_slot_invalid (offset_type idx
) const
176 /* Build the symbol name component sorted vector, if we haven't
178 void build_name_components ();
180 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
181 possible matches for LN_NO_PARAMS in the name component
183 std::pair
<std::vector
<name_component
>::const_iterator
,
184 std::vector
<name_component
>::const_iterator
>
185 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
186 enum language lang
) const;
188 /* Prevent deleting/destroying via a base class pointer. */
190 ~mapped_index_base() = default;
193 /* A description of the mapped index. The file format is described in
194 a comment by the code that writes the index. */
195 struct mapped_index final
: public mapped_index_base
197 /* A slot/bucket in the symbol table hash. */
198 struct symbol_table_slot
200 const offset_type name
;
201 const offset_type vec
;
204 /* Index data format version. */
207 /* The address table data. */
208 gdb::array_view
<const gdb_byte
> address_table
;
210 /* The symbol table, implemented as a hash table. */
211 gdb::array_view
<symbol_table_slot
> symbol_table
;
213 /* A pointer to the constant pool. */
214 const char *constant_pool
= nullptr;
216 bool symbol_name_slot_invalid (offset_type idx
) const override
218 const auto &bucket
= this->symbol_table
[idx
];
219 return bucket
.name
== 0 && bucket
.vec
== 0;
222 /* Convenience method to get at the name of the symbol at IDX in the
224 const char *symbol_name_at (offset_type idx
) const override
225 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
227 size_t symbol_name_count () const override
228 { return this->symbol_table
.size (); }
231 /* A description of the mapped .debug_names.
232 Uninitialized map has CU_COUNT 0. */
233 struct mapped_debug_names final
: public mapped_index_base
235 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
236 : dwarf2_per_objfile (dwarf2_per_objfile_
)
239 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
240 bfd_endian dwarf5_byte_order
;
241 bool dwarf5_is_dwarf64
;
242 bool augmentation_is_gdb
;
244 uint32_t cu_count
= 0;
245 uint32_t tu_count
, bucket_count
, name_count
;
246 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
247 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
248 const gdb_byte
*name_table_string_offs_reordered
;
249 const gdb_byte
*name_table_entry_offs_reordered
;
250 const gdb_byte
*entry_pool
;
257 /* Attribute name DW_IDX_*. */
260 /* Attribute form DW_FORM_*. */
263 /* Value if FORM is DW_FORM_implicit_const. */
264 LONGEST implicit_const
;
266 std::vector
<attr
> attr_vec
;
269 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
271 const char *namei_to_name (uint32_t namei
) const;
273 /* Implementation of the mapped_index_base virtual interface, for
274 the name_components cache. */
276 const char *symbol_name_at (offset_type idx
) const override
277 { return namei_to_name (idx
); }
279 size_t symbol_name_count () const override
280 { return this->name_count
; }
283 /* See dwarf2read.h. */
286 get_dwarf2_per_objfile (struct objfile
*objfile
)
288 return dwarf2_objfile_data_key
.get (objfile
);
291 /* Default names of the debugging sections. */
293 /* Note that if the debugging section has been compressed, it might
294 have a name like .zdebug_info. */
296 static const struct dwarf2_debug_sections dwarf2_elf_names
=
298 { ".debug_info", ".zdebug_info" },
299 { ".debug_abbrev", ".zdebug_abbrev" },
300 { ".debug_line", ".zdebug_line" },
301 { ".debug_loc", ".zdebug_loc" },
302 { ".debug_loclists", ".zdebug_loclists" },
303 { ".debug_macinfo", ".zdebug_macinfo" },
304 { ".debug_macro", ".zdebug_macro" },
305 { ".debug_str", ".zdebug_str" },
306 { ".debug_str_offsets", ".zdebug_str_offsets" },
307 { ".debug_line_str", ".zdebug_line_str" },
308 { ".debug_ranges", ".zdebug_ranges" },
309 { ".debug_rnglists", ".zdebug_rnglists" },
310 { ".debug_types", ".zdebug_types" },
311 { ".debug_addr", ".zdebug_addr" },
312 { ".debug_frame", ".zdebug_frame" },
313 { ".eh_frame", NULL
},
314 { ".gdb_index", ".zgdb_index" },
315 { ".debug_names", ".zdebug_names" },
316 { ".debug_aranges", ".zdebug_aranges" },
320 /* List of DWO/DWP sections. */
322 static const struct dwop_section_names
324 struct dwarf2_section_names abbrev_dwo
;
325 struct dwarf2_section_names info_dwo
;
326 struct dwarf2_section_names line_dwo
;
327 struct dwarf2_section_names loc_dwo
;
328 struct dwarf2_section_names loclists_dwo
;
329 struct dwarf2_section_names macinfo_dwo
;
330 struct dwarf2_section_names macro_dwo
;
331 struct dwarf2_section_names str_dwo
;
332 struct dwarf2_section_names str_offsets_dwo
;
333 struct dwarf2_section_names types_dwo
;
334 struct dwarf2_section_names cu_index
;
335 struct dwarf2_section_names tu_index
;
339 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
340 { ".debug_info.dwo", ".zdebug_info.dwo" },
341 { ".debug_line.dwo", ".zdebug_line.dwo" },
342 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
343 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
344 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
345 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
346 { ".debug_str.dwo", ".zdebug_str.dwo" },
347 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
348 { ".debug_types.dwo", ".zdebug_types.dwo" },
349 { ".debug_cu_index", ".zdebug_cu_index" },
350 { ".debug_tu_index", ".zdebug_tu_index" },
353 /* local data types */
355 /* The location list section (.debug_loclists) begins with a header,
356 which contains the following information. */
357 struct loclist_header
359 /* A 4-byte or 12-byte length containing the length of the
360 set of entries for this compilation unit, not including the
361 length field itself. */
364 /* A 2-byte version identifier. */
367 /* A 1-byte unsigned integer containing the size in bytes of an address on
368 the target system. */
369 unsigned char addr_size
;
371 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
372 on the target system. */
373 unsigned char segment_collector_size
;
375 /* A 4-byte count of the number of offsets that follow the header. */
376 unsigned int offset_entry_count
;
379 /* Type used for delaying computation of method physnames.
380 See comments for compute_delayed_physnames. */
381 struct delayed_method_info
383 /* The type to which the method is attached, i.e., its parent class. */
386 /* The index of the method in the type's function fieldlists. */
389 /* The index of the method in the fieldlist. */
392 /* The name of the DIE. */
395 /* The DIE associated with this method. */
396 struct die_info
*die
;
399 /* Internal state when decoding a particular compilation unit. */
402 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
403 dwarf2_per_objfile
*per_objfile
);
406 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
408 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
409 Create the set of symtabs used by this TU, or if this TU is sharing
410 symtabs with another TU and the symtabs have already been created
411 then restore those symtabs in the line header.
412 We don't need the pc/line-number mapping for type units. */
413 void setup_type_unit_groups (struct die_info
*die
);
415 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
416 buildsym_compunit constructor. */
417 struct compunit_symtab
*start_symtab (const char *name
,
418 const char *comp_dir
,
421 /* Reset the builder. */
422 void reset_builder () { m_builder
.reset (); }
424 /* Return a type that is a generic pointer type, the size of which
425 matches the address size given in the compilation unit header for
427 struct type
*addr_type () const;
429 /* Find an integer type the same size as the address size given in
430 the compilation unit header for this CU. UNSIGNED_P controls if
431 the integer is unsigned or not. */
432 struct type
*addr_sized_int_type (bool unsigned_p
) const;
434 /* The header of the compilation unit. */
435 struct comp_unit_head header
{};
437 /* Base address of this compilation unit. */
438 gdb::optional
<CORE_ADDR
> base_address
;
440 /* The language we are debugging. */
441 enum language language
= language_unknown
;
442 const struct language_defn
*language_defn
= nullptr;
444 const char *producer
= nullptr;
447 /* The symtab builder for this CU. This is only non-NULL when full
448 symbols are being read. */
449 std::unique_ptr
<buildsym_compunit
> m_builder
;
452 /* The generic symbol table building routines have separate lists for
453 file scope symbols and all all other scopes (local scopes). So
454 we need to select the right one to pass to add_symbol_to_list().
455 We do it by keeping a pointer to the correct list in list_in_scope.
457 FIXME: The original dwarf code just treated the file scope as the
458 first local scope, and all other local scopes as nested local
459 scopes, and worked fine. Check to see if we really need to
460 distinguish these in buildsym.c. */
461 struct pending
**list_in_scope
= nullptr;
463 /* Hash table holding all the loaded partial DIEs
464 with partial_die->offset.SECT_OFF as hash. */
465 htab_t partial_dies
= nullptr;
467 /* Storage for things with the same lifetime as this read-in compilation
468 unit, including partial DIEs. */
469 auto_obstack comp_unit_obstack
;
471 /* When multiple dwarf2_cu structures are living in memory, this field
472 chains them all together, so that they can be released efficiently.
473 We will probably also want a generation counter so that most-recently-used
474 compilation units are cached... */
475 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
477 /* Backlink to our per_cu entry. */
478 struct dwarf2_per_cu_data
*per_cu
;
480 /* The dwarf2_per_objfile that owns this. */
481 struct dwarf2_per_objfile
*per_objfile
;
483 /* How many compilation units ago was this CU last referenced? */
486 /* A hash table of DIE cu_offset for following references with
487 die_info->offset.sect_off as hash. */
488 htab_t die_hash
= nullptr;
490 /* Full DIEs if read in. */
491 struct die_info
*dies
= nullptr;
493 /* A set of pointers to dwarf2_per_cu_data objects for compilation
494 units referenced by this one. Only set during full symbol processing;
495 partial symbol tables do not have dependencies. */
496 htab_t dependencies
= nullptr;
498 /* Header data from the line table, during full symbol processing. */
499 struct line_header
*line_header
= nullptr;
500 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
501 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
502 this is the DW_TAG_compile_unit die for this CU. We'll hold on
503 to the line header as long as this DIE is being processed. See
504 process_die_scope. */
505 die_info
*line_header_die_owner
= nullptr;
507 /* A list of methods which need to have physnames computed
508 after all type information has been read. */
509 std::vector
<delayed_method_info
> method_list
;
511 /* To be copied to symtab->call_site_htab. */
512 htab_t call_site_htab
= nullptr;
514 /* Non-NULL if this CU came from a DWO file.
515 There is an invariant here that is important to remember:
516 Except for attributes copied from the top level DIE in the "main"
517 (or "stub") file in preparation for reading the DWO file
518 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
519 Either there isn't a DWO file (in which case this is NULL and the point
520 is moot), or there is and either we're not going to read it (in which
521 case this is NULL) or there is and we are reading it (in which case this
523 struct dwo_unit
*dwo_unit
= nullptr;
525 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
526 Note this value comes from the Fission stub CU/TU's DIE. */
527 gdb::optional
<ULONGEST
> addr_base
;
529 /* The DW_AT_rnglists_base attribute if present.
530 Note this value comes from the Fission stub CU/TU's DIE.
531 Also note that the value is zero in the non-DWO case so this value can
532 be used without needing to know whether DWO files are in use or not.
533 N.B. This does not apply to DW_AT_ranges appearing in
534 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
535 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
536 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
537 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
538 ULONGEST ranges_base
= 0;
540 /* The DW_AT_loclists_base attribute if present. */
541 ULONGEST loclist_base
= 0;
543 /* When reading debug info generated by older versions of rustc, we
544 have to rewrite some union types to be struct types with a
545 variant part. This rewriting must be done after the CU is fully
546 read in, because otherwise at the point of rewriting some struct
547 type might not have been fully processed. So, we keep a list of
548 all such types here and process them after expansion. */
549 std::vector
<struct type
*> rust_unions
;
551 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
552 files, the value is implicitly zero. For DWARF 5 version DWO files, the
553 value is often implicit and is the size of the header of
554 .debug_str_offsets section (8 or 4, depending on the address size). */
555 gdb::optional
<ULONGEST
> str_offsets_base
;
557 /* Mark used when releasing cached dies. */
560 /* This CU references .debug_loc. See the symtab->locations_valid field.
561 This test is imperfect as there may exist optimized debug code not using
562 any location list and still facing inlining issues if handled as
563 unoptimized code. For a future better test see GCC PR other/32998. */
564 bool has_loclist
: 1;
566 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
567 if all the producer_is_* fields are valid. This information is cached
568 because profiling CU expansion showed excessive time spent in
569 producer_is_gxx_lt_4_6. */
570 bool checked_producer
: 1;
571 bool producer_is_gxx_lt_4_6
: 1;
572 bool producer_is_gcc_lt_4_3
: 1;
573 bool producer_is_icc
: 1;
574 bool producer_is_icc_lt_14
: 1;
575 bool producer_is_codewarrior
: 1;
577 /* When true, the file that we're processing is known to have
578 debugging info for C++ namespaces. GCC 3.3.x did not produce
579 this information, but later versions do. */
581 bool processing_has_namespace_info
: 1;
583 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
585 /* If this CU was inherited by another CU (via specification,
586 abstract_origin, etc), this is the ancestor CU. */
589 /* Get the buildsym_compunit for this CU. */
590 buildsym_compunit
*get_builder ()
592 /* If this CU has a builder associated with it, use that. */
593 if (m_builder
!= nullptr)
594 return m_builder
.get ();
596 /* Otherwise, search ancestors for a valid builder. */
597 if (ancestor
!= nullptr)
598 return ancestor
->get_builder ();
604 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
605 This includes type_unit_group and quick_file_names. */
607 struct stmt_list_hash
609 /* The DWO unit this table is from or NULL if there is none. */
610 struct dwo_unit
*dwo_unit
;
612 /* Offset in .debug_line or .debug_line.dwo. */
613 sect_offset line_sect_off
;
616 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
617 an object of this type. This contains elements of type unit groups
618 that can be shared across objfiles. The non-shareable parts are in
619 type_unit_group_unshareable. */
621 struct type_unit_group
623 /* dwarf2read.c's main "handle" on a TU symtab.
624 To simplify things we create an artificial CU that "includes" all the
625 type units using this stmt_list so that the rest of the code still has
626 a "per_cu" handle on the symtab. */
627 struct dwarf2_per_cu_data per_cu
;
629 /* The TUs that share this DW_AT_stmt_list entry.
630 This is added to while parsing type units to build partial symtabs,
631 and is deleted afterwards and not used again. */
632 std::vector
<signatured_type
*> *tus
;
634 /* The data used to construct the hash key. */
635 struct stmt_list_hash hash
;
638 /* These sections are what may appear in a (real or virtual) DWO file. */
642 struct dwarf2_section_info abbrev
;
643 struct dwarf2_section_info line
;
644 struct dwarf2_section_info loc
;
645 struct dwarf2_section_info loclists
;
646 struct dwarf2_section_info macinfo
;
647 struct dwarf2_section_info macro
;
648 struct dwarf2_section_info str
;
649 struct dwarf2_section_info str_offsets
;
650 /* In the case of a virtual DWO file, these two are unused. */
651 struct dwarf2_section_info info
;
652 std::vector
<dwarf2_section_info
> types
;
655 /* CUs/TUs in DWP/DWO files. */
659 /* Backlink to the containing struct dwo_file. */
660 struct dwo_file
*dwo_file
;
662 /* The "id" that distinguishes this CU/TU.
663 .debug_info calls this "dwo_id", .debug_types calls this "signature".
664 Since signatures came first, we stick with it for consistency. */
667 /* The section this CU/TU lives in, in the DWO file. */
668 struct dwarf2_section_info
*section
;
670 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
671 sect_offset sect_off
;
674 /* For types, offset in the type's DIE of the type defined by this TU. */
675 cu_offset type_offset_in_tu
;
678 /* include/dwarf2.h defines the DWP section codes.
679 It defines a max value but it doesn't define a min value, which we
680 use for error checking, so provide one. */
682 enum dwp_v2_section_ids
687 /* Data for one DWO file.
689 This includes virtual DWO files (a virtual DWO file is a DWO file as it
690 appears in a DWP file). DWP files don't really have DWO files per se -
691 comdat folding of types "loses" the DWO file they came from, and from
692 a high level view DWP files appear to contain a mass of random types.
693 However, to maintain consistency with the non-DWP case we pretend DWP
694 files contain virtual DWO files, and we assign each TU with one virtual
695 DWO file (generally based on the line and abbrev section offsets -
696 a heuristic that seems to work in practice). */
700 dwo_file () = default;
701 DISABLE_COPY_AND_ASSIGN (dwo_file
);
703 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
704 For virtual DWO files the name is constructed from the section offsets
705 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
706 from related CU+TUs. */
707 const char *dwo_name
= nullptr;
709 /* The DW_AT_comp_dir attribute. */
710 const char *comp_dir
= nullptr;
712 /* The bfd, when the file is open. Otherwise this is NULL.
713 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
714 gdb_bfd_ref_ptr dbfd
;
716 /* The sections that make up this DWO file.
717 Remember that for virtual DWO files in DWP V2, these are virtual
718 sections (for lack of a better name). */
719 struct dwo_sections sections
{};
721 /* The CUs in the file.
722 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
723 an extension to handle LLVM's Link Time Optimization output (where
724 multiple source files may be compiled into a single object/dwo pair). */
727 /* Table of TUs in the file.
728 Each element is a struct dwo_unit. */
732 /* These sections are what may appear in a DWP file. */
736 /* These are used by both DWP version 1 and 2. */
737 struct dwarf2_section_info str
;
738 struct dwarf2_section_info cu_index
;
739 struct dwarf2_section_info tu_index
;
741 /* These are only used by DWP version 2 files.
742 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
743 sections are referenced by section number, and are not recorded here.
744 In DWP version 2 there is at most one copy of all these sections, each
745 section being (effectively) comprised of the concatenation of all of the
746 individual sections that exist in the version 1 format.
747 To keep the code simple we treat each of these concatenated pieces as a
748 section itself (a virtual section?). */
749 struct dwarf2_section_info abbrev
;
750 struct dwarf2_section_info info
;
751 struct dwarf2_section_info line
;
752 struct dwarf2_section_info loc
;
753 struct dwarf2_section_info macinfo
;
754 struct dwarf2_section_info macro
;
755 struct dwarf2_section_info str_offsets
;
756 struct dwarf2_section_info types
;
759 /* These sections are what may appear in a virtual DWO file in DWP version 1.
760 A virtual DWO file is a DWO file as it appears in a DWP file. */
762 struct virtual_v1_dwo_sections
764 struct dwarf2_section_info abbrev
;
765 struct dwarf2_section_info line
;
766 struct dwarf2_section_info loc
;
767 struct dwarf2_section_info macinfo
;
768 struct dwarf2_section_info macro
;
769 struct dwarf2_section_info str_offsets
;
770 /* Each DWP hash table entry records one CU or one TU.
771 That is recorded here, and copied to dwo_unit.section. */
772 struct dwarf2_section_info info_or_types
;
775 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
776 In version 2, the sections of the DWO files are concatenated together
777 and stored in one section of that name. Thus each ELF section contains
778 several "virtual" sections. */
780 struct virtual_v2_dwo_sections
782 bfd_size_type abbrev_offset
;
783 bfd_size_type abbrev_size
;
785 bfd_size_type line_offset
;
786 bfd_size_type line_size
;
788 bfd_size_type loc_offset
;
789 bfd_size_type loc_size
;
791 bfd_size_type macinfo_offset
;
792 bfd_size_type macinfo_size
;
794 bfd_size_type macro_offset
;
795 bfd_size_type macro_size
;
797 bfd_size_type str_offsets_offset
;
798 bfd_size_type str_offsets_size
;
800 /* Each DWP hash table entry records one CU or one TU.
801 That is recorded here, and copied to dwo_unit.section. */
802 bfd_size_type info_or_types_offset
;
803 bfd_size_type info_or_types_size
;
806 /* Contents of DWP hash tables. */
808 struct dwp_hash_table
810 uint32_t version
, nr_columns
;
811 uint32_t nr_units
, nr_slots
;
812 const gdb_byte
*hash_table
, *unit_table
;
817 const gdb_byte
*indices
;
821 /* This is indexed by column number and gives the id of the section
823 #define MAX_NR_V2_DWO_SECTIONS \
824 (1 /* .debug_info or .debug_types */ \
825 + 1 /* .debug_abbrev */ \
826 + 1 /* .debug_line */ \
827 + 1 /* .debug_loc */ \
828 + 1 /* .debug_str_offsets */ \
829 + 1 /* .debug_macro or .debug_macinfo */)
830 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
831 const gdb_byte
*offsets
;
832 const gdb_byte
*sizes
;
837 /* Data for one DWP file. */
841 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
843 dbfd (std::move (abfd
))
847 /* Name of the file. */
850 /* File format version. */
854 gdb_bfd_ref_ptr dbfd
;
856 /* Section info for this file. */
857 struct dwp_sections sections
{};
859 /* Table of CUs in the file. */
860 const struct dwp_hash_table
*cus
= nullptr;
862 /* Table of TUs in the file. */
863 const struct dwp_hash_table
*tus
= nullptr;
865 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
869 /* Table to map ELF section numbers to their sections.
870 This is only needed for the DWP V1 file format. */
871 unsigned int num_sections
= 0;
872 asection
**elf_sections
= nullptr;
875 /* Struct used to pass misc. parameters to read_die_and_children, et
876 al. which are used for both .debug_info and .debug_types dies.
877 All parameters here are unchanging for the life of the call. This
878 struct exists to abstract away the constant parameters of die reading. */
880 struct die_reader_specs
882 /* The bfd of die_section. */
885 /* The CU of the DIE we are parsing. */
886 struct dwarf2_cu
*cu
;
888 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
889 struct dwo_file
*dwo_file
;
891 /* The section the die comes from.
892 This is either .debug_info or .debug_types, or the .dwo variants. */
893 struct dwarf2_section_info
*die_section
;
895 /* die_section->buffer. */
896 const gdb_byte
*buffer
;
898 /* The end of the buffer. */
899 const gdb_byte
*buffer_end
;
901 /* The abbreviation table to use when reading the DIEs. */
902 struct abbrev_table
*abbrev_table
;
905 /* A subclass of die_reader_specs that holds storage and has complex
906 constructor and destructor behavior. */
908 class cutu_reader
: public die_reader_specs
912 cutu_reader (dwarf2_per_cu_data
*this_cu
,
913 dwarf2_per_objfile
*per_objfile
,
914 struct abbrev_table
*abbrev_table
,
918 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
919 dwarf2_per_objfile
*per_objfile
,
920 struct dwarf2_cu
*parent_cu
= nullptr,
921 struct dwo_file
*dwo_file
= nullptr);
923 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
925 const gdb_byte
*info_ptr
= nullptr;
926 struct die_info
*comp_unit_die
= nullptr;
927 bool dummy_p
= false;
929 /* Release the new CU, putting it on the chain. This cannot be done
934 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
935 dwarf2_per_objfile
*per_objfile
,
936 int use_existing_cu
);
938 struct dwarf2_per_cu_data
*m_this_cu
;
939 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
941 /* The ordinary abbreviation table. */
942 abbrev_table_up m_abbrev_table_holder
;
944 /* The DWO abbreviation table. */
945 abbrev_table_up m_dwo_abbrev_table
;
948 /* When we construct a partial symbol table entry we only
949 need this much information. */
950 struct partial_die_info
: public allocate_on_obstack
952 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
954 /* Disable assign but still keep copy ctor, which is needed
955 load_partial_dies. */
956 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
958 /* Adjust the partial die before generating a symbol for it. This
959 function may set the is_external flag or change the DIE's
961 void fixup (struct dwarf2_cu
*cu
);
963 /* Read a minimal amount of information into the minimal die
965 const gdb_byte
*read (const struct die_reader_specs
*reader
,
966 const struct abbrev_info
&abbrev
,
967 const gdb_byte
*info_ptr
);
969 /* Offset of this DIE. */
970 const sect_offset sect_off
;
972 /* DWARF-2 tag for this DIE. */
973 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
975 /* Assorted flags describing the data found in this DIE. */
976 const unsigned int has_children
: 1;
978 unsigned int is_external
: 1;
979 unsigned int is_declaration
: 1;
980 unsigned int has_type
: 1;
981 unsigned int has_specification
: 1;
982 unsigned int has_pc_info
: 1;
983 unsigned int may_be_inlined
: 1;
985 /* This DIE has been marked DW_AT_main_subprogram. */
986 unsigned int main_subprogram
: 1;
988 /* Flag set if the SCOPE field of this structure has been
990 unsigned int scope_set
: 1;
992 /* Flag set if the DIE has a byte_size attribute. */
993 unsigned int has_byte_size
: 1;
995 /* Flag set if the DIE has a DW_AT_const_value attribute. */
996 unsigned int has_const_value
: 1;
998 /* Flag set if any of the DIE's children are template arguments. */
999 unsigned int has_template_arguments
: 1;
1001 /* Flag set if fixup has been called on this die. */
1002 unsigned int fixup_called
: 1;
1004 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1005 unsigned int is_dwz
: 1;
1007 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1008 unsigned int spec_is_dwz
: 1;
1010 /* The name of this DIE. Normally the value of DW_AT_name, but
1011 sometimes a default name for unnamed DIEs. */
1012 const char *name
= nullptr;
1014 /* The linkage name, if present. */
1015 const char *linkage_name
= nullptr;
1017 /* The scope to prepend to our children. This is generally
1018 allocated on the comp_unit_obstack, so will disappear
1019 when this compilation unit leaves the cache. */
1020 const char *scope
= nullptr;
1022 /* Some data associated with the partial DIE. The tag determines
1023 which field is live. */
1026 /* The location description associated with this DIE, if any. */
1027 struct dwarf_block
*locdesc
;
1028 /* The offset of an import, for DW_TAG_imported_unit. */
1029 sect_offset sect_off
;
1032 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1033 CORE_ADDR lowpc
= 0;
1034 CORE_ADDR highpc
= 0;
1036 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1037 DW_AT_sibling, if any. */
1038 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1039 could return DW_AT_sibling values to its caller load_partial_dies. */
1040 const gdb_byte
*sibling
= nullptr;
1042 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1043 DW_AT_specification (or DW_AT_abstract_origin or
1044 DW_AT_extension). */
1045 sect_offset spec_offset
{};
1047 /* Pointers to this DIE's parent, first child, and next sibling,
1049 struct partial_die_info
*die_parent
= nullptr;
1050 struct partial_die_info
*die_child
= nullptr;
1051 struct partial_die_info
*die_sibling
= nullptr;
1053 friend struct partial_die_info
*
1054 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1057 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1058 partial_die_info (sect_offset sect_off
)
1059 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1063 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1065 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1070 has_specification
= 0;
1073 main_subprogram
= 0;
1076 has_const_value
= 0;
1077 has_template_arguments
= 0;
1084 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1085 but this would require a corresponding change in unpack_field_as_long
1087 static int bits_per_byte
= 8;
1089 struct variant_part_builder
;
1091 /* When reading a variant, we track a bit more information about the
1092 field, and store it in an object of this type. */
1094 struct variant_field
1096 int first_field
= -1;
1097 int last_field
= -1;
1099 /* A variant can contain other variant parts. */
1100 std::vector
<variant_part_builder
> variant_parts
;
1102 /* If we see a DW_TAG_variant, then this will be set if this is the
1104 bool default_branch
= false;
1105 /* If we see a DW_AT_discr_value, then this will be the discriminant
1107 ULONGEST discriminant_value
= 0;
1108 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1110 struct dwarf_block
*discr_list_data
= nullptr;
1113 /* This represents a DW_TAG_variant_part. */
1115 struct variant_part_builder
1117 /* The offset of the discriminant field. */
1118 sect_offset discriminant_offset
{};
1120 /* Variants that are direct children of this variant part. */
1121 std::vector
<variant_field
> variants
;
1123 /* True if we're currently reading a variant. */
1124 bool processing_variant
= false;
1129 int accessibility
= 0;
1131 /* Variant parts need to find the discriminant, which is a DIE
1132 reference. We track the section offset of each field to make
1135 struct field field
{};
1140 const char *name
= nullptr;
1141 std::vector
<struct fn_field
> fnfields
;
1144 /* The routines that read and process dies for a C struct or C++ class
1145 pass lists of data member fields and lists of member function fields
1146 in an instance of a field_info structure, as defined below. */
1149 /* List of data member and baseclasses fields. */
1150 std::vector
<struct nextfield
> fields
;
1151 std::vector
<struct nextfield
> baseclasses
;
1153 /* Set if the accessibility of one of the fields is not public. */
1154 int non_public_fields
= 0;
1156 /* Member function fieldlist array, contains name of possibly overloaded
1157 member function, number of overloaded member functions and a pointer
1158 to the head of the member function field chain. */
1159 std::vector
<struct fnfieldlist
> fnfieldlists
;
1161 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1162 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1163 std::vector
<struct decl_field
> typedef_field_list
;
1165 /* Nested types defined by this class and the number of elements in this
1167 std::vector
<struct decl_field
> nested_types_list
;
1169 /* If non-null, this is the variant part we are currently
1171 variant_part_builder
*current_variant_part
= nullptr;
1172 /* This holds all the top-level variant parts attached to the type
1174 std::vector
<variant_part_builder
> variant_parts
;
1176 /* Return the total number of fields (including baseclasses). */
1177 int nfields () const
1179 return fields
.size () + baseclasses
.size ();
1183 /* Loaded secondary compilation units are kept in memory until they
1184 have not been referenced for the processing of this many
1185 compilation units. Set this to zero to disable caching. Cache
1186 sizes of up to at least twenty will improve startup time for
1187 typical inter-CU-reference binaries, at an obvious memory cost. */
1188 static int dwarf_max_cache_age
= 5;
1190 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1191 struct cmd_list_element
*c
, const char *value
)
1193 fprintf_filtered (file
, _("The upper bound on the age of cached "
1194 "DWARF compilation units is %s.\n"),
1198 /* local function prototypes */
1200 static void dwarf2_find_base_address (struct die_info
*die
,
1201 struct dwarf2_cu
*cu
);
1203 static dwarf2_psymtab
*create_partial_symtab
1204 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1207 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1208 const gdb_byte
*info_ptr
,
1209 struct die_info
*type_unit_die
);
1211 static void dwarf2_build_psymtabs_hard
1212 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1214 static void scan_partial_symbols (struct partial_die_info
*,
1215 CORE_ADDR
*, CORE_ADDR
*,
1216 int, struct dwarf2_cu
*);
1218 static void add_partial_symbol (struct partial_die_info
*,
1219 struct dwarf2_cu
*);
1221 static void add_partial_namespace (struct partial_die_info
*pdi
,
1222 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1223 int set_addrmap
, struct dwarf2_cu
*cu
);
1225 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1226 CORE_ADDR
*highpc
, int set_addrmap
,
1227 struct dwarf2_cu
*cu
);
1229 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1230 struct dwarf2_cu
*cu
);
1232 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1233 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1234 int need_pc
, struct dwarf2_cu
*cu
);
1236 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1238 static struct partial_die_info
*load_partial_dies
1239 (const struct die_reader_specs
*, const gdb_byte
*, int);
1241 /* A pair of partial_die_info and compilation unit. */
1242 struct cu_partial_die_info
1244 /* The compilation unit of the partial_die_info. */
1245 struct dwarf2_cu
*cu
;
1246 /* A partial_die_info. */
1247 struct partial_die_info
*pdi
;
1249 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1255 cu_partial_die_info () = delete;
1258 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1259 struct dwarf2_cu
*);
1261 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1262 struct attribute
*, struct attr_abbrev
*,
1263 const gdb_byte
*, bool *need_reprocess
);
1265 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1266 struct attribute
*attr
);
1268 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1270 static sect_offset read_abbrev_offset
1271 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1272 struct dwarf2_section_info
*, sect_offset
);
1274 static const char *read_indirect_string
1275 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1276 const struct comp_unit_head
*, unsigned int *);
1278 static const char *read_indirect_string_at_offset
1279 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1281 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1285 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1286 ULONGEST str_index
);
1288 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1289 ULONGEST str_index
);
1291 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1293 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1294 struct dwarf2_cu
*);
1296 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1297 struct dwarf2_cu
*cu
);
1299 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1301 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1302 struct dwarf2_cu
*cu
);
1304 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1306 static struct die_info
*die_specification (struct die_info
*die
,
1307 struct dwarf2_cu
**);
1309 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1310 struct dwarf2_cu
*cu
);
1312 static void dwarf_decode_lines (struct line_header
*, const char *,
1313 struct dwarf2_cu
*, dwarf2_psymtab
*,
1314 CORE_ADDR
, int decode_mapping
);
1316 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1319 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1320 struct dwarf2_cu
*, struct symbol
* = NULL
);
1322 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1323 struct dwarf2_cu
*);
1325 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1328 struct obstack
*obstack
,
1329 struct dwarf2_cu
*cu
, LONGEST
*value
,
1330 const gdb_byte
**bytes
,
1331 struct dwarf2_locexpr_baton
**baton
);
1333 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1335 static int need_gnat_info (struct dwarf2_cu
*);
1337 static struct type
*die_descriptive_type (struct die_info
*,
1338 struct dwarf2_cu
*);
1340 static void set_descriptive_type (struct type
*, struct die_info
*,
1341 struct dwarf2_cu
*);
1343 static struct type
*die_containing_type (struct die_info
*,
1344 struct dwarf2_cu
*);
1346 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1347 struct dwarf2_cu
*);
1349 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1351 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1353 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1355 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1356 const char *suffix
, int physname
,
1357 struct dwarf2_cu
*cu
);
1359 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1361 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1363 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1365 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1367 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1369 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1371 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1372 struct dwarf2_cu
*, dwarf2_psymtab
*);
1374 /* Return the .debug_loclists section to use for cu. */
1375 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1377 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1378 values. Keep the items ordered with increasing constraints compliance. */
1381 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1382 PC_BOUNDS_NOT_PRESENT
,
1384 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1385 were present but they do not form a valid range of PC addresses. */
1388 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1391 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1395 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1396 CORE_ADDR
*, CORE_ADDR
*,
1400 static void get_scope_pc_bounds (struct die_info
*,
1401 CORE_ADDR
*, CORE_ADDR
*,
1402 struct dwarf2_cu
*);
1404 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1405 CORE_ADDR
, struct dwarf2_cu
*);
1407 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1408 struct dwarf2_cu
*);
1410 static void dwarf2_attach_fields_to_type (struct field_info
*,
1411 struct type
*, struct dwarf2_cu
*);
1413 static void dwarf2_add_member_fn (struct field_info
*,
1414 struct die_info
*, struct type
*,
1415 struct dwarf2_cu
*);
1417 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1419 struct dwarf2_cu
*);
1421 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1423 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1425 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1427 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1429 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1431 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1433 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1435 static struct type
*read_module_type (struct die_info
*die
,
1436 struct dwarf2_cu
*cu
);
1438 static const char *namespace_name (struct die_info
*die
,
1439 int *is_anonymous
, struct dwarf2_cu
*);
1441 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1443 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1446 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1447 struct dwarf2_cu
*);
1449 static struct die_info
*read_die_and_siblings_1
1450 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1453 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1454 const gdb_byte
*info_ptr
,
1455 const gdb_byte
**new_info_ptr
,
1456 struct die_info
*parent
);
1458 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1459 struct die_info
**, const gdb_byte
*,
1462 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1463 struct die_info
**, const gdb_byte
*);
1465 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1467 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1470 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1472 static const char *dwarf2_full_name (const char *name
,
1473 struct die_info
*die
,
1474 struct dwarf2_cu
*cu
);
1476 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1477 struct dwarf2_cu
*cu
);
1479 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1480 struct dwarf2_cu
**);
1482 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1484 static void dump_die_for_error (struct die_info
*);
1486 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1489 /*static*/ void dump_die (struct die_info
*, int max_level
);
1491 static void store_in_ref_table (struct die_info
*,
1492 struct dwarf2_cu
*);
1494 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1495 const struct attribute
*,
1496 struct dwarf2_cu
**);
1498 static struct die_info
*follow_die_ref (struct die_info
*,
1499 const struct attribute
*,
1500 struct dwarf2_cu
**);
1502 static struct die_info
*follow_die_sig (struct die_info
*,
1503 const struct attribute
*,
1504 struct dwarf2_cu
**);
1506 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1507 struct dwarf2_cu
*);
1509 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1510 const struct attribute
*,
1511 struct dwarf2_cu
*);
1513 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1514 dwarf2_per_objfile
*per_objfile
);
1516 static void read_signatured_type (signatured_type
*sig_type
,
1517 dwarf2_per_objfile
*per_objfile
);
1519 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1520 struct die_info
*die
, struct dwarf2_cu
*cu
,
1521 struct dynamic_prop
*prop
, struct type
*type
);
1523 /* memory allocation interface */
1525 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1527 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1529 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1531 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1532 struct dwarf2_loclist_baton
*baton
,
1533 const struct attribute
*attr
);
1535 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1537 struct dwarf2_cu
*cu
,
1540 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1541 const gdb_byte
*info_ptr
,
1542 struct abbrev_info
*abbrev
);
1544 static hashval_t
partial_die_hash (const void *item
);
1546 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1548 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1549 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1550 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1552 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1553 struct die_info
*comp_unit_die
,
1554 enum language pretend_language
);
1556 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1558 static void free_one_cached_comp_unit (dwarf2_per_cu_data
*target_per_cu
,
1559 dwarf2_per_objfile
*per_objfile
);
1561 static struct type
*set_die_type (struct die_info
*, struct type
*,
1562 struct dwarf2_cu
*);
1564 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1566 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1568 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1569 dwarf2_per_objfile
*per_objfile
,
1571 enum language pretend_language
);
1573 static void process_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1574 dwarf2_per_objfile
*per_objfile
,
1575 enum language pretend_language
);
1577 static void process_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1578 dwarf2_per_objfile
*per_objfile
,
1579 enum language pretend_language
);
1581 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1582 struct dwarf2_per_cu_data
*);
1584 static void dwarf2_mark (struct dwarf2_cu
*);
1586 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1588 static struct type
*get_die_type_at_offset (sect_offset
,
1589 dwarf2_per_cu_data
*per_cu
,
1590 dwarf2_per_objfile
*per_objfile
);
1592 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1594 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1595 dwarf2_per_objfile
*per_objfile
,
1596 enum language pretend_language
);
1598 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1600 /* Class, the destructor of which frees all allocated queue entries. This
1601 will only have work to do if an error was thrown while processing the
1602 dwarf. If no error was thrown then the queue entries should have all
1603 been processed, and freed, as we went along. */
1605 class dwarf2_queue_guard
1608 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1609 : m_per_objfile (per_objfile
)
1613 /* Free any entries remaining on the queue. There should only be
1614 entries left if we hit an error while processing the dwarf. */
1615 ~dwarf2_queue_guard ()
1617 /* Ensure that no memory is allocated by the queue. */
1618 std::queue
<dwarf2_queue_item
> empty
;
1619 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1622 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1625 dwarf2_per_objfile
*m_per_objfile
;
1628 dwarf2_queue_item::~dwarf2_queue_item ()
1630 /* Anything still marked queued is likely to be in an
1631 inconsistent state, so discard it. */
1634 if (per_cu
->cu
!= NULL
)
1635 free_one_cached_comp_unit (per_cu
, per_objfile
);
1640 /* The return type of find_file_and_directory. Note, the enclosed
1641 string pointers are only valid while this object is valid. */
1643 struct file_and_directory
1645 /* The filename. This is never NULL. */
1648 /* The compilation directory. NULL if not known. If we needed to
1649 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1650 points directly to the DW_AT_comp_dir string attribute owned by
1651 the obstack that owns the DIE. */
1652 const char *comp_dir
;
1654 /* If we needed to build a new string for comp_dir, this is what
1655 owns the storage. */
1656 std::string comp_dir_storage
;
1659 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1660 struct dwarf2_cu
*cu
);
1662 static htab_up
allocate_signatured_type_table ();
1664 static htab_up
allocate_dwo_unit_table ();
1666 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1667 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1668 struct dwp_file
*dwp_file
, const char *comp_dir
,
1669 ULONGEST signature
, int is_debug_types
);
1671 static struct dwp_file
*get_dwp_file
1672 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1674 static struct dwo_unit
*lookup_dwo_comp_unit
1675 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1676 ULONGEST signature
);
1678 static struct dwo_unit
*lookup_dwo_type_unit
1679 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1681 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1683 /* A unique pointer to a dwo_file. */
1685 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1687 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1689 static void check_producer (struct dwarf2_cu
*cu
);
1691 static void free_line_header_voidp (void *arg
);
1693 /* Various complaints about symbol reading that don't abort the process. */
1696 dwarf2_debug_line_missing_file_complaint (void)
1698 complaint (_(".debug_line section has line data without a file"));
1702 dwarf2_debug_line_missing_end_sequence_complaint (void)
1704 complaint (_(".debug_line section has line "
1705 "program sequence without an end"));
1709 dwarf2_complex_location_expr_complaint (void)
1711 complaint (_("location expression too complex"));
1715 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1718 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1723 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1725 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1729 /* Hash function for line_header_hash. */
1732 line_header_hash (const struct line_header
*ofs
)
1734 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1737 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1740 line_header_hash_voidp (const void *item
)
1742 const struct line_header
*ofs
= (const struct line_header
*) item
;
1744 return line_header_hash (ofs
);
1747 /* Equality function for line_header_hash. */
1750 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1752 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1753 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1755 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1756 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1761 /* See declaration. */
1763 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1766 can_copy (can_copy_
)
1769 names
= &dwarf2_elf_names
;
1771 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1772 locate_sections (obfd
, sec
, *names
);
1775 dwarf2_per_bfd::~dwarf2_per_bfd ()
1777 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1778 free_cached_comp_units ();
1780 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1781 per_cu
->imported_symtabs_free ();
1783 for (signatured_type
*sig_type
: all_type_units
)
1784 sig_type
->per_cu
.imported_symtabs_free ();
1786 /* Everything else should be on this->obstack. */
1789 /* See declaration. */
1792 dwarf2_per_bfd::free_cached_comp_units ()
1794 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1795 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1796 while (per_cu
!= NULL
)
1798 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1801 *last_chain
= next_cu
;
1806 /* A helper class that calls free_cached_comp_units on
1809 class free_cached_comp_units
1813 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1814 : m_per_objfile (per_objfile
)
1818 ~free_cached_comp_units ()
1820 m_per_objfile
->per_bfd
->free_cached_comp_units ();
1823 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1827 dwarf2_per_objfile
*m_per_objfile
;
1833 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1835 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1837 return this->m_symtabs
[per_cu
->index
] != nullptr;
1843 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1845 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1847 return this->m_symtabs
[per_cu
->index
];
1853 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1854 compunit_symtab
*symtab
)
1856 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1857 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1859 this->m_symtabs
[per_cu
->index
] = symtab
;
1862 /* Try to locate the sections we need for DWARF 2 debugging
1863 information and return true if we have enough to do something.
1864 NAMES points to the dwarf2 section names, or is NULL if the standard
1865 ELF names are used. CAN_COPY is true for formats where symbol
1866 interposition is possible and so symbol values must follow copy
1867 relocation rules. */
1870 dwarf2_has_info (struct objfile
*objfile
,
1871 const struct dwarf2_debug_sections
*names
,
1874 if (objfile
->flags
& OBJF_READNEVER
)
1877 struct dwarf2_per_objfile
*dwarf2_per_objfile
1878 = get_dwarf2_per_objfile (objfile
);
1880 if (dwarf2_per_objfile
== NULL
)
1882 /* For now, each dwarf2_per_objfile owns its own dwarf2_per_bfd (no
1884 dwarf2_per_bfd
*per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1886 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1889 return (!dwarf2_per_objfile
->per_bfd
->info
.is_virtual
1890 && dwarf2_per_objfile
->per_bfd
->info
.s
.section
!= NULL
1891 && !dwarf2_per_objfile
->per_bfd
->abbrev
.is_virtual
1892 && dwarf2_per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1895 /* When loading sections, we look either for uncompressed section or for
1896 compressed section names. */
1899 section_is_p (const char *section_name
,
1900 const struct dwarf2_section_names
*names
)
1902 if (names
->normal
!= NULL
1903 && strcmp (section_name
, names
->normal
) == 0)
1905 if (names
->compressed
!= NULL
1906 && strcmp (section_name
, names
->compressed
) == 0)
1911 /* See declaration. */
1914 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1915 const dwarf2_debug_sections
&names
)
1917 flagword aflag
= bfd_section_flags (sectp
);
1919 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1922 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1923 > bfd_get_file_size (abfd
))
1925 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1926 warning (_("Discarding section %s which has a section size (%s"
1927 ") larger than the file size [in module %s]"),
1928 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1929 bfd_get_filename (abfd
));
1931 else if (section_is_p (sectp
->name
, &names
.info
))
1933 this->info
.s
.section
= sectp
;
1934 this->info
.size
= bfd_section_size (sectp
);
1936 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1938 this->abbrev
.s
.section
= sectp
;
1939 this->abbrev
.size
= bfd_section_size (sectp
);
1941 else if (section_is_p (sectp
->name
, &names
.line
))
1943 this->line
.s
.section
= sectp
;
1944 this->line
.size
= bfd_section_size (sectp
);
1946 else if (section_is_p (sectp
->name
, &names
.loc
))
1948 this->loc
.s
.section
= sectp
;
1949 this->loc
.size
= bfd_section_size (sectp
);
1951 else if (section_is_p (sectp
->name
, &names
.loclists
))
1953 this->loclists
.s
.section
= sectp
;
1954 this->loclists
.size
= bfd_section_size (sectp
);
1956 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1958 this->macinfo
.s
.section
= sectp
;
1959 this->macinfo
.size
= bfd_section_size (sectp
);
1961 else if (section_is_p (sectp
->name
, &names
.macro
))
1963 this->macro
.s
.section
= sectp
;
1964 this->macro
.size
= bfd_section_size (sectp
);
1966 else if (section_is_p (sectp
->name
, &names
.str
))
1968 this->str
.s
.section
= sectp
;
1969 this->str
.size
= bfd_section_size (sectp
);
1971 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1973 this->str_offsets
.s
.section
= sectp
;
1974 this->str_offsets
.size
= bfd_section_size (sectp
);
1976 else if (section_is_p (sectp
->name
, &names
.line_str
))
1978 this->line_str
.s
.section
= sectp
;
1979 this->line_str
.size
= bfd_section_size (sectp
);
1981 else if (section_is_p (sectp
->name
, &names
.addr
))
1983 this->addr
.s
.section
= sectp
;
1984 this->addr
.size
= bfd_section_size (sectp
);
1986 else if (section_is_p (sectp
->name
, &names
.frame
))
1988 this->frame
.s
.section
= sectp
;
1989 this->frame
.size
= bfd_section_size (sectp
);
1991 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1993 this->eh_frame
.s
.section
= sectp
;
1994 this->eh_frame
.size
= bfd_section_size (sectp
);
1996 else if (section_is_p (sectp
->name
, &names
.ranges
))
1998 this->ranges
.s
.section
= sectp
;
1999 this->ranges
.size
= bfd_section_size (sectp
);
2001 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2003 this->rnglists
.s
.section
= sectp
;
2004 this->rnglists
.size
= bfd_section_size (sectp
);
2006 else if (section_is_p (sectp
->name
, &names
.types
))
2008 struct dwarf2_section_info type_section
;
2010 memset (&type_section
, 0, sizeof (type_section
));
2011 type_section
.s
.section
= sectp
;
2012 type_section
.size
= bfd_section_size (sectp
);
2014 this->types
.push_back (type_section
);
2016 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2018 this->gdb_index
.s
.section
= sectp
;
2019 this->gdb_index
.size
= bfd_section_size (sectp
);
2021 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2023 this->debug_names
.s
.section
= sectp
;
2024 this->debug_names
.size
= bfd_section_size (sectp
);
2026 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2028 this->debug_aranges
.s
.section
= sectp
;
2029 this->debug_aranges
.size
= bfd_section_size (sectp
);
2032 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2033 && bfd_section_vma (sectp
) == 0)
2034 this->has_section_at_zero
= true;
2037 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2041 dwarf2_get_section_info (struct objfile
*objfile
,
2042 enum dwarf2_section_enum sect
,
2043 asection
**sectp
, const gdb_byte
**bufp
,
2044 bfd_size_type
*sizep
)
2046 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2047 struct dwarf2_section_info
*info
;
2049 /* We may see an objfile without any DWARF, in which case we just
2060 case DWARF2_DEBUG_FRAME
:
2061 info
= &data
->per_bfd
->frame
;
2063 case DWARF2_EH_FRAME
:
2064 info
= &data
->per_bfd
->eh_frame
;
2067 gdb_assert_not_reached ("unexpected section");
2070 info
->read (objfile
);
2072 *sectp
= info
->get_bfd_section ();
2073 *bufp
= info
->buffer
;
2074 *sizep
= info
->size
;
2077 /* A helper function to find the sections for a .dwz file. */
2080 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2082 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2084 /* Note that we only support the standard ELF names, because .dwz
2085 is ELF-only (at the time of writing). */
2086 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2088 dwz_file
->abbrev
.s
.section
= sectp
;
2089 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2091 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2093 dwz_file
->info
.s
.section
= sectp
;
2094 dwz_file
->info
.size
= bfd_section_size (sectp
);
2096 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2098 dwz_file
->str
.s
.section
= sectp
;
2099 dwz_file
->str
.size
= bfd_section_size (sectp
);
2101 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2103 dwz_file
->line
.s
.section
= sectp
;
2104 dwz_file
->line
.size
= bfd_section_size (sectp
);
2106 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2108 dwz_file
->macro
.s
.section
= sectp
;
2109 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2111 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2113 dwz_file
->gdb_index
.s
.section
= sectp
;
2114 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2116 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2118 dwz_file
->debug_names
.s
.section
= sectp
;
2119 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2123 /* See dwarf2read.h. */
2126 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2128 const char *filename
;
2129 bfd_size_type buildid_len_arg
;
2133 if (per_bfd
->dwz_file
!= NULL
)
2134 return per_bfd
->dwz_file
.get ();
2136 bfd_set_error (bfd_error_no_error
);
2137 gdb::unique_xmalloc_ptr
<char> data
2138 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2139 &buildid_len_arg
, &buildid
));
2142 if (bfd_get_error () == bfd_error_no_error
)
2144 error (_("could not read '.gnu_debugaltlink' section: %s"),
2145 bfd_errmsg (bfd_get_error ()));
2148 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2150 buildid_len
= (size_t) buildid_len_arg
;
2152 filename
= data
.get ();
2154 std::string abs_storage
;
2155 if (!IS_ABSOLUTE_PATH (filename
))
2157 gdb::unique_xmalloc_ptr
<char> abs
2158 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2160 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2161 filename
= abs_storage
.c_str ();
2164 /* First try the file name given in the section. If that doesn't
2165 work, try to use the build-id instead. */
2166 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2167 if (dwz_bfd
!= NULL
)
2169 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2170 dwz_bfd
.reset (nullptr);
2173 if (dwz_bfd
== NULL
)
2174 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2176 if (dwz_bfd
== nullptr)
2178 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2179 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2181 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2188 /* File successfully retrieved from server. */
2189 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2191 if (dwz_bfd
== nullptr)
2192 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2193 alt_filename
.get ());
2194 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2195 dwz_bfd
.reset (nullptr);
2199 if (dwz_bfd
== NULL
)
2200 error (_("could not find '.gnu_debugaltlink' file for %s"),
2201 bfd_get_filename (per_bfd
->obfd
));
2203 std::unique_ptr
<struct dwz_file
> result
2204 (new struct dwz_file (std::move (dwz_bfd
)));
2206 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2209 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2210 per_bfd
->dwz_file
= std::move (result
);
2211 return per_bfd
->dwz_file
.get ();
2214 /* DWARF quick_symbols_functions support. */
2216 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2217 unique line tables, so we maintain a separate table of all .debug_line
2218 derived entries to support the sharing.
2219 All the quick functions need is the list of file names. We discard the
2220 line_header when we're done and don't need to record it here. */
2221 struct quick_file_names
2223 /* The data used to construct the hash key. */
2224 struct stmt_list_hash hash
;
2226 /* The number of entries in file_names, real_names. */
2227 unsigned int num_file_names
;
2229 /* The file names from the line table, after being run through
2231 const char **file_names
;
2233 /* The file names from the line table after being run through
2234 gdb_realpath. These are computed lazily. */
2235 const char **real_names
;
2238 /* When using the index (and thus not using psymtabs), each CU has an
2239 object of this type. This is used to hold information needed by
2240 the various "quick" methods. */
2241 struct dwarf2_per_cu_quick_data
2243 /* The file table. This can be NULL if there was no file table
2244 or it's currently not read in.
2245 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2246 struct quick_file_names
*file_names
;
2248 /* A temporary mark bit used when iterating over all CUs in
2249 expand_symtabs_matching. */
2250 unsigned int mark
: 1;
2252 /* True if we've tried to read the file table and found there isn't one.
2253 There will be no point in trying to read it again next time. */
2254 unsigned int no_file_data
: 1;
2257 /* Utility hash function for a stmt_list_hash. */
2260 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2264 if (stmt_list_hash
->dwo_unit
!= NULL
)
2265 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2266 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2270 /* Utility equality function for a stmt_list_hash. */
2273 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2274 const struct stmt_list_hash
*rhs
)
2276 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2278 if (lhs
->dwo_unit
!= NULL
2279 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2282 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2285 /* Hash function for a quick_file_names. */
2288 hash_file_name_entry (const void *e
)
2290 const struct quick_file_names
*file_data
2291 = (const struct quick_file_names
*) e
;
2293 return hash_stmt_list_entry (&file_data
->hash
);
2296 /* Equality function for a quick_file_names. */
2299 eq_file_name_entry (const void *a
, const void *b
)
2301 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2302 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2304 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2307 /* Delete function for a quick_file_names. */
2310 delete_file_name_entry (void *e
)
2312 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2315 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2317 xfree ((void*) file_data
->file_names
[i
]);
2318 if (file_data
->real_names
)
2319 xfree ((void*) file_data
->real_names
[i
]);
2322 /* The space for the struct itself lives on the obstack, so we don't
2326 /* Create a quick_file_names hash table. */
2329 create_quick_file_names_table (unsigned int nr_initial_entries
)
2331 return htab_up (htab_create_alloc (nr_initial_entries
,
2332 hash_file_name_entry
, eq_file_name_entry
,
2333 delete_file_name_entry
, xcalloc
, xfree
));
2336 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2337 function is unrelated to symtabs, symtab would have to be created afterwards.
2338 You should call age_cached_comp_units after processing the CU. */
2341 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2344 if (per_cu
->is_debug_types
)
2345 load_full_type_unit (per_cu
, per_objfile
);
2347 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2349 if (per_cu
->cu
== NULL
)
2350 return; /* Dummy CU. */
2352 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2355 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2358 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2359 dwarf2_per_objfile
*dwarf2_per_objfile
,
2362 /* Skip type_unit_groups, reading the type units they contain
2363 is handled elsewhere. */
2364 if (per_cu
->type_unit_group_p ())
2367 /* The destructor of dwarf2_queue_guard frees any entries left on
2368 the queue. After this point we're guaranteed to leave this function
2369 with the dwarf queue empty. */
2370 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2372 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2374 queue_comp_unit (per_cu
, dwarf2_per_objfile
, language_minimal
);
2375 load_cu (per_cu
, dwarf2_per_objfile
, skip_partial
);
2377 /* If we just loaded a CU from a DWO, and we're working with an index
2378 that may badly handle TUs, load all the TUs in that DWO as well.
2379 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2380 if (!per_cu
->is_debug_types
2381 && per_cu
->cu
!= NULL
2382 && per_cu
->cu
->dwo_unit
!= NULL
2383 && dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
2384 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7
2385 /* DWP files aren't supported yet. */
2386 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2387 queue_and_load_all_dwo_tus (per_cu
);
2390 process_queue (dwarf2_per_objfile
);
2392 /* Age the cache, releasing compilation units that have not
2393 been used recently. */
2394 age_cached_comp_units (dwarf2_per_objfile
);
2397 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2398 the per-objfile for which this symtab is instantiated.
2400 Returns the resulting symbol table. */
2402 static struct compunit_symtab
*
2403 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2404 dwarf2_per_objfile
*dwarf2_per_objfile
,
2407 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
2409 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2411 free_cached_comp_units
freer (dwarf2_per_objfile
);
2412 scoped_restore decrementer
= increment_reading_symtab ();
2413 dw2_do_instantiate_symtab (per_cu
, dwarf2_per_objfile
, skip_partial
);
2414 process_cu_includes (dwarf2_per_objfile
);
2417 return dwarf2_per_objfile
->get_symtab (per_cu
);
2420 /* See declaration. */
2422 dwarf2_per_cu_data
*
2423 dwarf2_per_bfd::get_cutu (int index
)
2425 if (index
>= this->all_comp_units
.size ())
2427 index
-= this->all_comp_units
.size ();
2428 gdb_assert (index
< this->all_type_units
.size ());
2429 return &this->all_type_units
[index
]->per_cu
;
2432 return this->all_comp_units
[index
];
2435 /* See declaration. */
2437 dwarf2_per_cu_data
*
2438 dwarf2_per_bfd::get_cu (int index
)
2440 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2442 return this->all_comp_units
[index
];
2445 /* See declaration. */
2448 dwarf2_per_bfd::get_tu (int index
)
2450 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2452 return this->all_type_units
[index
];
2457 dwarf2_per_cu_data
*
2458 dwarf2_per_bfd::allocate_per_cu ()
2460 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2461 result
->per_bfd
= this;
2462 result
->index
= m_num_psymtabs
++;
2469 dwarf2_per_bfd::allocate_signatured_type ()
2471 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2472 result
->per_cu
.per_bfd
= this;
2473 result
->per_cu
.index
= m_num_psymtabs
++;
2477 /* Return a new dwarf2_per_cu_data allocated on the dwarf2_per_objfile
2478 obstack, and constructed with the specified field values. */
2480 static dwarf2_per_cu_data
*
2481 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2482 struct dwarf2_section_info
*section
,
2484 sect_offset sect_off
, ULONGEST length
)
2486 dwarf2_per_cu_data
*the_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
2487 the_cu
->sect_off
= sect_off
;
2488 the_cu
->length
= length
;
2489 the_cu
->section
= section
;
2490 the_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2491 struct dwarf2_per_cu_quick_data
);
2492 the_cu
->is_dwz
= is_dwz
;
2496 /* A helper for create_cus_from_index that handles a given list of
2500 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2501 const gdb_byte
*cu_list
, offset_type n_elements
,
2502 struct dwarf2_section_info
*section
,
2505 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2507 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2509 sect_offset sect_off
2510 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2511 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2514 dwarf2_per_cu_data
*per_cu
2515 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2517 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
2521 /* Read the CU list from the mapped index, and use it to create all
2522 the CU objects for this objfile. */
2525 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2526 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2527 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2529 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
2530 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve
2531 ((cu_list_elements
+ dwz_elements
) / 2);
2533 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2534 &dwarf2_per_objfile
->per_bfd
->info
, 0);
2536 if (dwz_elements
== 0)
2539 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
2540 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2544 /* Create the signatured type hash table from the index. */
2547 create_signatured_type_table_from_index
2548 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2549 struct dwarf2_section_info
*section
,
2550 const gdb_byte
*bytes
,
2551 offset_type elements
)
2553 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2554 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (elements
/ 3);
2556 htab_up sig_types_hash
= allocate_signatured_type_table ();
2558 for (offset_type i
= 0; i
< elements
; i
+= 3)
2560 struct signatured_type
*sig_type
;
2563 cu_offset type_offset_in_tu
;
2565 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2566 sect_offset sect_off
2567 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2569 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2571 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2574 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2575 sig_type
->signature
= signature
;
2576 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2577 sig_type
->per_cu
.is_debug_types
= 1;
2578 sig_type
->per_cu
.section
= section
;
2579 sig_type
->per_cu
.sect_off
= sect_off
;
2580 sig_type
->per_cu
.v
.quick
2581 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2582 struct dwarf2_per_cu_quick_data
);
2584 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2587 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2590 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2593 /* Create the signatured type hash table from .debug_names. */
2596 create_signatured_type_table_from_debug_names
2597 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2598 const mapped_debug_names
&map
,
2599 struct dwarf2_section_info
*section
,
2600 struct dwarf2_section_info
*abbrev_section
)
2602 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2604 section
->read (objfile
);
2605 abbrev_section
->read (objfile
);
2607 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2608 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2610 htab_up sig_types_hash
= allocate_signatured_type_table ();
2612 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2614 struct signatured_type
*sig_type
;
2617 sect_offset sect_off
2618 = (sect_offset
) (extract_unsigned_integer
2619 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2621 map
.dwarf5_byte_order
));
2623 comp_unit_head cu_header
;
2624 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2626 section
->buffer
+ to_underlying (sect_off
),
2629 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2630 sig_type
->signature
= cu_header
.signature
;
2631 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2632 sig_type
->per_cu
.is_debug_types
= 1;
2633 sig_type
->per_cu
.section
= section
;
2634 sig_type
->per_cu
.sect_off
= sect_off
;
2635 sig_type
->per_cu
.v
.quick
2636 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2637 struct dwarf2_per_cu_quick_data
);
2639 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2642 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2645 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2648 /* Read the address map data from the mapped index, and use it to
2649 populate the objfile's psymtabs_addrmap. */
2652 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2653 struct mapped_index
*index
)
2655 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2656 struct gdbarch
*gdbarch
= objfile
->arch ();
2657 const gdb_byte
*iter
, *end
;
2658 struct addrmap
*mutable_map
;
2661 auto_obstack temp_obstack
;
2663 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2665 iter
= index
->address_table
.data ();
2666 end
= iter
+ index
->address_table
.size ();
2668 baseaddr
= objfile
->text_section_offset ();
2672 ULONGEST hi
, lo
, cu_index
;
2673 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2675 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2677 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2682 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2683 hex_string (lo
), hex_string (hi
));
2687 if (cu_index
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
2689 complaint (_(".gdb_index address table has invalid CU number %u"),
2690 (unsigned) cu_index
);
2694 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2695 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2696 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2697 dwarf2_per_objfile
->per_bfd
->get_cu (cu_index
));
2700 objfile
->partial_symtabs
->psymtabs_addrmap
2701 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2704 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2705 populate the objfile's psymtabs_addrmap. */
2708 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2709 struct dwarf2_section_info
*section
)
2711 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2712 bfd
*abfd
= objfile
->obfd
;
2713 struct gdbarch
*gdbarch
= objfile
->arch ();
2714 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2716 auto_obstack temp_obstack
;
2717 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2719 std::unordered_map
<sect_offset
,
2720 dwarf2_per_cu_data
*,
2721 gdb::hash_enum
<sect_offset
>>
2722 debug_info_offset_to_per_cu
;
2723 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
2725 const auto insertpair
2726 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2727 if (!insertpair
.second
)
2729 warning (_("Section .debug_aranges in %s has duplicate "
2730 "debug_info_offset %s, ignoring .debug_aranges."),
2731 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2736 section
->read (objfile
);
2738 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2740 const gdb_byte
*addr
= section
->buffer
;
2742 while (addr
< section
->buffer
+ section
->size
)
2744 const gdb_byte
*const entry_addr
= addr
;
2745 unsigned int bytes_read
;
2747 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2751 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2752 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2753 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2754 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2756 warning (_("Section .debug_aranges in %s entry at offset %s "
2757 "length %s exceeds section length %s, "
2758 "ignoring .debug_aranges."),
2759 objfile_name (objfile
),
2760 plongest (entry_addr
- section
->buffer
),
2761 plongest (bytes_read
+ entry_length
),
2762 pulongest (section
->size
));
2766 /* The version number. */
2767 const uint16_t version
= read_2_bytes (abfd
, addr
);
2771 warning (_("Section .debug_aranges in %s entry at offset %s "
2772 "has unsupported version %d, ignoring .debug_aranges."),
2773 objfile_name (objfile
),
2774 plongest (entry_addr
- section
->buffer
), version
);
2778 const uint64_t debug_info_offset
2779 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2780 addr
+= offset_size
;
2781 const auto per_cu_it
2782 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2783 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2785 warning (_("Section .debug_aranges in %s entry at offset %s "
2786 "debug_info_offset %s does not exists, "
2787 "ignoring .debug_aranges."),
2788 objfile_name (objfile
),
2789 plongest (entry_addr
- section
->buffer
),
2790 pulongest (debug_info_offset
));
2793 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2795 const uint8_t address_size
= *addr
++;
2796 if (address_size
< 1 || address_size
> 8)
2798 warning (_("Section .debug_aranges in %s entry at offset %s "
2799 "address_size %u is invalid, ignoring .debug_aranges."),
2800 objfile_name (objfile
),
2801 plongest (entry_addr
- section
->buffer
), address_size
);
2805 const uint8_t segment_selector_size
= *addr
++;
2806 if (segment_selector_size
!= 0)
2808 warning (_("Section .debug_aranges in %s entry at offset %s "
2809 "segment_selector_size %u is not supported, "
2810 "ignoring .debug_aranges."),
2811 objfile_name (objfile
),
2812 plongest (entry_addr
- section
->buffer
),
2813 segment_selector_size
);
2817 /* Must pad to an alignment boundary that is twice the address
2818 size. It is undocumented by the DWARF standard but GCC does
2820 for (size_t padding
= ((-(addr
- section
->buffer
))
2821 & (2 * address_size
- 1));
2822 padding
> 0; padding
--)
2825 warning (_("Section .debug_aranges in %s entry at offset %s "
2826 "padding is not zero, ignoring .debug_aranges."),
2827 objfile_name (objfile
),
2828 plongest (entry_addr
- section
->buffer
));
2834 if (addr
+ 2 * address_size
> entry_end
)
2836 warning (_("Section .debug_aranges in %s entry at offset %s "
2837 "address list is not properly terminated, "
2838 "ignoring .debug_aranges."),
2839 objfile_name (objfile
),
2840 plongest (entry_addr
- section
->buffer
));
2843 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2845 addr
+= address_size
;
2846 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2848 addr
+= address_size
;
2849 if (start
== 0 && length
== 0)
2851 if (start
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
2853 /* Symbol was eliminated due to a COMDAT group. */
2856 ULONGEST end
= start
+ length
;
2857 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2859 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2861 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2865 objfile
->partial_symtabs
->psymtabs_addrmap
2866 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2869 /* Find a slot in the mapped index INDEX for the object named NAME.
2870 If NAME is found, set *VEC_OUT to point to the CU vector in the
2871 constant pool and return true. If NAME cannot be found, return
2875 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2876 offset_type
**vec_out
)
2879 offset_type slot
, step
;
2880 int (*cmp
) (const char *, const char *);
2882 gdb::unique_xmalloc_ptr
<char> without_params
;
2883 if (current_language
->la_language
== language_cplus
2884 || current_language
->la_language
== language_fortran
2885 || current_language
->la_language
== language_d
)
2887 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2890 if (strchr (name
, '(') != NULL
)
2892 without_params
= cp_remove_params (name
);
2894 if (without_params
!= NULL
)
2895 name
= without_params
.get ();
2899 /* Index version 4 did not support case insensitive searches. But the
2900 indices for case insensitive languages are built in lowercase, therefore
2901 simulate our NAME being searched is also lowercased. */
2902 hash
= mapped_index_string_hash ((index
->version
== 4
2903 && case_sensitivity
== case_sensitive_off
2904 ? 5 : index
->version
),
2907 slot
= hash
& (index
->symbol_table
.size () - 1);
2908 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2909 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2915 const auto &bucket
= index
->symbol_table
[slot
];
2916 if (bucket
.name
== 0 && bucket
.vec
== 0)
2919 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2920 if (!cmp (name
, str
))
2922 *vec_out
= (offset_type
*) (index
->constant_pool
2923 + MAYBE_SWAP (bucket
.vec
));
2927 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2931 /* A helper function that reads the .gdb_index from BUFFER and fills
2932 in MAP. FILENAME is the name of the file containing the data;
2933 it is used for error reporting. DEPRECATED_OK is true if it is
2934 ok to use deprecated sections.
2936 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2937 out parameters that are filled in with information about the CU and
2938 TU lists in the section.
2940 Returns true if all went well, false otherwise. */
2943 read_gdb_index_from_buffer (const char *filename
,
2945 gdb::array_view
<const gdb_byte
> buffer
,
2946 struct mapped_index
*map
,
2947 const gdb_byte
**cu_list
,
2948 offset_type
*cu_list_elements
,
2949 const gdb_byte
**types_list
,
2950 offset_type
*types_list_elements
)
2952 const gdb_byte
*addr
= &buffer
[0];
2954 /* Version check. */
2955 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2956 /* Versions earlier than 3 emitted every copy of a psymbol. This
2957 causes the index to behave very poorly for certain requests. Version 3
2958 contained incomplete addrmap. So, it seems better to just ignore such
2962 static int warning_printed
= 0;
2963 if (!warning_printed
)
2965 warning (_("Skipping obsolete .gdb_index section in %s."),
2967 warning_printed
= 1;
2971 /* Index version 4 uses a different hash function than index version
2974 Versions earlier than 6 did not emit psymbols for inlined
2975 functions. Using these files will cause GDB not to be able to
2976 set breakpoints on inlined functions by name, so we ignore these
2977 indices unless the user has done
2978 "set use-deprecated-index-sections on". */
2979 if (version
< 6 && !deprecated_ok
)
2981 static int warning_printed
= 0;
2982 if (!warning_printed
)
2985 Skipping deprecated .gdb_index section in %s.\n\
2986 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2987 to use the section anyway."),
2989 warning_printed
= 1;
2993 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2994 of the TU (for symbols coming from TUs),
2995 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2996 Plus gold-generated indices can have duplicate entries for global symbols,
2997 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2998 These are just performance bugs, and we can't distinguish gdb-generated
2999 indices from gold-generated ones, so issue no warning here. */
3001 /* Indexes with higher version than the one supported by GDB may be no
3002 longer backward compatible. */
3006 map
->version
= version
;
3008 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3011 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3012 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3016 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3017 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3018 - MAYBE_SWAP (metadata
[i
]))
3022 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3023 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3025 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3028 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3029 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3031 = gdb::array_view
<mapped_index::symbol_table_slot
>
3032 ((mapped_index::symbol_table_slot
*) symbol_table
,
3033 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3036 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3041 /* Callback types for dwarf2_read_gdb_index. */
3043 typedef gdb::function_view
3044 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3045 get_gdb_index_contents_ftype
;
3046 typedef gdb::function_view
3047 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3048 get_gdb_index_contents_dwz_ftype
;
3050 /* Read .gdb_index. If everything went ok, initialize the "quick"
3051 elements of all the CUs and return 1. Otherwise, return 0. */
3054 dwarf2_read_gdb_index
3055 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3056 get_gdb_index_contents_ftype get_gdb_index_contents
,
3057 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3059 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3060 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3061 struct dwz_file
*dwz
;
3062 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3064 gdb::array_view
<const gdb_byte
> main_index_contents
3065 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
->per_bfd
);
3067 if (main_index_contents
.empty ())
3070 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3071 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3072 use_deprecated_index_sections
,
3073 main_index_contents
, map
.get (), &cu_list
,
3074 &cu_list_elements
, &types_list
,
3075 &types_list_elements
))
3078 /* Don't use the index if it's empty. */
3079 if (map
->symbol_table
.empty ())
3082 /* If there is a .dwz file, read it so we can get its CU list as
3084 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
3087 struct mapped_index dwz_map
;
3088 const gdb_byte
*dwz_types_ignore
;
3089 offset_type dwz_types_elements_ignore
;
3091 gdb::array_view
<const gdb_byte
> dwz_index_content
3092 = get_gdb_index_contents_dwz (objfile
, dwz
);
3094 if (dwz_index_content
.empty ())
3097 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3098 1, dwz_index_content
, &dwz_map
,
3099 &dwz_list
, &dwz_list_elements
,
3101 &dwz_types_elements_ignore
))
3103 warning (_("could not read '.gdb_index' section from %s; skipping"),
3104 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3109 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3110 dwz_list
, dwz_list_elements
);
3112 if (types_list_elements
)
3114 /* We can only handle a single .debug_types when we have an
3116 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
3119 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
3121 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3122 types_list
, types_list_elements
);
3125 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3127 dwarf2_per_objfile
->per_bfd
->index_table
= std::move (map
);
3128 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
3129 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
3130 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
3135 /* die_reader_func for dw2_get_file_names. */
3138 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3139 const gdb_byte
*info_ptr
,
3140 struct die_info
*comp_unit_die
)
3142 struct dwarf2_cu
*cu
= reader
->cu
;
3143 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3144 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
3145 struct dwarf2_per_cu_data
*lh_cu
;
3146 struct attribute
*attr
;
3148 struct quick_file_names
*qfn
;
3150 gdb_assert (! this_cu
->is_debug_types
);
3152 /* Our callers never want to match partial units -- instead they
3153 will match the enclosing full CU. */
3154 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3156 this_cu
->v
.quick
->no_file_data
= 1;
3164 sect_offset line_offset
{};
3166 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3167 if (attr
!= nullptr)
3169 struct quick_file_names find_entry
;
3171 line_offset
= (sect_offset
) DW_UNSND (attr
);
3173 /* We may have already read in this line header (TU line header sharing).
3174 If we have we're done. */
3175 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3176 find_entry
.hash
.line_sect_off
= line_offset
;
3177 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3178 &find_entry
, INSERT
);
3181 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3185 lh
= dwarf_decode_line_header (line_offset
, cu
);
3189 lh_cu
->v
.quick
->no_file_data
= 1;
3193 qfn
= XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3194 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3195 qfn
->hash
.line_sect_off
= line_offset
;
3196 gdb_assert (slot
!= NULL
);
3199 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3202 if (strcmp (fnd
.name
, "<unknown>") != 0)
3205 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3207 XOBNEWVEC (&dwarf2_per_objfile
->per_bfd
->obstack
, const char *,
3208 qfn
->num_file_names
);
3210 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3211 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3212 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3213 fnd
.comp_dir
).release ();
3214 qfn
->real_names
= NULL
;
3216 lh_cu
->v
.quick
->file_names
= qfn
;
3219 /* A helper for the "quick" functions which attempts to read the line
3220 table for THIS_CU. */
3222 static struct quick_file_names
*
3223 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3224 dwarf2_per_objfile
*per_objfile
)
3226 /* This should never be called for TUs. */
3227 gdb_assert (! this_cu
->is_debug_types
);
3228 /* Nor type unit groups. */
3229 gdb_assert (! this_cu
->type_unit_group_p ());
3231 if (this_cu
->v
.quick
->file_names
!= NULL
)
3232 return this_cu
->v
.quick
->file_names
;
3233 /* If we know there is no line data, no point in looking again. */
3234 if (this_cu
->v
.quick
->no_file_data
)
3237 cutu_reader
reader (this_cu
, per_objfile
);
3238 if (!reader
.dummy_p
)
3239 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3241 if (this_cu
->v
.quick
->no_file_data
)
3243 return this_cu
->v
.quick
->file_names
;
3246 /* A helper for the "quick" functions which computes and caches the
3247 real path for a given file name from the line table. */
3250 dw2_get_real_path (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3251 struct quick_file_names
*qfn
, int index
)
3253 if (qfn
->real_names
== NULL
)
3254 qfn
->real_names
= OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
3255 qfn
->num_file_names
, const char *);
3257 if (qfn
->real_names
[index
] == NULL
)
3258 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3260 return qfn
->real_names
[index
];
3263 static struct symtab
*
3264 dw2_find_last_source_symtab (struct objfile
*objfile
)
3266 struct dwarf2_per_objfile
*dwarf2_per_objfile
3267 = get_dwarf2_per_objfile (objfile
);
3268 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->per_bfd
->all_comp_units
.back ();
3269 compunit_symtab
*cust
3270 = dw2_instantiate_symtab (dwarf_cu
, dwarf2_per_objfile
, false);
3275 return compunit_primary_filetab (cust
);
3278 /* Traversal function for dw2_forget_cached_source_info. */
3281 dw2_free_cached_file_names (void **slot
, void *info
)
3283 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3285 if (file_data
->real_names
)
3289 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3291 xfree ((void*) file_data
->real_names
[i
]);
3292 file_data
->real_names
[i
] = NULL
;
3300 dw2_forget_cached_source_info (struct objfile
*objfile
)
3302 struct dwarf2_per_objfile
*dwarf2_per_objfile
3303 = get_dwarf2_per_objfile (objfile
);
3305 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3306 dw2_free_cached_file_names
, NULL
);
3309 /* Helper function for dw2_map_symtabs_matching_filename that expands
3310 the symtabs and calls the iterator. */
3313 dw2_map_expand_apply (struct objfile
*objfile
,
3314 struct dwarf2_per_cu_data
*per_cu
,
3315 const char *name
, const char *real_path
,
3316 gdb::function_view
<bool (symtab
*)> callback
)
3318 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3320 /* Don't visit already-expanded CUs. */
3321 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3322 if (per_objfile
->symtab_set_p (per_cu
))
3325 /* This may expand more than one symtab, and we want to iterate over
3327 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3329 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3330 last_made
, callback
);
3333 /* Implementation of the map_symtabs_matching_filename method. */
3336 dw2_map_symtabs_matching_filename
3337 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3338 gdb::function_view
<bool (symtab
*)> callback
)
3340 const char *name_basename
= lbasename (name
);
3341 struct dwarf2_per_objfile
*dwarf2_per_objfile
3342 = get_dwarf2_per_objfile (objfile
);
3344 /* The rule is CUs specify all the files, including those used by
3345 any TU, so there's no need to scan TUs here. */
3347 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3349 /* We only need to look at symtabs not already expanded. */
3350 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3353 quick_file_names
*file_data
3354 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3355 if (file_data
== NULL
)
3358 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3360 const char *this_name
= file_data
->file_names
[j
];
3361 const char *this_real_name
;
3363 if (compare_filenames_for_search (this_name
, name
))
3365 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3371 /* Before we invoke realpath, which can get expensive when many
3372 files are involved, do a quick comparison of the basenames. */
3373 if (! basenames_may_differ
3374 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3377 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
3379 if (compare_filenames_for_search (this_real_name
, name
))
3381 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3387 if (real_path
!= NULL
)
3389 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3390 gdb_assert (IS_ABSOLUTE_PATH (name
));
3391 if (this_real_name
!= NULL
3392 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3394 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3406 /* Struct used to manage iterating over all CUs looking for a symbol. */
3408 struct dw2_symtab_iterator
3410 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3411 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3412 /* If set, only look for symbols that match that block. Valid values are
3413 GLOBAL_BLOCK and STATIC_BLOCK. */
3414 gdb::optional
<block_enum
> block_index
;
3415 /* The kind of symbol we're looking for. */
3417 /* The list of CUs from the index entry of the symbol,
3418 or NULL if not found. */
3420 /* The next element in VEC to look at. */
3422 /* The number of elements in VEC, or zero if there is no match. */
3424 /* Have we seen a global version of the symbol?
3425 If so we can ignore all further global instances.
3426 This is to work around gold/15646, inefficient gold-generated
3431 /* Initialize the index symtab iterator ITER. */
3434 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3435 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3436 gdb::optional
<block_enum
> block_index
,
3440 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3441 iter
->block_index
= block_index
;
3442 iter
->domain
= domain
;
3444 iter
->global_seen
= 0;
3446 mapped_index
*index
= dwarf2_per_objfile
->per_bfd
->index_table
.get ();
3448 /* index is NULL if OBJF_READNOW. */
3449 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3450 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3458 /* Return the next matching CU or NULL if there are no more. */
3460 static struct dwarf2_per_cu_data
*
3461 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3463 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3465 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3467 offset_type cu_index_and_attrs
=
3468 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3469 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3470 gdb_index_symbol_kind symbol_kind
=
3471 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3472 /* Only check the symbol attributes if they're present.
3473 Indices prior to version 7 don't record them,
3474 and indices >= 7 may elide them for certain symbols
3475 (gold does this). */
3477 (dwarf2_per_objfile
->per_bfd
->index_table
->version
>= 7
3478 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3480 /* Don't crash on bad data. */
3481 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3482 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
3484 complaint (_(".gdb_index entry has bad CU index"
3486 objfile_name (dwarf2_per_objfile
->objfile
));
3490 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
3492 /* Skip if already read in. */
3493 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3496 /* Check static vs global. */
3499 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3501 if (iter
->block_index
.has_value ())
3503 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3505 if (is_static
!= want_static
)
3509 /* Work around gold/15646. */
3510 if (!is_static
&& iter
->global_seen
)
3513 iter
->global_seen
= 1;
3516 /* Only check the symbol's kind if it has one. */
3519 switch (iter
->domain
)
3522 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3523 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3524 /* Some types are also in VAR_DOMAIN. */
3525 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3529 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3533 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3537 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3552 static struct compunit_symtab
*
3553 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3554 const char *name
, domain_enum domain
)
3556 struct compunit_symtab
*stab_best
= NULL
;
3557 struct dwarf2_per_objfile
*dwarf2_per_objfile
3558 = get_dwarf2_per_objfile (objfile
);
3560 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3562 struct dw2_symtab_iterator iter
;
3563 struct dwarf2_per_cu_data
*per_cu
;
3565 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3567 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3569 struct symbol
*sym
, *with_opaque
= NULL
;
3570 struct compunit_symtab
*stab
3571 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3572 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3573 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3575 sym
= block_find_symbol (block
, name
, domain
,
3576 block_find_non_opaque_type_preferred
,
3579 /* Some caution must be observed with overloaded functions
3580 and methods, since the index will not contain any overload
3581 information (but NAME might contain it). */
3584 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3586 if (with_opaque
!= NULL
3587 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3590 /* Keep looking through other CUs. */
3597 dw2_print_stats (struct objfile
*objfile
)
3599 struct dwarf2_per_objfile
*dwarf2_per_objfile
3600 = get_dwarf2_per_objfile (objfile
);
3601 int total
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3602 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3605 for (int i
= 0; i
< total
; ++i
)
3607 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3609 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
3612 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3613 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3616 /* This dumps minimal information about the index.
3617 It is called via "mt print objfiles".
3618 One use is to verify .gdb_index has been loaded by the
3619 gdb.dwarf2/gdb-index.exp testcase. */
3622 dw2_dump (struct objfile
*objfile
)
3624 struct dwarf2_per_objfile
*dwarf2_per_objfile
3625 = get_dwarf2_per_objfile (objfile
);
3627 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
3628 printf_filtered (".gdb_index:");
3629 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
)
3631 printf_filtered (" version %d\n",
3632 dwarf2_per_objfile
->per_bfd
->index_table
->version
);
3635 printf_filtered (" faked for \"readnow\"\n");
3636 printf_filtered ("\n");
3640 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3641 const char *func_name
)
3643 struct dwarf2_per_objfile
*dwarf2_per_objfile
3644 = get_dwarf2_per_objfile (objfile
);
3646 struct dw2_symtab_iterator iter
;
3647 struct dwarf2_per_cu_data
*per_cu
;
3649 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3651 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3652 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3657 dw2_expand_all_symtabs (struct objfile
*objfile
)
3659 struct dwarf2_per_objfile
*dwarf2_per_objfile
3660 = get_dwarf2_per_objfile (objfile
);
3661 int total_units
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3662 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3664 for (int i
= 0; i
< total_units
; ++i
)
3666 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3668 /* We don't want to directly expand a partial CU, because if we
3669 read it with the wrong language, then assertion failures can
3670 be triggered later on. See PR symtab/23010. So, tell
3671 dw2_instantiate_symtab to skip partial CUs -- any important
3672 partial CU will be read via DW_TAG_imported_unit anyway. */
3673 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, true);
3678 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3679 const char *fullname
)
3681 struct dwarf2_per_objfile
*dwarf2_per_objfile
3682 = get_dwarf2_per_objfile (objfile
);
3684 /* We don't need to consider type units here.
3685 This is only called for examining code, e.g. expand_line_sal.
3686 There can be an order of magnitude (or more) more type units
3687 than comp units, and we avoid them if we can. */
3689 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3691 /* We only need to look at symtabs not already expanded. */
3692 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3695 quick_file_names
*file_data
3696 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3697 if (file_data
== NULL
)
3700 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3702 const char *this_fullname
= file_data
->file_names
[j
];
3704 if (filename_cmp (this_fullname
, fullname
) == 0)
3706 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3714 dw2_expand_symtabs_matching_symbol
3715 (mapped_index_base
&index
,
3716 const lookup_name_info
&lookup_name_in
,
3717 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3718 enum search_domain kind
,
3719 gdb::function_view
<bool (offset_type
)> match_callback
);
3722 dw2_expand_symtabs_matching_one
3723 (dwarf2_per_cu_data
*per_cu
,
3724 dwarf2_per_objfile
*per_objfile
,
3725 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3726 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3729 dw2_map_matching_symbols
3730 (struct objfile
*objfile
,
3731 const lookup_name_info
&name
, domain_enum domain
,
3733 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3734 symbol_compare_ftype
*ordered_compare
)
3737 struct dwarf2_per_objfile
*dwarf2_per_objfile
3738 = get_dwarf2_per_objfile (objfile
);
3740 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3742 if (dwarf2_per_objfile
->per_bfd
->index_table
!= nullptr)
3744 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3745 here though if the current language is Ada for a non-Ada objfile
3747 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
3749 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3750 auto matcher
= [&] (const char *symname
)
3752 if (ordered_compare
== nullptr)
3754 return ordered_compare (symname
, match_name
) == 0;
3757 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3758 [&] (offset_type namei
)
3760 struct dw2_symtab_iterator iter
;
3761 struct dwarf2_per_cu_data
*per_cu
;
3763 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_kind
, domain
,
3765 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3766 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
3773 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3774 proceed assuming all symtabs have been read in. */
3777 for (compunit_symtab
*cust
: objfile
->compunits ())
3779 const struct block
*block
;
3783 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3784 if (!iterate_over_symbols_terminated (block
, name
,
3790 /* Starting from a search name, return the string that finds the upper
3791 bound of all strings that start with SEARCH_NAME in a sorted name
3792 list. Returns the empty string to indicate that the upper bound is
3793 the end of the list. */
3796 make_sort_after_prefix_name (const char *search_name
)
3798 /* When looking to complete "func", we find the upper bound of all
3799 symbols that start with "func" by looking for where we'd insert
3800 the closest string that would follow "func" in lexicographical
3801 order. Usually, that's "func"-with-last-character-incremented,
3802 i.e. "fund". Mind non-ASCII characters, though. Usually those
3803 will be UTF-8 multi-byte sequences, but we can't be certain.
3804 Especially mind the 0xff character, which is a valid character in
3805 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3806 rule out compilers allowing it in identifiers. Note that
3807 conveniently, strcmp/strcasecmp are specified to compare
3808 characters interpreted as unsigned char. So what we do is treat
3809 the whole string as a base 256 number composed of a sequence of
3810 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3811 to 0, and carries 1 to the following more-significant position.
3812 If the very first character in SEARCH_NAME ends up incremented
3813 and carries/overflows, then the upper bound is the end of the
3814 list. The string after the empty string is also the empty
3817 Some examples of this operation:
3819 SEARCH_NAME => "+1" RESULT
3823 "\xff" "a" "\xff" => "\xff" "b"
3828 Then, with these symbols for example:
3834 completing "func" looks for symbols between "func" and
3835 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3836 which finds "func" and "func1", but not "fund".
3840 funcÿ (Latin1 'ÿ' [0xff])
3844 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3845 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3849 ÿÿ (Latin1 'ÿ' [0xff])
3852 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3853 the end of the list.
3855 std::string after
= search_name
;
3856 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3858 if (!after
.empty ())
3859 after
.back () = (unsigned char) after
.back () + 1;
3863 /* See declaration. */
3865 std::pair
<std::vector
<name_component
>::const_iterator
,
3866 std::vector
<name_component
>::const_iterator
>
3867 mapped_index_base::find_name_components_bounds
3868 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3871 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3873 const char *lang_name
3874 = lookup_name_without_params
.language_lookup_name (lang
);
3876 /* Comparison function object for lower_bound that matches against a
3877 given symbol name. */
3878 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3881 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3882 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3883 return name_cmp (elem_name
, name
) < 0;
3886 /* Comparison function object for upper_bound that matches against a
3887 given symbol name. */
3888 auto lookup_compare_upper
= [&] (const char *name
,
3889 const name_component
&elem
)
3891 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3892 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3893 return name_cmp (name
, elem_name
) < 0;
3896 auto begin
= this->name_components
.begin ();
3897 auto end
= this->name_components
.end ();
3899 /* Find the lower bound. */
3902 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3905 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3908 /* Find the upper bound. */
3911 if (lookup_name_without_params
.completion_mode ())
3913 /* In completion mode, we want UPPER to point past all
3914 symbols names that have the same prefix. I.e., with
3915 these symbols, and completing "func":
3917 function << lower bound
3919 other_function << upper bound
3921 We find the upper bound by looking for the insertion
3922 point of "func"-with-last-character-incremented,
3924 std::string after
= make_sort_after_prefix_name (lang_name
);
3927 return std::lower_bound (lower
, end
, after
.c_str (),
3928 lookup_compare_lower
);
3931 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3934 return {lower
, upper
};
3937 /* See declaration. */
3940 mapped_index_base::build_name_components ()
3942 if (!this->name_components
.empty ())
3945 this->name_components_casing
= case_sensitivity
;
3947 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3949 /* The code below only knows how to break apart components of C++
3950 symbol names (and other languages that use '::' as
3951 namespace/module separator) and Ada symbol names. */
3952 auto count
= this->symbol_name_count ();
3953 for (offset_type idx
= 0; idx
< count
; idx
++)
3955 if (this->symbol_name_slot_invalid (idx
))
3958 const char *name
= this->symbol_name_at (idx
);
3960 /* Add each name component to the name component table. */
3961 unsigned int previous_len
= 0;
3963 if (strstr (name
, "::") != nullptr)
3965 for (unsigned int current_len
= cp_find_first_component (name
);
3966 name
[current_len
] != '\0';
3967 current_len
+= cp_find_first_component (name
+ current_len
))
3969 gdb_assert (name
[current_len
] == ':');
3970 this->name_components
.push_back ({previous_len
, idx
});
3971 /* Skip the '::'. */
3973 previous_len
= current_len
;
3978 /* Handle the Ada encoded (aka mangled) form here. */
3979 for (const char *iter
= strstr (name
, "__");
3981 iter
= strstr (iter
, "__"))
3983 this->name_components
.push_back ({previous_len
, idx
});
3985 previous_len
= iter
- name
;
3989 this->name_components
.push_back ({previous_len
, idx
});
3992 /* Sort name_components elements by name. */
3993 auto name_comp_compare
= [&] (const name_component
&left
,
3994 const name_component
&right
)
3996 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3997 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3999 const char *left_name
= left_qualified
+ left
.name_offset
;
4000 const char *right_name
= right_qualified
+ right
.name_offset
;
4002 return name_cmp (left_name
, right_name
) < 0;
4005 std::sort (this->name_components
.begin (),
4006 this->name_components
.end (),
4010 /* Helper for dw2_expand_symtabs_matching that works with a
4011 mapped_index_base instead of the containing objfile. This is split
4012 to a separate function in order to be able to unit test the
4013 name_components matching using a mock mapped_index_base. For each
4014 symbol name that matches, calls MATCH_CALLBACK, passing it the
4015 symbol's index in the mapped_index_base symbol table. */
4018 dw2_expand_symtabs_matching_symbol
4019 (mapped_index_base
&index
,
4020 const lookup_name_info
&lookup_name_in
,
4021 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4022 enum search_domain kind
,
4023 gdb::function_view
<bool (offset_type
)> match_callback
)
4025 lookup_name_info lookup_name_without_params
4026 = lookup_name_in
.make_ignore_params ();
4028 /* Build the symbol name component sorted vector, if we haven't
4030 index
.build_name_components ();
4032 /* The same symbol may appear more than once in the range though.
4033 E.g., if we're looking for symbols that complete "w", and we have
4034 a symbol named "w1::w2", we'll find the two name components for
4035 that same symbol in the range. To be sure we only call the
4036 callback once per symbol, we first collect the symbol name
4037 indexes that matched in a temporary vector and ignore
4039 std::vector
<offset_type
> matches
;
4041 struct name_and_matcher
4043 symbol_name_matcher_ftype
*matcher
;
4046 bool operator== (const name_and_matcher
&other
) const
4048 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4052 /* A vector holding all the different symbol name matchers, for all
4054 std::vector
<name_and_matcher
> matchers
;
4056 for (int i
= 0; i
< nr_languages
; i
++)
4058 enum language lang_e
= (enum language
) i
;
4060 const language_defn
*lang
= language_def (lang_e
);
4061 symbol_name_matcher_ftype
*name_matcher
4062 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4064 name_and_matcher key
{
4066 lookup_name_without_params
.language_lookup_name (lang_e
)
4069 /* Don't insert the same comparison routine more than once.
4070 Note that we do this linear walk. This is not a problem in
4071 practice because the number of supported languages is
4073 if (std::find (matchers
.begin (), matchers
.end (), key
)
4076 matchers
.push_back (std::move (key
));
4079 = index
.find_name_components_bounds (lookup_name_without_params
,
4082 /* Now for each symbol name in range, check to see if we have a name
4083 match, and if so, call the MATCH_CALLBACK callback. */
4085 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4087 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4089 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4090 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4093 matches
.push_back (bounds
.first
->idx
);
4097 std::sort (matches
.begin (), matches
.end ());
4099 /* Finally call the callback, once per match. */
4101 for (offset_type idx
: matches
)
4105 if (!match_callback (idx
))
4111 /* Above we use a type wider than idx's for 'prev', since 0 and
4112 (offset_type)-1 are both possible values. */
4113 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4118 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4120 /* A mock .gdb_index/.debug_names-like name index table, enough to
4121 exercise dw2_expand_symtabs_matching_symbol, which works with the
4122 mapped_index_base interface. Builds an index from the symbol list
4123 passed as parameter to the constructor. */
4124 class mock_mapped_index
: public mapped_index_base
4127 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4128 : m_symbol_table (symbols
)
4131 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4133 /* Return the number of names in the symbol table. */
4134 size_t symbol_name_count () const override
4136 return m_symbol_table
.size ();
4139 /* Get the name of the symbol at IDX in the symbol table. */
4140 const char *symbol_name_at (offset_type idx
) const override
4142 return m_symbol_table
[idx
];
4146 gdb::array_view
<const char *> m_symbol_table
;
4149 /* Convenience function that converts a NULL pointer to a "<null>"
4150 string, to pass to print routines. */
4153 string_or_null (const char *str
)
4155 return str
!= NULL
? str
: "<null>";
4158 /* Check if a lookup_name_info built from
4159 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4160 index. EXPECTED_LIST is the list of expected matches, in expected
4161 matching order. If no match expected, then an empty list is
4162 specified. Returns true on success. On failure prints a warning
4163 indicating the file:line that failed, and returns false. */
4166 check_match (const char *file
, int line
,
4167 mock_mapped_index
&mock_index
,
4168 const char *name
, symbol_name_match_type match_type
,
4169 bool completion_mode
,
4170 std::initializer_list
<const char *> expected_list
)
4172 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4174 bool matched
= true;
4176 auto mismatch
= [&] (const char *expected_str
,
4179 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4180 "expected=\"%s\", got=\"%s\"\n"),
4182 (match_type
== symbol_name_match_type::FULL
4184 name
, string_or_null (expected_str
), string_or_null (got
));
4188 auto expected_it
= expected_list
.begin ();
4189 auto expected_end
= expected_list
.end ();
4191 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4193 [&] (offset_type idx
)
4195 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4196 const char *expected_str
4197 = expected_it
== expected_end
? NULL
: *expected_it
++;
4199 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4200 mismatch (expected_str
, matched_name
);
4204 const char *expected_str
4205 = expected_it
== expected_end
? NULL
: *expected_it
++;
4206 if (expected_str
!= NULL
)
4207 mismatch (expected_str
, NULL
);
4212 /* The symbols added to the mock mapped_index for testing (in
4214 static const char *test_symbols
[] = {
4223 "ns2::tmpl<int>::foo2",
4224 "(anonymous namespace)::A::B::C",
4226 /* These are used to check that the increment-last-char in the
4227 matching algorithm for completion doesn't match "t1_fund" when
4228 completing "t1_func". */
4234 /* A UTF-8 name with multi-byte sequences to make sure that
4235 cp-name-parser understands this as a single identifier ("função"
4236 is "function" in PT). */
4239 /* \377 (0xff) is Latin1 'ÿ'. */
4242 /* \377 (0xff) is Latin1 'ÿ'. */
4246 /* A name with all sorts of complications. Starts with "z" to make
4247 it easier for the completion tests below. */
4248 #define Z_SYM_NAME \
4249 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4250 "::tuple<(anonymous namespace)::ui*, " \
4251 "std::default_delete<(anonymous namespace)::ui>, void>"
4256 /* Returns true if the mapped_index_base::find_name_component_bounds
4257 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4258 in completion mode. */
4261 check_find_bounds_finds (mapped_index_base
&index
,
4262 const char *search_name
,
4263 gdb::array_view
<const char *> expected_syms
)
4265 lookup_name_info
lookup_name (search_name
,
4266 symbol_name_match_type::FULL
, true);
4268 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4271 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4272 if (distance
!= expected_syms
.size ())
4275 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4277 auto nc_elem
= bounds
.first
+ exp_elem
;
4278 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4279 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4286 /* Test the lower-level mapped_index::find_name_component_bounds
4290 test_mapped_index_find_name_component_bounds ()
4292 mock_mapped_index
mock_index (test_symbols
);
4294 mock_index
.build_name_components ();
4296 /* Test the lower-level mapped_index::find_name_component_bounds
4297 method in completion mode. */
4299 static const char *expected_syms
[] = {
4304 SELF_CHECK (check_find_bounds_finds (mock_index
,
4305 "t1_func", expected_syms
));
4308 /* Check that the increment-last-char in the name matching algorithm
4309 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4311 static const char *expected_syms1
[] = {
4315 SELF_CHECK (check_find_bounds_finds (mock_index
,
4316 "\377", expected_syms1
));
4318 static const char *expected_syms2
[] = {
4321 SELF_CHECK (check_find_bounds_finds (mock_index
,
4322 "\377\377", expected_syms2
));
4326 /* Test dw2_expand_symtabs_matching_symbol. */
4329 test_dw2_expand_symtabs_matching_symbol ()
4331 mock_mapped_index
mock_index (test_symbols
);
4333 /* We let all tests run until the end even if some fails, for debug
4335 bool any_mismatch
= false;
4337 /* Create the expected symbols list (an initializer_list). Needed
4338 because lists have commas, and we need to pass them to CHECK,
4339 which is a macro. */
4340 #define EXPECT(...) { __VA_ARGS__ }
4342 /* Wrapper for check_match that passes down the current
4343 __FILE__/__LINE__. */
4344 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4345 any_mismatch |= !check_match (__FILE__, __LINE__, \
4347 NAME, MATCH_TYPE, COMPLETION_MODE, \
4350 /* Identity checks. */
4351 for (const char *sym
: test_symbols
)
4353 /* Should be able to match all existing symbols. */
4354 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4357 /* Should be able to match all existing symbols with
4359 std::string with_params
= std::string (sym
) + "(int)";
4360 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4363 /* Should be able to match all existing symbols with
4364 parameters and qualifiers. */
4365 with_params
= std::string (sym
) + " ( int ) const";
4366 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4369 /* This should really find sym, but cp-name-parser.y doesn't
4370 know about lvalue/rvalue qualifiers yet. */
4371 with_params
= std::string (sym
) + " ( int ) &&";
4372 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4376 /* Check that the name matching algorithm for completion doesn't get
4377 confused with Latin1 'ÿ' / 0xff. */
4379 static const char str
[] = "\377";
4380 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4381 EXPECT ("\377", "\377\377123"));
4384 /* Check that the increment-last-char in the matching algorithm for
4385 completion doesn't match "t1_fund" when completing "t1_func". */
4387 static const char str
[] = "t1_func";
4388 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4389 EXPECT ("t1_func", "t1_func1"));
4392 /* Check that completion mode works at each prefix of the expected
4395 static const char str
[] = "function(int)";
4396 size_t len
= strlen (str
);
4399 for (size_t i
= 1; i
< len
; i
++)
4401 lookup
.assign (str
, i
);
4402 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4403 EXPECT ("function"));
4407 /* While "w" is a prefix of both components, the match function
4408 should still only be called once. */
4410 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4412 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4416 /* Same, with a "complicated" symbol. */
4418 static const char str
[] = Z_SYM_NAME
;
4419 size_t len
= strlen (str
);
4422 for (size_t i
= 1; i
< len
; i
++)
4424 lookup
.assign (str
, i
);
4425 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4426 EXPECT (Z_SYM_NAME
));
4430 /* In FULL mode, an incomplete symbol doesn't match. */
4432 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4436 /* A complete symbol with parameters matches any overload, since the
4437 index has no overload info. */
4439 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4440 EXPECT ("std::zfunction", "std::zfunction2"));
4441 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4442 EXPECT ("std::zfunction", "std::zfunction2"));
4443 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4444 EXPECT ("std::zfunction", "std::zfunction2"));
4447 /* Check that whitespace is ignored appropriately. A symbol with a
4448 template argument list. */
4450 static const char expected
[] = "ns::foo<int>";
4451 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4453 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4457 /* Check that whitespace is ignored appropriately. A symbol with a
4458 template argument list that includes a pointer. */
4460 static const char expected
[] = "ns::foo<char*>";
4461 /* Try both completion and non-completion modes. */
4462 static const bool completion_mode
[2] = {false, true};
4463 for (size_t i
= 0; i
< 2; i
++)
4465 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4466 completion_mode
[i
], EXPECT (expected
));
4467 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4468 completion_mode
[i
], EXPECT (expected
));
4470 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4471 completion_mode
[i
], EXPECT (expected
));
4472 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4473 completion_mode
[i
], EXPECT (expected
));
4478 /* Check method qualifiers are ignored. */
4479 static const char expected
[] = "ns::foo<char*>";
4480 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4481 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4482 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4483 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4484 CHECK_MATCH ("foo < char * > ( int ) const",
4485 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4486 CHECK_MATCH ("foo < char * > ( int ) &&",
4487 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4490 /* Test lookup names that don't match anything. */
4492 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4495 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4499 /* Some wild matching tests, exercising "(anonymous namespace)",
4500 which should not be confused with a parameter list. */
4502 static const char *syms
[] = {
4506 "A :: B :: C ( int )",
4511 for (const char *s
: syms
)
4513 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4514 EXPECT ("(anonymous namespace)::A::B::C"));
4519 static const char expected
[] = "ns2::tmpl<int>::foo2";
4520 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4522 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4526 SELF_CHECK (!any_mismatch
);
4535 test_mapped_index_find_name_component_bounds ();
4536 test_dw2_expand_symtabs_matching_symbol ();
4539 }} // namespace selftests::dw2_expand_symtabs_matching
4541 #endif /* GDB_SELF_TEST */
4543 /* If FILE_MATCHER is NULL or if PER_CU has
4544 dwarf2_per_cu_quick_data::MARK set (see
4545 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4546 EXPANSION_NOTIFY on it. */
4549 dw2_expand_symtabs_matching_one
4550 (dwarf2_per_cu_data
*per_cu
,
4551 dwarf2_per_objfile
*per_objfile
,
4552 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4553 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4555 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4557 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4559 compunit_symtab
*symtab
4560 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4561 gdb_assert (symtab
!= nullptr);
4563 if (expansion_notify
!= NULL
&& symtab_was_null
)
4564 expansion_notify (symtab
);
4568 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4569 matched, to expand corresponding CUs that were marked. IDX is the
4570 index of the symbol name that matched. */
4573 dw2_expand_marked_cus
4574 (dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4575 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4576 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4579 offset_type
*vec
, vec_len
, vec_idx
;
4580 bool global_seen
= false;
4581 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4583 vec
= (offset_type
*) (index
.constant_pool
4584 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4585 vec_len
= MAYBE_SWAP (vec
[0]);
4586 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4588 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4589 /* This value is only valid for index versions >= 7. */
4590 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4591 gdb_index_symbol_kind symbol_kind
=
4592 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4593 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4594 /* Only check the symbol attributes if they're present.
4595 Indices prior to version 7 don't record them,
4596 and indices >= 7 may elide them for certain symbols
4597 (gold does this). */
4600 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4602 /* Work around gold/15646. */
4605 if (!is_static
&& global_seen
)
4611 /* Only check the symbol's kind if it has one. */
4616 case VARIABLES_DOMAIN
:
4617 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4620 case FUNCTIONS_DOMAIN
:
4621 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4625 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4628 case MODULES_DOMAIN
:
4629 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4637 /* Don't crash on bad data. */
4638 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
4639 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
4641 complaint (_(".gdb_index entry has bad CU index"
4643 objfile_name (dwarf2_per_objfile
->objfile
));
4647 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
4648 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, file_matcher
,
4653 /* If FILE_MATCHER is non-NULL, set all the
4654 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4655 that match FILE_MATCHER. */
4658 dw_expand_symtabs_matching_file_matcher
4659 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4660 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4662 if (file_matcher
== NULL
)
4665 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4667 NULL
, xcalloc
, xfree
));
4668 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4670 NULL
, xcalloc
, xfree
));
4672 /* The rule is CUs specify all the files, including those used by
4673 any TU, so there's no need to scan TUs here. */
4675 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4679 per_cu
->v
.quick
->mark
= 0;
4681 /* We only need to look at symtabs not already expanded. */
4682 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4685 quick_file_names
*file_data
4686 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4687 if (file_data
== NULL
)
4690 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4692 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4694 per_cu
->v
.quick
->mark
= 1;
4698 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4700 const char *this_real_name
;
4702 if (file_matcher (file_data
->file_names
[j
], false))
4704 per_cu
->v
.quick
->mark
= 1;
4708 /* Before we invoke realpath, which can get expensive when many
4709 files are involved, do a quick comparison of the basenames. */
4710 if (!basenames_may_differ
4711 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4715 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
4717 if (file_matcher (this_real_name
, false))
4719 per_cu
->v
.quick
->mark
= 1;
4724 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4725 ? visited_found
.get ()
4726 : visited_not_found
.get (),
4733 dw2_expand_symtabs_matching
4734 (struct objfile
*objfile
,
4735 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4736 const lookup_name_info
*lookup_name
,
4737 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4738 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4739 enum search_domain kind
)
4741 struct dwarf2_per_objfile
*dwarf2_per_objfile
4742 = get_dwarf2_per_objfile (objfile
);
4744 /* index_table is NULL if OBJF_READNOW. */
4745 if (!dwarf2_per_objfile
->per_bfd
->index_table
)
4748 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4750 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4752 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4756 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
4757 file_matcher
, expansion_notify
);
4762 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4764 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4766 kind
, [&] (offset_type idx
)
4768 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4769 expansion_notify
, kind
);
4774 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4777 static struct compunit_symtab
*
4778 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4783 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4784 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4787 if (cust
->includes
== NULL
)
4790 for (i
= 0; cust
->includes
[i
]; ++i
)
4792 struct compunit_symtab
*s
= cust
->includes
[i
];
4794 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4802 static struct compunit_symtab
*
4803 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4804 struct bound_minimal_symbol msymbol
,
4806 struct obj_section
*section
,
4809 struct dwarf2_per_cu_data
*data
;
4810 struct compunit_symtab
*result
;
4812 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4815 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4816 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4817 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4821 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4822 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4823 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4824 paddress (objfile
->arch (), pc
));
4826 result
= recursively_find_pc_sect_compunit_symtab
4827 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4829 gdb_assert (result
!= NULL
);
4834 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4835 void *data
, int need_fullname
)
4837 struct dwarf2_per_objfile
*dwarf2_per_objfile
4838 = get_dwarf2_per_objfile (objfile
);
4840 if (!dwarf2_per_objfile
->per_bfd
->filenames_cache
)
4842 dwarf2_per_objfile
->per_bfd
->filenames_cache
.emplace ();
4844 htab_up
visited (htab_create_alloc (10,
4845 htab_hash_pointer
, htab_eq_pointer
,
4846 NULL
, xcalloc
, xfree
));
4848 /* The rule is CUs specify all the files, including those used
4849 by any TU, so there's no need to scan TUs here. We can
4850 ignore file names coming from already-expanded CUs. */
4852 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4854 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4856 void **slot
= htab_find_slot (visited
.get (),
4857 per_cu
->v
.quick
->file_names
,
4860 *slot
= per_cu
->v
.quick
->file_names
;
4864 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4866 /* We only need to look at symtabs not already expanded. */
4867 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4870 quick_file_names
*file_data
4871 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4872 if (file_data
== NULL
)
4875 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4878 /* Already visited. */
4883 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4885 const char *filename
= file_data
->file_names
[j
];
4886 dwarf2_per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4891 dwarf2_per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4893 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4896 this_real_name
= gdb_realpath (filename
);
4897 (*fun
) (filename
, this_real_name
.get (), data
);
4902 dw2_has_symbols (struct objfile
*objfile
)
4907 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4910 dw2_find_last_source_symtab
,
4911 dw2_forget_cached_source_info
,
4912 dw2_map_symtabs_matching_filename
,
4917 dw2_expand_symtabs_for_function
,
4918 dw2_expand_all_symtabs
,
4919 dw2_expand_symtabs_with_fullname
,
4920 dw2_map_matching_symbols
,
4921 dw2_expand_symtabs_matching
,
4922 dw2_find_pc_sect_compunit_symtab
,
4924 dw2_map_symbol_filenames
4927 /* DWARF-5 debug_names reader. */
4929 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4930 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4932 /* A helper function that reads the .debug_names section in SECTION
4933 and fills in MAP. FILENAME is the name of the file containing the
4934 section; it is used for error reporting.
4936 Returns true if all went well, false otherwise. */
4939 read_debug_names_from_section (struct objfile
*objfile
,
4940 const char *filename
,
4941 struct dwarf2_section_info
*section
,
4942 mapped_debug_names
&map
)
4944 if (section
->empty ())
4947 /* Older elfutils strip versions could keep the section in the main
4948 executable while splitting it for the separate debug info file. */
4949 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4952 section
->read (objfile
);
4954 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4956 const gdb_byte
*addr
= section
->buffer
;
4958 bfd
*const abfd
= section
->get_bfd_owner ();
4960 unsigned int bytes_read
;
4961 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4964 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4965 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4966 if (bytes_read
+ length
!= section
->size
)
4968 /* There may be multiple per-CU indices. */
4969 warning (_("Section .debug_names in %s length %s does not match "
4970 "section length %s, ignoring .debug_names."),
4971 filename
, plongest (bytes_read
+ length
),
4972 pulongest (section
->size
));
4976 /* The version number. */
4977 uint16_t version
= read_2_bytes (abfd
, addr
);
4981 warning (_("Section .debug_names in %s has unsupported version %d, "
4982 "ignoring .debug_names."),
4988 uint16_t padding
= read_2_bytes (abfd
, addr
);
4992 warning (_("Section .debug_names in %s has unsupported padding %d, "
4993 "ignoring .debug_names."),
4998 /* comp_unit_count - The number of CUs in the CU list. */
4999 map
.cu_count
= read_4_bytes (abfd
, addr
);
5002 /* local_type_unit_count - The number of TUs in the local TU
5004 map
.tu_count
= read_4_bytes (abfd
, addr
);
5007 /* foreign_type_unit_count - The number of TUs in the foreign TU
5009 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5011 if (foreign_tu_count
!= 0)
5013 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5014 "ignoring .debug_names."),
5015 filename
, static_cast<unsigned long> (foreign_tu_count
));
5019 /* bucket_count - The number of hash buckets in the hash lookup
5021 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5024 /* name_count - The number of unique names in the index. */
5025 map
.name_count
= read_4_bytes (abfd
, addr
);
5028 /* abbrev_table_size - The size in bytes of the abbreviations
5030 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5033 /* augmentation_string_size - The size in bytes of the augmentation
5034 string. This value is rounded up to a multiple of 4. */
5035 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5037 map
.augmentation_is_gdb
= ((augmentation_string_size
5038 == sizeof (dwarf5_augmentation
))
5039 && memcmp (addr
, dwarf5_augmentation
,
5040 sizeof (dwarf5_augmentation
)) == 0);
5041 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5042 addr
+= augmentation_string_size
;
5045 map
.cu_table_reordered
= addr
;
5046 addr
+= map
.cu_count
* map
.offset_size
;
5048 /* List of Local TUs */
5049 map
.tu_table_reordered
= addr
;
5050 addr
+= map
.tu_count
* map
.offset_size
;
5052 /* Hash Lookup Table */
5053 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5054 addr
+= map
.bucket_count
* 4;
5055 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5056 addr
+= map
.name_count
* 4;
5059 map
.name_table_string_offs_reordered
= addr
;
5060 addr
+= map
.name_count
* map
.offset_size
;
5061 map
.name_table_entry_offs_reordered
= addr
;
5062 addr
+= map
.name_count
* map
.offset_size
;
5064 const gdb_byte
*abbrev_table_start
= addr
;
5067 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5072 const auto insertpair
5073 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5074 if (!insertpair
.second
)
5076 warning (_("Section .debug_names in %s has duplicate index %s, "
5077 "ignoring .debug_names."),
5078 filename
, pulongest (index_num
));
5081 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5082 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5087 mapped_debug_names::index_val::attr attr
;
5088 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5090 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5092 if (attr
.form
== DW_FORM_implicit_const
)
5094 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5098 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5100 indexval
.attr_vec
.push_back (std::move (attr
));
5103 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5105 warning (_("Section .debug_names in %s has abbreviation_table "
5106 "of size %s vs. written as %u, ignoring .debug_names."),
5107 filename
, plongest (addr
- abbrev_table_start
),
5111 map
.entry_pool
= addr
;
5116 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5120 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5121 const mapped_debug_names
&map
,
5122 dwarf2_section_info
§ion
,
5125 if (!map
.augmentation_is_gdb
)
5127 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5129 sect_offset sect_off
5130 = (sect_offset
) (extract_unsigned_integer
5131 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5133 map
.dwarf5_byte_order
));
5134 /* We don't know the length of the CU, because the CU list in a
5135 .debug_names index can be incomplete, so we can't use the start of
5136 the next CU as end of this CU. We create the CUs here with length 0,
5137 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5138 dwarf2_per_cu_data
*per_cu
5139 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5141 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5145 sect_offset sect_off_prev
;
5146 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5148 sect_offset sect_off_next
;
5149 if (i
< map
.cu_count
)
5152 = (sect_offset
) (extract_unsigned_integer
5153 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5155 map
.dwarf5_byte_order
));
5158 sect_off_next
= (sect_offset
) section
.size
;
5161 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5162 dwarf2_per_cu_data
*per_cu
5163 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5164 sect_off_prev
, length
);
5165 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5167 sect_off_prev
= sect_off_next
;
5171 /* Read the CU list from the mapped index, and use it to create all
5172 the CU objects for this dwarf2_per_objfile. */
5175 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5176 const mapped_debug_names
&map
,
5177 const mapped_debug_names
&dwz_map
)
5179 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
5180 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5182 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5183 dwarf2_per_objfile
->per_bfd
->info
,
5184 false /* is_dwz */);
5186 if (dwz_map
.cu_count
== 0)
5189 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
5190 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5194 /* Read .debug_names. If everything went ok, initialize the "quick"
5195 elements of all the CUs and return true. Otherwise, return false. */
5198 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5200 std::unique_ptr
<mapped_debug_names
> map
5201 (new mapped_debug_names (dwarf2_per_objfile
));
5202 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5203 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5205 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5206 &dwarf2_per_objfile
->per_bfd
->debug_names
,
5210 /* Don't use the index if it's empty. */
5211 if (map
->name_count
== 0)
5214 /* If there is a .dwz file, read it so we can get its CU list as
5216 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
5219 if (!read_debug_names_from_section (objfile
,
5220 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5221 &dwz
->debug_names
, dwz_map
))
5223 warning (_("could not read '.debug_names' section from %s; skipping"),
5224 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5229 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5231 if (map
->tu_count
!= 0)
5233 /* We can only handle a single .debug_types when we have an
5235 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
5238 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
5240 create_signatured_type_table_from_debug_names
5241 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->per_bfd
->abbrev
);
5244 create_addrmap_from_aranges (dwarf2_per_objfile
,
5245 &dwarf2_per_objfile
->per_bfd
->debug_aranges
);
5247 dwarf2_per_objfile
->per_bfd
->debug_names_table
= std::move (map
);
5248 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5249 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
5250 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5255 /* Type used to manage iterating over all CUs looking for a symbol for
5258 class dw2_debug_names_iterator
5261 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5262 gdb::optional
<block_enum
> block_index
,
5265 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5266 m_addr (find_vec_in_debug_names (map
, name
))
5269 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5270 search_domain search
, uint32_t namei
)
5273 m_addr (find_vec_in_debug_names (map
, namei
))
5276 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5277 block_enum block_index
, domain_enum domain
,
5279 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5280 m_addr (find_vec_in_debug_names (map
, namei
))
5283 /* Return the next matching CU or NULL if there are no more. */
5284 dwarf2_per_cu_data
*next ();
5287 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5289 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5292 /* The internalized form of .debug_names. */
5293 const mapped_debug_names
&m_map
;
5295 /* If set, only look for symbols that match that block. Valid values are
5296 GLOBAL_BLOCK and STATIC_BLOCK. */
5297 const gdb::optional
<block_enum
> m_block_index
;
5299 /* The kind of symbol we're looking for. */
5300 const domain_enum m_domain
= UNDEF_DOMAIN
;
5301 const search_domain m_search
= ALL_DOMAIN
;
5303 /* The list of CUs from the index entry of the symbol, or NULL if
5305 const gdb_byte
*m_addr
;
5309 mapped_debug_names::namei_to_name (uint32_t namei
) const
5311 const ULONGEST namei_string_offs
5312 = extract_unsigned_integer ((name_table_string_offs_reordered
5313 + namei
* offset_size
),
5316 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5320 /* Find a slot in .debug_names for the object named NAME. If NAME is
5321 found, return pointer to its pool data. If NAME cannot be found,
5325 dw2_debug_names_iterator::find_vec_in_debug_names
5326 (const mapped_debug_names
&map
, const char *name
)
5328 int (*cmp
) (const char *, const char *);
5330 gdb::unique_xmalloc_ptr
<char> without_params
;
5331 if (current_language
->la_language
== language_cplus
5332 || current_language
->la_language
== language_fortran
5333 || current_language
->la_language
== language_d
)
5335 /* NAME is already canonical. Drop any qualifiers as
5336 .debug_names does not contain any. */
5338 if (strchr (name
, '(') != NULL
)
5340 without_params
= cp_remove_params (name
);
5341 if (without_params
!= NULL
)
5342 name
= without_params
.get ();
5346 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5348 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5350 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5351 (map
.bucket_table_reordered
5352 + (full_hash
% map
.bucket_count
)), 4,
5353 map
.dwarf5_byte_order
);
5357 if (namei
>= map
.name_count
)
5359 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5361 namei
, map
.name_count
,
5362 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5368 const uint32_t namei_full_hash
5369 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5370 (map
.hash_table_reordered
+ namei
), 4,
5371 map
.dwarf5_byte_order
);
5372 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5375 if (full_hash
== namei_full_hash
)
5377 const char *const namei_string
= map
.namei_to_name (namei
);
5379 #if 0 /* An expensive sanity check. */
5380 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5382 complaint (_("Wrong .debug_names hash for string at index %u "
5384 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5389 if (cmp (namei_string
, name
) == 0)
5391 const ULONGEST namei_entry_offs
5392 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5393 + namei
* map
.offset_size
),
5394 map
.offset_size
, map
.dwarf5_byte_order
);
5395 return map
.entry_pool
+ namei_entry_offs
;
5400 if (namei
>= map
.name_count
)
5406 dw2_debug_names_iterator::find_vec_in_debug_names
5407 (const mapped_debug_names
&map
, uint32_t namei
)
5409 if (namei
>= map
.name_count
)
5411 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5413 namei
, map
.name_count
,
5414 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5418 const ULONGEST namei_entry_offs
5419 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5420 + namei
* map
.offset_size
),
5421 map
.offset_size
, map
.dwarf5_byte_order
);
5422 return map
.entry_pool
+ namei_entry_offs
;
5425 /* See dw2_debug_names_iterator. */
5427 dwarf2_per_cu_data
*
5428 dw2_debug_names_iterator::next ()
5433 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5434 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5435 bfd
*const abfd
= objfile
->obfd
;
5439 unsigned int bytes_read
;
5440 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5441 m_addr
+= bytes_read
;
5445 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5446 if (indexval_it
== m_map
.abbrev_map
.cend ())
5448 complaint (_("Wrong .debug_names undefined abbrev code %s "
5450 pulongest (abbrev
), objfile_name (objfile
));
5453 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5454 enum class symbol_linkage
{
5458 } symbol_linkage_
= symbol_linkage::unknown
;
5459 dwarf2_per_cu_data
*per_cu
= NULL
;
5460 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5465 case DW_FORM_implicit_const
:
5466 ull
= attr
.implicit_const
;
5468 case DW_FORM_flag_present
:
5472 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5473 m_addr
+= bytes_read
;
5476 ull
= read_4_bytes (abfd
, m_addr
);
5480 ull
= read_8_bytes (abfd
, m_addr
);
5483 case DW_FORM_ref_sig8
:
5484 ull
= read_8_bytes (abfd
, m_addr
);
5488 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5489 dwarf_form_name (attr
.form
),
5490 objfile_name (objfile
));
5493 switch (attr
.dw_idx
)
5495 case DW_IDX_compile_unit
:
5496 /* Don't crash on bad data. */
5497 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
5499 complaint (_(".debug_names entry has bad CU index %s"
5502 objfile_name (dwarf2_per_objfile
->objfile
));
5505 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (ull
);
5507 case DW_IDX_type_unit
:
5508 /* Don't crash on bad data. */
5509 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_type_units
.size ())
5511 complaint (_(".debug_names entry has bad TU index %s"
5514 objfile_name (dwarf2_per_objfile
->objfile
));
5517 per_cu
= &dwarf2_per_objfile
->per_bfd
->get_tu (ull
)->per_cu
;
5519 case DW_IDX_die_offset
:
5520 /* In a per-CU index (as opposed to a per-module index), index
5521 entries without CU attribute implicitly refer to the single CU. */
5523 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cu (0);
5525 case DW_IDX_GNU_internal
:
5526 if (!m_map
.augmentation_is_gdb
)
5528 symbol_linkage_
= symbol_linkage::static_
;
5530 case DW_IDX_GNU_external
:
5531 if (!m_map
.augmentation_is_gdb
)
5533 symbol_linkage_
= symbol_linkage::extern_
;
5538 /* Skip if already read in. */
5539 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
5542 /* Check static vs global. */
5543 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5545 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5546 const bool symbol_is_static
=
5547 symbol_linkage_
== symbol_linkage::static_
;
5548 if (want_static
!= symbol_is_static
)
5552 /* Match dw2_symtab_iter_next, symbol_kind
5553 and debug_names::psymbol_tag. */
5557 switch (indexval
.dwarf_tag
)
5559 case DW_TAG_variable
:
5560 case DW_TAG_subprogram
:
5561 /* Some types are also in VAR_DOMAIN. */
5562 case DW_TAG_typedef
:
5563 case DW_TAG_structure_type
:
5570 switch (indexval
.dwarf_tag
)
5572 case DW_TAG_typedef
:
5573 case DW_TAG_structure_type
:
5580 switch (indexval
.dwarf_tag
)
5583 case DW_TAG_variable
:
5590 switch (indexval
.dwarf_tag
)
5602 /* Match dw2_expand_symtabs_matching, symbol_kind and
5603 debug_names::psymbol_tag. */
5606 case VARIABLES_DOMAIN
:
5607 switch (indexval
.dwarf_tag
)
5609 case DW_TAG_variable
:
5615 case FUNCTIONS_DOMAIN
:
5616 switch (indexval
.dwarf_tag
)
5618 case DW_TAG_subprogram
:
5625 switch (indexval
.dwarf_tag
)
5627 case DW_TAG_typedef
:
5628 case DW_TAG_structure_type
:
5634 case MODULES_DOMAIN
:
5635 switch (indexval
.dwarf_tag
)
5649 static struct compunit_symtab
*
5650 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5651 const char *name
, domain_enum domain
)
5653 struct dwarf2_per_objfile
*dwarf2_per_objfile
5654 = get_dwarf2_per_objfile (objfile
);
5656 const auto &mapp
= dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5659 /* index is NULL if OBJF_READNOW. */
5662 const auto &map
= *mapp
;
5664 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5666 struct compunit_symtab
*stab_best
= NULL
;
5667 struct dwarf2_per_cu_data
*per_cu
;
5668 while ((per_cu
= iter
.next ()) != NULL
)
5670 struct symbol
*sym
, *with_opaque
= NULL
;
5671 compunit_symtab
*stab
5672 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5673 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5674 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5676 sym
= block_find_symbol (block
, name
, domain
,
5677 block_find_non_opaque_type_preferred
,
5680 /* Some caution must be observed with overloaded functions and
5681 methods, since the index will not contain any overload
5682 information (but NAME might contain it). */
5685 && strcmp_iw (sym
->search_name (), name
) == 0)
5687 if (with_opaque
!= NULL
5688 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5691 /* Keep looking through other CUs. */
5697 /* This dumps minimal information about .debug_names. It is called
5698 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5699 uses this to verify that .debug_names has been loaded. */
5702 dw2_debug_names_dump (struct objfile
*objfile
)
5704 struct dwarf2_per_objfile
*dwarf2_per_objfile
5705 = get_dwarf2_per_objfile (objfile
);
5707 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
5708 printf_filtered (".debug_names:");
5709 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5710 printf_filtered (" exists\n");
5712 printf_filtered (" faked for \"readnow\"\n");
5713 printf_filtered ("\n");
5717 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5718 const char *func_name
)
5720 struct dwarf2_per_objfile
*dwarf2_per_objfile
5721 = get_dwarf2_per_objfile (objfile
);
5723 /* dwarf2_per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5724 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5726 const mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5728 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5730 struct dwarf2_per_cu_data
*per_cu
;
5731 while ((per_cu
= iter
.next ()) != NULL
)
5732 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5737 dw2_debug_names_map_matching_symbols
5738 (struct objfile
*objfile
,
5739 const lookup_name_info
&name
, domain_enum domain
,
5741 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5742 symbol_compare_ftype
*ordered_compare
)
5744 struct dwarf2_per_objfile
*dwarf2_per_objfile
5745 = get_dwarf2_per_objfile (objfile
);
5747 /* debug_names_table is NULL if OBJF_READNOW. */
5748 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5751 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5752 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5754 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5755 auto matcher
= [&] (const char *symname
)
5757 if (ordered_compare
== nullptr)
5759 return ordered_compare (symname
, match_name
) == 0;
5762 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5763 [&] (offset_type namei
)
5765 /* The name was matched, now expand corresponding CUs that were
5767 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5769 struct dwarf2_per_cu_data
*per_cu
;
5770 while ((per_cu
= iter
.next ()) != NULL
)
5771 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
5776 /* It's a shame we couldn't do this inside the
5777 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5778 that have already been expanded. Instead, this loop matches what
5779 the psymtab code does. */
5780 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5782 compunit_symtab
*symtab
= dwarf2_per_objfile
->get_symtab (per_cu
);
5783 if (symtab
!= nullptr)
5785 const struct block
*block
5786 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5787 if (!iterate_over_symbols_terminated (block
, name
,
5795 dw2_debug_names_expand_symtabs_matching
5796 (struct objfile
*objfile
,
5797 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5798 const lookup_name_info
*lookup_name
,
5799 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5800 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5801 enum search_domain kind
)
5803 struct dwarf2_per_objfile
*dwarf2_per_objfile
5804 = get_dwarf2_per_objfile (objfile
);
5806 /* debug_names_table is NULL if OBJF_READNOW. */
5807 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5810 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5812 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5814 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5818 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5819 file_matcher
, expansion_notify
);
5824 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5826 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5828 kind
, [&] (offset_type namei
)
5830 /* The name was matched, now expand corresponding CUs that were
5832 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5834 struct dwarf2_per_cu_data
*per_cu
;
5835 while ((per_cu
= iter
.next ()) != NULL
)
5836 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5837 file_matcher
, expansion_notify
);
5842 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5845 dw2_find_last_source_symtab
,
5846 dw2_forget_cached_source_info
,
5847 dw2_map_symtabs_matching_filename
,
5848 dw2_debug_names_lookup_symbol
,
5851 dw2_debug_names_dump
,
5852 dw2_debug_names_expand_symtabs_for_function
,
5853 dw2_expand_all_symtabs
,
5854 dw2_expand_symtabs_with_fullname
,
5855 dw2_debug_names_map_matching_symbols
,
5856 dw2_debug_names_expand_symtabs_matching
,
5857 dw2_find_pc_sect_compunit_symtab
,
5859 dw2_map_symbol_filenames
5862 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5863 to either a dwarf2_per_bfd or dwz_file object. */
5865 template <typename T
>
5866 static gdb::array_view
<const gdb_byte
>
5867 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5869 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5871 if (section
->empty ())
5874 /* Older elfutils strip versions could keep the section in the main
5875 executable while splitting it for the separate debug info file. */
5876 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5879 section
->read (obj
);
5881 /* dwarf2_section_info::size is a bfd_size_type, while
5882 gdb::array_view works with size_t. On 32-bit hosts, with
5883 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5884 is 32-bit. So we need an explicit narrowing conversion here.
5885 This is fine, because it's impossible to allocate or mmap an
5886 array/buffer larger than what size_t can represent. */
5887 return gdb::make_array_view (section
->buffer
, section
->size
);
5890 /* Lookup the index cache for the contents of the index associated to
5893 static gdb::array_view
<const gdb_byte
>
5894 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5896 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5897 if (build_id
== nullptr)
5900 return global_index_cache
.lookup_gdb_index (build_id
,
5901 &dwarf2_per_bfd
->index_cache_res
);
5904 /* Same as the above, but for DWZ. */
5906 static gdb::array_view
<const gdb_byte
>
5907 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5909 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5910 if (build_id
== nullptr)
5913 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5916 /* See symfile.h. */
5919 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5921 struct dwarf2_per_objfile
*dwarf2_per_objfile
5922 = get_dwarf2_per_objfile (objfile
);
5924 /* If we're about to read full symbols, don't bother with the
5925 indices. In this case we also don't care if some other debug
5926 format is making psymtabs, because they are all about to be
5928 if ((objfile
->flags
& OBJF_READNOW
))
5930 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5931 create_all_comp_units (dwarf2_per_objfile
);
5932 create_all_type_units (dwarf2_per_objfile
);
5933 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
5934 = create_quick_file_names_table
5935 (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5936 dwarf2_per_objfile
->resize_symtabs ();
5938 for (int i
= 0; i
< (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
5939 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()); ++i
)
5941 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
5943 per_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
5944 struct dwarf2_per_cu_quick_data
);
5947 /* Return 1 so that gdb sees the "quick" functions. However,
5948 these functions will be no-ops because we will have expanded
5950 *index_kind
= dw_index_kind::GDB_INDEX
;
5954 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5956 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5957 dwarf2_per_objfile
->resize_symtabs ();
5961 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5962 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5963 get_gdb_index_contents_from_section
<dwz_file
>))
5965 *index_kind
= dw_index_kind::GDB_INDEX
;
5966 dwarf2_per_objfile
->resize_symtabs ();
5970 /* ... otherwise, try to find the index in the index cache. */
5971 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5972 get_gdb_index_contents_from_cache
,
5973 get_gdb_index_contents_from_cache_dwz
))
5975 global_index_cache
.hit ();
5976 *index_kind
= dw_index_kind::GDB_INDEX
;
5977 dwarf2_per_objfile
->resize_symtabs ();
5981 global_index_cache
.miss ();
5987 /* Build a partial symbol table. */
5990 dwarf2_build_psymtabs (struct objfile
*objfile
)
5992 struct dwarf2_per_objfile
*dwarf2_per_objfile
5993 = get_dwarf2_per_objfile (objfile
);
5995 init_psymbol_list (objfile
, 1024);
5999 /* This isn't really ideal: all the data we allocate on the
6000 objfile's obstack is still uselessly kept around. However,
6001 freeing it seems unsafe. */
6002 psymtab_discarder
psymtabs (objfile
);
6003 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6006 dwarf2_per_objfile
->resize_symtabs ();
6008 /* (maybe) store an index in the cache. */
6009 global_index_cache
.store (dwarf2_per_objfile
);
6011 catch (const gdb_exception_error
&except
)
6013 exception_print (gdb_stderr
, except
);
6017 /* Find the base address of the compilation unit for range lists and
6018 location lists. It will normally be specified by DW_AT_low_pc.
6019 In DWARF-3 draft 4, the base address could be overridden by
6020 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6021 compilation units with discontinuous ranges. */
6024 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6026 struct attribute
*attr
;
6028 cu
->base_address
.reset ();
6030 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6031 if (attr
!= nullptr)
6032 cu
->base_address
= attr
->value_as_address ();
6035 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6036 if (attr
!= nullptr)
6037 cu
->base_address
= attr
->value_as_address ();
6041 /* Helper function that returns the proper abbrev section for
6044 static struct dwarf2_section_info
*
6045 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6047 struct dwarf2_section_info
*abbrev
;
6048 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6050 if (this_cu
->is_dwz
)
6051 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6053 abbrev
= &per_bfd
->abbrev
;
6058 /* Fetch the abbreviation table offset from a comp or type unit header. */
6061 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6062 struct dwarf2_section_info
*section
,
6063 sect_offset sect_off
)
6065 bfd
*abfd
= section
->get_bfd_owner ();
6066 const gdb_byte
*info_ptr
;
6067 unsigned int initial_length_size
, offset_size
;
6070 section
->read (dwarf2_per_objfile
->objfile
);
6071 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6072 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6073 offset_size
= initial_length_size
== 4 ? 4 : 8;
6074 info_ptr
+= initial_length_size
;
6076 version
= read_2_bytes (abfd
, info_ptr
);
6080 /* Skip unit type and address size. */
6084 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6087 /* A partial symtab that is used only for include files. */
6088 struct dwarf2_include_psymtab
: public partial_symtab
6090 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6091 : partial_symtab (filename
, objfile
)
6095 void read_symtab (struct objfile
*objfile
) override
6097 /* It's an include file, no symbols to read for it.
6098 Everything is in the includer symtab. */
6100 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6101 expansion of the includer psymtab. We use the dependencies[0] field to
6102 model the includer. But if we go the regular route of calling
6103 expand_psymtab here, and having expand_psymtab call expand_dependencies
6104 to expand the includer, we'll only use expand_psymtab on the includer
6105 (making it a non-toplevel psymtab), while if we expand the includer via
6106 another path, we'll use read_symtab (making it a toplevel psymtab).
6107 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6108 psymtab, and trigger read_symtab on the includer here directly. */
6109 includer ()->read_symtab (objfile
);
6112 void expand_psymtab (struct objfile
*objfile
) override
6114 /* This is not called by read_symtab, and should not be called by any
6115 expand_dependencies. */
6119 bool readin_p (struct objfile
*objfile
) const override
6121 return includer ()->readin_p (objfile
);
6124 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6130 partial_symtab
*includer () const
6132 /* An include psymtab has exactly one dependency: the psymtab that
6134 gdb_assert (this->number_of_dependencies
== 1);
6135 return this->dependencies
[0];
6139 /* Allocate a new partial symtab for file named NAME and mark this new
6140 partial symtab as being an include of PST. */
6143 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6144 struct objfile
*objfile
)
6146 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6148 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6149 subpst
->dirname
= pst
->dirname
;
6151 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6152 subpst
->dependencies
[0] = pst
;
6153 subpst
->number_of_dependencies
= 1;
6156 /* Read the Line Number Program data and extract the list of files
6157 included by the source file represented by PST. Build an include
6158 partial symtab for each of these included files. */
6161 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6162 struct die_info
*die
,
6163 dwarf2_psymtab
*pst
)
6166 struct attribute
*attr
;
6168 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6169 if (attr
!= nullptr)
6170 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6172 return; /* No linetable, so no includes. */
6174 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6175 that we pass in the raw text_low here; that is ok because we're
6176 only decoding the line table to make include partial symtabs, and
6177 so the addresses aren't really used. */
6178 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6179 pst
->raw_text_low (), 1);
6183 hash_signatured_type (const void *item
)
6185 const struct signatured_type
*sig_type
6186 = (const struct signatured_type
*) item
;
6188 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6189 return sig_type
->signature
;
6193 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6195 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6196 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6198 return lhs
->signature
== rhs
->signature
;
6201 /* Allocate a hash table for signatured types. */
6204 allocate_signatured_type_table ()
6206 return htab_up (htab_create_alloc (41,
6207 hash_signatured_type
,
6209 NULL
, xcalloc
, xfree
));
6212 /* A helper function to add a signatured type CU to a table. */
6215 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6217 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6218 std::vector
<signatured_type
*> *all_type_units
6219 = (std::vector
<signatured_type
*> *) datum
;
6221 all_type_units
->push_back (sigt
);
6226 /* A helper for create_debug_types_hash_table. Read types from SECTION
6227 and fill them into TYPES_HTAB. It will process only type units,
6228 therefore DW_UT_type. */
6231 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6232 struct dwo_file
*dwo_file
,
6233 dwarf2_section_info
*section
, htab_up
&types_htab
,
6234 rcuh_kind section_kind
)
6236 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6237 struct dwarf2_section_info
*abbrev_section
;
6239 const gdb_byte
*info_ptr
, *end_ptr
;
6241 abbrev_section
= (dwo_file
!= NULL
6242 ? &dwo_file
->sections
.abbrev
6243 : &dwarf2_per_objfile
->per_bfd
->abbrev
);
6245 if (dwarf_read_debug
)
6246 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6247 section
->get_name (),
6248 abbrev_section
->get_file_name ());
6250 section
->read (objfile
);
6251 info_ptr
= section
->buffer
;
6253 if (info_ptr
== NULL
)
6256 /* We can't set abfd until now because the section may be empty or
6257 not present, in which case the bfd is unknown. */
6258 abfd
= section
->get_bfd_owner ();
6260 /* We don't use cutu_reader here because we don't need to read
6261 any dies: the signature is in the header. */
6263 end_ptr
= info_ptr
+ section
->size
;
6264 while (info_ptr
< end_ptr
)
6266 struct signatured_type
*sig_type
;
6267 struct dwo_unit
*dwo_tu
;
6269 const gdb_byte
*ptr
= info_ptr
;
6270 struct comp_unit_head header
;
6271 unsigned int length
;
6273 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6275 /* Initialize it due to a false compiler warning. */
6276 header
.signature
= -1;
6277 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6279 /* We need to read the type's signature in order to build the hash
6280 table, but we don't need anything else just yet. */
6282 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6283 abbrev_section
, ptr
, section_kind
);
6285 length
= header
.get_length ();
6287 /* Skip dummy type units. */
6288 if (ptr
>= info_ptr
+ length
6289 || peek_abbrev_code (abfd
, ptr
) == 0
6290 || header
.unit_type
!= DW_UT_type
)
6296 if (types_htab
== NULL
)
6299 types_htab
= allocate_dwo_unit_table ();
6301 types_htab
= allocate_signatured_type_table ();
6307 dwo_tu
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6309 dwo_tu
->dwo_file
= dwo_file
;
6310 dwo_tu
->signature
= header
.signature
;
6311 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6312 dwo_tu
->section
= section
;
6313 dwo_tu
->sect_off
= sect_off
;
6314 dwo_tu
->length
= length
;
6318 /* N.B.: type_offset is not usable if this type uses a DWO file.
6319 The real type_offset is in the DWO file. */
6321 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6322 sig_type
->signature
= header
.signature
;
6323 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6324 sig_type
->per_cu
.is_debug_types
= 1;
6325 sig_type
->per_cu
.section
= section
;
6326 sig_type
->per_cu
.sect_off
= sect_off
;
6327 sig_type
->per_cu
.length
= length
;
6330 slot
= htab_find_slot (types_htab
.get (),
6331 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6333 gdb_assert (slot
!= NULL
);
6336 sect_offset dup_sect_off
;
6340 const struct dwo_unit
*dup_tu
6341 = (const struct dwo_unit
*) *slot
;
6343 dup_sect_off
= dup_tu
->sect_off
;
6347 const struct signatured_type
*dup_tu
6348 = (const struct signatured_type
*) *slot
;
6350 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6353 complaint (_("debug type entry at offset %s is duplicate to"
6354 " the entry at offset %s, signature %s"),
6355 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6356 hex_string (header
.signature
));
6358 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6360 if (dwarf_read_debug
> 1)
6361 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6362 sect_offset_str (sect_off
),
6363 hex_string (header
.signature
));
6369 /* Create the hash table of all entries in the .debug_types
6370 (or .debug_types.dwo) section(s).
6371 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6372 otherwise it is NULL.
6374 The result is a pointer to the hash table or NULL if there are no types.
6376 Note: This function processes DWO files only, not DWP files. */
6379 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6380 struct dwo_file
*dwo_file
,
6381 gdb::array_view
<dwarf2_section_info
> type_sections
,
6382 htab_up
&types_htab
)
6384 for (dwarf2_section_info
§ion
: type_sections
)
6385 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6386 types_htab
, rcuh_kind::TYPE
);
6389 /* Create the hash table of all entries in the .debug_types section,
6390 and initialize all_type_units.
6391 The result is zero if there is an error (e.g. missing .debug_types section),
6392 otherwise non-zero. */
6395 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6399 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6400 &dwarf2_per_objfile
->per_bfd
->info
, types_htab
,
6401 rcuh_kind::COMPILE
);
6402 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6403 dwarf2_per_objfile
->per_bfd
->types
, types_htab
);
6404 if (types_htab
== NULL
)
6406 dwarf2_per_objfile
->per_bfd
->signatured_types
= NULL
;
6410 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6412 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
6413 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve
6414 (htab_elements (dwarf2_per_objfile
->per_bfd
->signatured_types
.get ()));
6416 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6417 add_signatured_type_cu_to_table
,
6418 &dwarf2_per_objfile
->per_bfd
->all_type_units
);
6423 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6424 If SLOT is non-NULL, it is the entry to use in the hash table.
6425 Otherwise we find one. */
6427 static struct signatured_type
*
6428 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6431 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()
6432 == dwarf2_per_objfile
->per_bfd
->all_type_units
.capacity ())
6433 ++dwarf2_per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6435 signatured_type
*sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6437 dwarf2_per_objfile
->resize_symtabs ();
6439 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6440 sig_type
->signature
= sig
;
6441 sig_type
->per_cu
.is_debug_types
= 1;
6442 if (dwarf2_per_objfile
->per_bfd
->using_index
)
6444 sig_type
->per_cu
.v
.quick
=
6445 OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6446 struct dwarf2_per_cu_quick_data
);
6451 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6454 gdb_assert (*slot
== NULL
);
6456 /* The rest of sig_type must be filled in by the caller. */
6460 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6461 Fill in SIG_ENTRY with DWO_ENTRY. */
6464 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6465 struct signatured_type
*sig_entry
,
6466 struct dwo_unit
*dwo_entry
)
6468 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
6470 /* Make sure we're not clobbering something we don't expect to. */
6471 gdb_assert (! sig_entry
->per_cu
.queued
);
6472 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6473 if (per_bfd
->using_index
)
6475 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6476 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6479 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6480 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6481 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6482 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6483 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6485 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6486 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6487 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6488 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6489 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6490 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6491 sig_entry
->dwo_unit
= dwo_entry
;
6494 /* Subroutine of lookup_signatured_type.
6495 If we haven't read the TU yet, create the signatured_type data structure
6496 for a TU to be read in directly from a DWO file, bypassing the stub.
6497 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6498 using .gdb_index, then when reading a CU we want to stay in the DWO file
6499 containing that CU. Otherwise we could end up reading several other DWO
6500 files (due to comdat folding) to process the transitive closure of all the
6501 mentioned TUs, and that can be slow. The current DWO file will have every
6502 type signature that it needs.
6503 We only do this for .gdb_index because in the psymtab case we already have
6504 to read all the DWOs to build the type unit groups. */
6506 static struct signatured_type
*
6507 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6509 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6510 struct dwo_file
*dwo_file
;
6511 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6512 struct signatured_type find_sig_entry
, *sig_entry
;
6515 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6517 /* If TU skeletons have been removed then we may not have read in any
6519 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6520 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6522 /* We only ever need to read in one copy of a signatured type.
6523 Use the global signatured_types array to do our own comdat-folding
6524 of types. If this is the first time we're reading this TU, and
6525 the TU has an entry in .gdb_index, replace the recorded data from
6526 .gdb_index with this TU. */
6528 find_sig_entry
.signature
= sig
;
6529 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6530 &find_sig_entry
, INSERT
);
6531 sig_entry
= (struct signatured_type
*) *slot
;
6533 /* We can get here with the TU already read, *or* in the process of being
6534 read. Don't reassign the global entry to point to this DWO if that's
6535 the case. Also note that if the TU is already being read, it may not
6536 have come from a DWO, the program may be a mix of Fission-compiled
6537 code and non-Fission-compiled code. */
6539 /* Have we already tried to read this TU?
6540 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6541 needn't exist in the global table yet). */
6542 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6545 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6546 dwo_unit of the TU itself. */
6547 dwo_file
= cu
->dwo_unit
->dwo_file
;
6549 /* Ok, this is the first time we're reading this TU. */
6550 if (dwo_file
->tus
== NULL
)
6552 find_dwo_entry
.signature
= sig
;
6553 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6555 if (dwo_entry
== NULL
)
6558 /* If the global table doesn't have an entry for this TU, add one. */
6559 if (sig_entry
== NULL
)
6560 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6562 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6563 sig_entry
->per_cu
.tu_read
= 1;
6567 /* Subroutine of lookup_signatured_type.
6568 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6569 then try the DWP file. If the TU stub (skeleton) has been removed then
6570 it won't be in .gdb_index. */
6572 static struct signatured_type
*
6573 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6575 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6576 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6577 struct dwo_unit
*dwo_entry
;
6578 struct signatured_type find_sig_entry
, *sig_entry
;
6581 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6582 gdb_assert (dwp_file
!= NULL
);
6584 /* If TU skeletons have been removed then we may not have read in any
6586 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6587 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6589 find_sig_entry
.signature
= sig
;
6590 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6591 &find_sig_entry
, INSERT
);
6592 sig_entry
= (struct signatured_type
*) *slot
;
6594 /* Have we already tried to read this TU?
6595 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6596 needn't exist in the global table yet). */
6597 if (sig_entry
!= NULL
)
6600 if (dwp_file
->tus
== NULL
)
6602 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6603 sig
, 1 /* is_debug_types */);
6604 if (dwo_entry
== NULL
)
6607 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6608 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6613 /* Lookup a signature based type for DW_FORM_ref_sig8.
6614 Returns NULL if signature SIG is not present in the table.
6615 It is up to the caller to complain about this. */
6617 static struct signatured_type
*
6618 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6620 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6623 && dwarf2_per_objfile
->per_bfd
->using_index
)
6625 /* We're in a DWO/DWP file, and we're using .gdb_index.
6626 These cases require special processing. */
6627 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6628 return lookup_dwo_signatured_type (cu
, sig
);
6630 return lookup_dwp_signatured_type (cu
, sig
);
6634 struct signatured_type find_entry
, *entry
;
6636 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6638 find_entry
.signature
= sig
;
6639 entry
= ((struct signatured_type
*)
6640 htab_find (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6646 /* Low level DIE reading support. */
6648 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6651 init_cu_die_reader (struct die_reader_specs
*reader
,
6652 struct dwarf2_cu
*cu
,
6653 struct dwarf2_section_info
*section
,
6654 struct dwo_file
*dwo_file
,
6655 struct abbrev_table
*abbrev_table
)
6657 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6658 reader
->abfd
= section
->get_bfd_owner ();
6660 reader
->dwo_file
= dwo_file
;
6661 reader
->die_section
= section
;
6662 reader
->buffer
= section
->buffer
;
6663 reader
->buffer_end
= section
->buffer
+ section
->size
;
6664 reader
->abbrev_table
= abbrev_table
;
6667 /* Subroutine of cutu_reader to simplify it.
6668 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6669 There's just a lot of work to do, and cutu_reader is big enough
6672 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6673 from it to the DIE in the DWO. If NULL we are skipping the stub.
6674 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6675 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6676 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6677 STUB_COMP_DIR may be non-NULL.
6678 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6679 are filled in with the info of the DIE from the DWO file.
6680 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6681 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6682 kept around for at least as long as *RESULT_READER.
6684 The result is non-zero if a valid (non-dummy) DIE was found. */
6687 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6688 struct dwo_unit
*dwo_unit
,
6689 struct die_info
*stub_comp_unit_die
,
6690 const char *stub_comp_dir
,
6691 struct die_reader_specs
*result_reader
,
6692 const gdb_byte
**result_info_ptr
,
6693 struct die_info
**result_comp_unit_die
,
6694 abbrev_table_up
*result_dwo_abbrev_table
)
6696 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6697 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6698 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6700 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6701 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6702 int i
,num_extra_attrs
;
6703 struct dwarf2_section_info
*dwo_abbrev_section
;
6704 struct die_info
*comp_unit_die
;
6706 /* At most one of these may be provided. */
6707 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6709 /* These attributes aren't processed until later:
6710 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6711 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6712 referenced later. However, these attributes are found in the stub
6713 which we won't have later. In order to not impose this complication
6714 on the rest of the code, we read them here and copy them to the
6723 if (stub_comp_unit_die
!= NULL
)
6725 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6727 if (!per_cu
->is_debug_types
)
6728 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6729 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6730 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6731 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6732 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6734 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6736 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6737 here (if needed). We need the value before we can process
6739 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6741 else if (stub_comp_dir
!= NULL
)
6743 /* Reconstruct the comp_dir attribute to simplify the code below. */
6744 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6745 comp_dir
->name
= DW_AT_comp_dir
;
6746 comp_dir
->form
= DW_FORM_string
;
6747 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6748 DW_STRING (comp_dir
) = stub_comp_dir
;
6751 /* Set up for reading the DWO CU/TU. */
6752 cu
->dwo_unit
= dwo_unit
;
6753 dwarf2_section_info
*section
= dwo_unit
->section
;
6754 section
->read (objfile
);
6755 abfd
= section
->get_bfd_owner ();
6756 begin_info_ptr
= info_ptr
= (section
->buffer
6757 + to_underlying (dwo_unit
->sect_off
));
6758 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6760 if (per_cu
->is_debug_types
)
6762 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6764 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6765 &cu
->header
, section
,
6767 info_ptr
, rcuh_kind::TYPE
);
6768 /* This is not an assert because it can be caused by bad debug info. */
6769 if (sig_type
->signature
!= cu
->header
.signature
)
6771 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6772 " TU at offset %s [in module %s]"),
6773 hex_string (sig_type
->signature
),
6774 hex_string (cu
->header
.signature
),
6775 sect_offset_str (dwo_unit
->sect_off
),
6776 bfd_get_filename (abfd
));
6778 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6779 /* For DWOs coming from DWP files, we don't know the CU length
6780 nor the type's offset in the TU until now. */
6781 dwo_unit
->length
= cu
->header
.get_length ();
6782 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6784 /* Establish the type offset that can be used to lookup the type.
6785 For DWO files, we don't know it until now. */
6786 sig_type
->type_offset_in_section
6787 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6791 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6792 &cu
->header
, section
,
6794 info_ptr
, rcuh_kind::COMPILE
);
6795 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6796 /* For DWOs coming from DWP files, we don't know the CU length
6798 dwo_unit
->length
= cu
->header
.get_length ();
6801 *result_dwo_abbrev_table
6802 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6803 cu
->header
.abbrev_sect_off
);
6804 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6805 result_dwo_abbrev_table
->get ());
6807 /* Read in the die, but leave space to copy over the attributes
6808 from the stub. This has the benefit of simplifying the rest of
6809 the code - all the work to maintain the illusion of a single
6810 DW_TAG_{compile,type}_unit DIE is done here. */
6811 num_extra_attrs
= ((stmt_list
!= NULL
)
6815 + (comp_dir
!= NULL
));
6816 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6819 /* Copy over the attributes from the stub to the DIE we just read in. */
6820 comp_unit_die
= *result_comp_unit_die
;
6821 i
= comp_unit_die
->num_attrs
;
6822 if (stmt_list
!= NULL
)
6823 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6825 comp_unit_die
->attrs
[i
++] = *low_pc
;
6826 if (high_pc
!= NULL
)
6827 comp_unit_die
->attrs
[i
++] = *high_pc
;
6829 comp_unit_die
->attrs
[i
++] = *ranges
;
6830 if (comp_dir
!= NULL
)
6831 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6832 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6834 if (dwarf_die_debug
)
6836 fprintf_unfiltered (gdb_stdlog
,
6837 "Read die from %s@0x%x of %s:\n",
6838 section
->get_name (),
6839 (unsigned) (begin_info_ptr
- section
->buffer
),
6840 bfd_get_filename (abfd
));
6841 dump_die (comp_unit_die
, dwarf_die_debug
);
6844 /* Skip dummy compilation units. */
6845 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6846 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6849 *result_info_ptr
= info_ptr
;
6853 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6854 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6855 signature is part of the header. */
6856 static gdb::optional
<ULONGEST
>
6857 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6859 if (cu
->header
.version
>= 5)
6860 return cu
->header
.signature
;
6861 struct attribute
*attr
;
6862 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6863 if (attr
== nullptr)
6864 return gdb::optional
<ULONGEST
> ();
6865 return DW_UNSND (attr
);
6868 /* Subroutine of cutu_reader to simplify it.
6869 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6870 Returns NULL if the specified DWO unit cannot be found. */
6872 static struct dwo_unit
*
6873 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6875 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6876 struct dwo_unit
*dwo_unit
;
6877 const char *comp_dir
;
6879 gdb_assert (cu
!= NULL
);
6881 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6882 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6883 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6885 if (per_cu
->is_debug_types
)
6886 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6889 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6891 if (!signature
.has_value ())
6892 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6894 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6896 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6902 /* Subroutine of cutu_reader to simplify it.
6903 See it for a description of the parameters.
6904 Read a TU directly from a DWO file, bypassing the stub. */
6907 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6908 dwarf2_per_objfile
*per_objfile
,
6909 int use_existing_cu
)
6911 struct signatured_type
*sig_type
;
6913 /* Verify we can do the following downcast, and that we have the
6915 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6916 sig_type
= (struct signatured_type
*) this_cu
;
6917 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6919 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6921 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6922 /* There's no need to do the rereading_dwo_cu handling that
6923 cutu_reader does since we don't read the stub. */
6927 /* If !use_existing_cu, this_cu->cu must be NULL. */
6928 gdb_assert (this_cu
->cu
== NULL
);
6929 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6932 /* A future optimization, if needed, would be to use an existing
6933 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6934 could share abbrev tables. */
6936 if (read_cutu_die_from_dwo (this_cu
->cu
, sig_type
->dwo_unit
,
6937 NULL
/* stub_comp_unit_die */,
6938 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6941 &m_dwo_abbrev_table
) == 0)
6948 /* Initialize a CU (or TU) and read its DIEs.
6949 If the CU defers to a DWO file, read the DWO file as well.
6951 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6952 Otherwise the table specified in the comp unit header is read in and used.
6953 This is an optimization for when we already have the abbrev table.
6955 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6956 Otherwise, a new CU is allocated with xmalloc. */
6958 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6959 dwarf2_per_objfile
*dwarf2_per_objfile
,
6960 struct abbrev_table
*abbrev_table
,
6961 int use_existing_cu
,
6963 : die_reader_specs
{},
6966 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6967 struct dwarf2_section_info
*section
= this_cu
->section
;
6968 bfd
*abfd
= section
->get_bfd_owner ();
6969 struct dwarf2_cu
*cu
;
6970 const gdb_byte
*begin_info_ptr
;
6971 struct signatured_type
*sig_type
= NULL
;
6972 struct dwarf2_section_info
*abbrev_section
;
6973 /* Non-zero if CU currently points to a DWO file and we need to
6974 reread it. When this happens we need to reread the skeleton die
6975 before we can reread the DWO file (this only applies to CUs, not TUs). */
6976 int rereading_dwo_cu
= 0;
6978 if (dwarf_die_debug
)
6979 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6980 this_cu
->is_debug_types
? "type" : "comp",
6981 sect_offset_str (this_cu
->sect_off
));
6983 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6984 file (instead of going through the stub), short-circuit all of this. */
6985 if (this_cu
->reading_dwo_directly
)
6987 /* Narrow down the scope of possibilities to have to understand. */
6988 gdb_assert (this_cu
->is_debug_types
);
6989 gdb_assert (abbrev_table
== NULL
);
6990 init_tu_and_read_dwo_dies (this_cu
, dwarf2_per_objfile
, use_existing_cu
);
6994 /* This is cheap if the section is already read in. */
6995 section
->read (objfile
);
6997 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6999 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7001 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7004 /* If this CU is from a DWO file we need to start over, we need to
7005 refetch the attributes from the skeleton CU.
7006 This could be optimized by retrieving those attributes from when we
7007 were here the first time: the previous comp_unit_die was stored in
7008 comp_unit_obstack. But there's no data yet that we need this
7010 if (cu
->dwo_unit
!= NULL
)
7011 rereading_dwo_cu
= 1;
7015 /* If !use_existing_cu, this_cu->cu must be NULL. */
7016 gdb_assert (this_cu
->cu
== NULL
);
7017 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7018 cu
= m_new_cu
.get ();
7021 /* Get the header. */
7022 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7024 /* We already have the header, there's no need to read it in again. */
7025 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7029 if (this_cu
->is_debug_types
)
7031 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7032 &cu
->header
, section
,
7033 abbrev_section
, info_ptr
,
7036 /* Since per_cu is the first member of struct signatured_type,
7037 we can go from a pointer to one to a pointer to the other. */
7038 sig_type
= (struct signatured_type
*) this_cu
;
7039 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7040 gdb_assert (sig_type
->type_offset_in_tu
7041 == cu
->header
.type_cu_offset_in_tu
);
7042 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7044 /* LENGTH has not been set yet for type units if we're
7045 using .gdb_index. */
7046 this_cu
->length
= cu
->header
.get_length ();
7048 /* Establish the type offset that can be used to lookup the type. */
7049 sig_type
->type_offset_in_section
=
7050 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7052 this_cu
->dwarf_version
= cu
->header
.version
;
7056 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7057 &cu
->header
, section
,
7060 rcuh_kind::COMPILE
);
7062 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7063 if (this_cu
->length
== 0)
7064 this_cu
->length
= cu
->header
.get_length ();
7066 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7067 this_cu
->dwarf_version
= cu
->header
.version
;
7071 /* Skip dummy compilation units. */
7072 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7073 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7079 /* If we don't have them yet, read the abbrevs for this compilation unit.
7080 And if we need to read them now, make sure they're freed when we're
7082 if (abbrev_table
!= NULL
)
7083 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7086 m_abbrev_table_holder
7087 = abbrev_table::read (objfile
, abbrev_section
,
7088 cu
->header
.abbrev_sect_off
);
7089 abbrev_table
= m_abbrev_table_holder
.get ();
7092 /* Read the top level CU/TU die. */
7093 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7094 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7096 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7102 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7103 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7104 table from the DWO file and pass the ownership over to us. It will be
7105 referenced from READER, so we must make sure to free it after we're done
7108 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7109 DWO CU, that this test will fail (the attribute will not be present). */
7110 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7111 if (dwo_name
!= nullptr)
7113 struct dwo_unit
*dwo_unit
;
7114 struct die_info
*dwo_comp_unit_die
;
7116 if (comp_unit_die
->has_children
)
7118 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7119 " has children (offset %s) [in module %s]"),
7120 sect_offset_str (this_cu
->sect_off
),
7121 bfd_get_filename (abfd
));
7123 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7124 if (dwo_unit
!= NULL
)
7126 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7127 comp_unit_die
, NULL
,
7130 &m_dwo_abbrev_table
) == 0)
7136 comp_unit_die
= dwo_comp_unit_die
;
7140 /* Yikes, we couldn't find the rest of the DIE, we only have
7141 the stub. A complaint has already been logged. There's
7142 not much more we can do except pass on the stub DIE to
7143 die_reader_func. We don't want to throw an error on bad
7150 cutu_reader::keep ()
7152 /* Done, clean up. */
7153 gdb_assert (!dummy_p
);
7154 if (m_new_cu
!= NULL
)
7156 /* We know that m_this_cu->cu is set, since we are in the process of
7158 gdb_assert (m_this_cu
->cu
!= nullptr);
7159 dwarf2_per_objfile
*dwarf2_per_objfile
= m_this_cu
->cu
->per_objfile
;
7161 /* Link this CU into read_in_chain. */
7162 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
7163 dwarf2_per_objfile
->per_bfd
->read_in_chain
= m_this_cu
;
7164 /* The chain owns it now. */
7165 m_new_cu
.release ();
7169 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7170 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7171 assumed to have already done the lookup to find the DWO file).
7173 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7174 THIS_CU->is_debug_types, but nothing else.
7176 We fill in THIS_CU->length.
7178 THIS_CU->cu is always freed when done.
7179 This is done in order to not leave THIS_CU->cu in a state where we have
7180 to care whether it refers to the "main" CU or the DWO CU.
7182 When parent_cu is passed, it is used to provide a default value for
7183 str_offsets_base and addr_base from the parent. */
7185 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7186 dwarf2_per_objfile
*dwarf2_per_objfile
,
7187 struct dwarf2_cu
*parent_cu
,
7188 struct dwo_file
*dwo_file
)
7189 : die_reader_specs
{},
7192 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7193 struct dwarf2_section_info
*section
= this_cu
->section
;
7194 bfd
*abfd
= section
->get_bfd_owner ();
7195 struct dwarf2_section_info
*abbrev_section
;
7196 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7198 if (dwarf_die_debug
)
7199 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7200 this_cu
->is_debug_types
? "type" : "comp",
7201 sect_offset_str (this_cu
->sect_off
));
7203 gdb_assert (this_cu
->cu
== NULL
);
7205 abbrev_section
= (dwo_file
!= NULL
7206 ? &dwo_file
->sections
.abbrev
7207 : get_abbrev_section_for_cu (this_cu
));
7209 /* This is cheap if the section is already read in. */
7210 section
->read (objfile
);
7212 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7214 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7215 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7216 &m_new_cu
->header
, section
,
7217 abbrev_section
, info_ptr
,
7218 (this_cu
->is_debug_types
7220 : rcuh_kind::COMPILE
));
7222 if (parent_cu
!= nullptr)
7224 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7225 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7227 this_cu
->length
= m_new_cu
->header
.get_length ();
7229 /* Skip dummy compilation units. */
7230 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7231 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7237 m_abbrev_table_holder
7238 = abbrev_table::read (objfile
, abbrev_section
,
7239 m_new_cu
->header
.abbrev_sect_off
);
7241 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7242 m_abbrev_table_holder
.get ());
7243 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7247 /* Type Unit Groups.
7249 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7250 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7251 so that all types coming from the same compilation (.o file) are grouped
7252 together. A future step could be to put the types in the same symtab as
7253 the CU the types ultimately came from. */
7256 hash_type_unit_group (const void *item
)
7258 const struct type_unit_group
*tu_group
7259 = (const struct type_unit_group
*) item
;
7261 return hash_stmt_list_entry (&tu_group
->hash
);
7265 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7267 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7268 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7270 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7273 /* Allocate a hash table for type unit groups. */
7276 allocate_type_unit_groups_table ()
7278 return htab_up (htab_create_alloc (3,
7279 hash_type_unit_group
,
7281 NULL
, xcalloc
, xfree
));
7284 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7285 partial symtabs. We combine several TUs per psymtab to not let the size
7286 of any one psymtab grow too big. */
7287 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7288 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7290 /* Helper routine for get_type_unit_group.
7291 Create the type_unit_group object used to hold one or more TUs. */
7293 static struct type_unit_group
*
7294 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7296 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7297 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
7298 struct dwarf2_per_cu_data
*per_cu
;
7299 struct type_unit_group
*tu_group
;
7301 tu_group
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
7302 struct type_unit_group
);
7303 per_cu
= &tu_group
->per_cu
;
7304 per_cu
->per_bfd
= per_bfd
;
7306 if (per_bfd
->using_index
)
7308 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7309 struct dwarf2_per_cu_quick_data
);
7313 unsigned int line_offset
= to_underlying (line_offset_struct
);
7314 dwarf2_psymtab
*pst
;
7317 /* Give the symtab a useful name for debug purposes. */
7318 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7319 name
= string_printf ("<type_units_%d>",
7320 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7322 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7324 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, name
.c_str ());
7325 pst
->anonymous
= true;
7328 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7329 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7334 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7335 STMT_LIST is a DW_AT_stmt_list attribute. */
7337 static struct type_unit_group
*
7338 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7340 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7341 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7342 struct type_unit_group
*tu_group
;
7344 unsigned int line_offset
;
7345 struct type_unit_group type_unit_group_for_lookup
;
7347 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7348 dwarf2_per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7350 /* Do we need to create a new group, or can we use an existing one? */
7354 line_offset
= DW_UNSND (stmt_list
);
7355 ++tu_stats
->nr_symtab_sharers
;
7359 /* Ugh, no stmt_list. Rare, but we have to handle it.
7360 We can do various things here like create one group per TU or
7361 spread them over multiple groups to split up the expansion work.
7362 To avoid worst case scenarios (too many groups or too large groups)
7363 we, umm, group them in bunches. */
7364 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7365 | (tu_stats
->nr_stmt_less_type_units
7366 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7367 ++tu_stats
->nr_stmt_less_type_units
;
7370 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7371 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7372 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7373 &type_unit_group_for_lookup
, INSERT
);
7376 tu_group
= (struct type_unit_group
*) *slot
;
7377 gdb_assert (tu_group
!= NULL
);
7381 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7382 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7384 ++tu_stats
->nr_symtabs
;
7390 /* Partial symbol tables. */
7392 /* Create a psymtab named NAME and assign it to PER_CU.
7394 The caller must fill in the following details:
7395 dirname, textlow, texthigh. */
7397 static dwarf2_psymtab
*
7398 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7399 dwarf2_per_objfile
*per_objfile
,
7402 struct objfile
*objfile
= per_objfile
->objfile
;
7403 dwarf2_psymtab
*pst
;
7405 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7407 pst
->psymtabs_addrmap_supported
= true;
7409 /* This is the glue that links PST into GDB's symbol API. */
7410 per_cu
->v
.psymtab
= pst
;
7415 /* DIE reader function for process_psymtab_comp_unit. */
7418 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7419 const gdb_byte
*info_ptr
,
7420 struct die_info
*comp_unit_die
,
7421 enum language pretend_language
)
7423 struct dwarf2_cu
*cu
= reader
->cu
;
7424 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7425 struct objfile
*objfile
= per_objfile
->objfile
;
7426 struct gdbarch
*gdbarch
= objfile
->arch ();
7427 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7429 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7430 dwarf2_psymtab
*pst
;
7431 enum pc_bounds_kind cu_bounds_kind
;
7432 const char *filename
;
7434 gdb_assert (! per_cu
->is_debug_types
);
7436 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7438 /* Allocate a new partial symbol table structure. */
7439 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7440 static const char artificial
[] = "<artificial>";
7441 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7442 if (filename
== NULL
)
7444 else if (strcmp (filename
, artificial
) == 0)
7446 debug_filename
.reset (concat (artificial
, "@",
7447 sect_offset_str (per_cu
->sect_off
),
7449 filename
= debug_filename
.get ();
7452 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7454 /* This must be done before calling dwarf2_build_include_psymtabs. */
7455 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7457 baseaddr
= objfile
->text_section_offset ();
7459 dwarf2_find_base_address (comp_unit_die
, cu
);
7461 /* Possibly set the default values of LOWPC and HIGHPC from
7463 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7464 &best_highpc
, cu
, pst
);
7465 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7468 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7471 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7473 /* Store the contiguous range if it is not empty; it can be
7474 empty for CUs with no code. */
7475 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7479 /* Check if comp unit has_children.
7480 If so, read the rest of the partial symbols from this comp unit.
7481 If not, there's no more debug_info for this comp unit. */
7482 if (comp_unit_die
->has_children
)
7484 struct partial_die_info
*first_die
;
7485 CORE_ADDR lowpc
, highpc
;
7487 lowpc
= ((CORE_ADDR
) -1);
7488 highpc
= ((CORE_ADDR
) 0);
7490 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7492 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7493 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7495 /* If we didn't find a lowpc, set it to highpc to avoid
7496 complaints from `maint check'. */
7497 if (lowpc
== ((CORE_ADDR
) -1))
7500 /* If the compilation unit didn't have an explicit address range,
7501 then use the information extracted from its child dies. */
7502 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7505 best_highpc
= highpc
;
7508 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7509 best_lowpc
+ baseaddr
)
7511 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7512 best_highpc
+ baseaddr
)
7515 end_psymtab_common (objfile
, pst
);
7517 if (!cu
->per_cu
->imported_symtabs_empty ())
7520 int len
= cu
->per_cu
->imported_symtabs_size ();
7522 /* Fill in 'dependencies' here; we fill in 'users' in a
7524 pst
->number_of_dependencies
= len
;
7526 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7527 for (i
= 0; i
< len
; ++i
)
7529 pst
->dependencies
[i
]
7530 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7533 cu
->per_cu
->imported_symtabs_free ();
7536 /* Get the list of files included in the current compilation unit,
7537 and build a psymtab for each of them. */
7538 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7540 if (dwarf_read_debug
)
7541 fprintf_unfiltered (gdb_stdlog
,
7542 "Psymtab for %s unit @%s: %s - %s"
7543 ", %d global, %d static syms\n",
7544 per_cu
->is_debug_types
? "type" : "comp",
7545 sect_offset_str (per_cu
->sect_off
),
7546 paddress (gdbarch
, pst
->text_low (objfile
)),
7547 paddress (gdbarch
, pst
->text_high (objfile
)),
7548 pst
->n_global_syms
, pst
->n_static_syms
);
7551 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7552 Process compilation unit THIS_CU for a psymtab. */
7555 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7556 dwarf2_per_objfile
*per_objfile
,
7557 bool want_partial_unit
,
7558 enum language pretend_language
)
7560 /* If this compilation unit was already read in, free the
7561 cached copy in order to read it in again. This is
7562 necessary because we skipped some symbols when we first
7563 read in the compilation unit (see load_partial_dies).
7564 This problem could be avoided, but the benefit is unclear. */
7565 if (this_cu
->cu
!= NULL
)
7566 free_one_cached_comp_unit (this_cu
, per_objfile
);
7568 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 0, false);
7570 switch (reader
.comp_unit_die
->tag
)
7572 case DW_TAG_compile_unit
:
7573 this_cu
->unit_type
= DW_UT_compile
;
7575 case DW_TAG_partial_unit
:
7576 this_cu
->unit_type
= DW_UT_partial
;
7586 else if (this_cu
->is_debug_types
)
7587 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7588 reader
.comp_unit_die
);
7589 else if (want_partial_unit
7590 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7591 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7592 reader
.comp_unit_die
,
7595 this_cu
->lang
= this_cu
->cu
->language
;
7597 /* Age out any secondary CUs. */
7598 age_cached_comp_units (per_objfile
);
7601 /* Reader function for build_type_psymtabs. */
7604 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7605 const gdb_byte
*info_ptr
,
7606 struct die_info
*type_unit_die
)
7608 struct dwarf2_per_objfile
*dwarf2_per_objfile
= reader
->cu
->per_objfile
;
7609 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7610 struct dwarf2_cu
*cu
= reader
->cu
;
7611 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7612 struct signatured_type
*sig_type
;
7613 struct type_unit_group
*tu_group
;
7614 struct attribute
*attr
;
7615 struct partial_die_info
*first_die
;
7616 CORE_ADDR lowpc
, highpc
;
7617 dwarf2_psymtab
*pst
;
7619 gdb_assert (per_cu
->is_debug_types
);
7620 sig_type
= (struct signatured_type
*) per_cu
;
7622 if (! type_unit_die
->has_children
)
7625 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7626 tu_group
= get_type_unit_group (cu
, attr
);
7628 if (tu_group
->tus
== nullptr)
7629 tu_group
->tus
= new std::vector
<signatured_type
*>;
7630 tu_group
->tus
->push_back (sig_type
);
7632 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7633 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, "");
7634 pst
->anonymous
= true;
7636 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7638 lowpc
= (CORE_ADDR
) -1;
7639 highpc
= (CORE_ADDR
) 0;
7640 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7642 end_psymtab_common (objfile
, pst
);
7645 /* Struct used to sort TUs by their abbreviation table offset. */
7647 struct tu_abbrev_offset
7649 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7650 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7653 signatured_type
*sig_type
;
7654 sect_offset abbrev_offset
;
7657 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7660 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7661 const struct tu_abbrev_offset
&b
)
7663 return a
.abbrev_offset
< b
.abbrev_offset
;
7666 /* Efficiently read all the type units.
7667 This does the bulk of the work for build_type_psymtabs.
7669 The efficiency is because we sort TUs by the abbrev table they use and
7670 only read each abbrev table once. In one program there are 200K TUs
7671 sharing 8K abbrev tables.
7673 The main purpose of this function is to support building the
7674 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7675 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7676 can collapse the search space by grouping them by stmt_list.
7677 The savings can be significant, in the same program from above the 200K TUs
7678 share 8K stmt_list tables.
7680 FUNC is expected to call get_type_unit_group, which will create the
7681 struct type_unit_group if necessary and add it to
7682 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7685 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7687 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7688 abbrev_table_up abbrev_table
;
7689 sect_offset abbrev_offset
;
7691 /* It's up to the caller to not call us multiple times. */
7692 gdb_assert (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7694 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ())
7697 /* TUs typically share abbrev tables, and there can be way more TUs than
7698 abbrev tables. Sort by abbrev table to reduce the number of times we
7699 read each abbrev table in.
7700 Alternatives are to punt or to maintain a cache of abbrev tables.
7701 This is simpler and efficient enough for now.
7703 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7704 symtab to use). Typically TUs with the same abbrev offset have the same
7705 stmt_list value too so in practice this should work well.
7707 The basic algorithm here is:
7709 sort TUs by abbrev table
7710 for each TU with same abbrev table:
7711 read abbrev table if first user
7712 read TU top level DIE
7713 [IWBN if DWO skeletons had DW_AT_stmt_list]
7716 if (dwarf_read_debug
)
7717 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7719 /* Sort in a separate table to maintain the order of all_type_units
7720 for .gdb_index: TU indices directly index all_type_units. */
7721 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7722 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7724 for (signatured_type
*sig_type
: dwarf2_per_objfile
->per_bfd
->all_type_units
)
7725 sorted_by_abbrev
.emplace_back
7726 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7727 sig_type
->per_cu
.section
,
7728 sig_type
->per_cu
.sect_off
));
7730 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7731 sort_tu_by_abbrev_offset
);
7733 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7735 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7737 /* Switch to the next abbrev table if necessary. */
7738 if (abbrev_table
== NULL
7739 || tu
.abbrev_offset
!= abbrev_offset
)
7741 abbrev_offset
= tu
.abbrev_offset
;
7743 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7744 &dwarf2_per_objfile
->per_bfd
->abbrev
,
7746 ++tu_stats
->nr_uniq_abbrev_tables
;
7749 cutu_reader
reader (&tu
.sig_type
->per_cu
, dwarf2_per_objfile
,
7750 abbrev_table
.get (), 0, false);
7751 if (!reader
.dummy_p
)
7752 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7753 reader
.comp_unit_die
);
7757 /* Print collected type unit statistics. */
7760 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7762 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7764 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7765 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7766 dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7767 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7768 tu_stats
->nr_uniq_abbrev_tables
);
7769 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7770 tu_stats
->nr_symtabs
);
7771 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7772 tu_stats
->nr_symtab_sharers
);
7773 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7774 tu_stats
->nr_stmt_less_type_units
);
7775 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7776 tu_stats
->nr_all_type_units_reallocs
);
7779 /* Traversal function for build_type_psymtabs. */
7782 build_type_psymtab_dependencies (void **slot
, void *info
)
7784 struct dwarf2_per_objfile
*dwarf2_per_objfile
7785 = (struct dwarf2_per_objfile
*) info
;
7786 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7787 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7788 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7789 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7790 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7793 gdb_assert (len
> 0);
7794 gdb_assert (per_cu
->type_unit_group_p ());
7796 pst
->number_of_dependencies
= len
;
7797 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7798 for (i
= 0; i
< len
; ++i
)
7800 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7801 gdb_assert (iter
->per_cu
.is_debug_types
);
7802 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7803 iter
->type_unit_group
= tu_group
;
7806 delete tu_group
->tus
;
7807 tu_group
->tus
= nullptr;
7812 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7813 Build partial symbol tables for the .debug_types comp-units. */
7816 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7818 if (! create_all_type_units (dwarf2_per_objfile
))
7821 build_type_psymtabs_1 (dwarf2_per_objfile
);
7824 /* Traversal function for process_skeletonless_type_unit.
7825 Read a TU in a DWO file and build partial symbols for it. */
7828 process_skeletonless_type_unit (void **slot
, void *info
)
7830 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7831 struct dwarf2_per_objfile
*dwarf2_per_objfile
7832 = (struct dwarf2_per_objfile
*) info
;
7833 struct signatured_type find_entry
, *entry
;
7835 /* If this TU doesn't exist in the global table, add it and read it in. */
7837 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
7838 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7840 find_entry
.signature
= dwo_unit
->signature
;
7841 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
7842 &find_entry
, INSERT
);
7843 /* If we've already seen this type there's nothing to do. What's happening
7844 is we're doing our own version of comdat-folding here. */
7848 /* This does the job that create_all_type_units would have done for
7850 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7851 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7854 /* This does the job that build_type_psymtabs_1 would have done. */
7855 cutu_reader
reader (&entry
->per_cu
, dwarf2_per_objfile
, NULL
, 0, false);
7856 if (!reader
.dummy_p
)
7857 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7858 reader
.comp_unit_die
);
7863 /* Traversal function for process_skeletonless_type_units. */
7866 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7868 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7870 if (dwo_file
->tus
!= NULL
)
7871 htab_traverse_noresize (dwo_file
->tus
.get (),
7872 process_skeletonless_type_unit
, info
);
7877 /* Scan all TUs of DWO files, verifying we've processed them.
7878 This is needed in case a TU was emitted without its skeleton.
7879 Note: This can't be done until we know what all the DWO files are. */
7882 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7884 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7885 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7886 && dwarf2_per_objfile
->per_bfd
->dwo_files
!= NULL
)
7888 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (),
7889 process_dwo_file_for_skeletonless_type_units
,
7890 dwarf2_per_objfile
);
7894 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7897 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7899 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7901 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7906 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7908 /* Set the 'user' field only if it is not already set. */
7909 if (pst
->dependencies
[j
]->user
== NULL
)
7910 pst
->dependencies
[j
]->user
= pst
;
7915 /* Build the partial symbol table by doing a quick pass through the
7916 .debug_info and .debug_abbrev sections. */
7919 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7921 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7923 if (dwarf_read_debug
)
7925 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7926 objfile_name (objfile
));
7929 scoped_restore restore_reading_psyms
7930 = make_scoped_restore (&dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
,
7933 dwarf2_per_objfile
->per_bfd
->info
.read (objfile
);
7935 /* Any cached compilation units will be linked by the per-objfile
7936 read_in_chain. Make sure to free them when we're done. */
7937 free_cached_comp_units
freer (dwarf2_per_objfile
);
7939 build_type_psymtabs (dwarf2_per_objfile
);
7941 create_all_comp_units (dwarf2_per_objfile
);
7943 /* Create a temporary address map on a temporary obstack. We later
7944 copy this to the final obstack. */
7945 auto_obstack temp_obstack
;
7947 scoped_restore save_psymtabs_addrmap
7948 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7949 addrmap_create_mutable (&temp_obstack
));
7951 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7953 if (per_cu
->v
.psymtab
!= NULL
)
7954 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7956 process_psymtab_comp_unit (per_cu
, dwarf2_per_objfile
, false,
7960 /* This has to wait until we read the CUs, we need the list of DWOs. */
7961 process_skeletonless_type_units (dwarf2_per_objfile
);
7963 /* Now that all TUs have been processed we can fill in the dependencies. */
7964 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
7966 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7967 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7970 if (dwarf_read_debug
)
7971 print_tu_stats (dwarf2_per_objfile
);
7973 set_partial_user (dwarf2_per_objfile
);
7975 objfile
->partial_symtabs
->psymtabs_addrmap
7976 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7977 objfile
->partial_symtabs
->obstack ());
7978 /* At this point we want to keep the address map. */
7979 save_psymtabs_addrmap
.release ();
7981 if (dwarf_read_debug
)
7982 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7983 objfile_name (objfile
));
7986 /* Load the partial DIEs for a secondary CU into memory.
7987 This is also used when rereading a primary CU with load_all_dies. */
7990 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7991 dwarf2_per_objfile
*per_objfile
)
7993 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 1, false);
7995 if (!reader
.dummy_p
)
7997 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8000 /* Check if comp unit has_children.
8001 If so, read the rest of the partial symbols from this comp unit.
8002 If not, there's no more debug_info for this comp unit. */
8003 if (reader
.comp_unit_die
->has_children
)
8004 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8011 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8012 struct dwarf2_section_info
*section
,
8013 struct dwarf2_section_info
*abbrev_section
,
8014 unsigned int is_dwz
)
8016 const gdb_byte
*info_ptr
;
8017 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8019 if (dwarf_read_debug
)
8020 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8021 section
->get_name (),
8022 section
->get_file_name ());
8024 section
->read (objfile
);
8026 info_ptr
= section
->buffer
;
8028 while (info_ptr
< section
->buffer
+ section
->size
)
8030 struct dwarf2_per_cu_data
*this_cu
;
8032 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8034 comp_unit_head cu_header
;
8035 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8036 abbrev_section
, info_ptr
,
8037 rcuh_kind::COMPILE
);
8039 /* Save the compilation unit for later lookup. */
8040 if (cu_header
.unit_type
!= DW_UT_type
)
8041 this_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
8044 auto sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
8045 sig_type
->signature
= cu_header
.signature
;
8046 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8047 this_cu
= &sig_type
->per_cu
;
8049 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8050 this_cu
->sect_off
= sect_off
;
8051 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8052 this_cu
->is_dwz
= is_dwz
;
8053 this_cu
->section
= section
;
8055 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8057 info_ptr
= info_ptr
+ this_cu
->length
;
8061 /* Create a list of all compilation units in OBJFILE.
8062 This is only done for -readnow and building partial symtabs. */
8065 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8067 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
8068 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->per_bfd
->info
,
8069 &dwarf2_per_objfile
->per_bfd
->abbrev
, 0);
8071 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
8073 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8077 /* Process all loaded DIEs for compilation unit CU, starting at
8078 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8079 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8080 DW_AT_ranges). See the comments of add_partial_subprogram on how
8081 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8084 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8085 CORE_ADDR
*highpc
, int set_addrmap
,
8086 struct dwarf2_cu
*cu
)
8088 struct partial_die_info
*pdi
;
8090 /* Now, march along the PDI's, descending into ones which have
8091 interesting children but skipping the children of the other ones,
8092 until we reach the end of the compilation unit. */
8100 /* Anonymous namespaces or modules have no name but have interesting
8101 children, so we need to look at them. Ditto for anonymous
8104 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8105 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8106 || pdi
->tag
== DW_TAG_imported_unit
8107 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8111 case DW_TAG_subprogram
:
8112 case DW_TAG_inlined_subroutine
:
8113 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8115 case DW_TAG_constant
:
8116 case DW_TAG_variable
:
8117 case DW_TAG_typedef
:
8118 case DW_TAG_union_type
:
8119 if (!pdi
->is_declaration
8120 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8122 add_partial_symbol (pdi
, cu
);
8125 case DW_TAG_class_type
:
8126 case DW_TAG_interface_type
:
8127 case DW_TAG_structure_type
:
8128 if (!pdi
->is_declaration
)
8130 add_partial_symbol (pdi
, cu
);
8132 if ((cu
->language
== language_rust
8133 || cu
->language
== language_cplus
) && pdi
->has_children
)
8134 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8137 case DW_TAG_enumeration_type
:
8138 if (!pdi
->is_declaration
)
8139 add_partial_enumeration (pdi
, cu
);
8141 case DW_TAG_base_type
:
8142 case DW_TAG_subrange_type
:
8143 /* File scope base type definitions are added to the partial
8145 add_partial_symbol (pdi
, cu
);
8147 case DW_TAG_namespace
:
8148 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8151 if (!pdi
->is_declaration
)
8152 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8154 case DW_TAG_imported_unit
:
8156 struct dwarf2_per_cu_data
*per_cu
;
8158 /* For now we don't handle imported units in type units. */
8159 if (cu
->per_cu
->is_debug_types
)
8161 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8162 " supported in type units [in module %s]"),
8163 objfile_name (cu
->per_objfile
->objfile
));
8166 per_cu
= dwarf2_find_containing_comp_unit
8167 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8169 /* Go read the partial unit, if needed. */
8170 if (per_cu
->v
.psymtab
== NULL
)
8171 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8174 cu
->per_cu
->imported_symtabs_push (per_cu
);
8177 case DW_TAG_imported_declaration
:
8178 add_partial_symbol (pdi
, cu
);
8185 /* If the die has a sibling, skip to the sibling. */
8187 pdi
= pdi
->die_sibling
;
8191 /* Functions used to compute the fully scoped name of a partial DIE.
8193 Normally, this is simple. For C++, the parent DIE's fully scoped
8194 name is concatenated with "::" and the partial DIE's name.
8195 Enumerators are an exception; they use the scope of their parent
8196 enumeration type, i.e. the name of the enumeration type is not
8197 prepended to the enumerator.
8199 There are two complexities. One is DW_AT_specification; in this
8200 case "parent" means the parent of the target of the specification,
8201 instead of the direct parent of the DIE. The other is compilers
8202 which do not emit DW_TAG_namespace; in this case we try to guess
8203 the fully qualified name of structure types from their members'
8204 linkage names. This must be done using the DIE's children rather
8205 than the children of any DW_AT_specification target. We only need
8206 to do this for structures at the top level, i.e. if the target of
8207 any DW_AT_specification (if any; otherwise the DIE itself) does not
8210 /* Compute the scope prefix associated with PDI's parent, in
8211 compilation unit CU. The result will be allocated on CU's
8212 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8213 field. NULL is returned if no prefix is necessary. */
8215 partial_die_parent_scope (struct partial_die_info
*pdi
,
8216 struct dwarf2_cu
*cu
)
8218 const char *grandparent_scope
;
8219 struct partial_die_info
*parent
, *real_pdi
;
8221 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8222 then this means the parent of the specification DIE. */
8225 while (real_pdi
->has_specification
)
8227 auto res
= find_partial_die (real_pdi
->spec_offset
,
8228 real_pdi
->spec_is_dwz
, cu
);
8233 parent
= real_pdi
->die_parent
;
8237 if (parent
->scope_set
)
8238 return parent
->scope
;
8242 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8244 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8245 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8246 Work around this problem here. */
8247 if (cu
->language
== language_cplus
8248 && parent
->tag
== DW_TAG_namespace
8249 && strcmp (parent
->name
, "::") == 0
8250 && grandparent_scope
== NULL
)
8252 parent
->scope
= NULL
;
8253 parent
->scope_set
= 1;
8257 /* Nested subroutines in Fortran get a prefix. */
8258 if (pdi
->tag
== DW_TAG_enumerator
)
8259 /* Enumerators should not get the name of the enumeration as a prefix. */
8260 parent
->scope
= grandparent_scope
;
8261 else if (parent
->tag
== DW_TAG_namespace
8262 || parent
->tag
== DW_TAG_module
8263 || parent
->tag
== DW_TAG_structure_type
8264 || parent
->tag
== DW_TAG_class_type
8265 || parent
->tag
== DW_TAG_interface_type
8266 || parent
->tag
== DW_TAG_union_type
8267 || parent
->tag
== DW_TAG_enumeration_type
8268 || (cu
->language
== language_fortran
8269 && parent
->tag
== DW_TAG_subprogram
8270 && pdi
->tag
== DW_TAG_subprogram
))
8272 if (grandparent_scope
== NULL
)
8273 parent
->scope
= parent
->name
;
8275 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8277 parent
->name
, 0, cu
);
8281 /* FIXME drow/2004-04-01: What should we be doing with
8282 function-local names? For partial symbols, we should probably be
8284 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8285 dwarf_tag_name (parent
->tag
),
8286 sect_offset_str (pdi
->sect_off
));
8287 parent
->scope
= grandparent_scope
;
8290 parent
->scope_set
= 1;
8291 return parent
->scope
;
8294 /* Return the fully scoped name associated with PDI, from compilation unit
8295 CU. The result will be allocated with malloc. */
8297 static gdb::unique_xmalloc_ptr
<char>
8298 partial_die_full_name (struct partial_die_info
*pdi
,
8299 struct dwarf2_cu
*cu
)
8301 const char *parent_scope
;
8303 /* If this is a template instantiation, we can not work out the
8304 template arguments from partial DIEs. So, unfortunately, we have
8305 to go through the full DIEs. At least any work we do building
8306 types here will be reused if full symbols are loaded later. */
8307 if (pdi
->has_template_arguments
)
8311 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8313 struct die_info
*die
;
8314 struct attribute attr
;
8315 struct dwarf2_cu
*ref_cu
= cu
;
8317 /* DW_FORM_ref_addr is using section offset. */
8318 attr
.name
= (enum dwarf_attribute
) 0;
8319 attr
.form
= DW_FORM_ref_addr
;
8320 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8321 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8323 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8327 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8328 if (parent_scope
== NULL
)
8331 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8336 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8338 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
8339 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8340 struct gdbarch
*gdbarch
= objfile
->arch ();
8342 const char *actual_name
= NULL
;
8345 baseaddr
= objfile
->text_section_offset ();
8347 gdb::unique_xmalloc_ptr
<char> built_actual_name
8348 = partial_die_full_name (pdi
, cu
);
8349 if (built_actual_name
!= NULL
)
8350 actual_name
= built_actual_name
.get ();
8352 if (actual_name
== NULL
)
8353 actual_name
= pdi
->name
;
8355 partial_symbol psymbol
;
8356 memset (&psymbol
, 0, sizeof (psymbol
));
8357 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8358 psymbol
.ginfo
.section
= -1;
8360 /* The code below indicates that the psymbol should be installed by
8362 gdb::optional
<psymbol_placement
> where
;
8366 case DW_TAG_inlined_subroutine
:
8367 case DW_TAG_subprogram
:
8368 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8370 if (pdi
->is_external
8371 || cu
->language
== language_ada
8372 || (cu
->language
== language_fortran
8373 && pdi
->die_parent
!= NULL
8374 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8376 /* Normally, only "external" DIEs are part of the global scope.
8377 But in Ada and Fortran, we want to be able to access nested
8378 procedures globally. So all Ada and Fortran subprograms are
8379 stored in the global scope. */
8380 where
= psymbol_placement::GLOBAL
;
8383 where
= psymbol_placement::STATIC
;
8385 psymbol
.domain
= VAR_DOMAIN
;
8386 psymbol
.aclass
= LOC_BLOCK
;
8387 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8388 psymbol
.ginfo
.value
.address
= addr
;
8390 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8391 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8393 case DW_TAG_constant
:
8394 psymbol
.domain
= VAR_DOMAIN
;
8395 psymbol
.aclass
= LOC_STATIC
;
8396 where
= (pdi
->is_external
8397 ? psymbol_placement::GLOBAL
8398 : psymbol_placement::STATIC
);
8400 case DW_TAG_variable
:
8402 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8406 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
8408 /* A global or static variable may also have been stripped
8409 out by the linker if unused, in which case its address
8410 will be nullified; do not add such variables into partial
8411 symbol table then. */
8413 else if (pdi
->is_external
)
8416 Don't enter into the minimal symbol tables as there is
8417 a minimal symbol table entry from the ELF symbols already.
8418 Enter into partial symbol table if it has a location
8419 descriptor or a type.
8420 If the location descriptor is missing, new_symbol will create
8421 a LOC_UNRESOLVED symbol, the address of the variable will then
8422 be determined from the minimal symbol table whenever the variable
8424 The address for the partial symbol table entry is not
8425 used by GDB, but it comes in handy for debugging partial symbol
8428 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8430 psymbol
.domain
= VAR_DOMAIN
;
8431 psymbol
.aclass
= LOC_STATIC
;
8432 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8433 psymbol
.ginfo
.value
.address
= addr
;
8434 where
= psymbol_placement::GLOBAL
;
8439 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8441 /* Static Variable. Skip symbols whose value we cannot know (those
8442 without location descriptors or constant values). */
8443 if (!has_loc
&& !pdi
->has_const_value
)
8446 psymbol
.domain
= VAR_DOMAIN
;
8447 psymbol
.aclass
= LOC_STATIC
;
8448 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8450 psymbol
.ginfo
.value
.address
= addr
;
8451 where
= psymbol_placement::STATIC
;
8454 case DW_TAG_typedef
:
8455 case DW_TAG_base_type
:
8456 case DW_TAG_subrange_type
:
8457 psymbol
.domain
= VAR_DOMAIN
;
8458 psymbol
.aclass
= LOC_TYPEDEF
;
8459 where
= psymbol_placement::STATIC
;
8461 case DW_TAG_imported_declaration
:
8462 case DW_TAG_namespace
:
8463 psymbol
.domain
= VAR_DOMAIN
;
8464 psymbol
.aclass
= LOC_TYPEDEF
;
8465 where
= psymbol_placement::GLOBAL
;
8468 /* With Fortran 77 there might be a "BLOCK DATA" module
8469 available without any name. If so, we skip the module as it
8470 doesn't bring any value. */
8471 if (actual_name
!= nullptr)
8473 psymbol
.domain
= MODULE_DOMAIN
;
8474 psymbol
.aclass
= LOC_TYPEDEF
;
8475 where
= psymbol_placement::GLOBAL
;
8478 case DW_TAG_class_type
:
8479 case DW_TAG_interface_type
:
8480 case DW_TAG_structure_type
:
8481 case DW_TAG_union_type
:
8482 case DW_TAG_enumeration_type
:
8483 /* Skip external references. The DWARF standard says in the section
8484 about "Structure, Union, and Class Type Entries": "An incomplete
8485 structure, union or class type is represented by a structure,
8486 union or class entry that does not have a byte size attribute
8487 and that has a DW_AT_declaration attribute." */
8488 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8491 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8492 static vs. global. */
8493 psymbol
.domain
= STRUCT_DOMAIN
;
8494 psymbol
.aclass
= LOC_TYPEDEF
;
8495 where
= (cu
->language
== language_cplus
8496 ? psymbol_placement::GLOBAL
8497 : psymbol_placement::STATIC
);
8499 case DW_TAG_enumerator
:
8500 psymbol
.domain
= VAR_DOMAIN
;
8501 psymbol
.aclass
= LOC_CONST
;
8502 where
= (cu
->language
== language_cplus
8503 ? psymbol_placement::GLOBAL
8504 : psymbol_placement::STATIC
);
8510 if (where
.has_value ())
8512 if (built_actual_name
!= nullptr)
8513 actual_name
= objfile
->intern (actual_name
);
8514 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8515 psymbol
.ginfo
.set_linkage_name (actual_name
);
8518 psymbol
.ginfo
.set_demangled_name (actual_name
,
8519 &objfile
->objfile_obstack
);
8520 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8522 add_psymbol_to_list (psymbol
, *where
, objfile
);
8526 /* Read a partial die corresponding to a namespace; also, add a symbol
8527 corresponding to that namespace to the symbol table. NAMESPACE is
8528 the name of the enclosing namespace. */
8531 add_partial_namespace (struct partial_die_info
*pdi
,
8532 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8533 int set_addrmap
, struct dwarf2_cu
*cu
)
8535 /* Add a symbol for the namespace. */
8537 add_partial_symbol (pdi
, cu
);
8539 /* Now scan partial symbols in that namespace. */
8541 if (pdi
->has_children
)
8542 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8545 /* Read a partial die corresponding to a Fortran module. */
8548 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8549 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8551 /* Add a symbol for the namespace. */
8553 add_partial_symbol (pdi
, cu
);
8555 /* Now scan partial symbols in that module. */
8557 if (pdi
->has_children
)
8558 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8561 /* Read a partial die corresponding to a subprogram or an inlined
8562 subprogram and create a partial symbol for that subprogram.
8563 When the CU language allows it, this routine also defines a partial
8564 symbol for each nested subprogram that this subprogram contains.
8565 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8566 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8568 PDI may also be a lexical block, in which case we simply search
8569 recursively for subprograms defined inside that lexical block.
8570 Again, this is only performed when the CU language allows this
8571 type of definitions. */
8574 add_partial_subprogram (struct partial_die_info
*pdi
,
8575 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8576 int set_addrmap
, struct dwarf2_cu
*cu
)
8578 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8580 if (pdi
->has_pc_info
)
8582 if (pdi
->lowpc
< *lowpc
)
8583 *lowpc
= pdi
->lowpc
;
8584 if (pdi
->highpc
> *highpc
)
8585 *highpc
= pdi
->highpc
;
8588 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8589 struct gdbarch
*gdbarch
= objfile
->arch ();
8591 CORE_ADDR this_highpc
;
8592 CORE_ADDR this_lowpc
;
8594 baseaddr
= objfile
->text_section_offset ();
8596 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8597 pdi
->lowpc
+ baseaddr
)
8600 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8601 pdi
->highpc
+ baseaddr
)
8603 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8604 this_lowpc
, this_highpc
- 1,
8605 cu
->per_cu
->v
.psymtab
);
8609 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8611 if (!pdi
->is_declaration
)
8612 /* Ignore subprogram DIEs that do not have a name, they are
8613 illegal. Do not emit a complaint at this point, we will
8614 do so when we convert this psymtab into a symtab. */
8616 add_partial_symbol (pdi
, cu
);
8620 if (! pdi
->has_children
)
8623 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8625 pdi
= pdi
->die_child
;
8629 if (pdi
->tag
== DW_TAG_subprogram
8630 || pdi
->tag
== DW_TAG_inlined_subroutine
8631 || pdi
->tag
== DW_TAG_lexical_block
)
8632 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8633 pdi
= pdi
->die_sibling
;
8638 /* Read a partial die corresponding to an enumeration type. */
8641 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8642 struct dwarf2_cu
*cu
)
8644 struct partial_die_info
*pdi
;
8646 if (enum_pdi
->name
!= NULL
)
8647 add_partial_symbol (enum_pdi
, cu
);
8649 pdi
= enum_pdi
->die_child
;
8652 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8653 complaint (_("malformed enumerator DIE ignored"));
8655 add_partial_symbol (pdi
, cu
);
8656 pdi
= pdi
->die_sibling
;
8660 /* Return the initial uleb128 in the die at INFO_PTR. */
8663 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8665 unsigned int bytes_read
;
8667 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8670 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8671 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8673 Return the corresponding abbrev, or NULL if the number is zero (indicating
8674 an empty DIE). In either case *BYTES_READ will be set to the length of
8675 the initial number. */
8677 static struct abbrev_info
*
8678 peek_die_abbrev (const die_reader_specs
&reader
,
8679 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8681 dwarf2_cu
*cu
= reader
.cu
;
8682 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8683 unsigned int abbrev_number
8684 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8686 if (abbrev_number
== 0)
8689 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8692 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8693 " at offset %s [in module %s]"),
8694 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8695 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8701 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8702 Returns a pointer to the end of a series of DIEs, terminated by an empty
8703 DIE. Any children of the skipped DIEs will also be skipped. */
8705 static const gdb_byte
*
8706 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8710 unsigned int bytes_read
;
8711 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8714 return info_ptr
+ bytes_read
;
8716 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8720 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8721 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8722 abbrev corresponding to that skipped uleb128 should be passed in
8723 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8726 static const gdb_byte
*
8727 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8728 struct abbrev_info
*abbrev
)
8730 unsigned int bytes_read
;
8731 struct attribute attr
;
8732 bfd
*abfd
= reader
->abfd
;
8733 struct dwarf2_cu
*cu
= reader
->cu
;
8734 const gdb_byte
*buffer
= reader
->buffer
;
8735 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8736 unsigned int form
, i
;
8738 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8740 /* The only abbrev we care about is DW_AT_sibling. */
8741 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8744 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8746 if (attr
.form
== DW_FORM_ref_addr
)
8747 complaint (_("ignoring absolute DW_AT_sibling"));
8750 sect_offset off
= attr
.get_ref_die_offset ();
8751 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8753 if (sibling_ptr
< info_ptr
)
8754 complaint (_("DW_AT_sibling points backwards"));
8755 else if (sibling_ptr
> reader
->buffer_end
)
8756 reader
->die_section
->overflow_complaint ();
8762 /* If it isn't DW_AT_sibling, skip this attribute. */
8763 form
= abbrev
->attrs
[i
].form
;
8767 case DW_FORM_ref_addr
:
8768 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8769 and later it is offset sized. */
8770 if (cu
->header
.version
== 2)
8771 info_ptr
+= cu
->header
.addr_size
;
8773 info_ptr
+= cu
->header
.offset_size
;
8775 case DW_FORM_GNU_ref_alt
:
8776 info_ptr
+= cu
->header
.offset_size
;
8779 info_ptr
+= cu
->header
.addr_size
;
8787 case DW_FORM_flag_present
:
8788 case DW_FORM_implicit_const
:
8805 case DW_FORM_ref_sig8
:
8808 case DW_FORM_data16
:
8811 case DW_FORM_string
:
8812 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8813 info_ptr
+= bytes_read
;
8815 case DW_FORM_sec_offset
:
8817 case DW_FORM_GNU_strp_alt
:
8818 info_ptr
+= cu
->header
.offset_size
;
8820 case DW_FORM_exprloc
:
8822 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8823 info_ptr
+= bytes_read
;
8825 case DW_FORM_block1
:
8826 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8828 case DW_FORM_block2
:
8829 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8831 case DW_FORM_block4
:
8832 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8838 case DW_FORM_ref_udata
:
8839 case DW_FORM_GNU_addr_index
:
8840 case DW_FORM_GNU_str_index
:
8841 case DW_FORM_rnglistx
:
8842 case DW_FORM_loclistx
:
8843 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8845 case DW_FORM_indirect
:
8846 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8847 info_ptr
+= bytes_read
;
8848 /* We need to continue parsing from here, so just go back to
8850 goto skip_attribute
;
8853 error (_("Dwarf Error: Cannot handle %s "
8854 "in DWARF reader [in module %s]"),
8855 dwarf_form_name (form
),
8856 bfd_get_filename (abfd
));
8860 if (abbrev
->has_children
)
8861 return skip_children (reader
, info_ptr
);
8866 /* Locate ORIG_PDI's sibling.
8867 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8869 static const gdb_byte
*
8870 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8871 struct partial_die_info
*orig_pdi
,
8872 const gdb_byte
*info_ptr
)
8874 /* Do we know the sibling already? */
8876 if (orig_pdi
->sibling
)
8877 return orig_pdi
->sibling
;
8879 /* Are there any children to deal with? */
8881 if (!orig_pdi
->has_children
)
8884 /* Skip the children the long way. */
8886 return skip_children (reader
, info_ptr
);
8889 /* Expand this partial symbol table into a full symbol table. SELF is
8893 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8895 struct dwarf2_per_objfile
*dwarf2_per_objfile
8896 = get_dwarf2_per_objfile (objfile
);
8898 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (per_cu_data
));
8900 /* If this psymtab is constructed from a debug-only objfile, the
8901 has_section_at_zero flag will not necessarily be correct. We
8902 can get the correct value for this flag by looking at the data
8903 associated with the (presumably stripped) associated objfile. */
8904 if (objfile
->separate_debug_objfile_backlink
)
8906 struct dwarf2_per_objfile
*dpo_backlink
8907 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8909 dwarf2_per_objfile
->per_bfd
->has_section_at_zero
8910 = dpo_backlink
->per_bfd
->has_section_at_zero
;
8913 expand_psymtab (objfile
);
8915 process_cu_includes (dwarf2_per_objfile
);
8918 /* Reading in full CUs. */
8920 /* Add PER_CU to the queue. */
8923 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8924 dwarf2_per_objfile
*per_objfile
,
8925 enum language pretend_language
)
8928 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
8931 /* If PER_CU is not yet queued, add it to the queue.
8932 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8934 The result is non-zero if PER_CU was queued, otherwise the result is zero
8935 meaning either PER_CU is already queued or it is already loaded.
8937 N.B. There is an invariant here that if a CU is queued then it is loaded.
8938 The caller is required to load PER_CU if we return non-zero. */
8941 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8942 dwarf2_per_cu_data
*per_cu
,
8943 dwarf2_per_objfile
*per_objfile
,
8944 enum language pretend_language
)
8946 /* We may arrive here during partial symbol reading, if we need full
8947 DIEs to process an unusual case (e.g. template arguments). Do
8948 not queue PER_CU, just tell our caller to load its DIEs. */
8949 if (per_cu
->per_bfd
->reading_partial_symbols
)
8951 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8956 /* Mark the dependence relation so that we don't flush PER_CU
8958 if (dependent_cu
!= NULL
)
8959 dwarf2_add_dependence (dependent_cu
, per_cu
);
8961 /* If it's already on the queue, we have nothing to do. */
8965 /* If the compilation unit is already loaded, just mark it as
8967 if (per_cu
->cu
!= NULL
)
8969 per_cu
->cu
->last_used
= 0;
8973 /* Add it to the queue. */
8974 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8979 /* Process the queue. */
8982 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8984 if (dwarf_read_debug
)
8986 fprintf_unfiltered (gdb_stdlog
,
8987 "Expanding one or more symtabs of objfile %s ...\n",
8988 objfile_name (dwarf2_per_objfile
->objfile
));
8991 /* The queue starts out with one item, but following a DIE reference
8992 may load a new CU, adding it to the end of the queue. */
8993 while (!dwarf2_per_objfile
->per_bfd
->queue
.empty ())
8995 dwarf2_queue_item
&item
= dwarf2_per_objfile
->per_bfd
->queue
.front ();
8997 if (!dwarf2_per_objfile
->symtab_set_p (item
.per_cu
)
8998 /* Skip dummy CUs. */
8999 && item
.per_cu
->cu
!= NULL
)
9001 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9002 unsigned int debug_print_threshold
;
9005 if (per_cu
->is_debug_types
)
9007 struct signatured_type
*sig_type
=
9008 (struct signatured_type
*) per_cu
;
9010 sprintf (buf
, "TU %s at offset %s",
9011 hex_string (sig_type
->signature
),
9012 sect_offset_str (per_cu
->sect_off
));
9013 /* There can be 100s of TUs.
9014 Only print them in verbose mode. */
9015 debug_print_threshold
= 2;
9019 sprintf (buf
, "CU at offset %s",
9020 sect_offset_str (per_cu
->sect_off
));
9021 debug_print_threshold
= 1;
9024 if (dwarf_read_debug
>= debug_print_threshold
)
9025 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9027 if (per_cu
->is_debug_types
)
9028 process_full_type_unit (per_cu
, dwarf2_per_objfile
,
9029 item
.pretend_language
);
9031 process_full_comp_unit (per_cu
, dwarf2_per_objfile
,
9032 item
.pretend_language
);
9034 if (dwarf_read_debug
>= debug_print_threshold
)
9035 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9038 item
.per_cu
->queued
= 0;
9039 dwarf2_per_objfile
->per_bfd
->queue
.pop ();
9042 if (dwarf_read_debug
)
9044 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9045 objfile_name (dwarf2_per_objfile
->objfile
));
9049 /* Read in full symbols for PST, and anything it depends on. */
9052 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9054 gdb_assert (!readin_p (objfile
));
9056 expand_dependencies (objfile
);
9058 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9059 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9060 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9063 /* See psympriv.h. */
9066 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9068 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9069 return per_objfile
->symtab_set_p (per_cu_data
);
9072 /* See psympriv.h. */
9075 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9077 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9078 return per_objfile
->get_symtab (per_cu_data
);
9081 /* Trivial hash function for die_info: the hash value of a DIE
9082 is its offset in .debug_info for this objfile. */
9085 die_hash (const void *item
)
9087 const struct die_info
*die
= (const struct die_info
*) item
;
9089 return to_underlying (die
->sect_off
);
9092 /* Trivial comparison function for die_info structures: two DIEs
9093 are equal if they have the same offset. */
9096 die_eq (const void *item_lhs
, const void *item_rhs
)
9098 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9099 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9101 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9104 /* Load the DIEs associated with PER_CU into memory. */
9107 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9108 dwarf2_per_objfile
*per_objfile
,
9110 enum language pretend_language
)
9112 gdb_assert (! this_cu
->is_debug_types
);
9114 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 1, skip_partial
);
9118 struct dwarf2_cu
*cu
= reader
.cu
;
9119 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9121 gdb_assert (cu
->die_hash
== NULL
);
9123 htab_create_alloc_ex (cu
->header
.length
/ 12,
9127 &cu
->comp_unit_obstack
,
9128 hashtab_obstack_allocate
,
9129 dummy_obstack_deallocate
);
9131 if (reader
.comp_unit_die
->has_children
)
9132 reader
.comp_unit_die
->child
9133 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9134 &info_ptr
, reader
.comp_unit_die
);
9135 cu
->dies
= reader
.comp_unit_die
;
9136 /* comp_unit_die is not stored in die_hash, no need. */
9138 /* We try not to read any attributes in this function, because not
9139 all CUs needed for references have been loaded yet, and symbol
9140 table processing isn't initialized. But we have to set the CU language,
9141 or we won't be able to build types correctly.
9142 Similarly, if we do not read the producer, we can not apply
9143 producer-specific interpretation. */
9144 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9149 /* Add a DIE to the delayed physname list. */
9152 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9153 const char *name
, struct die_info
*die
,
9154 struct dwarf2_cu
*cu
)
9156 struct delayed_method_info mi
;
9158 mi
.fnfield_index
= fnfield_index
;
9162 cu
->method_list
.push_back (mi
);
9165 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9166 "const" / "volatile". If so, decrements LEN by the length of the
9167 modifier and return true. Otherwise return false. */
9171 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9173 size_t mod_len
= sizeof (mod
) - 1;
9174 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9182 /* Compute the physnames of any methods on the CU's method list.
9184 The computation of method physnames is delayed in order to avoid the
9185 (bad) condition that one of the method's formal parameters is of an as yet
9189 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9191 /* Only C++ delays computing physnames. */
9192 if (cu
->method_list
.empty ())
9194 gdb_assert (cu
->language
== language_cplus
);
9196 for (const delayed_method_info
&mi
: cu
->method_list
)
9198 const char *physname
;
9199 struct fn_fieldlist
*fn_flp
9200 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9201 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9202 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9203 = physname
? physname
: "";
9205 /* Since there's no tag to indicate whether a method is a
9206 const/volatile overload, extract that information out of the
9208 if (physname
!= NULL
)
9210 size_t len
= strlen (physname
);
9214 if (physname
[len
] == ')') /* shortcut */
9216 else if (check_modifier (physname
, len
, " const"))
9217 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9218 else if (check_modifier (physname
, len
, " volatile"))
9219 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9226 /* The list is no longer needed. */
9227 cu
->method_list
.clear ();
9230 /* Go objects should be embedded in a DW_TAG_module DIE,
9231 and it's not clear if/how imported objects will appear.
9232 To keep Go support simple until that's worked out,
9233 go back through what we've read and create something usable.
9234 We could do this while processing each DIE, and feels kinda cleaner,
9235 but that way is more invasive.
9236 This is to, for example, allow the user to type "p var" or "b main"
9237 without having to specify the package name, and allow lookups
9238 of module.object to work in contexts that use the expression
9242 fixup_go_packaging (struct dwarf2_cu
*cu
)
9244 gdb::unique_xmalloc_ptr
<char> package_name
;
9245 struct pending
*list
;
9248 for (list
= *cu
->get_builder ()->get_global_symbols ();
9252 for (i
= 0; i
< list
->nsyms
; ++i
)
9254 struct symbol
*sym
= list
->symbol
[i
];
9256 if (sym
->language () == language_go
9257 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9259 gdb::unique_xmalloc_ptr
<char> this_package_name
9260 (go_symbol_package_name (sym
));
9262 if (this_package_name
== NULL
)
9264 if (package_name
== NULL
)
9265 package_name
= std::move (this_package_name
);
9268 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9269 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9270 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9271 (symbol_symtab (sym
) != NULL
9272 ? symtab_to_filename_for_display
9273 (symbol_symtab (sym
))
9274 : objfile_name (objfile
)),
9275 this_package_name
.get (), package_name
.get ());
9281 if (package_name
!= NULL
)
9283 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9284 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9285 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9286 saved_package_name
);
9289 sym
= new (&objfile
->objfile_obstack
) symbol
;
9290 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9291 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9292 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9293 e.g., "main" finds the "main" module and not C's main(). */
9294 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9295 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9296 SYMBOL_TYPE (sym
) = type
;
9298 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9302 /* Allocate a fully-qualified name consisting of the two parts on the
9306 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9308 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9311 /* A helper that allocates a variant part to attach to a Rust enum
9312 type. OBSTACK is where the results should be allocated. TYPE is
9313 the type we're processing. DISCRIMINANT_INDEX is the index of the
9314 discriminant. It must be the index of one of the fields of TYPE.
9315 DEFAULT_INDEX is the index of the default field; or -1 if there is
9316 no default. RANGES is indexed by "effective" field number (the
9317 field index, but omitting the discriminant and default fields) and
9318 must hold the discriminant values used by the variants. Note that
9319 RANGES must have a lifetime at least as long as OBSTACK -- either
9320 already allocated on it, or static. */
9323 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9324 int discriminant_index
, int default_index
,
9325 gdb::array_view
<discriminant_range
> ranges
)
9327 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9328 must be handled by the caller. */
9329 gdb_assert (discriminant_index
>= 0
9330 && discriminant_index
< type
->num_fields ());
9331 gdb_assert (default_index
== -1
9332 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9334 /* We have one variant for each non-discriminant field. */
9335 int n_variants
= type
->num_fields () - 1;
9337 variant
*variants
= new (obstack
) variant
[n_variants
];
9340 for (int i
= 0; i
< type
->num_fields (); ++i
)
9342 if (i
== discriminant_index
)
9345 variants
[var_idx
].first_field
= i
;
9346 variants
[var_idx
].last_field
= i
+ 1;
9348 /* The default field does not need a range, but other fields do.
9349 We skipped the discriminant above. */
9350 if (i
!= default_index
)
9352 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9359 gdb_assert (range_idx
== ranges
.size ());
9360 gdb_assert (var_idx
== n_variants
);
9362 variant_part
*part
= new (obstack
) variant_part
;
9363 part
->discriminant_index
= discriminant_index
;
9364 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9365 discriminant_index
));
9366 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9368 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9369 gdb::array_view
<variant_part
> *prop_value
9370 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9372 struct dynamic_prop prop
;
9373 prop
.kind
= PROP_VARIANT_PARTS
;
9374 prop
.data
.variant_parts
= prop_value
;
9376 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9379 /* Some versions of rustc emitted enums in an unusual way.
9381 Ordinary enums were emitted as unions. The first element of each
9382 structure in the union was named "RUST$ENUM$DISR". This element
9383 held the discriminant.
9385 These versions of Rust also implemented the "non-zero"
9386 optimization. When the enum had two values, and one is empty and
9387 the other holds a pointer that cannot be zero, the pointer is used
9388 as the discriminant, with a zero value meaning the empty variant.
9389 Here, the union's first member is of the form
9390 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9391 where the fieldnos are the indices of the fields that should be
9392 traversed in order to find the field (which may be several fields deep)
9393 and the variantname is the name of the variant of the case when the
9396 This function recognizes whether TYPE is of one of these forms,
9397 and, if so, smashes it to be a variant type. */
9400 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9402 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9404 /* We don't need to deal with empty enums. */
9405 if (type
->num_fields () == 0)
9408 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9409 if (type
->num_fields () == 1
9410 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9412 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9414 /* Decode the field name to find the offset of the
9416 ULONGEST bit_offset
= 0;
9417 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9418 while (name
[0] >= '0' && name
[0] <= '9')
9421 unsigned long index
= strtoul (name
, &tail
, 10);
9424 || index
>= field_type
->num_fields ()
9425 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9426 != FIELD_LOC_KIND_BITPOS
))
9428 complaint (_("Could not parse Rust enum encoding string \"%s\""
9430 TYPE_FIELD_NAME (type
, 0),
9431 objfile_name (objfile
));
9436 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9437 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9440 /* Smash this type to be a structure type. We have to do this
9441 because the type has already been recorded. */
9442 type
->set_code (TYPE_CODE_STRUCT
);
9443 type
->set_num_fields (3);
9444 /* Save the field we care about. */
9445 struct field saved_field
= type
->field (0);
9447 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9449 /* Put the discriminant at index 0. */
9450 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9451 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9452 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9453 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9455 /* The order of fields doesn't really matter, so put the real
9456 field at index 1 and the data-less field at index 2. */
9457 type
->field (1) = saved_field
;
9458 TYPE_FIELD_NAME (type
, 1)
9459 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9460 TYPE_FIELD_TYPE (type
, 1)->set_name
9461 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9462 TYPE_FIELD_NAME (type
, 1)));
9464 const char *dataless_name
9465 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9467 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9469 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9470 /* NAME points into the original discriminant name, which
9471 already has the correct lifetime. */
9472 TYPE_FIELD_NAME (type
, 2) = name
;
9473 SET_FIELD_BITPOS (type
->field (2), 0);
9475 /* Indicate that this is a variant type. */
9476 static discriminant_range ranges
[1] = { { 0, 0 } };
9477 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9479 /* A union with a single anonymous field is probably an old-style
9481 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9483 /* Smash this type to be a structure type. We have to do this
9484 because the type has already been recorded. */
9485 type
->set_code (TYPE_CODE_STRUCT
);
9487 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9488 const char *variant_name
9489 = rust_last_path_segment (field_type
->name ());
9490 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9491 field_type
->set_name
9492 (rust_fully_qualify (&objfile
->objfile_obstack
,
9493 type
->name (), variant_name
));
9497 struct type
*disr_type
= nullptr;
9498 for (int i
= 0; i
< type
->num_fields (); ++i
)
9500 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9502 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9504 /* All fields of a true enum will be structs. */
9507 else if (disr_type
->num_fields () == 0)
9509 /* Could be data-less variant, so keep going. */
9510 disr_type
= nullptr;
9512 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9513 "RUST$ENUM$DISR") != 0)
9515 /* Not a Rust enum. */
9525 /* If we got here without a discriminant, then it's probably
9527 if (disr_type
== nullptr)
9530 /* Smash this type to be a structure type. We have to do this
9531 because the type has already been recorded. */
9532 type
->set_code (TYPE_CODE_STRUCT
);
9534 /* Make space for the discriminant field. */
9535 struct field
*disr_field
= &disr_type
->field (0);
9537 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9538 * sizeof (struct field
)));
9539 memcpy (new_fields
+ 1, type
->fields (),
9540 type
->num_fields () * sizeof (struct field
));
9541 type
->set_fields (new_fields
);
9542 type
->set_num_fields (type
->num_fields () + 1);
9544 /* Install the discriminant at index 0 in the union. */
9545 type
->field (0) = *disr_field
;
9546 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9547 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9549 /* We need a way to find the correct discriminant given a
9550 variant name. For convenience we build a map here. */
9551 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9552 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9553 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9555 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9558 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9559 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9563 int n_fields
= type
->num_fields ();
9564 /* We don't need a range entry for the discriminant, but we do
9565 need one for every other field, as there is no default
9567 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9570 /* Skip the discriminant here. */
9571 for (int i
= 1; i
< n_fields
; ++i
)
9573 /* Find the final word in the name of this variant's type.
9574 That name can be used to look up the correct
9576 const char *variant_name
9577 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9579 auto iter
= discriminant_map
.find (variant_name
);
9580 if (iter
!= discriminant_map
.end ())
9582 ranges
[i
].low
= iter
->second
;
9583 ranges
[i
].high
= iter
->second
;
9586 /* Remove the discriminant field, if it exists. */
9587 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9588 if (sub_type
->num_fields () > 0)
9590 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9591 sub_type
->set_fields (sub_type
->fields () + 1);
9593 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9595 (rust_fully_qualify (&objfile
->objfile_obstack
,
9596 type
->name (), variant_name
));
9599 /* Indicate that this is a variant type. */
9600 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9601 gdb::array_view
<discriminant_range
> (ranges
,
9606 /* Rewrite some Rust unions to be structures with variants parts. */
9609 rust_union_quirks (struct dwarf2_cu
*cu
)
9611 gdb_assert (cu
->language
== language_rust
);
9612 for (type
*type_
: cu
->rust_unions
)
9613 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9614 /* We don't need this any more. */
9615 cu
->rust_unions
.clear ();
9620 type_unit_group_unshareable
*
9621 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9623 auto iter
= this->m_type_units
.find (tu_group
);
9624 if (iter
!= this->m_type_units
.end ())
9625 return iter
->second
.get ();
9627 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9628 type_unit_group_unshareable
*result
= uniq
.get ();
9629 this->m_type_units
[tu_group
] = std::move (uniq
);
9633 /* A helper function for computing the list of all symbol tables
9634 included by PER_CU. */
9637 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9638 htab_t all_children
, htab_t all_type_symtabs
,
9639 dwarf2_per_cu_data
*per_cu
,
9640 dwarf2_per_objfile
*per_objfile
,
9641 struct compunit_symtab
*immediate_parent
)
9643 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9646 /* This inclusion and its children have been processed. */
9652 /* Only add a CU if it has a symbol table. */
9653 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9656 /* If this is a type unit only add its symbol table if we haven't
9657 seen it yet (type unit per_cu's can share symtabs). */
9658 if (per_cu
->is_debug_types
)
9660 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9664 result
->push_back (cust
);
9665 if (cust
->user
== NULL
)
9666 cust
->user
= immediate_parent
;
9671 result
->push_back (cust
);
9672 if (cust
->user
== NULL
)
9673 cust
->user
= immediate_parent
;
9677 if (!per_cu
->imported_symtabs_empty ())
9678 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9680 recursively_compute_inclusions (result
, all_children
,
9681 all_type_symtabs
, ptr
, per_objfile
,
9686 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9690 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9691 dwarf2_per_objfile
*per_objfile
)
9693 gdb_assert (! per_cu
->is_debug_types
);
9695 if (!per_cu
->imported_symtabs_empty ())
9698 std::vector
<compunit_symtab
*> result_symtabs
;
9699 htab_t all_children
, all_type_symtabs
;
9700 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9702 /* If we don't have a symtab, we can just skip this case. */
9706 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9707 NULL
, xcalloc
, xfree
);
9708 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9709 NULL
, xcalloc
, xfree
);
9711 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9713 recursively_compute_inclusions (&result_symtabs
, all_children
,
9714 all_type_symtabs
, ptr
, per_objfile
,
9718 /* Now we have a transitive closure of all the included symtabs. */
9719 len
= result_symtabs
.size ();
9721 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9722 struct compunit_symtab
*, len
+ 1);
9723 memcpy (cust
->includes
, result_symtabs
.data (),
9724 len
* sizeof (compunit_symtab
*));
9725 cust
->includes
[len
] = NULL
;
9727 htab_delete (all_children
);
9728 htab_delete (all_type_symtabs
);
9732 /* Compute the 'includes' field for the symtabs of all the CUs we just
9736 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9738 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->per_bfd
->just_read_cus
)
9740 if (! iter
->is_debug_types
)
9741 compute_compunit_symtab_includes (iter
, dwarf2_per_objfile
);
9744 dwarf2_per_objfile
->per_bfd
->just_read_cus
.clear ();
9747 /* Generate full symbol information for PER_CU, whose DIEs have
9748 already been loaded into memory. */
9751 process_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
9752 dwarf2_per_objfile
*dwarf2_per_objfile
,
9753 enum language pretend_language
)
9755 struct dwarf2_cu
*cu
= per_cu
->cu
;
9756 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9757 struct gdbarch
*gdbarch
= objfile
->arch ();
9758 CORE_ADDR lowpc
, highpc
;
9759 struct compunit_symtab
*cust
;
9761 struct block
*static_block
;
9764 baseaddr
= objfile
->text_section_offset ();
9766 /* Clear the list here in case something was left over. */
9767 cu
->method_list
.clear ();
9769 cu
->language
= pretend_language
;
9770 cu
->language_defn
= language_def (cu
->language
);
9772 /* Do line number decoding in read_file_scope () */
9773 process_die (cu
->dies
, cu
);
9775 /* For now fudge the Go package. */
9776 if (cu
->language
== language_go
)
9777 fixup_go_packaging (cu
);
9779 /* Now that we have processed all the DIEs in the CU, all the types
9780 should be complete, and it should now be safe to compute all of the
9782 compute_delayed_physnames (cu
);
9784 if (cu
->language
== language_rust
)
9785 rust_union_quirks (cu
);
9787 /* Some compilers don't define a DW_AT_high_pc attribute for the
9788 compilation unit. If the DW_AT_high_pc is missing, synthesize
9789 it, by scanning the DIE's below the compilation unit. */
9790 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9792 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9793 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9795 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9796 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9797 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9798 addrmap to help ensure it has an accurate map of pc values belonging to
9800 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9802 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9803 SECT_OFF_TEXT (objfile
),
9808 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9810 /* Set symtab language to language from DW_AT_language. If the
9811 compilation is from a C file generated by language preprocessors, do
9812 not set the language if it was already deduced by start_subfile. */
9813 if (!(cu
->language
== language_c
9814 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9815 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9817 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9818 produce DW_AT_location with location lists but it can be possibly
9819 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9820 there were bugs in prologue debug info, fixed later in GCC-4.5
9821 by "unwind info for epilogues" patch (which is not directly related).
9823 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9824 needed, it would be wrong due to missing DW_AT_producer there.
9826 Still one can confuse GDB by using non-standard GCC compilation
9827 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9829 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9830 cust
->locations_valid
= 1;
9832 if (gcc_4_minor
>= 5)
9833 cust
->epilogue_unwind_valid
= 1;
9835 cust
->call_site_htab
= cu
->call_site_htab
;
9838 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9840 /* Push it for inclusion processing later. */
9841 dwarf2_per_objfile
->per_bfd
->just_read_cus
.push_back (per_cu
);
9843 /* Not needed any more. */
9844 cu
->reset_builder ();
9847 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9848 already been loaded into memory. */
9851 process_full_type_unit (dwarf2_per_cu_data
*per_cu
,
9852 dwarf2_per_objfile
*dwarf2_per_objfile
,
9853 enum language pretend_language
)
9855 struct dwarf2_cu
*cu
= per_cu
->cu
;
9856 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9857 struct compunit_symtab
*cust
;
9858 struct signatured_type
*sig_type
;
9860 gdb_assert (per_cu
->is_debug_types
);
9861 sig_type
= (struct signatured_type
*) per_cu
;
9863 /* Clear the list here in case something was left over. */
9864 cu
->method_list
.clear ();
9866 cu
->language
= pretend_language
;
9867 cu
->language_defn
= language_def (cu
->language
);
9869 /* The symbol tables are set up in read_type_unit_scope. */
9870 process_die (cu
->dies
, cu
);
9872 /* For now fudge the Go package. */
9873 if (cu
->language
== language_go
)
9874 fixup_go_packaging (cu
);
9876 /* Now that we have processed all the DIEs in the CU, all the types
9877 should be complete, and it should now be safe to compute all of the
9879 compute_delayed_physnames (cu
);
9881 if (cu
->language
== language_rust
)
9882 rust_union_quirks (cu
);
9884 /* TUs share symbol tables.
9885 If this is the first TU to use this symtab, complete the construction
9886 of it with end_expandable_symtab. Otherwise, complete the addition of
9887 this TU's symbols to the existing symtab. */
9888 type_unit_group_unshareable
*tug_unshare
=
9889 dwarf2_per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9890 if (tug_unshare
->compunit_symtab
== NULL
)
9892 buildsym_compunit
*builder
= cu
->get_builder ();
9893 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9894 tug_unshare
->compunit_symtab
= cust
;
9898 /* Set symtab language to language from DW_AT_language. If the
9899 compilation is from a C file generated by language preprocessors,
9900 do not set the language if it was already deduced by
9902 if (!(cu
->language
== language_c
9903 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9904 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9909 cu
->get_builder ()->augment_type_symtab ();
9910 cust
= tug_unshare
->compunit_symtab
;
9913 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9915 /* Not needed any more. */
9916 cu
->reset_builder ();
9919 /* Process an imported unit DIE. */
9922 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9924 struct attribute
*attr
;
9926 /* For now we don't handle imported units in type units. */
9927 if (cu
->per_cu
->is_debug_types
)
9929 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9930 " supported in type units [in module %s]"),
9931 objfile_name (cu
->per_objfile
->objfile
));
9934 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9937 sect_offset sect_off
= attr
->get_ref_die_offset ();
9938 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9939 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9940 dwarf2_per_cu_data
*per_cu
9941 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9943 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9944 into another compilation unit, at root level. Regard this as a hint,
9946 if (die
->parent
&& die
->parent
->parent
== NULL
9947 && per_cu
->unit_type
== DW_UT_compile
9948 && per_cu
->lang
== language_cplus
)
9951 /* If necessary, add it to the queue and load its DIEs. */
9952 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
9953 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
9955 cu
->per_cu
->imported_symtabs_push (per_cu
);
9959 /* RAII object that represents a process_die scope: i.e.,
9960 starts/finishes processing a DIE. */
9961 class process_die_scope
9964 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9965 : m_die (die
), m_cu (cu
)
9967 /* We should only be processing DIEs not already in process. */
9968 gdb_assert (!m_die
->in_process
);
9969 m_die
->in_process
= true;
9972 ~process_die_scope ()
9974 m_die
->in_process
= false;
9976 /* If we're done processing the DIE for the CU that owns the line
9977 header, we don't need the line header anymore. */
9978 if (m_cu
->line_header_die_owner
== m_die
)
9980 delete m_cu
->line_header
;
9981 m_cu
->line_header
= NULL
;
9982 m_cu
->line_header_die_owner
= NULL
;
9991 /* Process a die and its children. */
9994 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9996 process_die_scope
scope (die
, cu
);
10000 case DW_TAG_padding
:
10002 case DW_TAG_compile_unit
:
10003 case DW_TAG_partial_unit
:
10004 read_file_scope (die
, cu
);
10006 case DW_TAG_type_unit
:
10007 read_type_unit_scope (die
, cu
);
10009 case DW_TAG_subprogram
:
10010 /* Nested subprograms in Fortran get a prefix. */
10011 if (cu
->language
== language_fortran
10012 && die
->parent
!= NULL
10013 && die
->parent
->tag
== DW_TAG_subprogram
)
10014 cu
->processing_has_namespace_info
= true;
10015 /* Fall through. */
10016 case DW_TAG_inlined_subroutine
:
10017 read_func_scope (die
, cu
);
10019 case DW_TAG_lexical_block
:
10020 case DW_TAG_try_block
:
10021 case DW_TAG_catch_block
:
10022 read_lexical_block_scope (die
, cu
);
10024 case DW_TAG_call_site
:
10025 case DW_TAG_GNU_call_site
:
10026 read_call_site_scope (die
, cu
);
10028 case DW_TAG_class_type
:
10029 case DW_TAG_interface_type
:
10030 case DW_TAG_structure_type
:
10031 case DW_TAG_union_type
:
10032 process_structure_scope (die
, cu
);
10034 case DW_TAG_enumeration_type
:
10035 process_enumeration_scope (die
, cu
);
10038 /* These dies have a type, but processing them does not create
10039 a symbol or recurse to process the children. Therefore we can
10040 read them on-demand through read_type_die. */
10041 case DW_TAG_subroutine_type
:
10042 case DW_TAG_set_type
:
10043 case DW_TAG_array_type
:
10044 case DW_TAG_pointer_type
:
10045 case DW_TAG_ptr_to_member_type
:
10046 case DW_TAG_reference_type
:
10047 case DW_TAG_rvalue_reference_type
:
10048 case DW_TAG_string_type
:
10051 case DW_TAG_base_type
:
10052 case DW_TAG_subrange_type
:
10053 case DW_TAG_typedef
:
10054 /* Add a typedef symbol for the type definition, if it has a
10056 new_symbol (die
, read_type_die (die
, cu
), cu
);
10058 case DW_TAG_common_block
:
10059 read_common_block (die
, cu
);
10061 case DW_TAG_common_inclusion
:
10063 case DW_TAG_namespace
:
10064 cu
->processing_has_namespace_info
= true;
10065 read_namespace (die
, cu
);
10067 case DW_TAG_module
:
10068 cu
->processing_has_namespace_info
= true;
10069 read_module (die
, cu
);
10071 case DW_TAG_imported_declaration
:
10072 cu
->processing_has_namespace_info
= true;
10073 if (read_namespace_alias (die
, cu
))
10075 /* The declaration is not a global namespace alias. */
10076 /* Fall through. */
10077 case DW_TAG_imported_module
:
10078 cu
->processing_has_namespace_info
= true;
10079 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10080 || cu
->language
!= language_fortran
))
10081 complaint (_("Tag '%s' has unexpected children"),
10082 dwarf_tag_name (die
->tag
));
10083 read_import_statement (die
, cu
);
10086 case DW_TAG_imported_unit
:
10087 process_imported_unit_die (die
, cu
);
10090 case DW_TAG_variable
:
10091 read_variable (die
, cu
);
10095 new_symbol (die
, NULL
, cu
);
10100 /* DWARF name computation. */
10102 /* A helper function for dwarf2_compute_name which determines whether DIE
10103 needs to have the name of the scope prepended to the name listed in the
10107 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10109 struct attribute
*attr
;
10113 case DW_TAG_namespace
:
10114 case DW_TAG_typedef
:
10115 case DW_TAG_class_type
:
10116 case DW_TAG_interface_type
:
10117 case DW_TAG_structure_type
:
10118 case DW_TAG_union_type
:
10119 case DW_TAG_enumeration_type
:
10120 case DW_TAG_enumerator
:
10121 case DW_TAG_subprogram
:
10122 case DW_TAG_inlined_subroutine
:
10123 case DW_TAG_member
:
10124 case DW_TAG_imported_declaration
:
10127 case DW_TAG_variable
:
10128 case DW_TAG_constant
:
10129 /* We only need to prefix "globally" visible variables. These include
10130 any variable marked with DW_AT_external or any variable that
10131 lives in a namespace. [Variables in anonymous namespaces
10132 require prefixing, but they are not DW_AT_external.] */
10134 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10136 struct dwarf2_cu
*spec_cu
= cu
;
10138 return die_needs_namespace (die_specification (die
, &spec_cu
),
10142 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10143 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10144 && die
->parent
->tag
!= DW_TAG_module
)
10146 /* A variable in a lexical block of some kind does not need a
10147 namespace, even though in C++ such variables may be external
10148 and have a mangled name. */
10149 if (die
->parent
->tag
== DW_TAG_lexical_block
10150 || die
->parent
->tag
== DW_TAG_try_block
10151 || die
->parent
->tag
== DW_TAG_catch_block
10152 || die
->parent
->tag
== DW_TAG_subprogram
)
10161 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10162 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10163 defined for the given DIE. */
10165 static struct attribute
*
10166 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10168 struct attribute
*attr
;
10170 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10172 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10177 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10178 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10179 defined for the given DIE. */
10181 static const char *
10182 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10184 const char *linkage_name
;
10186 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10187 if (linkage_name
== NULL
)
10188 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10190 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10191 See https://github.com/rust-lang/rust/issues/32925. */
10192 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10193 && strchr (linkage_name
, '{') != NULL
)
10194 linkage_name
= NULL
;
10196 return linkage_name
;
10199 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10200 compute the physname for the object, which include a method's:
10201 - formal parameters (C++),
10202 - receiver type (Go),
10204 The term "physname" is a bit confusing.
10205 For C++, for example, it is the demangled name.
10206 For Go, for example, it's the mangled name.
10208 For Ada, return the DIE's linkage name rather than the fully qualified
10209 name. PHYSNAME is ignored..
10211 The result is allocated on the objfile->per_bfd's obstack and
10214 static const char *
10215 dwarf2_compute_name (const char *name
,
10216 struct die_info
*die
, struct dwarf2_cu
*cu
,
10219 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10222 name
= dwarf2_name (die
, cu
);
10224 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10225 but otherwise compute it by typename_concat inside GDB.
10226 FIXME: Actually this is not really true, or at least not always true.
10227 It's all very confusing. compute_and_set_names doesn't try to demangle
10228 Fortran names because there is no mangling standard. So new_symbol
10229 will set the demangled name to the result of dwarf2_full_name, and it is
10230 the demangled name that GDB uses if it exists. */
10231 if (cu
->language
== language_ada
10232 || (cu
->language
== language_fortran
&& physname
))
10234 /* For Ada unit, we prefer the linkage name over the name, as
10235 the former contains the exported name, which the user expects
10236 to be able to reference. Ideally, we want the user to be able
10237 to reference this entity using either natural or linkage name,
10238 but we haven't started looking at this enhancement yet. */
10239 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10241 if (linkage_name
!= NULL
)
10242 return linkage_name
;
10245 /* These are the only languages we know how to qualify names in. */
10247 && (cu
->language
== language_cplus
10248 || cu
->language
== language_fortran
|| cu
->language
== language_d
10249 || cu
->language
== language_rust
))
10251 if (die_needs_namespace (die
, cu
))
10253 const char *prefix
;
10254 const char *canonical_name
= NULL
;
10258 prefix
= determine_prefix (die
, cu
);
10259 if (*prefix
!= '\0')
10261 gdb::unique_xmalloc_ptr
<char> prefixed_name
10262 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10264 buf
.puts (prefixed_name
.get ());
10269 /* Template parameters may be specified in the DIE's DW_AT_name, or
10270 as children with DW_TAG_template_type_param or
10271 DW_TAG_value_type_param. If the latter, add them to the name
10272 here. If the name already has template parameters, then
10273 skip this step; some versions of GCC emit both, and
10274 it is more efficient to use the pre-computed name.
10276 Something to keep in mind about this process: it is very
10277 unlikely, or in some cases downright impossible, to produce
10278 something that will match the mangled name of a function.
10279 If the definition of the function has the same debug info,
10280 we should be able to match up with it anyway. But fallbacks
10281 using the minimal symbol, for instance to find a method
10282 implemented in a stripped copy of libstdc++, will not work.
10283 If we do not have debug info for the definition, we will have to
10284 match them up some other way.
10286 When we do name matching there is a related problem with function
10287 templates; two instantiated function templates are allowed to
10288 differ only by their return types, which we do not add here. */
10290 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10292 struct attribute
*attr
;
10293 struct die_info
*child
;
10296 die
->building_fullname
= 1;
10298 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10302 const gdb_byte
*bytes
;
10303 struct dwarf2_locexpr_baton
*baton
;
10306 if (child
->tag
!= DW_TAG_template_type_param
10307 && child
->tag
!= DW_TAG_template_value_param
)
10318 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10321 complaint (_("template parameter missing DW_AT_type"));
10322 buf
.puts ("UNKNOWN_TYPE");
10325 type
= die_type (child
, cu
);
10327 if (child
->tag
== DW_TAG_template_type_param
)
10329 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10330 &type_print_raw_options
);
10334 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10337 complaint (_("template parameter missing "
10338 "DW_AT_const_value"));
10339 buf
.puts ("UNKNOWN_VALUE");
10343 dwarf2_const_value_attr (attr
, type
, name
,
10344 &cu
->comp_unit_obstack
, cu
,
10345 &value
, &bytes
, &baton
);
10347 if (TYPE_NOSIGN (type
))
10348 /* GDB prints characters as NUMBER 'CHAR'. If that's
10349 changed, this can use value_print instead. */
10350 c_printchar (value
, type
, &buf
);
10353 struct value_print_options opts
;
10356 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10360 baton
->per_objfile
);
10361 else if (bytes
!= NULL
)
10363 v
= allocate_value (type
);
10364 memcpy (value_contents_writeable (v
), bytes
,
10365 TYPE_LENGTH (type
));
10368 v
= value_from_longest (type
, value
);
10370 /* Specify decimal so that we do not depend on
10372 get_formatted_print_options (&opts
, 'd');
10374 value_print (v
, &buf
, &opts
);
10379 die
->building_fullname
= 0;
10383 /* Close the argument list, with a space if necessary
10384 (nested templates). */
10385 if (!buf
.empty () && buf
.string ().back () == '>')
10392 /* For C++ methods, append formal parameter type
10393 information, if PHYSNAME. */
10395 if (physname
&& die
->tag
== DW_TAG_subprogram
10396 && cu
->language
== language_cplus
)
10398 struct type
*type
= read_type_die (die
, cu
);
10400 c_type_print_args (type
, &buf
, 1, cu
->language
,
10401 &type_print_raw_options
);
10403 if (cu
->language
== language_cplus
)
10405 /* Assume that an artificial first parameter is
10406 "this", but do not crash if it is not. RealView
10407 marks unnamed (and thus unused) parameters as
10408 artificial; there is no way to differentiate
10410 if (type
->num_fields () > 0
10411 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10412 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10413 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10415 buf
.puts (" const");
10419 const std::string
&intermediate_name
= buf
.string ();
10421 if (cu
->language
== language_cplus
)
10423 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10426 /* If we only computed INTERMEDIATE_NAME, or if
10427 INTERMEDIATE_NAME is already canonical, then we need to
10429 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10430 name
= objfile
->intern (intermediate_name
);
10432 name
= canonical_name
;
10439 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10440 If scope qualifiers are appropriate they will be added. The result
10441 will be allocated on the storage_obstack, or NULL if the DIE does
10442 not have a name. NAME may either be from a previous call to
10443 dwarf2_name or NULL.
10445 The output string will be canonicalized (if C++). */
10447 static const char *
10448 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10450 return dwarf2_compute_name (name
, die
, cu
, 0);
10453 /* Construct a physname for the given DIE in CU. NAME may either be
10454 from a previous call to dwarf2_name or NULL. The result will be
10455 allocated on the objfile_objstack or NULL if the DIE does not have a
10458 The output string will be canonicalized (if C++). */
10460 static const char *
10461 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10463 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10464 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10467 /* In this case dwarf2_compute_name is just a shortcut not building anything
10469 if (!die_needs_namespace (die
, cu
))
10470 return dwarf2_compute_name (name
, die
, cu
, 1);
10472 if (cu
->language
!= language_rust
)
10473 mangled
= dw2_linkage_name (die
, cu
);
10475 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10477 gdb::unique_xmalloc_ptr
<char> demangled
;
10478 if (mangled
!= NULL
)
10481 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10483 /* Do nothing (do not demangle the symbol name). */
10485 else if (cu
->language
== language_go
)
10487 /* This is a lie, but we already lie to the caller new_symbol.
10488 new_symbol assumes we return the mangled name.
10489 This just undoes that lie until things are cleaned up. */
10493 /* Use DMGL_RET_DROP for C++ template functions to suppress
10494 their return type. It is easier for GDB users to search
10495 for such functions as `name(params)' than `long name(params)'.
10496 In such case the minimal symbol names do not match the full
10497 symbol names but for template functions there is never a need
10498 to look up their definition from their declaration so
10499 the only disadvantage remains the minimal symbol variant
10500 `long name(params)' does not have the proper inferior type. */
10501 demangled
.reset (gdb_demangle (mangled
,
10502 (DMGL_PARAMS
| DMGL_ANSI
10503 | DMGL_RET_DROP
)));
10506 canon
= demangled
.get ();
10514 if (canon
== NULL
|| check_physname
)
10516 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10518 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10520 /* It may not mean a bug in GDB. The compiler could also
10521 compute DW_AT_linkage_name incorrectly. But in such case
10522 GDB would need to be bug-to-bug compatible. */
10524 complaint (_("Computed physname <%s> does not match demangled <%s> "
10525 "(from linkage <%s>) - DIE at %s [in module %s]"),
10526 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10527 objfile_name (objfile
));
10529 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10530 is available here - over computed PHYSNAME. It is safer
10531 against both buggy GDB and buggy compilers. */
10545 retval
= objfile
->intern (retval
);
10550 /* Inspect DIE in CU for a namespace alias. If one exists, record
10551 a new symbol for it.
10553 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10556 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10558 struct attribute
*attr
;
10560 /* If the die does not have a name, this is not a namespace
10562 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10566 struct die_info
*d
= die
;
10567 struct dwarf2_cu
*imported_cu
= cu
;
10569 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10570 keep inspecting DIEs until we hit the underlying import. */
10571 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10572 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10574 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10578 d
= follow_die_ref (d
, attr
, &imported_cu
);
10579 if (d
->tag
!= DW_TAG_imported_declaration
)
10583 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10585 complaint (_("DIE at %s has too many recursively imported "
10586 "declarations"), sect_offset_str (d
->sect_off
));
10593 sect_offset sect_off
= attr
->get_ref_die_offset ();
10595 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10596 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10598 /* This declaration is a global namespace alias. Add
10599 a symbol for it whose type is the aliased namespace. */
10600 new_symbol (die
, type
, cu
);
10609 /* Return the using directives repository (global or local?) to use in the
10610 current context for CU.
10612 For Ada, imported declarations can materialize renamings, which *may* be
10613 global. However it is impossible (for now?) in DWARF to distinguish
10614 "external" imported declarations and "static" ones. As all imported
10615 declarations seem to be static in all other languages, make them all CU-wide
10616 global only in Ada. */
10618 static struct using_direct
**
10619 using_directives (struct dwarf2_cu
*cu
)
10621 if (cu
->language
== language_ada
10622 && cu
->get_builder ()->outermost_context_p ())
10623 return cu
->get_builder ()->get_global_using_directives ();
10625 return cu
->get_builder ()->get_local_using_directives ();
10628 /* Read the import statement specified by the given die and record it. */
10631 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10633 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10634 struct attribute
*import_attr
;
10635 struct die_info
*imported_die
, *child_die
;
10636 struct dwarf2_cu
*imported_cu
;
10637 const char *imported_name
;
10638 const char *imported_name_prefix
;
10639 const char *canonical_name
;
10640 const char *import_alias
;
10641 const char *imported_declaration
= NULL
;
10642 const char *import_prefix
;
10643 std::vector
<const char *> excludes
;
10645 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10646 if (import_attr
== NULL
)
10648 complaint (_("Tag '%s' has no DW_AT_import"),
10649 dwarf_tag_name (die
->tag
));
10654 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10655 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10656 if (imported_name
== NULL
)
10658 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10660 The import in the following code:
10674 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10675 <52> DW_AT_decl_file : 1
10676 <53> DW_AT_decl_line : 6
10677 <54> DW_AT_import : <0x75>
10678 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10679 <59> DW_AT_name : B
10680 <5b> DW_AT_decl_file : 1
10681 <5c> DW_AT_decl_line : 2
10682 <5d> DW_AT_type : <0x6e>
10684 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10685 <76> DW_AT_byte_size : 4
10686 <77> DW_AT_encoding : 5 (signed)
10688 imports the wrong die ( 0x75 instead of 0x58 ).
10689 This case will be ignored until the gcc bug is fixed. */
10693 /* Figure out the local name after import. */
10694 import_alias
= dwarf2_name (die
, cu
);
10696 /* Figure out where the statement is being imported to. */
10697 import_prefix
= determine_prefix (die
, cu
);
10699 /* Figure out what the scope of the imported die is and prepend it
10700 to the name of the imported die. */
10701 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10703 if (imported_die
->tag
!= DW_TAG_namespace
10704 && imported_die
->tag
!= DW_TAG_module
)
10706 imported_declaration
= imported_name
;
10707 canonical_name
= imported_name_prefix
;
10709 else if (strlen (imported_name_prefix
) > 0)
10710 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10711 imported_name_prefix
,
10712 (cu
->language
== language_d
? "." : "::"),
10713 imported_name
, (char *) NULL
);
10715 canonical_name
= imported_name
;
10717 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10718 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10719 child_die
= child_die
->sibling
)
10721 /* DWARF-4: A Fortran use statement with a “rename list” may be
10722 represented by an imported module entry with an import attribute
10723 referring to the module and owned entries corresponding to those
10724 entities that are renamed as part of being imported. */
10726 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10728 complaint (_("child DW_TAG_imported_declaration expected "
10729 "- DIE at %s [in module %s]"),
10730 sect_offset_str (child_die
->sect_off
),
10731 objfile_name (objfile
));
10735 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10736 if (import_attr
== NULL
)
10738 complaint (_("Tag '%s' has no DW_AT_import"),
10739 dwarf_tag_name (child_die
->tag
));
10744 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10746 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10747 if (imported_name
== NULL
)
10749 complaint (_("child DW_TAG_imported_declaration has unknown "
10750 "imported name - DIE at %s [in module %s]"),
10751 sect_offset_str (child_die
->sect_off
),
10752 objfile_name (objfile
));
10756 excludes
.push_back (imported_name
);
10758 process_die (child_die
, cu
);
10761 add_using_directive (using_directives (cu
),
10765 imported_declaration
,
10768 &objfile
->objfile_obstack
);
10771 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10772 types, but gives them a size of zero. Starting with version 14,
10773 ICC is compatible with GCC. */
10776 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10778 if (!cu
->checked_producer
)
10779 check_producer (cu
);
10781 return cu
->producer_is_icc_lt_14
;
10784 /* ICC generates a DW_AT_type for C void functions. This was observed on
10785 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10786 which says that void functions should not have a DW_AT_type. */
10789 producer_is_icc (struct dwarf2_cu
*cu
)
10791 if (!cu
->checked_producer
)
10792 check_producer (cu
);
10794 return cu
->producer_is_icc
;
10797 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10798 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10799 this, it was first present in GCC release 4.3.0. */
10802 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10804 if (!cu
->checked_producer
)
10805 check_producer (cu
);
10807 return cu
->producer_is_gcc_lt_4_3
;
10810 static file_and_directory
10811 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10813 file_and_directory res
;
10815 /* Find the filename. Do not use dwarf2_name here, since the filename
10816 is not a source language identifier. */
10817 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10818 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10820 if (res
.comp_dir
== NULL
10821 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10822 && IS_ABSOLUTE_PATH (res
.name
))
10824 res
.comp_dir_storage
= ldirname (res
.name
);
10825 if (!res
.comp_dir_storage
.empty ())
10826 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10828 if (res
.comp_dir
!= NULL
)
10830 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10831 directory, get rid of it. */
10832 const char *cp
= strchr (res
.comp_dir
, ':');
10834 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10835 res
.comp_dir
= cp
+ 1;
10838 if (res
.name
== NULL
)
10839 res
.name
= "<unknown>";
10844 /* Handle DW_AT_stmt_list for a compilation unit.
10845 DIE is the DW_TAG_compile_unit die for CU.
10846 COMP_DIR is the compilation directory. LOWPC is passed to
10847 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10850 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10851 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10853 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10854 struct attribute
*attr
;
10855 struct line_header line_header_local
;
10856 hashval_t line_header_local_hash
;
10858 int decode_mapping
;
10860 gdb_assert (! cu
->per_cu
->is_debug_types
);
10862 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10866 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10868 /* The line header hash table is only created if needed (it exists to
10869 prevent redundant reading of the line table for partial_units).
10870 If we're given a partial_unit, we'll need it. If we're given a
10871 compile_unit, then use the line header hash table if it's already
10872 created, but don't create one just yet. */
10874 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
10875 && die
->tag
== DW_TAG_partial_unit
)
10877 dwarf2_per_objfile
->per_bfd
->line_header_hash
10878 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10879 line_header_eq_voidp
,
10880 free_line_header_voidp
,
10884 line_header_local
.sect_off
= line_offset
;
10885 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10886 line_header_local_hash
= line_header_hash (&line_header_local
);
10887 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
!= NULL
)
10889 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10890 &line_header_local
,
10891 line_header_local_hash
, NO_INSERT
);
10893 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10894 is not present in *SLOT (since if there is something in *SLOT then
10895 it will be for a partial_unit). */
10896 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10898 gdb_assert (*slot
!= NULL
);
10899 cu
->line_header
= (struct line_header
*) *slot
;
10904 /* dwarf_decode_line_header does not yet provide sufficient information.
10905 We always have to call also dwarf_decode_lines for it. */
10906 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10910 cu
->line_header
= lh
.release ();
10911 cu
->line_header_die_owner
= die
;
10913 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
)
10917 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10918 &line_header_local
,
10919 line_header_local_hash
, INSERT
);
10920 gdb_assert (slot
!= NULL
);
10922 if (slot
!= NULL
&& *slot
== NULL
)
10924 /* This newly decoded line number information unit will be owned
10925 by line_header_hash hash table. */
10926 *slot
= cu
->line_header
;
10927 cu
->line_header_die_owner
= NULL
;
10931 /* We cannot free any current entry in (*slot) as that struct line_header
10932 may be already used by multiple CUs. Create only temporary decoded
10933 line_header for this CU - it may happen at most once for each line
10934 number information unit. And if we're not using line_header_hash
10935 then this is what we want as well. */
10936 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10938 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10939 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10944 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10947 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10949 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10950 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10951 struct gdbarch
*gdbarch
= objfile
->arch ();
10952 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10953 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10954 struct attribute
*attr
;
10955 struct die_info
*child_die
;
10956 CORE_ADDR baseaddr
;
10958 prepare_one_comp_unit (cu
, die
, cu
->language
);
10959 baseaddr
= objfile
->text_section_offset ();
10961 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10963 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10964 from finish_block. */
10965 if (lowpc
== ((CORE_ADDR
) -1))
10967 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10969 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10971 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10972 standardised yet. As a workaround for the language detection we fall
10973 back to the DW_AT_producer string. */
10974 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10975 cu
->language
= language_opencl
;
10977 /* Similar hack for Go. */
10978 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10979 set_cu_language (DW_LANG_Go
, cu
);
10981 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10983 /* Decode line number information if present. We do this before
10984 processing child DIEs, so that the line header table is available
10985 for DW_AT_decl_file. */
10986 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10988 /* Process all dies in compilation unit. */
10989 if (die
->child
!= NULL
)
10991 child_die
= die
->child
;
10992 while (child_die
&& child_die
->tag
)
10994 process_die (child_die
, cu
);
10995 child_die
= child_die
->sibling
;
10999 /* Decode macro information, if present. Dwarf 2 macro information
11000 refers to information in the line number info statement program
11001 header, so we can only read it if we've read the header
11003 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11005 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11006 if (attr
&& cu
->line_header
)
11008 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11009 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11011 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11015 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11016 if (attr
&& cu
->line_header
)
11018 unsigned int macro_offset
= DW_UNSND (attr
);
11020 dwarf_decode_macros (cu
, macro_offset
, 0);
11026 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11028 struct type_unit_group
*tu_group
;
11030 struct attribute
*attr
;
11032 struct signatured_type
*sig_type
;
11034 gdb_assert (per_cu
->is_debug_types
);
11035 sig_type
= (struct signatured_type
*) per_cu
;
11037 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11039 /* If we're using .gdb_index (includes -readnow) then
11040 per_cu->type_unit_group may not have been set up yet. */
11041 if (sig_type
->type_unit_group
== NULL
)
11042 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11043 tu_group
= sig_type
->type_unit_group
;
11045 /* If we've already processed this stmt_list there's no real need to
11046 do it again, we could fake it and just recreate the part we need
11047 (file name,index -> symtab mapping). If data shows this optimization
11048 is useful we can do it then. */
11049 type_unit_group_unshareable
*tug_unshare
11050 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11051 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11053 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11058 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11059 lh
= dwarf_decode_line_header (line_offset
, this);
11064 start_symtab ("", NULL
, 0);
11067 gdb_assert (tug_unshare
->symtabs
== NULL
);
11068 gdb_assert (m_builder
== nullptr);
11069 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11070 m_builder
.reset (new struct buildsym_compunit
11071 (COMPUNIT_OBJFILE (cust
), "",
11072 COMPUNIT_DIRNAME (cust
),
11073 compunit_language (cust
),
11075 list_in_scope
= get_builder ()->get_file_symbols ();
11080 line_header
= lh
.release ();
11081 line_header_die_owner
= die
;
11085 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11087 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11088 still initializing it, and our caller (a few levels up)
11089 process_full_type_unit still needs to know if this is the first
11092 tug_unshare
->symtabs
11093 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11094 struct symtab
*, line_header
->file_names_size ());
11096 auto &file_names
= line_header
->file_names ();
11097 for (i
= 0; i
< file_names
.size (); ++i
)
11099 file_entry
&fe
= file_names
[i
];
11100 dwarf2_start_subfile (this, fe
.name
,
11101 fe
.include_dir (line_header
));
11102 buildsym_compunit
*b
= get_builder ();
11103 if (b
->get_current_subfile ()->symtab
== NULL
)
11105 /* NOTE: start_subfile will recognize when it's been
11106 passed a file it has already seen. So we can't
11107 assume there's a simple mapping from
11108 cu->line_header->file_names to subfiles, plus
11109 cu->line_header->file_names may contain dups. */
11110 b
->get_current_subfile ()->symtab
11111 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11114 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11115 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11120 gdb_assert (m_builder
== nullptr);
11121 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11122 m_builder
.reset (new struct buildsym_compunit
11123 (COMPUNIT_OBJFILE (cust
), "",
11124 COMPUNIT_DIRNAME (cust
),
11125 compunit_language (cust
),
11127 list_in_scope
= get_builder ()->get_file_symbols ();
11129 auto &file_names
= line_header
->file_names ();
11130 for (i
= 0; i
< file_names
.size (); ++i
)
11132 file_entry
&fe
= file_names
[i
];
11133 fe
.symtab
= tug_unshare
->symtabs
[i
];
11137 /* The main symtab is allocated last. Type units don't have DW_AT_name
11138 so they don't have a "real" (so to speak) symtab anyway.
11139 There is later code that will assign the main symtab to all symbols
11140 that don't have one. We need to handle the case of a symbol with a
11141 missing symtab (DW_AT_decl_file) anyway. */
11144 /* Process DW_TAG_type_unit.
11145 For TUs we want to skip the first top level sibling if it's not the
11146 actual type being defined by this TU. In this case the first top
11147 level sibling is there to provide context only. */
11150 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11152 struct die_info
*child_die
;
11154 prepare_one_comp_unit (cu
, die
, language_minimal
);
11156 /* Initialize (or reinitialize) the machinery for building symtabs.
11157 We do this before processing child DIEs, so that the line header table
11158 is available for DW_AT_decl_file. */
11159 cu
->setup_type_unit_groups (die
);
11161 if (die
->child
!= NULL
)
11163 child_die
= die
->child
;
11164 while (child_die
&& child_die
->tag
)
11166 process_die (child_die
, cu
);
11167 child_die
= child_die
->sibling
;
11174 http://gcc.gnu.org/wiki/DebugFission
11175 http://gcc.gnu.org/wiki/DebugFissionDWP
11177 To simplify handling of both DWO files ("object" files with the DWARF info)
11178 and DWP files (a file with the DWOs packaged up into one file), we treat
11179 DWP files as having a collection of virtual DWO files. */
11182 hash_dwo_file (const void *item
)
11184 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11187 hash
= htab_hash_string (dwo_file
->dwo_name
);
11188 if (dwo_file
->comp_dir
!= NULL
)
11189 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11194 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11196 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11197 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11199 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11201 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11202 return lhs
->comp_dir
== rhs
->comp_dir
;
11203 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11206 /* Allocate a hash table for DWO files. */
11209 allocate_dwo_file_hash_table ()
11211 auto delete_dwo_file
= [] (void *item
)
11213 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11218 return htab_up (htab_create_alloc (41,
11225 /* Lookup DWO file DWO_NAME. */
11228 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11229 const char *dwo_name
,
11230 const char *comp_dir
)
11232 struct dwo_file find_entry
;
11235 if (dwarf2_per_objfile
->per_bfd
->dwo_files
== NULL
)
11236 dwarf2_per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11238 find_entry
.dwo_name
= dwo_name
;
11239 find_entry
.comp_dir
= comp_dir
;
11240 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11247 hash_dwo_unit (const void *item
)
11249 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11251 /* This drops the top 32 bits of the id, but is ok for a hash. */
11252 return dwo_unit
->signature
;
11256 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11258 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11259 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11261 /* The signature is assumed to be unique within the DWO file.
11262 So while object file CU dwo_id's always have the value zero,
11263 that's OK, assuming each object file DWO file has only one CU,
11264 and that's the rule for now. */
11265 return lhs
->signature
== rhs
->signature
;
11268 /* Allocate a hash table for DWO CUs,TUs.
11269 There is one of these tables for each of CUs,TUs for each DWO file. */
11272 allocate_dwo_unit_table ()
11274 /* Start out with a pretty small number.
11275 Generally DWO files contain only one CU and maybe some TUs. */
11276 return htab_up (htab_create_alloc (3,
11279 NULL
, xcalloc
, xfree
));
11282 /* die_reader_func for create_dwo_cu. */
11285 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11286 const gdb_byte
*info_ptr
,
11287 struct die_info
*comp_unit_die
,
11288 struct dwo_file
*dwo_file
,
11289 struct dwo_unit
*dwo_unit
)
11291 struct dwarf2_cu
*cu
= reader
->cu
;
11292 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11293 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11295 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11296 if (!signature
.has_value ())
11298 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11299 " its dwo_id [in module %s]"),
11300 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11304 dwo_unit
->dwo_file
= dwo_file
;
11305 dwo_unit
->signature
= *signature
;
11306 dwo_unit
->section
= section
;
11307 dwo_unit
->sect_off
= sect_off
;
11308 dwo_unit
->length
= cu
->per_cu
->length
;
11310 if (dwarf_read_debug
)
11311 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11312 sect_offset_str (sect_off
),
11313 hex_string (dwo_unit
->signature
));
11316 /* Create the dwo_units for the CUs in a DWO_FILE.
11317 Note: This function processes DWO files only, not DWP files. */
11320 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11321 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11322 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11324 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11325 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
11326 const gdb_byte
*info_ptr
, *end_ptr
;
11328 section
.read (objfile
);
11329 info_ptr
= section
.buffer
;
11331 if (info_ptr
== NULL
)
11334 if (dwarf_read_debug
)
11336 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11337 section
.get_name (),
11338 section
.get_file_name ());
11341 end_ptr
= info_ptr
+ section
.size
;
11342 while (info_ptr
< end_ptr
)
11344 struct dwarf2_per_cu_data per_cu
;
11345 struct dwo_unit read_unit
{};
11346 struct dwo_unit
*dwo_unit
;
11348 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11350 memset (&per_cu
, 0, sizeof (per_cu
));
11351 per_cu
.per_bfd
= per_bfd
;
11352 per_cu
.is_debug_types
= 0;
11353 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11354 per_cu
.section
= §ion
;
11356 cutu_reader
reader (&per_cu
, dwarf2_per_objfile
, cu
, &dwo_file
);
11357 if (!reader
.dummy_p
)
11358 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11359 &dwo_file
, &read_unit
);
11360 info_ptr
+= per_cu
.length
;
11362 // If the unit could not be parsed, skip it.
11363 if (read_unit
.dwo_file
== NULL
)
11366 if (cus_htab
== NULL
)
11367 cus_htab
= allocate_dwo_unit_table ();
11369 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11371 *dwo_unit
= read_unit
;
11372 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11373 gdb_assert (slot
!= NULL
);
11376 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11377 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11379 complaint (_("debug cu entry at offset %s is duplicate to"
11380 " the entry at offset %s, signature %s"),
11381 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11382 hex_string (dwo_unit
->signature
));
11384 *slot
= (void *)dwo_unit
;
11388 /* DWP file .debug_{cu,tu}_index section format:
11389 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11393 Both index sections have the same format, and serve to map a 64-bit
11394 signature to a set of section numbers. Each section begins with a header,
11395 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11396 indexes, and a pool of 32-bit section numbers. The index sections will be
11397 aligned at 8-byte boundaries in the file.
11399 The index section header consists of:
11401 V, 32 bit version number
11403 N, 32 bit number of compilation units or type units in the index
11404 M, 32 bit number of slots in the hash table
11406 Numbers are recorded using the byte order of the application binary.
11408 The hash table begins at offset 16 in the section, and consists of an array
11409 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11410 order of the application binary). Unused slots in the hash table are 0.
11411 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11413 The parallel table begins immediately after the hash table
11414 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11415 array of 32-bit indexes (using the byte order of the application binary),
11416 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11417 table contains a 32-bit index into the pool of section numbers. For unused
11418 hash table slots, the corresponding entry in the parallel table will be 0.
11420 The pool of section numbers begins immediately following the hash table
11421 (at offset 16 + 12 * M from the beginning of the section). The pool of
11422 section numbers consists of an array of 32-bit words (using the byte order
11423 of the application binary). Each item in the array is indexed starting
11424 from 0. The hash table entry provides the index of the first section
11425 number in the set. Additional section numbers in the set follow, and the
11426 set is terminated by a 0 entry (section number 0 is not used in ELF).
11428 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11429 section must be the first entry in the set, and the .debug_abbrev.dwo must
11430 be the second entry. Other members of the set may follow in any order.
11436 DWP Version 2 combines all the .debug_info, etc. sections into one,
11437 and the entries in the index tables are now offsets into these sections.
11438 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11441 Index Section Contents:
11443 Hash Table of Signatures dwp_hash_table.hash_table
11444 Parallel Table of Indices dwp_hash_table.unit_table
11445 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11446 Table of Section Sizes dwp_hash_table.v2.sizes
11448 The index section header consists of:
11450 V, 32 bit version number
11451 L, 32 bit number of columns in the table of section offsets
11452 N, 32 bit number of compilation units or type units in the index
11453 M, 32 bit number of slots in the hash table
11455 Numbers are recorded using the byte order of the application binary.
11457 The hash table has the same format as version 1.
11458 The parallel table of indices has the same format as version 1,
11459 except that the entries are origin-1 indices into the table of sections
11460 offsets and the table of section sizes.
11462 The table of offsets begins immediately following the parallel table
11463 (at offset 16 + 12 * M from the beginning of the section). The table is
11464 a two-dimensional array of 32-bit words (using the byte order of the
11465 application binary), with L columns and N+1 rows, in row-major order.
11466 Each row in the array is indexed starting from 0. The first row provides
11467 a key to the remaining rows: each column in this row provides an identifier
11468 for a debug section, and the offsets in the same column of subsequent rows
11469 refer to that section. The section identifiers are:
11471 DW_SECT_INFO 1 .debug_info.dwo
11472 DW_SECT_TYPES 2 .debug_types.dwo
11473 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11474 DW_SECT_LINE 4 .debug_line.dwo
11475 DW_SECT_LOC 5 .debug_loc.dwo
11476 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11477 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11478 DW_SECT_MACRO 8 .debug_macro.dwo
11480 The offsets provided by the CU and TU index sections are the base offsets
11481 for the contributions made by each CU or TU to the corresponding section
11482 in the package file. Each CU and TU header contains an abbrev_offset
11483 field, used to find the abbreviations table for that CU or TU within the
11484 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11485 be interpreted as relative to the base offset given in the index section.
11486 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11487 should be interpreted as relative to the base offset for .debug_line.dwo,
11488 and offsets into other debug sections obtained from DWARF attributes should
11489 also be interpreted as relative to the corresponding base offset.
11491 The table of sizes begins immediately following the table of offsets.
11492 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11493 with L columns and N rows, in row-major order. Each row in the array is
11494 indexed starting from 1 (row 0 is shared by the two tables).
11498 Hash table lookup is handled the same in version 1 and 2:
11500 We assume that N and M will not exceed 2^32 - 1.
11501 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11503 Given a 64-bit compilation unit signature or a type signature S, an entry
11504 in the hash table is located as follows:
11506 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11507 the low-order k bits all set to 1.
11509 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11511 3) If the hash table entry at index H matches the signature, use that
11512 entry. If the hash table entry at index H is unused (all zeroes),
11513 terminate the search: the signature is not present in the table.
11515 4) Let H = (H + H') modulo M. Repeat at Step 3.
11517 Because M > N and H' and M are relatively prime, the search is guaranteed
11518 to stop at an unused slot or find the match. */
11520 /* Create a hash table to map DWO IDs to their CU/TU entry in
11521 .debug_{info,types}.dwo in DWP_FILE.
11522 Returns NULL if there isn't one.
11523 Note: This function processes DWP files only, not DWO files. */
11525 static struct dwp_hash_table
*
11526 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11527 struct dwp_file
*dwp_file
, int is_debug_types
)
11529 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11530 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11531 const gdb_byte
*index_ptr
, *index_end
;
11532 struct dwarf2_section_info
*index
;
11533 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11534 struct dwp_hash_table
*htab
;
11536 if (is_debug_types
)
11537 index
= &dwp_file
->sections
.tu_index
;
11539 index
= &dwp_file
->sections
.cu_index
;
11541 if (index
->empty ())
11543 index
->read (objfile
);
11545 index_ptr
= index
->buffer
;
11546 index_end
= index_ptr
+ index
->size
;
11548 version
= read_4_bytes (dbfd
, index_ptr
);
11551 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11555 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11557 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11560 if (version
!= 1 && version
!= 2)
11562 error (_("Dwarf Error: unsupported DWP file version (%s)"
11563 " [in module %s]"),
11564 pulongest (version
), dwp_file
->name
);
11566 if (nr_slots
!= (nr_slots
& -nr_slots
))
11568 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11569 " is not power of 2 [in module %s]"),
11570 pulongest (nr_slots
), dwp_file
->name
);
11573 htab
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11574 htab
->version
= version
;
11575 htab
->nr_columns
= nr_columns
;
11576 htab
->nr_units
= nr_units
;
11577 htab
->nr_slots
= nr_slots
;
11578 htab
->hash_table
= index_ptr
;
11579 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11581 /* Exit early if the table is empty. */
11582 if (nr_slots
== 0 || nr_units
== 0
11583 || (version
== 2 && nr_columns
== 0))
11585 /* All must be zero. */
11586 if (nr_slots
!= 0 || nr_units
!= 0
11587 || (version
== 2 && nr_columns
!= 0))
11589 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11590 " all zero [in modules %s]"),
11598 htab
->section_pool
.v1
.indices
=
11599 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11600 /* It's harder to decide whether the section is too small in v1.
11601 V1 is deprecated anyway so we punt. */
11605 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11606 int *ids
= htab
->section_pool
.v2
.section_ids
;
11607 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11608 /* Reverse map for error checking. */
11609 int ids_seen
[DW_SECT_MAX
+ 1];
11612 if (nr_columns
< 2)
11614 error (_("Dwarf Error: bad DWP hash table, too few columns"
11615 " in section table [in module %s]"),
11618 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11620 error (_("Dwarf Error: bad DWP hash table, too many columns"
11621 " in section table [in module %s]"),
11624 memset (ids
, 255, sizeof_ids
);
11625 memset (ids_seen
, 255, sizeof (ids_seen
));
11626 for (i
= 0; i
< nr_columns
; ++i
)
11628 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11630 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11632 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11633 " in section table [in module %s]"),
11634 id
, dwp_file
->name
);
11636 if (ids_seen
[id
] != -1)
11638 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11639 " id %d in section table [in module %s]"),
11640 id
, dwp_file
->name
);
11645 /* Must have exactly one info or types section. */
11646 if (((ids_seen
[DW_SECT_INFO
] != -1)
11647 + (ids_seen
[DW_SECT_TYPES
] != -1))
11650 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11651 " DWO info/types section [in module %s]"),
11654 /* Must have an abbrev section. */
11655 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11657 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11658 " section [in module %s]"),
11661 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11662 htab
->section_pool
.v2
.sizes
=
11663 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11664 * nr_units
* nr_columns
);
11665 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11666 * nr_units
* nr_columns
))
11669 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11670 " [in module %s]"),
11678 /* Update SECTIONS with the data from SECTP.
11680 This function is like the other "locate" section routines that are
11681 passed to bfd_map_over_sections, but in this context the sections to
11682 read comes from the DWP V1 hash table, not the full ELF section table.
11684 The result is non-zero for success, or zero if an error was found. */
11687 locate_v1_virtual_dwo_sections (asection
*sectp
,
11688 struct virtual_v1_dwo_sections
*sections
)
11690 const struct dwop_section_names
*names
= &dwop_section_names
;
11692 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11694 /* There can be only one. */
11695 if (sections
->abbrev
.s
.section
!= NULL
)
11697 sections
->abbrev
.s
.section
= sectp
;
11698 sections
->abbrev
.size
= bfd_section_size (sectp
);
11700 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11701 || section_is_p (sectp
->name
, &names
->types_dwo
))
11703 /* There can be only one. */
11704 if (sections
->info_or_types
.s
.section
!= NULL
)
11706 sections
->info_or_types
.s
.section
= sectp
;
11707 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11709 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11711 /* There can be only one. */
11712 if (sections
->line
.s
.section
!= NULL
)
11714 sections
->line
.s
.section
= sectp
;
11715 sections
->line
.size
= bfd_section_size (sectp
);
11717 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11719 /* There can be only one. */
11720 if (sections
->loc
.s
.section
!= NULL
)
11722 sections
->loc
.s
.section
= sectp
;
11723 sections
->loc
.size
= bfd_section_size (sectp
);
11725 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11727 /* There can be only one. */
11728 if (sections
->macinfo
.s
.section
!= NULL
)
11730 sections
->macinfo
.s
.section
= sectp
;
11731 sections
->macinfo
.size
= bfd_section_size (sectp
);
11733 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11735 /* There can be only one. */
11736 if (sections
->macro
.s
.section
!= NULL
)
11738 sections
->macro
.s
.section
= sectp
;
11739 sections
->macro
.size
= bfd_section_size (sectp
);
11741 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11743 /* There can be only one. */
11744 if (sections
->str_offsets
.s
.section
!= NULL
)
11746 sections
->str_offsets
.s
.section
= sectp
;
11747 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11751 /* No other kind of section is valid. */
11758 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11759 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11760 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11761 This is for DWP version 1 files. */
11763 static struct dwo_unit
*
11764 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11765 struct dwp_file
*dwp_file
,
11766 uint32_t unit_index
,
11767 const char *comp_dir
,
11768 ULONGEST signature
, int is_debug_types
)
11770 const struct dwp_hash_table
*dwp_htab
=
11771 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11772 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11773 const char *kind
= is_debug_types
? "TU" : "CU";
11774 struct dwo_file
*dwo_file
;
11775 struct dwo_unit
*dwo_unit
;
11776 struct virtual_v1_dwo_sections sections
;
11777 void **dwo_file_slot
;
11780 gdb_assert (dwp_file
->version
== 1);
11782 if (dwarf_read_debug
)
11784 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11786 pulongest (unit_index
), hex_string (signature
),
11790 /* Fetch the sections of this DWO unit.
11791 Put a limit on the number of sections we look for so that bad data
11792 doesn't cause us to loop forever. */
11794 #define MAX_NR_V1_DWO_SECTIONS \
11795 (1 /* .debug_info or .debug_types */ \
11796 + 1 /* .debug_abbrev */ \
11797 + 1 /* .debug_line */ \
11798 + 1 /* .debug_loc */ \
11799 + 1 /* .debug_str_offsets */ \
11800 + 1 /* .debug_macro or .debug_macinfo */ \
11801 + 1 /* trailing zero */)
11803 memset (§ions
, 0, sizeof (sections
));
11805 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11808 uint32_t section_nr
=
11809 read_4_bytes (dbfd
,
11810 dwp_htab
->section_pool
.v1
.indices
11811 + (unit_index
+ i
) * sizeof (uint32_t));
11813 if (section_nr
== 0)
11815 if (section_nr
>= dwp_file
->num_sections
)
11817 error (_("Dwarf Error: bad DWP hash table, section number too large"
11818 " [in module %s]"),
11822 sectp
= dwp_file
->elf_sections
[section_nr
];
11823 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11825 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11826 " [in module %s]"),
11832 || sections
.info_or_types
.empty ()
11833 || sections
.abbrev
.empty ())
11835 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11836 " [in module %s]"),
11839 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11841 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11842 " [in module %s]"),
11846 /* It's easier for the rest of the code if we fake a struct dwo_file and
11847 have dwo_unit "live" in that. At least for now.
11849 The DWP file can be made up of a random collection of CUs and TUs.
11850 However, for each CU + set of TUs that came from the same original DWO
11851 file, we can combine them back into a virtual DWO file to save space
11852 (fewer struct dwo_file objects to allocate). Remember that for really
11853 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11855 std::string virtual_dwo_name
=
11856 string_printf ("virtual-dwo/%d-%d-%d-%d",
11857 sections
.abbrev
.get_id (),
11858 sections
.line
.get_id (),
11859 sections
.loc
.get_id (),
11860 sections
.str_offsets
.get_id ());
11861 /* Can we use an existing virtual DWO file? */
11862 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11863 virtual_dwo_name
.c_str (),
11865 /* Create one if necessary. */
11866 if (*dwo_file_slot
== NULL
)
11868 if (dwarf_read_debug
)
11870 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11871 virtual_dwo_name
.c_str ());
11873 dwo_file
= new struct dwo_file
;
11874 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
11875 dwo_file
->comp_dir
= comp_dir
;
11876 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11877 dwo_file
->sections
.line
= sections
.line
;
11878 dwo_file
->sections
.loc
= sections
.loc
;
11879 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11880 dwo_file
->sections
.macro
= sections
.macro
;
11881 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11882 /* The "str" section is global to the entire DWP file. */
11883 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11884 /* The info or types section is assigned below to dwo_unit,
11885 there's no need to record it in dwo_file.
11886 Also, we can't simply record type sections in dwo_file because
11887 we record a pointer into the vector in dwo_unit. As we collect more
11888 types we'll grow the vector and eventually have to reallocate space
11889 for it, invalidating all copies of pointers into the previous
11891 *dwo_file_slot
= dwo_file
;
11895 if (dwarf_read_debug
)
11897 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11898 virtual_dwo_name
.c_str ());
11900 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11903 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11904 dwo_unit
->dwo_file
= dwo_file
;
11905 dwo_unit
->signature
= signature
;
11906 dwo_unit
->section
=
11907 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11908 *dwo_unit
->section
= sections
.info_or_types
;
11909 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11914 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11915 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11916 piece within that section used by a TU/CU, return a virtual section
11917 of just that piece. */
11919 static struct dwarf2_section_info
11920 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11921 struct dwarf2_section_info
*section
,
11922 bfd_size_type offset
, bfd_size_type size
)
11924 struct dwarf2_section_info result
;
11927 gdb_assert (section
!= NULL
);
11928 gdb_assert (!section
->is_virtual
);
11930 memset (&result
, 0, sizeof (result
));
11931 result
.s
.containing_section
= section
;
11932 result
.is_virtual
= true;
11937 sectp
= section
->get_bfd_section ();
11939 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11940 bounds of the real section. This is a pretty-rare event, so just
11941 flag an error (easier) instead of a warning and trying to cope. */
11943 || offset
+ size
> bfd_section_size (sectp
))
11945 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11946 " in section %s [in module %s]"),
11947 sectp
? bfd_section_name (sectp
) : "<unknown>",
11948 objfile_name (dwarf2_per_objfile
->objfile
));
11951 result
.virtual_offset
= offset
;
11952 result
.size
= size
;
11956 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11957 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11958 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11959 This is for DWP version 2 files. */
11961 static struct dwo_unit
*
11962 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11963 struct dwp_file
*dwp_file
,
11964 uint32_t unit_index
,
11965 const char *comp_dir
,
11966 ULONGEST signature
, int is_debug_types
)
11968 const struct dwp_hash_table
*dwp_htab
=
11969 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11970 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11971 const char *kind
= is_debug_types
? "TU" : "CU";
11972 struct dwo_file
*dwo_file
;
11973 struct dwo_unit
*dwo_unit
;
11974 struct virtual_v2_dwo_sections sections
;
11975 void **dwo_file_slot
;
11978 gdb_assert (dwp_file
->version
== 2);
11980 if (dwarf_read_debug
)
11982 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11984 pulongest (unit_index
), hex_string (signature
),
11988 /* Fetch the section offsets of this DWO unit. */
11990 memset (§ions
, 0, sizeof (sections
));
11992 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11994 uint32_t offset
= read_4_bytes (dbfd
,
11995 dwp_htab
->section_pool
.v2
.offsets
11996 + (((unit_index
- 1) * dwp_htab
->nr_columns
11998 * sizeof (uint32_t)));
11999 uint32_t size
= read_4_bytes (dbfd
,
12000 dwp_htab
->section_pool
.v2
.sizes
12001 + (((unit_index
- 1) * dwp_htab
->nr_columns
12003 * sizeof (uint32_t)));
12005 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12008 case DW_SECT_TYPES
:
12009 sections
.info_or_types_offset
= offset
;
12010 sections
.info_or_types_size
= size
;
12012 case DW_SECT_ABBREV
:
12013 sections
.abbrev_offset
= offset
;
12014 sections
.abbrev_size
= size
;
12017 sections
.line_offset
= offset
;
12018 sections
.line_size
= size
;
12021 sections
.loc_offset
= offset
;
12022 sections
.loc_size
= size
;
12024 case DW_SECT_STR_OFFSETS
:
12025 sections
.str_offsets_offset
= offset
;
12026 sections
.str_offsets_size
= size
;
12028 case DW_SECT_MACINFO
:
12029 sections
.macinfo_offset
= offset
;
12030 sections
.macinfo_size
= size
;
12032 case DW_SECT_MACRO
:
12033 sections
.macro_offset
= offset
;
12034 sections
.macro_size
= size
;
12039 /* It's easier for the rest of the code if we fake a struct dwo_file and
12040 have dwo_unit "live" in that. At least for now.
12042 The DWP file can be made up of a random collection of CUs and TUs.
12043 However, for each CU + set of TUs that came from the same original DWO
12044 file, we can combine them back into a virtual DWO file to save space
12045 (fewer struct dwo_file objects to allocate). Remember that for really
12046 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12048 std::string virtual_dwo_name
=
12049 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12050 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12051 (long) (sections
.line_size
? sections
.line_offset
: 0),
12052 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12053 (long) (sections
.str_offsets_size
12054 ? sections
.str_offsets_offset
: 0));
12055 /* Can we use an existing virtual DWO file? */
12056 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12057 virtual_dwo_name
.c_str (),
12059 /* Create one if necessary. */
12060 if (*dwo_file_slot
== NULL
)
12062 if (dwarf_read_debug
)
12064 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12065 virtual_dwo_name
.c_str ());
12067 dwo_file
= new struct dwo_file
;
12068 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
12069 dwo_file
->comp_dir
= comp_dir
;
12070 dwo_file
->sections
.abbrev
=
12071 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12072 sections
.abbrev_offset
, sections
.abbrev_size
);
12073 dwo_file
->sections
.line
=
12074 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12075 sections
.line_offset
, sections
.line_size
);
12076 dwo_file
->sections
.loc
=
12077 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12078 sections
.loc_offset
, sections
.loc_size
);
12079 dwo_file
->sections
.macinfo
=
12080 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12081 sections
.macinfo_offset
, sections
.macinfo_size
);
12082 dwo_file
->sections
.macro
=
12083 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12084 sections
.macro_offset
, sections
.macro_size
);
12085 dwo_file
->sections
.str_offsets
=
12086 create_dwp_v2_section (dwarf2_per_objfile
,
12087 &dwp_file
->sections
.str_offsets
,
12088 sections
.str_offsets_offset
,
12089 sections
.str_offsets_size
);
12090 /* The "str" section is global to the entire DWP file. */
12091 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12092 /* The info or types section is assigned below to dwo_unit,
12093 there's no need to record it in dwo_file.
12094 Also, we can't simply record type sections in dwo_file because
12095 we record a pointer into the vector in dwo_unit. As we collect more
12096 types we'll grow the vector and eventually have to reallocate space
12097 for it, invalidating all copies of pointers into the previous
12099 *dwo_file_slot
= dwo_file
;
12103 if (dwarf_read_debug
)
12105 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12106 virtual_dwo_name
.c_str ());
12108 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12111 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12112 dwo_unit
->dwo_file
= dwo_file
;
12113 dwo_unit
->signature
= signature
;
12114 dwo_unit
->section
=
12115 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12116 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12118 ? &dwp_file
->sections
.types
12119 : &dwp_file
->sections
.info
,
12120 sections
.info_or_types_offset
,
12121 sections
.info_or_types_size
);
12122 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12127 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12128 Returns NULL if the signature isn't found. */
12130 static struct dwo_unit
*
12131 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12132 struct dwp_file
*dwp_file
, const char *comp_dir
,
12133 ULONGEST signature
, int is_debug_types
)
12135 const struct dwp_hash_table
*dwp_htab
=
12136 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12137 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12138 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12139 uint32_t hash
= signature
& mask
;
12140 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12143 struct dwo_unit find_dwo_cu
;
12145 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12146 find_dwo_cu
.signature
= signature
;
12147 slot
= htab_find_slot (is_debug_types
12148 ? dwp_file
->loaded_tus
.get ()
12149 : dwp_file
->loaded_cus
.get (),
12150 &find_dwo_cu
, INSERT
);
12153 return (struct dwo_unit
*) *slot
;
12155 /* Use a for loop so that we don't loop forever on bad debug info. */
12156 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12158 ULONGEST signature_in_table
;
12160 signature_in_table
=
12161 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12162 if (signature_in_table
== signature
)
12164 uint32_t unit_index
=
12165 read_4_bytes (dbfd
,
12166 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12168 if (dwp_file
->version
== 1)
12170 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12171 dwp_file
, unit_index
,
12172 comp_dir
, signature
,
12177 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12178 dwp_file
, unit_index
,
12179 comp_dir
, signature
,
12182 return (struct dwo_unit
*) *slot
;
12184 if (signature_in_table
== 0)
12186 hash
= (hash
+ hash2
) & mask
;
12189 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12190 " [in module %s]"),
12194 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12195 Open the file specified by FILE_NAME and hand it off to BFD for
12196 preliminary analysis. Return a newly initialized bfd *, which
12197 includes a canonicalized copy of FILE_NAME.
12198 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12199 SEARCH_CWD is true if the current directory is to be searched.
12200 It will be searched before debug-file-directory.
12201 If successful, the file is added to the bfd include table of the
12202 objfile's bfd (see gdb_bfd_record_inclusion).
12203 If unable to find/open the file, return NULL.
12204 NOTE: This function is derived from symfile_bfd_open. */
12206 static gdb_bfd_ref_ptr
12207 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12208 const char *file_name
, int is_dwp
, int search_cwd
)
12211 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12212 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12213 to debug_file_directory. */
12214 const char *search_path
;
12215 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12217 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12220 if (*debug_file_directory
!= '\0')
12222 search_path_holder
.reset (concat (".", dirname_separator_string
,
12223 debug_file_directory
,
12225 search_path
= search_path_holder
.get ();
12231 search_path
= debug_file_directory
;
12233 openp_flags flags
= OPF_RETURN_REALPATH
;
12235 flags
|= OPF_SEARCH_IN_PATH
;
12237 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12238 desc
= openp (search_path
, flags
, file_name
,
12239 O_RDONLY
| O_BINARY
, &absolute_name
);
12243 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12245 if (sym_bfd
== NULL
)
12247 bfd_set_cacheable (sym_bfd
.get (), 1);
12249 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12252 /* Success. Record the bfd as having been included by the objfile's bfd.
12253 This is important because things like demangled_names_hash lives in the
12254 objfile's per_bfd space and may have references to things like symbol
12255 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12256 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12261 /* Try to open DWO file FILE_NAME.
12262 COMP_DIR is the DW_AT_comp_dir attribute.
12263 The result is the bfd handle of the file.
12264 If there is a problem finding or opening the file, return NULL.
12265 Upon success, the canonicalized path of the file is stored in the bfd,
12266 same as symfile_bfd_open. */
12268 static gdb_bfd_ref_ptr
12269 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12270 const char *file_name
, const char *comp_dir
)
12272 if (IS_ABSOLUTE_PATH (file_name
))
12273 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12274 0 /*is_dwp*/, 0 /*search_cwd*/);
12276 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12278 if (comp_dir
!= NULL
)
12280 gdb::unique_xmalloc_ptr
<char> path_to_try
12281 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12283 /* NOTE: If comp_dir is a relative path, this will also try the
12284 search path, which seems useful. */
12285 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12286 path_to_try
.get (),
12288 1 /*search_cwd*/));
12293 /* That didn't work, try debug-file-directory, which, despite its name,
12294 is a list of paths. */
12296 if (*debug_file_directory
== '\0')
12299 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12300 0 /*is_dwp*/, 1 /*search_cwd*/);
12303 /* This function is mapped across the sections and remembers the offset and
12304 size of each of the DWO debugging sections we are interested in. */
12307 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12309 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12310 const struct dwop_section_names
*names
= &dwop_section_names
;
12312 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12314 dwo_sections
->abbrev
.s
.section
= sectp
;
12315 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12317 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12319 dwo_sections
->info
.s
.section
= sectp
;
12320 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12322 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12324 dwo_sections
->line
.s
.section
= sectp
;
12325 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12327 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12329 dwo_sections
->loc
.s
.section
= sectp
;
12330 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12332 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12334 dwo_sections
->loclists
.s
.section
= sectp
;
12335 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12337 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12339 dwo_sections
->macinfo
.s
.section
= sectp
;
12340 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12342 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12344 dwo_sections
->macro
.s
.section
= sectp
;
12345 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12347 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12349 dwo_sections
->str
.s
.section
= sectp
;
12350 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12352 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12354 dwo_sections
->str_offsets
.s
.section
= sectp
;
12355 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12357 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12359 struct dwarf2_section_info type_section
;
12361 memset (&type_section
, 0, sizeof (type_section
));
12362 type_section
.s
.section
= sectp
;
12363 type_section
.size
= bfd_section_size (sectp
);
12364 dwo_sections
->types
.push_back (type_section
);
12368 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12369 by PER_CU. This is for the non-DWP case.
12370 The result is NULL if DWO_NAME can't be found. */
12372 static struct dwo_file
*
12373 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12374 const char *comp_dir
)
12376 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12378 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12381 if (dwarf_read_debug
)
12382 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12386 dwo_file_up
dwo_file (new struct dwo_file
);
12387 dwo_file
->dwo_name
= dwo_name
;
12388 dwo_file
->comp_dir
= comp_dir
;
12389 dwo_file
->dbfd
= std::move (dbfd
);
12391 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12392 &dwo_file
->sections
);
12394 create_cus_hash_table (dwarf2_per_objfile
, cu
, *dwo_file
,
12395 dwo_file
->sections
.info
, dwo_file
->cus
);
12397 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12398 dwo_file
->sections
.types
, dwo_file
->tus
);
12400 if (dwarf_read_debug
)
12401 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12403 return dwo_file
.release ();
12406 /* This function is mapped across the sections and remembers the offset and
12407 size of each of the DWP debugging sections common to version 1 and 2 that
12408 we are interested in. */
12411 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12412 void *dwp_file_ptr
)
12414 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12415 const struct dwop_section_names
*names
= &dwop_section_names
;
12416 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12418 /* Record the ELF section number for later lookup: this is what the
12419 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12420 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12421 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12423 /* Look for specific sections that we need. */
12424 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12426 dwp_file
->sections
.str
.s
.section
= sectp
;
12427 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12429 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12431 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12432 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12434 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12436 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12437 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12441 /* This function is mapped across the sections and remembers the offset and
12442 size of each of the DWP version 2 debugging sections that we are interested
12443 in. This is split into a separate function because we don't know if we
12444 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12447 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12449 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12450 const struct dwop_section_names
*names
= &dwop_section_names
;
12451 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12453 /* Record the ELF section number for later lookup: this is what the
12454 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12455 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12456 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12458 /* Look for specific sections that we need. */
12459 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12461 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12462 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12464 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12466 dwp_file
->sections
.info
.s
.section
= sectp
;
12467 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12469 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12471 dwp_file
->sections
.line
.s
.section
= sectp
;
12472 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12474 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12476 dwp_file
->sections
.loc
.s
.section
= sectp
;
12477 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12479 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12481 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12482 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12484 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12486 dwp_file
->sections
.macro
.s
.section
= sectp
;
12487 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12489 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12491 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12492 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12494 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12496 dwp_file
->sections
.types
.s
.section
= sectp
;
12497 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12501 /* Hash function for dwp_file loaded CUs/TUs. */
12504 hash_dwp_loaded_cutus (const void *item
)
12506 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12508 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12509 return dwo_unit
->signature
;
12512 /* Equality function for dwp_file loaded CUs/TUs. */
12515 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12517 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12518 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12520 return dua
->signature
== dub
->signature
;
12523 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12526 allocate_dwp_loaded_cutus_table ()
12528 return htab_up (htab_create_alloc (3,
12529 hash_dwp_loaded_cutus
,
12530 eq_dwp_loaded_cutus
,
12531 NULL
, xcalloc
, xfree
));
12534 /* Try to open DWP file FILE_NAME.
12535 The result is the bfd handle of the file.
12536 If there is a problem finding or opening the file, return NULL.
12537 Upon success, the canonicalized path of the file is stored in the bfd,
12538 same as symfile_bfd_open. */
12540 static gdb_bfd_ref_ptr
12541 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12542 const char *file_name
)
12544 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12546 1 /*search_cwd*/));
12550 /* Work around upstream bug 15652.
12551 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12552 [Whether that's a "bug" is debatable, but it is getting in our way.]
12553 We have no real idea where the dwp file is, because gdb's realpath-ing
12554 of the executable's path may have discarded the needed info.
12555 [IWBN if the dwp file name was recorded in the executable, akin to
12556 .gnu_debuglink, but that doesn't exist yet.]
12557 Strip the directory from FILE_NAME and search again. */
12558 if (*debug_file_directory
!= '\0')
12560 /* Don't implicitly search the current directory here.
12561 If the user wants to search "." to handle this case,
12562 it must be added to debug-file-directory. */
12563 return try_open_dwop_file (dwarf2_per_objfile
,
12564 lbasename (file_name
), 1 /*is_dwp*/,
12571 /* Initialize the use of the DWP file for the current objfile.
12572 By convention the name of the DWP file is ${objfile}.dwp.
12573 The result is NULL if it can't be found. */
12575 static std::unique_ptr
<struct dwp_file
>
12576 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12578 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12580 /* Try to find first .dwp for the binary file before any symbolic links
12583 /* If the objfile is a debug file, find the name of the real binary
12584 file and get the name of dwp file from there. */
12585 std::string dwp_name
;
12586 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12588 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12589 const char *backlink_basename
= lbasename (backlink
->original_name
);
12591 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12594 dwp_name
= objfile
->original_name
;
12596 dwp_name
+= ".dwp";
12598 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12600 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12602 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12603 dwp_name
= objfile_name (objfile
);
12604 dwp_name
+= ".dwp";
12605 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12610 if (dwarf_read_debug
)
12611 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12612 return std::unique_ptr
<dwp_file
> ();
12615 const char *name
= bfd_get_filename (dbfd
.get ());
12616 std::unique_ptr
<struct dwp_file
> dwp_file
12617 (new struct dwp_file (name
, std::move (dbfd
)));
12619 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12620 dwp_file
->elf_sections
=
12621 OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
12622 dwp_file
->num_sections
, asection
*);
12624 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12625 dwarf2_locate_common_dwp_sections
,
12628 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12631 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12634 /* The DWP file version is stored in the hash table. Oh well. */
12635 if (dwp_file
->cus
&& dwp_file
->tus
12636 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12638 /* Technically speaking, we should try to limp along, but this is
12639 pretty bizarre. We use pulongest here because that's the established
12640 portability solution (e.g, we cannot use %u for uint32_t). */
12641 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12642 " TU version %s [in DWP file %s]"),
12643 pulongest (dwp_file
->cus
->version
),
12644 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12648 dwp_file
->version
= dwp_file
->cus
->version
;
12649 else if (dwp_file
->tus
)
12650 dwp_file
->version
= dwp_file
->tus
->version
;
12652 dwp_file
->version
= 2;
12654 if (dwp_file
->version
== 2)
12655 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12656 dwarf2_locate_v2_dwp_sections
,
12659 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12660 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12662 if (dwarf_read_debug
)
12664 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12665 fprintf_unfiltered (gdb_stdlog
,
12666 " %s CUs, %s TUs\n",
12667 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12668 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12674 /* Wrapper around open_and_init_dwp_file, only open it once. */
12676 static struct dwp_file
*
12677 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12679 if (! dwarf2_per_objfile
->per_bfd
->dwp_checked
)
12681 dwarf2_per_objfile
->per_bfd
->dwp_file
12682 = open_and_init_dwp_file (dwarf2_per_objfile
);
12683 dwarf2_per_objfile
->per_bfd
->dwp_checked
= 1;
12685 return dwarf2_per_objfile
->per_bfd
->dwp_file
.get ();
12688 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12689 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12690 or in the DWP file for the objfile, referenced by THIS_UNIT.
12691 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12692 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12694 This is called, for example, when wanting to read a variable with a
12695 complex location. Therefore we don't want to do file i/o for every call.
12696 Therefore we don't want to look for a DWO file on every call.
12697 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12698 then we check if we've already seen DWO_NAME, and only THEN do we check
12701 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12702 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12704 static struct dwo_unit
*
12705 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12706 ULONGEST signature
, int is_debug_types
)
12708 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12709 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12710 const char *kind
= is_debug_types
? "TU" : "CU";
12711 void **dwo_file_slot
;
12712 struct dwo_file
*dwo_file
;
12713 struct dwp_file
*dwp_file
;
12715 /* First see if there's a DWP file.
12716 If we have a DWP file but didn't find the DWO inside it, don't
12717 look for the original DWO file. It makes gdb behave differently
12718 depending on whether one is debugging in the build tree. */
12720 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12721 if (dwp_file
!= NULL
)
12723 const struct dwp_hash_table
*dwp_htab
=
12724 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12726 if (dwp_htab
!= NULL
)
12728 struct dwo_unit
*dwo_cutu
=
12729 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12730 signature
, is_debug_types
);
12732 if (dwo_cutu
!= NULL
)
12734 if (dwarf_read_debug
)
12736 fprintf_unfiltered (gdb_stdlog
,
12737 "Virtual DWO %s %s found: @%s\n",
12738 kind
, hex_string (signature
),
12739 host_address_to_string (dwo_cutu
));
12747 /* No DWP file, look for the DWO file. */
12749 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12750 dwo_name
, comp_dir
);
12751 if (*dwo_file_slot
== NULL
)
12753 /* Read in the file and build a table of the CUs/TUs it contains. */
12754 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12756 /* NOTE: This will be NULL if unable to open the file. */
12757 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12759 if (dwo_file
!= NULL
)
12761 struct dwo_unit
*dwo_cutu
= NULL
;
12763 if (is_debug_types
&& dwo_file
->tus
)
12765 struct dwo_unit find_dwo_cutu
;
12767 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12768 find_dwo_cutu
.signature
= signature
;
12770 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12773 else if (!is_debug_types
&& dwo_file
->cus
)
12775 struct dwo_unit find_dwo_cutu
;
12777 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12778 find_dwo_cutu
.signature
= signature
;
12779 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12783 if (dwo_cutu
!= NULL
)
12785 if (dwarf_read_debug
)
12787 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12788 kind
, dwo_name
, hex_string (signature
),
12789 host_address_to_string (dwo_cutu
));
12796 /* We didn't find it. This could mean a dwo_id mismatch, or
12797 someone deleted the DWO/DWP file, or the search path isn't set up
12798 correctly to find the file. */
12800 if (dwarf_read_debug
)
12802 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12803 kind
, dwo_name
, hex_string (signature
));
12806 /* This is a warning and not a complaint because it can be caused by
12807 pilot error (e.g., user accidentally deleting the DWO). */
12809 /* Print the name of the DWP file if we looked there, helps the user
12810 better diagnose the problem. */
12811 std::string dwp_text
;
12813 if (dwp_file
!= NULL
)
12814 dwp_text
= string_printf (" [in DWP file %s]",
12815 lbasename (dwp_file
->name
));
12817 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12818 " [in module %s]"),
12819 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12820 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12825 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12826 See lookup_dwo_cutu_unit for details. */
12828 static struct dwo_unit
*
12829 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12830 ULONGEST signature
)
12832 gdb_assert (!cu
->per_cu
->is_debug_types
);
12834 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12837 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12838 See lookup_dwo_cutu_unit for details. */
12840 static struct dwo_unit
*
12841 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12843 gdb_assert (cu
->per_cu
->is_debug_types
);
12845 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12847 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12850 /* Traversal function for queue_and_load_all_dwo_tus. */
12853 queue_and_load_dwo_tu (void **slot
, void *info
)
12855 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12856 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12857 ULONGEST signature
= dwo_unit
->signature
;
12858 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12860 if (sig_type
!= NULL
)
12862 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12864 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12865 a real dependency of PER_CU on SIG_TYPE. That is detected later
12866 while processing PER_CU. */
12867 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
12868 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12869 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12875 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12876 The DWO may have the only definition of the type, though it may not be
12877 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12878 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12881 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12883 struct dwo_unit
*dwo_unit
;
12884 struct dwo_file
*dwo_file
;
12886 gdb_assert (!per_cu
->is_debug_types
);
12887 gdb_assert (per_cu
->cu
!= NULL
);
12888 gdb_assert (get_dwp_file (per_cu
->cu
->per_objfile
) == NULL
);
12890 dwo_unit
= per_cu
->cu
->dwo_unit
;
12891 gdb_assert (dwo_unit
!= NULL
);
12893 dwo_file
= dwo_unit
->dwo_file
;
12894 if (dwo_file
->tus
!= NULL
)
12895 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12899 /* Read in various DIEs. */
12901 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12902 Inherit only the children of the DW_AT_abstract_origin DIE not being
12903 already referenced by DW_AT_abstract_origin from the children of the
12907 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12909 struct die_info
*child_die
;
12910 sect_offset
*offsetp
;
12911 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12912 struct die_info
*origin_die
;
12913 /* Iterator of the ORIGIN_DIE children. */
12914 struct die_info
*origin_child_die
;
12915 struct attribute
*attr
;
12916 struct dwarf2_cu
*origin_cu
;
12917 struct pending
**origin_previous_list_in_scope
;
12919 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12923 /* Note that following die references may follow to a die in a
12927 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12929 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12931 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12932 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12934 if (die
->tag
!= origin_die
->tag
12935 && !(die
->tag
== DW_TAG_inlined_subroutine
12936 && origin_die
->tag
== DW_TAG_subprogram
))
12937 complaint (_("DIE %s and its abstract origin %s have different tags"),
12938 sect_offset_str (die
->sect_off
),
12939 sect_offset_str (origin_die
->sect_off
));
12941 std::vector
<sect_offset
> offsets
;
12943 for (child_die
= die
->child
;
12944 child_die
&& child_die
->tag
;
12945 child_die
= child_die
->sibling
)
12947 struct die_info
*child_origin_die
;
12948 struct dwarf2_cu
*child_origin_cu
;
12950 /* We are trying to process concrete instance entries:
12951 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12952 it's not relevant to our analysis here. i.e. detecting DIEs that are
12953 present in the abstract instance but not referenced in the concrete
12955 if (child_die
->tag
== DW_TAG_call_site
12956 || child_die
->tag
== DW_TAG_GNU_call_site
)
12959 /* For each CHILD_DIE, find the corresponding child of
12960 ORIGIN_DIE. If there is more than one layer of
12961 DW_AT_abstract_origin, follow them all; there shouldn't be,
12962 but GCC versions at least through 4.4 generate this (GCC PR
12964 child_origin_die
= child_die
;
12965 child_origin_cu
= cu
;
12968 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12972 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12976 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12977 counterpart may exist. */
12978 if (child_origin_die
!= child_die
)
12980 if (child_die
->tag
!= child_origin_die
->tag
12981 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12982 && child_origin_die
->tag
== DW_TAG_subprogram
))
12983 complaint (_("Child DIE %s and its abstract origin %s have "
12985 sect_offset_str (child_die
->sect_off
),
12986 sect_offset_str (child_origin_die
->sect_off
));
12987 if (child_origin_die
->parent
!= origin_die
)
12988 complaint (_("Child DIE %s and its abstract origin %s have "
12989 "different parents"),
12990 sect_offset_str (child_die
->sect_off
),
12991 sect_offset_str (child_origin_die
->sect_off
));
12993 offsets
.push_back (child_origin_die
->sect_off
);
12996 std::sort (offsets
.begin (), offsets
.end ());
12997 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12998 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12999 if (offsetp
[-1] == *offsetp
)
13000 complaint (_("Multiple children of DIE %s refer "
13001 "to DIE %s as their abstract origin"),
13002 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13004 offsetp
= offsets
.data ();
13005 origin_child_die
= origin_die
->child
;
13006 while (origin_child_die
&& origin_child_die
->tag
)
13008 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13009 while (offsetp
< offsets_end
13010 && *offsetp
< origin_child_die
->sect_off
)
13012 if (offsetp
>= offsets_end
13013 || *offsetp
> origin_child_die
->sect_off
)
13015 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13016 Check whether we're already processing ORIGIN_CHILD_DIE.
13017 This can happen with mutually referenced abstract_origins.
13019 if (!origin_child_die
->in_process
)
13020 process_die (origin_child_die
, origin_cu
);
13022 origin_child_die
= origin_child_die
->sibling
;
13024 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13026 if (cu
!= origin_cu
)
13027 compute_delayed_physnames (origin_cu
);
13031 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13033 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13034 struct gdbarch
*gdbarch
= objfile
->arch ();
13035 struct context_stack
*newobj
;
13038 struct die_info
*child_die
;
13039 struct attribute
*attr
, *call_line
, *call_file
;
13041 CORE_ADDR baseaddr
;
13042 struct block
*block
;
13043 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13044 std::vector
<struct symbol
*> template_args
;
13045 struct template_symbol
*templ_func
= NULL
;
13049 /* If we do not have call site information, we can't show the
13050 caller of this inlined function. That's too confusing, so
13051 only use the scope for local variables. */
13052 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13053 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13054 if (call_line
== NULL
|| call_file
== NULL
)
13056 read_lexical_block_scope (die
, cu
);
13061 baseaddr
= objfile
->text_section_offset ();
13063 name
= dwarf2_name (die
, cu
);
13065 /* Ignore functions with missing or empty names. These are actually
13066 illegal according to the DWARF standard. */
13069 complaint (_("missing name for subprogram DIE at %s"),
13070 sect_offset_str (die
->sect_off
));
13074 /* Ignore functions with missing or invalid low and high pc attributes. */
13075 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13076 <= PC_BOUNDS_INVALID
)
13078 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13079 if (!attr
|| !DW_UNSND (attr
))
13080 complaint (_("cannot get low and high bounds "
13081 "for subprogram DIE at %s"),
13082 sect_offset_str (die
->sect_off
));
13086 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13087 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13089 /* If we have any template arguments, then we must allocate a
13090 different sort of symbol. */
13091 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13093 if (child_die
->tag
== DW_TAG_template_type_param
13094 || child_die
->tag
== DW_TAG_template_value_param
)
13096 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13097 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13102 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13103 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13104 (struct symbol
*) templ_func
);
13106 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13107 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13110 /* If there is a location expression for DW_AT_frame_base, record
13112 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13113 if (attr
!= nullptr)
13114 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13116 /* If there is a location for the static link, record it. */
13117 newobj
->static_link
= NULL
;
13118 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13119 if (attr
!= nullptr)
13121 newobj
->static_link
13122 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13123 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13127 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13129 if (die
->child
!= NULL
)
13131 child_die
= die
->child
;
13132 while (child_die
&& child_die
->tag
)
13134 if (child_die
->tag
== DW_TAG_template_type_param
13135 || child_die
->tag
== DW_TAG_template_value_param
)
13137 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13140 template_args
.push_back (arg
);
13143 process_die (child_die
, cu
);
13144 child_die
= child_die
->sibling
;
13148 inherit_abstract_dies (die
, cu
);
13150 /* If we have a DW_AT_specification, we might need to import using
13151 directives from the context of the specification DIE. See the
13152 comment in determine_prefix. */
13153 if (cu
->language
== language_cplus
13154 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13156 struct dwarf2_cu
*spec_cu
= cu
;
13157 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13161 child_die
= spec_die
->child
;
13162 while (child_die
&& child_die
->tag
)
13164 if (child_die
->tag
== DW_TAG_imported_module
)
13165 process_die (child_die
, spec_cu
);
13166 child_die
= child_die
->sibling
;
13169 /* In some cases, GCC generates specification DIEs that
13170 themselves contain DW_AT_specification attributes. */
13171 spec_die
= die_specification (spec_die
, &spec_cu
);
13175 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13176 /* Make a block for the local symbols within. */
13177 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13178 cstk
.static_link
, lowpc
, highpc
);
13180 /* For C++, set the block's scope. */
13181 if ((cu
->language
== language_cplus
13182 || cu
->language
== language_fortran
13183 || cu
->language
== language_d
13184 || cu
->language
== language_rust
)
13185 && cu
->processing_has_namespace_info
)
13186 block_set_scope (block
, determine_prefix (die
, cu
),
13187 &objfile
->objfile_obstack
);
13189 /* If we have address ranges, record them. */
13190 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13192 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13194 /* Attach template arguments to function. */
13195 if (!template_args
.empty ())
13197 gdb_assert (templ_func
!= NULL
);
13199 templ_func
->n_template_arguments
= template_args
.size ();
13200 templ_func
->template_arguments
13201 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13202 templ_func
->n_template_arguments
);
13203 memcpy (templ_func
->template_arguments
,
13204 template_args
.data (),
13205 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13207 /* Make sure that the symtab is set on the new symbols. Even
13208 though they don't appear in this symtab directly, other parts
13209 of gdb assume that symbols do, and this is reasonably
13211 for (symbol
*sym
: template_args
)
13212 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13215 /* In C++, we can have functions nested inside functions (e.g., when
13216 a function declares a class that has methods). This means that
13217 when we finish processing a function scope, we may need to go
13218 back to building a containing block's symbol lists. */
13219 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13220 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13222 /* If we've finished processing a top-level function, subsequent
13223 symbols go in the file symbol list. */
13224 if (cu
->get_builder ()->outermost_context_p ())
13225 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13228 /* Process all the DIES contained within a lexical block scope. Start
13229 a new scope, process the dies, and then close the scope. */
13232 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13234 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13235 struct gdbarch
*gdbarch
= objfile
->arch ();
13236 CORE_ADDR lowpc
, highpc
;
13237 struct die_info
*child_die
;
13238 CORE_ADDR baseaddr
;
13240 baseaddr
= objfile
->text_section_offset ();
13242 /* Ignore blocks with missing or invalid low and high pc attributes. */
13243 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13244 as multiple lexical blocks? Handling children in a sane way would
13245 be nasty. Might be easier to properly extend generic blocks to
13246 describe ranges. */
13247 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13249 case PC_BOUNDS_NOT_PRESENT
:
13250 /* DW_TAG_lexical_block has no attributes, process its children as if
13251 there was no wrapping by that DW_TAG_lexical_block.
13252 GCC does no longer produces such DWARF since GCC r224161. */
13253 for (child_die
= die
->child
;
13254 child_die
!= NULL
&& child_die
->tag
;
13255 child_die
= child_die
->sibling
)
13257 /* We might already be processing this DIE. This can happen
13258 in an unusual circumstance -- where a subroutine A
13259 appears lexically in another subroutine B, but A actually
13260 inlines B. The recursion is broken here, rather than in
13261 inherit_abstract_dies, because it seems better to simply
13262 drop concrete children here. */
13263 if (!child_die
->in_process
)
13264 process_die (child_die
, cu
);
13267 case PC_BOUNDS_INVALID
:
13270 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13271 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13273 cu
->get_builder ()->push_context (0, lowpc
);
13274 if (die
->child
!= NULL
)
13276 child_die
= die
->child
;
13277 while (child_die
&& child_die
->tag
)
13279 process_die (child_die
, cu
);
13280 child_die
= child_die
->sibling
;
13283 inherit_abstract_dies (die
, cu
);
13284 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13286 if (*cu
->get_builder ()->get_local_symbols () != NULL
13287 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13289 struct block
*block
13290 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13291 cstk
.start_addr
, highpc
);
13293 /* Note that recording ranges after traversing children, as we
13294 do here, means that recording a parent's ranges entails
13295 walking across all its children's ranges as they appear in
13296 the address map, which is quadratic behavior.
13298 It would be nicer to record the parent's ranges before
13299 traversing its children, simply overriding whatever you find
13300 there. But since we don't even decide whether to create a
13301 block until after we've traversed its children, that's hard
13303 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13305 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13306 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13309 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13312 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13314 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13315 struct objfile
*objfile
= per_objfile
->objfile
;
13316 struct gdbarch
*gdbarch
= objfile
->arch ();
13317 CORE_ADDR pc
, baseaddr
;
13318 struct attribute
*attr
;
13319 struct call_site
*call_site
, call_site_local
;
13322 struct die_info
*child_die
;
13324 baseaddr
= objfile
->text_section_offset ();
13326 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13329 /* This was a pre-DWARF-5 GNU extension alias
13330 for DW_AT_call_return_pc. */
13331 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13335 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13336 "DIE %s [in module %s]"),
13337 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13340 pc
= attr
->value_as_address () + baseaddr
;
13341 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13343 if (cu
->call_site_htab
== NULL
)
13344 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13345 NULL
, &objfile
->objfile_obstack
,
13346 hashtab_obstack_allocate
, NULL
);
13347 call_site_local
.pc
= pc
;
13348 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13351 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13352 "DIE %s [in module %s]"),
13353 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13354 objfile_name (objfile
));
13358 /* Count parameters at the caller. */
13361 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13362 child_die
= child_die
->sibling
)
13364 if (child_die
->tag
!= DW_TAG_call_site_parameter
13365 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13367 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13368 "DW_TAG_call_site child DIE %s [in module %s]"),
13369 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13370 objfile_name (objfile
));
13378 = ((struct call_site
*)
13379 obstack_alloc (&objfile
->objfile_obstack
,
13380 sizeof (*call_site
)
13381 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13383 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13384 call_site
->pc
= pc
;
13386 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13387 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13389 struct die_info
*func_die
;
13391 /* Skip also over DW_TAG_inlined_subroutine. */
13392 for (func_die
= die
->parent
;
13393 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13394 && func_die
->tag
!= DW_TAG_subroutine_type
;
13395 func_die
= func_die
->parent
);
13397 /* DW_AT_call_all_calls is a superset
13398 of DW_AT_call_all_tail_calls. */
13400 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13401 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13402 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13403 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13405 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13406 not complete. But keep CALL_SITE for look ups via call_site_htab,
13407 both the initial caller containing the real return address PC and
13408 the final callee containing the current PC of a chain of tail
13409 calls do not need to have the tail call list complete. But any
13410 function candidate for a virtual tail call frame searched via
13411 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13412 determined unambiguously. */
13416 struct type
*func_type
= NULL
;
13419 func_type
= get_die_type (func_die
, cu
);
13420 if (func_type
!= NULL
)
13422 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13424 /* Enlist this call site to the function. */
13425 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13426 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13429 complaint (_("Cannot find function owning DW_TAG_call_site "
13430 "DIE %s [in module %s]"),
13431 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13435 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13437 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13439 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13442 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13443 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13445 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13446 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13447 /* Keep NULL DWARF_BLOCK. */;
13448 else if (attr
->form_is_block ())
13450 struct dwarf2_locexpr_baton
*dlbaton
;
13452 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13453 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13454 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13455 dlbaton
->per_objfile
= per_objfile
;
13456 dlbaton
->per_cu
= cu
->per_cu
;
13458 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13460 else if (attr
->form_is_ref ())
13462 struct dwarf2_cu
*target_cu
= cu
;
13463 struct die_info
*target_die
;
13465 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13466 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13467 if (die_is_declaration (target_die
, target_cu
))
13469 const char *target_physname
;
13471 /* Prefer the mangled name; otherwise compute the demangled one. */
13472 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13473 if (target_physname
== NULL
)
13474 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13475 if (target_physname
== NULL
)
13476 complaint (_("DW_AT_call_target target DIE has invalid "
13477 "physname, for referencing DIE %s [in module %s]"),
13478 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13480 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13486 /* DW_AT_entry_pc should be preferred. */
13487 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13488 <= PC_BOUNDS_INVALID
)
13489 complaint (_("DW_AT_call_target target DIE has invalid "
13490 "low pc, for referencing DIE %s [in module %s]"),
13491 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13494 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13495 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13500 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13501 "block nor reference, for DIE %s [in module %s]"),
13502 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13504 call_site
->per_cu
= cu
->per_cu
;
13505 call_site
->per_objfile
= per_objfile
;
13507 for (child_die
= die
->child
;
13508 child_die
&& child_die
->tag
;
13509 child_die
= child_die
->sibling
)
13511 struct call_site_parameter
*parameter
;
13512 struct attribute
*loc
, *origin
;
13514 if (child_die
->tag
!= DW_TAG_call_site_parameter
13515 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13517 /* Already printed the complaint above. */
13521 gdb_assert (call_site
->parameter_count
< nparams
);
13522 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13524 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13525 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13526 register is contained in DW_AT_call_value. */
13528 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13529 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13530 if (origin
== NULL
)
13532 /* This was a pre-DWARF-5 GNU extension alias
13533 for DW_AT_call_parameter. */
13534 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13536 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13538 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13540 sect_offset sect_off
= origin
->get_ref_die_offset ();
13541 if (!cu
->header
.offset_in_cu_p (sect_off
))
13543 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13544 binding can be done only inside one CU. Such referenced DIE
13545 therefore cannot be even moved to DW_TAG_partial_unit. */
13546 complaint (_("DW_AT_call_parameter offset is not in CU for "
13547 "DW_TAG_call_site child DIE %s [in module %s]"),
13548 sect_offset_str (child_die
->sect_off
),
13549 objfile_name (objfile
));
13552 parameter
->u
.param_cu_off
13553 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13555 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13557 complaint (_("No DW_FORM_block* DW_AT_location for "
13558 "DW_TAG_call_site child DIE %s [in module %s]"),
13559 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13564 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13565 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13566 if (parameter
->u
.dwarf_reg
!= -1)
13567 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13568 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13569 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13570 ¶meter
->u
.fb_offset
))
13571 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13574 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13575 "for DW_FORM_block* DW_AT_location is supported for "
13576 "DW_TAG_call_site child DIE %s "
13578 sect_offset_str (child_die
->sect_off
),
13579 objfile_name (objfile
));
13584 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13586 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13587 if (attr
== NULL
|| !attr
->form_is_block ())
13589 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13590 "DW_TAG_call_site child DIE %s [in module %s]"),
13591 sect_offset_str (child_die
->sect_off
),
13592 objfile_name (objfile
));
13595 parameter
->value
= DW_BLOCK (attr
)->data
;
13596 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13598 /* Parameters are not pre-cleared by memset above. */
13599 parameter
->data_value
= NULL
;
13600 parameter
->data_value_size
= 0;
13601 call_site
->parameter_count
++;
13603 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13605 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13606 if (attr
!= nullptr)
13608 if (!attr
->form_is_block ())
13609 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13610 "DW_TAG_call_site child DIE %s [in module %s]"),
13611 sect_offset_str (child_die
->sect_off
),
13612 objfile_name (objfile
));
13615 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13616 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13622 /* Helper function for read_variable. If DIE represents a virtual
13623 table, then return the type of the concrete object that is
13624 associated with the virtual table. Otherwise, return NULL. */
13626 static struct type
*
13627 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13629 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13633 /* Find the type DIE. */
13634 struct die_info
*type_die
= NULL
;
13635 struct dwarf2_cu
*type_cu
= cu
;
13637 if (attr
->form_is_ref ())
13638 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13639 if (type_die
== NULL
)
13642 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13644 return die_containing_type (type_die
, type_cu
);
13647 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13650 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13652 struct rust_vtable_symbol
*storage
= NULL
;
13654 if (cu
->language
== language_rust
)
13656 struct type
*containing_type
= rust_containing_type (die
, cu
);
13658 if (containing_type
!= NULL
)
13660 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13662 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13663 storage
->concrete_type
= containing_type
;
13664 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13668 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13669 struct attribute
*abstract_origin
13670 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13671 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13672 if (res
== NULL
&& loc
&& abstract_origin
)
13674 /* We have a variable without a name, but with a location and an abstract
13675 origin. This may be a concrete instance of an abstract variable
13676 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13678 struct dwarf2_cu
*origin_cu
= cu
;
13679 struct die_info
*origin_die
13680 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13681 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13682 per_objfile
->per_bfd
->abstract_to_concrete
13683 [origin_die
->sect_off
].push_back (die
->sect_off
);
13687 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13688 reading .debug_rnglists.
13689 Callback's type should be:
13690 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13691 Return true if the attributes are present and valid, otherwise,
13694 template <typename Callback
>
13696 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13697 Callback
&&callback
)
13699 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
13700 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13701 bfd
*obfd
= objfile
->obfd
;
13702 /* Base address selection entry. */
13703 gdb::optional
<CORE_ADDR
> base
;
13704 const gdb_byte
*buffer
;
13705 CORE_ADDR baseaddr
;
13706 bool overflow
= false;
13708 base
= cu
->base_address
;
13710 dwarf2_per_objfile
->per_bfd
->rnglists
.read (objfile
);
13711 if (offset
>= dwarf2_per_objfile
->per_bfd
->rnglists
.size
)
13713 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13717 buffer
= dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13719 baseaddr
= objfile
->text_section_offset ();
13723 /* Initialize it due to a false compiler warning. */
13724 CORE_ADDR range_beginning
= 0, range_end
= 0;
13725 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
13726 + dwarf2_per_objfile
->per_bfd
->rnglists
.size
);
13727 unsigned int bytes_read
;
13729 if (buffer
== buf_end
)
13734 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13737 case DW_RLE_end_of_list
:
13739 case DW_RLE_base_address
:
13740 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13745 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13746 buffer
+= bytes_read
;
13748 case DW_RLE_start_length
:
13749 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13754 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13756 buffer
+= bytes_read
;
13757 range_end
= (range_beginning
13758 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13759 buffer
+= bytes_read
;
13760 if (buffer
> buf_end
)
13766 case DW_RLE_offset_pair
:
13767 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13768 buffer
+= bytes_read
;
13769 if (buffer
> buf_end
)
13774 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13775 buffer
+= bytes_read
;
13776 if (buffer
> buf_end
)
13782 case DW_RLE_start_end
:
13783 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13788 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13790 buffer
+= bytes_read
;
13791 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13792 buffer
+= bytes_read
;
13795 complaint (_("Invalid .debug_rnglists data (no base address)"));
13798 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13800 if (rlet
== DW_RLE_base_address
)
13803 if (!base
.has_value ())
13805 /* We have no valid base address for the ranges
13807 complaint (_("Invalid .debug_rnglists data (no base address)"));
13811 if (range_beginning
> range_end
)
13813 /* Inverted range entries are invalid. */
13814 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13818 /* Empty range entries have no effect. */
13819 if (range_beginning
== range_end
)
13822 range_beginning
+= *base
;
13823 range_end
+= *base
;
13825 /* A not-uncommon case of bad debug info.
13826 Don't pollute the addrmap with bad data. */
13827 if (range_beginning
+ baseaddr
== 0
13828 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
13830 complaint (_(".debug_rnglists entry has start address of zero"
13831 " [in module %s]"), objfile_name (objfile
));
13835 callback (range_beginning
, range_end
);
13840 complaint (_("Offset %d is not terminated "
13841 "for DW_AT_ranges attribute"),
13849 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13850 Callback's type should be:
13851 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13852 Return 1 if the attributes are present and valid, otherwise, return 0. */
13854 template <typename Callback
>
13856 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13857 Callback
&&callback
)
13859 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13860 struct objfile
*objfile
= per_objfile
->objfile
;
13861 struct comp_unit_head
*cu_header
= &cu
->header
;
13862 bfd
*obfd
= objfile
->obfd
;
13863 unsigned int addr_size
= cu_header
->addr_size
;
13864 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13865 /* Base address selection entry. */
13866 gdb::optional
<CORE_ADDR
> base
;
13867 unsigned int dummy
;
13868 const gdb_byte
*buffer
;
13869 CORE_ADDR baseaddr
;
13871 if (cu_header
->version
>= 5)
13872 return dwarf2_rnglists_process (offset
, cu
, callback
);
13874 base
= cu
->base_address
;
13876 per_objfile
->per_bfd
->ranges
.read (objfile
);
13877 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13879 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13883 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13885 baseaddr
= objfile
->text_section_offset ();
13889 CORE_ADDR range_beginning
, range_end
;
13891 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13892 buffer
+= addr_size
;
13893 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13894 buffer
+= addr_size
;
13895 offset
+= 2 * addr_size
;
13897 /* An end of list marker is a pair of zero addresses. */
13898 if (range_beginning
== 0 && range_end
== 0)
13899 /* Found the end of list entry. */
13902 /* Each base address selection entry is a pair of 2 values.
13903 The first is the largest possible address, the second is
13904 the base address. Check for a base address here. */
13905 if ((range_beginning
& mask
) == mask
)
13907 /* If we found the largest possible address, then we already
13908 have the base address in range_end. */
13913 if (!base
.has_value ())
13915 /* We have no valid base address for the ranges
13917 complaint (_("Invalid .debug_ranges data (no base address)"));
13921 if (range_beginning
> range_end
)
13923 /* Inverted range entries are invalid. */
13924 complaint (_("Invalid .debug_ranges data (inverted range)"));
13928 /* Empty range entries have no effect. */
13929 if (range_beginning
== range_end
)
13932 range_beginning
+= *base
;
13933 range_end
+= *base
;
13935 /* A not-uncommon case of bad debug info.
13936 Don't pollute the addrmap with bad data. */
13937 if (range_beginning
+ baseaddr
== 0
13938 && !per_objfile
->per_bfd
->has_section_at_zero
)
13940 complaint (_(".debug_ranges entry has start address of zero"
13941 " [in module %s]"), objfile_name (objfile
));
13945 callback (range_beginning
, range_end
);
13951 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13952 Return 1 if the attributes are present and valid, otherwise, return 0.
13953 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13956 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13957 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13958 dwarf2_psymtab
*ranges_pst
)
13960 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13961 struct gdbarch
*gdbarch
= objfile
->arch ();
13962 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13965 CORE_ADDR high
= 0;
13968 retval
= dwarf2_ranges_process (offset
, cu
,
13969 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13971 if (ranges_pst
!= NULL
)
13976 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13977 range_beginning
+ baseaddr
)
13979 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13980 range_end
+ baseaddr
)
13982 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13983 lowpc
, highpc
- 1, ranges_pst
);
13986 /* FIXME: This is recording everything as a low-high
13987 segment of consecutive addresses. We should have a
13988 data structure for discontiguous block ranges
13992 low
= range_beginning
;
13998 if (range_beginning
< low
)
13999 low
= range_beginning
;
14000 if (range_end
> high
)
14008 /* If the first entry is an end-of-list marker, the range
14009 describes an empty scope, i.e. no instructions. */
14015 *high_return
= high
;
14019 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14020 definition for the return value. *LOWPC and *HIGHPC are set iff
14021 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14023 static enum pc_bounds_kind
14024 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14025 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14026 dwarf2_psymtab
*pst
)
14028 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
14029 struct attribute
*attr
;
14030 struct attribute
*attr_high
;
14032 CORE_ADDR high
= 0;
14033 enum pc_bounds_kind ret
;
14035 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14038 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14039 if (attr
!= nullptr)
14041 low
= attr
->value_as_address ();
14042 high
= attr_high
->value_as_address ();
14043 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14047 /* Found high w/o low attribute. */
14048 return PC_BOUNDS_INVALID
;
14050 /* Found consecutive range of addresses. */
14051 ret
= PC_BOUNDS_HIGH_LOW
;
14055 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14058 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14059 We take advantage of the fact that DW_AT_ranges does not appear
14060 in DW_TAG_compile_unit of DWO files. */
14061 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14062 unsigned int ranges_offset
= (DW_UNSND (attr
)
14063 + (need_ranges_base
14067 /* Value of the DW_AT_ranges attribute is the offset in the
14068 .debug_ranges section. */
14069 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14070 return PC_BOUNDS_INVALID
;
14071 /* Found discontinuous range of addresses. */
14072 ret
= PC_BOUNDS_RANGES
;
14075 return PC_BOUNDS_NOT_PRESENT
;
14078 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14080 return PC_BOUNDS_INVALID
;
14082 /* When using the GNU linker, .gnu.linkonce. sections are used to
14083 eliminate duplicate copies of functions and vtables and such.
14084 The linker will arbitrarily choose one and discard the others.
14085 The AT_*_pc values for such functions refer to local labels in
14086 these sections. If the section from that file was discarded, the
14087 labels are not in the output, so the relocs get a value of 0.
14088 If this is a discarded function, mark the pc bounds as invalid,
14089 so that GDB will ignore it. */
14090 if (low
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
14091 return PC_BOUNDS_INVALID
;
14099 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14100 its low and high PC addresses. Do nothing if these addresses could not
14101 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14102 and HIGHPC to the high address if greater than HIGHPC. */
14105 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14106 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14107 struct dwarf2_cu
*cu
)
14109 CORE_ADDR low
, high
;
14110 struct die_info
*child
= die
->child
;
14112 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14114 *lowpc
= std::min (*lowpc
, low
);
14115 *highpc
= std::max (*highpc
, high
);
14118 /* If the language does not allow nested subprograms (either inside
14119 subprograms or lexical blocks), we're done. */
14120 if (cu
->language
!= language_ada
)
14123 /* Check all the children of the given DIE. If it contains nested
14124 subprograms, then check their pc bounds. Likewise, we need to
14125 check lexical blocks as well, as they may also contain subprogram
14127 while (child
&& child
->tag
)
14129 if (child
->tag
== DW_TAG_subprogram
14130 || child
->tag
== DW_TAG_lexical_block
)
14131 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14132 child
= child
->sibling
;
14136 /* Get the low and high pc's represented by the scope DIE, and store
14137 them in *LOWPC and *HIGHPC. If the correct values can't be
14138 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14141 get_scope_pc_bounds (struct die_info
*die
,
14142 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14143 struct dwarf2_cu
*cu
)
14145 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14146 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14147 CORE_ADDR current_low
, current_high
;
14149 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14150 >= PC_BOUNDS_RANGES
)
14152 best_low
= current_low
;
14153 best_high
= current_high
;
14157 struct die_info
*child
= die
->child
;
14159 while (child
&& child
->tag
)
14161 switch (child
->tag
) {
14162 case DW_TAG_subprogram
:
14163 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14165 case DW_TAG_namespace
:
14166 case DW_TAG_module
:
14167 /* FIXME: carlton/2004-01-16: Should we do this for
14168 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14169 that current GCC's always emit the DIEs corresponding
14170 to definitions of methods of classes as children of a
14171 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14172 the DIEs giving the declarations, which could be
14173 anywhere). But I don't see any reason why the
14174 standards says that they have to be there. */
14175 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14177 if (current_low
!= ((CORE_ADDR
) -1))
14179 best_low
= std::min (best_low
, current_low
);
14180 best_high
= std::max (best_high
, current_high
);
14188 child
= child
->sibling
;
14193 *highpc
= best_high
;
14196 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14200 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14201 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14203 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14204 struct gdbarch
*gdbarch
= objfile
->arch ();
14205 struct attribute
*attr
;
14206 struct attribute
*attr_high
;
14208 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14211 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14212 if (attr
!= nullptr)
14214 CORE_ADDR low
= attr
->value_as_address ();
14215 CORE_ADDR high
= attr_high
->value_as_address ();
14217 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14220 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14221 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14222 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14226 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14227 if (attr
!= nullptr)
14229 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14230 We take advantage of the fact that DW_AT_ranges does not appear
14231 in DW_TAG_compile_unit of DWO files. */
14232 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14234 /* The value of the DW_AT_ranges attribute is the offset of the
14235 address range list in the .debug_ranges section. */
14236 unsigned long offset
= (DW_UNSND (attr
)
14237 + (need_ranges_base
? cu
->ranges_base
: 0));
14239 std::vector
<blockrange
> blockvec
;
14240 dwarf2_ranges_process (offset
, cu
,
14241 [&] (CORE_ADDR start
, CORE_ADDR end
)
14245 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14246 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14247 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14248 blockvec
.emplace_back (start
, end
);
14251 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14255 /* Check whether the producer field indicates either of GCC < 4.6, or the
14256 Intel C/C++ compiler, and cache the result in CU. */
14259 check_producer (struct dwarf2_cu
*cu
)
14263 if (cu
->producer
== NULL
)
14265 /* For unknown compilers expect their behavior is DWARF version
14268 GCC started to support .debug_types sections by -gdwarf-4 since
14269 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14270 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14271 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14272 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14274 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14276 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14277 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14279 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14281 cu
->producer_is_icc
= true;
14282 cu
->producer_is_icc_lt_14
= major
< 14;
14284 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14285 cu
->producer_is_codewarrior
= true;
14288 /* For other non-GCC compilers, expect their behavior is DWARF version
14292 cu
->checked_producer
= true;
14295 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14296 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14297 during 4.6.0 experimental. */
14300 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14302 if (!cu
->checked_producer
)
14303 check_producer (cu
);
14305 return cu
->producer_is_gxx_lt_4_6
;
14309 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14310 with incorrect is_stmt attributes. */
14313 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14315 if (!cu
->checked_producer
)
14316 check_producer (cu
);
14318 return cu
->producer_is_codewarrior
;
14321 /* Return the default accessibility type if it is not overridden by
14322 DW_AT_accessibility. */
14324 static enum dwarf_access_attribute
14325 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14327 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14329 /* The default DWARF 2 accessibility for members is public, the default
14330 accessibility for inheritance is private. */
14332 if (die
->tag
!= DW_TAG_inheritance
)
14333 return DW_ACCESS_public
;
14335 return DW_ACCESS_private
;
14339 /* DWARF 3+ defines the default accessibility a different way. The same
14340 rules apply now for DW_TAG_inheritance as for the members and it only
14341 depends on the container kind. */
14343 if (die
->parent
->tag
== DW_TAG_class_type
)
14344 return DW_ACCESS_private
;
14346 return DW_ACCESS_public
;
14350 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14351 offset. If the attribute was not found return 0, otherwise return
14352 1. If it was found but could not properly be handled, set *OFFSET
14356 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14359 struct attribute
*attr
;
14361 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14366 /* Note that we do not check for a section offset first here.
14367 This is because DW_AT_data_member_location is new in DWARF 4,
14368 so if we see it, we can assume that a constant form is really
14369 a constant and not a section offset. */
14370 if (attr
->form_is_constant ())
14371 *offset
= attr
->constant_value (0);
14372 else if (attr
->form_is_section_offset ())
14373 dwarf2_complex_location_expr_complaint ();
14374 else if (attr
->form_is_block ())
14375 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14377 dwarf2_complex_location_expr_complaint ();
14385 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14388 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14389 struct field
*field
)
14391 struct attribute
*attr
;
14393 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14396 if (attr
->form_is_constant ())
14398 LONGEST offset
= attr
->constant_value (0);
14399 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14401 else if (attr
->form_is_section_offset ())
14402 dwarf2_complex_location_expr_complaint ();
14403 else if (attr
->form_is_block ())
14406 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14408 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14411 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14412 struct objfile
*objfile
= per_objfile
->objfile
;
14413 struct dwarf2_locexpr_baton
*dlbaton
14414 = XOBNEW (&objfile
->objfile_obstack
,
14415 struct dwarf2_locexpr_baton
);
14416 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14417 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14418 /* When using this baton, we want to compute the address
14419 of the field, not the value. This is why
14420 is_reference is set to false here. */
14421 dlbaton
->is_reference
= false;
14422 dlbaton
->per_objfile
= per_objfile
;
14423 dlbaton
->per_cu
= cu
->per_cu
;
14425 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14429 dwarf2_complex_location_expr_complaint ();
14433 /* Add an aggregate field to the field list. */
14436 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14437 struct dwarf2_cu
*cu
)
14439 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14440 struct gdbarch
*gdbarch
= objfile
->arch ();
14441 struct nextfield
*new_field
;
14442 struct attribute
*attr
;
14444 const char *fieldname
= "";
14446 if (die
->tag
== DW_TAG_inheritance
)
14448 fip
->baseclasses
.emplace_back ();
14449 new_field
= &fip
->baseclasses
.back ();
14453 fip
->fields
.emplace_back ();
14454 new_field
= &fip
->fields
.back ();
14457 new_field
->offset
= die
->sect_off
;
14459 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14460 if (attr
!= nullptr)
14461 new_field
->accessibility
= DW_UNSND (attr
);
14463 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14464 if (new_field
->accessibility
!= DW_ACCESS_public
)
14465 fip
->non_public_fields
= 1;
14467 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14468 if (attr
!= nullptr)
14469 new_field
->virtuality
= DW_UNSND (attr
);
14471 new_field
->virtuality
= DW_VIRTUALITY_none
;
14473 fp
= &new_field
->field
;
14475 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14477 /* Data member other than a C++ static data member. */
14479 /* Get type of field. */
14480 fp
->type
= die_type (die
, cu
);
14482 SET_FIELD_BITPOS (*fp
, 0);
14484 /* Get bit size of field (zero if none). */
14485 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14486 if (attr
!= nullptr)
14488 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14492 FIELD_BITSIZE (*fp
) = 0;
14495 /* Get bit offset of field. */
14496 handle_data_member_location (die
, cu
, fp
);
14497 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14498 if (attr
!= nullptr)
14500 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14502 /* For big endian bits, the DW_AT_bit_offset gives the
14503 additional bit offset from the MSB of the containing
14504 anonymous object to the MSB of the field. We don't
14505 have to do anything special since we don't need to
14506 know the size of the anonymous object. */
14507 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14511 /* For little endian bits, compute the bit offset to the
14512 MSB of the anonymous object, subtract off the number of
14513 bits from the MSB of the field to the MSB of the
14514 object, and then subtract off the number of bits of
14515 the field itself. The result is the bit offset of
14516 the LSB of the field. */
14517 int anonymous_size
;
14518 int bit_offset
= DW_UNSND (attr
);
14520 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14521 if (attr
!= nullptr)
14523 /* The size of the anonymous object containing
14524 the bit field is explicit, so use the
14525 indicated size (in bytes). */
14526 anonymous_size
= DW_UNSND (attr
);
14530 /* The size of the anonymous object containing
14531 the bit field must be inferred from the type
14532 attribute of the data member containing the
14534 anonymous_size
= TYPE_LENGTH (fp
->type
);
14536 SET_FIELD_BITPOS (*fp
,
14537 (FIELD_BITPOS (*fp
)
14538 + anonymous_size
* bits_per_byte
14539 - bit_offset
- FIELD_BITSIZE (*fp
)));
14542 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14544 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14545 + attr
->constant_value (0)));
14547 /* Get name of field. */
14548 fieldname
= dwarf2_name (die
, cu
);
14549 if (fieldname
== NULL
)
14552 /* The name is already allocated along with this objfile, so we don't
14553 need to duplicate it for the type. */
14554 fp
->name
= fieldname
;
14556 /* Change accessibility for artificial fields (e.g. virtual table
14557 pointer or virtual base class pointer) to private. */
14558 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14560 FIELD_ARTIFICIAL (*fp
) = 1;
14561 new_field
->accessibility
= DW_ACCESS_private
;
14562 fip
->non_public_fields
= 1;
14565 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14567 /* C++ static member. */
14569 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14570 is a declaration, but all versions of G++ as of this writing
14571 (so through at least 3.2.1) incorrectly generate
14572 DW_TAG_variable tags. */
14574 const char *physname
;
14576 /* Get name of field. */
14577 fieldname
= dwarf2_name (die
, cu
);
14578 if (fieldname
== NULL
)
14581 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14583 /* Only create a symbol if this is an external value.
14584 new_symbol checks this and puts the value in the global symbol
14585 table, which we want. If it is not external, new_symbol
14586 will try to put the value in cu->list_in_scope which is wrong. */
14587 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14589 /* A static const member, not much different than an enum as far as
14590 we're concerned, except that we can support more types. */
14591 new_symbol (die
, NULL
, cu
);
14594 /* Get physical name. */
14595 physname
= dwarf2_physname (fieldname
, die
, cu
);
14597 /* The name is already allocated along with this objfile, so we don't
14598 need to duplicate it for the type. */
14599 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14600 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14601 FIELD_NAME (*fp
) = fieldname
;
14603 else if (die
->tag
== DW_TAG_inheritance
)
14605 /* C++ base class field. */
14606 handle_data_member_location (die
, cu
, fp
);
14607 FIELD_BITSIZE (*fp
) = 0;
14608 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14609 FIELD_NAME (*fp
) = fp
->type
->name ();
14612 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14615 /* Can the type given by DIE define another type? */
14618 type_can_define_types (const struct die_info
*die
)
14622 case DW_TAG_typedef
:
14623 case DW_TAG_class_type
:
14624 case DW_TAG_structure_type
:
14625 case DW_TAG_union_type
:
14626 case DW_TAG_enumeration_type
:
14634 /* Add a type definition defined in the scope of the FIP's class. */
14637 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14638 struct dwarf2_cu
*cu
)
14640 struct decl_field fp
;
14641 memset (&fp
, 0, sizeof (fp
));
14643 gdb_assert (type_can_define_types (die
));
14645 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14646 fp
.name
= dwarf2_name (die
, cu
);
14647 fp
.type
= read_type_die (die
, cu
);
14649 /* Save accessibility. */
14650 enum dwarf_access_attribute accessibility
;
14651 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14653 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14655 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14656 switch (accessibility
)
14658 case DW_ACCESS_public
:
14659 /* The assumed value if neither private nor protected. */
14661 case DW_ACCESS_private
:
14664 case DW_ACCESS_protected
:
14665 fp
.is_protected
= 1;
14668 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14671 if (die
->tag
== DW_TAG_typedef
)
14672 fip
->typedef_field_list
.push_back (fp
);
14674 fip
->nested_types_list
.push_back (fp
);
14677 /* A convenience typedef that's used when finding the discriminant
14678 field for a variant part. */
14679 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14682 /* Compute the discriminant range for a given variant. OBSTACK is
14683 where the results will be stored. VARIANT is the variant to
14684 process. IS_UNSIGNED indicates whether the discriminant is signed
14687 static const gdb::array_view
<discriminant_range
>
14688 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14691 std::vector
<discriminant_range
> ranges
;
14693 if (variant
.default_branch
)
14696 if (variant
.discr_list_data
== nullptr)
14698 discriminant_range r
14699 = {variant
.discriminant_value
, variant
.discriminant_value
};
14700 ranges
.push_back (r
);
14704 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14705 variant
.discr_list_data
->size
);
14706 while (!data
.empty ())
14708 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14710 complaint (_("invalid discriminant marker: %d"), data
[0]);
14713 bool is_range
= data
[0] == DW_DSC_range
;
14714 data
= data
.slice (1);
14716 ULONGEST low
, high
;
14717 unsigned int bytes_read
;
14721 complaint (_("DW_AT_discr_list missing low value"));
14725 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14727 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14729 data
= data
.slice (bytes_read
);
14735 complaint (_("DW_AT_discr_list missing high value"));
14739 high
= read_unsigned_leb128 (nullptr, data
.data (),
14742 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14744 data
= data
.slice (bytes_read
);
14749 ranges
.push_back ({ low
, high
});
14753 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14755 std::copy (ranges
.begin (), ranges
.end (), result
);
14756 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14759 static const gdb::array_view
<variant_part
> create_variant_parts
14760 (struct obstack
*obstack
,
14761 const offset_map_type
&offset_map
,
14762 struct field_info
*fi
,
14763 const std::vector
<variant_part_builder
> &variant_parts
);
14765 /* Fill in a "struct variant" for a given variant field. RESULT is
14766 the variant to fill in. OBSTACK is where any needed allocations
14767 will be done. OFFSET_MAP holds the mapping from section offsets to
14768 fields for the type. FI describes the fields of the type we're
14769 processing. FIELD is the variant field we're converting. */
14772 create_one_variant (variant
&result
, struct obstack
*obstack
,
14773 const offset_map_type
&offset_map
,
14774 struct field_info
*fi
, const variant_field
&field
)
14776 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14777 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14778 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14779 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14780 field
.variant_parts
);
14783 /* Fill in a "struct variant_part" for a given variant part. RESULT
14784 is the variant part to fill in. OBSTACK is where any needed
14785 allocations will be done. OFFSET_MAP holds the mapping from
14786 section offsets to fields for the type. FI describes the fields of
14787 the type we're processing. BUILDER is the variant part to be
14791 create_one_variant_part (variant_part
&result
,
14792 struct obstack
*obstack
,
14793 const offset_map_type
&offset_map
,
14794 struct field_info
*fi
,
14795 const variant_part_builder
&builder
)
14797 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14798 if (iter
== offset_map
.end ())
14800 result
.discriminant_index
= -1;
14801 /* Doesn't matter. */
14802 result
.is_unsigned
= false;
14806 result
.discriminant_index
= iter
->second
;
14808 = TYPE_UNSIGNED (FIELD_TYPE
14809 (fi
->fields
[result
.discriminant_index
].field
));
14812 size_t n
= builder
.variants
.size ();
14813 variant
*output
= new (obstack
) variant
[n
];
14814 for (size_t i
= 0; i
< n
; ++i
)
14815 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14816 builder
.variants
[i
]);
14818 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14821 /* Create a vector of variant parts that can be attached to a type.
14822 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14823 holds the mapping from section offsets to fields for the type. FI
14824 describes the fields of the type we're processing. VARIANT_PARTS
14825 is the vector to convert. */
14827 static const gdb::array_view
<variant_part
>
14828 create_variant_parts (struct obstack
*obstack
,
14829 const offset_map_type
&offset_map
,
14830 struct field_info
*fi
,
14831 const std::vector
<variant_part_builder
> &variant_parts
)
14833 if (variant_parts
.empty ())
14836 size_t n
= variant_parts
.size ();
14837 variant_part
*result
= new (obstack
) variant_part
[n
];
14838 for (size_t i
= 0; i
< n
; ++i
)
14839 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14842 return gdb::array_view
<variant_part
> (result
, n
);
14845 /* Compute the variant part vector for FIP, attaching it to TYPE when
14849 add_variant_property (struct field_info
*fip
, struct type
*type
,
14850 struct dwarf2_cu
*cu
)
14852 /* Map section offsets of fields to their field index. Note the
14853 field index here does not take the number of baseclasses into
14855 offset_map_type offset_map
;
14856 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14857 offset_map
[fip
->fields
[i
].offset
] = i
;
14859 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14860 gdb::array_view
<variant_part
> parts
14861 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14862 fip
->variant_parts
);
14864 struct dynamic_prop prop
;
14865 prop
.kind
= PROP_VARIANT_PARTS
;
14866 prop
.data
.variant_parts
14867 = ((gdb::array_view
<variant_part
> *)
14868 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14870 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14873 /* Create the vector of fields, and attach it to the type. */
14876 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14877 struct dwarf2_cu
*cu
)
14879 int nfields
= fip
->nfields ();
14881 /* Record the field count, allocate space for the array of fields,
14882 and create blank accessibility bitfields if necessary. */
14883 type
->set_num_fields (nfields
);
14885 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14887 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14889 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14891 TYPE_FIELD_PRIVATE_BITS (type
) =
14892 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14893 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14895 TYPE_FIELD_PROTECTED_BITS (type
) =
14896 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14897 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14899 TYPE_FIELD_IGNORE_BITS (type
) =
14900 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14901 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14904 /* If the type has baseclasses, allocate and clear a bit vector for
14905 TYPE_FIELD_VIRTUAL_BITS. */
14906 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14908 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14909 unsigned char *pointer
;
14911 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14912 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14913 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14914 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14915 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14918 if (!fip
->variant_parts
.empty ())
14919 add_variant_property (fip
, type
, cu
);
14921 /* Copy the saved-up fields into the field vector. */
14922 for (int i
= 0; i
< nfields
; ++i
)
14924 struct nextfield
&field
14925 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14926 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14928 type
->field (i
) = field
.field
;
14929 switch (field
.accessibility
)
14931 case DW_ACCESS_private
:
14932 if (cu
->language
!= language_ada
)
14933 SET_TYPE_FIELD_PRIVATE (type
, i
);
14936 case DW_ACCESS_protected
:
14937 if (cu
->language
!= language_ada
)
14938 SET_TYPE_FIELD_PROTECTED (type
, i
);
14941 case DW_ACCESS_public
:
14945 /* Unknown accessibility. Complain and treat it as public. */
14947 complaint (_("unsupported accessibility %d"),
14948 field
.accessibility
);
14952 if (i
< fip
->baseclasses
.size ())
14954 switch (field
.virtuality
)
14956 case DW_VIRTUALITY_virtual
:
14957 case DW_VIRTUALITY_pure_virtual
:
14958 if (cu
->language
== language_ada
)
14959 error (_("unexpected virtuality in component of Ada type"));
14960 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14967 /* Return true if this member function is a constructor, false
14971 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14973 const char *fieldname
;
14974 const char *type_name
;
14977 if (die
->parent
== NULL
)
14980 if (die
->parent
->tag
!= DW_TAG_structure_type
14981 && die
->parent
->tag
!= DW_TAG_union_type
14982 && die
->parent
->tag
!= DW_TAG_class_type
)
14985 fieldname
= dwarf2_name (die
, cu
);
14986 type_name
= dwarf2_name (die
->parent
, cu
);
14987 if (fieldname
== NULL
|| type_name
== NULL
)
14990 len
= strlen (fieldname
);
14991 return (strncmp (fieldname
, type_name
, len
) == 0
14992 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14995 /* Check if the given VALUE is a recognized enum
14996 dwarf_defaulted_attribute constant according to DWARF5 spec,
15000 is_valid_DW_AT_defaulted (ULONGEST value
)
15004 case DW_DEFAULTED_no
:
15005 case DW_DEFAULTED_in_class
:
15006 case DW_DEFAULTED_out_of_class
:
15010 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15014 /* Add a member function to the proper fieldlist. */
15017 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15018 struct type
*type
, struct dwarf2_cu
*cu
)
15020 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15021 struct attribute
*attr
;
15023 struct fnfieldlist
*flp
= nullptr;
15024 struct fn_field
*fnp
;
15025 const char *fieldname
;
15026 struct type
*this_type
;
15027 enum dwarf_access_attribute accessibility
;
15029 if (cu
->language
== language_ada
)
15030 error (_("unexpected member function in Ada type"));
15032 /* Get name of member function. */
15033 fieldname
= dwarf2_name (die
, cu
);
15034 if (fieldname
== NULL
)
15037 /* Look up member function name in fieldlist. */
15038 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15040 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15042 flp
= &fip
->fnfieldlists
[i
];
15047 /* Create a new fnfieldlist if necessary. */
15048 if (flp
== nullptr)
15050 fip
->fnfieldlists
.emplace_back ();
15051 flp
= &fip
->fnfieldlists
.back ();
15052 flp
->name
= fieldname
;
15053 i
= fip
->fnfieldlists
.size () - 1;
15056 /* Create a new member function field and add it to the vector of
15058 flp
->fnfields
.emplace_back ();
15059 fnp
= &flp
->fnfields
.back ();
15061 /* Delay processing of the physname until later. */
15062 if (cu
->language
== language_cplus
)
15063 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15067 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15068 fnp
->physname
= physname
? physname
: "";
15071 fnp
->type
= alloc_type (objfile
);
15072 this_type
= read_type_die (die
, cu
);
15073 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15075 int nparams
= this_type
->num_fields ();
15077 /* TYPE is the domain of this method, and THIS_TYPE is the type
15078 of the method itself (TYPE_CODE_METHOD). */
15079 smash_to_method_type (fnp
->type
, type
,
15080 TYPE_TARGET_TYPE (this_type
),
15081 this_type
->fields (),
15082 this_type
->num_fields (),
15083 TYPE_VARARGS (this_type
));
15085 /* Handle static member functions.
15086 Dwarf2 has no clean way to discern C++ static and non-static
15087 member functions. G++ helps GDB by marking the first
15088 parameter for non-static member functions (which is the this
15089 pointer) as artificial. We obtain this information from
15090 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15091 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15092 fnp
->voffset
= VOFFSET_STATIC
;
15095 complaint (_("member function type missing for '%s'"),
15096 dwarf2_full_name (fieldname
, die
, cu
));
15098 /* Get fcontext from DW_AT_containing_type if present. */
15099 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15100 fnp
->fcontext
= die_containing_type (die
, cu
);
15102 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15103 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15105 /* Get accessibility. */
15106 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15107 if (attr
!= nullptr)
15108 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15110 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15111 switch (accessibility
)
15113 case DW_ACCESS_private
:
15114 fnp
->is_private
= 1;
15116 case DW_ACCESS_protected
:
15117 fnp
->is_protected
= 1;
15121 /* Check for artificial methods. */
15122 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15123 if (attr
&& DW_UNSND (attr
) != 0)
15124 fnp
->is_artificial
= 1;
15126 /* Check for defaulted methods. */
15127 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15128 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15129 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15131 /* Check for deleted methods. */
15132 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15133 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15134 fnp
->is_deleted
= 1;
15136 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15138 /* Get index in virtual function table if it is a virtual member
15139 function. For older versions of GCC, this is an offset in the
15140 appropriate virtual table, as specified by DW_AT_containing_type.
15141 For everyone else, it is an expression to be evaluated relative
15142 to the object address. */
15144 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15145 if (attr
!= nullptr)
15147 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15149 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15151 /* Old-style GCC. */
15152 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15154 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15155 || (DW_BLOCK (attr
)->size
> 1
15156 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15157 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15159 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15160 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15161 dwarf2_complex_location_expr_complaint ();
15163 fnp
->voffset
/= cu
->header
.addr_size
;
15167 dwarf2_complex_location_expr_complaint ();
15169 if (!fnp
->fcontext
)
15171 /* If there is no `this' field and no DW_AT_containing_type,
15172 we cannot actually find a base class context for the
15174 if (this_type
->num_fields () == 0
15175 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15177 complaint (_("cannot determine context for virtual member "
15178 "function \"%s\" (offset %s)"),
15179 fieldname
, sect_offset_str (die
->sect_off
));
15184 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15188 else if (attr
->form_is_section_offset ())
15190 dwarf2_complex_location_expr_complaint ();
15194 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15200 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15201 if (attr
&& DW_UNSND (attr
))
15203 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15204 complaint (_("Member function \"%s\" (offset %s) is virtual "
15205 "but the vtable offset is not specified"),
15206 fieldname
, sect_offset_str (die
->sect_off
));
15207 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15208 TYPE_CPLUS_DYNAMIC (type
) = 1;
15213 /* Create the vector of member function fields, and attach it to the type. */
15216 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15217 struct dwarf2_cu
*cu
)
15219 if (cu
->language
== language_ada
)
15220 error (_("unexpected member functions in Ada type"));
15222 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15223 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15225 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15227 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15229 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15230 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15232 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15233 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15234 fn_flp
->fn_fields
= (struct fn_field
*)
15235 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15237 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15238 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15241 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15244 /* Returns non-zero if NAME is the name of a vtable member in CU's
15245 language, zero otherwise. */
15247 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15249 static const char vptr
[] = "_vptr";
15251 /* Look for the C++ form of the vtable. */
15252 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15258 /* GCC outputs unnamed structures that are really pointers to member
15259 functions, with the ABI-specified layout. If TYPE describes
15260 such a structure, smash it into a member function type.
15262 GCC shouldn't do this; it should just output pointer to member DIEs.
15263 This is GCC PR debug/28767. */
15266 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15268 struct type
*pfn_type
, *self_type
, *new_type
;
15270 /* Check for a structure with no name and two children. */
15271 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15274 /* Check for __pfn and __delta members. */
15275 if (TYPE_FIELD_NAME (type
, 0) == NULL
15276 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15277 || TYPE_FIELD_NAME (type
, 1) == NULL
15278 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15281 /* Find the type of the method. */
15282 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15283 if (pfn_type
== NULL
15284 || pfn_type
->code () != TYPE_CODE_PTR
15285 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15288 /* Look for the "this" argument. */
15289 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15290 if (pfn_type
->num_fields () == 0
15291 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15292 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15295 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15296 new_type
= alloc_type (objfile
);
15297 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15298 pfn_type
->fields (), pfn_type
->num_fields (),
15299 TYPE_VARARGS (pfn_type
));
15300 smash_to_methodptr_type (type
, new_type
);
15303 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15304 appropriate error checking and issuing complaints if there is a
15308 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15310 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15312 if (attr
== nullptr)
15315 if (!attr
->form_is_constant ())
15317 complaint (_("DW_AT_alignment must have constant form"
15318 " - DIE at %s [in module %s]"),
15319 sect_offset_str (die
->sect_off
),
15320 objfile_name (cu
->per_objfile
->objfile
));
15325 if (attr
->form
== DW_FORM_sdata
)
15327 LONGEST val
= DW_SND (attr
);
15330 complaint (_("DW_AT_alignment value must not be negative"
15331 " - DIE at %s [in module %s]"),
15332 sect_offset_str (die
->sect_off
),
15333 objfile_name (cu
->per_objfile
->objfile
));
15339 align
= DW_UNSND (attr
);
15343 complaint (_("DW_AT_alignment value must not be zero"
15344 " - DIE at %s [in module %s]"),
15345 sect_offset_str (die
->sect_off
),
15346 objfile_name (cu
->per_objfile
->objfile
));
15349 if ((align
& (align
- 1)) != 0)
15351 complaint (_("DW_AT_alignment value must be a power of 2"
15352 " - DIE at %s [in module %s]"),
15353 sect_offset_str (die
->sect_off
),
15354 objfile_name (cu
->per_objfile
->objfile
));
15361 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15362 the alignment for TYPE. */
15365 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15368 if (!set_type_align (type
, get_alignment (cu
, die
)))
15369 complaint (_("DW_AT_alignment value too large"
15370 " - DIE at %s [in module %s]"),
15371 sect_offset_str (die
->sect_off
),
15372 objfile_name (cu
->per_objfile
->objfile
));
15375 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15376 constant for a type, according to DWARF5 spec, Table 5.5. */
15379 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15384 case DW_CC_pass_by_reference
:
15385 case DW_CC_pass_by_value
:
15389 complaint (_("unrecognized DW_AT_calling_convention value "
15390 "(%s) for a type"), pulongest (value
));
15395 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15396 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15397 also according to GNU-specific values (see include/dwarf2.h). */
15400 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15405 case DW_CC_program
:
15409 case DW_CC_GNU_renesas_sh
:
15410 case DW_CC_GNU_borland_fastcall_i386
:
15411 case DW_CC_GDB_IBM_OpenCL
:
15415 complaint (_("unrecognized DW_AT_calling_convention value "
15416 "(%s) for a subroutine"), pulongest (value
));
15421 /* Called when we find the DIE that starts a structure or union scope
15422 (definition) to create a type for the structure or union. Fill in
15423 the type's name and general properties; the members will not be
15424 processed until process_structure_scope. A symbol table entry for
15425 the type will also not be done until process_structure_scope (assuming
15426 the type has a name).
15428 NOTE: we need to call these functions regardless of whether or not the
15429 DIE has a DW_AT_name attribute, since it might be an anonymous
15430 structure or union. This gets the type entered into our set of
15431 user defined types. */
15433 static struct type
*
15434 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15436 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15438 struct attribute
*attr
;
15441 /* If the definition of this type lives in .debug_types, read that type.
15442 Don't follow DW_AT_specification though, that will take us back up
15443 the chain and we want to go down. */
15444 attr
= die
->attr (DW_AT_signature
);
15445 if (attr
!= nullptr)
15447 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15449 /* The type's CU may not be the same as CU.
15450 Ensure TYPE is recorded with CU in die_type_hash. */
15451 return set_die_type (die
, type
, cu
);
15454 type
= alloc_type (objfile
);
15455 INIT_CPLUS_SPECIFIC (type
);
15457 name
= dwarf2_name (die
, cu
);
15460 if (cu
->language
== language_cplus
15461 || cu
->language
== language_d
15462 || cu
->language
== language_rust
)
15464 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15466 /* dwarf2_full_name might have already finished building the DIE's
15467 type. If so, there is no need to continue. */
15468 if (get_die_type (die
, cu
) != NULL
)
15469 return get_die_type (die
, cu
);
15471 type
->set_name (full_name
);
15475 /* The name is already allocated along with this objfile, so
15476 we don't need to duplicate it for the type. */
15477 type
->set_name (name
);
15481 if (die
->tag
== DW_TAG_structure_type
)
15483 type
->set_code (TYPE_CODE_STRUCT
);
15485 else if (die
->tag
== DW_TAG_union_type
)
15487 type
->set_code (TYPE_CODE_UNION
);
15491 type
->set_code (TYPE_CODE_STRUCT
);
15494 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15495 TYPE_DECLARED_CLASS (type
) = 1;
15497 /* Store the calling convention in the type if it's available in
15498 the die. Otherwise the calling convention remains set to
15499 the default value DW_CC_normal. */
15500 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15501 if (attr
!= nullptr
15502 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15504 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15505 TYPE_CPLUS_CALLING_CONVENTION (type
)
15506 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15509 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15510 if (attr
!= nullptr)
15512 if (attr
->form_is_constant ())
15513 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15516 struct dynamic_prop prop
;
15517 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15518 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15519 TYPE_LENGTH (type
) = 0;
15524 TYPE_LENGTH (type
) = 0;
15527 maybe_set_alignment (cu
, die
, type
);
15529 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15531 /* ICC<14 does not output the required DW_AT_declaration on
15532 incomplete types, but gives them a size of zero. */
15533 TYPE_STUB (type
) = 1;
15536 TYPE_STUB_SUPPORTED (type
) = 1;
15538 if (die_is_declaration (die
, cu
))
15539 TYPE_STUB (type
) = 1;
15540 else if (attr
== NULL
&& die
->child
== NULL
15541 && producer_is_realview (cu
->producer
))
15542 /* RealView does not output the required DW_AT_declaration
15543 on incomplete types. */
15544 TYPE_STUB (type
) = 1;
15546 /* We need to add the type field to the die immediately so we don't
15547 infinitely recurse when dealing with pointers to the structure
15548 type within the structure itself. */
15549 set_die_type (die
, type
, cu
);
15551 /* set_die_type should be already done. */
15552 set_descriptive_type (type
, die
, cu
);
15557 static void handle_struct_member_die
15558 (struct die_info
*child_die
,
15560 struct field_info
*fi
,
15561 std::vector
<struct symbol
*> *template_args
,
15562 struct dwarf2_cu
*cu
);
15564 /* A helper for handle_struct_member_die that handles
15565 DW_TAG_variant_part. */
15568 handle_variant_part (struct die_info
*die
, struct type
*type
,
15569 struct field_info
*fi
,
15570 std::vector
<struct symbol
*> *template_args
,
15571 struct dwarf2_cu
*cu
)
15573 variant_part_builder
*new_part
;
15574 if (fi
->current_variant_part
== nullptr)
15576 fi
->variant_parts
.emplace_back ();
15577 new_part
= &fi
->variant_parts
.back ();
15579 else if (!fi
->current_variant_part
->processing_variant
)
15581 complaint (_("nested DW_TAG_variant_part seen "
15582 "- DIE at %s [in module %s]"),
15583 sect_offset_str (die
->sect_off
),
15584 objfile_name (cu
->per_objfile
->objfile
));
15589 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15590 current
.variant_parts
.emplace_back ();
15591 new_part
= ¤t
.variant_parts
.back ();
15594 /* When we recurse, we want callees to add to this new variant
15596 scoped_restore save_current_variant_part
15597 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15599 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15602 /* It's a univariant form, an extension we support. */
15604 else if (discr
->form_is_ref ())
15606 struct dwarf2_cu
*target_cu
= cu
;
15607 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15609 new_part
->discriminant_offset
= target_die
->sect_off
;
15613 complaint (_("DW_AT_discr does not have DIE reference form"
15614 " - DIE at %s [in module %s]"),
15615 sect_offset_str (die
->sect_off
),
15616 objfile_name (cu
->per_objfile
->objfile
));
15619 for (die_info
*child_die
= die
->child
;
15621 child_die
= child_die
->sibling
)
15622 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15625 /* A helper for handle_struct_member_die that handles
15629 handle_variant (struct die_info
*die
, struct type
*type
,
15630 struct field_info
*fi
,
15631 std::vector
<struct symbol
*> *template_args
,
15632 struct dwarf2_cu
*cu
)
15634 if (fi
->current_variant_part
== nullptr)
15636 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15637 "- DIE at %s [in module %s]"),
15638 sect_offset_str (die
->sect_off
),
15639 objfile_name (cu
->per_objfile
->objfile
));
15642 if (fi
->current_variant_part
->processing_variant
)
15644 complaint (_("nested DW_TAG_variant seen "
15645 "- DIE at %s [in module %s]"),
15646 sect_offset_str (die
->sect_off
),
15647 objfile_name (cu
->per_objfile
->objfile
));
15651 scoped_restore save_processing_variant
15652 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15655 fi
->current_variant_part
->variants
.emplace_back ();
15656 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15657 variant
.first_field
= fi
->fields
.size ();
15659 /* In a variant we want to get the discriminant and also add a
15660 field for our sole member child. */
15661 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15662 if (discr
== nullptr)
15664 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15665 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15666 variant
.default_branch
= true;
15668 variant
.discr_list_data
= DW_BLOCK (discr
);
15671 variant
.discriminant_value
= DW_UNSND (discr
);
15673 for (die_info
*variant_child
= die
->child
;
15674 variant_child
!= NULL
;
15675 variant_child
= variant_child
->sibling
)
15676 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15678 variant
.last_field
= fi
->fields
.size ();
15681 /* A helper for process_structure_scope that handles a single member
15685 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15686 struct field_info
*fi
,
15687 std::vector
<struct symbol
*> *template_args
,
15688 struct dwarf2_cu
*cu
)
15690 if (child_die
->tag
== DW_TAG_member
15691 || child_die
->tag
== DW_TAG_variable
)
15693 /* NOTE: carlton/2002-11-05: A C++ static data member
15694 should be a DW_TAG_member that is a declaration, but
15695 all versions of G++ as of this writing (so through at
15696 least 3.2.1) incorrectly generate DW_TAG_variable
15697 tags for them instead. */
15698 dwarf2_add_field (fi
, child_die
, cu
);
15700 else if (child_die
->tag
== DW_TAG_subprogram
)
15702 /* Rust doesn't have member functions in the C++ sense.
15703 However, it does emit ordinary functions as children
15704 of a struct DIE. */
15705 if (cu
->language
== language_rust
)
15706 read_func_scope (child_die
, cu
);
15709 /* C++ member function. */
15710 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15713 else if (child_die
->tag
== DW_TAG_inheritance
)
15715 /* C++ base class field. */
15716 dwarf2_add_field (fi
, child_die
, cu
);
15718 else if (type_can_define_types (child_die
))
15719 dwarf2_add_type_defn (fi
, child_die
, cu
);
15720 else if (child_die
->tag
== DW_TAG_template_type_param
15721 || child_die
->tag
== DW_TAG_template_value_param
)
15723 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15726 template_args
->push_back (arg
);
15728 else if (child_die
->tag
== DW_TAG_variant_part
)
15729 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15730 else if (child_die
->tag
== DW_TAG_variant
)
15731 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15734 /* Finish creating a structure or union type, including filling in
15735 its members and creating a symbol for it. */
15738 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15740 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15741 struct die_info
*child_die
;
15744 type
= get_die_type (die
, cu
);
15746 type
= read_structure_type (die
, cu
);
15748 bool has_template_parameters
= false;
15749 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15751 struct field_info fi
;
15752 std::vector
<struct symbol
*> template_args
;
15754 child_die
= die
->child
;
15756 while (child_die
&& child_die
->tag
)
15758 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15759 child_die
= child_die
->sibling
;
15762 /* Attach template arguments to type. */
15763 if (!template_args
.empty ())
15765 has_template_parameters
= true;
15766 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15767 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15768 TYPE_TEMPLATE_ARGUMENTS (type
)
15769 = XOBNEWVEC (&objfile
->objfile_obstack
,
15771 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15772 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15773 template_args
.data (),
15774 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15775 * sizeof (struct symbol
*)));
15778 /* Attach fields and member functions to the type. */
15779 if (fi
.nfields () > 0)
15780 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15781 if (!fi
.fnfieldlists
.empty ())
15783 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15785 /* Get the type which refers to the base class (possibly this
15786 class itself) which contains the vtable pointer for the current
15787 class from the DW_AT_containing_type attribute. This use of
15788 DW_AT_containing_type is a GNU extension. */
15790 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15792 struct type
*t
= die_containing_type (die
, cu
);
15794 set_type_vptr_basetype (type
, t
);
15799 /* Our own class provides vtbl ptr. */
15800 for (i
= t
->num_fields () - 1;
15801 i
>= TYPE_N_BASECLASSES (t
);
15804 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15806 if (is_vtable_name (fieldname
, cu
))
15808 set_type_vptr_fieldno (type
, i
);
15813 /* Complain if virtual function table field not found. */
15814 if (i
< TYPE_N_BASECLASSES (t
))
15815 complaint (_("virtual function table pointer "
15816 "not found when defining class '%s'"),
15817 type
->name () ? type
->name () : "");
15821 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15824 else if (cu
->producer
15825 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15827 /* The IBM XLC compiler does not provide direct indication
15828 of the containing type, but the vtable pointer is
15829 always named __vfp. */
15833 for (i
= type
->num_fields () - 1;
15834 i
>= TYPE_N_BASECLASSES (type
);
15837 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15839 set_type_vptr_fieldno (type
, i
);
15840 set_type_vptr_basetype (type
, type
);
15847 /* Copy fi.typedef_field_list linked list elements content into the
15848 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15849 if (!fi
.typedef_field_list
.empty ())
15851 int count
= fi
.typedef_field_list
.size ();
15853 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15854 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15855 = ((struct decl_field
*)
15857 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15858 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15860 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15861 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15864 /* Copy fi.nested_types_list linked list elements content into the
15865 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15866 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15868 int count
= fi
.nested_types_list
.size ();
15870 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15871 TYPE_NESTED_TYPES_ARRAY (type
)
15872 = ((struct decl_field
*)
15873 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15874 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15876 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15877 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15881 quirk_gcc_member_function_pointer (type
, objfile
);
15882 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15883 cu
->rust_unions
.push_back (type
);
15885 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15886 snapshots) has been known to create a die giving a declaration
15887 for a class that has, as a child, a die giving a definition for a
15888 nested class. So we have to process our children even if the
15889 current die is a declaration. Normally, of course, a declaration
15890 won't have any children at all. */
15892 child_die
= die
->child
;
15894 while (child_die
!= NULL
&& child_die
->tag
)
15896 if (child_die
->tag
== DW_TAG_member
15897 || child_die
->tag
== DW_TAG_variable
15898 || child_die
->tag
== DW_TAG_inheritance
15899 || child_die
->tag
== DW_TAG_template_value_param
15900 || child_die
->tag
== DW_TAG_template_type_param
)
15905 process_die (child_die
, cu
);
15907 child_die
= child_die
->sibling
;
15910 /* Do not consider external references. According to the DWARF standard,
15911 these DIEs are identified by the fact that they have no byte_size
15912 attribute, and a declaration attribute. */
15913 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15914 || !die_is_declaration (die
, cu
)
15915 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15917 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15919 if (has_template_parameters
)
15921 struct symtab
*symtab
;
15922 if (sym
!= nullptr)
15923 symtab
= symbol_symtab (sym
);
15924 else if (cu
->line_header
!= nullptr)
15926 /* Any related symtab will do. */
15928 = cu
->line_header
->file_names ()[0].symtab
;
15933 complaint (_("could not find suitable "
15934 "symtab for template parameter"
15935 " - DIE at %s [in module %s]"),
15936 sect_offset_str (die
->sect_off
),
15937 objfile_name (objfile
));
15940 if (symtab
!= nullptr)
15942 /* Make sure that the symtab is set on the new symbols.
15943 Even though they don't appear in this symtab directly,
15944 other parts of gdb assume that symbols do, and this is
15945 reasonably true. */
15946 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15947 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15953 /* Assuming DIE is an enumeration type, and TYPE is its associated
15954 type, update TYPE using some information only available in DIE's
15955 children. In particular, the fields are computed. */
15958 update_enumeration_type_from_children (struct die_info
*die
,
15960 struct dwarf2_cu
*cu
)
15962 struct die_info
*child_die
;
15963 int unsigned_enum
= 1;
15966 auto_obstack obstack
;
15967 std::vector
<struct field
> fields
;
15969 for (child_die
= die
->child
;
15970 child_die
!= NULL
&& child_die
->tag
;
15971 child_die
= child_die
->sibling
)
15973 struct attribute
*attr
;
15975 const gdb_byte
*bytes
;
15976 struct dwarf2_locexpr_baton
*baton
;
15979 if (child_die
->tag
!= DW_TAG_enumerator
)
15982 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15986 name
= dwarf2_name (child_die
, cu
);
15988 name
= "<anonymous enumerator>";
15990 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15991 &value
, &bytes
, &baton
);
15999 if (count_one_bits_ll (value
) >= 2)
16003 fields
.emplace_back ();
16004 struct field
&field
= fields
.back ();
16005 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16006 SET_FIELD_ENUMVAL (field
, value
);
16009 if (!fields
.empty ())
16011 type
->set_num_fields (fields
.size ());
16014 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16015 memcpy (type
->fields (), fields
.data (),
16016 sizeof (struct field
) * fields
.size ());
16020 TYPE_UNSIGNED (type
) = 1;
16022 TYPE_FLAG_ENUM (type
) = 1;
16025 /* Given a DW_AT_enumeration_type die, set its type. We do not
16026 complete the type's fields yet, or create any symbols. */
16028 static struct type
*
16029 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16031 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16033 struct attribute
*attr
;
16036 /* If the definition of this type lives in .debug_types, read that type.
16037 Don't follow DW_AT_specification though, that will take us back up
16038 the chain and we want to go down. */
16039 attr
= die
->attr (DW_AT_signature
);
16040 if (attr
!= nullptr)
16042 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16044 /* The type's CU may not be the same as CU.
16045 Ensure TYPE is recorded with CU in die_type_hash. */
16046 return set_die_type (die
, type
, cu
);
16049 type
= alloc_type (objfile
);
16051 type
->set_code (TYPE_CODE_ENUM
);
16052 name
= dwarf2_full_name (NULL
, die
, cu
);
16054 type
->set_name (name
);
16056 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16059 struct type
*underlying_type
= die_type (die
, cu
);
16061 TYPE_TARGET_TYPE (type
) = underlying_type
;
16064 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16065 if (attr
!= nullptr)
16067 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16071 TYPE_LENGTH (type
) = 0;
16074 maybe_set_alignment (cu
, die
, type
);
16076 /* The enumeration DIE can be incomplete. In Ada, any type can be
16077 declared as private in the package spec, and then defined only
16078 inside the package body. Such types are known as Taft Amendment
16079 Types. When another package uses such a type, an incomplete DIE
16080 may be generated by the compiler. */
16081 if (die_is_declaration (die
, cu
))
16082 TYPE_STUB (type
) = 1;
16084 /* If this type has an underlying type that is not a stub, then we
16085 may use its attributes. We always use the "unsigned" attribute
16086 in this situation, because ordinarily we guess whether the type
16087 is unsigned -- but the guess can be wrong and the underlying type
16088 can tell us the reality. However, we defer to a local size
16089 attribute if one exists, because this lets the compiler override
16090 the underlying type if needed. */
16091 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16093 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16094 underlying_type
= check_typedef (underlying_type
);
16095 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16096 if (TYPE_LENGTH (type
) == 0)
16097 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16098 if (TYPE_RAW_ALIGN (type
) == 0
16099 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16100 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16103 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16105 set_die_type (die
, type
, cu
);
16107 /* Finish the creation of this type by using the enum's children.
16108 Note that, as usual, this must come after set_die_type to avoid
16109 infinite recursion when trying to compute the names of the
16111 update_enumeration_type_from_children (die
, type
, cu
);
16116 /* Given a pointer to a die which begins an enumeration, process all
16117 the dies that define the members of the enumeration, and create the
16118 symbol for the enumeration type.
16120 NOTE: We reverse the order of the element list. */
16123 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16125 struct type
*this_type
;
16127 this_type
= get_die_type (die
, cu
);
16128 if (this_type
== NULL
)
16129 this_type
= read_enumeration_type (die
, cu
);
16131 if (die
->child
!= NULL
)
16133 struct die_info
*child_die
;
16136 child_die
= die
->child
;
16137 while (child_die
&& child_die
->tag
)
16139 if (child_die
->tag
!= DW_TAG_enumerator
)
16141 process_die (child_die
, cu
);
16145 name
= dwarf2_name (child_die
, cu
);
16147 new_symbol (child_die
, this_type
, cu
);
16150 child_die
= child_die
->sibling
;
16154 /* If we are reading an enum from a .debug_types unit, and the enum
16155 is a declaration, and the enum is not the signatured type in the
16156 unit, then we do not want to add a symbol for it. Adding a
16157 symbol would in some cases obscure the true definition of the
16158 enum, giving users an incomplete type when the definition is
16159 actually available. Note that we do not want to do this for all
16160 enums which are just declarations, because C++0x allows forward
16161 enum declarations. */
16162 if (cu
->per_cu
->is_debug_types
16163 && die_is_declaration (die
, cu
))
16165 struct signatured_type
*sig_type
;
16167 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16168 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16169 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16173 new_symbol (die
, this_type
, cu
);
16176 /* Extract all information from a DW_TAG_array_type DIE and put it in
16177 the DIE's type field. For now, this only handles one dimensional
16180 static struct type
*
16181 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16183 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16184 struct die_info
*child_die
;
16186 struct type
*element_type
, *range_type
, *index_type
;
16187 struct attribute
*attr
;
16189 struct dynamic_prop
*byte_stride_prop
= NULL
;
16190 unsigned int bit_stride
= 0;
16192 element_type
= die_type (die
, cu
);
16194 /* The die_type call above may have already set the type for this DIE. */
16195 type
= get_die_type (die
, cu
);
16199 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16203 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16206 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16207 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16211 complaint (_("unable to read array DW_AT_byte_stride "
16212 " - DIE at %s [in module %s]"),
16213 sect_offset_str (die
->sect_off
),
16214 objfile_name (cu
->per_objfile
->objfile
));
16215 /* Ignore this attribute. We will likely not be able to print
16216 arrays of this type correctly, but there is little we can do
16217 to help if we cannot read the attribute's value. */
16218 byte_stride_prop
= NULL
;
16222 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16224 bit_stride
= DW_UNSND (attr
);
16226 /* Irix 6.2 native cc creates array types without children for
16227 arrays with unspecified length. */
16228 if (die
->child
== NULL
)
16230 index_type
= objfile_type (objfile
)->builtin_int
;
16231 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16232 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16233 byte_stride_prop
, bit_stride
);
16234 return set_die_type (die
, type
, cu
);
16237 std::vector
<struct type
*> range_types
;
16238 child_die
= die
->child
;
16239 while (child_die
&& child_die
->tag
)
16241 if (child_die
->tag
== DW_TAG_subrange_type
)
16243 struct type
*child_type
= read_type_die (child_die
, cu
);
16245 if (child_type
!= NULL
)
16247 /* The range type was succesfully read. Save it for the
16248 array type creation. */
16249 range_types
.push_back (child_type
);
16252 child_die
= child_die
->sibling
;
16255 /* Dwarf2 dimensions are output from left to right, create the
16256 necessary array types in backwards order. */
16258 type
= element_type
;
16260 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16264 while (i
< range_types
.size ())
16265 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16266 byte_stride_prop
, bit_stride
);
16270 size_t ndim
= range_types
.size ();
16272 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16273 byte_stride_prop
, bit_stride
);
16276 /* Understand Dwarf2 support for vector types (like they occur on
16277 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16278 array type. This is not part of the Dwarf2/3 standard yet, but a
16279 custom vendor extension. The main difference between a regular
16280 array and the vector variant is that vectors are passed by value
16282 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16283 if (attr
!= nullptr)
16284 make_vector_type (type
);
16286 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16287 implementation may choose to implement triple vectors using this
16289 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16290 if (attr
!= nullptr)
16292 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16293 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16295 complaint (_("DW_AT_byte_size for array type smaller "
16296 "than the total size of elements"));
16299 name
= dwarf2_name (die
, cu
);
16301 type
->set_name (name
);
16303 maybe_set_alignment (cu
, die
, type
);
16305 /* Install the type in the die. */
16306 set_die_type (die
, type
, cu
);
16308 /* set_die_type should be already done. */
16309 set_descriptive_type (type
, die
, cu
);
16314 static enum dwarf_array_dim_ordering
16315 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16317 struct attribute
*attr
;
16319 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16321 if (attr
!= nullptr)
16322 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16324 /* GNU F77 is a special case, as at 08/2004 array type info is the
16325 opposite order to the dwarf2 specification, but data is still
16326 laid out as per normal fortran.
16328 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16329 version checking. */
16331 if (cu
->language
== language_fortran
16332 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16334 return DW_ORD_row_major
;
16337 switch (cu
->language_defn
->la_array_ordering
)
16339 case array_column_major
:
16340 return DW_ORD_col_major
;
16341 case array_row_major
:
16343 return DW_ORD_row_major
;
16347 /* Extract all information from a DW_TAG_set_type DIE and put it in
16348 the DIE's type field. */
16350 static struct type
*
16351 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16353 struct type
*domain_type
, *set_type
;
16354 struct attribute
*attr
;
16356 domain_type
= die_type (die
, cu
);
16358 /* The die_type call above may have already set the type for this DIE. */
16359 set_type
= get_die_type (die
, cu
);
16363 set_type
= create_set_type (NULL
, domain_type
);
16365 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16366 if (attr
!= nullptr)
16367 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16369 maybe_set_alignment (cu
, die
, set_type
);
16371 return set_die_type (die
, set_type
, cu
);
16374 /* A helper for read_common_block that creates a locexpr baton.
16375 SYM is the symbol which we are marking as computed.
16376 COMMON_DIE is the DIE for the common block.
16377 COMMON_LOC is the location expression attribute for the common
16379 MEMBER_LOC is the location expression attribute for the particular
16380 member of the common block that we are processing.
16381 CU is the CU from which the above come. */
16384 mark_common_block_symbol_computed (struct symbol
*sym
,
16385 struct die_info
*common_die
,
16386 struct attribute
*common_loc
,
16387 struct attribute
*member_loc
,
16388 struct dwarf2_cu
*cu
)
16390 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16391 struct objfile
*objfile
= per_objfile
->objfile
;
16392 struct dwarf2_locexpr_baton
*baton
;
16394 unsigned int cu_off
;
16395 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16396 LONGEST offset
= 0;
16398 gdb_assert (common_loc
&& member_loc
);
16399 gdb_assert (common_loc
->form_is_block ());
16400 gdb_assert (member_loc
->form_is_block ()
16401 || member_loc
->form_is_constant ());
16403 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16404 baton
->per_objfile
= per_objfile
;
16405 baton
->per_cu
= cu
->per_cu
;
16406 gdb_assert (baton
->per_cu
);
16408 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16410 if (member_loc
->form_is_constant ())
16412 offset
= member_loc
->constant_value (0);
16413 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16416 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16418 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16421 *ptr
++ = DW_OP_call4
;
16422 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16423 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16426 if (member_loc
->form_is_constant ())
16428 *ptr
++ = DW_OP_addr
;
16429 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16430 ptr
+= cu
->header
.addr_size
;
16434 /* We have to copy the data here, because DW_OP_call4 will only
16435 use a DW_AT_location attribute. */
16436 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16437 ptr
+= DW_BLOCK (member_loc
)->size
;
16440 *ptr
++ = DW_OP_plus
;
16441 gdb_assert (ptr
- baton
->data
== baton
->size
);
16443 SYMBOL_LOCATION_BATON (sym
) = baton
;
16444 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16447 /* Create appropriate locally-scoped variables for all the
16448 DW_TAG_common_block entries. Also create a struct common_block
16449 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16450 is used to separate the common blocks name namespace from regular
16454 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16456 struct attribute
*attr
;
16458 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16459 if (attr
!= nullptr)
16461 /* Support the .debug_loc offsets. */
16462 if (attr
->form_is_block ())
16466 else if (attr
->form_is_section_offset ())
16468 dwarf2_complex_location_expr_complaint ();
16473 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16474 "common block member");
16479 if (die
->child
!= NULL
)
16481 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16482 struct die_info
*child_die
;
16483 size_t n_entries
= 0, size
;
16484 struct common_block
*common_block
;
16485 struct symbol
*sym
;
16487 for (child_die
= die
->child
;
16488 child_die
&& child_die
->tag
;
16489 child_die
= child_die
->sibling
)
16492 size
= (sizeof (struct common_block
)
16493 + (n_entries
- 1) * sizeof (struct symbol
*));
16495 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16497 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16498 common_block
->n_entries
= 0;
16500 for (child_die
= die
->child
;
16501 child_die
&& child_die
->tag
;
16502 child_die
= child_die
->sibling
)
16504 /* Create the symbol in the DW_TAG_common_block block in the current
16506 sym
= new_symbol (child_die
, NULL
, cu
);
16509 struct attribute
*member_loc
;
16511 common_block
->contents
[common_block
->n_entries
++] = sym
;
16513 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16517 /* GDB has handled this for a long time, but it is
16518 not specified by DWARF. It seems to have been
16519 emitted by gfortran at least as recently as:
16520 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16521 complaint (_("Variable in common block has "
16522 "DW_AT_data_member_location "
16523 "- DIE at %s [in module %s]"),
16524 sect_offset_str (child_die
->sect_off
),
16525 objfile_name (objfile
));
16527 if (member_loc
->form_is_section_offset ())
16528 dwarf2_complex_location_expr_complaint ();
16529 else if (member_loc
->form_is_constant ()
16530 || member_loc
->form_is_block ())
16532 if (attr
!= nullptr)
16533 mark_common_block_symbol_computed (sym
, die
, attr
,
16537 dwarf2_complex_location_expr_complaint ();
16542 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16543 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16547 /* Create a type for a C++ namespace. */
16549 static struct type
*
16550 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16552 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16553 const char *previous_prefix
, *name
;
16557 /* For extensions, reuse the type of the original namespace. */
16558 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16560 struct die_info
*ext_die
;
16561 struct dwarf2_cu
*ext_cu
= cu
;
16563 ext_die
= dwarf2_extension (die
, &ext_cu
);
16564 type
= read_type_die (ext_die
, ext_cu
);
16566 /* EXT_CU may not be the same as CU.
16567 Ensure TYPE is recorded with CU in die_type_hash. */
16568 return set_die_type (die
, type
, cu
);
16571 name
= namespace_name (die
, &is_anonymous
, cu
);
16573 /* Now build the name of the current namespace. */
16575 previous_prefix
= determine_prefix (die
, cu
);
16576 if (previous_prefix
[0] != '\0')
16577 name
= typename_concat (&objfile
->objfile_obstack
,
16578 previous_prefix
, name
, 0, cu
);
16580 /* Create the type. */
16581 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16583 return set_die_type (die
, type
, cu
);
16586 /* Read a namespace scope. */
16589 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16591 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16594 /* Add a symbol associated to this if we haven't seen the namespace
16595 before. Also, add a using directive if it's an anonymous
16598 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16602 type
= read_type_die (die
, cu
);
16603 new_symbol (die
, type
, cu
);
16605 namespace_name (die
, &is_anonymous
, cu
);
16608 const char *previous_prefix
= determine_prefix (die
, cu
);
16610 std::vector
<const char *> excludes
;
16611 add_using_directive (using_directives (cu
),
16612 previous_prefix
, type
->name (), NULL
,
16613 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16617 if (die
->child
!= NULL
)
16619 struct die_info
*child_die
= die
->child
;
16621 while (child_die
&& child_die
->tag
)
16623 process_die (child_die
, cu
);
16624 child_die
= child_die
->sibling
;
16629 /* Read a Fortran module as type. This DIE can be only a declaration used for
16630 imported module. Still we need that type as local Fortran "use ... only"
16631 declaration imports depend on the created type in determine_prefix. */
16633 static struct type
*
16634 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16636 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16637 const char *module_name
;
16640 module_name
= dwarf2_name (die
, cu
);
16641 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16643 return set_die_type (die
, type
, cu
);
16646 /* Read a Fortran module. */
16649 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16651 struct die_info
*child_die
= die
->child
;
16654 type
= read_type_die (die
, cu
);
16655 new_symbol (die
, type
, cu
);
16657 while (child_die
&& child_die
->tag
)
16659 process_die (child_die
, cu
);
16660 child_die
= child_die
->sibling
;
16664 /* Return the name of the namespace represented by DIE. Set
16665 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16668 static const char *
16669 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16671 struct die_info
*current_die
;
16672 const char *name
= NULL
;
16674 /* Loop through the extensions until we find a name. */
16676 for (current_die
= die
;
16677 current_die
!= NULL
;
16678 current_die
= dwarf2_extension (die
, &cu
))
16680 /* We don't use dwarf2_name here so that we can detect the absence
16681 of a name -> anonymous namespace. */
16682 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16688 /* Is it an anonymous namespace? */
16690 *is_anonymous
= (name
== NULL
);
16692 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16697 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16698 the user defined type vector. */
16700 static struct type
*
16701 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16703 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16704 struct comp_unit_head
*cu_header
= &cu
->header
;
16706 struct attribute
*attr_byte_size
;
16707 struct attribute
*attr_address_class
;
16708 int byte_size
, addr_class
;
16709 struct type
*target_type
;
16711 target_type
= die_type (die
, cu
);
16713 /* The die_type call above may have already set the type for this DIE. */
16714 type
= get_die_type (die
, cu
);
16718 type
= lookup_pointer_type (target_type
);
16720 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16721 if (attr_byte_size
)
16722 byte_size
= DW_UNSND (attr_byte_size
);
16724 byte_size
= cu_header
->addr_size
;
16726 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16727 if (attr_address_class
)
16728 addr_class
= DW_UNSND (attr_address_class
);
16730 addr_class
= DW_ADDR_none
;
16732 ULONGEST alignment
= get_alignment (cu
, die
);
16734 /* If the pointer size, alignment, or address class is different
16735 than the default, create a type variant marked as such and set
16736 the length accordingly. */
16737 if (TYPE_LENGTH (type
) != byte_size
16738 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16739 && alignment
!= TYPE_RAW_ALIGN (type
))
16740 || addr_class
!= DW_ADDR_none
)
16742 if (gdbarch_address_class_type_flags_p (gdbarch
))
16746 type_flags
= gdbarch_address_class_type_flags
16747 (gdbarch
, byte_size
, addr_class
);
16748 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16750 type
= make_type_with_address_space (type
, type_flags
);
16752 else if (TYPE_LENGTH (type
) != byte_size
)
16754 complaint (_("invalid pointer size %d"), byte_size
);
16756 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16758 complaint (_("Invalid DW_AT_alignment"
16759 " - DIE at %s [in module %s]"),
16760 sect_offset_str (die
->sect_off
),
16761 objfile_name (cu
->per_objfile
->objfile
));
16765 /* Should we also complain about unhandled address classes? */
16769 TYPE_LENGTH (type
) = byte_size
;
16770 set_type_align (type
, alignment
);
16771 return set_die_type (die
, type
, cu
);
16774 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16775 the user defined type vector. */
16777 static struct type
*
16778 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16781 struct type
*to_type
;
16782 struct type
*domain
;
16784 to_type
= die_type (die
, cu
);
16785 domain
= die_containing_type (die
, cu
);
16787 /* The calls above may have already set the type for this DIE. */
16788 type
= get_die_type (die
, cu
);
16792 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16793 type
= lookup_methodptr_type (to_type
);
16794 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16796 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16798 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16799 to_type
->fields (), to_type
->num_fields (),
16800 TYPE_VARARGS (to_type
));
16801 type
= lookup_methodptr_type (new_type
);
16804 type
= lookup_memberptr_type (to_type
, domain
);
16806 return set_die_type (die
, type
, cu
);
16809 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16810 the user defined type vector. */
16812 static struct type
*
16813 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16814 enum type_code refcode
)
16816 struct comp_unit_head
*cu_header
= &cu
->header
;
16817 struct type
*type
, *target_type
;
16818 struct attribute
*attr
;
16820 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16822 target_type
= die_type (die
, cu
);
16824 /* The die_type call above may have already set the type for this DIE. */
16825 type
= get_die_type (die
, cu
);
16829 type
= lookup_reference_type (target_type
, refcode
);
16830 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16831 if (attr
!= nullptr)
16833 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16837 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16839 maybe_set_alignment (cu
, die
, type
);
16840 return set_die_type (die
, type
, cu
);
16843 /* Add the given cv-qualifiers to the element type of the array. GCC
16844 outputs DWARF type qualifiers that apply to an array, not the
16845 element type. But GDB relies on the array element type to carry
16846 the cv-qualifiers. This mimics section 6.7.3 of the C99
16849 static struct type
*
16850 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16851 struct type
*base_type
, int cnst
, int voltl
)
16853 struct type
*el_type
, *inner_array
;
16855 base_type
= copy_type (base_type
);
16856 inner_array
= base_type
;
16858 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16860 TYPE_TARGET_TYPE (inner_array
) =
16861 copy_type (TYPE_TARGET_TYPE (inner_array
));
16862 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16865 el_type
= TYPE_TARGET_TYPE (inner_array
);
16866 cnst
|= TYPE_CONST (el_type
);
16867 voltl
|= TYPE_VOLATILE (el_type
);
16868 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16870 return set_die_type (die
, base_type
, cu
);
16873 static struct type
*
16874 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16876 struct type
*base_type
, *cv_type
;
16878 base_type
= die_type (die
, cu
);
16880 /* The die_type call above may have already set the type for this DIE. */
16881 cv_type
= get_die_type (die
, cu
);
16885 /* In case the const qualifier is applied to an array type, the element type
16886 is so qualified, not the array type (section 6.7.3 of C99). */
16887 if (base_type
->code () == TYPE_CODE_ARRAY
)
16888 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16890 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16891 return set_die_type (die
, cv_type
, cu
);
16894 static struct type
*
16895 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16897 struct type
*base_type
, *cv_type
;
16899 base_type
= die_type (die
, cu
);
16901 /* The die_type call above may have already set the type for this DIE. */
16902 cv_type
= get_die_type (die
, cu
);
16906 /* In case the volatile qualifier is applied to an array type, the
16907 element type is so qualified, not the array type (section 6.7.3
16909 if (base_type
->code () == TYPE_CODE_ARRAY
)
16910 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16912 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16913 return set_die_type (die
, cv_type
, cu
);
16916 /* Handle DW_TAG_restrict_type. */
16918 static struct type
*
16919 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16921 struct type
*base_type
, *cv_type
;
16923 base_type
= die_type (die
, cu
);
16925 /* The die_type call above may have already set the type for this DIE. */
16926 cv_type
= get_die_type (die
, cu
);
16930 cv_type
= make_restrict_type (base_type
);
16931 return set_die_type (die
, cv_type
, cu
);
16934 /* Handle DW_TAG_atomic_type. */
16936 static struct type
*
16937 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16939 struct type
*base_type
, *cv_type
;
16941 base_type
= die_type (die
, cu
);
16943 /* The die_type call above may have already set the type for this DIE. */
16944 cv_type
= get_die_type (die
, cu
);
16948 cv_type
= make_atomic_type (base_type
);
16949 return set_die_type (die
, cv_type
, cu
);
16952 /* Extract all information from a DW_TAG_string_type DIE and add to
16953 the user defined type vector. It isn't really a user defined type,
16954 but it behaves like one, with other DIE's using an AT_user_def_type
16955 attribute to reference it. */
16957 static struct type
*
16958 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16960 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16961 struct gdbarch
*gdbarch
= objfile
->arch ();
16962 struct type
*type
, *range_type
, *index_type
, *char_type
;
16963 struct attribute
*attr
;
16964 struct dynamic_prop prop
;
16965 bool length_is_constant
= true;
16968 /* There are a couple of places where bit sizes might be made use of
16969 when parsing a DW_TAG_string_type, however, no producer that we know
16970 of make use of these. Handling bit sizes that are a multiple of the
16971 byte size is easy enough, but what about other bit sizes? Lets deal
16972 with that problem when we have to. Warn about these attributes being
16973 unsupported, then parse the type and ignore them like we always
16975 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16976 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16978 static bool warning_printed
= false;
16979 if (!warning_printed
)
16981 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16982 "currently supported on DW_TAG_string_type."));
16983 warning_printed
= true;
16987 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16988 if (attr
!= nullptr && !attr
->form_is_constant ())
16990 /* The string length describes the location at which the length of
16991 the string can be found. The size of the length field can be
16992 specified with one of the attributes below. */
16993 struct type
*prop_type
;
16994 struct attribute
*len
16995 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16996 if (len
== nullptr)
16997 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16998 if (len
!= nullptr && len
->form_is_constant ())
17000 /* Pass 0 as the default as we know this attribute is constant
17001 and the default value will not be returned. */
17002 LONGEST sz
= len
->constant_value (0);
17003 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17007 /* If the size is not specified then we assume it is the size of
17008 an address on this target. */
17009 prop_type
= cu
->addr_sized_int_type (true);
17012 /* Convert the attribute into a dynamic property. */
17013 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17016 length_is_constant
= false;
17018 else if (attr
!= nullptr)
17020 /* This DW_AT_string_length just contains the length with no
17021 indirection. There's no need to create a dynamic property in this
17022 case. Pass 0 for the default value as we know it will not be
17023 returned in this case. */
17024 length
= attr
->constant_value (0);
17026 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17028 /* We don't currently support non-constant byte sizes for strings. */
17029 length
= attr
->constant_value (1);
17033 /* Use 1 as a fallback length if we have nothing else. */
17037 index_type
= objfile_type (objfile
)->builtin_int
;
17038 if (length_is_constant
)
17039 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17042 struct dynamic_prop low_bound
;
17044 low_bound
.kind
= PROP_CONST
;
17045 low_bound
.data
.const_val
= 1;
17046 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17048 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17049 type
= create_string_type (NULL
, char_type
, range_type
);
17051 return set_die_type (die
, type
, cu
);
17054 /* Assuming that DIE corresponds to a function, returns nonzero
17055 if the function is prototyped. */
17058 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17060 struct attribute
*attr
;
17062 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17063 if (attr
&& (DW_UNSND (attr
) != 0))
17066 /* The DWARF standard implies that the DW_AT_prototyped attribute
17067 is only meaningful for C, but the concept also extends to other
17068 languages that allow unprototyped functions (Eg: Objective C).
17069 For all other languages, assume that functions are always
17071 if (cu
->language
!= language_c
17072 && cu
->language
!= language_objc
17073 && cu
->language
!= language_opencl
)
17076 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17077 prototyped and unprototyped functions; default to prototyped,
17078 since that is more common in modern code (and RealView warns
17079 about unprototyped functions). */
17080 if (producer_is_realview (cu
->producer
))
17086 /* Handle DIES due to C code like:
17090 int (*funcp)(int a, long l);
17094 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17096 static struct type
*
17097 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17099 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17100 struct type
*type
; /* Type that this function returns. */
17101 struct type
*ftype
; /* Function that returns above type. */
17102 struct attribute
*attr
;
17104 type
= die_type (die
, cu
);
17106 /* The die_type call above may have already set the type for this DIE. */
17107 ftype
= get_die_type (die
, cu
);
17111 ftype
= lookup_function_type (type
);
17113 if (prototyped_function_p (die
, cu
))
17114 TYPE_PROTOTYPED (ftype
) = 1;
17116 /* Store the calling convention in the type if it's available in
17117 the subroutine die. Otherwise set the calling convention to
17118 the default value DW_CC_normal. */
17119 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17120 if (attr
!= nullptr
17121 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17122 TYPE_CALLING_CONVENTION (ftype
)
17123 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17124 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17125 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17127 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17129 /* Record whether the function returns normally to its caller or not
17130 if the DWARF producer set that information. */
17131 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17132 if (attr
&& (DW_UNSND (attr
) != 0))
17133 TYPE_NO_RETURN (ftype
) = 1;
17135 /* We need to add the subroutine type to the die immediately so
17136 we don't infinitely recurse when dealing with parameters
17137 declared as the same subroutine type. */
17138 set_die_type (die
, ftype
, cu
);
17140 if (die
->child
!= NULL
)
17142 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17143 struct die_info
*child_die
;
17144 int nparams
, iparams
;
17146 /* Count the number of parameters.
17147 FIXME: GDB currently ignores vararg functions, but knows about
17148 vararg member functions. */
17150 child_die
= die
->child
;
17151 while (child_die
&& child_die
->tag
)
17153 if (child_die
->tag
== DW_TAG_formal_parameter
)
17155 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17156 TYPE_VARARGS (ftype
) = 1;
17157 child_die
= child_die
->sibling
;
17160 /* Allocate storage for parameters and fill them in. */
17161 ftype
->set_num_fields (nparams
);
17163 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17165 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17166 even if we error out during the parameters reading below. */
17167 for (iparams
= 0; iparams
< nparams
; iparams
++)
17168 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17171 child_die
= die
->child
;
17172 while (child_die
&& child_die
->tag
)
17174 if (child_die
->tag
== DW_TAG_formal_parameter
)
17176 struct type
*arg_type
;
17178 /* DWARF version 2 has no clean way to discern C++
17179 static and non-static member functions. G++ helps
17180 GDB by marking the first parameter for non-static
17181 member functions (which is the this pointer) as
17182 artificial. We pass this information to
17183 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17185 DWARF version 3 added DW_AT_object_pointer, which GCC
17186 4.5 does not yet generate. */
17187 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17188 if (attr
!= nullptr)
17189 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17191 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17192 arg_type
= die_type (child_die
, cu
);
17194 /* RealView does not mark THIS as const, which the testsuite
17195 expects. GCC marks THIS as const in method definitions,
17196 but not in the class specifications (GCC PR 43053). */
17197 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17198 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17201 struct dwarf2_cu
*arg_cu
= cu
;
17202 const char *name
= dwarf2_name (child_die
, cu
);
17204 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17205 if (attr
!= nullptr)
17207 /* If the compiler emits this, use it. */
17208 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17211 else if (name
&& strcmp (name
, "this") == 0)
17212 /* Function definitions will have the argument names. */
17214 else if (name
== NULL
&& iparams
== 0)
17215 /* Declarations may not have the names, so like
17216 elsewhere in GDB, assume an artificial first
17217 argument is "this". */
17221 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17225 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17228 child_die
= child_die
->sibling
;
17235 static struct type
*
17236 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17238 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17239 const char *name
= NULL
;
17240 struct type
*this_type
, *target_type
;
17242 name
= dwarf2_full_name (NULL
, die
, cu
);
17243 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17244 TYPE_TARGET_STUB (this_type
) = 1;
17245 set_die_type (die
, this_type
, cu
);
17246 target_type
= die_type (die
, cu
);
17247 if (target_type
!= this_type
)
17248 TYPE_TARGET_TYPE (this_type
) = target_type
;
17251 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17252 spec and cause infinite loops in GDB. */
17253 complaint (_("Self-referential DW_TAG_typedef "
17254 "- DIE at %s [in module %s]"),
17255 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17256 TYPE_TARGET_TYPE (this_type
) = NULL
;
17260 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17261 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17262 Handle these by just returning the target type, rather than
17263 constructing an anonymous typedef type and trying to handle this
17265 set_die_type (die
, target_type
, cu
);
17266 return target_type
;
17271 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17272 (which may be different from NAME) to the architecture back-end to allow
17273 it to guess the correct format if necessary. */
17275 static struct type
*
17276 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17277 const char *name_hint
, enum bfd_endian byte_order
)
17279 struct gdbarch
*gdbarch
= objfile
->arch ();
17280 const struct floatformat
**format
;
17283 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17285 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17287 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17292 /* Allocate an integer type of size BITS and name NAME. */
17294 static struct type
*
17295 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17296 int bits
, int unsigned_p
, const char *name
)
17300 /* Versions of Intel's C Compiler generate an integer type called "void"
17301 instead of using DW_TAG_unspecified_type. This has been seen on
17302 at least versions 14, 17, and 18. */
17303 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17304 && strcmp (name
, "void") == 0)
17305 type
= objfile_type (objfile
)->builtin_void
;
17307 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17312 /* Initialise and return a floating point type of size BITS suitable for
17313 use as a component of a complex number. The NAME_HINT is passed through
17314 when initialising the floating point type and is the name of the complex
17317 As DWARF doesn't currently provide an explicit name for the components
17318 of a complex number, but it can be helpful to have these components
17319 named, we try to select a suitable name based on the size of the
17321 static struct type
*
17322 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17323 struct objfile
*objfile
,
17324 int bits
, const char *name_hint
,
17325 enum bfd_endian byte_order
)
17327 gdbarch
*gdbarch
= objfile
->arch ();
17328 struct type
*tt
= nullptr;
17330 /* Try to find a suitable floating point builtin type of size BITS.
17331 We're going to use the name of this type as the name for the complex
17332 target type that we are about to create. */
17333 switch (cu
->language
)
17335 case language_fortran
:
17339 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17342 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17344 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17346 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17354 tt
= builtin_type (gdbarch
)->builtin_float
;
17357 tt
= builtin_type (gdbarch
)->builtin_double
;
17359 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17361 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17367 /* If the type we found doesn't match the size we were looking for, then
17368 pretend we didn't find a type at all, the complex target type we
17369 create will then be nameless. */
17370 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17373 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17374 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17377 /* Find a representation of a given base type and install
17378 it in the TYPE field of the die. */
17380 static struct type
*
17381 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17383 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17385 struct attribute
*attr
;
17386 int encoding
= 0, bits
= 0;
17390 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17391 if (attr
!= nullptr)
17392 encoding
= DW_UNSND (attr
);
17393 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17394 if (attr
!= nullptr)
17395 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17396 name
= dwarf2_name (die
, cu
);
17398 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17400 arch
= objfile
->arch ();
17401 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17403 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17406 int endianity
= DW_UNSND (attr
);
17411 byte_order
= BFD_ENDIAN_BIG
;
17413 case DW_END_little
:
17414 byte_order
= BFD_ENDIAN_LITTLE
;
17417 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17424 case DW_ATE_address
:
17425 /* Turn DW_ATE_address into a void * pointer. */
17426 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17427 type
= init_pointer_type (objfile
, bits
, name
, type
);
17429 case DW_ATE_boolean
:
17430 type
= init_boolean_type (objfile
, bits
, 1, name
);
17432 case DW_ATE_complex_float
:
17433 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17435 if (type
->code () == TYPE_CODE_ERROR
)
17437 if (name
== nullptr)
17439 struct obstack
*obstack
17440 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17441 name
= obconcat (obstack
, "_Complex ", type
->name (),
17444 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17447 type
= init_complex_type (name
, type
);
17449 case DW_ATE_decimal_float
:
17450 type
= init_decfloat_type (objfile
, bits
, name
);
17453 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17455 case DW_ATE_signed
:
17456 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17458 case DW_ATE_unsigned
:
17459 if (cu
->language
== language_fortran
17461 && startswith (name
, "character("))
17462 type
= init_character_type (objfile
, bits
, 1, name
);
17464 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17466 case DW_ATE_signed_char
:
17467 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17468 || cu
->language
== language_pascal
17469 || cu
->language
== language_fortran
)
17470 type
= init_character_type (objfile
, bits
, 0, name
);
17472 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17474 case DW_ATE_unsigned_char
:
17475 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17476 || cu
->language
== language_pascal
17477 || cu
->language
== language_fortran
17478 || cu
->language
== language_rust
)
17479 type
= init_character_type (objfile
, bits
, 1, name
);
17481 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17486 type
= builtin_type (arch
)->builtin_char16
;
17487 else if (bits
== 32)
17488 type
= builtin_type (arch
)->builtin_char32
;
17491 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17493 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17495 return set_die_type (die
, type
, cu
);
17500 complaint (_("unsupported DW_AT_encoding: '%s'"),
17501 dwarf_type_encoding_name (encoding
));
17502 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17506 if (name
&& strcmp (name
, "char") == 0)
17507 TYPE_NOSIGN (type
) = 1;
17509 maybe_set_alignment (cu
, die
, type
);
17511 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17513 return set_die_type (die
, type
, cu
);
17516 /* Parse dwarf attribute if it's a block, reference or constant and put the
17517 resulting value of the attribute into struct bound_prop.
17518 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17521 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17522 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17523 struct type
*default_type
)
17525 struct dwarf2_property_baton
*baton
;
17526 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17527 struct objfile
*objfile
= per_objfile
->objfile
;
17528 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17530 gdb_assert (default_type
!= NULL
);
17532 if (attr
== NULL
|| prop
== NULL
)
17535 if (attr
->form_is_block ())
17537 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17538 baton
->property_type
= default_type
;
17539 baton
->locexpr
.per_cu
= cu
->per_cu
;
17540 baton
->locexpr
.per_objfile
= per_objfile
;
17541 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17542 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17543 switch (attr
->name
)
17545 case DW_AT_string_length
:
17546 baton
->locexpr
.is_reference
= true;
17549 baton
->locexpr
.is_reference
= false;
17552 prop
->data
.baton
= baton
;
17553 prop
->kind
= PROP_LOCEXPR
;
17554 gdb_assert (prop
->data
.baton
!= NULL
);
17556 else if (attr
->form_is_ref ())
17558 struct dwarf2_cu
*target_cu
= cu
;
17559 struct die_info
*target_die
;
17560 struct attribute
*target_attr
;
17562 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17563 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17564 if (target_attr
== NULL
)
17565 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17567 if (target_attr
== NULL
)
17570 switch (target_attr
->name
)
17572 case DW_AT_location
:
17573 if (target_attr
->form_is_section_offset ())
17575 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17576 baton
->property_type
= die_type (target_die
, target_cu
);
17577 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17578 prop
->data
.baton
= baton
;
17579 prop
->kind
= PROP_LOCLIST
;
17580 gdb_assert (prop
->data
.baton
!= NULL
);
17582 else if (target_attr
->form_is_block ())
17584 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17585 baton
->property_type
= die_type (target_die
, target_cu
);
17586 baton
->locexpr
.per_cu
= cu
->per_cu
;
17587 baton
->locexpr
.per_objfile
= per_objfile
;
17588 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17589 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17590 baton
->locexpr
.is_reference
= true;
17591 prop
->data
.baton
= baton
;
17592 prop
->kind
= PROP_LOCEXPR
;
17593 gdb_assert (prop
->data
.baton
!= NULL
);
17597 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17598 "dynamic property");
17602 case DW_AT_data_member_location
:
17606 if (!handle_data_member_location (target_die
, target_cu
,
17610 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17611 baton
->property_type
= read_type_die (target_die
->parent
,
17613 baton
->offset_info
.offset
= offset
;
17614 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17615 prop
->data
.baton
= baton
;
17616 prop
->kind
= PROP_ADDR_OFFSET
;
17621 else if (attr
->form_is_constant ())
17623 prop
->data
.const_val
= attr
->constant_value (0);
17624 prop
->kind
= PROP_CONST
;
17628 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17629 dwarf2_name (die
, cu
));
17639 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17641 struct type
*int_type
;
17643 /* Helper macro to examine the various builtin types. */
17644 #define TRY_TYPE(F) \
17645 int_type = (unsigned_p \
17646 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17647 : objfile_type (objfile)->builtin_ ## F); \
17648 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17655 TRY_TYPE (long_long
);
17659 gdb_assert_not_reached ("unable to find suitable integer type");
17665 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17667 int addr_size
= this->per_cu
->addr_size ();
17668 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17671 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17672 present (which is valid) then compute the default type based on the
17673 compilation units address size. */
17675 static struct type
*
17676 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17678 struct type
*index_type
= die_type (die
, cu
);
17680 /* Dwarf-2 specifications explicitly allows to create subrange types
17681 without specifying a base type.
17682 In that case, the base type must be set to the type of
17683 the lower bound, upper bound or count, in that order, if any of these
17684 three attributes references an object that has a type.
17685 If no base type is found, the Dwarf-2 specifications say that
17686 a signed integer type of size equal to the size of an address should
17688 For the following C code: `extern char gdb_int [];'
17689 GCC produces an empty range DIE.
17690 FIXME: muller/2010-05-28: Possible references to object for low bound,
17691 high bound or count are not yet handled by this code. */
17692 if (index_type
->code () == TYPE_CODE_VOID
)
17693 index_type
= cu
->addr_sized_int_type (false);
17698 /* Read the given DW_AT_subrange DIE. */
17700 static struct type
*
17701 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17703 struct type
*base_type
, *orig_base_type
;
17704 struct type
*range_type
;
17705 struct attribute
*attr
;
17706 struct dynamic_prop low
, high
;
17707 int low_default_is_valid
;
17708 int high_bound_is_count
= 0;
17710 ULONGEST negative_mask
;
17712 orig_base_type
= read_subrange_index_type (die
, cu
);
17714 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17715 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17716 creating the range type, but we use the result of check_typedef
17717 when examining properties of the type. */
17718 base_type
= check_typedef (orig_base_type
);
17720 /* The die_type call above may have already set the type for this DIE. */
17721 range_type
= get_die_type (die
, cu
);
17725 low
.kind
= PROP_CONST
;
17726 high
.kind
= PROP_CONST
;
17727 high
.data
.const_val
= 0;
17729 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17730 omitting DW_AT_lower_bound. */
17731 switch (cu
->language
)
17734 case language_cplus
:
17735 low
.data
.const_val
= 0;
17736 low_default_is_valid
= 1;
17738 case language_fortran
:
17739 low
.data
.const_val
= 1;
17740 low_default_is_valid
= 1;
17743 case language_objc
:
17744 case language_rust
:
17745 low
.data
.const_val
= 0;
17746 low_default_is_valid
= (cu
->header
.version
>= 4);
17750 case language_pascal
:
17751 low
.data
.const_val
= 1;
17752 low_default_is_valid
= (cu
->header
.version
>= 4);
17755 low
.data
.const_val
= 0;
17756 low_default_is_valid
= 0;
17760 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17761 if (attr
!= nullptr)
17762 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17763 else if (!low_default_is_valid
)
17764 complaint (_("Missing DW_AT_lower_bound "
17765 "- DIE at %s [in module %s]"),
17766 sect_offset_str (die
->sect_off
),
17767 objfile_name (cu
->per_objfile
->objfile
));
17769 struct attribute
*attr_ub
, *attr_count
;
17770 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17771 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17773 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17774 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17776 /* If bounds are constant do the final calculation here. */
17777 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17778 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17780 high_bound_is_count
= 1;
17784 if (attr_ub
!= NULL
)
17785 complaint (_("Unresolved DW_AT_upper_bound "
17786 "- DIE at %s [in module %s]"),
17787 sect_offset_str (die
->sect_off
),
17788 objfile_name (cu
->per_objfile
->objfile
));
17789 if (attr_count
!= NULL
)
17790 complaint (_("Unresolved DW_AT_count "
17791 "- DIE at %s [in module %s]"),
17792 sect_offset_str (die
->sect_off
),
17793 objfile_name (cu
->per_objfile
->objfile
));
17798 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17799 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17800 bias
= bias_attr
->constant_value (0);
17802 /* Normally, the DWARF producers are expected to use a signed
17803 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17804 But this is unfortunately not always the case, as witnessed
17805 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17806 is used instead. To work around that ambiguity, we treat
17807 the bounds as signed, and thus sign-extend their values, when
17808 the base type is signed. */
17810 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17811 if (low
.kind
== PROP_CONST
17812 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17813 low
.data
.const_val
|= negative_mask
;
17814 if (high
.kind
== PROP_CONST
17815 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17816 high
.data
.const_val
|= negative_mask
;
17818 /* Check for bit and byte strides. */
17819 struct dynamic_prop byte_stride_prop
;
17820 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17821 if (attr_byte_stride
!= nullptr)
17823 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17824 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17828 struct dynamic_prop bit_stride_prop
;
17829 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17830 if (attr_bit_stride
!= nullptr)
17832 /* It only makes sense to have either a bit or byte stride. */
17833 if (attr_byte_stride
!= nullptr)
17835 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17836 "- DIE at %s [in module %s]"),
17837 sect_offset_str (die
->sect_off
),
17838 objfile_name (cu
->per_objfile
->objfile
));
17839 attr_bit_stride
= nullptr;
17843 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17844 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17849 if (attr_byte_stride
!= nullptr
17850 || attr_bit_stride
!= nullptr)
17852 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17853 struct dynamic_prop
*stride
17854 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17857 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17858 &high
, bias
, stride
, byte_stride_p
);
17861 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17863 if (high_bound_is_count
)
17864 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17866 /* Ada expects an empty array on no boundary attributes. */
17867 if (attr
== NULL
&& cu
->language
!= language_ada
)
17868 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17870 name
= dwarf2_name (die
, cu
);
17872 range_type
->set_name (name
);
17874 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17875 if (attr
!= nullptr)
17876 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17878 maybe_set_alignment (cu
, die
, range_type
);
17880 set_die_type (die
, range_type
, cu
);
17882 /* set_die_type should be already done. */
17883 set_descriptive_type (range_type
, die
, cu
);
17888 static struct type
*
17889 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17893 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17894 type
->set_name (dwarf2_name (die
, cu
));
17896 /* In Ada, an unspecified type is typically used when the description
17897 of the type is deferred to a different unit. When encountering
17898 such a type, we treat it as a stub, and try to resolve it later on,
17900 if (cu
->language
== language_ada
)
17901 TYPE_STUB (type
) = 1;
17903 return set_die_type (die
, type
, cu
);
17906 /* Read a single die and all its descendents. Set the die's sibling
17907 field to NULL; set other fields in the die correctly, and set all
17908 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17909 location of the info_ptr after reading all of those dies. PARENT
17910 is the parent of the die in question. */
17912 static struct die_info
*
17913 read_die_and_children (const struct die_reader_specs
*reader
,
17914 const gdb_byte
*info_ptr
,
17915 const gdb_byte
**new_info_ptr
,
17916 struct die_info
*parent
)
17918 struct die_info
*die
;
17919 const gdb_byte
*cur_ptr
;
17921 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17924 *new_info_ptr
= cur_ptr
;
17927 store_in_ref_table (die
, reader
->cu
);
17929 if (die
->has_children
)
17930 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17934 *new_info_ptr
= cur_ptr
;
17937 die
->sibling
= NULL
;
17938 die
->parent
= parent
;
17942 /* Read a die, all of its descendents, and all of its siblings; set
17943 all of the fields of all of the dies correctly. Arguments are as
17944 in read_die_and_children. */
17946 static struct die_info
*
17947 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17948 const gdb_byte
*info_ptr
,
17949 const gdb_byte
**new_info_ptr
,
17950 struct die_info
*parent
)
17952 struct die_info
*first_die
, *last_sibling
;
17953 const gdb_byte
*cur_ptr
;
17955 cur_ptr
= info_ptr
;
17956 first_die
= last_sibling
= NULL
;
17960 struct die_info
*die
17961 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17965 *new_info_ptr
= cur_ptr
;
17972 last_sibling
->sibling
= die
;
17974 last_sibling
= die
;
17978 /* Read a die, all of its descendents, and all of its siblings; set
17979 all of the fields of all of the dies correctly. Arguments are as
17980 in read_die_and_children.
17981 This the main entry point for reading a DIE and all its children. */
17983 static struct die_info
*
17984 read_die_and_siblings (const struct die_reader_specs
*reader
,
17985 const gdb_byte
*info_ptr
,
17986 const gdb_byte
**new_info_ptr
,
17987 struct die_info
*parent
)
17989 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17990 new_info_ptr
, parent
);
17992 if (dwarf_die_debug
)
17994 fprintf_unfiltered (gdb_stdlog
,
17995 "Read die from %s@0x%x of %s:\n",
17996 reader
->die_section
->get_name (),
17997 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17998 bfd_get_filename (reader
->abfd
));
17999 dump_die (die
, dwarf_die_debug
);
18005 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18007 The caller is responsible for filling in the extra attributes
18008 and updating (*DIEP)->num_attrs.
18009 Set DIEP to point to a newly allocated die with its information,
18010 except for its child, sibling, and parent fields. */
18012 static const gdb_byte
*
18013 read_full_die_1 (const struct die_reader_specs
*reader
,
18014 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18015 int num_extra_attrs
)
18017 unsigned int abbrev_number
, bytes_read
, i
;
18018 struct abbrev_info
*abbrev
;
18019 struct die_info
*die
;
18020 struct dwarf2_cu
*cu
= reader
->cu
;
18021 bfd
*abfd
= reader
->abfd
;
18023 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18024 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18025 info_ptr
+= bytes_read
;
18026 if (!abbrev_number
)
18032 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18034 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18036 bfd_get_filename (abfd
));
18038 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18039 die
->sect_off
= sect_off
;
18040 die
->tag
= abbrev
->tag
;
18041 die
->abbrev
= abbrev_number
;
18042 die
->has_children
= abbrev
->has_children
;
18044 /* Make the result usable.
18045 The caller needs to update num_attrs after adding the extra
18047 die
->num_attrs
= abbrev
->num_attrs
;
18049 std::vector
<int> indexes_that_need_reprocess
;
18050 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18052 bool need_reprocess
;
18054 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18055 info_ptr
, &need_reprocess
);
18056 if (need_reprocess
)
18057 indexes_that_need_reprocess
.push_back (i
);
18060 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18061 if (attr
!= nullptr)
18062 cu
->str_offsets_base
= DW_UNSND (attr
);
18064 attr
= die
->attr (DW_AT_loclists_base
);
18065 if (attr
!= nullptr)
18066 cu
->loclist_base
= DW_UNSND (attr
);
18068 auto maybe_addr_base
= die
->addr_base ();
18069 if (maybe_addr_base
.has_value ())
18070 cu
->addr_base
= *maybe_addr_base
;
18071 for (int index
: indexes_that_need_reprocess
)
18072 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18077 /* Read a die and all its attributes.
18078 Set DIEP to point to a newly allocated die with its information,
18079 except for its child, sibling, and parent fields. */
18081 static const gdb_byte
*
18082 read_full_die (const struct die_reader_specs
*reader
,
18083 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18085 const gdb_byte
*result
;
18087 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18089 if (dwarf_die_debug
)
18091 fprintf_unfiltered (gdb_stdlog
,
18092 "Read die from %s@0x%x of %s:\n",
18093 reader
->die_section
->get_name (),
18094 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18095 bfd_get_filename (reader
->abfd
));
18096 dump_die (*diep
, dwarf_die_debug
);
18103 /* Returns nonzero if TAG represents a type that we might generate a partial
18107 is_type_tag_for_partial (int tag
)
18112 /* Some types that would be reasonable to generate partial symbols for,
18113 that we don't at present. */
18114 case DW_TAG_array_type
:
18115 case DW_TAG_file_type
:
18116 case DW_TAG_ptr_to_member_type
:
18117 case DW_TAG_set_type
:
18118 case DW_TAG_string_type
:
18119 case DW_TAG_subroutine_type
:
18121 case DW_TAG_base_type
:
18122 case DW_TAG_class_type
:
18123 case DW_TAG_interface_type
:
18124 case DW_TAG_enumeration_type
:
18125 case DW_TAG_structure_type
:
18126 case DW_TAG_subrange_type
:
18127 case DW_TAG_typedef
:
18128 case DW_TAG_union_type
:
18135 /* Load all DIEs that are interesting for partial symbols into memory. */
18137 static struct partial_die_info
*
18138 load_partial_dies (const struct die_reader_specs
*reader
,
18139 const gdb_byte
*info_ptr
, int building_psymtab
)
18141 struct dwarf2_cu
*cu
= reader
->cu
;
18142 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18143 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18144 unsigned int bytes_read
;
18145 unsigned int load_all
= 0;
18146 int nesting_level
= 1;
18151 gdb_assert (cu
->per_cu
!= NULL
);
18152 if (cu
->per_cu
->load_all_dies
)
18156 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18160 &cu
->comp_unit_obstack
,
18161 hashtab_obstack_allocate
,
18162 dummy_obstack_deallocate
);
18166 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18168 /* A NULL abbrev means the end of a series of children. */
18169 if (abbrev
== NULL
)
18171 if (--nesting_level
== 0)
18174 info_ptr
+= bytes_read
;
18175 last_die
= parent_die
;
18176 parent_die
= parent_die
->die_parent
;
18180 /* Check for template arguments. We never save these; if
18181 they're seen, we just mark the parent, and go on our way. */
18182 if (parent_die
!= NULL
18183 && cu
->language
== language_cplus
18184 && (abbrev
->tag
== DW_TAG_template_type_param
18185 || abbrev
->tag
== DW_TAG_template_value_param
))
18187 parent_die
->has_template_arguments
= 1;
18191 /* We don't need a partial DIE for the template argument. */
18192 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18197 /* We only recurse into c++ subprograms looking for template arguments.
18198 Skip their other children. */
18200 && cu
->language
== language_cplus
18201 && parent_die
!= NULL
18202 && parent_die
->tag
== DW_TAG_subprogram
)
18204 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18208 /* Check whether this DIE is interesting enough to save. Normally
18209 we would not be interested in members here, but there may be
18210 later variables referencing them via DW_AT_specification (for
18211 static members). */
18213 && !is_type_tag_for_partial (abbrev
->tag
)
18214 && abbrev
->tag
!= DW_TAG_constant
18215 && abbrev
->tag
!= DW_TAG_enumerator
18216 && abbrev
->tag
!= DW_TAG_subprogram
18217 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18218 && abbrev
->tag
!= DW_TAG_lexical_block
18219 && abbrev
->tag
!= DW_TAG_variable
18220 && abbrev
->tag
!= DW_TAG_namespace
18221 && abbrev
->tag
!= DW_TAG_module
18222 && abbrev
->tag
!= DW_TAG_member
18223 && abbrev
->tag
!= DW_TAG_imported_unit
18224 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18226 /* Otherwise we skip to the next sibling, if any. */
18227 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18231 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18234 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18236 /* This two-pass algorithm for processing partial symbols has a
18237 high cost in cache pressure. Thus, handle some simple cases
18238 here which cover the majority of C partial symbols. DIEs
18239 which neither have specification tags in them, nor could have
18240 specification tags elsewhere pointing at them, can simply be
18241 processed and discarded.
18243 This segment is also optional; scan_partial_symbols and
18244 add_partial_symbol will handle these DIEs if we chain
18245 them in normally. When compilers which do not emit large
18246 quantities of duplicate debug information are more common,
18247 this code can probably be removed. */
18249 /* Any complete simple types at the top level (pretty much all
18250 of them, for a language without namespaces), can be processed
18252 if (parent_die
== NULL
18253 && pdi
.has_specification
== 0
18254 && pdi
.is_declaration
== 0
18255 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18256 || pdi
.tag
== DW_TAG_base_type
18257 || pdi
.tag
== DW_TAG_subrange_type
))
18259 if (building_psymtab
&& pdi
.name
!= NULL
)
18260 add_psymbol_to_list (pdi
.name
, false,
18261 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18262 psymbol_placement::STATIC
,
18263 0, cu
->language
, objfile
);
18264 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18268 /* The exception for DW_TAG_typedef with has_children above is
18269 a workaround of GCC PR debug/47510. In the case of this complaint
18270 type_name_or_error will error on such types later.
18272 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18273 it could not find the child DIEs referenced later, this is checked
18274 above. In correct DWARF DW_TAG_typedef should have no children. */
18276 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18277 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18278 "- DIE at %s [in module %s]"),
18279 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18281 /* If we're at the second level, and we're an enumerator, and
18282 our parent has no specification (meaning possibly lives in a
18283 namespace elsewhere), then we can add the partial symbol now
18284 instead of queueing it. */
18285 if (pdi
.tag
== DW_TAG_enumerator
18286 && parent_die
!= NULL
18287 && parent_die
->die_parent
== NULL
18288 && parent_die
->tag
== DW_TAG_enumeration_type
18289 && parent_die
->has_specification
== 0)
18291 if (pdi
.name
== NULL
)
18292 complaint (_("malformed enumerator DIE ignored"));
18293 else if (building_psymtab
)
18294 add_psymbol_to_list (pdi
.name
, false,
18295 VAR_DOMAIN
, LOC_CONST
, -1,
18296 cu
->language
== language_cplus
18297 ? psymbol_placement::GLOBAL
18298 : psymbol_placement::STATIC
,
18299 0, cu
->language
, objfile
);
18301 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18305 struct partial_die_info
*part_die
18306 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18308 /* We'll save this DIE so link it in. */
18309 part_die
->die_parent
= parent_die
;
18310 part_die
->die_sibling
= NULL
;
18311 part_die
->die_child
= NULL
;
18313 if (last_die
&& last_die
== parent_die
)
18314 last_die
->die_child
= part_die
;
18316 last_die
->die_sibling
= part_die
;
18318 last_die
= part_die
;
18320 if (first_die
== NULL
)
18321 first_die
= part_die
;
18323 /* Maybe add the DIE to the hash table. Not all DIEs that we
18324 find interesting need to be in the hash table, because we
18325 also have the parent/sibling/child chains; only those that we
18326 might refer to by offset later during partial symbol reading.
18328 For now this means things that might have be the target of a
18329 DW_AT_specification, DW_AT_abstract_origin, or
18330 DW_AT_extension. DW_AT_extension will refer only to
18331 namespaces; DW_AT_abstract_origin refers to functions (and
18332 many things under the function DIE, but we do not recurse
18333 into function DIEs during partial symbol reading) and
18334 possibly variables as well; DW_AT_specification refers to
18335 declarations. Declarations ought to have the DW_AT_declaration
18336 flag. It happens that GCC forgets to put it in sometimes, but
18337 only for functions, not for types.
18339 Adding more things than necessary to the hash table is harmless
18340 except for the performance cost. Adding too few will result in
18341 wasted time in find_partial_die, when we reread the compilation
18342 unit with load_all_dies set. */
18345 || abbrev
->tag
== DW_TAG_constant
18346 || abbrev
->tag
== DW_TAG_subprogram
18347 || abbrev
->tag
== DW_TAG_variable
18348 || abbrev
->tag
== DW_TAG_namespace
18349 || part_die
->is_declaration
)
18353 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18354 to_underlying (part_die
->sect_off
),
18359 /* For some DIEs we want to follow their children (if any). For C
18360 we have no reason to follow the children of structures; for other
18361 languages we have to, so that we can get at method physnames
18362 to infer fully qualified class names, for DW_AT_specification,
18363 and for C++ template arguments. For C++, we also look one level
18364 inside functions to find template arguments (if the name of the
18365 function does not already contain the template arguments).
18367 For Ada and Fortran, we need to scan the children of subprograms
18368 and lexical blocks as well because these languages allow the
18369 definition of nested entities that could be interesting for the
18370 debugger, such as nested subprograms for instance. */
18371 if (last_die
->has_children
18373 || last_die
->tag
== DW_TAG_namespace
18374 || last_die
->tag
== DW_TAG_module
18375 || last_die
->tag
== DW_TAG_enumeration_type
18376 || (cu
->language
== language_cplus
18377 && last_die
->tag
== DW_TAG_subprogram
18378 && (last_die
->name
== NULL
18379 || strchr (last_die
->name
, '<') == NULL
))
18380 || (cu
->language
!= language_c
18381 && (last_die
->tag
== DW_TAG_class_type
18382 || last_die
->tag
== DW_TAG_interface_type
18383 || last_die
->tag
== DW_TAG_structure_type
18384 || last_die
->tag
== DW_TAG_union_type
))
18385 || ((cu
->language
== language_ada
18386 || cu
->language
== language_fortran
)
18387 && (last_die
->tag
== DW_TAG_subprogram
18388 || last_die
->tag
== DW_TAG_lexical_block
))))
18391 parent_die
= last_die
;
18395 /* Otherwise we skip to the next sibling, if any. */
18396 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18398 /* Back to the top, do it again. */
18402 partial_die_info::partial_die_info (sect_offset sect_off_
,
18403 struct abbrev_info
*abbrev
)
18404 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18408 /* Read a minimal amount of information into the minimal die structure.
18409 INFO_PTR should point just after the initial uleb128 of a DIE. */
18412 partial_die_info::read (const struct die_reader_specs
*reader
,
18413 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18415 struct dwarf2_cu
*cu
= reader
->cu
;
18416 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18418 int has_low_pc_attr
= 0;
18419 int has_high_pc_attr
= 0;
18420 int high_pc_relative
= 0;
18422 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18425 bool need_reprocess
;
18426 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18427 info_ptr
, &need_reprocess
);
18428 /* String and address offsets that need to do the reprocessing have
18429 already been read at this point, so there is no need to wait until
18430 the loop terminates to do the reprocessing. */
18431 if (need_reprocess
)
18432 read_attribute_reprocess (reader
, &attr
);
18433 /* Store the data if it is of an attribute we want to keep in a
18434 partial symbol table. */
18440 case DW_TAG_compile_unit
:
18441 case DW_TAG_partial_unit
:
18442 case DW_TAG_type_unit
:
18443 /* Compilation units have a DW_AT_name that is a filename, not
18444 a source language identifier. */
18445 case DW_TAG_enumeration_type
:
18446 case DW_TAG_enumerator
:
18447 /* These tags always have simple identifiers already; no need
18448 to canonicalize them. */
18449 name
= DW_STRING (&attr
);
18453 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18456 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18461 case DW_AT_linkage_name
:
18462 case DW_AT_MIPS_linkage_name
:
18463 /* Note that both forms of linkage name might appear. We
18464 assume they will be the same, and we only store the last
18466 linkage_name
= attr
.value_as_string ();
18467 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18468 See https://github.com/rust-lang/rust/issues/32925. */
18469 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18470 && strchr (linkage_name
, '{') != NULL
)
18471 linkage_name
= NULL
;
18474 has_low_pc_attr
= 1;
18475 lowpc
= attr
.value_as_address ();
18477 case DW_AT_high_pc
:
18478 has_high_pc_attr
= 1;
18479 highpc
= attr
.value_as_address ();
18480 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18481 high_pc_relative
= 1;
18483 case DW_AT_location
:
18484 /* Support the .debug_loc offsets. */
18485 if (attr
.form_is_block ())
18487 d
.locdesc
= DW_BLOCK (&attr
);
18489 else if (attr
.form_is_section_offset ())
18491 dwarf2_complex_location_expr_complaint ();
18495 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18496 "partial symbol information");
18499 case DW_AT_external
:
18500 is_external
= DW_UNSND (&attr
);
18502 case DW_AT_declaration
:
18503 is_declaration
= DW_UNSND (&attr
);
18508 case DW_AT_abstract_origin
:
18509 case DW_AT_specification
:
18510 case DW_AT_extension
:
18511 has_specification
= 1;
18512 spec_offset
= attr
.get_ref_die_offset ();
18513 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18514 || cu
->per_cu
->is_dwz
);
18516 case DW_AT_sibling
:
18517 /* Ignore absolute siblings, they might point outside of
18518 the current compile unit. */
18519 if (attr
.form
== DW_FORM_ref_addr
)
18520 complaint (_("ignoring absolute DW_AT_sibling"));
18523 const gdb_byte
*buffer
= reader
->buffer
;
18524 sect_offset off
= attr
.get_ref_die_offset ();
18525 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18527 if (sibling_ptr
< info_ptr
)
18528 complaint (_("DW_AT_sibling points backwards"));
18529 else if (sibling_ptr
> reader
->buffer_end
)
18530 reader
->die_section
->overflow_complaint ();
18532 sibling
= sibling_ptr
;
18535 case DW_AT_byte_size
:
18538 case DW_AT_const_value
:
18539 has_const_value
= 1;
18541 case DW_AT_calling_convention
:
18542 /* DWARF doesn't provide a way to identify a program's source-level
18543 entry point. DW_AT_calling_convention attributes are only meant
18544 to describe functions' calling conventions.
18546 However, because it's a necessary piece of information in
18547 Fortran, and before DWARF 4 DW_CC_program was the only
18548 piece of debugging information whose definition refers to
18549 a 'main program' at all, several compilers marked Fortran
18550 main programs with DW_CC_program --- even when those
18551 functions use the standard calling conventions.
18553 Although DWARF now specifies a way to provide this
18554 information, we support this practice for backward
18556 if (DW_UNSND (&attr
) == DW_CC_program
18557 && cu
->language
== language_fortran
)
18558 main_subprogram
= 1;
18561 if (DW_UNSND (&attr
) == DW_INL_inlined
18562 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18563 may_be_inlined
= 1;
18567 if (tag
== DW_TAG_imported_unit
)
18569 d
.sect_off
= attr
.get_ref_die_offset ();
18570 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18571 || cu
->per_cu
->is_dwz
);
18575 case DW_AT_main_subprogram
:
18576 main_subprogram
= DW_UNSND (&attr
);
18581 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18582 but that requires a full DIE, so instead we just
18584 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18585 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18586 + (need_ranges_base
18590 /* Value of the DW_AT_ranges attribute is the offset in the
18591 .debug_ranges section. */
18592 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18603 /* For Ada, if both the name and the linkage name appear, we prefer
18604 the latter. This lets "catch exception" work better, regardless
18605 of the order in which the name and linkage name were emitted.
18606 Really, though, this is just a workaround for the fact that gdb
18607 doesn't store both the name and the linkage name. */
18608 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18609 name
= linkage_name
;
18611 if (high_pc_relative
)
18614 if (has_low_pc_attr
&& has_high_pc_attr
)
18616 /* When using the GNU linker, .gnu.linkonce. sections are used to
18617 eliminate duplicate copies of functions and vtables and such.
18618 The linker will arbitrarily choose one and discard the others.
18619 The AT_*_pc values for such functions refer to local labels in
18620 these sections. If the section from that file was discarded, the
18621 labels are not in the output, so the relocs get a value of 0.
18622 If this is a discarded function, mark the pc bounds as invalid,
18623 so that GDB will ignore it. */
18624 if (lowpc
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
18626 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18627 struct gdbarch
*gdbarch
= objfile
->arch ();
18629 complaint (_("DW_AT_low_pc %s is zero "
18630 "for DIE at %s [in module %s]"),
18631 paddress (gdbarch
, lowpc
),
18632 sect_offset_str (sect_off
),
18633 objfile_name (objfile
));
18635 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18636 else if (lowpc
>= highpc
)
18638 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18639 struct gdbarch
*gdbarch
= objfile
->arch ();
18641 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18642 "for DIE at %s [in module %s]"),
18643 paddress (gdbarch
, lowpc
),
18644 paddress (gdbarch
, highpc
),
18645 sect_offset_str (sect_off
),
18646 objfile_name (objfile
));
18655 /* Find a cached partial DIE at OFFSET in CU. */
18657 struct partial_die_info
*
18658 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18660 struct partial_die_info
*lookup_die
= NULL
;
18661 struct partial_die_info
part_die (sect_off
);
18663 lookup_die
= ((struct partial_die_info
*)
18664 htab_find_with_hash (partial_dies
, &part_die
,
18665 to_underlying (sect_off
)));
18670 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18671 except in the case of .debug_types DIEs which do not reference
18672 outside their CU (they do however referencing other types via
18673 DW_FORM_ref_sig8). */
18675 static const struct cu_partial_die_info
18676 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18678 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18679 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18680 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18681 struct partial_die_info
*pd
= NULL
;
18683 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18684 && cu
->header
.offset_in_cu_p (sect_off
))
18686 pd
= cu
->find_partial_die (sect_off
);
18689 /* We missed recording what we needed.
18690 Load all dies and try again. */
18691 per_cu
= cu
->per_cu
;
18695 /* TUs don't reference other CUs/TUs (except via type signatures). */
18696 if (cu
->per_cu
->is_debug_types
)
18698 error (_("Dwarf Error: Type Unit at offset %s contains"
18699 " external reference to offset %s [in module %s].\n"),
18700 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18701 bfd_get_filename (objfile
->obfd
));
18703 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18704 dwarf2_per_objfile
);
18706 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18707 load_partial_comp_unit (per_cu
, cu
->per_objfile
);
18709 per_cu
->cu
->last_used
= 0;
18710 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18713 /* If we didn't find it, and not all dies have been loaded,
18714 load them all and try again. */
18716 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18718 per_cu
->load_all_dies
= 1;
18720 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18721 THIS_CU->cu may already be in use. So we can't just free it and
18722 replace its DIEs with the ones we read in. Instead, we leave those
18723 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18724 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18726 load_partial_comp_unit (per_cu
, cu
->per_objfile
);
18728 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18732 internal_error (__FILE__
, __LINE__
,
18733 _("could not find partial DIE %s "
18734 "in cache [from module %s]\n"),
18735 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18736 return { per_cu
->cu
, pd
};
18739 /* See if we can figure out if the class lives in a namespace. We do
18740 this by looking for a member function; its demangled name will
18741 contain namespace info, if there is any. */
18744 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18745 struct dwarf2_cu
*cu
)
18747 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18748 what template types look like, because the demangler
18749 frequently doesn't give the same name as the debug info. We
18750 could fix this by only using the demangled name to get the
18751 prefix (but see comment in read_structure_type). */
18753 struct partial_die_info
*real_pdi
;
18754 struct partial_die_info
*child_pdi
;
18756 /* If this DIE (this DIE's specification, if any) has a parent, then
18757 we should not do this. We'll prepend the parent's fully qualified
18758 name when we create the partial symbol. */
18760 real_pdi
= struct_pdi
;
18761 while (real_pdi
->has_specification
)
18763 auto res
= find_partial_die (real_pdi
->spec_offset
,
18764 real_pdi
->spec_is_dwz
, cu
);
18765 real_pdi
= res
.pdi
;
18769 if (real_pdi
->die_parent
!= NULL
)
18772 for (child_pdi
= struct_pdi
->die_child
;
18774 child_pdi
= child_pdi
->die_sibling
)
18776 if (child_pdi
->tag
== DW_TAG_subprogram
18777 && child_pdi
->linkage_name
!= NULL
)
18779 gdb::unique_xmalloc_ptr
<char> actual_class_name
18780 (language_class_name_from_physname (cu
->language_defn
,
18781 child_pdi
->linkage_name
));
18782 if (actual_class_name
!= NULL
)
18784 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18785 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18792 /* Return true if a DIE with TAG may have the DW_AT_const_value
18796 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18800 case DW_TAG_constant
:
18801 case DW_TAG_enumerator
:
18802 case DW_TAG_formal_parameter
:
18803 case DW_TAG_template_value_param
:
18804 case DW_TAG_variable
:
18812 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18814 /* Once we've fixed up a die, there's no point in doing so again.
18815 This also avoids a memory leak if we were to call
18816 guess_partial_die_structure_name multiple times. */
18820 /* If we found a reference attribute and the DIE has no name, try
18821 to find a name in the referred to DIE. */
18823 if (name
== NULL
&& has_specification
)
18825 struct partial_die_info
*spec_die
;
18827 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18828 spec_die
= res
.pdi
;
18831 spec_die
->fixup (cu
);
18833 if (spec_die
->name
)
18835 name
= spec_die
->name
;
18837 /* Copy DW_AT_external attribute if it is set. */
18838 if (spec_die
->is_external
)
18839 is_external
= spec_die
->is_external
;
18843 if (!has_const_value
&& has_specification
18844 && can_have_DW_AT_const_value_p (tag
))
18846 struct partial_die_info
*spec_die
;
18848 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18849 spec_die
= res
.pdi
;
18852 spec_die
->fixup (cu
);
18854 if (spec_die
->has_const_value
)
18856 /* Copy DW_AT_const_value attribute if it is set. */
18857 has_const_value
= spec_die
->has_const_value
;
18861 /* Set default names for some unnamed DIEs. */
18863 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18864 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18866 /* If there is no parent die to provide a namespace, and there are
18867 children, see if we can determine the namespace from their linkage
18869 if (cu
->language
== language_cplus
18870 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18871 && die_parent
== NULL
18873 && (tag
== DW_TAG_class_type
18874 || tag
== DW_TAG_structure_type
18875 || tag
== DW_TAG_union_type
))
18876 guess_partial_die_structure_name (this, cu
);
18878 /* GCC might emit a nameless struct or union that has a linkage
18879 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18881 && (tag
== DW_TAG_class_type
18882 || tag
== DW_TAG_interface_type
18883 || tag
== DW_TAG_structure_type
18884 || tag
== DW_TAG_union_type
)
18885 && linkage_name
!= NULL
)
18887 gdb::unique_xmalloc_ptr
<char> demangled
18888 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18889 if (demangled
!= nullptr)
18893 /* Strip any leading namespaces/classes, keep only the base name.
18894 DW_AT_name for named DIEs does not contain the prefixes. */
18895 base
= strrchr (demangled
.get (), ':');
18896 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18899 base
= demangled
.get ();
18901 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18902 name
= objfile
->intern (base
);
18909 /* Read the .debug_loclists header contents from the given SECTION in the
18912 read_loclist_header (struct loclist_header
*header
,
18913 struct dwarf2_section_info
*section
)
18915 unsigned int bytes_read
;
18916 bfd
*abfd
= section
->get_bfd_owner ();
18917 const gdb_byte
*info_ptr
= section
->buffer
;
18918 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18919 info_ptr
+= bytes_read
;
18920 header
->version
= read_2_bytes (abfd
, info_ptr
);
18922 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18924 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18926 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18929 /* Return the DW_AT_loclists_base value for the CU. */
18931 lookup_loclist_base (struct dwarf2_cu
*cu
)
18933 /* For the .dwo unit, the loclist_base points to the first offset following
18934 the header. The header consists of the following entities-
18935 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18937 2. version (2 bytes)
18938 3. address size (1 byte)
18939 4. segment selector size (1 byte)
18940 5. offset entry count (4 bytes)
18941 These sizes are derived as per the DWARFv5 standard. */
18942 if (cu
->dwo_unit
!= nullptr)
18944 if (cu
->header
.initial_length_size
== 4)
18945 return LOCLIST_HEADER_SIZE32
;
18946 return LOCLIST_HEADER_SIZE64
;
18948 return cu
->loclist_base
;
18951 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18952 array of offsets in the .debug_loclists section. */
18954 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18956 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18957 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18958 bfd
*abfd
= objfile
->obfd
;
18959 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18960 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18962 section
->read (objfile
);
18963 if (section
->buffer
== NULL
)
18964 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18965 "section [in module %s]"), objfile_name (objfile
));
18966 struct loclist_header header
;
18967 read_loclist_header (&header
, section
);
18968 if (loclist_index
>= header
.offset_entry_count
)
18969 complaint (_("DW_FORM_loclistx pointing outside of "
18970 ".debug_loclists offset array [in module %s]"),
18971 objfile_name (objfile
));
18972 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18974 complaint (_("DW_FORM_loclistx pointing outside of "
18975 ".debug_loclists section [in module %s]"),
18976 objfile_name (objfile
));
18977 const gdb_byte
*info_ptr
18978 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18980 if (cu
->header
.offset_size
== 4)
18981 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18983 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18986 /* Process the attributes that had to be skipped in the first round. These
18987 attributes are the ones that need str_offsets_base or addr_base attributes.
18988 They could not have been processed in the first round, because at the time
18989 the values of str_offsets_base or addr_base may not have been known. */
18991 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18992 struct attribute
*attr
)
18994 struct dwarf2_cu
*cu
= reader
->cu
;
18995 switch (attr
->form
)
18997 case DW_FORM_addrx
:
18998 case DW_FORM_GNU_addr_index
:
18999 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19001 case DW_FORM_loclistx
:
19002 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19005 case DW_FORM_strx1
:
19006 case DW_FORM_strx2
:
19007 case DW_FORM_strx3
:
19008 case DW_FORM_strx4
:
19009 case DW_FORM_GNU_str_index
:
19011 unsigned int str_index
= DW_UNSND (attr
);
19012 if (reader
->dwo_file
!= NULL
)
19014 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19015 DW_STRING_IS_CANONICAL (attr
) = 0;
19019 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19020 DW_STRING_IS_CANONICAL (attr
) = 0;
19025 gdb_assert_not_reached (_("Unexpected DWARF form."));
19029 /* Read an attribute value described by an attribute form. */
19031 static const gdb_byte
*
19032 read_attribute_value (const struct die_reader_specs
*reader
,
19033 struct attribute
*attr
, unsigned form
,
19034 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19035 bool *need_reprocess
)
19037 struct dwarf2_cu
*cu
= reader
->cu
;
19038 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19039 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19040 bfd
*abfd
= reader
->abfd
;
19041 struct comp_unit_head
*cu_header
= &cu
->header
;
19042 unsigned int bytes_read
;
19043 struct dwarf_block
*blk
;
19044 *need_reprocess
= false;
19046 attr
->form
= (enum dwarf_form
) form
;
19049 case DW_FORM_ref_addr
:
19050 if (cu
->header
.version
== 2)
19051 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19054 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19056 info_ptr
+= bytes_read
;
19058 case DW_FORM_GNU_ref_alt
:
19059 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19060 info_ptr
+= bytes_read
;
19064 struct gdbarch
*gdbarch
= objfile
->arch ();
19065 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19066 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19067 info_ptr
+= bytes_read
;
19070 case DW_FORM_block2
:
19071 blk
= dwarf_alloc_block (cu
);
19072 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19074 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19075 info_ptr
+= blk
->size
;
19076 DW_BLOCK (attr
) = blk
;
19078 case DW_FORM_block4
:
19079 blk
= dwarf_alloc_block (cu
);
19080 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19082 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19083 info_ptr
+= blk
->size
;
19084 DW_BLOCK (attr
) = blk
;
19086 case DW_FORM_data2
:
19087 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19090 case DW_FORM_data4
:
19091 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19094 case DW_FORM_data8
:
19095 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19098 case DW_FORM_data16
:
19099 blk
= dwarf_alloc_block (cu
);
19101 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19103 DW_BLOCK (attr
) = blk
;
19105 case DW_FORM_sec_offset
:
19106 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19107 info_ptr
+= bytes_read
;
19109 case DW_FORM_loclistx
:
19111 *need_reprocess
= true;
19112 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19113 info_ptr
+= bytes_read
;
19116 case DW_FORM_string
:
19117 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19118 DW_STRING_IS_CANONICAL (attr
) = 0;
19119 info_ptr
+= bytes_read
;
19122 if (!cu
->per_cu
->is_dwz
)
19124 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19125 abfd
, info_ptr
, cu_header
,
19127 DW_STRING_IS_CANONICAL (attr
) = 0;
19128 info_ptr
+= bytes_read
;
19132 case DW_FORM_line_strp
:
19133 if (!cu
->per_cu
->is_dwz
)
19136 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
19138 DW_STRING_IS_CANONICAL (attr
) = 0;
19139 info_ptr
+= bytes_read
;
19143 case DW_FORM_GNU_strp_alt
:
19145 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19146 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19149 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19150 DW_STRING_IS_CANONICAL (attr
) = 0;
19151 info_ptr
+= bytes_read
;
19154 case DW_FORM_exprloc
:
19155 case DW_FORM_block
:
19156 blk
= dwarf_alloc_block (cu
);
19157 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19158 info_ptr
+= bytes_read
;
19159 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19160 info_ptr
+= blk
->size
;
19161 DW_BLOCK (attr
) = blk
;
19163 case DW_FORM_block1
:
19164 blk
= dwarf_alloc_block (cu
);
19165 blk
->size
= read_1_byte (abfd
, info_ptr
);
19167 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19168 info_ptr
+= blk
->size
;
19169 DW_BLOCK (attr
) = blk
;
19171 case DW_FORM_data1
:
19172 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19176 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19179 case DW_FORM_flag_present
:
19180 DW_UNSND (attr
) = 1;
19182 case DW_FORM_sdata
:
19183 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19184 info_ptr
+= bytes_read
;
19186 case DW_FORM_udata
:
19187 case DW_FORM_rnglistx
:
19188 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19189 info_ptr
+= bytes_read
;
19192 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19193 + read_1_byte (abfd
, info_ptr
));
19197 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19198 + read_2_bytes (abfd
, info_ptr
));
19202 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19203 + read_4_bytes (abfd
, info_ptr
));
19207 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19208 + read_8_bytes (abfd
, info_ptr
));
19211 case DW_FORM_ref_sig8
:
19212 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19215 case DW_FORM_ref_udata
:
19216 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19217 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19218 info_ptr
+= bytes_read
;
19220 case DW_FORM_indirect
:
19221 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19222 info_ptr
+= bytes_read
;
19223 if (form
== DW_FORM_implicit_const
)
19225 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19226 info_ptr
+= bytes_read
;
19228 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19229 info_ptr
, need_reprocess
);
19231 case DW_FORM_implicit_const
:
19232 DW_SND (attr
) = implicit_const
;
19234 case DW_FORM_addrx
:
19235 case DW_FORM_GNU_addr_index
:
19236 *need_reprocess
= true;
19237 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19238 info_ptr
+= bytes_read
;
19241 case DW_FORM_strx1
:
19242 case DW_FORM_strx2
:
19243 case DW_FORM_strx3
:
19244 case DW_FORM_strx4
:
19245 case DW_FORM_GNU_str_index
:
19247 ULONGEST str_index
;
19248 if (form
== DW_FORM_strx1
)
19250 str_index
= read_1_byte (abfd
, info_ptr
);
19253 else if (form
== DW_FORM_strx2
)
19255 str_index
= read_2_bytes (abfd
, info_ptr
);
19258 else if (form
== DW_FORM_strx3
)
19260 str_index
= read_3_bytes (abfd
, info_ptr
);
19263 else if (form
== DW_FORM_strx4
)
19265 str_index
= read_4_bytes (abfd
, info_ptr
);
19270 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19271 info_ptr
+= bytes_read
;
19273 *need_reprocess
= true;
19274 DW_UNSND (attr
) = str_index
;
19278 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19279 dwarf_form_name (form
),
19280 bfd_get_filename (abfd
));
19284 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19285 attr
->form
= DW_FORM_GNU_ref_alt
;
19287 /* We have seen instances where the compiler tried to emit a byte
19288 size attribute of -1 which ended up being encoded as an unsigned
19289 0xffffffff. Although 0xffffffff is technically a valid size value,
19290 an object of this size seems pretty unlikely so we can relatively
19291 safely treat these cases as if the size attribute was invalid and
19292 treat them as zero by default. */
19293 if (attr
->name
== DW_AT_byte_size
19294 && form
== DW_FORM_data4
19295 && DW_UNSND (attr
) >= 0xffffffff)
19298 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19299 hex_string (DW_UNSND (attr
)));
19300 DW_UNSND (attr
) = 0;
19306 /* Read an attribute described by an abbreviated attribute. */
19308 static const gdb_byte
*
19309 read_attribute (const struct die_reader_specs
*reader
,
19310 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19311 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19313 attr
->name
= abbrev
->name
;
19314 return read_attribute_value (reader
, attr
, abbrev
->form
,
19315 abbrev
->implicit_const
, info_ptr
,
19319 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19321 static const char *
19322 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19323 LONGEST str_offset
)
19325 return dwarf2_per_objfile
->per_bfd
->str
.read_string
19326 (dwarf2_per_objfile
->objfile
, str_offset
, "DW_FORM_strp");
19329 /* Return pointer to string at .debug_str offset as read from BUF.
19330 BUF is assumed to be in a compilation unit described by CU_HEADER.
19331 Return *BYTES_READ_PTR count of bytes read from BUF. */
19333 static const char *
19334 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19335 const gdb_byte
*buf
,
19336 const struct comp_unit_head
*cu_header
,
19337 unsigned int *bytes_read_ptr
)
19339 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19341 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
19347 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19348 const struct comp_unit_head
*cu_header
,
19349 unsigned int *bytes_read_ptr
)
19351 bfd
*abfd
= objfile
->obfd
;
19352 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19354 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19357 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19358 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19359 ADDR_SIZE is the size of addresses from the CU header. */
19362 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19363 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19366 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19367 bfd
*abfd
= objfile
->obfd
;
19368 const gdb_byte
*info_ptr
;
19369 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19371 dwarf2_per_objfile
->per_bfd
->addr
.read (objfile
);
19372 if (dwarf2_per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19373 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19374 objfile_name (objfile
));
19375 if (addr_base_or_zero
+ addr_index
* addr_size
19376 >= dwarf2_per_objfile
->per_bfd
->addr
.size
)
19377 error (_("DW_FORM_addr_index pointing outside of "
19378 ".debug_addr section [in module %s]"),
19379 objfile_name (objfile
));
19380 info_ptr
= (dwarf2_per_objfile
->per_bfd
->addr
.buffer
19381 + addr_base_or_zero
+ addr_index
* addr_size
);
19382 if (addr_size
== 4)
19383 return bfd_get_32 (abfd
, info_ptr
);
19385 return bfd_get_64 (abfd
, info_ptr
);
19388 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19391 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19393 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19394 cu
->addr_base
, cu
->header
.addr_size
);
19397 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19400 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19401 unsigned int *bytes_read
)
19403 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19404 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19406 return read_addr_index (cu
, addr_index
);
19412 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19413 dwarf2_per_objfile
*dwarf2_per_objfile
,
19414 unsigned int addr_index
)
19416 struct dwarf2_cu
*cu
= per_cu
->cu
;
19417 gdb::optional
<ULONGEST
> addr_base
;
19420 /* We need addr_base and addr_size.
19421 If we don't have PER_CU->cu, we have to get it.
19422 Nasty, but the alternative is storing the needed info in PER_CU,
19423 which at this point doesn't seem justified: it's not clear how frequently
19424 it would get used and it would increase the size of every PER_CU.
19425 Entry points like dwarf2_per_cu_addr_size do a similar thing
19426 so we're not in uncharted territory here.
19427 Alas we need to be a bit more complicated as addr_base is contained
19430 We don't need to read the entire CU(/TU).
19431 We just need the header and top level die.
19433 IWBN to use the aging mechanism to let us lazily later discard the CU.
19434 For now we skip this optimization. */
19438 addr_base
= cu
->addr_base
;
19439 addr_size
= cu
->header
.addr_size
;
19443 cutu_reader
reader (per_cu
, dwarf2_per_objfile
, NULL
, 0, false);
19444 addr_base
= reader
.cu
->addr_base
;
19445 addr_size
= reader
.cu
->header
.addr_size
;
19448 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19452 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19453 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19456 static const char *
19457 read_str_index (struct dwarf2_cu
*cu
,
19458 struct dwarf2_section_info
*str_section
,
19459 struct dwarf2_section_info
*str_offsets_section
,
19460 ULONGEST str_offsets_base
, ULONGEST str_index
)
19462 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19463 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19464 const char *objf_name
= objfile_name (objfile
);
19465 bfd
*abfd
= objfile
->obfd
;
19466 const gdb_byte
*info_ptr
;
19467 ULONGEST str_offset
;
19468 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19470 str_section
->read (objfile
);
19471 str_offsets_section
->read (objfile
);
19472 if (str_section
->buffer
== NULL
)
19473 error (_("%s used without %s section"
19474 " in CU at offset %s [in module %s]"),
19475 form_name
, str_section
->get_name (),
19476 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19477 if (str_offsets_section
->buffer
== NULL
)
19478 error (_("%s used without %s section"
19479 " in CU at offset %s [in module %s]"),
19480 form_name
, str_section
->get_name (),
19481 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19482 info_ptr
= (str_offsets_section
->buffer
19484 + str_index
* cu
->header
.offset_size
);
19485 if (cu
->header
.offset_size
== 4)
19486 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19488 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19489 if (str_offset
>= str_section
->size
)
19490 error (_("Offset from %s pointing outside of"
19491 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19492 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19493 return (const char *) (str_section
->buffer
+ str_offset
);
19496 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19498 static const char *
19499 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19501 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19502 ? reader
->cu
->header
.addr_size
: 0;
19503 return read_str_index (reader
->cu
,
19504 &reader
->dwo_file
->sections
.str
,
19505 &reader
->dwo_file
->sections
.str_offsets
,
19506 str_offsets_base
, str_index
);
19509 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19511 static const char *
19512 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19514 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19515 const char *objf_name
= objfile_name (objfile
);
19516 static const char form_name
[] = "DW_FORM_GNU_str_index";
19517 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19519 if (!cu
->str_offsets_base
.has_value ())
19520 error (_("%s used in Fission stub without %s"
19521 " in CU at offset 0x%lx [in module %s]"),
19522 form_name
, str_offsets_attr_name
,
19523 (long) cu
->header
.offset_size
, objf_name
);
19525 return read_str_index (cu
,
19526 &cu
->per_objfile
->per_bfd
->str
,
19527 &cu
->per_objfile
->per_bfd
->str_offsets
,
19528 *cu
->str_offsets_base
, str_index
);
19531 /* Return the length of an LEB128 number in BUF. */
19534 leb128_size (const gdb_byte
*buf
)
19536 const gdb_byte
*begin
= buf
;
19542 if ((byte
& 128) == 0)
19543 return buf
- begin
;
19548 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19557 cu
->language
= language_c
;
19560 case DW_LANG_C_plus_plus
:
19561 case DW_LANG_C_plus_plus_11
:
19562 case DW_LANG_C_plus_plus_14
:
19563 cu
->language
= language_cplus
;
19566 cu
->language
= language_d
;
19568 case DW_LANG_Fortran77
:
19569 case DW_LANG_Fortran90
:
19570 case DW_LANG_Fortran95
:
19571 case DW_LANG_Fortran03
:
19572 case DW_LANG_Fortran08
:
19573 cu
->language
= language_fortran
;
19576 cu
->language
= language_go
;
19578 case DW_LANG_Mips_Assembler
:
19579 cu
->language
= language_asm
;
19581 case DW_LANG_Ada83
:
19582 case DW_LANG_Ada95
:
19583 cu
->language
= language_ada
;
19585 case DW_LANG_Modula2
:
19586 cu
->language
= language_m2
;
19588 case DW_LANG_Pascal83
:
19589 cu
->language
= language_pascal
;
19592 cu
->language
= language_objc
;
19595 case DW_LANG_Rust_old
:
19596 cu
->language
= language_rust
;
19598 case DW_LANG_Cobol74
:
19599 case DW_LANG_Cobol85
:
19601 cu
->language
= language_minimal
;
19604 cu
->language_defn
= language_def (cu
->language
);
19607 /* Return the named attribute or NULL if not there. */
19609 static struct attribute
*
19610 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19615 struct attribute
*spec
= NULL
;
19617 for (i
= 0; i
< die
->num_attrs
; ++i
)
19619 if (die
->attrs
[i
].name
== name
)
19620 return &die
->attrs
[i
];
19621 if (die
->attrs
[i
].name
== DW_AT_specification
19622 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19623 spec
= &die
->attrs
[i
];
19629 die
= follow_die_ref (die
, spec
, &cu
);
19635 /* Return the string associated with a string-typed attribute, or NULL if it
19636 is either not found or is of an incorrect type. */
19638 static const char *
19639 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19641 struct attribute
*attr
;
19642 const char *str
= NULL
;
19644 attr
= dwarf2_attr (die
, name
, cu
);
19648 str
= attr
->value_as_string ();
19649 if (str
== nullptr)
19650 complaint (_("string type expected for attribute %s for "
19651 "DIE at %s in module %s"),
19652 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19653 objfile_name (cu
->per_objfile
->objfile
));
19659 /* Return the dwo name or NULL if not present. If present, it is in either
19660 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19661 static const char *
19662 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19664 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19665 if (dwo_name
== nullptr)
19666 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19670 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19671 and holds a non-zero value. This function should only be used for
19672 DW_FORM_flag or DW_FORM_flag_present attributes. */
19675 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19677 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19679 return (attr
&& DW_UNSND (attr
));
19683 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19685 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19686 which value is non-zero. However, we have to be careful with
19687 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19688 (via dwarf2_flag_true_p) follows this attribute. So we may
19689 end up accidently finding a declaration attribute that belongs
19690 to a different DIE referenced by the specification attribute,
19691 even though the given DIE does not have a declaration attribute. */
19692 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19693 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19696 /* Return the die giving the specification for DIE, if there is
19697 one. *SPEC_CU is the CU containing DIE on input, and the CU
19698 containing the return value on output. If there is no
19699 specification, but there is an abstract origin, that is
19702 static struct die_info
*
19703 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19705 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19708 if (spec_attr
== NULL
)
19709 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19711 if (spec_attr
== NULL
)
19714 return follow_die_ref (die
, spec_attr
, spec_cu
);
19717 /* Stub for free_line_header to match void * callback types. */
19720 free_line_header_voidp (void *arg
)
19722 struct line_header
*lh
= (struct line_header
*) arg
;
19727 /* A convenience function to find the proper .debug_line section for a CU. */
19729 static struct dwarf2_section_info
*
19730 get_debug_line_section (struct dwarf2_cu
*cu
)
19732 struct dwarf2_section_info
*section
;
19733 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19735 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19737 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19738 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19739 else if (cu
->per_cu
->is_dwz
)
19741 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19743 section
= &dwz
->line
;
19746 section
= &dwarf2_per_objfile
->per_bfd
->line
;
19751 /* Read the statement program header starting at OFFSET in
19752 .debug_line, or .debug_line.dwo. Return a pointer
19753 to a struct line_header, allocated using xmalloc.
19754 Returns NULL if there is a problem reading the header, e.g., if it
19755 has a version we don't understand.
19757 NOTE: the strings in the include directory and file name tables of
19758 the returned object point into the dwarf line section buffer,
19759 and must not be freed. */
19761 static line_header_up
19762 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19764 struct dwarf2_section_info
*section
;
19765 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19767 section
= get_debug_line_section (cu
);
19768 section
->read (dwarf2_per_objfile
->objfile
);
19769 if (section
->buffer
== NULL
)
19771 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19772 complaint (_("missing .debug_line.dwo section"));
19774 complaint (_("missing .debug_line section"));
19778 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19779 dwarf2_per_objfile
, section
,
19783 /* Subroutine of dwarf_decode_lines to simplify it.
19784 Return the file name of the psymtab for the given file_entry.
19785 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19786 If space for the result is malloc'd, *NAME_HOLDER will be set.
19787 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19789 static const char *
19790 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19791 const dwarf2_psymtab
*pst
,
19792 const char *comp_dir
,
19793 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19795 const char *include_name
= fe
.name
;
19796 const char *include_name_to_compare
= include_name
;
19797 const char *pst_filename
;
19800 const char *dir_name
= fe
.include_dir (lh
);
19802 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19803 if (!IS_ABSOLUTE_PATH (include_name
)
19804 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19806 /* Avoid creating a duplicate psymtab for PST.
19807 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19808 Before we do the comparison, however, we need to account
19809 for DIR_NAME and COMP_DIR.
19810 First prepend dir_name (if non-NULL). If we still don't
19811 have an absolute path prepend comp_dir (if non-NULL).
19812 However, the directory we record in the include-file's
19813 psymtab does not contain COMP_DIR (to match the
19814 corresponding symtab(s)).
19819 bash$ gcc -g ./hello.c
19820 include_name = "hello.c"
19822 DW_AT_comp_dir = comp_dir = "/tmp"
19823 DW_AT_name = "./hello.c"
19827 if (dir_name
!= NULL
)
19829 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19830 include_name
, (char *) NULL
));
19831 include_name
= name_holder
->get ();
19832 include_name_to_compare
= include_name
;
19834 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19836 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19837 include_name
, (char *) NULL
));
19838 include_name_to_compare
= hold_compare
.get ();
19842 pst_filename
= pst
->filename
;
19843 gdb::unique_xmalloc_ptr
<char> copied_name
;
19844 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19846 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19847 pst_filename
, (char *) NULL
));
19848 pst_filename
= copied_name
.get ();
19851 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19855 return include_name
;
19858 /* State machine to track the state of the line number program. */
19860 class lnp_state_machine
19863 /* Initialize a machine state for the start of a line number
19865 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19866 bool record_lines_p
);
19868 file_entry
*current_file ()
19870 /* lh->file_names is 0-based, but the file name numbers in the
19871 statement program are 1-based. */
19872 return m_line_header
->file_name_at (m_file
);
19875 /* Record the line in the state machine. END_SEQUENCE is true if
19876 we're processing the end of a sequence. */
19877 void record_line (bool end_sequence
);
19879 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19880 nop-out rest of the lines in this sequence. */
19881 void check_line_address (struct dwarf2_cu
*cu
,
19882 const gdb_byte
*line_ptr
,
19883 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19885 void handle_set_discriminator (unsigned int discriminator
)
19887 m_discriminator
= discriminator
;
19888 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19891 /* Handle DW_LNE_set_address. */
19892 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19895 address
+= baseaddr
;
19896 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19899 /* Handle DW_LNS_advance_pc. */
19900 void handle_advance_pc (CORE_ADDR adjust
);
19902 /* Handle a special opcode. */
19903 void handle_special_opcode (unsigned char op_code
);
19905 /* Handle DW_LNS_advance_line. */
19906 void handle_advance_line (int line_delta
)
19908 advance_line (line_delta
);
19911 /* Handle DW_LNS_set_file. */
19912 void handle_set_file (file_name_index file
);
19914 /* Handle DW_LNS_negate_stmt. */
19915 void handle_negate_stmt ()
19917 m_is_stmt
= !m_is_stmt
;
19920 /* Handle DW_LNS_const_add_pc. */
19921 void handle_const_add_pc ();
19923 /* Handle DW_LNS_fixed_advance_pc. */
19924 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19926 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19930 /* Handle DW_LNS_copy. */
19931 void handle_copy ()
19933 record_line (false);
19934 m_discriminator
= 0;
19937 /* Handle DW_LNE_end_sequence. */
19938 void handle_end_sequence ()
19940 m_currently_recording_lines
= true;
19944 /* Advance the line by LINE_DELTA. */
19945 void advance_line (int line_delta
)
19947 m_line
+= line_delta
;
19949 if (line_delta
!= 0)
19950 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19953 struct dwarf2_cu
*m_cu
;
19955 gdbarch
*m_gdbarch
;
19957 /* True if we're recording lines.
19958 Otherwise we're building partial symtabs and are just interested in
19959 finding include files mentioned by the line number program. */
19960 bool m_record_lines_p
;
19962 /* The line number header. */
19963 line_header
*m_line_header
;
19965 /* These are part of the standard DWARF line number state machine,
19966 and initialized according to the DWARF spec. */
19968 unsigned char m_op_index
= 0;
19969 /* The line table index of the current file. */
19970 file_name_index m_file
= 1;
19971 unsigned int m_line
= 1;
19973 /* These are initialized in the constructor. */
19975 CORE_ADDR m_address
;
19977 unsigned int m_discriminator
;
19979 /* Additional bits of state we need to track. */
19981 /* The last file that we called dwarf2_start_subfile for.
19982 This is only used for TLLs. */
19983 unsigned int m_last_file
= 0;
19984 /* The last file a line number was recorded for. */
19985 struct subfile
*m_last_subfile
= NULL
;
19987 /* When true, record the lines we decode. */
19988 bool m_currently_recording_lines
= false;
19990 /* The last line number that was recorded, used to coalesce
19991 consecutive entries for the same line. This can happen, for
19992 example, when discriminators are present. PR 17276. */
19993 unsigned int m_last_line
= 0;
19994 bool m_line_has_non_zero_discriminator
= false;
19998 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20000 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20001 / m_line_header
->maximum_ops_per_instruction
)
20002 * m_line_header
->minimum_instruction_length
);
20003 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20004 m_op_index
= ((m_op_index
+ adjust
)
20005 % m_line_header
->maximum_ops_per_instruction
);
20009 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20011 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20012 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20013 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20014 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20015 / m_line_header
->maximum_ops_per_instruction
)
20016 * m_line_header
->minimum_instruction_length
);
20017 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20018 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20019 % m_line_header
->maximum_ops_per_instruction
);
20021 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20022 advance_line (line_delta
);
20023 record_line (false);
20024 m_discriminator
= 0;
20028 lnp_state_machine::handle_set_file (file_name_index file
)
20032 const file_entry
*fe
= current_file ();
20034 dwarf2_debug_line_missing_file_complaint ();
20035 else if (m_record_lines_p
)
20037 const char *dir
= fe
->include_dir (m_line_header
);
20039 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20040 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20041 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20046 lnp_state_machine::handle_const_add_pc ()
20049 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20052 = (((m_op_index
+ adjust
)
20053 / m_line_header
->maximum_ops_per_instruction
)
20054 * m_line_header
->minimum_instruction_length
);
20056 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20057 m_op_index
= ((m_op_index
+ adjust
)
20058 % m_line_header
->maximum_ops_per_instruction
);
20061 /* Return non-zero if we should add LINE to the line number table.
20062 LINE is the line to add, LAST_LINE is the last line that was added,
20063 LAST_SUBFILE is the subfile for LAST_LINE.
20064 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20065 had a non-zero discriminator.
20067 We have to be careful in the presence of discriminators.
20068 E.g., for this line:
20070 for (i = 0; i < 100000; i++);
20072 clang can emit four line number entries for that one line,
20073 each with a different discriminator.
20074 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20076 However, we want gdb to coalesce all four entries into one.
20077 Otherwise the user could stepi into the middle of the line and
20078 gdb would get confused about whether the pc really was in the
20079 middle of the line.
20081 Things are further complicated by the fact that two consecutive
20082 line number entries for the same line is a heuristic used by gcc
20083 to denote the end of the prologue. So we can't just discard duplicate
20084 entries, we have to be selective about it. The heuristic we use is
20085 that we only collapse consecutive entries for the same line if at least
20086 one of those entries has a non-zero discriminator. PR 17276.
20088 Note: Addresses in the line number state machine can never go backwards
20089 within one sequence, thus this coalescing is ok. */
20092 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20093 unsigned int line
, unsigned int last_line
,
20094 int line_has_non_zero_discriminator
,
20095 struct subfile
*last_subfile
)
20097 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20099 if (line
!= last_line
)
20101 /* Same line for the same file that we've seen already.
20102 As a last check, for pr 17276, only record the line if the line
20103 has never had a non-zero discriminator. */
20104 if (!line_has_non_zero_discriminator
)
20109 /* Use the CU's builder to record line number LINE beginning at
20110 address ADDRESS in the line table of subfile SUBFILE. */
20113 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20114 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20115 struct dwarf2_cu
*cu
)
20117 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20119 if (dwarf_line_debug
)
20121 fprintf_unfiltered (gdb_stdlog
,
20122 "Recording line %u, file %s, address %s\n",
20123 line
, lbasename (subfile
->name
),
20124 paddress (gdbarch
, address
));
20128 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20131 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20132 Mark the end of a set of line number records.
20133 The arguments are the same as for dwarf_record_line_1.
20134 If SUBFILE is NULL the request is ignored. */
20137 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20138 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20140 if (subfile
== NULL
)
20143 if (dwarf_line_debug
)
20145 fprintf_unfiltered (gdb_stdlog
,
20146 "Finishing current line, file %s, address %s\n",
20147 lbasename (subfile
->name
),
20148 paddress (gdbarch
, address
));
20151 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20155 lnp_state_machine::record_line (bool end_sequence
)
20157 if (dwarf_line_debug
)
20159 fprintf_unfiltered (gdb_stdlog
,
20160 "Processing actual line %u: file %u,"
20161 " address %s, is_stmt %u, discrim %u%s\n",
20163 paddress (m_gdbarch
, m_address
),
20164 m_is_stmt
, m_discriminator
,
20165 (end_sequence
? "\t(end sequence)" : ""));
20168 file_entry
*fe
= current_file ();
20171 dwarf2_debug_line_missing_file_complaint ();
20172 /* For now we ignore lines not starting on an instruction boundary.
20173 But not when processing end_sequence for compatibility with the
20174 previous version of the code. */
20175 else if (m_op_index
== 0 || end_sequence
)
20177 fe
->included_p
= 1;
20178 if (m_record_lines_p
)
20180 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20183 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20184 m_currently_recording_lines
? m_cu
: nullptr);
20189 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20191 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20192 m_line_has_non_zero_discriminator
,
20195 buildsym_compunit
*builder
= m_cu
->get_builder ();
20196 dwarf_record_line_1 (m_gdbarch
,
20197 builder
->get_current_subfile (),
20198 m_line
, m_address
, is_stmt
,
20199 m_currently_recording_lines
? m_cu
: nullptr);
20201 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20202 m_last_line
= m_line
;
20208 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20209 line_header
*lh
, bool record_lines_p
)
20213 m_record_lines_p
= record_lines_p
;
20214 m_line_header
= lh
;
20216 m_currently_recording_lines
= true;
20218 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20219 was a line entry for it so that the backend has a chance to adjust it
20220 and also record it in case it needs it. This is currently used by MIPS
20221 code, cf. `mips_adjust_dwarf2_line'. */
20222 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20223 m_is_stmt
= lh
->default_is_stmt
;
20224 m_discriminator
= 0;
20228 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20229 const gdb_byte
*line_ptr
,
20230 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20232 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20233 the pc range of the CU. However, we restrict the test to only ADDRESS
20234 values of zero to preserve GDB's previous behaviour which is to handle
20235 the specific case of a function being GC'd by the linker. */
20237 if (address
== 0 && address
< unrelocated_lowpc
)
20239 /* This line table is for a function which has been
20240 GCd by the linker. Ignore it. PR gdb/12528 */
20242 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20243 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20245 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20246 line_offset
, objfile_name (objfile
));
20247 m_currently_recording_lines
= false;
20248 /* Note: m_currently_recording_lines is left as false until we see
20249 DW_LNE_end_sequence. */
20253 /* Subroutine of dwarf_decode_lines to simplify it.
20254 Process the line number information in LH.
20255 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20256 program in order to set included_p for every referenced header. */
20259 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20260 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20262 const gdb_byte
*line_ptr
, *extended_end
;
20263 const gdb_byte
*line_end
;
20264 unsigned int bytes_read
, extended_len
;
20265 unsigned char op_code
, extended_op
;
20266 CORE_ADDR baseaddr
;
20267 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20268 bfd
*abfd
= objfile
->obfd
;
20269 struct gdbarch
*gdbarch
= objfile
->arch ();
20270 /* True if we're recording line info (as opposed to building partial
20271 symtabs and just interested in finding include files mentioned by
20272 the line number program). */
20273 bool record_lines_p
= !decode_for_pst_p
;
20275 baseaddr
= objfile
->text_section_offset ();
20277 line_ptr
= lh
->statement_program_start
;
20278 line_end
= lh
->statement_program_end
;
20280 /* Read the statement sequences until there's nothing left. */
20281 while (line_ptr
< line_end
)
20283 /* The DWARF line number program state machine. Reset the state
20284 machine at the start of each sequence. */
20285 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20286 bool end_sequence
= false;
20288 if (record_lines_p
)
20290 /* Start a subfile for the current file of the state
20292 const file_entry
*fe
= state_machine
.current_file ();
20295 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20298 /* Decode the table. */
20299 while (line_ptr
< line_end
&& !end_sequence
)
20301 op_code
= read_1_byte (abfd
, line_ptr
);
20304 if (op_code
>= lh
->opcode_base
)
20306 /* Special opcode. */
20307 state_machine
.handle_special_opcode (op_code
);
20309 else switch (op_code
)
20311 case DW_LNS_extended_op
:
20312 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20314 line_ptr
+= bytes_read
;
20315 extended_end
= line_ptr
+ extended_len
;
20316 extended_op
= read_1_byte (abfd
, line_ptr
);
20318 switch (extended_op
)
20320 case DW_LNE_end_sequence
:
20321 state_machine
.handle_end_sequence ();
20322 end_sequence
= true;
20324 case DW_LNE_set_address
:
20327 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20328 line_ptr
+= bytes_read
;
20330 state_machine
.check_line_address (cu
, line_ptr
,
20331 lowpc
- baseaddr
, address
);
20332 state_machine
.handle_set_address (baseaddr
, address
);
20335 case DW_LNE_define_file
:
20337 const char *cur_file
;
20338 unsigned int mod_time
, length
;
20341 cur_file
= read_direct_string (abfd
, line_ptr
,
20343 line_ptr
+= bytes_read
;
20344 dindex
= (dir_index
)
20345 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20346 line_ptr
+= bytes_read
;
20348 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20349 line_ptr
+= bytes_read
;
20351 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20352 line_ptr
+= bytes_read
;
20353 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20356 case DW_LNE_set_discriminator
:
20358 /* The discriminator is not interesting to the
20359 debugger; just ignore it. We still need to
20360 check its value though:
20361 if there are consecutive entries for the same
20362 (non-prologue) line we want to coalesce them.
20365 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20366 line_ptr
+= bytes_read
;
20368 state_machine
.handle_set_discriminator (discr
);
20372 complaint (_("mangled .debug_line section"));
20375 /* Make sure that we parsed the extended op correctly. If e.g.
20376 we expected a different address size than the producer used,
20377 we may have read the wrong number of bytes. */
20378 if (line_ptr
!= extended_end
)
20380 complaint (_("mangled .debug_line section"));
20385 state_machine
.handle_copy ();
20387 case DW_LNS_advance_pc
:
20390 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20391 line_ptr
+= bytes_read
;
20393 state_machine
.handle_advance_pc (adjust
);
20396 case DW_LNS_advance_line
:
20399 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20400 line_ptr
+= bytes_read
;
20402 state_machine
.handle_advance_line (line_delta
);
20405 case DW_LNS_set_file
:
20407 file_name_index file
20408 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20410 line_ptr
+= bytes_read
;
20412 state_machine
.handle_set_file (file
);
20415 case DW_LNS_set_column
:
20416 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20417 line_ptr
+= bytes_read
;
20419 case DW_LNS_negate_stmt
:
20420 state_machine
.handle_negate_stmt ();
20422 case DW_LNS_set_basic_block
:
20424 /* Add to the address register of the state machine the
20425 address increment value corresponding to special opcode
20426 255. I.e., this value is scaled by the minimum
20427 instruction length since special opcode 255 would have
20428 scaled the increment. */
20429 case DW_LNS_const_add_pc
:
20430 state_machine
.handle_const_add_pc ();
20432 case DW_LNS_fixed_advance_pc
:
20434 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20437 state_machine
.handle_fixed_advance_pc (addr_adj
);
20442 /* Unknown standard opcode, ignore it. */
20445 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20447 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20448 line_ptr
+= bytes_read
;
20455 dwarf2_debug_line_missing_end_sequence_complaint ();
20457 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20458 in which case we still finish recording the last line). */
20459 state_machine
.record_line (true);
20463 /* Decode the Line Number Program (LNP) for the given line_header
20464 structure and CU. The actual information extracted and the type
20465 of structures created from the LNP depends on the value of PST.
20467 1. If PST is NULL, then this procedure uses the data from the program
20468 to create all necessary symbol tables, and their linetables.
20470 2. If PST is not NULL, this procedure reads the program to determine
20471 the list of files included by the unit represented by PST, and
20472 builds all the associated partial symbol tables.
20474 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20475 It is used for relative paths in the line table.
20476 NOTE: When processing partial symtabs (pst != NULL),
20477 comp_dir == pst->dirname.
20479 NOTE: It is important that psymtabs have the same file name (via strcmp)
20480 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20481 symtab we don't use it in the name of the psymtabs we create.
20482 E.g. expand_line_sal requires this when finding psymtabs to expand.
20483 A good testcase for this is mb-inline.exp.
20485 LOWPC is the lowest address in CU (or 0 if not known).
20487 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20488 for its PC<->lines mapping information. Otherwise only the filename
20489 table is read in. */
20492 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20493 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20494 CORE_ADDR lowpc
, int decode_mapping
)
20496 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20497 const int decode_for_pst_p
= (pst
!= NULL
);
20499 if (decode_mapping
)
20500 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20502 if (decode_for_pst_p
)
20504 /* Now that we're done scanning the Line Header Program, we can
20505 create the psymtab of each included file. */
20506 for (auto &file_entry
: lh
->file_names ())
20507 if (file_entry
.included_p
== 1)
20509 gdb::unique_xmalloc_ptr
<char> name_holder
;
20510 const char *include_name
=
20511 psymtab_include_file_name (lh
, file_entry
, pst
,
20512 comp_dir
, &name_holder
);
20513 if (include_name
!= NULL
)
20514 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20519 /* Make sure a symtab is created for every file, even files
20520 which contain only variables (i.e. no code with associated
20522 buildsym_compunit
*builder
= cu
->get_builder ();
20523 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20525 for (auto &fe
: lh
->file_names ())
20527 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20528 if (builder
->get_current_subfile ()->symtab
== NULL
)
20530 builder
->get_current_subfile ()->symtab
20531 = allocate_symtab (cust
,
20532 builder
->get_current_subfile ()->name
);
20534 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20539 /* Start a subfile for DWARF. FILENAME is the name of the file and
20540 DIRNAME the name of the source directory which contains FILENAME
20541 or NULL if not known.
20542 This routine tries to keep line numbers from identical absolute and
20543 relative file names in a common subfile.
20545 Using the `list' example from the GDB testsuite, which resides in
20546 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20547 of /srcdir/list0.c yields the following debugging information for list0.c:
20549 DW_AT_name: /srcdir/list0.c
20550 DW_AT_comp_dir: /compdir
20551 files.files[0].name: list0.h
20552 files.files[0].dir: /srcdir
20553 files.files[1].name: list0.c
20554 files.files[1].dir: /srcdir
20556 The line number information for list0.c has to end up in a single
20557 subfile, so that `break /srcdir/list0.c:1' works as expected.
20558 start_subfile will ensure that this happens provided that we pass the
20559 concatenation of files.files[1].dir and files.files[1].name as the
20563 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20564 const char *dirname
)
20566 gdb::unique_xmalloc_ptr
<char> copy
;
20568 /* In order not to lose the line information directory,
20569 we concatenate it to the filename when it makes sense.
20570 Note that the Dwarf3 standard says (speaking of filenames in line
20571 information): ``The directory index is ignored for file names
20572 that represent full path names''. Thus ignoring dirname in the
20573 `else' branch below isn't an issue. */
20575 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20577 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20578 filename
= copy
.get ();
20581 cu
->get_builder ()->start_subfile (filename
);
20584 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20585 buildsym_compunit constructor. */
20587 struct compunit_symtab
*
20588 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20591 gdb_assert (m_builder
== nullptr);
20593 m_builder
.reset (new struct buildsym_compunit
20594 (this->per_objfile
->objfile
,
20595 name
, comp_dir
, language
, low_pc
));
20597 list_in_scope
= get_builder ()->get_file_symbols ();
20599 get_builder ()->record_debugformat ("DWARF 2");
20600 get_builder ()->record_producer (producer
);
20602 processing_has_namespace_info
= false;
20604 return get_builder ()->get_compunit_symtab ();
20608 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20609 struct dwarf2_cu
*cu
)
20611 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20612 struct comp_unit_head
*cu_header
= &cu
->header
;
20614 /* NOTE drow/2003-01-30: There used to be a comment and some special
20615 code here to turn a symbol with DW_AT_external and a
20616 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20617 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20618 with some versions of binutils) where shared libraries could have
20619 relocations against symbols in their debug information - the
20620 minimal symbol would have the right address, but the debug info
20621 would not. It's no longer necessary, because we will explicitly
20622 apply relocations when we read in the debug information now. */
20624 /* A DW_AT_location attribute with no contents indicates that a
20625 variable has been optimized away. */
20626 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20628 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20632 /* Handle one degenerate form of location expression specially, to
20633 preserve GDB's previous behavior when section offsets are
20634 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20635 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20637 if (attr
->form_is_block ()
20638 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20639 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20640 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20641 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20642 && (DW_BLOCK (attr
)->size
20643 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20645 unsigned int dummy
;
20647 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20648 SET_SYMBOL_VALUE_ADDRESS
20649 (sym
, cu
->header
.read_address (objfile
->obfd
,
20650 DW_BLOCK (attr
)->data
+ 1,
20653 SET_SYMBOL_VALUE_ADDRESS
20654 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20656 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20657 fixup_symbol_section (sym
, objfile
);
20658 SET_SYMBOL_VALUE_ADDRESS
20660 SYMBOL_VALUE_ADDRESS (sym
)
20661 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20665 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20666 expression evaluator, and use LOC_COMPUTED only when necessary
20667 (i.e. when the value of a register or memory location is
20668 referenced, or a thread-local block, etc.). Then again, it might
20669 not be worthwhile. I'm assuming that it isn't unless performance
20670 or memory numbers show me otherwise. */
20672 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20674 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20675 cu
->has_loclist
= true;
20678 /* Given a pointer to a DWARF information entry, figure out if we need
20679 to make a symbol table entry for it, and if so, create a new entry
20680 and return a pointer to it.
20681 If TYPE is NULL, determine symbol type from the die, otherwise
20682 used the passed type.
20683 If SPACE is not NULL, use it to hold the new symbol. If it is
20684 NULL, allocate a new symbol on the objfile's obstack. */
20686 static struct symbol
*
20687 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20688 struct symbol
*space
)
20690 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20691 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20692 struct gdbarch
*gdbarch
= objfile
->arch ();
20693 struct symbol
*sym
= NULL
;
20695 struct attribute
*attr
= NULL
;
20696 struct attribute
*attr2
= NULL
;
20697 CORE_ADDR baseaddr
;
20698 struct pending
**list_to_add
= NULL
;
20700 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20702 baseaddr
= objfile
->text_section_offset ();
20704 name
= dwarf2_name (die
, cu
);
20707 int suppress_add
= 0;
20712 sym
= new (&objfile
->objfile_obstack
) symbol
;
20713 OBJSTAT (objfile
, n_syms
++);
20715 /* Cache this symbol's name and the name's demangled form (if any). */
20716 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20717 /* Fortran does not have mangling standard and the mangling does differ
20718 between gfortran, iFort etc. */
20719 const char *physname
20720 = (cu
->language
== language_fortran
20721 ? dwarf2_full_name (name
, die
, cu
)
20722 : dwarf2_physname (name
, die
, cu
));
20723 const char *linkagename
= dw2_linkage_name (die
, cu
);
20725 if (linkagename
== nullptr || cu
->language
== language_ada
)
20726 sym
->set_linkage_name (physname
);
20729 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20730 sym
->set_linkage_name (linkagename
);
20733 /* Default assumptions.
20734 Use the passed type or decode it from the die. */
20735 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20736 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20738 SYMBOL_TYPE (sym
) = type
;
20740 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20741 attr
= dwarf2_attr (die
,
20742 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20744 if (attr
!= nullptr)
20746 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20749 attr
= dwarf2_attr (die
,
20750 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20752 if (attr
!= nullptr)
20754 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20755 struct file_entry
*fe
;
20757 if (cu
->line_header
!= NULL
)
20758 fe
= cu
->line_header
->file_name_at (file_index
);
20763 complaint (_("file index out of range"));
20765 symbol_set_symtab (sym
, fe
->symtab
);
20771 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20772 if (attr
!= nullptr)
20776 addr
= attr
->value_as_address ();
20777 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20778 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20780 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20781 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20782 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20783 add_symbol_to_list (sym
, cu
->list_in_scope
);
20785 case DW_TAG_subprogram
:
20786 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20788 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20789 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20790 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20791 || cu
->language
== language_ada
20792 || cu
->language
== language_fortran
)
20794 /* Subprograms marked external are stored as a global symbol.
20795 Ada and Fortran subprograms, whether marked external or
20796 not, are always stored as a global symbol, because we want
20797 to be able to access them globally. For instance, we want
20798 to be able to break on a nested subprogram without having
20799 to specify the context. */
20800 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20804 list_to_add
= cu
->list_in_scope
;
20807 case DW_TAG_inlined_subroutine
:
20808 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20810 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20811 SYMBOL_INLINED (sym
) = 1;
20812 list_to_add
= cu
->list_in_scope
;
20814 case DW_TAG_template_value_param
:
20816 /* Fall through. */
20817 case DW_TAG_constant
:
20818 case DW_TAG_variable
:
20819 case DW_TAG_member
:
20820 /* Compilation with minimal debug info may result in
20821 variables with missing type entries. Change the
20822 misleading `void' type to something sensible. */
20823 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20824 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20826 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20827 /* In the case of DW_TAG_member, we should only be called for
20828 static const members. */
20829 if (die
->tag
== DW_TAG_member
)
20831 /* dwarf2_add_field uses die_is_declaration,
20832 so we do the same. */
20833 gdb_assert (die_is_declaration (die
, cu
));
20836 if (attr
!= nullptr)
20838 dwarf2_const_value (attr
, sym
, cu
);
20839 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20842 if (attr2
&& (DW_UNSND (attr2
) != 0))
20843 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20845 list_to_add
= cu
->list_in_scope
;
20849 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20850 if (attr
!= nullptr)
20852 var_decode_location (attr
, sym
, cu
);
20853 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20855 /* Fortran explicitly imports any global symbols to the local
20856 scope by DW_TAG_common_block. */
20857 if (cu
->language
== language_fortran
&& die
->parent
20858 && die
->parent
->tag
== DW_TAG_common_block
)
20861 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20862 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20863 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
20865 /* When a static variable is eliminated by the linker,
20866 the corresponding debug information is not stripped
20867 out, but the variable address is set to null;
20868 do not add such variables into symbol table. */
20870 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20872 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20873 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20874 && dwarf2_per_objfile
->per_bfd
->can_copy
)
20876 /* A global static variable might be subject to
20877 copy relocation. We first check for a local
20878 minsym, though, because maybe the symbol was
20879 marked hidden, in which case this would not
20881 bound_minimal_symbol found
20882 = (lookup_minimal_symbol_linkage
20883 (sym
->linkage_name (), objfile
));
20884 if (found
.minsym
!= nullptr)
20885 sym
->maybe_copied
= 1;
20888 /* A variable with DW_AT_external is never static,
20889 but it may be block-scoped. */
20891 = ((cu
->list_in_scope
20892 == cu
->get_builder ()->get_file_symbols ())
20893 ? cu
->get_builder ()->get_global_symbols ()
20894 : cu
->list_in_scope
);
20897 list_to_add
= cu
->list_in_scope
;
20901 /* We do not know the address of this symbol.
20902 If it is an external symbol and we have type information
20903 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20904 The address of the variable will then be determined from
20905 the minimal symbol table whenever the variable is
20907 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20909 /* Fortran explicitly imports any global symbols to the local
20910 scope by DW_TAG_common_block. */
20911 if (cu
->language
== language_fortran
&& die
->parent
20912 && die
->parent
->tag
== DW_TAG_common_block
)
20914 /* SYMBOL_CLASS doesn't matter here because
20915 read_common_block is going to reset it. */
20917 list_to_add
= cu
->list_in_scope
;
20919 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20920 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20922 /* A variable with DW_AT_external is never static, but it
20923 may be block-scoped. */
20925 = ((cu
->list_in_scope
20926 == cu
->get_builder ()->get_file_symbols ())
20927 ? cu
->get_builder ()->get_global_symbols ()
20928 : cu
->list_in_scope
);
20930 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20932 else if (!die_is_declaration (die
, cu
))
20934 /* Use the default LOC_OPTIMIZED_OUT class. */
20935 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20937 list_to_add
= cu
->list_in_scope
;
20941 case DW_TAG_formal_parameter
:
20943 /* If we are inside a function, mark this as an argument. If
20944 not, we might be looking at an argument to an inlined function
20945 when we do not have enough information to show inlined frames;
20946 pretend it's a local variable in that case so that the user can
20948 struct context_stack
*curr
20949 = cu
->get_builder ()->get_current_context_stack ();
20950 if (curr
!= nullptr && curr
->name
!= nullptr)
20951 SYMBOL_IS_ARGUMENT (sym
) = 1;
20952 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20953 if (attr
!= nullptr)
20955 var_decode_location (attr
, sym
, cu
);
20957 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20958 if (attr
!= nullptr)
20960 dwarf2_const_value (attr
, sym
, cu
);
20963 list_to_add
= cu
->list_in_scope
;
20966 case DW_TAG_unspecified_parameters
:
20967 /* From varargs functions; gdb doesn't seem to have any
20968 interest in this information, so just ignore it for now.
20971 case DW_TAG_template_type_param
:
20973 /* Fall through. */
20974 case DW_TAG_class_type
:
20975 case DW_TAG_interface_type
:
20976 case DW_TAG_structure_type
:
20977 case DW_TAG_union_type
:
20978 case DW_TAG_set_type
:
20979 case DW_TAG_enumeration_type
:
20980 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20981 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20984 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20985 really ever be static objects: otherwise, if you try
20986 to, say, break of a class's method and you're in a file
20987 which doesn't mention that class, it won't work unless
20988 the check for all static symbols in lookup_symbol_aux
20989 saves you. See the OtherFileClass tests in
20990 gdb.c++/namespace.exp. */
20994 buildsym_compunit
*builder
= cu
->get_builder ();
20996 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20997 && cu
->language
== language_cplus
20998 ? builder
->get_global_symbols ()
20999 : cu
->list_in_scope
);
21001 /* The semantics of C++ state that "struct foo {
21002 ... }" also defines a typedef for "foo". */
21003 if (cu
->language
== language_cplus
21004 || cu
->language
== language_ada
21005 || cu
->language
== language_d
21006 || cu
->language
== language_rust
)
21008 /* The symbol's name is already allocated along
21009 with this objfile, so we don't need to
21010 duplicate it for the type. */
21011 if (SYMBOL_TYPE (sym
)->name () == 0)
21012 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21017 case DW_TAG_typedef
:
21018 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21019 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21020 list_to_add
= cu
->list_in_scope
;
21022 case DW_TAG_base_type
:
21023 case DW_TAG_subrange_type
:
21024 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21025 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21026 list_to_add
= cu
->list_in_scope
;
21028 case DW_TAG_enumerator
:
21029 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21030 if (attr
!= nullptr)
21032 dwarf2_const_value (attr
, sym
, cu
);
21035 /* NOTE: carlton/2003-11-10: See comment above in the
21036 DW_TAG_class_type, etc. block. */
21039 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21040 && cu
->language
== language_cplus
21041 ? cu
->get_builder ()->get_global_symbols ()
21042 : cu
->list_in_scope
);
21045 case DW_TAG_imported_declaration
:
21046 case DW_TAG_namespace
:
21047 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21048 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21050 case DW_TAG_module
:
21051 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21052 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21053 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21055 case DW_TAG_common_block
:
21056 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21057 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21058 add_symbol_to_list (sym
, cu
->list_in_scope
);
21061 /* Not a tag we recognize. Hopefully we aren't processing
21062 trash data, but since we must specifically ignore things
21063 we don't recognize, there is nothing else we should do at
21065 complaint (_("unsupported tag: '%s'"),
21066 dwarf_tag_name (die
->tag
));
21072 sym
->hash_next
= objfile
->template_symbols
;
21073 objfile
->template_symbols
= sym
;
21074 list_to_add
= NULL
;
21077 if (list_to_add
!= NULL
)
21078 add_symbol_to_list (sym
, list_to_add
);
21080 /* For the benefit of old versions of GCC, check for anonymous
21081 namespaces based on the demangled name. */
21082 if (!cu
->processing_has_namespace_info
21083 && cu
->language
== language_cplus
)
21084 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21089 /* Given an attr with a DW_FORM_dataN value in host byte order,
21090 zero-extend it as appropriate for the symbol's type. The DWARF
21091 standard (v4) is not entirely clear about the meaning of using
21092 DW_FORM_dataN for a constant with a signed type, where the type is
21093 wider than the data. The conclusion of a discussion on the DWARF
21094 list was that this is unspecified. We choose to always zero-extend
21095 because that is the interpretation long in use by GCC. */
21098 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21099 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21101 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21102 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21103 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21104 LONGEST l
= DW_UNSND (attr
);
21106 if (bits
< sizeof (*value
) * 8)
21108 l
&= ((LONGEST
) 1 << bits
) - 1;
21111 else if (bits
== sizeof (*value
) * 8)
21115 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21116 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21123 /* Read a constant value from an attribute. Either set *VALUE, or if
21124 the value does not fit in *VALUE, set *BYTES - either already
21125 allocated on the objfile obstack, or newly allocated on OBSTACK,
21126 or, set *BATON, if we translated the constant to a location
21130 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21131 const char *name
, struct obstack
*obstack
,
21132 struct dwarf2_cu
*cu
,
21133 LONGEST
*value
, const gdb_byte
**bytes
,
21134 struct dwarf2_locexpr_baton
**baton
)
21136 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21137 struct objfile
*objfile
= per_objfile
->objfile
;
21138 struct comp_unit_head
*cu_header
= &cu
->header
;
21139 struct dwarf_block
*blk
;
21140 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21141 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21147 switch (attr
->form
)
21150 case DW_FORM_addrx
:
21151 case DW_FORM_GNU_addr_index
:
21155 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21156 dwarf2_const_value_length_mismatch_complaint (name
,
21157 cu_header
->addr_size
,
21158 TYPE_LENGTH (type
));
21159 /* Symbols of this form are reasonably rare, so we just
21160 piggyback on the existing location code rather than writing
21161 a new implementation of symbol_computed_ops. */
21162 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21163 (*baton
)->per_objfile
= per_objfile
;
21164 (*baton
)->per_cu
= cu
->per_cu
;
21165 gdb_assert ((*baton
)->per_cu
);
21167 (*baton
)->size
= 2 + cu_header
->addr_size
;
21168 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21169 (*baton
)->data
= data
;
21171 data
[0] = DW_OP_addr
;
21172 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21173 byte_order
, DW_ADDR (attr
));
21174 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21177 case DW_FORM_string
:
21180 case DW_FORM_GNU_str_index
:
21181 case DW_FORM_GNU_strp_alt
:
21182 /* DW_STRING is already allocated on the objfile obstack, point
21184 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21186 case DW_FORM_block1
:
21187 case DW_FORM_block2
:
21188 case DW_FORM_block4
:
21189 case DW_FORM_block
:
21190 case DW_FORM_exprloc
:
21191 case DW_FORM_data16
:
21192 blk
= DW_BLOCK (attr
);
21193 if (TYPE_LENGTH (type
) != blk
->size
)
21194 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21195 TYPE_LENGTH (type
));
21196 *bytes
= blk
->data
;
21199 /* The DW_AT_const_value attributes are supposed to carry the
21200 symbol's value "represented as it would be on the target
21201 architecture." By the time we get here, it's already been
21202 converted to host endianness, so we just need to sign- or
21203 zero-extend it as appropriate. */
21204 case DW_FORM_data1
:
21205 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21207 case DW_FORM_data2
:
21208 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21210 case DW_FORM_data4
:
21211 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21213 case DW_FORM_data8
:
21214 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21217 case DW_FORM_sdata
:
21218 case DW_FORM_implicit_const
:
21219 *value
= DW_SND (attr
);
21222 case DW_FORM_udata
:
21223 *value
= DW_UNSND (attr
);
21227 complaint (_("unsupported const value attribute form: '%s'"),
21228 dwarf_form_name (attr
->form
));
21235 /* Copy constant value from an attribute to a symbol. */
21238 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21239 struct dwarf2_cu
*cu
)
21241 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21243 const gdb_byte
*bytes
;
21244 struct dwarf2_locexpr_baton
*baton
;
21246 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21247 sym
->print_name (),
21248 &objfile
->objfile_obstack
, cu
,
21249 &value
, &bytes
, &baton
);
21253 SYMBOL_LOCATION_BATON (sym
) = baton
;
21254 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21256 else if (bytes
!= NULL
)
21258 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21259 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21263 SYMBOL_VALUE (sym
) = value
;
21264 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21268 /* Return the type of the die in question using its DW_AT_type attribute. */
21270 static struct type
*
21271 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21273 struct attribute
*type_attr
;
21275 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21278 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21279 /* A missing DW_AT_type represents a void type. */
21280 return objfile_type (objfile
)->builtin_void
;
21283 return lookup_die_type (die
, type_attr
, cu
);
21286 /* True iff CU's producer generates GNAT Ada auxiliary information
21287 that allows to find parallel types through that information instead
21288 of having to do expensive parallel lookups by type name. */
21291 need_gnat_info (struct dwarf2_cu
*cu
)
21293 /* Assume that the Ada compiler was GNAT, which always produces
21294 the auxiliary information. */
21295 return (cu
->language
== language_ada
);
21298 /* Return the auxiliary type of the die in question using its
21299 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21300 attribute is not present. */
21302 static struct type
*
21303 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21305 struct attribute
*type_attr
;
21307 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21311 return lookup_die_type (die
, type_attr
, cu
);
21314 /* If DIE has a descriptive_type attribute, then set the TYPE's
21315 descriptive type accordingly. */
21318 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21319 struct dwarf2_cu
*cu
)
21321 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21323 if (descriptive_type
)
21325 ALLOCATE_GNAT_AUX_TYPE (type
);
21326 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21330 /* Return the containing type of the die in question using its
21331 DW_AT_containing_type attribute. */
21333 static struct type
*
21334 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21336 struct attribute
*type_attr
;
21337 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21339 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21341 error (_("Dwarf Error: Problem turning containing type into gdb type "
21342 "[in module %s]"), objfile_name (objfile
));
21344 return lookup_die_type (die
, type_attr
, cu
);
21347 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21349 static struct type
*
21350 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21352 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21353 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21356 std::string message
21357 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21358 objfile_name (objfile
),
21359 sect_offset_str (cu
->header
.sect_off
),
21360 sect_offset_str (die
->sect_off
));
21361 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21363 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21366 /* Look up the type of DIE in CU using its type attribute ATTR.
21367 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21368 DW_AT_containing_type.
21369 If there is no type substitute an error marker. */
21371 static struct type
*
21372 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21373 struct dwarf2_cu
*cu
)
21375 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21376 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21377 struct type
*this_type
;
21379 gdb_assert (attr
->name
== DW_AT_type
21380 || attr
->name
== DW_AT_GNAT_descriptive_type
21381 || attr
->name
== DW_AT_containing_type
);
21383 /* First see if we have it cached. */
21385 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21387 struct dwarf2_per_cu_data
*per_cu
;
21388 sect_offset sect_off
= attr
->get_ref_die_offset ();
21390 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21391 dwarf2_per_objfile
);
21392 this_type
= get_die_type_at_offset (sect_off
, per_cu
, dwarf2_per_objfile
);
21394 else if (attr
->form_is_ref ())
21396 sect_offset sect_off
= attr
->get_ref_die_offset ();
21398 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
,
21399 dwarf2_per_objfile
);
21401 else if (attr
->form
== DW_FORM_ref_sig8
)
21403 ULONGEST signature
= DW_SIGNATURE (attr
);
21405 return get_signatured_type (die
, signature
, cu
);
21409 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21410 " at %s [in module %s]"),
21411 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21412 objfile_name (objfile
));
21413 return build_error_marker_type (cu
, die
);
21416 /* If not cached we need to read it in. */
21418 if (this_type
== NULL
)
21420 struct die_info
*type_die
= NULL
;
21421 struct dwarf2_cu
*type_cu
= cu
;
21423 if (attr
->form_is_ref ())
21424 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21425 if (type_die
== NULL
)
21426 return build_error_marker_type (cu
, die
);
21427 /* If we find the type now, it's probably because the type came
21428 from an inter-CU reference and the type's CU got expanded before
21430 this_type
= read_type_die (type_die
, type_cu
);
21433 /* If we still don't have a type use an error marker. */
21435 if (this_type
== NULL
)
21436 return build_error_marker_type (cu
, die
);
21441 /* Return the type in DIE, CU.
21442 Returns NULL for invalid types.
21444 This first does a lookup in die_type_hash,
21445 and only reads the die in if necessary.
21447 NOTE: This can be called when reading in partial or full symbols. */
21449 static struct type
*
21450 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21452 struct type
*this_type
;
21454 this_type
= get_die_type (die
, cu
);
21458 return read_type_die_1 (die
, cu
);
21461 /* Read the type in DIE, CU.
21462 Returns NULL for invalid types. */
21464 static struct type
*
21465 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21467 struct type
*this_type
= NULL
;
21471 case DW_TAG_class_type
:
21472 case DW_TAG_interface_type
:
21473 case DW_TAG_structure_type
:
21474 case DW_TAG_union_type
:
21475 this_type
= read_structure_type (die
, cu
);
21477 case DW_TAG_enumeration_type
:
21478 this_type
= read_enumeration_type (die
, cu
);
21480 case DW_TAG_subprogram
:
21481 case DW_TAG_subroutine_type
:
21482 case DW_TAG_inlined_subroutine
:
21483 this_type
= read_subroutine_type (die
, cu
);
21485 case DW_TAG_array_type
:
21486 this_type
= read_array_type (die
, cu
);
21488 case DW_TAG_set_type
:
21489 this_type
= read_set_type (die
, cu
);
21491 case DW_TAG_pointer_type
:
21492 this_type
= read_tag_pointer_type (die
, cu
);
21494 case DW_TAG_ptr_to_member_type
:
21495 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21497 case DW_TAG_reference_type
:
21498 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21500 case DW_TAG_rvalue_reference_type
:
21501 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21503 case DW_TAG_const_type
:
21504 this_type
= read_tag_const_type (die
, cu
);
21506 case DW_TAG_volatile_type
:
21507 this_type
= read_tag_volatile_type (die
, cu
);
21509 case DW_TAG_restrict_type
:
21510 this_type
= read_tag_restrict_type (die
, cu
);
21512 case DW_TAG_string_type
:
21513 this_type
= read_tag_string_type (die
, cu
);
21515 case DW_TAG_typedef
:
21516 this_type
= read_typedef (die
, cu
);
21518 case DW_TAG_subrange_type
:
21519 this_type
= read_subrange_type (die
, cu
);
21521 case DW_TAG_base_type
:
21522 this_type
= read_base_type (die
, cu
);
21524 case DW_TAG_unspecified_type
:
21525 this_type
= read_unspecified_type (die
, cu
);
21527 case DW_TAG_namespace
:
21528 this_type
= read_namespace_type (die
, cu
);
21530 case DW_TAG_module
:
21531 this_type
= read_module_type (die
, cu
);
21533 case DW_TAG_atomic_type
:
21534 this_type
= read_tag_atomic_type (die
, cu
);
21537 complaint (_("unexpected tag in read_type_die: '%s'"),
21538 dwarf_tag_name (die
->tag
));
21545 /* See if we can figure out if the class lives in a namespace. We do
21546 this by looking for a member function; its demangled name will
21547 contain namespace info, if there is any.
21548 Return the computed name or NULL.
21549 Space for the result is allocated on the objfile's obstack.
21550 This is the full-die version of guess_partial_die_structure_name.
21551 In this case we know DIE has no useful parent. */
21553 static const char *
21554 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21556 struct die_info
*spec_die
;
21557 struct dwarf2_cu
*spec_cu
;
21558 struct die_info
*child
;
21559 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21562 spec_die
= die_specification (die
, &spec_cu
);
21563 if (spec_die
!= NULL
)
21569 for (child
= die
->child
;
21571 child
= child
->sibling
)
21573 if (child
->tag
== DW_TAG_subprogram
)
21575 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21577 if (linkage_name
!= NULL
)
21579 gdb::unique_xmalloc_ptr
<char> actual_name
21580 (language_class_name_from_physname (cu
->language_defn
,
21582 const char *name
= NULL
;
21584 if (actual_name
!= NULL
)
21586 const char *die_name
= dwarf2_name (die
, cu
);
21588 if (die_name
!= NULL
21589 && strcmp (die_name
, actual_name
.get ()) != 0)
21591 /* Strip off the class name from the full name.
21592 We want the prefix. */
21593 int die_name_len
= strlen (die_name
);
21594 int actual_name_len
= strlen (actual_name
.get ());
21595 const char *ptr
= actual_name
.get ();
21597 /* Test for '::' as a sanity check. */
21598 if (actual_name_len
> die_name_len
+ 2
21599 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21600 name
= obstack_strndup (
21601 &objfile
->per_bfd
->storage_obstack
,
21602 ptr
, actual_name_len
- die_name_len
- 2);
21613 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21614 prefix part in such case. See
21615 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21617 static const char *
21618 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21620 struct attribute
*attr
;
21623 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21624 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21627 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21630 attr
= dw2_linkage_name_attr (die
, cu
);
21631 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21634 /* dwarf2_name had to be already called. */
21635 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21637 /* Strip the base name, keep any leading namespaces/classes. */
21638 base
= strrchr (DW_STRING (attr
), ':');
21639 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21642 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21643 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21645 &base
[-1] - DW_STRING (attr
));
21648 /* Return the name of the namespace/class that DIE is defined within,
21649 or "" if we can't tell. The caller should not xfree the result.
21651 For example, if we're within the method foo() in the following
21661 then determine_prefix on foo's die will return "N::C". */
21663 static const char *
21664 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21666 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21667 struct die_info
*parent
, *spec_die
;
21668 struct dwarf2_cu
*spec_cu
;
21669 struct type
*parent_type
;
21670 const char *retval
;
21672 if (cu
->language
!= language_cplus
21673 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21674 && cu
->language
!= language_rust
)
21677 retval
= anonymous_struct_prefix (die
, cu
);
21681 /* We have to be careful in the presence of DW_AT_specification.
21682 For example, with GCC 3.4, given the code
21686 // Definition of N::foo.
21690 then we'll have a tree of DIEs like this:
21692 1: DW_TAG_compile_unit
21693 2: DW_TAG_namespace // N
21694 3: DW_TAG_subprogram // declaration of N::foo
21695 4: DW_TAG_subprogram // definition of N::foo
21696 DW_AT_specification // refers to die #3
21698 Thus, when processing die #4, we have to pretend that we're in
21699 the context of its DW_AT_specification, namely the contex of die
21702 spec_die
= die_specification (die
, &spec_cu
);
21703 if (spec_die
== NULL
)
21704 parent
= die
->parent
;
21707 parent
= spec_die
->parent
;
21711 if (parent
== NULL
)
21713 else if (parent
->building_fullname
)
21716 const char *parent_name
;
21718 /* It has been seen on RealView 2.2 built binaries,
21719 DW_TAG_template_type_param types actually _defined_ as
21720 children of the parent class:
21723 template class <class Enum> Class{};
21724 Class<enum E> class_e;
21726 1: DW_TAG_class_type (Class)
21727 2: DW_TAG_enumeration_type (E)
21728 3: DW_TAG_enumerator (enum1:0)
21729 3: DW_TAG_enumerator (enum2:1)
21731 2: DW_TAG_template_type_param
21732 DW_AT_type DW_FORM_ref_udata (E)
21734 Besides being broken debug info, it can put GDB into an
21735 infinite loop. Consider:
21737 When we're building the full name for Class<E>, we'll start
21738 at Class, and go look over its template type parameters,
21739 finding E. We'll then try to build the full name of E, and
21740 reach here. We're now trying to build the full name of E,
21741 and look over the parent DIE for containing scope. In the
21742 broken case, if we followed the parent DIE of E, we'd again
21743 find Class, and once again go look at its template type
21744 arguments, etc., etc. Simply don't consider such parent die
21745 as source-level parent of this die (it can't be, the language
21746 doesn't allow it), and break the loop here. */
21747 name
= dwarf2_name (die
, cu
);
21748 parent_name
= dwarf2_name (parent
, cu
);
21749 complaint (_("template param type '%s' defined within parent '%s'"),
21750 name
? name
: "<unknown>",
21751 parent_name
? parent_name
: "<unknown>");
21755 switch (parent
->tag
)
21757 case DW_TAG_namespace
:
21758 parent_type
= read_type_die (parent
, cu
);
21759 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21760 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21761 Work around this problem here. */
21762 if (cu
->language
== language_cplus
21763 && strcmp (parent_type
->name (), "::") == 0)
21765 /* We give a name to even anonymous namespaces. */
21766 return parent_type
->name ();
21767 case DW_TAG_class_type
:
21768 case DW_TAG_interface_type
:
21769 case DW_TAG_structure_type
:
21770 case DW_TAG_union_type
:
21771 case DW_TAG_module
:
21772 parent_type
= read_type_die (parent
, cu
);
21773 if (parent_type
->name () != NULL
)
21774 return parent_type
->name ();
21776 /* An anonymous structure is only allowed non-static data
21777 members; no typedefs, no member functions, et cetera.
21778 So it does not need a prefix. */
21780 case DW_TAG_compile_unit
:
21781 case DW_TAG_partial_unit
:
21782 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21783 if (cu
->language
== language_cplus
21784 && !dwarf2_per_objfile
->per_bfd
->types
.empty ()
21785 && die
->child
!= NULL
21786 && (die
->tag
== DW_TAG_class_type
21787 || die
->tag
== DW_TAG_structure_type
21788 || die
->tag
== DW_TAG_union_type
))
21790 const char *name
= guess_full_die_structure_name (die
, cu
);
21795 case DW_TAG_subprogram
:
21796 /* Nested subroutines in Fortran get a prefix with the name
21797 of the parent's subroutine. */
21798 if (cu
->language
== language_fortran
)
21800 if ((die
->tag
== DW_TAG_subprogram
)
21801 && (dwarf2_name (parent
, cu
) != NULL
))
21802 return dwarf2_name (parent
, cu
);
21804 return determine_prefix (parent
, cu
);
21805 case DW_TAG_enumeration_type
:
21806 parent_type
= read_type_die (parent
, cu
);
21807 if (TYPE_DECLARED_CLASS (parent_type
))
21809 if (parent_type
->name () != NULL
)
21810 return parent_type
->name ();
21813 /* Fall through. */
21815 return determine_prefix (parent
, cu
);
21819 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21820 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21821 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21822 an obconcat, otherwise allocate storage for the result. The CU argument is
21823 used to determine the language and hence, the appropriate separator. */
21825 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21828 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21829 int physname
, struct dwarf2_cu
*cu
)
21831 const char *lead
= "";
21834 if (suffix
== NULL
|| suffix
[0] == '\0'
21835 || prefix
== NULL
|| prefix
[0] == '\0')
21837 else if (cu
->language
== language_d
)
21839 /* For D, the 'main' function could be defined in any module, but it
21840 should never be prefixed. */
21841 if (strcmp (suffix
, "D main") == 0)
21849 else if (cu
->language
== language_fortran
&& physname
)
21851 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21852 DW_AT_MIPS_linkage_name is preferred and used instead. */
21860 if (prefix
== NULL
)
21862 if (suffix
== NULL
)
21869 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21871 strcpy (retval
, lead
);
21872 strcat (retval
, prefix
);
21873 strcat (retval
, sep
);
21874 strcat (retval
, suffix
);
21879 /* We have an obstack. */
21880 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21884 /* Get name of a die, return NULL if not found. */
21886 static const char *
21887 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21888 struct objfile
*objfile
)
21890 if (name
&& cu
->language
== language_cplus
)
21892 gdb::unique_xmalloc_ptr
<char> canon_name
21893 = cp_canonicalize_string (name
);
21895 if (canon_name
!= nullptr)
21896 name
= objfile
->intern (canon_name
.get ());
21902 /* Get name of a die, return NULL if not found.
21903 Anonymous namespaces are converted to their magic string. */
21905 static const char *
21906 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21908 struct attribute
*attr
;
21909 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21911 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21912 if ((!attr
|| !DW_STRING (attr
))
21913 && die
->tag
!= DW_TAG_namespace
21914 && die
->tag
!= DW_TAG_class_type
21915 && die
->tag
!= DW_TAG_interface_type
21916 && die
->tag
!= DW_TAG_structure_type
21917 && die
->tag
!= DW_TAG_union_type
)
21922 case DW_TAG_compile_unit
:
21923 case DW_TAG_partial_unit
:
21924 /* Compilation units have a DW_AT_name that is a filename, not
21925 a source language identifier. */
21926 case DW_TAG_enumeration_type
:
21927 case DW_TAG_enumerator
:
21928 /* These tags always have simple identifiers already; no need
21929 to canonicalize them. */
21930 return DW_STRING (attr
);
21932 case DW_TAG_namespace
:
21933 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21934 return DW_STRING (attr
);
21935 return CP_ANONYMOUS_NAMESPACE_STR
;
21937 case DW_TAG_class_type
:
21938 case DW_TAG_interface_type
:
21939 case DW_TAG_structure_type
:
21940 case DW_TAG_union_type
:
21941 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21942 structures or unions. These were of the form "._%d" in GCC 4.1,
21943 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21944 and GCC 4.4. We work around this problem by ignoring these. */
21945 if (attr
&& DW_STRING (attr
)
21946 && (startswith (DW_STRING (attr
), "._")
21947 || startswith (DW_STRING (attr
), "<anonymous")))
21950 /* GCC might emit a nameless typedef that has a linkage name. See
21951 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21952 if (!attr
|| DW_STRING (attr
) == NULL
)
21954 attr
= dw2_linkage_name_attr (die
, cu
);
21955 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21958 /* Avoid demangling DW_STRING (attr) the second time on a second
21959 call for the same DIE. */
21960 if (!DW_STRING_IS_CANONICAL (attr
))
21962 gdb::unique_xmalloc_ptr
<char> demangled
21963 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21964 if (demangled
== nullptr)
21967 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21968 DW_STRING_IS_CANONICAL (attr
) = 1;
21971 /* Strip any leading namespaces/classes, keep only the base name.
21972 DW_AT_name for named DIEs does not contain the prefixes. */
21973 const char *base
= strrchr (DW_STRING (attr
), ':');
21974 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21977 return DW_STRING (attr
);
21985 if (!DW_STRING_IS_CANONICAL (attr
))
21987 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21989 DW_STRING_IS_CANONICAL (attr
) = 1;
21991 return DW_STRING (attr
);
21994 /* Return the die that this die in an extension of, or NULL if there
21995 is none. *EXT_CU is the CU containing DIE on input, and the CU
21996 containing the return value on output. */
21998 static struct die_info
*
21999 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22001 struct attribute
*attr
;
22003 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22007 return follow_die_ref (die
, attr
, ext_cu
);
22011 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22015 print_spaces (indent
, f
);
22016 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22017 dwarf_tag_name (die
->tag
), die
->abbrev
,
22018 sect_offset_str (die
->sect_off
));
22020 if (die
->parent
!= NULL
)
22022 print_spaces (indent
, f
);
22023 fprintf_unfiltered (f
, " parent at offset: %s\n",
22024 sect_offset_str (die
->parent
->sect_off
));
22027 print_spaces (indent
, f
);
22028 fprintf_unfiltered (f
, " has children: %s\n",
22029 dwarf_bool_name (die
->child
!= NULL
));
22031 print_spaces (indent
, f
);
22032 fprintf_unfiltered (f
, " attributes:\n");
22034 for (i
= 0; i
< die
->num_attrs
; ++i
)
22036 print_spaces (indent
, f
);
22037 fprintf_unfiltered (f
, " %s (%s) ",
22038 dwarf_attr_name (die
->attrs
[i
].name
),
22039 dwarf_form_name (die
->attrs
[i
].form
));
22041 switch (die
->attrs
[i
].form
)
22044 case DW_FORM_addrx
:
22045 case DW_FORM_GNU_addr_index
:
22046 fprintf_unfiltered (f
, "address: ");
22047 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22049 case DW_FORM_block2
:
22050 case DW_FORM_block4
:
22051 case DW_FORM_block
:
22052 case DW_FORM_block1
:
22053 fprintf_unfiltered (f
, "block: size %s",
22054 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22056 case DW_FORM_exprloc
:
22057 fprintf_unfiltered (f
, "expression: size %s",
22058 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22060 case DW_FORM_data16
:
22061 fprintf_unfiltered (f
, "constant of 16 bytes");
22063 case DW_FORM_ref_addr
:
22064 fprintf_unfiltered (f
, "ref address: ");
22065 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22067 case DW_FORM_GNU_ref_alt
:
22068 fprintf_unfiltered (f
, "alt ref address: ");
22069 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22075 case DW_FORM_ref_udata
:
22076 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22077 (long) (DW_UNSND (&die
->attrs
[i
])));
22079 case DW_FORM_data1
:
22080 case DW_FORM_data2
:
22081 case DW_FORM_data4
:
22082 case DW_FORM_data8
:
22083 case DW_FORM_udata
:
22084 case DW_FORM_sdata
:
22085 fprintf_unfiltered (f
, "constant: %s",
22086 pulongest (DW_UNSND (&die
->attrs
[i
])));
22088 case DW_FORM_sec_offset
:
22089 fprintf_unfiltered (f
, "section offset: %s",
22090 pulongest (DW_UNSND (&die
->attrs
[i
])));
22092 case DW_FORM_ref_sig8
:
22093 fprintf_unfiltered (f
, "signature: %s",
22094 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22096 case DW_FORM_string
:
22098 case DW_FORM_line_strp
:
22100 case DW_FORM_GNU_str_index
:
22101 case DW_FORM_GNU_strp_alt
:
22102 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22103 DW_STRING (&die
->attrs
[i
])
22104 ? DW_STRING (&die
->attrs
[i
]) : "",
22105 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22108 if (DW_UNSND (&die
->attrs
[i
]))
22109 fprintf_unfiltered (f
, "flag: TRUE");
22111 fprintf_unfiltered (f
, "flag: FALSE");
22113 case DW_FORM_flag_present
:
22114 fprintf_unfiltered (f
, "flag: TRUE");
22116 case DW_FORM_indirect
:
22117 /* The reader will have reduced the indirect form to
22118 the "base form" so this form should not occur. */
22119 fprintf_unfiltered (f
,
22120 "unexpected attribute form: DW_FORM_indirect");
22122 case DW_FORM_implicit_const
:
22123 fprintf_unfiltered (f
, "constant: %s",
22124 plongest (DW_SND (&die
->attrs
[i
])));
22127 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22128 die
->attrs
[i
].form
);
22131 fprintf_unfiltered (f
, "\n");
22136 dump_die_for_error (struct die_info
*die
)
22138 dump_die_shallow (gdb_stderr
, 0, die
);
22142 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22144 int indent
= level
* 4;
22146 gdb_assert (die
!= NULL
);
22148 if (level
>= max_level
)
22151 dump_die_shallow (f
, indent
, die
);
22153 if (die
->child
!= NULL
)
22155 print_spaces (indent
, f
);
22156 fprintf_unfiltered (f
, " Children:");
22157 if (level
+ 1 < max_level
)
22159 fprintf_unfiltered (f
, "\n");
22160 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22164 fprintf_unfiltered (f
,
22165 " [not printed, max nesting level reached]\n");
22169 if (die
->sibling
!= NULL
&& level
> 0)
22171 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22175 /* This is called from the pdie macro in gdbinit.in.
22176 It's not static so gcc will keep a copy callable from gdb. */
22179 dump_die (struct die_info
*die
, int max_level
)
22181 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22185 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22189 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22190 to_underlying (die
->sect_off
),
22196 /* Follow reference or signature attribute ATTR of SRC_DIE.
22197 On entry *REF_CU is the CU of SRC_DIE.
22198 On exit *REF_CU is the CU of the result. */
22200 static struct die_info
*
22201 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22202 struct dwarf2_cu
**ref_cu
)
22204 struct die_info
*die
;
22206 if (attr
->form_is_ref ())
22207 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22208 else if (attr
->form
== DW_FORM_ref_sig8
)
22209 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22212 dump_die_for_error (src_die
);
22213 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22214 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22220 /* Follow reference OFFSET.
22221 On entry *REF_CU is the CU of the source die referencing OFFSET.
22222 On exit *REF_CU is the CU of the result.
22223 Returns NULL if OFFSET is invalid. */
22225 static struct die_info
*
22226 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22227 struct dwarf2_cu
**ref_cu
)
22229 struct die_info temp_die
;
22230 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22231 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22233 gdb_assert (cu
->per_cu
!= NULL
);
22237 if (cu
->per_cu
->is_debug_types
)
22239 /* .debug_types CUs cannot reference anything outside their CU.
22240 If they need to, they have to reference a signatured type via
22241 DW_FORM_ref_sig8. */
22242 if (!cu
->header
.offset_in_cu_p (sect_off
))
22245 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22246 || !cu
->header
.offset_in_cu_p (sect_off
))
22248 struct dwarf2_per_cu_data
*per_cu
;
22250 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22251 dwarf2_per_objfile
);
22253 /* If necessary, add it to the queue and load its DIEs. */
22254 if (maybe_queue_comp_unit (cu
, per_cu
, dwarf2_per_objfile
, cu
->language
))
22255 load_full_comp_unit (per_cu
, dwarf2_per_objfile
, false, cu
->language
);
22257 target_cu
= per_cu
->cu
;
22259 else if (cu
->dies
== NULL
)
22261 /* We're loading full DIEs during partial symbol reading. */
22262 gdb_assert (dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
);
22263 load_full_comp_unit (cu
->per_cu
, dwarf2_per_objfile
, false,
22267 *ref_cu
= target_cu
;
22268 temp_die
.sect_off
= sect_off
;
22270 if (target_cu
!= cu
)
22271 target_cu
->ancestor
= cu
;
22273 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22275 to_underlying (sect_off
));
22278 /* Follow reference attribute ATTR of SRC_DIE.
22279 On entry *REF_CU is the CU of SRC_DIE.
22280 On exit *REF_CU is the CU of the result. */
22282 static struct die_info
*
22283 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22284 struct dwarf2_cu
**ref_cu
)
22286 sect_offset sect_off
= attr
->get_ref_die_offset ();
22287 struct dwarf2_cu
*cu
= *ref_cu
;
22288 struct die_info
*die
;
22290 die
= follow_die_offset (sect_off
,
22291 (attr
->form
== DW_FORM_GNU_ref_alt
22292 || cu
->per_cu
->is_dwz
),
22295 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22296 "at %s [in module %s]"),
22297 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22298 objfile_name (cu
->per_objfile
->objfile
));
22305 struct dwarf2_locexpr_baton
22306 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22307 dwarf2_per_cu_data
*per_cu
,
22308 dwarf2_per_objfile
*dwarf2_per_objfile
,
22309 CORE_ADDR (*get_frame_pc
) (void *baton
),
22310 void *baton
, bool resolve_abstract_p
)
22312 struct dwarf2_cu
*cu
;
22313 struct die_info
*die
;
22314 struct attribute
*attr
;
22315 struct dwarf2_locexpr_baton retval
;
22316 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22318 if (per_cu
->cu
== NULL
)
22319 load_cu (per_cu
, dwarf2_per_objfile
, false);
22323 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22324 Instead just throw an error, not much else we can do. */
22325 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22326 sect_offset_str (sect_off
), objfile_name (objfile
));
22329 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22331 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22332 sect_offset_str (sect_off
), objfile_name (objfile
));
22334 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22335 if (!attr
&& resolve_abstract_p
22336 && (dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22337 != dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22339 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22340 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22341 struct gdbarch
*gdbarch
= objfile
->arch ();
22343 for (const auto &cand_off
22344 : dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22346 struct dwarf2_cu
*cand_cu
= cu
;
22347 struct die_info
*cand
22348 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22351 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22354 CORE_ADDR pc_low
, pc_high
;
22355 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22356 if (pc_low
== ((CORE_ADDR
) -1))
22358 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22359 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22360 if (!(pc_low
<= pc
&& pc
< pc_high
))
22364 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22371 /* DWARF: "If there is no such attribute, then there is no effect.".
22372 DATA is ignored if SIZE is 0. */
22374 retval
.data
= NULL
;
22377 else if (attr
->form_is_section_offset ())
22379 struct dwarf2_loclist_baton loclist_baton
;
22380 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22383 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22385 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22387 retval
.size
= size
;
22391 if (!attr
->form_is_block ())
22392 error (_("Dwarf Error: DIE at %s referenced in module %s "
22393 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22394 sect_offset_str (sect_off
), objfile_name (objfile
));
22396 retval
.data
= DW_BLOCK (attr
)->data
;
22397 retval
.size
= DW_BLOCK (attr
)->size
;
22399 retval
.per_objfile
= dwarf2_per_objfile
;
22400 retval
.per_cu
= cu
->per_cu
;
22402 age_cached_comp_units (dwarf2_per_objfile
);
22409 struct dwarf2_locexpr_baton
22410 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22411 dwarf2_per_cu_data
*per_cu
,
22412 dwarf2_per_objfile
*per_objfile
,
22413 CORE_ADDR (*get_frame_pc
) (void *baton
),
22416 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22418 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22419 get_frame_pc
, baton
);
22422 /* Write a constant of a given type as target-ordered bytes into
22425 static const gdb_byte
*
22426 write_constant_as_bytes (struct obstack
*obstack
,
22427 enum bfd_endian byte_order
,
22434 *len
= TYPE_LENGTH (type
);
22435 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22436 store_unsigned_integer (result
, *len
, byte_order
, value
);
22444 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22445 dwarf2_per_cu_data
*per_cu
,
22446 dwarf2_per_objfile
*per_objfile
,
22450 struct dwarf2_cu
*cu
;
22451 struct die_info
*die
;
22452 struct attribute
*attr
;
22453 const gdb_byte
*result
= NULL
;
22456 enum bfd_endian byte_order
;
22457 struct objfile
*objfile
= per_objfile
->objfile
;
22459 if (per_cu
->cu
== NULL
)
22460 load_cu (per_cu
, per_objfile
, false);
22464 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22465 Instead just throw an error, not much else we can do. */
22466 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22467 sect_offset_str (sect_off
), objfile_name (objfile
));
22470 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22472 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22473 sect_offset_str (sect_off
), objfile_name (objfile
));
22475 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22479 byte_order
= (bfd_big_endian (objfile
->obfd
)
22480 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22482 switch (attr
->form
)
22485 case DW_FORM_addrx
:
22486 case DW_FORM_GNU_addr_index
:
22490 *len
= cu
->header
.addr_size
;
22491 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22492 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22496 case DW_FORM_string
:
22499 case DW_FORM_GNU_str_index
:
22500 case DW_FORM_GNU_strp_alt
:
22501 /* DW_STRING is already allocated on the objfile obstack, point
22503 result
= (const gdb_byte
*) DW_STRING (attr
);
22504 *len
= strlen (DW_STRING (attr
));
22506 case DW_FORM_block1
:
22507 case DW_FORM_block2
:
22508 case DW_FORM_block4
:
22509 case DW_FORM_block
:
22510 case DW_FORM_exprloc
:
22511 case DW_FORM_data16
:
22512 result
= DW_BLOCK (attr
)->data
;
22513 *len
= DW_BLOCK (attr
)->size
;
22516 /* The DW_AT_const_value attributes are supposed to carry the
22517 symbol's value "represented as it would be on the target
22518 architecture." By the time we get here, it's already been
22519 converted to host endianness, so we just need to sign- or
22520 zero-extend it as appropriate. */
22521 case DW_FORM_data1
:
22522 type
= die_type (die
, cu
);
22523 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22524 if (result
== NULL
)
22525 result
= write_constant_as_bytes (obstack
, byte_order
,
22528 case DW_FORM_data2
:
22529 type
= die_type (die
, cu
);
22530 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22531 if (result
== NULL
)
22532 result
= write_constant_as_bytes (obstack
, byte_order
,
22535 case DW_FORM_data4
:
22536 type
= die_type (die
, cu
);
22537 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22538 if (result
== NULL
)
22539 result
= write_constant_as_bytes (obstack
, byte_order
,
22542 case DW_FORM_data8
:
22543 type
= die_type (die
, cu
);
22544 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22545 if (result
== NULL
)
22546 result
= write_constant_as_bytes (obstack
, byte_order
,
22550 case DW_FORM_sdata
:
22551 case DW_FORM_implicit_const
:
22552 type
= die_type (die
, cu
);
22553 result
= write_constant_as_bytes (obstack
, byte_order
,
22554 type
, DW_SND (attr
), len
);
22557 case DW_FORM_udata
:
22558 type
= die_type (die
, cu
);
22559 result
= write_constant_as_bytes (obstack
, byte_order
,
22560 type
, DW_UNSND (attr
), len
);
22564 complaint (_("unsupported const value attribute form: '%s'"),
22565 dwarf_form_name (attr
->form
));
22575 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22576 dwarf2_per_cu_data
*per_cu
,
22577 dwarf2_per_objfile
*per_objfile
)
22579 struct dwarf2_cu
*cu
;
22580 struct die_info
*die
;
22582 if (per_cu
->cu
== NULL
)
22583 load_cu (per_cu
, per_objfile
, false);
22588 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22592 return die_type (die
, cu
);
22598 dwarf2_get_die_type (cu_offset die_offset
,
22599 dwarf2_per_cu_data
*per_cu
,
22600 dwarf2_per_objfile
*per_objfile
)
22602 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22603 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
22606 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22607 On entry *REF_CU is the CU of SRC_DIE.
22608 On exit *REF_CU is the CU of the result.
22609 Returns NULL if the referenced DIE isn't found. */
22611 static struct die_info
*
22612 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22613 struct dwarf2_cu
**ref_cu
)
22615 struct die_info temp_die
;
22616 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22617 struct die_info
*die
;
22618 dwarf2_per_objfile
*dwarf2_per_objfile
= (*ref_cu
)->per_objfile
;
22621 /* While it might be nice to assert sig_type->type == NULL here,
22622 we can get here for DW_AT_imported_declaration where we need
22623 the DIE not the type. */
22625 /* If necessary, add it to the queue and load its DIEs. */
22627 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, dwarf2_per_objfile
,
22629 read_signatured_type (sig_type
, dwarf2_per_objfile
);
22631 sig_cu
= sig_type
->per_cu
.cu
;
22632 gdb_assert (sig_cu
!= NULL
);
22633 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22634 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22635 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22636 to_underlying (temp_die
.sect_off
));
22639 /* For .gdb_index version 7 keep track of included TUs.
22640 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22641 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
22642 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7)
22644 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22649 sig_cu
->ancestor
= cu
;
22657 /* Follow signatured type referenced by ATTR in SRC_DIE.
22658 On entry *REF_CU is the CU of SRC_DIE.
22659 On exit *REF_CU is the CU of the result.
22660 The result is the DIE of the type.
22661 If the referenced type cannot be found an error is thrown. */
22663 static struct die_info
*
22664 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22665 struct dwarf2_cu
**ref_cu
)
22667 ULONGEST signature
= DW_SIGNATURE (attr
);
22668 struct signatured_type
*sig_type
;
22669 struct die_info
*die
;
22671 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22673 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22674 /* sig_type will be NULL if the signatured type is missing from
22676 if (sig_type
== NULL
)
22678 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22679 " from DIE at %s [in module %s]"),
22680 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22681 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22684 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22687 dump_die_for_error (src_die
);
22688 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22689 " from DIE at %s [in module %s]"),
22690 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22691 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22697 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22698 reading in and processing the type unit if necessary. */
22700 static struct type
*
22701 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22702 struct dwarf2_cu
*cu
)
22704 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22705 struct signatured_type
*sig_type
;
22706 struct dwarf2_cu
*type_cu
;
22707 struct die_info
*type_die
;
22710 sig_type
= lookup_signatured_type (cu
, signature
);
22711 /* sig_type will be NULL if the signatured type is missing from
22713 if (sig_type
== NULL
)
22715 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22716 " from DIE at %s [in module %s]"),
22717 hex_string (signature
), sect_offset_str (die
->sect_off
),
22718 objfile_name (dwarf2_per_objfile
->objfile
));
22719 return build_error_marker_type (cu
, die
);
22722 /* If we already know the type we're done. */
22723 if (sig_type
->type
!= NULL
)
22724 return sig_type
->type
;
22727 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22728 if (type_die
!= NULL
)
22730 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22731 is created. This is important, for example, because for c++ classes
22732 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22733 type
= read_type_die (type_die
, type_cu
);
22736 complaint (_("Dwarf Error: Cannot build signatured type %s"
22737 " referenced from DIE at %s [in module %s]"),
22738 hex_string (signature
), sect_offset_str (die
->sect_off
),
22739 objfile_name (dwarf2_per_objfile
->objfile
));
22740 type
= build_error_marker_type (cu
, die
);
22745 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22746 " from DIE at %s [in module %s]"),
22747 hex_string (signature
), sect_offset_str (die
->sect_off
),
22748 objfile_name (dwarf2_per_objfile
->objfile
));
22749 type
= build_error_marker_type (cu
, die
);
22751 sig_type
->type
= type
;
22756 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22757 reading in and processing the type unit if necessary. */
22759 static struct type
*
22760 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22761 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22763 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22764 if (attr
->form_is_ref ())
22766 struct dwarf2_cu
*type_cu
= cu
;
22767 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22769 return read_type_die (type_die
, type_cu
);
22771 else if (attr
->form
== DW_FORM_ref_sig8
)
22773 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22777 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22779 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22780 " at %s [in module %s]"),
22781 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22782 objfile_name (dwarf2_per_objfile
->objfile
));
22783 return build_error_marker_type (cu
, die
);
22787 /* Load the DIEs associated with type unit PER_CU into memory. */
22790 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22791 dwarf2_per_objfile
*per_objfile
)
22793 struct signatured_type
*sig_type
;
22795 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22796 gdb_assert (! per_cu
->type_unit_group_p ());
22798 /* We have the per_cu, but we need the signatured_type.
22799 Fortunately this is an easy translation. */
22800 gdb_assert (per_cu
->is_debug_types
);
22801 sig_type
= (struct signatured_type
*) per_cu
;
22803 gdb_assert (per_cu
->cu
== NULL
);
22805 read_signatured_type (sig_type
, per_objfile
);
22807 gdb_assert (per_cu
->cu
!= NULL
);
22810 /* Read in a signatured type and build its CU and DIEs.
22811 If the type is a stub for the real type in a DWO file,
22812 read in the real type from the DWO file as well. */
22815 read_signatured_type (signatured_type
*sig_type
,
22816 dwarf2_per_objfile
*per_objfile
)
22818 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22820 gdb_assert (per_cu
->is_debug_types
);
22821 gdb_assert (per_cu
->cu
== NULL
);
22823 cutu_reader
reader (per_cu
, per_objfile
, NULL
, 0, false);
22825 if (!reader
.dummy_p
)
22827 struct dwarf2_cu
*cu
= reader
.cu
;
22828 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22830 gdb_assert (cu
->die_hash
== NULL
);
22832 htab_create_alloc_ex (cu
->header
.length
/ 12,
22836 &cu
->comp_unit_obstack
,
22837 hashtab_obstack_allocate
,
22838 dummy_obstack_deallocate
);
22840 if (reader
.comp_unit_die
->has_children
)
22841 reader
.comp_unit_die
->child
22842 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22843 reader
.comp_unit_die
);
22844 cu
->dies
= reader
.comp_unit_die
;
22845 /* comp_unit_die is not stored in die_hash, no need. */
22847 /* We try not to read any attributes in this function, because
22848 not all CUs needed for references have been loaded yet, and
22849 symbol table processing isn't initialized. But we have to
22850 set the CU language, or we won't be able to build types
22851 correctly. Similarly, if we do not read the producer, we can
22852 not apply producer-specific interpretation. */
22853 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22858 sig_type
->per_cu
.tu_read
= 1;
22861 /* Decode simple location descriptions.
22862 Given a pointer to a dwarf block that defines a location, compute
22863 the location and return the value. If COMPUTED is non-null, it is
22864 set to true to indicate that decoding was successful, and false
22865 otherwise. If COMPUTED is null, then this function may emit a
22869 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22871 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22873 size_t size
= blk
->size
;
22874 const gdb_byte
*data
= blk
->data
;
22875 CORE_ADDR stack
[64];
22877 unsigned int bytes_read
, unsnd
;
22880 if (computed
!= nullptr)
22886 stack
[++stacki
] = 0;
22925 stack
[++stacki
] = op
- DW_OP_lit0
;
22960 stack
[++stacki
] = op
- DW_OP_reg0
;
22963 if (computed
== nullptr)
22964 dwarf2_complex_location_expr_complaint ();
22971 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22973 stack
[++stacki
] = unsnd
;
22976 if (computed
== nullptr)
22977 dwarf2_complex_location_expr_complaint ();
22984 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22989 case DW_OP_const1u
:
22990 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22994 case DW_OP_const1s
:
22995 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22999 case DW_OP_const2u
:
23000 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23004 case DW_OP_const2s
:
23005 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23009 case DW_OP_const4u
:
23010 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23014 case DW_OP_const4s
:
23015 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23019 case DW_OP_const8u
:
23020 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23025 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23031 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23036 stack
[stacki
+ 1] = stack
[stacki
];
23041 stack
[stacki
- 1] += stack
[stacki
];
23045 case DW_OP_plus_uconst
:
23046 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23052 stack
[stacki
- 1] -= stack
[stacki
];
23057 /* If we're not the last op, then we definitely can't encode
23058 this using GDB's address_class enum. This is valid for partial
23059 global symbols, although the variable's address will be bogus
23063 if (computed
== nullptr)
23064 dwarf2_complex_location_expr_complaint ();
23070 case DW_OP_GNU_push_tls_address
:
23071 case DW_OP_form_tls_address
:
23072 /* The top of the stack has the offset from the beginning
23073 of the thread control block at which the variable is located. */
23074 /* Nothing should follow this operator, so the top of stack would
23076 /* This is valid for partial global symbols, but the variable's
23077 address will be bogus in the psymtab. Make it always at least
23078 non-zero to not look as a variable garbage collected by linker
23079 which have DW_OP_addr 0. */
23082 if (computed
== nullptr)
23083 dwarf2_complex_location_expr_complaint ();
23090 case DW_OP_GNU_uninit
:
23091 if (computed
!= nullptr)
23096 case DW_OP_GNU_addr_index
:
23097 case DW_OP_GNU_const_index
:
23098 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23104 if (computed
== nullptr)
23106 const char *name
= get_DW_OP_name (op
);
23109 complaint (_("unsupported stack op: '%s'"),
23112 complaint (_("unsupported stack op: '%02x'"),
23116 return (stack
[stacki
]);
23119 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23120 outside of the allocated space. Also enforce minimum>0. */
23121 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23123 if (computed
== nullptr)
23124 complaint (_("location description stack overflow"));
23130 if (computed
== nullptr)
23131 complaint (_("location description stack underflow"));
23136 if (computed
!= nullptr)
23138 return (stack
[stacki
]);
23141 /* memory allocation interface */
23143 static struct dwarf_block
*
23144 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23146 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23149 static struct die_info
*
23150 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23152 struct die_info
*die
;
23153 size_t size
= sizeof (struct die_info
);
23156 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23158 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23159 memset (die
, 0, sizeof (struct die_info
));
23165 /* Macro support. */
23167 /* An overload of dwarf_decode_macros that finds the correct section
23168 and ensures it is read in before calling the other overload. */
23171 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23172 int section_is_gnu
)
23174 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23175 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23176 const struct line_header
*lh
= cu
->line_header
;
23177 unsigned int offset_size
= cu
->header
.offset_size
;
23178 struct dwarf2_section_info
*section
;
23179 const char *section_name
;
23181 if (cu
->dwo_unit
!= nullptr)
23183 if (section_is_gnu
)
23185 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23186 section_name
= ".debug_macro.dwo";
23190 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23191 section_name
= ".debug_macinfo.dwo";
23196 if (section_is_gnu
)
23198 section
= &dwarf2_per_objfile
->per_bfd
->macro
;
23199 section_name
= ".debug_macro";
23203 section
= &dwarf2_per_objfile
->per_bfd
->macinfo
;
23204 section_name
= ".debug_macinfo";
23208 section
->read (objfile
);
23209 if (section
->buffer
== nullptr)
23211 complaint (_("missing %s section"), section_name
);
23215 buildsym_compunit
*builder
= cu
->get_builder ();
23217 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23218 offset_size
, offset
, section_is_gnu
);
23221 /* Return the .debug_loc section to use for CU.
23222 For DWO files use .debug_loc.dwo. */
23224 static struct dwarf2_section_info
*
23225 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23227 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23231 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23233 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23235 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->per_bfd
->loclists
23236 : &dwarf2_per_objfile
->per_bfd
->loc
);
23239 /* A helper function that fills in a dwarf2_loclist_baton. */
23242 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23243 struct dwarf2_loclist_baton
*baton
,
23244 const struct attribute
*attr
)
23246 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23247 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23249 section
->read (dwarf2_per_objfile
->objfile
);
23251 baton
->per_objfile
= dwarf2_per_objfile
;
23252 baton
->per_cu
= cu
->per_cu
;
23253 gdb_assert (baton
->per_cu
);
23254 /* We don't know how long the location list is, but make sure we
23255 don't run off the edge of the section. */
23256 baton
->size
= section
->size
- DW_UNSND (attr
);
23257 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23258 if (cu
->base_address
.has_value ())
23259 baton
->base_address
= *cu
->base_address
;
23261 baton
->base_address
= 0;
23262 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23266 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23267 struct dwarf2_cu
*cu
, int is_block
)
23269 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23270 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23271 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23273 if (attr
->form_is_section_offset ()
23274 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23275 the section. If so, fall through to the complaint in the
23277 && DW_UNSND (attr
) < section
->get_size (objfile
))
23279 struct dwarf2_loclist_baton
*baton
;
23281 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23283 fill_in_loclist_baton (cu
, baton
, attr
);
23285 if (!cu
->base_address
.has_value ())
23286 complaint (_("Location list used without "
23287 "specifying the CU base address."));
23289 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23290 ? dwarf2_loclist_block_index
23291 : dwarf2_loclist_index
);
23292 SYMBOL_LOCATION_BATON (sym
) = baton
;
23296 struct dwarf2_locexpr_baton
*baton
;
23298 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23299 baton
->per_objfile
= dwarf2_per_objfile
;
23300 baton
->per_cu
= cu
->per_cu
;
23301 gdb_assert (baton
->per_cu
);
23303 if (attr
->form_is_block ())
23305 /* Note that we're just copying the block's data pointer
23306 here, not the actual data. We're still pointing into the
23307 info_buffer for SYM's objfile; right now we never release
23308 that buffer, but when we do clean up properly this may
23310 baton
->size
= DW_BLOCK (attr
)->size
;
23311 baton
->data
= DW_BLOCK (attr
)->data
;
23315 dwarf2_invalid_attrib_class_complaint ("location description",
23316 sym
->natural_name ());
23320 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23321 ? dwarf2_locexpr_block_index
23322 : dwarf2_locexpr_index
);
23323 SYMBOL_LOCATION_BATON (sym
) = baton
;
23327 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
23328 (CU_HEADERP is unused in such case) or prepare a temporary copy at
23329 CU_HEADERP first. */
23331 static const struct comp_unit_head
*
23332 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
23333 const struct dwarf2_per_cu_data
*per_cu
)
23335 const gdb_byte
*info_ptr
;
23338 return &per_cu
->cu
->header
;
23340 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
23342 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
23343 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
23344 rcuh_kind::COMPILE
);
23352 dwarf2_per_cu_data::addr_size () const
23354 struct comp_unit_head cu_header_local
;
23355 const struct comp_unit_head
*cu_headerp
;
23357 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23359 return cu_headerp
->addr_size
;
23365 dwarf2_per_cu_data::offset_size () const
23367 struct comp_unit_head cu_header_local
;
23368 const struct comp_unit_head
*cu_headerp
;
23370 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23372 return cu_headerp
->offset_size
;
23378 dwarf2_per_cu_data::ref_addr_size () const
23380 struct comp_unit_head cu_header_local
;
23381 const struct comp_unit_head
*cu_headerp
;
23383 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23385 if (cu_headerp
->version
== 2)
23386 return cu_headerp
->addr_size
;
23388 return cu_headerp
->offset_size
;
23394 dwarf2_cu::addr_type () const
23396 struct objfile
*objfile
= this->per_objfile
->objfile
;
23397 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23398 struct type
*addr_type
= lookup_pointer_type (void_type
);
23399 int addr_size
= this->per_cu
->addr_size ();
23401 if (TYPE_LENGTH (addr_type
) == addr_size
)
23404 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23408 /* A helper function for dwarf2_find_containing_comp_unit that returns
23409 the index of the result, and that searches a vector. It will
23410 return a result even if the offset in question does not actually
23411 occur in any CU. This is separate so that it can be unit
23415 dwarf2_find_containing_comp_unit
23416 (sect_offset sect_off
,
23417 unsigned int offset_in_dwz
,
23418 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23423 high
= all_comp_units
.size () - 1;
23426 struct dwarf2_per_cu_data
*mid_cu
;
23427 int mid
= low
+ (high
- low
) / 2;
23429 mid_cu
= all_comp_units
[mid
];
23430 if (mid_cu
->is_dwz
> offset_in_dwz
23431 || (mid_cu
->is_dwz
== offset_in_dwz
23432 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23437 gdb_assert (low
== high
);
23441 /* Locate the .debug_info compilation unit from CU's objfile which contains
23442 the DIE at OFFSET. Raises an error on failure. */
23444 static struct dwarf2_per_cu_data
*
23445 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23446 unsigned int offset_in_dwz
,
23447 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23450 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23451 dwarf2_per_objfile
->per_bfd
->all_comp_units
);
23452 struct dwarf2_per_cu_data
*this_cu
23453 = dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
];
23455 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23457 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23458 error (_("Dwarf Error: could not find partial DIE containing "
23459 "offset %s [in module %s]"),
23460 sect_offset_str (sect_off
),
23461 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23463 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23465 return dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1];
23469 if (low
== dwarf2_per_objfile
->per_bfd
->all_comp_units
.size () - 1
23470 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23471 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23472 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23479 namespace selftests
{
23480 namespace find_containing_comp_unit
{
23485 struct dwarf2_per_cu_data one
{};
23486 struct dwarf2_per_cu_data two
{};
23487 struct dwarf2_per_cu_data three
{};
23488 struct dwarf2_per_cu_data four
{};
23491 two
.sect_off
= sect_offset (one
.length
);
23496 four
.sect_off
= sect_offset (three
.length
);
23500 std::vector
<dwarf2_per_cu_data
*> units
;
23501 units
.push_back (&one
);
23502 units
.push_back (&two
);
23503 units
.push_back (&three
);
23504 units
.push_back (&four
);
23508 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23509 SELF_CHECK (units
[result
] == &one
);
23510 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23511 SELF_CHECK (units
[result
] == &one
);
23512 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23513 SELF_CHECK (units
[result
] == &two
);
23515 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23516 SELF_CHECK (units
[result
] == &three
);
23517 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23518 SELF_CHECK (units
[result
] == &three
);
23519 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23520 SELF_CHECK (units
[result
] == &four
);
23526 #endif /* GDB_SELF_TEST */
23528 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23530 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23531 dwarf2_per_objfile
*per_objfile
)
23533 per_objfile (per_objfile
),
23535 has_loclist (false),
23536 checked_producer (false),
23537 producer_is_gxx_lt_4_6 (false),
23538 producer_is_gcc_lt_4_3 (false),
23539 producer_is_icc (false),
23540 producer_is_icc_lt_14 (false),
23541 producer_is_codewarrior (false),
23542 processing_has_namespace_info (false)
23547 /* Destroy a dwarf2_cu. */
23549 dwarf2_cu::~dwarf2_cu ()
23554 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23557 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23558 enum language pretend_language
)
23560 struct attribute
*attr
;
23562 /* Set the language we're debugging. */
23563 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23564 if (attr
!= nullptr)
23565 set_cu_language (DW_UNSND (attr
), cu
);
23568 cu
->language
= pretend_language
;
23569 cu
->language_defn
= language_def (cu
->language
);
23572 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23575 /* Increase the age counter on each cached compilation unit, and free
23576 any that are too old. */
23579 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23581 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23583 dwarf2_clear_marks (dwarf2_per_objfile
->per_bfd
->read_in_chain
);
23584 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23585 while (per_cu
!= NULL
)
23587 per_cu
->cu
->last_used
++;
23588 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23589 dwarf2_mark (per_cu
->cu
);
23590 per_cu
= per_cu
->cu
->read_in_chain
;
23593 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23594 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23595 while (per_cu
!= NULL
)
23597 struct dwarf2_per_cu_data
*next_cu
;
23599 next_cu
= per_cu
->cu
->read_in_chain
;
23601 if (!per_cu
->cu
->mark
)
23604 *last_chain
= next_cu
;
23607 last_chain
= &per_cu
->cu
->read_in_chain
;
23613 /* Remove a single compilation unit from the cache. */
23616 free_one_cached_comp_unit (dwarf2_per_cu_data
*target_per_cu
,
23617 dwarf2_per_objfile
*dwarf2_per_objfile
)
23619 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23621 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23622 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23623 while (per_cu
!= NULL
)
23625 struct dwarf2_per_cu_data
*next_cu
;
23627 next_cu
= per_cu
->cu
->read_in_chain
;
23629 if (per_cu
== target_per_cu
)
23633 *last_chain
= next_cu
;
23637 last_chain
= &per_cu
->cu
->read_in_chain
;
23643 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23644 We store these in a hash table separate from the DIEs, and preserve them
23645 when the DIEs are flushed out of cache.
23647 The CU "per_cu" pointer is needed because offset alone is not enough to
23648 uniquely identify the type. A file may have multiple .debug_types sections,
23649 or the type may come from a DWO file. Furthermore, while it's more logical
23650 to use per_cu->section+offset, with Fission the section with the data is in
23651 the DWO file but we don't know that section at the point we need it.
23652 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23653 because we can enter the lookup routine, get_die_type_at_offset, from
23654 outside this file, and thus won't necessarily have PER_CU->cu.
23655 Fortunately, PER_CU is stable for the life of the objfile. */
23657 struct dwarf2_per_cu_offset_and_type
23659 const struct dwarf2_per_cu_data
*per_cu
;
23660 sect_offset sect_off
;
23664 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23667 per_cu_offset_and_type_hash (const void *item
)
23669 const struct dwarf2_per_cu_offset_and_type
*ofs
23670 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23672 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23675 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23678 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23680 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23681 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23682 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23683 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23685 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23686 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23689 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23690 table if necessary. For convenience, return TYPE.
23692 The DIEs reading must have careful ordering to:
23693 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23694 reading current DIE.
23695 * Not trying to dereference contents of still incompletely read in types
23696 while reading in other DIEs.
23697 * Enable referencing still incompletely read in types just by a pointer to
23698 the type without accessing its fields.
23700 Therefore caller should follow these rules:
23701 * Try to fetch any prerequisite types we may need to build this DIE type
23702 before building the type and calling set_die_type.
23703 * After building type call set_die_type for current DIE as soon as
23704 possible before fetching more types to complete the current type.
23705 * Make the type as complete as possible before fetching more types. */
23707 static struct type
*
23708 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23710 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23711 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23712 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23713 struct attribute
*attr
;
23714 struct dynamic_prop prop
;
23716 /* For Ada types, make sure that the gnat-specific data is always
23717 initialized (if not already set). There are a few types where
23718 we should not be doing so, because the type-specific area is
23719 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23720 where the type-specific area is used to store the floatformat).
23721 But this is not a problem, because the gnat-specific information
23722 is actually not needed for these types. */
23723 if (need_gnat_info (cu
)
23724 && type
->code () != TYPE_CODE_FUNC
23725 && type
->code () != TYPE_CODE_FLT
23726 && type
->code () != TYPE_CODE_METHODPTR
23727 && type
->code () != TYPE_CODE_MEMBERPTR
23728 && type
->code () != TYPE_CODE_METHOD
23729 && !HAVE_GNAT_AUX_INFO (type
))
23730 INIT_GNAT_SPECIFIC (type
);
23732 /* Read DW_AT_allocated and set in type. */
23733 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23734 if (attr
!= NULL
&& attr
->form_is_block ())
23736 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23737 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23738 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23740 else if (attr
!= NULL
)
23742 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23743 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23744 sect_offset_str (die
->sect_off
));
23747 /* Read DW_AT_associated and set in type. */
23748 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23749 if (attr
!= NULL
&& attr
->form_is_block ())
23751 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23752 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23753 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23755 else if (attr
!= NULL
)
23757 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23758 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23759 sect_offset_str (die
->sect_off
));
23762 /* Read DW_AT_data_location and set in type. */
23763 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23764 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23765 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23767 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23768 dwarf2_per_objfile
->die_type_hash
23769 = htab_up (htab_create_alloc (127,
23770 per_cu_offset_and_type_hash
,
23771 per_cu_offset_and_type_eq
,
23772 NULL
, xcalloc
, xfree
));
23774 ofs
.per_cu
= cu
->per_cu
;
23775 ofs
.sect_off
= die
->sect_off
;
23777 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23778 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23780 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23781 sect_offset_str (die
->sect_off
));
23782 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23783 struct dwarf2_per_cu_offset_and_type
);
23788 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23789 or return NULL if the die does not have a saved type. */
23791 static struct type
*
23792 get_die_type_at_offset (sect_offset sect_off
,
23793 dwarf2_per_cu_data
*per_cu
,
23794 dwarf2_per_objfile
*dwarf2_per_objfile
)
23796 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23798 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23801 ofs
.per_cu
= per_cu
;
23802 ofs
.sect_off
= sect_off
;
23803 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23804 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23811 /* Look up the type for DIE in CU in die_type_hash,
23812 or return NULL if DIE does not have a saved type. */
23814 static struct type
*
23815 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23817 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
23820 /* Add a dependence relationship from CU to REF_PER_CU. */
23823 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23824 struct dwarf2_per_cu_data
*ref_per_cu
)
23828 if (cu
->dependencies
== NULL
)
23830 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23831 NULL
, &cu
->comp_unit_obstack
,
23832 hashtab_obstack_allocate
,
23833 dummy_obstack_deallocate
);
23835 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23837 *slot
= ref_per_cu
;
23840 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23841 Set the mark field in every compilation unit in the
23842 cache that we must keep because we are keeping CU. */
23845 dwarf2_mark_helper (void **slot
, void *data
)
23847 struct dwarf2_per_cu_data
*per_cu
;
23849 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23851 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23852 reading of the chain. As such dependencies remain valid it is not much
23853 useful to track and undo them during QUIT cleanups. */
23854 if (per_cu
->cu
== NULL
)
23857 if (per_cu
->cu
->mark
)
23859 per_cu
->cu
->mark
= true;
23861 if (per_cu
->cu
->dependencies
!= NULL
)
23862 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23867 /* Set the mark field in CU and in every other compilation unit in the
23868 cache that we must keep because we are keeping CU. */
23871 dwarf2_mark (struct dwarf2_cu
*cu
)
23876 if (cu
->dependencies
!= NULL
)
23877 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23881 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23885 per_cu
->cu
->mark
= false;
23886 per_cu
= per_cu
->cu
->read_in_chain
;
23890 /* Trivial hash function for partial_die_info: the hash value of a DIE
23891 is its offset in .debug_info for this objfile. */
23894 partial_die_hash (const void *item
)
23896 const struct partial_die_info
*part_die
23897 = (const struct partial_die_info
*) item
;
23899 return to_underlying (part_die
->sect_off
);
23902 /* Trivial comparison function for partial_die_info structures: two DIEs
23903 are equal if they have the same offset. */
23906 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23908 const struct partial_die_info
*part_die_lhs
23909 = (const struct partial_die_info
*) item_lhs
;
23910 const struct partial_die_info
*part_die_rhs
23911 = (const struct partial_die_info
*) item_rhs
;
23913 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23916 struct cmd_list_element
*set_dwarf_cmdlist
;
23917 struct cmd_list_element
*show_dwarf_cmdlist
;
23920 show_check_physname (struct ui_file
*file
, int from_tty
,
23921 struct cmd_list_element
*c
, const char *value
)
23923 fprintf_filtered (file
,
23924 _("Whether to check \"physname\" is %s.\n"),
23928 void _initialize_dwarf2_read ();
23930 _initialize_dwarf2_read ()
23932 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
23933 Set DWARF specific variables.\n\
23934 Configure DWARF variables such as the cache size."),
23935 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23936 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23938 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
23939 Show DWARF specific variables.\n\
23940 Show DWARF variables such as the cache size."),
23941 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23942 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23944 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23945 &dwarf_max_cache_age
, _("\
23946 Set the upper bound on the age of cached DWARF compilation units."), _("\
23947 Show the upper bound on the age of cached DWARF compilation units."), _("\
23948 A higher limit means that cached compilation units will be stored\n\
23949 in memory longer, and more total memory will be used. Zero disables\n\
23950 caching, which can slow down startup."),
23952 show_dwarf_max_cache_age
,
23953 &set_dwarf_cmdlist
,
23954 &show_dwarf_cmdlist
);
23956 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23957 Set debugging of the DWARF reader."), _("\
23958 Show debugging of the DWARF reader."), _("\
23959 When enabled (non-zero), debugging messages are printed during DWARF\n\
23960 reading and symtab expansion. A value of 1 (one) provides basic\n\
23961 information. A value greater than 1 provides more verbose information."),
23964 &setdebuglist
, &showdebuglist
);
23966 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23967 Set debugging of the DWARF DIE reader."), _("\
23968 Show debugging of the DWARF DIE reader."), _("\
23969 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23970 The value is the maximum depth to print."),
23973 &setdebuglist
, &showdebuglist
);
23975 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23976 Set debugging of the dwarf line reader."), _("\
23977 Show debugging of the dwarf line reader."), _("\
23978 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23979 A value of 1 (one) provides basic information.\n\
23980 A value greater than 1 provides more verbose information."),
23983 &setdebuglist
, &showdebuglist
);
23985 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23986 Set cross-checking of \"physname\" code against demangler."), _("\
23987 Show cross-checking of \"physname\" code against demangler."), _("\
23988 When enabled, GDB's internal \"physname\" code is checked against\n\
23990 NULL
, show_check_physname
,
23991 &setdebuglist
, &showdebuglist
);
23993 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23994 no_class
, &use_deprecated_index_sections
, _("\
23995 Set whether to use deprecated gdb_index sections."), _("\
23996 Show whether to use deprecated gdb_index sections."), _("\
23997 When enabled, deprecated .gdb_index sections are used anyway.\n\
23998 Normally they are ignored either because of a missing feature or\n\
23999 performance issue.\n\
24000 Warning: This option must be enabled before gdb reads the file."),
24003 &setlist
, &showlist
);
24005 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24006 &dwarf2_locexpr_funcs
);
24007 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24008 &dwarf2_loclist_funcs
);
24010 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24011 &dwarf2_block_frame_base_locexpr_funcs
);
24012 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24013 &dwarf2_block_frame_base_loclist_funcs
);
24016 selftests::register_test ("dw2_expand_symtabs_matching",
24017 selftests::dw2_expand_symtabs_matching::run_test
);
24018 selftests::register_test ("dwarf2_find_containing_comp_unit",
24019 selftests::find_containing_comp_unit::run_test
);