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 (SYMBOL_LANGUAGE (sym
) == 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 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9957 SYMBOL_SET_NAMES (sym
, saved_package_name
, false, objfile
);
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. SYMBOL_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 /* Add a member function to the proper fieldlist. */
15479 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15480 struct type
*type
, struct dwarf2_cu
*cu
)
15482 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15483 struct attribute
*attr
;
15485 struct fnfieldlist
*flp
= nullptr;
15486 struct fn_field
*fnp
;
15487 const char *fieldname
;
15488 struct type
*this_type
;
15489 enum dwarf_access_attribute accessibility
;
15491 if (cu
->language
== language_ada
)
15492 error (_("unexpected member function in Ada type"));
15494 /* Get name of member function. */
15495 fieldname
= dwarf2_name (die
, cu
);
15496 if (fieldname
== NULL
)
15499 /* Look up member function name in fieldlist. */
15500 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15502 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15504 flp
= &fip
->fnfieldlists
[i
];
15509 /* Create a new fnfieldlist if necessary. */
15510 if (flp
== nullptr)
15512 fip
->fnfieldlists
.emplace_back ();
15513 flp
= &fip
->fnfieldlists
.back ();
15514 flp
->name
= fieldname
;
15515 i
= fip
->fnfieldlists
.size () - 1;
15518 /* Create a new member function field and add it to the vector of
15520 flp
->fnfields
.emplace_back ();
15521 fnp
= &flp
->fnfields
.back ();
15523 /* Delay processing of the physname until later. */
15524 if (cu
->language
== language_cplus
)
15525 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15529 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15530 fnp
->physname
= physname
? physname
: "";
15533 fnp
->type
= alloc_type (objfile
);
15534 this_type
= read_type_die (die
, cu
);
15535 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15537 int nparams
= TYPE_NFIELDS (this_type
);
15539 /* TYPE is the domain of this method, and THIS_TYPE is the type
15540 of the method itself (TYPE_CODE_METHOD). */
15541 smash_to_method_type (fnp
->type
, type
,
15542 TYPE_TARGET_TYPE (this_type
),
15543 TYPE_FIELDS (this_type
),
15544 TYPE_NFIELDS (this_type
),
15545 TYPE_VARARGS (this_type
));
15547 /* Handle static member functions.
15548 Dwarf2 has no clean way to discern C++ static and non-static
15549 member functions. G++ helps GDB by marking the first
15550 parameter for non-static member functions (which is the this
15551 pointer) as artificial. We obtain this information from
15552 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15553 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15554 fnp
->voffset
= VOFFSET_STATIC
;
15557 complaint (_("member function type missing for '%s'"),
15558 dwarf2_full_name (fieldname
, die
, cu
));
15560 /* Get fcontext from DW_AT_containing_type if present. */
15561 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15562 fnp
->fcontext
= die_containing_type (die
, cu
);
15564 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15565 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15567 /* Get accessibility. */
15568 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15569 if (attr
!= nullptr)
15570 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15572 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15573 switch (accessibility
)
15575 case DW_ACCESS_private
:
15576 fnp
->is_private
= 1;
15578 case DW_ACCESS_protected
:
15579 fnp
->is_protected
= 1;
15583 /* Check for artificial methods. */
15584 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15585 if (attr
&& DW_UNSND (attr
) != 0)
15586 fnp
->is_artificial
= 1;
15588 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15590 /* Get index in virtual function table if it is a virtual member
15591 function. For older versions of GCC, this is an offset in the
15592 appropriate virtual table, as specified by DW_AT_containing_type.
15593 For everyone else, it is an expression to be evaluated relative
15594 to the object address. */
15596 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15597 if (attr
!= nullptr)
15599 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15601 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15603 /* Old-style GCC. */
15604 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15606 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15607 || (DW_BLOCK (attr
)->size
> 1
15608 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15609 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15611 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15612 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15613 dwarf2_complex_location_expr_complaint ();
15615 fnp
->voffset
/= cu
->header
.addr_size
;
15619 dwarf2_complex_location_expr_complaint ();
15621 if (!fnp
->fcontext
)
15623 /* If there is no `this' field and no DW_AT_containing_type,
15624 we cannot actually find a base class context for the
15626 if (TYPE_NFIELDS (this_type
) == 0
15627 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15629 complaint (_("cannot determine context for virtual member "
15630 "function \"%s\" (offset %s)"),
15631 fieldname
, sect_offset_str (die
->sect_off
));
15636 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15640 else if (attr_form_is_section_offset (attr
))
15642 dwarf2_complex_location_expr_complaint ();
15646 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15652 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15653 if (attr
&& DW_UNSND (attr
))
15655 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15656 complaint (_("Member function \"%s\" (offset %s) is virtual "
15657 "but the vtable offset is not specified"),
15658 fieldname
, sect_offset_str (die
->sect_off
));
15659 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15660 TYPE_CPLUS_DYNAMIC (type
) = 1;
15665 /* Create the vector of member function fields, and attach it to the type. */
15668 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15669 struct dwarf2_cu
*cu
)
15671 if (cu
->language
== language_ada
)
15672 error (_("unexpected member functions in Ada type"));
15674 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15675 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15677 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15679 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15681 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15682 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15684 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15685 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15686 fn_flp
->fn_fields
= (struct fn_field
*)
15687 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15689 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15690 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15693 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15696 /* Returns non-zero if NAME is the name of a vtable member in CU's
15697 language, zero otherwise. */
15699 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15701 static const char vptr
[] = "_vptr";
15703 /* Look for the C++ form of the vtable. */
15704 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15710 /* GCC outputs unnamed structures that are really pointers to member
15711 functions, with the ABI-specified layout. If TYPE describes
15712 such a structure, smash it into a member function type.
15714 GCC shouldn't do this; it should just output pointer to member DIEs.
15715 This is GCC PR debug/28767. */
15718 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15720 struct type
*pfn_type
, *self_type
, *new_type
;
15722 /* Check for a structure with no name and two children. */
15723 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15726 /* Check for __pfn and __delta members. */
15727 if (TYPE_FIELD_NAME (type
, 0) == NULL
15728 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15729 || TYPE_FIELD_NAME (type
, 1) == NULL
15730 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15733 /* Find the type of the method. */
15734 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15735 if (pfn_type
== NULL
15736 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15737 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15740 /* Look for the "this" argument. */
15741 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15742 if (TYPE_NFIELDS (pfn_type
) == 0
15743 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15744 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15747 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15748 new_type
= alloc_type (objfile
);
15749 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15750 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15751 TYPE_VARARGS (pfn_type
));
15752 smash_to_methodptr_type (type
, new_type
);
15755 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15756 appropriate error checking and issuing complaints if there is a
15760 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15762 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15764 if (attr
== nullptr)
15767 if (!attr_form_is_constant (attr
))
15769 complaint (_("DW_AT_alignment must have constant form"
15770 " - DIE at %s [in module %s]"),
15771 sect_offset_str (die
->sect_off
),
15772 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15777 if (attr
->form
== DW_FORM_sdata
)
15779 LONGEST val
= DW_SND (attr
);
15782 complaint (_("DW_AT_alignment value must not be negative"
15783 " - DIE at %s [in module %s]"),
15784 sect_offset_str (die
->sect_off
),
15785 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15791 align
= DW_UNSND (attr
);
15795 complaint (_("DW_AT_alignment value must not be zero"
15796 " - DIE at %s [in module %s]"),
15797 sect_offset_str (die
->sect_off
),
15798 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15801 if ((align
& (align
- 1)) != 0)
15803 complaint (_("DW_AT_alignment value must be a power of 2"
15804 " - DIE at %s [in module %s]"),
15805 sect_offset_str (die
->sect_off
),
15806 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15813 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15814 the alignment for TYPE. */
15817 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15820 if (!set_type_align (type
, get_alignment (cu
, die
)))
15821 complaint (_("DW_AT_alignment value too large"
15822 " - DIE at %s [in module %s]"),
15823 sect_offset_str (die
->sect_off
),
15824 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15827 /* Called when we find the DIE that starts a structure or union scope
15828 (definition) to create a type for the structure or union. Fill in
15829 the type's name and general properties; the members will not be
15830 processed until process_structure_scope. A symbol table entry for
15831 the type will also not be done until process_structure_scope (assuming
15832 the type has a name).
15834 NOTE: we need to call these functions regardless of whether or not the
15835 DIE has a DW_AT_name attribute, since it might be an anonymous
15836 structure or union. This gets the type entered into our set of
15837 user defined types. */
15839 static struct type
*
15840 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15842 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15844 struct attribute
*attr
;
15847 /* If the definition of this type lives in .debug_types, read that type.
15848 Don't follow DW_AT_specification though, that will take us back up
15849 the chain and we want to go down. */
15850 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15851 if (attr
!= nullptr)
15853 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15855 /* The type's CU may not be the same as CU.
15856 Ensure TYPE is recorded with CU in die_type_hash. */
15857 return set_die_type (die
, type
, cu
);
15860 type
= alloc_type (objfile
);
15861 INIT_CPLUS_SPECIFIC (type
);
15863 name
= dwarf2_name (die
, cu
);
15866 if (cu
->language
== language_cplus
15867 || cu
->language
== language_d
15868 || cu
->language
== language_rust
)
15870 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15872 /* dwarf2_full_name might have already finished building the DIE's
15873 type. If so, there is no need to continue. */
15874 if (get_die_type (die
, cu
) != NULL
)
15875 return get_die_type (die
, cu
);
15877 TYPE_NAME (type
) = full_name
;
15881 /* The name is already allocated along with this objfile, so
15882 we don't need to duplicate it for the type. */
15883 TYPE_NAME (type
) = name
;
15887 if (die
->tag
== DW_TAG_structure_type
)
15889 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15891 else if (die
->tag
== DW_TAG_union_type
)
15893 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15895 else if (die
->tag
== DW_TAG_variant_part
)
15897 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15898 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15902 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15905 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15906 TYPE_DECLARED_CLASS (type
) = 1;
15908 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15909 if (attr
!= nullptr)
15911 if (attr_form_is_constant (attr
))
15912 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15915 /* For the moment, dynamic type sizes are not supported
15916 by GDB's struct type. The actual size is determined
15917 on-demand when resolving the type of a given object,
15918 so set the type's length to zero for now. Otherwise,
15919 we record an expression as the length, and that expression
15920 could lead to a very large value, which could eventually
15921 lead to us trying to allocate that much memory when creating
15922 a value of that type. */
15923 TYPE_LENGTH (type
) = 0;
15928 TYPE_LENGTH (type
) = 0;
15931 maybe_set_alignment (cu
, die
, type
);
15933 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15935 /* ICC<14 does not output the required DW_AT_declaration on
15936 incomplete types, but gives them a size of zero. */
15937 TYPE_STUB (type
) = 1;
15940 TYPE_STUB_SUPPORTED (type
) = 1;
15942 if (die_is_declaration (die
, cu
))
15943 TYPE_STUB (type
) = 1;
15944 else if (attr
== NULL
&& die
->child
== NULL
15945 && producer_is_realview (cu
->producer
))
15946 /* RealView does not output the required DW_AT_declaration
15947 on incomplete types. */
15948 TYPE_STUB (type
) = 1;
15950 /* We need to add the type field to the die immediately so we don't
15951 infinitely recurse when dealing with pointers to the structure
15952 type within the structure itself. */
15953 set_die_type (die
, type
, cu
);
15955 /* set_die_type should be already done. */
15956 set_descriptive_type (type
, die
, cu
);
15961 /* A helper for process_structure_scope that handles a single member
15965 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15966 struct field_info
*fi
,
15967 std::vector
<struct symbol
*> *template_args
,
15968 struct dwarf2_cu
*cu
)
15970 if (child_die
->tag
== DW_TAG_member
15971 || child_die
->tag
== DW_TAG_variable
15972 || child_die
->tag
== DW_TAG_variant_part
)
15974 /* NOTE: carlton/2002-11-05: A C++ static data member
15975 should be a DW_TAG_member that is a declaration, but
15976 all versions of G++ as of this writing (so through at
15977 least 3.2.1) incorrectly generate DW_TAG_variable
15978 tags for them instead. */
15979 dwarf2_add_field (fi
, child_die
, cu
);
15981 else if (child_die
->tag
== DW_TAG_subprogram
)
15983 /* Rust doesn't have member functions in the C++ sense.
15984 However, it does emit ordinary functions as children
15985 of a struct DIE. */
15986 if (cu
->language
== language_rust
)
15987 read_func_scope (child_die
, cu
);
15990 /* C++ member function. */
15991 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15994 else if (child_die
->tag
== DW_TAG_inheritance
)
15996 /* C++ base class field. */
15997 dwarf2_add_field (fi
, child_die
, cu
);
15999 else if (type_can_define_types (child_die
))
16000 dwarf2_add_type_defn (fi
, child_die
, cu
);
16001 else if (child_die
->tag
== DW_TAG_template_type_param
16002 || child_die
->tag
== DW_TAG_template_value_param
)
16004 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16007 template_args
->push_back (arg
);
16009 else if (child_die
->tag
== DW_TAG_variant
)
16011 /* In a variant we want to get the discriminant and also add a
16012 field for our sole member child. */
16013 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16015 for (die_info
*variant_child
= child_die
->child
;
16016 variant_child
!= NULL
;
16017 variant_child
= sibling_die (variant_child
))
16019 if (variant_child
->tag
== DW_TAG_member
)
16021 handle_struct_member_die (variant_child
, type
, fi
,
16022 template_args
, cu
);
16023 /* Only handle the one. */
16028 /* We don't handle this but we might as well report it if we see
16030 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16031 complaint (_("DW_AT_discr_list is not supported yet"
16032 " - DIE at %s [in module %s]"),
16033 sect_offset_str (child_die
->sect_off
),
16034 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16036 /* The first field was just added, so we can stash the
16037 discriminant there. */
16038 gdb_assert (!fi
->fields
.empty ());
16040 fi
->fields
.back ().variant
.default_branch
= true;
16042 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16046 /* Finish creating a structure or union type, including filling in
16047 its members and creating a symbol for it. */
16050 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16052 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16053 struct die_info
*child_die
;
16056 type
= get_die_type (die
, cu
);
16058 type
= read_structure_type (die
, cu
);
16060 /* When reading a DW_TAG_variant_part, we need to notice when we
16061 read the discriminant member, so we can record it later in the
16062 discriminant_info. */
16063 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16064 sect_offset discr_offset
{};
16065 bool has_template_parameters
= false;
16067 if (is_variant_part
)
16069 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16072 /* Maybe it's a univariant form, an extension we support.
16073 In this case arrange not to check the offset. */
16074 is_variant_part
= false;
16076 else if (attr_form_is_ref (discr
))
16078 struct dwarf2_cu
*target_cu
= cu
;
16079 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16081 discr_offset
= target_die
->sect_off
;
16085 complaint (_("DW_AT_discr does not have DIE reference form"
16086 " - DIE at %s [in module %s]"),
16087 sect_offset_str (die
->sect_off
),
16088 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16089 is_variant_part
= false;
16093 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16095 struct field_info fi
;
16096 std::vector
<struct symbol
*> template_args
;
16098 child_die
= die
->child
;
16100 while (child_die
&& child_die
->tag
)
16102 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16104 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16105 fi
.fields
.back ().variant
.is_discriminant
= true;
16107 child_die
= sibling_die (child_die
);
16110 /* Attach template arguments to type. */
16111 if (!template_args
.empty ())
16113 has_template_parameters
= true;
16114 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16115 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16116 TYPE_TEMPLATE_ARGUMENTS (type
)
16117 = XOBNEWVEC (&objfile
->objfile_obstack
,
16119 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16120 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16121 template_args
.data (),
16122 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16123 * sizeof (struct symbol
*)));
16126 /* Attach fields and member functions to the type. */
16128 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16129 if (!fi
.fnfieldlists
.empty ())
16131 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16133 /* Get the type which refers to the base class (possibly this
16134 class itself) which contains the vtable pointer for the current
16135 class from the DW_AT_containing_type attribute. This use of
16136 DW_AT_containing_type is a GNU extension. */
16138 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16140 struct type
*t
= die_containing_type (die
, cu
);
16142 set_type_vptr_basetype (type
, t
);
16147 /* Our own class provides vtbl ptr. */
16148 for (i
= TYPE_NFIELDS (t
) - 1;
16149 i
>= TYPE_N_BASECLASSES (t
);
16152 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16154 if (is_vtable_name (fieldname
, cu
))
16156 set_type_vptr_fieldno (type
, i
);
16161 /* Complain if virtual function table field not found. */
16162 if (i
< TYPE_N_BASECLASSES (t
))
16163 complaint (_("virtual function table pointer "
16164 "not found when defining class '%s'"),
16165 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16169 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16172 else if (cu
->producer
16173 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16175 /* The IBM XLC compiler does not provide direct indication
16176 of the containing type, but the vtable pointer is
16177 always named __vfp. */
16181 for (i
= TYPE_NFIELDS (type
) - 1;
16182 i
>= TYPE_N_BASECLASSES (type
);
16185 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16187 set_type_vptr_fieldno (type
, i
);
16188 set_type_vptr_basetype (type
, type
);
16195 /* Copy fi.typedef_field_list linked list elements content into the
16196 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16197 if (!fi
.typedef_field_list
.empty ())
16199 int count
= fi
.typedef_field_list
.size ();
16201 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16202 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16203 = ((struct decl_field
*)
16205 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16206 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16208 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16209 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16212 /* Copy fi.nested_types_list linked list elements content into the
16213 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16214 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16216 int count
= fi
.nested_types_list
.size ();
16218 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16219 TYPE_NESTED_TYPES_ARRAY (type
)
16220 = ((struct decl_field
*)
16221 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16222 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16224 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16225 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16229 quirk_gcc_member_function_pointer (type
, objfile
);
16230 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16231 cu
->rust_unions
.push_back (type
);
16233 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16234 snapshots) has been known to create a die giving a declaration
16235 for a class that has, as a child, a die giving a definition for a
16236 nested class. So we have to process our children even if the
16237 current die is a declaration. Normally, of course, a declaration
16238 won't have any children at all. */
16240 child_die
= die
->child
;
16242 while (child_die
!= NULL
&& child_die
->tag
)
16244 if (child_die
->tag
== DW_TAG_member
16245 || child_die
->tag
== DW_TAG_variable
16246 || child_die
->tag
== DW_TAG_inheritance
16247 || child_die
->tag
== DW_TAG_template_value_param
16248 || child_die
->tag
== DW_TAG_template_type_param
)
16253 process_die (child_die
, cu
);
16255 child_die
= sibling_die (child_die
);
16258 /* Do not consider external references. According to the DWARF standard,
16259 these DIEs are identified by the fact that they have no byte_size
16260 attribute, and a declaration attribute. */
16261 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16262 || !die_is_declaration (die
, cu
))
16264 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16266 if (has_template_parameters
)
16268 struct symtab
*symtab
;
16269 if (sym
!= nullptr)
16270 symtab
= symbol_symtab (sym
);
16271 else if (cu
->line_header
!= nullptr)
16273 /* Any related symtab will do. */
16275 = cu
->line_header
->file_names ()[0].symtab
;
16280 complaint (_("could not find suitable "
16281 "symtab for template parameter"
16282 " - DIE at %s [in module %s]"),
16283 sect_offset_str (die
->sect_off
),
16284 objfile_name (objfile
));
16287 if (symtab
!= nullptr)
16289 /* Make sure that the symtab is set on the new symbols.
16290 Even though they don't appear in this symtab directly,
16291 other parts of gdb assume that symbols do, and this is
16292 reasonably true. */
16293 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16294 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16300 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16301 update TYPE using some information only available in DIE's children. */
16304 update_enumeration_type_from_children (struct die_info
*die
,
16306 struct dwarf2_cu
*cu
)
16308 struct die_info
*child_die
;
16309 int unsigned_enum
= 1;
16313 auto_obstack obstack
;
16315 for (child_die
= die
->child
;
16316 child_die
!= NULL
&& child_die
->tag
;
16317 child_die
= sibling_die (child_die
))
16319 struct attribute
*attr
;
16321 const gdb_byte
*bytes
;
16322 struct dwarf2_locexpr_baton
*baton
;
16325 if (child_die
->tag
!= DW_TAG_enumerator
)
16328 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16332 name
= dwarf2_name (child_die
, cu
);
16334 name
= "<anonymous enumerator>";
16336 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16337 &value
, &bytes
, &baton
);
16343 else if ((mask
& value
) != 0)
16348 /* If we already know that the enum type is neither unsigned, nor
16349 a flag type, no need to look at the rest of the enumerates. */
16350 if (!unsigned_enum
&& !flag_enum
)
16355 TYPE_UNSIGNED (type
) = 1;
16357 TYPE_FLAG_ENUM (type
) = 1;
16360 /* Given a DW_AT_enumeration_type die, set its type. We do not
16361 complete the type's fields yet, or create any symbols. */
16363 static struct type
*
16364 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16366 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16368 struct attribute
*attr
;
16371 /* If the definition of this type lives in .debug_types, read that type.
16372 Don't follow DW_AT_specification though, that will take us back up
16373 the chain and we want to go down. */
16374 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16375 if (attr
!= nullptr)
16377 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16379 /* The type's CU may not be the same as CU.
16380 Ensure TYPE is recorded with CU in die_type_hash. */
16381 return set_die_type (die
, type
, cu
);
16384 type
= alloc_type (objfile
);
16386 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16387 name
= dwarf2_full_name (NULL
, die
, cu
);
16389 TYPE_NAME (type
) = name
;
16391 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16394 struct type
*underlying_type
= die_type (die
, cu
);
16396 TYPE_TARGET_TYPE (type
) = underlying_type
;
16399 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16400 if (attr
!= nullptr)
16402 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16406 TYPE_LENGTH (type
) = 0;
16409 maybe_set_alignment (cu
, die
, type
);
16411 /* The enumeration DIE can be incomplete. In Ada, any type can be
16412 declared as private in the package spec, and then defined only
16413 inside the package body. Such types are known as Taft Amendment
16414 Types. When another package uses such a type, an incomplete DIE
16415 may be generated by the compiler. */
16416 if (die_is_declaration (die
, cu
))
16417 TYPE_STUB (type
) = 1;
16419 /* Finish the creation of this type by using the enum's children.
16420 We must call this even when the underlying type has been provided
16421 so that we can determine if we're looking at a "flag" enum. */
16422 update_enumeration_type_from_children (die
, type
, cu
);
16424 /* If this type has an underlying type that is not a stub, then we
16425 may use its attributes. We always use the "unsigned" attribute
16426 in this situation, because ordinarily we guess whether the type
16427 is unsigned -- but the guess can be wrong and the underlying type
16428 can tell us the reality. However, we defer to a local size
16429 attribute if one exists, because this lets the compiler override
16430 the underlying type if needed. */
16431 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16433 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16434 if (TYPE_LENGTH (type
) == 0)
16435 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16436 if (TYPE_RAW_ALIGN (type
) == 0
16437 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16438 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16441 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16443 return set_die_type (die
, type
, cu
);
16446 /* Given a pointer to a die which begins an enumeration, process all
16447 the dies that define the members of the enumeration, and create the
16448 symbol for the enumeration type.
16450 NOTE: We reverse the order of the element list. */
16453 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16455 struct type
*this_type
;
16457 this_type
= get_die_type (die
, cu
);
16458 if (this_type
== NULL
)
16459 this_type
= read_enumeration_type (die
, cu
);
16461 if (die
->child
!= NULL
)
16463 struct die_info
*child_die
;
16464 struct symbol
*sym
;
16465 struct field
*fields
= NULL
;
16466 int num_fields
= 0;
16469 child_die
= die
->child
;
16470 while (child_die
&& child_die
->tag
)
16472 if (child_die
->tag
!= DW_TAG_enumerator
)
16474 process_die (child_die
, cu
);
16478 name
= dwarf2_name (child_die
, cu
);
16481 sym
= new_symbol (child_die
, this_type
, cu
);
16483 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16485 fields
= (struct field
*)
16487 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16488 * sizeof (struct field
));
16491 FIELD_NAME (fields
[num_fields
]) = sym
->linkage_name ();
16492 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16493 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16494 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16500 child_die
= sibling_die (child_die
);
16505 TYPE_NFIELDS (this_type
) = num_fields
;
16506 TYPE_FIELDS (this_type
) = (struct field
*)
16507 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16508 memcpy (TYPE_FIELDS (this_type
), fields
,
16509 sizeof (struct field
) * num_fields
);
16514 /* If we are reading an enum from a .debug_types unit, and the enum
16515 is a declaration, and the enum is not the signatured type in the
16516 unit, then we do not want to add a symbol for it. Adding a
16517 symbol would in some cases obscure the true definition of the
16518 enum, giving users an incomplete type when the definition is
16519 actually available. Note that we do not want to do this for all
16520 enums which are just declarations, because C++0x allows forward
16521 enum declarations. */
16522 if (cu
->per_cu
->is_debug_types
16523 && die_is_declaration (die
, cu
))
16525 struct signatured_type
*sig_type
;
16527 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16528 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16529 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16533 new_symbol (die
, this_type
, cu
);
16536 /* Extract all information from a DW_TAG_array_type DIE and put it in
16537 the DIE's type field. For now, this only handles one dimensional
16540 static struct type
*
16541 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16543 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16544 struct die_info
*child_die
;
16546 struct type
*element_type
, *range_type
, *index_type
;
16547 struct attribute
*attr
;
16549 struct dynamic_prop
*byte_stride_prop
= NULL
;
16550 unsigned int bit_stride
= 0;
16552 element_type
= die_type (die
, cu
);
16554 /* The die_type call above may have already set the type for this DIE. */
16555 type
= get_die_type (die
, cu
);
16559 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16563 struct type
*prop_type
16564 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16567 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16568 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16572 complaint (_("unable to read array DW_AT_byte_stride "
16573 " - DIE at %s [in module %s]"),
16574 sect_offset_str (die
->sect_off
),
16575 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16576 /* Ignore this attribute. We will likely not be able to print
16577 arrays of this type correctly, but there is little we can do
16578 to help if we cannot read the attribute's value. */
16579 byte_stride_prop
= NULL
;
16583 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16585 bit_stride
= DW_UNSND (attr
);
16587 /* Irix 6.2 native cc creates array types without children for
16588 arrays with unspecified length. */
16589 if (die
->child
== NULL
)
16591 index_type
= objfile_type (objfile
)->builtin_int
;
16592 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16593 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16594 byte_stride_prop
, bit_stride
);
16595 return set_die_type (die
, type
, cu
);
16598 std::vector
<struct type
*> range_types
;
16599 child_die
= die
->child
;
16600 while (child_die
&& child_die
->tag
)
16602 if (child_die
->tag
== DW_TAG_subrange_type
)
16604 struct type
*child_type
= read_type_die (child_die
, cu
);
16606 if (child_type
!= NULL
)
16608 /* The range type was succesfully read. Save it for the
16609 array type creation. */
16610 range_types
.push_back (child_type
);
16613 child_die
= sibling_die (child_die
);
16616 /* Dwarf2 dimensions are output from left to right, create the
16617 necessary array types in backwards order. */
16619 type
= element_type
;
16621 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16625 while (i
< range_types
.size ())
16626 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16627 byte_stride_prop
, bit_stride
);
16631 size_t ndim
= range_types
.size ();
16633 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16634 byte_stride_prop
, bit_stride
);
16637 /* Understand Dwarf2 support for vector types (like they occur on
16638 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16639 array type. This is not part of the Dwarf2/3 standard yet, but a
16640 custom vendor extension. The main difference between a regular
16641 array and the vector variant is that vectors are passed by value
16643 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16644 if (attr
!= nullptr)
16645 make_vector_type (type
);
16647 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16648 implementation may choose to implement triple vectors using this
16650 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16651 if (attr
!= nullptr)
16653 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16654 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16656 complaint (_("DW_AT_byte_size for array type smaller "
16657 "than the total size of elements"));
16660 name
= dwarf2_name (die
, cu
);
16662 TYPE_NAME (type
) = name
;
16664 maybe_set_alignment (cu
, die
, type
);
16666 /* Install the type in the die. */
16667 set_die_type (die
, type
, cu
);
16669 /* set_die_type should be already done. */
16670 set_descriptive_type (type
, die
, cu
);
16675 static enum dwarf_array_dim_ordering
16676 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16678 struct attribute
*attr
;
16680 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16682 if (attr
!= nullptr)
16683 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16685 /* GNU F77 is a special case, as at 08/2004 array type info is the
16686 opposite order to the dwarf2 specification, but data is still
16687 laid out as per normal fortran.
16689 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16690 version checking. */
16692 if (cu
->language
== language_fortran
16693 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16695 return DW_ORD_row_major
;
16698 switch (cu
->language_defn
->la_array_ordering
)
16700 case array_column_major
:
16701 return DW_ORD_col_major
;
16702 case array_row_major
:
16704 return DW_ORD_row_major
;
16708 /* Extract all information from a DW_TAG_set_type DIE and put it in
16709 the DIE's type field. */
16711 static struct type
*
16712 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16714 struct type
*domain_type
, *set_type
;
16715 struct attribute
*attr
;
16717 domain_type
= die_type (die
, cu
);
16719 /* The die_type call above may have already set the type for this DIE. */
16720 set_type
= get_die_type (die
, cu
);
16724 set_type
= create_set_type (NULL
, domain_type
);
16726 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16727 if (attr
!= nullptr)
16728 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16730 maybe_set_alignment (cu
, die
, set_type
);
16732 return set_die_type (die
, set_type
, cu
);
16735 /* A helper for read_common_block that creates a locexpr baton.
16736 SYM is the symbol which we are marking as computed.
16737 COMMON_DIE is the DIE for the common block.
16738 COMMON_LOC is the location expression attribute for the common
16740 MEMBER_LOC is the location expression attribute for the particular
16741 member of the common block that we are processing.
16742 CU is the CU from which the above come. */
16745 mark_common_block_symbol_computed (struct symbol
*sym
,
16746 struct die_info
*common_die
,
16747 struct attribute
*common_loc
,
16748 struct attribute
*member_loc
,
16749 struct dwarf2_cu
*cu
)
16751 struct dwarf2_per_objfile
*dwarf2_per_objfile
16752 = cu
->per_cu
->dwarf2_per_objfile
;
16753 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16754 struct dwarf2_locexpr_baton
*baton
;
16756 unsigned int cu_off
;
16757 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16758 LONGEST offset
= 0;
16760 gdb_assert (common_loc
&& member_loc
);
16761 gdb_assert (attr_form_is_block (common_loc
));
16762 gdb_assert (attr_form_is_block (member_loc
)
16763 || attr_form_is_constant (member_loc
));
16765 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16766 baton
->per_cu
= cu
->per_cu
;
16767 gdb_assert (baton
->per_cu
);
16769 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16771 if (attr_form_is_constant (member_loc
))
16773 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16774 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16777 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16779 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16782 *ptr
++ = DW_OP_call4
;
16783 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16784 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16787 if (attr_form_is_constant (member_loc
))
16789 *ptr
++ = DW_OP_addr
;
16790 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16791 ptr
+= cu
->header
.addr_size
;
16795 /* We have to copy the data here, because DW_OP_call4 will only
16796 use a DW_AT_location attribute. */
16797 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16798 ptr
+= DW_BLOCK (member_loc
)->size
;
16801 *ptr
++ = DW_OP_plus
;
16802 gdb_assert (ptr
- baton
->data
== baton
->size
);
16804 SYMBOL_LOCATION_BATON (sym
) = baton
;
16805 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16808 /* Create appropriate locally-scoped variables for all the
16809 DW_TAG_common_block entries. Also create a struct common_block
16810 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16811 is used to separate the common blocks name namespace from regular
16815 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16817 struct attribute
*attr
;
16819 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16820 if (attr
!= nullptr)
16822 /* Support the .debug_loc offsets. */
16823 if (attr_form_is_block (attr
))
16827 else if (attr_form_is_section_offset (attr
))
16829 dwarf2_complex_location_expr_complaint ();
16834 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16835 "common block member");
16840 if (die
->child
!= NULL
)
16842 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16843 struct die_info
*child_die
;
16844 size_t n_entries
= 0, size
;
16845 struct common_block
*common_block
;
16846 struct symbol
*sym
;
16848 for (child_die
= die
->child
;
16849 child_die
&& child_die
->tag
;
16850 child_die
= sibling_die (child_die
))
16853 size
= (sizeof (struct common_block
)
16854 + (n_entries
- 1) * sizeof (struct symbol
*));
16856 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16858 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16859 common_block
->n_entries
= 0;
16861 for (child_die
= die
->child
;
16862 child_die
&& child_die
->tag
;
16863 child_die
= sibling_die (child_die
))
16865 /* Create the symbol in the DW_TAG_common_block block in the current
16867 sym
= new_symbol (child_die
, NULL
, cu
);
16870 struct attribute
*member_loc
;
16872 common_block
->contents
[common_block
->n_entries
++] = sym
;
16874 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16878 /* GDB has handled this for a long time, but it is
16879 not specified by DWARF. It seems to have been
16880 emitted by gfortran at least as recently as:
16881 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16882 complaint (_("Variable in common block has "
16883 "DW_AT_data_member_location "
16884 "- DIE at %s [in module %s]"),
16885 sect_offset_str (child_die
->sect_off
),
16886 objfile_name (objfile
));
16888 if (attr_form_is_section_offset (member_loc
))
16889 dwarf2_complex_location_expr_complaint ();
16890 else if (attr_form_is_constant (member_loc
)
16891 || attr_form_is_block (member_loc
))
16893 if (attr
!= nullptr)
16894 mark_common_block_symbol_computed (sym
, die
, attr
,
16898 dwarf2_complex_location_expr_complaint ();
16903 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16904 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16908 /* Create a type for a C++ namespace. */
16910 static struct type
*
16911 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16913 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16914 const char *previous_prefix
, *name
;
16918 /* For extensions, reuse the type of the original namespace. */
16919 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16921 struct die_info
*ext_die
;
16922 struct dwarf2_cu
*ext_cu
= cu
;
16924 ext_die
= dwarf2_extension (die
, &ext_cu
);
16925 type
= read_type_die (ext_die
, ext_cu
);
16927 /* EXT_CU may not be the same as CU.
16928 Ensure TYPE is recorded with CU in die_type_hash. */
16929 return set_die_type (die
, type
, cu
);
16932 name
= namespace_name (die
, &is_anonymous
, cu
);
16934 /* Now build the name of the current namespace. */
16936 previous_prefix
= determine_prefix (die
, cu
);
16937 if (previous_prefix
[0] != '\0')
16938 name
= typename_concat (&objfile
->objfile_obstack
,
16939 previous_prefix
, name
, 0, cu
);
16941 /* Create the type. */
16942 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16944 return set_die_type (die
, type
, cu
);
16947 /* Read a namespace scope. */
16950 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16952 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16955 /* Add a symbol associated to this if we haven't seen the namespace
16956 before. Also, add a using directive if it's an anonymous
16959 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16963 type
= read_type_die (die
, cu
);
16964 new_symbol (die
, type
, cu
);
16966 namespace_name (die
, &is_anonymous
, cu
);
16969 const char *previous_prefix
= determine_prefix (die
, cu
);
16971 std::vector
<const char *> excludes
;
16972 add_using_directive (using_directives (cu
),
16973 previous_prefix
, TYPE_NAME (type
), NULL
,
16974 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16978 if (die
->child
!= NULL
)
16980 struct die_info
*child_die
= die
->child
;
16982 while (child_die
&& child_die
->tag
)
16984 process_die (child_die
, cu
);
16985 child_die
= sibling_die (child_die
);
16990 /* Read a Fortran module as type. This DIE can be only a declaration used for
16991 imported module. Still we need that type as local Fortran "use ... only"
16992 declaration imports depend on the created type in determine_prefix. */
16994 static struct type
*
16995 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16997 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16998 const char *module_name
;
17001 module_name
= dwarf2_name (die
, cu
);
17002 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17004 return set_die_type (die
, type
, cu
);
17007 /* Read a Fortran module. */
17010 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17012 struct die_info
*child_die
= die
->child
;
17015 type
= read_type_die (die
, cu
);
17016 new_symbol (die
, type
, cu
);
17018 while (child_die
&& child_die
->tag
)
17020 process_die (child_die
, cu
);
17021 child_die
= sibling_die (child_die
);
17025 /* Return the name of the namespace represented by DIE. Set
17026 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17029 static const char *
17030 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17032 struct die_info
*current_die
;
17033 const char *name
= NULL
;
17035 /* Loop through the extensions until we find a name. */
17037 for (current_die
= die
;
17038 current_die
!= NULL
;
17039 current_die
= dwarf2_extension (die
, &cu
))
17041 /* We don't use dwarf2_name here so that we can detect the absence
17042 of a name -> anonymous namespace. */
17043 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17049 /* Is it an anonymous namespace? */
17051 *is_anonymous
= (name
== NULL
);
17053 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17058 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17059 the user defined type vector. */
17061 static struct type
*
17062 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17064 struct gdbarch
*gdbarch
17065 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17066 struct comp_unit_head
*cu_header
= &cu
->header
;
17068 struct attribute
*attr_byte_size
;
17069 struct attribute
*attr_address_class
;
17070 int byte_size
, addr_class
;
17071 struct type
*target_type
;
17073 target_type
= die_type (die
, cu
);
17075 /* The die_type call above may have already set the type for this DIE. */
17076 type
= get_die_type (die
, cu
);
17080 type
= lookup_pointer_type (target_type
);
17082 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17083 if (attr_byte_size
)
17084 byte_size
= DW_UNSND (attr_byte_size
);
17086 byte_size
= cu_header
->addr_size
;
17088 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17089 if (attr_address_class
)
17090 addr_class
= DW_UNSND (attr_address_class
);
17092 addr_class
= DW_ADDR_none
;
17094 ULONGEST alignment
= get_alignment (cu
, die
);
17096 /* If the pointer size, alignment, or address class is different
17097 than the default, create a type variant marked as such and set
17098 the length accordingly. */
17099 if (TYPE_LENGTH (type
) != byte_size
17100 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17101 && alignment
!= TYPE_RAW_ALIGN (type
))
17102 || addr_class
!= DW_ADDR_none
)
17104 if (gdbarch_address_class_type_flags_p (gdbarch
))
17108 type_flags
= gdbarch_address_class_type_flags
17109 (gdbarch
, byte_size
, addr_class
);
17110 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17112 type
= make_type_with_address_space (type
, type_flags
);
17114 else if (TYPE_LENGTH (type
) != byte_size
)
17116 complaint (_("invalid pointer size %d"), byte_size
);
17118 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17120 complaint (_("Invalid DW_AT_alignment"
17121 " - DIE at %s [in module %s]"),
17122 sect_offset_str (die
->sect_off
),
17123 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17127 /* Should we also complain about unhandled address classes? */
17131 TYPE_LENGTH (type
) = byte_size
;
17132 set_type_align (type
, alignment
);
17133 return set_die_type (die
, type
, cu
);
17136 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17137 the user defined type vector. */
17139 static struct type
*
17140 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17143 struct type
*to_type
;
17144 struct type
*domain
;
17146 to_type
= die_type (die
, cu
);
17147 domain
= die_containing_type (die
, cu
);
17149 /* The calls above may have already set the type for this DIE. */
17150 type
= get_die_type (die
, cu
);
17154 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17155 type
= lookup_methodptr_type (to_type
);
17156 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17158 struct type
*new_type
17159 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17161 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17162 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17163 TYPE_VARARGS (to_type
));
17164 type
= lookup_methodptr_type (new_type
);
17167 type
= lookup_memberptr_type (to_type
, domain
);
17169 return set_die_type (die
, type
, cu
);
17172 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17173 the user defined type vector. */
17175 static struct type
*
17176 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17177 enum type_code refcode
)
17179 struct comp_unit_head
*cu_header
= &cu
->header
;
17180 struct type
*type
, *target_type
;
17181 struct attribute
*attr
;
17183 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17185 target_type
= die_type (die
, cu
);
17187 /* The die_type call above may have already set the type for this DIE. */
17188 type
= get_die_type (die
, cu
);
17192 type
= lookup_reference_type (target_type
, refcode
);
17193 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17194 if (attr
!= nullptr)
17196 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17200 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17202 maybe_set_alignment (cu
, die
, type
);
17203 return set_die_type (die
, type
, cu
);
17206 /* Add the given cv-qualifiers to the element type of the array. GCC
17207 outputs DWARF type qualifiers that apply to an array, not the
17208 element type. But GDB relies on the array element type to carry
17209 the cv-qualifiers. This mimics section 6.7.3 of the C99
17212 static struct type
*
17213 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17214 struct type
*base_type
, int cnst
, int voltl
)
17216 struct type
*el_type
, *inner_array
;
17218 base_type
= copy_type (base_type
);
17219 inner_array
= base_type
;
17221 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17223 TYPE_TARGET_TYPE (inner_array
) =
17224 copy_type (TYPE_TARGET_TYPE (inner_array
));
17225 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17228 el_type
= TYPE_TARGET_TYPE (inner_array
);
17229 cnst
|= TYPE_CONST (el_type
);
17230 voltl
|= TYPE_VOLATILE (el_type
);
17231 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17233 return set_die_type (die
, base_type
, cu
);
17236 static struct type
*
17237 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17239 struct type
*base_type
, *cv_type
;
17241 base_type
= die_type (die
, cu
);
17243 /* The die_type call above may have already set the type for this DIE. */
17244 cv_type
= get_die_type (die
, cu
);
17248 /* In case the const qualifier is applied to an array type, the element type
17249 is so qualified, not the array type (section 6.7.3 of C99). */
17250 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17251 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17253 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17254 return set_die_type (die
, cv_type
, cu
);
17257 static struct type
*
17258 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17260 struct type
*base_type
, *cv_type
;
17262 base_type
= die_type (die
, cu
);
17264 /* The die_type call above may have already set the type for this DIE. */
17265 cv_type
= get_die_type (die
, cu
);
17269 /* In case the volatile qualifier is applied to an array type, the
17270 element type is so qualified, not the array type (section 6.7.3
17272 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17273 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17275 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17276 return set_die_type (die
, cv_type
, cu
);
17279 /* Handle DW_TAG_restrict_type. */
17281 static struct type
*
17282 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17284 struct type
*base_type
, *cv_type
;
17286 base_type
= die_type (die
, cu
);
17288 /* The die_type call above may have already set the type for this DIE. */
17289 cv_type
= get_die_type (die
, cu
);
17293 cv_type
= make_restrict_type (base_type
);
17294 return set_die_type (die
, cv_type
, cu
);
17297 /* Handle DW_TAG_atomic_type. */
17299 static struct type
*
17300 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17302 struct type
*base_type
, *cv_type
;
17304 base_type
= die_type (die
, cu
);
17306 /* The die_type call above may have already set the type for this DIE. */
17307 cv_type
= get_die_type (die
, cu
);
17311 cv_type
= make_atomic_type (base_type
);
17312 return set_die_type (die
, cv_type
, cu
);
17315 /* Extract all information from a DW_TAG_string_type DIE and add to
17316 the user defined type vector. It isn't really a user defined type,
17317 but it behaves like one, with other DIE's using an AT_user_def_type
17318 attribute to reference it. */
17320 static struct type
*
17321 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17323 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17324 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17325 struct type
*type
, *range_type
, *index_type
, *char_type
;
17326 struct attribute
*attr
;
17327 struct dynamic_prop prop
;
17328 bool length_is_constant
= true;
17331 /* There are a couple of places where bit sizes might be made use of
17332 when parsing a DW_TAG_string_type, however, no producer that we know
17333 of make use of these. Handling bit sizes that are a multiple of the
17334 byte size is easy enough, but what about other bit sizes? Lets deal
17335 with that problem when we have to. Warn about these attributes being
17336 unsupported, then parse the type and ignore them like we always
17338 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17339 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17341 static bool warning_printed
= false;
17342 if (!warning_printed
)
17344 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17345 "currently supported on DW_TAG_string_type."));
17346 warning_printed
= true;
17350 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17351 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17353 /* The string length describes the location at which the length of
17354 the string can be found. The size of the length field can be
17355 specified with one of the attributes below. */
17356 struct type
*prop_type
;
17357 struct attribute
*len
17358 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17359 if (len
== nullptr)
17360 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17361 if (len
!= nullptr && attr_form_is_constant (len
))
17363 /* Pass 0 as the default as we know this attribute is constant
17364 and the default value will not be returned. */
17365 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17366 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17370 /* If the size is not specified then we assume it is the size of
17371 an address on this target. */
17372 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17375 /* Convert the attribute into a dynamic property. */
17376 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17379 length_is_constant
= false;
17381 else if (attr
!= nullptr)
17383 /* This DW_AT_string_length just contains the length with no
17384 indirection. There's no need to create a dynamic property in this
17385 case. Pass 0 for the default value as we know it will not be
17386 returned in this case. */
17387 length
= dwarf2_get_attr_constant_value (attr
, 0);
17389 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17391 /* We don't currently support non-constant byte sizes for strings. */
17392 length
= dwarf2_get_attr_constant_value (attr
, 1);
17396 /* Use 1 as a fallback length if we have nothing else. */
17400 index_type
= objfile_type (objfile
)->builtin_int
;
17401 if (length_is_constant
)
17402 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17405 struct dynamic_prop low_bound
;
17407 low_bound
.kind
= PROP_CONST
;
17408 low_bound
.data
.const_val
= 1;
17409 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17411 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17412 type
= create_string_type (NULL
, char_type
, range_type
);
17414 return set_die_type (die
, type
, cu
);
17417 /* Assuming that DIE corresponds to a function, returns nonzero
17418 if the function is prototyped. */
17421 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17423 struct attribute
*attr
;
17425 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17426 if (attr
&& (DW_UNSND (attr
) != 0))
17429 /* The DWARF standard implies that the DW_AT_prototyped attribute
17430 is only meaningful for C, but the concept also extends to other
17431 languages that allow unprototyped functions (Eg: Objective C).
17432 For all other languages, assume that functions are always
17434 if (cu
->language
!= language_c
17435 && cu
->language
!= language_objc
17436 && cu
->language
!= language_opencl
)
17439 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17440 prototyped and unprototyped functions; default to prototyped,
17441 since that is more common in modern code (and RealView warns
17442 about unprototyped functions). */
17443 if (producer_is_realview (cu
->producer
))
17449 /* Handle DIES due to C code like:
17453 int (*funcp)(int a, long l);
17457 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17459 static struct type
*
17460 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17462 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17463 struct type
*type
; /* Type that this function returns. */
17464 struct type
*ftype
; /* Function that returns above type. */
17465 struct attribute
*attr
;
17467 type
= die_type (die
, cu
);
17469 /* The die_type call above may have already set the type for this DIE. */
17470 ftype
= get_die_type (die
, cu
);
17474 ftype
= lookup_function_type (type
);
17476 if (prototyped_function_p (die
, cu
))
17477 TYPE_PROTOTYPED (ftype
) = 1;
17479 /* Store the calling convention in the type if it's available in
17480 the subroutine die. Otherwise set the calling convention to
17481 the default value DW_CC_normal. */
17482 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17483 if (attr
!= nullptr)
17484 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17485 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17486 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17488 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17490 /* Record whether the function returns normally to its caller or not
17491 if the DWARF producer set that information. */
17492 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17493 if (attr
&& (DW_UNSND (attr
) != 0))
17494 TYPE_NO_RETURN (ftype
) = 1;
17496 /* We need to add the subroutine type to the die immediately so
17497 we don't infinitely recurse when dealing with parameters
17498 declared as the same subroutine type. */
17499 set_die_type (die
, ftype
, cu
);
17501 if (die
->child
!= NULL
)
17503 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17504 struct die_info
*child_die
;
17505 int nparams
, iparams
;
17507 /* Count the number of parameters.
17508 FIXME: GDB currently ignores vararg functions, but knows about
17509 vararg member functions. */
17511 child_die
= die
->child
;
17512 while (child_die
&& child_die
->tag
)
17514 if (child_die
->tag
== DW_TAG_formal_parameter
)
17516 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17517 TYPE_VARARGS (ftype
) = 1;
17518 child_die
= sibling_die (child_die
);
17521 /* Allocate storage for parameters and fill them in. */
17522 TYPE_NFIELDS (ftype
) = nparams
;
17523 TYPE_FIELDS (ftype
) = (struct field
*)
17524 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17526 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17527 even if we error out during the parameters reading below. */
17528 for (iparams
= 0; iparams
< nparams
; iparams
++)
17529 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17532 child_die
= die
->child
;
17533 while (child_die
&& child_die
->tag
)
17535 if (child_die
->tag
== DW_TAG_formal_parameter
)
17537 struct type
*arg_type
;
17539 /* DWARF version 2 has no clean way to discern C++
17540 static and non-static member functions. G++ helps
17541 GDB by marking the first parameter for non-static
17542 member functions (which is the this pointer) as
17543 artificial. We pass this information to
17544 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17546 DWARF version 3 added DW_AT_object_pointer, which GCC
17547 4.5 does not yet generate. */
17548 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17549 if (attr
!= nullptr)
17550 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17552 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17553 arg_type
= die_type (child_die
, cu
);
17555 /* RealView does not mark THIS as const, which the testsuite
17556 expects. GCC marks THIS as const in method definitions,
17557 but not in the class specifications (GCC PR 43053). */
17558 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17559 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17562 struct dwarf2_cu
*arg_cu
= cu
;
17563 const char *name
= dwarf2_name (child_die
, cu
);
17565 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17566 if (attr
!= nullptr)
17568 /* If the compiler emits this, use it. */
17569 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17572 else if (name
&& strcmp (name
, "this") == 0)
17573 /* Function definitions will have the argument names. */
17575 else if (name
== NULL
&& iparams
== 0)
17576 /* Declarations may not have the names, so like
17577 elsewhere in GDB, assume an artificial first
17578 argument is "this". */
17582 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17586 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17589 child_die
= sibling_die (child_die
);
17596 static struct type
*
17597 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17599 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17600 const char *name
= NULL
;
17601 struct type
*this_type
, *target_type
;
17603 name
= dwarf2_full_name (NULL
, die
, cu
);
17604 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17605 TYPE_TARGET_STUB (this_type
) = 1;
17606 set_die_type (die
, this_type
, cu
);
17607 target_type
= die_type (die
, cu
);
17608 if (target_type
!= this_type
)
17609 TYPE_TARGET_TYPE (this_type
) = target_type
;
17612 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17613 spec and cause infinite loops in GDB. */
17614 complaint (_("Self-referential DW_TAG_typedef "
17615 "- DIE at %s [in module %s]"),
17616 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17617 TYPE_TARGET_TYPE (this_type
) = NULL
;
17622 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17623 (which may be different from NAME) to the architecture back-end to allow
17624 it to guess the correct format if necessary. */
17626 static struct type
*
17627 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17628 const char *name_hint
, enum bfd_endian byte_order
)
17630 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17631 const struct floatformat
**format
;
17634 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17636 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17638 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17643 /* Allocate an integer type of size BITS and name NAME. */
17645 static struct type
*
17646 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17647 int bits
, int unsigned_p
, const char *name
)
17651 /* Versions of Intel's C Compiler generate an integer type called "void"
17652 instead of using DW_TAG_unspecified_type. This has been seen on
17653 at least versions 14, 17, and 18. */
17654 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17655 && strcmp (name
, "void") == 0)
17656 type
= objfile_type (objfile
)->builtin_void
;
17658 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17663 /* Initialise and return a floating point type of size BITS suitable for
17664 use as a component of a complex number. The NAME_HINT is passed through
17665 when initialising the floating point type and is the name of the complex
17668 As DWARF doesn't currently provide an explicit name for the components
17669 of a complex number, but it can be helpful to have these components
17670 named, we try to select a suitable name based on the size of the
17672 static struct type
*
17673 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17674 struct objfile
*objfile
,
17675 int bits
, const char *name_hint
,
17676 enum bfd_endian byte_order
)
17678 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17679 struct type
*tt
= nullptr;
17681 /* Try to find a suitable floating point builtin type of size BITS.
17682 We're going to use the name of this type as the name for the complex
17683 target type that we are about to create. */
17684 switch (cu
->language
)
17686 case language_fortran
:
17690 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17693 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17695 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17697 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17705 tt
= builtin_type (gdbarch
)->builtin_float
;
17708 tt
= builtin_type (gdbarch
)->builtin_double
;
17710 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17712 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17718 /* If the type we found doesn't match the size we were looking for, then
17719 pretend we didn't find a type at all, the complex target type we
17720 create will then be nameless. */
17721 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17724 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17725 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17728 /* Find a representation of a given base type and install
17729 it in the TYPE field of the die. */
17731 static struct type
*
17732 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17734 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17736 struct attribute
*attr
;
17737 int encoding
= 0, bits
= 0;
17741 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17742 if (attr
!= nullptr)
17743 encoding
= DW_UNSND (attr
);
17744 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17745 if (attr
!= nullptr)
17746 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17747 name
= dwarf2_name (die
, cu
);
17749 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17751 arch
= get_objfile_arch (objfile
);
17752 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17754 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17757 int endianity
= DW_UNSND (attr
);
17762 byte_order
= BFD_ENDIAN_BIG
;
17764 case DW_END_little
:
17765 byte_order
= BFD_ENDIAN_LITTLE
;
17768 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17775 case DW_ATE_address
:
17776 /* Turn DW_ATE_address into a void * pointer. */
17777 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17778 type
= init_pointer_type (objfile
, bits
, name
, type
);
17780 case DW_ATE_boolean
:
17781 type
= init_boolean_type (objfile
, bits
, 1, name
);
17783 case DW_ATE_complex_float
:
17784 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17786 type
= init_complex_type (objfile
, name
, type
);
17788 case DW_ATE_decimal_float
:
17789 type
= init_decfloat_type (objfile
, bits
, name
);
17792 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17794 case DW_ATE_signed
:
17795 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17797 case DW_ATE_unsigned
:
17798 if (cu
->language
== language_fortran
17800 && startswith (name
, "character("))
17801 type
= init_character_type (objfile
, bits
, 1, name
);
17803 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17805 case DW_ATE_signed_char
:
17806 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17807 || cu
->language
== language_pascal
17808 || cu
->language
== language_fortran
)
17809 type
= init_character_type (objfile
, bits
, 0, name
);
17811 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17813 case DW_ATE_unsigned_char
:
17814 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17815 || cu
->language
== language_pascal
17816 || cu
->language
== language_fortran
17817 || cu
->language
== language_rust
)
17818 type
= init_character_type (objfile
, bits
, 1, name
);
17820 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17825 type
= builtin_type (arch
)->builtin_char16
;
17826 else if (bits
== 32)
17827 type
= builtin_type (arch
)->builtin_char32
;
17830 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17832 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17834 return set_die_type (die
, type
, cu
);
17839 complaint (_("unsupported DW_AT_encoding: '%s'"),
17840 dwarf_type_encoding_name (encoding
));
17841 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17845 if (name
&& strcmp (name
, "char") == 0)
17846 TYPE_NOSIGN (type
) = 1;
17848 maybe_set_alignment (cu
, die
, type
);
17850 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17852 return set_die_type (die
, type
, cu
);
17855 /* Parse dwarf attribute if it's a block, reference or constant and put the
17856 resulting value of the attribute into struct bound_prop.
17857 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17860 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17861 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17862 struct type
*default_type
)
17864 struct dwarf2_property_baton
*baton
;
17865 struct obstack
*obstack
17866 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17868 gdb_assert (default_type
!= NULL
);
17870 if (attr
== NULL
|| prop
== NULL
)
17873 if (attr_form_is_block (attr
))
17875 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17876 baton
->property_type
= default_type
;
17877 baton
->locexpr
.per_cu
= cu
->per_cu
;
17878 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17879 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17880 switch (attr
->name
)
17882 case DW_AT_string_length
:
17883 baton
->locexpr
.is_reference
= true;
17886 baton
->locexpr
.is_reference
= false;
17889 prop
->data
.baton
= baton
;
17890 prop
->kind
= PROP_LOCEXPR
;
17891 gdb_assert (prop
->data
.baton
!= NULL
);
17893 else if (attr_form_is_ref (attr
))
17895 struct dwarf2_cu
*target_cu
= cu
;
17896 struct die_info
*target_die
;
17897 struct attribute
*target_attr
;
17899 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17900 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17901 if (target_attr
== NULL
)
17902 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17904 if (target_attr
== NULL
)
17907 switch (target_attr
->name
)
17909 case DW_AT_location
:
17910 if (attr_form_is_section_offset (target_attr
))
17912 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17913 baton
->property_type
= die_type (target_die
, target_cu
);
17914 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17915 prop
->data
.baton
= baton
;
17916 prop
->kind
= PROP_LOCLIST
;
17917 gdb_assert (prop
->data
.baton
!= NULL
);
17919 else if (attr_form_is_block (target_attr
))
17921 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17922 baton
->property_type
= die_type (target_die
, target_cu
);
17923 baton
->locexpr
.per_cu
= cu
->per_cu
;
17924 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17925 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17926 baton
->locexpr
.is_reference
= true;
17927 prop
->data
.baton
= baton
;
17928 prop
->kind
= PROP_LOCEXPR
;
17929 gdb_assert (prop
->data
.baton
!= NULL
);
17933 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17934 "dynamic property");
17938 case DW_AT_data_member_location
:
17942 if (!handle_data_member_location (target_die
, target_cu
,
17946 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17947 baton
->property_type
= read_type_die (target_die
->parent
,
17949 baton
->offset_info
.offset
= offset
;
17950 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17951 prop
->data
.baton
= baton
;
17952 prop
->kind
= PROP_ADDR_OFFSET
;
17957 else if (attr_form_is_constant (attr
))
17959 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17960 prop
->kind
= PROP_CONST
;
17964 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17965 dwarf2_name (die
, cu
));
17972 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
17973 UNSIGNED_P controls if the integer is unsigned or not. */
17975 static struct type
*
17976 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
17977 int size_in_bytes
, bool unsigned_p
)
17979 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17980 struct type
*int_type
;
17982 /* Helper macro to examine the various builtin types. */
17983 #define TRY_TYPE(F) \
17984 int_type = (unsigned_p \
17985 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17986 : objfile_type (objfile)->builtin_ ## F); \
17987 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17994 TRY_TYPE (long_long
);
17998 gdb_assert_not_reached ("unable to find suitable integer type");
18001 /* Find an integer type the same size as the address size given in the
18002 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
18003 is unsigned or not. */
18005 static struct type
*
18006 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
18009 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
18010 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
18013 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18014 present (which is valid) then compute the default type based on the
18015 compilation units address size. */
18017 static struct type
*
18018 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18020 struct type
*index_type
= die_type (die
, cu
);
18022 /* Dwarf-2 specifications explicitly allows to create subrange types
18023 without specifying a base type.
18024 In that case, the base type must be set to the type of
18025 the lower bound, upper bound or count, in that order, if any of these
18026 three attributes references an object that has a type.
18027 If no base type is found, the Dwarf-2 specifications say that
18028 a signed integer type of size equal to the size of an address should
18030 For the following C code: `extern char gdb_int [];'
18031 GCC produces an empty range DIE.
18032 FIXME: muller/2010-05-28: Possible references to object for low bound,
18033 high bound or count are not yet handled by this code. */
18034 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
18035 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18040 /* Read the given DW_AT_subrange DIE. */
18042 static struct type
*
18043 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18045 struct type
*base_type
, *orig_base_type
;
18046 struct type
*range_type
;
18047 struct attribute
*attr
;
18048 struct dynamic_prop low
, high
;
18049 int low_default_is_valid
;
18050 int high_bound_is_count
= 0;
18052 ULONGEST negative_mask
;
18054 orig_base_type
= read_subrange_index_type (die
, cu
);
18056 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18057 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18058 creating the range type, but we use the result of check_typedef
18059 when examining properties of the type. */
18060 base_type
= check_typedef (orig_base_type
);
18062 /* The die_type call above may have already set the type for this DIE. */
18063 range_type
= get_die_type (die
, cu
);
18067 low
.kind
= PROP_CONST
;
18068 high
.kind
= PROP_CONST
;
18069 high
.data
.const_val
= 0;
18071 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18072 omitting DW_AT_lower_bound. */
18073 switch (cu
->language
)
18076 case language_cplus
:
18077 low
.data
.const_val
= 0;
18078 low_default_is_valid
= 1;
18080 case language_fortran
:
18081 low
.data
.const_val
= 1;
18082 low_default_is_valid
= 1;
18085 case language_objc
:
18086 case language_rust
:
18087 low
.data
.const_val
= 0;
18088 low_default_is_valid
= (cu
->header
.version
>= 4);
18092 case language_pascal
:
18093 low
.data
.const_val
= 1;
18094 low_default_is_valid
= (cu
->header
.version
>= 4);
18097 low
.data
.const_val
= 0;
18098 low_default_is_valid
= 0;
18102 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18103 if (attr
!= nullptr)
18104 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18105 else if (!low_default_is_valid
)
18106 complaint (_("Missing DW_AT_lower_bound "
18107 "- DIE at %s [in module %s]"),
18108 sect_offset_str (die
->sect_off
),
18109 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18111 struct attribute
*attr_ub
, *attr_count
;
18112 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18113 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18115 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18116 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18118 /* If bounds are constant do the final calculation here. */
18119 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18120 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18122 high_bound_is_count
= 1;
18126 if (attr_ub
!= NULL
)
18127 complaint (_("Unresolved DW_AT_upper_bound "
18128 "- DIE at %s [in module %s]"),
18129 sect_offset_str (die
->sect_off
),
18130 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18131 if (attr_count
!= NULL
)
18132 complaint (_("Unresolved DW_AT_count "
18133 "- DIE at %s [in module %s]"),
18134 sect_offset_str (die
->sect_off
),
18135 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18140 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18141 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18142 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18144 /* Normally, the DWARF producers are expected to use a signed
18145 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18146 But this is unfortunately not always the case, as witnessed
18147 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18148 is used instead. To work around that ambiguity, we treat
18149 the bounds as signed, and thus sign-extend their values, when
18150 the base type is signed. */
18152 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18153 if (low
.kind
== PROP_CONST
18154 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18155 low
.data
.const_val
|= negative_mask
;
18156 if (high
.kind
== PROP_CONST
18157 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18158 high
.data
.const_val
|= negative_mask
;
18160 /* Check for bit and byte strides. */
18161 struct dynamic_prop byte_stride_prop
;
18162 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18163 if (attr_byte_stride
!= nullptr)
18165 struct type
*prop_type
18166 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18167 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18171 struct dynamic_prop bit_stride_prop
;
18172 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18173 if (attr_bit_stride
!= nullptr)
18175 /* It only makes sense to have either a bit or byte stride. */
18176 if (attr_byte_stride
!= nullptr)
18178 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18179 "- DIE at %s [in module %s]"),
18180 sect_offset_str (die
->sect_off
),
18181 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18182 attr_bit_stride
= nullptr;
18186 struct type
*prop_type
18187 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18188 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18193 if (attr_byte_stride
!= nullptr
18194 || attr_bit_stride
!= nullptr)
18196 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18197 struct dynamic_prop
*stride
18198 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18201 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18202 &high
, bias
, stride
, byte_stride_p
);
18205 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18207 if (high_bound_is_count
)
18208 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18210 /* Ada expects an empty array on no boundary attributes. */
18211 if (attr
== NULL
&& cu
->language
!= language_ada
)
18212 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18214 name
= dwarf2_name (die
, cu
);
18216 TYPE_NAME (range_type
) = name
;
18218 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18219 if (attr
!= nullptr)
18220 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18222 maybe_set_alignment (cu
, die
, range_type
);
18224 set_die_type (die
, range_type
, cu
);
18226 /* set_die_type should be already done. */
18227 set_descriptive_type (range_type
, die
, cu
);
18232 static struct type
*
18233 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18237 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18239 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18241 /* In Ada, an unspecified type is typically used when the description
18242 of the type is deferred to a different unit. When encountering
18243 such a type, we treat it as a stub, and try to resolve it later on,
18245 if (cu
->language
== language_ada
)
18246 TYPE_STUB (type
) = 1;
18248 return set_die_type (die
, type
, cu
);
18251 /* Read a single die and all its descendents. Set the die's sibling
18252 field to NULL; set other fields in the die correctly, and set all
18253 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18254 location of the info_ptr after reading all of those dies. PARENT
18255 is the parent of the die in question. */
18257 static struct die_info
*
18258 read_die_and_children (const struct die_reader_specs
*reader
,
18259 const gdb_byte
*info_ptr
,
18260 const gdb_byte
**new_info_ptr
,
18261 struct die_info
*parent
)
18263 struct die_info
*die
;
18264 const gdb_byte
*cur_ptr
;
18267 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18270 *new_info_ptr
= cur_ptr
;
18273 store_in_ref_table (die
, reader
->cu
);
18276 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18280 *new_info_ptr
= cur_ptr
;
18283 die
->sibling
= NULL
;
18284 die
->parent
= parent
;
18288 /* Read a die, all of its descendents, and all of its siblings; set
18289 all of the fields of all of the dies correctly. Arguments are as
18290 in read_die_and_children. */
18292 static struct die_info
*
18293 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18294 const gdb_byte
*info_ptr
,
18295 const gdb_byte
**new_info_ptr
,
18296 struct die_info
*parent
)
18298 struct die_info
*first_die
, *last_sibling
;
18299 const gdb_byte
*cur_ptr
;
18301 cur_ptr
= info_ptr
;
18302 first_die
= last_sibling
= NULL
;
18306 struct die_info
*die
18307 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18311 *new_info_ptr
= cur_ptr
;
18318 last_sibling
->sibling
= die
;
18320 last_sibling
= die
;
18324 /* Read a die, all of its descendents, and all of its siblings; set
18325 all of the fields of all of the dies correctly. Arguments are as
18326 in read_die_and_children.
18327 This the main entry point for reading a DIE and all its children. */
18329 static struct die_info
*
18330 read_die_and_siblings (const struct die_reader_specs
*reader
,
18331 const gdb_byte
*info_ptr
,
18332 const gdb_byte
**new_info_ptr
,
18333 struct die_info
*parent
)
18335 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18336 new_info_ptr
, parent
);
18338 if (dwarf_die_debug
)
18340 fprintf_unfiltered (gdb_stdlog
,
18341 "Read die from %s@0x%x of %s:\n",
18342 get_section_name (reader
->die_section
),
18343 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18344 bfd_get_filename (reader
->abfd
));
18345 dump_die (die
, dwarf_die_debug
);
18351 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18353 The caller is responsible for filling in the extra attributes
18354 and updating (*DIEP)->num_attrs.
18355 Set DIEP to point to a newly allocated die with its information,
18356 except for its child, sibling, and parent fields.
18357 Set HAS_CHILDREN to tell whether the die has children or not. */
18359 static const gdb_byte
*
18360 read_full_die_1 (const struct die_reader_specs
*reader
,
18361 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18362 int *has_children
, int num_extra_attrs
)
18364 unsigned int abbrev_number
, bytes_read
, i
;
18365 struct abbrev_info
*abbrev
;
18366 struct die_info
*die
;
18367 struct dwarf2_cu
*cu
= reader
->cu
;
18368 bfd
*abfd
= reader
->abfd
;
18370 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18371 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18372 info_ptr
+= bytes_read
;
18373 if (!abbrev_number
)
18380 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18382 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18384 bfd_get_filename (abfd
));
18386 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18387 die
->sect_off
= sect_off
;
18388 die
->tag
= abbrev
->tag
;
18389 die
->abbrev
= abbrev_number
;
18391 /* Make the result usable.
18392 The caller needs to update num_attrs after adding the extra
18394 die
->num_attrs
= abbrev
->num_attrs
;
18396 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18397 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18401 *has_children
= abbrev
->has_children
;
18405 /* Read a die and all its attributes.
18406 Set DIEP to point to a newly allocated die with its information,
18407 except for its child, sibling, and parent fields.
18408 Set HAS_CHILDREN to tell whether the die has children or not. */
18410 static const gdb_byte
*
18411 read_full_die (const struct die_reader_specs
*reader
,
18412 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18415 const gdb_byte
*result
;
18417 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18419 if (dwarf_die_debug
)
18421 fprintf_unfiltered (gdb_stdlog
,
18422 "Read die from %s@0x%x of %s:\n",
18423 get_section_name (reader
->die_section
),
18424 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18425 bfd_get_filename (reader
->abfd
));
18426 dump_die (*diep
, dwarf_die_debug
);
18432 /* Abbreviation tables.
18434 In DWARF version 2, the description of the debugging information is
18435 stored in a separate .debug_abbrev section. Before we read any
18436 dies from a section we read in all abbreviations and install them
18437 in a hash table. */
18439 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18441 struct abbrev_info
*
18442 abbrev_table::alloc_abbrev ()
18444 struct abbrev_info
*abbrev
;
18446 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18447 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18452 /* Add an abbreviation to the table. */
18455 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18456 struct abbrev_info
*abbrev
)
18458 unsigned int hash_number
;
18460 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18461 abbrev
->next
= m_abbrevs
[hash_number
];
18462 m_abbrevs
[hash_number
] = abbrev
;
18465 /* Look up an abbrev in the table.
18466 Returns NULL if the abbrev is not found. */
18468 struct abbrev_info
*
18469 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18471 unsigned int hash_number
;
18472 struct abbrev_info
*abbrev
;
18474 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18475 abbrev
= m_abbrevs
[hash_number
];
18479 if (abbrev
->number
== abbrev_number
)
18481 abbrev
= abbrev
->next
;
18486 /* Read in an abbrev table. */
18488 static abbrev_table_up
18489 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18490 struct dwarf2_section_info
*section
,
18491 sect_offset sect_off
)
18493 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18494 bfd
*abfd
= get_section_bfd_owner (section
);
18495 const gdb_byte
*abbrev_ptr
;
18496 struct abbrev_info
*cur_abbrev
;
18497 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18498 unsigned int abbrev_form
;
18499 struct attr_abbrev
*cur_attrs
;
18500 unsigned int allocated_attrs
;
18502 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18504 dwarf2_read_section (objfile
, section
);
18505 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18506 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18507 abbrev_ptr
+= bytes_read
;
18509 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18510 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18512 /* Loop until we reach an abbrev number of 0. */
18513 while (abbrev_number
)
18515 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18517 /* read in abbrev header */
18518 cur_abbrev
->number
= abbrev_number
;
18520 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18521 abbrev_ptr
+= bytes_read
;
18522 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18525 /* now read in declarations */
18528 LONGEST implicit_const
;
18530 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18531 abbrev_ptr
+= bytes_read
;
18532 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18533 abbrev_ptr
+= bytes_read
;
18534 if (abbrev_form
== DW_FORM_implicit_const
)
18536 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18538 abbrev_ptr
+= bytes_read
;
18542 /* Initialize it due to a false compiler warning. */
18543 implicit_const
= -1;
18546 if (abbrev_name
== 0)
18549 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18551 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18553 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18556 cur_attrs
[cur_abbrev
->num_attrs
].name
18557 = (enum dwarf_attribute
) abbrev_name
;
18558 cur_attrs
[cur_abbrev
->num_attrs
].form
18559 = (enum dwarf_form
) abbrev_form
;
18560 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18561 ++cur_abbrev
->num_attrs
;
18564 cur_abbrev
->attrs
=
18565 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18566 cur_abbrev
->num_attrs
);
18567 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18568 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18570 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18572 /* Get next abbreviation.
18573 Under Irix6 the abbreviations for a compilation unit are not
18574 always properly terminated with an abbrev number of 0.
18575 Exit loop if we encounter an abbreviation which we have
18576 already read (which means we are about to read the abbreviations
18577 for the next compile unit) or if the end of the abbreviation
18578 table is reached. */
18579 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18581 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18582 abbrev_ptr
+= bytes_read
;
18583 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18588 return abbrev_table
;
18591 /* Returns nonzero if TAG represents a type that we might generate a partial
18595 is_type_tag_for_partial (int tag
)
18600 /* Some types that would be reasonable to generate partial symbols for,
18601 that we don't at present. */
18602 case DW_TAG_array_type
:
18603 case DW_TAG_file_type
:
18604 case DW_TAG_ptr_to_member_type
:
18605 case DW_TAG_set_type
:
18606 case DW_TAG_string_type
:
18607 case DW_TAG_subroutine_type
:
18609 case DW_TAG_base_type
:
18610 case DW_TAG_class_type
:
18611 case DW_TAG_interface_type
:
18612 case DW_TAG_enumeration_type
:
18613 case DW_TAG_structure_type
:
18614 case DW_TAG_subrange_type
:
18615 case DW_TAG_typedef
:
18616 case DW_TAG_union_type
:
18623 /* Load all DIEs that are interesting for partial symbols into memory. */
18625 static struct partial_die_info
*
18626 load_partial_dies (const struct die_reader_specs
*reader
,
18627 const gdb_byte
*info_ptr
, int building_psymtab
)
18629 struct dwarf2_cu
*cu
= reader
->cu
;
18630 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18631 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18632 unsigned int bytes_read
;
18633 unsigned int load_all
= 0;
18634 int nesting_level
= 1;
18639 gdb_assert (cu
->per_cu
!= NULL
);
18640 if (cu
->per_cu
->load_all_dies
)
18644 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18648 &cu
->comp_unit_obstack
,
18649 hashtab_obstack_allocate
,
18650 dummy_obstack_deallocate
);
18654 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18656 /* A NULL abbrev means the end of a series of children. */
18657 if (abbrev
== NULL
)
18659 if (--nesting_level
== 0)
18662 info_ptr
+= bytes_read
;
18663 last_die
= parent_die
;
18664 parent_die
= parent_die
->die_parent
;
18668 /* Check for template arguments. We never save these; if
18669 they're seen, we just mark the parent, and go on our way. */
18670 if (parent_die
!= NULL
18671 && cu
->language
== language_cplus
18672 && (abbrev
->tag
== DW_TAG_template_type_param
18673 || abbrev
->tag
== DW_TAG_template_value_param
))
18675 parent_die
->has_template_arguments
= 1;
18679 /* We don't need a partial DIE for the template argument. */
18680 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18685 /* We only recurse into c++ subprograms looking for template arguments.
18686 Skip their other children. */
18688 && cu
->language
== language_cplus
18689 && parent_die
!= NULL
18690 && parent_die
->tag
== DW_TAG_subprogram
)
18692 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18696 /* Check whether this DIE is interesting enough to save. Normally
18697 we would not be interested in members here, but there may be
18698 later variables referencing them via DW_AT_specification (for
18699 static members). */
18701 && !is_type_tag_for_partial (abbrev
->tag
)
18702 && abbrev
->tag
!= DW_TAG_constant
18703 && abbrev
->tag
!= DW_TAG_enumerator
18704 && abbrev
->tag
!= DW_TAG_subprogram
18705 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18706 && abbrev
->tag
!= DW_TAG_lexical_block
18707 && abbrev
->tag
!= DW_TAG_variable
18708 && abbrev
->tag
!= DW_TAG_namespace
18709 && abbrev
->tag
!= DW_TAG_module
18710 && abbrev
->tag
!= DW_TAG_member
18711 && abbrev
->tag
!= DW_TAG_imported_unit
18712 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18714 /* Otherwise we skip to the next sibling, if any. */
18715 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18719 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18722 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18724 /* This two-pass algorithm for processing partial symbols has a
18725 high cost in cache pressure. Thus, handle some simple cases
18726 here which cover the majority of C partial symbols. DIEs
18727 which neither have specification tags in them, nor could have
18728 specification tags elsewhere pointing at them, can simply be
18729 processed and discarded.
18731 This segment is also optional; scan_partial_symbols and
18732 add_partial_symbol will handle these DIEs if we chain
18733 them in normally. When compilers which do not emit large
18734 quantities of duplicate debug information are more common,
18735 this code can probably be removed. */
18737 /* Any complete simple types at the top level (pretty much all
18738 of them, for a language without namespaces), can be processed
18740 if (parent_die
== NULL
18741 && pdi
.has_specification
== 0
18742 && pdi
.is_declaration
== 0
18743 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18744 || pdi
.tag
== DW_TAG_base_type
18745 || pdi
.tag
== DW_TAG_subrange_type
))
18747 if (building_psymtab
&& pdi
.name
!= NULL
)
18748 add_psymbol_to_list (pdi
.name
, false,
18749 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18750 psymbol_placement::STATIC
,
18751 0, cu
->language
, objfile
);
18752 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18756 /* The exception for DW_TAG_typedef with has_children above is
18757 a workaround of GCC PR debug/47510. In the case of this complaint
18758 type_name_or_error will error on such types later.
18760 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18761 it could not find the child DIEs referenced later, this is checked
18762 above. In correct DWARF DW_TAG_typedef should have no children. */
18764 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18765 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18766 "- DIE at %s [in module %s]"),
18767 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18769 /* If we're at the second level, and we're an enumerator, and
18770 our parent has no specification (meaning possibly lives in a
18771 namespace elsewhere), then we can add the partial symbol now
18772 instead of queueing it. */
18773 if (pdi
.tag
== DW_TAG_enumerator
18774 && parent_die
!= NULL
18775 && parent_die
->die_parent
== NULL
18776 && parent_die
->tag
== DW_TAG_enumeration_type
18777 && parent_die
->has_specification
== 0)
18779 if (pdi
.name
== NULL
)
18780 complaint (_("malformed enumerator DIE ignored"));
18781 else if (building_psymtab
)
18782 add_psymbol_to_list (pdi
.name
, false,
18783 VAR_DOMAIN
, LOC_CONST
, -1,
18784 cu
->language
== language_cplus
18785 ? psymbol_placement::GLOBAL
18786 : psymbol_placement::STATIC
,
18787 0, cu
->language
, objfile
);
18789 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18793 struct partial_die_info
*part_die
18794 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18796 /* We'll save this DIE so link it in. */
18797 part_die
->die_parent
= parent_die
;
18798 part_die
->die_sibling
= NULL
;
18799 part_die
->die_child
= NULL
;
18801 if (last_die
&& last_die
== parent_die
)
18802 last_die
->die_child
= part_die
;
18804 last_die
->die_sibling
= part_die
;
18806 last_die
= part_die
;
18808 if (first_die
== NULL
)
18809 first_die
= part_die
;
18811 /* Maybe add the DIE to the hash table. Not all DIEs that we
18812 find interesting need to be in the hash table, because we
18813 also have the parent/sibling/child chains; only those that we
18814 might refer to by offset later during partial symbol reading.
18816 For now this means things that might have be the target of a
18817 DW_AT_specification, DW_AT_abstract_origin, or
18818 DW_AT_extension. DW_AT_extension will refer only to
18819 namespaces; DW_AT_abstract_origin refers to functions (and
18820 many things under the function DIE, but we do not recurse
18821 into function DIEs during partial symbol reading) and
18822 possibly variables as well; DW_AT_specification refers to
18823 declarations. Declarations ought to have the DW_AT_declaration
18824 flag. It happens that GCC forgets to put it in sometimes, but
18825 only for functions, not for types.
18827 Adding more things than necessary to the hash table is harmless
18828 except for the performance cost. Adding too few will result in
18829 wasted time in find_partial_die, when we reread the compilation
18830 unit with load_all_dies set. */
18833 || abbrev
->tag
== DW_TAG_constant
18834 || abbrev
->tag
== DW_TAG_subprogram
18835 || abbrev
->tag
== DW_TAG_variable
18836 || abbrev
->tag
== DW_TAG_namespace
18837 || part_die
->is_declaration
)
18841 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18842 to_underlying (part_die
->sect_off
),
18847 /* For some DIEs we want to follow their children (if any). For C
18848 we have no reason to follow the children of structures; for other
18849 languages we have to, so that we can get at method physnames
18850 to infer fully qualified class names, for DW_AT_specification,
18851 and for C++ template arguments. For C++, we also look one level
18852 inside functions to find template arguments (if the name of the
18853 function does not already contain the template arguments).
18855 For Ada and Fortran, we need to scan the children of subprograms
18856 and lexical blocks as well because these languages allow the
18857 definition of nested entities that could be interesting for the
18858 debugger, such as nested subprograms for instance. */
18859 if (last_die
->has_children
18861 || last_die
->tag
== DW_TAG_namespace
18862 || last_die
->tag
== DW_TAG_module
18863 || last_die
->tag
== DW_TAG_enumeration_type
18864 || (cu
->language
== language_cplus
18865 && last_die
->tag
== DW_TAG_subprogram
18866 && (last_die
->name
== NULL
18867 || strchr (last_die
->name
, '<') == NULL
))
18868 || (cu
->language
!= language_c
18869 && (last_die
->tag
== DW_TAG_class_type
18870 || last_die
->tag
== DW_TAG_interface_type
18871 || last_die
->tag
== DW_TAG_structure_type
18872 || last_die
->tag
== DW_TAG_union_type
))
18873 || ((cu
->language
== language_ada
18874 || cu
->language
== language_fortran
)
18875 && (last_die
->tag
== DW_TAG_subprogram
18876 || last_die
->tag
== DW_TAG_lexical_block
))))
18879 parent_die
= last_die
;
18883 /* Otherwise we skip to the next sibling, if any. */
18884 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18886 /* Back to the top, do it again. */
18890 partial_die_info::partial_die_info (sect_offset sect_off_
,
18891 struct abbrev_info
*abbrev
)
18892 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18896 /* Read a minimal amount of information into the minimal die structure.
18897 INFO_PTR should point just after the initial uleb128 of a DIE. */
18900 partial_die_info::read (const struct die_reader_specs
*reader
,
18901 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18903 struct dwarf2_cu
*cu
= reader
->cu
;
18904 struct dwarf2_per_objfile
*dwarf2_per_objfile
18905 = cu
->per_cu
->dwarf2_per_objfile
;
18907 int has_low_pc_attr
= 0;
18908 int has_high_pc_attr
= 0;
18909 int high_pc_relative
= 0;
18911 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18913 struct attribute attr
;
18915 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18917 /* Store the data if it is of an attribute we want to keep in a
18918 partial symbol table. */
18924 case DW_TAG_compile_unit
:
18925 case DW_TAG_partial_unit
:
18926 case DW_TAG_type_unit
:
18927 /* Compilation units have a DW_AT_name that is a filename, not
18928 a source language identifier. */
18929 case DW_TAG_enumeration_type
:
18930 case DW_TAG_enumerator
:
18931 /* These tags always have simple identifiers already; no need
18932 to canonicalize them. */
18933 name
= DW_STRING (&attr
);
18937 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18940 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18941 &objfile
->per_bfd
->storage_obstack
);
18946 case DW_AT_linkage_name
:
18947 case DW_AT_MIPS_linkage_name
:
18948 /* Note that both forms of linkage name might appear. We
18949 assume they will be the same, and we only store the last
18951 linkage_name
= DW_STRING (&attr
);
18954 has_low_pc_attr
= 1;
18955 lowpc
= attr_value_as_address (&attr
);
18957 case DW_AT_high_pc
:
18958 has_high_pc_attr
= 1;
18959 highpc
= attr_value_as_address (&attr
);
18960 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18961 high_pc_relative
= 1;
18963 case DW_AT_location
:
18964 /* Support the .debug_loc offsets. */
18965 if (attr_form_is_block (&attr
))
18967 d
.locdesc
= DW_BLOCK (&attr
);
18969 else if (attr_form_is_section_offset (&attr
))
18971 dwarf2_complex_location_expr_complaint ();
18975 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18976 "partial symbol information");
18979 case DW_AT_external
:
18980 is_external
= DW_UNSND (&attr
);
18982 case DW_AT_declaration
:
18983 is_declaration
= DW_UNSND (&attr
);
18988 case DW_AT_abstract_origin
:
18989 case DW_AT_specification
:
18990 case DW_AT_extension
:
18991 has_specification
= 1;
18992 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18993 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18994 || cu
->per_cu
->is_dwz
);
18996 case DW_AT_sibling
:
18997 /* Ignore absolute siblings, they might point outside of
18998 the current compile unit. */
18999 if (attr
.form
== DW_FORM_ref_addr
)
19000 complaint (_("ignoring absolute DW_AT_sibling"));
19003 const gdb_byte
*buffer
= reader
->buffer
;
19004 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
19005 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19007 if (sibling_ptr
< info_ptr
)
19008 complaint (_("DW_AT_sibling points backwards"));
19009 else if (sibling_ptr
> reader
->buffer_end
)
19010 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19012 sibling
= sibling_ptr
;
19015 case DW_AT_byte_size
:
19018 case DW_AT_const_value
:
19019 has_const_value
= 1;
19021 case DW_AT_calling_convention
:
19022 /* DWARF doesn't provide a way to identify a program's source-level
19023 entry point. DW_AT_calling_convention attributes are only meant
19024 to describe functions' calling conventions.
19026 However, because it's a necessary piece of information in
19027 Fortran, and before DWARF 4 DW_CC_program was the only
19028 piece of debugging information whose definition refers to
19029 a 'main program' at all, several compilers marked Fortran
19030 main programs with DW_CC_program --- even when those
19031 functions use the standard calling conventions.
19033 Although DWARF now specifies a way to provide this
19034 information, we support this practice for backward
19036 if (DW_UNSND (&attr
) == DW_CC_program
19037 && cu
->language
== language_fortran
)
19038 main_subprogram
= 1;
19041 if (DW_UNSND (&attr
) == DW_INL_inlined
19042 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19043 may_be_inlined
= 1;
19047 if (tag
== DW_TAG_imported_unit
)
19049 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19050 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19051 || cu
->per_cu
->is_dwz
);
19055 case DW_AT_main_subprogram
:
19056 main_subprogram
= DW_UNSND (&attr
);
19061 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19062 but that requires a full DIE, so instead we just
19064 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
19065 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19066 + (need_ranges_base
19070 /* Value of the DW_AT_ranges attribute is the offset in the
19071 .debug_ranges section. */
19072 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19083 /* For Ada, if both the name and the linkage name appear, we prefer
19084 the latter. This lets "catch exception" work better, regardless
19085 of the order in which the name and linkage name were emitted.
19086 Really, though, this is just a workaround for the fact that gdb
19087 doesn't store both the name and the linkage name. */
19088 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19089 name
= linkage_name
;
19091 if (high_pc_relative
)
19094 if (has_low_pc_attr
&& has_high_pc_attr
)
19096 /* When using the GNU linker, .gnu.linkonce. sections are used to
19097 eliminate duplicate copies of functions and vtables and such.
19098 The linker will arbitrarily choose one and discard the others.
19099 The AT_*_pc values for such functions refer to local labels in
19100 these sections. If the section from that file was discarded, the
19101 labels are not in the output, so the relocs get a value of 0.
19102 If this is a discarded function, mark the pc bounds as invalid,
19103 so that GDB will ignore it. */
19104 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19106 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19107 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19109 complaint (_("DW_AT_low_pc %s is zero "
19110 "for DIE at %s [in module %s]"),
19111 paddress (gdbarch
, lowpc
),
19112 sect_offset_str (sect_off
),
19113 objfile_name (objfile
));
19115 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19116 else if (lowpc
>= highpc
)
19118 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19119 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19121 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19122 "for DIE at %s [in module %s]"),
19123 paddress (gdbarch
, lowpc
),
19124 paddress (gdbarch
, highpc
),
19125 sect_offset_str (sect_off
),
19126 objfile_name (objfile
));
19135 /* Find a cached partial DIE at OFFSET in CU. */
19137 struct partial_die_info
*
19138 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19140 struct partial_die_info
*lookup_die
= NULL
;
19141 struct partial_die_info
part_die (sect_off
);
19143 lookup_die
= ((struct partial_die_info
*)
19144 htab_find_with_hash (partial_dies
, &part_die
,
19145 to_underlying (sect_off
)));
19150 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19151 except in the case of .debug_types DIEs which do not reference
19152 outside their CU (they do however referencing other types via
19153 DW_FORM_ref_sig8). */
19155 static const struct cu_partial_die_info
19156 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19158 struct dwarf2_per_objfile
*dwarf2_per_objfile
19159 = cu
->per_cu
->dwarf2_per_objfile
;
19160 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19161 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19162 struct partial_die_info
*pd
= NULL
;
19164 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19165 && offset_in_cu_p (&cu
->header
, sect_off
))
19167 pd
= cu
->find_partial_die (sect_off
);
19170 /* We missed recording what we needed.
19171 Load all dies and try again. */
19172 per_cu
= cu
->per_cu
;
19176 /* TUs don't reference other CUs/TUs (except via type signatures). */
19177 if (cu
->per_cu
->is_debug_types
)
19179 error (_("Dwarf Error: Type Unit at offset %s contains"
19180 " external reference to offset %s [in module %s].\n"),
19181 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19182 bfd_get_filename (objfile
->obfd
));
19184 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19185 dwarf2_per_objfile
);
19187 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19188 load_partial_comp_unit (per_cu
);
19190 per_cu
->cu
->last_used
= 0;
19191 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19194 /* If we didn't find it, and not all dies have been loaded,
19195 load them all and try again. */
19197 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19199 per_cu
->load_all_dies
= 1;
19201 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19202 THIS_CU->cu may already be in use. So we can't just free it and
19203 replace its DIEs with the ones we read in. Instead, we leave those
19204 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19205 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19207 load_partial_comp_unit (per_cu
);
19209 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19213 internal_error (__FILE__
, __LINE__
,
19214 _("could not find partial DIE %s "
19215 "in cache [from module %s]\n"),
19216 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19217 return { per_cu
->cu
, pd
};
19220 /* See if we can figure out if the class lives in a namespace. We do
19221 this by looking for a member function; its demangled name will
19222 contain namespace info, if there is any. */
19225 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19226 struct dwarf2_cu
*cu
)
19228 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19229 what template types look like, because the demangler
19230 frequently doesn't give the same name as the debug info. We
19231 could fix this by only using the demangled name to get the
19232 prefix (but see comment in read_structure_type). */
19234 struct partial_die_info
*real_pdi
;
19235 struct partial_die_info
*child_pdi
;
19237 /* If this DIE (this DIE's specification, if any) has a parent, then
19238 we should not do this. We'll prepend the parent's fully qualified
19239 name when we create the partial symbol. */
19241 real_pdi
= struct_pdi
;
19242 while (real_pdi
->has_specification
)
19244 auto res
= find_partial_die (real_pdi
->spec_offset
,
19245 real_pdi
->spec_is_dwz
, cu
);
19246 real_pdi
= res
.pdi
;
19250 if (real_pdi
->die_parent
!= NULL
)
19253 for (child_pdi
= struct_pdi
->die_child
;
19255 child_pdi
= child_pdi
->die_sibling
)
19257 if (child_pdi
->tag
== DW_TAG_subprogram
19258 && child_pdi
->linkage_name
!= NULL
)
19260 char *actual_class_name
19261 = language_class_name_from_physname (cu
->language_defn
,
19262 child_pdi
->linkage_name
);
19263 if (actual_class_name
!= NULL
)
19265 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19267 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19268 actual_class_name
);
19269 xfree (actual_class_name
);
19277 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19279 /* Once we've fixed up a die, there's no point in doing so again.
19280 This also avoids a memory leak if we were to call
19281 guess_partial_die_structure_name multiple times. */
19285 /* If we found a reference attribute and the DIE has no name, try
19286 to find a name in the referred to DIE. */
19288 if (name
== NULL
&& has_specification
)
19290 struct partial_die_info
*spec_die
;
19292 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19293 spec_die
= res
.pdi
;
19296 spec_die
->fixup (cu
);
19298 if (spec_die
->name
)
19300 name
= spec_die
->name
;
19302 /* Copy DW_AT_external attribute if it is set. */
19303 if (spec_die
->is_external
)
19304 is_external
= spec_die
->is_external
;
19308 /* Set default names for some unnamed DIEs. */
19310 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19311 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19313 /* If there is no parent die to provide a namespace, and there are
19314 children, see if we can determine the namespace from their linkage
19316 if (cu
->language
== language_cplus
19317 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19318 && die_parent
== NULL
19320 && (tag
== DW_TAG_class_type
19321 || tag
== DW_TAG_structure_type
19322 || tag
== DW_TAG_union_type
))
19323 guess_partial_die_structure_name (this, cu
);
19325 /* GCC might emit a nameless struct or union that has a linkage
19326 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19328 && (tag
== DW_TAG_class_type
19329 || tag
== DW_TAG_interface_type
19330 || tag
== DW_TAG_structure_type
19331 || tag
== DW_TAG_union_type
)
19332 && linkage_name
!= NULL
)
19336 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19341 /* Strip any leading namespaces/classes, keep only the base name.
19342 DW_AT_name for named DIEs does not contain the prefixes. */
19343 base
= strrchr (demangled
, ':');
19344 if (base
&& base
> demangled
&& base
[-1] == ':')
19349 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19350 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19358 /* Read an attribute value described by an attribute form. */
19360 static const gdb_byte
*
19361 read_attribute_value (const struct die_reader_specs
*reader
,
19362 struct attribute
*attr
, unsigned form
,
19363 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19365 struct dwarf2_cu
*cu
= reader
->cu
;
19366 struct dwarf2_per_objfile
*dwarf2_per_objfile
19367 = cu
->per_cu
->dwarf2_per_objfile
;
19368 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19369 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19370 bfd
*abfd
= reader
->abfd
;
19371 struct comp_unit_head
*cu_header
= &cu
->header
;
19372 unsigned int bytes_read
;
19373 struct dwarf_block
*blk
;
19375 attr
->form
= (enum dwarf_form
) form
;
19378 case DW_FORM_ref_addr
:
19379 if (cu
->header
.version
== 2)
19380 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19382 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19383 &cu
->header
, &bytes_read
);
19384 info_ptr
+= bytes_read
;
19386 case DW_FORM_GNU_ref_alt
:
19387 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19388 info_ptr
+= bytes_read
;
19391 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19392 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19393 info_ptr
+= bytes_read
;
19395 case DW_FORM_block2
:
19396 blk
= dwarf_alloc_block (cu
);
19397 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19399 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19400 info_ptr
+= blk
->size
;
19401 DW_BLOCK (attr
) = blk
;
19403 case DW_FORM_block4
:
19404 blk
= dwarf_alloc_block (cu
);
19405 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19407 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19408 info_ptr
+= blk
->size
;
19409 DW_BLOCK (attr
) = blk
;
19411 case DW_FORM_data2
:
19412 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19415 case DW_FORM_data4
:
19416 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19419 case DW_FORM_data8
:
19420 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19423 case DW_FORM_data16
:
19424 blk
= dwarf_alloc_block (cu
);
19426 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19428 DW_BLOCK (attr
) = blk
;
19430 case DW_FORM_sec_offset
:
19431 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19432 info_ptr
+= bytes_read
;
19434 case DW_FORM_string
:
19435 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19436 DW_STRING_IS_CANONICAL (attr
) = 0;
19437 info_ptr
+= bytes_read
;
19440 if (!cu
->per_cu
->is_dwz
)
19442 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19443 abfd
, info_ptr
, cu_header
,
19445 DW_STRING_IS_CANONICAL (attr
) = 0;
19446 info_ptr
+= bytes_read
;
19450 case DW_FORM_line_strp
:
19451 if (!cu
->per_cu
->is_dwz
)
19453 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19455 cu_header
, &bytes_read
);
19456 DW_STRING_IS_CANONICAL (attr
) = 0;
19457 info_ptr
+= bytes_read
;
19461 case DW_FORM_GNU_strp_alt
:
19463 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19464 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19467 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19469 DW_STRING_IS_CANONICAL (attr
) = 0;
19470 info_ptr
+= bytes_read
;
19473 case DW_FORM_exprloc
:
19474 case DW_FORM_block
:
19475 blk
= dwarf_alloc_block (cu
);
19476 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19477 info_ptr
+= bytes_read
;
19478 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19479 info_ptr
+= blk
->size
;
19480 DW_BLOCK (attr
) = blk
;
19482 case DW_FORM_block1
:
19483 blk
= dwarf_alloc_block (cu
);
19484 blk
->size
= read_1_byte (abfd
, info_ptr
);
19486 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19487 info_ptr
+= blk
->size
;
19488 DW_BLOCK (attr
) = blk
;
19490 case DW_FORM_data1
:
19491 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19495 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19498 case DW_FORM_flag_present
:
19499 DW_UNSND (attr
) = 1;
19501 case DW_FORM_sdata
:
19502 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19503 info_ptr
+= bytes_read
;
19505 case DW_FORM_udata
:
19506 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19507 info_ptr
+= bytes_read
;
19510 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19511 + read_1_byte (abfd
, info_ptr
));
19515 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19516 + read_2_bytes (abfd
, info_ptr
));
19520 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19521 + read_4_bytes (abfd
, info_ptr
));
19525 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19526 + read_8_bytes (abfd
, info_ptr
));
19529 case DW_FORM_ref_sig8
:
19530 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19533 case DW_FORM_ref_udata
:
19534 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19535 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19536 info_ptr
+= bytes_read
;
19538 case DW_FORM_indirect
:
19539 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19540 info_ptr
+= bytes_read
;
19541 if (form
== DW_FORM_implicit_const
)
19543 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19544 info_ptr
+= bytes_read
;
19546 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19549 case DW_FORM_implicit_const
:
19550 DW_SND (attr
) = implicit_const
;
19552 case DW_FORM_addrx
:
19553 case DW_FORM_GNU_addr_index
:
19554 if (reader
->dwo_file
== NULL
)
19556 /* For now flag a hard error.
19557 Later we can turn this into a complaint. */
19558 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19559 dwarf_form_name (form
),
19560 bfd_get_filename (abfd
));
19562 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19563 info_ptr
+= bytes_read
;
19566 case DW_FORM_strx1
:
19567 case DW_FORM_strx2
:
19568 case DW_FORM_strx3
:
19569 case DW_FORM_strx4
:
19570 case DW_FORM_GNU_str_index
:
19571 if (reader
->dwo_file
== NULL
)
19573 /* For now flag a hard error.
19574 Later we can turn this into a complaint if warranted. */
19575 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19576 dwarf_form_name (form
),
19577 bfd_get_filename (abfd
));
19580 ULONGEST str_index
;
19581 if (form
== DW_FORM_strx1
)
19583 str_index
= read_1_byte (abfd
, info_ptr
);
19586 else if (form
== DW_FORM_strx2
)
19588 str_index
= read_2_bytes (abfd
, info_ptr
);
19591 else if (form
== DW_FORM_strx3
)
19593 str_index
= read_3_bytes (abfd
, info_ptr
);
19596 else if (form
== DW_FORM_strx4
)
19598 str_index
= read_4_bytes (abfd
, info_ptr
);
19603 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19604 info_ptr
+= bytes_read
;
19606 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19607 DW_STRING_IS_CANONICAL (attr
) = 0;
19611 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19612 dwarf_form_name (form
),
19613 bfd_get_filename (abfd
));
19617 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19618 attr
->form
= DW_FORM_GNU_ref_alt
;
19620 /* We have seen instances where the compiler tried to emit a byte
19621 size attribute of -1 which ended up being encoded as an unsigned
19622 0xffffffff. Although 0xffffffff is technically a valid size value,
19623 an object of this size seems pretty unlikely so we can relatively
19624 safely treat these cases as if the size attribute was invalid and
19625 treat them as zero by default. */
19626 if (attr
->name
== DW_AT_byte_size
19627 && form
== DW_FORM_data4
19628 && DW_UNSND (attr
) >= 0xffffffff)
19631 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19632 hex_string (DW_UNSND (attr
)));
19633 DW_UNSND (attr
) = 0;
19639 /* Read an attribute described by an abbreviated attribute. */
19641 static const gdb_byte
*
19642 read_attribute (const struct die_reader_specs
*reader
,
19643 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19644 const gdb_byte
*info_ptr
)
19646 attr
->name
= abbrev
->name
;
19647 return read_attribute_value (reader
, attr
, abbrev
->form
,
19648 abbrev
->implicit_const
, info_ptr
);
19651 /* Read dwarf information from a buffer. */
19653 static unsigned int
19654 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19656 return bfd_get_8 (abfd
, buf
);
19660 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19662 return bfd_get_signed_8 (abfd
, buf
);
19665 static unsigned int
19666 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19668 return bfd_get_16 (abfd
, buf
);
19672 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19674 return bfd_get_signed_16 (abfd
, buf
);
19677 static unsigned int
19678 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19680 unsigned int result
= 0;
19681 for (int i
= 0; i
< 3; ++i
)
19683 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19685 result
|= ((unsigned int) byte
<< (i
* 8));
19690 static unsigned int
19691 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19693 return bfd_get_32 (abfd
, buf
);
19697 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19699 return bfd_get_signed_32 (abfd
, buf
);
19703 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19705 return bfd_get_64 (abfd
, buf
);
19709 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19710 unsigned int *bytes_read
)
19712 struct comp_unit_head
*cu_header
= &cu
->header
;
19713 CORE_ADDR retval
= 0;
19715 if (cu_header
->signed_addr_p
)
19717 switch (cu_header
->addr_size
)
19720 retval
= bfd_get_signed_16 (abfd
, buf
);
19723 retval
= bfd_get_signed_32 (abfd
, buf
);
19726 retval
= bfd_get_signed_64 (abfd
, buf
);
19729 internal_error (__FILE__
, __LINE__
,
19730 _("read_address: bad switch, signed [in module %s]"),
19731 bfd_get_filename (abfd
));
19736 switch (cu_header
->addr_size
)
19739 retval
= bfd_get_16 (abfd
, buf
);
19742 retval
= bfd_get_32 (abfd
, buf
);
19745 retval
= bfd_get_64 (abfd
, buf
);
19748 internal_error (__FILE__
, __LINE__
,
19749 _("read_address: bad switch, "
19750 "unsigned [in module %s]"),
19751 bfd_get_filename (abfd
));
19755 *bytes_read
= cu_header
->addr_size
;
19759 /* Read the initial length from a section. The (draft) DWARF 3
19760 specification allows the initial length to take up either 4 bytes
19761 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19762 bytes describe the length and all offsets will be 8 bytes in length
19765 An older, non-standard 64-bit format is also handled by this
19766 function. The older format in question stores the initial length
19767 as an 8-byte quantity without an escape value. Lengths greater
19768 than 2^32 aren't very common which means that the initial 4 bytes
19769 is almost always zero. Since a length value of zero doesn't make
19770 sense for the 32-bit format, this initial zero can be considered to
19771 be an escape value which indicates the presence of the older 64-bit
19772 format. As written, the code can't detect (old format) lengths
19773 greater than 4GB. If it becomes necessary to handle lengths
19774 somewhat larger than 4GB, we could allow other small values (such
19775 as the non-sensical values of 1, 2, and 3) to also be used as
19776 escape values indicating the presence of the old format.
19778 The value returned via bytes_read should be used to increment the
19779 relevant pointer after calling read_initial_length().
19781 [ Note: read_initial_length() and read_offset() are based on the
19782 document entitled "DWARF Debugging Information Format", revision
19783 3, draft 8, dated November 19, 2001. This document was obtained
19786 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19788 This document is only a draft and is subject to change. (So beware.)
19790 Details regarding the older, non-standard 64-bit format were
19791 determined empirically by examining 64-bit ELF files produced by
19792 the SGI toolchain on an IRIX 6.5 machine.
19794 - Kevin, July 16, 2002
19798 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19800 LONGEST length
= bfd_get_32 (abfd
, buf
);
19802 if (length
== 0xffffffff)
19804 length
= bfd_get_64 (abfd
, buf
+ 4);
19807 else if (length
== 0)
19809 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19810 length
= bfd_get_64 (abfd
, buf
);
19821 /* Cover function for read_initial_length.
19822 Returns the length of the object at BUF, and stores the size of the
19823 initial length in *BYTES_READ and stores the size that offsets will be in
19825 If the initial length size is not equivalent to that specified in
19826 CU_HEADER then issue a complaint.
19827 This is useful when reading non-comp-unit headers. */
19830 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19831 const struct comp_unit_head
*cu_header
,
19832 unsigned int *bytes_read
,
19833 unsigned int *offset_size
)
19835 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19837 gdb_assert (cu_header
->initial_length_size
== 4
19838 || cu_header
->initial_length_size
== 8
19839 || cu_header
->initial_length_size
== 12);
19841 if (cu_header
->initial_length_size
!= *bytes_read
)
19842 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19844 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19848 /* Read an offset from the data stream. The size of the offset is
19849 given by cu_header->offset_size. */
19852 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19853 const struct comp_unit_head
*cu_header
,
19854 unsigned int *bytes_read
)
19856 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19858 *bytes_read
= cu_header
->offset_size
;
19862 /* Read an offset from the data stream. */
19865 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19867 LONGEST retval
= 0;
19869 switch (offset_size
)
19872 retval
= bfd_get_32 (abfd
, buf
);
19875 retval
= bfd_get_64 (abfd
, buf
);
19878 internal_error (__FILE__
, __LINE__
,
19879 _("read_offset_1: bad switch [in module %s]"),
19880 bfd_get_filename (abfd
));
19886 static const gdb_byte
*
19887 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19889 /* If the size of a host char is 8 bits, we can return a pointer
19890 to the buffer, otherwise we have to copy the data to a buffer
19891 allocated on the temporary obstack. */
19892 gdb_assert (HOST_CHAR_BIT
== 8);
19896 static const char *
19897 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19898 unsigned int *bytes_read_ptr
)
19900 /* If the size of a host char is 8 bits, we can return a pointer
19901 to the string, otherwise we have to copy the string to a buffer
19902 allocated on the temporary obstack. */
19903 gdb_assert (HOST_CHAR_BIT
== 8);
19906 *bytes_read_ptr
= 1;
19909 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19910 return (const char *) buf
;
19913 /* Return pointer to string at section SECT offset STR_OFFSET with error
19914 reporting strings FORM_NAME and SECT_NAME. */
19916 static const char *
19917 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19918 bfd
*abfd
, LONGEST str_offset
,
19919 struct dwarf2_section_info
*sect
,
19920 const char *form_name
,
19921 const char *sect_name
)
19923 dwarf2_read_section (objfile
, sect
);
19924 if (sect
->buffer
== NULL
)
19925 error (_("%s used without %s section [in module %s]"),
19926 form_name
, sect_name
, bfd_get_filename (abfd
));
19927 if (str_offset
>= sect
->size
)
19928 error (_("%s pointing outside of %s section [in module %s]"),
19929 form_name
, sect_name
, bfd_get_filename (abfd
));
19930 gdb_assert (HOST_CHAR_BIT
== 8);
19931 if (sect
->buffer
[str_offset
] == '\0')
19933 return (const char *) (sect
->buffer
+ str_offset
);
19936 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19938 static const char *
19939 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19940 bfd
*abfd
, LONGEST str_offset
)
19942 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19944 &dwarf2_per_objfile
->str
,
19945 "DW_FORM_strp", ".debug_str");
19948 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19950 static const char *
19951 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19952 bfd
*abfd
, LONGEST str_offset
)
19954 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19956 &dwarf2_per_objfile
->line_str
,
19957 "DW_FORM_line_strp",
19958 ".debug_line_str");
19961 /* Read a string at offset STR_OFFSET in the .debug_str section from
19962 the .dwz file DWZ. Throw an error if the offset is too large. If
19963 the string consists of a single NUL byte, return NULL; otherwise
19964 return a pointer to the string. */
19966 static const char *
19967 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19968 LONGEST str_offset
)
19970 dwarf2_read_section (objfile
, &dwz
->str
);
19972 if (dwz
->str
.buffer
== NULL
)
19973 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19974 "section [in module %s]"),
19975 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19976 if (str_offset
>= dwz
->str
.size
)
19977 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19978 ".debug_str section [in module %s]"),
19979 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19980 gdb_assert (HOST_CHAR_BIT
== 8);
19981 if (dwz
->str
.buffer
[str_offset
] == '\0')
19983 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19986 /* Return pointer to string at .debug_str offset as read from BUF.
19987 BUF is assumed to be in a compilation unit described by CU_HEADER.
19988 Return *BYTES_READ_PTR count of bytes read from BUF. */
19990 static const char *
19991 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19992 const gdb_byte
*buf
,
19993 const struct comp_unit_head
*cu_header
,
19994 unsigned int *bytes_read_ptr
)
19996 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19998 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
20001 /* Return pointer to string at .debug_line_str offset as read from BUF.
20002 BUF is assumed to be in a compilation unit described by CU_HEADER.
20003 Return *BYTES_READ_PTR count of bytes read from BUF. */
20005 static const char *
20006 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20007 bfd
*abfd
, const gdb_byte
*buf
,
20008 const struct comp_unit_head
*cu_header
,
20009 unsigned int *bytes_read_ptr
)
20011 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20013 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
20018 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20019 unsigned int *bytes_read_ptr
)
20022 unsigned int num_read
;
20024 unsigned char byte
;
20031 byte
= bfd_get_8 (abfd
, buf
);
20034 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20035 if ((byte
& 128) == 0)
20041 *bytes_read_ptr
= num_read
;
20046 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20047 unsigned int *bytes_read_ptr
)
20050 int shift
, num_read
;
20051 unsigned char byte
;
20058 byte
= bfd_get_8 (abfd
, buf
);
20061 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20063 if ((byte
& 128) == 0)
20068 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
20069 result
|= -(((ULONGEST
) 1) << shift
);
20070 *bytes_read_ptr
= num_read
;
20074 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20075 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
20076 ADDR_SIZE is the size of addresses from the CU header. */
20079 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20080 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
20082 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20083 bfd
*abfd
= objfile
->obfd
;
20084 const gdb_byte
*info_ptr
;
20086 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20087 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20088 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20089 objfile_name (objfile
));
20090 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
20091 error (_("DW_FORM_addr_index pointing outside of "
20092 ".debug_addr section [in module %s]"),
20093 objfile_name (objfile
));
20094 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20095 + addr_base
+ addr_index
* addr_size
);
20096 if (addr_size
== 4)
20097 return bfd_get_32 (abfd
, info_ptr
);
20099 return bfd_get_64 (abfd
, info_ptr
);
20102 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20105 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20107 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20108 cu
->addr_base
, cu
->header
.addr_size
);
20111 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20114 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20115 unsigned int *bytes_read
)
20117 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20118 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20120 return read_addr_index (cu
, addr_index
);
20123 /* Data structure to pass results from dwarf2_read_addr_index_reader
20124 back to dwarf2_read_addr_index. */
20126 struct dwarf2_read_addr_index_data
20128 ULONGEST addr_base
;
20132 /* die_reader_func for dwarf2_read_addr_index. */
20135 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
20136 const gdb_byte
*info_ptr
,
20137 struct die_info
*comp_unit_die
,
20141 struct dwarf2_cu
*cu
= reader
->cu
;
20142 struct dwarf2_read_addr_index_data
*aidata
=
20143 (struct dwarf2_read_addr_index_data
*) data
;
20145 aidata
->addr_base
= cu
->addr_base
;
20146 aidata
->addr_size
= cu
->header
.addr_size
;
20149 /* Given an index in .debug_addr, fetch the value.
20150 NOTE: This can be called during dwarf expression evaluation,
20151 long after the debug information has been read, and thus per_cu->cu
20152 may no longer exist. */
20155 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20156 unsigned int addr_index
)
20158 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20159 struct dwarf2_cu
*cu
= per_cu
->cu
;
20160 ULONGEST addr_base
;
20163 /* We need addr_base and addr_size.
20164 If we don't have PER_CU->cu, we have to get it.
20165 Nasty, but the alternative is storing the needed info in PER_CU,
20166 which at this point doesn't seem justified: it's not clear how frequently
20167 it would get used and it would increase the size of every PER_CU.
20168 Entry points like dwarf2_per_cu_addr_size do a similar thing
20169 so we're not in uncharted territory here.
20170 Alas we need to be a bit more complicated as addr_base is contained
20173 We don't need to read the entire CU(/TU).
20174 We just need the header and top level die.
20176 IWBN to use the aging mechanism to let us lazily later discard the CU.
20177 For now we skip this optimization. */
20181 addr_base
= cu
->addr_base
;
20182 addr_size
= cu
->header
.addr_size
;
20186 struct dwarf2_read_addr_index_data aidata
;
20188 /* Note: We can't use init_cutu_and_read_dies_simple here,
20189 we need addr_base. */
20190 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
20191 dwarf2_read_addr_index_reader
, &aidata
);
20192 addr_base
= aidata
.addr_base
;
20193 addr_size
= aidata
.addr_size
;
20196 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20200 /* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
20201 This is only used by the Fission support. */
20203 static const char *
20204 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20206 struct dwarf2_cu
*cu
= reader
->cu
;
20207 struct dwarf2_per_objfile
*dwarf2_per_objfile
20208 = cu
->per_cu
->dwarf2_per_objfile
;
20209 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20210 const char *objf_name
= objfile_name (objfile
);
20211 bfd
*abfd
= objfile
->obfd
;
20212 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20213 struct dwarf2_section_info
*str_offsets_section
=
20214 &reader
->dwo_file
->sections
.str_offsets
;
20215 const gdb_byte
*info_ptr
;
20216 ULONGEST str_offset
;
20217 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20219 dwarf2_read_section (objfile
, str_section
);
20220 dwarf2_read_section (objfile
, str_offsets_section
);
20221 if (str_section
->buffer
== NULL
)
20222 error (_("%s used without .debug_str.dwo section"
20223 " in CU at offset %s [in module %s]"),
20224 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20225 if (str_offsets_section
->buffer
== NULL
)
20226 error (_("%s used without .debug_str_offsets.dwo section"
20227 " in CU at offset %s [in module %s]"),
20228 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20229 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20230 error (_("%s pointing outside of .debug_str_offsets.dwo"
20231 " section in CU at offset %s [in module %s]"),
20232 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20233 info_ptr
= (str_offsets_section
->buffer
20234 + str_index
* cu
->header
.offset_size
);
20235 if (cu
->header
.offset_size
== 4)
20236 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20238 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20239 if (str_offset
>= str_section
->size
)
20240 error (_("Offset from %s pointing outside of"
20241 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20242 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20243 return (const char *) (str_section
->buffer
+ str_offset
);
20246 /* Return the length of an LEB128 number in BUF. */
20249 leb128_size (const gdb_byte
*buf
)
20251 const gdb_byte
*begin
= buf
;
20257 if ((byte
& 128) == 0)
20258 return buf
- begin
;
20263 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20272 cu
->language
= language_c
;
20275 case DW_LANG_C_plus_plus
:
20276 case DW_LANG_C_plus_plus_11
:
20277 case DW_LANG_C_plus_plus_14
:
20278 cu
->language
= language_cplus
;
20281 cu
->language
= language_d
;
20283 case DW_LANG_Fortran77
:
20284 case DW_LANG_Fortran90
:
20285 case DW_LANG_Fortran95
:
20286 case DW_LANG_Fortran03
:
20287 case DW_LANG_Fortran08
:
20288 cu
->language
= language_fortran
;
20291 cu
->language
= language_go
;
20293 case DW_LANG_Mips_Assembler
:
20294 cu
->language
= language_asm
;
20296 case DW_LANG_Ada83
:
20297 case DW_LANG_Ada95
:
20298 cu
->language
= language_ada
;
20300 case DW_LANG_Modula2
:
20301 cu
->language
= language_m2
;
20303 case DW_LANG_Pascal83
:
20304 cu
->language
= language_pascal
;
20307 cu
->language
= language_objc
;
20310 case DW_LANG_Rust_old
:
20311 cu
->language
= language_rust
;
20313 case DW_LANG_Cobol74
:
20314 case DW_LANG_Cobol85
:
20316 cu
->language
= language_minimal
;
20319 cu
->language_defn
= language_def (cu
->language
);
20322 /* Return the named attribute or NULL if not there. */
20324 static struct attribute
*
20325 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20330 struct attribute
*spec
= NULL
;
20332 for (i
= 0; i
< die
->num_attrs
; ++i
)
20334 if (die
->attrs
[i
].name
== name
)
20335 return &die
->attrs
[i
];
20336 if (die
->attrs
[i
].name
== DW_AT_specification
20337 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20338 spec
= &die
->attrs
[i
];
20344 die
= follow_die_ref (die
, spec
, &cu
);
20350 /* Return the named attribute or NULL if not there,
20351 but do not follow DW_AT_specification, etc.
20352 This is for use in contexts where we're reading .debug_types dies.
20353 Following DW_AT_specification, DW_AT_abstract_origin will take us
20354 back up the chain, and we want to go down. */
20356 static struct attribute
*
20357 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20361 for (i
= 0; i
< die
->num_attrs
; ++i
)
20362 if (die
->attrs
[i
].name
== name
)
20363 return &die
->attrs
[i
];
20368 /* Return the string associated with a string-typed attribute, or NULL if it
20369 is either not found or is of an incorrect type. */
20371 static const char *
20372 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20374 struct attribute
*attr
;
20375 const char *str
= NULL
;
20377 attr
= dwarf2_attr (die
, name
, cu
);
20381 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20382 || attr
->form
== DW_FORM_string
20383 || attr
->form
== DW_FORM_strx
20384 || attr
->form
== DW_FORM_strx1
20385 || attr
->form
== DW_FORM_strx2
20386 || attr
->form
== DW_FORM_strx3
20387 || attr
->form
== DW_FORM_strx4
20388 || attr
->form
== DW_FORM_GNU_str_index
20389 || attr
->form
== DW_FORM_GNU_strp_alt
)
20390 str
= DW_STRING (attr
);
20392 complaint (_("string type expected for attribute %s for "
20393 "DIE at %s in module %s"),
20394 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20395 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20401 /* Return the dwo name or NULL if not present. If present, it is in either
20402 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20403 static const char *
20404 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20406 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20407 if (dwo_name
== nullptr)
20408 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20412 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20413 and holds a non-zero value. This function should only be used for
20414 DW_FORM_flag or DW_FORM_flag_present attributes. */
20417 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20419 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20421 return (attr
&& DW_UNSND (attr
));
20425 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20427 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20428 which value is non-zero. However, we have to be careful with
20429 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20430 (via dwarf2_flag_true_p) follows this attribute. So we may
20431 end up accidently finding a declaration attribute that belongs
20432 to a different DIE referenced by the specification attribute,
20433 even though the given DIE does not have a declaration attribute. */
20434 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20435 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20438 /* Return the die giving the specification for DIE, if there is
20439 one. *SPEC_CU is the CU containing DIE on input, and the CU
20440 containing the return value on output. If there is no
20441 specification, but there is an abstract origin, that is
20444 static struct die_info
*
20445 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20447 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20450 if (spec_attr
== NULL
)
20451 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20453 if (spec_attr
== NULL
)
20456 return follow_die_ref (die
, spec_attr
, spec_cu
);
20459 /* Stub for free_line_header to match void * callback types. */
20462 free_line_header_voidp (void *arg
)
20464 struct line_header
*lh
= (struct line_header
*) arg
;
20470 line_header::add_include_dir (const char *include_dir
)
20472 if (dwarf_line_debug
>= 2)
20476 new_size
= m_include_dirs
.size ();
20478 new_size
= m_include_dirs
.size () + 1;
20479 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20480 new_size
, include_dir
);
20482 m_include_dirs
.push_back (include_dir
);
20486 line_header::add_file_name (const char *name
,
20488 unsigned int mod_time
,
20489 unsigned int length
)
20491 if (dwarf_line_debug
>= 2)
20495 new_size
= file_names_size ();
20497 new_size
= file_names_size () + 1;
20498 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20501 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20504 /* A convenience function to find the proper .debug_line section for a CU. */
20506 static struct dwarf2_section_info
*
20507 get_debug_line_section (struct dwarf2_cu
*cu
)
20509 struct dwarf2_section_info
*section
;
20510 struct dwarf2_per_objfile
*dwarf2_per_objfile
20511 = cu
->per_cu
->dwarf2_per_objfile
;
20513 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20515 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20516 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20517 else if (cu
->per_cu
->is_dwz
)
20519 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20521 section
= &dwz
->line
;
20524 section
= &dwarf2_per_objfile
->line
;
20529 /* Read directory or file name entry format, starting with byte of
20530 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20531 entries count and the entries themselves in the described entry
20535 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20536 bfd
*abfd
, const gdb_byte
**bufp
,
20537 struct line_header
*lh
,
20538 const struct comp_unit_head
*cu_header
,
20539 void (*callback
) (struct line_header
*lh
,
20542 unsigned int mod_time
,
20543 unsigned int length
))
20545 gdb_byte format_count
, formati
;
20546 ULONGEST data_count
, datai
;
20547 const gdb_byte
*buf
= *bufp
;
20548 const gdb_byte
*format_header_data
;
20549 unsigned int bytes_read
;
20551 format_count
= read_1_byte (abfd
, buf
);
20553 format_header_data
= buf
;
20554 for (formati
= 0; formati
< format_count
; formati
++)
20556 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20558 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20562 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20564 for (datai
= 0; datai
< data_count
; datai
++)
20566 const gdb_byte
*format
= format_header_data
;
20567 struct file_entry fe
;
20569 for (formati
= 0; formati
< format_count
; formati
++)
20571 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20572 format
+= bytes_read
;
20574 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20575 format
+= bytes_read
;
20577 gdb::optional
<const char *> string
;
20578 gdb::optional
<unsigned int> uint
;
20582 case DW_FORM_string
:
20583 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20587 case DW_FORM_line_strp
:
20588 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20595 case DW_FORM_data1
:
20596 uint
.emplace (read_1_byte (abfd
, buf
));
20600 case DW_FORM_data2
:
20601 uint
.emplace (read_2_bytes (abfd
, buf
));
20605 case DW_FORM_data4
:
20606 uint
.emplace (read_4_bytes (abfd
, buf
));
20610 case DW_FORM_data8
:
20611 uint
.emplace (read_8_bytes (abfd
, buf
));
20615 case DW_FORM_data16
:
20616 /* This is used for MD5, but file_entry does not record MD5s. */
20620 case DW_FORM_udata
:
20621 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20625 case DW_FORM_block
:
20626 /* It is valid only for DW_LNCT_timestamp which is ignored by
20631 switch (content_type
)
20634 if (string
.has_value ())
20637 case DW_LNCT_directory_index
:
20638 if (uint
.has_value ())
20639 fe
.d_index
= (dir_index
) *uint
;
20641 case DW_LNCT_timestamp
:
20642 if (uint
.has_value ())
20643 fe
.mod_time
= *uint
;
20646 if (uint
.has_value ())
20652 complaint (_("Unknown format content type %s"),
20653 pulongest (content_type
));
20657 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20663 /* Read the statement program header starting at OFFSET in
20664 .debug_line, or .debug_line.dwo. Return a pointer
20665 to a struct line_header, allocated using xmalloc.
20666 Returns NULL if there is a problem reading the header, e.g., if it
20667 has a version we don't understand.
20669 NOTE: the strings in the include directory and file name tables of
20670 the returned object point into the dwarf line section buffer,
20671 and must not be freed. */
20673 static line_header_up
20674 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20676 const gdb_byte
*line_ptr
;
20677 unsigned int bytes_read
, offset_size
;
20679 const char *cur_dir
, *cur_file
;
20680 struct dwarf2_section_info
*section
;
20682 struct dwarf2_per_objfile
*dwarf2_per_objfile
20683 = cu
->per_cu
->dwarf2_per_objfile
;
20685 section
= get_debug_line_section (cu
);
20686 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20687 if (section
->buffer
== NULL
)
20689 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20690 complaint (_("missing .debug_line.dwo section"));
20692 complaint (_("missing .debug_line section"));
20696 /* We can't do this until we know the section is non-empty.
20697 Only then do we know we have such a section. */
20698 abfd
= get_section_bfd_owner (section
);
20700 /* Make sure that at least there's room for the total_length field.
20701 That could be 12 bytes long, but we're just going to fudge that. */
20702 if (to_underlying (sect_off
) + 4 >= section
->size
)
20704 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20708 line_header_up
lh (new line_header ());
20710 lh
->sect_off
= sect_off
;
20711 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20713 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20715 /* Read in the header. */
20717 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20718 &bytes_read
, &offset_size
);
20719 line_ptr
+= bytes_read
;
20721 const gdb_byte
*start_here
= line_ptr
;
20723 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20725 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20728 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20729 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20731 if (lh
->version
> 5)
20733 /* This is a version we don't understand. The format could have
20734 changed in ways we don't handle properly so just punt. */
20735 complaint (_("unsupported version in .debug_line section"));
20738 if (lh
->version
>= 5)
20740 gdb_byte segment_selector_size
;
20742 /* Skip address size. */
20743 read_1_byte (abfd
, line_ptr
);
20746 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20748 if (segment_selector_size
!= 0)
20750 complaint (_("unsupported segment selector size %u "
20751 "in .debug_line section"),
20752 segment_selector_size
);
20756 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20757 line_ptr
+= offset_size
;
20758 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20759 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20761 if (lh
->version
>= 4)
20763 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20767 lh
->maximum_ops_per_instruction
= 1;
20769 if (lh
->maximum_ops_per_instruction
== 0)
20771 lh
->maximum_ops_per_instruction
= 1;
20772 complaint (_("invalid maximum_ops_per_instruction "
20773 "in `.debug_line' section"));
20776 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20778 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20780 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20782 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20784 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20786 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20787 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20789 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20793 if (lh
->version
>= 5)
20795 /* Read directory table. */
20796 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20798 [] (struct line_header
*header
, const char *name
,
20799 dir_index d_index
, unsigned int mod_time
,
20800 unsigned int length
)
20802 header
->add_include_dir (name
);
20805 /* Read file name table. */
20806 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20808 [] (struct line_header
*header
, const char *name
,
20809 dir_index d_index
, unsigned int mod_time
,
20810 unsigned int length
)
20812 header
->add_file_name (name
, d_index
, mod_time
, length
);
20817 /* Read directory table. */
20818 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20820 line_ptr
+= bytes_read
;
20821 lh
->add_include_dir (cur_dir
);
20823 line_ptr
+= bytes_read
;
20825 /* Read file name table. */
20826 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20828 unsigned int mod_time
, length
;
20831 line_ptr
+= bytes_read
;
20832 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20833 line_ptr
+= bytes_read
;
20834 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20835 line_ptr
+= bytes_read
;
20836 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20837 line_ptr
+= bytes_read
;
20839 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20841 line_ptr
+= bytes_read
;
20844 if (line_ptr
> (section
->buffer
+ section
->size
))
20845 complaint (_("line number info header doesn't "
20846 "fit in `.debug_line' section"));
20851 /* Subroutine of dwarf_decode_lines to simplify it.
20852 Return the file name of the psymtab for the given file_entry.
20853 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20854 If space for the result is malloc'd, *NAME_HOLDER will be set.
20855 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20857 static const char *
20858 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20859 const struct partial_symtab
*pst
,
20860 const char *comp_dir
,
20861 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20863 const char *include_name
= fe
.name
;
20864 const char *include_name_to_compare
= include_name
;
20865 const char *pst_filename
;
20868 const char *dir_name
= fe
.include_dir (lh
);
20870 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20871 if (!IS_ABSOLUTE_PATH (include_name
)
20872 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20874 /* Avoid creating a duplicate psymtab for PST.
20875 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20876 Before we do the comparison, however, we need to account
20877 for DIR_NAME and COMP_DIR.
20878 First prepend dir_name (if non-NULL). If we still don't
20879 have an absolute path prepend comp_dir (if non-NULL).
20880 However, the directory we record in the include-file's
20881 psymtab does not contain COMP_DIR (to match the
20882 corresponding symtab(s)).
20887 bash$ gcc -g ./hello.c
20888 include_name = "hello.c"
20890 DW_AT_comp_dir = comp_dir = "/tmp"
20891 DW_AT_name = "./hello.c"
20895 if (dir_name
!= NULL
)
20897 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20898 include_name
, (char *) NULL
));
20899 include_name
= name_holder
->get ();
20900 include_name_to_compare
= include_name
;
20902 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20904 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20905 include_name
, (char *) NULL
));
20906 include_name_to_compare
= hold_compare
.get ();
20910 pst_filename
= pst
->filename
;
20911 gdb::unique_xmalloc_ptr
<char> copied_name
;
20912 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20914 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20915 pst_filename
, (char *) NULL
));
20916 pst_filename
= copied_name
.get ();
20919 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20923 return include_name
;
20926 /* State machine to track the state of the line number program. */
20928 class lnp_state_machine
20931 /* Initialize a machine state for the start of a line number
20933 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20934 bool record_lines_p
);
20936 file_entry
*current_file ()
20938 /* lh->file_names is 0-based, but the file name numbers in the
20939 statement program are 1-based. */
20940 return m_line_header
->file_name_at (m_file
);
20943 /* Record the line in the state machine. END_SEQUENCE is true if
20944 we're processing the end of a sequence. */
20945 void record_line (bool end_sequence
);
20947 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20948 nop-out rest of the lines in this sequence. */
20949 void check_line_address (struct dwarf2_cu
*cu
,
20950 const gdb_byte
*line_ptr
,
20951 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20953 void handle_set_discriminator (unsigned int discriminator
)
20955 m_discriminator
= discriminator
;
20956 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20959 /* Handle DW_LNE_set_address. */
20960 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20963 address
+= baseaddr
;
20964 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20967 /* Handle DW_LNS_advance_pc. */
20968 void handle_advance_pc (CORE_ADDR adjust
);
20970 /* Handle a special opcode. */
20971 void handle_special_opcode (unsigned char op_code
);
20973 /* Handle DW_LNS_advance_line. */
20974 void handle_advance_line (int line_delta
)
20976 advance_line (line_delta
);
20979 /* Handle DW_LNS_set_file. */
20980 void handle_set_file (file_name_index file
);
20982 /* Handle DW_LNS_negate_stmt. */
20983 void handle_negate_stmt ()
20985 m_is_stmt
= !m_is_stmt
;
20988 /* Handle DW_LNS_const_add_pc. */
20989 void handle_const_add_pc ();
20991 /* Handle DW_LNS_fixed_advance_pc. */
20992 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20994 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20998 /* Handle DW_LNS_copy. */
20999 void handle_copy ()
21001 record_line (false);
21002 m_discriminator
= 0;
21005 /* Handle DW_LNE_end_sequence. */
21006 void handle_end_sequence ()
21008 m_currently_recording_lines
= true;
21012 /* Advance the line by LINE_DELTA. */
21013 void advance_line (int line_delta
)
21015 m_line
+= line_delta
;
21017 if (line_delta
!= 0)
21018 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21021 struct dwarf2_cu
*m_cu
;
21023 gdbarch
*m_gdbarch
;
21025 /* True if we're recording lines.
21026 Otherwise we're building partial symtabs and are just interested in
21027 finding include files mentioned by the line number program. */
21028 bool m_record_lines_p
;
21030 /* The line number header. */
21031 line_header
*m_line_header
;
21033 /* These are part of the standard DWARF line number state machine,
21034 and initialized according to the DWARF spec. */
21036 unsigned char m_op_index
= 0;
21037 /* The line table index of the current file. */
21038 file_name_index m_file
= 1;
21039 unsigned int m_line
= 1;
21041 /* These are initialized in the constructor. */
21043 CORE_ADDR m_address
;
21045 unsigned int m_discriminator
;
21047 /* Additional bits of state we need to track. */
21049 /* The last file that we called dwarf2_start_subfile for.
21050 This is only used for TLLs. */
21051 unsigned int m_last_file
= 0;
21052 /* The last file a line number was recorded for. */
21053 struct subfile
*m_last_subfile
= NULL
;
21055 /* When true, record the lines we decode. */
21056 bool m_currently_recording_lines
= false;
21058 /* The last line number that was recorded, used to coalesce
21059 consecutive entries for the same line. This can happen, for
21060 example, when discriminators are present. PR 17276. */
21061 unsigned int m_last_line
= 0;
21062 bool m_line_has_non_zero_discriminator
= false;
21066 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21068 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21069 / m_line_header
->maximum_ops_per_instruction
)
21070 * m_line_header
->minimum_instruction_length
);
21071 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21072 m_op_index
= ((m_op_index
+ adjust
)
21073 % m_line_header
->maximum_ops_per_instruction
);
21077 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21079 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21080 CORE_ADDR addr_adj
= (((m_op_index
21081 + (adj_opcode
/ m_line_header
->line_range
))
21082 / m_line_header
->maximum_ops_per_instruction
)
21083 * m_line_header
->minimum_instruction_length
);
21084 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21085 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
21086 % m_line_header
->maximum_ops_per_instruction
);
21088 int line_delta
= (m_line_header
->line_base
21089 + (adj_opcode
% m_line_header
->line_range
));
21090 advance_line (line_delta
);
21091 record_line (false);
21092 m_discriminator
= 0;
21096 lnp_state_machine::handle_set_file (file_name_index file
)
21100 const file_entry
*fe
= current_file ();
21102 dwarf2_debug_line_missing_file_complaint ();
21103 else if (m_record_lines_p
)
21105 const char *dir
= fe
->include_dir (m_line_header
);
21107 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21108 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21109 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21114 lnp_state_machine::handle_const_add_pc ()
21117 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21120 = (((m_op_index
+ adjust
)
21121 / m_line_header
->maximum_ops_per_instruction
)
21122 * m_line_header
->minimum_instruction_length
);
21124 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21125 m_op_index
= ((m_op_index
+ adjust
)
21126 % m_line_header
->maximum_ops_per_instruction
);
21129 /* Return non-zero if we should add LINE to the line number table.
21130 LINE is the line to add, LAST_LINE is the last line that was added,
21131 LAST_SUBFILE is the subfile for LAST_LINE.
21132 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21133 had a non-zero discriminator.
21135 We have to be careful in the presence of discriminators.
21136 E.g., for this line:
21138 for (i = 0; i < 100000; i++);
21140 clang can emit four line number entries for that one line,
21141 each with a different discriminator.
21142 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21144 However, we want gdb to coalesce all four entries into one.
21145 Otherwise the user could stepi into the middle of the line and
21146 gdb would get confused about whether the pc really was in the
21147 middle of the line.
21149 Things are further complicated by the fact that two consecutive
21150 line number entries for the same line is a heuristic used by gcc
21151 to denote the end of the prologue. So we can't just discard duplicate
21152 entries, we have to be selective about it. The heuristic we use is
21153 that we only collapse consecutive entries for the same line if at least
21154 one of those entries has a non-zero discriminator. PR 17276.
21156 Note: Addresses in the line number state machine can never go backwards
21157 within one sequence, thus this coalescing is ok. */
21160 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21161 unsigned int line
, unsigned int last_line
,
21162 int line_has_non_zero_discriminator
,
21163 struct subfile
*last_subfile
)
21165 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21167 if (line
!= last_line
)
21169 /* Same line for the same file that we've seen already.
21170 As a last check, for pr 17276, only record the line if the line
21171 has never had a non-zero discriminator. */
21172 if (!line_has_non_zero_discriminator
)
21177 /* Use the CU's builder to record line number LINE beginning at
21178 address ADDRESS in the line table of subfile SUBFILE. */
21181 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21182 unsigned int line
, CORE_ADDR address
,
21183 struct dwarf2_cu
*cu
)
21185 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21187 if (dwarf_line_debug
)
21189 fprintf_unfiltered (gdb_stdlog
,
21190 "Recording line %u, file %s, address %s\n",
21191 line
, lbasename (subfile
->name
),
21192 paddress (gdbarch
, address
));
21196 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21199 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21200 Mark the end of a set of line number records.
21201 The arguments are the same as for dwarf_record_line_1.
21202 If SUBFILE is NULL the request is ignored. */
21205 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21206 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21208 if (subfile
== NULL
)
21211 if (dwarf_line_debug
)
21213 fprintf_unfiltered (gdb_stdlog
,
21214 "Finishing current line, file %s, address %s\n",
21215 lbasename (subfile
->name
),
21216 paddress (gdbarch
, address
));
21219 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21223 lnp_state_machine::record_line (bool end_sequence
)
21225 if (dwarf_line_debug
)
21227 fprintf_unfiltered (gdb_stdlog
,
21228 "Processing actual line %u: file %u,"
21229 " address %s, is_stmt %u, discrim %u\n",
21231 paddress (m_gdbarch
, m_address
),
21232 m_is_stmt
, m_discriminator
);
21235 file_entry
*fe
= current_file ();
21238 dwarf2_debug_line_missing_file_complaint ();
21239 /* For now we ignore lines not starting on an instruction boundary.
21240 But not when processing end_sequence for compatibility with the
21241 previous version of the code. */
21242 else if (m_op_index
== 0 || end_sequence
)
21244 fe
->included_p
= 1;
21245 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
21247 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21250 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21251 m_currently_recording_lines
? m_cu
: nullptr);
21256 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21257 m_line_has_non_zero_discriminator
,
21260 buildsym_compunit
*builder
= m_cu
->get_builder ();
21261 dwarf_record_line_1 (m_gdbarch
,
21262 builder
->get_current_subfile (),
21264 m_currently_recording_lines
? m_cu
: nullptr);
21266 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21267 m_last_line
= m_line
;
21273 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21274 line_header
*lh
, bool record_lines_p
)
21278 m_record_lines_p
= record_lines_p
;
21279 m_line_header
= lh
;
21281 m_currently_recording_lines
= true;
21283 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21284 was a line entry for it so that the backend has a chance to adjust it
21285 and also record it in case it needs it. This is currently used by MIPS
21286 code, cf. `mips_adjust_dwarf2_line'. */
21287 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21288 m_is_stmt
= lh
->default_is_stmt
;
21289 m_discriminator
= 0;
21293 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21294 const gdb_byte
*line_ptr
,
21295 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21297 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21298 the pc range of the CU. However, we restrict the test to only ADDRESS
21299 values of zero to preserve GDB's previous behaviour which is to handle
21300 the specific case of a function being GC'd by the linker. */
21302 if (address
== 0 && address
< unrelocated_lowpc
)
21304 /* This line table is for a function which has been
21305 GCd by the linker. Ignore it. PR gdb/12528 */
21307 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21308 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21310 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21311 line_offset
, objfile_name (objfile
));
21312 m_currently_recording_lines
= false;
21313 /* Note: m_currently_recording_lines is left as false until we see
21314 DW_LNE_end_sequence. */
21318 /* Subroutine of dwarf_decode_lines to simplify it.
21319 Process the line number information in LH.
21320 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21321 program in order to set included_p for every referenced header. */
21324 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21325 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21327 const gdb_byte
*line_ptr
, *extended_end
;
21328 const gdb_byte
*line_end
;
21329 unsigned int bytes_read
, extended_len
;
21330 unsigned char op_code
, extended_op
;
21331 CORE_ADDR baseaddr
;
21332 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21333 bfd
*abfd
= objfile
->obfd
;
21334 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21335 /* True if we're recording line info (as opposed to building partial
21336 symtabs and just interested in finding include files mentioned by
21337 the line number program). */
21338 bool record_lines_p
= !decode_for_pst_p
;
21340 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21342 line_ptr
= lh
->statement_program_start
;
21343 line_end
= lh
->statement_program_end
;
21345 /* Read the statement sequences until there's nothing left. */
21346 while (line_ptr
< line_end
)
21348 /* The DWARF line number program state machine. Reset the state
21349 machine at the start of each sequence. */
21350 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21351 bool end_sequence
= false;
21353 if (record_lines_p
)
21355 /* Start a subfile for the current file of the state
21357 const file_entry
*fe
= state_machine
.current_file ();
21360 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21363 /* Decode the table. */
21364 while (line_ptr
< line_end
&& !end_sequence
)
21366 op_code
= read_1_byte (abfd
, line_ptr
);
21369 if (op_code
>= lh
->opcode_base
)
21371 /* Special opcode. */
21372 state_machine
.handle_special_opcode (op_code
);
21374 else switch (op_code
)
21376 case DW_LNS_extended_op
:
21377 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21379 line_ptr
+= bytes_read
;
21380 extended_end
= line_ptr
+ extended_len
;
21381 extended_op
= read_1_byte (abfd
, line_ptr
);
21383 switch (extended_op
)
21385 case DW_LNE_end_sequence
:
21386 state_machine
.handle_end_sequence ();
21387 end_sequence
= true;
21389 case DW_LNE_set_address
:
21392 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21393 line_ptr
+= bytes_read
;
21395 state_machine
.check_line_address (cu
, line_ptr
,
21396 lowpc
- baseaddr
, address
);
21397 state_machine
.handle_set_address (baseaddr
, address
);
21400 case DW_LNE_define_file
:
21402 const char *cur_file
;
21403 unsigned int mod_time
, length
;
21406 cur_file
= read_direct_string (abfd
, line_ptr
,
21408 line_ptr
+= bytes_read
;
21409 dindex
= (dir_index
)
21410 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21411 line_ptr
+= bytes_read
;
21413 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21414 line_ptr
+= bytes_read
;
21416 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21417 line_ptr
+= bytes_read
;
21418 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21421 case DW_LNE_set_discriminator
:
21423 /* The discriminator is not interesting to the
21424 debugger; just ignore it. We still need to
21425 check its value though:
21426 if there are consecutive entries for the same
21427 (non-prologue) line we want to coalesce them.
21430 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21431 line_ptr
+= bytes_read
;
21433 state_machine
.handle_set_discriminator (discr
);
21437 complaint (_("mangled .debug_line section"));
21440 /* Make sure that we parsed the extended op correctly. If e.g.
21441 we expected a different address size than the producer used,
21442 we may have read the wrong number of bytes. */
21443 if (line_ptr
!= extended_end
)
21445 complaint (_("mangled .debug_line section"));
21450 state_machine
.handle_copy ();
21452 case DW_LNS_advance_pc
:
21455 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21456 line_ptr
+= bytes_read
;
21458 state_machine
.handle_advance_pc (adjust
);
21461 case DW_LNS_advance_line
:
21464 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21465 line_ptr
+= bytes_read
;
21467 state_machine
.handle_advance_line (line_delta
);
21470 case DW_LNS_set_file
:
21472 file_name_index file
21473 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21475 line_ptr
+= bytes_read
;
21477 state_machine
.handle_set_file (file
);
21480 case DW_LNS_set_column
:
21481 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21482 line_ptr
+= bytes_read
;
21484 case DW_LNS_negate_stmt
:
21485 state_machine
.handle_negate_stmt ();
21487 case DW_LNS_set_basic_block
:
21489 /* Add to the address register of the state machine the
21490 address increment value corresponding to special opcode
21491 255. I.e., this value is scaled by the minimum
21492 instruction length since special opcode 255 would have
21493 scaled the increment. */
21494 case DW_LNS_const_add_pc
:
21495 state_machine
.handle_const_add_pc ();
21497 case DW_LNS_fixed_advance_pc
:
21499 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21502 state_machine
.handle_fixed_advance_pc (addr_adj
);
21507 /* Unknown standard opcode, ignore it. */
21510 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21512 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21513 line_ptr
+= bytes_read
;
21520 dwarf2_debug_line_missing_end_sequence_complaint ();
21522 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21523 in which case we still finish recording the last line). */
21524 state_machine
.record_line (true);
21528 /* Decode the Line Number Program (LNP) for the given line_header
21529 structure and CU. The actual information extracted and the type
21530 of structures created from the LNP depends on the value of PST.
21532 1. If PST is NULL, then this procedure uses the data from the program
21533 to create all necessary symbol tables, and their linetables.
21535 2. If PST is not NULL, this procedure reads the program to determine
21536 the list of files included by the unit represented by PST, and
21537 builds all the associated partial symbol tables.
21539 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21540 It is used for relative paths in the line table.
21541 NOTE: When processing partial symtabs (pst != NULL),
21542 comp_dir == pst->dirname.
21544 NOTE: It is important that psymtabs have the same file name (via strcmp)
21545 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21546 symtab we don't use it in the name of the psymtabs we create.
21547 E.g. expand_line_sal requires this when finding psymtabs to expand.
21548 A good testcase for this is mb-inline.exp.
21550 LOWPC is the lowest address in CU (or 0 if not known).
21552 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21553 for its PC<->lines mapping information. Otherwise only the filename
21554 table is read in. */
21557 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21558 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21559 CORE_ADDR lowpc
, int decode_mapping
)
21561 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21562 const int decode_for_pst_p
= (pst
!= NULL
);
21564 if (decode_mapping
)
21565 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21567 if (decode_for_pst_p
)
21569 /* Now that we're done scanning the Line Header Program, we can
21570 create the psymtab of each included file. */
21571 for (auto &file_entry
: lh
->file_names ())
21572 if (file_entry
.included_p
== 1)
21574 gdb::unique_xmalloc_ptr
<char> name_holder
;
21575 const char *include_name
=
21576 psymtab_include_file_name (lh
, file_entry
, pst
,
21577 comp_dir
, &name_holder
);
21578 if (include_name
!= NULL
)
21579 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21584 /* Make sure a symtab is created for every file, even files
21585 which contain only variables (i.e. no code with associated
21587 buildsym_compunit
*builder
= cu
->get_builder ();
21588 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21590 for (auto &fe
: lh
->file_names ())
21592 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21593 if (builder
->get_current_subfile ()->symtab
== NULL
)
21595 builder
->get_current_subfile ()->symtab
21596 = allocate_symtab (cust
,
21597 builder
->get_current_subfile ()->name
);
21599 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21604 /* Start a subfile for DWARF. FILENAME is the name of the file and
21605 DIRNAME the name of the source directory which contains FILENAME
21606 or NULL if not known.
21607 This routine tries to keep line numbers from identical absolute and
21608 relative file names in a common subfile.
21610 Using the `list' example from the GDB testsuite, which resides in
21611 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21612 of /srcdir/list0.c yields the following debugging information for list0.c:
21614 DW_AT_name: /srcdir/list0.c
21615 DW_AT_comp_dir: /compdir
21616 files.files[0].name: list0.h
21617 files.files[0].dir: /srcdir
21618 files.files[1].name: list0.c
21619 files.files[1].dir: /srcdir
21621 The line number information for list0.c has to end up in a single
21622 subfile, so that `break /srcdir/list0.c:1' works as expected.
21623 start_subfile will ensure that this happens provided that we pass the
21624 concatenation of files.files[1].dir and files.files[1].name as the
21628 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21629 const char *dirname
)
21633 /* In order not to lose the line information directory,
21634 we concatenate it to the filename when it makes sense.
21635 Note that the Dwarf3 standard says (speaking of filenames in line
21636 information): ``The directory index is ignored for file names
21637 that represent full path names''. Thus ignoring dirname in the
21638 `else' branch below isn't an issue. */
21640 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21642 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21646 cu
->get_builder ()->start_subfile (filename
);
21652 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21653 buildsym_compunit constructor. */
21655 struct compunit_symtab
*
21656 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21659 gdb_assert (m_builder
== nullptr);
21661 m_builder
.reset (new struct buildsym_compunit
21662 (per_cu
->dwarf2_per_objfile
->objfile
,
21663 name
, comp_dir
, language
, low_pc
));
21665 list_in_scope
= get_builder ()->get_file_symbols ();
21667 get_builder ()->record_debugformat (xstrprintf ("DWARF %d", this->header
.version
));
21668 get_builder ()->record_producer (producer
);
21670 processing_has_namespace_info
= false;
21672 return get_builder ()->get_compunit_symtab ();
21676 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21677 struct dwarf2_cu
*cu
)
21679 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21680 struct comp_unit_head
*cu_header
= &cu
->header
;
21682 /* NOTE drow/2003-01-30: There used to be a comment and some special
21683 code here to turn a symbol with DW_AT_external and a
21684 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21685 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21686 with some versions of binutils) where shared libraries could have
21687 relocations against symbols in their debug information - the
21688 minimal symbol would have the right address, but the debug info
21689 would not. It's no longer necessary, because we will explicitly
21690 apply relocations when we read in the debug information now. */
21692 /* A DW_AT_location attribute with no contents indicates that a
21693 variable has been optimized away. */
21694 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21696 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21700 /* Handle one degenerate form of location expression specially, to
21701 preserve GDB's previous behavior when section offsets are
21702 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21703 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21705 if (attr_form_is_block (attr
)
21706 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21707 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21708 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21709 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21710 && (DW_BLOCK (attr
)->size
21711 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21713 unsigned int dummy
;
21715 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21716 SET_SYMBOL_VALUE_ADDRESS (sym
,
21717 read_address (objfile
->obfd
,
21718 DW_BLOCK (attr
)->data
+ 1,
21721 SET_SYMBOL_VALUE_ADDRESS
21722 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21724 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21725 fixup_symbol_section (sym
, objfile
);
21726 SET_SYMBOL_VALUE_ADDRESS (sym
,
21727 SYMBOL_VALUE_ADDRESS (sym
)
21728 + ANOFFSET (objfile
->section_offsets
,
21729 SYMBOL_SECTION (sym
)));
21733 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21734 expression evaluator, and use LOC_COMPUTED only when necessary
21735 (i.e. when the value of a register or memory location is
21736 referenced, or a thread-local block, etc.). Then again, it might
21737 not be worthwhile. I'm assuming that it isn't unless performance
21738 or memory numbers show me otherwise. */
21740 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21742 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21743 cu
->has_loclist
= true;
21746 /* Given a pointer to a DWARF information entry, figure out if we need
21747 to make a symbol table entry for it, and if so, create a new entry
21748 and return a pointer to it.
21749 If TYPE is NULL, determine symbol type from the die, otherwise
21750 used the passed type.
21751 If SPACE is not NULL, use it to hold the new symbol. If it is
21752 NULL, allocate a new symbol on the objfile's obstack. */
21754 static struct symbol
*
21755 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21756 struct symbol
*space
)
21758 struct dwarf2_per_objfile
*dwarf2_per_objfile
21759 = cu
->per_cu
->dwarf2_per_objfile
;
21760 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21761 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21762 struct symbol
*sym
= NULL
;
21764 struct attribute
*attr
= NULL
;
21765 struct attribute
*attr2
= NULL
;
21766 CORE_ADDR baseaddr
;
21767 struct pending
**list_to_add
= NULL
;
21769 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21771 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21773 name
= dwarf2_name (die
, cu
);
21776 const char *linkagename
;
21777 int suppress_add
= 0;
21782 sym
= allocate_symbol (objfile
);
21783 OBJSTAT (objfile
, n_syms
++);
21785 /* Cache this symbol's name and the name's demangled form (if any). */
21786 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21787 linkagename
= dwarf2_physname (name
, die
, cu
);
21788 SYMBOL_SET_NAMES (sym
, linkagename
, false, objfile
);
21790 /* Fortran does not have mangling standard and the mangling does differ
21791 between gfortran, iFort etc. */
21792 if (cu
->language
== language_fortran
21793 && symbol_get_demangled_name (sym
) == NULL
)
21794 symbol_set_demangled_name (sym
,
21795 dwarf2_full_name (name
, die
, cu
),
21798 /* Default assumptions.
21799 Use the passed type or decode it from the die. */
21800 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21801 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21803 SYMBOL_TYPE (sym
) = type
;
21805 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21806 attr
= dwarf2_attr (die
,
21807 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21809 if (attr
!= nullptr)
21811 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21814 attr
= dwarf2_attr (die
,
21815 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21817 if (attr
!= nullptr)
21819 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21820 struct file_entry
*fe
;
21822 if (cu
->line_header
!= NULL
)
21823 fe
= cu
->line_header
->file_name_at (file_index
);
21828 complaint (_("file index out of range"));
21830 symbol_set_symtab (sym
, fe
->symtab
);
21836 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21837 if (attr
!= nullptr)
21841 addr
= attr_value_as_address (attr
);
21842 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21843 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21845 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21846 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21847 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21848 add_symbol_to_list (sym
, cu
->list_in_scope
);
21850 case DW_TAG_subprogram
:
21851 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21853 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21854 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21855 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21856 || cu
->language
== language_ada
21857 || cu
->language
== language_fortran
)
21859 /* Subprograms marked external are stored as a global symbol.
21860 Ada and Fortran subprograms, whether marked external or
21861 not, are always stored as a global symbol, because we want
21862 to be able to access them globally. For instance, we want
21863 to be able to break on a nested subprogram without having
21864 to specify the context. */
21865 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21869 list_to_add
= cu
->list_in_scope
;
21872 case DW_TAG_inlined_subroutine
:
21873 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21875 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21876 SYMBOL_INLINED (sym
) = 1;
21877 list_to_add
= cu
->list_in_scope
;
21879 case DW_TAG_template_value_param
:
21881 /* Fall through. */
21882 case DW_TAG_constant
:
21883 case DW_TAG_variable
:
21884 case DW_TAG_member
:
21885 /* Compilation with minimal debug info may result in
21886 variables with missing type entries. Change the
21887 misleading `void' type to something sensible. */
21888 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21889 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21891 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21892 /* In the case of DW_TAG_member, we should only be called for
21893 static const members. */
21894 if (die
->tag
== DW_TAG_member
)
21896 /* dwarf2_add_field uses die_is_declaration,
21897 so we do the same. */
21898 gdb_assert (die_is_declaration (die
, cu
));
21901 if (attr
!= nullptr)
21903 dwarf2_const_value (attr
, sym
, cu
);
21904 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21907 if (attr2
&& (DW_UNSND (attr2
) != 0))
21908 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21910 list_to_add
= cu
->list_in_scope
;
21914 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21915 if (attr
!= nullptr)
21917 var_decode_location (attr
, sym
, cu
);
21918 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21920 /* Fortran explicitly imports any global symbols to the local
21921 scope by DW_TAG_common_block. */
21922 if (cu
->language
== language_fortran
&& die
->parent
21923 && die
->parent
->tag
== DW_TAG_common_block
)
21926 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21927 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21928 && !dwarf2_per_objfile
->has_section_at_zero
)
21930 /* When a static variable is eliminated by the linker,
21931 the corresponding debug information is not stripped
21932 out, but the variable address is set to null;
21933 do not add such variables into symbol table. */
21935 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21937 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21938 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21939 && dwarf2_per_objfile
->can_copy
)
21941 /* A global static variable might be subject to
21942 copy relocation. We first check for a local
21943 minsym, though, because maybe the symbol was
21944 marked hidden, in which case this would not
21946 bound_minimal_symbol found
21947 = (lookup_minimal_symbol_linkage
21948 (sym
->linkage_name (), objfile
));
21949 if (found
.minsym
!= nullptr)
21950 sym
->maybe_copied
= 1;
21953 /* A variable with DW_AT_external is never static,
21954 but it may be block-scoped. */
21956 = ((cu
->list_in_scope
21957 == cu
->get_builder ()->get_file_symbols ())
21958 ? cu
->get_builder ()->get_global_symbols ()
21959 : cu
->list_in_scope
);
21962 list_to_add
= cu
->list_in_scope
;
21966 /* We do not know the address of this symbol.
21967 If it is an external symbol and we have type information
21968 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21969 The address of the variable will then be determined from
21970 the minimal symbol table whenever the variable is
21972 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21974 /* Fortran explicitly imports any global symbols to the local
21975 scope by DW_TAG_common_block. */
21976 if (cu
->language
== language_fortran
&& die
->parent
21977 && die
->parent
->tag
== DW_TAG_common_block
)
21979 /* SYMBOL_CLASS doesn't matter here because
21980 read_common_block is going to reset it. */
21982 list_to_add
= cu
->list_in_scope
;
21984 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21985 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21987 /* A variable with DW_AT_external is never static, but it
21988 may be block-scoped. */
21990 = ((cu
->list_in_scope
21991 == cu
->get_builder ()->get_file_symbols ())
21992 ? cu
->get_builder ()->get_global_symbols ()
21993 : cu
->list_in_scope
);
21995 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21997 else if (!die_is_declaration (die
, cu
))
21999 /* Use the default LOC_OPTIMIZED_OUT class. */
22000 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22002 list_to_add
= cu
->list_in_scope
;
22006 case DW_TAG_formal_parameter
:
22008 /* If we are inside a function, mark this as an argument. If
22009 not, we might be looking at an argument to an inlined function
22010 when we do not have enough information to show inlined frames;
22011 pretend it's a local variable in that case so that the user can
22013 struct context_stack
*curr
22014 = cu
->get_builder ()->get_current_context_stack ();
22015 if (curr
!= nullptr && curr
->name
!= nullptr)
22016 SYMBOL_IS_ARGUMENT (sym
) = 1;
22017 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22018 if (attr
!= nullptr)
22020 var_decode_location (attr
, sym
, cu
);
22022 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22023 if (attr
!= nullptr)
22025 dwarf2_const_value (attr
, sym
, cu
);
22028 list_to_add
= cu
->list_in_scope
;
22031 case DW_TAG_unspecified_parameters
:
22032 /* From varargs functions; gdb doesn't seem to have any
22033 interest in this information, so just ignore it for now.
22036 case DW_TAG_template_type_param
:
22038 /* Fall through. */
22039 case DW_TAG_class_type
:
22040 case DW_TAG_interface_type
:
22041 case DW_TAG_structure_type
:
22042 case DW_TAG_union_type
:
22043 case DW_TAG_set_type
:
22044 case DW_TAG_enumeration_type
:
22045 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22046 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22049 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22050 really ever be static objects: otherwise, if you try
22051 to, say, break of a class's method and you're in a file
22052 which doesn't mention that class, it won't work unless
22053 the check for all static symbols in lookup_symbol_aux
22054 saves you. See the OtherFileClass tests in
22055 gdb.c++/namespace.exp. */
22059 buildsym_compunit
*builder
= cu
->get_builder ();
22061 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22062 && cu
->language
== language_cplus
22063 ? builder
->get_global_symbols ()
22064 : cu
->list_in_scope
);
22066 /* The semantics of C++ state that "struct foo {
22067 ... }" also defines a typedef for "foo". */
22068 if (cu
->language
== language_cplus
22069 || cu
->language
== language_ada
22070 || cu
->language
== language_d
22071 || cu
->language
== language_rust
)
22073 /* The symbol's name is already allocated along
22074 with this objfile, so we don't need to
22075 duplicate it for the type. */
22076 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
22077 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
22082 case DW_TAG_typedef
:
22083 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22084 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22085 list_to_add
= cu
->list_in_scope
;
22087 case DW_TAG_base_type
:
22088 case DW_TAG_subrange_type
:
22089 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22090 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22091 list_to_add
= cu
->list_in_scope
;
22093 case DW_TAG_enumerator
:
22094 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22095 if (attr
!= nullptr)
22097 dwarf2_const_value (attr
, sym
, cu
);
22100 /* NOTE: carlton/2003-11-10: See comment above in the
22101 DW_TAG_class_type, etc. block. */
22104 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22105 && cu
->language
== language_cplus
22106 ? cu
->get_builder ()->get_global_symbols ()
22107 : cu
->list_in_scope
);
22110 case DW_TAG_imported_declaration
:
22111 case DW_TAG_namespace
:
22112 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22113 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22115 case DW_TAG_module
:
22116 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22117 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22118 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22120 case DW_TAG_common_block
:
22121 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22122 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22123 add_symbol_to_list (sym
, cu
->list_in_scope
);
22126 /* Not a tag we recognize. Hopefully we aren't processing
22127 trash data, but since we must specifically ignore things
22128 we don't recognize, there is nothing else we should do at
22130 complaint (_("unsupported tag: '%s'"),
22131 dwarf_tag_name (die
->tag
));
22137 sym
->hash_next
= objfile
->template_symbols
;
22138 objfile
->template_symbols
= sym
;
22139 list_to_add
= NULL
;
22142 if (list_to_add
!= NULL
)
22143 add_symbol_to_list (sym
, list_to_add
);
22145 /* For the benefit of old versions of GCC, check for anonymous
22146 namespaces based on the demangled name. */
22147 if (!cu
->processing_has_namespace_info
22148 && cu
->language
== language_cplus
)
22149 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22154 /* Given an attr with a DW_FORM_dataN value in host byte order,
22155 zero-extend it as appropriate for the symbol's type. The DWARF
22156 standard (v4) is not entirely clear about the meaning of using
22157 DW_FORM_dataN for a constant with a signed type, where the type is
22158 wider than the data. The conclusion of a discussion on the DWARF
22159 list was that this is unspecified. We choose to always zero-extend
22160 because that is the interpretation long in use by GCC. */
22163 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22164 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22166 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22167 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22168 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22169 LONGEST l
= DW_UNSND (attr
);
22171 if (bits
< sizeof (*value
) * 8)
22173 l
&= ((LONGEST
) 1 << bits
) - 1;
22176 else if (bits
== sizeof (*value
) * 8)
22180 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22181 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22188 /* Read a constant value from an attribute. Either set *VALUE, or if
22189 the value does not fit in *VALUE, set *BYTES - either already
22190 allocated on the objfile obstack, or newly allocated on OBSTACK,
22191 or, set *BATON, if we translated the constant to a location
22195 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22196 const char *name
, struct obstack
*obstack
,
22197 struct dwarf2_cu
*cu
,
22198 LONGEST
*value
, const gdb_byte
**bytes
,
22199 struct dwarf2_locexpr_baton
**baton
)
22201 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22202 struct comp_unit_head
*cu_header
= &cu
->header
;
22203 struct dwarf_block
*blk
;
22204 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22205 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22211 switch (attr
->form
)
22214 case DW_FORM_addrx
:
22215 case DW_FORM_GNU_addr_index
:
22219 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22220 dwarf2_const_value_length_mismatch_complaint (name
,
22221 cu_header
->addr_size
,
22222 TYPE_LENGTH (type
));
22223 /* Symbols of this form are reasonably rare, so we just
22224 piggyback on the existing location code rather than writing
22225 a new implementation of symbol_computed_ops. */
22226 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22227 (*baton
)->per_cu
= cu
->per_cu
;
22228 gdb_assert ((*baton
)->per_cu
);
22230 (*baton
)->size
= 2 + cu_header
->addr_size
;
22231 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22232 (*baton
)->data
= data
;
22234 data
[0] = DW_OP_addr
;
22235 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22236 byte_order
, DW_ADDR (attr
));
22237 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22240 case DW_FORM_string
:
22243 case DW_FORM_GNU_str_index
:
22244 case DW_FORM_GNU_strp_alt
:
22245 /* DW_STRING is already allocated on the objfile obstack, point
22247 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22249 case DW_FORM_block1
:
22250 case DW_FORM_block2
:
22251 case DW_FORM_block4
:
22252 case DW_FORM_block
:
22253 case DW_FORM_exprloc
:
22254 case DW_FORM_data16
:
22255 blk
= DW_BLOCK (attr
);
22256 if (TYPE_LENGTH (type
) != blk
->size
)
22257 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22258 TYPE_LENGTH (type
));
22259 *bytes
= blk
->data
;
22262 /* The DW_AT_const_value attributes are supposed to carry the
22263 symbol's value "represented as it would be on the target
22264 architecture." By the time we get here, it's already been
22265 converted to host endianness, so we just need to sign- or
22266 zero-extend it as appropriate. */
22267 case DW_FORM_data1
:
22268 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22270 case DW_FORM_data2
:
22271 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22273 case DW_FORM_data4
:
22274 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22276 case DW_FORM_data8
:
22277 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22280 case DW_FORM_sdata
:
22281 case DW_FORM_implicit_const
:
22282 *value
= DW_SND (attr
);
22285 case DW_FORM_udata
:
22286 *value
= DW_UNSND (attr
);
22290 complaint (_("unsupported const value attribute form: '%s'"),
22291 dwarf_form_name (attr
->form
));
22298 /* Copy constant value from an attribute to a symbol. */
22301 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22302 struct dwarf2_cu
*cu
)
22304 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22306 const gdb_byte
*bytes
;
22307 struct dwarf2_locexpr_baton
*baton
;
22309 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22310 sym
->print_name (),
22311 &objfile
->objfile_obstack
, cu
,
22312 &value
, &bytes
, &baton
);
22316 SYMBOL_LOCATION_BATON (sym
) = baton
;
22317 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22319 else if (bytes
!= NULL
)
22321 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22322 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22326 SYMBOL_VALUE (sym
) = value
;
22327 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22331 /* Return the type of the die in question using its DW_AT_type attribute. */
22333 static struct type
*
22334 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22336 struct attribute
*type_attr
;
22338 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22341 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22342 /* A missing DW_AT_type represents a void type. */
22343 return objfile_type (objfile
)->builtin_void
;
22346 return lookup_die_type (die
, type_attr
, cu
);
22349 /* True iff CU's producer generates GNAT Ada auxiliary information
22350 that allows to find parallel types through that information instead
22351 of having to do expensive parallel lookups by type name. */
22354 need_gnat_info (struct dwarf2_cu
*cu
)
22356 /* Assume that the Ada compiler was GNAT, which always produces
22357 the auxiliary information. */
22358 return (cu
->language
== language_ada
);
22361 /* Return the auxiliary type of the die in question using its
22362 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22363 attribute is not present. */
22365 static struct type
*
22366 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22368 struct attribute
*type_attr
;
22370 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22374 return lookup_die_type (die
, type_attr
, cu
);
22377 /* If DIE has a descriptive_type attribute, then set the TYPE's
22378 descriptive type accordingly. */
22381 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22382 struct dwarf2_cu
*cu
)
22384 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22386 if (descriptive_type
)
22388 ALLOCATE_GNAT_AUX_TYPE (type
);
22389 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22393 /* Return the containing type of the die in question using its
22394 DW_AT_containing_type attribute. */
22396 static struct type
*
22397 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22399 struct attribute
*type_attr
;
22400 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22402 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22404 error (_("Dwarf Error: Problem turning containing type into gdb type "
22405 "[in module %s]"), objfile_name (objfile
));
22407 return lookup_die_type (die
, type_attr
, cu
);
22410 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22412 static struct type
*
22413 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22415 struct dwarf2_per_objfile
*dwarf2_per_objfile
22416 = cu
->per_cu
->dwarf2_per_objfile
;
22417 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22420 std::string message
22421 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22422 objfile_name (objfile
),
22423 sect_offset_str (cu
->header
.sect_off
),
22424 sect_offset_str (die
->sect_off
));
22425 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22427 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22430 /* Look up the type of DIE in CU using its type attribute ATTR.
22431 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22432 DW_AT_containing_type.
22433 If there is no type substitute an error marker. */
22435 static struct type
*
22436 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22437 struct dwarf2_cu
*cu
)
22439 struct dwarf2_per_objfile
*dwarf2_per_objfile
22440 = cu
->per_cu
->dwarf2_per_objfile
;
22441 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22442 struct type
*this_type
;
22444 gdb_assert (attr
->name
== DW_AT_type
22445 || attr
->name
== DW_AT_GNAT_descriptive_type
22446 || attr
->name
== DW_AT_containing_type
);
22448 /* First see if we have it cached. */
22450 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22452 struct dwarf2_per_cu_data
*per_cu
;
22453 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22455 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22456 dwarf2_per_objfile
);
22457 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22459 else if (attr_form_is_ref (attr
))
22461 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22463 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22465 else if (attr
->form
== DW_FORM_ref_sig8
)
22467 ULONGEST signature
= DW_SIGNATURE (attr
);
22469 return get_signatured_type (die
, signature
, cu
);
22473 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22474 " at %s [in module %s]"),
22475 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22476 objfile_name (objfile
));
22477 return build_error_marker_type (cu
, die
);
22480 /* If not cached we need to read it in. */
22482 if (this_type
== NULL
)
22484 struct die_info
*type_die
= NULL
;
22485 struct dwarf2_cu
*type_cu
= cu
;
22487 if (attr_form_is_ref (attr
))
22488 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22489 if (type_die
== NULL
)
22490 return build_error_marker_type (cu
, die
);
22491 /* If we find the type now, it's probably because the type came
22492 from an inter-CU reference and the type's CU got expanded before
22494 this_type
= read_type_die (type_die
, type_cu
);
22497 /* If we still don't have a type use an error marker. */
22499 if (this_type
== NULL
)
22500 return build_error_marker_type (cu
, die
);
22505 /* Return the type in DIE, CU.
22506 Returns NULL for invalid types.
22508 This first does a lookup in die_type_hash,
22509 and only reads the die in if necessary.
22511 NOTE: This can be called when reading in partial or full symbols. */
22513 static struct type
*
22514 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22516 struct type
*this_type
;
22518 this_type
= get_die_type (die
, cu
);
22522 return read_type_die_1 (die
, cu
);
22525 /* Read the type in DIE, CU.
22526 Returns NULL for invalid types. */
22528 static struct type
*
22529 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22531 struct type
*this_type
= NULL
;
22535 case DW_TAG_class_type
:
22536 case DW_TAG_interface_type
:
22537 case DW_TAG_structure_type
:
22538 case DW_TAG_union_type
:
22539 this_type
= read_structure_type (die
, cu
);
22541 case DW_TAG_enumeration_type
:
22542 this_type
= read_enumeration_type (die
, cu
);
22544 case DW_TAG_subprogram
:
22545 case DW_TAG_subroutine_type
:
22546 case DW_TAG_inlined_subroutine
:
22547 this_type
= read_subroutine_type (die
, cu
);
22549 case DW_TAG_array_type
:
22550 this_type
= read_array_type (die
, cu
);
22552 case DW_TAG_set_type
:
22553 this_type
= read_set_type (die
, cu
);
22555 case DW_TAG_pointer_type
:
22556 this_type
= read_tag_pointer_type (die
, cu
);
22558 case DW_TAG_ptr_to_member_type
:
22559 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22561 case DW_TAG_reference_type
:
22562 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22564 case DW_TAG_rvalue_reference_type
:
22565 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22567 case DW_TAG_const_type
:
22568 this_type
= read_tag_const_type (die
, cu
);
22570 case DW_TAG_volatile_type
:
22571 this_type
= read_tag_volatile_type (die
, cu
);
22573 case DW_TAG_restrict_type
:
22574 this_type
= read_tag_restrict_type (die
, cu
);
22576 case DW_TAG_string_type
:
22577 this_type
= read_tag_string_type (die
, cu
);
22579 case DW_TAG_typedef
:
22580 this_type
= read_typedef (die
, cu
);
22582 case DW_TAG_subrange_type
:
22583 this_type
= read_subrange_type (die
, cu
);
22585 case DW_TAG_base_type
:
22586 this_type
= read_base_type (die
, cu
);
22588 case DW_TAG_unspecified_type
:
22589 this_type
= read_unspecified_type (die
, cu
);
22591 case DW_TAG_namespace
:
22592 this_type
= read_namespace_type (die
, cu
);
22594 case DW_TAG_module
:
22595 this_type
= read_module_type (die
, cu
);
22597 case DW_TAG_atomic_type
:
22598 this_type
= read_tag_atomic_type (die
, cu
);
22601 complaint (_("unexpected tag in read_type_die: '%s'"),
22602 dwarf_tag_name (die
->tag
));
22609 /* See if we can figure out if the class lives in a namespace. We do
22610 this by looking for a member function; its demangled name will
22611 contain namespace info, if there is any.
22612 Return the computed name or NULL.
22613 Space for the result is allocated on the objfile's obstack.
22614 This is the full-die version of guess_partial_die_structure_name.
22615 In this case we know DIE has no useful parent. */
22618 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22620 struct die_info
*spec_die
;
22621 struct dwarf2_cu
*spec_cu
;
22622 struct die_info
*child
;
22623 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22626 spec_die
= die_specification (die
, &spec_cu
);
22627 if (spec_die
!= NULL
)
22633 for (child
= die
->child
;
22635 child
= child
->sibling
)
22637 if (child
->tag
== DW_TAG_subprogram
)
22639 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22641 if (linkage_name
!= NULL
)
22644 = language_class_name_from_physname (cu
->language_defn
,
22648 if (actual_name
!= NULL
)
22650 const char *die_name
= dwarf2_name (die
, cu
);
22652 if (die_name
!= NULL
22653 && strcmp (die_name
, actual_name
) != 0)
22655 /* Strip off the class name from the full name.
22656 We want the prefix. */
22657 int die_name_len
= strlen (die_name
);
22658 int actual_name_len
= strlen (actual_name
);
22660 /* Test for '::' as a sanity check. */
22661 if (actual_name_len
> die_name_len
+ 2
22662 && actual_name
[actual_name_len
22663 - die_name_len
- 1] == ':')
22664 name
= obstack_strndup (
22665 &objfile
->per_bfd
->storage_obstack
,
22666 actual_name
, actual_name_len
- die_name_len
- 2);
22669 xfree (actual_name
);
22678 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22679 prefix part in such case. See
22680 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22682 static const char *
22683 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22685 struct attribute
*attr
;
22688 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22689 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22692 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22695 attr
= dw2_linkage_name_attr (die
, cu
);
22696 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22699 /* dwarf2_name had to be already called. */
22700 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22702 /* Strip the base name, keep any leading namespaces/classes. */
22703 base
= strrchr (DW_STRING (attr
), ':');
22704 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22707 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22708 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22710 &base
[-1] - DW_STRING (attr
));
22713 /* Return the name of the namespace/class that DIE is defined within,
22714 or "" if we can't tell. The caller should not xfree the result.
22716 For example, if we're within the method foo() in the following
22726 then determine_prefix on foo's die will return "N::C". */
22728 static const char *
22729 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22731 struct dwarf2_per_objfile
*dwarf2_per_objfile
22732 = cu
->per_cu
->dwarf2_per_objfile
;
22733 struct die_info
*parent
, *spec_die
;
22734 struct dwarf2_cu
*spec_cu
;
22735 struct type
*parent_type
;
22736 const char *retval
;
22738 if (cu
->language
!= language_cplus
22739 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22740 && cu
->language
!= language_rust
)
22743 retval
= anonymous_struct_prefix (die
, cu
);
22747 /* We have to be careful in the presence of DW_AT_specification.
22748 For example, with GCC 3.4, given the code
22752 // Definition of N::foo.
22756 then we'll have a tree of DIEs like this:
22758 1: DW_TAG_compile_unit
22759 2: DW_TAG_namespace // N
22760 3: DW_TAG_subprogram // declaration of N::foo
22761 4: DW_TAG_subprogram // definition of N::foo
22762 DW_AT_specification // refers to die #3
22764 Thus, when processing die #4, we have to pretend that we're in
22765 the context of its DW_AT_specification, namely the contex of die
22768 spec_die
= die_specification (die
, &spec_cu
);
22769 if (spec_die
== NULL
)
22770 parent
= die
->parent
;
22773 parent
= spec_die
->parent
;
22777 if (parent
== NULL
)
22779 else if (parent
->building_fullname
)
22782 const char *parent_name
;
22784 /* It has been seen on RealView 2.2 built binaries,
22785 DW_TAG_template_type_param types actually _defined_ as
22786 children of the parent class:
22789 template class <class Enum> Class{};
22790 Class<enum E> class_e;
22792 1: DW_TAG_class_type (Class)
22793 2: DW_TAG_enumeration_type (E)
22794 3: DW_TAG_enumerator (enum1:0)
22795 3: DW_TAG_enumerator (enum2:1)
22797 2: DW_TAG_template_type_param
22798 DW_AT_type DW_FORM_ref_udata (E)
22800 Besides being broken debug info, it can put GDB into an
22801 infinite loop. Consider:
22803 When we're building the full name for Class<E>, we'll start
22804 at Class, and go look over its template type parameters,
22805 finding E. We'll then try to build the full name of E, and
22806 reach here. We're now trying to build the full name of E,
22807 and look over the parent DIE for containing scope. In the
22808 broken case, if we followed the parent DIE of E, we'd again
22809 find Class, and once again go look at its template type
22810 arguments, etc., etc. Simply don't consider such parent die
22811 as source-level parent of this die (it can't be, the language
22812 doesn't allow it), and break the loop here. */
22813 name
= dwarf2_name (die
, cu
);
22814 parent_name
= dwarf2_name (parent
, cu
);
22815 complaint (_("template param type '%s' defined within parent '%s'"),
22816 name
? name
: "<unknown>",
22817 parent_name
? parent_name
: "<unknown>");
22821 switch (parent
->tag
)
22823 case DW_TAG_namespace
:
22824 parent_type
= read_type_die (parent
, cu
);
22825 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22826 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22827 Work around this problem here. */
22828 if (cu
->language
== language_cplus
22829 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22831 /* We give a name to even anonymous namespaces. */
22832 return TYPE_NAME (parent_type
);
22833 case DW_TAG_class_type
:
22834 case DW_TAG_interface_type
:
22835 case DW_TAG_structure_type
:
22836 case DW_TAG_union_type
:
22837 case DW_TAG_module
:
22838 parent_type
= read_type_die (parent
, cu
);
22839 if (TYPE_NAME (parent_type
) != NULL
)
22840 return TYPE_NAME (parent_type
);
22842 /* An anonymous structure is only allowed non-static data
22843 members; no typedefs, no member functions, et cetera.
22844 So it does not need a prefix. */
22846 case DW_TAG_compile_unit
:
22847 case DW_TAG_partial_unit
:
22848 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22849 if (cu
->language
== language_cplus
22850 && !dwarf2_per_objfile
->types
.empty ()
22851 && die
->child
!= NULL
22852 && (die
->tag
== DW_TAG_class_type
22853 || die
->tag
== DW_TAG_structure_type
22854 || die
->tag
== DW_TAG_union_type
))
22856 char *name
= guess_full_die_structure_name (die
, cu
);
22861 case DW_TAG_subprogram
:
22862 /* Nested subroutines in Fortran get a prefix with the name
22863 of the parent's subroutine. */
22864 if (cu
->language
== language_fortran
)
22866 if ((die
->tag
== DW_TAG_subprogram
)
22867 && (dwarf2_name (parent
, cu
) != NULL
))
22868 return dwarf2_name (parent
, cu
);
22870 return determine_prefix (parent
, cu
);
22871 case DW_TAG_enumeration_type
:
22872 parent_type
= read_type_die (parent
, cu
);
22873 if (TYPE_DECLARED_CLASS (parent_type
))
22875 if (TYPE_NAME (parent_type
) != NULL
)
22876 return TYPE_NAME (parent_type
);
22879 /* Fall through. */
22881 return determine_prefix (parent
, cu
);
22885 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22886 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22887 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22888 an obconcat, otherwise allocate storage for the result. The CU argument is
22889 used to determine the language and hence, the appropriate separator. */
22891 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22894 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22895 int physname
, struct dwarf2_cu
*cu
)
22897 const char *lead
= "";
22900 if (suffix
== NULL
|| suffix
[0] == '\0'
22901 || prefix
== NULL
|| prefix
[0] == '\0')
22903 else if (cu
->language
== language_d
)
22905 /* For D, the 'main' function could be defined in any module, but it
22906 should never be prefixed. */
22907 if (strcmp (suffix
, "D main") == 0)
22915 else if (cu
->language
== language_fortran
&& physname
)
22917 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22918 DW_AT_MIPS_linkage_name is preferred and used instead. */
22926 if (prefix
== NULL
)
22928 if (suffix
== NULL
)
22935 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22937 strcpy (retval
, lead
);
22938 strcat (retval
, prefix
);
22939 strcat (retval
, sep
);
22940 strcat (retval
, suffix
);
22945 /* We have an obstack. */
22946 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22950 /* Return sibling of die, NULL if no sibling. */
22952 static struct die_info
*
22953 sibling_die (struct die_info
*die
)
22955 return die
->sibling
;
22958 /* Get name of a die, return NULL if not found. */
22960 static const char *
22961 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22962 struct obstack
*obstack
)
22964 if (name
&& cu
->language
== language_cplus
)
22966 std::string canon_name
= cp_canonicalize_string (name
);
22968 if (!canon_name
.empty ())
22970 if (canon_name
!= name
)
22971 name
= obstack_strdup (obstack
, canon_name
);
22978 /* Get name of a die, return NULL if not found.
22979 Anonymous namespaces are converted to their magic string. */
22981 static const char *
22982 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22984 struct attribute
*attr
;
22985 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22987 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22988 if ((!attr
|| !DW_STRING (attr
))
22989 && die
->tag
!= DW_TAG_namespace
22990 && die
->tag
!= DW_TAG_class_type
22991 && die
->tag
!= DW_TAG_interface_type
22992 && die
->tag
!= DW_TAG_structure_type
22993 && die
->tag
!= DW_TAG_union_type
)
22998 case DW_TAG_compile_unit
:
22999 case DW_TAG_partial_unit
:
23000 /* Compilation units have a DW_AT_name that is a filename, not
23001 a source language identifier. */
23002 case DW_TAG_enumeration_type
:
23003 case DW_TAG_enumerator
:
23004 /* These tags always have simple identifiers already; no need
23005 to canonicalize them. */
23006 return DW_STRING (attr
);
23008 case DW_TAG_namespace
:
23009 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
23010 return DW_STRING (attr
);
23011 return CP_ANONYMOUS_NAMESPACE_STR
;
23013 case DW_TAG_class_type
:
23014 case DW_TAG_interface_type
:
23015 case DW_TAG_structure_type
:
23016 case DW_TAG_union_type
:
23017 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23018 structures or unions. These were of the form "._%d" in GCC 4.1,
23019 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23020 and GCC 4.4. We work around this problem by ignoring these. */
23021 if (attr
&& DW_STRING (attr
)
23022 && (startswith (DW_STRING (attr
), "._")
23023 || startswith (DW_STRING (attr
), "<anonymous")))
23026 /* GCC might emit a nameless typedef that has a linkage name. See
23027 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23028 if (!attr
|| DW_STRING (attr
) == NULL
)
23030 char *demangled
= NULL
;
23032 attr
= dw2_linkage_name_attr (die
, cu
);
23033 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
23036 /* Avoid demangling DW_STRING (attr) the second time on a second
23037 call for the same DIE. */
23038 if (!DW_STRING_IS_CANONICAL (attr
))
23039 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
23045 /* FIXME: we already did this for the partial symbol... */
23047 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
23049 DW_STRING_IS_CANONICAL (attr
) = 1;
23052 /* Strip any leading namespaces/classes, keep only the base name.
23053 DW_AT_name for named DIEs does not contain the prefixes. */
23054 base
= strrchr (DW_STRING (attr
), ':');
23055 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
23058 return DW_STRING (attr
);
23067 if (!DW_STRING_IS_CANONICAL (attr
))
23070 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
23071 &objfile
->per_bfd
->storage_obstack
);
23072 DW_STRING_IS_CANONICAL (attr
) = 1;
23074 return DW_STRING (attr
);
23077 /* Return the die that this die in an extension of, or NULL if there
23078 is none. *EXT_CU is the CU containing DIE on input, and the CU
23079 containing the return value on output. */
23081 static struct die_info
*
23082 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23084 struct attribute
*attr
;
23086 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23090 return follow_die_ref (die
, attr
, ext_cu
);
23093 /* A convenience function that returns an "unknown" DWARF name,
23094 including the value of V. STR is the name of the entity being
23095 printed, e.g., "TAG". */
23097 static const char *
23098 dwarf_unknown (const char *str
, unsigned v
)
23100 char *cell
= get_print_cell ();
23101 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
23105 /* Convert a DIE tag into its string name. */
23107 static const char *
23108 dwarf_tag_name (unsigned tag
)
23110 const char *name
= get_DW_TAG_name (tag
);
23113 return dwarf_unknown ("TAG", tag
);
23118 /* Convert a DWARF attribute code into its string name. */
23120 static const char *
23121 dwarf_attr_name (unsigned attr
)
23125 #ifdef MIPS /* collides with DW_AT_HP_block_index */
23126 if (attr
== DW_AT_MIPS_fde
)
23127 return "DW_AT_MIPS_fde";
23129 if (attr
== DW_AT_HP_block_index
)
23130 return "DW_AT_HP_block_index";
23133 name
= get_DW_AT_name (attr
);
23136 return dwarf_unknown ("AT", attr
);
23141 /* Convert a unit type to corresponding DW_UT name. */
23143 static const char *
23144 dwarf_unit_type_name (int unit_type
) {
23148 return "DW_UT_compile (0x01)";
23150 return "DW_UT_type (0x02)";
23152 return "DW_UT_partial (0x03)";
23154 return "DW_UT_skeleton (0x04)";
23156 return "DW_UT_split_compile (0x05)";
23158 return "DW_UT_split_type (0x06)";
23160 return "DW_UT_lo_user (0x80)";
23162 return "DW_UT_hi_user (0xff)";
23168 /* Convert a DWARF value form code into its string name. */
23170 static const char *
23171 dwarf_form_name (unsigned form
)
23173 const char *name
= get_DW_FORM_name (form
);
23176 return dwarf_unknown ("FORM", form
);
23181 static const char *
23182 dwarf_bool_name (unsigned mybool
)
23190 /* Convert a DWARF type code into its string name. */
23192 static const char *
23193 dwarf_type_encoding_name (unsigned enc
)
23195 const char *name
= get_DW_ATE_name (enc
);
23198 return dwarf_unknown ("ATE", enc
);
23204 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23208 print_spaces (indent
, f
);
23209 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23210 dwarf_tag_name (die
->tag
), die
->abbrev
,
23211 sect_offset_str (die
->sect_off
));
23213 if (die
->parent
!= NULL
)
23215 print_spaces (indent
, f
);
23216 fprintf_unfiltered (f
, " parent at offset: %s\n",
23217 sect_offset_str (die
->parent
->sect_off
));
23220 print_spaces (indent
, f
);
23221 fprintf_unfiltered (f
, " has children: %s\n",
23222 dwarf_bool_name (die
->child
!= NULL
));
23224 print_spaces (indent
, f
);
23225 fprintf_unfiltered (f
, " attributes:\n");
23227 for (i
= 0; i
< die
->num_attrs
; ++i
)
23229 print_spaces (indent
, f
);
23230 fprintf_unfiltered (f
, " %s (%s) ",
23231 dwarf_attr_name (die
->attrs
[i
].name
),
23232 dwarf_form_name (die
->attrs
[i
].form
));
23234 switch (die
->attrs
[i
].form
)
23237 case DW_FORM_addrx
:
23238 case DW_FORM_GNU_addr_index
:
23239 fprintf_unfiltered (f
, "address: ");
23240 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23242 case DW_FORM_block2
:
23243 case DW_FORM_block4
:
23244 case DW_FORM_block
:
23245 case DW_FORM_block1
:
23246 fprintf_unfiltered (f
, "block: size %s",
23247 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23249 case DW_FORM_exprloc
:
23250 fprintf_unfiltered (f
, "expression: size %s",
23251 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23253 case DW_FORM_data16
:
23254 fprintf_unfiltered (f
, "constant of 16 bytes");
23256 case DW_FORM_ref_addr
:
23257 fprintf_unfiltered (f
, "ref address: ");
23258 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23260 case DW_FORM_GNU_ref_alt
:
23261 fprintf_unfiltered (f
, "alt ref address: ");
23262 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23268 case DW_FORM_ref_udata
:
23269 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23270 (long) (DW_UNSND (&die
->attrs
[i
])));
23272 case DW_FORM_data1
:
23273 case DW_FORM_data2
:
23274 case DW_FORM_data4
:
23275 case DW_FORM_data8
:
23276 case DW_FORM_udata
:
23277 case DW_FORM_sdata
:
23278 fprintf_unfiltered (f
, "constant: %s",
23279 pulongest (DW_UNSND (&die
->attrs
[i
])));
23281 case DW_FORM_sec_offset
:
23282 fprintf_unfiltered (f
, "section offset: %s",
23283 pulongest (DW_UNSND (&die
->attrs
[i
])));
23285 case DW_FORM_ref_sig8
:
23286 fprintf_unfiltered (f
, "signature: %s",
23287 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23289 case DW_FORM_string
:
23291 case DW_FORM_line_strp
:
23293 case DW_FORM_GNU_str_index
:
23294 case DW_FORM_GNU_strp_alt
:
23295 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23296 DW_STRING (&die
->attrs
[i
])
23297 ? DW_STRING (&die
->attrs
[i
]) : "",
23298 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23301 if (DW_UNSND (&die
->attrs
[i
]))
23302 fprintf_unfiltered (f
, "flag: TRUE");
23304 fprintf_unfiltered (f
, "flag: FALSE");
23306 case DW_FORM_flag_present
:
23307 fprintf_unfiltered (f
, "flag: TRUE");
23309 case DW_FORM_indirect
:
23310 /* The reader will have reduced the indirect form to
23311 the "base form" so this form should not occur. */
23312 fprintf_unfiltered (f
,
23313 "unexpected attribute form: DW_FORM_indirect");
23315 case DW_FORM_implicit_const
:
23316 fprintf_unfiltered (f
, "constant: %s",
23317 plongest (DW_SND (&die
->attrs
[i
])));
23320 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23321 die
->attrs
[i
].form
);
23324 fprintf_unfiltered (f
, "\n");
23329 dump_die_for_error (struct die_info
*die
)
23331 dump_die_shallow (gdb_stderr
, 0, die
);
23335 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23337 int indent
= level
* 4;
23339 gdb_assert (die
!= NULL
);
23341 if (level
>= max_level
)
23344 dump_die_shallow (f
, indent
, die
);
23346 if (die
->child
!= NULL
)
23348 print_spaces (indent
, f
);
23349 fprintf_unfiltered (f
, " Children:");
23350 if (level
+ 1 < max_level
)
23352 fprintf_unfiltered (f
, "\n");
23353 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23357 fprintf_unfiltered (f
,
23358 " [not printed, max nesting level reached]\n");
23362 if (die
->sibling
!= NULL
&& level
> 0)
23364 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23368 /* This is called from the pdie macro in gdbinit.in.
23369 It's not static so gcc will keep a copy callable from gdb. */
23372 dump_die (struct die_info
*die
, int max_level
)
23374 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23378 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23382 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23383 to_underlying (die
->sect_off
),
23389 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23393 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23395 if (attr_form_is_ref (attr
))
23396 return (sect_offset
) DW_UNSND (attr
);
23398 complaint (_("unsupported die ref attribute form: '%s'"),
23399 dwarf_form_name (attr
->form
));
23403 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23404 * the value held by the attribute is not constant. */
23407 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23409 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23410 return DW_SND (attr
);
23411 else if (attr
->form
== DW_FORM_udata
23412 || attr
->form
== DW_FORM_data1
23413 || attr
->form
== DW_FORM_data2
23414 || attr
->form
== DW_FORM_data4
23415 || attr
->form
== DW_FORM_data8
)
23416 return DW_UNSND (attr
);
23419 /* For DW_FORM_data16 see attr_form_is_constant. */
23420 complaint (_("Attribute value is not a constant (%s)"),
23421 dwarf_form_name (attr
->form
));
23422 return default_value
;
23426 /* Follow reference or signature attribute ATTR of SRC_DIE.
23427 On entry *REF_CU is the CU of SRC_DIE.
23428 On exit *REF_CU is the CU of the result. */
23430 static struct die_info
*
23431 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23432 struct dwarf2_cu
**ref_cu
)
23434 struct die_info
*die
;
23436 if (attr_form_is_ref (attr
))
23437 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23438 else if (attr
->form
== DW_FORM_ref_sig8
)
23439 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23442 dump_die_for_error (src_die
);
23443 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23444 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23450 /* Follow reference OFFSET.
23451 On entry *REF_CU is the CU of the source die referencing OFFSET.
23452 On exit *REF_CU is the CU of the result.
23453 Returns NULL if OFFSET is invalid. */
23455 static struct die_info
*
23456 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23457 struct dwarf2_cu
**ref_cu
)
23459 struct die_info temp_die
;
23460 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23461 struct dwarf2_per_objfile
*dwarf2_per_objfile
23462 = cu
->per_cu
->dwarf2_per_objfile
;
23464 gdb_assert (cu
->per_cu
!= NULL
);
23468 if (cu
->per_cu
->is_debug_types
)
23470 /* .debug_types CUs cannot reference anything outside their CU.
23471 If they need to, they have to reference a signatured type via
23472 DW_FORM_ref_sig8. */
23473 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23476 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23477 || !offset_in_cu_p (&cu
->header
, sect_off
))
23479 struct dwarf2_per_cu_data
*per_cu
;
23481 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23482 dwarf2_per_objfile
);
23484 /* If necessary, add it to the queue and load its DIEs. */
23485 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23486 load_full_comp_unit (per_cu
, false, cu
->language
);
23488 target_cu
= per_cu
->cu
;
23490 else if (cu
->dies
== NULL
)
23492 /* We're loading full DIEs during partial symbol reading. */
23493 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23494 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23497 *ref_cu
= target_cu
;
23498 temp_die
.sect_off
= sect_off
;
23500 if (target_cu
!= cu
)
23501 target_cu
->ancestor
= cu
;
23503 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23505 to_underlying (sect_off
));
23508 /* Follow reference attribute ATTR of SRC_DIE.
23509 On entry *REF_CU is the CU of SRC_DIE.
23510 On exit *REF_CU is the CU of the result. */
23512 static struct die_info
*
23513 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23514 struct dwarf2_cu
**ref_cu
)
23516 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23517 struct dwarf2_cu
*cu
= *ref_cu
;
23518 struct die_info
*die
;
23520 die
= follow_die_offset (sect_off
,
23521 (attr
->form
== DW_FORM_GNU_ref_alt
23522 || cu
->per_cu
->is_dwz
),
23525 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23526 "at %s [in module %s]"),
23527 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23528 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23533 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23534 Returned value is intended for DW_OP_call*. Returned
23535 dwarf2_locexpr_baton->data has lifetime of
23536 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23538 struct dwarf2_locexpr_baton
23539 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23540 struct dwarf2_per_cu_data
*per_cu
,
23541 CORE_ADDR (*get_frame_pc
) (void *baton
),
23542 void *baton
, bool resolve_abstract_p
)
23544 struct dwarf2_cu
*cu
;
23545 struct die_info
*die
;
23546 struct attribute
*attr
;
23547 struct dwarf2_locexpr_baton retval
;
23548 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23549 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23551 if (per_cu
->cu
== NULL
)
23552 load_cu (per_cu
, false);
23556 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23557 Instead just throw an error, not much else we can do. */
23558 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23559 sect_offset_str (sect_off
), objfile_name (objfile
));
23562 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23564 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23565 sect_offset_str (sect_off
), objfile_name (objfile
));
23567 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23568 if (!attr
&& resolve_abstract_p
23569 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23570 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23572 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23574 = ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23575 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23577 for (const auto &cand_off
23578 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23580 struct dwarf2_cu
*cand_cu
= cu
;
23581 struct die_info
*cand
23582 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23585 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23588 CORE_ADDR pc_low
, pc_high
;
23589 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23590 if (pc_low
== ((CORE_ADDR
) -1))
23592 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23593 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23594 if (!(pc_low
<= pc
&& pc
< pc_high
))
23598 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23605 /* DWARF: "If there is no such attribute, then there is no effect.".
23606 DATA is ignored if SIZE is 0. */
23608 retval
.data
= NULL
;
23611 else if (attr_form_is_section_offset (attr
))
23613 struct dwarf2_loclist_baton loclist_baton
;
23614 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23617 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23619 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23621 retval
.size
= size
;
23625 if (!attr_form_is_block (attr
))
23626 error (_("Dwarf Error: DIE at %s referenced in module %s "
23627 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23628 sect_offset_str (sect_off
), objfile_name (objfile
));
23630 retval
.data
= DW_BLOCK (attr
)->data
;
23631 retval
.size
= DW_BLOCK (attr
)->size
;
23633 retval
.per_cu
= cu
->per_cu
;
23635 age_cached_comp_units (dwarf2_per_objfile
);
23640 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23643 struct dwarf2_locexpr_baton
23644 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23645 struct dwarf2_per_cu_data
*per_cu
,
23646 CORE_ADDR (*get_frame_pc
) (void *baton
),
23649 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23651 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23654 /* Write a constant of a given type as target-ordered bytes into
23657 static const gdb_byte
*
23658 write_constant_as_bytes (struct obstack
*obstack
,
23659 enum bfd_endian byte_order
,
23666 *len
= TYPE_LENGTH (type
);
23667 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23668 store_unsigned_integer (result
, *len
, byte_order
, value
);
23673 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23674 pointer to the constant bytes and set LEN to the length of the
23675 data. If memory is needed, allocate it on OBSTACK. If the DIE
23676 does not have a DW_AT_const_value, return NULL. */
23679 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23680 struct dwarf2_per_cu_data
*per_cu
,
23681 struct obstack
*obstack
,
23684 struct dwarf2_cu
*cu
;
23685 struct die_info
*die
;
23686 struct attribute
*attr
;
23687 const gdb_byte
*result
= NULL
;
23690 enum bfd_endian byte_order
;
23691 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23693 if (per_cu
->cu
== NULL
)
23694 load_cu (per_cu
, false);
23698 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23699 Instead just throw an error, not much else we can do. */
23700 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23701 sect_offset_str (sect_off
), objfile_name (objfile
));
23704 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23706 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23707 sect_offset_str (sect_off
), objfile_name (objfile
));
23709 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23713 byte_order
= (bfd_big_endian (objfile
->obfd
)
23714 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23716 switch (attr
->form
)
23719 case DW_FORM_addrx
:
23720 case DW_FORM_GNU_addr_index
:
23724 *len
= cu
->header
.addr_size
;
23725 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23726 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23730 case DW_FORM_string
:
23733 case DW_FORM_GNU_str_index
:
23734 case DW_FORM_GNU_strp_alt
:
23735 /* DW_STRING is already allocated on the objfile obstack, point
23737 result
= (const gdb_byte
*) DW_STRING (attr
);
23738 *len
= strlen (DW_STRING (attr
));
23740 case DW_FORM_block1
:
23741 case DW_FORM_block2
:
23742 case DW_FORM_block4
:
23743 case DW_FORM_block
:
23744 case DW_FORM_exprloc
:
23745 case DW_FORM_data16
:
23746 result
= DW_BLOCK (attr
)->data
;
23747 *len
= DW_BLOCK (attr
)->size
;
23750 /* The DW_AT_const_value attributes are supposed to carry the
23751 symbol's value "represented as it would be on the target
23752 architecture." By the time we get here, it's already been
23753 converted to host endianness, so we just need to sign- or
23754 zero-extend it as appropriate. */
23755 case DW_FORM_data1
:
23756 type
= die_type (die
, cu
);
23757 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23758 if (result
== NULL
)
23759 result
= write_constant_as_bytes (obstack
, byte_order
,
23762 case DW_FORM_data2
:
23763 type
= die_type (die
, cu
);
23764 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23765 if (result
== NULL
)
23766 result
= write_constant_as_bytes (obstack
, byte_order
,
23769 case DW_FORM_data4
:
23770 type
= die_type (die
, cu
);
23771 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23772 if (result
== NULL
)
23773 result
= write_constant_as_bytes (obstack
, byte_order
,
23776 case DW_FORM_data8
:
23777 type
= die_type (die
, cu
);
23778 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23779 if (result
== NULL
)
23780 result
= write_constant_as_bytes (obstack
, byte_order
,
23784 case DW_FORM_sdata
:
23785 case DW_FORM_implicit_const
:
23786 type
= die_type (die
, cu
);
23787 result
= write_constant_as_bytes (obstack
, byte_order
,
23788 type
, DW_SND (attr
), len
);
23791 case DW_FORM_udata
:
23792 type
= die_type (die
, cu
);
23793 result
= write_constant_as_bytes (obstack
, byte_order
,
23794 type
, DW_UNSND (attr
), len
);
23798 complaint (_("unsupported const value attribute form: '%s'"),
23799 dwarf_form_name (attr
->form
));
23806 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23807 valid type for this die is found. */
23810 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23811 struct dwarf2_per_cu_data
*per_cu
)
23813 struct dwarf2_cu
*cu
;
23814 struct die_info
*die
;
23816 if (per_cu
->cu
== NULL
)
23817 load_cu (per_cu
, false);
23822 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23826 return die_type (die
, cu
);
23829 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23833 dwarf2_get_die_type (cu_offset die_offset
,
23834 struct dwarf2_per_cu_data
*per_cu
)
23836 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23837 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23840 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23841 On entry *REF_CU is the CU of SRC_DIE.
23842 On exit *REF_CU is the CU of the result.
23843 Returns NULL if the referenced DIE isn't found. */
23845 static struct die_info
*
23846 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23847 struct dwarf2_cu
**ref_cu
)
23849 struct die_info temp_die
;
23850 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23851 struct die_info
*die
;
23853 /* While it might be nice to assert sig_type->type == NULL here,
23854 we can get here for DW_AT_imported_declaration where we need
23855 the DIE not the type. */
23857 /* If necessary, add it to the queue and load its DIEs. */
23859 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23860 read_signatured_type (sig_type
);
23862 sig_cu
= sig_type
->per_cu
.cu
;
23863 gdb_assert (sig_cu
!= NULL
);
23864 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23865 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23866 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23867 to_underlying (temp_die
.sect_off
));
23870 struct dwarf2_per_objfile
*dwarf2_per_objfile
23871 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23873 /* For .gdb_index version 7 keep track of included TUs.
23874 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23875 if (dwarf2_per_objfile
->index_table
!= NULL
23876 && dwarf2_per_objfile
->index_table
->version
<= 7)
23878 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23883 sig_cu
->ancestor
= cu
;
23891 /* Follow signatured type referenced by ATTR in SRC_DIE.
23892 On entry *REF_CU is the CU of SRC_DIE.
23893 On exit *REF_CU is the CU of the result.
23894 The result is the DIE of the type.
23895 If the referenced type cannot be found an error is thrown. */
23897 static struct die_info
*
23898 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23899 struct dwarf2_cu
**ref_cu
)
23901 ULONGEST signature
= DW_SIGNATURE (attr
);
23902 struct signatured_type
*sig_type
;
23903 struct die_info
*die
;
23905 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23907 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23908 /* sig_type will be NULL if the signatured type is missing from
23910 if (sig_type
== NULL
)
23912 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23913 " from DIE at %s [in module %s]"),
23914 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23915 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23918 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23921 dump_die_for_error (src_die
);
23922 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23923 " from DIE at %s [in module %s]"),
23924 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23925 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23931 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23932 reading in and processing the type unit if necessary. */
23934 static struct type
*
23935 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23936 struct dwarf2_cu
*cu
)
23938 struct dwarf2_per_objfile
*dwarf2_per_objfile
23939 = cu
->per_cu
->dwarf2_per_objfile
;
23940 struct signatured_type
*sig_type
;
23941 struct dwarf2_cu
*type_cu
;
23942 struct die_info
*type_die
;
23945 sig_type
= lookup_signatured_type (cu
, signature
);
23946 /* sig_type will be NULL if the signatured type is missing from
23948 if (sig_type
== NULL
)
23950 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23951 " from DIE at %s [in module %s]"),
23952 hex_string (signature
), sect_offset_str (die
->sect_off
),
23953 objfile_name (dwarf2_per_objfile
->objfile
));
23954 return build_error_marker_type (cu
, die
);
23957 /* If we already know the type we're done. */
23958 if (sig_type
->type
!= NULL
)
23959 return sig_type
->type
;
23962 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23963 if (type_die
!= NULL
)
23965 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23966 is created. This is important, for example, because for c++ classes
23967 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23968 type
= read_type_die (type_die
, type_cu
);
23971 complaint (_("Dwarf Error: Cannot build signatured type %s"
23972 " referenced from DIE at %s [in module %s]"),
23973 hex_string (signature
), sect_offset_str (die
->sect_off
),
23974 objfile_name (dwarf2_per_objfile
->objfile
));
23975 type
= build_error_marker_type (cu
, die
);
23980 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23981 " from DIE at %s [in module %s]"),
23982 hex_string (signature
), sect_offset_str (die
->sect_off
),
23983 objfile_name (dwarf2_per_objfile
->objfile
));
23984 type
= build_error_marker_type (cu
, die
);
23986 sig_type
->type
= type
;
23991 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23992 reading in and processing the type unit if necessary. */
23994 static struct type
*
23995 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23996 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23998 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23999 if (attr_form_is_ref (attr
))
24001 struct dwarf2_cu
*type_cu
= cu
;
24002 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24004 return read_type_die (type_die
, type_cu
);
24006 else if (attr
->form
== DW_FORM_ref_sig8
)
24008 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
24012 struct dwarf2_per_objfile
*dwarf2_per_objfile
24013 = cu
->per_cu
->dwarf2_per_objfile
;
24015 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24016 " at %s [in module %s]"),
24017 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24018 objfile_name (dwarf2_per_objfile
->objfile
));
24019 return build_error_marker_type (cu
, die
);
24023 /* Load the DIEs associated with type unit PER_CU into memory. */
24026 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
24028 struct signatured_type
*sig_type
;
24030 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24031 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
24033 /* We have the per_cu, but we need the signatured_type.
24034 Fortunately this is an easy translation. */
24035 gdb_assert (per_cu
->is_debug_types
);
24036 sig_type
= (struct signatured_type
*) per_cu
;
24038 gdb_assert (per_cu
->cu
== NULL
);
24040 read_signatured_type (sig_type
);
24042 gdb_assert (per_cu
->cu
!= NULL
);
24045 /* die_reader_func for read_signatured_type.
24046 This is identical to load_full_comp_unit_reader,
24047 but is kept separate for now. */
24050 read_signatured_type_reader (const struct die_reader_specs
*reader
,
24051 const gdb_byte
*info_ptr
,
24052 struct die_info
*comp_unit_die
,
24056 struct dwarf2_cu
*cu
= reader
->cu
;
24058 gdb_assert (cu
->die_hash
== NULL
);
24060 htab_create_alloc_ex (cu
->header
.length
/ 12,
24064 &cu
->comp_unit_obstack
,
24065 hashtab_obstack_allocate
,
24066 dummy_obstack_deallocate
);
24069 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
24070 &info_ptr
, comp_unit_die
);
24071 cu
->dies
= comp_unit_die
;
24072 /* comp_unit_die is not stored in die_hash, no need. */
24074 /* We try not to read any attributes in this function, because not
24075 all CUs needed for references have been loaded yet, and symbol
24076 table processing isn't initialized. But we have to set the CU language,
24077 or we won't be able to build types correctly.
24078 Similarly, if we do not read the producer, we can not apply
24079 producer-specific interpretation. */
24080 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24083 /* Read in a signatured type and build its CU and DIEs.
24084 If the type is a stub for the real type in a DWO file,
24085 read in the real type from the DWO file as well. */
24088 read_signatured_type (struct signatured_type
*sig_type
)
24090 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24092 gdb_assert (per_cu
->is_debug_types
);
24093 gdb_assert (per_cu
->cu
== NULL
);
24095 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
24096 read_signatured_type_reader
, NULL
);
24097 sig_type
->per_cu
.tu_read
= 1;
24100 /* Decode simple location descriptions.
24101 Given a pointer to a dwarf block that defines a location, compute
24102 the location and return the value.
24104 NOTE drow/2003-11-18: This function is called in two situations
24105 now: for the address of static or global variables (partial symbols
24106 only) and for offsets into structures which are expected to be
24107 (more or less) constant. The partial symbol case should go away,
24108 and only the constant case should remain. That will let this
24109 function complain more accurately. A few special modes are allowed
24110 without complaint for global variables (for instance, global
24111 register values and thread-local values).
24113 A location description containing no operations indicates that the
24114 object is optimized out. The return value is 0 for that case.
24115 FIXME drow/2003-11-16: No callers check for this case any more; soon all
24116 callers will only want a very basic result and this can become a
24119 Note that stack[0] is unused except as a default error return. */
24122 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
24124 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
24126 size_t size
= blk
->size
;
24127 const gdb_byte
*data
= blk
->data
;
24128 CORE_ADDR stack
[64];
24130 unsigned int bytes_read
, unsnd
;
24136 stack
[++stacki
] = 0;
24175 stack
[++stacki
] = op
- DW_OP_lit0
;
24210 stack
[++stacki
] = op
- DW_OP_reg0
;
24212 dwarf2_complex_location_expr_complaint ();
24216 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24218 stack
[++stacki
] = unsnd
;
24220 dwarf2_complex_location_expr_complaint ();
24224 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24229 case DW_OP_const1u
:
24230 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24234 case DW_OP_const1s
:
24235 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24239 case DW_OP_const2u
:
24240 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24244 case DW_OP_const2s
:
24245 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24249 case DW_OP_const4u
:
24250 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24254 case DW_OP_const4s
:
24255 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24259 case DW_OP_const8u
:
24260 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24265 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24271 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24276 stack
[stacki
+ 1] = stack
[stacki
];
24281 stack
[stacki
- 1] += stack
[stacki
];
24285 case DW_OP_plus_uconst
:
24286 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24292 stack
[stacki
- 1] -= stack
[stacki
];
24297 /* If we're not the last op, then we definitely can't encode
24298 this using GDB's address_class enum. This is valid for partial
24299 global symbols, although the variable's address will be bogus
24302 dwarf2_complex_location_expr_complaint ();
24305 case DW_OP_GNU_push_tls_address
:
24306 case DW_OP_form_tls_address
:
24307 /* The top of the stack has the offset from the beginning
24308 of the thread control block at which the variable is located. */
24309 /* Nothing should follow this operator, so the top of stack would
24311 /* This is valid for partial global symbols, but the variable's
24312 address will be bogus in the psymtab. Make it always at least
24313 non-zero to not look as a variable garbage collected by linker
24314 which have DW_OP_addr 0. */
24316 dwarf2_complex_location_expr_complaint ();
24320 case DW_OP_GNU_uninit
:
24324 case DW_OP_GNU_addr_index
:
24325 case DW_OP_GNU_const_index
:
24326 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24333 const char *name
= get_DW_OP_name (op
);
24336 complaint (_("unsupported stack op: '%s'"),
24339 complaint (_("unsupported stack op: '%02x'"),
24343 return (stack
[stacki
]);
24346 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24347 outside of the allocated space. Also enforce minimum>0. */
24348 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24350 complaint (_("location description stack overflow"));
24356 complaint (_("location description stack underflow"));
24360 return (stack
[stacki
]);
24363 /* memory allocation interface */
24365 static struct dwarf_block
*
24366 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24368 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24371 static struct die_info
*
24372 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24374 struct die_info
*die
;
24375 size_t size
= sizeof (struct die_info
);
24378 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24380 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24381 memset (die
, 0, sizeof (struct die_info
));
24386 /* Macro support. */
24388 /* Return file name relative to the compilation directory of file number I in
24389 *LH's file name table. The result is allocated using xmalloc; the caller is
24390 responsible for freeing it. */
24393 file_file_name (int file
, struct line_header
*lh
)
24395 /* Is the file number a valid index into the line header's file name
24396 table? Remember that file numbers start with one, not zero. */
24397 if (lh
->is_valid_file_index (file
))
24399 const file_entry
*fe
= lh
->file_name_at (file
);
24401 if (!IS_ABSOLUTE_PATH (fe
->name
))
24403 const char *dir
= fe
->include_dir (lh
);
24405 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24407 return xstrdup (fe
->name
);
24411 /* The compiler produced a bogus file number. We can at least
24412 record the macro definitions made in the file, even if we
24413 won't be able to find the file by name. */
24414 char fake_name
[80];
24416 xsnprintf (fake_name
, sizeof (fake_name
),
24417 "<bad macro file number %d>", file
);
24419 complaint (_("bad file number in macro information (%d)"),
24422 return xstrdup (fake_name
);
24426 /* Return the full name of file number I in *LH's file name table.
24427 Use COMP_DIR as the name of the current directory of the
24428 compilation. The result is allocated using xmalloc; the caller is
24429 responsible for freeing it. */
24431 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24433 /* Is the file number a valid index into the line header's file name
24434 table? Remember that file numbers start with one, not zero. */
24435 if (lh
->is_valid_file_index (file
))
24437 char *relative
= file_file_name (file
, lh
);
24439 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24441 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24442 relative
, (char *) NULL
);
24445 return file_file_name (file
, lh
);
24449 static struct macro_source_file
*
24450 macro_start_file (struct dwarf2_cu
*cu
,
24451 int file
, int line
,
24452 struct macro_source_file
*current_file
,
24453 struct line_header
*lh
)
24455 /* File name relative to the compilation directory of this source file. */
24456 char *file_name
= file_file_name (file
, lh
);
24458 if (! current_file
)
24460 /* Note: We don't create a macro table for this compilation unit
24461 at all until we actually get a filename. */
24462 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24464 /* If we have no current file, then this must be the start_file
24465 directive for the compilation unit's main source file. */
24466 current_file
= macro_set_main (macro_table
, file_name
);
24467 macro_define_special (macro_table
);
24470 current_file
= macro_include (current_file
, line
, file_name
);
24474 return current_file
;
24477 static const char *
24478 consume_improper_spaces (const char *p
, const char *body
)
24482 complaint (_("macro definition contains spaces "
24483 "in formal argument list:\n`%s'"),
24495 parse_macro_definition (struct macro_source_file
*file
, int line
,
24500 /* The body string takes one of two forms. For object-like macro
24501 definitions, it should be:
24503 <macro name> " " <definition>
24505 For function-like macro definitions, it should be:
24507 <macro name> "() " <definition>
24509 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24511 Spaces may appear only where explicitly indicated, and in the
24514 The Dwarf 2 spec says that an object-like macro's name is always
24515 followed by a space, but versions of GCC around March 2002 omit
24516 the space when the macro's definition is the empty string.
24518 The Dwarf 2 spec says that there should be no spaces between the
24519 formal arguments in a function-like macro's formal argument list,
24520 but versions of GCC around March 2002 include spaces after the
24524 /* Find the extent of the macro name. The macro name is terminated
24525 by either a space or null character (for an object-like macro) or
24526 an opening paren (for a function-like macro). */
24527 for (p
= body
; *p
; p
++)
24528 if (*p
== ' ' || *p
== '(')
24531 if (*p
== ' ' || *p
== '\0')
24533 /* It's an object-like macro. */
24534 int name_len
= p
- body
;
24535 char *name
= savestring (body
, name_len
);
24536 const char *replacement
;
24539 replacement
= body
+ name_len
+ 1;
24542 dwarf2_macro_malformed_definition_complaint (body
);
24543 replacement
= body
+ name_len
;
24546 macro_define_object (file
, line
, name
, replacement
);
24550 else if (*p
== '(')
24552 /* It's a function-like macro. */
24553 char *name
= savestring (body
, p
- body
);
24556 char **argv
= XNEWVEC (char *, argv_size
);
24560 p
= consume_improper_spaces (p
, body
);
24562 /* Parse the formal argument list. */
24563 while (*p
&& *p
!= ')')
24565 /* Find the extent of the current argument name. */
24566 const char *arg_start
= p
;
24568 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24571 if (! *p
|| p
== arg_start
)
24572 dwarf2_macro_malformed_definition_complaint (body
);
24575 /* Make sure argv has room for the new argument. */
24576 if (argc
>= argv_size
)
24579 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24582 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24585 p
= consume_improper_spaces (p
, body
);
24587 /* Consume the comma, if present. */
24592 p
= consume_improper_spaces (p
, body
);
24601 /* Perfectly formed definition, no complaints. */
24602 macro_define_function (file
, line
, name
,
24603 argc
, (const char **) argv
,
24605 else if (*p
== '\0')
24607 /* Complain, but do define it. */
24608 dwarf2_macro_malformed_definition_complaint (body
);
24609 macro_define_function (file
, line
, name
,
24610 argc
, (const char **) argv
,
24614 /* Just complain. */
24615 dwarf2_macro_malformed_definition_complaint (body
);
24618 /* Just complain. */
24619 dwarf2_macro_malformed_definition_complaint (body
);
24625 for (i
= 0; i
< argc
; i
++)
24631 dwarf2_macro_malformed_definition_complaint (body
);
24634 /* Skip some bytes from BYTES according to the form given in FORM.
24635 Returns the new pointer. */
24637 static const gdb_byte
*
24638 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24639 enum dwarf_form form
,
24640 unsigned int offset_size
,
24641 struct dwarf2_section_info
*section
)
24643 unsigned int bytes_read
;
24647 case DW_FORM_data1
:
24652 case DW_FORM_data2
:
24656 case DW_FORM_data4
:
24660 case DW_FORM_data8
:
24664 case DW_FORM_data16
:
24668 case DW_FORM_string
:
24669 read_direct_string (abfd
, bytes
, &bytes_read
);
24670 bytes
+= bytes_read
;
24673 case DW_FORM_sec_offset
:
24675 case DW_FORM_GNU_strp_alt
:
24676 bytes
+= offset_size
;
24679 case DW_FORM_block
:
24680 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24681 bytes
+= bytes_read
;
24684 case DW_FORM_block1
:
24685 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24687 case DW_FORM_block2
:
24688 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24690 case DW_FORM_block4
:
24691 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24694 case DW_FORM_addrx
:
24695 case DW_FORM_sdata
:
24697 case DW_FORM_udata
:
24698 case DW_FORM_GNU_addr_index
:
24699 case DW_FORM_GNU_str_index
:
24700 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24703 dwarf2_section_buffer_overflow_complaint (section
);
24708 case DW_FORM_implicit_const
:
24713 complaint (_("invalid form 0x%x in `%s'"),
24714 form
, get_section_name (section
));
24722 /* A helper for dwarf_decode_macros that handles skipping an unknown
24723 opcode. Returns an updated pointer to the macro data buffer; or,
24724 on error, issues a complaint and returns NULL. */
24726 static const gdb_byte
*
24727 skip_unknown_opcode (unsigned int opcode
,
24728 const gdb_byte
**opcode_definitions
,
24729 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24731 unsigned int offset_size
,
24732 struct dwarf2_section_info
*section
)
24734 unsigned int bytes_read
, i
;
24736 const gdb_byte
*defn
;
24738 if (opcode_definitions
[opcode
] == NULL
)
24740 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24745 defn
= opcode_definitions
[opcode
];
24746 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24747 defn
+= bytes_read
;
24749 for (i
= 0; i
< arg
; ++i
)
24751 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24752 (enum dwarf_form
) defn
[i
], offset_size
,
24754 if (mac_ptr
== NULL
)
24756 /* skip_form_bytes already issued the complaint. */
24764 /* A helper function which parses the header of a macro section.
24765 If the macro section is the extended (for now called "GNU") type,
24766 then this updates *OFFSET_SIZE. Returns a pointer to just after
24767 the header, or issues a complaint and returns NULL on error. */
24769 static const gdb_byte
*
24770 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24772 const gdb_byte
*mac_ptr
,
24773 unsigned int *offset_size
,
24774 int section_is_gnu
)
24776 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24778 if (section_is_gnu
)
24780 unsigned int version
, flags
;
24782 version
= read_2_bytes (abfd
, mac_ptr
);
24783 if (version
!= 4 && version
!= 5)
24785 complaint (_("unrecognized version `%d' in .debug_macro section"),
24791 flags
= read_1_byte (abfd
, mac_ptr
);
24793 *offset_size
= (flags
& 1) ? 8 : 4;
24795 if ((flags
& 2) != 0)
24796 /* We don't need the line table offset. */
24797 mac_ptr
+= *offset_size
;
24799 /* Vendor opcode descriptions. */
24800 if ((flags
& 4) != 0)
24802 unsigned int i
, count
;
24804 count
= read_1_byte (abfd
, mac_ptr
);
24806 for (i
= 0; i
< count
; ++i
)
24808 unsigned int opcode
, bytes_read
;
24811 opcode
= read_1_byte (abfd
, mac_ptr
);
24813 opcode_definitions
[opcode
] = mac_ptr
;
24814 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24815 mac_ptr
+= bytes_read
;
24824 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24825 including DW_MACRO_import. */
24828 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24830 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24831 struct macro_source_file
*current_file
,
24832 struct line_header
*lh
,
24833 struct dwarf2_section_info
*section
,
24834 int section_is_gnu
, int section_is_dwz
,
24835 unsigned int offset_size
,
24836 htab_t include_hash
)
24838 struct dwarf2_per_objfile
*dwarf2_per_objfile
24839 = cu
->per_cu
->dwarf2_per_objfile
;
24840 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24841 enum dwarf_macro_record_type macinfo_type
;
24842 int at_commandline
;
24843 const gdb_byte
*opcode_definitions
[256];
24845 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24846 &offset_size
, section_is_gnu
);
24847 if (mac_ptr
== NULL
)
24849 /* We already issued a complaint. */
24853 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24854 GDB is still reading the definitions from command line. First
24855 DW_MACINFO_start_file will need to be ignored as it was already executed
24856 to create CURRENT_FILE for the main source holding also the command line
24857 definitions. On first met DW_MACINFO_start_file this flag is reset to
24858 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24860 at_commandline
= 1;
24864 /* Do we at least have room for a macinfo type byte? */
24865 if (mac_ptr
>= mac_end
)
24867 dwarf2_section_buffer_overflow_complaint (section
);
24871 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24874 /* Note that we rely on the fact that the corresponding GNU and
24875 DWARF constants are the same. */
24877 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24878 switch (macinfo_type
)
24880 /* A zero macinfo type indicates the end of the macro
24885 case DW_MACRO_define
:
24886 case DW_MACRO_undef
:
24887 case DW_MACRO_define_strp
:
24888 case DW_MACRO_undef_strp
:
24889 case DW_MACRO_define_sup
:
24890 case DW_MACRO_undef_sup
:
24892 unsigned int bytes_read
;
24897 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24898 mac_ptr
+= bytes_read
;
24900 if (macinfo_type
== DW_MACRO_define
24901 || macinfo_type
== DW_MACRO_undef
)
24903 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24904 mac_ptr
+= bytes_read
;
24908 LONGEST str_offset
;
24910 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24911 mac_ptr
+= offset_size
;
24913 if (macinfo_type
== DW_MACRO_define_sup
24914 || macinfo_type
== DW_MACRO_undef_sup
24917 struct dwz_file
*dwz
24918 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24920 body
= read_indirect_string_from_dwz (objfile
,
24924 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24928 is_define
= (macinfo_type
== DW_MACRO_define
24929 || macinfo_type
== DW_MACRO_define_strp
24930 || macinfo_type
== DW_MACRO_define_sup
);
24931 if (! current_file
)
24933 /* DWARF violation as no main source is present. */
24934 complaint (_("debug info with no main source gives macro %s "
24936 is_define
? _("definition") : _("undefinition"),
24940 if ((line
== 0 && !at_commandline
)
24941 || (line
!= 0 && at_commandline
))
24942 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24943 at_commandline
? _("command-line") : _("in-file"),
24944 is_define
? _("definition") : _("undefinition"),
24945 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24949 /* Fedora's rpm-build's "debugedit" binary
24950 corrupted .debug_macro sections.
24953 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24954 complaint (_("debug info gives %s invalid macro %s "
24955 "without body (corrupted?) at line %d "
24957 at_commandline
? _("command-line") : _("in-file"),
24958 is_define
? _("definition") : _("undefinition"),
24959 line
, current_file
->filename
);
24961 else if (is_define
)
24962 parse_macro_definition (current_file
, line
, body
);
24965 gdb_assert (macinfo_type
== DW_MACRO_undef
24966 || macinfo_type
== DW_MACRO_undef_strp
24967 || macinfo_type
== DW_MACRO_undef_sup
);
24968 macro_undef (current_file
, line
, body
);
24973 case DW_MACRO_start_file
:
24975 unsigned int bytes_read
;
24978 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24979 mac_ptr
+= bytes_read
;
24980 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24981 mac_ptr
+= bytes_read
;
24983 if ((line
== 0 && !at_commandline
)
24984 || (line
!= 0 && at_commandline
))
24985 complaint (_("debug info gives source %d included "
24986 "from %s at %s line %d"),
24987 file
, at_commandline
? _("command-line") : _("file"),
24988 line
== 0 ? _("zero") : _("non-zero"), line
);
24990 if (at_commandline
)
24992 /* This DW_MACRO_start_file was executed in the
24994 at_commandline
= 0;
24997 current_file
= macro_start_file (cu
, file
, line
, current_file
,
25002 case DW_MACRO_end_file
:
25003 if (! current_file
)
25004 complaint (_("macro debug info has an unmatched "
25005 "`close_file' directive"));
25008 current_file
= current_file
->included_by
;
25009 if (! current_file
)
25011 enum dwarf_macro_record_type next_type
;
25013 /* GCC circa March 2002 doesn't produce the zero
25014 type byte marking the end of the compilation
25015 unit. Complain if it's not there, but exit no
25018 /* Do we at least have room for a macinfo type byte? */
25019 if (mac_ptr
>= mac_end
)
25021 dwarf2_section_buffer_overflow_complaint (section
);
25025 /* We don't increment mac_ptr here, so this is just
25028 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
25030 if (next_type
!= 0)
25031 complaint (_("no terminating 0-type entry for "
25032 "macros in `.debug_macinfo' section"));
25039 case DW_MACRO_import
:
25040 case DW_MACRO_import_sup
:
25044 bfd
*include_bfd
= abfd
;
25045 struct dwarf2_section_info
*include_section
= section
;
25046 const gdb_byte
*include_mac_end
= mac_end
;
25047 int is_dwz
= section_is_dwz
;
25048 const gdb_byte
*new_mac_ptr
;
25050 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25051 mac_ptr
+= offset_size
;
25053 if (macinfo_type
== DW_MACRO_import_sup
)
25055 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
25057 dwarf2_read_section (objfile
, &dwz
->macro
);
25059 include_section
= &dwz
->macro
;
25060 include_bfd
= get_section_bfd_owner (include_section
);
25061 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
25065 new_mac_ptr
= include_section
->buffer
+ offset
;
25066 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
25070 /* This has actually happened; see
25071 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
25072 complaint (_("recursive DW_MACRO_import in "
25073 ".debug_macro section"));
25077 *slot
= (void *) new_mac_ptr
;
25079 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
25080 include_mac_end
, current_file
, lh
,
25081 section
, section_is_gnu
, is_dwz
,
25082 offset_size
, include_hash
);
25084 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
25089 case DW_MACINFO_vendor_ext
:
25090 if (!section_is_gnu
)
25092 unsigned int bytes_read
;
25094 /* This reads the constant, but since we don't recognize
25095 any vendor extensions, we ignore it. */
25096 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25097 mac_ptr
+= bytes_read
;
25098 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25099 mac_ptr
+= bytes_read
;
25101 /* We don't recognize any vendor extensions. */
25107 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25108 mac_ptr
, mac_end
, abfd
, offset_size
,
25110 if (mac_ptr
== NULL
)
25115 } while (macinfo_type
!= 0);
25119 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25120 int section_is_gnu
)
25122 struct dwarf2_per_objfile
*dwarf2_per_objfile
25123 = cu
->per_cu
->dwarf2_per_objfile
;
25124 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25125 struct line_header
*lh
= cu
->line_header
;
25127 const gdb_byte
*mac_ptr
, *mac_end
;
25128 struct macro_source_file
*current_file
= 0;
25129 enum dwarf_macro_record_type macinfo_type
;
25130 unsigned int offset_size
= cu
->header
.offset_size
;
25131 const gdb_byte
*opcode_definitions
[256];
25133 struct dwarf2_section_info
*section
;
25134 const char *section_name
;
25136 if (cu
->dwo_unit
!= NULL
)
25138 if (section_is_gnu
)
25140 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25141 section_name
= ".debug_macro.dwo";
25145 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25146 section_name
= ".debug_macinfo.dwo";
25151 if (section_is_gnu
)
25153 section
= &dwarf2_per_objfile
->macro
;
25154 section_name
= ".debug_macro";
25158 section
= &dwarf2_per_objfile
->macinfo
;
25159 section_name
= ".debug_macinfo";
25163 dwarf2_read_section (objfile
, section
);
25164 if (section
->buffer
== NULL
)
25166 complaint (_("missing %s section"), section_name
);
25169 abfd
= get_section_bfd_owner (section
);
25171 /* First pass: Find the name of the base filename.
25172 This filename is needed in order to process all macros whose definition
25173 (or undefinition) comes from the command line. These macros are defined
25174 before the first DW_MACINFO_start_file entry, and yet still need to be
25175 associated to the base file.
25177 To determine the base file name, we scan the macro definitions until we
25178 reach the first DW_MACINFO_start_file entry. We then initialize
25179 CURRENT_FILE accordingly so that any macro definition found before the
25180 first DW_MACINFO_start_file can still be associated to the base file. */
25182 mac_ptr
= section
->buffer
+ offset
;
25183 mac_end
= section
->buffer
+ section
->size
;
25185 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25186 &offset_size
, section_is_gnu
);
25187 if (mac_ptr
== NULL
)
25189 /* We already issued a complaint. */
25195 /* Do we at least have room for a macinfo type byte? */
25196 if (mac_ptr
>= mac_end
)
25198 /* Complaint is printed during the second pass as GDB will probably
25199 stop the first pass earlier upon finding
25200 DW_MACINFO_start_file. */
25204 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25207 /* Note that we rely on the fact that the corresponding GNU and
25208 DWARF constants are the same. */
25210 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25211 switch (macinfo_type
)
25213 /* A zero macinfo type indicates the end of the macro
25218 case DW_MACRO_define
:
25219 case DW_MACRO_undef
:
25220 /* Only skip the data by MAC_PTR. */
25222 unsigned int bytes_read
;
25224 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25225 mac_ptr
+= bytes_read
;
25226 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25227 mac_ptr
+= bytes_read
;
25231 case DW_MACRO_start_file
:
25233 unsigned int bytes_read
;
25236 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25237 mac_ptr
+= bytes_read
;
25238 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25239 mac_ptr
+= bytes_read
;
25241 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25245 case DW_MACRO_end_file
:
25246 /* No data to skip by MAC_PTR. */
25249 case DW_MACRO_define_strp
:
25250 case DW_MACRO_undef_strp
:
25251 case DW_MACRO_define_sup
:
25252 case DW_MACRO_undef_sup
:
25254 unsigned int bytes_read
;
25256 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25257 mac_ptr
+= bytes_read
;
25258 mac_ptr
+= offset_size
;
25262 case DW_MACRO_import
:
25263 case DW_MACRO_import_sup
:
25264 /* Note that, according to the spec, a transparent include
25265 chain cannot call DW_MACRO_start_file. So, we can just
25266 skip this opcode. */
25267 mac_ptr
+= offset_size
;
25270 case DW_MACINFO_vendor_ext
:
25271 /* Only skip the data by MAC_PTR. */
25272 if (!section_is_gnu
)
25274 unsigned int bytes_read
;
25276 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25277 mac_ptr
+= bytes_read
;
25278 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25279 mac_ptr
+= bytes_read
;
25284 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25285 mac_ptr
, mac_end
, abfd
, offset_size
,
25287 if (mac_ptr
== NULL
)
25292 } while (macinfo_type
!= 0 && current_file
== NULL
);
25294 /* Second pass: Process all entries.
25296 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25297 command-line macro definitions/undefinitions. This flag is unset when we
25298 reach the first DW_MACINFO_start_file entry. */
25300 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25302 NULL
, xcalloc
, xfree
));
25303 mac_ptr
= section
->buffer
+ offset
;
25304 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25305 *slot
= (void *) mac_ptr
;
25306 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25307 current_file
, lh
, section
,
25308 section_is_gnu
, 0, offset_size
,
25309 include_hash
.get ());
25312 /* Check if the attribute's form is a DW_FORM_block*
25313 if so return true else false. */
25316 attr_form_is_block (const struct attribute
*attr
)
25318 return (attr
== NULL
? 0 :
25319 attr
->form
== DW_FORM_block1
25320 || attr
->form
== DW_FORM_block2
25321 || attr
->form
== DW_FORM_block4
25322 || attr
->form
== DW_FORM_block
25323 || attr
->form
== DW_FORM_exprloc
);
25326 /* Return non-zero if ATTR's value is a section offset --- classes
25327 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25328 You may use DW_UNSND (attr) to retrieve such offsets.
25330 Section 7.5.4, "Attribute Encodings", explains that no attribute
25331 may have a value that belongs to more than one of these classes; it
25332 would be ambiguous if we did, because we use the same forms for all
25336 attr_form_is_section_offset (const struct attribute
*attr
)
25338 return (attr
->form
== DW_FORM_data4
25339 || attr
->form
== DW_FORM_data8
25340 || attr
->form
== DW_FORM_sec_offset
);
25343 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25344 zero otherwise. When this function returns true, you can apply
25345 dwarf2_get_attr_constant_value to it.
25347 However, note that for some attributes you must check
25348 attr_form_is_section_offset before using this test. DW_FORM_data4
25349 and DW_FORM_data8 are members of both the constant class, and of
25350 the classes that contain offsets into other debug sections
25351 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25352 that, if an attribute's can be either a constant or one of the
25353 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25354 taken as section offsets, not constants.
25356 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25357 cannot handle that. */
25360 attr_form_is_constant (const struct attribute
*attr
)
25362 switch (attr
->form
)
25364 case DW_FORM_sdata
:
25365 case DW_FORM_udata
:
25366 case DW_FORM_data1
:
25367 case DW_FORM_data2
:
25368 case DW_FORM_data4
:
25369 case DW_FORM_data8
:
25370 case DW_FORM_implicit_const
:
25378 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25379 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25382 attr_form_is_ref (const struct attribute
*attr
)
25384 switch (attr
->form
)
25386 case DW_FORM_ref_addr
:
25391 case DW_FORM_ref_udata
:
25392 case DW_FORM_GNU_ref_alt
:
25399 /* Return the .debug_loc section to use for CU.
25400 For DWO files use .debug_loc.dwo. */
25402 static struct dwarf2_section_info
*
25403 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25405 struct dwarf2_per_objfile
*dwarf2_per_objfile
25406 = cu
->per_cu
->dwarf2_per_objfile
;
25410 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25412 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25414 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25415 : &dwarf2_per_objfile
->loc
);
25418 /* A helper function that fills in a dwarf2_loclist_baton. */
25421 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25422 struct dwarf2_loclist_baton
*baton
,
25423 const struct attribute
*attr
)
25425 struct dwarf2_per_objfile
*dwarf2_per_objfile
25426 = cu
->per_cu
->dwarf2_per_objfile
;
25427 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25429 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25431 baton
->per_cu
= cu
->per_cu
;
25432 gdb_assert (baton
->per_cu
);
25433 /* We don't know how long the location list is, but make sure we
25434 don't run off the edge of the section. */
25435 baton
->size
= section
->size
- DW_UNSND (attr
);
25436 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25437 baton
->base_address
= cu
->base_address
;
25438 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25442 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25443 struct dwarf2_cu
*cu
, int is_block
)
25445 struct dwarf2_per_objfile
*dwarf2_per_objfile
25446 = cu
->per_cu
->dwarf2_per_objfile
;
25447 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25448 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25450 if (attr_form_is_section_offset (attr
)
25451 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25452 the section. If so, fall through to the complaint in the
25454 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25456 struct dwarf2_loclist_baton
*baton
;
25458 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25460 fill_in_loclist_baton (cu
, baton
, attr
);
25462 if (cu
->base_known
== 0)
25463 complaint (_("Location list used without "
25464 "specifying the CU base address."));
25466 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25467 ? dwarf2_loclist_block_index
25468 : dwarf2_loclist_index
);
25469 SYMBOL_LOCATION_BATON (sym
) = baton
;
25473 struct dwarf2_locexpr_baton
*baton
;
25475 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25476 baton
->per_cu
= cu
->per_cu
;
25477 gdb_assert (baton
->per_cu
);
25479 if (attr_form_is_block (attr
))
25481 /* Note that we're just copying the block's data pointer
25482 here, not the actual data. We're still pointing into the
25483 info_buffer for SYM's objfile; right now we never release
25484 that buffer, but when we do clean up properly this may
25486 baton
->size
= DW_BLOCK (attr
)->size
;
25487 baton
->data
= DW_BLOCK (attr
)->data
;
25491 dwarf2_invalid_attrib_class_complaint ("location description",
25492 sym
->natural_name ());
25496 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25497 ? dwarf2_locexpr_block_index
25498 : dwarf2_locexpr_index
);
25499 SYMBOL_LOCATION_BATON (sym
) = baton
;
25503 /* Return the OBJFILE associated with the compilation unit CU. If CU
25504 came from a separate debuginfo file, then the master objfile is
25508 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25510 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25512 /* Return the master objfile, so that we can report and look up the
25513 correct file containing this variable. */
25514 if (objfile
->separate_debug_objfile_backlink
)
25515 objfile
= objfile
->separate_debug_objfile_backlink
;
25520 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25521 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25522 CU_HEADERP first. */
25524 static const struct comp_unit_head
*
25525 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25526 struct dwarf2_per_cu_data
*per_cu
)
25528 const gdb_byte
*info_ptr
;
25531 return &per_cu
->cu
->header
;
25533 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25535 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25536 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25537 rcuh_kind::COMPILE
);
25542 /* Return the address size given in the compilation unit header for CU. */
25545 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25547 struct comp_unit_head cu_header_local
;
25548 const struct comp_unit_head
*cu_headerp
;
25550 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25552 return cu_headerp
->addr_size
;
25555 /* Return the offset size given in the compilation unit header for CU. */
25558 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25560 struct comp_unit_head cu_header_local
;
25561 const struct comp_unit_head
*cu_headerp
;
25563 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25565 return cu_headerp
->offset_size
;
25568 /* See its dwarf2loc.h declaration. */
25571 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25573 struct comp_unit_head cu_header_local
;
25574 const struct comp_unit_head
*cu_headerp
;
25576 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25578 if (cu_headerp
->version
== 2)
25579 return cu_headerp
->addr_size
;
25581 return cu_headerp
->offset_size
;
25584 /* Return the text offset of the CU. The returned offset comes from
25585 this CU's objfile. If this objfile came from a separate debuginfo
25586 file, then the offset may be different from the corresponding
25587 offset in the parent objfile. */
25590 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25592 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25594 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25597 /* Return a type that is a generic pointer type, the size of which matches
25598 the address size given in the compilation unit header for PER_CU. */
25599 static struct type
*
25600 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25602 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25603 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25604 struct type
*addr_type
= lookup_pointer_type (void_type
);
25605 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25607 if (TYPE_LENGTH (addr_type
) == addr_size
)
25611 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25615 /* Return DWARF version number of PER_CU. */
25618 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25620 return per_cu
->dwarf_version
;
25623 /* Locate the .debug_info compilation unit from CU's objfile which contains
25624 the DIE at OFFSET. Raises an error on failure. */
25626 static struct dwarf2_per_cu_data
*
25627 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25628 unsigned int offset_in_dwz
,
25629 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25631 struct dwarf2_per_cu_data
*this_cu
;
25635 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25638 struct dwarf2_per_cu_data
*mid_cu
;
25639 int mid
= low
+ (high
- low
) / 2;
25641 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25642 if (mid_cu
->is_dwz
> offset_in_dwz
25643 || (mid_cu
->is_dwz
== offset_in_dwz
25644 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25649 gdb_assert (low
== high
);
25650 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25651 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25653 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25654 error (_("Dwarf Error: could not find partial DIE containing "
25655 "offset %s [in module %s]"),
25656 sect_offset_str (sect_off
),
25657 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25659 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25661 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25665 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25666 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25667 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25668 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25673 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25675 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25676 : per_cu (per_cu_
),
25678 has_loclist (false),
25679 checked_producer (false),
25680 producer_is_gxx_lt_4_6 (false),
25681 producer_is_gcc_lt_4_3 (false),
25682 producer_is_icc (false),
25683 producer_is_icc_lt_14 (false),
25684 producer_is_codewarrior (false),
25685 processing_has_namespace_info (false)
25690 /* Destroy a dwarf2_cu. */
25692 dwarf2_cu::~dwarf2_cu ()
25697 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25700 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25701 enum language pretend_language
)
25703 struct attribute
*attr
;
25705 /* Set the language we're debugging. */
25706 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25707 if (attr
!= nullptr)
25708 set_cu_language (DW_UNSND (attr
), cu
);
25711 cu
->language
= pretend_language
;
25712 cu
->language_defn
= language_def (cu
->language
);
25715 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25718 /* Increase the age counter on each cached compilation unit, and free
25719 any that are too old. */
25722 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25724 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25726 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25727 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25728 while (per_cu
!= NULL
)
25730 per_cu
->cu
->last_used
++;
25731 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25732 dwarf2_mark (per_cu
->cu
);
25733 per_cu
= per_cu
->cu
->read_in_chain
;
25736 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25737 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25738 while (per_cu
!= NULL
)
25740 struct dwarf2_per_cu_data
*next_cu
;
25742 next_cu
= per_cu
->cu
->read_in_chain
;
25744 if (!per_cu
->cu
->mark
)
25747 *last_chain
= next_cu
;
25750 last_chain
= &per_cu
->cu
->read_in_chain
;
25756 /* Remove a single compilation unit from the cache. */
25759 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25761 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25762 struct dwarf2_per_objfile
*dwarf2_per_objfile
25763 = target_per_cu
->dwarf2_per_objfile
;
25765 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25766 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25767 while (per_cu
!= NULL
)
25769 struct dwarf2_per_cu_data
*next_cu
;
25771 next_cu
= per_cu
->cu
->read_in_chain
;
25773 if (per_cu
== target_per_cu
)
25777 *last_chain
= next_cu
;
25781 last_chain
= &per_cu
->cu
->read_in_chain
;
25787 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25788 We store these in a hash table separate from the DIEs, and preserve them
25789 when the DIEs are flushed out of cache.
25791 The CU "per_cu" pointer is needed because offset alone is not enough to
25792 uniquely identify the type. A file may have multiple .debug_types sections,
25793 or the type may come from a DWO file. Furthermore, while it's more logical
25794 to use per_cu->section+offset, with Fission the section with the data is in
25795 the DWO file but we don't know that section at the point we need it.
25796 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25797 because we can enter the lookup routine, get_die_type_at_offset, from
25798 outside this file, and thus won't necessarily have PER_CU->cu.
25799 Fortunately, PER_CU is stable for the life of the objfile. */
25801 struct dwarf2_per_cu_offset_and_type
25803 const struct dwarf2_per_cu_data
*per_cu
;
25804 sect_offset sect_off
;
25808 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25811 per_cu_offset_and_type_hash (const void *item
)
25813 const struct dwarf2_per_cu_offset_and_type
*ofs
25814 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25816 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25819 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25822 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25824 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25825 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25826 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25827 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25829 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25830 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25833 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25834 table if necessary. For convenience, return TYPE.
25836 The DIEs reading must have careful ordering to:
25837 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25838 reading current DIE.
25839 * Not trying to dereference contents of still incompletely read in types
25840 while reading in other DIEs.
25841 * Enable referencing still incompletely read in types just by a pointer to
25842 the type without accessing its fields.
25844 Therefore caller should follow these rules:
25845 * Try to fetch any prerequisite types we may need to build this DIE type
25846 before building the type and calling set_die_type.
25847 * After building type call set_die_type for current DIE as soon as
25848 possible before fetching more types to complete the current type.
25849 * Make the type as complete as possible before fetching more types. */
25851 static struct type
*
25852 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25854 struct dwarf2_per_objfile
*dwarf2_per_objfile
25855 = cu
->per_cu
->dwarf2_per_objfile
;
25856 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25857 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25858 struct attribute
*attr
;
25859 struct dynamic_prop prop
;
25861 /* For Ada types, make sure that the gnat-specific data is always
25862 initialized (if not already set). There are a few types where
25863 we should not be doing so, because the type-specific area is
25864 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25865 where the type-specific area is used to store the floatformat).
25866 But this is not a problem, because the gnat-specific information
25867 is actually not needed for these types. */
25868 if (need_gnat_info (cu
)
25869 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25870 && TYPE_CODE (type
) != TYPE_CODE_FLT
25871 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25872 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25873 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25874 && !HAVE_GNAT_AUX_INFO (type
))
25875 INIT_GNAT_SPECIFIC (type
);
25877 /* Read DW_AT_allocated and set in type. */
25878 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25879 if (attr_form_is_block (attr
))
25881 struct type
*prop_type
25882 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25883 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25884 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25886 else if (attr
!= NULL
)
25888 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25889 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25890 sect_offset_str (die
->sect_off
));
25893 /* Read DW_AT_associated and set in type. */
25894 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25895 if (attr_form_is_block (attr
))
25897 struct type
*prop_type
25898 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25899 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25900 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25902 else if (attr
!= NULL
)
25904 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25905 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25906 sect_offset_str (die
->sect_off
));
25909 /* Read DW_AT_data_location and set in type. */
25910 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25911 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25912 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25913 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25915 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25917 dwarf2_per_objfile
->die_type_hash
=
25918 htab_create_alloc_ex (127,
25919 per_cu_offset_and_type_hash
,
25920 per_cu_offset_and_type_eq
,
25922 &objfile
->objfile_obstack
,
25923 hashtab_obstack_allocate
,
25924 dummy_obstack_deallocate
);
25927 ofs
.per_cu
= cu
->per_cu
;
25928 ofs
.sect_off
= die
->sect_off
;
25930 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25931 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25933 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25934 sect_offset_str (die
->sect_off
));
25935 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25936 struct dwarf2_per_cu_offset_and_type
);
25941 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25942 or return NULL if the die does not have a saved type. */
25944 static struct type
*
25945 get_die_type_at_offset (sect_offset sect_off
,
25946 struct dwarf2_per_cu_data
*per_cu
)
25948 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25949 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25951 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25954 ofs
.per_cu
= per_cu
;
25955 ofs
.sect_off
= sect_off
;
25956 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25957 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25964 /* Look up the type for DIE in CU in die_type_hash,
25965 or return NULL if DIE does not have a saved type. */
25967 static struct type
*
25968 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25970 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25973 /* Add a dependence relationship from CU to REF_PER_CU. */
25976 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25977 struct dwarf2_per_cu_data
*ref_per_cu
)
25981 if (cu
->dependencies
== NULL
)
25983 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25984 NULL
, &cu
->comp_unit_obstack
,
25985 hashtab_obstack_allocate
,
25986 dummy_obstack_deallocate
);
25988 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25990 *slot
= ref_per_cu
;
25993 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25994 Set the mark field in every compilation unit in the
25995 cache that we must keep because we are keeping CU. */
25998 dwarf2_mark_helper (void **slot
, void *data
)
26000 struct dwarf2_per_cu_data
*per_cu
;
26002 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
26004 /* cu->dependencies references may not yet have been ever read if QUIT aborts
26005 reading of the chain. As such dependencies remain valid it is not much
26006 useful to track and undo them during QUIT cleanups. */
26007 if (per_cu
->cu
== NULL
)
26010 if (per_cu
->cu
->mark
)
26012 per_cu
->cu
->mark
= true;
26014 if (per_cu
->cu
->dependencies
!= NULL
)
26015 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26020 /* Set the mark field in CU and in every other compilation unit in the
26021 cache that we must keep because we are keeping CU. */
26024 dwarf2_mark (struct dwarf2_cu
*cu
)
26029 if (cu
->dependencies
!= NULL
)
26030 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26034 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
26038 per_cu
->cu
->mark
= false;
26039 per_cu
= per_cu
->cu
->read_in_chain
;
26043 /* Trivial hash function for partial_die_info: the hash value of a DIE
26044 is its offset in .debug_info for this objfile. */
26047 partial_die_hash (const void *item
)
26049 const struct partial_die_info
*part_die
26050 = (const struct partial_die_info
*) item
;
26052 return to_underlying (part_die
->sect_off
);
26055 /* Trivial comparison function for partial_die_info structures: two DIEs
26056 are equal if they have the same offset. */
26059 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
26061 const struct partial_die_info
*part_die_lhs
26062 = (const struct partial_die_info
*) item_lhs
;
26063 const struct partial_die_info
*part_die_rhs
26064 = (const struct partial_die_info
*) item_rhs
;
26066 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
26069 struct cmd_list_element
*set_dwarf_cmdlist
;
26070 struct cmd_list_element
*show_dwarf_cmdlist
;
26073 set_dwarf_cmd (const char *args
, int from_tty
)
26075 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
26080 show_dwarf_cmd (const char *args
, int from_tty
)
26082 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
26085 bool dwarf_always_disassemble
;
26088 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
26089 struct cmd_list_element
*c
, const char *value
)
26091 fprintf_filtered (file
,
26092 _("Whether to always disassemble "
26093 "DWARF expressions is %s.\n"),
26098 show_check_physname (struct ui_file
*file
, int from_tty
,
26099 struct cmd_list_element
*c
, const char *value
)
26101 fprintf_filtered (file
,
26102 _("Whether to check \"physname\" is %s.\n"),
26107 _initialize_dwarf2_read (void)
26109 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26110 Set DWARF specific variables.\n\
26111 Configure DWARF variables such as the cache size."),
26112 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26113 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26115 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26116 Show DWARF specific variables.\n\
26117 Show DWARF variables such as the cache size."),
26118 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26119 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26121 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26122 &dwarf_max_cache_age
, _("\
26123 Set the upper bound on the age of cached DWARF compilation units."), _("\
26124 Show the upper bound on the age of cached DWARF compilation units."), _("\
26125 A higher limit means that cached compilation units will be stored\n\
26126 in memory longer, and more total memory will be used. Zero disables\n\
26127 caching, which can slow down startup."),
26129 show_dwarf_max_cache_age
,
26130 &set_dwarf_cmdlist
,
26131 &show_dwarf_cmdlist
);
26133 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26134 &dwarf_always_disassemble
, _("\
26135 Set whether `info address' always disassembles DWARF expressions."), _("\
26136 Show whether `info address' always disassembles DWARF expressions."), _("\
26137 When enabled, DWARF expressions are always printed in an assembly-like\n\
26138 syntax. When disabled, expressions will be printed in a more\n\
26139 conversational style, when possible."),
26141 show_dwarf_always_disassemble
,
26142 &set_dwarf_cmdlist
,
26143 &show_dwarf_cmdlist
);
26145 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26146 Set debugging of the DWARF reader."), _("\
26147 Show debugging of the DWARF reader."), _("\
26148 When enabled (non-zero), debugging messages are printed during DWARF\n\
26149 reading and symtab expansion. A value of 1 (one) provides basic\n\
26150 information. A value greater than 1 provides more verbose information."),
26153 &setdebuglist
, &showdebuglist
);
26155 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26156 Set debugging of the DWARF DIE reader."), _("\
26157 Show debugging of the DWARF DIE reader."), _("\
26158 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26159 The value is the maximum depth to print."),
26162 &setdebuglist
, &showdebuglist
);
26164 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26165 Set debugging of the dwarf line reader."), _("\
26166 Show debugging of the dwarf line reader."), _("\
26167 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26168 A value of 1 (one) provides basic information.\n\
26169 A value greater than 1 provides more verbose information."),
26172 &setdebuglist
, &showdebuglist
);
26174 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26175 Set cross-checking of \"physname\" code against demangler."), _("\
26176 Show cross-checking of \"physname\" code against demangler."), _("\
26177 When enabled, GDB's internal \"physname\" code is checked against\n\
26179 NULL
, show_check_physname
,
26180 &setdebuglist
, &showdebuglist
);
26182 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26183 no_class
, &use_deprecated_index_sections
, _("\
26184 Set whether to use deprecated gdb_index sections."), _("\
26185 Show whether to use deprecated gdb_index sections."), _("\
26186 When enabled, deprecated .gdb_index sections are used anyway.\n\
26187 Normally they are ignored either because of a missing feature or\n\
26188 performance issue.\n\
26189 Warning: This option must be enabled before gdb reads the file."),
26192 &setlist
, &showlist
);
26194 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26195 &dwarf2_locexpr_funcs
);
26196 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26197 &dwarf2_loclist_funcs
);
26199 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26200 &dwarf2_block_frame_base_locexpr_funcs
);
26201 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26202 &dwarf2_block_frame_base_loclist_funcs
);
26205 selftests::register_test ("dw2_expand_symtabs_matching",
26206 selftests::dw2_expand_symtabs_matching::run_test
);