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 (struct dwarf2_per_cu_data
*per_cu
);
405 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
407 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
408 Create the set of symtabs used by this TU, or if this TU is sharing
409 symtabs with another TU and the symtabs have already been created
410 then restore those symtabs in the line header.
411 We don't need the pc/line-number mapping for type units. */
412 void setup_type_unit_groups (struct die_info
*die
);
414 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
415 buildsym_compunit constructor. */
416 struct compunit_symtab
*start_symtab (const char *name
,
417 const char *comp_dir
,
420 /* Reset the builder. */
421 void reset_builder () { m_builder
.reset (); }
423 /* The header of the compilation unit. */
424 struct comp_unit_head header
{};
426 /* Base address of this compilation unit. */
427 gdb::optional
<CORE_ADDR
> base_address
;
429 /* The language we are debugging. */
430 enum language language
= language_unknown
;
431 const struct language_defn
*language_defn
= nullptr;
433 const char *producer
= nullptr;
436 /* The symtab builder for this CU. This is only non-NULL when full
437 symbols are being read. */
438 std::unique_ptr
<buildsym_compunit
> m_builder
;
441 /* The generic symbol table building routines have separate lists for
442 file scope symbols and all all other scopes (local scopes). So
443 we need to select the right one to pass to add_symbol_to_list().
444 We do it by keeping a pointer to the correct list in list_in_scope.
446 FIXME: The original dwarf code just treated the file scope as the
447 first local scope, and all other local scopes as nested local
448 scopes, and worked fine. Check to see if we really need to
449 distinguish these in buildsym.c. */
450 struct pending
**list_in_scope
= nullptr;
452 /* Hash table holding all the loaded partial DIEs
453 with partial_die->offset.SECT_OFF as hash. */
454 htab_t partial_dies
= nullptr;
456 /* Storage for things with the same lifetime as this read-in compilation
457 unit, including partial DIEs. */
458 auto_obstack comp_unit_obstack
;
460 /* When multiple dwarf2_cu structures are living in memory, this field
461 chains them all together, so that they can be released efficiently.
462 We will probably also want a generation counter so that most-recently-used
463 compilation units are cached... */
464 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
466 /* Backlink to our per_cu entry. */
467 struct dwarf2_per_cu_data
*per_cu
;
469 /* How many compilation units ago was this CU last referenced? */
472 /* A hash table of DIE cu_offset for following references with
473 die_info->offset.sect_off as hash. */
474 htab_t die_hash
= nullptr;
476 /* Full DIEs if read in. */
477 struct die_info
*dies
= nullptr;
479 /* A set of pointers to dwarf2_per_cu_data objects for compilation
480 units referenced by this one. Only set during full symbol processing;
481 partial symbol tables do not have dependencies. */
482 htab_t dependencies
= nullptr;
484 /* Header data from the line table, during full symbol processing. */
485 struct line_header
*line_header
= nullptr;
486 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
487 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
488 this is the DW_TAG_compile_unit die for this CU. We'll hold on
489 to the line header as long as this DIE is being processed. See
490 process_die_scope. */
491 die_info
*line_header_die_owner
= nullptr;
493 /* A list of methods which need to have physnames computed
494 after all type information has been read. */
495 std::vector
<delayed_method_info
> method_list
;
497 /* To be copied to symtab->call_site_htab. */
498 htab_t call_site_htab
= nullptr;
500 /* Non-NULL if this CU came from a DWO file.
501 There is an invariant here that is important to remember:
502 Except for attributes copied from the top level DIE in the "main"
503 (or "stub") file in preparation for reading the DWO file
504 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
505 Either there isn't a DWO file (in which case this is NULL and the point
506 is moot), or there is and either we're not going to read it (in which
507 case this is NULL) or there is and we are reading it (in which case this
509 struct dwo_unit
*dwo_unit
= nullptr;
511 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
512 Note this value comes from the Fission stub CU/TU's DIE. */
513 gdb::optional
<ULONGEST
> addr_base
;
515 /* The DW_AT_rnglists_base attribute if present.
516 Note this value comes from the Fission stub CU/TU's DIE.
517 Also note that the value is zero in the non-DWO case so this value can
518 be used without needing to know whether DWO files are in use or not.
519 N.B. This does not apply to DW_AT_ranges appearing in
520 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
521 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
522 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
523 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
524 ULONGEST ranges_base
= 0;
526 /* The DW_AT_loclists_base attribute if present. */
527 ULONGEST loclist_base
= 0;
529 /* When reading debug info generated by older versions of rustc, we
530 have to rewrite some union types to be struct types with a
531 variant part. This rewriting must be done after the CU is fully
532 read in, because otherwise at the point of rewriting some struct
533 type might not have been fully processed. So, we keep a list of
534 all such types here and process them after expansion. */
535 std::vector
<struct type
*> rust_unions
;
537 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
538 files, the value is implicitly zero. For DWARF 5 version DWO files, the
539 value is often implicit and is the size of the header of
540 .debug_str_offsets section (8 or 4, depending on the address size). */
541 gdb::optional
<ULONGEST
> str_offsets_base
;
543 /* Mark used when releasing cached dies. */
546 /* This CU references .debug_loc. See the symtab->locations_valid field.
547 This test is imperfect as there may exist optimized debug code not using
548 any location list and still facing inlining issues if handled as
549 unoptimized code. For a future better test see GCC PR other/32998. */
550 bool has_loclist
: 1;
552 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
553 if all the producer_is_* fields are valid. This information is cached
554 because profiling CU expansion showed excessive time spent in
555 producer_is_gxx_lt_4_6. */
556 bool checked_producer
: 1;
557 bool producer_is_gxx_lt_4_6
: 1;
558 bool producer_is_gcc_lt_4_3
: 1;
559 bool producer_is_icc
: 1;
560 bool producer_is_icc_lt_14
: 1;
561 bool producer_is_codewarrior
: 1;
563 /* When true, the file that we're processing is known to have
564 debugging info for C++ namespaces. GCC 3.3.x did not produce
565 this information, but later versions do. */
567 bool processing_has_namespace_info
: 1;
569 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
571 /* If this CU was inherited by another CU (via specification,
572 abstract_origin, etc), this is the ancestor CU. */
575 /* Get the buildsym_compunit for this CU. */
576 buildsym_compunit
*get_builder ()
578 /* If this CU has a builder associated with it, use that. */
579 if (m_builder
!= nullptr)
580 return m_builder
.get ();
582 /* Otherwise, search ancestors for a valid builder. */
583 if (ancestor
!= nullptr)
584 return ancestor
->get_builder ();
590 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
591 This includes type_unit_group and quick_file_names. */
593 struct stmt_list_hash
595 /* The DWO unit this table is from or NULL if there is none. */
596 struct dwo_unit
*dwo_unit
;
598 /* Offset in .debug_line or .debug_line.dwo. */
599 sect_offset line_sect_off
;
602 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
603 an object of this type. */
605 struct type_unit_group
607 /* dwarf2read.c's main "handle" on a TU symtab.
608 To simplify things we create an artificial CU that "includes" all the
609 type units using this stmt_list so that the rest of the code still has
610 a "per_cu" handle on the symtab. */
611 struct dwarf2_per_cu_data per_cu
;
613 /* The TUs that share this DW_AT_stmt_list entry.
614 This is added to while parsing type units to build partial symtabs,
615 and is deleted afterwards and not used again. */
616 std::vector
<signatured_type
*> *tus
;
618 /* The compunit symtab.
619 Type units in a group needn't all be defined in the same source file,
620 so we create an essentially anonymous symtab as the compunit symtab. */
621 struct compunit_symtab
*compunit_symtab
;
623 /* The data used to construct the hash key. */
624 struct stmt_list_hash hash
;
626 /* The symbol tables for this TU (obtained from the files listed in
628 WARNING: The order of entries here must match the order of entries
629 in the line header. After the first TU using this type_unit_group, the
630 line header for the subsequent TUs is recreated from this. This is done
631 because we need to use the same symtabs for each TU using the same
632 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
633 there's no guarantee the line header doesn't have duplicate entries. */
634 struct symtab
**symtabs
;
637 /* These sections are what may appear in a (real or virtual) DWO file. */
641 struct dwarf2_section_info abbrev
;
642 struct dwarf2_section_info line
;
643 struct dwarf2_section_info loc
;
644 struct dwarf2_section_info loclists
;
645 struct dwarf2_section_info macinfo
;
646 struct dwarf2_section_info macro
;
647 struct dwarf2_section_info str
;
648 struct dwarf2_section_info str_offsets
;
649 /* In the case of a virtual DWO file, these two are unused. */
650 struct dwarf2_section_info info
;
651 std::vector
<dwarf2_section_info
> types
;
654 /* CUs/TUs in DWP/DWO files. */
658 /* Backlink to the containing struct dwo_file. */
659 struct dwo_file
*dwo_file
;
661 /* The "id" that distinguishes this CU/TU.
662 .debug_info calls this "dwo_id", .debug_types calls this "signature".
663 Since signatures came first, we stick with it for consistency. */
666 /* The section this CU/TU lives in, in the DWO file. */
667 struct dwarf2_section_info
*section
;
669 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
670 sect_offset sect_off
;
673 /* For types, offset in the type's DIE of the type defined by this TU. */
674 cu_offset type_offset_in_tu
;
677 /* include/dwarf2.h defines the DWP section codes.
678 It defines a max value but it doesn't define a min value, which we
679 use for error checking, so provide one. */
681 enum dwp_v2_section_ids
686 /* Data for one DWO file.
688 This includes virtual DWO files (a virtual DWO file is a DWO file as it
689 appears in a DWP file). DWP files don't really have DWO files per se -
690 comdat folding of types "loses" the DWO file they came from, and from
691 a high level view DWP files appear to contain a mass of random types.
692 However, to maintain consistency with the non-DWP case we pretend DWP
693 files contain virtual DWO files, and we assign each TU with one virtual
694 DWO file (generally based on the line and abbrev section offsets -
695 a heuristic that seems to work in practice). */
699 dwo_file () = default;
700 DISABLE_COPY_AND_ASSIGN (dwo_file
);
702 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
703 For virtual DWO files the name is constructed from the section offsets
704 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
705 from related CU+TUs. */
706 const char *dwo_name
= nullptr;
708 /* The DW_AT_comp_dir attribute. */
709 const char *comp_dir
= nullptr;
711 /* The bfd, when the file is open. Otherwise this is NULL.
712 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
713 gdb_bfd_ref_ptr dbfd
;
715 /* The sections that make up this DWO file.
716 Remember that for virtual DWO files in DWP V2, these are virtual
717 sections (for lack of a better name). */
718 struct dwo_sections sections
{};
720 /* The CUs in the file.
721 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
722 an extension to handle LLVM's Link Time Optimization output (where
723 multiple source files may be compiled into a single object/dwo pair). */
726 /* Table of TUs in the file.
727 Each element is a struct dwo_unit. */
731 /* These sections are what may appear in a DWP file. */
735 /* These are used by both DWP version 1 and 2. */
736 struct dwarf2_section_info str
;
737 struct dwarf2_section_info cu_index
;
738 struct dwarf2_section_info tu_index
;
740 /* These are only used by DWP version 2 files.
741 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
742 sections are referenced by section number, and are not recorded here.
743 In DWP version 2 there is at most one copy of all these sections, each
744 section being (effectively) comprised of the concatenation of all of the
745 individual sections that exist in the version 1 format.
746 To keep the code simple we treat each of these concatenated pieces as a
747 section itself (a virtual section?). */
748 struct dwarf2_section_info abbrev
;
749 struct dwarf2_section_info info
;
750 struct dwarf2_section_info line
;
751 struct dwarf2_section_info loc
;
752 struct dwarf2_section_info macinfo
;
753 struct dwarf2_section_info macro
;
754 struct dwarf2_section_info str_offsets
;
755 struct dwarf2_section_info types
;
758 /* These sections are what may appear in a virtual DWO file in DWP version 1.
759 A virtual DWO file is a DWO file as it appears in a DWP file. */
761 struct virtual_v1_dwo_sections
763 struct dwarf2_section_info abbrev
;
764 struct dwarf2_section_info line
;
765 struct dwarf2_section_info loc
;
766 struct dwarf2_section_info macinfo
;
767 struct dwarf2_section_info macro
;
768 struct dwarf2_section_info str_offsets
;
769 /* Each DWP hash table entry records one CU or one TU.
770 That is recorded here, and copied to dwo_unit.section. */
771 struct dwarf2_section_info info_or_types
;
774 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
775 In version 2, the sections of the DWO files are concatenated together
776 and stored in one section of that name. Thus each ELF section contains
777 several "virtual" sections. */
779 struct virtual_v2_dwo_sections
781 bfd_size_type abbrev_offset
;
782 bfd_size_type abbrev_size
;
784 bfd_size_type line_offset
;
785 bfd_size_type line_size
;
787 bfd_size_type loc_offset
;
788 bfd_size_type loc_size
;
790 bfd_size_type macinfo_offset
;
791 bfd_size_type macinfo_size
;
793 bfd_size_type macro_offset
;
794 bfd_size_type macro_size
;
796 bfd_size_type str_offsets_offset
;
797 bfd_size_type str_offsets_size
;
799 /* Each DWP hash table entry records one CU or one TU.
800 That is recorded here, and copied to dwo_unit.section. */
801 bfd_size_type info_or_types_offset
;
802 bfd_size_type info_or_types_size
;
805 /* Contents of DWP hash tables. */
807 struct dwp_hash_table
809 uint32_t version
, nr_columns
;
810 uint32_t nr_units
, nr_slots
;
811 const gdb_byte
*hash_table
, *unit_table
;
816 const gdb_byte
*indices
;
820 /* This is indexed by column number and gives the id of the section
822 #define MAX_NR_V2_DWO_SECTIONS \
823 (1 /* .debug_info or .debug_types */ \
824 + 1 /* .debug_abbrev */ \
825 + 1 /* .debug_line */ \
826 + 1 /* .debug_loc */ \
827 + 1 /* .debug_str_offsets */ \
828 + 1 /* .debug_macro or .debug_macinfo */)
829 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
830 const gdb_byte
*offsets
;
831 const gdb_byte
*sizes
;
836 /* Data for one DWP file. */
840 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
842 dbfd (std::move (abfd
))
846 /* Name of the file. */
849 /* File format version. */
853 gdb_bfd_ref_ptr dbfd
;
855 /* Section info for this file. */
856 struct dwp_sections sections
{};
858 /* Table of CUs in the file. */
859 const struct dwp_hash_table
*cus
= nullptr;
861 /* Table of TUs in the file. */
862 const struct dwp_hash_table
*tus
= nullptr;
864 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
868 /* Table to map ELF section numbers to their sections.
869 This is only needed for the DWP V1 file format. */
870 unsigned int num_sections
= 0;
871 asection
**elf_sections
= nullptr;
874 /* Struct used to pass misc. parameters to read_die_and_children, et
875 al. which are used for both .debug_info and .debug_types dies.
876 All parameters here are unchanging for the life of the call. This
877 struct exists to abstract away the constant parameters of die reading. */
879 struct die_reader_specs
881 /* The bfd of die_section. */
884 /* The CU of the DIE we are parsing. */
885 struct dwarf2_cu
*cu
;
887 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
888 struct dwo_file
*dwo_file
;
890 /* The section the die comes from.
891 This is either .debug_info or .debug_types, or the .dwo variants. */
892 struct dwarf2_section_info
*die_section
;
894 /* die_section->buffer. */
895 const gdb_byte
*buffer
;
897 /* The end of the buffer. */
898 const gdb_byte
*buffer_end
;
900 /* The abbreviation table to use when reading the DIEs. */
901 struct abbrev_table
*abbrev_table
;
904 /* A subclass of die_reader_specs that holds storage and has complex
905 constructor and destructor behavior. */
907 class cutu_reader
: public die_reader_specs
911 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
912 struct abbrev_table
*abbrev_table
,
916 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
917 struct dwarf2_cu
*parent_cu
= nullptr,
918 struct dwo_file
*dwo_file
= nullptr);
920 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
922 const gdb_byte
*info_ptr
= nullptr;
923 struct die_info
*comp_unit_die
= nullptr;
924 bool dummy_p
= false;
926 /* Release the new CU, putting it on the chain. This cannot be done
931 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
932 int use_existing_cu
);
934 struct dwarf2_per_cu_data
*m_this_cu
;
935 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
937 /* The ordinary abbreviation table. */
938 abbrev_table_up m_abbrev_table_holder
;
940 /* The DWO abbreviation table. */
941 abbrev_table_up m_dwo_abbrev_table
;
944 /* When we construct a partial symbol table entry we only
945 need this much information. */
946 struct partial_die_info
: public allocate_on_obstack
948 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
950 /* Disable assign but still keep copy ctor, which is needed
951 load_partial_dies. */
952 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
954 /* Adjust the partial die before generating a symbol for it. This
955 function may set the is_external flag or change the DIE's
957 void fixup (struct dwarf2_cu
*cu
);
959 /* Read a minimal amount of information into the minimal die
961 const gdb_byte
*read (const struct die_reader_specs
*reader
,
962 const struct abbrev_info
&abbrev
,
963 const gdb_byte
*info_ptr
);
965 /* Offset of this DIE. */
966 const sect_offset sect_off
;
968 /* DWARF-2 tag for this DIE. */
969 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
971 /* Assorted flags describing the data found in this DIE. */
972 const unsigned int has_children
: 1;
974 unsigned int is_external
: 1;
975 unsigned int is_declaration
: 1;
976 unsigned int has_type
: 1;
977 unsigned int has_specification
: 1;
978 unsigned int has_pc_info
: 1;
979 unsigned int may_be_inlined
: 1;
981 /* This DIE has been marked DW_AT_main_subprogram. */
982 unsigned int main_subprogram
: 1;
984 /* Flag set if the SCOPE field of this structure has been
986 unsigned int scope_set
: 1;
988 /* Flag set if the DIE has a byte_size attribute. */
989 unsigned int has_byte_size
: 1;
991 /* Flag set if the DIE has a DW_AT_const_value attribute. */
992 unsigned int has_const_value
: 1;
994 /* Flag set if any of the DIE's children are template arguments. */
995 unsigned int has_template_arguments
: 1;
997 /* Flag set if fixup has been called on this die. */
998 unsigned int fixup_called
: 1;
1000 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1001 unsigned int is_dwz
: 1;
1003 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1004 unsigned int spec_is_dwz
: 1;
1006 /* The name of this DIE. Normally the value of DW_AT_name, but
1007 sometimes a default name for unnamed DIEs. */
1008 const char *name
= nullptr;
1010 /* The linkage name, if present. */
1011 const char *linkage_name
= nullptr;
1013 /* The scope to prepend to our children. This is generally
1014 allocated on the comp_unit_obstack, so will disappear
1015 when this compilation unit leaves the cache. */
1016 const char *scope
= nullptr;
1018 /* Some data associated with the partial DIE. The tag determines
1019 which field is live. */
1022 /* The location description associated with this DIE, if any. */
1023 struct dwarf_block
*locdesc
;
1024 /* The offset of an import, for DW_TAG_imported_unit. */
1025 sect_offset sect_off
;
1028 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1029 CORE_ADDR lowpc
= 0;
1030 CORE_ADDR highpc
= 0;
1032 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1033 DW_AT_sibling, if any. */
1034 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1035 could return DW_AT_sibling values to its caller load_partial_dies. */
1036 const gdb_byte
*sibling
= nullptr;
1038 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1039 DW_AT_specification (or DW_AT_abstract_origin or
1040 DW_AT_extension). */
1041 sect_offset spec_offset
{};
1043 /* Pointers to this DIE's parent, first child, and next sibling,
1045 struct partial_die_info
*die_parent
= nullptr;
1046 struct partial_die_info
*die_child
= nullptr;
1047 struct partial_die_info
*die_sibling
= nullptr;
1049 friend struct partial_die_info
*
1050 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1053 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1054 partial_die_info (sect_offset sect_off
)
1055 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1059 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1061 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1066 has_specification
= 0;
1069 main_subprogram
= 0;
1072 has_const_value
= 0;
1073 has_template_arguments
= 0;
1080 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1081 but this would require a corresponding change in unpack_field_as_long
1083 static int bits_per_byte
= 8;
1085 struct variant_part_builder
;
1087 /* When reading a variant, we track a bit more information about the
1088 field, and store it in an object of this type. */
1090 struct variant_field
1092 int first_field
= -1;
1093 int last_field
= -1;
1095 /* A variant can contain other variant parts. */
1096 std::vector
<variant_part_builder
> variant_parts
;
1098 /* If we see a DW_TAG_variant, then this will be set if this is the
1100 bool default_branch
= false;
1101 /* If we see a DW_AT_discr_value, then this will be the discriminant
1103 ULONGEST discriminant_value
= 0;
1104 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1106 struct dwarf_block
*discr_list_data
= nullptr;
1109 /* This represents a DW_TAG_variant_part. */
1111 struct variant_part_builder
1113 /* The offset of the discriminant field. */
1114 sect_offset discriminant_offset
{};
1116 /* Variants that are direct children of this variant part. */
1117 std::vector
<variant_field
> variants
;
1119 /* True if we're currently reading a variant. */
1120 bool processing_variant
= false;
1125 int accessibility
= 0;
1127 /* Variant parts need to find the discriminant, which is a DIE
1128 reference. We track the section offset of each field to make
1131 struct field field
{};
1136 const char *name
= nullptr;
1137 std::vector
<struct fn_field
> fnfields
;
1140 /* The routines that read and process dies for a C struct or C++ class
1141 pass lists of data member fields and lists of member function fields
1142 in an instance of a field_info structure, as defined below. */
1145 /* List of data member and baseclasses fields. */
1146 std::vector
<struct nextfield
> fields
;
1147 std::vector
<struct nextfield
> baseclasses
;
1149 /* Set if the accessibility of one of the fields is not public. */
1150 int non_public_fields
= 0;
1152 /* Member function fieldlist array, contains name of possibly overloaded
1153 member function, number of overloaded member functions and a pointer
1154 to the head of the member function field chain. */
1155 std::vector
<struct fnfieldlist
> fnfieldlists
;
1157 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1158 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1159 std::vector
<struct decl_field
> typedef_field_list
;
1161 /* Nested types defined by this class and the number of elements in this
1163 std::vector
<struct decl_field
> nested_types_list
;
1165 /* If non-null, this is the variant part we are currently
1167 variant_part_builder
*current_variant_part
= nullptr;
1168 /* This holds all the top-level variant parts attached to the type
1170 std::vector
<variant_part_builder
> variant_parts
;
1172 /* Return the total number of fields (including baseclasses). */
1173 int nfields () const
1175 return fields
.size () + baseclasses
.size ();
1179 /* Loaded secondary compilation units are kept in memory until they
1180 have not been referenced for the processing of this many
1181 compilation units. Set this to zero to disable caching. Cache
1182 sizes of up to at least twenty will improve startup time for
1183 typical inter-CU-reference binaries, at an obvious memory cost. */
1184 static int dwarf_max_cache_age
= 5;
1186 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1187 struct cmd_list_element
*c
, const char *value
)
1189 fprintf_filtered (file
, _("The upper bound on the age of cached "
1190 "DWARF compilation units is %s.\n"),
1194 /* local function prototypes */
1196 static void dwarf2_find_base_address (struct die_info
*die
,
1197 struct dwarf2_cu
*cu
);
1199 static dwarf2_psymtab
*create_partial_symtab
1200 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1202 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1203 const gdb_byte
*info_ptr
,
1204 struct die_info
*type_unit_die
);
1206 static void dwarf2_build_psymtabs_hard
1207 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1209 static void scan_partial_symbols (struct partial_die_info
*,
1210 CORE_ADDR
*, CORE_ADDR
*,
1211 int, struct dwarf2_cu
*);
1213 static void add_partial_symbol (struct partial_die_info
*,
1214 struct dwarf2_cu
*);
1216 static void add_partial_namespace (struct partial_die_info
*pdi
,
1217 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1218 int set_addrmap
, struct dwarf2_cu
*cu
);
1220 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1221 CORE_ADDR
*highpc
, int set_addrmap
,
1222 struct dwarf2_cu
*cu
);
1224 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1225 struct dwarf2_cu
*cu
);
1227 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1228 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1229 int need_pc
, struct dwarf2_cu
*cu
);
1231 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1233 static struct partial_die_info
*load_partial_dies
1234 (const struct die_reader_specs
*, const gdb_byte
*, int);
1236 /* A pair of partial_die_info and compilation unit. */
1237 struct cu_partial_die_info
1239 /* The compilation unit of the partial_die_info. */
1240 struct dwarf2_cu
*cu
;
1241 /* A partial_die_info. */
1242 struct partial_die_info
*pdi
;
1244 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1250 cu_partial_die_info () = delete;
1253 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1254 struct dwarf2_cu
*);
1256 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1257 struct attribute
*, struct attr_abbrev
*,
1258 const gdb_byte
*, bool *need_reprocess
);
1260 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1261 struct attribute
*attr
);
1263 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1265 static sect_offset read_abbrev_offset
1266 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1267 struct dwarf2_section_info
*, sect_offset
);
1269 static const char *read_indirect_string
1270 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1271 const struct comp_unit_head
*, unsigned int *);
1273 static const char *read_indirect_string_at_offset
1274 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1276 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1280 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1281 ULONGEST str_index
);
1283 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1284 ULONGEST str_index
);
1286 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1288 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1289 struct dwarf2_cu
*);
1291 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1292 struct dwarf2_cu
*cu
);
1294 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1296 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1297 struct dwarf2_cu
*cu
);
1299 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1301 static struct die_info
*die_specification (struct die_info
*die
,
1302 struct dwarf2_cu
**);
1304 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1305 struct dwarf2_cu
*cu
);
1307 static void dwarf_decode_lines (struct line_header
*, const char *,
1308 struct dwarf2_cu
*, dwarf2_psymtab
*,
1309 CORE_ADDR
, int decode_mapping
);
1311 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1314 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1315 struct dwarf2_cu
*, struct symbol
* = NULL
);
1317 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1318 struct dwarf2_cu
*);
1320 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1323 struct obstack
*obstack
,
1324 struct dwarf2_cu
*cu
, LONGEST
*value
,
1325 const gdb_byte
**bytes
,
1326 struct dwarf2_locexpr_baton
**baton
);
1328 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1330 static int need_gnat_info (struct dwarf2_cu
*);
1332 static struct type
*die_descriptive_type (struct die_info
*,
1333 struct dwarf2_cu
*);
1335 static void set_descriptive_type (struct type
*, struct die_info
*,
1336 struct dwarf2_cu
*);
1338 static struct type
*die_containing_type (struct die_info
*,
1339 struct dwarf2_cu
*);
1341 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1342 struct dwarf2_cu
*);
1344 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1346 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1348 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1350 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1351 const char *suffix
, int physname
,
1352 struct dwarf2_cu
*cu
);
1354 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1356 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1358 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1360 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1362 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1364 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1366 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1367 struct dwarf2_cu
*, dwarf2_psymtab
*);
1369 /* Return the .debug_loclists section to use for cu. */
1370 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1372 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1373 values. Keep the items ordered with increasing constraints compliance. */
1376 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1377 PC_BOUNDS_NOT_PRESENT
,
1379 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1380 were present but they do not form a valid range of PC addresses. */
1383 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1386 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1390 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1391 CORE_ADDR
*, CORE_ADDR
*,
1395 static void get_scope_pc_bounds (struct die_info
*,
1396 CORE_ADDR
*, CORE_ADDR
*,
1397 struct dwarf2_cu
*);
1399 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1400 CORE_ADDR
, struct dwarf2_cu
*);
1402 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1403 struct dwarf2_cu
*);
1405 static void dwarf2_attach_fields_to_type (struct field_info
*,
1406 struct type
*, struct dwarf2_cu
*);
1408 static void dwarf2_add_member_fn (struct field_info
*,
1409 struct die_info
*, struct type
*,
1410 struct dwarf2_cu
*);
1412 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1414 struct dwarf2_cu
*);
1416 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1418 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1420 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1422 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1424 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1426 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1428 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1430 static struct type
*read_module_type (struct die_info
*die
,
1431 struct dwarf2_cu
*cu
);
1433 static const char *namespace_name (struct die_info
*die
,
1434 int *is_anonymous
, struct dwarf2_cu
*);
1436 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1438 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1441 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1442 struct dwarf2_cu
*);
1444 static struct die_info
*read_die_and_siblings_1
1445 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1448 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1449 const gdb_byte
*info_ptr
,
1450 const gdb_byte
**new_info_ptr
,
1451 struct die_info
*parent
);
1453 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1454 struct die_info
**, const gdb_byte
*,
1457 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1458 struct die_info
**, const gdb_byte
*);
1460 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1462 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1465 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1467 static const char *dwarf2_full_name (const char *name
,
1468 struct die_info
*die
,
1469 struct dwarf2_cu
*cu
);
1471 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1472 struct dwarf2_cu
*cu
);
1474 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1475 struct dwarf2_cu
**);
1477 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1479 static void dump_die_for_error (struct die_info
*);
1481 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1484 /*static*/ void dump_die (struct die_info
*, int max_level
);
1486 static void store_in_ref_table (struct die_info
*,
1487 struct dwarf2_cu
*);
1489 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1490 const struct attribute
*,
1491 struct dwarf2_cu
**);
1493 static struct die_info
*follow_die_ref (struct die_info
*,
1494 const struct attribute
*,
1495 struct dwarf2_cu
**);
1497 static struct die_info
*follow_die_sig (struct die_info
*,
1498 const struct attribute
*,
1499 struct dwarf2_cu
**);
1501 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1502 struct dwarf2_cu
*);
1504 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1505 const struct attribute
*,
1506 struct dwarf2_cu
*);
1508 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1510 static void read_signatured_type (struct signatured_type
*);
1512 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1513 struct die_info
*die
, struct dwarf2_cu
*cu
,
1514 struct dynamic_prop
*prop
, struct type
*type
);
1516 /* memory allocation interface */
1518 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1520 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1522 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1524 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1525 struct dwarf2_loclist_baton
*baton
,
1526 const struct attribute
*attr
);
1528 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1530 struct dwarf2_cu
*cu
,
1533 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1534 const gdb_byte
*info_ptr
,
1535 struct abbrev_info
*abbrev
);
1537 static hashval_t
partial_die_hash (const void *item
);
1539 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1541 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1542 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1543 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1545 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1546 struct die_info
*comp_unit_die
,
1547 enum language pretend_language
);
1549 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1551 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1553 static struct type
*set_die_type (struct die_info
*, struct type
*,
1554 struct dwarf2_cu
*);
1556 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1558 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1560 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1563 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1566 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1569 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1570 struct dwarf2_per_cu_data
*);
1572 static void dwarf2_mark (struct dwarf2_cu
*);
1574 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1576 static struct type
*get_die_type_at_offset (sect_offset
,
1577 struct dwarf2_per_cu_data
*);
1579 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1581 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1582 enum language pretend_language
);
1584 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1586 /* Class, the destructor of which frees all allocated queue entries. This
1587 will only have work to do if an error was thrown while processing the
1588 dwarf. If no error was thrown then the queue entries should have all
1589 been processed, and freed, as we went along. */
1591 class dwarf2_queue_guard
1594 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1595 : m_per_objfile (per_objfile
)
1599 /* Free any entries remaining on the queue. There should only be
1600 entries left if we hit an error while processing the dwarf. */
1601 ~dwarf2_queue_guard ()
1603 /* Ensure that no memory is allocated by the queue. */
1604 std::queue
<dwarf2_queue_item
> empty
;
1605 std::swap (m_per_objfile
->queue
, empty
);
1608 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1611 dwarf2_per_objfile
*m_per_objfile
;
1614 dwarf2_queue_item::~dwarf2_queue_item ()
1616 /* Anything still marked queued is likely to be in an
1617 inconsistent state, so discard it. */
1620 if (per_cu
->cu
!= NULL
)
1621 free_one_cached_comp_unit (per_cu
);
1626 /* The return type of find_file_and_directory. Note, the enclosed
1627 string pointers are only valid while this object is valid. */
1629 struct file_and_directory
1631 /* The filename. This is never NULL. */
1634 /* The compilation directory. NULL if not known. If we needed to
1635 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1636 points directly to the DW_AT_comp_dir string attribute owned by
1637 the obstack that owns the DIE. */
1638 const char *comp_dir
;
1640 /* If we needed to build a new string for comp_dir, this is what
1641 owns the storage. */
1642 std::string comp_dir_storage
;
1645 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1646 struct dwarf2_cu
*cu
);
1648 static htab_up
allocate_signatured_type_table ();
1650 static htab_up
allocate_dwo_unit_table ();
1652 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1653 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1654 struct dwp_file
*dwp_file
, const char *comp_dir
,
1655 ULONGEST signature
, int is_debug_types
);
1657 static struct dwp_file
*get_dwp_file
1658 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1660 static struct dwo_unit
*lookup_dwo_comp_unit
1661 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1663 static struct dwo_unit
*lookup_dwo_type_unit
1664 (struct signatured_type
*, const char *, const char *);
1666 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1668 /* A unique pointer to a dwo_file. */
1670 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1672 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1674 static void check_producer (struct dwarf2_cu
*cu
);
1676 static void free_line_header_voidp (void *arg
);
1678 /* Various complaints about symbol reading that don't abort the process. */
1681 dwarf2_debug_line_missing_file_complaint (void)
1683 complaint (_(".debug_line section has line data without a file"));
1687 dwarf2_debug_line_missing_end_sequence_complaint (void)
1689 complaint (_(".debug_line section has line "
1690 "program sequence without an end"));
1694 dwarf2_complex_location_expr_complaint (void)
1696 complaint (_("location expression too complex"));
1700 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1703 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1708 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1710 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1714 /* Hash function for line_header_hash. */
1717 line_header_hash (const struct line_header
*ofs
)
1719 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1722 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1725 line_header_hash_voidp (const void *item
)
1727 const struct line_header
*ofs
= (const struct line_header
*) item
;
1729 return line_header_hash (ofs
);
1732 /* Equality function for line_header_hash. */
1735 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1737 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1738 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1740 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1741 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1746 /* See declaration. */
1748 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1749 const dwarf2_debug_sections
*names
,
1751 : objfile (objfile_
),
1752 can_copy (can_copy_
)
1755 names
= &dwarf2_elf_names
;
1757 bfd
*obfd
= objfile
->obfd
;
1759 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1760 locate_sections (obfd
, sec
, *names
);
1763 dwarf2_per_objfile::~dwarf2_per_objfile ()
1765 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1766 free_cached_comp_units ();
1768 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1769 per_cu
->imported_symtabs_free ();
1771 for (signatured_type
*sig_type
: all_type_units
)
1772 sig_type
->per_cu
.imported_symtabs_free ();
1774 /* Everything else should be on the objfile obstack. */
1777 /* See declaration. */
1780 dwarf2_per_objfile::free_cached_comp_units ()
1782 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1783 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1784 while (per_cu
!= NULL
)
1786 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1789 *last_chain
= next_cu
;
1794 /* A helper class that calls free_cached_comp_units on
1797 class free_cached_comp_units
1801 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1802 : m_per_objfile (per_objfile
)
1806 ~free_cached_comp_units ()
1808 m_per_objfile
->free_cached_comp_units ();
1811 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1815 dwarf2_per_objfile
*m_per_objfile
;
1818 /* Try to locate the sections we need for DWARF 2 debugging
1819 information and return true if we have enough to do something.
1820 NAMES points to the dwarf2 section names, or is NULL if the standard
1821 ELF names are used. CAN_COPY is true for formats where symbol
1822 interposition is possible and so symbol values must follow copy
1823 relocation rules. */
1826 dwarf2_has_info (struct objfile
*objfile
,
1827 const struct dwarf2_debug_sections
*names
,
1830 if (objfile
->flags
& OBJF_READNEVER
)
1833 struct dwarf2_per_objfile
*dwarf2_per_objfile
1834 = get_dwarf2_per_objfile (objfile
);
1836 if (dwarf2_per_objfile
== NULL
)
1837 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1841 return (!dwarf2_per_objfile
->info
.is_virtual
1842 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1843 && !dwarf2_per_objfile
->abbrev
.is_virtual
1844 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1847 /* When loading sections, we look either for uncompressed section or for
1848 compressed section names. */
1851 section_is_p (const char *section_name
,
1852 const struct dwarf2_section_names
*names
)
1854 if (names
->normal
!= NULL
1855 && strcmp (section_name
, names
->normal
) == 0)
1857 if (names
->compressed
!= NULL
1858 && strcmp (section_name
, names
->compressed
) == 0)
1863 /* See declaration. */
1866 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1867 const dwarf2_debug_sections
&names
)
1869 flagword aflag
= bfd_section_flags (sectp
);
1871 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1874 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1875 > bfd_get_file_size (abfd
))
1877 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1878 warning (_("Discarding section %s which has a section size (%s"
1879 ") larger than the file size [in module %s]"),
1880 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1881 bfd_get_filename (abfd
));
1883 else if (section_is_p (sectp
->name
, &names
.info
))
1885 this->info
.s
.section
= sectp
;
1886 this->info
.size
= bfd_section_size (sectp
);
1888 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1890 this->abbrev
.s
.section
= sectp
;
1891 this->abbrev
.size
= bfd_section_size (sectp
);
1893 else if (section_is_p (sectp
->name
, &names
.line
))
1895 this->line
.s
.section
= sectp
;
1896 this->line
.size
= bfd_section_size (sectp
);
1898 else if (section_is_p (sectp
->name
, &names
.loc
))
1900 this->loc
.s
.section
= sectp
;
1901 this->loc
.size
= bfd_section_size (sectp
);
1903 else if (section_is_p (sectp
->name
, &names
.loclists
))
1905 this->loclists
.s
.section
= sectp
;
1906 this->loclists
.size
= bfd_section_size (sectp
);
1908 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1910 this->macinfo
.s
.section
= sectp
;
1911 this->macinfo
.size
= bfd_section_size (sectp
);
1913 else if (section_is_p (sectp
->name
, &names
.macro
))
1915 this->macro
.s
.section
= sectp
;
1916 this->macro
.size
= bfd_section_size (sectp
);
1918 else if (section_is_p (sectp
->name
, &names
.str
))
1920 this->str
.s
.section
= sectp
;
1921 this->str
.size
= bfd_section_size (sectp
);
1923 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1925 this->str_offsets
.s
.section
= sectp
;
1926 this->str_offsets
.size
= bfd_section_size (sectp
);
1928 else if (section_is_p (sectp
->name
, &names
.line_str
))
1930 this->line_str
.s
.section
= sectp
;
1931 this->line_str
.size
= bfd_section_size (sectp
);
1933 else if (section_is_p (sectp
->name
, &names
.addr
))
1935 this->addr
.s
.section
= sectp
;
1936 this->addr
.size
= bfd_section_size (sectp
);
1938 else if (section_is_p (sectp
->name
, &names
.frame
))
1940 this->frame
.s
.section
= sectp
;
1941 this->frame
.size
= bfd_section_size (sectp
);
1943 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1945 this->eh_frame
.s
.section
= sectp
;
1946 this->eh_frame
.size
= bfd_section_size (sectp
);
1948 else if (section_is_p (sectp
->name
, &names
.ranges
))
1950 this->ranges
.s
.section
= sectp
;
1951 this->ranges
.size
= bfd_section_size (sectp
);
1953 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1955 this->rnglists
.s
.section
= sectp
;
1956 this->rnglists
.size
= bfd_section_size (sectp
);
1958 else if (section_is_p (sectp
->name
, &names
.types
))
1960 struct dwarf2_section_info type_section
;
1962 memset (&type_section
, 0, sizeof (type_section
));
1963 type_section
.s
.section
= sectp
;
1964 type_section
.size
= bfd_section_size (sectp
);
1966 this->types
.push_back (type_section
);
1968 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1970 this->gdb_index
.s
.section
= sectp
;
1971 this->gdb_index
.size
= bfd_section_size (sectp
);
1973 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1975 this->debug_names
.s
.section
= sectp
;
1976 this->debug_names
.size
= bfd_section_size (sectp
);
1978 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1980 this->debug_aranges
.s
.section
= sectp
;
1981 this->debug_aranges
.size
= bfd_section_size (sectp
);
1984 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1985 && bfd_section_vma (sectp
) == 0)
1986 this->has_section_at_zero
= true;
1989 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1993 dwarf2_get_section_info (struct objfile
*objfile
,
1994 enum dwarf2_section_enum sect
,
1995 asection
**sectp
, const gdb_byte
**bufp
,
1996 bfd_size_type
*sizep
)
1998 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
1999 struct dwarf2_section_info
*info
;
2001 /* We may see an objfile without any DWARF, in which case we just
2012 case DWARF2_DEBUG_FRAME
:
2013 info
= &data
->frame
;
2015 case DWARF2_EH_FRAME
:
2016 info
= &data
->eh_frame
;
2019 gdb_assert_not_reached ("unexpected section");
2022 info
->read (objfile
);
2024 *sectp
= info
->get_bfd_section ();
2025 *bufp
= info
->buffer
;
2026 *sizep
= info
->size
;
2029 /* A helper function to find the sections for a .dwz file. */
2032 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2034 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2036 /* Note that we only support the standard ELF names, because .dwz
2037 is ELF-only (at the time of writing). */
2038 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2040 dwz_file
->abbrev
.s
.section
= sectp
;
2041 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2043 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2045 dwz_file
->info
.s
.section
= sectp
;
2046 dwz_file
->info
.size
= bfd_section_size (sectp
);
2048 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2050 dwz_file
->str
.s
.section
= sectp
;
2051 dwz_file
->str
.size
= bfd_section_size (sectp
);
2053 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2055 dwz_file
->line
.s
.section
= sectp
;
2056 dwz_file
->line
.size
= bfd_section_size (sectp
);
2058 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2060 dwz_file
->macro
.s
.section
= sectp
;
2061 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2063 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2065 dwz_file
->gdb_index
.s
.section
= sectp
;
2066 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2068 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2070 dwz_file
->debug_names
.s
.section
= sectp
;
2071 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2075 /* See dwarf2read.h. */
2078 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2080 const char *filename
;
2081 bfd_size_type buildid_len_arg
;
2085 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2086 return dwarf2_per_objfile
->dwz_file
.get ();
2088 bfd_set_error (bfd_error_no_error
);
2089 gdb::unique_xmalloc_ptr
<char> data
2090 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2091 &buildid_len_arg
, &buildid
));
2094 if (bfd_get_error () == bfd_error_no_error
)
2096 error (_("could not read '.gnu_debugaltlink' section: %s"),
2097 bfd_errmsg (bfd_get_error ()));
2100 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2102 buildid_len
= (size_t) buildid_len_arg
;
2104 filename
= data
.get ();
2106 std::string abs_storage
;
2107 if (!IS_ABSOLUTE_PATH (filename
))
2109 gdb::unique_xmalloc_ptr
<char> abs
2110 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2112 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2113 filename
= abs_storage
.c_str ();
2116 /* First try the file name given in the section. If that doesn't
2117 work, try to use the build-id instead. */
2118 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2119 if (dwz_bfd
!= NULL
)
2121 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2122 dwz_bfd
.reset (nullptr);
2125 if (dwz_bfd
== NULL
)
2126 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2128 if (dwz_bfd
== nullptr)
2130 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2131 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2133 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2140 /* File successfully retrieved from server. */
2141 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2143 if (dwz_bfd
== nullptr)
2144 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2145 alt_filename
.get ());
2146 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2147 dwz_bfd
.reset (nullptr);
2151 if (dwz_bfd
== NULL
)
2152 error (_("could not find '.gnu_debugaltlink' file for %s"),
2153 objfile_name (dwarf2_per_objfile
->objfile
));
2155 std::unique_ptr
<struct dwz_file
> result
2156 (new struct dwz_file (std::move (dwz_bfd
)));
2158 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2161 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2162 result
->dwz_bfd
.get ());
2163 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2164 return dwarf2_per_objfile
->dwz_file
.get ();
2167 /* DWARF quick_symbols_functions support. */
2169 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2170 unique line tables, so we maintain a separate table of all .debug_line
2171 derived entries to support the sharing.
2172 All the quick functions need is the list of file names. We discard the
2173 line_header when we're done and don't need to record it here. */
2174 struct quick_file_names
2176 /* The data used to construct the hash key. */
2177 struct stmt_list_hash hash
;
2179 /* The number of entries in file_names, real_names. */
2180 unsigned int num_file_names
;
2182 /* The file names from the line table, after being run through
2184 const char **file_names
;
2186 /* The file names from the line table after being run through
2187 gdb_realpath. These are computed lazily. */
2188 const char **real_names
;
2191 /* When using the index (and thus not using psymtabs), each CU has an
2192 object of this type. This is used to hold information needed by
2193 the various "quick" methods. */
2194 struct dwarf2_per_cu_quick_data
2196 /* The file table. This can be NULL if there was no file table
2197 or it's currently not read in.
2198 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2199 struct quick_file_names
*file_names
;
2201 /* The corresponding symbol table. This is NULL if symbols for this
2202 CU have not yet been read. */
2203 struct compunit_symtab
*compunit_symtab
;
2205 /* A temporary mark bit used when iterating over all CUs in
2206 expand_symtabs_matching. */
2207 unsigned int mark
: 1;
2209 /* True if we've tried to read the file table and found there isn't one.
2210 There will be no point in trying to read it again next time. */
2211 unsigned int no_file_data
: 1;
2214 /* Utility hash function for a stmt_list_hash. */
2217 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2221 if (stmt_list_hash
->dwo_unit
!= NULL
)
2222 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2223 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2227 /* Utility equality function for a stmt_list_hash. */
2230 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2231 const struct stmt_list_hash
*rhs
)
2233 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2235 if (lhs
->dwo_unit
!= NULL
2236 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2239 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2242 /* Hash function for a quick_file_names. */
2245 hash_file_name_entry (const void *e
)
2247 const struct quick_file_names
*file_data
2248 = (const struct quick_file_names
*) e
;
2250 return hash_stmt_list_entry (&file_data
->hash
);
2253 /* Equality function for a quick_file_names. */
2256 eq_file_name_entry (const void *a
, const void *b
)
2258 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2259 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2261 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2264 /* Delete function for a quick_file_names. */
2267 delete_file_name_entry (void *e
)
2269 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2272 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2274 xfree ((void*) file_data
->file_names
[i
]);
2275 if (file_data
->real_names
)
2276 xfree ((void*) file_data
->real_names
[i
]);
2279 /* The space for the struct itself lives on objfile_obstack,
2280 so we don't free it here. */
2283 /* Create a quick_file_names hash table. */
2286 create_quick_file_names_table (unsigned int nr_initial_entries
)
2288 return htab_up (htab_create_alloc (nr_initial_entries
,
2289 hash_file_name_entry
, eq_file_name_entry
,
2290 delete_file_name_entry
, xcalloc
, xfree
));
2293 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2294 have to be created afterwards. You should call age_cached_comp_units after
2295 processing PER_CU->CU. dw2_setup must have been already called. */
2298 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2300 if (per_cu
->is_debug_types
)
2301 load_full_type_unit (per_cu
);
2303 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2305 if (per_cu
->cu
== NULL
)
2306 return; /* Dummy CU. */
2308 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2311 /* Read in the symbols for PER_CU. */
2314 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2316 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2318 /* Skip type_unit_groups, reading the type units they contain
2319 is handled elsewhere. */
2320 if (per_cu
->type_unit_group_p ())
2323 /* The destructor of dwarf2_queue_guard frees any entries left on
2324 the queue. After this point we're guaranteed to leave this function
2325 with the dwarf queue empty. */
2326 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2328 if (dwarf2_per_objfile
->using_index
2329 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2330 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2332 queue_comp_unit (per_cu
, language_minimal
);
2333 load_cu (per_cu
, skip_partial
);
2335 /* If we just loaded a CU from a DWO, and we're working with an index
2336 that may badly handle TUs, load all the TUs in that DWO as well.
2337 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2338 if (!per_cu
->is_debug_types
2339 && per_cu
->cu
!= NULL
2340 && per_cu
->cu
->dwo_unit
!= NULL
2341 && dwarf2_per_objfile
->index_table
!= NULL
2342 && dwarf2_per_objfile
->index_table
->version
<= 7
2343 /* DWP files aren't supported yet. */
2344 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2345 queue_and_load_all_dwo_tus (per_cu
);
2348 process_queue (dwarf2_per_objfile
);
2350 /* Age the cache, releasing compilation units that have not
2351 been used recently. */
2352 age_cached_comp_units (dwarf2_per_objfile
);
2355 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2356 the objfile from which this CU came. Returns the resulting symbol
2359 static struct compunit_symtab
*
2360 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2362 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2364 gdb_assert (dwarf2_per_objfile
->using_index
);
2365 if (!per_cu
->v
.quick
->compunit_symtab
)
2367 free_cached_comp_units
freer (dwarf2_per_objfile
);
2368 scoped_restore decrementer
= increment_reading_symtab ();
2369 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2370 process_cu_includes (dwarf2_per_objfile
);
2373 return per_cu
->v
.quick
->compunit_symtab
;
2376 /* See declaration. */
2378 dwarf2_per_cu_data
*
2379 dwarf2_per_objfile::get_cutu (int index
)
2381 if (index
>= this->all_comp_units
.size ())
2383 index
-= this->all_comp_units
.size ();
2384 gdb_assert (index
< this->all_type_units
.size ());
2385 return &this->all_type_units
[index
]->per_cu
;
2388 return this->all_comp_units
[index
];
2391 /* See declaration. */
2393 dwarf2_per_cu_data
*
2394 dwarf2_per_objfile::get_cu (int index
)
2396 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2398 return this->all_comp_units
[index
];
2401 /* See declaration. */
2404 dwarf2_per_objfile::get_tu (int index
)
2406 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2408 return this->all_type_units
[index
];
2411 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2412 objfile_obstack, and constructed with the specified field
2415 static dwarf2_per_cu_data
*
2416 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2417 struct dwarf2_section_info
*section
,
2419 sect_offset sect_off
, ULONGEST length
)
2421 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2422 dwarf2_per_cu_data
*the_cu
2423 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2424 struct dwarf2_per_cu_data
);
2425 the_cu
->sect_off
= sect_off
;
2426 the_cu
->length
= length
;
2427 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2428 the_cu
->section
= section
;
2429 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2430 struct dwarf2_per_cu_quick_data
);
2431 the_cu
->is_dwz
= is_dwz
;
2435 /* A helper for create_cus_from_index that handles a given list of
2439 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2440 const gdb_byte
*cu_list
, offset_type n_elements
,
2441 struct dwarf2_section_info
*section
,
2444 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2446 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2448 sect_offset sect_off
2449 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2450 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2453 dwarf2_per_cu_data
*per_cu
2454 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2456 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2460 /* Read the CU list from the mapped index, and use it to create all
2461 the CU objects for this objfile. */
2464 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2465 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2466 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2468 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2469 dwarf2_per_objfile
->all_comp_units
.reserve
2470 ((cu_list_elements
+ dwz_elements
) / 2);
2472 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2473 &dwarf2_per_objfile
->info
, 0);
2475 if (dwz_elements
== 0)
2478 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2479 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2483 /* Create the signatured type hash table from the index. */
2486 create_signatured_type_table_from_index
2487 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2488 struct dwarf2_section_info
*section
,
2489 const gdb_byte
*bytes
,
2490 offset_type elements
)
2492 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2494 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2495 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2497 htab_up sig_types_hash
= allocate_signatured_type_table ();
2499 for (offset_type i
= 0; i
< elements
; i
+= 3)
2501 struct signatured_type
*sig_type
;
2504 cu_offset type_offset_in_tu
;
2506 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2507 sect_offset sect_off
2508 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2510 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2512 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2515 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2516 struct signatured_type
);
2517 sig_type
->signature
= signature
;
2518 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2519 sig_type
->per_cu
.is_debug_types
= 1;
2520 sig_type
->per_cu
.section
= section
;
2521 sig_type
->per_cu
.sect_off
= sect_off
;
2522 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2523 sig_type
->per_cu
.v
.quick
2524 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2525 struct dwarf2_per_cu_quick_data
);
2527 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2530 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2533 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2536 /* Create the signatured type hash table from .debug_names. */
2539 create_signatured_type_table_from_debug_names
2540 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2541 const mapped_debug_names
&map
,
2542 struct dwarf2_section_info
*section
,
2543 struct dwarf2_section_info
*abbrev_section
)
2545 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2547 section
->read (objfile
);
2548 abbrev_section
->read (objfile
);
2550 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2551 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2553 htab_up sig_types_hash
= allocate_signatured_type_table ();
2555 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2557 struct signatured_type
*sig_type
;
2560 sect_offset sect_off
2561 = (sect_offset
) (extract_unsigned_integer
2562 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2564 map
.dwarf5_byte_order
));
2566 comp_unit_head cu_header
;
2567 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2569 section
->buffer
+ to_underlying (sect_off
),
2572 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2573 struct signatured_type
);
2574 sig_type
->signature
= cu_header
.signature
;
2575 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2576 sig_type
->per_cu
.is_debug_types
= 1;
2577 sig_type
->per_cu
.section
= section
;
2578 sig_type
->per_cu
.sect_off
= sect_off
;
2579 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2580 sig_type
->per_cu
.v
.quick
2581 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2582 struct dwarf2_per_cu_quick_data
);
2584 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2587 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2590 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2593 /* Read the address map data from the mapped index, and use it to
2594 populate the objfile's psymtabs_addrmap. */
2597 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2598 struct mapped_index
*index
)
2600 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2601 struct gdbarch
*gdbarch
= objfile
->arch ();
2602 const gdb_byte
*iter
, *end
;
2603 struct addrmap
*mutable_map
;
2606 auto_obstack temp_obstack
;
2608 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2610 iter
= index
->address_table
.data ();
2611 end
= iter
+ index
->address_table
.size ();
2613 baseaddr
= objfile
->text_section_offset ();
2617 ULONGEST hi
, lo
, cu_index
;
2618 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2620 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2622 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2627 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2628 hex_string (lo
), hex_string (hi
));
2632 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2634 complaint (_(".gdb_index address table has invalid CU number %u"),
2635 (unsigned) cu_index
);
2639 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2640 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2641 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2642 dwarf2_per_objfile
->get_cu (cu_index
));
2645 objfile
->partial_symtabs
->psymtabs_addrmap
2646 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2649 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2650 populate the objfile's psymtabs_addrmap. */
2653 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2654 struct dwarf2_section_info
*section
)
2656 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2657 bfd
*abfd
= objfile
->obfd
;
2658 struct gdbarch
*gdbarch
= objfile
->arch ();
2659 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2661 auto_obstack temp_obstack
;
2662 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2664 std::unordered_map
<sect_offset
,
2665 dwarf2_per_cu_data
*,
2666 gdb::hash_enum
<sect_offset
>>
2667 debug_info_offset_to_per_cu
;
2668 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2670 const auto insertpair
2671 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2672 if (!insertpair
.second
)
2674 warning (_("Section .debug_aranges in %s has duplicate "
2675 "debug_info_offset %s, ignoring .debug_aranges."),
2676 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2681 section
->read (objfile
);
2683 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2685 const gdb_byte
*addr
= section
->buffer
;
2687 while (addr
< section
->buffer
+ section
->size
)
2689 const gdb_byte
*const entry_addr
= addr
;
2690 unsigned int bytes_read
;
2692 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2696 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2697 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2698 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2699 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2701 warning (_("Section .debug_aranges in %s entry at offset %s "
2702 "length %s exceeds section length %s, "
2703 "ignoring .debug_aranges."),
2704 objfile_name (objfile
),
2705 plongest (entry_addr
- section
->buffer
),
2706 plongest (bytes_read
+ entry_length
),
2707 pulongest (section
->size
));
2711 /* The version number. */
2712 const uint16_t version
= read_2_bytes (abfd
, addr
);
2716 warning (_("Section .debug_aranges in %s entry at offset %s "
2717 "has unsupported version %d, ignoring .debug_aranges."),
2718 objfile_name (objfile
),
2719 plongest (entry_addr
- section
->buffer
), version
);
2723 const uint64_t debug_info_offset
2724 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2725 addr
+= offset_size
;
2726 const auto per_cu_it
2727 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2728 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2730 warning (_("Section .debug_aranges in %s entry at offset %s "
2731 "debug_info_offset %s does not exists, "
2732 "ignoring .debug_aranges."),
2733 objfile_name (objfile
),
2734 plongest (entry_addr
- section
->buffer
),
2735 pulongest (debug_info_offset
));
2738 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2740 const uint8_t address_size
= *addr
++;
2741 if (address_size
< 1 || address_size
> 8)
2743 warning (_("Section .debug_aranges in %s entry at offset %s "
2744 "address_size %u is invalid, ignoring .debug_aranges."),
2745 objfile_name (objfile
),
2746 plongest (entry_addr
- section
->buffer
), address_size
);
2750 const uint8_t segment_selector_size
= *addr
++;
2751 if (segment_selector_size
!= 0)
2753 warning (_("Section .debug_aranges in %s entry at offset %s "
2754 "segment_selector_size %u is not supported, "
2755 "ignoring .debug_aranges."),
2756 objfile_name (objfile
),
2757 plongest (entry_addr
- section
->buffer
),
2758 segment_selector_size
);
2762 /* Must pad to an alignment boundary that is twice the address
2763 size. It is undocumented by the DWARF standard but GCC does
2765 for (size_t padding
= ((-(addr
- section
->buffer
))
2766 & (2 * address_size
- 1));
2767 padding
> 0; padding
--)
2770 warning (_("Section .debug_aranges in %s entry at offset %s "
2771 "padding is not zero, ignoring .debug_aranges."),
2772 objfile_name (objfile
),
2773 plongest (entry_addr
- section
->buffer
));
2779 if (addr
+ 2 * address_size
> entry_end
)
2781 warning (_("Section .debug_aranges in %s entry at offset %s "
2782 "address list is not properly terminated, "
2783 "ignoring .debug_aranges."),
2784 objfile_name (objfile
),
2785 plongest (entry_addr
- section
->buffer
));
2788 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2790 addr
+= address_size
;
2791 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2793 addr
+= address_size
;
2794 if (start
== 0 && length
== 0)
2796 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2798 /* Symbol was eliminated due to a COMDAT group. */
2801 ULONGEST end
= start
+ length
;
2802 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2804 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2806 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2810 objfile
->partial_symtabs
->psymtabs_addrmap
2811 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2814 /* Find a slot in the mapped index INDEX for the object named NAME.
2815 If NAME is found, set *VEC_OUT to point to the CU vector in the
2816 constant pool and return true. If NAME cannot be found, return
2820 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2821 offset_type
**vec_out
)
2824 offset_type slot
, step
;
2825 int (*cmp
) (const char *, const char *);
2827 gdb::unique_xmalloc_ptr
<char> without_params
;
2828 if (current_language
->la_language
== language_cplus
2829 || current_language
->la_language
== language_fortran
2830 || current_language
->la_language
== language_d
)
2832 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2835 if (strchr (name
, '(') != NULL
)
2837 without_params
= cp_remove_params (name
);
2839 if (without_params
!= NULL
)
2840 name
= without_params
.get ();
2844 /* Index version 4 did not support case insensitive searches. But the
2845 indices for case insensitive languages are built in lowercase, therefore
2846 simulate our NAME being searched is also lowercased. */
2847 hash
= mapped_index_string_hash ((index
->version
== 4
2848 && case_sensitivity
== case_sensitive_off
2849 ? 5 : index
->version
),
2852 slot
= hash
& (index
->symbol_table
.size () - 1);
2853 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2854 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2860 const auto &bucket
= index
->symbol_table
[slot
];
2861 if (bucket
.name
== 0 && bucket
.vec
== 0)
2864 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2865 if (!cmp (name
, str
))
2867 *vec_out
= (offset_type
*) (index
->constant_pool
2868 + MAYBE_SWAP (bucket
.vec
));
2872 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2876 /* A helper function that reads the .gdb_index from BUFFER and fills
2877 in MAP. FILENAME is the name of the file containing the data;
2878 it is used for error reporting. DEPRECATED_OK is true if it is
2879 ok to use deprecated sections.
2881 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2882 out parameters that are filled in with information about the CU and
2883 TU lists in the section.
2885 Returns true if all went well, false otherwise. */
2888 read_gdb_index_from_buffer (const char *filename
,
2890 gdb::array_view
<const gdb_byte
> buffer
,
2891 struct mapped_index
*map
,
2892 const gdb_byte
**cu_list
,
2893 offset_type
*cu_list_elements
,
2894 const gdb_byte
**types_list
,
2895 offset_type
*types_list_elements
)
2897 const gdb_byte
*addr
= &buffer
[0];
2899 /* Version check. */
2900 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2901 /* Versions earlier than 3 emitted every copy of a psymbol. This
2902 causes the index to behave very poorly for certain requests. Version 3
2903 contained incomplete addrmap. So, it seems better to just ignore such
2907 static int warning_printed
= 0;
2908 if (!warning_printed
)
2910 warning (_("Skipping obsolete .gdb_index section in %s."),
2912 warning_printed
= 1;
2916 /* Index version 4 uses a different hash function than index version
2919 Versions earlier than 6 did not emit psymbols for inlined
2920 functions. Using these files will cause GDB not to be able to
2921 set breakpoints on inlined functions by name, so we ignore these
2922 indices unless the user has done
2923 "set use-deprecated-index-sections on". */
2924 if (version
< 6 && !deprecated_ok
)
2926 static int warning_printed
= 0;
2927 if (!warning_printed
)
2930 Skipping deprecated .gdb_index section in %s.\n\
2931 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2932 to use the section anyway."),
2934 warning_printed
= 1;
2938 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2939 of the TU (for symbols coming from TUs),
2940 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2941 Plus gold-generated indices can have duplicate entries for global symbols,
2942 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2943 These are just performance bugs, and we can't distinguish gdb-generated
2944 indices from gold-generated ones, so issue no warning here. */
2946 /* Indexes with higher version than the one supported by GDB may be no
2947 longer backward compatible. */
2951 map
->version
= version
;
2953 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2956 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2957 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2961 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2962 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2963 - MAYBE_SWAP (metadata
[i
]))
2967 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2968 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2970 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2973 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2974 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2976 = gdb::array_view
<mapped_index::symbol_table_slot
>
2977 ((mapped_index::symbol_table_slot
*) symbol_table
,
2978 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2981 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2986 /* Callback types for dwarf2_read_gdb_index. */
2988 typedef gdb::function_view
2989 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2990 get_gdb_index_contents_ftype
;
2991 typedef gdb::function_view
2992 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2993 get_gdb_index_contents_dwz_ftype
;
2995 /* Read .gdb_index. If everything went ok, initialize the "quick"
2996 elements of all the CUs and return 1. Otherwise, return 0. */
2999 dwarf2_read_gdb_index
3000 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3001 get_gdb_index_contents_ftype get_gdb_index_contents
,
3002 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3004 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3005 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3006 struct dwz_file
*dwz
;
3007 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3009 gdb::array_view
<const gdb_byte
> main_index_contents
3010 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3012 if (main_index_contents
.empty ())
3015 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3016 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3017 use_deprecated_index_sections
,
3018 main_index_contents
, map
.get (), &cu_list
,
3019 &cu_list_elements
, &types_list
,
3020 &types_list_elements
))
3023 /* Don't use the index if it's empty. */
3024 if (map
->symbol_table
.empty ())
3027 /* If there is a .dwz file, read it so we can get its CU list as
3029 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3032 struct mapped_index dwz_map
;
3033 const gdb_byte
*dwz_types_ignore
;
3034 offset_type dwz_types_elements_ignore
;
3036 gdb::array_view
<const gdb_byte
> dwz_index_content
3037 = get_gdb_index_contents_dwz (objfile
, dwz
);
3039 if (dwz_index_content
.empty ())
3042 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3043 1, dwz_index_content
, &dwz_map
,
3044 &dwz_list
, &dwz_list_elements
,
3046 &dwz_types_elements_ignore
))
3048 warning (_("could not read '.gdb_index' section from %s; skipping"),
3049 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3054 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3055 dwz_list
, dwz_list_elements
);
3057 if (types_list_elements
)
3059 /* We can only handle a single .debug_types when we have an
3061 if (dwarf2_per_objfile
->types
.size () != 1)
3064 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3066 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3067 types_list
, types_list_elements
);
3070 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3072 dwarf2_per_objfile
->index_table
= std::move (map
);
3073 dwarf2_per_objfile
->using_index
= 1;
3074 dwarf2_per_objfile
->quick_file_names_table
=
3075 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3080 /* die_reader_func for dw2_get_file_names. */
3083 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3084 const gdb_byte
*info_ptr
,
3085 struct die_info
*comp_unit_die
)
3087 struct dwarf2_cu
*cu
= reader
->cu
;
3088 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3089 struct dwarf2_per_objfile
*dwarf2_per_objfile
3090 = cu
->per_cu
->dwarf2_per_objfile
;
3091 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3092 struct dwarf2_per_cu_data
*lh_cu
;
3093 struct attribute
*attr
;
3095 struct quick_file_names
*qfn
;
3097 gdb_assert (! this_cu
->is_debug_types
);
3099 /* Our callers never want to match partial units -- instead they
3100 will match the enclosing full CU. */
3101 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3103 this_cu
->v
.quick
->no_file_data
= 1;
3111 sect_offset line_offset
{};
3113 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3114 if (attr
!= nullptr)
3116 struct quick_file_names find_entry
;
3118 line_offset
= (sect_offset
) DW_UNSND (attr
);
3120 /* We may have already read in this line header (TU line header sharing).
3121 If we have we're done. */
3122 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3123 find_entry
.hash
.line_sect_off
= line_offset
;
3124 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3125 &find_entry
, INSERT
);
3128 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3132 lh
= dwarf_decode_line_header (line_offset
, cu
);
3136 lh_cu
->v
.quick
->no_file_data
= 1;
3140 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3141 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3142 qfn
->hash
.line_sect_off
= line_offset
;
3143 gdb_assert (slot
!= NULL
);
3146 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3149 if (strcmp (fnd
.name
, "<unknown>") != 0)
3152 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3154 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3156 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3157 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3158 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3159 fnd
.comp_dir
).release ();
3160 qfn
->real_names
= NULL
;
3162 lh_cu
->v
.quick
->file_names
= qfn
;
3165 /* A helper for the "quick" functions which attempts to read the line
3166 table for THIS_CU. */
3168 static struct quick_file_names
*
3169 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3171 /* This should never be called for TUs. */
3172 gdb_assert (! this_cu
->is_debug_types
);
3173 /* Nor type unit groups. */
3174 gdb_assert (! this_cu
->type_unit_group_p ());
3176 if (this_cu
->v
.quick
->file_names
!= NULL
)
3177 return this_cu
->v
.quick
->file_names
;
3178 /* If we know there is no line data, no point in looking again. */
3179 if (this_cu
->v
.quick
->no_file_data
)
3182 cutu_reader
reader (this_cu
);
3183 if (!reader
.dummy_p
)
3184 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3186 if (this_cu
->v
.quick
->no_file_data
)
3188 return this_cu
->v
.quick
->file_names
;
3191 /* A helper for the "quick" functions which computes and caches the
3192 real path for a given file name from the line table. */
3195 dw2_get_real_path (struct objfile
*objfile
,
3196 struct quick_file_names
*qfn
, int index
)
3198 if (qfn
->real_names
== NULL
)
3199 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3200 qfn
->num_file_names
, const char *);
3202 if (qfn
->real_names
[index
] == NULL
)
3203 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3205 return qfn
->real_names
[index
];
3208 static struct symtab
*
3209 dw2_find_last_source_symtab (struct objfile
*objfile
)
3211 struct dwarf2_per_objfile
*dwarf2_per_objfile
3212 = get_dwarf2_per_objfile (objfile
);
3213 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3214 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3219 return compunit_primary_filetab (cust
);
3222 /* Traversal function for dw2_forget_cached_source_info. */
3225 dw2_free_cached_file_names (void **slot
, void *info
)
3227 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3229 if (file_data
->real_names
)
3233 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3235 xfree ((void*) file_data
->real_names
[i
]);
3236 file_data
->real_names
[i
] = NULL
;
3244 dw2_forget_cached_source_info (struct objfile
*objfile
)
3246 struct dwarf2_per_objfile
*dwarf2_per_objfile
3247 = get_dwarf2_per_objfile (objfile
);
3249 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3250 dw2_free_cached_file_names
, NULL
);
3253 /* Helper function for dw2_map_symtabs_matching_filename that expands
3254 the symtabs and calls the iterator. */
3257 dw2_map_expand_apply (struct objfile
*objfile
,
3258 struct dwarf2_per_cu_data
*per_cu
,
3259 const char *name
, const char *real_path
,
3260 gdb::function_view
<bool (symtab
*)> callback
)
3262 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3264 /* Don't visit already-expanded CUs. */
3265 if (per_cu
->v
.quick
->compunit_symtab
)
3268 /* This may expand more than one symtab, and we want to iterate over
3270 dw2_instantiate_symtab (per_cu
, false);
3272 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3273 last_made
, callback
);
3276 /* Implementation of the map_symtabs_matching_filename method. */
3279 dw2_map_symtabs_matching_filename
3280 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3281 gdb::function_view
<bool (symtab
*)> callback
)
3283 const char *name_basename
= lbasename (name
);
3284 struct dwarf2_per_objfile
*dwarf2_per_objfile
3285 = get_dwarf2_per_objfile (objfile
);
3287 /* The rule is CUs specify all the files, including those used by
3288 any TU, so there's no need to scan TUs here. */
3290 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3292 /* We only need to look at symtabs not already expanded. */
3293 if (per_cu
->v
.quick
->compunit_symtab
)
3296 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3297 if (file_data
== NULL
)
3300 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3302 const char *this_name
= file_data
->file_names
[j
];
3303 const char *this_real_name
;
3305 if (compare_filenames_for_search (this_name
, name
))
3307 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3313 /* Before we invoke realpath, which can get expensive when many
3314 files are involved, do a quick comparison of the basenames. */
3315 if (! basenames_may_differ
3316 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3319 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3320 if (compare_filenames_for_search (this_real_name
, name
))
3322 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3328 if (real_path
!= NULL
)
3330 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3331 gdb_assert (IS_ABSOLUTE_PATH (name
));
3332 if (this_real_name
!= NULL
3333 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3335 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3347 /* Struct used to manage iterating over all CUs looking for a symbol. */
3349 struct dw2_symtab_iterator
3351 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3352 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3353 /* If set, only look for symbols that match that block. Valid values are
3354 GLOBAL_BLOCK and STATIC_BLOCK. */
3355 gdb::optional
<block_enum
> block_index
;
3356 /* The kind of symbol we're looking for. */
3358 /* The list of CUs from the index entry of the symbol,
3359 or NULL if not found. */
3361 /* The next element in VEC to look at. */
3363 /* The number of elements in VEC, or zero if there is no match. */
3365 /* Have we seen a global version of the symbol?
3366 If so we can ignore all further global instances.
3367 This is to work around gold/15646, inefficient gold-generated
3372 /* Initialize the index symtab iterator ITER. */
3375 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3376 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3377 gdb::optional
<block_enum
> block_index
,
3381 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3382 iter
->block_index
= block_index
;
3383 iter
->domain
= domain
;
3385 iter
->global_seen
= 0;
3387 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3389 /* index is NULL if OBJF_READNOW. */
3390 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3391 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3399 /* Return the next matching CU or NULL if there are no more. */
3401 static struct dwarf2_per_cu_data
*
3402 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3404 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3406 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3408 offset_type cu_index_and_attrs
=
3409 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3410 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3411 gdb_index_symbol_kind symbol_kind
=
3412 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3413 /* Only check the symbol attributes if they're present.
3414 Indices prior to version 7 don't record them,
3415 and indices >= 7 may elide them for certain symbols
3416 (gold does this). */
3418 (dwarf2_per_objfile
->index_table
->version
>= 7
3419 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3421 /* Don't crash on bad data. */
3422 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3423 + dwarf2_per_objfile
->all_type_units
.size ()))
3425 complaint (_(".gdb_index entry has bad CU index"
3427 objfile_name (dwarf2_per_objfile
->objfile
));
3431 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3433 /* Skip if already read in. */
3434 if (per_cu
->v
.quick
->compunit_symtab
)
3437 /* Check static vs global. */
3440 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3442 if (iter
->block_index
.has_value ())
3444 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3446 if (is_static
!= want_static
)
3450 /* Work around gold/15646. */
3451 if (!is_static
&& iter
->global_seen
)
3454 iter
->global_seen
= 1;
3457 /* Only check the symbol's kind if it has one. */
3460 switch (iter
->domain
)
3463 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3464 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3465 /* Some types are also in VAR_DOMAIN. */
3466 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3470 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3474 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3478 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3493 static struct compunit_symtab
*
3494 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3495 const char *name
, domain_enum domain
)
3497 struct compunit_symtab
*stab_best
= NULL
;
3498 struct dwarf2_per_objfile
*dwarf2_per_objfile
3499 = get_dwarf2_per_objfile (objfile
);
3501 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3503 struct dw2_symtab_iterator iter
;
3504 struct dwarf2_per_cu_data
*per_cu
;
3506 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3508 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3510 struct symbol
*sym
, *with_opaque
= NULL
;
3511 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3512 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3513 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3515 sym
= block_find_symbol (block
, name
, domain
,
3516 block_find_non_opaque_type_preferred
,
3519 /* Some caution must be observed with overloaded functions
3520 and methods, since the index will not contain any overload
3521 information (but NAME might contain it). */
3524 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3526 if (with_opaque
!= NULL
3527 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3530 /* Keep looking through other CUs. */
3537 dw2_print_stats (struct objfile
*objfile
)
3539 struct dwarf2_per_objfile
*dwarf2_per_objfile
3540 = get_dwarf2_per_objfile (objfile
);
3541 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3542 + dwarf2_per_objfile
->all_type_units
.size ());
3545 for (int i
= 0; i
< total
; ++i
)
3547 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3549 if (!per_cu
->v
.quick
->compunit_symtab
)
3552 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3553 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3556 /* This dumps minimal information about the index.
3557 It is called via "mt print objfiles".
3558 One use is to verify .gdb_index has been loaded by the
3559 gdb.dwarf2/gdb-index.exp testcase. */
3562 dw2_dump (struct objfile
*objfile
)
3564 struct dwarf2_per_objfile
*dwarf2_per_objfile
3565 = get_dwarf2_per_objfile (objfile
);
3567 gdb_assert (dwarf2_per_objfile
->using_index
);
3568 printf_filtered (".gdb_index:");
3569 if (dwarf2_per_objfile
->index_table
!= NULL
)
3571 printf_filtered (" version %d\n",
3572 dwarf2_per_objfile
->index_table
->version
);
3575 printf_filtered (" faked for \"readnow\"\n");
3576 printf_filtered ("\n");
3580 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3581 const char *func_name
)
3583 struct dwarf2_per_objfile
*dwarf2_per_objfile
3584 = get_dwarf2_per_objfile (objfile
);
3586 struct dw2_symtab_iterator iter
;
3587 struct dwarf2_per_cu_data
*per_cu
;
3589 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3591 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3592 dw2_instantiate_symtab (per_cu
, false);
3597 dw2_expand_all_symtabs (struct objfile
*objfile
)
3599 struct dwarf2_per_objfile
*dwarf2_per_objfile
3600 = get_dwarf2_per_objfile (objfile
);
3601 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3602 + dwarf2_per_objfile
->all_type_units
.size ());
3604 for (int i
= 0; i
< total_units
; ++i
)
3606 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3608 /* We don't want to directly expand a partial CU, because if we
3609 read it with the wrong language, then assertion failures can
3610 be triggered later on. See PR symtab/23010. So, tell
3611 dw2_instantiate_symtab to skip partial CUs -- any important
3612 partial CU will be read via DW_TAG_imported_unit anyway. */
3613 dw2_instantiate_symtab (per_cu
, true);
3618 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3619 const char *fullname
)
3621 struct dwarf2_per_objfile
*dwarf2_per_objfile
3622 = get_dwarf2_per_objfile (objfile
);
3624 /* We don't need to consider type units here.
3625 This is only called for examining code, e.g. expand_line_sal.
3626 There can be an order of magnitude (or more) more type units
3627 than comp units, and we avoid them if we can. */
3629 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3631 /* We only need to look at symtabs not already expanded. */
3632 if (per_cu
->v
.quick
->compunit_symtab
)
3635 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3636 if (file_data
== NULL
)
3639 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3641 const char *this_fullname
= file_data
->file_names
[j
];
3643 if (filename_cmp (this_fullname
, fullname
) == 0)
3645 dw2_instantiate_symtab (per_cu
, false);
3653 dw2_expand_symtabs_matching_symbol
3654 (mapped_index_base
&index
,
3655 const lookup_name_info
&lookup_name_in
,
3656 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3657 enum search_domain kind
,
3658 gdb::function_view
<bool (offset_type
)> match_callback
);
3661 dw2_expand_symtabs_matching_one
3662 (struct dwarf2_per_cu_data
*per_cu
,
3663 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3664 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3667 dw2_map_matching_symbols
3668 (struct objfile
*objfile
,
3669 const lookup_name_info
&name
, domain_enum domain
,
3671 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3672 symbol_compare_ftype
*ordered_compare
)
3675 struct dwarf2_per_objfile
*dwarf2_per_objfile
3676 = get_dwarf2_per_objfile (objfile
);
3678 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3680 if (dwarf2_per_objfile
->index_table
!= nullptr)
3682 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3683 here though if the current language is Ada for a non-Ada objfile
3685 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
3687 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3688 auto matcher
= [&] (const char *symname
)
3690 if (ordered_compare
== nullptr)
3692 return ordered_compare (symname
, match_name
) == 0;
3695 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3696 [&] (offset_type namei
)
3698 struct dw2_symtab_iterator iter
;
3699 struct dwarf2_per_cu_data
*per_cu
;
3701 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_kind
, domain
,
3703 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3704 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
3710 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3711 proceed assuming all symtabs have been read in. */
3714 for (compunit_symtab
*cust
: objfile
->compunits ())
3716 const struct block
*block
;
3720 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3721 if (!iterate_over_symbols_terminated (block
, name
,
3727 /* Starting from a search name, return the string that finds the upper
3728 bound of all strings that start with SEARCH_NAME in a sorted name
3729 list. Returns the empty string to indicate that the upper bound is
3730 the end of the list. */
3733 make_sort_after_prefix_name (const char *search_name
)
3735 /* When looking to complete "func", we find the upper bound of all
3736 symbols that start with "func" by looking for where we'd insert
3737 the closest string that would follow "func" in lexicographical
3738 order. Usually, that's "func"-with-last-character-incremented,
3739 i.e. "fund". Mind non-ASCII characters, though. Usually those
3740 will be UTF-8 multi-byte sequences, but we can't be certain.
3741 Especially mind the 0xff character, which is a valid character in
3742 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3743 rule out compilers allowing it in identifiers. Note that
3744 conveniently, strcmp/strcasecmp are specified to compare
3745 characters interpreted as unsigned char. So what we do is treat
3746 the whole string as a base 256 number composed of a sequence of
3747 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3748 to 0, and carries 1 to the following more-significant position.
3749 If the very first character in SEARCH_NAME ends up incremented
3750 and carries/overflows, then the upper bound is the end of the
3751 list. The string after the empty string is also the empty
3754 Some examples of this operation:
3756 SEARCH_NAME => "+1" RESULT
3760 "\xff" "a" "\xff" => "\xff" "b"
3765 Then, with these symbols for example:
3771 completing "func" looks for symbols between "func" and
3772 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3773 which finds "func" and "func1", but not "fund".
3777 funcÿ (Latin1 'ÿ' [0xff])
3781 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3782 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3786 ÿÿ (Latin1 'ÿ' [0xff])
3789 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3790 the end of the list.
3792 std::string after
= search_name
;
3793 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3795 if (!after
.empty ())
3796 after
.back () = (unsigned char) after
.back () + 1;
3800 /* See declaration. */
3802 std::pair
<std::vector
<name_component
>::const_iterator
,
3803 std::vector
<name_component
>::const_iterator
>
3804 mapped_index_base::find_name_components_bounds
3805 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3808 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3810 const char *lang_name
3811 = lookup_name_without_params
.language_lookup_name (lang
);
3813 /* Comparison function object for lower_bound that matches against a
3814 given symbol name. */
3815 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3818 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3819 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3820 return name_cmp (elem_name
, name
) < 0;
3823 /* Comparison function object for upper_bound that matches against a
3824 given symbol name. */
3825 auto lookup_compare_upper
= [&] (const char *name
,
3826 const name_component
&elem
)
3828 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3829 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3830 return name_cmp (name
, elem_name
) < 0;
3833 auto begin
= this->name_components
.begin ();
3834 auto end
= this->name_components
.end ();
3836 /* Find the lower bound. */
3839 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3842 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3845 /* Find the upper bound. */
3848 if (lookup_name_without_params
.completion_mode ())
3850 /* In completion mode, we want UPPER to point past all
3851 symbols names that have the same prefix. I.e., with
3852 these symbols, and completing "func":
3854 function << lower bound
3856 other_function << upper bound
3858 We find the upper bound by looking for the insertion
3859 point of "func"-with-last-character-incremented,
3861 std::string after
= make_sort_after_prefix_name (lang_name
);
3864 return std::lower_bound (lower
, end
, after
.c_str (),
3865 lookup_compare_lower
);
3868 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3871 return {lower
, upper
};
3874 /* See declaration. */
3877 mapped_index_base::build_name_components ()
3879 if (!this->name_components
.empty ())
3882 this->name_components_casing
= case_sensitivity
;
3884 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3886 /* The code below only knows how to break apart components of C++
3887 symbol names (and other languages that use '::' as
3888 namespace/module separator) and Ada symbol names. */
3889 auto count
= this->symbol_name_count ();
3890 for (offset_type idx
= 0; idx
< count
; idx
++)
3892 if (this->symbol_name_slot_invalid (idx
))
3895 const char *name
= this->symbol_name_at (idx
);
3897 /* Add each name component to the name component table. */
3898 unsigned int previous_len
= 0;
3900 if (strstr (name
, "::") != nullptr)
3902 for (unsigned int current_len
= cp_find_first_component (name
);
3903 name
[current_len
] != '\0';
3904 current_len
+= cp_find_first_component (name
+ current_len
))
3906 gdb_assert (name
[current_len
] == ':');
3907 this->name_components
.push_back ({previous_len
, idx
});
3908 /* Skip the '::'. */
3910 previous_len
= current_len
;
3915 /* Handle the Ada encoded (aka mangled) form here. */
3916 for (const char *iter
= strstr (name
, "__");
3918 iter
= strstr (iter
, "__"))
3920 this->name_components
.push_back ({previous_len
, idx
});
3922 previous_len
= iter
- name
;
3926 this->name_components
.push_back ({previous_len
, idx
});
3929 /* Sort name_components elements by name. */
3930 auto name_comp_compare
= [&] (const name_component
&left
,
3931 const name_component
&right
)
3933 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3934 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3936 const char *left_name
= left_qualified
+ left
.name_offset
;
3937 const char *right_name
= right_qualified
+ right
.name_offset
;
3939 return name_cmp (left_name
, right_name
) < 0;
3942 std::sort (this->name_components
.begin (),
3943 this->name_components
.end (),
3947 /* Helper for dw2_expand_symtabs_matching that works with a
3948 mapped_index_base instead of the containing objfile. This is split
3949 to a separate function in order to be able to unit test the
3950 name_components matching using a mock mapped_index_base. For each
3951 symbol name that matches, calls MATCH_CALLBACK, passing it the
3952 symbol's index in the mapped_index_base symbol table. */
3955 dw2_expand_symtabs_matching_symbol
3956 (mapped_index_base
&index
,
3957 const lookup_name_info
&lookup_name_in
,
3958 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3959 enum search_domain kind
,
3960 gdb::function_view
<bool (offset_type
)> match_callback
)
3962 lookup_name_info lookup_name_without_params
3963 = lookup_name_in
.make_ignore_params ();
3965 /* Build the symbol name component sorted vector, if we haven't
3967 index
.build_name_components ();
3969 /* The same symbol may appear more than once in the range though.
3970 E.g., if we're looking for symbols that complete "w", and we have
3971 a symbol named "w1::w2", we'll find the two name components for
3972 that same symbol in the range. To be sure we only call the
3973 callback once per symbol, we first collect the symbol name
3974 indexes that matched in a temporary vector and ignore
3976 std::vector
<offset_type
> matches
;
3978 struct name_and_matcher
3980 symbol_name_matcher_ftype
*matcher
;
3983 bool operator== (const name_and_matcher
&other
) const
3985 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3989 /* A vector holding all the different symbol name matchers, for all
3991 std::vector
<name_and_matcher
> matchers
;
3993 for (int i
= 0; i
< nr_languages
; i
++)
3995 enum language lang_e
= (enum language
) i
;
3997 const language_defn
*lang
= language_def (lang_e
);
3998 symbol_name_matcher_ftype
*name_matcher
3999 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4001 name_and_matcher key
{
4003 lookup_name_without_params
.language_lookup_name (lang_e
)
4006 /* Don't insert the same comparison routine more than once.
4007 Note that we do this linear walk. This is not a problem in
4008 practice because the number of supported languages is
4010 if (std::find (matchers
.begin (), matchers
.end (), key
)
4013 matchers
.push_back (std::move (key
));
4016 = index
.find_name_components_bounds (lookup_name_without_params
,
4019 /* Now for each symbol name in range, check to see if we have a name
4020 match, and if so, call the MATCH_CALLBACK callback. */
4022 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4024 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4026 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4027 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4030 matches
.push_back (bounds
.first
->idx
);
4034 std::sort (matches
.begin (), matches
.end ());
4036 /* Finally call the callback, once per match. */
4038 for (offset_type idx
: matches
)
4042 if (!match_callback (idx
))
4048 /* Above we use a type wider than idx's for 'prev', since 0 and
4049 (offset_type)-1 are both possible values. */
4050 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4055 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4057 /* A mock .gdb_index/.debug_names-like name index table, enough to
4058 exercise dw2_expand_symtabs_matching_symbol, which works with the
4059 mapped_index_base interface. Builds an index from the symbol list
4060 passed as parameter to the constructor. */
4061 class mock_mapped_index
: public mapped_index_base
4064 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4065 : m_symbol_table (symbols
)
4068 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4070 /* Return the number of names in the symbol table. */
4071 size_t symbol_name_count () const override
4073 return m_symbol_table
.size ();
4076 /* Get the name of the symbol at IDX in the symbol table. */
4077 const char *symbol_name_at (offset_type idx
) const override
4079 return m_symbol_table
[idx
];
4083 gdb::array_view
<const char *> m_symbol_table
;
4086 /* Convenience function that converts a NULL pointer to a "<null>"
4087 string, to pass to print routines. */
4090 string_or_null (const char *str
)
4092 return str
!= NULL
? str
: "<null>";
4095 /* Check if a lookup_name_info built from
4096 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4097 index. EXPECTED_LIST is the list of expected matches, in expected
4098 matching order. If no match expected, then an empty list is
4099 specified. Returns true on success. On failure prints a warning
4100 indicating the file:line that failed, and returns false. */
4103 check_match (const char *file
, int line
,
4104 mock_mapped_index
&mock_index
,
4105 const char *name
, symbol_name_match_type match_type
,
4106 bool completion_mode
,
4107 std::initializer_list
<const char *> expected_list
)
4109 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4111 bool matched
= true;
4113 auto mismatch
= [&] (const char *expected_str
,
4116 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4117 "expected=\"%s\", got=\"%s\"\n"),
4119 (match_type
== symbol_name_match_type::FULL
4121 name
, string_or_null (expected_str
), string_or_null (got
));
4125 auto expected_it
= expected_list
.begin ();
4126 auto expected_end
= expected_list
.end ();
4128 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4130 [&] (offset_type idx
)
4132 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4133 const char *expected_str
4134 = expected_it
== expected_end
? NULL
: *expected_it
++;
4136 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4137 mismatch (expected_str
, matched_name
);
4141 const char *expected_str
4142 = expected_it
== expected_end
? NULL
: *expected_it
++;
4143 if (expected_str
!= NULL
)
4144 mismatch (expected_str
, NULL
);
4149 /* The symbols added to the mock mapped_index for testing (in
4151 static const char *test_symbols
[] = {
4160 "ns2::tmpl<int>::foo2",
4161 "(anonymous namespace)::A::B::C",
4163 /* These are used to check that the increment-last-char in the
4164 matching algorithm for completion doesn't match "t1_fund" when
4165 completing "t1_func". */
4171 /* A UTF-8 name with multi-byte sequences to make sure that
4172 cp-name-parser understands this as a single identifier ("função"
4173 is "function" in PT). */
4176 /* \377 (0xff) is Latin1 'ÿ'. */
4179 /* \377 (0xff) is Latin1 'ÿ'. */
4183 /* A name with all sorts of complications. Starts with "z" to make
4184 it easier for the completion tests below. */
4185 #define Z_SYM_NAME \
4186 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4187 "::tuple<(anonymous namespace)::ui*, " \
4188 "std::default_delete<(anonymous namespace)::ui>, void>"
4193 /* Returns true if the mapped_index_base::find_name_component_bounds
4194 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4195 in completion mode. */
4198 check_find_bounds_finds (mapped_index_base
&index
,
4199 const char *search_name
,
4200 gdb::array_view
<const char *> expected_syms
)
4202 lookup_name_info
lookup_name (search_name
,
4203 symbol_name_match_type::FULL
, true);
4205 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4208 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4209 if (distance
!= expected_syms
.size ())
4212 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4214 auto nc_elem
= bounds
.first
+ exp_elem
;
4215 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4216 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4223 /* Test the lower-level mapped_index::find_name_component_bounds
4227 test_mapped_index_find_name_component_bounds ()
4229 mock_mapped_index
mock_index (test_symbols
);
4231 mock_index
.build_name_components ();
4233 /* Test the lower-level mapped_index::find_name_component_bounds
4234 method in completion mode. */
4236 static const char *expected_syms
[] = {
4241 SELF_CHECK (check_find_bounds_finds (mock_index
,
4242 "t1_func", expected_syms
));
4245 /* Check that the increment-last-char in the name matching algorithm
4246 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4248 static const char *expected_syms1
[] = {
4252 SELF_CHECK (check_find_bounds_finds (mock_index
,
4253 "\377", expected_syms1
));
4255 static const char *expected_syms2
[] = {
4258 SELF_CHECK (check_find_bounds_finds (mock_index
,
4259 "\377\377", expected_syms2
));
4263 /* Test dw2_expand_symtabs_matching_symbol. */
4266 test_dw2_expand_symtabs_matching_symbol ()
4268 mock_mapped_index
mock_index (test_symbols
);
4270 /* We let all tests run until the end even if some fails, for debug
4272 bool any_mismatch
= false;
4274 /* Create the expected symbols list (an initializer_list). Needed
4275 because lists have commas, and we need to pass them to CHECK,
4276 which is a macro. */
4277 #define EXPECT(...) { __VA_ARGS__ }
4279 /* Wrapper for check_match that passes down the current
4280 __FILE__/__LINE__. */
4281 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4282 any_mismatch |= !check_match (__FILE__, __LINE__, \
4284 NAME, MATCH_TYPE, COMPLETION_MODE, \
4287 /* Identity checks. */
4288 for (const char *sym
: test_symbols
)
4290 /* Should be able to match all existing symbols. */
4291 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4294 /* Should be able to match all existing symbols with
4296 std::string with_params
= std::string (sym
) + "(int)";
4297 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4300 /* Should be able to match all existing symbols with
4301 parameters and qualifiers. */
4302 with_params
= std::string (sym
) + " ( int ) const";
4303 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4306 /* This should really find sym, but cp-name-parser.y doesn't
4307 know about lvalue/rvalue qualifiers yet. */
4308 with_params
= std::string (sym
) + " ( int ) &&";
4309 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4313 /* Check that the name matching algorithm for completion doesn't get
4314 confused with Latin1 'ÿ' / 0xff. */
4316 static const char str
[] = "\377";
4317 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4318 EXPECT ("\377", "\377\377123"));
4321 /* Check that the increment-last-char in the matching algorithm for
4322 completion doesn't match "t1_fund" when completing "t1_func". */
4324 static const char str
[] = "t1_func";
4325 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4326 EXPECT ("t1_func", "t1_func1"));
4329 /* Check that completion mode works at each prefix of the expected
4332 static const char str
[] = "function(int)";
4333 size_t len
= strlen (str
);
4336 for (size_t i
= 1; i
< len
; i
++)
4338 lookup
.assign (str
, i
);
4339 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4340 EXPECT ("function"));
4344 /* While "w" is a prefix of both components, the match function
4345 should still only be called once. */
4347 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4349 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4353 /* Same, with a "complicated" symbol. */
4355 static const char str
[] = Z_SYM_NAME
;
4356 size_t len
= strlen (str
);
4359 for (size_t i
= 1; i
< len
; i
++)
4361 lookup
.assign (str
, i
);
4362 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4363 EXPECT (Z_SYM_NAME
));
4367 /* In FULL mode, an incomplete symbol doesn't match. */
4369 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4373 /* A complete symbol with parameters matches any overload, since the
4374 index has no overload info. */
4376 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4377 EXPECT ("std::zfunction", "std::zfunction2"));
4378 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4379 EXPECT ("std::zfunction", "std::zfunction2"));
4380 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4381 EXPECT ("std::zfunction", "std::zfunction2"));
4384 /* Check that whitespace is ignored appropriately. A symbol with a
4385 template argument list. */
4387 static const char expected
[] = "ns::foo<int>";
4388 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4390 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4394 /* Check that whitespace is ignored appropriately. A symbol with a
4395 template argument list that includes a pointer. */
4397 static const char expected
[] = "ns::foo<char*>";
4398 /* Try both completion and non-completion modes. */
4399 static const bool completion_mode
[2] = {false, true};
4400 for (size_t i
= 0; i
< 2; i
++)
4402 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4403 completion_mode
[i
], EXPECT (expected
));
4404 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4405 completion_mode
[i
], EXPECT (expected
));
4407 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4408 completion_mode
[i
], EXPECT (expected
));
4409 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4410 completion_mode
[i
], EXPECT (expected
));
4415 /* Check method qualifiers are ignored. */
4416 static const char expected
[] = "ns::foo<char*>";
4417 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4418 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4419 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4420 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4421 CHECK_MATCH ("foo < char * > ( int ) const",
4422 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4423 CHECK_MATCH ("foo < char * > ( int ) &&",
4424 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4427 /* Test lookup names that don't match anything. */
4429 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4432 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4436 /* Some wild matching tests, exercising "(anonymous namespace)",
4437 which should not be confused with a parameter list. */
4439 static const char *syms
[] = {
4443 "A :: B :: C ( int )",
4448 for (const char *s
: syms
)
4450 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4451 EXPECT ("(anonymous namespace)::A::B::C"));
4456 static const char expected
[] = "ns2::tmpl<int>::foo2";
4457 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4459 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4463 SELF_CHECK (!any_mismatch
);
4472 test_mapped_index_find_name_component_bounds ();
4473 test_dw2_expand_symtabs_matching_symbol ();
4476 }} // namespace selftests::dw2_expand_symtabs_matching
4478 #endif /* GDB_SELF_TEST */
4480 /* If FILE_MATCHER is NULL or if PER_CU has
4481 dwarf2_per_cu_quick_data::MARK set (see
4482 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4483 EXPANSION_NOTIFY on it. */
4486 dw2_expand_symtabs_matching_one
4487 (struct dwarf2_per_cu_data
*per_cu
,
4488 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4489 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4491 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4493 bool symtab_was_null
4494 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4496 dw2_instantiate_symtab (per_cu
, false);
4498 if (expansion_notify
!= NULL
4500 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4501 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4505 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4506 matched, to expand corresponding CUs that were marked. IDX is the
4507 index of the symbol name that matched. */
4510 dw2_expand_marked_cus
4511 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4512 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4513 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4516 offset_type
*vec
, vec_len
, vec_idx
;
4517 bool global_seen
= false;
4518 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4520 vec
= (offset_type
*) (index
.constant_pool
4521 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4522 vec_len
= MAYBE_SWAP (vec
[0]);
4523 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4525 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4526 /* This value is only valid for index versions >= 7. */
4527 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4528 gdb_index_symbol_kind symbol_kind
=
4529 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4530 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4531 /* Only check the symbol attributes if they're present.
4532 Indices prior to version 7 don't record them,
4533 and indices >= 7 may elide them for certain symbols
4534 (gold does this). */
4537 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4539 /* Work around gold/15646. */
4542 if (!is_static
&& global_seen
)
4548 /* Only check the symbol's kind if it has one. */
4553 case VARIABLES_DOMAIN
:
4554 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4557 case FUNCTIONS_DOMAIN
:
4558 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4562 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4565 case MODULES_DOMAIN
:
4566 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4574 /* Don't crash on bad data. */
4575 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4576 + dwarf2_per_objfile
->all_type_units
.size ()))
4578 complaint (_(".gdb_index entry has bad CU index"
4580 objfile_name (dwarf2_per_objfile
->objfile
));
4584 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4585 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4590 /* If FILE_MATCHER is non-NULL, set all the
4591 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4592 that match FILE_MATCHER. */
4595 dw_expand_symtabs_matching_file_matcher
4596 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4597 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4599 if (file_matcher
== NULL
)
4602 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4604 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4606 NULL
, xcalloc
, xfree
));
4607 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4609 NULL
, xcalloc
, xfree
));
4611 /* The rule is CUs specify all the files, including those used by
4612 any TU, so there's no need to scan TUs here. */
4614 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4618 per_cu
->v
.quick
->mark
= 0;
4620 /* We only need to look at symtabs not already expanded. */
4621 if (per_cu
->v
.quick
->compunit_symtab
)
4624 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4625 if (file_data
== NULL
)
4628 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4630 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4632 per_cu
->v
.quick
->mark
= 1;
4636 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4638 const char *this_real_name
;
4640 if (file_matcher (file_data
->file_names
[j
], false))
4642 per_cu
->v
.quick
->mark
= 1;
4646 /* Before we invoke realpath, which can get expensive when many
4647 files are involved, do a quick comparison of the basenames. */
4648 if (!basenames_may_differ
4649 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4653 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4654 if (file_matcher (this_real_name
, false))
4656 per_cu
->v
.quick
->mark
= 1;
4661 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4662 ? visited_found
.get ()
4663 : visited_not_found
.get (),
4670 dw2_expand_symtabs_matching
4671 (struct objfile
*objfile
,
4672 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4673 const lookup_name_info
*lookup_name
,
4674 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4675 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4676 enum search_domain kind
)
4678 struct dwarf2_per_objfile
*dwarf2_per_objfile
4679 = get_dwarf2_per_objfile (objfile
);
4681 /* index_table is NULL if OBJF_READNOW. */
4682 if (!dwarf2_per_objfile
->index_table
)
4685 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4687 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4689 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4693 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4699 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4701 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4703 kind
, [&] (offset_type idx
)
4705 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4706 expansion_notify
, kind
);
4711 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4714 static struct compunit_symtab
*
4715 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4720 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4721 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4724 if (cust
->includes
== NULL
)
4727 for (i
= 0; cust
->includes
[i
]; ++i
)
4729 struct compunit_symtab
*s
= cust
->includes
[i
];
4731 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4739 static struct compunit_symtab
*
4740 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4741 struct bound_minimal_symbol msymbol
,
4743 struct obj_section
*section
,
4746 struct dwarf2_per_cu_data
*data
;
4747 struct compunit_symtab
*result
;
4749 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4752 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4753 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4754 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4758 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4759 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4760 paddress (objfile
->arch (), pc
));
4763 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4766 gdb_assert (result
!= NULL
);
4771 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4772 void *data
, int need_fullname
)
4774 struct dwarf2_per_objfile
*dwarf2_per_objfile
4775 = get_dwarf2_per_objfile (objfile
);
4777 if (!dwarf2_per_objfile
->filenames_cache
)
4779 dwarf2_per_objfile
->filenames_cache
.emplace ();
4781 htab_up
visited (htab_create_alloc (10,
4782 htab_hash_pointer
, htab_eq_pointer
,
4783 NULL
, xcalloc
, xfree
));
4785 /* The rule is CUs specify all the files, including those used
4786 by any TU, so there's no need to scan TUs here. We can
4787 ignore file names coming from already-expanded CUs. */
4789 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4791 if (per_cu
->v
.quick
->compunit_symtab
)
4793 void **slot
= htab_find_slot (visited
.get (),
4794 per_cu
->v
.quick
->file_names
,
4797 *slot
= per_cu
->v
.quick
->file_names
;
4801 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4803 /* We only need to look at symtabs not already expanded. */
4804 if (per_cu
->v
.quick
->compunit_symtab
)
4807 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4808 if (file_data
== NULL
)
4811 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4814 /* Already visited. */
4819 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4821 const char *filename
= file_data
->file_names
[j
];
4822 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4827 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4829 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4832 this_real_name
= gdb_realpath (filename
);
4833 (*fun
) (filename
, this_real_name
.get (), data
);
4838 dw2_has_symbols (struct objfile
*objfile
)
4843 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4846 dw2_find_last_source_symtab
,
4847 dw2_forget_cached_source_info
,
4848 dw2_map_symtabs_matching_filename
,
4853 dw2_expand_symtabs_for_function
,
4854 dw2_expand_all_symtabs
,
4855 dw2_expand_symtabs_with_fullname
,
4856 dw2_map_matching_symbols
,
4857 dw2_expand_symtabs_matching
,
4858 dw2_find_pc_sect_compunit_symtab
,
4860 dw2_map_symbol_filenames
4863 /* DWARF-5 debug_names reader. */
4865 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4866 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4868 /* A helper function that reads the .debug_names section in SECTION
4869 and fills in MAP. FILENAME is the name of the file containing the
4870 section; it is used for error reporting.
4872 Returns true if all went well, false otherwise. */
4875 read_debug_names_from_section (struct objfile
*objfile
,
4876 const char *filename
,
4877 struct dwarf2_section_info
*section
,
4878 mapped_debug_names
&map
)
4880 if (section
->empty ())
4883 /* Older elfutils strip versions could keep the section in the main
4884 executable while splitting it for the separate debug info file. */
4885 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4888 section
->read (objfile
);
4890 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4892 const gdb_byte
*addr
= section
->buffer
;
4894 bfd
*const abfd
= section
->get_bfd_owner ();
4896 unsigned int bytes_read
;
4897 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4900 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4901 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4902 if (bytes_read
+ length
!= section
->size
)
4904 /* There may be multiple per-CU indices. */
4905 warning (_("Section .debug_names in %s length %s does not match "
4906 "section length %s, ignoring .debug_names."),
4907 filename
, plongest (bytes_read
+ length
),
4908 pulongest (section
->size
));
4912 /* The version number. */
4913 uint16_t version
= read_2_bytes (abfd
, addr
);
4917 warning (_("Section .debug_names in %s has unsupported version %d, "
4918 "ignoring .debug_names."),
4924 uint16_t padding
= read_2_bytes (abfd
, addr
);
4928 warning (_("Section .debug_names in %s has unsupported padding %d, "
4929 "ignoring .debug_names."),
4934 /* comp_unit_count - The number of CUs in the CU list. */
4935 map
.cu_count
= read_4_bytes (abfd
, addr
);
4938 /* local_type_unit_count - The number of TUs in the local TU
4940 map
.tu_count
= read_4_bytes (abfd
, addr
);
4943 /* foreign_type_unit_count - The number of TUs in the foreign TU
4945 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4947 if (foreign_tu_count
!= 0)
4949 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4950 "ignoring .debug_names."),
4951 filename
, static_cast<unsigned long> (foreign_tu_count
));
4955 /* bucket_count - The number of hash buckets in the hash lookup
4957 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4960 /* name_count - The number of unique names in the index. */
4961 map
.name_count
= read_4_bytes (abfd
, addr
);
4964 /* abbrev_table_size - The size in bytes of the abbreviations
4966 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4969 /* augmentation_string_size - The size in bytes of the augmentation
4970 string. This value is rounded up to a multiple of 4. */
4971 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4973 map
.augmentation_is_gdb
= ((augmentation_string_size
4974 == sizeof (dwarf5_augmentation
))
4975 && memcmp (addr
, dwarf5_augmentation
,
4976 sizeof (dwarf5_augmentation
)) == 0);
4977 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4978 addr
+= augmentation_string_size
;
4981 map
.cu_table_reordered
= addr
;
4982 addr
+= map
.cu_count
* map
.offset_size
;
4984 /* List of Local TUs */
4985 map
.tu_table_reordered
= addr
;
4986 addr
+= map
.tu_count
* map
.offset_size
;
4988 /* Hash Lookup Table */
4989 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4990 addr
+= map
.bucket_count
* 4;
4991 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4992 addr
+= map
.name_count
* 4;
4995 map
.name_table_string_offs_reordered
= addr
;
4996 addr
+= map
.name_count
* map
.offset_size
;
4997 map
.name_table_entry_offs_reordered
= addr
;
4998 addr
+= map
.name_count
* map
.offset_size
;
5000 const gdb_byte
*abbrev_table_start
= addr
;
5003 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5008 const auto insertpair
5009 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5010 if (!insertpair
.second
)
5012 warning (_("Section .debug_names in %s has duplicate index %s, "
5013 "ignoring .debug_names."),
5014 filename
, pulongest (index_num
));
5017 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5018 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5023 mapped_debug_names::index_val::attr attr
;
5024 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5026 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5028 if (attr
.form
== DW_FORM_implicit_const
)
5030 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5034 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5036 indexval
.attr_vec
.push_back (std::move (attr
));
5039 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5041 warning (_("Section .debug_names in %s has abbreviation_table "
5042 "of size %s vs. written as %u, ignoring .debug_names."),
5043 filename
, plongest (addr
- abbrev_table_start
),
5047 map
.entry_pool
= addr
;
5052 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5056 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5057 const mapped_debug_names
&map
,
5058 dwarf2_section_info
§ion
,
5061 if (!map
.augmentation_is_gdb
)
5063 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5065 sect_offset sect_off
5066 = (sect_offset
) (extract_unsigned_integer
5067 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5069 map
.dwarf5_byte_order
));
5070 /* We don't know the length of the CU, because the CU list in a
5071 .debug_names index can be incomplete, so we can't use the start of
5072 the next CU as end of this CU. We create the CUs here with length 0,
5073 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5074 dwarf2_per_cu_data
*per_cu
5075 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5077 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5081 sect_offset sect_off_prev
;
5082 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5084 sect_offset sect_off_next
;
5085 if (i
< map
.cu_count
)
5088 = (sect_offset
) (extract_unsigned_integer
5089 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5091 map
.dwarf5_byte_order
));
5094 sect_off_next
= (sect_offset
) section
.size
;
5097 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5098 dwarf2_per_cu_data
*per_cu
5099 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5100 sect_off_prev
, length
);
5101 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5103 sect_off_prev
= sect_off_next
;
5107 /* Read the CU list from the mapped index, and use it to create all
5108 the CU objects for this dwarf2_per_objfile. */
5111 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5112 const mapped_debug_names
&map
,
5113 const mapped_debug_names
&dwz_map
)
5115 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5116 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5118 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5119 dwarf2_per_objfile
->info
,
5120 false /* is_dwz */);
5122 if (dwz_map
.cu_count
== 0)
5125 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5126 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5130 /* Read .debug_names. If everything went ok, initialize the "quick"
5131 elements of all the CUs and return true. Otherwise, return false. */
5134 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5136 std::unique_ptr
<mapped_debug_names
> map
5137 (new mapped_debug_names (dwarf2_per_objfile
));
5138 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5139 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5141 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5142 &dwarf2_per_objfile
->debug_names
,
5146 /* Don't use the index if it's empty. */
5147 if (map
->name_count
== 0)
5150 /* If there is a .dwz file, read it so we can get its CU list as
5152 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5155 if (!read_debug_names_from_section (objfile
,
5156 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5157 &dwz
->debug_names
, dwz_map
))
5159 warning (_("could not read '.debug_names' section from %s; skipping"),
5160 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5165 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5167 if (map
->tu_count
!= 0)
5169 /* We can only handle a single .debug_types when we have an
5171 if (dwarf2_per_objfile
->types
.size () != 1)
5174 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5176 create_signatured_type_table_from_debug_names
5177 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5180 create_addrmap_from_aranges (dwarf2_per_objfile
,
5181 &dwarf2_per_objfile
->debug_aranges
);
5183 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5184 dwarf2_per_objfile
->using_index
= 1;
5185 dwarf2_per_objfile
->quick_file_names_table
=
5186 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5191 /* Type used to manage iterating over all CUs looking for a symbol for
5194 class dw2_debug_names_iterator
5197 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5198 gdb::optional
<block_enum
> block_index
,
5201 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5202 m_addr (find_vec_in_debug_names (map
, name
))
5205 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5206 search_domain search
, uint32_t namei
)
5209 m_addr (find_vec_in_debug_names (map
, namei
))
5212 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5213 block_enum block_index
, domain_enum domain
,
5215 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5216 m_addr (find_vec_in_debug_names (map
, namei
))
5219 /* Return the next matching CU or NULL if there are no more. */
5220 dwarf2_per_cu_data
*next ();
5223 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5225 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5228 /* The internalized form of .debug_names. */
5229 const mapped_debug_names
&m_map
;
5231 /* If set, only look for symbols that match that block. Valid values are
5232 GLOBAL_BLOCK and STATIC_BLOCK. */
5233 const gdb::optional
<block_enum
> m_block_index
;
5235 /* The kind of symbol we're looking for. */
5236 const domain_enum m_domain
= UNDEF_DOMAIN
;
5237 const search_domain m_search
= ALL_DOMAIN
;
5239 /* The list of CUs from the index entry of the symbol, or NULL if
5241 const gdb_byte
*m_addr
;
5245 mapped_debug_names::namei_to_name (uint32_t namei
) const
5247 const ULONGEST namei_string_offs
5248 = extract_unsigned_integer ((name_table_string_offs_reordered
5249 + namei
* offset_size
),
5252 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5256 /* Find a slot in .debug_names for the object named NAME. If NAME is
5257 found, return pointer to its pool data. If NAME cannot be found,
5261 dw2_debug_names_iterator::find_vec_in_debug_names
5262 (const mapped_debug_names
&map
, const char *name
)
5264 int (*cmp
) (const char *, const char *);
5266 gdb::unique_xmalloc_ptr
<char> without_params
;
5267 if (current_language
->la_language
== language_cplus
5268 || current_language
->la_language
== language_fortran
5269 || current_language
->la_language
== language_d
)
5271 /* NAME is already canonical. Drop any qualifiers as
5272 .debug_names does not contain any. */
5274 if (strchr (name
, '(') != NULL
)
5276 without_params
= cp_remove_params (name
);
5277 if (without_params
!= NULL
)
5278 name
= without_params
.get ();
5282 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5284 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5286 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5287 (map
.bucket_table_reordered
5288 + (full_hash
% map
.bucket_count
)), 4,
5289 map
.dwarf5_byte_order
);
5293 if (namei
>= map
.name_count
)
5295 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5297 namei
, map
.name_count
,
5298 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5304 const uint32_t namei_full_hash
5305 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5306 (map
.hash_table_reordered
+ namei
), 4,
5307 map
.dwarf5_byte_order
);
5308 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5311 if (full_hash
== namei_full_hash
)
5313 const char *const namei_string
= map
.namei_to_name (namei
);
5315 #if 0 /* An expensive sanity check. */
5316 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5318 complaint (_("Wrong .debug_names hash for string at index %u "
5320 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5325 if (cmp (namei_string
, name
) == 0)
5327 const ULONGEST namei_entry_offs
5328 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5329 + namei
* map
.offset_size
),
5330 map
.offset_size
, map
.dwarf5_byte_order
);
5331 return map
.entry_pool
+ namei_entry_offs
;
5336 if (namei
>= map
.name_count
)
5342 dw2_debug_names_iterator::find_vec_in_debug_names
5343 (const mapped_debug_names
&map
, uint32_t namei
)
5345 if (namei
>= map
.name_count
)
5347 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5349 namei
, map
.name_count
,
5350 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5354 const ULONGEST namei_entry_offs
5355 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5356 + namei
* map
.offset_size
),
5357 map
.offset_size
, map
.dwarf5_byte_order
);
5358 return map
.entry_pool
+ namei_entry_offs
;
5361 /* See dw2_debug_names_iterator. */
5363 dwarf2_per_cu_data
*
5364 dw2_debug_names_iterator::next ()
5369 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5370 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5371 bfd
*const abfd
= objfile
->obfd
;
5375 unsigned int bytes_read
;
5376 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5377 m_addr
+= bytes_read
;
5381 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5382 if (indexval_it
== m_map
.abbrev_map
.cend ())
5384 complaint (_("Wrong .debug_names undefined abbrev code %s "
5386 pulongest (abbrev
), objfile_name (objfile
));
5389 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5390 enum class symbol_linkage
{
5394 } symbol_linkage_
= symbol_linkage::unknown
;
5395 dwarf2_per_cu_data
*per_cu
= NULL
;
5396 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5401 case DW_FORM_implicit_const
:
5402 ull
= attr
.implicit_const
;
5404 case DW_FORM_flag_present
:
5408 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5409 m_addr
+= bytes_read
;
5412 ull
= read_4_bytes (abfd
, m_addr
);
5416 ull
= read_8_bytes (abfd
, m_addr
);
5419 case DW_FORM_ref_sig8
:
5420 ull
= read_8_bytes (abfd
, m_addr
);
5424 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5425 dwarf_form_name (attr
.form
),
5426 objfile_name (objfile
));
5429 switch (attr
.dw_idx
)
5431 case DW_IDX_compile_unit
:
5432 /* Don't crash on bad data. */
5433 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5435 complaint (_(".debug_names entry has bad CU index %s"
5438 objfile_name (dwarf2_per_objfile
->objfile
));
5441 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5443 case DW_IDX_type_unit
:
5444 /* Don't crash on bad data. */
5445 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5447 complaint (_(".debug_names entry has bad TU index %s"
5450 objfile_name (dwarf2_per_objfile
->objfile
));
5453 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5455 case DW_IDX_die_offset
:
5456 /* In a per-CU index (as opposed to a per-module index), index
5457 entries without CU attribute implicitly refer to the single CU. */
5459 per_cu
= dwarf2_per_objfile
->get_cu (0);
5461 case DW_IDX_GNU_internal
:
5462 if (!m_map
.augmentation_is_gdb
)
5464 symbol_linkage_
= symbol_linkage::static_
;
5466 case DW_IDX_GNU_external
:
5467 if (!m_map
.augmentation_is_gdb
)
5469 symbol_linkage_
= symbol_linkage::extern_
;
5474 /* Skip if already read in. */
5475 if (per_cu
->v
.quick
->compunit_symtab
)
5478 /* Check static vs global. */
5479 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5481 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5482 const bool symbol_is_static
=
5483 symbol_linkage_
== symbol_linkage::static_
;
5484 if (want_static
!= symbol_is_static
)
5488 /* Match dw2_symtab_iter_next, symbol_kind
5489 and debug_names::psymbol_tag. */
5493 switch (indexval
.dwarf_tag
)
5495 case DW_TAG_variable
:
5496 case DW_TAG_subprogram
:
5497 /* Some types are also in VAR_DOMAIN. */
5498 case DW_TAG_typedef
:
5499 case DW_TAG_structure_type
:
5506 switch (indexval
.dwarf_tag
)
5508 case DW_TAG_typedef
:
5509 case DW_TAG_structure_type
:
5516 switch (indexval
.dwarf_tag
)
5519 case DW_TAG_variable
:
5526 switch (indexval
.dwarf_tag
)
5538 /* Match dw2_expand_symtabs_matching, symbol_kind and
5539 debug_names::psymbol_tag. */
5542 case VARIABLES_DOMAIN
:
5543 switch (indexval
.dwarf_tag
)
5545 case DW_TAG_variable
:
5551 case FUNCTIONS_DOMAIN
:
5552 switch (indexval
.dwarf_tag
)
5554 case DW_TAG_subprogram
:
5561 switch (indexval
.dwarf_tag
)
5563 case DW_TAG_typedef
:
5564 case DW_TAG_structure_type
:
5570 case MODULES_DOMAIN
:
5571 switch (indexval
.dwarf_tag
)
5585 static struct compunit_symtab
*
5586 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5587 const char *name
, domain_enum domain
)
5589 struct dwarf2_per_objfile
*dwarf2_per_objfile
5590 = get_dwarf2_per_objfile (objfile
);
5592 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5595 /* index is NULL if OBJF_READNOW. */
5598 const auto &map
= *mapp
;
5600 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5602 struct compunit_symtab
*stab_best
= NULL
;
5603 struct dwarf2_per_cu_data
*per_cu
;
5604 while ((per_cu
= iter
.next ()) != NULL
)
5606 struct symbol
*sym
, *with_opaque
= NULL
;
5607 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5608 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5609 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5611 sym
= block_find_symbol (block
, name
, domain
,
5612 block_find_non_opaque_type_preferred
,
5615 /* Some caution must be observed with overloaded functions and
5616 methods, since the index will not contain any overload
5617 information (but NAME might contain it). */
5620 && strcmp_iw (sym
->search_name (), name
) == 0)
5622 if (with_opaque
!= NULL
5623 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5626 /* Keep looking through other CUs. */
5632 /* This dumps minimal information about .debug_names. It is called
5633 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5634 uses this to verify that .debug_names has been loaded. */
5637 dw2_debug_names_dump (struct objfile
*objfile
)
5639 struct dwarf2_per_objfile
*dwarf2_per_objfile
5640 = get_dwarf2_per_objfile (objfile
);
5642 gdb_assert (dwarf2_per_objfile
->using_index
);
5643 printf_filtered (".debug_names:");
5644 if (dwarf2_per_objfile
->debug_names_table
)
5645 printf_filtered (" exists\n");
5647 printf_filtered (" faked for \"readnow\"\n");
5648 printf_filtered ("\n");
5652 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5653 const char *func_name
)
5655 struct dwarf2_per_objfile
*dwarf2_per_objfile
5656 = get_dwarf2_per_objfile (objfile
);
5658 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5659 if (dwarf2_per_objfile
->debug_names_table
)
5661 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5663 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5665 struct dwarf2_per_cu_data
*per_cu
;
5666 while ((per_cu
= iter
.next ()) != NULL
)
5667 dw2_instantiate_symtab (per_cu
, false);
5672 dw2_debug_names_map_matching_symbols
5673 (struct objfile
*objfile
,
5674 const lookup_name_info
&name
, domain_enum domain
,
5676 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5677 symbol_compare_ftype
*ordered_compare
)
5679 struct dwarf2_per_objfile
*dwarf2_per_objfile
5680 = get_dwarf2_per_objfile (objfile
);
5682 /* debug_names_table is NULL if OBJF_READNOW. */
5683 if (!dwarf2_per_objfile
->debug_names_table
)
5686 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5687 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5689 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5690 auto matcher
= [&] (const char *symname
)
5692 if (ordered_compare
== nullptr)
5694 return ordered_compare (symname
, match_name
) == 0;
5697 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5698 [&] (offset_type namei
)
5700 /* The name was matched, now expand corresponding CUs that were
5702 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5704 struct dwarf2_per_cu_data
*per_cu
;
5705 while ((per_cu
= iter
.next ()) != NULL
)
5706 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5710 /* It's a shame we couldn't do this inside the
5711 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5712 that have already been expanded. Instead, this loop matches what
5713 the psymtab code does. */
5714 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5716 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5717 if (cust
!= nullptr)
5719 const struct block
*block
5720 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5721 if (!iterate_over_symbols_terminated (block
, name
,
5729 dw2_debug_names_expand_symtabs_matching
5730 (struct objfile
*objfile
,
5731 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5732 const lookup_name_info
*lookup_name
,
5733 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5734 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5735 enum search_domain kind
)
5737 struct dwarf2_per_objfile
*dwarf2_per_objfile
5738 = get_dwarf2_per_objfile (objfile
);
5740 /* debug_names_table is NULL if OBJF_READNOW. */
5741 if (!dwarf2_per_objfile
->debug_names_table
)
5744 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5746 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5748 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5752 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5758 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5760 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5762 kind
, [&] (offset_type namei
)
5764 /* The name was matched, now expand corresponding CUs that were
5766 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5768 struct dwarf2_per_cu_data
*per_cu
;
5769 while ((per_cu
= iter
.next ()) != NULL
)
5770 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5776 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5779 dw2_find_last_source_symtab
,
5780 dw2_forget_cached_source_info
,
5781 dw2_map_symtabs_matching_filename
,
5782 dw2_debug_names_lookup_symbol
,
5785 dw2_debug_names_dump
,
5786 dw2_debug_names_expand_symtabs_for_function
,
5787 dw2_expand_all_symtabs
,
5788 dw2_expand_symtabs_with_fullname
,
5789 dw2_debug_names_map_matching_symbols
,
5790 dw2_debug_names_expand_symtabs_matching
,
5791 dw2_find_pc_sect_compunit_symtab
,
5793 dw2_map_symbol_filenames
5796 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5797 to either a dwarf2_per_objfile or dwz_file object. */
5799 template <typename T
>
5800 static gdb::array_view
<const gdb_byte
>
5801 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5803 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5805 if (section
->empty ())
5808 /* Older elfutils strip versions could keep the section in the main
5809 executable while splitting it for the separate debug info file. */
5810 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5813 section
->read (obj
);
5815 /* dwarf2_section_info::size is a bfd_size_type, while
5816 gdb::array_view works with size_t. On 32-bit hosts, with
5817 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5818 is 32-bit. So we need an explicit narrowing conversion here.
5819 This is fine, because it's impossible to allocate or mmap an
5820 array/buffer larger than what size_t can represent. */
5821 return gdb::make_array_view (section
->buffer
, section
->size
);
5824 /* Lookup the index cache for the contents of the index associated to
5827 static gdb::array_view
<const gdb_byte
>
5828 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5830 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5831 if (build_id
== nullptr)
5834 return global_index_cache
.lookup_gdb_index (build_id
,
5835 &dwarf2_obj
->index_cache_res
);
5838 /* Same as the above, but for DWZ. */
5840 static gdb::array_view
<const gdb_byte
>
5841 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5843 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5844 if (build_id
== nullptr)
5847 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5850 /* See symfile.h. */
5853 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5855 struct dwarf2_per_objfile
*dwarf2_per_objfile
5856 = get_dwarf2_per_objfile (objfile
);
5858 /* If we're about to read full symbols, don't bother with the
5859 indices. In this case we also don't care if some other debug
5860 format is making psymtabs, because they are all about to be
5862 if ((objfile
->flags
& OBJF_READNOW
))
5864 dwarf2_per_objfile
->using_index
= 1;
5865 create_all_comp_units (dwarf2_per_objfile
);
5866 create_all_type_units (dwarf2_per_objfile
);
5867 dwarf2_per_objfile
->quick_file_names_table
5868 = create_quick_file_names_table
5869 (dwarf2_per_objfile
->all_comp_units
.size ());
5871 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5872 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5874 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5876 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5877 struct dwarf2_per_cu_quick_data
);
5880 /* Return 1 so that gdb sees the "quick" functions. However,
5881 these functions will be no-ops because we will have expanded
5883 *index_kind
= dw_index_kind::GDB_INDEX
;
5887 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5889 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5893 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5894 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5895 get_gdb_index_contents_from_section
<dwz_file
>))
5897 *index_kind
= dw_index_kind::GDB_INDEX
;
5901 /* ... otherwise, try to find the index in the index cache. */
5902 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5903 get_gdb_index_contents_from_cache
,
5904 get_gdb_index_contents_from_cache_dwz
))
5906 global_index_cache
.hit ();
5907 *index_kind
= dw_index_kind::GDB_INDEX
;
5911 global_index_cache
.miss ();
5917 /* Build a partial symbol table. */
5920 dwarf2_build_psymtabs (struct objfile
*objfile
)
5922 struct dwarf2_per_objfile
*dwarf2_per_objfile
5923 = get_dwarf2_per_objfile (objfile
);
5925 init_psymbol_list (objfile
, 1024);
5929 /* This isn't really ideal: all the data we allocate on the
5930 objfile's obstack is still uselessly kept around. However,
5931 freeing it seems unsafe. */
5932 psymtab_discarder
psymtabs (objfile
);
5933 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5936 /* (maybe) store an index in the cache. */
5937 global_index_cache
.store (dwarf2_per_objfile
);
5939 catch (const gdb_exception_error
&except
)
5941 exception_print (gdb_stderr
, except
);
5945 /* Find the base address of the compilation unit for range lists and
5946 location lists. It will normally be specified by DW_AT_low_pc.
5947 In DWARF-3 draft 4, the base address could be overridden by
5948 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5949 compilation units with discontinuous ranges. */
5952 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5954 struct attribute
*attr
;
5956 cu
->base_address
.reset ();
5958 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5959 if (attr
!= nullptr)
5960 cu
->base_address
= attr
->value_as_address ();
5963 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5964 if (attr
!= nullptr)
5965 cu
->base_address
= attr
->value_as_address ();
5969 /* Helper function that returns the proper abbrev section for
5972 static struct dwarf2_section_info
*
5973 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5975 struct dwarf2_section_info
*abbrev
;
5976 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5978 if (this_cu
->is_dwz
)
5979 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5981 abbrev
= &dwarf2_per_objfile
->abbrev
;
5986 /* Fetch the abbreviation table offset from a comp or type unit header. */
5989 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5990 struct dwarf2_section_info
*section
,
5991 sect_offset sect_off
)
5993 bfd
*abfd
= section
->get_bfd_owner ();
5994 const gdb_byte
*info_ptr
;
5995 unsigned int initial_length_size
, offset_size
;
5998 section
->read (dwarf2_per_objfile
->objfile
);
5999 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6000 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6001 offset_size
= initial_length_size
== 4 ? 4 : 8;
6002 info_ptr
+= initial_length_size
;
6004 version
= read_2_bytes (abfd
, info_ptr
);
6008 /* Skip unit type and address size. */
6012 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6015 /* A partial symtab that is used only for include files. */
6016 struct dwarf2_include_psymtab
: public partial_symtab
6018 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6019 : partial_symtab (filename
, objfile
)
6023 void read_symtab (struct objfile
*objfile
) override
6025 /* It's an include file, no symbols to read for it.
6026 Everything is in the includer symtab. */
6028 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6029 expansion of the includer psymtab. We use the dependencies[0] field to
6030 model the includer. But if we go the regular route of calling
6031 expand_psymtab here, and having expand_psymtab call expand_dependencies
6032 to expand the includer, we'll only use expand_psymtab on the includer
6033 (making it a non-toplevel psymtab), while if we expand the includer via
6034 another path, we'll use read_symtab (making it a toplevel psymtab).
6035 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6036 psymtab, and trigger read_symtab on the includer here directly. */
6037 includer ()->read_symtab (objfile
);
6040 void expand_psymtab (struct objfile
*objfile
) override
6042 /* This is not called by read_symtab, and should not be called by any
6043 expand_dependencies. */
6047 bool readin_p () const override
6049 return includer ()->readin_p ();
6052 struct compunit_symtab
*get_compunit_symtab () const override
6058 partial_symtab
*includer () const
6060 /* An include psymtab has exactly one dependency: the psymtab that
6062 gdb_assert (this->number_of_dependencies
== 1);
6063 return this->dependencies
[0];
6067 /* Allocate a new partial symtab for file named NAME and mark this new
6068 partial symtab as being an include of PST. */
6071 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6072 struct objfile
*objfile
)
6074 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6076 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6078 /* It shares objfile->objfile_obstack. */
6079 subpst
->dirname
= pst
->dirname
;
6082 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6083 subpst
->dependencies
[0] = pst
;
6084 subpst
->number_of_dependencies
= 1;
6087 /* Read the Line Number Program data and extract the list of files
6088 included by the source file represented by PST. Build an include
6089 partial symtab for each of these included files. */
6092 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6093 struct die_info
*die
,
6094 dwarf2_psymtab
*pst
)
6097 struct attribute
*attr
;
6099 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6100 if (attr
!= nullptr)
6101 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6103 return; /* No linetable, so no includes. */
6105 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6106 that we pass in the raw text_low here; that is ok because we're
6107 only decoding the line table to make include partial symtabs, and
6108 so the addresses aren't really used. */
6109 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6110 pst
->raw_text_low (), 1);
6114 hash_signatured_type (const void *item
)
6116 const struct signatured_type
*sig_type
6117 = (const struct signatured_type
*) item
;
6119 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6120 return sig_type
->signature
;
6124 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6126 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6127 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6129 return lhs
->signature
== rhs
->signature
;
6132 /* Allocate a hash table for signatured types. */
6135 allocate_signatured_type_table ()
6137 return htab_up (htab_create_alloc (41,
6138 hash_signatured_type
,
6140 NULL
, xcalloc
, xfree
));
6143 /* A helper function to add a signatured type CU to a table. */
6146 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6148 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6149 std::vector
<signatured_type
*> *all_type_units
6150 = (std::vector
<signatured_type
*> *) datum
;
6152 all_type_units
->push_back (sigt
);
6157 /* A helper for create_debug_types_hash_table. Read types from SECTION
6158 and fill them into TYPES_HTAB. It will process only type units,
6159 therefore DW_UT_type. */
6162 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6163 struct dwo_file
*dwo_file
,
6164 dwarf2_section_info
*section
, htab_up
&types_htab
,
6165 rcuh_kind section_kind
)
6167 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6168 struct dwarf2_section_info
*abbrev_section
;
6170 const gdb_byte
*info_ptr
, *end_ptr
;
6172 abbrev_section
= (dwo_file
!= NULL
6173 ? &dwo_file
->sections
.abbrev
6174 : &dwarf2_per_objfile
->abbrev
);
6176 if (dwarf_read_debug
)
6177 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6178 section
->get_name (),
6179 abbrev_section
->get_file_name ());
6181 section
->read (objfile
);
6182 info_ptr
= section
->buffer
;
6184 if (info_ptr
== NULL
)
6187 /* We can't set abfd until now because the section may be empty or
6188 not present, in which case the bfd is unknown. */
6189 abfd
= section
->get_bfd_owner ();
6191 /* We don't use cutu_reader here because we don't need to read
6192 any dies: the signature is in the header. */
6194 end_ptr
= info_ptr
+ section
->size
;
6195 while (info_ptr
< end_ptr
)
6197 struct signatured_type
*sig_type
;
6198 struct dwo_unit
*dwo_tu
;
6200 const gdb_byte
*ptr
= info_ptr
;
6201 struct comp_unit_head header
;
6202 unsigned int length
;
6204 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6206 /* Initialize it due to a false compiler warning. */
6207 header
.signature
= -1;
6208 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6210 /* We need to read the type's signature in order to build the hash
6211 table, but we don't need anything else just yet. */
6213 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6214 abbrev_section
, ptr
, section_kind
);
6216 length
= header
.get_length ();
6218 /* Skip dummy type units. */
6219 if (ptr
>= info_ptr
+ length
6220 || peek_abbrev_code (abfd
, ptr
) == 0
6221 || header
.unit_type
!= DW_UT_type
)
6227 if (types_htab
== NULL
)
6230 types_htab
= allocate_dwo_unit_table ();
6232 types_htab
= allocate_signatured_type_table ();
6238 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6240 dwo_tu
->dwo_file
= dwo_file
;
6241 dwo_tu
->signature
= header
.signature
;
6242 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6243 dwo_tu
->section
= section
;
6244 dwo_tu
->sect_off
= sect_off
;
6245 dwo_tu
->length
= length
;
6249 /* N.B.: type_offset is not usable if this type uses a DWO file.
6250 The real type_offset is in the DWO file. */
6252 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6253 struct signatured_type
);
6254 sig_type
->signature
= header
.signature
;
6255 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6256 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6257 sig_type
->per_cu
.is_debug_types
= 1;
6258 sig_type
->per_cu
.section
= section
;
6259 sig_type
->per_cu
.sect_off
= sect_off
;
6260 sig_type
->per_cu
.length
= length
;
6263 slot
= htab_find_slot (types_htab
.get (),
6264 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6266 gdb_assert (slot
!= NULL
);
6269 sect_offset dup_sect_off
;
6273 const struct dwo_unit
*dup_tu
6274 = (const struct dwo_unit
*) *slot
;
6276 dup_sect_off
= dup_tu
->sect_off
;
6280 const struct signatured_type
*dup_tu
6281 = (const struct signatured_type
*) *slot
;
6283 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6286 complaint (_("debug type entry at offset %s is duplicate to"
6287 " the entry at offset %s, signature %s"),
6288 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6289 hex_string (header
.signature
));
6291 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6293 if (dwarf_read_debug
> 1)
6294 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6295 sect_offset_str (sect_off
),
6296 hex_string (header
.signature
));
6302 /* Create the hash table of all entries in the .debug_types
6303 (or .debug_types.dwo) section(s).
6304 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6305 otherwise it is NULL.
6307 The result is a pointer to the hash table or NULL if there are no types.
6309 Note: This function processes DWO files only, not DWP files. */
6312 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6313 struct dwo_file
*dwo_file
,
6314 gdb::array_view
<dwarf2_section_info
> type_sections
,
6315 htab_up
&types_htab
)
6317 for (dwarf2_section_info
§ion
: type_sections
)
6318 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6319 types_htab
, rcuh_kind::TYPE
);
6322 /* Create the hash table of all entries in the .debug_types section,
6323 and initialize all_type_units.
6324 The result is zero if there is an error (e.g. missing .debug_types section),
6325 otherwise non-zero. */
6328 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6332 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6333 &dwarf2_per_objfile
->info
, types_htab
,
6334 rcuh_kind::COMPILE
);
6335 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6336 dwarf2_per_objfile
->types
, types_htab
);
6337 if (types_htab
== NULL
)
6339 dwarf2_per_objfile
->signatured_types
= NULL
;
6343 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6345 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6346 dwarf2_per_objfile
->all_type_units
.reserve
6347 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6349 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6350 add_signatured_type_cu_to_table
,
6351 &dwarf2_per_objfile
->all_type_units
);
6356 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6357 If SLOT is non-NULL, it is the entry to use in the hash table.
6358 Otherwise we find one. */
6360 static struct signatured_type
*
6361 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6364 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6366 if (dwarf2_per_objfile
->all_type_units
.size ()
6367 == dwarf2_per_objfile
->all_type_units
.capacity ())
6368 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6370 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6371 struct signatured_type
);
6373 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6374 sig_type
->signature
= sig
;
6375 sig_type
->per_cu
.is_debug_types
= 1;
6376 if (dwarf2_per_objfile
->using_index
)
6378 sig_type
->per_cu
.v
.quick
=
6379 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6380 struct dwarf2_per_cu_quick_data
);
6385 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6388 gdb_assert (*slot
== NULL
);
6390 /* The rest of sig_type must be filled in by the caller. */
6394 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6395 Fill in SIG_ENTRY with DWO_ENTRY. */
6398 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6399 struct signatured_type
*sig_entry
,
6400 struct dwo_unit
*dwo_entry
)
6402 /* Make sure we're not clobbering something we don't expect to. */
6403 gdb_assert (! sig_entry
->per_cu
.queued
);
6404 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6405 if (dwarf2_per_objfile
->using_index
)
6407 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6408 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6411 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6412 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6413 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6414 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6415 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6417 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6418 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6419 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6420 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6421 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6422 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6423 sig_entry
->dwo_unit
= dwo_entry
;
6426 /* Subroutine of lookup_signatured_type.
6427 If we haven't read the TU yet, create the signatured_type data structure
6428 for a TU to be read in directly from a DWO file, bypassing the stub.
6429 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6430 using .gdb_index, then when reading a CU we want to stay in the DWO file
6431 containing that CU. Otherwise we could end up reading several other DWO
6432 files (due to comdat folding) to process the transitive closure of all the
6433 mentioned TUs, and that can be slow. The current DWO file will have every
6434 type signature that it needs.
6435 We only do this for .gdb_index because in the psymtab case we already have
6436 to read all the DWOs to build the type unit groups. */
6438 static struct signatured_type
*
6439 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6441 struct dwarf2_per_objfile
*dwarf2_per_objfile
6442 = cu
->per_cu
->dwarf2_per_objfile
;
6443 struct dwo_file
*dwo_file
;
6444 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6445 struct signatured_type find_sig_entry
, *sig_entry
;
6448 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6450 /* If TU skeletons have been removed then we may not have read in any
6452 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6453 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6455 /* We only ever need to read in one copy of a signatured type.
6456 Use the global signatured_types array to do our own comdat-folding
6457 of types. If this is the first time we're reading this TU, and
6458 the TU has an entry in .gdb_index, replace the recorded data from
6459 .gdb_index with this TU. */
6461 find_sig_entry
.signature
= sig
;
6462 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6463 &find_sig_entry
, INSERT
);
6464 sig_entry
= (struct signatured_type
*) *slot
;
6466 /* We can get here with the TU already read, *or* in the process of being
6467 read. Don't reassign the global entry to point to this DWO if that's
6468 the case. Also note that if the TU is already being read, it may not
6469 have come from a DWO, the program may be a mix of Fission-compiled
6470 code and non-Fission-compiled code. */
6472 /* Have we already tried to read this TU?
6473 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6474 needn't exist in the global table yet). */
6475 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6478 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6479 dwo_unit of the TU itself. */
6480 dwo_file
= cu
->dwo_unit
->dwo_file
;
6482 /* Ok, this is the first time we're reading this TU. */
6483 if (dwo_file
->tus
== NULL
)
6485 find_dwo_entry
.signature
= sig
;
6486 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6488 if (dwo_entry
== NULL
)
6491 /* If the global table doesn't have an entry for this TU, add one. */
6492 if (sig_entry
== NULL
)
6493 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6495 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6496 sig_entry
->per_cu
.tu_read
= 1;
6500 /* Subroutine of lookup_signatured_type.
6501 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6502 then try the DWP file. If the TU stub (skeleton) has been removed then
6503 it won't be in .gdb_index. */
6505 static struct signatured_type
*
6506 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6508 struct dwarf2_per_objfile
*dwarf2_per_objfile
6509 = cu
->per_cu
->dwarf2_per_objfile
;
6510 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6511 struct dwo_unit
*dwo_entry
;
6512 struct signatured_type find_sig_entry
, *sig_entry
;
6515 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6516 gdb_assert (dwp_file
!= NULL
);
6518 /* If TU skeletons have been removed then we may not have read in any
6520 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6521 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6523 find_sig_entry
.signature
= sig
;
6524 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6525 &find_sig_entry
, INSERT
);
6526 sig_entry
= (struct signatured_type
*) *slot
;
6528 /* Have we already tried to read this TU?
6529 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6530 needn't exist in the global table yet). */
6531 if (sig_entry
!= NULL
)
6534 if (dwp_file
->tus
== NULL
)
6536 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6537 sig
, 1 /* is_debug_types */);
6538 if (dwo_entry
== NULL
)
6541 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6542 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6547 /* Lookup a signature based type for DW_FORM_ref_sig8.
6548 Returns NULL if signature SIG is not present in the table.
6549 It is up to the caller to complain about this. */
6551 static struct signatured_type
*
6552 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6554 struct dwarf2_per_objfile
*dwarf2_per_objfile
6555 = cu
->per_cu
->dwarf2_per_objfile
;
6558 && dwarf2_per_objfile
->using_index
)
6560 /* We're in a DWO/DWP file, and we're using .gdb_index.
6561 These cases require special processing. */
6562 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6563 return lookup_dwo_signatured_type (cu
, sig
);
6565 return lookup_dwp_signatured_type (cu
, sig
);
6569 struct signatured_type find_entry
, *entry
;
6571 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6573 find_entry
.signature
= sig
;
6574 entry
= ((struct signatured_type
*)
6575 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6581 /* Low level DIE reading support. */
6583 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6586 init_cu_die_reader (struct die_reader_specs
*reader
,
6587 struct dwarf2_cu
*cu
,
6588 struct dwarf2_section_info
*section
,
6589 struct dwo_file
*dwo_file
,
6590 struct abbrev_table
*abbrev_table
)
6592 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6593 reader
->abfd
= section
->get_bfd_owner ();
6595 reader
->dwo_file
= dwo_file
;
6596 reader
->die_section
= section
;
6597 reader
->buffer
= section
->buffer
;
6598 reader
->buffer_end
= section
->buffer
+ section
->size
;
6599 reader
->abbrev_table
= abbrev_table
;
6602 /* Subroutine of cutu_reader to simplify it.
6603 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6604 There's just a lot of work to do, and cutu_reader is big enough
6607 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6608 from it to the DIE in the DWO. If NULL we are skipping the stub.
6609 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6610 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6611 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6612 STUB_COMP_DIR may be non-NULL.
6613 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6614 are filled in with the info of the DIE from the DWO file.
6615 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6616 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6617 kept around for at least as long as *RESULT_READER.
6619 The result is non-zero if a valid (non-dummy) DIE was found. */
6622 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6623 struct dwo_unit
*dwo_unit
,
6624 struct die_info
*stub_comp_unit_die
,
6625 const char *stub_comp_dir
,
6626 struct die_reader_specs
*result_reader
,
6627 const gdb_byte
**result_info_ptr
,
6628 struct die_info
**result_comp_unit_die
,
6629 abbrev_table_up
*result_dwo_abbrev_table
)
6631 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6632 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6633 struct dwarf2_cu
*cu
= this_cu
->cu
;
6635 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6636 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6637 int i
,num_extra_attrs
;
6638 struct dwarf2_section_info
*dwo_abbrev_section
;
6639 struct die_info
*comp_unit_die
;
6641 /* At most one of these may be provided. */
6642 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6644 /* These attributes aren't processed until later:
6645 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6646 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6647 referenced later. However, these attributes are found in the stub
6648 which we won't have later. In order to not impose this complication
6649 on the rest of the code, we read them here and copy them to the
6658 if (stub_comp_unit_die
!= NULL
)
6660 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6662 if (! this_cu
->is_debug_types
)
6663 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6664 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6665 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6666 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6667 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6669 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6671 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6672 here (if needed). We need the value before we can process
6674 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6676 else if (stub_comp_dir
!= NULL
)
6678 /* Reconstruct the comp_dir attribute to simplify the code below. */
6679 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6680 comp_dir
->name
= DW_AT_comp_dir
;
6681 comp_dir
->form
= DW_FORM_string
;
6682 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6683 DW_STRING (comp_dir
) = stub_comp_dir
;
6686 /* Set up for reading the DWO CU/TU. */
6687 cu
->dwo_unit
= dwo_unit
;
6688 dwarf2_section_info
*section
= dwo_unit
->section
;
6689 section
->read (objfile
);
6690 abfd
= section
->get_bfd_owner ();
6691 begin_info_ptr
= info_ptr
= (section
->buffer
6692 + to_underlying (dwo_unit
->sect_off
));
6693 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6695 if (this_cu
->is_debug_types
)
6697 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6699 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6700 &cu
->header
, section
,
6702 info_ptr
, rcuh_kind::TYPE
);
6703 /* This is not an assert because it can be caused by bad debug info. */
6704 if (sig_type
->signature
!= cu
->header
.signature
)
6706 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6707 " TU at offset %s [in module %s]"),
6708 hex_string (sig_type
->signature
),
6709 hex_string (cu
->header
.signature
),
6710 sect_offset_str (dwo_unit
->sect_off
),
6711 bfd_get_filename (abfd
));
6713 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6714 /* For DWOs coming from DWP files, we don't know the CU length
6715 nor the type's offset in the TU until now. */
6716 dwo_unit
->length
= cu
->header
.get_length ();
6717 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6719 /* Establish the type offset that can be used to lookup the type.
6720 For DWO files, we don't know it until now. */
6721 sig_type
->type_offset_in_section
6722 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6726 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6727 &cu
->header
, section
,
6729 info_ptr
, rcuh_kind::COMPILE
);
6730 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6731 /* For DWOs coming from DWP files, we don't know the CU length
6733 dwo_unit
->length
= cu
->header
.get_length ();
6736 *result_dwo_abbrev_table
6737 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6738 cu
->header
.abbrev_sect_off
);
6739 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6740 result_dwo_abbrev_table
->get ());
6742 /* Read in the die, but leave space to copy over the attributes
6743 from the stub. This has the benefit of simplifying the rest of
6744 the code - all the work to maintain the illusion of a single
6745 DW_TAG_{compile,type}_unit DIE is done here. */
6746 num_extra_attrs
= ((stmt_list
!= NULL
)
6750 + (comp_dir
!= NULL
));
6751 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6754 /* Copy over the attributes from the stub to the DIE we just read in. */
6755 comp_unit_die
= *result_comp_unit_die
;
6756 i
= comp_unit_die
->num_attrs
;
6757 if (stmt_list
!= NULL
)
6758 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6760 comp_unit_die
->attrs
[i
++] = *low_pc
;
6761 if (high_pc
!= NULL
)
6762 comp_unit_die
->attrs
[i
++] = *high_pc
;
6764 comp_unit_die
->attrs
[i
++] = *ranges
;
6765 if (comp_dir
!= NULL
)
6766 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6767 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6769 if (dwarf_die_debug
)
6771 fprintf_unfiltered (gdb_stdlog
,
6772 "Read die from %s@0x%x of %s:\n",
6773 section
->get_name (),
6774 (unsigned) (begin_info_ptr
- section
->buffer
),
6775 bfd_get_filename (abfd
));
6776 dump_die (comp_unit_die
, dwarf_die_debug
);
6779 /* Skip dummy compilation units. */
6780 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6781 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6784 *result_info_ptr
= info_ptr
;
6788 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6789 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6790 signature is part of the header. */
6791 static gdb::optional
<ULONGEST
>
6792 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6794 if (cu
->header
.version
>= 5)
6795 return cu
->header
.signature
;
6796 struct attribute
*attr
;
6797 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6798 if (attr
== nullptr)
6799 return gdb::optional
<ULONGEST
> ();
6800 return DW_UNSND (attr
);
6803 /* Subroutine of cutu_reader to simplify it.
6804 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6805 Returns NULL if the specified DWO unit cannot be found. */
6807 static struct dwo_unit
*
6808 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6809 struct die_info
*comp_unit_die
,
6810 const char *dwo_name
)
6812 struct dwarf2_cu
*cu
= this_cu
->cu
;
6813 struct dwo_unit
*dwo_unit
;
6814 const char *comp_dir
;
6816 gdb_assert (cu
!= NULL
);
6818 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6819 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6820 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6822 if (this_cu
->is_debug_types
)
6824 struct signatured_type
*sig_type
;
6826 /* Since this_cu is the first member of struct signatured_type,
6827 we can go from a pointer to one to a pointer to the other. */
6828 sig_type
= (struct signatured_type
*) this_cu
;
6829 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6833 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6834 if (!signature
.has_value ())
6835 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6837 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6838 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6845 /* Subroutine of cutu_reader to simplify it.
6846 See it for a description of the parameters.
6847 Read a TU directly from a DWO file, bypassing the stub. */
6850 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6851 int use_existing_cu
)
6853 struct signatured_type
*sig_type
;
6855 /* Verify we can do the following downcast, and that we have the
6857 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6858 sig_type
= (struct signatured_type
*) this_cu
;
6859 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6861 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6863 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6864 /* There's no need to do the rereading_dwo_cu handling that
6865 cutu_reader does since we don't read the stub. */
6869 /* If !use_existing_cu, this_cu->cu must be NULL. */
6870 gdb_assert (this_cu
->cu
== NULL
);
6871 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6874 /* A future optimization, if needed, would be to use an existing
6875 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6876 could share abbrev tables. */
6878 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6879 NULL
/* stub_comp_unit_die */,
6880 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6883 &m_dwo_abbrev_table
) == 0)
6890 /* Initialize a CU (or TU) and read its DIEs.
6891 If the CU defers to a DWO file, read the DWO file as well.
6893 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6894 Otherwise the table specified in the comp unit header is read in and used.
6895 This is an optimization for when we already have the abbrev table.
6897 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6898 Otherwise, a new CU is allocated with xmalloc. */
6900 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6901 struct abbrev_table
*abbrev_table
,
6902 int use_existing_cu
,
6904 : die_reader_specs
{},
6907 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6908 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6909 struct dwarf2_section_info
*section
= this_cu
->section
;
6910 bfd
*abfd
= section
->get_bfd_owner ();
6911 struct dwarf2_cu
*cu
;
6912 const gdb_byte
*begin_info_ptr
;
6913 struct signatured_type
*sig_type
= NULL
;
6914 struct dwarf2_section_info
*abbrev_section
;
6915 /* Non-zero if CU currently points to a DWO file and we need to
6916 reread it. When this happens we need to reread the skeleton die
6917 before we can reread the DWO file (this only applies to CUs, not TUs). */
6918 int rereading_dwo_cu
= 0;
6920 if (dwarf_die_debug
)
6921 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6922 this_cu
->is_debug_types
? "type" : "comp",
6923 sect_offset_str (this_cu
->sect_off
));
6925 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6926 file (instead of going through the stub), short-circuit all of this. */
6927 if (this_cu
->reading_dwo_directly
)
6929 /* Narrow down the scope of possibilities to have to understand. */
6930 gdb_assert (this_cu
->is_debug_types
);
6931 gdb_assert (abbrev_table
== NULL
);
6932 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6936 /* This is cheap if the section is already read in. */
6937 section
->read (objfile
);
6939 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6941 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6943 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6946 /* If this CU is from a DWO file we need to start over, we need to
6947 refetch the attributes from the skeleton CU.
6948 This could be optimized by retrieving those attributes from when we
6949 were here the first time: the previous comp_unit_die was stored in
6950 comp_unit_obstack. But there's no data yet that we need this
6952 if (cu
->dwo_unit
!= NULL
)
6953 rereading_dwo_cu
= 1;
6957 /* If !use_existing_cu, this_cu->cu must be NULL. */
6958 gdb_assert (this_cu
->cu
== NULL
);
6959 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6960 cu
= m_new_cu
.get ();
6963 /* Get the header. */
6964 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6966 /* We already have the header, there's no need to read it in again. */
6967 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6971 if (this_cu
->is_debug_types
)
6973 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6974 &cu
->header
, section
,
6975 abbrev_section
, info_ptr
,
6978 /* Since per_cu is the first member of struct signatured_type,
6979 we can go from a pointer to one to a pointer to the other. */
6980 sig_type
= (struct signatured_type
*) this_cu
;
6981 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6982 gdb_assert (sig_type
->type_offset_in_tu
6983 == cu
->header
.type_cu_offset_in_tu
);
6984 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6986 /* LENGTH has not been set yet for type units if we're
6987 using .gdb_index. */
6988 this_cu
->length
= cu
->header
.get_length ();
6990 /* Establish the type offset that can be used to lookup the type. */
6991 sig_type
->type_offset_in_section
=
6992 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6994 this_cu
->dwarf_version
= cu
->header
.version
;
6998 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6999 &cu
->header
, section
,
7002 rcuh_kind::COMPILE
);
7004 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7005 if (this_cu
->length
== 0)
7006 this_cu
->length
= cu
->header
.get_length ();
7008 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7009 this_cu
->dwarf_version
= cu
->header
.version
;
7013 /* Skip dummy compilation units. */
7014 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7015 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7021 /* If we don't have them yet, read the abbrevs for this compilation unit.
7022 And if we need to read them now, make sure they're freed when we're
7024 if (abbrev_table
!= NULL
)
7025 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7028 m_abbrev_table_holder
7029 = abbrev_table::read (objfile
, abbrev_section
,
7030 cu
->header
.abbrev_sect_off
);
7031 abbrev_table
= m_abbrev_table_holder
.get ();
7034 /* Read the top level CU/TU die. */
7035 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7036 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7038 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7044 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7045 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7046 table from the DWO file and pass the ownership over to us. It will be
7047 referenced from READER, so we must make sure to free it after we're done
7050 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7051 DWO CU, that this test will fail (the attribute will not be present). */
7052 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7053 if (dwo_name
!= nullptr)
7055 struct dwo_unit
*dwo_unit
;
7056 struct die_info
*dwo_comp_unit_die
;
7058 if (comp_unit_die
->has_children
)
7060 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7061 " has children (offset %s) [in module %s]"),
7062 sect_offset_str (this_cu
->sect_off
),
7063 bfd_get_filename (abfd
));
7065 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
7066 if (dwo_unit
!= NULL
)
7068 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7069 comp_unit_die
, NULL
,
7072 &m_dwo_abbrev_table
) == 0)
7078 comp_unit_die
= dwo_comp_unit_die
;
7082 /* Yikes, we couldn't find the rest of the DIE, we only have
7083 the stub. A complaint has already been logged. There's
7084 not much more we can do except pass on the stub DIE to
7085 die_reader_func. We don't want to throw an error on bad
7092 cutu_reader::keep ()
7094 /* Done, clean up. */
7095 gdb_assert (!dummy_p
);
7096 if (m_new_cu
!= NULL
)
7098 struct dwarf2_per_objfile
*dwarf2_per_objfile
7099 = m_this_cu
->dwarf2_per_objfile
;
7100 /* Link this CU into read_in_chain. */
7101 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7102 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7103 /* The chain owns it now. */
7104 m_new_cu
.release ();
7108 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7109 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7110 assumed to have already done the lookup to find the DWO file).
7112 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7113 THIS_CU->is_debug_types, but nothing else.
7115 We fill in THIS_CU->length.
7117 THIS_CU->cu is always freed when done.
7118 This is done in order to not leave THIS_CU->cu in a state where we have
7119 to care whether it refers to the "main" CU or the DWO CU.
7121 When parent_cu is passed, it is used to provide a default value for
7122 str_offsets_base and addr_base from the parent. */
7124 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7125 struct dwarf2_cu
*parent_cu
,
7126 struct dwo_file
*dwo_file
)
7127 : die_reader_specs
{},
7130 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7131 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7132 struct dwarf2_section_info
*section
= this_cu
->section
;
7133 bfd
*abfd
= section
->get_bfd_owner ();
7134 struct dwarf2_section_info
*abbrev_section
;
7135 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7137 if (dwarf_die_debug
)
7138 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7139 this_cu
->is_debug_types
? "type" : "comp",
7140 sect_offset_str (this_cu
->sect_off
));
7142 gdb_assert (this_cu
->cu
== NULL
);
7144 abbrev_section
= (dwo_file
!= NULL
7145 ? &dwo_file
->sections
.abbrev
7146 : get_abbrev_section_for_cu (this_cu
));
7148 /* This is cheap if the section is already read in. */
7149 section
->read (objfile
);
7151 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7153 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7154 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7155 &m_new_cu
->header
, section
,
7156 abbrev_section
, info_ptr
,
7157 (this_cu
->is_debug_types
7159 : rcuh_kind::COMPILE
));
7161 if (parent_cu
!= nullptr)
7163 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7164 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7166 this_cu
->length
= m_new_cu
->header
.get_length ();
7168 /* Skip dummy compilation units. */
7169 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7170 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7176 m_abbrev_table_holder
7177 = abbrev_table::read (objfile
, abbrev_section
,
7178 m_new_cu
->header
.abbrev_sect_off
);
7180 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7181 m_abbrev_table_holder
.get ());
7182 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7186 /* Type Unit Groups.
7188 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7189 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7190 so that all types coming from the same compilation (.o file) are grouped
7191 together. A future step could be to put the types in the same symtab as
7192 the CU the types ultimately came from. */
7195 hash_type_unit_group (const void *item
)
7197 const struct type_unit_group
*tu_group
7198 = (const struct type_unit_group
*) item
;
7200 return hash_stmt_list_entry (&tu_group
->hash
);
7204 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7206 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7207 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7209 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7212 /* Allocate a hash table for type unit groups. */
7215 allocate_type_unit_groups_table ()
7217 return htab_up (htab_create_alloc (3,
7218 hash_type_unit_group
,
7220 NULL
, xcalloc
, xfree
));
7223 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7224 partial symtabs. We combine several TUs per psymtab to not let the size
7225 of any one psymtab grow too big. */
7226 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7227 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7229 /* Helper routine for get_type_unit_group.
7230 Create the type_unit_group object used to hold one or more TUs. */
7232 static struct type_unit_group
*
7233 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7235 struct dwarf2_per_objfile
*dwarf2_per_objfile
7236 = cu
->per_cu
->dwarf2_per_objfile
;
7237 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7238 struct dwarf2_per_cu_data
*per_cu
;
7239 struct type_unit_group
*tu_group
;
7241 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7242 struct type_unit_group
);
7243 per_cu
= &tu_group
->per_cu
;
7244 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7246 if (dwarf2_per_objfile
->using_index
)
7248 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7249 struct dwarf2_per_cu_quick_data
);
7253 unsigned int line_offset
= to_underlying (line_offset_struct
);
7254 dwarf2_psymtab
*pst
;
7257 /* Give the symtab a useful name for debug purposes. */
7258 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7259 name
= string_printf ("<type_units_%d>",
7260 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7262 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7264 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7265 pst
->anonymous
= true;
7268 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7269 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7274 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7275 STMT_LIST is a DW_AT_stmt_list attribute. */
7277 static struct type_unit_group
*
7278 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7280 struct dwarf2_per_objfile
*dwarf2_per_objfile
7281 = cu
->per_cu
->dwarf2_per_objfile
;
7282 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7283 struct type_unit_group
*tu_group
;
7285 unsigned int line_offset
;
7286 struct type_unit_group type_unit_group_for_lookup
;
7288 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7289 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7291 /* Do we need to create a new group, or can we use an existing one? */
7295 line_offset
= DW_UNSND (stmt_list
);
7296 ++tu_stats
->nr_symtab_sharers
;
7300 /* Ugh, no stmt_list. Rare, but we have to handle it.
7301 We can do various things here like create one group per TU or
7302 spread them over multiple groups to split up the expansion work.
7303 To avoid worst case scenarios (too many groups or too large groups)
7304 we, umm, group them in bunches. */
7305 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7306 | (tu_stats
->nr_stmt_less_type_units
7307 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7308 ++tu_stats
->nr_stmt_less_type_units
;
7311 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7312 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7313 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7314 &type_unit_group_for_lookup
, INSERT
);
7317 tu_group
= (struct type_unit_group
*) *slot
;
7318 gdb_assert (tu_group
!= NULL
);
7322 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7323 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7325 ++tu_stats
->nr_symtabs
;
7331 /* Partial symbol tables. */
7333 /* Create a psymtab named NAME and assign it to PER_CU.
7335 The caller must fill in the following details:
7336 dirname, textlow, texthigh. */
7338 static dwarf2_psymtab
*
7339 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7341 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7342 dwarf2_psymtab
*pst
;
7344 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7346 pst
->psymtabs_addrmap_supported
= true;
7348 /* This is the glue that links PST into GDB's symbol API. */
7349 per_cu
->v
.psymtab
= pst
;
7354 /* DIE reader function for process_psymtab_comp_unit. */
7357 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7358 const gdb_byte
*info_ptr
,
7359 struct die_info
*comp_unit_die
,
7360 enum language pretend_language
)
7362 struct dwarf2_cu
*cu
= reader
->cu
;
7363 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7364 struct gdbarch
*gdbarch
= objfile
->arch ();
7365 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7367 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7368 dwarf2_psymtab
*pst
;
7369 enum pc_bounds_kind cu_bounds_kind
;
7370 const char *filename
;
7372 gdb_assert (! per_cu
->is_debug_types
);
7374 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7376 /* Allocate a new partial symbol table structure. */
7377 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7378 static const char artificial
[] = "<artificial>";
7379 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7380 if (filename
== NULL
)
7382 else if (strcmp (filename
, artificial
) == 0)
7384 debug_filename
.reset (concat (artificial
, "@",
7385 sect_offset_str (per_cu
->sect_off
),
7387 filename
= debug_filename
.get ();
7390 pst
= create_partial_symtab (per_cu
, filename
);
7392 /* This must be done before calling dwarf2_build_include_psymtabs. */
7393 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7395 baseaddr
= objfile
->text_section_offset ();
7397 dwarf2_find_base_address (comp_unit_die
, cu
);
7399 /* Possibly set the default values of LOWPC and HIGHPC from
7401 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7402 &best_highpc
, cu
, pst
);
7403 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7406 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7409 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7411 /* Store the contiguous range if it is not empty; it can be
7412 empty for CUs with no code. */
7413 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7417 /* Check if comp unit has_children.
7418 If so, read the rest of the partial symbols from this comp unit.
7419 If not, there's no more debug_info for this comp unit. */
7420 if (comp_unit_die
->has_children
)
7422 struct partial_die_info
*first_die
;
7423 CORE_ADDR lowpc
, highpc
;
7425 lowpc
= ((CORE_ADDR
) -1);
7426 highpc
= ((CORE_ADDR
) 0);
7428 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7430 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7431 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7433 /* If we didn't find a lowpc, set it to highpc to avoid
7434 complaints from `maint check'. */
7435 if (lowpc
== ((CORE_ADDR
) -1))
7438 /* If the compilation unit didn't have an explicit address range,
7439 then use the information extracted from its child dies. */
7440 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7443 best_highpc
= highpc
;
7446 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7447 best_lowpc
+ baseaddr
)
7449 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7450 best_highpc
+ baseaddr
)
7453 end_psymtab_common (objfile
, pst
);
7455 if (!cu
->per_cu
->imported_symtabs_empty ())
7458 int len
= cu
->per_cu
->imported_symtabs_size ();
7460 /* Fill in 'dependencies' here; we fill in 'users' in a
7462 pst
->number_of_dependencies
= len
;
7464 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7465 for (i
= 0; i
< len
; ++i
)
7467 pst
->dependencies
[i
]
7468 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7471 cu
->per_cu
->imported_symtabs_free ();
7474 /* Get the list of files included in the current compilation unit,
7475 and build a psymtab for each of them. */
7476 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7478 if (dwarf_read_debug
)
7479 fprintf_unfiltered (gdb_stdlog
,
7480 "Psymtab for %s unit @%s: %s - %s"
7481 ", %d global, %d static syms\n",
7482 per_cu
->is_debug_types
? "type" : "comp",
7483 sect_offset_str (per_cu
->sect_off
),
7484 paddress (gdbarch
, pst
->text_low (objfile
)),
7485 paddress (gdbarch
, pst
->text_high (objfile
)),
7486 pst
->n_global_syms
, pst
->n_static_syms
);
7489 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7490 Process compilation unit THIS_CU for a psymtab. */
7493 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7494 bool want_partial_unit
,
7495 enum language pretend_language
)
7497 /* If this compilation unit was already read in, free the
7498 cached copy in order to read it in again. This is
7499 necessary because we skipped some symbols when we first
7500 read in the compilation unit (see load_partial_dies).
7501 This problem could be avoided, but the benefit is unclear. */
7502 if (this_cu
->cu
!= NULL
)
7503 free_one_cached_comp_unit (this_cu
);
7505 cutu_reader
reader (this_cu
, NULL
, 0, false);
7507 switch (reader
.comp_unit_die
->tag
)
7509 case DW_TAG_compile_unit
:
7510 this_cu
->unit_type
= DW_UT_compile
;
7512 case DW_TAG_partial_unit
:
7513 this_cu
->unit_type
= DW_UT_partial
;
7523 else if (this_cu
->is_debug_types
)
7524 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7525 reader
.comp_unit_die
);
7526 else if (want_partial_unit
7527 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7528 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7529 reader
.comp_unit_die
,
7532 this_cu
->lang
= this_cu
->cu
->language
;
7534 /* Age out any secondary CUs. */
7535 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7538 /* Reader function for build_type_psymtabs. */
7541 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7542 const gdb_byte
*info_ptr
,
7543 struct die_info
*type_unit_die
)
7545 struct dwarf2_per_objfile
*dwarf2_per_objfile
7546 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7547 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7548 struct dwarf2_cu
*cu
= reader
->cu
;
7549 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7550 struct signatured_type
*sig_type
;
7551 struct type_unit_group
*tu_group
;
7552 struct attribute
*attr
;
7553 struct partial_die_info
*first_die
;
7554 CORE_ADDR lowpc
, highpc
;
7555 dwarf2_psymtab
*pst
;
7557 gdb_assert (per_cu
->is_debug_types
);
7558 sig_type
= (struct signatured_type
*) per_cu
;
7560 if (! type_unit_die
->has_children
)
7563 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7564 tu_group
= get_type_unit_group (cu
, attr
);
7566 if (tu_group
->tus
== nullptr)
7567 tu_group
->tus
= new std::vector
<signatured_type
*>;
7568 tu_group
->tus
->push_back (sig_type
);
7570 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7571 pst
= create_partial_symtab (per_cu
, "");
7572 pst
->anonymous
= true;
7574 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7576 lowpc
= (CORE_ADDR
) -1;
7577 highpc
= (CORE_ADDR
) 0;
7578 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7580 end_psymtab_common (objfile
, pst
);
7583 /* Struct used to sort TUs by their abbreviation table offset. */
7585 struct tu_abbrev_offset
7587 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7588 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7591 signatured_type
*sig_type
;
7592 sect_offset abbrev_offset
;
7595 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7598 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7599 const struct tu_abbrev_offset
&b
)
7601 return a
.abbrev_offset
< b
.abbrev_offset
;
7604 /* Efficiently read all the type units.
7605 This does the bulk of the work for build_type_psymtabs.
7607 The efficiency is because we sort TUs by the abbrev table they use and
7608 only read each abbrev table once. In one program there are 200K TUs
7609 sharing 8K abbrev tables.
7611 The main purpose of this function is to support building the
7612 dwarf2_per_objfile->type_unit_groups table.
7613 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7614 can collapse the search space by grouping them by stmt_list.
7615 The savings can be significant, in the same program from above the 200K TUs
7616 share 8K stmt_list tables.
7618 FUNC is expected to call get_type_unit_group, which will create the
7619 struct type_unit_group if necessary and add it to
7620 dwarf2_per_objfile->type_unit_groups. */
7623 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7625 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7626 abbrev_table_up abbrev_table
;
7627 sect_offset abbrev_offset
;
7629 /* It's up to the caller to not call us multiple times. */
7630 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7632 if (dwarf2_per_objfile
->all_type_units
.empty ())
7635 /* TUs typically share abbrev tables, and there can be way more TUs than
7636 abbrev tables. Sort by abbrev table to reduce the number of times we
7637 read each abbrev table in.
7638 Alternatives are to punt or to maintain a cache of abbrev tables.
7639 This is simpler and efficient enough for now.
7641 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7642 symtab to use). Typically TUs with the same abbrev offset have the same
7643 stmt_list value too so in practice this should work well.
7645 The basic algorithm here is:
7647 sort TUs by abbrev table
7648 for each TU with same abbrev table:
7649 read abbrev table if first user
7650 read TU top level DIE
7651 [IWBN if DWO skeletons had DW_AT_stmt_list]
7654 if (dwarf_read_debug
)
7655 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7657 /* Sort in a separate table to maintain the order of all_type_units
7658 for .gdb_index: TU indices directly index all_type_units. */
7659 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7660 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7662 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7663 sorted_by_abbrev
.emplace_back
7664 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7665 sig_type
->per_cu
.section
,
7666 sig_type
->per_cu
.sect_off
));
7668 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7669 sort_tu_by_abbrev_offset
);
7671 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7673 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7675 /* Switch to the next abbrev table if necessary. */
7676 if (abbrev_table
== NULL
7677 || tu
.abbrev_offset
!= abbrev_offset
)
7679 abbrev_offset
= tu
.abbrev_offset
;
7681 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7682 &dwarf2_per_objfile
->abbrev
,
7684 ++tu_stats
->nr_uniq_abbrev_tables
;
7687 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7689 if (!reader
.dummy_p
)
7690 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7691 reader
.comp_unit_die
);
7695 /* Print collected type unit statistics. */
7698 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7700 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7702 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7703 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7704 dwarf2_per_objfile
->all_type_units
.size ());
7705 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7706 tu_stats
->nr_uniq_abbrev_tables
);
7707 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7708 tu_stats
->nr_symtabs
);
7709 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7710 tu_stats
->nr_symtab_sharers
);
7711 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7712 tu_stats
->nr_stmt_less_type_units
);
7713 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7714 tu_stats
->nr_all_type_units_reallocs
);
7717 /* Traversal function for build_type_psymtabs. */
7720 build_type_psymtab_dependencies (void **slot
, void *info
)
7722 struct dwarf2_per_objfile
*dwarf2_per_objfile
7723 = (struct dwarf2_per_objfile
*) info
;
7724 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7725 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7726 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7727 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7728 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7731 gdb_assert (len
> 0);
7732 gdb_assert (per_cu
->type_unit_group_p ());
7734 pst
->number_of_dependencies
= len
;
7735 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7736 for (i
= 0; i
< len
; ++i
)
7738 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7739 gdb_assert (iter
->per_cu
.is_debug_types
);
7740 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7741 iter
->type_unit_group
= tu_group
;
7744 delete tu_group
->tus
;
7745 tu_group
->tus
= nullptr;
7750 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7751 Build partial symbol tables for the .debug_types comp-units. */
7754 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7756 if (! create_all_type_units (dwarf2_per_objfile
))
7759 build_type_psymtabs_1 (dwarf2_per_objfile
);
7762 /* Traversal function for process_skeletonless_type_unit.
7763 Read a TU in a DWO file and build partial symbols for it. */
7766 process_skeletonless_type_unit (void **slot
, void *info
)
7768 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7769 struct dwarf2_per_objfile
*dwarf2_per_objfile
7770 = (struct dwarf2_per_objfile
*) info
;
7771 struct signatured_type find_entry
, *entry
;
7773 /* If this TU doesn't exist in the global table, add it and read it in. */
7775 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7776 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7778 find_entry
.signature
= dwo_unit
->signature
;
7779 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7780 &find_entry
, INSERT
);
7781 /* If we've already seen this type there's nothing to do. What's happening
7782 is we're doing our own version of comdat-folding here. */
7786 /* This does the job that create_all_type_units would have done for
7788 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7789 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7792 /* This does the job that build_type_psymtabs_1 would have done. */
7793 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7794 if (!reader
.dummy_p
)
7795 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7796 reader
.comp_unit_die
);
7801 /* Traversal function for process_skeletonless_type_units. */
7804 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7806 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7808 if (dwo_file
->tus
!= NULL
)
7809 htab_traverse_noresize (dwo_file
->tus
.get (),
7810 process_skeletonless_type_unit
, info
);
7815 /* Scan all TUs of DWO files, verifying we've processed them.
7816 This is needed in case a TU was emitted without its skeleton.
7817 Note: This can't be done until we know what all the DWO files are. */
7820 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7822 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7823 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7824 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7826 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7827 process_dwo_file_for_skeletonless_type_units
,
7828 dwarf2_per_objfile
);
7832 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7835 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7837 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7839 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7844 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7846 /* Set the 'user' field only if it is not already set. */
7847 if (pst
->dependencies
[j
]->user
== NULL
)
7848 pst
->dependencies
[j
]->user
= pst
;
7853 /* Build the partial symbol table by doing a quick pass through the
7854 .debug_info and .debug_abbrev sections. */
7857 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7859 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7861 if (dwarf_read_debug
)
7863 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7864 objfile_name (objfile
));
7867 scoped_restore restore_reading_psyms
7868 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7871 dwarf2_per_objfile
->info
.read (objfile
);
7873 /* Any cached compilation units will be linked by the per-objfile
7874 read_in_chain. Make sure to free them when we're done. */
7875 free_cached_comp_units
freer (dwarf2_per_objfile
);
7877 build_type_psymtabs (dwarf2_per_objfile
);
7879 create_all_comp_units (dwarf2_per_objfile
);
7881 /* Create a temporary address map on a temporary obstack. We later
7882 copy this to the final obstack. */
7883 auto_obstack temp_obstack
;
7885 scoped_restore save_psymtabs_addrmap
7886 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7887 addrmap_create_mutable (&temp_obstack
));
7889 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7891 if (per_cu
->v
.psymtab
!= NULL
)
7892 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7894 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7897 /* This has to wait until we read the CUs, we need the list of DWOs. */
7898 process_skeletonless_type_units (dwarf2_per_objfile
);
7900 /* Now that all TUs have been processed we can fill in the dependencies. */
7901 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7903 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7904 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7907 if (dwarf_read_debug
)
7908 print_tu_stats (dwarf2_per_objfile
);
7910 set_partial_user (dwarf2_per_objfile
);
7912 objfile
->partial_symtabs
->psymtabs_addrmap
7913 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7914 objfile
->partial_symtabs
->obstack ());
7915 /* At this point we want to keep the address map. */
7916 save_psymtabs_addrmap
.release ();
7918 if (dwarf_read_debug
)
7919 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7920 objfile_name (objfile
));
7923 /* Load the partial DIEs for a secondary CU into memory.
7924 This is also used when rereading a primary CU with load_all_dies. */
7927 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7929 cutu_reader
reader (this_cu
, NULL
, 1, false);
7931 if (!reader
.dummy_p
)
7933 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7936 /* Check if comp unit has_children.
7937 If so, read the rest of the partial symbols from this comp unit.
7938 If not, there's no more debug_info for this comp unit. */
7939 if (reader
.comp_unit_die
->has_children
)
7940 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7947 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7948 struct dwarf2_section_info
*section
,
7949 struct dwarf2_section_info
*abbrev_section
,
7950 unsigned int is_dwz
)
7952 const gdb_byte
*info_ptr
;
7953 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7955 if (dwarf_read_debug
)
7956 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7957 section
->get_name (),
7958 section
->get_file_name ());
7960 section
->read (objfile
);
7962 info_ptr
= section
->buffer
;
7964 while (info_ptr
< section
->buffer
+ section
->size
)
7966 struct dwarf2_per_cu_data
*this_cu
;
7968 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7970 comp_unit_head cu_header
;
7971 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7972 abbrev_section
, info_ptr
,
7973 rcuh_kind::COMPILE
);
7975 /* Save the compilation unit for later lookup. */
7976 if (cu_header
.unit_type
!= DW_UT_type
)
7978 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7979 struct dwarf2_per_cu_data
);
7980 memset (this_cu
, 0, sizeof (*this_cu
));
7984 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7985 struct signatured_type
);
7986 memset (sig_type
, 0, sizeof (*sig_type
));
7987 sig_type
->signature
= cu_header
.signature
;
7988 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7989 this_cu
= &sig_type
->per_cu
;
7991 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7992 this_cu
->sect_off
= sect_off
;
7993 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7994 this_cu
->is_dwz
= is_dwz
;
7995 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7996 this_cu
->section
= section
;
7998 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8000 info_ptr
= info_ptr
+ this_cu
->length
;
8004 /* Create a list of all compilation units in OBJFILE.
8005 This is only done for -readnow and building partial symtabs. */
8008 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8010 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8011 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8012 &dwarf2_per_objfile
->abbrev
, 0);
8014 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8016 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8020 /* Process all loaded DIEs for compilation unit CU, starting at
8021 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8022 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8023 DW_AT_ranges). See the comments of add_partial_subprogram on how
8024 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8027 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8028 CORE_ADDR
*highpc
, int set_addrmap
,
8029 struct dwarf2_cu
*cu
)
8031 struct partial_die_info
*pdi
;
8033 /* Now, march along the PDI's, descending into ones which have
8034 interesting children but skipping the children of the other ones,
8035 until we reach the end of the compilation unit. */
8043 /* Anonymous namespaces or modules have no name but have interesting
8044 children, so we need to look at them. Ditto for anonymous
8047 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8048 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8049 || pdi
->tag
== DW_TAG_imported_unit
8050 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8054 case DW_TAG_subprogram
:
8055 case DW_TAG_inlined_subroutine
:
8056 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8058 case DW_TAG_constant
:
8059 case DW_TAG_variable
:
8060 case DW_TAG_typedef
:
8061 case DW_TAG_union_type
:
8062 if (!pdi
->is_declaration
8063 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8065 add_partial_symbol (pdi
, cu
);
8068 case DW_TAG_class_type
:
8069 case DW_TAG_interface_type
:
8070 case DW_TAG_structure_type
:
8071 if (!pdi
->is_declaration
)
8073 add_partial_symbol (pdi
, cu
);
8075 if ((cu
->language
== language_rust
8076 || cu
->language
== language_cplus
) && pdi
->has_children
)
8077 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8080 case DW_TAG_enumeration_type
:
8081 if (!pdi
->is_declaration
)
8082 add_partial_enumeration (pdi
, cu
);
8084 case DW_TAG_base_type
:
8085 case DW_TAG_subrange_type
:
8086 /* File scope base type definitions are added to the partial
8088 add_partial_symbol (pdi
, cu
);
8090 case DW_TAG_namespace
:
8091 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8094 if (!pdi
->is_declaration
)
8095 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8097 case DW_TAG_imported_unit
:
8099 struct dwarf2_per_cu_data
*per_cu
;
8101 /* For now we don't handle imported units in type units. */
8102 if (cu
->per_cu
->is_debug_types
)
8104 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8105 " supported in type units [in module %s]"),
8106 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8109 per_cu
= dwarf2_find_containing_comp_unit
8110 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8111 cu
->per_cu
->dwarf2_per_objfile
);
8113 /* Go read the partial unit, if needed. */
8114 if (per_cu
->v
.psymtab
== NULL
)
8115 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
8117 cu
->per_cu
->imported_symtabs_push (per_cu
);
8120 case DW_TAG_imported_declaration
:
8121 add_partial_symbol (pdi
, cu
);
8128 /* If the die has a sibling, skip to the sibling. */
8130 pdi
= pdi
->die_sibling
;
8134 /* Functions used to compute the fully scoped name of a partial DIE.
8136 Normally, this is simple. For C++, the parent DIE's fully scoped
8137 name is concatenated with "::" and the partial DIE's name.
8138 Enumerators are an exception; they use the scope of their parent
8139 enumeration type, i.e. the name of the enumeration type is not
8140 prepended to the enumerator.
8142 There are two complexities. One is DW_AT_specification; in this
8143 case "parent" means the parent of the target of the specification,
8144 instead of the direct parent of the DIE. The other is compilers
8145 which do not emit DW_TAG_namespace; in this case we try to guess
8146 the fully qualified name of structure types from their members'
8147 linkage names. This must be done using the DIE's children rather
8148 than the children of any DW_AT_specification target. We only need
8149 to do this for structures at the top level, i.e. if the target of
8150 any DW_AT_specification (if any; otherwise the DIE itself) does not
8153 /* Compute the scope prefix associated with PDI's parent, in
8154 compilation unit CU. The result will be allocated on CU's
8155 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8156 field. NULL is returned if no prefix is necessary. */
8158 partial_die_parent_scope (struct partial_die_info
*pdi
,
8159 struct dwarf2_cu
*cu
)
8161 const char *grandparent_scope
;
8162 struct partial_die_info
*parent
, *real_pdi
;
8164 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8165 then this means the parent of the specification DIE. */
8168 while (real_pdi
->has_specification
)
8170 auto res
= find_partial_die (real_pdi
->spec_offset
,
8171 real_pdi
->spec_is_dwz
, cu
);
8176 parent
= real_pdi
->die_parent
;
8180 if (parent
->scope_set
)
8181 return parent
->scope
;
8185 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8187 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8188 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8189 Work around this problem here. */
8190 if (cu
->language
== language_cplus
8191 && parent
->tag
== DW_TAG_namespace
8192 && strcmp (parent
->name
, "::") == 0
8193 && grandparent_scope
== NULL
)
8195 parent
->scope
= NULL
;
8196 parent
->scope_set
= 1;
8200 /* Nested subroutines in Fortran get a prefix. */
8201 if (pdi
->tag
== DW_TAG_enumerator
)
8202 /* Enumerators should not get the name of the enumeration as a prefix. */
8203 parent
->scope
= grandparent_scope
;
8204 else if (parent
->tag
== DW_TAG_namespace
8205 || parent
->tag
== DW_TAG_module
8206 || parent
->tag
== DW_TAG_structure_type
8207 || parent
->tag
== DW_TAG_class_type
8208 || parent
->tag
== DW_TAG_interface_type
8209 || parent
->tag
== DW_TAG_union_type
8210 || parent
->tag
== DW_TAG_enumeration_type
8211 || (cu
->language
== language_fortran
8212 && parent
->tag
== DW_TAG_subprogram
8213 && pdi
->tag
== DW_TAG_subprogram
))
8215 if (grandparent_scope
== NULL
)
8216 parent
->scope
= parent
->name
;
8218 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8220 parent
->name
, 0, cu
);
8224 /* FIXME drow/2004-04-01: What should we be doing with
8225 function-local names? For partial symbols, we should probably be
8227 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8228 dwarf_tag_name (parent
->tag
),
8229 sect_offset_str (pdi
->sect_off
));
8230 parent
->scope
= grandparent_scope
;
8233 parent
->scope_set
= 1;
8234 return parent
->scope
;
8237 /* Return the fully scoped name associated with PDI, from compilation unit
8238 CU. The result will be allocated with malloc. */
8240 static gdb::unique_xmalloc_ptr
<char>
8241 partial_die_full_name (struct partial_die_info
*pdi
,
8242 struct dwarf2_cu
*cu
)
8244 const char *parent_scope
;
8246 /* If this is a template instantiation, we can not work out the
8247 template arguments from partial DIEs. So, unfortunately, we have
8248 to go through the full DIEs. At least any work we do building
8249 types here will be reused if full symbols are loaded later. */
8250 if (pdi
->has_template_arguments
)
8254 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8256 struct die_info
*die
;
8257 struct attribute attr
;
8258 struct dwarf2_cu
*ref_cu
= cu
;
8260 /* DW_FORM_ref_addr is using section offset. */
8261 attr
.name
= (enum dwarf_attribute
) 0;
8262 attr
.form
= DW_FORM_ref_addr
;
8263 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8264 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8266 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8270 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8271 if (parent_scope
== NULL
)
8274 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8279 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8281 struct dwarf2_per_objfile
*dwarf2_per_objfile
8282 = cu
->per_cu
->dwarf2_per_objfile
;
8283 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8284 struct gdbarch
*gdbarch
= objfile
->arch ();
8286 const char *actual_name
= NULL
;
8289 baseaddr
= objfile
->text_section_offset ();
8291 gdb::unique_xmalloc_ptr
<char> built_actual_name
8292 = partial_die_full_name (pdi
, cu
);
8293 if (built_actual_name
!= NULL
)
8294 actual_name
= built_actual_name
.get ();
8296 if (actual_name
== NULL
)
8297 actual_name
= pdi
->name
;
8299 partial_symbol psymbol
;
8300 memset (&psymbol
, 0, sizeof (psymbol
));
8301 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8302 psymbol
.ginfo
.section
= -1;
8304 /* The code below indicates that the psymbol should be installed by
8306 gdb::optional
<psymbol_placement
> where
;
8310 case DW_TAG_inlined_subroutine
:
8311 case DW_TAG_subprogram
:
8312 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8314 if (pdi
->is_external
8315 || cu
->language
== language_ada
8316 || (cu
->language
== language_fortran
8317 && pdi
->die_parent
!= NULL
8318 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8320 /* Normally, only "external" DIEs are part of the global scope.
8321 But in Ada and Fortran, we want to be able to access nested
8322 procedures globally. So all Ada and Fortran subprograms are
8323 stored in the global scope. */
8324 where
= psymbol_placement::GLOBAL
;
8327 where
= psymbol_placement::STATIC
;
8329 psymbol
.domain
= VAR_DOMAIN
;
8330 psymbol
.aclass
= LOC_BLOCK
;
8331 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8332 psymbol
.ginfo
.value
.address
= addr
;
8334 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8335 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8337 case DW_TAG_constant
:
8338 psymbol
.domain
= VAR_DOMAIN
;
8339 psymbol
.aclass
= LOC_STATIC
;
8340 where
= (pdi
->is_external
8341 ? psymbol_placement::GLOBAL
8342 : psymbol_placement::STATIC
);
8344 case DW_TAG_variable
:
8346 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8350 && !dwarf2_per_objfile
->has_section_at_zero
)
8352 /* A global or static variable may also have been stripped
8353 out by the linker if unused, in which case its address
8354 will be nullified; do not add such variables into partial
8355 symbol table then. */
8357 else if (pdi
->is_external
)
8360 Don't enter into the minimal symbol tables as there is
8361 a minimal symbol table entry from the ELF symbols already.
8362 Enter into partial symbol table if it has a location
8363 descriptor or a type.
8364 If the location descriptor is missing, new_symbol will create
8365 a LOC_UNRESOLVED symbol, the address of the variable will then
8366 be determined from the minimal symbol table whenever the variable
8368 The address for the partial symbol table entry is not
8369 used by GDB, but it comes in handy for debugging partial symbol
8372 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8374 psymbol
.domain
= VAR_DOMAIN
;
8375 psymbol
.aclass
= LOC_STATIC
;
8376 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8377 psymbol
.ginfo
.value
.address
= addr
;
8378 where
= psymbol_placement::GLOBAL
;
8383 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8385 /* Static Variable. Skip symbols whose value we cannot know (those
8386 without location descriptors or constant values). */
8387 if (!has_loc
&& !pdi
->has_const_value
)
8390 psymbol
.domain
= VAR_DOMAIN
;
8391 psymbol
.aclass
= LOC_STATIC
;
8392 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8394 psymbol
.ginfo
.value
.address
= addr
;
8395 where
= psymbol_placement::STATIC
;
8398 case DW_TAG_typedef
:
8399 case DW_TAG_base_type
:
8400 case DW_TAG_subrange_type
:
8401 psymbol
.domain
= VAR_DOMAIN
;
8402 psymbol
.aclass
= LOC_TYPEDEF
;
8403 where
= psymbol_placement::STATIC
;
8405 case DW_TAG_imported_declaration
:
8406 case DW_TAG_namespace
:
8407 psymbol
.domain
= VAR_DOMAIN
;
8408 psymbol
.aclass
= LOC_TYPEDEF
;
8409 where
= psymbol_placement::GLOBAL
;
8412 /* With Fortran 77 there might be a "BLOCK DATA" module
8413 available without any name. If so, we skip the module as it
8414 doesn't bring any value. */
8415 if (actual_name
!= nullptr)
8417 psymbol
.domain
= MODULE_DOMAIN
;
8418 psymbol
.aclass
= LOC_TYPEDEF
;
8419 where
= psymbol_placement::GLOBAL
;
8422 case DW_TAG_class_type
:
8423 case DW_TAG_interface_type
:
8424 case DW_TAG_structure_type
:
8425 case DW_TAG_union_type
:
8426 case DW_TAG_enumeration_type
:
8427 /* Skip external references. The DWARF standard says in the section
8428 about "Structure, Union, and Class Type Entries": "An incomplete
8429 structure, union or class type is represented by a structure,
8430 union or class entry that does not have a byte size attribute
8431 and that has a DW_AT_declaration attribute." */
8432 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8435 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8436 static vs. global. */
8437 psymbol
.domain
= STRUCT_DOMAIN
;
8438 psymbol
.aclass
= LOC_TYPEDEF
;
8439 where
= (cu
->language
== language_cplus
8440 ? psymbol_placement::GLOBAL
8441 : psymbol_placement::STATIC
);
8443 case DW_TAG_enumerator
:
8444 psymbol
.domain
= VAR_DOMAIN
;
8445 psymbol
.aclass
= LOC_CONST
;
8446 where
= (cu
->language
== language_cplus
8447 ? psymbol_placement::GLOBAL
8448 : psymbol_placement::STATIC
);
8454 if (where
.has_value ())
8456 if (built_actual_name
!= nullptr)
8457 actual_name
= objfile
->intern (actual_name
);
8458 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8459 psymbol
.ginfo
.set_linkage_name (actual_name
);
8462 psymbol
.ginfo
.set_demangled_name (actual_name
,
8463 &objfile
->objfile_obstack
);
8464 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8466 add_psymbol_to_list (psymbol
, *where
, objfile
);
8470 /* Read a partial die corresponding to a namespace; also, add a symbol
8471 corresponding to that namespace to the symbol table. NAMESPACE is
8472 the name of the enclosing namespace. */
8475 add_partial_namespace (struct partial_die_info
*pdi
,
8476 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8477 int set_addrmap
, struct dwarf2_cu
*cu
)
8479 /* Add a symbol for the namespace. */
8481 add_partial_symbol (pdi
, cu
);
8483 /* Now scan partial symbols in that namespace. */
8485 if (pdi
->has_children
)
8486 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8489 /* Read a partial die corresponding to a Fortran module. */
8492 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8493 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8495 /* Add a symbol for the namespace. */
8497 add_partial_symbol (pdi
, cu
);
8499 /* Now scan partial symbols in that module. */
8501 if (pdi
->has_children
)
8502 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8505 /* Read a partial die corresponding to a subprogram or an inlined
8506 subprogram and create a partial symbol for that subprogram.
8507 When the CU language allows it, this routine also defines a partial
8508 symbol for each nested subprogram that this subprogram contains.
8509 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8510 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8512 PDI may also be a lexical block, in which case we simply search
8513 recursively for subprograms defined inside that lexical block.
8514 Again, this is only performed when the CU language allows this
8515 type of definitions. */
8518 add_partial_subprogram (struct partial_die_info
*pdi
,
8519 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8520 int set_addrmap
, struct dwarf2_cu
*cu
)
8522 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8524 if (pdi
->has_pc_info
)
8526 if (pdi
->lowpc
< *lowpc
)
8527 *lowpc
= pdi
->lowpc
;
8528 if (pdi
->highpc
> *highpc
)
8529 *highpc
= pdi
->highpc
;
8532 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8533 struct gdbarch
*gdbarch
= objfile
->arch ();
8535 CORE_ADDR this_highpc
;
8536 CORE_ADDR this_lowpc
;
8538 baseaddr
= objfile
->text_section_offset ();
8540 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8541 pdi
->lowpc
+ baseaddr
)
8544 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8545 pdi
->highpc
+ baseaddr
)
8547 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8548 this_lowpc
, this_highpc
- 1,
8549 cu
->per_cu
->v
.psymtab
);
8553 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8555 if (!pdi
->is_declaration
)
8556 /* Ignore subprogram DIEs that do not have a name, they are
8557 illegal. Do not emit a complaint at this point, we will
8558 do so when we convert this psymtab into a symtab. */
8560 add_partial_symbol (pdi
, cu
);
8564 if (! pdi
->has_children
)
8567 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8569 pdi
= pdi
->die_child
;
8573 if (pdi
->tag
== DW_TAG_subprogram
8574 || pdi
->tag
== DW_TAG_inlined_subroutine
8575 || pdi
->tag
== DW_TAG_lexical_block
)
8576 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8577 pdi
= pdi
->die_sibling
;
8582 /* Read a partial die corresponding to an enumeration type. */
8585 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8586 struct dwarf2_cu
*cu
)
8588 struct partial_die_info
*pdi
;
8590 if (enum_pdi
->name
!= NULL
)
8591 add_partial_symbol (enum_pdi
, cu
);
8593 pdi
= enum_pdi
->die_child
;
8596 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8597 complaint (_("malformed enumerator DIE ignored"));
8599 add_partial_symbol (pdi
, cu
);
8600 pdi
= pdi
->die_sibling
;
8604 /* Return the initial uleb128 in the die at INFO_PTR. */
8607 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8609 unsigned int bytes_read
;
8611 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8614 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8615 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8617 Return the corresponding abbrev, or NULL if the number is zero (indicating
8618 an empty DIE). In either case *BYTES_READ will be set to the length of
8619 the initial number. */
8621 static struct abbrev_info
*
8622 peek_die_abbrev (const die_reader_specs
&reader
,
8623 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8625 dwarf2_cu
*cu
= reader
.cu
;
8626 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8627 unsigned int abbrev_number
8628 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8630 if (abbrev_number
== 0)
8633 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8636 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8637 " at offset %s [in module %s]"),
8638 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8639 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8645 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8646 Returns a pointer to the end of a series of DIEs, terminated by an empty
8647 DIE. Any children of the skipped DIEs will also be skipped. */
8649 static const gdb_byte
*
8650 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8654 unsigned int bytes_read
;
8655 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8658 return info_ptr
+ bytes_read
;
8660 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8664 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8665 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8666 abbrev corresponding to that skipped uleb128 should be passed in
8667 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8670 static const gdb_byte
*
8671 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8672 struct abbrev_info
*abbrev
)
8674 unsigned int bytes_read
;
8675 struct attribute attr
;
8676 bfd
*abfd
= reader
->abfd
;
8677 struct dwarf2_cu
*cu
= reader
->cu
;
8678 const gdb_byte
*buffer
= reader
->buffer
;
8679 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8680 unsigned int form
, i
;
8682 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8684 /* The only abbrev we care about is DW_AT_sibling. */
8685 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8688 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8690 if (attr
.form
== DW_FORM_ref_addr
)
8691 complaint (_("ignoring absolute DW_AT_sibling"));
8694 sect_offset off
= attr
.get_ref_die_offset ();
8695 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8697 if (sibling_ptr
< info_ptr
)
8698 complaint (_("DW_AT_sibling points backwards"));
8699 else if (sibling_ptr
> reader
->buffer_end
)
8700 reader
->die_section
->overflow_complaint ();
8706 /* If it isn't DW_AT_sibling, skip this attribute. */
8707 form
= abbrev
->attrs
[i
].form
;
8711 case DW_FORM_ref_addr
:
8712 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8713 and later it is offset sized. */
8714 if (cu
->header
.version
== 2)
8715 info_ptr
+= cu
->header
.addr_size
;
8717 info_ptr
+= cu
->header
.offset_size
;
8719 case DW_FORM_GNU_ref_alt
:
8720 info_ptr
+= cu
->header
.offset_size
;
8723 info_ptr
+= cu
->header
.addr_size
;
8731 case DW_FORM_flag_present
:
8732 case DW_FORM_implicit_const
:
8749 case DW_FORM_ref_sig8
:
8752 case DW_FORM_data16
:
8755 case DW_FORM_string
:
8756 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8757 info_ptr
+= bytes_read
;
8759 case DW_FORM_sec_offset
:
8761 case DW_FORM_GNU_strp_alt
:
8762 info_ptr
+= cu
->header
.offset_size
;
8764 case DW_FORM_exprloc
:
8766 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8767 info_ptr
+= bytes_read
;
8769 case DW_FORM_block1
:
8770 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8772 case DW_FORM_block2
:
8773 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8775 case DW_FORM_block4
:
8776 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8782 case DW_FORM_ref_udata
:
8783 case DW_FORM_GNU_addr_index
:
8784 case DW_FORM_GNU_str_index
:
8785 case DW_FORM_rnglistx
:
8786 case DW_FORM_loclistx
:
8787 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8789 case DW_FORM_indirect
:
8790 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8791 info_ptr
+= bytes_read
;
8792 /* We need to continue parsing from here, so just go back to
8794 goto skip_attribute
;
8797 error (_("Dwarf Error: Cannot handle %s "
8798 "in DWARF reader [in module %s]"),
8799 dwarf_form_name (form
),
8800 bfd_get_filename (abfd
));
8804 if (abbrev
->has_children
)
8805 return skip_children (reader
, info_ptr
);
8810 /* Locate ORIG_PDI's sibling.
8811 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8813 static const gdb_byte
*
8814 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8815 struct partial_die_info
*orig_pdi
,
8816 const gdb_byte
*info_ptr
)
8818 /* Do we know the sibling already? */
8820 if (orig_pdi
->sibling
)
8821 return orig_pdi
->sibling
;
8823 /* Are there any children to deal with? */
8825 if (!orig_pdi
->has_children
)
8828 /* Skip the children the long way. */
8830 return skip_children (reader
, info_ptr
);
8833 /* Expand this partial symbol table into a full symbol table. SELF is
8837 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8839 struct dwarf2_per_objfile
*dwarf2_per_objfile
8840 = get_dwarf2_per_objfile (objfile
);
8842 gdb_assert (!readin
);
8843 /* If this psymtab is constructed from a debug-only objfile, the
8844 has_section_at_zero flag will not necessarily be correct. We
8845 can get the correct value for this flag by looking at the data
8846 associated with the (presumably stripped) associated objfile. */
8847 if (objfile
->separate_debug_objfile_backlink
)
8849 struct dwarf2_per_objfile
*dpo_backlink
8850 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8852 dwarf2_per_objfile
->has_section_at_zero
8853 = dpo_backlink
->has_section_at_zero
;
8856 expand_psymtab (objfile
);
8858 process_cu_includes (dwarf2_per_objfile
);
8861 /* Reading in full CUs. */
8863 /* Add PER_CU to the queue. */
8866 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8867 enum language pretend_language
)
8870 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8873 /* If PER_CU is not yet queued, add it to the queue.
8874 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8876 The result is non-zero if PER_CU was queued, otherwise the result is zero
8877 meaning either PER_CU is already queued or it is already loaded.
8879 N.B. There is an invariant here that if a CU is queued then it is loaded.
8880 The caller is required to load PER_CU if we return non-zero. */
8883 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8884 struct dwarf2_per_cu_data
*per_cu
,
8885 enum language pretend_language
)
8887 /* We may arrive here during partial symbol reading, if we need full
8888 DIEs to process an unusual case (e.g. template arguments). Do
8889 not queue PER_CU, just tell our caller to load its DIEs. */
8890 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8892 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8897 /* Mark the dependence relation so that we don't flush PER_CU
8899 if (dependent_cu
!= NULL
)
8900 dwarf2_add_dependence (dependent_cu
, per_cu
);
8902 /* If it's already on the queue, we have nothing to do. */
8906 /* If the compilation unit is already loaded, just mark it as
8908 if (per_cu
->cu
!= NULL
)
8910 per_cu
->cu
->last_used
= 0;
8914 /* Add it to the queue. */
8915 queue_comp_unit (per_cu
, pretend_language
);
8920 /* Process the queue. */
8923 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8925 if (dwarf_read_debug
)
8927 fprintf_unfiltered (gdb_stdlog
,
8928 "Expanding one or more symtabs of objfile %s ...\n",
8929 objfile_name (dwarf2_per_objfile
->objfile
));
8932 /* The queue starts out with one item, but following a DIE reference
8933 may load a new CU, adding it to the end of the queue. */
8934 while (!dwarf2_per_objfile
->queue
.empty ())
8936 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8938 if ((dwarf2_per_objfile
->using_index
8939 ? !item
.per_cu
->v
.quick
->compunit_symtab
8940 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8941 /* Skip dummy CUs. */
8942 && item
.per_cu
->cu
!= NULL
)
8944 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8945 unsigned int debug_print_threshold
;
8948 if (per_cu
->is_debug_types
)
8950 struct signatured_type
*sig_type
=
8951 (struct signatured_type
*) per_cu
;
8953 sprintf (buf
, "TU %s at offset %s",
8954 hex_string (sig_type
->signature
),
8955 sect_offset_str (per_cu
->sect_off
));
8956 /* There can be 100s of TUs.
8957 Only print them in verbose mode. */
8958 debug_print_threshold
= 2;
8962 sprintf (buf
, "CU at offset %s",
8963 sect_offset_str (per_cu
->sect_off
));
8964 debug_print_threshold
= 1;
8967 if (dwarf_read_debug
>= debug_print_threshold
)
8968 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8970 if (per_cu
->is_debug_types
)
8971 process_full_type_unit (per_cu
, item
.pretend_language
);
8973 process_full_comp_unit (per_cu
, item
.pretend_language
);
8975 if (dwarf_read_debug
>= debug_print_threshold
)
8976 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8979 item
.per_cu
->queued
= 0;
8980 dwarf2_per_objfile
->queue
.pop ();
8983 if (dwarf_read_debug
)
8985 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8986 objfile_name (dwarf2_per_objfile
->objfile
));
8990 /* Read in full symbols for PST, and anything it depends on. */
8993 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8995 gdb_assert (!readin
);
8997 expand_dependencies (objfile
);
8999 dw2_do_instantiate_symtab (per_cu_data
, false);
9000 gdb_assert (get_compunit_symtab () != nullptr);
9003 /* Trivial hash function for die_info: the hash value of a DIE
9004 is its offset in .debug_info for this objfile. */
9007 die_hash (const void *item
)
9009 const struct die_info
*die
= (const struct die_info
*) item
;
9011 return to_underlying (die
->sect_off
);
9014 /* Trivial comparison function for die_info structures: two DIEs
9015 are equal if they have the same offset. */
9018 die_eq (const void *item_lhs
, const void *item_rhs
)
9020 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9021 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9023 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9026 /* Load the DIEs associated with PER_CU into memory. */
9029 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9031 enum language pretend_language
)
9033 gdb_assert (! this_cu
->is_debug_types
);
9035 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
9039 struct dwarf2_cu
*cu
= reader
.cu
;
9040 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9042 gdb_assert (cu
->die_hash
== NULL
);
9044 htab_create_alloc_ex (cu
->header
.length
/ 12,
9048 &cu
->comp_unit_obstack
,
9049 hashtab_obstack_allocate
,
9050 dummy_obstack_deallocate
);
9052 if (reader
.comp_unit_die
->has_children
)
9053 reader
.comp_unit_die
->child
9054 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9055 &info_ptr
, reader
.comp_unit_die
);
9056 cu
->dies
= reader
.comp_unit_die
;
9057 /* comp_unit_die is not stored in die_hash, no need. */
9059 /* We try not to read any attributes in this function, because not
9060 all CUs needed for references have been loaded yet, and symbol
9061 table processing isn't initialized. But we have to set the CU language,
9062 or we won't be able to build types correctly.
9063 Similarly, if we do not read the producer, we can not apply
9064 producer-specific interpretation. */
9065 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9070 /* Add a DIE to the delayed physname list. */
9073 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9074 const char *name
, struct die_info
*die
,
9075 struct dwarf2_cu
*cu
)
9077 struct delayed_method_info mi
;
9079 mi
.fnfield_index
= fnfield_index
;
9083 cu
->method_list
.push_back (mi
);
9086 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9087 "const" / "volatile". If so, decrements LEN by the length of the
9088 modifier and return true. Otherwise return false. */
9092 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9094 size_t mod_len
= sizeof (mod
) - 1;
9095 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9103 /* Compute the physnames of any methods on the CU's method list.
9105 The computation of method physnames is delayed in order to avoid the
9106 (bad) condition that one of the method's formal parameters is of an as yet
9110 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9112 /* Only C++ delays computing physnames. */
9113 if (cu
->method_list
.empty ())
9115 gdb_assert (cu
->language
== language_cplus
);
9117 for (const delayed_method_info
&mi
: cu
->method_list
)
9119 const char *physname
;
9120 struct fn_fieldlist
*fn_flp
9121 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9122 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9123 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9124 = physname
? physname
: "";
9126 /* Since there's no tag to indicate whether a method is a
9127 const/volatile overload, extract that information out of the
9129 if (physname
!= NULL
)
9131 size_t len
= strlen (physname
);
9135 if (physname
[len
] == ')') /* shortcut */
9137 else if (check_modifier (physname
, len
, " const"))
9138 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9139 else if (check_modifier (physname
, len
, " volatile"))
9140 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9147 /* The list is no longer needed. */
9148 cu
->method_list
.clear ();
9151 /* Go objects should be embedded in a DW_TAG_module DIE,
9152 and it's not clear if/how imported objects will appear.
9153 To keep Go support simple until that's worked out,
9154 go back through what we've read and create something usable.
9155 We could do this while processing each DIE, and feels kinda cleaner,
9156 but that way is more invasive.
9157 This is to, for example, allow the user to type "p var" or "b main"
9158 without having to specify the package name, and allow lookups
9159 of module.object to work in contexts that use the expression
9163 fixup_go_packaging (struct dwarf2_cu
*cu
)
9165 gdb::unique_xmalloc_ptr
<char> package_name
;
9166 struct pending
*list
;
9169 for (list
= *cu
->get_builder ()->get_global_symbols ();
9173 for (i
= 0; i
< list
->nsyms
; ++i
)
9175 struct symbol
*sym
= list
->symbol
[i
];
9177 if (sym
->language () == language_go
9178 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9180 gdb::unique_xmalloc_ptr
<char> this_package_name
9181 (go_symbol_package_name (sym
));
9183 if (this_package_name
== NULL
)
9185 if (package_name
== NULL
)
9186 package_name
= std::move (this_package_name
);
9189 struct objfile
*objfile
9190 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9191 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9192 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9193 (symbol_symtab (sym
) != NULL
9194 ? symtab_to_filename_for_display
9195 (symbol_symtab (sym
))
9196 : objfile_name (objfile
)),
9197 this_package_name
.get (), package_name
.get ());
9203 if (package_name
!= NULL
)
9205 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9206 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9207 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9208 saved_package_name
);
9211 sym
= new (&objfile
->objfile_obstack
) symbol
;
9212 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9213 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9214 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9215 e.g., "main" finds the "main" module and not C's main(). */
9216 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9217 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9218 SYMBOL_TYPE (sym
) = type
;
9220 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9224 /* Allocate a fully-qualified name consisting of the two parts on the
9228 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9230 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9233 /* A helper that allocates a variant part to attach to a Rust enum
9234 type. OBSTACK is where the results should be allocated. TYPE is
9235 the type we're processing. DISCRIMINANT_INDEX is the index of the
9236 discriminant. It must be the index of one of the fields of TYPE.
9237 DEFAULT_INDEX is the index of the default field; or -1 if there is
9238 no default. RANGES is indexed by "effective" field number (the
9239 field index, but omitting the discriminant and default fields) and
9240 must hold the discriminant values used by the variants. Note that
9241 RANGES must have a lifetime at least as long as OBSTACK -- either
9242 already allocated on it, or static. */
9245 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9246 int discriminant_index
, int default_index
,
9247 gdb::array_view
<discriminant_range
> ranges
)
9249 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9250 must be handled by the caller. */
9251 gdb_assert (discriminant_index
>= 0
9252 && discriminant_index
< type
->num_fields ());
9253 gdb_assert (default_index
== -1
9254 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9256 /* We have one variant for each non-discriminant field. */
9257 int n_variants
= type
->num_fields () - 1;
9259 variant
*variants
= new (obstack
) variant
[n_variants
];
9262 for (int i
= 0; i
< type
->num_fields (); ++i
)
9264 if (i
== discriminant_index
)
9267 variants
[var_idx
].first_field
= i
;
9268 variants
[var_idx
].last_field
= i
+ 1;
9270 /* The default field does not need a range, but other fields do.
9271 We skipped the discriminant above. */
9272 if (i
!= default_index
)
9274 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9281 gdb_assert (range_idx
== ranges
.size ());
9282 gdb_assert (var_idx
== n_variants
);
9284 variant_part
*part
= new (obstack
) variant_part
;
9285 part
->discriminant_index
= discriminant_index
;
9286 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9287 discriminant_index
));
9288 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9290 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9291 gdb::array_view
<variant_part
> *prop_value
9292 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9294 struct dynamic_prop prop
;
9295 prop
.kind
= PROP_VARIANT_PARTS
;
9296 prop
.data
.variant_parts
= prop_value
;
9298 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9301 /* Some versions of rustc emitted enums in an unusual way.
9303 Ordinary enums were emitted as unions. The first element of each
9304 structure in the union was named "RUST$ENUM$DISR". This element
9305 held the discriminant.
9307 These versions of Rust also implemented the "non-zero"
9308 optimization. When the enum had two values, and one is empty and
9309 the other holds a pointer that cannot be zero, the pointer is used
9310 as the discriminant, with a zero value meaning the empty variant.
9311 Here, the union's first member is of the form
9312 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9313 where the fieldnos are the indices of the fields that should be
9314 traversed in order to find the field (which may be several fields deep)
9315 and the variantname is the name of the variant of the case when the
9318 This function recognizes whether TYPE is of one of these forms,
9319 and, if so, smashes it to be a variant type. */
9322 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9324 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9326 /* We don't need to deal with empty enums. */
9327 if (type
->num_fields () == 0)
9330 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9331 if (type
->num_fields () == 1
9332 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9334 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9336 /* Decode the field name to find the offset of the
9338 ULONGEST bit_offset
= 0;
9339 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9340 while (name
[0] >= '0' && name
[0] <= '9')
9343 unsigned long index
= strtoul (name
, &tail
, 10);
9346 || index
>= field_type
->num_fields ()
9347 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9348 != FIELD_LOC_KIND_BITPOS
))
9350 complaint (_("Could not parse Rust enum encoding string \"%s\""
9352 TYPE_FIELD_NAME (type
, 0),
9353 objfile_name (objfile
));
9358 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9359 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9362 /* Smash this type to be a structure type. We have to do this
9363 because the type has already been recorded. */
9364 type
->set_code (TYPE_CODE_STRUCT
);
9365 type
->set_num_fields (3);
9366 /* Save the field we care about. */
9367 struct field saved_field
= TYPE_FIELD (type
, 0);
9369 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9371 /* Put the discriminant at index 0. */
9372 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9373 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9374 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9375 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), bit_offset
);
9377 /* The order of fields doesn't really matter, so put the real
9378 field at index 1 and the data-less field at index 2. */
9379 TYPE_FIELD (type
, 1) = saved_field
;
9380 TYPE_FIELD_NAME (type
, 1)
9381 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9382 TYPE_FIELD_TYPE (type
, 1)->set_name
9383 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9384 TYPE_FIELD_NAME (type
, 1)));
9386 const char *dataless_name
9387 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9389 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9391 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9392 /* NAME points into the original discriminant name, which
9393 already has the correct lifetime. */
9394 TYPE_FIELD_NAME (type
, 2) = name
;
9395 SET_FIELD_BITPOS (TYPE_FIELD (type
, 2), 0);
9397 /* Indicate that this is a variant type. */
9398 static discriminant_range ranges
[1] = { { 0, 0 } };
9399 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9401 /* A union with a single anonymous field is probably an old-style
9403 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9405 /* Smash this type to be a structure type. We have to do this
9406 because the type has already been recorded. */
9407 type
->set_code (TYPE_CODE_STRUCT
);
9409 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9410 const char *variant_name
9411 = rust_last_path_segment (field_type
->name ());
9412 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9413 field_type
->set_name
9414 (rust_fully_qualify (&objfile
->objfile_obstack
,
9415 type
->name (), variant_name
));
9419 struct type
*disr_type
= nullptr;
9420 for (int i
= 0; i
< type
->num_fields (); ++i
)
9422 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9424 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9426 /* All fields of a true enum will be structs. */
9429 else if (disr_type
->num_fields () == 0)
9431 /* Could be data-less variant, so keep going. */
9432 disr_type
= nullptr;
9434 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9435 "RUST$ENUM$DISR") != 0)
9437 /* Not a Rust enum. */
9447 /* If we got here without a discriminant, then it's probably
9449 if (disr_type
== nullptr)
9452 /* Smash this type to be a structure type. We have to do this
9453 because the type has already been recorded. */
9454 type
->set_code (TYPE_CODE_STRUCT
);
9456 /* Make space for the discriminant field. */
9457 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9459 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9460 * sizeof (struct field
)));
9461 memcpy (new_fields
+ 1, type
->fields (),
9462 type
->num_fields () * sizeof (struct field
));
9463 type
->set_fields (new_fields
);
9464 type
->set_num_fields (type
->num_fields () + 1);
9466 /* Install the discriminant at index 0 in the union. */
9467 TYPE_FIELD (type
, 0) = *disr_field
;
9468 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9469 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9471 /* We need a way to find the correct discriminant given a
9472 variant name. For convenience we build a map here. */
9473 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9474 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9475 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9477 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9480 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9481 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9485 int n_fields
= type
->num_fields ();
9486 /* We don't need a range entry for the discriminant, but we do
9487 need one for every other field, as there is no default
9489 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9492 /* Skip the discriminant here. */
9493 for (int i
= 1; i
< n_fields
; ++i
)
9495 /* Find the final word in the name of this variant's type.
9496 That name can be used to look up the correct
9498 const char *variant_name
9499 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9501 auto iter
= discriminant_map
.find (variant_name
);
9502 if (iter
!= discriminant_map
.end ())
9504 ranges
[i
].low
= iter
->second
;
9505 ranges
[i
].high
= iter
->second
;
9508 /* Remove the discriminant field, if it exists. */
9509 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9510 if (sub_type
->num_fields () > 0)
9512 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9513 sub_type
->set_fields (sub_type
->fields () + 1);
9515 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9517 (rust_fully_qualify (&objfile
->objfile_obstack
,
9518 type
->name (), variant_name
));
9521 /* Indicate that this is a variant type. */
9522 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9523 gdb::array_view
<discriminant_range
> (ranges
,
9528 /* Rewrite some Rust unions to be structures with variants parts. */
9531 rust_union_quirks (struct dwarf2_cu
*cu
)
9533 gdb_assert (cu
->language
== language_rust
);
9534 for (type
*type_
: cu
->rust_unions
)
9535 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9536 /* We don't need this any more. */
9537 cu
->rust_unions
.clear ();
9540 /* Return the symtab for PER_CU. This works properly regardless of
9541 whether we're using the index or psymtabs. */
9543 static struct compunit_symtab
*
9544 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9546 return (per_cu
->dwarf2_per_objfile
->using_index
9547 ? per_cu
->v
.quick
->compunit_symtab
9548 : per_cu
->v
.psymtab
->compunit_symtab
);
9551 /* A helper function for computing the list of all symbol tables
9552 included by PER_CU. */
9555 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9556 htab_t all_children
, htab_t all_type_symtabs
,
9557 struct dwarf2_per_cu_data
*per_cu
,
9558 struct compunit_symtab
*immediate_parent
)
9561 struct compunit_symtab
*cust
;
9563 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9566 /* This inclusion and its children have been processed. */
9571 /* Only add a CU if it has a symbol table. */
9572 cust
= get_compunit_symtab (per_cu
);
9575 /* If this is a type unit only add its symbol table if we haven't
9576 seen it yet (type unit per_cu's can share symtabs). */
9577 if (per_cu
->is_debug_types
)
9579 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9583 result
->push_back (cust
);
9584 if (cust
->user
== NULL
)
9585 cust
->user
= immediate_parent
;
9590 result
->push_back (cust
);
9591 if (cust
->user
== NULL
)
9592 cust
->user
= immediate_parent
;
9596 if (!per_cu
->imported_symtabs_empty ())
9597 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9599 recursively_compute_inclusions (result
, all_children
,
9600 all_type_symtabs
, ptr
, cust
);
9604 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9608 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9610 gdb_assert (! per_cu
->is_debug_types
);
9612 if (!per_cu
->imported_symtabs_empty ())
9615 std::vector
<compunit_symtab
*> result_symtabs
;
9616 htab_t all_children
, all_type_symtabs
;
9617 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9619 /* If we don't have a symtab, we can just skip this case. */
9623 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9624 NULL
, xcalloc
, xfree
);
9625 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9626 NULL
, xcalloc
, xfree
);
9628 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9630 recursively_compute_inclusions (&result_symtabs
, all_children
,
9631 all_type_symtabs
, ptr
, cust
);
9634 /* Now we have a transitive closure of all the included symtabs. */
9635 len
= result_symtabs
.size ();
9637 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9638 struct compunit_symtab
*, len
+ 1);
9639 memcpy (cust
->includes
, result_symtabs
.data (),
9640 len
* sizeof (compunit_symtab
*));
9641 cust
->includes
[len
] = NULL
;
9643 htab_delete (all_children
);
9644 htab_delete (all_type_symtabs
);
9648 /* Compute the 'includes' field for the symtabs of all the CUs we just
9652 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9654 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9656 if (! iter
->is_debug_types
)
9657 compute_compunit_symtab_includes (iter
);
9660 dwarf2_per_objfile
->just_read_cus
.clear ();
9663 /* Generate full symbol information for PER_CU, whose DIEs have
9664 already been loaded into memory. */
9667 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9668 enum language pretend_language
)
9670 struct dwarf2_cu
*cu
= per_cu
->cu
;
9671 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9672 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9673 struct gdbarch
*gdbarch
= objfile
->arch ();
9674 CORE_ADDR lowpc
, highpc
;
9675 struct compunit_symtab
*cust
;
9677 struct block
*static_block
;
9680 baseaddr
= objfile
->text_section_offset ();
9682 /* Clear the list here in case something was left over. */
9683 cu
->method_list
.clear ();
9685 cu
->language
= pretend_language
;
9686 cu
->language_defn
= language_def (cu
->language
);
9688 /* Do line number decoding in read_file_scope () */
9689 process_die (cu
->dies
, cu
);
9691 /* For now fudge the Go package. */
9692 if (cu
->language
== language_go
)
9693 fixup_go_packaging (cu
);
9695 /* Now that we have processed all the DIEs in the CU, all the types
9696 should be complete, and it should now be safe to compute all of the
9698 compute_delayed_physnames (cu
);
9700 if (cu
->language
== language_rust
)
9701 rust_union_quirks (cu
);
9703 /* Some compilers don't define a DW_AT_high_pc attribute for the
9704 compilation unit. If the DW_AT_high_pc is missing, synthesize
9705 it, by scanning the DIE's below the compilation unit. */
9706 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9708 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9709 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9711 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9712 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9713 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9714 addrmap to help ensure it has an accurate map of pc values belonging to
9716 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9718 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9719 SECT_OFF_TEXT (objfile
),
9724 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9726 /* Set symtab language to language from DW_AT_language. If the
9727 compilation is from a C file generated by language preprocessors, do
9728 not set the language if it was already deduced by start_subfile. */
9729 if (!(cu
->language
== language_c
9730 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9731 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9733 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9734 produce DW_AT_location with location lists but it can be possibly
9735 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9736 there were bugs in prologue debug info, fixed later in GCC-4.5
9737 by "unwind info for epilogues" patch (which is not directly related).
9739 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9740 needed, it would be wrong due to missing DW_AT_producer there.
9742 Still one can confuse GDB by using non-standard GCC compilation
9743 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9745 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9746 cust
->locations_valid
= 1;
9748 if (gcc_4_minor
>= 5)
9749 cust
->epilogue_unwind_valid
= 1;
9751 cust
->call_site_htab
= cu
->call_site_htab
;
9754 if (dwarf2_per_objfile
->using_index
)
9755 per_cu
->v
.quick
->compunit_symtab
= cust
;
9758 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9759 pst
->compunit_symtab
= cust
;
9763 /* Push it for inclusion processing later. */
9764 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9766 /* Not needed any more. */
9767 cu
->reset_builder ();
9770 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9771 already been loaded into memory. */
9774 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9775 enum language pretend_language
)
9777 struct dwarf2_cu
*cu
= per_cu
->cu
;
9778 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9779 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9780 struct compunit_symtab
*cust
;
9781 struct signatured_type
*sig_type
;
9783 gdb_assert (per_cu
->is_debug_types
);
9784 sig_type
= (struct signatured_type
*) per_cu
;
9786 /* Clear the list here in case something was left over. */
9787 cu
->method_list
.clear ();
9789 cu
->language
= pretend_language
;
9790 cu
->language_defn
= language_def (cu
->language
);
9792 /* The symbol tables are set up in read_type_unit_scope. */
9793 process_die (cu
->dies
, cu
);
9795 /* For now fudge the Go package. */
9796 if (cu
->language
== language_go
)
9797 fixup_go_packaging (cu
);
9799 /* Now that we have processed all the DIEs in the CU, all the types
9800 should be complete, and it should now be safe to compute all of the
9802 compute_delayed_physnames (cu
);
9804 if (cu
->language
== language_rust
)
9805 rust_union_quirks (cu
);
9807 /* TUs share symbol tables.
9808 If this is the first TU to use this symtab, complete the construction
9809 of it with end_expandable_symtab. Otherwise, complete the addition of
9810 this TU's symbols to the existing symtab. */
9811 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9813 buildsym_compunit
*builder
= cu
->get_builder ();
9814 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9815 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9819 /* Set symtab language to language from DW_AT_language. If the
9820 compilation is from a C file generated by language preprocessors,
9821 do not set the language if it was already deduced by
9823 if (!(cu
->language
== language_c
9824 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9825 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9830 cu
->get_builder ()->augment_type_symtab ();
9831 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9834 if (dwarf2_per_objfile
->using_index
)
9835 per_cu
->v
.quick
->compunit_symtab
= cust
;
9838 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9839 pst
->compunit_symtab
= cust
;
9843 /* Not needed any more. */
9844 cu
->reset_builder ();
9847 /* Process an imported unit DIE. */
9850 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9852 struct attribute
*attr
;
9854 /* For now we don't handle imported units in type units. */
9855 if (cu
->per_cu
->is_debug_types
)
9857 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9858 " supported in type units [in module %s]"),
9859 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9862 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9865 sect_offset sect_off
= attr
->get_ref_die_offset ();
9866 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9867 dwarf2_per_cu_data
*per_cu
9868 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9869 cu
->per_cu
->dwarf2_per_objfile
);
9871 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9872 into another compilation unit, at root level. Regard this as a hint,
9874 if (die
->parent
&& die
->parent
->parent
== NULL
9875 && per_cu
->unit_type
== DW_UT_compile
9876 && per_cu
->lang
== language_cplus
)
9879 /* If necessary, add it to the queue and load its DIEs. */
9880 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9881 load_full_comp_unit (per_cu
, false, cu
->language
);
9883 cu
->per_cu
->imported_symtabs_push (per_cu
);
9887 /* RAII object that represents a process_die scope: i.e.,
9888 starts/finishes processing a DIE. */
9889 class process_die_scope
9892 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9893 : m_die (die
), m_cu (cu
)
9895 /* We should only be processing DIEs not already in process. */
9896 gdb_assert (!m_die
->in_process
);
9897 m_die
->in_process
= true;
9900 ~process_die_scope ()
9902 m_die
->in_process
= false;
9904 /* If we're done processing the DIE for the CU that owns the line
9905 header, we don't need the line header anymore. */
9906 if (m_cu
->line_header_die_owner
== m_die
)
9908 delete m_cu
->line_header
;
9909 m_cu
->line_header
= NULL
;
9910 m_cu
->line_header_die_owner
= NULL
;
9919 /* Process a die and its children. */
9922 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9924 process_die_scope
scope (die
, cu
);
9928 case DW_TAG_padding
:
9930 case DW_TAG_compile_unit
:
9931 case DW_TAG_partial_unit
:
9932 read_file_scope (die
, cu
);
9934 case DW_TAG_type_unit
:
9935 read_type_unit_scope (die
, cu
);
9937 case DW_TAG_subprogram
:
9938 /* Nested subprograms in Fortran get a prefix. */
9939 if (cu
->language
== language_fortran
9940 && die
->parent
!= NULL
9941 && die
->parent
->tag
== DW_TAG_subprogram
)
9942 cu
->processing_has_namespace_info
= true;
9944 case DW_TAG_inlined_subroutine
:
9945 read_func_scope (die
, cu
);
9947 case DW_TAG_lexical_block
:
9948 case DW_TAG_try_block
:
9949 case DW_TAG_catch_block
:
9950 read_lexical_block_scope (die
, cu
);
9952 case DW_TAG_call_site
:
9953 case DW_TAG_GNU_call_site
:
9954 read_call_site_scope (die
, cu
);
9956 case DW_TAG_class_type
:
9957 case DW_TAG_interface_type
:
9958 case DW_TAG_structure_type
:
9959 case DW_TAG_union_type
:
9960 process_structure_scope (die
, cu
);
9962 case DW_TAG_enumeration_type
:
9963 process_enumeration_scope (die
, cu
);
9966 /* These dies have a type, but processing them does not create
9967 a symbol or recurse to process the children. Therefore we can
9968 read them on-demand through read_type_die. */
9969 case DW_TAG_subroutine_type
:
9970 case DW_TAG_set_type
:
9971 case DW_TAG_array_type
:
9972 case DW_TAG_pointer_type
:
9973 case DW_TAG_ptr_to_member_type
:
9974 case DW_TAG_reference_type
:
9975 case DW_TAG_rvalue_reference_type
:
9976 case DW_TAG_string_type
:
9979 case DW_TAG_base_type
:
9980 case DW_TAG_subrange_type
:
9981 case DW_TAG_typedef
:
9982 /* Add a typedef symbol for the type definition, if it has a
9984 new_symbol (die
, read_type_die (die
, cu
), cu
);
9986 case DW_TAG_common_block
:
9987 read_common_block (die
, cu
);
9989 case DW_TAG_common_inclusion
:
9991 case DW_TAG_namespace
:
9992 cu
->processing_has_namespace_info
= true;
9993 read_namespace (die
, cu
);
9996 cu
->processing_has_namespace_info
= true;
9997 read_module (die
, cu
);
9999 case DW_TAG_imported_declaration
:
10000 cu
->processing_has_namespace_info
= true;
10001 if (read_namespace_alias (die
, cu
))
10003 /* The declaration is not a global namespace alias. */
10004 /* Fall through. */
10005 case DW_TAG_imported_module
:
10006 cu
->processing_has_namespace_info
= true;
10007 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10008 || cu
->language
!= language_fortran
))
10009 complaint (_("Tag '%s' has unexpected children"),
10010 dwarf_tag_name (die
->tag
));
10011 read_import_statement (die
, cu
);
10014 case DW_TAG_imported_unit
:
10015 process_imported_unit_die (die
, cu
);
10018 case DW_TAG_variable
:
10019 read_variable (die
, cu
);
10023 new_symbol (die
, NULL
, cu
);
10028 /* DWARF name computation. */
10030 /* A helper function for dwarf2_compute_name which determines whether DIE
10031 needs to have the name of the scope prepended to the name listed in the
10035 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10037 struct attribute
*attr
;
10041 case DW_TAG_namespace
:
10042 case DW_TAG_typedef
:
10043 case DW_TAG_class_type
:
10044 case DW_TAG_interface_type
:
10045 case DW_TAG_structure_type
:
10046 case DW_TAG_union_type
:
10047 case DW_TAG_enumeration_type
:
10048 case DW_TAG_enumerator
:
10049 case DW_TAG_subprogram
:
10050 case DW_TAG_inlined_subroutine
:
10051 case DW_TAG_member
:
10052 case DW_TAG_imported_declaration
:
10055 case DW_TAG_variable
:
10056 case DW_TAG_constant
:
10057 /* We only need to prefix "globally" visible variables. These include
10058 any variable marked with DW_AT_external or any variable that
10059 lives in a namespace. [Variables in anonymous namespaces
10060 require prefixing, but they are not DW_AT_external.] */
10062 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10064 struct dwarf2_cu
*spec_cu
= cu
;
10066 return die_needs_namespace (die_specification (die
, &spec_cu
),
10070 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10071 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10072 && die
->parent
->tag
!= DW_TAG_module
)
10074 /* A variable in a lexical block of some kind does not need a
10075 namespace, even though in C++ such variables may be external
10076 and have a mangled name. */
10077 if (die
->parent
->tag
== DW_TAG_lexical_block
10078 || die
->parent
->tag
== DW_TAG_try_block
10079 || die
->parent
->tag
== DW_TAG_catch_block
10080 || die
->parent
->tag
== DW_TAG_subprogram
)
10089 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10090 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10091 defined for the given DIE. */
10093 static struct attribute
*
10094 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10096 struct attribute
*attr
;
10098 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10100 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10105 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10106 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10107 defined for the given DIE. */
10109 static const char *
10110 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10112 const char *linkage_name
;
10114 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10115 if (linkage_name
== NULL
)
10116 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10118 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10119 See https://github.com/rust-lang/rust/issues/32925. */
10120 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10121 && strchr (linkage_name
, '{') != NULL
)
10122 linkage_name
= NULL
;
10124 return linkage_name
;
10127 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10128 compute the physname for the object, which include a method's:
10129 - formal parameters (C++),
10130 - receiver type (Go),
10132 The term "physname" is a bit confusing.
10133 For C++, for example, it is the demangled name.
10134 For Go, for example, it's the mangled name.
10136 For Ada, return the DIE's linkage name rather than the fully qualified
10137 name. PHYSNAME is ignored..
10139 The result is allocated on the objfile_obstack and canonicalized. */
10141 static const char *
10142 dwarf2_compute_name (const char *name
,
10143 struct die_info
*die
, struct dwarf2_cu
*cu
,
10146 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10149 name
= dwarf2_name (die
, cu
);
10151 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10152 but otherwise compute it by typename_concat inside GDB.
10153 FIXME: Actually this is not really true, or at least not always true.
10154 It's all very confusing. compute_and_set_names doesn't try to demangle
10155 Fortran names because there is no mangling standard. So new_symbol
10156 will set the demangled name to the result of dwarf2_full_name, and it is
10157 the demangled name that GDB uses if it exists. */
10158 if (cu
->language
== language_ada
10159 || (cu
->language
== language_fortran
&& physname
))
10161 /* For Ada unit, we prefer the linkage name over the name, as
10162 the former contains the exported name, which the user expects
10163 to be able to reference. Ideally, we want the user to be able
10164 to reference this entity using either natural or linkage name,
10165 but we haven't started looking at this enhancement yet. */
10166 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10168 if (linkage_name
!= NULL
)
10169 return linkage_name
;
10172 /* These are the only languages we know how to qualify names in. */
10174 && (cu
->language
== language_cplus
10175 || cu
->language
== language_fortran
|| cu
->language
== language_d
10176 || cu
->language
== language_rust
))
10178 if (die_needs_namespace (die
, cu
))
10180 const char *prefix
;
10181 const char *canonical_name
= NULL
;
10185 prefix
= determine_prefix (die
, cu
);
10186 if (*prefix
!= '\0')
10188 gdb::unique_xmalloc_ptr
<char> prefixed_name
10189 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10191 buf
.puts (prefixed_name
.get ());
10196 /* Template parameters may be specified in the DIE's DW_AT_name, or
10197 as children with DW_TAG_template_type_param or
10198 DW_TAG_value_type_param. If the latter, add them to the name
10199 here. If the name already has template parameters, then
10200 skip this step; some versions of GCC emit both, and
10201 it is more efficient to use the pre-computed name.
10203 Something to keep in mind about this process: it is very
10204 unlikely, or in some cases downright impossible, to produce
10205 something that will match the mangled name of a function.
10206 If the definition of the function has the same debug info,
10207 we should be able to match up with it anyway. But fallbacks
10208 using the minimal symbol, for instance to find a method
10209 implemented in a stripped copy of libstdc++, will not work.
10210 If we do not have debug info for the definition, we will have to
10211 match them up some other way.
10213 When we do name matching there is a related problem with function
10214 templates; two instantiated function templates are allowed to
10215 differ only by their return types, which we do not add here. */
10217 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10219 struct attribute
*attr
;
10220 struct die_info
*child
;
10223 die
->building_fullname
= 1;
10225 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10229 const gdb_byte
*bytes
;
10230 struct dwarf2_locexpr_baton
*baton
;
10233 if (child
->tag
!= DW_TAG_template_type_param
10234 && child
->tag
!= DW_TAG_template_value_param
)
10245 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10248 complaint (_("template parameter missing DW_AT_type"));
10249 buf
.puts ("UNKNOWN_TYPE");
10252 type
= die_type (child
, cu
);
10254 if (child
->tag
== DW_TAG_template_type_param
)
10256 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10257 &type_print_raw_options
);
10261 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10264 complaint (_("template parameter missing "
10265 "DW_AT_const_value"));
10266 buf
.puts ("UNKNOWN_VALUE");
10270 dwarf2_const_value_attr (attr
, type
, name
,
10271 &cu
->comp_unit_obstack
, cu
,
10272 &value
, &bytes
, &baton
);
10274 if (TYPE_NOSIGN (type
))
10275 /* GDB prints characters as NUMBER 'CHAR'. If that's
10276 changed, this can use value_print instead. */
10277 c_printchar (value
, type
, &buf
);
10280 struct value_print_options opts
;
10283 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10287 else if (bytes
!= NULL
)
10289 v
= allocate_value (type
);
10290 memcpy (value_contents_writeable (v
), bytes
,
10291 TYPE_LENGTH (type
));
10294 v
= value_from_longest (type
, value
);
10296 /* Specify decimal so that we do not depend on
10298 get_formatted_print_options (&opts
, 'd');
10300 value_print (v
, &buf
, &opts
);
10305 die
->building_fullname
= 0;
10309 /* Close the argument list, with a space if necessary
10310 (nested templates). */
10311 if (!buf
.empty () && buf
.string ().back () == '>')
10318 /* For C++ methods, append formal parameter type
10319 information, if PHYSNAME. */
10321 if (physname
&& die
->tag
== DW_TAG_subprogram
10322 && cu
->language
== language_cplus
)
10324 struct type
*type
= read_type_die (die
, cu
);
10326 c_type_print_args (type
, &buf
, 1, cu
->language
,
10327 &type_print_raw_options
);
10329 if (cu
->language
== language_cplus
)
10331 /* Assume that an artificial first parameter is
10332 "this", but do not crash if it is not. RealView
10333 marks unnamed (and thus unused) parameters as
10334 artificial; there is no way to differentiate
10336 if (type
->num_fields () > 0
10337 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10338 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10339 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10341 buf
.puts (" const");
10345 const std::string
&intermediate_name
= buf
.string ();
10347 if (cu
->language
== language_cplus
)
10349 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10352 /* If we only computed INTERMEDIATE_NAME, or if
10353 INTERMEDIATE_NAME is already canonical, then we need to
10355 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10356 name
= objfile
->intern (intermediate_name
);
10358 name
= canonical_name
;
10365 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10366 If scope qualifiers are appropriate they will be added. The result
10367 will be allocated on the storage_obstack, or NULL if the DIE does
10368 not have a name. NAME may either be from a previous call to
10369 dwarf2_name or NULL.
10371 The output string will be canonicalized (if C++). */
10373 static const char *
10374 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10376 return dwarf2_compute_name (name
, die
, cu
, 0);
10379 /* Construct a physname for the given DIE in CU. NAME may either be
10380 from a previous call to dwarf2_name or NULL. The result will be
10381 allocated on the objfile_objstack or NULL if the DIE does not have a
10384 The output string will be canonicalized (if C++). */
10386 static const char *
10387 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10389 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10390 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10393 /* In this case dwarf2_compute_name is just a shortcut not building anything
10395 if (!die_needs_namespace (die
, cu
))
10396 return dwarf2_compute_name (name
, die
, cu
, 1);
10398 if (cu
->language
!= language_rust
)
10399 mangled
= dw2_linkage_name (die
, cu
);
10401 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10403 gdb::unique_xmalloc_ptr
<char> demangled
;
10404 if (mangled
!= NULL
)
10407 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10409 /* Do nothing (do not demangle the symbol name). */
10411 else if (cu
->language
== language_go
)
10413 /* This is a lie, but we already lie to the caller new_symbol.
10414 new_symbol assumes we return the mangled name.
10415 This just undoes that lie until things are cleaned up. */
10419 /* Use DMGL_RET_DROP for C++ template functions to suppress
10420 their return type. It is easier for GDB users to search
10421 for such functions as `name(params)' than `long name(params)'.
10422 In such case the minimal symbol names do not match the full
10423 symbol names but for template functions there is never a need
10424 to look up their definition from their declaration so
10425 the only disadvantage remains the minimal symbol variant
10426 `long name(params)' does not have the proper inferior type. */
10427 demangled
.reset (gdb_demangle (mangled
,
10428 (DMGL_PARAMS
| DMGL_ANSI
10429 | DMGL_RET_DROP
)));
10432 canon
= demangled
.get ();
10440 if (canon
== NULL
|| check_physname
)
10442 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10444 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10446 /* It may not mean a bug in GDB. The compiler could also
10447 compute DW_AT_linkage_name incorrectly. But in such case
10448 GDB would need to be bug-to-bug compatible. */
10450 complaint (_("Computed physname <%s> does not match demangled <%s> "
10451 "(from linkage <%s>) - DIE at %s [in module %s]"),
10452 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10453 objfile_name (objfile
));
10455 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10456 is available here - over computed PHYSNAME. It is safer
10457 against both buggy GDB and buggy compilers. */
10471 retval
= objfile
->intern (retval
);
10476 /* Inspect DIE in CU for a namespace alias. If one exists, record
10477 a new symbol for it.
10479 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10482 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10484 struct attribute
*attr
;
10486 /* If the die does not have a name, this is not a namespace
10488 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10492 struct die_info
*d
= die
;
10493 struct dwarf2_cu
*imported_cu
= cu
;
10495 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10496 keep inspecting DIEs until we hit the underlying import. */
10497 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10498 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10500 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10504 d
= follow_die_ref (d
, attr
, &imported_cu
);
10505 if (d
->tag
!= DW_TAG_imported_declaration
)
10509 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10511 complaint (_("DIE at %s has too many recursively imported "
10512 "declarations"), sect_offset_str (d
->sect_off
));
10519 sect_offset sect_off
= attr
->get_ref_die_offset ();
10521 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10522 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10524 /* This declaration is a global namespace alias. Add
10525 a symbol for it whose type is the aliased namespace. */
10526 new_symbol (die
, type
, cu
);
10535 /* Return the using directives repository (global or local?) to use in the
10536 current context for CU.
10538 For Ada, imported declarations can materialize renamings, which *may* be
10539 global. However it is impossible (for now?) in DWARF to distinguish
10540 "external" imported declarations and "static" ones. As all imported
10541 declarations seem to be static in all other languages, make them all CU-wide
10542 global only in Ada. */
10544 static struct using_direct
**
10545 using_directives (struct dwarf2_cu
*cu
)
10547 if (cu
->language
== language_ada
10548 && cu
->get_builder ()->outermost_context_p ())
10549 return cu
->get_builder ()->get_global_using_directives ();
10551 return cu
->get_builder ()->get_local_using_directives ();
10554 /* Read the import statement specified by the given die and record it. */
10557 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10559 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10560 struct attribute
*import_attr
;
10561 struct die_info
*imported_die
, *child_die
;
10562 struct dwarf2_cu
*imported_cu
;
10563 const char *imported_name
;
10564 const char *imported_name_prefix
;
10565 const char *canonical_name
;
10566 const char *import_alias
;
10567 const char *imported_declaration
= NULL
;
10568 const char *import_prefix
;
10569 std::vector
<const char *> excludes
;
10571 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10572 if (import_attr
== NULL
)
10574 complaint (_("Tag '%s' has no DW_AT_import"),
10575 dwarf_tag_name (die
->tag
));
10580 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10581 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10582 if (imported_name
== NULL
)
10584 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10586 The import in the following code:
10600 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10601 <52> DW_AT_decl_file : 1
10602 <53> DW_AT_decl_line : 6
10603 <54> DW_AT_import : <0x75>
10604 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10605 <59> DW_AT_name : B
10606 <5b> DW_AT_decl_file : 1
10607 <5c> DW_AT_decl_line : 2
10608 <5d> DW_AT_type : <0x6e>
10610 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10611 <76> DW_AT_byte_size : 4
10612 <77> DW_AT_encoding : 5 (signed)
10614 imports the wrong die ( 0x75 instead of 0x58 ).
10615 This case will be ignored until the gcc bug is fixed. */
10619 /* Figure out the local name after import. */
10620 import_alias
= dwarf2_name (die
, cu
);
10622 /* Figure out where the statement is being imported to. */
10623 import_prefix
= determine_prefix (die
, cu
);
10625 /* Figure out what the scope of the imported die is and prepend it
10626 to the name of the imported die. */
10627 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10629 if (imported_die
->tag
!= DW_TAG_namespace
10630 && imported_die
->tag
!= DW_TAG_module
)
10632 imported_declaration
= imported_name
;
10633 canonical_name
= imported_name_prefix
;
10635 else if (strlen (imported_name_prefix
) > 0)
10636 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10637 imported_name_prefix
,
10638 (cu
->language
== language_d
? "." : "::"),
10639 imported_name
, (char *) NULL
);
10641 canonical_name
= imported_name
;
10643 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10644 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10645 child_die
= child_die
->sibling
)
10647 /* DWARF-4: A Fortran use statement with a “rename list” may be
10648 represented by an imported module entry with an import attribute
10649 referring to the module and owned entries corresponding to those
10650 entities that are renamed as part of being imported. */
10652 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10654 complaint (_("child DW_TAG_imported_declaration expected "
10655 "- DIE at %s [in module %s]"),
10656 sect_offset_str (child_die
->sect_off
),
10657 objfile_name (objfile
));
10661 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10662 if (import_attr
== NULL
)
10664 complaint (_("Tag '%s' has no DW_AT_import"),
10665 dwarf_tag_name (child_die
->tag
));
10670 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10672 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10673 if (imported_name
== NULL
)
10675 complaint (_("child DW_TAG_imported_declaration has unknown "
10676 "imported name - DIE at %s [in module %s]"),
10677 sect_offset_str (child_die
->sect_off
),
10678 objfile_name (objfile
));
10682 excludes
.push_back (imported_name
);
10684 process_die (child_die
, cu
);
10687 add_using_directive (using_directives (cu
),
10691 imported_declaration
,
10694 &objfile
->objfile_obstack
);
10697 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10698 types, but gives them a size of zero. Starting with version 14,
10699 ICC is compatible with GCC. */
10702 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10704 if (!cu
->checked_producer
)
10705 check_producer (cu
);
10707 return cu
->producer_is_icc_lt_14
;
10710 /* ICC generates a DW_AT_type for C void functions. This was observed on
10711 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10712 which says that void functions should not have a DW_AT_type. */
10715 producer_is_icc (struct dwarf2_cu
*cu
)
10717 if (!cu
->checked_producer
)
10718 check_producer (cu
);
10720 return cu
->producer_is_icc
;
10723 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10724 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10725 this, it was first present in GCC release 4.3.0. */
10728 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10730 if (!cu
->checked_producer
)
10731 check_producer (cu
);
10733 return cu
->producer_is_gcc_lt_4_3
;
10736 static file_and_directory
10737 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10739 file_and_directory res
;
10741 /* Find the filename. Do not use dwarf2_name here, since the filename
10742 is not a source language identifier. */
10743 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10744 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10746 if (res
.comp_dir
== NULL
10747 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10748 && IS_ABSOLUTE_PATH (res
.name
))
10750 res
.comp_dir_storage
= ldirname (res
.name
);
10751 if (!res
.comp_dir_storage
.empty ())
10752 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10754 if (res
.comp_dir
!= NULL
)
10756 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10757 directory, get rid of it. */
10758 const char *cp
= strchr (res
.comp_dir
, ':');
10760 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10761 res
.comp_dir
= cp
+ 1;
10764 if (res
.name
== NULL
)
10765 res
.name
= "<unknown>";
10770 /* Handle DW_AT_stmt_list for a compilation unit.
10771 DIE is the DW_TAG_compile_unit die for CU.
10772 COMP_DIR is the compilation directory. LOWPC is passed to
10773 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10776 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10777 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10779 struct dwarf2_per_objfile
*dwarf2_per_objfile
10780 = cu
->per_cu
->dwarf2_per_objfile
;
10781 struct attribute
*attr
;
10782 struct line_header line_header_local
;
10783 hashval_t line_header_local_hash
;
10785 int decode_mapping
;
10787 gdb_assert (! cu
->per_cu
->is_debug_types
);
10789 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10793 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10795 /* The line header hash table is only created if needed (it exists to
10796 prevent redundant reading of the line table for partial_units).
10797 If we're given a partial_unit, we'll need it. If we're given a
10798 compile_unit, then use the line header hash table if it's already
10799 created, but don't create one just yet. */
10801 if (dwarf2_per_objfile
->line_header_hash
== NULL
10802 && die
->tag
== DW_TAG_partial_unit
)
10804 dwarf2_per_objfile
->line_header_hash
10805 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10806 line_header_eq_voidp
,
10807 free_line_header_voidp
,
10811 line_header_local
.sect_off
= line_offset
;
10812 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10813 line_header_local_hash
= line_header_hash (&line_header_local
);
10814 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10816 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10817 &line_header_local
,
10818 line_header_local_hash
, NO_INSERT
);
10820 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10821 is not present in *SLOT (since if there is something in *SLOT then
10822 it will be for a partial_unit). */
10823 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10825 gdb_assert (*slot
!= NULL
);
10826 cu
->line_header
= (struct line_header
*) *slot
;
10831 /* dwarf_decode_line_header does not yet provide sufficient information.
10832 We always have to call also dwarf_decode_lines for it. */
10833 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10837 cu
->line_header
= lh
.release ();
10838 cu
->line_header_die_owner
= die
;
10840 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10844 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10845 &line_header_local
,
10846 line_header_local_hash
, INSERT
);
10847 gdb_assert (slot
!= NULL
);
10849 if (slot
!= NULL
&& *slot
== NULL
)
10851 /* This newly decoded line number information unit will be owned
10852 by line_header_hash hash table. */
10853 *slot
= cu
->line_header
;
10854 cu
->line_header_die_owner
= NULL
;
10858 /* We cannot free any current entry in (*slot) as that struct line_header
10859 may be already used by multiple CUs. Create only temporary decoded
10860 line_header for this CU - it may happen at most once for each line
10861 number information unit. And if we're not using line_header_hash
10862 then this is what we want as well. */
10863 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10865 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10866 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10871 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10874 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10876 struct dwarf2_per_objfile
*dwarf2_per_objfile
10877 = cu
->per_cu
->dwarf2_per_objfile
;
10878 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10879 struct gdbarch
*gdbarch
= objfile
->arch ();
10880 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10881 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10882 struct attribute
*attr
;
10883 struct die_info
*child_die
;
10884 CORE_ADDR baseaddr
;
10886 prepare_one_comp_unit (cu
, die
, cu
->language
);
10887 baseaddr
= objfile
->text_section_offset ();
10889 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10891 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10892 from finish_block. */
10893 if (lowpc
== ((CORE_ADDR
) -1))
10895 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10897 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10899 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10900 standardised yet. As a workaround for the language detection we fall
10901 back to the DW_AT_producer string. */
10902 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10903 cu
->language
= language_opencl
;
10905 /* Similar hack for Go. */
10906 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10907 set_cu_language (DW_LANG_Go
, cu
);
10909 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10911 /* Decode line number information if present. We do this before
10912 processing child DIEs, so that the line header table is available
10913 for DW_AT_decl_file. */
10914 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10916 /* Process all dies in compilation unit. */
10917 if (die
->child
!= NULL
)
10919 child_die
= die
->child
;
10920 while (child_die
&& child_die
->tag
)
10922 process_die (child_die
, cu
);
10923 child_die
= child_die
->sibling
;
10927 /* Decode macro information, if present. Dwarf 2 macro information
10928 refers to information in the line number info statement program
10929 header, so we can only read it if we've read the header
10931 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10933 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10934 if (attr
&& cu
->line_header
)
10936 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10937 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10939 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10943 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10944 if (attr
&& cu
->line_header
)
10946 unsigned int macro_offset
= DW_UNSND (attr
);
10948 dwarf_decode_macros (cu
, macro_offset
, 0);
10954 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10956 struct type_unit_group
*tu_group
;
10958 struct attribute
*attr
;
10960 struct signatured_type
*sig_type
;
10962 gdb_assert (per_cu
->is_debug_types
);
10963 sig_type
= (struct signatured_type
*) per_cu
;
10965 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10967 /* If we're using .gdb_index (includes -readnow) then
10968 per_cu->type_unit_group may not have been set up yet. */
10969 if (sig_type
->type_unit_group
== NULL
)
10970 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10971 tu_group
= sig_type
->type_unit_group
;
10973 /* If we've already processed this stmt_list there's no real need to
10974 do it again, we could fake it and just recreate the part we need
10975 (file name,index -> symtab mapping). If data shows this optimization
10976 is useful we can do it then. */
10977 first_time
= tu_group
->compunit_symtab
== NULL
;
10979 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10984 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10985 lh
= dwarf_decode_line_header (line_offset
, this);
10990 start_symtab ("", NULL
, 0);
10993 gdb_assert (tu_group
->symtabs
== NULL
);
10994 gdb_assert (m_builder
== nullptr);
10995 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10996 m_builder
.reset (new struct buildsym_compunit
10997 (COMPUNIT_OBJFILE (cust
), "",
10998 COMPUNIT_DIRNAME (cust
),
10999 compunit_language (cust
),
11001 list_in_scope
= get_builder ()->get_file_symbols ();
11006 line_header
= lh
.release ();
11007 line_header_die_owner
= die
;
11011 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11013 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11014 still initializing it, and our caller (a few levels up)
11015 process_full_type_unit still needs to know if this is the first
11019 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11020 struct symtab
*, line_header
->file_names_size ());
11022 auto &file_names
= line_header
->file_names ();
11023 for (i
= 0; i
< file_names
.size (); ++i
)
11025 file_entry
&fe
= file_names
[i
];
11026 dwarf2_start_subfile (this, fe
.name
,
11027 fe
.include_dir (line_header
));
11028 buildsym_compunit
*b
= get_builder ();
11029 if (b
->get_current_subfile ()->symtab
== NULL
)
11031 /* NOTE: start_subfile will recognize when it's been
11032 passed a file it has already seen. So we can't
11033 assume there's a simple mapping from
11034 cu->line_header->file_names to subfiles, plus
11035 cu->line_header->file_names may contain dups. */
11036 b
->get_current_subfile ()->symtab
11037 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11040 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11041 tu_group
->symtabs
[i
] = fe
.symtab
;
11046 gdb_assert (m_builder
== nullptr);
11047 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11048 m_builder
.reset (new struct buildsym_compunit
11049 (COMPUNIT_OBJFILE (cust
), "",
11050 COMPUNIT_DIRNAME (cust
),
11051 compunit_language (cust
),
11053 list_in_scope
= get_builder ()->get_file_symbols ();
11055 auto &file_names
= line_header
->file_names ();
11056 for (i
= 0; i
< file_names
.size (); ++i
)
11058 file_entry
&fe
= file_names
[i
];
11059 fe
.symtab
= tu_group
->symtabs
[i
];
11063 /* The main symtab is allocated last. Type units don't have DW_AT_name
11064 so they don't have a "real" (so to speak) symtab anyway.
11065 There is later code that will assign the main symtab to all symbols
11066 that don't have one. We need to handle the case of a symbol with a
11067 missing symtab (DW_AT_decl_file) anyway. */
11070 /* Process DW_TAG_type_unit.
11071 For TUs we want to skip the first top level sibling if it's not the
11072 actual type being defined by this TU. In this case the first top
11073 level sibling is there to provide context only. */
11076 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11078 struct die_info
*child_die
;
11080 prepare_one_comp_unit (cu
, die
, language_minimal
);
11082 /* Initialize (or reinitialize) the machinery for building symtabs.
11083 We do this before processing child DIEs, so that the line header table
11084 is available for DW_AT_decl_file. */
11085 cu
->setup_type_unit_groups (die
);
11087 if (die
->child
!= NULL
)
11089 child_die
= die
->child
;
11090 while (child_die
&& child_die
->tag
)
11092 process_die (child_die
, cu
);
11093 child_die
= child_die
->sibling
;
11100 http://gcc.gnu.org/wiki/DebugFission
11101 http://gcc.gnu.org/wiki/DebugFissionDWP
11103 To simplify handling of both DWO files ("object" files with the DWARF info)
11104 and DWP files (a file with the DWOs packaged up into one file), we treat
11105 DWP files as having a collection of virtual DWO files. */
11108 hash_dwo_file (const void *item
)
11110 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11113 hash
= htab_hash_string (dwo_file
->dwo_name
);
11114 if (dwo_file
->comp_dir
!= NULL
)
11115 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11120 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11122 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11123 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11125 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11127 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11128 return lhs
->comp_dir
== rhs
->comp_dir
;
11129 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11132 /* Allocate a hash table for DWO files. */
11135 allocate_dwo_file_hash_table ()
11137 auto delete_dwo_file
= [] (void *item
)
11139 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11144 return htab_up (htab_create_alloc (41,
11151 /* Lookup DWO file DWO_NAME. */
11154 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11155 const char *dwo_name
,
11156 const char *comp_dir
)
11158 struct dwo_file find_entry
;
11161 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11162 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
11164 find_entry
.dwo_name
= dwo_name
;
11165 find_entry
.comp_dir
= comp_dir
;
11166 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11173 hash_dwo_unit (const void *item
)
11175 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11177 /* This drops the top 32 bits of the id, but is ok for a hash. */
11178 return dwo_unit
->signature
;
11182 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11184 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11185 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11187 /* The signature is assumed to be unique within the DWO file.
11188 So while object file CU dwo_id's always have the value zero,
11189 that's OK, assuming each object file DWO file has only one CU,
11190 and that's the rule for now. */
11191 return lhs
->signature
== rhs
->signature
;
11194 /* Allocate a hash table for DWO CUs,TUs.
11195 There is one of these tables for each of CUs,TUs for each DWO file. */
11198 allocate_dwo_unit_table ()
11200 /* Start out with a pretty small number.
11201 Generally DWO files contain only one CU and maybe some TUs. */
11202 return htab_up (htab_create_alloc (3,
11205 NULL
, xcalloc
, xfree
));
11208 /* die_reader_func for create_dwo_cu. */
11211 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11212 const gdb_byte
*info_ptr
,
11213 struct die_info
*comp_unit_die
,
11214 struct dwo_file
*dwo_file
,
11215 struct dwo_unit
*dwo_unit
)
11217 struct dwarf2_cu
*cu
= reader
->cu
;
11218 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11219 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11221 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11222 if (!signature
.has_value ())
11224 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11225 " its dwo_id [in module %s]"),
11226 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11230 dwo_unit
->dwo_file
= dwo_file
;
11231 dwo_unit
->signature
= *signature
;
11232 dwo_unit
->section
= section
;
11233 dwo_unit
->sect_off
= sect_off
;
11234 dwo_unit
->length
= cu
->per_cu
->length
;
11236 if (dwarf_read_debug
)
11237 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11238 sect_offset_str (sect_off
),
11239 hex_string (dwo_unit
->signature
));
11242 /* Create the dwo_units for the CUs in a DWO_FILE.
11243 Note: This function processes DWO files only, not DWP files. */
11246 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11247 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11248 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11250 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11251 const gdb_byte
*info_ptr
, *end_ptr
;
11253 section
.read (objfile
);
11254 info_ptr
= section
.buffer
;
11256 if (info_ptr
== NULL
)
11259 if (dwarf_read_debug
)
11261 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11262 section
.get_name (),
11263 section
.get_file_name ());
11266 end_ptr
= info_ptr
+ section
.size
;
11267 while (info_ptr
< end_ptr
)
11269 struct dwarf2_per_cu_data per_cu
;
11270 struct dwo_unit read_unit
{};
11271 struct dwo_unit
*dwo_unit
;
11273 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11275 memset (&per_cu
, 0, sizeof (per_cu
));
11276 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11277 per_cu
.is_debug_types
= 0;
11278 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11279 per_cu
.section
= §ion
;
11281 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11282 if (!reader
.dummy_p
)
11283 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11284 &dwo_file
, &read_unit
);
11285 info_ptr
+= per_cu
.length
;
11287 // If the unit could not be parsed, skip it.
11288 if (read_unit
.dwo_file
== NULL
)
11291 if (cus_htab
== NULL
)
11292 cus_htab
= allocate_dwo_unit_table ();
11294 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11295 *dwo_unit
= read_unit
;
11296 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11297 gdb_assert (slot
!= NULL
);
11300 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11301 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11303 complaint (_("debug cu entry at offset %s is duplicate to"
11304 " the entry at offset %s, signature %s"),
11305 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11306 hex_string (dwo_unit
->signature
));
11308 *slot
= (void *)dwo_unit
;
11312 /* DWP file .debug_{cu,tu}_index section format:
11313 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11317 Both index sections have the same format, and serve to map a 64-bit
11318 signature to a set of section numbers. Each section begins with a header,
11319 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11320 indexes, and a pool of 32-bit section numbers. The index sections will be
11321 aligned at 8-byte boundaries in the file.
11323 The index section header consists of:
11325 V, 32 bit version number
11327 N, 32 bit number of compilation units or type units in the index
11328 M, 32 bit number of slots in the hash table
11330 Numbers are recorded using the byte order of the application binary.
11332 The hash table begins at offset 16 in the section, and consists of an array
11333 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11334 order of the application binary). Unused slots in the hash table are 0.
11335 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11337 The parallel table begins immediately after the hash table
11338 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11339 array of 32-bit indexes (using the byte order of the application binary),
11340 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11341 table contains a 32-bit index into the pool of section numbers. For unused
11342 hash table slots, the corresponding entry in the parallel table will be 0.
11344 The pool of section numbers begins immediately following the hash table
11345 (at offset 16 + 12 * M from the beginning of the section). The pool of
11346 section numbers consists of an array of 32-bit words (using the byte order
11347 of the application binary). Each item in the array is indexed starting
11348 from 0. The hash table entry provides the index of the first section
11349 number in the set. Additional section numbers in the set follow, and the
11350 set is terminated by a 0 entry (section number 0 is not used in ELF).
11352 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11353 section must be the first entry in the set, and the .debug_abbrev.dwo must
11354 be the second entry. Other members of the set may follow in any order.
11360 DWP Version 2 combines all the .debug_info, etc. sections into one,
11361 and the entries in the index tables are now offsets into these sections.
11362 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11365 Index Section Contents:
11367 Hash Table of Signatures dwp_hash_table.hash_table
11368 Parallel Table of Indices dwp_hash_table.unit_table
11369 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11370 Table of Section Sizes dwp_hash_table.v2.sizes
11372 The index section header consists of:
11374 V, 32 bit version number
11375 L, 32 bit number of columns in the table of section offsets
11376 N, 32 bit number of compilation units or type units in the index
11377 M, 32 bit number of slots in the hash table
11379 Numbers are recorded using the byte order of the application binary.
11381 The hash table has the same format as version 1.
11382 The parallel table of indices has the same format as version 1,
11383 except that the entries are origin-1 indices into the table of sections
11384 offsets and the table of section sizes.
11386 The table of offsets begins immediately following the parallel table
11387 (at offset 16 + 12 * M from the beginning of the section). The table is
11388 a two-dimensional array of 32-bit words (using the byte order of the
11389 application binary), with L columns and N+1 rows, in row-major order.
11390 Each row in the array is indexed starting from 0. The first row provides
11391 a key to the remaining rows: each column in this row provides an identifier
11392 for a debug section, and the offsets in the same column of subsequent rows
11393 refer to that section. The section identifiers are:
11395 DW_SECT_INFO 1 .debug_info.dwo
11396 DW_SECT_TYPES 2 .debug_types.dwo
11397 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11398 DW_SECT_LINE 4 .debug_line.dwo
11399 DW_SECT_LOC 5 .debug_loc.dwo
11400 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11401 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11402 DW_SECT_MACRO 8 .debug_macro.dwo
11404 The offsets provided by the CU and TU index sections are the base offsets
11405 for the contributions made by each CU or TU to the corresponding section
11406 in the package file. Each CU and TU header contains an abbrev_offset
11407 field, used to find the abbreviations table for that CU or TU within the
11408 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11409 be interpreted as relative to the base offset given in the index section.
11410 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11411 should be interpreted as relative to the base offset for .debug_line.dwo,
11412 and offsets into other debug sections obtained from DWARF attributes should
11413 also be interpreted as relative to the corresponding base offset.
11415 The table of sizes begins immediately following the table of offsets.
11416 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11417 with L columns and N rows, in row-major order. Each row in the array is
11418 indexed starting from 1 (row 0 is shared by the two tables).
11422 Hash table lookup is handled the same in version 1 and 2:
11424 We assume that N and M will not exceed 2^32 - 1.
11425 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11427 Given a 64-bit compilation unit signature or a type signature S, an entry
11428 in the hash table is located as follows:
11430 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11431 the low-order k bits all set to 1.
11433 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11435 3) If the hash table entry at index H matches the signature, use that
11436 entry. If the hash table entry at index H is unused (all zeroes),
11437 terminate the search: the signature is not present in the table.
11439 4) Let H = (H + H') modulo M. Repeat at Step 3.
11441 Because M > N and H' and M are relatively prime, the search is guaranteed
11442 to stop at an unused slot or find the match. */
11444 /* Create a hash table to map DWO IDs to their CU/TU entry in
11445 .debug_{info,types}.dwo in DWP_FILE.
11446 Returns NULL if there isn't one.
11447 Note: This function processes DWP files only, not DWO files. */
11449 static struct dwp_hash_table
*
11450 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11451 struct dwp_file
*dwp_file
, int is_debug_types
)
11453 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11454 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11455 const gdb_byte
*index_ptr
, *index_end
;
11456 struct dwarf2_section_info
*index
;
11457 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11458 struct dwp_hash_table
*htab
;
11460 if (is_debug_types
)
11461 index
= &dwp_file
->sections
.tu_index
;
11463 index
= &dwp_file
->sections
.cu_index
;
11465 if (index
->empty ())
11467 index
->read (objfile
);
11469 index_ptr
= index
->buffer
;
11470 index_end
= index_ptr
+ index
->size
;
11472 version
= read_4_bytes (dbfd
, index_ptr
);
11475 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11479 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11481 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11484 if (version
!= 1 && version
!= 2)
11486 error (_("Dwarf Error: unsupported DWP file version (%s)"
11487 " [in module %s]"),
11488 pulongest (version
), dwp_file
->name
);
11490 if (nr_slots
!= (nr_slots
& -nr_slots
))
11492 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11493 " is not power of 2 [in module %s]"),
11494 pulongest (nr_slots
), dwp_file
->name
);
11497 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11498 htab
->version
= version
;
11499 htab
->nr_columns
= nr_columns
;
11500 htab
->nr_units
= nr_units
;
11501 htab
->nr_slots
= nr_slots
;
11502 htab
->hash_table
= index_ptr
;
11503 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11505 /* Exit early if the table is empty. */
11506 if (nr_slots
== 0 || nr_units
== 0
11507 || (version
== 2 && nr_columns
== 0))
11509 /* All must be zero. */
11510 if (nr_slots
!= 0 || nr_units
!= 0
11511 || (version
== 2 && nr_columns
!= 0))
11513 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11514 " all zero [in modules %s]"),
11522 htab
->section_pool
.v1
.indices
=
11523 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11524 /* It's harder to decide whether the section is too small in v1.
11525 V1 is deprecated anyway so we punt. */
11529 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11530 int *ids
= htab
->section_pool
.v2
.section_ids
;
11531 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11532 /* Reverse map for error checking. */
11533 int ids_seen
[DW_SECT_MAX
+ 1];
11536 if (nr_columns
< 2)
11538 error (_("Dwarf Error: bad DWP hash table, too few columns"
11539 " in section table [in module %s]"),
11542 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11544 error (_("Dwarf Error: bad DWP hash table, too many columns"
11545 " in section table [in module %s]"),
11548 memset (ids
, 255, sizeof_ids
);
11549 memset (ids_seen
, 255, sizeof (ids_seen
));
11550 for (i
= 0; i
< nr_columns
; ++i
)
11552 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11554 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11556 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11557 " in section table [in module %s]"),
11558 id
, dwp_file
->name
);
11560 if (ids_seen
[id
] != -1)
11562 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11563 " id %d in section table [in module %s]"),
11564 id
, dwp_file
->name
);
11569 /* Must have exactly one info or types section. */
11570 if (((ids_seen
[DW_SECT_INFO
] != -1)
11571 + (ids_seen
[DW_SECT_TYPES
] != -1))
11574 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11575 " DWO info/types section [in module %s]"),
11578 /* Must have an abbrev section. */
11579 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11581 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11582 " section [in module %s]"),
11585 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11586 htab
->section_pool
.v2
.sizes
=
11587 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11588 * nr_units
* nr_columns
);
11589 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11590 * nr_units
* nr_columns
))
11593 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11594 " [in module %s]"),
11602 /* Update SECTIONS with the data from SECTP.
11604 This function is like the other "locate" section routines that are
11605 passed to bfd_map_over_sections, but in this context the sections to
11606 read comes from the DWP V1 hash table, not the full ELF section table.
11608 The result is non-zero for success, or zero if an error was found. */
11611 locate_v1_virtual_dwo_sections (asection
*sectp
,
11612 struct virtual_v1_dwo_sections
*sections
)
11614 const struct dwop_section_names
*names
= &dwop_section_names
;
11616 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11618 /* There can be only one. */
11619 if (sections
->abbrev
.s
.section
!= NULL
)
11621 sections
->abbrev
.s
.section
= sectp
;
11622 sections
->abbrev
.size
= bfd_section_size (sectp
);
11624 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11625 || section_is_p (sectp
->name
, &names
->types_dwo
))
11627 /* There can be only one. */
11628 if (sections
->info_or_types
.s
.section
!= NULL
)
11630 sections
->info_or_types
.s
.section
= sectp
;
11631 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11633 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11635 /* There can be only one. */
11636 if (sections
->line
.s
.section
!= NULL
)
11638 sections
->line
.s
.section
= sectp
;
11639 sections
->line
.size
= bfd_section_size (sectp
);
11641 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11643 /* There can be only one. */
11644 if (sections
->loc
.s
.section
!= NULL
)
11646 sections
->loc
.s
.section
= sectp
;
11647 sections
->loc
.size
= bfd_section_size (sectp
);
11649 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11651 /* There can be only one. */
11652 if (sections
->macinfo
.s
.section
!= NULL
)
11654 sections
->macinfo
.s
.section
= sectp
;
11655 sections
->macinfo
.size
= bfd_section_size (sectp
);
11657 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11659 /* There can be only one. */
11660 if (sections
->macro
.s
.section
!= NULL
)
11662 sections
->macro
.s
.section
= sectp
;
11663 sections
->macro
.size
= bfd_section_size (sectp
);
11665 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11667 /* There can be only one. */
11668 if (sections
->str_offsets
.s
.section
!= NULL
)
11670 sections
->str_offsets
.s
.section
= sectp
;
11671 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11675 /* No other kind of section is valid. */
11682 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11683 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11684 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11685 This is for DWP version 1 files. */
11687 static struct dwo_unit
*
11688 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11689 struct dwp_file
*dwp_file
,
11690 uint32_t unit_index
,
11691 const char *comp_dir
,
11692 ULONGEST signature
, int is_debug_types
)
11694 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11695 const struct dwp_hash_table
*dwp_htab
=
11696 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11697 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11698 const char *kind
= is_debug_types
? "TU" : "CU";
11699 struct dwo_file
*dwo_file
;
11700 struct dwo_unit
*dwo_unit
;
11701 struct virtual_v1_dwo_sections sections
;
11702 void **dwo_file_slot
;
11705 gdb_assert (dwp_file
->version
== 1);
11707 if (dwarf_read_debug
)
11709 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11711 pulongest (unit_index
), hex_string (signature
),
11715 /* Fetch the sections of this DWO unit.
11716 Put a limit on the number of sections we look for so that bad data
11717 doesn't cause us to loop forever. */
11719 #define MAX_NR_V1_DWO_SECTIONS \
11720 (1 /* .debug_info or .debug_types */ \
11721 + 1 /* .debug_abbrev */ \
11722 + 1 /* .debug_line */ \
11723 + 1 /* .debug_loc */ \
11724 + 1 /* .debug_str_offsets */ \
11725 + 1 /* .debug_macro or .debug_macinfo */ \
11726 + 1 /* trailing zero */)
11728 memset (§ions
, 0, sizeof (sections
));
11730 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11733 uint32_t section_nr
=
11734 read_4_bytes (dbfd
,
11735 dwp_htab
->section_pool
.v1
.indices
11736 + (unit_index
+ i
) * sizeof (uint32_t));
11738 if (section_nr
== 0)
11740 if (section_nr
>= dwp_file
->num_sections
)
11742 error (_("Dwarf Error: bad DWP hash table, section number too large"
11743 " [in module %s]"),
11747 sectp
= dwp_file
->elf_sections
[section_nr
];
11748 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11750 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11751 " [in module %s]"),
11757 || sections
.info_or_types
.empty ()
11758 || sections
.abbrev
.empty ())
11760 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11761 " [in module %s]"),
11764 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11766 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11767 " [in module %s]"),
11771 /* It's easier for the rest of the code if we fake a struct dwo_file and
11772 have dwo_unit "live" in that. At least for now.
11774 The DWP file can be made up of a random collection of CUs and TUs.
11775 However, for each CU + set of TUs that came from the same original DWO
11776 file, we can combine them back into a virtual DWO file to save space
11777 (fewer struct dwo_file objects to allocate). Remember that for really
11778 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11780 std::string virtual_dwo_name
=
11781 string_printf ("virtual-dwo/%d-%d-%d-%d",
11782 sections
.abbrev
.get_id (),
11783 sections
.line
.get_id (),
11784 sections
.loc
.get_id (),
11785 sections
.str_offsets
.get_id ());
11786 /* Can we use an existing virtual DWO file? */
11787 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11788 virtual_dwo_name
.c_str (),
11790 /* Create one if necessary. */
11791 if (*dwo_file_slot
== NULL
)
11793 if (dwarf_read_debug
)
11795 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11796 virtual_dwo_name
.c_str ());
11798 dwo_file
= new struct dwo_file
;
11799 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11800 dwo_file
->comp_dir
= comp_dir
;
11801 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11802 dwo_file
->sections
.line
= sections
.line
;
11803 dwo_file
->sections
.loc
= sections
.loc
;
11804 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11805 dwo_file
->sections
.macro
= sections
.macro
;
11806 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11807 /* The "str" section is global to the entire DWP file. */
11808 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11809 /* The info or types section is assigned below to dwo_unit,
11810 there's no need to record it in dwo_file.
11811 Also, we can't simply record type sections in dwo_file because
11812 we record a pointer into the vector in dwo_unit. As we collect more
11813 types we'll grow the vector and eventually have to reallocate space
11814 for it, invalidating all copies of pointers into the previous
11816 *dwo_file_slot
= dwo_file
;
11820 if (dwarf_read_debug
)
11822 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11823 virtual_dwo_name
.c_str ());
11825 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11828 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11829 dwo_unit
->dwo_file
= dwo_file
;
11830 dwo_unit
->signature
= signature
;
11831 dwo_unit
->section
=
11832 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11833 *dwo_unit
->section
= sections
.info_or_types
;
11834 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11839 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11840 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11841 piece within that section used by a TU/CU, return a virtual section
11842 of just that piece. */
11844 static struct dwarf2_section_info
11845 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11846 struct dwarf2_section_info
*section
,
11847 bfd_size_type offset
, bfd_size_type size
)
11849 struct dwarf2_section_info result
;
11852 gdb_assert (section
!= NULL
);
11853 gdb_assert (!section
->is_virtual
);
11855 memset (&result
, 0, sizeof (result
));
11856 result
.s
.containing_section
= section
;
11857 result
.is_virtual
= true;
11862 sectp
= section
->get_bfd_section ();
11864 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11865 bounds of the real section. This is a pretty-rare event, so just
11866 flag an error (easier) instead of a warning and trying to cope. */
11868 || offset
+ size
> bfd_section_size (sectp
))
11870 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11871 " in section %s [in module %s]"),
11872 sectp
? bfd_section_name (sectp
) : "<unknown>",
11873 objfile_name (dwarf2_per_objfile
->objfile
));
11876 result
.virtual_offset
= offset
;
11877 result
.size
= size
;
11881 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11882 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11883 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11884 This is for DWP version 2 files. */
11886 static struct dwo_unit
*
11887 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11888 struct dwp_file
*dwp_file
,
11889 uint32_t unit_index
,
11890 const char *comp_dir
,
11891 ULONGEST signature
, int is_debug_types
)
11893 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11894 const struct dwp_hash_table
*dwp_htab
=
11895 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11896 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11897 const char *kind
= is_debug_types
? "TU" : "CU";
11898 struct dwo_file
*dwo_file
;
11899 struct dwo_unit
*dwo_unit
;
11900 struct virtual_v2_dwo_sections sections
;
11901 void **dwo_file_slot
;
11904 gdb_assert (dwp_file
->version
== 2);
11906 if (dwarf_read_debug
)
11908 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11910 pulongest (unit_index
), hex_string (signature
),
11914 /* Fetch the section offsets of this DWO unit. */
11916 memset (§ions
, 0, sizeof (sections
));
11918 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11920 uint32_t offset
= read_4_bytes (dbfd
,
11921 dwp_htab
->section_pool
.v2
.offsets
11922 + (((unit_index
- 1) * dwp_htab
->nr_columns
11924 * sizeof (uint32_t)));
11925 uint32_t size
= read_4_bytes (dbfd
,
11926 dwp_htab
->section_pool
.v2
.sizes
11927 + (((unit_index
- 1) * dwp_htab
->nr_columns
11929 * sizeof (uint32_t)));
11931 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11934 case DW_SECT_TYPES
:
11935 sections
.info_or_types_offset
= offset
;
11936 sections
.info_or_types_size
= size
;
11938 case DW_SECT_ABBREV
:
11939 sections
.abbrev_offset
= offset
;
11940 sections
.abbrev_size
= size
;
11943 sections
.line_offset
= offset
;
11944 sections
.line_size
= size
;
11947 sections
.loc_offset
= offset
;
11948 sections
.loc_size
= size
;
11950 case DW_SECT_STR_OFFSETS
:
11951 sections
.str_offsets_offset
= offset
;
11952 sections
.str_offsets_size
= size
;
11954 case DW_SECT_MACINFO
:
11955 sections
.macinfo_offset
= offset
;
11956 sections
.macinfo_size
= size
;
11958 case DW_SECT_MACRO
:
11959 sections
.macro_offset
= offset
;
11960 sections
.macro_size
= size
;
11965 /* It's easier for the rest of the code if we fake a struct dwo_file and
11966 have dwo_unit "live" in that. At least for now.
11968 The DWP file can be made up of a random collection of CUs and TUs.
11969 However, for each CU + set of TUs that came from the same original DWO
11970 file, we can combine them back into a virtual DWO file to save space
11971 (fewer struct dwo_file objects to allocate). Remember that for really
11972 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11974 std::string virtual_dwo_name
=
11975 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11976 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11977 (long) (sections
.line_size
? sections
.line_offset
: 0),
11978 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11979 (long) (sections
.str_offsets_size
11980 ? sections
.str_offsets_offset
: 0));
11981 /* Can we use an existing virtual DWO file? */
11982 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11983 virtual_dwo_name
.c_str (),
11985 /* Create one if necessary. */
11986 if (*dwo_file_slot
== NULL
)
11988 if (dwarf_read_debug
)
11990 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11991 virtual_dwo_name
.c_str ());
11993 dwo_file
= new struct dwo_file
;
11994 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11995 dwo_file
->comp_dir
= comp_dir
;
11996 dwo_file
->sections
.abbrev
=
11997 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11998 sections
.abbrev_offset
, sections
.abbrev_size
);
11999 dwo_file
->sections
.line
=
12000 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12001 sections
.line_offset
, sections
.line_size
);
12002 dwo_file
->sections
.loc
=
12003 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12004 sections
.loc_offset
, sections
.loc_size
);
12005 dwo_file
->sections
.macinfo
=
12006 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12007 sections
.macinfo_offset
, sections
.macinfo_size
);
12008 dwo_file
->sections
.macro
=
12009 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12010 sections
.macro_offset
, sections
.macro_size
);
12011 dwo_file
->sections
.str_offsets
=
12012 create_dwp_v2_section (dwarf2_per_objfile
,
12013 &dwp_file
->sections
.str_offsets
,
12014 sections
.str_offsets_offset
,
12015 sections
.str_offsets_size
);
12016 /* The "str" section is global to the entire DWP file. */
12017 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12018 /* The info or types section is assigned below to dwo_unit,
12019 there's no need to record it in dwo_file.
12020 Also, we can't simply record type sections in dwo_file because
12021 we record a pointer into the vector in dwo_unit. As we collect more
12022 types we'll grow the vector and eventually have to reallocate space
12023 for it, invalidating all copies of pointers into the previous
12025 *dwo_file_slot
= dwo_file
;
12029 if (dwarf_read_debug
)
12031 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12032 virtual_dwo_name
.c_str ());
12034 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12037 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12038 dwo_unit
->dwo_file
= dwo_file
;
12039 dwo_unit
->signature
= signature
;
12040 dwo_unit
->section
=
12041 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12042 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12044 ? &dwp_file
->sections
.types
12045 : &dwp_file
->sections
.info
,
12046 sections
.info_or_types_offset
,
12047 sections
.info_or_types_size
);
12048 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12053 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12054 Returns NULL if the signature isn't found. */
12056 static struct dwo_unit
*
12057 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12058 struct dwp_file
*dwp_file
, const char *comp_dir
,
12059 ULONGEST signature
, int is_debug_types
)
12061 const struct dwp_hash_table
*dwp_htab
=
12062 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12063 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12064 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12065 uint32_t hash
= signature
& mask
;
12066 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12069 struct dwo_unit find_dwo_cu
;
12071 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12072 find_dwo_cu
.signature
= signature
;
12073 slot
= htab_find_slot (is_debug_types
12074 ? dwp_file
->loaded_tus
.get ()
12075 : dwp_file
->loaded_cus
.get (),
12076 &find_dwo_cu
, INSERT
);
12079 return (struct dwo_unit
*) *slot
;
12081 /* Use a for loop so that we don't loop forever on bad debug info. */
12082 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12084 ULONGEST signature_in_table
;
12086 signature_in_table
=
12087 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12088 if (signature_in_table
== signature
)
12090 uint32_t unit_index
=
12091 read_4_bytes (dbfd
,
12092 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12094 if (dwp_file
->version
== 1)
12096 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12097 dwp_file
, unit_index
,
12098 comp_dir
, signature
,
12103 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12104 dwp_file
, unit_index
,
12105 comp_dir
, signature
,
12108 return (struct dwo_unit
*) *slot
;
12110 if (signature_in_table
== 0)
12112 hash
= (hash
+ hash2
) & mask
;
12115 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12116 " [in module %s]"),
12120 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12121 Open the file specified by FILE_NAME and hand it off to BFD for
12122 preliminary analysis. Return a newly initialized bfd *, which
12123 includes a canonicalized copy of FILE_NAME.
12124 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12125 SEARCH_CWD is true if the current directory is to be searched.
12126 It will be searched before debug-file-directory.
12127 If successful, the file is added to the bfd include table of the
12128 objfile's bfd (see gdb_bfd_record_inclusion).
12129 If unable to find/open the file, return NULL.
12130 NOTE: This function is derived from symfile_bfd_open. */
12132 static gdb_bfd_ref_ptr
12133 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12134 const char *file_name
, int is_dwp
, int search_cwd
)
12137 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12138 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12139 to debug_file_directory. */
12140 const char *search_path
;
12141 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12143 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12146 if (*debug_file_directory
!= '\0')
12148 search_path_holder
.reset (concat (".", dirname_separator_string
,
12149 debug_file_directory
,
12151 search_path
= search_path_holder
.get ();
12157 search_path
= debug_file_directory
;
12159 openp_flags flags
= OPF_RETURN_REALPATH
;
12161 flags
|= OPF_SEARCH_IN_PATH
;
12163 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12164 desc
= openp (search_path
, flags
, file_name
,
12165 O_RDONLY
| O_BINARY
, &absolute_name
);
12169 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12171 if (sym_bfd
== NULL
)
12173 bfd_set_cacheable (sym_bfd
.get (), 1);
12175 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12178 /* Success. Record the bfd as having been included by the objfile's bfd.
12179 This is important because things like demangled_names_hash lives in the
12180 objfile's per_bfd space and may have references to things like symbol
12181 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12182 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12187 /* Try to open DWO file FILE_NAME.
12188 COMP_DIR is the DW_AT_comp_dir attribute.
12189 The result is the bfd handle of the file.
12190 If there is a problem finding or opening the file, return NULL.
12191 Upon success, the canonicalized path of the file is stored in the bfd,
12192 same as symfile_bfd_open. */
12194 static gdb_bfd_ref_ptr
12195 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12196 const char *file_name
, const char *comp_dir
)
12198 if (IS_ABSOLUTE_PATH (file_name
))
12199 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12200 0 /*is_dwp*/, 0 /*search_cwd*/);
12202 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12204 if (comp_dir
!= NULL
)
12206 gdb::unique_xmalloc_ptr
<char> path_to_try
12207 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12209 /* NOTE: If comp_dir is a relative path, this will also try the
12210 search path, which seems useful. */
12211 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12212 path_to_try
.get (),
12214 1 /*search_cwd*/));
12219 /* That didn't work, try debug-file-directory, which, despite its name,
12220 is a list of paths. */
12222 if (*debug_file_directory
== '\0')
12225 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12226 0 /*is_dwp*/, 1 /*search_cwd*/);
12229 /* This function is mapped across the sections and remembers the offset and
12230 size of each of the DWO debugging sections we are interested in. */
12233 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12235 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12236 const struct dwop_section_names
*names
= &dwop_section_names
;
12238 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12240 dwo_sections
->abbrev
.s
.section
= sectp
;
12241 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12243 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12245 dwo_sections
->info
.s
.section
= sectp
;
12246 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12248 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12250 dwo_sections
->line
.s
.section
= sectp
;
12251 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12253 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12255 dwo_sections
->loc
.s
.section
= sectp
;
12256 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12258 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12260 dwo_sections
->loclists
.s
.section
= sectp
;
12261 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12263 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12265 dwo_sections
->macinfo
.s
.section
= sectp
;
12266 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12268 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12270 dwo_sections
->macro
.s
.section
= sectp
;
12271 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12273 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12275 dwo_sections
->str
.s
.section
= sectp
;
12276 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12278 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12280 dwo_sections
->str_offsets
.s
.section
= sectp
;
12281 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12283 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12285 struct dwarf2_section_info type_section
;
12287 memset (&type_section
, 0, sizeof (type_section
));
12288 type_section
.s
.section
= sectp
;
12289 type_section
.size
= bfd_section_size (sectp
);
12290 dwo_sections
->types
.push_back (type_section
);
12294 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12295 by PER_CU. This is for the non-DWP case.
12296 The result is NULL if DWO_NAME can't be found. */
12298 static struct dwo_file
*
12299 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12300 const char *dwo_name
, const char *comp_dir
)
12302 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12304 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12307 if (dwarf_read_debug
)
12308 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12312 dwo_file_up
dwo_file (new struct dwo_file
);
12313 dwo_file
->dwo_name
= dwo_name
;
12314 dwo_file
->comp_dir
= comp_dir
;
12315 dwo_file
->dbfd
= std::move (dbfd
);
12317 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12318 &dwo_file
->sections
);
12320 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12321 dwo_file
->sections
.info
, dwo_file
->cus
);
12323 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12324 dwo_file
->sections
.types
, dwo_file
->tus
);
12326 if (dwarf_read_debug
)
12327 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12329 return dwo_file
.release ();
12332 /* This function is mapped across the sections and remembers the offset and
12333 size of each of the DWP debugging sections common to version 1 and 2 that
12334 we are interested in. */
12337 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12338 void *dwp_file_ptr
)
12340 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12341 const struct dwop_section_names
*names
= &dwop_section_names
;
12342 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12344 /* Record the ELF section number for later lookup: this is what the
12345 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12346 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12347 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12349 /* Look for specific sections that we need. */
12350 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12352 dwp_file
->sections
.str
.s
.section
= sectp
;
12353 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12355 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12357 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12358 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12360 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12362 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12363 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12367 /* This function is mapped across the sections and remembers the offset and
12368 size of each of the DWP version 2 debugging sections that we are interested
12369 in. This is split into a separate function because we don't know if we
12370 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12373 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12375 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12376 const struct dwop_section_names
*names
= &dwop_section_names
;
12377 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12379 /* Record the ELF section number for later lookup: this is what the
12380 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12381 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12382 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12384 /* Look for specific sections that we need. */
12385 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12387 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12388 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12390 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12392 dwp_file
->sections
.info
.s
.section
= sectp
;
12393 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12395 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12397 dwp_file
->sections
.line
.s
.section
= sectp
;
12398 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12400 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12402 dwp_file
->sections
.loc
.s
.section
= sectp
;
12403 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12405 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12407 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12408 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12410 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12412 dwp_file
->sections
.macro
.s
.section
= sectp
;
12413 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12415 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12417 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12418 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12420 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12422 dwp_file
->sections
.types
.s
.section
= sectp
;
12423 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12427 /* Hash function for dwp_file loaded CUs/TUs. */
12430 hash_dwp_loaded_cutus (const void *item
)
12432 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12434 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12435 return dwo_unit
->signature
;
12438 /* Equality function for dwp_file loaded CUs/TUs. */
12441 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12443 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12444 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12446 return dua
->signature
== dub
->signature
;
12449 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12452 allocate_dwp_loaded_cutus_table ()
12454 return htab_up (htab_create_alloc (3,
12455 hash_dwp_loaded_cutus
,
12456 eq_dwp_loaded_cutus
,
12457 NULL
, xcalloc
, xfree
));
12460 /* Try to open DWP file FILE_NAME.
12461 The result is the bfd handle of the file.
12462 If there is a problem finding or opening the file, return NULL.
12463 Upon success, the canonicalized path of the file is stored in the bfd,
12464 same as symfile_bfd_open. */
12466 static gdb_bfd_ref_ptr
12467 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12468 const char *file_name
)
12470 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12472 1 /*search_cwd*/));
12476 /* Work around upstream bug 15652.
12477 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12478 [Whether that's a "bug" is debatable, but it is getting in our way.]
12479 We have no real idea where the dwp file is, because gdb's realpath-ing
12480 of the executable's path may have discarded the needed info.
12481 [IWBN if the dwp file name was recorded in the executable, akin to
12482 .gnu_debuglink, but that doesn't exist yet.]
12483 Strip the directory from FILE_NAME and search again. */
12484 if (*debug_file_directory
!= '\0')
12486 /* Don't implicitly search the current directory here.
12487 If the user wants to search "." to handle this case,
12488 it must be added to debug-file-directory. */
12489 return try_open_dwop_file (dwarf2_per_objfile
,
12490 lbasename (file_name
), 1 /*is_dwp*/,
12497 /* Initialize the use of the DWP file for the current objfile.
12498 By convention the name of the DWP file is ${objfile}.dwp.
12499 The result is NULL if it can't be found. */
12501 static std::unique_ptr
<struct dwp_file
>
12502 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12504 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12506 /* Try to find first .dwp for the binary file before any symbolic links
12509 /* If the objfile is a debug file, find the name of the real binary
12510 file and get the name of dwp file from there. */
12511 std::string dwp_name
;
12512 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12514 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12515 const char *backlink_basename
= lbasename (backlink
->original_name
);
12517 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12520 dwp_name
= objfile
->original_name
;
12522 dwp_name
+= ".dwp";
12524 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12526 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12528 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12529 dwp_name
= objfile_name (objfile
);
12530 dwp_name
+= ".dwp";
12531 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12536 if (dwarf_read_debug
)
12537 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12538 return std::unique_ptr
<dwp_file
> ();
12541 const char *name
= bfd_get_filename (dbfd
.get ());
12542 std::unique_ptr
<struct dwp_file
> dwp_file
12543 (new struct dwp_file (name
, std::move (dbfd
)));
12545 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12546 dwp_file
->elf_sections
=
12547 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12548 dwp_file
->num_sections
, asection
*);
12550 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12551 dwarf2_locate_common_dwp_sections
,
12554 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12557 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12560 /* The DWP file version is stored in the hash table. Oh well. */
12561 if (dwp_file
->cus
&& dwp_file
->tus
12562 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12564 /* Technically speaking, we should try to limp along, but this is
12565 pretty bizarre. We use pulongest here because that's the established
12566 portability solution (e.g, we cannot use %u for uint32_t). */
12567 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12568 " TU version %s [in DWP file %s]"),
12569 pulongest (dwp_file
->cus
->version
),
12570 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12574 dwp_file
->version
= dwp_file
->cus
->version
;
12575 else if (dwp_file
->tus
)
12576 dwp_file
->version
= dwp_file
->tus
->version
;
12578 dwp_file
->version
= 2;
12580 if (dwp_file
->version
== 2)
12581 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12582 dwarf2_locate_v2_dwp_sections
,
12585 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12586 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12588 if (dwarf_read_debug
)
12590 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12591 fprintf_unfiltered (gdb_stdlog
,
12592 " %s CUs, %s TUs\n",
12593 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12594 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12600 /* Wrapper around open_and_init_dwp_file, only open it once. */
12602 static struct dwp_file
*
12603 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12605 if (! dwarf2_per_objfile
->dwp_checked
)
12607 dwarf2_per_objfile
->dwp_file
12608 = open_and_init_dwp_file (dwarf2_per_objfile
);
12609 dwarf2_per_objfile
->dwp_checked
= 1;
12611 return dwarf2_per_objfile
->dwp_file
.get ();
12614 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12615 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12616 or in the DWP file for the objfile, referenced by THIS_UNIT.
12617 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12618 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12620 This is called, for example, when wanting to read a variable with a
12621 complex location. Therefore we don't want to do file i/o for every call.
12622 Therefore we don't want to look for a DWO file on every call.
12623 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12624 then we check if we've already seen DWO_NAME, and only THEN do we check
12627 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12628 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12630 static struct dwo_unit
*
12631 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12632 const char *dwo_name
, const char *comp_dir
,
12633 ULONGEST signature
, int is_debug_types
)
12635 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12636 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12637 const char *kind
= is_debug_types
? "TU" : "CU";
12638 void **dwo_file_slot
;
12639 struct dwo_file
*dwo_file
;
12640 struct dwp_file
*dwp_file
;
12642 /* First see if there's a DWP file.
12643 If we have a DWP file but didn't find the DWO inside it, don't
12644 look for the original DWO file. It makes gdb behave differently
12645 depending on whether one is debugging in the build tree. */
12647 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12648 if (dwp_file
!= NULL
)
12650 const struct dwp_hash_table
*dwp_htab
=
12651 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12653 if (dwp_htab
!= NULL
)
12655 struct dwo_unit
*dwo_cutu
=
12656 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12657 signature
, is_debug_types
);
12659 if (dwo_cutu
!= NULL
)
12661 if (dwarf_read_debug
)
12663 fprintf_unfiltered (gdb_stdlog
,
12664 "Virtual DWO %s %s found: @%s\n",
12665 kind
, hex_string (signature
),
12666 host_address_to_string (dwo_cutu
));
12674 /* No DWP file, look for the DWO file. */
12676 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12677 dwo_name
, comp_dir
);
12678 if (*dwo_file_slot
== NULL
)
12680 /* Read in the file and build a table of the CUs/TUs it contains. */
12681 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12683 /* NOTE: This will be NULL if unable to open the file. */
12684 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12686 if (dwo_file
!= NULL
)
12688 struct dwo_unit
*dwo_cutu
= NULL
;
12690 if (is_debug_types
&& dwo_file
->tus
)
12692 struct dwo_unit find_dwo_cutu
;
12694 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12695 find_dwo_cutu
.signature
= signature
;
12697 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12700 else if (!is_debug_types
&& dwo_file
->cus
)
12702 struct dwo_unit find_dwo_cutu
;
12704 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12705 find_dwo_cutu
.signature
= signature
;
12706 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12710 if (dwo_cutu
!= NULL
)
12712 if (dwarf_read_debug
)
12714 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12715 kind
, dwo_name
, hex_string (signature
),
12716 host_address_to_string (dwo_cutu
));
12723 /* We didn't find it. This could mean a dwo_id mismatch, or
12724 someone deleted the DWO/DWP file, or the search path isn't set up
12725 correctly to find the file. */
12727 if (dwarf_read_debug
)
12729 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12730 kind
, dwo_name
, hex_string (signature
));
12733 /* This is a warning and not a complaint because it can be caused by
12734 pilot error (e.g., user accidentally deleting the DWO). */
12736 /* Print the name of the DWP file if we looked there, helps the user
12737 better diagnose the problem. */
12738 std::string dwp_text
;
12740 if (dwp_file
!= NULL
)
12741 dwp_text
= string_printf (" [in DWP file %s]",
12742 lbasename (dwp_file
->name
));
12744 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12745 " [in module %s]"),
12746 kind
, dwo_name
, hex_string (signature
),
12748 this_unit
->is_debug_types
? "TU" : "CU",
12749 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12754 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12755 See lookup_dwo_cutu_unit for details. */
12757 static struct dwo_unit
*
12758 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12759 const char *dwo_name
, const char *comp_dir
,
12760 ULONGEST signature
)
12762 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12765 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12766 See lookup_dwo_cutu_unit for details. */
12768 static struct dwo_unit
*
12769 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12770 const char *dwo_name
, const char *comp_dir
)
12772 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12775 /* Traversal function for queue_and_load_all_dwo_tus. */
12778 queue_and_load_dwo_tu (void **slot
, void *info
)
12780 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12781 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12782 ULONGEST signature
= dwo_unit
->signature
;
12783 struct signatured_type
*sig_type
=
12784 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12786 if (sig_type
!= NULL
)
12788 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12790 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12791 a real dependency of PER_CU on SIG_TYPE. That is detected later
12792 while processing PER_CU. */
12793 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12794 load_full_type_unit (sig_cu
);
12795 per_cu
->imported_symtabs_push (sig_cu
);
12801 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12802 The DWO may have the only definition of the type, though it may not be
12803 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12804 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12807 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12809 struct dwo_unit
*dwo_unit
;
12810 struct dwo_file
*dwo_file
;
12812 gdb_assert (!per_cu
->is_debug_types
);
12813 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12814 gdb_assert (per_cu
->cu
!= NULL
);
12816 dwo_unit
= per_cu
->cu
->dwo_unit
;
12817 gdb_assert (dwo_unit
!= NULL
);
12819 dwo_file
= dwo_unit
->dwo_file
;
12820 if (dwo_file
->tus
!= NULL
)
12821 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12825 /* Read in various DIEs. */
12827 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12828 Inherit only the children of the DW_AT_abstract_origin DIE not being
12829 already referenced by DW_AT_abstract_origin from the children of the
12833 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12835 struct die_info
*child_die
;
12836 sect_offset
*offsetp
;
12837 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12838 struct die_info
*origin_die
;
12839 /* Iterator of the ORIGIN_DIE children. */
12840 struct die_info
*origin_child_die
;
12841 struct attribute
*attr
;
12842 struct dwarf2_cu
*origin_cu
;
12843 struct pending
**origin_previous_list_in_scope
;
12845 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12849 /* Note that following die references may follow to a die in a
12853 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12855 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12857 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12858 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12860 if (die
->tag
!= origin_die
->tag
12861 && !(die
->tag
== DW_TAG_inlined_subroutine
12862 && origin_die
->tag
== DW_TAG_subprogram
))
12863 complaint (_("DIE %s and its abstract origin %s have different tags"),
12864 sect_offset_str (die
->sect_off
),
12865 sect_offset_str (origin_die
->sect_off
));
12867 std::vector
<sect_offset
> offsets
;
12869 for (child_die
= die
->child
;
12870 child_die
&& child_die
->tag
;
12871 child_die
= child_die
->sibling
)
12873 struct die_info
*child_origin_die
;
12874 struct dwarf2_cu
*child_origin_cu
;
12876 /* We are trying to process concrete instance entries:
12877 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12878 it's not relevant to our analysis here. i.e. detecting DIEs that are
12879 present in the abstract instance but not referenced in the concrete
12881 if (child_die
->tag
== DW_TAG_call_site
12882 || child_die
->tag
== DW_TAG_GNU_call_site
)
12885 /* For each CHILD_DIE, find the corresponding child of
12886 ORIGIN_DIE. If there is more than one layer of
12887 DW_AT_abstract_origin, follow them all; there shouldn't be,
12888 but GCC versions at least through 4.4 generate this (GCC PR
12890 child_origin_die
= child_die
;
12891 child_origin_cu
= cu
;
12894 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12898 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12902 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12903 counterpart may exist. */
12904 if (child_origin_die
!= child_die
)
12906 if (child_die
->tag
!= child_origin_die
->tag
12907 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12908 && child_origin_die
->tag
== DW_TAG_subprogram
))
12909 complaint (_("Child DIE %s and its abstract origin %s have "
12911 sect_offset_str (child_die
->sect_off
),
12912 sect_offset_str (child_origin_die
->sect_off
));
12913 if (child_origin_die
->parent
!= origin_die
)
12914 complaint (_("Child DIE %s and its abstract origin %s have "
12915 "different parents"),
12916 sect_offset_str (child_die
->sect_off
),
12917 sect_offset_str (child_origin_die
->sect_off
));
12919 offsets
.push_back (child_origin_die
->sect_off
);
12922 std::sort (offsets
.begin (), offsets
.end ());
12923 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12924 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12925 if (offsetp
[-1] == *offsetp
)
12926 complaint (_("Multiple children of DIE %s refer "
12927 "to DIE %s as their abstract origin"),
12928 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12930 offsetp
= offsets
.data ();
12931 origin_child_die
= origin_die
->child
;
12932 while (origin_child_die
&& origin_child_die
->tag
)
12934 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12935 while (offsetp
< offsets_end
12936 && *offsetp
< origin_child_die
->sect_off
)
12938 if (offsetp
>= offsets_end
12939 || *offsetp
> origin_child_die
->sect_off
)
12941 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12942 Check whether we're already processing ORIGIN_CHILD_DIE.
12943 This can happen with mutually referenced abstract_origins.
12945 if (!origin_child_die
->in_process
)
12946 process_die (origin_child_die
, origin_cu
);
12948 origin_child_die
= origin_child_die
->sibling
;
12950 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12952 if (cu
!= origin_cu
)
12953 compute_delayed_physnames (origin_cu
);
12957 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12959 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12960 struct gdbarch
*gdbarch
= objfile
->arch ();
12961 struct context_stack
*newobj
;
12964 struct die_info
*child_die
;
12965 struct attribute
*attr
, *call_line
, *call_file
;
12967 CORE_ADDR baseaddr
;
12968 struct block
*block
;
12969 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12970 std::vector
<struct symbol
*> template_args
;
12971 struct template_symbol
*templ_func
= NULL
;
12975 /* If we do not have call site information, we can't show the
12976 caller of this inlined function. That's too confusing, so
12977 only use the scope for local variables. */
12978 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12979 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12980 if (call_line
== NULL
|| call_file
== NULL
)
12982 read_lexical_block_scope (die
, cu
);
12987 baseaddr
= objfile
->text_section_offset ();
12989 name
= dwarf2_name (die
, cu
);
12991 /* Ignore functions with missing or empty names. These are actually
12992 illegal according to the DWARF standard. */
12995 complaint (_("missing name for subprogram DIE at %s"),
12996 sect_offset_str (die
->sect_off
));
13000 /* Ignore functions with missing or invalid low and high pc attributes. */
13001 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13002 <= PC_BOUNDS_INVALID
)
13004 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13005 if (!attr
|| !DW_UNSND (attr
))
13006 complaint (_("cannot get low and high bounds "
13007 "for subprogram DIE at %s"),
13008 sect_offset_str (die
->sect_off
));
13012 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13013 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13015 /* If we have any template arguments, then we must allocate a
13016 different sort of symbol. */
13017 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13019 if (child_die
->tag
== DW_TAG_template_type_param
13020 || child_die
->tag
== DW_TAG_template_value_param
)
13022 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13023 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13028 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13029 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13030 (struct symbol
*) templ_func
);
13032 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13033 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13036 /* If there is a location expression for DW_AT_frame_base, record
13038 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13039 if (attr
!= nullptr)
13040 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13042 /* If there is a location for the static link, record it. */
13043 newobj
->static_link
= NULL
;
13044 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13045 if (attr
!= nullptr)
13047 newobj
->static_link
13048 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13049 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13050 cu
->per_cu
->addr_type ());
13053 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13055 if (die
->child
!= NULL
)
13057 child_die
= die
->child
;
13058 while (child_die
&& child_die
->tag
)
13060 if (child_die
->tag
== DW_TAG_template_type_param
13061 || child_die
->tag
== DW_TAG_template_value_param
)
13063 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13066 template_args
.push_back (arg
);
13069 process_die (child_die
, cu
);
13070 child_die
= child_die
->sibling
;
13074 inherit_abstract_dies (die
, cu
);
13076 /* If we have a DW_AT_specification, we might need to import using
13077 directives from the context of the specification DIE. See the
13078 comment in determine_prefix. */
13079 if (cu
->language
== language_cplus
13080 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13082 struct dwarf2_cu
*spec_cu
= cu
;
13083 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13087 child_die
= spec_die
->child
;
13088 while (child_die
&& child_die
->tag
)
13090 if (child_die
->tag
== DW_TAG_imported_module
)
13091 process_die (child_die
, spec_cu
);
13092 child_die
= child_die
->sibling
;
13095 /* In some cases, GCC generates specification DIEs that
13096 themselves contain DW_AT_specification attributes. */
13097 spec_die
= die_specification (spec_die
, &spec_cu
);
13101 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13102 /* Make a block for the local symbols within. */
13103 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13104 cstk
.static_link
, lowpc
, highpc
);
13106 /* For C++, set the block's scope. */
13107 if ((cu
->language
== language_cplus
13108 || cu
->language
== language_fortran
13109 || cu
->language
== language_d
13110 || cu
->language
== language_rust
)
13111 && cu
->processing_has_namespace_info
)
13112 block_set_scope (block
, determine_prefix (die
, cu
),
13113 &objfile
->objfile_obstack
);
13115 /* If we have address ranges, record them. */
13116 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13118 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13120 /* Attach template arguments to function. */
13121 if (!template_args
.empty ())
13123 gdb_assert (templ_func
!= NULL
);
13125 templ_func
->n_template_arguments
= template_args
.size ();
13126 templ_func
->template_arguments
13127 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13128 templ_func
->n_template_arguments
);
13129 memcpy (templ_func
->template_arguments
,
13130 template_args
.data (),
13131 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13133 /* Make sure that the symtab is set on the new symbols. Even
13134 though they don't appear in this symtab directly, other parts
13135 of gdb assume that symbols do, and this is reasonably
13137 for (symbol
*sym
: template_args
)
13138 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13141 /* In C++, we can have functions nested inside functions (e.g., when
13142 a function declares a class that has methods). This means that
13143 when we finish processing a function scope, we may need to go
13144 back to building a containing block's symbol lists. */
13145 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13146 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13148 /* If we've finished processing a top-level function, subsequent
13149 symbols go in the file symbol list. */
13150 if (cu
->get_builder ()->outermost_context_p ())
13151 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13154 /* Process all the DIES contained within a lexical block scope. Start
13155 a new scope, process the dies, and then close the scope. */
13158 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13160 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13161 struct gdbarch
*gdbarch
= objfile
->arch ();
13162 CORE_ADDR lowpc
, highpc
;
13163 struct die_info
*child_die
;
13164 CORE_ADDR baseaddr
;
13166 baseaddr
= objfile
->text_section_offset ();
13168 /* Ignore blocks with missing or invalid low and high pc attributes. */
13169 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13170 as multiple lexical blocks? Handling children in a sane way would
13171 be nasty. Might be easier to properly extend generic blocks to
13172 describe ranges. */
13173 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13175 case PC_BOUNDS_NOT_PRESENT
:
13176 /* DW_TAG_lexical_block has no attributes, process its children as if
13177 there was no wrapping by that DW_TAG_lexical_block.
13178 GCC does no longer produces such DWARF since GCC r224161. */
13179 for (child_die
= die
->child
;
13180 child_die
!= NULL
&& child_die
->tag
;
13181 child_die
= child_die
->sibling
)
13183 /* We might already be processing this DIE. This can happen
13184 in an unusual circumstance -- where a subroutine A
13185 appears lexically in another subroutine B, but A actually
13186 inlines B. The recursion is broken here, rather than in
13187 inherit_abstract_dies, because it seems better to simply
13188 drop concrete children here. */
13189 if (!child_die
->in_process
)
13190 process_die (child_die
, cu
);
13193 case PC_BOUNDS_INVALID
:
13196 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13197 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13199 cu
->get_builder ()->push_context (0, lowpc
);
13200 if (die
->child
!= NULL
)
13202 child_die
= die
->child
;
13203 while (child_die
&& child_die
->tag
)
13205 process_die (child_die
, cu
);
13206 child_die
= child_die
->sibling
;
13209 inherit_abstract_dies (die
, cu
);
13210 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13212 if (*cu
->get_builder ()->get_local_symbols () != NULL
13213 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13215 struct block
*block
13216 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13217 cstk
.start_addr
, highpc
);
13219 /* Note that recording ranges after traversing children, as we
13220 do here, means that recording a parent's ranges entails
13221 walking across all its children's ranges as they appear in
13222 the address map, which is quadratic behavior.
13224 It would be nicer to record the parent's ranges before
13225 traversing its children, simply overriding whatever you find
13226 there. But since we don't even decide whether to create a
13227 block until after we've traversed its children, that's hard
13229 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13231 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13232 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13235 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13238 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13240 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13241 struct gdbarch
*gdbarch
= objfile
->arch ();
13242 CORE_ADDR pc
, baseaddr
;
13243 struct attribute
*attr
;
13244 struct call_site
*call_site
, call_site_local
;
13247 struct die_info
*child_die
;
13249 baseaddr
= objfile
->text_section_offset ();
13251 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13254 /* This was a pre-DWARF-5 GNU extension alias
13255 for DW_AT_call_return_pc. */
13256 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13260 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13261 "DIE %s [in module %s]"),
13262 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13265 pc
= attr
->value_as_address () + baseaddr
;
13266 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13268 if (cu
->call_site_htab
== NULL
)
13269 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13270 NULL
, &objfile
->objfile_obstack
,
13271 hashtab_obstack_allocate
, NULL
);
13272 call_site_local
.pc
= pc
;
13273 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13276 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13277 "DIE %s [in module %s]"),
13278 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13279 objfile_name (objfile
));
13283 /* Count parameters at the caller. */
13286 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13287 child_die
= child_die
->sibling
)
13289 if (child_die
->tag
!= DW_TAG_call_site_parameter
13290 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13292 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13293 "DW_TAG_call_site child DIE %s [in module %s]"),
13294 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13295 objfile_name (objfile
));
13303 = ((struct call_site
*)
13304 obstack_alloc (&objfile
->objfile_obstack
,
13305 sizeof (*call_site
)
13306 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13308 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13309 call_site
->pc
= pc
;
13311 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13312 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13314 struct die_info
*func_die
;
13316 /* Skip also over DW_TAG_inlined_subroutine. */
13317 for (func_die
= die
->parent
;
13318 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13319 && func_die
->tag
!= DW_TAG_subroutine_type
;
13320 func_die
= func_die
->parent
);
13322 /* DW_AT_call_all_calls is a superset
13323 of DW_AT_call_all_tail_calls. */
13325 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13326 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13327 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13328 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13330 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13331 not complete. But keep CALL_SITE for look ups via call_site_htab,
13332 both the initial caller containing the real return address PC and
13333 the final callee containing the current PC of a chain of tail
13334 calls do not need to have the tail call list complete. But any
13335 function candidate for a virtual tail call frame searched via
13336 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13337 determined unambiguously. */
13341 struct type
*func_type
= NULL
;
13344 func_type
= get_die_type (func_die
, cu
);
13345 if (func_type
!= NULL
)
13347 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13349 /* Enlist this call site to the function. */
13350 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13351 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13354 complaint (_("Cannot find function owning DW_TAG_call_site "
13355 "DIE %s [in module %s]"),
13356 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13360 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13362 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13364 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13367 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13368 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13370 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13371 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13372 /* Keep NULL DWARF_BLOCK. */;
13373 else if (attr
->form_is_block ())
13375 struct dwarf2_locexpr_baton
*dlbaton
;
13377 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13378 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13379 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13380 dlbaton
->per_cu
= cu
->per_cu
;
13382 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13384 else if (attr
->form_is_ref ())
13386 struct dwarf2_cu
*target_cu
= cu
;
13387 struct die_info
*target_die
;
13389 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13390 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13391 if (die_is_declaration (target_die
, target_cu
))
13393 const char *target_physname
;
13395 /* Prefer the mangled name; otherwise compute the demangled one. */
13396 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13397 if (target_physname
== NULL
)
13398 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13399 if (target_physname
== NULL
)
13400 complaint (_("DW_AT_call_target target DIE has invalid "
13401 "physname, for referencing DIE %s [in module %s]"),
13402 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13404 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13410 /* DW_AT_entry_pc should be preferred. */
13411 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13412 <= PC_BOUNDS_INVALID
)
13413 complaint (_("DW_AT_call_target target DIE has invalid "
13414 "low pc, for referencing DIE %s [in module %s]"),
13415 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13418 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13419 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13424 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13425 "block nor reference, for DIE %s [in module %s]"),
13426 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13428 call_site
->per_cu
= cu
->per_cu
;
13430 for (child_die
= die
->child
;
13431 child_die
&& child_die
->tag
;
13432 child_die
= child_die
->sibling
)
13434 struct call_site_parameter
*parameter
;
13435 struct attribute
*loc
, *origin
;
13437 if (child_die
->tag
!= DW_TAG_call_site_parameter
13438 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13440 /* Already printed the complaint above. */
13444 gdb_assert (call_site
->parameter_count
< nparams
);
13445 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13447 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13448 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13449 register is contained in DW_AT_call_value. */
13451 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13452 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13453 if (origin
== NULL
)
13455 /* This was a pre-DWARF-5 GNU extension alias
13456 for DW_AT_call_parameter. */
13457 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13459 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13461 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13463 sect_offset sect_off
= origin
->get_ref_die_offset ();
13464 if (!cu
->header
.offset_in_cu_p (sect_off
))
13466 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13467 binding can be done only inside one CU. Such referenced DIE
13468 therefore cannot be even moved to DW_TAG_partial_unit. */
13469 complaint (_("DW_AT_call_parameter offset is not in CU for "
13470 "DW_TAG_call_site child DIE %s [in module %s]"),
13471 sect_offset_str (child_die
->sect_off
),
13472 objfile_name (objfile
));
13475 parameter
->u
.param_cu_off
13476 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13478 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13480 complaint (_("No DW_FORM_block* DW_AT_location for "
13481 "DW_TAG_call_site child DIE %s [in module %s]"),
13482 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13487 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13488 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13489 if (parameter
->u
.dwarf_reg
!= -1)
13490 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13491 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13492 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13493 ¶meter
->u
.fb_offset
))
13494 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13497 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13498 "for DW_FORM_block* DW_AT_location is supported for "
13499 "DW_TAG_call_site child DIE %s "
13501 sect_offset_str (child_die
->sect_off
),
13502 objfile_name (objfile
));
13507 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13509 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13510 if (attr
== NULL
|| !attr
->form_is_block ())
13512 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13513 "DW_TAG_call_site child DIE %s [in module %s]"),
13514 sect_offset_str (child_die
->sect_off
),
13515 objfile_name (objfile
));
13518 parameter
->value
= DW_BLOCK (attr
)->data
;
13519 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13521 /* Parameters are not pre-cleared by memset above. */
13522 parameter
->data_value
= NULL
;
13523 parameter
->data_value_size
= 0;
13524 call_site
->parameter_count
++;
13526 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13528 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13529 if (attr
!= nullptr)
13531 if (!attr
->form_is_block ())
13532 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13533 "DW_TAG_call_site child DIE %s [in module %s]"),
13534 sect_offset_str (child_die
->sect_off
),
13535 objfile_name (objfile
));
13538 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13539 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13545 /* Helper function for read_variable. If DIE represents a virtual
13546 table, then return the type of the concrete object that is
13547 associated with the virtual table. Otherwise, return NULL. */
13549 static struct type
*
13550 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13552 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13556 /* Find the type DIE. */
13557 struct die_info
*type_die
= NULL
;
13558 struct dwarf2_cu
*type_cu
= cu
;
13560 if (attr
->form_is_ref ())
13561 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13562 if (type_die
== NULL
)
13565 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13567 return die_containing_type (type_die
, type_cu
);
13570 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13573 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13575 struct rust_vtable_symbol
*storage
= NULL
;
13577 if (cu
->language
== language_rust
)
13579 struct type
*containing_type
= rust_containing_type (die
, cu
);
13581 if (containing_type
!= NULL
)
13583 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13585 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13586 storage
->concrete_type
= containing_type
;
13587 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13591 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13592 struct attribute
*abstract_origin
13593 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13594 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13595 if (res
== NULL
&& loc
&& abstract_origin
)
13597 /* We have a variable without a name, but with a location and an abstract
13598 origin. This may be a concrete instance of an abstract variable
13599 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13601 struct dwarf2_cu
*origin_cu
= cu
;
13602 struct die_info
*origin_die
13603 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13604 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13605 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13609 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13610 reading .debug_rnglists.
13611 Callback's type should be:
13612 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13613 Return true if the attributes are present and valid, otherwise,
13616 template <typename Callback
>
13618 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13619 Callback
&&callback
)
13621 struct dwarf2_per_objfile
*dwarf2_per_objfile
13622 = cu
->per_cu
->dwarf2_per_objfile
;
13623 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13624 bfd
*obfd
= objfile
->obfd
;
13625 /* Base address selection entry. */
13626 gdb::optional
<CORE_ADDR
> base
;
13627 const gdb_byte
*buffer
;
13628 CORE_ADDR baseaddr
;
13629 bool overflow
= false;
13631 base
= cu
->base_address
;
13633 dwarf2_per_objfile
->rnglists
.read (objfile
);
13634 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13636 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13640 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13642 baseaddr
= objfile
->text_section_offset ();
13646 /* Initialize it due to a false compiler warning. */
13647 CORE_ADDR range_beginning
= 0, range_end
= 0;
13648 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13649 + dwarf2_per_objfile
->rnglists
.size
);
13650 unsigned int bytes_read
;
13652 if (buffer
== buf_end
)
13657 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13660 case DW_RLE_end_of_list
:
13662 case DW_RLE_base_address
:
13663 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13668 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13669 buffer
+= bytes_read
;
13671 case DW_RLE_start_length
:
13672 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13677 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13679 buffer
+= bytes_read
;
13680 range_end
= (range_beginning
13681 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13682 buffer
+= bytes_read
;
13683 if (buffer
> buf_end
)
13689 case DW_RLE_offset_pair
:
13690 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13691 buffer
+= bytes_read
;
13692 if (buffer
> buf_end
)
13697 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13698 buffer
+= bytes_read
;
13699 if (buffer
> buf_end
)
13705 case DW_RLE_start_end
:
13706 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13711 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13713 buffer
+= bytes_read
;
13714 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13715 buffer
+= bytes_read
;
13718 complaint (_("Invalid .debug_rnglists data (no base address)"));
13721 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13723 if (rlet
== DW_RLE_base_address
)
13726 if (!base
.has_value ())
13728 /* We have no valid base address for the ranges
13730 complaint (_("Invalid .debug_rnglists data (no base address)"));
13734 if (range_beginning
> range_end
)
13736 /* Inverted range entries are invalid. */
13737 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13741 /* Empty range entries have no effect. */
13742 if (range_beginning
== range_end
)
13745 range_beginning
+= *base
;
13746 range_end
+= *base
;
13748 /* A not-uncommon case of bad debug info.
13749 Don't pollute the addrmap with bad data. */
13750 if (range_beginning
+ baseaddr
== 0
13751 && !dwarf2_per_objfile
->has_section_at_zero
)
13753 complaint (_(".debug_rnglists entry has start address of zero"
13754 " [in module %s]"), objfile_name (objfile
));
13758 callback (range_beginning
, range_end
);
13763 complaint (_("Offset %d is not terminated "
13764 "for DW_AT_ranges attribute"),
13772 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13773 Callback's type should be:
13774 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13775 Return 1 if the attributes are present and valid, otherwise, return 0. */
13777 template <typename Callback
>
13779 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13780 Callback
&&callback
)
13782 struct dwarf2_per_objfile
*dwarf2_per_objfile
13783 = cu
->per_cu
->dwarf2_per_objfile
;
13784 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13785 struct comp_unit_head
*cu_header
= &cu
->header
;
13786 bfd
*obfd
= objfile
->obfd
;
13787 unsigned int addr_size
= cu_header
->addr_size
;
13788 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13789 /* Base address selection entry. */
13790 gdb::optional
<CORE_ADDR
> base
;
13791 unsigned int dummy
;
13792 const gdb_byte
*buffer
;
13793 CORE_ADDR baseaddr
;
13795 if (cu_header
->version
>= 5)
13796 return dwarf2_rnglists_process (offset
, cu
, callback
);
13798 base
= cu
->base_address
;
13800 dwarf2_per_objfile
->ranges
.read (objfile
);
13801 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13803 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13807 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13809 baseaddr
= objfile
->text_section_offset ();
13813 CORE_ADDR range_beginning
, range_end
;
13815 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13816 buffer
+= addr_size
;
13817 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13818 buffer
+= addr_size
;
13819 offset
+= 2 * addr_size
;
13821 /* An end of list marker is a pair of zero addresses. */
13822 if (range_beginning
== 0 && range_end
== 0)
13823 /* Found the end of list entry. */
13826 /* Each base address selection entry is a pair of 2 values.
13827 The first is the largest possible address, the second is
13828 the base address. Check for a base address here. */
13829 if ((range_beginning
& mask
) == mask
)
13831 /* If we found the largest possible address, then we already
13832 have the base address in range_end. */
13837 if (!base
.has_value ())
13839 /* We have no valid base address for the ranges
13841 complaint (_("Invalid .debug_ranges data (no base address)"));
13845 if (range_beginning
> range_end
)
13847 /* Inverted range entries are invalid. */
13848 complaint (_("Invalid .debug_ranges data (inverted range)"));
13852 /* Empty range entries have no effect. */
13853 if (range_beginning
== range_end
)
13856 range_beginning
+= *base
;
13857 range_end
+= *base
;
13859 /* A not-uncommon case of bad debug info.
13860 Don't pollute the addrmap with bad data. */
13861 if (range_beginning
+ baseaddr
== 0
13862 && !dwarf2_per_objfile
->has_section_at_zero
)
13864 complaint (_(".debug_ranges entry has start address of zero"
13865 " [in module %s]"), objfile_name (objfile
));
13869 callback (range_beginning
, range_end
);
13875 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13876 Return 1 if the attributes are present and valid, otherwise, return 0.
13877 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13880 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13881 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13882 dwarf2_psymtab
*ranges_pst
)
13884 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13885 struct gdbarch
*gdbarch
= objfile
->arch ();
13886 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13889 CORE_ADDR high
= 0;
13892 retval
= dwarf2_ranges_process (offset
, cu
,
13893 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13895 if (ranges_pst
!= NULL
)
13900 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13901 range_beginning
+ baseaddr
)
13903 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13904 range_end
+ baseaddr
)
13906 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13907 lowpc
, highpc
- 1, ranges_pst
);
13910 /* FIXME: This is recording everything as a low-high
13911 segment of consecutive addresses. We should have a
13912 data structure for discontiguous block ranges
13916 low
= range_beginning
;
13922 if (range_beginning
< low
)
13923 low
= range_beginning
;
13924 if (range_end
> high
)
13932 /* If the first entry is an end-of-list marker, the range
13933 describes an empty scope, i.e. no instructions. */
13939 *high_return
= high
;
13943 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13944 definition for the return value. *LOWPC and *HIGHPC are set iff
13945 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13947 static enum pc_bounds_kind
13948 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13949 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13950 dwarf2_psymtab
*pst
)
13952 struct dwarf2_per_objfile
*dwarf2_per_objfile
13953 = cu
->per_cu
->dwarf2_per_objfile
;
13954 struct attribute
*attr
;
13955 struct attribute
*attr_high
;
13957 CORE_ADDR high
= 0;
13958 enum pc_bounds_kind ret
;
13960 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13963 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13964 if (attr
!= nullptr)
13966 low
= attr
->value_as_address ();
13967 high
= attr_high
->value_as_address ();
13968 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13972 /* Found high w/o low attribute. */
13973 return PC_BOUNDS_INVALID
;
13975 /* Found consecutive range of addresses. */
13976 ret
= PC_BOUNDS_HIGH_LOW
;
13980 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13983 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13984 We take advantage of the fact that DW_AT_ranges does not appear
13985 in DW_TAG_compile_unit of DWO files. */
13986 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13987 unsigned int ranges_offset
= (DW_UNSND (attr
)
13988 + (need_ranges_base
13992 /* Value of the DW_AT_ranges attribute is the offset in the
13993 .debug_ranges section. */
13994 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13995 return PC_BOUNDS_INVALID
;
13996 /* Found discontinuous range of addresses. */
13997 ret
= PC_BOUNDS_RANGES
;
14000 return PC_BOUNDS_NOT_PRESENT
;
14003 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14005 return PC_BOUNDS_INVALID
;
14007 /* When using the GNU linker, .gnu.linkonce. sections are used to
14008 eliminate duplicate copies of functions and vtables and such.
14009 The linker will arbitrarily choose one and discard the others.
14010 The AT_*_pc values for such functions refer to local labels in
14011 these sections. If the section from that file was discarded, the
14012 labels are not in the output, so the relocs get a value of 0.
14013 If this is a discarded function, mark the pc bounds as invalid,
14014 so that GDB will ignore it. */
14015 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14016 return PC_BOUNDS_INVALID
;
14024 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14025 its low and high PC addresses. Do nothing if these addresses could not
14026 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14027 and HIGHPC to the high address if greater than HIGHPC. */
14030 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14031 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14032 struct dwarf2_cu
*cu
)
14034 CORE_ADDR low
, high
;
14035 struct die_info
*child
= die
->child
;
14037 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14039 *lowpc
= std::min (*lowpc
, low
);
14040 *highpc
= std::max (*highpc
, high
);
14043 /* If the language does not allow nested subprograms (either inside
14044 subprograms or lexical blocks), we're done. */
14045 if (cu
->language
!= language_ada
)
14048 /* Check all the children of the given DIE. If it contains nested
14049 subprograms, then check their pc bounds. Likewise, we need to
14050 check lexical blocks as well, as they may also contain subprogram
14052 while (child
&& child
->tag
)
14054 if (child
->tag
== DW_TAG_subprogram
14055 || child
->tag
== DW_TAG_lexical_block
)
14056 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14057 child
= child
->sibling
;
14061 /* Get the low and high pc's represented by the scope DIE, and store
14062 them in *LOWPC and *HIGHPC. If the correct values can't be
14063 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14066 get_scope_pc_bounds (struct die_info
*die
,
14067 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14068 struct dwarf2_cu
*cu
)
14070 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14071 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14072 CORE_ADDR current_low
, current_high
;
14074 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14075 >= PC_BOUNDS_RANGES
)
14077 best_low
= current_low
;
14078 best_high
= current_high
;
14082 struct die_info
*child
= die
->child
;
14084 while (child
&& child
->tag
)
14086 switch (child
->tag
) {
14087 case DW_TAG_subprogram
:
14088 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14090 case DW_TAG_namespace
:
14091 case DW_TAG_module
:
14092 /* FIXME: carlton/2004-01-16: Should we do this for
14093 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14094 that current GCC's always emit the DIEs corresponding
14095 to definitions of methods of classes as children of a
14096 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14097 the DIEs giving the declarations, which could be
14098 anywhere). But I don't see any reason why the
14099 standards says that they have to be there. */
14100 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14102 if (current_low
!= ((CORE_ADDR
) -1))
14104 best_low
= std::min (best_low
, current_low
);
14105 best_high
= std::max (best_high
, current_high
);
14113 child
= child
->sibling
;
14118 *highpc
= best_high
;
14121 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14125 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14126 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14128 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14129 struct gdbarch
*gdbarch
= objfile
->arch ();
14130 struct attribute
*attr
;
14131 struct attribute
*attr_high
;
14133 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14136 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14137 if (attr
!= nullptr)
14139 CORE_ADDR low
= attr
->value_as_address ();
14140 CORE_ADDR high
= attr_high
->value_as_address ();
14142 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14145 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14146 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14147 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14151 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14152 if (attr
!= nullptr)
14154 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14155 We take advantage of the fact that DW_AT_ranges does not appear
14156 in DW_TAG_compile_unit of DWO files. */
14157 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14159 /* The value of the DW_AT_ranges attribute is the offset of the
14160 address range list in the .debug_ranges section. */
14161 unsigned long offset
= (DW_UNSND (attr
)
14162 + (need_ranges_base
? cu
->ranges_base
: 0));
14164 std::vector
<blockrange
> blockvec
;
14165 dwarf2_ranges_process (offset
, cu
,
14166 [&] (CORE_ADDR start
, CORE_ADDR end
)
14170 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14171 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14172 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14173 blockvec
.emplace_back (start
, end
);
14176 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14180 /* Check whether the producer field indicates either of GCC < 4.6, or the
14181 Intel C/C++ compiler, and cache the result in CU. */
14184 check_producer (struct dwarf2_cu
*cu
)
14188 if (cu
->producer
== NULL
)
14190 /* For unknown compilers expect their behavior is DWARF version
14193 GCC started to support .debug_types sections by -gdwarf-4 since
14194 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14195 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14196 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14197 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14199 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14201 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14202 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14204 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14206 cu
->producer_is_icc
= true;
14207 cu
->producer_is_icc_lt_14
= major
< 14;
14209 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14210 cu
->producer_is_codewarrior
= true;
14213 /* For other non-GCC compilers, expect their behavior is DWARF version
14217 cu
->checked_producer
= true;
14220 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14221 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14222 during 4.6.0 experimental. */
14225 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14227 if (!cu
->checked_producer
)
14228 check_producer (cu
);
14230 return cu
->producer_is_gxx_lt_4_6
;
14234 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14235 with incorrect is_stmt attributes. */
14238 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14240 if (!cu
->checked_producer
)
14241 check_producer (cu
);
14243 return cu
->producer_is_codewarrior
;
14246 /* Return the default accessibility type if it is not overridden by
14247 DW_AT_accessibility. */
14249 static enum dwarf_access_attribute
14250 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14252 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14254 /* The default DWARF 2 accessibility for members is public, the default
14255 accessibility for inheritance is private. */
14257 if (die
->tag
!= DW_TAG_inheritance
)
14258 return DW_ACCESS_public
;
14260 return DW_ACCESS_private
;
14264 /* DWARF 3+ defines the default accessibility a different way. The same
14265 rules apply now for DW_TAG_inheritance as for the members and it only
14266 depends on the container kind. */
14268 if (die
->parent
->tag
== DW_TAG_class_type
)
14269 return DW_ACCESS_private
;
14271 return DW_ACCESS_public
;
14275 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14276 offset. If the attribute was not found return 0, otherwise return
14277 1. If it was found but could not properly be handled, set *OFFSET
14281 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14284 struct attribute
*attr
;
14286 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14291 /* Note that we do not check for a section offset first here.
14292 This is because DW_AT_data_member_location is new in DWARF 4,
14293 so if we see it, we can assume that a constant form is really
14294 a constant and not a section offset. */
14295 if (attr
->form_is_constant ())
14296 *offset
= attr
->constant_value (0);
14297 else if (attr
->form_is_section_offset ())
14298 dwarf2_complex_location_expr_complaint ();
14299 else if (attr
->form_is_block ())
14300 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14302 dwarf2_complex_location_expr_complaint ();
14310 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14313 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14314 struct field
*field
)
14316 struct attribute
*attr
;
14318 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14321 if (attr
->form_is_constant ())
14323 LONGEST offset
= attr
->constant_value (0);
14324 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14326 else if (attr
->form_is_section_offset ())
14327 dwarf2_complex_location_expr_complaint ();
14328 else if (attr
->form_is_block ())
14331 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14333 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14336 struct objfile
*objfile
14337 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14338 struct dwarf2_locexpr_baton
*dlbaton
14339 = XOBNEW (&objfile
->objfile_obstack
,
14340 struct dwarf2_locexpr_baton
);
14341 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14342 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14343 /* When using this baton, we want to compute the address
14344 of the field, not the value. This is why
14345 is_reference is set to false here. */
14346 dlbaton
->is_reference
= false;
14347 dlbaton
->per_cu
= cu
->per_cu
;
14349 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14353 dwarf2_complex_location_expr_complaint ();
14357 /* Add an aggregate field to the field list. */
14360 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14361 struct dwarf2_cu
*cu
)
14363 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14364 struct gdbarch
*gdbarch
= objfile
->arch ();
14365 struct nextfield
*new_field
;
14366 struct attribute
*attr
;
14368 const char *fieldname
= "";
14370 if (die
->tag
== DW_TAG_inheritance
)
14372 fip
->baseclasses
.emplace_back ();
14373 new_field
= &fip
->baseclasses
.back ();
14377 fip
->fields
.emplace_back ();
14378 new_field
= &fip
->fields
.back ();
14381 new_field
->offset
= die
->sect_off
;
14383 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14384 if (attr
!= nullptr)
14385 new_field
->accessibility
= DW_UNSND (attr
);
14387 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14388 if (new_field
->accessibility
!= DW_ACCESS_public
)
14389 fip
->non_public_fields
= 1;
14391 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14392 if (attr
!= nullptr)
14393 new_field
->virtuality
= DW_UNSND (attr
);
14395 new_field
->virtuality
= DW_VIRTUALITY_none
;
14397 fp
= &new_field
->field
;
14399 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14401 /* Data member other than a C++ static data member. */
14403 /* Get type of field. */
14404 fp
->type
= die_type (die
, cu
);
14406 SET_FIELD_BITPOS (*fp
, 0);
14408 /* Get bit size of field (zero if none). */
14409 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14410 if (attr
!= nullptr)
14412 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14416 FIELD_BITSIZE (*fp
) = 0;
14419 /* Get bit offset of field. */
14420 handle_data_member_location (die
, cu
, fp
);
14421 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14422 if (attr
!= nullptr)
14424 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14426 /* For big endian bits, the DW_AT_bit_offset gives the
14427 additional bit offset from the MSB of the containing
14428 anonymous object to the MSB of the field. We don't
14429 have to do anything special since we don't need to
14430 know the size of the anonymous object. */
14431 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14435 /* For little endian bits, compute the bit offset to the
14436 MSB of the anonymous object, subtract off the number of
14437 bits from the MSB of the field to the MSB of the
14438 object, and then subtract off the number of bits of
14439 the field itself. The result is the bit offset of
14440 the LSB of the field. */
14441 int anonymous_size
;
14442 int bit_offset
= DW_UNSND (attr
);
14444 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14445 if (attr
!= nullptr)
14447 /* The size of the anonymous object containing
14448 the bit field is explicit, so use the
14449 indicated size (in bytes). */
14450 anonymous_size
= DW_UNSND (attr
);
14454 /* The size of the anonymous object containing
14455 the bit field must be inferred from the type
14456 attribute of the data member containing the
14458 anonymous_size
= TYPE_LENGTH (fp
->type
);
14460 SET_FIELD_BITPOS (*fp
,
14461 (FIELD_BITPOS (*fp
)
14462 + anonymous_size
* bits_per_byte
14463 - bit_offset
- FIELD_BITSIZE (*fp
)));
14466 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14468 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14469 + attr
->constant_value (0)));
14471 /* Get name of field. */
14472 fieldname
= dwarf2_name (die
, cu
);
14473 if (fieldname
== NULL
)
14476 /* The name is already allocated along with this objfile, so we don't
14477 need to duplicate it for the type. */
14478 fp
->name
= fieldname
;
14480 /* Change accessibility for artificial fields (e.g. virtual table
14481 pointer or virtual base class pointer) to private. */
14482 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14484 FIELD_ARTIFICIAL (*fp
) = 1;
14485 new_field
->accessibility
= DW_ACCESS_private
;
14486 fip
->non_public_fields
= 1;
14489 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14491 /* C++ static member. */
14493 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14494 is a declaration, but all versions of G++ as of this writing
14495 (so through at least 3.2.1) incorrectly generate
14496 DW_TAG_variable tags. */
14498 const char *physname
;
14500 /* Get name of field. */
14501 fieldname
= dwarf2_name (die
, cu
);
14502 if (fieldname
== NULL
)
14505 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14507 /* Only create a symbol if this is an external value.
14508 new_symbol checks this and puts the value in the global symbol
14509 table, which we want. If it is not external, new_symbol
14510 will try to put the value in cu->list_in_scope which is wrong. */
14511 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14513 /* A static const member, not much different than an enum as far as
14514 we're concerned, except that we can support more types. */
14515 new_symbol (die
, NULL
, cu
);
14518 /* Get physical name. */
14519 physname
= dwarf2_physname (fieldname
, die
, cu
);
14521 /* The name is already allocated along with this objfile, so we don't
14522 need to duplicate it for the type. */
14523 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14524 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14525 FIELD_NAME (*fp
) = fieldname
;
14527 else if (die
->tag
== DW_TAG_inheritance
)
14529 /* C++ base class field. */
14530 handle_data_member_location (die
, cu
, fp
);
14531 FIELD_BITSIZE (*fp
) = 0;
14532 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14533 FIELD_NAME (*fp
) = fp
->type
->name ();
14536 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14539 /* Can the type given by DIE define another type? */
14542 type_can_define_types (const struct die_info
*die
)
14546 case DW_TAG_typedef
:
14547 case DW_TAG_class_type
:
14548 case DW_TAG_structure_type
:
14549 case DW_TAG_union_type
:
14550 case DW_TAG_enumeration_type
:
14558 /* Add a type definition defined in the scope of the FIP's class. */
14561 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14562 struct dwarf2_cu
*cu
)
14564 struct decl_field fp
;
14565 memset (&fp
, 0, sizeof (fp
));
14567 gdb_assert (type_can_define_types (die
));
14569 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14570 fp
.name
= dwarf2_name (die
, cu
);
14571 fp
.type
= read_type_die (die
, cu
);
14573 /* Save accessibility. */
14574 enum dwarf_access_attribute accessibility
;
14575 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14577 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14579 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14580 switch (accessibility
)
14582 case DW_ACCESS_public
:
14583 /* The assumed value if neither private nor protected. */
14585 case DW_ACCESS_private
:
14588 case DW_ACCESS_protected
:
14589 fp
.is_protected
= 1;
14592 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14595 if (die
->tag
== DW_TAG_typedef
)
14596 fip
->typedef_field_list
.push_back (fp
);
14598 fip
->nested_types_list
.push_back (fp
);
14601 /* A convenience typedef that's used when finding the discriminant
14602 field for a variant part. */
14603 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14606 /* Compute the discriminant range for a given variant. OBSTACK is
14607 where the results will be stored. VARIANT is the variant to
14608 process. IS_UNSIGNED indicates whether the discriminant is signed
14611 static const gdb::array_view
<discriminant_range
>
14612 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14615 std::vector
<discriminant_range
> ranges
;
14617 if (variant
.default_branch
)
14620 if (variant
.discr_list_data
== nullptr)
14622 discriminant_range r
14623 = {variant
.discriminant_value
, variant
.discriminant_value
};
14624 ranges
.push_back (r
);
14628 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14629 variant
.discr_list_data
->size
);
14630 while (!data
.empty ())
14632 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14634 complaint (_("invalid discriminant marker: %d"), data
[0]);
14637 bool is_range
= data
[0] == DW_DSC_range
;
14638 data
= data
.slice (1);
14640 ULONGEST low
, high
;
14641 unsigned int bytes_read
;
14645 complaint (_("DW_AT_discr_list missing low value"));
14649 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14651 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14653 data
= data
.slice (bytes_read
);
14659 complaint (_("DW_AT_discr_list missing high value"));
14663 high
= read_unsigned_leb128 (nullptr, data
.data (),
14666 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14668 data
= data
.slice (bytes_read
);
14673 ranges
.push_back ({ low
, high
});
14677 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14679 std::copy (ranges
.begin (), ranges
.end (), result
);
14680 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14683 static const gdb::array_view
<variant_part
> create_variant_parts
14684 (struct obstack
*obstack
,
14685 const offset_map_type
&offset_map
,
14686 struct field_info
*fi
,
14687 const std::vector
<variant_part_builder
> &variant_parts
);
14689 /* Fill in a "struct variant" for a given variant field. RESULT is
14690 the variant to fill in. OBSTACK is where any needed allocations
14691 will be done. OFFSET_MAP holds the mapping from section offsets to
14692 fields for the type. FI describes the fields of the type we're
14693 processing. FIELD is the variant field we're converting. */
14696 create_one_variant (variant
&result
, struct obstack
*obstack
,
14697 const offset_map_type
&offset_map
,
14698 struct field_info
*fi
, const variant_field
&field
)
14700 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14701 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14702 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14703 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14704 field
.variant_parts
);
14707 /* Fill in a "struct variant_part" for a given variant part. RESULT
14708 is the variant part to fill in. OBSTACK is where any needed
14709 allocations will be done. OFFSET_MAP holds the mapping from
14710 section offsets to fields for the type. FI describes the fields of
14711 the type we're processing. BUILDER is the variant part to be
14715 create_one_variant_part (variant_part
&result
,
14716 struct obstack
*obstack
,
14717 const offset_map_type
&offset_map
,
14718 struct field_info
*fi
,
14719 const variant_part_builder
&builder
)
14721 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14722 if (iter
== offset_map
.end ())
14724 result
.discriminant_index
= -1;
14725 /* Doesn't matter. */
14726 result
.is_unsigned
= false;
14730 result
.discriminant_index
= iter
->second
;
14732 = TYPE_UNSIGNED (FIELD_TYPE
14733 (fi
->fields
[result
.discriminant_index
].field
));
14736 size_t n
= builder
.variants
.size ();
14737 variant
*output
= new (obstack
) variant
[n
];
14738 for (size_t i
= 0; i
< n
; ++i
)
14739 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14740 builder
.variants
[i
]);
14742 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14745 /* Create a vector of variant parts that can be attached to a type.
14746 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14747 holds the mapping from section offsets to fields for the type. FI
14748 describes the fields of the type we're processing. VARIANT_PARTS
14749 is the vector to convert. */
14751 static const gdb::array_view
<variant_part
>
14752 create_variant_parts (struct obstack
*obstack
,
14753 const offset_map_type
&offset_map
,
14754 struct field_info
*fi
,
14755 const std::vector
<variant_part_builder
> &variant_parts
)
14757 if (variant_parts
.empty ())
14760 size_t n
= variant_parts
.size ();
14761 variant_part
*result
= new (obstack
) variant_part
[n
];
14762 for (size_t i
= 0; i
< n
; ++i
)
14763 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14766 return gdb::array_view
<variant_part
> (result
, n
);
14769 /* Compute the variant part vector for FIP, attaching it to TYPE when
14773 add_variant_property (struct field_info
*fip
, struct type
*type
,
14774 struct dwarf2_cu
*cu
)
14776 /* Map section offsets of fields to their field index. Note the
14777 field index here does not take the number of baseclasses into
14779 offset_map_type offset_map
;
14780 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14781 offset_map
[fip
->fields
[i
].offset
] = i
;
14783 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14784 gdb::array_view
<variant_part
> parts
14785 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14786 fip
->variant_parts
);
14788 struct dynamic_prop prop
;
14789 prop
.kind
= PROP_VARIANT_PARTS
;
14790 prop
.data
.variant_parts
14791 = ((gdb::array_view
<variant_part
> *)
14792 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14794 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14797 /* Create the vector of fields, and attach it to the type. */
14800 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14801 struct dwarf2_cu
*cu
)
14803 int nfields
= fip
->nfields ();
14805 /* Record the field count, allocate space for the array of fields,
14806 and create blank accessibility bitfields if necessary. */
14807 type
->set_num_fields (nfields
);
14809 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14811 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14813 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14815 TYPE_FIELD_PRIVATE_BITS (type
) =
14816 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14817 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14819 TYPE_FIELD_PROTECTED_BITS (type
) =
14820 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14821 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14823 TYPE_FIELD_IGNORE_BITS (type
) =
14824 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14825 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14828 /* If the type has baseclasses, allocate and clear a bit vector for
14829 TYPE_FIELD_VIRTUAL_BITS. */
14830 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14832 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14833 unsigned char *pointer
;
14835 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14836 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14837 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14838 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14839 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14842 if (!fip
->variant_parts
.empty ())
14843 add_variant_property (fip
, type
, cu
);
14845 /* Copy the saved-up fields into the field vector. */
14846 for (int i
= 0; i
< nfields
; ++i
)
14848 struct nextfield
&field
14849 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14850 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14852 TYPE_FIELD (type
, i
) = field
.field
;
14853 switch (field
.accessibility
)
14855 case DW_ACCESS_private
:
14856 if (cu
->language
!= language_ada
)
14857 SET_TYPE_FIELD_PRIVATE (type
, i
);
14860 case DW_ACCESS_protected
:
14861 if (cu
->language
!= language_ada
)
14862 SET_TYPE_FIELD_PROTECTED (type
, i
);
14865 case DW_ACCESS_public
:
14869 /* Unknown accessibility. Complain and treat it as public. */
14871 complaint (_("unsupported accessibility %d"),
14872 field
.accessibility
);
14876 if (i
< fip
->baseclasses
.size ())
14878 switch (field
.virtuality
)
14880 case DW_VIRTUALITY_virtual
:
14881 case DW_VIRTUALITY_pure_virtual
:
14882 if (cu
->language
== language_ada
)
14883 error (_("unexpected virtuality in component of Ada type"));
14884 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14891 /* Return true if this member function is a constructor, false
14895 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14897 const char *fieldname
;
14898 const char *type_name
;
14901 if (die
->parent
== NULL
)
14904 if (die
->parent
->tag
!= DW_TAG_structure_type
14905 && die
->parent
->tag
!= DW_TAG_union_type
14906 && die
->parent
->tag
!= DW_TAG_class_type
)
14909 fieldname
= dwarf2_name (die
, cu
);
14910 type_name
= dwarf2_name (die
->parent
, cu
);
14911 if (fieldname
== NULL
|| type_name
== NULL
)
14914 len
= strlen (fieldname
);
14915 return (strncmp (fieldname
, type_name
, len
) == 0
14916 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14919 /* Check if the given VALUE is a recognized enum
14920 dwarf_defaulted_attribute constant according to DWARF5 spec,
14924 is_valid_DW_AT_defaulted (ULONGEST value
)
14928 case DW_DEFAULTED_no
:
14929 case DW_DEFAULTED_in_class
:
14930 case DW_DEFAULTED_out_of_class
:
14934 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14938 /* Add a member function to the proper fieldlist. */
14941 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14942 struct type
*type
, struct dwarf2_cu
*cu
)
14944 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14945 struct attribute
*attr
;
14947 struct fnfieldlist
*flp
= nullptr;
14948 struct fn_field
*fnp
;
14949 const char *fieldname
;
14950 struct type
*this_type
;
14951 enum dwarf_access_attribute accessibility
;
14953 if (cu
->language
== language_ada
)
14954 error (_("unexpected member function in Ada type"));
14956 /* Get name of member function. */
14957 fieldname
= dwarf2_name (die
, cu
);
14958 if (fieldname
== NULL
)
14961 /* Look up member function name in fieldlist. */
14962 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14964 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14966 flp
= &fip
->fnfieldlists
[i
];
14971 /* Create a new fnfieldlist if necessary. */
14972 if (flp
== nullptr)
14974 fip
->fnfieldlists
.emplace_back ();
14975 flp
= &fip
->fnfieldlists
.back ();
14976 flp
->name
= fieldname
;
14977 i
= fip
->fnfieldlists
.size () - 1;
14980 /* Create a new member function field and add it to the vector of
14982 flp
->fnfields
.emplace_back ();
14983 fnp
= &flp
->fnfields
.back ();
14985 /* Delay processing of the physname until later. */
14986 if (cu
->language
== language_cplus
)
14987 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14991 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14992 fnp
->physname
= physname
? physname
: "";
14995 fnp
->type
= alloc_type (objfile
);
14996 this_type
= read_type_die (die
, cu
);
14997 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
14999 int nparams
= this_type
->num_fields ();
15001 /* TYPE is the domain of this method, and THIS_TYPE is the type
15002 of the method itself (TYPE_CODE_METHOD). */
15003 smash_to_method_type (fnp
->type
, type
,
15004 TYPE_TARGET_TYPE (this_type
),
15005 this_type
->fields (),
15006 this_type
->num_fields (),
15007 TYPE_VARARGS (this_type
));
15009 /* Handle static member functions.
15010 Dwarf2 has no clean way to discern C++ static and non-static
15011 member functions. G++ helps GDB by marking the first
15012 parameter for non-static member functions (which is the this
15013 pointer) as artificial. We obtain this information from
15014 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15015 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15016 fnp
->voffset
= VOFFSET_STATIC
;
15019 complaint (_("member function type missing for '%s'"),
15020 dwarf2_full_name (fieldname
, die
, cu
));
15022 /* Get fcontext from DW_AT_containing_type if present. */
15023 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15024 fnp
->fcontext
= die_containing_type (die
, cu
);
15026 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15027 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15029 /* Get accessibility. */
15030 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15031 if (attr
!= nullptr)
15032 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15034 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15035 switch (accessibility
)
15037 case DW_ACCESS_private
:
15038 fnp
->is_private
= 1;
15040 case DW_ACCESS_protected
:
15041 fnp
->is_protected
= 1;
15045 /* Check for artificial methods. */
15046 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15047 if (attr
&& DW_UNSND (attr
) != 0)
15048 fnp
->is_artificial
= 1;
15050 /* Check for defaulted methods. */
15051 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15052 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15053 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15055 /* Check for deleted methods. */
15056 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15057 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15058 fnp
->is_deleted
= 1;
15060 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15062 /* Get index in virtual function table if it is a virtual member
15063 function. For older versions of GCC, this is an offset in the
15064 appropriate virtual table, as specified by DW_AT_containing_type.
15065 For everyone else, it is an expression to be evaluated relative
15066 to the object address. */
15068 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15069 if (attr
!= nullptr)
15071 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15073 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15075 /* Old-style GCC. */
15076 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15078 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15079 || (DW_BLOCK (attr
)->size
> 1
15080 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15081 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15083 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15084 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15085 dwarf2_complex_location_expr_complaint ();
15087 fnp
->voffset
/= cu
->header
.addr_size
;
15091 dwarf2_complex_location_expr_complaint ();
15093 if (!fnp
->fcontext
)
15095 /* If there is no `this' field and no DW_AT_containing_type,
15096 we cannot actually find a base class context for the
15098 if (this_type
->num_fields () == 0
15099 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15101 complaint (_("cannot determine context for virtual member "
15102 "function \"%s\" (offset %s)"),
15103 fieldname
, sect_offset_str (die
->sect_off
));
15108 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15112 else if (attr
->form_is_section_offset ())
15114 dwarf2_complex_location_expr_complaint ();
15118 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15124 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15125 if (attr
&& DW_UNSND (attr
))
15127 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15128 complaint (_("Member function \"%s\" (offset %s) is virtual "
15129 "but the vtable offset is not specified"),
15130 fieldname
, sect_offset_str (die
->sect_off
));
15131 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15132 TYPE_CPLUS_DYNAMIC (type
) = 1;
15137 /* Create the vector of member function fields, and attach it to the type. */
15140 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15141 struct dwarf2_cu
*cu
)
15143 if (cu
->language
== language_ada
)
15144 error (_("unexpected member functions in Ada type"));
15146 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15147 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15149 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15151 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15153 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15154 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15156 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15157 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15158 fn_flp
->fn_fields
= (struct fn_field
*)
15159 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15161 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15162 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15165 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15168 /* Returns non-zero if NAME is the name of a vtable member in CU's
15169 language, zero otherwise. */
15171 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15173 static const char vptr
[] = "_vptr";
15175 /* Look for the C++ form of the vtable. */
15176 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15182 /* GCC outputs unnamed structures that are really pointers to member
15183 functions, with the ABI-specified layout. If TYPE describes
15184 such a structure, smash it into a member function type.
15186 GCC shouldn't do this; it should just output pointer to member DIEs.
15187 This is GCC PR debug/28767. */
15190 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15192 struct type
*pfn_type
, *self_type
, *new_type
;
15194 /* Check for a structure with no name and two children. */
15195 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15198 /* Check for __pfn and __delta members. */
15199 if (TYPE_FIELD_NAME (type
, 0) == NULL
15200 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15201 || TYPE_FIELD_NAME (type
, 1) == NULL
15202 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15205 /* Find the type of the method. */
15206 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15207 if (pfn_type
== NULL
15208 || pfn_type
->code () != TYPE_CODE_PTR
15209 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15212 /* Look for the "this" argument. */
15213 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15214 if (pfn_type
->num_fields () == 0
15215 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15216 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15219 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15220 new_type
= alloc_type (objfile
);
15221 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15222 pfn_type
->fields (), pfn_type
->num_fields (),
15223 TYPE_VARARGS (pfn_type
));
15224 smash_to_methodptr_type (type
, new_type
);
15227 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15228 appropriate error checking and issuing complaints if there is a
15232 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15234 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15236 if (attr
== nullptr)
15239 if (!attr
->form_is_constant ())
15241 complaint (_("DW_AT_alignment must have constant form"
15242 " - DIE at %s [in module %s]"),
15243 sect_offset_str (die
->sect_off
),
15244 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15249 if (attr
->form
== DW_FORM_sdata
)
15251 LONGEST val
= DW_SND (attr
);
15254 complaint (_("DW_AT_alignment value must not be negative"
15255 " - DIE at %s [in module %s]"),
15256 sect_offset_str (die
->sect_off
),
15257 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15263 align
= DW_UNSND (attr
);
15267 complaint (_("DW_AT_alignment value must not be zero"
15268 " - DIE at %s [in module %s]"),
15269 sect_offset_str (die
->sect_off
),
15270 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15273 if ((align
& (align
- 1)) != 0)
15275 complaint (_("DW_AT_alignment value must be a power of 2"
15276 " - DIE at %s [in module %s]"),
15277 sect_offset_str (die
->sect_off
),
15278 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15285 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15286 the alignment for TYPE. */
15289 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15292 if (!set_type_align (type
, get_alignment (cu
, die
)))
15293 complaint (_("DW_AT_alignment value too large"
15294 " - DIE at %s [in module %s]"),
15295 sect_offset_str (die
->sect_off
),
15296 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15299 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15300 constant for a type, according to DWARF5 spec, Table 5.5. */
15303 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15308 case DW_CC_pass_by_reference
:
15309 case DW_CC_pass_by_value
:
15313 complaint (_("unrecognized DW_AT_calling_convention value "
15314 "(%s) for a type"), pulongest (value
));
15319 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15320 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15321 also according to GNU-specific values (see include/dwarf2.h). */
15324 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15329 case DW_CC_program
:
15333 case DW_CC_GNU_renesas_sh
:
15334 case DW_CC_GNU_borland_fastcall_i386
:
15335 case DW_CC_GDB_IBM_OpenCL
:
15339 complaint (_("unrecognized DW_AT_calling_convention value "
15340 "(%s) for a subroutine"), pulongest (value
));
15345 /* Called when we find the DIE that starts a structure or union scope
15346 (definition) to create a type for the structure or union. Fill in
15347 the type's name and general properties; the members will not be
15348 processed until process_structure_scope. A symbol table entry for
15349 the type will also not be done until process_structure_scope (assuming
15350 the type has a name).
15352 NOTE: we need to call these functions regardless of whether or not the
15353 DIE has a DW_AT_name attribute, since it might be an anonymous
15354 structure or union. This gets the type entered into our set of
15355 user defined types. */
15357 static struct type
*
15358 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15360 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15362 struct attribute
*attr
;
15365 /* If the definition of this type lives in .debug_types, read that type.
15366 Don't follow DW_AT_specification though, that will take us back up
15367 the chain and we want to go down. */
15368 attr
= die
->attr (DW_AT_signature
);
15369 if (attr
!= nullptr)
15371 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15373 /* The type's CU may not be the same as CU.
15374 Ensure TYPE is recorded with CU in die_type_hash. */
15375 return set_die_type (die
, type
, cu
);
15378 type
= alloc_type (objfile
);
15379 INIT_CPLUS_SPECIFIC (type
);
15381 name
= dwarf2_name (die
, cu
);
15384 if (cu
->language
== language_cplus
15385 || cu
->language
== language_d
15386 || cu
->language
== language_rust
)
15388 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15390 /* dwarf2_full_name might have already finished building the DIE's
15391 type. If so, there is no need to continue. */
15392 if (get_die_type (die
, cu
) != NULL
)
15393 return get_die_type (die
, cu
);
15395 type
->set_name (full_name
);
15399 /* The name is already allocated along with this objfile, so
15400 we don't need to duplicate it for the type. */
15401 type
->set_name (name
);
15405 if (die
->tag
== DW_TAG_structure_type
)
15407 type
->set_code (TYPE_CODE_STRUCT
);
15409 else if (die
->tag
== DW_TAG_union_type
)
15411 type
->set_code (TYPE_CODE_UNION
);
15415 type
->set_code (TYPE_CODE_STRUCT
);
15418 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15419 TYPE_DECLARED_CLASS (type
) = 1;
15421 /* Store the calling convention in the type if it's available in
15422 the die. Otherwise the calling convention remains set to
15423 the default value DW_CC_normal. */
15424 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15425 if (attr
!= nullptr
15426 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15428 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15429 TYPE_CPLUS_CALLING_CONVENTION (type
)
15430 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15433 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15434 if (attr
!= nullptr)
15436 if (attr
->form_is_constant ())
15437 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15440 struct dynamic_prop prop
;
15441 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
15442 cu
->per_cu
->addr_type ()))
15443 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15444 TYPE_LENGTH (type
) = 0;
15449 TYPE_LENGTH (type
) = 0;
15452 maybe_set_alignment (cu
, die
, type
);
15454 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15456 /* ICC<14 does not output the required DW_AT_declaration on
15457 incomplete types, but gives them a size of zero. */
15458 TYPE_STUB (type
) = 1;
15461 TYPE_STUB_SUPPORTED (type
) = 1;
15463 if (die_is_declaration (die
, cu
))
15464 TYPE_STUB (type
) = 1;
15465 else if (attr
== NULL
&& die
->child
== NULL
15466 && producer_is_realview (cu
->producer
))
15467 /* RealView does not output the required DW_AT_declaration
15468 on incomplete types. */
15469 TYPE_STUB (type
) = 1;
15471 /* We need to add the type field to the die immediately so we don't
15472 infinitely recurse when dealing with pointers to the structure
15473 type within the structure itself. */
15474 set_die_type (die
, type
, cu
);
15476 /* set_die_type should be already done. */
15477 set_descriptive_type (type
, die
, cu
);
15482 static void handle_struct_member_die
15483 (struct die_info
*child_die
,
15485 struct field_info
*fi
,
15486 std::vector
<struct symbol
*> *template_args
,
15487 struct dwarf2_cu
*cu
);
15489 /* A helper for handle_struct_member_die that handles
15490 DW_TAG_variant_part. */
15493 handle_variant_part (struct die_info
*die
, struct type
*type
,
15494 struct field_info
*fi
,
15495 std::vector
<struct symbol
*> *template_args
,
15496 struct dwarf2_cu
*cu
)
15498 variant_part_builder
*new_part
;
15499 if (fi
->current_variant_part
== nullptr)
15501 fi
->variant_parts
.emplace_back ();
15502 new_part
= &fi
->variant_parts
.back ();
15504 else if (!fi
->current_variant_part
->processing_variant
)
15506 complaint (_("nested DW_TAG_variant_part seen "
15507 "- DIE at %s [in module %s]"),
15508 sect_offset_str (die
->sect_off
),
15509 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15514 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15515 current
.variant_parts
.emplace_back ();
15516 new_part
= ¤t
.variant_parts
.back ();
15519 /* When we recurse, we want callees to add to this new variant
15521 scoped_restore save_current_variant_part
15522 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15524 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15527 /* It's a univariant form, an extension we support. */
15529 else if (discr
->form_is_ref ())
15531 struct dwarf2_cu
*target_cu
= cu
;
15532 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15534 new_part
->discriminant_offset
= target_die
->sect_off
;
15538 complaint (_("DW_AT_discr does not have DIE reference form"
15539 " - DIE at %s [in module %s]"),
15540 sect_offset_str (die
->sect_off
),
15541 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15544 for (die_info
*child_die
= die
->child
;
15546 child_die
= child_die
->sibling
)
15547 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15550 /* A helper for handle_struct_member_die that handles
15554 handle_variant (struct die_info
*die
, struct type
*type
,
15555 struct field_info
*fi
,
15556 std::vector
<struct symbol
*> *template_args
,
15557 struct dwarf2_cu
*cu
)
15559 if (fi
->current_variant_part
== nullptr)
15561 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15562 "- DIE at %s [in module %s]"),
15563 sect_offset_str (die
->sect_off
),
15564 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15567 if (fi
->current_variant_part
->processing_variant
)
15569 complaint (_("nested DW_TAG_variant seen "
15570 "- DIE at %s [in module %s]"),
15571 sect_offset_str (die
->sect_off
),
15572 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15576 scoped_restore save_processing_variant
15577 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15580 fi
->current_variant_part
->variants
.emplace_back ();
15581 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15582 variant
.first_field
= fi
->fields
.size ();
15584 /* In a variant we want to get the discriminant and also add a
15585 field for our sole member child. */
15586 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15587 if (discr
== nullptr)
15589 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15590 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15591 variant
.default_branch
= true;
15593 variant
.discr_list_data
= DW_BLOCK (discr
);
15596 variant
.discriminant_value
= DW_UNSND (discr
);
15598 for (die_info
*variant_child
= die
->child
;
15599 variant_child
!= NULL
;
15600 variant_child
= variant_child
->sibling
)
15601 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15603 variant
.last_field
= fi
->fields
.size ();
15606 /* A helper for process_structure_scope that handles a single member
15610 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15611 struct field_info
*fi
,
15612 std::vector
<struct symbol
*> *template_args
,
15613 struct dwarf2_cu
*cu
)
15615 if (child_die
->tag
== DW_TAG_member
15616 || child_die
->tag
== DW_TAG_variable
)
15618 /* NOTE: carlton/2002-11-05: A C++ static data member
15619 should be a DW_TAG_member that is a declaration, but
15620 all versions of G++ as of this writing (so through at
15621 least 3.2.1) incorrectly generate DW_TAG_variable
15622 tags for them instead. */
15623 dwarf2_add_field (fi
, child_die
, cu
);
15625 else if (child_die
->tag
== DW_TAG_subprogram
)
15627 /* Rust doesn't have member functions in the C++ sense.
15628 However, it does emit ordinary functions as children
15629 of a struct DIE. */
15630 if (cu
->language
== language_rust
)
15631 read_func_scope (child_die
, cu
);
15634 /* C++ member function. */
15635 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15638 else if (child_die
->tag
== DW_TAG_inheritance
)
15640 /* C++ base class field. */
15641 dwarf2_add_field (fi
, child_die
, cu
);
15643 else if (type_can_define_types (child_die
))
15644 dwarf2_add_type_defn (fi
, child_die
, cu
);
15645 else if (child_die
->tag
== DW_TAG_template_type_param
15646 || child_die
->tag
== DW_TAG_template_value_param
)
15648 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15651 template_args
->push_back (arg
);
15653 else if (child_die
->tag
== DW_TAG_variant_part
)
15654 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15655 else if (child_die
->tag
== DW_TAG_variant
)
15656 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15659 /* Finish creating a structure or union type, including filling in
15660 its members and creating a symbol for it. */
15663 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15665 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15666 struct die_info
*child_die
;
15669 type
= get_die_type (die
, cu
);
15671 type
= read_structure_type (die
, cu
);
15673 bool has_template_parameters
= false;
15674 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15676 struct field_info fi
;
15677 std::vector
<struct symbol
*> template_args
;
15679 child_die
= die
->child
;
15681 while (child_die
&& child_die
->tag
)
15683 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15684 child_die
= child_die
->sibling
;
15687 /* Attach template arguments to type. */
15688 if (!template_args
.empty ())
15690 has_template_parameters
= true;
15691 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15692 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15693 TYPE_TEMPLATE_ARGUMENTS (type
)
15694 = XOBNEWVEC (&objfile
->objfile_obstack
,
15696 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15697 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15698 template_args
.data (),
15699 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15700 * sizeof (struct symbol
*)));
15703 /* Attach fields and member functions to the type. */
15704 if (fi
.nfields () > 0)
15705 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15706 if (!fi
.fnfieldlists
.empty ())
15708 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15710 /* Get the type which refers to the base class (possibly this
15711 class itself) which contains the vtable pointer for the current
15712 class from the DW_AT_containing_type attribute. This use of
15713 DW_AT_containing_type is a GNU extension. */
15715 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15717 struct type
*t
= die_containing_type (die
, cu
);
15719 set_type_vptr_basetype (type
, t
);
15724 /* Our own class provides vtbl ptr. */
15725 for (i
= t
->num_fields () - 1;
15726 i
>= TYPE_N_BASECLASSES (t
);
15729 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15731 if (is_vtable_name (fieldname
, cu
))
15733 set_type_vptr_fieldno (type
, i
);
15738 /* Complain if virtual function table field not found. */
15739 if (i
< TYPE_N_BASECLASSES (t
))
15740 complaint (_("virtual function table pointer "
15741 "not found when defining class '%s'"),
15742 type
->name () ? type
->name () : "");
15746 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15749 else if (cu
->producer
15750 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15752 /* The IBM XLC compiler does not provide direct indication
15753 of the containing type, but the vtable pointer is
15754 always named __vfp. */
15758 for (i
= type
->num_fields () - 1;
15759 i
>= TYPE_N_BASECLASSES (type
);
15762 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15764 set_type_vptr_fieldno (type
, i
);
15765 set_type_vptr_basetype (type
, type
);
15772 /* Copy fi.typedef_field_list linked list elements content into the
15773 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15774 if (!fi
.typedef_field_list
.empty ())
15776 int count
= fi
.typedef_field_list
.size ();
15778 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15779 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15780 = ((struct decl_field
*)
15782 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15783 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15785 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15786 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15789 /* Copy fi.nested_types_list linked list elements content into the
15790 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15791 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15793 int count
= fi
.nested_types_list
.size ();
15795 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15796 TYPE_NESTED_TYPES_ARRAY (type
)
15797 = ((struct decl_field
*)
15798 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15799 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15801 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15802 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15806 quirk_gcc_member_function_pointer (type
, objfile
);
15807 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15808 cu
->rust_unions
.push_back (type
);
15810 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15811 snapshots) has been known to create a die giving a declaration
15812 for a class that has, as a child, a die giving a definition for a
15813 nested class. So we have to process our children even if the
15814 current die is a declaration. Normally, of course, a declaration
15815 won't have any children at all. */
15817 child_die
= die
->child
;
15819 while (child_die
!= NULL
&& child_die
->tag
)
15821 if (child_die
->tag
== DW_TAG_member
15822 || child_die
->tag
== DW_TAG_variable
15823 || child_die
->tag
== DW_TAG_inheritance
15824 || child_die
->tag
== DW_TAG_template_value_param
15825 || child_die
->tag
== DW_TAG_template_type_param
)
15830 process_die (child_die
, cu
);
15832 child_die
= child_die
->sibling
;
15835 /* Do not consider external references. According to the DWARF standard,
15836 these DIEs are identified by the fact that they have no byte_size
15837 attribute, and a declaration attribute. */
15838 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15839 || !die_is_declaration (die
, cu
)
15840 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15842 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15844 if (has_template_parameters
)
15846 struct symtab
*symtab
;
15847 if (sym
!= nullptr)
15848 symtab
= symbol_symtab (sym
);
15849 else if (cu
->line_header
!= nullptr)
15851 /* Any related symtab will do. */
15853 = cu
->line_header
->file_names ()[0].symtab
;
15858 complaint (_("could not find suitable "
15859 "symtab for template parameter"
15860 " - DIE at %s [in module %s]"),
15861 sect_offset_str (die
->sect_off
),
15862 objfile_name (objfile
));
15865 if (symtab
!= nullptr)
15867 /* Make sure that the symtab is set on the new symbols.
15868 Even though they don't appear in this symtab directly,
15869 other parts of gdb assume that symbols do, and this is
15870 reasonably true. */
15871 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15872 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15878 /* Assuming DIE is an enumeration type, and TYPE is its associated
15879 type, update TYPE using some information only available in DIE's
15880 children. In particular, the fields are computed. */
15883 update_enumeration_type_from_children (struct die_info
*die
,
15885 struct dwarf2_cu
*cu
)
15887 struct die_info
*child_die
;
15888 int unsigned_enum
= 1;
15891 auto_obstack obstack
;
15892 std::vector
<struct field
> fields
;
15894 for (child_die
= die
->child
;
15895 child_die
!= NULL
&& child_die
->tag
;
15896 child_die
= child_die
->sibling
)
15898 struct attribute
*attr
;
15900 const gdb_byte
*bytes
;
15901 struct dwarf2_locexpr_baton
*baton
;
15904 if (child_die
->tag
!= DW_TAG_enumerator
)
15907 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15911 name
= dwarf2_name (child_die
, cu
);
15913 name
= "<anonymous enumerator>";
15915 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15916 &value
, &bytes
, &baton
);
15924 if (count_one_bits_ll (value
) >= 2)
15928 fields
.emplace_back ();
15929 struct field
&field
= fields
.back ();
15930 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
15931 SET_FIELD_ENUMVAL (field
, value
);
15934 if (!fields
.empty ())
15936 type
->set_num_fields (fields
.size ());
15939 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
15940 memcpy (type
->fields (), fields
.data (),
15941 sizeof (struct field
) * fields
.size ());
15945 TYPE_UNSIGNED (type
) = 1;
15947 TYPE_FLAG_ENUM (type
) = 1;
15950 /* Given a DW_AT_enumeration_type die, set its type. We do not
15951 complete the type's fields yet, or create any symbols. */
15953 static struct type
*
15954 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15956 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15958 struct attribute
*attr
;
15961 /* If the definition of this type lives in .debug_types, read that type.
15962 Don't follow DW_AT_specification though, that will take us back up
15963 the chain and we want to go down. */
15964 attr
= die
->attr (DW_AT_signature
);
15965 if (attr
!= nullptr)
15967 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15969 /* The type's CU may not be the same as CU.
15970 Ensure TYPE is recorded with CU in die_type_hash. */
15971 return set_die_type (die
, type
, cu
);
15974 type
= alloc_type (objfile
);
15976 type
->set_code (TYPE_CODE_ENUM
);
15977 name
= dwarf2_full_name (NULL
, die
, cu
);
15979 type
->set_name (name
);
15981 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15984 struct type
*underlying_type
= die_type (die
, cu
);
15986 TYPE_TARGET_TYPE (type
) = underlying_type
;
15989 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15990 if (attr
!= nullptr)
15992 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15996 TYPE_LENGTH (type
) = 0;
15999 maybe_set_alignment (cu
, die
, type
);
16001 /* The enumeration DIE can be incomplete. In Ada, any type can be
16002 declared as private in the package spec, and then defined only
16003 inside the package body. Such types are known as Taft Amendment
16004 Types. When another package uses such a type, an incomplete DIE
16005 may be generated by the compiler. */
16006 if (die_is_declaration (die
, cu
))
16007 TYPE_STUB (type
) = 1;
16009 /* If this type has an underlying type that is not a stub, then we
16010 may use its attributes. We always use the "unsigned" attribute
16011 in this situation, because ordinarily we guess whether the type
16012 is unsigned -- but the guess can be wrong and the underlying type
16013 can tell us the reality. However, we defer to a local size
16014 attribute if one exists, because this lets the compiler override
16015 the underlying type if needed. */
16016 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16018 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16019 underlying_type
= check_typedef (underlying_type
);
16020 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16021 if (TYPE_LENGTH (type
) == 0)
16022 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16023 if (TYPE_RAW_ALIGN (type
) == 0
16024 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16025 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16028 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16030 set_die_type (die
, type
, cu
);
16032 /* Finish the creation of this type by using the enum's children.
16033 Note that, as usual, this must come after set_die_type to avoid
16034 infinite recursion when trying to compute the names of the
16036 update_enumeration_type_from_children (die
, type
, cu
);
16041 /* Given a pointer to a die which begins an enumeration, process all
16042 the dies that define the members of the enumeration, and create the
16043 symbol for the enumeration type.
16045 NOTE: We reverse the order of the element list. */
16048 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16050 struct type
*this_type
;
16052 this_type
= get_die_type (die
, cu
);
16053 if (this_type
== NULL
)
16054 this_type
= read_enumeration_type (die
, cu
);
16056 if (die
->child
!= NULL
)
16058 struct die_info
*child_die
;
16061 child_die
= die
->child
;
16062 while (child_die
&& child_die
->tag
)
16064 if (child_die
->tag
!= DW_TAG_enumerator
)
16066 process_die (child_die
, cu
);
16070 name
= dwarf2_name (child_die
, cu
);
16072 new_symbol (child_die
, this_type
, cu
);
16075 child_die
= child_die
->sibling
;
16079 /* If we are reading an enum from a .debug_types unit, and the enum
16080 is a declaration, and the enum is not the signatured type in the
16081 unit, then we do not want to add a symbol for it. Adding a
16082 symbol would in some cases obscure the true definition of the
16083 enum, giving users an incomplete type when the definition is
16084 actually available. Note that we do not want to do this for all
16085 enums which are just declarations, because C++0x allows forward
16086 enum declarations. */
16087 if (cu
->per_cu
->is_debug_types
16088 && die_is_declaration (die
, cu
))
16090 struct signatured_type
*sig_type
;
16092 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16093 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16094 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16098 new_symbol (die
, this_type
, cu
);
16101 /* Extract all information from a DW_TAG_array_type DIE and put it in
16102 the DIE's type field. For now, this only handles one dimensional
16105 static struct type
*
16106 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16108 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16109 struct die_info
*child_die
;
16111 struct type
*element_type
, *range_type
, *index_type
;
16112 struct attribute
*attr
;
16114 struct dynamic_prop
*byte_stride_prop
= NULL
;
16115 unsigned int bit_stride
= 0;
16117 element_type
= die_type (die
, cu
);
16119 /* The die_type call above may have already set the type for this DIE. */
16120 type
= get_die_type (die
, cu
);
16124 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16128 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
16131 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16132 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16136 complaint (_("unable to read array DW_AT_byte_stride "
16137 " - DIE at %s [in module %s]"),
16138 sect_offset_str (die
->sect_off
),
16139 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16140 /* Ignore this attribute. We will likely not be able to print
16141 arrays of this type correctly, but there is little we can do
16142 to help if we cannot read the attribute's value. */
16143 byte_stride_prop
= NULL
;
16147 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16149 bit_stride
= DW_UNSND (attr
);
16151 /* Irix 6.2 native cc creates array types without children for
16152 arrays with unspecified length. */
16153 if (die
->child
== NULL
)
16155 index_type
= objfile_type (objfile
)->builtin_int
;
16156 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16157 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16158 byte_stride_prop
, bit_stride
);
16159 return set_die_type (die
, type
, cu
);
16162 std::vector
<struct type
*> range_types
;
16163 child_die
= die
->child
;
16164 while (child_die
&& child_die
->tag
)
16166 if (child_die
->tag
== DW_TAG_subrange_type
)
16168 struct type
*child_type
= read_type_die (child_die
, cu
);
16170 if (child_type
!= NULL
)
16172 /* The range type was succesfully read. Save it for the
16173 array type creation. */
16174 range_types
.push_back (child_type
);
16177 child_die
= child_die
->sibling
;
16180 /* Dwarf2 dimensions are output from left to right, create the
16181 necessary array types in backwards order. */
16183 type
= element_type
;
16185 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16189 while (i
< range_types
.size ())
16190 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16191 byte_stride_prop
, bit_stride
);
16195 size_t ndim
= range_types
.size ();
16197 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16198 byte_stride_prop
, bit_stride
);
16201 /* Understand Dwarf2 support for vector types (like they occur on
16202 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16203 array type. This is not part of the Dwarf2/3 standard yet, but a
16204 custom vendor extension. The main difference between a regular
16205 array and the vector variant is that vectors are passed by value
16207 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16208 if (attr
!= nullptr)
16209 make_vector_type (type
);
16211 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16212 implementation may choose to implement triple vectors using this
16214 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16215 if (attr
!= nullptr)
16217 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16218 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16220 complaint (_("DW_AT_byte_size for array type smaller "
16221 "than the total size of elements"));
16224 name
= dwarf2_name (die
, cu
);
16226 type
->set_name (name
);
16228 maybe_set_alignment (cu
, die
, type
);
16230 /* Install the type in the die. */
16231 set_die_type (die
, type
, cu
);
16233 /* set_die_type should be already done. */
16234 set_descriptive_type (type
, die
, cu
);
16239 static enum dwarf_array_dim_ordering
16240 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16242 struct attribute
*attr
;
16244 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16246 if (attr
!= nullptr)
16247 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16249 /* GNU F77 is a special case, as at 08/2004 array type info is the
16250 opposite order to the dwarf2 specification, but data is still
16251 laid out as per normal fortran.
16253 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16254 version checking. */
16256 if (cu
->language
== language_fortran
16257 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16259 return DW_ORD_row_major
;
16262 switch (cu
->language_defn
->la_array_ordering
)
16264 case array_column_major
:
16265 return DW_ORD_col_major
;
16266 case array_row_major
:
16268 return DW_ORD_row_major
;
16272 /* Extract all information from a DW_TAG_set_type DIE and put it in
16273 the DIE's type field. */
16275 static struct type
*
16276 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16278 struct type
*domain_type
, *set_type
;
16279 struct attribute
*attr
;
16281 domain_type
= die_type (die
, cu
);
16283 /* The die_type call above may have already set the type for this DIE. */
16284 set_type
= get_die_type (die
, cu
);
16288 set_type
= create_set_type (NULL
, domain_type
);
16290 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16291 if (attr
!= nullptr)
16292 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16294 maybe_set_alignment (cu
, die
, set_type
);
16296 return set_die_type (die
, set_type
, cu
);
16299 /* A helper for read_common_block that creates a locexpr baton.
16300 SYM is the symbol which we are marking as computed.
16301 COMMON_DIE is the DIE for the common block.
16302 COMMON_LOC is the location expression attribute for the common
16304 MEMBER_LOC is the location expression attribute for the particular
16305 member of the common block that we are processing.
16306 CU is the CU from which the above come. */
16309 mark_common_block_symbol_computed (struct symbol
*sym
,
16310 struct die_info
*common_die
,
16311 struct attribute
*common_loc
,
16312 struct attribute
*member_loc
,
16313 struct dwarf2_cu
*cu
)
16315 struct dwarf2_per_objfile
*dwarf2_per_objfile
16316 = cu
->per_cu
->dwarf2_per_objfile
;
16317 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16318 struct dwarf2_locexpr_baton
*baton
;
16320 unsigned int cu_off
;
16321 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16322 LONGEST offset
= 0;
16324 gdb_assert (common_loc
&& member_loc
);
16325 gdb_assert (common_loc
->form_is_block ());
16326 gdb_assert (member_loc
->form_is_block ()
16327 || member_loc
->form_is_constant ());
16329 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16330 baton
->per_cu
= cu
->per_cu
;
16331 gdb_assert (baton
->per_cu
);
16333 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16335 if (member_loc
->form_is_constant ())
16337 offset
= member_loc
->constant_value (0);
16338 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16341 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16343 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16346 *ptr
++ = DW_OP_call4
;
16347 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16348 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16351 if (member_loc
->form_is_constant ())
16353 *ptr
++ = DW_OP_addr
;
16354 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16355 ptr
+= cu
->header
.addr_size
;
16359 /* We have to copy the data here, because DW_OP_call4 will only
16360 use a DW_AT_location attribute. */
16361 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16362 ptr
+= DW_BLOCK (member_loc
)->size
;
16365 *ptr
++ = DW_OP_plus
;
16366 gdb_assert (ptr
- baton
->data
== baton
->size
);
16368 SYMBOL_LOCATION_BATON (sym
) = baton
;
16369 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16372 /* Create appropriate locally-scoped variables for all the
16373 DW_TAG_common_block entries. Also create a struct common_block
16374 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16375 is used to separate the common blocks name namespace from regular
16379 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16381 struct attribute
*attr
;
16383 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16384 if (attr
!= nullptr)
16386 /* Support the .debug_loc offsets. */
16387 if (attr
->form_is_block ())
16391 else if (attr
->form_is_section_offset ())
16393 dwarf2_complex_location_expr_complaint ();
16398 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16399 "common block member");
16404 if (die
->child
!= NULL
)
16406 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16407 struct die_info
*child_die
;
16408 size_t n_entries
= 0, size
;
16409 struct common_block
*common_block
;
16410 struct symbol
*sym
;
16412 for (child_die
= die
->child
;
16413 child_die
&& child_die
->tag
;
16414 child_die
= child_die
->sibling
)
16417 size
= (sizeof (struct common_block
)
16418 + (n_entries
- 1) * sizeof (struct symbol
*));
16420 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16422 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16423 common_block
->n_entries
= 0;
16425 for (child_die
= die
->child
;
16426 child_die
&& child_die
->tag
;
16427 child_die
= child_die
->sibling
)
16429 /* Create the symbol in the DW_TAG_common_block block in the current
16431 sym
= new_symbol (child_die
, NULL
, cu
);
16434 struct attribute
*member_loc
;
16436 common_block
->contents
[common_block
->n_entries
++] = sym
;
16438 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16442 /* GDB has handled this for a long time, but it is
16443 not specified by DWARF. It seems to have been
16444 emitted by gfortran at least as recently as:
16445 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16446 complaint (_("Variable in common block has "
16447 "DW_AT_data_member_location "
16448 "- DIE at %s [in module %s]"),
16449 sect_offset_str (child_die
->sect_off
),
16450 objfile_name (objfile
));
16452 if (member_loc
->form_is_section_offset ())
16453 dwarf2_complex_location_expr_complaint ();
16454 else if (member_loc
->form_is_constant ()
16455 || member_loc
->form_is_block ())
16457 if (attr
!= nullptr)
16458 mark_common_block_symbol_computed (sym
, die
, attr
,
16462 dwarf2_complex_location_expr_complaint ();
16467 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16468 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16472 /* Create a type for a C++ namespace. */
16474 static struct type
*
16475 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16477 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16478 const char *previous_prefix
, *name
;
16482 /* For extensions, reuse the type of the original namespace. */
16483 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16485 struct die_info
*ext_die
;
16486 struct dwarf2_cu
*ext_cu
= cu
;
16488 ext_die
= dwarf2_extension (die
, &ext_cu
);
16489 type
= read_type_die (ext_die
, ext_cu
);
16491 /* EXT_CU may not be the same as CU.
16492 Ensure TYPE is recorded with CU in die_type_hash. */
16493 return set_die_type (die
, type
, cu
);
16496 name
= namespace_name (die
, &is_anonymous
, cu
);
16498 /* Now build the name of the current namespace. */
16500 previous_prefix
= determine_prefix (die
, cu
);
16501 if (previous_prefix
[0] != '\0')
16502 name
= typename_concat (&objfile
->objfile_obstack
,
16503 previous_prefix
, name
, 0, cu
);
16505 /* Create the type. */
16506 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16508 return set_die_type (die
, type
, cu
);
16511 /* Read a namespace scope. */
16514 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16516 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16519 /* Add a symbol associated to this if we haven't seen the namespace
16520 before. Also, add a using directive if it's an anonymous
16523 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16527 type
= read_type_die (die
, cu
);
16528 new_symbol (die
, type
, cu
);
16530 namespace_name (die
, &is_anonymous
, cu
);
16533 const char *previous_prefix
= determine_prefix (die
, cu
);
16535 std::vector
<const char *> excludes
;
16536 add_using_directive (using_directives (cu
),
16537 previous_prefix
, type
->name (), NULL
,
16538 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16542 if (die
->child
!= NULL
)
16544 struct die_info
*child_die
= die
->child
;
16546 while (child_die
&& child_die
->tag
)
16548 process_die (child_die
, cu
);
16549 child_die
= child_die
->sibling
;
16554 /* Read a Fortran module as type. This DIE can be only a declaration used for
16555 imported module. Still we need that type as local Fortran "use ... only"
16556 declaration imports depend on the created type in determine_prefix. */
16558 static struct type
*
16559 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16561 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16562 const char *module_name
;
16565 module_name
= dwarf2_name (die
, cu
);
16566 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16568 return set_die_type (die
, type
, cu
);
16571 /* Read a Fortran module. */
16574 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16576 struct die_info
*child_die
= die
->child
;
16579 type
= read_type_die (die
, cu
);
16580 new_symbol (die
, type
, cu
);
16582 while (child_die
&& child_die
->tag
)
16584 process_die (child_die
, cu
);
16585 child_die
= child_die
->sibling
;
16589 /* Return the name of the namespace represented by DIE. Set
16590 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16593 static const char *
16594 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16596 struct die_info
*current_die
;
16597 const char *name
= NULL
;
16599 /* Loop through the extensions until we find a name. */
16601 for (current_die
= die
;
16602 current_die
!= NULL
;
16603 current_die
= dwarf2_extension (die
, &cu
))
16605 /* We don't use dwarf2_name here so that we can detect the absence
16606 of a name -> anonymous namespace. */
16607 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16613 /* Is it an anonymous namespace? */
16615 *is_anonymous
= (name
== NULL
);
16617 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16622 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16623 the user defined type vector. */
16625 static struct type
*
16626 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16628 struct gdbarch
*gdbarch
16629 = cu
->per_cu
->dwarf2_per_objfile
->objfile
->arch ();
16630 struct comp_unit_head
*cu_header
= &cu
->header
;
16632 struct attribute
*attr_byte_size
;
16633 struct attribute
*attr_address_class
;
16634 int byte_size
, addr_class
;
16635 struct type
*target_type
;
16637 target_type
= die_type (die
, cu
);
16639 /* The die_type call above may have already set the type for this DIE. */
16640 type
= get_die_type (die
, cu
);
16644 type
= lookup_pointer_type (target_type
);
16646 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16647 if (attr_byte_size
)
16648 byte_size
= DW_UNSND (attr_byte_size
);
16650 byte_size
= cu_header
->addr_size
;
16652 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16653 if (attr_address_class
)
16654 addr_class
= DW_UNSND (attr_address_class
);
16656 addr_class
= DW_ADDR_none
;
16658 ULONGEST alignment
= get_alignment (cu
, die
);
16660 /* If the pointer size, alignment, or address class is different
16661 than the default, create a type variant marked as such and set
16662 the length accordingly. */
16663 if (TYPE_LENGTH (type
) != byte_size
16664 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16665 && alignment
!= TYPE_RAW_ALIGN (type
))
16666 || addr_class
!= DW_ADDR_none
)
16668 if (gdbarch_address_class_type_flags_p (gdbarch
))
16672 type_flags
= gdbarch_address_class_type_flags
16673 (gdbarch
, byte_size
, addr_class
);
16674 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16676 type
= make_type_with_address_space (type
, type_flags
);
16678 else if (TYPE_LENGTH (type
) != byte_size
)
16680 complaint (_("invalid pointer size %d"), byte_size
);
16682 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16684 complaint (_("Invalid DW_AT_alignment"
16685 " - DIE at %s [in module %s]"),
16686 sect_offset_str (die
->sect_off
),
16687 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16691 /* Should we also complain about unhandled address classes? */
16695 TYPE_LENGTH (type
) = byte_size
;
16696 set_type_align (type
, alignment
);
16697 return set_die_type (die
, type
, cu
);
16700 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16701 the user defined type vector. */
16703 static struct type
*
16704 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16707 struct type
*to_type
;
16708 struct type
*domain
;
16710 to_type
= die_type (die
, cu
);
16711 domain
= die_containing_type (die
, cu
);
16713 /* The calls above may have already set the type for this DIE. */
16714 type
= get_die_type (die
, cu
);
16718 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16719 type
= lookup_methodptr_type (to_type
);
16720 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16722 struct type
*new_type
16723 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16725 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16726 to_type
->fields (), to_type
->num_fields (),
16727 TYPE_VARARGS (to_type
));
16728 type
= lookup_methodptr_type (new_type
);
16731 type
= lookup_memberptr_type (to_type
, domain
);
16733 return set_die_type (die
, type
, cu
);
16736 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16737 the user defined type vector. */
16739 static struct type
*
16740 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16741 enum type_code refcode
)
16743 struct comp_unit_head
*cu_header
= &cu
->header
;
16744 struct type
*type
, *target_type
;
16745 struct attribute
*attr
;
16747 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16749 target_type
= die_type (die
, cu
);
16751 /* The die_type call above may have already set the type for this DIE. */
16752 type
= get_die_type (die
, cu
);
16756 type
= lookup_reference_type (target_type
, refcode
);
16757 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16758 if (attr
!= nullptr)
16760 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16764 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16766 maybe_set_alignment (cu
, die
, type
);
16767 return set_die_type (die
, type
, cu
);
16770 /* Add the given cv-qualifiers to the element type of the array. GCC
16771 outputs DWARF type qualifiers that apply to an array, not the
16772 element type. But GDB relies on the array element type to carry
16773 the cv-qualifiers. This mimics section 6.7.3 of the C99
16776 static struct type
*
16777 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16778 struct type
*base_type
, int cnst
, int voltl
)
16780 struct type
*el_type
, *inner_array
;
16782 base_type
= copy_type (base_type
);
16783 inner_array
= base_type
;
16785 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16787 TYPE_TARGET_TYPE (inner_array
) =
16788 copy_type (TYPE_TARGET_TYPE (inner_array
));
16789 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16792 el_type
= TYPE_TARGET_TYPE (inner_array
);
16793 cnst
|= TYPE_CONST (el_type
);
16794 voltl
|= TYPE_VOLATILE (el_type
);
16795 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16797 return set_die_type (die
, base_type
, cu
);
16800 static struct type
*
16801 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16803 struct type
*base_type
, *cv_type
;
16805 base_type
= die_type (die
, cu
);
16807 /* The die_type call above may have already set the type for this DIE. */
16808 cv_type
= get_die_type (die
, cu
);
16812 /* In case the const qualifier is applied to an array type, the element type
16813 is so qualified, not the array type (section 6.7.3 of C99). */
16814 if (base_type
->code () == TYPE_CODE_ARRAY
)
16815 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16817 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16818 return set_die_type (die
, cv_type
, cu
);
16821 static struct type
*
16822 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16824 struct type
*base_type
, *cv_type
;
16826 base_type
= die_type (die
, cu
);
16828 /* The die_type call above may have already set the type for this DIE. */
16829 cv_type
= get_die_type (die
, cu
);
16833 /* In case the volatile qualifier is applied to an array type, the
16834 element type is so qualified, not the array type (section 6.7.3
16836 if (base_type
->code () == TYPE_CODE_ARRAY
)
16837 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16839 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16840 return set_die_type (die
, cv_type
, cu
);
16843 /* Handle DW_TAG_restrict_type. */
16845 static struct type
*
16846 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16848 struct type
*base_type
, *cv_type
;
16850 base_type
= die_type (die
, cu
);
16852 /* The die_type call above may have already set the type for this DIE. */
16853 cv_type
= get_die_type (die
, cu
);
16857 cv_type
= make_restrict_type (base_type
);
16858 return set_die_type (die
, cv_type
, cu
);
16861 /* Handle DW_TAG_atomic_type. */
16863 static struct type
*
16864 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16866 struct type
*base_type
, *cv_type
;
16868 base_type
= die_type (die
, cu
);
16870 /* The die_type call above may have already set the type for this DIE. */
16871 cv_type
= get_die_type (die
, cu
);
16875 cv_type
= make_atomic_type (base_type
);
16876 return set_die_type (die
, cv_type
, cu
);
16879 /* Extract all information from a DW_TAG_string_type DIE and add to
16880 the user defined type vector. It isn't really a user defined type,
16881 but it behaves like one, with other DIE's using an AT_user_def_type
16882 attribute to reference it. */
16884 static struct type
*
16885 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16887 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16888 struct gdbarch
*gdbarch
= objfile
->arch ();
16889 struct type
*type
, *range_type
, *index_type
, *char_type
;
16890 struct attribute
*attr
;
16891 struct dynamic_prop prop
;
16892 bool length_is_constant
= true;
16895 /* There are a couple of places where bit sizes might be made use of
16896 when parsing a DW_TAG_string_type, however, no producer that we know
16897 of make use of these. Handling bit sizes that are a multiple of the
16898 byte size is easy enough, but what about other bit sizes? Lets deal
16899 with that problem when we have to. Warn about these attributes being
16900 unsupported, then parse the type and ignore them like we always
16902 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16903 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16905 static bool warning_printed
= false;
16906 if (!warning_printed
)
16908 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16909 "currently supported on DW_TAG_string_type."));
16910 warning_printed
= true;
16914 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16915 if (attr
!= nullptr && !attr
->form_is_constant ())
16917 /* The string length describes the location at which the length of
16918 the string can be found. The size of the length field can be
16919 specified with one of the attributes below. */
16920 struct type
*prop_type
;
16921 struct attribute
*len
16922 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16923 if (len
== nullptr)
16924 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16925 if (len
!= nullptr && len
->form_is_constant ())
16927 /* Pass 0 as the default as we know this attribute is constant
16928 and the default value will not be returned. */
16929 LONGEST sz
= len
->constant_value (0);
16930 prop_type
= cu
->per_cu
->int_type (sz
, true);
16934 /* If the size is not specified then we assume it is the size of
16935 an address on this target. */
16936 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16939 /* Convert the attribute into a dynamic property. */
16940 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16943 length_is_constant
= false;
16945 else if (attr
!= nullptr)
16947 /* This DW_AT_string_length just contains the length with no
16948 indirection. There's no need to create a dynamic property in this
16949 case. Pass 0 for the default value as we know it will not be
16950 returned in this case. */
16951 length
= attr
->constant_value (0);
16953 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16955 /* We don't currently support non-constant byte sizes for strings. */
16956 length
= attr
->constant_value (1);
16960 /* Use 1 as a fallback length if we have nothing else. */
16964 index_type
= objfile_type (objfile
)->builtin_int
;
16965 if (length_is_constant
)
16966 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16969 struct dynamic_prop low_bound
;
16971 low_bound
.kind
= PROP_CONST
;
16972 low_bound
.data
.const_val
= 1;
16973 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16975 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16976 type
= create_string_type (NULL
, char_type
, range_type
);
16978 return set_die_type (die
, type
, cu
);
16981 /* Assuming that DIE corresponds to a function, returns nonzero
16982 if the function is prototyped. */
16985 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16987 struct attribute
*attr
;
16989 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16990 if (attr
&& (DW_UNSND (attr
) != 0))
16993 /* The DWARF standard implies that the DW_AT_prototyped attribute
16994 is only meaningful for C, but the concept also extends to other
16995 languages that allow unprototyped functions (Eg: Objective C).
16996 For all other languages, assume that functions are always
16998 if (cu
->language
!= language_c
16999 && cu
->language
!= language_objc
17000 && cu
->language
!= language_opencl
)
17003 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17004 prototyped and unprototyped functions; default to prototyped,
17005 since that is more common in modern code (and RealView warns
17006 about unprototyped functions). */
17007 if (producer_is_realview (cu
->producer
))
17013 /* Handle DIES due to C code like:
17017 int (*funcp)(int a, long l);
17021 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17023 static struct type
*
17024 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17026 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17027 struct type
*type
; /* Type that this function returns. */
17028 struct type
*ftype
; /* Function that returns above type. */
17029 struct attribute
*attr
;
17031 type
= die_type (die
, cu
);
17033 /* The die_type call above may have already set the type for this DIE. */
17034 ftype
= get_die_type (die
, cu
);
17038 ftype
= lookup_function_type (type
);
17040 if (prototyped_function_p (die
, cu
))
17041 TYPE_PROTOTYPED (ftype
) = 1;
17043 /* Store the calling convention in the type if it's available in
17044 the subroutine die. Otherwise set the calling convention to
17045 the default value DW_CC_normal. */
17046 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17047 if (attr
!= nullptr
17048 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17049 TYPE_CALLING_CONVENTION (ftype
)
17050 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17051 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17052 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17054 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17056 /* Record whether the function returns normally to its caller or not
17057 if the DWARF producer set that information. */
17058 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17059 if (attr
&& (DW_UNSND (attr
) != 0))
17060 TYPE_NO_RETURN (ftype
) = 1;
17062 /* We need to add the subroutine type to the die immediately so
17063 we don't infinitely recurse when dealing with parameters
17064 declared as the same subroutine type. */
17065 set_die_type (die
, ftype
, cu
);
17067 if (die
->child
!= NULL
)
17069 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17070 struct die_info
*child_die
;
17071 int nparams
, iparams
;
17073 /* Count the number of parameters.
17074 FIXME: GDB currently ignores vararg functions, but knows about
17075 vararg member functions. */
17077 child_die
= die
->child
;
17078 while (child_die
&& child_die
->tag
)
17080 if (child_die
->tag
== DW_TAG_formal_parameter
)
17082 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17083 TYPE_VARARGS (ftype
) = 1;
17084 child_die
= child_die
->sibling
;
17087 /* Allocate storage for parameters and fill them in. */
17088 ftype
->set_num_fields (nparams
);
17090 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17092 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17093 even if we error out during the parameters reading below. */
17094 for (iparams
= 0; iparams
< nparams
; iparams
++)
17095 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17098 child_die
= die
->child
;
17099 while (child_die
&& child_die
->tag
)
17101 if (child_die
->tag
== DW_TAG_formal_parameter
)
17103 struct type
*arg_type
;
17105 /* DWARF version 2 has no clean way to discern C++
17106 static and non-static member functions. G++ helps
17107 GDB by marking the first parameter for non-static
17108 member functions (which is the this pointer) as
17109 artificial. We pass this information to
17110 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17112 DWARF version 3 added DW_AT_object_pointer, which GCC
17113 4.5 does not yet generate. */
17114 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17115 if (attr
!= nullptr)
17116 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17118 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17119 arg_type
= die_type (child_die
, cu
);
17121 /* RealView does not mark THIS as const, which the testsuite
17122 expects. GCC marks THIS as const in method definitions,
17123 but not in the class specifications (GCC PR 43053). */
17124 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17125 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17128 struct dwarf2_cu
*arg_cu
= cu
;
17129 const char *name
= dwarf2_name (child_die
, cu
);
17131 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17132 if (attr
!= nullptr)
17134 /* If the compiler emits this, use it. */
17135 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17138 else if (name
&& strcmp (name
, "this") == 0)
17139 /* Function definitions will have the argument names. */
17141 else if (name
== NULL
&& iparams
== 0)
17142 /* Declarations may not have the names, so like
17143 elsewhere in GDB, assume an artificial first
17144 argument is "this". */
17148 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17152 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17155 child_die
= child_die
->sibling
;
17162 static struct type
*
17163 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17165 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17166 const char *name
= NULL
;
17167 struct type
*this_type
, *target_type
;
17169 name
= dwarf2_full_name (NULL
, die
, cu
);
17170 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17171 TYPE_TARGET_STUB (this_type
) = 1;
17172 set_die_type (die
, this_type
, cu
);
17173 target_type
= die_type (die
, cu
);
17174 if (target_type
!= this_type
)
17175 TYPE_TARGET_TYPE (this_type
) = target_type
;
17178 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17179 spec and cause infinite loops in GDB. */
17180 complaint (_("Self-referential DW_TAG_typedef "
17181 "- DIE at %s [in module %s]"),
17182 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17183 TYPE_TARGET_TYPE (this_type
) = NULL
;
17187 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17188 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17189 Handle these by just returning the target type, rather than
17190 constructing an anonymous typedef type and trying to handle this
17192 set_die_type (die
, target_type
, cu
);
17193 return target_type
;
17198 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17199 (which may be different from NAME) to the architecture back-end to allow
17200 it to guess the correct format if necessary. */
17202 static struct type
*
17203 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17204 const char *name_hint
, enum bfd_endian byte_order
)
17206 struct gdbarch
*gdbarch
= objfile
->arch ();
17207 const struct floatformat
**format
;
17210 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17212 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17214 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17219 /* Allocate an integer type of size BITS and name NAME. */
17221 static struct type
*
17222 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17223 int bits
, int unsigned_p
, const char *name
)
17227 /* Versions of Intel's C Compiler generate an integer type called "void"
17228 instead of using DW_TAG_unspecified_type. This has been seen on
17229 at least versions 14, 17, and 18. */
17230 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17231 && strcmp (name
, "void") == 0)
17232 type
= objfile_type (objfile
)->builtin_void
;
17234 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17239 /* Initialise and return a floating point type of size BITS suitable for
17240 use as a component of a complex number. The NAME_HINT is passed through
17241 when initialising the floating point type and is the name of the complex
17244 As DWARF doesn't currently provide an explicit name for the components
17245 of a complex number, but it can be helpful to have these components
17246 named, we try to select a suitable name based on the size of the
17248 static struct type
*
17249 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17250 struct objfile
*objfile
,
17251 int bits
, const char *name_hint
,
17252 enum bfd_endian byte_order
)
17254 gdbarch
*gdbarch
= objfile
->arch ();
17255 struct type
*tt
= nullptr;
17257 /* Try to find a suitable floating point builtin type of size BITS.
17258 We're going to use the name of this type as the name for the complex
17259 target type that we are about to create. */
17260 switch (cu
->language
)
17262 case language_fortran
:
17266 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17269 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17271 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17273 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17281 tt
= builtin_type (gdbarch
)->builtin_float
;
17284 tt
= builtin_type (gdbarch
)->builtin_double
;
17286 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17288 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17294 /* If the type we found doesn't match the size we were looking for, then
17295 pretend we didn't find a type at all, the complex target type we
17296 create will then be nameless. */
17297 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17300 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17301 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17304 /* Find a representation of a given base type and install
17305 it in the TYPE field of the die. */
17307 static struct type
*
17308 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17310 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17312 struct attribute
*attr
;
17313 int encoding
= 0, bits
= 0;
17317 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17318 if (attr
!= nullptr)
17319 encoding
= DW_UNSND (attr
);
17320 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17321 if (attr
!= nullptr)
17322 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17323 name
= dwarf2_name (die
, cu
);
17325 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17327 arch
= objfile
->arch ();
17328 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17330 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17333 int endianity
= DW_UNSND (attr
);
17338 byte_order
= BFD_ENDIAN_BIG
;
17340 case DW_END_little
:
17341 byte_order
= BFD_ENDIAN_LITTLE
;
17344 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17351 case DW_ATE_address
:
17352 /* Turn DW_ATE_address into a void * pointer. */
17353 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17354 type
= init_pointer_type (objfile
, bits
, name
, type
);
17356 case DW_ATE_boolean
:
17357 type
= init_boolean_type (objfile
, bits
, 1, name
);
17359 case DW_ATE_complex_float
:
17360 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17362 if (type
->code () == TYPE_CODE_ERROR
)
17364 if (name
== nullptr)
17366 struct obstack
*obstack
17367 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17368 name
= obconcat (obstack
, "_Complex ", type
->name (),
17371 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17374 type
= init_complex_type (name
, type
);
17376 case DW_ATE_decimal_float
:
17377 type
= init_decfloat_type (objfile
, bits
, name
);
17380 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17382 case DW_ATE_signed
:
17383 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17385 case DW_ATE_unsigned
:
17386 if (cu
->language
== language_fortran
17388 && startswith (name
, "character("))
17389 type
= init_character_type (objfile
, bits
, 1, name
);
17391 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17393 case DW_ATE_signed_char
:
17394 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17395 || cu
->language
== language_pascal
17396 || cu
->language
== language_fortran
)
17397 type
= init_character_type (objfile
, bits
, 0, name
);
17399 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17401 case DW_ATE_unsigned_char
:
17402 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17403 || cu
->language
== language_pascal
17404 || cu
->language
== language_fortran
17405 || cu
->language
== language_rust
)
17406 type
= init_character_type (objfile
, bits
, 1, name
);
17408 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17413 type
= builtin_type (arch
)->builtin_char16
;
17414 else if (bits
== 32)
17415 type
= builtin_type (arch
)->builtin_char32
;
17418 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17420 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17422 return set_die_type (die
, type
, cu
);
17427 complaint (_("unsupported DW_AT_encoding: '%s'"),
17428 dwarf_type_encoding_name (encoding
));
17429 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17433 if (name
&& strcmp (name
, "char") == 0)
17434 TYPE_NOSIGN (type
) = 1;
17436 maybe_set_alignment (cu
, die
, type
);
17438 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17440 return set_die_type (die
, type
, cu
);
17443 /* Parse dwarf attribute if it's a block, reference or constant and put the
17444 resulting value of the attribute into struct bound_prop.
17445 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17448 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17449 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17450 struct type
*default_type
)
17452 struct dwarf2_property_baton
*baton
;
17453 struct obstack
*obstack
17454 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17456 gdb_assert (default_type
!= NULL
);
17458 if (attr
== NULL
|| prop
== NULL
)
17461 if (attr
->form_is_block ())
17463 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17464 baton
->property_type
= default_type
;
17465 baton
->locexpr
.per_cu
= cu
->per_cu
;
17466 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17467 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17468 switch (attr
->name
)
17470 case DW_AT_string_length
:
17471 baton
->locexpr
.is_reference
= true;
17474 baton
->locexpr
.is_reference
= false;
17477 prop
->data
.baton
= baton
;
17478 prop
->kind
= PROP_LOCEXPR
;
17479 gdb_assert (prop
->data
.baton
!= NULL
);
17481 else if (attr
->form_is_ref ())
17483 struct dwarf2_cu
*target_cu
= cu
;
17484 struct die_info
*target_die
;
17485 struct attribute
*target_attr
;
17487 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17488 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17489 if (target_attr
== NULL
)
17490 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17492 if (target_attr
== NULL
)
17495 switch (target_attr
->name
)
17497 case DW_AT_location
:
17498 if (target_attr
->form_is_section_offset ())
17500 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17501 baton
->property_type
= die_type (target_die
, target_cu
);
17502 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17503 prop
->data
.baton
= baton
;
17504 prop
->kind
= PROP_LOCLIST
;
17505 gdb_assert (prop
->data
.baton
!= NULL
);
17507 else if (target_attr
->form_is_block ())
17509 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17510 baton
->property_type
= die_type (target_die
, target_cu
);
17511 baton
->locexpr
.per_cu
= cu
->per_cu
;
17512 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17513 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17514 baton
->locexpr
.is_reference
= true;
17515 prop
->data
.baton
= baton
;
17516 prop
->kind
= PROP_LOCEXPR
;
17517 gdb_assert (prop
->data
.baton
!= NULL
);
17521 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17522 "dynamic property");
17526 case DW_AT_data_member_location
:
17530 if (!handle_data_member_location (target_die
, target_cu
,
17534 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17535 baton
->property_type
= read_type_die (target_die
->parent
,
17537 baton
->offset_info
.offset
= offset
;
17538 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17539 prop
->data
.baton
= baton
;
17540 prop
->kind
= PROP_ADDR_OFFSET
;
17545 else if (attr
->form_is_constant ())
17547 prop
->data
.const_val
= attr
->constant_value (0);
17548 prop
->kind
= PROP_CONST
;
17552 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17553 dwarf2_name (die
, cu
));
17563 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17565 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17566 struct type
*int_type
;
17568 /* Helper macro to examine the various builtin types. */
17569 #define TRY_TYPE(F) \
17570 int_type = (unsigned_p \
17571 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17572 : objfile_type (objfile)->builtin_ ## F); \
17573 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17580 TRY_TYPE (long_long
);
17584 gdb_assert_not_reached ("unable to find suitable integer type");
17590 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17592 int addr_size
= this->addr_size ();
17593 return int_type (addr_size
, unsigned_p
);
17596 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17597 present (which is valid) then compute the default type based on the
17598 compilation units address size. */
17600 static struct type
*
17601 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17603 struct type
*index_type
= die_type (die
, cu
);
17605 /* Dwarf-2 specifications explicitly allows to create subrange types
17606 without specifying a base type.
17607 In that case, the base type must be set to the type of
17608 the lower bound, upper bound or count, in that order, if any of these
17609 three attributes references an object that has a type.
17610 If no base type is found, the Dwarf-2 specifications say that
17611 a signed integer type of size equal to the size of an address should
17613 For the following C code: `extern char gdb_int [];'
17614 GCC produces an empty range DIE.
17615 FIXME: muller/2010-05-28: Possible references to object for low bound,
17616 high bound or count are not yet handled by this code. */
17617 if (index_type
->code () == TYPE_CODE_VOID
)
17618 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17623 /* Read the given DW_AT_subrange DIE. */
17625 static struct type
*
17626 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17628 struct type
*base_type
, *orig_base_type
;
17629 struct type
*range_type
;
17630 struct attribute
*attr
;
17631 struct dynamic_prop low
, high
;
17632 int low_default_is_valid
;
17633 int high_bound_is_count
= 0;
17635 ULONGEST negative_mask
;
17637 orig_base_type
= read_subrange_index_type (die
, cu
);
17639 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17640 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17641 creating the range type, but we use the result of check_typedef
17642 when examining properties of the type. */
17643 base_type
= check_typedef (orig_base_type
);
17645 /* The die_type call above may have already set the type for this DIE. */
17646 range_type
= get_die_type (die
, cu
);
17650 low
.kind
= PROP_CONST
;
17651 high
.kind
= PROP_CONST
;
17652 high
.data
.const_val
= 0;
17654 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17655 omitting DW_AT_lower_bound. */
17656 switch (cu
->language
)
17659 case language_cplus
:
17660 low
.data
.const_val
= 0;
17661 low_default_is_valid
= 1;
17663 case language_fortran
:
17664 low
.data
.const_val
= 1;
17665 low_default_is_valid
= 1;
17668 case language_objc
:
17669 case language_rust
:
17670 low
.data
.const_val
= 0;
17671 low_default_is_valid
= (cu
->header
.version
>= 4);
17675 case language_pascal
:
17676 low
.data
.const_val
= 1;
17677 low_default_is_valid
= (cu
->header
.version
>= 4);
17680 low
.data
.const_val
= 0;
17681 low_default_is_valid
= 0;
17685 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17686 if (attr
!= nullptr)
17687 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17688 else if (!low_default_is_valid
)
17689 complaint (_("Missing DW_AT_lower_bound "
17690 "- DIE at %s [in module %s]"),
17691 sect_offset_str (die
->sect_off
),
17692 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17694 struct attribute
*attr_ub
, *attr_count
;
17695 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17696 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17698 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17699 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17701 /* If bounds are constant do the final calculation here. */
17702 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17703 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17705 high_bound_is_count
= 1;
17709 if (attr_ub
!= NULL
)
17710 complaint (_("Unresolved DW_AT_upper_bound "
17711 "- DIE at %s [in module %s]"),
17712 sect_offset_str (die
->sect_off
),
17713 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17714 if (attr_count
!= NULL
)
17715 complaint (_("Unresolved DW_AT_count "
17716 "- DIE at %s [in module %s]"),
17717 sect_offset_str (die
->sect_off
),
17718 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17723 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17724 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17725 bias
= bias_attr
->constant_value (0);
17727 /* Normally, the DWARF producers are expected to use a signed
17728 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17729 But this is unfortunately not always the case, as witnessed
17730 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17731 is used instead. To work around that ambiguity, we treat
17732 the bounds as signed, and thus sign-extend their values, when
17733 the base type is signed. */
17735 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17736 if (low
.kind
== PROP_CONST
17737 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17738 low
.data
.const_val
|= negative_mask
;
17739 if (high
.kind
== PROP_CONST
17740 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17741 high
.data
.const_val
|= negative_mask
;
17743 /* Check for bit and byte strides. */
17744 struct dynamic_prop byte_stride_prop
;
17745 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17746 if (attr_byte_stride
!= nullptr)
17748 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17749 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17753 struct dynamic_prop bit_stride_prop
;
17754 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17755 if (attr_bit_stride
!= nullptr)
17757 /* It only makes sense to have either a bit or byte stride. */
17758 if (attr_byte_stride
!= nullptr)
17760 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17761 "- DIE at %s [in module %s]"),
17762 sect_offset_str (die
->sect_off
),
17763 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17764 attr_bit_stride
= nullptr;
17768 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17769 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17774 if (attr_byte_stride
!= nullptr
17775 || attr_bit_stride
!= nullptr)
17777 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17778 struct dynamic_prop
*stride
17779 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17782 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17783 &high
, bias
, stride
, byte_stride_p
);
17786 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17788 if (high_bound_is_count
)
17789 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17791 /* Ada expects an empty array on no boundary attributes. */
17792 if (attr
== NULL
&& cu
->language
!= language_ada
)
17793 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17795 name
= dwarf2_name (die
, cu
);
17797 range_type
->set_name (name
);
17799 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17800 if (attr
!= nullptr)
17801 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17803 maybe_set_alignment (cu
, die
, range_type
);
17805 set_die_type (die
, range_type
, cu
);
17807 /* set_die_type should be already done. */
17808 set_descriptive_type (range_type
, die
, cu
);
17813 static struct type
*
17814 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17818 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17820 type
->set_name (dwarf2_name (die
, cu
));
17822 /* In Ada, an unspecified type is typically used when the description
17823 of the type is deferred to a different unit. When encountering
17824 such a type, we treat it as a stub, and try to resolve it later on,
17826 if (cu
->language
== language_ada
)
17827 TYPE_STUB (type
) = 1;
17829 return set_die_type (die
, type
, cu
);
17832 /* Read a single die and all its descendents. Set the die's sibling
17833 field to NULL; set other fields in the die correctly, and set all
17834 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17835 location of the info_ptr after reading all of those dies. PARENT
17836 is the parent of the die in question. */
17838 static struct die_info
*
17839 read_die_and_children (const struct die_reader_specs
*reader
,
17840 const gdb_byte
*info_ptr
,
17841 const gdb_byte
**new_info_ptr
,
17842 struct die_info
*parent
)
17844 struct die_info
*die
;
17845 const gdb_byte
*cur_ptr
;
17847 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17850 *new_info_ptr
= cur_ptr
;
17853 store_in_ref_table (die
, reader
->cu
);
17855 if (die
->has_children
)
17856 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17860 *new_info_ptr
= cur_ptr
;
17863 die
->sibling
= NULL
;
17864 die
->parent
= parent
;
17868 /* Read a die, all of its descendents, and all of its siblings; set
17869 all of the fields of all of the dies correctly. Arguments are as
17870 in read_die_and_children. */
17872 static struct die_info
*
17873 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17874 const gdb_byte
*info_ptr
,
17875 const gdb_byte
**new_info_ptr
,
17876 struct die_info
*parent
)
17878 struct die_info
*first_die
, *last_sibling
;
17879 const gdb_byte
*cur_ptr
;
17881 cur_ptr
= info_ptr
;
17882 first_die
= last_sibling
= NULL
;
17886 struct die_info
*die
17887 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17891 *new_info_ptr
= cur_ptr
;
17898 last_sibling
->sibling
= die
;
17900 last_sibling
= die
;
17904 /* Read a die, all of its descendents, and all of its siblings; set
17905 all of the fields of all of the dies correctly. Arguments are as
17906 in read_die_and_children.
17907 This the main entry point for reading a DIE and all its children. */
17909 static struct die_info
*
17910 read_die_and_siblings (const struct die_reader_specs
*reader
,
17911 const gdb_byte
*info_ptr
,
17912 const gdb_byte
**new_info_ptr
,
17913 struct die_info
*parent
)
17915 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17916 new_info_ptr
, parent
);
17918 if (dwarf_die_debug
)
17920 fprintf_unfiltered (gdb_stdlog
,
17921 "Read die from %s@0x%x of %s:\n",
17922 reader
->die_section
->get_name (),
17923 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17924 bfd_get_filename (reader
->abfd
));
17925 dump_die (die
, dwarf_die_debug
);
17931 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17933 The caller is responsible for filling in the extra attributes
17934 and updating (*DIEP)->num_attrs.
17935 Set DIEP to point to a newly allocated die with its information,
17936 except for its child, sibling, and parent fields. */
17938 static const gdb_byte
*
17939 read_full_die_1 (const struct die_reader_specs
*reader
,
17940 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17941 int num_extra_attrs
)
17943 unsigned int abbrev_number
, bytes_read
, i
;
17944 struct abbrev_info
*abbrev
;
17945 struct die_info
*die
;
17946 struct dwarf2_cu
*cu
= reader
->cu
;
17947 bfd
*abfd
= reader
->abfd
;
17949 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17950 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17951 info_ptr
+= bytes_read
;
17952 if (!abbrev_number
)
17958 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17960 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17962 bfd_get_filename (abfd
));
17964 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17965 die
->sect_off
= sect_off
;
17966 die
->tag
= abbrev
->tag
;
17967 die
->abbrev
= abbrev_number
;
17968 die
->has_children
= abbrev
->has_children
;
17970 /* Make the result usable.
17971 The caller needs to update num_attrs after adding the extra
17973 die
->num_attrs
= abbrev
->num_attrs
;
17975 std::vector
<int> indexes_that_need_reprocess
;
17976 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17978 bool need_reprocess
;
17980 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17981 info_ptr
, &need_reprocess
);
17982 if (need_reprocess
)
17983 indexes_that_need_reprocess
.push_back (i
);
17986 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17987 if (attr
!= nullptr)
17988 cu
->str_offsets_base
= DW_UNSND (attr
);
17990 attr
= die
->attr (DW_AT_loclists_base
);
17991 if (attr
!= nullptr)
17992 cu
->loclist_base
= DW_UNSND (attr
);
17994 auto maybe_addr_base
= die
->addr_base ();
17995 if (maybe_addr_base
.has_value ())
17996 cu
->addr_base
= *maybe_addr_base
;
17997 for (int index
: indexes_that_need_reprocess
)
17998 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18003 /* Read a die and all its attributes.
18004 Set DIEP to point to a newly allocated die with its information,
18005 except for its child, sibling, and parent fields. */
18007 static const gdb_byte
*
18008 read_full_die (const struct die_reader_specs
*reader
,
18009 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18011 const gdb_byte
*result
;
18013 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18015 if (dwarf_die_debug
)
18017 fprintf_unfiltered (gdb_stdlog
,
18018 "Read die from %s@0x%x of %s:\n",
18019 reader
->die_section
->get_name (),
18020 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18021 bfd_get_filename (reader
->abfd
));
18022 dump_die (*diep
, dwarf_die_debug
);
18029 /* Returns nonzero if TAG represents a type that we might generate a partial
18033 is_type_tag_for_partial (int tag
)
18038 /* Some types that would be reasonable to generate partial symbols for,
18039 that we don't at present. */
18040 case DW_TAG_array_type
:
18041 case DW_TAG_file_type
:
18042 case DW_TAG_ptr_to_member_type
:
18043 case DW_TAG_set_type
:
18044 case DW_TAG_string_type
:
18045 case DW_TAG_subroutine_type
:
18047 case DW_TAG_base_type
:
18048 case DW_TAG_class_type
:
18049 case DW_TAG_interface_type
:
18050 case DW_TAG_enumeration_type
:
18051 case DW_TAG_structure_type
:
18052 case DW_TAG_subrange_type
:
18053 case DW_TAG_typedef
:
18054 case DW_TAG_union_type
:
18061 /* Load all DIEs that are interesting for partial symbols into memory. */
18063 static struct partial_die_info
*
18064 load_partial_dies (const struct die_reader_specs
*reader
,
18065 const gdb_byte
*info_ptr
, int building_psymtab
)
18067 struct dwarf2_cu
*cu
= reader
->cu
;
18068 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18069 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18070 unsigned int bytes_read
;
18071 unsigned int load_all
= 0;
18072 int nesting_level
= 1;
18077 gdb_assert (cu
->per_cu
!= NULL
);
18078 if (cu
->per_cu
->load_all_dies
)
18082 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18086 &cu
->comp_unit_obstack
,
18087 hashtab_obstack_allocate
,
18088 dummy_obstack_deallocate
);
18092 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18094 /* A NULL abbrev means the end of a series of children. */
18095 if (abbrev
== NULL
)
18097 if (--nesting_level
== 0)
18100 info_ptr
+= bytes_read
;
18101 last_die
= parent_die
;
18102 parent_die
= parent_die
->die_parent
;
18106 /* Check for template arguments. We never save these; if
18107 they're seen, we just mark the parent, and go on our way. */
18108 if (parent_die
!= NULL
18109 && cu
->language
== language_cplus
18110 && (abbrev
->tag
== DW_TAG_template_type_param
18111 || abbrev
->tag
== DW_TAG_template_value_param
))
18113 parent_die
->has_template_arguments
= 1;
18117 /* We don't need a partial DIE for the template argument. */
18118 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18123 /* We only recurse into c++ subprograms looking for template arguments.
18124 Skip their other children. */
18126 && cu
->language
== language_cplus
18127 && parent_die
!= NULL
18128 && parent_die
->tag
== DW_TAG_subprogram
)
18130 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18134 /* Check whether this DIE is interesting enough to save. Normally
18135 we would not be interested in members here, but there may be
18136 later variables referencing them via DW_AT_specification (for
18137 static members). */
18139 && !is_type_tag_for_partial (abbrev
->tag
)
18140 && abbrev
->tag
!= DW_TAG_constant
18141 && abbrev
->tag
!= DW_TAG_enumerator
18142 && abbrev
->tag
!= DW_TAG_subprogram
18143 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18144 && abbrev
->tag
!= DW_TAG_lexical_block
18145 && abbrev
->tag
!= DW_TAG_variable
18146 && abbrev
->tag
!= DW_TAG_namespace
18147 && abbrev
->tag
!= DW_TAG_module
18148 && abbrev
->tag
!= DW_TAG_member
18149 && abbrev
->tag
!= DW_TAG_imported_unit
18150 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18152 /* Otherwise we skip to the next sibling, if any. */
18153 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18157 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18160 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18162 /* This two-pass algorithm for processing partial symbols has a
18163 high cost in cache pressure. Thus, handle some simple cases
18164 here which cover the majority of C partial symbols. DIEs
18165 which neither have specification tags in them, nor could have
18166 specification tags elsewhere pointing at them, can simply be
18167 processed and discarded.
18169 This segment is also optional; scan_partial_symbols and
18170 add_partial_symbol will handle these DIEs if we chain
18171 them in normally. When compilers which do not emit large
18172 quantities of duplicate debug information are more common,
18173 this code can probably be removed. */
18175 /* Any complete simple types at the top level (pretty much all
18176 of them, for a language without namespaces), can be processed
18178 if (parent_die
== NULL
18179 && pdi
.has_specification
== 0
18180 && pdi
.is_declaration
== 0
18181 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18182 || pdi
.tag
== DW_TAG_base_type
18183 || pdi
.tag
== DW_TAG_subrange_type
))
18185 if (building_psymtab
&& pdi
.name
!= NULL
)
18186 add_psymbol_to_list (pdi
.name
, false,
18187 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18188 psymbol_placement::STATIC
,
18189 0, cu
->language
, objfile
);
18190 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18194 /* The exception for DW_TAG_typedef with has_children above is
18195 a workaround of GCC PR debug/47510. In the case of this complaint
18196 type_name_or_error will error on such types later.
18198 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18199 it could not find the child DIEs referenced later, this is checked
18200 above. In correct DWARF DW_TAG_typedef should have no children. */
18202 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18203 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18204 "- DIE at %s [in module %s]"),
18205 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18207 /* If we're at the second level, and we're an enumerator, and
18208 our parent has no specification (meaning possibly lives in a
18209 namespace elsewhere), then we can add the partial symbol now
18210 instead of queueing it. */
18211 if (pdi
.tag
== DW_TAG_enumerator
18212 && parent_die
!= NULL
18213 && parent_die
->die_parent
== NULL
18214 && parent_die
->tag
== DW_TAG_enumeration_type
18215 && parent_die
->has_specification
== 0)
18217 if (pdi
.name
== NULL
)
18218 complaint (_("malformed enumerator DIE ignored"));
18219 else if (building_psymtab
)
18220 add_psymbol_to_list (pdi
.name
, false,
18221 VAR_DOMAIN
, LOC_CONST
, -1,
18222 cu
->language
== language_cplus
18223 ? psymbol_placement::GLOBAL
18224 : psymbol_placement::STATIC
,
18225 0, cu
->language
, objfile
);
18227 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18231 struct partial_die_info
*part_die
18232 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18234 /* We'll save this DIE so link it in. */
18235 part_die
->die_parent
= parent_die
;
18236 part_die
->die_sibling
= NULL
;
18237 part_die
->die_child
= NULL
;
18239 if (last_die
&& last_die
== parent_die
)
18240 last_die
->die_child
= part_die
;
18242 last_die
->die_sibling
= part_die
;
18244 last_die
= part_die
;
18246 if (first_die
== NULL
)
18247 first_die
= part_die
;
18249 /* Maybe add the DIE to the hash table. Not all DIEs that we
18250 find interesting need to be in the hash table, because we
18251 also have the parent/sibling/child chains; only those that we
18252 might refer to by offset later during partial symbol reading.
18254 For now this means things that might have be the target of a
18255 DW_AT_specification, DW_AT_abstract_origin, or
18256 DW_AT_extension. DW_AT_extension will refer only to
18257 namespaces; DW_AT_abstract_origin refers to functions (and
18258 many things under the function DIE, but we do not recurse
18259 into function DIEs during partial symbol reading) and
18260 possibly variables as well; DW_AT_specification refers to
18261 declarations. Declarations ought to have the DW_AT_declaration
18262 flag. It happens that GCC forgets to put it in sometimes, but
18263 only for functions, not for types.
18265 Adding more things than necessary to the hash table is harmless
18266 except for the performance cost. Adding too few will result in
18267 wasted time in find_partial_die, when we reread the compilation
18268 unit with load_all_dies set. */
18271 || abbrev
->tag
== DW_TAG_constant
18272 || abbrev
->tag
== DW_TAG_subprogram
18273 || abbrev
->tag
== DW_TAG_variable
18274 || abbrev
->tag
== DW_TAG_namespace
18275 || part_die
->is_declaration
)
18279 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18280 to_underlying (part_die
->sect_off
),
18285 /* For some DIEs we want to follow their children (if any). For C
18286 we have no reason to follow the children of structures; for other
18287 languages we have to, so that we can get at method physnames
18288 to infer fully qualified class names, for DW_AT_specification,
18289 and for C++ template arguments. For C++, we also look one level
18290 inside functions to find template arguments (if the name of the
18291 function does not already contain the template arguments).
18293 For Ada and Fortran, we need to scan the children of subprograms
18294 and lexical blocks as well because these languages allow the
18295 definition of nested entities that could be interesting for the
18296 debugger, such as nested subprograms for instance. */
18297 if (last_die
->has_children
18299 || last_die
->tag
== DW_TAG_namespace
18300 || last_die
->tag
== DW_TAG_module
18301 || last_die
->tag
== DW_TAG_enumeration_type
18302 || (cu
->language
== language_cplus
18303 && last_die
->tag
== DW_TAG_subprogram
18304 && (last_die
->name
== NULL
18305 || strchr (last_die
->name
, '<') == NULL
))
18306 || (cu
->language
!= language_c
18307 && (last_die
->tag
== DW_TAG_class_type
18308 || last_die
->tag
== DW_TAG_interface_type
18309 || last_die
->tag
== DW_TAG_structure_type
18310 || last_die
->tag
== DW_TAG_union_type
))
18311 || ((cu
->language
== language_ada
18312 || cu
->language
== language_fortran
)
18313 && (last_die
->tag
== DW_TAG_subprogram
18314 || last_die
->tag
== DW_TAG_lexical_block
))))
18317 parent_die
= last_die
;
18321 /* Otherwise we skip to the next sibling, if any. */
18322 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18324 /* Back to the top, do it again. */
18328 partial_die_info::partial_die_info (sect_offset sect_off_
,
18329 struct abbrev_info
*abbrev
)
18330 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18334 /* Read a minimal amount of information into the minimal die structure.
18335 INFO_PTR should point just after the initial uleb128 of a DIE. */
18338 partial_die_info::read (const struct die_reader_specs
*reader
,
18339 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18341 struct dwarf2_cu
*cu
= reader
->cu
;
18342 struct dwarf2_per_objfile
*dwarf2_per_objfile
18343 = cu
->per_cu
->dwarf2_per_objfile
;
18345 int has_low_pc_attr
= 0;
18346 int has_high_pc_attr
= 0;
18347 int high_pc_relative
= 0;
18349 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18352 bool need_reprocess
;
18353 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18354 info_ptr
, &need_reprocess
);
18355 /* String and address offsets that need to do the reprocessing have
18356 already been read at this point, so there is no need to wait until
18357 the loop terminates to do the reprocessing. */
18358 if (need_reprocess
)
18359 read_attribute_reprocess (reader
, &attr
);
18360 /* Store the data if it is of an attribute we want to keep in a
18361 partial symbol table. */
18367 case DW_TAG_compile_unit
:
18368 case DW_TAG_partial_unit
:
18369 case DW_TAG_type_unit
:
18370 /* Compilation units have a DW_AT_name that is a filename, not
18371 a source language identifier. */
18372 case DW_TAG_enumeration_type
:
18373 case DW_TAG_enumerator
:
18374 /* These tags always have simple identifiers already; no need
18375 to canonicalize them. */
18376 name
= DW_STRING (&attr
);
18380 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18383 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18388 case DW_AT_linkage_name
:
18389 case DW_AT_MIPS_linkage_name
:
18390 /* Note that both forms of linkage name might appear. We
18391 assume they will be the same, and we only store the last
18393 linkage_name
= attr
.value_as_string ();
18394 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18395 See https://github.com/rust-lang/rust/issues/32925. */
18396 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18397 && strchr (linkage_name
, '{') != NULL
)
18398 linkage_name
= NULL
;
18401 has_low_pc_attr
= 1;
18402 lowpc
= attr
.value_as_address ();
18404 case DW_AT_high_pc
:
18405 has_high_pc_attr
= 1;
18406 highpc
= attr
.value_as_address ();
18407 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18408 high_pc_relative
= 1;
18410 case DW_AT_location
:
18411 /* Support the .debug_loc offsets. */
18412 if (attr
.form_is_block ())
18414 d
.locdesc
= DW_BLOCK (&attr
);
18416 else if (attr
.form_is_section_offset ())
18418 dwarf2_complex_location_expr_complaint ();
18422 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18423 "partial symbol information");
18426 case DW_AT_external
:
18427 is_external
= DW_UNSND (&attr
);
18429 case DW_AT_declaration
:
18430 is_declaration
= DW_UNSND (&attr
);
18435 case DW_AT_abstract_origin
:
18436 case DW_AT_specification
:
18437 case DW_AT_extension
:
18438 has_specification
= 1;
18439 spec_offset
= attr
.get_ref_die_offset ();
18440 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18441 || cu
->per_cu
->is_dwz
);
18443 case DW_AT_sibling
:
18444 /* Ignore absolute siblings, they might point outside of
18445 the current compile unit. */
18446 if (attr
.form
== DW_FORM_ref_addr
)
18447 complaint (_("ignoring absolute DW_AT_sibling"));
18450 const gdb_byte
*buffer
= reader
->buffer
;
18451 sect_offset off
= attr
.get_ref_die_offset ();
18452 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18454 if (sibling_ptr
< info_ptr
)
18455 complaint (_("DW_AT_sibling points backwards"));
18456 else if (sibling_ptr
> reader
->buffer_end
)
18457 reader
->die_section
->overflow_complaint ();
18459 sibling
= sibling_ptr
;
18462 case DW_AT_byte_size
:
18465 case DW_AT_const_value
:
18466 has_const_value
= 1;
18468 case DW_AT_calling_convention
:
18469 /* DWARF doesn't provide a way to identify a program's source-level
18470 entry point. DW_AT_calling_convention attributes are only meant
18471 to describe functions' calling conventions.
18473 However, because it's a necessary piece of information in
18474 Fortran, and before DWARF 4 DW_CC_program was the only
18475 piece of debugging information whose definition refers to
18476 a 'main program' at all, several compilers marked Fortran
18477 main programs with DW_CC_program --- even when those
18478 functions use the standard calling conventions.
18480 Although DWARF now specifies a way to provide this
18481 information, we support this practice for backward
18483 if (DW_UNSND (&attr
) == DW_CC_program
18484 && cu
->language
== language_fortran
)
18485 main_subprogram
= 1;
18488 if (DW_UNSND (&attr
) == DW_INL_inlined
18489 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18490 may_be_inlined
= 1;
18494 if (tag
== DW_TAG_imported_unit
)
18496 d
.sect_off
= attr
.get_ref_die_offset ();
18497 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18498 || cu
->per_cu
->is_dwz
);
18502 case DW_AT_main_subprogram
:
18503 main_subprogram
= DW_UNSND (&attr
);
18508 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18509 but that requires a full DIE, so instead we just
18511 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18512 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18513 + (need_ranges_base
18517 /* Value of the DW_AT_ranges attribute is the offset in the
18518 .debug_ranges section. */
18519 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18530 /* For Ada, if both the name and the linkage name appear, we prefer
18531 the latter. This lets "catch exception" work better, regardless
18532 of the order in which the name and linkage name were emitted.
18533 Really, though, this is just a workaround for the fact that gdb
18534 doesn't store both the name and the linkage name. */
18535 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18536 name
= linkage_name
;
18538 if (high_pc_relative
)
18541 if (has_low_pc_attr
&& has_high_pc_attr
)
18543 /* When using the GNU linker, .gnu.linkonce. sections are used to
18544 eliminate duplicate copies of functions and vtables and such.
18545 The linker will arbitrarily choose one and discard the others.
18546 The AT_*_pc values for such functions refer to local labels in
18547 these sections. If the section from that file was discarded, the
18548 labels are not in the output, so the relocs get a value of 0.
18549 If this is a discarded function, mark the pc bounds as invalid,
18550 so that GDB will ignore it. */
18551 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18553 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18554 struct gdbarch
*gdbarch
= objfile
->arch ();
18556 complaint (_("DW_AT_low_pc %s is zero "
18557 "for DIE at %s [in module %s]"),
18558 paddress (gdbarch
, lowpc
),
18559 sect_offset_str (sect_off
),
18560 objfile_name (objfile
));
18562 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18563 else if (lowpc
>= highpc
)
18565 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18566 struct gdbarch
*gdbarch
= objfile
->arch ();
18568 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18569 "for DIE at %s [in module %s]"),
18570 paddress (gdbarch
, lowpc
),
18571 paddress (gdbarch
, highpc
),
18572 sect_offset_str (sect_off
),
18573 objfile_name (objfile
));
18582 /* Find a cached partial DIE at OFFSET in CU. */
18584 struct partial_die_info
*
18585 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18587 struct partial_die_info
*lookup_die
= NULL
;
18588 struct partial_die_info
part_die (sect_off
);
18590 lookup_die
= ((struct partial_die_info
*)
18591 htab_find_with_hash (partial_dies
, &part_die
,
18592 to_underlying (sect_off
)));
18597 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18598 except in the case of .debug_types DIEs which do not reference
18599 outside their CU (they do however referencing other types via
18600 DW_FORM_ref_sig8). */
18602 static const struct cu_partial_die_info
18603 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18605 struct dwarf2_per_objfile
*dwarf2_per_objfile
18606 = cu
->per_cu
->dwarf2_per_objfile
;
18607 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18608 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18609 struct partial_die_info
*pd
= NULL
;
18611 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18612 && cu
->header
.offset_in_cu_p (sect_off
))
18614 pd
= cu
->find_partial_die (sect_off
);
18617 /* We missed recording what we needed.
18618 Load all dies and try again. */
18619 per_cu
= cu
->per_cu
;
18623 /* TUs don't reference other CUs/TUs (except via type signatures). */
18624 if (cu
->per_cu
->is_debug_types
)
18626 error (_("Dwarf Error: Type Unit at offset %s contains"
18627 " external reference to offset %s [in module %s].\n"),
18628 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18629 bfd_get_filename (objfile
->obfd
));
18631 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18632 dwarf2_per_objfile
);
18634 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18635 load_partial_comp_unit (per_cu
);
18637 per_cu
->cu
->last_used
= 0;
18638 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18641 /* If we didn't find it, and not all dies have been loaded,
18642 load them all and try again. */
18644 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18646 per_cu
->load_all_dies
= 1;
18648 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18649 THIS_CU->cu may already be in use. So we can't just free it and
18650 replace its DIEs with the ones we read in. Instead, we leave those
18651 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18652 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18654 load_partial_comp_unit (per_cu
);
18656 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18660 internal_error (__FILE__
, __LINE__
,
18661 _("could not find partial DIE %s "
18662 "in cache [from module %s]\n"),
18663 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18664 return { per_cu
->cu
, pd
};
18667 /* See if we can figure out if the class lives in a namespace. We do
18668 this by looking for a member function; its demangled name will
18669 contain namespace info, if there is any. */
18672 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18673 struct dwarf2_cu
*cu
)
18675 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18676 what template types look like, because the demangler
18677 frequently doesn't give the same name as the debug info. We
18678 could fix this by only using the demangled name to get the
18679 prefix (but see comment in read_structure_type). */
18681 struct partial_die_info
*real_pdi
;
18682 struct partial_die_info
*child_pdi
;
18684 /* If this DIE (this DIE's specification, if any) has a parent, then
18685 we should not do this. We'll prepend the parent's fully qualified
18686 name when we create the partial symbol. */
18688 real_pdi
= struct_pdi
;
18689 while (real_pdi
->has_specification
)
18691 auto res
= find_partial_die (real_pdi
->spec_offset
,
18692 real_pdi
->spec_is_dwz
, cu
);
18693 real_pdi
= res
.pdi
;
18697 if (real_pdi
->die_parent
!= NULL
)
18700 for (child_pdi
= struct_pdi
->die_child
;
18702 child_pdi
= child_pdi
->die_sibling
)
18704 if (child_pdi
->tag
== DW_TAG_subprogram
18705 && child_pdi
->linkage_name
!= NULL
)
18707 gdb::unique_xmalloc_ptr
<char> actual_class_name
18708 (language_class_name_from_physname (cu
->language_defn
,
18709 child_pdi
->linkage_name
));
18710 if (actual_class_name
!= NULL
)
18712 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18713 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18720 /* Return true if a DIE with TAG may have the DW_AT_const_value
18724 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18728 case DW_TAG_constant
:
18729 case DW_TAG_enumerator
:
18730 case DW_TAG_formal_parameter
:
18731 case DW_TAG_template_value_param
:
18732 case DW_TAG_variable
:
18740 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18742 /* Once we've fixed up a die, there's no point in doing so again.
18743 This also avoids a memory leak if we were to call
18744 guess_partial_die_structure_name multiple times. */
18748 /* If we found a reference attribute and the DIE has no name, try
18749 to find a name in the referred to DIE. */
18751 if (name
== NULL
&& has_specification
)
18753 struct partial_die_info
*spec_die
;
18755 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18756 spec_die
= res
.pdi
;
18759 spec_die
->fixup (cu
);
18761 if (spec_die
->name
)
18763 name
= spec_die
->name
;
18765 /* Copy DW_AT_external attribute if it is set. */
18766 if (spec_die
->is_external
)
18767 is_external
= spec_die
->is_external
;
18771 if (!has_const_value
&& has_specification
18772 && can_have_DW_AT_const_value_p (tag
))
18774 struct partial_die_info
*spec_die
;
18776 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18777 spec_die
= res
.pdi
;
18780 spec_die
->fixup (cu
);
18782 if (spec_die
->has_const_value
)
18784 /* Copy DW_AT_const_value attribute if it is set. */
18785 has_const_value
= spec_die
->has_const_value
;
18789 /* Set default names for some unnamed DIEs. */
18791 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18792 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18794 /* If there is no parent die to provide a namespace, and there are
18795 children, see if we can determine the namespace from their linkage
18797 if (cu
->language
== language_cplus
18798 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18799 && die_parent
== NULL
18801 && (tag
== DW_TAG_class_type
18802 || tag
== DW_TAG_structure_type
18803 || tag
== DW_TAG_union_type
))
18804 guess_partial_die_structure_name (this, cu
);
18806 /* GCC might emit a nameless struct or union that has a linkage
18807 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18809 && (tag
== DW_TAG_class_type
18810 || tag
== DW_TAG_interface_type
18811 || tag
== DW_TAG_structure_type
18812 || tag
== DW_TAG_union_type
)
18813 && linkage_name
!= NULL
)
18815 gdb::unique_xmalloc_ptr
<char> demangled
18816 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18817 if (demangled
!= nullptr)
18821 /* Strip any leading namespaces/classes, keep only the base name.
18822 DW_AT_name for named DIEs does not contain the prefixes. */
18823 base
= strrchr (demangled
.get (), ':');
18824 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18827 base
= demangled
.get ();
18829 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18830 name
= objfile
->intern (base
);
18837 /* Read the .debug_loclists header contents from the given SECTION in the
18840 read_loclist_header (struct loclist_header
*header
,
18841 struct dwarf2_section_info
*section
)
18843 unsigned int bytes_read
;
18844 bfd
*abfd
= section
->get_bfd_owner ();
18845 const gdb_byte
*info_ptr
= section
->buffer
;
18846 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18847 info_ptr
+= bytes_read
;
18848 header
->version
= read_2_bytes (abfd
, info_ptr
);
18850 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18852 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18854 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18857 /* Return the DW_AT_loclists_base value for the CU. */
18859 lookup_loclist_base (struct dwarf2_cu
*cu
)
18861 /* For the .dwo unit, the loclist_base points to the first offset following
18862 the header. The header consists of the following entities-
18863 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18865 2. version (2 bytes)
18866 3. address size (1 byte)
18867 4. segment selector size (1 byte)
18868 5. offset entry count (4 bytes)
18869 These sizes are derived as per the DWARFv5 standard. */
18870 if (cu
->dwo_unit
!= nullptr)
18872 if (cu
->header
.initial_length_size
== 4)
18873 return LOCLIST_HEADER_SIZE32
;
18874 return LOCLIST_HEADER_SIZE64
;
18876 return cu
->loclist_base
;
18879 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18880 array of offsets in the .debug_loclists section. */
18882 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18884 struct dwarf2_per_objfile
*dwarf2_per_objfile
18885 = cu
->per_cu
->dwarf2_per_objfile
;
18886 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18887 bfd
*abfd
= objfile
->obfd
;
18888 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18889 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18891 section
->read (objfile
);
18892 if (section
->buffer
== NULL
)
18893 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18894 "section [in module %s]"), objfile_name (objfile
));
18895 struct loclist_header header
;
18896 read_loclist_header (&header
, section
);
18897 if (loclist_index
>= header
.offset_entry_count
)
18898 complaint (_("DW_FORM_loclistx pointing outside of "
18899 ".debug_loclists offset array [in module %s]"),
18900 objfile_name (objfile
));
18901 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18903 complaint (_("DW_FORM_loclistx pointing outside of "
18904 ".debug_loclists section [in module %s]"),
18905 objfile_name (objfile
));
18906 const gdb_byte
*info_ptr
18907 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18909 if (cu
->header
.offset_size
== 4)
18910 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18912 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18915 /* Process the attributes that had to be skipped in the first round. These
18916 attributes are the ones that need str_offsets_base or addr_base attributes.
18917 They could not have been processed in the first round, because at the time
18918 the values of str_offsets_base or addr_base may not have been known. */
18920 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18921 struct attribute
*attr
)
18923 struct dwarf2_cu
*cu
= reader
->cu
;
18924 switch (attr
->form
)
18926 case DW_FORM_addrx
:
18927 case DW_FORM_GNU_addr_index
:
18928 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18930 case DW_FORM_loclistx
:
18931 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
18934 case DW_FORM_strx1
:
18935 case DW_FORM_strx2
:
18936 case DW_FORM_strx3
:
18937 case DW_FORM_strx4
:
18938 case DW_FORM_GNU_str_index
:
18940 unsigned int str_index
= DW_UNSND (attr
);
18941 if (reader
->dwo_file
!= NULL
)
18943 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18944 DW_STRING_IS_CANONICAL (attr
) = 0;
18948 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18949 DW_STRING_IS_CANONICAL (attr
) = 0;
18954 gdb_assert_not_reached (_("Unexpected DWARF form."));
18958 /* Read an attribute value described by an attribute form. */
18960 static const gdb_byte
*
18961 read_attribute_value (const struct die_reader_specs
*reader
,
18962 struct attribute
*attr
, unsigned form
,
18963 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18964 bool *need_reprocess
)
18966 struct dwarf2_cu
*cu
= reader
->cu
;
18967 struct dwarf2_per_objfile
*dwarf2_per_objfile
18968 = cu
->per_cu
->dwarf2_per_objfile
;
18969 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18970 bfd
*abfd
= reader
->abfd
;
18971 struct comp_unit_head
*cu_header
= &cu
->header
;
18972 unsigned int bytes_read
;
18973 struct dwarf_block
*blk
;
18974 *need_reprocess
= false;
18976 attr
->form
= (enum dwarf_form
) form
;
18979 case DW_FORM_ref_addr
:
18980 if (cu
->header
.version
== 2)
18981 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18984 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18986 info_ptr
+= bytes_read
;
18988 case DW_FORM_GNU_ref_alt
:
18989 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18990 info_ptr
+= bytes_read
;
18994 struct gdbarch
*gdbarch
= objfile
->arch ();
18995 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18996 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18997 info_ptr
+= bytes_read
;
19000 case DW_FORM_block2
:
19001 blk
= dwarf_alloc_block (cu
);
19002 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19004 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19005 info_ptr
+= blk
->size
;
19006 DW_BLOCK (attr
) = blk
;
19008 case DW_FORM_block4
:
19009 blk
= dwarf_alloc_block (cu
);
19010 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19012 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19013 info_ptr
+= blk
->size
;
19014 DW_BLOCK (attr
) = blk
;
19016 case DW_FORM_data2
:
19017 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19020 case DW_FORM_data4
:
19021 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19024 case DW_FORM_data8
:
19025 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19028 case DW_FORM_data16
:
19029 blk
= dwarf_alloc_block (cu
);
19031 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19033 DW_BLOCK (attr
) = blk
;
19035 case DW_FORM_sec_offset
:
19036 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19037 info_ptr
+= bytes_read
;
19039 case DW_FORM_loclistx
:
19041 *need_reprocess
= true;
19042 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19043 info_ptr
+= bytes_read
;
19046 case DW_FORM_string
:
19047 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19048 DW_STRING_IS_CANONICAL (attr
) = 0;
19049 info_ptr
+= bytes_read
;
19052 if (!cu
->per_cu
->is_dwz
)
19054 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19055 abfd
, info_ptr
, cu_header
,
19057 DW_STRING_IS_CANONICAL (attr
) = 0;
19058 info_ptr
+= bytes_read
;
19062 case DW_FORM_line_strp
:
19063 if (!cu
->per_cu
->is_dwz
)
19066 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
19068 DW_STRING_IS_CANONICAL (attr
) = 0;
19069 info_ptr
+= bytes_read
;
19073 case DW_FORM_GNU_strp_alt
:
19075 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19076 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19079 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19080 DW_STRING_IS_CANONICAL (attr
) = 0;
19081 info_ptr
+= bytes_read
;
19084 case DW_FORM_exprloc
:
19085 case DW_FORM_block
:
19086 blk
= dwarf_alloc_block (cu
);
19087 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19088 info_ptr
+= bytes_read
;
19089 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19090 info_ptr
+= blk
->size
;
19091 DW_BLOCK (attr
) = blk
;
19093 case DW_FORM_block1
:
19094 blk
= dwarf_alloc_block (cu
);
19095 blk
->size
= read_1_byte (abfd
, info_ptr
);
19097 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19098 info_ptr
+= blk
->size
;
19099 DW_BLOCK (attr
) = blk
;
19101 case DW_FORM_data1
:
19102 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19106 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19109 case DW_FORM_flag_present
:
19110 DW_UNSND (attr
) = 1;
19112 case DW_FORM_sdata
:
19113 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19114 info_ptr
+= bytes_read
;
19116 case DW_FORM_udata
:
19117 case DW_FORM_rnglistx
:
19118 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19119 info_ptr
+= bytes_read
;
19122 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19123 + read_1_byte (abfd
, info_ptr
));
19127 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19128 + read_2_bytes (abfd
, info_ptr
));
19132 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19133 + read_4_bytes (abfd
, info_ptr
));
19137 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19138 + read_8_bytes (abfd
, info_ptr
));
19141 case DW_FORM_ref_sig8
:
19142 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19145 case DW_FORM_ref_udata
:
19146 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19147 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19148 info_ptr
+= bytes_read
;
19150 case DW_FORM_indirect
:
19151 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19152 info_ptr
+= bytes_read
;
19153 if (form
== DW_FORM_implicit_const
)
19155 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19156 info_ptr
+= bytes_read
;
19158 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19159 info_ptr
, need_reprocess
);
19161 case DW_FORM_implicit_const
:
19162 DW_SND (attr
) = implicit_const
;
19164 case DW_FORM_addrx
:
19165 case DW_FORM_GNU_addr_index
:
19166 *need_reprocess
= true;
19167 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19168 info_ptr
+= bytes_read
;
19171 case DW_FORM_strx1
:
19172 case DW_FORM_strx2
:
19173 case DW_FORM_strx3
:
19174 case DW_FORM_strx4
:
19175 case DW_FORM_GNU_str_index
:
19177 ULONGEST str_index
;
19178 if (form
== DW_FORM_strx1
)
19180 str_index
= read_1_byte (abfd
, info_ptr
);
19183 else if (form
== DW_FORM_strx2
)
19185 str_index
= read_2_bytes (abfd
, info_ptr
);
19188 else if (form
== DW_FORM_strx3
)
19190 str_index
= read_3_bytes (abfd
, info_ptr
);
19193 else if (form
== DW_FORM_strx4
)
19195 str_index
= read_4_bytes (abfd
, info_ptr
);
19200 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19201 info_ptr
+= bytes_read
;
19203 *need_reprocess
= true;
19204 DW_UNSND (attr
) = str_index
;
19208 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19209 dwarf_form_name (form
),
19210 bfd_get_filename (abfd
));
19214 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19215 attr
->form
= DW_FORM_GNU_ref_alt
;
19217 /* We have seen instances where the compiler tried to emit a byte
19218 size attribute of -1 which ended up being encoded as an unsigned
19219 0xffffffff. Although 0xffffffff is technically a valid size value,
19220 an object of this size seems pretty unlikely so we can relatively
19221 safely treat these cases as if the size attribute was invalid and
19222 treat them as zero by default. */
19223 if (attr
->name
== DW_AT_byte_size
19224 && form
== DW_FORM_data4
19225 && DW_UNSND (attr
) >= 0xffffffff)
19228 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19229 hex_string (DW_UNSND (attr
)));
19230 DW_UNSND (attr
) = 0;
19236 /* Read an attribute described by an abbreviated attribute. */
19238 static const gdb_byte
*
19239 read_attribute (const struct die_reader_specs
*reader
,
19240 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19241 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19243 attr
->name
= abbrev
->name
;
19244 return read_attribute_value (reader
, attr
, abbrev
->form
,
19245 abbrev
->implicit_const
, info_ptr
,
19249 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19251 static const char *
19252 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19253 LONGEST str_offset
)
19255 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
19256 str_offset
, "DW_FORM_strp");
19259 /* Return pointer to string at .debug_str offset as read from BUF.
19260 BUF is assumed to be in a compilation unit described by CU_HEADER.
19261 Return *BYTES_READ_PTR count of bytes read from BUF. */
19263 static const char *
19264 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19265 const gdb_byte
*buf
,
19266 const struct comp_unit_head
*cu_header
,
19267 unsigned int *bytes_read_ptr
)
19269 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19271 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
19277 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19278 const struct comp_unit_head
*cu_header
,
19279 unsigned int *bytes_read_ptr
)
19281 bfd
*abfd
= objfile
->obfd
;
19282 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19284 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19287 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19288 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19289 ADDR_SIZE is the size of addresses from the CU header. */
19292 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19293 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19296 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19297 bfd
*abfd
= objfile
->obfd
;
19298 const gdb_byte
*info_ptr
;
19299 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19301 dwarf2_per_objfile
->addr
.read (objfile
);
19302 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19303 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19304 objfile_name (objfile
));
19305 if (addr_base_or_zero
+ addr_index
* addr_size
19306 >= dwarf2_per_objfile
->addr
.size
)
19307 error (_("DW_FORM_addr_index pointing outside of "
19308 ".debug_addr section [in module %s]"),
19309 objfile_name (objfile
));
19310 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19311 + addr_base_or_zero
+ addr_index
* addr_size
);
19312 if (addr_size
== 4)
19313 return bfd_get_32 (abfd
, info_ptr
);
19315 return bfd_get_64 (abfd
, info_ptr
);
19318 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19321 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19323 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19324 cu
->addr_base
, cu
->header
.addr_size
);
19327 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19330 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19331 unsigned int *bytes_read
)
19333 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19334 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19336 return read_addr_index (cu
, addr_index
);
19342 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
19344 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19345 struct dwarf2_cu
*cu
= per_cu
->cu
;
19346 gdb::optional
<ULONGEST
> addr_base
;
19349 /* We need addr_base and addr_size.
19350 If we don't have PER_CU->cu, we have to get it.
19351 Nasty, but the alternative is storing the needed info in PER_CU,
19352 which at this point doesn't seem justified: it's not clear how frequently
19353 it would get used and it would increase the size of every PER_CU.
19354 Entry points like dwarf2_per_cu_addr_size do a similar thing
19355 so we're not in uncharted territory here.
19356 Alas we need to be a bit more complicated as addr_base is contained
19359 We don't need to read the entire CU(/TU).
19360 We just need the header and top level die.
19362 IWBN to use the aging mechanism to let us lazily later discard the CU.
19363 For now we skip this optimization. */
19367 addr_base
= cu
->addr_base
;
19368 addr_size
= cu
->header
.addr_size
;
19372 cutu_reader
reader (per_cu
, NULL
, 0, false);
19373 addr_base
= reader
.cu
->addr_base
;
19374 addr_size
= reader
.cu
->header
.addr_size
;
19377 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19381 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19382 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19385 static const char *
19386 read_str_index (struct dwarf2_cu
*cu
,
19387 struct dwarf2_section_info
*str_section
,
19388 struct dwarf2_section_info
*str_offsets_section
,
19389 ULONGEST str_offsets_base
, ULONGEST str_index
)
19391 struct dwarf2_per_objfile
*dwarf2_per_objfile
19392 = cu
->per_cu
->dwarf2_per_objfile
;
19393 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19394 const char *objf_name
= objfile_name (objfile
);
19395 bfd
*abfd
= objfile
->obfd
;
19396 const gdb_byte
*info_ptr
;
19397 ULONGEST str_offset
;
19398 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19400 str_section
->read (objfile
);
19401 str_offsets_section
->read (objfile
);
19402 if (str_section
->buffer
== NULL
)
19403 error (_("%s used without %s section"
19404 " in CU at offset %s [in module %s]"),
19405 form_name
, str_section
->get_name (),
19406 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19407 if (str_offsets_section
->buffer
== NULL
)
19408 error (_("%s used without %s section"
19409 " in CU at offset %s [in module %s]"),
19410 form_name
, str_section
->get_name (),
19411 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19412 info_ptr
= (str_offsets_section
->buffer
19414 + str_index
* cu
->header
.offset_size
);
19415 if (cu
->header
.offset_size
== 4)
19416 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19418 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19419 if (str_offset
>= str_section
->size
)
19420 error (_("Offset from %s pointing outside of"
19421 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19422 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19423 return (const char *) (str_section
->buffer
+ str_offset
);
19426 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19428 static const char *
19429 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19431 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19432 ? reader
->cu
->header
.addr_size
: 0;
19433 return read_str_index (reader
->cu
,
19434 &reader
->dwo_file
->sections
.str
,
19435 &reader
->dwo_file
->sections
.str_offsets
,
19436 str_offsets_base
, str_index
);
19439 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19441 static const char *
19442 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19444 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19445 const char *objf_name
= objfile_name (objfile
);
19446 static const char form_name
[] = "DW_FORM_GNU_str_index";
19447 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19449 if (!cu
->str_offsets_base
.has_value ())
19450 error (_("%s used in Fission stub without %s"
19451 " in CU at offset 0x%lx [in module %s]"),
19452 form_name
, str_offsets_attr_name
,
19453 (long) cu
->header
.offset_size
, objf_name
);
19455 return read_str_index (cu
,
19456 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19457 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19458 *cu
->str_offsets_base
, str_index
);
19461 /* Return the length of an LEB128 number in BUF. */
19464 leb128_size (const gdb_byte
*buf
)
19466 const gdb_byte
*begin
= buf
;
19472 if ((byte
& 128) == 0)
19473 return buf
- begin
;
19478 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19487 cu
->language
= language_c
;
19490 case DW_LANG_C_plus_plus
:
19491 case DW_LANG_C_plus_plus_11
:
19492 case DW_LANG_C_plus_plus_14
:
19493 cu
->language
= language_cplus
;
19496 cu
->language
= language_d
;
19498 case DW_LANG_Fortran77
:
19499 case DW_LANG_Fortran90
:
19500 case DW_LANG_Fortran95
:
19501 case DW_LANG_Fortran03
:
19502 case DW_LANG_Fortran08
:
19503 cu
->language
= language_fortran
;
19506 cu
->language
= language_go
;
19508 case DW_LANG_Mips_Assembler
:
19509 cu
->language
= language_asm
;
19511 case DW_LANG_Ada83
:
19512 case DW_LANG_Ada95
:
19513 cu
->language
= language_ada
;
19515 case DW_LANG_Modula2
:
19516 cu
->language
= language_m2
;
19518 case DW_LANG_Pascal83
:
19519 cu
->language
= language_pascal
;
19522 cu
->language
= language_objc
;
19525 case DW_LANG_Rust_old
:
19526 cu
->language
= language_rust
;
19528 case DW_LANG_Cobol74
:
19529 case DW_LANG_Cobol85
:
19531 cu
->language
= language_minimal
;
19534 cu
->language_defn
= language_def (cu
->language
);
19537 /* Return the named attribute or NULL if not there. */
19539 static struct attribute
*
19540 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19545 struct attribute
*spec
= NULL
;
19547 for (i
= 0; i
< die
->num_attrs
; ++i
)
19549 if (die
->attrs
[i
].name
== name
)
19550 return &die
->attrs
[i
];
19551 if (die
->attrs
[i
].name
== DW_AT_specification
19552 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19553 spec
= &die
->attrs
[i
];
19559 die
= follow_die_ref (die
, spec
, &cu
);
19565 /* Return the string associated with a string-typed attribute, or NULL if it
19566 is either not found or is of an incorrect type. */
19568 static const char *
19569 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19571 struct attribute
*attr
;
19572 const char *str
= NULL
;
19574 attr
= dwarf2_attr (die
, name
, cu
);
19578 str
= attr
->value_as_string ();
19579 if (str
== nullptr)
19580 complaint (_("string type expected for attribute %s for "
19581 "DIE at %s in module %s"),
19582 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19583 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19589 /* Return the dwo name or NULL if not present. If present, it is in either
19590 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19591 static const char *
19592 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19594 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19595 if (dwo_name
== nullptr)
19596 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19600 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19601 and holds a non-zero value. This function should only be used for
19602 DW_FORM_flag or DW_FORM_flag_present attributes. */
19605 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19607 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19609 return (attr
&& DW_UNSND (attr
));
19613 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19615 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19616 which value is non-zero. However, we have to be careful with
19617 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19618 (via dwarf2_flag_true_p) follows this attribute. So we may
19619 end up accidently finding a declaration attribute that belongs
19620 to a different DIE referenced by the specification attribute,
19621 even though the given DIE does not have a declaration attribute. */
19622 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19623 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19626 /* Return the die giving the specification for DIE, if there is
19627 one. *SPEC_CU is the CU containing DIE on input, and the CU
19628 containing the return value on output. If there is no
19629 specification, but there is an abstract origin, that is
19632 static struct die_info
*
19633 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19635 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19638 if (spec_attr
== NULL
)
19639 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19641 if (spec_attr
== NULL
)
19644 return follow_die_ref (die
, spec_attr
, spec_cu
);
19647 /* Stub for free_line_header to match void * callback types. */
19650 free_line_header_voidp (void *arg
)
19652 struct line_header
*lh
= (struct line_header
*) arg
;
19657 /* A convenience function to find the proper .debug_line section for a CU. */
19659 static struct dwarf2_section_info
*
19660 get_debug_line_section (struct dwarf2_cu
*cu
)
19662 struct dwarf2_section_info
*section
;
19663 struct dwarf2_per_objfile
*dwarf2_per_objfile
19664 = cu
->per_cu
->dwarf2_per_objfile
;
19666 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19668 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19669 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19670 else if (cu
->per_cu
->is_dwz
)
19672 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19674 section
= &dwz
->line
;
19677 section
= &dwarf2_per_objfile
->line
;
19682 /* Read the statement program header starting at OFFSET in
19683 .debug_line, or .debug_line.dwo. Return a pointer
19684 to a struct line_header, allocated using xmalloc.
19685 Returns NULL if there is a problem reading the header, e.g., if it
19686 has a version we don't understand.
19688 NOTE: the strings in the include directory and file name tables of
19689 the returned object point into the dwarf line section buffer,
19690 and must not be freed. */
19692 static line_header_up
19693 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19695 struct dwarf2_section_info
*section
;
19696 struct dwarf2_per_objfile
*dwarf2_per_objfile
19697 = cu
->per_cu
->dwarf2_per_objfile
;
19699 section
= get_debug_line_section (cu
);
19700 section
->read (dwarf2_per_objfile
->objfile
);
19701 if (section
->buffer
== NULL
)
19703 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19704 complaint (_("missing .debug_line.dwo section"));
19706 complaint (_("missing .debug_line section"));
19710 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19711 dwarf2_per_objfile
, section
,
19715 /* Subroutine of dwarf_decode_lines to simplify it.
19716 Return the file name of the psymtab for the given file_entry.
19717 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19718 If space for the result is malloc'd, *NAME_HOLDER will be set.
19719 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19721 static const char *
19722 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19723 const dwarf2_psymtab
*pst
,
19724 const char *comp_dir
,
19725 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19727 const char *include_name
= fe
.name
;
19728 const char *include_name_to_compare
= include_name
;
19729 const char *pst_filename
;
19732 const char *dir_name
= fe
.include_dir (lh
);
19734 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19735 if (!IS_ABSOLUTE_PATH (include_name
)
19736 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19738 /* Avoid creating a duplicate psymtab for PST.
19739 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19740 Before we do the comparison, however, we need to account
19741 for DIR_NAME and COMP_DIR.
19742 First prepend dir_name (if non-NULL). If we still don't
19743 have an absolute path prepend comp_dir (if non-NULL).
19744 However, the directory we record in the include-file's
19745 psymtab does not contain COMP_DIR (to match the
19746 corresponding symtab(s)).
19751 bash$ gcc -g ./hello.c
19752 include_name = "hello.c"
19754 DW_AT_comp_dir = comp_dir = "/tmp"
19755 DW_AT_name = "./hello.c"
19759 if (dir_name
!= NULL
)
19761 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19762 include_name
, (char *) NULL
));
19763 include_name
= name_holder
->get ();
19764 include_name_to_compare
= include_name
;
19766 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19768 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19769 include_name
, (char *) NULL
));
19770 include_name_to_compare
= hold_compare
.get ();
19774 pst_filename
= pst
->filename
;
19775 gdb::unique_xmalloc_ptr
<char> copied_name
;
19776 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19778 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19779 pst_filename
, (char *) NULL
));
19780 pst_filename
= copied_name
.get ();
19783 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19787 return include_name
;
19790 /* State machine to track the state of the line number program. */
19792 class lnp_state_machine
19795 /* Initialize a machine state for the start of a line number
19797 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19798 bool record_lines_p
);
19800 file_entry
*current_file ()
19802 /* lh->file_names is 0-based, but the file name numbers in the
19803 statement program are 1-based. */
19804 return m_line_header
->file_name_at (m_file
);
19807 /* Record the line in the state machine. END_SEQUENCE is true if
19808 we're processing the end of a sequence. */
19809 void record_line (bool end_sequence
);
19811 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19812 nop-out rest of the lines in this sequence. */
19813 void check_line_address (struct dwarf2_cu
*cu
,
19814 const gdb_byte
*line_ptr
,
19815 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19817 void handle_set_discriminator (unsigned int discriminator
)
19819 m_discriminator
= discriminator
;
19820 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19823 /* Handle DW_LNE_set_address. */
19824 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19827 address
+= baseaddr
;
19828 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19831 /* Handle DW_LNS_advance_pc. */
19832 void handle_advance_pc (CORE_ADDR adjust
);
19834 /* Handle a special opcode. */
19835 void handle_special_opcode (unsigned char op_code
);
19837 /* Handle DW_LNS_advance_line. */
19838 void handle_advance_line (int line_delta
)
19840 advance_line (line_delta
);
19843 /* Handle DW_LNS_set_file. */
19844 void handle_set_file (file_name_index file
);
19846 /* Handle DW_LNS_negate_stmt. */
19847 void handle_negate_stmt ()
19849 m_is_stmt
= !m_is_stmt
;
19852 /* Handle DW_LNS_const_add_pc. */
19853 void handle_const_add_pc ();
19855 /* Handle DW_LNS_fixed_advance_pc. */
19856 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19858 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19862 /* Handle DW_LNS_copy. */
19863 void handle_copy ()
19865 record_line (false);
19866 m_discriminator
= 0;
19869 /* Handle DW_LNE_end_sequence. */
19870 void handle_end_sequence ()
19872 m_currently_recording_lines
= true;
19876 /* Advance the line by LINE_DELTA. */
19877 void advance_line (int line_delta
)
19879 m_line
+= line_delta
;
19881 if (line_delta
!= 0)
19882 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19885 struct dwarf2_cu
*m_cu
;
19887 gdbarch
*m_gdbarch
;
19889 /* True if we're recording lines.
19890 Otherwise we're building partial symtabs and are just interested in
19891 finding include files mentioned by the line number program. */
19892 bool m_record_lines_p
;
19894 /* The line number header. */
19895 line_header
*m_line_header
;
19897 /* These are part of the standard DWARF line number state machine,
19898 and initialized according to the DWARF spec. */
19900 unsigned char m_op_index
= 0;
19901 /* The line table index of the current file. */
19902 file_name_index m_file
= 1;
19903 unsigned int m_line
= 1;
19905 /* These are initialized in the constructor. */
19907 CORE_ADDR m_address
;
19909 unsigned int m_discriminator
;
19911 /* Additional bits of state we need to track. */
19913 /* The last file that we called dwarf2_start_subfile for.
19914 This is only used for TLLs. */
19915 unsigned int m_last_file
= 0;
19916 /* The last file a line number was recorded for. */
19917 struct subfile
*m_last_subfile
= NULL
;
19919 /* When true, record the lines we decode. */
19920 bool m_currently_recording_lines
= false;
19922 /* The last line number that was recorded, used to coalesce
19923 consecutive entries for the same line. This can happen, for
19924 example, when discriminators are present. PR 17276. */
19925 unsigned int m_last_line
= 0;
19926 bool m_line_has_non_zero_discriminator
= false;
19930 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19932 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19933 / m_line_header
->maximum_ops_per_instruction
)
19934 * m_line_header
->minimum_instruction_length
);
19935 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19936 m_op_index
= ((m_op_index
+ adjust
)
19937 % m_line_header
->maximum_ops_per_instruction
);
19941 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19943 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19944 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19945 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19946 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19947 / m_line_header
->maximum_ops_per_instruction
)
19948 * m_line_header
->minimum_instruction_length
);
19949 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19950 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19951 % m_line_header
->maximum_ops_per_instruction
);
19953 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19954 advance_line (line_delta
);
19955 record_line (false);
19956 m_discriminator
= 0;
19960 lnp_state_machine::handle_set_file (file_name_index file
)
19964 const file_entry
*fe
= current_file ();
19966 dwarf2_debug_line_missing_file_complaint ();
19967 else if (m_record_lines_p
)
19969 const char *dir
= fe
->include_dir (m_line_header
);
19971 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19972 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19973 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19978 lnp_state_machine::handle_const_add_pc ()
19981 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19984 = (((m_op_index
+ adjust
)
19985 / m_line_header
->maximum_ops_per_instruction
)
19986 * m_line_header
->minimum_instruction_length
);
19988 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19989 m_op_index
= ((m_op_index
+ adjust
)
19990 % m_line_header
->maximum_ops_per_instruction
);
19993 /* Return non-zero if we should add LINE to the line number table.
19994 LINE is the line to add, LAST_LINE is the last line that was added,
19995 LAST_SUBFILE is the subfile for LAST_LINE.
19996 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19997 had a non-zero discriminator.
19999 We have to be careful in the presence of discriminators.
20000 E.g., for this line:
20002 for (i = 0; i < 100000; i++);
20004 clang can emit four line number entries for that one line,
20005 each with a different discriminator.
20006 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20008 However, we want gdb to coalesce all four entries into one.
20009 Otherwise the user could stepi into the middle of the line and
20010 gdb would get confused about whether the pc really was in the
20011 middle of the line.
20013 Things are further complicated by the fact that two consecutive
20014 line number entries for the same line is a heuristic used by gcc
20015 to denote the end of the prologue. So we can't just discard duplicate
20016 entries, we have to be selective about it. The heuristic we use is
20017 that we only collapse consecutive entries for the same line if at least
20018 one of those entries has a non-zero discriminator. PR 17276.
20020 Note: Addresses in the line number state machine can never go backwards
20021 within one sequence, thus this coalescing is ok. */
20024 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20025 unsigned int line
, unsigned int last_line
,
20026 int line_has_non_zero_discriminator
,
20027 struct subfile
*last_subfile
)
20029 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20031 if (line
!= last_line
)
20033 /* Same line for the same file that we've seen already.
20034 As a last check, for pr 17276, only record the line if the line
20035 has never had a non-zero discriminator. */
20036 if (!line_has_non_zero_discriminator
)
20041 /* Use the CU's builder to record line number LINE beginning at
20042 address ADDRESS in the line table of subfile SUBFILE. */
20045 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20046 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20047 struct dwarf2_cu
*cu
)
20049 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20051 if (dwarf_line_debug
)
20053 fprintf_unfiltered (gdb_stdlog
,
20054 "Recording line %u, file %s, address %s\n",
20055 line
, lbasename (subfile
->name
),
20056 paddress (gdbarch
, address
));
20060 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20063 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20064 Mark the end of a set of line number records.
20065 The arguments are the same as for dwarf_record_line_1.
20066 If SUBFILE is NULL the request is ignored. */
20069 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20070 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20072 if (subfile
== NULL
)
20075 if (dwarf_line_debug
)
20077 fprintf_unfiltered (gdb_stdlog
,
20078 "Finishing current line, file %s, address %s\n",
20079 lbasename (subfile
->name
),
20080 paddress (gdbarch
, address
));
20083 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20087 lnp_state_machine::record_line (bool end_sequence
)
20089 if (dwarf_line_debug
)
20091 fprintf_unfiltered (gdb_stdlog
,
20092 "Processing actual line %u: file %u,"
20093 " address %s, is_stmt %u, discrim %u%s\n",
20095 paddress (m_gdbarch
, m_address
),
20096 m_is_stmt
, m_discriminator
,
20097 (end_sequence
? "\t(end sequence)" : ""));
20100 file_entry
*fe
= current_file ();
20103 dwarf2_debug_line_missing_file_complaint ();
20104 /* For now we ignore lines not starting on an instruction boundary.
20105 But not when processing end_sequence for compatibility with the
20106 previous version of the code. */
20107 else if (m_op_index
== 0 || end_sequence
)
20109 fe
->included_p
= 1;
20110 if (m_record_lines_p
)
20112 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20115 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20116 m_currently_recording_lines
? m_cu
: nullptr);
20121 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20123 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20124 m_line_has_non_zero_discriminator
,
20127 buildsym_compunit
*builder
= m_cu
->get_builder ();
20128 dwarf_record_line_1 (m_gdbarch
,
20129 builder
->get_current_subfile (),
20130 m_line
, m_address
, is_stmt
,
20131 m_currently_recording_lines
? m_cu
: nullptr);
20133 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20134 m_last_line
= m_line
;
20140 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20141 line_header
*lh
, bool record_lines_p
)
20145 m_record_lines_p
= record_lines_p
;
20146 m_line_header
= lh
;
20148 m_currently_recording_lines
= true;
20150 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20151 was a line entry for it so that the backend has a chance to adjust it
20152 and also record it in case it needs it. This is currently used by MIPS
20153 code, cf. `mips_adjust_dwarf2_line'. */
20154 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20155 m_is_stmt
= lh
->default_is_stmt
;
20156 m_discriminator
= 0;
20160 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20161 const gdb_byte
*line_ptr
,
20162 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20164 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20165 the pc range of the CU. However, we restrict the test to only ADDRESS
20166 values of zero to preserve GDB's previous behaviour which is to handle
20167 the specific case of a function being GC'd by the linker. */
20169 if (address
== 0 && address
< unrelocated_lowpc
)
20171 /* This line table is for a function which has been
20172 GCd by the linker. Ignore it. PR gdb/12528 */
20174 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20175 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20177 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20178 line_offset
, objfile_name (objfile
));
20179 m_currently_recording_lines
= false;
20180 /* Note: m_currently_recording_lines is left as false until we see
20181 DW_LNE_end_sequence. */
20185 /* Subroutine of dwarf_decode_lines to simplify it.
20186 Process the line number information in LH.
20187 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20188 program in order to set included_p for every referenced header. */
20191 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20192 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20194 const gdb_byte
*line_ptr
, *extended_end
;
20195 const gdb_byte
*line_end
;
20196 unsigned int bytes_read
, extended_len
;
20197 unsigned char op_code
, extended_op
;
20198 CORE_ADDR baseaddr
;
20199 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20200 bfd
*abfd
= objfile
->obfd
;
20201 struct gdbarch
*gdbarch
= objfile
->arch ();
20202 /* True if we're recording line info (as opposed to building partial
20203 symtabs and just interested in finding include files mentioned by
20204 the line number program). */
20205 bool record_lines_p
= !decode_for_pst_p
;
20207 baseaddr
= objfile
->text_section_offset ();
20209 line_ptr
= lh
->statement_program_start
;
20210 line_end
= lh
->statement_program_end
;
20212 /* Read the statement sequences until there's nothing left. */
20213 while (line_ptr
< line_end
)
20215 /* The DWARF line number program state machine. Reset the state
20216 machine at the start of each sequence. */
20217 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20218 bool end_sequence
= false;
20220 if (record_lines_p
)
20222 /* Start a subfile for the current file of the state
20224 const file_entry
*fe
= state_machine
.current_file ();
20227 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20230 /* Decode the table. */
20231 while (line_ptr
< line_end
&& !end_sequence
)
20233 op_code
= read_1_byte (abfd
, line_ptr
);
20236 if (op_code
>= lh
->opcode_base
)
20238 /* Special opcode. */
20239 state_machine
.handle_special_opcode (op_code
);
20241 else switch (op_code
)
20243 case DW_LNS_extended_op
:
20244 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20246 line_ptr
+= bytes_read
;
20247 extended_end
= line_ptr
+ extended_len
;
20248 extended_op
= read_1_byte (abfd
, line_ptr
);
20250 switch (extended_op
)
20252 case DW_LNE_end_sequence
:
20253 state_machine
.handle_end_sequence ();
20254 end_sequence
= true;
20256 case DW_LNE_set_address
:
20259 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20260 line_ptr
+= bytes_read
;
20262 state_machine
.check_line_address (cu
, line_ptr
,
20263 lowpc
- baseaddr
, address
);
20264 state_machine
.handle_set_address (baseaddr
, address
);
20267 case DW_LNE_define_file
:
20269 const char *cur_file
;
20270 unsigned int mod_time
, length
;
20273 cur_file
= read_direct_string (abfd
, line_ptr
,
20275 line_ptr
+= bytes_read
;
20276 dindex
= (dir_index
)
20277 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20278 line_ptr
+= bytes_read
;
20280 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20281 line_ptr
+= bytes_read
;
20283 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20284 line_ptr
+= bytes_read
;
20285 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20288 case DW_LNE_set_discriminator
:
20290 /* The discriminator is not interesting to the
20291 debugger; just ignore it. We still need to
20292 check its value though:
20293 if there are consecutive entries for the same
20294 (non-prologue) line we want to coalesce them.
20297 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20298 line_ptr
+= bytes_read
;
20300 state_machine
.handle_set_discriminator (discr
);
20304 complaint (_("mangled .debug_line section"));
20307 /* Make sure that we parsed the extended op correctly. If e.g.
20308 we expected a different address size than the producer used,
20309 we may have read the wrong number of bytes. */
20310 if (line_ptr
!= extended_end
)
20312 complaint (_("mangled .debug_line section"));
20317 state_machine
.handle_copy ();
20319 case DW_LNS_advance_pc
:
20322 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20323 line_ptr
+= bytes_read
;
20325 state_machine
.handle_advance_pc (adjust
);
20328 case DW_LNS_advance_line
:
20331 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20332 line_ptr
+= bytes_read
;
20334 state_machine
.handle_advance_line (line_delta
);
20337 case DW_LNS_set_file
:
20339 file_name_index file
20340 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20342 line_ptr
+= bytes_read
;
20344 state_machine
.handle_set_file (file
);
20347 case DW_LNS_set_column
:
20348 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20349 line_ptr
+= bytes_read
;
20351 case DW_LNS_negate_stmt
:
20352 state_machine
.handle_negate_stmt ();
20354 case DW_LNS_set_basic_block
:
20356 /* Add to the address register of the state machine the
20357 address increment value corresponding to special opcode
20358 255. I.e., this value is scaled by the minimum
20359 instruction length since special opcode 255 would have
20360 scaled the increment. */
20361 case DW_LNS_const_add_pc
:
20362 state_machine
.handle_const_add_pc ();
20364 case DW_LNS_fixed_advance_pc
:
20366 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20369 state_machine
.handle_fixed_advance_pc (addr_adj
);
20374 /* Unknown standard opcode, ignore it. */
20377 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20379 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20380 line_ptr
+= bytes_read
;
20387 dwarf2_debug_line_missing_end_sequence_complaint ();
20389 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20390 in which case we still finish recording the last line). */
20391 state_machine
.record_line (true);
20395 /* Decode the Line Number Program (LNP) for the given line_header
20396 structure and CU. The actual information extracted and the type
20397 of structures created from the LNP depends on the value of PST.
20399 1. If PST is NULL, then this procedure uses the data from the program
20400 to create all necessary symbol tables, and their linetables.
20402 2. If PST is not NULL, this procedure reads the program to determine
20403 the list of files included by the unit represented by PST, and
20404 builds all the associated partial symbol tables.
20406 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20407 It is used for relative paths in the line table.
20408 NOTE: When processing partial symtabs (pst != NULL),
20409 comp_dir == pst->dirname.
20411 NOTE: It is important that psymtabs have the same file name (via strcmp)
20412 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20413 symtab we don't use it in the name of the psymtabs we create.
20414 E.g. expand_line_sal requires this when finding psymtabs to expand.
20415 A good testcase for this is mb-inline.exp.
20417 LOWPC is the lowest address in CU (or 0 if not known).
20419 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20420 for its PC<->lines mapping information. Otherwise only the filename
20421 table is read in. */
20424 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20425 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20426 CORE_ADDR lowpc
, int decode_mapping
)
20428 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20429 const int decode_for_pst_p
= (pst
!= NULL
);
20431 if (decode_mapping
)
20432 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20434 if (decode_for_pst_p
)
20436 /* Now that we're done scanning the Line Header Program, we can
20437 create the psymtab of each included file. */
20438 for (auto &file_entry
: lh
->file_names ())
20439 if (file_entry
.included_p
== 1)
20441 gdb::unique_xmalloc_ptr
<char> name_holder
;
20442 const char *include_name
=
20443 psymtab_include_file_name (lh
, file_entry
, pst
,
20444 comp_dir
, &name_holder
);
20445 if (include_name
!= NULL
)
20446 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20451 /* Make sure a symtab is created for every file, even files
20452 which contain only variables (i.e. no code with associated
20454 buildsym_compunit
*builder
= cu
->get_builder ();
20455 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20457 for (auto &fe
: lh
->file_names ())
20459 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20460 if (builder
->get_current_subfile ()->symtab
== NULL
)
20462 builder
->get_current_subfile ()->symtab
20463 = allocate_symtab (cust
,
20464 builder
->get_current_subfile ()->name
);
20466 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20471 /* Start a subfile for DWARF. FILENAME is the name of the file and
20472 DIRNAME the name of the source directory which contains FILENAME
20473 or NULL if not known.
20474 This routine tries to keep line numbers from identical absolute and
20475 relative file names in a common subfile.
20477 Using the `list' example from the GDB testsuite, which resides in
20478 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20479 of /srcdir/list0.c yields the following debugging information for list0.c:
20481 DW_AT_name: /srcdir/list0.c
20482 DW_AT_comp_dir: /compdir
20483 files.files[0].name: list0.h
20484 files.files[0].dir: /srcdir
20485 files.files[1].name: list0.c
20486 files.files[1].dir: /srcdir
20488 The line number information for list0.c has to end up in a single
20489 subfile, so that `break /srcdir/list0.c:1' works as expected.
20490 start_subfile will ensure that this happens provided that we pass the
20491 concatenation of files.files[1].dir and files.files[1].name as the
20495 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20496 const char *dirname
)
20498 gdb::unique_xmalloc_ptr
<char> copy
;
20500 /* In order not to lose the line information directory,
20501 we concatenate it to the filename when it makes sense.
20502 Note that the Dwarf3 standard says (speaking of filenames in line
20503 information): ``The directory index is ignored for file names
20504 that represent full path names''. Thus ignoring dirname in the
20505 `else' branch below isn't an issue. */
20507 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20509 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20510 filename
= copy
.get ();
20513 cu
->get_builder ()->start_subfile (filename
);
20516 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20517 buildsym_compunit constructor. */
20519 struct compunit_symtab
*
20520 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20523 gdb_assert (m_builder
== nullptr);
20525 m_builder
.reset (new struct buildsym_compunit
20526 (per_cu
->dwarf2_per_objfile
->objfile
,
20527 name
, comp_dir
, language
, low_pc
));
20529 list_in_scope
= get_builder ()->get_file_symbols ();
20531 get_builder ()->record_debugformat ("DWARF 2");
20532 get_builder ()->record_producer (producer
);
20534 processing_has_namespace_info
= false;
20536 return get_builder ()->get_compunit_symtab ();
20540 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20541 struct dwarf2_cu
*cu
)
20543 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20544 struct comp_unit_head
*cu_header
= &cu
->header
;
20546 /* NOTE drow/2003-01-30: There used to be a comment and some special
20547 code here to turn a symbol with DW_AT_external and a
20548 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20549 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20550 with some versions of binutils) where shared libraries could have
20551 relocations against symbols in their debug information - the
20552 minimal symbol would have the right address, but the debug info
20553 would not. It's no longer necessary, because we will explicitly
20554 apply relocations when we read in the debug information now. */
20556 /* A DW_AT_location attribute with no contents indicates that a
20557 variable has been optimized away. */
20558 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20560 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20564 /* Handle one degenerate form of location expression specially, to
20565 preserve GDB's previous behavior when section offsets are
20566 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20567 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20569 if (attr
->form_is_block ()
20570 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20571 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20572 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20573 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20574 && (DW_BLOCK (attr
)->size
20575 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20577 unsigned int dummy
;
20579 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20580 SET_SYMBOL_VALUE_ADDRESS
20581 (sym
, cu
->header
.read_address (objfile
->obfd
,
20582 DW_BLOCK (attr
)->data
+ 1,
20585 SET_SYMBOL_VALUE_ADDRESS
20586 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20588 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20589 fixup_symbol_section (sym
, objfile
);
20590 SET_SYMBOL_VALUE_ADDRESS
20592 SYMBOL_VALUE_ADDRESS (sym
)
20593 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20597 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20598 expression evaluator, and use LOC_COMPUTED only when necessary
20599 (i.e. when the value of a register or memory location is
20600 referenced, or a thread-local block, etc.). Then again, it might
20601 not be worthwhile. I'm assuming that it isn't unless performance
20602 or memory numbers show me otherwise. */
20604 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20606 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20607 cu
->has_loclist
= true;
20610 /* Given a pointer to a DWARF information entry, figure out if we need
20611 to make a symbol table entry for it, and if so, create a new entry
20612 and return a pointer to it.
20613 If TYPE is NULL, determine symbol type from the die, otherwise
20614 used the passed type.
20615 If SPACE is not NULL, use it to hold the new symbol. If it is
20616 NULL, allocate a new symbol on the objfile's obstack. */
20618 static struct symbol
*
20619 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20620 struct symbol
*space
)
20622 struct dwarf2_per_objfile
*dwarf2_per_objfile
20623 = cu
->per_cu
->dwarf2_per_objfile
;
20624 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20625 struct gdbarch
*gdbarch
= objfile
->arch ();
20626 struct symbol
*sym
= NULL
;
20628 struct attribute
*attr
= NULL
;
20629 struct attribute
*attr2
= NULL
;
20630 CORE_ADDR baseaddr
;
20631 struct pending
**list_to_add
= NULL
;
20633 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20635 baseaddr
= objfile
->text_section_offset ();
20637 name
= dwarf2_name (die
, cu
);
20640 int suppress_add
= 0;
20645 sym
= new (&objfile
->objfile_obstack
) symbol
;
20646 OBJSTAT (objfile
, n_syms
++);
20648 /* Cache this symbol's name and the name's demangled form (if any). */
20649 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20650 /* Fortran does not have mangling standard and the mangling does differ
20651 between gfortran, iFort etc. */
20652 const char *physname
20653 = (cu
->language
== language_fortran
20654 ? dwarf2_full_name (name
, die
, cu
)
20655 : dwarf2_physname (name
, die
, cu
));
20656 const char *linkagename
= dw2_linkage_name (die
, cu
);
20658 if (linkagename
== nullptr || cu
->language
== language_ada
)
20659 sym
->set_linkage_name (physname
);
20662 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20663 sym
->set_linkage_name (linkagename
);
20666 /* Default assumptions.
20667 Use the passed type or decode it from the die. */
20668 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20669 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20671 SYMBOL_TYPE (sym
) = type
;
20673 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20674 attr
= dwarf2_attr (die
,
20675 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20677 if (attr
!= nullptr)
20679 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20682 attr
= dwarf2_attr (die
,
20683 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20685 if (attr
!= nullptr)
20687 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20688 struct file_entry
*fe
;
20690 if (cu
->line_header
!= NULL
)
20691 fe
= cu
->line_header
->file_name_at (file_index
);
20696 complaint (_("file index out of range"));
20698 symbol_set_symtab (sym
, fe
->symtab
);
20704 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20705 if (attr
!= nullptr)
20709 addr
= attr
->value_as_address ();
20710 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20711 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20713 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20714 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20715 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20716 add_symbol_to_list (sym
, cu
->list_in_scope
);
20718 case DW_TAG_subprogram
:
20719 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20721 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20722 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20723 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20724 || cu
->language
== language_ada
20725 || cu
->language
== language_fortran
)
20727 /* Subprograms marked external are stored as a global symbol.
20728 Ada and Fortran subprograms, whether marked external or
20729 not, are always stored as a global symbol, because we want
20730 to be able to access them globally. For instance, we want
20731 to be able to break on a nested subprogram without having
20732 to specify the context. */
20733 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20737 list_to_add
= cu
->list_in_scope
;
20740 case DW_TAG_inlined_subroutine
:
20741 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20743 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20744 SYMBOL_INLINED (sym
) = 1;
20745 list_to_add
= cu
->list_in_scope
;
20747 case DW_TAG_template_value_param
:
20749 /* Fall through. */
20750 case DW_TAG_constant
:
20751 case DW_TAG_variable
:
20752 case DW_TAG_member
:
20753 /* Compilation with minimal debug info may result in
20754 variables with missing type entries. Change the
20755 misleading `void' type to something sensible. */
20756 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20757 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20759 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20760 /* In the case of DW_TAG_member, we should only be called for
20761 static const members. */
20762 if (die
->tag
== DW_TAG_member
)
20764 /* dwarf2_add_field uses die_is_declaration,
20765 so we do the same. */
20766 gdb_assert (die_is_declaration (die
, cu
));
20769 if (attr
!= nullptr)
20771 dwarf2_const_value (attr
, sym
, cu
);
20772 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20775 if (attr2
&& (DW_UNSND (attr2
) != 0))
20776 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20778 list_to_add
= cu
->list_in_scope
;
20782 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20783 if (attr
!= nullptr)
20785 var_decode_location (attr
, sym
, cu
);
20786 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20788 /* Fortran explicitly imports any global symbols to the local
20789 scope by DW_TAG_common_block. */
20790 if (cu
->language
== language_fortran
&& die
->parent
20791 && die
->parent
->tag
== DW_TAG_common_block
)
20794 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20795 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20796 && !dwarf2_per_objfile
->has_section_at_zero
)
20798 /* When a static variable is eliminated by the linker,
20799 the corresponding debug information is not stripped
20800 out, but the variable address is set to null;
20801 do not add such variables into symbol table. */
20803 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20805 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20806 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20807 && dwarf2_per_objfile
->can_copy
)
20809 /* A global static variable might be subject to
20810 copy relocation. We first check for a local
20811 minsym, though, because maybe the symbol was
20812 marked hidden, in which case this would not
20814 bound_minimal_symbol found
20815 = (lookup_minimal_symbol_linkage
20816 (sym
->linkage_name (), objfile
));
20817 if (found
.minsym
!= nullptr)
20818 sym
->maybe_copied
= 1;
20821 /* A variable with DW_AT_external is never static,
20822 but it may be block-scoped. */
20824 = ((cu
->list_in_scope
20825 == cu
->get_builder ()->get_file_symbols ())
20826 ? cu
->get_builder ()->get_global_symbols ()
20827 : cu
->list_in_scope
);
20830 list_to_add
= cu
->list_in_scope
;
20834 /* We do not know the address of this symbol.
20835 If it is an external symbol and we have type information
20836 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20837 The address of the variable will then be determined from
20838 the minimal symbol table whenever the variable is
20840 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20842 /* Fortran explicitly imports any global symbols to the local
20843 scope by DW_TAG_common_block. */
20844 if (cu
->language
== language_fortran
&& die
->parent
20845 && die
->parent
->tag
== DW_TAG_common_block
)
20847 /* SYMBOL_CLASS doesn't matter here because
20848 read_common_block is going to reset it. */
20850 list_to_add
= cu
->list_in_scope
;
20852 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20853 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20855 /* A variable with DW_AT_external is never static, but it
20856 may be block-scoped. */
20858 = ((cu
->list_in_scope
20859 == cu
->get_builder ()->get_file_symbols ())
20860 ? cu
->get_builder ()->get_global_symbols ()
20861 : cu
->list_in_scope
);
20863 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20865 else if (!die_is_declaration (die
, cu
))
20867 /* Use the default LOC_OPTIMIZED_OUT class. */
20868 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20870 list_to_add
= cu
->list_in_scope
;
20874 case DW_TAG_formal_parameter
:
20876 /* If we are inside a function, mark this as an argument. If
20877 not, we might be looking at an argument to an inlined function
20878 when we do not have enough information to show inlined frames;
20879 pretend it's a local variable in that case so that the user can
20881 struct context_stack
*curr
20882 = cu
->get_builder ()->get_current_context_stack ();
20883 if (curr
!= nullptr && curr
->name
!= nullptr)
20884 SYMBOL_IS_ARGUMENT (sym
) = 1;
20885 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20886 if (attr
!= nullptr)
20888 var_decode_location (attr
, sym
, cu
);
20890 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20891 if (attr
!= nullptr)
20893 dwarf2_const_value (attr
, sym
, cu
);
20896 list_to_add
= cu
->list_in_scope
;
20899 case DW_TAG_unspecified_parameters
:
20900 /* From varargs functions; gdb doesn't seem to have any
20901 interest in this information, so just ignore it for now.
20904 case DW_TAG_template_type_param
:
20906 /* Fall through. */
20907 case DW_TAG_class_type
:
20908 case DW_TAG_interface_type
:
20909 case DW_TAG_structure_type
:
20910 case DW_TAG_union_type
:
20911 case DW_TAG_set_type
:
20912 case DW_TAG_enumeration_type
:
20913 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20914 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20917 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20918 really ever be static objects: otherwise, if you try
20919 to, say, break of a class's method and you're in a file
20920 which doesn't mention that class, it won't work unless
20921 the check for all static symbols in lookup_symbol_aux
20922 saves you. See the OtherFileClass tests in
20923 gdb.c++/namespace.exp. */
20927 buildsym_compunit
*builder
= cu
->get_builder ();
20929 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20930 && cu
->language
== language_cplus
20931 ? builder
->get_global_symbols ()
20932 : cu
->list_in_scope
);
20934 /* The semantics of C++ state that "struct foo {
20935 ... }" also defines a typedef for "foo". */
20936 if (cu
->language
== language_cplus
20937 || cu
->language
== language_ada
20938 || cu
->language
== language_d
20939 || cu
->language
== language_rust
)
20941 /* The symbol's name is already allocated along
20942 with this objfile, so we don't need to
20943 duplicate it for the type. */
20944 if (SYMBOL_TYPE (sym
)->name () == 0)
20945 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
20950 case DW_TAG_typedef
:
20951 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20952 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20953 list_to_add
= cu
->list_in_scope
;
20955 case DW_TAG_base_type
:
20956 case DW_TAG_subrange_type
:
20957 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20958 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20959 list_to_add
= cu
->list_in_scope
;
20961 case DW_TAG_enumerator
:
20962 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20963 if (attr
!= nullptr)
20965 dwarf2_const_value (attr
, sym
, cu
);
20968 /* NOTE: carlton/2003-11-10: See comment above in the
20969 DW_TAG_class_type, etc. block. */
20972 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20973 && cu
->language
== language_cplus
20974 ? cu
->get_builder ()->get_global_symbols ()
20975 : cu
->list_in_scope
);
20978 case DW_TAG_imported_declaration
:
20979 case DW_TAG_namespace
:
20980 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20981 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20983 case DW_TAG_module
:
20984 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20985 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20986 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20988 case DW_TAG_common_block
:
20989 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20990 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20991 add_symbol_to_list (sym
, cu
->list_in_scope
);
20994 /* Not a tag we recognize. Hopefully we aren't processing
20995 trash data, but since we must specifically ignore things
20996 we don't recognize, there is nothing else we should do at
20998 complaint (_("unsupported tag: '%s'"),
20999 dwarf_tag_name (die
->tag
));
21005 sym
->hash_next
= objfile
->template_symbols
;
21006 objfile
->template_symbols
= sym
;
21007 list_to_add
= NULL
;
21010 if (list_to_add
!= NULL
)
21011 add_symbol_to_list (sym
, list_to_add
);
21013 /* For the benefit of old versions of GCC, check for anonymous
21014 namespaces based on the demangled name. */
21015 if (!cu
->processing_has_namespace_info
21016 && cu
->language
== language_cplus
)
21017 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21022 /* Given an attr with a DW_FORM_dataN value in host byte order,
21023 zero-extend it as appropriate for the symbol's type. The DWARF
21024 standard (v4) is not entirely clear about the meaning of using
21025 DW_FORM_dataN for a constant with a signed type, where the type is
21026 wider than the data. The conclusion of a discussion on the DWARF
21027 list was that this is unspecified. We choose to always zero-extend
21028 because that is the interpretation long in use by GCC. */
21031 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21032 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21034 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21035 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21036 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21037 LONGEST l
= DW_UNSND (attr
);
21039 if (bits
< sizeof (*value
) * 8)
21041 l
&= ((LONGEST
) 1 << bits
) - 1;
21044 else if (bits
== sizeof (*value
) * 8)
21048 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21049 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21056 /* Read a constant value from an attribute. Either set *VALUE, or if
21057 the value does not fit in *VALUE, set *BYTES - either already
21058 allocated on the objfile obstack, or newly allocated on OBSTACK,
21059 or, set *BATON, if we translated the constant to a location
21063 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21064 const char *name
, struct obstack
*obstack
,
21065 struct dwarf2_cu
*cu
,
21066 LONGEST
*value
, const gdb_byte
**bytes
,
21067 struct dwarf2_locexpr_baton
**baton
)
21069 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21070 struct comp_unit_head
*cu_header
= &cu
->header
;
21071 struct dwarf_block
*blk
;
21072 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21073 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21079 switch (attr
->form
)
21082 case DW_FORM_addrx
:
21083 case DW_FORM_GNU_addr_index
:
21087 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21088 dwarf2_const_value_length_mismatch_complaint (name
,
21089 cu_header
->addr_size
,
21090 TYPE_LENGTH (type
));
21091 /* Symbols of this form are reasonably rare, so we just
21092 piggyback on the existing location code rather than writing
21093 a new implementation of symbol_computed_ops. */
21094 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21095 (*baton
)->per_cu
= cu
->per_cu
;
21096 gdb_assert ((*baton
)->per_cu
);
21098 (*baton
)->size
= 2 + cu_header
->addr_size
;
21099 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21100 (*baton
)->data
= data
;
21102 data
[0] = DW_OP_addr
;
21103 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21104 byte_order
, DW_ADDR (attr
));
21105 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21108 case DW_FORM_string
:
21111 case DW_FORM_GNU_str_index
:
21112 case DW_FORM_GNU_strp_alt
:
21113 /* DW_STRING is already allocated on the objfile obstack, point
21115 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21117 case DW_FORM_block1
:
21118 case DW_FORM_block2
:
21119 case DW_FORM_block4
:
21120 case DW_FORM_block
:
21121 case DW_FORM_exprloc
:
21122 case DW_FORM_data16
:
21123 blk
= DW_BLOCK (attr
);
21124 if (TYPE_LENGTH (type
) != blk
->size
)
21125 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21126 TYPE_LENGTH (type
));
21127 *bytes
= blk
->data
;
21130 /* The DW_AT_const_value attributes are supposed to carry the
21131 symbol's value "represented as it would be on the target
21132 architecture." By the time we get here, it's already been
21133 converted to host endianness, so we just need to sign- or
21134 zero-extend it as appropriate. */
21135 case DW_FORM_data1
:
21136 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21138 case DW_FORM_data2
:
21139 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21141 case DW_FORM_data4
:
21142 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21144 case DW_FORM_data8
:
21145 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21148 case DW_FORM_sdata
:
21149 case DW_FORM_implicit_const
:
21150 *value
= DW_SND (attr
);
21153 case DW_FORM_udata
:
21154 *value
= DW_UNSND (attr
);
21158 complaint (_("unsupported const value attribute form: '%s'"),
21159 dwarf_form_name (attr
->form
));
21166 /* Copy constant value from an attribute to a symbol. */
21169 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21170 struct dwarf2_cu
*cu
)
21172 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21174 const gdb_byte
*bytes
;
21175 struct dwarf2_locexpr_baton
*baton
;
21177 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21178 sym
->print_name (),
21179 &objfile
->objfile_obstack
, cu
,
21180 &value
, &bytes
, &baton
);
21184 SYMBOL_LOCATION_BATON (sym
) = baton
;
21185 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21187 else if (bytes
!= NULL
)
21189 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21190 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21194 SYMBOL_VALUE (sym
) = value
;
21195 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21199 /* Return the type of the die in question using its DW_AT_type attribute. */
21201 static struct type
*
21202 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21204 struct attribute
*type_attr
;
21206 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21209 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21210 /* A missing DW_AT_type represents a void type. */
21211 return objfile_type (objfile
)->builtin_void
;
21214 return lookup_die_type (die
, type_attr
, cu
);
21217 /* True iff CU's producer generates GNAT Ada auxiliary information
21218 that allows to find parallel types through that information instead
21219 of having to do expensive parallel lookups by type name. */
21222 need_gnat_info (struct dwarf2_cu
*cu
)
21224 /* Assume that the Ada compiler was GNAT, which always produces
21225 the auxiliary information. */
21226 return (cu
->language
== language_ada
);
21229 /* Return the auxiliary type of the die in question using its
21230 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21231 attribute is not present. */
21233 static struct type
*
21234 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21236 struct attribute
*type_attr
;
21238 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21242 return lookup_die_type (die
, type_attr
, cu
);
21245 /* If DIE has a descriptive_type attribute, then set the TYPE's
21246 descriptive type accordingly. */
21249 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21250 struct dwarf2_cu
*cu
)
21252 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21254 if (descriptive_type
)
21256 ALLOCATE_GNAT_AUX_TYPE (type
);
21257 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21261 /* Return the containing type of the die in question using its
21262 DW_AT_containing_type attribute. */
21264 static struct type
*
21265 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21267 struct attribute
*type_attr
;
21268 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21270 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21272 error (_("Dwarf Error: Problem turning containing type into gdb type "
21273 "[in module %s]"), objfile_name (objfile
));
21275 return lookup_die_type (die
, type_attr
, cu
);
21278 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21280 static struct type
*
21281 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21283 struct dwarf2_per_objfile
*dwarf2_per_objfile
21284 = cu
->per_cu
->dwarf2_per_objfile
;
21285 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21288 std::string message
21289 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21290 objfile_name (objfile
),
21291 sect_offset_str (cu
->header
.sect_off
),
21292 sect_offset_str (die
->sect_off
));
21293 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21295 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21298 /* Look up the type of DIE in CU using its type attribute ATTR.
21299 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21300 DW_AT_containing_type.
21301 If there is no type substitute an error marker. */
21303 static struct type
*
21304 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21305 struct dwarf2_cu
*cu
)
21307 struct dwarf2_per_objfile
*dwarf2_per_objfile
21308 = cu
->per_cu
->dwarf2_per_objfile
;
21309 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21310 struct type
*this_type
;
21312 gdb_assert (attr
->name
== DW_AT_type
21313 || attr
->name
== DW_AT_GNAT_descriptive_type
21314 || attr
->name
== DW_AT_containing_type
);
21316 /* First see if we have it cached. */
21318 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21320 struct dwarf2_per_cu_data
*per_cu
;
21321 sect_offset sect_off
= attr
->get_ref_die_offset ();
21323 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21324 dwarf2_per_objfile
);
21325 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21327 else if (attr
->form_is_ref ())
21329 sect_offset sect_off
= attr
->get_ref_die_offset ();
21331 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21333 else if (attr
->form
== DW_FORM_ref_sig8
)
21335 ULONGEST signature
= DW_SIGNATURE (attr
);
21337 return get_signatured_type (die
, signature
, cu
);
21341 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21342 " at %s [in module %s]"),
21343 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21344 objfile_name (objfile
));
21345 return build_error_marker_type (cu
, die
);
21348 /* If not cached we need to read it in. */
21350 if (this_type
== NULL
)
21352 struct die_info
*type_die
= NULL
;
21353 struct dwarf2_cu
*type_cu
= cu
;
21355 if (attr
->form_is_ref ())
21356 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21357 if (type_die
== NULL
)
21358 return build_error_marker_type (cu
, die
);
21359 /* If we find the type now, it's probably because the type came
21360 from an inter-CU reference and the type's CU got expanded before
21362 this_type
= read_type_die (type_die
, type_cu
);
21365 /* If we still don't have a type use an error marker. */
21367 if (this_type
== NULL
)
21368 return build_error_marker_type (cu
, die
);
21373 /* Return the type in DIE, CU.
21374 Returns NULL for invalid types.
21376 This first does a lookup in die_type_hash,
21377 and only reads the die in if necessary.
21379 NOTE: This can be called when reading in partial or full symbols. */
21381 static struct type
*
21382 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21384 struct type
*this_type
;
21386 this_type
= get_die_type (die
, cu
);
21390 return read_type_die_1 (die
, cu
);
21393 /* Read the type in DIE, CU.
21394 Returns NULL for invalid types. */
21396 static struct type
*
21397 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21399 struct type
*this_type
= NULL
;
21403 case DW_TAG_class_type
:
21404 case DW_TAG_interface_type
:
21405 case DW_TAG_structure_type
:
21406 case DW_TAG_union_type
:
21407 this_type
= read_structure_type (die
, cu
);
21409 case DW_TAG_enumeration_type
:
21410 this_type
= read_enumeration_type (die
, cu
);
21412 case DW_TAG_subprogram
:
21413 case DW_TAG_subroutine_type
:
21414 case DW_TAG_inlined_subroutine
:
21415 this_type
= read_subroutine_type (die
, cu
);
21417 case DW_TAG_array_type
:
21418 this_type
= read_array_type (die
, cu
);
21420 case DW_TAG_set_type
:
21421 this_type
= read_set_type (die
, cu
);
21423 case DW_TAG_pointer_type
:
21424 this_type
= read_tag_pointer_type (die
, cu
);
21426 case DW_TAG_ptr_to_member_type
:
21427 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21429 case DW_TAG_reference_type
:
21430 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21432 case DW_TAG_rvalue_reference_type
:
21433 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21435 case DW_TAG_const_type
:
21436 this_type
= read_tag_const_type (die
, cu
);
21438 case DW_TAG_volatile_type
:
21439 this_type
= read_tag_volatile_type (die
, cu
);
21441 case DW_TAG_restrict_type
:
21442 this_type
= read_tag_restrict_type (die
, cu
);
21444 case DW_TAG_string_type
:
21445 this_type
= read_tag_string_type (die
, cu
);
21447 case DW_TAG_typedef
:
21448 this_type
= read_typedef (die
, cu
);
21450 case DW_TAG_subrange_type
:
21451 this_type
= read_subrange_type (die
, cu
);
21453 case DW_TAG_base_type
:
21454 this_type
= read_base_type (die
, cu
);
21456 case DW_TAG_unspecified_type
:
21457 this_type
= read_unspecified_type (die
, cu
);
21459 case DW_TAG_namespace
:
21460 this_type
= read_namespace_type (die
, cu
);
21462 case DW_TAG_module
:
21463 this_type
= read_module_type (die
, cu
);
21465 case DW_TAG_atomic_type
:
21466 this_type
= read_tag_atomic_type (die
, cu
);
21469 complaint (_("unexpected tag in read_type_die: '%s'"),
21470 dwarf_tag_name (die
->tag
));
21477 /* See if we can figure out if the class lives in a namespace. We do
21478 this by looking for a member function; its demangled name will
21479 contain namespace info, if there is any.
21480 Return the computed name or NULL.
21481 Space for the result is allocated on the objfile's obstack.
21482 This is the full-die version of guess_partial_die_structure_name.
21483 In this case we know DIE has no useful parent. */
21485 static const char *
21486 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21488 struct die_info
*spec_die
;
21489 struct dwarf2_cu
*spec_cu
;
21490 struct die_info
*child
;
21491 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21494 spec_die
= die_specification (die
, &spec_cu
);
21495 if (spec_die
!= NULL
)
21501 for (child
= die
->child
;
21503 child
= child
->sibling
)
21505 if (child
->tag
== DW_TAG_subprogram
)
21507 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21509 if (linkage_name
!= NULL
)
21511 gdb::unique_xmalloc_ptr
<char> actual_name
21512 (language_class_name_from_physname (cu
->language_defn
,
21514 const char *name
= NULL
;
21516 if (actual_name
!= NULL
)
21518 const char *die_name
= dwarf2_name (die
, cu
);
21520 if (die_name
!= NULL
21521 && strcmp (die_name
, actual_name
.get ()) != 0)
21523 /* Strip off the class name from the full name.
21524 We want the prefix. */
21525 int die_name_len
= strlen (die_name
);
21526 int actual_name_len
= strlen (actual_name
.get ());
21527 const char *ptr
= actual_name
.get ();
21529 /* Test for '::' as a sanity check. */
21530 if (actual_name_len
> die_name_len
+ 2
21531 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21532 name
= obstack_strndup (
21533 &objfile
->per_bfd
->storage_obstack
,
21534 ptr
, actual_name_len
- die_name_len
- 2);
21545 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21546 prefix part in such case. See
21547 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21549 static const char *
21550 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21552 struct attribute
*attr
;
21555 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21556 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21559 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21562 attr
= dw2_linkage_name_attr (die
, cu
);
21563 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21566 /* dwarf2_name had to be already called. */
21567 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21569 /* Strip the base name, keep any leading namespaces/classes. */
21570 base
= strrchr (DW_STRING (attr
), ':');
21571 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21574 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21575 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21577 &base
[-1] - DW_STRING (attr
));
21580 /* Return the name of the namespace/class that DIE is defined within,
21581 or "" if we can't tell. The caller should not xfree the result.
21583 For example, if we're within the method foo() in the following
21593 then determine_prefix on foo's die will return "N::C". */
21595 static const char *
21596 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21598 struct dwarf2_per_objfile
*dwarf2_per_objfile
21599 = cu
->per_cu
->dwarf2_per_objfile
;
21600 struct die_info
*parent
, *spec_die
;
21601 struct dwarf2_cu
*spec_cu
;
21602 struct type
*parent_type
;
21603 const char *retval
;
21605 if (cu
->language
!= language_cplus
21606 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21607 && cu
->language
!= language_rust
)
21610 retval
= anonymous_struct_prefix (die
, cu
);
21614 /* We have to be careful in the presence of DW_AT_specification.
21615 For example, with GCC 3.4, given the code
21619 // Definition of N::foo.
21623 then we'll have a tree of DIEs like this:
21625 1: DW_TAG_compile_unit
21626 2: DW_TAG_namespace // N
21627 3: DW_TAG_subprogram // declaration of N::foo
21628 4: DW_TAG_subprogram // definition of N::foo
21629 DW_AT_specification // refers to die #3
21631 Thus, when processing die #4, we have to pretend that we're in
21632 the context of its DW_AT_specification, namely the contex of die
21635 spec_die
= die_specification (die
, &spec_cu
);
21636 if (spec_die
== NULL
)
21637 parent
= die
->parent
;
21640 parent
= spec_die
->parent
;
21644 if (parent
== NULL
)
21646 else if (parent
->building_fullname
)
21649 const char *parent_name
;
21651 /* It has been seen on RealView 2.2 built binaries,
21652 DW_TAG_template_type_param types actually _defined_ as
21653 children of the parent class:
21656 template class <class Enum> Class{};
21657 Class<enum E> class_e;
21659 1: DW_TAG_class_type (Class)
21660 2: DW_TAG_enumeration_type (E)
21661 3: DW_TAG_enumerator (enum1:0)
21662 3: DW_TAG_enumerator (enum2:1)
21664 2: DW_TAG_template_type_param
21665 DW_AT_type DW_FORM_ref_udata (E)
21667 Besides being broken debug info, it can put GDB into an
21668 infinite loop. Consider:
21670 When we're building the full name for Class<E>, we'll start
21671 at Class, and go look over its template type parameters,
21672 finding E. We'll then try to build the full name of E, and
21673 reach here. We're now trying to build the full name of E,
21674 and look over the parent DIE for containing scope. In the
21675 broken case, if we followed the parent DIE of E, we'd again
21676 find Class, and once again go look at its template type
21677 arguments, etc., etc. Simply don't consider such parent die
21678 as source-level parent of this die (it can't be, the language
21679 doesn't allow it), and break the loop here. */
21680 name
= dwarf2_name (die
, cu
);
21681 parent_name
= dwarf2_name (parent
, cu
);
21682 complaint (_("template param type '%s' defined within parent '%s'"),
21683 name
? name
: "<unknown>",
21684 parent_name
? parent_name
: "<unknown>");
21688 switch (parent
->tag
)
21690 case DW_TAG_namespace
:
21691 parent_type
= read_type_die (parent
, cu
);
21692 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21693 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21694 Work around this problem here. */
21695 if (cu
->language
== language_cplus
21696 && strcmp (parent_type
->name (), "::") == 0)
21698 /* We give a name to even anonymous namespaces. */
21699 return parent_type
->name ();
21700 case DW_TAG_class_type
:
21701 case DW_TAG_interface_type
:
21702 case DW_TAG_structure_type
:
21703 case DW_TAG_union_type
:
21704 case DW_TAG_module
:
21705 parent_type
= read_type_die (parent
, cu
);
21706 if (parent_type
->name () != NULL
)
21707 return parent_type
->name ();
21709 /* An anonymous structure is only allowed non-static data
21710 members; no typedefs, no member functions, et cetera.
21711 So it does not need a prefix. */
21713 case DW_TAG_compile_unit
:
21714 case DW_TAG_partial_unit
:
21715 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21716 if (cu
->language
== language_cplus
21717 && !dwarf2_per_objfile
->types
.empty ()
21718 && die
->child
!= NULL
21719 && (die
->tag
== DW_TAG_class_type
21720 || die
->tag
== DW_TAG_structure_type
21721 || die
->tag
== DW_TAG_union_type
))
21723 const char *name
= guess_full_die_structure_name (die
, cu
);
21728 case DW_TAG_subprogram
:
21729 /* Nested subroutines in Fortran get a prefix with the name
21730 of the parent's subroutine. */
21731 if (cu
->language
== language_fortran
)
21733 if ((die
->tag
== DW_TAG_subprogram
)
21734 && (dwarf2_name (parent
, cu
) != NULL
))
21735 return dwarf2_name (parent
, cu
);
21737 return determine_prefix (parent
, cu
);
21738 case DW_TAG_enumeration_type
:
21739 parent_type
= read_type_die (parent
, cu
);
21740 if (TYPE_DECLARED_CLASS (parent_type
))
21742 if (parent_type
->name () != NULL
)
21743 return parent_type
->name ();
21746 /* Fall through. */
21748 return determine_prefix (parent
, cu
);
21752 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21753 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21754 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21755 an obconcat, otherwise allocate storage for the result. The CU argument is
21756 used to determine the language and hence, the appropriate separator. */
21758 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21761 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21762 int physname
, struct dwarf2_cu
*cu
)
21764 const char *lead
= "";
21767 if (suffix
== NULL
|| suffix
[0] == '\0'
21768 || prefix
== NULL
|| prefix
[0] == '\0')
21770 else if (cu
->language
== language_d
)
21772 /* For D, the 'main' function could be defined in any module, but it
21773 should never be prefixed. */
21774 if (strcmp (suffix
, "D main") == 0)
21782 else if (cu
->language
== language_fortran
&& physname
)
21784 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21785 DW_AT_MIPS_linkage_name is preferred and used instead. */
21793 if (prefix
== NULL
)
21795 if (suffix
== NULL
)
21802 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21804 strcpy (retval
, lead
);
21805 strcat (retval
, prefix
);
21806 strcat (retval
, sep
);
21807 strcat (retval
, suffix
);
21812 /* We have an obstack. */
21813 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21817 /* Get name of a die, return NULL if not found. */
21819 static const char *
21820 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21821 struct objfile
*objfile
)
21823 if (name
&& cu
->language
== language_cplus
)
21825 gdb::unique_xmalloc_ptr
<char> canon_name
21826 = cp_canonicalize_string (name
);
21828 if (canon_name
!= nullptr)
21829 name
= objfile
->intern (canon_name
.get ());
21835 /* Get name of a die, return NULL if not found.
21836 Anonymous namespaces are converted to their magic string. */
21838 static const char *
21839 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21841 struct attribute
*attr
;
21842 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21844 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21845 if ((!attr
|| !DW_STRING (attr
))
21846 && die
->tag
!= DW_TAG_namespace
21847 && die
->tag
!= DW_TAG_class_type
21848 && die
->tag
!= DW_TAG_interface_type
21849 && die
->tag
!= DW_TAG_structure_type
21850 && die
->tag
!= DW_TAG_union_type
)
21855 case DW_TAG_compile_unit
:
21856 case DW_TAG_partial_unit
:
21857 /* Compilation units have a DW_AT_name that is a filename, not
21858 a source language identifier. */
21859 case DW_TAG_enumeration_type
:
21860 case DW_TAG_enumerator
:
21861 /* These tags always have simple identifiers already; no need
21862 to canonicalize them. */
21863 return DW_STRING (attr
);
21865 case DW_TAG_namespace
:
21866 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21867 return DW_STRING (attr
);
21868 return CP_ANONYMOUS_NAMESPACE_STR
;
21870 case DW_TAG_class_type
:
21871 case DW_TAG_interface_type
:
21872 case DW_TAG_structure_type
:
21873 case DW_TAG_union_type
:
21874 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21875 structures or unions. These were of the form "._%d" in GCC 4.1,
21876 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21877 and GCC 4.4. We work around this problem by ignoring these. */
21878 if (attr
&& DW_STRING (attr
)
21879 && (startswith (DW_STRING (attr
), "._")
21880 || startswith (DW_STRING (attr
), "<anonymous")))
21883 /* GCC might emit a nameless typedef that has a linkage name. See
21884 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21885 if (!attr
|| DW_STRING (attr
) == NULL
)
21887 attr
= dw2_linkage_name_attr (die
, cu
);
21888 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21891 /* Avoid demangling DW_STRING (attr) the second time on a second
21892 call for the same DIE. */
21893 if (!DW_STRING_IS_CANONICAL (attr
))
21895 gdb::unique_xmalloc_ptr
<char> demangled
21896 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21897 if (demangled
== nullptr)
21900 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21901 DW_STRING_IS_CANONICAL (attr
) = 1;
21904 /* Strip any leading namespaces/classes, keep only the base name.
21905 DW_AT_name for named DIEs does not contain the prefixes. */
21906 const char *base
= strrchr (DW_STRING (attr
), ':');
21907 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21910 return DW_STRING (attr
);
21918 if (!DW_STRING_IS_CANONICAL (attr
))
21920 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21922 DW_STRING_IS_CANONICAL (attr
) = 1;
21924 return DW_STRING (attr
);
21927 /* Return the die that this die in an extension of, or NULL if there
21928 is none. *EXT_CU is the CU containing DIE on input, and the CU
21929 containing the return value on output. */
21931 static struct die_info
*
21932 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21934 struct attribute
*attr
;
21936 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21940 return follow_die_ref (die
, attr
, ext_cu
);
21944 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21948 print_spaces (indent
, f
);
21949 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21950 dwarf_tag_name (die
->tag
), die
->abbrev
,
21951 sect_offset_str (die
->sect_off
));
21953 if (die
->parent
!= NULL
)
21955 print_spaces (indent
, f
);
21956 fprintf_unfiltered (f
, " parent at offset: %s\n",
21957 sect_offset_str (die
->parent
->sect_off
));
21960 print_spaces (indent
, f
);
21961 fprintf_unfiltered (f
, " has children: %s\n",
21962 dwarf_bool_name (die
->child
!= NULL
));
21964 print_spaces (indent
, f
);
21965 fprintf_unfiltered (f
, " attributes:\n");
21967 for (i
= 0; i
< die
->num_attrs
; ++i
)
21969 print_spaces (indent
, f
);
21970 fprintf_unfiltered (f
, " %s (%s) ",
21971 dwarf_attr_name (die
->attrs
[i
].name
),
21972 dwarf_form_name (die
->attrs
[i
].form
));
21974 switch (die
->attrs
[i
].form
)
21977 case DW_FORM_addrx
:
21978 case DW_FORM_GNU_addr_index
:
21979 fprintf_unfiltered (f
, "address: ");
21980 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21982 case DW_FORM_block2
:
21983 case DW_FORM_block4
:
21984 case DW_FORM_block
:
21985 case DW_FORM_block1
:
21986 fprintf_unfiltered (f
, "block: size %s",
21987 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21989 case DW_FORM_exprloc
:
21990 fprintf_unfiltered (f
, "expression: size %s",
21991 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21993 case DW_FORM_data16
:
21994 fprintf_unfiltered (f
, "constant of 16 bytes");
21996 case DW_FORM_ref_addr
:
21997 fprintf_unfiltered (f
, "ref address: ");
21998 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22000 case DW_FORM_GNU_ref_alt
:
22001 fprintf_unfiltered (f
, "alt ref address: ");
22002 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22008 case DW_FORM_ref_udata
:
22009 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22010 (long) (DW_UNSND (&die
->attrs
[i
])));
22012 case DW_FORM_data1
:
22013 case DW_FORM_data2
:
22014 case DW_FORM_data4
:
22015 case DW_FORM_data8
:
22016 case DW_FORM_udata
:
22017 case DW_FORM_sdata
:
22018 fprintf_unfiltered (f
, "constant: %s",
22019 pulongest (DW_UNSND (&die
->attrs
[i
])));
22021 case DW_FORM_sec_offset
:
22022 fprintf_unfiltered (f
, "section offset: %s",
22023 pulongest (DW_UNSND (&die
->attrs
[i
])));
22025 case DW_FORM_ref_sig8
:
22026 fprintf_unfiltered (f
, "signature: %s",
22027 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22029 case DW_FORM_string
:
22031 case DW_FORM_line_strp
:
22033 case DW_FORM_GNU_str_index
:
22034 case DW_FORM_GNU_strp_alt
:
22035 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22036 DW_STRING (&die
->attrs
[i
])
22037 ? DW_STRING (&die
->attrs
[i
]) : "",
22038 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22041 if (DW_UNSND (&die
->attrs
[i
]))
22042 fprintf_unfiltered (f
, "flag: TRUE");
22044 fprintf_unfiltered (f
, "flag: FALSE");
22046 case DW_FORM_flag_present
:
22047 fprintf_unfiltered (f
, "flag: TRUE");
22049 case DW_FORM_indirect
:
22050 /* The reader will have reduced the indirect form to
22051 the "base form" so this form should not occur. */
22052 fprintf_unfiltered (f
,
22053 "unexpected attribute form: DW_FORM_indirect");
22055 case DW_FORM_implicit_const
:
22056 fprintf_unfiltered (f
, "constant: %s",
22057 plongest (DW_SND (&die
->attrs
[i
])));
22060 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22061 die
->attrs
[i
].form
);
22064 fprintf_unfiltered (f
, "\n");
22069 dump_die_for_error (struct die_info
*die
)
22071 dump_die_shallow (gdb_stderr
, 0, die
);
22075 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22077 int indent
= level
* 4;
22079 gdb_assert (die
!= NULL
);
22081 if (level
>= max_level
)
22084 dump_die_shallow (f
, indent
, die
);
22086 if (die
->child
!= NULL
)
22088 print_spaces (indent
, f
);
22089 fprintf_unfiltered (f
, " Children:");
22090 if (level
+ 1 < max_level
)
22092 fprintf_unfiltered (f
, "\n");
22093 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22097 fprintf_unfiltered (f
,
22098 " [not printed, max nesting level reached]\n");
22102 if (die
->sibling
!= NULL
&& level
> 0)
22104 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22108 /* This is called from the pdie macro in gdbinit.in.
22109 It's not static so gcc will keep a copy callable from gdb. */
22112 dump_die (struct die_info
*die
, int max_level
)
22114 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22118 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22122 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22123 to_underlying (die
->sect_off
),
22129 /* Follow reference or signature attribute ATTR of SRC_DIE.
22130 On entry *REF_CU is the CU of SRC_DIE.
22131 On exit *REF_CU is the CU of the result. */
22133 static struct die_info
*
22134 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22135 struct dwarf2_cu
**ref_cu
)
22137 struct die_info
*die
;
22139 if (attr
->form_is_ref ())
22140 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22141 else if (attr
->form
== DW_FORM_ref_sig8
)
22142 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22145 dump_die_for_error (src_die
);
22146 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22147 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22153 /* Follow reference OFFSET.
22154 On entry *REF_CU is the CU of the source die referencing OFFSET.
22155 On exit *REF_CU is the CU of the result.
22156 Returns NULL if OFFSET is invalid. */
22158 static struct die_info
*
22159 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22160 struct dwarf2_cu
**ref_cu
)
22162 struct die_info temp_die
;
22163 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22164 struct dwarf2_per_objfile
*dwarf2_per_objfile
22165 = cu
->per_cu
->dwarf2_per_objfile
;
22167 gdb_assert (cu
->per_cu
!= NULL
);
22171 if (cu
->per_cu
->is_debug_types
)
22173 /* .debug_types CUs cannot reference anything outside their CU.
22174 If they need to, they have to reference a signatured type via
22175 DW_FORM_ref_sig8. */
22176 if (!cu
->header
.offset_in_cu_p (sect_off
))
22179 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22180 || !cu
->header
.offset_in_cu_p (sect_off
))
22182 struct dwarf2_per_cu_data
*per_cu
;
22184 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22185 dwarf2_per_objfile
);
22187 /* If necessary, add it to the queue and load its DIEs. */
22188 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22189 load_full_comp_unit (per_cu
, false, cu
->language
);
22191 target_cu
= per_cu
->cu
;
22193 else if (cu
->dies
== NULL
)
22195 /* We're loading full DIEs during partial symbol reading. */
22196 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22197 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22200 *ref_cu
= target_cu
;
22201 temp_die
.sect_off
= sect_off
;
22203 if (target_cu
!= cu
)
22204 target_cu
->ancestor
= cu
;
22206 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22208 to_underlying (sect_off
));
22211 /* Follow reference attribute ATTR of SRC_DIE.
22212 On entry *REF_CU is the CU of SRC_DIE.
22213 On exit *REF_CU is the CU of the result. */
22215 static struct die_info
*
22216 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22217 struct dwarf2_cu
**ref_cu
)
22219 sect_offset sect_off
= attr
->get_ref_die_offset ();
22220 struct dwarf2_cu
*cu
= *ref_cu
;
22221 struct die_info
*die
;
22223 die
= follow_die_offset (sect_off
,
22224 (attr
->form
== DW_FORM_GNU_ref_alt
22225 || cu
->per_cu
->is_dwz
),
22228 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22229 "at %s [in module %s]"),
22230 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22231 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22238 struct dwarf2_locexpr_baton
22239 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22240 dwarf2_per_cu_data
*per_cu
,
22241 CORE_ADDR (*get_frame_pc
) (void *baton
),
22242 void *baton
, bool resolve_abstract_p
)
22244 struct dwarf2_cu
*cu
;
22245 struct die_info
*die
;
22246 struct attribute
*attr
;
22247 struct dwarf2_locexpr_baton retval
;
22248 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22249 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22251 if (per_cu
->cu
== NULL
)
22252 load_cu (per_cu
, false);
22256 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22257 Instead just throw an error, not much else we can do. */
22258 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22259 sect_offset_str (sect_off
), objfile_name (objfile
));
22262 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22264 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22265 sect_offset_str (sect_off
), objfile_name (objfile
));
22267 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22268 if (!attr
&& resolve_abstract_p
22269 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22270 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22272 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22273 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22274 struct gdbarch
*gdbarch
= objfile
->arch ();
22276 for (const auto &cand_off
22277 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22279 struct dwarf2_cu
*cand_cu
= cu
;
22280 struct die_info
*cand
22281 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22284 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22287 CORE_ADDR pc_low
, pc_high
;
22288 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22289 if (pc_low
== ((CORE_ADDR
) -1))
22291 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22292 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22293 if (!(pc_low
<= pc
&& pc
< pc_high
))
22297 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22304 /* DWARF: "If there is no such attribute, then there is no effect.".
22305 DATA is ignored if SIZE is 0. */
22307 retval
.data
= NULL
;
22310 else if (attr
->form_is_section_offset ())
22312 struct dwarf2_loclist_baton loclist_baton
;
22313 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22316 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22318 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22320 retval
.size
= size
;
22324 if (!attr
->form_is_block ())
22325 error (_("Dwarf Error: DIE at %s referenced in module %s "
22326 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22327 sect_offset_str (sect_off
), objfile_name (objfile
));
22329 retval
.data
= DW_BLOCK (attr
)->data
;
22330 retval
.size
= DW_BLOCK (attr
)->size
;
22332 retval
.per_cu
= cu
->per_cu
;
22334 age_cached_comp_units (dwarf2_per_objfile
);
22341 struct dwarf2_locexpr_baton
22342 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22343 dwarf2_per_cu_data
*per_cu
,
22344 CORE_ADDR (*get_frame_pc
) (void *baton
),
22347 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22349 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22352 /* Write a constant of a given type as target-ordered bytes into
22355 static const gdb_byte
*
22356 write_constant_as_bytes (struct obstack
*obstack
,
22357 enum bfd_endian byte_order
,
22364 *len
= TYPE_LENGTH (type
);
22365 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22366 store_unsigned_integer (result
, *len
, byte_order
, value
);
22374 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22375 dwarf2_per_cu_data
*per_cu
,
22379 struct dwarf2_cu
*cu
;
22380 struct die_info
*die
;
22381 struct attribute
*attr
;
22382 const gdb_byte
*result
= NULL
;
22385 enum bfd_endian byte_order
;
22386 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22388 if (per_cu
->cu
== NULL
)
22389 load_cu (per_cu
, false);
22393 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22394 Instead just throw an error, not much else we can do. */
22395 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22396 sect_offset_str (sect_off
), objfile_name (objfile
));
22399 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22401 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22402 sect_offset_str (sect_off
), objfile_name (objfile
));
22404 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22408 byte_order
= (bfd_big_endian (objfile
->obfd
)
22409 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22411 switch (attr
->form
)
22414 case DW_FORM_addrx
:
22415 case DW_FORM_GNU_addr_index
:
22419 *len
= cu
->header
.addr_size
;
22420 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22421 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22425 case DW_FORM_string
:
22428 case DW_FORM_GNU_str_index
:
22429 case DW_FORM_GNU_strp_alt
:
22430 /* DW_STRING is already allocated on the objfile obstack, point
22432 result
= (const gdb_byte
*) DW_STRING (attr
);
22433 *len
= strlen (DW_STRING (attr
));
22435 case DW_FORM_block1
:
22436 case DW_FORM_block2
:
22437 case DW_FORM_block4
:
22438 case DW_FORM_block
:
22439 case DW_FORM_exprloc
:
22440 case DW_FORM_data16
:
22441 result
= DW_BLOCK (attr
)->data
;
22442 *len
= DW_BLOCK (attr
)->size
;
22445 /* The DW_AT_const_value attributes are supposed to carry the
22446 symbol's value "represented as it would be on the target
22447 architecture." By the time we get here, it's already been
22448 converted to host endianness, so we just need to sign- or
22449 zero-extend it as appropriate. */
22450 case DW_FORM_data1
:
22451 type
= die_type (die
, cu
);
22452 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22453 if (result
== NULL
)
22454 result
= write_constant_as_bytes (obstack
, byte_order
,
22457 case DW_FORM_data2
:
22458 type
= die_type (die
, cu
);
22459 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22460 if (result
== NULL
)
22461 result
= write_constant_as_bytes (obstack
, byte_order
,
22464 case DW_FORM_data4
:
22465 type
= die_type (die
, cu
);
22466 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22467 if (result
== NULL
)
22468 result
= write_constant_as_bytes (obstack
, byte_order
,
22471 case DW_FORM_data8
:
22472 type
= die_type (die
, cu
);
22473 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22474 if (result
== NULL
)
22475 result
= write_constant_as_bytes (obstack
, byte_order
,
22479 case DW_FORM_sdata
:
22480 case DW_FORM_implicit_const
:
22481 type
= die_type (die
, cu
);
22482 result
= write_constant_as_bytes (obstack
, byte_order
,
22483 type
, DW_SND (attr
), len
);
22486 case DW_FORM_udata
:
22487 type
= die_type (die
, cu
);
22488 result
= write_constant_as_bytes (obstack
, byte_order
,
22489 type
, DW_UNSND (attr
), len
);
22493 complaint (_("unsupported const value attribute form: '%s'"),
22494 dwarf_form_name (attr
->form
));
22504 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22505 dwarf2_per_cu_data
*per_cu
)
22507 struct dwarf2_cu
*cu
;
22508 struct die_info
*die
;
22510 if (per_cu
->cu
== NULL
)
22511 load_cu (per_cu
, false);
22516 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22520 return die_type (die
, cu
);
22526 dwarf2_get_die_type (cu_offset die_offset
,
22527 struct dwarf2_per_cu_data
*per_cu
)
22529 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22530 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22533 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22534 On entry *REF_CU is the CU of SRC_DIE.
22535 On exit *REF_CU is the CU of the result.
22536 Returns NULL if the referenced DIE isn't found. */
22538 static struct die_info
*
22539 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22540 struct dwarf2_cu
**ref_cu
)
22542 struct die_info temp_die
;
22543 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22544 struct die_info
*die
;
22546 /* While it might be nice to assert sig_type->type == NULL here,
22547 we can get here for DW_AT_imported_declaration where we need
22548 the DIE not the type. */
22550 /* If necessary, add it to the queue and load its DIEs. */
22552 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22553 read_signatured_type (sig_type
);
22555 sig_cu
= sig_type
->per_cu
.cu
;
22556 gdb_assert (sig_cu
!= NULL
);
22557 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22558 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22559 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22560 to_underlying (temp_die
.sect_off
));
22563 struct dwarf2_per_objfile
*dwarf2_per_objfile
22564 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22566 /* For .gdb_index version 7 keep track of included TUs.
22567 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22568 if (dwarf2_per_objfile
->index_table
!= NULL
22569 && dwarf2_per_objfile
->index_table
->version
<= 7)
22571 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22576 sig_cu
->ancestor
= cu
;
22584 /* Follow signatured type referenced by ATTR in SRC_DIE.
22585 On entry *REF_CU is the CU of SRC_DIE.
22586 On exit *REF_CU is the CU of the result.
22587 The result is the DIE of the type.
22588 If the referenced type cannot be found an error is thrown. */
22590 static struct die_info
*
22591 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22592 struct dwarf2_cu
**ref_cu
)
22594 ULONGEST signature
= DW_SIGNATURE (attr
);
22595 struct signatured_type
*sig_type
;
22596 struct die_info
*die
;
22598 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22600 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22601 /* sig_type will be NULL if the signatured type is missing from
22603 if (sig_type
== NULL
)
22605 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22606 " from DIE at %s [in module %s]"),
22607 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22608 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22611 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22614 dump_die_for_error (src_die
);
22615 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22616 " from DIE at %s [in module %s]"),
22617 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22618 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22624 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22625 reading in and processing the type unit if necessary. */
22627 static struct type
*
22628 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22629 struct dwarf2_cu
*cu
)
22631 struct dwarf2_per_objfile
*dwarf2_per_objfile
22632 = cu
->per_cu
->dwarf2_per_objfile
;
22633 struct signatured_type
*sig_type
;
22634 struct dwarf2_cu
*type_cu
;
22635 struct die_info
*type_die
;
22638 sig_type
= lookup_signatured_type (cu
, signature
);
22639 /* sig_type will be NULL if the signatured type is missing from
22641 if (sig_type
== NULL
)
22643 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22644 " from DIE at %s [in module %s]"),
22645 hex_string (signature
), sect_offset_str (die
->sect_off
),
22646 objfile_name (dwarf2_per_objfile
->objfile
));
22647 return build_error_marker_type (cu
, die
);
22650 /* If we already know the type we're done. */
22651 if (sig_type
->type
!= NULL
)
22652 return sig_type
->type
;
22655 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22656 if (type_die
!= NULL
)
22658 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22659 is created. This is important, for example, because for c++ classes
22660 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22661 type
= read_type_die (type_die
, type_cu
);
22664 complaint (_("Dwarf Error: Cannot build signatured type %s"
22665 " referenced from DIE at %s [in module %s]"),
22666 hex_string (signature
), sect_offset_str (die
->sect_off
),
22667 objfile_name (dwarf2_per_objfile
->objfile
));
22668 type
= build_error_marker_type (cu
, die
);
22673 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22674 " from DIE at %s [in module %s]"),
22675 hex_string (signature
), sect_offset_str (die
->sect_off
),
22676 objfile_name (dwarf2_per_objfile
->objfile
));
22677 type
= build_error_marker_type (cu
, die
);
22679 sig_type
->type
= type
;
22684 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22685 reading in and processing the type unit if necessary. */
22687 static struct type
*
22688 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22689 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22691 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22692 if (attr
->form_is_ref ())
22694 struct dwarf2_cu
*type_cu
= cu
;
22695 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22697 return read_type_die (type_die
, type_cu
);
22699 else if (attr
->form
== DW_FORM_ref_sig8
)
22701 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22705 struct dwarf2_per_objfile
*dwarf2_per_objfile
22706 = cu
->per_cu
->dwarf2_per_objfile
;
22708 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22709 " at %s [in module %s]"),
22710 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22711 objfile_name (dwarf2_per_objfile
->objfile
));
22712 return build_error_marker_type (cu
, die
);
22716 /* Load the DIEs associated with type unit PER_CU into memory. */
22719 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22721 struct signatured_type
*sig_type
;
22723 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22724 gdb_assert (! per_cu
->type_unit_group_p ());
22726 /* We have the per_cu, but we need the signatured_type.
22727 Fortunately this is an easy translation. */
22728 gdb_assert (per_cu
->is_debug_types
);
22729 sig_type
= (struct signatured_type
*) per_cu
;
22731 gdb_assert (per_cu
->cu
== NULL
);
22733 read_signatured_type (sig_type
);
22735 gdb_assert (per_cu
->cu
!= NULL
);
22738 /* Read in a signatured type and build its CU and DIEs.
22739 If the type is a stub for the real type in a DWO file,
22740 read in the real type from the DWO file as well. */
22743 read_signatured_type (struct signatured_type
*sig_type
)
22745 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22747 gdb_assert (per_cu
->is_debug_types
);
22748 gdb_assert (per_cu
->cu
== NULL
);
22750 cutu_reader
reader (per_cu
, NULL
, 0, false);
22752 if (!reader
.dummy_p
)
22754 struct dwarf2_cu
*cu
= reader
.cu
;
22755 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22757 gdb_assert (cu
->die_hash
== NULL
);
22759 htab_create_alloc_ex (cu
->header
.length
/ 12,
22763 &cu
->comp_unit_obstack
,
22764 hashtab_obstack_allocate
,
22765 dummy_obstack_deallocate
);
22767 if (reader
.comp_unit_die
->has_children
)
22768 reader
.comp_unit_die
->child
22769 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22770 reader
.comp_unit_die
);
22771 cu
->dies
= reader
.comp_unit_die
;
22772 /* comp_unit_die is not stored in die_hash, no need. */
22774 /* We try not to read any attributes in this function, because
22775 not all CUs needed for references have been loaded yet, and
22776 symbol table processing isn't initialized. But we have to
22777 set the CU language, or we won't be able to build types
22778 correctly. Similarly, if we do not read the producer, we can
22779 not apply producer-specific interpretation. */
22780 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22785 sig_type
->per_cu
.tu_read
= 1;
22788 /* Decode simple location descriptions.
22789 Given a pointer to a dwarf block that defines a location, compute
22790 the location and return the value. If COMPUTED is non-null, it is
22791 set to true to indicate that decoding was successful, and false
22792 otherwise. If COMPUTED is null, then this function may emit a
22796 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22798 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22800 size_t size
= blk
->size
;
22801 const gdb_byte
*data
= blk
->data
;
22802 CORE_ADDR stack
[64];
22804 unsigned int bytes_read
, unsnd
;
22807 if (computed
!= nullptr)
22813 stack
[++stacki
] = 0;
22852 stack
[++stacki
] = op
- DW_OP_lit0
;
22887 stack
[++stacki
] = op
- DW_OP_reg0
;
22890 if (computed
== nullptr)
22891 dwarf2_complex_location_expr_complaint ();
22898 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22900 stack
[++stacki
] = unsnd
;
22903 if (computed
== nullptr)
22904 dwarf2_complex_location_expr_complaint ();
22911 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22916 case DW_OP_const1u
:
22917 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22921 case DW_OP_const1s
:
22922 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22926 case DW_OP_const2u
:
22927 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22931 case DW_OP_const2s
:
22932 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22936 case DW_OP_const4u
:
22937 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22941 case DW_OP_const4s
:
22942 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22946 case DW_OP_const8u
:
22947 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22952 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22958 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22963 stack
[stacki
+ 1] = stack
[stacki
];
22968 stack
[stacki
- 1] += stack
[stacki
];
22972 case DW_OP_plus_uconst
:
22973 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22979 stack
[stacki
- 1] -= stack
[stacki
];
22984 /* If we're not the last op, then we definitely can't encode
22985 this using GDB's address_class enum. This is valid for partial
22986 global symbols, although the variable's address will be bogus
22990 if (computed
== nullptr)
22991 dwarf2_complex_location_expr_complaint ();
22997 case DW_OP_GNU_push_tls_address
:
22998 case DW_OP_form_tls_address
:
22999 /* The top of the stack has the offset from the beginning
23000 of the thread control block at which the variable is located. */
23001 /* Nothing should follow this operator, so the top of stack would
23003 /* This is valid for partial global symbols, but the variable's
23004 address will be bogus in the psymtab. Make it always at least
23005 non-zero to not look as a variable garbage collected by linker
23006 which have DW_OP_addr 0. */
23009 if (computed
== nullptr)
23010 dwarf2_complex_location_expr_complaint ();
23017 case DW_OP_GNU_uninit
:
23018 if (computed
!= nullptr)
23023 case DW_OP_GNU_addr_index
:
23024 case DW_OP_GNU_const_index
:
23025 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23031 if (computed
== nullptr)
23033 const char *name
= get_DW_OP_name (op
);
23036 complaint (_("unsupported stack op: '%s'"),
23039 complaint (_("unsupported stack op: '%02x'"),
23043 return (stack
[stacki
]);
23046 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23047 outside of the allocated space. Also enforce minimum>0. */
23048 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23050 if (computed
== nullptr)
23051 complaint (_("location description stack overflow"));
23057 if (computed
== nullptr)
23058 complaint (_("location description stack underflow"));
23063 if (computed
!= nullptr)
23065 return (stack
[stacki
]);
23068 /* memory allocation interface */
23070 static struct dwarf_block
*
23071 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23073 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23076 static struct die_info
*
23077 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23079 struct die_info
*die
;
23080 size_t size
= sizeof (struct die_info
);
23083 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23085 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23086 memset (die
, 0, sizeof (struct die_info
));
23092 /* Macro support. */
23094 /* An overload of dwarf_decode_macros that finds the correct section
23095 and ensures it is read in before calling the other overload. */
23098 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23099 int section_is_gnu
)
23101 struct dwarf2_per_objfile
*dwarf2_per_objfile
23102 = cu
->per_cu
->dwarf2_per_objfile
;
23103 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23104 const struct line_header
*lh
= cu
->line_header
;
23105 unsigned int offset_size
= cu
->header
.offset_size
;
23106 struct dwarf2_section_info
*section
;
23107 const char *section_name
;
23109 if (cu
->dwo_unit
!= nullptr)
23111 if (section_is_gnu
)
23113 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23114 section_name
= ".debug_macro.dwo";
23118 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23119 section_name
= ".debug_macinfo.dwo";
23124 if (section_is_gnu
)
23126 section
= &dwarf2_per_objfile
->macro
;
23127 section_name
= ".debug_macro";
23131 section
= &dwarf2_per_objfile
->macinfo
;
23132 section_name
= ".debug_macinfo";
23136 section
->read (objfile
);
23137 if (section
->buffer
== nullptr)
23139 complaint (_("missing %s section"), section_name
);
23143 buildsym_compunit
*builder
= cu
->get_builder ();
23145 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23146 offset_size
, offset
, section_is_gnu
);
23149 /* Return the .debug_loc section to use for CU.
23150 For DWO files use .debug_loc.dwo. */
23152 static struct dwarf2_section_info
*
23153 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23155 struct dwarf2_per_objfile
*dwarf2_per_objfile
23156 = cu
->per_cu
->dwarf2_per_objfile
;
23160 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23162 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23164 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23165 : &dwarf2_per_objfile
->loc
);
23168 /* A helper function that fills in a dwarf2_loclist_baton. */
23171 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23172 struct dwarf2_loclist_baton
*baton
,
23173 const struct attribute
*attr
)
23175 struct dwarf2_per_objfile
*dwarf2_per_objfile
23176 = cu
->per_cu
->dwarf2_per_objfile
;
23177 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23179 section
->read (dwarf2_per_objfile
->objfile
);
23181 baton
->per_cu
= cu
->per_cu
;
23182 gdb_assert (baton
->per_cu
);
23183 /* We don't know how long the location list is, but make sure we
23184 don't run off the edge of the section. */
23185 baton
->size
= section
->size
- DW_UNSND (attr
);
23186 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23187 if (cu
->base_address
.has_value ())
23188 baton
->base_address
= *cu
->base_address
;
23190 baton
->base_address
= 0;
23191 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23195 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23196 struct dwarf2_cu
*cu
, int is_block
)
23198 struct dwarf2_per_objfile
*dwarf2_per_objfile
23199 = cu
->per_cu
->dwarf2_per_objfile
;
23200 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23201 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23203 if (attr
->form_is_section_offset ()
23204 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23205 the section. If so, fall through to the complaint in the
23207 && DW_UNSND (attr
) < section
->get_size (objfile
))
23209 struct dwarf2_loclist_baton
*baton
;
23211 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23213 fill_in_loclist_baton (cu
, baton
, attr
);
23215 if (!cu
->base_address
.has_value ())
23216 complaint (_("Location list used without "
23217 "specifying the CU base address."));
23219 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23220 ? dwarf2_loclist_block_index
23221 : dwarf2_loclist_index
);
23222 SYMBOL_LOCATION_BATON (sym
) = baton
;
23226 struct dwarf2_locexpr_baton
*baton
;
23228 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23229 baton
->per_cu
= cu
->per_cu
;
23230 gdb_assert (baton
->per_cu
);
23232 if (attr
->form_is_block ())
23234 /* Note that we're just copying the block's data pointer
23235 here, not the actual data. We're still pointing into the
23236 info_buffer for SYM's objfile; right now we never release
23237 that buffer, but when we do clean up properly this may
23239 baton
->size
= DW_BLOCK (attr
)->size
;
23240 baton
->data
= DW_BLOCK (attr
)->data
;
23244 dwarf2_invalid_attrib_class_complaint ("location description",
23245 sym
->natural_name ());
23249 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23250 ? dwarf2_locexpr_block_index
23251 : dwarf2_locexpr_index
);
23252 SYMBOL_LOCATION_BATON (sym
) = baton
;
23259 dwarf2_per_cu_data::objfile () const
23261 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23263 /* Return the master objfile, so that we can report and look up the
23264 correct file containing this variable. */
23265 if (objfile
->separate_debug_objfile_backlink
)
23266 objfile
= objfile
->separate_debug_objfile_backlink
;
23271 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
23272 (CU_HEADERP is unused in such case) or prepare a temporary copy at
23273 CU_HEADERP first. */
23275 static const struct comp_unit_head
*
23276 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
23277 const struct dwarf2_per_cu_data
*per_cu
)
23279 const gdb_byte
*info_ptr
;
23282 return &per_cu
->cu
->header
;
23284 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
23286 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
23287 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
23288 rcuh_kind::COMPILE
);
23296 dwarf2_per_cu_data::addr_size () const
23298 struct comp_unit_head cu_header_local
;
23299 const struct comp_unit_head
*cu_headerp
;
23301 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23303 return cu_headerp
->addr_size
;
23309 dwarf2_per_cu_data::offset_size () const
23311 struct comp_unit_head cu_header_local
;
23312 const struct comp_unit_head
*cu_headerp
;
23314 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23316 return cu_headerp
->offset_size
;
23322 dwarf2_per_cu_data::ref_addr_size () const
23324 struct comp_unit_head cu_header_local
;
23325 const struct comp_unit_head
*cu_headerp
;
23327 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23329 if (cu_headerp
->version
== 2)
23330 return cu_headerp
->addr_size
;
23332 return cu_headerp
->offset_size
;
23338 dwarf2_per_cu_data::text_offset () const
23340 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23342 return objfile
->text_section_offset ();
23348 dwarf2_per_cu_data::addr_type () const
23350 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23351 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23352 struct type
*addr_type
= lookup_pointer_type (void_type
);
23353 int addr_size
= this->addr_size ();
23355 if (TYPE_LENGTH (addr_type
) == addr_size
)
23358 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23362 /* A helper function for dwarf2_find_containing_comp_unit that returns
23363 the index of the result, and that searches a vector. It will
23364 return a result even if the offset in question does not actually
23365 occur in any CU. This is separate so that it can be unit
23369 dwarf2_find_containing_comp_unit
23370 (sect_offset sect_off
,
23371 unsigned int offset_in_dwz
,
23372 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23377 high
= all_comp_units
.size () - 1;
23380 struct dwarf2_per_cu_data
*mid_cu
;
23381 int mid
= low
+ (high
- low
) / 2;
23383 mid_cu
= all_comp_units
[mid
];
23384 if (mid_cu
->is_dwz
> offset_in_dwz
23385 || (mid_cu
->is_dwz
== offset_in_dwz
23386 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23391 gdb_assert (low
== high
);
23395 /* Locate the .debug_info compilation unit from CU's objfile which contains
23396 the DIE at OFFSET. Raises an error on failure. */
23398 static struct dwarf2_per_cu_data
*
23399 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23400 unsigned int offset_in_dwz
,
23401 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23404 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23405 dwarf2_per_objfile
->all_comp_units
);
23406 struct dwarf2_per_cu_data
*this_cu
23407 = dwarf2_per_objfile
->all_comp_units
[low
];
23409 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23411 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23412 error (_("Dwarf Error: could not find partial DIE containing "
23413 "offset %s [in module %s]"),
23414 sect_offset_str (sect_off
),
23415 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23417 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
23419 return dwarf2_per_objfile
->all_comp_units
[low
-1];
23423 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
23424 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23425 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23426 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23433 namespace selftests
{
23434 namespace find_containing_comp_unit
{
23439 struct dwarf2_per_cu_data one
{};
23440 struct dwarf2_per_cu_data two
{};
23441 struct dwarf2_per_cu_data three
{};
23442 struct dwarf2_per_cu_data four
{};
23445 two
.sect_off
= sect_offset (one
.length
);
23450 four
.sect_off
= sect_offset (three
.length
);
23454 std::vector
<dwarf2_per_cu_data
*> units
;
23455 units
.push_back (&one
);
23456 units
.push_back (&two
);
23457 units
.push_back (&three
);
23458 units
.push_back (&four
);
23462 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23463 SELF_CHECK (units
[result
] == &one
);
23464 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23465 SELF_CHECK (units
[result
] == &one
);
23466 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23467 SELF_CHECK (units
[result
] == &two
);
23469 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23470 SELF_CHECK (units
[result
] == &three
);
23471 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23472 SELF_CHECK (units
[result
] == &three
);
23473 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23474 SELF_CHECK (units
[result
] == &four
);
23480 #endif /* GDB_SELF_TEST */
23482 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23484 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
23485 : per_cu (per_cu_
),
23487 has_loclist (false),
23488 checked_producer (false),
23489 producer_is_gxx_lt_4_6 (false),
23490 producer_is_gcc_lt_4_3 (false),
23491 producer_is_icc (false),
23492 producer_is_icc_lt_14 (false),
23493 producer_is_codewarrior (false),
23494 processing_has_namespace_info (false)
23499 /* Destroy a dwarf2_cu. */
23501 dwarf2_cu::~dwarf2_cu ()
23506 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23509 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23510 enum language pretend_language
)
23512 struct attribute
*attr
;
23514 /* Set the language we're debugging. */
23515 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23516 if (attr
!= nullptr)
23517 set_cu_language (DW_UNSND (attr
), cu
);
23520 cu
->language
= pretend_language
;
23521 cu
->language_defn
= language_def (cu
->language
);
23524 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23527 /* Increase the age counter on each cached compilation unit, and free
23528 any that are too old. */
23531 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23533 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23535 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23536 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23537 while (per_cu
!= NULL
)
23539 per_cu
->cu
->last_used
++;
23540 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23541 dwarf2_mark (per_cu
->cu
);
23542 per_cu
= per_cu
->cu
->read_in_chain
;
23545 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23546 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23547 while (per_cu
!= NULL
)
23549 struct dwarf2_per_cu_data
*next_cu
;
23551 next_cu
= per_cu
->cu
->read_in_chain
;
23553 if (!per_cu
->cu
->mark
)
23556 *last_chain
= next_cu
;
23559 last_chain
= &per_cu
->cu
->read_in_chain
;
23565 /* Remove a single compilation unit from the cache. */
23568 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23570 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23571 struct dwarf2_per_objfile
*dwarf2_per_objfile
23572 = target_per_cu
->dwarf2_per_objfile
;
23574 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23575 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23576 while (per_cu
!= NULL
)
23578 struct dwarf2_per_cu_data
*next_cu
;
23580 next_cu
= per_cu
->cu
->read_in_chain
;
23582 if (per_cu
== target_per_cu
)
23586 *last_chain
= next_cu
;
23590 last_chain
= &per_cu
->cu
->read_in_chain
;
23596 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23597 We store these in a hash table separate from the DIEs, and preserve them
23598 when the DIEs are flushed out of cache.
23600 The CU "per_cu" pointer is needed because offset alone is not enough to
23601 uniquely identify the type. A file may have multiple .debug_types sections,
23602 or the type may come from a DWO file. Furthermore, while it's more logical
23603 to use per_cu->section+offset, with Fission the section with the data is in
23604 the DWO file but we don't know that section at the point we need it.
23605 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23606 because we can enter the lookup routine, get_die_type_at_offset, from
23607 outside this file, and thus won't necessarily have PER_CU->cu.
23608 Fortunately, PER_CU is stable for the life of the objfile. */
23610 struct dwarf2_per_cu_offset_and_type
23612 const struct dwarf2_per_cu_data
*per_cu
;
23613 sect_offset sect_off
;
23617 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23620 per_cu_offset_and_type_hash (const void *item
)
23622 const struct dwarf2_per_cu_offset_and_type
*ofs
23623 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23625 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23628 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23631 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23633 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23634 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23635 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23636 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23638 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23639 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23642 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23643 table if necessary. For convenience, return TYPE.
23645 The DIEs reading must have careful ordering to:
23646 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23647 reading current DIE.
23648 * Not trying to dereference contents of still incompletely read in types
23649 while reading in other DIEs.
23650 * Enable referencing still incompletely read in types just by a pointer to
23651 the type without accessing its fields.
23653 Therefore caller should follow these rules:
23654 * Try to fetch any prerequisite types we may need to build this DIE type
23655 before building the type and calling set_die_type.
23656 * After building type call set_die_type for current DIE as soon as
23657 possible before fetching more types to complete the current type.
23658 * Make the type as complete as possible before fetching more types. */
23660 static struct type
*
23661 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23663 struct dwarf2_per_objfile
*dwarf2_per_objfile
23664 = cu
->per_cu
->dwarf2_per_objfile
;
23665 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23666 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23667 struct attribute
*attr
;
23668 struct dynamic_prop prop
;
23670 /* For Ada types, make sure that the gnat-specific data is always
23671 initialized (if not already set). There are a few types where
23672 we should not be doing so, because the type-specific area is
23673 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23674 where the type-specific area is used to store the floatformat).
23675 But this is not a problem, because the gnat-specific information
23676 is actually not needed for these types. */
23677 if (need_gnat_info (cu
)
23678 && type
->code () != TYPE_CODE_FUNC
23679 && type
->code () != TYPE_CODE_FLT
23680 && type
->code () != TYPE_CODE_METHODPTR
23681 && type
->code () != TYPE_CODE_MEMBERPTR
23682 && type
->code () != TYPE_CODE_METHOD
23683 && !HAVE_GNAT_AUX_INFO (type
))
23684 INIT_GNAT_SPECIFIC (type
);
23686 /* Read DW_AT_allocated and set in type. */
23687 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23688 if (attr
!= NULL
&& attr
->form_is_block ())
23690 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23691 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23692 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23694 else if (attr
!= NULL
)
23696 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23697 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23698 sect_offset_str (die
->sect_off
));
23701 /* Read DW_AT_associated and set in type. */
23702 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23703 if (attr
!= NULL
&& attr
->form_is_block ())
23705 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23706 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23707 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23709 else if (attr
!= NULL
)
23711 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23712 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23713 sect_offset_str (die
->sect_off
));
23716 /* Read DW_AT_data_location and set in type. */
23717 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23718 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23719 cu
->per_cu
->addr_type ()))
23720 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23722 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23723 dwarf2_per_objfile
->die_type_hash
23724 = htab_up (htab_create_alloc (127,
23725 per_cu_offset_and_type_hash
,
23726 per_cu_offset_and_type_eq
,
23727 NULL
, xcalloc
, xfree
));
23729 ofs
.per_cu
= cu
->per_cu
;
23730 ofs
.sect_off
= die
->sect_off
;
23732 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23733 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23735 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23736 sect_offset_str (die
->sect_off
));
23737 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23738 struct dwarf2_per_cu_offset_and_type
);
23743 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23744 or return NULL if the die does not have a saved type. */
23746 static struct type
*
23747 get_die_type_at_offset (sect_offset sect_off
,
23748 struct dwarf2_per_cu_data
*per_cu
)
23750 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23751 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23753 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23756 ofs
.per_cu
= per_cu
;
23757 ofs
.sect_off
= sect_off
;
23758 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23759 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23766 /* Look up the type for DIE in CU in die_type_hash,
23767 or return NULL if DIE does not have a saved type. */
23769 static struct type
*
23770 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23772 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23775 /* Add a dependence relationship from CU to REF_PER_CU. */
23778 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23779 struct dwarf2_per_cu_data
*ref_per_cu
)
23783 if (cu
->dependencies
== NULL
)
23785 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23786 NULL
, &cu
->comp_unit_obstack
,
23787 hashtab_obstack_allocate
,
23788 dummy_obstack_deallocate
);
23790 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23792 *slot
= ref_per_cu
;
23795 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23796 Set the mark field in every compilation unit in the
23797 cache that we must keep because we are keeping CU. */
23800 dwarf2_mark_helper (void **slot
, void *data
)
23802 struct dwarf2_per_cu_data
*per_cu
;
23804 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23806 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23807 reading of the chain. As such dependencies remain valid it is not much
23808 useful to track and undo them during QUIT cleanups. */
23809 if (per_cu
->cu
== NULL
)
23812 if (per_cu
->cu
->mark
)
23814 per_cu
->cu
->mark
= true;
23816 if (per_cu
->cu
->dependencies
!= NULL
)
23817 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23822 /* Set the mark field in CU and in every other compilation unit in the
23823 cache that we must keep because we are keeping CU. */
23826 dwarf2_mark (struct dwarf2_cu
*cu
)
23831 if (cu
->dependencies
!= NULL
)
23832 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23836 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23840 per_cu
->cu
->mark
= false;
23841 per_cu
= per_cu
->cu
->read_in_chain
;
23845 /* Trivial hash function for partial_die_info: the hash value of a DIE
23846 is its offset in .debug_info for this objfile. */
23849 partial_die_hash (const void *item
)
23851 const struct partial_die_info
*part_die
23852 = (const struct partial_die_info
*) item
;
23854 return to_underlying (part_die
->sect_off
);
23857 /* Trivial comparison function for partial_die_info structures: two DIEs
23858 are equal if they have the same offset. */
23861 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23863 const struct partial_die_info
*part_die_lhs
23864 = (const struct partial_die_info
*) item_lhs
;
23865 const struct partial_die_info
*part_die_rhs
23866 = (const struct partial_die_info
*) item_rhs
;
23868 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23871 struct cmd_list_element
*set_dwarf_cmdlist
;
23872 struct cmd_list_element
*show_dwarf_cmdlist
;
23875 show_check_physname (struct ui_file
*file
, int from_tty
,
23876 struct cmd_list_element
*c
, const char *value
)
23878 fprintf_filtered (file
,
23879 _("Whether to check \"physname\" is %s.\n"),
23883 void _initialize_dwarf2_read ();
23885 _initialize_dwarf2_read ()
23887 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
23888 Set DWARF specific variables.\n\
23889 Configure DWARF variables such as the cache size."),
23890 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23891 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23893 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
23894 Show DWARF specific variables.\n\
23895 Show DWARF variables such as the cache size."),
23896 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23897 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23899 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23900 &dwarf_max_cache_age
, _("\
23901 Set the upper bound on the age of cached DWARF compilation units."), _("\
23902 Show the upper bound on the age of cached DWARF compilation units."), _("\
23903 A higher limit means that cached compilation units will be stored\n\
23904 in memory longer, and more total memory will be used. Zero disables\n\
23905 caching, which can slow down startup."),
23907 show_dwarf_max_cache_age
,
23908 &set_dwarf_cmdlist
,
23909 &show_dwarf_cmdlist
);
23911 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23912 Set debugging of the DWARF reader."), _("\
23913 Show debugging of the DWARF reader."), _("\
23914 When enabled (non-zero), debugging messages are printed during DWARF\n\
23915 reading and symtab expansion. A value of 1 (one) provides basic\n\
23916 information. A value greater than 1 provides more verbose information."),
23919 &setdebuglist
, &showdebuglist
);
23921 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23922 Set debugging of the DWARF DIE reader."), _("\
23923 Show debugging of the DWARF DIE reader."), _("\
23924 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23925 The value is the maximum depth to print."),
23928 &setdebuglist
, &showdebuglist
);
23930 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23931 Set debugging of the dwarf line reader."), _("\
23932 Show debugging of the dwarf line reader."), _("\
23933 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23934 A value of 1 (one) provides basic information.\n\
23935 A value greater than 1 provides more verbose information."),
23938 &setdebuglist
, &showdebuglist
);
23940 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23941 Set cross-checking of \"physname\" code against demangler."), _("\
23942 Show cross-checking of \"physname\" code against demangler."), _("\
23943 When enabled, GDB's internal \"physname\" code is checked against\n\
23945 NULL
, show_check_physname
,
23946 &setdebuglist
, &showdebuglist
);
23948 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23949 no_class
, &use_deprecated_index_sections
, _("\
23950 Set whether to use deprecated gdb_index sections."), _("\
23951 Show whether to use deprecated gdb_index sections."), _("\
23952 When enabled, deprecated .gdb_index sections are used anyway.\n\
23953 Normally they are ignored either because of a missing feature or\n\
23954 performance issue.\n\
23955 Warning: This option must be enabled before gdb reads the file."),
23958 &setlist
, &showlist
);
23960 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23961 &dwarf2_locexpr_funcs
);
23962 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23963 &dwarf2_loclist_funcs
);
23965 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23966 &dwarf2_block_frame_base_locexpr_funcs
);
23967 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23968 &dwarf2_block_frame_base_loclist_funcs
);
23971 selftests::register_test ("dw2_expand_symtabs_matching",
23972 selftests::dw2_expand_symtabs_matching::run_test
);
23973 selftests::register_test ("dwarf2_find_containing_comp_unit",
23974 selftests::find_containing_comp_unit::run_test
);