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 #ifndef ATTR_ALLOC_CHUNK
1344 #define ATTR_ALLOC_CHUNK 4
1347 /* Allocate fields for structs, unions and enums in this size. */
1348 #ifndef DW_FIELD_ALLOC_CHUNK
1349 #define DW_FIELD_ALLOC_CHUNK 4
1352 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1353 but this would require a corresponding change in unpack_field_as_long
1355 static int bits_per_byte
= 8;
1357 /* When reading a variant or variant part, we track a bit more
1358 information about the field, and store it in an object of this
1361 struct variant_field
1363 /* If we see a DW_TAG_variant, then this will be the discriminant
1365 ULONGEST discriminant_value
;
1366 /* If we see a DW_TAG_variant, then this will be set if this is the
1368 bool default_branch
;
1369 /* While reading a DW_TAG_variant_part, this will be set if this
1370 field is the discriminant. */
1371 bool is_discriminant
;
1376 int accessibility
= 0;
1378 /* Extra information to describe a variant or variant part. */
1379 struct variant_field variant
{};
1380 struct field field
{};
1385 const char *name
= nullptr;
1386 std::vector
<struct fn_field
> fnfields
;
1389 /* The routines that read and process dies for a C struct or C++ class
1390 pass lists of data member fields and lists of member function fields
1391 in an instance of a field_info structure, as defined below. */
1394 /* List of data member and baseclasses fields. */
1395 std::vector
<struct nextfield
> fields
;
1396 std::vector
<struct nextfield
> baseclasses
;
1398 /* Number of fields (including baseclasses). */
1401 /* Set if the accessibility of one of the fields is not public. */
1402 int non_public_fields
= 0;
1404 /* Member function fieldlist array, contains name of possibly overloaded
1405 member function, number of overloaded member functions and a pointer
1406 to the head of the member function field chain. */
1407 std::vector
<struct fnfieldlist
> fnfieldlists
;
1409 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1410 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1411 std::vector
<struct decl_field
> typedef_field_list
;
1413 /* Nested types defined by this class and the number of elements in this
1415 std::vector
<struct decl_field
> nested_types_list
;
1418 /* One item on the queue of compilation units to read in full symbols
1420 struct dwarf2_queue_item
1422 struct dwarf2_per_cu_data
*per_cu
;
1423 enum language pretend_language
;
1424 struct dwarf2_queue_item
*next
;
1427 /* The current queue. */
1428 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1430 /* Loaded secondary compilation units are kept in memory until they
1431 have not been referenced for the processing of this many
1432 compilation units. Set this to zero to disable caching. Cache
1433 sizes of up to at least twenty will improve startup time for
1434 typical inter-CU-reference binaries, at an obvious memory cost. */
1435 static int dwarf_max_cache_age
= 5;
1437 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1438 struct cmd_list_element
*c
, const char *value
)
1440 fprintf_filtered (file
, _("The upper bound on the age of cached "
1441 "DWARF compilation units is %s.\n"),
1445 /* local function prototypes */
1447 static const char *get_section_name (const struct dwarf2_section_info
*);
1449 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1451 static void dwarf2_find_base_address (struct die_info
*die
,
1452 struct dwarf2_cu
*cu
);
1454 static struct partial_symtab
*create_partial_symtab
1455 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1457 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1458 const gdb_byte
*info_ptr
,
1459 struct die_info
*type_unit_die
,
1460 int has_children
, void *data
);
1462 static void dwarf2_build_psymtabs_hard
1463 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1465 static void scan_partial_symbols (struct partial_die_info
*,
1466 CORE_ADDR
*, CORE_ADDR
*,
1467 int, struct dwarf2_cu
*);
1469 static void add_partial_symbol (struct partial_die_info
*,
1470 struct dwarf2_cu
*);
1472 static void add_partial_namespace (struct partial_die_info
*pdi
,
1473 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1474 int set_addrmap
, struct dwarf2_cu
*cu
);
1476 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1477 CORE_ADDR
*highpc
, int set_addrmap
,
1478 struct dwarf2_cu
*cu
);
1480 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1481 struct dwarf2_cu
*cu
);
1483 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1484 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1485 int need_pc
, struct dwarf2_cu
*cu
);
1487 static void dwarf2_read_symtab (struct partial_symtab
*,
1490 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1492 static abbrev_table_up abbrev_table_read_table
1493 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1496 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1498 static struct partial_die_info
*load_partial_dies
1499 (const struct die_reader_specs
*, const gdb_byte
*, int);
1501 /* A pair of partial_die_info and compilation unit. */
1502 struct cu_partial_die_info
1504 /* The compilation unit of the partial_die_info. */
1505 struct dwarf2_cu
*cu
;
1506 /* A partial_die_info. */
1507 struct partial_die_info
*pdi
;
1509 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1515 cu_partial_die_info () = delete;
1518 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1519 struct dwarf2_cu
*);
1521 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1522 struct attribute
*, struct attr_abbrev
*,
1525 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1527 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1529 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1531 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1532 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1534 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1536 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1538 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1541 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1543 static LONGEST read_checked_initial_length_and_offset
1544 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1545 unsigned int *, unsigned int *);
1547 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1548 const struct comp_unit_head
*,
1551 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1553 static sect_offset read_abbrev_offset
1554 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1555 struct dwarf2_section_info
*, sect_offset
);
1557 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1559 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1561 static const char *read_indirect_string
1562 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1563 const struct comp_unit_head
*, unsigned int *);
1565 static const char *read_indirect_line_string
1566 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1567 const struct comp_unit_head
*, unsigned int *);
1569 static const char *read_indirect_string_at_offset
1570 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1571 LONGEST str_offset
);
1573 static const char *read_indirect_string_from_dwz
1574 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1576 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1578 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1582 static const char *read_str_index (const struct die_reader_specs
*reader
,
1583 ULONGEST str_index
);
1585 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1587 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1588 struct dwarf2_cu
*);
1590 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1593 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1594 struct dwarf2_cu
*cu
);
1596 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1598 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1599 struct dwarf2_cu
*cu
);
1601 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1603 static struct die_info
*die_specification (struct die_info
*die
,
1604 struct dwarf2_cu
**);
1606 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1607 struct dwarf2_cu
*cu
);
1609 static void dwarf_decode_lines (struct line_header
*, const char *,
1610 struct dwarf2_cu
*, struct partial_symtab
*,
1611 CORE_ADDR
, int decode_mapping
);
1613 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1616 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1617 struct dwarf2_cu
*, struct symbol
* = NULL
);
1619 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1620 struct dwarf2_cu
*);
1622 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1625 struct obstack
*obstack
,
1626 struct dwarf2_cu
*cu
, LONGEST
*value
,
1627 const gdb_byte
**bytes
,
1628 struct dwarf2_locexpr_baton
**baton
);
1630 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1632 static int need_gnat_info (struct dwarf2_cu
*);
1634 static struct type
*die_descriptive_type (struct die_info
*,
1635 struct dwarf2_cu
*);
1637 static void set_descriptive_type (struct type
*, struct die_info
*,
1638 struct dwarf2_cu
*);
1640 static struct type
*die_containing_type (struct die_info
*,
1641 struct dwarf2_cu
*);
1643 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1644 struct dwarf2_cu
*);
1646 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1648 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1650 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1652 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1653 const char *suffix
, int physname
,
1654 struct dwarf2_cu
*cu
);
1656 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1658 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1660 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1662 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1664 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1666 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1668 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1669 struct dwarf2_cu
*, struct partial_symtab
*);
1671 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1672 values. Keep the items ordered with increasing constraints compliance. */
1675 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1676 PC_BOUNDS_NOT_PRESENT
,
1678 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1679 were present but they do not form a valid range of PC addresses. */
1682 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1685 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1689 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1690 CORE_ADDR
*, CORE_ADDR
*,
1692 struct partial_symtab
*);
1694 static void get_scope_pc_bounds (struct die_info
*,
1695 CORE_ADDR
*, CORE_ADDR
*,
1696 struct dwarf2_cu
*);
1698 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1699 CORE_ADDR
, struct dwarf2_cu
*);
1701 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1702 struct dwarf2_cu
*);
1704 static void dwarf2_attach_fields_to_type (struct field_info
*,
1705 struct type
*, struct dwarf2_cu
*);
1707 static void dwarf2_add_member_fn (struct field_info
*,
1708 struct die_info
*, struct type
*,
1709 struct dwarf2_cu
*);
1711 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1713 struct dwarf2_cu
*);
1715 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1717 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1719 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1721 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1723 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1725 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1727 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1729 static struct type
*read_module_type (struct die_info
*die
,
1730 struct dwarf2_cu
*cu
);
1732 static const char *namespace_name (struct die_info
*die
,
1733 int *is_anonymous
, struct dwarf2_cu
*);
1735 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1737 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1739 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1740 struct dwarf2_cu
*);
1742 static struct die_info
*read_die_and_siblings_1
1743 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1746 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1747 const gdb_byte
*info_ptr
,
1748 const gdb_byte
**new_info_ptr
,
1749 struct die_info
*parent
);
1751 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1752 struct die_info
**, const gdb_byte
*,
1755 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1756 struct die_info
**, const gdb_byte
*,
1759 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1761 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1764 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1766 static const char *dwarf2_full_name (const char *name
,
1767 struct die_info
*die
,
1768 struct dwarf2_cu
*cu
);
1770 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1771 struct dwarf2_cu
*cu
);
1773 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1774 struct dwarf2_cu
**);
1776 static const char *dwarf_tag_name (unsigned int);
1778 static const char *dwarf_attr_name (unsigned int);
1780 static const char *dwarf_unit_type_name (int unit_type
);
1782 static const char *dwarf_form_name (unsigned int);
1784 static const char *dwarf_bool_name (unsigned int);
1786 static const char *dwarf_type_encoding_name (unsigned int);
1788 static struct die_info
*sibling_die (struct die_info
*);
1790 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1792 static void dump_die_for_error (struct die_info
*);
1794 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1797 /*static*/ void dump_die (struct die_info
*, int max_level
);
1799 static void store_in_ref_table (struct die_info
*,
1800 struct dwarf2_cu
*);
1802 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1804 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1806 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1807 const struct attribute
*,
1808 struct dwarf2_cu
**);
1810 static struct die_info
*follow_die_ref (struct die_info
*,
1811 const struct attribute
*,
1812 struct dwarf2_cu
**);
1814 static struct die_info
*follow_die_sig (struct die_info
*,
1815 const struct attribute
*,
1816 struct dwarf2_cu
**);
1818 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1819 struct dwarf2_cu
*);
1821 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1822 const struct attribute
*,
1823 struct dwarf2_cu
*);
1825 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1827 static void read_signatured_type (struct signatured_type
*);
1829 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1830 struct die_info
*die
, struct dwarf2_cu
*cu
,
1831 struct dynamic_prop
*prop
, struct type
*type
);
1833 /* memory allocation interface */
1835 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1837 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1839 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1841 static int attr_form_is_block (const struct attribute
*);
1843 static int attr_form_is_section_offset (const struct attribute
*);
1845 static int attr_form_is_constant (const struct attribute
*);
1847 static int attr_form_is_ref (const struct attribute
*);
1849 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1850 struct dwarf2_loclist_baton
*baton
,
1851 const struct attribute
*attr
);
1853 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1855 struct dwarf2_cu
*cu
,
1858 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1859 const gdb_byte
*info_ptr
,
1860 struct abbrev_info
*abbrev
);
1862 static hashval_t
partial_die_hash (const void *item
);
1864 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1866 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1867 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1868 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1870 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1871 struct die_info
*comp_unit_die
,
1872 enum language pretend_language
);
1874 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1876 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1878 static struct type
*set_die_type (struct die_info
*, struct type
*,
1879 struct dwarf2_cu
*);
1881 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1883 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1885 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1888 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1891 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1894 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1895 struct dwarf2_per_cu_data
*);
1897 static void dwarf2_mark (struct dwarf2_cu
*);
1899 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1901 static struct type
*get_die_type_at_offset (sect_offset
,
1902 struct dwarf2_per_cu_data
*);
1904 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1906 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1907 enum language pretend_language
);
1909 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1911 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1912 static struct type
*dwarf2_per_cu_addr_sized_int_type
1913 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1914 static struct type
*dwarf2_per_cu_int_type
1915 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1918 /* Class, the destructor of which frees all allocated queue entries. This
1919 will only have work to do if an error was thrown while processing the
1920 dwarf. If no error was thrown then the queue entries should have all
1921 been processed, and freed, as we went along. */
1923 class dwarf2_queue_guard
1926 dwarf2_queue_guard () = default;
1928 /* Free any entries remaining on the queue. There should only be
1929 entries left if we hit an error while processing the dwarf. */
1930 ~dwarf2_queue_guard ()
1932 struct dwarf2_queue_item
*item
, *last
;
1934 item
= dwarf2_queue
;
1937 /* Anything still marked queued is likely to be in an
1938 inconsistent state, so discard it. */
1939 if (item
->per_cu
->queued
)
1941 if (item
->per_cu
->cu
!= NULL
)
1942 free_one_cached_comp_unit (item
->per_cu
);
1943 item
->per_cu
->queued
= 0;
1951 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1955 /* The return type of find_file_and_directory. Note, the enclosed
1956 string pointers are only valid while this object is valid. */
1958 struct file_and_directory
1960 /* The filename. This is never NULL. */
1963 /* The compilation directory. NULL if not known. If we needed to
1964 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1965 points directly to the DW_AT_comp_dir string attribute owned by
1966 the obstack that owns the DIE. */
1967 const char *comp_dir
;
1969 /* If we needed to build a new string for comp_dir, this is what
1970 owns the storage. */
1971 std::string comp_dir_storage
;
1974 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1975 struct dwarf2_cu
*cu
);
1977 static char *file_full_name (int file
, struct line_header
*lh
,
1978 const char *comp_dir
);
1980 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1981 enum class rcuh_kind
{ COMPILE
, TYPE
};
1983 static const gdb_byte
*read_and_check_comp_unit_head
1984 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1985 struct comp_unit_head
*header
,
1986 struct dwarf2_section_info
*section
,
1987 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1988 rcuh_kind section_kind
);
1990 static void init_cutu_and_read_dies
1991 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1992 int use_existing_cu
, int keep
, bool skip_partial
,
1993 die_reader_func_ftype
*die_reader_func
, void *data
);
1995 static void init_cutu_and_read_dies_simple
1996 (struct dwarf2_per_cu_data
*this_cu
,
1997 die_reader_func_ftype
*die_reader_func
, void *data
);
1999 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2001 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2003 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2004 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2005 struct dwp_file
*dwp_file
, const char *comp_dir
,
2006 ULONGEST signature
, int is_debug_types
);
2008 static struct dwp_file
*get_dwp_file
2009 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2011 static struct dwo_unit
*lookup_dwo_comp_unit
2012 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2014 static struct dwo_unit
*lookup_dwo_type_unit
2015 (struct signatured_type
*, const char *, const char *);
2017 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2019 /* A unique pointer to a dwo_file. */
2021 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2023 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2025 static void check_producer (struct dwarf2_cu
*cu
);
2027 static void free_line_header_voidp (void *arg
);
2029 /* Various complaints about symbol reading that don't abort the process. */
2032 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2034 complaint (_("statement list doesn't fit in .debug_line section"));
2038 dwarf2_debug_line_missing_file_complaint (void)
2040 complaint (_(".debug_line section has line data without a file"));
2044 dwarf2_debug_line_missing_end_sequence_complaint (void)
2046 complaint (_(".debug_line section has line "
2047 "program sequence without an end"));
2051 dwarf2_complex_location_expr_complaint (void)
2053 complaint (_("location expression too complex"));
2057 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2060 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2065 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2067 complaint (_("debug info runs off end of %s section"
2069 get_section_name (section
),
2070 get_section_file_name (section
));
2074 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2076 complaint (_("macro debug info contains a "
2077 "malformed macro definition:\n`%s'"),
2082 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2084 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2088 /* Hash function for line_header_hash. */
2091 line_header_hash (const struct line_header
*ofs
)
2093 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2096 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2099 line_header_hash_voidp (const void *item
)
2101 const struct line_header
*ofs
= (const struct line_header
*) item
;
2103 return line_header_hash (ofs
);
2106 /* Equality function for line_header_hash. */
2109 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2111 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2112 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2114 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2115 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2120 /* Read the given attribute value as an address, taking the attribute's
2121 form into account. */
2124 attr_value_as_address (struct attribute
*attr
)
2128 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2129 && attr
->form
!= DW_FORM_GNU_addr_index
)
2131 /* Aside from a few clearly defined exceptions, attributes that
2132 contain an address must always be in DW_FORM_addr form.
2133 Unfortunately, some compilers happen to be violating this
2134 requirement by encoding addresses using other forms, such
2135 as DW_FORM_data4 for example. For those broken compilers,
2136 we try to do our best, without any guarantee of success,
2137 to interpret the address correctly. It would also be nice
2138 to generate a complaint, but that would require us to maintain
2139 a list of legitimate cases where a non-address form is allowed,
2140 as well as update callers to pass in at least the CU's DWARF
2141 version. This is more overhead than what we're willing to
2142 expand for a pretty rare case. */
2143 addr
= DW_UNSND (attr
);
2146 addr
= DW_ADDR (attr
);
2151 /* See declaration. */
2153 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2154 const dwarf2_debug_sections
*names
,
2156 : objfile (objfile_
),
2157 can_copy (can_copy_
)
2160 names
= &dwarf2_elf_names
;
2162 bfd
*obfd
= objfile
->obfd
;
2164 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2165 locate_sections (obfd
, sec
, *names
);
2168 dwarf2_per_objfile::~dwarf2_per_objfile ()
2170 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2171 free_cached_comp_units ();
2173 if (quick_file_names_table
)
2174 htab_delete (quick_file_names_table
);
2176 if (line_header_hash
)
2177 htab_delete (line_header_hash
);
2179 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2180 per_cu
->imported_symtabs_free ();
2182 for (signatured_type
*sig_type
: all_type_units
)
2183 sig_type
->per_cu
.imported_symtabs_free ();
2185 /* Everything else should be on the objfile obstack. */
2188 /* See declaration. */
2191 dwarf2_per_objfile::free_cached_comp_units ()
2193 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2194 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2195 while (per_cu
!= NULL
)
2197 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2200 *last_chain
= next_cu
;
2205 /* A helper class that calls free_cached_comp_units on
2208 class free_cached_comp_units
2212 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2213 : m_per_objfile (per_objfile
)
2217 ~free_cached_comp_units ()
2219 m_per_objfile
->free_cached_comp_units ();
2222 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2226 dwarf2_per_objfile
*m_per_objfile
;
2229 /* Try to locate the sections we need for DWARF 2 debugging
2230 information and return true if we have enough to do something.
2231 NAMES points to the dwarf2 section names, or is NULL if the standard
2232 ELF names are used. CAN_COPY is true for formats where symbol
2233 interposition is possible and so symbol values must follow copy
2234 relocation rules. */
2237 dwarf2_has_info (struct objfile
*objfile
,
2238 const struct dwarf2_debug_sections
*names
,
2241 if (objfile
->flags
& OBJF_READNEVER
)
2244 struct dwarf2_per_objfile
*dwarf2_per_objfile
2245 = get_dwarf2_per_objfile (objfile
);
2247 if (dwarf2_per_objfile
== NULL
)
2248 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2252 return (!dwarf2_per_objfile
->info
.is_virtual
2253 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2254 && !dwarf2_per_objfile
->abbrev
.is_virtual
2255 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2258 /* Return the containing section of virtual section SECTION. */
2260 static struct dwarf2_section_info
*
2261 get_containing_section (const struct dwarf2_section_info
*section
)
2263 gdb_assert (section
->is_virtual
);
2264 return section
->s
.containing_section
;
2267 /* Return the bfd owner of SECTION. */
2270 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2272 if (section
->is_virtual
)
2274 section
= get_containing_section (section
);
2275 gdb_assert (!section
->is_virtual
);
2277 return section
->s
.section
->owner
;
2280 /* Return the bfd section of SECTION.
2281 Returns NULL if the section is not present. */
2284 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2286 if (section
->is_virtual
)
2288 section
= get_containing_section (section
);
2289 gdb_assert (!section
->is_virtual
);
2291 return section
->s
.section
;
2294 /* Return the name of SECTION. */
2297 get_section_name (const struct dwarf2_section_info
*section
)
2299 asection
*sectp
= get_section_bfd_section (section
);
2301 gdb_assert (sectp
!= NULL
);
2302 return bfd_section_name (sectp
);
2305 /* Return the name of the file SECTION is in. */
2308 get_section_file_name (const struct dwarf2_section_info
*section
)
2310 bfd
*abfd
= get_section_bfd_owner (section
);
2312 return bfd_get_filename (abfd
);
2315 /* Return the id of SECTION.
2316 Returns 0 if SECTION doesn't exist. */
2319 get_section_id (const struct dwarf2_section_info
*section
)
2321 asection
*sectp
= get_section_bfd_section (section
);
2328 /* Return the flags of SECTION.
2329 SECTION (or containing section if this is a virtual section) must exist. */
2332 get_section_flags (const struct dwarf2_section_info
*section
)
2334 asection
*sectp
= get_section_bfd_section (section
);
2336 gdb_assert (sectp
!= NULL
);
2337 return bfd_section_flags (sectp
);
2340 /* When loading sections, we look either for uncompressed section or for
2341 compressed section names. */
2344 section_is_p (const char *section_name
,
2345 const struct dwarf2_section_names
*names
)
2347 if (names
->normal
!= NULL
2348 && strcmp (section_name
, names
->normal
) == 0)
2350 if (names
->compressed
!= NULL
2351 && strcmp (section_name
, names
->compressed
) == 0)
2356 /* See declaration. */
2359 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2360 const dwarf2_debug_sections
&names
)
2362 flagword aflag
= bfd_section_flags (sectp
);
2364 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2367 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2368 > bfd_get_file_size (abfd
))
2370 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2371 warning (_("Discarding section %s which has a section size (%s"
2372 ") larger than the file size [in module %s]"),
2373 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2374 bfd_get_filename (abfd
));
2376 else if (section_is_p (sectp
->name
, &names
.info
))
2378 this->info
.s
.section
= sectp
;
2379 this->info
.size
= bfd_section_size (sectp
);
2381 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2383 this->abbrev
.s
.section
= sectp
;
2384 this->abbrev
.size
= bfd_section_size (sectp
);
2386 else if (section_is_p (sectp
->name
, &names
.line
))
2388 this->line
.s
.section
= sectp
;
2389 this->line
.size
= bfd_section_size (sectp
);
2391 else if (section_is_p (sectp
->name
, &names
.loc
))
2393 this->loc
.s
.section
= sectp
;
2394 this->loc
.size
= bfd_section_size (sectp
);
2396 else if (section_is_p (sectp
->name
, &names
.loclists
))
2398 this->loclists
.s
.section
= sectp
;
2399 this->loclists
.size
= bfd_section_size (sectp
);
2401 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2403 this->macinfo
.s
.section
= sectp
;
2404 this->macinfo
.size
= bfd_section_size (sectp
);
2406 else if (section_is_p (sectp
->name
, &names
.macro
))
2408 this->macro
.s
.section
= sectp
;
2409 this->macro
.size
= bfd_section_size (sectp
);
2411 else if (section_is_p (sectp
->name
, &names
.str
))
2413 this->str
.s
.section
= sectp
;
2414 this->str
.size
= bfd_section_size (sectp
);
2416 else if (section_is_p (sectp
->name
, &names
.line_str
))
2418 this->line_str
.s
.section
= sectp
;
2419 this->line_str
.size
= bfd_section_size (sectp
);
2421 else if (section_is_p (sectp
->name
, &names
.addr
))
2423 this->addr
.s
.section
= sectp
;
2424 this->addr
.size
= bfd_section_size (sectp
);
2426 else if (section_is_p (sectp
->name
, &names
.frame
))
2428 this->frame
.s
.section
= sectp
;
2429 this->frame
.size
= bfd_section_size (sectp
);
2431 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2433 this->eh_frame
.s
.section
= sectp
;
2434 this->eh_frame
.size
= bfd_section_size (sectp
);
2436 else if (section_is_p (sectp
->name
, &names
.ranges
))
2438 this->ranges
.s
.section
= sectp
;
2439 this->ranges
.size
= bfd_section_size (sectp
);
2441 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2443 this->rnglists
.s
.section
= sectp
;
2444 this->rnglists
.size
= bfd_section_size (sectp
);
2446 else if (section_is_p (sectp
->name
, &names
.types
))
2448 struct dwarf2_section_info type_section
;
2450 memset (&type_section
, 0, sizeof (type_section
));
2451 type_section
.s
.section
= sectp
;
2452 type_section
.size
= bfd_section_size (sectp
);
2454 this->types
.push_back (type_section
);
2456 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2458 this->gdb_index
.s
.section
= sectp
;
2459 this->gdb_index
.size
= bfd_section_size (sectp
);
2461 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2463 this->debug_names
.s
.section
= sectp
;
2464 this->debug_names
.size
= bfd_section_size (sectp
);
2466 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2468 this->debug_aranges
.s
.section
= sectp
;
2469 this->debug_aranges
.size
= bfd_section_size (sectp
);
2472 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2473 && bfd_section_vma (sectp
) == 0)
2474 this->has_section_at_zero
= true;
2477 /* A helper function that decides whether a section is empty,
2481 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2483 if (section
->is_virtual
)
2484 return section
->size
== 0;
2485 return section
->s
.section
== NULL
|| section
->size
== 0;
2488 /* See dwarf2read.h. */
2491 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2495 gdb_byte
*buf
, *retbuf
;
2499 info
->buffer
= NULL
;
2500 info
->readin
= true;
2502 if (dwarf2_section_empty_p (info
))
2505 sectp
= get_section_bfd_section (info
);
2507 /* If this is a virtual section we need to read in the real one first. */
2508 if (info
->is_virtual
)
2510 struct dwarf2_section_info
*containing_section
=
2511 get_containing_section (info
);
2513 gdb_assert (sectp
!= NULL
);
2514 if ((sectp
->flags
& SEC_RELOC
) != 0)
2516 error (_("Dwarf Error: DWP format V2 with relocations is not"
2517 " supported in section %s [in module %s]"),
2518 get_section_name (info
), get_section_file_name (info
));
2520 dwarf2_read_section (objfile
, containing_section
);
2521 /* Other code should have already caught virtual sections that don't
2523 gdb_assert (info
->virtual_offset
+ info
->size
2524 <= containing_section
->size
);
2525 /* If the real section is empty or there was a problem reading the
2526 section we shouldn't get here. */
2527 gdb_assert (containing_section
->buffer
!= NULL
);
2528 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2532 /* If the section has relocations, we must read it ourselves.
2533 Otherwise we attach it to the BFD. */
2534 if ((sectp
->flags
& SEC_RELOC
) == 0)
2536 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2540 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2543 /* When debugging .o files, we may need to apply relocations; see
2544 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2545 We never compress sections in .o files, so we only need to
2546 try this when the section is not compressed. */
2547 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2550 info
->buffer
= retbuf
;
2554 abfd
= get_section_bfd_owner (info
);
2555 gdb_assert (abfd
!= NULL
);
2557 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2558 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2560 error (_("Dwarf Error: Can't read DWARF data"
2561 " in section %s [in module %s]"),
2562 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2566 /* A helper function that returns the size of a section in a safe way.
2567 If you are positive that the section has been read before using the
2568 size, then it is safe to refer to the dwarf2_section_info object's
2569 "size" field directly. In other cases, you must call this
2570 function, because for compressed sections the size field is not set
2571 correctly until the section has been read. */
2573 static bfd_size_type
2574 dwarf2_section_size (struct objfile
*objfile
,
2575 struct dwarf2_section_info
*info
)
2578 dwarf2_read_section (objfile
, info
);
2582 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2586 dwarf2_get_section_info (struct objfile
*objfile
,
2587 enum dwarf2_section_enum sect
,
2588 asection
**sectp
, const gdb_byte
**bufp
,
2589 bfd_size_type
*sizep
)
2591 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2592 struct dwarf2_section_info
*info
;
2594 /* We may see an objfile without any DWARF, in which case we just
2605 case DWARF2_DEBUG_FRAME
:
2606 info
= &data
->frame
;
2608 case DWARF2_EH_FRAME
:
2609 info
= &data
->eh_frame
;
2612 gdb_assert_not_reached ("unexpected section");
2615 dwarf2_read_section (objfile
, info
);
2617 *sectp
= get_section_bfd_section (info
);
2618 *bufp
= info
->buffer
;
2619 *sizep
= info
->size
;
2622 /* A helper function to find the sections for a .dwz file. */
2625 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2627 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2629 /* Note that we only support the standard ELF names, because .dwz
2630 is ELF-only (at the time of writing). */
2631 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2633 dwz_file
->abbrev
.s
.section
= sectp
;
2634 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2636 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2638 dwz_file
->info
.s
.section
= sectp
;
2639 dwz_file
->info
.size
= bfd_section_size (sectp
);
2641 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2643 dwz_file
->str
.s
.section
= sectp
;
2644 dwz_file
->str
.size
= bfd_section_size (sectp
);
2646 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2648 dwz_file
->line
.s
.section
= sectp
;
2649 dwz_file
->line
.size
= bfd_section_size (sectp
);
2651 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2653 dwz_file
->macro
.s
.section
= sectp
;
2654 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2656 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2658 dwz_file
->gdb_index
.s
.section
= sectp
;
2659 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2661 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2663 dwz_file
->debug_names
.s
.section
= sectp
;
2664 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2668 /* See dwarf2read.h. */
2671 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2673 const char *filename
;
2674 bfd_size_type buildid_len_arg
;
2678 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2679 return dwarf2_per_objfile
->dwz_file
.get ();
2681 bfd_set_error (bfd_error_no_error
);
2682 gdb::unique_xmalloc_ptr
<char> data
2683 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2684 &buildid_len_arg
, &buildid
));
2687 if (bfd_get_error () == bfd_error_no_error
)
2689 error (_("could not read '.gnu_debugaltlink' section: %s"),
2690 bfd_errmsg (bfd_get_error ()));
2693 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2695 buildid_len
= (size_t) buildid_len_arg
;
2697 filename
= data
.get ();
2699 std::string abs_storage
;
2700 if (!IS_ABSOLUTE_PATH (filename
))
2702 gdb::unique_xmalloc_ptr
<char> abs
2703 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2705 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2706 filename
= abs_storage
.c_str ();
2709 /* First try the file name given in the section. If that doesn't
2710 work, try to use the build-id instead. */
2711 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2712 if (dwz_bfd
!= NULL
)
2714 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2715 dwz_bfd
.reset (nullptr);
2718 if (dwz_bfd
== NULL
)
2719 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2721 if (dwz_bfd
== NULL
)
2722 error (_("could not find '.gnu_debugaltlink' file for %s"),
2723 objfile_name (dwarf2_per_objfile
->objfile
));
2725 std::unique_ptr
<struct dwz_file
> result
2726 (new struct dwz_file (std::move (dwz_bfd
)));
2728 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2731 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2732 result
->dwz_bfd
.get ());
2733 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2734 return dwarf2_per_objfile
->dwz_file
.get ();
2737 /* DWARF quick_symbols_functions support. */
2739 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2740 unique line tables, so we maintain a separate table of all .debug_line
2741 derived entries to support the sharing.
2742 All the quick functions need is the list of file names. We discard the
2743 line_header when we're done and don't need to record it here. */
2744 struct quick_file_names
2746 /* The data used to construct the hash key. */
2747 struct stmt_list_hash hash
;
2749 /* The number of entries in file_names, real_names. */
2750 unsigned int num_file_names
;
2752 /* The file names from the line table, after being run through
2754 const char **file_names
;
2756 /* The file names from the line table after being run through
2757 gdb_realpath. These are computed lazily. */
2758 const char **real_names
;
2761 /* When using the index (and thus not using psymtabs), each CU has an
2762 object of this type. This is used to hold information needed by
2763 the various "quick" methods. */
2764 struct dwarf2_per_cu_quick_data
2766 /* The file table. This can be NULL if there was no file table
2767 or it's currently not read in.
2768 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2769 struct quick_file_names
*file_names
;
2771 /* The corresponding symbol table. This is NULL if symbols for this
2772 CU have not yet been read. */
2773 struct compunit_symtab
*compunit_symtab
;
2775 /* A temporary mark bit used when iterating over all CUs in
2776 expand_symtabs_matching. */
2777 unsigned int mark
: 1;
2779 /* True if we've tried to read the file table and found there isn't one.
2780 There will be no point in trying to read it again next time. */
2781 unsigned int no_file_data
: 1;
2784 /* Utility hash function for a stmt_list_hash. */
2787 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2791 if (stmt_list_hash
->dwo_unit
!= NULL
)
2792 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2793 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2797 /* Utility equality function for a stmt_list_hash. */
2800 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2801 const struct stmt_list_hash
*rhs
)
2803 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2805 if (lhs
->dwo_unit
!= NULL
2806 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2809 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2812 /* Hash function for a quick_file_names. */
2815 hash_file_name_entry (const void *e
)
2817 const struct quick_file_names
*file_data
2818 = (const struct quick_file_names
*) e
;
2820 return hash_stmt_list_entry (&file_data
->hash
);
2823 /* Equality function for a quick_file_names. */
2826 eq_file_name_entry (const void *a
, const void *b
)
2828 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2829 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2831 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2834 /* Delete function for a quick_file_names. */
2837 delete_file_name_entry (void *e
)
2839 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2842 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2844 xfree ((void*) file_data
->file_names
[i
]);
2845 if (file_data
->real_names
)
2846 xfree ((void*) file_data
->real_names
[i
]);
2849 /* The space for the struct itself lives on objfile_obstack,
2850 so we don't free it here. */
2853 /* Create a quick_file_names hash table. */
2856 create_quick_file_names_table (unsigned int nr_initial_entries
)
2858 return htab_create_alloc (nr_initial_entries
,
2859 hash_file_name_entry
, eq_file_name_entry
,
2860 delete_file_name_entry
, xcalloc
, xfree
);
2863 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2864 have to be created afterwards. You should call age_cached_comp_units after
2865 processing PER_CU->CU. dw2_setup must have been already called. */
2868 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2870 if (per_cu
->is_debug_types
)
2871 load_full_type_unit (per_cu
);
2873 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2875 if (per_cu
->cu
== NULL
)
2876 return; /* Dummy CU. */
2878 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2881 /* Read in the symbols for PER_CU. */
2884 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2886 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2888 /* Skip type_unit_groups, reading the type units they contain
2889 is handled elsewhere. */
2890 if (IS_TYPE_UNIT_GROUP (per_cu
))
2893 /* The destructor of dwarf2_queue_guard frees any entries left on
2894 the queue. After this point we're guaranteed to leave this function
2895 with the dwarf queue empty. */
2896 dwarf2_queue_guard q_guard
;
2898 if (dwarf2_per_objfile
->using_index
2899 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2900 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2902 queue_comp_unit (per_cu
, language_minimal
);
2903 load_cu (per_cu
, skip_partial
);
2905 /* If we just loaded a CU from a DWO, and we're working with an index
2906 that may badly handle TUs, load all the TUs in that DWO as well.
2907 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2908 if (!per_cu
->is_debug_types
2909 && per_cu
->cu
!= NULL
2910 && per_cu
->cu
->dwo_unit
!= NULL
2911 && dwarf2_per_objfile
->index_table
!= NULL
2912 && dwarf2_per_objfile
->index_table
->version
<= 7
2913 /* DWP files aren't supported yet. */
2914 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2915 queue_and_load_all_dwo_tus (per_cu
);
2918 process_queue (dwarf2_per_objfile
);
2920 /* Age the cache, releasing compilation units that have not
2921 been used recently. */
2922 age_cached_comp_units (dwarf2_per_objfile
);
2925 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2926 the objfile from which this CU came. Returns the resulting symbol
2929 static struct compunit_symtab
*
2930 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2932 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2934 gdb_assert (dwarf2_per_objfile
->using_index
);
2935 if (!per_cu
->v
.quick
->compunit_symtab
)
2937 free_cached_comp_units
freer (dwarf2_per_objfile
);
2938 scoped_restore decrementer
= increment_reading_symtab ();
2939 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2940 process_cu_includes (dwarf2_per_objfile
);
2943 return per_cu
->v
.quick
->compunit_symtab
;
2946 /* See declaration. */
2948 dwarf2_per_cu_data
*
2949 dwarf2_per_objfile::get_cutu (int index
)
2951 if (index
>= this->all_comp_units
.size ())
2953 index
-= this->all_comp_units
.size ();
2954 gdb_assert (index
< this->all_type_units
.size ());
2955 return &this->all_type_units
[index
]->per_cu
;
2958 return this->all_comp_units
[index
];
2961 /* See declaration. */
2963 dwarf2_per_cu_data
*
2964 dwarf2_per_objfile::get_cu (int index
)
2966 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2968 return this->all_comp_units
[index
];
2971 /* See declaration. */
2974 dwarf2_per_objfile::get_tu (int index
)
2976 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2978 return this->all_type_units
[index
];
2981 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2982 objfile_obstack, and constructed with the specified field
2985 static dwarf2_per_cu_data
*
2986 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2987 struct dwarf2_section_info
*section
,
2989 sect_offset sect_off
, ULONGEST length
)
2991 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2992 dwarf2_per_cu_data
*the_cu
2993 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2994 struct dwarf2_per_cu_data
);
2995 the_cu
->sect_off
= sect_off
;
2996 the_cu
->length
= length
;
2997 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2998 the_cu
->section
= section
;
2999 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3000 struct dwarf2_per_cu_quick_data
);
3001 the_cu
->is_dwz
= is_dwz
;
3005 /* A helper for create_cus_from_index that handles a given list of
3009 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3010 const gdb_byte
*cu_list
, offset_type n_elements
,
3011 struct dwarf2_section_info
*section
,
3014 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
3016 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3018 sect_offset sect_off
3019 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3020 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3023 dwarf2_per_cu_data
*per_cu
3024 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3026 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3030 /* Read the CU list from the mapped index, and use it to create all
3031 the CU objects for this objfile. */
3034 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3035 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3036 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3038 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3039 dwarf2_per_objfile
->all_comp_units
.reserve
3040 ((cu_list_elements
+ dwz_elements
) / 2);
3042 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3043 &dwarf2_per_objfile
->info
, 0);
3045 if (dwz_elements
== 0)
3048 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3049 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3053 /* Create the signatured type hash table from the index. */
3056 create_signatured_type_table_from_index
3057 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3058 struct dwarf2_section_info
*section
,
3059 const gdb_byte
*bytes
,
3060 offset_type elements
)
3062 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3064 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3065 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3067 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3069 for (offset_type i
= 0; i
< elements
; i
+= 3)
3071 struct signatured_type
*sig_type
;
3074 cu_offset type_offset_in_tu
;
3076 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3077 sect_offset sect_off
3078 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3080 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3082 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3085 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3086 struct signatured_type
);
3087 sig_type
->signature
= signature
;
3088 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3089 sig_type
->per_cu
.is_debug_types
= 1;
3090 sig_type
->per_cu
.section
= section
;
3091 sig_type
->per_cu
.sect_off
= sect_off
;
3092 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3093 sig_type
->per_cu
.v
.quick
3094 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3095 struct dwarf2_per_cu_quick_data
);
3097 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3100 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3103 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3106 /* Create the signatured type hash table from .debug_names. */
3109 create_signatured_type_table_from_debug_names
3110 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3111 const mapped_debug_names
&map
,
3112 struct dwarf2_section_info
*section
,
3113 struct dwarf2_section_info
*abbrev_section
)
3115 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3117 dwarf2_read_section (objfile
, section
);
3118 dwarf2_read_section (objfile
, abbrev_section
);
3120 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3121 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3123 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3125 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3127 struct signatured_type
*sig_type
;
3130 sect_offset sect_off
3131 = (sect_offset
) (extract_unsigned_integer
3132 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3134 map
.dwarf5_byte_order
));
3136 comp_unit_head cu_header
;
3137 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3139 section
->buffer
+ to_underlying (sect_off
),
3142 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3143 struct signatured_type
);
3144 sig_type
->signature
= cu_header
.signature
;
3145 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3146 sig_type
->per_cu
.is_debug_types
= 1;
3147 sig_type
->per_cu
.section
= section
;
3148 sig_type
->per_cu
.sect_off
= sect_off
;
3149 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3150 sig_type
->per_cu
.v
.quick
3151 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3152 struct dwarf2_per_cu_quick_data
);
3154 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3157 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3160 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3163 /* Read the address map data from the mapped index, and use it to
3164 populate the objfile's psymtabs_addrmap. */
3167 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3168 struct mapped_index
*index
)
3170 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3171 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3172 const gdb_byte
*iter
, *end
;
3173 struct addrmap
*mutable_map
;
3176 auto_obstack temp_obstack
;
3178 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3180 iter
= index
->address_table
.data ();
3181 end
= iter
+ index
->address_table
.size ();
3183 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3187 ULONGEST hi
, lo
, cu_index
;
3188 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3190 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3192 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3197 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3198 hex_string (lo
), hex_string (hi
));
3202 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3204 complaint (_(".gdb_index address table has invalid CU number %u"),
3205 (unsigned) cu_index
);
3209 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3210 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3211 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3212 dwarf2_per_objfile
->get_cu (cu_index
));
3215 objfile
->partial_symtabs
->psymtabs_addrmap
3216 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3219 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3220 populate the objfile's psymtabs_addrmap. */
3223 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3224 struct dwarf2_section_info
*section
)
3226 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3227 bfd
*abfd
= objfile
->obfd
;
3228 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3229 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3230 SECT_OFF_TEXT (objfile
));
3232 auto_obstack temp_obstack
;
3233 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3235 std::unordered_map
<sect_offset
,
3236 dwarf2_per_cu_data
*,
3237 gdb::hash_enum
<sect_offset
>>
3238 debug_info_offset_to_per_cu
;
3239 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3241 const auto insertpair
3242 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3243 if (!insertpair
.second
)
3245 warning (_("Section .debug_aranges in %s has duplicate "
3246 "debug_info_offset %s, ignoring .debug_aranges."),
3247 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3252 dwarf2_read_section (objfile
, section
);
3254 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3256 const gdb_byte
*addr
= section
->buffer
;
3258 while (addr
< section
->buffer
+ section
->size
)
3260 const gdb_byte
*const entry_addr
= addr
;
3261 unsigned int bytes_read
;
3263 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3267 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3268 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3269 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3270 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3272 warning (_("Section .debug_aranges in %s entry at offset %s "
3273 "length %s exceeds section length %s, "
3274 "ignoring .debug_aranges."),
3275 objfile_name (objfile
),
3276 plongest (entry_addr
- section
->buffer
),
3277 plongest (bytes_read
+ entry_length
),
3278 pulongest (section
->size
));
3282 /* The version number. */
3283 const uint16_t version
= read_2_bytes (abfd
, addr
);
3287 warning (_("Section .debug_aranges in %s entry at offset %s "
3288 "has unsupported version %d, ignoring .debug_aranges."),
3289 objfile_name (objfile
),
3290 plongest (entry_addr
- section
->buffer
), version
);
3294 const uint64_t debug_info_offset
3295 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3296 addr
+= offset_size
;
3297 const auto per_cu_it
3298 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3299 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3301 warning (_("Section .debug_aranges in %s entry at offset %s "
3302 "debug_info_offset %s does not exists, "
3303 "ignoring .debug_aranges."),
3304 objfile_name (objfile
),
3305 plongest (entry_addr
- section
->buffer
),
3306 pulongest (debug_info_offset
));
3309 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3311 const uint8_t address_size
= *addr
++;
3312 if (address_size
< 1 || address_size
> 8)
3314 warning (_("Section .debug_aranges in %s entry at offset %s "
3315 "address_size %u is invalid, ignoring .debug_aranges."),
3316 objfile_name (objfile
),
3317 plongest (entry_addr
- section
->buffer
), address_size
);
3321 const uint8_t segment_selector_size
= *addr
++;
3322 if (segment_selector_size
!= 0)
3324 warning (_("Section .debug_aranges in %s entry at offset %s "
3325 "segment_selector_size %u is not supported, "
3326 "ignoring .debug_aranges."),
3327 objfile_name (objfile
),
3328 plongest (entry_addr
- section
->buffer
),
3329 segment_selector_size
);
3333 /* Must pad to an alignment boundary that is twice the address
3334 size. It is undocumented by the DWARF standard but GCC does
3336 for (size_t padding
= ((-(addr
- section
->buffer
))
3337 & (2 * address_size
- 1));
3338 padding
> 0; padding
--)
3341 warning (_("Section .debug_aranges in %s entry at offset %s "
3342 "padding is not zero, ignoring .debug_aranges."),
3343 objfile_name (objfile
),
3344 plongest (entry_addr
- section
->buffer
));
3350 if (addr
+ 2 * address_size
> entry_end
)
3352 warning (_("Section .debug_aranges in %s entry at offset %s "
3353 "address list is not properly terminated, "
3354 "ignoring .debug_aranges."),
3355 objfile_name (objfile
),
3356 plongest (entry_addr
- section
->buffer
));
3359 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3361 addr
+= address_size
;
3362 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3364 addr
+= address_size
;
3365 if (start
== 0 && length
== 0)
3367 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3369 /* Symbol was eliminated due to a COMDAT group. */
3372 ULONGEST end
= start
+ length
;
3373 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3375 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3377 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3381 objfile
->partial_symtabs
->psymtabs_addrmap
3382 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3385 /* Find a slot in the mapped index INDEX for the object named NAME.
3386 If NAME is found, set *VEC_OUT to point to the CU vector in the
3387 constant pool and return true. If NAME cannot be found, return
3391 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3392 offset_type
**vec_out
)
3395 offset_type slot
, step
;
3396 int (*cmp
) (const char *, const char *);
3398 gdb::unique_xmalloc_ptr
<char> without_params
;
3399 if (current_language
->la_language
== language_cplus
3400 || current_language
->la_language
== language_fortran
3401 || current_language
->la_language
== language_d
)
3403 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3406 if (strchr (name
, '(') != NULL
)
3408 without_params
= cp_remove_params (name
);
3410 if (without_params
!= NULL
)
3411 name
= without_params
.get ();
3415 /* Index version 4 did not support case insensitive searches. But the
3416 indices for case insensitive languages are built in lowercase, therefore
3417 simulate our NAME being searched is also lowercased. */
3418 hash
= mapped_index_string_hash ((index
->version
== 4
3419 && case_sensitivity
== case_sensitive_off
3420 ? 5 : index
->version
),
3423 slot
= hash
& (index
->symbol_table
.size () - 1);
3424 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3425 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3431 const auto &bucket
= index
->symbol_table
[slot
];
3432 if (bucket
.name
== 0 && bucket
.vec
== 0)
3435 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3436 if (!cmp (name
, str
))
3438 *vec_out
= (offset_type
*) (index
->constant_pool
3439 + MAYBE_SWAP (bucket
.vec
));
3443 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3447 /* A helper function that reads the .gdb_index from BUFFER and fills
3448 in MAP. FILENAME is the name of the file containing the data;
3449 it is used for error reporting. DEPRECATED_OK is true if it is
3450 ok to use deprecated sections.
3452 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3453 out parameters that are filled in with information about the CU and
3454 TU lists in the section.
3456 Returns true if all went well, false otherwise. */
3459 read_gdb_index_from_buffer (struct objfile
*objfile
,
3460 const char *filename
,
3462 gdb::array_view
<const gdb_byte
> buffer
,
3463 struct mapped_index
*map
,
3464 const gdb_byte
**cu_list
,
3465 offset_type
*cu_list_elements
,
3466 const gdb_byte
**types_list
,
3467 offset_type
*types_list_elements
)
3469 const gdb_byte
*addr
= &buffer
[0];
3471 /* Version check. */
3472 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3473 /* Versions earlier than 3 emitted every copy of a psymbol. This
3474 causes the index to behave very poorly for certain requests. Version 3
3475 contained incomplete addrmap. So, it seems better to just ignore such
3479 static int warning_printed
= 0;
3480 if (!warning_printed
)
3482 warning (_("Skipping obsolete .gdb_index section in %s."),
3484 warning_printed
= 1;
3488 /* Index version 4 uses a different hash function than index version
3491 Versions earlier than 6 did not emit psymbols for inlined
3492 functions. Using these files will cause GDB not to be able to
3493 set breakpoints on inlined functions by name, so we ignore these
3494 indices unless the user has done
3495 "set use-deprecated-index-sections on". */
3496 if (version
< 6 && !deprecated_ok
)
3498 static int warning_printed
= 0;
3499 if (!warning_printed
)
3502 Skipping deprecated .gdb_index section in %s.\n\
3503 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3504 to use the section anyway."),
3506 warning_printed
= 1;
3510 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3511 of the TU (for symbols coming from TUs),
3512 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3513 Plus gold-generated indices can have duplicate entries for global symbols,
3514 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3515 These are just performance bugs, and we can't distinguish gdb-generated
3516 indices from gold-generated ones, so issue no warning here. */
3518 /* Indexes with higher version than the one supported by GDB may be no
3519 longer backward compatible. */
3523 map
->version
= version
;
3525 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3528 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3529 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3533 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3534 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3535 - MAYBE_SWAP (metadata
[i
]))
3539 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3540 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3542 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3545 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3546 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3548 = gdb::array_view
<mapped_index::symbol_table_slot
>
3549 ((mapped_index::symbol_table_slot
*) symbol_table
,
3550 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3553 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3558 /* Callback types for dwarf2_read_gdb_index. */
3560 typedef gdb::function_view
3561 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3562 get_gdb_index_contents_ftype
;
3563 typedef gdb::function_view
3564 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3565 get_gdb_index_contents_dwz_ftype
;
3567 /* Read .gdb_index. If everything went ok, initialize the "quick"
3568 elements of all the CUs and return 1. Otherwise, return 0. */
3571 dwarf2_read_gdb_index
3572 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3573 get_gdb_index_contents_ftype get_gdb_index_contents
,
3574 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3576 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3577 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3578 struct dwz_file
*dwz
;
3579 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3581 gdb::array_view
<const gdb_byte
> main_index_contents
3582 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3584 if (main_index_contents
.empty ())
3587 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3588 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3589 use_deprecated_index_sections
,
3590 main_index_contents
, map
.get (), &cu_list
,
3591 &cu_list_elements
, &types_list
,
3592 &types_list_elements
))
3595 /* Don't use the index if it's empty. */
3596 if (map
->symbol_table
.empty ())
3599 /* If there is a .dwz file, read it so we can get its CU list as
3601 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3604 struct mapped_index dwz_map
;
3605 const gdb_byte
*dwz_types_ignore
;
3606 offset_type dwz_types_elements_ignore
;
3608 gdb::array_view
<const gdb_byte
> dwz_index_content
3609 = get_gdb_index_contents_dwz (objfile
, dwz
);
3611 if (dwz_index_content
.empty ())
3614 if (!read_gdb_index_from_buffer (objfile
,
3615 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3616 1, dwz_index_content
, &dwz_map
,
3617 &dwz_list
, &dwz_list_elements
,
3619 &dwz_types_elements_ignore
))
3621 warning (_("could not read '.gdb_index' section from %s; skipping"),
3622 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3627 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3628 dwz_list
, dwz_list_elements
);
3630 if (types_list_elements
)
3632 /* We can only handle a single .debug_types when we have an
3634 if (dwarf2_per_objfile
->types
.size () != 1)
3637 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3639 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3640 types_list
, types_list_elements
);
3643 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3645 dwarf2_per_objfile
->index_table
= std::move (map
);
3646 dwarf2_per_objfile
->using_index
= 1;
3647 dwarf2_per_objfile
->quick_file_names_table
=
3648 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3653 /* die_reader_func for dw2_get_file_names. */
3656 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3657 const gdb_byte
*info_ptr
,
3658 struct die_info
*comp_unit_die
,
3662 struct dwarf2_cu
*cu
= reader
->cu
;
3663 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3664 struct dwarf2_per_objfile
*dwarf2_per_objfile
3665 = cu
->per_cu
->dwarf2_per_objfile
;
3666 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3667 struct dwarf2_per_cu_data
*lh_cu
;
3668 struct attribute
*attr
;
3670 struct quick_file_names
*qfn
;
3672 gdb_assert (! this_cu
->is_debug_types
);
3674 /* Our callers never want to match partial units -- instead they
3675 will match the enclosing full CU. */
3676 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3678 this_cu
->v
.quick
->no_file_data
= 1;
3686 sect_offset line_offset
{};
3688 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3689 if (attr
!= nullptr)
3691 struct quick_file_names find_entry
;
3693 line_offset
= (sect_offset
) DW_UNSND (attr
);
3695 /* We may have already read in this line header (TU line header sharing).
3696 If we have we're done. */
3697 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3698 find_entry
.hash
.line_sect_off
= line_offset
;
3699 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3700 &find_entry
, INSERT
);
3703 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3707 lh
= dwarf_decode_line_header (line_offset
, cu
);
3711 lh_cu
->v
.quick
->no_file_data
= 1;
3715 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3716 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3717 qfn
->hash
.line_sect_off
= line_offset
;
3718 gdb_assert (slot
!= NULL
);
3721 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3724 if (strcmp (fnd
.name
, "<unknown>") != 0)
3727 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3729 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3731 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3732 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3733 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3734 qfn
->real_names
= NULL
;
3736 lh_cu
->v
.quick
->file_names
= qfn
;
3739 /* A helper for the "quick" functions which attempts to read the line
3740 table for THIS_CU. */
3742 static struct quick_file_names
*
3743 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3745 /* This should never be called for TUs. */
3746 gdb_assert (! this_cu
->is_debug_types
);
3747 /* Nor type unit groups. */
3748 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3750 if (this_cu
->v
.quick
->file_names
!= NULL
)
3751 return this_cu
->v
.quick
->file_names
;
3752 /* If we know there is no line data, no point in looking again. */
3753 if (this_cu
->v
.quick
->no_file_data
)
3756 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3758 if (this_cu
->v
.quick
->no_file_data
)
3760 return this_cu
->v
.quick
->file_names
;
3763 /* A helper for the "quick" functions which computes and caches the
3764 real path for a given file name from the line table. */
3767 dw2_get_real_path (struct objfile
*objfile
,
3768 struct quick_file_names
*qfn
, int index
)
3770 if (qfn
->real_names
== NULL
)
3771 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3772 qfn
->num_file_names
, const char *);
3774 if (qfn
->real_names
[index
] == NULL
)
3775 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3777 return qfn
->real_names
[index
];
3780 static struct symtab
*
3781 dw2_find_last_source_symtab (struct objfile
*objfile
)
3783 struct dwarf2_per_objfile
*dwarf2_per_objfile
3784 = get_dwarf2_per_objfile (objfile
);
3785 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3786 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3791 return compunit_primary_filetab (cust
);
3794 /* Traversal function for dw2_forget_cached_source_info. */
3797 dw2_free_cached_file_names (void **slot
, void *info
)
3799 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3801 if (file_data
->real_names
)
3805 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3807 xfree ((void*) file_data
->real_names
[i
]);
3808 file_data
->real_names
[i
] = NULL
;
3816 dw2_forget_cached_source_info (struct objfile
*objfile
)
3818 struct dwarf2_per_objfile
*dwarf2_per_objfile
3819 = get_dwarf2_per_objfile (objfile
);
3821 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3822 dw2_free_cached_file_names
, NULL
);
3825 /* Helper function for dw2_map_symtabs_matching_filename that expands
3826 the symtabs and calls the iterator. */
3829 dw2_map_expand_apply (struct objfile
*objfile
,
3830 struct dwarf2_per_cu_data
*per_cu
,
3831 const char *name
, const char *real_path
,
3832 gdb::function_view
<bool (symtab
*)> callback
)
3834 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3836 /* Don't visit already-expanded CUs. */
3837 if (per_cu
->v
.quick
->compunit_symtab
)
3840 /* This may expand more than one symtab, and we want to iterate over
3842 dw2_instantiate_symtab (per_cu
, false);
3844 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3845 last_made
, callback
);
3848 /* Implementation of the map_symtabs_matching_filename method. */
3851 dw2_map_symtabs_matching_filename
3852 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3853 gdb::function_view
<bool (symtab
*)> callback
)
3855 const char *name_basename
= lbasename (name
);
3856 struct dwarf2_per_objfile
*dwarf2_per_objfile
3857 = get_dwarf2_per_objfile (objfile
);
3859 /* The rule is CUs specify all the files, including those used by
3860 any TU, so there's no need to scan TUs here. */
3862 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3864 /* We only need to look at symtabs not already expanded. */
3865 if (per_cu
->v
.quick
->compunit_symtab
)
3868 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3869 if (file_data
== NULL
)
3872 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3874 const char *this_name
= file_data
->file_names
[j
];
3875 const char *this_real_name
;
3877 if (compare_filenames_for_search (this_name
, name
))
3879 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3885 /* Before we invoke realpath, which can get expensive when many
3886 files are involved, do a quick comparison of the basenames. */
3887 if (! basenames_may_differ
3888 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3891 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3892 if (compare_filenames_for_search (this_real_name
, name
))
3894 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3900 if (real_path
!= NULL
)
3902 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3903 gdb_assert (IS_ABSOLUTE_PATH (name
));
3904 if (this_real_name
!= NULL
3905 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3907 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3919 /* Struct used to manage iterating over all CUs looking for a symbol. */
3921 struct dw2_symtab_iterator
3923 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3924 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3925 /* If set, only look for symbols that match that block. Valid values are
3926 GLOBAL_BLOCK and STATIC_BLOCK. */
3927 gdb::optional
<block_enum
> block_index
;
3928 /* The kind of symbol we're looking for. */
3930 /* The list of CUs from the index entry of the symbol,
3931 or NULL if not found. */
3933 /* The next element in VEC to look at. */
3935 /* The number of elements in VEC, or zero if there is no match. */
3937 /* Have we seen a global version of the symbol?
3938 If so we can ignore all further global instances.
3939 This is to work around gold/15646, inefficient gold-generated
3944 /* Initialize the index symtab iterator ITER. */
3947 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3948 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3949 gdb::optional
<block_enum
> block_index
,
3953 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3954 iter
->block_index
= block_index
;
3955 iter
->domain
= domain
;
3957 iter
->global_seen
= 0;
3959 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3961 /* index is NULL if OBJF_READNOW. */
3962 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3963 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3971 /* Return the next matching CU or NULL if there are no more. */
3973 static struct dwarf2_per_cu_data
*
3974 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3976 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3978 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3980 offset_type cu_index_and_attrs
=
3981 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3982 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3983 gdb_index_symbol_kind symbol_kind
=
3984 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3985 /* Only check the symbol attributes if they're present.
3986 Indices prior to version 7 don't record them,
3987 and indices >= 7 may elide them for certain symbols
3988 (gold does this). */
3990 (dwarf2_per_objfile
->index_table
->version
>= 7
3991 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3993 /* Don't crash on bad data. */
3994 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3995 + dwarf2_per_objfile
->all_type_units
.size ()))
3997 complaint (_(".gdb_index entry has bad CU index"
3999 objfile_name (dwarf2_per_objfile
->objfile
));
4003 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4005 /* Skip if already read in. */
4006 if (per_cu
->v
.quick
->compunit_symtab
)
4009 /* Check static vs global. */
4012 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4014 if (iter
->block_index
.has_value ())
4016 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
4018 if (is_static
!= want_static
)
4022 /* Work around gold/15646. */
4023 if (!is_static
&& iter
->global_seen
)
4026 iter
->global_seen
= 1;
4029 /* Only check the symbol's kind if it has one. */
4032 switch (iter
->domain
)
4035 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4036 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4037 /* Some types are also in VAR_DOMAIN. */
4038 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4042 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4046 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4050 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4065 static struct compunit_symtab
*
4066 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4067 const char *name
, domain_enum domain
)
4069 struct compunit_symtab
*stab_best
= NULL
;
4070 struct dwarf2_per_objfile
*dwarf2_per_objfile
4071 = get_dwarf2_per_objfile (objfile
);
4073 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4075 struct dw2_symtab_iterator iter
;
4076 struct dwarf2_per_cu_data
*per_cu
;
4078 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4080 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4082 struct symbol
*sym
, *with_opaque
= NULL
;
4083 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4084 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4085 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4087 sym
= block_find_symbol (block
, name
, domain
,
4088 block_find_non_opaque_type_preferred
,
4091 /* Some caution must be observed with overloaded functions
4092 and methods, since the index will not contain any overload
4093 information (but NAME might contain it). */
4096 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4098 if (with_opaque
!= NULL
4099 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4102 /* Keep looking through other CUs. */
4109 dw2_print_stats (struct objfile
*objfile
)
4111 struct dwarf2_per_objfile
*dwarf2_per_objfile
4112 = get_dwarf2_per_objfile (objfile
);
4113 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4114 + dwarf2_per_objfile
->all_type_units
.size ());
4117 for (int i
= 0; i
< total
; ++i
)
4119 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4121 if (!per_cu
->v
.quick
->compunit_symtab
)
4124 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4125 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4128 /* This dumps minimal information about the index.
4129 It is called via "mt print objfiles".
4130 One use is to verify .gdb_index has been loaded by the
4131 gdb.dwarf2/gdb-index.exp testcase. */
4134 dw2_dump (struct objfile
*objfile
)
4136 struct dwarf2_per_objfile
*dwarf2_per_objfile
4137 = get_dwarf2_per_objfile (objfile
);
4139 gdb_assert (dwarf2_per_objfile
->using_index
);
4140 printf_filtered (".gdb_index:");
4141 if (dwarf2_per_objfile
->index_table
!= NULL
)
4143 printf_filtered (" version %d\n",
4144 dwarf2_per_objfile
->index_table
->version
);
4147 printf_filtered (" faked for \"readnow\"\n");
4148 printf_filtered ("\n");
4152 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4153 const char *func_name
)
4155 struct dwarf2_per_objfile
*dwarf2_per_objfile
4156 = get_dwarf2_per_objfile (objfile
);
4158 struct dw2_symtab_iterator iter
;
4159 struct dwarf2_per_cu_data
*per_cu
;
4161 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4163 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4164 dw2_instantiate_symtab (per_cu
, false);
4169 dw2_expand_all_symtabs (struct objfile
*objfile
)
4171 struct dwarf2_per_objfile
*dwarf2_per_objfile
4172 = get_dwarf2_per_objfile (objfile
);
4173 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4174 + dwarf2_per_objfile
->all_type_units
.size ());
4176 for (int i
= 0; i
< total_units
; ++i
)
4178 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4180 /* We don't want to directly expand a partial CU, because if we
4181 read it with the wrong language, then assertion failures can
4182 be triggered later on. See PR symtab/23010. So, tell
4183 dw2_instantiate_symtab to skip partial CUs -- any important
4184 partial CU will be read via DW_TAG_imported_unit anyway. */
4185 dw2_instantiate_symtab (per_cu
, true);
4190 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4191 const char *fullname
)
4193 struct dwarf2_per_objfile
*dwarf2_per_objfile
4194 = get_dwarf2_per_objfile (objfile
);
4196 /* We don't need to consider type units here.
4197 This is only called for examining code, e.g. expand_line_sal.
4198 There can be an order of magnitude (or more) more type units
4199 than comp units, and we avoid them if we can. */
4201 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4203 /* We only need to look at symtabs not already expanded. */
4204 if (per_cu
->v
.quick
->compunit_symtab
)
4207 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4208 if (file_data
== NULL
)
4211 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4213 const char *this_fullname
= file_data
->file_names
[j
];
4215 if (filename_cmp (this_fullname
, fullname
) == 0)
4217 dw2_instantiate_symtab (per_cu
, false);
4225 dw2_map_matching_symbols
4226 (struct objfile
*objfile
,
4227 const lookup_name_info
&name
, domain_enum domain
,
4229 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4230 symbol_compare_ftype
*ordered_compare
)
4232 /* Currently unimplemented; used for Ada. The function can be called if the
4233 current language is Ada for a non-Ada objfile using GNU index. As Ada
4234 does not look for non-Ada symbols this function should just return. */
4237 /* Starting from a search name, return the string that finds the upper
4238 bound of all strings that start with SEARCH_NAME in a sorted name
4239 list. Returns the empty string to indicate that the upper bound is
4240 the end of the list. */
4243 make_sort_after_prefix_name (const char *search_name
)
4245 /* When looking to complete "func", we find the upper bound of all
4246 symbols that start with "func" by looking for where we'd insert
4247 the closest string that would follow "func" in lexicographical
4248 order. Usually, that's "func"-with-last-character-incremented,
4249 i.e. "fund". Mind non-ASCII characters, though. Usually those
4250 will be UTF-8 multi-byte sequences, but we can't be certain.
4251 Especially mind the 0xff character, which is a valid character in
4252 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4253 rule out compilers allowing it in identifiers. Note that
4254 conveniently, strcmp/strcasecmp are specified to compare
4255 characters interpreted as unsigned char. So what we do is treat
4256 the whole string as a base 256 number composed of a sequence of
4257 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4258 to 0, and carries 1 to the following more-significant position.
4259 If the very first character in SEARCH_NAME ends up incremented
4260 and carries/overflows, then the upper bound is the end of the
4261 list. The string after the empty string is also the empty
4264 Some examples of this operation:
4266 SEARCH_NAME => "+1" RESULT
4270 "\xff" "a" "\xff" => "\xff" "b"
4275 Then, with these symbols for example:
4281 completing "func" looks for symbols between "func" and
4282 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4283 which finds "func" and "func1", but not "fund".
4287 funcÿ (Latin1 'ÿ' [0xff])
4291 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4292 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4296 ÿÿ (Latin1 'ÿ' [0xff])
4299 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4300 the end of the list.
4302 std::string after
= search_name
;
4303 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4305 if (!after
.empty ())
4306 after
.back () = (unsigned char) after
.back () + 1;
4310 /* See declaration. */
4312 std::pair
<std::vector
<name_component
>::const_iterator
,
4313 std::vector
<name_component
>::const_iterator
>
4314 mapped_index_base::find_name_components_bounds
4315 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4318 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4320 const char *lang_name
4321 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4323 /* Comparison function object for lower_bound that matches against a
4324 given symbol name. */
4325 auto lookup_compare_lower
= [&] (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 (elem_name
, name
) < 0;
4333 /* Comparison function object for upper_bound that matches against a
4334 given symbol name. */
4335 auto lookup_compare_upper
= [&] (const char *name
,
4336 const name_component
&elem
)
4338 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4339 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4340 return name_cmp (name
, elem_name
) < 0;
4343 auto begin
= this->name_components
.begin ();
4344 auto end
= this->name_components
.end ();
4346 /* Find the lower bound. */
4349 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4352 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4355 /* Find the upper bound. */
4358 if (lookup_name_without_params
.completion_mode ())
4360 /* In completion mode, we want UPPER to point past all
4361 symbols names that have the same prefix. I.e., with
4362 these symbols, and completing "func":
4364 function << lower bound
4366 other_function << upper bound
4368 We find the upper bound by looking for the insertion
4369 point of "func"-with-last-character-incremented,
4371 std::string after
= make_sort_after_prefix_name (lang_name
);
4374 return std::lower_bound (lower
, end
, after
.c_str (),
4375 lookup_compare_lower
);
4378 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4381 return {lower
, upper
};
4384 /* See declaration. */
4387 mapped_index_base::build_name_components ()
4389 if (!this->name_components
.empty ())
4392 this->name_components_casing
= case_sensitivity
;
4394 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4396 /* The code below only knows how to break apart components of C++
4397 symbol names (and other languages that use '::' as
4398 namespace/module separator) and Ada symbol names. */
4399 auto count
= this->symbol_name_count ();
4400 for (offset_type idx
= 0; idx
< count
; idx
++)
4402 if (this->symbol_name_slot_invalid (idx
))
4405 const char *name
= this->symbol_name_at (idx
);
4407 /* Add each name component to the name component table. */
4408 unsigned int previous_len
= 0;
4410 if (strstr (name
, "::") != nullptr)
4412 for (unsigned int current_len
= cp_find_first_component (name
);
4413 name
[current_len
] != '\0';
4414 current_len
+= cp_find_first_component (name
+ current_len
))
4416 gdb_assert (name
[current_len
] == ':');
4417 this->name_components
.push_back ({previous_len
, idx
});
4418 /* Skip the '::'. */
4420 previous_len
= current_len
;
4425 /* Handle the Ada encoded (aka mangled) form here. */
4426 for (const char *iter
= strstr (name
, "__");
4428 iter
= strstr (iter
, "__"))
4430 this->name_components
.push_back ({previous_len
, idx
});
4432 previous_len
= iter
- name
;
4436 this->name_components
.push_back ({previous_len
, idx
});
4439 /* Sort name_components elements by name. */
4440 auto name_comp_compare
= [&] (const name_component
&left
,
4441 const name_component
&right
)
4443 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4444 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4446 const char *left_name
= left_qualified
+ left
.name_offset
;
4447 const char *right_name
= right_qualified
+ right
.name_offset
;
4449 return name_cmp (left_name
, right_name
) < 0;
4452 std::sort (this->name_components
.begin (),
4453 this->name_components
.end (),
4457 /* Helper for dw2_expand_symtabs_matching that works with a
4458 mapped_index_base instead of the containing objfile. This is split
4459 to a separate function in order to be able to unit test the
4460 name_components matching using a mock mapped_index_base. For each
4461 symbol name that matches, calls MATCH_CALLBACK, passing it the
4462 symbol's index in the mapped_index_base symbol table. */
4465 dw2_expand_symtabs_matching_symbol
4466 (mapped_index_base
&index
,
4467 const lookup_name_info
&lookup_name_in
,
4468 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4469 enum search_domain kind
,
4470 gdb::function_view
<bool (offset_type
)> match_callback
)
4472 lookup_name_info lookup_name_without_params
4473 = lookup_name_in
.make_ignore_params ();
4475 /* Build the symbol name component sorted vector, if we haven't
4477 index
.build_name_components ();
4479 /* The same symbol may appear more than once in the range though.
4480 E.g., if we're looking for symbols that complete "w", and we have
4481 a symbol named "w1::w2", we'll find the two name components for
4482 that same symbol in the range. To be sure we only call the
4483 callback once per symbol, we first collect the symbol name
4484 indexes that matched in a temporary vector and ignore
4486 std::vector
<offset_type
> matches
;
4488 struct name_and_matcher
4490 symbol_name_matcher_ftype
*matcher
;
4491 const std::string
&name
;
4493 bool operator== (const name_and_matcher
&other
) const
4495 return matcher
== other
.matcher
&& name
== other
.name
;
4499 /* A vector holding all the different symbol name matchers, for all
4501 std::vector
<name_and_matcher
> matchers
;
4503 for (int i
= 0; i
< nr_languages
; i
++)
4505 enum language lang_e
= (enum language
) i
;
4507 const language_defn
*lang
= language_def (lang_e
);
4508 symbol_name_matcher_ftype
*name_matcher
4509 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4511 name_and_matcher key
{
4513 lookup_name_without_params
.language_lookup_name (lang_e
)
4516 /* Don't insert the same comparison routine more than once.
4517 Note that we do this linear walk. This is not a problem in
4518 practice because the number of supported languages is
4520 if (std::find (matchers
.begin (), matchers
.end (), key
)
4523 matchers
.push_back (std::move (key
));
4526 = index
.find_name_components_bounds (lookup_name_without_params
,
4529 /* Now for each symbol name in range, check to see if we have a name
4530 match, and if so, call the MATCH_CALLBACK callback. */
4532 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4534 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4536 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4537 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4540 matches
.push_back (bounds
.first
->idx
);
4544 std::sort (matches
.begin (), matches
.end ());
4546 /* Finally call the callback, once per match. */
4548 for (offset_type idx
: matches
)
4552 if (!match_callback (idx
))
4558 /* Above we use a type wider than idx's for 'prev', since 0 and
4559 (offset_type)-1 are both possible values. */
4560 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4565 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4567 /* A mock .gdb_index/.debug_names-like name index table, enough to
4568 exercise dw2_expand_symtabs_matching_symbol, which works with the
4569 mapped_index_base interface. Builds an index from the symbol list
4570 passed as parameter to the constructor. */
4571 class mock_mapped_index
: public mapped_index_base
4574 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4575 : m_symbol_table (symbols
)
4578 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4580 /* Return the number of names in the symbol table. */
4581 size_t symbol_name_count () const override
4583 return m_symbol_table
.size ();
4586 /* Get the name of the symbol at IDX in the symbol table. */
4587 const char *symbol_name_at (offset_type idx
) const override
4589 return m_symbol_table
[idx
];
4593 gdb::array_view
<const char *> m_symbol_table
;
4596 /* Convenience function that converts a NULL pointer to a "<null>"
4597 string, to pass to print routines. */
4600 string_or_null (const char *str
)
4602 return str
!= NULL
? str
: "<null>";
4605 /* Check if a lookup_name_info built from
4606 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4607 index. EXPECTED_LIST is the list of expected matches, in expected
4608 matching order. If no match expected, then an empty list is
4609 specified. Returns true on success. On failure prints a warning
4610 indicating the file:line that failed, and returns false. */
4613 check_match (const char *file
, int line
,
4614 mock_mapped_index
&mock_index
,
4615 const char *name
, symbol_name_match_type match_type
,
4616 bool completion_mode
,
4617 std::initializer_list
<const char *> expected_list
)
4619 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4621 bool matched
= true;
4623 auto mismatch
= [&] (const char *expected_str
,
4626 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4627 "expected=\"%s\", got=\"%s\"\n"),
4629 (match_type
== symbol_name_match_type::FULL
4631 name
, string_or_null (expected_str
), string_or_null (got
));
4635 auto expected_it
= expected_list
.begin ();
4636 auto expected_end
= expected_list
.end ();
4638 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4640 [&] (offset_type idx
)
4642 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4643 const char *expected_str
4644 = expected_it
== expected_end
? NULL
: *expected_it
++;
4646 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4647 mismatch (expected_str
, matched_name
);
4651 const char *expected_str
4652 = expected_it
== expected_end
? NULL
: *expected_it
++;
4653 if (expected_str
!= NULL
)
4654 mismatch (expected_str
, NULL
);
4659 /* The symbols added to the mock mapped_index for testing (in
4661 static const char *test_symbols
[] = {
4670 "ns2::tmpl<int>::foo2",
4671 "(anonymous namespace)::A::B::C",
4673 /* These are used to check that the increment-last-char in the
4674 matching algorithm for completion doesn't match "t1_fund" when
4675 completing "t1_func". */
4681 /* A UTF-8 name with multi-byte sequences to make sure that
4682 cp-name-parser understands this as a single identifier ("função"
4683 is "function" in PT). */
4686 /* \377 (0xff) is Latin1 'ÿ'. */
4689 /* \377 (0xff) is Latin1 'ÿ'. */
4693 /* A name with all sorts of complications. Starts with "z" to make
4694 it easier for the completion tests below. */
4695 #define Z_SYM_NAME \
4696 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4697 "::tuple<(anonymous namespace)::ui*, " \
4698 "std::default_delete<(anonymous namespace)::ui>, void>"
4703 /* Returns true if the mapped_index_base::find_name_component_bounds
4704 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4705 in completion mode. */
4708 check_find_bounds_finds (mapped_index_base
&index
,
4709 const char *search_name
,
4710 gdb::array_view
<const char *> expected_syms
)
4712 lookup_name_info
lookup_name (search_name
,
4713 symbol_name_match_type::FULL
, true);
4715 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4718 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4719 if (distance
!= expected_syms
.size ())
4722 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4724 auto nc_elem
= bounds
.first
+ exp_elem
;
4725 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4726 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4733 /* Test the lower-level mapped_index::find_name_component_bounds
4737 test_mapped_index_find_name_component_bounds ()
4739 mock_mapped_index
mock_index (test_symbols
);
4741 mock_index
.build_name_components ();
4743 /* Test the lower-level mapped_index::find_name_component_bounds
4744 method in completion mode. */
4746 static const char *expected_syms
[] = {
4751 SELF_CHECK (check_find_bounds_finds (mock_index
,
4752 "t1_func", expected_syms
));
4755 /* Check that the increment-last-char in the name matching algorithm
4756 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4758 static const char *expected_syms1
[] = {
4762 SELF_CHECK (check_find_bounds_finds (mock_index
,
4763 "\377", expected_syms1
));
4765 static const char *expected_syms2
[] = {
4768 SELF_CHECK (check_find_bounds_finds (mock_index
,
4769 "\377\377", expected_syms2
));
4773 /* Test dw2_expand_symtabs_matching_symbol. */
4776 test_dw2_expand_symtabs_matching_symbol ()
4778 mock_mapped_index
mock_index (test_symbols
);
4780 /* We let all tests run until the end even if some fails, for debug
4782 bool any_mismatch
= false;
4784 /* Create the expected symbols list (an initializer_list). Needed
4785 because lists have commas, and we need to pass them to CHECK,
4786 which is a macro. */
4787 #define EXPECT(...) { __VA_ARGS__ }
4789 /* Wrapper for check_match that passes down the current
4790 __FILE__/__LINE__. */
4791 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4792 any_mismatch |= !check_match (__FILE__, __LINE__, \
4794 NAME, MATCH_TYPE, COMPLETION_MODE, \
4797 /* Identity checks. */
4798 for (const char *sym
: test_symbols
)
4800 /* Should be able to match all existing symbols. */
4801 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4804 /* Should be able to match all existing symbols with
4806 std::string with_params
= std::string (sym
) + "(int)";
4807 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4810 /* Should be able to match all existing symbols with
4811 parameters and qualifiers. */
4812 with_params
= std::string (sym
) + " ( int ) const";
4813 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4816 /* This should really find sym, but cp-name-parser.y doesn't
4817 know about lvalue/rvalue qualifiers yet. */
4818 with_params
= std::string (sym
) + " ( int ) &&";
4819 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4823 /* Check that the name matching algorithm for completion doesn't get
4824 confused with Latin1 'ÿ' / 0xff. */
4826 static const char str
[] = "\377";
4827 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4828 EXPECT ("\377", "\377\377123"));
4831 /* Check that the increment-last-char in the matching algorithm for
4832 completion doesn't match "t1_fund" when completing "t1_func". */
4834 static const char str
[] = "t1_func";
4835 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4836 EXPECT ("t1_func", "t1_func1"));
4839 /* Check that completion mode works at each prefix of the expected
4842 static const char str
[] = "function(int)";
4843 size_t len
= strlen (str
);
4846 for (size_t i
= 1; i
< len
; i
++)
4848 lookup
.assign (str
, i
);
4849 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4850 EXPECT ("function"));
4854 /* While "w" is a prefix of both components, the match function
4855 should still only be called once. */
4857 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4859 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4863 /* Same, with a "complicated" symbol. */
4865 static const char str
[] = Z_SYM_NAME
;
4866 size_t len
= strlen (str
);
4869 for (size_t i
= 1; i
< len
; i
++)
4871 lookup
.assign (str
, i
);
4872 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4873 EXPECT (Z_SYM_NAME
));
4877 /* In FULL mode, an incomplete symbol doesn't match. */
4879 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4883 /* A complete symbol with parameters matches any overload, since the
4884 index has no overload info. */
4886 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4887 EXPECT ("std::zfunction", "std::zfunction2"));
4888 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4889 EXPECT ("std::zfunction", "std::zfunction2"));
4890 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4891 EXPECT ("std::zfunction", "std::zfunction2"));
4894 /* Check that whitespace is ignored appropriately. A symbol with a
4895 template argument list. */
4897 static const char expected
[] = "ns::foo<int>";
4898 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4900 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4904 /* Check that whitespace is ignored appropriately. A symbol with a
4905 template argument list that includes a pointer. */
4907 static const char expected
[] = "ns::foo<char*>";
4908 /* Try both completion and non-completion modes. */
4909 static const bool completion_mode
[2] = {false, true};
4910 for (size_t i
= 0; i
< 2; i
++)
4912 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4913 completion_mode
[i
], EXPECT (expected
));
4914 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4915 completion_mode
[i
], EXPECT (expected
));
4917 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4918 completion_mode
[i
], EXPECT (expected
));
4919 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4920 completion_mode
[i
], EXPECT (expected
));
4925 /* Check method qualifiers are ignored. */
4926 static const char expected
[] = "ns::foo<char*>";
4927 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4928 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4929 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4930 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4931 CHECK_MATCH ("foo < char * > ( int ) const",
4932 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4933 CHECK_MATCH ("foo < char * > ( int ) &&",
4934 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4937 /* Test lookup names that don't match anything. */
4939 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4942 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4946 /* Some wild matching tests, exercising "(anonymous namespace)",
4947 which should not be confused with a parameter list. */
4949 static const char *syms
[] = {
4953 "A :: B :: C ( int )",
4958 for (const char *s
: syms
)
4960 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4961 EXPECT ("(anonymous namespace)::A::B::C"));
4966 static const char expected
[] = "ns2::tmpl<int>::foo2";
4967 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4969 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4973 SELF_CHECK (!any_mismatch
);
4982 test_mapped_index_find_name_component_bounds ();
4983 test_dw2_expand_symtabs_matching_symbol ();
4986 }} // namespace selftests::dw2_expand_symtabs_matching
4988 #endif /* GDB_SELF_TEST */
4990 /* If FILE_MATCHER is NULL or if PER_CU has
4991 dwarf2_per_cu_quick_data::MARK set (see
4992 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4993 EXPANSION_NOTIFY on it. */
4996 dw2_expand_symtabs_matching_one
4997 (struct dwarf2_per_cu_data
*per_cu
,
4998 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4999 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5001 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5003 bool symtab_was_null
5004 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5006 dw2_instantiate_symtab (per_cu
, false);
5008 if (expansion_notify
!= NULL
5010 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5011 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5015 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5016 matched, to expand corresponding CUs that were marked. IDX is the
5017 index of the symbol name that matched. */
5020 dw2_expand_marked_cus
5021 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5022 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5023 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5026 offset_type
*vec
, vec_len
, vec_idx
;
5027 bool global_seen
= false;
5028 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5030 vec
= (offset_type
*) (index
.constant_pool
5031 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5032 vec_len
= MAYBE_SWAP (vec
[0]);
5033 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5035 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5036 /* This value is only valid for index versions >= 7. */
5037 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5038 gdb_index_symbol_kind symbol_kind
=
5039 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5040 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5041 /* Only check the symbol attributes if they're present.
5042 Indices prior to version 7 don't record them,
5043 and indices >= 7 may elide them for certain symbols
5044 (gold does this). */
5047 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5049 /* Work around gold/15646. */
5052 if (!is_static
&& global_seen
)
5058 /* Only check the symbol's kind if it has one. */
5063 case VARIABLES_DOMAIN
:
5064 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5067 case FUNCTIONS_DOMAIN
:
5068 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5072 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5075 case MODULES_DOMAIN
:
5076 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
5084 /* Don't crash on bad data. */
5085 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5086 + dwarf2_per_objfile
->all_type_units
.size ()))
5088 complaint (_(".gdb_index entry has bad CU index"
5090 objfile_name (dwarf2_per_objfile
->objfile
));
5094 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5095 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5100 /* If FILE_MATCHER is non-NULL, set all the
5101 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5102 that match FILE_MATCHER. */
5105 dw_expand_symtabs_matching_file_matcher
5106 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5107 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5109 if (file_matcher
== NULL
)
5112 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5114 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5116 NULL
, xcalloc
, xfree
));
5117 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5119 NULL
, xcalloc
, xfree
));
5121 /* The rule is CUs specify all the files, including those used by
5122 any TU, so there's no need to scan TUs here. */
5124 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5128 per_cu
->v
.quick
->mark
= 0;
5130 /* We only need to look at symtabs not already expanded. */
5131 if (per_cu
->v
.quick
->compunit_symtab
)
5134 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5135 if (file_data
== NULL
)
5138 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5140 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5142 per_cu
->v
.quick
->mark
= 1;
5146 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5148 const char *this_real_name
;
5150 if (file_matcher (file_data
->file_names
[j
], false))
5152 per_cu
->v
.quick
->mark
= 1;
5156 /* Before we invoke realpath, which can get expensive when many
5157 files are involved, do a quick comparison of the basenames. */
5158 if (!basenames_may_differ
5159 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5163 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5164 if (file_matcher (this_real_name
, false))
5166 per_cu
->v
.quick
->mark
= 1;
5171 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5172 ? visited_found
.get ()
5173 : visited_not_found
.get (),
5180 dw2_expand_symtabs_matching
5181 (struct objfile
*objfile
,
5182 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5183 const lookup_name_info
&lookup_name
,
5184 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5185 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5186 enum search_domain kind
)
5188 struct dwarf2_per_objfile
*dwarf2_per_objfile
5189 = get_dwarf2_per_objfile (objfile
);
5191 /* index_table is NULL if OBJF_READNOW. */
5192 if (!dwarf2_per_objfile
->index_table
)
5195 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5197 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5199 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5201 kind
, [&] (offset_type idx
)
5203 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5204 expansion_notify
, kind
);
5209 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5212 static struct compunit_symtab
*
5213 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5218 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5219 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5222 if (cust
->includes
== NULL
)
5225 for (i
= 0; cust
->includes
[i
]; ++i
)
5227 struct compunit_symtab
*s
= cust
->includes
[i
];
5229 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5237 static struct compunit_symtab
*
5238 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5239 struct bound_minimal_symbol msymbol
,
5241 struct obj_section
*section
,
5244 struct dwarf2_per_cu_data
*data
;
5245 struct compunit_symtab
*result
;
5247 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5250 CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
5251 SECT_OFF_TEXT (objfile
));
5252 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5253 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5257 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5258 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5259 paddress (get_objfile_arch (objfile
), pc
));
5262 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5265 gdb_assert (result
!= NULL
);
5270 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5271 void *data
, int need_fullname
)
5273 struct dwarf2_per_objfile
*dwarf2_per_objfile
5274 = get_dwarf2_per_objfile (objfile
);
5276 if (!dwarf2_per_objfile
->filenames_cache
)
5278 dwarf2_per_objfile
->filenames_cache
.emplace ();
5280 htab_up
visited (htab_create_alloc (10,
5281 htab_hash_pointer
, htab_eq_pointer
,
5282 NULL
, xcalloc
, xfree
));
5284 /* The rule is CUs specify all the files, including those used
5285 by any TU, so there's no need to scan TUs here. We can
5286 ignore file names coming from already-expanded CUs. */
5288 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5290 if (per_cu
->v
.quick
->compunit_symtab
)
5292 void **slot
= htab_find_slot (visited
.get (),
5293 per_cu
->v
.quick
->file_names
,
5296 *slot
= per_cu
->v
.quick
->file_names
;
5300 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5302 /* We only need to look at symtabs not already expanded. */
5303 if (per_cu
->v
.quick
->compunit_symtab
)
5306 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5307 if (file_data
== NULL
)
5310 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5313 /* Already visited. */
5318 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5320 const char *filename
= file_data
->file_names
[j
];
5321 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5326 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5328 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5331 this_real_name
= gdb_realpath (filename
);
5332 (*fun
) (filename
, this_real_name
.get (), data
);
5337 dw2_has_symbols (struct objfile
*objfile
)
5342 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5345 dw2_find_last_source_symtab
,
5346 dw2_forget_cached_source_info
,
5347 dw2_map_symtabs_matching_filename
,
5351 dw2_expand_symtabs_for_function
,
5352 dw2_expand_all_symtabs
,
5353 dw2_expand_symtabs_with_fullname
,
5354 dw2_map_matching_symbols
,
5355 dw2_expand_symtabs_matching
,
5356 dw2_find_pc_sect_compunit_symtab
,
5358 dw2_map_symbol_filenames
5361 /* DWARF-5 debug_names reader. */
5363 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5364 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5366 /* A helper function that reads the .debug_names section in SECTION
5367 and fills in MAP. FILENAME is the name of the file containing the
5368 section; it is used for error reporting.
5370 Returns true if all went well, false otherwise. */
5373 read_debug_names_from_section (struct objfile
*objfile
,
5374 const char *filename
,
5375 struct dwarf2_section_info
*section
,
5376 mapped_debug_names
&map
)
5378 if (dwarf2_section_empty_p (section
))
5381 /* Older elfutils strip versions could keep the section in the main
5382 executable while splitting it for the separate debug info file. */
5383 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5386 dwarf2_read_section (objfile
, section
);
5388 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5390 const gdb_byte
*addr
= section
->buffer
;
5392 bfd
*const abfd
= get_section_bfd_owner (section
);
5394 unsigned int bytes_read
;
5395 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5398 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5399 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5400 if (bytes_read
+ length
!= section
->size
)
5402 /* There may be multiple per-CU indices. */
5403 warning (_("Section .debug_names in %s length %s does not match "
5404 "section length %s, ignoring .debug_names."),
5405 filename
, plongest (bytes_read
+ length
),
5406 pulongest (section
->size
));
5410 /* The version number. */
5411 uint16_t version
= read_2_bytes (abfd
, addr
);
5415 warning (_("Section .debug_names in %s has unsupported version %d, "
5416 "ignoring .debug_names."),
5422 uint16_t padding
= read_2_bytes (abfd
, addr
);
5426 warning (_("Section .debug_names in %s has unsupported padding %d, "
5427 "ignoring .debug_names."),
5432 /* comp_unit_count - The number of CUs in the CU list. */
5433 map
.cu_count
= read_4_bytes (abfd
, addr
);
5436 /* local_type_unit_count - The number of TUs in the local TU
5438 map
.tu_count
= read_4_bytes (abfd
, addr
);
5441 /* foreign_type_unit_count - The number of TUs in the foreign TU
5443 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5445 if (foreign_tu_count
!= 0)
5447 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5448 "ignoring .debug_names."),
5449 filename
, static_cast<unsigned long> (foreign_tu_count
));
5453 /* bucket_count - The number of hash buckets in the hash lookup
5455 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5458 /* name_count - The number of unique names in the index. */
5459 map
.name_count
= read_4_bytes (abfd
, addr
);
5462 /* abbrev_table_size - The size in bytes of the abbreviations
5464 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5467 /* augmentation_string_size - The size in bytes of the augmentation
5468 string. This value is rounded up to a multiple of 4. */
5469 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5471 map
.augmentation_is_gdb
= ((augmentation_string_size
5472 == sizeof (dwarf5_augmentation
))
5473 && memcmp (addr
, dwarf5_augmentation
,
5474 sizeof (dwarf5_augmentation
)) == 0);
5475 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5476 addr
+= augmentation_string_size
;
5479 map
.cu_table_reordered
= addr
;
5480 addr
+= map
.cu_count
* map
.offset_size
;
5482 /* List of Local TUs */
5483 map
.tu_table_reordered
= addr
;
5484 addr
+= map
.tu_count
* map
.offset_size
;
5486 /* Hash Lookup Table */
5487 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5488 addr
+= map
.bucket_count
* 4;
5489 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5490 addr
+= map
.name_count
* 4;
5493 map
.name_table_string_offs_reordered
= addr
;
5494 addr
+= map
.name_count
* map
.offset_size
;
5495 map
.name_table_entry_offs_reordered
= addr
;
5496 addr
+= map
.name_count
* map
.offset_size
;
5498 const gdb_byte
*abbrev_table_start
= addr
;
5501 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5506 const auto insertpair
5507 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5508 if (!insertpair
.second
)
5510 warning (_("Section .debug_names in %s has duplicate index %s, "
5511 "ignoring .debug_names."),
5512 filename
, pulongest (index_num
));
5515 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5516 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5521 mapped_debug_names::index_val::attr attr
;
5522 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5524 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5526 if (attr
.form
== DW_FORM_implicit_const
)
5528 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5532 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5534 indexval
.attr_vec
.push_back (std::move (attr
));
5537 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5539 warning (_("Section .debug_names in %s has abbreviation_table "
5540 "of size %s vs. written as %u, ignoring .debug_names."),
5541 filename
, plongest (addr
- abbrev_table_start
),
5545 map
.entry_pool
= addr
;
5550 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5554 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5555 const mapped_debug_names
&map
,
5556 dwarf2_section_info
§ion
,
5559 sect_offset sect_off_prev
;
5560 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5562 sect_offset sect_off_next
;
5563 if (i
< map
.cu_count
)
5566 = (sect_offset
) (extract_unsigned_integer
5567 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5569 map
.dwarf5_byte_order
));
5572 sect_off_next
= (sect_offset
) section
.size
;
5575 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5576 dwarf2_per_cu_data
*per_cu
5577 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5578 sect_off_prev
, length
);
5579 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5581 sect_off_prev
= sect_off_next
;
5585 /* Read the CU list from the mapped index, and use it to create all
5586 the CU objects for this dwarf2_per_objfile. */
5589 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5590 const mapped_debug_names
&map
,
5591 const mapped_debug_names
&dwz_map
)
5593 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5594 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5596 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5597 dwarf2_per_objfile
->info
,
5598 false /* is_dwz */);
5600 if (dwz_map
.cu_count
== 0)
5603 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5604 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5608 /* Read .debug_names. If everything went ok, initialize the "quick"
5609 elements of all the CUs and return true. Otherwise, return false. */
5612 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5614 std::unique_ptr
<mapped_debug_names
> map
5615 (new mapped_debug_names (dwarf2_per_objfile
));
5616 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5617 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5619 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5620 &dwarf2_per_objfile
->debug_names
,
5624 /* Don't use the index if it's empty. */
5625 if (map
->name_count
== 0)
5628 /* If there is a .dwz file, read it so we can get its CU list as
5630 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5633 if (!read_debug_names_from_section (objfile
,
5634 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5635 &dwz
->debug_names
, dwz_map
))
5637 warning (_("could not read '.debug_names' section from %s; skipping"),
5638 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5643 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5645 if (map
->tu_count
!= 0)
5647 /* We can only handle a single .debug_types when we have an
5649 if (dwarf2_per_objfile
->types
.size () != 1)
5652 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5654 create_signatured_type_table_from_debug_names
5655 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5658 create_addrmap_from_aranges (dwarf2_per_objfile
,
5659 &dwarf2_per_objfile
->debug_aranges
);
5661 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5662 dwarf2_per_objfile
->using_index
= 1;
5663 dwarf2_per_objfile
->quick_file_names_table
=
5664 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5669 /* Type used to manage iterating over all CUs looking for a symbol for
5672 class dw2_debug_names_iterator
5675 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5676 gdb::optional
<block_enum
> block_index
,
5679 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5680 m_addr (find_vec_in_debug_names (map
, name
))
5683 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5684 search_domain search
, uint32_t namei
)
5687 m_addr (find_vec_in_debug_names (map
, namei
))
5690 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5691 block_enum block_index
, domain_enum domain
,
5693 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5694 m_addr (find_vec_in_debug_names (map
, namei
))
5697 /* Return the next matching CU or NULL if there are no more. */
5698 dwarf2_per_cu_data
*next ();
5701 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5703 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5706 /* The internalized form of .debug_names. */
5707 const mapped_debug_names
&m_map
;
5709 /* If set, only look for symbols that match that block. Valid values are
5710 GLOBAL_BLOCK and STATIC_BLOCK. */
5711 const gdb::optional
<block_enum
> m_block_index
;
5713 /* The kind of symbol we're looking for. */
5714 const domain_enum m_domain
= UNDEF_DOMAIN
;
5715 const search_domain m_search
= ALL_DOMAIN
;
5717 /* The list of CUs from the index entry of the symbol, or NULL if
5719 const gdb_byte
*m_addr
;
5723 mapped_debug_names::namei_to_name (uint32_t namei
) const
5725 const ULONGEST namei_string_offs
5726 = extract_unsigned_integer ((name_table_string_offs_reordered
5727 + namei
* offset_size
),
5730 return read_indirect_string_at_offset
5731 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5734 /* Find a slot in .debug_names for the object named NAME. If NAME is
5735 found, return pointer to its pool data. If NAME cannot be found,
5739 dw2_debug_names_iterator::find_vec_in_debug_names
5740 (const mapped_debug_names
&map
, const char *name
)
5742 int (*cmp
) (const char *, const char *);
5744 gdb::unique_xmalloc_ptr
<char> without_params
;
5745 if (current_language
->la_language
== language_cplus
5746 || current_language
->la_language
== language_fortran
5747 || current_language
->la_language
== language_d
)
5749 /* NAME is already canonical. Drop any qualifiers as
5750 .debug_names does not contain any. */
5752 if (strchr (name
, '(') != NULL
)
5754 without_params
= cp_remove_params (name
);
5755 if (without_params
!= NULL
)
5756 name
= without_params
.get ();
5760 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5762 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5764 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5765 (map
.bucket_table_reordered
5766 + (full_hash
% map
.bucket_count
)), 4,
5767 map
.dwarf5_byte_order
);
5771 if (namei
>= map
.name_count
)
5773 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5775 namei
, map
.name_count
,
5776 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5782 const uint32_t namei_full_hash
5783 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5784 (map
.hash_table_reordered
+ namei
), 4,
5785 map
.dwarf5_byte_order
);
5786 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5789 if (full_hash
== namei_full_hash
)
5791 const char *const namei_string
= map
.namei_to_name (namei
);
5793 #if 0 /* An expensive sanity check. */
5794 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5796 complaint (_("Wrong .debug_names hash for string at index %u "
5798 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5803 if (cmp (namei_string
, name
) == 0)
5805 const ULONGEST namei_entry_offs
5806 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5807 + namei
* map
.offset_size
),
5808 map
.offset_size
, map
.dwarf5_byte_order
);
5809 return map
.entry_pool
+ namei_entry_offs
;
5814 if (namei
>= map
.name_count
)
5820 dw2_debug_names_iterator::find_vec_in_debug_names
5821 (const mapped_debug_names
&map
, uint32_t namei
)
5823 if (namei
>= map
.name_count
)
5825 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5827 namei
, map
.name_count
,
5828 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5832 const ULONGEST namei_entry_offs
5833 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5834 + namei
* map
.offset_size
),
5835 map
.offset_size
, map
.dwarf5_byte_order
);
5836 return map
.entry_pool
+ namei_entry_offs
;
5839 /* See dw2_debug_names_iterator. */
5841 dwarf2_per_cu_data
*
5842 dw2_debug_names_iterator::next ()
5847 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5848 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5849 bfd
*const abfd
= objfile
->obfd
;
5853 unsigned int bytes_read
;
5854 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5855 m_addr
+= bytes_read
;
5859 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5860 if (indexval_it
== m_map
.abbrev_map
.cend ())
5862 complaint (_("Wrong .debug_names undefined abbrev code %s "
5864 pulongest (abbrev
), objfile_name (objfile
));
5867 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5868 enum class symbol_linkage
{
5872 } symbol_linkage_
= symbol_linkage::unknown
;
5873 dwarf2_per_cu_data
*per_cu
= NULL
;
5874 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5879 case DW_FORM_implicit_const
:
5880 ull
= attr
.implicit_const
;
5882 case DW_FORM_flag_present
:
5886 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5887 m_addr
+= bytes_read
;
5890 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5891 dwarf_form_name (attr
.form
),
5892 objfile_name (objfile
));
5895 switch (attr
.dw_idx
)
5897 case DW_IDX_compile_unit
:
5898 /* Don't crash on bad data. */
5899 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5901 complaint (_(".debug_names entry has bad CU index %s"
5904 objfile_name (dwarf2_per_objfile
->objfile
));
5907 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5909 case DW_IDX_type_unit
:
5910 /* Don't crash on bad data. */
5911 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5913 complaint (_(".debug_names entry has bad TU index %s"
5916 objfile_name (dwarf2_per_objfile
->objfile
));
5919 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5921 case DW_IDX_GNU_internal
:
5922 if (!m_map
.augmentation_is_gdb
)
5924 symbol_linkage_
= symbol_linkage::static_
;
5926 case DW_IDX_GNU_external
:
5927 if (!m_map
.augmentation_is_gdb
)
5929 symbol_linkage_
= symbol_linkage::extern_
;
5934 /* Skip if already read in. */
5935 if (per_cu
->v
.quick
->compunit_symtab
)
5938 /* Check static vs global. */
5939 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5941 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5942 const bool symbol_is_static
=
5943 symbol_linkage_
== symbol_linkage::static_
;
5944 if (want_static
!= symbol_is_static
)
5948 /* Match dw2_symtab_iter_next, symbol_kind
5949 and debug_names::psymbol_tag. */
5953 switch (indexval
.dwarf_tag
)
5955 case DW_TAG_variable
:
5956 case DW_TAG_subprogram
:
5957 /* Some types are also in VAR_DOMAIN. */
5958 case DW_TAG_typedef
:
5959 case DW_TAG_structure_type
:
5966 switch (indexval
.dwarf_tag
)
5968 case DW_TAG_typedef
:
5969 case DW_TAG_structure_type
:
5976 switch (indexval
.dwarf_tag
)
5979 case DW_TAG_variable
:
5986 switch (indexval
.dwarf_tag
)
5998 /* Match dw2_expand_symtabs_matching, symbol_kind and
5999 debug_names::psymbol_tag. */
6002 case VARIABLES_DOMAIN
:
6003 switch (indexval
.dwarf_tag
)
6005 case DW_TAG_variable
:
6011 case FUNCTIONS_DOMAIN
:
6012 switch (indexval
.dwarf_tag
)
6014 case DW_TAG_subprogram
:
6021 switch (indexval
.dwarf_tag
)
6023 case DW_TAG_typedef
:
6024 case DW_TAG_structure_type
:
6030 case MODULES_DOMAIN
:
6031 switch (indexval
.dwarf_tag
)
6045 static struct compunit_symtab
*
6046 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6047 const char *name
, domain_enum domain
)
6049 struct dwarf2_per_objfile
*dwarf2_per_objfile
6050 = get_dwarf2_per_objfile (objfile
);
6052 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6055 /* index is NULL if OBJF_READNOW. */
6058 const auto &map
= *mapp
;
6060 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6062 struct compunit_symtab
*stab_best
= NULL
;
6063 struct dwarf2_per_cu_data
*per_cu
;
6064 while ((per_cu
= iter
.next ()) != NULL
)
6066 struct symbol
*sym
, *with_opaque
= NULL
;
6067 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6068 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6069 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6071 sym
= block_find_symbol (block
, name
, domain
,
6072 block_find_non_opaque_type_preferred
,
6075 /* Some caution must be observed with overloaded functions and
6076 methods, since the index will not contain any overload
6077 information (but NAME might contain it). */
6080 && strcmp_iw (sym
->search_name (), name
) == 0)
6082 if (with_opaque
!= NULL
6083 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
6086 /* Keep looking through other CUs. */
6092 /* This dumps minimal information about .debug_names. It is called
6093 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6094 uses this to verify that .debug_names has been loaded. */
6097 dw2_debug_names_dump (struct objfile
*objfile
)
6099 struct dwarf2_per_objfile
*dwarf2_per_objfile
6100 = get_dwarf2_per_objfile (objfile
);
6102 gdb_assert (dwarf2_per_objfile
->using_index
);
6103 printf_filtered (".debug_names:");
6104 if (dwarf2_per_objfile
->debug_names_table
)
6105 printf_filtered (" exists\n");
6107 printf_filtered (" faked for \"readnow\"\n");
6108 printf_filtered ("\n");
6112 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6113 const char *func_name
)
6115 struct dwarf2_per_objfile
*dwarf2_per_objfile
6116 = get_dwarf2_per_objfile (objfile
);
6118 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6119 if (dwarf2_per_objfile
->debug_names_table
)
6121 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6123 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6125 struct dwarf2_per_cu_data
*per_cu
;
6126 while ((per_cu
= iter
.next ()) != NULL
)
6127 dw2_instantiate_symtab (per_cu
, false);
6132 dw2_debug_names_map_matching_symbols
6133 (struct objfile
*objfile
,
6134 const lookup_name_info
&name
, domain_enum domain
,
6136 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6137 symbol_compare_ftype
*ordered_compare
)
6139 struct dwarf2_per_objfile
*dwarf2_per_objfile
6140 = get_dwarf2_per_objfile (objfile
);
6142 /* debug_names_table is NULL if OBJF_READNOW. */
6143 if (!dwarf2_per_objfile
->debug_names_table
)
6146 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6147 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6149 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6150 auto matcher
= [&] (const char *symname
)
6152 if (ordered_compare
== nullptr)
6154 return ordered_compare (symname
, match_name
) == 0;
6157 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6158 [&] (offset_type namei
)
6160 /* The name was matched, now expand corresponding CUs that were
6162 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6164 struct dwarf2_per_cu_data
*per_cu
;
6165 while ((per_cu
= iter
.next ()) != NULL
)
6166 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6170 /* It's a shame we couldn't do this inside the
6171 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6172 that have already been expanded. Instead, this loop matches what
6173 the psymtab code does. */
6174 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6176 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6177 if (cust
!= nullptr)
6179 const struct block
*block
6180 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6181 if (!iterate_over_symbols_terminated (block
, name
,
6189 dw2_debug_names_expand_symtabs_matching
6190 (struct objfile
*objfile
,
6191 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6192 const lookup_name_info
&lookup_name
,
6193 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6194 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6195 enum search_domain kind
)
6197 struct dwarf2_per_objfile
*dwarf2_per_objfile
6198 = get_dwarf2_per_objfile (objfile
);
6200 /* debug_names_table is NULL if OBJF_READNOW. */
6201 if (!dwarf2_per_objfile
->debug_names_table
)
6204 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6206 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6208 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6210 kind
, [&] (offset_type namei
)
6212 /* The name was matched, now expand corresponding CUs that were
6214 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6216 struct dwarf2_per_cu_data
*per_cu
;
6217 while ((per_cu
= iter
.next ()) != NULL
)
6218 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6224 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6227 dw2_find_last_source_symtab
,
6228 dw2_forget_cached_source_info
,
6229 dw2_map_symtabs_matching_filename
,
6230 dw2_debug_names_lookup_symbol
,
6232 dw2_debug_names_dump
,
6233 dw2_debug_names_expand_symtabs_for_function
,
6234 dw2_expand_all_symtabs
,
6235 dw2_expand_symtabs_with_fullname
,
6236 dw2_debug_names_map_matching_symbols
,
6237 dw2_debug_names_expand_symtabs_matching
,
6238 dw2_find_pc_sect_compunit_symtab
,
6240 dw2_map_symbol_filenames
6243 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6244 to either a dwarf2_per_objfile or dwz_file object. */
6246 template <typename T
>
6247 static gdb::array_view
<const gdb_byte
>
6248 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6250 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6252 if (dwarf2_section_empty_p (section
))
6255 /* Older elfutils strip versions could keep the section in the main
6256 executable while splitting it for the separate debug info file. */
6257 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6260 dwarf2_read_section (obj
, section
);
6262 /* dwarf2_section_info::size is a bfd_size_type, while
6263 gdb::array_view works with size_t. On 32-bit hosts, with
6264 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6265 is 32-bit. So we need an explicit narrowing conversion here.
6266 This is fine, because it's impossible to allocate or mmap an
6267 array/buffer larger than what size_t can represent. */
6268 return gdb::make_array_view (section
->buffer
, section
->size
);
6271 /* Lookup the index cache for the contents of the index associated to
6274 static gdb::array_view
<const gdb_byte
>
6275 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6277 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6278 if (build_id
== nullptr)
6281 return global_index_cache
.lookup_gdb_index (build_id
,
6282 &dwarf2_obj
->index_cache_res
);
6285 /* Same as the above, but for DWZ. */
6287 static gdb::array_view
<const gdb_byte
>
6288 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6290 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6291 if (build_id
== nullptr)
6294 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6297 /* See symfile.h. */
6300 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6302 struct dwarf2_per_objfile
*dwarf2_per_objfile
6303 = get_dwarf2_per_objfile (objfile
);
6305 /* If we're about to read full symbols, don't bother with the
6306 indices. In this case we also don't care if some other debug
6307 format is making psymtabs, because they are all about to be
6309 if ((objfile
->flags
& OBJF_READNOW
))
6311 dwarf2_per_objfile
->using_index
= 1;
6312 create_all_comp_units (dwarf2_per_objfile
);
6313 create_all_type_units (dwarf2_per_objfile
);
6314 dwarf2_per_objfile
->quick_file_names_table
6315 = create_quick_file_names_table
6316 (dwarf2_per_objfile
->all_comp_units
.size ());
6318 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6319 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6321 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6323 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6324 struct dwarf2_per_cu_quick_data
);
6327 /* Return 1 so that gdb sees the "quick" functions. However,
6328 these functions will be no-ops because we will have expanded
6330 *index_kind
= dw_index_kind::GDB_INDEX
;
6334 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6336 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6340 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6341 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6342 get_gdb_index_contents_from_section
<dwz_file
>))
6344 *index_kind
= dw_index_kind::GDB_INDEX
;
6348 /* ... otherwise, try to find the index in the index cache. */
6349 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6350 get_gdb_index_contents_from_cache
,
6351 get_gdb_index_contents_from_cache_dwz
))
6353 global_index_cache
.hit ();
6354 *index_kind
= dw_index_kind::GDB_INDEX
;
6358 global_index_cache
.miss ();
6364 /* Build a partial symbol table. */
6367 dwarf2_build_psymtabs (struct objfile
*objfile
)
6369 struct dwarf2_per_objfile
*dwarf2_per_objfile
6370 = get_dwarf2_per_objfile (objfile
);
6372 init_psymbol_list (objfile
, 1024);
6376 /* This isn't really ideal: all the data we allocate on the
6377 objfile's obstack is still uselessly kept around. However,
6378 freeing it seems unsafe. */
6379 psymtab_discarder
psymtabs (objfile
);
6380 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6383 /* (maybe) store an index in the cache. */
6384 global_index_cache
.store (dwarf2_per_objfile
);
6386 catch (const gdb_exception_error
&except
)
6388 exception_print (gdb_stderr
, except
);
6392 /* Return the total length of the CU described by HEADER. */
6395 get_cu_length (const struct comp_unit_head
*header
)
6397 return header
->initial_length_size
+ header
->length
;
6400 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6403 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6405 sect_offset bottom
= cu_header
->sect_off
;
6406 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6408 return sect_off
>= bottom
&& sect_off
< top
;
6411 /* Find the base address of the compilation unit for range lists and
6412 location lists. It will normally be specified by DW_AT_low_pc.
6413 In DWARF-3 draft 4, the base address could be overridden by
6414 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6415 compilation units with discontinuous ranges. */
6418 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6420 struct attribute
*attr
;
6423 cu
->base_address
= 0;
6425 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6426 if (attr
!= nullptr)
6428 cu
->base_address
= attr_value_as_address (attr
);
6433 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6434 if (attr
!= nullptr)
6436 cu
->base_address
= attr_value_as_address (attr
);
6442 /* Read in the comp unit header information from the debug_info at info_ptr.
6443 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6444 NOTE: This leaves members offset, first_die_offset to be filled in
6447 static const gdb_byte
*
6448 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6449 const gdb_byte
*info_ptr
,
6450 struct dwarf2_section_info
*section
,
6451 rcuh_kind section_kind
)
6454 unsigned int bytes_read
;
6455 const char *filename
= get_section_file_name (section
);
6456 bfd
*abfd
= get_section_bfd_owner (section
);
6458 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6459 cu_header
->initial_length_size
= bytes_read
;
6460 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6461 info_ptr
+= bytes_read
;
6462 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6463 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6464 error (_("Dwarf Error: wrong version in compilation unit header "
6465 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6466 cu_header
->version
, filename
);
6468 if (cu_header
->version
< 5)
6469 switch (section_kind
)
6471 case rcuh_kind::COMPILE
:
6472 cu_header
->unit_type
= DW_UT_compile
;
6474 case rcuh_kind::TYPE
:
6475 cu_header
->unit_type
= DW_UT_type
;
6478 internal_error (__FILE__
, __LINE__
,
6479 _("read_comp_unit_head: invalid section_kind"));
6483 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6484 (read_1_byte (abfd
, info_ptr
));
6486 switch (cu_header
->unit_type
)
6490 case DW_UT_skeleton
:
6491 case DW_UT_split_compile
:
6492 if (section_kind
!= rcuh_kind::COMPILE
)
6493 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6494 "(is %s, should be %s) [in module %s]"),
6495 dwarf_unit_type_name (cu_header
->unit_type
),
6496 dwarf_unit_type_name (DW_UT_type
), filename
);
6499 case DW_UT_split_type
:
6500 section_kind
= rcuh_kind::TYPE
;
6503 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6504 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6505 "[in module %s]"), cu_header
->unit_type
,
6506 dwarf_unit_type_name (DW_UT_compile
),
6507 dwarf_unit_type_name (DW_UT_skeleton
),
6508 dwarf_unit_type_name (DW_UT_split_compile
),
6509 dwarf_unit_type_name (DW_UT_type
),
6510 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6513 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6516 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6519 info_ptr
+= bytes_read
;
6520 if (cu_header
->version
< 5)
6522 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6525 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6526 if (signed_addr
< 0)
6527 internal_error (__FILE__
, __LINE__
,
6528 _("read_comp_unit_head: dwarf from non elf file"));
6529 cu_header
->signed_addr_p
= signed_addr
;
6531 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6532 || cu_header
->unit_type
== DW_UT_skeleton
6533 || cu_header
->unit_type
== DW_UT_split_compile
;
6535 if (header_has_signature
)
6537 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6541 if (section_kind
== rcuh_kind::TYPE
)
6543 LONGEST type_offset
;
6544 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6545 info_ptr
+= bytes_read
;
6546 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6547 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6548 error (_("Dwarf Error: Too big type_offset in compilation unit "
6549 "header (is %s) [in module %s]"), plongest (type_offset
),
6556 /* Helper function that returns the proper abbrev section for
6559 static struct dwarf2_section_info
*
6560 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6562 struct dwarf2_section_info
*abbrev
;
6563 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6565 if (this_cu
->is_dwz
)
6566 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6568 abbrev
= &dwarf2_per_objfile
->abbrev
;
6573 /* Subroutine of read_and_check_comp_unit_head and
6574 read_and_check_type_unit_head to simplify them.
6575 Perform various error checking on the header. */
6578 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6579 struct comp_unit_head
*header
,
6580 struct dwarf2_section_info
*section
,
6581 struct dwarf2_section_info
*abbrev_section
)
6583 const char *filename
= get_section_file_name (section
);
6585 if (to_underlying (header
->abbrev_sect_off
)
6586 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6587 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6588 "(offset %s + 6) [in module %s]"),
6589 sect_offset_str (header
->abbrev_sect_off
),
6590 sect_offset_str (header
->sect_off
),
6593 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6594 avoid potential 32-bit overflow. */
6595 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6597 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6598 "(offset %s + 0) [in module %s]"),
6599 header
->length
, sect_offset_str (header
->sect_off
),
6603 /* Read in a CU/TU header and perform some basic error checking.
6604 The contents of the header are stored in HEADER.
6605 The result is a pointer to the start of the first DIE. */
6607 static const gdb_byte
*
6608 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6609 struct comp_unit_head
*header
,
6610 struct dwarf2_section_info
*section
,
6611 struct dwarf2_section_info
*abbrev_section
,
6612 const gdb_byte
*info_ptr
,
6613 rcuh_kind section_kind
)
6615 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6617 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6619 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6621 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6623 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6629 /* Fetch the abbreviation table offset from a comp or type unit header. */
6632 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6633 struct dwarf2_section_info
*section
,
6634 sect_offset sect_off
)
6636 bfd
*abfd
= get_section_bfd_owner (section
);
6637 const gdb_byte
*info_ptr
;
6638 unsigned int initial_length_size
, offset_size
;
6641 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6642 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6643 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6644 offset_size
= initial_length_size
== 4 ? 4 : 8;
6645 info_ptr
+= initial_length_size
;
6647 version
= read_2_bytes (abfd
, info_ptr
);
6651 /* Skip unit type and address size. */
6655 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6658 /* Allocate a new partial symtab for file named NAME and mark this new
6659 partial symtab as being an include of PST. */
6662 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6663 struct objfile
*objfile
)
6665 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6667 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6669 /* It shares objfile->objfile_obstack. */
6670 subpst
->dirname
= pst
->dirname
;
6673 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6674 subpst
->dependencies
[0] = pst
;
6675 subpst
->number_of_dependencies
= 1;
6677 subpst
->read_symtab
= pst
->read_symtab
;
6679 /* No private part is necessary for include psymtabs. This property
6680 can be used to differentiate between such include psymtabs and
6681 the regular ones. */
6682 subpst
->read_symtab_private
= NULL
;
6685 /* Read the Line Number Program data and extract the list of files
6686 included by the source file represented by PST. Build an include
6687 partial symtab for each of these included files. */
6690 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6691 struct die_info
*die
,
6692 struct partial_symtab
*pst
)
6695 struct attribute
*attr
;
6697 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6698 if (attr
!= nullptr)
6699 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6701 return; /* No linetable, so no includes. */
6703 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6704 that we pass in the raw text_low here; that is ok because we're
6705 only decoding the line table to make include partial symtabs, and
6706 so the addresses aren't really used. */
6707 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6708 pst
->raw_text_low (), 1);
6712 hash_signatured_type (const void *item
)
6714 const struct signatured_type
*sig_type
6715 = (const struct signatured_type
*) item
;
6717 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6718 return sig_type
->signature
;
6722 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6724 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6725 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6727 return lhs
->signature
== rhs
->signature
;
6730 /* Allocate a hash table for signatured types. */
6733 allocate_signatured_type_table (struct objfile
*objfile
)
6735 return htab_create_alloc_ex (41,
6736 hash_signatured_type
,
6739 &objfile
->objfile_obstack
,
6740 hashtab_obstack_allocate
,
6741 dummy_obstack_deallocate
);
6744 /* A helper function to add a signatured type CU to a table. */
6747 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6749 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6750 std::vector
<signatured_type
*> *all_type_units
6751 = (std::vector
<signatured_type
*> *) datum
;
6753 all_type_units
->push_back (sigt
);
6758 /* A helper for create_debug_types_hash_table. Read types from SECTION
6759 and fill them into TYPES_HTAB. It will process only type units,
6760 therefore DW_UT_type. */
6763 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6764 struct dwo_file
*dwo_file
,
6765 dwarf2_section_info
*section
, htab_t
&types_htab
,
6766 rcuh_kind section_kind
)
6768 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6769 struct dwarf2_section_info
*abbrev_section
;
6771 const gdb_byte
*info_ptr
, *end_ptr
;
6773 abbrev_section
= (dwo_file
!= NULL
6774 ? &dwo_file
->sections
.abbrev
6775 : &dwarf2_per_objfile
->abbrev
);
6777 if (dwarf_read_debug
)
6778 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6779 get_section_name (section
),
6780 get_section_file_name (abbrev_section
));
6782 dwarf2_read_section (objfile
, section
);
6783 info_ptr
= section
->buffer
;
6785 if (info_ptr
== NULL
)
6788 /* We can't set abfd until now because the section may be empty or
6789 not present, in which case the bfd is unknown. */
6790 abfd
= get_section_bfd_owner (section
);
6792 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6793 because we don't need to read any dies: the signature is in the
6796 end_ptr
= info_ptr
+ section
->size
;
6797 while (info_ptr
< end_ptr
)
6799 struct signatured_type
*sig_type
;
6800 struct dwo_unit
*dwo_tu
;
6802 const gdb_byte
*ptr
= info_ptr
;
6803 struct comp_unit_head header
;
6804 unsigned int length
;
6806 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6808 /* Initialize it due to a false compiler warning. */
6809 header
.signature
= -1;
6810 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6812 /* We need to read the type's signature in order to build the hash
6813 table, but we don't need anything else just yet. */
6815 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6816 abbrev_section
, ptr
, section_kind
);
6818 length
= get_cu_length (&header
);
6820 /* Skip dummy type units. */
6821 if (ptr
>= info_ptr
+ length
6822 || peek_abbrev_code (abfd
, ptr
) == 0
6823 || header
.unit_type
!= DW_UT_type
)
6829 if (types_htab
== NULL
)
6832 types_htab
= allocate_dwo_unit_table (objfile
);
6834 types_htab
= allocate_signatured_type_table (objfile
);
6840 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6842 dwo_tu
->dwo_file
= dwo_file
;
6843 dwo_tu
->signature
= header
.signature
;
6844 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6845 dwo_tu
->section
= section
;
6846 dwo_tu
->sect_off
= sect_off
;
6847 dwo_tu
->length
= length
;
6851 /* N.B.: type_offset is not usable if this type uses a DWO file.
6852 The real type_offset is in the DWO file. */
6854 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6855 struct signatured_type
);
6856 sig_type
->signature
= header
.signature
;
6857 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6858 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6859 sig_type
->per_cu
.is_debug_types
= 1;
6860 sig_type
->per_cu
.section
= section
;
6861 sig_type
->per_cu
.sect_off
= sect_off
;
6862 sig_type
->per_cu
.length
= length
;
6865 slot
= htab_find_slot (types_htab
,
6866 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6868 gdb_assert (slot
!= NULL
);
6871 sect_offset dup_sect_off
;
6875 const struct dwo_unit
*dup_tu
6876 = (const struct dwo_unit
*) *slot
;
6878 dup_sect_off
= dup_tu
->sect_off
;
6882 const struct signatured_type
*dup_tu
6883 = (const struct signatured_type
*) *slot
;
6885 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6888 complaint (_("debug type entry at offset %s is duplicate to"
6889 " the entry at offset %s, signature %s"),
6890 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6891 hex_string (header
.signature
));
6893 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6895 if (dwarf_read_debug
> 1)
6896 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6897 sect_offset_str (sect_off
),
6898 hex_string (header
.signature
));
6904 /* Create the hash table of all entries in the .debug_types
6905 (or .debug_types.dwo) section(s).
6906 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6907 otherwise it is NULL.
6909 The result is a pointer to the hash table or NULL if there are no types.
6911 Note: This function processes DWO files only, not DWP files. */
6914 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6915 struct dwo_file
*dwo_file
,
6916 gdb::array_view
<dwarf2_section_info
> type_sections
,
6919 for (dwarf2_section_info
§ion
: type_sections
)
6920 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6921 types_htab
, rcuh_kind::TYPE
);
6924 /* Create the hash table of all entries in the .debug_types section,
6925 and initialize all_type_units.
6926 The result is zero if there is an error (e.g. missing .debug_types section),
6927 otherwise non-zero. */
6930 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6932 htab_t types_htab
= NULL
;
6934 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6935 &dwarf2_per_objfile
->info
, types_htab
,
6936 rcuh_kind::COMPILE
);
6937 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6938 dwarf2_per_objfile
->types
, types_htab
);
6939 if (types_htab
== NULL
)
6941 dwarf2_per_objfile
->signatured_types
= NULL
;
6945 dwarf2_per_objfile
->signatured_types
= types_htab
;
6947 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6948 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6950 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6951 &dwarf2_per_objfile
->all_type_units
);
6956 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6957 If SLOT is non-NULL, it is the entry to use in the hash table.
6958 Otherwise we find one. */
6960 static struct signatured_type
*
6961 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6964 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6966 if (dwarf2_per_objfile
->all_type_units
.size ()
6967 == dwarf2_per_objfile
->all_type_units
.capacity ())
6968 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6970 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6971 struct signatured_type
);
6973 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6974 sig_type
->signature
= sig
;
6975 sig_type
->per_cu
.is_debug_types
= 1;
6976 if (dwarf2_per_objfile
->using_index
)
6978 sig_type
->per_cu
.v
.quick
=
6979 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6980 struct dwarf2_per_cu_quick_data
);
6985 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6988 gdb_assert (*slot
== NULL
);
6990 /* The rest of sig_type must be filled in by the caller. */
6994 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6995 Fill in SIG_ENTRY with DWO_ENTRY. */
6998 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6999 struct signatured_type
*sig_entry
,
7000 struct dwo_unit
*dwo_entry
)
7002 /* Make sure we're not clobbering something we don't expect to. */
7003 gdb_assert (! sig_entry
->per_cu
.queued
);
7004 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7005 if (dwarf2_per_objfile
->using_index
)
7007 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7008 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7011 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7012 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7013 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7014 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7015 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7017 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7018 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7019 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7020 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7021 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7022 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7023 sig_entry
->dwo_unit
= dwo_entry
;
7026 /* Subroutine of lookup_signatured_type.
7027 If we haven't read the TU yet, create the signatured_type data structure
7028 for a TU to be read in directly from a DWO file, bypassing the stub.
7029 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7030 using .gdb_index, then when reading a CU we want to stay in the DWO file
7031 containing that CU. Otherwise we could end up reading several other DWO
7032 files (due to comdat folding) to process the transitive closure of all the
7033 mentioned TUs, and that can be slow. The current DWO file will have every
7034 type signature that it needs.
7035 We only do this for .gdb_index because in the psymtab case we already have
7036 to read all the DWOs to build the type unit groups. */
7038 static struct signatured_type
*
7039 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7041 struct dwarf2_per_objfile
*dwarf2_per_objfile
7042 = cu
->per_cu
->dwarf2_per_objfile
;
7043 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7044 struct dwo_file
*dwo_file
;
7045 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7046 struct signatured_type find_sig_entry
, *sig_entry
;
7049 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7051 /* If TU skeletons have been removed then we may not have read in any
7053 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7055 dwarf2_per_objfile
->signatured_types
7056 = allocate_signatured_type_table (objfile
);
7059 /* We only ever need to read in one copy of a signatured type.
7060 Use the global signatured_types array to do our own comdat-folding
7061 of types. If this is the first time we're reading this TU, and
7062 the TU has an entry in .gdb_index, replace the recorded data from
7063 .gdb_index with this TU. */
7065 find_sig_entry
.signature
= sig
;
7066 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7067 &find_sig_entry
, INSERT
);
7068 sig_entry
= (struct signatured_type
*) *slot
;
7070 /* We can get here with the TU already read, *or* in the process of being
7071 read. Don't reassign the global entry to point to this DWO if that's
7072 the case. Also note that if the TU is already being read, it may not
7073 have come from a DWO, the program may be a mix of Fission-compiled
7074 code and non-Fission-compiled code. */
7076 /* Have we already tried to read this TU?
7077 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7078 needn't exist in the global table yet). */
7079 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7082 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7083 dwo_unit of the TU itself. */
7084 dwo_file
= cu
->dwo_unit
->dwo_file
;
7086 /* Ok, this is the first time we're reading this TU. */
7087 if (dwo_file
->tus
== NULL
)
7089 find_dwo_entry
.signature
= sig
;
7090 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7091 if (dwo_entry
== NULL
)
7094 /* If the global table doesn't have an entry for this TU, add one. */
7095 if (sig_entry
== NULL
)
7096 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7098 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7099 sig_entry
->per_cu
.tu_read
= 1;
7103 /* Subroutine of lookup_signatured_type.
7104 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7105 then try the DWP file. If the TU stub (skeleton) has been removed then
7106 it won't be in .gdb_index. */
7108 static struct signatured_type
*
7109 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7111 struct dwarf2_per_objfile
*dwarf2_per_objfile
7112 = cu
->per_cu
->dwarf2_per_objfile
;
7113 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7114 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7115 struct dwo_unit
*dwo_entry
;
7116 struct signatured_type find_sig_entry
, *sig_entry
;
7119 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7120 gdb_assert (dwp_file
!= NULL
);
7122 /* If TU skeletons have been removed then we may not have read in any
7124 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7126 dwarf2_per_objfile
->signatured_types
7127 = allocate_signatured_type_table (objfile
);
7130 find_sig_entry
.signature
= sig
;
7131 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7132 &find_sig_entry
, INSERT
);
7133 sig_entry
= (struct signatured_type
*) *slot
;
7135 /* Have we already tried to read this TU?
7136 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7137 needn't exist in the global table yet). */
7138 if (sig_entry
!= NULL
)
7141 if (dwp_file
->tus
== NULL
)
7143 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7144 sig
, 1 /* is_debug_types */);
7145 if (dwo_entry
== NULL
)
7148 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7149 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7154 /* Lookup a signature based type for DW_FORM_ref_sig8.
7155 Returns NULL if signature SIG is not present in the table.
7156 It is up to the caller to complain about this. */
7158 static struct signatured_type
*
7159 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7161 struct dwarf2_per_objfile
*dwarf2_per_objfile
7162 = cu
->per_cu
->dwarf2_per_objfile
;
7165 && dwarf2_per_objfile
->using_index
)
7167 /* We're in a DWO/DWP file, and we're using .gdb_index.
7168 These cases require special processing. */
7169 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7170 return lookup_dwo_signatured_type (cu
, sig
);
7172 return lookup_dwp_signatured_type (cu
, sig
);
7176 struct signatured_type find_entry
, *entry
;
7178 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7180 find_entry
.signature
= sig
;
7181 entry
= ((struct signatured_type
*)
7182 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7187 /* Low level DIE reading support. */
7189 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7192 init_cu_die_reader (struct die_reader_specs
*reader
,
7193 struct dwarf2_cu
*cu
,
7194 struct dwarf2_section_info
*section
,
7195 struct dwo_file
*dwo_file
,
7196 struct abbrev_table
*abbrev_table
)
7198 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7199 reader
->abfd
= get_section_bfd_owner (section
);
7201 reader
->dwo_file
= dwo_file
;
7202 reader
->die_section
= section
;
7203 reader
->buffer
= section
->buffer
;
7204 reader
->buffer_end
= section
->buffer
+ section
->size
;
7205 reader
->comp_dir
= NULL
;
7206 reader
->abbrev_table
= abbrev_table
;
7209 /* Subroutine of init_cutu_and_read_dies to simplify it.
7210 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7211 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7214 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7215 from it to the DIE in the DWO. If NULL we are skipping the stub.
7216 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7217 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7218 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7219 STUB_COMP_DIR may be non-NULL.
7220 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7221 are filled in with the info of the DIE from the DWO file.
7222 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7223 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7224 kept around for at least as long as *RESULT_READER.
7226 The result is non-zero if a valid (non-dummy) DIE was found. */
7229 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7230 struct dwo_unit
*dwo_unit
,
7231 struct die_info
*stub_comp_unit_die
,
7232 const char *stub_comp_dir
,
7233 struct die_reader_specs
*result_reader
,
7234 const gdb_byte
**result_info_ptr
,
7235 struct die_info
**result_comp_unit_die
,
7236 int *result_has_children
,
7237 abbrev_table_up
*result_dwo_abbrev_table
)
7239 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7240 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7241 struct dwarf2_cu
*cu
= this_cu
->cu
;
7243 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7244 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7245 int i
,num_extra_attrs
;
7246 struct dwarf2_section_info
*dwo_abbrev_section
;
7247 struct attribute
*attr
;
7248 struct die_info
*comp_unit_die
;
7250 /* At most one of these may be provided. */
7251 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7253 /* These attributes aren't processed until later:
7254 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7255 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7256 referenced later. However, these attributes are found in the stub
7257 which we won't have later. In order to not impose this complication
7258 on the rest of the code, we read them here and copy them to the
7267 if (stub_comp_unit_die
!= NULL
)
7269 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7271 if (! this_cu
->is_debug_types
)
7272 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7273 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7274 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7275 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7276 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7278 /* There should be a DW_AT_addr_base attribute here (if needed).
7279 We need the value before we can process DW_FORM_GNU_addr_index
7280 or DW_FORM_addrx. */
7282 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7283 if (attr
!= nullptr)
7284 cu
->addr_base
= DW_UNSND (attr
);
7286 /* There should be a DW_AT_ranges_base attribute here (if needed).
7287 We need the value before we can process DW_AT_ranges. */
7288 cu
->ranges_base
= 0;
7289 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7290 if (attr
!= nullptr)
7291 cu
->ranges_base
= DW_UNSND (attr
);
7293 else if (stub_comp_dir
!= NULL
)
7295 /* Reconstruct the comp_dir attribute to simplify the code below. */
7296 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7297 comp_dir
->name
= DW_AT_comp_dir
;
7298 comp_dir
->form
= DW_FORM_string
;
7299 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7300 DW_STRING (comp_dir
) = stub_comp_dir
;
7303 /* Set up for reading the DWO CU/TU. */
7304 cu
->dwo_unit
= dwo_unit
;
7305 dwarf2_section_info
*section
= dwo_unit
->section
;
7306 dwarf2_read_section (objfile
, section
);
7307 abfd
= get_section_bfd_owner (section
);
7308 begin_info_ptr
= info_ptr
= (section
->buffer
7309 + to_underlying (dwo_unit
->sect_off
));
7310 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7312 if (this_cu
->is_debug_types
)
7314 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7316 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7317 &cu
->header
, section
,
7319 info_ptr
, rcuh_kind::TYPE
);
7320 /* This is not an assert because it can be caused by bad debug info. */
7321 if (sig_type
->signature
!= cu
->header
.signature
)
7323 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7324 " TU at offset %s [in module %s]"),
7325 hex_string (sig_type
->signature
),
7326 hex_string (cu
->header
.signature
),
7327 sect_offset_str (dwo_unit
->sect_off
),
7328 bfd_get_filename (abfd
));
7330 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7331 /* For DWOs coming from DWP files, we don't know the CU length
7332 nor the type's offset in the TU until now. */
7333 dwo_unit
->length
= get_cu_length (&cu
->header
);
7334 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7336 /* Establish the type offset that can be used to lookup the type.
7337 For DWO files, we don't know it until now. */
7338 sig_type
->type_offset_in_section
7339 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7343 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7344 &cu
->header
, section
,
7346 info_ptr
, rcuh_kind::COMPILE
);
7347 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7348 /* For DWOs coming from DWP files, we don't know the CU length
7350 dwo_unit
->length
= get_cu_length (&cu
->header
);
7353 *result_dwo_abbrev_table
7354 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7355 cu
->header
.abbrev_sect_off
);
7356 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7357 result_dwo_abbrev_table
->get ());
7359 /* Read in the die, but leave space to copy over the attributes
7360 from the stub. This has the benefit of simplifying the rest of
7361 the code - all the work to maintain the illusion of a single
7362 DW_TAG_{compile,type}_unit DIE is done here. */
7363 num_extra_attrs
= ((stmt_list
!= NULL
)
7367 + (comp_dir
!= NULL
));
7368 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7369 result_has_children
, num_extra_attrs
);
7371 /* Copy over the attributes from the stub to the DIE we just read in. */
7372 comp_unit_die
= *result_comp_unit_die
;
7373 i
= comp_unit_die
->num_attrs
;
7374 if (stmt_list
!= NULL
)
7375 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7377 comp_unit_die
->attrs
[i
++] = *low_pc
;
7378 if (high_pc
!= NULL
)
7379 comp_unit_die
->attrs
[i
++] = *high_pc
;
7381 comp_unit_die
->attrs
[i
++] = *ranges
;
7382 if (comp_dir
!= NULL
)
7383 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7384 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7386 if (dwarf_die_debug
)
7388 fprintf_unfiltered (gdb_stdlog
,
7389 "Read die from %s@0x%x of %s:\n",
7390 get_section_name (section
),
7391 (unsigned) (begin_info_ptr
- section
->buffer
),
7392 bfd_get_filename (abfd
));
7393 dump_die (comp_unit_die
, dwarf_die_debug
);
7396 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7397 TUs by skipping the stub and going directly to the entry in the DWO file.
7398 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7399 to get it via circuitous means. Blech. */
7400 if (comp_dir
!= NULL
)
7401 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7403 /* Skip dummy compilation units. */
7404 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7405 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7408 *result_info_ptr
= info_ptr
;
7412 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7413 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7414 signature is part of the header. */
7415 static gdb::optional
<ULONGEST
>
7416 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7418 if (cu
->header
.version
>= 5)
7419 return cu
->header
.signature
;
7420 struct attribute
*attr
;
7421 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7422 if (attr
== nullptr)
7423 return gdb::optional
<ULONGEST
> ();
7424 return DW_UNSND (attr
);
7427 /* Subroutine of init_cutu_and_read_dies to simplify it.
7428 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7429 Returns NULL if the specified DWO unit cannot be found. */
7431 static struct dwo_unit
*
7432 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7433 struct die_info
*comp_unit_die
)
7435 struct dwarf2_cu
*cu
= this_cu
->cu
;
7436 struct dwo_unit
*dwo_unit
;
7437 const char *comp_dir
, *dwo_name
;
7439 gdb_assert (cu
!= NULL
);
7441 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7442 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7443 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7445 if (this_cu
->is_debug_types
)
7447 struct signatured_type
*sig_type
;
7449 /* Since this_cu is the first member of struct signatured_type,
7450 we can go from a pointer to one to a pointer to the other. */
7451 sig_type
= (struct signatured_type
*) this_cu
;
7452 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7456 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7457 if (!signature
.has_value ())
7458 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7460 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7461 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7468 /* Subroutine of init_cutu_and_read_dies to simplify it.
7469 See it for a description of the parameters.
7470 Read a TU directly from a DWO file, bypassing the stub. */
7473 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7474 int use_existing_cu
, int keep
,
7475 die_reader_func_ftype
*die_reader_func
,
7478 std::unique_ptr
<dwarf2_cu
> new_cu
;
7479 struct signatured_type
*sig_type
;
7480 struct die_reader_specs reader
;
7481 const gdb_byte
*info_ptr
;
7482 struct die_info
*comp_unit_die
;
7484 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7486 /* Verify we can do the following downcast, and that we have the
7488 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7489 sig_type
= (struct signatured_type
*) this_cu
;
7490 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7492 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7494 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7495 /* There's no need to do the rereading_dwo_cu handling that
7496 init_cutu_and_read_dies does since we don't read the stub. */
7500 /* If !use_existing_cu, this_cu->cu must be NULL. */
7501 gdb_assert (this_cu
->cu
== NULL
);
7502 new_cu
.reset (new dwarf2_cu (this_cu
));
7505 /* A future optimization, if needed, would be to use an existing
7506 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7507 could share abbrev tables. */
7509 /* The abbreviation table used by READER, this must live at least as long as
7511 abbrev_table_up dwo_abbrev_table
;
7513 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7514 NULL
/* stub_comp_unit_die */,
7515 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7517 &comp_unit_die
, &has_children
,
7518 &dwo_abbrev_table
) == 0)
7524 /* All the "real" work is done here. */
7525 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7527 /* This duplicates the code in init_cutu_and_read_dies,
7528 but the alternative is making the latter more complex.
7529 This function is only for the special case of using DWO files directly:
7530 no point in overly complicating the general case just to handle this. */
7531 if (new_cu
!= NULL
&& keep
)
7533 /* Link this CU into read_in_chain. */
7534 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7535 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7536 /* The chain owns it now. */
7541 /* Initialize a CU (or TU) and read its DIEs.
7542 If the CU defers to a DWO file, read the DWO file as well.
7544 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7545 Otherwise the table specified in the comp unit header is read in and used.
7546 This is an optimization for when we already have the abbrev table.
7548 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7549 Otherwise, a new CU is allocated with xmalloc.
7551 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7552 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7554 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7555 linker) then DIE_READER_FUNC will not get called. */
7558 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7559 struct abbrev_table
*abbrev_table
,
7560 int use_existing_cu
, int keep
,
7562 die_reader_func_ftype
*die_reader_func
,
7565 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7566 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7567 struct dwarf2_section_info
*section
= this_cu
->section
;
7568 bfd
*abfd
= get_section_bfd_owner (section
);
7569 struct dwarf2_cu
*cu
;
7570 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7571 struct die_reader_specs reader
;
7572 struct die_info
*comp_unit_die
;
7574 struct signatured_type
*sig_type
= NULL
;
7575 struct dwarf2_section_info
*abbrev_section
;
7576 /* Non-zero if CU currently points to a DWO file and we need to
7577 reread it. When this happens we need to reread the skeleton die
7578 before we can reread the DWO file (this only applies to CUs, not TUs). */
7579 int rereading_dwo_cu
= 0;
7581 if (dwarf_die_debug
)
7582 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7583 this_cu
->is_debug_types
? "type" : "comp",
7584 sect_offset_str (this_cu
->sect_off
));
7586 if (use_existing_cu
)
7589 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7590 file (instead of going through the stub), short-circuit all of this. */
7591 if (this_cu
->reading_dwo_directly
)
7593 /* Narrow down the scope of possibilities to have to understand. */
7594 gdb_assert (this_cu
->is_debug_types
);
7595 gdb_assert (abbrev_table
== NULL
);
7596 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7597 die_reader_func
, data
);
7601 /* This is cheap if the section is already read in. */
7602 dwarf2_read_section (objfile
, section
);
7604 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7606 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7608 std::unique_ptr
<dwarf2_cu
> new_cu
;
7609 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7612 /* If this CU is from a DWO file we need to start over, we need to
7613 refetch the attributes from the skeleton CU.
7614 This could be optimized by retrieving those attributes from when we
7615 were here the first time: the previous comp_unit_die was stored in
7616 comp_unit_obstack. But there's no data yet that we need this
7618 if (cu
->dwo_unit
!= NULL
)
7619 rereading_dwo_cu
= 1;
7623 /* If !use_existing_cu, this_cu->cu must be NULL. */
7624 gdb_assert (this_cu
->cu
== NULL
);
7625 new_cu
.reset (new dwarf2_cu (this_cu
));
7629 /* Get the header. */
7630 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7632 /* We already have the header, there's no need to read it in again. */
7633 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7637 if (this_cu
->is_debug_types
)
7639 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7640 &cu
->header
, section
,
7641 abbrev_section
, info_ptr
,
7644 /* Since per_cu is the first member of struct signatured_type,
7645 we can go from a pointer to one to a pointer to the other. */
7646 sig_type
= (struct signatured_type
*) this_cu
;
7647 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7648 gdb_assert (sig_type
->type_offset_in_tu
7649 == cu
->header
.type_cu_offset_in_tu
);
7650 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7652 /* LENGTH has not been set yet for type units if we're
7653 using .gdb_index. */
7654 this_cu
->length
= get_cu_length (&cu
->header
);
7656 /* Establish the type offset that can be used to lookup the type. */
7657 sig_type
->type_offset_in_section
=
7658 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7660 this_cu
->dwarf_version
= cu
->header
.version
;
7664 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7665 &cu
->header
, section
,
7668 rcuh_kind::COMPILE
);
7670 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7671 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7672 this_cu
->dwarf_version
= cu
->header
.version
;
7676 /* Skip dummy compilation units. */
7677 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7678 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7681 /* If we don't have them yet, read the abbrevs for this compilation unit.
7682 And if we need to read them now, make sure they're freed when we're
7683 done (own the table through ABBREV_TABLE_HOLDER). */
7684 abbrev_table_up abbrev_table_holder
;
7685 if (abbrev_table
!= NULL
)
7686 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7690 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7691 cu
->header
.abbrev_sect_off
);
7692 abbrev_table
= abbrev_table_holder
.get ();
7695 /* Read the top level CU/TU die. */
7696 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7697 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7699 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7702 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7703 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7704 table from the DWO file and pass the ownership over to us. It will be
7705 referenced from READER, so we must make sure to free it after we're done
7708 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7709 DWO CU, that this test will fail (the attribute will not be present). */
7710 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7711 abbrev_table_up dwo_abbrev_table
;
7712 if (dwo_name
!= nullptr)
7714 struct dwo_unit
*dwo_unit
;
7715 struct die_info
*dwo_comp_unit_die
;
7719 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7720 " has children (offset %s) [in module %s]"),
7721 sect_offset_str (this_cu
->sect_off
),
7722 bfd_get_filename (abfd
));
7724 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7725 if (dwo_unit
!= NULL
)
7727 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7728 comp_unit_die
, NULL
,
7730 &dwo_comp_unit_die
, &has_children
,
7731 &dwo_abbrev_table
) == 0)
7736 comp_unit_die
= dwo_comp_unit_die
;
7740 /* Yikes, we couldn't find the rest of the DIE, we only have
7741 the stub. A complaint has already been logged. There's
7742 not much more we can do except pass on the stub DIE to
7743 die_reader_func. We don't want to throw an error on bad
7748 /* All of the above is setup for this call. Yikes. */
7749 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7751 /* Done, clean up. */
7752 if (new_cu
!= NULL
&& keep
)
7754 /* Link this CU into read_in_chain. */
7755 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7756 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7757 /* The chain owns it now. */
7762 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7763 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7764 to have already done the lookup to find the DWO file).
7766 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7767 THIS_CU->is_debug_types, but nothing else.
7769 We fill in THIS_CU->length.
7771 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7772 linker) then DIE_READER_FUNC will not get called.
7774 THIS_CU->cu is always freed when done.
7775 This is done in order to not leave THIS_CU->cu in a state where we have
7776 to care whether it refers to the "main" CU or the DWO CU. */
7779 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7780 struct dwo_file
*dwo_file
,
7781 die_reader_func_ftype
*die_reader_func
,
7784 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7785 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7786 struct dwarf2_section_info
*section
= this_cu
->section
;
7787 bfd
*abfd
= get_section_bfd_owner (section
);
7788 struct dwarf2_section_info
*abbrev_section
;
7789 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7790 struct die_reader_specs reader
;
7791 struct die_info
*comp_unit_die
;
7794 if (dwarf_die_debug
)
7795 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7796 this_cu
->is_debug_types
? "type" : "comp",
7797 sect_offset_str (this_cu
->sect_off
));
7799 gdb_assert (this_cu
->cu
== NULL
);
7801 abbrev_section
= (dwo_file
!= NULL
7802 ? &dwo_file
->sections
.abbrev
7803 : get_abbrev_section_for_cu (this_cu
));
7805 /* This is cheap if the section is already read in. */
7806 dwarf2_read_section (objfile
, section
);
7808 struct dwarf2_cu
cu (this_cu
);
7810 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7811 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7812 &cu
.header
, section
,
7813 abbrev_section
, info_ptr
,
7814 (this_cu
->is_debug_types
7816 : rcuh_kind::COMPILE
));
7818 this_cu
->length
= get_cu_length (&cu
.header
);
7820 /* Skip dummy compilation units. */
7821 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7822 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7825 abbrev_table_up abbrev_table
7826 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7827 cu
.header
.abbrev_sect_off
);
7829 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7830 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7832 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7835 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7836 does not lookup the specified DWO file.
7837 This cannot be used to read DWO files.
7839 THIS_CU->cu is always freed when done.
7840 This is done in order to not leave THIS_CU->cu in a state where we have
7841 to care whether it refers to the "main" CU or the DWO CU.
7842 We can revisit this if the data shows there's a performance issue. */
7845 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7846 die_reader_func_ftype
*die_reader_func
,
7849 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7852 /* Type Unit Groups.
7854 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7855 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7856 so that all types coming from the same compilation (.o file) are grouped
7857 together. A future step could be to put the types in the same symtab as
7858 the CU the types ultimately came from. */
7861 hash_type_unit_group (const void *item
)
7863 const struct type_unit_group
*tu_group
7864 = (const struct type_unit_group
*) item
;
7866 return hash_stmt_list_entry (&tu_group
->hash
);
7870 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7872 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7873 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7875 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7878 /* Allocate a hash table for type unit groups. */
7881 allocate_type_unit_groups_table (struct objfile
*objfile
)
7883 return htab_create_alloc_ex (3,
7884 hash_type_unit_group
,
7887 &objfile
->objfile_obstack
,
7888 hashtab_obstack_allocate
,
7889 dummy_obstack_deallocate
);
7892 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7893 partial symtabs. We combine several TUs per psymtab to not let the size
7894 of any one psymtab grow too big. */
7895 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7896 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7898 /* Helper routine for get_type_unit_group.
7899 Create the type_unit_group object used to hold one or more TUs. */
7901 static struct type_unit_group
*
7902 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7904 struct dwarf2_per_objfile
*dwarf2_per_objfile
7905 = cu
->per_cu
->dwarf2_per_objfile
;
7906 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7907 struct dwarf2_per_cu_data
*per_cu
;
7908 struct type_unit_group
*tu_group
;
7910 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7911 struct type_unit_group
);
7912 per_cu
= &tu_group
->per_cu
;
7913 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7915 if (dwarf2_per_objfile
->using_index
)
7917 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7918 struct dwarf2_per_cu_quick_data
);
7922 unsigned int line_offset
= to_underlying (line_offset_struct
);
7923 struct partial_symtab
*pst
;
7926 /* Give the symtab a useful name for debug purposes. */
7927 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7928 name
= string_printf ("<type_units_%d>",
7929 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7931 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7933 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7937 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7938 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7943 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7944 STMT_LIST is a DW_AT_stmt_list attribute. */
7946 static struct type_unit_group
*
7947 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7949 struct dwarf2_per_objfile
*dwarf2_per_objfile
7950 = cu
->per_cu
->dwarf2_per_objfile
;
7951 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7952 struct type_unit_group
*tu_group
;
7954 unsigned int line_offset
;
7955 struct type_unit_group type_unit_group_for_lookup
;
7957 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7959 dwarf2_per_objfile
->type_unit_groups
=
7960 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7963 /* Do we need to create a new group, or can we use an existing one? */
7967 line_offset
= DW_UNSND (stmt_list
);
7968 ++tu_stats
->nr_symtab_sharers
;
7972 /* Ugh, no stmt_list. Rare, but we have to handle it.
7973 We can do various things here like create one group per TU or
7974 spread them over multiple groups to split up the expansion work.
7975 To avoid worst case scenarios (too many groups or too large groups)
7976 we, umm, group them in bunches. */
7977 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7978 | (tu_stats
->nr_stmt_less_type_units
7979 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7980 ++tu_stats
->nr_stmt_less_type_units
;
7983 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7984 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7985 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7986 &type_unit_group_for_lookup
, INSERT
);
7989 tu_group
= (struct type_unit_group
*) *slot
;
7990 gdb_assert (tu_group
!= NULL
);
7994 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7995 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7997 ++tu_stats
->nr_symtabs
;
8003 /* Partial symbol tables. */
8005 /* Create a psymtab named NAME and assign it to PER_CU.
8007 The caller must fill in the following details:
8008 dirname, textlow, texthigh. */
8010 static struct partial_symtab
*
8011 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8013 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8014 struct partial_symtab
*pst
;
8016 pst
= start_psymtab_common (objfile
, name
, 0);
8018 pst
->psymtabs_addrmap_supported
= 1;
8020 /* This is the glue that links PST into GDB's symbol API. */
8021 pst
->read_symtab_private
= per_cu
;
8022 pst
->read_symtab
= dwarf2_read_symtab
;
8023 per_cu
->v
.psymtab
= pst
;
8028 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8031 struct process_psymtab_comp_unit_data
8033 /* True if we are reading a DW_TAG_partial_unit. */
8035 int want_partial_unit
;
8037 /* The "pretend" language that is used if the CU doesn't declare a
8040 enum language pretend_language
;
8043 /* die_reader_func for process_psymtab_comp_unit. */
8046 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8047 const gdb_byte
*info_ptr
,
8048 struct die_info
*comp_unit_die
,
8052 struct dwarf2_cu
*cu
= reader
->cu
;
8053 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8054 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8055 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8057 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8058 struct partial_symtab
*pst
;
8059 enum pc_bounds_kind cu_bounds_kind
;
8060 const char *filename
;
8061 struct process_psymtab_comp_unit_data
*info
8062 = (struct process_psymtab_comp_unit_data
*) data
;
8064 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8067 gdb_assert (! per_cu
->is_debug_types
);
8069 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8071 /* Allocate a new partial symbol table structure. */
8072 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8073 if (filename
== NULL
)
8076 pst
= create_partial_symtab (per_cu
, filename
);
8078 /* This must be done before calling dwarf2_build_include_psymtabs. */
8079 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8081 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8083 dwarf2_find_base_address (comp_unit_die
, cu
);
8085 /* Possibly set the default values of LOWPC and HIGHPC from
8087 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8088 &best_highpc
, cu
, pst
);
8089 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8092 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8095 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8097 /* Store the contiguous range if it is not empty; it can be
8098 empty for CUs with no code. */
8099 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8103 /* Check if comp unit has_children.
8104 If so, read the rest of the partial symbols from this comp unit.
8105 If not, there's no more debug_info for this comp unit. */
8108 struct partial_die_info
*first_die
;
8109 CORE_ADDR lowpc
, highpc
;
8111 lowpc
= ((CORE_ADDR
) -1);
8112 highpc
= ((CORE_ADDR
) 0);
8114 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8116 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8117 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8119 /* If we didn't find a lowpc, set it to highpc to avoid
8120 complaints from `maint check'. */
8121 if (lowpc
== ((CORE_ADDR
) -1))
8124 /* If the compilation unit didn't have an explicit address range,
8125 then use the information extracted from its child dies. */
8126 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8129 best_highpc
= highpc
;
8132 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8133 best_lowpc
+ baseaddr
)
8135 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8136 best_highpc
+ baseaddr
)
8139 end_psymtab_common (objfile
, pst
);
8141 if (!cu
->per_cu
->imported_symtabs_empty ())
8144 int len
= cu
->per_cu
->imported_symtabs_size ();
8146 /* Fill in 'dependencies' here; we fill in 'users' in a
8148 pst
->number_of_dependencies
= len
;
8150 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8151 for (i
= 0; i
< len
; ++i
)
8153 pst
->dependencies
[i
]
8154 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8157 cu
->per_cu
->imported_symtabs_free ();
8160 /* Get the list of files included in the current compilation unit,
8161 and build a psymtab for each of them. */
8162 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8164 if (dwarf_read_debug
)
8165 fprintf_unfiltered (gdb_stdlog
,
8166 "Psymtab for %s unit @%s: %s - %s"
8167 ", %d global, %d static syms\n",
8168 per_cu
->is_debug_types
? "type" : "comp",
8169 sect_offset_str (per_cu
->sect_off
),
8170 paddress (gdbarch
, pst
->text_low (objfile
)),
8171 paddress (gdbarch
, pst
->text_high (objfile
)),
8172 pst
->n_global_syms
, pst
->n_static_syms
);
8175 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8176 Process compilation unit THIS_CU for a psymtab. */
8179 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8180 int want_partial_unit
,
8181 enum language pretend_language
)
8183 /* If this compilation unit was already read in, free the
8184 cached copy in order to read it in again. This is
8185 necessary because we skipped some symbols when we first
8186 read in the compilation unit (see load_partial_dies).
8187 This problem could be avoided, but the benefit is unclear. */
8188 if (this_cu
->cu
!= NULL
)
8189 free_one_cached_comp_unit (this_cu
);
8191 if (this_cu
->is_debug_types
)
8192 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8193 build_type_psymtabs_reader
, NULL
);
8196 process_psymtab_comp_unit_data info
;
8197 info
.want_partial_unit
= want_partial_unit
;
8198 info
.pretend_language
= pretend_language
;
8199 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8200 process_psymtab_comp_unit_reader
, &info
);
8203 /* Age out any secondary CUs. */
8204 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8207 /* Reader function for build_type_psymtabs. */
8210 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8211 const gdb_byte
*info_ptr
,
8212 struct die_info
*type_unit_die
,
8216 struct dwarf2_per_objfile
*dwarf2_per_objfile
8217 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8218 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8219 struct dwarf2_cu
*cu
= reader
->cu
;
8220 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8221 struct signatured_type
*sig_type
;
8222 struct type_unit_group
*tu_group
;
8223 struct attribute
*attr
;
8224 struct partial_die_info
*first_die
;
8225 CORE_ADDR lowpc
, highpc
;
8226 struct partial_symtab
*pst
;
8228 gdb_assert (data
== NULL
);
8229 gdb_assert (per_cu
->is_debug_types
);
8230 sig_type
= (struct signatured_type
*) per_cu
;
8235 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8236 tu_group
= get_type_unit_group (cu
, attr
);
8238 if (tu_group
->tus
== nullptr)
8239 tu_group
->tus
= new std::vector
<signatured_type
*>;
8240 tu_group
->tus
->push_back (sig_type
);
8242 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8243 pst
= create_partial_symtab (per_cu
, "");
8246 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8248 lowpc
= (CORE_ADDR
) -1;
8249 highpc
= (CORE_ADDR
) 0;
8250 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8252 end_psymtab_common (objfile
, pst
);
8255 /* Struct used to sort TUs by their abbreviation table offset. */
8257 struct tu_abbrev_offset
8259 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8260 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8263 signatured_type
*sig_type
;
8264 sect_offset abbrev_offset
;
8267 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8270 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8271 const struct tu_abbrev_offset
&b
)
8273 return a
.abbrev_offset
< b
.abbrev_offset
;
8276 /* Efficiently read all the type units.
8277 This does the bulk of the work for build_type_psymtabs.
8279 The efficiency is because we sort TUs by the abbrev table they use and
8280 only read each abbrev table once. In one program there are 200K TUs
8281 sharing 8K abbrev tables.
8283 The main purpose of this function is to support building the
8284 dwarf2_per_objfile->type_unit_groups table.
8285 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8286 can collapse the search space by grouping them by stmt_list.
8287 The savings can be significant, in the same program from above the 200K TUs
8288 share 8K stmt_list tables.
8290 FUNC is expected to call get_type_unit_group, which will create the
8291 struct type_unit_group if necessary and add it to
8292 dwarf2_per_objfile->type_unit_groups. */
8295 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8297 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8298 abbrev_table_up abbrev_table
;
8299 sect_offset abbrev_offset
;
8301 /* It's up to the caller to not call us multiple times. */
8302 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8304 if (dwarf2_per_objfile
->all_type_units
.empty ())
8307 /* TUs typically share abbrev tables, and there can be way more TUs than
8308 abbrev tables. Sort by abbrev table to reduce the number of times we
8309 read each abbrev table in.
8310 Alternatives are to punt or to maintain a cache of abbrev tables.
8311 This is simpler and efficient enough for now.
8313 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8314 symtab to use). Typically TUs with the same abbrev offset have the same
8315 stmt_list value too so in practice this should work well.
8317 The basic algorithm here is:
8319 sort TUs by abbrev table
8320 for each TU with same abbrev table:
8321 read abbrev table if first user
8322 read TU top level DIE
8323 [IWBN if DWO skeletons had DW_AT_stmt_list]
8326 if (dwarf_read_debug
)
8327 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8329 /* Sort in a separate table to maintain the order of all_type_units
8330 for .gdb_index: TU indices directly index all_type_units. */
8331 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8332 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8334 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8335 sorted_by_abbrev
.emplace_back
8336 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8337 sig_type
->per_cu
.section
,
8338 sig_type
->per_cu
.sect_off
));
8340 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8341 sort_tu_by_abbrev_offset
);
8343 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8345 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8347 /* Switch to the next abbrev table if necessary. */
8348 if (abbrev_table
== NULL
8349 || tu
.abbrev_offset
!= abbrev_offset
)
8351 abbrev_offset
= tu
.abbrev_offset
;
8353 abbrev_table_read_table (dwarf2_per_objfile
,
8354 &dwarf2_per_objfile
->abbrev
,
8356 ++tu_stats
->nr_uniq_abbrev_tables
;
8359 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8360 0, 0, false, build_type_psymtabs_reader
, NULL
);
8364 /* Print collected type unit statistics. */
8367 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8369 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8371 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8372 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8373 dwarf2_per_objfile
->all_type_units
.size ());
8374 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8375 tu_stats
->nr_uniq_abbrev_tables
);
8376 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8377 tu_stats
->nr_symtabs
);
8378 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8379 tu_stats
->nr_symtab_sharers
);
8380 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8381 tu_stats
->nr_stmt_less_type_units
);
8382 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8383 tu_stats
->nr_all_type_units_reallocs
);
8386 /* Traversal function for build_type_psymtabs. */
8389 build_type_psymtab_dependencies (void **slot
, void *info
)
8391 struct dwarf2_per_objfile
*dwarf2_per_objfile
8392 = (struct dwarf2_per_objfile
*) info
;
8393 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8394 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8395 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8396 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8397 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8400 gdb_assert (len
> 0);
8401 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8403 pst
->number_of_dependencies
= len
;
8404 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8405 for (i
= 0; i
< len
; ++i
)
8407 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8408 gdb_assert (iter
->per_cu
.is_debug_types
);
8409 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8410 iter
->type_unit_group
= tu_group
;
8413 delete tu_group
->tus
;
8414 tu_group
->tus
= nullptr;
8419 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8420 Build partial symbol tables for the .debug_types comp-units. */
8423 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8425 if (! create_all_type_units (dwarf2_per_objfile
))
8428 build_type_psymtabs_1 (dwarf2_per_objfile
);
8431 /* Traversal function for process_skeletonless_type_unit.
8432 Read a TU in a DWO file and build partial symbols for it. */
8435 process_skeletonless_type_unit (void **slot
, void *info
)
8437 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8438 struct dwarf2_per_objfile
*dwarf2_per_objfile
8439 = (struct dwarf2_per_objfile
*) info
;
8440 struct signatured_type find_entry
, *entry
;
8442 /* If this TU doesn't exist in the global table, add it and read it in. */
8444 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8446 dwarf2_per_objfile
->signatured_types
8447 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8450 find_entry
.signature
= dwo_unit
->signature
;
8451 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8453 /* If we've already seen this type there's nothing to do. What's happening
8454 is we're doing our own version of comdat-folding here. */
8458 /* This does the job that create_all_type_units would have done for
8460 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8461 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8464 /* This does the job that build_type_psymtabs_1 would have done. */
8465 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8466 build_type_psymtabs_reader
, NULL
);
8471 /* Traversal function for process_skeletonless_type_units. */
8474 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8476 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8478 if (dwo_file
->tus
!= NULL
)
8480 htab_traverse_noresize (dwo_file
->tus
,
8481 process_skeletonless_type_unit
, info
);
8487 /* Scan all TUs of DWO files, verifying we've processed them.
8488 This is needed in case a TU was emitted without its skeleton.
8489 Note: This can't be done until we know what all the DWO files are. */
8492 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8494 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8495 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8496 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8498 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8499 process_dwo_file_for_skeletonless_type_units
,
8500 dwarf2_per_objfile
);
8504 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8507 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8509 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8511 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8516 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8518 /* Set the 'user' field only if it is not already set. */
8519 if (pst
->dependencies
[j
]->user
== NULL
)
8520 pst
->dependencies
[j
]->user
= pst
;
8525 /* Build the partial symbol table by doing a quick pass through the
8526 .debug_info and .debug_abbrev sections. */
8529 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8531 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8533 if (dwarf_read_debug
)
8535 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8536 objfile_name (objfile
));
8539 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8541 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8543 /* Any cached compilation units will be linked by the per-objfile
8544 read_in_chain. Make sure to free them when we're done. */
8545 free_cached_comp_units
freer (dwarf2_per_objfile
);
8547 build_type_psymtabs (dwarf2_per_objfile
);
8549 create_all_comp_units (dwarf2_per_objfile
);
8551 /* Create a temporary address map on a temporary obstack. We later
8552 copy this to the final obstack. */
8553 auto_obstack temp_obstack
;
8555 scoped_restore save_psymtabs_addrmap
8556 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8557 addrmap_create_mutable (&temp_obstack
));
8559 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8560 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8562 /* This has to wait until we read the CUs, we need the list of DWOs. */
8563 process_skeletonless_type_units (dwarf2_per_objfile
);
8565 /* Now that all TUs have been processed we can fill in the dependencies. */
8566 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8568 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8569 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8572 if (dwarf_read_debug
)
8573 print_tu_stats (dwarf2_per_objfile
);
8575 set_partial_user (dwarf2_per_objfile
);
8577 objfile
->partial_symtabs
->psymtabs_addrmap
8578 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8579 objfile
->partial_symtabs
->obstack ());
8580 /* At this point we want to keep the address map. */
8581 save_psymtabs_addrmap
.release ();
8583 if (dwarf_read_debug
)
8584 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8585 objfile_name (objfile
));
8588 /* die_reader_func for load_partial_comp_unit. */
8591 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8592 const gdb_byte
*info_ptr
,
8593 struct die_info
*comp_unit_die
,
8597 struct dwarf2_cu
*cu
= reader
->cu
;
8599 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8601 /* Check if comp unit has_children.
8602 If so, read the rest of the partial symbols from this comp unit.
8603 If not, there's no more debug_info for this comp unit. */
8605 load_partial_dies (reader
, info_ptr
, 0);
8608 /* Load the partial DIEs for a secondary CU into memory.
8609 This is also used when rereading a primary CU with load_all_dies. */
8612 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8614 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8615 load_partial_comp_unit_reader
, NULL
);
8619 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8620 struct dwarf2_section_info
*section
,
8621 struct dwarf2_section_info
*abbrev_section
,
8622 unsigned int is_dwz
)
8624 const gdb_byte
*info_ptr
;
8625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8627 if (dwarf_read_debug
)
8628 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8629 get_section_name (section
),
8630 get_section_file_name (section
));
8632 dwarf2_read_section (objfile
, section
);
8634 info_ptr
= section
->buffer
;
8636 while (info_ptr
< section
->buffer
+ section
->size
)
8638 struct dwarf2_per_cu_data
*this_cu
;
8640 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8642 comp_unit_head cu_header
;
8643 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8644 abbrev_section
, info_ptr
,
8645 rcuh_kind::COMPILE
);
8647 /* Save the compilation unit for later lookup. */
8648 if (cu_header
.unit_type
!= DW_UT_type
)
8650 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8651 struct dwarf2_per_cu_data
);
8652 memset (this_cu
, 0, sizeof (*this_cu
));
8656 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8657 struct signatured_type
);
8658 memset (sig_type
, 0, sizeof (*sig_type
));
8659 sig_type
->signature
= cu_header
.signature
;
8660 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8661 this_cu
= &sig_type
->per_cu
;
8663 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8664 this_cu
->sect_off
= sect_off
;
8665 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8666 this_cu
->is_dwz
= is_dwz
;
8667 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8668 this_cu
->section
= section
;
8670 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8672 info_ptr
= info_ptr
+ this_cu
->length
;
8676 /* Create a list of all compilation units in OBJFILE.
8677 This is only done for -readnow and building partial symtabs. */
8680 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8682 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8683 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8684 &dwarf2_per_objfile
->abbrev
, 0);
8686 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8688 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8692 /* Process all loaded DIEs for compilation unit CU, starting at
8693 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8694 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8695 DW_AT_ranges). See the comments of add_partial_subprogram on how
8696 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8699 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8700 CORE_ADDR
*highpc
, int set_addrmap
,
8701 struct dwarf2_cu
*cu
)
8703 struct partial_die_info
*pdi
;
8705 /* Now, march along the PDI's, descending into ones which have
8706 interesting children but skipping the children of the other ones,
8707 until we reach the end of the compilation unit. */
8715 /* Anonymous namespaces or modules have no name but have interesting
8716 children, so we need to look at them. Ditto for anonymous
8719 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8720 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8721 || pdi
->tag
== DW_TAG_imported_unit
8722 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8726 case DW_TAG_subprogram
:
8727 case DW_TAG_inlined_subroutine
:
8728 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8730 case DW_TAG_constant
:
8731 case DW_TAG_variable
:
8732 case DW_TAG_typedef
:
8733 case DW_TAG_union_type
:
8734 if (!pdi
->is_declaration
)
8736 add_partial_symbol (pdi
, cu
);
8739 case DW_TAG_class_type
:
8740 case DW_TAG_interface_type
:
8741 case DW_TAG_structure_type
:
8742 if (!pdi
->is_declaration
)
8744 add_partial_symbol (pdi
, cu
);
8746 if ((cu
->language
== language_rust
8747 || cu
->language
== language_cplus
) && pdi
->has_children
)
8748 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8751 case DW_TAG_enumeration_type
:
8752 if (!pdi
->is_declaration
)
8753 add_partial_enumeration (pdi
, cu
);
8755 case DW_TAG_base_type
:
8756 case DW_TAG_subrange_type
:
8757 /* File scope base type definitions are added to the partial
8759 add_partial_symbol (pdi
, cu
);
8761 case DW_TAG_namespace
:
8762 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8765 if (!pdi
->is_declaration
)
8766 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8768 case DW_TAG_imported_unit
:
8770 struct dwarf2_per_cu_data
*per_cu
;
8772 /* For now we don't handle imported units in type units. */
8773 if (cu
->per_cu
->is_debug_types
)
8775 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8776 " supported in type units [in module %s]"),
8777 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8780 per_cu
= dwarf2_find_containing_comp_unit
8781 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8782 cu
->per_cu
->dwarf2_per_objfile
);
8784 /* Go read the partial unit, if needed. */
8785 if (per_cu
->v
.psymtab
== NULL
)
8786 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8788 cu
->per_cu
->imported_symtabs_push (per_cu
);
8791 case DW_TAG_imported_declaration
:
8792 add_partial_symbol (pdi
, cu
);
8799 /* If the die has a sibling, skip to the sibling. */
8801 pdi
= pdi
->die_sibling
;
8805 /* Functions used to compute the fully scoped name of a partial DIE.
8807 Normally, this is simple. For C++, the parent DIE's fully scoped
8808 name is concatenated with "::" and the partial DIE's name.
8809 Enumerators are an exception; they use the scope of their parent
8810 enumeration type, i.e. the name of the enumeration type is not
8811 prepended to the enumerator.
8813 There are two complexities. One is DW_AT_specification; in this
8814 case "parent" means the parent of the target of the specification,
8815 instead of the direct parent of the DIE. The other is compilers
8816 which do not emit DW_TAG_namespace; in this case we try to guess
8817 the fully qualified name of structure types from their members'
8818 linkage names. This must be done using the DIE's children rather
8819 than the children of any DW_AT_specification target. We only need
8820 to do this for structures at the top level, i.e. if the target of
8821 any DW_AT_specification (if any; otherwise the DIE itself) does not
8824 /* Compute the scope prefix associated with PDI's parent, in
8825 compilation unit CU. The result will be allocated on CU's
8826 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8827 field. NULL is returned if no prefix is necessary. */
8829 partial_die_parent_scope (struct partial_die_info
*pdi
,
8830 struct dwarf2_cu
*cu
)
8832 const char *grandparent_scope
;
8833 struct partial_die_info
*parent
, *real_pdi
;
8835 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8836 then this means the parent of the specification DIE. */
8839 while (real_pdi
->has_specification
)
8841 auto res
= find_partial_die (real_pdi
->spec_offset
,
8842 real_pdi
->spec_is_dwz
, cu
);
8847 parent
= real_pdi
->die_parent
;
8851 if (parent
->scope_set
)
8852 return parent
->scope
;
8856 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8858 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8859 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8860 Work around this problem here. */
8861 if (cu
->language
== language_cplus
8862 && parent
->tag
== DW_TAG_namespace
8863 && strcmp (parent
->name
, "::") == 0
8864 && grandparent_scope
== NULL
)
8866 parent
->scope
= NULL
;
8867 parent
->scope_set
= 1;
8871 /* Nested subroutines in Fortran get a prefix. */
8872 if (pdi
->tag
== DW_TAG_enumerator
)
8873 /* Enumerators should not get the name of the enumeration as a prefix. */
8874 parent
->scope
= grandparent_scope
;
8875 else if (parent
->tag
== DW_TAG_namespace
8876 || parent
->tag
== DW_TAG_module
8877 || parent
->tag
== DW_TAG_structure_type
8878 || parent
->tag
== DW_TAG_class_type
8879 || parent
->tag
== DW_TAG_interface_type
8880 || parent
->tag
== DW_TAG_union_type
8881 || parent
->tag
== DW_TAG_enumeration_type
8882 || (cu
->language
== language_fortran
8883 && parent
->tag
== DW_TAG_subprogram
8884 && pdi
->tag
== DW_TAG_subprogram
))
8886 if (grandparent_scope
== NULL
)
8887 parent
->scope
= parent
->name
;
8889 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8891 parent
->name
, 0, cu
);
8895 /* FIXME drow/2004-04-01: What should we be doing with
8896 function-local names? For partial symbols, we should probably be
8898 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8899 dwarf_tag_name (parent
->tag
),
8900 sect_offset_str (pdi
->sect_off
));
8901 parent
->scope
= grandparent_scope
;
8904 parent
->scope_set
= 1;
8905 return parent
->scope
;
8908 /* Return the fully scoped name associated with PDI, from compilation unit
8909 CU. The result will be allocated with malloc. */
8912 partial_die_full_name (struct partial_die_info
*pdi
,
8913 struct dwarf2_cu
*cu
)
8915 const char *parent_scope
;
8917 /* If this is a template instantiation, we can not work out the
8918 template arguments from partial DIEs. So, unfortunately, we have
8919 to go through the full DIEs. At least any work we do building
8920 types here will be reused if full symbols are loaded later. */
8921 if (pdi
->has_template_arguments
)
8925 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8927 struct die_info
*die
;
8928 struct attribute attr
;
8929 struct dwarf2_cu
*ref_cu
= cu
;
8931 /* DW_FORM_ref_addr is using section offset. */
8932 attr
.name
= (enum dwarf_attribute
) 0;
8933 attr
.form
= DW_FORM_ref_addr
;
8934 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8935 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8937 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8941 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8942 if (parent_scope
== NULL
)
8945 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8949 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8951 struct dwarf2_per_objfile
*dwarf2_per_objfile
8952 = cu
->per_cu
->dwarf2_per_objfile
;
8953 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8954 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8956 const char *actual_name
= NULL
;
8958 char *built_actual_name
;
8960 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8962 built_actual_name
= partial_die_full_name (pdi
, cu
);
8963 if (built_actual_name
!= NULL
)
8964 actual_name
= built_actual_name
;
8966 if (actual_name
== NULL
)
8967 actual_name
= pdi
->name
;
8971 case DW_TAG_inlined_subroutine
:
8972 case DW_TAG_subprogram
:
8973 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8975 if (pdi
->is_external
8976 || cu
->language
== language_ada
8977 || (cu
->language
== language_fortran
8978 && pdi
->die_parent
!= NULL
8979 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8981 /* Normally, only "external" DIEs are part of the global scope.
8982 But in Ada and Fortran, we want to be able to access nested
8983 procedures globally. So all Ada and Fortran subprograms are
8984 stored in the global scope. */
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::GLOBAL
,
8991 cu
->language
, objfile
);
8995 add_psymbol_to_list (actual_name
,
8996 built_actual_name
!= NULL
,
8997 VAR_DOMAIN
, LOC_BLOCK
,
8998 SECT_OFF_TEXT (objfile
),
8999 psymbol_placement::STATIC
,
9000 addr
, cu
->language
, objfile
);
9003 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
9004 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
9006 case DW_TAG_constant
:
9007 add_psymbol_to_list (actual_name
,
9008 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9009 -1, (pdi
->is_external
9010 ? psymbol_placement::GLOBAL
9011 : psymbol_placement::STATIC
),
9012 0, cu
->language
, objfile
);
9014 case DW_TAG_variable
:
9016 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9020 && !dwarf2_per_objfile
->has_section_at_zero
)
9022 /* A global or static variable may also have been stripped
9023 out by the linker if unused, in which case its address
9024 will be nullified; do not add such variables into partial
9025 symbol table then. */
9027 else if (pdi
->is_external
)
9030 Don't enter into the minimal symbol tables as there is
9031 a minimal symbol table entry from the ELF symbols already.
9032 Enter into partial symbol table if it has a location
9033 descriptor or a type.
9034 If the location descriptor is missing, new_symbol will create
9035 a LOC_UNRESOLVED symbol, the address of the variable will then
9036 be determined from the minimal symbol table whenever the variable
9038 The address for the partial symbol table entry is not
9039 used by GDB, but it comes in handy for debugging partial symbol
9042 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9043 add_psymbol_to_list (actual_name
,
9044 built_actual_name
!= NULL
,
9045 VAR_DOMAIN
, LOC_STATIC
,
9046 SECT_OFF_TEXT (objfile
),
9047 psymbol_placement::GLOBAL
,
9048 addr
, cu
->language
, objfile
);
9052 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9054 /* Static Variable. Skip symbols whose value we cannot know (those
9055 without location descriptors or constant values). */
9056 if (!has_loc
&& !pdi
->has_const_value
)
9058 xfree (built_actual_name
);
9062 add_psymbol_to_list (actual_name
,
9063 built_actual_name
!= NULL
,
9064 VAR_DOMAIN
, LOC_STATIC
,
9065 SECT_OFF_TEXT (objfile
),
9066 psymbol_placement::STATIC
,
9068 cu
->language
, objfile
);
9071 case DW_TAG_typedef
:
9072 case DW_TAG_base_type
:
9073 case DW_TAG_subrange_type
:
9074 add_psymbol_to_list (actual_name
,
9075 built_actual_name
!= NULL
,
9076 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9077 psymbol_placement::STATIC
,
9078 0, cu
->language
, objfile
);
9080 case DW_TAG_imported_declaration
:
9081 case DW_TAG_namespace
:
9082 add_psymbol_to_list (actual_name
,
9083 built_actual_name
!= NULL
,
9084 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9085 psymbol_placement::GLOBAL
,
9086 0, cu
->language
, objfile
);
9089 /* With Fortran 77 there might be a "BLOCK DATA" module
9090 available without any name. If so, we skip the module as it
9091 doesn't bring any value. */
9092 if (actual_name
!= nullptr)
9093 add_psymbol_to_list (actual_name
,
9094 built_actual_name
!= NULL
,
9095 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9096 psymbol_placement::GLOBAL
,
9097 0, cu
->language
, objfile
);
9099 case DW_TAG_class_type
:
9100 case DW_TAG_interface_type
:
9101 case DW_TAG_structure_type
:
9102 case DW_TAG_union_type
:
9103 case DW_TAG_enumeration_type
:
9104 /* Skip external references. The DWARF standard says in the section
9105 about "Structure, Union, and Class Type Entries": "An incomplete
9106 structure, union or class type is represented by a structure,
9107 union or class entry that does not have a byte size attribute
9108 and that has a DW_AT_declaration attribute." */
9109 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9111 xfree (built_actual_name
);
9115 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9116 static vs. global. */
9117 add_psymbol_to_list (actual_name
,
9118 built_actual_name
!= NULL
,
9119 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9120 cu
->language
== language_cplus
9121 ? psymbol_placement::GLOBAL
9122 : psymbol_placement::STATIC
,
9123 0, cu
->language
, objfile
);
9126 case DW_TAG_enumerator
:
9127 add_psymbol_to_list (actual_name
,
9128 built_actual_name
!= NULL
,
9129 VAR_DOMAIN
, LOC_CONST
, -1,
9130 cu
->language
== language_cplus
9131 ? psymbol_placement::GLOBAL
9132 : psymbol_placement::STATIC
,
9133 0, cu
->language
, objfile
);
9139 xfree (built_actual_name
);
9142 /* Read a partial die corresponding to a namespace; also, add a symbol
9143 corresponding to that namespace to the symbol table. NAMESPACE is
9144 the name of the enclosing namespace. */
9147 add_partial_namespace (struct partial_die_info
*pdi
,
9148 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9149 int set_addrmap
, struct dwarf2_cu
*cu
)
9151 /* Add a symbol for the namespace. */
9153 add_partial_symbol (pdi
, cu
);
9155 /* Now scan partial symbols in that namespace. */
9157 if (pdi
->has_children
)
9158 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9161 /* Read a partial die corresponding to a Fortran module. */
9164 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9165 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9167 /* Add a symbol for the namespace. */
9169 add_partial_symbol (pdi
, cu
);
9171 /* Now scan partial symbols in that module. */
9173 if (pdi
->has_children
)
9174 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9177 /* Read a partial die corresponding to a subprogram or an inlined
9178 subprogram and create a partial symbol for that subprogram.
9179 When the CU language allows it, this routine also defines a partial
9180 symbol for each nested subprogram that this subprogram contains.
9181 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9182 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9184 PDI may also be a lexical block, in which case we simply search
9185 recursively for subprograms defined inside that lexical block.
9186 Again, this is only performed when the CU language allows this
9187 type of definitions. */
9190 add_partial_subprogram (struct partial_die_info
*pdi
,
9191 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9192 int set_addrmap
, struct dwarf2_cu
*cu
)
9194 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9196 if (pdi
->has_pc_info
)
9198 if (pdi
->lowpc
< *lowpc
)
9199 *lowpc
= pdi
->lowpc
;
9200 if (pdi
->highpc
> *highpc
)
9201 *highpc
= pdi
->highpc
;
9204 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9205 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9207 CORE_ADDR this_highpc
;
9208 CORE_ADDR this_lowpc
;
9210 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9211 SECT_OFF_TEXT (objfile
));
9213 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9214 pdi
->lowpc
+ baseaddr
)
9217 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9218 pdi
->highpc
+ baseaddr
)
9220 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9221 this_lowpc
, this_highpc
- 1,
9222 cu
->per_cu
->v
.psymtab
);
9226 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9228 if (!pdi
->is_declaration
)
9229 /* Ignore subprogram DIEs that do not have a name, they are
9230 illegal. Do not emit a complaint at this point, we will
9231 do so when we convert this psymtab into a symtab. */
9233 add_partial_symbol (pdi
, cu
);
9237 if (! pdi
->has_children
)
9240 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9242 pdi
= pdi
->die_child
;
9246 if (pdi
->tag
== DW_TAG_subprogram
9247 || pdi
->tag
== DW_TAG_inlined_subroutine
9248 || pdi
->tag
== DW_TAG_lexical_block
)
9249 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9250 pdi
= pdi
->die_sibling
;
9255 /* Read a partial die corresponding to an enumeration type. */
9258 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9259 struct dwarf2_cu
*cu
)
9261 struct partial_die_info
*pdi
;
9263 if (enum_pdi
->name
!= NULL
)
9264 add_partial_symbol (enum_pdi
, cu
);
9266 pdi
= enum_pdi
->die_child
;
9269 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9270 complaint (_("malformed enumerator DIE ignored"));
9272 add_partial_symbol (pdi
, cu
);
9273 pdi
= pdi
->die_sibling
;
9277 /* Return the initial uleb128 in the die at INFO_PTR. */
9280 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9282 unsigned int bytes_read
;
9284 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9287 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9288 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9290 Return the corresponding abbrev, or NULL if the number is zero (indicating
9291 an empty DIE). In either case *BYTES_READ will be set to the length of
9292 the initial number. */
9294 static struct abbrev_info
*
9295 peek_die_abbrev (const die_reader_specs
&reader
,
9296 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9298 dwarf2_cu
*cu
= reader
.cu
;
9299 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9300 unsigned int abbrev_number
9301 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9303 if (abbrev_number
== 0)
9306 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9309 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9310 " at offset %s [in module %s]"),
9311 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9312 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9318 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9319 Returns a pointer to the end of a series of DIEs, terminated by an empty
9320 DIE. Any children of the skipped DIEs will also be skipped. */
9322 static const gdb_byte
*
9323 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9327 unsigned int bytes_read
;
9328 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9331 return info_ptr
+ bytes_read
;
9333 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9337 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9338 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9339 abbrev corresponding to that skipped uleb128 should be passed in
9340 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9343 static const gdb_byte
*
9344 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9345 struct abbrev_info
*abbrev
)
9347 unsigned int bytes_read
;
9348 struct attribute attr
;
9349 bfd
*abfd
= reader
->abfd
;
9350 struct dwarf2_cu
*cu
= reader
->cu
;
9351 const gdb_byte
*buffer
= reader
->buffer
;
9352 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9353 unsigned int form
, i
;
9355 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9357 /* The only abbrev we care about is DW_AT_sibling. */
9358 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9360 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9361 if (attr
.form
== DW_FORM_ref_addr
)
9362 complaint (_("ignoring absolute DW_AT_sibling"));
9365 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9366 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9368 if (sibling_ptr
< info_ptr
)
9369 complaint (_("DW_AT_sibling points backwards"));
9370 else if (sibling_ptr
> reader
->buffer_end
)
9371 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9377 /* If it isn't DW_AT_sibling, skip this attribute. */
9378 form
= abbrev
->attrs
[i
].form
;
9382 case DW_FORM_ref_addr
:
9383 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9384 and later it is offset sized. */
9385 if (cu
->header
.version
== 2)
9386 info_ptr
+= cu
->header
.addr_size
;
9388 info_ptr
+= cu
->header
.offset_size
;
9390 case DW_FORM_GNU_ref_alt
:
9391 info_ptr
+= cu
->header
.offset_size
;
9394 info_ptr
+= cu
->header
.addr_size
;
9402 case DW_FORM_flag_present
:
9403 case DW_FORM_implicit_const
:
9420 case DW_FORM_ref_sig8
:
9423 case DW_FORM_data16
:
9426 case DW_FORM_string
:
9427 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9428 info_ptr
+= bytes_read
;
9430 case DW_FORM_sec_offset
:
9432 case DW_FORM_GNU_strp_alt
:
9433 info_ptr
+= cu
->header
.offset_size
;
9435 case DW_FORM_exprloc
:
9437 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9438 info_ptr
+= bytes_read
;
9440 case DW_FORM_block1
:
9441 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9443 case DW_FORM_block2
:
9444 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9446 case DW_FORM_block4
:
9447 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9453 case DW_FORM_ref_udata
:
9454 case DW_FORM_GNU_addr_index
:
9455 case DW_FORM_GNU_str_index
:
9456 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9458 case DW_FORM_indirect
:
9459 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9460 info_ptr
+= bytes_read
;
9461 /* We need to continue parsing from here, so just go back to
9463 goto skip_attribute
;
9466 error (_("Dwarf Error: Cannot handle %s "
9467 "in DWARF reader [in module %s]"),
9468 dwarf_form_name (form
),
9469 bfd_get_filename (abfd
));
9473 if (abbrev
->has_children
)
9474 return skip_children (reader
, info_ptr
);
9479 /* Locate ORIG_PDI's sibling.
9480 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9482 static const gdb_byte
*
9483 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9484 struct partial_die_info
*orig_pdi
,
9485 const gdb_byte
*info_ptr
)
9487 /* Do we know the sibling already? */
9489 if (orig_pdi
->sibling
)
9490 return orig_pdi
->sibling
;
9492 /* Are there any children to deal with? */
9494 if (!orig_pdi
->has_children
)
9497 /* Skip the children the long way. */
9499 return skip_children (reader
, info_ptr
);
9502 /* Expand this partial symbol table into a full symbol table. SELF is
9506 dwarf2_read_symtab (struct partial_symtab
*self
,
9507 struct objfile
*objfile
)
9509 struct dwarf2_per_objfile
*dwarf2_per_objfile
9510 = get_dwarf2_per_objfile (objfile
);
9514 warning (_("bug: psymtab for %s is already read in."),
9521 printf_filtered (_("Reading in symbols for %s..."),
9523 gdb_flush (gdb_stdout
);
9526 /* If this psymtab is constructed from a debug-only objfile, the
9527 has_section_at_zero flag will not necessarily be correct. We
9528 can get the correct value for this flag by looking at the data
9529 associated with the (presumably stripped) associated objfile. */
9530 if (objfile
->separate_debug_objfile_backlink
)
9532 struct dwarf2_per_objfile
*dpo_backlink
9533 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9535 dwarf2_per_objfile
->has_section_at_zero
9536 = dpo_backlink
->has_section_at_zero
;
9539 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9541 psymtab_to_symtab_1 (self
);
9543 /* Finish up the debug error message. */
9545 printf_filtered (_("done.\n"));
9548 process_cu_includes (dwarf2_per_objfile
);
9551 /* Reading in full CUs. */
9553 /* Add PER_CU to the queue. */
9556 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9557 enum language pretend_language
)
9559 struct dwarf2_queue_item
*item
;
9562 item
= XNEW (struct dwarf2_queue_item
);
9563 item
->per_cu
= per_cu
;
9564 item
->pretend_language
= pretend_language
;
9567 if (dwarf2_queue
== NULL
)
9568 dwarf2_queue
= item
;
9570 dwarf2_queue_tail
->next
= item
;
9572 dwarf2_queue_tail
= item
;
9575 /* If PER_CU is not yet queued, add it to the queue.
9576 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9578 The result is non-zero if PER_CU was queued, otherwise the result is zero
9579 meaning either PER_CU is already queued or it is already loaded.
9581 N.B. There is an invariant here that if a CU is queued then it is loaded.
9582 The caller is required to load PER_CU if we return non-zero. */
9585 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9586 struct dwarf2_per_cu_data
*per_cu
,
9587 enum language pretend_language
)
9589 /* We may arrive here during partial symbol reading, if we need full
9590 DIEs to process an unusual case (e.g. template arguments). Do
9591 not queue PER_CU, just tell our caller to load its DIEs. */
9592 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9594 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9599 /* Mark the dependence relation so that we don't flush PER_CU
9601 if (dependent_cu
!= NULL
)
9602 dwarf2_add_dependence (dependent_cu
, per_cu
);
9604 /* If it's already on the queue, we have nothing to do. */
9608 /* If the compilation unit is already loaded, just mark it as
9610 if (per_cu
->cu
!= NULL
)
9612 per_cu
->cu
->last_used
= 0;
9616 /* Add it to the queue. */
9617 queue_comp_unit (per_cu
, pretend_language
);
9622 /* Process the queue. */
9625 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9627 struct dwarf2_queue_item
*item
, *next_item
;
9629 if (dwarf_read_debug
)
9631 fprintf_unfiltered (gdb_stdlog
,
9632 "Expanding one or more symtabs of objfile %s ...\n",
9633 objfile_name (dwarf2_per_objfile
->objfile
));
9636 /* The queue starts out with one item, but following a DIE reference
9637 may load a new CU, adding it to the end of the queue. */
9638 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9640 if ((dwarf2_per_objfile
->using_index
9641 ? !item
->per_cu
->v
.quick
->compunit_symtab
9642 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9643 /* Skip dummy CUs. */
9644 && item
->per_cu
->cu
!= NULL
)
9646 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9647 unsigned int debug_print_threshold
;
9650 if (per_cu
->is_debug_types
)
9652 struct signatured_type
*sig_type
=
9653 (struct signatured_type
*) per_cu
;
9655 sprintf (buf
, "TU %s at offset %s",
9656 hex_string (sig_type
->signature
),
9657 sect_offset_str (per_cu
->sect_off
));
9658 /* There can be 100s of TUs.
9659 Only print them in verbose mode. */
9660 debug_print_threshold
= 2;
9664 sprintf (buf
, "CU at offset %s",
9665 sect_offset_str (per_cu
->sect_off
));
9666 debug_print_threshold
= 1;
9669 if (dwarf_read_debug
>= debug_print_threshold
)
9670 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9672 if (per_cu
->is_debug_types
)
9673 process_full_type_unit (per_cu
, item
->pretend_language
);
9675 process_full_comp_unit (per_cu
, item
->pretend_language
);
9677 if (dwarf_read_debug
>= debug_print_threshold
)
9678 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9681 item
->per_cu
->queued
= 0;
9682 next_item
= item
->next
;
9686 dwarf2_queue_tail
= NULL
;
9688 if (dwarf_read_debug
)
9690 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9691 objfile_name (dwarf2_per_objfile
->objfile
));
9695 /* Read in full symbols for PST, and anything it depends on. */
9698 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9700 struct dwarf2_per_cu_data
*per_cu
;
9706 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9707 if (!pst
->dependencies
[i
]->readin
9708 && pst
->dependencies
[i
]->user
== NULL
)
9710 /* Inform about additional files that need to be read in. */
9713 /* FIXME: i18n: Need to make this a single string. */
9714 fputs_filtered (" ", gdb_stdout
);
9716 fputs_filtered ("and ", gdb_stdout
);
9718 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9719 wrap_here (""); /* Flush output. */
9720 gdb_flush (gdb_stdout
);
9722 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9725 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9729 /* It's an include file, no symbols to read for it.
9730 Everything is in the parent symtab. */
9735 dw2_do_instantiate_symtab (per_cu
, false);
9738 /* Trivial hash function for die_info: the hash value of a DIE
9739 is its offset in .debug_info for this objfile. */
9742 die_hash (const void *item
)
9744 const struct die_info
*die
= (const struct die_info
*) item
;
9746 return to_underlying (die
->sect_off
);
9749 /* Trivial comparison function for die_info structures: two DIEs
9750 are equal if they have the same offset. */
9753 die_eq (const void *item_lhs
, const void *item_rhs
)
9755 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9756 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9758 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9761 /* die_reader_func for load_full_comp_unit.
9762 This is identical to read_signatured_type_reader,
9763 but is kept separate for now. */
9766 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9767 const gdb_byte
*info_ptr
,
9768 struct die_info
*comp_unit_die
,
9772 struct dwarf2_cu
*cu
= reader
->cu
;
9773 enum language
*language_ptr
= (enum language
*) data
;
9775 gdb_assert (cu
->die_hash
== NULL
);
9777 htab_create_alloc_ex (cu
->header
.length
/ 12,
9781 &cu
->comp_unit_obstack
,
9782 hashtab_obstack_allocate
,
9783 dummy_obstack_deallocate
);
9786 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9787 &info_ptr
, comp_unit_die
);
9788 cu
->dies
= comp_unit_die
;
9789 /* comp_unit_die is not stored in die_hash, no need. */
9791 /* We try not to read any attributes in this function, because not
9792 all CUs needed for references have been loaded yet, and symbol
9793 table processing isn't initialized. But we have to set the CU language,
9794 or we won't be able to build types correctly.
9795 Similarly, if we do not read the producer, we can not apply
9796 producer-specific interpretation. */
9797 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9800 /* Load the DIEs associated with PER_CU into memory. */
9803 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9805 enum language pretend_language
)
9807 gdb_assert (! this_cu
->is_debug_types
);
9809 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9810 load_full_comp_unit_reader
, &pretend_language
);
9813 /* Add a DIE to the delayed physname list. */
9816 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9817 const char *name
, struct die_info
*die
,
9818 struct dwarf2_cu
*cu
)
9820 struct delayed_method_info mi
;
9822 mi
.fnfield_index
= fnfield_index
;
9826 cu
->method_list
.push_back (mi
);
9829 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9830 "const" / "volatile". If so, decrements LEN by the length of the
9831 modifier and return true. Otherwise return false. */
9835 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9837 size_t mod_len
= sizeof (mod
) - 1;
9838 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9846 /* Compute the physnames of any methods on the CU's method list.
9848 The computation of method physnames is delayed in order to avoid the
9849 (bad) condition that one of the method's formal parameters is of an as yet
9853 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9855 /* Only C++ delays computing physnames. */
9856 if (cu
->method_list
.empty ())
9858 gdb_assert (cu
->language
== language_cplus
);
9860 for (const delayed_method_info
&mi
: cu
->method_list
)
9862 const char *physname
;
9863 struct fn_fieldlist
*fn_flp
9864 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9865 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9866 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9867 = physname
? physname
: "";
9869 /* Since there's no tag to indicate whether a method is a
9870 const/volatile overload, extract that information out of the
9872 if (physname
!= NULL
)
9874 size_t len
= strlen (physname
);
9878 if (physname
[len
] == ')') /* shortcut */
9880 else if (check_modifier (physname
, len
, " const"))
9881 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9882 else if (check_modifier (physname
, len
, " volatile"))
9883 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9890 /* The list is no longer needed. */
9891 cu
->method_list
.clear ();
9894 /* Go objects should be embedded in a DW_TAG_module DIE,
9895 and it's not clear if/how imported objects will appear.
9896 To keep Go support simple until that's worked out,
9897 go back through what we've read and create something usable.
9898 We could do this while processing each DIE, and feels kinda cleaner,
9899 but that way is more invasive.
9900 This is to, for example, allow the user to type "p var" or "b main"
9901 without having to specify the package name, and allow lookups
9902 of module.object to work in contexts that use the expression
9906 fixup_go_packaging (struct dwarf2_cu
*cu
)
9908 char *package_name
= NULL
;
9909 struct pending
*list
;
9912 for (list
= *cu
->get_builder ()->get_global_symbols ();
9916 for (i
= 0; i
< list
->nsyms
; ++i
)
9918 struct symbol
*sym
= list
->symbol
[i
];
9920 if (sym
->language () == language_go
9921 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9923 char *this_package_name
= go_symbol_package_name (sym
);
9925 if (this_package_name
== NULL
)
9927 if (package_name
== NULL
)
9928 package_name
= this_package_name
;
9931 struct objfile
*objfile
9932 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9933 if (strcmp (package_name
, this_package_name
) != 0)
9934 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9935 (symbol_symtab (sym
) != NULL
9936 ? symtab_to_filename_for_display
9937 (symbol_symtab (sym
))
9938 : objfile_name (objfile
)),
9939 this_package_name
, package_name
);
9940 xfree (this_package_name
);
9946 if (package_name
!= NULL
)
9948 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9949 const char *saved_package_name
9950 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
);
9951 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9952 saved_package_name
);
9955 sym
= allocate_symbol (objfile
);
9956 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9957 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9958 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9959 e.g., "main" finds the "main" module and not C's main(). */
9960 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9961 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9962 SYMBOL_TYPE (sym
) = type
;
9964 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9966 xfree (package_name
);
9970 /* Allocate a fully-qualified name consisting of the two parts on the
9974 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9976 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9979 /* A helper that allocates a struct discriminant_info to attach to a
9982 static struct discriminant_info
*
9983 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9986 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9987 gdb_assert (discriminant_index
== -1
9988 || (discriminant_index
>= 0
9989 && discriminant_index
< TYPE_NFIELDS (type
)));
9990 gdb_assert (default_index
== -1
9991 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9993 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9995 struct discriminant_info
*disc
9996 = ((struct discriminant_info
*)
9998 offsetof (struct discriminant_info
, discriminants
)
9999 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
10000 disc
->default_index
= default_index
;
10001 disc
->discriminant_index
= discriminant_index
;
10003 struct dynamic_prop prop
;
10004 prop
.kind
= PROP_UNDEFINED
;
10005 prop
.data
.baton
= disc
;
10007 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
10012 /* Some versions of rustc emitted enums in an unusual way.
10014 Ordinary enums were emitted as unions. The first element of each
10015 structure in the union was named "RUST$ENUM$DISR". This element
10016 held the discriminant.
10018 These versions of Rust also implemented the "non-zero"
10019 optimization. When the enum had two values, and one is empty and
10020 the other holds a pointer that cannot be zero, the pointer is used
10021 as the discriminant, with a zero value meaning the empty variant.
10022 Here, the union's first member is of the form
10023 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
10024 where the fieldnos are the indices of the fields that should be
10025 traversed in order to find the field (which may be several fields deep)
10026 and the variantname is the name of the variant of the case when the
10029 This function recognizes whether TYPE is of one of these forms,
10030 and, if so, smashes it to be a variant type. */
10033 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
10035 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10037 /* We don't need to deal with empty enums. */
10038 if (TYPE_NFIELDS (type
) == 0)
10041 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
10042 if (TYPE_NFIELDS (type
) == 1
10043 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
10045 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10047 /* Decode the field name to find the offset of the
10049 ULONGEST bit_offset
= 0;
10050 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10051 while (name
[0] >= '0' && name
[0] <= '9')
10054 unsigned long index
= strtoul (name
, &tail
, 10);
10057 || index
>= TYPE_NFIELDS (field_type
)
10058 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10059 != FIELD_LOC_KIND_BITPOS
))
10061 complaint (_("Could not parse Rust enum encoding string \"%s\""
10063 TYPE_FIELD_NAME (type
, 0),
10064 objfile_name (objfile
));
10069 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10070 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10073 /* Make a union to hold the variants. */
10074 struct type
*union_type
= alloc_type (objfile
);
10075 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10076 TYPE_NFIELDS (union_type
) = 3;
10077 TYPE_FIELDS (union_type
)
10078 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10079 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10080 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10082 /* Put the discriminant must at index 0. */
10083 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10084 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10085 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10086 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10088 /* The order of fields doesn't really matter, so put the real
10089 field at index 1 and the data-less field at index 2. */
10090 struct discriminant_info
*disc
10091 = alloc_discriminant_info (union_type
, 0, 1);
10092 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10093 TYPE_FIELD_NAME (union_type
, 1)
10094 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10095 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10096 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10097 TYPE_FIELD_NAME (union_type
, 1));
10099 const char *dataless_name
10100 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10102 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10104 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10105 /* NAME points into the original discriminant name, which
10106 already has the correct lifetime. */
10107 TYPE_FIELD_NAME (union_type
, 2) = name
;
10108 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10109 disc
->discriminants
[2] = 0;
10111 /* Smash this type to be a structure type. We have to do this
10112 because the type has already been recorded. */
10113 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10114 TYPE_NFIELDS (type
) = 1;
10116 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10118 /* Install the variant part. */
10119 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10120 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10121 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10123 /* A union with a single anonymous field is probably an old-style
10124 univariant enum. */
10125 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10127 /* Smash this type to be a structure type. We have to do this
10128 because the type has already been recorded. */
10129 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10131 /* Make a union to hold the variants. */
10132 struct type
*union_type
= alloc_type (objfile
);
10133 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10134 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10135 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10136 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10137 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10139 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10140 const char *variant_name
10141 = rust_last_path_segment (TYPE_NAME (field_type
));
10142 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10143 TYPE_NAME (field_type
)
10144 = rust_fully_qualify (&objfile
->objfile_obstack
,
10145 TYPE_NAME (type
), variant_name
);
10147 /* Install the union in the outer struct type. */
10148 TYPE_NFIELDS (type
) = 1;
10150 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10151 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10152 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10153 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10155 alloc_discriminant_info (union_type
, -1, 0);
10159 struct type
*disr_type
= nullptr;
10160 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10162 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10164 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10166 /* All fields of a true enum will be structs. */
10169 else if (TYPE_NFIELDS (disr_type
) == 0)
10171 /* Could be data-less variant, so keep going. */
10172 disr_type
= nullptr;
10174 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10175 "RUST$ENUM$DISR") != 0)
10177 /* Not a Rust enum. */
10187 /* If we got here without a discriminant, then it's probably
10189 if (disr_type
== nullptr)
10192 /* Smash this type to be a structure type. We have to do this
10193 because the type has already been recorded. */
10194 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10196 /* Make a union to hold the variants. */
10197 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10198 struct type
*union_type
= alloc_type (objfile
);
10199 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10200 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10201 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10202 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10203 TYPE_FIELDS (union_type
)
10204 = (struct field
*) TYPE_ZALLOC (union_type
,
10205 (TYPE_NFIELDS (union_type
)
10206 * sizeof (struct field
)));
10208 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10209 TYPE_NFIELDS (type
) * sizeof (struct field
));
10211 /* Install the discriminant at index 0 in the union. */
10212 TYPE_FIELD (union_type
, 0) = *disr_field
;
10213 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10214 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10216 /* Install the union in the outer struct type. */
10217 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10218 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10219 TYPE_NFIELDS (type
) = 1;
10221 /* Set the size and offset of the union type. */
10222 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10224 /* We need a way to find the correct discriminant given a
10225 variant name. For convenience we build a map here. */
10226 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10227 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10228 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10230 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10233 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10234 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10238 int n_fields
= TYPE_NFIELDS (union_type
);
10239 struct discriminant_info
*disc
10240 = alloc_discriminant_info (union_type
, 0, -1);
10241 /* Skip the discriminant here. */
10242 for (int i
= 1; i
< n_fields
; ++i
)
10244 /* Find the final word in the name of this variant's type.
10245 That name can be used to look up the correct
10247 const char *variant_name
10248 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10251 auto iter
= discriminant_map
.find (variant_name
);
10252 if (iter
!= discriminant_map
.end ())
10253 disc
->discriminants
[i
] = iter
->second
;
10255 /* Remove the discriminant field, if it exists. */
10256 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10257 if (TYPE_NFIELDS (sub_type
) > 0)
10259 --TYPE_NFIELDS (sub_type
);
10260 ++TYPE_FIELDS (sub_type
);
10262 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10263 TYPE_NAME (sub_type
)
10264 = rust_fully_qualify (&objfile
->objfile_obstack
,
10265 TYPE_NAME (type
), variant_name
);
10270 /* Rewrite some Rust unions to be structures with variants parts. */
10273 rust_union_quirks (struct dwarf2_cu
*cu
)
10275 gdb_assert (cu
->language
== language_rust
);
10276 for (type
*type_
: cu
->rust_unions
)
10277 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10278 /* We don't need this any more. */
10279 cu
->rust_unions
.clear ();
10282 /* Return the symtab for PER_CU. This works properly regardless of
10283 whether we're using the index or psymtabs. */
10285 static struct compunit_symtab
*
10286 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10288 return (per_cu
->dwarf2_per_objfile
->using_index
10289 ? per_cu
->v
.quick
->compunit_symtab
10290 : per_cu
->v
.psymtab
->compunit_symtab
);
10293 /* A helper function for computing the list of all symbol tables
10294 included by PER_CU. */
10297 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10298 htab_t all_children
, htab_t all_type_symtabs
,
10299 struct dwarf2_per_cu_data
*per_cu
,
10300 struct compunit_symtab
*immediate_parent
)
10303 struct compunit_symtab
*cust
;
10305 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10308 /* This inclusion and its children have been processed. */
10313 /* Only add a CU if it has a symbol table. */
10314 cust
= get_compunit_symtab (per_cu
);
10317 /* If this is a type unit only add its symbol table if we haven't
10318 seen it yet (type unit per_cu's can share symtabs). */
10319 if (per_cu
->is_debug_types
)
10321 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10325 result
->push_back (cust
);
10326 if (cust
->user
== NULL
)
10327 cust
->user
= immediate_parent
;
10332 result
->push_back (cust
);
10333 if (cust
->user
== NULL
)
10334 cust
->user
= immediate_parent
;
10338 if (!per_cu
->imported_symtabs_empty ())
10339 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10341 recursively_compute_inclusions (result
, all_children
,
10342 all_type_symtabs
, ptr
, cust
);
10346 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10350 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10352 gdb_assert (! per_cu
->is_debug_types
);
10354 if (!per_cu
->imported_symtabs_empty ())
10357 std::vector
<compunit_symtab
*> result_symtabs
;
10358 htab_t all_children
, all_type_symtabs
;
10359 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10361 /* If we don't have a symtab, we can just skip this case. */
10365 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10366 NULL
, xcalloc
, xfree
);
10367 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10368 NULL
, xcalloc
, xfree
);
10370 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10372 recursively_compute_inclusions (&result_symtabs
, all_children
,
10373 all_type_symtabs
, ptr
, cust
);
10376 /* Now we have a transitive closure of all the included symtabs. */
10377 len
= result_symtabs
.size ();
10379 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10380 struct compunit_symtab
*, len
+ 1);
10381 memcpy (cust
->includes
, result_symtabs
.data (),
10382 len
* sizeof (compunit_symtab
*));
10383 cust
->includes
[len
] = NULL
;
10385 htab_delete (all_children
);
10386 htab_delete (all_type_symtabs
);
10390 /* Compute the 'includes' field for the symtabs of all the CUs we just
10394 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10396 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10398 if (! iter
->is_debug_types
)
10399 compute_compunit_symtab_includes (iter
);
10402 dwarf2_per_objfile
->just_read_cus
.clear ();
10405 /* Generate full symbol information for PER_CU, whose DIEs have
10406 already been loaded into memory. */
10409 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10410 enum language pretend_language
)
10412 struct dwarf2_cu
*cu
= per_cu
->cu
;
10413 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10414 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10415 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10416 CORE_ADDR lowpc
, highpc
;
10417 struct compunit_symtab
*cust
;
10418 CORE_ADDR baseaddr
;
10419 struct block
*static_block
;
10422 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10424 /* Clear the list here in case something was left over. */
10425 cu
->method_list
.clear ();
10427 cu
->language
= pretend_language
;
10428 cu
->language_defn
= language_def (cu
->language
);
10430 /* Do line number decoding in read_file_scope () */
10431 process_die (cu
->dies
, cu
);
10433 /* For now fudge the Go package. */
10434 if (cu
->language
== language_go
)
10435 fixup_go_packaging (cu
);
10437 /* Now that we have processed all the DIEs in the CU, all the types
10438 should be complete, and it should now be safe to compute all of the
10440 compute_delayed_physnames (cu
);
10442 if (cu
->language
== language_rust
)
10443 rust_union_quirks (cu
);
10445 /* Some compilers don't define a DW_AT_high_pc attribute for the
10446 compilation unit. If the DW_AT_high_pc is missing, synthesize
10447 it, by scanning the DIE's below the compilation unit. */
10448 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10450 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10451 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10453 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10454 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10455 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10456 addrmap to help ensure it has an accurate map of pc values belonging to
10458 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10460 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10461 SECT_OFF_TEXT (objfile
),
10466 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10468 /* Set symtab language to language from DW_AT_language. If the
10469 compilation is from a C file generated by language preprocessors, do
10470 not set the language if it was already deduced by start_subfile. */
10471 if (!(cu
->language
== language_c
10472 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10473 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10475 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10476 produce DW_AT_location with location lists but it can be possibly
10477 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10478 there were bugs in prologue debug info, fixed later in GCC-4.5
10479 by "unwind info for epilogues" patch (which is not directly related).
10481 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10482 needed, it would be wrong due to missing DW_AT_producer there.
10484 Still one can confuse GDB by using non-standard GCC compilation
10485 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10487 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10488 cust
->locations_valid
= 1;
10490 if (gcc_4_minor
>= 5)
10491 cust
->epilogue_unwind_valid
= 1;
10493 cust
->call_site_htab
= cu
->call_site_htab
;
10496 if (dwarf2_per_objfile
->using_index
)
10497 per_cu
->v
.quick
->compunit_symtab
= cust
;
10500 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10501 pst
->compunit_symtab
= cust
;
10505 /* Push it for inclusion processing later. */
10506 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10508 /* Not needed any more. */
10509 cu
->reset_builder ();
10512 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10513 already been loaded into memory. */
10516 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10517 enum language pretend_language
)
10519 struct dwarf2_cu
*cu
= per_cu
->cu
;
10520 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10521 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10522 struct compunit_symtab
*cust
;
10523 struct signatured_type
*sig_type
;
10525 gdb_assert (per_cu
->is_debug_types
);
10526 sig_type
= (struct signatured_type
*) per_cu
;
10528 /* Clear the list here in case something was left over. */
10529 cu
->method_list
.clear ();
10531 cu
->language
= pretend_language
;
10532 cu
->language_defn
= language_def (cu
->language
);
10534 /* The symbol tables are set up in read_type_unit_scope. */
10535 process_die (cu
->dies
, cu
);
10537 /* For now fudge the Go package. */
10538 if (cu
->language
== language_go
)
10539 fixup_go_packaging (cu
);
10541 /* Now that we have processed all the DIEs in the CU, all the types
10542 should be complete, and it should now be safe to compute all of the
10544 compute_delayed_physnames (cu
);
10546 if (cu
->language
== language_rust
)
10547 rust_union_quirks (cu
);
10549 /* TUs share symbol tables.
10550 If this is the first TU to use this symtab, complete the construction
10551 of it with end_expandable_symtab. Otherwise, complete the addition of
10552 this TU's symbols to the existing symtab. */
10553 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10555 buildsym_compunit
*builder
= cu
->get_builder ();
10556 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10557 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10561 /* Set symtab language to language from DW_AT_language. If the
10562 compilation is from a C file generated by language preprocessors,
10563 do not set the language if it was already deduced by
10565 if (!(cu
->language
== language_c
10566 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10567 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10572 cu
->get_builder ()->augment_type_symtab ();
10573 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10576 if (dwarf2_per_objfile
->using_index
)
10577 per_cu
->v
.quick
->compunit_symtab
= cust
;
10580 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10581 pst
->compunit_symtab
= cust
;
10585 /* Not needed any more. */
10586 cu
->reset_builder ();
10589 /* Process an imported unit DIE. */
10592 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10594 struct attribute
*attr
;
10596 /* For now we don't handle imported units in type units. */
10597 if (cu
->per_cu
->is_debug_types
)
10599 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10600 " supported in type units [in module %s]"),
10601 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10604 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10607 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10608 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10609 dwarf2_per_cu_data
*per_cu
10610 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10611 cu
->per_cu
->dwarf2_per_objfile
);
10613 /* If necessary, add it to the queue and load its DIEs. */
10614 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10615 load_full_comp_unit (per_cu
, false, cu
->language
);
10617 cu
->per_cu
->imported_symtabs_push (per_cu
);
10621 /* RAII object that represents a process_die scope: i.e.,
10622 starts/finishes processing a DIE. */
10623 class process_die_scope
10626 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10627 : m_die (die
), m_cu (cu
)
10629 /* We should only be processing DIEs not already in process. */
10630 gdb_assert (!m_die
->in_process
);
10631 m_die
->in_process
= true;
10634 ~process_die_scope ()
10636 m_die
->in_process
= false;
10638 /* If we're done processing the DIE for the CU that owns the line
10639 header, we don't need the line header anymore. */
10640 if (m_cu
->line_header_die_owner
== m_die
)
10642 delete m_cu
->line_header
;
10643 m_cu
->line_header
= NULL
;
10644 m_cu
->line_header_die_owner
= NULL
;
10653 /* Process a die and its children. */
10656 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10658 process_die_scope
scope (die
, cu
);
10662 case DW_TAG_padding
:
10664 case DW_TAG_compile_unit
:
10665 case DW_TAG_partial_unit
:
10666 read_file_scope (die
, cu
);
10668 case DW_TAG_type_unit
:
10669 read_type_unit_scope (die
, cu
);
10671 case DW_TAG_subprogram
:
10672 /* Nested subprograms in Fortran get a prefix. */
10673 if (cu
->language
== language_fortran
10674 && die
->parent
!= NULL
10675 && die
->parent
->tag
== DW_TAG_subprogram
)
10676 cu
->processing_has_namespace_info
= true;
10677 /* Fall through. */
10678 case DW_TAG_inlined_subroutine
:
10679 read_func_scope (die
, cu
);
10681 case DW_TAG_lexical_block
:
10682 case DW_TAG_try_block
:
10683 case DW_TAG_catch_block
:
10684 read_lexical_block_scope (die
, cu
);
10686 case DW_TAG_call_site
:
10687 case DW_TAG_GNU_call_site
:
10688 read_call_site_scope (die
, cu
);
10690 case DW_TAG_class_type
:
10691 case DW_TAG_interface_type
:
10692 case DW_TAG_structure_type
:
10693 case DW_TAG_union_type
:
10694 process_structure_scope (die
, cu
);
10696 case DW_TAG_enumeration_type
:
10697 process_enumeration_scope (die
, cu
);
10700 /* These dies have a type, but processing them does not create
10701 a symbol or recurse to process the children. Therefore we can
10702 read them on-demand through read_type_die. */
10703 case DW_TAG_subroutine_type
:
10704 case DW_TAG_set_type
:
10705 case DW_TAG_array_type
:
10706 case DW_TAG_pointer_type
:
10707 case DW_TAG_ptr_to_member_type
:
10708 case DW_TAG_reference_type
:
10709 case DW_TAG_rvalue_reference_type
:
10710 case DW_TAG_string_type
:
10713 case DW_TAG_base_type
:
10714 case DW_TAG_subrange_type
:
10715 case DW_TAG_typedef
:
10716 /* Add a typedef symbol for the type definition, if it has a
10718 new_symbol (die
, read_type_die (die
, cu
), cu
);
10720 case DW_TAG_common_block
:
10721 read_common_block (die
, cu
);
10723 case DW_TAG_common_inclusion
:
10725 case DW_TAG_namespace
:
10726 cu
->processing_has_namespace_info
= true;
10727 read_namespace (die
, cu
);
10729 case DW_TAG_module
:
10730 cu
->processing_has_namespace_info
= true;
10731 read_module (die
, cu
);
10733 case DW_TAG_imported_declaration
:
10734 cu
->processing_has_namespace_info
= true;
10735 if (read_namespace_alias (die
, cu
))
10737 /* The declaration is not a global namespace alias. */
10738 /* Fall through. */
10739 case DW_TAG_imported_module
:
10740 cu
->processing_has_namespace_info
= true;
10741 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10742 || cu
->language
!= language_fortran
))
10743 complaint (_("Tag '%s' has unexpected children"),
10744 dwarf_tag_name (die
->tag
));
10745 read_import_statement (die
, cu
);
10748 case DW_TAG_imported_unit
:
10749 process_imported_unit_die (die
, cu
);
10752 case DW_TAG_variable
:
10753 read_variable (die
, cu
);
10757 new_symbol (die
, NULL
, cu
);
10762 /* DWARF name computation. */
10764 /* A helper function for dwarf2_compute_name which determines whether DIE
10765 needs to have the name of the scope prepended to the name listed in the
10769 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10771 struct attribute
*attr
;
10775 case DW_TAG_namespace
:
10776 case DW_TAG_typedef
:
10777 case DW_TAG_class_type
:
10778 case DW_TAG_interface_type
:
10779 case DW_TAG_structure_type
:
10780 case DW_TAG_union_type
:
10781 case DW_TAG_enumeration_type
:
10782 case DW_TAG_enumerator
:
10783 case DW_TAG_subprogram
:
10784 case DW_TAG_inlined_subroutine
:
10785 case DW_TAG_member
:
10786 case DW_TAG_imported_declaration
:
10789 case DW_TAG_variable
:
10790 case DW_TAG_constant
:
10791 /* We only need to prefix "globally" visible variables. These include
10792 any variable marked with DW_AT_external or any variable that
10793 lives in a namespace. [Variables in anonymous namespaces
10794 require prefixing, but they are not DW_AT_external.] */
10796 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10798 struct dwarf2_cu
*spec_cu
= cu
;
10800 return die_needs_namespace (die_specification (die
, &spec_cu
),
10804 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10805 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10806 && die
->parent
->tag
!= DW_TAG_module
)
10808 /* A variable in a lexical block of some kind does not need a
10809 namespace, even though in C++ such variables may be external
10810 and have a mangled name. */
10811 if (die
->parent
->tag
== DW_TAG_lexical_block
10812 || die
->parent
->tag
== DW_TAG_try_block
10813 || die
->parent
->tag
== DW_TAG_catch_block
10814 || die
->parent
->tag
== DW_TAG_subprogram
)
10823 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10824 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10825 defined for the given DIE. */
10827 static struct attribute
*
10828 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10830 struct attribute
*attr
;
10832 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10834 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10839 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10840 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10841 defined for the given DIE. */
10843 static const char *
10844 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10846 const char *linkage_name
;
10848 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10849 if (linkage_name
== NULL
)
10850 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10852 return linkage_name
;
10855 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10856 compute the physname for the object, which include a method's:
10857 - formal parameters (C++),
10858 - receiver type (Go),
10860 The term "physname" is a bit confusing.
10861 For C++, for example, it is the demangled name.
10862 For Go, for example, it's the mangled name.
10864 For Ada, return the DIE's linkage name rather than the fully qualified
10865 name. PHYSNAME is ignored..
10867 The result is allocated on the objfile_obstack and canonicalized. */
10869 static const char *
10870 dwarf2_compute_name (const char *name
,
10871 struct die_info
*die
, struct dwarf2_cu
*cu
,
10874 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10877 name
= dwarf2_name (die
, cu
);
10879 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10880 but otherwise compute it by typename_concat inside GDB.
10881 FIXME: Actually this is not really true, or at least not always true.
10882 It's all very confusing. compute_and_set_names doesn't try to demangle
10883 Fortran names because there is no mangling standard. So new_symbol
10884 will set the demangled name to the result of dwarf2_full_name, and it is
10885 the demangled name that GDB uses if it exists. */
10886 if (cu
->language
== language_ada
10887 || (cu
->language
== language_fortran
&& physname
))
10889 /* For Ada unit, we prefer the linkage name over the name, as
10890 the former contains the exported name, which the user expects
10891 to be able to reference. Ideally, we want the user to be able
10892 to reference this entity using either natural or linkage name,
10893 but we haven't started looking at this enhancement yet. */
10894 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10896 if (linkage_name
!= NULL
)
10897 return linkage_name
;
10900 /* These are the only languages we know how to qualify names in. */
10902 && (cu
->language
== language_cplus
10903 || cu
->language
== language_fortran
|| cu
->language
== language_d
10904 || cu
->language
== language_rust
))
10906 if (die_needs_namespace (die
, cu
))
10908 const char *prefix
;
10909 const char *canonical_name
= NULL
;
10913 prefix
= determine_prefix (die
, cu
);
10914 if (*prefix
!= '\0')
10916 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10919 buf
.puts (prefixed_name
);
10920 xfree (prefixed_name
);
10925 /* Template parameters may be specified in the DIE's DW_AT_name, or
10926 as children with DW_TAG_template_type_param or
10927 DW_TAG_value_type_param. If the latter, add them to the name
10928 here. If the name already has template parameters, then
10929 skip this step; some versions of GCC emit both, and
10930 it is more efficient to use the pre-computed name.
10932 Something to keep in mind about this process: it is very
10933 unlikely, or in some cases downright impossible, to produce
10934 something that will match the mangled name of a function.
10935 If the definition of the function has the same debug info,
10936 we should be able to match up with it anyway. But fallbacks
10937 using the minimal symbol, for instance to find a method
10938 implemented in a stripped copy of libstdc++, will not work.
10939 If we do not have debug info for the definition, we will have to
10940 match them up some other way.
10942 When we do name matching there is a related problem with function
10943 templates; two instantiated function templates are allowed to
10944 differ only by their return types, which we do not add here. */
10946 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10948 struct attribute
*attr
;
10949 struct die_info
*child
;
10952 die
->building_fullname
= 1;
10954 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10958 const gdb_byte
*bytes
;
10959 struct dwarf2_locexpr_baton
*baton
;
10962 if (child
->tag
!= DW_TAG_template_type_param
10963 && child
->tag
!= DW_TAG_template_value_param
)
10974 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10977 complaint (_("template parameter missing DW_AT_type"));
10978 buf
.puts ("UNKNOWN_TYPE");
10981 type
= die_type (child
, cu
);
10983 if (child
->tag
== DW_TAG_template_type_param
)
10985 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10986 &type_print_raw_options
);
10990 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10993 complaint (_("template parameter missing "
10994 "DW_AT_const_value"));
10995 buf
.puts ("UNKNOWN_VALUE");
10999 dwarf2_const_value_attr (attr
, type
, name
,
11000 &cu
->comp_unit_obstack
, cu
,
11001 &value
, &bytes
, &baton
);
11003 if (TYPE_NOSIGN (type
))
11004 /* GDB prints characters as NUMBER 'CHAR'. If that's
11005 changed, this can use value_print instead. */
11006 c_printchar (value
, type
, &buf
);
11009 struct value_print_options opts
;
11012 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
11016 else if (bytes
!= NULL
)
11018 v
= allocate_value (type
);
11019 memcpy (value_contents_writeable (v
), bytes
,
11020 TYPE_LENGTH (type
));
11023 v
= value_from_longest (type
, value
);
11025 /* Specify decimal so that we do not depend on
11027 get_formatted_print_options (&opts
, 'd');
11029 value_print (v
, &buf
, &opts
);
11034 die
->building_fullname
= 0;
11038 /* Close the argument list, with a space if necessary
11039 (nested templates). */
11040 if (!buf
.empty () && buf
.string ().back () == '>')
11047 /* For C++ methods, append formal parameter type
11048 information, if PHYSNAME. */
11050 if (physname
&& die
->tag
== DW_TAG_subprogram
11051 && cu
->language
== language_cplus
)
11053 struct type
*type
= read_type_die (die
, cu
);
11055 c_type_print_args (type
, &buf
, 1, cu
->language
,
11056 &type_print_raw_options
);
11058 if (cu
->language
== language_cplus
)
11060 /* Assume that an artificial first parameter is
11061 "this", but do not crash if it is not. RealView
11062 marks unnamed (and thus unused) parameters as
11063 artificial; there is no way to differentiate
11065 if (TYPE_NFIELDS (type
) > 0
11066 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11067 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11068 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11070 buf
.puts (" const");
11074 const std::string
&intermediate_name
= buf
.string ();
11076 if (cu
->language
== language_cplus
)
11078 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11079 &objfile
->per_bfd
->storage_obstack
);
11081 /* If we only computed INTERMEDIATE_NAME, or if
11082 INTERMEDIATE_NAME is already canonical, then we need to
11083 copy it to the appropriate obstack. */
11084 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11085 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11086 intermediate_name
);
11088 name
= canonical_name
;
11095 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11096 If scope qualifiers are appropriate they will be added. The result
11097 will be allocated on the storage_obstack, or NULL if the DIE does
11098 not have a name. NAME may either be from a previous call to
11099 dwarf2_name or NULL.
11101 The output string will be canonicalized (if C++). */
11103 static const char *
11104 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11106 return dwarf2_compute_name (name
, die
, cu
, 0);
11109 /* Construct a physname for the given DIE in CU. NAME may either be
11110 from a previous call to dwarf2_name or NULL. The result will be
11111 allocated on the objfile_objstack or NULL if the DIE does not have a
11114 The output string will be canonicalized (if C++). */
11116 static const char *
11117 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11119 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11120 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11123 /* In this case dwarf2_compute_name is just a shortcut not building anything
11125 if (!die_needs_namespace (die
, cu
))
11126 return dwarf2_compute_name (name
, die
, cu
, 1);
11128 mangled
= dw2_linkage_name (die
, cu
);
11130 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11131 See https://github.com/rust-lang/rust/issues/32925. */
11132 if (cu
->language
== language_rust
&& mangled
!= NULL
11133 && strchr (mangled
, '{') != NULL
)
11136 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11138 gdb::unique_xmalloc_ptr
<char> demangled
;
11139 if (mangled
!= NULL
)
11142 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11144 /* Do nothing (do not demangle the symbol name). */
11146 else if (cu
->language
== language_go
)
11148 /* This is a lie, but we already lie to the caller new_symbol.
11149 new_symbol assumes we return the mangled name.
11150 This just undoes that lie until things are cleaned up. */
11154 /* Use DMGL_RET_DROP for C++ template functions to suppress
11155 their return type. It is easier for GDB users to search
11156 for such functions as `name(params)' than `long name(params)'.
11157 In such case the minimal symbol names do not match the full
11158 symbol names but for template functions there is never a need
11159 to look up their definition from their declaration so
11160 the only disadvantage remains the minimal symbol variant
11161 `long name(params)' does not have the proper inferior type. */
11162 demangled
.reset (gdb_demangle (mangled
,
11163 (DMGL_PARAMS
| DMGL_ANSI
11164 | DMGL_RET_DROP
)));
11167 canon
= demangled
.get ();
11175 if (canon
== NULL
|| check_physname
)
11177 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11179 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11181 /* It may not mean a bug in GDB. The compiler could also
11182 compute DW_AT_linkage_name incorrectly. But in such case
11183 GDB would need to be bug-to-bug compatible. */
11185 complaint (_("Computed physname <%s> does not match demangled <%s> "
11186 "(from linkage <%s>) - DIE at %s [in module %s]"),
11187 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11188 objfile_name (objfile
));
11190 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11191 is available here - over computed PHYSNAME. It is safer
11192 against both buggy GDB and buggy compilers. */
11206 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11211 /* Inspect DIE in CU for a namespace alias. If one exists, record
11212 a new symbol for it.
11214 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11217 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11219 struct attribute
*attr
;
11221 /* If the die does not have a name, this is not a namespace
11223 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11227 struct die_info
*d
= die
;
11228 struct dwarf2_cu
*imported_cu
= cu
;
11230 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11231 keep inspecting DIEs until we hit the underlying import. */
11232 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11233 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11235 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11239 d
= follow_die_ref (d
, attr
, &imported_cu
);
11240 if (d
->tag
!= DW_TAG_imported_declaration
)
11244 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11246 complaint (_("DIE at %s has too many recursively imported "
11247 "declarations"), sect_offset_str (d
->sect_off
));
11254 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11256 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11257 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11259 /* This declaration is a global namespace alias. Add
11260 a symbol for it whose type is the aliased namespace. */
11261 new_symbol (die
, type
, cu
);
11270 /* Return the using directives repository (global or local?) to use in the
11271 current context for CU.
11273 For Ada, imported declarations can materialize renamings, which *may* be
11274 global. However it is impossible (for now?) in DWARF to distinguish
11275 "external" imported declarations and "static" ones. As all imported
11276 declarations seem to be static in all other languages, make them all CU-wide
11277 global only in Ada. */
11279 static struct using_direct
**
11280 using_directives (struct dwarf2_cu
*cu
)
11282 if (cu
->language
== language_ada
11283 && cu
->get_builder ()->outermost_context_p ())
11284 return cu
->get_builder ()->get_global_using_directives ();
11286 return cu
->get_builder ()->get_local_using_directives ();
11289 /* Read the import statement specified by the given die and record it. */
11292 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11294 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11295 struct attribute
*import_attr
;
11296 struct die_info
*imported_die
, *child_die
;
11297 struct dwarf2_cu
*imported_cu
;
11298 const char *imported_name
;
11299 const char *imported_name_prefix
;
11300 const char *canonical_name
;
11301 const char *import_alias
;
11302 const char *imported_declaration
= NULL
;
11303 const char *import_prefix
;
11304 std::vector
<const char *> excludes
;
11306 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11307 if (import_attr
== NULL
)
11309 complaint (_("Tag '%s' has no DW_AT_import"),
11310 dwarf_tag_name (die
->tag
));
11315 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11316 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11317 if (imported_name
== NULL
)
11319 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11321 The import in the following code:
11335 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11336 <52> DW_AT_decl_file : 1
11337 <53> DW_AT_decl_line : 6
11338 <54> DW_AT_import : <0x75>
11339 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11340 <59> DW_AT_name : B
11341 <5b> DW_AT_decl_file : 1
11342 <5c> DW_AT_decl_line : 2
11343 <5d> DW_AT_type : <0x6e>
11345 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11346 <76> DW_AT_byte_size : 4
11347 <77> DW_AT_encoding : 5 (signed)
11349 imports the wrong die ( 0x75 instead of 0x58 ).
11350 This case will be ignored until the gcc bug is fixed. */
11354 /* Figure out the local name after import. */
11355 import_alias
= dwarf2_name (die
, cu
);
11357 /* Figure out where the statement is being imported to. */
11358 import_prefix
= determine_prefix (die
, cu
);
11360 /* Figure out what the scope of the imported die is and prepend it
11361 to the name of the imported die. */
11362 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11364 if (imported_die
->tag
!= DW_TAG_namespace
11365 && imported_die
->tag
!= DW_TAG_module
)
11367 imported_declaration
= imported_name
;
11368 canonical_name
= imported_name_prefix
;
11370 else if (strlen (imported_name_prefix
) > 0)
11371 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11372 imported_name_prefix
,
11373 (cu
->language
== language_d
? "." : "::"),
11374 imported_name
, (char *) NULL
);
11376 canonical_name
= imported_name
;
11378 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11379 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11380 child_die
= sibling_die (child_die
))
11382 /* DWARF-4: A Fortran use statement with a “rename list” may be
11383 represented by an imported module entry with an import attribute
11384 referring to the module and owned entries corresponding to those
11385 entities that are renamed as part of being imported. */
11387 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11389 complaint (_("child DW_TAG_imported_declaration expected "
11390 "- DIE at %s [in module %s]"),
11391 sect_offset_str (child_die
->sect_off
),
11392 objfile_name (objfile
));
11396 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11397 if (import_attr
== NULL
)
11399 complaint (_("Tag '%s' has no DW_AT_import"),
11400 dwarf_tag_name (child_die
->tag
));
11405 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11407 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11408 if (imported_name
== NULL
)
11410 complaint (_("child DW_TAG_imported_declaration has unknown "
11411 "imported name - DIE at %s [in module %s]"),
11412 sect_offset_str (child_die
->sect_off
),
11413 objfile_name (objfile
));
11417 excludes
.push_back (imported_name
);
11419 process_die (child_die
, cu
);
11422 add_using_directive (using_directives (cu
),
11426 imported_declaration
,
11429 &objfile
->objfile_obstack
);
11432 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11433 types, but gives them a size of zero. Starting with version 14,
11434 ICC is compatible with GCC. */
11437 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11439 if (!cu
->checked_producer
)
11440 check_producer (cu
);
11442 return cu
->producer_is_icc_lt_14
;
11445 /* ICC generates a DW_AT_type for C void functions. This was observed on
11446 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11447 which says that void functions should not have a DW_AT_type. */
11450 producer_is_icc (struct dwarf2_cu
*cu
)
11452 if (!cu
->checked_producer
)
11453 check_producer (cu
);
11455 return cu
->producer_is_icc
;
11458 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11459 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11460 this, it was first present in GCC release 4.3.0. */
11463 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11465 if (!cu
->checked_producer
)
11466 check_producer (cu
);
11468 return cu
->producer_is_gcc_lt_4_3
;
11471 static file_and_directory
11472 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11474 file_and_directory res
;
11476 /* Find the filename. Do not use dwarf2_name here, since the filename
11477 is not a source language identifier. */
11478 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11479 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11481 if (res
.comp_dir
== NULL
11482 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11483 && IS_ABSOLUTE_PATH (res
.name
))
11485 res
.comp_dir_storage
= ldirname (res
.name
);
11486 if (!res
.comp_dir_storage
.empty ())
11487 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11489 if (res
.comp_dir
!= NULL
)
11491 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11492 directory, get rid of it. */
11493 const char *cp
= strchr (res
.comp_dir
, ':');
11495 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11496 res
.comp_dir
= cp
+ 1;
11499 if (res
.name
== NULL
)
11500 res
.name
= "<unknown>";
11505 /* Handle DW_AT_stmt_list for a compilation unit.
11506 DIE is the DW_TAG_compile_unit die for CU.
11507 COMP_DIR is the compilation directory. LOWPC is passed to
11508 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11511 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11512 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11514 struct dwarf2_per_objfile
*dwarf2_per_objfile
11515 = cu
->per_cu
->dwarf2_per_objfile
;
11516 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11517 struct attribute
*attr
;
11518 struct line_header line_header_local
;
11519 hashval_t line_header_local_hash
;
11521 int decode_mapping
;
11523 gdb_assert (! cu
->per_cu
->is_debug_types
);
11525 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11529 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11531 /* The line header hash table is only created if needed (it exists to
11532 prevent redundant reading of the line table for partial_units).
11533 If we're given a partial_unit, we'll need it. If we're given a
11534 compile_unit, then use the line header hash table if it's already
11535 created, but don't create one just yet. */
11537 if (dwarf2_per_objfile
->line_header_hash
== NULL
11538 && die
->tag
== DW_TAG_partial_unit
)
11540 dwarf2_per_objfile
->line_header_hash
11541 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11542 line_header_eq_voidp
,
11543 free_line_header_voidp
,
11544 &objfile
->objfile_obstack
,
11545 hashtab_obstack_allocate
,
11546 dummy_obstack_deallocate
);
11549 line_header_local
.sect_off
= line_offset
;
11550 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11551 line_header_local_hash
= line_header_hash (&line_header_local
);
11552 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11554 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11555 &line_header_local
,
11556 line_header_local_hash
, NO_INSERT
);
11558 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11559 is not present in *SLOT (since if there is something in *SLOT then
11560 it will be for a partial_unit). */
11561 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11563 gdb_assert (*slot
!= NULL
);
11564 cu
->line_header
= (struct line_header
*) *slot
;
11569 /* dwarf_decode_line_header does not yet provide sufficient information.
11570 We always have to call also dwarf_decode_lines for it. */
11571 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11575 cu
->line_header
= lh
.release ();
11576 cu
->line_header_die_owner
= die
;
11578 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11582 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11583 &line_header_local
,
11584 line_header_local_hash
, INSERT
);
11585 gdb_assert (slot
!= NULL
);
11587 if (slot
!= NULL
&& *slot
== NULL
)
11589 /* This newly decoded line number information unit will be owned
11590 by line_header_hash hash table. */
11591 *slot
= cu
->line_header
;
11592 cu
->line_header_die_owner
= NULL
;
11596 /* We cannot free any current entry in (*slot) as that struct line_header
11597 may be already used by multiple CUs. Create only temporary decoded
11598 line_header for this CU - it may happen at most once for each line
11599 number information unit. And if we're not using line_header_hash
11600 then this is what we want as well. */
11601 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11603 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11604 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11609 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11612 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11614 struct dwarf2_per_objfile
*dwarf2_per_objfile
11615 = cu
->per_cu
->dwarf2_per_objfile
;
11616 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11617 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11618 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11619 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11620 struct attribute
*attr
;
11621 struct die_info
*child_die
;
11622 CORE_ADDR baseaddr
;
11624 prepare_one_comp_unit (cu
, die
, cu
->language
);
11625 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11627 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11629 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11630 from finish_block. */
11631 if (lowpc
== ((CORE_ADDR
) -1))
11633 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11635 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11637 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11638 standardised yet. As a workaround for the language detection we fall
11639 back to the DW_AT_producer string. */
11640 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11641 cu
->language
= language_opencl
;
11643 /* Similar hack for Go. */
11644 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11645 set_cu_language (DW_LANG_Go
, cu
);
11647 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11649 /* Decode line number information if present. We do this before
11650 processing child DIEs, so that the line header table is available
11651 for DW_AT_decl_file. */
11652 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11654 /* Process all dies in compilation unit. */
11655 if (die
->child
!= NULL
)
11657 child_die
= die
->child
;
11658 while (child_die
&& child_die
->tag
)
11660 process_die (child_die
, cu
);
11661 child_die
= sibling_die (child_die
);
11665 /* Decode macro information, if present. Dwarf 2 macro information
11666 refers to information in the line number info statement program
11667 header, so we can only read it if we've read the header
11669 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11671 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11672 if (attr
&& cu
->line_header
)
11674 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11675 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11677 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11681 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11682 if (attr
&& cu
->line_header
)
11684 unsigned int macro_offset
= DW_UNSND (attr
);
11686 dwarf_decode_macros (cu
, macro_offset
, 0);
11692 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11694 struct type_unit_group
*tu_group
;
11696 struct attribute
*attr
;
11698 struct signatured_type
*sig_type
;
11700 gdb_assert (per_cu
->is_debug_types
);
11701 sig_type
= (struct signatured_type
*) per_cu
;
11703 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11705 /* If we're using .gdb_index (includes -readnow) then
11706 per_cu->type_unit_group may not have been set up yet. */
11707 if (sig_type
->type_unit_group
== NULL
)
11708 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11709 tu_group
= sig_type
->type_unit_group
;
11711 /* If we've already processed this stmt_list there's no real need to
11712 do it again, we could fake it and just recreate the part we need
11713 (file name,index -> symtab mapping). If data shows this optimization
11714 is useful we can do it then. */
11715 first_time
= tu_group
->compunit_symtab
== NULL
;
11717 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11722 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11723 lh
= dwarf_decode_line_header (line_offset
, this);
11728 start_symtab ("", NULL
, 0);
11731 gdb_assert (tu_group
->symtabs
== NULL
);
11732 gdb_assert (m_builder
== nullptr);
11733 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11734 m_builder
.reset (new struct buildsym_compunit
11735 (COMPUNIT_OBJFILE (cust
), "",
11736 COMPUNIT_DIRNAME (cust
),
11737 compunit_language (cust
),
11743 line_header
= lh
.release ();
11744 line_header_die_owner
= die
;
11748 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11750 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11751 still initializing it, and our caller (a few levels up)
11752 process_full_type_unit still needs to know if this is the first
11755 tu_group
->num_symtabs
= line_header
->file_names_size ();
11756 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11757 line_header
->file_names_size ());
11759 auto &file_names
= line_header
->file_names ();
11760 for (i
= 0; i
< file_names
.size (); ++i
)
11762 file_entry
&fe
= file_names
[i
];
11763 dwarf2_start_subfile (this, fe
.name
,
11764 fe
.include_dir (line_header
));
11765 buildsym_compunit
*b
= get_builder ();
11766 if (b
->get_current_subfile ()->symtab
== NULL
)
11768 /* NOTE: start_subfile will recognize when it's been
11769 passed a file it has already seen. So we can't
11770 assume there's a simple mapping from
11771 cu->line_header->file_names to subfiles, plus
11772 cu->line_header->file_names may contain dups. */
11773 b
->get_current_subfile ()->symtab
11774 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11777 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11778 tu_group
->symtabs
[i
] = fe
.symtab
;
11783 gdb_assert (m_builder
== nullptr);
11784 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11785 m_builder
.reset (new struct buildsym_compunit
11786 (COMPUNIT_OBJFILE (cust
), "",
11787 COMPUNIT_DIRNAME (cust
),
11788 compunit_language (cust
),
11791 auto &file_names
= line_header
->file_names ();
11792 for (i
= 0; i
< file_names
.size (); ++i
)
11794 file_entry
&fe
= file_names
[i
];
11795 fe
.symtab
= tu_group
->symtabs
[i
];
11799 /* The main symtab is allocated last. Type units don't have DW_AT_name
11800 so they don't have a "real" (so to speak) symtab anyway.
11801 There is later code that will assign the main symtab to all symbols
11802 that don't have one. We need to handle the case of a symbol with a
11803 missing symtab (DW_AT_decl_file) anyway. */
11806 /* Process DW_TAG_type_unit.
11807 For TUs we want to skip the first top level sibling if it's not the
11808 actual type being defined by this TU. In this case the first top
11809 level sibling is there to provide context only. */
11812 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11814 struct die_info
*child_die
;
11816 prepare_one_comp_unit (cu
, die
, language_minimal
);
11818 /* Initialize (or reinitialize) the machinery for building symtabs.
11819 We do this before processing child DIEs, so that the line header table
11820 is available for DW_AT_decl_file. */
11821 cu
->setup_type_unit_groups (die
);
11823 if (die
->child
!= NULL
)
11825 child_die
= die
->child
;
11826 while (child_die
&& child_die
->tag
)
11828 process_die (child_die
, cu
);
11829 child_die
= sibling_die (child_die
);
11836 http://gcc.gnu.org/wiki/DebugFission
11837 http://gcc.gnu.org/wiki/DebugFissionDWP
11839 To simplify handling of both DWO files ("object" files with the DWARF info)
11840 and DWP files (a file with the DWOs packaged up into one file), we treat
11841 DWP files as having a collection of virtual DWO files. */
11844 hash_dwo_file (const void *item
)
11846 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11849 hash
= htab_hash_string (dwo_file
->dwo_name
);
11850 if (dwo_file
->comp_dir
!= NULL
)
11851 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11856 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11858 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11859 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11861 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11863 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11864 return lhs
->comp_dir
== rhs
->comp_dir
;
11865 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11868 /* Allocate a hash table for DWO files. */
11871 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11873 auto delete_dwo_file
= [] (void *item
)
11875 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11880 return htab_up (htab_create_alloc_ex (41,
11884 &objfile
->objfile_obstack
,
11885 hashtab_obstack_allocate
,
11886 dummy_obstack_deallocate
));
11889 /* Lookup DWO file DWO_NAME. */
11892 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11893 const char *dwo_name
,
11894 const char *comp_dir
)
11896 struct dwo_file find_entry
;
11899 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11900 dwarf2_per_objfile
->dwo_files
11901 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11903 find_entry
.dwo_name
= dwo_name
;
11904 find_entry
.comp_dir
= comp_dir
;
11905 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11912 hash_dwo_unit (const void *item
)
11914 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11916 /* This drops the top 32 bits of the id, but is ok for a hash. */
11917 return dwo_unit
->signature
;
11921 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11923 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11924 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11926 /* The signature is assumed to be unique within the DWO file.
11927 So while object file CU dwo_id's always have the value zero,
11928 that's OK, assuming each object file DWO file has only one CU,
11929 and that's the rule for now. */
11930 return lhs
->signature
== rhs
->signature
;
11933 /* Allocate a hash table for DWO CUs,TUs.
11934 There is one of these tables for each of CUs,TUs for each DWO file. */
11937 allocate_dwo_unit_table (struct objfile
*objfile
)
11939 /* Start out with a pretty small number.
11940 Generally DWO files contain only one CU and maybe some TUs. */
11941 return htab_create_alloc_ex (3,
11945 &objfile
->objfile_obstack
,
11946 hashtab_obstack_allocate
,
11947 dummy_obstack_deallocate
);
11950 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11952 struct create_dwo_cu_data
11954 struct dwo_file
*dwo_file
;
11955 struct dwo_unit dwo_unit
;
11958 /* die_reader_func for create_dwo_cu. */
11961 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11962 const gdb_byte
*info_ptr
,
11963 struct die_info
*comp_unit_die
,
11967 struct dwarf2_cu
*cu
= reader
->cu
;
11968 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11969 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11970 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11971 struct dwo_file
*dwo_file
= data
->dwo_file
;
11972 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11974 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11975 if (!signature
.has_value ())
11977 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11978 " its dwo_id [in module %s]"),
11979 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11983 dwo_unit
->dwo_file
= dwo_file
;
11984 dwo_unit
->signature
= *signature
;
11985 dwo_unit
->section
= section
;
11986 dwo_unit
->sect_off
= sect_off
;
11987 dwo_unit
->length
= cu
->per_cu
->length
;
11989 if (dwarf_read_debug
)
11990 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11991 sect_offset_str (sect_off
),
11992 hex_string (dwo_unit
->signature
));
11995 /* Create the dwo_units for the CUs in a DWO_FILE.
11996 Note: This function processes DWO files only, not DWP files. */
11999 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12000 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
12003 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12004 const gdb_byte
*info_ptr
, *end_ptr
;
12006 dwarf2_read_section (objfile
, §ion
);
12007 info_ptr
= section
.buffer
;
12009 if (info_ptr
== NULL
)
12012 if (dwarf_read_debug
)
12014 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
12015 get_section_name (§ion
),
12016 get_section_file_name (§ion
));
12019 end_ptr
= info_ptr
+ section
.size
;
12020 while (info_ptr
< end_ptr
)
12022 struct dwarf2_per_cu_data per_cu
;
12023 struct create_dwo_cu_data create_dwo_cu_data
;
12024 struct dwo_unit
*dwo_unit
;
12026 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
12028 memset (&create_dwo_cu_data
.dwo_unit
, 0,
12029 sizeof (create_dwo_cu_data
.dwo_unit
));
12030 memset (&per_cu
, 0, sizeof (per_cu
));
12031 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
12032 per_cu
.is_debug_types
= 0;
12033 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12034 per_cu
.section
= §ion
;
12035 create_dwo_cu_data
.dwo_file
= &dwo_file
;
12037 init_cutu_and_read_dies_no_follow (
12038 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
12039 info_ptr
+= per_cu
.length
;
12041 // If the unit could not be parsed, skip it.
12042 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12045 if (cus_htab
== NULL
)
12046 cus_htab
= allocate_dwo_unit_table (objfile
);
12048 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12049 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12050 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12051 gdb_assert (slot
!= NULL
);
12054 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12055 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12057 complaint (_("debug cu entry at offset %s is duplicate to"
12058 " the entry at offset %s, signature %s"),
12059 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12060 hex_string (dwo_unit
->signature
));
12062 *slot
= (void *)dwo_unit
;
12066 /* DWP file .debug_{cu,tu}_index section format:
12067 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12071 Both index sections have the same format, and serve to map a 64-bit
12072 signature to a set of section numbers. Each section begins with a header,
12073 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12074 indexes, and a pool of 32-bit section numbers. The index sections will be
12075 aligned at 8-byte boundaries in the file.
12077 The index section header consists of:
12079 V, 32 bit version number
12081 N, 32 bit number of compilation units or type units in the index
12082 M, 32 bit number of slots in the hash table
12084 Numbers are recorded using the byte order of the application binary.
12086 The hash table begins at offset 16 in the section, and consists of an array
12087 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12088 order of the application binary). Unused slots in the hash table are 0.
12089 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12091 The parallel table begins immediately after the hash table
12092 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12093 array of 32-bit indexes (using the byte order of the application binary),
12094 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12095 table contains a 32-bit index into the pool of section numbers. For unused
12096 hash table slots, the corresponding entry in the parallel table will be 0.
12098 The pool of section numbers begins immediately following the hash table
12099 (at offset 16 + 12 * M from the beginning of the section). The pool of
12100 section numbers consists of an array of 32-bit words (using the byte order
12101 of the application binary). Each item in the array is indexed starting
12102 from 0. The hash table entry provides the index of the first section
12103 number in the set. Additional section numbers in the set follow, and the
12104 set is terminated by a 0 entry (section number 0 is not used in ELF).
12106 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12107 section must be the first entry in the set, and the .debug_abbrev.dwo must
12108 be the second entry. Other members of the set may follow in any order.
12114 DWP Version 2 combines all the .debug_info, etc. sections into one,
12115 and the entries in the index tables are now offsets into these sections.
12116 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12119 Index Section Contents:
12121 Hash Table of Signatures dwp_hash_table.hash_table
12122 Parallel Table of Indices dwp_hash_table.unit_table
12123 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12124 Table of Section Sizes dwp_hash_table.v2.sizes
12126 The index section header consists of:
12128 V, 32 bit version number
12129 L, 32 bit number of columns in the table of section offsets
12130 N, 32 bit number of compilation units or type units in the index
12131 M, 32 bit number of slots in the hash table
12133 Numbers are recorded using the byte order of the application binary.
12135 The hash table has the same format as version 1.
12136 The parallel table of indices has the same format as version 1,
12137 except that the entries are origin-1 indices into the table of sections
12138 offsets and the table of section sizes.
12140 The table of offsets begins immediately following the parallel table
12141 (at offset 16 + 12 * M from the beginning of the section). The table is
12142 a two-dimensional array of 32-bit words (using the byte order of the
12143 application binary), with L columns and N+1 rows, in row-major order.
12144 Each row in the array is indexed starting from 0. The first row provides
12145 a key to the remaining rows: each column in this row provides an identifier
12146 for a debug section, and the offsets in the same column of subsequent rows
12147 refer to that section. The section identifiers are:
12149 DW_SECT_INFO 1 .debug_info.dwo
12150 DW_SECT_TYPES 2 .debug_types.dwo
12151 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12152 DW_SECT_LINE 4 .debug_line.dwo
12153 DW_SECT_LOC 5 .debug_loc.dwo
12154 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12155 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12156 DW_SECT_MACRO 8 .debug_macro.dwo
12158 The offsets provided by the CU and TU index sections are the base offsets
12159 for the contributions made by each CU or TU to the corresponding section
12160 in the package file. Each CU and TU header contains an abbrev_offset
12161 field, used to find the abbreviations table for that CU or TU within the
12162 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12163 be interpreted as relative to the base offset given in the index section.
12164 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12165 should be interpreted as relative to the base offset for .debug_line.dwo,
12166 and offsets into other debug sections obtained from DWARF attributes should
12167 also be interpreted as relative to the corresponding base offset.
12169 The table of sizes begins immediately following the table of offsets.
12170 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12171 with L columns and N rows, in row-major order. Each row in the array is
12172 indexed starting from 1 (row 0 is shared by the two tables).
12176 Hash table lookup is handled the same in version 1 and 2:
12178 We assume that N and M will not exceed 2^32 - 1.
12179 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12181 Given a 64-bit compilation unit signature or a type signature S, an entry
12182 in the hash table is located as follows:
12184 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12185 the low-order k bits all set to 1.
12187 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12189 3) If the hash table entry at index H matches the signature, use that
12190 entry. If the hash table entry at index H is unused (all zeroes),
12191 terminate the search: the signature is not present in the table.
12193 4) Let H = (H + H') modulo M. Repeat at Step 3.
12195 Because M > N and H' and M are relatively prime, the search is guaranteed
12196 to stop at an unused slot or find the match. */
12198 /* Create a hash table to map DWO IDs to their CU/TU entry in
12199 .debug_{info,types}.dwo in DWP_FILE.
12200 Returns NULL if there isn't one.
12201 Note: This function processes DWP files only, not DWO files. */
12203 static struct dwp_hash_table
*
12204 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12205 struct dwp_file
*dwp_file
, int is_debug_types
)
12207 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12208 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12209 const gdb_byte
*index_ptr
, *index_end
;
12210 struct dwarf2_section_info
*index
;
12211 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12212 struct dwp_hash_table
*htab
;
12214 if (is_debug_types
)
12215 index
= &dwp_file
->sections
.tu_index
;
12217 index
= &dwp_file
->sections
.cu_index
;
12219 if (dwarf2_section_empty_p (index
))
12221 dwarf2_read_section (objfile
, index
);
12223 index_ptr
= index
->buffer
;
12224 index_end
= index_ptr
+ index
->size
;
12226 version
= read_4_bytes (dbfd
, index_ptr
);
12229 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12233 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12235 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12238 if (version
!= 1 && version
!= 2)
12240 error (_("Dwarf Error: unsupported DWP file version (%s)"
12241 " [in module %s]"),
12242 pulongest (version
), dwp_file
->name
);
12244 if (nr_slots
!= (nr_slots
& -nr_slots
))
12246 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12247 " is not power of 2 [in module %s]"),
12248 pulongest (nr_slots
), dwp_file
->name
);
12251 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12252 htab
->version
= version
;
12253 htab
->nr_columns
= nr_columns
;
12254 htab
->nr_units
= nr_units
;
12255 htab
->nr_slots
= nr_slots
;
12256 htab
->hash_table
= index_ptr
;
12257 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12259 /* Exit early if the table is empty. */
12260 if (nr_slots
== 0 || nr_units
== 0
12261 || (version
== 2 && nr_columns
== 0))
12263 /* All must be zero. */
12264 if (nr_slots
!= 0 || nr_units
!= 0
12265 || (version
== 2 && nr_columns
!= 0))
12267 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12268 " all zero [in modules %s]"),
12276 htab
->section_pool
.v1
.indices
=
12277 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12278 /* It's harder to decide whether the section is too small in v1.
12279 V1 is deprecated anyway so we punt. */
12283 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12284 int *ids
= htab
->section_pool
.v2
.section_ids
;
12285 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12286 /* Reverse map for error checking. */
12287 int ids_seen
[DW_SECT_MAX
+ 1];
12290 if (nr_columns
< 2)
12292 error (_("Dwarf Error: bad DWP hash table, too few columns"
12293 " in section table [in module %s]"),
12296 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12298 error (_("Dwarf Error: bad DWP hash table, too many columns"
12299 " in section table [in module %s]"),
12302 memset (ids
, 255, sizeof_ids
);
12303 memset (ids_seen
, 255, sizeof (ids_seen
));
12304 for (i
= 0; i
< nr_columns
; ++i
)
12306 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12308 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12310 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12311 " in section table [in module %s]"),
12312 id
, dwp_file
->name
);
12314 if (ids_seen
[id
] != -1)
12316 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12317 " id %d in section table [in module %s]"),
12318 id
, dwp_file
->name
);
12323 /* Must have exactly one info or types section. */
12324 if (((ids_seen
[DW_SECT_INFO
] != -1)
12325 + (ids_seen
[DW_SECT_TYPES
] != -1))
12328 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12329 " DWO info/types section [in module %s]"),
12332 /* Must have an abbrev section. */
12333 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12335 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12336 " section [in module %s]"),
12339 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12340 htab
->section_pool
.v2
.sizes
=
12341 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12342 * nr_units
* nr_columns
);
12343 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12344 * nr_units
* nr_columns
))
12347 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12348 " [in module %s]"),
12356 /* Update SECTIONS with the data from SECTP.
12358 This function is like the other "locate" section routines that are
12359 passed to bfd_map_over_sections, but in this context the sections to
12360 read comes from the DWP V1 hash table, not the full ELF section table.
12362 The result is non-zero for success, or zero if an error was found. */
12365 locate_v1_virtual_dwo_sections (asection
*sectp
,
12366 struct virtual_v1_dwo_sections
*sections
)
12368 const struct dwop_section_names
*names
= &dwop_section_names
;
12370 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12372 /* There can be only one. */
12373 if (sections
->abbrev
.s
.section
!= NULL
)
12375 sections
->abbrev
.s
.section
= sectp
;
12376 sections
->abbrev
.size
= bfd_section_size (sectp
);
12378 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12379 || section_is_p (sectp
->name
, &names
->types_dwo
))
12381 /* There can be only one. */
12382 if (sections
->info_or_types
.s
.section
!= NULL
)
12384 sections
->info_or_types
.s
.section
= sectp
;
12385 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12387 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12389 /* There can be only one. */
12390 if (sections
->line
.s
.section
!= NULL
)
12392 sections
->line
.s
.section
= sectp
;
12393 sections
->line
.size
= bfd_section_size (sectp
);
12395 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12397 /* There can be only one. */
12398 if (sections
->loc
.s
.section
!= NULL
)
12400 sections
->loc
.s
.section
= sectp
;
12401 sections
->loc
.size
= bfd_section_size (sectp
);
12403 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12405 /* There can be only one. */
12406 if (sections
->macinfo
.s
.section
!= NULL
)
12408 sections
->macinfo
.s
.section
= sectp
;
12409 sections
->macinfo
.size
= bfd_section_size (sectp
);
12411 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12413 /* There can be only one. */
12414 if (sections
->macro
.s
.section
!= NULL
)
12416 sections
->macro
.s
.section
= sectp
;
12417 sections
->macro
.size
= bfd_section_size (sectp
);
12419 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12421 /* There can be only one. */
12422 if (sections
->str_offsets
.s
.section
!= NULL
)
12424 sections
->str_offsets
.s
.section
= sectp
;
12425 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12429 /* No other kind of section is valid. */
12436 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12437 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12438 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12439 This is for DWP version 1 files. */
12441 static struct dwo_unit
*
12442 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12443 struct dwp_file
*dwp_file
,
12444 uint32_t unit_index
,
12445 const char *comp_dir
,
12446 ULONGEST signature
, int is_debug_types
)
12448 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12449 const struct dwp_hash_table
*dwp_htab
=
12450 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12451 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12452 const char *kind
= is_debug_types
? "TU" : "CU";
12453 struct dwo_file
*dwo_file
;
12454 struct dwo_unit
*dwo_unit
;
12455 struct virtual_v1_dwo_sections sections
;
12456 void **dwo_file_slot
;
12459 gdb_assert (dwp_file
->version
== 1);
12461 if (dwarf_read_debug
)
12463 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12465 pulongest (unit_index
), hex_string (signature
),
12469 /* Fetch the sections of this DWO unit.
12470 Put a limit on the number of sections we look for so that bad data
12471 doesn't cause us to loop forever. */
12473 #define MAX_NR_V1_DWO_SECTIONS \
12474 (1 /* .debug_info or .debug_types */ \
12475 + 1 /* .debug_abbrev */ \
12476 + 1 /* .debug_line */ \
12477 + 1 /* .debug_loc */ \
12478 + 1 /* .debug_str_offsets */ \
12479 + 1 /* .debug_macro or .debug_macinfo */ \
12480 + 1 /* trailing zero */)
12482 memset (§ions
, 0, sizeof (sections
));
12484 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12487 uint32_t section_nr
=
12488 read_4_bytes (dbfd
,
12489 dwp_htab
->section_pool
.v1
.indices
12490 + (unit_index
+ i
) * sizeof (uint32_t));
12492 if (section_nr
== 0)
12494 if (section_nr
>= dwp_file
->num_sections
)
12496 error (_("Dwarf Error: bad DWP hash table, section number too large"
12497 " [in module %s]"),
12501 sectp
= dwp_file
->elf_sections
[section_nr
];
12502 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12504 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12505 " [in module %s]"),
12511 || dwarf2_section_empty_p (§ions
.info_or_types
)
12512 || dwarf2_section_empty_p (§ions
.abbrev
))
12514 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12515 " [in module %s]"),
12518 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12520 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12521 " [in module %s]"),
12525 /* It's easier for the rest of the code if we fake a struct dwo_file and
12526 have dwo_unit "live" in that. At least for now.
12528 The DWP file can be made up of a random collection of CUs and TUs.
12529 However, for each CU + set of TUs that came from the same original DWO
12530 file, we can combine them back into a virtual DWO file to save space
12531 (fewer struct dwo_file objects to allocate). Remember that for really
12532 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12534 std::string virtual_dwo_name
=
12535 string_printf ("virtual-dwo/%d-%d-%d-%d",
12536 get_section_id (§ions
.abbrev
),
12537 get_section_id (§ions
.line
),
12538 get_section_id (§ions
.loc
),
12539 get_section_id (§ions
.str_offsets
));
12540 /* Can we use an existing virtual DWO file? */
12541 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12542 virtual_dwo_name
.c_str (),
12544 /* Create one if necessary. */
12545 if (*dwo_file_slot
== NULL
)
12547 if (dwarf_read_debug
)
12549 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12550 virtual_dwo_name
.c_str ());
12552 dwo_file
= new struct dwo_file
;
12553 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12555 dwo_file
->comp_dir
= comp_dir
;
12556 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12557 dwo_file
->sections
.line
= sections
.line
;
12558 dwo_file
->sections
.loc
= sections
.loc
;
12559 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12560 dwo_file
->sections
.macro
= sections
.macro
;
12561 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12562 /* The "str" section is global to the entire DWP file. */
12563 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12564 /* The info or types section is assigned below to dwo_unit,
12565 there's no need to record it in dwo_file.
12566 Also, we can't simply record type sections in dwo_file because
12567 we record a pointer into the vector in dwo_unit. As we collect more
12568 types we'll grow the vector and eventually have to reallocate space
12569 for it, invalidating all copies of pointers into the previous
12571 *dwo_file_slot
= dwo_file
;
12575 if (dwarf_read_debug
)
12577 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12578 virtual_dwo_name
.c_str ());
12580 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12583 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12584 dwo_unit
->dwo_file
= dwo_file
;
12585 dwo_unit
->signature
= signature
;
12586 dwo_unit
->section
=
12587 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12588 *dwo_unit
->section
= sections
.info_or_types
;
12589 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12594 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12595 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12596 piece within that section used by a TU/CU, return a virtual section
12597 of just that piece. */
12599 static struct dwarf2_section_info
12600 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12601 struct dwarf2_section_info
*section
,
12602 bfd_size_type offset
, bfd_size_type size
)
12604 struct dwarf2_section_info result
;
12607 gdb_assert (section
!= NULL
);
12608 gdb_assert (!section
->is_virtual
);
12610 memset (&result
, 0, sizeof (result
));
12611 result
.s
.containing_section
= section
;
12612 result
.is_virtual
= true;
12617 sectp
= get_section_bfd_section (section
);
12619 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12620 bounds of the real section. This is a pretty-rare event, so just
12621 flag an error (easier) instead of a warning and trying to cope. */
12623 || offset
+ size
> bfd_section_size (sectp
))
12625 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12626 " in section %s [in module %s]"),
12627 sectp
? bfd_section_name (sectp
) : "<unknown>",
12628 objfile_name (dwarf2_per_objfile
->objfile
));
12631 result
.virtual_offset
= offset
;
12632 result
.size
= size
;
12636 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12637 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12638 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12639 This is for DWP version 2 files. */
12641 static struct dwo_unit
*
12642 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12643 struct dwp_file
*dwp_file
,
12644 uint32_t unit_index
,
12645 const char *comp_dir
,
12646 ULONGEST signature
, int is_debug_types
)
12648 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12649 const struct dwp_hash_table
*dwp_htab
=
12650 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12651 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12652 const char *kind
= is_debug_types
? "TU" : "CU";
12653 struct dwo_file
*dwo_file
;
12654 struct dwo_unit
*dwo_unit
;
12655 struct virtual_v2_dwo_sections sections
;
12656 void **dwo_file_slot
;
12659 gdb_assert (dwp_file
->version
== 2);
12661 if (dwarf_read_debug
)
12663 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12665 pulongest (unit_index
), hex_string (signature
),
12669 /* Fetch the section offsets of this DWO unit. */
12671 memset (§ions
, 0, sizeof (sections
));
12673 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12675 uint32_t offset
= read_4_bytes (dbfd
,
12676 dwp_htab
->section_pool
.v2
.offsets
12677 + (((unit_index
- 1) * dwp_htab
->nr_columns
12679 * sizeof (uint32_t)));
12680 uint32_t size
= read_4_bytes (dbfd
,
12681 dwp_htab
->section_pool
.v2
.sizes
12682 + (((unit_index
- 1) * dwp_htab
->nr_columns
12684 * sizeof (uint32_t)));
12686 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12689 case DW_SECT_TYPES
:
12690 sections
.info_or_types_offset
= offset
;
12691 sections
.info_or_types_size
= size
;
12693 case DW_SECT_ABBREV
:
12694 sections
.abbrev_offset
= offset
;
12695 sections
.abbrev_size
= size
;
12698 sections
.line_offset
= offset
;
12699 sections
.line_size
= size
;
12702 sections
.loc_offset
= offset
;
12703 sections
.loc_size
= size
;
12705 case DW_SECT_STR_OFFSETS
:
12706 sections
.str_offsets_offset
= offset
;
12707 sections
.str_offsets_size
= size
;
12709 case DW_SECT_MACINFO
:
12710 sections
.macinfo_offset
= offset
;
12711 sections
.macinfo_size
= size
;
12713 case DW_SECT_MACRO
:
12714 sections
.macro_offset
= offset
;
12715 sections
.macro_size
= size
;
12720 /* It's easier for the rest of the code if we fake a struct dwo_file and
12721 have dwo_unit "live" in that. At least for now.
12723 The DWP file can be made up of a random collection of CUs and TUs.
12724 However, for each CU + set of TUs that came from the same original DWO
12725 file, we can combine them back into a virtual DWO file to save space
12726 (fewer struct dwo_file objects to allocate). Remember that for really
12727 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12729 std::string virtual_dwo_name
=
12730 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12731 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12732 (long) (sections
.line_size
? sections
.line_offset
: 0),
12733 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12734 (long) (sections
.str_offsets_size
12735 ? sections
.str_offsets_offset
: 0));
12736 /* Can we use an existing virtual DWO file? */
12737 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12738 virtual_dwo_name
.c_str (),
12740 /* Create one if necessary. */
12741 if (*dwo_file_slot
== NULL
)
12743 if (dwarf_read_debug
)
12745 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12746 virtual_dwo_name
.c_str ());
12748 dwo_file
= new struct dwo_file
;
12749 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12751 dwo_file
->comp_dir
= comp_dir
;
12752 dwo_file
->sections
.abbrev
=
12753 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12754 sections
.abbrev_offset
, sections
.abbrev_size
);
12755 dwo_file
->sections
.line
=
12756 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12757 sections
.line_offset
, sections
.line_size
);
12758 dwo_file
->sections
.loc
=
12759 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12760 sections
.loc_offset
, sections
.loc_size
);
12761 dwo_file
->sections
.macinfo
=
12762 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12763 sections
.macinfo_offset
, sections
.macinfo_size
);
12764 dwo_file
->sections
.macro
=
12765 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12766 sections
.macro_offset
, sections
.macro_size
);
12767 dwo_file
->sections
.str_offsets
=
12768 create_dwp_v2_section (dwarf2_per_objfile
,
12769 &dwp_file
->sections
.str_offsets
,
12770 sections
.str_offsets_offset
,
12771 sections
.str_offsets_size
);
12772 /* The "str" section is global to the entire DWP file. */
12773 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12774 /* The info or types section is assigned below to dwo_unit,
12775 there's no need to record it in dwo_file.
12776 Also, we can't simply record type sections in dwo_file because
12777 we record a pointer into the vector in dwo_unit. As we collect more
12778 types we'll grow the vector and eventually have to reallocate space
12779 for it, invalidating all copies of pointers into the previous
12781 *dwo_file_slot
= dwo_file
;
12785 if (dwarf_read_debug
)
12787 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12788 virtual_dwo_name
.c_str ());
12790 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12793 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12794 dwo_unit
->dwo_file
= dwo_file
;
12795 dwo_unit
->signature
= signature
;
12796 dwo_unit
->section
=
12797 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12798 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12800 ? &dwp_file
->sections
.types
12801 : &dwp_file
->sections
.info
,
12802 sections
.info_or_types_offset
,
12803 sections
.info_or_types_size
);
12804 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12809 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12810 Returns NULL if the signature isn't found. */
12812 static struct dwo_unit
*
12813 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12814 struct dwp_file
*dwp_file
, const char *comp_dir
,
12815 ULONGEST signature
, int is_debug_types
)
12817 const struct dwp_hash_table
*dwp_htab
=
12818 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12819 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12820 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12821 uint32_t hash
= signature
& mask
;
12822 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12825 struct dwo_unit find_dwo_cu
;
12827 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12828 find_dwo_cu
.signature
= signature
;
12829 slot
= htab_find_slot (is_debug_types
12830 ? dwp_file
->loaded_tus
12831 : dwp_file
->loaded_cus
,
12832 &find_dwo_cu
, INSERT
);
12835 return (struct dwo_unit
*) *slot
;
12837 /* Use a for loop so that we don't loop forever on bad debug info. */
12838 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12840 ULONGEST signature_in_table
;
12842 signature_in_table
=
12843 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12844 if (signature_in_table
== signature
)
12846 uint32_t unit_index
=
12847 read_4_bytes (dbfd
,
12848 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12850 if (dwp_file
->version
== 1)
12852 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12853 dwp_file
, unit_index
,
12854 comp_dir
, signature
,
12859 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12860 dwp_file
, unit_index
,
12861 comp_dir
, signature
,
12864 return (struct dwo_unit
*) *slot
;
12866 if (signature_in_table
== 0)
12868 hash
= (hash
+ hash2
) & mask
;
12871 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12872 " [in module %s]"),
12876 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12877 Open the file specified by FILE_NAME and hand it off to BFD for
12878 preliminary analysis. Return a newly initialized bfd *, which
12879 includes a canonicalized copy of FILE_NAME.
12880 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12881 SEARCH_CWD is true if the current directory is to be searched.
12882 It will be searched before debug-file-directory.
12883 If successful, the file is added to the bfd include table of the
12884 objfile's bfd (see gdb_bfd_record_inclusion).
12885 If unable to find/open the file, return NULL.
12886 NOTE: This function is derived from symfile_bfd_open. */
12888 static gdb_bfd_ref_ptr
12889 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12890 const char *file_name
, int is_dwp
, int search_cwd
)
12893 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12894 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12895 to debug_file_directory. */
12896 const char *search_path
;
12897 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12899 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12902 if (*debug_file_directory
!= '\0')
12904 search_path_holder
.reset (concat (".", dirname_separator_string
,
12905 debug_file_directory
,
12907 search_path
= search_path_holder
.get ();
12913 search_path
= debug_file_directory
;
12915 openp_flags flags
= OPF_RETURN_REALPATH
;
12917 flags
|= OPF_SEARCH_IN_PATH
;
12919 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12920 desc
= openp (search_path
, flags
, file_name
,
12921 O_RDONLY
| O_BINARY
, &absolute_name
);
12925 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12927 if (sym_bfd
== NULL
)
12929 bfd_set_cacheable (sym_bfd
.get (), 1);
12931 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12934 /* Success. Record the bfd as having been included by the objfile's bfd.
12935 This is important because things like demangled_names_hash lives in the
12936 objfile's per_bfd space and may have references to things like symbol
12937 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12938 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12943 /* Try to open DWO file FILE_NAME.
12944 COMP_DIR is the DW_AT_comp_dir attribute.
12945 The result is the bfd handle of the file.
12946 If there is a problem finding or opening the file, return NULL.
12947 Upon success, the canonicalized path of the file is stored in the bfd,
12948 same as symfile_bfd_open. */
12950 static gdb_bfd_ref_ptr
12951 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12952 const char *file_name
, const char *comp_dir
)
12954 if (IS_ABSOLUTE_PATH (file_name
))
12955 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12956 0 /*is_dwp*/, 0 /*search_cwd*/);
12958 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12960 if (comp_dir
!= NULL
)
12962 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12963 file_name
, (char *) NULL
);
12965 /* NOTE: If comp_dir is a relative path, this will also try the
12966 search path, which seems useful. */
12967 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12970 1 /*search_cwd*/));
12971 xfree (path_to_try
);
12976 /* That didn't work, try debug-file-directory, which, despite its name,
12977 is a list of paths. */
12979 if (*debug_file_directory
== '\0')
12982 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12983 0 /*is_dwp*/, 1 /*search_cwd*/);
12986 /* This function is mapped across the sections and remembers the offset and
12987 size of each of the DWO debugging sections we are interested in. */
12990 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12992 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12993 const struct dwop_section_names
*names
= &dwop_section_names
;
12995 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12997 dwo_sections
->abbrev
.s
.section
= sectp
;
12998 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
13000 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13002 dwo_sections
->info
.s
.section
= sectp
;
13003 dwo_sections
->info
.size
= bfd_section_size (sectp
);
13005 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13007 dwo_sections
->line
.s
.section
= sectp
;
13008 dwo_sections
->line
.size
= bfd_section_size (sectp
);
13010 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13012 dwo_sections
->loc
.s
.section
= sectp
;
13013 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
13015 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13017 dwo_sections
->macinfo
.s
.section
= sectp
;
13018 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
13020 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13022 dwo_sections
->macro
.s
.section
= sectp
;
13023 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
13025 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
13027 dwo_sections
->str
.s
.section
= sectp
;
13028 dwo_sections
->str
.size
= bfd_section_size (sectp
);
13030 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13032 dwo_sections
->str_offsets
.s
.section
= sectp
;
13033 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
13035 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13037 struct dwarf2_section_info type_section
;
13039 memset (&type_section
, 0, sizeof (type_section
));
13040 type_section
.s
.section
= sectp
;
13041 type_section
.size
= bfd_section_size (sectp
);
13042 dwo_sections
->types
.push_back (type_section
);
13046 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13047 by PER_CU. This is for the non-DWP case.
13048 The result is NULL if DWO_NAME can't be found. */
13050 static struct dwo_file
*
13051 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13052 const char *dwo_name
, const char *comp_dir
)
13054 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13056 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
13059 if (dwarf_read_debug
)
13060 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13064 dwo_file_up
dwo_file (new struct dwo_file
);
13065 dwo_file
->dwo_name
= dwo_name
;
13066 dwo_file
->comp_dir
= comp_dir
;
13067 dwo_file
->dbfd
= std::move (dbfd
);
13069 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13070 &dwo_file
->sections
);
13072 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13075 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13076 dwo_file
->sections
.types
, dwo_file
->tus
);
13078 if (dwarf_read_debug
)
13079 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13081 return dwo_file
.release ();
13084 /* This function is mapped across the sections and remembers the offset and
13085 size of each of the DWP debugging sections common to version 1 and 2 that
13086 we are interested in. */
13089 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13090 void *dwp_file_ptr
)
13092 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13093 const struct dwop_section_names
*names
= &dwop_section_names
;
13094 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13096 /* Record the ELF section number for later lookup: this is what the
13097 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13098 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13099 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13101 /* Look for specific sections that we need. */
13102 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13104 dwp_file
->sections
.str
.s
.section
= sectp
;
13105 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13107 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13109 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13110 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13112 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13114 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13115 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13119 /* This function is mapped across the sections and remembers the offset and
13120 size of each of the DWP version 2 debugging sections that we are interested
13121 in. This is split into a separate function because we don't know if we
13122 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13125 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13127 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13128 const struct dwop_section_names
*names
= &dwop_section_names
;
13129 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13131 /* Record the ELF section number for later lookup: this is what the
13132 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13133 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13134 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13136 /* Look for specific sections that we need. */
13137 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13139 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13140 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13142 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13144 dwp_file
->sections
.info
.s
.section
= sectp
;
13145 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13147 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13149 dwp_file
->sections
.line
.s
.section
= sectp
;
13150 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13152 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13154 dwp_file
->sections
.loc
.s
.section
= sectp
;
13155 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13157 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13159 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13160 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13162 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13164 dwp_file
->sections
.macro
.s
.section
= sectp
;
13165 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13167 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13169 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13170 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13172 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13174 dwp_file
->sections
.types
.s
.section
= sectp
;
13175 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13179 /* Hash function for dwp_file loaded CUs/TUs. */
13182 hash_dwp_loaded_cutus (const void *item
)
13184 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13186 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13187 return dwo_unit
->signature
;
13190 /* Equality function for dwp_file loaded CUs/TUs. */
13193 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13195 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13196 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13198 return dua
->signature
== dub
->signature
;
13201 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13204 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13206 return htab_create_alloc_ex (3,
13207 hash_dwp_loaded_cutus
,
13208 eq_dwp_loaded_cutus
,
13210 &objfile
->objfile_obstack
,
13211 hashtab_obstack_allocate
,
13212 dummy_obstack_deallocate
);
13215 /* Try to open DWP file FILE_NAME.
13216 The result is the bfd handle of the file.
13217 If there is a problem finding or opening the file, return NULL.
13218 Upon success, the canonicalized path of the file is stored in the bfd,
13219 same as symfile_bfd_open. */
13221 static gdb_bfd_ref_ptr
13222 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13223 const char *file_name
)
13225 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13227 1 /*search_cwd*/));
13231 /* Work around upstream bug 15652.
13232 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13233 [Whether that's a "bug" is debatable, but it is getting in our way.]
13234 We have no real idea where the dwp file is, because gdb's realpath-ing
13235 of the executable's path may have discarded the needed info.
13236 [IWBN if the dwp file name was recorded in the executable, akin to
13237 .gnu_debuglink, but that doesn't exist yet.]
13238 Strip the directory from FILE_NAME and search again. */
13239 if (*debug_file_directory
!= '\0')
13241 /* Don't implicitly search the current directory here.
13242 If the user wants to search "." to handle this case,
13243 it must be added to debug-file-directory. */
13244 return try_open_dwop_file (dwarf2_per_objfile
,
13245 lbasename (file_name
), 1 /*is_dwp*/,
13252 /* Initialize the use of the DWP file for the current objfile.
13253 By convention the name of the DWP file is ${objfile}.dwp.
13254 The result is NULL if it can't be found. */
13256 static std::unique_ptr
<struct dwp_file
>
13257 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13259 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13261 /* Try to find first .dwp for the binary file before any symbolic links
13264 /* If the objfile is a debug file, find the name of the real binary
13265 file and get the name of dwp file from there. */
13266 std::string dwp_name
;
13267 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13269 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13270 const char *backlink_basename
= lbasename (backlink
->original_name
);
13272 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13275 dwp_name
= objfile
->original_name
;
13277 dwp_name
+= ".dwp";
13279 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13281 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13283 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13284 dwp_name
= objfile_name (objfile
);
13285 dwp_name
+= ".dwp";
13286 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13291 if (dwarf_read_debug
)
13292 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13293 return std::unique_ptr
<dwp_file
> ();
13296 const char *name
= bfd_get_filename (dbfd
.get ());
13297 std::unique_ptr
<struct dwp_file
> dwp_file
13298 (new struct dwp_file (name
, std::move (dbfd
)));
13300 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13301 dwp_file
->elf_sections
=
13302 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13303 dwp_file
->num_sections
, asection
*);
13305 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13306 dwarf2_locate_common_dwp_sections
,
13309 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13312 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13315 /* The DWP file version is stored in the hash table. Oh well. */
13316 if (dwp_file
->cus
&& dwp_file
->tus
13317 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13319 /* Technically speaking, we should try to limp along, but this is
13320 pretty bizarre. We use pulongest here because that's the established
13321 portability solution (e.g, we cannot use %u for uint32_t). */
13322 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13323 " TU version %s [in DWP file %s]"),
13324 pulongest (dwp_file
->cus
->version
),
13325 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13329 dwp_file
->version
= dwp_file
->cus
->version
;
13330 else if (dwp_file
->tus
)
13331 dwp_file
->version
= dwp_file
->tus
->version
;
13333 dwp_file
->version
= 2;
13335 if (dwp_file
->version
== 2)
13336 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13337 dwarf2_locate_v2_dwp_sections
,
13340 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13341 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13343 if (dwarf_read_debug
)
13345 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13346 fprintf_unfiltered (gdb_stdlog
,
13347 " %s CUs, %s TUs\n",
13348 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13349 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13355 /* Wrapper around open_and_init_dwp_file, only open it once. */
13357 static struct dwp_file
*
13358 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13360 if (! dwarf2_per_objfile
->dwp_checked
)
13362 dwarf2_per_objfile
->dwp_file
13363 = open_and_init_dwp_file (dwarf2_per_objfile
);
13364 dwarf2_per_objfile
->dwp_checked
= 1;
13366 return dwarf2_per_objfile
->dwp_file
.get ();
13369 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13370 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13371 or in the DWP file for the objfile, referenced by THIS_UNIT.
13372 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13373 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13375 This is called, for example, when wanting to read a variable with a
13376 complex location. Therefore we don't want to do file i/o for every call.
13377 Therefore we don't want to look for a DWO file on every call.
13378 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13379 then we check if we've already seen DWO_NAME, and only THEN do we check
13382 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13383 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13385 static struct dwo_unit
*
13386 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13387 const char *dwo_name
, const char *comp_dir
,
13388 ULONGEST signature
, int is_debug_types
)
13390 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13391 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13392 const char *kind
= is_debug_types
? "TU" : "CU";
13393 void **dwo_file_slot
;
13394 struct dwo_file
*dwo_file
;
13395 struct dwp_file
*dwp_file
;
13397 /* First see if there's a DWP file.
13398 If we have a DWP file but didn't find the DWO inside it, don't
13399 look for the original DWO file. It makes gdb behave differently
13400 depending on whether one is debugging in the build tree. */
13402 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13403 if (dwp_file
!= NULL
)
13405 const struct dwp_hash_table
*dwp_htab
=
13406 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13408 if (dwp_htab
!= NULL
)
13410 struct dwo_unit
*dwo_cutu
=
13411 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13412 signature
, is_debug_types
);
13414 if (dwo_cutu
!= NULL
)
13416 if (dwarf_read_debug
)
13418 fprintf_unfiltered (gdb_stdlog
,
13419 "Virtual DWO %s %s found: @%s\n",
13420 kind
, hex_string (signature
),
13421 host_address_to_string (dwo_cutu
));
13429 /* No DWP file, look for the DWO file. */
13431 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13432 dwo_name
, comp_dir
);
13433 if (*dwo_file_slot
== NULL
)
13435 /* Read in the file and build a table of the CUs/TUs it contains. */
13436 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13438 /* NOTE: This will be NULL if unable to open the file. */
13439 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13441 if (dwo_file
!= NULL
)
13443 struct dwo_unit
*dwo_cutu
= NULL
;
13445 if (is_debug_types
&& dwo_file
->tus
)
13447 struct dwo_unit find_dwo_cutu
;
13449 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13450 find_dwo_cutu
.signature
= signature
;
13452 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13454 else if (!is_debug_types
&& dwo_file
->cus
)
13456 struct dwo_unit find_dwo_cutu
;
13458 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13459 find_dwo_cutu
.signature
= signature
;
13460 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13464 if (dwo_cutu
!= NULL
)
13466 if (dwarf_read_debug
)
13468 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13469 kind
, dwo_name
, hex_string (signature
),
13470 host_address_to_string (dwo_cutu
));
13477 /* We didn't find it. This could mean a dwo_id mismatch, or
13478 someone deleted the DWO/DWP file, or the search path isn't set up
13479 correctly to find the file. */
13481 if (dwarf_read_debug
)
13483 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13484 kind
, dwo_name
, hex_string (signature
));
13487 /* This is a warning and not a complaint because it can be caused by
13488 pilot error (e.g., user accidentally deleting the DWO). */
13490 /* Print the name of the DWP file if we looked there, helps the user
13491 better diagnose the problem. */
13492 std::string dwp_text
;
13494 if (dwp_file
!= NULL
)
13495 dwp_text
= string_printf (" [in DWP file %s]",
13496 lbasename (dwp_file
->name
));
13498 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13499 " [in module %s]"),
13500 kind
, dwo_name
, hex_string (signature
),
13502 this_unit
->is_debug_types
? "TU" : "CU",
13503 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13508 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13509 See lookup_dwo_cutu_unit for details. */
13511 static struct dwo_unit
*
13512 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13513 const char *dwo_name
, const char *comp_dir
,
13514 ULONGEST signature
)
13516 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13519 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13520 See lookup_dwo_cutu_unit for details. */
13522 static struct dwo_unit
*
13523 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13524 const char *dwo_name
, const char *comp_dir
)
13526 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13529 /* Traversal function for queue_and_load_all_dwo_tus. */
13532 queue_and_load_dwo_tu (void **slot
, void *info
)
13534 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13535 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13536 ULONGEST signature
= dwo_unit
->signature
;
13537 struct signatured_type
*sig_type
=
13538 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13540 if (sig_type
!= NULL
)
13542 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13544 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13545 a real dependency of PER_CU on SIG_TYPE. That is detected later
13546 while processing PER_CU. */
13547 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13548 load_full_type_unit (sig_cu
);
13549 per_cu
->imported_symtabs_push (sig_cu
);
13555 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13556 The DWO may have the only definition of the type, though it may not be
13557 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13558 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13561 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13563 struct dwo_unit
*dwo_unit
;
13564 struct dwo_file
*dwo_file
;
13566 gdb_assert (!per_cu
->is_debug_types
);
13567 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13568 gdb_assert (per_cu
->cu
!= NULL
);
13570 dwo_unit
= per_cu
->cu
->dwo_unit
;
13571 gdb_assert (dwo_unit
!= NULL
);
13573 dwo_file
= dwo_unit
->dwo_file
;
13574 if (dwo_file
->tus
!= NULL
)
13575 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13578 /* Read in various DIEs. */
13580 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13581 Inherit only the children of the DW_AT_abstract_origin DIE not being
13582 already referenced by DW_AT_abstract_origin from the children of the
13586 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13588 struct die_info
*child_die
;
13589 sect_offset
*offsetp
;
13590 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13591 struct die_info
*origin_die
;
13592 /* Iterator of the ORIGIN_DIE children. */
13593 struct die_info
*origin_child_die
;
13594 struct attribute
*attr
;
13595 struct dwarf2_cu
*origin_cu
;
13596 struct pending
**origin_previous_list_in_scope
;
13598 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13602 /* Note that following die references may follow to a die in a
13606 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13608 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13610 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13611 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13613 if (die
->tag
!= origin_die
->tag
13614 && !(die
->tag
== DW_TAG_inlined_subroutine
13615 && origin_die
->tag
== DW_TAG_subprogram
))
13616 complaint (_("DIE %s and its abstract origin %s have different tags"),
13617 sect_offset_str (die
->sect_off
),
13618 sect_offset_str (origin_die
->sect_off
));
13620 std::vector
<sect_offset
> offsets
;
13622 for (child_die
= die
->child
;
13623 child_die
&& child_die
->tag
;
13624 child_die
= sibling_die (child_die
))
13626 struct die_info
*child_origin_die
;
13627 struct dwarf2_cu
*child_origin_cu
;
13629 /* We are trying to process concrete instance entries:
13630 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13631 it's not relevant to our analysis here. i.e. detecting DIEs that are
13632 present in the abstract instance but not referenced in the concrete
13634 if (child_die
->tag
== DW_TAG_call_site
13635 || child_die
->tag
== DW_TAG_GNU_call_site
)
13638 /* For each CHILD_DIE, find the corresponding child of
13639 ORIGIN_DIE. If there is more than one layer of
13640 DW_AT_abstract_origin, follow them all; there shouldn't be,
13641 but GCC versions at least through 4.4 generate this (GCC PR
13643 child_origin_die
= child_die
;
13644 child_origin_cu
= cu
;
13647 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13651 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13655 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13656 counterpart may exist. */
13657 if (child_origin_die
!= child_die
)
13659 if (child_die
->tag
!= child_origin_die
->tag
13660 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13661 && child_origin_die
->tag
== DW_TAG_subprogram
))
13662 complaint (_("Child DIE %s and its abstract origin %s have "
13664 sect_offset_str (child_die
->sect_off
),
13665 sect_offset_str (child_origin_die
->sect_off
));
13666 if (child_origin_die
->parent
!= origin_die
)
13667 complaint (_("Child DIE %s and its abstract origin %s have "
13668 "different parents"),
13669 sect_offset_str (child_die
->sect_off
),
13670 sect_offset_str (child_origin_die
->sect_off
));
13672 offsets
.push_back (child_origin_die
->sect_off
);
13675 std::sort (offsets
.begin (), offsets
.end ());
13676 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13677 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13678 if (offsetp
[-1] == *offsetp
)
13679 complaint (_("Multiple children of DIE %s refer "
13680 "to DIE %s as their abstract origin"),
13681 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13683 offsetp
= offsets
.data ();
13684 origin_child_die
= origin_die
->child
;
13685 while (origin_child_die
&& origin_child_die
->tag
)
13687 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13688 while (offsetp
< offsets_end
13689 && *offsetp
< origin_child_die
->sect_off
)
13691 if (offsetp
>= offsets_end
13692 || *offsetp
> origin_child_die
->sect_off
)
13694 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13695 Check whether we're already processing ORIGIN_CHILD_DIE.
13696 This can happen with mutually referenced abstract_origins.
13698 if (!origin_child_die
->in_process
)
13699 process_die (origin_child_die
, origin_cu
);
13701 origin_child_die
= sibling_die (origin_child_die
);
13703 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13705 if (cu
!= origin_cu
)
13706 compute_delayed_physnames (origin_cu
);
13710 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13712 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13713 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13714 struct context_stack
*newobj
;
13717 struct die_info
*child_die
;
13718 struct attribute
*attr
, *call_line
, *call_file
;
13720 CORE_ADDR baseaddr
;
13721 struct block
*block
;
13722 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13723 std::vector
<struct symbol
*> template_args
;
13724 struct template_symbol
*templ_func
= NULL
;
13728 /* If we do not have call site information, we can't show the
13729 caller of this inlined function. That's too confusing, so
13730 only use the scope for local variables. */
13731 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13732 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13733 if (call_line
== NULL
|| call_file
== NULL
)
13735 read_lexical_block_scope (die
, cu
);
13740 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13742 name
= dwarf2_name (die
, cu
);
13744 /* Ignore functions with missing or empty names. These are actually
13745 illegal according to the DWARF standard. */
13748 complaint (_("missing name for subprogram DIE at %s"),
13749 sect_offset_str (die
->sect_off
));
13753 /* Ignore functions with missing or invalid low and high pc attributes. */
13754 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13755 <= PC_BOUNDS_INVALID
)
13757 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13758 if (!attr
|| !DW_UNSND (attr
))
13759 complaint (_("cannot get low and high bounds "
13760 "for subprogram DIE at %s"),
13761 sect_offset_str (die
->sect_off
));
13765 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13766 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13768 /* If we have any template arguments, then we must allocate a
13769 different sort of symbol. */
13770 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13772 if (child_die
->tag
== DW_TAG_template_type_param
13773 || child_die
->tag
== DW_TAG_template_value_param
)
13775 templ_func
= allocate_template_symbol (objfile
);
13776 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13781 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13782 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13783 (struct symbol
*) templ_func
);
13785 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13786 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13789 /* If there is a location expression for DW_AT_frame_base, record
13791 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13792 if (attr
!= nullptr)
13793 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13795 /* If there is a location for the static link, record it. */
13796 newobj
->static_link
= NULL
;
13797 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13798 if (attr
!= nullptr)
13800 newobj
->static_link
13801 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13802 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13803 dwarf2_per_cu_addr_type (cu
->per_cu
));
13806 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13808 if (die
->child
!= NULL
)
13810 child_die
= die
->child
;
13811 while (child_die
&& child_die
->tag
)
13813 if (child_die
->tag
== DW_TAG_template_type_param
13814 || child_die
->tag
== DW_TAG_template_value_param
)
13816 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13819 template_args
.push_back (arg
);
13822 process_die (child_die
, cu
);
13823 child_die
= sibling_die (child_die
);
13827 inherit_abstract_dies (die
, cu
);
13829 /* If we have a DW_AT_specification, we might need to import using
13830 directives from the context of the specification DIE. See the
13831 comment in determine_prefix. */
13832 if (cu
->language
== language_cplus
13833 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13835 struct dwarf2_cu
*spec_cu
= cu
;
13836 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13840 child_die
= spec_die
->child
;
13841 while (child_die
&& child_die
->tag
)
13843 if (child_die
->tag
== DW_TAG_imported_module
)
13844 process_die (child_die
, spec_cu
);
13845 child_die
= sibling_die (child_die
);
13848 /* In some cases, GCC generates specification DIEs that
13849 themselves contain DW_AT_specification attributes. */
13850 spec_die
= die_specification (spec_die
, &spec_cu
);
13854 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13855 /* Make a block for the local symbols within. */
13856 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13857 cstk
.static_link
, lowpc
, highpc
);
13859 /* For C++, set the block's scope. */
13860 if ((cu
->language
== language_cplus
13861 || cu
->language
== language_fortran
13862 || cu
->language
== language_d
13863 || cu
->language
== language_rust
)
13864 && cu
->processing_has_namespace_info
)
13865 block_set_scope (block
, determine_prefix (die
, cu
),
13866 &objfile
->objfile_obstack
);
13868 /* If we have address ranges, record them. */
13869 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13871 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13873 /* Attach template arguments to function. */
13874 if (!template_args
.empty ())
13876 gdb_assert (templ_func
!= NULL
);
13878 templ_func
->n_template_arguments
= template_args
.size ();
13879 templ_func
->template_arguments
13880 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13881 templ_func
->n_template_arguments
);
13882 memcpy (templ_func
->template_arguments
,
13883 template_args
.data (),
13884 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13886 /* Make sure that the symtab is set on the new symbols. Even
13887 though they don't appear in this symtab directly, other parts
13888 of gdb assume that symbols do, and this is reasonably
13890 for (symbol
*sym
: template_args
)
13891 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13894 /* In C++, we can have functions nested inside functions (e.g., when
13895 a function declares a class that has methods). This means that
13896 when we finish processing a function scope, we may need to go
13897 back to building a containing block's symbol lists. */
13898 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13899 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13901 /* If we've finished processing a top-level function, subsequent
13902 symbols go in the file symbol list. */
13903 if (cu
->get_builder ()->outermost_context_p ())
13904 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13907 /* Process all the DIES contained within a lexical block scope. Start
13908 a new scope, process the dies, and then close the scope. */
13911 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13913 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13914 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13915 CORE_ADDR lowpc
, highpc
;
13916 struct die_info
*child_die
;
13917 CORE_ADDR baseaddr
;
13919 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13921 /* Ignore blocks with missing or invalid low and high pc attributes. */
13922 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13923 as multiple lexical blocks? Handling children in a sane way would
13924 be nasty. Might be easier to properly extend generic blocks to
13925 describe ranges. */
13926 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13928 case PC_BOUNDS_NOT_PRESENT
:
13929 /* DW_TAG_lexical_block has no attributes, process its children as if
13930 there was no wrapping by that DW_TAG_lexical_block.
13931 GCC does no longer produces such DWARF since GCC r224161. */
13932 for (child_die
= die
->child
;
13933 child_die
!= NULL
&& child_die
->tag
;
13934 child_die
= sibling_die (child_die
))
13935 process_die (child_die
, cu
);
13937 case PC_BOUNDS_INVALID
:
13940 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13941 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13943 cu
->get_builder ()->push_context (0, lowpc
);
13944 if (die
->child
!= NULL
)
13946 child_die
= die
->child
;
13947 while (child_die
&& child_die
->tag
)
13949 process_die (child_die
, cu
);
13950 child_die
= sibling_die (child_die
);
13953 inherit_abstract_dies (die
, cu
);
13954 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13956 if (*cu
->get_builder ()->get_local_symbols () != NULL
13957 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13959 struct block
*block
13960 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13961 cstk
.start_addr
, highpc
);
13963 /* Note that recording ranges after traversing children, as we
13964 do here, means that recording a parent's ranges entails
13965 walking across all its children's ranges as they appear in
13966 the address map, which is quadratic behavior.
13968 It would be nicer to record the parent's ranges before
13969 traversing its children, simply overriding whatever you find
13970 there. But since we don't even decide whether to create a
13971 block until after we've traversed its children, that's hard
13973 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13975 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13976 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13979 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13982 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13984 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13985 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13986 CORE_ADDR pc
, baseaddr
;
13987 struct attribute
*attr
;
13988 struct call_site
*call_site
, call_site_local
;
13991 struct die_info
*child_die
;
13993 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13995 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13998 /* This was a pre-DWARF-5 GNU extension alias
13999 for DW_AT_call_return_pc. */
14000 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14004 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
14005 "DIE %s [in module %s]"),
14006 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14009 pc
= attr_value_as_address (attr
) + baseaddr
;
14010 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
14012 if (cu
->call_site_htab
== NULL
)
14013 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
14014 NULL
, &objfile
->objfile_obstack
,
14015 hashtab_obstack_allocate
, NULL
);
14016 call_site_local
.pc
= pc
;
14017 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
14020 complaint (_("Duplicate PC %s for DW_TAG_call_site "
14021 "DIE %s [in module %s]"),
14022 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
14023 objfile_name (objfile
));
14027 /* Count parameters at the caller. */
14030 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14031 child_die
= sibling_die (child_die
))
14033 if (child_die
->tag
!= DW_TAG_call_site_parameter
14034 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14036 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
14037 "DW_TAG_call_site child DIE %s [in module %s]"),
14038 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14039 objfile_name (objfile
));
14047 = ((struct call_site
*)
14048 obstack_alloc (&objfile
->objfile_obstack
,
14049 sizeof (*call_site
)
14050 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14052 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14053 call_site
->pc
= pc
;
14055 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14056 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14058 struct die_info
*func_die
;
14060 /* Skip also over DW_TAG_inlined_subroutine. */
14061 for (func_die
= die
->parent
;
14062 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14063 && func_die
->tag
!= DW_TAG_subroutine_type
;
14064 func_die
= func_die
->parent
);
14066 /* DW_AT_call_all_calls is a superset
14067 of DW_AT_call_all_tail_calls. */
14069 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14070 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14071 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14072 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14074 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14075 not complete. But keep CALL_SITE for look ups via call_site_htab,
14076 both the initial caller containing the real return address PC and
14077 the final callee containing the current PC of a chain of tail
14078 calls do not need to have the tail call list complete. But any
14079 function candidate for a virtual tail call frame searched via
14080 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14081 determined unambiguously. */
14085 struct type
*func_type
= NULL
;
14088 func_type
= get_die_type (func_die
, cu
);
14089 if (func_type
!= NULL
)
14091 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14093 /* Enlist this call site to the function. */
14094 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14095 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14098 complaint (_("Cannot find function owning DW_TAG_call_site "
14099 "DIE %s [in module %s]"),
14100 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14104 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14106 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14108 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14111 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14112 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14114 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14115 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14116 /* Keep NULL DWARF_BLOCK. */;
14117 else if (attr_form_is_block (attr
))
14119 struct dwarf2_locexpr_baton
*dlbaton
;
14121 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14122 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14123 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14124 dlbaton
->per_cu
= cu
->per_cu
;
14126 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14128 else if (attr_form_is_ref (attr
))
14130 struct dwarf2_cu
*target_cu
= cu
;
14131 struct die_info
*target_die
;
14133 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14134 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14135 if (die_is_declaration (target_die
, target_cu
))
14137 const char *target_physname
;
14139 /* Prefer the mangled name; otherwise compute the demangled one. */
14140 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14141 if (target_physname
== NULL
)
14142 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14143 if (target_physname
== NULL
)
14144 complaint (_("DW_AT_call_target target DIE has invalid "
14145 "physname, for referencing DIE %s [in module %s]"),
14146 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14148 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14154 /* DW_AT_entry_pc should be preferred. */
14155 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14156 <= PC_BOUNDS_INVALID
)
14157 complaint (_("DW_AT_call_target target DIE has invalid "
14158 "low pc, for referencing DIE %s [in module %s]"),
14159 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14162 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14163 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14168 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14169 "block nor reference, for DIE %s [in module %s]"),
14170 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14172 call_site
->per_cu
= cu
->per_cu
;
14174 for (child_die
= die
->child
;
14175 child_die
&& child_die
->tag
;
14176 child_die
= sibling_die (child_die
))
14178 struct call_site_parameter
*parameter
;
14179 struct attribute
*loc
, *origin
;
14181 if (child_die
->tag
!= DW_TAG_call_site_parameter
14182 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14184 /* Already printed the complaint above. */
14188 gdb_assert (call_site
->parameter_count
< nparams
);
14189 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14191 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14192 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14193 register is contained in DW_AT_call_value. */
14195 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14196 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14197 if (origin
== NULL
)
14199 /* This was a pre-DWARF-5 GNU extension alias
14200 for DW_AT_call_parameter. */
14201 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14203 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14205 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14207 sect_offset sect_off
14208 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14209 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14211 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14212 binding can be done only inside one CU. Such referenced DIE
14213 therefore cannot be even moved to DW_TAG_partial_unit. */
14214 complaint (_("DW_AT_call_parameter offset is not in CU for "
14215 "DW_TAG_call_site child DIE %s [in module %s]"),
14216 sect_offset_str (child_die
->sect_off
),
14217 objfile_name (objfile
));
14220 parameter
->u
.param_cu_off
14221 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14223 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14225 complaint (_("No DW_FORM_block* DW_AT_location for "
14226 "DW_TAG_call_site child DIE %s [in module %s]"),
14227 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14232 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14233 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14234 if (parameter
->u
.dwarf_reg
!= -1)
14235 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14236 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14237 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14238 ¶meter
->u
.fb_offset
))
14239 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14242 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14243 "for DW_FORM_block* DW_AT_location is supported for "
14244 "DW_TAG_call_site child DIE %s "
14246 sect_offset_str (child_die
->sect_off
),
14247 objfile_name (objfile
));
14252 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14254 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14255 if (!attr_form_is_block (attr
))
14257 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14258 "DW_TAG_call_site child DIE %s [in module %s]"),
14259 sect_offset_str (child_die
->sect_off
),
14260 objfile_name (objfile
));
14263 parameter
->value
= DW_BLOCK (attr
)->data
;
14264 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14266 /* Parameters are not pre-cleared by memset above. */
14267 parameter
->data_value
= NULL
;
14268 parameter
->data_value_size
= 0;
14269 call_site
->parameter_count
++;
14271 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14273 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14274 if (attr
!= nullptr)
14276 if (!attr_form_is_block (attr
))
14277 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14278 "DW_TAG_call_site child DIE %s [in module %s]"),
14279 sect_offset_str (child_die
->sect_off
),
14280 objfile_name (objfile
));
14283 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14284 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14290 /* Helper function for read_variable. If DIE represents a virtual
14291 table, then return the type of the concrete object that is
14292 associated with the virtual table. Otherwise, return NULL. */
14294 static struct type
*
14295 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14297 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14301 /* Find the type DIE. */
14302 struct die_info
*type_die
= NULL
;
14303 struct dwarf2_cu
*type_cu
= cu
;
14305 if (attr_form_is_ref (attr
))
14306 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14307 if (type_die
== NULL
)
14310 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14312 return die_containing_type (type_die
, type_cu
);
14315 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14318 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14320 struct rust_vtable_symbol
*storage
= NULL
;
14322 if (cu
->language
== language_rust
)
14324 struct type
*containing_type
= rust_containing_type (die
, cu
);
14326 if (containing_type
!= NULL
)
14328 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14330 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
14331 initialize_objfile_symbol (storage
);
14332 storage
->concrete_type
= containing_type
;
14333 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14337 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14338 struct attribute
*abstract_origin
14339 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14340 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14341 if (res
== NULL
&& loc
&& abstract_origin
)
14343 /* We have a variable without a name, but with a location and an abstract
14344 origin. This may be a concrete instance of an abstract variable
14345 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14347 struct dwarf2_cu
*origin_cu
= cu
;
14348 struct die_info
*origin_die
14349 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14350 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14351 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14355 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14356 reading .debug_rnglists.
14357 Callback's type should be:
14358 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14359 Return true if the attributes are present and valid, otherwise,
14362 template <typename Callback
>
14364 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14365 Callback
&&callback
)
14367 struct dwarf2_per_objfile
*dwarf2_per_objfile
14368 = cu
->per_cu
->dwarf2_per_objfile
;
14369 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14370 bfd
*obfd
= objfile
->obfd
;
14371 /* Base address selection entry. */
14374 const gdb_byte
*buffer
;
14375 CORE_ADDR baseaddr
;
14376 bool overflow
= false;
14378 found_base
= cu
->base_known
;
14379 base
= cu
->base_address
;
14381 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14382 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14384 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14388 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14390 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14394 /* Initialize it due to a false compiler warning. */
14395 CORE_ADDR range_beginning
= 0, range_end
= 0;
14396 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14397 + dwarf2_per_objfile
->rnglists
.size
);
14398 unsigned int bytes_read
;
14400 if (buffer
== buf_end
)
14405 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14408 case DW_RLE_end_of_list
:
14410 case DW_RLE_base_address
:
14411 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14416 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14418 buffer
+= bytes_read
;
14420 case DW_RLE_start_length
:
14421 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14426 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14427 buffer
+= bytes_read
;
14428 range_end
= (range_beginning
14429 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14430 buffer
+= bytes_read
;
14431 if (buffer
> buf_end
)
14437 case DW_RLE_offset_pair
:
14438 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14439 buffer
+= bytes_read
;
14440 if (buffer
> buf_end
)
14445 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14446 buffer
+= bytes_read
;
14447 if (buffer
> buf_end
)
14453 case DW_RLE_start_end
:
14454 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14459 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14460 buffer
+= bytes_read
;
14461 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14462 buffer
+= bytes_read
;
14465 complaint (_("Invalid .debug_rnglists data (no base address)"));
14468 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14470 if (rlet
== DW_RLE_base_address
)
14475 /* We have no valid base address for the ranges
14477 complaint (_("Invalid .debug_rnglists data (no base address)"));
14481 if (range_beginning
> range_end
)
14483 /* Inverted range entries are invalid. */
14484 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14488 /* Empty range entries have no effect. */
14489 if (range_beginning
== range_end
)
14492 range_beginning
+= base
;
14495 /* A not-uncommon case of bad debug info.
14496 Don't pollute the addrmap with bad data. */
14497 if (range_beginning
+ baseaddr
== 0
14498 && !dwarf2_per_objfile
->has_section_at_zero
)
14500 complaint (_(".debug_rnglists entry has start address of zero"
14501 " [in module %s]"), objfile_name (objfile
));
14505 callback (range_beginning
, range_end
);
14510 complaint (_("Offset %d is not terminated "
14511 "for DW_AT_ranges attribute"),
14519 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14520 Callback's type should be:
14521 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14522 Return 1 if the attributes are present and valid, otherwise, return 0. */
14524 template <typename Callback
>
14526 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14527 Callback
&&callback
)
14529 struct dwarf2_per_objfile
*dwarf2_per_objfile
14530 = cu
->per_cu
->dwarf2_per_objfile
;
14531 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14532 struct comp_unit_head
*cu_header
= &cu
->header
;
14533 bfd
*obfd
= objfile
->obfd
;
14534 unsigned int addr_size
= cu_header
->addr_size
;
14535 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14536 /* Base address selection entry. */
14539 unsigned int dummy
;
14540 const gdb_byte
*buffer
;
14541 CORE_ADDR baseaddr
;
14543 if (cu_header
->version
>= 5)
14544 return dwarf2_rnglists_process (offset
, cu
, callback
);
14546 found_base
= cu
->base_known
;
14547 base
= cu
->base_address
;
14549 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14550 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14552 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14556 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14558 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14562 CORE_ADDR range_beginning
, range_end
;
14564 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14565 buffer
+= addr_size
;
14566 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14567 buffer
+= addr_size
;
14568 offset
+= 2 * addr_size
;
14570 /* An end of list marker is a pair of zero addresses. */
14571 if (range_beginning
== 0 && range_end
== 0)
14572 /* Found the end of list entry. */
14575 /* Each base address selection entry is a pair of 2 values.
14576 The first is the largest possible address, the second is
14577 the base address. Check for a base address here. */
14578 if ((range_beginning
& mask
) == mask
)
14580 /* If we found the largest possible address, then we already
14581 have the base address in range_end. */
14589 /* We have no valid base address for the ranges
14591 complaint (_("Invalid .debug_ranges data (no base address)"));
14595 if (range_beginning
> range_end
)
14597 /* Inverted range entries are invalid. */
14598 complaint (_("Invalid .debug_ranges data (inverted range)"));
14602 /* Empty range entries have no effect. */
14603 if (range_beginning
== range_end
)
14606 range_beginning
+= base
;
14609 /* A not-uncommon case of bad debug info.
14610 Don't pollute the addrmap with bad data. */
14611 if (range_beginning
+ baseaddr
== 0
14612 && !dwarf2_per_objfile
->has_section_at_zero
)
14614 complaint (_(".debug_ranges entry has start address of zero"
14615 " [in module %s]"), objfile_name (objfile
));
14619 callback (range_beginning
, range_end
);
14625 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14626 Return 1 if the attributes are present and valid, otherwise, return 0.
14627 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14630 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14631 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14632 struct partial_symtab
*ranges_pst
)
14634 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14635 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14636 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14637 SECT_OFF_TEXT (objfile
));
14640 CORE_ADDR high
= 0;
14643 retval
= dwarf2_ranges_process (offset
, cu
,
14644 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14646 if (ranges_pst
!= NULL
)
14651 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14652 range_beginning
+ baseaddr
)
14654 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14655 range_end
+ baseaddr
)
14657 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14658 lowpc
, highpc
- 1, ranges_pst
);
14661 /* FIXME: This is recording everything as a low-high
14662 segment of consecutive addresses. We should have a
14663 data structure for discontiguous block ranges
14667 low
= range_beginning
;
14673 if (range_beginning
< low
)
14674 low
= range_beginning
;
14675 if (range_end
> high
)
14683 /* If the first entry is an end-of-list marker, the range
14684 describes an empty scope, i.e. no instructions. */
14690 *high_return
= high
;
14694 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14695 definition for the return value. *LOWPC and *HIGHPC are set iff
14696 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14698 static enum pc_bounds_kind
14699 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14700 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14701 struct partial_symtab
*pst
)
14703 struct dwarf2_per_objfile
*dwarf2_per_objfile
14704 = cu
->per_cu
->dwarf2_per_objfile
;
14705 struct attribute
*attr
;
14706 struct attribute
*attr_high
;
14708 CORE_ADDR high
= 0;
14709 enum pc_bounds_kind ret
;
14711 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14714 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14715 if (attr
!= nullptr)
14717 low
= attr_value_as_address (attr
);
14718 high
= attr_value_as_address (attr_high
);
14719 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14723 /* Found high w/o low attribute. */
14724 return PC_BOUNDS_INVALID
;
14726 /* Found consecutive range of addresses. */
14727 ret
= PC_BOUNDS_HIGH_LOW
;
14731 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14734 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14735 We take advantage of the fact that DW_AT_ranges does not appear
14736 in DW_TAG_compile_unit of DWO files. */
14737 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14738 unsigned int ranges_offset
= (DW_UNSND (attr
)
14739 + (need_ranges_base
14743 /* Value of the DW_AT_ranges attribute is the offset in the
14744 .debug_ranges section. */
14745 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14746 return PC_BOUNDS_INVALID
;
14747 /* Found discontinuous range of addresses. */
14748 ret
= PC_BOUNDS_RANGES
;
14751 return PC_BOUNDS_NOT_PRESENT
;
14754 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14756 return PC_BOUNDS_INVALID
;
14758 /* When using the GNU linker, .gnu.linkonce. sections are used to
14759 eliminate duplicate copies of functions and vtables and such.
14760 The linker will arbitrarily choose one and discard the others.
14761 The AT_*_pc values for such functions refer to local labels in
14762 these sections. If the section from that file was discarded, the
14763 labels are not in the output, so the relocs get a value of 0.
14764 If this is a discarded function, mark the pc bounds as invalid,
14765 so that GDB will ignore it. */
14766 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14767 return PC_BOUNDS_INVALID
;
14775 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14776 its low and high PC addresses. Do nothing if these addresses could not
14777 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14778 and HIGHPC to the high address if greater than HIGHPC. */
14781 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14782 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14783 struct dwarf2_cu
*cu
)
14785 CORE_ADDR low
, high
;
14786 struct die_info
*child
= die
->child
;
14788 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14790 *lowpc
= std::min (*lowpc
, low
);
14791 *highpc
= std::max (*highpc
, high
);
14794 /* If the language does not allow nested subprograms (either inside
14795 subprograms or lexical blocks), we're done. */
14796 if (cu
->language
!= language_ada
)
14799 /* Check all the children of the given DIE. If it contains nested
14800 subprograms, then check their pc bounds. Likewise, we need to
14801 check lexical blocks as well, as they may also contain subprogram
14803 while (child
&& child
->tag
)
14805 if (child
->tag
== DW_TAG_subprogram
14806 || child
->tag
== DW_TAG_lexical_block
)
14807 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14808 child
= sibling_die (child
);
14812 /* Get the low and high pc's represented by the scope DIE, and store
14813 them in *LOWPC and *HIGHPC. If the correct values can't be
14814 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14817 get_scope_pc_bounds (struct die_info
*die
,
14818 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14819 struct dwarf2_cu
*cu
)
14821 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14822 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14823 CORE_ADDR current_low
, current_high
;
14825 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14826 >= PC_BOUNDS_RANGES
)
14828 best_low
= current_low
;
14829 best_high
= current_high
;
14833 struct die_info
*child
= die
->child
;
14835 while (child
&& child
->tag
)
14837 switch (child
->tag
) {
14838 case DW_TAG_subprogram
:
14839 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14841 case DW_TAG_namespace
:
14842 case DW_TAG_module
:
14843 /* FIXME: carlton/2004-01-16: Should we do this for
14844 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14845 that current GCC's always emit the DIEs corresponding
14846 to definitions of methods of classes as children of a
14847 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14848 the DIEs giving the declarations, which could be
14849 anywhere). But I don't see any reason why the
14850 standards says that they have to be there. */
14851 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14853 if (current_low
!= ((CORE_ADDR
) -1))
14855 best_low
= std::min (best_low
, current_low
);
14856 best_high
= std::max (best_high
, current_high
);
14864 child
= sibling_die (child
);
14869 *highpc
= best_high
;
14872 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14876 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14877 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14879 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14880 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14881 struct attribute
*attr
;
14882 struct attribute
*attr_high
;
14884 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14887 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14888 if (attr
!= nullptr)
14890 CORE_ADDR low
= attr_value_as_address (attr
);
14891 CORE_ADDR high
= attr_value_as_address (attr_high
);
14893 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14896 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14897 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14898 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14902 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14903 if (attr
!= nullptr)
14905 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14906 We take advantage of the fact that DW_AT_ranges does not appear
14907 in DW_TAG_compile_unit of DWO files. */
14908 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14910 /* The value of the DW_AT_ranges attribute is the offset of the
14911 address range list in the .debug_ranges section. */
14912 unsigned long offset
= (DW_UNSND (attr
)
14913 + (need_ranges_base
? cu
->ranges_base
: 0));
14915 std::vector
<blockrange
> blockvec
;
14916 dwarf2_ranges_process (offset
, cu
,
14917 [&] (CORE_ADDR start
, CORE_ADDR end
)
14921 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14922 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14923 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14924 blockvec
.emplace_back (start
, end
);
14927 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14931 /* Check whether the producer field indicates either of GCC < 4.6, or the
14932 Intel C/C++ compiler, and cache the result in CU. */
14935 check_producer (struct dwarf2_cu
*cu
)
14939 if (cu
->producer
== NULL
)
14941 /* For unknown compilers expect their behavior is DWARF version
14944 GCC started to support .debug_types sections by -gdwarf-4 since
14945 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14946 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14947 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14948 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14950 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14952 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14953 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14955 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14957 cu
->producer_is_icc
= true;
14958 cu
->producer_is_icc_lt_14
= major
< 14;
14960 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14961 cu
->producer_is_codewarrior
= true;
14964 /* For other non-GCC compilers, expect their behavior is DWARF version
14968 cu
->checked_producer
= true;
14971 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14972 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14973 during 4.6.0 experimental. */
14976 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14978 if (!cu
->checked_producer
)
14979 check_producer (cu
);
14981 return cu
->producer_is_gxx_lt_4_6
;
14985 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14986 with incorrect is_stmt attributes. */
14989 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14991 if (!cu
->checked_producer
)
14992 check_producer (cu
);
14994 return cu
->producer_is_codewarrior
;
14997 /* Return the default accessibility type if it is not overridden by
14998 DW_AT_accessibility. */
15000 static enum dwarf_access_attribute
15001 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
15003 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
15005 /* The default DWARF 2 accessibility for members is public, the default
15006 accessibility for inheritance is private. */
15008 if (die
->tag
!= DW_TAG_inheritance
)
15009 return DW_ACCESS_public
;
15011 return DW_ACCESS_private
;
15015 /* DWARF 3+ defines the default accessibility a different way. The same
15016 rules apply now for DW_TAG_inheritance as for the members and it only
15017 depends on the container kind. */
15019 if (die
->parent
->tag
== DW_TAG_class_type
)
15020 return DW_ACCESS_private
;
15022 return DW_ACCESS_public
;
15026 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15027 offset. If the attribute was not found return 0, otherwise return
15028 1. If it was found but could not properly be handled, set *OFFSET
15032 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15035 struct attribute
*attr
;
15037 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15042 /* Note that we do not check for a section offset first here.
15043 This is because DW_AT_data_member_location is new in DWARF 4,
15044 so if we see it, we can assume that a constant form is really
15045 a constant and not a section offset. */
15046 if (attr_form_is_constant (attr
))
15047 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15048 else if (attr_form_is_section_offset (attr
))
15049 dwarf2_complex_location_expr_complaint ();
15050 else if (attr_form_is_block (attr
))
15051 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15053 dwarf2_complex_location_expr_complaint ();
15061 /* Add an aggregate field to the field list. */
15064 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15065 struct dwarf2_cu
*cu
)
15067 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15068 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15069 struct nextfield
*new_field
;
15070 struct attribute
*attr
;
15072 const char *fieldname
= "";
15074 if (die
->tag
== DW_TAG_inheritance
)
15076 fip
->baseclasses
.emplace_back ();
15077 new_field
= &fip
->baseclasses
.back ();
15081 fip
->fields
.emplace_back ();
15082 new_field
= &fip
->fields
.back ();
15087 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15088 if (attr
!= nullptr)
15089 new_field
->accessibility
= DW_UNSND (attr
);
15091 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15092 if (new_field
->accessibility
!= DW_ACCESS_public
)
15093 fip
->non_public_fields
= 1;
15095 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15096 if (attr
!= nullptr)
15097 new_field
->virtuality
= DW_UNSND (attr
);
15099 new_field
->virtuality
= DW_VIRTUALITY_none
;
15101 fp
= &new_field
->field
;
15103 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15107 /* Data member other than a C++ static data member. */
15109 /* Get type of field. */
15110 fp
->type
= die_type (die
, cu
);
15112 SET_FIELD_BITPOS (*fp
, 0);
15114 /* Get bit size of field (zero if none). */
15115 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15116 if (attr
!= nullptr)
15118 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15122 FIELD_BITSIZE (*fp
) = 0;
15125 /* Get bit offset of field. */
15126 if (handle_data_member_location (die
, cu
, &offset
))
15127 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15128 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15129 if (attr
!= nullptr)
15131 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15133 /* For big endian bits, the DW_AT_bit_offset gives the
15134 additional bit offset from the MSB of the containing
15135 anonymous object to the MSB of the field. We don't
15136 have to do anything special since we don't need to
15137 know the size of the anonymous object. */
15138 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15142 /* For little endian bits, compute the bit offset to the
15143 MSB of the anonymous object, subtract off the number of
15144 bits from the MSB of the field to the MSB of the
15145 object, and then subtract off the number of bits of
15146 the field itself. The result is the bit offset of
15147 the LSB of the field. */
15148 int anonymous_size
;
15149 int bit_offset
= DW_UNSND (attr
);
15151 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15152 if (attr
!= nullptr)
15154 /* The size of the anonymous object containing
15155 the bit field is explicit, so use the
15156 indicated size (in bytes). */
15157 anonymous_size
= DW_UNSND (attr
);
15161 /* The size of the anonymous object containing
15162 the bit field must be inferred from the type
15163 attribute of the data member containing the
15165 anonymous_size
= TYPE_LENGTH (fp
->type
);
15167 SET_FIELD_BITPOS (*fp
,
15168 (FIELD_BITPOS (*fp
)
15169 + anonymous_size
* bits_per_byte
15170 - bit_offset
- FIELD_BITSIZE (*fp
)));
15173 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15175 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15176 + dwarf2_get_attr_constant_value (attr
, 0)));
15178 /* Get name of field. */
15179 fieldname
= dwarf2_name (die
, cu
);
15180 if (fieldname
== NULL
)
15183 /* The name is already allocated along with this objfile, so we don't
15184 need to duplicate it for the type. */
15185 fp
->name
= fieldname
;
15187 /* Change accessibility for artificial fields (e.g. virtual table
15188 pointer or virtual base class pointer) to private. */
15189 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15191 FIELD_ARTIFICIAL (*fp
) = 1;
15192 new_field
->accessibility
= DW_ACCESS_private
;
15193 fip
->non_public_fields
= 1;
15196 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15198 /* C++ static member. */
15200 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15201 is a declaration, but all versions of G++ as of this writing
15202 (so through at least 3.2.1) incorrectly generate
15203 DW_TAG_variable tags. */
15205 const char *physname
;
15207 /* Get name of field. */
15208 fieldname
= dwarf2_name (die
, cu
);
15209 if (fieldname
== NULL
)
15212 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15214 /* Only create a symbol if this is an external value.
15215 new_symbol checks this and puts the value in the global symbol
15216 table, which we want. If it is not external, new_symbol
15217 will try to put the value in cu->list_in_scope which is wrong. */
15218 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15220 /* A static const member, not much different than an enum as far as
15221 we're concerned, except that we can support more types. */
15222 new_symbol (die
, NULL
, cu
);
15225 /* Get physical name. */
15226 physname
= dwarf2_physname (fieldname
, die
, cu
);
15228 /* The name is already allocated along with this objfile, so we don't
15229 need to duplicate it for the type. */
15230 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15231 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15232 FIELD_NAME (*fp
) = fieldname
;
15234 else if (die
->tag
== DW_TAG_inheritance
)
15238 /* C++ base class field. */
15239 if (handle_data_member_location (die
, cu
, &offset
))
15240 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15241 FIELD_BITSIZE (*fp
) = 0;
15242 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15243 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15245 else if (die
->tag
== DW_TAG_variant_part
)
15247 /* process_structure_scope will treat this DIE as a union. */
15248 process_structure_scope (die
, cu
);
15250 /* The variant part is relative to the start of the enclosing
15252 SET_FIELD_BITPOS (*fp
, 0);
15253 fp
->type
= get_die_type (die
, cu
);
15254 fp
->artificial
= 1;
15255 fp
->name
= "<<variant>>";
15257 /* Normally a DW_TAG_variant_part won't have a size, but our
15258 representation requires one, so set it to the maximum of the
15259 child sizes, being sure to account for the offset at which
15260 each child is seen. */
15261 if (TYPE_LENGTH (fp
->type
) == 0)
15264 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15266 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
15267 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
15271 TYPE_LENGTH (fp
->type
) = max
;
15275 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15278 /* Can the type given by DIE define another type? */
15281 type_can_define_types (const struct die_info
*die
)
15285 case DW_TAG_typedef
:
15286 case DW_TAG_class_type
:
15287 case DW_TAG_structure_type
:
15288 case DW_TAG_union_type
:
15289 case DW_TAG_enumeration_type
:
15297 /* Add a type definition defined in the scope of the FIP's class. */
15300 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15301 struct dwarf2_cu
*cu
)
15303 struct decl_field fp
;
15304 memset (&fp
, 0, sizeof (fp
));
15306 gdb_assert (type_can_define_types (die
));
15308 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15309 fp
.name
= dwarf2_name (die
, cu
);
15310 fp
.type
= read_type_die (die
, cu
);
15312 /* Save accessibility. */
15313 enum dwarf_access_attribute accessibility
;
15314 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15316 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15318 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15319 switch (accessibility
)
15321 case DW_ACCESS_public
:
15322 /* The assumed value if neither private nor protected. */
15324 case DW_ACCESS_private
:
15327 case DW_ACCESS_protected
:
15328 fp
.is_protected
= 1;
15331 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15334 if (die
->tag
== DW_TAG_typedef
)
15335 fip
->typedef_field_list
.push_back (fp
);
15337 fip
->nested_types_list
.push_back (fp
);
15340 /* Create the vector of fields, and attach it to the type. */
15343 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15344 struct dwarf2_cu
*cu
)
15346 int nfields
= fip
->nfields
;
15348 /* Record the field count, allocate space for the array of fields,
15349 and create blank accessibility bitfields if necessary. */
15350 TYPE_NFIELDS (type
) = nfields
;
15351 TYPE_FIELDS (type
) = (struct field
*)
15352 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15354 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15356 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15358 TYPE_FIELD_PRIVATE_BITS (type
) =
15359 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15360 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15362 TYPE_FIELD_PROTECTED_BITS (type
) =
15363 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15364 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15366 TYPE_FIELD_IGNORE_BITS (type
) =
15367 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15368 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15371 /* If the type has baseclasses, allocate and clear a bit vector for
15372 TYPE_FIELD_VIRTUAL_BITS. */
15373 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15375 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15376 unsigned char *pointer
;
15378 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15379 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15380 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15381 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15382 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15385 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15387 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15389 for (int index
= 0; index
< nfields
; ++index
)
15391 struct nextfield
&field
= fip
->fields
[index
];
15393 if (field
.variant
.is_discriminant
)
15394 di
->discriminant_index
= index
;
15395 else if (field
.variant
.default_branch
)
15396 di
->default_index
= index
;
15398 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15402 /* Copy the saved-up fields into the field vector. */
15403 for (int i
= 0; i
< nfields
; ++i
)
15405 struct nextfield
&field
15406 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15407 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15409 TYPE_FIELD (type
, i
) = field
.field
;
15410 switch (field
.accessibility
)
15412 case DW_ACCESS_private
:
15413 if (cu
->language
!= language_ada
)
15414 SET_TYPE_FIELD_PRIVATE (type
, i
);
15417 case DW_ACCESS_protected
:
15418 if (cu
->language
!= language_ada
)
15419 SET_TYPE_FIELD_PROTECTED (type
, i
);
15422 case DW_ACCESS_public
:
15426 /* Unknown accessibility. Complain and treat it as public. */
15428 complaint (_("unsupported accessibility %d"),
15429 field
.accessibility
);
15433 if (i
< fip
->baseclasses
.size ())
15435 switch (field
.virtuality
)
15437 case DW_VIRTUALITY_virtual
:
15438 case DW_VIRTUALITY_pure_virtual
:
15439 if (cu
->language
== language_ada
)
15440 error (_("unexpected virtuality in component of Ada type"));
15441 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15448 /* Return true if this member function is a constructor, false
15452 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15454 const char *fieldname
;
15455 const char *type_name
;
15458 if (die
->parent
== NULL
)
15461 if (die
->parent
->tag
!= DW_TAG_structure_type
15462 && die
->parent
->tag
!= DW_TAG_union_type
15463 && die
->parent
->tag
!= DW_TAG_class_type
)
15466 fieldname
= dwarf2_name (die
, cu
);
15467 type_name
= dwarf2_name (die
->parent
, cu
);
15468 if (fieldname
== NULL
|| type_name
== NULL
)
15471 len
= strlen (fieldname
);
15472 return (strncmp (fieldname
, type_name
, len
) == 0
15473 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15476 /* Check if the given VALUE is a recognized enum
15477 dwarf_defaulted_attribute constant according to DWARF5 spec,
15481 is_valid_DW_AT_defaulted (ULONGEST value
)
15485 case DW_DEFAULTED_no
:
15486 case DW_DEFAULTED_in_class
:
15487 case DW_DEFAULTED_out_of_class
:
15491 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15495 /* Add a member function to the proper fieldlist. */
15498 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15499 struct type
*type
, struct dwarf2_cu
*cu
)
15501 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15502 struct attribute
*attr
;
15504 struct fnfieldlist
*flp
= nullptr;
15505 struct fn_field
*fnp
;
15506 const char *fieldname
;
15507 struct type
*this_type
;
15508 enum dwarf_access_attribute accessibility
;
15510 if (cu
->language
== language_ada
)
15511 error (_("unexpected member function in Ada type"));
15513 /* Get name of member function. */
15514 fieldname
= dwarf2_name (die
, cu
);
15515 if (fieldname
== NULL
)
15518 /* Look up member function name in fieldlist. */
15519 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15521 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15523 flp
= &fip
->fnfieldlists
[i
];
15528 /* Create a new fnfieldlist if necessary. */
15529 if (flp
== nullptr)
15531 fip
->fnfieldlists
.emplace_back ();
15532 flp
= &fip
->fnfieldlists
.back ();
15533 flp
->name
= fieldname
;
15534 i
= fip
->fnfieldlists
.size () - 1;
15537 /* Create a new member function field and add it to the vector of
15539 flp
->fnfields
.emplace_back ();
15540 fnp
= &flp
->fnfields
.back ();
15542 /* Delay processing of the physname until later. */
15543 if (cu
->language
== language_cplus
)
15544 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15548 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15549 fnp
->physname
= physname
? physname
: "";
15552 fnp
->type
= alloc_type (objfile
);
15553 this_type
= read_type_die (die
, cu
);
15554 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15556 int nparams
= TYPE_NFIELDS (this_type
);
15558 /* TYPE is the domain of this method, and THIS_TYPE is the type
15559 of the method itself (TYPE_CODE_METHOD). */
15560 smash_to_method_type (fnp
->type
, type
,
15561 TYPE_TARGET_TYPE (this_type
),
15562 TYPE_FIELDS (this_type
),
15563 TYPE_NFIELDS (this_type
),
15564 TYPE_VARARGS (this_type
));
15566 /* Handle static member functions.
15567 Dwarf2 has no clean way to discern C++ static and non-static
15568 member functions. G++ helps GDB by marking the first
15569 parameter for non-static member functions (which is the this
15570 pointer) as artificial. We obtain this information from
15571 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15572 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15573 fnp
->voffset
= VOFFSET_STATIC
;
15576 complaint (_("member function type missing for '%s'"),
15577 dwarf2_full_name (fieldname
, die
, cu
));
15579 /* Get fcontext from DW_AT_containing_type if present. */
15580 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15581 fnp
->fcontext
= die_containing_type (die
, cu
);
15583 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15584 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15586 /* Get accessibility. */
15587 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15588 if (attr
!= nullptr)
15589 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15591 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15592 switch (accessibility
)
15594 case DW_ACCESS_private
:
15595 fnp
->is_private
= 1;
15597 case DW_ACCESS_protected
:
15598 fnp
->is_protected
= 1;
15602 /* Check for artificial methods. */
15603 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15604 if (attr
&& DW_UNSND (attr
) != 0)
15605 fnp
->is_artificial
= 1;
15607 /* Check for defaulted methods. */
15608 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15609 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15610 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15612 /* Check for deleted methods. */
15613 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15614 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15615 fnp
->is_deleted
= 1;
15617 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15619 /* Get index in virtual function table if it is a virtual member
15620 function. For older versions of GCC, this is an offset in the
15621 appropriate virtual table, as specified by DW_AT_containing_type.
15622 For everyone else, it is an expression to be evaluated relative
15623 to the object address. */
15625 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15626 if (attr
!= nullptr)
15628 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15630 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15632 /* Old-style GCC. */
15633 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15635 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15636 || (DW_BLOCK (attr
)->size
> 1
15637 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15638 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15640 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15641 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15642 dwarf2_complex_location_expr_complaint ();
15644 fnp
->voffset
/= cu
->header
.addr_size
;
15648 dwarf2_complex_location_expr_complaint ();
15650 if (!fnp
->fcontext
)
15652 /* If there is no `this' field and no DW_AT_containing_type,
15653 we cannot actually find a base class context for the
15655 if (TYPE_NFIELDS (this_type
) == 0
15656 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15658 complaint (_("cannot determine context for virtual member "
15659 "function \"%s\" (offset %s)"),
15660 fieldname
, sect_offset_str (die
->sect_off
));
15665 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15669 else if (attr_form_is_section_offset (attr
))
15671 dwarf2_complex_location_expr_complaint ();
15675 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15681 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15682 if (attr
&& DW_UNSND (attr
))
15684 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15685 complaint (_("Member function \"%s\" (offset %s) is virtual "
15686 "but the vtable offset is not specified"),
15687 fieldname
, sect_offset_str (die
->sect_off
));
15688 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15689 TYPE_CPLUS_DYNAMIC (type
) = 1;
15694 /* Create the vector of member function fields, and attach it to the type. */
15697 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15698 struct dwarf2_cu
*cu
)
15700 if (cu
->language
== language_ada
)
15701 error (_("unexpected member functions in Ada type"));
15703 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15704 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15706 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15708 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15710 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15711 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15713 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15714 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15715 fn_flp
->fn_fields
= (struct fn_field
*)
15716 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15718 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15719 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15722 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15725 /* Returns non-zero if NAME is the name of a vtable member in CU's
15726 language, zero otherwise. */
15728 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15730 static const char vptr
[] = "_vptr";
15732 /* Look for the C++ form of the vtable. */
15733 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15739 /* GCC outputs unnamed structures that are really pointers to member
15740 functions, with the ABI-specified layout. If TYPE describes
15741 such a structure, smash it into a member function type.
15743 GCC shouldn't do this; it should just output pointer to member DIEs.
15744 This is GCC PR debug/28767. */
15747 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15749 struct type
*pfn_type
, *self_type
, *new_type
;
15751 /* Check for a structure with no name and two children. */
15752 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15755 /* Check for __pfn and __delta members. */
15756 if (TYPE_FIELD_NAME (type
, 0) == NULL
15757 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15758 || TYPE_FIELD_NAME (type
, 1) == NULL
15759 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15762 /* Find the type of the method. */
15763 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15764 if (pfn_type
== NULL
15765 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15766 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15769 /* Look for the "this" argument. */
15770 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15771 if (TYPE_NFIELDS (pfn_type
) == 0
15772 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15773 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15776 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15777 new_type
= alloc_type (objfile
);
15778 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15779 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15780 TYPE_VARARGS (pfn_type
));
15781 smash_to_methodptr_type (type
, new_type
);
15784 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15785 appropriate error checking and issuing complaints if there is a
15789 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15791 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15793 if (attr
== nullptr)
15796 if (!attr_form_is_constant (attr
))
15798 complaint (_("DW_AT_alignment must have constant form"
15799 " - DIE at %s [in module %s]"),
15800 sect_offset_str (die
->sect_off
),
15801 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15806 if (attr
->form
== DW_FORM_sdata
)
15808 LONGEST val
= DW_SND (attr
);
15811 complaint (_("DW_AT_alignment value must not be negative"
15812 " - DIE at %s [in module %s]"),
15813 sect_offset_str (die
->sect_off
),
15814 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15820 align
= DW_UNSND (attr
);
15824 complaint (_("DW_AT_alignment value must not be zero"
15825 " - DIE at %s [in module %s]"),
15826 sect_offset_str (die
->sect_off
),
15827 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15830 if ((align
& (align
- 1)) != 0)
15832 complaint (_("DW_AT_alignment value must be a power of 2"
15833 " - DIE at %s [in module %s]"),
15834 sect_offset_str (die
->sect_off
),
15835 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15842 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15843 the alignment for TYPE. */
15846 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15849 if (!set_type_align (type
, get_alignment (cu
, die
)))
15850 complaint (_("DW_AT_alignment value too large"
15851 " - DIE at %s [in module %s]"),
15852 sect_offset_str (die
->sect_off
),
15853 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15856 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15857 constant for a type, according to DWARF5 spec, Table 5.5. */
15860 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15865 case DW_CC_pass_by_reference
:
15866 case DW_CC_pass_by_value
:
15870 complaint (_("unrecognized DW_AT_calling_convention value "
15871 "(%s) for a type"), pulongest (value
));
15876 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15877 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15878 also according to GNU-specific values (see include/dwarf2.h). */
15881 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15886 case DW_CC_program
:
15890 case DW_CC_GNU_renesas_sh
:
15891 case DW_CC_GNU_borland_fastcall_i386
:
15892 case DW_CC_GDB_IBM_OpenCL
:
15896 complaint (_("unrecognized DW_AT_calling_convention value "
15897 "(%s) for a subroutine"), pulongest (value
));
15902 /* Called when we find the DIE that starts a structure or union scope
15903 (definition) to create a type for the structure or union. Fill in
15904 the type's name and general properties; the members will not be
15905 processed until process_structure_scope. A symbol table entry for
15906 the type will also not be done until process_structure_scope (assuming
15907 the type has a name).
15909 NOTE: we need to call these functions regardless of whether or not the
15910 DIE has a DW_AT_name attribute, since it might be an anonymous
15911 structure or union. This gets the type entered into our set of
15912 user defined types. */
15914 static struct type
*
15915 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15917 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15919 struct attribute
*attr
;
15922 /* If the definition of this type lives in .debug_types, read that type.
15923 Don't follow DW_AT_specification though, that will take us back up
15924 the chain and we want to go down. */
15925 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15926 if (attr
!= nullptr)
15928 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15930 /* The type's CU may not be the same as CU.
15931 Ensure TYPE is recorded with CU in die_type_hash. */
15932 return set_die_type (die
, type
, cu
);
15935 type
= alloc_type (objfile
);
15936 INIT_CPLUS_SPECIFIC (type
);
15938 name
= dwarf2_name (die
, cu
);
15941 if (cu
->language
== language_cplus
15942 || cu
->language
== language_d
15943 || cu
->language
== language_rust
)
15945 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15947 /* dwarf2_full_name might have already finished building the DIE's
15948 type. If so, there is no need to continue. */
15949 if (get_die_type (die
, cu
) != NULL
)
15950 return get_die_type (die
, cu
);
15952 TYPE_NAME (type
) = full_name
;
15956 /* The name is already allocated along with this objfile, so
15957 we don't need to duplicate it for the type. */
15958 TYPE_NAME (type
) = name
;
15962 if (die
->tag
== DW_TAG_structure_type
)
15964 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15966 else if (die
->tag
== DW_TAG_union_type
)
15968 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15970 else if (die
->tag
== DW_TAG_variant_part
)
15972 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15973 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15977 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15980 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15981 TYPE_DECLARED_CLASS (type
) = 1;
15983 /* Store the calling convention in the type if it's available in
15984 the die. Otherwise the calling convention remains set to
15985 the default value DW_CC_normal. */
15986 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15987 if (attr
!= nullptr
15988 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15990 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15991 TYPE_CPLUS_CALLING_CONVENTION (type
)
15992 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15995 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15996 if (attr
!= nullptr)
15998 if (attr_form_is_constant (attr
))
15999 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16002 /* For the moment, dynamic type sizes are not supported
16003 by GDB's struct type. The actual size is determined
16004 on-demand when resolving the type of a given object,
16005 so set the type's length to zero for now. Otherwise,
16006 we record an expression as the length, and that expression
16007 could lead to a very large value, which could eventually
16008 lead to us trying to allocate that much memory when creating
16009 a value of that type. */
16010 TYPE_LENGTH (type
) = 0;
16015 TYPE_LENGTH (type
) = 0;
16018 maybe_set_alignment (cu
, die
, type
);
16020 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16022 /* ICC<14 does not output the required DW_AT_declaration on
16023 incomplete types, but gives them a size of zero. */
16024 TYPE_STUB (type
) = 1;
16027 TYPE_STUB_SUPPORTED (type
) = 1;
16029 if (die_is_declaration (die
, cu
))
16030 TYPE_STUB (type
) = 1;
16031 else if (attr
== NULL
&& die
->child
== NULL
16032 && producer_is_realview (cu
->producer
))
16033 /* RealView does not output the required DW_AT_declaration
16034 on incomplete types. */
16035 TYPE_STUB (type
) = 1;
16037 /* We need to add the type field to the die immediately so we don't
16038 infinitely recurse when dealing with pointers to the structure
16039 type within the structure itself. */
16040 set_die_type (die
, type
, cu
);
16042 /* set_die_type should be already done. */
16043 set_descriptive_type (type
, die
, cu
);
16048 /* A helper for process_structure_scope that handles a single member
16052 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16053 struct field_info
*fi
,
16054 std::vector
<struct symbol
*> *template_args
,
16055 struct dwarf2_cu
*cu
)
16057 if (child_die
->tag
== DW_TAG_member
16058 || child_die
->tag
== DW_TAG_variable
16059 || child_die
->tag
== DW_TAG_variant_part
)
16061 /* NOTE: carlton/2002-11-05: A C++ static data member
16062 should be a DW_TAG_member that is a declaration, but
16063 all versions of G++ as of this writing (so through at
16064 least 3.2.1) incorrectly generate DW_TAG_variable
16065 tags for them instead. */
16066 dwarf2_add_field (fi
, child_die
, cu
);
16068 else if (child_die
->tag
== DW_TAG_subprogram
)
16070 /* Rust doesn't have member functions in the C++ sense.
16071 However, it does emit ordinary functions as children
16072 of a struct DIE. */
16073 if (cu
->language
== language_rust
)
16074 read_func_scope (child_die
, cu
);
16077 /* C++ member function. */
16078 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16081 else if (child_die
->tag
== DW_TAG_inheritance
)
16083 /* C++ base class field. */
16084 dwarf2_add_field (fi
, child_die
, cu
);
16086 else if (type_can_define_types (child_die
))
16087 dwarf2_add_type_defn (fi
, child_die
, cu
);
16088 else if (child_die
->tag
== DW_TAG_template_type_param
16089 || child_die
->tag
== DW_TAG_template_value_param
)
16091 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16094 template_args
->push_back (arg
);
16096 else if (child_die
->tag
== DW_TAG_variant
)
16098 /* In a variant we want to get the discriminant and also add a
16099 field for our sole member child. */
16100 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16102 for (die_info
*variant_child
= child_die
->child
;
16103 variant_child
!= NULL
;
16104 variant_child
= sibling_die (variant_child
))
16106 if (variant_child
->tag
== DW_TAG_member
)
16108 handle_struct_member_die (variant_child
, type
, fi
,
16109 template_args
, cu
);
16110 /* Only handle the one. */
16115 /* We don't handle this but we might as well report it if we see
16117 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16118 complaint (_("DW_AT_discr_list is not supported yet"
16119 " - DIE at %s [in module %s]"),
16120 sect_offset_str (child_die
->sect_off
),
16121 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16123 /* The first field was just added, so we can stash the
16124 discriminant there. */
16125 gdb_assert (!fi
->fields
.empty ());
16127 fi
->fields
.back ().variant
.default_branch
= true;
16129 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16133 /* Finish creating a structure or union type, including filling in
16134 its members and creating a symbol for it. */
16137 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16139 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16140 struct die_info
*child_die
;
16143 type
= get_die_type (die
, cu
);
16145 type
= read_structure_type (die
, cu
);
16147 /* When reading a DW_TAG_variant_part, we need to notice when we
16148 read the discriminant member, so we can record it later in the
16149 discriminant_info. */
16150 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16151 sect_offset discr_offset
{};
16152 bool has_template_parameters
= false;
16154 if (is_variant_part
)
16156 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16159 /* Maybe it's a univariant form, an extension we support.
16160 In this case arrange not to check the offset. */
16161 is_variant_part
= false;
16163 else if (attr_form_is_ref (discr
))
16165 struct dwarf2_cu
*target_cu
= cu
;
16166 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16168 discr_offset
= target_die
->sect_off
;
16172 complaint (_("DW_AT_discr does not have DIE reference form"
16173 " - DIE at %s [in module %s]"),
16174 sect_offset_str (die
->sect_off
),
16175 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16176 is_variant_part
= false;
16180 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16182 struct field_info fi
;
16183 std::vector
<struct symbol
*> template_args
;
16185 child_die
= die
->child
;
16187 while (child_die
&& child_die
->tag
)
16189 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16191 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16192 fi
.fields
.back ().variant
.is_discriminant
= true;
16194 child_die
= sibling_die (child_die
);
16197 /* Attach template arguments to type. */
16198 if (!template_args
.empty ())
16200 has_template_parameters
= true;
16201 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16202 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16203 TYPE_TEMPLATE_ARGUMENTS (type
)
16204 = XOBNEWVEC (&objfile
->objfile_obstack
,
16206 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16207 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16208 template_args
.data (),
16209 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16210 * sizeof (struct symbol
*)));
16213 /* Attach fields and member functions to the type. */
16215 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16216 if (!fi
.fnfieldlists
.empty ())
16218 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16220 /* Get the type which refers to the base class (possibly this
16221 class itself) which contains the vtable pointer for the current
16222 class from the DW_AT_containing_type attribute. This use of
16223 DW_AT_containing_type is a GNU extension. */
16225 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16227 struct type
*t
= die_containing_type (die
, cu
);
16229 set_type_vptr_basetype (type
, t
);
16234 /* Our own class provides vtbl ptr. */
16235 for (i
= TYPE_NFIELDS (t
) - 1;
16236 i
>= TYPE_N_BASECLASSES (t
);
16239 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16241 if (is_vtable_name (fieldname
, cu
))
16243 set_type_vptr_fieldno (type
, i
);
16248 /* Complain if virtual function table field not found. */
16249 if (i
< TYPE_N_BASECLASSES (t
))
16250 complaint (_("virtual function table pointer "
16251 "not found when defining class '%s'"),
16252 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16256 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16259 else if (cu
->producer
16260 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16262 /* The IBM XLC compiler does not provide direct indication
16263 of the containing type, but the vtable pointer is
16264 always named __vfp. */
16268 for (i
= TYPE_NFIELDS (type
) - 1;
16269 i
>= TYPE_N_BASECLASSES (type
);
16272 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16274 set_type_vptr_fieldno (type
, i
);
16275 set_type_vptr_basetype (type
, type
);
16282 /* Copy fi.typedef_field_list linked list elements content into the
16283 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16284 if (!fi
.typedef_field_list
.empty ())
16286 int count
= fi
.typedef_field_list
.size ();
16288 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16289 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16290 = ((struct decl_field
*)
16292 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16293 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16295 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16296 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16299 /* Copy fi.nested_types_list linked list elements content into the
16300 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16301 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16303 int count
= fi
.nested_types_list
.size ();
16305 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16306 TYPE_NESTED_TYPES_ARRAY (type
)
16307 = ((struct decl_field
*)
16308 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16309 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16311 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16312 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16316 quirk_gcc_member_function_pointer (type
, objfile
);
16317 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16318 cu
->rust_unions
.push_back (type
);
16320 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16321 snapshots) has been known to create a die giving a declaration
16322 for a class that has, as a child, a die giving a definition for a
16323 nested class. So we have to process our children even if the
16324 current die is a declaration. Normally, of course, a declaration
16325 won't have any children at all. */
16327 child_die
= die
->child
;
16329 while (child_die
!= NULL
&& child_die
->tag
)
16331 if (child_die
->tag
== DW_TAG_member
16332 || child_die
->tag
== DW_TAG_variable
16333 || child_die
->tag
== DW_TAG_inheritance
16334 || child_die
->tag
== DW_TAG_template_value_param
16335 || child_die
->tag
== DW_TAG_template_type_param
)
16340 process_die (child_die
, cu
);
16342 child_die
= sibling_die (child_die
);
16345 /* Do not consider external references. According to the DWARF standard,
16346 these DIEs are identified by the fact that they have no byte_size
16347 attribute, and a declaration attribute. */
16348 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16349 || !die_is_declaration (die
, cu
))
16351 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16353 if (has_template_parameters
)
16355 struct symtab
*symtab
;
16356 if (sym
!= nullptr)
16357 symtab
= symbol_symtab (sym
);
16358 else if (cu
->line_header
!= nullptr)
16360 /* Any related symtab will do. */
16362 = cu
->line_header
->file_names ()[0].symtab
;
16367 complaint (_("could not find suitable "
16368 "symtab for template parameter"
16369 " - DIE at %s [in module %s]"),
16370 sect_offset_str (die
->sect_off
),
16371 objfile_name (objfile
));
16374 if (symtab
!= nullptr)
16376 /* Make sure that the symtab is set on the new symbols.
16377 Even though they don't appear in this symtab directly,
16378 other parts of gdb assume that symbols do, and this is
16379 reasonably true. */
16380 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16381 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16387 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16388 update TYPE using some information only available in DIE's children. */
16391 update_enumeration_type_from_children (struct die_info
*die
,
16393 struct dwarf2_cu
*cu
)
16395 struct die_info
*child_die
;
16396 int unsigned_enum
= 1;
16400 auto_obstack obstack
;
16402 for (child_die
= die
->child
;
16403 child_die
!= NULL
&& child_die
->tag
;
16404 child_die
= sibling_die (child_die
))
16406 struct attribute
*attr
;
16408 const gdb_byte
*bytes
;
16409 struct dwarf2_locexpr_baton
*baton
;
16412 if (child_die
->tag
!= DW_TAG_enumerator
)
16415 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16419 name
= dwarf2_name (child_die
, cu
);
16421 name
= "<anonymous enumerator>";
16423 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16424 &value
, &bytes
, &baton
);
16430 else if ((mask
& value
) != 0)
16435 /* If we already know that the enum type is neither unsigned, nor
16436 a flag type, no need to look at the rest of the enumerates. */
16437 if (!unsigned_enum
&& !flag_enum
)
16442 TYPE_UNSIGNED (type
) = 1;
16444 TYPE_FLAG_ENUM (type
) = 1;
16447 /* Given a DW_AT_enumeration_type die, set its type. We do not
16448 complete the type's fields yet, or create any symbols. */
16450 static struct type
*
16451 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16453 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16455 struct attribute
*attr
;
16458 /* If the definition of this type lives in .debug_types, read that type.
16459 Don't follow DW_AT_specification though, that will take us back up
16460 the chain and we want to go down. */
16461 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16462 if (attr
!= nullptr)
16464 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16466 /* The type's CU may not be the same as CU.
16467 Ensure TYPE is recorded with CU in die_type_hash. */
16468 return set_die_type (die
, type
, cu
);
16471 type
= alloc_type (objfile
);
16473 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16474 name
= dwarf2_full_name (NULL
, die
, cu
);
16476 TYPE_NAME (type
) = name
;
16478 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16481 struct type
*underlying_type
= die_type (die
, cu
);
16483 TYPE_TARGET_TYPE (type
) = underlying_type
;
16486 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16487 if (attr
!= nullptr)
16489 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16493 TYPE_LENGTH (type
) = 0;
16496 maybe_set_alignment (cu
, die
, type
);
16498 /* The enumeration DIE can be incomplete. In Ada, any type can be
16499 declared as private in the package spec, and then defined only
16500 inside the package body. Such types are known as Taft Amendment
16501 Types. When another package uses such a type, an incomplete DIE
16502 may be generated by the compiler. */
16503 if (die_is_declaration (die
, cu
))
16504 TYPE_STUB (type
) = 1;
16506 /* Finish the creation of this type by using the enum's children.
16507 We must call this even when the underlying type has been provided
16508 so that we can determine if we're looking at a "flag" enum. */
16509 update_enumeration_type_from_children (die
, type
, cu
);
16511 /* If this type has an underlying type that is not a stub, then we
16512 may use its attributes. We always use the "unsigned" attribute
16513 in this situation, because ordinarily we guess whether the type
16514 is unsigned -- but the guess can be wrong and the underlying type
16515 can tell us the reality. However, we defer to a local size
16516 attribute if one exists, because this lets the compiler override
16517 the underlying type if needed. */
16518 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16520 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16521 if (TYPE_LENGTH (type
) == 0)
16522 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16523 if (TYPE_RAW_ALIGN (type
) == 0
16524 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16525 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16528 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16530 return set_die_type (die
, type
, cu
);
16533 /* Given a pointer to a die which begins an enumeration, process all
16534 the dies that define the members of the enumeration, and create the
16535 symbol for the enumeration type.
16537 NOTE: We reverse the order of the element list. */
16540 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16542 struct type
*this_type
;
16544 this_type
= get_die_type (die
, cu
);
16545 if (this_type
== NULL
)
16546 this_type
= read_enumeration_type (die
, cu
);
16548 if (die
->child
!= NULL
)
16550 struct die_info
*child_die
;
16551 struct symbol
*sym
;
16552 struct field
*fields
= NULL
;
16553 int num_fields
= 0;
16556 child_die
= die
->child
;
16557 while (child_die
&& child_die
->tag
)
16559 if (child_die
->tag
!= DW_TAG_enumerator
)
16561 process_die (child_die
, cu
);
16565 name
= dwarf2_name (child_die
, cu
);
16568 sym
= new_symbol (child_die
, this_type
, cu
);
16570 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16572 fields
= (struct field
*)
16574 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16575 * sizeof (struct field
));
16578 FIELD_NAME (fields
[num_fields
]) = sym
->linkage_name ();
16579 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16580 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16581 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16587 child_die
= sibling_die (child_die
);
16592 TYPE_NFIELDS (this_type
) = num_fields
;
16593 TYPE_FIELDS (this_type
) = (struct field
*)
16594 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16595 memcpy (TYPE_FIELDS (this_type
), fields
,
16596 sizeof (struct field
) * num_fields
);
16601 /* If we are reading an enum from a .debug_types unit, and the enum
16602 is a declaration, and the enum is not the signatured type in the
16603 unit, then we do not want to add a symbol for it. Adding a
16604 symbol would in some cases obscure the true definition of the
16605 enum, giving users an incomplete type when the definition is
16606 actually available. Note that we do not want to do this for all
16607 enums which are just declarations, because C++0x allows forward
16608 enum declarations. */
16609 if (cu
->per_cu
->is_debug_types
16610 && die_is_declaration (die
, cu
))
16612 struct signatured_type
*sig_type
;
16614 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16615 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16616 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16620 new_symbol (die
, this_type
, cu
);
16623 /* Extract all information from a DW_TAG_array_type DIE and put it in
16624 the DIE's type field. For now, this only handles one dimensional
16627 static struct type
*
16628 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16630 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16631 struct die_info
*child_die
;
16633 struct type
*element_type
, *range_type
, *index_type
;
16634 struct attribute
*attr
;
16636 struct dynamic_prop
*byte_stride_prop
= NULL
;
16637 unsigned int bit_stride
= 0;
16639 element_type
= die_type (die
, cu
);
16641 /* The die_type call above may have already set the type for this DIE. */
16642 type
= get_die_type (die
, cu
);
16646 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16650 struct type
*prop_type
16651 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16654 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16655 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16659 complaint (_("unable to read array DW_AT_byte_stride "
16660 " - DIE at %s [in module %s]"),
16661 sect_offset_str (die
->sect_off
),
16662 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16663 /* Ignore this attribute. We will likely not be able to print
16664 arrays of this type correctly, but there is little we can do
16665 to help if we cannot read the attribute's value. */
16666 byte_stride_prop
= NULL
;
16670 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16672 bit_stride
= DW_UNSND (attr
);
16674 /* Irix 6.2 native cc creates array types without children for
16675 arrays with unspecified length. */
16676 if (die
->child
== NULL
)
16678 index_type
= objfile_type (objfile
)->builtin_int
;
16679 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16680 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16681 byte_stride_prop
, bit_stride
);
16682 return set_die_type (die
, type
, cu
);
16685 std::vector
<struct type
*> range_types
;
16686 child_die
= die
->child
;
16687 while (child_die
&& child_die
->tag
)
16689 if (child_die
->tag
== DW_TAG_subrange_type
)
16691 struct type
*child_type
= read_type_die (child_die
, cu
);
16693 if (child_type
!= NULL
)
16695 /* The range type was succesfully read. Save it for the
16696 array type creation. */
16697 range_types
.push_back (child_type
);
16700 child_die
= sibling_die (child_die
);
16703 /* Dwarf2 dimensions are output from left to right, create the
16704 necessary array types in backwards order. */
16706 type
= element_type
;
16708 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16712 while (i
< range_types
.size ())
16713 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16714 byte_stride_prop
, bit_stride
);
16718 size_t ndim
= range_types
.size ();
16720 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16721 byte_stride_prop
, bit_stride
);
16724 /* Understand Dwarf2 support for vector types (like they occur on
16725 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16726 array type. This is not part of the Dwarf2/3 standard yet, but a
16727 custom vendor extension. The main difference between a regular
16728 array and the vector variant is that vectors are passed by value
16730 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16731 if (attr
!= nullptr)
16732 make_vector_type (type
);
16734 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16735 implementation may choose to implement triple vectors using this
16737 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16738 if (attr
!= nullptr)
16740 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16741 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16743 complaint (_("DW_AT_byte_size for array type smaller "
16744 "than the total size of elements"));
16747 name
= dwarf2_name (die
, cu
);
16749 TYPE_NAME (type
) = name
;
16751 maybe_set_alignment (cu
, die
, type
);
16753 /* Install the type in the die. */
16754 set_die_type (die
, type
, cu
);
16756 /* set_die_type should be already done. */
16757 set_descriptive_type (type
, die
, cu
);
16762 static enum dwarf_array_dim_ordering
16763 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16765 struct attribute
*attr
;
16767 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16769 if (attr
!= nullptr)
16770 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16772 /* GNU F77 is a special case, as at 08/2004 array type info is the
16773 opposite order to the dwarf2 specification, but data is still
16774 laid out as per normal fortran.
16776 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16777 version checking. */
16779 if (cu
->language
== language_fortran
16780 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16782 return DW_ORD_row_major
;
16785 switch (cu
->language_defn
->la_array_ordering
)
16787 case array_column_major
:
16788 return DW_ORD_col_major
;
16789 case array_row_major
:
16791 return DW_ORD_row_major
;
16795 /* Extract all information from a DW_TAG_set_type DIE and put it in
16796 the DIE's type field. */
16798 static struct type
*
16799 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16801 struct type
*domain_type
, *set_type
;
16802 struct attribute
*attr
;
16804 domain_type
= die_type (die
, cu
);
16806 /* The die_type call above may have already set the type for this DIE. */
16807 set_type
= get_die_type (die
, cu
);
16811 set_type
= create_set_type (NULL
, domain_type
);
16813 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16814 if (attr
!= nullptr)
16815 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16817 maybe_set_alignment (cu
, die
, set_type
);
16819 return set_die_type (die
, set_type
, cu
);
16822 /* A helper for read_common_block that creates a locexpr baton.
16823 SYM is the symbol which we are marking as computed.
16824 COMMON_DIE is the DIE for the common block.
16825 COMMON_LOC is the location expression attribute for the common
16827 MEMBER_LOC is the location expression attribute for the particular
16828 member of the common block that we are processing.
16829 CU is the CU from which the above come. */
16832 mark_common_block_symbol_computed (struct symbol
*sym
,
16833 struct die_info
*common_die
,
16834 struct attribute
*common_loc
,
16835 struct attribute
*member_loc
,
16836 struct dwarf2_cu
*cu
)
16838 struct dwarf2_per_objfile
*dwarf2_per_objfile
16839 = cu
->per_cu
->dwarf2_per_objfile
;
16840 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16841 struct dwarf2_locexpr_baton
*baton
;
16843 unsigned int cu_off
;
16844 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16845 LONGEST offset
= 0;
16847 gdb_assert (common_loc
&& member_loc
);
16848 gdb_assert (attr_form_is_block (common_loc
));
16849 gdb_assert (attr_form_is_block (member_loc
)
16850 || attr_form_is_constant (member_loc
));
16852 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16853 baton
->per_cu
= cu
->per_cu
;
16854 gdb_assert (baton
->per_cu
);
16856 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16858 if (attr_form_is_constant (member_loc
))
16860 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16861 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16864 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16866 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16869 *ptr
++ = DW_OP_call4
;
16870 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16871 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16874 if (attr_form_is_constant (member_loc
))
16876 *ptr
++ = DW_OP_addr
;
16877 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16878 ptr
+= cu
->header
.addr_size
;
16882 /* We have to copy the data here, because DW_OP_call4 will only
16883 use a DW_AT_location attribute. */
16884 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16885 ptr
+= DW_BLOCK (member_loc
)->size
;
16888 *ptr
++ = DW_OP_plus
;
16889 gdb_assert (ptr
- baton
->data
== baton
->size
);
16891 SYMBOL_LOCATION_BATON (sym
) = baton
;
16892 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16895 /* Create appropriate locally-scoped variables for all the
16896 DW_TAG_common_block entries. Also create a struct common_block
16897 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16898 is used to separate the common blocks name namespace from regular
16902 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16904 struct attribute
*attr
;
16906 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16907 if (attr
!= nullptr)
16909 /* Support the .debug_loc offsets. */
16910 if (attr_form_is_block (attr
))
16914 else if (attr_form_is_section_offset (attr
))
16916 dwarf2_complex_location_expr_complaint ();
16921 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16922 "common block member");
16927 if (die
->child
!= NULL
)
16929 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16930 struct die_info
*child_die
;
16931 size_t n_entries
= 0, size
;
16932 struct common_block
*common_block
;
16933 struct symbol
*sym
;
16935 for (child_die
= die
->child
;
16936 child_die
&& child_die
->tag
;
16937 child_die
= sibling_die (child_die
))
16940 size
= (sizeof (struct common_block
)
16941 + (n_entries
- 1) * sizeof (struct symbol
*));
16943 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16945 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16946 common_block
->n_entries
= 0;
16948 for (child_die
= die
->child
;
16949 child_die
&& child_die
->tag
;
16950 child_die
= sibling_die (child_die
))
16952 /* Create the symbol in the DW_TAG_common_block block in the current
16954 sym
= new_symbol (child_die
, NULL
, cu
);
16957 struct attribute
*member_loc
;
16959 common_block
->contents
[common_block
->n_entries
++] = sym
;
16961 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16965 /* GDB has handled this for a long time, but it is
16966 not specified by DWARF. It seems to have been
16967 emitted by gfortran at least as recently as:
16968 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16969 complaint (_("Variable in common block has "
16970 "DW_AT_data_member_location "
16971 "- DIE at %s [in module %s]"),
16972 sect_offset_str (child_die
->sect_off
),
16973 objfile_name (objfile
));
16975 if (attr_form_is_section_offset (member_loc
))
16976 dwarf2_complex_location_expr_complaint ();
16977 else if (attr_form_is_constant (member_loc
)
16978 || attr_form_is_block (member_loc
))
16980 if (attr
!= nullptr)
16981 mark_common_block_symbol_computed (sym
, die
, attr
,
16985 dwarf2_complex_location_expr_complaint ();
16990 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16991 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16995 /* Create a type for a C++ namespace. */
16997 static struct type
*
16998 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17000 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17001 const char *previous_prefix
, *name
;
17005 /* For extensions, reuse the type of the original namespace. */
17006 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17008 struct die_info
*ext_die
;
17009 struct dwarf2_cu
*ext_cu
= cu
;
17011 ext_die
= dwarf2_extension (die
, &ext_cu
);
17012 type
= read_type_die (ext_die
, ext_cu
);
17014 /* EXT_CU may not be the same as CU.
17015 Ensure TYPE is recorded with CU in die_type_hash. */
17016 return set_die_type (die
, type
, cu
);
17019 name
= namespace_name (die
, &is_anonymous
, cu
);
17021 /* Now build the name of the current namespace. */
17023 previous_prefix
= determine_prefix (die
, cu
);
17024 if (previous_prefix
[0] != '\0')
17025 name
= typename_concat (&objfile
->objfile_obstack
,
17026 previous_prefix
, name
, 0, cu
);
17028 /* Create the type. */
17029 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17031 return set_die_type (die
, type
, cu
);
17034 /* Read a namespace scope. */
17037 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17039 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17042 /* Add a symbol associated to this if we haven't seen the namespace
17043 before. Also, add a using directive if it's an anonymous
17046 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17050 type
= read_type_die (die
, cu
);
17051 new_symbol (die
, type
, cu
);
17053 namespace_name (die
, &is_anonymous
, cu
);
17056 const char *previous_prefix
= determine_prefix (die
, cu
);
17058 std::vector
<const char *> excludes
;
17059 add_using_directive (using_directives (cu
),
17060 previous_prefix
, TYPE_NAME (type
), NULL
,
17061 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17065 if (die
->child
!= NULL
)
17067 struct die_info
*child_die
= die
->child
;
17069 while (child_die
&& child_die
->tag
)
17071 process_die (child_die
, cu
);
17072 child_die
= sibling_die (child_die
);
17077 /* Read a Fortran module as type. This DIE can be only a declaration used for
17078 imported module. Still we need that type as local Fortran "use ... only"
17079 declaration imports depend on the created type in determine_prefix. */
17081 static struct type
*
17082 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17084 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17085 const char *module_name
;
17088 module_name
= dwarf2_name (die
, cu
);
17089 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17091 return set_die_type (die
, type
, cu
);
17094 /* Read a Fortran module. */
17097 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17099 struct die_info
*child_die
= die
->child
;
17102 type
= read_type_die (die
, cu
);
17103 new_symbol (die
, type
, cu
);
17105 while (child_die
&& child_die
->tag
)
17107 process_die (child_die
, cu
);
17108 child_die
= sibling_die (child_die
);
17112 /* Return the name of the namespace represented by DIE. Set
17113 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17116 static const char *
17117 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17119 struct die_info
*current_die
;
17120 const char *name
= NULL
;
17122 /* Loop through the extensions until we find a name. */
17124 for (current_die
= die
;
17125 current_die
!= NULL
;
17126 current_die
= dwarf2_extension (die
, &cu
))
17128 /* We don't use dwarf2_name here so that we can detect the absence
17129 of a name -> anonymous namespace. */
17130 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17136 /* Is it an anonymous namespace? */
17138 *is_anonymous
= (name
== NULL
);
17140 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17145 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17146 the user defined type vector. */
17148 static struct type
*
17149 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17151 struct gdbarch
*gdbarch
17152 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17153 struct comp_unit_head
*cu_header
= &cu
->header
;
17155 struct attribute
*attr_byte_size
;
17156 struct attribute
*attr_address_class
;
17157 int byte_size
, addr_class
;
17158 struct type
*target_type
;
17160 target_type
= die_type (die
, cu
);
17162 /* The die_type call above may have already set the type for this DIE. */
17163 type
= get_die_type (die
, cu
);
17167 type
= lookup_pointer_type (target_type
);
17169 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17170 if (attr_byte_size
)
17171 byte_size
= DW_UNSND (attr_byte_size
);
17173 byte_size
= cu_header
->addr_size
;
17175 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17176 if (attr_address_class
)
17177 addr_class
= DW_UNSND (attr_address_class
);
17179 addr_class
= DW_ADDR_none
;
17181 ULONGEST alignment
= get_alignment (cu
, die
);
17183 /* If the pointer size, alignment, or address class is different
17184 than the default, create a type variant marked as such and set
17185 the length accordingly. */
17186 if (TYPE_LENGTH (type
) != byte_size
17187 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17188 && alignment
!= TYPE_RAW_ALIGN (type
))
17189 || addr_class
!= DW_ADDR_none
)
17191 if (gdbarch_address_class_type_flags_p (gdbarch
))
17195 type_flags
= gdbarch_address_class_type_flags
17196 (gdbarch
, byte_size
, addr_class
);
17197 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17199 type
= make_type_with_address_space (type
, type_flags
);
17201 else if (TYPE_LENGTH (type
) != byte_size
)
17203 complaint (_("invalid pointer size %d"), byte_size
);
17205 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17207 complaint (_("Invalid DW_AT_alignment"
17208 " - DIE at %s [in module %s]"),
17209 sect_offset_str (die
->sect_off
),
17210 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17214 /* Should we also complain about unhandled address classes? */
17218 TYPE_LENGTH (type
) = byte_size
;
17219 set_type_align (type
, alignment
);
17220 return set_die_type (die
, type
, cu
);
17223 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17224 the user defined type vector. */
17226 static struct type
*
17227 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17230 struct type
*to_type
;
17231 struct type
*domain
;
17233 to_type
= die_type (die
, cu
);
17234 domain
= die_containing_type (die
, cu
);
17236 /* The calls above may have already set the type for this DIE. */
17237 type
= get_die_type (die
, cu
);
17241 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17242 type
= lookup_methodptr_type (to_type
);
17243 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17245 struct type
*new_type
17246 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17248 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17249 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17250 TYPE_VARARGS (to_type
));
17251 type
= lookup_methodptr_type (new_type
);
17254 type
= lookup_memberptr_type (to_type
, domain
);
17256 return set_die_type (die
, type
, cu
);
17259 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17260 the user defined type vector. */
17262 static struct type
*
17263 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17264 enum type_code refcode
)
17266 struct comp_unit_head
*cu_header
= &cu
->header
;
17267 struct type
*type
, *target_type
;
17268 struct attribute
*attr
;
17270 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17272 target_type
= die_type (die
, cu
);
17274 /* The die_type call above may have already set the type for this DIE. */
17275 type
= get_die_type (die
, cu
);
17279 type
= lookup_reference_type (target_type
, refcode
);
17280 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17281 if (attr
!= nullptr)
17283 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17287 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17289 maybe_set_alignment (cu
, die
, type
);
17290 return set_die_type (die
, type
, cu
);
17293 /* Add the given cv-qualifiers to the element type of the array. GCC
17294 outputs DWARF type qualifiers that apply to an array, not the
17295 element type. But GDB relies on the array element type to carry
17296 the cv-qualifiers. This mimics section 6.7.3 of the C99
17299 static struct type
*
17300 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17301 struct type
*base_type
, int cnst
, int voltl
)
17303 struct type
*el_type
, *inner_array
;
17305 base_type
= copy_type (base_type
);
17306 inner_array
= base_type
;
17308 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17310 TYPE_TARGET_TYPE (inner_array
) =
17311 copy_type (TYPE_TARGET_TYPE (inner_array
));
17312 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17315 el_type
= TYPE_TARGET_TYPE (inner_array
);
17316 cnst
|= TYPE_CONST (el_type
);
17317 voltl
|= TYPE_VOLATILE (el_type
);
17318 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17320 return set_die_type (die
, base_type
, cu
);
17323 static struct type
*
17324 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17326 struct type
*base_type
, *cv_type
;
17328 base_type
= die_type (die
, cu
);
17330 /* The die_type call above may have already set the type for this DIE. */
17331 cv_type
= get_die_type (die
, cu
);
17335 /* In case the const qualifier is applied to an array type, the element type
17336 is so qualified, not the array type (section 6.7.3 of C99). */
17337 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17338 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17340 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17341 return set_die_type (die
, cv_type
, cu
);
17344 static struct type
*
17345 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17347 struct type
*base_type
, *cv_type
;
17349 base_type
= die_type (die
, cu
);
17351 /* The die_type call above may have already set the type for this DIE. */
17352 cv_type
= get_die_type (die
, cu
);
17356 /* In case the volatile qualifier is applied to an array type, the
17357 element type is so qualified, not the array type (section 6.7.3
17359 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17360 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17362 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17363 return set_die_type (die
, cv_type
, cu
);
17366 /* Handle DW_TAG_restrict_type. */
17368 static struct type
*
17369 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17371 struct type
*base_type
, *cv_type
;
17373 base_type
= die_type (die
, cu
);
17375 /* The die_type call above may have already set the type for this DIE. */
17376 cv_type
= get_die_type (die
, cu
);
17380 cv_type
= make_restrict_type (base_type
);
17381 return set_die_type (die
, cv_type
, cu
);
17384 /* Handle DW_TAG_atomic_type. */
17386 static struct type
*
17387 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17389 struct type
*base_type
, *cv_type
;
17391 base_type
= die_type (die
, cu
);
17393 /* The die_type call above may have already set the type for this DIE. */
17394 cv_type
= get_die_type (die
, cu
);
17398 cv_type
= make_atomic_type (base_type
);
17399 return set_die_type (die
, cv_type
, cu
);
17402 /* Extract all information from a DW_TAG_string_type DIE and add to
17403 the user defined type vector. It isn't really a user defined type,
17404 but it behaves like one, with other DIE's using an AT_user_def_type
17405 attribute to reference it. */
17407 static struct type
*
17408 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17410 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17411 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17412 struct type
*type
, *range_type
, *index_type
, *char_type
;
17413 struct attribute
*attr
;
17414 struct dynamic_prop prop
;
17415 bool length_is_constant
= true;
17418 /* There are a couple of places where bit sizes might be made use of
17419 when parsing a DW_TAG_string_type, however, no producer that we know
17420 of make use of these. Handling bit sizes that are a multiple of the
17421 byte size is easy enough, but what about other bit sizes? Lets deal
17422 with that problem when we have to. Warn about these attributes being
17423 unsupported, then parse the type and ignore them like we always
17425 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17426 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17428 static bool warning_printed
= false;
17429 if (!warning_printed
)
17431 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17432 "currently supported on DW_TAG_string_type."));
17433 warning_printed
= true;
17437 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17438 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17440 /* The string length describes the location at which the length of
17441 the string can be found. The size of the length field can be
17442 specified with one of the attributes below. */
17443 struct type
*prop_type
;
17444 struct attribute
*len
17445 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17446 if (len
== nullptr)
17447 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17448 if (len
!= nullptr && attr_form_is_constant (len
))
17450 /* Pass 0 as the default as we know this attribute is constant
17451 and the default value will not be returned. */
17452 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17453 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17457 /* If the size is not specified then we assume it is the size of
17458 an address on this target. */
17459 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17462 /* Convert the attribute into a dynamic property. */
17463 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17466 length_is_constant
= false;
17468 else if (attr
!= nullptr)
17470 /* This DW_AT_string_length just contains the length with no
17471 indirection. There's no need to create a dynamic property in this
17472 case. Pass 0 for the default value as we know it will not be
17473 returned in this case. */
17474 length
= dwarf2_get_attr_constant_value (attr
, 0);
17476 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17478 /* We don't currently support non-constant byte sizes for strings. */
17479 length
= dwarf2_get_attr_constant_value (attr
, 1);
17483 /* Use 1 as a fallback length if we have nothing else. */
17487 index_type
= objfile_type (objfile
)->builtin_int
;
17488 if (length_is_constant
)
17489 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17492 struct dynamic_prop low_bound
;
17494 low_bound
.kind
= PROP_CONST
;
17495 low_bound
.data
.const_val
= 1;
17496 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17498 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17499 type
= create_string_type (NULL
, char_type
, range_type
);
17501 return set_die_type (die
, type
, cu
);
17504 /* Assuming that DIE corresponds to a function, returns nonzero
17505 if the function is prototyped. */
17508 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17510 struct attribute
*attr
;
17512 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17513 if (attr
&& (DW_UNSND (attr
) != 0))
17516 /* The DWARF standard implies that the DW_AT_prototyped attribute
17517 is only meaningful for C, but the concept also extends to other
17518 languages that allow unprototyped functions (Eg: Objective C).
17519 For all other languages, assume that functions are always
17521 if (cu
->language
!= language_c
17522 && cu
->language
!= language_objc
17523 && cu
->language
!= language_opencl
)
17526 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17527 prototyped and unprototyped functions; default to prototyped,
17528 since that is more common in modern code (and RealView warns
17529 about unprototyped functions). */
17530 if (producer_is_realview (cu
->producer
))
17536 /* Handle DIES due to C code like:
17540 int (*funcp)(int a, long l);
17544 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17546 static struct type
*
17547 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17549 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17550 struct type
*type
; /* Type that this function returns. */
17551 struct type
*ftype
; /* Function that returns above type. */
17552 struct attribute
*attr
;
17554 type
= die_type (die
, cu
);
17556 /* The die_type call above may have already set the type for this DIE. */
17557 ftype
= get_die_type (die
, cu
);
17561 ftype
= lookup_function_type (type
);
17563 if (prototyped_function_p (die
, cu
))
17564 TYPE_PROTOTYPED (ftype
) = 1;
17566 /* Store the calling convention in the type if it's available in
17567 the subroutine die. Otherwise set the calling convention to
17568 the default value DW_CC_normal. */
17569 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17570 if (attr
!= nullptr
17571 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17572 TYPE_CALLING_CONVENTION (ftype
)
17573 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17574 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17575 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17577 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17579 /* Record whether the function returns normally to its caller or not
17580 if the DWARF producer set that information. */
17581 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17582 if (attr
&& (DW_UNSND (attr
) != 0))
17583 TYPE_NO_RETURN (ftype
) = 1;
17585 /* We need to add the subroutine type to the die immediately so
17586 we don't infinitely recurse when dealing with parameters
17587 declared as the same subroutine type. */
17588 set_die_type (die
, ftype
, cu
);
17590 if (die
->child
!= NULL
)
17592 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17593 struct die_info
*child_die
;
17594 int nparams
, iparams
;
17596 /* Count the number of parameters.
17597 FIXME: GDB currently ignores vararg functions, but knows about
17598 vararg member functions. */
17600 child_die
= die
->child
;
17601 while (child_die
&& child_die
->tag
)
17603 if (child_die
->tag
== DW_TAG_formal_parameter
)
17605 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17606 TYPE_VARARGS (ftype
) = 1;
17607 child_die
= sibling_die (child_die
);
17610 /* Allocate storage for parameters and fill them in. */
17611 TYPE_NFIELDS (ftype
) = nparams
;
17612 TYPE_FIELDS (ftype
) = (struct field
*)
17613 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17615 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17616 even if we error out during the parameters reading below. */
17617 for (iparams
= 0; iparams
< nparams
; iparams
++)
17618 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17621 child_die
= die
->child
;
17622 while (child_die
&& child_die
->tag
)
17624 if (child_die
->tag
== DW_TAG_formal_parameter
)
17626 struct type
*arg_type
;
17628 /* DWARF version 2 has no clean way to discern C++
17629 static and non-static member functions. G++ helps
17630 GDB by marking the first parameter for non-static
17631 member functions (which is the this pointer) as
17632 artificial. We pass this information to
17633 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17635 DWARF version 3 added DW_AT_object_pointer, which GCC
17636 4.5 does not yet generate. */
17637 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17638 if (attr
!= nullptr)
17639 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17641 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17642 arg_type
= die_type (child_die
, cu
);
17644 /* RealView does not mark THIS as const, which the testsuite
17645 expects. GCC marks THIS as const in method definitions,
17646 but not in the class specifications (GCC PR 43053). */
17647 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17648 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17651 struct dwarf2_cu
*arg_cu
= cu
;
17652 const char *name
= dwarf2_name (child_die
, cu
);
17654 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17655 if (attr
!= nullptr)
17657 /* If the compiler emits this, use it. */
17658 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17661 else if (name
&& strcmp (name
, "this") == 0)
17662 /* Function definitions will have the argument names. */
17664 else if (name
== NULL
&& iparams
== 0)
17665 /* Declarations may not have the names, so like
17666 elsewhere in GDB, assume an artificial first
17667 argument is "this". */
17671 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17675 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17678 child_die
= sibling_die (child_die
);
17685 static struct type
*
17686 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17688 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17689 const char *name
= NULL
;
17690 struct type
*this_type
, *target_type
;
17692 name
= dwarf2_full_name (NULL
, die
, cu
);
17693 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17694 TYPE_TARGET_STUB (this_type
) = 1;
17695 set_die_type (die
, this_type
, cu
);
17696 target_type
= die_type (die
, cu
);
17697 if (target_type
!= this_type
)
17698 TYPE_TARGET_TYPE (this_type
) = target_type
;
17701 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17702 spec and cause infinite loops in GDB. */
17703 complaint (_("Self-referential DW_TAG_typedef "
17704 "- DIE at %s [in module %s]"),
17705 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17706 TYPE_TARGET_TYPE (this_type
) = NULL
;
17711 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17712 (which may be different from NAME) to the architecture back-end to allow
17713 it to guess the correct format if necessary. */
17715 static struct type
*
17716 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17717 const char *name_hint
, enum bfd_endian byte_order
)
17719 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17720 const struct floatformat
**format
;
17723 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17725 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17727 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17732 /* Allocate an integer type of size BITS and name NAME. */
17734 static struct type
*
17735 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17736 int bits
, int unsigned_p
, const char *name
)
17740 /* Versions of Intel's C Compiler generate an integer type called "void"
17741 instead of using DW_TAG_unspecified_type. This has been seen on
17742 at least versions 14, 17, and 18. */
17743 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17744 && strcmp (name
, "void") == 0)
17745 type
= objfile_type (objfile
)->builtin_void
;
17747 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17752 /* Initialise and return a floating point type of size BITS suitable for
17753 use as a component of a complex number. The NAME_HINT is passed through
17754 when initialising the floating point type and is the name of the complex
17757 As DWARF doesn't currently provide an explicit name for the components
17758 of a complex number, but it can be helpful to have these components
17759 named, we try to select a suitable name based on the size of the
17761 static struct type
*
17762 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17763 struct objfile
*objfile
,
17764 int bits
, const char *name_hint
,
17765 enum bfd_endian byte_order
)
17767 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17768 struct type
*tt
= nullptr;
17770 /* Try to find a suitable floating point builtin type of size BITS.
17771 We're going to use the name of this type as the name for the complex
17772 target type that we are about to create. */
17773 switch (cu
->language
)
17775 case language_fortran
:
17779 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17782 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17784 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17786 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17794 tt
= builtin_type (gdbarch
)->builtin_float
;
17797 tt
= builtin_type (gdbarch
)->builtin_double
;
17799 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17801 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17807 /* If the type we found doesn't match the size we were looking for, then
17808 pretend we didn't find a type at all, the complex target type we
17809 create will then be nameless. */
17810 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17813 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17814 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17817 /* Find a representation of a given base type and install
17818 it in the TYPE field of the die. */
17820 static struct type
*
17821 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17823 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17825 struct attribute
*attr
;
17826 int encoding
= 0, bits
= 0;
17830 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17831 if (attr
!= nullptr)
17832 encoding
= DW_UNSND (attr
);
17833 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17834 if (attr
!= nullptr)
17835 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17836 name
= dwarf2_name (die
, cu
);
17838 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17840 arch
= get_objfile_arch (objfile
);
17841 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17843 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17846 int endianity
= DW_UNSND (attr
);
17851 byte_order
= BFD_ENDIAN_BIG
;
17853 case DW_END_little
:
17854 byte_order
= BFD_ENDIAN_LITTLE
;
17857 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17864 case DW_ATE_address
:
17865 /* Turn DW_ATE_address into a void * pointer. */
17866 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17867 type
= init_pointer_type (objfile
, bits
, name
, type
);
17869 case DW_ATE_boolean
:
17870 type
= init_boolean_type (objfile
, bits
, 1, name
);
17872 case DW_ATE_complex_float
:
17873 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17875 type
= init_complex_type (objfile
, name
, type
);
17877 case DW_ATE_decimal_float
:
17878 type
= init_decfloat_type (objfile
, bits
, name
);
17881 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17883 case DW_ATE_signed
:
17884 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17886 case DW_ATE_unsigned
:
17887 if (cu
->language
== language_fortran
17889 && startswith (name
, "character("))
17890 type
= init_character_type (objfile
, bits
, 1, name
);
17892 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17894 case DW_ATE_signed_char
:
17895 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17896 || cu
->language
== language_pascal
17897 || cu
->language
== language_fortran
)
17898 type
= init_character_type (objfile
, bits
, 0, name
);
17900 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17902 case DW_ATE_unsigned_char
:
17903 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17904 || cu
->language
== language_pascal
17905 || cu
->language
== language_fortran
17906 || cu
->language
== language_rust
)
17907 type
= init_character_type (objfile
, bits
, 1, name
);
17909 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17914 type
= builtin_type (arch
)->builtin_char16
;
17915 else if (bits
== 32)
17916 type
= builtin_type (arch
)->builtin_char32
;
17919 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17921 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17923 return set_die_type (die
, type
, cu
);
17928 complaint (_("unsupported DW_AT_encoding: '%s'"),
17929 dwarf_type_encoding_name (encoding
));
17930 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17934 if (name
&& strcmp (name
, "char") == 0)
17935 TYPE_NOSIGN (type
) = 1;
17937 maybe_set_alignment (cu
, die
, type
);
17939 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17941 return set_die_type (die
, type
, cu
);
17944 /* Parse dwarf attribute if it's a block, reference or constant and put the
17945 resulting value of the attribute into struct bound_prop.
17946 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17949 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17950 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17951 struct type
*default_type
)
17953 struct dwarf2_property_baton
*baton
;
17954 struct obstack
*obstack
17955 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17957 gdb_assert (default_type
!= NULL
);
17959 if (attr
== NULL
|| prop
== NULL
)
17962 if (attr_form_is_block (attr
))
17964 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17965 baton
->property_type
= default_type
;
17966 baton
->locexpr
.per_cu
= cu
->per_cu
;
17967 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17968 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17969 switch (attr
->name
)
17971 case DW_AT_string_length
:
17972 baton
->locexpr
.is_reference
= true;
17975 baton
->locexpr
.is_reference
= false;
17978 prop
->data
.baton
= baton
;
17979 prop
->kind
= PROP_LOCEXPR
;
17980 gdb_assert (prop
->data
.baton
!= NULL
);
17982 else if (attr_form_is_ref (attr
))
17984 struct dwarf2_cu
*target_cu
= cu
;
17985 struct die_info
*target_die
;
17986 struct attribute
*target_attr
;
17988 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17989 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17990 if (target_attr
== NULL
)
17991 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17993 if (target_attr
== NULL
)
17996 switch (target_attr
->name
)
17998 case DW_AT_location
:
17999 if (attr_form_is_section_offset (target_attr
))
18001 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18002 baton
->property_type
= die_type (target_die
, target_cu
);
18003 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18004 prop
->data
.baton
= baton
;
18005 prop
->kind
= PROP_LOCLIST
;
18006 gdb_assert (prop
->data
.baton
!= NULL
);
18008 else if (attr_form_is_block (target_attr
))
18010 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18011 baton
->property_type
= die_type (target_die
, target_cu
);
18012 baton
->locexpr
.per_cu
= cu
->per_cu
;
18013 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
18014 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
18015 baton
->locexpr
.is_reference
= true;
18016 prop
->data
.baton
= baton
;
18017 prop
->kind
= PROP_LOCEXPR
;
18018 gdb_assert (prop
->data
.baton
!= NULL
);
18022 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18023 "dynamic property");
18027 case DW_AT_data_member_location
:
18031 if (!handle_data_member_location (target_die
, target_cu
,
18035 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18036 baton
->property_type
= read_type_die (target_die
->parent
,
18038 baton
->offset_info
.offset
= offset
;
18039 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18040 prop
->data
.baton
= baton
;
18041 prop
->kind
= PROP_ADDR_OFFSET
;
18046 else if (attr_form_is_constant (attr
))
18048 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
18049 prop
->kind
= PROP_CONST
;
18053 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18054 dwarf2_name (die
, cu
));
18061 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
18062 UNSIGNED_P controls if the integer is unsigned or not. */
18064 static struct type
*
18065 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
18066 int size_in_bytes
, bool unsigned_p
)
18068 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
18069 struct type
*int_type
;
18071 /* Helper macro to examine the various builtin types. */
18072 #define TRY_TYPE(F) \
18073 int_type = (unsigned_p \
18074 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18075 : objfile_type (objfile)->builtin_ ## F); \
18076 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18083 TRY_TYPE (long_long
);
18087 gdb_assert_not_reached ("unable to find suitable integer type");
18090 /* Find an integer type the same size as the address size given in the
18091 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
18092 is unsigned or not. */
18094 static struct type
*
18095 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
18098 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
18099 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
18102 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18103 present (which is valid) then compute the default type based on the
18104 compilation units address size. */
18106 static struct type
*
18107 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18109 struct type
*index_type
= die_type (die
, cu
);
18111 /* Dwarf-2 specifications explicitly allows to create subrange types
18112 without specifying a base type.
18113 In that case, the base type must be set to the type of
18114 the lower bound, upper bound or count, in that order, if any of these
18115 three attributes references an object that has a type.
18116 If no base type is found, the Dwarf-2 specifications say that
18117 a signed integer type of size equal to the size of an address should
18119 For the following C code: `extern char gdb_int [];'
18120 GCC produces an empty range DIE.
18121 FIXME: muller/2010-05-28: Possible references to object for low bound,
18122 high bound or count are not yet handled by this code. */
18123 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
18124 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18129 /* Read the given DW_AT_subrange DIE. */
18131 static struct type
*
18132 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18134 struct type
*base_type
, *orig_base_type
;
18135 struct type
*range_type
;
18136 struct attribute
*attr
;
18137 struct dynamic_prop low
, high
;
18138 int low_default_is_valid
;
18139 int high_bound_is_count
= 0;
18141 ULONGEST negative_mask
;
18143 orig_base_type
= read_subrange_index_type (die
, cu
);
18145 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18146 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18147 creating the range type, but we use the result of check_typedef
18148 when examining properties of the type. */
18149 base_type
= check_typedef (orig_base_type
);
18151 /* The die_type call above may have already set the type for this DIE. */
18152 range_type
= get_die_type (die
, cu
);
18156 low
.kind
= PROP_CONST
;
18157 high
.kind
= PROP_CONST
;
18158 high
.data
.const_val
= 0;
18160 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18161 omitting DW_AT_lower_bound. */
18162 switch (cu
->language
)
18165 case language_cplus
:
18166 low
.data
.const_val
= 0;
18167 low_default_is_valid
= 1;
18169 case language_fortran
:
18170 low
.data
.const_val
= 1;
18171 low_default_is_valid
= 1;
18174 case language_objc
:
18175 case language_rust
:
18176 low
.data
.const_val
= 0;
18177 low_default_is_valid
= (cu
->header
.version
>= 4);
18181 case language_pascal
:
18182 low
.data
.const_val
= 1;
18183 low_default_is_valid
= (cu
->header
.version
>= 4);
18186 low
.data
.const_val
= 0;
18187 low_default_is_valid
= 0;
18191 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18192 if (attr
!= nullptr)
18193 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18194 else if (!low_default_is_valid
)
18195 complaint (_("Missing DW_AT_lower_bound "
18196 "- DIE at %s [in module %s]"),
18197 sect_offset_str (die
->sect_off
),
18198 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18200 struct attribute
*attr_ub
, *attr_count
;
18201 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18202 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18204 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18205 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18207 /* If bounds are constant do the final calculation here. */
18208 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18209 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18211 high_bound_is_count
= 1;
18215 if (attr_ub
!= NULL
)
18216 complaint (_("Unresolved DW_AT_upper_bound "
18217 "- DIE at %s [in module %s]"),
18218 sect_offset_str (die
->sect_off
),
18219 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18220 if (attr_count
!= NULL
)
18221 complaint (_("Unresolved DW_AT_count "
18222 "- DIE at %s [in module %s]"),
18223 sect_offset_str (die
->sect_off
),
18224 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18229 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18230 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18231 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18233 /* Normally, the DWARF producers are expected to use a signed
18234 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18235 But this is unfortunately not always the case, as witnessed
18236 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18237 is used instead. To work around that ambiguity, we treat
18238 the bounds as signed, and thus sign-extend their values, when
18239 the base type is signed. */
18241 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18242 if (low
.kind
== PROP_CONST
18243 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18244 low
.data
.const_val
|= negative_mask
;
18245 if (high
.kind
== PROP_CONST
18246 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18247 high
.data
.const_val
|= negative_mask
;
18249 /* Check for bit and byte strides. */
18250 struct dynamic_prop byte_stride_prop
;
18251 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18252 if (attr_byte_stride
!= nullptr)
18254 struct type
*prop_type
18255 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18256 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18260 struct dynamic_prop bit_stride_prop
;
18261 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18262 if (attr_bit_stride
!= nullptr)
18264 /* It only makes sense to have either a bit or byte stride. */
18265 if (attr_byte_stride
!= nullptr)
18267 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18268 "- DIE at %s [in module %s]"),
18269 sect_offset_str (die
->sect_off
),
18270 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18271 attr_bit_stride
= nullptr;
18275 struct type
*prop_type
18276 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18277 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18282 if (attr_byte_stride
!= nullptr
18283 || attr_bit_stride
!= nullptr)
18285 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18286 struct dynamic_prop
*stride
18287 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18290 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18291 &high
, bias
, stride
, byte_stride_p
);
18294 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18296 if (high_bound_is_count
)
18297 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18299 /* Ada expects an empty array on no boundary attributes. */
18300 if (attr
== NULL
&& cu
->language
!= language_ada
)
18301 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18303 name
= dwarf2_name (die
, cu
);
18305 TYPE_NAME (range_type
) = name
;
18307 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18308 if (attr
!= nullptr)
18309 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18311 maybe_set_alignment (cu
, die
, range_type
);
18313 set_die_type (die
, range_type
, cu
);
18315 /* set_die_type should be already done. */
18316 set_descriptive_type (range_type
, die
, cu
);
18321 static struct type
*
18322 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18326 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18328 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18330 /* In Ada, an unspecified type is typically used when the description
18331 of the type is deferred to a different unit. When encountering
18332 such a type, we treat it as a stub, and try to resolve it later on,
18334 if (cu
->language
== language_ada
)
18335 TYPE_STUB (type
) = 1;
18337 return set_die_type (die
, type
, cu
);
18340 /* Read a single die and all its descendents. Set the die's sibling
18341 field to NULL; set other fields in the die correctly, and set all
18342 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18343 location of the info_ptr after reading all of those dies. PARENT
18344 is the parent of the die in question. */
18346 static struct die_info
*
18347 read_die_and_children (const struct die_reader_specs
*reader
,
18348 const gdb_byte
*info_ptr
,
18349 const gdb_byte
**new_info_ptr
,
18350 struct die_info
*parent
)
18352 struct die_info
*die
;
18353 const gdb_byte
*cur_ptr
;
18356 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18359 *new_info_ptr
= cur_ptr
;
18362 store_in_ref_table (die
, reader
->cu
);
18365 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18369 *new_info_ptr
= cur_ptr
;
18372 die
->sibling
= NULL
;
18373 die
->parent
= parent
;
18377 /* Read a die, all of its descendents, and all of its siblings; set
18378 all of the fields of all of the dies correctly. Arguments are as
18379 in read_die_and_children. */
18381 static struct die_info
*
18382 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18383 const gdb_byte
*info_ptr
,
18384 const gdb_byte
**new_info_ptr
,
18385 struct die_info
*parent
)
18387 struct die_info
*first_die
, *last_sibling
;
18388 const gdb_byte
*cur_ptr
;
18390 cur_ptr
= info_ptr
;
18391 first_die
= last_sibling
= NULL
;
18395 struct die_info
*die
18396 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18400 *new_info_ptr
= cur_ptr
;
18407 last_sibling
->sibling
= die
;
18409 last_sibling
= die
;
18413 /* Read a die, all of its descendents, and all of its siblings; set
18414 all of the fields of all of the dies correctly. Arguments are as
18415 in read_die_and_children.
18416 This the main entry point for reading a DIE and all its children. */
18418 static struct die_info
*
18419 read_die_and_siblings (const struct die_reader_specs
*reader
,
18420 const gdb_byte
*info_ptr
,
18421 const gdb_byte
**new_info_ptr
,
18422 struct die_info
*parent
)
18424 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18425 new_info_ptr
, parent
);
18427 if (dwarf_die_debug
)
18429 fprintf_unfiltered (gdb_stdlog
,
18430 "Read die from %s@0x%x of %s:\n",
18431 get_section_name (reader
->die_section
),
18432 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18433 bfd_get_filename (reader
->abfd
));
18434 dump_die (die
, dwarf_die_debug
);
18440 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18442 The caller is responsible for filling in the extra attributes
18443 and updating (*DIEP)->num_attrs.
18444 Set DIEP to point to a newly allocated die with its information,
18445 except for its child, sibling, and parent fields.
18446 Set HAS_CHILDREN to tell whether the die has children or not. */
18448 static const gdb_byte
*
18449 read_full_die_1 (const struct die_reader_specs
*reader
,
18450 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18451 int *has_children
, int num_extra_attrs
)
18453 unsigned int abbrev_number
, bytes_read
, i
;
18454 struct abbrev_info
*abbrev
;
18455 struct die_info
*die
;
18456 struct dwarf2_cu
*cu
= reader
->cu
;
18457 bfd
*abfd
= reader
->abfd
;
18459 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18460 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18461 info_ptr
+= bytes_read
;
18462 if (!abbrev_number
)
18469 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18471 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18473 bfd_get_filename (abfd
));
18475 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18476 die
->sect_off
= sect_off
;
18477 die
->tag
= abbrev
->tag
;
18478 die
->abbrev
= abbrev_number
;
18480 /* Make the result usable.
18481 The caller needs to update num_attrs after adding the extra
18483 die
->num_attrs
= abbrev
->num_attrs
;
18485 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18486 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18490 *has_children
= abbrev
->has_children
;
18494 /* Read a die and all its attributes.
18495 Set DIEP to point to a newly allocated die with its information,
18496 except for its child, sibling, and parent fields.
18497 Set HAS_CHILDREN to tell whether the die has children or not. */
18499 static const gdb_byte
*
18500 read_full_die (const struct die_reader_specs
*reader
,
18501 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18504 const gdb_byte
*result
;
18506 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18508 if (dwarf_die_debug
)
18510 fprintf_unfiltered (gdb_stdlog
,
18511 "Read die from %s@0x%x of %s:\n",
18512 get_section_name (reader
->die_section
),
18513 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18514 bfd_get_filename (reader
->abfd
));
18515 dump_die (*diep
, dwarf_die_debug
);
18521 /* Abbreviation tables.
18523 In DWARF version 2, the description of the debugging information is
18524 stored in a separate .debug_abbrev section. Before we read any
18525 dies from a section we read in all abbreviations and install them
18526 in a hash table. */
18528 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18530 struct abbrev_info
*
18531 abbrev_table::alloc_abbrev ()
18533 struct abbrev_info
*abbrev
;
18535 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18536 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18541 /* Add an abbreviation to the table. */
18544 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18545 struct abbrev_info
*abbrev
)
18547 unsigned int hash_number
;
18549 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18550 abbrev
->next
= m_abbrevs
[hash_number
];
18551 m_abbrevs
[hash_number
] = abbrev
;
18554 /* Look up an abbrev in the table.
18555 Returns NULL if the abbrev is not found. */
18557 struct abbrev_info
*
18558 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18560 unsigned int hash_number
;
18561 struct abbrev_info
*abbrev
;
18563 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18564 abbrev
= m_abbrevs
[hash_number
];
18568 if (abbrev
->number
== abbrev_number
)
18570 abbrev
= abbrev
->next
;
18575 /* Read in an abbrev table. */
18577 static abbrev_table_up
18578 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18579 struct dwarf2_section_info
*section
,
18580 sect_offset sect_off
)
18582 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18583 bfd
*abfd
= get_section_bfd_owner (section
);
18584 const gdb_byte
*abbrev_ptr
;
18585 struct abbrev_info
*cur_abbrev
;
18586 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18587 unsigned int abbrev_form
;
18588 struct attr_abbrev
*cur_attrs
;
18589 unsigned int allocated_attrs
;
18591 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18593 dwarf2_read_section (objfile
, section
);
18594 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18595 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18596 abbrev_ptr
+= bytes_read
;
18598 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18599 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18601 /* Loop until we reach an abbrev number of 0. */
18602 while (abbrev_number
)
18604 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18606 /* read in abbrev header */
18607 cur_abbrev
->number
= abbrev_number
;
18609 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18610 abbrev_ptr
+= bytes_read
;
18611 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18614 /* now read in declarations */
18617 LONGEST implicit_const
;
18619 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18620 abbrev_ptr
+= bytes_read
;
18621 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18622 abbrev_ptr
+= bytes_read
;
18623 if (abbrev_form
== DW_FORM_implicit_const
)
18625 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18627 abbrev_ptr
+= bytes_read
;
18631 /* Initialize it due to a false compiler warning. */
18632 implicit_const
= -1;
18635 if (abbrev_name
== 0)
18638 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18640 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18642 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18645 cur_attrs
[cur_abbrev
->num_attrs
].name
18646 = (enum dwarf_attribute
) abbrev_name
;
18647 cur_attrs
[cur_abbrev
->num_attrs
].form
18648 = (enum dwarf_form
) abbrev_form
;
18649 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18650 ++cur_abbrev
->num_attrs
;
18653 cur_abbrev
->attrs
=
18654 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18655 cur_abbrev
->num_attrs
);
18656 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18657 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18659 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18661 /* Get next abbreviation.
18662 Under Irix6 the abbreviations for a compilation unit are not
18663 always properly terminated with an abbrev number of 0.
18664 Exit loop if we encounter an abbreviation which we have
18665 already read (which means we are about to read the abbreviations
18666 for the next compile unit) or if the end of the abbreviation
18667 table is reached. */
18668 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18670 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18671 abbrev_ptr
+= bytes_read
;
18672 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18677 return abbrev_table
;
18680 /* Returns nonzero if TAG represents a type that we might generate a partial
18684 is_type_tag_for_partial (int tag
)
18689 /* Some types that would be reasonable to generate partial symbols for,
18690 that we don't at present. */
18691 case DW_TAG_array_type
:
18692 case DW_TAG_file_type
:
18693 case DW_TAG_ptr_to_member_type
:
18694 case DW_TAG_set_type
:
18695 case DW_TAG_string_type
:
18696 case DW_TAG_subroutine_type
:
18698 case DW_TAG_base_type
:
18699 case DW_TAG_class_type
:
18700 case DW_TAG_interface_type
:
18701 case DW_TAG_enumeration_type
:
18702 case DW_TAG_structure_type
:
18703 case DW_TAG_subrange_type
:
18704 case DW_TAG_typedef
:
18705 case DW_TAG_union_type
:
18712 /* Load all DIEs that are interesting for partial symbols into memory. */
18714 static struct partial_die_info
*
18715 load_partial_dies (const struct die_reader_specs
*reader
,
18716 const gdb_byte
*info_ptr
, int building_psymtab
)
18718 struct dwarf2_cu
*cu
= reader
->cu
;
18719 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18720 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18721 unsigned int bytes_read
;
18722 unsigned int load_all
= 0;
18723 int nesting_level
= 1;
18728 gdb_assert (cu
->per_cu
!= NULL
);
18729 if (cu
->per_cu
->load_all_dies
)
18733 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18737 &cu
->comp_unit_obstack
,
18738 hashtab_obstack_allocate
,
18739 dummy_obstack_deallocate
);
18743 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18745 /* A NULL abbrev means the end of a series of children. */
18746 if (abbrev
== NULL
)
18748 if (--nesting_level
== 0)
18751 info_ptr
+= bytes_read
;
18752 last_die
= parent_die
;
18753 parent_die
= parent_die
->die_parent
;
18757 /* Check for template arguments. We never save these; if
18758 they're seen, we just mark the parent, and go on our way. */
18759 if (parent_die
!= NULL
18760 && cu
->language
== language_cplus
18761 && (abbrev
->tag
== DW_TAG_template_type_param
18762 || abbrev
->tag
== DW_TAG_template_value_param
))
18764 parent_die
->has_template_arguments
= 1;
18768 /* We don't need a partial DIE for the template argument. */
18769 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18774 /* We only recurse into c++ subprograms looking for template arguments.
18775 Skip their other children. */
18777 && cu
->language
== language_cplus
18778 && parent_die
!= NULL
18779 && parent_die
->tag
== DW_TAG_subprogram
)
18781 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18785 /* Check whether this DIE is interesting enough to save. Normally
18786 we would not be interested in members here, but there may be
18787 later variables referencing them via DW_AT_specification (for
18788 static members). */
18790 && !is_type_tag_for_partial (abbrev
->tag
)
18791 && abbrev
->tag
!= DW_TAG_constant
18792 && abbrev
->tag
!= DW_TAG_enumerator
18793 && abbrev
->tag
!= DW_TAG_subprogram
18794 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18795 && abbrev
->tag
!= DW_TAG_lexical_block
18796 && abbrev
->tag
!= DW_TAG_variable
18797 && abbrev
->tag
!= DW_TAG_namespace
18798 && abbrev
->tag
!= DW_TAG_module
18799 && abbrev
->tag
!= DW_TAG_member
18800 && abbrev
->tag
!= DW_TAG_imported_unit
18801 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18803 /* Otherwise we skip to the next sibling, if any. */
18804 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18808 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18811 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18813 /* This two-pass algorithm for processing partial symbols has a
18814 high cost in cache pressure. Thus, handle some simple cases
18815 here which cover the majority of C partial symbols. DIEs
18816 which neither have specification tags in them, nor could have
18817 specification tags elsewhere pointing at them, can simply be
18818 processed and discarded.
18820 This segment is also optional; scan_partial_symbols and
18821 add_partial_symbol will handle these DIEs if we chain
18822 them in normally. When compilers which do not emit large
18823 quantities of duplicate debug information are more common,
18824 this code can probably be removed. */
18826 /* Any complete simple types at the top level (pretty much all
18827 of them, for a language without namespaces), can be processed
18829 if (parent_die
== NULL
18830 && pdi
.has_specification
== 0
18831 && pdi
.is_declaration
== 0
18832 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18833 || pdi
.tag
== DW_TAG_base_type
18834 || pdi
.tag
== DW_TAG_subrange_type
))
18836 if (building_psymtab
&& pdi
.name
!= NULL
)
18837 add_psymbol_to_list (pdi
.name
, false,
18838 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18839 psymbol_placement::STATIC
,
18840 0, cu
->language
, objfile
);
18841 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18845 /* The exception for DW_TAG_typedef with has_children above is
18846 a workaround of GCC PR debug/47510. In the case of this complaint
18847 type_name_or_error will error on such types later.
18849 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18850 it could not find the child DIEs referenced later, this is checked
18851 above. In correct DWARF DW_TAG_typedef should have no children. */
18853 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18854 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18855 "- DIE at %s [in module %s]"),
18856 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18858 /* If we're at the second level, and we're an enumerator, and
18859 our parent has no specification (meaning possibly lives in a
18860 namespace elsewhere), then we can add the partial symbol now
18861 instead of queueing it. */
18862 if (pdi
.tag
== DW_TAG_enumerator
18863 && parent_die
!= NULL
18864 && parent_die
->die_parent
== NULL
18865 && parent_die
->tag
== DW_TAG_enumeration_type
18866 && parent_die
->has_specification
== 0)
18868 if (pdi
.name
== NULL
)
18869 complaint (_("malformed enumerator DIE ignored"));
18870 else if (building_psymtab
)
18871 add_psymbol_to_list (pdi
.name
, false,
18872 VAR_DOMAIN
, LOC_CONST
, -1,
18873 cu
->language
== language_cplus
18874 ? psymbol_placement::GLOBAL
18875 : psymbol_placement::STATIC
,
18876 0, cu
->language
, objfile
);
18878 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18882 struct partial_die_info
*part_die
18883 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18885 /* We'll save this DIE so link it in. */
18886 part_die
->die_parent
= parent_die
;
18887 part_die
->die_sibling
= NULL
;
18888 part_die
->die_child
= NULL
;
18890 if (last_die
&& last_die
== parent_die
)
18891 last_die
->die_child
= part_die
;
18893 last_die
->die_sibling
= part_die
;
18895 last_die
= part_die
;
18897 if (first_die
== NULL
)
18898 first_die
= part_die
;
18900 /* Maybe add the DIE to the hash table. Not all DIEs that we
18901 find interesting need to be in the hash table, because we
18902 also have the parent/sibling/child chains; only those that we
18903 might refer to by offset later during partial symbol reading.
18905 For now this means things that might have be the target of a
18906 DW_AT_specification, DW_AT_abstract_origin, or
18907 DW_AT_extension. DW_AT_extension will refer only to
18908 namespaces; DW_AT_abstract_origin refers to functions (and
18909 many things under the function DIE, but we do not recurse
18910 into function DIEs during partial symbol reading) and
18911 possibly variables as well; DW_AT_specification refers to
18912 declarations. Declarations ought to have the DW_AT_declaration
18913 flag. It happens that GCC forgets to put it in sometimes, but
18914 only for functions, not for types.
18916 Adding more things than necessary to the hash table is harmless
18917 except for the performance cost. Adding too few will result in
18918 wasted time in find_partial_die, when we reread the compilation
18919 unit with load_all_dies set. */
18922 || abbrev
->tag
== DW_TAG_constant
18923 || abbrev
->tag
== DW_TAG_subprogram
18924 || abbrev
->tag
== DW_TAG_variable
18925 || abbrev
->tag
== DW_TAG_namespace
18926 || part_die
->is_declaration
)
18930 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18931 to_underlying (part_die
->sect_off
),
18936 /* For some DIEs we want to follow their children (if any). For C
18937 we have no reason to follow the children of structures; for other
18938 languages we have to, so that we can get at method physnames
18939 to infer fully qualified class names, for DW_AT_specification,
18940 and for C++ template arguments. For C++, we also look one level
18941 inside functions to find template arguments (if the name of the
18942 function does not already contain the template arguments).
18944 For Ada and Fortran, we need to scan the children of subprograms
18945 and lexical blocks as well because these languages allow the
18946 definition of nested entities that could be interesting for the
18947 debugger, such as nested subprograms for instance. */
18948 if (last_die
->has_children
18950 || last_die
->tag
== DW_TAG_namespace
18951 || last_die
->tag
== DW_TAG_module
18952 || last_die
->tag
== DW_TAG_enumeration_type
18953 || (cu
->language
== language_cplus
18954 && last_die
->tag
== DW_TAG_subprogram
18955 && (last_die
->name
== NULL
18956 || strchr (last_die
->name
, '<') == NULL
))
18957 || (cu
->language
!= language_c
18958 && (last_die
->tag
== DW_TAG_class_type
18959 || last_die
->tag
== DW_TAG_interface_type
18960 || last_die
->tag
== DW_TAG_structure_type
18961 || last_die
->tag
== DW_TAG_union_type
))
18962 || ((cu
->language
== language_ada
18963 || cu
->language
== language_fortran
)
18964 && (last_die
->tag
== DW_TAG_subprogram
18965 || last_die
->tag
== DW_TAG_lexical_block
))))
18968 parent_die
= last_die
;
18972 /* Otherwise we skip to the next sibling, if any. */
18973 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18975 /* Back to the top, do it again. */
18979 partial_die_info::partial_die_info (sect_offset sect_off_
,
18980 struct abbrev_info
*abbrev
)
18981 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18985 /* Read a minimal amount of information into the minimal die structure.
18986 INFO_PTR should point just after the initial uleb128 of a DIE. */
18989 partial_die_info::read (const struct die_reader_specs
*reader
,
18990 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18992 struct dwarf2_cu
*cu
= reader
->cu
;
18993 struct dwarf2_per_objfile
*dwarf2_per_objfile
18994 = cu
->per_cu
->dwarf2_per_objfile
;
18996 int has_low_pc_attr
= 0;
18997 int has_high_pc_attr
= 0;
18998 int high_pc_relative
= 0;
19000 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19002 struct attribute attr
;
19004 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19006 /* Store the data if it is of an attribute we want to keep in a
19007 partial symbol table. */
19013 case DW_TAG_compile_unit
:
19014 case DW_TAG_partial_unit
:
19015 case DW_TAG_type_unit
:
19016 /* Compilation units have a DW_AT_name that is a filename, not
19017 a source language identifier. */
19018 case DW_TAG_enumeration_type
:
19019 case DW_TAG_enumerator
:
19020 /* These tags always have simple identifiers already; no need
19021 to canonicalize them. */
19022 name
= DW_STRING (&attr
);
19026 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19029 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
19030 &objfile
->per_bfd
->storage_obstack
);
19035 case DW_AT_linkage_name
:
19036 case DW_AT_MIPS_linkage_name
:
19037 /* Note that both forms of linkage name might appear. We
19038 assume they will be the same, and we only store the last
19040 linkage_name
= DW_STRING (&attr
);
19043 has_low_pc_attr
= 1;
19044 lowpc
= attr_value_as_address (&attr
);
19046 case DW_AT_high_pc
:
19047 has_high_pc_attr
= 1;
19048 highpc
= attr_value_as_address (&attr
);
19049 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
19050 high_pc_relative
= 1;
19052 case DW_AT_location
:
19053 /* Support the .debug_loc offsets. */
19054 if (attr_form_is_block (&attr
))
19056 d
.locdesc
= DW_BLOCK (&attr
);
19058 else if (attr_form_is_section_offset (&attr
))
19060 dwarf2_complex_location_expr_complaint ();
19064 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19065 "partial symbol information");
19068 case DW_AT_external
:
19069 is_external
= DW_UNSND (&attr
);
19071 case DW_AT_declaration
:
19072 is_declaration
= DW_UNSND (&attr
);
19077 case DW_AT_abstract_origin
:
19078 case DW_AT_specification
:
19079 case DW_AT_extension
:
19080 has_specification
= 1;
19081 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
19082 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19083 || cu
->per_cu
->is_dwz
);
19085 case DW_AT_sibling
:
19086 /* Ignore absolute siblings, they might point outside of
19087 the current compile unit. */
19088 if (attr
.form
== DW_FORM_ref_addr
)
19089 complaint (_("ignoring absolute DW_AT_sibling"));
19092 const gdb_byte
*buffer
= reader
->buffer
;
19093 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
19094 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19096 if (sibling_ptr
< info_ptr
)
19097 complaint (_("DW_AT_sibling points backwards"));
19098 else if (sibling_ptr
> reader
->buffer_end
)
19099 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19101 sibling
= sibling_ptr
;
19104 case DW_AT_byte_size
:
19107 case DW_AT_const_value
:
19108 has_const_value
= 1;
19110 case DW_AT_calling_convention
:
19111 /* DWARF doesn't provide a way to identify a program's source-level
19112 entry point. DW_AT_calling_convention attributes are only meant
19113 to describe functions' calling conventions.
19115 However, because it's a necessary piece of information in
19116 Fortran, and before DWARF 4 DW_CC_program was the only
19117 piece of debugging information whose definition refers to
19118 a 'main program' at all, several compilers marked Fortran
19119 main programs with DW_CC_program --- even when those
19120 functions use the standard calling conventions.
19122 Although DWARF now specifies a way to provide this
19123 information, we support this practice for backward
19125 if (DW_UNSND (&attr
) == DW_CC_program
19126 && cu
->language
== language_fortran
)
19127 main_subprogram
= 1;
19130 if (DW_UNSND (&attr
) == DW_INL_inlined
19131 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19132 may_be_inlined
= 1;
19136 if (tag
== DW_TAG_imported_unit
)
19138 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19139 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19140 || cu
->per_cu
->is_dwz
);
19144 case DW_AT_main_subprogram
:
19145 main_subprogram
= DW_UNSND (&attr
);
19150 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19151 but that requires a full DIE, so instead we just
19153 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
19154 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19155 + (need_ranges_base
19159 /* Value of the DW_AT_ranges attribute is the offset in the
19160 .debug_ranges section. */
19161 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19172 /* For Ada, if both the name and the linkage name appear, we prefer
19173 the latter. This lets "catch exception" work better, regardless
19174 of the order in which the name and linkage name were emitted.
19175 Really, though, this is just a workaround for the fact that gdb
19176 doesn't store both the name and the linkage name. */
19177 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19178 name
= linkage_name
;
19180 if (high_pc_relative
)
19183 if (has_low_pc_attr
&& has_high_pc_attr
)
19185 /* When using the GNU linker, .gnu.linkonce. sections are used to
19186 eliminate duplicate copies of functions and vtables and such.
19187 The linker will arbitrarily choose one and discard the others.
19188 The AT_*_pc values for such functions refer to local labels in
19189 these sections. If the section from that file was discarded, the
19190 labels are not in the output, so the relocs get a value of 0.
19191 If this is a discarded function, mark the pc bounds as invalid,
19192 so that GDB will ignore it. */
19193 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19195 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19196 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19198 complaint (_("DW_AT_low_pc %s is zero "
19199 "for DIE at %s [in module %s]"),
19200 paddress (gdbarch
, lowpc
),
19201 sect_offset_str (sect_off
),
19202 objfile_name (objfile
));
19204 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19205 else if (lowpc
>= highpc
)
19207 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19208 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19210 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19211 "for DIE at %s [in module %s]"),
19212 paddress (gdbarch
, lowpc
),
19213 paddress (gdbarch
, highpc
),
19214 sect_offset_str (sect_off
),
19215 objfile_name (objfile
));
19224 /* Find a cached partial DIE at OFFSET in CU. */
19226 struct partial_die_info
*
19227 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19229 struct partial_die_info
*lookup_die
= NULL
;
19230 struct partial_die_info
part_die (sect_off
);
19232 lookup_die
= ((struct partial_die_info
*)
19233 htab_find_with_hash (partial_dies
, &part_die
,
19234 to_underlying (sect_off
)));
19239 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19240 except in the case of .debug_types DIEs which do not reference
19241 outside their CU (they do however referencing other types via
19242 DW_FORM_ref_sig8). */
19244 static const struct cu_partial_die_info
19245 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19247 struct dwarf2_per_objfile
*dwarf2_per_objfile
19248 = cu
->per_cu
->dwarf2_per_objfile
;
19249 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19250 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19251 struct partial_die_info
*pd
= NULL
;
19253 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19254 && offset_in_cu_p (&cu
->header
, sect_off
))
19256 pd
= cu
->find_partial_die (sect_off
);
19259 /* We missed recording what we needed.
19260 Load all dies and try again. */
19261 per_cu
= cu
->per_cu
;
19265 /* TUs don't reference other CUs/TUs (except via type signatures). */
19266 if (cu
->per_cu
->is_debug_types
)
19268 error (_("Dwarf Error: Type Unit at offset %s contains"
19269 " external reference to offset %s [in module %s].\n"),
19270 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19271 bfd_get_filename (objfile
->obfd
));
19273 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19274 dwarf2_per_objfile
);
19276 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19277 load_partial_comp_unit (per_cu
);
19279 per_cu
->cu
->last_used
= 0;
19280 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19283 /* If we didn't find it, and not all dies have been loaded,
19284 load them all and try again. */
19286 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19288 per_cu
->load_all_dies
= 1;
19290 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19291 THIS_CU->cu may already be in use. So we can't just free it and
19292 replace its DIEs with the ones we read in. Instead, we leave those
19293 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19294 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19296 load_partial_comp_unit (per_cu
);
19298 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19302 internal_error (__FILE__
, __LINE__
,
19303 _("could not find partial DIE %s "
19304 "in cache [from module %s]\n"),
19305 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19306 return { per_cu
->cu
, pd
};
19309 /* See if we can figure out if the class lives in a namespace. We do
19310 this by looking for a member function; its demangled name will
19311 contain namespace info, if there is any. */
19314 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19315 struct dwarf2_cu
*cu
)
19317 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19318 what template types look like, because the demangler
19319 frequently doesn't give the same name as the debug info. We
19320 could fix this by only using the demangled name to get the
19321 prefix (but see comment in read_structure_type). */
19323 struct partial_die_info
*real_pdi
;
19324 struct partial_die_info
*child_pdi
;
19326 /* If this DIE (this DIE's specification, if any) has a parent, then
19327 we should not do this. We'll prepend the parent's fully qualified
19328 name when we create the partial symbol. */
19330 real_pdi
= struct_pdi
;
19331 while (real_pdi
->has_specification
)
19333 auto res
= find_partial_die (real_pdi
->spec_offset
,
19334 real_pdi
->spec_is_dwz
, cu
);
19335 real_pdi
= res
.pdi
;
19339 if (real_pdi
->die_parent
!= NULL
)
19342 for (child_pdi
= struct_pdi
->die_child
;
19344 child_pdi
= child_pdi
->die_sibling
)
19346 if (child_pdi
->tag
== DW_TAG_subprogram
19347 && child_pdi
->linkage_name
!= NULL
)
19349 char *actual_class_name
19350 = language_class_name_from_physname (cu
->language_defn
,
19351 child_pdi
->linkage_name
);
19352 if (actual_class_name
!= NULL
)
19354 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19356 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19357 actual_class_name
);
19358 xfree (actual_class_name
);
19366 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19368 /* Once we've fixed up a die, there's no point in doing so again.
19369 This also avoids a memory leak if we were to call
19370 guess_partial_die_structure_name multiple times. */
19374 /* If we found a reference attribute and the DIE has no name, try
19375 to find a name in the referred to DIE. */
19377 if (name
== NULL
&& has_specification
)
19379 struct partial_die_info
*spec_die
;
19381 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19382 spec_die
= res
.pdi
;
19385 spec_die
->fixup (cu
);
19387 if (spec_die
->name
)
19389 name
= spec_die
->name
;
19391 /* Copy DW_AT_external attribute if it is set. */
19392 if (spec_die
->is_external
)
19393 is_external
= spec_die
->is_external
;
19397 /* Set default names for some unnamed DIEs. */
19399 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19400 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19402 /* If there is no parent die to provide a namespace, and there are
19403 children, see if we can determine the namespace from their linkage
19405 if (cu
->language
== language_cplus
19406 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19407 && die_parent
== NULL
19409 && (tag
== DW_TAG_class_type
19410 || tag
== DW_TAG_structure_type
19411 || tag
== DW_TAG_union_type
))
19412 guess_partial_die_structure_name (this, cu
);
19414 /* GCC might emit a nameless struct or union that has a linkage
19415 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19417 && (tag
== DW_TAG_class_type
19418 || tag
== DW_TAG_interface_type
19419 || tag
== DW_TAG_structure_type
19420 || tag
== DW_TAG_union_type
)
19421 && linkage_name
!= NULL
)
19425 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19430 /* Strip any leading namespaces/classes, keep only the base name.
19431 DW_AT_name for named DIEs does not contain the prefixes. */
19432 base
= strrchr (demangled
, ':');
19433 if (base
&& base
> demangled
&& base
[-1] == ':')
19438 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19439 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19447 /* Read an attribute value described by an attribute form. */
19449 static const gdb_byte
*
19450 read_attribute_value (const struct die_reader_specs
*reader
,
19451 struct attribute
*attr
, unsigned form
,
19452 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19454 struct dwarf2_cu
*cu
= reader
->cu
;
19455 struct dwarf2_per_objfile
*dwarf2_per_objfile
19456 = cu
->per_cu
->dwarf2_per_objfile
;
19457 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19458 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19459 bfd
*abfd
= reader
->abfd
;
19460 struct comp_unit_head
*cu_header
= &cu
->header
;
19461 unsigned int bytes_read
;
19462 struct dwarf_block
*blk
;
19464 attr
->form
= (enum dwarf_form
) form
;
19467 case DW_FORM_ref_addr
:
19468 if (cu
->header
.version
== 2)
19469 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19471 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19472 &cu
->header
, &bytes_read
);
19473 info_ptr
+= bytes_read
;
19475 case DW_FORM_GNU_ref_alt
:
19476 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19477 info_ptr
+= bytes_read
;
19480 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19481 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19482 info_ptr
+= bytes_read
;
19484 case DW_FORM_block2
:
19485 blk
= dwarf_alloc_block (cu
);
19486 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19488 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19489 info_ptr
+= blk
->size
;
19490 DW_BLOCK (attr
) = blk
;
19492 case DW_FORM_block4
:
19493 blk
= dwarf_alloc_block (cu
);
19494 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19496 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19497 info_ptr
+= blk
->size
;
19498 DW_BLOCK (attr
) = blk
;
19500 case DW_FORM_data2
:
19501 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19504 case DW_FORM_data4
:
19505 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19508 case DW_FORM_data8
:
19509 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19512 case DW_FORM_data16
:
19513 blk
= dwarf_alloc_block (cu
);
19515 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19517 DW_BLOCK (attr
) = blk
;
19519 case DW_FORM_sec_offset
:
19520 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19521 info_ptr
+= bytes_read
;
19523 case DW_FORM_string
:
19524 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19525 DW_STRING_IS_CANONICAL (attr
) = 0;
19526 info_ptr
+= bytes_read
;
19529 if (!cu
->per_cu
->is_dwz
)
19531 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19532 abfd
, info_ptr
, cu_header
,
19534 DW_STRING_IS_CANONICAL (attr
) = 0;
19535 info_ptr
+= bytes_read
;
19539 case DW_FORM_line_strp
:
19540 if (!cu
->per_cu
->is_dwz
)
19542 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19544 cu_header
, &bytes_read
);
19545 DW_STRING_IS_CANONICAL (attr
) = 0;
19546 info_ptr
+= bytes_read
;
19550 case DW_FORM_GNU_strp_alt
:
19552 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19553 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19556 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19558 DW_STRING_IS_CANONICAL (attr
) = 0;
19559 info_ptr
+= bytes_read
;
19562 case DW_FORM_exprloc
:
19563 case DW_FORM_block
:
19564 blk
= dwarf_alloc_block (cu
);
19565 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19566 info_ptr
+= bytes_read
;
19567 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19568 info_ptr
+= blk
->size
;
19569 DW_BLOCK (attr
) = blk
;
19571 case DW_FORM_block1
:
19572 blk
= dwarf_alloc_block (cu
);
19573 blk
->size
= read_1_byte (abfd
, info_ptr
);
19575 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19576 info_ptr
+= blk
->size
;
19577 DW_BLOCK (attr
) = blk
;
19579 case DW_FORM_data1
:
19580 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19584 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19587 case DW_FORM_flag_present
:
19588 DW_UNSND (attr
) = 1;
19590 case DW_FORM_sdata
:
19591 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19592 info_ptr
+= bytes_read
;
19594 case DW_FORM_udata
:
19595 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19596 info_ptr
+= bytes_read
;
19599 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19600 + read_1_byte (abfd
, info_ptr
));
19604 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19605 + read_2_bytes (abfd
, info_ptr
));
19609 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19610 + read_4_bytes (abfd
, info_ptr
));
19614 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19615 + read_8_bytes (abfd
, info_ptr
));
19618 case DW_FORM_ref_sig8
:
19619 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19622 case DW_FORM_ref_udata
:
19623 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19624 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19625 info_ptr
+= bytes_read
;
19627 case DW_FORM_indirect
:
19628 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19629 info_ptr
+= bytes_read
;
19630 if (form
== DW_FORM_implicit_const
)
19632 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19633 info_ptr
+= bytes_read
;
19635 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19638 case DW_FORM_implicit_const
:
19639 DW_SND (attr
) = implicit_const
;
19641 case DW_FORM_addrx
:
19642 case DW_FORM_GNU_addr_index
:
19643 if (reader
->dwo_file
== NULL
)
19645 /* For now flag a hard error.
19646 Later we can turn this into a complaint. */
19647 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19648 dwarf_form_name (form
),
19649 bfd_get_filename (abfd
));
19651 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19652 info_ptr
+= bytes_read
;
19655 case DW_FORM_strx1
:
19656 case DW_FORM_strx2
:
19657 case DW_FORM_strx3
:
19658 case DW_FORM_strx4
:
19659 case DW_FORM_GNU_str_index
:
19660 if (reader
->dwo_file
== NULL
)
19662 /* For now flag a hard error.
19663 Later we can turn this into a complaint if warranted. */
19664 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19665 dwarf_form_name (form
),
19666 bfd_get_filename (abfd
));
19669 ULONGEST str_index
;
19670 if (form
== DW_FORM_strx1
)
19672 str_index
= read_1_byte (abfd
, info_ptr
);
19675 else if (form
== DW_FORM_strx2
)
19677 str_index
= read_2_bytes (abfd
, info_ptr
);
19680 else if (form
== DW_FORM_strx3
)
19682 str_index
= read_3_bytes (abfd
, info_ptr
);
19685 else if (form
== DW_FORM_strx4
)
19687 str_index
= read_4_bytes (abfd
, info_ptr
);
19692 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19693 info_ptr
+= bytes_read
;
19695 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19696 DW_STRING_IS_CANONICAL (attr
) = 0;
19700 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19701 dwarf_form_name (form
),
19702 bfd_get_filename (abfd
));
19706 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19707 attr
->form
= DW_FORM_GNU_ref_alt
;
19709 /* We have seen instances where the compiler tried to emit a byte
19710 size attribute of -1 which ended up being encoded as an unsigned
19711 0xffffffff. Although 0xffffffff is technically a valid size value,
19712 an object of this size seems pretty unlikely so we can relatively
19713 safely treat these cases as if the size attribute was invalid and
19714 treat them as zero by default. */
19715 if (attr
->name
== DW_AT_byte_size
19716 && form
== DW_FORM_data4
19717 && DW_UNSND (attr
) >= 0xffffffff)
19720 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19721 hex_string (DW_UNSND (attr
)));
19722 DW_UNSND (attr
) = 0;
19728 /* Read an attribute described by an abbreviated attribute. */
19730 static const gdb_byte
*
19731 read_attribute (const struct die_reader_specs
*reader
,
19732 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19733 const gdb_byte
*info_ptr
)
19735 attr
->name
= abbrev
->name
;
19736 return read_attribute_value (reader
, attr
, abbrev
->form
,
19737 abbrev
->implicit_const
, info_ptr
);
19740 /* Read dwarf information from a buffer. */
19742 static unsigned int
19743 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19745 return bfd_get_8 (abfd
, buf
);
19749 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19751 return bfd_get_signed_8 (abfd
, buf
);
19754 static unsigned int
19755 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19757 return bfd_get_16 (abfd
, buf
);
19761 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19763 return bfd_get_signed_16 (abfd
, buf
);
19766 static unsigned int
19767 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19769 unsigned int result
= 0;
19770 for (int i
= 0; i
< 3; ++i
)
19772 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19774 result
|= ((unsigned int) byte
<< (i
* 8));
19779 static unsigned int
19780 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19782 return bfd_get_32 (abfd
, buf
);
19786 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19788 return bfd_get_signed_32 (abfd
, buf
);
19792 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19794 return bfd_get_64 (abfd
, buf
);
19798 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19799 unsigned int *bytes_read
)
19801 struct comp_unit_head
*cu_header
= &cu
->header
;
19802 CORE_ADDR retval
= 0;
19804 if (cu_header
->signed_addr_p
)
19806 switch (cu_header
->addr_size
)
19809 retval
= bfd_get_signed_16 (abfd
, buf
);
19812 retval
= bfd_get_signed_32 (abfd
, buf
);
19815 retval
= bfd_get_signed_64 (abfd
, buf
);
19818 internal_error (__FILE__
, __LINE__
,
19819 _("read_address: bad switch, signed [in module %s]"),
19820 bfd_get_filename (abfd
));
19825 switch (cu_header
->addr_size
)
19828 retval
= bfd_get_16 (abfd
, buf
);
19831 retval
= bfd_get_32 (abfd
, buf
);
19834 retval
= bfd_get_64 (abfd
, buf
);
19837 internal_error (__FILE__
, __LINE__
,
19838 _("read_address: bad switch, "
19839 "unsigned [in module %s]"),
19840 bfd_get_filename (abfd
));
19844 *bytes_read
= cu_header
->addr_size
;
19848 /* Read the initial length from a section. The (draft) DWARF 3
19849 specification allows the initial length to take up either 4 bytes
19850 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19851 bytes describe the length and all offsets will be 8 bytes in length
19854 An older, non-standard 64-bit format is also handled by this
19855 function. The older format in question stores the initial length
19856 as an 8-byte quantity without an escape value. Lengths greater
19857 than 2^32 aren't very common which means that the initial 4 bytes
19858 is almost always zero. Since a length value of zero doesn't make
19859 sense for the 32-bit format, this initial zero can be considered to
19860 be an escape value which indicates the presence of the older 64-bit
19861 format. As written, the code can't detect (old format) lengths
19862 greater than 4GB. If it becomes necessary to handle lengths
19863 somewhat larger than 4GB, we could allow other small values (such
19864 as the non-sensical values of 1, 2, and 3) to also be used as
19865 escape values indicating the presence of the old format.
19867 The value returned via bytes_read should be used to increment the
19868 relevant pointer after calling read_initial_length().
19870 [ Note: read_initial_length() and read_offset() are based on the
19871 document entitled "DWARF Debugging Information Format", revision
19872 3, draft 8, dated November 19, 2001. This document was obtained
19875 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19877 This document is only a draft and is subject to change. (So beware.)
19879 Details regarding the older, non-standard 64-bit format were
19880 determined empirically by examining 64-bit ELF files produced by
19881 the SGI toolchain on an IRIX 6.5 machine.
19883 - Kevin, July 16, 2002
19887 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19889 LONGEST length
= bfd_get_32 (abfd
, buf
);
19891 if (length
== 0xffffffff)
19893 length
= bfd_get_64 (abfd
, buf
+ 4);
19896 else if (length
== 0)
19898 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19899 length
= bfd_get_64 (abfd
, buf
);
19910 /* Cover function for read_initial_length.
19911 Returns the length of the object at BUF, and stores the size of the
19912 initial length in *BYTES_READ and stores the size that offsets will be in
19914 If the initial length size is not equivalent to that specified in
19915 CU_HEADER then issue a complaint.
19916 This is useful when reading non-comp-unit headers. */
19919 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19920 const struct comp_unit_head
*cu_header
,
19921 unsigned int *bytes_read
,
19922 unsigned int *offset_size
)
19924 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19926 gdb_assert (cu_header
->initial_length_size
== 4
19927 || cu_header
->initial_length_size
== 8
19928 || cu_header
->initial_length_size
== 12);
19930 if (cu_header
->initial_length_size
!= *bytes_read
)
19931 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19933 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19937 /* Read an offset from the data stream. The size of the offset is
19938 given by cu_header->offset_size. */
19941 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19942 const struct comp_unit_head
*cu_header
,
19943 unsigned int *bytes_read
)
19945 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19947 *bytes_read
= cu_header
->offset_size
;
19951 /* Read an offset from the data stream. */
19954 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19956 LONGEST retval
= 0;
19958 switch (offset_size
)
19961 retval
= bfd_get_32 (abfd
, buf
);
19964 retval
= bfd_get_64 (abfd
, buf
);
19967 internal_error (__FILE__
, __LINE__
,
19968 _("read_offset_1: bad switch [in module %s]"),
19969 bfd_get_filename (abfd
));
19975 static const gdb_byte
*
19976 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19978 /* If the size of a host char is 8 bits, we can return a pointer
19979 to the buffer, otherwise we have to copy the data to a buffer
19980 allocated on the temporary obstack. */
19981 gdb_assert (HOST_CHAR_BIT
== 8);
19985 static const char *
19986 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19987 unsigned int *bytes_read_ptr
)
19989 /* If the size of a host char is 8 bits, we can return a pointer
19990 to the string, otherwise we have to copy the string to a buffer
19991 allocated on the temporary obstack. */
19992 gdb_assert (HOST_CHAR_BIT
== 8);
19995 *bytes_read_ptr
= 1;
19998 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19999 return (const char *) buf
;
20002 /* Return pointer to string at section SECT offset STR_OFFSET with error
20003 reporting strings FORM_NAME and SECT_NAME. */
20005 static const char *
20006 read_indirect_string_at_offset_from (struct objfile
*objfile
,
20007 bfd
*abfd
, LONGEST str_offset
,
20008 struct dwarf2_section_info
*sect
,
20009 const char *form_name
,
20010 const char *sect_name
)
20012 dwarf2_read_section (objfile
, sect
);
20013 if (sect
->buffer
== NULL
)
20014 error (_("%s used without %s section [in module %s]"),
20015 form_name
, sect_name
, bfd_get_filename (abfd
));
20016 if (str_offset
>= sect
->size
)
20017 error (_("%s pointing outside of %s section [in module %s]"),
20018 form_name
, sect_name
, bfd_get_filename (abfd
));
20019 gdb_assert (HOST_CHAR_BIT
== 8);
20020 if (sect
->buffer
[str_offset
] == '\0')
20022 return (const char *) (sect
->buffer
+ str_offset
);
20025 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20027 static const char *
20028 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20029 bfd
*abfd
, LONGEST str_offset
)
20031 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
20033 &dwarf2_per_objfile
->str
,
20034 "DW_FORM_strp", ".debug_str");
20037 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
20039 static const char *
20040 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20041 bfd
*abfd
, LONGEST str_offset
)
20043 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
20045 &dwarf2_per_objfile
->line_str
,
20046 "DW_FORM_line_strp",
20047 ".debug_line_str");
20050 /* Read a string at offset STR_OFFSET in the .debug_str section from
20051 the .dwz file DWZ. Throw an error if the offset is too large. If
20052 the string consists of a single NUL byte, return NULL; otherwise
20053 return a pointer to the string. */
20055 static const char *
20056 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
20057 LONGEST str_offset
)
20059 dwarf2_read_section (objfile
, &dwz
->str
);
20061 if (dwz
->str
.buffer
== NULL
)
20062 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
20063 "section [in module %s]"),
20064 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20065 if (str_offset
>= dwz
->str
.size
)
20066 error (_("DW_FORM_GNU_strp_alt pointing outside of "
20067 ".debug_str section [in module %s]"),
20068 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20069 gdb_assert (HOST_CHAR_BIT
== 8);
20070 if (dwz
->str
.buffer
[str_offset
] == '\0')
20072 return (const char *) (dwz
->str
.buffer
+ str_offset
);
20075 /* Return pointer to string at .debug_str offset as read from BUF.
20076 BUF is assumed to be in a compilation unit described by CU_HEADER.
20077 Return *BYTES_READ_PTR count of bytes read from BUF. */
20079 static const char *
20080 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
20081 const gdb_byte
*buf
,
20082 const struct comp_unit_head
*cu_header
,
20083 unsigned int *bytes_read_ptr
)
20085 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20087 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
20090 /* Return pointer to string at .debug_line_str offset as read from BUF.
20091 BUF is assumed to be in a compilation unit described by CU_HEADER.
20092 Return *BYTES_READ_PTR count of bytes read from BUF. */
20094 static const char *
20095 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20096 bfd
*abfd
, const gdb_byte
*buf
,
20097 const struct comp_unit_head
*cu_header
,
20098 unsigned int *bytes_read_ptr
)
20100 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20102 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
20107 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20108 unsigned int *bytes_read_ptr
)
20111 unsigned int num_read
;
20113 unsigned char byte
;
20120 byte
= bfd_get_8 (abfd
, buf
);
20123 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20124 if ((byte
& 128) == 0)
20130 *bytes_read_ptr
= num_read
;
20135 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20136 unsigned int *bytes_read_ptr
)
20139 int shift
, num_read
;
20140 unsigned char byte
;
20147 byte
= bfd_get_8 (abfd
, buf
);
20150 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20152 if ((byte
& 128) == 0)
20157 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
20158 result
|= -(((ULONGEST
) 1) << shift
);
20159 *bytes_read_ptr
= num_read
;
20163 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20164 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
20165 ADDR_SIZE is the size of addresses from the CU header. */
20168 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20169 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
20171 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20172 bfd
*abfd
= objfile
->obfd
;
20173 const gdb_byte
*info_ptr
;
20175 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20176 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20177 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20178 objfile_name (objfile
));
20179 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
20180 error (_("DW_FORM_addr_index pointing outside of "
20181 ".debug_addr section [in module %s]"),
20182 objfile_name (objfile
));
20183 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20184 + addr_base
+ addr_index
* addr_size
);
20185 if (addr_size
== 4)
20186 return bfd_get_32 (abfd
, info_ptr
);
20188 return bfd_get_64 (abfd
, info_ptr
);
20191 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20194 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20196 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20197 cu
->addr_base
, cu
->header
.addr_size
);
20200 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20203 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20204 unsigned int *bytes_read
)
20206 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20207 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20209 return read_addr_index (cu
, addr_index
);
20212 /* Data structure to pass results from dwarf2_read_addr_index_reader
20213 back to dwarf2_read_addr_index. */
20215 struct dwarf2_read_addr_index_data
20217 ULONGEST addr_base
;
20221 /* die_reader_func for dwarf2_read_addr_index. */
20224 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
20225 const gdb_byte
*info_ptr
,
20226 struct die_info
*comp_unit_die
,
20230 struct dwarf2_cu
*cu
= reader
->cu
;
20231 struct dwarf2_read_addr_index_data
*aidata
=
20232 (struct dwarf2_read_addr_index_data
*) data
;
20234 aidata
->addr_base
= cu
->addr_base
;
20235 aidata
->addr_size
= cu
->header
.addr_size
;
20238 /* Given an index in .debug_addr, fetch the value.
20239 NOTE: This can be called during dwarf expression evaluation,
20240 long after the debug information has been read, and thus per_cu->cu
20241 may no longer exist. */
20244 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20245 unsigned int addr_index
)
20247 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20248 struct dwarf2_cu
*cu
= per_cu
->cu
;
20249 ULONGEST addr_base
;
20252 /* We need addr_base and addr_size.
20253 If we don't have PER_CU->cu, we have to get it.
20254 Nasty, but the alternative is storing the needed info in PER_CU,
20255 which at this point doesn't seem justified: it's not clear how frequently
20256 it would get used and it would increase the size of every PER_CU.
20257 Entry points like dwarf2_per_cu_addr_size do a similar thing
20258 so we're not in uncharted territory here.
20259 Alas we need to be a bit more complicated as addr_base is contained
20262 We don't need to read the entire CU(/TU).
20263 We just need the header and top level die.
20265 IWBN to use the aging mechanism to let us lazily later discard the CU.
20266 For now we skip this optimization. */
20270 addr_base
= cu
->addr_base
;
20271 addr_size
= cu
->header
.addr_size
;
20275 struct dwarf2_read_addr_index_data aidata
;
20277 /* Note: We can't use init_cutu_and_read_dies_simple here,
20278 we need addr_base. */
20279 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
20280 dwarf2_read_addr_index_reader
, &aidata
);
20281 addr_base
= aidata
.addr_base
;
20282 addr_size
= aidata
.addr_size
;
20285 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20289 /* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
20290 This is only used by the Fission support. */
20292 static const char *
20293 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20295 struct dwarf2_cu
*cu
= reader
->cu
;
20296 struct dwarf2_per_objfile
*dwarf2_per_objfile
20297 = cu
->per_cu
->dwarf2_per_objfile
;
20298 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20299 const char *objf_name
= objfile_name (objfile
);
20300 bfd
*abfd
= objfile
->obfd
;
20301 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20302 struct dwarf2_section_info
*str_offsets_section
=
20303 &reader
->dwo_file
->sections
.str_offsets
;
20304 const gdb_byte
*info_ptr
;
20305 ULONGEST str_offset
;
20306 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20308 dwarf2_read_section (objfile
, str_section
);
20309 dwarf2_read_section (objfile
, str_offsets_section
);
20310 if (str_section
->buffer
== NULL
)
20311 error (_("%s used without .debug_str.dwo section"
20312 " in CU at offset %s [in module %s]"),
20313 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20314 if (str_offsets_section
->buffer
== NULL
)
20315 error (_("%s used without .debug_str_offsets.dwo section"
20316 " in CU at offset %s [in module %s]"),
20317 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20318 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20319 error (_("%s pointing outside of .debug_str_offsets.dwo"
20320 " section in CU at offset %s [in module %s]"),
20321 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20322 info_ptr
= (str_offsets_section
->buffer
20323 + str_index
* cu
->header
.offset_size
);
20324 if (cu
->header
.offset_size
== 4)
20325 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20327 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20328 if (str_offset
>= str_section
->size
)
20329 error (_("Offset from %s pointing outside of"
20330 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20331 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20332 return (const char *) (str_section
->buffer
+ str_offset
);
20335 /* Return the length of an LEB128 number in BUF. */
20338 leb128_size (const gdb_byte
*buf
)
20340 const gdb_byte
*begin
= buf
;
20346 if ((byte
& 128) == 0)
20347 return buf
- begin
;
20352 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20361 cu
->language
= language_c
;
20364 case DW_LANG_C_plus_plus
:
20365 case DW_LANG_C_plus_plus_11
:
20366 case DW_LANG_C_plus_plus_14
:
20367 cu
->language
= language_cplus
;
20370 cu
->language
= language_d
;
20372 case DW_LANG_Fortran77
:
20373 case DW_LANG_Fortran90
:
20374 case DW_LANG_Fortran95
:
20375 case DW_LANG_Fortran03
:
20376 case DW_LANG_Fortran08
:
20377 cu
->language
= language_fortran
;
20380 cu
->language
= language_go
;
20382 case DW_LANG_Mips_Assembler
:
20383 cu
->language
= language_asm
;
20385 case DW_LANG_Ada83
:
20386 case DW_LANG_Ada95
:
20387 cu
->language
= language_ada
;
20389 case DW_LANG_Modula2
:
20390 cu
->language
= language_m2
;
20392 case DW_LANG_Pascal83
:
20393 cu
->language
= language_pascal
;
20396 cu
->language
= language_objc
;
20399 case DW_LANG_Rust_old
:
20400 cu
->language
= language_rust
;
20402 case DW_LANG_Cobol74
:
20403 case DW_LANG_Cobol85
:
20405 cu
->language
= language_minimal
;
20408 cu
->language_defn
= language_def (cu
->language
);
20411 /* Return the named attribute or NULL if not there. */
20413 static struct attribute
*
20414 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20419 struct attribute
*spec
= NULL
;
20421 for (i
= 0; i
< die
->num_attrs
; ++i
)
20423 if (die
->attrs
[i
].name
== name
)
20424 return &die
->attrs
[i
];
20425 if (die
->attrs
[i
].name
== DW_AT_specification
20426 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20427 spec
= &die
->attrs
[i
];
20433 die
= follow_die_ref (die
, spec
, &cu
);
20439 /* Return the named attribute or NULL if not there,
20440 but do not follow DW_AT_specification, etc.
20441 This is for use in contexts where we're reading .debug_types dies.
20442 Following DW_AT_specification, DW_AT_abstract_origin will take us
20443 back up the chain, and we want to go down. */
20445 static struct attribute
*
20446 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20450 for (i
= 0; i
< die
->num_attrs
; ++i
)
20451 if (die
->attrs
[i
].name
== name
)
20452 return &die
->attrs
[i
];
20457 /* Return the string associated with a string-typed attribute, or NULL if it
20458 is either not found or is of an incorrect type. */
20460 static const char *
20461 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20463 struct attribute
*attr
;
20464 const char *str
= NULL
;
20466 attr
= dwarf2_attr (die
, name
, cu
);
20470 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20471 || attr
->form
== DW_FORM_string
20472 || attr
->form
== DW_FORM_strx
20473 || attr
->form
== DW_FORM_strx1
20474 || attr
->form
== DW_FORM_strx2
20475 || attr
->form
== DW_FORM_strx3
20476 || attr
->form
== DW_FORM_strx4
20477 || attr
->form
== DW_FORM_GNU_str_index
20478 || attr
->form
== DW_FORM_GNU_strp_alt
)
20479 str
= DW_STRING (attr
);
20481 complaint (_("string type expected for attribute %s for "
20482 "DIE at %s in module %s"),
20483 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20484 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20490 /* Return the dwo name or NULL if not present. If present, it is in either
20491 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20492 static const char *
20493 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20495 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20496 if (dwo_name
== nullptr)
20497 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20501 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20502 and holds a non-zero value. This function should only be used for
20503 DW_FORM_flag or DW_FORM_flag_present attributes. */
20506 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20508 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20510 return (attr
&& DW_UNSND (attr
));
20514 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20516 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20517 which value is non-zero. However, we have to be careful with
20518 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20519 (via dwarf2_flag_true_p) follows this attribute. So we may
20520 end up accidently finding a declaration attribute that belongs
20521 to a different DIE referenced by the specification attribute,
20522 even though the given DIE does not have a declaration attribute. */
20523 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20524 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20527 /* Return the die giving the specification for DIE, if there is
20528 one. *SPEC_CU is the CU containing DIE on input, and the CU
20529 containing the return value on output. If there is no
20530 specification, but there is an abstract origin, that is
20533 static struct die_info
*
20534 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20536 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20539 if (spec_attr
== NULL
)
20540 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20542 if (spec_attr
== NULL
)
20545 return follow_die_ref (die
, spec_attr
, spec_cu
);
20548 /* Stub for free_line_header to match void * callback types. */
20551 free_line_header_voidp (void *arg
)
20553 struct line_header
*lh
= (struct line_header
*) arg
;
20559 line_header::add_include_dir (const char *include_dir
)
20561 if (dwarf_line_debug
>= 2)
20565 new_size
= m_include_dirs
.size ();
20567 new_size
= m_include_dirs
.size () + 1;
20568 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20569 new_size
, include_dir
);
20571 m_include_dirs
.push_back (include_dir
);
20575 line_header::add_file_name (const char *name
,
20577 unsigned int mod_time
,
20578 unsigned int length
)
20580 if (dwarf_line_debug
>= 2)
20584 new_size
= file_names_size ();
20586 new_size
= file_names_size () + 1;
20587 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20590 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20593 /* A convenience function to find the proper .debug_line section for a CU. */
20595 static struct dwarf2_section_info
*
20596 get_debug_line_section (struct dwarf2_cu
*cu
)
20598 struct dwarf2_section_info
*section
;
20599 struct dwarf2_per_objfile
*dwarf2_per_objfile
20600 = cu
->per_cu
->dwarf2_per_objfile
;
20602 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20604 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20605 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20606 else if (cu
->per_cu
->is_dwz
)
20608 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20610 section
= &dwz
->line
;
20613 section
= &dwarf2_per_objfile
->line
;
20618 /* Read directory or file name entry format, starting with byte of
20619 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20620 entries count and the entries themselves in the described entry
20624 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20625 bfd
*abfd
, const gdb_byte
**bufp
,
20626 struct line_header
*lh
,
20627 const struct comp_unit_head
*cu_header
,
20628 void (*callback
) (struct line_header
*lh
,
20631 unsigned int mod_time
,
20632 unsigned int length
))
20634 gdb_byte format_count
, formati
;
20635 ULONGEST data_count
, datai
;
20636 const gdb_byte
*buf
= *bufp
;
20637 const gdb_byte
*format_header_data
;
20638 unsigned int bytes_read
;
20640 format_count
= read_1_byte (abfd
, buf
);
20642 format_header_data
= buf
;
20643 for (formati
= 0; formati
< format_count
; formati
++)
20645 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20647 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20651 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20653 for (datai
= 0; datai
< data_count
; datai
++)
20655 const gdb_byte
*format
= format_header_data
;
20656 struct file_entry fe
;
20658 for (formati
= 0; formati
< format_count
; formati
++)
20660 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20661 format
+= bytes_read
;
20663 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20664 format
+= bytes_read
;
20666 gdb::optional
<const char *> string
;
20667 gdb::optional
<unsigned int> uint
;
20671 case DW_FORM_string
:
20672 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20676 case DW_FORM_line_strp
:
20677 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20684 case DW_FORM_data1
:
20685 uint
.emplace (read_1_byte (abfd
, buf
));
20689 case DW_FORM_data2
:
20690 uint
.emplace (read_2_bytes (abfd
, buf
));
20694 case DW_FORM_data4
:
20695 uint
.emplace (read_4_bytes (abfd
, buf
));
20699 case DW_FORM_data8
:
20700 uint
.emplace (read_8_bytes (abfd
, buf
));
20704 case DW_FORM_data16
:
20705 /* This is used for MD5, but file_entry does not record MD5s. */
20709 case DW_FORM_udata
:
20710 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20714 case DW_FORM_block
:
20715 /* It is valid only for DW_LNCT_timestamp which is ignored by
20720 switch (content_type
)
20723 if (string
.has_value ())
20726 case DW_LNCT_directory_index
:
20727 if (uint
.has_value ())
20728 fe
.d_index
= (dir_index
) *uint
;
20730 case DW_LNCT_timestamp
:
20731 if (uint
.has_value ())
20732 fe
.mod_time
= *uint
;
20735 if (uint
.has_value ())
20741 complaint (_("Unknown format content type %s"),
20742 pulongest (content_type
));
20746 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20752 /* Read the statement program header starting at OFFSET in
20753 .debug_line, or .debug_line.dwo. Return a pointer
20754 to a struct line_header, allocated using xmalloc.
20755 Returns NULL if there is a problem reading the header, e.g., if it
20756 has a version we don't understand.
20758 NOTE: the strings in the include directory and file name tables of
20759 the returned object point into the dwarf line section buffer,
20760 and must not be freed. */
20762 static line_header_up
20763 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20765 const gdb_byte
*line_ptr
;
20766 unsigned int bytes_read
, offset_size
;
20768 const char *cur_dir
, *cur_file
;
20769 struct dwarf2_section_info
*section
;
20771 struct dwarf2_per_objfile
*dwarf2_per_objfile
20772 = cu
->per_cu
->dwarf2_per_objfile
;
20774 section
= get_debug_line_section (cu
);
20775 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20776 if (section
->buffer
== NULL
)
20778 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20779 complaint (_("missing .debug_line.dwo section"));
20781 complaint (_("missing .debug_line section"));
20785 /* We can't do this until we know the section is non-empty.
20786 Only then do we know we have such a section. */
20787 abfd
= get_section_bfd_owner (section
);
20789 /* Make sure that at least there's room for the total_length field.
20790 That could be 12 bytes long, but we're just going to fudge that. */
20791 if (to_underlying (sect_off
) + 4 >= section
->size
)
20793 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20797 line_header_up
lh (new line_header ());
20799 lh
->sect_off
= sect_off
;
20800 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20802 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20804 /* Read in the header. */
20806 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20807 &bytes_read
, &offset_size
);
20808 line_ptr
+= bytes_read
;
20810 const gdb_byte
*start_here
= line_ptr
;
20812 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20814 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20817 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20818 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20820 if (lh
->version
> 5)
20822 /* This is a version we don't understand. The format could have
20823 changed in ways we don't handle properly so just punt. */
20824 complaint (_("unsupported version in .debug_line section"));
20827 if (lh
->version
>= 5)
20829 gdb_byte segment_selector_size
;
20831 /* Skip address size. */
20832 read_1_byte (abfd
, line_ptr
);
20835 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20837 if (segment_selector_size
!= 0)
20839 complaint (_("unsupported segment selector size %u "
20840 "in .debug_line section"),
20841 segment_selector_size
);
20845 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20846 line_ptr
+= offset_size
;
20847 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20848 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20850 if (lh
->version
>= 4)
20852 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20856 lh
->maximum_ops_per_instruction
= 1;
20858 if (lh
->maximum_ops_per_instruction
== 0)
20860 lh
->maximum_ops_per_instruction
= 1;
20861 complaint (_("invalid maximum_ops_per_instruction "
20862 "in `.debug_line' section"));
20865 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20867 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20869 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20871 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20873 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20875 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20876 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20878 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20882 if (lh
->version
>= 5)
20884 /* Read directory table. */
20885 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20887 [] (struct line_header
*header
, const char *name
,
20888 dir_index d_index
, unsigned int mod_time
,
20889 unsigned int length
)
20891 header
->add_include_dir (name
);
20894 /* Read file name table. */
20895 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20897 [] (struct line_header
*header
, const char *name
,
20898 dir_index d_index
, unsigned int mod_time
,
20899 unsigned int length
)
20901 header
->add_file_name (name
, d_index
, mod_time
, length
);
20906 /* Read directory table. */
20907 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20909 line_ptr
+= bytes_read
;
20910 lh
->add_include_dir (cur_dir
);
20912 line_ptr
+= bytes_read
;
20914 /* Read file name table. */
20915 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20917 unsigned int mod_time
, length
;
20920 line_ptr
+= bytes_read
;
20921 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20922 line_ptr
+= bytes_read
;
20923 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20924 line_ptr
+= bytes_read
;
20925 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20926 line_ptr
+= bytes_read
;
20928 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20930 line_ptr
+= bytes_read
;
20933 if (line_ptr
> (section
->buffer
+ section
->size
))
20934 complaint (_("line number info header doesn't "
20935 "fit in `.debug_line' section"));
20940 /* Subroutine of dwarf_decode_lines to simplify it.
20941 Return the file name of the psymtab for the given file_entry.
20942 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20943 If space for the result is malloc'd, *NAME_HOLDER will be set.
20944 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20946 static const char *
20947 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20948 const struct partial_symtab
*pst
,
20949 const char *comp_dir
,
20950 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20952 const char *include_name
= fe
.name
;
20953 const char *include_name_to_compare
= include_name
;
20954 const char *pst_filename
;
20957 const char *dir_name
= fe
.include_dir (lh
);
20959 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20960 if (!IS_ABSOLUTE_PATH (include_name
)
20961 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20963 /* Avoid creating a duplicate psymtab for PST.
20964 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20965 Before we do the comparison, however, we need to account
20966 for DIR_NAME and COMP_DIR.
20967 First prepend dir_name (if non-NULL). If we still don't
20968 have an absolute path prepend comp_dir (if non-NULL).
20969 However, the directory we record in the include-file's
20970 psymtab does not contain COMP_DIR (to match the
20971 corresponding symtab(s)).
20976 bash$ gcc -g ./hello.c
20977 include_name = "hello.c"
20979 DW_AT_comp_dir = comp_dir = "/tmp"
20980 DW_AT_name = "./hello.c"
20984 if (dir_name
!= NULL
)
20986 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20987 include_name
, (char *) NULL
));
20988 include_name
= name_holder
->get ();
20989 include_name_to_compare
= include_name
;
20991 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20993 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20994 include_name
, (char *) NULL
));
20995 include_name_to_compare
= hold_compare
.get ();
20999 pst_filename
= pst
->filename
;
21000 gdb::unique_xmalloc_ptr
<char> copied_name
;
21001 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
21003 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
21004 pst_filename
, (char *) NULL
));
21005 pst_filename
= copied_name
.get ();
21008 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
21012 return include_name
;
21015 /* State machine to track the state of the line number program. */
21017 class lnp_state_machine
21020 /* Initialize a machine state for the start of a line number
21022 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21023 bool record_lines_p
);
21025 file_entry
*current_file ()
21027 /* lh->file_names is 0-based, but the file name numbers in the
21028 statement program are 1-based. */
21029 return m_line_header
->file_name_at (m_file
);
21032 /* Record the line in the state machine. END_SEQUENCE is true if
21033 we're processing the end of a sequence. */
21034 void record_line (bool end_sequence
);
21036 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
21037 nop-out rest of the lines in this sequence. */
21038 void check_line_address (struct dwarf2_cu
*cu
,
21039 const gdb_byte
*line_ptr
,
21040 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21042 void handle_set_discriminator (unsigned int discriminator
)
21044 m_discriminator
= discriminator
;
21045 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21048 /* Handle DW_LNE_set_address. */
21049 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21052 address
+= baseaddr
;
21053 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21056 /* Handle DW_LNS_advance_pc. */
21057 void handle_advance_pc (CORE_ADDR adjust
);
21059 /* Handle a special opcode. */
21060 void handle_special_opcode (unsigned char op_code
);
21062 /* Handle DW_LNS_advance_line. */
21063 void handle_advance_line (int line_delta
)
21065 advance_line (line_delta
);
21068 /* Handle DW_LNS_set_file. */
21069 void handle_set_file (file_name_index file
);
21071 /* Handle DW_LNS_negate_stmt. */
21072 void handle_negate_stmt ()
21074 m_is_stmt
= !m_is_stmt
;
21077 /* Handle DW_LNS_const_add_pc. */
21078 void handle_const_add_pc ();
21080 /* Handle DW_LNS_fixed_advance_pc. */
21081 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21083 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21087 /* Handle DW_LNS_copy. */
21088 void handle_copy ()
21090 record_line (false);
21091 m_discriminator
= 0;
21094 /* Handle DW_LNE_end_sequence. */
21095 void handle_end_sequence ()
21097 m_currently_recording_lines
= true;
21101 /* Advance the line by LINE_DELTA. */
21102 void advance_line (int line_delta
)
21104 m_line
+= line_delta
;
21106 if (line_delta
!= 0)
21107 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21110 struct dwarf2_cu
*m_cu
;
21112 gdbarch
*m_gdbarch
;
21114 /* True if we're recording lines.
21115 Otherwise we're building partial symtabs and are just interested in
21116 finding include files mentioned by the line number program. */
21117 bool m_record_lines_p
;
21119 /* The line number header. */
21120 line_header
*m_line_header
;
21122 /* These are part of the standard DWARF line number state machine,
21123 and initialized according to the DWARF spec. */
21125 unsigned char m_op_index
= 0;
21126 /* The line table index of the current file. */
21127 file_name_index m_file
= 1;
21128 unsigned int m_line
= 1;
21130 /* These are initialized in the constructor. */
21132 CORE_ADDR m_address
;
21134 unsigned int m_discriminator
;
21136 /* Additional bits of state we need to track. */
21138 /* The last file that we called dwarf2_start_subfile for.
21139 This is only used for TLLs. */
21140 unsigned int m_last_file
= 0;
21141 /* The last file a line number was recorded for. */
21142 struct subfile
*m_last_subfile
= NULL
;
21144 /* When true, record the lines we decode. */
21145 bool m_currently_recording_lines
= false;
21147 /* The last line number that was recorded, used to coalesce
21148 consecutive entries for the same line. This can happen, for
21149 example, when discriminators are present. PR 17276. */
21150 unsigned int m_last_line
= 0;
21151 bool m_line_has_non_zero_discriminator
= false;
21155 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21157 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21158 / m_line_header
->maximum_ops_per_instruction
)
21159 * m_line_header
->minimum_instruction_length
);
21160 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21161 m_op_index
= ((m_op_index
+ adjust
)
21162 % m_line_header
->maximum_ops_per_instruction
);
21166 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21168 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21169 CORE_ADDR addr_adj
= (((m_op_index
21170 + (adj_opcode
/ m_line_header
->line_range
))
21171 / m_line_header
->maximum_ops_per_instruction
)
21172 * m_line_header
->minimum_instruction_length
);
21173 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21174 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
21175 % m_line_header
->maximum_ops_per_instruction
);
21177 int line_delta
= (m_line_header
->line_base
21178 + (adj_opcode
% m_line_header
->line_range
));
21179 advance_line (line_delta
);
21180 record_line (false);
21181 m_discriminator
= 0;
21185 lnp_state_machine::handle_set_file (file_name_index file
)
21189 const file_entry
*fe
= current_file ();
21191 dwarf2_debug_line_missing_file_complaint ();
21192 else if (m_record_lines_p
)
21194 const char *dir
= fe
->include_dir (m_line_header
);
21196 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21197 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21198 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21203 lnp_state_machine::handle_const_add_pc ()
21206 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21209 = (((m_op_index
+ adjust
)
21210 / m_line_header
->maximum_ops_per_instruction
)
21211 * m_line_header
->minimum_instruction_length
);
21213 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21214 m_op_index
= ((m_op_index
+ adjust
)
21215 % m_line_header
->maximum_ops_per_instruction
);
21218 /* Return non-zero if we should add LINE to the line number table.
21219 LINE is the line to add, LAST_LINE is the last line that was added,
21220 LAST_SUBFILE is the subfile for LAST_LINE.
21221 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21222 had a non-zero discriminator.
21224 We have to be careful in the presence of discriminators.
21225 E.g., for this line:
21227 for (i = 0; i < 100000; i++);
21229 clang can emit four line number entries for that one line,
21230 each with a different discriminator.
21231 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21233 However, we want gdb to coalesce all four entries into one.
21234 Otherwise the user could stepi into the middle of the line and
21235 gdb would get confused about whether the pc really was in the
21236 middle of the line.
21238 Things are further complicated by the fact that two consecutive
21239 line number entries for the same line is a heuristic used by gcc
21240 to denote the end of the prologue. So we can't just discard duplicate
21241 entries, we have to be selective about it. The heuristic we use is
21242 that we only collapse consecutive entries for the same line if at least
21243 one of those entries has a non-zero discriminator. PR 17276.
21245 Note: Addresses in the line number state machine can never go backwards
21246 within one sequence, thus this coalescing is ok. */
21249 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21250 unsigned int line
, unsigned int last_line
,
21251 int line_has_non_zero_discriminator
,
21252 struct subfile
*last_subfile
)
21254 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21256 if (line
!= last_line
)
21258 /* Same line for the same file that we've seen already.
21259 As a last check, for pr 17276, only record the line if the line
21260 has never had a non-zero discriminator. */
21261 if (!line_has_non_zero_discriminator
)
21266 /* Use the CU's builder to record line number LINE beginning at
21267 address ADDRESS in the line table of subfile SUBFILE. */
21270 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21271 unsigned int line
, CORE_ADDR address
,
21272 struct dwarf2_cu
*cu
)
21274 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21276 if (dwarf_line_debug
)
21278 fprintf_unfiltered (gdb_stdlog
,
21279 "Recording line %u, file %s, address %s\n",
21280 line
, lbasename (subfile
->name
),
21281 paddress (gdbarch
, address
));
21285 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21288 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21289 Mark the end of a set of line number records.
21290 The arguments are the same as for dwarf_record_line_1.
21291 If SUBFILE is NULL the request is ignored. */
21294 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21295 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21297 if (subfile
== NULL
)
21300 if (dwarf_line_debug
)
21302 fprintf_unfiltered (gdb_stdlog
,
21303 "Finishing current line, file %s, address %s\n",
21304 lbasename (subfile
->name
),
21305 paddress (gdbarch
, address
));
21308 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21312 lnp_state_machine::record_line (bool end_sequence
)
21314 if (dwarf_line_debug
)
21316 fprintf_unfiltered (gdb_stdlog
,
21317 "Processing actual line %u: file %u,"
21318 " address %s, is_stmt %u, discrim %u\n",
21320 paddress (m_gdbarch
, m_address
),
21321 m_is_stmt
, m_discriminator
);
21324 file_entry
*fe
= current_file ();
21327 dwarf2_debug_line_missing_file_complaint ();
21328 /* For now we ignore lines not starting on an instruction boundary.
21329 But not when processing end_sequence for compatibility with the
21330 previous version of the code. */
21331 else if (m_op_index
== 0 || end_sequence
)
21333 fe
->included_p
= 1;
21334 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
21336 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21339 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21340 m_currently_recording_lines
? m_cu
: nullptr);
21345 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21346 m_line_has_non_zero_discriminator
,
21349 buildsym_compunit
*builder
= m_cu
->get_builder ();
21350 dwarf_record_line_1 (m_gdbarch
,
21351 builder
->get_current_subfile (),
21353 m_currently_recording_lines
? m_cu
: nullptr);
21355 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21356 m_last_line
= m_line
;
21362 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21363 line_header
*lh
, bool record_lines_p
)
21367 m_record_lines_p
= record_lines_p
;
21368 m_line_header
= lh
;
21370 m_currently_recording_lines
= true;
21372 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21373 was a line entry for it so that the backend has a chance to adjust it
21374 and also record it in case it needs it. This is currently used by MIPS
21375 code, cf. `mips_adjust_dwarf2_line'. */
21376 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21377 m_is_stmt
= lh
->default_is_stmt
;
21378 m_discriminator
= 0;
21382 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21383 const gdb_byte
*line_ptr
,
21384 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21386 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21387 the pc range of the CU. However, we restrict the test to only ADDRESS
21388 values of zero to preserve GDB's previous behaviour which is to handle
21389 the specific case of a function being GC'd by the linker. */
21391 if (address
== 0 && address
< unrelocated_lowpc
)
21393 /* This line table is for a function which has been
21394 GCd by the linker. Ignore it. PR gdb/12528 */
21396 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21397 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21399 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21400 line_offset
, objfile_name (objfile
));
21401 m_currently_recording_lines
= false;
21402 /* Note: m_currently_recording_lines is left as false until we see
21403 DW_LNE_end_sequence. */
21407 /* Subroutine of dwarf_decode_lines to simplify it.
21408 Process the line number information in LH.
21409 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21410 program in order to set included_p for every referenced header. */
21413 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21414 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21416 const gdb_byte
*line_ptr
, *extended_end
;
21417 const gdb_byte
*line_end
;
21418 unsigned int bytes_read
, extended_len
;
21419 unsigned char op_code
, extended_op
;
21420 CORE_ADDR baseaddr
;
21421 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21422 bfd
*abfd
= objfile
->obfd
;
21423 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21424 /* True if we're recording line info (as opposed to building partial
21425 symtabs and just interested in finding include files mentioned by
21426 the line number program). */
21427 bool record_lines_p
= !decode_for_pst_p
;
21429 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21431 line_ptr
= lh
->statement_program_start
;
21432 line_end
= lh
->statement_program_end
;
21434 /* Read the statement sequences until there's nothing left. */
21435 while (line_ptr
< line_end
)
21437 /* The DWARF line number program state machine. Reset the state
21438 machine at the start of each sequence. */
21439 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21440 bool end_sequence
= false;
21442 if (record_lines_p
)
21444 /* Start a subfile for the current file of the state
21446 const file_entry
*fe
= state_machine
.current_file ();
21449 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21452 /* Decode the table. */
21453 while (line_ptr
< line_end
&& !end_sequence
)
21455 op_code
= read_1_byte (abfd
, line_ptr
);
21458 if (op_code
>= lh
->opcode_base
)
21460 /* Special opcode. */
21461 state_machine
.handle_special_opcode (op_code
);
21463 else switch (op_code
)
21465 case DW_LNS_extended_op
:
21466 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21468 line_ptr
+= bytes_read
;
21469 extended_end
= line_ptr
+ extended_len
;
21470 extended_op
= read_1_byte (abfd
, line_ptr
);
21472 switch (extended_op
)
21474 case DW_LNE_end_sequence
:
21475 state_machine
.handle_end_sequence ();
21476 end_sequence
= true;
21478 case DW_LNE_set_address
:
21481 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21482 line_ptr
+= bytes_read
;
21484 state_machine
.check_line_address (cu
, line_ptr
,
21485 lowpc
- baseaddr
, address
);
21486 state_machine
.handle_set_address (baseaddr
, address
);
21489 case DW_LNE_define_file
:
21491 const char *cur_file
;
21492 unsigned int mod_time
, length
;
21495 cur_file
= read_direct_string (abfd
, line_ptr
,
21497 line_ptr
+= bytes_read
;
21498 dindex
= (dir_index
)
21499 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21500 line_ptr
+= bytes_read
;
21502 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21503 line_ptr
+= bytes_read
;
21505 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21506 line_ptr
+= bytes_read
;
21507 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21510 case DW_LNE_set_discriminator
:
21512 /* The discriminator is not interesting to the
21513 debugger; just ignore it. We still need to
21514 check its value though:
21515 if there are consecutive entries for the same
21516 (non-prologue) line we want to coalesce them.
21519 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21520 line_ptr
+= bytes_read
;
21522 state_machine
.handle_set_discriminator (discr
);
21526 complaint (_("mangled .debug_line section"));
21529 /* Make sure that we parsed the extended op correctly. If e.g.
21530 we expected a different address size than the producer used,
21531 we may have read the wrong number of bytes. */
21532 if (line_ptr
!= extended_end
)
21534 complaint (_("mangled .debug_line section"));
21539 state_machine
.handle_copy ();
21541 case DW_LNS_advance_pc
:
21544 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21545 line_ptr
+= bytes_read
;
21547 state_machine
.handle_advance_pc (adjust
);
21550 case DW_LNS_advance_line
:
21553 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21554 line_ptr
+= bytes_read
;
21556 state_machine
.handle_advance_line (line_delta
);
21559 case DW_LNS_set_file
:
21561 file_name_index file
21562 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21564 line_ptr
+= bytes_read
;
21566 state_machine
.handle_set_file (file
);
21569 case DW_LNS_set_column
:
21570 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21571 line_ptr
+= bytes_read
;
21573 case DW_LNS_negate_stmt
:
21574 state_machine
.handle_negate_stmt ();
21576 case DW_LNS_set_basic_block
:
21578 /* Add to the address register of the state machine the
21579 address increment value corresponding to special opcode
21580 255. I.e., this value is scaled by the minimum
21581 instruction length since special opcode 255 would have
21582 scaled the increment. */
21583 case DW_LNS_const_add_pc
:
21584 state_machine
.handle_const_add_pc ();
21586 case DW_LNS_fixed_advance_pc
:
21588 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21591 state_machine
.handle_fixed_advance_pc (addr_adj
);
21596 /* Unknown standard opcode, ignore it. */
21599 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21601 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21602 line_ptr
+= bytes_read
;
21609 dwarf2_debug_line_missing_end_sequence_complaint ();
21611 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21612 in which case we still finish recording the last line). */
21613 state_machine
.record_line (true);
21617 /* Decode the Line Number Program (LNP) for the given line_header
21618 structure and CU. The actual information extracted and the type
21619 of structures created from the LNP depends on the value of PST.
21621 1. If PST is NULL, then this procedure uses the data from the program
21622 to create all necessary symbol tables, and their linetables.
21624 2. If PST is not NULL, this procedure reads the program to determine
21625 the list of files included by the unit represented by PST, and
21626 builds all the associated partial symbol tables.
21628 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21629 It is used for relative paths in the line table.
21630 NOTE: When processing partial symtabs (pst != NULL),
21631 comp_dir == pst->dirname.
21633 NOTE: It is important that psymtabs have the same file name (via strcmp)
21634 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21635 symtab we don't use it in the name of the psymtabs we create.
21636 E.g. expand_line_sal requires this when finding psymtabs to expand.
21637 A good testcase for this is mb-inline.exp.
21639 LOWPC is the lowest address in CU (or 0 if not known).
21641 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21642 for its PC<->lines mapping information. Otherwise only the filename
21643 table is read in. */
21646 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21647 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21648 CORE_ADDR lowpc
, int decode_mapping
)
21650 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21651 const int decode_for_pst_p
= (pst
!= NULL
);
21653 if (decode_mapping
)
21654 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21656 if (decode_for_pst_p
)
21658 /* Now that we're done scanning the Line Header Program, we can
21659 create the psymtab of each included file. */
21660 for (auto &file_entry
: lh
->file_names ())
21661 if (file_entry
.included_p
== 1)
21663 gdb::unique_xmalloc_ptr
<char> name_holder
;
21664 const char *include_name
=
21665 psymtab_include_file_name (lh
, file_entry
, pst
,
21666 comp_dir
, &name_holder
);
21667 if (include_name
!= NULL
)
21668 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21673 /* Make sure a symtab is created for every file, even files
21674 which contain only variables (i.e. no code with associated
21676 buildsym_compunit
*builder
= cu
->get_builder ();
21677 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21679 for (auto &fe
: lh
->file_names ())
21681 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21682 if (builder
->get_current_subfile ()->symtab
== NULL
)
21684 builder
->get_current_subfile ()->symtab
21685 = allocate_symtab (cust
,
21686 builder
->get_current_subfile ()->name
);
21688 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21693 /* Start a subfile for DWARF. FILENAME is the name of the file and
21694 DIRNAME the name of the source directory which contains FILENAME
21695 or NULL if not known.
21696 This routine tries to keep line numbers from identical absolute and
21697 relative file names in a common subfile.
21699 Using the `list' example from the GDB testsuite, which resides in
21700 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21701 of /srcdir/list0.c yields the following debugging information for list0.c:
21703 DW_AT_name: /srcdir/list0.c
21704 DW_AT_comp_dir: /compdir
21705 files.files[0].name: list0.h
21706 files.files[0].dir: /srcdir
21707 files.files[1].name: list0.c
21708 files.files[1].dir: /srcdir
21710 The line number information for list0.c has to end up in a single
21711 subfile, so that `break /srcdir/list0.c:1' works as expected.
21712 start_subfile will ensure that this happens provided that we pass the
21713 concatenation of files.files[1].dir and files.files[1].name as the
21717 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21718 const char *dirname
)
21722 /* In order not to lose the line information directory,
21723 we concatenate it to the filename when it makes sense.
21724 Note that the Dwarf3 standard says (speaking of filenames in line
21725 information): ``The directory index is ignored for file names
21726 that represent full path names''. Thus ignoring dirname in the
21727 `else' branch below isn't an issue. */
21729 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21731 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21735 cu
->get_builder ()->start_subfile (filename
);
21741 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21742 buildsym_compunit constructor. */
21744 struct compunit_symtab
*
21745 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21748 gdb_assert (m_builder
== nullptr);
21750 m_builder
.reset (new struct buildsym_compunit
21751 (per_cu
->dwarf2_per_objfile
->objfile
,
21752 name
, comp_dir
, language
, low_pc
));
21754 list_in_scope
= get_builder ()->get_file_symbols ();
21756 get_builder ()->record_debugformat (xstrprintf ("DWARF %d", this->header
.version
));
21757 get_builder ()->record_producer (producer
);
21759 processing_has_namespace_info
= false;
21761 return get_builder ()->get_compunit_symtab ();
21765 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21766 struct dwarf2_cu
*cu
)
21768 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21769 struct comp_unit_head
*cu_header
= &cu
->header
;
21771 /* NOTE drow/2003-01-30: There used to be a comment and some special
21772 code here to turn a symbol with DW_AT_external and a
21773 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21774 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21775 with some versions of binutils) where shared libraries could have
21776 relocations against symbols in their debug information - the
21777 minimal symbol would have the right address, but the debug info
21778 would not. It's no longer necessary, because we will explicitly
21779 apply relocations when we read in the debug information now. */
21781 /* A DW_AT_location attribute with no contents indicates that a
21782 variable has been optimized away. */
21783 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21785 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21789 /* Handle one degenerate form of location expression specially, to
21790 preserve GDB's previous behavior when section offsets are
21791 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21792 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21794 if (attr_form_is_block (attr
)
21795 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21796 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21797 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21798 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21799 && (DW_BLOCK (attr
)->size
21800 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21802 unsigned int dummy
;
21804 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21805 SET_SYMBOL_VALUE_ADDRESS (sym
,
21806 read_address (objfile
->obfd
,
21807 DW_BLOCK (attr
)->data
+ 1,
21810 SET_SYMBOL_VALUE_ADDRESS
21811 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21813 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21814 fixup_symbol_section (sym
, objfile
);
21815 SET_SYMBOL_VALUE_ADDRESS (sym
,
21816 SYMBOL_VALUE_ADDRESS (sym
)
21817 + ANOFFSET (objfile
->section_offsets
,
21818 SYMBOL_SECTION (sym
)));
21822 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21823 expression evaluator, and use LOC_COMPUTED only when necessary
21824 (i.e. when the value of a register or memory location is
21825 referenced, or a thread-local block, etc.). Then again, it might
21826 not be worthwhile. I'm assuming that it isn't unless performance
21827 or memory numbers show me otherwise. */
21829 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21831 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21832 cu
->has_loclist
= true;
21835 /* Given a pointer to a DWARF information entry, figure out if we need
21836 to make a symbol table entry for it, and if so, create a new entry
21837 and return a pointer to it.
21838 If TYPE is NULL, determine symbol type from the die, otherwise
21839 used the passed type.
21840 If SPACE is not NULL, use it to hold the new symbol. If it is
21841 NULL, allocate a new symbol on the objfile's obstack. */
21843 static struct symbol
*
21844 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21845 struct symbol
*space
)
21847 struct dwarf2_per_objfile
*dwarf2_per_objfile
21848 = cu
->per_cu
->dwarf2_per_objfile
;
21849 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21850 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21851 struct symbol
*sym
= NULL
;
21853 struct attribute
*attr
= NULL
;
21854 struct attribute
*attr2
= NULL
;
21855 CORE_ADDR baseaddr
;
21856 struct pending
**list_to_add
= NULL
;
21858 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21860 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21862 name
= dwarf2_name (die
, cu
);
21865 const char *linkagename
;
21866 int suppress_add
= 0;
21871 sym
= allocate_symbol (objfile
);
21872 OBJSTAT (objfile
, n_syms
++);
21874 /* Cache this symbol's name and the name's demangled form (if any). */
21875 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21876 linkagename
= dwarf2_physname (name
, die
, cu
);
21877 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21879 /* Fortran does not have mangling standard and the mangling does differ
21880 between gfortran, iFort etc. */
21881 if (cu
->language
== language_fortran
21882 && symbol_get_demangled_name (sym
) == NULL
)
21883 symbol_set_demangled_name (sym
,
21884 dwarf2_full_name (name
, die
, cu
),
21887 /* Default assumptions.
21888 Use the passed type or decode it from the die. */
21889 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21890 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21892 SYMBOL_TYPE (sym
) = type
;
21894 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21895 attr
= dwarf2_attr (die
,
21896 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21898 if (attr
!= nullptr)
21900 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21903 attr
= dwarf2_attr (die
,
21904 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21906 if (attr
!= nullptr)
21908 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21909 struct file_entry
*fe
;
21911 if (cu
->line_header
!= NULL
)
21912 fe
= cu
->line_header
->file_name_at (file_index
);
21917 complaint (_("file index out of range"));
21919 symbol_set_symtab (sym
, fe
->symtab
);
21925 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21926 if (attr
!= nullptr)
21930 addr
= attr_value_as_address (attr
);
21931 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21932 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21934 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21935 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21936 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21937 add_symbol_to_list (sym
, cu
->list_in_scope
);
21939 case DW_TAG_subprogram
:
21940 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21942 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21943 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21944 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21945 || cu
->language
== language_ada
21946 || cu
->language
== language_fortran
)
21948 /* Subprograms marked external are stored as a global symbol.
21949 Ada and Fortran subprograms, whether marked external or
21950 not, are always stored as a global symbol, because we want
21951 to be able to access them globally. For instance, we want
21952 to be able to break on a nested subprogram without having
21953 to specify the context. */
21954 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21958 list_to_add
= cu
->list_in_scope
;
21961 case DW_TAG_inlined_subroutine
:
21962 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21964 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21965 SYMBOL_INLINED (sym
) = 1;
21966 list_to_add
= cu
->list_in_scope
;
21968 case DW_TAG_template_value_param
:
21970 /* Fall through. */
21971 case DW_TAG_constant
:
21972 case DW_TAG_variable
:
21973 case DW_TAG_member
:
21974 /* Compilation with minimal debug info may result in
21975 variables with missing type entries. Change the
21976 misleading `void' type to something sensible. */
21977 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21978 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21980 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21981 /* In the case of DW_TAG_member, we should only be called for
21982 static const members. */
21983 if (die
->tag
== DW_TAG_member
)
21985 /* dwarf2_add_field uses die_is_declaration,
21986 so we do the same. */
21987 gdb_assert (die_is_declaration (die
, cu
));
21990 if (attr
!= nullptr)
21992 dwarf2_const_value (attr
, sym
, cu
);
21993 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21996 if (attr2
&& (DW_UNSND (attr2
) != 0))
21997 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21999 list_to_add
= cu
->list_in_scope
;
22003 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22004 if (attr
!= nullptr)
22006 var_decode_location (attr
, sym
, cu
);
22007 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22009 /* Fortran explicitly imports any global symbols to the local
22010 scope by DW_TAG_common_block. */
22011 if (cu
->language
== language_fortran
&& die
->parent
22012 && die
->parent
->tag
== DW_TAG_common_block
)
22015 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22016 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22017 && !dwarf2_per_objfile
->has_section_at_zero
)
22019 /* When a static variable is eliminated by the linker,
22020 the corresponding debug information is not stripped
22021 out, but the variable address is set to null;
22022 do not add such variables into symbol table. */
22024 else if (attr2
&& (DW_UNSND (attr2
) != 0))
22026 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22027 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22028 && dwarf2_per_objfile
->can_copy
)
22030 /* A global static variable might be subject to
22031 copy relocation. We first check for a local
22032 minsym, though, because maybe the symbol was
22033 marked hidden, in which case this would not
22035 bound_minimal_symbol found
22036 = (lookup_minimal_symbol_linkage
22037 (sym
->linkage_name (), objfile
));
22038 if (found
.minsym
!= nullptr)
22039 sym
->maybe_copied
= 1;
22042 /* A variable with DW_AT_external is never static,
22043 but it may be block-scoped. */
22045 = ((cu
->list_in_scope
22046 == cu
->get_builder ()->get_file_symbols ())
22047 ? cu
->get_builder ()->get_global_symbols ()
22048 : cu
->list_in_scope
);
22051 list_to_add
= cu
->list_in_scope
;
22055 /* We do not know the address of this symbol.
22056 If it is an external symbol and we have type information
22057 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22058 The address of the variable will then be determined from
22059 the minimal symbol table whenever the variable is
22061 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22063 /* Fortran explicitly imports any global symbols to the local
22064 scope by DW_TAG_common_block. */
22065 if (cu
->language
== language_fortran
&& die
->parent
22066 && die
->parent
->tag
== DW_TAG_common_block
)
22068 /* SYMBOL_CLASS doesn't matter here because
22069 read_common_block is going to reset it. */
22071 list_to_add
= cu
->list_in_scope
;
22073 else if (attr2
&& (DW_UNSND (attr2
) != 0)
22074 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22076 /* A variable with DW_AT_external is never static, but it
22077 may be block-scoped. */
22079 = ((cu
->list_in_scope
22080 == cu
->get_builder ()->get_file_symbols ())
22081 ? cu
->get_builder ()->get_global_symbols ()
22082 : cu
->list_in_scope
);
22084 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22086 else if (!die_is_declaration (die
, cu
))
22088 /* Use the default LOC_OPTIMIZED_OUT class. */
22089 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22091 list_to_add
= cu
->list_in_scope
;
22095 case DW_TAG_formal_parameter
:
22097 /* If we are inside a function, mark this as an argument. If
22098 not, we might be looking at an argument to an inlined function
22099 when we do not have enough information to show inlined frames;
22100 pretend it's a local variable in that case so that the user can
22102 struct context_stack
*curr
22103 = cu
->get_builder ()->get_current_context_stack ();
22104 if (curr
!= nullptr && curr
->name
!= nullptr)
22105 SYMBOL_IS_ARGUMENT (sym
) = 1;
22106 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22107 if (attr
!= nullptr)
22109 var_decode_location (attr
, sym
, cu
);
22111 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22112 if (attr
!= nullptr)
22114 dwarf2_const_value (attr
, sym
, cu
);
22117 list_to_add
= cu
->list_in_scope
;
22120 case DW_TAG_unspecified_parameters
:
22121 /* From varargs functions; gdb doesn't seem to have any
22122 interest in this information, so just ignore it for now.
22125 case DW_TAG_template_type_param
:
22127 /* Fall through. */
22128 case DW_TAG_class_type
:
22129 case DW_TAG_interface_type
:
22130 case DW_TAG_structure_type
:
22131 case DW_TAG_union_type
:
22132 case DW_TAG_set_type
:
22133 case DW_TAG_enumeration_type
:
22134 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22135 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22138 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22139 really ever be static objects: otherwise, if you try
22140 to, say, break of a class's method and you're in a file
22141 which doesn't mention that class, it won't work unless
22142 the check for all static symbols in lookup_symbol_aux
22143 saves you. See the OtherFileClass tests in
22144 gdb.c++/namespace.exp. */
22148 buildsym_compunit
*builder
= cu
->get_builder ();
22150 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22151 && cu
->language
== language_cplus
22152 ? builder
->get_global_symbols ()
22153 : cu
->list_in_scope
);
22155 /* The semantics of C++ state that "struct foo {
22156 ... }" also defines a typedef for "foo". */
22157 if (cu
->language
== language_cplus
22158 || cu
->language
== language_ada
22159 || cu
->language
== language_d
22160 || cu
->language
== language_rust
)
22162 /* The symbol's name is already allocated along
22163 with this objfile, so we don't need to
22164 duplicate it for the type. */
22165 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
22166 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
22171 case DW_TAG_typedef
:
22172 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22173 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22174 list_to_add
= cu
->list_in_scope
;
22176 case DW_TAG_base_type
:
22177 case DW_TAG_subrange_type
:
22178 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22179 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22180 list_to_add
= cu
->list_in_scope
;
22182 case DW_TAG_enumerator
:
22183 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22184 if (attr
!= nullptr)
22186 dwarf2_const_value (attr
, sym
, cu
);
22189 /* NOTE: carlton/2003-11-10: See comment above in the
22190 DW_TAG_class_type, etc. block. */
22193 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22194 && cu
->language
== language_cplus
22195 ? cu
->get_builder ()->get_global_symbols ()
22196 : cu
->list_in_scope
);
22199 case DW_TAG_imported_declaration
:
22200 case DW_TAG_namespace
:
22201 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22202 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22204 case DW_TAG_module
:
22205 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22206 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22207 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22209 case DW_TAG_common_block
:
22210 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22211 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22212 add_symbol_to_list (sym
, cu
->list_in_scope
);
22215 /* Not a tag we recognize. Hopefully we aren't processing
22216 trash data, but since we must specifically ignore things
22217 we don't recognize, there is nothing else we should do at
22219 complaint (_("unsupported tag: '%s'"),
22220 dwarf_tag_name (die
->tag
));
22226 sym
->hash_next
= objfile
->template_symbols
;
22227 objfile
->template_symbols
= sym
;
22228 list_to_add
= NULL
;
22231 if (list_to_add
!= NULL
)
22232 add_symbol_to_list (sym
, list_to_add
);
22234 /* For the benefit of old versions of GCC, check for anonymous
22235 namespaces based on the demangled name. */
22236 if (!cu
->processing_has_namespace_info
22237 && cu
->language
== language_cplus
)
22238 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22243 /* Given an attr with a DW_FORM_dataN value in host byte order,
22244 zero-extend it as appropriate for the symbol's type. The DWARF
22245 standard (v4) is not entirely clear about the meaning of using
22246 DW_FORM_dataN for a constant with a signed type, where the type is
22247 wider than the data. The conclusion of a discussion on the DWARF
22248 list was that this is unspecified. We choose to always zero-extend
22249 because that is the interpretation long in use by GCC. */
22252 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22253 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22255 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22256 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22257 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22258 LONGEST l
= DW_UNSND (attr
);
22260 if (bits
< sizeof (*value
) * 8)
22262 l
&= ((LONGEST
) 1 << bits
) - 1;
22265 else if (bits
== sizeof (*value
) * 8)
22269 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22270 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22277 /* Read a constant value from an attribute. Either set *VALUE, or if
22278 the value does not fit in *VALUE, set *BYTES - either already
22279 allocated on the objfile obstack, or newly allocated on OBSTACK,
22280 or, set *BATON, if we translated the constant to a location
22284 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22285 const char *name
, struct obstack
*obstack
,
22286 struct dwarf2_cu
*cu
,
22287 LONGEST
*value
, const gdb_byte
**bytes
,
22288 struct dwarf2_locexpr_baton
**baton
)
22290 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22291 struct comp_unit_head
*cu_header
= &cu
->header
;
22292 struct dwarf_block
*blk
;
22293 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22294 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22300 switch (attr
->form
)
22303 case DW_FORM_addrx
:
22304 case DW_FORM_GNU_addr_index
:
22308 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22309 dwarf2_const_value_length_mismatch_complaint (name
,
22310 cu_header
->addr_size
,
22311 TYPE_LENGTH (type
));
22312 /* Symbols of this form are reasonably rare, so we just
22313 piggyback on the existing location code rather than writing
22314 a new implementation of symbol_computed_ops. */
22315 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22316 (*baton
)->per_cu
= cu
->per_cu
;
22317 gdb_assert ((*baton
)->per_cu
);
22319 (*baton
)->size
= 2 + cu_header
->addr_size
;
22320 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22321 (*baton
)->data
= data
;
22323 data
[0] = DW_OP_addr
;
22324 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22325 byte_order
, DW_ADDR (attr
));
22326 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22329 case DW_FORM_string
:
22332 case DW_FORM_GNU_str_index
:
22333 case DW_FORM_GNU_strp_alt
:
22334 /* DW_STRING is already allocated on the objfile obstack, point
22336 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22338 case DW_FORM_block1
:
22339 case DW_FORM_block2
:
22340 case DW_FORM_block4
:
22341 case DW_FORM_block
:
22342 case DW_FORM_exprloc
:
22343 case DW_FORM_data16
:
22344 blk
= DW_BLOCK (attr
);
22345 if (TYPE_LENGTH (type
) != blk
->size
)
22346 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22347 TYPE_LENGTH (type
));
22348 *bytes
= blk
->data
;
22351 /* The DW_AT_const_value attributes are supposed to carry the
22352 symbol's value "represented as it would be on the target
22353 architecture." By the time we get here, it's already been
22354 converted to host endianness, so we just need to sign- or
22355 zero-extend it as appropriate. */
22356 case DW_FORM_data1
:
22357 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22359 case DW_FORM_data2
:
22360 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22362 case DW_FORM_data4
:
22363 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22365 case DW_FORM_data8
:
22366 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22369 case DW_FORM_sdata
:
22370 case DW_FORM_implicit_const
:
22371 *value
= DW_SND (attr
);
22374 case DW_FORM_udata
:
22375 *value
= DW_UNSND (attr
);
22379 complaint (_("unsupported const value attribute form: '%s'"),
22380 dwarf_form_name (attr
->form
));
22387 /* Copy constant value from an attribute to a symbol. */
22390 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22391 struct dwarf2_cu
*cu
)
22393 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22395 const gdb_byte
*bytes
;
22396 struct dwarf2_locexpr_baton
*baton
;
22398 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22399 sym
->print_name (),
22400 &objfile
->objfile_obstack
, cu
,
22401 &value
, &bytes
, &baton
);
22405 SYMBOL_LOCATION_BATON (sym
) = baton
;
22406 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22408 else if (bytes
!= NULL
)
22410 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22411 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22415 SYMBOL_VALUE (sym
) = value
;
22416 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22420 /* Return the type of the die in question using its DW_AT_type attribute. */
22422 static struct type
*
22423 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22425 struct attribute
*type_attr
;
22427 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22430 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22431 /* A missing DW_AT_type represents a void type. */
22432 return objfile_type (objfile
)->builtin_void
;
22435 return lookup_die_type (die
, type_attr
, cu
);
22438 /* True iff CU's producer generates GNAT Ada auxiliary information
22439 that allows to find parallel types through that information instead
22440 of having to do expensive parallel lookups by type name. */
22443 need_gnat_info (struct dwarf2_cu
*cu
)
22445 /* Assume that the Ada compiler was GNAT, which always produces
22446 the auxiliary information. */
22447 return (cu
->language
== language_ada
);
22450 /* Return the auxiliary type of the die in question using its
22451 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22452 attribute is not present. */
22454 static struct type
*
22455 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22457 struct attribute
*type_attr
;
22459 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22463 return lookup_die_type (die
, type_attr
, cu
);
22466 /* If DIE has a descriptive_type attribute, then set the TYPE's
22467 descriptive type accordingly. */
22470 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22471 struct dwarf2_cu
*cu
)
22473 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22475 if (descriptive_type
)
22477 ALLOCATE_GNAT_AUX_TYPE (type
);
22478 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22482 /* Return the containing type of the die in question using its
22483 DW_AT_containing_type attribute. */
22485 static struct type
*
22486 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22488 struct attribute
*type_attr
;
22489 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22491 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22493 error (_("Dwarf Error: Problem turning containing type into gdb type "
22494 "[in module %s]"), objfile_name (objfile
));
22496 return lookup_die_type (die
, type_attr
, cu
);
22499 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22501 static struct type
*
22502 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22504 struct dwarf2_per_objfile
*dwarf2_per_objfile
22505 = cu
->per_cu
->dwarf2_per_objfile
;
22506 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22509 std::string message
22510 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22511 objfile_name (objfile
),
22512 sect_offset_str (cu
->header
.sect_off
),
22513 sect_offset_str (die
->sect_off
));
22514 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22516 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22519 /* Look up the type of DIE in CU using its type attribute ATTR.
22520 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22521 DW_AT_containing_type.
22522 If there is no type substitute an error marker. */
22524 static struct type
*
22525 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22526 struct dwarf2_cu
*cu
)
22528 struct dwarf2_per_objfile
*dwarf2_per_objfile
22529 = cu
->per_cu
->dwarf2_per_objfile
;
22530 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22531 struct type
*this_type
;
22533 gdb_assert (attr
->name
== DW_AT_type
22534 || attr
->name
== DW_AT_GNAT_descriptive_type
22535 || attr
->name
== DW_AT_containing_type
);
22537 /* First see if we have it cached. */
22539 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22541 struct dwarf2_per_cu_data
*per_cu
;
22542 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22544 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22545 dwarf2_per_objfile
);
22546 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22548 else if (attr_form_is_ref (attr
))
22550 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22552 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22554 else if (attr
->form
== DW_FORM_ref_sig8
)
22556 ULONGEST signature
= DW_SIGNATURE (attr
);
22558 return get_signatured_type (die
, signature
, cu
);
22562 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22563 " at %s [in module %s]"),
22564 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22565 objfile_name (objfile
));
22566 return build_error_marker_type (cu
, die
);
22569 /* If not cached we need to read it in. */
22571 if (this_type
== NULL
)
22573 struct die_info
*type_die
= NULL
;
22574 struct dwarf2_cu
*type_cu
= cu
;
22576 if (attr_form_is_ref (attr
))
22577 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22578 if (type_die
== NULL
)
22579 return build_error_marker_type (cu
, die
);
22580 /* If we find the type now, it's probably because the type came
22581 from an inter-CU reference and the type's CU got expanded before
22583 this_type
= read_type_die (type_die
, type_cu
);
22586 /* If we still don't have a type use an error marker. */
22588 if (this_type
== NULL
)
22589 return build_error_marker_type (cu
, die
);
22594 /* Return the type in DIE, CU.
22595 Returns NULL for invalid types.
22597 This first does a lookup in die_type_hash,
22598 and only reads the die in if necessary.
22600 NOTE: This can be called when reading in partial or full symbols. */
22602 static struct type
*
22603 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22605 struct type
*this_type
;
22607 this_type
= get_die_type (die
, cu
);
22611 return read_type_die_1 (die
, cu
);
22614 /* Read the type in DIE, CU.
22615 Returns NULL for invalid types. */
22617 static struct type
*
22618 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22620 struct type
*this_type
= NULL
;
22624 case DW_TAG_class_type
:
22625 case DW_TAG_interface_type
:
22626 case DW_TAG_structure_type
:
22627 case DW_TAG_union_type
:
22628 this_type
= read_structure_type (die
, cu
);
22630 case DW_TAG_enumeration_type
:
22631 this_type
= read_enumeration_type (die
, cu
);
22633 case DW_TAG_subprogram
:
22634 case DW_TAG_subroutine_type
:
22635 case DW_TAG_inlined_subroutine
:
22636 this_type
= read_subroutine_type (die
, cu
);
22638 case DW_TAG_array_type
:
22639 this_type
= read_array_type (die
, cu
);
22641 case DW_TAG_set_type
:
22642 this_type
= read_set_type (die
, cu
);
22644 case DW_TAG_pointer_type
:
22645 this_type
= read_tag_pointer_type (die
, cu
);
22647 case DW_TAG_ptr_to_member_type
:
22648 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22650 case DW_TAG_reference_type
:
22651 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22653 case DW_TAG_rvalue_reference_type
:
22654 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22656 case DW_TAG_const_type
:
22657 this_type
= read_tag_const_type (die
, cu
);
22659 case DW_TAG_volatile_type
:
22660 this_type
= read_tag_volatile_type (die
, cu
);
22662 case DW_TAG_restrict_type
:
22663 this_type
= read_tag_restrict_type (die
, cu
);
22665 case DW_TAG_string_type
:
22666 this_type
= read_tag_string_type (die
, cu
);
22668 case DW_TAG_typedef
:
22669 this_type
= read_typedef (die
, cu
);
22671 case DW_TAG_subrange_type
:
22672 this_type
= read_subrange_type (die
, cu
);
22674 case DW_TAG_base_type
:
22675 this_type
= read_base_type (die
, cu
);
22677 case DW_TAG_unspecified_type
:
22678 this_type
= read_unspecified_type (die
, cu
);
22680 case DW_TAG_namespace
:
22681 this_type
= read_namespace_type (die
, cu
);
22683 case DW_TAG_module
:
22684 this_type
= read_module_type (die
, cu
);
22686 case DW_TAG_atomic_type
:
22687 this_type
= read_tag_atomic_type (die
, cu
);
22690 complaint (_("unexpected tag in read_type_die: '%s'"),
22691 dwarf_tag_name (die
->tag
));
22698 /* See if we can figure out if the class lives in a namespace. We do
22699 this by looking for a member function; its demangled name will
22700 contain namespace info, if there is any.
22701 Return the computed name or NULL.
22702 Space for the result is allocated on the objfile's obstack.
22703 This is the full-die version of guess_partial_die_structure_name.
22704 In this case we know DIE has no useful parent. */
22707 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22709 struct die_info
*spec_die
;
22710 struct dwarf2_cu
*spec_cu
;
22711 struct die_info
*child
;
22712 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22715 spec_die
= die_specification (die
, &spec_cu
);
22716 if (spec_die
!= NULL
)
22722 for (child
= die
->child
;
22724 child
= child
->sibling
)
22726 if (child
->tag
== DW_TAG_subprogram
)
22728 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22730 if (linkage_name
!= NULL
)
22733 = language_class_name_from_physname (cu
->language_defn
,
22737 if (actual_name
!= NULL
)
22739 const char *die_name
= dwarf2_name (die
, cu
);
22741 if (die_name
!= NULL
22742 && strcmp (die_name
, actual_name
) != 0)
22744 /* Strip off the class name from the full name.
22745 We want the prefix. */
22746 int die_name_len
= strlen (die_name
);
22747 int actual_name_len
= strlen (actual_name
);
22749 /* Test for '::' as a sanity check. */
22750 if (actual_name_len
> die_name_len
+ 2
22751 && actual_name
[actual_name_len
22752 - die_name_len
- 1] == ':')
22753 name
= obstack_strndup (
22754 &objfile
->per_bfd
->storage_obstack
,
22755 actual_name
, actual_name_len
- die_name_len
- 2);
22758 xfree (actual_name
);
22767 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22768 prefix part in such case. See
22769 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22771 static const char *
22772 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22774 struct attribute
*attr
;
22777 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22778 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22781 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22784 attr
= dw2_linkage_name_attr (die
, cu
);
22785 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22788 /* dwarf2_name had to be already called. */
22789 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22791 /* Strip the base name, keep any leading namespaces/classes. */
22792 base
= strrchr (DW_STRING (attr
), ':');
22793 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22796 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22797 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22799 &base
[-1] - DW_STRING (attr
));
22802 /* Return the name of the namespace/class that DIE is defined within,
22803 or "" if we can't tell. The caller should not xfree the result.
22805 For example, if we're within the method foo() in the following
22815 then determine_prefix on foo's die will return "N::C". */
22817 static const char *
22818 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22820 struct dwarf2_per_objfile
*dwarf2_per_objfile
22821 = cu
->per_cu
->dwarf2_per_objfile
;
22822 struct die_info
*parent
, *spec_die
;
22823 struct dwarf2_cu
*spec_cu
;
22824 struct type
*parent_type
;
22825 const char *retval
;
22827 if (cu
->language
!= language_cplus
22828 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22829 && cu
->language
!= language_rust
)
22832 retval
= anonymous_struct_prefix (die
, cu
);
22836 /* We have to be careful in the presence of DW_AT_specification.
22837 For example, with GCC 3.4, given the code
22841 // Definition of N::foo.
22845 then we'll have a tree of DIEs like this:
22847 1: DW_TAG_compile_unit
22848 2: DW_TAG_namespace // N
22849 3: DW_TAG_subprogram // declaration of N::foo
22850 4: DW_TAG_subprogram // definition of N::foo
22851 DW_AT_specification // refers to die #3
22853 Thus, when processing die #4, we have to pretend that we're in
22854 the context of its DW_AT_specification, namely the contex of die
22857 spec_die
= die_specification (die
, &spec_cu
);
22858 if (spec_die
== NULL
)
22859 parent
= die
->parent
;
22862 parent
= spec_die
->parent
;
22866 if (parent
== NULL
)
22868 else if (parent
->building_fullname
)
22871 const char *parent_name
;
22873 /* It has been seen on RealView 2.2 built binaries,
22874 DW_TAG_template_type_param types actually _defined_ as
22875 children of the parent class:
22878 template class <class Enum> Class{};
22879 Class<enum E> class_e;
22881 1: DW_TAG_class_type (Class)
22882 2: DW_TAG_enumeration_type (E)
22883 3: DW_TAG_enumerator (enum1:0)
22884 3: DW_TAG_enumerator (enum2:1)
22886 2: DW_TAG_template_type_param
22887 DW_AT_type DW_FORM_ref_udata (E)
22889 Besides being broken debug info, it can put GDB into an
22890 infinite loop. Consider:
22892 When we're building the full name for Class<E>, we'll start
22893 at Class, and go look over its template type parameters,
22894 finding E. We'll then try to build the full name of E, and
22895 reach here. We're now trying to build the full name of E,
22896 and look over the parent DIE for containing scope. In the
22897 broken case, if we followed the parent DIE of E, we'd again
22898 find Class, and once again go look at its template type
22899 arguments, etc., etc. Simply don't consider such parent die
22900 as source-level parent of this die (it can't be, the language
22901 doesn't allow it), and break the loop here. */
22902 name
= dwarf2_name (die
, cu
);
22903 parent_name
= dwarf2_name (parent
, cu
);
22904 complaint (_("template param type '%s' defined within parent '%s'"),
22905 name
? name
: "<unknown>",
22906 parent_name
? parent_name
: "<unknown>");
22910 switch (parent
->tag
)
22912 case DW_TAG_namespace
:
22913 parent_type
= read_type_die (parent
, cu
);
22914 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22915 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22916 Work around this problem here. */
22917 if (cu
->language
== language_cplus
22918 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22920 /* We give a name to even anonymous namespaces. */
22921 return TYPE_NAME (parent_type
);
22922 case DW_TAG_class_type
:
22923 case DW_TAG_interface_type
:
22924 case DW_TAG_structure_type
:
22925 case DW_TAG_union_type
:
22926 case DW_TAG_module
:
22927 parent_type
= read_type_die (parent
, cu
);
22928 if (TYPE_NAME (parent_type
) != NULL
)
22929 return TYPE_NAME (parent_type
);
22931 /* An anonymous structure is only allowed non-static data
22932 members; no typedefs, no member functions, et cetera.
22933 So it does not need a prefix. */
22935 case DW_TAG_compile_unit
:
22936 case DW_TAG_partial_unit
:
22937 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22938 if (cu
->language
== language_cplus
22939 && !dwarf2_per_objfile
->types
.empty ()
22940 && die
->child
!= NULL
22941 && (die
->tag
== DW_TAG_class_type
22942 || die
->tag
== DW_TAG_structure_type
22943 || die
->tag
== DW_TAG_union_type
))
22945 char *name
= guess_full_die_structure_name (die
, cu
);
22950 case DW_TAG_subprogram
:
22951 /* Nested subroutines in Fortran get a prefix with the name
22952 of the parent's subroutine. */
22953 if (cu
->language
== language_fortran
)
22955 if ((die
->tag
== DW_TAG_subprogram
)
22956 && (dwarf2_name (parent
, cu
) != NULL
))
22957 return dwarf2_name (parent
, cu
);
22959 return determine_prefix (parent
, cu
);
22960 case DW_TAG_enumeration_type
:
22961 parent_type
= read_type_die (parent
, cu
);
22962 if (TYPE_DECLARED_CLASS (parent_type
))
22964 if (TYPE_NAME (parent_type
) != NULL
)
22965 return TYPE_NAME (parent_type
);
22968 /* Fall through. */
22970 return determine_prefix (parent
, cu
);
22974 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22975 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22976 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22977 an obconcat, otherwise allocate storage for the result. The CU argument is
22978 used to determine the language and hence, the appropriate separator. */
22980 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22983 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22984 int physname
, struct dwarf2_cu
*cu
)
22986 const char *lead
= "";
22989 if (suffix
== NULL
|| suffix
[0] == '\0'
22990 || prefix
== NULL
|| prefix
[0] == '\0')
22992 else if (cu
->language
== language_d
)
22994 /* For D, the 'main' function could be defined in any module, but it
22995 should never be prefixed. */
22996 if (strcmp (suffix
, "D main") == 0)
23004 else if (cu
->language
== language_fortran
&& physname
)
23006 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
23007 DW_AT_MIPS_linkage_name is preferred and used instead. */
23015 if (prefix
== NULL
)
23017 if (suffix
== NULL
)
23024 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23026 strcpy (retval
, lead
);
23027 strcat (retval
, prefix
);
23028 strcat (retval
, sep
);
23029 strcat (retval
, suffix
);
23034 /* We have an obstack. */
23035 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23039 /* Return sibling of die, NULL if no sibling. */
23041 static struct die_info
*
23042 sibling_die (struct die_info
*die
)
23044 return die
->sibling
;
23047 /* Get name of a die, return NULL if not found. */
23049 static const char *
23050 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23051 struct obstack
*obstack
)
23053 if (name
&& cu
->language
== language_cplus
)
23055 std::string canon_name
= cp_canonicalize_string (name
);
23057 if (!canon_name
.empty ())
23059 if (canon_name
!= name
)
23060 name
= obstack_strdup (obstack
, canon_name
);
23067 /* Get name of a die, return NULL if not found.
23068 Anonymous namespaces are converted to their magic string. */
23070 static const char *
23071 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23073 struct attribute
*attr
;
23074 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23076 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23077 if ((!attr
|| !DW_STRING (attr
))
23078 && die
->tag
!= DW_TAG_namespace
23079 && die
->tag
!= DW_TAG_class_type
23080 && die
->tag
!= DW_TAG_interface_type
23081 && die
->tag
!= DW_TAG_structure_type
23082 && die
->tag
!= DW_TAG_union_type
)
23087 case DW_TAG_compile_unit
:
23088 case DW_TAG_partial_unit
:
23089 /* Compilation units have a DW_AT_name that is a filename, not
23090 a source language identifier. */
23091 case DW_TAG_enumeration_type
:
23092 case DW_TAG_enumerator
:
23093 /* These tags always have simple identifiers already; no need
23094 to canonicalize them. */
23095 return DW_STRING (attr
);
23097 case DW_TAG_namespace
:
23098 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
23099 return DW_STRING (attr
);
23100 return CP_ANONYMOUS_NAMESPACE_STR
;
23102 case DW_TAG_class_type
:
23103 case DW_TAG_interface_type
:
23104 case DW_TAG_structure_type
:
23105 case DW_TAG_union_type
:
23106 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23107 structures or unions. These were of the form "._%d" in GCC 4.1,
23108 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23109 and GCC 4.4. We work around this problem by ignoring these. */
23110 if (attr
&& DW_STRING (attr
)
23111 && (startswith (DW_STRING (attr
), "._")
23112 || startswith (DW_STRING (attr
), "<anonymous")))
23115 /* GCC might emit a nameless typedef that has a linkage name. See
23116 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23117 if (!attr
|| DW_STRING (attr
) == NULL
)
23119 char *demangled
= NULL
;
23121 attr
= dw2_linkage_name_attr (die
, cu
);
23122 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
23125 /* Avoid demangling DW_STRING (attr) the second time on a second
23126 call for the same DIE. */
23127 if (!DW_STRING_IS_CANONICAL (attr
))
23128 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
23134 /* FIXME: we already did this for the partial symbol... */
23136 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
23138 DW_STRING_IS_CANONICAL (attr
) = 1;
23141 /* Strip any leading namespaces/classes, keep only the base name.
23142 DW_AT_name for named DIEs does not contain the prefixes. */
23143 base
= strrchr (DW_STRING (attr
), ':');
23144 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
23147 return DW_STRING (attr
);
23156 if (!DW_STRING_IS_CANONICAL (attr
))
23159 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
23160 &objfile
->per_bfd
->storage_obstack
);
23161 DW_STRING_IS_CANONICAL (attr
) = 1;
23163 return DW_STRING (attr
);
23166 /* Return the die that this die in an extension of, or NULL if there
23167 is none. *EXT_CU is the CU containing DIE on input, and the CU
23168 containing the return value on output. */
23170 static struct die_info
*
23171 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23173 struct attribute
*attr
;
23175 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23179 return follow_die_ref (die
, attr
, ext_cu
);
23182 /* A convenience function that returns an "unknown" DWARF name,
23183 including the value of V. STR is the name of the entity being
23184 printed, e.g., "TAG". */
23186 static const char *
23187 dwarf_unknown (const char *str
, unsigned v
)
23189 char *cell
= get_print_cell ();
23190 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
23194 /* Convert a DIE tag into its string name. */
23196 static const char *
23197 dwarf_tag_name (unsigned tag
)
23199 const char *name
= get_DW_TAG_name (tag
);
23202 return dwarf_unknown ("TAG", tag
);
23207 /* Convert a DWARF attribute code into its string name. */
23209 static const char *
23210 dwarf_attr_name (unsigned attr
)
23214 #ifdef MIPS /* collides with DW_AT_HP_block_index */
23215 if (attr
== DW_AT_MIPS_fde
)
23216 return "DW_AT_MIPS_fde";
23218 if (attr
== DW_AT_HP_block_index
)
23219 return "DW_AT_HP_block_index";
23222 name
= get_DW_AT_name (attr
);
23225 return dwarf_unknown ("AT", attr
);
23230 /* Convert a unit type to corresponding DW_UT name. */
23232 static const char *
23233 dwarf_unit_type_name (int unit_type
) {
23237 return "DW_UT_compile (0x01)";
23239 return "DW_UT_type (0x02)";
23241 return "DW_UT_partial (0x03)";
23243 return "DW_UT_skeleton (0x04)";
23245 return "DW_UT_split_compile (0x05)";
23247 return "DW_UT_split_type (0x06)";
23249 return "DW_UT_lo_user (0x80)";
23251 return "DW_UT_hi_user (0xff)";
23257 /* Convert a DWARF value form code into its string name. */
23259 static const char *
23260 dwarf_form_name (unsigned form
)
23262 const char *name
= get_DW_FORM_name (form
);
23265 return dwarf_unknown ("FORM", form
);
23270 static const char *
23271 dwarf_bool_name (unsigned mybool
)
23279 /* Convert a DWARF type code into its string name. */
23281 static const char *
23282 dwarf_type_encoding_name (unsigned enc
)
23284 const char *name
= get_DW_ATE_name (enc
);
23287 return dwarf_unknown ("ATE", enc
);
23293 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23297 print_spaces (indent
, f
);
23298 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23299 dwarf_tag_name (die
->tag
), die
->abbrev
,
23300 sect_offset_str (die
->sect_off
));
23302 if (die
->parent
!= NULL
)
23304 print_spaces (indent
, f
);
23305 fprintf_unfiltered (f
, " parent at offset: %s\n",
23306 sect_offset_str (die
->parent
->sect_off
));
23309 print_spaces (indent
, f
);
23310 fprintf_unfiltered (f
, " has children: %s\n",
23311 dwarf_bool_name (die
->child
!= NULL
));
23313 print_spaces (indent
, f
);
23314 fprintf_unfiltered (f
, " attributes:\n");
23316 for (i
= 0; i
< die
->num_attrs
; ++i
)
23318 print_spaces (indent
, f
);
23319 fprintf_unfiltered (f
, " %s (%s) ",
23320 dwarf_attr_name (die
->attrs
[i
].name
),
23321 dwarf_form_name (die
->attrs
[i
].form
));
23323 switch (die
->attrs
[i
].form
)
23326 case DW_FORM_addrx
:
23327 case DW_FORM_GNU_addr_index
:
23328 fprintf_unfiltered (f
, "address: ");
23329 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23331 case DW_FORM_block2
:
23332 case DW_FORM_block4
:
23333 case DW_FORM_block
:
23334 case DW_FORM_block1
:
23335 fprintf_unfiltered (f
, "block: size %s",
23336 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23338 case DW_FORM_exprloc
:
23339 fprintf_unfiltered (f
, "expression: size %s",
23340 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23342 case DW_FORM_data16
:
23343 fprintf_unfiltered (f
, "constant of 16 bytes");
23345 case DW_FORM_ref_addr
:
23346 fprintf_unfiltered (f
, "ref address: ");
23347 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23349 case DW_FORM_GNU_ref_alt
:
23350 fprintf_unfiltered (f
, "alt ref address: ");
23351 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23357 case DW_FORM_ref_udata
:
23358 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23359 (long) (DW_UNSND (&die
->attrs
[i
])));
23361 case DW_FORM_data1
:
23362 case DW_FORM_data2
:
23363 case DW_FORM_data4
:
23364 case DW_FORM_data8
:
23365 case DW_FORM_udata
:
23366 case DW_FORM_sdata
:
23367 fprintf_unfiltered (f
, "constant: %s",
23368 pulongest (DW_UNSND (&die
->attrs
[i
])));
23370 case DW_FORM_sec_offset
:
23371 fprintf_unfiltered (f
, "section offset: %s",
23372 pulongest (DW_UNSND (&die
->attrs
[i
])));
23374 case DW_FORM_ref_sig8
:
23375 fprintf_unfiltered (f
, "signature: %s",
23376 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23378 case DW_FORM_string
:
23380 case DW_FORM_line_strp
:
23382 case DW_FORM_GNU_str_index
:
23383 case DW_FORM_GNU_strp_alt
:
23384 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23385 DW_STRING (&die
->attrs
[i
])
23386 ? DW_STRING (&die
->attrs
[i
]) : "",
23387 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23390 if (DW_UNSND (&die
->attrs
[i
]))
23391 fprintf_unfiltered (f
, "flag: TRUE");
23393 fprintf_unfiltered (f
, "flag: FALSE");
23395 case DW_FORM_flag_present
:
23396 fprintf_unfiltered (f
, "flag: TRUE");
23398 case DW_FORM_indirect
:
23399 /* The reader will have reduced the indirect form to
23400 the "base form" so this form should not occur. */
23401 fprintf_unfiltered (f
,
23402 "unexpected attribute form: DW_FORM_indirect");
23404 case DW_FORM_implicit_const
:
23405 fprintf_unfiltered (f
, "constant: %s",
23406 plongest (DW_SND (&die
->attrs
[i
])));
23409 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23410 die
->attrs
[i
].form
);
23413 fprintf_unfiltered (f
, "\n");
23418 dump_die_for_error (struct die_info
*die
)
23420 dump_die_shallow (gdb_stderr
, 0, die
);
23424 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23426 int indent
= level
* 4;
23428 gdb_assert (die
!= NULL
);
23430 if (level
>= max_level
)
23433 dump_die_shallow (f
, indent
, die
);
23435 if (die
->child
!= NULL
)
23437 print_spaces (indent
, f
);
23438 fprintf_unfiltered (f
, " Children:");
23439 if (level
+ 1 < max_level
)
23441 fprintf_unfiltered (f
, "\n");
23442 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23446 fprintf_unfiltered (f
,
23447 " [not printed, max nesting level reached]\n");
23451 if (die
->sibling
!= NULL
&& level
> 0)
23453 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23457 /* This is called from the pdie macro in gdbinit.in.
23458 It's not static so gcc will keep a copy callable from gdb. */
23461 dump_die (struct die_info
*die
, int max_level
)
23463 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23467 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23471 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23472 to_underlying (die
->sect_off
),
23478 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23482 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23484 if (attr_form_is_ref (attr
))
23485 return (sect_offset
) DW_UNSND (attr
);
23487 complaint (_("unsupported die ref attribute form: '%s'"),
23488 dwarf_form_name (attr
->form
));
23492 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23493 * the value held by the attribute is not constant. */
23496 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23498 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23499 return DW_SND (attr
);
23500 else if (attr
->form
== DW_FORM_udata
23501 || attr
->form
== DW_FORM_data1
23502 || attr
->form
== DW_FORM_data2
23503 || attr
->form
== DW_FORM_data4
23504 || attr
->form
== DW_FORM_data8
)
23505 return DW_UNSND (attr
);
23508 /* For DW_FORM_data16 see attr_form_is_constant. */
23509 complaint (_("Attribute value is not a constant (%s)"),
23510 dwarf_form_name (attr
->form
));
23511 return default_value
;
23515 /* Follow reference or signature attribute ATTR of SRC_DIE.
23516 On entry *REF_CU is the CU of SRC_DIE.
23517 On exit *REF_CU is the CU of the result. */
23519 static struct die_info
*
23520 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23521 struct dwarf2_cu
**ref_cu
)
23523 struct die_info
*die
;
23525 if (attr_form_is_ref (attr
))
23526 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23527 else if (attr
->form
== DW_FORM_ref_sig8
)
23528 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23531 dump_die_for_error (src_die
);
23532 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23533 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23539 /* Follow reference OFFSET.
23540 On entry *REF_CU is the CU of the source die referencing OFFSET.
23541 On exit *REF_CU is the CU of the result.
23542 Returns NULL if OFFSET is invalid. */
23544 static struct die_info
*
23545 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23546 struct dwarf2_cu
**ref_cu
)
23548 struct die_info temp_die
;
23549 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23550 struct dwarf2_per_objfile
*dwarf2_per_objfile
23551 = cu
->per_cu
->dwarf2_per_objfile
;
23553 gdb_assert (cu
->per_cu
!= NULL
);
23557 if (cu
->per_cu
->is_debug_types
)
23559 /* .debug_types CUs cannot reference anything outside their CU.
23560 If they need to, they have to reference a signatured type via
23561 DW_FORM_ref_sig8. */
23562 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23565 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23566 || !offset_in_cu_p (&cu
->header
, sect_off
))
23568 struct dwarf2_per_cu_data
*per_cu
;
23570 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23571 dwarf2_per_objfile
);
23573 /* If necessary, add it to the queue and load its DIEs. */
23574 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23575 load_full_comp_unit (per_cu
, false, cu
->language
);
23577 target_cu
= per_cu
->cu
;
23579 else if (cu
->dies
== NULL
)
23581 /* We're loading full DIEs during partial symbol reading. */
23582 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23583 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23586 *ref_cu
= target_cu
;
23587 temp_die
.sect_off
= sect_off
;
23589 if (target_cu
!= cu
)
23590 target_cu
->ancestor
= cu
;
23592 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23594 to_underlying (sect_off
));
23597 /* Follow reference attribute ATTR of SRC_DIE.
23598 On entry *REF_CU is the CU of SRC_DIE.
23599 On exit *REF_CU is the CU of the result. */
23601 static struct die_info
*
23602 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23603 struct dwarf2_cu
**ref_cu
)
23605 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23606 struct dwarf2_cu
*cu
= *ref_cu
;
23607 struct die_info
*die
;
23609 die
= follow_die_offset (sect_off
,
23610 (attr
->form
== DW_FORM_GNU_ref_alt
23611 || cu
->per_cu
->is_dwz
),
23614 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23615 "at %s [in module %s]"),
23616 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23617 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23622 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23623 Returned value is intended for DW_OP_call*. Returned
23624 dwarf2_locexpr_baton->data has lifetime of
23625 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23627 struct dwarf2_locexpr_baton
23628 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23629 struct dwarf2_per_cu_data
*per_cu
,
23630 CORE_ADDR (*get_frame_pc
) (void *baton
),
23631 void *baton
, bool resolve_abstract_p
)
23633 struct dwarf2_cu
*cu
;
23634 struct die_info
*die
;
23635 struct attribute
*attr
;
23636 struct dwarf2_locexpr_baton retval
;
23637 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23638 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23640 if (per_cu
->cu
== NULL
)
23641 load_cu (per_cu
, false);
23645 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23646 Instead just throw an error, not much else we can do. */
23647 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23648 sect_offset_str (sect_off
), objfile_name (objfile
));
23651 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23653 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23654 sect_offset_str (sect_off
), objfile_name (objfile
));
23656 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23657 if (!attr
&& resolve_abstract_p
23658 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23659 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23661 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23663 = ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23664 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23666 for (const auto &cand_off
23667 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23669 struct dwarf2_cu
*cand_cu
= cu
;
23670 struct die_info
*cand
23671 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23674 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23677 CORE_ADDR pc_low
, pc_high
;
23678 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23679 if (pc_low
== ((CORE_ADDR
) -1))
23681 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23682 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23683 if (!(pc_low
<= pc
&& pc
< pc_high
))
23687 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23694 /* DWARF: "If there is no such attribute, then there is no effect.".
23695 DATA is ignored if SIZE is 0. */
23697 retval
.data
= NULL
;
23700 else if (attr_form_is_section_offset (attr
))
23702 struct dwarf2_loclist_baton loclist_baton
;
23703 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23706 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23708 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23710 retval
.size
= size
;
23714 if (!attr_form_is_block (attr
))
23715 error (_("Dwarf Error: DIE at %s referenced in module %s "
23716 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23717 sect_offset_str (sect_off
), objfile_name (objfile
));
23719 retval
.data
= DW_BLOCK (attr
)->data
;
23720 retval
.size
= DW_BLOCK (attr
)->size
;
23722 retval
.per_cu
= cu
->per_cu
;
23724 age_cached_comp_units (dwarf2_per_objfile
);
23729 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23732 struct dwarf2_locexpr_baton
23733 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23734 struct dwarf2_per_cu_data
*per_cu
,
23735 CORE_ADDR (*get_frame_pc
) (void *baton
),
23738 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23740 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23743 /* Write a constant of a given type as target-ordered bytes into
23746 static const gdb_byte
*
23747 write_constant_as_bytes (struct obstack
*obstack
,
23748 enum bfd_endian byte_order
,
23755 *len
= TYPE_LENGTH (type
);
23756 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23757 store_unsigned_integer (result
, *len
, byte_order
, value
);
23762 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23763 pointer to the constant bytes and set LEN to the length of the
23764 data. If memory is needed, allocate it on OBSTACK. If the DIE
23765 does not have a DW_AT_const_value, return NULL. */
23768 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23769 struct dwarf2_per_cu_data
*per_cu
,
23770 struct obstack
*obstack
,
23773 struct dwarf2_cu
*cu
;
23774 struct die_info
*die
;
23775 struct attribute
*attr
;
23776 const gdb_byte
*result
= NULL
;
23779 enum bfd_endian byte_order
;
23780 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23782 if (per_cu
->cu
== NULL
)
23783 load_cu (per_cu
, false);
23787 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23788 Instead just throw an error, not much else we can do. */
23789 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23790 sect_offset_str (sect_off
), objfile_name (objfile
));
23793 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23795 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23796 sect_offset_str (sect_off
), objfile_name (objfile
));
23798 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23802 byte_order
= (bfd_big_endian (objfile
->obfd
)
23803 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23805 switch (attr
->form
)
23808 case DW_FORM_addrx
:
23809 case DW_FORM_GNU_addr_index
:
23813 *len
= cu
->header
.addr_size
;
23814 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23815 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23819 case DW_FORM_string
:
23822 case DW_FORM_GNU_str_index
:
23823 case DW_FORM_GNU_strp_alt
:
23824 /* DW_STRING is already allocated on the objfile obstack, point
23826 result
= (const gdb_byte
*) DW_STRING (attr
);
23827 *len
= strlen (DW_STRING (attr
));
23829 case DW_FORM_block1
:
23830 case DW_FORM_block2
:
23831 case DW_FORM_block4
:
23832 case DW_FORM_block
:
23833 case DW_FORM_exprloc
:
23834 case DW_FORM_data16
:
23835 result
= DW_BLOCK (attr
)->data
;
23836 *len
= DW_BLOCK (attr
)->size
;
23839 /* The DW_AT_const_value attributes are supposed to carry the
23840 symbol's value "represented as it would be on the target
23841 architecture." By the time we get here, it's already been
23842 converted to host endianness, so we just need to sign- or
23843 zero-extend it as appropriate. */
23844 case DW_FORM_data1
:
23845 type
= die_type (die
, cu
);
23846 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23847 if (result
== NULL
)
23848 result
= write_constant_as_bytes (obstack
, byte_order
,
23851 case DW_FORM_data2
:
23852 type
= die_type (die
, cu
);
23853 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23854 if (result
== NULL
)
23855 result
= write_constant_as_bytes (obstack
, byte_order
,
23858 case DW_FORM_data4
:
23859 type
= die_type (die
, cu
);
23860 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23861 if (result
== NULL
)
23862 result
= write_constant_as_bytes (obstack
, byte_order
,
23865 case DW_FORM_data8
:
23866 type
= die_type (die
, cu
);
23867 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23868 if (result
== NULL
)
23869 result
= write_constant_as_bytes (obstack
, byte_order
,
23873 case DW_FORM_sdata
:
23874 case DW_FORM_implicit_const
:
23875 type
= die_type (die
, cu
);
23876 result
= write_constant_as_bytes (obstack
, byte_order
,
23877 type
, DW_SND (attr
), len
);
23880 case DW_FORM_udata
:
23881 type
= die_type (die
, cu
);
23882 result
= write_constant_as_bytes (obstack
, byte_order
,
23883 type
, DW_UNSND (attr
), len
);
23887 complaint (_("unsupported const value attribute form: '%s'"),
23888 dwarf_form_name (attr
->form
));
23895 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23896 valid type for this die is found. */
23899 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23900 struct dwarf2_per_cu_data
*per_cu
)
23902 struct dwarf2_cu
*cu
;
23903 struct die_info
*die
;
23905 if (per_cu
->cu
== NULL
)
23906 load_cu (per_cu
, false);
23911 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23915 return die_type (die
, cu
);
23918 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23922 dwarf2_get_die_type (cu_offset die_offset
,
23923 struct dwarf2_per_cu_data
*per_cu
)
23925 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23926 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23929 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23930 On entry *REF_CU is the CU of SRC_DIE.
23931 On exit *REF_CU is the CU of the result.
23932 Returns NULL if the referenced DIE isn't found. */
23934 static struct die_info
*
23935 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23936 struct dwarf2_cu
**ref_cu
)
23938 struct die_info temp_die
;
23939 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23940 struct die_info
*die
;
23942 /* While it might be nice to assert sig_type->type == NULL here,
23943 we can get here for DW_AT_imported_declaration where we need
23944 the DIE not the type. */
23946 /* If necessary, add it to the queue and load its DIEs. */
23948 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23949 read_signatured_type (sig_type
);
23951 sig_cu
= sig_type
->per_cu
.cu
;
23952 gdb_assert (sig_cu
!= NULL
);
23953 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23954 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23955 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23956 to_underlying (temp_die
.sect_off
));
23959 struct dwarf2_per_objfile
*dwarf2_per_objfile
23960 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23962 /* For .gdb_index version 7 keep track of included TUs.
23963 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23964 if (dwarf2_per_objfile
->index_table
!= NULL
23965 && dwarf2_per_objfile
->index_table
->version
<= 7)
23967 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23972 sig_cu
->ancestor
= cu
;
23980 /* Follow signatured type referenced by ATTR in SRC_DIE.
23981 On entry *REF_CU is the CU of SRC_DIE.
23982 On exit *REF_CU is the CU of the result.
23983 The result is the DIE of the type.
23984 If the referenced type cannot be found an error is thrown. */
23986 static struct die_info
*
23987 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23988 struct dwarf2_cu
**ref_cu
)
23990 ULONGEST signature
= DW_SIGNATURE (attr
);
23991 struct signatured_type
*sig_type
;
23992 struct die_info
*die
;
23994 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23996 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23997 /* sig_type will be NULL if the signatured type is missing from
23999 if (sig_type
== NULL
)
24001 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24002 " from DIE at %s [in module %s]"),
24003 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24004 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
24007 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
24010 dump_die_for_error (src_die
);
24011 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24012 " from DIE at %s [in module %s]"),
24013 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24014 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
24020 /* Get the type specified by SIGNATURE referenced in DIE/CU,
24021 reading in and processing the type unit if necessary. */
24023 static struct type
*
24024 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
24025 struct dwarf2_cu
*cu
)
24027 struct dwarf2_per_objfile
*dwarf2_per_objfile
24028 = cu
->per_cu
->dwarf2_per_objfile
;
24029 struct signatured_type
*sig_type
;
24030 struct dwarf2_cu
*type_cu
;
24031 struct die_info
*type_die
;
24034 sig_type
= lookup_signatured_type (cu
, signature
);
24035 /* sig_type will be NULL if the signatured type is missing from
24037 if (sig_type
== NULL
)
24039 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24040 " from DIE at %s [in module %s]"),
24041 hex_string (signature
), sect_offset_str (die
->sect_off
),
24042 objfile_name (dwarf2_per_objfile
->objfile
));
24043 return build_error_marker_type (cu
, die
);
24046 /* If we already know the type we're done. */
24047 if (sig_type
->type
!= NULL
)
24048 return sig_type
->type
;
24051 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24052 if (type_die
!= NULL
)
24054 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24055 is created. This is important, for example, because for c++ classes
24056 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24057 type
= read_type_die (type_die
, type_cu
);
24060 complaint (_("Dwarf Error: Cannot build signatured type %s"
24061 " referenced from DIE at %s [in module %s]"),
24062 hex_string (signature
), sect_offset_str (die
->sect_off
),
24063 objfile_name (dwarf2_per_objfile
->objfile
));
24064 type
= build_error_marker_type (cu
, die
);
24069 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24070 " from DIE at %s [in module %s]"),
24071 hex_string (signature
), sect_offset_str (die
->sect_off
),
24072 objfile_name (dwarf2_per_objfile
->objfile
));
24073 type
= build_error_marker_type (cu
, die
);
24075 sig_type
->type
= type
;
24080 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24081 reading in and processing the type unit if necessary. */
24083 static struct type
*
24084 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24085 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24087 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24088 if (attr_form_is_ref (attr
))
24090 struct dwarf2_cu
*type_cu
= cu
;
24091 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24093 return read_type_die (type_die
, type_cu
);
24095 else if (attr
->form
== DW_FORM_ref_sig8
)
24097 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
24101 struct dwarf2_per_objfile
*dwarf2_per_objfile
24102 = cu
->per_cu
->dwarf2_per_objfile
;
24104 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24105 " at %s [in module %s]"),
24106 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24107 objfile_name (dwarf2_per_objfile
->objfile
));
24108 return build_error_marker_type (cu
, die
);
24112 /* Load the DIEs associated with type unit PER_CU into memory. */
24115 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
24117 struct signatured_type
*sig_type
;
24119 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24120 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
24122 /* We have the per_cu, but we need the signatured_type.
24123 Fortunately this is an easy translation. */
24124 gdb_assert (per_cu
->is_debug_types
);
24125 sig_type
= (struct signatured_type
*) per_cu
;
24127 gdb_assert (per_cu
->cu
== NULL
);
24129 read_signatured_type (sig_type
);
24131 gdb_assert (per_cu
->cu
!= NULL
);
24134 /* die_reader_func for read_signatured_type.
24135 This is identical to load_full_comp_unit_reader,
24136 but is kept separate for now. */
24139 read_signatured_type_reader (const struct die_reader_specs
*reader
,
24140 const gdb_byte
*info_ptr
,
24141 struct die_info
*comp_unit_die
,
24145 struct dwarf2_cu
*cu
= reader
->cu
;
24147 gdb_assert (cu
->die_hash
== NULL
);
24149 htab_create_alloc_ex (cu
->header
.length
/ 12,
24153 &cu
->comp_unit_obstack
,
24154 hashtab_obstack_allocate
,
24155 dummy_obstack_deallocate
);
24158 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
24159 &info_ptr
, comp_unit_die
);
24160 cu
->dies
= comp_unit_die
;
24161 /* comp_unit_die is not stored in die_hash, no need. */
24163 /* We try not to read any attributes in this function, because not
24164 all CUs needed for references have been loaded yet, and symbol
24165 table processing isn't initialized. But we have to set the CU language,
24166 or we won't be able to build types correctly.
24167 Similarly, if we do not read the producer, we can not apply
24168 producer-specific interpretation. */
24169 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24172 /* Read in a signatured type and build its CU and DIEs.
24173 If the type is a stub for the real type in a DWO file,
24174 read in the real type from the DWO file as well. */
24177 read_signatured_type (struct signatured_type
*sig_type
)
24179 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24181 gdb_assert (per_cu
->is_debug_types
);
24182 gdb_assert (per_cu
->cu
== NULL
);
24184 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
24185 read_signatured_type_reader
, NULL
);
24186 sig_type
->per_cu
.tu_read
= 1;
24189 /* Decode simple location descriptions.
24190 Given a pointer to a dwarf block that defines a location, compute
24191 the location and return the value.
24193 NOTE drow/2003-11-18: This function is called in two situations
24194 now: for the address of static or global variables (partial symbols
24195 only) and for offsets into structures which are expected to be
24196 (more or less) constant. The partial symbol case should go away,
24197 and only the constant case should remain. That will let this
24198 function complain more accurately. A few special modes are allowed
24199 without complaint for global variables (for instance, global
24200 register values and thread-local values).
24202 A location description containing no operations indicates that the
24203 object is optimized out. The return value is 0 for that case.
24204 FIXME drow/2003-11-16: No callers check for this case any more; soon all
24205 callers will only want a very basic result and this can become a
24208 Note that stack[0] is unused except as a default error return. */
24211 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
24213 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
24215 size_t size
= blk
->size
;
24216 const gdb_byte
*data
= blk
->data
;
24217 CORE_ADDR stack
[64];
24219 unsigned int bytes_read
, unsnd
;
24225 stack
[++stacki
] = 0;
24264 stack
[++stacki
] = op
- DW_OP_lit0
;
24299 stack
[++stacki
] = op
- DW_OP_reg0
;
24301 dwarf2_complex_location_expr_complaint ();
24305 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24307 stack
[++stacki
] = unsnd
;
24309 dwarf2_complex_location_expr_complaint ();
24313 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24318 case DW_OP_const1u
:
24319 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24323 case DW_OP_const1s
:
24324 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24328 case DW_OP_const2u
:
24329 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24333 case DW_OP_const2s
:
24334 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24338 case DW_OP_const4u
:
24339 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24343 case DW_OP_const4s
:
24344 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24348 case DW_OP_const8u
:
24349 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24354 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24360 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24365 stack
[stacki
+ 1] = stack
[stacki
];
24370 stack
[stacki
- 1] += stack
[stacki
];
24374 case DW_OP_plus_uconst
:
24375 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24381 stack
[stacki
- 1] -= stack
[stacki
];
24386 /* If we're not the last op, then we definitely can't encode
24387 this using GDB's address_class enum. This is valid for partial
24388 global symbols, although the variable's address will be bogus
24391 dwarf2_complex_location_expr_complaint ();
24394 case DW_OP_GNU_push_tls_address
:
24395 case DW_OP_form_tls_address
:
24396 /* The top of the stack has the offset from the beginning
24397 of the thread control block at which the variable is located. */
24398 /* Nothing should follow this operator, so the top of stack would
24400 /* This is valid for partial global symbols, but the variable's
24401 address will be bogus in the psymtab. Make it always at least
24402 non-zero to not look as a variable garbage collected by linker
24403 which have DW_OP_addr 0. */
24405 dwarf2_complex_location_expr_complaint ();
24409 case DW_OP_GNU_uninit
:
24413 case DW_OP_GNU_addr_index
:
24414 case DW_OP_GNU_const_index
:
24415 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24422 const char *name
= get_DW_OP_name (op
);
24425 complaint (_("unsupported stack op: '%s'"),
24428 complaint (_("unsupported stack op: '%02x'"),
24432 return (stack
[stacki
]);
24435 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24436 outside of the allocated space. Also enforce minimum>0. */
24437 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24439 complaint (_("location description stack overflow"));
24445 complaint (_("location description stack underflow"));
24449 return (stack
[stacki
]);
24452 /* memory allocation interface */
24454 static struct dwarf_block
*
24455 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24457 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24460 static struct die_info
*
24461 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24463 struct die_info
*die
;
24464 size_t size
= sizeof (struct die_info
);
24467 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24469 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24470 memset (die
, 0, sizeof (struct die_info
));
24475 /* Macro support. */
24477 /* Return file name relative to the compilation directory of file number I in
24478 *LH's file name table. The result is allocated using xmalloc; the caller is
24479 responsible for freeing it. */
24482 file_file_name (int file
, struct line_header
*lh
)
24484 /* Is the file number a valid index into the line header's file name
24485 table? Remember that file numbers start with one, not zero. */
24486 if (lh
->is_valid_file_index (file
))
24488 const file_entry
*fe
= lh
->file_name_at (file
);
24490 if (!IS_ABSOLUTE_PATH (fe
->name
))
24492 const char *dir
= fe
->include_dir (lh
);
24494 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24496 return xstrdup (fe
->name
);
24500 /* The compiler produced a bogus file number. We can at least
24501 record the macro definitions made in the file, even if we
24502 won't be able to find the file by name. */
24503 char fake_name
[80];
24505 xsnprintf (fake_name
, sizeof (fake_name
),
24506 "<bad macro file number %d>", file
);
24508 complaint (_("bad file number in macro information (%d)"),
24511 return xstrdup (fake_name
);
24515 /* Return the full name of file number I in *LH's file name table.
24516 Use COMP_DIR as the name of the current directory of the
24517 compilation. The result is allocated using xmalloc; the caller is
24518 responsible for freeing it. */
24520 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24522 /* Is the file number a valid index into the line header's file name
24523 table? Remember that file numbers start with one, not zero. */
24524 if (lh
->is_valid_file_index (file
))
24526 char *relative
= file_file_name (file
, lh
);
24528 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24530 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24531 relative
, (char *) NULL
);
24534 return file_file_name (file
, lh
);
24538 static struct macro_source_file
*
24539 macro_start_file (struct dwarf2_cu
*cu
,
24540 int file
, int line
,
24541 struct macro_source_file
*current_file
,
24542 struct line_header
*lh
)
24544 /* File name relative to the compilation directory of this source file. */
24545 char *file_name
= file_file_name (file
, lh
);
24547 if (! current_file
)
24549 /* Note: We don't create a macro table for this compilation unit
24550 at all until we actually get a filename. */
24551 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24553 /* If we have no current file, then this must be the start_file
24554 directive for the compilation unit's main source file. */
24555 current_file
= macro_set_main (macro_table
, file_name
);
24556 macro_define_special (macro_table
);
24559 current_file
= macro_include (current_file
, line
, file_name
);
24563 return current_file
;
24566 static const char *
24567 consume_improper_spaces (const char *p
, const char *body
)
24571 complaint (_("macro definition contains spaces "
24572 "in formal argument list:\n`%s'"),
24584 parse_macro_definition (struct macro_source_file
*file
, int line
,
24589 /* The body string takes one of two forms. For object-like macro
24590 definitions, it should be:
24592 <macro name> " " <definition>
24594 For function-like macro definitions, it should be:
24596 <macro name> "() " <definition>
24598 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24600 Spaces may appear only where explicitly indicated, and in the
24603 The Dwarf 2 spec says that an object-like macro's name is always
24604 followed by a space, but versions of GCC around March 2002 omit
24605 the space when the macro's definition is the empty string.
24607 The Dwarf 2 spec says that there should be no spaces between the
24608 formal arguments in a function-like macro's formal argument list,
24609 but versions of GCC around March 2002 include spaces after the
24613 /* Find the extent of the macro name. The macro name is terminated
24614 by either a space or null character (for an object-like macro) or
24615 an opening paren (for a function-like macro). */
24616 for (p
= body
; *p
; p
++)
24617 if (*p
== ' ' || *p
== '(')
24620 if (*p
== ' ' || *p
== '\0')
24622 /* It's an object-like macro. */
24623 int name_len
= p
- body
;
24624 char *name
= savestring (body
, name_len
);
24625 const char *replacement
;
24628 replacement
= body
+ name_len
+ 1;
24631 dwarf2_macro_malformed_definition_complaint (body
);
24632 replacement
= body
+ name_len
;
24635 macro_define_object (file
, line
, name
, replacement
);
24639 else if (*p
== '(')
24641 /* It's a function-like macro. */
24642 char *name
= savestring (body
, p
- body
);
24645 char **argv
= XNEWVEC (char *, argv_size
);
24649 p
= consume_improper_spaces (p
, body
);
24651 /* Parse the formal argument list. */
24652 while (*p
&& *p
!= ')')
24654 /* Find the extent of the current argument name. */
24655 const char *arg_start
= p
;
24657 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24660 if (! *p
|| p
== arg_start
)
24661 dwarf2_macro_malformed_definition_complaint (body
);
24664 /* Make sure argv has room for the new argument. */
24665 if (argc
>= argv_size
)
24668 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24671 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24674 p
= consume_improper_spaces (p
, body
);
24676 /* Consume the comma, if present. */
24681 p
= consume_improper_spaces (p
, body
);
24690 /* Perfectly formed definition, no complaints. */
24691 macro_define_function (file
, line
, name
,
24692 argc
, (const char **) argv
,
24694 else if (*p
== '\0')
24696 /* Complain, but do define it. */
24697 dwarf2_macro_malformed_definition_complaint (body
);
24698 macro_define_function (file
, line
, name
,
24699 argc
, (const char **) argv
,
24703 /* Just complain. */
24704 dwarf2_macro_malformed_definition_complaint (body
);
24707 /* Just complain. */
24708 dwarf2_macro_malformed_definition_complaint (body
);
24714 for (i
= 0; i
< argc
; i
++)
24720 dwarf2_macro_malformed_definition_complaint (body
);
24723 /* Skip some bytes from BYTES according to the form given in FORM.
24724 Returns the new pointer. */
24726 static const gdb_byte
*
24727 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24728 enum dwarf_form form
,
24729 unsigned int offset_size
,
24730 struct dwarf2_section_info
*section
)
24732 unsigned int bytes_read
;
24736 case DW_FORM_data1
:
24741 case DW_FORM_data2
:
24745 case DW_FORM_data4
:
24749 case DW_FORM_data8
:
24753 case DW_FORM_data16
:
24757 case DW_FORM_string
:
24758 read_direct_string (abfd
, bytes
, &bytes_read
);
24759 bytes
+= bytes_read
;
24762 case DW_FORM_sec_offset
:
24764 case DW_FORM_GNU_strp_alt
:
24765 bytes
+= offset_size
;
24768 case DW_FORM_block
:
24769 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24770 bytes
+= bytes_read
;
24773 case DW_FORM_block1
:
24774 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24776 case DW_FORM_block2
:
24777 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24779 case DW_FORM_block4
:
24780 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24783 case DW_FORM_addrx
:
24784 case DW_FORM_sdata
:
24786 case DW_FORM_udata
:
24787 case DW_FORM_GNU_addr_index
:
24788 case DW_FORM_GNU_str_index
:
24789 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24792 dwarf2_section_buffer_overflow_complaint (section
);
24797 case DW_FORM_implicit_const
:
24802 complaint (_("invalid form 0x%x in `%s'"),
24803 form
, get_section_name (section
));
24811 /* A helper for dwarf_decode_macros that handles skipping an unknown
24812 opcode. Returns an updated pointer to the macro data buffer; or,
24813 on error, issues a complaint and returns NULL. */
24815 static const gdb_byte
*
24816 skip_unknown_opcode (unsigned int opcode
,
24817 const gdb_byte
**opcode_definitions
,
24818 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24820 unsigned int offset_size
,
24821 struct dwarf2_section_info
*section
)
24823 unsigned int bytes_read
, i
;
24825 const gdb_byte
*defn
;
24827 if (opcode_definitions
[opcode
] == NULL
)
24829 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24834 defn
= opcode_definitions
[opcode
];
24835 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24836 defn
+= bytes_read
;
24838 for (i
= 0; i
< arg
; ++i
)
24840 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24841 (enum dwarf_form
) defn
[i
], offset_size
,
24843 if (mac_ptr
== NULL
)
24845 /* skip_form_bytes already issued the complaint. */
24853 /* A helper function which parses the header of a macro section.
24854 If the macro section is the extended (for now called "GNU") type,
24855 then this updates *OFFSET_SIZE. Returns a pointer to just after
24856 the header, or issues a complaint and returns NULL on error. */
24858 static const gdb_byte
*
24859 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24861 const gdb_byte
*mac_ptr
,
24862 unsigned int *offset_size
,
24863 int section_is_gnu
)
24865 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24867 if (section_is_gnu
)
24869 unsigned int version
, flags
;
24871 version
= read_2_bytes (abfd
, mac_ptr
);
24872 if (version
!= 4 && version
!= 5)
24874 complaint (_("unrecognized version `%d' in .debug_macro section"),
24880 flags
= read_1_byte (abfd
, mac_ptr
);
24882 *offset_size
= (flags
& 1) ? 8 : 4;
24884 if ((flags
& 2) != 0)
24885 /* We don't need the line table offset. */
24886 mac_ptr
+= *offset_size
;
24888 /* Vendor opcode descriptions. */
24889 if ((flags
& 4) != 0)
24891 unsigned int i
, count
;
24893 count
= read_1_byte (abfd
, mac_ptr
);
24895 for (i
= 0; i
< count
; ++i
)
24897 unsigned int opcode
, bytes_read
;
24900 opcode
= read_1_byte (abfd
, mac_ptr
);
24902 opcode_definitions
[opcode
] = mac_ptr
;
24903 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24904 mac_ptr
+= bytes_read
;
24913 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24914 including DW_MACRO_import. */
24917 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24919 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24920 struct macro_source_file
*current_file
,
24921 struct line_header
*lh
,
24922 struct dwarf2_section_info
*section
,
24923 int section_is_gnu
, int section_is_dwz
,
24924 unsigned int offset_size
,
24925 htab_t include_hash
)
24927 struct dwarf2_per_objfile
*dwarf2_per_objfile
24928 = cu
->per_cu
->dwarf2_per_objfile
;
24929 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24930 enum dwarf_macro_record_type macinfo_type
;
24931 int at_commandline
;
24932 const gdb_byte
*opcode_definitions
[256];
24934 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24935 &offset_size
, section_is_gnu
);
24936 if (mac_ptr
== NULL
)
24938 /* We already issued a complaint. */
24942 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24943 GDB is still reading the definitions from command line. First
24944 DW_MACINFO_start_file will need to be ignored as it was already executed
24945 to create CURRENT_FILE for the main source holding also the command line
24946 definitions. On first met DW_MACINFO_start_file this flag is reset to
24947 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24949 at_commandline
= 1;
24953 /* Do we at least have room for a macinfo type byte? */
24954 if (mac_ptr
>= mac_end
)
24956 dwarf2_section_buffer_overflow_complaint (section
);
24960 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24963 /* Note that we rely on the fact that the corresponding GNU and
24964 DWARF constants are the same. */
24966 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24967 switch (macinfo_type
)
24969 /* A zero macinfo type indicates the end of the macro
24974 case DW_MACRO_define
:
24975 case DW_MACRO_undef
:
24976 case DW_MACRO_define_strp
:
24977 case DW_MACRO_undef_strp
:
24978 case DW_MACRO_define_sup
:
24979 case DW_MACRO_undef_sup
:
24981 unsigned int bytes_read
;
24986 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24987 mac_ptr
+= bytes_read
;
24989 if (macinfo_type
== DW_MACRO_define
24990 || macinfo_type
== DW_MACRO_undef
)
24992 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24993 mac_ptr
+= bytes_read
;
24997 LONGEST str_offset
;
24999 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25000 mac_ptr
+= offset_size
;
25002 if (macinfo_type
== DW_MACRO_define_sup
25003 || macinfo_type
== DW_MACRO_undef_sup
25006 struct dwz_file
*dwz
25007 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
25009 body
= read_indirect_string_from_dwz (objfile
,
25013 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
25017 is_define
= (macinfo_type
== DW_MACRO_define
25018 || macinfo_type
== DW_MACRO_define_strp
25019 || macinfo_type
== DW_MACRO_define_sup
);
25020 if (! current_file
)
25022 /* DWARF violation as no main source is present. */
25023 complaint (_("debug info with no main source gives macro %s "
25025 is_define
? _("definition") : _("undefinition"),
25029 if ((line
== 0 && !at_commandline
)
25030 || (line
!= 0 && at_commandline
))
25031 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
25032 at_commandline
? _("command-line") : _("in-file"),
25033 is_define
? _("definition") : _("undefinition"),
25034 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
25038 /* Fedora's rpm-build's "debugedit" binary
25039 corrupted .debug_macro sections.
25042 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
25043 complaint (_("debug info gives %s invalid macro %s "
25044 "without body (corrupted?) at line %d "
25046 at_commandline
? _("command-line") : _("in-file"),
25047 is_define
? _("definition") : _("undefinition"),
25048 line
, current_file
->filename
);
25050 else if (is_define
)
25051 parse_macro_definition (current_file
, line
, body
);
25054 gdb_assert (macinfo_type
== DW_MACRO_undef
25055 || macinfo_type
== DW_MACRO_undef_strp
25056 || macinfo_type
== DW_MACRO_undef_sup
);
25057 macro_undef (current_file
, line
, body
);
25062 case DW_MACRO_start_file
:
25064 unsigned int bytes_read
;
25067 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25068 mac_ptr
+= bytes_read
;
25069 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25070 mac_ptr
+= bytes_read
;
25072 if ((line
== 0 && !at_commandline
)
25073 || (line
!= 0 && at_commandline
))
25074 complaint (_("debug info gives source %d included "
25075 "from %s at %s line %d"),
25076 file
, at_commandline
? _("command-line") : _("file"),
25077 line
== 0 ? _("zero") : _("non-zero"), line
);
25079 if (at_commandline
)
25081 /* This DW_MACRO_start_file was executed in the
25083 at_commandline
= 0;
25086 current_file
= macro_start_file (cu
, file
, line
, current_file
,
25091 case DW_MACRO_end_file
:
25092 if (! current_file
)
25093 complaint (_("macro debug info has an unmatched "
25094 "`close_file' directive"));
25097 current_file
= current_file
->included_by
;
25098 if (! current_file
)
25100 enum dwarf_macro_record_type next_type
;
25102 /* GCC circa March 2002 doesn't produce the zero
25103 type byte marking the end of the compilation
25104 unit. Complain if it's not there, but exit no
25107 /* Do we at least have room for a macinfo type byte? */
25108 if (mac_ptr
>= mac_end
)
25110 dwarf2_section_buffer_overflow_complaint (section
);
25114 /* We don't increment mac_ptr here, so this is just
25117 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
25119 if (next_type
!= 0)
25120 complaint (_("no terminating 0-type entry for "
25121 "macros in `.debug_macinfo' section"));
25128 case DW_MACRO_import
:
25129 case DW_MACRO_import_sup
:
25133 bfd
*include_bfd
= abfd
;
25134 struct dwarf2_section_info
*include_section
= section
;
25135 const gdb_byte
*include_mac_end
= mac_end
;
25136 int is_dwz
= section_is_dwz
;
25137 const gdb_byte
*new_mac_ptr
;
25139 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25140 mac_ptr
+= offset_size
;
25142 if (macinfo_type
== DW_MACRO_import_sup
)
25144 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
25146 dwarf2_read_section (objfile
, &dwz
->macro
);
25148 include_section
= &dwz
->macro
;
25149 include_bfd
= get_section_bfd_owner (include_section
);
25150 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
25154 new_mac_ptr
= include_section
->buffer
+ offset
;
25155 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
25159 /* This has actually happened; see
25160 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
25161 complaint (_("recursive DW_MACRO_import in "
25162 ".debug_macro section"));
25166 *slot
= (void *) new_mac_ptr
;
25168 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
25169 include_mac_end
, current_file
, lh
,
25170 section
, section_is_gnu
, is_dwz
,
25171 offset_size
, include_hash
);
25173 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
25178 case DW_MACINFO_vendor_ext
:
25179 if (!section_is_gnu
)
25181 unsigned int bytes_read
;
25183 /* This reads the constant, but since we don't recognize
25184 any vendor extensions, we ignore it. */
25185 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25186 mac_ptr
+= bytes_read
;
25187 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25188 mac_ptr
+= bytes_read
;
25190 /* We don't recognize any vendor extensions. */
25196 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25197 mac_ptr
, mac_end
, abfd
, offset_size
,
25199 if (mac_ptr
== NULL
)
25204 } while (macinfo_type
!= 0);
25208 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25209 int section_is_gnu
)
25211 struct dwarf2_per_objfile
*dwarf2_per_objfile
25212 = cu
->per_cu
->dwarf2_per_objfile
;
25213 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25214 struct line_header
*lh
= cu
->line_header
;
25216 const gdb_byte
*mac_ptr
, *mac_end
;
25217 struct macro_source_file
*current_file
= 0;
25218 enum dwarf_macro_record_type macinfo_type
;
25219 unsigned int offset_size
= cu
->header
.offset_size
;
25220 const gdb_byte
*opcode_definitions
[256];
25222 struct dwarf2_section_info
*section
;
25223 const char *section_name
;
25225 if (cu
->dwo_unit
!= NULL
)
25227 if (section_is_gnu
)
25229 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25230 section_name
= ".debug_macro.dwo";
25234 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25235 section_name
= ".debug_macinfo.dwo";
25240 if (section_is_gnu
)
25242 section
= &dwarf2_per_objfile
->macro
;
25243 section_name
= ".debug_macro";
25247 section
= &dwarf2_per_objfile
->macinfo
;
25248 section_name
= ".debug_macinfo";
25252 dwarf2_read_section (objfile
, section
);
25253 if (section
->buffer
== NULL
)
25255 complaint (_("missing %s section"), section_name
);
25258 abfd
= get_section_bfd_owner (section
);
25260 /* First pass: Find the name of the base filename.
25261 This filename is needed in order to process all macros whose definition
25262 (or undefinition) comes from the command line. These macros are defined
25263 before the first DW_MACINFO_start_file entry, and yet still need to be
25264 associated to the base file.
25266 To determine the base file name, we scan the macro definitions until we
25267 reach the first DW_MACINFO_start_file entry. We then initialize
25268 CURRENT_FILE accordingly so that any macro definition found before the
25269 first DW_MACINFO_start_file can still be associated to the base file. */
25271 mac_ptr
= section
->buffer
+ offset
;
25272 mac_end
= section
->buffer
+ section
->size
;
25274 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25275 &offset_size
, section_is_gnu
);
25276 if (mac_ptr
== NULL
)
25278 /* We already issued a complaint. */
25284 /* Do we at least have room for a macinfo type byte? */
25285 if (mac_ptr
>= mac_end
)
25287 /* Complaint is printed during the second pass as GDB will probably
25288 stop the first pass earlier upon finding
25289 DW_MACINFO_start_file. */
25293 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25296 /* Note that we rely on the fact that the corresponding GNU and
25297 DWARF constants are the same. */
25299 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25300 switch (macinfo_type
)
25302 /* A zero macinfo type indicates the end of the macro
25307 case DW_MACRO_define
:
25308 case DW_MACRO_undef
:
25309 /* Only skip the data by MAC_PTR. */
25311 unsigned int bytes_read
;
25313 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25314 mac_ptr
+= bytes_read
;
25315 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25316 mac_ptr
+= bytes_read
;
25320 case DW_MACRO_start_file
:
25322 unsigned int bytes_read
;
25325 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25326 mac_ptr
+= bytes_read
;
25327 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25328 mac_ptr
+= bytes_read
;
25330 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25334 case DW_MACRO_end_file
:
25335 /* No data to skip by MAC_PTR. */
25338 case DW_MACRO_define_strp
:
25339 case DW_MACRO_undef_strp
:
25340 case DW_MACRO_define_sup
:
25341 case DW_MACRO_undef_sup
:
25343 unsigned int bytes_read
;
25345 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25346 mac_ptr
+= bytes_read
;
25347 mac_ptr
+= offset_size
;
25351 case DW_MACRO_import
:
25352 case DW_MACRO_import_sup
:
25353 /* Note that, according to the spec, a transparent include
25354 chain cannot call DW_MACRO_start_file. So, we can just
25355 skip this opcode. */
25356 mac_ptr
+= offset_size
;
25359 case DW_MACINFO_vendor_ext
:
25360 /* Only skip the data by MAC_PTR. */
25361 if (!section_is_gnu
)
25363 unsigned int bytes_read
;
25365 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25366 mac_ptr
+= bytes_read
;
25367 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25368 mac_ptr
+= bytes_read
;
25373 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25374 mac_ptr
, mac_end
, abfd
, offset_size
,
25376 if (mac_ptr
== NULL
)
25381 } while (macinfo_type
!= 0 && current_file
== NULL
);
25383 /* Second pass: Process all entries.
25385 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25386 command-line macro definitions/undefinitions. This flag is unset when we
25387 reach the first DW_MACINFO_start_file entry. */
25389 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25391 NULL
, xcalloc
, xfree
));
25392 mac_ptr
= section
->buffer
+ offset
;
25393 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25394 *slot
= (void *) mac_ptr
;
25395 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25396 current_file
, lh
, section
,
25397 section_is_gnu
, 0, offset_size
,
25398 include_hash
.get ());
25401 /* Check if the attribute's form is a DW_FORM_block*
25402 if so return true else false. */
25405 attr_form_is_block (const struct attribute
*attr
)
25407 return (attr
== NULL
? 0 :
25408 attr
->form
== DW_FORM_block1
25409 || attr
->form
== DW_FORM_block2
25410 || attr
->form
== DW_FORM_block4
25411 || attr
->form
== DW_FORM_block
25412 || attr
->form
== DW_FORM_exprloc
);
25415 /* Return non-zero if ATTR's value is a section offset --- classes
25416 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25417 You may use DW_UNSND (attr) to retrieve such offsets.
25419 Section 7.5.4, "Attribute Encodings", explains that no attribute
25420 may have a value that belongs to more than one of these classes; it
25421 would be ambiguous if we did, because we use the same forms for all
25425 attr_form_is_section_offset (const struct attribute
*attr
)
25427 return (attr
->form
== DW_FORM_data4
25428 || attr
->form
== DW_FORM_data8
25429 || attr
->form
== DW_FORM_sec_offset
);
25432 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25433 zero otherwise. When this function returns true, you can apply
25434 dwarf2_get_attr_constant_value to it.
25436 However, note that for some attributes you must check
25437 attr_form_is_section_offset before using this test. DW_FORM_data4
25438 and DW_FORM_data8 are members of both the constant class, and of
25439 the classes that contain offsets into other debug sections
25440 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25441 that, if an attribute's can be either a constant or one of the
25442 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25443 taken as section offsets, not constants.
25445 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25446 cannot handle that. */
25449 attr_form_is_constant (const struct attribute
*attr
)
25451 switch (attr
->form
)
25453 case DW_FORM_sdata
:
25454 case DW_FORM_udata
:
25455 case DW_FORM_data1
:
25456 case DW_FORM_data2
:
25457 case DW_FORM_data4
:
25458 case DW_FORM_data8
:
25459 case DW_FORM_implicit_const
:
25467 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25468 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25471 attr_form_is_ref (const struct attribute
*attr
)
25473 switch (attr
->form
)
25475 case DW_FORM_ref_addr
:
25480 case DW_FORM_ref_udata
:
25481 case DW_FORM_GNU_ref_alt
:
25488 /* Return the .debug_loc section to use for CU.
25489 For DWO files use .debug_loc.dwo. */
25491 static struct dwarf2_section_info
*
25492 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25494 struct dwarf2_per_objfile
*dwarf2_per_objfile
25495 = cu
->per_cu
->dwarf2_per_objfile
;
25499 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25501 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25503 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25504 : &dwarf2_per_objfile
->loc
);
25507 /* A helper function that fills in a dwarf2_loclist_baton. */
25510 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25511 struct dwarf2_loclist_baton
*baton
,
25512 const struct attribute
*attr
)
25514 struct dwarf2_per_objfile
*dwarf2_per_objfile
25515 = cu
->per_cu
->dwarf2_per_objfile
;
25516 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25518 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25520 baton
->per_cu
= cu
->per_cu
;
25521 gdb_assert (baton
->per_cu
);
25522 /* We don't know how long the location list is, but make sure we
25523 don't run off the edge of the section. */
25524 baton
->size
= section
->size
- DW_UNSND (attr
);
25525 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25526 baton
->base_address
= cu
->base_address
;
25527 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25531 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25532 struct dwarf2_cu
*cu
, int is_block
)
25534 struct dwarf2_per_objfile
*dwarf2_per_objfile
25535 = cu
->per_cu
->dwarf2_per_objfile
;
25536 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25537 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25539 if (attr_form_is_section_offset (attr
)
25540 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25541 the section. If so, fall through to the complaint in the
25543 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25545 struct dwarf2_loclist_baton
*baton
;
25547 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25549 fill_in_loclist_baton (cu
, baton
, attr
);
25551 if (cu
->base_known
== 0)
25552 complaint (_("Location list used without "
25553 "specifying the CU base address."));
25555 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25556 ? dwarf2_loclist_block_index
25557 : dwarf2_loclist_index
);
25558 SYMBOL_LOCATION_BATON (sym
) = baton
;
25562 struct dwarf2_locexpr_baton
*baton
;
25564 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25565 baton
->per_cu
= cu
->per_cu
;
25566 gdb_assert (baton
->per_cu
);
25568 if (attr_form_is_block (attr
))
25570 /* Note that we're just copying the block's data pointer
25571 here, not the actual data. We're still pointing into the
25572 info_buffer for SYM's objfile; right now we never release
25573 that buffer, but when we do clean up properly this may
25575 baton
->size
= DW_BLOCK (attr
)->size
;
25576 baton
->data
= DW_BLOCK (attr
)->data
;
25580 dwarf2_invalid_attrib_class_complaint ("location description",
25581 sym
->natural_name ());
25585 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25586 ? dwarf2_locexpr_block_index
25587 : dwarf2_locexpr_index
);
25588 SYMBOL_LOCATION_BATON (sym
) = baton
;
25592 /* Return the OBJFILE associated with the compilation unit CU. If CU
25593 came from a separate debuginfo file, then the master objfile is
25597 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25599 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25601 /* Return the master objfile, so that we can report and look up the
25602 correct file containing this variable. */
25603 if (objfile
->separate_debug_objfile_backlink
)
25604 objfile
= objfile
->separate_debug_objfile_backlink
;
25609 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25610 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25611 CU_HEADERP first. */
25613 static const struct comp_unit_head
*
25614 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25615 struct dwarf2_per_cu_data
*per_cu
)
25617 const gdb_byte
*info_ptr
;
25620 return &per_cu
->cu
->header
;
25622 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25624 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25625 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25626 rcuh_kind::COMPILE
);
25631 /* Return the address size given in the compilation unit header for CU. */
25634 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25636 struct comp_unit_head cu_header_local
;
25637 const struct comp_unit_head
*cu_headerp
;
25639 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25641 return cu_headerp
->addr_size
;
25644 /* Return the offset size given in the compilation unit header for CU. */
25647 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25649 struct comp_unit_head cu_header_local
;
25650 const struct comp_unit_head
*cu_headerp
;
25652 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25654 return cu_headerp
->offset_size
;
25657 /* See its dwarf2loc.h declaration. */
25660 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25662 struct comp_unit_head cu_header_local
;
25663 const struct comp_unit_head
*cu_headerp
;
25665 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25667 if (cu_headerp
->version
== 2)
25668 return cu_headerp
->addr_size
;
25670 return cu_headerp
->offset_size
;
25673 /* Return the text offset of the CU. The returned offset comes from
25674 this CU's objfile. If this objfile came from a separate debuginfo
25675 file, then the offset may be different from the corresponding
25676 offset in the parent objfile. */
25679 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25681 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25683 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25686 /* Return a type that is a generic pointer type, the size of which matches
25687 the address size given in the compilation unit header for PER_CU. */
25688 static struct type
*
25689 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25691 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25692 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25693 struct type
*addr_type
= lookup_pointer_type (void_type
);
25694 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25696 if (TYPE_LENGTH (addr_type
) == addr_size
)
25700 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25704 /* Return DWARF version number of PER_CU. */
25707 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25709 return per_cu
->dwarf_version
;
25712 /* Locate the .debug_info compilation unit from CU's objfile which contains
25713 the DIE at OFFSET. Raises an error on failure. */
25715 static struct dwarf2_per_cu_data
*
25716 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25717 unsigned int offset_in_dwz
,
25718 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25720 struct dwarf2_per_cu_data
*this_cu
;
25724 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25727 struct dwarf2_per_cu_data
*mid_cu
;
25728 int mid
= low
+ (high
- low
) / 2;
25730 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25731 if (mid_cu
->is_dwz
> offset_in_dwz
25732 || (mid_cu
->is_dwz
== offset_in_dwz
25733 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25738 gdb_assert (low
== high
);
25739 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25740 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25742 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25743 error (_("Dwarf Error: could not find partial DIE containing "
25744 "offset %s [in module %s]"),
25745 sect_offset_str (sect_off
),
25746 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25748 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25750 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25754 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25755 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25756 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25757 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25762 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25764 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25765 : per_cu (per_cu_
),
25767 has_loclist (false),
25768 checked_producer (false),
25769 producer_is_gxx_lt_4_6 (false),
25770 producer_is_gcc_lt_4_3 (false),
25771 producer_is_icc (false),
25772 producer_is_icc_lt_14 (false),
25773 producer_is_codewarrior (false),
25774 processing_has_namespace_info (false)
25779 /* Destroy a dwarf2_cu. */
25781 dwarf2_cu::~dwarf2_cu ()
25786 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25789 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25790 enum language pretend_language
)
25792 struct attribute
*attr
;
25794 /* Set the language we're debugging. */
25795 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25796 if (attr
!= nullptr)
25797 set_cu_language (DW_UNSND (attr
), cu
);
25800 cu
->language
= pretend_language
;
25801 cu
->language_defn
= language_def (cu
->language
);
25804 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25807 /* Increase the age counter on each cached compilation unit, and free
25808 any that are too old. */
25811 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25813 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25815 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25816 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25817 while (per_cu
!= NULL
)
25819 per_cu
->cu
->last_used
++;
25820 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25821 dwarf2_mark (per_cu
->cu
);
25822 per_cu
= per_cu
->cu
->read_in_chain
;
25825 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25826 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25827 while (per_cu
!= NULL
)
25829 struct dwarf2_per_cu_data
*next_cu
;
25831 next_cu
= per_cu
->cu
->read_in_chain
;
25833 if (!per_cu
->cu
->mark
)
25836 *last_chain
= next_cu
;
25839 last_chain
= &per_cu
->cu
->read_in_chain
;
25845 /* Remove a single compilation unit from the cache. */
25848 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25850 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25851 struct dwarf2_per_objfile
*dwarf2_per_objfile
25852 = target_per_cu
->dwarf2_per_objfile
;
25854 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25855 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25856 while (per_cu
!= NULL
)
25858 struct dwarf2_per_cu_data
*next_cu
;
25860 next_cu
= per_cu
->cu
->read_in_chain
;
25862 if (per_cu
== target_per_cu
)
25866 *last_chain
= next_cu
;
25870 last_chain
= &per_cu
->cu
->read_in_chain
;
25876 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25877 We store these in a hash table separate from the DIEs, and preserve them
25878 when the DIEs are flushed out of cache.
25880 The CU "per_cu" pointer is needed because offset alone is not enough to
25881 uniquely identify the type. A file may have multiple .debug_types sections,
25882 or the type may come from a DWO file. Furthermore, while it's more logical
25883 to use per_cu->section+offset, with Fission the section with the data is in
25884 the DWO file but we don't know that section at the point we need it.
25885 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25886 because we can enter the lookup routine, get_die_type_at_offset, from
25887 outside this file, and thus won't necessarily have PER_CU->cu.
25888 Fortunately, PER_CU is stable for the life of the objfile. */
25890 struct dwarf2_per_cu_offset_and_type
25892 const struct dwarf2_per_cu_data
*per_cu
;
25893 sect_offset sect_off
;
25897 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25900 per_cu_offset_and_type_hash (const void *item
)
25902 const struct dwarf2_per_cu_offset_and_type
*ofs
25903 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25905 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25908 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25911 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25913 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25914 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25915 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25916 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25918 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25919 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25922 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25923 table if necessary. For convenience, return TYPE.
25925 The DIEs reading must have careful ordering to:
25926 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25927 reading current DIE.
25928 * Not trying to dereference contents of still incompletely read in types
25929 while reading in other DIEs.
25930 * Enable referencing still incompletely read in types just by a pointer to
25931 the type without accessing its fields.
25933 Therefore caller should follow these rules:
25934 * Try to fetch any prerequisite types we may need to build this DIE type
25935 before building the type and calling set_die_type.
25936 * After building type call set_die_type for current DIE as soon as
25937 possible before fetching more types to complete the current type.
25938 * Make the type as complete as possible before fetching more types. */
25940 static struct type
*
25941 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25943 struct dwarf2_per_objfile
*dwarf2_per_objfile
25944 = cu
->per_cu
->dwarf2_per_objfile
;
25945 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25946 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25947 struct attribute
*attr
;
25948 struct dynamic_prop prop
;
25950 /* For Ada types, make sure that the gnat-specific data is always
25951 initialized (if not already set). There are a few types where
25952 we should not be doing so, because the type-specific area is
25953 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25954 where the type-specific area is used to store the floatformat).
25955 But this is not a problem, because the gnat-specific information
25956 is actually not needed for these types. */
25957 if (need_gnat_info (cu
)
25958 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25959 && TYPE_CODE (type
) != TYPE_CODE_FLT
25960 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25961 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25962 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25963 && !HAVE_GNAT_AUX_INFO (type
))
25964 INIT_GNAT_SPECIFIC (type
);
25966 /* Read DW_AT_allocated and set in type. */
25967 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25968 if (attr_form_is_block (attr
))
25970 struct type
*prop_type
25971 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25972 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25973 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25975 else if (attr
!= NULL
)
25977 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25978 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25979 sect_offset_str (die
->sect_off
));
25982 /* Read DW_AT_associated and set in type. */
25983 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25984 if (attr_form_is_block (attr
))
25986 struct type
*prop_type
25987 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25988 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25989 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25991 else if (attr
!= NULL
)
25993 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25994 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25995 sect_offset_str (die
->sect_off
));
25998 /* Read DW_AT_data_location and set in type. */
25999 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
26000 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
26001 dwarf2_per_cu_addr_type (cu
->per_cu
)))
26002 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
26004 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
26006 dwarf2_per_objfile
->die_type_hash
=
26007 htab_create_alloc_ex (127,
26008 per_cu_offset_and_type_hash
,
26009 per_cu_offset_and_type_eq
,
26011 &objfile
->objfile_obstack
,
26012 hashtab_obstack_allocate
,
26013 dummy_obstack_deallocate
);
26016 ofs
.per_cu
= cu
->per_cu
;
26017 ofs
.sect_off
= die
->sect_off
;
26019 slot
= (struct dwarf2_per_cu_offset_and_type
**)
26020 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
26022 complaint (_("A problem internal to GDB: DIE %s has type already set"),
26023 sect_offset_str (die
->sect_off
));
26024 *slot
= XOBNEW (&objfile
->objfile_obstack
,
26025 struct dwarf2_per_cu_offset_and_type
);
26030 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
26031 or return NULL if the die does not have a saved type. */
26033 static struct type
*
26034 get_die_type_at_offset (sect_offset sect_off
,
26035 struct dwarf2_per_cu_data
*per_cu
)
26037 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
26038 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
26040 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
26043 ofs
.per_cu
= per_cu
;
26044 ofs
.sect_off
= sect_off
;
26045 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
26046 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
26053 /* Look up the type for DIE in CU in die_type_hash,
26054 or return NULL if DIE does not have a saved type. */
26056 static struct type
*
26057 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
26059 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
26062 /* Add a dependence relationship from CU to REF_PER_CU. */
26065 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
26066 struct dwarf2_per_cu_data
*ref_per_cu
)
26070 if (cu
->dependencies
== NULL
)
26072 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
26073 NULL
, &cu
->comp_unit_obstack
,
26074 hashtab_obstack_allocate
,
26075 dummy_obstack_deallocate
);
26077 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
26079 *slot
= ref_per_cu
;
26082 /* Subroutine of dwarf2_mark to pass to htab_traverse.
26083 Set the mark field in every compilation unit in the
26084 cache that we must keep because we are keeping CU. */
26087 dwarf2_mark_helper (void **slot
, void *data
)
26089 struct dwarf2_per_cu_data
*per_cu
;
26091 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
26093 /* cu->dependencies references may not yet have been ever read if QUIT aborts
26094 reading of the chain. As such dependencies remain valid it is not much
26095 useful to track and undo them during QUIT cleanups. */
26096 if (per_cu
->cu
== NULL
)
26099 if (per_cu
->cu
->mark
)
26101 per_cu
->cu
->mark
= true;
26103 if (per_cu
->cu
->dependencies
!= NULL
)
26104 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26109 /* Set the mark field in CU and in every other compilation unit in the
26110 cache that we must keep because we are keeping CU. */
26113 dwarf2_mark (struct dwarf2_cu
*cu
)
26118 if (cu
->dependencies
!= NULL
)
26119 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26123 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
26127 per_cu
->cu
->mark
= false;
26128 per_cu
= per_cu
->cu
->read_in_chain
;
26132 /* Trivial hash function for partial_die_info: the hash value of a DIE
26133 is its offset in .debug_info for this objfile. */
26136 partial_die_hash (const void *item
)
26138 const struct partial_die_info
*part_die
26139 = (const struct partial_die_info
*) item
;
26141 return to_underlying (part_die
->sect_off
);
26144 /* Trivial comparison function for partial_die_info structures: two DIEs
26145 are equal if they have the same offset. */
26148 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
26150 const struct partial_die_info
*part_die_lhs
26151 = (const struct partial_die_info
*) item_lhs
;
26152 const struct partial_die_info
*part_die_rhs
26153 = (const struct partial_die_info
*) item_rhs
;
26155 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
26158 struct cmd_list_element
*set_dwarf_cmdlist
;
26159 struct cmd_list_element
*show_dwarf_cmdlist
;
26162 set_dwarf_cmd (const char *args
, int from_tty
)
26164 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
26169 show_dwarf_cmd (const char *args
, int from_tty
)
26171 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
26174 bool dwarf_always_disassemble
;
26177 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
26178 struct cmd_list_element
*c
, const char *value
)
26180 fprintf_filtered (file
,
26181 _("Whether to always disassemble "
26182 "DWARF expressions is %s.\n"),
26187 show_check_physname (struct ui_file
*file
, int from_tty
,
26188 struct cmd_list_element
*c
, const char *value
)
26190 fprintf_filtered (file
,
26191 _("Whether to check \"physname\" is %s.\n"),
26196 _initialize_dwarf2_read (void)
26198 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26199 Set DWARF specific variables.\n\
26200 Configure DWARF variables such as the cache size."),
26201 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26202 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26204 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26205 Show DWARF specific variables.\n\
26206 Show DWARF variables such as the cache size."),
26207 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26208 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26210 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26211 &dwarf_max_cache_age
, _("\
26212 Set the upper bound on the age of cached DWARF compilation units."), _("\
26213 Show the upper bound on the age of cached DWARF compilation units."), _("\
26214 A higher limit means that cached compilation units will be stored\n\
26215 in memory longer, and more total memory will be used. Zero disables\n\
26216 caching, which can slow down startup."),
26218 show_dwarf_max_cache_age
,
26219 &set_dwarf_cmdlist
,
26220 &show_dwarf_cmdlist
);
26222 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26223 &dwarf_always_disassemble
, _("\
26224 Set whether `info address' always disassembles DWARF expressions."), _("\
26225 Show whether `info address' always disassembles DWARF expressions."), _("\
26226 When enabled, DWARF expressions are always printed in an assembly-like\n\
26227 syntax. When disabled, expressions will be printed in a more\n\
26228 conversational style, when possible."),
26230 show_dwarf_always_disassemble
,
26231 &set_dwarf_cmdlist
,
26232 &show_dwarf_cmdlist
);
26234 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26235 Set debugging of the DWARF reader."), _("\
26236 Show debugging of the DWARF reader."), _("\
26237 When enabled (non-zero), debugging messages are printed during DWARF\n\
26238 reading and symtab expansion. A value of 1 (one) provides basic\n\
26239 information. A value greater than 1 provides more verbose information."),
26242 &setdebuglist
, &showdebuglist
);
26244 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26245 Set debugging of the DWARF DIE reader."), _("\
26246 Show debugging of the DWARF DIE reader."), _("\
26247 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26248 The value is the maximum depth to print."),
26251 &setdebuglist
, &showdebuglist
);
26253 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26254 Set debugging of the dwarf line reader."), _("\
26255 Show debugging of the dwarf line reader."), _("\
26256 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26257 A value of 1 (one) provides basic information.\n\
26258 A value greater than 1 provides more verbose information."),
26261 &setdebuglist
, &showdebuglist
);
26263 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26264 Set cross-checking of \"physname\" code against demangler."), _("\
26265 Show cross-checking of \"physname\" code against demangler."), _("\
26266 When enabled, GDB's internal \"physname\" code is checked against\n\
26268 NULL
, show_check_physname
,
26269 &setdebuglist
, &showdebuglist
);
26271 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26272 no_class
, &use_deprecated_index_sections
, _("\
26273 Set whether to use deprecated gdb_index sections."), _("\
26274 Show whether to use deprecated gdb_index sections."), _("\
26275 When enabled, deprecated .gdb_index sections are used anyway.\n\
26276 Normally they are ignored either because of a missing feature or\n\
26277 performance issue.\n\
26278 Warning: This option must be enabled before gdb reads the file."),
26281 &setlist
, &showlist
);
26283 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26284 &dwarf2_locexpr_funcs
);
26285 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26286 &dwarf2_loclist_funcs
);
26288 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26289 &dwarf2_block_frame_base_locexpr_funcs
);
26290 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26291 &dwarf2_block_frame_base_loclist_funcs
);
26294 selftests::register_test ("dw2_expand_symtabs_matching",
26295 selftests::dw2_expand_symtabs_matching::run_test
);