1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
4 Copyright (C) 2019-2020 Advanced Micro Devices, Inc. All rights reserved.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 /* FIXME: Various die-reading functions need to be more careful with
29 reading off the end of the section.
30 E.g., load_partial_dies, read_partial_die. */
33 #include "dwarf2read.h"
34 #include "dwarf-index-cache.h"
35 #include "dwarf-index-common.h"
44 #include "gdb-demangle.h"
45 #include "filenames.h" /* for DOSish file names */
48 #include "complaints.h"
49 #include "dwarf2expr.h"
50 #include "dwarf2loc.h"
51 #include "cp-support.h"
57 #include "typeprint.h"
62 #include "gdbcore.h" /* for gnutarget */
63 #include "gdb/gdb-index.h"
68 #include "namespace.h"
69 #include "gdbsupport/function-view.h"
70 #include "gdbsupport/gdb_optional.h"
71 #include "gdbsupport/underlying.h"
72 #include "gdbsupport/hash_enum.h"
73 #include "filename-seen-cache.h"
77 #include <unordered_map>
78 #include "gdbsupport/selftest.h"
79 #include "rust-lang.h"
80 #include "gdbsupport/pathstuff.h"
82 /* When == 1, print basic high level tracing messages.
83 When > 1, be more verbose.
84 This is in contrast to the low level DIE reading of dwarf_die_debug. */
85 static unsigned int dwarf_read_debug
= 0;
87 /* When non-zero, dump DIEs after they are read in. */
88 static unsigned int dwarf_die_debug
= 0;
90 /* When non-zero, dump line number entries as they are read in. */
91 static unsigned int dwarf_line_debug
= 0;
93 /* When true, cross-check physname against demangler. */
94 static bool check_physname
= false;
96 /* When true, do not reject deprecated .gdb_index sections. */
97 static bool use_deprecated_index_sections
= false;
99 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
101 /* The "aclass" indices for various kinds of computed DWARF symbols. */
103 static int dwarf2_locexpr_index
;
104 static int dwarf2_loclist_index
;
105 static int dwarf2_locexpr_block_index
;
106 static int dwarf2_loclist_block_index
;
108 /* An index into a (C++) symbol name component in a symbol name as
109 recorded in the mapped_index's symbol table. For each C++ symbol
110 in the symbol table, we record one entry for the start of each
111 component in the symbol in a table of name components, and then
112 sort the table, in order to be able to binary search symbol names,
113 ignoring leading namespaces, both completion and regular look up.
114 For example, for symbol "A::B::C", we'll have an entry that points
115 to "A::B::C", another that points to "B::C", and another for "C".
116 Note that function symbols in GDB index have no parameter
117 information, just the function/method names. You can convert a
118 name_component to a "const char *" using the
119 'mapped_index::symbol_name_at(offset_type)' method. */
121 struct name_component
123 /* Offset in the symbol name where the component starts. Stored as
124 a (32-bit) offset instead of a pointer to save memory and improve
125 locality on 64-bit architectures. */
126 offset_type name_offset
;
128 /* The symbol's index in the symbol and constant pool tables of a
133 /* Base class containing bits shared by both .gdb_index and
134 .debug_name indexes. */
136 struct mapped_index_base
138 mapped_index_base () = default;
139 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
141 /* The name_component table (a sorted vector). See name_component's
142 description above. */
143 std::vector
<name_component
> name_components
;
145 /* How NAME_COMPONENTS is sorted. */
146 enum case_sensitivity name_components_casing
;
148 /* Return the number of names in the symbol table. */
149 virtual size_t symbol_name_count () const = 0;
151 /* Get the name of the symbol at IDX in the symbol table. */
152 virtual const char *symbol_name_at (offset_type idx
) const = 0;
154 /* Return whether the name at IDX in the symbol table should be
156 virtual bool symbol_name_slot_invalid (offset_type idx
) const
161 /* Build the symbol name component sorted vector, if we haven't
163 void build_name_components ();
165 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
166 possible matches for LN_NO_PARAMS in the name component
168 std::pair
<std::vector
<name_component
>::const_iterator
,
169 std::vector
<name_component
>::const_iterator
>
170 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
171 enum language lang
) const;
173 /* Prevent deleting/destroying via a base class pointer. */
175 ~mapped_index_base() = default;
178 /* A description of the mapped index. The file format is described in
179 a comment by the code that writes the index. */
180 struct mapped_index final
: public mapped_index_base
182 /* A slot/bucket in the symbol table hash. */
183 struct symbol_table_slot
185 const offset_type name
;
186 const offset_type vec
;
189 /* Index data format version. */
192 /* The address table data. */
193 gdb::array_view
<const gdb_byte
> address_table
;
195 /* The symbol table, implemented as a hash table. */
196 gdb::array_view
<symbol_table_slot
> symbol_table
;
198 /* A pointer to the constant pool. */
199 const char *constant_pool
= nullptr;
201 bool symbol_name_slot_invalid (offset_type idx
) const override
203 const auto &bucket
= this->symbol_table
[idx
];
204 return bucket
.name
== 0 && bucket
.vec
== 0;
207 /* Convenience method to get at the name of the symbol at IDX in the
209 const char *symbol_name_at (offset_type idx
) const override
210 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
212 size_t symbol_name_count () const override
213 { return this->symbol_table
.size (); }
216 /* A description of the mapped .debug_names.
217 Uninitialized map has CU_COUNT 0. */
218 struct mapped_debug_names final
: public mapped_index_base
220 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
221 : dwarf2_per_objfile (dwarf2_per_objfile_
)
224 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
225 bfd_endian dwarf5_byte_order
;
226 bool dwarf5_is_dwarf64
;
227 bool augmentation_is_gdb
;
229 uint32_t cu_count
= 0;
230 uint32_t tu_count
, bucket_count
, name_count
;
231 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
232 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
233 const gdb_byte
*name_table_string_offs_reordered
;
234 const gdb_byte
*name_table_entry_offs_reordered
;
235 const gdb_byte
*entry_pool
;
242 /* Attribute name DW_IDX_*. */
245 /* Attribute form DW_FORM_*. */
248 /* Value if FORM is DW_FORM_implicit_const. */
249 LONGEST implicit_const
;
251 std::vector
<attr
> attr_vec
;
254 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
256 const char *namei_to_name (uint32_t namei
) const;
258 /* Implementation of the mapped_index_base virtual interface, for
259 the name_components cache. */
261 const char *symbol_name_at (offset_type idx
) const override
262 { return namei_to_name (idx
); }
264 size_t symbol_name_count () const override
265 { return this->name_count
; }
268 /* See dwarf2read.h. */
271 get_dwarf2_per_objfile (struct objfile
*objfile
)
273 return dwarf2_objfile_data_key
.get (objfile
);
276 /* Default names of the debugging sections. */
278 /* Note that if the debugging section has been compressed, it might
279 have a name like .zdebug_info. */
281 static const struct dwarf2_debug_sections dwarf2_elf_names
=
283 { ".debug_info", ".zdebug_info" },
284 { ".debug_abbrev", ".zdebug_abbrev" },
285 { ".debug_line", ".zdebug_line" },
286 { ".debug_loc", ".zdebug_loc" },
287 { ".debug_loclists", ".zdebug_loclists" },
288 { ".debug_macinfo", ".zdebug_macinfo" },
289 { ".debug_macro", ".zdebug_macro" },
290 { ".debug_str", ".zdebug_str" },
291 { ".debug_line_str", ".zdebug_line_str" },
292 { ".debug_ranges", ".zdebug_ranges" },
293 { ".debug_rnglists", ".zdebug_rnglists" },
294 { ".debug_types", ".zdebug_types" },
295 { ".debug_addr", ".zdebug_addr" },
296 { ".debug_frame", ".zdebug_frame" },
297 { ".eh_frame", NULL
},
298 { ".gdb_index", ".zgdb_index" },
299 { ".debug_names", ".zdebug_names" },
300 { ".debug_aranges", ".zdebug_aranges" },
304 /* List of DWO/DWP sections. */
306 static const struct dwop_section_names
308 struct dwarf2_section_names abbrev_dwo
;
309 struct dwarf2_section_names info_dwo
;
310 struct dwarf2_section_names line_dwo
;
311 struct dwarf2_section_names loc_dwo
;
312 struct dwarf2_section_names loclists_dwo
;
313 struct dwarf2_section_names macinfo_dwo
;
314 struct dwarf2_section_names macro_dwo
;
315 struct dwarf2_section_names str_dwo
;
316 struct dwarf2_section_names str_offsets_dwo
;
317 struct dwarf2_section_names types_dwo
;
318 struct dwarf2_section_names cu_index
;
319 struct dwarf2_section_names tu_index
;
323 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
324 { ".debug_info.dwo", ".zdebug_info.dwo" },
325 { ".debug_line.dwo", ".zdebug_line.dwo" },
326 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
327 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
328 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
329 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
330 { ".debug_str.dwo", ".zdebug_str.dwo" },
331 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
332 { ".debug_types.dwo", ".zdebug_types.dwo" },
333 { ".debug_cu_index", ".zdebug_cu_index" },
334 { ".debug_tu_index", ".zdebug_tu_index" },
337 /* local data types */
339 /* The data in a compilation unit header, after target2host
340 translation, looks like this. */
341 struct comp_unit_head
345 unsigned char addr_size
;
346 unsigned char signed_addr_p
;
347 sect_offset abbrev_sect_off
;
349 /* Size of file offsets; either 4 or 8. */
350 unsigned int offset_size
;
352 /* Size of the length field; either 4 or 12. */
353 unsigned int initial_length_size
;
355 enum dwarf_unit_type unit_type
;
357 /* Offset to the first byte of this compilation unit header in the
358 .debug_info section, for resolving relative reference dies. */
359 sect_offset sect_off
;
361 /* Offset to first die in this cu from the start of the cu.
362 This will be the first byte following the compilation unit header. */
363 cu_offset first_die_cu_offset
;
366 /* 64-bit signature of this unit. For type units, it denotes the signature of
367 the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
368 Also used in DWARF 5, to denote the dwo id when the unit type is
369 DW_UT_skeleton or DW_UT_split_compile. */
372 /* For types, offset in the type's DIE of the type defined by this TU. */
373 cu_offset type_cu_offset_in_tu
;
376 /* Type used for delaying computation of method physnames.
377 See comments for compute_delayed_physnames. */
378 struct delayed_method_info
380 /* The type to which the method is attached, i.e., its parent class. */
383 /* The index of the method in the type's function fieldlists. */
386 /* The index of the method in the fieldlist. */
389 /* The name of the DIE. */
392 /* The DIE associated with this method. */
393 struct die_info
*die
;
396 /* Internal state when decoding a particular compilation unit. */
399 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
402 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
404 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
405 Create the set of symtabs used by this TU, or if this TU is sharing
406 symtabs with another TU and the symtabs have already been created
407 then restore those symtabs in the line header.
408 We don't need the pc/line-number mapping for type units. */
409 void setup_type_unit_groups (struct die_info
*die
);
411 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
412 buildsym_compunit constructor. */
413 struct compunit_symtab
*start_symtab (const char *name
,
414 const char *comp_dir
,
417 /* Reset the builder. */
418 void reset_builder () { m_builder
.reset (); }
420 /* The header of the compilation unit. */
421 struct comp_unit_head header
{};
423 /* Base address of this compilation unit. */
424 CORE_ADDR base_address
= 0;
426 /* Non-zero if base_address has been set. */
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_GNU_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 attribute if present, zero otherwise
512 (zero is a valid value though).
513 Note this value comes from the Fission stub CU/TU's DIE. */
514 ULONGEST addr_base
= 0;
516 /* The DW_AT_ranges_base attribute if present, zero otherwise
517 (zero is a valid value though).
518 Note this value comes from the Fission stub CU/TU's DIE.
519 Also note that the value is zero in the non-DWO case so this value can
520 be used without needing to know whether DWO files are in use or not.
521 N.B. This does not apply to DW_AT_ranges appearing in
522 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
523 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
524 DW_AT_ranges_base *would* have to be applied, and we'd have to care
525 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
526 ULONGEST ranges_base
= 0;
528 /* When reading debug info generated by older versions of rustc, we
529 have to rewrite some union types to be struct types with a
530 variant part. This rewriting must be done after the CU is fully
531 read in, because otherwise at the point of rewriting some struct
532 type might not have been fully processed. So, we keep a list of
533 all such types here and process them after expansion. */
534 std::vector
<struct type
*> rust_unions
;
536 /* Mark used when releasing cached dies. */
539 /* This CU references .debug_loc. See the symtab->locations_valid field.
540 This test is imperfect as there may exist optimized debug code not using
541 any location list and still facing inlining issues if handled as
542 unoptimized code. For a future better test see GCC PR other/32998. */
543 bool has_loclist
: 1;
545 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
546 if all the producer_is_* fields are valid. This information is cached
547 because profiling CU expansion showed excessive time spent in
548 producer_is_gxx_lt_4_6. */
549 bool checked_producer
: 1;
550 bool producer_is_gxx_lt_4_6
: 1;
551 bool producer_is_gcc_lt_4_3
: 1;
552 bool producer_is_icc
: 1;
553 bool producer_is_icc_lt_14
: 1;
554 bool producer_is_codewarrior
: 1;
556 /* When true, the file that we're processing is known to have
557 debugging info for C++ namespaces. GCC 3.3.x did not produce
558 this information, but later versions do. */
560 bool processing_has_namespace_info
: 1;
562 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
564 /* If this CU was inherited by another CU (via specification,
565 abstract_origin, etc), this is the ancestor CU. */
568 /* Get the buildsym_compunit for this CU. */
569 buildsym_compunit
*get_builder ()
571 /* If this CU has a builder associated with it, use that. */
572 if (m_builder
!= nullptr)
573 return m_builder
.get ();
575 /* Otherwise, search ancestors for a valid builder. */
576 if (ancestor
!= nullptr)
577 return ancestor
->get_builder ();
583 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
584 This includes type_unit_group and quick_file_names. */
586 struct stmt_list_hash
588 /* The DWO unit this table is from or NULL if there is none. */
589 struct dwo_unit
*dwo_unit
;
591 /* Offset in .debug_line or .debug_line.dwo. */
592 sect_offset line_sect_off
;
595 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
596 an object of this type. */
598 struct type_unit_group
600 /* dwarf2read.c's main "handle" on a TU symtab.
601 To simplify things we create an artificial CU that "includes" all the
602 type units using this stmt_list so that the rest of the code still has
603 a "per_cu" handle on the symtab.
604 This PER_CU is recognized by having no section. */
605 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
606 struct dwarf2_per_cu_data per_cu
;
608 /* The TUs that share this DW_AT_stmt_list entry.
609 This is added to while parsing type units to build partial symtabs,
610 and is deleted afterwards and not used again. */
611 std::vector
<signatured_type
*> *tus
;
613 /* The compunit symtab.
614 Type units in a group needn't all be defined in the same source file,
615 so we create an essentially anonymous symtab as the compunit symtab. */
616 struct compunit_symtab
*compunit_symtab
;
618 /* The data used to construct the hash key. */
619 struct stmt_list_hash hash
;
621 /* The number of symtabs from the line header.
622 The value here must match line_header.num_file_names. */
623 unsigned int num_symtabs
;
625 /* The symbol tables for this TU (obtained from the files listed in
627 WARNING: The order of entries here must match the order of entries
628 in the line header. After the first TU using this type_unit_group, the
629 line header for the subsequent TUs is recreated from this. This is done
630 because we need to use the same symtabs for each TU using the same
631 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
632 there's no guarantee the line header doesn't have duplicate entries. */
633 struct symtab
**symtabs
;
636 /* These sections are what may appear in a (real or virtual) DWO file. */
640 struct dwarf2_section_info abbrev
;
641 struct dwarf2_section_info line
;
642 struct dwarf2_section_info loc
;
643 struct dwarf2_section_info loclists
;
644 struct dwarf2_section_info macinfo
;
645 struct dwarf2_section_info macro
;
646 struct dwarf2_section_info str
;
647 struct dwarf2_section_info str_offsets
;
648 /* In the case of a virtual DWO file, these two are unused. */
649 struct dwarf2_section_info info
;
650 std::vector
<dwarf2_section_info
> types
;
653 /* CUs/TUs in DWP/DWO files. */
657 /* Backlink to the containing struct dwo_file. */
658 struct dwo_file
*dwo_file
;
660 /* The "id" that distinguishes this CU/TU.
661 .debug_info calls this "dwo_id", .debug_types calls this "signature".
662 Since signatures came first, we stick with it for consistency. */
665 /* The section this CU/TU lives in, in the DWO file. */
666 struct dwarf2_section_info
*section
;
668 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
669 sect_offset sect_off
;
672 /* For types, offset in the type's DIE of the type defined by this TU. */
673 cu_offset type_offset_in_tu
;
676 /* include/dwarf2.h defines the DWP section codes.
677 It defines a max value but it doesn't define a min value, which we
678 use for error checking, so provide one. */
680 enum dwp_v2_section_ids
685 /* Data for one DWO file.
687 This includes virtual DWO files (a virtual DWO file is a DWO file as it
688 appears in a DWP file). DWP files don't really have DWO files per se -
689 comdat folding of types "loses" the DWO file they came from, and from
690 a high level view DWP files appear to contain a mass of random types.
691 However, to maintain consistency with the non-DWP case we pretend DWP
692 files contain virtual DWO files, and we assign each TU with one virtual
693 DWO file (generally based on the line and abbrev section offsets -
694 a heuristic that seems to work in practice). */
698 dwo_file () = default;
699 DISABLE_COPY_AND_ASSIGN (dwo_file
);
701 /* The DW_AT_GNU_dwo_name attribute.
702 For virtual DWO files the name is constructed from the section offsets
703 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
704 from related CU+TUs. */
705 const char *dwo_name
= nullptr;
707 /* The DW_AT_comp_dir attribute. */
708 const char *comp_dir
= nullptr;
710 /* The bfd, when the file is open. Otherwise this is NULL.
711 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
712 gdb_bfd_ref_ptr dbfd
;
714 /* The sections that make up this DWO file.
715 Remember that for virtual DWO files in DWP V2, these are virtual
716 sections (for lack of a better name). */
717 struct dwo_sections sections
{};
719 /* The CUs in the file.
720 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
721 an extension to handle LLVM's Link Time Optimization output (where
722 multiple source files may be compiled into a single object/dwo pair). */
725 /* Table of TUs in the file.
726 Each element is a struct dwo_unit. */
730 /* These sections are what may appear in a DWP file. */
734 /* These are used by both DWP version 1 and 2. */
735 struct dwarf2_section_info str
;
736 struct dwarf2_section_info cu_index
;
737 struct dwarf2_section_info tu_index
;
739 /* These are only used by DWP version 2 files.
740 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
741 sections are referenced by section number, and are not recorded here.
742 In DWP version 2 there is at most one copy of all these sections, each
743 section being (effectively) comprised of the concatenation of all of the
744 individual sections that exist in the version 1 format.
745 To keep the code simple we treat each of these concatenated pieces as a
746 section itself (a virtual section?). */
747 struct dwarf2_section_info abbrev
;
748 struct dwarf2_section_info info
;
749 struct dwarf2_section_info line
;
750 struct dwarf2_section_info loc
;
751 struct dwarf2_section_info macinfo
;
752 struct dwarf2_section_info macro
;
753 struct dwarf2_section_info str_offsets
;
754 struct dwarf2_section_info types
;
757 /* These sections are what may appear in a virtual DWO file in DWP version 1.
758 A virtual DWO file is a DWO file as it appears in a DWP file. */
760 struct virtual_v1_dwo_sections
762 struct dwarf2_section_info abbrev
;
763 struct dwarf2_section_info line
;
764 struct dwarf2_section_info loc
;
765 struct dwarf2_section_info macinfo
;
766 struct dwarf2_section_info macro
;
767 struct dwarf2_section_info str_offsets
;
768 /* Each DWP hash table entry records one CU or one TU.
769 That is recorded here, and copied to dwo_unit.section. */
770 struct dwarf2_section_info info_or_types
;
773 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
774 In version 2, the sections of the DWO files are concatenated together
775 and stored in one section of that name. Thus each ELF section contains
776 several "virtual" sections. */
778 struct virtual_v2_dwo_sections
780 bfd_size_type abbrev_offset
;
781 bfd_size_type abbrev_size
;
783 bfd_size_type line_offset
;
784 bfd_size_type line_size
;
786 bfd_size_type loc_offset
;
787 bfd_size_type loc_size
;
789 bfd_size_type macinfo_offset
;
790 bfd_size_type macinfo_size
;
792 bfd_size_type macro_offset
;
793 bfd_size_type macro_size
;
795 bfd_size_type str_offsets_offset
;
796 bfd_size_type str_offsets_size
;
798 /* Each DWP hash table entry records one CU or one TU.
799 That is recorded here, and copied to dwo_unit.section. */
800 bfd_size_type info_or_types_offset
;
801 bfd_size_type info_or_types_size
;
804 /* Contents of DWP hash tables. */
806 struct dwp_hash_table
808 uint32_t version
, nr_columns
;
809 uint32_t nr_units
, nr_slots
;
810 const gdb_byte
*hash_table
, *unit_table
;
815 const gdb_byte
*indices
;
819 /* This is indexed by column number and gives the id of the section
821 #define MAX_NR_V2_DWO_SECTIONS \
822 (1 /* .debug_info or .debug_types */ \
823 + 1 /* .debug_abbrev */ \
824 + 1 /* .debug_line */ \
825 + 1 /* .debug_loc */ \
826 + 1 /* .debug_str_offsets */ \
827 + 1 /* .debug_macro or .debug_macinfo */)
828 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
829 const gdb_byte
*offsets
;
830 const gdb_byte
*sizes
;
835 /* Data for one DWP file. */
839 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
841 dbfd (std::move (abfd
))
845 /* Name of the file. */
848 /* File format version. */
852 gdb_bfd_ref_ptr dbfd
;
854 /* Section info for this file. */
855 struct dwp_sections sections
{};
857 /* Table of CUs in the file. */
858 const struct dwp_hash_table
*cus
= nullptr;
860 /* Table of TUs in the file. */
861 const struct dwp_hash_table
*tus
= nullptr;
863 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
864 htab_t loaded_cus
{};
865 htab_t loaded_tus
{};
867 /* Table to map ELF section numbers to their sections.
868 This is only needed for the DWP V1 file format. */
869 unsigned int num_sections
= 0;
870 asection
**elf_sections
= nullptr;
873 /* Struct used to pass misc. parameters to read_die_and_children, et
874 al. which are used for both .debug_info and .debug_types dies.
875 All parameters here are unchanging for the life of the call. This
876 struct exists to abstract away the constant parameters of die reading. */
878 struct die_reader_specs
880 /* The bfd of die_section. */
883 /* The CU of the DIE we are parsing. */
884 struct dwarf2_cu
*cu
;
886 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
887 struct dwo_file
*dwo_file
;
889 /* The section the die comes from.
890 This is either .debug_info or .debug_types, or the .dwo variants. */
891 struct dwarf2_section_info
*die_section
;
893 /* die_section->buffer. */
894 const gdb_byte
*buffer
;
896 /* The end of the buffer. */
897 const gdb_byte
*buffer_end
;
899 /* The value of the DW_AT_comp_dir attribute. */
900 const char *comp_dir
;
902 /* The abbreviation table to use when reading the DIEs. */
903 struct abbrev_table
*abbrev_table
;
906 /* Type of function passed to init_cutu_and_read_dies, et.al. */
907 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
908 const gdb_byte
*info_ptr
,
909 struct die_info
*comp_unit_die
,
913 /* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
915 typedef int dir_index
;
917 /* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
919 typedef int file_name_index
;
923 file_entry () = default;
925 file_entry (const char *name_
, dir_index d_index_
,
926 unsigned int mod_time_
, unsigned int length_
)
929 mod_time (mod_time_
),
933 /* Return the include directory at D_INDEX stored in LH. Returns
934 NULL if D_INDEX is out of bounds. */
935 const char *include_dir (const line_header
*lh
) const;
937 /* The file name. Note this is an observing pointer. The memory is
938 owned by debug_line_buffer. */
941 /* The directory index (1-based). */
942 dir_index d_index
{};
944 unsigned int mod_time
{};
946 unsigned int length
{};
948 /* True if referenced by the Line Number Program. */
951 /* The associated symbol table, if any. */
952 struct symtab
*symtab
{};
955 /* The line number information for a compilation unit (found in the
956 .debug_line section) begins with a "statement program header",
957 which contains the following information. */
964 /* Add an entry to the include directory table. */
965 void add_include_dir (const char *include_dir
);
967 /* Add an entry to the file name table. */
968 void add_file_name (const char *name
, dir_index d_index
,
969 unsigned int mod_time
, unsigned int length
);
971 /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
972 Returns NULL if INDEX is out of bounds. */
973 const char *include_dir_at (dir_index index
) const
979 vec_index
= index
- 1;
980 if (vec_index
< 0 || vec_index
>= m_include_dirs
.size ())
982 return m_include_dirs
[vec_index
];
985 bool is_valid_file_index (int file_index
)
988 return 0 <= file_index
&& file_index
< file_names_size ();
989 return 1 <= file_index
&& file_index
<= file_names_size ();
992 /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
993 Returns NULL if INDEX is out of bounds. */
994 file_entry
*file_name_at (file_name_index index
)
1000 vec_index
= index
- 1;
1001 if (vec_index
< 0 || vec_index
>= m_file_names
.size ())
1003 return &m_file_names
[vec_index
];
1006 /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
1007 this method should only be used to iterate through all file entries in an
1008 index-agnostic manner. */
1009 std::vector
<file_entry
> &file_names ()
1010 { return m_file_names
; }
1012 /* Offset of line number information in .debug_line section. */
1013 sect_offset sect_off
{};
1015 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1016 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1018 unsigned int total_length
{};
1019 unsigned short version
{};
1020 unsigned int header_length
{};
1021 unsigned char minimum_instruction_length
{};
1022 unsigned char maximum_ops_per_instruction
{};
1023 unsigned char default_is_stmt
{};
1025 unsigned char line_range
{};
1026 unsigned char opcode_base
{};
1028 /* standard_opcode_lengths[i] is the number of operands for the
1029 standard opcode whose value is i. This means that
1030 standard_opcode_lengths[0] is unused, and the last meaningful
1031 element is standard_opcode_lengths[opcode_base - 1]. */
1032 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1034 int file_names_size ()
1035 { return m_file_names
.size(); }
1037 /* The start and end of the statement program following this
1038 header. These point into dwarf2_per_objfile->line_buffer. */
1039 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1042 /* The include_directories table. Note these are observing
1043 pointers. The memory is owned by debug_line_buffer. */
1044 std::vector
<const char *> m_include_dirs
;
1046 /* The file_names table. This is private because the meaning of indexes
1047 differs among DWARF versions (The first valid index is 1 in DWARF 4 and
1048 before, and is 0 in DWARF 5 and later). So the client should use
1049 file_name_at method for access. */
1050 std::vector
<file_entry
> m_file_names
;
1053 typedef std::unique_ptr
<line_header
> line_header_up
;
1056 file_entry::include_dir (const line_header
*lh
) const
1058 return lh
->include_dir_at (d_index
);
1061 /* When we construct a partial symbol table entry we only
1062 need this much information. */
1063 struct partial_die_info
: public allocate_on_obstack
1065 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1067 /* Disable assign but still keep copy ctor, which is needed
1068 load_partial_dies. */
1069 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1071 /* Adjust the partial die before generating a symbol for it. This
1072 function may set the is_external flag or change the DIE's
1074 void fixup (struct dwarf2_cu
*cu
);
1076 /* Read a minimal amount of information into the minimal die
1078 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1079 const struct abbrev_info
&abbrev
,
1080 const gdb_byte
*info_ptr
);
1082 /* Offset of this DIE. */
1083 const sect_offset sect_off
;
1085 /* DWARF-2 tag for this DIE. */
1086 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1088 /* Assorted flags describing the data found in this DIE. */
1089 const unsigned int has_children
: 1;
1091 unsigned int is_external
: 1;
1092 unsigned int is_declaration
: 1;
1093 unsigned int has_type
: 1;
1094 unsigned int has_specification
: 1;
1095 unsigned int has_pc_info
: 1;
1096 unsigned int may_be_inlined
: 1;
1098 /* This DIE has been marked DW_AT_main_subprogram. */
1099 unsigned int main_subprogram
: 1;
1101 /* Flag set if the SCOPE field of this structure has been
1103 unsigned int scope_set
: 1;
1105 /* Flag set if the DIE has a byte_size attribute. */
1106 unsigned int has_byte_size
: 1;
1108 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1109 unsigned int has_const_value
: 1;
1111 /* Flag set if any of the DIE's children are template arguments. */
1112 unsigned int has_template_arguments
: 1;
1114 /* Flag set if fixup has been called on this die. */
1115 unsigned int fixup_called
: 1;
1117 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1118 unsigned int is_dwz
: 1;
1120 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1121 unsigned int spec_is_dwz
: 1;
1123 /* The name of this DIE. Normally the value of DW_AT_name, but
1124 sometimes a default name for unnamed DIEs. */
1125 const char *name
= nullptr;
1127 /* The linkage name, if present. */
1128 const char *linkage_name
= nullptr;
1130 /* The scope to prepend to our children. This is generally
1131 allocated on the comp_unit_obstack, so will disappear
1132 when this compilation unit leaves the cache. */
1133 const char *scope
= nullptr;
1135 /* Some data associated with the partial DIE. The tag determines
1136 which field is live. */
1139 /* The location description associated with this DIE, if any. */
1140 struct dwarf_block
*locdesc
;
1141 /* The offset of an import, for DW_TAG_imported_unit. */
1142 sect_offset sect_off
;
1145 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1146 CORE_ADDR lowpc
= 0;
1147 CORE_ADDR highpc
= 0;
1149 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1150 DW_AT_sibling, if any. */
1151 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1152 could return DW_AT_sibling values to its caller load_partial_dies. */
1153 const gdb_byte
*sibling
= nullptr;
1155 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1156 DW_AT_specification (or DW_AT_abstract_origin or
1157 DW_AT_extension). */
1158 sect_offset spec_offset
{};
1160 /* Pointers to this DIE's parent, first child, and next sibling,
1162 struct partial_die_info
*die_parent
= nullptr;
1163 struct partial_die_info
*die_child
= nullptr;
1164 struct partial_die_info
*die_sibling
= nullptr;
1166 friend struct partial_die_info
*
1167 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1170 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1171 partial_die_info (sect_offset sect_off
)
1172 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1176 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1178 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1183 has_specification
= 0;
1186 main_subprogram
= 0;
1189 has_const_value
= 0;
1190 has_template_arguments
= 0;
1197 /* This data structure holds the information of an abbrev. */
1200 unsigned int number
; /* number identifying abbrev */
1201 enum dwarf_tag tag
; /* dwarf tag */
1202 unsigned short has_children
; /* boolean */
1203 unsigned short num_attrs
; /* number of attributes */
1204 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1205 struct abbrev_info
*next
; /* next in chain */
1210 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1211 ENUM_BITFIELD(dwarf_form
) form
: 16;
1213 /* It is valid only if FORM is DW_FORM_implicit_const. */
1214 LONGEST implicit_const
;
1217 /* Size of abbrev_table.abbrev_hash_table. */
1218 #define ABBREV_HASH_SIZE 121
1220 /* Top level data structure to contain an abbreviation table. */
1224 explicit abbrev_table (sect_offset off
)
1228 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1229 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1232 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1234 /* Allocate space for a struct abbrev_info object in
1236 struct abbrev_info
*alloc_abbrev ();
1238 /* Add an abbreviation to the table. */
1239 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1241 /* Look up an abbrev in the table.
1242 Returns NULL if the abbrev is not found. */
1244 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1247 /* Where the abbrev table came from.
1248 This is used as a sanity check when the table is used. */
1249 const sect_offset sect_off
;
1251 /* Storage for the abbrev table. */
1252 auto_obstack abbrev_obstack
;
1256 /* Hash table of abbrevs.
1257 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1258 It could be statically allocated, but the previous code didn't so we
1260 struct abbrev_info
**m_abbrevs
;
1263 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1265 /* Attributes have a name and a value. */
1268 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1269 ENUM_BITFIELD(dwarf_form
) form
: 15;
1271 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1272 field should be in u.str (existing only for DW_STRING) but it is kept
1273 here for better struct attribute alignment. */
1274 unsigned int string_is_canonical
: 1;
1279 struct dwarf_block
*blk
;
1288 /* This data structure holds a complete die structure. */
1291 /* DWARF-2 tag for this DIE. */
1292 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1294 /* Number of attributes */
1295 unsigned char num_attrs
;
1297 /* True if we're presently building the full type name for the
1298 type derived from this DIE. */
1299 unsigned char building_fullname
: 1;
1301 /* True if this die is in process. PR 16581. */
1302 unsigned char in_process
: 1;
1305 unsigned int abbrev
;
1307 /* Offset in .debug_info or .debug_types section. */
1308 sect_offset sect_off
;
1310 /* The dies in a compilation unit form an n-ary tree. PARENT
1311 points to this die's parent; CHILD points to the first child of
1312 this node; and all the children of a given node are chained
1313 together via their SIBLING fields. */
1314 struct die_info
*child
; /* Its first child, if any. */
1315 struct die_info
*sibling
; /* Its next sibling, if any. */
1316 struct die_info
*parent
; /* Its parent, if any. */
1318 /* An array of attributes, with NUM_ATTRS elements. There may be
1319 zero, but it's not common and zero-sized arrays are not
1320 sufficiently portable C. */
1321 struct attribute attrs
[1];
1324 /* Get at parts of an attribute structure. */
1326 #define DW_STRING(attr) ((attr)->u.str)
1327 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1328 #define DW_UNSND(attr) ((attr)->u.unsnd)
1329 #define DW_BLOCK(attr) ((attr)->u.blk)
1330 #define DW_SND(attr) ((attr)->u.snd)
1331 #define DW_ADDR(attr) ((attr)->u.addr)
1332 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1334 /* Blocks are a bunch of untyped bytes. */
1339 /* Valid only if SIZE is not zero. */
1340 const gdb_byte
*data
;
1343 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1344 but this would require a corresponding change in unpack_field_as_long
1346 static int bits_per_byte
= 8;
1348 /* When reading a variant or variant part, we track a bit more
1349 information about the field, and store it in an object of this
1352 struct variant_field
1354 /* If we see a DW_TAG_variant, then this will be the discriminant
1356 ULONGEST discriminant_value
;
1357 /* If we see a DW_TAG_variant, then this will be set if this is the
1359 bool default_branch
;
1360 /* While reading a DW_TAG_variant_part, this will be set if this
1361 field is the discriminant. */
1362 bool is_discriminant
;
1367 int accessibility
= 0;
1369 /* Extra information to describe a variant or variant part. */
1370 struct variant_field variant
{};
1371 struct field field
{};
1376 const char *name
= nullptr;
1377 std::vector
<struct fn_field
> fnfields
;
1380 /* The routines that read and process dies for a C struct or C++ class
1381 pass lists of data member fields and lists of member function fields
1382 in an instance of a field_info structure, as defined below. */
1385 /* List of data member and baseclasses fields. */
1386 std::vector
<struct nextfield
> fields
;
1387 std::vector
<struct nextfield
> baseclasses
;
1389 /* Number of fields (including baseclasses). */
1392 /* Set if the accessibility of one of the fields is not public. */
1393 int non_public_fields
= 0;
1395 /* Member function fieldlist array, contains name of possibly overloaded
1396 member function, number of overloaded member functions and a pointer
1397 to the head of the member function field chain. */
1398 std::vector
<struct fnfieldlist
> fnfieldlists
;
1400 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1401 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1402 std::vector
<struct decl_field
> typedef_field_list
;
1404 /* Nested types defined by this class and the number of elements in this
1406 std::vector
<struct decl_field
> nested_types_list
;
1409 /* One item on the queue of compilation units to read in full symbols
1411 struct dwarf2_queue_item
1413 struct dwarf2_per_cu_data
*per_cu
;
1414 enum language pretend_language
;
1415 struct dwarf2_queue_item
*next
;
1418 /* The current queue. */
1419 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1421 /* Loaded secondary compilation units are kept in memory until they
1422 have not been referenced for the processing of this many
1423 compilation units. Set this to zero to disable caching. Cache
1424 sizes of up to at least twenty will improve startup time for
1425 typical inter-CU-reference binaries, at an obvious memory cost. */
1426 static int dwarf_max_cache_age
= 5;
1428 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1429 struct cmd_list_element
*c
, const char *value
)
1431 fprintf_filtered (file
, _("The upper bound on the age of cached "
1432 "DWARF compilation units is %s.\n"),
1436 /* local function prototypes */
1438 static const char *get_section_name (const struct dwarf2_section_info
*);
1440 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1442 static void dwarf2_find_base_address (struct die_info
*die
,
1443 struct dwarf2_cu
*cu
);
1445 static struct partial_symtab
*create_partial_symtab
1446 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1448 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1449 const gdb_byte
*info_ptr
,
1450 struct die_info
*type_unit_die
,
1451 int has_children
, void *data
);
1453 static void dwarf2_build_psymtabs_hard
1454 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1456 static void scan_partial_symbols (struct partial_die_info
*,
1457 CORE_ADDR
*, CORE_ADDR
*,
1458 int, struct dwarf2_cu
*);
1460 static void add_partial_symbol (struct partial_die_info
*,
1461 struct dwarf2_cu
*);
1463 static void add_partial_namespace (struct partial_die_info
*pdi
,
1464 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1465 int set_addrmap
, struct dwarf2_cu
*cu
);
1467 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1468 CORE_ADDR
*highpc
, int set_addrmap
,
1469 struct dwarf2_cu
*cu
);
1471 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1472 struct dwarf2_cu
*cu
);
1474 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1475 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1476 int need_pc
, struct dwarf2_cu
*cu
);
1478 static void dwarf2_read_symtab (struct partial_symtab
*,
1481 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1483 static abbrev_table_up abbrev_table_read_table
1484 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1487 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1489 static struct partial_die_info
*load_partial_dies
1490 (const struct die_reader_specs
*, const gdb_byte
*, int);
1492 /* A pair of partial_die_info and compilation unit. */
1493 struct cu_partial_die_info
1495 /* The compilation unit of the partial_die_info. */
1496 struct dwarf2_cu
*cu
;
1497 /* A partial_die_info. */
1498 struct partial_die_info
*pdi
;
1500 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1506 cu_partial_die_info () = delete;
1509 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1510 struct dwarf2_cu
*);
1512 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1513 struct attribute
*, struct attr_abbrev
*,
1516 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1518 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1520 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1522 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1523 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1525 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1527 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1529 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1532 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1534 static LONGEST read_checked_initial_length_and_offset
1535 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1536 unsigned int *, unsigned int *);
1538 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1539 const struct comp_unit_head
*,
1542 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1544 static sect_offset read_abbrev_offset
1545 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1546 struct dwarf2_section_info
*, sect_offset
);
1548 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1550 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1552 static const char *read_indirect_string
1553 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1554 const struct comp_unit_head
*, unsigned int *);
1556 static const char *read_indirect_line_string
1557 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1558 const struct comp_unit_head
*, unsigned int *);
1560 static const char *read_indirect_string_at_offset
1561 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1562 LONGEST str_offset
);
1564 static const char *read_indirect_string_from_dwz
1565 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1567 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1569 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1573 static const char *read_str_index (const struct die_reader_specs
*reader
,
1574 ULONGEST str_index
);
1576 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1578 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1579 struct dwarf2_cu
*);
1581 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1584 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1585 struct dwarf2_cu
*cu
);
1587 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1589 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1590 struct dwarf2_cu
*cu
);
1592 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1594 static struct die_info
*die_specification (struct die_info
*die
,
1595 struct dwarf2_cu
**);
1597 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1598 struct dwarf2_cu
*cu
);
1600 static void dwarf_decode_lines (struct line_header
*, const char *,
1601 struct dwarf2_cu
*, struct partial_symtab
*,
1602 CORE_ADDR
, int decode_mapping
);
1604 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1607 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1608 struct dwarf2_cu
*, struct symbol
* = NULL
);
1610 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1611 struct dwarf2_cu
*);
1613 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1616 struct obstack
*obstack
,
1617 struct dwarf2_cu
*cu
, LONGEST
*value
,
1618 const gdb_byte
**bytes
,
1619 struct dwarf2_locexpr_baton
**baton
);
1621 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1623 static int need_gnat_info (struct dwarf2_cu
*);
1625 static struct type
*die_descriptive_type (struct die_info
*,
1626 struct dwarf2_cu
*);
1628 static void set_descriptive_type (struct type
*, struct die_info
*,
1629 struct dwarf2_cu
*);
1631 static struct type
*die_containing_type (struct die_info
*,
1632 struct dwarf2_cu
*);
1634 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1635 struct dwarf2_cu
*);
1637 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1639 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1641 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1643 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1644 const char *suffix
, int physname
,
1645 struct dwarf2_cu
*cu
);
1647 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1649 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1651 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1653 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1655 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1657 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1659 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1660 struct dwarf2_cu
*, struct partial_symtab
*);
1662 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1663 values. Keep the items ordered with increasing constraints compliance. */
1666 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1667 PC_BOUNDS_NOT_PRESENT
,
1669 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1670 were present but they do not form a valid range of PC addresses. */
1673 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1676 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1680 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1681 CORE_ADDR
*, CORE_ADDR
*,
1683 struct partial_symtab
*);
1685 static void get_scope_pc_bounds (struct die_info
*,
1686 CORE_ADDR
*, CORE_ADDR
*,
1687 struct dwarf2_cu
*);
1689 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1690 CORE_ADDR
, struct dwarf2_cu
*);
1692 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1693 struct dwarf2_cu
*);
1695 static void dwarf2_attach_fields_to_type (struct field_info
*,
1696 struct type
*, struct dwarf2_cu
*);
1698 static void dwarf2_add_member_fn (struct field_info
*,
1699 struct die_info
*, struct type
*,
1700 struct dwarf2_cu
*);
1702 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1704 struct dwarf2_cu
*);
1706 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1708 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1710 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1712 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1714 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1716 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1718 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1720 static struct type
*read_module_type (struct die_info
*die
,
1721 struct dwarf2_cu
*cu
);
1723 static const char *namespace_name (struct die_info
*die
,
1724 int *is_anonymous
, struct dwarf2_cu
*);
1726 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1728 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1730 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1731 struct dwarf2_cu
*);
1733 static struct die_info
*read_die_and_siblings_1
1734 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1737 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1738 const gdb_byte
*info_ptr
,
1739 const gdb_byte
**new_info_ptr
,
1740 struct die_info
*parent
);
1742 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1743 struct die_info
**, const gdb_byte
*,
1746 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1747 struct die_info
**, const gdb_byte
*,
1750 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1752 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1755 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1757 static const char *dwarf2_full_name (const char *name
,
1758 struct die_info
*die
,
1759 struct dwarf2_cu
*cu
);
1761 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1762 struct dwarf2_cu
*cu
);
1764 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1765 struct dwarf2_cu
**);
1767 static const char *dwarf_tag_name (unsigned int);
1769 static const char *dwarf_attr_name (unsigned int);
1771 static const char *dwarf_unit_type_name (int unit_type
);
1773 static const char *dwarf_form_name (unsigned int);
1775 static const char *dwarf_bool_name (unsigned int);
1777 static const char *dwarf_type_encoding_name (unsigned int);
1779 static struct die_info
*sibling_die (struct die_info
*);
1781 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1783 static void dump_die_for_error (struct die_info
*);
1785 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1788 /*static*/ void dump_die (struct die_info
*, int max_level
);
1790 static void store_in_ref_table (struct die_info
*,
1791 struct dwarf2_cu
*);
1793 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1795 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1797 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1798 const struct attribute
*,
1799 struct dwarf2_cu
**);
1801 static struct die_info
*follow_die_ref (struct die_info
*,
1802 const struct attribute
*,
1803 struct dwarf2_cu
**);
1805 static struct die_info
*follow_die_sig (struct die_info
*,
1806 const struct attribute
*,
1807 struct dwarf2_cu
**);
1809 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1810 struct dwarf2_cu
*);
1812 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1813 const struct attribute
*,
1814 struct dwarf2_cu
*);
1816 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1818 static void read_signatured_type (struct signatured_type
*);
1820 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1821 struct die_info
*die
, struct dwarf2_cu
*cu
,
1822 struct dynamic_prop
*prop
, struct type
*type
);
1824 /* memory allocation interface */
1826 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1828 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1830 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1832 static int attr_form_is_block (const struct attribute
*);
1834 static int attr_form_is_section_offset (const struct attribute
*);
1836 static int attr_form_is_constant (const struct attribute
*);
1838 static int attr_form_is_ref (const struct attribute
*);
1840 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1841 struct dwarf2_loclist_baton
*baton
,
1842 const struct attribute
*attr
);
1844 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1846 struct dwarf2_cu
*cu
,
1849 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1850 const gdb_byte
*info_ptr
,
1851 struct abbrev_info
*abbrev
);
1853 static hashval_t
partial_die_hash (const void *item
);
1855 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1857 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1858 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1859 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1861 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1862 struct die_info
*comp_unit_die
,
1863 enum language pretend_language
);
1865 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1867 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1869 static struct type
*set_die_type (struct die_info
*, struct type
*,
1870 struct dwarf2_cu
*);
1872 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1874 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1876 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1879 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1882 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1885 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1886 struct dwarf2_per_cu_data
*);
1888 static void dwarf2_mark (struct dwarf2_cu
*);
1890 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1892 static struct type
*get_die_type_at_offset (sect_offset
,
1893 struct dwarf2_per_cu_data
*);
1895 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1897 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1898 enum language pretend_language
);
1900 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1902 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1903 static struct type
*dwarf2_per_cu_addr_sized_int_type
1904 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1905 static struct type
*dwarf2_per_cu_int_type
1906 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1909 /* Class, the destructor of which frees all allocated queue entries. This
1910 will only have work to do if an error was thrown while processing the
1911 dwarf. If no error was thrown then the queue entries should have all
1912 been processed, and freed, as we went along. */
1914 class dwarf2_queue_guard
1917 dwarf2_queue_guard () = default;
1919 /* Free any entries remaining on the queue. There should only be
1920 entries left if we hit an error while processing the dwarf. */
1921 ~dwarf2_queue_guard ()
1923 struct dwarf2_queue_item
*item
, *last
;
1925 item
= dwarf2_queue
;
1928 /* Anything still marked queued is likely to be in an
1929 inconsistent state, so discard it. */
1930 if (item
->per_cu
->queued
)
1932 if (item
->per_cu
->cu
!= NULL
)
1933 free_one_cached_comp_unit (item
->per_cu
);
1934 item
->per_cu
->queued
= 0;
1942 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1946 /* The return type of find_file_and_directory. Note, the enclosed
1947 string pointers are only valid while this object is valid. */
1949 struct file_and_directory
1951 /* The filename. This is never NULL. */
1954 /* The compilation directory. NULL if not known. If we needed to
1955 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1956 points directly to the DW_AT_comp_dir string attribute owned by
1957 the obstack that owns the DIE. */
1958 const char *comp_dir
;
1960 /* If we needed to build a new string for comp_dir, this is what
1961 owns the storage. */
1962 std::string comp_dir_storage
;
1965 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1966 struct dwarf2_cu
*cu
);
1968 static char *file_full_name (int file
, struct line_header
*lh
,
1969 const char *comp_dir
);
1971 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1972 enum class rcuh_kind
{ COMPILE
, TYPE
};
1974 static const gdb_byte
*read_and_check_comp_unit_head
1975 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1976 struct comp_unit_head
*header
,
1977 struct dwarf2_section_info
*section
,
1978 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1979 rcuh_kind section_kind
);
1981 static void init_cutu_and_read_dies
1982 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1983 int use_existing_cu
, int keep
, bool skip_partial
,
1984 die_reader_func_ftype
*die_reader_func
, void *data
);
1986 static void init_cutu_and_read_dies_simple
1987 (struct dwarf2_per_cu_data
*this_cu
,
1988 die_reader_func_ftype
*die_reader_func
, void *data
);
1990 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1992 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1994 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1995 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1996 struct dwp_file
*dwp_file
, const char *comp_dir
,
1997 ULONGEST signature
, int is_debug_types
);
1999 static struct dwp_file
*get_dwp_file
2000 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2002 static struct dwo_unit
*lookup_dwo_comp_unit
2003 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2005 static struct dwo_unit
*lookup_dwo_type_unit
2006 (struct signatured_type
*, const char *, const char *);
2008 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2010 /* A unique pointer to a dwo_file. */
2012 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2014 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2016 static void check_producer (struct dwarf2_cu
*cu
);
2018 static void free_line_header_voidp (void *arg
);
2020 /* Various complaints about symbol reading that don't abort the process. */
2023 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2025 complaint (_("statement list doesn't fit in .debug_line section"));
2029 dwarf2_debug_line_missing_file_complaint (void)
2031 complaint (_(".debug_line section has line data without a file"));
2035 dwarf2_debug_line_missing_end_sequence_complaint (void)
2037 complaint (_(".debug_line section has line "
2038 "program sequence without an end"));
2042 dwarf2_complex_location_expr_complaint (void)
2044 complaint (_("location expression too complex"));
2048 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2051 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2056 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2058 complaint (_("debug info runs off end of %s section"
2060 get_section_name (section
),
2061 get_section_file_name (section
));
2065 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2067 complaint (_("macro debug info contains a "
2068 "malformed macro definition:\n`%s'"),
2073 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2075 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2079 /* Hash function for line_header_hash. */
2082 line_header_hash (const struct line_header
*ofs
)
2084 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2087 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2090 line_header_hash_voidp (const void *item
)
2092 const struct line_header
*ofs
= (const struct line_header
*) item
;
2094 return line_header_hash (ofs
);
2097 /* Equality function for line_header_hash. */
2100 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2102 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2103 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2105 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2106 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2111 /* Read the given attribute value as an address, taking the attribute's
2112 form into account. */
2115 attr_value_as_address (struct attribute
*attr
)
2119 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2120 && attr
->form
!= DW_FORM_GNU_addr_index
)
2122 /* Aside from a few clearly defined exceptions, attributes that
2123 contain an address must always be in DW_FORM_addr form.
2124 Unfortunately, some compilers happen to be violating this
2125 requirement by encoding addresses using other forms, such
2126 as DW_FORM_data4 for example. For those broken compilers,
2127 we try to do our best, without any guarantee of success,
2128 to interpret the address correctly. It would also be nice
2129 to generate a complaint, but that would require us to maintain
2130 a list of legitimate cases where a non-address form is allowed,
2131 as well as update callers to pass in at least the CU's DWARF
2132 version. This is more overhead than what we're willing to
2133 expand for a pretty rare case. */
2134 addr
= DW_UNSND (attr
);
2137 addr
= DW_ADDR (attr
);
2142 /* See declaration. */
2144 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2145 const dwarf2_debug_sections
*names
,
2147 : objfile (objfile_
),
2148 can_copy (can_copy_
)
2151 names
= &dwarf2_elf_names
;
2153 bfd
*obfd
= objfile
->obfd
;
2155 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2156 locate_sections (obfd
, sec
, *names
);
2159 dwarf2_per_objfile::~dwarf2_per_objfile ()
2161 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2162 free_cached_comp_units ();
2164 if (quick_file_names_table
)
2165 htab_delete (quick_file_names_table
);
2167 if (line_header_hash
)
2168 htab_delete (line_header_hash
);
2170 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2171 per_cu
->imported_symtabs_free ();
2173 for (signatured_type
*sig_type
: all_type_units
)
2174 sig_type
->per_cu
.imported_symtabs_free ();
2176 /* Everything else should be on the objfile obstack. */
2179 /* See declaration. */
2182 dwarf2_per_objfile::free_cached_comp_units ()
2184 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2185 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2186 while (per_cu
!= NULL
)
2188 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2191 *last_chain
= next_cu
;
2196 /* A helper class that calls free_cached_comp_units on
2199 class free_cached_comp_units
2203 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2204 : m_per_objfile (per_objfile
)
2208 ~free_cached_comp_units ()
2210 m_per_objfile
->free_cached_comp_units ();
2213 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2217 dwarf2_per_objfile
*m_per_objfile
;
2220 /* Try to locate the sections we need for DWARF 2 debugging
2221 information and return true if we have enough to do something.
2222 NAMES points to the dwarf2 section names, or is NULL if the standard
2223 ELF names are used. CAN_COPY is true for formats where symbol
2224 interposition is possible and so symbol values must follow copy
2225 relocation rules. */
2228 dwarf2_has_info (struct objfile
*objfile
,
2229 const struct dwarf2_debug_sections
*names
,
2232 if (objfile
->flags
& OBJF_READNEVER
)
2235 struct dwarf2_per_objfile
*dwarf2_per_objfile
2236 = get_dwarf2_per_objfile (objfile
);
2238 if (dwarf2_per_objfile
== NULL
)
2239 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2243 return (!dwarf2_per_objfile
->info
.is_virtual
2244 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2245 && !dwarf2_per_objfile
->abbrev
.is_virtual
2246 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2249 /* Return the containing section of virtual section SECTION. */
2251 static struct dwarf2_section_info
*
2252 get_containing_section (const struct dwarf2_section_info
*section
)
2254 gdb_assert (section
->is_virtual
);
2255 return section
->s
.containing_section
;
2258 /* Return the bfd owner of SECTION. */
2261 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2263 if (section
->is_virtual
)
2265 section
= get_containing_section (section
);
2266 gdb_assert (!section
->is_virtual
);
2268 return section
->s
.section
->owner
;
2271 /* Return the bfd section of SECTION.
2272 Returns NULL if the section is not present. */
2275 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2277 if (section
->is_virtual
)
2279 section
= get_containing_section (section
);
2280 gdb_assert (!section
->is_virtual
);
2282 return section
->s
.section
;
2285 /* Return the name of SECTION. */
2288 get_section_name (const struct dwarf2_section_info
*section
)
2290 asection
*sectp
= get_section_bfd_section (section
);
2292 gdb_assert (sectp
!= NULL
);
2293 return bfd_section_name (sectp
);
2296 /* Return the name of the file SECTION is in. */
2299 get_section_file_name (const struct dwarf2_section_info
*section
)
2301 bfd
*abfd
= get_section_bfd_owner (section
);
2303 return bfd_get_filename (abfd
);
2306 /* Return the id of SECTION.
2307 Returns 0 if SECTION doesn't exist. */
2310 get_section_id (const struct dwarf2_section_info
*section
)
2312 asection
*sectp
= get_section_bfd_section (section
);
2319 /* Return the flags of SECTION.
2320 SECTION (or containing section if this is a virtual section) must exist. */
2323 get_section_flags (const struct dwarf2_section_info
*section
)
2325 asection
*sectp
= get_section_bfd_section (section
);
2327 gdb_assert (sectp
!= NULL
);
2328 return bfd_section_flags (sectp
);
2331 /* When loading sections, we look either for uncompressed section or for
2332 compressed section names. */
2335 section_is_p (const char *section_name
,
2336 const struct dwarf2_section_names
*names
)
2338 if (names
->normal
!= NULL
2339 && strcmp (section_name
, names
->normal
) == 0)
2341 if (names
->compressed
!= NULL
2342 && strcmp (section_name
, names
->compressed
) == 0)
2347 /* See declaration. */
2350 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2351 const dwarf2_debug_sections
&names
)
2353 flagword aflag
= bfd_section_flags (sectp
);
2355 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2358 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2359 > bfd_get_file_size (abfd
))
2361 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2362 warning (_("Discarding section %s which has a section size (%s"
2363 ") larger than the file size [in module %s]"),
2364 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2365 bfd_get_filename (abfd
));
2367 else if (section_is_p (sectp
->name
, &names
.info
))
2369 this->info
.s
.section
= sectp
;
2370 this->info
.size
= bfd_section_size (sectp
);
2372 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2374 this->abbrev
.s
.section
= sectp
;
2375 this->abbrev
.size
= bfd_section_size (sectp
);
2377 else if (section_is_p (sectp
->name
, &names
.line
))
2379 this->line
.s
.section
= sectp
;
2380 this->line
.size
= bfd_section_size (sectp
);
2382 else if (section_is_p (sectp
->name
, &names
.loc
))
2384 this->loc
.s
.section
= sectp
;
2385 this->loc
.size
= bfd_section_size (sectp
);
2387 else if (section_is_p (sectp
->name
, &names
.loclists
))
2389 this->loclists
.s
.section
= sectp
;
2390 this->loclists
.size
= bfd_section_size (sectp
);
2392 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2394 this->macinfo
.s
.section
= sectp
;
2395 this->macinfo
.size
= bfd_section_size (sectp
);
2397 else if (section_is_p (sectp
->name
, &names
.macro
))
2399 this->macro
.s
.section
= sectp
;
2400 this->macro
.size
= bfd_section_size (sectp
);
2402 else if (section_is_p (sectp
->name
, &names
.str
))
2404 this->str
.s
.section
= sectp
;
2405 this->str
.size
= bfd_section_size (sectp
);
2407 else if (section_is_p (sectp
->name
, &names
.line_str
))
2409 this->line_str
.s
.section
= sectp
;
2410 this->line_str
.size
= bfd_section_size (sectp
);
2412 else if (section_is_p (sectp
->name
, &names
.addr
))
2414 this->addr
.s
.section
= sectp
;
2415 this->addr
.size
= bfd_section_size (sectp
);
2417 else if (section_is_p (sectp
->name
, &names
.frame
))
2419 this->frame
.s
.section
= sectp
;
2420 this->frame
.size
= bfd_section_size (sectp
);
2422 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2424 this->eh_frame
.s
.section
= sectp
;
2425 this->eh_frame
.size
= bfd_section_size (sectp
);
2427 else if (section_is_p (sectp
->name
, &names
.ranges
))
2429 this->ranges
.s
.section
= sectp
;
2430 this->ranges
.size
= bfd_section_size (sectp
);
2432 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2434 this->rnglists
.s
.section
= sectp
;
2435 this->rnglists
.size
= bfd_section_size (sectp
);
2437 else if (section_is_p (sectp
->name
, &names
.types
))
2439 struct dwarf2_section_info type_section
;
2441 memset (&type_section
, 0, sizeof (type_section
));
2442 type_section
.s
.section
= sectp
;
2443 type_section
.size
= bfd_section_size (sectp
);
2445 this->types
.push_back (type_section
);
2447 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2449 this->gdb_index
.s
.section
= sectp
;
2450 this->gdb_index
.size
= bfd_section_size (sectp
);
2452 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2454 this->debug_names
.s
.section
= sectp
;
2455 this->debug_names
.size
= bfd_section_size (sectp
);
2457 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2459 this->debug_aranges
.s
.section
= sectp
;
2460 this->debug_aranges
.size
= bfd_section_size (sectp
);
2463 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2464 && bfd_section_vma (sectp
) == 0)
2465 this->has_section_at_zero
= true;
2468 /* A helper function that decides whether a section is empty,
2472 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2474 if (section
->is_virtual
)
2475 return section
->size
== 0;
2476 return section
->s
.section
== NULL
|| section
->size
== 0;
2479 /* See dwarf2read.h. */
2482 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2486 gdb_byte
*buf
, *retbuf
;
2490 info
->buffer
= NULL
;
2491 info
->readin
= true;
2493 if (dwarf2_section_empty_p (info
))
2496 sectp
= get_section_bfd_section (info
);
2498 /* If this is a virtual section we need to read in the real one first. */
2499 if (info
->is_virtual
)
2501 struct dwarf2_section_info
*containing_section
=
2502 get_containing_section (info
);
2504 gdb_assert (sectp
!= NULL
);
2505 if ((sectp
->flags
& SEC_RELOC
) != 0)
2507 error (_("Dwarf Error: DWP format V2 with relocations is not"
2508 " supported in section %s [in module %s]"),
2509 get_section_name (info
), get_section_file_name (info
));
2511 dwarf2_read_section (objfile
, containing_section
);
2512 /* Other code should have already caught virtual sections that don't
2514 gdb_assert (info
->virtual_offset
+ info
->size
2515 <= containing_section
->size
);
2516 /* If the real section is empty or there was a problem reading the
2517 section we shouldn't get here. */
2518 gdb_assert (containing_section
->buffer
!= NULL
);
2519 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2523 /* If the section has relocations, we must read it ourselves.
2524 Otherwise we attach it to the BFD. */
2525 if ((sectp
->flags
& SEC_RELOC
) == 0)
2527 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2531 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2534 /* When debugging .o files, we may need to apply relocations; see
2535 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2536 We never compress sections in .o files, so we only need to
2537 try this when the section is not compressed. */
2538 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2541 info
->buffer
= retbuf
;
2545 abfd
= get_section_bfd_owner (info
);
2546 gdb_assert (abfd
!= NULL
);
2548 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2549 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2551 error (_("Dwarf Error: Can't read DWARF data"
2552 " in section %s [in module %s]"),
2553 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2557 /* A helper function that returns the size of a section in a safe way.
2558 If you are positive that the section has been read before using the
2559 size, then it is safe to refer to the dwarf2_section_info object's
2560 "size" field directly. In other cases, you must call this
2561 function, because for compressed sections the size field is not set
2562 correctly until the section has been read. */
2564 static bfd_size_type
2565 dwarf2_section_size (struct objfile
*objfile
,
2566 struct dwarf2_section_info
*info
)
2569 dwarf2_read_section (objfile
, info
);
2573 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2577 dwarf2_get_section_info (struct objfile
*objfile
,
2578 enum dwarf2_section_enum sect
,
2579 asection
**sectp
, const gdb_byte
**bufp
,
2580 bfd_size_type
*sizep
)
2582 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2583 struct dwarf2_section_info
*info
;
2585 /* We may see an objfile without any DWARF, in which case we just
2596 case DWARF2_DEBUG_FRAME
:
2597 info
= &data
->frame
;
2599 case DWARF2_EH_FRAME
:
2600 info
= &data
->eh_frame
;
2603 gdb_assert_not_reached ("unexpected section");
2606 dwarf2_read_section (objfile
, info
);
2608 *sectp
= get_section_bfd_section (info
);
2609 *bufp
= info
->buffer
;
2610 *sizep
= info
->size
;
2613 /* A helper function to find the sections for a .dwz file. */
2616 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2618 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2620 /* Note that we only support the standard ELF names, because .dwz
2621 is ELF-only (at the time of writing). */
2622 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2624 dwz_file
->abbrev
.s
.section
= sectp
;
2625 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2627 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2629 dwz_file
->info
.s
.section
= sectp
;
2630 dwz_file
->info
.size
= bfd_section_size (sectp
);
2632 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2634 dwz_file
->str
.s
.section
= sectp
;
2635 dwz_file
->str
.size
= bfd_section_size (sectp
);
2637 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2639 dwz_file
->line
.s
.section
= sectp
;
2640 dwz_file
->line
.size
= bfd_section_size (sectp
);
2642 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2644 dwz_file
->macro
.s
.section
= sectp
;
2645 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2647 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2649 dwz_file
->gdb_index
.s
.section
= sectp
;
2650 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2652 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2654 dwz_file
->debug_names
.s
.section
= sectp
;
2655 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2659 /* See dwarf2read.h. */
2662 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2664 const char *filename
;
2665 bfd_size_type buildid_len_arg
;
2669 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2670 return dwarf2_per_objfile
->dwz_file
.get ();
2672 bfd_set_error (bfd_error_no_error
);
2673 gdb::unique_xmalloc_ptr
<char> data
2674 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2675 &buildid_len_arg
, &buildid
));
2678 if (bfd_get_error () == bfd_error_no_error
)
2680 error (_("could not read '.gnu_debugaltlink' section: %s"),
2681 bfd_errmsg (bfd_get_error ()));
2684 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2686 buildid_len
= (size_t) buildid_len_arg
;
2688 filename
= data
.get ();
2690 std::string abs_storage
;
2691 if (!IS_ABSOLUTE_PATH (filename
))
2693 gdb::unique_xmalloc_ptr
<char> abs
2694 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2696 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2697 filename
= abs_storage
.c_str ();
2700 /* First try the file name given in the section. If that doesn't
2701 work, try to use the build-id instead. */
2702 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2703 if (dwz_bfd
!= NULL
)
2705 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2706 dwz_bfd
.reset (nullptr);
2709 if (dwz_bfd
== NULL
)
2710 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2712 if (dwz_bfd
== NULL
)
2713 error (_("could not find '.gnu_debugaltlink' file for %s"),
2714 objfile_name (dwarf2_per_objfile
->objfile
));
2716 std::unique_ptr
<struct dwz_file
> result
2717 (new struct dwz_file (std::move (dwz_bfd
)));
2719 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2722 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2723 result
->dwz_bfd
.get ());
2724 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2725 return dwarf2_per_objfile
->dwz_file
.get ();
2728 /* DWARF quick_symbols_functions support. */
2730 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2731 unique line tables, so we maintain a separate table of all .debug_line
2732 derived entries to support the sharing.
2733 All the quick functions need is the list of file names. We discard the
2734 line_header when we're done and don't need to record it here. */
2735 struct quick_file_names
2737 /* The data used to construct the hash key. */
2738 struct stmt_list_hash hash
;
2740 /* The number of entries in file_names, real_names. */
2741 unsigned int num_file_names
;
2743 /* The file names from the line table, after being run through
2745 const char **file_names
;
2747 /* The file names from the line table after being run through
2748 gdb_realpath. These are computed lazily. */
2749 const char **real_names
;
2752 /* When using the index (and thus not using psymtabs), each CU has an
2753 object of this type. This is used to hold information needed by
2754 the various "quick" methods. */
2755 struct dwarf2_per_cu_quick_data
2757 /* The file table. This can be NULL if there was no file table
2758 or it's currently not read in.
2759 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2760 struct quick_file_names
*file_names
;
2762 /* The corresponding symbol table. This is NULL if symbols for this
2763 CU have not yet been read. */
2764 struct compunit_symtab
*compunit_symtab
;
2766 /* A temporary mark bit used when iterating over all CUs in
2767 expand_symtabs_matching. */
2768 unsigned int mark
: 1;
2770 /* True if we've tried to read the file table and found there isn't one.
2771 There will be no point in trying to read it again next time. */
2772 unsigned int no_file_data
: 1;
2775 /* Utility hash function for a stmt_list_hash. */
2778 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2782 if (stmt_list_hash
->dwo_unit
!= NULL
)
2783 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2784 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2788 /* Utility equality function for a stmt_list_hash. */
2791 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2792 const struct stmt_list_hash
*rhs
)
2794 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2796 if (lhs
->dwo_unit
!= NULL
2797 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2800 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2803 /* Hash function for a quick_file_names. */
2806 hash_file_name_entry (const void *e
)
2808 const struct quick_file_names
*file_data
2809 = (const struct quick_file_names
*) e
;
2811 return hash_stmt_list_entry (&file_data
->hash
);
2814 /* Equality function for a quick_file_names. */
2817 eq_file_name_entry (const void *a
, const void *b
)
2819 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2820 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2822 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2825 /* Delete function for a quick_file_names. */
2828 delete_file_name_entry (void *e
)
2830 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2833 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2835 xfree ((void*) file_data
->file_names
[i
]);
2836 if (file_data
->real_names
)
2837 xfree ((void*) file_data
->real_names
[i
]);
2840 /* The space for the struct itself lives on objfile_obstack,
2841 so we don't free it here. */
2844 /* Create a quick_file_names hash table. */
2847 create_quick_file_names_table (unsigned int nr_initial_entries
)
2849 return htab_create_alloc (nr_initial_entries
,
2850 hash_file_name_entry
, eq_file_name_entry
,
2851 delete_file_name_entry
, xcalloc
, xfree
);
2854 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2855 have to be created afterwards. You should call age_cached_comp_units after
2856 processing PER_CU->CU. dw2_setup must have been already called. */
2859 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2861 if (per_cu
->is_debug_types
)
2862 load_full_type_unit (per_cu
);
2864 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2866 if (per_cu
->cu
== NULL
)
2867 return; /* Dummy CU. */
2869 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2872 /* Read in the symbols for PER_CU. */
2875 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2877 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2879 /* Skip type_unit_groups, reading the type units they contain
2880 is handled elsewhere. */
2881 if (IS_TYPE_UNIT_GROUP (per_cu
))
2884 /* The destructor of dwarf2_queue_guard frees any entries left on
2885 the queue. After this point we're guaranteed to leave this function
2886 with the dwarf queue empty. */
2887 dwarf2_queue_guard q_guard
;
2889 if (dwarf2_per_objfile
->using_index
2890 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2891 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2893 queue_comp_unit (per_cu
, language_minimal
);
2894 load_cu (per_cu
, skip_partial
);
2896 /* If we just loaded a CU from a DWO, and we're working with an index
2897 that may badly handle TUs, load all the TUs in that DWO as well.
2898 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2899 if (!per_cu
->is_debug_types
2900 && per_cu
->cu
!= NULL
2901 && per_cu
->cu
->dwo_unit
!= NULL
2902 && dwarf2_per_objfile
->index_table
!= NULL
2903 && dwarf2_per_objfile
->index_table
->version
<= 7
2904 /* DWP files aren't supported yet. */
2905 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2906 queue_and_load_all_dwo_tus (per_cu
);
2909 process_queue (dwarf2_per_objfile
);
2911 /* Age the cache, releasing compilation units that have not
2912 been used recently. */
2913 age_cached_comp_units (dwarf2_per_objfile
);
2916 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2917 the objfile from which this CU came. Returns the resulting symbol
2920 static struct compunit_symtab
*
2921 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2923 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2925 gdb_assert (dwarf2_per_objfile
->using_index
);
2926 if (!per_cu
->v
.quick
->compunit_symtab
)
2928 free_cached_comp_units
freer (dwarf2_per_objfile
);
2929 scoped_restore decrementer
= increment_reading_symtab ();
2930 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2931 process_cu_includes (dwarf2_per_objfile
);
2934 return per_cu
->v
.quick
->compunit_symtab
;
2937 /* See declaration. */
2939 dwarf2_per_cu_data
*
2940 dwarf2_per_objfile::get_cutu (int index
)
2942 if (index
>= this->all_comp_units
.size ())
2944 index
-= this->all_comp_units
.size ();
2945 gdb_assert (index
< this->all_type_units
.size ());
2946 return &this->all_type_units
[index
]->per_cu
;
2949 return this->all_comp_units
[index
];
2952 /* See declaration. */
2954 dwarf2_per_cu_data
*
2955 dwarf2_per_objfile::get_cu (int index
)
2957 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2959 return this->all_comp_units
[index
];
2962 /* See declaration. */
2965 dwarf2_per_objfile::get_tu (int index
)
2967 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2969 return this->all_type_units
[index
];
2972 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2973 objfile_obstack, and constructed with the specified field
2976 static dwarf2_per_cu_data
*
2977 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2978 struct dwarf2_section_info
*section
,
2980 sect_offset sect_off
, ULONGEST length
)
2982 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2983 dwarf2_per_cu_data
*the_cu
2984 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2985 struct dwarf2_per_cu_data
);
2986 the_cu
->sect_off
= sect_off
;
2987 the_cu
->length
= length
;
2988 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2989 the_cu
->section
= section
;
2990 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2991 struct dwarf2_per_cu_quick_data
);
2992 the_cu
->is_dwz
= is_dwz
;
2996 /* A helper for create_cus_from_index that handles a given list of
3000 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3001 const gdb_byte
*cu_list
, offset_type n_elements
,
3002 struct dwarf2_section_info
*section
,
3005 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
3007 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3009 sect_offset sect_off
3010 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3011 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3014 dwarf2_per_cu_data
*per_cu
3015 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3017 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3021 /* Read the CU list from the mapped index, and use it to create all
3022 the CU objects for this objfile. */
3025 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3026 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3027 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3029 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3030 dwarf2_per_objfile
->all_comp_units
.reserve
3031 ((cu_list_elements
+ dwz_elements
) / 2);
3033 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3034 &dwarf2_per_objfile
->info
, 0);
3036 if (dwz_elements
== 0)
3039 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3040 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3044 /* Create the signatured type hash table from the index. */
3047 create_signatured_type_table_from_index
3048 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3049 struct dwarf2_section_info
*section
,
3050 const gdb_byte
*bytes
,
3051 offset_type elements
)
3053 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3055 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3056 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3058 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3060 for (offset_type i
= 0; i
< elements
; i
+= 3)
3062 struct signatured_type
*sig_type
;
3065 cu_offset type_offset_in_tu
;
3067 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3068 sect_offset sect_off
3069 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3071 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3073 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3076 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3077 struct signatured_type
);
3078 sig_type
->signature
= signature
;
3079 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3080 sig_type
->per_cu
.is_debug_types
= 1;
3081 sig_type
->per_cu
.section
= section
;
3082 sig_type
->per_cu
.sect_off
= sect_off
;
3083 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3084 sig_type
->per_cu
.v
.quick
3085 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3086 struct dwarf2_per_cu_quick_data
);
3088 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3091 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3094 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3097 /* Create the signatured type hash table from .debug_names. */
3100 create_signatured_type_table_from_debug_names
3101 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3102 const mapped_debug_names
&map
,
3103 struct dwarf2_section_info
*section
,
3104 struct dwarf2_section_info
*abbrev_section
)
3106 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3108 dwarf2_read_section (objfile
, section
);
3109 dwarf2_read_section (objfile
, abbrev_section
);
3111 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3112 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3114 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3116 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3118 struct signatured_type
*sig_type
;
3121 sect_offset sect_off
3122 = (sect_offset
) (extract_unsigned_integer
3123 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3125 map
.dwarf5_byte_order
));
3127 comp_unit_head cu_header
;
3128 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3130 section
->buffer
+ to_underlying (sect_off
),
3133 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3134 struct signatured_type
);
3135 sig_type
->signature
= cu_header
.signature
;
3136 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3137 sig_type
->per_cu
.is_debug_types
= 1;
3138 sig_type
->per_cu
.section
= section
;
3139 sig_type
->per_cu
.sect_off
= sect_off
;
3140 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3141 sig_type
->per_cu
.v
.quick
3142 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3143 struct dwarf2_per_cu_quick_data
);
3145 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3148 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3151 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3154 /* Read the address map data from the mapped index, and use it to
3155 populate the objfile's psymtabs_addrmap. */
3158 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3159 struct mapped_index
*index
)
3161 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3162 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3163 const gdb_byte
*iter
, *end
;
3164 struct addrmap
*mutable_map
;
3167 auto_obstack temp_obstack
;
3169 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3171 iter
= index
->address_table
.data ();
3172 end
= iter
+ index
->address_table
.size ();
3174 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
3178 ULONGEST hi
, lo
, cu_index
;
3179 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3181 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3183 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3188 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3189 hex_string (lo
), hex_string (hi
));
3193 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3195 complaint (_(".gdb_index address table has invalid CU number %u"),
3196 (unsigned) cu_index
);
3200 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3201 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3202 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3203 dwarf2_per_objfile
->get_cu (cu_index
));
3206 objfile
->partial_symtabs
->psymtabs_addrmap
3207 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3210 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3211 populate the objfile's psymtabs_addrmap. */
3214 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3215 struct dwarf2_section_info
*section
)
3217 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3218 bfd
*abfd
= objfile
->obfd
;
3219 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3220 const CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
3222 auto_obstack temp_obstack
;
3223 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3225 std::unordered_map
<sect_offset
,
3226 dwarf2_per_cu_data
*,
3227 gdb::hash_enum
<sect_offset
>>
3228 debug_info_offset_to_per_cu
;
3229 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3231 const auto insertpair
3232 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3233 if (!insertpair
.second
)
3235 warning (_("Section .debug_aranges in %s has duplicate "
3236 "debug_info_offset %s, ignoring .debug_aranges."),
3237 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3242 dwarf2_read_section (objfile
, section
);
3244 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3246 const gdb_byte
*addr
= section
->buffer
;
3248 while (addr
< section
->buffer
+ section
->size
)
3250 const gdb_byte
*const entry_addr
= addr
;
3251 unsigned int bytes_read
;
3253 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3257 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3258 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3259 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3260 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3262 warning (_("Section .debug_aranges in %s entry at offset %s "
3263 "length %s exceeds section length %s, "
3264 "ignoring .debug_aranges."),
3265 objfile_name (objfile
),
3266 plongest (entry_addr
- section
->buffer
),
3267 plongest (bytes_read
+ entry_length
),
3268 pulongest (section
->size
));
3272 /* The version number. */
3273 const uint16_t version
= read_2_bytes (abfd
, addr
);
3277 warning (_("Section .debug_aranges in %s entry at offset %s "
3278 "has unsupported version %d, ignoring .debug_aranges."),
3279 objfile_name (objfile
),
3280 plongest (entry_addr
- section
->buffer
), version
);
3284 const uint64_t debug_info_offset
3285 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3286 addr
+= offset_size
;
3287 const auto per_cu_it
3288 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3289 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3291 warning (_("Section .debug_aranges in %s entry at offset %s "
3292 "debug_info_offset %s does not exists, "
3293 "ignoring .debug_aranges."),
3294 objfile_name (objfile
),
3295 plongest (entry_addr
- section
->buffer
),
3296 pulongest (debug_info_offset
));
3299 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3301 const uint8_t address_size
= *addr
++;
3302 if (address_size
< 1 || address_size
> 8)
3304 warning (_("Section .debug_aranges in %s entry at offset %s "
3305 "address_size %u is invalid, ignoring .debug_aranges."),
3306 objfile_name (objfile
),
3307 plongest (entry_addr
- section
->buffer
), address_size
);
3311 const uint8_t segment_selector_size
= *addr
++;
3312 if (segment_selector_size
!= 0)
3314 warning (_("Section .debug_aranges in %s entry at offset %s "
3315 "segment_selector_size %u is not supported, "
3316 "ignoring .debug_aranges."),
3317 objfile_name (objfile
),
3318 plongest (entry_addr
- section
->buffer
),
3319 segment_selector_size
);
3323 /* Must pad to an alignment boundary that is twice the address
3324 size. It is undocumented by the DWARF standard but GCC does
3326 for (size_t padding
= ((-(addr
- section
->buffer
))
3327 & (2 * address_size
- 1));
3328 padding
> 0; padding
--)
3331 warning (_("Section .debug_aranges in %s entry at offset %s "
3332 "padding is not zero, ignoring .debug_aranges."),
3333 objfile_name (objfile
),
3334 plongest (entry_addr
- section
->buffer
));
3340 if (addr
+ 2 * address_size
> entry_end
)
3342 warning (_("Section .debug_aranges in %s entry at offset %s "
3343 "address list is not properly terminated, "
3344 "ignoring .debug_aranges."),
3345 objfile_name (objfile
),
3346 plongest (entry_addr
- section
->buffer
));
3349 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3351 addr
+= address_size
;
3352 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3354 addr
+= address_size
;
3355 if (start
== 0 && length
== 0)
3357 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3359 /* Symbol was eliminated due to a COMDAT group. */
3362 ULONGEST end
= start
+ length
;
3363 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3365 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3367 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3371 objfile
->partial_symtabs
->psymtabs_addrmap
3372 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3375 /* Find a slot in the mapped index INDEX for the object named NAME.
3376 If NAME is found, set *VEC_OUT to point to the CU vector in the
3377 constant pool and return true. If NAME cannot be found, return
3381 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3382 offset_type
**vec_out
)
3385 offset_type slot
, step
;
3386 int (*cmp
) (const char *, const char *);
3388 gdb::unique_xmalloc_ptr
<char> without_params
;
3389 if (current_language
->la_language
== language_cplus
3390 || current_language
->la_language
== language_fortran
3391 || current_language
->la_language
== language_d
)
3393 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3396 if (strchr (name
, '(') != NULL
)
3398 without_params
= cp_remove_params (name
);
3400 if (without_params
!= NULL
)
3401 name
= without_params
.get ();
3405 /* Index version 4 did not support case insensitive searches. But the
3406 indices for case insensitive languages are built in lowercase, therefore
3407 simulate our NAME being searched is also lowercased. */
3408 hash
= mapped_index_string_hash ((index
->version
== 4
3409 && case_sensitivity
== case_sensitive_off
3410 ? 5 : index
->version
),
3413 slot
= hash
& (index
->symbol_table
.size () - 1);
3414 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3415 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3421 const auto &bucket
= index
->symbol_table
[slot
];
3422 if (bucket
.name
== 0 && bucket
.vec
== 0)
3425 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3426 if (!cmp (name
, str
))
3428 *vec_out
= (offset_type
*) (index
->constant_pool
3429 + MAYBE_SWAP (bucket
.vec
));
3433 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3437 /* A helper function that reads the .gdb_index from BUFFER and fills
3438 in MAP. FILENAME is the name of the file containing the data;
3439 it is used for error reporting. DEPRECATED_OK is true if it is
3440 ok to use deprecated sections.
3442 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3443 out parameters that are filled in with information about the CU and
3444 TU lists in the section.
3446 Returns true if all went well, false otherwise. */
3449 read_gdb_index_from_buffer (struct objfile
*objfile
,
3450 const char *filename
,
3452 gdb::array_view
<const gdb_byte
> buffer
,
3453 struct mapped_index
*map
,
3454 const gdb_byte
**cu_list
,
3455 offset_type
*cu_list_elements
,
3456 const gdb_byte
**types_list
,
3457 offset_type
*types_list_elements
)
3459 const gdb_byte
*addr
= &buffer
[0];
3461 /* Version check. */
3462 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3463 /* Versions earlier than 3 emitted every copy of a psymbol. This
3464 causes the index to behave very poorly for certain requests. Version 3
3465 contained incomplete addrmap. So, it seems better to just ignore such
3469 static int warning_printed
= 0;
3470 if (!warning_printed
)
3472 warning (_("Skipping obsolete .gdb_index section in %s."),
3474 warning_printed
= 1;
3478 /* Index version 4 uses a different hash function than index version
3481 Versions earlier than 6 did not emit psymbols for inlined
3482 functions. Using these files will cause GDB not to be able to
3483 set breakpoints on inlined functions by name, so we ignore these
3484 indices unless the user has done
3485 "set use-deprecated-index-sections on". */
3486 if (version
< 6 && !deprecated_ok
)
3488 static int warning_printed
= 0;
3489 if (!warning_printed
)
3492 Skipping deprecated .gdb_index section in %s.\n\
3493 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3494 to use the section anyway."),
3496 warning_printed
= 1;
3500 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3501 of the TU (for symbols coming from TUs),
3502 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3503 Plus gold-generated indices can have duplicate entries for global symbols,
3504 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3505 These are just performance bugs, and we can't distinguish gdb-generated
3506 indices from gold-generated ones, so issue no warning here. */
3508 /* Indexes with higher version than the one supported by GDB may be no
3509 longer backward compatible. */
3513 map
->version
= version
;
3515 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3518 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3519 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3523 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3524 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3525 - MAYBE_SWAP (metadata
[i
]))
3529 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3530 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3532 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3535 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3536 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3538 = gdb::array_view
<mapped_index::symbol_table_slot
>
3539 ((mapped_index::symbol_table_slot
*) symbol_table
,
3540 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3543 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3548 /* Callback types for dwarf2_read_gdb_index. */
3550 typedef gdb::function_view
3551 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3552 get_gdb_index_contents_ftype
;
3553 typedef gdb::function_view
3554 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3555 get_gdb_index_contents_dwz_ftype
;
3557 /* Read .gdb_index. If everything went ok, initialize the "quick"
3558 elements of all the CUs and return 1. Otherwise, return 0. */
3561 dwarf2_read_gdb_index
3562 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3563 get_gdb_index_contents_ftype get_gdb_index_contents
,
3564 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3566 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3567 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3568 struct dwz_file
*dwz
;
3569 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3571 gdb::array_view
<const gdb_byte
> main_index_contents
3572 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3574 if (main_index_contents
.empty ())
3577 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3578 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3579 use_deprecated_index_sections
,
3580 main_index_contents
, map
.get (), &cu_list
,
3581 &cu_list_elements
, &types_list
,
3582 &types_list_elements
))
3585 /* Don't use the index if it's empty. */
3586 if (map
->symbol_table
.empty ())
3589 /* If there is a .dwz file, read it so we can get its CU list as
3591 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3594 struct mapped_index dwz_map
;
3595 const gdb_byte
*dwz_types_ignore
;
3596 offset_type dwz_types_elements_ignore
;
3598 gdb::array_view
<const gdb_byte
> dwz_index_content
3599 = get_gdb_index_contents_dwz (objfile
, dwz
);
3601 if (dwz_index_content
.empty ())
3604 if (!read_gdb_index_from_buffer (objfile
,
3605 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3606 1, dwz_index_content
, &dwz_map
,
3607 &dwz_list
, &dwz_list_elements
,
3609 &dwz_types_elements_ignore
))
3611 warning (_("could not read '.gdb_index' section from %s; skipping"),
3612 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3617 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3618 dwz_list
, dwz_list_elements
);
3620 if (types_list_elements
)
3622 /* We can only handle a single .debug_types when we have an
3624 if (dwarf2_per_objfile
->types
.size () != 1)
3627 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3629 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3630 types_list
, types_list_elements
);
3633 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3635 dwarf2_per_objfile
->index_table
= std::move (map
);
3636 dwarf2_per_objfile
->using_index
= 1;
3637 dwarf2_per_objfile
->quick_file_names_table
=
3638 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3643 /* die_reader_func for dw2_get_file_names. */
3646 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3647 const gdb_byte
*info_ptr
,
3648 struct die_info
*comp_unit_die
,
3652 struct dwarf2_cu
*cu
= reader
->cu
;
3653 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3654 struct dwarf2_per_objfile
*dwarf2_per_objfile
3655 = cu
->per_cu
->dwarf2_per_objfile
;
3656 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3657 struct dwarf2_per_cu_data
*lh_cu
;
3658 struct attribute
*attr
;
3660 struct quick_file_names
*qfn
;
3662 gdb_assert (! this_cu
->is_debug_types
);
3664 /* Our callers never want to match partial units -- instead they
3665 will match the enclosing full CU. */
3666 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3668 this_cu
->v
.quick
->no_file_data
= 1;
3676 sect_offset line_offset
{};
3678 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3679 if (attr
!= nullptr)
3681 struct quick_file_names find_entry
;
3683 line_offset
= (sect_offset
) DW_UNSND (attr
);
3685 /* We may have already read in this line header (TU line header sharing).
3686 If we have we're done. */
3687 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3688 find_entry
.hash
.line_sect_off
= line_offset
;
3689 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3690 &find_entry
, INSERT
);
3693 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3697 lh
= dwarf_decode_line_header (line_offset
, cu
);
3701 lh_cu
->v
.quick
->no_file_data
= 1;
3705 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3706 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3707 qfn
->hash
.line_sect_off
= line_offset
;
3708 gdb_assert (slot
!= NULL
);
3711 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3714 if (strcmp (fnd
.name
, "<unknown>") != 0)
3717 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3719 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3721 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3722 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3723 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3724 qfn
->real_names
= NULL
;
3726 lh_cu
->v
.quick
->file_names
= qfn
;
3729 /* A helper for the "quick" functions which attempts to read the line
3730 table for THIS_CU. */
3732 static struct quick_file_names
*
3733 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3735 /* This should never be called for TUs. */
3736 gdb_assert (! this_cu
->is_debug_types
);
3737 /* Nor type unit groups. */
3738 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3740 if (this_cu
->v
.quick
->file_names
!= NULL
)
3741 return this_cu
->v
.quick
->file_names
;
3742 /* If we know there is no line data, no point in looking again. */
3743 if (this_cu
->v
.quick
->no_file_data
)
3746 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3748 if (this_cu
->v
.quick
->no_file_data
)
3750 return this_cu
->v
.quick
->file_names
;
3753 /* A helper for the "quick" functions which computes and caches the
3754 real path for a given file name from the line table. */
3757 dw2_get_real_path (struct objfile
*objfile
,
3758 struct quick_file_names
*qfn
, int index
)
3760 if (qfn
->real_names
== NULL
)
3761 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3762 qfn
->num_file_names
, const char *);
3764 if (qfn
->real_names
[index
] == NULL
)
3765 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3767 return qfn
->real_names
[index
];
3770 static struct symtab
*
3771 dw2_find_last_source_symtab (struct objfile
*objfile
)
3773 struct dwarf2_per_objfile
*dwarf2_per_objfile
3774 = get_dwarf2_per_objfile (objfile
);
3775 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3776 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3781 return compunit_primary_filetab (cust
);
3784 /* Traversal function for dw2_forget_cached_source_info. */
3787 dw2_free_cached_file_names (void **slot
, void *info
)
3789 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3791 if (file_data
->real_names
)
3795 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3797 xfree ((void*) file_data
->real_names
[i
]);
3798 file_data
->real_names
[i
] = NULL
;
3806 dw2_forget_cached_source_info (struct objfile
*objfile
)
3808 struct dwarf2_per_objfile
*dwarf2_per_objfile
3809 = get_dwarf2_per_objfile (objfile
);
3811 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3812 dw2_free_cached_file_names
, NULL
);
3815 /* Helper function for dw2_map_symtabs_matching_filename that expands
3816 the symtabs and calls the iterator. */
3819 dw2_map_expand_apply (struct objfile
*objfile
,
3820 struct dwarf2_per_cu_data
*per_cu
,
3821 const char *name
, const char *real_path
,
3822 gdb::function_view
<bool (symtab
*)> callback
)
3824 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3826 /* Don't visit already-expanded CUs. */
3827 if (per_cu
->v
.quick
->compunit_symtab
)
3830 /* This may expand more than one symtab, and we want to iterate over
3832 dw2_instantiate_symtab (per_cu
, false);
3834 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3835 last_made
, callback
);
3838 /* Implementation of the map_symtabs_matching_filename method. */
3841 dw2_map_symtabs_matching_filename
3842 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3843 gdb::function_view
<bool (symtab
*)> callback
)
3845 const char *name_basename
= lbasename (name
);
3846 struct dwarf2_per_objfile
*dwarf2_per_objfile
3847 = get_dwarf2_per_objfile (objfile
);
3849 /* The rule is CUs specify all the files, including those used by
3850 any TU, so there's no need to scan TUs here. */
3852 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3854 /* We only need to look at symtabs not already expanded. */
3855 if (per_cu
->v
.quick
->compunit_symtab
)
3858 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3859 if (file_data
== NULL
)
3862 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3864 const char *this_name
= file_data
->file_names
[j
];
3865 const char *this_real_name
;
3867 if (compare_filenames_for_search (this_name
, name
))
3869 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3875 /* Before we invoke realpath, which can get expensive when many
3876 files are involved, do a quick comparison of the basenames. */
3877 if (! basenames_may_differ
3878 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3881 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3882 if (compare_filenames_for_search (this_real_name
, name
))
3884 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3890 if (real_path
!= NULL
)
3892 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3893 gdb_assert (IS_ABSOLUTE_PATH (name
));
3894 if (this_real_name
!= NULL
3895 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3897 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3909 /* Struct used to manage iterating over all CUs looking for a symbol. */
3911 struct dw2_symtab_iterator
3913 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3914 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3915 /* If set, only look for symbols that match that block. Valid values are
3916 GLOBAL_BLOCK and STATIC_BLOCK. */
3917 gdb::optional
<block_enum
> block_index
;
3918 /* The kind of symbol we're looking for. */
3920 /* The list of CUs from the index entry of the symbol,
3921 or NULL if not found. */
3923 /* The next element in VEC to look at. */
3925 /* The number of elements in VEC, or zero if there is no match. */
3927 /* Have we seen a global version of the symbol?
3928 If so we can ignore all further global instances.
3929 This is to work around gold/15646, inefficient gold-generated
3934 /* Initialize the index symtab iterator ITER. */
3937 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3938 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3939 gdb::optional
<block_enum
> block_index
,
3943 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3944 iter
->block_index
= block_index
;
3945 iter
->domain
= domain
;
3947 iter
->global_seen
= 0;
3949 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3951 /* index is NULL if OBJF_READNOW. */
3952 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3953 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3961 /* Return the next matching CU or NULL if there are no more. */
3963 static struct dwarf2_per_cu_data
*
3964 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3966 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3968 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3970 offset_type cu_index_and_attrs
=
3971 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3972 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3973 gdb_index_symbol_kind symbol_kind
=
3974 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3975 /* Only check the symbol attributes if they're present.
3976 Indices prior to version 7 don't record them,
3977 and indices >= 7 may elide them for certain symbols
3978 (gold does this). */
3980 (dwarf2_per_objfile
->index_table
->version
>= 7
3981 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3983 /* Don't crash on bad data. */
3984 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3985 + dwarf2_per_objfile
->all_type_units
.size ()))
3987 complaint (_(".gdb_index entry has bad CU index"
3989 objfile_name (dwarf2_per_objfile
->objfile
));
3993 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3995 /* Skip if already read in. */
3996 if (per_cu
->v
.quick
->compunit_symtab
)
3999 /* Check static vs global. */
4002 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4004 if (iter
->block_index
.has_value ())
4006 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
4008 if (is_static
!= want_static
)
4012 /* Work around gold/15646. */
4013 if (!is_static
&& iter
->global_seen
)
4016 iter
->global_seen
= 1;
4019 /* Only check the symbol's kind if it has one. */
4022 switch (iter
->domain
)
4025 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4026 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4027 /* Some types are also in VAR_DOMAIN. */
4028 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4032 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4036 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4040 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4055 static struct compunit_symtab
*
4056 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4057 const char *name
, domain_enum domain
)
4059 struct compunit_symtab
*stab_best
= NULL
;
4060 struct dwarf2_per_objfile
*dwarf2_per_objfile
4061 = get_dwarf2_per_objfile (objfile
);
4063 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4065 struct dw2_symtab_iterator iter
;
4066 struct dwarf2_per_cu_data
*per_cu
;
4068 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4070 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4072 struct symbol
*sym
, *with_opaque
= NULL
;
4073 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4074 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4075 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4077 sym
= block_find_symbol (block
, name
, domain
,
4078 block_find_non_opaque_type_preferred
,
4081 /* Some caution must be observed with overloaded functions
4082 and methods, since the index will not contain any overload
4083 information (but NAME might contain it). */
4086 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4088 if (with_opaque
!= NULL
4089 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4092 /* Keep looking through other CUs. */
4099 dw2_print_stats (struct objfile
*objfile
)
4101 struct dwarf2_per_objfile
*dwarf2_per_objfile
4102 = get_dwarf2_per_objfile (objfile
);
4103 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4104 + dwarf2_per_objfile
->all_type_units
.size ());
4107 for (int i
= 0; i
< total
; ++i
)
4109 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4111 if (!per_cu
->v
.quick
->compunit_symtab
)
4114 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4115 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4118 /* This dumps minimal information about the index.
4119 It is called via "mt print objfiles".
4120 One use is to verify .gdb_index has been loaded by the
4121 gdb.dwarf2/gdb-index.exp testcase. */
4124 dw2_dump (struct objfile
*objfile
)
4126 struct dwarf2_per_objfile
*dwarf2_per_objfile
4127 = get_dwarf2_per_objfile (objfile
);
4129 gdb_assert (dwarf2_per_objfile
->using_index
);
4130 printf_filtered (".gdb_index:");
4131 if (dwarf2_per_objfile
->index_table
!= NULL
)
4133 printf_filtered (" version %d\n",
4134 dwarf2_per_objfile
->index_table
->version
);
4137 printf_filtered (" faked for \"readnow\"\n");
4138 printf_filtered ("\n");
4142 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4143 const char *func_name
)
4145 struct dwarf2_per_objfile
*dwarf2_per_objfile
4146 = get_dwarf2_per_objfile (objfile
);
4148 struct dw2_symtab_iterator iter
;
4149 struct dwarf2_per_cu_data
*per_cu
;
4151 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4153 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4154 dw2_instantiate_symtab (per_cu
, false);
4159 dw2_expand_all_symtabs (struct objfile
*objfile
)
4161 struct dwarf2_per_objfile
*dwarf2_per_objfile
4162 = get_dwarf2_per_objfile (objfile
);
4163 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4164 + dwarf2_per_objfile
->all_type_units
.size ());
4166 for (int i
= 0; i
< total_units
; ++i
)
4168 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4170 /* We don't want to directly expand a partial CU, because if we
4171 read it with the wrong language, then assertion failures can
4172 be triggered later on. See PR symtab/23010. So, tell
4173 dw2_instantiate_symtab to skip partial CUs -- any important
4174 partial CU will be read via DW_TAG_imported_unit anyway. */
4175 dw2_instantiate_symtab (per_cu
, true);
4180 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4181 const char *fullname
)
4183 struct dwarf2_per_objfile
*dwarf2_per_objfile
4184 = get_dwarf2_per_objfile (objfile
);
4186 /* We don't need to consider type units here.
4187 This is only called for examining code, e.g. expand_line_sal.
4188 There can be an order of magnitude (or more) more type units
4189 than comp units, and we avoid them if we can. */
4191 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4193 /* We only need to look at symtabs not already expanded. */
4194 if (per_cu
->v
.quick
->compunit_symtab
)
4197 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4198 if (file_data
== NULL
)
4201 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4203 const char *this_fullname
= file_data
->file_names
[j
];
4205 if (filename_cmp (this_fullname
, fullname
) == 0)
4207 dw2_instantiate_symtab (per_cu
, false);
4215 dw2_map_matching_symbols
4216 (struct objfile
*objfile
,
4217 const lookup_name_info
&name
, domain_enum domain
,
4219 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4220 symbol_compare_ftype
*ordered_compare
)
4222 /* Currently unimplemented; used for Ada. The function can be called if the
4223 current language is Ada for a non-Ada objfile using GNU index. As Ada
4224 does not look for non-Ada symbols this function should just return. */
4227 /* Starting from a search name, return the string that finds the upper
4228 bound of all strings that start with SEARCH_NAME in a sorted name
4229 list. Returns the empty string to indicate that the upper bound is
4230 the end of the list. */
4233 make_sort_after_prefix_name (const char *search_name
)
4235 /* When looking to complete "func", we find the upper bound of all
4236 symbols that start with "func" by looking for where we'd insert
4237 the closest string that would follow "func" in lexicographical
4238 order. Usually, that's "func"-with-last-character-incremented,
4239 i.e. "fund". Mind non-ASCII characters, though. Usually those
4240 will be UTF-8 multi-byte sequences, but we can't be certain.
4241 Especially mind the 0xff character, which is a valid character in
4242 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4243 rule out compilers allowing it in identifiers. Note that
4244 conveniently, strcmp/strcasecmp are specified to compare
4245 characters interpreted as unsigned char. So what we do is treat
4246 the whole string as a base 256 number composed of a sequence of
4247 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4248 to 0, and carries 1 to the following more-significant position.
4249 If the very first character in SEARCH_NAME ends up incremented
4250 and carries/overflows, then the upper bound is the end of the
4251 list. The string after the empty string is also the empty
4254 Some examples of this operation:
4256 SEARCH_NAME => "+1" RESULT
4260 "\xff" "a" "\xff" => "\xff" "b"
4265 Then, with these symbols for example:
4271 completing "func" looks for symbols between "func" and
4272 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4273 which finds "func" and "func1", but not "fund".
4277 funcÿ (Latin1 'ÿ' [0xff])
4281 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4282 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4286 ÿÿ (Latin1 'ÿ' [0xff])
4289 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4290 the end of the list.
4292 std::string after
= search_name
;
4293 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4295 if (!after
.empty ())
4296 after
.back () = (unsigned char) after
.back () + 1;
4300 /* See declaration. */
4302 std::pair
<std::vector
<name_component
>::const_iterator
,
4303 std::vector
<name_component
>::const_iterator
>
4304 mapped_index_base::find_name_components_bounds
4305 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4308 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4310 const char *lang_name
4311 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4313 /* Comparison function object for lower_bound that matches against a
4314 given symbol name. */
4315 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4318 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4319 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4320 return name_cmp (elem_name
, name
) < 0;
4323 /* Comparison function object for upper_bound that matches against a
4324 given symbol name. */
4325 auto lookup_compare_upper
= [&] (const char *name
,
4326 const name_component
&elem
)
4328 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4329 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4330 return name_cmp (name
, elem_name
) < 0;
4333 auto begin
= this->name_components
.begin ();
4334 auto end
= this->name_components
.end ();
4336 /* Find the lower bound. */
4339 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4342 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4345 /* Find the upper bound. */
4348 if (lookup_name_without_params
.completion_mode ())
4350 /* In completion mode, we want UPPER to point past all
4351 symbols names that have the same prefix. I.e., with
4352 these symbols, and completing "func":
4354 function << lower bound
4356 other_function << upper bound
4358 We find the upper bound by looking for the insertion
4359 point of "func"-with-last-character-incremented,
4361 std::string after
= make_sort_after_prefix_name (lang_name
);
4364 return std::lower_bound (lower
, end
, after
.c_str (),
4365 lookup_compare_lower
);
4368 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4371 return {lower
, upper
};
4374 /* See declaration. */
4377 mapped_index_base::build_name_components ()
4379 if (!this->name_components
.empty ())
4382 this->name_components_casing
= case_sensitivity
;
4384 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4386 /* The code below only knows how to break apart components of C++
4387 symbol names (and other languages that use '::' as
4388 namespace/module separator) and Ada symbol names. */
4389 auto count
= this->symbol_name_count ();
4390 for (offset_type idx
= 0; idx
< count
; idx
++)
4392 if (this->symbol_name_slot_invalid (idx
))
4395 const char *name
= this->symbol_name_at (idx
);
4397 /* Add each name component to the name component table. */
4398 unsigned int previous_len
= 0;
4400 if (strstr (name
, "::") != nullptr)
4402 for (unsigned int current_len
= cp_find_first_component (name
);
4403 name
[current_len
] != '\0';
4404 current_len
+= cp_find_first_component (name
+ current_len
))
4406 gdb_assert (name
[current_len
] == ':');
4407 this->name_components
.push_back ({previous_len
, idx
});
4408 /* Skip the '::'. */
4410 previous_len
= current_len
;
4415 /* Handle the Ada encoded (aka mangled) form here. */
4416 for (const char *iter
= strstr (name
, "__");
4418 iter
= strstr (iter
, "__"))
4420 this->name_components
.push_back ({previous_len
, idx
});
4422 previous_len
= iter
- name
;
4426 this->name_components
.push_back ({previous_len
, idx
});
4429 /* Sort name_components elements by name. */
4430 auto name_comp_compare
= [&] (const name_component
&left
,
4431 const name_component
&right
)
4433 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4434 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4436 const char *left_name
= left_qualified
+ left
.name_offset
;
4437 const char *right_name
= right_qualified
+ right
.name_offset
;
4439 return name_cmp (left_name
, right_name
) < 0;
4442 std::sort (this->name_components
.begin (),
4443 this->name_components
.end (),
4447 /* Helper for dw2_expand_symtabs_matching that works with a
4448 mapped_index_base instead of the containing objfile. This is split
4449 to a separate function in order to be able to unit test the
4450 name_components matching using a mock mapped_index_base. For each
4451 symbol name that matches, calls MATCH_CALLBACK, passing it the
4452 symbol's index in the mapped_index_base symbol table. */
4455 dw2_expand_symtabs_matching_symbol
4456 (mapped_index_base
&index
,
4457 const lookup_name_info
&lookup_name_in
,
4458 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4459 enum search_domain kind
,
4460 gdb::function_view
<bool (offset_type
)> match_callback
)
4462 lookup_name_info lookup_name_without_params
4463 = lookup_name_in
.make_ignore_params ();
4465 /* Build the symbol name component sorted vector, if we haven't
4467 index
.build_name_components ();
4469 /* The same symbol may appear more than once in the range though.
4470 E.g., if we're looking for symbols that complete "w", and we have
4471 a symbol named "w1::w2", we'll find the two name components for
4472 that same symbol in the range. To be sure we only call the
4473 callback once per symbol, we first collect the symbol name
4474 indexes that matched in a temporary vector and ignore
4476 std::vector
<offset_type
> matches
;
4478 struct name_and_matcher
4480 symbol_name_matcher_ftype
*matcher
;
4481 const std::string
&name
;
4483 bool operator== (const name_and_matcher
&other
) const
4485 return matcher
== other
.matcher
&& name
== other
.name
;
4489 /* A vector holding all the different symbol name matchers, for all
4491 std::vector
<name_and_matcher
> matchers
;
4493 for (int i
= 0; i
< nr_languages
; i
++)
4495 enum language lang_e
= (enum language
) i
;
4497 const language_defn
*lang
= language_def (lang_e
);
4498 symbol_name_matcher_ftype
*name_matcher
4499 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4501 name_and_matcher key
{
4503 lookup_name_without_params
.language_lookup_name (lang_e
)
4506 /* Don't insert the same comparison routine more than once.
4507 Note that we do this linear walk. This is not a problem in
4508 practice because the number of supported languages is
4510 if (std::find (matchers
.begin (), matchers
.end (), key
)
4513 matchers
.push_back (std::move (key
));
4516 = index
.find_name_components_bounds (lookup_name_without_params
,
4519 /* Now for each symbol name in range, check to see if we have a name
4520 match, and if so, call the MATCH_CALLBACK callback. */
4522 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4524 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4526 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4527 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4530 matches
.push_back (bounds
.first
->idx
);
4534 std::sort (matches
.begin (), matches
.end ());
4536 /* Finally call the callback, once per match. */
4538 for (offset_type idx
: matches
)
4542 if (!match_callback (idx
))
4548 /* Above we use a type wider than idx's for 'prev', since 0 and
4549 (offset_type)-1 are both possible values. */
4550 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4555 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4557 /* A mock .gdb_index/.debug_names-like name index table, enough to
4558 exercise dw2_expand_symtabs_matching_symbol, which works with the
4559 mapped_index_base interface. Builds an index from the symbol list
4560 passed as parameter to the constructor. */
4561 class mock_mapped_index
: public mapped_index_base
4564 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4565 : m_symbol_table (symbols
)
4568 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4570 /* Return the number of names in the symbol table. */
4571 size_t symbol_name_count () const override
4573 return m_symbol_table
.size ();
4576 /* Get the name of the symbol at IDX in the symbol table. */
4577 const char *symbol_name_at (offset_type idx
) const override
4579 return m_symbol_table
[idx
];
4583 gdb::array_view
<const char *> m_symbol_table
;
4586 /* Convenience function that converts a NULL pointer to a "<null>"
4587 string, to pass to print routines. */
4590 string_or_null (const char *str
)
4592 return str
!= NULL
? str
: "<null>";
4595 /* Check if a lookup_name_info built from
4596 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4597 index. EXPECTED_LIST is the list of expected matches, in expected
4598 matching order. If no match expected, then an empty list is
4599 specified. Returns true on success. On failure prints a warning
4600 indicating the file:line that failed, and returns false. */
4603 check_match (const char *file
, int line
,
4604 mock_mapped_index
&mock_index
,
4605 const char *name
, symbol_name_match_type match_type
,
4606 bool completion_mode
,
4607 std::initializer_list
<const char *> expected_list
)
4609 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4611 bool matched
= true;
4613 auto mismatch
= [&] (const char *expected_str
,
4616 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4617 "expected=\"%s\", got=\"%s\"\n"),
4619 (match_type
== symbol_name_match_type::FULL
4621 name
, string_or_null (expected_str
), string_or_null (got
));
4625 auto expected_it
= expected_list
.begin ();
4626 auto expected_end
= expected_list
.end ();
4628 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4630 [&] (offset_type idx
)
4632 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4633 const char *expected_str
4634 = expected_it
== expected_end
? NULL
: *expected_it
++;
4636 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4637 mismatch (expected_str
, matched_name
);
4641 const char *expected_str
4642 = expected_it
== expected_end
? NULL
: *expected_it
++;
4643 if (expected_str
!= NULL
)
4644 mismatch (expected_str
, NULL
);
4649 /* The symbols added to the mock mapped_index for testing (in
4651 static const char *test_symbols
[] = {
4660 "ns2::tmpl<int>::foo2",
4661 "(anonymous namespace)::A::B::C",
4663 /* These are used to check that the increment-last-char in the
4664 matching algorithm for completion doesn't match "t1_fund" when
4665 completing "t1_func". */
4671 /* A UTF-8 name with multi-byte sequences to make sure that
4672 cp-name-parser understands this as a single identifier ("função"
4673 is "function" in PT). */
4676 /* \377 (0xff) is Latin1 'ÿ'. */
4679 /* \377 (0xff) is Latin1 'ÿ'. */
4683 /* A name with all sorts of complications. Starts with "z" to make
4684 it easier for the completion tests below. */
4685 #define Z_SYM_NAME \
4686 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4687 "::tuple<(anonymous namespace)::ui*, " \
4688 "std::default_delete<(anonymous namespace)::ui>, void>"
4693 /* Returns true if the mapped_index_base::find_name_component_bounds
4694 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4695 in completion mode. */
4698 check_find_bounds_finds (mapped_index_base
&index
,
4699 const char *search_name
,
4700 gdb::array_view
<const char *> expected_syms
)
4702 lookup_name_info
lookup_name (search_name
,
4703 symbol_name_match_type::FULL
, true);
4705 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4708 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4709 if (distance
!= expected_syms
.size ())
4712 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4714 auto nc_elem
= bounds
.first
+ exp_elem
;
4715 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4716 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4723 /* Test the lower-level mapped_index::find_name_component_bounds
4727 test_mapped_index_find_name_component_bounds ()
4729 mock_mapped_index
mock_index (test_symbols
);
4731 mock_index
.build_name_components ();
4733 /* Test the lower-level mapped_index::find_name_component_bounds
4734 method in completion mode. */
4736 static const char *expected_syms
[] = {
4741 SELF_CHECK (check_find_bounds_finds (mock_index
,
4742 "t1_func", expected_syms
));
4745 /* Check that the increment-last-char in the name matching algorithm
4746 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4748 static const char *expected_syms1
[] = {
4752 SELF_CHECK (check_find_bounds_finds (mock_index
,
4753 "\377", expected_syms1
));
4755 static const char *expected_syms2
[] = {
4758 SELF_CHECK (check_find_bounds_finds (mock_index
,
4759 "\377\377", expected_syms2
));
4763 /* Test dw2_expand_symtabs_matching_symbol. */
4766 test_dw2_expand_symtabs_matching_symbol ()
4768 mock_mapped_index
mock_index (test_symbols
);
4770 /* We let all tests run until the end even if some fails, for debug
4772 bool any_mismatch
= false;
4774 /* Create the expected symbols list (an initializer_list). Needed
4775 because lists have commas, and we need to pass them to CHECK,
4776 which is a macro. */
4777 #define EXPECT(...) { __VA_ARGS__ }
4779 /* Wrapper for check_match that passes down the current
4780 __FILE__/__LINE__. */
4781 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4782 any_mismatch |= !check_match (__FILE__, __LINE__, \
4784 NAME, MATCH_TYPE, COMPLETION_MODE, \
4787 /* Identity checks. */
4788 for (const char *sym
: test_symbols
)
4790 /* Should be able to match all existing symbols. */
4791 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4794 /* Should be able to match all existing symbols with
4796 std::string with_params
= std::string (sym
) + "(int)";
4797 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4800 /* Should be able to match all existing symbols with
4801 parameters and qualifiers. */
4802 with_params
= std::string (sym
) + " ( int ) const";
4803 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4806 /* This should really find sym, but cp-name-parser.y doesn't
4807 know about lvalue/rvalue qualifiers yet. */
4808 with_params
= std::string (sym
) + " ( int ) &&";
4809 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4813 /* Check that the name matching algorithm for completion doesn't get
4814 confused with Latin1 'ÿ' / 0xff. */
4816 static const char str
[] = "\377";
4817 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4818 EXPECT ("\377", "\377\377123"));
4821 /* Check that the increment-last-char in the matching algorithm for
4822 completion doesn't match "t1_fund" when completing "t1_func". */
4824 static const char str
[] = "t1_func";
4825 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4826 EXPECT ("t1_func", "t1_func1"));
4829 /* Check that completion mode works at each prefix of the expected
4832 static const char str
[] = "function(int)";
4833 size_t len
= strlen (str
);
4836 for (size_t i
= 1; i
< len
; i
++)
4838 lookup
.assign (str
, i
);
4839 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4840 EXPECT ("function"));
4844 /* While "w" is a prefix of both components, the match function
4845 should still only be called once. */
4847 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4849 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4853 /* Same, with a "complicated" symbol. */
4855 static const char str
[] = Z_SYM_NAME
;
4856 size_t len
= strlen (str
);
4859 for (size_t i
= 1; i
< len
; i
++)
4861 lookup
.assign (str
, i
);
4862 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4863 EXPECT (Z_SYM_NAME
));
4867 /* In FULL mode, an incomplete symbol doesn't match. */
4869 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4873 /* A complete symbol with parameters matches any overload, since the
4874 index has no overload info. */
4876 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4877 EXPECT ("std::zfunction", "std::zfunction2"));
4878 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4879 EXPECT ("std::zfunction", "std::zfunction2"));
4880 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4881 EXPECT ("std::zfunction", "std::zfunction2"));
4884 /* Check that whitespace is ignored appropriately. A symbol with a
4885 template argument list. */
4887 static const char expected
[] = "ns::foo<int>";
4888 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4890 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4894 /* Check that whitespace is ignored appropriately. A symbol with a
4895 template argument list that includes a pointer. */
4897 static const char expected
[] = "ns::foo<char*>";
4898 /* Try both completion and non-completion modes. */
4899 static const bool completion_mode
[2] = {false, true};
4900 for (size_t i
= 0; i
< 2; i
++)
4902 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4903 completion_mode
[i
], EXPECT (expected
));
4904 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4905 completion_mode
[i
], EXPECT (expected
));
4907 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4908 completion_mode
[i
], EXPECT (expected
));
4909 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4910 completion_mode
[i
], EXPECT (expected
));
4915 /* Check method qualifiers are ignored. */
4916 static const char expected
[] = "ns::foo<char*>";
4917 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4918 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4919 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4920 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4921 CHECK_MATCH ("foo < char * > ( int ) const",
4922 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4923 CHECK_MATCH ("foo < char * > ( int ) &&",
4924 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4927 /* Test lookup names that don't match anything. */
4929 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4932 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4936 /* Some wild matching tests, exercising "(anonymous namespace)",
4937 which should not be confused with a parameter list. */
4939 static const char *syms
[] = {
4943 "A :: B :: C ( int )",
4948 for (const char *s
: syms
)
4950 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4951 EXPECT ("(anonymous namespace)::A::B::C"));
4956 static const char expected
[] = "ns2::tmpl<int>::foo2";
4957 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4959 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4963 SELF_CHECK (!any_mismatch
);
4972 test_mapped_index_find_name_component_bounds ();
4973 test_dw2_expand_symtabs_matching_symbol ();
4976 }} // namespace selftests::dw2_expand_symtabs_matching
4978 #endif /* GDB_SELF_TEST */
4980 /* If FILE_MATCHER is NULL or if PER_CU has
4981 dwarf2_per_cu_quick_data::MARK set (see
4982 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4983 EXPANSION_NOTIFY on it. */
4986 dw2_expand_symtabs_matching_one
4987 (struct dwarf2_per_cu_data
*per_cu
,
4988 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4989 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4991 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4993 bool symtab_was_null
4994 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4996 dw2_instantiate_symtab (per_cu
, false);
4998 if (expansion_notify
!= NULL
5000 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5001 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5005 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5006 matched, to expand corresponding CUs that were marked. IDX is the
5007 index of the symbol name that matched. */
5010 dw2_expand_marked_cus
5011 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5012 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5013 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5016 offset_type
*vec
, vec_len
, vec_idx
;
5017 bool global_seen
= false;
5018 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5020 vec
= (offset_type
*) (index
.constant_pool
5021 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5022 vec_len
= MAYBE_SWAP (vec
[0]);
5023 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5025 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5026 /* This value is only valid for index versions >= 7. */
5027 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5028 gdb_index_symbol_kind symbol_kind
=
5029 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5030 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5031 /* Only check the symbol attributes if they're present.
5032 Indices prior to version 7 don't record them,
5033 and indices >= 7 may elide them for certain symbols
5034 (gold does this). */
5037 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5039 /* Work around gold/15646. */
5042 if (!is_static
&& global_seen
)
5048 /* Only check the symbol's kind if it has one. */
5053 case VARIABLES_DOMAIN
:
5054 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5057 case FUNCTIONS_DOMAIN
:
5058 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5062 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5065 case MODULES_DOMAIN
:
5066 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
5074 /* Don't crash on bad data. */
5075 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5076 + dwarf2_per_objfile
->all_type_units
.size ()))
5078 complaint (_(".gdb_index entry has bad CU index"
5080 objfile_name (dwarf2_per_objfile
->objfile
));
5084 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5085 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5090 /* If FILE_MATCHER is non-NULL, set all the
5091 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5092 that match FILE_MATCHER. */
5095 dw_expand_symtabs_matching_file_matcher
5096 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5097 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5099 if (file_matcher
== NULL
)
5102 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5104 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5106 NULL
, xcalloc
, xfree
));
5107 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5109 NULL
, xcalloc
, xfree
));
5111 /* The rule is CUs specify all the files, including those used by
5112 any TU, so there's no need to scan TUs here. */
5114 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5118 per_cu
->v
.quick
->mark
= 0;
5120 /* We only need to look at symtabs not already expanded. */
5121 if (per_cu
->v
.quick
->compunit_symtab
)
5124 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5125 if (file_data
== NULL
)
5128 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5130 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5132 per_cu
->v
.quick
->mark
= 1;
5136 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5138 const char *this_real_name
;
5140 if (file_matcher (file_data
->file_names
[j
], false))
5142 per_cu
->v
.quick
->mark
= 1;
5146 /* Before we invoke realpath, which can get expensive when many
5147 files are involved, do a quick comparison of the basenames. */
5148 if (!basenames_may_differ
5149 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5153 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5154 if (file_matcher (this_real_name
, false))
5156 per_cu
->v
.quick
->mark
= 1;
5161 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5162 ? visited_found
.get ()
5163 : visited_not_found
.get (),
5170 dw2_expand_symtabs_matching
5171 (struct objfile
*objfile
,
5172 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5173 const lookup_name_info
&lookup_name
,
5174 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5175 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5176 enum search_domain kind
)
5178 struct dwarf2_per_objfile
*dwarf2_per_objfile
5179 = get_dwarf2_per_objfile (objfile
);
5181 /* index_table is NULL if OBJF_READNOW. */
5182 if (!dwarf2_per_objfile
->index_table
)
5185 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5187 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5189 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5191 kind
, [&] (offset_type idx
)
5193 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5194 expansion_notify
, kind
);
5199 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5202 static struct compunit_symtab
*
5203 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5208 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5209 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5212 if (cust
->includes
== NULL
)
5215 for (i
= 0; cust
->includes
[i
]; ++i
)
5217 struct compunit_symtab
*s
= cust
->includes
[i
];
5219 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5227 static struct compunit_symtab
*
5228 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5229 struct bound_minimal_symbol msymbol
,
5231 struct obj_section
*section
,
5234 struct dwarf2_per_cu_data
*data
;
5235 struct compunit_symtab
*result
;
5237 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5240 CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
5241 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5242 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5246 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5247 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5248 paddress (get_objfile_arch (objfile
), pc
));
5251 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5254 gdb_assert (result
!= NULL
);
5259 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5260 void *data
, int need_fullname
)
5262 struct dwarf2_per_objfile
*dwarf2_per_objfile
5263 = get_dwarf2_per_objfile (objfile
);
5265 if (!dwarf2_per_objfile
->filenames_cache
)
5267 dwarf2_per_objfile
->filenames_cache
.emplace ();
5269 htab_up
visited (htab_create_alloc (10,
5270 htab_hash_pointer
, htab_eq_pointer
,
5271 NULL
, xcalloc
, xfree
));
5273 /* The rule is CUs specify all the files, including those used
5274 by any TU, so there's no need to scan TUs here. We can
5275 ignore file names coming from already-expanded CUs. */
5277 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5279 if (per_cu
->v
.quick
->compunit_symtab
)
5281 void **slot
= htab_find_slot (visited
.get (),
5282 per_cu
->v
.quick
->file_names
,
5285 *slot
= per_cu
->v
.quick
->file_names
;
5289 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5291 /* We only need to look at symtabs not already expanded. */
5292 if (per_cu
->v
.quick
->compunit_symtab
)
5295 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5296 if (file_data
== NULL
)
5299 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5302 /* Already visited. */
5307 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5309 const char *filename
= file_data
->file_names
[j
];
5310 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5315 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5317 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5320 this_real_name
= gdb_realpath (filename
);
5321 (*fun
) (filename
, this_real_name
.get (), data
);
5326 dw2_has_symbols (struct objfile
*objfile
)
5331 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5334 dw2_find_last_source_symtab
,
5335 dw2_forget_cached_source_info
,
5336 dw2_map_symtabs_matching_filename
,
5340 dw2_expand_symtabs_for_function
,
5341 dw2_expand_all_symtabs
,
5342 dw2_expand_symtabs_with_fullname
,
5343 dw2_map_matching_symbols
,
5344 dw2_expand_symtabs_matching
,
5345 dw2_find_pc_sect_compunit_symtab
,
5347 dw2_map_symbol_filenames
5350 /* DWARF-5 debug_names reader. */
5352 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5353 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5355 /* A helper function that reads the .debug_names section in SECTION
5356 and fills in MAP. FILENAME is the name of the file containing the
5357 section; it is used for error reporting.
5359 Returns true if all went well, false otherwise. */
5362 read_debug_names_from_section (struct objfile
*objfile
,
5363 const char *filename
,
5364 struct dwarf2_section_info
*section
,
5365 mapped_debug_names
&map
)
5367 if (dwarf2_section_empty_p (section
))
5370 /* Older elfutils strip versions could keep the section in the main
5371 executable while splitting it for the separate debug info file. */
5372 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5375 dwarf2_read_section (objfile
, section
);
5377 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5379 const gdb_byte
*addr
= section
->buffer
;
5381 bfd
*const abfd
= get_section_bfd_owner (section
);
5383 unsigned int bytes_read
;
5384 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5387 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5388 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5389 if (bytes_read
+ length
!= section
->size
)
5391 /* There may be multiple per-CU indices. */
5392 warning (_("Section .debug_names in %s length %s does not match "
5393 "section length %s, ignoring .debug_names."),
5394 filename
, plongest (bytes_read
+ length
),
5395 pulongest (section
->size
));
5399 /* The version number. */
5400 uint16_t version
= read_2_bytes (abfd
, addr
);
5404 warning (_("Section .debug_names in %s has unsupported version %d, "
5405 "ignoring .debug_names."),
5411 uint16_t padding
= read_2_bytes (abfd
, addr
);
5415 warning (_("Section .debug_names in %s has unsupported padding %d, "
5416 "ignoring .debug_names."),
5421 /* comp_unit_count - The number of CUs in the CU list. */
5422 map
.cu_count
= read_4_bytes (abfd
, addr
);
5425 /* local_type_unit_count - The number of TUs in the local TU
5427 map
.tu_count
= read_4_bytes (abfd
, addr
);
5430 /* foreign_type_unit_count - The number of TUs in the foreign TU
5432 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5434 if (foreign_tu_count
!= 0)
5436 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5437 "ignoring .debug_names."),
5438 filename
, static_cast<unsigned long> (foreign_tu_count
));
5442 /* bucket_count - The number of hash buckets in the hash lookup
5444 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5447 /* name_count - The number of unique names in the index. */
5448 map
.name_count
= read_4_bytes (abfd
, addr
);
5451 /* abbrev_table_size - The size in bytes of the abbreviations
5453 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5456 /* augmentation_string_size - The size in bytes of the augmentation
5457 string. This value is rounded up to a multiple of 4. */
5458 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5460 map
.augmentation_is_gdb
= ((augmentation_string_size
5461 == sizeof (dwarf5_augmentation
))
5462 && memcmp (addr
, dwarf5_augmentation
,
5463 sizeof (dwarf5_augmentation
)) == 0);
5464 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5465 addr
+= augmentation_string_size
;
5468 map
.cu_table_reordered
= addr
;
5469 addr
+= map
.cu_count
* map
.offset_size
;
5471 /* List of Local TUs */
5472 map
.tu_table_reordered
= addr
;
5473 addr
+= map
.tu_count
* map
.offset_size
;
5475 /* Hash Lookup Table */
5476 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5477 addr
+= map
.bucket_count
* 4;
5478 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5479 addr
+= map
.name_count
* 4;
5482 map
.name_table_string_offs_reordered
= addr
;
5483 addr
+= map
.name_count
* map
.offset_size
;
5484 map
.name_table_entry_offs_reordered
= addr
;
5485 addr
+= map
.name_count
* map
.offset_size
;
5487 const gdb_byte
*abbrev_table_start
= addr
;
5490 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5495 const auto insertpair
5496 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5497 if (!insertpair
.second
)
5499 warning (_("Section .debug_names in %s has duplicate index %s, "
5500 "ignoring .debug_names."),
5501 filename
, pulongest (index_num
));
5504 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5505 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5510 mapped_debug_names::index_val::attr attr
;
5511 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5513 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5515 if (attr
.form
== DW_FORM_implicit_const
)
5517 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5521 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5523 indexval
.attr_vec
.push_back (std::move (attr
));
5526 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5528 warning (_("Section .debug_names in %s has abbreviation_table "
5529 "of size %s vs. written as %u, ignoring .debug_names."),
5530 filename
, plongest (addr
- abbrev_table_start
),
5534 map
.entry_pool
= addr
;
5539 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5543 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5544 const mapped_debug_names
&map
,
5545 dwarf2_section_info
§ion
,
5548 sect_offset sect_off_prev
;
5549 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5551 sect_offset sect_off_next
;
5552 if (i
< map
.cu_count
)
5555 = (sect_offset
) (extract_unsigned_integer
5556 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5558 map
.dwarf5_byte_order
));
5561 sect_off_next
= (sect_offset
) section
.size
;
5564 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5565 dwarf2_per_cu_data
*per_cu
5566 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5567 sect_off_prev
, length
);
5568 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5570 sect_off_prev
= sect_off_next
;
5574 /* Read the CU list from the mapped index, and use it to create all
5575 the CU objects for this dwarf2_per_objfile. */
5578 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5579 const mapped_debug_names
&map
,
5580 const mapped_debug_names
&dwz_map
)
5582 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5583 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5585 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5586 dwarf2_per_objfile
->info
,
5587 false /* is_dwz */);
5589 if (dwz_map
.cu_count
== 0)
5592 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5593 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5597 /* Read .debug_names. If everything went ok, initialize the "quick"
5598 elements of all the CUs and return true. Otherwise, return false. */
5601 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5603 std::unique_ptr
<mapped_debug_names
> map
5604 (new mapped_debug_names (dwarf2_per_objfile
));
5605 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5606 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5608 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5609 &dwarf2_per_objfile
->debug_names
,
5613 /* Don't use the index if it's empty. */
5614 if (map
->name_count
== 0)
5617 /* If there is a .dwz file, read it so we can get its CU list as
5619 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5622 if (!read_debug_names_from_section (objfile
,
5623 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5624 &dwz
->debug_names
, dwz_map
))
5626 warning (_("could not read '.debug_names' section from %s; skipping"),
5627 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5632 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5634 if (map
->tu_count
!= 0)
5636 /* We can only handle a single .debug_types when we have an
5638 if (dwarf2_per_objfile
->types
.size () != 1)
5641 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5643 create_signatured_type_table_from_debug_names
5644 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5647 create_addrmap_from_aranges (dwarf2_per_objfile
,
5648 &dwarf2_per_objfile
->debug_aranges
);
5650 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5651 dwarf2_per_objfile
->using_index
= 1;
5652 dwarf2_per_objfile
->quick_file_names_table
=
5653 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5658 /* Type used to manage iterating over all CUs looking for a symbol for
5661 class dw2_debug_names_iterator
5664 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5665 gdb::optional
<block_enum
> block_index
,
5668 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5669 m_addr (find_vec_in_debug_names (map
, name
))
5672 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5673 search_domain search
, uint32_t namei
)
5676 m_addr (find_vec_in_debug_names (map
, namei
))
5679 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5680 block_enum block_index
, domain_enum domain
,
5682 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5683 m_addr (find_vec_in_debug_names (map
, namei
))
5686 /* Return the next matching CU or NULL if there are no more. */
5687 dwarf2_per_cu_data
*next ();
5690 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5692 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5695 /* The internalized form of .debug_names. */
5696 const mapped_debug_names
&m_map
;
5698 /* If set, only look for symbols that match that block. Valid values are
5699 GLOBAL_BLOCK and STATIC_BLOCK. */
5700 const gdb::optional
<block_enum
> m_block_index
;
5702 /* The kind of symbol we're looking for. */
5703 const domain_enum m_domain
= UNDEF_DOMAIN
;
5704 const search_domain m_search
= ALL_DOMAIN
;
5706 /* The list of CUs from the index entry of the symbol, or NULL if
5708 const gdb_byte
*m_addr
;
5712 mapped_debug_names::namei_to_name (uint32_t namei
) const
5714 const ULONGEST namei_string_offs
5715 = extract_unsigned_integer ((name_table_string_offs_reordered
5716 + namei
* offset_size
),
5719 return read_indirect_string_at_offset
5720 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5723 /* Find a slot in .debug_names for the object named NAME. If NAME is
5724 found, return pointer to its pool data. If NAME cannot be found,
5728 dw2_debug_names_iterator::find_vec_in_debug_names
5729 (const mapped_debug_names
&map
, const char *name
)
5731 int (*cmp
) (const char *, const char *);
5733 gdb::unique_xmalloc_ptr
<char> without_params
;
5734 if (current_language
->la_language
== language_cplus
5735 || current_language
->la_language
== language_fortran
5736 || current_language
->la_language
== language_d
)
5738 /* NAME is already canonical. Drop any qualifiers as
5739 .debug_names does not contain any. */
5741 if (strchr (name
, '(') != NULL
)
5743 without_params
= cp_remove_params (name
);
5744 if (without_params
!= NULL
)
5745 name
= without_params
.get ();
5749 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5751 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5753 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5754 (map
.bucket_table_reordered
5755 + (full_hash
% map
.bucket_count
)), 4,
5756 map
.dwarf5_byte_order
);
5760 if (namei
>= map
.name_count
)
5762 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5764 namei
, map
.name_count
,
5765 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5771 const uint32_t namei_full_hash
5772 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5773 (map
.hash_table_reordered
+ namei
), 4,
5774 map
.dwarf5_byte_order
);
5775 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5778 if (full_hash
== namei_full_hash
)
5780 const char *const namei_string
= map
.namei_to_name (namei
);
5782 #if 0 /* An expensive sanity check. */
5783 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5785 complaint (_("Wrong .debug_names hash for string at index %u "
5787 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5792 if (cmp (namei_string
, name
) == 0)
5794 const ULONGEST namei_entry_offs
5795 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5796 + namei
* map
.offset_size
),
5797 map
.offset_size
, map
.dwarf5_byte_order
);
5798 return map
.entry_pool
+ namei_entry_offs
;
5803 if (namei
>= map
.name_count
)
5809 dw2_debug_names_iterator::find_vec_in_debug_names
5810 (const mapped_debug_names
&map
, uint32_t namei
)
5812 if (namei
>= map
.name_count
)
5814 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5816 namei
, map
.name_count
,
5817 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5821 const ULONGEST namei_entry_offs
5822 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5823 + namei
* map
.offset_size
),
5824 map
.offset_size
, map
.dwarf5_byte_order
);
5825 return map
.entry_pool
+ namei_entry_offs
;
5828 /* See dw2_debug_names_iterator. */
5830 dwarf2_per_cu_data
*
5831 dw2_debug_names_iterator::next ()
5836 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5837 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5838 bfd
*const abfd
= objfile
->obfd
;
5842 unsigned int bytes_read
;
5843 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5844 m_addr
+= bytes_read
;
5848 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5849 if (indexval_it
== m_map
.abbrev_map
.cend ())
5851 complaint (_("Wrong .debug_names undefined abbrev code %s "
5853 pulongest (abbrev
), objfile_name (objfile
));
5856 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5857 enum class symbol_linkage
{
5861 } symbol_linkage_
= symbol_linkage::unknown
;
5862 dwarf2_per_cu_data
*per_cu
= NULL
;
5863 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5868 case DW_FORM_implicit_const
:
5869 ull
= attr
.implicit_const
;
5871 case DW_FORM_flag_present
:
5875 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5876 m_addr
+= bytes_read
;
5879 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5880 dwarf_form_name (attr
.form
),
5881 objfile_name (objfile
));
5884 switch (attr
.dw_idx
)
5886 case DW_IDX_compile_unit
:
5887 /* Don't crash on bad data. */
5888 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5890 complaint (_(".debug_names entry has bad CU index %s"
5893 objfile_name (dwarf2_per_objfile
->objfile
));
5896 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5898 case DW_IDX_type_unit
:
5899 /* Don't crash on bad data. */
5900 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5902 complaint (_(".debug_names entry has bad TU index %s"
5905 objfile_name (dwarf2_per_objfile
->objfile
));
5908 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5910 case DW_IDX_GNU_internal
:
5911 if (!m_map
.augmentation_is_gdb
)
5913 symbol_linkage_
= symbol_linkage::static_
;
5915 case DW_IDX_GNU_external
:
5916 if (!m_map
.augmentation_is_gdb
)
5918 symbol_linkage_
= symbol_linkage::extern_
;
5923 /* Skip if already read in. */
5924 if (per_cu
->v
.quick
->compunit_symtab
)
5927 /* Check static vs global. */
5928 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5930 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5931 const bool symbol_is_static
=
5932 symbol_linkage_
== symbol_linkage::static_
;
5933 if (want_static
!= symbol_is_static
)
5937 /* Match dw2_symtab_iter_next, symbol_kind
5938 and debug_names::psymbol_tag. */
5942 switch (indexval
.dwarf_tag
)
5944 case DW_TAG_variable
:
5945 case DW_TAG_subprogram
:
5946 /* Some types are also in VAR_DOMAIN. */
5947 case DW_TAG_typedef
:
5948 case DW_TAG_structure_type
:
5955 switch (indexval
.dwarf_tag
)
5957 case DW_TAG_typedef
:
5958 case DW_TAG_structure_type
:
5965 switch (indexval
.dwarf_tag
)
5968 case DW_TAG_variable
:
5975 switch (indexval
.dwarf_tag
)
5987 /* Match dw2_expand_symtabs_matching, symbol_kind and
5988 debug_names::psymbol_tag. */
5991 case VARIABLES_DOMAIN
:
5992 switch (indexval
.dwarf_tag
)
5994 case DW_TAG_variable
:
6000 case FUNCTIONS_DOMAIN
:
6001 switch (indexval
.dwarf_tag
)
6003 case DW_TAG_subprogram
:
6010 switch (indexval
.dwarf_tag
)
6012 case DW_TAG_typedef
:
6013 case DW_TAG_structure_type
:
6019 case MODULES_DOMAIN
:
6020 switch (indexval
.dwarf_tag
)
6034 static struct compunit_symtab
*
6035 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6036 const char *name
, domain_enum domain
)
6038 struct dwarf2_per_objfile
*dwarf2_per_objfile
6039 = get_dwarf2_per_objfile (objfile
);
6041 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6044 /* index is NULL if OBJF_READNOW. */
6047 const auto &map
= *mapp
;
6049 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6051 struct compunit_symtab
*stab_best
= NULL
;
6052 struct dwarf2_per_cu_data
*per_cu
;
6053 while ((per_cu
= iter
.next ()) != NULL
)
6055 struct symbol
*sym
, *with_opaque
= NULL
;
6056 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6057 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6058 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6060 sym
= block_find_symbol (block
, name
, domain
,
6061 block_find_non_opaque_type_preferred
,
6064 /* Some caution must be observed with overloaded functions and
6065 methods, since the index will not contain any overload
6066 information (but NAME might contain it). */
6069 && strcmp_iw (sym
->search_name (), name
) == 0)
6071 if (with_opaque
!= NULL
6072 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
6075 /* Keep looking through other CUs. */
6081 /* This dumps minimal information about .debug_names. It is called
6082 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6083 uses this to verify that .debug_names has been loaded. */
6086 dw2_debug_names_dump (struct objfile
*objfile
)
6088 struct dwarf2_per_objfile
*dwarf2_per_objfile
6089 = get_dwarf2_per_objfile (objfile
);
6091 gdb_assert (dwarf2_per_objfile
->using_index
);
6092 printf_filtered (".debug_names:");
6093 if (dwarf2_per_objfile
->debug_names_table
)
6094 printf_filtered (" exists\n");
6096 printf_filtered (" faked for \"readnow\"\n");
6097 printf_filtered ("\n");
6101 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6102 const char *func_name
)
6104 struct dwarf2_per_objfile
*dwarf2_per_objfile
6105 = get_dwarf2_per_objfile (objfile
);
6107 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6108 if (dwarf2_per_objfile
->debug_names_table
)
6110 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6112 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6114 struct dwarf2_per_cu_data
*per_cu
;
6115 while ((per_cu
= iter
.next ()) != NULL
)
6116 dw2_instantiate_symtab (per_cu
, false);
6121 dw2_debug_names_map_matching_symbols
6122 (struct objfile
*objfile
,
6123 const lookup_name_info
&name
, domain_enum domain
,
6125 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6126 symbol_compare_ftype
*ordered_compare
)
6128 struct dwarf2_per_objfile
*dwarf2_per_objfile
6129 = get_dwarf2_per_objfile (objfile
);
6131 /* debug_names_table is NULL if OBJF_READNOW. */
6132 if (!dwarf2_per_objfile
->debug_names_table
)
6135 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6136 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6138 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6139 auto matcher
= [&] (const char *symname
)
6141 if (ordered_compare
== nullptr)
6143 return ordered_compare (symname
, match_name
) == 0;
6146 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6147 [&] (offset_type namei
)
6149 /* The name was matched, now expand corresponding CUs that were
6151 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6153 struct dwarf2_per_cu_data
*per_cu
;
6154 while ((per_cu
= iter
.next ()) != NULL
)
6155 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6159 /* It's a shame we couldn't do this inside the
6160 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6161 that have already been expanded. Instead, this loop matches what
6162 the psymtab code does. */
6163 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6165 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6166 if (cust
!= nullptr)
6168 const struct block
*block
6169 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6170 if (!iterate_over_symbols_terminated (block
, name
,
6178 dw2_debug_names_expand_symtabs_matching
6179 (struct objfile
*objfile
,
6180 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6181 const lookup_name_info
&lookup_name
,
6182 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6183 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6184 enum search_domain kind
)
6186 struct dwarf2_per_objfile
*dwarf2_per_objfile
6187 = get_dwarf2_per_objfile (objfile
);
6189 /* debug_names_table is NULL if OBJF_READNOW. */
6190 if (!dwarf2_per_objfile
->debug_names_table
)
6193 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6195 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6197 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6199 kind
, [&] (offset_type namei
)
6201 /* The name was matched, now expand corresponding CUs that were
6203 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6205 struct dwarf2_per_cu_data
*per_cu
;
6206 while ((per_cu
= iter
.next ()) != NULL
)
6207 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6213 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6216 dw2_find_last_source_symtab
,
6217 dw2_forget_cached_source_info
,
6218 dw2_map_symtabs_matching_filename
,
6219 dw2_debug_names_lookup_symbol
,
6221 dw2_debug_names_dump
,
6222 dw2_debug_names_expand_symtabs_for_function
,
6223 dw2_expand_all_symtabs
,
6224 dw2_expand_symtabs_with_fullname
,
6225 dw2_debug_names_map_matching_symbols
,
6226 dw2_debug_names_expand_symtabs_matching
,
6227 dw2_find_pc_sect_compunit_symtab
,
6229 dw2_map_symbol_filenames
6232 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6233 to either a dwarf2_per_objfile or dwz_file object. */
6235 template <typename T
>
6236 static gdb::array_view
<const gdb_byte
>
6237 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6239 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6241 if (dwarf2_section_empty_p (section
))
6244 /* Older elfutils strip versions could keep the section in the main
6245 executable while splitting it for the separate debug info file. */
6246 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6249 dwarf2_read_section (obj
, section
);
6251 /* dwarf2_section_info::size is a bfd_size_type, while
6252 gdb::array_view works with size_t. On 32-bit hosts, with
6253 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6254 is 32-bit. So we need an explicit narrowing conversion here.
6255 This is fine, because it's impossible to allocate or mmap an
6256 array/buffer larger than what size_t can represent. */
6257 return gdb::make_array_view (section
->buffer
, section
->size
);
6260 /* Lookup the index cache for the contents of the index associated to
6263 static gdb::array_view
<const gdb_byte
>
6264 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6266 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6267 if (build_id
== nullptr)
6270 return global_index_cache
.lookup_gdb_index (build_id
,
6271 &dwarf2_obj
->index_cache_res
);
6274 /* Same as the above, but for DWZ. */
6276 static gdb::array_view
<const gdb_byte
>
6277 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6279 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6280 if (build_id
== nullptr)
6283 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6286 /* See symfile.h. */
6289 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6291 struct dwarf2_per_objfile
*dwarf2_per_objfile
6292 = get_dwarf2_per_objfile (objfile
);
6294 /* If we're about to read full symbols, don't bother with the
6295 indices. In this case we also don't care if some other debug
6296 format is making psymtabs, because they are all about to be
6298 if ((objfile
->flags
& OBJF_READNOW
))
6300 dwarf2_per_objfile
->using_index
= 1;
6301 create_all_comp_units (dwarf2_per_objfile
);
6302 create_all_type_units (dwarf2_per_objfile
);
6303 dwarf2_per_objfile
->quick_file_names_table
6304 = create_quick_file_names_table
6305 (dwarf2_per_objfile
->all_comp_units
.size ());
6307 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6308 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6310 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6312 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6313 struct dwarf2_per_cu_quick_data
);
6316 /* Return 1 so that gdb sees the "quick" functions. However,
6317 these functions will be no-ops because we will have expanded
6319 *index_kind
= dw_index_kind::GDB_INDEX
;
6323 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6325 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6329 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6330 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6331 get_gdb_index_contents_from_section
<dwz_file
>))
6333 *index_kind
= dw_index_kind::GDB_INDEX
;
6337 /* ... otherwise, try to find the index in the index cache. */
6338 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6339 get_gdb_index_contents_from_cache
,
6340 get_gdb_index_contents_from_cache_dwz
))
6342 global_index_cache
.hit ();
6343 *index_kind
= dw_index_kind::GDB_INDEX
;
6347 global_index_cache
.miss ();
6353 /* Build a partial symbol table. */
6356 dwarf2_build_psymtabs (struct objfile
*objfile
)
6358 struct dwarf2_per_objfile
*dwarf2_per_objfile
6359 = get_dwarf2_per_objfile (objfile
);
6361 init_psymbol_list (objfile
, 1024);
6365 /* This isn't really ideal: all the data we allocate on the
6366 objfile's obstack is still uselessly kept around. However,
6367 freeing it seems unsafe. */
6368 psymtab_discarder
psymtabs (objfile
);
6369 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6372 /* (maybe) store an index in the cache. */
6373 global_index_cache
.store (dwarf2_per_objfile
);
6375 catch (const gdb_exception_error
&except
)
6377 exception_print (gdb_stderr
, except
);
6381 /* Return the total length of the CU described by HEADER. */
6384 get_cu_length (const struct comp_unit_head
*header
)
6386 return header
->initial_length_size
+ header
->length
;
6389 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6392 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6394 sect_offset bottom
= cu_header
->sect_off
;
6395 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6397 return sect_off
>= bottom
&& sect_off
< top
;
6400 /* Find the base address of the compilation unit for range lists and
6401 location lists. It will normally be specified by DW_AT_low_pc.
6402 In DWARF-3 draft 4, the base address could be overridden by
6403 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6404 compilation units with discontinuous ranges. */
6407 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6409 struct attribute
*attr
;
6412 cu
->base_address
= 0;
6414 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6415 if (attr
!= nullptr)
6417 cu
->base_address
= attr_value_as_address (attr
);
6422 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6423 if (attr
!= nullptr)
6425 cu
->base_address
= attr_value_as_address (attr
);
6431 /* Read in the comp unit header information from the debug_info at info_ptr.
6432 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6433 NOTE: This leaves members offset, first_die_offset to be filled in
6436 static const gdb_byte
*
6437 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6438 const gdb_byte
*info_ptr
,
6439 struct dwarf2_section_info
*section
,
6440 rcuh_kind section_kind
)
6443 unsigned int bytes_read
;
6444 const char *filename
= get_section_file_name (section
);
6445 bfd
*abfd
= get_section_bfd_owner (section
);
6447 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6448 cu_header
->initial_length_size
= bytes_read
;
6449 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6450 info_ptr
+= bytes_read
;
6451 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6452 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6453 error (_("Dwarf Error: wrong version in compilation unit header "
6454 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6455 cu_header
->version
, filename
);
6457 if (cu_header
->version
< 5)
6458 switch (section_kind
)
6460 case rcuh_kind::COMPILE
:
6461 cu_header
->unit_type
= DW_UT_compile
;
6463 case rcuh_kind::TYPE
:
6464 cu_header
->unit_type
= DW_UT_type
;
6467 internal_error (__FILE__
, __LINE__
,
6468 _("read_comp_unit_head: invalid section_kind"));
6472 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6473 (read_1_byte (abfd
, info_ptr
));
6475 switch (cu_header
->unit_type
)
6479 case DW_UT_skeleton
:
6480 case DW_UT_split_compile
:
6481 if (section_kind
!= rcuh_kind::COMPILE
)
6482 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6483 "(is %s, should be %s) [in module %s]"),
6484 dwarf_unit_type_name (cu_header
->unit_type
),
6485 dwarf_unit_type_name (DW_UT_type
), filename
);
6488 case DW_UT_split_type
:
6489 section_kind
= rcuh_kind::TYPE
;
6492 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6493 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6494 "[in module %s]"), cu_header
->unit_type
,
6495 dwarf_unit_type_name (DW_UT_compile
),
6496 dwarf_unit_type_name (DW_UT_skeleton
),
6497 dwarf_unit_type_name (DW_UT_split_compile
),
6498 dwarf_unit_type_name (DW_UT_type
),
6499 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6502 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6505 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6508 info_ptr
+= bytes_read
;
6509 if (cu_header
->version
< 5)
6511 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6514 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6515 if (signed_addr
< 0)
6516 internal_error (__FILE__
, __LINE__
,
6517 _("read_comp_unit_head: dwarf from non elf file"));
6518 cu_header
->signed_addr_p
= signed_addr
;
6520 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6521 || cu_header
->unit_type
== DW_UT_skeleton
6522 || cu_header
->unit_type
== DW_UT_split_compile
;
6524 if (header_has_signature
)
6526 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6530 if (section_kind
== rcuh_kind::TYPE
)
6532 LONGEST type_offset
;
6533 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6534 info_ptr
+= bytes_read
;
6535 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6536 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6537 error (_("Dwarf Error: Too big type_offset in compilation unit "
6538 "header (is %s) [in module %s]"), plongest (type_offset
),
6545 /* Helper function that returns the proper abbrev section for
6548 static struct dwarf2_section_info
*
6549 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6551 struct dwarf2_section_info
*abbrev
;
6552 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6554 if (this_cu
->is_dwz
)
6555 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6557 abbrev
= &dwarf2_per_objfile
->abbrev
;
6562 /* Subroutine of read_and_check_comp_unit_head and
6563 read_and_check_type_unit_head to simplify them.
6564 Perform various error checking on the header. */
6567 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6568 struct comp_unit_head
*header
,
6569 struct dwarf2_section_info
*section
,
6570 struct dwarf2_section_info
*abbrev_section
)
6572 const char *filename
= get_section_file_name (section
);
6574 if (to_underlying (header
->abbrev_sect_off
)
6575 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6576 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6577 "(offset %s + 6) [in module %s]"),
6578 sect_offset_str (header
->abbrev_sect_off
),
6579 sect_offset_str (header
->sect_off
),
6582 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6583 avoid potential 32-bit overflow. */
6584 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6586 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6587 "(offset %s + 0) [in module %s]"),
6588 header
->length
, sect_offset_str (header
->sect_off
),
6592 /* Read in a CU/TU header and perform some basic error checking.
6593 The contents of the header are stored in HEADER.
6594 The result is a pointer to the start of the first DIE. */
6596 static const gdb_byte
*
6597 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6598 struct comp_unit_head
*header
,
6599 struct dwarf2_section_info
*section
,
6600 struct dwarf2_section_info
*abbrev_section
,
6601 const gdb_byte
*info_ptr
,
6602 rcuh_kind section_kind
)
6604 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6606 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6608 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6610 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6612 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6618 /* Fetch the abbreviation table offset from a comp or type unit header. */
6621 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6622 struct dwarf2_section_info
*section
,
6623 sect_offset sect_off
)
6625 bfd
*abfd
= get_section_bfd_owner (section
);
6626 const gdb_byte
*info_ptr
;
6627 unsigned int initial_length_size
, offset_size
;
6630 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6631 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6632 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6633 offset_size
= initial_length_size
== 4 ? 4 : 8;
6634 info_ptr
+= initial_length_size
;
6636 version
= read_2_bytes (abfd
, info_ptr
);
6640 /* Skip unit type and address size. */
6644 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6647 /* Allocate a new partial symtab for file named NAME and mark this new
6648 partial symtab as being an include of PST. */
6651 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6652 struct objfile
*objfile
)
6654 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6656 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6658 /* It shares objfile->objfile_obstack. */
6659 subpst
->dirname
= pst
->dirname
;
6662 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6663 subpst
->dependencies
[0] = pst
;
6664 subpst
->number_of_dependencies
= 1;
6666 subpst
->read_symtab
= pst
->read_symtab
;
6668 /* No private part is necessary for include psymtabs. This property
6669 can be used to differentiate between such include psymtabs and
6670 the regular ones. */
6671 subpst
->read_symtab_private
= NULL
;
6674 /* Read the Line Number Program data and extract the list of files
6675 included by the source file represented by PST. Build an include
6676 partial symtab for each of these included files. */
6679 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6680 struct die_info
*die
,
6681 struct partial_symtab
*pst
)
6684 struct attribute
*attr
;
6686 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6687 if (attr
!= nullptr)
6688 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6690 return; /* No linetable, so no includes. */
6692 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6693 that we pass in the raw text_low here; that is ok because we're
6694 only decoding the line table to make include partial symtabs, and
6695 so the addresses aren't really used. */
6696 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6697 pst
->raw_text_low (), 1);
6701 hash_signatured_type (const void *item
)
6703 const struct signatured_type
*sig_type
6704 = (const struct signatured_type
*) item
;
6706 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6707 return sig_type
->signature
;
6711 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6713 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6714 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6716 return lhs
->signature
== rhs
->signature
;
6719 /* Allocate a hash table for signatured types. */
6722 allocate_signatured_type_table (struct objfile
*objfile
)
6724 return htab_create_alloc_ex (41,
6725 hash_signatured_type
,
6728 &objfile
->objfile_obstack
,
6729 hashtab_obstack_allocate
,
6730 dummy_obstack_deallocate
);
6733 /* A helper function to add a signatured type CU to a table. */
6736 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6738 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6739 std::vector
<signatured_type
*> *all_type_units
6740 = (std::vector
<signatured_type
*> *) datum
;
6742 all_type_units
->push_back (sigt
);
6747 /* A helper for create_debug_types_hash_table. Read types from SECTION
6748 and fill them into TYPES_HTAB. It will process only type units,
6749 therefore DW_UT_type. */
6752 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6753 struct dwo_file
*dwo_file
,
6754 dwarf2_section_info
*section
, htab_t
&types_htab
,
6755 rcuh_kind section_kind
)
6757 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6758 struct dwarf2_section_info
*abbrev_section
;
6760 const gdb_byte
*info_ptr
, *end_ptr
;
6762 abbrev_section
= (dwo_file
!= NULL
6763 ? &dwo_file
->sections
.abbrev
6764 : &dwarf2_per_objfile
->abbrev
);
6766 if (dwarf_read_debug
)
6767 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6768 get_section_name (section
),
6769 get_section_file_name (abbrev_section
));
6771 dwarf2_read_section (objfile
, section
);
6772 info_ptr
= section
->buffer
;
6774 if (info_ptr
== NULL
)
6777 /* We can't set abfd until now because the section may be empty or
6778 not present, in which case the bfd is unknown. */
6779 abfd
= get_section_bfd_owner (section
);
6781 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6782 because we don't need to read any dies: the signature is in the
6785 end_ptr
= info_ptr
+ section
->size
;
6786 while (info_ptr
< end_ptr
)
6788 struct signatured_type
*sig_type
;
6789 struct dwo_unit
*dwo_tu
;
6791 const gdb_byte
*ptr
= info_ptr
;
6792 struct comp_unit_head header
;
6793 unsigned int length
;
6795 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6797 /* Initialize it due to a false compiler warning. */
6798 header
.signature
= -1;
6799 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6801 /* We need to read the type's signature in order to build the hash
6802 table, but we don't need anything else just yet. */
6804 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6805 abbrev_section
, ptr
, section_kind
);
6807 length
= get_cu_length (&header
);
6809 /* Skip dummy type units. */
6810 if (ptr
>= info_ptr
+ length
6811 || peek_abbrev_code (abfd
, ptr
) == 0
6812 || header
.unit_type
!= DW_UT_type
)
6818 if (types_htab
== NULL
)
6821 types_htab
= allocate_dwo_unit_table (objfile
);
6823 types_htab
= allocate_signatured_type_table (objfile
);
6829 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6831 dwo_tu
->dwo_file
= dwo_file
;
6832 dwo_tu
->signature
= header
.signature
;
6833 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6834 dwo_tu
->section
= section
;
6835 dwo_tu
->sect_off
= sect_off
;
6836 dwo_tu
->length
= length
;
6840 /* N.B.: type_offset is not usable if this type uses a DWO file.
6841 The real type_offset is in the DWO file. */
6843 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6844 struct signatured_type
);
6845 sig_type
->signature
= header
.signature
;
6846 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6847 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6848 sig_type
->per_cu
.is_debug_types
= 1;
6849 sig_type
->per_cu
.section
= section
;
6850 sig_type
->per_cu
.sect_off
= sect_off
;
6851 sig_type
->per_cu
.length
= length
;
6854 slot
= htab_find_slot (types_htab
,
6855 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6857 gdb_assert (slot
!= NULL
);
6860 sect_offset dup_sect_off
;
6864 const struct dwo_unit
*dup_tu
6865 = (const struct dwo_unit
*) *slot
;
6867 dup_sect_off
= dup_tu
->sect_off
;
6871 const struct signatured_type
*dup_tu
6872 = (const struct signatured_type
*) *slot
;
6874 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6877 complaint (_("debug type entry at offset %s is duplicate to"
6878 " the entry at offset %s, signature %s"),
6879 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6880 hex_string (header
.signature
));
6882 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6884 if (dwarf_read_debug
> 1)
6885 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6886 sect_offset_str (sect_off
),
6887 hex_string (header
.signature
));
6893 /* Create the hash table of all entries in the .debug_types
6894 (or .debug_types.dwo) section(s).
6895 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6896 otherwise it is NULL.
6898 The result is a pointer to the hash table or NULL if there are no types.
6900 Note: This function processes DWO files only, not DWP files. */
6903 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6904 struct dwo_file
*dwo_file
,
6905 gdb::array_view
<dwarf2_section_info
> type_sections
,
6908 for (dwarf2_section_info
§ion
: type_sections
)
6909 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6910 types_htab
, rcuh_kind::TYPE
);
6913 /* Create the hash table of all entries in the .debug_types section,
6914 and initialize all_type_units.
6915 The result is zero if there is an error (e.g. missing .debug_types section),
6916 otherwise non-zero. */
6919 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6921 htab_t types_htab
= NULL
;
6923 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6924 &dwarf2_per_objfile
->info
, types_htab
,
6925 rcuh_kind::COMPILE
);
6926 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6927 dwarf2_per_objfile
->types
, types_htab
);
6928 if (types_htab
== NULL
)
6930 dwarf2_per_objfile
->signatured_types
= NULL
;
6934 dwarf2_per_objfile
->signatured_types
= types_htab
;
6936 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6937 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6939 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6940 &dwarf2_per_objfile
->all_type_units
);
6945 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6946 If SLOT is non-NULL, it is the entry to use in the hash table.
6947 Otherwise we find one. */
6949 static struct signatured_type
*
6950 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6953 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6955 if (dwarf2_per_objfile
->all_type_units
.size ()
6956 == dwarf2_per_objfile
->all_type_units
.capacity ())
6957 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6959 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6960 struct signatured_type
);
6962 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6963 sig_type
->signature
= sig
;
6964 sig_type
->per_cu
.is_debug_types
= 1;
6965 if (dwarf2_per_objfile
->using_index
)
6967 sig_type
->per_cu
.v
.quick
=
6968 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6969 struct dwarf2_per_cu_quick_data
);
6974 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6977 gdb_assert (*slot
== NULL
);
6979 /* The rest of sig_type must be filled in by the caller. */
6983 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6984 Fill in SIG_ENTRY with DWO_ENTRY. */
6987 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6988 struct signatured_type
*sig_entry
,
6989 struct dwo_unit
*dwo_entry
)
6991 /* Make sure we're not clobbering something we don't expect to. */
6992 gdb_assert (! sig_entry
->per_cu
.queued
);
6993 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6994 if (dwarf2_per_objfile
->using_index
)
6996 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6997 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7000 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7001 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7002 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7003 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7004 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7006 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7007 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7008 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7009 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7010 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7011 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7012 sig_entry
->dwo_unit
= dwo_entry
;
7015 /* Subroutine of lookup_signatured_type.
7016 If we haven't read the TU yet, create the signatured_type data structure
7017 for a TU to be read in directly from a DWO file, bypassing the stub.
7018 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7019 using .gdb_index, then when reading a CU we want to stay in the DWO file
7020 containing that CU. Otherwise we could end up reading several other DWO
7021 files (due to comdat folding) to process the transitive closure of all the
7022 mentioned TUs, and that can be slow. The current DWO file will have every
7023 type signature that it needs.
7024 We only do this for .gdb_index because in the psymtab case we already have
7025 to read all the DWOs to build the type unit groups. */
7027 static struct signatured_type
*
7028 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7030 struct dwarf2_per_objfile
*dwarf2_per_objfile
7031 = cu
->per_cu
->dwarf2_per_objfile
;
7032 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7033 struct dwo_file
*dwo_file
;
7034 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7035 struct signatured_type find_sig_entry
, *sig_entry
;
7038 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7040 /* If TU skeletons have been removed then we may not have read in any
7042 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7044 dwarf2_per_objfile
->signatured_types
7045 = allocate_signatured_type_table (objfile
);
7048 /* We only ever need to read in one copy of a signatured type.
7049 Use the global signatured_types array to do our own comdat-folding
7050 of types. If this is the first time we're reading this TU, and
7051 the TU has an entry in .gdb_index, replace the recorded data from
7052 .gdb_index with this TU. */
7054 find_sig_entry
.signature
= sig
;
7055 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7056 &find_sig_entry
, INSERT
);
7057 sig_entry
= (struct signatured_type
*) *slot
;
7059 /* We can get here with the TU already read, *or* in the process of being
7060 read. Don't reassign the global entry to point to this DWO if that's
7061 the case. Also note that if the TU is already being read, it may not
7062 have come from a DWO, the program may be a mix of Fission-compiled
7063 code and non-Fission-compiled code. */
7065 /* Have we already tried to read this TU?
7066 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7067 needn't exist in the global table yet). */
7068 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7071 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7072 dwo_unit of the TU itself. */
7073 dwo_file
= cu
->dwo_unit
->dwo_file
;
7075 /* Ok, this is the first time we're reading this TU. */
7076 if (dwo_file
->tus
== NULL
)
7078 find_dwo_entry
.signature
= sig
;
7079 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7080 if (dwo_entry
== NULL
)
7083 /* If the global table doesn't have an entry for this TU, add one. */
7084 if (sig_entry
== NULL
)
7085 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7087 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7088 sig_entry
->per_cu
.tu_read
= 1;
7092 /* Subroutine of lookup_signatured_type.
7093 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7094 then try the DWP file. If the TU stub (skeleton) has been removed then
7095 it won't be in .gdb_index. */
7097 static struct signatured_type
*
7098 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7100 struct dwarf2_per_objfile
*dwarf2_per_objfile
7101 = cu
->per_cu
->dwarf2_per_objfile
;
7102 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7103 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7104 struct dwo_unit
*dwo_entry
;
7105 struct signatured_type find_sig_entry
, *sig_entry
;
7108 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7109 gdb_assert (dwp_file
!= NULL
);
7111 /* If TU skeletons have been removed then we may not have read in any
7113 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7115 dwarf2_per_objfile
->signatured_types
7116 = allocate_signatured_type_table (objfile
);
7119 find_sig_entry
.signature
= sig
;
7120 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7121 &find_sig_entry
, INSERT
);
7122 sig_entry
= (struct signatured_type
*) *slot
;
7124 /* Have we already tried to read this TU?
7125 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7126 needn't exist in the global table yet). */
7127 if (sig_entry
!= NULL
)
7130 if (dwp_file
->tus
== NULL
)
7132 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7133 sig
, 1 /* is_debug_types */);
7134 if (dwo_entry
== NULL
)
7137 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7138 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7143 /* Lookup a signature based type for DW_FORM_ref_sig8.
7144 Returns NULL if signature SIG is not present in the table.
7145 It is up to the caller to complain about this. */
7147 static struct signatured_type
*
7148 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7150 struct dwarf2_per_objfile
*dwarf2_per_objfile
7151 = cu
->per_cu
->dwarf2_per_objfile
;
7154 && dwarf2_per_objfile
->using_index
)
7156 /* We're in a DWO/DWP file, and we're using .gdb_index.
7157 These cases require special processing. */
7158 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7159 return lookup_dwo_signatured_type (cu
, sig
);
7161 return lookup_dwp_signatured_type (cu
, sig
);
7165 struct signatured_type find_entry
, *entry
;
7167 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7169 find_entry
.signature
= sig
;
7170 entry
= ((struct signatured_type
*)
7171 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7176 /* Low level DIE reading support. */
7178 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7181 init_cu_die_reader (struct die_reader_specs
*reader
,
7182 struct dwarf2_cu
*cu
,
7183 struct dwarf2_section_info
*section
,
7184 struct dwo_file
*dwo_file
,
7185 struct abbrev_table
*abbrev_table
)
7187 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7188 reader
->abfd
= get_section_bfd_owner (section
);
7190 reader
->dwo_file
= dwo_file
;
7191 reader
->die_section
= section
;
7192 reader
->buffer
= section
->buffer
;
7193 reader
->buffer_end
= section
->buffer
+ section
->size
;
7194 reader
->comp_dir
= NULL
;
7195 reader
->abbrev_table
= abbrev_table
;
7198 /* Subroutine of init_cutu_and_read_dies to simplify it.
7199 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7200 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7203 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7204 from it to the DIE in the DWO. If NULL we are skipping the stub.
7205 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7206 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7207 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7208 STUB_COMP_DIR may be non-NULL.
7209 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7210 are filled in with the info of the DIE from the DWO file.
7211 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7212 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7213 kept around for at least as long as *RESULT_READER.
7215 The result is non-zero if a valid (non-dummy) DIE was found. */
7218 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7219 struct dwo_unit
*dwo_unit
,
7220 struct die_info
*stub_comp_unit_die
,
7221 const char *stub_comp_dir
,
7222 struct die_reader_specs
*result_reader
,
7223 const gdb_byte
**result_info_ptr
,
7224 struct die_info
**result_comp_unit_die
,
7225 int *result_has_children
,
7226 abbrev_table_up
*result_dwo_abbrev_table
)
7228 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7229 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7230 struct dwarf2_cu
*cu
= this_cu
->cu
;
7232 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7233 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7234 int i
,num_extra_attrs
;
7235 struct dwarf2_section_info
*dwo_abbrev_section
;
7236 struct attribute
*attr
;
7237 struct die_info
*comp_unit_die
;
7239 /* At most one of these may be provided. */
7240 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7242 /* These attributes aren't processed until later:
7243 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7244 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7245 referenced later. However, these attributes are found in the stub
7246 which we won't have later. In order to not impose this complication
7247 on the rest of the code, we read them here and copy them to the
7256 if (stub_comp_unit_die
!= NULL
)
7258 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7260 if (! this_cu
->is_debug_types
)
7261 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7262 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7263 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7264 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7265 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7267 /* There should be a DW_AT_addr_base attribute here (if needed).
7268 We need the value before we can process DW_FORM_GNU_addr_index
7269 or DW_FORM_addrx. */
7271 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7272 if (attr
!= nullptr)
7273 cu
->addr_base
= DW_UNSND (attr
);
7275 /* There should be a DW_AT_ranges_base attribute here (if needed).
7276 We need the value before we can process DW_AT_ranges. */
7277 cu
->ranges_base
= 0;
7278 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7279 if (attr
!= nullptr)
7280 cu
->ranges_base
= DW_UNSND (attr
);
7282 else if (stub_comp_dir
!= NULL
)
7284 /* Reconstruct the comp_dir attribute to simplify the code below. */
7285 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7286 comp_dir
->name
= DW_AT_comp_dir
;
7287 comp_dir
->form
= DW_FORM_string
;
7288 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7289 DW_STRING (comp_dir
) = stub_comp_dir
;
7292 /* Set up for reading the DWO CU/TU. */
7293 cu
->dwo_unit
= dwo_unit
;
7294 dwarf2_section_info
*section
= dwo_unit
->section
;
7295 dwarf2_read_section (objfile
, section
);
7296 abfd
= get_section_bfd_owner (section
);
7297 begin_info_ptr
= info_ptr
= (section
->buffer
7298 + to_underlying (dwo_unit
->sect_off
));
7299 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7301 if (this_cu
->is_debug_types
)
7303 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7305 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7306 &cu
->header
, section
,
7308 info_ptr
, rcuh_kind::TYPE
);
7309 /* This is not an assert because it can be caused by bad debug info. */
7310 if (sig_type
->signature
!= cu
->header
.signature
)
7312 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7313 " TU at offset %s [in module %s]"),
7314 hex_string (sig_type
->signature
),
7315 hex_string (cu
->header
.signature
),
7316 sect_offset_str (dwo_unit
->sect_off
),
7317 bfd_get_filename (abfd
));
7319 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7320 /* For DWOs coming from DWP files, we don't know the CU length
7321 nor the type's offset in the TU until now. */
7322 dwo_unit
->length
= get_cu_length (&cu
->header
);
7323 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7325 /* Establish the type offset that can be used to lookup the type.
7326 For DWO files, we don't know it until now. */
7327 sig_type
->type_offset_in_section
7328 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7332 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7333 &cu
->header
, section
,
7335 info_ptr
, rcuh_kind::COMPILE
);
7336 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7337 /* For DWOs coming from DWP files, we don't know the CU length
7339 dwo_unit
->length
= get_cu_length (&cu
->header
);
7342 *result_dwo_abbrev_table
7343 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7344 cu
->header
.abbrev_sect_off
);
7345 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7346 result_dwo_abbrev_table
->get ());
7348 /* Read in the die, but leave space to copy over the attributes
7349 from the stub. This has the benefit of simplifying the rest of
7350 the code - all the work to maintain the illusion of a single
7351 DW_TAG_{compile,type}_unit DIE is done here. */
7352 num_extra_attrs
= ((stmt_list
!= NULL
)
7356 + (comp_dir
!= NULL
));
7357 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7358 result_has_children
, num_extra_attrs
);
7360 /* Copy over the attributes from the stub to the DIE we just read in. */
7361 comp_unit_die
= *result_comp_unit_die
;
7362 i
= comp_unit_die
->num_attrs
;
7363 if (stmt_list
!= NULL
)
7364 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7366 comp_unit_die
->attrs
[i
++] = *low_pc
;
7367 if (high_pc
!= NULL
)
7368 comp_unit_die
->attrs
[i
++] = *high_pc
;
7370 comp_unit_die
->attrs
[i
++] = *ranges
;
7371 if (comp_dir
!= NULL
)
7372 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7373 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7375 if (dwarf_die_debug
)
7377 fprintf_unfiltered (gdb_stdlog
,
7378 "Read die from %s@0x%x of %s:\n",
7379 get_section_name (section
),
7380 (unsigned) (begin_info_ptr
- section
->buffer
),
7381 bfd_get_filename (abfd
));
7382 dump_die (comp_unit_die
, dwarf_die_debug
);
7385 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7386 TUs by skipping the stub and going directly to the entry in the DWO file.
7387 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7388 to get it via circuitous means. Blech. */
7389 if (comp_dir
!= NULL
)
7390 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7392 /* Skip dummy compilation units. */
7393 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7394 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7397 *result_info_ptr
= info_ptr
;
7401 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7402 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7403 signature is part of the header. */
7404 static gdb::optional
<ULONGEST
>
7405 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7407 if (cu
->header
.version
>= 5)
7408 return cu
->header
.signature
;
7409 struct attribute
*attr
;
7410 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7411 if (attr
== nullptr)
7412 return gdb::optional
<ULONGEST
> ();
7413 return DW_UNSND (attr
);
7416 /* Subroutine of init_cutu_and_read_dies to simplify it.
7417 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7418 Returns NULL if the specified DWO unit cannot be found. */
7420 static struct dwo_unit
*
7421 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7422 struct die_info
*comp_unit_die
)
7424 struct dwarf2_cu
*cu
= this_cu
->cu
;
7425 struct dwo_unit
*dwo_unit
;
7426 const char *comp_dir
, *dwo_name
;
7428 gdb_assert (cu
!= NULL
);
7430 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7431 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7432 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7434 if (this_cu
->is_debug_types
)
7436 struct signatured_type
*sig_type
;
7438 /* Since this_cu is the first member of struct signatured_type,
7439 we can go from a pointer to one to a pointer to the other. */
7440 sig_type
= (struct signatured_type
*) this_cu
;
7441 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7445 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7446 if (!signature
.has_value ())
7447 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7449 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7450 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7457 /* Subroutine of init_cutu_and_read_dies to simplify it.
7458 See it for a description of the parameters.
7459 Read a TU directly from a DWO file, bypassing the stub. */
7462 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7463 int use_existing_cu
, int keep
,
7464 die_reader_func_ftype
*die_reader_func
,
7467 std::unique_ptr
<dwarf2_cu
> new_cu
;
7468 struct signatured_type
*sig_type
;
7469 struct die_reader_specs reader
;
7470 const gdb_byte
*info_ptr
;
7471 struct die_info
*comp_unit_die
;
7473 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7475 /* Verify we can do the following downcast, and that we have the
7477 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7478 sig_type
= (struct signatured_type
*) this_cu
;
7479 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7481 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7483 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7484 /* There's no need to do the rereading_dwo_cu handling that
7485 init_cutu_and_read_dies does since we don't read the stub. */
7489 /* If !use_existing_cu, this_cu->cu must be NULL. */
7490 gdb_assert (this_cu
->cu
== NULL
);
7491 new_cu
.reset (new dwarf2_cu (this_cu
));
7494 /* A future optimization, if needed, would be to use an existing
7495 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7496 could share abbrev tables. */
7498 /* The abbreviation table used by READER, this must live at least as long as
7500 abbrev_table_up dwo_abbrev_table
;
7502 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7503 NULL
/* stub_comp_unit_die */,
7504 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7506 &comp_unit_die
, &has_children
,
7507 &dwo_abbrev_table
) == 0)
7513 /* All the "real" work is done here. */
7514 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7516 /* This duplicates the code in init_cutu_and_read_dies,
7517 but the alternative is making the latter more complex.
7518 This function is only for the special case of using DWO files directly:
7519 no point in overly complicating the general case just to handle this. */
7520 if (new_cu
!= NULL
&& keep
)
7522 /* Link this CU into read_in_chain. */
7523 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7524 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7525 /* The chain owns it now. */
7530 /* Initialize a CU (or TU) and read its DIEs.
7531 If the CU defers to a DWO file, read the DWO file as well.
7533 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7534 Otherwise the table specified in the comp unit header is read in and used.
7535 This is an optimization for when we already have the abbrev table.
7537 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7538 Otherwise, a new CU is allocated with xmalloc.
7540 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7541 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7543 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7544 linker) then DIE_READER_FUNC will not get called. */
7547 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7548 struct abbrev_table
*abbrev_table
,
7549 int use_existing_cu
, int keep
,
7551 die_reader_func_ftype
*die_reader_func
,
7554 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7555 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7556 struct dwarf2_section_info
*section
= this_cu
->section
;
7557 bfd
*abfd
= get_section_bfd_owner (section
);
7558 struct dwarf2_cu
*cu
;
7559 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7560 struct die_reader_specs reader
;
7561 struct die_info
*comp_unit_die
;
7563 struct signatured_type
*sig_type
= NULL
;
7564 struct dwarf2_section_info
*abbrev_section
;
7565 /* Non-zero if CU currently points to a DWO file and we need to
7566 reread it. When this happens we need to reread the skeleton die
7567 before we can reread the DWO file (this only applies to CUs, not TUs). */
7568 int rereading_dwo_cu
= 0;
7570 if (dwarf_die_debug
)
7571 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7572 this_cu
->is_debug_types
? "type" : "comp",
7573 sect_offset_str (this_cu
->sect_off
));
7575 if (use_existing_cu
)
7578 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7579 file (instead of going through the stub), short-circuit all of this. */
7580 if (this_cu
->reading_dwo_directly
)
7582 /* Narrow down the scope of possibilities to have to understand. */
7583 gdb_assert (this_cu
->is_debug_types
);
7584 gdb_assert (abbrev_table
== NULL
);
7585 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7586 die_reader_func
, data
);
7590 /* This is cheap if the section is already read in. */
7591 dwarf2_read_section (objfile
, section
);
7593 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7595 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7597 std::unique_ptr
<dwarf2_cu
> new_cu
;
7598 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7601 /* If this CU is from a DWO file we need to start over, we need to
7602 refetch the attributes from the skeleton CU.
7603 This could be optimized by retrieving those attributes from when we
7604 were here the first time: the previous comp_unit_die was stored in
7605 comp_unit_obstack. But there's no data yet that we need this
7607 if (cu
->dwo_unit
!= NULL
)
7608 rereading_dwo_cu
= 1;
7612 /* If !use_existing_cu, this_cu->cu must be NULL. */
7613 gdb_assert (this_cu
->cu
== NULL
);
7614 new_cu
.reset (new dwarf2_cu (this_cu
));
7618 /* Get the header. */
7619 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7621 /* We already have the header, there's no need to read it in again. */
7622 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7626 if (this_cu
->is_debug_types
)
7628 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7629 &cu
->header
, section
,
7630 abbrev_section
, info_ptr
,
7633 /* Since per_cu is the first member of struct signatured_type,
7634 we can go from a pointer to one to a pointer to the other. */
7635 sig_type
= (struct signatured_type
*) this_cu
;
7636 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7637 gdb_assert (sig_type
->type_offset_in_tu
7638 == cu
->header
.type_cu_offset_in_tu
);
7639 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7641 /* LENGTH has not been set yet for type units if we're
7642 using .gdb_index. */
7643 this_cu
->length
= get_cu_length (&cu
->header
);
7645 /* Establish the type offset that can be used to lookup the type. */
7646 sig_type
->type_offset_in_section
=
7647 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7649 this_cu
->dwarf_version
= cu
->header
.version
;
7653 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7654 &cu
->header
, section
,
7657 rcuh_kind::COMPILE
);
7659 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7660 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7661 this_cu
->dwarf_version
= cu
->header
.version
;
7665 /* Skip dummy compilation units. */
7666 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7667 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7670 /* If we don't have them yet, read the abbrevs for this compilation unit.
7671 And if we need to read them now, make sure they're freed when we're
7672 done (own the table through ABBREV_TABLE_HOLDER). */
7673 abbrev_table_up abbrev_table_holder
;
7674 if (abbrev_table
!= NULL
)
7675 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7679 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7680 cu
->header
.abbrev_sect_off
);
7681 abbrev_table
= abbrev_table_holder
.get ();
7684 /* Read the top level CU/TU die. */
7685 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7686 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7688 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7691 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7692 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7693 table from the DWO file and pass the ownership over to us. It will be
7694 referenced from READER, so we must make sure to free it after we're done
7697 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7698 DWO CU, that this test will fail (the attribute will not be present). */
7699 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7700 abbrev_table_up dwo_abbrev_table
;
7701 if (dwo_name
!= nullptr)
7703 struct dwo_unit
*dwo_unit
;
7704 struct die_info
*dwo_comp_unit_die
;
7708 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7709 " has children (offset %s) [in module %s]"),
7710 sect_offset_str (this_cu
->sect_off
),
7711 bfd_get_filename (abfd
));
7713 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7714 if (dwo_unit
!= NULL
)
7716 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7717 comp_unit_die
, NULL
,
7719 &dwo_comp_unit_die
, &has_children
,
7720 &dwo_abbrev_table
) == 0)
7725 comp_unit_die
= dwo_comp_unit_die
;
7729 /* Yikes, we couldn't find the rest of the DIE, we only have
7730 the stub. A complaint has already been logged. There's
7731 not much more we can do except pass on the stub DIE to
7732 die_reader_func. We don't want to throw an error on bad
7737 /* All of the above is setup for this call. Yikes. */
7738 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7740 /* Done, clean up. */
7741 if (new_cu
!= NULL
&& keep
)
7743 /* Link this CU into read_in_chain. */
7744 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7745 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7746 /* The chain owns it now. */
7751 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7752 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7753 to have already done the lookup to find the DWO file).
7755 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7756 THIS_CU->is_debug_types, but nothing else.
7758 We fill in THIS_CU->length.
7760 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7761 linker) then DIE_READER_FUNC will not get called.
7763 THIS_CU->cu is always freed when done.
7764 This is done in order to not leave THIS_CU->cu in a state where we have
7765 to care whether it refers to the "main" CU or the DWO CU. */
7768 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7769 struct dwo_file
*dwo_file
,
7770 die_reader_func_ftype
*die_reader_func
,
7773 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7774 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7775 struct dwarf2_section_info
*section
= this_cu
->section
;
7776 bfd
*abfd
= get_section_bfd_owner (section
);
7777 struct dwarf2_section_info
*abbrev_section
;
7778 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7779 struct die_reader_specs reader
;
7780 struct die_info
*comp_unit_die
;
7783 if (dwarf_die_debug
)
7784 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7785 this_cu
->is_debug_types
? "type" : "comp",
7786 sect_offset_str (this_cu
->sect_off
));
7788 gdb_assert (this_cu
->cu
== NULL
);
7790 abbrev_section
= (dwo_file
!= NULL
7791 ? &dwo_file
->sections
.abbrev
7792 : get_abbrev_section_for_cu (this_cu
));
7794 /* This is cheap if the section is already read in. */
7795 dwarf2_read_section (objfile
, section
);
7797 struct dwarf2_cu
cu (this_cu
);
7799 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7800 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7801 &cu
.header
, section
,
7802 abbrev_section
, info_ptr
,
7803 (this_cu
->is_debug_types
7805 : rcuh_kind::COMPILE
));
7807 this_cu
->length
= get_cu_length (&cu
.header
);
7809 /* Skip dummy compilation units. */
7810 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7811 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7814 abbrev_table_up abbrev_table
7815 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7816 cu
.header
.abbrev_sect_off
);
7818 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7819 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7821 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7824 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7825 does not lookup the specified DWO file.
7826 This cannot be used to read DWO files.
7828 THIS_CU->cu is always freed when done.
7829 This is done in order to not leave THIS_CU->cu in a state where we have
7830 to care whether it refers to the "main" CU or the DWO CU.
7831 We can revisit this if the data shows there's a performance issue. */
7834 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7835 die_reader_func_ftype
*die_reader_func
,
7838 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7841 /* Type Unit Groups.
7843 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7844 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7845 so that all types coming from the same compilation (.o file) are grouped
7846 together. A future step could be to put the types in the same symtab as
7847 the CU the types ultimately came from. */
7850 hash_type_unit_group (const void *item
)
7852 const struct type_unit_group
*tu_group
7853 = (const struct type_unit_group
*) item
;
7855 return hash_stmt_list_entry (&tu_group
->hash
);
7859 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7861 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7862 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7864 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7867 /* Allocate a hash table for type unit groups. */
7870 allocate_type_unit_groups_table (struct objfile
*objfile
)
7872 return htab_create_alloc_ex (3,
7873 hash_type_unit_group
,
7876 &objfile
->objfile_obstack
,
7877 hashtab_obstack_allocate
,
7878 dummy_obstack_deallocate
);
7881 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7882 partial symtabs. We combine several TUs per psymtab to not let the size
7883 of any one psymtab grow too big. */
7884 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7885 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7887 /* Helper routine for get_type_unit_group.
7888 Create the type_unit_group object used to hold one or more TUs. */
7890 static struct type_unit_group
*
7891 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7893 struct dwarf2_per_objfile
*dwarf2_per_objfile
7894 = cu
->per_cu
->dwarf2_per_objfile
;
7895 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7896 struct dwarf2_per_cu_data
*per_cu
;
7897 struct type_unit_group
*tu_group
;
7899 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7900 struct type_unit_group
);
7901 per_cu
= &tu_group
->per_cu
;
7902 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7904 if (dwarf2_per_objfile
->using_index
)
7906 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7907 struct dwarf2_per_cu_quick_data
);
7911 unsigned int line_offset
= to_underlying (line_offset_struct
);
7912 struct partial_symtab
*pst
;
7915 /* Give the symtab a useful name for debug purposes. */
7916 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7917 name
= string_printf ("<type_units_%d>",
7918 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7920 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7922 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7926 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7927 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7932 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7933 STMT_LIST is a DW_AT_stmt_list attribute. */
7935 static struct type_unit_group
*
7936 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7938 struct dwarf2_per_objfile
*dwarf2_per_objfile
7939 = cu
->per_cu
->dwarf2_per_objfile
;
7940 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7941 struct type_unit_group
*tu_group
;
7943 unsigned int line_offset
;
7944 struct type_unit_group type_unit_group_for_lookup
;
7946 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7948 dwarf2_per_objfile
->type_unit_groups
=
7949 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7952 /* Do we need to create a new group, or can we use an existing one? */
7956 line_offset
= DW_UNSND (stmt_list
);
7957 ++tu_stats
->nr_symtab_sharers
;
7961 /* Ugh, no stmt_list. Rare, but we have to handle it.
7962 We can do various things here like create one group per TU or
7963 spread them over multiple groups to split up the expansion work.
7964 To avoid worst case scenarios (too many groups or too large groups)
7965 we, umm, group them in bunches. */
7966 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7967 | (tu_stats
->nr_stmt_less_type_units
7968 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7969 ++tu_stats
->nr_stmt_less_type_units
;
7972 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7973 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7974 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7975 &type_unit_group_for_lookup
, INSERT
);
7978 tu_group
= (struct type_unit_group
*) *slot
;
7979 gdb_assert (tu_group
!= NULL
);
7983 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7984 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7986 ++tu_stats
->nr_symtabs
;
7992 /* Partial symbol tables. */
7994 /* Create a psymtab named NAME and assign it to PER_CU.
7996 The caller must fill in the following details:
7997 dirname, textlow, texthigh. */
7999 static struct partial_symtab
*
8000 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8002 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8003 struct partial_symtab
*pst
;
8005 pst
= start_psymtab_common (objfile
, name
, 0);
8007 pst
->psymtabs_addrmap_supported
= 1;
8009 /* This is the glue that links PST into GDB's symbol API. */
8010 pst
->read_symtab_private
= per_cu
;
8011 pst
->read_symtab
= dwarf2_read_symtab
;
8012 per_cu
->v
.psymtab
= pst
;
8017 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8020 struct process_psymtab_comp_unit_data
8022 /* True if we are reading a DW_TAG_partial_unit. */
8024 int want_partial_unit
;
8026 /* The "pretend" language that is used if the CU doesn't declare a
8029 enum language pretend_language
;
8032 /* die_reader_func for process_psymtab_comp_unit. */
8035 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8036 const gdb_byte
*info_ptr
,
8037 struct die_info
*comp_unit_die
,
8041 struct dwarf2_cu
*cu
= reader
->cu
;
8042 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8043 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8044 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8046 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8047 struct partial_symtab
*pst
;
8048 enum pc_bounds_kind cu_bounds_kind
;
8049 const char *filename
;
8050 struct process_psymtab_comp_unit_data
*info
8051 = (struct process_psymtab_comp_unit_data
*) data
;
8053 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8056 gdb_assert (! per_cu
->is_debug_types
);
8058 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8060 /* Allocate a new partial symbol table structure. */
8061 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8062 if (filename
== NULL
)
8065 pst
= create_partial_symtab (per_cu
, filename
);
8067 /* This must be done before calling dwarf2_build_include_psymtabs. */
8068 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8070 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
8072 dwarf2_find_base_address (comp_unit_die
, cu
);
8074 /* Possibly set the default values of LOWPC and HIGHPC from
8076 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8077 &best_highpc
, cu
, pst
);
8078 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8081 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8084 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8086 /* Store the contiguous range if it is not empty; it can be
8087 empty for CUs with no code. */
8088 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8092 /* Check if comp unit has_children.
8093 If so, read the rest of the partial symbols from this comp unit.
8094 If not, there's no more debug_info for this comp unit. */
8097 struct partial_die_info
*first_die
;
8098 CORE_ADDR lowpc
, highpc
;
8100 lowpc
= ((CORE_ADDR
) -1);
8101 highpc
= ((CORE_ADDR
) 0);
8103 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8105 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8106 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8108 /* If we didn't find a lowpc, set it to highpc to avoid
8109 complaints from `maint check'. */
8110 if (lowpc
== ((CORE_ADDR
) -1))
8113 /* If the compilation unit didn't have an explicit address range,
8114 then use the information extracted from its child dies. */
8115 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8118 best_highpc
= highpc
;
8121 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8122 best_lowpc
+ baseaddr
)
8124 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8125 best_highpc
+ baseaddr
)
8128 end_psymtab_common (objfile
, pst
);
8130 if (!cu
->per_cu
->imported_symtabs_empty ())
8133 int len
= cu
->per_cu
->imported_symtabs_size ();
8135 /* Fill in 'dependencies' here; we fill in 'users' in a
8137 pst
->number_of_dependencies
= len
;
8139 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8140 for (i
= 0; i
< len
; ++i
)
8142 pst
->dependencies
[i
]
8143 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8146 cu
->per_cu
->imported_symtabs_free ();
8149 /* Get the list of files included in the current compilation unit,
8150 and build a psymtab for each of them. */
8151 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8153 if (dwarf_read_debug
)
8154 fprintf_unfiltered (gdb_stdlog
,
8155 "Psymtab for %s unit @%s: %s - %s"
8156 ", %d global, %d static syms\n",
8157 per_cu
->is_debug_types
? "type" : "comp",
8158 sect_offset_str (per_cu
->sect_off
),
8159 paddress (gdbarch
, pst
->text_low (objfile
)),
8160 paddress (gdbarch
, pst
->text_high (objfile
)),
8161 pst
->n_global_syms
, pst
->n_static_syms
);
8164 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8165 Process compilation unit THIS_CU for a psymtab. */
8168 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8169 int want_partial_unit
,
8170 enum language pretend_language
)
8172 /* If this compilation unit was already read in, free the
8173 cached copy in order to read it in again. This is
8174 necessary because we skipped some symbols when we first
8175 read in the compilation unit (see load_partial_dies).
8176 This problem could be avoided, but the benefit is unclear. */
8177 if (this_cu
->cu
!= NULL
)
8178 free_one_cached_comp_unit (this_cu
);
8180 if (this_cu
->is_debug_types
)
8181 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8182 build_type_psymtabs_reader
, NULL
);
8185 process_psymtab_comp_unit_data info
;
8186 info
.want_partial_unit
= want_partial_unit
;
8187 info
.pretend_language
= pretend_language
;
8188 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8189 process_psymtab_comp_unit_reader
, &info
);
8192 /* Age out any secondary CUs. */
8193 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8196 /* Reader function for build_type_psymtabs. */
8199 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8200 const gdb_byte
*info_ptr
,
8201 struct die_info
*type_unit_die
,
8205 struct dwarf2_per_objfile
*dwarf2_per_objfile
8206 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8207 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8208 struct dwarf2_cu
*cu
= reader
->cu
;
8209 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8210 struct signatured_type
*sig_type
;
8211 struct type_unit_group
*tu_group
;
8212 struct attribute
*attr
;
8213 struct partial_die_info
*first_die
;
8214 CORE_ADDR lowpc
, highpc
;
8215 struct partial_symtab
*pst
;
8217 gdb_assert (data
== NULL
);
8218 gdb_assert (per_cu
->is_debug_types
);
8219 sig_type
= (struct signatured_type
*) per_cu
;
8224 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8225 tu_group
= get_type_unit_group (cu
, attr
);
8227 if (tu_group
->tus
== nullptr)
8228 tu_group
->tus
= new std::vector
<signatured_type
*>;
8229 tu_group
->tus
->push_back (sig_type
);
8231 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8232 pst
= create_partial_symtab (per_cu
, "");
8235 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8237 lowpc
= (CORE_ADDR
) -1;
8238 highpc
= (CORE_ADDR
) 0;
8239 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8241 end_psymtab_common (objfile
, pst
);
8244 /* Struct used to sort TUs by their abbreviation table offset. */
8246 struct tu_abbrev_offset
8248 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8249 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8252 signatured_type
*sig_type
;
8253 sect_offset abbrev_offset
;
8256 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8259 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8260 const struct tu_abbrev_offset
&b
)
8262 return a
.abbrev_offset
< b
.abbrev_offset
;
8265 /* Efficiently read all the type units.
8266 This does the bulk of the work for build_type_psymtabs.
8268 The efficiency is because we sort TUs by the abbrev table they use and
8269 only read each abbrev table once. In one program there are 200K TUs
8270 sharing 8K abbrev tables.
8272 The main purpose of this function is to support building the
8273 dwarf2_per_objfile->type_unit_groups table.
8274 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8275 can collapse the search space by grouping them by stmt_list.
8276 The savings can be significant, in the same program from above the 200K TUs
8277 share 8K stmt_list tables.
8279 FUNC is expected to call get_type_unit_group, which will create the
8280 struct type_unit_group if necessary and add it to
8281 dwarf2_per_objfile->type_unit_groups. */
8284 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8286 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8287 abbrev_table_up abbrev_table
;
8288 sect_offset abbrev_offset
;
8290 /* It's up to the caller to not call us multiple times. */
8291 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8293 if (dwarf2_per_objfile
->all_type_units
.empty ())
8296 /* TUs typically share abbrev tables, and there can be way more TUs than
8297 abbrev tables. Sort by abbrev table to reduce the number of times we
8298 read each abbrev table in.
8299 Alternatives are to punt or to maintain a cache of abbrev tables.
8300 This is simpler and efficient enough for now.
8302 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8303 symtab to use). Typically TUs with the same abbrev offset have the same
8304 stmt_list value too so in practice this should work well.
8306 The basic algorithm here is:
8308 sort TUs by abbrev table
8309 for each TU with same abbrev table:
8310 read abbrev table if first user
8311 read TU top level DIE
8312 [IWBN if DWO skeletons had DW_AT_stmt_list]
8315 if (dwarf_read_debug
)
8316 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8318 /* Sort in a separate table to maintain the order of all_type_units
8319 for .gdb_index: TU indices directly index all_type_units. */
8320 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8321 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8323 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8324 sorted_by_abbrev
.emplace_back
8325 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8326 sig_type
->per_cu
.section
,
8327 sig_type
->per_cu
.sect_off
));
8329 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8330 sort_tu_by_abbrev_offset
);
8332 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8334 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8336 /* Switch to the next abbrev table if necessary. */
8337 if (abbrev_table
== NULL
8338 || tu
.abbrev_offset
!= abbrev_offset
)
8340 abbrev_offset
= tu
.abbrev_offset
;
8342 abbrev_table_read_table (dwarf2_per_objfile
,
8343 &dwarf2_per_objfile
->abbrev
,
8345 ++tu_stats
->nr_uniq_abbrev_tables
;
8348 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8349 0, 0, false, build_type_psymtabs_reader
, NULL
);
8353 /* Print collected type unit statistics. */
8356 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8358 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8360 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8361 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8362 dwarf2_per_objfile
->all_type_units
.size ());
8363 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8364 tu_stats
->nr_uniq_abbrev_tables
);
8365 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8366 tu_stats
->nr_symtabs
);
8367 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8368 tu_stats
->nr_symtab_sharers
);
8369 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8370 tu_stats
->nr_stmt_less_type_units
);
8371 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8372 tu_stats
->nr_all_type_units_reallocs
);
8375 /* Traversal function for build_type_psymtabs. */
8378 build_type_psymtab_dependencies (void **slot
, void *info
)
8380 struct dwarf2_per_objfile
*dwarf2_per_objfile
8381 = (struct dwarf2_per_objfile
*) info
;
8382 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8383 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8384 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8385 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8386 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8389 gdb_assert (len
> 0);
8390 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8392 pst
->number_of_dependencies
= len
;
8393 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8394 for (i
= 0; i
< len
; ++i
)
8396 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8397 gdb_assert (iter
->per_cu
.is_debug_types
);
8398 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8399 iter
->type_unit_group
= tu_group
;
8402 delete tu_group
->tus
;
8403 tu_group
->tus
= nullptr;
8408 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8409 Build partial symbol tables for the .debug_types comp-units. */
8412 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8414 if (! create_all_type_units (dwarf2_per_objfile
))
8417 build_type_psymtabs_1 (dwarf2_per_objfile
);
8420 /* Traversal function for process_skeletonless_type_unit.
8421 Read a TU in a DWO file and build partial symbols for it. */
8424 process_skeletonless_type_unit (void **slot
, void *info
)
8426 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8427 struct dwarf2_per_objfile
*dwarf2_per_objfile
8428 = (struct dwarf2_per_objfile
*) info
;
8429 struct signatured_type find_entry
, *entry
;
8431 /* If this TU doesn't exist in the global table, add it and read it in. */
8433 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8435 dwarf2_per_objfile
->signatured_types
8436 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8439 find_entry
.signature
= dwo_unit
->signature
;
8440 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8442 /* If we've already seen this type there's nothing to do. What's happening
8443 is we're doing our own version of comdat-folding here. */
8447 /* This does the job that create_all_type_units would have done for
8449 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8450 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8453 /* This does the job that build_type_psymtabs_1 would have done. */
8454 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8455 build_type_psymtabs_reader
, NULL
);
8460 /* Traversal function for process_skeletonless_type_units. */
8463 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8465 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8467 if (dwo_file
->tus
!= NULL
)
8469 htab_traverse_noresize (dwo_file
->tus
,
8470 process_skeletonless_type_unit
, info
);
8476 /* Scan all TUs of DWO files, verifying we've processed them.
8477 This is needed in case a TU was emitted without its skeleton.
8478 Note: This can't be done until we know what all the DWO files are. */
8481 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8483 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8484 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8485 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8487 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8488 process_dwo_file_for_skeletonless_type_units
,
8489 dwarf2_per_objfile
);
8493 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8496 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8498 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8500 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8505 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8507 /* Set the 'user' field only if it is not already set. */
8508 if (pst
->dependencies
[j
]->user
== NULL
)
8509 pst
->dependencies
[j
]->user
= pst
;
8514 /* Build the partial symbol table by doing a quick pass through the
8515 .debug_info and .debug_abbrev sections. */
8518 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8520 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8522 if (dwarf_read_debug
)
8524 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8525 objfile_name (objfile
));
8528 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8530 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8532 /* Any cached compilation units will be linked by the per-objfile
8533 read_in_chain. Make sure to free them when we're done. */
8534 free_cached_comp_units
freer (dwarf2_per_objfile
);
8536 build_type_psymtabs (dwarf2_per_objfile
);
8538 create_all_comp_units (dwarf2_per_objfile
);
8540 /* Create a temporary address map on a temporary obstack. We later
8541 copy this to the final obstack. */
8542 auto_obstack temp_obstack
;
8544 scoped_restore save_psymtabs_addrmap
8545 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8546 addrmap_create_mutable (&temp_obstack
));
8548 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8549 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8551 /* This has to wait until we read the CUs, we need the list of DWOs. */
8552 process_skeletonless_type_units (dwarf2_per_objfile
);
8554 /* Now that all TUs have been processed we can fill in the dependencies. */
8555 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8557 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8558 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8561 if (dwarf_read_debug
)
8562 print_tu_stats (dwarf2_per_objfile
);
8564 set_partial_user (dwarf2_per_objfile
);
8566 objfile
->partial_symtabs
->psymtabs_addrmap
8567 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8568 objfile
->partial_symtabs
->obstack ());
8569 /* At this point we want to keep the address map. */
8570 save_psymtabs_addrmap
.release ();
8572 if (dwarf_read_debug
)
8573 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8574 objfile_name (objfile
));
8577 /* die_reader_func for load_partial_comp_unit. */
8580 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8581 const gdb_byte
*info_ptr
,
8582 struct die_info
*comp_unit_die
,
8586 struct dwarf2_cu
*cu
= reader
->cu
;
8588 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8590 /* Check if comp unit has_children.
8591 If so, read the rest of the partial symbols from this comp unit.
8592 If not, there's no more debug_info for this comp unit. */
8594 load_partial_dies (reader
, info_ptr
, 0);
8597 /* Load the partial DIEs for a secondary CU into memory.
8598 This is also used when rereading a primary CU with load_all_dies. */
8601 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8603 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8604 load_partial_comp_unit_reader
, NULL
);
8608 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8609 struct dwarf2_section_info
*section
,
8610 struct dwarf2_section_info
*abbrev_section
,
8611 unsigned int is_dwz
)
8613 const gdb_byte
*info_ptr
;
8614 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8616 if (dwarf_read_debug
)
8617 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8618 get_section_name (section
),
8619 get_section_file_name (section
));
8621 dwarf2_read_section (objfile
, section
);
8623 info_ptr
= section
->buffer
;
8625 while (info_ptr
< section
->buffer
+ section
->size
)
8627 struct dwarf2_per_cu_data
*this_cu
;
8629 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8631 comp_unit_head cu_header
;
8632 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8633 abbrev_section
, info_ptr
,
8634 rcuh_kind::COMPILE
);
8636 /* Save the compilation unit for later lookup. */
8637 if (cu_header
.unit_type
!= DW_UT_type
)
8639 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8640 struct dwarf2_per_cu_data
);
8641 memset (this_cu
, 0, sizeof (*this_cu
));
8645 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8646 struct signatured_type
);
8647 memset (sig_type
, 0, sizeof (*sig_type
));
8648 sig_type
->signature
= cu_header
.signature
;
8649 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8650 this_cu
= &sig_type
->per_cu
;
8652 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8653 this_cu
->sect_off
= sect_off
;
8654 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8655 this_cu
->is_dwz
= is_dwz
;
8656 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8657 this_cu
->section
= section
;
8659 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8661 info_ptr
= info_ptr
+ this_cu
->length
;
8665 /* Create a list of all compilation units in OBJFILE.
8666 This is only done for -readnow and building partial symtabs. */
8669 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8671 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8672 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8673 &dwarf2_per_objfile
->abbrev
, 0);
8675 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8677 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8681 /* Process all loaded DIEs for compilation unit CU, starting at
8682 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8683 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8684 DW_AT_ranges). See the comments of add_partial_subprogram on how
8685 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8688 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8689 CORE_ADDR
*highpc
, int set_addrmap
,
8690 struct dwarf2_cu
*cu
)
8692 struct partial_die_info
*pdi
;
8694 /* Now, march along the PDI's, descending into ones which have
8695 interesting children but skipping the children of the other ones,
8696 until we reach the end of the compilation unit. */
8704 /* Anonymous namespaces or modules have no name but have interesting
8705 children, so we need to look at them. Ditto for anonymous
8708 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8709 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8710 || pdi
->tag
== DW_TAG_imported_unit
8711 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8715 case DW_TAG_subprogram
:
8716 case DW_TAG_inlined_subroutine
:
8717 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8719 case DW_TAG_constant
:
8720 case DW_TAG_variable
:
8721 case DW_TAG_typedef
:
8722 case DW_TAG_union_type
:
8723 if (!pdi
->is_declaration
)
8725 add_partial_symbol (pdi
, cu
);
8728 case DW_TAG_class_type
:
8729 case DW_TAG_interface_type
:
8730 case DW_TAG_structure_type
:
8731 if (!pdi
->is_declaration
)
8733 add_partial_symbol (pdi
, cu
);
8735 if ((cu
->language
== language_rust
8736 || cu
->language
== language_cplus
) && pdi
->has_children
)
8737 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8740 case DW_TAG_enumeration_type
:
8741 if (!pdi
->is_declaration
)
8742 add_partial_enumeration (pdi
, cu
);
8744 case DW_TAG_base_type
:
8745 case DW_TAG_subrange_type
:
8746 /* File scope base type definitions are added to the partial
8748 add_partial_symbol (pdi
, cu
);
8750 case DW_TAG_namespace
:
8751 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8754 if (!pdi
->is_declaration
)
8755 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8757 case DW_TAG_imported_unit
:
8759 struct dwarf2_per_cu_data
*per_cu
;
8761 /* For now we don't handle imported units in type units. */
8762 if (cu
->per_cu
->is_debug_types
)
8764 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8765 " supported in type units [in module %s]"),
8766 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8769 per_cu
= dwarf2_find_containing_comp_unit
8770 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8771 cu
->per_cu
->dwarf2_per_objfile
);
8773 /* Go read the partial unit, if needed. */
8774 if (per_cu
->v
.psymtab
== NULL
)
8775 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8777 cu
->per_cu
->imported_symtabs_push (per_cu
);
8780 case DW_TAG_imported_declaration
:
8781 add_partial_symbol (pdi
, cu
);
8788 /* If the die has a sibling, skip to the sibling. */
8790 pdi
= pdi
->die_sibling
;
8794 /* Functions used to compute the fully scoped name of a partial DIE.
8796 Normally, this is simple. For C++, the parent DIE's fully scoped
8797 name is concatenated with "::" and the partial DIE's name.
8798 Enumerators are an exception; they use the scope of their parent
8799 enumeration type, i.e. the name of the enumeration type is not
8800 prepended to the enumerator.
8802 There are two complexities. One is DW_AT_specification; in this
8803 case "parent" means the parent of the target of the specification,
8804 instead of the direct parent of the DIE. The other is compilers
8805 which do not emit DW_TAG_namespace; in this case we try to guess
8806 the fully qualified name of structure types from their members'
8807 linkage names. This must be done using the DIE's children rather
8808 than the children of any DW_AT_specification target. We only need
8809 to do this for structures at the top level, i.e. if the target of
8810 any DW_AT_specification (if any; otherwise the DIE itself) does not
8813 /* Compute the scope prefix associated with PDI's parent, in
8814 compilation unit CU. The result will be allocated on CU's
8815 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8816 field. NULL is returned if no prefix is necessary. */
8818 partial_die_parent_scope (struct partial_die_info
*pdi
,
8819 struct dwarf2_cu
*cu
)
8821 const char *grandparent_scope
;
8822 struct partial_die_info
*parent
, *real_pdi
;
8824 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8825 then this means the parent of the specification DIE. */
8828 while (real_pdi
->has_specification
)
8830 auto res
= find_partial_die (real_pdi
->spec_offset
,
8831 real_pdi
->spec_is_dwz
, cu
);
8836 parent
= real_pdi
->die_parent
;
8840 if (parent
->scope_set
)
8841 return parent
->scope
;
8845 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8847 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8848 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8849 Work around this problem here. */
8850 if (cu
->language
== language_cplus
8851 && parent
->tag
== DW_TAG_namespace
8852 && strcmp (parent
->name
, "::") == 0
8853 && grandparent_scope
== NULL
)
8855 parent
->scope
= NULL
;
8856 parent
->scope_set
= 1;
8860 /* Nested subroutines in Fortran get a prefix. */
8861 if (pdi
->tag
== DW_TAG_enumerator
)
8862 /* Enumerators should not get the name of the enumeration as a prefix. */
8863 parent
->scope
= grandparent_scope
;
8864 else if (parent
->tag
== DW_TAG_namespace
8865 || parent
->tag
== DW_TAG_module
8866 || parent
->tag
== DW_TAG_structure_type
8867 || parent
->tag
== DW_TAG_class_type
8868 || parent
->tag
== DW_TAG_interface_type
8869 || parent
->tag
== DW_TAG_union_type
8870 || parent
->tag
== DW_TAG_enumeration_type
8871 || (cu
->language
== language_fortran
8872 && parent
->tag
== DW_TAG_subprogram
8873 && pdi
->tag
== DW_TAG_subprogram
))
8875 if (grandparent_scope
== NULL
)
8876 parent
->scope
= parent
->name
;
8878 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8880 parent
->name
, 0, cu
);
8884 /* FIXME drow/2004-04-01: What should we be doing with
8885 function-local names? For partial symbols, we should probably be
8887 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8888 dwarf_tag_name (parent
->tag
),
8889 sect_offset_str (pdi
->sect_off
));
8890 parent
->scope
= grandparent_scope
;
8893 parent
->scope_set
= 1;
8894 return parent
->scope
;
8897 /* Return the fully scoped name associated with PDI, from compilation unit
8898 CU. The result will be allocated with malloc. */
8900 static gdb::unique_xmalloc_ptr
<char>
8901 partial_die_full_name (struct partial_die_info
*pdi
,
8902 struct dwarf2_cu
*cu
)
8904 const char *parent_scope
;
8906 /* If this is a template instantiation, we can not work out the
8907 template arguments from partial DIEs. So, unfortunately, we have
8908 to go through the full DIEs. At least any work we do building
8909 types here will be reused if full symbols are loaded later. */
8910 if (pdi
->has_template_arguments
)
8914 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8916 struct die_info
*die
;
8917 struct attribute attr
;
8918 struct dwarf2_cu
*ref_cu
= cu
;
8920 /* DW_FORM_ref_addr is using section offset. */
8921 attr
.name
= (enum dwarf_attribute
) 0;
8922 attr
.form
= DW_FORM_ref_addr
;
8923 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8924 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8926 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8930 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8931 if (parent_scope
== NULL
)
8934 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8939 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8941 struct dwarf2_per_objfile
*dwarf2_per_objfile
8942 = cu
->per_cu
->dwarf2_per_objfile
;
8943 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8944 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8946 const char *actual_name
= NULL
;
8949 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
8951 gdb::unique_xmalloc_ptr
<char> built_actual_name
8952 = partial_die_full_name (pdi
, cu
);
8953 if (built_actual_name
!= NULL
)
8954 actual_name
= built_actual_name
.get ();
8956 if (actual_name
== NULL
)
8957 actual_name
= pdi
->name
;
8961 case DW_TAG_inlined_subroutine
:
8962 case DW_TAG_subprogram
:
8963 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8965 if (pdi
->is_external
8966 || cu
->language
== language_ada
8967 || (cu
->language
== language_fortran
8968 && pdi
->die_parent
!= NULL
8969 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8971 /* Normally, only "external" DIEs are part of the global scope.
8972 But in Ada and Fortran, we want to be able to access nested
8973 procedures globally. So all Ada and Fortran subprograms are
8974 stored in the global scope. */
8975 add_psymbol_to_list (actual_name
,
8976 built_actual_name
!= NULL
,
8977 VAR_DOMAIN
, LOC_BLOCK
,
8978 SECT_OFF_TEXT (objfile
),
8979 psymbol_placement::GLOBAL
,
8981 cu
->language
, objfile
);
8985 add_psymbol_to_list (actual_name
,
8986 built_actual_name
!= NULL
,
8987 VAR_DOMAIN
, LOC_BLOCK
,
8988 SECT_OFF_TEXT (objfile
),
8989 psymbol_placement::STATIC
,
8990 addr
, cu
->language
, objfile
);
8993 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8994 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8996 case DW_TAG_constant
:
8997 add_psymbol_to_list (actual_name
,
8998 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8999 -1, (pdi
->is_external
9000 ? psymbol_placement::GLOBAL
9001 : psymbol_placement::STATIC
),
9002 0, cu
->language
, objfile
);
9004 case DW_TAG_variable
:
9006 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9010 && !dwarf2_per_objfile
->has_section_at_zero
)
9012 /* A global or static variable may also have been stripped
9013 out by the linker if unused, in which case its address
9014 will be nullified; do not add such variables into partial
9015 symbol table then. */
9017 else if (pdi
->is_external
)
9020 Don't enter into the minimal symbol tables as there is
9021 a minimal symbol table entry from the ELF symbols already.
9022 Enter into partial symbol table if it has a location
9023 descriptor or a type.
9024 If the location descriptor is missing, new_symbol will create
9025 a LOC_UNRESOLVED symbol, the address of the variable will then
9026 be determined from the minimal symbol table whenever the variable
9028 The address for the partial symbol table entry is not
9029 used by GDB, but it comes in handy for debugging partial symbol
9032 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9033 add_psymbol_to_list (actual_name
,
9034 built_actual_name
!= NULL
,
9035 VAR_DOMAIN
, LOC_STATIC
,
9036 SECT_OFF_TEXT (objfile
),
9037 psymbol_placement::GLOBAL
,
9038 addr
, cu
->language
, objfile
);
9042 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9044 /* Static Variable. Skip symbols whose value we cannot know (those
9045 without location descriptors or constant values). */
9046 if (!has_loc
&& !pdi
->has_const_value
)
9049 add_psymbol_to_list (actual_name
,
9050 built_actual_name
!= NULL
,
9051 VAR_DOMAIN
, LOC_STATIC
,
9052 SECT_OFF_TEXT (objfile
),
9053 psymbol_placement::STATIC
,
9055 cu
->language
, objfile
);
9058 case DW_TAG_typedef
:
9059 case DW_TAG_base_type
:
9060 case DW_TAG_subrange_type
:
9061 add_psymbol_to_list (actual_name
,
9062 built_actual_name
!= NULL
,
9063 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9064 psymbol_placement::STATIC
,
9065 0, cu
->language
, objfile
);
9067 case DW_TAG_imported_declaration
:
9068 case DW_TAG_namespace
:
9069 add_psymbol_to_list (actual_name
,
9070 built_actual_name
!= NULL
,
9071 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9072 psymbol_placement::GLOBAL
,
9073 0, cu
->language
, objfile
);
9076 /* With Fortran 77 there might be a "BLOCK DATA" module
9077 available without any name. If so, we skip the module as it
9078 doesn't bring any value. */
9079 if (actual_name
!= nullptr)
9080 add_psymbol_to_list (actual_name
,
9081 built_actual_name
!= NULL
,
9082 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9083 psymbol_placement::GLOBAL
,
9084 0, cu
->language
, objfile
);
9086 case DW_TAG_class_type
:
9087 case DW_TAG_interface_type
:
9088 case DW_TAG_structure_type
:
9089 case DW_TAG_union_type
:
9090 case DW_TAG_enumeration_type
:
9091 /* Skip external references. The DWARF standard says in the section
9092 about "Structure, Union, and Class Type Entries": "An incomplete
9093 structure, union or class type is represented by a structure,
9094 union or class entry that does not have a byte size attribute
9095 and that has a DW_AT_declaration attribute." */
9096 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9099 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9100 static vs. global. */
9101 add_psymbol_to_list (actual_name
,
9102 built_actual_name
!= NULL
,
9103 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9104 cu
->language
== language_cplus
9105 ? psymbol_placement::GLOBAL
9106 : psymbol_placement::STATIC
,
9107 0, cu
->language
, objfile
);
9110 case DW_TAG_enumerator
:
9111 add_psymbol_to_list (actual_name
,
9112 built_actual_name
!= NULL
,
9113 VAR_DOMAIN
, LOC_CONST
, -1,
9114 cu
->language
== language_cplus
9115 ? psymbol_placement::GLOBAL
9116 : psymbol_placement::STATIC
,
9117 0, cu
->language
, objfile
);
9124 /* Read a partial die corresponding to a namespace; also, add a symbol
9125 corresponding to that namespace to the symbol table. NAMESPACE is
9126 the name of the enclosing namespace. */
9129 add_partial_namespace (struct partial_die_info
*pdi
,
9130 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9131 int set_addrmap
, struct dwarf2_cu
*cu
)
9133 /* Add a symbol for the namespace. */
9135 add_partial_symbol (pdi
, cu
);
9137 /* Now scan partial symbols in that namespace. */
9139 if (pdi
->has_children
)
9140 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9143 /* Read a partial die corresponding to a Fortran module. */
9146 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9147 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9149 /* Add a symbol for the namespace. */
9151 add_partial_symbol (pdi
, cu
);
9153 /* Now scan partial symbols in that module. */
9155 if (pdi
->has_children
)
9156 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9159 /* Read a partial die corresponding to a subprogram or an inlined
9160 subprogram and create a partial symbol for that subprogram.
9161 When the CU language allows it, this routine also defines a partial
9162 symbol for each nested subprogram that this subprogram contains.
9163 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9164 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9166 PDI may also be a lexical block, in which case we simply search
9167 recursively for subprograms defined inside that lexical block.
9168 Again, this is only performed when the CU language allows this
9169 type of definitions. */
9172 add_partial_subprogram (struct partial_die_info
*pdi
,
9173 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9174 int set_addrmap
, struct dwarf2_cu
*cu
)
9176 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9178 if (pdi
->has_pc_info
)
9180 if (pdi
->lowpc
< *lowpc
)
9181 *lowpc
= pdi
->lowpc
;
9182 if (pdi
->highpc
> *highpc
)
9183 *highpc
= pdi
->highpc
;
9186 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9187 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9189 CORE_ADDR this_highpc
;
9190 CORE_ADDR this_lowpc
;
9192 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
9194 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9195 pdi
->lowpc
+ baseaddr
)
9198 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9199 pdi
->highpc
+ baseaddr
)
9201 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9202 this_lowpc
, this_highpc
- 1,
9203 cu
->per_cu
->v
.psymtab
);
9207 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9209 if (!pdi
->is_declaration
)
9210 /* Ignore subprogram DIEs that do not have a name, they are
9211 illegal. Do not emit a complaint at this point, we will
9212 do so when we convert this psymtab into a symtab. */
9214 add_partial_symbol (pdi
, cu
);
9218 if (! pdi
->has_children
)
9221 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9223 pdi
= pdi
->die_child
;
9227 if (pdi
->tag
== DW_TAG_subprogram
9228 || pdi
->tag
== DW_TAG_inlined_subroutine
9229 || pdi
->tag
== DW_TAG_lexical_block
)
9230 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9231 pdi
= pdi
->die_sibling
;
9236 /* Read a partial die corresponding to an enumeration type. */
9239 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9240 struct dwarf2_cu
*cu
)
9242 struct partial_die_info
*pdi
;
9244 if (enum_pdi
->name
!= NULL
)
9245 add_partial_symbol (enum_pdi
, cu
);
9247 pdi
= enum_pdi
->die_child
;
9250 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9251 complaint (_("malformed enumerator DIE ignored"));
9253 add_partial_symbol (pdi
, cu
);
9254 pdi
= pdi
->die_sibling
;
9258 /* Return the initial uleb128 in the die at INFO_PTR. */
9261 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9263 unsigned int bytes_read
;
9265 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9268 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9269 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9271 Return the corresponding abbrev, or NULL if the number is zero (indicating
9272 an empty DIE). In either case *BYTES_READ will be set to the length of
9273 the initial number. */
9275 static struct abbrev_info
*
9276 peek_die_abbrev (const die_reader_specs
&reader
,
9277 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9279 dwarf2_cu
*cu
= reader
.cu
;
9280 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9281 unsigned int abbrev_number
9282 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9284 if (abbrev_number
== 0)
9287 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9290 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9291 " at offset %s [in module %s]"),
9292 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9293 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9299 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9300 Returns a pointer to the end of a series of DIEs, terminated by an empty
9301 DIE. Any children of the skipped DIEs will also be skipped. */
9303 static const gdb_byte
*
9304 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9308 unsigned int bytes_read
;
9309 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9312 return info_ptr
+ bytes_read
;
9314 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9318 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9319 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9320 abbrev corresponding to that skipped uleb128 should be passed in
9321 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9324 static const gdb_byte
*
9325 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9326 struct abbrev_info
*abbrev
)
9328 unsigned int bytes_read
;
9329 struct attribute attr
;
9330 bfd
*abfd
= reader
->abfd
;
9331 struct dwarf2_cu
*cu
= reader
->cu
;
9332 const gdb_byte
*buffer
= reader
->buffer
;
9333 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9334 unsigned int form
, i
;
9336 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9338 /* The only abbrev we care about is DW_AT_sibling. */
9339 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9341 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9342 if (attr
.form
== DW_FORM_ref_addr
)
9343 complaint (_("ignoring absolute DW_AT_sibling"));
9346 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9347 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9349 if (sibling_ptr
< info_ptr
)
9350 complaint (_("DW_AT_sibling points backwards"));
9351 else if (sibling_ptr
> reader
->buffer_end
)
9352 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9358 /* If it isn't DW_AT_sibling, skip this attribute. */
9359 form
= abbrev
->attrs
[i
].form
;
9363 case DW_FORM_ref_addr
:
9364 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9365 and later it is offset sized. */
9366 if (cu
->header
.version
== 2)
9367 info_ptr
+= cu
->header
.addr_size
;
9369 info_ptr
+= cu
->header
.offset_size
;
9371 case DW_FORM_GNU_ref_alt
:
9372 info_ptr
+= cu
->header
.offset_size
;
9375 info_ptr
+= cu
->header
.addr_size
;
9383 case DW_FORM_flag_present
:
9384 case DW_FORM_implicit_const
:
9401 case DW_FORM_ref_sig8
:
9404 case DW_FORM_data16
:
9407 case DW_FORM_string
:
9408 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9409 info_ptr
+= bytes_read
;
9411 case DW_FORM_sec_offset
:
9413 case DW_FORM_GNU_strp_alt
:
9414 info_ptr
+= cu
->header
.offset_size
;
9416 case DW_FORM_exprloc
:
9418 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9419 info_ptr
+= bytes_read
;
9421 case DW_FORM_block1
:
9422 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9424 case DW_FORM_block2
:
9425 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9427 case DW_FORM_block4
:
9428 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9434 case DW_FORM_ref_udata
:
9435 case DW_FORM_GNU_addr_index
:
9436 case DW_FORM_GNU_str_index
:
9437 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9439 case DW_FORM_indirect
:
9440 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9441 info_ptr
+= bytes_read
;
9442 /* We need to continue parsing from here, so just go back to
9444 goto skip_attribute
;
9447 error (_("Dwarf Error: Cannot handle %s "
9448 "in DWARF reader [in module %s]"),
9449 dwarf_form_name (form
),
9450 bfd_get_filename (abfd
));
9454 if (abbrev
->has_children
)
9455 return skip_children (reader
, info_ptr
);
9460 /* Locate ORIG_PDI's sibling.
9461 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9463 static const gdb_byte
*
9464 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9465 struct partial_die_info
*orig_pdi
,
9466 const gdb_byte
*info_ptr
)
9468 /* Do we know the sibling already? */
9470 if (orig_pdi
->sibling
)
9471 return orig_pdi
->sibling
;
9473 /* Are there any children to deal with? */
9475 if (!orig_pdi
->has_children
)
9478 /* Skip the children the long way. */
9480 return skip_children (reader
, info_ptr
);
9483 /* Expand this partial symbol table into a full symbol table. SELF is
9487 dwarf2_read_symtab (struct partial_symtab
*self
,
9488 struct objfile
*objfile
)
9490 struct dwarf2_per_objfile
*dwarf2_per_objfile
9491 = get_dwarf2_per_objfile (objfile
);
9495 warning (_("bug: psymtab for %s is already read in."),
9502 printf_filtered (_("Reading in symbols for %s..."),
9504 gdb_flush (gdb_stdout
);
9507 /* If this psymtab is constructed from a debug-only objfile, the
9508 has_section_at_zero flag will not necessarily be correct. We
9509 can get the correct value for this flag by looking at the data
9510 associated with the (presumably stripped) associated objfile. */
9511 if (objfile
->separate_debug_objfile_backlink
)
9513 struct dwarf2_per_objfile
*dpo_backlink
9514 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9516 dwarf2_per_objfile
->has_section_at_zero
9517 = dpo_backlink
->has_section_at_zero
;
9520 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9522 psymtab_to_symtab_1 (self
);
9524 /* Finish up the debug error message. */
9526 printf_filtered (_("done.\n"));
9529 process_cu_includes (dwarf2_per_objfile
);
9532 /* Reading in full CUs. */
9534 /* Add PER_CU to the queue. */
9537 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9538 enum language pretend_language
)
9540 struct dwarf2_queue_item
*item
;
9543 item
= XNEW (struct dwarf2_queue_item
);
9544 item
->per_cu
= per_cu
;
9545 item
->pretend_language
= pretend_language
;
9548 if (dwarf2_queue
== NULL
)
9549 dwarf2_queue
= item
;
9551 dwarf2_queue_tail
->next
= item
;
9553 dwarf2_queue_tail
= item
;
9556 /* If PER_CU is not yet queued, add it to the queue.
9557 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9559 The result is non-zero if PER_CU was queued, otherwise the result is zero
9560 meaning either PER_CU is already queued or it is already loaded.
9562 N.B. There is an invariant here that if a CU is queued then it is loaded.
9563 The caller is required to load PER_CU if we return non-zero. */
9566 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9567 struct dwarf2_per_cu_data
*per_cu
,
9568 enum language pretend_language
)
9570 /* We may arrive here during partial symbol reading, if we need full
9571 DIEs to process an unusual case (e.g. template arguments). Do
9572 not queue PER_CU, just tell our caller to load its DIEs. */
9573 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9575 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9580 /* Mark the dependence relation so that we don't flush PER_CU
9582 if (dependent_cu
!= NULL
)
9583 dwarf2_add_dependence (dependent_cu
, per_cu
);
9585 /* If it's already on the queue, we have nothing to do. */
9589 /* If the compilation unit is already loaded, just mark it as
9591 if (per_cu
->cu
!= NULL
)
9593 per_cu
->cu
->last_used
= 0;
9597 /* Add it to the queue. */
9598 queue_comp_unit (per_cu
, pretend_language
);
9603 /* Process the queue. */
9606 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9608 struct dwarf2_queue_item
*item
, *next_item
;
9610 if (dwarf_read_debug
)
9612 fprintf_unfiltered (gdb_stdlog
,
9613 "Expanding one or more symtabs of objfile %s ...\n",
9614 objfile_name (dwarf2_per_objfile
->objfile
));
9617 /* The queue starts out with one item, but following a DIE reference
9618 may load a new CU, adding it to the end of the queue. */
9619 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9621 if ((dwarf2_per_objfile
->using_index
9622 ? !item
->per_cu
->v
.quick
->compunit_symtab
9623 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9624 /* Skip dummy CUs. */
9625 && item
->per_cu
->cu
!= NULL
)
9627 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9628 unsigned int debug_print_threshold
;
9631 if (per_cu
->is_debug_types
)
9633 struct signatured_type
*sig_type
=
9634 (struct signatured_type
*) per_cu
;
9636 sprintf (buf
, "TU %s at offset %s",
9637 hex_string (sig_type
->signature
),
9638 sect_offset_str (per_cu
->sect_off
));
9639 /* There can be 100s of TUs.
9640 Only print them in verbose mode. */
9641 debug_print_threshold
= 2;
9645 sprintf (buf
, "CU at offset %s",
9646 sect_offset_str (per_cu
->sect_off
));
9647 debug_print_threshold
= 1;
9650 if (dwarf_read_debug
>= debug_print_threshold
)
9651 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9653 if (per_cu
->is_debug_types
)
9654 process_full_type_unit (per_cu
, item
->pretend_language
);
9656 process_full_comp_unit (per_cu
, item
->pretend_language
);
9658 if (dwarf_read_debug
>= debug_print_threshold
)
9659 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9662 item
->per_cu
->queued
= 0;
9663 next_item
= item
->next
;
9667 dwarf2_queue_tail
= NULL
;
9669 if (dwarf_read_debug
)
9671 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9672 objfile_name (dwarf2_per_objfile
->objfile
));
9676 /* Read in full symbols for PST, and anything it depends on. */
9679 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9681 struct dwarf2_per_cu_data
*per_cu
;
9687 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9688 if (!pst
->dependencies
[i
]->readin
9689 && pst
->dependencies
[i
]->user
== NULL
)
9691 /* Inform about additional files that need to be read in. */
9694 /* FIXME: i18n: Need to make this a single string. */
9695 fputs_filtered (" ", gdb_stdout
);
9697 fputs_filtered ("and ", gdb_stdout
);
9699 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9700 wrap_here (""); /* Flush output. */
9701 gdb_flush (gdb_stdout
);
9703 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9706 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9710 /* It's an include file, no symbols to read for it.
9711 Everything is in the parent symtab. */
9716 dw2_do_instantiate_symtab (per_cu
, false);
9719 /* Trivial hash function for die_info: the hash value of a DIE
9720 is its offset in .debug_info for this objfile. */
9723 die_hash (const void *item
)
9725 const struct die_info
*die
= (const struct die_info
*) item
;
9727 return to_underlying (die
->sect_off
);
9730 /* Trivial comparison function for die_info structures: two DIEs
9731 are equal if they have the same offset. */
9734 die_eq (const void *item_lhs
, const void *item_rhs
)
9736 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9737 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9739 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9742 /* die_reader_func for load_full_comp_unit.
9743 This is identical to read_signatured_type_reader,
9744 but is kept separate for now. */
9747 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9748 const gdb_byte
*info_ptr
,
9749 struct die_info
*comp_unit_die
,
9753 struct dwarf2_cu
*cu
= reader
->cu
;
9754 enum language
*language_ptr
= (enum language
*) data
;
9756 gdb_assert (cu
->die_hash
== NULL
);
9758 htab_create_alloc_ex (cu
->header
.length
/ 12,
9762 &cu
->comp_unit_obstack
,
9763 hashtab_obstack_allocate
,
9764 dummy_obstack_deallocate
);
9767 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9768 &info_ptr
, comp_unit_die
);
9769 cu
->dies
= comp_unit_die
;
9770 /* comp_unit_die is not stored in die_hash, no need. */
9772 /* We try not to read any attributes in this function, because not
9773 all CUs needed for references have been loaded yet, and symbol
9774 table processing isn't initialized. But we have to set the CU language,
9775 or we won't be able to build types correctly.
9776 Similarly, if we do not read the producer, we can not apply
9777 producer-specific interpretation. */
9778 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9781 /* Load the DIEs associated with PER_CU into memory. */
9784 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9786 enum language pretend_language
)
9788 gdb_assert (! this_cu
->is_debug_types
);
9790 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9791 load_full_comp_unit_reader
, &pretend_language
);
9794 /* Add a DIE to the delayed physname list. */
9797 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9798 const char *name
, struct die_info
*die
,
9799 struct dwarf2_cu
*cu
)
9801 struct delayed_method_info mi
;
9803 mi
.fnfield_index
= fnfield_index
;
9807 cu
->method_list
.push_back (mi
);
9810 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9811 "const" / "volatile". If so, decrements LEN by the length of the
9812 modifier and return true. Otherwise return false. */
9816 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9818 size_t mod_len
= sizeof (mod
) - 1;
9819 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9827 /* Compute the physnames of any methods on the CU's method list.
9829 The computation of method physnames is delayed in order to avoid the
9830 (bad) condition that one of the method's formal parameters is of an as yet
9834 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9836 /* Only C++ delays computing physnames. */
9837 if (cu
->method_list
.empty ())
9839 gdb_assert (cu
->language
== language_cplus
);
9841 for (const delayed_method_info
&mi
: cu
->method_list
)
9843 const char *physname
;
9844 struct fn_fieldlist
*fn_flp
9845 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9846 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9847 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9848 = physname
? physname
: "";
9850 /* Since there's no tag to indicate whether a method is a
9851 const/volatile overload, extract that information out of the
9853 if (physname
!= NULL
)
9855 size_t len
= strlen (physname
);
9859 if (physname
[len
] == ')') /* shortcut */
9861 else if (check_modifier (physname
, len
, " const"))
9862 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9863 else if (check_modifier (physname
, len
, " volatile"))
9864 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9871 /* The list is no longer needed. */
9872 cu
->method_list
.clear ();
9875 /* Go objects should be embedded in a DW_TAG_module DIE,
9876 and it's not clear if/how imported objects will appear.
9877 To keep Go support simple until that's worked out,
9878 go back through what we've read and create something usable.
9879 We could do this while processing each DIE, and feels kinda cleaner,
9880 but that way is more invasive.
9881 This is to, for example, allow the user to type "p var" or "b main"
9882 without having to specify the package name, and allow lookups
9883 of module.object to work in contexts that use the expression
9887 fixup_go_packaging (struct dwarf2_cu
*cu
)
9889 gdb::unique_xmalloc_ptr
<char> package_name
;
9890 struct pending
*list
;
9893 for (list
= *cu
->get_builder ()->get_global_symbols ();
9897 for (i
= 0; i
< list
->nsyms
; ++i
)
9899 struct symbol
*sym
= list
->symbol
[i
];
9901 if (sym
->language () == language_go
9902 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9904 gdb::unique_xmalloc_ptr
<char> this_package_name
9905 (go_symbol_package_name (sym
));
9907 if (this_package_name
== NULL
)
9909 if (package_name
== NULL
)
9910 package_name
= std::move (this_package_name
);
9913 struct objfile
*objfile
9914 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9915 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9916 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9917 (symbol_symtab (sym
) != NULL
9918 ? symtab_to_filename_for_display
9919 (symbol_symtab (sym
))
9920 : objfile_name (objfile
)),
9921 this_package_name
.get (), package_name
.get ());
9927 if (package_name
!= NULL
)
9929 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9930 const char *saved_package_name
9931 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9932 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9933 saved_package_name
);
9936 sym
= allocate_symbol (objfile
);
9937 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9938 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9939 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9940 e.g., "main" finds the "main" module and not C's main(). */
9941 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9942 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9943 SYMBOL_TYPE (sym
) = type
;
9945 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9949 /* Allocate a fully-qualified name consisting of the two parts on the
9953 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9955 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9958 /* A helper that allocates a struct discriminant_info to attach to a
9961 static struct discriminant_info
*
9962 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9965 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9966 gdb_assert (discriminant_index
== -1
9967 || (discriminant_index
>= 0
9968 && discriminant_index
< TYPE_NFIELDS (type
)));
9969 gdb_assert (default_index
== -1
9970 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9972 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9974 struct discriminant_info
*disc
9975 = ((struct discriminant_info
*)
9977 offsetof (struct discriminant_info
, discriminants
)
9978 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9979 disc
->default_index
= default_index
;
9980 disc
->discriminant_index
= discriminant_index
;
9982 struct dynamic_prop prop
;
9983 prop
.kind
= PROP_UNDEFINED
;
9984 prop
.data
.baton
= disc
;
9986 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9991 /* Some versions of rustc emitted enums in an unusual way.
9993 Ordinary enums were emitted as unions. The first element of each
9994 structure in the union was named "RUST$ENUM$DISR". This element
9995 held the discriminant.
9997 These versions of Rust also implemented the "non-zero"
9998 optimization. When the enum had two values, and one is empty and
9999 the other holds a pointer that cannot be zero, the pointer is used
10000 as the discriminant, with a zero value meaning the empty variant.
10001 Here, the union's first member is of the form
10002 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
10003 where the fieldnos are the indices of the fields that should be
10004 traversed in order to find the field (which may be several fields deep)
10005 and the variantname is the name of the variant of the case when the
10008 This function recognizes whether TYPE is of one of these forms,
10009 and, if so, smashes it to be a variant type. */
10012 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
10014 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10016 /* We don't need to deal with empty enums. */
10017 if (TYPE_NFIELDS (type
) == 0)
10020 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
10021 if (TYPE_NFIELDS (type
) == 1
10022 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
10024 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10026 /* Decode the field name to find the offset of the
10028 ULONGEST bit_offset
= 0;
10029 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10030 while (name
[0] >= '0' && name
[0] <= '9')
10033 unsigned long index
= strtoul (name
, &tail
, 10);
10036 || index
>= TYPE_NFIELDS (field_type
)
10037 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10038 != FIELD_LOC_KIND_BITPOS
))
10040 complaint (_("Could not parse Rust enum encoding string \"%s\""
10042 TYPE_FIELD_NAME (type
, 0),
10043 objfile_name (objfile
));
10048 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10049 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10052 /* Make a union to hold the variants. */
10053 struct type
*union_type
= alloc_type (objfile
);
10054 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10055 TYPE_NFIELDS (union_type
) = 3;
10056 TYPE_FIELDS (union_type
)
10057 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10058 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10059 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10061 /* Put the discriminant must at index 0. */
10062 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10063 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10064 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10065 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10067 /* The order of fields doesn't really matter, so put the real
10068 field at index 1 and the data-less field at index 2. */
10069 struct discriminant_info
*disc
10070 = alloc_discriminant_info (union_type
, 0, 1);
10071 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10072 TYPE_FIELD_NAME (union_type
, 1)
10073 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10074 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10075 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10076 TYPE_FIELD_NAME (union_type
, 1));
10078 const char *dataless_name
10079 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10081 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10083 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10084 /* NAME points into the original discriminant name, which
10085 already has the correct lifetime. */
10086 TYPE_FIELD_NAME (union_type
, 2) = name
;
10087 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10088 disc
->discriminants
[2] = 0;
10090 /* Smash this type to be a structure type. We have to do this
10091 because the type has already been recorded. */
10092 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10093 TYPE_NFIELDS (type
) = 1;
10095 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10097 /* Install the variant part. */
10098 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10099 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10100 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10102 /* A union with a single anonymous field is probably an old-style
10103 univariant enum. */
10104 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10106 /* Smash this type to be a structure type. We have to do this
10107 because the type has already been recorded. */
10108 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10110 /* Make a union to hold the variants. */
10111 struct type
*union_type
= alloc_type (objfile
);
10112 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10113 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10114 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10115 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10116 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10118 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10119 const char *variant_name
10120 = rust_last_path_segment (TYPE_NAME (field_type
));
10121 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10122 TYPE_NAME (field_type
)
10123 = rust_fully_qualify (&objfile
->objfile_obstack
,
10124 TYPE_NAME (type
), variant_name
);
10126 /* Install the union in the outer struct type. */
10127 TYPE_NFIELDS (type
) = 1;
10129 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10130 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10131 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10132 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10134 alloc_discriminant_info (union_type
, -1, 0);
10138 struct type
*disr_type
= nullptr;
10139 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10141 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10143 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10145 /* All fields of a true enum will be structs. */
10148 else if (TYPE_NFIELDS (disr_type
) == 0)
10150 /* Could be data-less variant, so keep going. */
10151 disr_type
= nullptr;
10153 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10154 "RUST$ENUM$DISR") != 0)
10156 /* Not a Rust enum. */
10166 /* If we got here without a discriminant, then it's probably
10168 if (disr_type
== nullptr)
10171 /* Smash this type to be a structure type. We have to do this
10172 because the type has already been recorded. */
10173 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10175 /* Make a union to hold the variants. */
10176 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10177 struct type
*union_type
= alloc_type (objfile
);
10178 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10179 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10180 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10181 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10182 TYPE_FIELDS (union_type
)
10183 = (struct field
*) TYPE_ZALLOC (union_type
,
10184 (TYPE_NFIELDS (union_type
)
10185 * sizeof (struct field
)));
10187 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10188 TYPE_NFIELDS (type
) * sizeof (struct field
));
10190 /* Install the discriminant at index 0 in the union. */
10191 TYPE_FIELD (union_type
, 0) = *disr_field
;
10192 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10193 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10195 /* Install the union in the outer struct type. */
10196 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10197 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10198 TYPE_NFIELDS (type
) = 1;
10200 /* Set the size and offset of the union type. */
10201 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10203 /* We need a way to find the correct discriminant given a
10204 variant name. For convenience we build a map here. */
10205 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10206 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10207 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10209 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10212 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10213 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10217 int n_fields
= TYPE_NFIELDS (union_type
);
10218 struct discriminant_info
*disc
10219 = alloc_discriminant_info (union_type
, 0, -1);
10220 /* Skip the discriminant here. */
10221 for (int i
= 1; i
< n_fields
; ++i
)
10223 /* Find the final word in the name of this variant's type.
10224 That name can be used to look up the correct
10226 const char *variant_name
10227 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10230 auto iter
= discriminant_map
.find (variant_name
);
10231 if (iter
!= discriminant_map
.end ())
10232 disc
->discriminants
[i
] = iter
->second
;
10234 /* Remove the discriminant field, if it exists. */
10235 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10236 if (TYPE_NFIELDS (sub_type
) > 0)
10238 --TYPE_NFIELDS (sub_type
);
10239 ++TYPE_FIELDS (sub_type
);
10241 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10242 TYPE_NAME (sub_type
)
10243 = rust_fully_qualify (&objfile
->objfile_obstack
,
10244 TYPE_NAME (type
), variant_name
);
10249 /* Rewrite some Rust unions to be structures with variants parts. */
10252 rust_union_quirks (struct dwarf2_cu
*cu
)
10254 gdb_assert (cu
->language
== language_rust
);
10255 for (type
*type_
: cu
->rust_unions
)
10256 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10257 /* We don't need this any more. */
10258 cu
->rust_unions
.clear ();
10261 /* Return the symtab for PER_CU. This works properly regardless of
10262 whether we're using the index or psymtabs. */
10264 static struct compunit_symtab
*
10265 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10267 return (per_cu
->dwarf2_per_objfile
->using_index
10268 ? per_cu
->v
.quick
->compunit_symtab
10269 : per_cu
->v
.psymtab
->compunit_symtab
);
10272 /* A helper function for computing the list of all symbol tables
10273 included by PER_CU. */
10276 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10277 htab_t all_children
, htab_t all_type_symtabs
,
10278 struct dwarf2_per_cu_data
*per_cu
,
10279 struct compunit_symtab
*immediate_parent
)
10282 struct compunit_symtab
*cust
;
10284 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10287 /* This inclusion and its children have been processed. */
10292 /* Only add a CU if it has a symbol table. */
10293 cust
= get_compunit_symtab (per_cu
);
10296 /* If this is a type unit only add its symbol table if we haven't
10297 seen it yet (type unit per_cu's can share symtabs). */
10298 if (per_cu
->is_debug_types
)
10300 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10304 result
->push_back (cust
);
10305 if (cust
->user
== NULL
)
10306 cust
->user
= immediate_parent
;
10311 result
->push_back (cust
);
10312 if (cust
->user
== NULL
)
10313 cust
->user
= immediate_parent
;
10317 if (!per_cu
->imported_symtabs_empty ())
10318 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10320 recursively_compute_inclusions (result
, all_children
,
10321 all_type_symtabs
, ptr
, cust
);
10325 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10329 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10331 gdb_assert (! per_cu
->is_debug_types
);
10333 if (!per_cu
->imported_symtabs_empty ())
10336 std::vector
<compunit_symtab
*> result_symtabs
;
10337 htab_t all_children
, all_type_symtabs
;
10338 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10340 /* If we don't have a symtab, we can just skip this case. */
10344 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10345 NULL
, xcalloc
, xfree
);
10346 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10347 NULL
, xcalloc
, xfree
);
10349 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10351 recursively_compute_inclusions (&result_symtabs
, all_children
,
10352 all_type_symtabs
, ptr
, cust
);
10355 /* Now we have a transitive closure of all the included symtabs. */
10356 len
= result_symtabs
.size ();
10358 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10359 struct compunit_symtab
*, len
+ 1);
10360 memcpy (cust
->includes
, result_symtabs
.data (),
10361 len
* sizeof (compunit_symtab
*));
10362 cust
->includes
[len
] = NULL
;
10364 htab_delete (all_children
);
10365 htab_delete (all_type_symtabs
);
10369 /* Compute the 'includes' field for the symtabs of all the CUs we just
10373 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10375 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10377 if (! iter
->is_debug_types
)
10378 compute_compunit_symtab_includes (iter
);
10381 dwarf2_per_objfile
->just_read_cus
.clear ();
10384 /* Generate full symbol information for PER_CU, whose DIEs have
10385 already been loaded into memory. */
10388 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10389 enum language pretend_language
)
10391 struct dwarf2_cu
*cu
= per_cu
->cu
;
10392 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10393 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10394 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10395 CORE_ADDR lowpc
, highpc
;
10396 struct compunit_symtab
*cust
;
10397 CORE_ADDR baseaddr
;
10398 struct block
*static_block
;
10401 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
10403 /* Clear the list here in case something was left over. */
10404 cu
->method_list
.clear ();
10406 cu
->language
= pretend_language
;
10407 cu
->language_defn
= language_def (cu
->language
);
10409 /* Do line number decoding in read_file_scope () */
10410 process_die (cu
->dies
, cu
);
10412 /* For now fudge the Go package. */
10413 if (cu
->language
== language_go
)
10414 fixup_go_packaging (cu
);
10416 /* Now that we have processed all the DIEs in the CU, all the types
10417 should be complete, and it should now be safe to compute all of the
10419 compute_delayed_physnames (cu
);
10421 if (cu
->language
== language_rust
)
10422 rust_union_quirks (cu
);
10424 /* Some compilers don't define a DW_AT_high_pc attribute for the
10425 compilation unit. If the DW_AT_high_pc is missing, synthesize
10426 it, by scanning the DIE's below the compilation unit. */
10427 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10429 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10430 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10432 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10433 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10434 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10435 addrmap to help ensure it has an accurate map of pc values belonging to
10437 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10439 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10440 SECT_OFF_TEXT (objfile
),
10445 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10447 /* Set symtab language to language from DW_AT_language. If the
10448 compilation is from a C file generated by language preprocessors, do
10449 not set the language if it was already deduced by start_subfile. */
10450 if (!(cu
->language
== language_c
10451 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10452 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10454 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10455 produce DW_AT_location with location lists but it can be possibly
10456 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10457 there were bugs in prologue debug info, fixed later in GCC-4.5
10458 by "unwind info for epilogues" patch (which is not directly related).
10460 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10461 needed, it would be wrong due to missing DW_AT_producer there.
10463 Still one can confuse GDB by using non-standard GCC compilation
10464 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10466 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10467 cust
->locations_valid
= 1;
10469 if (gcc_4_minor
>= 5)
10470 cust
->epilogue_unwind_valid
= 1;
10472 cust
->call_site_htab
= cu
->call_site_htab
;
10475 if (dwarf2_per_objfile
->using_index
)
10476 per_cu
->v
.quick
->compunit_symtab
= cust
;
10479 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10480 pst
->compunit_symtab
= cust
;
10484 /* Push it for inclusion processing later. */
10485 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10487 /* Not needed any more. */
10488 cu
->reset_builder ();
10491 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10492 already been loaded into memory. */
10495 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10496 enum language pretend_language
)
10498 struct dwarf2_cu
*cu
= per_cu
->cu
;
10499 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10500 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10501 struct compunit_symtab
*cust
;
10502 struct signatured_type
*sig_type
;
10504 gdb_assert (per_cu
->is_debug_types
);
10505 sig_type
= (struct signatured_type
*) per_cu
;
10507 /* Clear the list here in case something was left over. */
10508 cu
->method_list
.clear ();
10510 cu
->language
= pretend_language
;
10511 cu
->language_defn
= language_def (cu
->language
);
10513 /* The symbol tables are set up in read_type_unit_scope. */
10514 process_die (cu
->dies
, cu
);
10516 /* For now fudge the Go package. */
10517 if (cu
->language
== language_go
)
10518 fixup_go_packaging (cu
);
10520 /* Now that we have processed all the DIEs in the CU, all the types
10521 should be complete, and it should now be safe to compute all of the
10523 compute_delayed_physnames (cu
);
10525 if (cu
->language
== language_rust
)
10526 rust_union_quirks (cu
);
10528 /* TUs share symbol tables.
10529 If this is the first TU to use this symtab, complete the construction
10530 of it with end_expandable_symtab. Otherwise, complete the addition of
10531 this TU's symbols to the existing symtab. */
10532 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10534 buildsym_compunit
*builder
= cu
->get_builder ();
10535 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10536 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10540 /* Set symtab language to language from DW_AT_language. If the
10541 compilation is from a C file generated by language preprocessors,
10542 do not set the language if it was already deduced by
10544 if (!(cu
->language
== language_c
10545 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10546 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10551 cu
->get_builder ()->augment_type_symtab ();
10552 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10555 if (dwarf2_per_objfile
->using_index
)
10556 per_cu
->v
.quick
->compunit_symtab
= cust
;
10559 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10560 pst
->compunit_symtab
= cust
;
10564 /* Not needed any more. */
10565 cu
->reset_builder ();
10568 /* Process an imported unit DIE. */
10571 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10573 struct attribute
*attr
;
10575 /* For now we don't handle imported units in type units. */
10576 if (cu
->per_cu
->is_debug_types
)
10578 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10579 " supported in type units [in module %s]"),
10580 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10583 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10586 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10587 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10588 dwarf2_per_cu_data
*per_cu
10589 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10590 cu
->per_cu
->dwarf2_per_objfile
);
10592 /* If necessary, add it to the queue and load its DIEs. */
10593 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10594 load_full_comp_unit (per_cu
, false, cu
->language
);
10596 cu
->per_cu
->imported_symtabs_push (per_cu
);
10600 /* RAII object that represents a process_die scope: i.e.,
10601 starts/finishes processing a DIE. */
10602 class process_die_scope
10605 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10606 : m_die (die
), m_cu (cu
)
10608 /* We should only be processing DIEs not already in process. */
10609 gdb_assert (!m_die
->in_process
);
10610 m_die
->in_process
= true;
10613 ~process_die_scope ()
10615 m_die
->in_process
= false;
10617 /* If we're done processing the DIE for the CU that owns the line
10618 header, we don't need the line header anymore. */
10619 if (m_cu
->line_header_die_owner
== m_die
)
10621 delete m_cu
->line_header
;
10622 m_cu
->line_header
= NULL
;
10623 m_cu
->line_header_die_owner
= NULL
;
10632 /* Process a die and its children. */
10635 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10637 process_die_scope
scope (die
, cu
);
10641 case DW_TAG_padding
:
10643 case DW_TAG_compile_unit
:
10644 case DW_TAG_partial_unit
:
10645 read_file_scope (die
, cu
);
10647 case DW_TAG_type_unit
:
10648 read_type_unit_scope (die
, cu
);
10650 case DW_TAG_subprogram
:
10651 /* Nested subprograms in Fortran get a prefix. */
10652 if (cu
->language
== language_fortran
10653 && die
->parent
!= NULL
10654 && die
->parent
->tag
== DW_TAG_subprogram
)
10655 cu
->processing_has_namespace_info
= true;
10656 /* Fall through. */
10657 case DW_TAG_inlined_subroutine
:
10658 read_func_scope (die
, cu
);
10660 case DW_TAG_lexical_block
:
10661 case DW_TAG_try_block
:
10662 case DW_TAG_catch_block
:
10663 read_lexical_block_scope (die
, cu
);
10665 case DW_TAG_call_site
:
10666 case DW_TAG_GNU_call_site
:
10667 read_call_site_scope (die
, cu
);
10669 case DW_TAG_class_type
:
10670 case DW_TAG_interface_type
:
10671 case DW_TAG_structure_type
:
10672 case DW_TAG_union_type
:
10673 process_structure_scope (die
, cu
);
10675 case DW_TAG_enumeration_type
:
10676 process_enumeration_scope (die
, cu
);
10679 /* These dies have a type, but processing them does not create
10680 a symbol or recurse to process the children. Therefore we can
10681 read them on-demand through read_type_die. */
10682 case DW_TAG_subroutine_type
:
10683 case DW_TAG_set_type
:
10684 case DW_TAG_array_type
:
10685 case DW_TAG_pointer_type
:
10686 case DW_TAG_ptr_to_member_type
:
10687 case DW_TAG_reference_type
:
10688 case DW_TAG_rvalue_reference_type
:
10689 case DW_TAG_string_type
:
10692 case DW_TAG_base_type
:
10693 case DW_TAG_subrange_type
:
10694 case DW_TAG_typedef
:
10695 /* Add a typedef symbol for the type definition, if it has a
10697 new_symbol (die
, read_type_die (die
, cu
), cu
);
10699 case DW_TAG_common_block
:
10700 read_common_block (die
, cu
);
10702 case DW_TAG_common_inclusion
:
10704 case DW_TAG_namespace
:
10705 cu
->processing_has_namespace_info
= true;
10706 read_namespace (die
, cu
);
10708 case DW_TAG_module
:
10709 cu
->processing_has_namespace_info
= true;
10710 read_module (die
, cu
);
10712 case DW_TAG_imported_declaration
:
10713 cu
->processing_has_namespace_info
= true;
10714 if (read_namespace_alias (die
, cu
))
10716 /* The declaration is not a global namespace alias. */
10717 /* Fall through. */
10718 case DW_TAG_imported_module
:
10719 cu
->processing_has_namespace_info
= true;
10720 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10721 || cu
->language
!= language_fortran
))
10722 complaint (_("Tag '%s' has unexpected children"),
10723 dwarf_tag_name (die
->tag
));
10724 read_import_statement (die
, cu
);
10727 case DW_TAG_imported_unit
:
10728 process_imported_unit_die (die
, cu
);
10731 case DW_TAG_variable
:
10732 read_variable (die
, cu
);
10736 new_symbol (die
, NULL
, cu
);
10741 /* DWARF name computation. */
10743 /* A helper function for dwarf2_compute_name which determines whether DIE
10744 needs to have the name of the scope prepended to the name listed in the
10748 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10750 struct attribute
*attr
;
10754 case DW_TAG_namespace
:
10755 case DW_TAG_typedef
:
10756 case DW_TAG_class_type
:
10757 case DW_TAG_interface_type
:
10758 case DW_TAG_structure_type
:
10759 case DW_TAG_union_type
:
10760 case DW_TAG_enumeration_type
:
10761 case DW_TAG_enumerator
:
10762 case DW_TAG_subprogram
:
10763 case DW_TAG_inlined_subroutine
:
10764 case DW_TAG_member
:
10765 case DW_TAG_imported_declaration
:
10768 case DW_TAG_variable
:
10769 case DW_TAG_constant
:
10770 /* We only need to prefix "globally" visible variables. These include
10771 any variable marked with DW_AT_external or any variable that
10772 lives in a namespace. [Variables in anonymous namespaces
10773 require prefixing, but they are not DW_AT_external.] */
10775 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10777 struct dwarf2_cu
*spec_cu
= cu
;
10779 return die_needs_namespace (die_specification (die
, &spec_cu
),
10783 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10784 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10785 && die
->parent
->tag
!= DW_TAG_module
)
10787 /* A variable in a lexical block of some kind does not need a
10788 namespace, even though in C++ such variables may be external
10789 and have a mangled name. */
10790 if (die
->parent
->tag
== DW_TAG_lexical_block
10791 || die
->parent
->tag
== DW_TAG_try_block
10792 || die
->parent
->tag
== DW_TAG_catch_block
10793 || die
->parent
->tag
== DW_TAG_subprogram
)
10802 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10803 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10804 defined for the given DIE. */
10806 static struct attribute
*
10807 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10809 struct attribute
*attr
;
10811 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10813 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10818 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10819 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10820 defined for the given DIE. */
10822 static const char *
10823 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10825 const char *linkage_name
;
10827 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10828 if (linkage_name
== NULL
)
10829 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10831 return linkage_name
;
10834 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10835 compute the physname for the object, which include a method's:
10836 - formal parameters (C++),
10837 - receiver type (Go),
10839 The term "physname" is a bit confusing.
10840 For C++, for example, it is the demangled name.
10841 For Go, for example, it's the mangled name.
10843 For Ada, return the DIE's linkage name rather than the fully qualified
10844 name. PHYSNAME is ignored..
10846 The result is allocated on the objfile_obstack and canonicalized. */
10848 static const char *
10849 dwarf2_compute_name (const char *name
,
10850 struct die_info
*die
, struct dwarf2_cu
*cu
,
10853 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10856 name
= dwarf2_name (die
, cu
);
10858 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10859 but otherwise compute it by typename_concat inside GDB.
10860 FIXME: Actually this is not really true, or at least not always true.
10861 It's all very confusing. compute_and_set_names doesn't try to demangle
10862 Fortran names because there is no mangling standard. So new_symbol
10863 will set the demangled name to the result of dwarf2_full_name, and it is
10864 the demangled name that GDB uses if it exists. */
10865 if (cu
->language
== language_ada
10866 || (cu
->language
== language_fortran
&& physname
))
10868 /* For Ada unit, we prefer the linkage name over the name, as
10869 the former contains the exported name, which the user expects
10870 to be able to reference. Ideally, we want the user to be able
10871 to reference this entity using either natural or linkage name,
10872 but we haven't started looking at this enhancement yet. */
10873 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10875 if (linkage_name
!= NULL
)
10876 return linkage_name
;
10879 /* These are the only languages we know how to qualify names in. */
10881 && (cu
->language
== language_cplus
10882 || cu
->language
== language_fortran
|| cu
->language
== language_d
10883 || cu
->language
== language_rust
))
10885 if (die_needs_namespace (die
, cu
))
10887 const char *prefix
;
10888 const char *canonical_name
= NULL
;
10892 prefix
= determine_prefix (die
, cu
);
10893 if (*prefix
!= '\0')
10895 gdb::unique_xmalloc_ptr
<char> prefixed_name
10896 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10898 buf
.puts (prefixed_name
.get ());
10903 /* Template parameters may be specified in the DIE's DW_AT_name, or
10904 as children with DW_TAG_template_type_param or
10905 DW_TAG_value_type_param. If the latter, add them to the name
10906 here. If the name already has template parameters, then
10907 skip this step; some versions of GCC emit both, and
10908 it is more efficient to use the pre-computed name.
10910 Something to keep in mind about this process: it is very
10911 unlikely, or in some cases downright impossible, to produce
10912 something that will match the mangled name of a function.
10913 If the definition of the function has the same debug info,
10914 we should be able to match up with it anyway. But fallbacks
10915 using the minimal symbol, for instance to find a method
10916 implemented in a stripped copy of libstdc++, will not work.
10917 If we do not have debug info for the definition, we will have to
10918 match them up some other way.
10920 When we do name matching there is a related problem with function
10921 templates; two instantiated function templates are allowed to
10922 differ only by their return types, which we do not add here. */
10924 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10926 struct attribute
*attr
;
10927 struct die_info
*child
;
10930 die
->building_fullname
= 1;
10932 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10936 const gdb_byte
*bytes
;
10937 struct dwarf2_locexpr_baton
*baton
;
10940 if (child
->tag
!= DW_TAG_template_type_param
10941 && child
->tag
!= DW_TAG_template_value_param
)
10952 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10955 complaint (_("template parameter missing DW_AT_type"));
10956 buf
.puts ("UNKNOWN_TYPE");
10959 type
= die_type (child
, cu
);
10961 if (child
->tag
== DW_TAG_template_type_param
)
10963 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10964 &type_print_raw_options
);
10968 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10971 complaint (_("template parameter missing "
10972 "DW_AT_const_value"));
10973 buf
.puts ("UNKNOWN_VALUE");
10977 dwarf2_const_value_attr (attr
, type
, name
,
10978 &cu
->comp_unit_obstack
, cu
,
10979 &value
, &bytes
, &baton
);
10981 if (TYPE_NOSIGN (type
))
10982 /* GDB prints characters as NUMBER 'CHAR'. If that's
10983 changed, this can use value_print instead. */
10984 c_printchar (value
, type
, &buf
);
10987 struct value_print_options opts
;
10990 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10994 else if (bytes
!= NULL
)
10996 v
= allocate_value (type
);
10997 memcpy (value_contents_writeable (v
), bytes
,
10998 TYPE_LENGTH (type
));
11001 v
= value_from_longest (type
, value
);
11003 /* Specify decimal so that we do not depend on
11005 get_formatted_print_options (&opts
, 'd');
11007 value_print (v
, &buf
, &opts
);
11012 die
->building_fullname
= 0;
11016 /* Close the argument list, with a space if necessary
11017 (nested templates). */
11018 if (!buf
.empty () && buf
.string ().back () == '>')
11025 /* For C++ methods, append formal parameter type
11026 information, if PHYSNAME. */
11028 if (physname
&& die
->tag
== DW_TAG_subprogram
11029 && cu
->language
== language_cplus
)
11031 struct type
*type
= read_type_die (die
, cu
);
11033 c_type_print_args (type
, &buf
, 1, cu
->language
,
11034 &type_print_raw_options
);
11036 if (cu
->language
== language_cplus
)
11038 /* Assume that an artificial first parameter is
11039 "this", but do not crash if it is not. RealView
11040 marks unnamed (and thus unused) parameters as
11041 artificial; there is no way to differentiate
11043 if (TYPE_NFIELDS (type
) > 0
11044 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11045 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11046 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11048 buf
.puts (" const");
11052 const std::string
&intermediate_name
= buf
.string ();
11054 if (cu
->language
== language_cplus
)
11056 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11057 &objfile
->per_bfd
->storage_obstack
);
11059 /* If we only computed INTERMEDIATE_NAME, or if
11060 INTERMEDIATE_NAME is already canonical, then we need to
11061 copy it to the appropriate obstack. */
11062 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11063 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11064 intermediate_name
);
11066 name
= canonical_name
;
11073 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11074 If scope qualifiers are appropriate they will be added. The result
11075 will be allocated on the storage_obstack, or NULL if the DIE does
11076 not have a name. NAME may either be from a previous call to
11077 dwarf2_name or NULL.
11079 The output string will be canonicalized (if C++). */
11081 static const char *
11082 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11084 return dwarf2_compute_name (name
, die
, cu
, 0);
11087 /* Construct a physname for the given DIE in CU. NAME may either be
11088 from a previous call to dwarf2_name or NULL. The result will be
11089 allocated on the objfile_objstack or NULL if the DIE does not have a
11092 The output string will be canonicalized (if C++). */
11094 static const char *
11095 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11097 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11098 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11101 /* In this case dwarf2_compute_name is just a shortcut not building anything
11103 if (!die_needs_namespace (die
, cu
))
11104 return dwarf2_compute_name (name
, die
, cu
, 1);
11106 mangled
= dw2_linkage_name (die
, cu
);
11108 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11109 See https://github.com/rust-lang/rust/issues/32925. */
11110 if (cu
->language
== language_rust
&& mangled
!= NULL
11111 && strchr (mangled
, '{') != NULL
)
11114 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11116 gdb::unique_xmalloc_ptr
<char> demangled
;
11117 if (mangled
!= NULL
)
11120 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11122 /* Do nothing (do not demangle the symbol name). */
11124 else if (cu
->language
== language_go
)
11126 /* This is a lie, but we already lie to the caller new_symbol.
11127 new_symbol assumes we return the mangled name.
11128 This just undoes that lie until things are cleaned up. */
11132 /* Use DMGL_RET_DROP for C++ template functions to suppress
11133 their return type. It is easier for GDB users to search
11134 for such functions as `name(params)' than `long name(params)'.
11135 In such case the minimal symbol names do not match the full
11136 symbol names but for template functions there is never a need
11137 to look up their definition from their declaration so
11138 the only disadvantage remains the minimal symbol variant
11139 `long name(params)' does not have the proper inferior type. */
11140 demangled
.reset (gdb_demangle (mangled
,
11141 (DMGL_PARAMS
| DMGL_ANSI
11142 | DMGL_RET_DROP
)));
11145 canon
= demangled
.get ();
11153 if (canon
== NULL
|| check_physname
)
11155 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11157 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11159 /* It may not mean a bug in GDB. The compiler could also
11160 compute DW_AT_linkage_name incorrectly. But in such case
11161 GDB would need to be bug-to-bug compatible. */
11163 complaint (_("Computed physname <%s> does not match demangled <%s> "
11164 "(from linkage <%s>) - DIE at %s [in module %s]"),
11165 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11166 objfile_name (objfile
));
11168 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11169 is available here - over computed PHYSNAME. It is safer
11170 against both buggy GDB and buggy compilers. */
11184 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11189 /* Inspect DIE in CU for a namespace alias. If one exists, record
11190 a new symbol for it.
11192 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11195 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11197 struct attribute
*attr
;
11199 /* If the die does not have a name, this is not a namespace
11201 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11205 struct die_info
*d
= die
;
11206 struct dwarf2_cu
*imported_cu
= cu
;
11208 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11209 keep inspecting DIEs until we hit the underlying import. */
11210 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11211 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11213 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11217 d
= follow_die_ref (d
, attr
, &imported_cu
);
11218 if (d
->tag
!= DW_TAG_imported_declaration
)
11222 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11224 complaint (_("DIE at %s has too many recursively imported "
11225 "declarations"), sect_offset_str (d
->sect_off
));
11232 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11234 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11235 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11237 /* This declaration is a global namespace alias. Add
11238 a symbol for it whose type is the aliased namespace. */
11239 new_symbol (die
, type
, cu
);
11248 /* Return the using directives repository (global or local?) to use in the
11249 current context for CU.
11251 For Ada, imported declarations can materialize renamings, which *may* be
11252 global. However it is impossible (for now?) in DWARF to distinguish
11253 "external" imported declarations and "static" ones. As all imported
11254 declarations seem to be static in all other languages, make them all CU-wide
11255 global only in Ada. */
11257 static struct using_direct
**
11258 using_directives (struct dwarf2_cu
*cu
)
11260 if (cu
->language
== language_ada
11261 && cu
->get_builder ()->outermost_context_p ())
11262 return cu
->get_builder ()->get_global_using_directives ();
11264 return cu
->get_builder ()->get_local_using_directives ();
11267 /* Read the import statement specified by the given die and record it. */
11270 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11272 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11273 struct attribute
*import_attr
;
11274 struct die_info
*imported_die
, *child_die
;
11275 struct dwarf2_cu
*imported_cu
;
11276 const char *imported_name
;
11277 const char *imported_name_prefix
;
11278 const char *canonical_name
;
11279 const char *import_alias
;
11280 const char *imported_declaration
= NULL
;
11281 const char *import_prefix
;
11282 std::vector
<const char *> excludes
;
11284 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11285 if (import_attr
== NULL
)
11287 complaint (_("Tag '%s' has no DW_AT_import"),
11288 dwarf_tag_name (die
->tag
));
11293 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11294 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11295 if (imported_name
== NULL
)
11297 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11299 The import in the following code:
11313 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11314 <52> DW_AT_decl_file : 1
11315 <53> DW_AT_decl_line : 6
11316 <54> DW_AT_import : <0x75>
11317 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11318 <59> DW_AT_name : B
11319 <5b> DW_AT_decl_file : 1
11320 <5c> DW_AT_decl_line : 2
11321 <5d> DW_AT_type : <0x6e>
11323 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11324 <76> DW_AT_byte_size : 4
11325 <77> DW_AT_encoding : 5 (signed)
11327 imports the wrong die ( 0x75 instead of 0x58 ).
11328 This case will be ignored until the gcc bug is fixed. */
11332 /* Figure out the local name after import. */
11333 import_alias
= dwarf2_name (die
, cu
);
11335 /* Figure out where the statement is being imported to. */
11336 import_prefix
= determine_prefix (die
, cu
);
11338 /* Figure out what the scope of the imported die is and prepend it
11339 to the name of the imported die. */
11340 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11342 if (imported_die
->tag
!= DW_TAG_namespace
11343 && imported_die
->tag
!= DW_TAG_module
)
11345 imported_declaration
= imported_name
;
11346 canonical_name
= imported_name_prefix
;
11348 else if (strlen (imported_name_prefix
) > 0)
11349 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11350 imported_name_prefix
,
11351 (cu
->language
== language_d
? "." : "::"),
11352 imported_name
, (char *) NULL
);
11354 canonical_name
= imported_name
;
11356 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11357 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11358 child_die
= sibling_die (child_die
))
11360 /* DWARF-4: A Fortran use statement with a “rename list” may be
11361 represented by an imported module entry with an import attribute
11362 referring to the module and owned entries corresponding to those
11363 entities that are renamed as part of being imported. */
11365 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11367 complaint (_("child DW_TAG_imported_declaration expected "
11368 "- DIE at %s [in module %s]"),
11369 sect_offset_str (child_die
->sect_off
),
11370 objfile_name (objfile
));
11374 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11375 if (import_attr
== NULL
)
11377 complaint (_("Tag '%s' has no DW_AT_import"),
11378 dwarf_tag_name (child_die
->tag
));
11383 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11385 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11386 if (imported_name
== NULL
)
11388 complaint (_("child DW_TAG_imported_declaration has unknown "
11389 "imported name - DIE at %s [in module %s]"),
11390 sect_offset_str (child_die
->sect_off
),
11391 objfile_name (objfile
));
11395 excludes
.push_back (imported_name
);
11397 process_die (child_die
, cu
);
11400 add_using_directive (using_directives (cu
),
11404 imported_declaration
,
11407 &objfile
->objfile_obstack
);
11410 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11411 types, but gives them a size of zero. Starting with version 14,
11412 ICC is compatible with GCC. */
11415 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11417 if (!cu
->checked_producer
)
11418 check_producer (cu
);
11420 return cu
->producer_is_icc_lt_14
;
11423 /* ICC generates a DW_AT_type for C void functions. This was observed on
11424 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11425 which says that void functions should not have a DW_AT_type. */
11428 producer_is_icc (struct dwarf2_cu
*cu
)
11430 if (!cu
->checked_producer
)
11431 check_producer (cu
);
11433 return cu
->producer_is_icc
;
11436 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11437 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11438 this, it was first present in GCC release 4.3.0. */
11441 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11443 if (!cu
->checked_producer
)
11444 check_producer (cu
);
11446 return cu
->producer_is_gcc_lt_4_3
;
11449 static file_and_directory
11450 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11452 file_and_directory res
;
11454 /* Find the filename. Do not use dwarf2_name here, since the filename
11455 is not a source language identifier. */
11456 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11457 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11459 if (res
.comp_dir
== NULL
11460 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11461 && IS_ABSOLUTE_PATH (res
.name
))
11463 res
.comp_dir_storage
= ldirname (res
.name
);
11464 if (!res
.comp_dir_storage
.empty ())
11465 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11467 if (res
.comp_dir
!= NULL
)
11469 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11470 directory, get rid of it. */
11471 const char *cp
= strchr (res
.comp_dir
, ':');
11473 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11474 res
.comp_dir
= cp
+ 1;
11477 if (res
.name
== NULL
)
11478 res
.name
= "<unknown>";
11483 /* Handle DW_AT_stmt_list for a compilation unit.
11484 DIE is the DW_TAG_compile_unit die for CU.
11485 COMP_DIR is the compilation directory. LOWPC is passed to
11486 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11489 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11490 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11492 struct dwarf2_per_objfile
*dwarf2_per_objfile
11493 = cu
->per_cu
->dwarf2_per_objfile
;
11494 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11495 struct attribute
*attr
;
11496 struct line_header line_header_local
;
11497 hashval_t line_header_local_hash
;
11499 int decode_mapping
;
11501 gdb_assert (! cu
->per_cu
->is_debug_types
);
11503 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11507 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11509 /* The line header hash table is only created if needed (it exists to
11510 prevent redundant reading of the line table for partial_units).
11511 If we're given a partial_unit, we'll need it. If we're given a
11512 compile_unit, then use the line header hash table if it's already
11513 created, but don't create one just yet. */
11515 if (dwarf2_per_objfile
->line_header_hash
== NULL
11516 && die
->tag
== DW_TAG_partial_unit
)
11518 dwarf2_per_objfile
->line_header_hash
11519 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11520 line_header_eq_voidp
,
11521 free_line_header_voidp
,
11522 &objfile
->objfile_obstack
,
11523 hashtab_obstack_allocate
,
11524 dummy_obstack_deallocate
);
11527 line_header_local
.sect_off
= line_offset
;
11528 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11529 line_header_local_hash
= line_header_hash (&line_header_local
);
11530 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11532 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11533 &line_header_local
,
11534 line_header_local_hash
, NO_INSERT
);
11536 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11537 is not present in *SLOT (since if there is something in *SLOT then
11538 it will be for a partial_unit). */
11539 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11541 gdb_assert (*slot
!= NULL
);
11542 cu
->line_header
= (struct line_header
*) *slot
;
11547 /* dwarf_decode_line_header does not yet provide sufficient information.
11548 We always have to call also dwarf_decode_lines for it. */
11549 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11553 cu
->line_header
= lh
.release ();
11554 cu
->line_header_die_owner
= die
;
11556 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11560 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11561 &line_header_local
,
11562 line_header_local_hash
, INSERT
);
11563 gdb_assert (slot
!= NULL
);
11565 if (slot
!= NULL
&& *slot
== NULL
)
11567 /* This newly decoded line number information unit will be owned
11568 by line_header_hash hash table. */
11569 *slot
= cu
->line_header
;
11570 cu
->line_header_die_owner
= NULL
;
11574 /* We cannot free any current entry in (*slot) as that struct line_header
11575 may be already used by multiple CUs. Create only temporary decoded
11576 line_header for this CU - it may happen at most once for each line
11577 number information unit. And if we're not using line_header_hash
11578 then this is what we want as well. */
11579 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11581 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11582 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11587 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11590 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11592 struct dwarf2_per_objfile
*dwarf2_per_objfile
11593 = cu
->per_cu
->dwarf2_per_objfile
;
11594 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11595 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11596 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11597 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11598 struct attribute
*attr
;
11599 struct die_info
*child_die
;
11600 CORE_ADDR baseaddr
;
11602 prepare_one_comp_unit (cu
, die
, cu
->language
);
11603 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
11605 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11607 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11608 from finish_block. */
11609 if (lowpc
== ((CORE_ADDR
) -1))
11611 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11613 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11615 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11616 standardised yet. As a workaround for the language detection we fall
11617 back to the DW_AT_producer string. */
11618 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11619 cu
->language
= language_opencl
;
11621 /* Similar hack for Go. */
11622 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11623 set_cu_language (DW_LANG_Go
, cu
);
11625 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11627 /* Decode line number information if present. We do this before
11628 processing child DIEs, so that the line header table is available
11629 for DW_AT_decl_file. */
11630 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11632 /* Process all dies in compilation unit. */
11633 if (die
->child
!= NULL
)
11635 child_die
= die
->child
;
11636 while (child_die
&& child_die
->tag
)
11638 process_die (child_die
, cu
);
11639 child_die
= sibling_die (child_die
);
11643 /* Decode macro information, if present. Dwarf 2 macro information
11644 refers to information in the line number info statement program
11645 header, so we can only read it if we've read the header
11647 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11649 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11650 if (attr
&& cu
->line_header
)
11652 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11653 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11655 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11659 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11660 if (attr
&& cu
->line_header
)
11662 unsigned int macro_offset
= DW_UNSND (attr
);
11664 dwarf_decode_macros (cu
, macro_offset
, 0);
11670 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11672 struct type_unit_group
*tu_group
;
11674 struct attribute
*attr
;
11676 struct signatured_type
*sig_type
;
11678 gdb_assert (per_cu
->is_debug_types
);
11679 sig_type
= (struct signatured_type
*) per_cu
;
11681 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11683 /* If we're using .gdb_index (includes -readnow) then
11684 per_cu->type_unit_group may not have been set up yet. */
11685 if (sig_type
->type_unit_group
== NULL
)
11686 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11687 tu_group
= sig_type
->type_unit_group
;
11689 /* If we've already processed this stmt_list there's no real need to
11690 do it again, we could fake it and just recreate the part we need
11691 (file name,index -> symtab mapping). If data shows this optimization
11692 is useful we can do it then. */
11693 first_time
= tu_group
->compunit_symtab
== NULL
;
11695 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11700 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11701 lh
= dwarf_decode_line_header (line_offset
, this);
11706 start_symtab ("", NULL
, 0);
11709 gdb_assert (tu_group
->symtabs
== NULL
);
11710 gdb_assert (m_builder
== nullptr);
11711 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11712 m_builder
.reset (new struct buildsym_compunit
11713 (COMPUNIT_OBJFILE (cust
), "",
11714 COMPUNIT_DIRNAME (cust
),
11715 compunit_language (cust
),
11721 line_header
= lh
.release ();
11722 line_header_die_owner
= die
;
11726 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11728 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11729 still initializing it, and our caller (a few levels up)
11730 process_full_type_unit still needs to know if this is the first
11733 tu_group
->num_symtabs
= line_header
->file_names_size ();
11734 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11735 line_header
->file_names_size ());
11737 auto &file_names
= line_header
->file_names ();
11738 for (i
= 0; i
< file_names
.size (); ++i
)
11740 file_entry
&fe
= file_names
[i
];
11741 dwarf2_start_subfile (this, fe
.name
,
11742 fe
.include_dir (line_header
));
11743 buildsym_compunit
*b
= get_builder ();
11744 if (b
->get_current_subfile ()->symtab
== NULL
)
11746 /* NOTE: start_subfile will recognize when it's been
11747 passed a file it has already seen. So we can't
11748 assume there's a simple mapping from
11749 cu->line_header->file_names to subfiles, plus
11750 cu->line_header->file_names may contain dups. */
11751 b
->get_current_subfile ()->symtab
11752 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11755 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11756 tu_group
->symtabs
[i
] = fe
.symtab
;
11761 gdb_assert (m_builder
== nullptr);
11762 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11763 m_builder
.reset (new struct buildsym_compunit
11764 (COMPUNIT_OBJFILE (cust
), "",
11765 COMPUNIT_DIRNAME (cust
),
11766 compunit_language (cust
),
11769 auto &file_names
= line_header
->file_names ();
11770 for (i
= 0; i
< file_names
.size (); ++i
)
11772 file_entry
&fe
= file_names
[i
];
11773 fe
.symtab
= tu_group
->symtabs
[i
];
11777 /* The main symtab is allocated last. Type units don't have DW_AT_name
11778 so they don't have a "real" (so to speak) symtab anyway.
11779 There is later code that will assign the main symtab to all symbols
11780 that don't have one. We need to handle the case of a symbol with a
11781 missing symtab (DW_AT_decl_file) anyway. */
11784 /* Process DW_TAG_type_unit.
11785 For TUs we want to skip the first top level sibling if it's not the
11786 actual type being defined by this TU. In this case the first top
11787 level sibling is there to provide context only. */
11790 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11792 struct die_info
*child_die
;
11794 prepare_one_comp_unit (cu
, die
, language_minimal
);
11796 /* Initialize (or reinitialize) the machinery for building symtabs.
11797 We do this before processing child DIEs, so that the line header table
11798 is available for DW_AT_decl_file. */
11799 cu
->setup_type_unit_groups (die
);
11801 if (die
->child
!= NULL
)
11803 child_die
= die
->child
;
11804 while (child_die
&& child_die
->tag
)
11806 process_die (child_die
, cu
);
11807 child_die
= sibling_die (child_die
);
11814 http://gcc.gnu.org/wiki/DebugFission
11815 http://gcc.gnu.org/wiki/DebugFissionDWP
11817 To simplify handling of both DWO files ("object" files with the DWARF info)
11818 and DWP files (a file with the DWOs packaged up into one file), we treat
11819 DWP files as having a collection of virtual DWO files. */
11822 hash_dwo_file (const void *item
)
11824 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11827 hash
= htab_hash_string (dwo_file
->dwo_name
);
11828 if (dwo_file
->comp_dir
!= NULL
)
11829 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11834 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11836 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11837 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11839 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11841 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11842 return lhs
->comp_dir
== rhs
->comp_dir
;
11843 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11846 /* Allocate a hash table for DWO files. */
11849 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11851 auto delete_dwo_file
= [] (void *item
)
11853 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11858 return htab_up (htab_create_alloc_ex (41,
11862 &objfile
->objfile_obstack
,
11863 hashtab_obstack_allocate
,
11864 dummy_obstack_deallocate
));
11867 /* Lookup DWO file DWO_NAME. */
11870 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11871 const char *dwo_name
,
11872 const char *comp_dir
)
11874 struct dwo_file find_entry
;
11877 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11878 dwarf2_per_objfile
->dwo_files
11879 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11881 find_entry
.dwo_name
= dwo_name
;
11882 find_entry
.comp_dir
= comp_dir
;
11883 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11890 hash_dwo_unit (const void *item
)
11892 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11894 /* This drops the top 32 bits of the id, but is ok for a hash. */
11895 return dwo_unit
->signature
;
11899 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11901 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11902 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11904 /* The signature is assumed to be unique within the DWO file.
11905 So while object file CU dwo_id's always have the value zero,
11906 that's OK, assuming each object file DWO file has only one CU,
11907 and that's the rule for now. */
11908 return lhs
->signature
== rhs
->signature
;
11911 /* Allocate a hash table for DWO CUs,TUs.
11912 There is one of these tables for each of CUs,TUs for each DWO file. */
11915 allocate_dwo_unit_table (struct objfile
*objfile
)
11917 /* Start out with a pretty small number.
11918 Generally DWO files contain only one CU and maybe some TUs. */
11919 return htab_create_alloc_ex (3,
11923 &objfile
->objfile_obstack
,
11924 hashtab_obstack_allocate
,
11925 dummy_obstack_deallocate
);
11928 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11930 struct create_dwo_cu_data
11932 struct dwo_file
*dwo_file
;
11933 struct dwo_unit dwo_unit
;
11936 /* die_reader_func for create_dwo_cu. */
11939 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11940 const gdb_byte
*info_ptr
,
11941 struct die_info
*comp_unit_die
,
11945 struct dwarf2_cu
*cu
= reader
->cu
;
11946 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11947 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11948 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11949 struct dwo_file
*dwo_file
= data
->dwo_file
;
11950 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11952 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11953 if (!signature
.has_value ())
11955 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11956 " its dwo_id [in module %s]"),
11957 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11961 dwo_unit
->dwo_file
= dwo_file
;
11962 dwo_unit
->signature
= *signature
;
11963 dwo_unit
->section
= section
;
11964 dwo_unit
->sect_off
= sect_off
;
11965 dwo_unit
->length
= cu
->per_cu
->length
;
11967 if (dwarf_read_debug
)
11968 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11969 sect_offset_str (sect_off
),
11970 hex_string (dwo_unit
->signature
));
11973 /* Create the dwo_units for the CUs in a DWO_FILE.
11974 Note: This function processes DWO files only, not DWP files. */
11977 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11978 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11981 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11982 const gdb_byte
*info_ptr
, *end_ptr
;
11984 dwarf2_read_section (objfile
, §ion
);
11985 info_ptr
= section
.buffer
;
11987 if (info_ptr
== NULL
)
11990 if (dwarf_read_debug
)
11992 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11993 get_section_name (§ion
),
11994 get_section_file_name (§ion
));
11997 end_ptr
= info_ptr
+ section
.size
;
11998 while (info_ptr
< end_ptr
)
12000 struct dwarf2_per_cu_data per_cu
;
12001 struct create_dwo_cu_data create_dwo_cu_data
;
12002 struct dwo_unit
*dwo_unit
;
12004 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
12006 memset (&create_dwo_cu_data
.dwo_unit
, 0,
12007 sizeof (create_dwo_cu_data
.dwo_unit
));
12008 memset (&per_cu
, 0, sizeof (per_cu
));
12009 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
12010 per_cu
.is_debug_types
= 0;
12011 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12012 per_cu
.section
= §ion
;
12013 create_dwo_cu_data
.dwo_file
= &dwo_file
;
12015 init_cutu_and_read_dies_no_follow (
12016 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
12017 info_ptr
+= per_cu
.length
;
12019 // If the unit could not be parsed, skip it.
12020 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12023 if (cus_htab
== NULL
)
12024 cus_htab
= allocate_dwo_unit_table (objfile
);
12026 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12027 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12028 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12029 gdb_assert (slot
!= NULL
);
12032 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12033 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12035 complaint (_("debug cu entry at offset %s is duplicate to"
12036 " the entry at offset %s, signature %s"),
12037 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12038 hex_string (dwo_unit
->signature
));
12040 *slot
= (void *)dwo_unit
;
12044 /* DWP file .debug_{cu,tu}_index section format:
12045 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12049 Both index sections have the same format, and serve to map a 64-bit
12050 signature to a set of section numbers. Each section begins with a header,
12051 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12052 indexes, and a pool of 32-bit section numbers. The index sections will be
12053 aligned at 8-byte boundaries in the file.
12055 The index section header consists of:
12057 V, 32 bit version number
12059 N, 32 bit number of compilation units or type units in the index
12060 M, 32 bit number of slots in the hash table
12062 Numbers are recorded using the byte order of the application binary.
12064 The hash table begins at offset 16 in the section, and consists of an array
12065 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12066 order of the application binary). Unused slots in the hash table are 0.
12067 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12069 The parallel table begins immediately after the hash table
12070 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12071 array of 32-bit indexes (using the byte order of the application binary),
12072 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12073 table contains a 32-bit index into the pool of section numbers. For unused
12074 hash table slots, the corresponding entry in the parallel table will be 0.
12076 The pool of section numbers begins immediately following the hash table
12077 (at offset 16 + 12 * M from the beginning of the section). The pool of
12078 section numbers consists of an array of 32-bit words (using the byte order
12079 of the application binary). Each item in the array is indexed starting
12080 from 0. The hash table entry provides the index of the first section
12081 number in the set. Additional section numbers in the set follow, and the
12082 set is terminated by a 0 entry (section number 0 is not used in ELF).
12084 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12085 section must be the first entry in the set, and the .debug_abbrev.dwo must
12086 be the second entry. Other members of the set may follow in any order.
12092 DWP Version 2 combines all the .debug_info, etc. sections into one,
12093 and the entries in the index tables are now offsets into these sections.
12094 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12097 Index Section Contents:
12099 Hash Table of Signatures dwp_hash_table.hash_table
12100 Parallel Table of Indices dwp_hash_table.unit_table
12101 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12102 Table of Section Sizes dwp_hash_table.v2.sizes
12104 The index section header consists of:
12106 V, 32 bit version number
12107 L, 32 bit number of columns in the table of section offsets
12108 N, 32 bit number of compilation units or type units in the index
12109 M, 32 bit number of slots in the hash table
12111 Numbers are recorded using the byte order of the application binary.
12113 The hash table has the same format as version 1.
12114 The parallel table of indices has the same format as version 1,
12115 except that the entries are origin-1 indices into the table of sections
12116 offsets and the table of section sizes.
12118 The table of offsets begins immediately following the parallel table
12119 (at offset 16 + 12 * M from the beginning of the section). The table is
12120 a two-dimensional array of 32-bit words (using the byte order of the
12121 application binary), with L columns and N+1 rows, in row-major order.
12122 Each row in the array is indexed starting from 0. The first row provides
12123 a key to the remaining rows: each column in this row provides an identifier
12124 for a debug section, and the offsets in the same column of subsequent rows
12125 refer to that section. The section identifiers are:
12127 DW_SECT_INFO 1 .debug_info.dwo
12128 DW_SECT_TYPES 2 .debug_types.dwo
12129 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12130 DW_SECT_LINE 4 .debug_line.dwo
12131 DW_SECT_LOC 5 .debug_loc.dwo
12132 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12133 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12134 DW_SECT_MACRO 8 .debug_macro.dwo
12136 The offsets provided by the CU and TU index sections are the base offsets
12137 for the contributions made by each CU or TU to the corresponding section
12138 in the package file. Each CU and TU header contains an abbrev_offset
12139 field, used to find the abbreviations table for that CU or TU within the
12140 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12141 be interpreted as relative to the base offset given in the index section.
12142 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12143 should be interpreted as relative to the base offset for .debug_line.dwo,
12144 and offsets into other debug sections obtained from DWARF attributes should
12145 also be interpreted as relative to the corresponding base offset.
12147 The table of sizes begins immediately following the table of offsets.
12148 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12149 with L columns and N rows, in row-major order. Each row in the array is
12150 indexed starting from 1 (row 0 is shared by the two tables).
12154 Hash table lookup is handled the same in version 1 and 2:
12156 We assume that N and M will not exceed 2^32 - 1.
12157 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12159 Given a 64-bit compilation unit signature or a type signature S, an entry
12160 in the hash table is located as follows:
12162 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12163 the low-order k bits all set to 1.
12165 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12167 3) If the hash table entry at index H matches the signature, use that
12168 entry. If the hash table entry at index H is unused (all zeroes),
12169 terminate the search: the signature is not present in the table.
12171 4) Let H = (H + H') modulo M. Repeat at Step 3.
12173 Because M > N and H' and M are relatively prime, the search is guaranteed
12174 to stop at an unused slot or find the match. */
12176 /* Create a hash table to map DWO IDs to their CU/TU entry in
12177 .debug_{info,types}.dwo in DWP_FILE.
12178 Returns NULL if there isn't one.
12179 Note: This function processes DWP files only, not DWO files. */
12181 static struct dwp_hash_table
*
12182 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12183 struct dwp_file
*dwp_file
, int is_debug_types
)
12185 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12186 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12187 const gdb_byte
*index_ptr
, *index_end
;
12188 struct dwarf2_section_info
*index
;
12189 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12190 struct dwp_hash_table
*htab
;
12192 if (is_debug_types
)
12193 index
= &dwp_file
->sections
.tu_index
;
12195 index
= &dwp_file
->sections
.cu_index
;
12197 if (dwarf2_section_empty_p (index
))
12199 dwarf2_read_section (objfile
, index
);
12201 index_ptr
= index
->buffer
;
12202 index_end
= index_ptr
+ index
->size
;
12204 version
= read_4_bytes (dbfd
, index_ptr
);
12207 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12211 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12213 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12216 if (version
!= 1 && version
!= 2)
12218 error (_("Dwarf Error: unsupported DWP file version (%s)"
12219 " [in module %s]"),
12220 pulongest (version
), dwp_file
->name
);
12222 if (nr_slots
!= (nr_slots
& -nr_slots
))
12224 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12225 " is not power of 2 [in module %s]"),
12226 pulongest (nr_slots
), dwp_file
->name
);
12229 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12230 htab
->version
= version
;
12231 htab
->nr_columns
= nr_columns
;
12232 htab
->nr_units
= nr_units
;
12233 htab
->nr_slots
= nr_slots
;
12234 htab
->hash_table
= index_ptr
;
12235 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12237 /* Exit early if the table is empty. */
12238 if (nr_slots
== 0 || nr_units
== 0
12239 || (version
== 2 && nr_columns
== 0))
12241 /* All must be zero. */
12242 if (nr_slots
!= 0 || nr_units
!= 0
12243 || (version
== 2 && nr_columns
!= 0))
12245 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12246 " all zero [in modules %s]"),
12254 htab
->section_pool
.v1
.indices
=
12255 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12256 /* It's harder to decide whether the section is too small in v1.
12257 V1 is deprecated anyway so we punt. */
12261 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12262 int *ids
= htab
->section_pool
.v2
.section_ids
;
12263 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12264 /* Reverse map for error checking. */
12265 int ids_seen
[DW_SECT_MAX
+ 1];
12268 if (nr_columns
< 2)
12270 error (_("Dwarf Error: bad DWP hash table, too few columns"
12271 " in section table [in module %s]"),
12274 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12276 error (_("Dwarf Error: bad DWP hash table, too many columns"
12277 " in section table [in module %s]"),
12280 memset (ids
, 255, sizeof_ids
);
12281 memset (ids_seen
, 255, sizeof (ids_seen
));
12282 for (i
= 0; i
< nr_columns
; ++i
)
12284 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12286 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12288 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12289 " in section table [in module %s]"),
12290 id
, dwp_file
->name
);
12292 if (ids_seen
[id
] != -1)
12294 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12295 " id %d in section table [in module %s]"),
12296 id
, dwp_file
->name
);
12301 /* Must have exactly one info or types section. */
12302 if (((ids_seen
[DW_SECT_INFO
] != -1)
12303 + (ids_seen
[DW_SECT_TYPES
] != -1))
12306 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12307 " DWO info/types section [in module %s]"),
12310 /* Must have an abbrev section. */
12311 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12313 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12314 " section [in module %s]"),
12317 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12318 htab
->section_pool
.v2
.sizes
=
12319 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12320 * nr_units
* nr_columns
);
12321 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12322 * nr_units
* nr_columns
))
12325 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12326 " [in module %s]"),
12334 /* Update SECTIONS with the data from SECTP.
12336 This function is like the other "locate" section routines that are
12337 passed to bfd_map_over_sections, but in this context the sections to
12338 read comes from the DWP V1 hash table, not the full ELF section table.
12340 The result is non-zero for success, or zero if an error was found. */
12343 locate_v1_virtual_dwo_sections (asection
*sectp
,
12344 struct virtual_v1_dwo_sections
*sections
)
12346 const struct dwop_section_names
*names
= &dwop_section_names
;
12348 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12350 /* There can be only one. */
12351 if (sections
->abbrev
.s
.section
!= NULL
)
12353 sections
->abbrev
.s
.section
= sectp
;
12354 sections
->abbrev
.size
= bfd_section_size (sectp
);
12356 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12357 || section_is_p (sectp
->name
, &names
->types_dwo
))
12359 /* There can be only one. */
12360 if (sections
->info_or_types
.s
.section
!= NULL
)
12362 sections
->info_or_types
.s
.section
= sectp
;
12363 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12365 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12367 /* There can be only one. */
12368 if (sections
->line
.s
.section
!= NULL
)
12370 sections
->line
.s
.section
= sectp
;
12371 sections
->line
.size
= bfd_section_size (sectp
);
12373 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12375 /* There can be only one. */
12376 if (sections
->loc
.s
.section
!= NULL
)
12378 sections
->loc
.s
.section
= sectp
;
12379 sections
->loc
.size
= bfd_section_size (sectp
);
12381 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12383 /* There can be only one. */
12384 if (sections
->macinfo
.s
.section
!= NULL
)
12386 sections
->macinfo
.s
.section
= sectp
;
12387 sections
->macinfo
.size
= bfd_section_size (sectp
);
12389 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12391 /* There can be only one. */
12392 if (sections
->macro
.s
.section
!= NULL
)
12394 sections
->macro
.s
.section
= sectp
;
12395 sections
->macro
.size
= bfd_section_size (sectp
);
12397 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12399 /* There can be only one. */
12400 if (sections
->str_offsets
.s
.section
!= NULL
)
12402 sections
->str_offsets
.s
.section
= sectp
;
12403 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12407 /* No other kind of section is valid. */
12414 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12415 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12416 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12417 This is for DWP version 1 files. */
12419 static struct dwo_unit
*
12420 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12421 struct dwp_file
*dwp_file
,
12422 uint32_t unit_index
,
12423 const char *comp_dir
,
12424 ULONGEST signature
, int is_debug_types
)
12426 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12427 const struct dwp_hash_table
*dwp_htab
=
12428 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12429 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12430 const char *kind
= is_debug_types
? "TU" : "CU";
12431 struct dwo_file
*dwo_file
;
12432 struct dwo_unit
*dwo_unit
;
12433 struct virtual_v1_dwo_sections sections
;
12434 void **dwo_file_slot
;
12437 gdb_assert (dwp_file
->version
== 1);
12439 if (dwarf_read_debug
)
12441 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12443 pulongest (unit_index
), hex_string (signature
),
12447 /* Fetch the sections of this DWO unit.
12448 Put a limit on the number of sections we look for so that bad data
12449 doesn't cause us to loop forever. */
12451 #define MAX_NR_V1_DWO_SECTIONS \
12452 (1 /* .debug_info or .debug_types */ \
12453 + 1 /* .debug_abbrev */ \
12454 + 1 /* .debug_line */ \
12455 + 1 /* .debug_loc */ \
12456 + 1 /* .debug_str_offsets */ \
12457 + 1 /* .debug_macro or .debug_macinfo */ \
12458 + 1 /* trailing zero */)
12460 memset (§ions
, 0, sizeof (sections
));
12462 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12465 uint32_t section_nr
=
12466 read_4_bytes (dbfd
,
12467 dwp_htab
->section_pool
.v1
.indices
12468 + (unit_index
+ i
) * sizeof (uint32_t));
12470 if (section_nr
== 0)
12472 if (section_nr
>= dwp_file
->num_sections
)
12474 error (_("Dwarf Error: bad DWP hash table, section number too large"
12475 " [in module %s]"),
12479 sectp
= dwp_file
->elf_sections
[section_nr
];
12480 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12482 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12483 " [in module %s]"),
12489 || dwarf2_section_empty_p (§ions
.info_or_types
)
12490 || dwarf2_section_empty_p (§ions
.abbrev
))
12492 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12493 " [in module %s]"),
12496 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12498 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12499 " [in module %s]"),
12503 /* It's easier for the rest of the code if we fake a struct dwo_file and
12504 have dwo_unit "live" in that. At least for now.
12506 The DWP file can be made up of a random collection of CUs and TUs.
12507 However, for each CU + set of TUs that came from the same original DWO
12508 file, we can combine them back into a virtual DWO file to save space
12509 (fewer struct dwo_file objects to allocate). Remember that for really
12510 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12512 std::string virtual_dwo_name
=
12513 string_printf ("virtual-dwo/%d-%d-%d-%d",
12514 get_section_id (§ions
.abbrev
),
12515 get_section_id (§ions
.line
),
12516 get_section_id (§ions
.loc
),
12517 get_section_id (§ions
.str_offsets
));
12518 /* Can we use an existing virtual DWO file? */
12519 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12520 virtual_dwo_name
.c_str (),
12522 /* Create one if necessary. */
12523 if (*dwo_file_slot
== NULL
)
12525 if (dwarf_read_debug
)
12527 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12528 virtual_dwo_name
.c_str ());
12530 dwo_file
= new struct dwo_file
;
12531 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12533 dwo_file
->comp_dir
= comp_dir
;
12534 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12535 dwo_file
->sections
.line
= sections
.line
;
12536 dwo_file
->sections
.loc
= sections
.loc
;
12537 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12538 dwo_file
->sections
.macro
= sections
.macro
;
12539 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12540 /* The "str" section is global to the entire DWP file. */
12541 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12542 /* The info or types section is assigned below to dwo_unit,
12543 there's no need to record it in dwo_file.
12544 Also, we can't simply record type sections in dwo_file because
12545 we record a pointer into the vector in dwo_unit. As we collect more
12546 types we'll grow the vector and eventually have to reallocate space
12547 for it, invalidating all copies of pointers into the previous
12549 *dwo_file_slot
= dwo_file
;
12553 if (dwarf_read_debug
)
12555 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12556 virtual_dwo_name
.c_str ());
12558 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12561 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12562 dwo_unit
->dwo_file
= dwo_file
;
12563 dwo_unit
->signature
= signature
;
12564 dwo_unit
->section
=
12565 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12566 *dwo_unit
->section
= sections
.info_or_types
;
12567 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12572 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12573 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12574 piece within that section used by a TU/CU, return a virtual section
12575 of just that piece. */
12577 static struct dwarf2_section_info
12578 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12579 struct dwarf2_section_info
*section
,
12580 bfd_size_type offset
, bfd_size_type size
)
12582 struct dwarf2_section_info result
;
12585 gdb_assert (section
!= NULL
);
12586 gdb_assert (!section
->is_virtual
);
12588 memset (&result
, 0, sizeof (result
));
12589 result
.s
.containing_section
= section
;
12590 result
.is_virtual
= true;
12595 sectp
= get_section_bfd_section (section
);
12597 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12598 bounds of the real section. This is a pretty-rare event, so just
12599 flag an error (easier) instead of a warning and trying to cope. */
12601 || offset
+ size
> bfd_section_size (sectp
))
12603 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12604 " in section %s [in module %s]"),
12605 sectp
? bfd_section_name (sectp
) : "<unknown>",
12606 objfile_name (dwarf2_per_objfile
->objfile
));
12609 result
.virtual_offset
= offset
;
12610 result
.size
= size
;
12614 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12615 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12616 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12617 This is for DWP version 2 files. */
12619 static struct dwo_unit
*
12620 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12621 struct dwp_file
*dwp_file
,
12622 uint32_t unit_index
,
12623 const char *comp_dir
,
12624 ULONGEST signature
, int is_debug_types
)
12626 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12627 const struct dwp_hash_table
*dwp_htab
=
12628 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12629 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12630 const char *kind
= is_debug_types
? "TU" : "CU";
12631 struct dwo_file
*dwo_file
;
12632 struct dwo_unit
*dwo_unit
;
12633 struct virtual_v2_dwo_sections sections
;
12634 void **dwo_file_slot
;
12637 gdb_assert (dwp_file
->version
== 2);
12639 if (dwarf_read_debug
)
12641 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12643 pulongest (unit_index
), hex_string (signature
),
12647 /* Fetch the section offsets of this DWO unit. */
12649 memset (§ions
, 0, sizeof (sections
));
12651 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12653 uint32_t offset
= read_4_bytes (dbfd
,
12654 dwp_htab
->section_pool
.v2
.offsets
12655 + (((unit_index
- 1) * dwp_htab
->nr_columns
12657 * sizeof (uint32_t)));
12658 uint32_t size
= read_4_bytes (dbfd
,
12659 dwp_htab
->section_pool
.v2
.sizes
12660 + (((unit_index
- 1) * dwp_htab
->nr_columns
12662 * sizeof (uint32_t)));
12664 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12667 case DW_SECT_TYPES
:
12668 sections
.info_or_types_offset
= offset
;
12669 sections
.info_or_types_size
= size
;
12671 case DW_SECT_ABBREV
:
12672 sections
.abbrev_offset
= offset
;
12673 sections
.abbrev_size
= size
;
12676 sections
.line_offset
= offset
;
12677 sections
.line_size
= size
;
12680 sections
.loc_offset
= offset
;
12681 sections
.loc_size
= size
;
12683 case DW_SECT_STR_OFFSETS
:
12684 sections
.str_offsets_offset
= offset
;
12685 sections
.str_offsets_size
= size
;
12687 case DW_SECT_MACINFO
:
12688 sections
.macinfo_offset
= offset
;
12689 sections
.macinfo_size
= size
;
12691 case DW_SECT_MACRO
:
12692 sections
.macro_offset
= offset
;
12693 sections
.macro_size
= size
;
12698 /* It's easier for the rest of the code if we fake a struct dwo_file and
12699 have dwo_unit "live" in that. At least for now.
12701 The DWP file can be made up of a random collection of CUs and TUs.
12702 However, for each CU + set of TUs that came from the same original DWO
12703 file, we can combine them back into a virtual DWO file to save space
12704 (fewer struct dwo_file objects to allocate). Remember that for really
12705 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12707 std::string virtual_dwo_name
=
12708 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12709 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12710 (long) (sections
.line_size
? sections
.line_offset
: 0),
12711 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12712 (long) (sections
.str_offsets_size
12713 ? sections
.str_offsets_offset
: 0));
12714 /* Can we use an existing virtual DWO file? */
12715 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12716 virtual_dwo_name
.c_str (),
12718 /* Create one if necessary. */
12719 if (*dwo_file_slot
== NULL
)
12721 if (dwarf_read_debug
)
12723 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12724 virtual_dwo_name
.c_str ());
12726 dwo_file
= new struct dwo_file
;
12727 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12729 dwo_file
->comp_dir
= comp_dir
;
12730 dwo_file
->sections
.abbrev
=
12731 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12732 sections
.abbrev_offset
, sections
.abbrev_size
);
12733 dwo_file
->sections
.line
=
12734 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12735 sections
.line_offset
, sections
.line_size
);
12736 dwo_file
->sections
.loc
=
12737 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12738 sections
.loc_offset
, sections
.loc_size
);
12739 dwo_file
->sections
.macinfo
=
12740 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12741 sections
.macinfo_offset
, sections
.macinfo_size
);
12742 dwo_file
->sections
.macro
=
12743 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12744 sections
.macro_offset
, sections
.macro_size
);
12745 dwo_file
->sections
.str_offsets
=
12746 create_dwp_v2_section (dwarf2_per_objfile
,
12747 &dwp_file
->sections
.str_offsets
,
12748 sections
.str_offsets_offset
,
12749 sections
.str_offsets_size
);
12750 /* The "str" section is global to the entire DWP file. */
12751 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12752 /* The info or types section is assigned below to dwo_unit,
12753 there's no need to record it in dwo_file.
12754 Also, we can't simply record type sections in dwo_file because
12755 we record a pointer into the vector in dwo_unit. As we collect more
12756 types we'll grow the vector and eventually have to reallocate space
12757 for it, invalidating all copies of pointers into the previous
12759 *dwo_file_slot
= dwo_file
;
12763 if (dwarf_read_debug
)
12765 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12766 virtual_dwo_name
.c_str ());
12768 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12771 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12772 dwo_unit
->dwo_file
= dwo_file
;
12773 dwo_unit
->signature
= signature
;
12774 dwo_unit
->section
=
12775 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12776 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12778 ? &dwp_file
->sections
.types
12779 : &dwp_file
->sections
.info
,
12780 sections
.info_or_types_offset
,
12781 sections
.info_or_types_size
);
12782 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12787 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12788 Returns NULL if the signature isn't found. */
12790 static struct dwo_unit
*
12791 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12792 struct dwp_file
*dwp_file
, const char *comp_dir
,
12793 ULONGEST signature
, int is_debug_types
)
12795 const struct dwp_hash_table
*dwp_htab
=
12796 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12797 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12798 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12799 uint32_t hash
= signature
& mask
;
12800 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12803 struct dwo_unit find_dwo_cu
;
12805 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12806 find_dwo_cu
.signature
= signature
;
12807 slot
= htab_find_slot (is_debug_types
12808 ? dwp_file
->loaded_tus
12809 : dwp_file
->loaded_cus
,
12810 &find_dwo_cu
, INSERT
);
12813 return (struct dwo_unit
*) *slot
;
12815 /* Use a for loop so that we don't loop forever on bad debug info. */
12816 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12818 ULONGEST signature_in_table
;
12820 signature_in_table
=
12821 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12822 if (signature_in_table
== signature
)
12824 uint32_t unit_index
=
12825 read_4_bytes (dbfd
,
12826 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12828 if (dwp_file
->version
== 1)
12830 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12831 dwp_file
, unit_index
,
12832 comp_dir
, signature
,
12837 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12838 dwp_file
, unit_index
,
12839 comp_dir
, signature
,
12842 return (struct dwo_unit
*) *slot
;
12844 if (signature_in_table
== 0)
12846 hash
= (hash
+ hash2
) & mask
;
12849 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12850 " [in module %s]"),
12854 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12855 Open the file specified by FILE_NAME and hand it off to BFD for
12856 preliminary analysis. Return a newly initialized bfd *, which
12857 includes a canonicalized copy of FILE_NAME.
12858 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12859 SEARCH_CWD is true if the current directory is to be searched.
12860 It will be searched before debug-file-directory.
12861 If successful, the file is added to the bfd include table of the
12862 objfile's bfd (see gdb_bfd_record_inclusion).
12863 If unable to find/open the file, return NULL.
12864 NOTE: This function is derived from symfile_bfd_open. */
12866 static gdb_bfd_ref_ptr
12867 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12868 const char *file_name
, int is_dwp
, int search_cwd
)
12871 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12872 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12873 to debug_file_directory. */
12874 const char *search_path
;
12875 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12877 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12880 if (*debug_file_directory
!= '\0')
12882 search_path_holder
.reset (concat (".", dirname_separator_string
,
12883 debug_file_directory
,
12885 search_path
= search_path_holder
.get ();
12891 search_path
= debug_file_directory
;
12893 openp_flags flags
= OPF_RETURN_REALPATH
;
12895 flags
|= OPF_SEARCH_IN_PATH
;
12897 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12898 desc
= openp (search_path
, flags
, file_name
,
12899 O_RDONLY
| O_BINARY
, &absolute_name
);
12903 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12905 if (sym_bfd
== NULL
)
12907 bfd_set_cacheable (sym_bfd
.get (), 1);
12909 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12912 /* Success. Record the bfd as having been included by the objfile's bfd.
12913 This is important because things like demangled_names_hash lives in the
12914 objfile's per_bfd space and may have references to things like symbol
12915 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12916 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12921 /* Try to open DWO file FILE_NAME.
12922 COMP_DIR is the DW_AT_comp_dir attribute.
12923 The result is the bfd handle of the file.
12924 If there is a problem finding or opening the file, return NULL.
12925 Upon success, the canonicalized path of the file is stored in the bfd,
12926 same as symfile_bfd_open. */
12928 static gdb_bfd_ref_ptr
12929 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12930 const char *file_name
, const char *comp_dir
)
12932 if (IS_ABSOLUTE_PATH (file_name
))
12933 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12934 0 /*is_dwp*/, 0 /*search_cwd*/);
12936 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12938 if (comp_dir
!= NULL
)
12940 gdb::unique_xmalloc_ptr
<char> path_to_try
12941 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12943 /* NOTE: If comp_dir is a relative path, this will also try the
12944 search path, which seems useful. */
12945 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12946 path_to_try
.get (),
12948 1 /*search_cwd*/));
12953 /* That didn't work, try debug-file-directory, which, despite its name,
12954 is a list of paths. */
12956 if (*debug_file_directory
== '\0')
12959 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12960 0 /*is_dwp*/, 1 /*search_cwd*/);
12963 /* This function is mapped across the sections and remembers the offset and
12964 size of each of the DWO debugging sections we are interested in. */
12967 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12969 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12970 const struct dwop_section_names
*names
= &dwop_section_names
;
12972 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12974 dwo_sections
->abbrev
.s
.section
= sectp
;
12975 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12977 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12979 dwo_sections
->info
.s
.section
= sectp
;
12980 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12982 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12984 dwo_sections
->line
.s
.section
= sectp
;
12985 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12987 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12989 dwo_sections
->loc
.s
.section
= sectp
;
12990 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12992 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12994 dwo_sections
->macinfo
.s
.section
= sectp
;
12995 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12997 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12999 dwo_sections
->macro
.s
.section
= sectp
;
13000 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
13002 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
13004 dwo_sections
->str
.s
.section
= sectp
;
13005 dwo_sections
->str
.size
= bfd_section_size (sectp
);
13007 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13009 dwo_sections
->str_offsets
.s
.section
= sectp
;
13010 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
13012 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13014 struct dwarf2_section_info type_section
;
13016 memset (&type_section
, 0, sizeof (type_section
));
13017 type_section
.s
.section
= sectp
;
13018 type_section
.size
= bfd_section_size (sectp
);
13019 dwo_sections
->types
.push_back (type_section
);
13023 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13024 by PER_CU. This is for the non-DWP case.
13025 The result is NULL if DWO_NAME can't be found. */
13027 static struct dwo_file
*
13028 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13029 const char *dwo_name
, const char *comp_dir
)
13031 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13033 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
13036 if (dwarf_read_debug
)
13037 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13041 dwo_file_up
dwo_file (new struct dwo_file
);
13042 dwo_file
->dwo_name
= dwo_name
;
13043 dwo_file
->comp_dir
= comp_dir
;
13044 dwo_file
->dbfd
= std::move (dbfd
);
13046 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13047 &dwo_file
->sections
);
13049 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13052 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13053 dwo_file
->sections
.types
, dwo_file
->tus
);
13055 if (dwarf_read_debug
)
13056 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13058 return dwo_file
.release ();
13061 /* This function is mapped across the sections and remembers the offset and
13062 size of each of the DWP debugging sections common to version 1 and 2 that
13063 we are interested in. */
13066 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13067 void *dwp_file_ptr
)
13069 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13070 const struct dwop_section_names
*names
= &dwop_section_names
;
13071 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13073 /* Record the ELF section number for later lookup: this is what the
13074 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13075 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13076 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13078 /* Look for specific sections that we need. */
13079 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13081 dwp_file
->sections
.str
.s
.section
= sectp
;
13082 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13084 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13086 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13087 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13089 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13091 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13092 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13096 /* This function is mapped across the sections and remembers the offset and
13097 size of each of the DWP version 2 debugging sections that we are interested
13098 in. This is split into a separate function because we don't know if we
13099 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13102 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13104 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13105 const struct dwop_section_names
*names
= &dwop_section_names
;
13106 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13108 /* Record the ELF section number for later lookup: this is what the
13109 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13110 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13111 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13113 /* Look for specific sections that we need. */
13114 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13116 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13117 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13119 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13121 dwp_file
->sections
.info
.s
.section
= sectp
;
13122 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13124 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13126 dwp_file
->sections
.line
.s
.section
= sectp
;
13127 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13129 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13131 dwp_file
->sections
.loc
.s
.section
= sectp
;
13132 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13134 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13136 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13137 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13139 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13141 dwp_file
->sections
.macro
.s
.section
= sectp
;
13142 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13144 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13146 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13147 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13149 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13151 dwp_file
->sections
.types
.s
.section
= sectp
;
13152 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13156 /* Hash function for dwp_file loaded CUs/TUs. */
13159 hash_dwp_loaded_cutus (const void *item
)
13161 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13163 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13164 return dwo_unit
->signature
;
13167 /* Equality function for dwp_file loaded CUs/TUs. */
13170 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13172 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13173 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13175 return dua
->signature
== dub
->signature
;
13178 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13181 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13183 return htab_create_alloc_ex (3,
13184 hash_dwp_loaded_cutus
,
13185 eq_dwp_loaded_cutus
,
13187 &objfile
->objfile_obstack
,
13188 hashtab_obstack_allocate
,
13189 dummy_obstack_deallocate
);
13192 /* Try to open DWP file FILE_NAME.
13193 The result is the bfd handle of the file.
13194 If there is a problem finding or opening the file, return NULL.
13195 Upon success, the canonicalized path of the file is stored in the bfd,
13196 same as symfile_bfd_open. */
13198 static gdb_bfd_ref_ptr
13199 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13200 const char *file_name
)
13202 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13204 1 /*search_cwd*/));
13208 /* Work around upstream bug 15652.
13209 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13210 [Whether that's a "bug" is debatable, but it is getting in our way.]
13211 We have no real idea where the dwp file is, because gdb's realpath-ing
13212 of the executable's path may have discarded the needed info.
13213 [IWBN if the dwp file name was recorded in the executable, akin to
13214 .gnu_debuglink, but that doesn't exist yet.]
13215 Strip the directory from FILE_NAME and search again. */
13216 if (*debug_file_directory
!= '\0')
13218 /* Don't implicitly search the current directory here.
13219 If the user wants to search "." to handle this case,
13220 it must be added to debug-file-directory. */
13221 return try_open_dwop_file (dwarf2_per_objfile
,
13222 lbasename (file_name
), 1 /*is_dwp*/,
13229 /* Initialize the use of the DWP file for the current objfile.
13230 By convention the name of the DWP file is ${objfile}.dwp.
13231 The result is NULL if it can't be found. */
13233 static std::unique_ptr
<struct dwp_file
>
13234 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13236 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13238 /* Try to find first .dwp for the binary file before any symbolic links
13241 /* If the objfile is a debug file, find the name of the real binary
13242 file and get the name of dwp file from there. */
13243 std::string dwp_name
;
13244 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13246 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13247 const char *backlink_basename
= lbasename (backlink
->original_name
);
13249 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13252 dwp_name
= objfile
->original_name
;
13254 dwp_name
+= ".dwp";
13256 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13258 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13260 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13261 dwp_name
= objfile_name (objfile
);
13262 dwp_name
+= ".dwp";
13263 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13268 if (dwarf_read_debug
)
13269 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13270 return std::unique_ptr
<dwp_file
> ();
13273 const char *name
= bfd_get_filename (dbfd
.get ());
13274 std::unique_ptr
<struct dwp_file
> dwp_file
13275 (new struct dwp_file (name
, std::move (dbfd
)));
13277 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13278 dwp_file
->elf_sections
=
13279 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13280 dwp_file
->num_sections
, asection
*);
13282 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13283 dwarf2_locate_common_dwp_sections
,
13286 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13289 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13292 /* The DWP file version is stored in the hash table. Oh well. */
13293 if (dwp_file
->cus
&& dwp_file
->tus
13294 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13296 /* Technically speaking, we should try to limp along, but this is
13297 pretty bizarre. We use pulongest here because that's the established
13298 portability solution (e.g, we cannot use %u for uint32_t). */
13299 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13300 " TU version %s [in DWP file %s]"),
13301 pulongest (dwp_file
->cus
->version
),
13302 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13306 dwp_file
->version
= dwp_file
->cus
->version
;
13307 else if (dwp_file
->tus
)
13308 dwp_file
->version
= dwp_file
->tus
->version
;
13310 dwp_file
->version
= 2;
13312 if (dwp_file
->version
== 2)
13313 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13314 dwarf2_locate_v2_dwp_sections
,
13317 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13318 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13320 if (dwarf_read_debug
)
13322 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13323 fprintf_unfiltered (gdb_stdlog
,
13324 " %s CUs, %s TUs\n",
13325 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13326 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13332 /* Wrapper around open_and_init_dwp_file, only open it once. */
13334 static struct dwp_file
*
13335 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13337 if (! dwarf2_per_objfile
->dwp_checked
)
13339 dwarf2_per_objfile
->dwp_file
13340 = open_and_init_dwp_file (dwarf2_per_objfile
);
13341 dwarf2_per_objfile
->dwp_checked
= 1;
13343 return dwarf2_per_objfile
->dwp_file
.get ();
13346 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13347 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13348 or in the DWP file for the objfile, referenced by THIS_UNIT.
13349 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13350 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13352 This is called, for example, when wanting to read a variable with a
13353 complex location. Therefore we don't want to do file i/o for every call.
13354 Therefore we don't want to look for a DWO file on every call.
13355 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13356 then we check if we've already seen DWO_NAME, and only THEN do we check
13359 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13360 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13362 static struct dwo_unit
*
13363 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13364 const char *dwo_name
, const char *comp_dir
,
13365 ULONGEST signature
, int is_debug_types
)
13367 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13368 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13369 const char *kind
= is_debug_types
? "TU" : "CU";
13370 void **dwo_file_slot
;
13371 struct dwo_file
*dwo_file
;
13372 struct dwp_file
*dwp_file
;
13374 /* First see if there's a DWP file.
13375 If we have a DWP file but didn't find the DWO inside it, don't
13376 look for the original DWO file. It makes gdb behave differently
13377 depending on whether one is debugging in the build tree. */
13379 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13380 if (dwp_file
!= NULL
)
13382 const struct dwp_hash_table
*dwp_htab
=
13383 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13385 if (dwp_htab
!= NULL
)
13387 struct dwo_unit
*dwo_cutu
=
13388 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13389 signature
, is_debug_types
);
13391 if (dwo_cutu
!= NULL
)
13393 if (dwarf_read_debug
)
13395 fprintf_unfiltered (gdb_stdlog
,
13396 "Virtual DWO %s %s found: @%s\n",
13397 kind
, hex_string (signature
),
13398 host_address_to_string (dwo_cutu
));
13406 /* No DWP file, look for the DWO file. */
13408 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13409 dwo_name
, comp_dir
);
13410 if (*dwo_file_slot
== NULL
)
13412 /* Read in the file and build a table of the CUs/TUs it contains. */
13413 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13415 /* NOTE: This will be NULL if unable to open the file. */
13416 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13418 if (dwo_file
!= NULL
)
13420 struct dwo_unit
*dwo_cutu
= NULL
;
13422 if (is_debug_types
&& dwo_file
->tus
)
13424 struct dwo_unit find_dwo_cutu
;
13426 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13427 find_dwo_cutu
.signature
= signature
;
13429 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13431 else if (!is_debug_types
&& dwo_file
->cus
)
13433 struct dwo_unit find_dwo_cutu
;
13435 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13436 find_dwo_cutu
.signature
= signature
;
13437 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13441 if (dwo_cutu
!= NULL
)
13443 if (dwarf_read_debug
)
13445 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13446 kind
, dwo_name
, hex_string (signature
),
13447 host_address_to_string (dwo_cutu
));
13454 /* We didn't find it. This could mean a dwo_id mismatch, or
13455 someone deleted the DWO/DWP file, or the search path isn't set up
13456 correctly to find the file. */
13458 if (dwarf_read_debug
)
13460 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13461 kind
, dwo_name
, hex_string (signature
));
13464 /* This is a warning and not a complaint because it can be caused by
13465 pilot error (e.g., user accidentally deleting the DWO). */
13467 /* Print the name of the DWP file if we looked there, helps the user
13468 better diagnose the problem. */
13469 std::string dwp_text
;
13471 if (dwp_file
!= NULL
)
13472 dwp_text
= string_printf (" [in DWP file %s]",
13473 lbasename (dwp_file
->name
));
13475 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13476 " [in module %s]"),
13477 kind
, dwo_name
, hex_string (signature
),
13479 this_unit
->is_debug_types
? "TU" : "CU",
13480 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13485 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13486 See lookup_dwo_cutu_unit for details. */
13488 static struct dwo_unit
*
13489 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13490 const char *dwo_name
, const char *comp_dir
,
13491 ULONGEST signature
)
13493 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13496 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13497 See lookup_dwo_cutu_unit for details. */
13499 static struct dwo_unit
*
13500 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13501 const char *dwo_name
, const char *comp_dir
)
13503 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13506 /* Traversal function for queue_and_load_all_dwo_tus. */
13509 queue_and_load_dwo_tu (void **slot
, void *info
)
13511 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13512 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13513 ULONGEST signature
= dwo_unit
->signature
;
13514 struct signatured_type
*sig_type
=
13515 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13517 if (sig_type
!= NULL
)
13519 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13521 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13522 a real dependency of PER_CU on SIG_TYPE. That is detected later
13523 while processing PER_CU. */
13524 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13525 load_full_type_unit (sig_cu
);
13526 per_cu
->imported_symtabs_push (sig_cu
);
13532 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13533 The DWO may have the only definition of the type, though it may not be
13534 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13535 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13538 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13540 struct dwo_unit
*dwo_unit
;
13541 struct dwo_file
*dwo_file
;
13543 gdb_assert (!per_cu
->is_debug_types
);
13544 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13545 gdb_assert (per_cu
->cu
!= NULL
);
13547 dwo_unit
= per_cu
->cu
->dwo_unit
;
13548 gdb_assert (dwo_unit
!= NULL
);
13550 dwo_file
= dwo_unit
->dwo_file
;
13551 if (dwo_file
->tus
!= NULL
)
13552 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13555 /* Read in various DIEs. */
13557 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13558 Inherit only the children of the DW_AT_abstract_origin DIE not being
13559 already referenced by DW_AT_abstract_origin from the children of the
13563 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13565 struct die_info
*child_die
;
13566 sect_offset
*offsetp
;
13567 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13568 struct die_info
*origin_die
;
13569 /* Iterator of the ORIGIN_DIE children. */
13570 struct die_info
*origin_child_die
;
13571 struct attribute
*attr
;
13572 struct dwarf2_cu
*origin_cu
;
13573 struct pending
**origin_previous_list_in_scope
;
13575 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13579 /* Note that following die references may follow to a die in a
13583 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13585 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13587 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13588 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13590 if (die
->tag
!= origin_die
->tag
13591 && !(die
->tag
== DW_TAG_inlined_subroutine
13592 && origin_die
->tag
== DW_TAG_subprogram
))
13593 complaint (_("DIE %s and its abstract origin %s have different tags"),
13594 sect_offset_str (die
->sect_off
),
13595 sect_offset_str (origin_die
->sect_off
));
13597 std::vector
<sect_offset
> offsets
;
13599 for (child_die
= die
->child
;
13600 child_die
&& child_die
->tag
;
13601 child_die
= sibling_die (child_die
))
13603 struct die_info
*child_origin_die
;
13604 struct dwarf2_cu
*child_origin_cu
;
13606 /* We are trying to process concrete instance entries:
13607 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13608 it's not relevant to our analysis here. i.e. detecting DIEs that are
13609 present in the abstract instance but not referenced in the concrete
13611 if (child_die
->tag
== DW_TAG_call_site
13612 || child_die
->tag
== DW_TAG_GNU_call_site
)
13615 /* For each CHILD_DIE, find the corresponding child of
13616 ORIGIN_DIE. If there is more than one layer of
13617 DW_AT_abstract_origin, follow them all; there shouldn't be,
13618 but GCC versions at least through 4.4 generate this (GCC PR
13620 child_origin_die
= child_die
;
13621 child_origin_cu
= cu
;
13624 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13628 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13632 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13633 counterpart may exist. */
13634 if (child_origin_die
!= child_die
)
13636 if (child_die
->tag
!= child_origin_die
->tag
13637 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13638 && child_origin_die
->tag
== DW_TAG_subprogram
))
13639 complaint (_("Child DIE %s and its abstract origin %s have "
13641 sect_offset_str (child_die
->sect_off
),
13642 sect_offset_str (child_origin_die
->sect_off
));
13643 if (child_origin_die
->parent
!= origin_die
)
13644 complaint (_("Child DIE %s and its abstract origin %s have "
13645 "different parents"),
13646 sect_offset_str (child_die
->sect_off
),
13647 sect_offset_str (child_origin_die
->sect_off
));
13649 offsets
.push_back (child_origin_die
->sect_off
);
13652 std::sort (offsets
.begin (), offsets
.end ());
13653 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13654 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13655 if (offsetp
[-1] == *offsetp
)
13656 complaint (_("Multiple children of DIE %s refer "
13657 "to DIE %s as their abstract origin"),
13658 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13660 offsetp
= offsets
.data ();
13661 origin_child_die
= origin_die
->child
;
13662 while (origin_child_die
&& origin_child_die
->tag
)
13664 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13665 while (offsetp
< offsets_end
13666 && *offsetp
< origin_child_die
->sect_off
)
13668 if (offsetp
>= offsets_end
13669 || *offsetp
> origin_child_die
->sect_off
)
13671 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13672 Check whether we're already processing ORIGIN_CHILD_DIE.
13673 This can happen with mutually referenced abstract_origins.
13675 if (!origin_child_die
->in_process
)
13676 process_die (origin_child_die
, origin_cu
);
13678 origin_child_die
= sibling_die (origin_child_die
);
13680 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13682 if (cu
!= origin_cu
)
13683 compute_delayed_physnames (origin_cu
);
13687 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13689 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13690 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13691 struct context_stack
*newobj
;
13694 struct die_info
*child_die
;
13695 struct attribute
*attr
, *call_line
, *call_file
;
13697 CORE_ADDR baseaddr
;
13698 struct block
*block
;
13699 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13700 std::vector
<struct symbol
*> template_args
;
13701 struct template_symbol
*templ_func
= NULL
;
13705 /* If we do not have call site information, we can't show the
13706 caller of this inlined function. That's too confusing, so
13707 only use the scope for local variables. */
13708 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13709 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13710 if (call_line
== NULL
|| call_file
== NULL
)
13712 read_lexical_block_scope (die
, cu
);
13717 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
13719 name
= dwarf2_name (die
, cu
);
13721 /* Ignore functions with missing or empty names. These are actually
13722 illegal according to the DWARF standard. */
13725 complaint (_("missing name for subprogram DIE at %s"),
13726 sect_offset_str (die
->sect_off
));
13730 /* Ignore functions with missing or invalid low and high pc attributes. */
13731 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13732 <= PC_BOUNDS_INVALID
)
13734 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13735 if (!attr
|| !DW_UNSND (attr
))
13736 complaint (_("cannot get low and high bounds "
13737 "for subprogram DIE at %s"),
13738 sect_offset_str (die
->sect_off
));
13742 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13743 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13745 /* If we have any template arguments, then we must allocate a
13746 different sort of symbol. */
13747 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13749 if (child_die
->tag
== DW_TAG_template_type_param
13750 || child_die
->tag
== DW_TAG_template_value_param
)
13752 templ_func
= allocate_template_symbol (objfile
);
13753 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13758 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13759 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13760 (struct symbol
*) templ_func
);
13762 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13763 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13766 /* If there is a location expression for DW_AT_frame_base, record
13768 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13769 if (attr
!= nullptr)
13770 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13772 /* If there is a location for the static link, record it. */
13773 newobj
->static_link
= NULL
;
13774 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13775 if (attr
!= nullptr)
13777 newobj
->static_link
13778 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13779 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13780 dwarf2_per_cu_addr_type (cu
->per_cu
));
13783 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13785 if (die
->child
!= NULL
)
13787 child_die
= die
->child
;
13788 while (child_die
&& child_die
->tag
)
13790 if (child_die
->tag
== DW_TAG_template_type_param
13791 || child_die
->tag
== DW_TAG_template_value_param
)
13793 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13796 template_args
.push_back (arg
);
13799 process_die (child_die
, cu
);
13800 child_die
= sibling_die (child_die
);
13804 inherit_abstract_dies (die
, cu
);
13806 /* If we have a DW_AT_specification, we might need to import using
13807 directives from the context of the specification DIE. See the
13808 comment in determine_prefix. */
13809 if (cu
->language
== language_cplus
13810 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13812 struct dwarf2_cu
*spec_cu
= cu
;
13813 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13817 child_die
= spec_die
->child
;
13818 while (child_die
&& child_die
->tag
)
13820 if (child_die
->tag
== DW_TAG_imported_module
)
13821 process_die (child_die
, spec_cu
);
13822 child_die
= sibling_die (child_die
);
13825 /* In some cases, GCC generates specification DIEs that
13826 themselves contain DW_AT_specification attributes. */
13827 spec_die
= die_specification (spec_die
, &spec_cu
);
13831 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13832 /* Make a block for the local symbols within. */
13833 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13834 cstk
.static_link
, lowpc
, highpc
);
13836 /* For C++, set the block's scope. */
13837 if ((cu
->language
== language_cplus
13838 || cu
->language
== language_fortran
13839 || cu
->language
== language_d
13840 || cu
->language
== language_rust
)
13841 && cu
->processing_has_namespace_info
)
13842 block_set_scope (block
, determine_prefix (die
, cu
),
13843 &objfile
->objfile_obstack
);
13845 /* If we have address ranges, record them. */
13846 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13848 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13850 /* Attach template arguments to function. */
13851 if (!template_args
.empty ())
13853 gdb_assert (templ_func
!= NULL
);
13855 templ_func
->n_template_arguments
= template_args
.size ();
13856 templ_func
->template_arguments
13857 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13858 templ_func
->n_template_arguments
);
13859 memcpy (templ_func
->template_arguments
,
13860 template_args
.data (),
13861 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13863 /* Make sure that the symtab is set on the new symbols. Even
13864 though they don't appear in this symtab directly, other parts
13865 of gdb assume that symbols do, and this is reasonably
13867 for (symbol
*sym
: template_args
)
13868 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13871 /* In C++, we can have functions nested inside functions (e.g., when
13872 a function declares a class that has methods). This means that
13873 when we finish processing a function scope, we may need to go
13874 back to building a containing block's symbol lists. */
13875 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13876 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13878 /* If we've finished processing a top-level function, subsequent
13879 symbols go in the file symbol list. */
13880 if (cu
->get_builder ()->outermost_context_p ())
13881 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13884 /* Process all the DIES contained within a lexical block scope. Start
13885 a new scope, process the dies, and then close the scope. */
13888 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13890 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13891 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13892 CORE_ADDR lowpc
, highpc
;
13893 struct die_info
*child_die
;
13894 CORE_ADDR baseaddr
;
13896 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
13898 /* Ignore blocks with missing or invalid low and high pc attributes. */
13899 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13900 as multiple lexical blocks? Handling children in a sane way would
13901 be nasty. Might be easier to properly extend generic blocks to
13902 describe ranges. */
13903 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13905 case PC_BOUNDS_NOT_PRESENT
:
13906 /* DW_TAG_lexical_block has no attributes, process its children as if
13907 there was no wrapping by that DW_TAG_lexical_block.
13908 GCC does no longer produces such DWARF since GCC r224161. */
13909 for (child_die
= die
->child
;
13910 child_die
!= NULL
&& child_die
->tag
;
13911 child_die
= sibling_die (child_die
))
13912 process_die (child_die
, cu
);
13914 case PC_BOUNDS_INVALID
:
13917 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13918 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13920 cu
->get_builder ()->push_context (0, lowpc
);
13921 if (die
->child
!= NULL
)
13923 child_die
= die
->child
;
13924 while (child_die
&& child_die
->tag
)
13926 process_die (child_die
, cu
);
13927 child_die
= sibling_die (child_die
);
13930 inherit_abstract_dies (die
, cu
);
13931 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13933 if (*cu
->get_builder ()->get_local_symbols () != NULL
13934 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13936 struct block
*block
13937 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13938 cstk
.start_addr
, highpc
);
13940 /* Note that recording ranges after traversing children, as we
13941 do here, means that recording a parent's ranges entails
13942 walking across all its children's ranges as they appear in
13943 the address map, which is quadratic behavior.
13945 It would be nicer to record the parent's ranges before
13946 traversing its children, simply overriding whatever you find
13947 there. But since we don't even decide whether to create a
13948 block until after we've traversed its children, that's hard
13950 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13952 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13953 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13956 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13959 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13961 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13962 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13963 CORE_ADDR pc
, baseaddr
;
13964 struct attribute
*attr
;
13965 struct call_site
*call_site
, call_site_local
;
13968 struct die_info
*child_die
;
13970 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
13972 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13975 /* This was a pre-DWARF-5 GNU extension alias
13976 for DW_AT_call_return_pc. */
13977 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13981 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13982 "DIE %s [in module %s]"),
13983 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13986 pc
= attr_value_as_address (attr
) + baseaddr
;
13987 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13989 if (cu
->call_site_htab
== NULL
)
13990 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13991 NULL
, &objfile
->objfile_obstack
,
13992 hashtab_obstack_allocate
, NULL
);
13993 call_site_local
.pc
= pc
;
13994 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13997 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13998 "DIE %s [in module %s]"),
13999 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
14000 objfile_name (objfile
));
14004 /* Count parameters at the caller. */
14007 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14008 child_die
= sibling_die (child_die
))
14010 if (child_die
->tag
!= DW_TAG_call_site_parameter
14011 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14013 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
14014 "DW_TAG_call_site child DIE %s [in module %s]"),
14015 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14016 objfile_name (objfile
));
14024 = ((struct call_site
*)
14025 obstack_alloc (&objfile
->objfile_obstack
,
14026 sizeof (*call_site
)
14027 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14029 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14030 call_site
->pc
= pc
;
14032 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14033 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14035 struct die_info
*func_die
;
14037 /* Skip also over DW_TAG_inlined_subroutine. */
14038 for (func_die
= die
->parent
;
14039 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14040 && func_die
->tag
!= DW_TAG_subroutine_type
;
14041 func_die
= func_die
->parent
);
14043 /* DW_AT_call_all_calls is a superset
14044 of DW_AT_call_all_tail_calls. */
14046 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14047 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14048 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14049 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14051 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14052 not complete. But keep CALL_SITE for look ups via call_site_htab,
14053 both the initial caller containing the real return address PC and
14054 the final callee containing the current PC of a chain of tail
14055 calls do not need to have the tail call list complete. But any
14056 function candidate for a virtual tail call frame searched via
14057 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14058 determined unambiguously. */
14062 struct type
*func_type
= NULL
;
14065 func_type
= get_die_type (func_die
, cu
);
14066 if (func_type
!= NULL
)
14068 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14070 /* Enlist this call site to the function. */
14071 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14072 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14075 complaint (_("Cannot find function owning DW_TAG_call_site "
14076 "DIE %s [in module %s]"),
14077 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14081 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14083 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14085 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14088 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14089 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14091 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14092 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14093 /* Keep NULL DWARF_BLOCK. */;
14094 else if (attr_form_is_block (attr
))
14096 struct dwarf2_locexpr_baton
*dlbaton
;
14098 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14099 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14100 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14101 dlbaton
->per_cu
= cu
->per_cu
;
14103 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14105 else if (attr_form_is_ref (attr
))
14107 struct dwarf2_cu
*target_cu
= cu
;
14108 struct die_info
*target_die
;
14110 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14111 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14112 if (die_is_declaration (target_die
, target_cu
))
14114 const char *target_physname
;
14116 /* Prefer the mangled name; otherwise compute the demangled one. */
14117 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14118 if (target_physname
== NULL
)
14119 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14120 if (target_physname
== NULL
)
14121 complaint (_("DW_AT_call_target target DIE has invalid "
14122 "physname, for referencing DIE %s [in module %s]"),
14123 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14125 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14131 /* DW_AT_entry_pc should be preferred. */
14132 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14133 <= PC_BOUNDS_INVALID
)
14134 complaint (_("DW_AT_call_target target DIE has invalid "
14135 "low pc, for referencing DIE %s [in module %s]"),
14136 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14139 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14140 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14145 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14146 "block nor reference, for DIE %s [in module %s]"),
14147 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14149 call_site
->per_cu
= cu
->per_cu
;
14151 for (child_die
= die
->child
;
14152 child_die
&& child_die
->tag
;
14153 child_die
= sibling_die (child_die
))
14155 struct call_site_parameter
*parameter
;
14156 struct attribute
*loc
, *origin
;
14158 if (child_die
->tag
!= DW_TAG_call_site_parameter
14159 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14161 /* Already printed the complaint above. */
14165 gdb_assert (call_site
->parameter_count
< nparams
);
14166 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14168 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14169 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14170 register is contained in DW_AT_call_value. */
14172 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14173 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14174 if (origin
== NULL
)
14176 /* This was a pre-DWARF-5 GNU extension alias
14177 for DW_AT_call_parameter. */
14178 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14180 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14182 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14184 sect_offset sect_off
14185 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14186 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14188 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14189 binding can be done only inside one CU. Such referenced DIE
14190 therefore cannot be even moved to DW_TAG_partial_unit. */
14191 complaint (_("DW_AT_call_parameter offset is not in CU for "
14192 "DW_TAG_call_site child DIE %s [in module %s]"),
14193 sect_offset_str (child_die
->sect_off
),
14194 objfile_name (objfile
));
14197 parameter
->u
.param_cu_off
14198 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14200 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14202 complaint (_("No DW_FORM_block* DW_AT_location for "
14203 "DW_TAG_call_site child DIE %s [in module %s]"),
14204 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14209 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14210 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14211 if (parameter
->u
.dwarf_reg
!= -1)
14212 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14213 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14214 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14215 ¶meter
->u
.fb_offset
))
14216 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14219 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14220 "for DW_FORM_block* DW_AT_location is supported for "
14221 "DW_TAG_call_site child DIE %s "
14223 sect_offset_str (child_die
->sect_off
),
14224 objfile_name (objfile
));
14229 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14231 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14232 if (!attr_form_is_block (attr
))
14234 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14235 "DW_TAG_call_site child DIE %s [in module %s]"),
14236 sect_offset_str (child_die
->sect_off
),
14237 objfile_name (objfile
));
14240 parameter
->value
= DW_BLOCK (attr
)->data
;
14241 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14243 /* Parameters are not pre-cleared by memset above. */
14244 parameter
->data_value
= NULL
;
14245 parameter
->data_value_size
= 0;
14246 call_site
->parameter_count
++;
14248 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14250 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14251 if (attr
!= nullptr)
14253 if (!attr_form_is_block (attr
))
14254 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14255 "DW_TAG_call_site child DIE %s [in module %s]"),
14256 sect_offset_str (child_die
->sect_off
),
14257 objfile_name (objfile
));
14260 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14261 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14267 /* Helper function for read_variable. If DIE represents a virtual
14268 table, then return the type of the concrete object that is
14269 associated with the virtual table. Otherwise, return NULL. */
14271 static struct type
*
14272 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14274 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14278 /* Find the type DIE. */
14279 struct die_info
*type_die
= NULL
;
14280 struct dwarf2_cu
*type_cu
= cu
;
14282 if (attr_form_is_ref (attr
))
14283 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14284 if (type_die
== NULL
)
14287 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14289 return die_containing_type (type_die
, type_cu
);
14292 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14295 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14297 struct rust_vtable_symbol
*storage
= NULL
;
14299 if (cu
->language
== language_rust
)
14301 struct type
*containing_type
= rust_containing_type (die
, cu
);
14303 if (containing_type
!= NULL
)
14305 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14307 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
14308 initialize_objfile_symbol (storage
);
14309 storage
->concrete_type
= containing_type
;
14310 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14314 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14315 struct attribute
*abstract_origin
14316 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14317 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14318 if (res
== NULL
&& loc
&& abstract_origin
)
14320 /* We have a variable without a name, but with a location and an abstract
14321 origin. This may be a concrete instance of an abstract variable
14322 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14324 struct dwarf2_cu
*origin_cu
= cu
;
14325 struct die_info
*origin_die
14326 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14327 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14328 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14332 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14333 reading .debug_rnglists.
14334 Callback's type should be:
14335 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14336 Return true if the attributes are present and valid, otherwise,
14339 template <typename Callback
>
14341 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14342 Callback
&&callback
)
14344 struct dwarf2_per_objfile
*dwarf2_per_objfile
14345 = cu
->per_cu
->dwarf2_per_objfile
;
14346 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14347 bfd
*obfd
= objfile
->obfd
;
14348 /* Base address selection entry. */
14351 const gdb_byte
*buffer
;
14352 CORE_ADDR baseaddr
;
14353 bool overflow
= false;
14355 found_base
= cu
->base_known
;
14356 base
= cu
->base_address
;
14358 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14359 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14361 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14365 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14367 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
14371 /* Initialize it due to a false compiler warning. */
14372 CORE_ADDR range_beginning
= 0, range_end
= 0;
14373 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14374 + dwarf2_per_objfile
->rnglists
.size
);
14375 unsigned int bytes_read
;
14377 if (buffer
== buf_end
)
14382 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14385 case DW_RLE_end_of_list
:
14387 case DW_RLE_base_address
:
14388 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14393 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14395 buffer
+= bytes_read
;
14397 case DW_RLE_start_length
:
14398 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14403 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14404 buffer
+= bytes_read
;
14405 range_end
= (range_beginning
14406 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14407 buffer
+= bytes_read
;
14408 if (buffer
> buf_end
)
14414 case DW_RLE_offset_pair
:
14415 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14416 buffer
+= bytes_read
;
14417 if (buffer
> buf_end
)
14422 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14423 buffer
+= bytes_read
;
14424 if (buffer
> buf_end
)
14430 case DW_RLE_start_end
:
14431 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14436 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14437 buffer
+= bytes_read
;
14438 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14439 buffer
+= bytes_read
;
14442 complaint (_("Invalid .debug_rnglists data (no base address)"));
14445 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14447 if (rlet
== DW_RLE_base_address
)
14452 /* We have no valid base address for the ranges
14454 complaint (_("Invalid .debug_rnglists data (no base address)"));
14458 if (range_beginning
> range_end
)
14460 /* Inverted range entries are invalid. */
14461 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14465 /* Empty range entries have no effect. */
14466 if (range_beginning
== range_end
)
14469 range_beginning
+= base
;
14472 /* A not-uncommon case of bad debug info.
14473 Don't pollute the addrmap with bad data. */
14474 if (range_beginning
+ baseaddr
== 0
14475 && !dwarf2_per_objfile
->has_section_at_zero
)
14477 complaint (_(".debug_rnglists entry has start address of zero"
14478 " [in module %s]"), objfile_name (objfile
));
14482 callback (range_beginning
, range_end
);
14487 complaint (_("Offset %d is not terminated "
14488 "for DW_AT_ranges attribute"),
14496 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14497 Callback's type should be:
14498 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14499 Return 1 if the attributes are present and valid, otherwise, return 0. */
14501 template <typename Callback
>
14503 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14504 Callback
&&callback
)
14506 struct dwarf2_per_objfile
*dwarf2_per_objfile
14507 = cu
->per_cu
->dwarf2_per_objfile
;
14508 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14509 struct comp_unit_head
*cu_header
= &cu
->header
;
14510 bfd
*obfd
= objfile
->obfd
;
14511 unsigned int addr_size
= cu_header
->addr_size
;
14512 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14513 /* Base address selection entry. */
14516 unsigned int dummy
;
14517 const gdb_byte
*buffer
;
14518 CORE_ADDR baseaddr
;
14520 if (cu_header
->version
>= 5)
14521 return dwarf2_rnglists_process (offset
, cu
, callback
);
14523 found_base
= cu
->base_known
;
14524 base
= cu
->base_address
;
14526 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14527 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14529 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14533 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14535 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
14539 CORE_ADDR range_beginning
, range_end
;
14541 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14542 buffer
+= addr_size
;
14543 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14544 buffer
+= addr_size
;
14545 offset
+= 2 * addr_size
;
14547 /* An end of list marker is a pair of zero addresses. */
14548 if (range_beginning
== 0 && range_end
== 0)
14549 /* Found the end of list entry. */
14552 /* Each base address selection entry is a pair of 2 values.
14553 The first is the largest possible address, the second is
14554 the base address. Check for a base address here. */
14555 if ((range_beginning
& mask
) == mask
)
14557 /* If we found the largest possible address, then we already
14558 have the base address in range_end. */
14566 /* We have no valid base address for the ranges
14568 complaint (_("Invalid .debug_ranges data (no base address)"));
14572 if (range_beginning
> range_end
)
14574 /* Inverted range entries are invalid. */
14575 complaint (_("Invalid .debug_ranges data (inverted range)"));
14579 /* Empty range entries have no effect. */
14580 if (range_beginning
== range_end
)
14583 range_beginning
+= base
;
14586 /* A not-uncommon case of bad debug info.
14587 Don't pollute the addrmap with bad data. */
14588 if (range_beginning
+ baseaddr
== 0
14589 && !dwarf2_per_objfile
->has_section_at_zero
)
14591 complaint (_(".debug_ranges entry has start address of zero"
14592 " [in module %s]"), objfile_name (objfile
));
14596 callback (range_beginning
, range_end
);
14602 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14603 Return 1 if the attributes are present and valid, otherwise, return 0.
14604 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14607 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14608 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14609 struct partial_symtab
*ranges_pst
)
14611 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14612 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14613 const CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
14616 CORE_ADDR high
= 0;
14619 retval
= dwarf2_ranges_process (offset
, cu
,
14620 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14622 if (ranges_pst
!= NULL
)
14627 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14628 range_beginning
+ baseaddr
)
14630 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14631 range_end
+ baseaddr
)
14633 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14634 lowpc
, highpc
- 1, ranges_pst
);
14637 /* FIXME: This is recording everything as a low-high
14638 segment of consecutive addresses. We should have a
14639 data structure for discontiguous block ranges
14643 low
= range_beginning
;
14649 if (range_beginning
< low
)
14650 low
= range_beginning
;
14651 if (range_end
> high
)
14659 /* If the first entry is an end-of-list marker, the range
14660 describes an empty scope, i.e. no instructions. */
14666 *high_return
= high
;
14670 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14671 definition for the return value. *LOWPC and *HIGHPC are set iff
14672 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14674 static enum pc_bounds_kind
14675 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14676 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14677 struct partial_symtab
*pst
)
14679 struct dwarf2_per_objfile
*dwarf2_per_objfile
14680 = cu
->per_cu
->dwarf2_per_objfile
;
14681 struct attribute
*attr
;
14682 struct attribute
*attr_high
;
14684 CORE_ADDR high
= 0;
14685 enum pc_bounds_kind ret
;
14687 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14690 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14691 if (attr
!= nullptr)
14693 low
= attr_value_as_address (attr
);
14694 high
= attr_value_as_address (attr_high
);
14695 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14699 /* Found high w/o low attribute. */
14700 return PC_BOUNDS_INVALID
;
14702 /* Found consecutive range of addresses. */
14703 ret
= PC_BOUNDS_HIGH_LOW
;
14707 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14710 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14711 We take advantage of the fact that DW_AT_ranges does not appear
14712 in DW_TAG_compile_unit of DWO files. */
14713 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14714 unsigned int ranges_offset
= (DW_UNSND (attr
)
14715 + (need_ranges_base
14719 /* Value of the DW_AT_ranges attribute is the offset in the
14720 .debug_ranges section. */
14721 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14722 return PC_BOUNDS_INVALID
;
14723 /* Found discontinuous range of addresses. */
14724 ret
= PC_BOUNDS_RANGES
;
14727 return PC_BOUNDS_NOT_PRESENT
;
14730 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14732 return PC_BOUNDS_INVALID
;
14734 /* When using the GNU linker, .gnu.linkonce. sections are used to
14735 eliminate duplicate copies of functions and vtables and such.
14736 The linker will arbitrarily choose one and discard the others.
14737 The AT_*_pc values for such functions refer to local labels in
14738 these sections. If the section from that file was discarded, the
14739 labels are not in the output, so the relocs get a value of 0.
14740 If this is a discarded function, mark the pc bounds as invalid,
14741 so that GDB will ignore it. */
14742 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14743 return PC_BOUNDS_INVALID
;
14751 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14752 its low and high PC addresses. Do nothing if these addresses could not
14753 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14754 and HIGHPC to the high address if greater than HIGHPC. */
14757 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14758 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14759 struct dwarf2_cu
*cu
)
14761 CORE_ADDR low
, high
;
14762 struct die_info
*child
= die
->child
;
14764 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14766 *lowpc
= std::min (*lowpc
, low
);
14767 *highpc
= std::max (*highpc
, high
);
14770 /* If the language does not allow nested subprograms (either inside
14771 subprograms or lexical blocks), we're done. */
14772 if (cu
->language
!= language_ada
)
14775 /* Check all the children of the given DIE. If it contains nested
14776 subprograms, then check their pc bounds. Likewise, we need to
14777 check lexical blocks as well, as they may also contain subprogram
14779 while (child
&& child
->tag
)
14781 if (child
->tag
== DW_TAG_subprogram
14782 || child
->tag
== DW_TAG_lexical_block
)
14783 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14784 child
= sibling_die (child
);
14788 /* Get the low and high pc's represented by the scope DIE, and store
14789 them in *LOWPC and *HIGHPC. If the correct values can't be
14790 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14793 get_scope_pc_bounds (struct die_info
*die
,
14794 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14795 struct dwarf2_cu
*cu
)
14797 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14798 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14799 CORE_ADDR current_low
, current_high
;
14801 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14802 >= PC_BOUNDS_RANGES
)
14804 best_low
= current_low
;
14805 best_high
= current_high
;
14809 struct die_info
*child
= die
->child
;
14811 while (child
&& child
->tag
)
14813 switch (child
->tag
) {
14814 case DW_TAG_subprogram
:
14815 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14817 case DW_TAG_namespace
:
14818 case DW_TAG_module
:
14819 /* FIXME: carlton/2004-01-16: Should we do this for
14820 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14821 that current GCC's always emit the DIEs corresponding
14822 to definitions of methods of classes as children of a
14823 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14824 the DIEs giving the declarations, which could be
14825 anywhere). But I don't see any reason why the
14826 standards says that they have to be there. */
14827 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14829 if (current_low
!= ((CORE_ADDR
) -1))
14831 best_low
= std::min (best_low
, current_low
);
14832 best_high
= std::max (best_high
, current_high
);
14840 child
= sibling_die (child
);
14845 *highpc
= best_high
;
14848 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14852 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14853 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14855 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14856 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14857 struct attribute
*attr
;
14858 struct attribute
*attr_high
;
14860 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14863 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14864 if (attr
!= nullptr)
14866 CORE_ADDR low
= attr_value_as_address (attr
);
14867 CORE_ADDR high
= attr_value_as_address (attr_high
);
14869 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14872 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14873 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14874 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14878 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14879 if (attr
!= nullptr)
14881 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14882 We take advantage of the fact that DW_AT_ranges does not appear
14883 in DW_TAG_compile_unit of DWO files. */
14884 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14886 /* The value of the DW_AT_ranges attribute is the offset of the
14887 address range list in the .debug_ranges section. */
14888 unsigned long offset
= (DW_UNSND (attr
)
14889 + (need_ranges_base
? cu
->ranges_base
: 0));
14891 std::vector
<blockrange
> blockvec
;
14892 dwarf2_ranges_process (offset
, cu
,
14893 [&] (CORE_ADDR start
, CORE_ADDR end
)
14897 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14898 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14899 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14900 blockvec
.emplace_back (start
, end
);
14903 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14907 /* Check whether the producer field indicates either of GCC < 4.6, or the
14908 Intel C/C++ compiler, and cache the result in CU. */
14911 check_producer (struct dwarf2_cu
*cu
)
14915 if (cu
->producer
== NULL
)
14917 /* For unknown compilers expect their behavior is DWARF version
14920 GCC started to support .debug_types sections by -gdwarf-4 since
14921 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14922 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14923 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14924 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14926 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14928 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14929 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14931 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14933 cu
->producer_is_icc
= true;
14934 cu
->producer_is_icc_lt_14
= major
< 14;
14936 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14937 cu
->producer_is_codewarrior
= true;
14940 /* For other non-GCC compilers, expect their behavior is DWARF version
14944 cu
->checked_producer
= true;
14947 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14948 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14949 during 4.6.0 experimental. */
14952 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14954 if (!cu
->checked_producer
)
14955 check_producer (cu
);
14957 return cu
->producer_is_gxx_lt_4_6
;
14961 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14962 with incorrect is_stmt attributes. */
14965 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14967 if (!cu
->checked_producer
)
14968 check_producer (cu
);
14970 return cu
->producer_is_codewarrior
;
14973 /* Return the default accessibility type if it is not overridden by
14974 DW_AT_accessibility. */
14976 static enum dwarf_access_attribute
14977 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14979 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14981 /* The default DWARF 2 accessibility for members is public, the default
14982 accessibility for inheritance is private. */
14984 if (die
->tag
!= DW_TAG_inheritance
)
14985 return DW_ACCESS_public
;
14987 return DW_ACCESS_private
;
14991 /* DWARF 3+ defines the default accessibility a different way. The same
14992 rules apply now for DW_TAG_inheritance as for the members and it only
14993 depends on the container kind. */
14995 if (die
->parent
->tag
== DW_TAG_class_type
)
14996 return DW_ACCESS_private
;
14998 return DW_ACCESS_public
;
15002 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15003 offset. If the attribute was not found return 0, otherwise return
15004 1. If it was found but could not properly be handled, set *OFFSET
15008 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15011 struct attribute
*attr
;
15013 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15018 /* Note that we do not check for a section offset first here.
15019 This is because DW_AT_data_member_location is new in DWARF 4,
15020 so if we see it, we can assume that a constant form is really
15021 a constant and not a section offset. */
15022 if (attr_form_is_constant (attr
))
15023 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15024 else if (attr_form_is_section_offset (attr
))
15025 dwarf2_complex_location_expr_complaint ();
15026 else if (attr_form_is_block (attr
))
15027 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15029 dwarf2_complex_location_expr_complaint ();
15037 /* Add an aggregate field to the field list. */
15040 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15041 struct dwarf2_cu
*cu
)
15043 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15044 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15045 struct nextfield
*new_field
;
15046 struct attribute
*attr
;
15048 const char *fieldname
= "";
15050 if (die
->tag
== DW_TAG_inheritance
)
15052 fip
->baseclasses
.emplace_back ();
15053 new_field
= &fip
->baseclasses
.back ();
15057 fip
->fields
.emplace_back ();
15058 new_field
= &fip
->fields
.back ();
15063 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15064 if (attr
!= nullptr)
15065 new_field
->accessibility
= DW_UNSND (attr
);
15067 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15068 if (new_field
->accessibility
!= DW_ACCESS_public
)
15069 fip
->non_public_fields
= 1;
15071 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15072 if (attr
!= nullptr)
15073 new_field
->virtuality
= DW_UNSND (attr
);
15075 new_field
->virtuality
= DW_VIRTUALITY_none
;
15077 fp
= &new_field
->field
;
15079 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15083 /* Data member other than a C++ static data member. */
15085 /* Get type of field. */
15086 fp
->type
= die_type (die
, cu
);
15088 SET_FIELD_BITPOS (*fp
, 0);
15090 /* Get bit size of field (zero if none). */
15091 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15092 if (attr
!= nullptr)
15094 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15098 FIELD_BITSIZE (*fp
) = 0;
15101 /* Get bit offset of field. */
15102 if (handle_data_member_location (die
, cu
, &offset
))
15103 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15104 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15105 if (attr
!= nullptr)
15107 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15109 /* For big endian bits, the DW_AT_bit_offset gives the
15110 additional bit offset from the MSB of the containing
15111 anonymous object to the MSB of the field. We don't
15112 have to do anything special since we don't need to
15113 know the size of the anonymous object. */
15114 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15118 /* For little endian bits, compute the bit offset to the
15119 MSB of the anonymous object, subtract off the number of
15120 bits from the MSB of the field to the MSB of the
15121 object, and then subtract off the number of bits of
15122 the field itself. The result is the bit offset of
15123 the LSB of the field. */
15124 int anonymous_size
;
15125 int bit_offset
= DW_UNSND (attr
);
15127 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15128 if (attr
!= nullptr)
15130 /* The size of the anonymous object containing
15131 the bit field is explicit, so use the
15132 indicated size (in bytes). */
15133 anonymous_size
= DW_UNSND (attr
);
15137 /* The size of the anonymous object containing
15138 the bit field must be inferred from the type
15139 attribute of the data member containing the
15141 anonymous_size
= TYPE_LENGTH (fp
->type
);
15143 SET_FIELD_BITPOS (*fp
,
15144 (FIELD_BITPOS (*fp
)
15145 + anonymous_size
* bits_per_byte
15146 - bit_offset
- FIELD_BITSIZE (*fp
)));
15149 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15151 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15152 + dwarf2_get_attr_constant_value (attr
, 0)));
15154 /* Get name of field. */
15155 fieldname
= dwarf2_name (die
, cu
);
15156 if (fieldname
== NULL
)
15159 /* The name is already allocated along with this objfile, so we don't
15160 need to duplicate it for the type. */
15161 fp
->name
= fieldname
;
15163 /* Change accessibility for artificial fields (e.g. virtual table
15164 pointer or virtual base class pointer) to private. */
15165 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15167 FIELD_ARTIFICIAL (*fp
) = 1;
15168 new_field
->accessibility
= DW_ACCESS_private
;
15169 fip
->non_public_fields
= 1;
15172 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15174 /* C++ static member. */
15176 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15177 is a declaration, but all versions of G++ as of this writing
15178 (so through at least 3.2.1) incorrectly generate
15179 DW_TAG_variable tags. */
15181 const char *physname
;
15183 /* Get name of field. */
15184 fieldname
= dwarf2_name (die
, cu
);
15185 if (fieldname
== NULL
)
15188 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15190 /* Only create a symbol if this is an external value.
15191 new_symbol checks this and puts the value in the global symbol
15192 table, which we want. If it is not external, new_symbol
15193 will try to put the value in cu->list_in_scope which is wrong. */
15194 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15196 /* A static const member, not much different than an enum as far as
15197 we're concerned, except that we can support more types. */
15198 new_symbol (die
, NULL
, cu
);
15201 /* Get physical name. */
15202 physname
= dwarf2_physname (fieldname
, die
, cu
);
15204 /* The name is already allocated along with this objfile, so we don't
15205 need to duplicate it for the type. */
15206 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15207 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15208 FIELD_NAME (*fp
) = fieldname
;
15210 else if (die
->tag
== DW_TAG_inheritance
)
15214 /* C++ base class field. */
15215 if (handle_data_member_location (die
, cu
, &offset
))
15216 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15217 FIELD_BITSIZE (*fp
) = 0;
15218 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15219 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15221 else if (die
->tag
== DW_TAG_variant_part
)
15223 /* process_structure_scope will treat this DIE as a union. */
15224 process_structure_scope (die
, cu
);
15226 /* The variant part is relative to the start of the enclosing
15228 SET_FIELD_BITPOS (*fp
, 0);
15229 fp
->type
= get_die_type (die
, cu
);
15230 fp
->artificial
= 1;
15231 fp
->name
= "<<variant>>";
15233 /* Normally a DW_TAG_variant_part won't have a size, but our
15234 representation requires one, so set it to the maximum of the
15235 child sizes, being sure to account for the offset at which
15236 each child is seen. */
15237 if (TYPE_LENGTH (fp
->type
) == 0)
15240 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15242 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
15243 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
15247 TYPE_LENGTH (fp
->type
) = max
;
15251 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15254 /* Can the type given by DIE define another type? */
15257 type_can_define_types (const struct die_info
*die
)
15261 case DW_TAG_typedef
:
15262 case DW_TAG_class_type
:
15263 case DW_TAG_structure_type
:
15264 case DW_TAG_union_type
:
15265 case DW_TAG_enumeration_type
:
15273 /* Add a type definition defined in the scope of the FIP's class. */
15276 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15277 struct dwarf2_cu
*cu
)
15279 struct decl_field fp
;
15280 memset (&fp
, 0, sizeof (fp
));
15282 gdb_assert (type_can_define_types (die
));
15284 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15285 fp
.name
= dwarf2_name (die
, cu
);
15286 fp
.type
= read_type_die (die
, cu
);
15288 /* Save accessibility. */
15289 enum dwarf_access_attribute accessibility
;
15290 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15292 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15294 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15295 switch (accessibility
)
15297 case DW_ACCESS_public
:
15298 /* The assumed value if neither private nor protected. */
15300 case DW_ACCESS_private
:
15303 case DW_ACCESS_protected
:
15304 fp
.is_protected
= 1;
15307 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15310 if (die
->tag
== DW_TAG_typedef
)
15311 fip
->typedef_field_list
.push_back (fp
);
15313 fip
->nested_types_list
.push_back (fp
);
15316 /* Create the vector of fields, and attach it to the type. */
15319 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15320 struct dwarf2_cu
*cu
)
15322 int nfields
= fip
->nfields
;
15324 /* Record the field count, allocate space for the array of fields,
15325 and create blank accessibility bitfields if necessary. */
15326 TYPE_NFIELDS (type
) = nfields
;
15327 TYPE_FIELDS (type
) = (struct field
*)
15328 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15330 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15332 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15334 TYPE_FIELD_PRIVATE_BITS (type
) =
15335 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15336 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15338 TYPE_FIELD_PROTECTED_BITS (type
) =
15339 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15340 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15342 TYPE_FIELD_IGNORE_BITS (type
) =
15343 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15344 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15347 /* If the type has baseclasses, allocate and clear a bit vector for
15348 TYPE_FIELD_VIRTUAL_BITS. */
15349 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15351 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15352 unsigned char *pointer
;
15354 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15355 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15356 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15357 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15358 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15361 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15363 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15365 for (int index
= 0; index
< nfields
; ++index
)
15367 struct nextfield
&field
= fip
->fields
[index
];
15369 if (field
.variant
.is_discriminant
)
15370 di
->discriminant_index
= index
;
15371 else if (field
.variant
.default_branch
)
15372 di
->default_index
= index
;
15374 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15378 /* Copy the saved-up fields into the field vector. */
15379 for (int i
= 0; i
< nfields
; ++i
)
15381 struct nextfield
&field
15382 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15383 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15385 TYPE_FIELD (type
, i
) = field
.field
;
15386 switch (field
.accessibility
)
15388 case DW_ACCESS_private
:
15389 if (cu
->language
!= language_ada
)
15390 SET_TYPE_FIELD_PRIVATE (type
, i
);
15393 case DW_ACCESS_protected
:
15394 if (cu
->language
!= language_ada
)
15395 SET_TYPE_FIELD_PROTECTED (type
, i
);
15398 case DW_ACCESS_public
:
15402 /* Unknown accessibility. Complain and treat it as public. */
15404 complaint (_("unsupported accessibility %d"),
15405 field
.accessibility
);
15409 if (i
< fip
->baseclasses
.size ())
15411 switch (field
.virtuality
)
15413 case DW_VIRTUALITY_virtual
:
15414 case DW_VIRTUALITY_pure_virtual
:
15415 if (cu
->language
== language_ada
)
15416 error (_("unexpected virtuality in component of Ada type"));
15417 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15424 /* Return true if this member function is a constructor, false
15428 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15430 const char *fieldname
;
15431 const char *type_name
;
15434 if (die
->parent
== NULL
)
15437 if (die
->parent
->tag
!= DW_TAG_structure_type
15438 && die
->parent
->tag
!= DW_TAG_union_type
15439 && die
->parent
->tag
!= DW_TAG_class_type
)
15442 fieldname
= dwarf2_name (die
, cu
);
15443 type_name
= dwarf2_name (die
->parent
, cu
);
15444 if (fieldname
== NULL
|| type_name
== NULL
)
15447 len
= strlen (fieldname
);
15448 return (strncmp (fieldname
, type_name
, len
) == 0
15449 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15452 /* Check if the given VALUE is a recognized enum
15453 dwarf_defaulted_attribute constant according to DWARF5 spec,
15457 is_valid_DW_AT_defaulted (ULONGEST value
)
15461 case DW_DEFAULTED_no
:
15462 case DW_DEFAULTED_in_class
:
15463 case DW_DEFAULTED_out_of_class
:
15467 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15471 /* Add a member function to the proper fieldlist. */
15474 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15475 struct type
*type
, struct dwarf2_cu
*cu
)
15477 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15478 struct attribute
*attr
;
15480 struct fnfieldlist
*flp
= nullptr;
15481 struct fn_field
*fnp
;
15482 const char *fieldname
;
15483 struct type
*this_type
;
15484 enum dwarf_access_attribute accessibility
;
15486 if (cu
->language
== language_ada
)
15487 error (_("unexpected member function in Ada type"));
15489 /* Get name of member function. */
15490 fieldname
= dwarf2_name (die
, cu
);
15491 if (fieldname
== NULL
)
15494 /* Look up member function name in fieldlist. */
15495 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15497 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15499 flp
= &fip
->fnfieldlists
[i
];
15504 /* Create a new fnfieldlist if necessary. */
15505 if (flp
== nullptr)
15507 fip
->fnfieldlists
.emplace_back ();
15508 flp
= &fip
->fnfieldlists
.back ();
15509 flp
->name
= fieldname
;
15510 i
= fip
->fnfieldlists
.size () - 1;
15513 /* Create a new member function field and add it to the vector of
15515 flp
->fnfields
.emplace_back ();
15516 fnp
= &flp
->fnfields
.back ();
15518 /* Delay processing of the physname until later. */
15519 if (cu
->language
== language_cplus
)
15520 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15524 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15525 fnp
->physname
= physname
? physname
: "";
15528 fnp
->type
= alloc_type (objfile
);
15529 this_type
= read_type_die (die
, cu
);
15530 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15532 int nparams
= TYPE_NFIELDS (this_type
);
15534 /* TYPE is the domain of this method, and THIS_TYPE is the type
15535 of the method itself (TYPE_CODE_METHOD). */
15536 smash_to_method_type (fnp
->type
, type
,
15537 TYPE_TARGET_TYPE (this_type
),
15538 TYPE_FIELDS (this_type
),
15539 TYPE_NFIELDS (this_type
),
15540 TYPE_VARARGS (this_type
));
15542 /* Handle static member functions.
15543 Dwarf2 has no clean way to discern C++ static and non-static
15544 member functions. G++ helps GDB by marking the first
15545 parameter for non-static member functions (which is the this
15546 pointer) as artificial. We obtain this information from
15547 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15548 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15549 fnp
->voffset
= VOFFSET_STATIC
;
15552 complaint (_("member function type missing for '%s'"),
15553 dwarf2_full_name (fieldname
, die
, cu
));
15555 /* Get fcontext from DW_AT_containing_type if present. */
15556 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15557 fnp
->fcontext
= die_containing_type (die
, cu
);
15559 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15560 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15562 /* Get accessibility. */
15563 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15564 if (attr
!= nullptr)
15565 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15567 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15568 switch (accessibility
)
15570 case DW_ACCESS_private
:
15571 fnp
->is_private
= 1;
15573 case DW_ACCESS_protected
:
15574 fnp
->is_protected
= 1;
15578 /* Check for artificial methods. */
15579 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15580 if (attr
&& DW_UNSND (attr
) != 0)
15581 fnp
->is_artificial
= 1;
15583 /* Check for defaulted methods. */
15584 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15585 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15586 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15588 /* Check for deleted methods. */
15589 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15590 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15591 fnp
->is_deleted
= 1;
15593 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15595 /* Get index in virtual function table if it is a virtual member
15596 function. For older versions of GCC, this is an offset in the
15597 appropriate virtual table, as specified by DW_AT_containing_type.
15598 For everyone else, it is an expression to be evaluated relative
15599 to the object address. */
15601 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15602 if (attr
!= nullptr)
15604 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15606 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15608 /* Old-style GCC. */
15609 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15611 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15612 || (DW_BLOCK (attr
)->size
> 1
15613 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15614 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15616 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15617 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15618 dwarf2_complex_location_expr_complaint ();
15620 fnp
->voffset
/= cu
->header
.addr_size
;
15624 dwarf2_complex_location_expr_complaint ();
15626 if (!fnp
->fcontext
)
15628 /* If there is no `this' field and no DW_AT_containing_type,
15629 we cannot actually find a base class context for the
15631 if (TYPE_NFIELDS (this_type
) == 0
15632 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15634 complaint (_("cannot determine context for virtual member "
15635 "function \"%s\" (offset %s)"),
15636 fieldname
, sect_offset_str (die
->sect_off
));
15641 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15645 else if (attr_form_is_section_offset (attr
))
15647 dwarf2_complex_location_expr_complaint ();
15651 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15657 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15658 if (attr
&& DW_UNSND (attr
))
15660 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15661 complaint (_("Member function \"%s\" (offset %s) is virtual "
15662 "but the vtable offset is not specified"),
15663 fieldname
, sect_offset_str (die
->sect_off
));
15664 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15665 TYPE_CPLUS_DYNAMIC (type
) = 1;
15670 /* Create the vector of member function fields, and attach it to the type. */
15673 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15674 struct dwarf2_cu
*cu
)
15676 if (cu
->language
== language_ada
)
15677 error (_("unexpected member functions in Ada type"));
15679 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15680 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15682 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15684 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15686 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15687 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15689 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15690 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15691 fn_flp
->fn_fields
= (struct fn_field
*)
15692 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15694 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15695 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15698 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15701 /* Returns non-zero if NAME is the name of a vtable member in CU's
15702 language, zero otherwise. */
15704 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15706 static const char vptr
[] = "_vptr";
15708 /* Look for the C++ form of the vtable. */
15709 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15715 /* GCC outputs unnamed structures that are really pointers to member
15716 functions, with the ABI-specified layout. If TYPE describes
15717 such a structure, smash it into a member function type.
15719 GCC shouldn't do this; it should just output pointer to member DIEs.
15720 This is GCC PR debug/28767. */
15723 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15725 struct type
*pfn_type
, *self_type
, *new_type
;
15727 /* Check for a structure with no name and two children. */
15728 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15731 /* Check for __pfn and __delta members. */
15732 if (TYPE_FIELD_NAME (type
, 0) == NULL
15733 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15734 || TYPE_FIELD_NAME (type
, 1) == NULL
15735 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15738 /* Find the type of the method. */
15739 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15740 if (pfn_type
== NULL
15741 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15742 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15745 /* Look for the "this" argument. */
15746 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15747 if (TYPE_NFIELDS (pfn_type
) == 0
15748 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15749 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15752 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15753 new_type
= alloc_type (objfile
);
15754 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15755 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15756 TYPE_VARARGS (pfn_type
));
15757 smash_to_methodptr_type (type
, new_type
);
15760 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15761 appropriate error checking and issuing complaints if there is a
15765 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15767 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15769 if (attr
== nullptr)
15772 if (!attr_form_is_constant (attr
))
15774 complaint (_("DW_AT_alignment must have constant form"
15775 " - DIE at %s [in module %s]"),
15776 sect_offset_str (die
->sect_off
),
15777 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15782 if (attr
->form
== DW_FORM_sdata
)
15784 LONGEST val
= DW_SND (attr
);
15787 complaint (_("DW_AT_alignment value must not be negative"
15788 " - DIE at %s [in module %s]"),
15789 sect_offset_str (die
->sect_off
),
15790 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15796 align
= DW_UNSND (attr
);
15800 complaint (_("DW_AT_alignment value must not be zero"
15801 " - DIE at %s [in module %s]"),
15802 sect_offset_str (die
->sect_off
),
15803 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15806 if ((align
& (align
- 1)) != 0)
15808 complaint (_("DW_AT_alignment value must be a power of 2"
15809 " - DIE at %s [in module %s]"),
15810 sect_offset_str (die
->sect_off
),
15811 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15818 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15819 the alignment for TYPE. */
15822 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15825 if (!set_type_align (type
, get_alignment (cu
, die
)))
15826 complaint (_("DW_AT_alignment value too large"
15827 " - DIE at %s [in module %s]"),
15828 sect_offset_str (die
->sect_off
),
15829 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15832 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15833 constant for a type, according to DWARF5 spec, Table 5.5. */
15836 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15841 case DW_CC_pass_by_reference
:
15842 case DW_CC_pass_by_value
:
15846 complaint (_("unrecognized DW_AT_calling_convention value "
15847 "(%s) for a type"), pulongest (value
));
15852 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15853 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15854 also according to GNU-specific values (see include/dwarf2.h). */
15857 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15862 case DW_CC_program
:
15866 case DW_CC_GNU_renesas_sh
:
15867 case DW_CC_GNU_borland_fastcall_i386
:
15868 case DW_CC_GDB_IBM_OpenCL
:
15872 complaint (_("unrecognized DW_AT_calling_convention value "
15873 "(%s) for a subroutine"), pulongest (value
));
15878 /* Called when we find the DIE that starts a structure or union scope
15879 (definition) to create a type for the structure or union. Fill in
15880 the type's name and general properties; the members will not be
15881 processed until process_structure_scope. A symbol table entry for
15882 the type will also not be done until process_structure_scope (assuming
15883 the type has a name).
15885 NOTE: we need to call these functions regardless of whether or not the
15886 DIE has a DW_AT_name attribute, since it might be an anonymous
15887 structure or union. This gets the type entered into our set of
15888 user defined types. */
15890 static struct type
*
15891 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15893 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15895 struct attribute
*attr
;
15898 /* If the definition of this type lives in .debug_types, read that type.
15899 Don't follow DW_AT_specification though, that will take us back up
15900 the chain and we want to go down. */
15901 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15902 if (attr
!= nullptr)
15904 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15906 /* The type's CU may not be the same as CU.
15907 Ensure TYPE is recorded with CU in die_type_hash. */
15908 return set_die_type (die
, type
, cu
);
15911 type
= alloc_type (objfile
);
15912 INIT_CPLUS_SPECIFIC (type
);
15914 name
= dwarf2_name (die
, cu
);
15917 if (cu
->language
== language_cplus
15918 || cu
->language
== language_d
15919 || cu
->language
== language_rust
)
15921 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15923 /* dwarf2_full_name might have already finished building the DIE's
15924 type. If so, there is no need to continue. */
15925 if (get_die_type (die
, cu
) != NULL
)
15926 return get_die_type (die
, cu
);
15928 TYPE_NAME (type
) = full_name
;
15932 /* The name is already allocated along with this objfile, so
15933 we don't need to duplicate it for the type. */
15934 TYPE_NAME (type
) = name
;
15938 if (die
->tag
== DW_TAG_structure_type
)
15940 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15942 else if (die
->tag
== DW_TAG_union_type
)
15944 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15946 else if (die
->tag
== DW_TAG_variant_part
)
15948 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15949 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15953 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15956 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15957 TYPE_DECLARED_CLASS (type
) = 1;
15959 /* Store the calling convention in the type if it's available in
15960 the die. Otherwise the calling convention remains set to
15961 the default value DW_CC_normal. */
15962 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15963 if (attr
!= nullptr
15964 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15966 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15967 TYPE_CPLUS_CALLING_CONVENTION (type
)
15968 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15971 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15972 if (attr
!= nullptr)
15974 if (attr_form_is_constant (attr
))
15975 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15978 /* For the moment, dynamic type sizes are not supported
15979 by GDB's struct type. The actual size is determined
15980 on-demand when resolving the type of a given object,
15981 so set the type's length to zero for now. Otherwise,
15982 we record an expression as the length, and that expression
15983 could lead to a very large value, which could eventually
15984 lead to us trying to allocate that much memory when creating
15985 a value of that type. */
15986 TYPE_LENGTH (type
) = 0;
15991 TYPE_LENGTH (type
) = 0;
15994 maybe_set_alignment (cu
, die
, type
);
15996 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15998 /* ICC<14 does not output the required DW_AT_declaration on
15999 incomplete types, but gives them a size of zero. */
16000 TYPE_STUB (type
) = 1;
16003 TYPE_STUB_SUPPORTED (type
) = 1;
16005 if (die_is_declaration (die
, cu
))
16006 TYPE_STUB (type
) = 1;
16007 else if (attr
== NULL
&& die
->child
== NULL
16008 && producer_is_realview (cu
->producer
))
16009 /* RealView does not output the required DW_AT_declaration
16010 on incomplete types. */
16011 TYPE_STUB (type
) = 1;
16013 /* We need to add the type field to the die immediately so we don't
16014 infinitely recurse when dealing with pointers to the structure
16015 type within the structure itself. */
16016 set_die_type (die
, type
, cu
);
16018 /* set_die_type should be already done. */
16019 set_descriptive_type (type
, die
, cu
);
16024 /* A helper for process_structure_scope that handles a single member
16028 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16029 struct field_info
*fi
,
16030 std::vector
<struct symbol
*> *template_args
,
16031 struct dwarf2_cu
*cu
)
16033 if (child_die
->tag
== DW_TAG_member
16034 || child_die
->tag
== DW_TAG_variable
16035 || child_die
->tag
== DW_TAG_variant_part
)
16037 /* NOTE: carlton/2002-11-05: A C++ static data member
16038 should be a DW_TAG_member that is a declaration, but
16039 all versions of G++ as of this writing (so through at
16040 least 3.2.1) incorrectly generate DW_TAG_variable
16041 tags for them instead. */
16042 dwarf2_add_field (fi
, child_die
, cu
);
16044 else if (child_die
->tag
== DW_TAG_subprogram
)
16046 /* Rust doesn't have member functions in the C++ sense.
16047 However, it does emit ordinary functions as children
16048 of a struct DIE. */
16049 if (cu
->language
== language_rust
)
16050 read_func_scope (child_die
, cu
);
16053 /* C++ member function. */
16054 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16057 else if (child_die
->tag
== DW_TAG_inheritance
)
16059 /* C++ base class field. */
16060 dwarf2_add_field (fi
, child_die
, cu
);
16062 else if (type_can_define_types (child_die
))
16063 dwarf2_add_type_defn (fi
, child_die
, cu
);
16064 else if (child_die
->tag
== DW_TAG_template_type_param
16065 || child_die
->tag
== DW_TAG_template_value_param
)
16067 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16070 template_args
->push_back (arg
);
16072 else if (child_die
->tag
== DW_TAG_variant
)
16074 /* In a variant we want to get the discriminant and also add a
16075 field for our sole member child. */
16076 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16078 for (die_info
*variant_child
= child_die
->child
;
16079 variant_child
!= NULL
;
16080 variant_child
= sibling_die (variant_child
))
16082 if (variant_child
->tag
== DW_TAG_member
)
16084 handle_struct_member_die (variant_child
, type
, fi
,
16085 template_args
, cu
);
16086 /* Only handle the one. */
16091 /* We don't handle this but we might as well report it if we see
16093 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16094 complaint (_("DW_AT_discr_list is not supported yet"
16095 " - DIE at %s [in module %s]"),
16096 sect_offset_str (child_die
->sect_off
),
16097 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16099 /* The first field was just added, so we can stash the
16100 discriminant there. */
16101 gdb_assert (!fi
->fields
.empty ());
16103 fi
->fields
.back ().variant
.default_branch
= true;
16105 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16109 /* Finish creating a structure or union type, including filling in
16110 its members and creating a symbol for it. */
16113 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16115 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16116 struct die_info
*child_die
;
16119 type
= get_die_type (die
, cu
);
16121 type
= read_structure_type (die
, cu
);
16123 /* When reading a DW_TAG_variant_part, we need to notice when we
16124 read the discriminant member, so we can record it later in the
16125 discriminant_info. */
16126 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16127 sect_offset discr_offset
{};
16128 bool has_template_parameters
= false;
16130 if (is_variant_part
)
16132 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16135 /* Maybe it's a univariant form, an extension we support.
16136 In this case arrange not to check the offset. */
16137 is_variant_part
= false;
16139 else if (attr_form_is_ref (discr
))
16141 struct dwarf2_cu
*target_cu
= cu
;
16142 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16144 discr_offset
= target_die
->sect_off
;
16148 complaint (_("DW_AT_discr does not have DIE reference form"
16149 " - DIE at %s [in module %s]"),
16150 sect_offset_str (die
->sect_off
),
16151 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16152 is_variant_part
= false;
16156 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16158 struct field_info fi
;
16159 std::vector
<struct symbol
*> template_args
;
16161 child_die
= die
->child
;
16163 while (child_die
&& child_die
->tag
)
16165 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16167 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16168 fi
.fields
.back ().variant
.is_discriminant
= true;
16170 child_die
= sibling_die (child_die
);
16173 /* Attach template arguments to type. */
16174 if (!template_args
.empty ())
16176 has_template_parameters
= true;
16177 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16178 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16179 TYPE_TEMPLATE_ARGUMENTS (type
)
16180 = XOBNEWVEC (&objfile
->objfile_obstack
,
16182 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16183 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16184 template_args
.data (),
16185 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16186 * sizeof (struct symbol
*)));
16189 /* Attach fields and member functions to the type. */
16191 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16192 if (!fi
.fnfieldlists
.empty ())
16194 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16196 /* Get the type which refers to the base class (possibly this
16197 class itself) which contains the vtable pointer for the current
16198 class from the DW_AT_containing_type attribute. This use of
16199 DW_AT_containing_type is a GNU extension. */
16201 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16203 struct type
*t
= die_containing_type (die
, cu
);
16205 set_type_vptr_basetype (type
, t
);
16210 /* Our own class provides vtbl ptr. */
16211 for (i
= TYPE_NFIELDS (t
) - 1;
16212 i
>= TYPE_N_BASECLASSES (t
);
16215 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16217 if (is_vtable_name (fieldname
, cu
))
16219 set_type_vptr_fieldno (type
, i
);
16224 /* Complain if virtual function table field not found. */
16225 if (i
< TYPE_N_BASECLASSES (t
))
16226 complaint (_("virtual function table pointer "
16227 "not found when defining class '%s'"),
16228 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16232 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16235 else if (cu
->producer
16236 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16238 /* The IBM XLC compiler does not provide direct indication
16239 of the containing type, but the vtable pointer is
16240 always named __vfp. */
16244 for (i
= TYPE_NFIELDS (type
) - 1;
16245 i
>= TYPE_N_BASECLASSES (type
);
16248 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16250 set_type_vptr_fieldno (type
, i
);
16251 set_type_vptr_basetype (type
, type
);
16258 /* Copy fi.typedef_field_list linked list elements content into the
16259 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16260 if (!fi
.typedef_field_list
.empty ())
16262 int count
= fi
.typedef_field_list
.size ();
16264 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16265 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16266 = ((struct decl_field
*)
16268 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16269 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16271 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16272 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16275 /* Copy fi.nested_types_list linked list elements content into the
16276 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16277 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16279 int count
= fi
.nested_types_list
.size ();
16281 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16282 TYPE_NESTED_TYPES_ARRAY (type
)
16283 = ((struct decl_field
*)
16284 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16285 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16287 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16288 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16292 quirk_gcc_member_function_pointer (type
, objfile
);
16293 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16294 cu
->rust_unions
.push_back (type
);
16296 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16297 snapshots) has been known to create a die giving a declaration
16298 for a class that has, as a child, a die giving a definition for a
16299 nested class. So we have to process our children even if the
16300 current die is a declaration. Normally, of course, a declaration
16301 won't have any children at all. */
16303 child_die
= die
->child
;
16305 while (child_die
!= NULL
&& child_die
->tag
)
16307 if (child_die
->tag
== DW_TAG_member
16308 || child_die
->tag
== DW_TAG_variable
16309 || child_die
->tag
== DW_TAG_inheritance
16310 || child_die
->tag
== DW_TAG_template_value_param
16311 || child_die
->tag
== DW_TAG_template_type_param
)
16316 process_die (child_die
, cu
);
16318 child_die
= sibling_die (child_die
);
16321 /* Do not consider external references. According to the DWARF standard,
16322 these DIEs are identified by the fact that they have no byte_size
16323 attribute, and a declaration attribute. */
16324 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16325 || !die_is_declaration (die
, cu
))
16327 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16329 if (has_template_parameters
)
16331 struct symtab
*symtab
;
16332 if (sym
!= nullptr)
16333 symtab
= symbol_symtab (sym
);
16334 else if (cu
->line_header
!= nullptr)
16336 /* Any related symtab will do. */
16338 = cu
->line_header
->file_names ()[0].symtab
;
16343 complaint (_("could not find suitable "
16344 "symtab for template parameter"
16345 " - DIE at %s [in module %s]"),
16346 sect_offset_str (die
->sect_off
),
16347 objfile_name (objfile
));
16350 if (symtab
!= nullptr)
16352 /* Make sure that the symtab is set on the new symbols.
16353 Even though they don't appear in this symtab directly,
16354 other parts of gdb assume that symbols do, and this is
16355 reasonably true. */
16356 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16357 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16363 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16364 update TYPE using some information only available in DIE's children. */
16367 update_enumeration_type_from_children (struct die_info
*die
,
16369 struct dwarf2_cu
*cu
)
16371 struct die_info
*child_die
;
16372 int unsigned_enum
= 1;
16376 auto_obstack obstack
;
16378 for (child_die
= die
->child
;
16379 child_die
!= NULL
&& child_die
->tag
;
16380 child_die
= sibling_die (child_die
))
16382 struct attribute
*attr
;
16384 const gdb_byte
*bytes
;
16385 struct dwarf2_locexpr_baton
*baton
;
16388 if (child_die
->tag
!= DW_TAG_enumerator
)
16391 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16395 name
= dwarf2_name (child_die
, cu
);
16397 name
= "<anonymous enumerator>";
16399 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16400 &value
, &bytes
, &baton
);
16406 else if ((mask
& value
) != 0)
16411 /* If we already know that the enum type is neither unsigned, nor
16412 a flag type, no need to look at the rest of the enumerates. */
16413 if (!unsigned_enum
&& !flag_enum
)
16418 TYPE_UNSIGNED (type
) = 1;
16420 TYPE_FLAG_ENUM (type
) = 1;
16423 /* Given a DW_AT_enumeration_type die, set its type. We do not
16424 complete the type's fields yet, or create any symbols. */
16426 static struct type
*
16427 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16429 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16431 struct attribute
*attr
;
16434 /* If the definition of this type lives in .debug_types, read that type.
16435 Don't follow DW_AT_specification though, that will take us back up
16436 the chain and we want to go down. */
16437 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16438 if (attr
!= nullptr)
16440 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16442 /* The type's CU may not be the same as CU.
16443 Ensure TYPE is recorded with CU in die_type_hash. */
16444 return set_die_type (die
, type
, cu
);
16447 type
= alloc_type (objfile
);
16449 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16450 name
= dwarf2_full_name (NULL
, die
, cu
);
16452 TYPE_NAME (type
) = name
;
16454 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16457 struct type
*underlying_type
= die_type (die
, cu
);
16459 TYPE_TARGET_TYPE (type
) = underlying_type
;
16462 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16463 if (attr
!= nullptr)
16465 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16469 TYPE_LENGTH (type
) = 0;
16472 maybe_set_alignment (cu
, die
, type
);
16474 /* The enumeration DIE can be incomplete. In Ada, any type can be
16475 declared as private in the package spec, and then defined only
16476 inside the package body. Such types are known as Taft Amendment
16477 Types. When another package uses such a type, an incomplete DIE
16478 may be generated by the compiler. */
16479 if (die_is_declaration (die
, cu
))
16480 TYPE_STUB (type
) = 1;
16482 /* Finish the creation of this type by using the enum's children.
16483 We must call this even when the underlying type has been provided
16484 so that we can determine if we're looking at a "flag" enum. */
16485 update_enumeration_type_from_children (die
, type
, cu
);
16487 /* If this type has an underlying type that is not a stub, then we
16488 may use its attributes. We always use the "unsigned" attribute
16489 in this situation, because ordinarily we guess whether the type
16490 is unsigned -- but the guess can be wrong and the underlying type
16491 can tell us the reality. However, we defer to a local size
16492 attribute if one exists, because this lets the compiler override
16493 the underlying type if needed. */
16494 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16496 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16497 if (TYPE_LENGTH (type
) == 0)
16498 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16499 if (TYPE_RAW_ALIGN (type
) == 0
16500 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16501 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16504 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16506 return set_die_type (die
, type
, cu
);
16509 /* Given a pointer to a die which begins an enumeration, process all
16510 the dies that define the members of the enumeration, and create the
16511 symbol for the enumeration type.
16513 NOTE: We reverse the order of the element list. */
16516 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16518 struct type
*this_type
;
16520 this_type
= get_die_type (die
, cu
);
16521 if (this_type
== NULL
)
16522 this_type
= read_enumeration_type (die
, cu
);
16524 if (die
->child
!= NULL
)
16526 struct die_info
*child_die
;
16527 struct symbol
*sym
;
16528 std::vector
<struct field
> fields
;
16531 child_die
= die
->child
;
16532 while (child_die
&& child_die
->tag
)
16534 if (child_die
->tag
!= DW_TAG_enumerator
)
16536 process_die (child_die
, cu
);
16540 name
= dwarf2_name (child_die
, cu
);
16543 sym
= new_symbol (child_die
, this_type
, cu
);
16545 fields
.emplace_back ();
16546 struct field
&field
= fields
.back ();
16548 FIELD_NAME (field
) = sym
->linkage_name ();
16549 FIELD_TYPE (field
) = NULL
;
16550 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16551 FIELD_BITSIZE (field
) = 0;
16555 child_die
= sibling_die (child_die
);
16558 if (!fields
.empty ())
16560 TYPE_NFIELDS (this_type
) = fields
.size ();
16561 TYPE_FIELDS (this_type
) = (struct field
*)
16562 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16563 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16564 sizeof (struct field
) * fields
.size ());
16568 /* If we are reading an enum from a .debug_types unit, and the enum
16569 is a declaration, and the enum is not the signatured type in the
16570 unit, then we do not want to add a symbol for it. Adding a
16571 symbol would in some cases obscure the true definition of the
16572 enum, giving users an incomplete type when the definition is
16573 actually available. Note that we do not want to do this for all
16574 enums which are just declarations, because C++0x allows forward
16575 enum declarations. */
16576 if (cu
->per_cu
->is_debug_types
16577 && die_is_declaration (die
, cu
))
16579 struct signatured_type
*sig_type
;
16581 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16582 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16583 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16587 new_symbol (die
, this_type
, cu
);
16590 /* Extract all information from a DW_TAG_array_type DIE and put it in
16591 the DIE's type field. For now, this only handles one dimensional
16594 static struct type
*
16595 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16597 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16598 struct die_info
*child_die
;
16600 struct type
*element_type
, *range_type
, *index_type
;
16601 struct attribute
*attr
;
16603 struct dynamic_prop
*byte_stride_prop
= NULL
;
16604 unsigned int bit_stride
= 0;
16606 element_type
= die_type (die
, cu
);
16608 /* The die_type call above may have already set the type for this DIE. */
16609 type
= get_die_type (die
, cu
);
16613 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16617 struct type
*prop_type
16618 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16621 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16622 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16626 complaint (_("unable to read array DW_AT_byte_stride "
16627 " - DIE at %s [in module %s]"),
16628 sect_offset_str (die
->sect_off
),
16629 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16630 /* Ignore this attribute. We will likely not be able to print
16631 arrays of this type correctly, but there is little we can do
16632 to help if we cannot read the attribute's value. */
16633 byte_stride_prop
= NULL
;
16637 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16639 bit_stride
= DW_UNSND (attr
);
16641 /* Irix 6.2 native cc creates array types without children for
16642 arrays with unspecified length. */
16643 if (die
->child
== NULL
)
16645 index_type
= objfile_type (objfile
)->builtin_int
;
16646 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16647 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16648 byte_stride_prop
, bit_stride
);
16649 return set_die_type (die
, type
, cu
);
16652 std::vector
<struct type
*> range_types
;
16653 child_die
= die
->child
;
16654 while (child_die
&& child_die
->tag
)
16656 if (child_die
->tag
== DW_TAG_subrange_type
)
16658 struct type
*child_type
= read_type_die (child_die
, cu
);
16660 if (child_type
!= NULL
)
16662 /* The range type was succesfully read. Save it for the
16663 array type creation. */
16664 range_types
.push_back (child_type
);
16667 child_die
= sibling_die (child_die
);
16670 /* Dwarf2 dimensions are output from left to right, create the
16671 necessary array types in backwards order. */
16673 type
= element_type
;
16675 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16679 while (i
< range_types
.size ())
16680 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16681 byte_stride_prop
, bit_stride
);
16685 size_t ndim
= range_types
.size ();
16687 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16688 byte_stride_prop
, bit_stride
);
16691 /* Understand Dwarf2 support for vector types (like they occur on
16692 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16693 array type. This is not part of the Dwarf2/3 standard yet, but a
16694 custom vendor extension. The main difference between a regular
16695 array and the vector variant is that vectors are passed by value
16697 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16698 if (attr
!= nullptr)
16699 make_vector_type (type
);
16701 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16702 implementation may choose to implement triple vectors using this
16704 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16705 if (attr
!= nullptr)
16707 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16708 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16710 complaint (_("DW_AT_byte_size for array type smaller "
16711 "than the total size of elements"));
16714 name
= dwarf2_name (die
, cu
);
16716 TYPE_NAME (type
) = name
;
16718 maybe_set_alignment (cu
, die
, type
);
16720 /* Install the type in the die. */
16721 set_die_type (die
, type
, cu
);
16723 /* set_die_type should be already done. */
16724 set_descriptive_type (type
, die
, cu
);
16729 static enum dwarf_array_dim_ordering
16730 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16732 struct attribute
*attr
;
16734 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16736 if (attr
!= nullptr)
16737 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16739 /* GNU F77 is a special case, as at 08/2004 array type info is the
16740 opposite order to the dwarf2 specification, but data is still
16741 laid out as per normal fortran.
16743 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16744 version checking. */
16746 if (cu
->language
== language_fortran
16747 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16749 return DW_ORD_row_major
;
16752 switch (cu
->language_defn
->la_array_ordering
)
16754 case array_column_major
:
16755 return DW_ORD_col_major
;
16756 case array_row_major
:
16758 return DW_ORD_row_major
;
16762 /* Extract all information from a DW_TAG_set_type DIE and put it in
16763 the DIE's type field. */
16765 static struct type
*
16766 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16768 struct type
*domain_type
, *set_type
;
16769 struct attribute
*attr
;
16771 domain_type
= die_type (die
, cu
);
16773 /* The die_type call above may have already set the type for this DIE. */
16774 set_type
= get_die_type (die
, cu
);
16778 set_type
= create_set_type (NULL
, domain_type
);
16780 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16781 if (attr
!= nullptr)
16782 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16784 maybe_set_alignment (cu
, die
, set_type
);
16786 return set_die_type (die
, set_type
, cu
);
16789 /* A helper for read_common_block that creates a locexpr baton.
16790 SYM is the symbol which we are marking as computed.
16791 COMMON_DIE is the DIE for the common block.
16792 COMMON_LOC is the location expression attribute for the common
16794 MEMBER_LOC is the location expression attribute for the particular
16795 member of the common block that we are processing.
16796 CU is the CU from which the above come. */
16799 mark_common_block_symbol_computed (struct symbol
*sym
,
16800 struct die_info
*common_die
,
16801 struct attribute
*common_loc
,
16802 struct attribute
*member_loc
,
16803 struct dwarf2_cu
*cu
)
16805 struct dwarf2_per_objfile
*dwarf2_per_objfile
16806 = cu
->per_cu
->dwarf2_per_objfile
;
16807 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16808 struct dwarf2_locexpr_baton
*baton
;
16810 unsigned int cu_off
;
16811 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16812 LONGEST offset
= 0;
16814 gdb_assert (common_loc
&& member_loc
);
16815 gdb_assert (attr_form_is_block (common_loc
));
16816 gdb_assert (attr_form_is_block (member_loc
)
16817 || attr_form_is_constant (member_loc
));
16819 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16820 baton
->per_cu
= cu
->per_cu
;
16821 gdb_assert (baton
->per_cu
);
16823 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16825 if (attr_form_is_constant (member_loc
))
16827 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16828 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16831 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16833 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16836 *ptr
++ = DW_OP_call4
;
16837 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16838 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16841 if (attr_form_is_constant (member_loc
))
16843 *ptr
++ = DW_OP_addr
;
16844 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16845 ptr
+= cu
->header
.addr_size
;
16849 /* We have to copy the data here, because DW_OP_call4 will only
16850 use a DW_AT_location attribute. */
16851 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16852 ptr
+= DW_BLOCK (member_loc
)->size
;
16855 *ptr
++ = DW_OP_plus
;
16856 gdb_assert (ptr
- baton
->data
== baton
->size
);
16858 SYMBOL_LOCATION_BATON (sym
) = baton
;
16859 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16862 /* Create appropriate locally-scoped variables for all the
16863 DW_TAG_common_block entries. Also create a struct common_block
16864 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16865 is used to separate the common blocks name namespace from regular
16869 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16871 struct attribute
*attr
;
16873 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16874 if (attr
!= nullptr)
16876 /* Support the .debug_loc offsets. */
16877 if (attr_form_is_block (attr
))
16881 else if (attr_form_is_section_offset (attr
))
16883 dwarf2_complex_location_expr_complaint ();
16888 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16889 "common block member");
16894 if (die
->child
!= NULL
)
16896 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16897 struct die_info
*child_die
;
16898 size_t n_entries
= 0, size
;
16899 struct common_block
*common_block
;
16900 struct symbol
*sym
;
16902 for (child_die
= die
->child
;
16903 child_die
&& child_die
->tag
;
16904 child_die
= sibling_die (child_die
))
16907 size
= (sizeof (struct common_block
)
16908 + (n_entries
- 1) * sizeof (struct symbol
*));
16910 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16912 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16913 common_block
->n_entries
= 0;
16915 for (child_die
= die
->child
;
16916 child_die
&& child_die
->tag
;
16917 child_die
= sibling_die (child_die
))
16919 /* Create the symbol in the DW_TAG_common_block block in the current
16921 sym
= new_symbol (child_die
, NULL
, cu
);
16924 struct attribute
*member_loc
;
16926 common_block
->contents
[common_block
->n_entries
++] = sym
;
16928 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16932 /* GDB has handled this for a long time, but it is
16933 not specified by DWARF. It seems to have been
16934 emitted by gfortran at least as recently as:
16935 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16936 complaint (_("Variable in common block has "
16937 "DW_AT_data_member_location "
16938 "- DIE at %s [in module %s]"),
16939 sect_offset_str (child_die
->sect_off
),
16940 objfile_name (objfile
));
16942 if (attr_form_is_section_offset (member_loc
))
16943 dwarf2_complex_location_expr_complaint ();
16944 else if (attr_form_is_constant (member_loc
)
16945 || attr_form_is_block (member_loc
))
16947 if (attr
!= nullptr)
16948 mark_common_block_symbol_computed (sym
, die
, attr
,
16952 dwarf2_complex_location_expr_complaint ();
16957 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16958 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16962 /* Create a type for a C++ namespace. */
16964 static struct type
*
16965 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16967 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16968 const char *previous_prefix
, *name
;
16972 /* For extensions, reuse the type of the original namespace. */
16973 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16975 struct die_info
*ext_die
;
16976 struct dwarf2_cu
*ext_cu
= cu
;
16978 ext_die
= dwarf2_extension (die
, &ext_cu
);
16979 type
= read_type_die (ext_die
, ext_cu
);
16981 /* EXT_CU may not be the same as CU.
16982 Ensure TYPE is recorded with CU in die_type_hash. */
16983 return set_die_type (die
, type
, cu
);
16986 name
= namespace_name (die
, &is_anonymous
, cu
);
16988 /* Now build the name of the current namespace. */
16990 previous_prefix
= determine_prefix (die
, cu
);
16991 if (previous_prefix
[0] != '\0')
16992 name
= typename_concat (&objfile
->objfile_obstack
,
16993 previous_prefix
, name
, 0, cu
);
16995 /* Create the type. */
16996 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16998 return set_die_type (die
, type
, cu
);
17001 /* Read a namespace scope. */
17004 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17006 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17009 /* Add a symbol associated to this if we haven't seen the namespace
17010 before. Also, add a using directive if it's an anonymous
17013 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17017 type
= read_type_die (die
, cu
);
17018 new_symbol (die
, type
, cu
);
17020 namespace_name (die
, &is_anonymous
, cu
);
17023 const char *previous_prefix
= determine_prefix (die
, cu
);
17025 std::vector
<const char *> excludes
;
17026 add_using_directive (using_directives (cu
),
17027 previous_prefix
, TYPE_NAME (type
), NULL
,
17028 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17032 if (die
->child
!= NULL
)
17034 struct die_info
*child_die
= die
->child
;
17036 while (child_die
&& child_die
->tag
)
17038 process_die (child_die
, cu
);
17039 child_die
= sibling_die (child_die
);
17044 /* Read a Fortran module as type. This DIE can be only a declaration used for
17045 imported module. Still we need that type as local Fortran "use ... only"
17046 declaration imports depend on the created type in determine_prefix. */
17048 static struct type
*
17049 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17051 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17052 const char *module_name
;
17055 module_name
= dwarf2_name (die
, cu
);
17056 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17058 return set_die_type (die
, type
, cu
);
17061 /* Read a Fortran module. */
17064 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17066 struct die_info
*child_die
= die
->child
;
17069 type
= read_type_die (die
, cu
);
17070 new_symbol (die
, type
, cu
);
17072 while (child_die
&& child_die
->tag
)
17074 process_die (child_die
, cu
);
17075 child_die
= sibling_die (child_die
);
17079 /* Return the name of the namespace represented by DIE. Set
17080 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17083 static const char *
17084 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17086 struct die_info
*current_die
;
17087 const char *name
= NULL
;
17089 /* Loop through the extensions until we find a name. */
17091 for (current_die
= die
;
17092 current_die
!= NULL
;
17093 current_die
= dwarf2_extension (die
, &cu
))
17095 /* We don't use dwarf2_name here so that we can detect the absence
17096 of a name -> anonymous namespace. */
17097 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17103 /* Is it an anonymous namespace? */
17105 *is_anonymous
= (name
== NULL
);
17107 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17112 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17113 the user defined type vector. */
17115 static struct type
*
17116 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17118 struct gdbarch
*gdbarch
17119 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17120 struct comp_unit_head
*cu_header
= &cu
->header
;
17122 struct attribute
*attr_byte_size
;
17123 struct attribute
*attr_address_class
;
17124 int byte_size
, addr_class
;
17125 struct type
*target_type
;
17127 target_type
= die_type (die
, cu
);
17129 /* The die_type call above may have already set the type for this DIE. */
17130 type
= get_die_type (die
, cu
);
17134 type
= lookup_pointer_type (target_type
);
17136 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17137 if (attr_byte_size
)
17138 byte_size
= DW_UNSND (attr_byte_size
);
17140 byte_size
= cu_header
->addr_size
;
17142 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17143 if (attr_address_class
)
17144 addr_class
= DW_UNSND (attr_address_class
);
17146 addr_class
= DW_ADDR_none
;
17148 ULONGEST alignment
= get_alignment (cu
, die
);
17150 /* If the pointer size, alignment, or address class is different
17151 than the default, create a type variant marked as such and set
17152 the length accordingly. */
17153 if (TYPE_LENGTH (type
) != byte_size
17154 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17155 && alignment
!= TYPE_RAW_ALIGN (type
))
17156 || addr_class
!= DW_ADDR_none
)
17158 if (gdbarch_address_class_type_flags_p (gdbarch
))
17162 type_flags
= gdbarch_address_class_type_flags
17163 (gdbarch
, byte_size
, addr_class
);
17164 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17166 type
= make_type_with_address_space (type
, type_flags
);
17168 else if (TYPE_LENGTH (type
) != byte_size
)
17170 complaint (_("invalid pointer size %d"), byte_size
);
17172 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17174 complaint (_("Invalid DW_AT_alignment"
17175 " - DIE at %s [in module %s]"),
17176 sect_offset_str (die
->sect_off
),
17177 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17181 /* Should we also complain about unhandled address classes? */
17185 TYPE_LENGTH (type
) = byte_size
;
17186 set_type_align (type
, alignment
);
17187 return set_die_type (die
, type
, cu
);
17190 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17191 the user defined type vector. */
17193 static struct type
*
17194 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17197 struct type
*to_type
;
17198 struct type
*domain
;
17200 to_type
= die_type (die
, cu
);
17201 domain
= die_containing_type (die
, cu
);
17203 /* The calls above may have already set the type for this DIE. */
17204 type
= get_die_type (die
, cu
);
17208 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17209 type
= lookup_methodptr_type (to_type
);
17210 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17212 struct type
*new_type
17213 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17215 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17216 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17217 TYPE_VARARGS (to_type
));
17218 type
= lookup_methodptr_type (new_type
);
17221 type
= lookup_memberptr_type (to_type
, domain
);
17223 return set_die_type (die
, type
, cu
);
17226 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17227 the user defined type vector. */
17229 static struct type
*
17230 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17231 enum type_code refcode
)
17233 struct comp_unit_head
*cu_header
= &cu
->header
;
17234 struct type
*type
, *target_type
;
17235 struct attribute
*attr
;
17237 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17239 target_type
= die_type (die
, cu
);
17241 /* The die_type call above may have already set the type for this DIE. */
17242 type
= get_die_type (die
, cu
);
17246 type
= lookup_reference_type (target_type
, refcode
);
17247 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17248 if (attr
!= nullptr)
17250 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17254 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17256 maybe_set_alignment (cu
, die
, type
);
17257 return set_die_type (die
, type
, cu
);
17260 /* Add the given cv-qualifiers to the element type of the array. GCC
17261 outputs DWARF type qualifiers that apply to an array, not the
17262 element type. But GDB relies on the array element type to carry
17263 the cv-qualifiers. This mimics section 6.7.3 of the C99
17266 static struct type
*
17267 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17268 struct type
*base_type
, int cnst
, int voltl
)
17270 struct type
*el_type
, *inner_array
;
17272 base_type
= copy_type (base_type
);
17273 inner_array
= base_type
;
17275 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17277 TYPE_TARGET_TYPE (inner_array
) =
17278 copy_type (TYPE_TARGET_TYPE (inner_array
));
17279 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17282 el_type
= TYPE_TARGET_TYPE (inner_array
);
17283 cnst
|= TYPE_CONST (el_type
);
17284 voltl
|= TYPE_VOLATILE (el_type
);
17285 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17287 return set_die_type (die
, base_type
, cu
);
17290 static struct type
*
17291 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17293 struct type
*base_type
, *cv_type
;
17295 base_type
= die_type (die
, cu
);
17297 /* The die_type call above may have already set the type for this DIE. */
17298 cv_type
= get_die_type (die
, cu
);
17302 /* In case the const qualifier is applied to an array type, the element type
17303 is so qualified, not the array type (section 6.7.3 of C99). */
17304 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17305 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17307 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17308 return set_die_type (die
, cv_type
, cu
);
17311 static struct type
*
17312 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17314 struct type
*base_type
, *cv_type
;
17316 base_type
= die_type (die
, cu
);
17318 /* The die_type call above may have already set the type for this DIE. */
17319 cv_type
= get_die_type (die
, cu
);
17323 /* In case the volatile qualifier is applied to an array type, the
17324 element type is so qualified, not the array type (section 6.7.3
17326 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17327 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17329 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17330 return set_die_type (die
, cv_type
, cu
);
17333 /* Handle DW_TAG_restrict_type. */
17335 static struct type
*
17336 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17338 struct type
*base_type
, *cv_type
;
17340 base_type
= die_type (die
, cu
);
17342 /* The die_type call above may have already set the type for this DIE. */
17343 cv_type
= get_die_type (die
, cu
);
17347 cv_type
= make_restrict_type (base_type
);
17348 return set_die_type (die
, cv_type
, cu
);
17351 /* Handle DW_TAG_atomic_type. */
17353 static struct type
*
17354 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17356 struct type
*base_type
, *cv_type
;
17358 base_type
= die_type (die
, cu
);
17360 /* The die_type call above may have already set the type for this DIE. */
17361 cv_type
= get_die_type (die
, cu
);
17365 cv_type
= make_atomic_type (base_type
);
17366 return set_die_type (die
, cv_type
, cu
);
17369 /* Extract all information from a DW_TAG_string_type DIE and add to
17370 the user defined type vector. It isn't really a user defined type,
17371 but it behaves like one, with other DIE's using an AT_user_def_type
17372 attribute to reference it. */
17374 static struct type
*
17375 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17377 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17378 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17379 struct type
*type
, *range_type
, *index_type
, *char_type
;
17380 struct attribute
*attr
;
17381 struct dynamic_prop prop
;
17382 bool length_is_constant
= true;
17385 /* There are a couple of places where bit sizes might be made use of
17386 when parsing a DW_TAG_string_type, however, no producer that we know
17387 of make use of these. Handling bit sizes that are a multiple of the
17388 byte size is easy enough, but what about other bit sizes? Lets deal
17389 with that problem when we have to. Warn about these attributes being
17390 unsupported, then parse the type and ignore them like we always
17392 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17393 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17395 static bool warning_printed
= false;
17396 if (!warning_printed
)
17398 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17399 "currently supported on DW_TAG_string_type."));
17400 warning_printed
= true;
17404 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17405 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17407 /* The string length describes the location at which the length of
17408 the string can be found. The size of the length field can be
17409 specified with one of the attributes below. */
17410 struct type
*prop_type
;
17411 struct attribute
*len
17412 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17413 if (len
== nullptr)
17414 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17415 if (len
!= nullptr && attr_form_is_constant (len
))
17417 /* Pass 0 as the default as we know this attribute is constant
17418 and the default value will not be returned. */
17419 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17420 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17424 /* If the size is not specified then we assume it is the size of
17425 an address on this target. */
17426 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17429 /* Convert the attribute into a dynamic property. */
17430 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17433 length_is_constant
= false;
17435 else if (attr
!= nullptr)
17437 /* This DW_AT_string_length just contains the length with no
17438 indirection. There's no need to create a dynamic property in this
17439 case. Pass 0 for the default value as we know it will not be
17440 returned in this case. */
17441 length
= dwarf2_get_attr_constant_value (attr
, 0);
17443 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17445 /* We don't currently support non-constant byte sizes for strings. */
17446 length
= dwarf2_get_attr_constant_value (attr
, 1);
17450 /* Use 1 as a fallback length if we have nothing else. */
17454 index_type
= objfile_type (objfile
)->builtin_int
;
17455 if (length_is_constant
)
17456 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17459 struct dynamic_prop low_bound
;
17461 low_bound
.kind
= PROP_CONST
;
17462 low_bound
.data
.const_val
= 1;
17463 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17465 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17466 type
= create_string_type (NULL
, char_type
, range_type
);
17468 return set_die_type (die
, type
, cu
);
17471 /* Assuming that DIE corresponds to a function, returns nonzero
17472 if the function is prototyped. */
17475 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17477 struct attribute
*attr
;
17479 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17480 if (attr
&& (DW_UNSND (attr
) != 0))
17483 /* The DWARF standard implies that the DW_AT_prototyped attribute
17484 is only meaningful for C, but the concept also extends to other
17485 languages that allow unprototyped functions (Eg: Objective C).
17486 For all other languages, assume that functions are always
17488 if (cu
->language
!= language_c
17489 && cu
->language
!= language_objc
17490 && cu
->language
!= language_opencl
)
17493 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17494 prototyped and unprototyped functions; default to prototyped,
17495 since that is more common in modern code (and RealView warns
17496 about unprototyped functions). */
17497 if (producer_is_realview (cu
->producer
))
17503 /* Handle DIES due to C code like:
17507 int (*funcp)(int a, long l);
17511 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17513 static struct type
*
17514 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17516 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17517 struct type
*type
; /* Type that this function returns. */
17518 struct type
*ftype
; /* Function that returns above type. */
17519 struct attribute
*attr
;
17521 type
= die_type (die
, cu
);
17523 /* The die_type call above may have already set the type for this DIE. */
17524 ftype
= get_die_type (die
, cu
);
17528 ftype
= lookup_function_type (type
);
17530 if (prototyped_function_p (die
, cu
))
17531 TYPE_PROTOTYPED (ftype
) = 1;
17533 /* Store the calling convention in the type if it's available in
17534 the subroutine die. Otherwise set the calling convention to
17535 the default value DW_CC_normal. */
17536 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17537 if (attr
!= nullptr
17538 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17539 TYPE_CALLING_CONVENTION (ftype
)
17540 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17541 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17542 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17544 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17546 /* Record whether the function returns normally to its caller or not
17547 if the DWARF producer set that information. */
17548 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17549 if (attr
&& (DW_UNSND (attr
) != 0))
17550 TYPE_NO_RETURN (ftype
) = 1;
17552 /* We need to add the subroutine type to the die immediately so
17553 we don't infinitely recurse when dealing with parameters
17554 declared as the same subroutine type. */
17555 set_die_type (die
, ftype
, cu
);
17557 if (die
->child
!= NULL
)
17559 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17560 struct die_info
*child_die
;
17561 int nparams
, iparams
;
17563 /* Count the number of parameters.
17564 FIXME: GDB currently ignores vararg functions, but knows about
17565 vararg member functions. */
17567 child_die
= die
->child
;
17568 while (child_die
&& child_die
->tag
)
17570 if (child_die
->tag
== DW_TAG_formal_parameter
)
17572 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17573 TYPE_VARARGS (ftype
) = 1;
17574 child_die
= sibling_die (child_die
);
17577 /* Allocate storage for parameters and fill them in. */
17578 TYPE_NFIELDS (ftype
) = nparams
;
17579 TYPE_FIELDS (ftype
) = (struct field
*)
17580 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17582 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17583 even if we error out during the parameters reading below. */
17584 for (iparams
= 0; iparams
< nparams
; iparams
++)
17585 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17588 child_die
= die
->child
;
17589 while (child_die
&& child_die
->tag
)
17591 if (child_die
->tag
== DW_TAG_formal_parameter
)
17593 struct type
*arg_type
;
17595 /* DWARF version 2 has no clean way to discern C++
17596 static and non-static member functions. G++ helps
17597 GDB by marking the first parameter for non-static
17598 member functions (which is the this pointer) as
17599 artificial. We pass this information to
17600 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17602 DWARF version 3 added DW_AT_object_pointer, which GCC
17603 4.5 does not yet generate. */
17604 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17605 if (attr
!= nullptr)
17606 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17608 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17609 arg_type
= die_type (child_die
, cu
);
17611 /* RealView does not mark THIS as const, which the testsuite
17612 expects. GCC marks THIS as const in method definitions,
17613 but not in the class specifications (GCC PR 43053). */
17614 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17615 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17618 struct dwarf2_cu
*arg_cu
= cu
;
17619 const char *name
= dwarf2_name (child_die
, cu
);
17621 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17622 if (attr
!= nullptr)
17624 /* If the compiler emits this, use it. */
17625 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17628 else if (name
&& strcmp (name
, "this") == 0)
17629 /* Function definitions will have the argument names. */
17631 else if (name
== NULL
&& iparams
== 0)
17632 /* Declarations may not have the names, so like
17633 elsewhere in GDB, assume an artificial first
17634 argument is "this". */
17638 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17642 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17645 child_die
= sibling_die (child_die
);
17652 static struct type
*
17653 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17655 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17656 const char *name
= NULL
;
17657 struct type
*this_type
, *target_type
;
17659 name
= dwarf2_full_name (NULL
, die
, cu
);
17660 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17661 TYPE_TARGET_STUB (this_type
) = 1;
17662 set_die_type (die
, this_type
, cu
);
17663 target_type
= die_type (die
, cu
);
17664 if (target_type
!= this_type
)
17665 TYPE_TARGET_TYPE (this_type
) = target_type
;
17668 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17669 spec and cause infinite loops in GDB. */
17670 complaint (_("Self-referential DW_TAG_typedef "
17671 "- DIE at %s [in module %s]"),
17672 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17673 TYPE_TARGET_TYPE (this_type
) = NULL
;
17678 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17679 (which may be different from NAME) to the architecture back-end to allow
17680 it to guess the correct format if necessary. */
17682 static struct type
*
17683 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17684 const char *name_hint
, enum bfd_endian byte_order
)
17686 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17687 const struct floatformat
**format
;
17690 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17692 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17694 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17699 /* Allocate an integer type of size BITS and name NAME. */
17701 static struct type
*
17702 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17703 int bits
, int unsigned_p
, const char *name
)
17707 /* Versions of Intel's C Compiler generate an integer type called "void"
17708 instead of using DW_TAG_unspecified_type. This has been seen on
17709 at least versions 14, 17, and 18. */
17710 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17711 && strcmp (name
, "void") == 0)
17712 type
= objfile_type (objfile
)->builtin_void
;
17714 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17719 /* Initialise and return a floating point type of size BITS suitable for
17720 use as a component of a complex number. The NAME_HINT is passed through
17721 when initialising the floating point type and is the name of the complex
17724 As DWARF doesn't currently provide an explicit name for the components
17725 of a complex number, but it can be helpful to have these components
17726 named, we try to select a suitable name based on the size of the
17728 static struct type
*
17729 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17730 struct objfile
*objfile
,
17731 int bits
, const char *name_hint
,
17732 enum bfd_endian byte_order
)
17734 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17735 struct type
*tt
= nullptr;
17737 /* Try to find a suitable floating point builtin type of size BITS.
17738 We're going to use the name of this type as the name for the complex
17739 target type that we are about to create. */
17740 switch (cu
->language
)
17742 case language_fortran
:
17746 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17749 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17751 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17753 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17761 tt
= builtin_type (gdbarch
)->builtin_float
;
17764 tt
= builtin_type (gdbarch
)->builtin_double
;
17766 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17768 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17774 /* If the type we found doesn't match the size we were looking for, then
17775 pretend we didn't find a type at all, the complex target type we
17776 create will then be nameless. */
17777 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17780 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17781 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17784 /* Find a representation of a given base type and install
17785 it in the TYPE field of the die. */
17787 static struct type
*
17788 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17790 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17792 struct attribute
*attr
;
17793 int encoding
= 0, bits
= 0;
17797 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17798 if (attr
!= nullptr)
17799 encoding
= DW_UNSND (attr
);
17800 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17801 if (attr
!= nullptr)
17802 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17803 name
= dwarf2_name (die
, cu
);
17805 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17807 arch
= get_objfile_arch (objfile
);
17808 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17810 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17813 int endianity
= DW_UNSND (attr
);
17818 byte_order
= BFD_ENDIAN_BIG
;
17820 case DW_END_little
:
17821 byte_order
= BFD_ENDIAN_LITTLE
;
17824 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17831 case DW_ATE_address
:
17832 /* Turn DW_ATE_address into a void * pointer. */
17833 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17834 type
= init_pointer_type (objfile
, bits
, name
, type
);
17836 case DW_ATE_boolean
:
17837 type
= init_boolean_type (objfile
, bits
, 1, name
);
17839 case DW_ATE_complex_float
:
17840 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17842 type
= init_complex_type (objfile
, name
, type
);
17844 case DW_ATE_decimal_float
:
17845 type
= init_decfloat_type (objfile
, bits
, name
);
17848 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17850 case DW_ATE_signed
:
17851 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17853 case DW_ATE_unsigned
:
17854 if (cu
->language
== language_fortran
17856 && startswith (name
, "character("))
17857 type
= init_character_type (objfile
, bits
, 1, name
);
17859 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17861 case DW_ATE_signed_char
:
17862 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17863 || cu
->language
== language_pascal
17864 || cu
->language
== language_fortran
)
17865 type
= init_character_type (objfile
, bits
, 0, name
);
17867 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17869 case DW_ATE_unsigned_char
:
17870 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17871 || cu
->language
== language_pascal
17872 || cu
->language
== language_fortran
17873 || cu
->language
== language_rust
)
17874 type
= init_character_type (objfile
, bits
, 1, name
);
17876 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17881 type
= builtin_type (arch
)->builtin_char16
;
17882 else if (bits
== 32)
17883 type
= builtin_type (arch
)->builtin_char32
;
17886 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17888 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17890 return set_die_type (die
, type
, cu
);
17895 complaint (_("unsupported DW_AT_encoding: '%s'"),
17896 dwarf_type_encoding_name (encoding
));
17897 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17901 if (name
&& strcmp (name
, "char") == 0)
17902 TYPE_NOSIGN (type
) = 1;
17904 maybe_set_alignment (cu
, die
, type
);
17906 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17908 return set_die_type (die
, type
, cu
);
17911 /* Parse dwarf attribute if it's a block, reference or constant and put the
17912 resulting value of the attribute into struct bound_prop.
17913 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17916 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17917 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17918 struct type
*default_type
)
17920 struct dwarf2_property_baton
*baton
;
17921 struct obstack
*obstack
17922 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17924 gdb_assert (default_type
!= NULL
);
17926 if (attr
== NULL
|| prop
== NULL
)
17929 if (attr_form_is_block (attr
))
17931 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17932 baton
->property_type
= default_type
;
17933 baton
->locexpr
.per_cu
= cu
->per_cu
;
17934 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17935 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17936 switch (attr
->name
)
17938 case DW_AT_string_length
:
17939 baton
->locexpr
.is_reference
= true;
17942 baton
->locexpr
.is_reference
= false;
17945 prop
->data
.baton
= baton
;
17946 prop
->kind
= PROP_LOCEXPR
;
17947 gdb_assert (prop
->data
.baton
!= NULL
);
17949 else if (attr_form_is_ref (attr
))
17951 struct dwarf2_cu
*target_cu
= cu
;
17952 struct die_info
*target_die
;
17953 struct attribute
*target_attr
;
17955 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17956 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17957 if (target_attr
== NULL
)
17958 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17960 if (target_attr
== NULL
)
17963 switch (target_attr
->name
)
17965 case DW_AT_location
:
17966 if (attr_form_is_section_offset (target_attr
))
17968 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17969 baton
->property_type
= die_type (target_die
, target_cu
);
17970 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17971 prop
->data
.baton
= baton
;
17972 prop
->kind
= PROP_LOCLIST
;
17973 gdb_assert (prop
->data
.baton
!= NULL
);
17975 else if (attr_form_is_block (target_attr
))
17977 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17978 baton
->property_type
= die_type (target_die
, target_cu
);
17979 baton
->locexpr
.per_cu
= cu
->per_cu
;
17980 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17981 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17982 baton
->locexpr
.is_reference
= true;
17983 prop
->data
.baton
= baton
;
17984 prop
->kind
= PROP_LOCEXPR
;
17985 gdb_assert (prop
->data
.baton
!= NULL
);
17989 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17990 "dynamic property");
17994 case DW_AT_data_member_location
:
17998 if (!handle_data_member_location (target_die
, target_cu
,
18002 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18003 baton
->property_type
= read_type_die (target_die
->parent
,
18005 baton
->offset_info
.offset
= offset
;
18006 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18007 prop
->data
.baton
= baton
;
18008 prop
->kind
= PROP_ADDR_OFFSET
;
18013 else if (attr_form_is_constant (attr
))
18015 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
18016 prop
->kind
= PROP_CONST
;
18020 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18021 dwarf2_name (die
, cu
));
18028 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
18029 UNSIGNED_P controls if the integer is unsigned or not. */
18031 static struct type
*
18032 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
18033 int size_in_bytes
, bool unsigned_p
)
18035 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
18036 struct type
*int_type
;
18038 /* Helper macro to examine the various builtin types. */
18039 #define TRY_TYPE(F) \
18040 int_type = (unsigned_p \
18041 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18042 : objfile_type (objfile)->builtin_ ## F); \
18043 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18050 TRY_TYPE (long_long
);
18054 gdb_assert_not_reached ("unable to find suitable integer type");
18057 /* Find an integer type the same size as the address size given in the
18058 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
18059 is unsigned or not. */
18061 static struct type
*
18062 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
18065 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
18066 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
18069 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18070 present (which is valid) then compute the default type based on the
18071 compilation units address size. */
18073 static struct type
*
18074 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18076 struct type
*index_type
= die_type (die
, cu
);
18078 /* Dwarf-2 specifications explicitly allows to create subrange types
18079 without specifying a base type.
18080 In that case, the base type must be set to the type of
18081 the lower bound, upper bound or count, in that order, if any of these
18082 three attributes references an object that has a type.
18083 If no base type is found, the Dwarf-2 specifications say that
18084 a signed integer type of size equal to the size of an address should
18086 For the following C code: `extern char gdb_int [];'
18087 GCC produces an empty range DIE.
18088 FIXME: muller/2010-05-28: Possible references to object for low bound,
18089 high bound or count are not yet handled by this code. */
18090 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
18091 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18096 /* Read the given DW_AT_subrange DIE. */
18098 static struct type
*
18099 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18101 struct type
*base_type
, *orig_base_type
;
18102 struct type
*range_type
;
18103 struct attribute
*attr
;
18104 struct dynamic_prop low
, high
;
18105 int low_default_is_valid
;
18106 int high_bound_is_count
= 0;
18108 ULONGEST negative_mask
;
18110 orig_base_type
= read_subrange_index_type (die
, cu
);
18112 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18113 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18114 creating the range type, but we use the result of check_typedef
18115 when examining properties of the type. */
18116 base_type
= check_typedef (orig_base_type
);
18118 /* The die_type call above may have already set the type for this DIE. */
18119 range_type
= get_die_type (die
, cu
);
18123 low
.kind
= PROP_CONST
;
18124 high
.kind
= PROP_CONST
;
18125 high
.data
.const_val
= 0;
18127 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18128 omitting DW_AT_lower_bound. */
18129 switch (cu
->language
)
18132 case language_cplus
:
18133 low
.data
.const_val
= 0;
18134 low_default_is_valid
= 1;
18136 case language_fortran
:
18137 low
.data
.const_val
= 1;
18138 low_default_is_valid
= 1;
18141 case language_objc
:
18142 case language_rust
:
18143 low
.data
.const_val
= 0;
18144 low_default_is_valid
= (cu
->header
.version
>= 4);
18148 case language_pascal
:
18149 low
.data
.const_val
= 1;
18150 low_default_is_valid
= (cu
->header
.version
>= 4);
18153 low
.data
.const_val
= 0;
18154 low_default_is_valid
= 0;
18158 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18159 if (attr
!= nullptr)
18160 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18161 else if (!low_default_is_valid
)
18162 complaint (_("Missing DW_AT_lower_bound "
18163 "- DIE at %s [in module %s]"),
18164 sect_offset_str (die
->sect_off
),
18165 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18167 struct attribute
*attr_ub
, *attr_count
;
18168 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18169 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18171 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18172 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18174 /* If bounds are constant do the final calculation here. */
18175 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18176 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18178 high_bound_is_count
= 1;
18182 if (attr_ub
!= NULL
)
18183 complaint (_("Unresolved DW_AT_upper_bound "
18184 "- DIE at %s [in module %s]"),
18185 sect_offset_str (die
->sect_off
),
18186 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18187 if (attr_count
!= NULL
)
18188 complaint (_("Unresolved DW_AT_count "
18189 "- DIE at %s [in module %s]"),
18190 sect_offset_str (die
->sect_off
),
18191 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18196 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18197 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18198 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18200 /* Normally, the DWARF producers are expected to use a signed
18201 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18202 But this is unfortunately not always the case, as witnessed
18203 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18204 is used instead. To work around that ambiguity, we treat
18205 the bounds as signed, and thus sign-extend their values, when
18206 the base type is signed. */
18208 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18209 if (low
.kind
== PROP_CONST
18210 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18211 low
.data
.const_val
|= negative_mask
;
18212 if (high
.kind
== PROP_CONST
18213 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18214 high
.data
.const_val
|= negative_mask
;
18216 /* Check for bit and byte strides. */
18217 struct dynamic_prop byte_stride_prop
;
18218 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18219 if (attr_byte_stride
!= nullptr)
18221 struct type
*prop_type
18222 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18223 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18227 struct dynamic_prop bit_stride_prop
;
18228 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18229 if (attr_bit_stride
!= nullptr)
18231 /* It only makes sense to have either a bit or byte stride. */
18232 if (attr_byte_stride
!= nullptr)
18234 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18235 "- DIE at %s [in module %s]"),
18236 sect_offset_str (die
->sect_off
),
18237 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18238 attr_bit_stride
= nullptr;
18242 struct type
*prop_type
18243 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18244 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18249 if (attr_byte_stride
!= nullptr
18250 || attr_bit_stride
!= nullptr)
18252 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18253 struct dynamic_prop
*stride
18254 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18257 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18258 &high
, bias
, stride
, byte_stride_p
);
18261 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18263 if (high_bound_is_count
)
18264 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18266 /* Ada expects an empty array on no boundary attributes. */
18267 if (attr
== NULL
&& cu
->language
!= language_ada
)
18268 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18270 name
= dwarf2_name (die
, cu
);
18272 TYPE_NAME (range_type
) = name
;
18274 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18275 if (attr
!= nullptr)
18276 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18278 maybe_set_alignment (cu
, die
, range_type
);
18280 set_die_type (die
, range_type
, cu
);
18282 /* set_die_type should be already done. */
18283 set_descriptive_type (range_type
, die
, cu
);
18288 static struct type
*
18289 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18293 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18295 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18297 /* In Ada, an unspecified type is typically used when the description
18298 of the type is deferred to a different unit. When encountering
18299 such a type, we treat it as a stub, and try to resolve it later on,
18301 if (cu
->language
== language_ada
)
18302 TYPE_STUB (type
) = 1;
18304 return set_die_type (die
, type
, cu
);
18307 /* Read a single die and all its descendents. Set the die's sibling
18308 field to NULL; set other fields in the die correctly, and set all
18309 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18310 location of the info_ptr after reading all of those dies. PARENT
18311 is the parent of the die in question. */
18313 static struct die_info
*
18314 read_die_and_children (const struct die_reader_specs
*reader
,
18315 const gdb_byte
*info_ptr
,
18316 const gdb_byte
**new_info_ptr
,
18317 struct die_info
*parent
)
18319 struct die_info
*die
;
18320 const gdb_byte
*cur_ptr
;
18323 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18326 *new_info_ptr
= cur_ptr
;
18329 store_in_ref_table (die
, reader
->cu
);
18332 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18336 *new_info_ptr
= cur_ptr
;
18339 die
->sibling
= NULL
;
18340 die
->parent
= parent
;
18344 /* Read a die, all of its descendents, and all of its siblings; set
18345 all of the fields of all of the dies correctly. Arguments are as
18346 in read_die_and_children. */
18348 static struct die_info
*
18349 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18350 const gdb_byte
*info_ptr
,
18351 const gdb_byte
**new_info_ptr
,
18352 struct die_info
*parent
)
18354 struct die_info
*first_die
, *last_sibling
;
18355 const gdb_byte
*cur_ptr
;
18357 cur_ptr
= info_ptr
;
18358 first_die
= last_sibling
= NULL
;
18362 struct die_info
*die
18363 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18367 *new_info_ptr
= cur_ptr
;
18374 last_sibling
->sibling
= die
;
18376 last_sibling
= die
;
18380 /* Read a die, all of its descendents, and all of its siblings; set
18381 all of the fields of all of the dies correctly. Arguments are as
18382 in read_die_and_children.
18383 This the main entry point for reading a DIE and all its children. */
18385 static struct die_info
*
18386 read_die_and_siblings (const struct die_reader_specs
*reader
,
18387 const gdb_byte
*info_ptr
,
18388 const gdb_byte
**new_info_ptr
,
18389 struct die_info
*parent
)
18391 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18392 new_info_ptr
, parent
);
18394 if (dwarf_die_debug
)
18396 fprintf_unfiltered (gdb_stdlog
,
18397 "Read die from %s@0x%x of %s:\n",
18398 get_section_name (reader
->die_section
),
18399 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18400 bfd_get_filename (reader
->abfd
));
18401 dump_die (die
, dwarf_die_debug
);
18407 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18409 The caller is responsible for filling in the extra attributes
18410 and updating (*DIEP)->num_attrs.
18411 Set DIEP to point to a newly allocated die with its information,
18412 except for its child, sibling, and parent fields.
18413 Set HAS_CHILDREN to tell whether the die has children or not. */
18415 static const gdb_byte
*
18416 read_full_die_1 (const struct die_reader_specs
*reader
,
18417 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18418 int *has_children
, int num_extra_attrs
)
18420 unsigned int abbrev_number
, bytes_read
, i
;
18421 struct abbrev_info
*abbrev
;
18422 struct die_info
*die
;
18423 struct dwarf2_cu
*cu
= reader
->cu
;
18424 bfd
*abfd
= reader
->abfd
;
18426 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18427 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18428 info_ptr
+= bytes_read
;
18429 if (!abbrev_number
)
18436 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18438 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18440 bfd_get_filename (abfd
));
18442 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18443 die
->sect_off
= sect_off
;
18444 die
->tag
= abbrev
->tag
;
18445 die
->abbrev
= abbrev_number
;
18447 /* Make the result usable.
18448 The caller needs to update num_attrs after adding the extra
18450 die
->num_attrs
= abbrev
->num_attrs
;
18452 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18453 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18457 *has_children
= abbrev
->has_children
;
18461 /* Read a die and all its attributes.
18462 Set DIEP to point to a newly allocated die with its information,
18463 except for its child, sibling, and parent fields.
18464 Set HAS_CHILDREN to tell whether the die has children or not. */
18466 static const gdb_byte
*
18467 read_full_die (const struct die_reader_specs
*reader
,
18468 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18471 const gdb_byte
*result
;
18473 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18475 if (dwarf_die_debug
)
18477 fprintf_unfiltered (gdb_stdlog
,
18478 "Read die from %s@0x%x of %s:\n",
18479 get_section_name (reader
->die_section
),
18480 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18481 bfd_get_filename (reader
->abfd
));
18482 dump_die (*diep
, dwarf_die_debug
);
18488 /* Abbreviation tables.
18490 In DWARF version 2, the description of the debugging information is
18491 stored in a separate .debug_abbrev section. Before we read any
18492 dies from a section we read in all abbreviations and install them
18493 in a hash table. */
18495 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18497 struct abbrev_info
*
18498 abbrev_table::alloc_abbrev ()
18500 struct abbrev_info
*abbrev
;
18502 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18503 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18508 /* Add an abbreviation to the table. */
18511 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18512 struct abbrev_info
*abbrev
)
18514 unsigned int hash_number
;
18516 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18517 abbrev
->next
= m_abbrevs
[hash_number
];
18518 m_abbrevs
[hash_number
] = abbrev
;
18521 /* Look up an abbrev in the table.
18522 Returns NULL if the abbrev is not found. */
18524 struct abbrev_info
*
18525 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18527 unsigned int hash_number
;
18528 struct abbrev_info
*abbrev
;
18530 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18531 abbrev
= m_abbrevs
[hash_number
];
18535 if (abbrev
->number
== abbrev_number
)
18537 abbrev
= abbrev
->next
;
18542 /* Read in an abbrev table. */
18544 static abbrev_table_up
18545 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18546 struct dwarf2_section_info
*section
,
18547 sect_offset sect_off
)
18549 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18550 bfd
*abfd
= get_section_bfd_owner (section
);
18551 const gdb_byte
*abbrev_ptr
;
18552 struct abbrev_info
*cur_abbrev
;
18553 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18554 unsigned int abbrev_form
;
18555 std::vector
<struct attr_abbrev
> cur_attrs
;
18557 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18559 dwarf2_read_section (objfile
, section
);
18560 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18561 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18562 abbrev_ptr
+= bytes_read
;
18564 /* Loop until we reach an abbrev number of 0. */
18565 while (abbrev_number
)
18567 cur_attrs
.clear ();
18568 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18570 /* read in abbrev header */
18571 cur_abbrev
->number
= abbrev_number
;
18573 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18574 abbrev_ptr
+= bytes_read
;
18575 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18578 /* now read in declarations */
18581 LONGEST implicit_const
;
18583 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18584 abbrev_ptr
+= bytes_read
;
18585 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18586 abbrev_ptr
+= bytes_read
;
18587 if (abbrev_form
== DW_FORM_implicit_const
)
18589 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18591 abbrev_ptr
+= bytes_read
;
18595 /* Initialize it due to a false compiler warning. */
18596 implicit_const
= -1;
18599 if (abbrev_name
== 0)
18602 cur_attrs
.emplace_back ();
18603 struct attr_abbrev
&cur_attr
= cur_attrs
.back ();
18604 cur_attr
.name
= (enum dwarf_attribute
) abbrev_name
;
18605 cur_attr
.form
= (enum dwarf_form
) abbrev_form
;
18606 cur_attr
.implicit_const
= implicit_const
;
18607 ++cur_abbrev
->num_attrs
;
18610 cur_abbrev
->attrs
=
18611 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18612 cur_abbrev
->num_attrs
);
18613 memcpy (cur_abbrev
->attrs
, cur_attrs
.data (),
18614 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18616 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18618 /* Get next abbreviation.
18619 Under Irix6 the abbreviations for a compilation unit are not
18620 always properly terminated with an abbrev number of 0.
18621 Exit loop if we encounter an abbreviation which we have
18622 already read (which means we are about to read the abbreviations
18623 for the next compile unit) or if the end of the abbreviation
18624 table is reached. */
18625 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18627 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18628 abbrev_ptr
+= bytes_read
;
18629 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18633 return abbrev_table
;
18636 /* Returns nonzero if TAG represents a type that we might generate a partial
18640 is_type_tag_for_partial (int tag
)
18645 /* Some types that would be reasonable to generate partial symbols for,
18646 that we don't at present. */
18647 case DW_TAG_array_type
:
18648 case DW_TAG_file_type
:
18649 case DW_TAG_ptr_to_member_type
:
18650 case DW_TAG_set_type
:
18651 case DW_TAG_string_type
:
18652 case DW_TAG_subroutine_type
:
18654 case DW_TAG_base_type
:
18655 case DW_TAG_class_type
:
18656 case DW_TAG_interface_type
:
18657 case DW_TAG_enumeration_type
:
18658 case DW_TAG_structure_type
:
18659 case DW_TAG_subrange_type
:
18660 case DW_TAG_typedef
:
18661 case DW_TAG_union_type
:
18668 /* Load all DIEs that are interesting for partial symbols into memory. */
18670 static struct partial_die_info
*
18671 load_partial_dies (const struct die_reader_specs
*reader
,
18672 const gdb_byte
*info_ptr
, int building_psymtab
)
18674 struct dwarf2_cu
*cu
= reader
->cu
;
18675 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18676 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18677 unsigned int bytes_read
;
18678 unsigned int load_all
= 0;
18679 int nesting_level
= 1;
18684 gdb_assert (cu
->per_cu
!= NULL
);
18685 if (cu
->per_cu
->load_all_dies
)
18689 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18693 &cu
->comp_unit_obstack
,
18694 hashtab_obstack_allocate
,
18695 dummy_obstack_deallocate
);
18699 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18701 /* A NULL abbrev means the end of a series of children. */
18702 if (abbrev
== NULL
)
18704 if (--nesting_level
== 0)
18707 info_ptr
+= bytes_read
;
18708 last_die
= parent_die
;
18709 parent_die
= parent_die
->die_parent
;
18713 /* Check for template arguments. We never save these; if
18714 they're seen, we just mark the parent, and go on our way. */
18715 if (parent_die
!= NULL
18716 && cu
->language
== language_cplus
18717 && (abbrev
->tag
== DW_TAG_template_type_param
18718 || abbrev
->tag
== DW_TAG_template_value_param
))
18720 parent_die
->has_template_arguments
= 1;
18724 /* We don't need a partial DIE for the template argument. */
18725 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18730 /* We only recurse into c++ subprograms looking for template arguments.
18731 Skip their other children. */
18733 && cu
->language
== language_cplus
18734 && parent_die
!= NULL
18735 && parent_die
->tag
== DW_TAG_subprogram
)
18737 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18741 /* Check whether this DIE is interesting enough to save. Normally
18742 we would not be interested in members here, but there may be
18743 later variables referencing them via DW_AT_specification (for
18744 static members). */
18746 && !is_type_tag_for_partial (abbrev
->tag
)
18747 && abbrev
->tag
!= DW_TAG_constant
18748 && abbrev
->tag
!= DW_TAG_enumerator
18749 && abbrev
->tag
!= DW_TAG_subprogram
18750 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18751 && abbrev
->tag
!= DW_TAG_lexical_block
18752 && abbrev
->tag
!= DW_TAG_variable
18753 && abbrev
->tag
!= DW_TAG_namespace
18754 && abbrev
->tag
!= DW_TAG_module
18755 && abbrev
->tag
!= DW_TAG_member
18756 && abbrev
->tag
!= DW_TAG_imported_unit
18757 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18759 /* Otherwise we skip to the next sibling, if any. */
18760 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18764 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18767 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18769 /* This two-pass algorithm for processing partial symbols has a
18770 high cost in cache pressure. Thus, handle some simple cases
18771 here which cover the majority of C partial symbols. DIEs
18772 which neither have specification tags in them, nor could have
18773 specification tags elsewhere pointing at them, can simply be
18774 processed and discarded.
18776 This segment is also optional; scan_partial_symbols and
18777 add_partial_symbol will handle these DIEs if we chain
18778 them in normally. When compilers which do not emit large
18779 quantities of duplicate debug information are more common,
18780 this code can probably be removed. */
18782 /* Any complete simple types at the top level (pretty much all
18783 of them, for a language without namespaces), can be processed
18785 if (parent_die
== NULL
18786 && pdi
.has_specification
== 0
18787 && pdi
.is_declaration
== 0
18788 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18789 || pdi
.tag
== DW_TAG_base_type
18790 || pdi
.tag
== DW_TAG_subrange_type
))
18792 if (building_psymtab
&& pdi
.name
!= NULL
)
18793 add_psymbol_to_list (pdi
.name
, false,
18794 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18795 psymbol_placement::STATIC
,
18796 0, cu
->language
, objfile
);
18797 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18801 /* The exception for DW_TAG_typedef with has_children above is
18802 a workaround of GCC PR debug/47510. In the case of this complaint
18803 type_name_or_error will error on such types later.
18805 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18806 it could not find the child DIEs referenced later, this is checked
18807 above. In correct DWARF DW_TAG_typedef should have no children. */
18809 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18810 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18811 "- DIE at %s [in module %s]"),
18812 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18814 /* If we're at the second level, and we're an enumerator, and
18815 our parent has no specification (meaning possibly lives in a
18816 namespace elsewhere), then we can add the partial symbol now
18817 instead of queueing it. */
18818 if (pdi
.tag
== DW_TAG_enumerator
18819 && parent_die
!= NULL
18820 && parent_die
->die_parent
== NULL
18821 && parent_die
->tag
== DW_TAG_enumeration_type
18822 && parent_die
->has_specification
== 0)
18824 if (pdi
.name
== NULL
)
18825 complaint (_("malformed enumerator DIE ignored"));
18826 else if (building_psymtab
)
18827 add_psymbol_to_list (pdi
.name
, false,
18828 VAR_DOMAIN
, LOC_CONST
, -1,
18829 cu
->language
== language_cplus
18830 ? psymbol_placement::GLOBAL
18831 : psymbol_placement::STATIC
,
18832 0, cu
->language
, objfile
);
18834 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18838 struct partial_die_info
*part_die
18839 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18841 /* We'll save this DIE so link it in. */
18842 part_die
->die_parent
= parent_die
;
18843 part_die
->die_sibling
= NULL
;
18844 part_die
->die_child
= NULL
;
18846 if (last_die
&& last_die
== parent_die
)
18847 last_die
->die_child
= part_die
;
18849 last_die
->die_sibling
= part_die
;
18851 last_die
= part_die
;
18853 if (first_die
== NULL
)
18854 first_die
= part_die
;
18856 /* Maybe add the DIE to the hash table. Not all DIEs that we
18857 find interesting need to be in the hash table, because we
18858 also have the parent/sibling/child chains; only those that we
18859 might refer to by offset later during partial symbol reading.
18861 For now this means things that might have be the target of a
18862 DW_AT_specification, DW_AT_abstract_origin, or
18863 DW_AT_extension. DW_AT_extension will refer only to
18864 namespaces; DW_AT_abstract_origin refers to functions (and
18865 many things under the function DIE, but we do not recurse
18866 into function DIEs during partial symbol reading) and
18867 possibly variables as well; DW_AT_specification refers to
18868 declarations. Declarations ought to have the DW_AT_declaration
18869 flag. It happens that GCC forgets to put it in sometimes, but
18870 only for functions, not for types.
18872 Adding more things than necessary to the hash table is harmless
18873 except for the performance cost. Adding too few will result in
18874 wasted time in find_partial_die, when we reread the compilation
18875 unit with load_all_dies set. */
18878 || abbrev
->tag
== DW_TAG_constant
18879 || abbrev
->tag
== DW_TAG_subprogram
18880 || abbrev
->tag
== DW_TAG_variable
18881 || abbrev
->tag
== DW_TAG_namespace
18882 || part_die
->is_declaration
)
18886 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18887 to_underlying (part_die
->sect_off
),
18892 /* For some DIEs we want to follow their children (if any). For C
18893 we have no reason to follow the children of structures; for other
18894 languages we have to, so that we can get at method physnames
18895 to infer fully qualified class names, for DW_AT_specification,
18896 and for C++ template arguments. For C++, we also look one level
18897 inside functions to find template arguments (if the name of the
18898 function does not already contain the template arguments).
18900 For Ada and Fortran, we need to scan the children of subprograms
18901 and lexical blocks as well because these languages allow the
18902 definition of nested entities that could be interesting for the
18903 debugger, such as nested subprograms for instance. */
18904 if (last_die
->has_children
18906 || last_die
->tag
== DW_TAG_namespace
18907 || last_die
->tag
== DW_TAG_module
18908 || last_die
->tag
== DW_TAG_enumeration_type
18909 || (cu
->language
== language_cplus
18910 && last_die
->tag
== DW_TAG_subprogram
18911 && (last_die
->name
== NULL
18912 || strchr (last_die
->name
, '<') == NULL
))
18913 || (cu
->language
!= language_c
18914 && (last_die
->tag
== DW_TAG_class_type
18915 || last_die
->tag
== DW_TAG_interface_type
18916 || last_die
->tag
== DW_TAG_structure_type
18917 || last_die
->tag
== DW_TAG_union_type
))
18918 || ((cu
->language
== language_ada
18919 || cu
->language
== language_fortran
)
18920 && (last_die
->tag
== DW_TAG_subprogram
18921 || last_die
->tag
== DW_TAG_lexical_block
))))
18924 parent_die
= last_die
;
18928 /* Otherwise we skip to the next sibling, if any. */
18929 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18931 /* Back to the top, do it again. */
18935 partial_die_info::partial_die_info (sect_offset sect_off_
,
18936 struct abbrev_info
*abbrev
)
18937 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18941 /* Read a minimal amount of information into the minimal die structure.
18942 INFO_PTR should point just after the initial uleb128 of a DIE. */
18945 partial_die_info::read (const struct die_reader_specs
*reader
,
18946 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18948 struct dwarf2_cu
*cu
= reader
->cu
;
18949 struct dwarf2_per_objfile
*dwarf2_per_objfile
18950 = cu
->per_cu
->dwarf2_per_objfile
;
18952 int has_low_pc_attr
= 0;
18953 int has_high_pc_attr
= 0;
18954 int high_pc_relative
= 0;
18956 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18958 struct attribute attr
;
18960 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18962 /* Store the data if it is of an attribute we want to keep in a
18963 partial symbol table. */
18969 case DW_TAG_compile_unit
:
18970 case DW_TAG_partial_unit
:
18971 case DW_TAG_type_unit
:
18972 /* Compilation units have a DW_AT_name that is a filename, not
18973 a source language identifier. */
18974 case DW_TAG_enumeration_type
:
18975 case DW_TAG_enumerator
:
18976 /* These tags always have simple identifiers already; no need
18977 to canonicalize them. */
18978 name
= DW_STRING (&attr
);
18982 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18985 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18986 &objfile
->per_bfd
->storage_obstack
);
18991 case DW_AT_linkage_name
:
18992 case DW_AT_MIPS_linkage_name
:
18993 /* Note that both forms of linkage name might appear. We
18994 assume they will be the same, and we only store the last
18996 linkage_name
= DW_STRING (&attr
);
18999 has_low_pc_attr
= 1;
19000 lowpc
= attr_value_as_address (&attr
);
19002 case DW_AT_high_pc
:
19003 has_high_pc_attr
= 1;
19004 highpc
= attr_value_as_address (&attr
);
19005 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
19006 high_pc_relative
= 1;
19008 case DW_AT_location
:
19009 /* Support the .debug_loc offsets. */
19010 if (attr_form_is_block (&attr
))
19012 d
.locdesc
= DW_BLOCK (&attr
);
19014 else if (attr_form_is_section_offset (&attr
))
19016 dwarf2_complex_location_expr_complaint ();
19020 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19021 "partial symbol information");
19024 case DW_AT_external
:
19025 is_external
= DW_UNSND (&attr
);
19027 case DW_AT_declaration
:
19028 is_declaration
= DW_UNSND (&attr
);
19033 case DW_AT_abstract_origin
:
19034 case DW_AT_specification
:
19035 case DW_AT_extension
:
19036 has_specification
= 1;
19037 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
19038 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19039 || cu
->per_cu
->is_dwz
);
19041 case DW_AT_sibling
:
19042 /* Ignore absolute siblings, they might point outside of
19043 the current compile unit. */
19044 if (attr
.form
== DW_FORM_ref_addr
)
19045 complaint (_("ignoring absolute DW_AT_sibling"));
19048 const gdb_byte
*buffer
= reader
->buffer
;
19049 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
19050 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19052 if (sibling_ptr
< info_ptr
)
19053 complaint (_("DW_AT_sibling points backwards"));
19054 else if (sibling_ptr
> reader
->buffer_end
)
19055 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19057 sibling
= sibling_ptr
;
19060 case DW_AT_byte_size
:
19063 case DW_AT_const_value
:
19064 has_const_value
= 1;
19066 case DW_AT_calling_convention
:
19067 /* DWARF doesn't provide a way to identify a program's source-level
19068 entry point. DW_AT_calling_convention attributes are only meant
19069 to describe functions' calling conventions.
19071 However, because it's a necessary piece of information in
19072 Fortran, and before DWARF 4 DW_CC_program was the only
19073 piece of debugging information whose definition refers to
19074 a 'main program' at all, several compilers marked Fortran
19075 main programs with DW_CC_program --- even when those
19076 functions use the standard calling conventions.
19078 Although DWARF now specifies a way to provide this
19079 information, we support this practice for backward
19081 if (DW_UNSND (&attr
) == DW_CC_program
19082 && cu
->language
== language_fortran
)
19083 main_subprogram
= 1;
19086 if (DW_UNSND (&attr
) == DW_INL_inlined
19087 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19088 may_be_inlined
= 1;
19092 if (tag
== DW_TAG_imported_unit
)
19094 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19095 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19096 || cu
->per_cu
->is_dwz
);
19100 case DW_AT_main_subprogram
:
19101 main_subprogram
= DW_UNSND (&attr
);
19106 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19107 but that requires a full DIE, so instead we just
19109 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
19110 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19111 + (need_ranges_base
19115 /* Value of the DW_AT_ranges attribute is the offset in the
19116 .debug_ranges section. */
19117 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19128 /* For Ada, if both the name and the linkage name appear, we prefer
19129 the latter. This lets "catch exception" work better, regardless
19130 of the order in which the name and linkage name were emitted.
19131 Really, though, this is just a workaround for the fact that gdb
19132 doesn't store both the name and the linkage name. */
19133 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19134 name
= linkage_name
;
19136 if (high_pc_relative
)
19139 if (has_low_pc_attr
&& has_high_pc_attr
)
19141 /* When using the GNU linker, .gnu.linkonce. sections are used to
19142 eliminate duplicate copies of functions and vtables and such.
19143 The linker will arbitrarily choose one and discard the others.
19144 The AT_*_pc values for such functions refer to local labels in
19145 these sections. If the section from that file was discarded, the
19146 labels are not in the output, so the relocs get a value of 0.
19147 If this is a discarded function, mark the pc bounds as invalid,
19148 so that GDB will ignore it. */
19149 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19151 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19152 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19154 complaint (_("DW_AT_low_pc %s is zero "
19155 "for DIE at %s [in module %s]"),
19156 paddress (gdbarch
, lowpc
),
19157 sect_offset_str (sect_off
),
19158 objfile_name (objfile
));
19160 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19161 else if (lowpc
>= highpc
)
19163 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19164 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19166 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19167 "for DIE at %s [in module %s]"),
19168 paddress (gdbarch
, lowpc
),
19169 paddress (gdbarch
, highpc
),
19170 sect_offset_str (sect_off
),
19171 objfile_name (objfile
));
19180 /* Find a cached partial DIE at OFFSET in CU. */
19182 struct partial_die_info
*
19183 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19185 struct partial_die_info
*lookup_die
= NULL
;
19186 struct partial_die_info
part_die (sect_off
);
19188 lookup_die
= ((struct partial_die_info
*)
19189 htab_find_with_hash (partial_dies
, &part_die
,
19190 to_underlying (sect_off
)));
19195 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19196 except in the case of .debug_types DIEs which do not reference
19197 outside their CU (they do however referencing other types via
19198 DW_FORM_ref_sig8). */
19200 static const struct cu_partial_die_info
19201 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19203 struct dwarf2_per_objfile
*dwarf2_per_objfile
19204 = cu
->per_cu
->dwarf2_per_objfile
;
19205 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19206 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19207 struct partial_die_info
*pd
= NULL
;
19209 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19210 && offset_in_cu_p (&cu
->header
, sect_off
))
19212 pd
= cu
->find_partial_die (sect_off
);
19215 /* We missed recording what we needed.
19216 Load all dies and try again. */
19217 per_cu
= cu
->per_cu
;
19221 /* TUs don't reference other CUs/TUs (except via type signatures). */
19222 if (cu
->per_cu
->is_debug_types
)
19224 error (_("Dwarf Error: Type Unit at offset %s contains"
19225 " external reference to offset %s [in module %s].\n"),
19226 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19227 bfd_get_filename (objfile
->obfd
));
19229 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19230 dwarf2_per_objfile
);
19232 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19233 load_partial_comp_unit (per_cu
);
19235 per_cu
->cu
->last_used
= 0;
19236 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19239 /* If we didn't find it, and not all dies have been loaded,
19240 load them all and try again. */
19242 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19244 per_cu
->load_all_dies
= 1;
19246 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19247 THIS_CU->cu may already be in use. So we can't just free it and
19248 replace its DIEs with the ones we read in. Instead, we leave those
19249 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19250 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19252 load_partial_comp_unit (per_cu
);
19254 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19258 internal_error (__FILE__
, __LINE__
,
19259 _("could not find partial DIE %s "
19260 "in cache [from module %s]\n"),
19261 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19262 return { per_cu
->cu
, pd
};
19265 /* See if we can figure out if the class lives in a namespace. We do
19266 this by looking for a member function; its demangled name will
19267 contain namespace info, if there is any. */
19270 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19271 struct dwarf2_cu
*cu
)
19273 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19274 what template types look like, because the demangler
19275 frequently doesn't give the same name as the debug info. We
19276 could fix this by only using the demangled name to get the
19277 prefix (but see comment in read_structure_type). */
19279 struct partial_die_info
*real_pdi
;
19280 struct partial_die_info
*child_pdi
;
19282 /* If this DIE (this DIE's specification, if any) has a parent, then
19283 we should not do this. We'll prepend the parent's fully qualified
19284 name when we create the partial symbol. */
19286 real_pdi
= struct_pdi
;
19287 while (real_pdi
->has_specification
)
19289 auto res
= find_partial_die (real_pdi
->spec_offset
,
19290 real_pdi
->spec_is_dwz
, cu
);
19291 real_pdi
= res
.pdi
;
19295 if (real_pdi
->die_parent
!= NULL
)
19298 for (child_pdi
= struct_pdi
->die_child
;
19300 child_pdi
= child_pdi
->die_sibling
)
19302 if (child_pdi
->tag
== DW_TAG_subprogram
19303 && child_pdi
->linkage_name
!= NULL
)
19305 gdb::unique_xmalloc_ptr
<char> actual_class_name
19306 (language_class_name_from_physname (cu
->language_defn
,
19307 child_pdi
->linkage_name
));
19308 if (actual_class_name
!= NULL
)
19310 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19312 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19313 actual_class_name
.get ());
19321 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19323 /* Once we've fixed up a die, there's no point in doing so again.
19324 This also avoids a memory leak if we were to call
19325 guess_partial_die_structure_name multiple times. */
19329 /* If we found a reference attribute and the DIE has no name, try
19330 to find a name in the referred to DIE. */
19332 if (name
== NULL
&& has_specification
)
19334 struct partial_die_info
*spec_die
;
19336 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19337 spec_die
= res
.pdi
;
19340 spec_die
->fixup (cu
);
19342 if (spec_die
->name
)
19344 name
= spec_die
->name
;
19346 /* Copy DW_AT_external attribute if it is set. */
19347 if (spec_die
->is_external
)
19348 is_external
= spec_die
->is_external
;
19352 /* Set default names for some unnamed DIEs. */
19354 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19355 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19357 /* If there is no parent die to provide a namespace, and there are
19358 children, see if we can determine the namespace from their linkage
19360 if (cu
->language
== language_cplus
19361 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19362 && die_parent
== NULL
19364 && (tag
== DW_TAG_class_type
19365 || tag
== DW_TAG_structure_type
19366 || tag
== DW_TAG_union_type
))
19367 guess_partial_die_structure_name (this, cu
);
19369 /* GCC might emit a nameless struct or union that has a linkage
19370 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19372 && (tag
== DW_TAG_class_type
19373 || tag
== DW_TAG_interface_type
19374 || tag
== DW_TAG_structure_type
19375 || tag
== DW_TAG_union_type
)
19376 && linkage_name
!= NULL
)
19378 gdb::unique_xmalloc_ptr
<char> demangled
19379 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19380 if (demangled
!= nullptr)
19384 /* Strip any leading namespaces/classes, keep only the base name.
19385 DW_AT_name for named DIEs does not contain the prefixes. */
19386 base
= strrchr (demangled
.get (), ':');
19387 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19390 base
= demangled
.get ();
19392 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19393 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19400 /* Read an attribute value described by an attribute form. */
19402 static const gdb_byte
*
19403 read_attribute_value (const struct die_reader_specs
*reader
,
19404 struct attribute
*attr
, unsigned form
,
19405 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19407 struct dwarf2_cu
*cu
= reader
->cu
;
19408 struct dwarf2_per_objfile
*dwarf2_per_objfile
19409 = cu
->per_cu
->dwarf2_per_objfile
;
19410 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19411 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19412 bfd
*abfd
= reader
->abfd
;
19413 struct comp_unit_head
*cu_header
= &cu
->header
;
19414 unsigned int bytes_read
;
19415 struct dwarf_block
*blk
;
19417 attr
->form
= (enum dwarf_form
) form
;
19420 case DW_FORM_ref_addr
:
19421 if (cu
->header
.version
== 2)
19422 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19424 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19425 &cu
->header
, &bytes_read
);
19426 info_ptr
+= bytes_read
;
19428 case DW_FORM_GNU_ref_alt
:
19429 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19430 info_ptr
+= bytes_read
;
19433 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19434 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19435 info_ptr
+= bytes_read
;
19437 case DW_FORM_block2
:
19438 blk
= dwarf_alloc_block (cu
);
19439 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19441 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19442 info_ptr
+= blk
->size
;
19443 DW_BLOCK (attr
) = blk
;
19445 case DW_FORM_block4
:
19446 blk
= dwarf_alloc_block (cu
);
19447 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19449 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19450 info_ptr
+= blk
->size
;
19451 DW_BLOCK (attr
) = blk
;
19453 case DW_FORM_data2
:
19454 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19457 case DW_FORM_data4
:
19458 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19461 case DW_FORM_data8
:
19462 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19465 case DW_FORM_data16
:
19466 blk
= dwarf_alloc_block (cu
);
19468 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19470 DW_BLOCK (attr
) = blk
;
19472 case DW_FORM_sec_offset
:
19473 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19474 info_ptr
+= bytes_read
;
19476 case DW_FORM_string
:
19477 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19478 DW_STRING_IS_CANONICAL (attr
) = 0;
19479 info_ptr
+= bytes_read
;
19482 if (!cu
->per_cu
->is_dwz
)
19484 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19485 abfd
, info_ptr
, cu_header
,
19487 DW_STRING_IS_CANONICAL (attr
) = 0;
19488 info_ptr
+= bytes_read
;
19492 case DW_FORM_line_strp
:
19493 if (!cu
->per_cu
->is_dwz
)
19495 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19497 cu_header
, &bytes_read
);
19498 DW_STRING_IS_CANONICAL (attr
) = 0;
19499 info_ptr
+= bytes_read
;
19503 case DW_FORM_GNU_strp_alt
:
19505 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19506 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19509 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19511 DW_STRING_IS_CANONICAL (attr
) = 0;
19512 info_ptr
+= bytes_read
;
19515 case DW_FORM_exprloc
:
19516 case DW_FORM_block
:
19517 blk
= dwarf_alloc_block (cu
);
19518 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19519 info_ptr
+= bytes_read
;
19520 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19521 info_ptr
+= blk
->size
;
19522 DW_BLOCK (attr
) = blk
;
19524 case DW_FORM_block1
:
19525 blk
= dwarf_alloc_block (cu
);
19526 blk
->size
= read_1_byte (abfd
, info_ptr
);
19528 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19529 info_ptr
+= blk
->size
;
19530 DW_BLOCK (attr
) = blk
;
19532 case DW_FORM_data1
:
19533 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19537 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19540 case DW_FORM_flag_present
:
19541 DW_UNSND (attr
) = 1;
19543 case DW_FORM_sdata
:
19544 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19545 info_ptr
+= bytes_read
;
19547 case DW_FORM_udata
:
19548 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19549 info_ptr
+= bytes_read
;
19552 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19553 + read_1_byte (abfd
, info_ptr
));
19557 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19558 + read_2_bytes (abfd
, info_ptr
));
19562 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19563 + read_4_bytes (abfd
, info_ptr
));
19567 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19568 + read_8_bytes (abfd
, info_ptr
));
19571 case DW_FORM_ref_sig8
:
19572 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19575 case DW_FORM_ref_udata
:
19576 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19577 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19578 info_ptr
+= bytes_read
;
19580 case DW_FORM_indirect
:
19581 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19582 info_ptr
+= bytes_read
;
19583 if (form
== DW_FORM_implicit_const
)
19585 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19586 info_ptr
+= bytes_read
;
19588 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19591 case DW_FORM_implicit_const
:
19592 DW_SND (attr
) = implicit_const
;
19594 case DW_FORM_addrx
:
19595 case DW_FORM_GNU_addr_index
:
19596 if (reader
->dwo_file
== NULL
)
19598 /* For now flag a hard error.
19599 Later we can turn this into a complaint. */
19600 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19601 dwarf_form_name (form
),
19602 bfd_get_filename (abfd
));
19604 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19605 info_ptr
+= bytes_read
;
19608 case DW_FORM_strx1
:
19609 case DW_FORM_strx2
:
19610 case DW_FORM_strx3
:
19611 case DW_FORM_strx4
:
19612 case DW_FORM_GNU_str_index
:
19613 if (reader
->dwo_file
== NULL
)
19615 /* For now flag a hard error.
19616 Later we can turn this into a complaint if warranted. */
19617 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19618 dwarf_form_name (form
),
19619 bfd_get_filename (abfd
));
19622 ULONGEST str_index
;
19623 if (form
== DW_FORM_strx1
)
19625 str_index
= read_1_byte (abfd
, info_ptr
);
19628 else if (form
== DW_FORM_strx2
)
19630 str_index
= read_2_bytes (abfd
, info_ptr
);
19633 else if (form
== DW_FORM_strx3
)
19635 str_index
= read_3_bytes (abfd
, info_ptr
);
19638 else if (form
== DW_FORM_strx4
)
19640 str_index
= read_4_bytes (abfd
, info_ptr
);
19645 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19646 info_ptr
+= bytes_read
;
19648 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19649 DW_STRING_IS_CANONICAL (attr
) = 0;
19653 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19654 dwarf_form_name (form
),
19655 bfd_get_filename (abfd
));
19659 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19660 attr
->form
= DW_FORM_GNU_ref_alt
;
19662 /* We have seen instances where the compiler tried to emit a byte
19663 size attribute of -1 which ended up being encoded as an unsigned
19664 0xffffffff. Although 0xffffffff is technically a valid size value,
19665 an object of this size seems pretty unlikely so we can relatively
19666 safely treat these cases as if the size attribute was invalid and
19667 treat them as zero by default. */
19668 if (attr
->name
== DW_AT_byte_size
19669 && form
== DW_FORM_data4
19670 && DW_UNSND (attr
) >= 0xffffffff)
19673 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19674 hex_string (DW_UNSND (attr
)));
19675 DW_UNSND (attr
) = 0;
19681 /* Read an attribute described by an abbreviated attribute. */
19683 static const gdb_byte
*
19684 read_attribute (const struct die_reader_specs
*reader
,
19685 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19686 const gdb_byte
*info_ptr
)
19688 attr
->name
= abbrev
->name
;
19689 return read_attribute_value (reader
, attr
, abbrev
->form
,
19690 abbrev
->implicit_const
, info_ptr
);
19693 /* Read dwarf information from a buffer. */
19695 static unsigned int
19696 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19698 return bfd_get_8 (abfd
, buf
);
19702 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19704 return bfd_get_signed_8 (abfd
, buf
);
19707 static unsigned int
19708 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19710 return bfd_get_16 (abfd
, buf
);
19714 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19716 return bfd_get_signed_16 (abfd
, buf
);
19719 static unsigned int
19720 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19722 unsigned int result
= 0;
19723 for (int i
= 0; i
< 3; ++i
)
19725 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19727 result
|= ((unsigned int) byte
<< (i
* 8));
19732 static unsigned int
19733 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19735 return bfd_get_32 (abfd
, buf
);
19739 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19741 return bfd_get_signed_32 (abfd
, buf
);
19745 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19747 return bfd_get_64 (abfd
, buf
);
19751 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19752 unsigned int *bytes_read
)
19754 struct comp_unit_head
*cu_header
= &cu
->header
;
19755 CORE_ADDR retval
= 0;
19757 if (cu_header
->signed_addr_p
)
19759 switch (cu_header
->addr_size
)
19762 retval
= bfd_get_signed_16 (abfd
, buf
);
19765 retval
= bfd_get_signed_32 (abfd
, buf
);
19768 retval
= bfd_get_signed_64 (abfd
, buf
);
19771 internal_error (__FILE__
, __LINE__
,
19772 _("read_address: bad switch, signed [in module %s]"),
19773 bfd_get_filename (abfd
));
19778 switch (cu_header
->addr_size
)
19781 retval
= bfd_get_16 (abfd
, buf
);
19784 retval
= bfd_get_32 (abfd
, buf
);
19787 retval
= bfd_get_64 (abfd
, buf
);
19790 internal_error (__FILE__
, __LINE__
,
19791 _("read_address: bad switch, "
19792 "unsigned [in module %s]"),
19793 bfd_get_filename (abfd
));
19797 *bytes_read
= cu_header
->addr_size
;
19801 /* Read the initial length from a section. The (draft) DWARF 3
19802 specification allows the initial length to take up either 4 bytes
19803 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19804 bytes describe the length and all offsets will be 8 bytes in length
19807 An older, non-standard 64-bit format is also handled by this
19808 function. The older format in question stores the initial length
19809 as an 8-byte quantity without an escape value. Lengths greater
19810 than 2^32 aren't very common which means that the initial 4 bytes
19811 is almost always zero. Since a length value of zero doesn't make
19812 sense for the 32-bit format, this initial zero can be considered to
19813 be an escape value which indicates the presence of the older 64-bit
19814 format. As written, the code can't detect (old format) lengths
19815 greater than 4GB. If it becomes necessary to handle lengths
19816 somewhat larger than 4GB, we could allow other small values (such
19817 as the non-sensical values of 1, 2, and 3) to also be used as
19818 escape values indicating the presence of the old format.
19820 The value returned via bytes_read should be used to increment the
19821 relevant pointer after calling read_initial_length().
19823 [ Note: read_initial_length() and read_offset() are based on the
19824 document entitled "DWARF Debugging Information Format", revision
19825 3, draft 8, dated November 19, 2001. This document was obtained
19828 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19830 This document is only a draft and is subject to change. (So beware.)
19832 Details regarding the older, non-standard 64-bit format were
19833 determined empirically by examining 64-bit ELF files produced by
19834 the SGI toolchain on an IRIX 6.5 machine.
19836 - Kevin, July 16, 2002
19840 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19842 LONGEST length
= bfd_get_32 (abfd
, buf
);
19844 if (length
== 0xffffffff)
19846 length
= bfd_get_64 (abfd
, buf
+ 4);
19849 else if (length
== 0)
19851 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19852 length
= bfd_get_64 (abfd
, buf
);
19863 /* Cover function for read_initial_length.
19864 Returns the length of the object at BUF, and stores the size of the
19865 initial length in *BYTES_READ and stores the size that offsets will be in
19867 If the initial length size is not equivalent to that specified in
19868 CU_HEADER then issue a complaint.
19869 This is useful when reading non-comp-unit headers. */
19872 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19873 const struct comp_unit_head
*cu_header
,
19874 unsigned int *bytes_read
,
19875 unsigned int *offset_size
)
19877 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19879 gdb_assert (cu_header
->initial_length_size
== 4
19880 || cu_header
->initial_length_size
== 8
19881 || cu_header
->initial_length_size
== 12);
19883 if (cu_header
->initial_length_size
!= *bytes_read
)
19884 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19886 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19890 /* Read an offset from the data stream. The size of the offset is
19891 given by cu_header->offset_size. */
19894 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19895 const struct comp_unit_head
*cu_header
,
19896 unsigned int *bytes_read
)
19898 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19900 *bytes_read
= cu_header
->offset_size
;
19904 /* Read an offset from the data stream. */
19907 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19909 LONGEST retval
= 0;
19911 switch (offset_size
)
19914 retval
= bfd_get_32 (abfd
, buf
);
19917 retval
= bfd_get_64 (abfd
, buf
);
19920 internal_error (__FILE__
, __LINE__
,
19921 _("read_offset_1: bad switch [in module %s]"),
19922 bfd_get_filename (abfd
));
19928 static const gdb_byte
*
19929 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19931 /* If the size of a host char is 8 bits, we can return a pointer
19932 to the buffer, otherwise we have to copy the data to a buffer
19933 allocated on the temporary obstack. */
19934 gdb_assert (HOST_CHAR_BIT
== 8);
19938 static const char *
19939 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19940 unsigned int *bytes_read_ptr
)
19942 /* If the size of a host char is 8 bits, we can return a pointer
19943 to the string, otherwise we have to copy the string to a buffer
19944 allocated on the temporary obstack. */
19945 gdb_assert (HOST_CHAR_BIT
== 8);
19948 *bytes_read_ptr
= 1;
19951 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19952 return (const char *) buf
;
19955 /* Return pointer to string at section SECT offset STR_OFFSET with error
19956 reporting strings FORM_NAME and SECT_NAME. */
19958 static const char *
19959 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19960 bfd
*abfd
, LONGEST str_offset
,
19961 struct dwarf2_section_info
*sect
,
19962 const char *form_name
,
19963 const char *sect_name
)
19965 dwarf2_read_section (objfile
, sect
);
19966 if (sect
->buffer
== NULL
)
19967 error (_("%s used without %s section [in module %s]"),
19968 form_name
, sect_name
, bfd_get_filename (abfd
));
19969 if (str_offset
>= sect
->size
)
19970 error (_("%s pointing outside of %s section [in module %s]"),
19971 form_name
, sect_name
, bfd_get_filename (abfd
));
19972 gdb_assert (HOST_CHAR_BIT
== 8);
19973 if (sect
->buffer
[str_offset
] == '\0')
19975 return (const char *) (sect
->buffer
+ str_offset
);
19978 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19980 static const char *
19981 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19982 bfd
*abfd
, LONGEST str_offset
)
19984 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19986 &dwarf2_per_objfile
->str
,
19987 "DW_FORM_strp", ".debug_str");
19990 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19992 static const char *
19993 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19994 bfd
*abfd
, LONGEST str_offset
)
19996 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19998 &dwarf2_per_objfile
->line_str
,
19999 "DW_FORM_line_strp",
20000 ".debug_line_str");
20003 /* Read a string at offset STR_OFFSET in the .debug_str section from
20004 the .dwz file DWZ. Throw an error if the offset is too large. If
20005 the string consists of a single NUL byte, return NULL; otherwise
20006 return a pointer to the string. */
20008 static const char *
20009 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
20010 LONGEST str_offset
)
20012 dwarf2_read_section (objfile
, &dwz
->str
);
20014 if (dwz
->str
.buffer
== NULL
)
20015 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
20016 "section [in module %s]"),
20017 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20018 if (str_offset
>= dwz
->str
.size
)
20019 error (_("DW_FORM_GNU_strp_alt pointing outside of "
20020 ".debug_str section [in module %s]"),
20021 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20022 gdb_assert (HOST_CHAR_BIT
== 8);
20023 if (dwz
->str
.buffer
[str_offset
] == '\0')
20025 return (const char *) (dwz
->str
.buffer
+ str_offset
);
20028 /* Return pointer to string at .debug_str offset as read from BUF.
20029 BUF is assumed to be in a compilation unit described by CU_HEADER.
20030 Return *BYTES_READ_PTR count of bytes read from BUF. */
20032 static const char *
20033 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
20034 const gdb_byte
*buf
,
20035 const struct comp_unit_head
*cu_header
,
20036 unsigned int *bytes_read_ptr
)
20038 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20040 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
20043 /* Return pointer to string at .debug_line_str offset as read from BUF.
20044 BUF is assumed to be in a compilation unit described by CU_HEADER.
20045 Return *BYTES_READ_PTR count of bytes read from BUF. */
20047 static const char *
20048 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20049 bfd
*abfd
, const gdb_byte
*buf
,
20050 const struct comp_unit_head
*cu_header
,
20051 unsigned int *bytes_read_ptr
)
20053 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20055 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
20060 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20061 unsigned int *bytes_read_ptr
)
20064 unsigned int num_read
;
20066 unsigned char byte
;
20073 byte
= bfd_get_8 (abfd
, buf
);
20076 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20077 if ((byte
& 128) == 0)
20083 *bytes_read_ptr
= num_read
;
20088 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20089 unsigned int *bytes_read_ptr
)
20092 int shift
, num_read
;
20093 unsigned char byte
;
20100 byte
= bfd_get_8 (abfd
, buf
);
20103 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20105 if ((byte
& 128) == 0)
20110 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
20111 result
|= -(((ULONGEST
) 1) << shift
);
20112 *bytes_read_ptr
= num_read
;
20116 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20117 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
20118 ADDR_SIZE is the size of addresses from the CU header. */
20121 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20122 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
20124 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20125 bfd
*abfd
= objfile
->obfd
;
20126 const gdb_byte
*info_ptr
;
20128 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20129 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20130 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20131 objfile_name (objfile
));
20132 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
20133 error (_("DW_FORM_addr_index pointing outside of "
20134 ".debug_addr section [in module %s]"),
20135 objfile_name (objfile
));
20136 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20137 + addr_base
+ addr_index
* addr_size
);
20138 if (addr_size
== 4)
20139 return bfd_get_32 (abfd
, info_ptr
);
20141 return bfd_get_64 (abfd
, info_ptr
);
20144 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20147 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20149 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20150 cu
->addr_base
, cu
->header
.addr_size
);
20153 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20156 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20157 unsigned int *bytes_read
)
20159 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20160 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20162 return read_addr_index (cu
, addr_index
);
20165 /* Data structure to pass results from dwarf2_read_addr_index_reader
20166 back to dwarf2_read_addr_index. */
20168 struct dwarf2_read_addr_index_data
20170 ULONGEST addr_base
;
20174 /* die_reader_func for dwarf2_read_addr_index. */
20177 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
20178 const gdb_byte
*info_ptr
,
20179 struct die_info
*comp_unit_die
,
20183 struct dwarf2_cu
*cu
= reader
->cu
;
20184 struct dwarf2_read_addr_index_data
*aidata
=
20185 (struct dwarf2_read_addr_index_data
*) data
;
20187 aidata
->addr_base
= cu
->addr_base
;
20188 aidata
->addr_size
= cu
->header
.addr_size
;
20191 /* Given an index in .debug_addr, fetch the value.
20192 NOTE: This can be called during dwarf expression evaluation,
20193 long after the debug information has been read, and thus per_cu->cu
20194 may no longer exist. */
20197 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20198 unsigned int addr_index
)
20200 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20201 struct dwarf2_cu
*cu
= per_cu
->cu
;
20202 ULONGEST addr_base
;
20205 /* We need addr_base and addr_size.
20206 If we don't have PER_CU->cu, we have to get it.
20207 Nasty, but the alternative is storing the needed info in PER_CU,
20208 which at this point doesn't seem justified: it's not clear how frequently
20209 it would get used and it would increase the size of every PER_CU.
20210 Entry points like dwarf2_per_cu_addr_size do a similar thing
20211 so we're not in uncharted territory here.
20212 Alas we need to be a bit more complicated as addr_base is contained
20215 We don't need to read the entire CU(/TU).
20216 We just need the header and top level die.
20218 IWBN to use the aging mechanism to let us lazily later discard the CU.
20219 For now we skip this optimization. */
20223 addr_base
= cu
->addr_base
;
20224 addr_size
= cu
->header
.addr_size
;
20228 struct dwarf2_read_addr_index_data aidata
;
20230 /* Note: We can't use init_cutu_and_read_dies_simple here,
20231 we need addr_base. */
20232 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
20233 dwarf2_read_addr_index_reader
, &aidata
);
20234 addr_base
= aidata
.addr_base
;
20235 addr_size
= aidata
.addr_size
;
20238 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20242 /* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
20243 This is only used by the Fission support. */
20245 static const char *
20246 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20248 struct dwarf2_cu
*cu
= reader
->cu
;
20249 struct dwarf2_per_objfile
*dwarf2_per_objfile
20250 = cu
->per_cu
->dwarf2_per_objfile
;
20251 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20252 const char *objf_name
= objfile_name (objfile
);
20253 bfd
*abfd
= objfile
->obfd
;
20254 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20255 struct dwarf2_section_info
*str_offsets_section
=
20256 &reader
->dwo_file
->sections
.str_offsets
;
20257 const gdb_byte
*info_ptr
;
20258 ULONGEST str_offset
;
20259 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20261 dwarf2_read_section (objfile
, str_section
);
20262 dwarf2_read_section (objfile
, str_offsets_section
);
20263 if (str_section
->buffer
== NULL
)
20264 error (_("%s used without .debug_str.dwo section"
20265 " in CU at offset %s [in module %s]"),
20266 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20267 if (str_offsets_section
->buffer
== NULL
)
20268 error (_("%s used without .debug_str_offsets.dwo section"
20269 " in CU at offset %s [in module %s]"),
20270 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20271 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20272 error (_("%s pointing outside of .debug_str_offsets.dwo"
20273 " section in CU at offset %s [in module %s]"),
20274 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20275 info_ptr
= (str_offsets_section
->buffer
20276 + str_index
* cu
->header
.offset_size
);
20277 if (cu
->header
.offset_size
== 4)
20278 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20280 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20281 if (str_offset
>= str_section
->size
)
20282 error (_("Offset from %s pointing outside of"
20283 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20284 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20285 return (const char *) (str_section
->buffer
+ str_offset
);
20288 /* Return the length of an LEB128 number in BUF. */
20291 leb128_size (const gdb_byte
*buf
)
20293 const gdb_byte
*begin
= buf
;
20299 if ((byte
& 128) == 0)
20300 return buf
- begin
;
20305 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20314 cu
->language
= language_c
;
20317 case DW_LANG_C_plus_plus
:
20318 case DW_LANG_C_plus_plus_11
:
20319 case DW_LANG_C_plus_plus_14
:
20320 cu
->language
= language_cplus
;
20323 cu
->language
= language_d
;
20325 case DW_LANG_Fortran77
:
20326 case DW_LANG_Fortran90
:
20327 case DW_LANG_Fortran95
:
20328 case DW_LANG_Fortran03
:
20329 case DW_LANG_Fortran08
:
20330 cu
->language
= language_fortran
;
20333 cu
->language
= language_go
;
20335 case DW_LANG_Mips_Assembler
:
20336 cu
->language
= language_asm
;
20338 case DW_LANG_Ada83
:
20339 case DW_LANG_Ada95
:
20340 cu
->language
= language_ada
;
20342 case DW_LANG_Modula2
:
20343 cu
->language
= language_m2
;
20345 case DW_LANG_Pascal83
:
20346 cu
->language
= language_pascal
;
20349 cu
->language
= language_objc
;
20352 case DW_LANG_Rust_old
:
20353 cu
->language
= language_rust
;
20355 case DW_LANG_Cobol74
:
20356 case DW_LANG_Cobol85
:
20358 cu
->language
= language_minimal
;
20361 cu
->language_defn
= language_def (cu
->language
);
20364 /* Return the named attribute or NULL if not there. */
20366 static struct attribute
*
20367 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20372 struct attribute
*spec
= NULL
;
20374 for (i
= 0; i
< die
->num_attrs
; ++i
)
20376 if (die
->attrs
[i
].name
== name
)
20377 return &die
->attrs
[i
];
20378 if (die
->attrs
[i
].name
== DW_AT_specification
20379 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20380 spec
= &die
->attrs
[i
];
20386 die
= follow_die_ref (die
, spec
, &cu
);
20392 /* Return the named attribute or NULL if not there,
20393 but do not follow DW_AT_specification, etc.
20394 This is for use in contexts where we're reading .debug_types dies.
20395 Following DW_AT_specification, DW_AT_abstract_origin will take us
20396 back up the chain, and we want to go down. */
20398 static struct attribute
*
20399 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20403 for (i
= 0; i
< die
->num_attrs
; ++i
)
20404 if (die
->attrs
[i
].name
== name
)
20405 return &die
->attrs
[i
];
20410 /* Return the string associated with a string-typed attribute, or NULL if it
20411 is either not found or is of an incorrect type. */
20413 static const char *
20414 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20416 struct attribute
*attr
;
20417 const char *str
= NULL
;
20419 attr
= dwarf2_attr (die
, name
, cu
);
20423 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20424 || attr
->form
== DW_FORM_string
20425 || attr
->form
== DW_FORM_strx
20426 || attr
->form
== DW_FORM_strx1
20427 || attr
->form
== DW_FORM_strx2
20428 || attr
->form
== DW_FORM_strx3
20429 || attr
->form
== DW_FORM_strx4
20430 || attr
->form
== DW_FORM_GNU_str_index
20431 || attr
->form
== DW_FORM_GNU_strp_alt
)
20432 str
= DW_STRING (attr
);
20434 complaint (_("string type expected for attribute %s for "
20435 "DIE at %s in module %s"),
20436 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20437 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20443 /* Return the dwo name or NULL if not present. If present, it is in either
20444 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20445 static const char *
20446 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20448 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20449 if (dwo_name
== nullptr)
20450 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20454 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20455 and holds a non-zero value. This function should only be used for
20456 DW_FORM_flag or DW_FORM_flag_present attributes. */
20459 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20461 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20463 return (attr
&& DW_UNSND (attr
));
20467 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20469 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20470 which value is non-zero. However, we have to be careful with
20471 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20472 (via dwarf2_flag_true_p) follows this attribute. So we may
20473 end up accidently finding a declaration attribute that belongs
20474 to a different DIE referenced by the specification attribute,
20475 even though the given DIE does not have a declaration attribute. */
20476 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20477 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20480 /* Return the die giving the specification for DIE, if there is
20481 one. *SPEC_CU is the CU containing DIE on input, and the CU
20482 containing the return value on output. If there is no
20483 specification, but there is an abstract origin, that is
20486 static struct die_info
*
20487 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20489 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20492 if (spec_attr
== NULL
)
20493 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20495 if (spec_attr
== NULL
)
20498 return follow_die_ref (die
, spec_attr
, spec_cu
);
20501 /* Stub for free_line_header to match void * callback types. */
20504 free_line_header_voidp (void *arg
)
20506 struct line_header
*lh
= (struct line_header
*) arg
;
20512 line_header::add_include_dir (const char *include_dir
)
20514 if (dwarf_line_debug
>= 2)
20518 new_size
= m_include_dirs
.size ();
20520 new_size
= m_include_dirs
.size () + 1;
20521 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20522 new_size
, include_dir
);
20524 m_include_dirs
.push_back (include_dir
);
20528 line_header::add_file_name (const char *name
,
20530 unsigned int mod_time
,
20531 unsigned int length
)
20533 if (dwarf_line_debug
>= 2)
20537 new_size
= file_names_size ();
20539 new_size
= file_names_size () + 1;
20540 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20543 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20546 /* A convenience function to find the proper .debug_line section for a CU. */
20548 static struct dwarf2_section_info
*
20549 get_debug_line_section (struct dwarf2_cu
*cu
)
20551 struct dwarf2_section_info
*section
;
20552 struct dwarf2_per_objfile
*dwarf2_per_objfile
20553 = cu
->per_cu
->dwarf2_per_objfile
;
20555 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20557 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20558 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20559 else if (cu
->per_cu
->is_dwz
)
20561 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20563 section
= &dwz
->line
;
20566 section
= &dwarf2_per_objfile
->line
;
20571 /* Read directory or file name entry format, starting with byte of
20572 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20573 entries count and the entries themselves in the described entry
20577 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20578 bfd
*abfd
, const gdb_byte
**bufp
,
20579 struct line_header
*lh
,
20580 const struct comp_unit_head
*cu_header
,
20581 void (*callback
) (struct line_header
*lh
,
20584 unsigned int mod_time
,
20585 unsigned int length
))
20587 gdb_byte format_count
, formati
;
20588 ULONGEST data_count
, datai
;
20589 const gdb_byte
*buf
= *bufp
;
20590 const gdb_byte
*format_header_data
;
20591 unsigned int bytes_read
;
20593 format_count
= read_1_byte (abfd
, buf
);
20595 format_header_data
= buf
;
20596 for (formati
= 0; formati
< format_count
; formati
++)
20598 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20600 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20604 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20606 for (datai
= 0; datai
< data_count
; datai
++)
20608 const gdb_byte
*format
= format_header_data
;
20609 struct file_entry fe
;
20611 for (formati
= 0; formati
< format_count
; formati
++)
20613 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20614 format
+= bytes_read
;
20616 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20617 format
+= bytes_read
;
20619 gdb::optional
<const char *> string
;
20620 gdb::optional
<unsigned int> uint
;
20624 case DW_FORM_string
:
20625 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20629 case DW_FORM_line_strp
:
20630 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20637 case DW_FORM_data1
:
20638 uint
.emplace (read_1_byte (abfd
, buf
));
20642 case DW_FORM_data2
:
20643 uint
.emplace (read_2_bytes (abfd
, buf
));
20647 case DW_FORM_data4
:
20648 uint
.emplace (read_4_bytes (abfd
, buf
));
20652 case DW_FORM_data8
:
20653 uint
.emplace (read_8_bytes (abfd
, buf
));
20657 case DW_FORM_data16
:
20658 /* This is used for MD5, but file_entry does not record MD5s. */
20662 case DW_FORM_udata
:
20663 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20667 case DW_FORM_block
:
20668 /* It is valid only for DW_LNCT_timestamp which is ignored by
20673 switch (content_type
)
20676 if (string
.has_value ())
20679 case DW_LNCT_directory_index
:
20680 if (uint
.has_value ())
20681 fe
.d_index
= (dir_index
) *uint
;
20683 case DW_LNCT_timestamp
:
20684 if (uint
.has_value ())
20685 fe
.mod_time
= *uint
;
20688 if (uint
.has_value ())
20694 complaint (_("Unknown format content type %s"),
20695 pulongest (content_type
));
20699 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20705 /* Read the statement program header starting at OFFSET in
20706 .debug_line, or .debug_line.dwo. Return a pointer
20707 to a struct line_header, allocated using xmalloc.
20708 Returns NULL if there is a problem reading the header, e.g., if it
20709 has a version we don't understand.
20711 NOTE: the strings in the include directory and file name tables of
20712 the returned object point into the dwarf line section buffer,
20713 and must not be freed. */
20715 static line_header_up
20716 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20718 const gdb_byte
*line_ptr
;
20719 unsigned int bytes_read
, offset_size
;
20721 const char *cur_dir
, *cur_file
;
20722 struct dwarf2_section_info
*section
;
20724 struct dwarf2_per_objfile
*dwarf2_per_objfile
20725 = cu
->per_cu
->dwarf2_per_objfile
;
20727 section
= get_debug_line_section (cu
);
20728 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20729 if (section
->buffer
== NULL
)
20731 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20732 complaint (_("missing .debug_line.dwo section"));
20734 complaint (_("missing .debug_line section"));
20738 /* We can't do this until we know the section is non-empty.
20739 Only then do we know we have such a section. */
20740 abfd
= get_section_bfd_owner (section
);
20742 /* Make sure that at least there's room for the total_length field.
20743 That could be 12 bytes long, but we're just going to fudge that. */
20744 if (to_underlying (sect_off
) + 4 >= section
->size
)
20746 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20750 line_header_up
lh (new line_header ());
20752 lh
->sect_off
= sect_off
;
20753 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20755 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20757 /* Read in the header. */
20759 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20760 &bytes_read
, &offset_size
);
20761 line_ptr
+= bytes_read
;
20763 const gdb_byte
*start_here
= line_ptr
;
20765 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20767 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20770 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20771 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20773 if (lh
->version
> 5)
20775 /* This is a version we don't understand. The format could have
20776 changed in ways we don't handle properly so just punt. */
20777 complaint (_("unsupported version in .debug_line section"));
20780 if (lh
->version
>= 5)
20782 gdb_byte segment_selector_size
;
20784 /* Skip address size. */
20785 read_1_byte (abfd
, line_ptr
);
20788 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20790 if (segment_selector_size
!= 0)
20792 complaint (_("unsupported segment selector size %u "
20793 "in .debug_line section"),
20794 segment_selector_size
);
20798 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20799 line_ptr
+= offset_size
;
20800 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20801 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20803 if (lh
->version
>= 4)
20805 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20809 lh
->maximum_ops_per_instruction
= 1;
20811 if (lh
->maximum_ops_per_instruction
== 0)
20813 lh
->maximum_ops_per_instruction
= 1;
20814 complaint (_("invalid maximum_ops_per_instruction "
20815 "in `.debug_line' section"));
20818 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20820 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20822 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20824 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20826 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20828 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20829 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20831 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20835 if (lh
->version
>= 5)
20837 /* Read directory table. */
20838 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20840 [] (struct line_header
*header
, const char *name
,
20841 dir_index d_index
, unsigned int mod_time
,
20842 unsigned int length
)
20844 header
->add_include_dir (name
);
20847 /* Read file name table. */
20848 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20850 [] (struct line_header
*header
, const char *name
,
20851 dir_index d_index
, unsigned int mod_time
,
20852 unsigned int length
)
20854 header
->add_file_name (name
, d_index
, mod_time
, length
);
20859 /* Read directory table. */
20860 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20862 line_ptr
+= bytes_read
;
20863 lh
->add_include_dir (cur_dir
);
20865 line_ptr
+= bytes_read
;
20867 /* Read file name table. */
20868 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20870 unsigned int mod_time
, length
;
20873 line_ptr
+= bytes_read
;
20874 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20875 line_ptr
+= bytes_read
;
20876 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20877 line_ptr
+= bytes_read
;
20878 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20879 line_ptr
+= bytes_read
;
20881 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20883 line_ptr
+= bytes_read
;
20886 if (line_ptr
> (section
->buffer
+ section
->size
))
20887 complaint (_("line number info header doesn't "
20888 "fit in `.debug_line' section"));
20893 /* Subroutine of dwarf_decode_lines to simplify it.
20894 Return the file name of the psymtab for the given file_entry.
20895 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20896 If space for the result is malloc'd, *NAME_HOLDER will be set.
20897 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20899 static const char *
20900 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20901 const struct partial_symtab
*pst
,
20902 const char *comp_dir
,
20903 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20905 const char *include_name
= fe
.name
;
20906 const char *include_name_to_compare
= include_name
;
20907 const char *pst_filename
;
20910 const char *dir_name
= fe
.include_dir (lh
);
20912 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20913 if (!IS_ABSOLUTE_PATH (include_name
)
20914 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20916 /* Avoid creating a duplicate psymtab for PST.
20917 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20918 Before we do the comparison, however, we need to account
20919 for DIR_NAME and COMP_DIR.
20920 First prepend dir_name (if non-NULL). If we still don't
20921 have an absolute path prepend comp_dir (if non-NULL).
20922 However, the directory we record in the include-file's
20923 psymtab does not contain COMP_DIR (to match the
20924 corresponding symtab(s)).
20929 bash$ gcc -g ./hello.c
20930 include_name = "hello.c"
20932 DW_AT_comp_dir = comp_dir = "/tmp"
20933 DW_AT_name = "./hello.c"
20937 if (dir_name
!= NULL
)
20939 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20940 include_name
, (char *) NULL
));
20941 include_name
= name_holder
->get ();
20942 include_name_to_compare
= include_name
;
20944 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20946 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20947 include_name
, (char *) NULL
));
20948 include_name_to_compare
= hold_compare
.get ();
20952 pst_filename
= pst
->filename
;
20953 gdb::unique_xmalloc_ptr
<char> copied_name
;
20954 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20956 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20957 pst_filename
, (char *) NULL
));
20958 pst_filename
= copied_name
.get ();
20961 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20965 return include_name
;
20968 /* State machine to track the state of the line number program. */
20970 class lnp_state_machine
20973 /* Initialize a machine state for the start of a line number
20975 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20976 bool record_lines_p
);
20978 file_entry
*current_file ()
20980 /* lh->file_names is 0-based, but the file name numbers in the
20981 statement program are 1-based. */
20982 return m_line_header
->file_name_at (m_file
);
20985 /* Record the line in the state machine. END_SEQUENCE is true if
20986 we're processing the end of a sequence. */
20987 void record_line (bool end_sequence
);
20989 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20990 nop-out rest of the lines in this sequence. */
20991 void check_line_address (struct dwarf2_cu
*cu
,
20992 const gdb_byte
*line_ptr
,
20993 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20995 void handle_set_discriminator (unsigned int discriminator
)
20997 m_discriminator
= discriminator
;
20998 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21001 /* Handle DW_LNE_set_address. */
21002 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21005 address
+= baseaddr
;
21006 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21009 /* Handle DW_LNS_advance_pc. */
21010 void handle_advance_pc (CORE_ADDR adjust
);
21012 /* Handle a special opcode. */
21013 void handle_special_opcode (unsigned char op_code
);
21015 /* Handle DW_LNS_advance_line. */
21016 void handle_advance_line (int line_delta
)
21018 advance_line (line_delta
);
21021 /* Handle DW_LNS_set_file. */
21022 void handle_set_file (file_name_index file
);
21024 /* Handle DW_LNS_negate_stmt. */
21025 void handle_negate_stmt ()
21027 m_is_stmt
= !m_is_stmt
;
21030 /* Handle DW_LNS_const_add_pc. */
21031 void handle_const_add_pc ();
21033 /* Handle DW_LNS_fixed_advance_pc. */
21034 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21036 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21040 /* Handle DW_LNS_copy. */
21041 void handle_copy ()
21043 record_line (false);
21044 m_discriminator
= 0;
21047 /* Handle DW_LNE_end_sequence. */
21048 void handle_end_sequence ()
21050 m_currently_recording_lines
= true;
21054 /* Advance the line by LINE_DELTA. */
21055 void advance_line (int line_delta
)
21057 m_line
+= line_delta
;
21059 if (line_delta
!= 0)
21060 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21063 struct dwarf2_cu
*m_cu
;
21065 gdbarch
*m_gdbarch
;
21067 /* True if we're recording lines.
21068 Otherwise we're building partial symtabs and are just interested in
21069 finding include files mentioned by the line number program. */
21070 bool m_record_lines_p
;
21072 /* The line number header. */
21073 line_header
*m_line_header
;
21075 /* These are part of the standard DWARF line number state machine,
21076 and initialized according to the DWARF spec. */
21078 unsigned char m_op_index
= 0;
21079 /* The line table index of the current file. */
21080 file_name_index m_file
= 1;
21081 unsigned int m_line
= 1;
21083 /* These are initialized in the constructor. */
21085 CORE_ADDR m_address
;
21087 unsigned int m_discriminator
;
21089 /* Additional bits of state we need to track. */
21091 /* The last file that we called dwarf2_start_subfile for.
21092 This is only used for TLLs. */
21093 unsigned int m_last_file
= 0;
21094 /* The last file a line number was recorded for. */
21095 struct subfile
*m_last_subfile
= NULL
;
21097 /* When true, record the lines we decode. */
21098 bool m_currently_recording_lines
= false;
21100 /* The last line number that was recorded, used to coalesce
21101 consecutive entries for the same line. This can happen, for
21102 example, when discriminators are present. PR 17276. */
21103 unsigned int m_last_line
= 0;
21104 bool m_line_has_non_zero_discriminator
= false;
21108 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21110 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21111 / m_line_header
->maximum_ops_per_instruction
)
21112 * m_line_header
->minimum_instruction_length
);
21113 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21114 m_op_index
= ((m_op_index
+ adjust
)
21115 % m_line_header
->maximum_ops_per_instruction
);
21119 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21121 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21122 CORE_ADDR addr_adj
= (((m_op_index
21123 + (adj_opcode
/ m_line_header
->line_range
))
21124 / m_line_header
->maximum_ops_per_instruction
)
21125 * m_line_header
->minimum_instruction_length
);
21126 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21127 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
21128 % m_line_header
->maximum_ops_per_instruction
);
21130 int line_delta
= (m_line_header
->line_base
21131 + (adj_opcode
% m_line_header
->line_range
));
21132 advance_line (line_delta
);
21133 record_line (false);
21134 m_discriminator
= 0;
21138 lnp_state_machine::handle_set_file (file_name_index file
)
21142 const file_entry
*fe
= current_file ();
21144 dwarf2_debug_line_missing_file_complaint ();
21145 else if (m_record_lines_p
)
21147 const char *dir
= fe
->include_dir (m_line_header
);
21149 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21150 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21151 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21156 lnp_state_machine::handle_const_add_pc ()
21159 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21162 = (((m_op_index
+ adjust
)
21163 / m_line_header
->maximum_ops_per_instruction
)
21164 * m_line_header
->minimum_instruction_length
);
21166 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21167 m_op_index
= ((m_op_index
+ adjust
)
21168 % m_line_header
->maximum_ops_per_instruction
);
21171 /* Return non-zero if we should add LINE to the line number table.
21172 LINE is the line to add, LAST_LINE is the last line that was added,
21173 LAST_SUBFILE is the subfile for LAST_LINE.
21174 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21175 had a non-zero discriminator.
21177 We have to be careful in the presence of discriminators.
21178 E.g., for this line:
21180 for (i = 0; i < 100000; i++);
21182 clang can emit four line number entries for that one line,
21183 each with a different discriminator.
21184 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21186 However, we want gdb to coalesce all four entries into one.
21187 Otherwise the user could stepi into the middle of the line and
21188 gdb would get confused about whether the pc really was in the
21189 middle of the line.
21191 Things are further complicated by the fact that two consecutive
21192 line number entries for the same line is a heuristic used by gcc
21193 to denote the end of the prologue. So we can't just discard duplicate
21194 entries, we have to be selective about it. The heuristic we use is
21195 that we only collapse consecutive entries for the same line if at least
21196 one of those entries has a non-zero discriminator. PR 17276.
21198 Note: Addresses in the line number state machine can never go backwards
21199 within one sequence, thus this coalescing is ok. */
21202 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21203 unsigned int line
, unsigned int last_line
,
21204 int line_has_non_zero_discriminator
,
21205 struct subfile
*last_subfile
)
21207 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21209 if (line
!= last_line
)
21211 /* Same line for the same file that we've seen already.
21212 As a last check, for pr 17276, only record the line if the line
21213 has never had a non-zero discriminator. */
21214 if (!line_has_non_zero_discriminator
)
21219 /* Use the CU's builder to record line number LINE beginning at
21220 address ADDRESS in the line table of subfile SUBFILE. */
21223 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21224 unsigned int line
, CORE_ADDR address
,
21225 struct dwarf2_cu
*cu
)
21227 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21229 if (dwarf_line_debug
)
21231 fprintf_unfiltered (gdb_stdlog
,
21232 "Recording line %u, file %s, address %s\n",
21233 line
, lbasename (subfile
->name
),
21234 paddress (gdbarch
, address
));
21238 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21241 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21242 Mark the end of a set of line number records.
21243 The arguments are the same as for dwarf_record_line_1.
21244 If SUBFILE is NULL the request is ignored. */
21247 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21248 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21250 if (subfile
== NULL
)
21253 if (dwarf_line_debug
)
21255 fprintf_unfiltered (gdb_stdlog
,
21256 "Finishing current line, file %s, address %s\n",
21257 lbasename (subfile
->name
),
21258 paddress (gdbarch
, address
));
21261 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21265 lnp_state_machine::record_line (bool end_sequence
)
21267 if (dwarf_line_debug
)
21269 fprintf_unfiltered (gdb_stdlog
,
21270 "Processing actual line %u: file %u,"
21271 " address %s, is_stmt %u, discrim %u\n",
21273 paddress (m_gdbarch
, m_address
),
21274 m_is_stmt
, m_discriminator
);
21277 file_entry
*fe
= current_file ();
21280 dwarf2_debug_line_missing_file_complaint ();
21281 /* For now we ignore lines not starting on an instruction boundary.
21282 But not when processing end_sequence for compatibility with the
21283 previous version of the code. */
21284 else if (m_op_index
== 0 || end_sequence
)
21286 fe
->included_p
= 1;
21287 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
21289 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21292 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21293 m_currently_recording_lines
? m_cu
: nullptr);
21298 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21299 m_line_has_non_zero_discriminator
,
21302 buildsym_compunit
*builder
= m_cu
->get_builder ();
21303 dwarf_record_line_1 (m_gdbarch
,
21304 builder
->get_current_subfile (),
21306 m_currently_recording_lines
? m_cu
: nullptr);
21308 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21309 m_last_line
= m_line
;
21315 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21316 line_header
*lh
, bool record_lines_p
)
21320 m_record_lines_p
= record_lines_p
;
21321 m_line_header
= lh
;
21323 m_currently_recording_lines
= true;
21325 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21326 was a line entry for it so that the backend has a chance to adjust it
21327 and also record it in case it needs it. This is currently used by MIPS
21328 code, cf. `mips_adjust_dwarf2_line'. */
21329 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21330 m_is_stmt
= lh
->default_is_stmt
;
21331 m_discriminator
= 0;
21335 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21336 const gdb_byte
*line_ptr
,
21337 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21339 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21340 the pc range of the CU. However, we restrict the test to only ADDRESS
21341 values of zero to preserve GDB's previous behaviour which is to handle
21342 the specific case of a function being GC'd by the linker. */
21344 if (address
== 0 && address
< unrelocated_lowpc
)
21346 /* This line table is for a function which has been
21347 GCd by the linker. Ignore it. PR gdb/12528 */
21349 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21350 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21352 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21353 line_offset
, objfile_name (objfile
));
21354 m_currently_recording_lines
= false;
21355 /* Note: m_currently_recording_lines is left as false until we see
21356 DW_LNE_end_sequence. */
21360 /* Subroutine of dwarf_decode_lines to simplify it.
21361 Process the line number information in LH.
21362 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21363 program in order to set included_p for every referenced header. */
21366 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21367 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21369 const gdb_byte
*line_ptr
, *extended_end
;
21370 const gdb_byte
*line_end
;
21371 unsigned int bytes_read
, extended_len
;
21372 unsigned char op_code
, extended_op
;
21373 CORE_ADDR baseaddr
;
21374 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21375 bfd
*abfd
= objfile
->obfd
;
21376 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21377 /* True if we're recording line info (as opposed to building partial
21378 symtabs and just interested in finding include files mentioned by
21379 the line number program). */
21380 bool record_lines_p
= !decode_for_pst_p
;
21382 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
21384 line_ptr
= lh
->statement_program_start
;
21385 line_end
= lh
->statement_program_end
;
21387 /* Read the statement sequences until there's nothing left. */
21388 while (line_ptr
< line_end
)
21390 /* The DWARF line number program state machine. Reset the state
21391 machine at the start of each sequence. */
21392 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21393 bool end_sequence
= false;
21395 if (record_lines_p
)
21397 /* Start a subfile for the current file of the state
21399 const file_entry
*fe
= state_machine
.current_file ();
21402 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21405 /* Decode the table. */
21406 while (line_ptr
< line_end
&& !end_sequence
)
21408 op_code
= read_1_byte (abfd
, line_ptr
);
21411 if (op_code
>= lh
->opcode_base
)
21413 /* Special opcode. */
21414 state_machine
.handle_special_opcode (op_code
);
21416 else switch (op_code
)
21418 case DW_LNS_extended_op
:
21419 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21421 line_ptr
+= bytes_read
;
21422 extended_end
= line_ptr
+ extended_len
;
21423 extended_op
= read_1_byte (abfd
, line_ptr
);
21425 switch (extended_op
)
21427 case DW_LNE_end_sequence
:
21428 state_machine
.handle_end_sequence ();
21429 end_sequence
= true;
21431 case DW_LNE_set_address
:
21434 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21435 line_ptr
+= bytes_read
;
21437 state_machine
.check_line_address (cu
, line_ptr
,
21438 lowpc
- baseaddr
, address
);
21439 state_machine
.handle_set_address (baseaddr
, address
);
21442 case DW_LNE_define_file
:
21444 const char *cur_file
;
21445 unsigned int mod_time
, length
;
21448 cur_file
= read_direct_string (abfd
, line_ptr
,
21450 line_ptr
+= bytes_read
;
21451 dindex
= (dir_index
)
21452 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21453 line_ptr
+= bytes_read
;
21455 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21456 line_ptr
+= bytes_read
;
21458 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21459 line_ptr
+= bytes_read
;
21460 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21463 case DW_LNE_set_discriminator
:
21465 /* The discriminator is not interesting to the
21466 debugger; just ignore it. We still need to
21467 check its value though:
21468 if there are consecutive entries for the same
21469 (non-prologue) line we want to coalesce them.
21472 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21473 line_ptr
+= bytes_read
;
21475 state_machine
.handle_set_discriminator (discr
);
21479 complaint (_("mangled .debug_line section"));
21482 /* Make sure that we parsed the extended op correctly. If e.g.
21483 we expected a different address size than the producer used,
21484 we may have read the wrong number of bytes. */
21485 if (line_ptr
!= extended_end
)
21487 complaint (_("mangled .debug_line section"));
21492 state_machine
.handle_copy ();
21494 case DW_LNS_advance_pc
:
21497 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21498 line_ptr
+= bytes_read
;
21500 state_machine
.handle_advance_pc (adjust
);
21503 case DW_LNS_advance_line
:
21506 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21507 line_ptr
+= bytes_read
;
21509 state_machine
.handle_advance_line (line_delta
);
21512 case DW_LNS_set_file
:
21514 file_name_index file
21515 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21517 line_ptr
+= bytes_read
;
21519 state_machine
.handle_set_file (file
);
21522 case DW_LNS_set_column
:
21523 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21524 line_ptr
+= bytes_read
;
21526 case DW_LNS_negate_stmt
:
21527 state_machine
.handle_negate_stmt ();
21529 case DW_LNS_set_basic_block
:
21531 /* Add to the address register of the state machine the
21532 address increment value corresponding to special opcode
21533 255. I.e., this value is scaled by the minimum
21534 instruction length since special opcode 255 would have
21535 scaled the increment. */
21536 case DW_LNS_const_add_pc
:
21537 state_machine
.handle_const_add_pc ();
21539 case DW_LNS_fixed_advance_pc
:
21541 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21544 state_machine
.handle_fixed_advance_pc (addr_adj
);
21549 /* Unknown standard opcode, ignore it. */
21552 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21554 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21555 line_ptr
+= bytes_read
;
21562 dwarf2_debug_line_missing_end_sequence_complaint ();
21564 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21565 in which case we still finish recording the last line). */
21566 state_machine
.record_line (true);
21570 /* Decode the Line Number Program (LNP) for the given line_header
21571 structure and CU. The actual information extracted and the type
21572 of structures created from the LNP depends on the value of PST.
21574 1. If PST is NULL, then this procedure uses the data from the program
21575 to create all necessary symbol tables, and their linetables.
21577 2. If PST is not NULL, this procedure reads the program to determine
21578 the list of files included by the unit represented by PST, and
21579 builds all the associated partial symbol tables.
21581 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21582 It is used for relative paths in the line table.
21583 NOTE: When processing partial symtabs (pst != NULL),
21584 comp_dir == pst->dirname.
21586 NOTE: It is important that psymtabs have the same file name (via strcmp)
21587 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21588 symtab we don't use it in the name of the psymtabs we create.
21589 E.g. expand_line_sal requires this when finding psymtabs to expand.
21590 A good testcase for this is mb-inline.exp.
21592 LOWPC is the lowest address in CU (or 0 if not known).
21594 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21595 for its PC<->lines mapping information. Otherwise only the filename
21596 table is read in. */
21599 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21600 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21601 CORE_ADDR lowpc
, int decode_mapping
)
21603 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21604 const int decode_for_pst_p
= (pst
!= NULL
);
21606 if (decode_mapping
)
21607 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21609 if (decode_for_pst_p
)
21611 /* Now that we're done scanning the Line Header Program, we can
21612 create the psymtab of each included file. */
21613 for (auto &file_entry
: lh
->file_names ())
21614 if (file_entry
.included_p
== 1)
21616 gdb::unique_xmalloc_ptr
<char> name_holder
;
21617 const char *include_name
=
21618 psymtab_include_file_name (lh
, file_entry
, pst
,
21619 comp_dir
, &name_holder
);
21620 if (include_name
!= NULL
)
21621 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21626 /* Make sure a symtab is created for every file, even files
21627 which contain only variables (i.e. no code with associated
21629 buildsym_compunit
*builder
= cu
->get_builder ();
21630 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21632 for (auto &fe
: lh
->file_names ())
21634 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21635 if (builder
->get_current_subfile ()->symtab
== NULL
)
21637 builder
->get_current_subfile ()->symtab
21638 = allocate_symtab (cust
,
21639 builder
->get_current_subfile ()->name
);
21641 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21646 /* Start a subfile for DWARF. FILENAME is the name of the file and
21647 DIRNAME the name of the source directory which contains FILENAME
21648 or NULL if not known.
21649 This routine tries to keep line numbers from identical absolute and
21650 relative file names in a common subfile.
21652 Using the `list' example from the GDB testsuite, which resides in
21653 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21654 of /srcdir/list0.c yields the following debugging information for list0.c:
21656 DW_AT_name: /srcdir/list0.c
21657 DW_AT_comp_dir: /compdir
21658 files.files[0].name: list0.h
21659 files.files[0].dir: /srcdir
21660 files.files[1].name: list0.c
21661 files.files[1].dir: /srcdir
21663 The line number information for list0.c has to end up in a single
21664 subfile, so that `break /srcdir/list0.c:1' works as expected.
21665 start_subfile will ensure that this happens provided that we pass the
21666 concatenation of files.files[1].dir and files.files[1].name as the
21670 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21671 const char *dirname
)
21673 gdb::unique_xmalloc_ptr
<char> copy
;
21675 /* In order not to lose the line information directory,
21676 we concatenate it to the filename when it makes sense.
21677 Note that the Dwarf3 standard says (speaking of filenames in line
21678 information): ``The directory index is ignored for file names
21679 that represent full path names''. Thus ignoring dirname in the
21680 `else' branch below isn't an issue. */
21682 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21684 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21685 filename
= copy
.get ();
21688 cu
->get_builder ()->start_subfile (filename
);
21691 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21692 buildsym_compunit constructor. */
21694 struct compunit_symtab
*
21695 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21698 gdb_assert (m_builder
== nullptr);
21700 m_builder
.reset (new struct buildsym_compunit
21701 (per_cu
->dwarf2_per_objfile
->objfile
,
21702 name
, comp_dir
, language
, low_pc
));
21704 list_in_scope
= get_builder ()->get_file_symbols ();
21706 get_builder ()->record_debugformat (xstrprintf ("DWARF %d", this->header
.version
));
21707 get_builder ()->record_producer (producer
);
21709 processing_has_namespace_info
= false;
21711 return get_builder ()->get_compunit_symtab ();
21715 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21716 struct dwarf2_cu
*cu
)
21718 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21719 struct comp_unit_head
*cu_header
= &cu
->header
;
21721 /* NOTE drow/2003-01-30: There used to be a comment and some special
21722 code here to turn a symbol with DW_AT_external and a
21723 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21724 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21725 with some versions of binutils) where shared libraries could have
21726 relocations against symbols in their debug information - the
21727 minimal symbol would have the right address, but the debug info
21728 would not. It's no longer necessary, because we will explicitly
21729 apply relocations when we read in the debug information now. */
21731 /* A DW_AT_location attribute with no contents indicates that a
21732 variable has been optimized away. */
21733 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21735 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21739 /* Handle one degenerate form of location expression specially, to
21740 preserve GDB's previous behavior when section offsets are
21741 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21742 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21744 if (attr_form_is_block (attr
)
21745 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21746 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21747 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21748 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21749 && (DW_BLOCK (attr
)->size
21750 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21752 unsigned int dummy
;
21754 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21755 SET_SYMBOL_VALUE_ADDRESS (sym
,
21756 read_address (objfile
->obfd
,
21757 DW_BLOCK (attr
)->data
+ 1,
21760 SET_SYMBOL_VALUE_ADDRESS
21761 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21763 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21764 fixup_symbol_section (sym
, objfile
);
21765 SET_SYMBOL_VALUE_ADDRESS
21767 SYMBOL_VALUE_ADDRESS (sym
)
21768 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21772 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21773 expression evaluator, and use LOC_COMPUTED only when necessary
21774 (i.e. when the value of a register or memory location is
21775 referenced, or a thread-local block, etc.). Then again, it might
21776 not be worthwhile. I'm assuming that it isn't unless performance
21777 or memory numbers show me otherwise. */
21779 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21781 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21782 cu
->has_loclist
= true;
21785 /* Given a pointer to a DWARF information entry, figure out if we need
21786 to make a symbol table entry for it, and if so, create a new entry
21787 and return a pointer to it.
21788 If TYPE is NULL, determine symbol type from the die, otherwise
21789 used the passed type.
21790 If SPACE is not NULL, use it to hold the new symbol. If it is
21791 NULL, allocate a new symbol on the objfile's obstack. */
21793 static struct symbol
*
21794 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21795 struct symbol
*space
)
21797 struct dwarf2_per_objfile
*dwarf2_per_objfile
21798 = cu
->per_cu
->dwarf2_per_objfile
;
21799 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21800 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21801 struct symbol
*sym
= NULL
;
21803 struct attribute
*attr
= NULL
;
21804 struct attribute
*attr2
= NULL
;
21805 CORE_ADDR baseaddr
;
21806 struct pending
**list_to_add
= NULL
;
21808 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21810 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
21812 name
= dwarf2_name (die
, cu
);
21815 const char *linkagename
;
21816 int suppress_add
= 0;
21821 sym
= allocate_symbol (objfile
);
21822 OBJSTAT (objfile
, n_syms
++);
21824 /* Cache this symbol's name and the name's demangled form (if any). */
21825 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21826 linkagename
= dwarf2_physname (name
, die
, cu
);
21827 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21829 /* Fortran does not have mangling standard and the mangling does differ
21830 between gfortran, iFort etc. */
21831 if (cu
->language
== language_fortran
21832 && symbol_get_demangled_name (sym
) == NULL
)
21833 symbol_set_demangled_name (sym
,
21834 dwarf2_full_name (name
, die
, cu
),
21837 /* Default assumptions.
21838 Use the passed type or decode it from the die. */
21839 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21840 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21842 SYMBOL_TYPE (sym
) = type
;
21844 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21845 attr
= dwarf2_attr (die
,
21846 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21848 if (attr
!= nullptr)
21850 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21853 attr
= dwarf2_attr (die
,
21854 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21856 if (attr
!= nullptr)
21858 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21859 struct file_entry
*fe
;
21861 if (cu
->line_header
!= NULL
)
21862 fe
= cu
->line_header
->file_name_at (file_index
);
21867 complaint (_("file index out of range"));
21869 symbol_set_symtab (sym
, fe
->symtab
);
21875 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21876 if (attr
!= nullptr)
21880 addr
= attr_value_as_address (attr
);
21881 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21882 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21884 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21885 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21886 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21887 add_symbol_to_list (sym
, cu
->list_in_scope
);
21889 case DW_TAG_subprogram
:
21890 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21892 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21893 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21894 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21895 || cu
->language
== language_ada
21896 || cu
->language
== language_fortran
)
21898 /* Subprograms marked external are stored as a global symbol.
21899 Ada and Fortran subprograms, whether marked external or
21900 not, are always stored as a global symbol, because we want
21901 to be able to access them globally. For instance, we want
21902 to be able to break on a nested subprogram without having
21903 to specify the context. */
21904 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21908 list_to_add
= cu
->list_in_scope
;
21911 case DW_TAG_inlined_subroutine
:
21912 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21914 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21915 SYMBOL_INLINED (sym
) = 1;
21916 list_to_add
= cu
->list_in_scope
;
21918 case DW_TAG_template_value_param
:
21920 /* Fall through. */
21921 case DW_TAG_constant
:
21922 case DW_TAG_variable
:
21923 case DW_TAG_member
:
21924 /* Compilation with minimal debug info may result in
21925 variables with missing type entries. Change the
21926 misleading `void' type to something sensible. */
21927 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21928 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21930 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21931 /* In the case of DW_TAG_member, we should only be called for
21932 static const members. */
21933 if (die
->tag
== DW_TAG_member
)
21935 /* dwarf2_add_field uses die_is_declaration,
21936 so we do the same. */
21937 gdb_assert (die_is_declaration (die
, cu
));
21940 if (attr
!= nullptr)
21942 dwarf2_const_value (attr
, sym
, cu
);
21943 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21946 if (attr2
&& (DW_UNSND (attr2
) != 0))
21947 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21949 list_to_add
= cu
->list_in_scope
;
21953 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21954 if (attr
!= nullptr)
21956 var_decode_location (attr
, sym
, cu
);
21957 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21959 /* Fortran explicitly imports any global symbols to the local
21960 scope by DW_TAG_common_block. */
21961 if (cu
->language
== language_fortran
&& die
->parent
21962 && die
->parent
->tag
== DW_TAG_common_block
)
21965 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21966 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21967 && !dwarf2_per_objfile
->has_section_at_zero
)
21969 /* When a static variable is eliminated by the linker,
21970 the corresponding debug information is not stripped
21971 out, but the variable address is set to null;
21972 do not add such variables into symbol table. */
21974 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21976 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21977 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21978 && dwarf2_per_objfile
->can_copy
)
21980 /* A global static variable might be subject to
21981 copy relocation. We first check for a local
21982 minsym, though, because maybe the symbol was
21983 marked hidden, in which case this would not
21985 bound_minimal_symbol found
21986 = (lookup_minimal_symbol_linkage
21987 (sym
->linkage_name (), objfile
));
21988 if (found
.minsym
!= nullptr)
21989 sym
->maybe_copied
= 1;
21992 /* A variable with DW_AT_external is never static,
21993 but it may be block-scoped. */
21995 = ((cu
->list_in_scope
21996 == cu
->get_builder ()->get_file_symbols ())
21997 ? cu
->get_builder ()->get_global_symbols ()
21998 : cu
->list_in_scope
);
22001 list_to_add
= cu
->list_in_scope
;
22005 /* We do not know the address of this symbol.
22006 If it is an external symbol and we have type information
22007 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22008 The address of the variable will then be determined from
22009 the minimal symbol table whenever the variable is
22011 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22013 /* Fortran explicitly imports any global symbols to the local
22014 scope by DW_TAG_common_block. */
22015 if (cu
->language
== language_fortran
&& die
->parent
22016 && die
->parent
->tag
== DW_TAG_common_block
)
22018 /* SYMBOL_CLASS doesn't matter here because
22019 read_common_block is going to reset it. */
22021 list_to_add
= cu
->list_in_scope
;
22023 else if (attr2
&& (DW_UNSND (attr2
) != 0)
22024 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22026 /* A variable with DW_AT_external is never static, but it
22027 may be block-scoped. */
22029 = ((cu
->list_in_scope
22030 == cu
->get_builder ()->get_file_symbols ())
22031 ? cu
->get_builder ()->get_global_symbols ()
22032 : cu
->list_in_scope
);
22034 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22036 else if (!die_is_declaration (die
, cu
))
22038 /* Use the default LOC_OPTIMIZED_OUT class. */
22039 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22041 list_to_add
= cu
->list_in_scope
;
22045 case DW_TAG_formal_parameter
:
22047 /* If we are inside a function, mark this as an argument. If
22048 not, we might be looking at an argument to an inlined function
22049 when we do not have enough information to show inlined frames;
22050 pretend it's a local variable in that case so that the user can
22052 struct context_stack
*curr
22053 = cu
->get_builder ()->get_current_context_stack ();
22054 if (curr
!= nullptr && curr
->name
!= nullptr)
22055 SYMBOL_IS_ARGUMENT (sym
) = 1;
22056 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22057 if (attr
!= nullptr)
22059 var_decode_location (attr
, sym
, cu
);
22061 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22062 if (attr
!= nullptr)
22064 dwarf2_const_value (attr
, sym
, cu
);
22067 list_to_add
= cu
->list_in_scope
;
22070 case DW_TAG_unspecified_parameters
:
22071 /* From varargs functions; gdb doesn't seem to have any
22072 interest in this information, so just ignore it for now.
22075 case DW_TAG_template_type_param
:
22077 /* Fall through. */
22078 case DW_TAG_class_type
:
22079 case DW_TAG_interface_type
:
22080 case DW_TAG_structure_type
:
22081 case DW_TAG_union_type
:
22082 case DW_TAG_set_type
:
22083 case DW_TAG_enumeration_type
:
22084 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22085 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22088 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22089 really ever be static objects: otherwise, if you try
22090 to, say, break of a class's method and you're in a file
22091 which doesn't mention that class, it won't work unless
22092 the check for all static symbols in lookup_symbol_aux
22093 saves you. See the OtherFileClass tests in
22094 gdb.c++/namespace.exp. */
22098 buildsym_compunit
*builder
= cu
->get_builder ();
22100 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22101 && cu
->language
== language_cplus
22102 ? builder
->get_global_symbols ()
22103 : cu
->list_in_scope
);
22105 /* The semantics of C++ state that "struct foo {
22106 ... }" also defines a typedef for "foo". */
22107 if (cu
->language
== language_cplus
22108 || cu
->language
== language_ada
22109 || cu
->language
== language_d
22110 || cu
->language
== language_rust
)
22112 /* The symbol's name is already allocated along
22113 with this objfile, so we don't need to
22114 duplicate it for the type. */
22115 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
22116 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
22121 case DW_TAG_typedef
:
22122 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22123 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22124 list_to_add
= cu
->list_in_scope
;
22126 case DW_TAG_base_type
:
22127 case DW_TAG_subrange_type
:
22128 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22129 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22130 list_to_add
= cu
->list_in_scope
;
22132 case DW_TAG_enumerator
:
22133 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22134 if (attr
!= nullptr)
22136 dwarf2_const_value (attr
, sym
, cu
);
22139 /* NOTE: carlton/2003-11-10: See comment above in the
22140 DW_TAG_class_type, etc. block. */
22143 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22144 && cu
->language
== language_cplus
22145 ? cu
->get_builder ()->get_global_symbols ()
22146 : cu
->list_in_scope
);
22149 case DW_TAG_imported_declaration
:
22150 case DW_TAG_namespace
:
22151 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22152 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22154 case DW_TAG_module
:
22155 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22156 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22157 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22159 case DW_TAG_common_block
:
22160 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22161 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22162 add_symbol_to_list (sym
, cu
->list_in_scope
);
22165 /* Not a tag we recognize. Hopefully we aren't processing
22166 trash data, but since we must specifically ignore things
22167 we don't recognize, there is nothing else we should do at
22169 complaint (_("unsupported tag: '%s'"),
22170 dwarf_tag_name (die
->tag
));
22176 sym
->hash_next
= objfile
->template_symbols
;
22177 objfile
->template_symbols
= sym
;
22178 list_to_add
= NULL
;
22181 if (list_to_add
!= NULL
)
22182 add_symbol_to_list (sym
, list_to_add
);
22184 /* For the benefit of old versions of GCC, check for anonymous
22185 namespaces based on the demangled name. */
22186 if (!cu
->processing_has_namespace_info
22187 && cu
->language
== language_cplus
)
22188 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22193 /* Given an attr with a DW_FORM_dataN value in host byte order,
22194 zero-extend it as appropriate for the symbol's type. The DWARF
22195 standard (v4) is not entirely clear about the meaning of using
22196 DW_FORM_dataN for a constant with a signed type, where the type is
22197 wider than the data. The conclusion of a discussion on the DWARF
22198 list was that this is unspecified. We choose to always zero-extend
22199 because that is the interpretation long in use by GCC. */
22202 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22203 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22205 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22206 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22207 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22208 LONGEST l
= DW_UNSND (attr
);
22210 if (bits
< sizeof (*value
) * 8)
22212 l
&= ((LONGEST
) 1 << bits
) - 1;
22215 else if (bits
== sizeof (*value
) * 8)
22219 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22220 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22227 /* Read a constant value from an attribute. Either set *VALUE, or if
22228 the value does not fit in *VALUE, set *BYTES - either already
22229 allocated on the objfile obstack, or newly allocated on OBSTACK,
22230 or, set *BATON, if we translated the constant to a location
22234 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22235 const char *name
, struct obstack
*obstack
,
22236 struct dwarf2_cu
*cu
,
22237 LONGEST
*value
, const gdb_byte
**bytes
,
22238 struct dwarf2_locexpr_baton
**baton
)
22240 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22241 struct comp_unit_head
*cu_header
= &cu
->header
;
22242 struct dwarf_block
*blk
;
22243 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22244 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22250 switch (attr
->form
)
22253 case DW_FORM_addrx
:
22254 case DW_FORM_GNU_addr_index
:
22258 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22259 dwarf2_const_value_length_mismatch_complaint (name
,
22260 cu_header
->addr_size
,
22261 TYPE_LENGTH (type
));
22262 /* Symbols of this form are reasonably rare, so we just
22263 piggyback on the existing location code rather than writing
22264 a new implementation of symbol_computed_ops. */
22265 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22266 (*baton
)->per_cu
= cu
->per_cu
;
22267 gdb_assert ((*baton
)->per_cu
);
22269 (*baton
)->size
= 2 + cu_header
->addr_size
;
22270 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22271 (*baton
)->data
= data
;
22273 data
[0] = DW_OP_addr
;
22274 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22275 byte_order
, DW_ADDR (attr
));
22276 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22279 case DW_FORM_string
:
22282 case DW_FORM_GNU_str_index
:
22283 case DW_FORM_GNU_strp_alt
:
22284 /* DW_STRING is already allocated on the objfile obstack, point
22286 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22288 case DW_FORM_block1
:
22289 case DW_FORM_block2
:
22290 case DW_FORM_block4
:
22291 case DW_FORM_block
:
22292 case DW_FORM_exprloc
:
22293 case DW_FORM_data16
:
22294 blk
= DW_BLOCK (attr
);
22295 if (TYPE_LENGTH (type
) != blk
->size
)
22296 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22297 TYPE_LENGTH (type
));
22298 *bytes
= blk
->data
;
22301 /* The DW_AT_const_value attributes are supposed to carry the
22302 symbol's value "represented as it would be on the target
22303 architecture." By the time we get here, it's already been
22304 converted to host endianness, so we just need to sign- or
22305 zero-extend it as appropriate. */
22306 case DW_FORM_data1
:
22307 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22309 case DW_FORM_data2
:
22310 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22312 case DW_FORM_data4
:
22313 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22315 case DW_FORM_data8
:
22316 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22319 case DW_FORM_sdata
:
22320 case DW_FORM_implicit_const
:
22321 *value
= DW_SND (attr
);
22324 case DW_FORM_udata
:
22325 *value
= DW_UNSND (attr
);
22329 complaint (_("unsupported const value attribute form: '%s'"),
22330 dwarf_form_name (attr
->form
));
22337 /* Copy constant value from an attribute to a symbol. */
22340 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22341 struct dwarf2_cu
*cu
)
22343 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22345 const gdb_byte
*bytes
;
22346 struct dwarf2_locexpr_baton
*baton
;
22348 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22349 sym
->print_name (),
22350 &objfile
->objfile_obstack
, cu
,
22351 &value
, &bytes
, &baton
);
22355 SYMBOL_LOCATION_BATON (sym
) = baton
;
22356 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22358 else if (bytes
!= NULL
)
22360 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22361 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22365 SYMBOL_VALUE (sym
) = value
;
22366 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22370 /* Return the type of the die in question using its DW_AT_type attribute. */
22372 static struct type
*
22373 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22375 struct attribute
*type_attr
;
22377 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22380 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22381 /* A missing DW_AT_type represents a void type. */
22382 return objfile_type (objfile
)->builtin_void
;
22385 return lookup_die_type (die
, type_attr
, cu
);
22388 /* True iff CU's producer generates GNAT Ada auxiliary information
22389 that allows to find parallel types through that information instead
22390 of having to do expensive parallel lookups by type name. */
22393 need_gnat_info (struct dwarf2_cu
*cu
)
22395 /* Assume that the Ada compiler was GNAT, which always produces
22396 the auxiliary information. */
22397 return (cu
->language
== language_ada
);
22400 /* Return the auxiliary type of the die in question using its
22401 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22402 attribute is not present. */
22404 static struct type
*
22405 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22407 struct attribute
*type_attr
;
22409 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22413 return lookup_die_type (die
, type_attr
, cu
);
22416 /* If DIE has a descriptive_type attribute, then set the TYPE's
22417 descriptive type accordingly. */
22420 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22421 struct dwarf2_cu
*cu
)
22423 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22425 if (descriptive_type
)
22427 ALLOCATE_GNAT_AUX_TYPE (type
);
22428 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22432 /* Return the containing type of the die in question using its
22433 DW_AT_containing_type attribute. */
22435 static struct type
*
22436 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22438 struct attribute
*type_attr
;
22439 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22441 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22443 error (_("Dwarf Error: Problem turning containing type into gdb type "
22444 "[in module %s]"), objfile_name (objfile
));
22446 return lookup_die_type (die
, type_attr
, cu
);
22449 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22451 static struct type
*
22452 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22454 struct dwarf2_per_objfile
*dwarf2_per_objfile
22455 = cu
->per_cu
->dwarf2_per_objfile
;
22456 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22459 std::string message
22460 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22461 objfile_name (objfile
),
22462 sect_offset_str (cu
->header
.sect_off
),
22463 sect_offset_str (die
->sect_off
));
22464 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22466 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22469 /* Look up the type of DIE in CU using its type attribute ATTR.
22470 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22471 DW_AT_containing_type.
22472 If there is no type substitute an error marker. */
22474 static struct type
*
22475 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22476 struct dwarf2_cu
*cu
)
22478 struct dwarf2_per_objfile
*dwarf2_per_objfile
22479 = cu
->per_cu
->dwarf2_per_objfile
;
22480 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22481 struct type
*this_type
;
22483 gdb_assert (attr
->name
== DW_AT_type
22484 || attr
->name
== DW_AT_GNAT_descriptive_type
22485 || attr
->name
== DW_AT_containing_type
);
22487 /* First see if we have it cached. */
22489 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22491 struct dwarf2_per_cu_data
*per_cu
;
22492 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22494 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22495 dwarf2_per_objfile
);
22496 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22498 else if (attr_form_is_ref (attr
))
22500 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22502 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22504 else if (attr
->form
== DW_FORM_ref_sig8
)
22506 ULONGEST signature
= DW_SIGNATURE (attr
);
22508 return get_signatured_type (die
, signature
, cu
);
22512 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22513 " at %s [in module %s]"),
22514 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22515 objfile_name (objfile
));
22516 return build_error_marker_type (cu
, die
);
22519 /* If not cached we need to read it in. */
22521 if (this_type
== NULL
)
22523 struct die_info
*type_die
= NULL
;
22524 struct dwarf2_cu
*type_cu
= cu
;
22526 if (attr_form_is_ref (attr
))
22527 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22528 if (type_die
== NULL
)
22529 return build_error_marker_type (cu
, die
);
22530 /* If we find the type now, it's probably because the type came
22531 from an inter-CU reference and the type's CU got expanded before
22533 this_type
= read_type_die (type_die
, type_cu
);
22536 /* If we still don't have a type use an error marker. */
22538 if (this_type
== NULL
)
22539 return build_error_marker_type (cu
, die
);
22544 /* Return the type in DIE, CU.
22545 Returns NULL for invalid types.
22547 This first does a lookup in die_type_hash,
22548 and only reads the die in if necessary.
22550 NOTE: This can be called when reading in partial or full symbols. */
22552 static struct type
*
22553 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22555 struct type
*this_type
;
22557 this_type
= get_die_type (die
, cu
);
22561 return read_type_die_1 (die
, cu
);
22564 /* Read the type in DIE, CU.
22565 Returns NULL for invalid types. */
22567 static struct type
*
22568 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22570 struct type
*this_type
= NULL
;
22574 case DW_TAG_class_type
:
22575 case DW_TAG_interface_type
:
22576 case DW_TAG_structure_type
:
22577 case DW_TAG_union_type
:
22578 this_type
= read_structure_type (die
, cu
);
22580 case DW_TAG_enumeration_type
:
22581 this_type
= read_enumeration_type (die
, cu
);
22583 case DW_TAG_subprogram
:
22584 case DW_TAG_subroutine_type
:
22585 case DW_TAG_inlined_subroutine
:
22586 this_type
= read_subroutine_type (die
, cu
);
22588 case DW_TAG_array_type
:
22589 this_type
= read_array_type (die
, cu
);
22591 case DW_TAG_set_type
:
22592 this_type
= read_set_type (die
, cu
);
22594 case DW_TAG_pointer_type
:
22595 this_type
= read_tag_pointer_type (die
, cu
);
22597 case DW_TAG_ptr_to_member_type
:
22598 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22600 case DW_TAG_reference_type
:
22601 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22603 case DW_TAG_rvalue_reference_type
:
22604 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22606 case DW_TAG_const_type
:
22607 this_type
= read_tag_const_type (die
, cu
);
22609 case DW_TAG_volatile_type
:
22610 this_type
= read_tag_volatile_type (die
, cu
);
22612 case DW_TAG_restrict_type
:
22613 this_type
= read_tag_restrict_type (die
, cu
);
22615 case DW_TAG_string_type
:
22616 this_type
= read_tag_string_type (die
, cu
);
22618 case DW_TAG_typedef
:
22619 this_type
= read_typedef (die
, cu
);
22621 case DW_TAG_subrange_type
:
22622 this_type
= read_subrange_type (die
, cu
);
22624 case DW_TAG_base_type
:
22625 this_type
= read_base_type (die
, cu
);
22627 case DW_TAG_unspecified_type
:
22628 this_type
= read_unspecified_type (die
, cu
);
22630 case DW_TAG_namespace
:
22631 this_type
= read_namespace_type (die
, cu
);
22633 case DW_TAG_module
:
22634 this_type
= read_module_type (die
, cu
);
22636 case DW_TAG_atomic_type
:
22637 this_type
= read_tag_atomic_type (die
, cu
);
22640 complaint (_("unexpected tag in read_type_die: '%s'"),
22641 dwarf_tag_name (die
->tag
));
22648 /* See if we can figure out if the class lives in a namespace. We do
22649 this by looking for a member function; its demangled name will
22650 contain namespace info, if there is any.
22651 Return the computed name or NULL.
22652 Space for the result is allocated on the objfile's obstack.
22653 This is the full-die version of guess_partial_die_structure_name.
22654 In this case we know DIE has no useful parent. */
22656 static const char *
22657 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22659 struct die_info
*spec_die
;
22660 struct dwarf2_cu
*spec_cu
;
22661 struct die_info
*child
;
22662 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22665 spec_die
= die_specification (die
, &spec_cu
);
22666 if (spec_die
!= NULL
)
22672 for (child
= die
->child
;
22674 child
= child
->sibling
)
22676 if (child
->tag
== DW_TAG_subprogram
)
22678 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22680 if (linkage_name
!= NULL
)
22682 gdb::unique_xmalloc_ptr
<char> actual_name
22683 (language_class_name_from_physname (cu
->language_defn
,
22685 const char *name
= NULL
;
22687 if (actual_name
!= NULL
)
22689 const char *die_name
= dwarf2_name (die
, cu
);
22691 if (die_name
!= NULL
22692 && strcmp (die_name
, actual_name
.get ()) != 0)
22694 /* Strip off the class name from the full name.
22695 We want the prefix. */
22696 int die_name_len
= strlen (die_name
);
22697 int actual_name_len
= strlen (actual_name
.get ());
22698 const char *ptr
= actual_name
.get ();
22700 /* Test for '::' as a sanity check. */
22701 if (actual_name_len
> die_name_len
+ 2
22702 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22703 name
= obstack_strndup (
22704 &objfile
->per_bfd
->storage_obstack
,
22705 ptr
, actual_name_len
- die_name_len
- 2);
22716 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22717 prefix part in such case. See
22718 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22720 static const char *
22721 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22723 struct attribute
*attr
;
22726 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22727 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22730 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22733 attr
= dw2_linkage_name_attr (die
, cu
);
22734 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22737 /* dwarf2_name had to be already called. */
22738 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22740 /* Strip the base name, keep any leading namespaces/classes. */
22741 base
= strrchr (DW_STRING (attr
), ':');
22742 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22745 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22746 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22748 &base
[-1] - DW_STRING (attr
));
22751 /* Return the name of the namespace/class that DIE is defined within,
22752 or "" if we can't tell. The caller should not xfree the result.
22754 For example, if we're within the method foo() in the following
22764 then determine_prefix on foo's die will return "N::C". */
22766 static const char *
22767 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22769 struct dwarf2_per_objfile
*dwarf2_per_objfile
22770 = cu
->per_cu
->dwarf2_per_objfile
;
22771 struct die_info
*parent
, *spec_die
;
22772 struct dwarf2_cu
*spec_cu
;
22773 struct type
*parent_type
;
22774 const char *retval
;
22776 if (cu
->language
!= language_cplus
22777 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22778 && cu
->language
!= language_rust
)
22781 retval
= anonymous_struct_prefix (die
, cu
);
22785 /* We have to be careful in the presence of DW_AT_specification.
22786 For example, with GCC 3.4, given the code
22790 // Definition of N::foo.
22794 then we'll have a tree of DIEs like this:
22796 1: DW_TAG_compile_unit
22797 2: DW_TAG_namespace // N
22798 3: DW_TAG_subprogram // declaration of N::foo
22799 4: DW_TAG_subprogram // definition of N::foo
22800 DW_AT_specification // refers to die #3
22802 Thus, when processing die #4, we have to pretend that we're in
22803 the context of its DW_AT_specification, namely the contex of die
22806 spec_die
= die_specification (die
, &spec_cu
);
22807 if (spec_die
== NULL
)
22808 parent
= die
->parent
;
22811 parent
= spec_die
->parent
;
22815 if (parent
== NULL
)
22817 else if (parent
->building_fullname
)
22820 const char *parent_name
;
22822 /* It has been seen on RealView 2.2 built binaries,
22823 DW_TAG_template_type_param types actually _defined_ as
22824 children of the parent class:
22827 template class <class Enum> Class{};
22828 Class<enum E> class_e;
22830 1: DW_TAG_class_type (Class)
22831 2: DW_TAG_enumeration_type (E)
22832 3: DW_TAG_enumerator (enum1:0)
22833 3: DW_TAG_enumerator (enum2:1)
22835 2: DW_TAG_template_type_param
22836 DW_AT_type DW_FORM_ref_udata (E)
22838 Besides being broken debug info, it can put GDB into an
22839 infinite loop. Consider:
22841 When we're building the full name for Class<E>, we'll start
22842 at Class, and go look over its template type parameters,
22843 finding E. We'll then try to build the full name of E, and
22844 reach here. We're now trying to build the full name of E,
22845 and look over the parent DIE for containing scope. In the
22846 broken case, if we followed the parent DIE of E, we'd again
22847 find Class, and once again go look at its template type
22848 arguments, etc., etc. Simply don't consider such parent die
22849 as source-level parent of this die (it can't be, the language
22850 doesn't allow it), and break the loop here. */
22851 name
= dwarf2_name (die
, cu
);
22852 parent_name
= dwarf2_name (parent
, cu
);
22853 complaint (_("template param type '%s' defined within parent '%s'"),
22854 name
? name
: "<unknown>",
22855 parent_name
? parent_name
: "<unknown>");
22859 switch (parent
->tag
)
22861 case DW_TAG_namespace
:
22862 parent_type
= read_type_die (parent
, cu
);
22863 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22864 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22865 Work around this problem here. */
22866 if (cu
->language
== language_cplus
22867 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22869 /* We give a name to even anonymous namespaces. */
22870 return TYPE_NAME (parent_type
);
22871 case DW_TAG_class_type
:
22872 case DW_TAG_interface_type
:
22873 case DW_TAG_structure_type
:
22874 case DW_TAG_union_type
:
22875 case DW_TAG_module
:
22876 parent_type
= read_type_die (parent
, cu
);
22877 if (TYPE_NAME (parent_type
) != NULL
)
22878 return TYPE_NAME (parent_type
);
22880 /* An anonymous structure is only allowed non-static data
22881 members; no typedefs, no member functions, et cetera.
22882 So it does not need a prefix. */
22884 case DW_TAG_compile_unit
:
22885 case DW_TAG_partial_unit
:
22886 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22887 if (cu
->language
== language_cplus
22888 && !dwarf2_per_objfile
->types
.empty ()
22889 && die
->child
!= NULL
22890 && (die
->tag
== DW_TAG_class_type
22891 || die
->tag
== DW_TAG_structure_type
22892 || die
->tag
== DW_TAG_union_type
))
22894 const char *name
= guess_full_die_structure_name (die
, cu
);
22899 case DW_TAG_subprogram
:
22900 /* Nested subroutines in Fortran get a prefix with the name
22901 of the parent's subroutine. */
22902 if (cu
->language
== language_fortran
)
22904 if ((die
->tag
== DW_TAG_subprogram
)
22905 && (dwarf2_name (parent
, cu
) != NULL
))
22906 return dwarf2_name (parent
, cu
);
22908 return determine_prefix (parent
, cu
);
22909 case DW_TAG_enumeration_type
:
22910 parent_type
= read_type_die (parent
, cu
);
22911 if (TYPE_DECLARED_CLASS (parent_type
))
22913 if (TYPE_NAME (parent_type
) != NULL
)
22914 return TYPE_NAME (parent_type
);
22917 /* Fall through. */
22919 return determine_prefix (parent
, cu
);
22923 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22924 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22925 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22926 an obconcat, otherwise allocate storage for the result. The CU argument is
22927 used to determine the language and hence, the appropriate separator. */
22929 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22932 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22933 int physname
, struct dwarf2_cu
*cu
)
22935 const char *lead
= "";
22938 if (suffix
== NULL
|| suffix
[0] == '\0'
22939 || prefix
== NULL
|| prefix
[0] == '\0')
22941 else if (cu
->language
== language_d
)
22943 /* For D, the 'main' function could be defined in any module, but it
22944 should never be prefixed. */
22945 if (strcmp (suffix
, "D main") == 0)
22953 else if (cu
->language
== language_fortran
&& physname
)
22955 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22956 DW_AT_MIPS_linkage_name is preferred and used instead. */
22964 if (prefix
== NULL
)
22966 if (suffix
== NULL
)
22973 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22975 strcpy (retval
, lead
);
22976 strcat (retval
, prefix
);
22977 strcat (retval
, sep
);
22978 strcat (retval
, suffix
);
22983 /* We have an obstack. */
22984 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22988 /* Return sibling of die, NULL if no sibling. */
22990 static struct die_info
*
22991 sibling_die (struct die_info
*die
)
22993 return die
->sibling
;
22996 /* Get name of a die, return NULL if not found. */
22998 static const char *
22999 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23000 struct obstack
*obstack
)
23002 if (name
&& cu
->language
== language_cplus
)
23004 std::string canon_name
= cp_canonicalize_string (name
);
23006 if (!canon_name
.empty ())
23008 if (canon_name
!= name
)
23009 name
= obstack_strdup (obstack
, canon_name
);
23016 /* Get name of a die, return NULL if not found.
23017 Anonymous namespaces are converted to their magic string. */
23019 static const char *
23020 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23022 struct attribute
*attr
;
23023 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23025 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23026 if ((!attr
|| !DW_STRING (attr
))
23027 && die
->tag
!= DW_TAG_namespace
23028 && die
->tag
!= DW_TAG_class_type
23029 && die
->tag
!= DW_TAG_interface_type
23030 && die
->tag
!= DW_TAG_structure_type
23031 && die
->tag
!= DW_TAG_union_type
)
23036 case DW_TAG_compile_unit
:
23037 case DW_TAG_partial_unit
:
23038 /* Compilation units have a DW_AT_name that is a filename, not
23039 a source language identifier. */
23040 case DW_TAG_enumeration_type
:
23041 case DW_TAG_enumerator
:
23042 /* These tags always have simple identifiers already; no need
23043 to canonicalize them. */
23044 return DW_STRING (attr
);
23046 case DW_TAG_namespace
:
23047 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
23048 return DW_STRING (attr
);
23049 return CP_ANONYMOUS_NAMESPACE_STR
;
23051 case DW_TAG_class_type
:
23052 case DW_TAG_interface_type
:
23053 case DW_TAG_structure_type
:
23054 case DW_TAG_union_type
:
23055 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23056 structures or unions. These were of the form "._%d" in GCC 4.1,
23057 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23058 and GCC 4.4. We work around this problem by ignoring these. */
23059 if (attr
&& DW_STRING (attr
)
23060 && (startswith (DW_STRING (attr
), "._")
23061 || startswith (DW_STRING (attr
), "<anonymous")))
23064 /* GCC might emit a nameless typedef that has a linkage name. See
23065 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23066 if (!attr
|| DW_STRING (attr
) == NULL
)
23068 attr
= dw2_linkage_name_attr (die
, cu
);
23069 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
23072 /* Avoid demangling DW_STRING (attr) the second time on a second
23073 call for the same DIE. */
23074 if (!DW_STRING_IS_CANONICAL (attr
))
23076 gdb::unique_xmalloc_ptr
<char> demangled
23077 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
23081 /* FIXME: we already did this for the partial symbol... */
23083 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
23085 DW_STRING_IS_CANONICAL (attr
) = 1;
23087 /* Strip any leading namespaces/classes, keep only the base name.
23088 DW_AT_name for named DIEs does not contain the prefixes. */
23089 base
= strrchr (DW_STRING (attr
), ':');
23090 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
23093 return DW_STRING (attr
);
23102 if (!DW_STRING_IS_CANONICAL (attr
))
23105 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
23106 &objfile
->per_bfd
->storage_obstack
);
23107 DW_STRING_IS_CANONICAL (attr
) = 1;
23109 return DW_STRING (attr
);
23112 /* Return the die that this die in an extension of, or NULL if there
23113 is none. *EXT_CU is the CU containing DIE on input, and the CU
23114 containing the return value on output. */
23116 static struct die_info
*
23117 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23119 struct attribute
*attr
;
23121 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23125 return follow_die_ref (die
, attr
, ext_cu
);
23128 /* A convenience function that returns an "unknown" DWARF name,
23129 including the value of V. STR is the name of the entity being
23130 printed, e.g., "TAG". */
23132 static const char *
23133 dwarf_unknown (const char *str
, unsigned v
)
23135 char *cell
= get_print_cell ();
23136 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
23140 /* Convert a DIE tag into its string name. */
23142 static const char *
23143 dwarf_tag_name (unsigned tag
)
23145 const char *name
= get_DW_TAG_name (tag
);
23148 return dwarf_unknown ("TAG", tag
);
23153 /* Convert a DWARF attribute code into its string name. */
23155 static const char *
23156 dwarf_attr_name (unsigned attr
)
23160 #ifdef MIPS /* collides with DW_AT_HP_block_index */
23161 if (attr
== DW_AT_MIPS_fde
)
23162 return "DW_AT_MIPS_fde";
23164 if (attr
== DW_AT_HP_block_index
)
23165 return "DW_AT_HP_block_index";
23168 name
= get_DW_AT_name (attr
);
23171 return dwarf_unknown ("AT", attr
);
23176 /* Convert a unit type to corresponding DW_UT name. */
23178 static const char *
23179 dwarf_unit_type_name (int unit_type
) {
23183 return "DW_UT_compile (0x01)";
23185 return "DW_UT_type (0x02)";
23187 return "DW_UT_partial (0x03)";
23189 return "DW_UT_skeleton (0x04)";
23191 return "DW_UT_split_compile (0x05)";
23193 return "DW_UT_split_type (0x06)";
23195 return "DW_UT_lo_user (0x80)";
23197 return "DW_UT_hi_user (0xff)";
23203 /* Convert a DWARF value form code into its string name. */
23205 static const char *
23206 dwarf_form_name (unsigned form
)
23208 const char *name
= get_DW_FORM_name (form
);
23211 return dwarf_unknown ("FORM", form
);
23216 static const char *
23217 dwarf_bool_name (unsigned mybool
)
23225 /* Convert a DWARF type code into its string name. */
23227 static const char *
23228 dwarf_type_encoding_name (unsigned enc
)
23230 const char *name
= get_DW_ATE_name (enc
);
23233 return dwarf_unknown ("ATE", enc
);
23239 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23243 print_spaces (indent
, f
);
23244 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23245 dwarf_tag_name (die
->tag
), die
->abbrev
,
23246 sect_offset_str (die
->sect_off
));
23248 if (die
->parent
!= NULL
)
23250 print_spaces (indent
, f
);
23251 fprintf_unfiltered (f
, " parent at offset: %s\n",
23252 sect_offset_str (die
->parent
->sect_off
));
23255 print_spaces (indent
, f
);
23256 fprintf_unfiltered (f
, " has children: %s\n",
23257 dwarf_bool_name (die
->child
!= NULL
));
23259 print_spaces (indent
, f
);
23260 fprintf_unfiltered (f
, " attributes:\n");
23262 for (i
= 0; i
< die
->num_attrs
; ++i
)
23264 print_spaces (indent
, f
);
23265 fprintf_unfiltered (f
, " %s (%s) ",
23266 dwarf_attr_name (die
->attrs
[i
].name
),
23267 dwarf_form_name (die
->attrs
[i
].form
));
23269 switch (die
->attrs
[i
].form
)
23272 case DW_FORM_addrx
:
23273 case DW_FORM_GNU_addr_index
:
23274 fprintf_unfiltered (f
, "address: ");
23275 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23277 case DW_FORM_block2
:
23278 case DW_FORM_block4
:
23279 case DW_FORM_block
:
23280 case DW_FORM_block1
:
23281 fprintf_unfiltered (f
, "block: size %s",
23282 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23284 case DW_FORM_exprloc
:
23285 fprintf_unfiltered (f
, "expression: size %s",
23286 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23288 case DW_FORM_data16
:
23289 fprintf_unfiltered (f
, "constant of 16 bytes");
23291 case DW_FORM_ref_addr
:
23292 fprintf_unfiltered (f
, "ref address: ");
23293 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23295 case DW_FORM_GNU_ref_alt
:
23296 fprintf_unfiltered (f
, "alt ref address: ");
23297 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23303 case DW_FORM_ref_udata
:
23304 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23305 (long) (DW_UNSND (&die
->attrs
[i
])));
23307 case DW_FORM_data1
:
23308 case DW_FORM_data2
:
23309 case DW_FORM_data4
:
23310 case DW_FORM_data8
:
23311 case DW_FORM_udata
:
23312 case DW_FORM_sdata
:
23313 fprintf_unfiltered (f
, "constant: %s",
23314 pulongest (DW_UNSND (&die
->attrs
[i
])));
23316 case DW_FORM_sec_offset
:
23317 fprintf_unfiltered (f
, "section offset: %s",
23318 pulongest (DW_UNSND (&die
->attrs
[i
])));
23320 case DW_FORM_ref_sig8
:
23321 fprintf_unfiltered (f
, "signature: %s",
23322 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23324 case DW_FORM_string
:
23326 case DW_FORM_line_strp
:
23328 case DW_FORM_GNU_str_index
:
23329 case DW_FORM_GNU_strp_alt
:
23330 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23331 DW_STRING (&die
->attrs
[i
])
23332 ? DW_STRING (&die
->attrs
[i
]) : "",
23333 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23336 if (DW_UNSND (&die
->attrs
[i
]))
23337 fprintf_unfiltered (f
, "flag: TRUE");
23339 fprintf_unfiltered (f
, "flag: FALSE");
23341 case DW_FORM_flag_present
:
23342 fprintf_unfiltered (f
, "flag: TRUE");
23344 case DW_FORM_indirect
:
23345 /* The reader will have reduced the indirect form to
23346 the "base form" so this form should not occur. */
23347 fprintf_unfiltered (f
,
23348 "unexpected attribute form: DW_FORM_indirect");
23350 case DW_FORM_implicit_const
:
23351 fprintf_unfiltered (f
, "constant: %s",
23352 plongest (DW_SND (&die
->attrs
[i
])));
23355 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23356 die
->attrs
[i
].form
);
23359 fprintf_unfiltered (f
, "\n");
23364 dump_die_for_error (struct die_info
*die
)
23366 dump_die_shallow (gdb_stderr
, 0, die
);
23370 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23372 int indent
= level
* 4;
23374 gdb_assert (die
!= NULL
);
23376 if (level
>= max_level
)
23379 dump_die_shallow (f
, indent
, die
);
23381 if (die
->child
!= NULL
)
23383 print_spaces (indent
, f
);
23384 fprintf_unfiltered (f
, " Children:");
23385 if (level
+ 1 < max_level
)
23387 fprintf_unfiltered (f
, "\n");
23388 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23392 fprintf_unfiltered (f
,
23393 " [not printed, max nesting level reached]\n");
23397 if (die
->sibling
!= NULL
&& level
> 0)
23399 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23403 /* This is called from the pdie macro in gdbinit.in.
23404 It's not static so gcc will keep a copy callable from gdb. */
23407 dump_die (struct die_info
*die
, int max_level
)
23409 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23413 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23417 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23418 to_underlying (die
->sect_off
),
23424 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23428 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23430 if (attr_form_is_ref (attr
))
23431 return (sect_offset
) DW_UNSND (attr
);
23433 complaint (_("unsupported die ref attribute form: '%s'"),
23434 dwarf_form_name (attr
->form
));
23438 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23439 * the value held by the attribute is not constant. */
23442 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23444 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23445 return DW_SND (attr
);
23446 else if (attr
->form
== DW_FORM_udata
23447 || attr
->form
== DW_FORM_data1
23448 || attr
->form
== DW_FORM_data2
23449 || attr
->form
== DW_FORM_data4
23450 || attr
->form
== DW_FORM_data8
)
23451 return DW_UNSND (attr
);
23454 /* For DW_FORM_data16 see attr_form_is_constant. */
23455 complaint (_("Attribute value is not a constant (%s)"),
23456 dwarf_form_name (attr
->form
));
23457 return default_value
;
23461 /* Follow reference or signature attribute ATTR of SRC_DIE.
23462 On entry *REF_CU is the CU of SRC_DIE.
23463 On exit *REF_CU is the CU of the result. */
23465 static struct die_info
*
23466 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23467 struct dwarf2_cu
**ref_cu
)
23469 struct die_info
*die
;
23471 if (attr_form_is_ref (attr
))
23472 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23473 else if (attr
->form
== DW_FORM_ref_sig8
)
23474 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23477 dump_die_for_error (src_die
);
23478 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23479 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23485 /* Follow reference OFFSET.
23486 On entry *REF_CU is the CU of the source die referencing OFFSET.
23487 On exit *REF_CU is the CU of the result.
23488 Returns NULL if OFFSET is invalid. */
23490 static struct die_info
*
23491 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23492 struct dwarf2_cu
**ref_cu
)
23494 struct die_info temp_die
;
23495 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23496 struct dwarf2_per_objfile
*dwarf2_per_objfile
23497 = cu
->per_cu
->dwarf2_per_objfile
;
23499 gdb_assert (cu
->per_cu
!= NULL
);
23503 if (cu
->per_cu
->is_debug_types
)
23505 /* .debug_types CUs cannot reference anything outside their CU.
23506 If they need to, they have to reference a signatured type via
23507 DW_FORM_ref_sig8. */
23508 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23511 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23512 || !offset_in_cu_p (&cu
->header
, sect_off
))
23514 struct dwarf2_per_cu_data
*per_cu
;
23516 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23517 dwarf2_per_objfile
);
23519 /* If necessary, add it to the queue and load its DIEs. */
23520 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23521 load_full_comp_unit (per_cu
, false, cu
->language
);
23523 target_cu
= per_cu
->cu
;
23525 else if (cu
->dies
== NULL
)
23527 /* We're loading full DIEs during partial symbol reading. */
23528 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23529 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23532 *ref_cu
= target_cu
;
23533 temp_die
.sect_off
= sect_off
;
23535 if (target_cu
!= cu
)
23536 target_cu
->ancestor
= cu
;
23538 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23540 to_underlying (sect_off
));
23543 /* Follow reference attribute ATTR of SRC_DIE.
23544 On entry *REF_CU is the CU of SRC_DIE.
23545 On exit *REF_CU is the CU of the result. */
23547 static struct die_info
*
23548 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23549 struct dwarf2_cu
**ref_cu
)
23551 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23552 struct dwarf2_cu
*cu
= *ref_cu
;
23553 struct die_info
*die
;
23555 die
= follow_die_offset (sect_off
,
23556 (attr
->form
== DW_FORM_GNU_ref_alt
23557 || cu
->per_cu
->is_dwz
),
23560 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23561 "at %s [in module %s]"),
23562 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23563 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23568 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23569 Returned value is intended for DW_OP_call*. Returned
23570 dwarf2_locexpr_baton->data has lifetime of
23571 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23573 struct dwarf2_locexpr_baton
23574 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23575 struct dwarf2_per_cu_data
*per_cu
,
23576 CORE_ADDR (*get_frame_pc
) (void *baton
),
23577 void *baton
, bool resolve_abstract_p
)
23579 struct dwarf2_cu
*cu
;
23580 struct die_info
*die
;
23581 struct attribute
*attr
;
23582 struct dwarf2_locexpr_baton retval
;
23583 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23584 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23586 if (per_cu
->cu
== NULL
)
23587 load_cu (per_cu
, false);
23591 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23592 Instead just throw an error, not much else we can do. */
23593 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23594 sect_offset_str (sect_off
), objfile_name (objfile
));
23597 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23599 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23600 sect_offset_str (sect_off
), objfile_name (objfile
));
23602 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23603 if (!attr
&& resolve_abstract_p
23604 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23605 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23607 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23608 CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
23609 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23611 for (const auto &cand_off
23612 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23614 struct dwarf2_cu
*cand_cu
= cu
;
23615 struct die_info
*cand
23616 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23619 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23622 CORE_ADDR pc_low
, pc_high
;
23623 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23624 if (pc_low
== ((CORE_ADDR
) -1))
23626 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23627 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23628 if (!(pc_low
<= pc
&& pc
< pc_high
))
23632 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23639 /* DWARF: "If there is no such attribute, then there is no effect.".
23640 DATA is ignored if SIZE is 0. */
23642 retval
.data
= NULL
;
23645 else if (attr_form_is_section_offset (attr
))
23647 struct dwarf2_loclist_baton loclist_baton
;
23648 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23651 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23653 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23655 retval
.size
= size
;
23659 if (!attr_form_is_block (attr
))
23660 error (_("Dwarf Error: DIE at %s referenced in module %s "
23661 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23662 sect_offset_str (sect_off
), objfile_name (objfile
));
23664 retval
.data
= DW_BLOCK (attr
)->data
;
23665 retval
.size
= DW_BLOCK (attr
)->size
;
23667 retval
.per_cu
= cu
->per_cu
;
23669 age_cached_comp_units (dwarf2_per_objfile
);
23674 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23677 struct dwarf2_locexpr_baton
23678 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23679 struct dwarf2_per_cu_data
*per_cu
,
23680 CORE_ADDR (*get_frame_pc
) (void *baton
),
23683 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23685 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23688 /* Write a constant of a given type as target-ordered bytes into
23691 static const gdb_byte
*
23692 write_constant_as_bytes (struct obstack
*obstack
,
23693 enum bfd_endian byte_order
,
23700 *len
= TYPE_LENGTH (type
);
23701 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23702 store_unsigned_integer (result
, *len
, byte_order
, value
);
23707 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23708 pointer to the constant bytes and set LEN to the length of the
23709 data. If memory is needed, allocate it on OBSTACK. If the DIE
23710 does not have a DW_AT_const_value, return NULL. */
23713 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23714 struct dwarf2_per_cu_data
*per_cu
,
23715 struct obstack
*obstack
,
23718 struct dwarf2_cu
*cu
;
23719 struct die_info
*die
;
23720 struct attribute
*attr
;
23721 const gdb_byte
*result
= NULL
;
23724 enum bfd_endian byte_order
;
23725 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23727 if (per_cu
->cu
== NULL
)
23728 load_cu (per_cu
, false);
23732 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23733 Instead just throw an error, not much else we can do. */
23734 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23735 sect_offset_str (sect_off
), objfile_name (objfile
));
23738 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23740 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23741 sect_offset_str (sect_off
), objfile_name (objfile
));
23743 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23747 byte_order
= (bfd_big_endian (objfile
->obfd
)
23748 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23750 switch (attr
->form
)
23753 case DW_FORM_addrx
:
23754 case DW_FORM_GNU_addr_index
:
23758 *len
= cu
->header
.addr_size
;
23759 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23760 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23764 case DW_FORM_string
:
23767 case DW_FORM_GNU_str_index
:
23768 case DW_FORM_GNU_strp_alt
:
23769 /* DW_STRING is already allocated on the objfile obstack, point
23771 result
= (const gdb_byte
*) DW_STRING (attr
);
23772 *len
= strlen (DW_STRING (attr
));
23774 case DW_FORM_block1
:
23775 case DW_FORM_block2
:
23776 case DW_FORM_block4
:
23777 case DW_FORM_block
:
23778 case DW_FORM_exprloc
:
23779 case DW_FORM_data16
:
23780 result
= DW_BLOCK (attr
)->data
;
23781 *len
= DW_BLOCK (attr
)->size
;
23784 /* The DW_AT_const_value attributes are supposed to carry the
23785 symbol's value "represented as it would be on the target
23786 architecture." By the time we get here, it's already been
23787 converted to host endianness, so we just need to sign- or
23788 zero-extend it as appropriate. */
23789 case DW_FORM_data1
:
23790 type
= die_type (die
, cu
);
23791 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23792 if (result
== NULL
)
23793 result
= write_constant_as_bytes (obstack
, byte_order
,
23796 case DW_FORM_data2
:
23797 type
= die_type (die
, cu
);
23798 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23799 if (result
== NULL
)
23800 result
= write_constant_as_bytes (obstack
, byte_order
,
23803 case DW_FORM_data4
:
23804 type
= die_type (die
, cu
);
23805 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23806 if (result
== NULL
)
23807 result
= write_constant_as_bytes (obstack
, byte_order
,
23810 case DW_FORM_data8
:
23811 type
= die_type (die
, cu
);
23812 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23813 if (result
== NULL
)
23814 result
= write_constant_as_bytes (obstack
, byte_order
,
23818 case DW_FORM_sdata
:
23819 case DW_FORM_implicit_const
:
23820 type
= die_type (die
, cu
);
23821 result
= write_constant_as_bytes (obstack
, byte_order
,
23822 type
, DW_SND (attr
), len
);
23825 case DW_FORM_udata
:
23826 type
= die_type (die
, cu
);
23827 result
= write_constant_as_bytes (obstack
, byte_order
,
23828 type
, DW_UNSND (attr
), len
);
23832 complaint (_("unsupported const value attribute form: '%s'"),
23833 dwarf_form_name (attr
->form
));
23840 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23841 valid type for this die is found. */
23844 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23845 struct dwarf2_per_cu_data
*per_cu
)
23847 struct dwarf2_cu
*cu
;
23848 struct die_info
*die
;
23850 if (per_cu
->cu
== NULL
)
23851 load_cu (per_cu
, false);
23856 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23860 return die_type (die
, cu
);
23863 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23867 dwarf2_get_die_type (cu_offset die_offset
,
23868 struct dwarf2_per_cu_data
*per_cu
)
23870 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23871 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23874 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23875 On entry *REF_CU is the CU of SRC_DIE.
23876 On exit *REF_CU is the CU of the result.
23877 Returns NULL if the referenced DIE isn't found. */
23879 static struct die_info
*
23880 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23881 struct dwarf2_cu
**ref_cu
)
23883 struct die_info temp_die
;
23884 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23885 struct die_info
*die
;
23887 /* While it might be nice to assert sig_type->type == NULL here,
23888 we can get here for DW_AT_imported_declaration where we need
23889 the DIE not the type. */
23891 /* If necessary, add it to the queue and load its DIEs. */
23893 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23894 read_signatured_type (sig_type
);
23896 sig_cu
= sig_type
->per_cu
.cu
;
23897 gdb_assert (sig_cu
!= NULL
);
23898 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23899 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23900 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23901 to_underlying (temp_die
.sect_off
));
23904 struct dwarf2_per_objfile
*dwarf2_per_objfile
23905 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23907 /* For .gdb_index version 7 keep track of included TUs.
23908 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23909 if (dwarf2_per_objfile
->index_table
!= NULL
23910 && dwarf2_per_objfile
->index_table
->version
<= 7)
23912 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23917 sig_cu
->ancestor
= cu
;
23925 /* Follow signatured type referenced by ATTR in SRC_DIE.
23926 On entry *REF_CU is the CU of SRC_DIE.
23927 On exit *REF_CU is the CU of the result.
23928 The result is the DIE of the type.
23929 If the referenced type cannot be found an error is thrown. */
23931 static struct die_info
*
23932 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23933 struct dwarf2_cu
**ref_cu
)
23935 ULONGEST signature
= DW_SIGNATURE (attr
);
23936 struct signatured_type
*sig_type
;
23937 struct die_info
*die
;
23939 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23941 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23942 /* sig_type will be NULL if the signatured type is missing from
23944 if (sig_type
== NULL
)
23946 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23947 " from DIE at %s [in module %s]"),
23948 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23949 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23952 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23955 dump_die_for_error (src_die
);
23956 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23957 " from DIE at %s [in module %s]"),
23958 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23959 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23965 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23966 reading in and processing the type unit if necessary. */
23968 static struct type
*
23969 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23970 struct dwarf2_cu
*cu
)
23972 struct dwarf2_per_objfile
*dwarf2_per_objfile
23973 = cu
->per_cu
->dwarf2_per_objfile
;
23974 struct signatured_type
*sig_type
;
23975 struct dwarf2_cu
*type_cu
;
23976 struct die_info
*type_die
;
23979 sig_type
= lookup_signatured_type (cu
, signature
);
23980 /* sig_type will be NULL if the signatured type is missing from
23982 if (sig_type
== NULL
)
23984 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23985 " from DIE at %s [in module %s]"),
23986 hex_string (signature
), sect_offset_str (die
->sect_off
),
23987 objfile_name (dwarf2_per_objfile
->objfile
));
23988 return build_error_marker_type (cu
, die
);
23991 /* If we already know the type we're done. */
23992 if (sig_type
->type
!= NULL
)
23993 return sig_type
->type
;
23996 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23997 if (type_die
!= NULL
)
23999 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24000 is created. This is important, for example, because for c++ classes
24001 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24002 type
= read_type_die (type_die
, type_cu
);
24005 complaint (_("Dwarf Error: Cannot build signatured type %s"
24006 " referenced from DIE at %s [in module %s]"),
24007 hex_string (signature
), sect_offset_str (die
->sect_off
),
24008 objfile_name (dwarf2_per_objfile
->objfile
));
24009 type
= build_error_marker_type (cu
, die
);
24014 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24015 " from DIE at %s [in module %s]"),
24016 hex_string (signature
), sect_offset_str (die
->sect_off
),
24017 objfile_name (dwarf2_per_objfile
->objfile
));
24018 type
= build_error_marker_type (cu
, die
);
24020 sig_type
->type
= type
;
24025 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24026 reading in and processing the type unit if necessary. */
24028 static struct type
*
24029 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24030 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24032 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24033 if (attr_form_is_ref (attr
))
24035 struct dwarf2_cu
*type_cu
= cu
;
24036 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24038 return read_type_die (type_die
, type_cu
);
24040 else if (attr
->form
== DW_FORM_ref_sig8
)
24042 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
24046 struct dwarf2_per_objfile
*dwarf2_per_objfile
24047 = cu
->per_cu
->dwarf2_per_objfile
;
24049 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24050 " at %s [in module %s]"),
24051 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24052 objfile_name (dwarf2_per_objfile
->objfile
));
24053 return build_error_marker_type (cu
, die
);
24057 /* Load the DIEs associated with type unit PER_CU into memory. */
24060 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
24062 struct signatured_type
*sig_type
;
24064 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24065 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
24067 /* We have the per_cu, but we need the signatured_type.
24068 Fortunately this is an easy translation. */
24069 gdb_assert (per_cu
->is_debug_types
);
24070 sig_type
= (struct signatured_type
*) per_cu
;
24072 gdb_assert (per_cu
->cu
== NULL
);
24074 read_signatured_type (sig_type
);
24076 gdb_assert (per_cu
->cu
!= NULL
);
24079 /* die_reader_func for read_signatured_type.
24080 This is identical to load_full_comp_unit_reader,
24081 but is kept separate for now. */
24084 read_signatured_type_reader (const struct die_reader_specs
*reader
,
24085 const gdb_byte
*info_ptr
,
24086 struct die_info
*comp_unit_die
,
24090 struct dwarf2_cu
*cu
= reader
->cu
;
24092 gdb_assert (cu
->die_hash
== NULL
);
24094 htab_create_alloc_ex (cu
->header
.length
/ 12,
24098 &cu
->comp_unit_obstack
,
24099 hashtab_obstack_allocate
,
24100 dummy_obstack_deallocate
);
24103 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
24104 &info_ptr
, comp_unit_die
);
24105 cu
->dies
= comp_unit_die
;
24106 /* comp_unit_die is not stored in die_hash, no need. */
24108 /* We try not to read any attributes in this function, because not
24109 all CUs needed for references have been loaded yet, and symbol
24110 table processing isn't initialized. But we have to set the CU language,
24111 or we won't be able to build types correctly.
24112 Similarly, if we do not read the producer, we can not apply
24113 producer-specific interpretation. */
24114 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24117 /* Read in a signatured type and build its CU and DIEs.
24118 If the type is a stub for the real type in a DWO file,
24119 read in the real type from the DWO file as well. */
24122 read_signatured_type (struct signatured_type
*sig_type
)
24124 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24126 gdb_assert (per_cu
->is_debug_types
);
24127 gdb_assert (per_cu
->cu
== NULL
);
24129 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
24130 read_signatured_type_reader
, NULL
);
24131 sig_type
->per_cu
.tu_read
= 1;
24134 /* Decode simple location descriptions.
24135 Given a pointer to a dwarf block that defines a location, compute
24136 the location and return the value.
24138 NOTE drow/2003-11-18: This function is called in two situations
24139 now: for the address of static or global variables (partial symbols
24140 only) and for offsets into structures which are expected to be
24141 (more or less) constant. The partial symbol case should go away,
24142 and only the constant case should remain. That will let this
24143 function complain more accurately. A few special modes are allowed
24144 without complaint for global variables (for instance, global
24145 register values and thread-local values).
24147 A location description containing no operations indicates that the
24148 object is optimized out. The return value is 0 for that case.
24149 FIXME drow/2003-11-16: No callers check for this case any more; soon all
24150 callers will only want a very basic result and this can become a
24153 Note that stack[0] is unused except as a default error return. */
24156 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
24158 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
24160 size_t size
= blk
->size
;
24161 const gdb_byte
*data
= blk
->data
;
24162 CORE_ADDR stack
[64];
24164 unsigned int bytes_read
, unsnd
;
24170 stack
[++stacki
] = 0;
24209 stack
[++stacki
] = op
- DW_OP_lit0
;
24244 stack
[++stacki
] = op
- DW_OP_reg0
;
24246 dwarf2_complex_location_expr_complaint ();
24250 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24252 stack
[++stacki
] = unsnd
;
24254 dwarf2_complex_location_expr_complaint ();
24258 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24263 case DW_OP_const1u
:
24264 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24268 case DW_OP_const1s
:
24269 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24273 case DW_OP_const2u
:
24274 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24278 case DW_OP_const2s
:
24279 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24283 case DW_OP_const4u
:
24284 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24288 case DW_OP_const4s
:
24289 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24293 case DW_OP_const8u
:
24294 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24299 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24305 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24310 stack
[stacki
+ 1] = stack
[stacki
];
24315 stack
[stacki
- 1] += stack
[stacki
];
24319 case DW_OP_plus_uconst
:
24320 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24326 stack
[stacki
- 1] -= stack
[stacki
];
24331 /* If we're not the last op, then we definitely can't encode
24332 this using GDB's address_class enum. This is valid for partial
24333 global symbols, although the variable's address will be bogus
24336 dwarf2_complex_location_expr_complaint ();
24339 case DW_OP_GNU_push_tls_address
:
24340 case DW_OP_form_tls_address
:
24341 /* The top of the stack has the offset from the beginning
24342 of the thread control block at which the variable is located. */
24343 /* Nothing should follow this operator, so the top of stack would
24345 /* This is valid for partial global symbols, but the variable's
24346 address will be bogus in the psymtab. Make it always at least
24347 non-zero to not look as a variable garbage collected by linker
24348 which have DW_OP_addr 0. */
24350 dwarf2_complex_location_expr_complaint ();
24354 case DW_OP_GNU_uninit
:
24358 case DW_OP_GNU_addr_index
:
24359 case DW_OP_GNU_const_index
:
24360 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24367 const char *name
= get_DW_OP_name (op
);
24370 complaint (_("unsupported stack op: '%s'"),
24373 complaint (_("unsupported stack op: '%02x'"),
24377 return (stack
[stacki
]);
24380 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24381 outside of the allocated space. Also enforce minimum>0. */
24382 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24384 complaint (_("location description stack overflow"));
24390 complaint (_("location description stack underflow"));
24394 return (stack
[stacki
]);
24397 /* memory allocation interface */
24399 static struct dwarf_block
*
24400 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24402 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24405 static struct die_info
*
24406 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24408 struct die_info
*die
;
24409 size_t size
= sizeof (struct die_info
);
24412 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24414 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24415 memset (die
, 0, sizeof (struct die_info
));
24420 /* Macro support. */
24422 /* Return file name relative to the compilation directory of file number I in
24423 *LH's file name table. The result is allocated using xmalloc; the caller is
24424 responsible for freeing it. */
24427 file_file_name (int file
, struct line_header
*lh
)
24429 /* Is the file number a valid index into the line header's file name
24430 table? Remember that file numbers start with one, not zero. */
24431 if (lh
->is_valid_file_index (file
))
24433 const file_entry
*fe
= lh
->file_name_at (file
);
24435 if (!IS_ABSOLUTE_PATH (fe
->name
))
24437 const char *dir
= fe
->include_dir (lh
);
24439 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24441 return xstrdup (fe
->name
);
24445 /* The compiler produced a bogus file number. We can at least
24446 record the macro definitions made in the file, even if we
24447 won't be able to find the file by name. */
24448 char fake_name
[80];
24450 xsnprintf (fake_name
, sizeof (fake_name
),
24451 "<bad macro file number %d>", file
);
24453 complaint (_("bad file number in macro information (%d)"),
24456 return xstrdup (fake_name
);
24460 /* Return the full name of file number I in *LH's file name table.
24461 Use COMP_DIR as the name of the current directory of the
24462 compilation. The result is allocated using xmalloc; the caller is
24463 responsible for freeing it. */
24465 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24467 /* Is the file number a valid index into the line header's file name
24468 table? Remember that file numbers start with one, not zero. */
24469 if (lh
->is_valid_file_index (file
))
24471 char *relative
= file_file_name (file
, lh
);
24473 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24475 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24476 relative
, (char *) NULL
);
24479 return file_file_name (file
, lh
);
24483 static struct macro_source_file
*
24484 macro_start_file (struct dwarf2_cu
*cu
,
24485 int file
, int line
,
24486 struct macro_source_file
*current_file
,
24487 struct line_header
*lh
)
24489 /* File name relative to the compilation directory of this source file. */
24490 char *file_name
= file_file_name (file
, lh
);
24492 if (! current_file
)
24494 /* Note: We don't create a macro table for this compilation unit
24495 at all until we actually get a filename. */
24496 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24498 /* If we have no current file, then this must be the start_file
24499 directive for the compilation unit's main source file. */
24500 current_file
= macro_set_main (macro_table
, file_name
);
24501 macro_define_special (macro_table
);
24504 current_file
= macro_include (current_file
, line
, file_name
);
24508 return current_file
;
24511 static const char *
24512 consume_improper_spaces (const char *p
, const char *body
)
24516 complaint (_("macro definition contains spaces "
24517 "in formal argument list:\n`%s'"),
24529 parse_macro_definition (struct macro_source_file
*file
, int line
,
24534 /* The body string takes one of two forms. For object-like macro
24535 definitions, it should be:
24537 <macro name> " " <definition>
24539 For function-like macro definitions, it should be:
24541 <macro name> "() " <definition>
24543 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24545 Spaces may appear only where explicitly indicated, and in the
24548 The Dwarf 2 spec says that an object-like macro's name is always
24549 followed by a space, but versions of GCC around March 2002 omit
24550 the space when the macro's definition is the empty string.
24552 The Dwarf 2 spec says that there should be no spaces between the
24553 formal arguments in a function-like macro's formal argument list,
24554 but versions of GCC around March 2002 include spaces after the
24558 /* Find the extent of the macro name. The macro name is terminated
24559 by either a space or null character (for an object-like macro) or
24560 an opening paren (for a function-like macro). */
24561 for (p
= body
; *p
; p
++)
24562 if (*p
== ' ' || *p
== '(')
24565 if (*p
== ' ' || *p
== '\0')
24567 /* It's an object-like macro. */
24568 int name_len
= p
- body
;
24569 std::string
name (body
, name_len
);
24570 const char *replacement
;
24573 replacement
= body
+ name_len
+ 1;
24576 dwarf2_macro_malformed_definition_complaint (body
);
24577 replacement
= body
+ name_len
;
24580 macro_define_object (file
, line
, name
.c_str (), replacement
);
24582 else if (*p
== '(')
24584 /* It's a function-like macro. */
24585 std::string
name (body
, p
- body
);
24588 char **argv
= XNEWVEC (char *, argv_size
);
24592 p
= consume_improper_spaces (p
, body
);
24594 /* Parse the formal argument list. */
24595 while (*p
&& *p
!= ')')
24597 /* Find the extent of the current argument name. */
24598 const char *arg_start
= p
;
24600 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24603 if (! *p
|| p
== arg_start
)
24604 dwarf2_macro_malformed_definition_complaint (body
);
24607 /* Make sure argv has room for the new argument. */
24608 if (argc
>= argv_size
)
24611 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24614 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24617 p
= consume_improper_spaces (p
, body
);
24619 /* Consume the comma, if present. */
24624 p
= consume_improper_spaces (p
, body
);
24633 /* Perfectly formed definition, no complaints. */
24634 macro_define_function (file
, line
, name
.c_str (),
24635 argc
, (const char **) argv
,
24637 else if (*p
== '\0')
24639 /* Complain, but do define it. */
24640 dwarf2_macro_malformed_definition_complaint (body
);
24641 macro_define_function (file
, line
, name
.c_str (),
24642 argc
, (const char **) argv
,
24646 /* Just complain. */
24647 dwarf2_macro_malformed_definition_complaint (body
);
24650 /* Just complain. */
24651 dwarf2_macro_malformed_definition_complaint (body
);
24656 for (i
= 0; i
< argc
; i
++)
24662 dwarf2_macro_malformed_definition_complaint (body
);
24665 /* Skip some bytes from BYTES according to the form given in FORM.
24666 Returns the new pointer. */
24668 static const gdb_byte
*
24669 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24670 enum dwarf_form form
,
24671 unsigned int offset_size
,
24672 struct dwarf2_section_info
*section
)
24674 unsigned int bytes_read
;
24678 case DW_FORM_data1
:
24683 case DW_FORM_data2
:
24687 case DW_FORM_data4
:
24691 case DW_FORM_data8
:
24695 case DW_FORM_data16
:
24699 case DW_FORM_string
:
24700 read_direct_string (abfd
, bytes
, &bytes_read
);
24701 bytes
+= bytes_read
;
24704 case DW_FORM_sec_offset
:
24706 case DW_FORM_GNU_strp_alt
:
24707 bytes
+= offset_size
;
24710 case DW_FORM_block
:
24711 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24712 bytes
+= bytes_read
;
24715 case DW_FORM_block1
:
24716 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24718 case DW_FORM_block2
:
24719 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24721 case DW_FORM_block4
:
24722 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24725 case DW_FORM_addrx
:
24726 case DW_FORM_sdata
:
24728 case DW_FORM_udata
:
24729 case DW_FORM_GNU_addr_index
:
24730 case DW_FORM_GNU_str_index
:
24731 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24734 dwarf2_section_buffer_overflow_complaint (section
);
24739 case DW_FORM_implicit_const
:
24744 complaint (_("invalid form 0x%x in `%s'"),
24745 form
, get_section_name (section
));
24753 /* A helper for dwarf_decode_macros that handles skipping an unknown
24754 opcode. Returns an updated pointer to the macro data buffer; or,
24755 on error, issues a complaint and returns NULL. */
24757 static const gdb_byte
*
24758 skip_unknown_opcode (unsigned int opcode
,
24759 const gdb_byte
**opcode_definitions
,
24760 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24762 unsigned int offset_size
,
24763 struct dwarf2_section_info
*section
)
24765 unsigned int bytes_read
, i
;
24767 const gdb_byte
*defn
;
24769 if (opcode_definitions
[opcode
] == NULL
)
24771 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24776 defn
= opcode_definitions
[opcode
];
24777 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24778 defn
+= bytes_read
;
24780 for (i
= 0; i
< arg
; ++i
)
24782 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24783 (enum dwarf_form
) defn
[i
], offset_size
,
24785 if (mac_ptr
== NULL
)
24787 /* skip_form_bytes already issued the complaint. */
24795 /* A helper function which parses the header of a macro section.
24796 If the macro section is the extended (for now called "GNU") type,
24797 then this updates *OFFSET_SIZE. Returns a pointer to just after
24798 the header, or issues a complaint and returns NULL on error. */
24800 static const gdb_byte
*
24801 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24803 const gdb_byte
*mac_ptr
,
24804 unsigned int *offset_size
,
24805 int section_is_gnu
)
24807 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24809 if (section_is_gnu
)
24811 unsigned int version
, flags
;
24813 version
= read_2_bytes (abfd
, mac_ptr
);
24814 if (version
!= 4 && version
!= 5)
24816 complaint (_("unrecognized version `%d' in .debug_macro section"),
24822 flags
= read_1_byte (abfd
, mac_ptr
);
24824 *offset_size
= (flags
& 1) ? 8 : 4;
24826 if ((flags
& 2) != 0)
24827 /* We don't need the line table offset. */
24828 mac_ptr
+= *offset_size
;
24830 /* Vendor opcode descriptions. */
24831 if ((flags
& 4) != 0)
24833 unsigned int i
, count
;
24835 count
= read_1_byte (abfd
, mac_ptr
);
24837 for (i
= 0; i
< count
; ++i
)
24839 unsigned int opcode
, bytes_read
;
24842 opcode
= read_1_byte (abfd
, mac_ptr
);
24844 opcode_definitions
[opcode
] = mac_ptr
;
24845 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24846 mac_ptr
+= bytes_read
;
24855 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24856 including DW_MACRO_import. */
24859 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24861 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24862 struct macro_source_file
*current_file
,
24863 struct line_header
*lh
,
24864 struct dwarf2_section_info
*section
,
24865 int section_is_gnu
, int section_is_dwz
,
24866 unsigned int offset_size
,
24867 htab_t include_hash
)
24869 struct dwarf2_per_objfile
*dwarf2_per_objfile
24870 = cu
->per_cu
->dwarf2_per_objfile
;
24871 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24872 enum dwarf_macro_record_type macinfo_type
;
24873 int at_commandline
;
24874 const gdb_byte
*opcode_definitions
[256];
24876 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24877 &offset_size
, section_is_gnu
);
24878 if (mac_ptr
== NULL
)
24880 /* We already issued a complaint. */
24884 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24885 GDB is still reading the definitions from command line. First
24886 DW_MACINFO_start_file will need to be ignored as it was already executed
24887 to create CURRENT_FILE for the main source holding also the command line
24888 definitions. On first met DW_MACINFO_start_file this flag is reset to
24889 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24891 at_commandline
= 1;
24895 /* Do we at least have room for a macinfo type byte? */
24896 if (mac_ptr
>= mac_end
)
24898 dwarf2_section_buffer_overflow_complaint (section
);
24902 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24905 /* Note that we rely on the fact that the corresponding GNU and
24906 DWARF constants are the same. */
24908 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24909 switch (macinfo_type
)
24911 /* A zero macinfo type indicates the end of the macro
24916 case DW_MACRO_define
:
24917 case DW_MACRO_undef
:
24918 case DW_MACRO_define_strp
:
24919 case DW_MACRO_undef_strp
:
24920 case DW_MACRO_define_sup
:
24921 case DW_MACRO_undef_sup
:
24923 unsigned int bytes_read
;
24928 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24929 mac_ptr
+= bytes_read
;
24931 if (macinfo_type
== DW_MACRO_define
24932 || macinfo_type
== DW_MACRO_undef
)
24934 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24935 mac_ptr
+= bytes_read
;
24939 LONGEST str_offset
;
24941 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24942 mac_ptr
+= offset_size
;
24944 if (macinfo_type
== DW_MACRO_define_sup
24945 || macinfo_type
== DW_MACRO_undef_sup
24948 struct dwz_file
*dwz
24949 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24951 body
= read_indirect_string_from_dwz (objfile
,
24955 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24959 is_define
= (macinfo_type
== DW_MACRO_define
24960 || macinfo_type
== DW_MACRO_define_strp
24961 || macinfo_type
== DW_MACRO_define_sup
);
24962 if (! current_file
)
24964 /* DWARF violation as no main source is present. */
24965 complaint (_("debug info with no main source gives macro %s "
24967 is_define
? _("definition") : _("undefinition"),
24971 if ((line
== 0 && !at_commandline
)
24972 || (line
!= 0 && at_commandline
))
24973 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24974 at_commandline
? _("command-line") : _("in-file"),
24975 is_define
? _("definition") : _("undefinition"),
24976 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24980 /* Fedora's rpm-build's "debugedit" binary
24981 corrupted .debug_macro sections.
24984 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24985 complaint (_("debug info gives %s invalid macro %s "
24986 "without body (corrupted?) at line %d "
24988 at_commandline
? _("command-line") : _("in-file"),
24989 is_define
? _("definition") : _("undefinition"),
24990 line
, current_file
->filename
);
24992 else if (is_define
)
24993 parse_macro_definition (current_file
, line
, body
);
24996 gdb_assert (macinfo_type
== DW_MACRO_undef
24997 || macinfo_type
== DW_MACRO_undef_strp
24998 || macinfo_type
== DW_MACRO_undef_sup
);
24999 macro_undef (current_file
, line
, body
);
25004 case DW_MACRO_start_file
:
25006 unsigned int bytes_read
;
25009 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25010 mac_ptr
+= bytes_read
;
25011 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25012 mac_ptr
+= bytes_read
;
25014 if ((line
== 0 && !at_commandline
)
25015 || (line
!= 0 && at_commandline
))
25016 complaint (_("debug info gives source %d included "
25017 "from %s at %s line %d"),
25018 file
, at_commandline
? _("command-line") : _("file"),
25019 line
== 0 ? _("zero") : _("non-zero"), line
);
25021 if (at_commandline
)
25023 /* This DW_MACRO_start_file was executed in the
25025 at_commandline
= 0;
25028 current_file
= macro_start_file (cu
, file
, line
, current_file
,
25033 case DW_MACRO_end_file
:
25034 if (! current_file
)
25035 complaint (_("macro debug info has an unmatched "
25036 "`close_file' directive"));
25039 current_file
= current_file
->included_by
;
25040 if (! current_file
)
25042 enum dwarf_macro_record_type next_type
;
25044 /* GCC circa March 2002 doesn't produce the zero
25045 type byte marking the end of the compilation
25046 unit. Complain if it's not there, but exit no
25049 /* Do we at least have room for a macinfo type byte? */
25050 if (mac_ptr
>= mac_end
)
25052 dwarf2_section_buffer_overflow_complaint (section
);
25056 /* We don't increment mac_ptr here, so this is just
25059 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
25061 if (next_type
!= 0)
25062 complaint (_("no terminating 0-type entry for "
25063 "macros in `.debug_macinfo' section"));
25070 case DW_MACRO_import
:
25071 case DW_MACRO_import_sup
:
25075 bfd
*include_bfd
= abfd
;
25076 struct dwarf2_section_info
*include_section
= section
;
25077 const gdb_byte
*include_mac_end
= mac_end
;
25078 int is_dwz
= section_is_dwz
;
25079 const gdb_byte
*new_mac_ptr
;
25081 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25082 mac_ptr
+= offset_size
;
25084 if (macinfo_type
== DW_MACRO_import_sup
)
25086 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
25088 dwarf2_read_section (objfile
, &dwz
->macro
);
25090 include_section
= &dwz
->macro
;
25091 include_bfd
= get_section_bfd_owner (include_section
);
25092 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
25096 new_mac_ptr
= include_section
->buffer
+ offset
;
25097 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
25101 /* This has actually happened; see
25102 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
25103 complaint (_("recursive DW_MACRO_import in "
25104 ".debug_macro section"));
25108 *slot
= (void *) new_mac_ptr
;
25110 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
25111 include_mac_end
, current_file
, lh
,
25112 section
, section_is_gnu
, is_dwz
,
25113 offset_size
, include_hash
);
25115 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
25120 case DW_MACINFO_vendor_ext
:
25121 if (!section_is_gnu
)
25123 unsigned int bytes_read
;
25125 /* This reads the constant, but since we don't recognize
25126 any vendor extensions, we ignore it. */
25127 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25128 mac_ptr
+= bytes_read
;
25129 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25130 mac_ptr
+= bytes_read
;
25132 /* We don't recognize any vendor extensions. */
25138 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25139 mac_ptr
, mac_end
, abfd
, offset_size
,
25141 if (mac_ptr
== NULL
)
25146 } while (macinfo_type
!= 0);
25150 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25151 int section_is_gnu
)
25153 struct dwarf2_per_objfile
*dwarf2_per_objfile
25154 = cu
->per_cu
->dwarf2_per_objfile
;
25155 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25156 struct line_header
*lh
= cu
->line_header
;
25158 const gdb_byte
*mac_ptr
, *mac_end
;
25159 struct macro_source_file
*current_file
= 0;
25160 enum dwarf_macro_record_type macinfo_type
;
25161 unsigned int offset_size
= cu
->header
.offset_size
;
25162 const gdb_byte
*opcode_definitions
[256];
25164 struct dwarf2_section_info
*section
;
25165 const char *section_name
;
25167 if (cu
->dwo_unit
!= NULL
)
25169 if (section_is_gnu
)
25171 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25172 section_name
= ".debug_macro.dwo";
25176 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25177 section_name
= ".debug_macinfo.dwo";
25182 if (section_is_gnu
)
25184 section
= &dwarf2_per_objfile
->macro
;
25185 section_name
= ".debug_macro";
25189 section
= &dwarf2_per_objfile
->macinfo
;
25190 section_name
= ".debug_macinfo";
25194 dwarf2_read_section (objfile
, section
);
25195 if (section
->buffer
== NULL
)
25197 complaint (_("missing %s section"), section_name
);
25200 abfd
= get_section_bfd_owner (section
);
25202 /* First pass: Find the name of the base filename.
25203 This filename is needed in order to process all macros whose definition
25204 (or undefinition) comes from the command line. These macros are defined
25205 before the first DW_MACINFO_start_file entry, and yet still need to be
25206 associated to the base file.
25208 To determine the base file name, we scan the macro definitions until we
25209 reach the first DW_MACINFO_start_file entry. We then initialize
25210 CURRENT_FILE accordingly so that any macro definition found before the
25211 first DW_MACINFO_start_file can still be associated to the base file. */
25213 mac_ptr
= section
->buffer
+ offset
;
25214 mac_end
= section
->buffer
+ section
->size
;
25216 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25217 &offset_size
, section_is_gnu
);
25218 if (mac_ptr
== NULL
)
25220 /* We already issued a complaint. */
25226 /* Do we at least have room for a macinfo type byte? */
25227 if (mac_ptr
>= mac_end
)
25229 /* Complaint is printed during the second pass as GDB will probably
25230 stop the first pass earlier upon finding
25231 DW_MACINFO_start_file. */
25235 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25238 /* Note that we rely on the fact that the corresponding GNU and
25239 DWARF constants are the same. */
25241 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25242 switch (macinfo_type
)
25244 /* A zero macinfo type indicates the end of the macro
25249 case DW_MACRO_define
:
25250 case DW_MACRO_undef
:
25251 /* Only skip the data by MAC_PTR. */
25253 unsigned int bytes_read
;
25255 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25256 mac_ptr
+= bytes_read
;
25257 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25258 mac_ptr
+= bytes_read
;
25262 case DW_MACRO_start_file
:
25264 unsigned int bytes_read
;
25267 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25268 mac_ptr
+= bytes_read
;
25269 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25270 mac_ptr
+= bytes_read
;
25272 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25276 case DW_MACRO_end_file
:
25277 /* No data to skip by MAC_PTR. */
25280 case DW_MACRO_define_strp
:
25281 case DW_MACRO_undef_strp
:
25282 case DW_MACRO_define_sup
:
25283 case DW_MACRO_undef_sup
:
25285 unsigned int bytes_read
;
25287 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25288 mac_ptr
+= bytes_read
;
25289 mac_ptr
+= offset_size
;
25293 case DW_MACRO_import
:
25294 case DW_MACRO_import_sup
:
25295 /* Note that, according to the spec, a transparent include
25296 chain cannot call DW_MACRO_start_file. So, we can just
25297 skip this opcode. */
25298 mac_ptr
+= offset_size
;
25301 case DW_MACINFO_vendor_ext
:
25302 /* Only skip the data by MAC_PTR. */
25303 if (!section_is_gnu
)
25305 unsigned int bytes_read
;
25307 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25308 mac_ptr
+= bytes_read
;
25309 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25310 mac_ptr
+= bytes_read
;
25315 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25316 mac_ptr
, mac_end
, abfd
, offset_size
,
25318 if (mac_ptr
== NULL
)
25323 } while (macinfo_type
!= 0 && current_file
== NULL
);
25325 /* Second pass: Process all entries.
25327 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25328 command-line macro definitions/undefinitions. This flag is unset when we
25329 reach the first DW_MACINFO_start_file entry. */
25331 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25333 NULL
, xcalloc
, xfree
));
25334 mac_ptr
= section
->buffer
+ offset
;
25335 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25336 *slot
= (void *) mac_ptr
;
25337 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25338 current_file
, lh
, section
,
25339 section_is_gnu
, 0, offset_size
,
25340 include_hash
.get ());
25343 /* Check if the attribute's form is a DW_FORM_block*
25344 if so return true else false. */
25347 attr_form_is_block (const struct attribute
*attr
)
25349 return (attr
== NULL
? 0 :
25350 attr
->form
== DW_FORM_block1
25351 || attr
->form
== DW_FORM_block2
25352 || attr
->form
== DW_FORM_block4
25353 || attr
->form
== DW_FORM_block
25354 || attr
->form
== DW_FORM_exprloc
);
25357 /* Return non-zero if ATTR's value is a section offset --- classes
25358 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25359 You may use DW_UNSND (attr) to retrieve such offsets.
25361 Section 7.5.4, "Attribute Encodings", explains that no attribute
25362 may have a value that belongs to more than one of these classes; it
25363 would be ambiguous if we did, because we use the same forms for all
25367 attr_form_is_section_offset (const struct attribute
*attr
)
25369 return (attr
->form
== DW_FORM_data4
25370 || attr
->form
== DW_FORM_data8
25371 || attr
->form
== DW_FORM_sec_offset
);
25374 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25375 zero otherwise. When this function returns true, you can apply
25376 dwarf2_get_attr_constant_value to it.
25378 However, note that for some attributes you must check
25379 attr_form_is_section_offset before using this test. DW_FORM_data4
25380 and DW_FORM_data8 are members of both the constant class, and of
25381 the classes that contain offsets into other debug sections
25382 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25383 that, if an attribute's can be either a constant or one of the
25384 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25385 taken as section offsets, not constants.
25387 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25388 cannot handle that. */
25391 attr_form_is_constant (const struct attribute
*attr
)
25393 switch (attr
->form
)
25395 case DW_FORM_sdata
:
25396 case DW_FORM_udata
:
25397 case DW_FORM_data1
:
25398 case DW_FORM_data2
:
25399 case DW_FORM_data4
:
25400 case DW_FORM_data8
:
25401 case DW_FORM_implicit_const
:
25409 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25410 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25413 attr_form_is_ref (const struct attribute
*attr
)
25415 switch (attr
->form
)
25417 case DW_FORM_ref_addr
:
25422 case DW_FORM_ref_udata
:
25423 case DW_FORM_GNU_ref_alt
:
25430 /* Return the .debug_loc section to use for CU.
25431 For DWO files use .debug_loc.dwo. */
25433 static struct dwarf2_section_info
*
25434 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25436 struct dwarf2_per_objfile
*dwarf2_per_objfile
25437 = cu
->per_cu
->dwarf2_per_objfile
;
25441 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25443 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25445 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25446 : &dwarf2_per_objfile
->loc
);
25449 /* A helper function that fills in a dwarf2_loclist_baton. */
25452 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25453 struct dwarf2_loclist_baton
*baton
,
25454 const struct attribute
*attr
)
25456 struct dwarf2_per_objfile
*dwarf2_per_objfile
25457 = cu
->per_cu
->dwarf2_per_objfile
;
25458 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25460 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25462 baton
->per_cu
= cu
->per_cu
;
25463 gdb_assert (baton
->per_cu
);
25464 /* We don't know how long the location list is, but make sure we
25465 don't run off the edge of the section. */
25466 baton
->size
= section
->size
- DW_UNSND (attr
);
25467 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25468 baton
->base_address
= cu
->base_address
;
25469 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25473 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25474 struct dwarf2_cu
*cu
, int is_block
)
25476 struct dwarf2_per_objfile
*dwarf2_per_objfile
25477 = cu
->per_cu
->dwarf2_per_objfile
;
25478 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25479 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25481 if (attr_form_is_section_offset (attr
)
25482 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25483 the section. If so, fall through to the complaint in the
25485 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25487 struct dwarf2_loclist_baton
*baton
;
25489 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25491 fill_in_loclist_baton (cu
, baton
, attr
);
25493 if (cu
->base_known
== 0)
25494 complaint (_("Location list used without "
25495 "specifying the CU base address."));
25497 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25498 ? dwarf2_loclist_block_index
25499 : dwarf2_loclist_index
);
25500 SYMBOL_LOCATION_BATON (sym
) = baton
;
25504 struct dwarf2_locexpr_baton
*baton
;
25506 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25507 baton
->per_cu
= cu
->per_cu
;
25508 gdb_assert (baton
->per_cu
);
25510 if (attr_form_is_block (attr
))
25512 /* Note that we're just copying the block's data pointer
25513 here, not the actual data. We're still pointing into the
25514 info_buffer for SYM's objfile; right now we never release
25515 that buffer, but when we do clean up properly this may
25517 baton
->size
= DW_BLOCK (attr
)->size
;
25518 baton
->data
= DW_BLOCK (attr
)->data
;
25522 dwarf2_invalid_attrib_class_complaint ("location description",
25523 sym
->natural_name ());
25527 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25528 ? dwarf2_locexpr_block_index
25529 : dwarf2_locexpr_index
);
25530 SYMBOL_LOCATION_BATON (sym
) = baton
;
25534 /* Return the OBJFILE associated with the compilation unit CU. If CU
25535 came from a separate debuginfo file, then the master objfile is
25539 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25541 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25543 /* Return the master objfile, so that we can report and look up the
25544 correct file containing this variable. */
25545 if (objfile
->separate_debug_objfile_backlink
)
25546 objfile
= objfile
->separate_debug_objfile_backlink
;
25551 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25552 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25553 CU_HEADERP first. */
25555 static const struct comp_unit_head
*
25556 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25557 struct dwarf2_per_cu_data
*per_cu
)
25559 const gdb_byte
*info_ptr
;
25562 return &per_cu
->cu
->header
;
25564 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25566 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25567 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25568 rcuh_kind::COMPILE
);
25573 /* Return the address size given in the compilation unit header for CU. */
25576 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25578 struct comp_unit_head cu_header_local
;
25579 const struct comp_unit_head
*cu_headerp
;
25581 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25583 return cu_headerp
->addr_size
;
25586 /* Return the offset size given in the compilation unit header for CU. */
25589 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25591 struct comp_unit_head cu_header_local
;
25592 const struct comp_unit_head
*cu_headerp
;
25594 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25596 return cu_headerp
->offset_size
;
25599 /* See its dwarf2loc.h declaration. */
25602 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25604 struct comp_unit_head cu_header_local
;
25605 const struct comp_unit_head
*cu_headerp
;
25607 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25609 if (cu_headerp
->version
== 2)
25610 return cu_headerp
->addr_size
;
25612 return cu_headerp
->offset_size
;
25615 /* Return the text offset of the CU. The returned offset comes from
25616 this CU's objfile. If this objfile came from a separate debuginfo
25617 file, then the offset may be different from the corresponding
25618 offset in the parent objfile. */
25621 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25623 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25625 return objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
25628 /* Return a type that is a generic pointer type, the size of which matches
25629 the address size given in the compilation unit header for PER_CU. */
25630 static struct type
*
25631 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25633 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25634 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25635 struct type
*addr_type
= lookup_pointer_type (void_type
);
25636 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25638 if (TYPE_LENGTH (addr_type
) == addr_size
)
25642 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25646 /* Return DWARF version number of PER_CU. */
25649 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25651 return per_cu
->dwarf_version
;
25654 /* Locate the .debug_info compilation unit from CU's objfile which contains
25655 the DIE at OFFSET. Raises an error on failure. */
25657 static struct dwarf2_per_cu_data
*
25658 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25659 unsigned int offset_in_dwz
,
25660 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25662 struct dwarf2_per_cu_data
*this_cu
;
25666 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25669 struct dwarf2_per_cu_data
*mid_cu
;
25670 int mid
= low
+ (high
- low
) / 2;
25672 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25673 if (mid_cu
->is_dwz
> offset_in_dwz
25674 || (mid_cu
->is_dwz
== offset_in_dwz
25675 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25680 gdb_assert (low
== high
);
25681 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25682 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25684 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25685 error (_("Dwarf Error: could not find partial DIE containing "
25686 "offset %s [in module %s]"),
25687 sect_offset_str (sect_off
),
25688 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25690 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25692 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25696 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25697 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25698 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25699 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25704 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25706 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25707 : per_cu (per_cu_
),
25709 has_loclist (false),
25710 checked_producer (false),
25711 producer_is_gxx_lt_4_6 (false),
25712 producer_is_gcc_lt_4_3 (false),
25713 producer_is_icc (false),
25714 producer_is_icc_lt_14 (false),
25715 producer_is_codewarrior (false),
25716 processing_has_namespace_info (false)
25721 /* Destroy a dwarf2_cu. */
25723 dwarf2_cu::~dwarf2_cu ()
25728 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25731 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25732 enum language pretend_language
)
25734 struct attribute
*attr
;
25736 /* Set the language we're debugging. */
25737 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25738 if (attr
!= nullptr)
25739 set_cu_language (DW_UNSND (attr
), cu
);
25742 cu
->language
= pretend_language
;
25743 cu
->language_defn
= language_def (cu
->language
);
25746 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25749 /* Increase the age counter on each cached compilation unit, and free
25750 any that are too old. */
25753 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25755 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25757 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25758 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25759 while (per_cu
!= NULL
)
25761 per_cu
->cu
->last_used
++;
25762 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25763 dwarf2_mark (per_cu
->cu
);
25764 per_cu
= per_cu
->cu
->read_in_chain
;
25767 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25768 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25769 while (per_cu
!= NULL
)
25771 struct dwarf2_per_cu_data
*next_cu
;
25773 next_cu
= per_cu
->cu
->read_in_chain
;
25775 if (!per_cu
->cu
->mark
)
25778 *last_chain
= next_cu
;
25781 last_chain
= &per_cu
->cu
->read_in_chain
;
25787 /* Remove a single compilation unit from the cache. */
25790 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25792 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25793 struct dwarf2_per_objfile
*dwarf2_per_objfile
25794 = target_per_cu
->dwarf2_per_objfile
;
25796 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25797 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25798 while (per_cu
!= NULL
)
25800 struct dwarf2_per_cu_data
*next_cu
;
25802 next_cu
= per_cu
->cu
->read_in_chain
;
25804 if (per_cu
== target_per_cu
)
25808 *last_chain
= next_cu
;
25812 last_chain
= &per_cu
->cu
->read_in_chain
;
25818 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25819 We store these in a hash table separate from the DIEs, and preserve them
25820 when the DIEs are flushed out of cache.
25822 The CU "per_cu" pointer is needed because offset alone is not enough to
25823 uniquely identify the type. A file may have multiple .debug_types sections,
25824 or the type may come from a DWO file. Furthermore, while it's more logical
25825 to use per_cu->section+offset, with Fission the section with the data is in
25826 the DWO file but we don't know that section at the point we need it.
25827 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25828 because we can enter the lookup routine, get_die_type_at_offset, from
25829 outside this file, and thus won't necessarily have PER_CU->cu.
25830 Fortunately, PER_CU is stable for the life of the objfile. */
25832 struct dwarf2_per_cu_offset_and_type
25834 const struct dwarf2_per_cu_data
*per_cu
;
25835 sect_offset sect_off
;
25839 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25842 per_cu_offset_and_type_hash (const void *item
)
25844 const struct dwarf2_per_cu_offset_and_type
*ofs
25845 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25847 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25850 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25853 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25855 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25856 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25857 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25858 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25860 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25861 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25864 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25865 table if necessary. For convenience, return TYPE.
25867 The DIEs reading must have careful ordering to:
25868 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25869 reading current DIE.
25870 * Not trying to dereference contents of still incompletely read in types
25871 while reading in other DIEs.
25872 * Enable referencing still incompletely read in types just by a pointer to
25873 the type without accessing its fields.
25875 Therefore caller should follow these rules:
25876 * Try to fetch any prerequisite types we may need to build this DIE type
25877 before building the type and calling set_die_type.
25878 * After building type call set_die_type for current DIE as soon as
25879 possible before fetching more types to complete the current type.
25880 * Make the type as complete as possible before fetching more types. */
25882 static struct type
*
25883 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25885 struct dwarf2_per_objfile
*dwarf2_per_objfile
25886 = cu
->per_cu
->dwarf2_per_objfile
;
25887 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25888 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25889 struct attribute
*attr
;
25890 struct dynamic_prop prop
;
25892 /* For Ada types, make sure that the gnat-specific data is always
25893 initialized (if not already set). There are a few types where
25894 we should not be doing so, because the type-specific area is
25895 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25896 where the type-specific area is used to store the floatformat).
25897 But this is not a problem, because the gnat-specific information
25898 is actually not needed for these types. */
25899 if (need_gnat_info (cu
)
25900 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25901 && TYPE_CODE (type
) != TYPE_CODE_FLT
25902 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25903 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25904 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25905 && !HAVE_GNAT_AUX_INFO (type
))
25906 INIT_GNAT_SPECIFIC (type
);
25908 /* Read DW_AT_allocated and set in type. */
25909 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25910 if (attr_form_is_block (attr
))
25912 struct type
*prop_type
25913 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25914 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25915 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25917 else if (attr
!= NULL
)
25919 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25920 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25921 sect_offset_str (die
->sect_off
));
25924 /* Read DW_AT_associated and set in type. */
25925 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25926 if (attr_form_is_block (attr
))
25928 struct type
*prop_type
25929 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25930 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25931 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25933 else if (attr
!= NULL
)
25935 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25936 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25937 sect_offset_str (die
->sect_off
));
25940 /* Read DW_AT_data_location and set in type. */
25941 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25942 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25943 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25944 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25946 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25948 dwarf2_per_objfile
->die_type_hash
=
25949 htab_create_alloc_ex (127,
25950 per_cu_offset_and_type_hash
,
25951 per_cu_offset_and_type_eq
,
25953 &objfile
->objfile_obstack
,
25954 hashtab_obstack_allocate
,
25955 dummy_obstack_deallocate
);
25958 ofs
.per_cu
= cu
->per_cu
;
25959 ofs
.sect_off
= die
->sect_off
;
25961 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25962 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25964 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25965 sect_offset_str (die
->sect_off
));
25966 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25967 struct dwarf2_per_cu_offset_and_type
);
25972 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25973 or return NULL if the die does not have a saved type. */
25975 static struct type
*
25976 get_die_type_at_offset (sect_offset sect_off
,
25977 struct dwarf2_per_cu_data
*per_cu
)
25979 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25980 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25982 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25985 ofs
.per_cu
= per_cu
;
25986 ofs
.sect_off
= sect_off
;
25987 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25988 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25995 /* Look up the type for DIE in CU in die_type_hash,
25996 or return NULL if DIE does not have a saved type. */
25998 static struct type
*
25999 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
26001 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
26004 /* Add a dependence relationship from CU to REF_PER_CU. */
26007 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
26008 struct dwarf2_per_cu_data
*ref_per_cu
)
26012 if (cu
->dependencies
== NULL
)
26014 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
26015 NULL
, &cu
->comp_unit_obstack
,
26016 hashtab_obstack_allocate
,
26017 dummy_obstack_deallocate
);
26019 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
26021 *slot
= ref_per_cu
;
26024 /* Subroutine of dwarf2_mark to pass to htab_traverse.
26025 Set the mark field in every compilation unit in the
26026 cache that we must keep because we are keeping CU. */
26029 dwarf2_mark_helper (void **slot
, void *data
)
26031 struct dwarf2_per_cu_data
*per_cu
;
26033 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
26035 /* cu->dependencies references may not yet have been ever read if QUIT aborts
26036 reading of the chain. As such dependencies remain valid it is not much
26037 useful to track and undo them during QUIT cleanups. */
26038 if (per_cu
->cu
== NULL
)
26041 if (per_cu
->cu
->mark
)
26043 per_cu
->cu
->mark
= true;
26045 if (per_cu
->cu
->dependencies
!= NULL
)
26046 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26051 /* Set the mark field in CU and in every other compilation unit in the
26052 cache that we must keep because we are keeping CU. */
26055 dwarf2_mark (struct dwarf2_cu
*cu
)
26060 if (cu
->dependencies
!= NULL
)
26061 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26065 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
26069 per_cu
->cu
->mark
= false;
26070 per_cu
= per_cu
->cu
->read_in_chain
;
26074 /* Trivial hash function for partial_die_info: the hash value of a DIE
26075 is its offset in .debug_info for this objfile. */
26078 partial_die_hash (const void *item
)
26080 const struct partial_die_info
*part_die
26081 = (const struct partial_die_info
*) item
;
26083 return to_underlying (part_die
->sect_off
);
26086 /* Trivial comparison function for partial_die_info structures: two DIEs
26087 are equal if they have the same offset. */
26090 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
26092 const struct partial_die_info
*part_die_lhs
26093 = (const struct partial_die_info
*) item_lhs
;
26094 const struct partial_die_info
*part_die_rhs
26095 = (const struct partial_die_info
*) item_rhs
;
26097 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
26100 struct cmd_list_element
*set_dwarf_cmdlist
;
26101 struct cmd_list_element
*show_dwarf_cmdlist
;
26104 set_dwarf_cmd (const char *args
, int from_tty
)
26106 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
26111 show_dwarf_cmd (const char *args
, int from_tty
)
26113 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
26116 bool dwarf_always_disassemble
;
26119 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
26120 struct cmd_list_element
*c
, const char *value
)
26122 fprintf_filtered (file
,
26123 _("Whether to always disassemble "
26124 "DWARF expressions is %s.\n"),
26129 show_check_physname (struct ui_file
*file
, int from_tty
,
26130 struct cmd_list_element
*c
, const char *value
)
26132 fprintf_filtered (file
,
26133 _("Whether to check \"physname\" is %s.\n"),
26138 _initialize_dwarf2_read (void)
26140 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26141 Set DWARF specific variables.\n\
26142 Configure DWARF variables such as the cache size."),
26143 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26144 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26146 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26147 Show DWARF specific variables.\n\
26148 Show DWARF variables such as the cache size."),
26149 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26150 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26152 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26153 &dwarf_max_cache_age
, _("\
26154 Set the upper bound on the age of cached DWARF compilation units."), _("\
26155 Show the upper bound on the age of cached DWARF compilation units."), _("\
26156 A higher limit means that cached compilation units will be stored\n\
26157 in memory longer, and more total memory will be used. Zero disables\n\
26158 caching, which can slow down startup."),
26160 show_dwarf_max_cache_age
,
26161 &set_dwarf_cmdlist
,
26162 &show_dwarf_cmdlist
);
26164 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26165 &dwarf_always_disassemble
, _("\
26166 Set whether `info address' always disassembles DWARF expressions."), _("\
26167 Show whether `info address' always disassembles DWARF expressions."), _("\
26168 When enabled, DWARF expressions are always printed in an assembly-like\n\
26169 syntax. When disabled, expressions will be printed in a more\n\
26170 conversational style, when possible."),
26172 show_dwarf_always_disassemble
,
26173 &set_dwarf_cmdlist
,
26174 &show_dwarf_cmdlist
);
26176 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26177 Set debugging of the DWARF reader."), _("\
26178 Show debugging of the DWARF reader."), _("\
26179 When enabled (non-zero), debugging messages are printed during DWARF\n\
26180 reading and symtab expansion. A value of 1 (one) provides basic\n\
26181 information. A value greater than 1 provides more verbose information."),
26184 &setdebuglist
, &showdebuglist
);
26186 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26187 Set debugging of the DWARF DIE reader."), _("\
26188 Show debugging of the DWARF DIE reader."), _("\
26189 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26190 The value is the maximum depth to print."),
26193 &setdebuglist
, &showdebuglist
);
26195 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26196 Set debugging of the dwarf line reader."), _("\
26197 Show debugging of the dwarf line reader."), _("\
26198 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26199 A value of 1 (one) provides basic information.\n\
26200 A value greater than 1 provides more verbose information."),
26203 &setdebuglist
, &showdebuglist
);
26205 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26206 Set cross-checking of \"physname\" code against demangler."), _("\
26207 Show cross-checking of \"physname\" code against demangler."), _("\
26208 When enabled, GDB's internal \"physname\" code is checked against\n\
26210 NULL
, show_check_physname
,
26211 &setdebuglist
, &showdebuglist
);
26213 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26214 no_class
, &use_deprecated_index_sections
, _("\
26215 Set whether to use deprecated gdb_index sections."), _("\
26216 Show whether to use deprecated gdb_index sections."), _("\
26217 When enabled, deprecated .gdb_index sections are used anyway.\n\
26218 Normally they are ignored either because of a missing feature or\n\
26219 performance issue.\n\
26220 Warning: This option must be enabled before gdb reads the file."),
26223 &setlist
, &showlist
);
26225 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26226 &dwarf2_locexpr_funcs
);
26227 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26228 &dwarf2_loclist_funcs
);
26230 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26231 &dwarf2_block_frame_base_locexpr_funcs
);
26232 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26233 &dwarf2_block_frame_base_loclist_funcs
);
26236 selftests::register_test ("dw2_expand_symtabs_matching",
26237 selftests::dw2_expand_symtabs_matching::run_test
);