1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
48 #include "gdb-demangle.h"
49 #include "filenames.h" /* for DOSish file names */
52 #include "complaints.h"
53 #include "dwarf2/expr.h"
54 #include "dwarf2/loc.h"
55 #include "cp-support.h"
61 #include "typeprint.h"
66 #include "gdbcore.h" /* for gnutarget */
67 #include "gdb/gdb-index.h"
72 #include "namespace.h"
73 #include "gdbsupport/function-view.h"
74 #include "gdbsupport/gdb_optional.h"
75 #include "gdbsupport/underlying.h"
76 #include "gdbsupport/hash_enum.h"
77 #include "filename-seen-cache.h"
81 #include <unordered_map>
82 #include "gdbsupport/selftest.h"
83 #include "rust-lang.h"
84 #include "gdbsupport/pathstuff.h"
86 /* When == 1, print basic high level tracing messages.
87 When > 1, be more verbose.
88 This is in contrast to the low level DIE reading of dwarf_die_debug. */
89 static unsigned int dwarf_read_debug
= 0;
91 /* When non-zero, dump DIEs after they are read in. */
92 static unsigned int dwarf_die_debug
= 0;
94 /* When non-zero, dump line number entries as they are read in. */
95 unsigned int dwarf_line_debug
= 0;
97 /* When true, cross-check physname against demangler. */
98 static bool check_physname
= false;
100 /* When true, do not reject deprecated .gdb_index sections. */
101 static bool use_deprecated_index_sections
= false;
103 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
105 /* The "aclass" indices for various kinds of computed DWARF symbols. */
107 static int dwarf2_locexpr_index
;
108 static int dwarf2_loclist_index
;
109 static int dwarf2_locexpr_block_index
;
110 static int dwarf2_loclist_block_index
;
112 /* An index into a (C++) symbol name component in a symbol name as
113 recorded in the mapped_index's symbol table. For each C++ symbol
114 in the symbol table, we record one entry for the start of each
115 component in the symbol in a table of name components, and then
116 sort the table, in order to be able to binary search symbol names,
117 ignoring leading namespaces, both completion and regular look up.
118 For example, for symbol "A::B::C", we'll have an entry that points
119 to "A::B::C", another that points to "B::C", and another for "C".
120 Note that function symbols in GDB index have no parameter
121 information, just the function/method names. You can convert a
122 name_component to a "const char *" using the
123 'mapped_index::symbol_name_at(offset_type)' method. */
125 struct name_component
127 /* Offset in the symbol name where the component starts. Stored as
128 a (32-bit) offset instead of a pointer to save memory and improve
129 locality on 64-bit architectures. */
130 offset_type name_offset
;
132 /* The symbol's index in the symbol and constant pool tables of a
137 /* Base class containing bits shared by both .gdb_index and
138 .debug_name indexes. */
140 struct mapped_index_base
142 mapped_index_base () = default;
143 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
145 /* The name_component table (a sorted vector). See name_component's
146 description above. */
147 std::vector
<name_component
> name_components
;
149 /* How NAME_COMPONENTS is sorted. */
150 enum case_sensitivity name_components_casing
;
152 /* Return the number of names in the symbol table. */
153 virtual size_t symbol_name_count () const = 0;
155 /* Get the name of the symbol at IDX in the symbol table. */
156 virtual const char *symbol_name_at (offset_type idx
) const = 0;
158 /* Return whether the name at IDX in the symbol table should be
160 virtual bool symbol_name_slot_invalid (offset_type idx
) const
165 /* Build the symbol name component sorted vector, if we haven't
167 void build_name_components ();
169 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
170 possible matches for LN_NO_PARAMS in the name component
172 std::pair
<std::vector
<name_component
>::const_iterator
,
173 std::vector
<name_component
>::const_iterator
>
174 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
175 enum language lang
) const;
177 /* Prevent deleting/destroying via a base class pointer. */
179 ~mapped_index_base() = default;
182 /* A description of the mapped index. The file format is described in
183 a comment by the code that writes the index. */
184 struct mapped_index final
: public mapped_index_base
186 /* A slot/bucket in the symbol table hash. */
187 struct symbol_table_slot
189 const offset_type name
;
190 const offset_type vec
;
193 /* Index data format version. */
196 /* The address table data. */
197 gdb::array_view
<const gdb_byte
> address_table
;
199 /* The symbol table, implemented as a hash table. */
200 gdb::array_view
<symbol_table_slot
> symbol_table
;
202 /* A pointer to the constant pool. */
203 const char *constant_pool
= nullptr;
205 bool symbol_name_slot_invalid (offset_type idx
) const override
207 const auto &bucket
= this->symbol_table
[idx
];
208 return bucket
.name
== 0 && bucket
.vec
== 0;
211 /* Convenience method to get at the name of the symbol at IDX in the
213 const char *symbol_name_at (offset_type idx
) const override
214 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
216 size_t symbol_name_count () const override
217 { return this->symbol_table
.size (); }
220 /* A description of the mapped .debug_names.
221 Uninitialized map has CU_COUNT 0. */
222 struct mapped_debug_names final
: public mapped_index_base
224 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
225 : dwarf2_per_objfile (dwarf2_per_objfile_
)
228 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
229 bfd_endian dwarf5_byte_order
;
230 bool dwarf5_is_dwarf64
;
231 bool augmentation_is_gdb
;
233 uint32_t cu_count
= 0;
234 uint32_t tu_count
, bucket_count
, name_count
;
235 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
236 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
237 const gdb_byte
*name_table_string_offs_reordered
;
238 const gdb_byte
*name_table_entry_offs_reordered
;
239 const gdb_byte
*entry_pool
;
246 /* Attribute name DW_IDX_*. */
249 /* Attribute form DW_FORM_*. */
252 /* Value if FORM is DW_FORM_implicit_const. */
253 LONGEST implicit_const
;
255 std::vector
<attr
> attr_vec
;
258 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
260 const char *namei_to_name (uint32_t namei
) const;
262 /* Implementation of the mapped_index_base virtual interface, for
263 the name_components cache. */
265 const char *symbol_name_at (offset_type idx
) const override
266 { return namei_to_name (idx
); }
268 size_t symbol_name_count () const override
269 { return this->name_count
; }
272 /* See dwarf2read.h. */
275 get_dwarf2_per_objfile (struct objfile
*objfile
)
277 return dwarf2_objfile_data_key
.get (objfile
);
280 /* Default names of the debugging sections. */
282 /* Note that if the debugging section has been compressed, it might
283 have a name like .zdebug_info. */
285 static const struct dwarf2_debug_sections dwarf2_elf_names
=
287 { ".debug_info", ".zdebug_info" },
288 { ".debug_abbrev", ".zdebug_abbrev" },
289 { ".debug_line", ".zdebug_line" },
290 { ".debug_loc", ".zdebug_loc" },
291 { ".debug_loclists", ".zdebug_loclists" },
292 { ".debug_macinfo", ".zdebug_macinfo" },
293 { ".debug_macro", ".zdebug_macro" },
294 { ".debug_str", ".zdebug_str" },
295 { ".debug_str_offsets", ".zdebug_str_offsets" },
296 { ".debug_line_str", ".zdebug_line_str" },
297 { ".debug_ranges", ".zdebug_ranges" },
298 { ".debug_rnglists", ".zdebug_rnglists" },
299 { ".debug_types", ".zdebug_types" },
300 { ".debug_addr", ".zdebug_addr" },
301 { ".debug_frame", ".zdebug_frame" },
302 { ".eh_frame", NULL
},
303 { ".gdb_index", ".zgdb_index" },
304 { ".debug_names", ".zdebug_names" },
305 { ".debug_aranges", ".zdebug_aranges" },
309 /* List of DWO/DWP sections. */
311 static const struct dwop_section_names
313 struct dwarf2_section_names abbrev_dwo
;
314 struct dwarf2_section_names info_dwo
;
315 struct dwarf2_section_names line_dwo
;
316 struct dwarf2_section_names loc_dwo
;
317 struct dwarf2_section_names loclists_dwo
;
318 struct dwarf2_section_names macinfo_dwo
;
319 struct dwarf2_section_names macro_dwo
;
320 struct dwarf2_section_names str_dwo
;
321 struct dwarf2_section_names str_offsets_dwo
;
322 struct dwarf2_section_names types_dwo
;
323 struct dwarf2_section_names cu_index
;
324 struct dwarf2_section_names tu_index
;
328 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
329 { ".debug_info.dwo", ".zdebug_info.dwo" },
330 { ".debug_line.dwo", ".zdebug_line.dwo" },
331 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
332 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
333 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
334 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
335 { ".debug_str.dwo", ".zdebug_str.dwo" },
336 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
337 { ".debug_types.dwo", ".zdebug_types.dwo" },
338 { ".debug_cu_index", ".zdebug_cu_index" },
339 { ".debug_tu_index", ".zdebug_tu_index" },
342 /* local data types */
344 /* Type used for delaying computation of method physnames.
345 See comments for compute_delayed_physnames. */
346 struct delayed_method_info
348 /* The type to which the method is attached, i.e., its parent class. */
351 /* The index of the method in the type's function fieldlists. */
354 /* The index of the method in the fieldlist. */
357 /* The name of the DIE. */
360 /* The DIE associated with this method. */
361 struct die_info
*die
;
364 /* Internal state when decoding a particular compilation unit. */
367 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
370 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
372 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
373 Create the set of symtabs used by this TU, or if this TU is sharing
374 symtabs with another TU and the symtabs have already been created
375 then restore those symtabs in the line header.
376 We don't need the pc/line-number mapping for type units. */
377 void setup_type_unit_groups (struct die_info
*die
);
379 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
380 buildsym_compunit constructor. */
381 struct compunit_symtab
*start_symtab (const char *name
,
382 const char *comp_dir
,
385 /* Reset the builder. */
386 void reset_builder () { m_builder
.reset (); }
388 /* The header of the compilation unit. */
389 struct comp_unit_head header
{};
391 /* Base address of this compilation unit. */
392 CORE_ADDR base_address
= 0;
394 /* Non-zero if base_address has been set. */
397 /* The language we are debugging. */
398 enum language language
= language_unknown
;
399 const struct language_defn
*language_defn
= nullptr;
401 const char *producer
= nullptr;
404 /* The symtab builder for this CU. This is only non-NULL when full
405 symbols are being read. */
406 std::unique_ptr
<buildsym_compunit
> m_builder
;
409 /* The generic symbol table building routines have separate lists for
410 file scope symbols and all all other scopes (local scopes). So
411 we need to select the right one to pass to add_symbol_to_list().
412 We do it by keeping a pointer to the correct list in list_in_scope.
414 FIXME: The original dwarf code just treated the file scope as the
415 first local scope, and all other local scopes as nested local
416 scopes, and worked fine. Check to see if we really need to
417 distinguish these in buildsym.c. */
418 struct pending
**list_in_scope
= nullptr;
420 /* Hash table holding all the loaded partial DIEs
421 with partial_die->offset.SECT_OFF as hash. */
422 htab_t partial_dies
= nullptr;
424 /* Storage for things with the same lifetime as this read-in compilation
425 unit, including partial DIEs. */
426 auto_obstack comp_unit_obstack
;
428 /* When multiple dwarf2_cu structures are living in memory, this field
429 chains them all together, so that they can be released efficiently.
430 We will probably also want a generation counter so that most-recently-used
431 compilation units are cached... */
432 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
434 /* Backlink to our per_cu entry. */
435 struct dwarf2_per_cu_data
*per_cu
;
437 /* How many compilation units ago was this CU last referenced? */
440 /* A hash table of DIE cu_offset for following references with
441 die_info->offset.sect_off as hash. */
442 htab_t die_hash
= nullptr;
444 /* Full DIEs if read in. */
445 struct die_info
*dies
= nullptr;
447 /* A set of pointers to dwarf2_per_cu_data objects for compilation
448 units referenced by this one. Only set during full symbol processing;
449 partial symbol tables do not have dependencies. */
450 htab_t dependencies
= nullptr;
452 /* Header data from the line table, during full symbol processing. */
453 struct line_header
*line_header
= nullptr;
454 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
455 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
456 this is the DW_TAG_compile_unit die for this CU. We'll hold on
457 to the line header as long as this DIE is being processed. See
458 process_die_scope. */
459 die_info
*line_header_die_owner
= nullptr;
461 /* A list of methods which need to have physnames computed
462 after all type information has been read. */
463 std::vector
<delayed_method_info
> method_list
;
465 /* To be copied to symtab->call_site_htab. */
466 htab_t call_site_htab
= nullptr;
468 /* Non-NULL if this CU came from a DWO file.
469 There is an invariant here that is important to remember:
470 Except for attributes copied from the top level DIE in the "main"
471 (or "stub") file in preparation for reading the DWO file
472 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
473 Either there isn't a DWO file (in which case this is NULL and the point
474 is moot), or there is and either we're not going to read it (in which
475 case this is NULL) or there is and we are reading it (in which case this
477 struct dwo_unit
*dwo_unit
= nullptr;
479 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
480 Note this value comes from the Fission stub CU/TU's DIE. */
481 gdb::optional
<ULONGEST
> addr_base
;
483 /* The DW_AT_rnglists_base attribute if present.
484 Note this value comes from the Fission stub CU/TU's DIE.
485 Also note that the value is zero in the non-DWO case so this value can
486 be used without needing to know whether DWO files are in use or not.
487 N.B. This does not apply to DW_AT_ranges appearing in
488 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
489 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
490 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
491 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
492 ULONGEST ranges_base
= 0;
494 /* When reading debug info generated by older versions of rustc, we
495 have to rewrite some union types to be struct types with a
496 variant part. This rewriting must be done after the CU is fully
497 read in, because otherwise at the point of rewriting some struct
498 type might not have been fully processed. So, we keep a list of
499 all such types here and process them after expansion. */
500 std::vector
<struct type
*> rust_unions
;
502 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
503 files, the value is implicitly zero. For DWARF 5 version DWO files, the
504 value is often implicit and is the size of the header of
505 .debug_str_offsets section (8 or 4, depending on the address size). */
506 gdb::optional
<ULONGEST
> str_offsets_base
;
508 /* Mark used when releasing cached dies. */
511 /* This CU references .debug_loc. See the symtab->locations_valid field.
512 This test is imperfect as there may exist optimized debug code not using
513 any location list and still facing inlining issues if handled as
514 unoptimized code. For a future better test see GCC PR other/32998. */
515 bool has_loclist
: 1;
517 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
518 if all the producer_is_* fields are valid. This information is cached
519 because profiling CU expansion showed excessive time spent in
520 producer_is_gxx_lt_4_6. */
521 bool checked_producer
: 1;
522 bool producer_is_gxx_lt_4_6
: 1;
523 bool producer_is_gcc_lt_4_3
: 1;
524 bool producer_is_icc
: 1;
525 bool producer_is_icc_lt_14
: 1;
526 bool producer_is_codewarrior
: 1;
528 /* When true, the file that we're processing is known to have
529 debugging info for C++ namespaces. GCC 3.3.x did not produce
530 this information, but later versions do. */
532 bool processing_has_namespace_info
: 1;
534 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
536 /* If this CU was inherited by another CU (via specification,
537 abstract_origin, etc), this is the ancestor CU. */
540 /* Get the buildsym_compunit for this CU. */
541 buildsym_compunit
*get_builder ()
543 /* If this CU has a builder associated with it, use that. */
544 if (m_builder
!= nullptr)
545 return m_builder
.get ();
547 /* Otherwise, search ancestors for a valid builder. */
548 if (ancestor
!= nullptr)
549 return ancestor
->get_builder ();
555 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
556 This includes type_unit_group and quick_file_names. */
558 struct stmt_list_hash
560 /* The DWO unit this table is from or NULL if there is none. */
561 struct dwo_unit
*dwo_unit
;
563 /* Offset in .debug_line or .debug_line.dwo. */
564 sect_offset line_sect_off
;
567 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
568 an object of this type. */
570 struct type_unit_group
572 /* dwarf2read.c's main "handle" on a TU symtab.
573 To simplify things we create an artificial CU that "includes" all the
574 type units using this stmt_list so that the rest of the code still has
575 a "per_cu" handle on the symtab.
576 This PER_CU is recognized by having no section. */
577 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
578 struct dwarf2_per_cu_data per_cu
;
580 /* The TUs that share this DW_AT_stmt_list entry.
581 This is added to while parsing type units to build partial symtabs,
582 and is deleted afterwards and not used again. */
583 std::vector
<signatured_type
*> *tus
;
585 /* The compunit symtab.
586 Type units in a group needn't all be defined in the same source file,
587 so we create an essentially anonymous symtab as the compunit symtab. */
588 struct compunit_symtab
*compunit_symtab
;
590 /* The data used to construct the hash key. */
591 struct stmt_list_hash hash
;
593 /* The number of symtabs from the line header.
594 The value here must match line_header.num_file_names. */
595 unsigned int num_symtabs
;
597 /* The symbol tables for this TU (obtained from the files listed in
599 WARNING: The order of entries here must match the order of entries
600 in the line header. After the first TU using this type_unit_group, the
601 line header for the subsequent TUs is recreated from this. This is done
602 because we need to use the same symtabs for each TU using the same
603 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
604 there's no guarantee the line header doesn't have duplicate entries. */
605 struct symtab
**symtabs
;
608 /* These sections are what may appear in a (real or virtual) DWO file. */
612 struct dwarf2_section_info abbrev
;
613 struct dwarf2_section_info line
;
614 struct dwarf2_section_info loc
;
615 struct dwarf2_section_info loclists
;
616 struct dwarf2_section_info macinfo
;
617 struct dwarf2_section_info macro
;
618 struct dwarf2_section_info str
;
619 struct dwarf2_section_info str_offsets
;
620 /* In the case of a virtual DWO file, these two are unused. */
621 struct dwarf2_section_info info
;
622 std::vector
<dwarf2_section_info
> types
;
625 /* CUs/TUs in DWP/DWO files. */
629 /* Backlink to the containing struct dwo_file. */
630 struct dwo_file
*dwo_file
;
632 /* The "id" that distinguishes this CU/TU.
633 .debug_info calls this "dwo_id", .debug_types calls this "signature".
634 Since signatures came first, we stick with it for consistency. */
637 /* The section this CU/TU lives in, in the DWO file. */
638 struct dwarf2_section_info
*section
;
640 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
641 sect_offset sect_off
;
644 /* For types, offset in the type's DIE of the type defined by this TU. */
645 cu_offset type_offset_in_tu
;
648 /* include/dwarf2.h defines the DWP section codes.
649 It defines a max value but it doesn't define a min value, which we
650 use for error checking, so provide one. */
652 enum dwp_v2_section_ids
657 /* Data for one DWO file.
659 This includes virtual DWO files (a virtual DWO file is a DWO file as it
660 appears in a DWP file). DWP files don't really have DWO files per se -
661 comdat folding of types "loses" the DWO file they came from, and from
662 a high level view DWP files appear to contain a mass of random types.
663 However, to maintain consistency with the non-DWP case we pretend DWP
664 files contain virtual DWO files, and we assign each TU with one virtual
665 DWO file (generally based on the line and abbrev section offsets -
666 a heuristic that seems to work in practice). */
670 dwo_file () = default;
671 DISABLE_COPY_AND_ASSIGN (dwo_file
);
673 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
674 For virtual DWO files the name is constructed from the section offsets
675 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
676 from related CU+TUs. */
677 const char *dwo_name
= nullptr;
679 /* The DW_AT_comp_dir attribute. */
680 const char *comp_dir
= nullptr;
682 /* The bfd, when the file is open. Otherwise this is NULL.
683 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
684 gdb_bfd_ref_ptr dbfd
;
686 /* The sections that make up this DWO file.
687 Remember that for virtual DWO files in DWP V2, these are virtual
688 sections (for lack of a better name). */
689 struct dwo_sections sections
{};
691 /* The CUs in the file.
692 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
693 an extension to handle LLVM's Link Time Optimization output (where
694 multiple source files may be compiled into a single object/dwo pair). */
697 /* Table of TUs in the file.
698 Each element is a struct dwo_unit. */
702 /* These sections are what may appear in a DWP file. */
706 /* These are used by both DWP version 1 and 2. */
707 struct dwarf2_section_info str
;
708 struct dwarf2_section_info cu_index
;
709 struct dwarf2_section_info tu_index
;
711 /* These are only used by DWP version 2 files.
712 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
713 sections are referenced by section number, and are not recorded here.
714 In DWP version 2 there is at most one copy of all these sections, each
715 section being (effectively) comprised of the concatenation of all of the
716 individual sections that exist in the version 1 format.
717 To keep the code simple we treat each of these concatenated pieces as a
718 section itself (a virtual section?). */
719 struct dwarf2_section_info abbrev
;
720 struct dwarf2_section_info info
;
721 struct dwarf2_section_info line
;
722 struct dwarf2_section_info loc
;
723 struct dwarf2_section_info macinfo
;
724 struct dwarf2_section_info macro
;
725 struct dwarf2_section_info str_offsets
;
726 struct dwarf2_section_info types
;
729 /* These sections are what may appear in a virtual DWO file in DWP version 1.
730 A virtual DWO file is a DWO file as it appears in a DWP file. */
732 struct virtual_v1_dwo_sections
734 struct dwarf2_section_info abbrev
;
735 struct dwarf2_section_info line
;
736 struct dwarf2_section_info loc
;
737 struct dwarf2_section_info macinfo
;
738 struct dwarf2_section_info macro
;
739 struct dwarf2_section_info str_offsets
;
740 /* Each DWP hash table entry records one CU or one TU.
741 That is recorded here, and copied to dwo_unit.section. */
742 struct dwarf2_section_info info_or_types
;
745 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
746 In version 2, the sections of the DWO files are concatenated together
747 and stored in one section of that name. Thus each ELF section contains
748 several "virtual" sections. */
750 struct virtual_v2_dwo_sections
752 bfd_size_type abbrev_offset
;
753 bfd_size_type abbrev_size
;
755 bfd_size_type line_offset
;
756 bfd_size_type line_size
;
758 bfd_size_type loc_offset
;
759 bfd_size_type loc_size
;
761 bfd_size_type macinfo_offset
;
762 bfd_size_type macinfo_size
;
764 bfd_size_type macro_offset
;
765 bfd_size_type macro_size
;
767 bfd_size_type str_offsets_offset
;
768 bfd_size_type str_offsets_size
;
770 /* Each DWP hash table entry records one CU or one TU.
771 That is recorded here, and copied to dwo_unit.section. */
772 bfd_size_type info_or_types_offset
;
773 bfd_size_type info_or_types_size
;
776 /* Contents of DWP hash tables. */
778 struct dwp_hash_table
780 uint32_t version
, nr_columns
;
781 uint32_t nr_units
, nr_slots
;
782 const gdb_byte
*hash_table
, *unit_table
;
787 const gdb_byte
*indices
;
791 /* This is indexed by column number and gives the id of the section
793 #define MAX_NR_V2_DWO_SECTIONS \
794 (1 /* .debug_info or .debug_types */ \
795 + 1 /* .debug_abbrev */ \
796 + 1 /* .debug_line */ \
797 + 1 /* .debug_loc */ \
798 + 1 /* .debug_str_offsets */ \
799 + 1 /* .debug_macro or .debug_macinfo */)
800 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
801 const gdb_byte
*offsets
;
802 const gdb_byte
*sizes
;
807 /* Data for one DWP file. */
811 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
813 dbfd (std::move (abfd
))
817 /* Name of the file. */
820 /* File format version. */
824 gdb_bfd_ref_ptr dbfd
;
826 /* Section info for this file. */
827 struct dwp_sections sections
{};
829 /* Table of CUs in the file. */
830 const struct dwp_hash_table
*cus
= nullptr;
832 /* Table of TUs in the file. */
833 const struct dwp_hash_table
*tus
= nullptr;
835 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
839 /* Table to map ELF section numbers to their sections.
840 This is only needed for the DWP V1 file format. */
841 unsigned int num_sections
= 0;
842 asection
**elf_sections
= nullptr;
845 /* Struct used to pass misc. parameters to read_die_and_children, et
846 al. which are used for both .debug_info and .debug_types dies.
847 All parameters here are unchanging for the life of the call. This
848 struct exists to abstract away the constant parameters of die reading. */
850 struct die_reader_specs
852 /* The bfd of die_section. */
855 /* The CU of the DIE we are parsing. */
856 struct dwarf2_cu
*cu
;
858 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
859 struct dwo_file
*dwo_file
;
861 /* The section the die comes from.
862 This is either .debug_info or .debug_types, or the .dwo variants. */
863 struct dwarf2_section_info
*die_section
;
865 /* die_section->buffer. */
866 const gdb_byte
*buffer
;
868 /* The end of the buffer. */
869 const gdb_byte
*buffer_end
;
871 /* The abbreviation table to use when reading the DIEs. */
872 struct abbrev_table
*abbrev_table
;
875 /* A subclass of die_reader_specs that holds storage and has complex
876 constructor and destructor behavior. */
878 class cutu_reader
: public die_reader_specs
882 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
883 struct abbrev_table
*abbrev_table
,
884 int use_existing_cu
, int keep
,
887 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
888 struct dwarf2_cu
*parent_cu
= nullptr,
889 struct dwo_file
*dwo_file
= nullptr);
893 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
895 const gdb_byte
*info_ptr
= nullptr;
896 struct die_info
*comp_unit_die
= nullptr;
897 bool dummy_p
= false;
900 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
901 int use_existing_cu
, int keep
);
903 struct dwarf2_per_cu_data
*m_this_cu
;
905 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
907 /* The ordinary abbreviation table. */
908 abbrev_table_up m_abbrev_table_holder
;
910 /* The DWO abbreviation table. */
911 abbrev_table_up m_dwo_abbrev_table
;
914 /* When we construct a partial symbol table entry we only
915 need this much information. */
916 struct partial_die_info
: public allocate_on_obstack
918 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
920 /* Disable assign but still keep copy ctor, which is needed
921 load_partial_dies. */
922 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
924 /* Adjust the partial die before generating a symbol for it. This
925 function may set the is_external flag or change the DIE's
927 void fixup (struct dwarf2_cu
*cu
);
929 /* Read a minimal amount of information into the minimal die
931 const gdb_byte
*read (const struct die_reader_specs
*reader
,
932 const struct abbrev_info
&abbrev
,
933 const gdb_byte
*info_ptr
);
935 /* Offset of this DIE. */
936 const sect_offset sect_off
;
938 /* DWARF-2 tag for this DIE. */
939 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
941 /* Assorted flags describing the data found in this DIE. */
942 const unsigned int has_children
: 1;
944 unsigned int is_external
: 1;
945 unsigned int is_declaration
: 1;
946 unsigned int has_type
: 1;
947 unsigned int has_specification
: 1;
948 unsigned int has_pc_info
: 1;
949 unsigned int may_be_inlined
: 1;
951 /* This DIE has been marked DW_AT_main_subprogram. */
952 unsigned int main_subprogram
: 1;
954 /* Flag set if the SCOPE field of this structure has been
956 unsigned int scope_set
: 1;
958 /* Flag set if the DIE has a byte_size attribute. */
959 unsigned int has_byte_size
: 1;
961 /* Flag set if the DIE has a DW_AT_const_value attribute. */
962 unsigned int has_const_value
: 1;
964 /* Flag set if any of the DIE's children are template arguments. */
965 unsigned int has_template_arguments
: 1;
967 /* Flag set if fixup has been called on this die. */
968 unsigned int fixup_called
: 1;
970 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
971 unsigned int is_dwz
: 1;
973 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
974 unsigned int spec_is_dwz
: 1;
976 /* The name of this DIE. Normally the value of DW_AT_name, but
977 sometimes a default name for unnamed DIEs. */
978 const char *name
= nullptr;
980 /* The linkage name, if present. */
981 const char *linkage_name
= nullptr;
983 /* The scope to prepend to our children. This is generally
984 allocated on the comp_unit_obstack, so will disappear
985 when this compilation unit leaves the cache. */
986 const char *scope
= nullptr;
988 /* Some data associated with the partial DIE. The tag determines
989 which field is live. */
992 /* The location description associated with this DIE, if any. */
993 struct dwarf_block
*locdesc
;
994 /* The offset of an import, for DW_TAG_imported_unit. */
995 sect_offset sect_off
;
998 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1000 CORE_ADDR highpc
= 0;
1002 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1003 DW_AT_sibling, if any. */
1004 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1005 could return DW_AT_sibling values to its caller load_partial_dies. */
1006 const gdb_byte
*sibling
= nullptr;
1008 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1009 DW_AT_specification (or DW_AT_abstract_origin or
1010 DW_AT_extension). */
1011 sect_offset spec_offset
{};
1013 /* Pointers to this DIE's parent, first child, and next sibling,
1015 struct partial_die_info
*die_parent
= nullptr;
1016 struct partial_die_info
*die_child
= nullptr;
1017 struct partial_die_info
*die_sibling
= nullptr;
1019 friend struct partial_die_info
*
1020 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1023 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1024 partial_die_info (sect_offset sect_off
)
1025 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1029 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1031 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1036 has_specification
= 0;
1039 main_subprogram
= 0;
1042 has_const_value
= 0;
1043 has_template_arguments
= 0;
1050 /* This data structure holds a complete die structure. */
1053 /* DWARF-2 tag for this DIE. */
1054 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1056 /* Number of attributes */
1057 unsigned char num_attrs
;
1059 /* True if we're presently building the full type name for the
1060 type derived from this DIE. */
1061 unsigned char building_fullname
: 1;
1063 /* True if this die is in process. PR 16581. */
1064 unsigned char in_process
: 1;
1066 /* True if this DIE has children. */
1067 unsigned char has_children
: 1;
1070 unsigned int abbrev
;
1072 /* Offset in .debug_info or .debug_types section. */
1073 sect_offset sect_off
;
1075 /* The dies in a compilation unit form an n-ary tree. PARENT
1076 points to this die's parent; CHILD points to the first child of
1077 this node; and all the children of a given node are chained
1078 together via their SIBLING fields. */
1079 struct die_info
*child
; /* Its first child, if any. */
1080 struct die_info
*sibling
; /* Its next sibling, if any. */
1081 struct die_info
*parent
; /* Its parent, if any. */
1083 /* An array of attributes, with NUM_ATTRS elements. There may be
1084 zero, but it's not common and zero-sized arrays are not
1085 sufficiently portable C. */
1086 struct attribute attrs
[1];
1089 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1090 but this would require a corresponding change in unpack_field_as_long
1092 static int bits_per_byte
= 8;
1094 /* When reading a variant or variant part, we track a bit more
1095 information about the field, and store it in an object of this
1098 struct variant_field
1100 /* If we see a DW_TAG_variant, then this will be the discriminant
1102 ULONGEST discriminant_value
;
1103 /* If we see a DW_TAG_variant, then this will be set if this is the
1105 bool default_branch
;
1106 /* While reading a DW_TAG_variant_part, this will be set if this
1107 field is the discriminant. */
1108 bool is_discriminant
;
1113 int accessibility
= 0;
1115 /* Extra information to describe a variant or variant part. */
1116 struct variant_field variant
{};
1117 struct field field
{};
1122 const char *name
= nullptr;
1123 std::vector
<struct fn_field
> fnfields
;
1126 /* The routines that read and process dies for a C struct or C++ class
1127 pass lists of data member fields and lists of member function fields
1128 in an instance of a field_info structure, as defined below. */
1131 /* List of data member and baseclasses fields. */
1132 std::vector
<struct nextfield
> fields
;
1133 std::vector
<struct nextfield
> baseclasses
;
1135 /* Number of fields (including baseclasses). */
1138 /* Set if the accessibility of one of the fields is not public. */
1139 int non_public_fields
= 0;
1141 /* Member function fieldlist array, contains name of possibly overloaded
1142 member function, number of overloaded member functions and a pointer
1143 to the head of the member function field chain. */
1144 std::vector
<struct fnfieldlist
> fnfieldlists
;
1146 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1147 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1148 std::vector
<struct decl_field
> typedef_field_list
;
1150 /* Nested types defined by this class and the number of elements in this
1152 std::vector
<struct decl_field
> nested_types_list
;
1155 /* Loaded secondary compilation units are kept in memory until they
1156 have not been referenced for the processing of this many
1157 compilation units. Set this to zero to disable caching. Cache
1158 sizes of up to at least twenty will improve startup time for
1159 typical inter-CU-reference binaries, at an obvious memory cost. */
1160 static int dwarf_max_cache_age
= 5;
1162 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1163 struct cmd_list_element
*c
, const char *value
)
1165 fprintf_filtered (file
, _("The upper bound on the age of cached "
1166 "DWARF compilation units is %s.\n"),
1170 /* local function prototypes */
1172 static void dwarf2_find_base_address (struct die_info
*die
,
1173 struct dwarf2_cu
*cu
);
1175 static dwarf2_psymtab
*create_partial_symtab
1176 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1178 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1179 const gdb_byte
*info_ptr
,
1180 struct die_info
*type_unit_die
);
1182 static void dwarf2_build_psymtabs_hard
1183 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1185 static void scan_partial_symbols (struct partial_die_info
*,
1186 CORE_ADDR
*, CORE_ADDR
*,
1187 int, struct dwarf2_cu
*);
1189 static void add_partial_symbol (struct partial_die_info
*,
1190 struct dwarf2_cu
*);
1192 static void add_partial_namespace (struct partial_die_info
*pdi
,
1193 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1194 int set_addrmap
, struct dwarf2_cu
*cu
);
1196 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1197 CORE_ADDR
*highpc
, int set_addrmap
,
1198 struct dwarf2_cu
*cu
);
1200 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1201 struct dwarf2_cu
*cu
);
1203 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1204 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1205 int need_pc
, struct dwarf2_cu
*cu
);
1207 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1209 static struct partial_die_info
*load_partial_dies
1210 (const struct die_reader_specs
*, const gdb_byte
*, int);
1212 /* A pair of partial_die_info and compilation unit. */
1213 struct cu_partial_die_info
1215 /* The compilation unit of the partial_die_info. */
1216 struct dwarf2_cu
*cu
;
1217 /* A partial_die_info. */
1218 struct partial_die_info
*pdi
;
1220 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1226 cu_partial_die_info () = delete;
1229 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1230 struct dwarf2_cu
*);
1232 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1233 struct attribute
*, struct attr_abbrev
*,
1234 const gdb_byte
*, bool *need_reprocess
);
1236 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1237 struct attribute
*attr
);
1239 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1241 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1244 static LONGEST read_checked_initial_length_and_offset
1245 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1246 unsigned int *, unsigned int *);
1248 static sect_offset read_abbrev_offset
1249 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1250 struct dwarf2_section_info
*, sect_offset
);
1252 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1254 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1256 static const char *read_indirect_string
1257 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1258 const struct comp_unit_head
*, unsigned int *);
1260 static const char *read_indirect_line_string
1261 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1262 const struct comp_unit_head
*, unsigned int *);
1264 static const char *read_indirect_string_at_offset
1265 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1266 LONGEST str_offset
);
1268 static const char *read_indirect_string_from_dwz
1269 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1271 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1275 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1276 ULONGEST str_index
);
1278 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1279 ULONGEST str_index
);
1281 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1283 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1284 struct dwarf2_cu
*);
1286 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1289 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1290 struct dwarf2_cu
*cu
);
1292 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1294 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1295 struct dwarf2_cu
*cu
);
1297 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1299 static struct die_info
*die_specification (struct die_info
*die
,
1300 struct dwarf2_cu
**);
1302 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1303 struct dwarf2_cu
*cu
);
1305 static void dwarf_decode_lines (struct line_header
*, const char *,
1306 struct dwarf2_cu
*, dwarf2_psymtab
*,
1307 CORE_ADDR
, int decode_mapping
);
1309 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1312 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1313 struct dwarf2_cu
*, struct symbol
* = NULL
);
1315 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1316 struct dwarf2_cu
*);
1318 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1321 struct obstack
*obstack
,
1322 struct dwarf2_cu
*cu
, LONGEST
*value
,
1323 const gdb_byte
**bytes
,
1324 struct dwarf2_locexpr_baton
**baton
);
1326 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1328 static int need_gnat_info (struct dwarf2_cu
*);
1330 static struct type
*die_descriptive_type (struct die_info
*,
1331 struct dwarf2_cu
*);
1333 static void set_descriptive_type (struct type
*, struct die_info
*,
1334 struct dwarf2_cu
*);
1336 static struct type
*die_containing_type (struct die_info
*,
1337 struct dwarf2_cu
*);
1339 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1340 struct dwarf2_cu
*);
1342 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1344 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1346 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1348 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1349 const char *suffix
, int physname
,
1350 struct dwarf2_cu
*cu
);
1352 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1354 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1356 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1358 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1360 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1362 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1364 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1365 struct dwarf2_cu
*, dwarf2_psymtab
*);
1367 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1368 values. Keep the items ordered with increasing constraints compliance. */
1371 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1372 PC_BOUNDS_NOT_PRESENT
,
1374 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1375 were present but they do not form a valid range of PC addresses. */
1378 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1381 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1385 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1386 CORE_ADDR
*, CORE_ADDR
*,
1390 static void get_scope_pc_bounds (struct die_info
*,
1391 CORE_ADDR
*, CORE_ADDR
*,
1392 struct dwarf2_cu
*);
1394 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1395 CORE_ADDR
, struct dwarf2_cu
*);
1397 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1398 struct dwarf2_cu
*);
1400 static void dwarf2_attach_fields_to_type (struct field_info
*,
1401 struct type
*, struct dwarf2_cu
*);
1403 static void dwarf2_add_member_fn (struct field_info
*,
1404 struct die_info
*, struct type
*,
1405 struct dwarf2_cu
*);
1407 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1409 struct dwarf2_cu
*);
1411 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1413 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1415 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1417 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1419 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1421 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1423 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1425 static struct type
*read_module_type (struct die_info
*die
,
1426 struct dwarf2_cu
*cu
);
1428 static const char *namespace_name (struct die_info
*die
,
1429 int *is_anonymous
, struct dwarf2_cu
*);
1431 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1433 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1435 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1436 struct dwarf2_cu
*);
1438 static struct die_info
*read_die_and_siblings_1
1439 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1442 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1443 const gdb_byte
*info_ptr
,
1444 const gdb_byte
**new_info_ptr
,
1445 struct die_info
*parent
);
1447 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1448 struct die_info
**, const gdb_byte
*,
1451 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1452 struct die_info
**, const gdb_byte
*);
1454 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1456 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1459 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1461 static const char *dwarf2_full_name (const char *name
,
1462 struct die_info
*die
,
1463 struct dwarf2_cu
*cu
);
1465 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1466 struct dwarf2_cu
*cu
);
1468 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1469 struct dwarf2_cu
**);
1471 static const char *dwarf_tag_name (unsigned int);
1473 static const char *dwarf_attr_name (unsigned int);
1475 static const char *dwarf_form_name (unsigned int);
1477 static const char *dwarf_bool_name (unsigned int);
1479 static const char *dwarf_type_encoding_name (unsigned int);
1481 static struct die_info
*sibling_die (struct die_info
*);
1483 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1485 static void dump_die_for_error (struct die_info
*);
1487 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1490 /*static*/ void dump_die (struct die_info
*, int max_level
);
1492 static void store_in_ref_table (struct die_info
*,
1493 struct dwarf2_cu
*);
1495 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1497 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1499 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1500 const struct attribute
*,
1501 struct dwarf2_cu
**);
1503 static struct die_info
*follow_die_ref (struct die_info
*,
1504 const struct attribute
*,
1505 struct dwarf2_cu
**);
1507 static struct die_info
*follow_die_sig (struct die_info
*,
1508 const struct attribute
*,
1509 struct dwarf2_cu
**);
1511 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1512 struct dwarf2_cu
*);
1514 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1515 const struct attribute
*,
1516 struct dwarf2_cu
*);
1518 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1520 static void read_signatured_type (struct signatured_type
*);
1522 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1523 struct die_info
*die
, struct dwarf2_cu
*cu
,
1524 struct dynamic_prop
*prop
, struct type
*type
);
1526 /* memory allocation interface */
1528 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1530 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1532 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1534 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1535 struct dwarf2_loclist_baton
*baton
,
1536 const struct attribute
*attr
);
1538 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1540 struct dwarf2_cu
*cu
,
1543 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1544 const gdb_byte
*info_ptr
,
1545 struct abbrev_info
*abbrev
);
1547 static hashval_t
partial_die_hash (const void *item
);
1549 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1551 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1552 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1553 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1555 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1556 struct die_info
*comp_unit_die
,
1557 enum language pretend_language
);
1559 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1561 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1563 static struct type
*set_die_type (struct die_info
*, struct type
*,
1564 struct dwarf2_cu
*);
1566 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1568 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1570 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1573 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1576 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1579 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1580 struct dwarf2_per_cu_data
*);
1582 static void dwarf2_mark (struct dwarf2_cu
*);
1584 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1586 static struct type
*get_die_type_at_offset (sect_offset
,
1587 struct dwarf2_per_cu_data
*);
1589 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1591 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1592 enum language pretend_language
);
1594 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1596 /* Class, the destructor of which frees all allocated queue entries. This
1597 will only have work to do if an error was thrown while processing the
1598 dwarf. If no error was thrown then the queue entries should have all
1599 been processed, and freed, as we went along. */
1601 class dwarf2_queue_guard
1604 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1605 : m_per_objfile (per_objfile
)
1609 /* Free any entries remaining on the queue. There should only be
1610 entries left if we hit an error while processing the dwarf. */
1611 ~dwarf2_queue_guard ()
1613 /* Ensure that no memory is allocated by the queue. */
1614 std::queue
<dwarf2_queue_item
> empty
;
1615 std::swap (m_per_objfile
->queue
, empty
);
1618 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1621 dwarf2_per_objfile
*m_per_objfile
;
1624 dwarf2_queue_item::~dwarf2_queue_item ()
1626 /* Anything still marked queued is likely to be in an
1627 inconsistent state, so discard it. */
1630 if (per_cu
->cu
!= NULL
)
1631 free_one_cached_comp_unit (per_cu
);
1636 /* The return type of find_file_and_directory. Note, the enclosed
1637 string pointers are only valid while this object is valid. */
1639 struct file_and_directory
1641 /* The filename. This is never NULL. */
1644 /* The compilation directory. NULL if not known. If we needed to
1645 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1646 points directly to the DW_AT_comp_dir string attribute owned by
1647 the obstack that owns the DIE. */
1648 const char *comp_dir
;
1650 /* If we needed to build a new string for comp_dir, this is what
1651 owns the storage. */
1652 std::string comp_dir_storage
;
1655 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1656 struct dwarf2_cu
*cu
);
1658 static htab_up
allocate_signatured_type_table (struct objfile
*objfile
);
1660 static htab_up
allocate_dwo_unit_table (struct objfile
*objfile
);
1662 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1663 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1664 struct dwp_file
*dwp_file
, const char *comp_dir
,
1665 ULONGEST signature
, int is_debug_types
);
1667 static struct dwp_file
*get_dwp_file
1668 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1670 static struct dwo_unit
*lookup_dwo_comp_unit
1671 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1673 static struct dwo_unit
*lookup_dwo_type_unit
1674 (struct signatured_type
*, const char *, const char *);
1676 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1678 /* A unique pointer to a dwo_file. */
1680 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1682 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1684 static void check_producer (struct dwarf2_cu
*cu
);
1686 static void free_line_header_voidp (void *arg
);
1688 /* Various complaints about symbol reading that don't abort the process. */
1691 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1693 complaint (_("statement list doesn't fit in .debug_line section"));
1697 dwarf2_debug_line_missing_file_complaint (void)
1699 complaint (_(".debug_line section has line data without a file"));
1703 dwarf2_debug_line_missing_end_sequence_complaint (void)
1705 complaint (_(".debug_line section has line "
1706 "program sequence without an end"));
1710 dwarf2_complex_location_expr_complaint (void)
1712 complaint (_("location expression too complex"));
1716 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1719 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1724 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1726 complaint (_("debug info runs off end of %s section"
1728 section
->get_name (),
1729 section
->get_file_name ());
1733 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1735 complaint (_("macro debug info contains a "
1736 "malformed macro definition:\n`%s'"),
1741 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1743 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1747 /* Hash function for line_header_hash. */
1750 line_header_hash (const struct line_header
*ofs
)
1752 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1755 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1758 line_header_hash_voidp (const void *item
)
1760 const struct line_header
*ofs
= (const struct line_header
*) item
;
1762 return line_header_hash (ofs
);
1765 /* Equality function for line_header_hash. */
1768 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1770 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1771 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1773 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1774 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1779 /* See declaration. */
1781 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1782 const dwarf2_debug_sections
*names
,
1784 : objfile (objfile_
),
1785 can_copy (can_copy_
)
1788 names
= &dwarf2_elf_names
;
1790 bfd
*obfd
= objfile
->obfd
;
1792 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1793 locate_sections (obfd
, sec
, *names
);
1796 dwarf2_per_objfile::~dwarf2_per_objfile ()
1798 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1799 free_cached_comp_units ();
1801 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1802 per_cu
->imported_symtabs_free ();
1804 for (signatured_type
*sig_type
: all_type_units
)
1805 sig_type
->per_cu
.imported_symtabs_free ();
1807 /* Everything else should be on the objfile obstack. */
1810 /* See declaration. */
1813 dwarf2_per_objfile::free_cached_comp_units ()
1815 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1816 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1817 while (per_cu
!= NULL
)
1819 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1822 *last_chain
= next_cu
;
1827 /* A helper class that calls free_cached_comp_units on
1830 class free_cached_comp_units
1834 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1835 : m_per_objfile (per_objfile
)
1839 ~free_cached_comp_units ()
1841 m_per_objfile
->free_cached_comp_units ();
1844 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1848 dwarf2_per_objfile
*m_per_objfile
;
1851 /* Try to locate the sections we need for DWARF 2 debugging
1852 information and return true if we have enough to do something.
1853 NAMES points to the dwarf2 section names, or is NULL if the standard
1854 ELF names are used. CAN_COPY is true for formats where symbol
1855 interposition is possible and so symbol values must follow copy
1856 relocation rules. */
1859 dwarf2_has_info (struct objfile
*objfile
,
1860 const struct dwarf2_debug_sections
*names
,
1863 if (objfile
->flags
& OBJF_READNEVER
)
1866 struct dwarf2_per_objfile
*dwarf2_per_objfile
1867 = get_dwarf2_per_objfile (objfile
);
1869 if (dwarf2_per_objfile
== NULL
)
1870 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1874 return (!dwarf2_per_objfile
->info
.is_virtual
1875 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1876 && !dwarf2_per_objfile
->abbrev
.is_virtual
1877 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1880 /* When loading sections, we look either for uncompressed section or for
1881 compressed section names. */
1884 section_is_p (const char *section_name
,
1885 const struct dwarf2_section_names
*names
)
1887 if (names
->normal
!= NULL
1888 && strcmp (section_name
, names
->normal
) == 0)
1890 if (names
->compressed
!= NULL
1891 && strcmp (section_name
, names
->compressed
) == 0)
1896 /* See declaration. */
1899 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1900 const dwarf2_debug_sections
&names
)
1902 flagword aflag
= bfd_section_flags (sectp
);
1904 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1907 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1908 > bfd_get_file_size (abfd
))
1910 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1911 warning (_("Discarding section %s which has a section size (%s"
1912 ") larger than the file size [in module %s]"),
1913 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1914 bfd_get_filename (abfd
));
1916 else if (section_is_p (sectp
->name
, &names
.info
))
1918 this->info
.s
.section
= sectp
;
1919 this->info
.size
= bfd_section_size (sectp
);
1921 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1923 this->abbrev
.s
.section
= sectp
;
1924 this->abbrev
.size
= bfd_section_size (sectp
);
1926 else if (section_is_p (sectp
->name
, &names
.line
))
1928 this->line
.s
.section
= sectp
;
1929 this->line
.size
= bfd_section_size (sectp
);
1931 else if (section_is_p (sectp
->name
, &names
.loc
))
1933 this->loc
.s
.section
= sectp
;
1934 this->loc
.size
= bfd_section_size (sectp
);
1936 else if (section_is_p (sectp
->name
, &names
.loclists
))
1938 this->loclists
.s
.section
= sectp
;
1939 this->loclists
.size
= bfd_section_size (sectp
);
1941 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1943 this->macinfo
.s
.section
= sectp
;
1944 this->macinfo
.size
= bfd_section_size (sectp
);
1946 else if (section_is_p (sectp
->name
, &names
.macro
))
1948 this->macro
.s
.section
= sectp
;
1949 this->macro
.size
= bfd_section_size (sectp
);
1951 else if (section_is_p (sectp
->name
, &names
.str
))
1953 this->str
.s
.section
= sectp
;
1954 this->str
.size
= bfd_section_size (sectp
);
1956 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1958 this->str_offsets
.s
.section
= sectp
;
1959 this->str_offsets
.size
= bfd_section_size (sectp
);
1961 else if (section_is_p (sectp
->name
, &names
.line_str
))
1963 this->line_str
.s
.section
= sectp
;
1964 this->line_str
.size
= bfd_section_size (sectp
);
1966 else if (section_is_p (sectp
->name
, &names
.addr
))
1968 this->addr
.s
.section
= sectp
;
1969 this->addr
.size
= bfd_section_size (sectp
);
1971 else if (section_is_p (sectp
->name
, &names
.frame
))
1973 this->frame
.s
.section
= sectp
;
1974 this->frame
.size
= bfd_section_size (sectp
);
1976 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1978 this->eh_frame
.s
.section
= sectp
;
1979 this->eh_frame
.size
= bfd_section_size (sectp
);
1981 else if (section_is_p (sectp
->name
, &names
.ranges
))
1983 this->ranges
.s
.section
= sectp
;
1984 this->ranges
.size
= bfd_section_size (sectp
);
1986 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1988 this->rnglists
.s
.section
= sectp
;
1989 this->rnglists
.size
= bfd_section_size (sectp
);
1991 else if (section_is_p (sectp
->name
, &names
.types
))
1993 struct dwarf2_section_info type_section
;
1995 memset (&type_section
, 0, sizeof (type_section
));
1996 type_section
.s
.section
= sectp
;
1997 type_section
.size
= bfd_section_size (sectp
);
1999 this->types
.push_back (type_section
);
2001 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2003 this->gdb_index
.s
.section
= sectp
;
2004 this->gdb_index
.size
= bfd_section_size (sectp
);
2006 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2008 this->debug_names
.s
.section
= sectp
;
2009 this->debug_names
.size
= bfd_section_size (sectp
);
2011 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2013 this->debug_aranges
.s
.section
= sectp
;
2014 this->debug_aranges
.size
= bfd_section_size (sectp
);
2017 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2018 && bfd_section_vma (sectp
) == 0)
2019 this->has_section_at_zero
= true;
2022 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2026 dwarf2_get_section_info (struct objfile
*objfile
,
2027 enum dwarf2_section_enum sect
,
2028 asection
**sectp
, const gdb_byte
**bufp
,
2029 bfd_size_type
*sizep
)
2031 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2032 struct dwarf2_section_info
*info
;
2034 /* We may see an objfile without any DWARF, in which case we just
2045 case DWARF2_DEBUG_FRAME
:
2046 info
= &data
->frame
;
2048 case DWARF2_EH_FRAME
:
2049 info
= &data
->eh_frame
;
2052 gdb_assert_not_reached ("unexpected section");
2055 info
->read (objfile
);
2057 *sectp
= info
->get_bfd_section ();
2058 *bufp
= info
->buffer
;
2059 *sizep
= info
->size
;
2062 /* A helper function to find the sections for a .dwz file. */
2065 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2067 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2069 /* Note that we only support the standard ELF names, because .dwz
2070 is ELF-only (at the time of writing). */
2071 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2073 dwz_file
->abbrev
.s
.section
= sectp
;
2074 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2076 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2078 dwz_file
->info
.s
.section
= sectp
;
2079 dwz_file
->info
.size
= bfd_section_size (sectp
);
2081 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2083 dwz_file
->str
.s
.section
= sectp
;
2084 dwz_file
->str
.size
= bfd_section_size (sectp
);
2086 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2088 dwz_file
->line
.s
.section
= sectp
;
2089 dwz_file
->line
.size
= bfd_section_size (sectp
);
2091 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2093 dwz_file
->macro
.s
.section
= sectp
;
2094 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2096 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2098 dwz_file
->gdb_index
.s
.section
= sectp
;
2099 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2101 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2103 dwz_file
->debug_names
.s
.section
= sectp
;
2104 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2108 /* See dwarf2read.h. */
2111 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2113 const char *filename
;
2114 bfd_size_type buildid_len_arg
;
2118 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2119 return dwarf2_per_objfile
->dwz_file
.get ();
2121 bfd_set_error (bfd_error_no_error
);
2122 gdb::unique_xmalloc_ptr
<char> data
2123 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2124 &buildid_len_arg
, &buildid
));
2127 if (bfd_get_error () == bfd_error_no_error
)
2129 error (_("could not read '.gnu_debugaltlink' section: %s"),
2130 bfd_errmsg (bfd_get_error ()));
2133 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2135 buildid_len
= (size_t) buildid_len_arg
;
2137 filename
= data
.get ();
2139 std::string abs_storage
;
2140 if (!IS_ABSOLUTE_PATH (filename
))
2142 gdb::unique_xmalloc_ptr
<char> abs
2143 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2145 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2146 filename
= abs_storage
.c_str ();
2149 /* First try the file name given in the section. If that doesn't
2150 work, try to use the build-id instead. */
2151 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2152 if (dwz_bfd
!= NULL
)
2154 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2155 dwz_bfd
.reset (nullptr);
2158 if (dwz_bfd
== NULL
)
2159 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2161 if (dwz_bfd
== NULL
)
2162 error (_("could not find '.gnu_debugaltlink' file for %s"),
2163 objfile_name (dwarf2_per_objfile
->objfile
));
2165 std::unique_ptr
<struct dwz_file
> result
2166 (new struct dwz_file (std::move (dwz_bfd
)));
2168 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2171 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2172 result
->dwz_bfd
.get ());
2173 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2174 return dwarf2_per_objfile
->dwz_file
.get ();
2177 /* DWARF quick_symbols_functions support. */
2179 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2180 unique line tables, so we maintain a separate table of all .debug_line
2181 derived entries to support the sharing.
2182 All the quick functions need is the list of file names. We discard the
2183 line_header when we're done and don't need to record it here. */
2184 struct quick_file_names
2186 /* The data used to construct the hash key. */
2187 struct stmt_list_hash hash
;
2189 /* The number of entries in file_names, real_names. */
2190 unsigned int num_file_names
;
2192 /* The file names from the line table, after being run through
2194 const char **file_names
;
2196 /* The file names from the line table after being run through
2197 gdb_realpath. These are computed lazily. */
2198 const char **real_names
;
2201 /* When using the index (and thus not using psymtabs), each CU has an
2202 object of this type. This is used to hold information needed by
2203 the various "quick" methods. */
2204 struct dwarf2_per_cu_quick_data
2206 /* The file table. This can be NULL if there was no file table
2207 or it's currently not read in.
2208 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2209 struct quick_file_names
*file_names
;
2211 /* The corresponding symbol table. This is NULL if symbols for this
2212 CU have not yet been read. */
2213 struct compunit_symtab
*compunit_symtab
;
2215 /* A temporary mark bit used when iterating over all CUs in
2216 expand_symtabs_matching. */
2217 unsigned int mark
: 1;
2219 /* True if we've tried to read the file table and found there isn't one.
2220 There will be no point in trying to read it again next time. */
2221 unsigned int no_file_data
: 1;
2224 /* Utility hash function for a stmt_list_hash. */
2227 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2231 if (stmt_list_hash
->dwo_unit
!= NULL
)
2232 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2233 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2237 /* Utility equality function for a stmt_list_hash. */
2240 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2241 const struct stmt_list_hash
*rhs
)
2243 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2245 if (lhs
->dwo_unit
!= NULL
2246 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2249 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2252 /* Hash function for a quick_file_names. */
2255 hash_file_name_entry (const void *e
)
2257 const struct quick_file_names
*file_data
2258 = (const struct quick_file_names
*) e
;
2260 return hash_stmt_list_entry (&file_data
->hash
);
2263 /* Equality function for a quick_file_names. */
2266 eq_file_name_entry (const void *a
, const void *b
)
2268 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2269 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2271 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2274 /* Delete function for a quick_file_names. */
2277 delete_file_name_entry (void *e
)
2279 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2282 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2284 xfree ((void*) file_data
->file_names
[i
]);
2285 if (file_data
->real_names
)
2286 xfree ((void*) file_data
->real_names
[i
]);
2289 /* The space for the struct itself lives on objfile_obstack,
2290 so we don't free it here. */
2293 /* Create a quick_file_names hash table. */
2296 create_quick_file_names_table (unsigned int nr_initial_entries
)
2298 return htab_up (htab_create_alloc (nr_initial_entries
,
2299 hash_file_name_entry
, eq_file_name_entry
,
2300 delete_file_name_entry
, xcalloc
, xfree
));
2303 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2304 have to be created afterwards. You should call age_cached_comp_units after
2305 processing PER_CU->CU. dw2_setup must have been already called. */
2308 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2310 if (per_cu
->is_debug_types
)
2311 load_full_type_unit (per_cu
);
2313 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2315 if (per_cu
->cu
== NULL
)
2316 return; /* Dummy CU. */
2318 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2321 /* Read in the symbols for PER_CU. */
2324 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2326 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2328 /* Skip type_unit_groups, reading the type units they contain
2329 is handled elsewhere. */
2330 if (IS_TYPE_UNIT_GROUP (per_cu
))
2333 /* The destructor of dwarf2_queue_guard frees any entries left on
2334 the queue. After this point we're guaranteed to leave this function
2335 with the dwarf queue empty. */
2336 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2338 if (dwarf2_per_objfile
->using_index
2339 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2340 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2342 queue_comp_unit (per_cu
, language_minimal
);
2343 load_cu (per_cu
, skip_partial
);
2345 /* If we just loaded a CU from a DWO, and we're working with an index
2346 that may badly handle TUs, load all the TUs in that DWO as well.
2347 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2348 if (!per_cu
->is_debug_types
2349 && per_cu
->cu
!= NULL
2350 && per_cu
->cu
->dwo_unit
!= NULL
2351 && dwarf2_per_objfile
->index_table
!= NULL
2352 && dwarf2_per_objfile
->index_table
->version
<= 7
2353 /* DWP files aren't supported yet. */
2354 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2355 queue_and_load_all_dwo_tus (per_cu
);
2358 process_queue (dwarf2_per_objfile
);
2360 /* Age the cache, releasing compilation units that have not
2361 been used recently. */
2362 age_cached_comp_units (dwarf2_per_objfile
);
2365 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2366 the objfile from which this CU came. Returns the resulting symbol
2369 static struct compunit_symtab
*
2370 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2372 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2374 gdb_assert (dwarf2_per_objfile
->using_index
);
2375 if (!per_cu
->v
.quick
->compunit_symtab
)
2377 free_cached_comp_units
freer (dwarf2_per_objfile
);
2378 scoped_restore decrementer
= increment_reading_symtab ();
2379 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2380 process_cu_includes (dwarf2_per_objfile
);
2383 return per_cu
->v
.quick
->compunit_symtab
;
2386 /* See declaration. */
2388 dwarf2_per_cu_data
*
2389 dwarf2_per_objfile::get_cutu (int index
)
2391 if (index
>= this->all_comp_units
.size ())
2393 index
-= this->all_comp_units
.size ();
2394 gdb_assert (index
< this->all_type_units
.size ());
2395 return &this->all_type_units
[index
]->per_cu
;
2398 return this->all_comp_units
[index
];
2401 /* See declaration. */
2403 dwarf2_per_cu_data
*
2404 dwarf2_per_objfile::get_cu (int index
)
2406 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2408 return this->all_comp_units
[index
];
2411 /* See declaration. */
2414 dwarf2_per_objfile::get_tu (int index
)
2416 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2418 return this->all_type_units
[index
];
2421 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2422 objfile_obstack, and constructed with the specified field
2425 static dwarf2_per_cu_data
*
2426 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2427 struct dwarf2_section_info
*section
,
2429 sect_offset sect_off
, ULONGEST length
)
2431 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2432 dwarf2_per_cu_data
*the_cu
2433 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2434 struct dwarf2_per_cu_data
);
2435 the_cu
->sect_off
= sect_off
;
2436 the_cu
->length
= length
;
2437 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2438 the_cu
->section
= section
;
2439 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2440 struct dwarf2_per_cu_quick_data
);
2441 the_cu
->is_dwz
= is_dwz
;
2445 /* A helper for create_cus_from_index that handles a given list of
2449 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2450 const gdb_byte
*cu_list
, offset_type n_elements
,
2451 struct dwarf2_section_info
*section
,
2454 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2456 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2458 sect_offset sect_off
2459 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2460 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2463 dwarf2_per_cu_data
*per_cu
2464 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2466 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2470 /* Read the CU list from the mapped index, and use it to create all
2471 the CU objects for this objfile. */
2474 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2475 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2476 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2478 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2479 dwarf2_per_objfile
->all_comp_units
.reserve
2480 ((cu_list_elements
+ dwz_elements
) / 2);
2482 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2483 &dwarf2_per_objfile
->info
, 0);
2485 if (dwz_elements
== 0)
2488 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2489 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2493 /* Create the signatured type hash table from the index. */
2496 create_signatured_type_table_from_index
2497 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2498 struct dwarf2_section_info
*section
,
2499 const gdb_byte
*bytes
,
2500 offset_type elements
)
2502 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2504 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2505 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2507 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2509 for (offset_type i
= 0; i
< elements
; i
+= 3)
2511 struct signatured_type
*sig_type
;
2514 cu_offset type_offset_in_tu
;
2516 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2517 sect_offset sect_off
2518 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2520 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2522 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2525 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2526 struct signatured_type
);
2527 sig_type
->signature
= signature
;
2528 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2529 sig_type
->per_cu
.is_debug_types
= 1;
2530 sig_type
->per_cu
.section
= section
;
2531 sig_type
->per_cu
.sect_off
= sect_off
;
2532 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2533 sig_type
->per_cu
.v
.quick
2534 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2535 struct dwarf2_per_cu_quick_data
);
2537 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2540 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2543 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2546 /* Create the signatured type hash table from .debug_names. */
2549 create_signatured_type_table_from_debug_names
2550 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2551 const mapped_debug_names
&map
,
2552 struct dwarf2_section_info
*section
,
2553 struct dwarf2_section_info
*abbrev_section
)
2555 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2557 section
->read (objfile
);
2558 abbrev_section
->read (objfile
);
2560 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2561 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2563 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2565 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2567 struct signatured_type
*sig_type
;
2570 sect_offset sect_off
2571 = (sect_offset
) (extract_unsigned_integer
2572 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2574 map
.dwarf5_byte_order
));
2576 comp_unit_head cu_header
;
2577 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2579 section
->buffer
+ to_underlying (sect_off
),
2582 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2583 struct signatured_type
);
2584 sig_type
->signature
= cu_header
.signature
;
2585 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2586 sig_type
->per_cu
.is_debug_types
= 1;
2587 sig_type
->per_cu
.section
= section
;
2588 sig_type
->per_cu
.sect_off
= sect_off
;
2589 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2590 sig_type
->per_cu
.v
.quick
2591 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2592 struct dwarf2_per_cu_quick_data
);
2594 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2597 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2600 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2603 /* Read the address map data from the mapped index, and use it to
2604 populate the objfile's psymtabs_addrmap. */
2607 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2608 struct mapped_index
*index
)
2610 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2611 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2612 const gdb_byte
*iter
, *end
;
2613 struct addrmap
*mutable_map
;
2616 auto_obstack temp_obstack
;
2618 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2620 iter
= index
->address_table
.data ();
2621 end
= iter
+ index
->address_table
.size ();
2623 baseaddr
= objfile
->text_section_offset ();
2627 ULONGEST hi
, lo
, cu_index
;
2628 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2630 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2632 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2637 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2638 hex_string (lo
), hex_string (hi
));
2642 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2644 complaint (_(".gdb_index address table has invalid CU number %u"),
2645 (unsigned) cu_index
);
2649 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2650 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2651 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2652 dwarf2_per_objfile
->get_cu (cu_index
));
2655 objfile
->partial_symtabs
->psymtabs_addrmap
2656 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2659 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2660 populate the objfile's psymtabs_addrmap. */
2663 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2664 struct dwarf2_section_info
*section
)
2666 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2667 bfd
*abfd
= objfile
->obfd
;
2668 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2669 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2671 auto_obstack temp_obstack
;
2672 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2674 std::unordered_map
<sect_offset
,
2675 dwarf2_per_cu_data
*,
2676 gdb::hash_enum
<sect_offset
>>
2677 debug_info_offset_to_per_cu
;
2678 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2680 const auto insertpair
2681 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2682 if (!insertpair
.second
)
2684 warning (_("Section .debug_aranges in %s has duplicate "
2685 "debug_info_offset %s, ignoring .debug_aranges."),
2686 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2691 section
->read (objfile
);
2693 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2695 const gdb_byte
*addr
= section
->buffer
;
2697 while (addr
< section
->buffer
+ section
->size
)
2699 const gdb_byte
*const entry_addr
= addr
;
2700 unsigned int bytes_read
;
2702 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2706 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2707 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2708 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2709 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2711 warning (_("Section .debug_aranges in %s entry at offset %s "
2712 "length %s exceeds section length %s, "
2713 "ignoring .debug_aranges."),
2714 objfile_name (objfile
),
2715 plongest (entry_addr
- section
->buffer
),
2716 plongest (bytes_read
+ entry_length
),
2717 pulongest (section
->size
));
2721 /* The version number. */
2722 const uint16_t version
= read_2_bytes (abfd
, addr
);
2726 warning (_("Section .debug_aranges in %s entry at offset %s "
2727 "has unsupported version %d, ignoring .debug_aranges."),
2728 objfile_name (objfile
),
2729 plongest (entry_addr
- section
->buffer
), version
);
2733 const uint64_t debug_info_offset
2734 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2735 addr
+= offset_size
;
2736 const auto per_cu_it
2737 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2738 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2740 warning (_("Section .debug_aranges in %s entry at offset %s "
2741 "debug_info_offset %s does not exists, "
2742 "ignoring .debug_aranges."),
2743 objfile_name (objfile
),
2744 plongest (entry_addr
- section
->buffer
),
2745 pulongest (debug_info_offset
));
2748 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2750 const uint8_t address_size
= *addr
++;
2751 if (address_size
< 1 || address_size
> 8)
2753 warning (_("Section .debug_aranges in %s entry at offset %s "
2754 "address_size %u is invalid, ignoring .debug_aranges."),
2755 objfile_name (objfile
),
2756 plongest (entry_addr
- section
->buffer
), address_size
);
2760 const uint8_t segment_selector_size
= *addr
++;
2761 if (segment_selector_size
!= 0)
2763 warning (_("Section .debug_aranges in %s entry at offset %s "
2764 "segment_selector_size %u is not supported, "
2765 "ignoring .debug_aranges."),
2766 objfile_name (objfile
),
2767 plongest (entry_addr
- section
->buffer
),
2768 segment_selector_size
);
2772 /* Must pad to an alignment boundary that is twice the address
2773 size. It is undocumented by the DWARF standard but GCC does
2775 for (size_t padding
= ((-(addr
- section
->buffer
))
2776 & (2 * address_size
- 1));
2777 padding
> 0; padding
--)
2780 warning (_("Section .debug_aranges in %s entry at offset %s "
2781 "padding is not zero, ignoring .debug_aranges."),
2782 objfile_name (objfile
),
2783 plongest (entry_addr
- section
->buffer
));
2789 if (addr
+ 2 * address_size
> entry_end
)
2791 warning (_("Section .debug_aranges in %s entry at offset %s "
2792 "address list is not properly terminated, "
2793 "ignoring .debug_aranges."),
2794 objfile_name (objfile
),
2795 plongest (entry_addr
- section
->buffer
));
2798 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2800 addr
+= address_size
;
2801 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2803 addr
+= address_size
;
2804 if (start
== 0 && length
== 0)
2806 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2808 /* Symbol was eliminated due to a COMDAT group. */
2811 ULONGEST end
= start
+ length
;
2812 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2814 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2816 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2820 objfile
->partial_symtabs
->psymtabs_addrmap
2821 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2824 /* Find a slot in the mapped index INDEX for the object named NAME.
2825 If NAME is found, set *VEC_OUT to point to the CU vector in the
2826 constant pool and return true. If NAME cannot be found, return
2830 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2831 offset_type
**vec_out
)
2834 offset_type slot
, step
;
2835 int (*cmp
) (const char *, const char *);
2837 gdb::unique_xmalloc_ptr
<char> without_params
;
2838 if (current_language
->la_language
== language_cplus
2839 || current_language
->la_language
== language_fortran
2840 || current_language
->la_language
== language_d
)
2842 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2845 if (strchr (name
, '(') != NULL
)
2847 without_params
= cp_remove_params (name
);
2849 if (without_params
!= NULL
)
2850 name
= without_params
.get ();
2854 /* Index version 4 did not support case insensitive searches. But the
2855 indices for case insensitive languages are built in lowercase, therefore
2856 simulate our NAME being searched is also lowercased. */
2857 hash
= mapped_index_string_hash ((index
->version
== 4
2858 && case_sensitivity
== case_sensitive_off
2859 ? 5 : index
->version
),
2862 slot
= hash
& (index
->symbol_table
.size () - 1);
2863 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2864 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2870 const auto &bucket
= index
->symbol_table
[slot
];
2871 if (bucket
.name
== 0 && bucket
.vec
== 0)
2874 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2875 if (!cmp (name
, str
))
2877 *vec_out
= (offset_type
*) (index
->constant_pool
2878 + MAYBE_SWAP (bucket
.vec
));
2882 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2886 /* A helper function that reads the .gdb_index from BUFFER and fills
2887 in MAP. FILENAME is the name of the file containing the data;
2888 it is used for error reporting. DEPRECATED_OK is true if it is
2889 ok to use deprecated sections.
2891 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2892 out parameters that are filled in with information about the CU and
2893 TU lists in the section.
2895 Returns true if all went well, false otherwise. */
2898 read_gdb_index_from_buffer (struct objfile
*objfile
,
2899 const char *filename
,
2901 gdb::array_view
<const gdb_byte
> buffer
,
2902 struct mapped_index
*map
,
2903 const gdb_byte
**cu_list
,
2904 offset_type
*cu_list_elements
,
2905 const gdb_byte
**types_list
,
2906 offset_type
*types_list_elements
)
2908 const gdb_byte
*addr
= &buffer
[0];
2910 /* Version check. */
2911 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2912 /* Versions earlier than 3 emitted every copy of a psymbol. This
2913 causes the index to behave very poorly for certain requests. Version 3
2914 contained incomplete addrmap. So, it seems better to just ignore such
2918 static int warning_printed
= 0;
2919 if (!warning_printed
)
2921 warning (_("Skipping obsolete .gdb_index section in %s."),
2923 warning_printed
= 1;
2927 /* Index version 4 uses a different hash function than index version
2930 Versions earlier than 6 did not emit psymbols for inlined
2931 functions. Using these files will cause GDB not to be able to
2932 set breakpoints on inlined functions by name, so we ignore these
2933 indices unless the user has done
2934 "set use-deprecated-index-sections on". */
2935 if (version
< 6 && !deprecated_ok
)
2937 static int warning_printed
= 0;
2938 if (!warning_printed
)
2941 Skipping deprecated .gdb_index section in %s.\n\
2942 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2943 to use the section anyway."),
2945 warning_printed
= 1;
2949 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2950 of the TU (for symbols coming from TUs),
2951 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2952 Plus gold-generated indices can have duplicate entries for global symbols,
2953 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2954 These are just performance bugs, and we can't distinguish gdb-generated
2955 indices from gold-generated ones, so issue no warning here. */
2957 /* Indexes with higher version than the one supported by GDB may be no
2958 longer backward compatible. */
2962 map
->version
= version
;
2964 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2967 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2968 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2972 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2973 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2974 - MAYBE_SWAP (metadata
[i
]))
2978 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2979 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2981 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2984 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2985 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2987 = gdb::array_view
<mapped_index::symbol_table_slot
>
2988 ((mapped_index::symbol_table_slot
*) symbol_table
,
2989 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2992 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2997 /* Callback types for dwarf2_read_gdb_index. */
2999 typedef gdb::function_view
3000 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3001 get_gdb_index_contents_ftype
;
3002 typedef gdb::function_view
3003 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3004 get_gdb_index_contents_dwz_ftype
;
3006 /* Read .gdb_index. If everything went ok, initialize the "quick"
3007 elements of all the CUs and return 1. Otherwise, return 0. */
3010 dwarf2_read_gdb_index
3011 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3012 get_gdb_index_contents_ftype get_gdb_index_contents
,
3013 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3015 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3016 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3017 struct dwz_file
*dwz
;
3018 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3020 gdb::array_view
<const gdb_byte
> main_index_contents
3021 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3023 if (main_index_contents
.empty ())
3026 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3027 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3028 use_deprecated_index_sections
,
3029 main_index_contents
, map
.get (), &cu_list
,
3030 &cu_list_elements
, &types_list
,
3031 &types_list_elements
))
3034 /* Don't use the index if it's empty. */
3035 if (map
->symbol_table
.empty ())
3038 /* If there is a .dwz file, read it so we can get its CU list as
3040 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3043 struct mapped_index dwz_map
;
3044 const gdb_byte
*dwz_types_ignore
;
3045 offset_type dwz_types_elements_ignore
;
3047 gdb::array_view
<const gdb_byte
> dwz_index_content
3048 = get_gdb_index_contents_dwz (objfile
, dwz
);
3050 if (dwz_index_content
.empty ())
3053 if (!read_gdb_index_from_buffer (objfile
,
3054 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3055 1, dwz_index_content
, &dwz_map
,
3056 &dwz_list
, &dwz_list_elements
,
3058 &dwz_types_elements_ignore
))
3060 warning (_("could not read '.gdb_index' section from %s; skipping"),
3061 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3066 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3067 dwz_list
, dwz_list_elements
);
3069 if (types_list_elements
)
3071 /* We can only handle a single .debug_types when we have an
3073 if (dwarf2_per_objfile
->types
.size () != 1)
3076 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3078 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3079 types_list
, types_list_elements
);
3082 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3084 dwarf2_per_objfile
->index_table
= std::move (map
);
3085 dwarf2_per_objfile
->using_index
= 1;
3086 dwarf2_per_objfile
->quick_file_names_table
=
3087 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3092 /* die_reader_func for dw2_get_file_names. */
3095 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3096 const gdb_byte
*info_ptr
,
3097 struct die_info
*comp_unit_die
)
3099 struct dwarf2_cu
*cu
= reader
->cu
;
3100 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3101 struct dwarf2_per_objfile
*dwarf2_per_objfile
3102 = cu
->per_cu
->dwarf2_per_objfile
;
3103 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3104 struct dwarf2_per_cu_data
*lh_cu
;
3105 struct attribute
*attr
;
3107 struct quick_file_names
*qfn
;
3109 gdb_assert (! this_cu
->is_debug_types
);
3111 /* Our callers never want to match partial units -- instead they
3112 will match the enclosing full CU. */
3113 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3115 this_cu
->v
.quick
->no_file_data
= 1;
3123 sect_offset line_offset
{};
3125 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3126 if (attr
!= nullptr)
3128 struct quick_file_names find_entry
;
3130 line_offset
= (sect_offset
) DW_UNSND (attr
);
3132 /* We may have already read in this line header (TU line header sharing).
3133 If we have we're done. */
3134 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3135 find_entry
.hash
.line_sect_off
= line_offset
;
3136 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3137 &find_entry
, INSERT
);
3140 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3144 lh
= dwarf_decode_line_header (line_offset
, cu
);
3148 lh_cu
->v
.quick
->no_file_data
= 1;
3152 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3153 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3154 qfn
->hash
.line_sect_off
= line_offset
;
3155 gdb_assert (slot
!= NULL
);
3158 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3161 if (strcmp (fnd
.name
, "<unknown>") != 0)
3164 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3166 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3168 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3169 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3170 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3171 fnd
.comp_dir
).release ();
3172 qfn
->real_names
= NULL
;
3174 lh_cu
->v
.quick
->file_names
= qfn
;
3177 /* A helper for the "quick" functions which attempts to read the line
3178 table for THIS_CU. */
3180 static struct quick_file_names
*
3181 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3183 /* This should never be called for TUs. */
3184 gdb_assert (! this_cu
->is_debug_types
);
3185 /* Nor type unit groups. */
3186 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3188 if (this_cu
->v
.quick
->file_names
!= NULL
)
3189 return this_cu
->v
.quick
->file_names
;
3190 /* If we know there is no line data, no point in looking again. */
3191 if (this_cu
->v
.quick
->no_file_data
)
3194 cutu_reader
reader (this_cu
);
3195 if (!reader
.dummy_p
)
3196 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3198 if (this_cu
->v
.quick
->no_file_data
)
3200 return this_cu
->v
.quick
->file_names
;
3203 /* A helper for the "quick" functions which computes and caches the
3204 real path for a given file name from the line table. */
3207 dw2_get_real_path (struct objfile
*objfile
,
3208 struct quick_file_names
*qfn
, int index
)
3210 if (qfn
->real_names
== NULL
)
3211 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3212 qfn
->num_file_names
, const char *);
3214 if (qfn
->real_names
[index
] == NULL
)
3215 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3217 return qfn
->real_names
[index
];
3220 static struct symtab
*
3221 dw2_find_last_source_symtab (struct objfile
*objfile
)
3223 struct dwarf2_per_objfile
*dwarf2_per_objfile
3224 = get_dwarf2_per_objfile (objfile
);
3225 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3226 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3231 return compunit_primary_filetab (cust
);
3234 /* Traversal function for dw2_forget_cached_source_info. */
3237 dw2_free_cached_file_names (void **slot
, void *info
)
3239 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3241 if (file_data
->real_names
)
3245 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3247 xfree ((void*) file_data
->real_names
[i
]);
3248 file_data
->real_names
[i
] = NULL
;
3256 dw2_forget_cached_source_info (struct objfile
*objfile
)
3258 struct dwarf2_per_objfile
*dwarf2_per_objfile
3259 = get_dwarf2_per_objfile (objfile
);
3261 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3262 dw2_free_cached_file_names
, NULL
);
3265 /* Helper function for dw2_map_symtabs_matching_filename that expands
3266 the symtabs and calls the iterator. */
3269 dw2_map_expand_apply (struct objfile
*objfile
,
3270 struct dwarf2_per_cu_data
*per_cu
,
3271 const char *name
, const char *real_path
,
3272 gdb::function_view
<bool (symtab
*)> callback
)
3274 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3276 /* Don't visit already-expanded CUs. */
3277 if (per_cu
->v
.quick
->compunit_symtab
)
3280 /* This may expand more than one symtab, and we want to iterate over
3282 dw2_instantiate_symtab (per_cu
, false);
3284 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3285 last_made
, callback
);
3288 /* Implementation of the map_symtabs_matching_filename method. */
3291 dw2_map_symtabs_matching_filename
3292 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3293 gdb::function_view
<bool (symtab
*)> callback
)
3295 const char *name_basename
= lbasename (name
);
3296 struct dwarf2_per_objfile
*dwarf2_per_objfile
3297 = get_dwarf2_per_objfile (objfile
);
3299 /* The rule is CUs specify all the files, including those used by
3300 any TU, so there's no need to scan TUs here. */
3302 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3304 /* We only need to look at symtabs not already expanded. */
3305 if (per_cu
->v
.quick
->compunit_symtab
)
3308 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3309 if (file_data
== NULL
)
3312 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3314 const char *this_name
= file_data
->file_names
[j
];
3315 const char *this_real_name
;
3317 if (compare_filenames_for_search (this_name
, name
))
3319 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3325 /* Before we invoke realpath, which can get expensive when many
3326 files are involved, do a quick comparison of the basenames. */
3327 if (! basenames_may_differ
3328 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3331 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3332 if (compare_filenames_for_search (this_real_name
, name
))
3334 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3340 if (real_path
!= NULL
)
3342 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3343 gdb_assert (IS_ABSOLUTE_PATH (name
));
3344 if (this_real_name
!= NULL
3345 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3347 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3359 /* Struct used to manage iterating over all CUs looking for a symbol. */
3361 struct dw2_symtab_iterator
3363 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3364 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3365 /* If set, only look for symbols that match that block. Valid values are
3366 GLOBAL_BLOCK and STATIC_BLOCK. */
3367 gdb::optional
<block_enum
> block_index
;
3368 /* The kind of symbol we're looking for. */
3370 /* The list of CUs from the index entry of the symbol,
3371 or NULL if not found. */
3373 /* The next element in VEC to look at. */
3375 /* The number of elements in VEC, or zero if there is no match. */
3377 /* Have we seen a global version of the symbol?
3378 If so we can ignore all further global instances.
3379 This is to work around gold/15646, inefficient gold-generated
3384 /* Initialize the index symtab iterator ITER. */
3387 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3388 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3389 gdb::optional
<block_enum
> block_index
,
3393 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3394 iter
->block_index
= block_index
;
3395 iter
->domain
= domain
;
3397 iter
->global_seen
= 0;
3399 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3401 /* index is NULL if OBJF_READNOW. */
3402 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3403 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3411 /* Return the next matching CU or NULL if there are no more. */
3413 static struct dwarf2_per_cu_data
*
3414 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3416 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3418 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3420 offset_type cu_index_and_attrs
=
3421 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3422 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3423 gdb_index_symbol_kind symbol_kind
=
3424 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3425 /* Only check the symbol attributes if they're present.
3426 Indices prior to version 7 don't record them,
3427 and indices >= 7 may elide them for certain symbols
3428 (gold does this). */
3430 (dwarf2_per_objfile
->index_table
->version
>= 7
3431 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3433 /* Don't crash on bad data. */
3434 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3435 + dwarf2_per_objfile
->all_type_units
.size ()))
3437 complaint (_(".gdb_index entry has bad CU index"
3439 objfile_name (dwarf2_per_objfile
->objfile
));
3443 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3445 /* Skip if already read in. */
3446 if (per_cu
->v
.quick
->compunit_symtab
)
3449 /* Check static vs global. */
3452 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3454 if (iter
->block_index
.has_value ())
3456 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3458 if (is_static
!= want_static
)
3462 /* Work around gold/15646. */
3463 if (!is_static
&& iter
->global_seen
)
3466 iter
->global_seen
= 1;
3469 /* Only check the symbol's kind if it has one. */
3472 switch (iter
->domain
)
3475 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3476 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3477 /* Some types are also in VAR_DOMAIN. */
3478 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3482 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3486 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3490 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3505 static struct compunit_symtab
*
3506 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3507 const char *name
, domain_enum domain
)
3509 struct compunit_symtab
*stab_best
= NULL
;
3510 struct dwarf2_per_objfile
*dwarf2_per_objfile
3511 = get_dwarf2_per_objfile (objfile
);
3513 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3515 struct dw2_symtab_iterator iter
;
3516 struct dwarf2_per_cu_data
*per_cu
;
3518 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3520 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3522 struct symbol
*sym
, *with_opaque
= NULL
;
3523 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3524 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3525 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3527 sym
= block_find_symbol (block
, name
, domain
,
3528 block_find_non_opaque_type_preferred
,
3531 /* Some caution must be observed with overloaded functions
3532 and methods, since the index will not contain any overload
3533 information (but NAME might contain it). */
3536 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3538 if (with_opaque
!= NULL
3539 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3542 /* Keep looking through other CUs. */
3549 dw2_print_stats (struct objfile
*objfile
)
3551 struct dwarf2_per_objfile
*dwarf2_per_objfile
3552 = get_dwarf2_per_objfile (objfile
);
3553 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3554 + dwarf2_per_objfile
->all_type_units
.size ());
3557 for (int i
= 0; i
< total
; ++i
)
3559 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3561 if (!per_cu
->v
.quick
->compunit_symtab
)
3564 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3565 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3568 /* This dumps minimal information about the index.
3569 It is called via "mt print objfiles".
3570 One use is to verify .gdb_index has been loaded by the
3571 gdb.dwarf2/gdb-index.exp testcase. */
3574 dw2_dump (struct objfile
*objfile
)
3576 struct dwarf2_per_objfile
*dwarf2_per_objfile
3577 = get_dwarf2_per_objfile (objfile
);
3579 gdb_assert (dwarf2_per_objfile
->using_index
);
3580 printf_filtered (".gdb_index:");
3581 if (dwarf2_per_objfile
->index_table
!= NULL
)
3583 printf_filtered (" version %d\n",
3584 dwarf2_per_objfile
->index_table
->version
);
3587 printf_filtered (" faked for \"readnow\"\n");
3588 printf_filtered ("\n");
3592 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3593 const char *func_name
)
3595 struct dwarf2_per_objfile
*dwarf2_per_objfile
3596 = get_dwarf2_per_objfile (objfile
);
3598 struct dw2_symtab_iterator iter
;
3599 struct dwarf2_per_cu_data
*per_cu
;
3601 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3603 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3604 dw2_instantiate_symtab (per_cu
, false);
3609 dw2_expand_all_symtabs (struct objfile
*objfile
)
3611 struct dwarf2_per_objfile
*dwarf2_per_objfile
3612 = get_dwarf2_per_objfile (objfile
);
3613 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3614 + dwarf2_per_objfile
->all_type_units
.size ());
3616 for (int i
= 0; i
< total_units
; ++i
)
3618 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3620 /* We don't want to directly expand a partial CU, because if we
3621 read it with the wrong language, then assertion failures can
3622 be triggered later on. See PR symtab/23010. So, tell
3623 dw2_instantiate_symtab to skip partial CUs -- any important
3624 partial CU will be read via DW_TAG_imported_unit anyway. */
3625 dw2_instantiate_symtab (per_cu
, true);
3630 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3631 const char *fullname
)
3633 struct dwarf2_per_objfile
*dwarf2_per_objfile
3634 = get_dwarf2_per_objfile (objfile
);
3636 /* We don't need to consider type units here.
3637 This is only called for examining code, e.g. expand_line_sal.
3638 There can be an order of magnitude (or more) more type units
3639 than comp units, and we avoid them if we can. */
3641 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3643 /* We only need to look at symtabs not already expanded. */
3644 if (per_cu
->v
.quick
->compunit_symtab
)
3647 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3648 if (file_data
== NULL
)
3651 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3653 const char *this_fullname
= file_data
->file_names
[j
];
3655 if (filename_cmp (this_fullname
, fullname
) == 0)
3657 dw2_instantiate_symtab (per_cu
, false);
3665 dw2_map_matching_symbols
3666 (struct objfile
*objfile
,
3667 const lookup_name_info
&name
, domain_enum domain
,
3669 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3670 symbol_compare_ftype
*ordered_compare
)
3672 /* Currently unimplemented; used for Ada. The function can be called if the
3673 current language is Ada for a non-Ada objfile using GNU index. As Ada
3674 does not look for non-Ada symbols this function should just return. */
3677 /* Starting from a search name, return the string that finds the upper
3678 bound of all strings that start with SEARCH_NAME in a sorted name
3679 list. Returns the empty string to indicate that the upper bound is
3680 the end of the list. */
3683 make_sort_after_prefix_name (const char *search_name
)
3685 /* When looking to complete "func", we find the upper bound of all
3686 symbols that start with "func" by looking for where we'd insert
3687 the closest string that would follow "func" in lexicographical
3688 order. Usually, that's "func"-with-last-character-incremented,
3689 i.e. "fund". Mind non-ASCII characters, though. Usually those
3690 will be UTF-8 multi-byte sequences, but we can't be certain.
3691 Especially mind the 0xff character, which is a valid character in
3692 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3693 rule out compilers allowing it in identifiers. Note that
3694 conveniently, strcmp/strcasecmp are specified to compare
3695 characters interpreted as unsigned char. So what we do is treat
3696 the whole string as a base 256 number composed of a sequence of
3697 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3698 to 0, and carries 1 to the following more-significant position.
3699 If the very first character in SEARCH_NAME ends up incremented
3700 and carries/overflows, then the upper bound is the end of the
3701 list. The string after the empty string is also the empty
3704 Some examples of this operation:
3706 SEARCH_NAME => "+1" RESULT
3710 "\xff" "a" "\xff" => "\xff" "b"
3715 Then, with these symbols for example:
3721 completing "func" looks for symbols between "func" and
3722 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3723 which finds "func" and "func1", but not "fund".
3727 funcÿ (Latin1 'ÿ' [0xff])
3731 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3732 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3736 ÿÿ (Latin1 'ÿ' [0xff])
3739 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3740 the end of the list.
3742 std::string after
= search_name
;
3743 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3745 if (!after
.empty ())
3746 after
.back () = (unsigned char) after
.back () + 1;
3750 /* See declaration. */
3752 std::pair
<std::vector
<name_component
>::const_iterator
,
3753 std::vector
<name_component
>::const_iterator
>
3754 mapped_index_base::find_name_components_bounds
3755 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3758 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3760 const char *lang_name
3761 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3763 /* Comparison function object for lower_bound that matches against a
3764 given symbol name. */
3765 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3768 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3769 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3770 return name_cmp (elem_name
, name
) < 0;
3773 /* Comparison function object for upper_bound that matches against a
3774 given symbol name. */
3775 auto lookup_compare_upper
= [&] (const char *name
,
3776 const name_component
&elem
)
3778 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3779 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3780 return name_cmp (name
, elem_name
) < 0;
3783 auto begin
= this->name_components
.begin ();
3784 auto end
= this->name_components
.end ();
3786 /* Find the lower bound. */
3789 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3792 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3795 /* Find the upper bound. */
3798 if (lookup_name_without_params
.completion_mode ())
3800 /* In completion mode, we want UPPER to point past all
3801 symbols names that have the same prefix. I.e., with
3802 these symbols, and completing "func":
3804 function << lower bound
3806 other_function << upper bound
3808 We find the upper bound by looking for the insertion
3809 point of "func"-with-last-character-incremented,
3811 std::string after
= make_sort_after_prefix_name (lang_name
);
3814 return std::lower_bound (lower
, end
, after
.c_str (),
3815 lookup_compare_lower
);
3818 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3821 return {lower
, upper
};
3824 /* See declaration. */
3827 mapped_index_base::build_name_components ()
3829 if (!this->name_components
.empty ())
3832 this->name_components_casing
= case_sensitivity
;
3834 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3836 /* The code below only knows how to break apart components of C++
3837 symbol names (and other languages that use '::' as
3838 namespace/module separator) and Ada symbol names. */
3839 auto count
= this->symbol_name_count ();
3840 for (offset_type idx
= 0; idx
< count
; idx
++)
3842 if (this->symbol_name_slot_invalid (idx
))
3845 const char *name
= this->symbol_name_at (idx
);
3847 /* Add each name component to the name component table. */
3848 unsigned int previous_len
= 0;
3850 if (strstr (name
, "::") != nullptr)
3852 for (unsigned int current_len
= cp_find_first_component (name
);
3853 name
[current_len
] != '\0';
3854 current_len
+= cp_find_first_component (name
+ current_len
))
3856 gdb_assert (name
[current_len
] == ':');
3857 this->name_components
.push_back ({previous_len
, idx
});
3858 /* Skip the '::'. */
3860 previous_len
= current_len
;
3865 /* Handle the Ada encoded (aka mangled) form here. */
3866 for (const char *iter
= strstr (name
, "__");
3868 iter
= strstr (iter
, "__"))
3870 this->name_components
.push_back ({previous_len
, idx
});
3872 previous_len
= iter
- name
;
3876 this->name_components
.push_back ({previous_len
, idx
});
3879 /* Sort name_components elements by name. */
3880 auto name_comp_compare
= [&] (const name_component
&left
,
3881 const name_component
&right
)
3883 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3884 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3886 const char *left_name
= left_qualified
+ left
.name_offset
;
3887 const char *right_name
= right_qualified
+ right
.name_offset
;
3889 return name_cmp (left_name
, right_name
) < 0;
3892 std::sort (this->name_components
.begin (),
3893 this->name_components
.end (),
3897 /* Helper for dw2_expand_symtabs_matching that works with a
3898 mapped_index_base instead of the containing objfile. This is split
3899 to a separate function in order to be able to unit test the
3900 name_components matching using a mock mapped_index_base. For each
3901 symbol name that matches, calls MATCH_CALLBACK, passing it the
3902 symbol's index in the mapped_index_base symbol table. */
3905 dw2_expand_symtabs_matching_symbol
3906 (mapped_index_base
&index
,
3907 const lookup_name_info
&lookup_name_in
,
3908 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3909 enum search_domain kind
,
3910 gdb::function_view
<bool (offset_type
)> match_callback
)
3912 lookup_name_info lookup_name_without_params
3913 = lookup_name_in
.make_ignore_params ();
3915 /* Build the symbol name component sorted vector, if we haven't
3917 index
.build_name_components ();
3919 /* The same symbol may appear more than once in the range though.
3920 E.g., if we're looking for symbols that complete "w", and we have
3921 a symbol named "w1::w2", we'll find the two name components for
3922 that same symbol in the range. To be sure we only call the
3923 callback once per symbol, we first collect the symbol name
3924 indexes that matched in a temporary vector and ignore
3926 std::vector
<offset_type
> matches
;
3928 struct name_and_matcher
3930 symbol_name_matcher_ftype
*matcher
;
3931 const std::string
&name
;
3933 bool operator== (const name_and_matcher
&other
) const
3935 return matcher
== other
.matcher
&& name
== other
.name
;
3939 /* A vector holding all the different symbol name matchers, for all
3941 std::vector
<name_and_matcher
> matchers
;
3943 for (int i
= 0; i
< nr_languages
; i
++)
3945 enum language lang_e
= (enum language
) i
;
3947 const language_defn
*lang
= language_def (lang_e
);
3948 symbol_name_matcher_ftype
*name_matcher
3949 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3951 name_and_matcher key
{
3953 lookup_name_without_params
.language_lookup_name (lang_e
)
3956 /* Don't insert the same comparison routine more than once.
3957 Note that we do this linear walk. This is not a problem in
3958 practice because the number of supported languages is
3960 if (std::find (matchers
.begin (), matchers
.end (), key
)
3963 matchers
.push_back (std::move (key
));
3966 = index
.find_name_components_bounds (lookup_name_without_params
,
3969 /* Now for each symbol name in range, check to see if we have a name
3970 match, and if so, call the MATCH_CALLBACK callback. */
3972 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3974 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3976 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3977 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3980 matches
.push_back (bounds
.first
->idx
);
3984 std::sort (matches
.begin (), matches
.end ());
3986 /* Finally call the callback, once per match. */
3988 for (offset_type idx
: matches
)
3992 if (!match_callback (idx
))
3998 /* Above we use a type wider than idx's for 'prev', since 0 and
3999 (offset_type)-1 are both possible values. */
4000 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4005 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4007 /* A mock .gdb_index/.debug_names-like name index table, enough to
4008 exercise dw2_expand_symtabs_matching_symbol, which works with the
4009 mapped_index_base interface. Builds an index from the symbol list
4010 passed as parameter to the constructor. */
4011 class mock_mapped_index
: public mapped_index_base
4014 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4015 : m_symbol_table (symbols
)
4018 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4020 /* Return the number of names in the symbol table. */
4021 size_t symbol_name_count () const override
4023 return m_symbol_table
.size ();
4026 /* Get the name of the symbol at IDX in the symbol table. */
4027 const char *symbol_name_at (offset_type idx
) const override
4029 return m_symbol_table
[idx
];
4033 gdb::array_view
<const char *> m_symbol_table
;
4036 /* Convenience function that converts a NULL pointer to a "<null>"
4037 string, to pass to print routines. */
4040 string_or_null (const char *str
)
4042 return str
!= NULL
? str
: "<null>";
4045 /* Check if a lookup_name_info built from
4046 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4047 index. EXPECTED_LIST is the list of expected matches, in expected
4048 matching order. If no match expected, then an empty list is
4049 specified. Returns true on success. On failure prints a warning
4050 indicating the file:line that failed, and returns false. */
4053 check_match (const char *file
, int line
,
4054 mock_mapped_index
&mock_index
,
4055 const char *name
, symbol_name_match_type match_type
,
4056 bool completion_mode
,
4057 std::initializer_list
<const char *> expected_list
)
4059 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4061 bool matched
= true;
4063 auto mismatch
= [&] (const char *expected_str
,
4066 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4067 "expected=\"%s\", got=\"%s\"\n"),
4069 (match_type
== symbol_name_match_type::FULL
4071 name
, string_or_null (expected_str
), string_or_null (got
));
4075 auto expected_it
= expected_list
.begin ();
4076 auto expected_end
= expected_list
.end ();
4078 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4080 [&] (offset_type idx
)
4082 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4083 const char *expected_str
4084 = expected_it
== expected_end
? NULL
: *expected_it
++;
4086 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4087 mismatch (expected_str
, matched_name
);
4091 const char *expected_str
4092 = expected_it
== expected_end
? NULL
: *expected_it
++;
4093 if (expected_str
!= NULL
)
4094 mismatch (expected_str
, NULL
);
4099 /* The symbols added to the mock mapped_index for testing (in
4101 static const char *test_symbols
[] = {
4110 "ns2::tmpl<int>::foo2",
4111 "(anonymous namespace)::A::B::C",
4113 /* These are used to check that the increment-last-char in the
4114 matching algorithm for completion doesn't match "t1_fund" when
4115 completing "t1_func". */
4121 /* A UTF-8 name with multi-byte sequences to make sure that
4122 cp-name-parser understands this as a single identifier ("função"
4123 is "function" in PT). */
4126 /* \377 (0xff) is Latin1 'ÿ'. */
4129 /* \377 (0xff) is Latin1 'ÿ'. */
4133 /* A name with all sorts of complications. Starts with "z" to make
4134 it easier for the completion tests below. */
4135 #define Z_SYM_NAME \
4136 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4137 "::tuple<(anonymous namespace)::ui*, " \
4138 "std::default_delete<(anonymous namespace)::ui>, void>"
4143 /* Returns true if the mapped_index_base::find_name_component_bounds
4144 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4145 in completion mode. */
4148 check_find_bounds_finds (mapped_index_base
&index
,
4149 const char *search_name
,
4150 gdb::array_view
<const char *> expected_syms
)
4152 lookup_name_info
lookup_name (search_name
,
4153 symbol_name_match_type::FULL
, true);
4155 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4158 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4159 if (distance
!= expected_syms
.size ())
4162 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4164 auto nc_elem
= bounds
.first
+ exp_elem
;
4165 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4166 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4173 /* Test the lower-level mapped_index::find_name_component_bounds
4177 test_mapped_index_find_name_component_bounds ()
4179 mock_mapped_index
mock_index (test_symbols
);
4181 mock_index
.build_name_components ();
4183 /* Test the lower-level mapped_index::find_name_component_bounds
4184 method in completion mode. */
4186 static const char *expected_syms
[] = {
4191 SELF_CHECK (check_find_bounds_finds (mock_index
,
4192 "t1_func", expected_syms
));
4195 /* Check that the increment-last-char in the name matching algorithm
4196 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4198 static const char *expected_syms1
[] = {
4202 SELF_CHECK (check_find_bounds_finds (mock_index
,
4203 "\377", expected_syms1
));
4205 static const char *expected_syms2
[] = {
4208 SELF_CHECK (check_find_bounds_finds (mock_index
,
4209 "\377\377", expected_syms2
));
4213 /* Test dw2_expand_symtabs_matching_symbol. */
4216 test_dw2_expand_symtabs_matching_symbol ()
4218 mock_mapped_index
mock_index (test_symbols
);
4220 /* We let all tests run until the end even if some fails, for debug
4222 bool any_mismatch
= false;
4224 /* Create the expected symbols list (an initializer_list). Needed
4225 because lists have commas, and we need to pass them to CHECK,
4226 which is a macro. */
4227 #define EXPECT(...) { __VA_ARGS__ }
4229 /* Wrapper for check_match that passes down the current
4230 __FILE__/__LINE__. */
4231 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4232 any_mismatch |= !check_match (__FILE__, __LINE__, \
4234 NAME, MATCH_TYPE, COMPLETION_MODE, \
4237 /* Identity checks. */
4238 for (const char *sym
: test_symbols
)
4240 /* Should be able to match all existing symbols. */
4241 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4244 /* Should be able to match all existing symbols with
4246 std::string with_params
= std::string (sym
) + "(int)";
4247 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4250 /* Should be able to match all existing symbols with
4251 parameters and qualifiers. */
4252 with_params
= std::string (sym
) + " ( int ) const";
4253 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4256 /* This should really find sym, but cp-name-parser.y doesn't
4257 know about lvalue/rvalue qualifiers yet. */
4258 with_params
= std::string (sym
) + " ( int ) &&";
4259 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4263 /* Check that the name matching algorithm for completion doesn't get
4264 confused with Latin1 'ÿ' / 0xff. */
4266 static const char str
[] = "\377";
4267 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4268 EXPECT ("\377", "\377\377123"));
4271 /* Check that the increment-last-char in the matching algorithm for
4272 completion doesn't match "t1_fund" when completing "t1_func". */
4274 static const char str
[] = "t1_func";
4275 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4276 EXPECT ("t1_func", "t1_func1"));
4279 /* Check that completion mode works at each prefix of the expected
4282 static const char str
[] = "function(int)";
4283 size_t len
= strlen (str
);
4286 for (size_t i
= 1; i
< len
; i
++)
4288 lookup
.assign (str
, i
);
4289 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4290 EXPECT ("function"));
4294 /* While "w" is a prefix of both components, the match function
4295 should still only be called once. */
4297 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4299 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4303 /* Same, with a "complicated" symbol. */
4305 static const char str
[] = Z_SYM_NAME
;
4306 size_t len
= strlen (str
);
4309 for (size_t i
= 1; i
< len
; i
++)
4311 lookup
.assign (str
, i
);
4312 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4313 EXPECT (Z_SYM_NAME
));
4317 /* In FULL mode, an incomplete symbol doesn't match. */
4319 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4323 /* A complete symbol with parameters matches any overload, since the
4324 index has no overload info. */
4326 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4327 EXPECT ("std::zfunction", "std::zfunction2"));
4328 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4329 EXPECT ("std::zfunction", "std::zfunction2"));
4330 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4331 EXPECT ("std::zfunction", "std::zfunction2"));
4334 /* Check that whitespace is ignored appropriately. A symbol with a
4335 template argument list. */
4337 static const char expected
[] = "ns::foo<int>";
4338 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4340 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4344 /* Check that whitespace is ignored appropriately. A symbol with a
4345 template argument list that includes a pointer. */
4347 static const char expected
[] = "ns::foo<char*>";
4348 /* Try both completion and non-completion modes. */
4349 static const bool completion_mode
[2] = {false, true};
4350 for (size_t i
= 0; i
< 2; i
++)
4352 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4353 completion_mode
[i
], EXPECT (expected
));
4354 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4355 completion_mode
[i
], EXPECT (expected
));
4357 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4358 completion_mode
[i
], EXPECT (expected
));
4359 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4360 completion_mode
[i
], EXPECT (expected
));
4365 /* Check method qualifiers are ignored. */
4366 static const char expected
[] = "ns::foo<char*>";
4367 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4368 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4369 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4370 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4371 CHECK_MATCH ("foo < char * > ( int ) const",
4372 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4373 CHECK_MATCH ("foo < char * > ( int ) &&",
4374 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4377 /* Test lookup names that don't match anything. */
4379 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4382 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4386 /* Some wild matching tests, exercising "(anonymous namespace)",
4387 which should not be confused with a parameter list. */
4389 static const char *syms
[] = {
4393 "A :: B :: C ( int )",
4398 for (const char *s
: syms
)
4400 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4401 EXPECT ("(anonymous namespace)::A::B::C"));
4406 static const char expected
[] = "ns2::tmpl<int>::foo2";
4407 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4409 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4413 SELF_CHECK (!any_mismatch
);
4422 test_mapped_index_find_name_component_bounds ();
4423 test_dw2_expand_symtabs_matching_symbol ();
4426 }} // namespace selftests::dw2_expand_symtabs_matching
4428 #endif /* GDB_SELF_TEST */
4430 /* If FILE_MATCHER is NULL or if PER_CU has
4431 dwarf2_per_cu_quick_data::MARK set (see
4432 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4433 EXPANSION_NOTIFY on it. */
4436 dw2_expand_symtabs_matching_one
4437 (struct dwarf2_per_cu_data
*per_cu
,
4438 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4439 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4441 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4443 bool symtab_was_null
4444 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4446 dw2_instantiate_symtab (per_cu
, false);
4448 if (expansion_notify
!= NULL
4450 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4451 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4455 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4456 matched, to expand corresponding CUs that were marked. IDX is the
4457 index of the symbol name that matched. */
4460 dw2_expand_marked_cus
4461 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4462 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4463 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4466 offset_type
*vec
, vec_len
, vec_idx
;
4467 bool global_seen
= false;
4468 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4470 vec
= (offset_type
*) (index
.constant_pool
4471 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4472 vec_len
= MAYBE_SWAP (vec
[0]);
4473 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4475 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4476 /* This value is only valid for index versions >= 7. */
4477 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4478 gdb_index_symbol_kind symbol_kind
=
4479 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4480 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4481 /* Only check the symbol attributes if they're present.
4482 Indices prior to version 7 don't record them,
4483 and indices >= 7 may elide them for certain symbols
4484 (gold does this). */
4487 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4489 /* Work around gold/15646. */
4492 if (!is_static
&& global_seen
)
4498 /* Only check the symbol's kind if it has one. */
4503 case VARIABLES_DOMAIN
:
4504 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4507 case FUNCTIONS_DOMAIN
:
4508 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4512 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4515 case MODULES_DOMAIN
:
4516 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4524 /* Don't crash on bad data. */
4525 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4526 + dwarf2_per_objfile
->all_type_units
.size ()))
4528 complaint (_(".gdb_index entry has bad CU index"
4530 objfile_name (dwarf2_per_objfile
->objfile
));
4534 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4535 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4540 /* If FILE_MATCHER is non-NULL, set all the
4541 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4542 that match FILE_MATCHER. */
4545 dw_expand_symtabs_matching_file_matcher
4546 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4547 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4549 if (file_matcher
== NULL
)
4552 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4554 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4556 NULL
, xcalloc
, xfree
));
4557 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4559 NULL
, xcalloc
, xfree
));
4561 /* The rule is CUs specify all the files, including those used by
4562 any TU, so there's no need to scan TUs here. */
4564 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4568 per_cu
->v
.quick
->mark
= 0;
4570 /* We only need to look at symtabs not already expanded. */
4571 if (per_cu
->v
.quick
->compunit_symtab
)
4574 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4575 if (file_data
== NULL
)
4578 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4580 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4582 per_cu
->v
.quick
->mark
= 1;
4586 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4588 const char *this_real_name
;
4590 if (file_matcher (file_data
->file_names
[j
], false))
4592 per_cu
->v
.quick
->mark
= 1;
4596 /* Before we invoke realpath, which can get expensive when many
4597 files are involved, do a quick comparison of the basenames. */
4598 if (!basenames_may_differ
4599 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4603 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4604 if (file_matcher (this_real_name
, false))
4606 per_cu
->v
.quick
->mark
= 1;
4611 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4612 ? visited_found
.get ()
4613 : visited_not_found
.get (),
4620 dw2_expand_symtabs_matching
4621 (struct objfile
*objfile
,
4622 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4623 const lookup_name_info
&lookup_name
,
4624 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4625 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4626 enum search_domain kind
)
4628 struct dwarf2_per_objfile
*dwarf2_per_objfile
4629 = get_dwarf2_per_objfile (objfile
);
4631 /* index_table is NULL if OBJF_READNOW. */
4632 if (!dwarf2_per_objfile
->index_table
)
4635 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4637 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4639 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4641 kind
, [&] (offset_type idx
)
4643 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4644 expansion_notify
, kind
);
4649 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4652 static struct compunit_symtab
*
4653 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4658 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4659 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4662 if (cust
->includes
== NULL
)
4665 for (i
= 0; cust
->includes
[i
]; ++i
)
4667 struct compunit_symtab
*s
= cust
->includes
[i
];
4669 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4677 static struct compunit_symtab
*
4678 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4679 struct bound_minimal_symbol msymbol
,
4681 struct obj_section
*section
,
4684 struct dwarf2_per_cu_data
*data
;
4685 struct compunit_symtab
*result
;
4687 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4690 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4691 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4692 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4696 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4697 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4698 paddress (get_objfile_arch (objfile
), pc
));
4701 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4704 gdb_assert (result
!= NULL
);
4709 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4710 void *data
, int need_fullname
)
4712 struct dwarf2_per_objfile
*dwarf2_per_objfile
4713 = get_dwarf2_per_objfile (objfile
);
4715 if (!dwarf2_per_objfile
->filenames_cache
)
4717 dwarf2_per_objfile
->filenames_cache
.emplace ();
4719 htab_up
visited (htab_create_alloc (10,
4720 htab_hash_pointer
, htab_eq_pointer
,
4721 NULL
, xcalloc
, xfree
));
4723 /* The rule is CUs specify all the files, including those used
4724 by any TU, so there's no need to scan TUs here. We can
4725 ignore file names coming from already-expanded CUs. */
4727 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4729 if (per_cu
->v
.quick
->compunit_symtab
)
4731 void **slot
= htab_find_slot (visited
.get (),
4732 per_cu
->v
.quick
->file_names
,
4735 *slot
= per_cu
->v
.quick
->file_names
;
4739 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4741 /* We only need to look at symtabs not already expanded. */
4742 if (per_cu
->v
.quick
->compunit_symtab
)
4745 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4746 if (file_data
== NULL
)
4749 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4752 /* Already visited. */
4757 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4759 const char *filename
= file_data
->file_names
[j
];
4760 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4765 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4767 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4770 this_real_name
= gdb_realpath (filename
);
4771 (*fun
) (filename
, this_real_name
.get (), data
);
4776 dw2_has_symbols (struct objfile
*objfile
)
4781 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4784 dw2_find_last_source_symtab
,
4785 dw2_forget_cached_source_info
,
4786 dw2_map_symtabs_matching_filename
,
4790 dw2_expand_symtabs_for_function
,
4791 dw2_expand_all_symtabs
,
4792 dw2_expand_symtabs_with_fullname
,
4793 dw2_map_matching_symbols
,
4794 dw2_expand_symtabs_matching
,
4795 dw2_find_pc_sect_compunit_symtab
,
4797 dw2_map_symbol_filenames
4800 /* DWARF-5 debug_names reader. */
4802 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4803 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4805 /* A helper function that reads the .debug_names section in SECTION
4806 and fills in MAP. FILENAME is the name of the file containing the
4807 section; it is used for error reporting.
4809 Returns true if all went well, false otherwise. */
4812 read_debug_names_from_section (struct objfile
*objfile
,
4813 const char *filename
,
4814 struct dwarf2_section_info
*section
,
4815 mapped_debug_names
&map
)
4817 if (section
->empty ())
4820 /* Older elfutils strip versions could keep the section in the main
4821 executable while splitting it for the separate debug info file. */
4822 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4825 section
->read (objfile
);
4827 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4829 const gdb_byte
*addr
= section
->buffer
;
4831 bfd
*const abfd
= section
->get_bfd_owner ();
4833 unsigned int bytes_read
;
4834 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4837 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4838 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4839 if (bytes_read
+ length
!= section
->size
)
4841 /* There may be multiple per-CU indices. */
4842 warning (_("Section .debug_names in %s length %s does not match "
4843 "section length %s, ignoring .debug_names."),
4844 filename
, plongest (bytes_read
+ length
),
4845 pulongest (section
->size
));
4849 /* The version number. */
4850 uint16_t version
= read_2_bytes (abfd
, addr
);
4854 warning (_("Section .debug_names in %s has unsupported version %d, "
4855 "ignoring .debug_names."),
4861 uint16_t padding
= read_2_bytes (abfd
, addr
);
4865 warning (_("Section .debug_names in %s has unsupported padding %d, "
4866 "ignoring .debug_names."),
4871 /* comp_unit_count - The number of CUs in the CU list. */
4872 map
.cu_count
= read_4_bytes (abfd
, addr
);
4875 /* local_type_unit_count - The number of TUs in the local TU
4877 map
.tu_count
= read_4_bytes (abfd
, addr
);
4880 /* foreign_type_unit_count - The number of TUs in the foreign TU
4882 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4884 if (foreign_tu_count
!= 0)
4886 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4887 "ignoring .debug_names."),
4888 filename
, static_cast<unsigned long> (foreign_tu_count
));
4892 /* bucket_count - The number of hash buckets in the hash lookup
4894 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4897 /* name_count - The number of unique names in the index. */
4898 map
.name_count
= read_4_bytes (abfd
, addr
);
4901 /* abbrev_table_size - The size in bytes of the abbreviations
4903 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4906 /* augmentation_string_size - The size in bytes of the augmentation
4907 string. This value is rounded up to a multiple of 4. */
4908 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4910 map
.augmentation_is_gdb
= ((augmentation_string_size
4911 == sizeof (dwarf5_augmentation
))
4912 && memcmp (addr
, dwarf5_augmentation
,
4913 sizeof (dwarf5_augmentation
)) == 0);
4914 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4915 addr
+= augmentation_string_size
;
4918 map
.cu_table_reordered
= addr
;
4919 addr
+= map
.cu_count
* map
.offset_size
;
4921 /* List of Local TUs */
4922 map
.tu_table_reordered
= addr
;
4923 addr
+= map
.tu_count
* map
.offset_size
;
4925 /* Hash Lookup Table */
4926 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4927 addr
+= map
.bucket_count
* 4;
4928 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4929 addr
+= map
.name_count
* 4;
4932 map
.name_table_string_offs_reordered
= addr
;
4933 addr
+= map
.name_count
* map
.offset_size
;
4934 map
.name_table_entry_offs_reordered
= addr
;
4935 addr
+= map
.name_count
* map
.offset_size
;
4937 const gdb_byte
*abbrev_table_start
= addr
;
4940 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4945 const auto insertpair
4946 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4947 if (!insertpair
.second
)
4949 warning (_("Section .debug_names in %s has duplicate index %s, "
4950 "ignoring .debug_names."),
4951 filename
, pulongest (index_num
));
4954 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4955 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4960 mapped_debug_names::index_val::attr attr
;
4961 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4963 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4965 if (attr
.form
== DW_FORM_implicit_const
)
4967 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4971 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4973 indexval
.attr_vec
.push_back (std::move (attr
));
4976 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4978 warning (_("Section .debug_names in %s has abbreviation_table "
4979 "of size %s vs. written as %u, ignoring .debug_names."),
4980 filename
, plongest (addr
- abbrev_table_start
),
4984 map
.entry_pool
= addr
;
4989 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4993 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4994 const mapped_debug_names
&map
,
4995 dwarf2_section_info
§ion
,
4998 sect_offset sect_off_prev
;
4999 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5001 sect_offset sect_off_next
;
5002 if (i
< map
.cu_count
)
5005 = (sect_offset
) (extract_unsigned_integer
5006 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5008 map
.dwarf5_byte_order
));
5011 sect_off_next
= (sect_offset
) section
.size
;
5014 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5015 dwarf2_per_cu_data
*per_cu
5016 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5017 sect_off_prev
, length
);
5018 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5020 sect_off_prev
= sect_off_next
;
5024 /* Read the CU list from the mapped index, and use it to create all
5025 the CU objects for this dwarf2_per_objfile. */
5028 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5029 const mapped_debug_names
&map
,
5030 const mapped_debug_names
&dwz_map
)
5032 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5033 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5035 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5036 dwarf2_per_objfile
->info
,
5037 false /* is_dwz */);
5039 if (dwz_map
.cu_count
== 0)
5042 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5043 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5047 /* Read .debug_names. If everything went ok, initialize the "quick"
5048 elements of all the CUs and return true. Otherwise, return false. */
5051 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5053 std::unique_ptr
<mapped_debug_names
> map
5054 (new mapped_debug_names (dwarf2_per_objfile
));
5055 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5056 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5058 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5059 &dwarf2_per_objfile
->debug_names
,
5063 /* Don't use the index if it's empty. */
5064 if (map
->name_count
== 0)
5067 /* If there is a .dwz file, read it so we can get its CU list as
5069 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5072 if (!read_debug_names_from_section (objfile
,
5073 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5074 &dwz
->debug_names
, dwz_map
))
5076 warning (_("could not read '.debug_names' section from %s; skipping"),
5077 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5082 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5084 if (map
->tu_count
!= 0)
5086 /* We can only handle a single .debug_types when we have an
5088 if (dwarf2_per_objfile
->types
.size () != 1)
5091 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5093 create_signatured_type_table_from_debug_names
5094 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5097 create_addrmap_from_aranges (dwarf2_per_objfile
,
5098 &dwarf2_per_objfile
->debug_aranges
);
5100 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5101 dwarf2_per_objfile
->using_index
= 1;
5102 dwarf2_per_objfile
->quick_file_names_table
=
5103 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5108 /* Type used to manage iterating over all CUs looking for a symbol for
5111 class dw2_debug_names_iterator
5114 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5115 gdb::optional
<block_enum
> block_index
,
5118 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5119 m_addr (find_vec_in_debug_names (map
, name
))
5122 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5123 search_domain search
, uint32_t namei
)
5126 m_addr (find_vec_in_debug_names (map
, namei
))
5129 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5130 block_enum block_index
, domain_enum domain
,
5132 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5133 m_addr (find_vec_in_debug_names (map
, namei
))
5136 /* Return the next matching CU or NULL if there are no more. */
5137 dwarf2_per_cu_data
*next ();
5140 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5142 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5145 /* The internalized form of .debug_names. */
5146 const mapped_debug_names
&m_map
;
5148 /* If set, only look for symbols that match that block. Valid values are
5149 GLOBAL_BLOCK and STATIC_BLOCK. */
5150 const gdb::optional
<block_enum
> m_block_index
;
5152 /* The kind of symbol we're looking for. */
5153 const domain_enum m_domain
= UNDEF_DOMAIN
;
5154 const search_domain m_search
= ALL_DOMAIN
;
5156 /* The list of CUs from the index entry of the symbol, or NULL if
5158 const gdb_byte
*m_addr
;
5162 mapped_debug_names::namei_to_name (uint32_t namei
) const
5164 const ULONGEST namei_string_offs
5165 = extract_unsigned_integer ((name_table_string_offs_reordered
5166 + namei
* offset_size
),
5169 return read_indirect_string_at_offset
5170 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5173 /* Find a slot in .debug_names for the object named NAME. If NAME is
5174 found, return pointer to its pool data. If NAME cannot be found,
5178 dw2_debug_names_iterator::find_vec_in_debug_names
5179 (const mapped_debug_names
&map
, const char *name
)
5181 int (*cmp
) (const char *, const char *);
5183 gdb::unique_xmalloc_ptr
<char> without_params
;
5184 if (current_language
->la_language
== language_cplus
5185 || current_language
->la_language
== language_fortran
5186 || current_language
->la_language
== language_d
)
5188 /* NAME is already canonical. Drop any qualifiers as
5189 .debug_names does not contain any. */
5191 if (strchr (name
, '(') != NULL
)
5193 without_params
= cp_remove_params (name
);
5194 if (without_params
!= NULL
)
5195 name
= without_params
.get ();
5199 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5201 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5203 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5204 (map
.bucket_table_reordered
5205 + (full_hash
% map
.bucket_count
)), 4,
5206 map
.dwarf5_byte_order
);
5210 if (namei
>= map
.name_count
)
5212 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5214 namei
, map
.name_count
,
5215 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5221 const uint32_t namei_full_hash
5222 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5223 (map
.hash_table_reordered
+ namei
), 4,
5224 map
.dwarf5_byte_order
);
5225 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5228 if (full_hash
== namei_full_hash
)
5230 const char *const namei_string
= map
.namei_to_name (namei
);
5232 #if 0 /* An expensive sanity check. */
5233 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5235 complaint (_("Wrong .debug_names hash for string at index %u "
5237 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5242 if (cmp (namei_string
, name
) == 0)
5244 const ULONGEST namei_entry_offs
5245 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5246 + namei
* map
.offset_size
),
5247 map
.offset_size
, map
.dwarf5_byte_order
);
5248 return map
.entry_pool
+ namei_entry_offs
;
5253 if (namei
>= map
.name_count
)
5259 dw2_debug_names_iterator::find_vec_in_debug_names
5260 (const mapped_debug_names
&map
, uint32_t namei
)
5262 if (namei
>= map
.name_count
)
5264 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5266 namei
, map
.name_count
,
5267 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5271 const ULONGEST namei_entry_offs
5272 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5273 + namei
* map
.offset_size
),
5274 map
.offset_size
, map
.dwarf5_byte_order
);
5275 return map
.entry_pool
+ namei_entry_offs
;
5278 /* See dw2_debug_names_iterator. */
5280 dwarf2_per_cu_data
*
5281 dw2_debug_names_iterator::next ()
5286 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5287 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5288 bfd
*const abfd
= objfile
->obfd
;
5292 unsigned int bytes_read
;
5293 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5294 m_addr
+= bytes_read
;
5298 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5299 if (indexval_it
== m_map
.abbrev_map
.cend ())
5301 complaint (_("Wrong .debug_names undefined abbrev code %s "
5303 pulongest (abbrev
), objfile_name (objfile
));
5306 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5307 enum class symbol_linkage
{
5311 } symbol_linkage_
= symbol_linkage::unknown
;
5312 dwarf2_per_cu_data
*per_cu
= NULL
;
5313 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5318 case DW_FORM_implicit_const
:
5319 ull
= attr
.implicit_const
;
5321 case DW_FORM_flag_present
:
5325 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5326 m_addr
+= bytes_read
;
5329 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5330 dwarf_form_name (attr
.form
),
5331 objfile_name (objfile
));
5334 switch (attr
.dw_idx
)
5336 case DW_IDX_compile_unit
:
5337 /* Don't crash on bad data. */
5338 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5340 complaint (_(".debug_names entry has bad CU index %s"
5343 objfile_name (dwarf2_per_objfile
->objfile
));
5346 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5348 case DW_IDX_type_unit
:
5349 /* Don't crash on bad data. */
5350 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5352 complaint (_(".debug_names entry has bad TU index %s"
5355 objfile_name (dwarf2_per_objfile
->objfile
));
5358 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5360 case DW_IDX_GNU_internal
:
5361 if (!m_map
.augmentation_is_gdb
)
5363 symbol_linkage_
= symbol_linkage::static_
;
5365 case DW_IDX_GNU_external
:
5366 if (!m_map
.augmentation_is_gdb
)
5368 symbol_linkage_
= symbol_linkage::extern_
;
5373 /* Skip if already read in. */
5374 if (per_cu
->v
.quick
->compunit_symtab
)
5377 /* Check static vs global. */
5378 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5380 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5381 const bool symbol_is_static
=
5382 symbol_linkage_
== symbol_linkage::static_
;
5383 if (want_static
!= symbol_is_static
)
5387 /* Match dw2_symtab_iter_next, symbol_kind
5388 and debug_names::psymbol_tag. */
5392 switch (indexval
.dwarf_tag
)
5394 case DW_TAG_variable
:
5395 case DW_TAG_subprogram
:
5396 /* Some types are also in VAR_DOMAIN. */
5397 case DW_TAG_typedef
:
5398 case DW_TAG_structure_type
:
5405 switch (indexval
.dwarf_tag
)
5407 case DW_TAG_typedef
:
5408 case DW_TAG_structure_type
:
5415 switch (indexval
.dwarf_tag
)
5418 case DW_TAG_variable
:
5425 switch (indexval
.dwarf_tag
)
5437 /* Match dw2_expand_symtabs_matching, symbol_kind and
5438 debug_names::psymbol_tag. */
5441 case VARIABLES_DOMAIN
:
5442 switch (indexval
.dwarf_tag
)
5444 case DW_TAG_variable
:
5450 case FUNCTIONS_DOMAIN
:
5451 switch (indexval
.dwarf_tag
)
5453 case DW_TAG_subprogram
:
5460 switch (indexval
.dwarf_tag
)
5462 case DW_TAG_typedef
:
5463 case DW_TAG_structure_type
:
5469 case MODULES_DOMAIN
:
5470 switch (indexval
.dwarf_tag
)
5484 static struct compunit_symtab
*
5485 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5486 const char *name
, domain_enum domain
)
5488 struct dwarf2_per_objfile
*dwarf2_per_objfile
5489 = get_dwarf2_per_objfile (objfile
);
5491 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5494 /* index is NULL if OBJF_READNOW. */
5497 const auto &map
= *mapp
;
5499 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5501 struct compunit_symtab
*stab_best
= NULL
;
5502 struct dwarf2_per_cu_data
*per_cu
;
5503 while ((per_cu
= iter
.next ()) != NULL
)
5505 struct symbol
*sym
, *with_opaque
= NULL
;
5506 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5507 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5508 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5510 sym
= block_find_symbol (block
, name
, domain
,
5511 block_find_non_opaque_type_preferred
,
5514 /* Some caution must be observed with overloaded functions and
5515 methods, since the index will not contain any overload
5516 information (but NAME might contain it). */
5519 && strcmp_iw (sym
->search_name (), name
) == 0)
5521 if (with_opaque
!= NULL
5522 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5525 /* Keep looking through other CUs. */
5531 /* This dumps minimal information about .debug_names. It is called
5532 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5533 uses this to verify that .debug_names has been loaded. */
5536 dw2_debug_names_dump (struct objfile
*objfile
)
5538 struct dwarf2_per_objfile
*dwarf2_per_objfile
5539 = get_dwarf2_per_objfile (objfile
);
5541 gdb_assert (dwarf2_per_objfile
->using_index
);
5542 printf_filtered (".debug_names:");
5543 if (dwarf2_per_objfile
->debug_names_table
)
5544 printf_filtered (" exists\n");
5546 printf_filtered (" faked for \"readnow\"\n");
5547 printf_filtered ("\n");
5551 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5552 const char *func_name
)
5554 struct dwarf2_per_objfile
*dwarf2_per_objfile
5555 = get_dwarf2_per_objfile (objfile
);
5557 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5558 if (dwarf2_per_objfile
->debug_names_table
)
5560 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5562 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5564 struct dwarf2_per_cu_data
*per_cu
;
5565 while ((per_cu
= iter
.next ()) != NULL
)
5566 dw2_instantiate_symtab (per_cu
, false);
5571 dw2_debug_names_map_matching_symbols
5572 (struct objfile
*objfile
,
5573 const lookup_name_info
&name
, domain_enum domain
,
5575 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5576 symbol_compare_ftype
*ordered_compare
)
5578 struct dwarf2_per_objfile
*dwarf2_per_objfile
5579 = get_dwarf2_per_objfile (objfile
);
5581 /* debug_names_table is NULL if OBJF_READNOW. */
5582 if (!dwarf2_per_objfile
->debug_names_table
)
5585 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5586 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5588 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5589 auto matcher
= [&] (const char *symname
)
5591 if (ordered_compare
== nullptr)
5593 return ordered_compare (symname
, match_name
) == 0;
5596 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5597 [&] (offset_type namei
)
5599 /* The name was matched, now expand corresponding CUs that were
5601 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5603 struct dwarf2_per_cu_data
*per_cu
;
5604 while ((per_cu
= iter
.next ()) != NULL
)
5605 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5609 /* It's a shame we couldn't do this inside the
5610 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5611 that have already been expanded. Instead, this loop matches what
5612 the psymtab code does. */
5613 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5615 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5616 if (cust
!= nullptr)
5618 const struct block
*block
5619 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5620 if (!iterate_over_symbols_terminated (block
, name
,
5628 dw2_debug_names_expand_symtabs_matching
5629 (struct objfile
*objfile
,
5630 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5631 const lookup_name_info
&lookup_name
,
5632 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5633 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5634 enum search_domain kind
)
5636 struct dwarf2_per_objfile
*dwarf2_per_objfile
5637 = get_dwarf2_per_objfile (objfile
);
5639 /* debug_names_table is NULL if OBJF_READNOW. */
5640 if (!dwarf2_per_objfile
->debug_names_table
)
5643 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5645 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5647 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5649 kind
, [&] (offset_type namei
)
5651 /* The name was matched, now expand corresponding CUs that were
5653 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5655 struct dwarf2_per_cu_data
*per_cu
;
5656 while ((per_cu
= iter
.next ()) != NULL
)
5657 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5663 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5666 dw2_find_last_source_symtab
,
5667 dw2_forget_cached_source_info
,
5668 dw2_map_symtabs_matching_filename
,
5669 dw2_debug_names_lookup_symbol
,
5671 dw2_debug_names_dump
,
5672 dw2_debug_names_expand_symtabs_for_function
,
5673 dw2_expand_all_symtabs
,
5674 dw2_expand_symtabs_with_fullname
,
5675 dw2_debug_names_map_matching_symbols
,
5676 dw2_debug_names_expand_symtabs_matching
,
5677 dw2_find_pc_sect_compunit_symtab
,
5679 dw2_map_symbol_filenames
5682 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5683 to either a dwarf2_per_objfile or dwz_file object. */
5685 template <typename T
>
5686 static gdb::array_view
<const gdb_byte
>
5687 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5689 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5691 if (section
->empty ())
5694 /* Older elfutils strip versions could keep the section in the main
5695 executable while splitting it for the separate debug info file. */
5696 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5699 section
->read (obj
);
5701 /* dwarf2_section_info::size is a bfd_size_type, while
5702 gdb::array_view works with size_t. On 32-bit hosts, with
5703 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5704 is 32-bit. So we need an explicit narrowing conversion here.
5705 This is fine, because it's impossible to allocate or mmap an
5706 array/buffer larger than what size_t can represent. */
5707 return gdb::make_array_view (section
->buffer
, section
->size
);
5710 /* Lookup the index cache for the contents of the index associated to
5713 static gdb::array_view
<const gdb_byte
>
5714 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5716 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5717 if (build_id
== nullptr)
5720 return global_index_cache
.lookup_gdb_index (build_id
,
5721 &dwarf2_obj
->index_cache_res
);
5724 /* Same as the above, but for DWZ. */
5726 static gdb::array_view
<const gdb_byte
>
5727 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5729 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5730 if (build_id
== nullptr)
5733 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5736 /* See symfile.h. */
5739 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5741 struct dwarf2_per_objfile
*dwarf2_per_objfile
5742 = get_dwarf2_per_objfile (objfile
);
5744 /* If we're about to read full symbols, don't bother with the
5745 indices. In this case we also don't care if some other debug
5746 format is making psymtabs, because they are all about to be
5748 if ((objfile
->flags
& OBJF_READNOW
))
5750 dwarf2_per_objfile
->using_index
= 1;
5751 create_all_comp_units (dwarf2_per_objfile
);
5752 create_all_type_units (dwarf2_per_objfile
);
5753 dwarf2_per_objfile
->quick_file_names_table
5754 = create_quick_file_names_table
5755 (dwarf2_per_objfile
->all_comp_units
.size ());
5757 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5758 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5760 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5762 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5763 struct dwarf2_per_cu_quick_data
);
5766 /* Return 1 so that gdb sees the "quick" functions. However,
5767 these functions will be no-ops because we will have expanded
5769 *index_kind
= dw_index_kind::GDB_INDEX
;
5773 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5775 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5779 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5780 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5781 get_gdb_index_contents_from_section
<dwz_file
>))
5783 *index_kind
= dw_index_kind::GDB_INDEX
;
5787 /* ... otherwise, try to find the index in the index cache. */
5788 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5789 get_gdb_index_contents_from_cache
,
5790 get_gdb_index_contents_from_cache_dwz
))
5792 global_index_cache
.hit ();
5793 *index_kind
= dw_index_kind::GDB_INDEX
;
5797 global_index_cache
.miss ();
5803 /* Build a partial symbol table. */
5806 dwarf2_build_psymtabs (struct objfile
*objfile
)
5808 struct dwarf2_per_objfile
*dwarf2_per_objfile
5809 = get_dwarf2_per_objfile (objfile
);
5811 init_psymbol_list (objfile
, 1024);
5815 /* This isn't really ideal: all the data we allocate on the
5816 objfile's obstack is still uselessly kept around. However,
5817 freeing it seems unsafe. */
5818 psymtab_discarder
psymtabs (objfile
);
5819 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5822 /* (maybe) store an index in the cache. */
5823 global_index_cache
.store (dwarf2_per_objfile
);
5825 catch (const gdb_exception_error
&except
)
5827 exception_print (gdb_stderr
, except
);
5831 /* Find the base address of the compilation unit for range lists and
5832 location lists. It will normally be specified by DW_AT_low_pc.
5833 In DWARF-3 draft 4, the base address could be overridden by
5834 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5835 compilation units with discontinuous ranges. */
5838 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5840 struct attribute
*attr
;
5843 cu
->base_address
= 0;
5845 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5846 if (attr
!= nullptr)
5848 cu
->base_address
= attr
->value_as_address ();
5853 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5854 if (attr
!= nullptr)
5856 cu
->base_address
= attr
->value_as_address ();
5862 /* Helper function that returns the proper abbrev section for
5865 static struct dwarf2_section_info
*
5866 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5868 struct dwarf2_section_info
*abbrev
;
5869 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5871 if (this_cu
->is_dwz
)
5872 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5874 abbrev
= &dwarf2_per_objfile
->abbrev
;
5879 /* Fetch the abbreviation table offset from a comp or type unit header. */
5882 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5883 struct dwarf2_section_info
*section
,
5884 sect_offset sect_off
)
5886 bfd
*abfd
= section
->get_bfd_owner ();
5887 const gdb_byte
*info_ptr
;
5888 unsigned int initial_length_size
, offset_size
;
5891 section
->read (dwarf2_per_objfile
->objfile
);
5892 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5893 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5894 offset_size
= initial_length_size
== 4 ? 4 : 8;
5895 info_ptr
+= initial_length_size
;
5897 version
= read_2_bytes (abfd
, info_ptr
);
5901 /* Skip unit type and address size. */
5905 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5908 /* Allocate a new partial symtab for file named NAME and mark this new
5909 partial symtab as being an include of PST. */
5912 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5913 struct objfile
*objfile
)
5915 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
5917 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5919 /* It shares objfile->objfile_obstack. */
5920 subpst
->dirname
= pst
->dirname
;
5923 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5924 subpst
->dependencies
[0] = pst
;
5925 subpst
->number_of_dependencies
= 1;
5927 /* No private part is necessary for include psymtabs. This property
5928 can be used to differentiate between such include psymtabs and
5929 the regular ones. */
5930 subpst
->per_cu_data
= nullptr;
5933 /* Read the Line Number Program data and extract the list of files
5934 included by the source file represented by PST. Build an include
5935 partial symtab for each of these included files. */
5938 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5939 struct die_info
*die
,
5940 dwarf2_psymtab
*pst
)
5943 struct attribute
*attr
;
5945 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5946 if (attr
!= nullptr)
5947 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5949 return; /* No linetable, so no includes. */
5951 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5952 that we pass in the raw text_low here; that is ok because we're
5953 only decoding the line table to make include partial symtabs, and
5954 so the addresses aren't really used. */
5955 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5956 pst
->raw_text_low (), 1);
5960 hash_signatured_type (const void *item
)
5962 const struct signatured_type
*sig_type
5963 = (const struct signatured_type
*) item
;
5965 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5966 return sig_type
->signature
;
5970 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5972 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5973 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5975 return lhs
->signature
== rhs
->signature
;
5978 /* Allocate a hash table for signatured types. */
5981 allocate_signatured_type_table (struct objfile
*objfile
)
5983 return htab_up (htab_create_alloc (41,
5984 hash_signatured_type
,
5986 NULL
, xcalloc
, xfree
));
5989 /* A helper function to add a signatured type CU to a table. */
5992 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5994 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5995 std::vector
<signatured_type
*> *all_type_units
5996 = (std::vector
<signatured_type
*> *) datum
;
5998 all_type_units
->push_back (sigt
);
6003 /* A helper for create_debug_types_hash_table. Read types from SECTION
6004 and fill them into TYPES_HTAB. It will process only type units,
6005 therefore DW_UT_type. */
6008 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6009 struct dwo_file
*dwo_file
,
6010 dwarf2_section_info
*section
, htab_up
&types_htab
,
6011 rcuh_kind section_kind
)
6013 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6014 struct dwarf2_section_info
*abbrev_section
;
6016 const gdb_byte
*info_ptr
, *end_ptr
;
6018 abbrev_section
= (dwo_file
!= NULL
6019 ? &dwo_file
->sections
.abbrev
6020 : &dwarf2_per_objfile
->abbrev
);
6022 if (dwarf_read_debug
)
6023 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6024 section
->get_name (),
6025 abbrev_section
->get_file_name ());
6027 section
->read (objfile
);
6028 info_ptr
= section
->buffer
;
6030 if (info_ptr
== NULL
)
6033 /* We can't set abfd until now because the section may be empty or
6034 not present, in which case the bfd is unknown. */
6035 abfd
= section
->get_bfd_owner ();
6037 /* We don't use cutu_reader here because we don't need to read
6038 any dies: the signature is in the header. */
6040 end_ptr
= info_ptr
+ section
->size
;
6041 while (info_ptr
< end_ptr
)
6043 struct signatured_type
*sig_type
;
6044 struct dwo_unit
*dwo_tu
;
6046 const gdb_byte
*ptr
= info_ptr
;
6047 struct comp_unit_head header
;
6048 unsigned int length
;
6050 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6052 /* Initialize it due to a false compiler warning. */
6053 header
.signature
= -1;
6054 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6056 /* We need to read the type's signature in order to build the hash
6057 table, but we don't need anything else just yet. */
6059 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6060 abbrev_section
, ptr
, section_kind
);
6062 length
= header
.get_length ();
6064 /* Skip dummy type units. */
6065 if (ptr
>= info_ptr
+ length
6066 || peek_abbrev_code (abfd
, ptr
) == 0
6067 || header
.unit_type
!= DW_UT_type
)
6073 if (types_htab
== NULL
)
6076 types_htab
= allocate_dwo_unit_table (objfile
);
6078 types_htab
= allocate_signatured_type_table (objfile
);
6084 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6086 dwo_tu
->dwo_file
= dwo_file
;
6087 dwo_tu
->signature
= header
.signature
;
6088 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6089 dwo_tu
->section
= section
;
6090 dwo_tu
->sect_off
= sect_off
;
6091 dwo_tu
->length
= length
;
6095 /* N.B.: type_offset is not usable if this type uses a DWO file.
6096 The real type_offset is in the DWO file. */
6098 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6099 struct signatured_type
);
6100 sig_type
->signature
= header
.signature
;
6101 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6102 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6103 sig_type
->per_cu
.is_debug_types
= 1;
6104 sig_type
->per_cu
.section
= section
;
6105 sig_type
->per_cu
.sect_off
= sect_off
;
6106 sig_type
->per_cu
.length
= length
;
6109 slot
= htab_find_slot (types_htab
.get (),
6110 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6112 gdb_assert (slot
!= NULL
);
6115 sect_offset dup_sect_off
;
6119 const struct dwo_unit
*dup_tu
6120 = (const struct dwo_unit
*) *slot
;
6122 dup_sect_off
= dup_tu
->sect_off
;
6126 const struct signatured_type
*dup_tu
6127 = (const struct signatured_type
*) *slot
;
6129 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6132 complaint (_("debug type entry at offset %s is duplicate to"
6133 " the entry at offset %s, signature %s"),
6134 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6135 hex_string (header
.signature
));
6137 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6139 if (dwarf_read_debug
> 1)
6140 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6141 sect_offset_str (sect_off
),
6142 hex_string (header
.signature
));
6148 /* Create the hash table of all entries in the .debug_types
6149 (or .debug_types.dwo) section(s).
6150 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6151 otherwise it is NULL.
6153 The result is a pointer to the hash table or NULL if there are no types.
6155 Note: This function processes DWO files only, not DWP files. */
6158 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6159 struct dwo_file
*dwo_file
,
6160 gdb::array_view
<dwarf2_section_info
> type_sections
,
6161 htab_up
&types_htab
)
6163 for (dwarf2_section_info
§ion
: type_sections
)
6164 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6165 types_htab
, rcuh_kind::TYPE
);
6168 /* Create the hash table of all entries in the .debug_types section,
6169 and initialize all_type_units.
6170 The result is zero if there is an error (e.g. missing .debug_types section),
6171 otherwise non-zero. */
6174 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6178 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6179 &dwarf2_per_objfile
->info
, types_htab
,
6180 rcuh_kind::COMPILE
);
6181 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6182 dwarf2_per_objfile
->types
, types_htab
);
6183 if (types_htab
== NULL
)
6185 dwarf2_per_objfile
->signatured_types
= NULL
;
6189 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6191 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6192 dwarf2_per_objfile
->all_type_units
.reserve
6193 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6195 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6196 add_signatured_type_cu_to_table
,
6197 &dwarf2_per_objfile
->all_type_units
);
6202 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6203 If SLOT is non-NULL, it is the entry to use in the hash table.
6204 Otherwise we find one. */
6206 static struct signatured_type
*
6207 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6210 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6212 if (dwarf2_per_objfile
->all_type_units
.size ()
6213 == dwarf2_per_objfile
->all_type_units
.capacity ())
6214 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6216 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6217 struct signatured_type
);
6219 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6220 sig_type
->signature
= sig
;
6221 sig_type
->per_cu
.is_debug_types
= 1;
6222 if (dwarf2_per_objfile
->using_index
)
6224 sig_type
->per_cu
.v
.quick
=
6225 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6226 struct dwarf2_per_cu_quick_data
);
6231 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6234 gdb_assert (*slot
== NULL
);
6236 /* The rest of sig_type must be filled in by the caller. */
6240 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6241 Fill in SIG_ENTRY with DWO_ENTRY. */
6244 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6245 struct signatured_type
*sig_entry
,
6246 struct dwo_unit
*dwo_entry
)
6248 /* Make sure we're not clobbering something we don't expect to. */
6249 gdb_assert (! sig_entry
->per_cu
.queued
);
6250 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6251 if (dwarf2_per_objfile
->using_index
)
6253 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6254 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6257 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6258 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6259 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6260 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6261 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6263 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6264 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6265 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6266 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6267 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6268 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6269 sig_entry
->dwo_unit
= dwo_entry
;
6272 /* Subroutine of lookup_signatured_type.
6273 If we haven't read the TU yet, create the signatured_type data structure
6274 for a TU to be read in directly from a DWO file, bypassing the stub.
6275 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6276 using .gdb_index, then when reading a CU we want to stay in the DWO file
6277 containing that CU. Otherwise we could end up reading several other DWO
6278 files (due to comdat folding) to process the transitive closure of all the
6279 mentioned TUs, and that can be slow. The current DWO file will have every
6280 type signature that it needs.
6281 We only do this for .gdb_index because in the psymtab case we already have
6282 to read all the DWOs to build the type unit groups. */
6284 static struct signatured_type
*
6285 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6287 struct dwarf2_per_objfile
*dwarf2_per_objfile
6288 = cu
->per_cu
->dwarf2_per_objfile
;
6289 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6290 struct dwo_file
*dwo_file
;
6291 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6292 struct signatured_type find_sig_entry
, *sig_entry
;
6295 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6297 /* If TU skeletons have been removed then we may not have read in any
6299 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6301 dwarf2_per_objfile
->signatured_types
6302 = allocate_signatured_type_table (objfile
);
6305 /* We only ever need to read in one copy of a signatured type.
6306 Use the global signatured_types array to do our own comdat-folding
6307 of types. If this is the first time we're reading this TU, and
6308 the TU has an entry in .gdb_index, replace the recorded data from
6309 .gdb_index with this TU. */
6311 find_sig_entry
.signature
= sig
;
6312 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6313 &find_sig_entry
, INSERT
);
6314 sig_entry
= (struct signatured_type
*) *slot
;
6316 /* We can get here with the TU already read, *or* in the process of being
6317 read. Don't reassign the global entry to point to this DWO if that's
6318 the case. Also note that if the TU is already being read, it may not
6319 have come from a DWO, the program may be a mix of Fission-compiled
6320 code and non-Fission-compiled code. */
6322 /* Have we already tried to read this TU?
6323 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6324 needn't exist in the global table yet). */
6325 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6328 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6329 dwo_unit of the TU itself. */
6330 dwo_file
= cu
->dwo_unit
->dwo_file
;
6332 /* Ok, this is the first time we're reading this TU. */
6333 if (dwo_file
->tus
== NULL
)
6335 find_dwo_entry
.signature
= sig
;
6336 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6338 if (dwo_entry
== NULL
)
6341 /* If the global table doesn't have an entry for this TU, add one. */
6342 if (sig_entry
== NULL
)
6343 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6345 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6346 sig_entry
->per_cu
.tu_read
= 1;
6350 /* Subroutine of lookup_signatured_type.
6351 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6352 then try the DWP file. If the TU stub (skeleton) has been removed then
6353 it won't be in .gdb_index. */
6355 static struct signatured_type
*
6356 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6358 struct dwarf2_per_objfile
*dwarf2_per_objfile
6359 = cu
->per_cu
->dwarf2_per_objfile
;
6360 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6361 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6362 struct dwo_unit
*dwo_entry
;
6363 struct signatured_type find_sig_entry
, *sig_entry
;
6366 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6367 gdb_assert (dwp_file
!= NULL
);
6369 /* If TU skeletons have been removed then we may not have read in any
6371 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6373 dwarf2_per_objfile
->signatured_types
6374 = allocate_signatured_type_table (objfile
);
6377 find_sig_entry
.signature
= sig
;
6378 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6379 &find_sig_entry
, INSERT
);
6380 sig_entry
= (struct signatured_type
*) *slot
;
6382 /* Have we already tried to read this TU?
6383 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6384 needn't exist in the global table yet). */
6385 if (sig_entry
!= NULL
)
6388 if (dwp_file
->tus
== NULL
)
6390 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6391 sig
, 1 /* is_debug_types */);
6392 if (dwo_entry
== NULL
)
6395 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6396 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6401 /* Lookup a signature based type for DW_FORM_ref_sig8.
6402 Returns NULL if signature SIG is not present in the table.
6403 It is up to the caller to complain about this. */
6405 static struct signatured_type
*
6406 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6408 struct dwarf2_per_objfile
*dwarf2_per_objfile
6409 = cu
->per_cu
->dwarf2_per_objfile
;
6412 && dwarf2_per_objfile
->using_index
)
6414 /* We're in a DWO/DWP file, and we're using .gdb_index.
6415 These cases require special processing. */
6416 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6417 return lookup_dwo_signatured_type (cu
, sig
);
6419 return lookup_dwp_signatured_type (cu
, sig
);
6423 struct signatured_type find_entry
, *entry
;
6425 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6427 find_entry
.signature
= sig
;
6428 entry
= ((struct signatured_type
*)
6429 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6435 /* Return the address base of the compile unit, which, if exists, is stored
6436 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6437 static gdb::optional
<ULONGEST
>
6438 lookup_addr_base (struct die_info
*comp_unit_die
)
6440 struct attribute
*attr
;
6441 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6442 if (attr
== nullptr)
6443 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6444 if (attr
== nullptr)
6445 return gdb::optional
<ULONGEST
> ();
6446 return DW_UNSND (attr
);
6449 /* Return range lists base of the compile unit, which, if exists, is stored
6450 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6452 lookup_ranges_base (struct die_info
*comp_unit_die
)
6454 struct attribute
*attr
;
6455 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6456 if (attr
== nullptr)
6457 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6458 if (attr
== nullptr)
6460 return DW_UNSND (attr
);
6463 /* Low level DIE reading support. */
6465 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6468 init_cu_die_reader (struct die_reader_specs
*reader
,
6469 struct dwarf2_cu
*cu
,
6470 struct dwarf2_section_info
*section
,
6471 struct dwo_file
*dwo_file
,
6472 struct abbrev_table
*abbrev_table
)
6474 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6475 reader
->abfd
= section
->get_bfd_owner ();
6477 reader
->dwo_file
= dwo_file
;
6478 reader
->die_section
= section
;
6479 reader
->buffer
= section
->buffer
;
6480 reader
->buffer_end
= section
->buffer
+ section
->size
;
6481 reader
->abbrev_table
= abbrev_table
;
6484 /* Subroutine of cutu_reader to simplify it.
6485 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6486 There's just a lot of work to do, and cutu_reader is big enough
6489 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6490 from it to the DIE in the DWO. If NULL we are skipping the stub.
6491 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6492 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6493 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6494 STUB_COMP_DIR may be non-NULL.
6495 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6496 are filled in with the info of the DIE from the DWO file.
6497 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6498 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6499 kept around for at least as long as *RESULT_READER.
6501 The result is non-zero if a valid (non-dummy) DIE was found. */
6504 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6505 struct dwo_unit
*dwo_unit
,
6506 struct die_info
*stub_comp_unit_die
,
6507 const char *stub_comp_dir
,
6508 struct die_reader_specs
*result_reader
,
6509 const gdb_byte
**result_info_ptr
,
6510 struct die_info
**result_comp_unit_die
,
6511 abbrev_table_up
*result_dwo_abbrev_table
)
6513 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6514 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6515 struct dwarf2_cu
*cu
= this_cu
->cu
;
6517 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6518 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6519 int i
,num_extra_attrs
;
6520 struct dwarf2_section_info
*dwo_abbrev_section
;
6521 struct die_info
*comp_unit_die
;
6523 /* At most one of these may be provided. */
6524 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6526 /* These attributes aren't processed until later:
6527 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6528 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6529 referenced later. However, these attributes are found in the stub
6530 which we won't have later. In order to not impose this complication
6531 on the rest of the code, we read them here and copy them to the
6540 if (stub_comp_unit_die
!= NULL
)
6542 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6544 if (! this_cu
->is_debug_types
)
6545 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6546 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6547 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6548 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6549 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6551 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6553 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6554 here (if needed). We need the value before we can process
6556 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6558 else if (stub_comp_dir
!= NULL
)
6560 /* Reconstruct the comp_dir attribute to simplify the code below. */
6561 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6562 comp_dir
->name
= DW_AT_comp_dir
;
6563 comp_dir
->form
= DW_FORM_string
;
6564 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6565 DW_STRING (comp_dir
) = stub_comp_dir
;
6568 /* Set up for reading the DWO CU/TU. */
6569 cu
->dwo_unit
= dwo_unit
;
6570 dwarf2_section_info
*section
= dwo_unit
->section
;
6571 section
->read (objfile
);
6572 abfd
= section
->get_bfd_owner ();
6573 begin_info_ptr
= info_ptr
= (section
->buffer
6574 + to_underlying (dwo_unit
->sect_off
));
6575 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6577 if (this_cu
->is_debug_types
)
6579 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6581 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6582 &cu
->header
, section
,
6584 info_ptr
, rcuh_kind::TYPE
);
6585 /* This is not an assert because it can be caused by bad debug info. */
6586 if (sig_type
->signature
!= cu
->header
.signature
)
6588 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6589 " TU at offset %s [in module %s]"),
6590 hex_string (sig_type
->signature
),
6591 hex_string (cu
->header
.signature
),
6592 sect_offset_str (dwo_unit
->sect_off
),
6593 bfd_get_filename (abfd
));
6595 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6596 /* For DWOs coming from DWP files, we don't know the CU length
6597 nor the type's offset in the TU until now. */
6598 dwo_unit
->length
= cu
->header
.get_length ();
6599 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6601 /* Establish the type offset that can be used to lookup the type.
6602 For DWO files, we don't know it until now. */
6603 sig_type
->type_offset_in_section
6604 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6608 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6609 &cu
->header
, section
,
6611 info_ptr
, rcuh_kind::COMPILE
);
6612 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6613 /* For DWOs coming from DWP files, we don't know the CU length
6615 dwo_unit
->length
= cu
->header
.get_length ();
6618 *result_dwo_abbrev_table
6619 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6620 cu
->header
.abbrev_sect_off
);
6621 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6622 result_dwo_abbrev_table
->get ());
6624 /* Read in the die, but leave space to copy over the attributes
6625 from the stub. This has the benefit of simplifying the rest of
6626 the code - all the work to maintain the illusion of a single
6627 DW_TAG_{compile,type}_unit DIE is done here. */
6628 num_extra_attrs
= ((stmt_list
!= NULL
)
6632 + (comp_dir
!= NULL
));
6633 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6636 /* Copy over the attributes from the stub to the DIE we just read in. */
6637 comp_unit_die
= *result_comp_unit_die
;
6638 i
= comp_unit_die
->num_attrs
;
6639 if (stmt_list
!= NULL
)
6640 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6642 comp_unit_die
->attrs
[i
++] = *low_pc
;
6643 if (high_pc
!= NULL
)
6644 comp_unit_die
->attrs
[i
++] = *high_pc
;
6646 comp_unit_die
->attrs
[i
++] = *ranges
;
6647 if (comp_dir
!= NULL
)
6648 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6649 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6651 if (dwarf_die_debug
)
6653 fprintf_unfiltered (gdb_stdlog
,
6654 "Read die from %s@0x%x of %s:\n",
6655 section
->get_name (),
6656 (unsigned) (begin_info_ptr
- section
->buffer
),
6657 bfd_get_filename (abfd
));
6658 dump_die (comp_unit_die
, dwarf_die_debug
);
6661 /* Skip dummy compilation units. */
6662 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6663 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6666 *result_info_ptr
= info_ptr
;
6670 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6671 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6672 signature is part of the header. */
6673 static gdb::optional
<ULONGEST
>
6674 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6676 if (cu
->header
.version
>= 5)
6677 return cu
->header
.signature
;
6678 struct attribute
*attr
;
6679 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6680 if (attr
== nullptr)
6681 return gdb::optional
<ULONGEST
> ();
6682 return DW_UNSND (attr
);
6685 /* Subroutine of cutu_reader to simplify it.
6686 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6687 Returns NULL if the specified DWO unit cannot be found. */
6689 static struct dwo_unit
*
6690 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6691 struct die_info
*comp_unit_die
,
6692 const char *dwo_name
)
6694 struct dwarf2_cu
*cu
= this_cu
->cu
;
6695 struct dwo_unit
*dwo_unit
;
6696 const char *comp_dir
;
6698 gdb_assert (cu
!= NULL
);
6700 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6701 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6702 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6704 if (this_cu
->is_debug_types
)
6706 struct signatured_type
*sig_type
;
6708 /* Since this_cu is the first member of struct signatured_type,
6709 we can go from a pointer to one to a pointer to the other. */
6710 sig_type
= (struct signatured_type
*) this_cu
;
6711 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6715 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6716 if (!signature
.has_value ())
6717 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6719 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6720 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6727 /* Subroutine of cutu_reader to simplify it.
6728 See it for a description of the parameters.
6729 Read a TU directly from a DWO file, bypassing the stub. */
6732 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6733 int use_existing_cu
, int keep
)
6735 struct signatured_type
*sig_type
;
6736 struct die_reader_specs reader
;
6738 /* Verify we can do the following downcast, and that we have the
6740 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6741 sig_type
= (struct signatured_type
*) this_cu
;
6742 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6744 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6746 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6747 /* There's no need to do the rereading_dwo_cu handling that
6748 cutu_reader does since we don't read the stub. */
6752 /* If !use_existing_cu, this_cu->cu must be NULL. */
6753 gdb_assert (this_cu
->cu
== NULL
);
6754 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6757 /* A future optimization, if needed, would be to use an existing
6758 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6759 could share abbrev tables. */
6761 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6762 NULL
/* stub_comp_unit_die */,
6763 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6766 &m_dwo_abbrev_table
) == 0)
6773 /* Initialize a CU (or TU) and read its DIEs.
6774 If the CU defers to a DWO file, read the DWO file as well.
6776 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6777 Otherwise the table specified in the comp unit header is read in and used.
6778 This is an optimization for when we already have the abbrev table.
6780 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6781 Otherwise, a new CU is allocated with xmalloc.
6783 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
6784 read_in_chain. Otherwise the dwarf2_cu data is freed at the
6787 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6788 struct abbrev_table
*abbrev_table
,
6789 int use_existing_cu
, int keep
,
6791 : die_reader_specs
{},
6792 m_this_cu (this_cu
),
6795 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6796 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6797 struct dwarf2_section_info
*section
= this_cu
->section
;
6798 bfd
*abfd
= section
->get_bfd_owner ();
6799 struct dwarf2_cu
*cu
;
6800 const gdb_byte
*begin_info_ptr
;
6801 struct signatured_type
*sig_type
= NULL
;
6802 struct dwarf2_section_info
*abbrev_section
;
6803 /* Non-zero if CU currently points to a DWO file and we need to
6804 reread it. When this happens we need to reread the skeleton die
6805 before we can reread the DWO file (this only applies to CUs, not TUs). */
6806 int rereading_dwo_cu
= 0;
6808 if (dwarf_die_debug
)
6809 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6810 this_cu
->is_debug_types
? "type" : "comp",
6811 sect_offset_str (this_cu
->sect_off
));
6813 if (use_existing_cu
)
6816 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6817 file (instead of going through the stub), short-circuit all of this. */
6818 if (this_cu
->reading_dwo_directly
)
6820 /* Narrow down the scope of possibilities to have to understand. */
6821 gdb_assert (this_cu
->is_debug_types
);
6822 gdb_assert (abbrev_table
== NULL
);
6823 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
);
6827 /* This is cheap if the section is already read in. */
6828 section
->read (objfile
);
6830 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6832 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6834 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6837 /* If this CU is from a DWO file we need to start over, we need to
6838 refetch the attributes from the skeleton CU.
6839 This could be optimized by retrieving those attributes from when we
6840 were here the first time: the previous comp_unit_die was stored in
6841 comp_unit_obstack. But there's no data yet that we need this
6843 if (cu
->dwo_unit
!= NULL
)
6844 rereading_dwo_cu
= 1;
6848 /* If !use_existing_cu, this_cu->cu must be NULL. */
6849 gdb_assert (this_cu
->cu
== NULL
);
6850 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6851 cu
= m_new_cu
.get ();
6854 /* Get the header. */
6855 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6857 /* We already have the header, there's no need to read it in again. */
6858 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6862 if (this_cu
->is_debug_types
)
6864 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6865 &cu
->header
, section
,
6866 abbrev_section
, info_ptr
,
6869 /* Since per_cu is the first member of struct signatured_type,
6870 we can go from a pointer to one to a pointer to the other. */
6871 sig_type
= (struct signatured_type
*) this_cu
;
6872 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6873 gdb_assert (sig_type
->type_offset_in_tu
6874 == cu
->header
.type_cu_offset_in_tu
);
6875 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6877 /* LENGTH has not been set yet for type units if we're
6878 using .gdb_index. */
6879 this_cu
->length
= cu
->header
.get_length ();
6881 /* Establish the type offset that can be used to lookup the type. */
6882 sig_type
->type_offset_in_section
=
6883 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6885 this_cu
->dwarf_version
= cu
->header
.version
;
6889 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6890 &cu
->header
, section
,
6893 rcuh_kind::COMPILE
);
6895 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6896 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6897 this_cu
->dwarf_version
= cu
->header
.version
;
6901 /* Skip dummy compilation units. */
6902 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6903 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6909 /* If we don't have them yet, read the abbrevs for this compilation unit.
6910 And if we need to read them now, make sure they're freed when we're
6912 if (abbrev_table
!= NULL
)
6913 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6916 m_abbrev_table_holder
6917 = abbrev_table::read (objfile
, abbrev_section
,
6918 cu
->header
.abbrev_sect_off
);
6919 abbrev_table
= m_abbrev_table_holder
.get ();
6922 /* Read the top level CU/TU die. */
6923 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6924 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6926 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6932 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6933 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6934 table from the DWO file and pass the ownership over to us. It will be
6935 referenced from READER, so we must make sure to free it after we're done
6938 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6939 DWO CU, that this test will fail (the attribute will not be present). */
6940 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6941 if (dwo_name
!= nullptr)
6943 struct dwo_unit
*dwo_unit
;
6944 struct die_info
*dwo_comp_unit_die
;
6946 if (comp_unit_die
->has_children
)
6948 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6949 " has children (offset %s) [in module %s]"),
6950 sect_offset_str (this_cu
->sect_off
),
6951 bfd_get_filename (abfd
));
6953 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6954 if (dwo_unit
!= NULL
)
6956 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6957 comp_unit_die
, NULL
,
6960 &m_dwo_abbrev_table
) == 0)
6966 comp_unit_die
= dwo_comp_unit_die
;
6970 /* Yikes, we couldn't find the rest of the DIE, we only have
6971 the stub. A complaint has already been logged. There's
6972 not much more we can do except pass on the stub DIE to
6973 die_reader_func. We don't want to throw an error on bad
6979 cutu_reader::~cutu_reader ()
6981 /* Done, clean up. */
6982 if (m_new_cu
!= NULL
&& m_keep
&& !dummy_p
)
6984 struct dwarf2_per_objfile
*dwarf2_per_objfile
6985 = m_this_cu
->dwarf2_per_objfile
;
6986 /* Link this CU into read_in_chain. */
6987 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6988 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6989 /* The chain owns it now. */
6990 m_new_cu
.release ();
6994 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6995 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6996 assumed to have already done the lookup to find the DWO file).
6998 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6999 THIS_CU->is_debug_types, but nothing else.
7001 We fill in THIS_CU->length.
7003 THIS_CU->cu is always freed when done.
7004 This is done in order to not leave THIS_CU->cu in a state where we have
7005 to care whether it refers to the "main" CU or the DWO CU.
7007 When parent_cu is passed, it is used to provide a default value for
7008 str_offsets_base and addr_base from the parent. */
7010 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7011 struct dwarf2_cu
*parent_cu
,
7012 struct dwo_file
*dwo_file
)
7013 : die_reader_specs
{},
7016 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7017 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7018 struct dwarf2_section_info
*section
= this_cu
->section
;
7019 bfd
*abfd
= section
->get_bfd_owner ();
7020 struct dwarf2_section_info
*abbrev_section
;
7021 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7023 if (dwarf_die_debug
)
7024 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7025 this_cu
->is_debug_types
? "type" : "comp",
7026 sect_offset_str (this_cu
->sect_off
));
7028 gdb_assert (this_cu
->cu
== NULL
);
7030 abbrev_section
= (dwo_file
!= NULL
7031 ? &dwo_file
->sections
.abbrev
7032 : get_abbrev_section_for_cu (this_cu
));
7034 /* This is cheap if the section is already read in. */
7035 section
->read (objfile
);
7037 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7039 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7040 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7041 &m_new_cu
->header
, section
,
7042 abbrev_section
, info_ptr
,
7043 (this_cu
->is_debug_types
7045 : rcuh_kind::COMPILE
));
7047 if (parent_cu
!= nullptr)
7049 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7050 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7052 this_cu
->length
= m_new_cu
->header
.get_length ();
7054 /* Skip dummy compilation units. */
7055 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7056 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7062 m_abbrev_table_holder
7063 = abbrev_table::read (objfile
, abbrev_section
,
7064 m_new_cu
->header
.abbrev_sect_off
);
7066 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7067 m_abbrev_table_holder
.get ());
7068 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7072 /* Type Unit Groups.
7074 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7075 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7076 so that all types coming from the same compilation (.o file) are grouped
7077 together. A future step could be to put the types in the same symtab as
7078 the CU the types ultimately came from. */
7081 hash_type_unit_group (const void *item
)
7083 const struct type_unit_group
*tu_group
7084 = (const struct type_unit_group
*) item
;
7086 return hash_stmt_list_entry (&tu_group
->hash
);
7090 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7092 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7093 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7095 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7098 /* Allocate a hash table for type unit groups. */
7101 allocate_type_unit_groups_table (struct objfile
*objfile
)
7103 return htab_up (htab_create_alloc (3,
7104 hash_type_unit_group
,
7106 NULL
, xcalloc
, xfree
));
7109 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7110 partial symtabs. We combine several TUs per psymtab to not let the size
7111 of any one psymtab grow too big. */
7112 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7113 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7115 /* Helper routine for get_type_unit_group.
7116 Create the type_unit_group object used to hold one or more TUs. */
7118 static struct type_unit_group
*
7119 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7121 struct dwarf2_per_objfile
*dwarf2_per_objfile
7122 = cu
->per_cu
->dwarf2_per_objfile
;
7123 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7124 struct dwarf2_per_cu_data
*per_cu
;
7125 struct type_unit_group
*tu_group
;
7127 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7128 struct type_unit_group
);
7129 per_cu
= &tu_group
->per_cu
;
7130 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7132 if (dwarf2_per_objfile
->using_index
)
7134 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7135 struct dwarf2_per_cu_quick_data
);
7139 unsigned int line_offset
= to_underlying (line_offset_struct
);
7140 dwarf2_psymtab
*pst
;
7143 /* Give the symtab a useful name for debug purposes. */
7144 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7145 name
= string_printf ("<type_units_%d>",
7146 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7148 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7150 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7151 pst
->anonymous
= true;
7154 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7155 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7160 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7161 STMT_LIST is a DW_AT_stmt_list attribute. */
7163 static struct type_unit_group
*
7164 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7166 struct dwarf2_per_objfile
*dwarf2_per_objfile
7167 = cu
->per_cu
->dwarf2_per_objfile
;
7168 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7169 struct type_unit_group
*tu_group
;
7171 unsigned int line_offset
;
7172 struct type_unit_group type_unit_group_for_lookup
;
7174 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7176 dwarf2_per_objfile
->type_unit_groups
=
7177 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7180 /* Do we need to create a new group, or can we use an existing one? */
7184 line_offset
= DW_UNSND (stmt_list
);
7185 ++tu_stats
->nr_symtab_sharers
;
7189 /* Ugh, no stmt_list. Rare, but we have to handle it.
7190 We can do various things here like create one group per TU or
7191 spread them over multiple groups to split up the expansion work.
7192 To avoid worst case scenarios (too many groups or too large groups)
7193 we, umm, group them in bunches. */
7194 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7195 | (tu_stats
->nr_stmt_less_type_units
7196 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7197 ++tu_stats
->nr_stmt_less_type_units
;
7200 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7201 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7202 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7203 &type_unit_group_for_lookup
, INSERT
);
7206 tu_group
= (struct type_unit_group
*) *slot
;
7207 gdb_assert (tu_group
!= NULL
);
7211 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7212 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7214 ++tu_stats
->nr_symtabs
;
7220 /* Partial symbol tables. */
7222 /* Create a psymtab named NAME and assign it to PER_CU.
7224 The caller must fill in the following details:
7225 dirname, textlow, texthigh. */
7227 static dwarf2_psymtab
*
7228 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7230 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7231 dwarf2_psymtab
*pst
;
7233 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7235 pst
->psymtabs_addrmap_supported
= true;
7237 /* This is the glue that links PST into GDB's symbol API. */
7238 pst
->per_cu_data
= per_cu
;
7239 per_cu
->v
.psymtab
= pst
;
7244 /* DIE reader function for process_psymtab_comp_unit. */
7247 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7248 const gdb_byte
*info_ptr
,
7249 struct die_info
*comp_unit_die
,
7250 int want_partial_unit
,
7251 enum language pretend_language
)
7253 struct dwarf2_cu
*cu
= reader
->cu
;
7254 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7255 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7256 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7258 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7259 dwarf2_psymtab
*pst
;
7260 enum pc_bounds_kind cu_bounds_kind
;
7261 const char *filename
;
7263 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !want_partial_unit
)
7266 gdb_assert (! per_cu
->is_debug_types
);
7268 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7270 /* Allocate a new partial symbol table structure. */
7271 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7272 if (filename
== NULL
)
7275 pst
= create_partial_symtab (per_cu
, filename
);
7277 /* This must be done before calling dwarf2_build_include_psymtabs. */
7278 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7280 baseaddr
= objfile
->text_section_offset ();
7282 dwarf2_find_base_address (comp_unit_die
, cu
);
7284 /* Possibly set the default values of LOWPC and HIGHPC from
7286 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7287 &best_highpc
, cu
, pst
);
7288 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7291 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7294 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7296 /* Store the contiguous range if it is not empty; it can be
7297 empty for CUs with no code. */
7298 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7302 /* Check if comp unit has_children.
7303 If so, read the rest of the partial symbols from this comp unit.
7304 If not, there's no more debug_info for this comp unit. */
7305 if (comp_unit_die
->has_children
)
7307 struct partial_die_info
*first_die
;
7308 CORE_ADDR lowpc
, highpc
;
7310 lowpc
= ((CORE_ADDR
) -1);
7311 highpc
= ((CORE_ADDR
) 0);
7313 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7315 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7316 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7318 /* If we didn't find a lowpc, set it to highpc to avoid
7319 complaints from `maint check'. */
7320 if (lowpc
== ((CORE_ADDR
) -1))
7323 /* If the compilation unit didn't have an explicit address range,
7324 then use the information extracted from its child dies. */
7325 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7328 best_highpc
= highpc
;
7331 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7332 best_lowpc
+ baseaddr
)
7334 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7335 best_highpc
+ baseaddr
)
7338 end_psymtab_common (objfile
, pst
);
7340 if (!cu
->per_cu
->imported_symtabs_empty ())
7343 int len
= cu
->per_cu
->imported_symtabs_size ();
7345 /* Fill in 'dependencies' here; we fill in 'users' in a
7347 pst
->number_of_dependencies
= len
;
7349 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7350 for (i
= 0; i
< len
; ++i
)
7352 pst
->dependencies
[i
]
7353 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7356 cu
->per_cu
->imported_symtabs_free ();
7359 /* Get the list of files included in the current compilation unit,
7360 and build a psymtab for each of them. */
7361 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7363 if (dwarf_read_debug
)
7364 fprintf_unfiltered (gdb_stdlog
,
7365 "Psymtab for %s unit @%s: %s - %s"
7366 ", %d global, %d static syms\n",
7367 per_cu
->is_debug_types
? "type" : "comp",
7368 sect_offset_str (per_cu
->sect_off
),
7369 paddress (gdbarch
, pst
->text_low (objfile
)),
7370 paddress (gdbarch
, pst
->text_high (objfile
)),
7371 pst
->n_global_syms
, pst
->n_static_syms
);
7374 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7375 Process compilation unit THIS_CU for a psymtab. */
7378 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7379 int want_partial_unit
,
7380 enum language pretend_language
)
7382 /* If this compilation unit was already read in, free the
7383 cached copy in order to read it in again. This is
7384 necessary because we skipped some symbols when we first
7385 read in the compilation unit (see load_partial_dies).
7386 This problem could be avoided, but the benefit is unclear. */
7387 if (this_cu
->cu
!= NULL
)
7388 free_one_cached_comp_unit (this_cu
);
7390 cutu_reader
reader (this_cu
, NULL
, 0, 0, false);
7396 else if (this_cu
->is_debug_types
)
7397 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7398 reader
.comp_unit_die
);
7400 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7401 reader
.comp_unit_die
,
7405 /* Age out any secondary CUs. */
7406 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7409 /* Reader function for build_type_psymtabs. */
7412 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7413 const gdb_byte
*info_ptr
,
7414 struct die_info
*type_unit_die
)
7416 struct dwarf2_per_objfile
*dwarf2_per_objfile
7417 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7418 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7419 struct dwarf2_cu
*cu
= reader
->cu
;
7420 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7421 struct signatured_type
*sig_type
;
7422 struct type_unit_group
*tu_group
;
7423 struct attribute
*attr
;
7424 struct partial_die_info
*first_die
;
7425 CORE_ADDR lowpc
, highpc
;
7426 dwarf2_psymtab
*pst
;
7428 gdb_assert (per_cu
->is_debug_types
);
7429 sig_type
= (struct signatured_type
*) per_cu
;
7431 if (! type_unit_die
->has_children
)
7434 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7435 tu_group
= get_type_unit_group (cu
, attr
);
7437 if (tu_group
->tus
== nullptr)
7438 tu_group
->tus
= new std::vector
<signatured_type
*>;
7439 tu_group
->tus
->push_back (sig_type
);
7441 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7442 pst
= create_partial_symtab (per_cu
, "");
7443 pst
->anonymous
= true;
7445 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7447 lowpc
= (CORE_ADDR
) -1;
7448 highpc
= (CORE_ADDR
) 0;
7449 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7451 end_psymtab_common (objfile
, pst
);
7454 /* Struct used to sort TUs by their abbreviation table offset. */
7456 struct tu_abbrev_offset
7458 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7459 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7462 signatured_type
*sig_type
;
7463 sect_offset abbrev_offset
;
7466 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7469 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7470 const struct tu_abbrev_offset
&b
)
7472 return a
.abbrev_offset
< b
.abbrev_offset
;
7475 /* Efficiently read all the type units.
7476 This does the bulk of the work for build_type_psymtabs.
7478 The efficiency is because we sort TUs by the abbrev table they use and
7479 only read each abbrev table once. In one program there are 200K TUs
7480 sharing 8K abbrev tables.
7482 The main purpose of this function is to support building the
7483 dwarf2_per_objfile->type_unit_groups table.
7484 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7485 can collapse the search space by grouping them by stmt_list.
7486 The savings can be significant, in the same program from above the 200K TUs
7487 share 8K stmt_list tables.
7489 FUNC is expected to call get_type_unit_group, which will create the
7490 struct type_unit_group if necessary and add it to
7491 dwarf2_per_objfile->type_unit_groups. */
7494 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7496 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7497 abbrev_table_up abbrev_table
;
7498 sect_offset abbrev_offset
;
7500 /* It's up to the caller to not call us multiple times. */
7501 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7503 if (dwarf2_per_objfile
->all_type_units
.empty ())
7506 /* TUs typically share abbrev tables, and there can be way more TUs than
7507 abbrev tables. Sort by abbrev table to reduce the number of times we
7508 read each abbrev table in.
7509 Alternatives are to punt or to maintain a cache of abbrev tables.
7510 This is simpler and efficient enough for now.
7512 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7513 symtab to use). Typically TUs with the same abbrev offset have the same
7514 stmt_list value too so in practice this should work well.
7516 The basic algorithm here is:
7518 sort TUs by abbrev table
7519 for each TU with same abbrev table:
7520 read abbrev table if first user
7521 read TU top level DIE
7522 [IWBN if DWO skeletons had DW_AT_stmt_list]
7525 if (dwarf_read_debug
)
7526 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7528 /* Sort in a separate table to maintain the order of all_type_units
7529 for .gdb_index: TU indices directly index all_type_units. */
7530 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7531 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7533 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7534 sorted_by_abbrev
.emplace_back
7535 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7536 sig_type
->per_cu
.section
,
7537 sig_type
->per_cu
.sect_off
));
7539 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7540 sort_tu_by_abbrev_offset
);
7542 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7544 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7546 /* Switch to the next abbrev table if necessary. */
7547 if (abbrev_table
== NULL
7548 || tu
.abbrev_offset
!= abbrev_offset
)
7550 abbrev_offset
= tu
.abbrev_offset
;
7552 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7553 &dwarf2_per_objfile
->abbrev
,
7555 ++tu_stats
->nr_uniq_abbrev_tables
;
7558 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7560 if (!reader
.dummy_p
)
7561 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7562 reader
.comp_unit_die
);
7566 /* Print collected type unit statistics. */
7569 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7571 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7573 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7574 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7575 dwarf2_per_objfile
->all_type_units
.size ());
7576 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7577 tu_stats
->nr_uniq_abbrev_tables
);
7578 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7579 tu_stats
->nr_symtabs
);
7580 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7581 tu_stats
->nr_symtab_sharers
);
7582 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7583 tu_stats
->nr_stmt_less_type_units
);
7584 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7585 tu_stats
->nr_all_type_units_reallocs
);
7588 /* Traversal function for build_type_psymtabs. */
7591 build_type_psymtab_dependencies (void **slot
, void *info
)
7593 struct dwarf2_per_objfile
*dwarf2_per_objfile
7594 = (struct dwarf2_per_objfile
*) info
;
7595 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7596 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7597 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7598 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7599 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7602 gdb_assert (len
> 0);
7603 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
7605 pst
->number_of_dependencies
= len
;
7606 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7607 for (i
= 0; i
< len
; ++i
)
7609 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7610 gdb_assert (iter
->per_cu
.is_debug_types
);
7611 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7612 iter
->type_unit_group
= tu_group
;
7615 delete tu_group
->tus
;
7616 tu_group
->tus
= nullptr;
7621 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7622 Build partial symbol tables for the .debug_types comp-units. */
7625 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7627 if (! create_all_type_units (dwarf2_per_objfile
))
7630 build_type_psymtabs_1 (dwarf2_per_objfile
);
7633 /* Traversal function for process_skeletonless_type_unit.
7634 Read a TU in a DWO file and build partial symbols for it. */
7637 process_skeletonless_type_unit (void **slot
, void *info
)
7639 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7640 struct dwarf2_per_objfile
*dwarf2_per_objfile
7641 = (struct dwarf2_per_objfile
*) info
;
7642 struct signatured_type find_entry
, *entry
;
7644 /* If this TU doesn't exist in the global table, add it and read it in. */
7646 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7648 dwarf2_per_objfile
->signatured_types
7649 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
7652 find_entry
.signature
= dwo_unit
->signature
;
7653 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7654 &find_entry
, INSERT
);
7655 /* If we've already seen this type there's nothing to do. What's happening
7656 is we're doing our own version of comdat-folding here. */
7660 /* This does the job that create_all_type_units would have done for
7662 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7663 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7666 /* This does the job that build_type_psymtabs_1 would have done. */
7667 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, 0, false);
7668 if (!reader
.dummy_p
)
7669 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7670 reader
.comp_unit_die
);
7675 /* Traversal function for process_skeletonless_type_units. */
7678 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7680 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7682 if (dwo_file
->tus
!= NULL
)
7683 htab_traverse_noresize (dwo_file
->tus
.get (),
7684 process_skeletonless_type_unit
, info
);
7689 /* Scan all TUs of DWO files, verifying we've processed them.
7690 This is needed in case a TU was emitted without its skeleton.
7691 Note: This can't be done until we know what all the DWO files are. */
7694 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7696 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7697 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7698 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7700 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7701 process_dwo_file_for_skeletonless_type_units
,
7702 dwarf2_per_objfile
);
7706 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7709 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7711 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7713 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7718 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7720 /* Set the 'user' field only if it is not already set. */
7721 if (pst
->dependencies
[j
]->user
== NULL
)
7722 pst
->dependencies
[j
]->user
= pst
;
7727 /* Build the partial symbol table by doing a quick pass through the
7728 .debug_info and .debug_abbrev sections. */
7731 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7733 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7735 if (dwarf_read_debug
)
7737 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7738 objfile_name (objfile
));
7741 dwarf2_per_objfile
->reading_partial_symbols
= 1;
7743 dwarf2_per_objfile
->info
.read (objfile
);
7745 /* Any cached compilation units will be linked by the per-objfile
7746 read_in_chain. Make sure to free them when we're done. */
7747 free_cached_comp_units
freer (dwarf2_per_objfile
);
7749 build_type_psymtabs (dwarf2_per_objfile
);
7751 create_all_comp_units (dwarf2_per_objfile
);
7753 /* Create a temporary address map on a temporary obstack. We later
7754 copy this to the final obstack. */
7755 auto_obstack temp_obstack
;
7757 scoped_restore save_psymtabs_addrmap
7758 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7759 addrmap_create_mutable (&temp_obstack
));
7761 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7762 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
7764 /* This has to wait until we read the CUs, we need the list of DWOs. */
7765 process_skeletonless_type_units (dwarf2_per_objfile
);
7767 /* Now that all TUs have been processed we can fill in the dependencies. */
7768 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7770 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7771 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7774 if (dwarf_read_debug
)
7775 print_tu_stats (dwarf2_per_objfile
);
7777 set_partial_user (dwarf2_per_objfile
);
7779 objfile
->partial_symtabs
->psymtabs_addrmap
7780 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7781 objfile
->partial_symtabs
->obstack ());
7782 /* At this point we want to keep the address map. */
7783 save_psymtabs_addrmap
.release ();
7785 if (dwarf_read_debug
)
7786 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7787 objfile_name (objfile
));
7790 /* Load the partial DIEs for a secondary CU into memory.
7791 This is also used when rereading a primary CU with load_all_dies. */
7794 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7796 cutu_reader
reader (this_cu
, NULL
, 1, 1, false);
7798 if (!reader
.dummy_p
)
7800 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7803 /* Check if comp unit has_children.
7804 If so, read the rest of the partial symbols from this comp unit.
7805 If not, there's no more debug_info for this comp unit. */
7806 if (reader
.comp_unit_die
->has_children
)
7807 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7812 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7813 struct dwarf2_section_info
*section
,
7814 struct dwarf2_section_info
*abbrev_section
,
7815 unsigned int is_dwz
)
7817 const gdb_byte
*info_ptr
;
7818 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7820 if (dwarf_read_debug
)
7821 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7822 section
->get_name (),
7823 section
->get_file_name ());
7825 section
->read (objfile
);
7827 info_ptr
= section
->buffer
;
7829 while (info_ptr
< section
->buffer
+ section
->size
)
7831 struct dwarf2_per_cu_data
*this_cu
;
7833 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7835 comp_unit_head cu_header
;
7836 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7837 abbrev_section
, info_ptr
,
7838 rcuh_kind::COMPILE
);
7840 /* Save the compilation unit for later lookup. */
7841 if (cu_header
.unit_type
!= DW_UT_type
)
7843 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7844 struct dwarf2_per_cu_data
);
7845 memset (this_cu
, 0, sizeof (*this_cu
));
7849 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7850 struct signatured_type
);
7851 memset (sig_type
, 0, sizeof (*sig_type
));
7852 sig_type
->signature
= cu_header
.signature
;
7853 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7854 this_cu
= &sig_type
->per_cu
;
7856 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7857 this_cu
->sect_off
= sect_off
;
7858 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7859 this_cu
->is_dwz
= is_dwz
;
7860 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7861 this_cu
->section
= section
;
7863 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7865 info_ptr
= info_ptr
+ this_cu
->length
;
7869 /* Create a list of all compilation units in OBJFILE.
7870 This is only done for -readnow and building partial symtabs. */
7873 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7875 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7876 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7877 &dwarf2_per_objfile
->abbrev
, 0);
7879 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7881 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7885 /* Process all loaded DIEs for compilation unit CU, starting at
7886 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7887 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7888 DW_AT_ranges). See the comments of add_partial_subprogram on how
7889 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7892 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7893 CORE_ADDR
*highpc
, int set_addrmap
,
7894 struct dwarf2_cu
*cu
)
7896 struct partial_die_info
*pdi
;
7898 /* Now, march along the PDI's, descending into ones which have
7899 interesting children but skipping the children of the other ones,
7900 until we reach the end of the compilation unit. */
7908 /* Anonymous namespaces or modules have no name but have interesting
7909 children, so we need to look at them. Ditto for anonymous
7912 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7913 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7914 || pdi
->tag
== DW_TAG_imported_unit
7915 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7919 case DW_TAG_subprogram
:
7920 case DW_TAG_inlined_subroutine
:
7921 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7923 case DW_TAG_constant
:
7924 case DW_TAG_variable
:
7925 case DW_TAG_typedef
:
7926 case DW_TAG_union_type
:
7927 if (!pdi
->is_declaration
)
7929 add_partial_symbol (pdi
, cu
);
7932 case DW_TAG_class_type
:
7933 case DW_TAG_interface_type
:
7934 case DW_TAG_structure_type
:
7935 if (!pdi
->is_declaration
)
7937 add_partial_symbol (pdi
, cu
);
7939 if ((cu
->language
== language_rust
7940 || cu
->language
== language_cplus
) && pdi
->has_children
)
7941 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7944 case DW_TAG_enumeration_type
:
7945 if (!pdi
->is_declaration
)
7946 add_partial_enumeration (pdi
, cu
);
7948 case DW_TAG_base_type
:
7949 case DW_TAG_subrange_type
:
7950 /* File scope base type definitions are added to the partial
7952 add_partial_symbol (pdi
, cu
);
7954 case DW_TAG_namespace
:
7955 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7958 if (!pdi
->is_declaration
)
7959 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7961 case DW_TAG_imported_unit
:
7963 struct dwarf2_per_cu_data
*per_cu
;
7965 /* For now we don't handle imported units in type units. */
7966 if (cu
->per_cu
->is_debug_types
)
7968 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7969 " supported in type units [in module %s]"),
7970 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7973 per_cu
= dwarf2_find_containing_comp_unit
7974 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7975 cu
->per_cu
->dwarf2_per_objfile
);
7977 /* Go read the partial unit, if needed. */
7978 if (per_cu
->v
.psymtab
== NULL
)
7979 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
7981 cu
->per_cu
->imported_symtabs_push (per_cu
);
7984 case DW_TAG_imported_declaration
:
7985 add_partial_symbol (pdi
, cu
);
7992 /* If the die has a sibling, skip to the sibling. */
7994 pdi
= pdi
->die_sibling
;
7998 /* Functions used to compute the fully scoped name of a partial DIE.
8000 Normally, this is simple. For C++, the parent DIE's fully scoped
8001 name is concatenated with "::" and the partial DIE's name.
8002 Enumerators are an exception; they use the scope of their parent
8003 enumeration type, i.e. the name of the enumeration type is not
8004 prepended to the enumerator.
8006 There are two complexities. One is DW_AT_specification; in this
8007 case "parent" means the parent of the target of the specification,
8008 instead of the direct parent of the DIE. The other is compilers
8009 which do not emit DW_TAG_namespace; in this case we try to guess
8010 the fully qualified name of structure types from their members'
8011 linkage names. This must be done using the DIE's children rather
8012 than the children of any DW_AT_specification target. We only need
8013 to do this for structures at the top level, i.e. if the target of
8014 any DW_AT_specification (if any; otherwise the DIE itself) does not
8017 /* Compute the scope prefix associated with PDI's parent, in
8018 compilation unit CU. The result will be allocated on CU's
8019 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8020 field. NULL is returned if no prefix is necessary. */
8022 partial_die_parent_scope (struct partial_die_info
*pdi
,
8023 struct dwarf2_cu
*cu
)
8025 const char *grandparent_scope
;
8026 struct partial_die_info
*parent
, *real_pdi
;
8028 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8029 then this means the parent of the specification DIE. */
8032 while (real_pdi
->has_specification
)
8034 auto res
= find_partial_die (real_pdi
->spec_offset
,
8035 real_pdi
->spec_is_dwz
, cu
);
8040 parent
= real_pdi
->die_parent
;
8044 if (parent
->scope_set
)
8045 return parent
->scope
;
8049 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8051 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8052 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8053 Work around this problem here. */
8054 if (cu
->language
== language_cplus
8055 && parent
->tag
== DW_TAG_namespace
8056 && strcmp (parent
->name
, "::") == 0
8057 && grandparent_scope
== NULL
)
8059 parent
->scope
= NULL
;
8060 parent
->scope_set
= 1;
8064 /* Nested subroutines in Fortran get a prefix. */
8065 if (pdi
->tag
== DW_TAG_enumerator
)
8066 /* Enumerators should not get the name of the enumeration as a prefix. */
8067 parent
->scope
= grandparent_scope
;
8068 else if (parent
->tag
== DW_TAG_namespace
8069 || parent
->tag
== DW_TAG_module
8070 || parent
->tag
== DW_TAG_structure_type
8071 || parent
->tag
== DW_TAG_class_type
8072 || parent
->tag
== DW_TAG_interface_type
8073 || parent
->tag
== DW_TAG_union_type
8074 || parent
->tag
== DW_TAG_enumeration_type
8075 || (cu
->language
== language_fortran
8076 && parent
->tag
== DW_TAG_subprogram
8077 && pdi
->tag
== DW_TAG_subprogram
))
8079 if (grandparent_scope
== NULL
)
8080 parent
->scope
= parent
->name
;
8082 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8084 parent
->name
, 0, cu
);
8088 /* FIXME drow/2004-04-01: What should we be doing with
8089 function-local names? For partial symbols, we should probably be
8091 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8092 dwarf_tag_name (parent
->tag
),
8093 sect_offset_str (pdi
->sect_off
));
8094 parent
->scope
= grandparent_scope
;
8097 parent
->scope_set
= 1;
8098 return parent
->scope
;
8101 /* Return the fully scoped name associated with PDI, from compilation unit
8102 CU. The result will be allocated with malloc. */
8104 static gdb::unique_xmalloc_ptr
<char>
8105 partial_die_full_name (struct partial_die_info
*pdi
,
8106 struct dwarf2_cu
*cu
)
8108 const char *parent_scope
;
8110 /* If this is a template instantiation, we can not work out the
8111 template arguments from partial DIEs. So, unfortunately, we have
8112 to go through the full DIEs. At least any work we do building
8113 types here will be reused if full symbols are loaded later. */
8114 if (pdi
->has_template_arguments
)
8118 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8120 struct die_info
*die
;
8121 struct attribute attr
;
8122 struct dwarf2_cu
*ref_cu
= cu
;
8124 /* DW_FORM_ref_addr is using section offset. */
8125 attr
.name
= (enum dwarf_attribute
) 0;
8126 attr
.form
= DW_FORM_ref_addr
;
8127 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8128 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8130 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8134 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8135 if (parent_scope
== NULL
)
8138 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8143 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8145 struct dwarf2_per_objfile
*dwarf2_per_objfile
8146 = cu
->per_cu
->dwarf2_per_objfile
;
8147 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8148 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8150 const char *actual_name
= NULL
;
8153 baseaddr
= objfile
->text_section_offset ();
8155 gdb::unique_xmalloc_ptr
<char> built_actual_name
8156 = partial_die_full_name (pdi
, cu
);
8157 if (built_actual_name
!= NULL
)
8158 actual_name
= built_actual_name
.get ();
8160 if (actual_name
== NULL
)
8161 actual_name
= pdi
->name
;
8165 case DW_TAG_inlined_subroutine
:
8166 case DW_TAG_subprogram
:
8167 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8169 if (pdi
->is_external
8170 || cu
->language
== language_ada
8171 || (cu
->language
== language_fortran
8172 && pdi
->die_parent
!= NULL
8173 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8175 /* Normally, only "external" DIEs are part of the global scope.
8176 But in Ada and Fortran, we want to be able to access nested
8177 procedures globally. So all Ada and Fortran subprograms are
8178 stored in the global scope. */
8179 add_psymbol_to_list (actual_name
,
8180 built_actual_name
!= NULL
,
8181 VAR_DOMAIN
, LOC_BLOCK
,
8182 SECT_OFF_TEXT (objfile
),
8183 psymbol_placement::GLOBAL
,
8185 cu
->language
, objfile
);
8189 add_psymbol_to_list (actual_name
,
8190 built_actual_name
!= NULL
,
8191 VAR_DOMAIN
, LOC_BLOCK
,
8192 SECT_OFF_TEXT (objfile
),
8193 psymbol_placement::STATIC
,
8194 addr
, cu
->language
, objfile
);
8197 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8198 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8200 case DW_TAG_constant
:
8201 add_psymbol_to_list (actual_name
,
8202 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8203 -1, (pdi
->is_external
8204 ? psymbol_placement::GLOBAL
8205 : psymbol_placement::STATIC
),
8206 0, cu
->language
, objfile
);
8208 case DW_TAG_variable
:
8210 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8214 && !dwarf2_per_objfile
->has_section_at_zero
)
8216 /* A global or static variable may also have been stripped
8217 out by the linker if unused, in which case its address
8218 will be nullified; do not add such variables into partial
8219 symbol table then. */
8221 else if (pdi
->is_external
)
8224 Don't enter into the minimal symbol tables as there is
8225 a minimal symbol table entry from the ELF symbols already.
8226 Enter into partial symbol table if it has a location
8227 descriptor or a type.
8228 If the location descriptor is missing, new_symbol will create
8229 a LOC_UNRESOLVED symbol, the address of the variable will then
8230 be determined from the minimal symbol table whenever the variable
8232 The address for the partial symbol table entry is not
8233 used by GDB, but it comes in handy for debugging partial symbol
8236 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8237 add_psymbol_to_list (actual_name
,
8238 built_actual_name
!= NULL
,
8239 VAR_DOMAIN
, LOC_STATIC
,
8240 SECT_OFF_TEXT (objfile
),
8241 psymbol_placement::GLOBAL
,
8242 addr
, cu
->language
, objfile
);
8246 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8248 /* Static Variable. Skip symbols whose value we cannot know (those
8249 without location descriptors or constant values). */
8250 if (!has_loc
&& !pdi
->has_const_value
)
8253 add_psymbol_to_list (actual_name
,
8254 built_actual_name
!= NULL
,
8255 VAR_DOMAIN
, LOC_STATIC
,
8256 SECT_OFF_TEXT (objfile
),
8257 psymbol_placement::STATIC
,
8259 cu
->language
, objfile
);
8262 case DW_TAG_typedef
:
8263 case DW_TAG_base_type
:
8264 case DW_TAG_subrange_type
:
8265 add_psymbol_to_list (actual_name
,
8266 built_actual_name
!= NULL
,
8267 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8268 psymbol_placement::STATIC
,
8269 0, cu
->language
, objfile
);
8271 case DW_TAG_imported_declaration
:
8272 case DW_TAG_namespace
:
8273 add_psymbol_to_list (actual_name
,
8274 built_actual_name
!= NULL
,
8275 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8276 psymbol_placement::GLOBAL
,
8277 0, cu
->language
, objfile
);
8280 /* With Fortran 77 there might be a "BLOCK DATA" module
8281 available without any name. If so, we skip the module as it
8282 doesn't bring any value. */
8283 if (actual_name
!= nullptr)
8284 add_psymbol_to_list (actual_name
,
8285 built_actual_name
!= NULL
,
8286 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8287 psymbol_placement::GLOBAL
,
8288 0, cu
->language
, objfile
);
8290 case DW_TAG_class_type
:
8291 case DW_TAG_interface_type
:
8292 case DW_TAG_structure_type
:
8293 case DW_TAG_union_type
:
8294 case DW_TAG_enumeration_type
:
8295 /* Skip external references. The DWARF standard says in the section
8296 about "Structure, Union, and Class Type Entries": "An incomplete
8297 structure, union or class type is represented by a structure,
8298 union or class entry that does not have a byte size attribute
8299 and that has a DW_AT_declaration attribute." */
8300 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8303 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8304 static vs. global. */
8305 add_psymbol_to_list (actual_name
,
8306 built_actual_name
!= NULL
,
8307 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8308 cu
->language
== language_cplus
8309 ? psymbol_placement::GLOBAL
8310 : psymbol_placement::STATIC
,
8311 0, cu
->language
, objfile
);
8314 case DW_TAG_enumerator
:
8315 add_psymbol_to_list (actual_name
,
8316 built_actual_name
!= NULL
,
8317 VAR_DOMAIN
, LOC_CONST
, -1,
8318 cu
->language
== language_cplus
8319 ? psymbol_placement::GLOBAL
8320 : psymbol_placement::STATIC
,
8321 0, cu
->language
, objfile
);
8328 /* Read a partial die corresponding to a namespace; also, add a symbol
8329 corresponding to that namespace to the symbol table. NAMESPACE is
8330 the name of the enclosing namespace. */
8333 add_partial_namespace (struct partial_die_info
*pdi
,
8334 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8335 int set_addrmap
, struct dwarf2_cu
*cu
)
8337 /* Add a symbol for the namespace. */
8339 add_partial_symbol (pdi
, cu
);
8341 /* Now scan partial symbols in that namespace. */
8343 if (pdi
->has_children
)
8344 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8347 /* Read a partial die corresponding to a Fortran module. */
8350 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8351 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8353 /* Add a symbol for the namespace. */
8355 add_partial_symbol (pdi
, cu
);
8357 /* Now scan partial symbols in that module. */
8359 if (pdi
->has_children
)
8360 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8363 /* Read a partial die corresponding to a subprogram or an inlined
8364 subprogram and create a partial symbol for that subprogram.
8365 When the CU language allows it, this routine also defines a partial
8366 symbol for each nested subprogram that this subprogram contains.
8367 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8368 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8370 PDI may also be a lexical block, in which case we simply search
8371 recursively for subprograms defined inside that lexical block.
8372 Again, this is only performed when the CU language allows this
8373 type of definitions. */
8376 add_partial_subprogram (struct partial_die_info
*pdi
,
8377 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8378 int set_addrmap
, struct dwarf2_cu
*cu
)
8380 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8382 if (pdi
->has_pc_info
)
8384 if (pdi
->lowpc
< *lowpc
)
8385 *lowpc
= pdi
->lowpc
;
8386 if (pdi
->highpc
> *highpc
)
8387 *highpc
= pdi
->highpc
;
8390 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8391 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8393 CORE_ADDR this_highpc
;
8394 CORE_ADDR this_lowpc
;
8396 baseaddr
= objfile
->text_section_offset ();
8398 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8399 pdi
->lowpc
+ baseaddr
)
8402 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8403 pdi
->highpc
+ baseaddr
)
8405 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8406 this_lowpc
, this_highpc
- 1,
8407 cu
->per_cu
->v
.psymtab
);
8411 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8413 if (!pdi
->is_declaration
)
8414 /* Ignore subprogram DIEs that do not have a name, they are
8415 illegal. Do not emit a complaint at this point, we will
8416 do so when we convert this psymtab into a symtab. */
8418 add_partial_symbol (pdi
, cu
);
8422 if (! pdi
->has_children
)
8425 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8427 pdi
= pdi
->die_child
;
8431 if (pdi
->tag
== DW_TAG_subprogram
8432 || pdi
->tag
== DW_TAG_inlined_subroutine
8433 || pdi
->tag
== DW_TAG_lexical_block
)
8434 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8435 pdi
= pdi
->die_sibling
;
8440 /* Read a partial die corresponding to an enumeration type. */
8443 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8444 struct dwarf2_cu
*cu
)
8446 struct partial_die_info
*pdi
;
8448 if (enum_pdi
->name
!= NULL
)
8449 add_partial_symbol (enum_pdi
, cu
);
8451 pdi
= enum_pdi
->die_child
;
8454 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8455 complaint (_("malformed enumerator DIE ignored"));
8457 add_partial_symbol (pdi
, cu
);
8458 pdi
= pdi
->die_sibling
;
8462 /* Return the initial uleb128 in the die at INFO_PTR. */
8465 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8467 unsigned int bytes_read
;
8469 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8472 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8473 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8475 Return the corresponding abbrev, or NULL if the number is zero (indicating
8476 an empty DIE). In either case *BYTES_READ will be set to the length of
8477 the initial number. */
8479 static struct abbrev_info
*
8480 peek_die_abbrev (const die_reader_specs
&reader
,
8481 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8483 dwarf2_cu
*cu
= reader
.cu
;
8484 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8485 unsigned int abbrev_number
8486 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8488 if (abbrev_number
== 0)
8491 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8494 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8495 " at offset %s [in module %s]"),
8496 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8497 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8503 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8504 Returns a pointer to the end of a series of DIEs, terminated by an empty
8505 DIE. Any children of the skipped DIEs will also be skipped. */
8507 static const gdb_byte
*
8508 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8512 unsigned int bytes_read
;
8513 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8516 return info_ptr
+ bytes_read
;
8518 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8522 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8523 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8524 abbrev corresponding to that skipped uleb128 should be passed in
8525 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8528 static const gdb_byte
*
8529 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8530 struct abbrev_info
*abbrev
)
8532 unsigned int bytes_read
;
8533 struct attribute attr
;
8534 bfd
*abfd
= reader
->abfd
;
8535 struct dwarf2_cu
*cu
= reader
->cu
;
8536 const gdb_byte
*buffer
= reader
->buffer
;
8537 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8538 unsigned int form
, i
;
8540 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8542 /* The only abbrev we care about is DW_AT_sibling. */
8543 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8546 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8548 if (attr
.form
== DW_FORM_ref_addr
)
8549 complaint (_("ignoring absolute DW_AT_sibling"));
8552 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8553 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8555 if (sibling_ptr
< info_ptr
)
8556 complaint (_("DW_AT_sibling points backwards"));
8557 else if (sibling_ptr
> reader
->buffer_end
)
8558 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
8564 /* If it isn't DW_AT_sibling, skip this attribute. */
8565 form
= abbrev
->attrs
[i
].form
;
8569 case DW_FORM_ref_addr
:
8570 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8571 and later it is offset sized. */
8572 if (cu
->header
.version
== 2)
8573 info_ptr
+= cu
->header
.addr_size
;
8575 info_ptr
+= cu
->header
.offset_size
;
8577 case DW_FORM_GNU_ref_alt
:
8578 info_ptr
+= cu
->header
.offset_size
;
8581 info_ptr
+= cu
->header
.addr_size
;
8589 case DW_FORM_flag_present
:
8590 case DW_FORM_implicit_const
:
8607 case DW_FORM_ref_sig8
:
8610 case DW_FORM_data16
:
8613 case DW_FORM_string
:
8614 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8615 info_ptr
+= bytes_read
;
8617 case DW_FORM_sec_offset
:
8619 case DW_FORM_GNU_strp_alt
:
8620 info_ptr
+= cu
->header
.offset_size
;
8622 case DW_FORM_exprloc
:
8624 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8625 info_ptr
+= bytes_read
;
8627 case DW_FORM_block1
:
8628 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8630 case DW_FORM_block2
:
8631 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8633 case DW_FORM_block4
:
8634 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8640 case DW_FORM_ref_udata
:
8641 case DW_FORM_GNU_addr_index
:
8642 case DW_FORM_GNU_str_index
:
8643 case DW_FORM_rnglistx
:
8644 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8646 case DW_FORM_indirect
:
8647 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8648 info_ptr
+= bytes_read
;
8649 /* We need to continue parsing from here, so just go back to
8651 goto skip_attribute
;
8654 error (_("Dwarf Error: Cannot handle %s "
8655 "in DWARF reader [in module %s]"),
8656 dwarf_form_name (form
),
8657 bfd_get_filename (abfd
));
8661 if (abbrev
->has_children
)
8662 return skip_children (reader
, info_ptr
);
8667 /* Locate ORIG_PDI's sibling.
8668 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8670 static const gdb_byte
*
8671 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8672 struct partial_die_info
*orig_pdi
,
8673 const gdb_byte
*info_ptr
)
8675 /* Do we know the sibling already? */
8677 if (orig_pdi
->sibling
)
8678 return orig_pdi
->sibling
;
8680 /* Are there any children to deal with? */
8682 if (!orig_pdi
->has_children
)
8685 /* Skip the children the long way. */
8687 return skip_children (reader
, info_ptr
);
8690 /* Expand this partial symbol table into a full symbol table. SELF is
8694 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8696 struct dwarf2_per_objfile
*dwarf2_per_objfile
8697 = get_dwarf2_per_objfile (objfile
);
8699 gdb_assert (!readin
);
8700 /* If this psymtab is constructed from a debug-only objfile, the
8701 has_section_at_zero flag will not necessarily be correct. We
8702 can get the correct value for this flag by looking at the data
8703 associated with the (presumably stripped) associated objfile. */
8704 if (objfile
->separate_debug_objfile_backlink
)
8706 struct dwarf2_per_objfile
*dpo_backlink
8707 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8709 dwarf2_per_objfile
->has_section_at_zero
8710 = dpo_backlink
->has_section_at_zero
;
8713 dwarf2_per_objfile
->reading_partial_symbols
= 0;
8715 expand_psymtab (objfile
);
8717 process_cu_includes (dwarf2_per_objfile
);
8720 /* Reading in full CUs. */
8722 /* Add PER_CU to the queue. */
8725 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8726 enum language pretend_language
)
8729 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8732 /* If PER_CU is not yet queued, add it to the queue.
8733 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8735 The result is non-zero if PER_CU was queued, otherwise the result is zero
8736 meaning either PER_CU is already queued or it is already loaded.
8738 N.B. There is an invariant here that if a CU is queued then it is loaded.
8739 The caller is required to load PER_CU if we return non-zero. */
8742 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8743 struct dwarf2_per_cu_data
*per_cu
,
8744 enum language pretend_language
)
8746 /* We may arrive here during partial symbol reading, if we need full
8747 DIEs to process an unusual case (e.g. template arguments). Do
8748 not queue PER_CU, just tell our caller to load its DIEs. */
8749 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8751 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8756 /* Mark the dependence relation so that we don't flush PER_CU
8758 if (dependent_cu
!= NULL
)
8759 dwarf2_add_dependence (dependent_cu
, per_cu
);
8761 /* If it's already on the queue, we have nothing to do. */
8765 /* If the compilation unit is already loaded, just mark it as
8767 if (per_cu
->cu
!= NULL
)
8769 per_cu
->cu
->last_used
= 0;
8773 /* Add it to the queue. */
8774 queue_comp_unit (per_cu
, pretend_language
);
8779 /* Process the queue. */
8782 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8784 if (dwarf_read_debug
)
8786 fprintf_unfiltered (gdb_stdlog
,
8787 "Expanding one or more symtabs of objfile %s ...\n",
8788 objfile_name (dwarf2_per_objfile
->objfile
));
8791 /* The queue starts out with one item, but following a DIE reference
8792 may load a new CU, adding it to the end of the queue. */
8793 while (!dwarf2_per_objfile
->queue
.empty ())
8795 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8797 if ((dwarf2_per_objfile
->using_index
8798 ? !item
.per_cu
->v
.quick
->compunit_symtab
8799 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8800 /* Skip dummy CUs. */
8801 && item
.per_cu
->cu
!= NULL
)
8803 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8804 unsigned int debug_print_threshold
;
8807 if (per_cu
->is_debug_types
)
8809 struct signatured_type
*sig_type
=
8810 (struct signatured_type
*) per_cu
;
8812 sprintf (buf
, "TU %s at offset %s",
8813 hex_string (sig_type
->signature
),
8814 sect_offset_str (per_cu
->sect_off
));
8815 /* There can be 100s of TUs.
8816 Only print them in verbose mode. */
8817 debug_print_threshold
= 2;
8821 sprintf (buf
, "CU at offset %s",
8822 sect_offset_str (per_cu
->sect_off
));
8823 debug_print_threshold
= 1;
8826 if (dwarf_read_debug
>= debug_print_threshold
)
8827 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8829 if (per_cu
->is_debug_types
)
8830 process_full_type_unit (per_cu
, item
.pretend_language
);
8832 process_full_comp_unit (per_cu
, item
.pretend_language
);
8834 if (dwarf_read_debug
>= debug_print_threshold
)
8835 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8838 item
.per_cu
->queued
= 0;
8839 dwarf2_per_objfile
->queue
.pop ();
8842 if (dwarf_read_debug
)
8844 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8845 objfile_name (dwarf2_per_objfile
->objfile
));
8849 /* Read in full symbols for PST, and anything it depends on. */
8852 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8854 struct dwarf2_per_cu_data
*per_cu
;
8859 read_dependencies (objfile
);
8861 per_cu
= per_cu_data
;
8865 /* It's an include file, no symbols to read for it.
8866 Everything is in the parent symtab. */
8871 dw2_do_instantiate_symtab (per_cu
, false);
8874 /* Trivial hash function for die_info: the hash value of a DIE
8875 is its offset in .debug_info for this objfile. */
8878 die_hash (const void *item
)
8880 const struct die_info
*die
= (const struct die_info
*) item
;
8882 return to_underlying (die
->sect_off
);
8885 /* Trivial comparison function for die_info structures: two DIEs
8886 are equal if they have the same offset. */
8889 die_eq (const void *item_lhs
, const void *item_rhs
)
8891 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8892 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8894 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8897 /* Load the DIEs associated with PER_CU into memory. */
8900 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8902 enum language pretend_language
)
8904 gdb_assert (! this_cu
->is_debug_types
);
8906 cutu_reader
reader (this_cu
, NULL
, 1, 1, skip_partial
);
8910 struct dwarf2_cu
*cu
= reader
.cu
;
8911 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8913 gdb_assert (cu
->die_hash
== NULL
);
8915 htab_create_alloc_ex (cu
->header
.length
/ 12,
8919 &cu
->comp_unit_obstack
,
8920 hashtab_obstack_allocate
,
8921 dummy_obstack_deallocate
);
8923 if (reader
.comp_unit_die
->has_children
)
8924 reader
.comp_unit_die
->child
8925 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8926 &info_ptr
, reader
.comp_unit_die
);
8927 cu
->dies
= reader
.comp_unit_die
;
8928 /* comp_unit_die is not stored in die_hash, no need. */
8930 /* We try not to read any attributes in this function, because not
8931 all CUs needed for references have been loaded yet, and symbol
8932 table processing isn't initialized. But we have to set the CU language,
8933 or we won't be able to build types correctly.
8934 Similarly, if we do not read the producer, we can not apply
8935 producer-specific interpretation. */
8936 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8939 /* Add a DIE to the delayed physname list. */
8942 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8943 const char *name
, struct die_info
*die
,
8944 struct dwarf2_cu
*cu
)
8946 struct delayed_method_info mi
;
8948 mi
.fnfield_index
= fnfield_index
;
8952 cu
->method_list
.push_back (mi
);
8955 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8956 "const" / "volatile". If so, decrements LEN by the length of the
8957 modifier and return true. Otherwise return false. */
8961 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8963 size_t mod_len
= sizeof (mod
) - 1;
8964 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8972 /* Compute the physnames of any methods on the CU's method list.
8974 The computation of method physnames is delayed in order to avoid the
8975 (bad) condition that one of the method's formal parameters is of an as yet
8979 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8981 /* Only C++ delays computing physnames. */
8982 if (cu
->method_list
.empty ())
8984 gdb_assert (cu
->language
== language_cplus
);
8986 for (const delayed_method_info
&mi
: cu
->method_list
)
8988 const char *physname
;
8989 struct fn_fieldlist
*fn_flp
8990 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8991 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8992 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8993 = physname
? physname
: "";
8995 /* Since there's no tag to indicate whether a method is a
8996 const/volatile overload, extract that information out of the
8998 if (physname
!= NULL
)
9000 size_t len
= strlen (physname
);
9004 if (physname
[len
] == ')') /* shortcut */
9006 else if (check_modifier (physname
, len
, " const"))
9007 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9008 else if (check_modifier (physname
, len
, " volatile"))
9009 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9016 /* The list is no longer needed. */
9017 cu
->method_list
.clear ();
9020 /* Go objects should be embedded in a DW_TAG_module DIE,
9021 and it's not clear if/how imported objects will appear.
9022 To keep Go support simple until that's worked out,
9023 go back through what we've read and create something usable.
9024 We could do this while processing each DIE, and feels kinda cleaner,
9025 but that way is more invasive.
9026 This is to, for example, allow the user to type "p var" or "b main"
9027 without having to specify the package name, and allow lookups
9028 of module.object to work in contexts that use the expression
9032 fixup_go_packaging (struct dwarf2_cu
*cu
)
9034 gdb::unique_xmalloc_ptr
<char> package_name
;
9035 struct pending
*list
;
9038 for (list
= *cu
->get_builder ()->get_global_symbols ();
9042 for (i
= 0; i
< list
->nsyms
; ++i
)
9044 struct symbol
*sym
= list
->symbol
[i
];
9046 if (sym
->language () == language_go
9047 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9049 gdb::unique_xmalloc_ptr
<char> this_package_name
9050 (go_symbol_package_name (sym
));
9052 if (this_package_name
== NULL
)
9054 if (package_name
== NULL
)
9055 package_name
= std::move (this_package_name
);
9058 struct objfile
*objfile
9059 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9060 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9061 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9062 (symbol_symtab (sym
) != NULL
9063 ? symtab_to_filename_for_display
9064 (symbol_symtab (sym
))
9065 : objfile_name (objfile
)),
9066 this_package_name
.get (), package_name
.get ());
9072 if (package_name
!= NULL
)
9074 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9075 const char *saved_package_name
9076 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9077 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9078 saved_package_name
);
9081 sym
= allocate_symbol (objfile
);
9082 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9083 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9084 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9085 e.g., "main" finds the "main" module and not C's main(). */
9086 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9087 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9088 SYMBOL_TYPE (sym
) = type
;
9090 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9094 /* Allocate a fully-qualified name consisting of the two parts on the
9098 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9100 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9103 /* A helper that allocates a struct discriminant_info to attach to a
9106 static struct discriminant_info
*
9107 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9110 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9111 gdb_assert (discriminant_index
== -1
9112 || (discriminant_index
>= 0
9113 && discriminant_index
< TYPE_NFIELDS (type
)));
9114 gdb_assert (default_index
== -1
9115 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9117 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9119 struct discriminant_info
*disc
9120 = ((struct discriminant_info
*)
9122 offsetof (struct discriminant_info
, discriminants
)
9123 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9124 disc
->default_index
= default_index
;
9125 disc
->discriminant_index
= discriminant_index
;
9127 struct dynamic_prop prop
;
9128 prop
.kind
= PROP_UNDEFINED
;
9129 prop
.data
.baton
= disc
;
9131 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9136 /* Some versions of rustc emitted enums in an unusual way.
9138 Ordinary enums were emitted as unions. The first element of each
9139 structure in the union was named "RUST$ENUM$DISR". This element
9140 held the discriminant.
9142 These versions of Rust also implemented the "non-zero"
9143 optimization. When the enum had two values, and one is empty and
9144 the other holds a pointer that cannot be zero, the pointer is used
9145 as the discriminant, with a zero value meaning the empty variant.
9146 Here, the union's first member is of the form
9147 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9148 where the fieldnos are the indices of the fields that should be
9149 traversed in order to find the field (which may be several fields deep)
9150 and the variantname is the name of the variant of the case when the
9153 This function recognizes whether TYPE is of one of these forms,
9154 and, if so, smashes it to be a variant type. */
9157 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9159 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9161 /* We don't need to deal with empty enums. */
9162 if (TYPE_NFIELDS (type
) == 0)
9165 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9166 if (TYPE_NFIELDS (type
) == 1
9167 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9169 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9171 /* Decode the field name to find the offset of the
9173 ULONGEST bit_offset
= 0;
9174 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9175 while (name
[0] >= '0' && name
[0] <= '9')
9178 unsigned long index
= strtoul (name
, &tail
, 10);
9181 || index
>= TYPE_NFIELDS (field_type
)
9182 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9183 != FIELD_LOC_KIND_BITPOS
))
9185 complaint (_("Could not parse Rust enum encoding string \"%s\""
9187 TYPE_FIELD_NAME (type
, 0),
9188 objfile_name (objfile
));
9193 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9194 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9197 /* Make a union to hold the variants. */
9198 struct type
*union_type
= alloc_type (objfile
);
9199 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9200 TYPE_NFIELDS (union_type
) = 3;
9201 TYPE_FIELDS (union_type
)
9202 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9203 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9204 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9206 /* Put the discriminant must at index 0. */
9207 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9208 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9209 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9210 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9212 /* The order of fields doesn't really matter, so put the real
9213 field at index 1 and the data-less field at index 2. */
9214 struct discriminant_info
*disc
9215 = alloc_discriminant_info (union_type
, 0, 1);
9216 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9217 TYPE_FIELD_NAME (union_type
, 1)
9218 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9219 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9220 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9221 TYPE_FIELD_NAME (union_type
, 1));
9223 const char *dataless_name
9224 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9226 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9228 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9229 /* NAME points into the original discriminant name, which
9230 already has the correct lifetime. */
9231 TYPE_FIELD_NAME (union_type
, 2) = name
;
9232 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9233 disc
->discriminants
[2] = 0;
9235 /* Smash this type to be a structure type. We have to do this
9236 because the type has already been recorded. */
9237 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9238 TYPE_NFIELDS (type
) = 1;
9240 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9242 /* Install the variant part. */
9243 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9244 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9245 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9247 /* A union with a single anonymous field is probably an old-style
9249 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9251 /* Smash this type to be a structure type. We have to do this
9252 because the type has already been recorded. */
9253 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9255 /* Make a union to hold the variants. */
9256 struct type
*union_type
= alloc_type (objfile
);
9257 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9258 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9259 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9260 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9261 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9263 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9264 const char *variant_name
9265 = rust_last_path_segment (TYPE_NAME (field_type
));
9266 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9267 TYPE_NAME (field_type
)
9268 = rust_fully_qualify (&objfile
->objfile_obstack
,
9269 TYPE_NAME (type
), variant_name
);
9271 /* Install the union in the outer struct type. */
9272 TYPE_NFIELDS (type
) = 1;
9274 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9275 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9276 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9277 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9279 alloc_discriminant_info (union_type
, -1, 0);
9283 struct type
*disr_type
= nullptr;
9284 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9286 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9288 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9290 /* All fields of a true enum will be structs. */
9293 else if (TYPE_NFIELDS (disr_type
) == 0)
9295 /* Could be data-less variant, so keep going. */
9296 disr_type
= nullptr;
9298 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9299 "RUST$ENUM$DISR") != 0)
9301 /* Not a Rust enum. */
9311 /* If we got here without a discriminant, then it's probably
9313 if (disr_type
== nullptr)
9316 /* Smash this type to be a structure type. We have to do this
9317 because the type has already been recorded. */
9318 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9320 /* Make a union to hold the variants. */
9321 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9322 struct type
*union_type
= alloc_type (objfile
);
9323 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9324 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9325 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9326 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9327 TYPE_FIELDS (union_type
)
9328 = (struct field
*) TYPE_ZALLOC (union_type
,
9329 (TYPE_NFIELDS (union_type
)
9330 * sizeof (struct field
)));
9332 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9333 TYPE_NFIELDS (type
) * sizeof (struct field
));
9335 /* Install the discriminant at index 0 in the union. */
9336 TYPE_FIELD (union_type
, 0) = *disr_field
;
9337 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9338 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9340 /* Install the union in the outer struct type. */
9341 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9342 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9343 TYPE_NFIELDS (type
) = 1;
9345 /* Set the size and offset of the union type. */
9346 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9348 /* We need a way to find the correct discriminant given a
9349 variant name. For convenience we build a map here. */
9350 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9351 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9352 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9354 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9357 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9358 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9362 int n_fields
= TYPE_NFIELDS (union_type
);
9363 struct discriminant_info
*disc
9364 = alloc_discriminant_info (union_type
, 0, -1);
9365 /* Skip the discriminant here. */
9366 for (int i
= 1; i
< n_fields
; ++i
)
9368 /* Find the final word in the name of this variant's type.
9369 That name can be used to look up the correct
9371 const char *variant_name
9372 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9375 auto iter
= discriminant_map
.find (variant_name
);
9376 if (iter
!= discriminant_map
.end ())
9377 disc
->discriminants
[i
] = iter
->second
;
9379 /* Remove the discriminant field, if it exists. */
9380 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9381 if (TYPE_NFIELDS (sub_type
) > 0)
9383 --TYPE_NFIELDS (sub_type
);
9384 ++TYPE_FIELDS (sub_type
);
9386 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9387 TYPE_NAME (sub_type
)
9388 = rust_fully_qualify (&objfile
->objfile_obstack
,
9389 TYPE_NAME (type
), variant_name
);
9394 /* Rewrite some Rust unions to be structures with variants parts. */
9397 rust_union_quirks (struct dwarf2_cu
*cu
)
9399 gdb_assert (cu
->language
== language_rust
);
9400 for (type
*type_
: cu
->rust_unions
)
9401 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9402 /* We don't need this any more. */
9403 cu
->rust_unions
.clear ();
9406 /* Return the symtab for PER_CU. This works properly regardless of
9407 whether we're using the index or psymtabs. */
9409 static struct compunit_symtab
*
9410 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9412 return (per_cu
->dwarf2_per_objfile
->using_index
9413 ? per_cu
->v
.quick
->compunit_symtab
9414 : per_cu
->v
.psymtab
->compunit_symtab
);
9417 /* A helper function for computing the list of all symbol tables
9418 included by PER_CU. */
9421 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9422 htab_t all_children
, htab_t all_type_symtabs
,
9423 struct dwarf2_per_cu_data
*per_cu
,
9424 struct compunit_symtab
*immediate_parent
)
9427 struct compunit_symtab
*cust
;
9429 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9432 /* This inclusion and its children have been processed. */
9437 /* Only add a CU if it has a symbol table. */
9438 cust
= get_compunit_symtab (per_cu
);
9441 /* If this is a type unit only add its symbol table if we haven't
9442 seen it yet (type unit per_cu's can share symtabs). */
9443 if (per_cu
->is_debug_types
)
9445 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9449 result
->push_back (cust
);
9450 if (cust
->user
== NULL
)
9451 cust
->user
= immediate_parent
;
9456 result
->push_back (cust
);
9457 if (cust
->user
== NULL
)
9458 cust
->user
= immediate_parent
;
9462 if (!per_cu
->imported_symtabs_empty ())
9463 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9465 recursively_compute_inclusions (result
, all_children
,
9466 all_type_symtabs
, ptr
, cust
);
9470 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9474 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9476 gdb_assert (! per_cu
->is_debug_types
);
9478 if (!per_cu
->imported_symtabs_empty ())
9481 std::vector
<compunit_symtab
*> result_symtabs
;
9482 htab_t all_children
, all_type_symtabs
;
9483 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9485 /* If we don't have a symtab, we can just skip this case. */
9489 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9490 NULL
, xcalloc
, xfree
);
9491 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9492 NULL
, xcalloc
, xfree
);
9494 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9496 recursively_compute_inclusions (&result_symtabs
, all_children
,
9497 all_type_symtabs
, ptr
, cust
);
9500 /* Now we have a transitive closure of all the included symtabs. */
9501 len
= result_symtabs
.size ();
9503 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9504 struct compunit_symtab
*, len
+ 1);
9505 memcpy (cust
->includes
, result_symtabs
.data (),
9506 len
* sizeof (compunit_symtab
*));
9507 cust
->includes
[len
] = NULL
;
9509 htab_delete (all_children
);
9510 htab_delete (all_type_symtabs
);
9514 /* Compute the 'includes' field for the symtabs of all the CUs we just
9518 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9520 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9522 if (! iter
->is_debug_types
)
9523 compute_compunit_symtab_includes (iter
);
9526 dwarf2_per_objfile
->just_read_cus
.clear ();
9529 /* Generate full symbol information for PER_CU, whose DIEs have
9530 already been loaded into memory. */
9533 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9534 enum language pretend_language
)
9536 struct dwarf2_cu
*cu
= per_cu
->cu
;
9537 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9538 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9539 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9540 CORE_ADDR lowpc
, highpc
;
9541 struct compunit_symtab
*cust
;
9543 struct block
*static_block
;
9546 baseaddr
= objfile
->text_section_offset ();
9548 /* Clear the list here in case something was left over. */
9549 cu
->method_list
.clear ();
9551 cu
->language
= pretend_language
;
9552 cu
->language_defn
= language_def (cu
->language
);
9554 /* Do line number decoding in read_file_scope () */
9555 process_die (cu
->dies
, cu
);
9557 /* For now fudge the Go package. */
9558 if (cu
->language
== language_go
)
9559 fixup_go_packaging (cu
);
9561 /* Now that we have processed all the DIEs in the CU, all the types
9562 should be complete, and it should now be safe to compute all of the
9564 compute_delayed_physnames (cu
);
9566 if (cu
->language
== language_rust
)
9567 rust_union_quirks (cu
);
9569 /* Some compilers don't define a DW_AT_high_pc attribute for the
9570 compilation unit. If the DW_AT_high_pc is missing, synthesize
9571 it, by scanning the DIE's below the compilation unit. */
9572 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9574 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9575 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9577 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9578 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9579 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9580 addrmap to help ensure it has an accurate map of pc values belonging to
9582 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9584 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9585 SECT_OFF_TEXT (objfile
),
9590 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9592 /* Set symtab language to language from DW_AT_language. If the
9593 compilation is from a C file generated by language preprocessors, do
9594 not set the language if it was already deduced by start_subfile. */
9595 if (!(cu
->language
== language_c
9596 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9597 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9599 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9600 produce DW_AT_location with location lists but it can be possibly
9601 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9602 there were bugs in prologue debug info, fixed later in GCC-4.5
9603 by "unwind info for epilogues" patch (which is not directly related).
9605 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9606 needed, it would be wrong due to missing DW_AT_producer there.
9608 Still one can confuse GDB by using non-standard GCC compilation
9609 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9611 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9612 cust
->locations_valid
= 1;
9614 if (gcc_4_minor
>= 5)
9615 cust
->epilogue_unwind_valid
= 1;
9617 cust
->call_site_htab
= cu
->call_site_htab
;
9620 if (dwarf2_per_objfile
->using_index
)
9621 per_cu
->v
.quick
->compunit_symtab
= cust
;
9624 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9625 pst
->compunit_symtab
= cust
;
9629 /* Push it for inclusion processing later. */
9630 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9632 /* Not needed any more. */
9633 cu
->reset_builder ();
9636 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9637 already been loaded into memory. */
9640 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9641 enum language pretend_language
)
9643 struct dwarf2_cu
*cu
= per_cu
->cu
;
9644 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9645 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9646 struct compunit_symtab
*cust
;
9647 struct signatured_type
*sig_type
;
9649 gdb_assert (per_cu
->is_debug_types
);
9650 sig_type
= (struct signatured_type
*) per_cu
;
9652 /* Clear the list here in case something was left over. */
9653 cu
->method_list
.clear ();
9655 cu
->language
= pretend_language
;
9656 cu
->language_defn
= language_def (cu
->language
);
9658 /* The symbol tables are set up in read_type_unit_scope. */
9659 process_die (cu
->dies
, cu
);
9661 /* For now fudge the Go package. */
9662 if (cu
->language
== language_go
)
9663 fixup_go_packaging (cu
);
9665 /* Now that we have processed all the DIEs in the CU, all the types
9666 should be complete, and it should now be safe to compute all of the
9668 compute_delayed_physnames (cu
);
9670 if (cu
->language
== language_rust
)
9671 rust_union_quirks (cu
);
9673 /* TUs share symbol tables.
9674 If this is the first TU to use this symtab, complete the construction
9675 of it with end_expandable_symtab. Otherwise, complete the addition of
9676 this TU's symbols to the existing symtab. */
9677 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9679 buildsym_compunit
*builder
= cu
->get_builder ();
9680 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9681 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9685 /* Set symtab language to language from DW_AT_language. If the
9686 compilation is from a C file generated by language preprocessors,
9687 do not set the language if it was already deduced by
9689 if (!(cu
->language
== language_c
9690 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9691 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9696 cu
->get_builder ()->augment_type_symtab ();
9697 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9700 if (dwarf2_per_objfile
->using_index
)
9701 per_cu
->v
.quick
->compunit_symtab
= cust
;
9704 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9705 pst
->compunit_symtab
= cust
;
9709 /* Not needed any more. */
9710 cu
->reset_builder ();
9713 /* Process an imported unit DIE. */
9716 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9718 struct attribute
*attr
;
9720 /* For now we don't handle imported units in type units. */
9721 if (cu
->per_cu
->is_debug_types
)
9723 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9724 " supported in type units [in module %s]"),
9725 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9728 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9731 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9732 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9733 dwarf2_per_cu_data
*per_cu
9734 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9735 cu
->per_cu
->dwarf2_per_objfile
);
9737 /* If necessary, add it to the queue and load its DIEs. */
9738 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9739 load_full_comp_unit (per_cu
, false, cu
->language
);
9741 cu
->per_cu
->imported_symtabs_push (per_cu
);
9745 /* RAII object that represents a process_die scope: i.e.,
9746 starts/finishes processing a DIE. */
9747 class process_die_scope
9750 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9751 : m_die (die
), m_cu (cu
)
9753 /* We should only be processing DIEs not already in process. */
9754 gdb_assert (!m_die
->in_process
);
9755 m_die
->in_process
= true;
9758 ~process_die_scope ()
9760 m_die
->in_process
= false;
9762 /* If we're done processing the DIE for the CU that owns the line
9763 header, we don't need the line header anymore. */
9764 if (m_cu
->line_header_die_owner
== m_die
)
9766 delete m_cu
->line_header
;
9767 m_cu
->line_header
= NULL
;
9768 m_cu
->line_header_die_owner
= NULL
;
9777 /* Process a die and its children. */
9780 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9782 process_die_scope
scope (die
, cu
);
9786 case DW_TAG_padding
:
9788 case DW_TAG_compile_unit
:
9789 case DW_TAG_partial_unit
:
9790 read_file_scope (die
, cu
);
9792 case DW_TAG_type_unit
:
9793 read_type_unit_scope (die
, cu
);
9795 case DW_TAG_subprogram
:
9796 /* Nested subprograms in Fortran get a prefix. */
9797 if (cu
->language
== language_fortran
9798 && die
->parent
!= NULL
9799 && die
->parent
->tag
== DW_TAG_subprogram
)
9800 cu
->processing_has_namespace_info
= true;
9802 case DW_TAG_inlined_subroutine
:
9803 read_func_scope (die
, cu
);
9805 case DW_TAG_lexical_block
:
9806 case DW_TAG_try_block
:
9807 case DW_TAG_catch_block
:
9808 read_lexical_block_scope (die
, cu
);
9810 case DW_TAG_call_site
:
9811 case DW_TAG_GNU_call_site
:
9812 read_call_site_scope (die
, cu
);
9814 case DW_TAG_class_type
:
9815 case DW_TAG_interface_type
:
9816 case DW_TAG_structure_type
:
9817 case DW_TAG_union_type
:
9818 process_structure_scope (die
, cu
);
9820 case DW_TAG_enumeration_type
:
9821 process_enumeration_scope (die
, cu
);
9824 /* These dies have a type, but processing them does not create
9825 a symbol or recurse to process the children. Therefore we can
9826 read them on-demand through read_type_die. */
9827 case DW_TAG_subroutine_type
:
9828 case DW_TAG_set_type
:
9829 case DW_TAG_array_type
:
9830 case DW_TAG_pointer_type
:
9831 case DW_TAG_ptr_to_member_type
:
9832 case DW_TAG_reference_type
:
9833 case DW_TAG_rvalue_reference_type
:
9834 case DW_TAG_string_type
:
9837 case DW_TAG_base_type
:
9838 case DW_TAG_subrange_type
:
9839 case DW_TAG_typedef
:
9840 /* Add a typedef symbol for the type definition, if it has a
9842 new_symbol (die
, read_type_die (die
, cu
), cu
);
9844 case DW_TAG_common_block
:
9845 read_common_block (die
, cu
);
9847 case DW_TAG_common_inclusion
:
9849 case DW_TAG_namespace
:
9850 cu
->processing_has_namespace_info
= true;
9851 read_namespace (die
, cu
);
9854 cu
->processing_has_namespace_info
= true;
9855 read_module (die
, cu
);
9857 case DW_TAG_imported_declaration
:
9858 cu
->processing_has_namespace_info
= true;
9859 if (read_namespace_alias (die
, cu
))
9861 /* The declaration is not a global namespace alias. */
9863 case DW_TAG_imported_module
:
9864 cu
->processing_has_namespace_info
= true;
9865 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9866 || cu
->language
!= language_fortran
))
9867 complaint (_("Tag '%s' has unexpected children"),
9868 dwarf_tag_name (die
->tag
));
9869 read_import_statement (die
, cu
);
9872 case DW_TAG_imported_unit
:
9873 process_imported_unit_die (die
, cu
);
9876 case DW_TAG_variable
:
9877 read_variable (die
, cu
);
9881 new_symbol (die
, NULL
, cu
);
9886 /* DWARF name computation. */
9888 /* A helper function for dwarf2_compute_name which determines whether DIE
9889 needs to have the name of the scope prepended to the name listed in the
9893 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9895 struct attribute
*attr
;
9899 case DW_TAG_namespace
:
9900 case DW_TAG_typedef
:
9901 case DW_TAG_class_type
:
9902 case DW_TAG_interface_type
:
9903 case DW_TAG_structure_type
:
9904 case DW_TAG_union_type
:
9905 case DW_TAG_enumeration_type
:
9906 case DW_TAG_enumerator
:
9907 case DW_TAG_subprogram
:
9908 case DW_TAG_inlined_subroutine
:
9910 case DW_TAG_imported_declaration
:
9913 case DW_TAG_variable
:
9914 case DW_TAG_constant
:
9915 /* We only need to prefix "globally" visible variables. These include
9916 any variable marked with DW_AT_external or any variable that
9917 lives in a namespace. [Variables in anonymous namespaces
9918 require prefixing, but they are not DW_AT_external.] */
9920 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9922 struct dwarf2_cu
*spec_cu
= cu
;
9924 return die_needs_namespace (die_specification (die
, &spec_cu
),
9928 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9929 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9930 && die
->parent
->tag
!= DW_TAG_module
)
9932 /* A variable in a lexical block of some kind does not need a
9933 namespace, even though in C++ such variables may be external
9934 and have a mangled name. */
9935 if (die
->parent
->tag
== DW_TAG_lexical_block
9936 || die
->parent
->tag
== DW_TAG_try_block
9937 || die
->parent
->tag
== DW_TAG_catch_block
9938 || die
->parent
->tag
== DW_TAG_subprogram
)
9947 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9948 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9949 defined for the given DIE. */
9951 static struct attribute
*
9952 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9954 struct attribute
*attr
;
9956 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9958 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9963 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9964 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9965 defined for the given DIE. */
9968 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9970 const char *linkage_name
;
9972 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9973 if (linkage_name
== NULL
)
9974 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9976 return linkage_name
;
9979 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9980 compute the physname for the object, which include a method's:
9981 - formal parameters (C++),
9982 - receiver type (Go),
9984 The term "physname" is a bit confusing.
9985 For C++, for example, it is the demangled name.
9986 For Go, for example, it's the mangled name.
9988 For Ada, return the DIE's linkage name rather than the fully qualified
9989 name. PHYSNAME is ignored..
9991 The result is allocated on the objfile_obstack and canonicalized. */
9994 dwarf2_compute_name (const char *name
,
9995 struct die_info
*die
, struct dwarf2_cu
*cu
,
9998 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10001 name
= dwarf2_name (die
, cu
);
10003 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10004 but otherwise compute it by typename_concat inside GDB.
10005 FIXME: Actually this is not really true, or at least not always true.
10006 It's all very confusing. compute_and_set_names doesn't try to demangle
10007 Fortran names because there is no mangling standard. So new_symbol
10008 will set the demangled name to the result of dwarf2_full_name, and it is
10009 the demangled name that GDB uses if it exists. */
10010 if (cu
->language
== language_ada
10011 || (cu
->language
== language_fortran
&& physname
))
10013 /* For Ada unit, we prefer the linkage name over the name, as
10014 the former contains the exported name, which the user expects
10015 to be able to reference. Ideally, we want the user to be able
10016 to reference this entity using either natural or linkage name,
10017 but we haven't started looking at this enhancement yet. */
10018 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10020 if (linkage_name
!= NULL
)
10021 return linkage_name
;
10024 /* These are the only languages we know how to qualify names in. */
10026 && (cu
->language
== language_cplus
10027 || cu
->language
== language_fortran
|| cu
->language
== language_d
10028 || cu
->language
== language_rust
))
10030 if (die_needs_namespace (die
, cu
))
10032 const char *prefix
;
10033 const char *canonical_name
= NULL
;
10037 prefix
= determine_prefix (die
, cu
);
10038 if (*prefix
!= '\0')
10040 gdb::unique_xmalloc_ptr
<char> prefixed_name
10041 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10043 buf
.puts (prefixed_name
.get ());
10048 /* Template parameters may be specified in the DIE's DW_AT_name, or
10049 as children with DW_TAG_template_type_param or
10050 DW_TAG_value_type_param. If the latter, add them to the name
10051 here. If the name already has template parameters, then
10052 skip this step; some versions of GCC emit both, and
10053 it is more efficient to use the pre-computed name.
10055 Something to keep in mind about this process: it is very
10056 unlikely, or in some cases downright impossible, to produce
10057 something that will match the mangled name of a function.
10058 If the definition of the function has the same debug info,
10059 we should be able to match up with it anyway. But fallbacks
10060 using the minimal symbol, for instance to find a method
10061 implemented in a stripped copy of libstdc++, will not work.
10062 If we do not have debug info for the definition, we will have to
10063 match them up some other way.
10065 When we do name matching there is a related problem with function
10066 templates; two instantiated function templates are allowed to
10067 differ only by their return types, which we do not add here. */
10069 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10071 struct attribute
*attr
;
10072 struct die_info
*child
;
10075 die
->building_fullname
= 1;
10077 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10081 const gdb_byte
*bytes
;
10082 struct dwarf2_locexpr_baton
*baton
;
10085 if (child
->tag
!= DW_TAG_template_type_param
10086 && child
->tag
!= DW_TAG_template_value_param
)
10097 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10100 complaint (_("template parameter missing DW_AT_type"));
10101 buf
.puts ("UNKNOWN_TYPE");
10104 type
= die_type (child
, cu
);
10106 if (child
->tag
== DW_TAG_template_type_param
)
10108 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10109 &type_print_raw_options
);
10113 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10116 complaint (_("template parameter missing "
10117 "DW_AT_const_value"));
10118 buf
.puts ("UNKNOWN_VALUE");
10122 dwarf2_const_value_attr (attr
, type
, name
,
10123 &cu
->comp_unit_obstack
, cu
,
10124 &value
, &bytes
, &baton
);
10126 if (TYPE_NOSIGN (type
))
10127 /* GDB prints characters as NUMBER 'CHAR'. If that's
10128 changed, this can use value_print instead. */
10129 c_printchar (value
, type
, &buf
);
10132 struct value_print_options opts
;
10135 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10139 else if (bytes
!= NULL
)
10141 v
= allocate_value (type
);
10142 memcpy (value_contents_writeable (v
), bytes
,
10143 TYPE_LENGTH (type
));
10146 v
= value_from_longest (type
, value
);
10148 /* Specify decimal so that we do not depend on
10150 get_formatted_print_options (&opts
, 'd');
10152 value_print (v
, &buf
, &opts
);
10157 die
->building_fullname
= 0;
10161 /* Close the argument list, with a space if necessary
10162 (nested templates). */
10163 if (!buf
.empty () && buf
.string ().back () == '>')
10170 /* For C++ methods, append formal parameter type
10171 information, if PHYSNAME. */
10173 if (physname
&& die
->tag
== DW_TAG_subprogram
10174 && cu
->language
== language_cplus
)
10176 struct type
*type
= read_type_die (die
, cu
);
10178 c_type_print_args (type
, &buf
, 1, cu
->language
,
10179 &type_print_raw_options
);
10181 if (cu
->language
== language_cplus
)
10183 /* Assume that an artificial first parameter is
10184 "this", but do not crash if it is not. RealView
10185 marks unnamed (and thus unused) parameters as
10186 artificial; there is no way to differentiate
10188 if (TYPE_NFIELDS (type
) > 0
10189 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10190 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10191 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10193 buf
.puts (" const");
10197 const std::string
&intermediate_name
= buf
.string ();
10199 if (cu
->language
== language_cplus
)
10201 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10202 &objfile
->per_bfd
->storage_obstack
);
10204 /* If we only computed INTERMEDIATE_NAME, or if
10205 INTERMEDIATE_NAME is already canonical, then we need to
10206 copy it to the appropriate obstack. */
10207 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10208 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
10209 intermediate_name
);
10211 name
= canonical_name
;
10218 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10219 If scope qualifiers are appropriate they will be added. The result
10220 will be allocated on the storage_obstack, or NULL if the DIE does
10221 not have a name. NAME may either be from a previous call to
10222 dwarf2_name or NULL.
10224 The output string will be canonicalized (if C++). */
10226 static const char *
10227 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10229 return dwarf2_compute_name (name
, die
, cu
, 0);
10232 /* Construct a physname for the given DIE in CU. NAME may either be
10233 from a previous call to dwarf2_name or NULL. The result will be
10234 allocated on the objfile_objstack or NULL if the DIE does not have a
10237 The output string will be canonicalized (if C++). */
10239 static const char *
10240 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10242 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10243 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10246 /* In this case dwarf2_compute_name is just a shortcut not building anything
10248 if (!die_needs_namespace (die
, cu
))
10249 return dwarf2_compute_name (name
, die
, cu
, 1);
10251 mangled
= dw2_linkage_name (die
, cu
);
10253 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10254 See https://github.com/rust-lang/rust/issues/32925. */
10255 if (cu
->language
== language_rust
&& mangled
!= NULL
10256 && strchr (mangled
, '{') != NULL
)
10259 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10261 gdb::unique_xmalloc_ptr
<char> demangled
;
10262 if (mangled
!= NULL
)
10265 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10267 /* Do nothing (do not demangle the symbol name). */
10269 else if (cu
->language
== language_go
)
10271 /* This is a lie, but we already lie to the caller new_symbol.
10272 new_symbol assumes we return the mangled name.
10273 This just undoes that lie until things are cleaned up. */
10277 /* Use DMGL_RET_DROP for C++ template functions to suppress
10278 their return type. It is easier for GDB users to search
10279 for such functions as `name(params)' than `long name(params)'.
10280 In such case the minimal symbol names do not match the full
10281 symbol names but for template functions there is never a need
10282 to look up their definition from their declaration so
10283 the only disadvantage remains the minimal symbol variant
10284 `long name(params)' does not have the proper inferior type. */
10285 demangled
.reset (gdb_demangle (mangled
,
10286 (DMGL_PARAMS
| DMGL_ANSI
10287 | DMGL_RET_DROP
)));
10290 canon
= demangled
.get ();
10298 if (canon
== NULL
|| check_physname
)
10300 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10302 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10304 /* It may not mean a bug in GDB. The compiler could also
10305 compute DW_AT_linkage_name incorrectly. But in such case
10306 GDB would need to be bug-to-bug compatible. */
10308 complaint (_("Computed physname <%s> does not match demangled <%s> "
10309 "(from linkage <%s>) - DIE at %s [in module %s]"),
10310 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10311 objfile_name (objfile
));
10313 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10314 is available here - over computed PHYSNAME. It is safer
10315 against both buggy GDB and buggy compilers. */
10329 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
10334 /* Inspect DIE in CU for a namespace alias. If one exists, record
10335 a new symbol for it.
10337 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10340 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10342 struct attribute
*attr
;
10344 /* If the die does not have a name, this is not a namespace
10346 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10350 struct die_info
*d
= die
;
10351 struct dwarf2_cu
*imported_cu
= cu
;
10353 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10354 keep inspecting DIEs until we hit the underlying import. */
10355 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10356 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10358 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10362 d
= follow_die_ref (d
, attr
, &imported_cu
);
10363 if (d
->tag
!= DW_TAG_imported_declaration
)
10367 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10369 complaint (_("DIE at %s has too many recursively imported "
10370 "declarations"), sect_offset_str (d
->sect_off
));
10377 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10379 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10380 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10382 /* This declaration is a global namespace alias. Add
10383 a symbol for it whose type is the aliased namespace. */
10384 new_symbol (die
, type
, cu
);
10393 /* Return the using directives repository (global or local?) to use in the
10394 current context for CU.
10396 For Ada, imported declarations can materialize renamings, which *may* be
10397 global. However it is impossible (for now?) in DWARF to distinguish
10398 "external" imported declarations and "static" ones. As all imported
10399 declarations seem to be static in all other languages, make them all CU-wide
10400 global only in Ada. */
10402 static struct using_direct
**
10403 using_directives (struct dwarf2_cu
*cu
)
10405 if (cu
->language
== language_ada
10406 && cu
->get_builder ()->outermost_context_p ())
10407 return cu
->get_builder ()->get_global_using_directives ();
10409 return cu
->get_builder ()->get_local_using_directives ();
10412 /* Read the import statement specified by the given die and record it. */
10415 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10417 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10418 struct attribute
*import_attr
;
10419 struct die_info
*imported_die
, *child_die
;
10420 struct dwarf2_cu
*imported_cu
;
10421 const char *imported_name
;
10422 const char *imported_name_prefix
;
10423 const char *canonical_name
;
10424 const char *import_alias
;
10425 const char *imported_declaration
= NULL
;
10426 const char *import_prefix
;
10427 std::vector
<const char *> excludes
;
10429 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10430 if (import_attr
== NULL
)
10432 complaint (_("Tag '%s' has no DW_AT_import"),
10433 dwarf_tag_name (die
->tag
));
10438 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10439 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10440 if (imported_name
== NULL
)
10442 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10444 The import in the following code:
10458 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10459 <52> DW_AT_decl_file : 1
10460 <53> DW_AT_decl_line : 6
10461 <54> DW_AT_import : <0x75>
10462 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10463 <59> DW_AT_name : B
10464 <5b> DW_AT_decl_file : 1
10465 <5c> DW_AT_decl_line : 2
10466 <5d> DW_AT_type : <0x6e>
10468 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10469 <76> DW_AT_byte_size : 4
10470 <77> DW_AT_encoding : 5 (signed)
10472 imports the wrong die ( 0x75 instead of 0x58 ).
10473 This case will be ignored until the gcc bug is fixed. */
10477 /* Figure out the local name after import. */
10478 import_alias
= dwarf2_name (die
, cu
);
10480 /* Figure out where the statement is being imported to. */
10481 import_prefix
= determine_prefix (die
, cu
);
10483 /* Figure out what the scope of the imported die is and prepend it
10484 to the name of the imported die. */
10485 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10487 if (imported_die
->tag
!= DW_TAG_namespace
10488 && imported_die
->tag
!= DW_TAG_module
)
10490 imported_declaration
= imported_name
;
10491 canonical_name
= imported_name_prefix
;
10493 else if (strlen (imported_name_prefix
) > 0)
10494 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10495 imported_name_prefix
,
10496 (cu
->language
== language_d
? "." : "::"),
10497 imported_name
, (char *) NULL
);
10499 canonical_name
= imported_name
;
10501 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10502 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10503 child_die
= sibling_die (child_die
))
10505 /* DWARF-4: A Fortran use statement with a “rename list” may be
10506 represented by an imported module entry with an import attribute
10507 referring to the module and owned entries corresponding to those
10508 entities that are renamed as part of being imported. */
10510 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10512 complaint (_("child DW_TAG_imported_declaration expected "
10513 "- DIE at %s [in module %s]"),
10514 sect_offset_str (child_die
->sect_off
),
10515 objfile_name (objfile
));
10519 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10520 if (import_attr
== NULL
)
10522 complaint (_("Tag '%s' has no DW_AT_import"),
10523 dwarf_tag_name (child_die
->tag
));
10528 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10530 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10531 if (imported_name
== NULL
)
10533 complaint (_("child DW_TAG_imported_declaration has unknown "
10534 "imported name - DIE at %s [in module %s]"),
10535 sect_offset_str (child_die
->sect_off
),
10536 objfile_name (objfile
));
10540 excludes
.push_back (imported_name
);
10542 process_die (child_die
, cu
);
10545 add_using_directive (using_directives (cu
),
10549 imported_declaration
,
10552 &objfile
->objfile_obstack
);
10555 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10556 types, but gives them a size of zero. Starting with version 14,
10557 ICC is compatible with GCC. */
10560 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10562 if (!cu
->checked_producer
)
10563 check_producer (cu
);
10565 return cu
->producer_is_icc_lt_14
;
10568 /* ICC generates a DW_AT_type for C void functions. This was observed on
10569 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10570 which says that void functions should not have a DW_AT_type. */
10573 producer_is_icc (struct dwarf2_cu
*cu
)
10575 if (!cu
->checked_producer
)
10576 check_producer (cu
);
10578 return cu
->producer_is_icc
;
10581 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10582 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10583 this, it was first present in GCC release 4.3.0. */
10586 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10588 if (!cu
->checked_producer
)
10589 check_producer (cu
);
10591 return cu
->producer_is_gcc_lt_4_3
;
10594 static file_and_directory
10595 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10597 file_and_directory res
;
10599 /* Find the filename. Do not use dwarf2_name here, since the filename
10600 is not a source language identifier. */
10601 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10602 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10604 if (res
.comp_dir
== NULL
10605 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10606 && IS_ABSOLUTE_PATH (res
.name
))
10608 res
.comp_dir_storage
= ldirname (res
.name
);
10609 if (!res
.comp_dir_storage
.empty ())
10610 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10612 if (res
.comp_dir
!= NULL
)
10614 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10615 directory, get rid of it. */
10616 const char *cp
= strchr (res
.comp_dir
, ':');
10618 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10619 res
.comp_dir
= cp
+ 1;
10622 if (res
.name
== NULL
)
10623 res
.name
= "<unknown>";
10628 /* Handle DW_AT_stmt_list for a compilation unit.
10629 DIE is the DW_TAG_compile_unit die for CU.
10630 COMP_DIR is the compilation directory. LOWPC is passed to
10631 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10634 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10635 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10637 struct dwarf2_per_objfile
*dwarf2_per_objfile
10638 = cu
->per_cu
->dwarf2_per_objfile
;
10639 struct attribute
*attr
;
10640 struct line_header line_header_local
;
10641 hashval_t line_header_local_hash
;
10643 int decode_mapping
;
10645 gdb_assert (! cu
->per_cu
->is_debug_types
);
10647 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10651 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10653 /* The line header hash table is only created if needed (it exists to
10654 prevent redundant reading of the line table for partial_units).
10655 If we're given a partial_unit, we'll need it. If we're given a
10656 compile_unit, then use the line header hash table if it's already
10657 created, but don't create one just yet. */
10659 if (dwarf2_per_objfile
->line_header_hash
== NULL
10660 && die
->tag
== DW_TAG_partial_unit
)
10662 dwarf2_per_objfile
->line_header_hash
10663 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10664 line_header_eq_voidp
,
10665 free_line_header_voidp
,
10669 line_header_local
.sect_off
= line_offset
;
10670 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10671 line_header_local_hash
= line_header_hash (&line_header_local
);
10672 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10674 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10675 &line_header_local
,
10676 line_header_local_hash
, NO_INSERT
);
10678 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10679 is not present in *SLOT (since if there is something in *SLOT then
10680 it will be for a partial_unit). */
10681 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10683 gdb_assert (*slot
!= NULL
);
10684 cu
->line_header
= (struct line_header
*) *slot
;
10689 /* dwarf_decode_line_header does not yet provide sufficient information.
10690 We always have to call also dwarf_decode_lines for it. */
10691 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10695 cu
->line_header
= lh
.release ();
10696 cu
->line_header_die_owner
= die
;
10698 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10702 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10703 &line_header_local
,
10704 line_header_local_hash
, INSERT
);
10705 gdb_assert (slot
!= NULL
);
10707 if (slot
!= NULL
&& *slot
== NULL
)
10709 /* This newly decoded line number information unit will be owned
10710 by line_header_hash hash table. */
10711 *slot
= cu
->line_header
;
10712 cu
->line_header_die_owner
= NULL
;
10716 /* We cannot free any current entry in (*slot) as that struct line_header
10717 may be already used by multiple CUs. Create only temporary decoded
10718 line_header for this CU - it may happen at most once for each line
10719 number information unit. And if we're not using line_header_hash
10720 then this is what we want as well. */
10721 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10723 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10724 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10729 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10732 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10734 struct dwarf2_per_objfile
*dwarf2_per_objfile
10735 = cu
->per_cu
->dwarf2_per_objfile
;
10736 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10737 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10738 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10739 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10740 struct attribute
*attr
;
10741 struct die_info
*child_die
;
10742 CORE_ADDR baseaddr
;
10744 prepare_one_comp_unit (cu
, die
, cu
->language
);
10745 baseaddr
= objfile
->text_section_offset ();
10747 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10749 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10750 from finish_block. */
10751 if (lowpc
== ((CORE_ADDR
) -1))
10753 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10755 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10757 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10758 standardised yet. As a workaround for the language detection we fall
10759 back to the DW_AT_producer string. */
10760 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10761 cu
->language
= language_opencl
;
10763 /* Similar hack for Go. */
10764 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10765 set_cu_language (DW_LANG_Go
, cu
);
10767 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10769 /* Decode line number information if present. We do this before
10770 processing child DIEs, so that the line header table is available
10771 for DW_AT_decl_file. */
10772 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10774 /* Process all dies in compilation unit. */
10775 if (die
->child
!= NULL
)
10777 child_die
= die
->child
;
10778 while (child_die
&& child_die
->tag
)
10780 process_die (child_die
, cu
);
10781 child_die
= sibling_die (child_die
);
10785 /* Decode macro information, if present. Dwarf 2 macro information
10786 refers to information in the line number info statement program
10787 header, so we can only read it if we've read the header
10789 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10791 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10792 if (attr
&& cu
->line_header
)
10794 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10795 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10797 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10801 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10802 if (attr
&& cu
->line_header
)
10804 unsigned int macro_offset
= DW_UNSND (attr
);
10806 dwarf_decode_macros (cu
, macro_offset
, 0);
10812 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10814 struct type_unit_group
*tu_group
;
10816 struct attribute
*attr
;
10818 struct signatured_type
*sig_type
;
10820 gdb_assert (per_cu
->is_debug_types
);
10821 sig_type
= (struct signatured_type
*) per_cu
;
10823 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10825 /* If we're using .gdb_index (includes -readnow) then
10826 per_cu->type_unit_group may not have been set up yet. */
10827 if (sig_type
->type_unit_group
== NULL
)
10828 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10829 tu_group
= sig_type
->type_unit_group
;
10831 /* If we've already processed this stmt_list there's no real need to
10832 do it again, we could fake it and just recreate the part we need
10833 (file name,index -> symtab mapping). If data shows this optimization
10834 is useful we can do it then. */
10835 first_time
= tu_group
->compunit_symtab
== NULL
;
10837 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10842 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10843 lh
= dwarf_decode_line_header (line_offset
, this);
10848 start_symtab ("", NULL
, 0);
10851 gdb_assert (tu_group
->symtabs
== NULL
);
10852 gdb_assert (m_builder
== nullptr);
10853 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10854 m_builder
.reset (new struct buildsym_compunit
10855 (COMPUNIT_OBJFILE (cust
), "",
10856 COMPUNIT_DIRNAME (cust
),
10857 compunit_language (cust
),
10863 line_header
= lh
.release ();
10864 line_header_die_owner
= die
;
10868 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10870 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10871 still initializing it, and our caller (a few levels up)
10872 process_full_type_unit still needs to know if this is the first
10875 tu_group
->num_symtabs
= line_header
->file_names_size ();
10876 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
10877 line_header
->file_names_size ());
10879 auto &file_names
= line_header
->file_names ();
10880 for (i
= 0; i
< file_names
.size (); ++i
)
10882 file_entry
&fe
= file_names
[i
];
10883 dwarf2_start_subfile (this, fe
.name
,
10884 fe
.include_dir (line_header
));
10885 buildsym_compunit
*b
= get_builder ();
10886 if (b
->get_current_subfile ()->symtab
== NULL
)
10888 /* NOTE: start_subfile will recognize when it's been
10889 passed a file it has already seen. So we can't
10890 assume there's a simple mapping from
10891 cu->line_header->file_names to subfiles, plus
10892 cu->line_header->file_names may contain dups. */
10893 b
->get_current_subfile ()->symtab
10894 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10897 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10898 tu_group
->symtabs
[i
] = fe
.symtab
;
10903 gdb_assert (m_builder
== nullptr);
10904 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10905 m_builder
.reset (new struct buildsym_compunit
10906 (COMPUNIT_OBJFILE (cust
), "",
10907 COMPUNIT_DIRNAME (cust
),
10908 compunit_language (cust
),
10911 auto &file_names
= line_header
->file_names ();
10912 for (i
= 0; i
< file_names
.size (); ++i
)
10914 file_entry
&fe
= file_names
[i
];
10915 fe
.symtab
= tu_group
->symtabs
[i
];
10919 /* The main symtab is allocated last. Type units don't have DW_AT_name
10920 so they don't have a "real" (so to speak) symtab anyway.
10921 There is later code that will assign the main symtab to all symbols
10922 that don't have one. We need to handle the case of a symbol with a
10923 missing symtab (DW_AT_decl_file) anyway. */
10926 /* Process DW_TAG_type_unit.
10927 For TUs we want to skip the first top level sibling if it's not the
10928 actual type being defined by this TU. In this case the first top
10929 level sibling is there to provide context only. */
10932 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10934 struct die_info
*child_die
;
10936 prepare_one_comp_unit (cu
, die
, language_minimal
);
10938 /* Initialize (or reinitialize) the machinery for building symtabs.
10939 We do this before processing child DIEs, so that the line header table
10940 is available for DW_AT_decl_file. */
10941 cu
->setup_type_unit_groups (die
);
10943 if (die
->child
!= NULL
)
10945 child_die
= die
->child
;
10946 while (child_die
&& child_die
->tag
)
10948 process_die (child_die
, cu
);
10949 child_die
= sibling_die (child_die
);
10956 http://gcc.gnu.org/wiki/DebugFission
10957 http://gcc.gnu.org/wiki/DebugFissionDWP
10959 To simplify handling of both DWO files ("object" files with the DWARF info)
10960 and DWP files (a file with the DWOs packaged up into one file), we treat
10961 DWP files as having a collection of virtual DWO files. */
10964 hash_dwo_file (const void *item
)
10966 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10969 hash
= htab_hash_string (dwo_file
->dwo_name
);
10970 if (dwo_file
->comp_dir
!= NULL
)
10971 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10976 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10978 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10979 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10981 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10983 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10984 return lhs
->comp_dir
== rhs
->comp_dir
;
10985 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10988 /* Allocate a hash table for DWO files. */
10991 allocate_dwo_file_hash_table (struct objfile
*objfile
)
10993 auto delete_dwo_file
= [] (void *item
)
10995 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11000 return htab_up (htab_create_alloc (41,
11007 /* Lookup DWO file DWO_NAME. */
11010 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11011 const char *dwo_name
,
11012 const char *comp_dir
)
11014 struct dwo_file find_entry
;
11017 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11018 dwarf2_per_objfile
->dwo_files
11019 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11021 find_entry
.dwo_name
= dwo_name
;
11022 find_entry
.comp_dir
= comp_dir
;
11023 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11030 hash_dwo_unit (const void *item
)
11032 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11034 /* This drops the top 32 bits of the id, but is ok for a hash. */
11035 return dwo_unit
->signature
;
11039 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11041 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11042 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11044 /* The signature is assumed to be unique within the DWO file.
11045 So while object file CU dwo_id's always have the value zero,
11046 that's OK, assuming each object file DWO file has only one CU,
11047 and that's the rule for now. */
11048 return lhs
->signature
== rhs
->signature
;
11051 /* Allocate a hash table for DWO CUs,TUs.
11052 There is one of these tables for each of CUs,TUs for each DWO file. */
11055 allocate_dwo_unit_table (struct objfile
*objfile
)
11057 /* Start out with a pretty small number.
11058 Generally DWO files contain only one CU and maybe some TUs. */
11059 return htab_up (htab_create_alloc (3,
11062 NULL
, xcalloc
, xfree
));
11065 /* die_reader_func for create_dwo_cu. */
11068 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11069 const gdb_byte
*info_ptr
,
11070 struct die_info
*comp_unit_die
,
11071 struct dwo_file
*dwo_file
,
11072 struct dwo_unit
*dwo_unit
)
11074 struct dwarf2_cu
*cu
= reader
->cu
;
11075 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11076 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11078 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11079 if (!signature
.has_value ())
11081 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11082 " its dwo_id [in module %s]"),
11083 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11087 dwo_unit
->dwo_file
= dwo_file
;
11088 dwo_unit
->signature
= *signature
;
11089 dwo_unit
->section
= section
;
11090 dwo_unit
->sect_off
= sect_off
;
11091 dwo_unit
->length
= cu
->per_cu
->length
;
11093 if (dwarf_read_debug
)
11094 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11095 sect_offset_str (sect_off
),
11096 hex_string (dwo_unit
->signature
));
11099 /* Create the dwo_units for the CUs in a DWO_FILE.
11100 Note: This function processes DWO files only, not DWP files. */
11103 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11104 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11105 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11107 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11108 const gdb_byte
*info_ptr
, *end_ptr
;
11110 section
.read (objfile
);
11111 info_ptr
= section
.buffer
;
11113 if (info_ptr
== NULL
)
11116 if (dwarf_read_debug
)
11118 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11119 section
.get_name (),
11120 section
.get_file_name ());
11123 end_ptr
= info_ptr
+ section
.size
;
11124 while (info_ptr
< end_ptr
)
11126 struct dwarf2_per_cu_data per_cu
;
11127 struct dwo_unit read_unit
{};
11128 struct dwo_unit
*dwo_unit
;
11130 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11132 memset (&per_cu
, 0, sizeof (per_cu
));
11133 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11134 per_cu
.is_debug_types
= 0;
11135 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11136 per_cu
.section
= §ion
;
11138 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11139 if (!reader
.dummy_p
)
11140 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11141 &dwo_file
, &read_unit
);
11142 info_ptr
+= per_cu
.length
;
11144 // If the unit could not be parsed, skip it.
11145 if (read_unit
.dwo_file
== NULL
)
11148 if (cus_htab
== NULL
)
11149 cus_htab
= allocate_dwo_unit_table (objfile
);
11151 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11152 *dwo_unit
= read_unit
;
11153 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11154 gdb_assert (slot
!= NULL
);
11157 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11158 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11160 complaint (_("debug cu entry at offset %s is duplicate to"
11161 " the entry at offset %s, signature %s"),
11162 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11163 hex_string (dwo_unit
->signature
));
11165 *slot
= (void *)dwo_unit
;
11169 /* DWP file .debug_{cu,tu}_index section format:
11170 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11174 Both index sections have the same format, and serve to map a 64-bit
11175 signature to a set of section numbers. Each section begins with a header,
11176 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11177 indexes, and a pool of 32-bit section numbers. The index sections will be
11178 aligned at 8-byte boundaries in the file.
11180 The index section header consists of:
11182 V, 32 bit version number
11184 N, 32 bit number of compilation units or type units in the index
11185 M, 32 bit number of slots in the hash table
11187 Numbers are recorded using the byte order of the application binary.
11189 The hash table begins at offset 16 in the section, and consists of an array
11190 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11191 order of the application binary). Unused slots in the hash table are 0.
11192 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11194 The parallel table begins immediately after the hash table
11195 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11196 array of 32-bit indexes (using the byte order of the application binary),
11197 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11198 table contains a 32-bit index into the pool of section numbers. For unused
11199 hash table slots, the corresponding entry in the parallel table will be 0.
11201 The pool of section numbers begins immediately following the hash table
11202 (at offset 16 + 12 * M from the beginning of the section). The pool of
11203 section numbers consists of an array of 32-bit words (using the byte order
11204 of the application binary). Each item in the array is indexed starting
11205 from 0. The hash table entry provides the index of the first section
11206 number in the set. Additional section numbers in the set follow, and the
11207 set is terminated by a 0 entry (section number 0 is not used in ELF).
11209 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11210 section must be the first entry in the set, and the .debug_abbrev.dwo must
11211 be the second entry. Other members of the set may follow in any order.
11217 DWP Version 2 combines all the .debug_info, etc. sections into one,
11218 and the entries in the index tables are now offsets into these sections.
11219 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11222 Index Section Contents:
11224 Hash Table of Signatures dwp_hash_table.hash_table
11225 Parallel Table of Indices dwp_hash_table.unit_table
11226 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11227 Table of Section Sizes dwp_hash_table.v2.sizes
11229 The index section header consists of:
11231 V, 32 bit version number
11232 L, 32 bit number of columns in the table of section offsets
11233 N, 32 bit number of compilation units or type units in the index
11234 M, 32 bit number of slots in the hash table
11236 Numbers are recorded using the byte order of the application binary.
11238 The hash table has the same format as version 1.
11239 The parallel table of indices has the same format as version 1,
11240 except that the entries are origin-1 indices into the table of sections
11241 offsets and the table of section sizes.
11243 The table of offsets begins immediately following the parallel table
11244 (at offset 16 + 12 * M from the beginning of the section). The table is
11245 a two-dimensional array of 32-bit words (using the byte order of the
11246 application binary), with L columns and N+1 rows, in row-major order.
11247 Each row in the array is indexed starting from 0. The first row provides
11248 a key to the remaining rows: each column in this row provides an identifier
11249 for a debug section, and the offsets in the same column of subsequent rows
11250 refer to that section. The section identifiers are:
11252 DW_SECT_INFO 1 .debug_info.dwo
11253 DW_SECT_TYPES 2 .debug_types.dwo
11254 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11255 DW_SECT_LINE 4 .debug_line.dwo
11256 DW_SECT_LOC 5 .debug_loc.dwo
11257 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11258 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11259 DW_SECT_MACRO 8 .debug_macro.dwo
11261 The offsets provided by the CU and TU index sections are the base offsets
11262 for the contributions made by each CU or TU to the corresponding section
11263 in the package file. Each CU and TU header contains an abbrev_offset
11264 field, used to find the abbreviations table for that CU or TU within the
11265 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11266 be interpreted as relative to the base offset given in the index section.
11267 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11268 should be interpreted as relative to the base offset for .debug_line.dwo,
11269 and offsets into other debug sections obtained from DWARF attributes should
11270 also be interpreted as relative to the corresponding base offset.
11272 The table of sizes begins immediately following the table of offsets.
11273 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11274 with L columns and N rows, in row-major order. Each row in the array is
11275 indexed starting from 1 (row 0 is shared by the two tables).
11279 Hash table lookup is handled the same in version 1 and 2:
11281 We assume that N and M will not exceed 2^32 - 1.
11282 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11284 Given a 64-bit compilation unit signature or a type signature S, an entry
11285 in the hash table is located as follows:
11287 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11288 the low-order k bits all set to 1.
11290 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11292 3) If the hash table entry at index H matches the signature, use that
11293 entry. If the hash table entry at index H is unused (all zeroes),
11294 terminate the search: the signature is not present in the table.
11296 4) Let H = (H + H') modulo M. Repeat at Step 3.
11298 Because M > N and H' and M are relatively prime, the search is guaranteed
11299 to stop at an unused slot or find the match. */
11301 /* Create a hash table to map DWO IDs to their CU/TU entry in
11302 .debug_{info,types}.dwo in DWP_FILE.
11303 Returns NULL if there isn't one.
11304 Note: This function processes DWP files only, not DWO files. */
11306 static struct dwp_hash_table
*
11307 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11308 struct dwp_file
*dwp_file
, int is_debug_types
)
11310 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11311 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11312 const gdb_byte
*index_ptr
, *index_end
;
11313 struct dwarf2_section_info
*index
;
11314 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11315 struct dwp_hash_table
*htab
;
11317 if (is_debug_types
)
11318 index
= &dwp_file
->sections
.tu_index
;
11320 index
= &dwp_file
->sections
.cu_index
;
11322 if (index
->empty ())
11324 index
->read (objfile
);
11326 index_ptr
= index
->buffer
;
11327 index_end
= index_ptr
+ index
->size
;
11329 version
= read_4_bytes (dbfd
, index_ptr
);
11332 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11336 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11338 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11341 if (version
!= 1 && version
!= 2)
11343 error (_("Dwarf Error: unsupported DWP file version (%s)"
11344 " [in module %s]"),
11345 pulongest (version
), dwp_file
->name
);
11347 if (nr_slots
!= (nr_slots
& -nr_slots
))
11349 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11350 " is not power of 2 [in module %s]"),
11351 pulongest (nr_slots
), dwp_file
->name
);
11354 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11355 htab
->version
= version
;
11356 htab
->nr_columns
= nr_columns
;
11357 htab
->nr_units
= nr_units
;
11358 htab
->nr_slots
= nr_slots
;
11359 htab
->hash_table
= index_ptr
;
11360 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11362 /* Exit early if the table is empty. */
11363 if (nr_slots
== 0 || nr_units
== 0
11364 || (version
== 2 && nr_columns
== 0))
11366 /* All must be zero. */
11367 if (nr_slots
!= 0 || nr_units
!= 0
11368 || (version
== 2 && nr_columns
!= 0))
11370 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11371 " all zero [in modules %s]"),
11379 htab
->section_pool
.v1
.indices
=
11380 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11381 /* It's harder to decide whether the section is too small in v1.
11382 V1 is deprecated anyway so we punt. */
11386 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11387 int *ids
= htab
->section_pool
.v2
.section_ids
;
11388 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11389 /* Reverse map for error checking. */
11390 int ids_seen
[DW_SECT_MAX
+ 1];
11393 if (nr_columns
< 2)
11395 error (_("Dwarf Error: bad DWP hash table, too few columns"
11396 " in section table [in module %s]"),
11399 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11401 error (_("Dwarf Error: bad DWP hash table, too many columns"
11402 " in section table [in module %s]"),
11405 memset (ids
, 255, sizeof_ids
);
11406 memset (ids_seen
, 255, sizeof (ids_seen
));
11407 for (i
= 0; i
< nr_columns
; ++i
)
11409 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11411 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11413 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11414 " in section table [in module %s]"),
11415 id
, dwp_file
->name
);
11417 if (ids_seen
[id
] != -1)
11419 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11420 " id %d in section table [in module %s]"),
11421 id
, dwp_file
->name
);
11426 /* Must have exactly one info or types section. */
11427 if (((ids_seen
[DW_SECT_INFO
] != -1)
11428 + (ids_seen
[DW_SECT_TYPES
] != -1))
11431 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11432 " DWO info/types section [in module %s]"),
11435 /* Must have an abbrev section. */
11436 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11438 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11439 " section [in module %s]"),
11442 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11443 htab
->section_pool
.v2
.sizes
=
11444 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11445 * nr_units
* nr_columns
);
11446 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11447 * nr_units
* nr_columns
))
11450 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11451 " [in module %s]"),
11459 /* Update SECTIONS with the data from SECTP.
11461 This function is like the other "locate" section routines that are
11462 passed to bfd_map_over_sections, but in this context the sections to
11463 read comes from the DWP V1 hash table, not the full ELF section table.
11465 The result is non-zero for success, or zero if an error was found. */
11468 locate_v1_virtual_dwo_sections (asection
*sectp
,
11469 struct virtual_v1_dwo_sections
*sections
)
11471 const struct dwop_section_names
*names
= &dwop_section_names
;
11473 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11475 /* There can be only one. */
11476 if (sections
->abbrev
.s
.section
!= NULL
)
11478 sections
->abbrev
.s
.section
= sectp
;
11479 sections
->abbrev
.size
= bfd_section_size (sectp
);
11481 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11482 || section_is_p (sectp
->name
, &names
->types_dwo
))
11484 /* There can be only one. */
11485 if (sections
->info_or_types
.s
.section
!= NULL
)
11487 sections
->info_or_types
.s
.section
= sectp
;
11488 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11490 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11492 /* There can be only one. */
11493 if (sections
->line
.s
.section
!= NULL
)
11495 sections
->line
.s
.section
= sectp
;
11496 sections
->line
.size
= bfd_section_size (sectp
);
11498 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11500 /* There can be only one. */
11501 if (sections
->loc
.s
.section
!= NULL
)
11503 sections
->loc
.s
.section
= sectp
;
11504 sections
->loc
.size
= bfd_section_size (sectp
);
11506 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11508 /* There can be only one. */
11509 if (sections
->macinfo
.s
.section
!= NULL
)
11511 sections
->macinfo
.s
.section
= sectp
;
11512 sections
->macinfo
.size
= bfd_section_size (sectp
);
11514 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11516 /* There can be only one. */
11517 if (sections
->macro
.s
.section
!= NULL
)
11519 sections
->macro
.s
.section
= sectp
;
11520 sections
->macro
.size
= bfd_section_size (sectp
);
11522 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11524 /* There can be only one. */
11525 if (sections
->str_offsets
.s
.section
!= NULL
)
11527 sections
->str_offsets
.s
.section
= sectp
;
11528 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11532 /* No other kind of section is valid. */
11539 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11540 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11541 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11542 This is for DWP version 1 files. */
11544 static struct dwo_unit
*
11545 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11546 struct dwp_file
*dwp_file
,
11547 uint32_t unit_index
,
11548 const char *comp_dir
,
11549 ULONGEST signature
, int is_debug_types
)
11551 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11552 const struct dwp_hash_table
*dwp_htab
=
11553 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11554 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11555 const char *kind
= is_debug_types
? "TU" : "CU";
11556 struct dwo_file
*dwo_file
;
11557 struct dwo_unit
*dwo_unit
;
11558 struct virtual_v1_dwo_sections sections
;
11559 void **dwo_file_slot
;
11562 gdb_assert (dwp_file
->version
== 1);
11564 if (dwarf_read_debug
)
11566 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11568 pulongest (unit_index
), hex_string (signature
),
11572 /* Fetch the sections of this DWO unit.
11573 Put a limit on the number of sections we look for so that bad data
11574 doesn't cause us to loop forever. */
11576 #define MAX_NR_V1_DWO_SECTIONS \
11577 (1 /* .debug_info or .debug_types */ \
11578 + 1 /* .debug_abbrev */ \
11579 + 1 /* .debug_line */ \
11580 + 1 /* .debug_loc */ \
11581 + 1 /* .debug_str_offsets */ \
11582 + 1 /* .debug_macro or .debug_macinfo */ \
11583 + 1 /* trailing zero */)
11585 memset (§ions
, 0, sizeof (sections
));
11587 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11590 uint32_t section_nr
=
11591 read_4_bytes (dbfd
,
11592 dwp_htab
->section_pool
.v1
.indices
11593 + (unit_index
+ i
) * sizeof (uint32_t));
11595 if (section_nr
== 0)
11597 if (section_nr
>= dwp_file
->num_sections
)
11599 error (_("Dwarf Error: bad DWP hash table, section number too large"
11600 " [in module %s]"),
11604 sectp
= dwp_file
->elf_sections
[section_nr
];
11605 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11607 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11608 " [in module %s]"),
11614 || sections
.info_or_types
.empty ()
11615 || sections
.abbrev
.empty ())
11617 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11618 " [in module %s]"),
11621 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11623 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11624 " [in module %s]"),
11628 /* It's easier for the rest of the code if we fake a struct dwo_file and
11629 have dwo_unit "live" in that. At least for now.
11631 The DWP file can be made up of a random collection of CUs and TUs.
11632 However, for each CU + set of TUs that came from the same original DWO
11633 file, we can combine them back into a virtual DWO file to save space
11634 (fewer struct dwo_file objects to allocate). Remember that for really
11635 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11637 std::string virtual_dwo_name
=
11638 string_printf ("virtual-dwo/%d-%d-%d-%d",
11639 sections
.abbrev
.get_id (),
11640 sections
.line
.get_id (),
11641 sections
.loc
.get_id (),
11642 sections
.str_offsets
.get_id ());
11643 /* Can we use an existing virtual DWO file? */
11644 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11645 virtual_dwo_name
.c_str (),
11647 /* Create one if necessary. */
11648 if (*dwo_file_slot
== NULL
)
11650 if (dwarf_read_debug
)
11652 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11653 virtual_dwo_name
.c_str ());
11655 dwo_file
= new struct dwo_file
;
11656 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11658 dwo_file
->comp_dir
= comp_dir
;
11659 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11660 dwo_file
->sections
.line
= sections
.line
;
11661 dwo_file
->sections
.loc
= sections
.loc
;
11662 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11663 dwo_file
->sections
.macro
= sections
.macro
;
11664 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11665 /* The "str" section is global to the entire DWP file. */
11666 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11667 /* The info or types section is assigned below to dwo_unit,
11668 there's no need to record it in dwo_file.
11669 Also, we can't simply record type sections in dwo_file because
11670 we record a pointer into the vector in dwo_unit. As we collect more
11671 types we'll grow the vector and eventually have to reallocate space
11672 for it, invalidating all copies of pointers into the previous
11674 *dwo_file_slot
= dwo_file
;
11678 if (dwarf_read_debug
)
11680 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11681 virtual_dwo_name
.c_str ());
11683 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11686 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11687 dwo_unit
->dwo_file
= dwo_file
;
11688 dwo_unit
->signature
= signature
;
11689 dwo_unit
->section
=
11690 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11691 *dwo_unit
->section
= sections
.info_or_types
;
11692 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11697 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11698 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11699 piece within that section used by a TU/CU, return a virtual section
11700 of just that piece. */
11702 static struct dwarf2_section_info
11703 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11704 struct dwarf2_section_info
*section
,
11705 bfd_size_type offset
, bfd_size_type size
)
11707 struct dwarf2_section_info result
;
11710 gdb_assert (section
!= NULL
);
11711 gdb_assert (!section
->is_virtual
);
11713 memset (&result
, 0, sizeof (result
));
11714 result
.s
.containing_section
= section
;
11715 result
.is_virtual
= true;
11720 sectp
= section
->get_bfd_section ();
11722 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11723 bounds of the real section. This is a pretty-rare event, so just
11724 flag an error (easier) instead of a warning and trying to cope. */
11726 || offset
+ size
> bfd_section_size (sectp
))
11728 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11729 " in section %s [in module %s]"),
11730 sectp
? bfd_section_name (sectp
) : "<unknown>",
11731 objfile_name (dwarf2_per_objfile
->objfile
));
11734 result
.virtual_offset
= offset
;
11735 result
.size
= size
;
11739 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11740 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11741 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11742 This is for DWP version 2 files. */
11744 static struct dwo_unit
*
11745 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11746 struct dwp_file
*dwp_file
,
11747 uint32_t unit_index
,
11748 const char *comp_dir
,
11749 ULONGEST signature
, int is_debug_types
)
11751 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11752 const struct dwp_hash_table
*dwp_htab
=
11753 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11754 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11755 const char *kind
= is_debug_types
? "TU" : "CU";
11756 struct dwo_file
*dwo_file
;
11757 struct dwo_unit
*dwo_unit
;
11758 struct virtual_v2_dwo_sections sections
;
11759 void **dwo_file_slot
;
11762 gdb_assert (dwp_file
->version
== 2);
11764 if (dwarf_read_debug
)
11766 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11768 pulongest (unit_index
), hex_string (signature
),
11772 /* Fetch the section offsets of this DWO unit. */
11774 memset (§ions
, 0, sizeof (sections
));
11776 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11778 uint32_t offset
= read_4_bytes (dbfd
,
11779 dwp_htab
->section_pool
.v2
.offsets
11780 + (((unit_index
- 1) * dwp_htab
->nr_columns
11782 * sizeof (uint32_t)));
11783 uint32_t size
= read_4_bytes (dbfd
,
11784 dwp_htab
->section_pool
.v2
.sizes
11785 + (((unit_index
- 1) * dwp_htab
->nr_columns
11787 * sizeof (uint32_t)));
11789 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11792 case DW_SECT_TYPES
:
11793 sections
.info_or_types_offset
= offset
;
11794 sections
.info_or_types_size
= size
;
11796 case DW_SECT_ABBREV
:
11797 sections
.abbrev_offset
= offset
;
11798 sections
.abbrev_size
= size
;
11801 sections
.line_offset
= offset
;
11802 sections
.line_size
= size
;
11805 sections
.loc_offset
= offset
;
11806 sections
.loc_size
= size
;
11808 case DW_SECT_STR_OFFSETS
:
11809 sections
.str_offsets_offset
= offset
;
11810 sections
.str_offsets_size
= size
;
11812 case DW_SECT_MACINFO
:
11813 sections
.macinfo_offset
= offset
;
11814 sections
.macinfo_size
= size
;
11816 case DW_SECT_MACRO
:
11817 sections
.macro_offset
= offset
;
11818 sections
.macro_size
= size
;
11823 /* It's easier for the rest of the code if we fake a struct dwo_file and
11824 have dwo_unit "live" in that. At least for now.
11826 The DWP file can be made up of a random collection of CUs and TUs.
11827 However, for each CU + set of TUs that came from the same original DWO
11828 file, we can combine them back into a virtual DWO file to save space
11829 (fewer struct dwo_file objects to allocate). Remember that for really
11830 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11832 std::string virtual_dwo_name
=
11833 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11834 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11835 (long) (sections
.line_size
? sections
.line_offset
: 0),
11836 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11837 (long) (sections
.str_offsets_size
11838 ? sections
.str_offsets_offset
: 0));
11839 /* Can we use an existing virtual DWO file? */
11840 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11841 virtual_dwo_name
.c_str (),
11843 /* Create one if necessary. */
11844 if (*dwo_file_slot
== NULL
)
11846 if (dwarf_read_debug
)
11848 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11849 virtual_dwo_name
.c_str ());
11851 dwo_file
= new struct dwo_file
;
11852 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11854 dwo_file
->comp_dir
= comp_dir
;
11855 dwo_file
->sections
.abbrev
=
11856 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11857 sections
.abbrev_offset
, sections
.abbrev_size
);
11858 dwo_file
->sections
.line
=
11859 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11860 sections
.line_offset
, sections
.line_size
);
11861 dwo_file
->sections
.loc
=
11862 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11863 sections
.loc_offset
, sections
.loc_size
);
11864 dwo_file
->sections
.macinfo
=
11865 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11866 sections
.macinfo_offset
, sections
.macinfo_size
);
11867 dwo_file
->sections
.macro
=
11868 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11869 sections
.macro_offset
, sections
.macro_size
);
11870 dwo_file
->sections
.str_offsets
=
11871 create_dwp_v2_section (dwarf2_per_objfile
,
11872 &dwp_file
->sections
.str_offsets
,
11873 sections
.str_offsets_offset
,
11874 sections
.str_offsets_size
);
11875 /* The "str" section is global to the entire DWP file. */
11876 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11877 /* The info or types section is assigned below to dwo_unit,
11878 there's no need to record it in dwo_file.
11879 Also, we can't simply record type sections in dwo_file because
11880 we record a pointer into the vector in dwo_unit. As we collect more
11881 types we'll grow the vector and eventually have to reallocate space
11882 for it, invalidating all copies of pointers into the previous
11884 *dwo_file_slot
= dwo_file
;
11888 if (dwarf_read_debug
)
11890 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11891 virtual_dwo_name
.c_str ());
11893 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11896 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11897 dwo_unit
->dwo_file
= dwo_file
;
11898 dwo_unit
->signature
= signature
;
11899 dwo_unit
->section
=
11900 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11901 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11903 ? &dwp_file
->sections
.types
11904 : &dwp_file
->sections
.info
,
11905 sections
.info_or_types_offset
,
11906 sections
.info_or_types_size
);
11907 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11912 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11913 Returns NULL if the signature isn't found. */
11915 static struct dwo_unit
*
11916 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11917 struct dwp_file
*dwp_file
, const char *comp_dir
,
11918 ULONGEST signature
, int is_debug_types
)
11920 const struct dwp_hash_table
*dwp_htab
=
11921 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11922 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11923 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11924 uint32_t hash
= signature
& mask
;
11925 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11928 struct dwo_unit find_dwo_cu
;
11930 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11931 find_dwo_cu
.signature
= signature
;
11932 slot
= htab_find_slot (is_debug_types
11933 ? dwp_file
->loaded_tus
.get ()
11934 : dwp_file
->loaded_cus
.get (),
11935 &find_dwo_cu
, INSERT
);
11938 return (struct dwo_unit
*) *slot
;
11940 /* Use a for loop so that we don't loop forever on bad debug info. */
11941 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11943 ULONGEST signature_in_table
;
11945 signature_in_table
=
11946 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11947 if (signature_in_table
== signature
)
11949 uint32_t unit_index
=
11950 read_4_bytes (dbfd
,
11951 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11953 if (dwp_file
->version
== 1)
11955 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11956 dwp_file
, unit_index
,
11957 comp_dir
, signature
,
11962 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11963 dwp_file
, unit_index
,
11964 comp_dir
, signature
,
11967 return (struct dwo_unit
*) *slot
;
11969 if (signature_in_table
== 0)
11971 hash
= (hash
+ hash2
) & mask
;
11974 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11975 " [in module %s]"),
11979 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11980 Open the file specified by FILE_NAME and hand it off to BFD for
11981 preliminary analysis. Return a newly initialized bfd *, which
11982 includes a canonicalized copy of FILE_NAME.
11983 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11984 SEARCH_CWD is true if the current directory is to be searched.
11985 It will be searched before debug-file-directory.
11986 If successful, the file is added to the bfd include table of the
11987 objfile's bfd (see gdb_bfd_record_inclusion).
11988 If unable to find/open the file, return NULL.
11989 NOTE: This function is derived from symfile_bfd_open. */
11991 static gdb_bfd_ref_ptr
11992 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11993 const char *file_name
, int is_dwp
, int search_cwd
)
11996 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11997 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11998 to debug_file_directory. */
11999 const char *search_path
;
12000 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12002 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12005 if (*debug_file_directory
!= '\0')
12007 search_path_holder
.reset (concat (".", dirname_separator_string
,
12008 debug_file_directory
,
12010 search_path
= search_path_holder
.get ();
12016 search_path
= debug_file_directory
;
12018 openp_flags flags
= OPF_RETURN_REALPATH
;
12020 flags
|= OPF_SEARCH_IN_PATH
;
12022 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12023 desc
= openp (search_path
, flags
, file_name
,
12024 O_RDONLY
| O_BINARY
, &absolute_name
);
12028 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12030 if (sym_bfd
== NULL
)
12032 bfd_set_cacheable (sym_bfd
.get (), 1);
12034 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12037 /* Success. Record the bfd as having been included by the objfile's bfd.
12038 This is important because things like demangled_names_hash lives in the
12039 objfile's per_bfd space and may have references to things like symbol
12040 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12041 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12046 /* Try to open DWO file FILE_NAME.
12047 COMP_DIR is the DW_AT_comp_dir attribute.
12048 The result is the bfd handle of the file.
12049 If there is a problem finding or opening the file, return NULL.
12050 Upon success, the canonicalized path of the file is stored in the bfd,
12051 same as symfile_bfd_open. */
12053 static gdb_bfd_ref_ptr
12054 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12055 const char *file_name
, const char *comp_dir
)
12057 if (IS_ABSOLUTE_PATH (file_name
))
12058 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12059 0 /*is_dwp*/, 0 /*search_cwd*/);
12061 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12063 if (comp_dir
!= NULL
)
12065 gdb::unique_xmalloc_ptr
<char> path_to_try
12066 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12068 /* NOTE: If comp_dir is a relative path, this will also try the
12069 search path, which seems useful. */
12070 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12071 path_to_try
.get (),
12073 1 /*search_cwd*/));
12078 /* That didn't work, try debug-file-directory, which, despite its name,
12079 is a list of paths. */
12081 if (*debug_file_directory
== '\0')
12084 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12085 0 /*is_dwp*/, 1 /*search_cwd*/);
12088 /* This function is mapped across the sections and remembers the offset and
12089 size of each of the DWO debugging sections we are interested in. */
12092 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12094 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12095 const struct dwop_section_names
*names
= &dwop_section_names
;
12097 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12099 dwo_sections
->abbrev
.s
.section
= sectp
;
12100 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12102 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12104 dwo_sections
->info
.s
.section
= sectp
;
12105 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12107 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12109 dwo_sections
->line
.s
.section
= sectp
;
12110 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12112 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12114 dwo_sections
->loc
.s
.section
= sectp
;
12115 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12117 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12119 dwo_sections
->macinfo
.s
.section
= sectp
;
12120 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12122 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12124 dwo_sections
->macro
.s
.section
= sectp
;
12125 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12127 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12129 dwo_sections
->str
.s
.section
= sectp
;
12130 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12132 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12134 dwo_sections
->str_offsets
.s
.section
= sectp
;
12135 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12137 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12139 struct dwarf2_section_info type_section
;
12141 memset (&type_section
, 0, sizeof (type_section
));
12142 type_section
.s
.section
= sectp
;
12143 type_section
.size
= bfd_section_size (sectp
);
12144 dwo_sections
->types
.push_back (type_section
);
12148 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12149 by PER_CU. This is for the non-DWP case.
12150 The result is NULL if DWO_NAME can't be found. */
12152 static struct dwo_file
*
12153 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12154 const char *dwo_name
, const char *comp_dir
)
12156 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12158 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12161 if (dwarf_read_debug
)
12162 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12166 dwo_file_up
dwo_file (new struct dwo_file
);
12167 dwo_file
->dwo_name
= dwo_name
;
12168 dwo_file
->comp_dir
= comp_dir
;
12169 dwo_file
->dbfd
= std::move (dbfd
);
12171 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12172 &dwo_file
->sections
);
12174 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12175 dwo_file
->sections
.info
, dwo_file
->cus
);
12177 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12178 dwo_file
->sections
.types
, dwo_file
->tus
);
12180 if (dwarf_read_debug
)
12181 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12183 return dwo_file
.release ();
12186 /* This function is mapped across the sections and remembers the offset and
12187 size of each of the DWP debugging sections common to version 1 and 2 that
12188 we are interested in. */
12191 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12192 void *dwp_file_ptr
)
12194 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12195 const struct dwop_section_names
*names
= &dwop_section_names
;
12196 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12198 /* Record the ELF section number for later lookup: this is what the
12199 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12200 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12201 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12203 /* Look for specific sections that we need. */
12204 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12206 dwp_file
->sections
.str
.s
.section
= sectp
;
12207 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12209 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12211 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12212 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12214 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12216 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12217 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12221 /* This function is mapped across the sections and remembers the offset and
12222 size of each of the DWP version 2 debugging sections that we are interested
12223 in. This is split into a separate function because we don't know if we
12224 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12227 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12229 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12230 const struct dwop_section_names
*names
= &dwop_section_names
;
12231 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12233 /* Record the ELF section number for later lookup: this is what the
12234 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12235 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12236 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12238 /* Look for specific sections that we need. */
12239 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12241 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12242 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12244 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12246 dwp_file
->sections
.info
.s
.section
= sectp
;
12247 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12249 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12251 dwp_file
->sections
.line
.s
.section
= sectp
;
12252 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12254 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12256 dwp_file
->sections
.loc
.s
.section
= sectp
;
12257 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12259 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12261 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12262 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12264 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12266 dwp_file
->sections
.macro
.s
.section
= sectp
;
12267 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12269 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12271 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12272 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12274 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12276 dwp_file
->sections
.types
.s
.section
= sectp
;
12277 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12281 /* Hash function for dwp_file loaded CUs/TUs. */
12284 hash_dwp_loaded_cutus (const void *item
)
12286 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12288 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12289 return dwo_unit
->signature
;
12292 /* Equality function for dwp_file loaded CUs/TUs. */
12295 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12297 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12298 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12300 return dua
->signature
== dub
->signature
;
12303 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12306 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
12308 return htab_up (htab_create_alloc (3,
12309 hash_dwp_loaded_cutus
,
12310 eq_dwp_loaded_cutus
,
12311 NULL
, xcalloc
, xfree
));
12314 /* Try to open DWP file FILE_NAME.
12315 The result is the bfd handle of the file.
12316 If there is a problem finding or opening the file, return NULL.
12317 Upon success, the canonicalized path of the file is stored in the bfd,
12318 same as symfile_bfd_open. */
12320 static gdb_bfd_ref_ptr
12321 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12322 const char *file_name
)
12324 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12326 1 /*search_cwd*/));
12330 /* Work around upstream bug 15652.
12331 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12332 [Whether that's a "bug" is debatable, but it is getting in our way.]
12333 We have no real idea where the dwp file is, because gdb's realpath-ing
12334 of the executable's path may have discarded the needed info.
12335 [IWBN if the dwp file name was recorded in the executable, akin to
12336 .gnu_debuglink, but that doesn't exist yet.]
12337 Strip the directory from FILE_NAME and search again. */
12338 if (*debug_file_directory
!= '\0')
12340 /* Don't implicitly search the current directory here.
12341 If the user wants to search "." to handle this case,
12342 it must be added to debug-file-directory. */
12343 return try_open_dwop_file (dwarf2_per_objfile
,
12344 lbasename (file_name
), 1 /*is_dwp*/,
12351 /* Initialize the use of the DWP file for the current objfile.
12352 By convention the name of the DWP file is ${objfile}.dwp.
12353 The result is NULL if it can't be found. */
12355 static std::unique_ptr
<struct dwp_file
>
12356 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12358 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12360 /* Try to find first .dwp for the binary file before any symbolic links
12363 /* If the objfile is a debug file, find the name of the real binary
12364 file and get the name of dwp file from there. */
12365 std::string dwp_name
;
12366 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12368 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12369 const char *backlink_basename
= lbasename (backlink
->original_name
);
12371 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12374 dwp_name
= objfile
->original_name
;
12376 dwp_name
+= ".dwp";
12378 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12380 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12382 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12383 dwp_name
= objfile_name (objfile
);
12384 dwp_name
+= ".dwp";
12385 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12390 if (dwarf_read_debug
)
12391 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12392 return std::unique_ptr
<dwp_file
> ();
12395 const char *name
= bfd_get_filename (dbfd
.get ());
12396 std::unique_ptr
<struct dwp_file
> dwp_file
12397 (new struct dwp_file (name
, std::move (dbfd
)));
12399 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12400 dwp_file
->elf_sections
=
12401 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12402 dwp_file
->num_sections
, asection
*);
12404 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12405 dwarf2_locate_common_dwp_sections
,
12408 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12411 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12414 /* The DWP file version is stored in the hash table. Oh well. */
12415 if (dwp_file
->cus
&& dwp_file
->tus
12416 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12418 /* Technically speaking, we should try to limp along, but this is
12419 pretty bizarre. We use pulongest here because that's the established
12420 portability solution (e.g, we cannot use %u for uint32_t). */
12421 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12422 " TU version %s [in DWP file %s]"),
12423 pulongest (dwp_file
->cus
->version
),
12424 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12428 dwp_file
->version
= dwp_file
->cus
->version
;
12429 else if (dwp_file
->tus
)
12430 dwp_file
->version
= dwp_file
->tus
->version
;
12432 dwp_file
->version
= 2;
12434 if (dwp_file
->version
== 2)
12435 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12436 dwarf2_locate_v2_dwp_sections
,
12439 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
12440 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
12442 if (dwarf_read_debug
)
12444 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12445 fprintf_unfiltered (gdb_stdlog
,
12446 " %s CUs, %s TUs\n",
12447 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12448 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12454 /* Wrapper around open_and_init_dwp_file, only open it once. */
12456 static struct dwp_file
*
12457 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12459 if (! dwarf2_per_objfile
->dwp_checked
)
12461 dwarf2_per_objfile
->dwp_file
12462 = open_and_init_dwp_file (dwarf2_per_objfile
);
12463 dwarf2_per_objfile
->dwp_checked
= 1;
12465 return dwarf2_per_objfile
->dwp_file
.get ();
12468 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12469 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12470 or in the DWP file for the objfile, referenced by THIS_UNIT.
12471 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12472 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12474 This is called, for example, when wanting to read a variable with a
12475 complex location. Therefore we don't want to do file i/o for every call.
12476 Therefore we don't want to look for a DWO file on every call.
12477 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12478 then we check if we've already seen DWO_NAME, and only THEN do we check
12481 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12482 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12484 static struct dwo_unit
*
12485 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12486 const char *dwo_name
, const char *comp_dir
,
12487 ULONGEST signature
, int is_debug_types
)
12489 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12490 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12491 const char *kind
= is_debug_types
? "TU" : "CU";
12492 void **dwo_file_slot
;
12493 struct dwo_file
*dwo_file
;
12494 struct dwp_file
*dwp_file
;
12496 /* First see if there's a DWP file.
12497 If we have a DWP file but didn't find the DWO inside it, don't
12498 look for the original DWO file. It makes gdb behave differently
12499 depending on whether one is debugging in the build tree. */
12501 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12502 if (dwp_file
!= NULL
)
12504 const struct dwp_hash_table
*dwp_htab
=
12505 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12507 if (dwp_htab
!= NULL
)
12509 struct dwo_unit
*dwo_cutu
=
12510 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12511 signature
, is_debug_types
);
12513 if (dwo_cutu
!= NULL
)
12515 if (dwarf_read_debug
)
12517 fprintf_unfiltered (gdb_stdlog
,
12518 "Virtual DWO %s %s found: @%s\n",
12519 kind
, hex_string (signature
),
12520 host_address_to_string (dwo_cutu
));
12528 /* No DWP file, look for the DWO file. */
12530 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12531 dwo_name
, comp_dir
);
12532 if (*dwo_file_slot
== NULL
)
12534 /* Read in the file and build a table of the CUs/TUs it contains. */
12535 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12537 /* NOTE: This will be NULL if unable to open the file. */
12538 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12540 if (dwo_file
!= NULL
)
12542 struct dwo_unit
*dwo_cutu
= NULL
;
12544 if (is_debug_types
&& dwo_file
->tus
)
12546 struct dwo_unit find_dwo_cutu
;
12548 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12549 find_dwo_cutu
.signature
= signature
;
12551 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12554 else if (!is_debug_types
&& dwo_file
->cus
)
12556 struct dwo_unit find_dwo_cutu
;
12558 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12559 find_dwo_cutu
.signature
= signature
;
12560 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12564 if (dwo_cutu
!= NULL
)
12566 if (dwarf_read_debug
)
12568 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12569 kind
, dwo_name
, hex_string (signature
),
12570 host_address_to_string (dwo_cutu
));
12577 /* We didn't find it. This could mean a dwo_id mismatch, or
12578 someone deleted the DWO/DWP file, or the search path isn't set up
12579 correctly to find the file. */
12581 if (dwarf_read_debug
)
12583 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12584 kind
, dwo_name
, hex_string (signature
));
12587 /* This is a warning and not a complaint because it can be caused by
12588 pilot error (e.g., user accidentally deleting the DWO). */
12590 /* Print the name of the DWP file if we looked there, helps the user
12591 better diagnose the problem. */
12592 std::string dwp_text
;
12594 if (dwp_file
!= NULL
)
12595 dwp_text
= string_printf (" [in DWP file %s]",
12596 lbasename (dwp_file
->name
));
12598 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12599 " [in module %s]"),
12600 kind
, dwo_name
, hex_string (signature
),
12602 this_unit
->is_debug_types
? "TU" : "CU",
12603 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12608 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12609 See lookup_dwo_cutu_unit for details. */
12611 static struct dwo_unit
*
12612 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12613 const char *dwo_name
, const char *comp_dir
,
12614 ULONGEST signature
)
12616 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12619 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12620 See lookup_dwo_cutu_unit for details. */
12622 static struct dwo_unit
*
12623 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12624 const char *dwo_name
, const char *comp_dir
)
12626 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12629 /* Traversal function for queue_and_load_all_dwo_tus. */
12632 queue_and_load_dwo_tu (void **slot
, void *info
)
12634 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12635 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12636 ULONGEST signature
= dwo_unit
->signature
;
12637 struct signatured_type
*sig_type
=
12638 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12640 if (sig_type
!= NULL
)
12642 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12644 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12645 a real dependency of PER_CU on SIG_TYPE. That is detected later
12646 while processing PER_CU. */
12647 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12648 load_full_type_unit (sig_cu
);
12649 per_cu
->imported_symtabs_push (sig_cu
);
12655 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12656 The DWO may have the only definition of the type, though it may not be
12657 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12658 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12661 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12663 struct dwo_unit
*dwo_unit
;
12664 struct dwo_file
*dwo_file
;
12666 gdb_assert (!per_cu
->is_debug_types
);
12667 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12668 gdb_assert (per_cu
->cu
!= NULL
);
12670 dwo_unit
= per_cu
->cu
->dwo_unit
;
12671 gdb_assert (dwo_unit
!= NULL
);
12673 dwo_file
= dwo_unit
->dwo_file
;
12674 if (dwo_file
->tus
!= NULL
)
12675 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12679 /* Read in various DIEs. */
12681 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12682 Inherit only the children of the DW_AT_abstract_origin DIE not being
12683 already referenced by DW_AT_abstract_origin from the children of the
12687 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12689 struct die_info
*child_die
;
12690 sect_offset
*offsetp
;
12691 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12692 struct die_info
*origin_die
;
12693 /* Iterator of the ORIGIN_DIE children. */
12694 struct die_info
*origin_child_die
;
12695 struct attribute
*attr
;
12696 struct dwarf2_cu
*origin_cu
;
12697 struct pending
**origin_previous_list_in_scope
;
12699 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12703 /* Note that following die references may follow to a die in a
12707 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12709 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12711 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12712 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12714 if (die
->tag
!= origin_die
->tag
12715 && !(die
->tag
== DW_TAG_inlined_subroutine
12716 && origin_die
->tag
== DW_TAG_subprogram
))
12717 complaint (_("DIE %s and its abstract origin %s have different tags"),
12718 sect_offset_str (die
->sect_off
),
12719 sect_offset_str (origin_die
->sect_off
));
12721 std::vector
<sect_offset
> offsets
;
12723 for (child_die
= die
->child
;
12724 child_die
&& child_die
->tag
;
12725 child_die
= sibling_die (child_die
))
12727 struct die_info
*child_origin_die
;
12728 struct dwarf2_cu
*child_origin_cu
;
12730 /* We are trying to process concrete instance entries:
12731 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12732 it's not relevant to our analysis here. i.e. detecting DIEs that are
12733 present in the abstract instance but not referenced in the concrete
12735 if (child_die
->tag
== DW_TAG_call_site
12736 || child_die
->tag
== DW_TAG_GNU_call_site
)
12739 /* For each CHILD_DIE, find the corresponding child of
12740 ORIGIN_DIE. If there is more than one layer of
12741 DW_AT_abstract_origin, follow them all; there shouldn't be,
12742 but GCC versions at least through 4.4 generate this (GCC PR
12744 child_origin_die
= child_die
;
12745 child_origin_cu
= cu
;
12748 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12752 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12756 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12757 counterpart may exist. */
12758 if (child_origin_die
!= child_die
)
12760 if (child_die
->tag
!= child_origin_die
->tag
12761 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12762 && child_origin_die
->tag
== DW_TAG_subprogram
))
12763 complaint (_("Child DIE %s and its abstract origin %s have "
12765 sect_offset_str (child_die
->sect_off
),
12766 sect_offset_str (child_origin_die
->sect_off
));
12767 if (child_origin_die
->parent
!= origin_die
)
12768 complaint (_("Child DIE %s and its abstract origin %s have "
12769 "different parents"),
12770 sect_offset_str (child_die
->sect_off
),
12771 sect_offset_str (child_origin_die
->sect_off
));
12773 offsets
.push_back (child_origin_die
->sect_off
);
12776 std::sort (offsets
.begin (), offsets
.end ());
12777 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12778 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12779 if (offsetp
[-1] == *offsetp
)
12780 complaint (_("Multiple children of DIE %s refer "
12781 "to DIE %s as their abstract origin"),
12782 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12784 offsetp
= offsets
.data ();
12785 origin_child_die
= origin_die
->child
;
12786 while (origin_child_die
&& origin_child_die
->tag
)
12788 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12789 while (offsetp
< offsets_end
12790 && *offsetp
< origin_child_die
->sect_off
)
12792 if (offsetp
>= offsets_end
12793 || *offsetp
> origin_child_die
->sect_off
)
12795 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12796 Check whether we're already processing ORIGIN_CHILD_DIE.
12797 This can happen with mutually referenced abstract_origins.
12799 if (!origin_child_die
->in_process
)
12800 process_die (origin_child_die
, origin_cu
);
12802 origin_child_die
= sibling_die (origin_child_die
);
12804 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12806 if (cu
!= origin_cu
)
12807 compute_delayed_physnames (origin_cu
);
12811 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12813 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12814 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12815 struct context_stack
*newobj
;
12818 struct die_info
*child_die
;
12819 struct attribute
*attr
, *call_line
, *call_file
;
12821 CORE_ADDR baseaddr
;
12822 struct block
*block
;
12823 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12824 std::vector
<struct symbol
*> template_args
;
12825 struct template_symbol
*templ_func
= NULL
;
12829 /* If we do not have call site information, we can't show the
12830 caller of this inlined function. That's too confusing, so
12831 only use the scope for local variables. */
12832 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12833 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12834 if (call_line
== NULL
|| call_file
== NULL
)
12836 read_lexical_block_scope (die
, cu
);
12841 baseaddr
= objfile
->text_section_offset ();
12843 name
= dwarf2_name (die
, cu
);
12845 /* Ignore functions with missing or empty names. These are actually
12846 illegal according to the DWARF standard. */
12849 complaint (_("missing name for subprogram DIE at %s"),
12850 sect_offset_str (die
->sect_off
));
12854 /* Ignore functions with missing or invalid low and high pc attributes. */
12855 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12856 <= PC_BOUNDS_INVALID
)
12858 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12859 if (!attr
|| !DW_UNSND (attr
))
12860 complaint (_("cannot get low and high bounds "
12861 "for subprogram DIE at %s"),
12862 sect_offset_str (die
->sect_off
));
12866 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12867 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12869 /* If we have any template arguments, then we must allocate a
12870 different sort of symbol. */
12871 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12873 if (child_die
->tag
== DW_TAG_template_type_param
12874 || child_die
->tag
== DW_TAG_template_value_param
)
12876 templ_func
= allocate_template_symbol (objfile
);
12877 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12882 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12883 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12884 (struct symbol
*) templ_func
);
12886 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12887 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12890 /* If there is a location expression for DW_AT_frame_base, record
12892 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12893 if (attr
!= nullptr)
12894 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12896 /* If there is a location for the static link, record it. */
12897 newobj
->static_link
= NULL
;
12898 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12899 if (attr
!= nullptr)
12901 newobj
->static_link
12902 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12903 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12904 cu
->per_cu
->addr_type ());
12907 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12909 if (die
->child
!= NULL
)
12911 child_die
= die
->child
;
12912 while (child_die
&& child_die
->tag
)
12914 if (child_die
->tag
== DW_TAG_template_type_param
12915 || child_die
->tag
== DW_TAG_template_value_param
)
12917 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12920 template_args
.push_back (arg
);
12923 process_die (child_die
, cu
);
12924 child_die
= sibling_die (child_die
);
12928 inherit_abstract_dies (die
, cu
);
12930 /* If we have a DW_AT_specification, we might need to import using
12931 directives from the context of the specification DIE. See the
12932 comment in determine_prefix. */
12933 if (cu
->language
== language_cplus
12934 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12936 struct dwarf2_cu
*spec_cu
= cu
;
12937 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12941 child_die
= spec_die
->child
;
12942 while (child_die
&& child_die
->tag
)
12944 if (child_die
->tag
== DW_TAG_imported_module
)
12945 process_die (child_die
, spec_cu
);
12946 child_die
= sibling_die (child_die
);
12949 /* In some cases, GCC generates specification DIEs that
12950 themselves contain DW_AT_specification attributes. */
12951 spec_die
= die_specification (spec_die
, &spec_cu
);
12955 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12956 /* Make a block for the local symbols within. */
12957 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12958 cstk
.static_link
, lowpc
, highpc
);
12960 /* For C++, set the block's scope. */
12961 if ((cu
->language
== language_cplus
12962 || cu
->language
== language_fortran
12963 || cu
->language
== language_d
12964 || cu
->language
== language_rust
)
12965 && cu
->processing_has_namespace_info
)
12966 block_set_scope (block
, determine_prefix (die
, cu
),
12967 &objfile
->objfile_obstack
);
12969 /* If we have address ranges, record them. */
12970 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12972 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12974 /* Attach template arguments to function. */
12975 if (!template_args
.empty ())
12977 gdb_assert (templ_func
!= NULL
);
12979 templ_func
->n_template_arguments
= template_args
.size ();
12980 templ_func
->template_arguments
12981 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12982 templ_func
->n_template_arguments
);
12983 memcpy (templ_func
->template_arguments
,
12984 template_args
.data (),
12985 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12987 /* Make sure that the symtab is set on the new symbols. Even
12988 though they don't appear in this symtab directly, other parts
12989 of gdb assume that symbols do, and this is reasonably
12991 for (symbol
*sym
: template_args
)
12992 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12995 /* In C++, we can have functions nested inside functions (e.g., when
12996 a function declares a class that has methods). This means that
12997 when we finish processing a function scope, we may need to go
12998 back to building a containing block's symbol lists. */
12999 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13000 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13002 /* If we've finished processing a top-level function, subsequent
13003 symbols go in the file symbol list. */
13004 if (cu
->get_builder ()->outermost_context_p ())
13005 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13008 /* Process all the DIES contained within a lexical block scope. Start
13009 a new scope, process the dies, and then close the scope. */
13012 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13014 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13015 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13016 CORE_ADDR lowpc
, highpc
;
13017 struct die_info
*child_die
;
13018 CORE_ADDR baseaddr
;
13020 baseaddr
= objfile
->text_section_offset ();
13022 /* Ignore blocks with missing or invalid low and high pc attributes. */
13023 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13024 as multiple lexical blocks? Handling children in a sane way would
13025 be nasty. Might be easier to properly extend generic blocks to
13026 describe ranges. */
13027 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13029 case PC_BOUNDS_NOT_PRESENT
:
13030 /* DW_TAG_lexical_block has no attributes, process its children as if
13031 there was no wrapping by that DW_TAG_lexical_block.
13032 GCC does no longer produces such DWARF since GCC r224161. */
13033 for (child_die
= die
->child
;
13034 child_die
!= NULL
&& child_die
->tag
;
13035 child_die
= sibling_die (child_die
))
13036 process_die (child_die
, cu
);
13038 case PC_BOUNDS_INVALID
:
13041 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13042 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13044 cu
->get_builder ()->push_context (0, lowpc
);
13045 if (die
->child
!= NULL
)
13047 child_die
= die
->child
;
13048 while (child_die
&& child_die
->tag
)
13050 process_die (child_die
, cu
);
13051 child_die
= sibling_die (child_die
);
13054 inherit_abstract_dies (die
, cu
);
13055 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13057 if (*cu
->get_builder ()->get_local_symbols () != NULL
13058 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13060 struct block
*block
13061 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13062 cstk
.start_addr
, highpc
);
13064 /* Note that recording ranges after traversing children, as we
13065 do here, means that recording a parent's ranges entails
13066 walking across all its children's ranges as they appear in
13067 the address map, which is quadratic behavior.
13069 It would be nicer to record the parent's ranges before
13070 traversing its children, simply overriding whatever you find
13071 there. But since we don't even decide whether to create a
13072 block until after we've traversed its children, that's hard
13074 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13076 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13077 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13080 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13083 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13085 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13086 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13087 CORE_ADDR pc
, baseaddr
;
13088 struct attribute
*attr
;
13089 struct call_site
*call_site
, call_site_local
;
13092 struct die_info
*child_die
;
13094 baseaddr
= objfile
->text_section_offset ();
13096 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13099 /* This was a pre-DWARF-5 GNU extension alias
13100 for DW_AT_call_return_pc. */
13101 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13105 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13106 "DIE %s [in module %s]"),
13107 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13110 pc
= attr
->value_as_address () + baseaddr
;
13111 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13113 if (cu
->call_site_htab
== NULL
)
13114 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13115 NULL
, &objfile
->objfile_obstack
,
13116 hashtab_obstack_allocate
, NULL
);
13117 call_site_local
.pc
= pc
;
13118 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13121 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13122 "DIE %s [in module %s]"),
13123 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13124 objfile_name (objfile
));
13128 /* Count parameters at the caller. */
13131 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13132 child_die
= sibling_die (child_die
))
13134 if (child_die
->tag
!= DW_TAG_call_site_parameter
13135 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13137 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13138 "DW_TAG_call_site child DIE %s [in module %s]"),
13139 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13140 objfile_name (objfile
));
13148 = ((struct call_site
*)
13149 obstack_alloc (&objfile
->objfile_obstack
,
13150 sizeof (*call_site
)
13151 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13153 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13154 call_site
->pc
= pc
;
13156 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13157 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13159 struct die_info
*func_die
;
13161 /* Skip also over DW_TAG_inlined_subroutine. */
13162 for (func_die
= die
->parent
;
13163 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13164 && func_die
->tag
!= DW_TAG_subroutine_type
;
13165 func_die
= func_die
->parent
);
13167 /* DW_AT_call_all_calls is a superset
13168 of DW_AT_call_all_tail_calls. */
13170 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13171 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13172 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13173 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13175 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13176 not complete. But keep CALL_SITE for look ups via call_site_htab,
13177 both the initial caller containing the real return address PC and
13178 the final callee containing the current PC of a chain of tail
13179 calls do not need to have the tail call list complete. But any
13180 function candidate for a virtual tail call frame searched via
13181 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13182 determined unambiguously. */
13186 struct type
*func_type
= NULL
;
13189 func_type
= get_die_type (func_die
, cu
);
13190 if (func_type
!= NULL
)
13192 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13194 /* Enlist this call site to the function. */
13195 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13196 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13199 complaint (_("Cannot find function owning DW_TAG_call_site "
13200 "DIE %s [in module %s]"),
13201 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13205 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13207 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13209 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13212 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13213 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13215 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13216 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13217 /* Keep NULL DWARF_BLOCK. */;
13218 else if (attr
->form_is_block ())
13220 struct dwarf2_locexpr_baton
*dlbaton
;
13222 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13223 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13224 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13225 dlbaton
->per_cu
= cu
->per_cu
;
13227 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13229 else if (attr
->form_is_ref ())
13231 struct dwarf2_cu
*target_cu
= cu
;
13232 struct die_info
*target_die
;
13234 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13235 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13236 if (die_is_declaration (target_die
, target_cu
))
13238 const char *target_physname
;
13240 /* Prefer the mangled name; otherwise compute the demangled one. */
13241 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13242 if (target_physname
== NULL
)
13243 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13244 if (target_physname
== NULL
)
13245 complaint (_("DW_AT_call_target target DIE has invalid "
13246 "physname, for referencing DIE %s [in module %s]"),
13247 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13249 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13255 /* DW_AT_entry_pc should be preferred. */
13256 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13257 <= PC_BOUNDS_INVALID
)
13258 complaint (_("DW_AT_call_target target DIE has invalid "
13259 "low pc, for referencing DIE %s [in module %s]"),
13260 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13263 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13264 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13269 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13270 "block nor reference, for DIE %s [in module %s]"),
13271 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13273 call_site
->per_cu
= cu
->per_cu
;
13275 for (child_die
= die
->child
;
13276 child_die
&& child_die
->tag
;
13277 child_die
= sibling_die (child_die
))
13279 struct call_site_parameter
*parameter
;
13280 struct attribute
*loc
, *origin
;
13282 if (child_die
->tag
!= DW_TAG_call_site_parameter
13283 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13285 /* Already printed the complaint above. */
13289 gdb_assert (call_site
->parameter_count
< nparams
);
13290 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13292 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13293 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13294 register is contained in DW_AT_call_value. */
13296 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13297 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13298 if (origin
== NULL
)
13300 /* This was a pre-DWARF-5 GNU extension alias
13301 for DW_AT_call_parameter. */
13302 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13304 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13306 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13308 sect_offset sect_off
13309 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13310 if (!cu
->header
.offset_in_cu_p (sect_off
))
13312 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13313 binding can be done only inside one CU. Such referenced DIE
13314 therefore cannot be even moved to DW_TAG_partial_unit. */
13315 complaint (_("DW_AT_call_parameter offset is not in CU for "
13316 "DW_TAG_call_site child DIE %s [in module %s]"),
13317 sect_offset_str (child_die
->sect_off
),
13318 objfile_name (objfile
));
13321 parameter
->u
.param_cu_off
13322 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13324 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13326 complaint (_("No DW_FORM_block* DW_AT_location for "
13327 "DW_TAG_call_site child DIE %s [in module %s]"),
13328 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13333 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13334 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13335 if (parameter
->u
.dwarf_reg
!= -1)
13336 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13337 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13338 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13339 ¶meter
->u
.fb_offset
))
13340 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13343 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13344 "for DW_FORM_block* DW_AT_location is supported for "
13345 "DW_TAG_call_site child DIE %s "
13347 sect_offset_str (child_die
->sect_off
),
13348 objfile_name (objfile
));
13353 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13355 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13356 if (attr
== NULL
|| !attr
->form_is_block ())
13358 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13359 "DW_TAG_call_site child DIE %s [in module %s]"),
13360 sect_offset_str (child_die
->sect_off
),
13361 objfile_name (objfile
));
13364 parameter
->value
= DW_BLOCK (attr
)->data
;
13365 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13367 /* Parameters are not pre-cleared by memset above. */
13368 parameter
->data_value
= NULL
;
13369 parameter
->data_value_size
= 0;
13370 call_site
->parameter_count
++;
13372 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13374 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13375 if (attr
!= nullptr)
13377 if (!attr
->form_is_block ())
13378 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13379 "DW_TAG_call_site child DIE %s [in module %s]"),
13380 sect_offset_str (child_die
->sect_off
),
13381 objfile_name (objfile
));
13384 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13385 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13391 /* Helper function for read_variable. If DIE represents a virtual
13392 table, then return the type of the concrete object that is
13393 associated with the virtual table. Otherwise, return NULL. */
13395 static struct type
*
13396 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13398 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13402 /* Find the type DIE. */
13403 struct die_info
*type_die
= NULL
;
13404 struct dwarf2_cu
*type_cu
= cu
;
13406 if (attr
->form_is_ref ())
13407 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13408 if (type_die
== NULL
)
13411 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13413 return die_containing_type (type_die
, type_cu
);
13416 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13419 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13421 struct rust_vtable_symbol
*storage
= NULL
;
13423 if (cu
->language
== language_rust
)
13425 struct type
*containing_type
= rust_containing_type (die
, cu
);
13427 if (containing_type
!= NULL
)
13429 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13431 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13432 initialize_objfile_symbol (storage
);
13433 storage
->concrete_type
= containing_type
;
13434 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13438 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13439 struct attribute
*abstract_origin
13440 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13441 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13442 if (res
== NULL
&& loc
&& abstract_origin
)
13444 /* We have a variable without a name, but with a location and an abstract
13445 origin. This may be a concrete instance of an abstract variable
13446 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13448 struct dwarf2_cu
*origin_cu
= cu
;
13449 struct die_info
*origin_die
13450 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13451 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13452 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13456 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13457 reading .debug_rnglists.
13458 Callback's type should be:
13459 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13460 Return true if the attributes are present and valid, otherwise,
13463 template <typename Callback
>
13465 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13466 Callback
&&callback
)
13468 struct dwarf2_per_objfile
*dwarf2_per_objfile
13469 = cu
->per_cu
->dwarf2_per_objfile
;
13470 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13471 bfd
*obfd
= objfile
->obfd
;
13472 /* Base address selection entry. */
13475 const gdb_byte
*buffer
;
13476 CORE_ADDR baseaddr
;
13477 bool overflow
= false;
13479 found_base
= cu
->base_known
;
13480 base
= cu
->base_address
;
13482 dwarf2_per_objfile
->rnglists
.read (objfile
);
13483 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13485 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13489 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13491 baseaddr
= objfile
->text_section_offset ();
13495 /* Initialize it due to a false compiler warning. */
13496 CORE_ADDR range_beginning
= 0, range_end
= 0;
13497 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13498 + dwarf2_per_objfile
->rnglists
.size
);
13499 unsigned int bytes_read
;
13501 if (buffer
== buf_end
)
13506 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13509 case DW_RLE_end_of_list
:
13511 case DW_RLE_base_address
:
13512 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13517 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
13519 buffer
+= bytes_read
;
13521 case DW_RLE_start_length
:
13522 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13527 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
13528 buffer
+= bytes_read
;
13529 range_end
= (range_beginning
13530 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13531 buffer
+= bytes_read
;
13532 if (buffer
> buf_end
)
13538 case DW_RLE_offset_pair
:
13539 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13540 buffer
+= bytes_read
;
13541 if (buffer
> buf_end
)
13546 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13547 buffer
+= bytes_read
;
13548 if (buffer
> buf_end
)
13554 case DW_RLE_start_end
:
13555 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13560 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
13561 buffer
+= bytes_read
;
13562 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
13563 buffer
+= bytes_read
;
13566 complaint (_("Invalid .debug_rnglists data (no base address)"));
13569 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13571 if (rlet
== DW_RLE_base_address
)
13576 /* We have no valid base address for the ranges
13578 complaint (_("Invalid .debug_rnglists data (no base address)"));
13582 if (range_beginning
> range_end
)
13584 /* Inverted range entries are invalid. */
13585 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13589 /* Empty range entries have no effect. */
13590 if (range_beginning
== range_end
)
13593 range_beginning
+= base
;
13596 /* A not-uncommon case of bad debug info.
13597 Don't pollute the addrmap with bad data. */
13598 if (range_beginning
+ baseaddr
== 0
13599 && !dwarf2_per_objfile
->has_section_at_zero
)
13601 complaint (_(".debug_rnglists entry has start address of zero"
13602 " [in module %s]"), objfile_name (objfile
));
13606 callback (range_beginning
, range_end
);
13611 complaint (_("Offset %d is not terminated "
13612 "for DW_AT_ranges attribute"),
13620 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13621 Callback's type should be:
13622 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13623 Return 1 if the attributes are present and valid, otherwise, return 0. */
13625 template <typename Callback
>
13627 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13628 Callback
&&callback
)
13630 struct dwarf2_per_objfile
*dwarf2_per_objfile
13631 = cu
->per_cu
->dwarf2_per_objfile
;
13632 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13633 struct comp_unit_head
*cu_header
= &cu
->header
;
13634 bfd
*obfd
= objfile
->obfd
;
13635 unsigned int addr_size
= cu_header
->addr_size
;
13636 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13637 /* Base address selection entry. */
13640 unsigned int dummy
;
13641 const gdb_byte
*buffer
;
13642 CORE_ADDR baseaddr
;
13644 if (cu_header
->version
>= 5)
13645 return dwarf2_rnglists_process (offset
, cu
, callback
);
13647 found_base
= cu
->base_known
;
13648 base
= cu
->base_address
;
13650 dwarf2_per_objfile
->ranges
.read (objfile
);
13651 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13653 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13657 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13659 baseaddr
= objfile
->text_section_offset ();
13663 CORE_ADDR range_beginning
, range_end
;
13665 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
13666 buffer
+= addr_size
;
13667 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
13668 buffer
+= addr_size
;
13669 offset
+= 2 * addr_size
;
13671 /* An end of list marker is a pair of zero addresses. */
13672 if (range_beginning
== 0 && range_end
== 0)
13673 /* Found the end of list entry. */
13676 /* Each base address selection entry is a pair of 2 values.
13677 The first is the largest possible address, the second is
13678 the base address. Check for a base address here. */
13679 if ((range_beginning
& mask
) == mask
)
13681 /* If we found the largest possible address, then we already
13682 have the base address in range_end. */
13690 /* We have no valid base address for the ranges
13692 complaint (_("Invalid .debug_ranges data (no base address)"));
13696 if (range_beginning
> range_end
)
13698 /* Inverted range entries are invalid. */
13699 complaint (_("Invalid .debug_ranges data (inverted range)"));
13703 /* Empty range entries have no effect. */
13704 if (range_beginning
== range_end
)
13707 range_beginning
+= base
;
13710 /* A not-uncommon case of bad debug info.
13711 Don't pollute the addrmap with bad data. */
13712 if (range_beginning
+ baseaddr
== 0
13713 && !dwarf2_per_objfile
->has_section_at_zero
)
13715 complaint (_(".debug_ranges entry has start address of zero"
13716 " [in module %s]"), objfile_name (objfile
));
13720 callback (range_beginning
, range_end
);
13726 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13727 Return 1 if the attributes are present and valid, otherwise, return 0.
13728 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13731 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13732 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13733 dwarf2_psymtab
*ranges_pst
)
13735 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13736 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13737 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13740 CORE_ADDR high
= 0;
13743 retval
= dwarf2_ranges_process (offset
, cu
,
13744 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13746 if (ranges_pst
!= NULL
)
13751 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13752 range_beginning
+ baseaddr
)
13754 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13755 range_end
+ baseaddr
)
13757 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13758 lowpc
, highpc
- 1, ranges_pst
);
13761 /* FIXME: This is recording everything as a low-high
13762 segment of consecutive addresses. We should have a
13763 data structure for discontiguous block ranges
13767 low
= range_beginning
;
13773 if (range_beginning
< low
)
13774 low
= range_beginning
;
13775 if (range_end
> high
)
13783 /* If the first entry is an end-of-list marker, the range
13784 describes an empty scope, i.e. no instructions. */
13790 *high_return
= high
;
13794 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13795 definition for the return value. *LOWPC and *HIGHPC are set iff
13796 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13798 static enum pc_bounds_kind
13799 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13800 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13801 dwarf2_psymtab
*pst
)
13803 struct dwarf2_per_objfile
*dwarf2_per_objfile
13804 = cu
->per_cu
->dwarf2_per_objfile
;
13805 struct attribute
*attr
;
13806 struct attribute
*attr_high
;
13808 CORE_ADDR high
= 0;
13809 enum pc_bounds_kind ret
;
13811 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13814 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13815 if (attr
!= nullptr)
13817 low
= attr
->value_as_address ();
13818 high
= attr_high
->value_as_address ();
13819 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13823 /* Found high w/o low attribute. */
13824 return PC_BOUNDS_INVALID
;
13826 /* Found consecutive range of addresses. */
13827 ret
= PC_BOUNDS_HIGH_LOW
;
13831 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13834 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13835 We take advantage of the fact that DW_AT_ranges does not appear
13836 in DW_TAG_compile_unit of DWO files. */
13837 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13838 unsigned int ranges_offset
= (DW_UNSND (attr
)
13839 + (need_ranges_base
13843 /* Value of the DW_AT_ranges attribute is the offset in the
13844 .debug_ranges section. */
13845 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13846 return PC_BOUNDS_INVALID
;
13847 /* Found discontinuous range of addresses. */
13848 ret
= PC_BOUNDS_RANGES
;
13851 return PC_BOUNDS_NOT_PRESENT
;
13854 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13856 return PC_BOUNDS_INVALID
;
13858 /* When using the GNU linker, .gnu.linkonce. sections are used to
13859 eliminate duplicate copies of functions and vtables and such.
13860 The linker will arbitrarily choose one and discard the others.
13861 The AT_*_pc values for such functions refer to local labels in
13862 these sections. If the section from that file was discarded, the
13863 labels are not in the output, so the relocs get a value of 0.
13864 If this is a discarded function, mark the pc bounds as invalid,
13865 so that GDB will ignore it. */
13866 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13867 return PC_BOUNDS_INVALID
;
13875 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13876 its low and high PC addresses. Do nothing if these addresses could not
13877 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13878 and HIGHPC to the high address if greater than HIGHPC. */
13881 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13882 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13883 struct dwarf2_cu
*cu
)
13885 CORE_ADDR low
, high
;
13886 struct die_info
*child
= die
->child
;
13888 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13890 *lowpc
= std::min (*lowpc
, low
);
13891 *highpc
= std::max (*highpc
, high
);
13894 /* If the language does not allow nested subprograms (either inside
13895 subprograms or lexical blocks), we're done. */
13896 if (cu
->language
!= language_ada
)
13899 /* Check all the children of the given DIE. If it contains nested
13900 subprograms, then check their pc bounds. Likewise, we need to
13901 check lexical blocks as well, as they may also contain subprogram
13903 while (child
&& child
->tag
)
13905 if (child
->tag
== DW_TAG_subprogram
13906 || child
->tag
== DW_TAG_lexical_block
)
13907 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13908 child
= sibling_die (child
);
13912 /* Get the low and high pc's represented by the scope DIE, and store
13913 them in *LOWPC and *HIGHPC. If the correct values can't be
13914 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13917 get_scope_pc_bounds (struct die_info
*die
,
13918 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13919 struct dwarf2_cu
*cu
)
13921 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13922 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13923 CORE_ADDR current_low
, current_high
;
13925 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13926 >= PC_BOUNDS_RANGES
)
13928 best_low
= current_low
;
13929 best_high
= current_high
;
13933 struct die_info
*child
= die
->child
;
13935 while (child
&& child
->tag
)
13937 switch (child
->tag
) {
13938 case DW_TAG_subprogram
:
13939 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13941 case DW_TAG_namespace
:
13942 case DW_TAG_module
:
13943 /* FIXME: carlton/2004-01-16: Should we do this for
13944 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13945 that current GCC's always emit the DIEs corresponding
13946 to definitions of methods of classes as children of a
13947 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13948 the DIEs giving the declarations, which could be
13949 anywhere). But I don't see any reason why the
13950 standards says that they have to be there. */
13951 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13953 if (current_low
!= ((CORE_ADDR
) -1))
13955 best_low
= std::min (best_low
, current_low
);
13956 best_high
= std::max (best_high
, current_high
);
13964 child
= sibling_die (child
);
13969 *highpc
= best_high
;
13972 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13976 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13977 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13979 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13980 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13981 struct attribute
*attr
;
13982 struct attribute
*attr_high
;
13984 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13987 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13988 if (attr
!= nullptr)
13990 CORE_ADDR low
= attr
->value_as_address ();
13991 CORE_ADDR high
= attr_high
->value_as_address ();
13993 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13996 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13997 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13998 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14002 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14003 if (attr
!= nullptr)
14005 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14006 We take advantage of the fact that DW_AT_ranges does not appear
14007 in DW_TAG_compile_unit of DWO files. */
14008 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14010 /* The value of the DW_AT_ranges attribute is the offset of the
14011 address range list in the .debug_ranges section. */
14012 unsigned long offset
= (DW_UNSND (attr
)
14013 + (need_ranges_base
? cu
->ranges_base
: 0));
14015 std::vector
<blockrange
> blockvec
;
14016 dwarf2_ranges_process (offset
, cu
,
14017 [&] (CORE_ADDR start
, CORE_ADDR end
)
14021 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14022 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14023 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14024 blockvec
.emplace_back (start
, end
);
14027 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14031 /* Check whether the producer field indicates either of GCC < 4.6, or the
14032 Intel C/C++ compiler, and cache the result in CU. */
14035 check_producer (struct dwarf2_cu
*cu
)
14039 if (cu
->producer
== NULL
)
14041 /* For unknown compilers expect their behavior is DWARF version
14044 GCC started to support .debug_types sections by -gdwarf-4 since
14045 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14046 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14047 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14048 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14050 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14052 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14053 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14055 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14057 cu
->producer_is_icc
= true;
14058 cu
->producer_is_icc_lt_14
= major
< 14;
14060 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14061 cu
->producer_is_codewarrior
= true;
14064 /* For other non-GCC compilers, expect their behavior is DWARF version
14068 cu
->checked_producer
= true;
14071 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14072 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14073 during 4.6.0 experimental. */
14076 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14078 if (!cu
->checked_producer
)
14079 check_producer (cu
);
14081 return cu
->producer_is_gxx_lt_4_6
;
14085 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14086 with incorrect is_stmt attributes. */
14089 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14091 if (!cu
->checked_producer
)
14092 check_producer (cu
);
14094 return cu
->producer_is_codewarrior
;
14097 /* Return the default accessibility type if it is not overridden by
14098 DW_AT_accessibility. */
14100 static enum dwarf_access_attribute
14101 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14103 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14105 /* The default DWARF 2 accessibility for members is public, the default
14106 accessibility for inheritance is private. */
14108 if (die
->tag
!= DW_TAG_inheritance
)
14109 return DW_ACCESS_public
;
14111 return DW_ACCESS_private
;
14115 /* DWARF 3+ defines the default accessibility a different way. The same
14116 rules apply now for DW_TAG_inheritance as for the members and it only
14117 depends on the container kind. */
14119 if (die
->parent
->tag
== DW_TAG_class_type
)
14120 return DW_ACCESS_private
;
14122 return DW_ACCESS_public
;
14126 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14127 offset. If the attribute was not found return 0, otherwise return
14128 1. If it was found but could not properly be handled, set *OFFSET
14132 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14135 struct attribute
*attr
;
14137 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14142 /* Note that we do not check for a section offset first here.
14143 This is because DW_AT_data_member_location is new in DWARF 4,
14144 so if we see it, we can assume that a constant form is really
14145 a constant and not a section offset. */
14146 if (attr
->form_is_constant ())
14147 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14148 else if (attr
->form_is_section_offset ())
14149 dwarf2_complex_location_expr_complaint ();
14150 else if (attr
->form_is_block ())
14151 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14153 dwarf2_complex_location_expr_complaint ();
14161 /* Add an aggregate field to the field list. */
14164 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14165 struct dwarf2_cu
*cu
)
14167 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14168 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14169 struct nextfield
*new_field
;
14170 struct attribute
*attr
;
14172 const char *fieldname
= "";
14174 if (die
->tag
== DW_TAG_inheritance
)
14176 fip
->baseclasses
.emplace_back ();
14177 new_field
= &fip
->baseclasses
.back ();
14181 fip
->fields
.emplace_back ();
14182 new_field
= &fip
->fields
.back ();
14187 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14188 if (attr
!= nullptr)
14189 new_field
->accessibility
= DW_UNSND (attr
);
14191 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14192 if (new_field
->accessibility
!= DW_ACCESS_public
)
14193 fip
->non_public_fields
= 1;
14195 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14196 if (attr
!= nullptr)
14197 new_field
->virtuality
= DW_UNSND (attr
);
14199 new_field
->virtuality
= DW_VIRTUALITY_none
;
14201 fp
= &new_field
->field
;
14203 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14207 /* Data member other than a C++ static data member. */
14209 /* Get type of field. */
14210 fp
->type
= die_type (die
, cu
);
14212 SET_FIELD_BITPOS (*fp
, 0);
14214 /* Get bit size of field (zero if none). */
14215 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14216 if (attr
!= nullptr)
14218 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14222 FIELD_BITSIZE (*fp
) = 0;
14225 /* Get bit offset of field. */
14226 if (handle_data_member_location (die
, cu
, &offset
))
14227 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14228 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14229 if (attr
!= nullptr)
14231 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14233 /* For big endian bits, the DW_AT_bit_offset gives the
14234 additional bit offset from the MSB of the containing
14235 anonymous object to the MSB of the field. We don't
14236 have to do anything special since we don't need to
14237 know the size of the anonymous object. */
14238 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14242 /* For little endian bits, compute the bit offset to the
14243 MSB of the anonymous object, subtract off the number of
14244 bits from the MSB of the field to the MSB of the
14245 object, and then subtract off the number of bits of
14246 the field itself. The result is the bit offset of
14247 the LSB of the field. */
14248 int anonymous_size
;
14249 int bit_offset
= DW_UNSND (attr
);
14251 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14252 if (attr
!= nullptr)
14254 /* The size of the anonymous object containing
14255 the bit field is explicit, so use the
14256 indicated size (in bytes). */
14257 anonymous_size
= DW_UNSND (attr
);
14261 /* The size of the anonymous object containing
14262 the bit field must be inferred from the type
14263 attribute of the data member containing the
14265 anonymous_size
= TYPE_LENGTH (fp
->type
);
14267 SET_FIELD_BITPOS (*fp
,
14268 (FIELD_BITPOS (*fp
)
14269 + anonymous_size
* bits_per_byte
14270 - bit_offset
- FIELD_BITSIZE (*fp
)));
14273 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14275 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14276 + dwarf2_get_attr_constant_value (attr
, 0)));
14278 /* Get name of field. */
14279 fieldname
= dwarf2_name (die
, cu
);
14280 if (fieldname
== NULL
)
14283 /* The name is already allocated along with this objfile, so we don't
14284 need to duplicate it for the type. */
14285 fp
->name
= fieldname
;
14287 /* Change accessibility for artificial fields (e.g. virtual table
14288 pointer or virtual base class pointer) to private. */
14289 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14291 FIELD_ARTIFICIAL (*fp
) = 1;
14292 new_field
->accessibility
= DW_ACCESS_private
;
14293 fip
->non_public_fields
= 1;
14296 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14298 /* C++ static member. */
14300 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14301 is a declaration, but all versions of G++ as of this writing
14302 (so through at least 3.2.1) incorrectly generate
14303 DW_TAG_variable tags. */
14305 const char *physname
;
14307 /* Get name of field. */
14308 fieldname
= dwarf2_name (die
, cu
);
14309 if (fieldname
== NULL
)
14312 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14314 /* Only create a symbol if this is an external value.
14315 new_symbol checks this and puts the value in the global symbol
14316 table, which we want. If it is not external, new_symbol
14317 will try to put the value in cu->list_in_scope which is wrong. */
14318 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14320 /* A static const member, not much different than an enum as far as
14321 we're concerned, except that we can support more types. */
14322 new_symbol (die
, NULL
, cu
);
14325 /* Get physical name. */
14326 physname
= dwarf2_physname (fieldname
, die
, cu
);
14328 /* The name is already allocated along with this objfile, so we don't
14329 need to duplicate it for the type. */
14330 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14331 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14332 FIELD_NAME (*fp
) = fieldname
;
14334 else if (die
->tag
== DW_TAG_inheritance
)
14338 /* C++ base class field. */
14339 if (handle_data_member_location (die
, cu
, &offset
))
14340 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14341 FIELD_BITSIZE (*fp
) = 0;
14342 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14343 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14345 else if (die
->tag
== DW_TAG_variant_part
)
14347 /* process_structure_scope will treat this DIE as a union. */
14348 process_structure_scope (die
, cu
);
14350 /* The variant part is relative to the start of the enclosing
14352 SET_FIELD_BITPOS (*fp
, 0);
14353 fp
->type
= get_die_type (die
, cu
);
14354 fp
->artificial
= 1;
14355 fp
->name
= "<<variant>>";
14357 /* Normally a DW_TAG_variant_part won't have a size, but our
14358 representation requires one, so set it to the maximum of the
14359 child sizes, being sure to account for the offset at which
14360 each child is seen. */
14361 if (TYPE_LENGTH (fp
->type
) == 0)
14364 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14366 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14367 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14371 TYPE_LENGTH (fp
->type
) = max
;
14375 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14378 /* Can the type given by DIE define another type? */
14381 type_can_define_types (const struct die_info
*die
)
14385 case DW_TAG_typedef
:
14386 case DW_TAG_class_type
:
14387 case DW_TAG_structure_type
:
14388 case DW_TAG_union_type
:
14389 case DW_TAG_enumeration_type
:
14397 /* Add a type definition defined in the scope of the FIP's class. */
14400 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14401 struct dwarf2_cu
*cu
)
14403 struct decl_field fp
;
14404 memset (&fp
, 0, sizeof (fp
));
14406 gdb_assert (type_can_define_types (die
));
14408 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14409 fp
.name
= dwarf2_name (die
, cu
);
14410 fp
.type
= read_type_die (die
, cu
);
14412 /* Save accessibility. */
14413 enum dwarf_access_attribute accessibility
;
14414 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14416 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14418 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14419 switch (accessibility
)
14421 case DW_ACCESS_public
:
14422 /* The assumed value if neither private nor protected. */
14424 case DW_ACCESS_private
:
14427 case DW_ACCESS_protected
:
14428 fp
.is_protected
= 1;
14431 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14434 if (die
->tag
== DW_TAG_typedef
)
14435 fip
->typedef_field_list
.push_back (fp
);
14437 fip
->nested_types_list
.push_back (fp
);
14440 /* Create the vector of fields, and attach it to the type. */
14443 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14444 struct dwarf2_cu
*cu
)
14446 int nfields
= fip
->nfields
;
14448 /* Record the field count, allocate space for the array of fields,
14449 and create blank accessibility bitfields if necessary. */
14450 TYPE_NFIELDS (type
) = nfields
;
14451 TYPE_FIELDS (type
) = (struct field
*)
14452 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14454 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14456 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14458 TYPE_FIELD_PRIVATE_BITS (type
) =
14459 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14460 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14462 TYPE_FIELD_PROTECTED_BITS (type
) =
14463 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14464 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14466 TYPE_FIELD_IGNORE_BITS (type
) =
14467 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14468 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14471 /* If the type has baseclasses, allocate and clear a bit vector for
14472 TYPE_FIELD_VIRTUAL_BITS. */
14473 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14475 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14476 unsigned char *pointer
;
14478 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14479 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14480 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14481 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14482 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14485 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14487 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14489 for (int index
= 0; index
< nfields
; ++index
)
14491 struct nextfield
&field
= fip
->fields
[index
];
14493 if (field
.variant
.is_discriminant
)
14494 di
->discriminant_index
= index
;
14495 else if (field
.variant
.default_branch
)
14496 di
->default_index
= index
;
14498 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14502 /* Copy the saved-up fields into the field vector. */
14503 for (int i
= 0; i
< nfields
; ++i
)
14505 struct nextfield
&field
14506 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14507 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14509 TYPE_FIELD (type
, i
) = field
.field
;
14510 switch (field
.accessibility
)
14512 case DW_ACCESS_private
:
14513 if (cu
->language
!= language_ada
)
14514 SET_TYPE_FIELD_PRIVATE (type
, i
);
14517 case DW_ACCESS_protected
:
14518 if (cu
->language
!= language_ada
)
14519 SET_TYPE_FIELD_PROTECTED (type
, i
);
14522 case DW_ACCESS_public
:
14526 /* Unknown accessibility. Complain and treat it as public. */
14528 complaint (_("unsupported accessibility %d"),
14529 field
.accessibility
);
14533 if (i
< fip
->baseclasses
.size ())
14535 switch (field
.virtuality
)
14537 case DW_VIRTUALITY_virtual
:
14538 case DW_VIRTUALITY_pure_virtual
:
14539 if (cu
->language
== language_ada
)
14540 error (_("unexpected virtuality in component of Ada type"));
14541 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14548 /* Return true if this member function is a constructor, false
14552 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14554 const char *fieldname
;
14555 const char *type_name
;
14558 if (die
->parent
== NULL
)
14561 if (die
->parent
->tag
!= DW_TAG_structure_type
14562 && die
->parent
->tag
!= DW_TAG_union_type
14563 && die
->parent
->tag
!= DW_TAG_class_type
)
14566 fieldname
= dwarf2_name (die
, cu
);
14567 type_name
= dwarf2_name (die
->parent
, cu
);
14568 if (fieldname
== NULL
|| type_name
== NULL
)
14571 len
= strlen (fieldname
);
14572 return (strncmp (fieldname
, type_name
, len
) == 0
14573 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14576 /* Check if the given VALUE is a recognized enum
14577 dwarf_defaulted_attribute constant according to DWARF5 spec,
14581 is_valid_DW_AT_defaulted (ULONGEST value
)
14585 case DW_DEFAULTED_no
:
14586 case DW_DEFAULTED_in_class
:
14587 case DW_DEFAULTED_out_of_class
:
14591 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14595 /* Add a member function to the proper fieldlist. */
14598 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14599 struct type
*type
, struct dwarf2_cu
*cu
)
14601 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14602 struct attribute
*attr
;
14604 struct fnfieldlist
*flp
= nullptr;
14605 struct fn_field
*fnp
;
14606 const char *fieldname
;
14607 struct type
*this_type
;
14608 enum dwarf_access_attribute accessibility
;
14610 if (cu
->language
== language_ada
)
14611 error (_("unexpected member function in Ada type"));
14613 /* Get name of member function. */
14614 fieldname
= dwarf2_name (die
, cu
);
14615 if (fieldname
== NULL
)
14618 /* Look up member function name in fieldlist. */
14619 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14621 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14623 flp
= &fip
->fnfieldlists
[i
];
14628 /* Create a new fnfieldlist if necessary. */
14629 if (flp
== nullptr)
14631 fip
->fnfieldlists
.emplace_back ();
14632 flp
= &fip
->fnfieldlists
.back ();
14633 flp
->name
= fieldname
;
14634 i
= fip
->fnfieldlists
.size () - 1;
14637 /* Create a new member function field and add it to the vector of
14639 flp
->fnfields
.emplace_back ();
14640 fnp
= &flp
->fnfields
.back ();
14642 /* Delay processing of the physname until later. */
14643 if (cu
->language
== language_cplus
)
14644 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14648 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14649 fnp
->physname
= physname
? physname
: "";
14652 fnp
->type
= alloc_type (objfile
);
14653 this_type
= read_type_die (die
, cu
);
14654 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14656 int nparams
= TYPE_NFIELDS (this_type
);
14658 /* TYPE is the domain of this method, and THIS_TYPE is the type
14659 of the method itself (TYPE_CODE_METHOD). */
14660 smash_to_method_type (fnp
->type
, type
,
14661 TYPE_TARGET_TYPE (this_type
),
14662 TYPE_FIELDS (this_type
),
14663 TYPE_NFIELDS (this_type
),
14664 TYPE_VARARGS (this_type
));
14666 /* Handle static member functions.
14667 Dwarf2 has no clean way to discern C++ static and non-static
14668 member functions. G++ helps GDB by marking the first
14669 parameter for non-static member functions (which is the this
14670 pointer) as artificial. We obtain this information from
14671 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14672 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14673 fnp
->voffset
= VOFFSET_STATIC
;
14676 complaint (_("member function type missing for '%s'"),
14677 dwarf2_full_name (fieldname
, die
, cu
));
14679 /* Get fcontext from DW_AT_containing_type if present. */
14680 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14681 fnp
->fcontext
= die_containing_type (die
, cu
);
14683 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14684 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14686 /* Get accessibility. */
14687 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14688 if (attr
!= nullptr)
14689 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14691 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14692 switch (accessibility
)
14694 case DW_ACCESS_private
:
14695 fnp
->is_private
= 1;
14697 case DW_ACCESS_protected
:
14698 fnp
->is_protected
= 1;
14702 /* Check for artificial methods. */
14703 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14704 if (attr
&& DW_UNSND (attr
) != 0)
14705 fnp
->is_artificial
= 1;
14707 /* Check for defaulted methods. */
14708 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14709 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14710 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14712 /* Check for deleted methods. */
14713 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14714 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14715 fnp
->is_deleted
= 1;
14717 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14719 /* Get index in virtual function table if it is a virtual member
14720 function. For older versions of GCC, this is an offset in the
14721 appropriate virtual table, as specified by DW_AT_containing_type.
14722 For everyone else, it is an expression to be evaluated relative
14723 to the object address. */
14725 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14726 if (attr
!= nullptr)
14728 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14730 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14732 /* Old-style GCC. */
14733 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14735 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14736 || (DW_BLOCK (attr
)->size
> 1
14737 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14738 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14740 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14741 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14742 dwarf2_complex_location_expr_complaint ();
14744 fnp
->voffset
/= cu
->header
.addr_size
;
14748 dwarf2_complex_location_expr_complaint ();
14750 if (!fnp
->fcontext
)
14752 /* If there is no `this' field and no DW_AT_containing_type,
14753 we cannot actually find a base class context for the
14755 if (TYPE_NFIELDS (this_type
) == 0
14756 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14758 complaint (_("cannot determine context for virtual member "
14759 "function \"%s\" (offset %s)"),
14760 fieldname
, sect_offset_str (die
->sect_off
));
14765 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14769 else if (attr
->form_is_section_offset ())
14771 dwarf2_complex_location_expr_complaint ();
14775 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14781 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14782 if (attr
&& DW_UNSND (attr
))
14784 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14785 complaint (_("Member function \"%s\" (offset %s) is virtual "
14786 "but the vtable offset is not specified"),
14787 fieldname
, sect_offset_str (die
->sect_off
));
14788 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14789 TYPE_CPLUS_DYNAMIC (type
) = 1;
14794 /* Create the vector of member function fields, and attach it to the type. */
14797 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14798 struct dwarf2_cu
*cu
)
14800 if (cu
->language
== language_ada
)
14801 error (_("unexpected member functions in Ada type"));
14803 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14804 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14806 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14808 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14810 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14811 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14813 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14814 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14815 fn_flp
->fn_fields
= (struct fn_field
*)
14816 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14818 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14819 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14822 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14825 /* Returns non-zero if NAME is the name of a vtable member in CU's
14826 language, zero otherwise. */
14828 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14830 static const char vptr
[] = "_vptr";
14832 /* Look for the C++ form of the vtable. */
14833 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14839 /* GCC outputs unnamed structures that are really pointers to member
14840 functions, with the ABI-specified layout. If TYPE describes
14841 such a structure, smash it into a member function type.
14843 GCC shouldn't do this; it should just output pointer to member DIEs.
14844 This is GCC PR debug/28767. */
14847 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14849 struct type
*pfn_type
, *self_type
, *new_type
;
14851 /* Check for a structure with no name and two children. */
14852 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14855 /* Check for __pfn and __delta members. */
14856 if (TYPE_FIELD_NAME (type
, 0) == NULL
14857 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14858 || TYPE_FIELD_NAME (type
, 1) == NULL
14859 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14862 /* Find the type of the method. */
14863 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14864 if (pfn_type
== NULL
14865 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14866 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14869 /* Look for the "this" argument. */
14870 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14871 if (TYPE_NFIELDS (pfn_type
) == 0
14872 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14873 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14876 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14877 new_type
= alloc_type (objfile
);
14878 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14879 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14880 TYPE_VARARGS (pfn_type
));
14881 smash_to_methodptr_type (type
, new_type
);
14884 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14885 appropriate error checking and issuing complaints if there is a
14889 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14891 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14893 if (attr
== nullptr)
14896 if (!attr
->form_is_constant ())
14898 complaint (_("DW_AT_alignment must have constant form"
14899 " - DIE at %s [in module %s]"),
14900 sect_offset_str (die
->sect_off
),
14901 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14906 if (attr
->form
== DW_FORM_sdata
)
14908 LONGEST val
= DW_SND (attr
);
14911 complaint (_("DW_AT_alignment value must not be negative"
14912 " - DIE at %s [in module %s]"),
14913 sect_offset_str (die
->sect_off
),
14914 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14920 align
= DW_UNSND (attr
);
14924 complaint (_("DW_AT_alignment value must not be zero"
14925 " - DIE at %s [in module %s]"),
14926 sect_offset_str (die
->sect_off
),
14927 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14930 if ((align
& (align
- 1)) != 0)
14932 complaint (_("DW_AT_alignment value must be a power of 2"
14933 " - DIE at %s [in module %s]"),
14934 sect_offset_str (die
->sect_off
),
14935 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14942 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14943 the alignment for TYPE. */
14946 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14949 if (!set_type_align (type
, get_alignment (cu
, die
)))
14950 complaint (_("DW_AT_alignment value too large"
14951 " - DIE at %s [in module %s]"),
14952 sect_offset_str (die
->sect_off
),
14953 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14956 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14957 constant for a type, according to DWARF5 spec, Table 5.5. */
14960 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14965 case DW_CC_pass_by_reference
:
14966 case DW_CC_pass_by_value
:
14970 complaint (_("unrecognized DW_AT_calling_convention value "
14971 "(%s) for a type"), pulongest (value
));
14976 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14977 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14978 also according to GNU-specific values (see include/dwarf2.h). */
14981 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14986 case DW_CC_program
:
14990 case DW_CC_GNU_renesas_sh
:
14991 case DW_CC_GNU_borland_fastcall_i386
:
14992 case DW_CC_GDB_IBM_OpenCL
:
14996 complaint (_("unrecognized DW_AT_calling_convention value "
14997 "(%s) for a subroutine"), pulongest (value
));
15002 /* Called when we find the DIE that starts a structure or union scope
15003 (definition) to create a type for the structure or union. Fill in
15004 the type's name and general properties; the members will not be
15005 processed until process_structure_scope. A symbol table entry for
15006 the type will also not be done until process_structure_scope (assuming
15007 the type has a name).
15009 NOTE: we need to call these functions regardless of whether or not the
15010 DIE has a DW_AT_name attribute, since it might be an anonymous
15011 structure or union. This gets the type entered into our set of
15012 user defined types. */
15014 static struct type
*
15015 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15017 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15019 struct attribute
*attr
;
15022 /* If the definition of this type lives in .debug_types, read that type.
15023 Don't follow DW_AT_specification though, that will take us back up
15024 the chain and we want to go down. */
15025 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15026 if (attr
!= nullptr)
15028 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15030 /* The type's CU may not be the same as CU.
15031 Ensure TYPE is recorded with CU in die_type_hash. */
15032 return set_die_type (die
, type
, cu
);
15035 type
= alloc_type (objfile
);
15036 INIT_CPLUS_SPECIFIC (type
);
15038 name
= dwarf2_name (die
, cu
);
15041 if (cu
->language
== language_cplus
15042 || cu
->language
== language_d
15043 || cu
->language
== language_rust
)
15045 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15047 /* dwarf2_full_name might have already finished building the DIE's
15048 type. If so, there is no need to continue. */
15049 if (get_die_type (die
, cu
) != NULL
)
15050 return get_die_type (die
, cu
);
15052 TYPE_NAME (type
) = full_name
;
15056 /* The name is already allocated along with this objfile, so
15057 we don't need to duplicate it for the type. */
15058 TYPE_NAME (type
) = name
;
15062 if (die
->tag
== DW_TAG_structure_type
)
15064 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15066 else if (die
->tag
== DW_TAG_union_type
)
15068 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15070 else if (die
->tag
== DW_TAG_variant_part
)
15072 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15073 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15077 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15080 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15081 TYPE_DECLARED_CLASS (type
) = 1;
15083 /* Store the calling convention in the type if it's available in
15084 the die. Otherwise the calling convention remains set to
15085 the default value DW_CC_normal. */
15086 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15087 if (attr
!= nullptr
15088 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15090 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15091 TYPE_CPLUS_CALLING_CONVENTION (type
)
15092 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15095 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15096 if (attr
!= nullptr)
15098 if (attr
->form_is_constant ())
15099 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15102 /* For the moment, dynamic type sizes are not supported
15103 by GDB's struct type. The actual size is determined
15104 on-demand when resolving the type of a given object,
15105 so set the type's length to zero for now. Otherwise,
15106 we record an expression as the length, and that expression
15107 could lead to a very large value, which could eventually
15108 lead to us trying to allocate that much memory when creating
15109 a value of that type. */
15110 TYPE_LENGTH (type
) = 0;
15115 TYPE_LENGTH (type
) = 0;
15118 maybe_set_alignment (cu
, die
, type
);
15120 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15122 /* ICC<14 does not output the required DW_AT_declaration on
15123 incomplete types, but gives them a size of zero. */
15124 TYPE_STUB (type
) = 1;
15127 TYPE_STUB_SUPPORTED (type
) = 1;
15129 if (die_is_declaration (die
, cu
))
15130 TYPE_STUB (type
) = 1;
15131 else if (attr
== NULL
&& die
->child
== NULL
15132 && producer_is_realview (cu
->producer
))
15133 /* RealView does not output the required DW_AT_declaration
15134 on incomplete types. */
15135 TYPE_STUB (type
) = 1;
15137 /* We need to add the type field to the die immediately so we don't
15138 infinitely recurse when dealing with pointers to the structure
15139 type within the structure itself. */
15140 set_die_type (die
, type
, cu
);
15142 /* set_die_type should be already done. */
15143 set_descriptive_type (type
, die
, cu
);
15148 /* A helper for process_structure_scope that handles a single member
15152 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15153 struct field_info
*fi
,
15154 std::vector
<struct symbol
*> *template_args
,
15155 struct dwarf2_cu
*cu
)
15157 if (child_die
->tag
== DW_TAG_member
15158 || child_die
->tag
== DW_TAG_variable
15159 || child_die
->tag
== DW_TAG_variant_part
)
15161 /* NOTE: carlton/2002-11-05: A C++ static data member
15162 should be a DW_TAG_member that is a declaration, but
15163 all versions of G++ as of this writing (so through at
15164 least 3.2.1) incorrectly generate DW_TAG_variable
15165 tags for them instead. */
15166 dwarf2_add_field (fi
, child_die
, cu
);
15168 else if (child_die
->tag
== DW_TAG_subprogram
)
15170 /* Rust doesn't have member functions in the C++ sense.
15171 However, it does emit ordinary functions as children
15172 of a struct DIE. */
15173 if (cu
->language
== language_rust
)
15174 read_func_scope (child_die
, cu
);
15177 /* C++ member function. */
15178 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15181 else if (child_die
->tag
== DW_TAG_inheritance
)
15183 /* C++ base class field. */
15184 dwarf2_add_field (fi
, child_die
, cu
);
15186 else if (type_can_define_types (child_die
))
15187 dwarf2_add_type_defn (fi
, child_die
, cu
);
15188 else if (child_die
->tag
== DW_TAG_template_type_param
15189 || child_die
->tag
== DW_TAG_template_value_param
)
15191 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15194 template_args
->push_back (arg
);
15196 else if (child_die
->tag
== DW_TAG_variant
)
15198 /* In a variant we want to get the discriminant and also add a
15199 field for our sole member child. */
15200 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15202 for (die_info
*variant_child
= child_die
->child
;
15203 variant_child
!= NULL
;
15204 variant_child
= sibling_die (variant_child
))
15206 if (variant_child
->tag
== DW_TAG_member
)
15208 handle_struct_member_die (variant_child
, type
, fi
,
15209 template_args
, cu
);
15210 /* Only handle the one. */
15215 /* We don't handle this but we might as well report it if we see
15217 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15218 complaint (_("DW_AT_discr_list is not supported yet"
15219 " - DIE at %s [in module %s]"),
15220 sect_offset_str (child_die
->sect_off
),
15221 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15223 /* The first field was just added, so we can stash the
15224 discriminant there. */
15225 gdb_assert (!fi
->fields
.empty ());
15227 fi
->fields
.back ().variant
.default_branch
= true;
15229 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15233 /* Finish creating a structure or union type, including filling in
15234 its members and creating a symbol for it. */
15237 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15239 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15240 struct die_info
*child_die
;
15243 type
= get_die_type (die
, cu
);
15245 type
= read_structure_type (die
, cu
);
15247 /* When reading a DW_TAG_variant_part, we need to notice when we
15248 read the discriminant member, so we can record it later in the
15249 discriminant_info. */
15250 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15251 sect_offset discr_offset
{};
15252 bool has_template_parameters
= false;
15254 if (is_variant_part
)
15256 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15259 /* Maybe it's a univariant form, an extension we support.
15260 In this case arrange not to check the offset. */
15261 is_variant_part
= false;
15263 else if (discr
->form_is_ref ())
15265 struct dwarf2_cu
*target_cu
= cu
;
15266 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15268 discr_offset
= target_die
->sect_off
;
15272 complaint (_("DW_AT_discr does not have DIE reference form"
15273 " - DIE at %s [in module %s]"),
15274 sect_offset_str (die
->sect_off
),
15275 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15276 is_variant_part
= false;
15280 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15282 struct field_info fi
;
15283 std::vector
<struct symbol
*> template_args
;
15285 child_die
= die
->child
;
15287 while (child_die
&& child_die
->tag
)
15289 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15291 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15292 fi
.fields
.back ().variant
.is_discriminant
= true;
15294 child_die
= sibling_die (child_die
);
15297 /* Attach template arguments to type. */
15298 if (!template_args
.empty ())
15300 has_template_parameters
= true;
15301 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15302 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15303 TYPE_TEMPLATE_ARGUMENTS (type
)
15304 = XOBNEWVEC (&objfile
->objfile_obstack
,
15306 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15307 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15308 template_args
.data (),
15309 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15310 * sizeof (struct symbol
*)));
15313 /* Attach fields and member functions to the type. */
15315 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15316 if (!fi
.fnfieldlists
.empty ())
15318 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15320 /* Get the type which refers to the base class (possibly this
15321 class itself) which contains the vtable pointer for the current
15322 class from the DW_AT_containing_type attribute. This use of
15323 DW_AT_containing_type is a GNU extension. */
15325 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15327 struct type
*t
= die_containing_type (die
, cu
);
15329 set_type_vptr_basetype (type
, t
);
15334 /* Our own class provides vtbl ptr. */
15335 for (i
= TYPE_NFIELDS (t
) - 1;
15336 i
>= TYPE_N_BASECLASSES (t
);
15339 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15341 if (is_vtable_name (fieldname
, cu
))
15343 set_type_vptr_fieldno (type
, i
);
15348 /* Complain if virtual function table field not found. */
15349 if (i
< TYPE_N_BASECLASSES (t
))
15350 complaint (_("virtual function table pointer "
15351 "not found when defining class '%s'"),
15352 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15356 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15359 else if (cu
->producer
15360 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15362 /* The IBM XLC compiler does not provide direct indication
15363 of the containing type, but the vtable pointer is
15364 always named __vfp. */
15368 for (i
= TYPE_NFIELDS (type
) - 1;
15369 i
>= TYPE_N_BASECLASSES (type
);
15372 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15374 set_type_vptr_fieldno (type
, i
);
15375 set_type_vptr_basetype (type
, type
);
15382 /* Copy fi.typedef_field_list linked list elements content into the
15383 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15384 if (!fi
.typedef_field_list
.empty ())
15386 int count
= fi
.typedef_field_list
.size ();
15388 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15389 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15390 = ((struct decl_field
*)
15392 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15393 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15395 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15396 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15399 /* Copy fi.nested_types_list linked list elements content into the
15400 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15401 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15403 int count
= fi
.nested_types_list
.size ();
15405 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15406 TYPE_NESTED_TYPES_ARRAY (type
)
15407 = ((struct decl_field
*)
15408 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15409 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15411 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15412 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15416 quirk_gcc_member_function_pointer (type
, objfile
);
15417 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15418 cu
->rust_unions
.push_back (type
);
15420 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15421 snapshots) has been known to create a die giving a declaration
15422 for a class that has, as a child, a die giving a definition for a
15423 nested class. So we have to process our children even if the
15424 current die is a declaration. Normally, of course, a declaration
15425 won't have any children at all. */
15427 child_die
= die
->child
;
15429 while (child_die
!= NULL
&& child_die
->tag
)
15431 if (child_die
->tag
== DW_TAG_member
15432 || child_die
->tag
== DW_TAG_variable
15433 || child_die
->tag
== DW_TAG_inheritance
15434 || child_die
->tag
== DW_TAG_template_value_param
15435 || child_die
->tag
== DW_TAG_template_type_param
)
15440 process_die (child_die
, cu
);
15442 child_die
= sibling_die (child_die
);
15445 /* Do not consider external references. According to the DWARF standard,
15446 these DIEs are identified by the fact that they have no byte_size
15447 attribute, and a declaration attribute. */
15448 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15449 || !die_is_declaration (die
, cu
))
15451 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15453 if (has_template_parameters
)
15455 struct symtab
*symtab
;
15456 if (sym
!= nullptr)
15457 symtab
= symbol_symtab (sym
);
15458 else if (cu
->line_header
!= nullptr)
15460 /* Any related symtab will do. */
15462 = cu
->line_header
->file_names ()[0].symtab
;
15467 complaint (_("could not find suitable "
15468 "symtab for template parameter"
15469 " - DIE at %s [in module %s]"),
15470 sect_offset_str (die
->sect_off
),
15471 objfile_name (objfile
));
15474 if (symtab
!= nullptr)
15476 /* Make sure that the symtab is set on the new symbols.
15477 Even though they don't appear in this symtab directly,
15478 other parts of gdb assume that symbols do, and this is
15479 reasonably true. */
15480 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15481 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15487 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15488 update TYPE using some information only available in DIE's children. */
15491 update_enumeration_type_from_children (struct die_info
*die
,
15493 struct dwarf2_cu
*cu
)
15495 struct die_info
*child_die
;
15496 int unsigned_enum
= 1;
15500 auto_obstack obstack
;
15502 for (child_die
= die
->child
;
15503 child_die
!= NULL
&& child_die
->tag
;
15504 child_die
= sibling_die (child_die
))
15506 struct attribute
*attr
;
15508 const gdb_byte
*bytes
;
15509 struct dwarf2_locexpr_baton
*baton
;
15512 if (child_die
->tag
!= DW_TAG_enumerator
)
15515 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15519 name
= dwarf2_name (child_die
, cu
);
15521 name
= "<anonymous enumerator>";
15523 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15524 &value
, &bytes
, &baton
);
15530 else if ((mask
& value
) != 0)
15535 /* If we already know that the enum type is neither unsigned, nor
15536 a flag type, no need to look at the rest of the enumerates. */
15537 if (!unsigned_enum
&& !flag_enum
)
15542 TYPE_UNSIGNED (type
) = 1;
15544 TYPE_FLAG_ENUM (type
) = 1;
15547 /* Given a DW_AT_enumeration_type die, set its type. We do not
15548 complete the type's fields yet, or create any symbols. */
15550 static struct type
*
15551 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15553 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15555 struct attribute
*attr
;
15558 /* If the definition of this type lives in .debug_types, read that type.
15559 Don't follow DW_AT_specification though, that will take us back up
15560 the chain and we want to go down. */
15561 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15562 if (attr
!= nullptr)
15564 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15566 /* The type's CU may not be the same as CU.
15567 Ensure TYPE is recorded with CU in die_type_hash. */
15568 return set_die_type (die
, type
, cu
);
15571 type
= alloc_type (objfile
);
15573 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15574 name
= dwarf2_full_name (NULL
, die
, cu
);
15576 TYPE_NAME (type
) = name
;
15578 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15581 struct type
*underlying_type
= die_type (die
, cu
);
15583 TYPE_TARGET_TYPE (type
) = underlying_type
;
15586 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15587 if (attr
!= nullptr)
15589 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15593 TYPE_LENGTH (type
) = 0;
15596 maybe_set_alignment (cu
, die
, type
);
15598 /* The enumeration DIE can be incomplete. In Ada, any type can be
15599 declared as private in the package spec, and then defined only
15600 inside the package body. Such types are known as Taft Amendment
15601 Types. When another package uses such a type, an incomplete DIE
15602 may be generated by the compiler. */
15603 if (die_is_declaration (die
, cu
))
15604 TYPE_STUB (type
) = 1;
15606 /* Finish the creation of this type by using the enum's children.
15607 We must call this even when the underlying type has been provided
15608 so that we can determine if we're looking at a "flag" enum. */
15609 update_enumeration_type_from_children (die
, type
, cu
);
15611 /* If this type has an underlying type that is not a stub, then we
15612 may use its attributes. We always use the "unsigned" attribute
15613 in this situation, because ordinarily we guess whether the type
15614 is unsigned -- but the guess can be wrong and the underlying type
15615 can tell us the reality. However, we defer to a local size
15616 attribute if one exists, because this lets the compiler override
15617 the underlying type if needed. */
15618 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15620 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15621 if (TYPE_LENGTH (type
) == 0)
15622 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15623 if (TYPE_RAW_ALIGN (type
) == 0
15624 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15625 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15628 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15630 return set_die_type (die
, type
, cu
);
15633 /* Given a pointer to a die which begins an enumeration, process all
15634 the dies that define the members of the enumeration, and create the
15635 symbol for the enumeration type.
15637 NOTE: We reverse the order of the element list. */
15640 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15642 struct type
*this_type
;
15644 this_type
= get_die_type (die
, cu
);
15645 if (this_type
== NULL
)
15646 this_type
= read_enumeration_type (die
, cu
);
15648 if (die
->child
!= NULL
)
15650 struct die_info
*child_die
;
15651 struct symbol
*sym
;
15652 std::vector
<struct field
> fields
;
15655 child_die
= die
->child
;
15656 while (child_die
&& child_die
->tag
)
15658 if (child_die
->tag
!= DW_TAG_enumerator
)
15660 process_die (child_die
, cu
);
15664 name
= dwarf2_name (child_die
, cu
);
15667 sym
= new_symbol (child_die
, this_type
, cu
);
15669 fields
.emplace_back ();
15670 struct field
&field
= fields
.back ();
15672 FIELD_NAME (field
) = sym
->linkage_name ();
15673 FIELD_TYPE (field
) = NULL
;
15674 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15675 FIELD_BITSIZE (field
) = 0;
15679 child_die
= sibling_die (child_die
);
15682 if (!fields
.empty ())
15684 TYPE_NFIELDS (this_type
) = fields
.size ();
15685 TYPE_FIELDS (this_type
) = (struct field
*)
15686 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15687 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15688 sizeof (struct field
) * fields
.size ());
15692 /* If we are reading an enum from a .debug_types unit, and the enum
15693 is a declaration, and the enum is not the signatured type in the
15694 unit, then we do not want to add a symbol for it. Adding a
15695 symbol would in some cases obscure the true definition of the
15696 enum, giving users an incomplete type when the definition is
15697 actually available. Note that we do not want to do this for all
15698 enums which are just declarations, because C++0x allows forward
15699 enum declarations. */
15700 if (cu
->per_cu
->is_debug_types
15701 && die_is_declaration (die
, cu
))
15703 struct signatured_type
*sig_type
;
15705 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15706 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15707 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15711 new_symbol (die
, this_type
, cu
);
15714 /* Extract all information from a DW_TAG_array_type DIE and put it in
15715 the DIE's type field. For now, this only handles one dimensional
15718 static struct type
*
15719 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15721 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15722 struct die_info
*child_die
;
15724 struct type
*element_type
, *range_type
, *index_type
;
15725 struct attribute
*attr
;
15727 struct dynamic_prop
*byte_stride_prop
= NULL
;
15728 unsigned int bit_stride
= 0;
15730 element_type
= die_type (die
, cu
);
15732 /* The die_type call above may have already set the type for this DIE. */
15733 type
= get_die_type (die
, cu
);
15737 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15741 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15744 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15745 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15749 complaint (_("unable to read array DW_AT_byte_stride "
15750 " - DIE at %s [in module %s]"),
15751 sect_offset_str (die
->sect_off
),
15752 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15753 /* Ignore this attribute. We will likely not be able to print
15754 arrays of this type correctly, but there is little we can do
15755 to help if we cannot read the attribute's value. */
15756 byte_stride_prop
= NULL
;
15760 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15762 bit_stride
= DW_UNSND (attr
);
15764 /* Irix 6.2 native cc creates array types without children for
15765 arrays with unspecified length. */
15766 if (die
->child
== NULL
)
15768 index_type
= objfile_type (objfile
)->builtin_int
;
15769 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15770 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15771 byte_stride_prop
, bit_stride
);
15772 return set_die_type (die
, type
, cu
);
15775 std::vector
<struct type
*> range_types
;
15776 child_die
= die
->child
;
15777 while (child_die
&& child_die
->tag
)
15779 if (child_die
->tag
== DW_TAG_subrange_type
)
15781 struct type
*child_type
= read_type_die (child_die
, cu
);
15783 if (child_type
!= NULL
)
15785 /* The range type was succesfully read. Save it for the
15786 array type creation. */
15787 range_types
.push_back (child_type
);
15790 child_die
= sibling_die (child_die
);
15793 /* Dwarf2 dimensions are output from left to right, create the
15794 necessary array types in backwards order. */
15796 type
= element_type
;
15798 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15802 while (i
< range_types
.size ())
15803 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15804 byte_stride_prop
, bit_stride
);
15808 size_t ndim
= range_types
.size ();
15810 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15811 byte_stride_prop
, bit_stride
);
15814 /* Understand Dwarf2 support for vector types (like they occur on
15815 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15816 array type. This is not part of the Dwarf2/3 standard yet, but a
15817 custom vendor extension. The main difference between a regular
15818 array and the vector variant is that vectors are passed by value
15820 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15821 if (attr
!= nullptr)
15822 make_vector_type (type
);
15824 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15825 implementation may choose to implement triple vectors using this
15827 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15828 if (attr
!= nullptr)
15830 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15831 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15833 complaint (_("DW_AT_byte_size for array type smaller "
15834 "than the total size of elements"));
15837 name
= dwarf2_name (die
, cu
);
15839 TYPE_NAME (type
) = name
;
15841 maybe_set_alignment (cu
, die
, type
);
15843 /* Install the type in the die. */
15844 set_die_type (die
, type
, cu
);
15846 /* set_die_type should be already done. */
15847 set_descriptive_type (type
, die
, cu
);
15852 static enum dwarf_array_dim_ordering
15853 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15855 struct attribute
*attr
;
15857 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15859 if (attr
!= nullptr)
15860 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15862 /* GNU F77 is a special case, as at 08/2004 array type info is the
15863 opposite order to the dwarf2 specification, but data is still
15864 laid out as per normal fortran.
15866 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15867 version checking. */
15869 if (cu
->language
== language_fortran
15870 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15872 return DW_ORD_row_major
;
15875 switch (cu
->language_defn
->la_array_ordering
)
15877 case array_column_major
:
15878 return DW_ORD_col_major
;
15879 case array_row_major
:
15881 return DW_ORD_row_major
;
15885 /* Extract all information from a DW_TAG_set_type DIE and put it in
15886 the DIE's type field. */
15888 static struct type
*
15889 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15891 struct type
*domain_type
, *set_type
;
15892 struct attribute
*attr
;
15894 domain_type
= die_type (die
, cu
);
15896 /* The die_type call above may have already set the type for this DIE. */
15897 set_type
= get_die_type (die
, cu
);
15901 set_type
= create_set_type (NULL
, domain_type
);
15903 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15904 if (attr
!= nullptr)
15905 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15907 maybe_set_alignment (cu
, die
, set_type
);
15909 return set_die_type (die
, set_type
, cu
);
15912 /* A helper for read_common_block that creates a locexpr baton.
15913 SYM is the symbol which we are marking as computed.
15914 COMMON_DIE is the DIE for the common block.
15915 COMMON_LOC is the location expression attribute for the common
15917 MEMBER_LOC is the location expression attribute for the particular
15918 member of the common block that we are processing.
15919 CU is the CU from which the above come. */
15922 mark_common_block_symbol_computed (struct symbol
*sym
,
15923 struct die_info
*common_die
,
15924 struct attribute
*common_loc
,
15925 struct attribute
*member_loc
,
15926 struct dwarf2_cu
*cu
)
15928 struct dwarf2_per_objfile
*dwarf2_per_objfile
15929 = cu
->per_cu
->dwarf2_per_objfile
;
15930 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15931 struct dwarf2_locexpr_baton
*baton
;
15933 unsigned int cu_off
;
15934 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15935 LONGEST offset
= 0;
15937 gdb_assert (common_loc
&& member_loc
);
15938 gdb_assert (common_loc
->form_is_block ());
15939 gdb_assert (member_loc
->form_is_block ()
15940 || member_loc
->form_is_constant ());
15942 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15943 baton
->per_cu
= cu
->per_cu
;
15944 gdb_assert (baton
->per_cu
);
15946 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15948 if (member_loc
->form_is_constant ())
15950 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15951 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15954 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15956 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15959 *ptr
++ = DW_OP_call4
;
15960 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15961 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15964 if (member_loc
->form_is_constant ())
15966 *ptr
++ = DW_OP_addr
;
15967 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15968 ptr
+= cu
->header
.addr_size
;
15972 /* We have to copy the data here, because DW_OP_call4 will only
15973 use a DW_AT_location attribute. */
15974 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15975 ptr
+= DW_BLOCK (member_loc
)->size
;
15978 *ptr
++ = DW_OP_plus
;
15979 gdb_assert (ptr
- baton
->data
== baton
->size
);
15981 SYMBOL_LOCATION_BATON (sym
) = baton
;
15982 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15985 /* Create appropriate locally-scoped variables for all the
15986 DW_TAG_common_block entries. Also create a struct common_block
15987 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15988 is used to separate the common blocks name namespace from regular
15992 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15994 struct attribute
*attr
;
15996 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15997 if (attr
!= nullptr)
15999 /* Support the .debug_loc offsets. */
16000 if (attr
->form_is_block ())
16004 else if (attr
->form_is_section_offset ())
16006 dwarf2_complex_location_expr_complaint ();
16011 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16012 "common block member");
16017 if (die
->child
!= NULL
)
16019 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16020 struct die_info
*child_die
;
16021 size_t n_entries
= 0, size
;
16022 struct common_block
*common_block
;
16023 struct symbol
*sym
;
16025 for (child_die
= die
->child
;
16026 child_die
&& child_die
->tag
;
16027 child_die
= sibling_die (child_die
))
16030 size
= (sizeof (struct common_block
)
16031 + (n_entries
- 1) * sizeof (struct symbol
*));
16033 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16035 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16036 common_block
->n_entries
= 0;
16038 for (child_die
= die
->child
;
16039 child_die
&& child_die
->tag
;
16040 child_die
= sibling_die (child_die
))
16042 /* Create the symbol in the DW_TAG_common_block block in the current
16044 sym
= new_symbol (child_die
, NULL
, cu
);
16047 struct attribute
*member_loc
;
16049 common_block
->contents
[common_block
->n_entries
++] = sym
;
16051 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16055 /* GDB has handled this for a long time, but it is
16056 not specified by DWARF. It seems to have been
16057 emitted by gfortran at least as recently as:
16058 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16059 complaint (_("Variable in common block has "
16060 "DW_AT_data_member_location "
16061 "- DIE at %s [in module %s]"),
16062 sect_offset_str (child_die
->sect_off
),
16063 objfile_name (objfile
));
16065 if (member_loc
->form_is_section_offset ())
16066 dwarf2_complex_location_expr_complaint ();
16067 else if (member_loc
->form_is_constant ()
16068 || member_loc
->form_is_block ())
16070 if (attr
!= nullptr)
16071 mark_common_block_symbol_computed (sym
, die
, attr
,
16075 dwarf2_complex_location_expr_complaint ();
16080 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16081 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16085 /* Create a type for a C++ namespace. */
16087 static struct type
*
16088 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16090 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16091 const char *previous_prefix
, *name
;
16095 /* For extensions, reuse the type of the original namespace. */
16096 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16098 struct die_info
*ext_die
;
16099 struct dwarf2_cu
*ext_cu
= cu
;
16101 ext_die
= dwarf2_extension (die
, &ext_cu
);
16102 type
= read_type_die (ext_die
, ext_cu
);
16104 /* EXT_CU may not be the same as CU.
16105 Ensure TYPE is recorded with CU in die_type_hash. */
16106 return set_die_type (die
, type
, cu
);
16109 name
= namespace_name (die
, &is_anonymous
, cu
);
16111 /* Now build the name of the current namespace. */
16113 previous_prefix
= determine_prefix (die
, cu
);
16114 if (previous_prefix
[0] != '\0')
16115 name
= typename_concat (&objfile
->objfile_obstack
,
16116 previous_prefix
, name
, 0, cu
);
16118 /* Create the type. */
16119 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16121 return set_die_type (die
, type
, cu
);
16124 /* Read a namespace scope. */
16127 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16129 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16132 /* Add a symbol associated to this if we haven't seen the namespace
16133 before. Also, add a using directive if it's an anonymous
16136 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16140 type
= read_type_die (die
, cu
);
16141 new_symbol (die
, type
, cu
);
16143 namespace_name (die
, &is_anonymous
, cu
);
16146 const char *previous_prefix
= determine_prefix (die
, cu
);
16148 std::vector
<const char *> excludes
;
16149 add_using_directive (using_directives (cu
),
16150 previous_prefix
, TYPE_NAME (type
), NULL
,
16151 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16155 if (die
->child
!= NULL
)
16157 struct die_info
*child_die
= die
->child
;
16159 while (child_die
&& child_die
->tag
)
16161 process_die (child_die
, cu
);
16162 child_die
= sibling_die (child_die
);
16167 /* Read a Fortran module as type. This DIE can be only a declaration used for
16168 imported module. Still we need that type as local Fortran "use ... only"
16169 declaration imports depend on the created type in determine_prefix. */
16171 static struct type
*
16172 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16174 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16175 const char *module_name
;
16178 module_name
= dwarf2_name (die
, cu
);
16179 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16181 return set_die_type (die
, type
, cu
);
16184 /* Read a Fortran module. */
16187 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16189 struct die_info
*child_die
= die
->child
;
16192 type
= read_type_die (die
, cu
);
16193 new_symbol (die
, type
, cu
);
16195 while (child_die
&& child_die
->tag
)
16197 process_die (child_die
, cu
);
16198 child_die
= sibling_die (child_die
);
16202 /* Return the name of the namespace represented by DIE. Set
16203 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16206 static const char *
16207 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16209 struct die_info
*current_die
;
16210 const char *name
= NULL
;
16212 /* Loop through the extensions until we find a name. */
16214 for (current_die
= die
;
16215 current_die
!= NULL
;
16216 current_die
= dwarf2_extension (die
, &cu
))
16218 /* We don't use dwarf2_name here so that we can detect the absence
16219 of a name -> anonymous namespace. */
16220 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16226 /* Is it an anonymous namespace? */
16228 *is_anonymous
= (name
== NULL
);
16230 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16235 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16236 the user defined type vector. */
16238 static struct type
*
16239 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16241 struct gdbarch
*gdbarch
16242 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16243 struct comp_unit_head
*cu_header
= &cu
->header
;
16245 struct attribute
*attr_byte_size
;
16246 struct attribute
*attr_address_class
;
16247 int byte_size
, addr_class
;
16248 struct type
*target_type
;
16250 target_type
= die_type (die
, cu
);
16252 /* The die_type call above may have already set the type for this DIE. */
16253 type
= get_die_type (die
, cu
);
16257 type
= lookup_pointer_type (target_type
);
16259 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16260 if (attr_byte_size
)
16261 byte_size
= DW_UNSND (attr_byte_size
);
16263 byte_size
= cu_header
->addr_size
;
16265 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16266 if (attr_address_class
)
16267 addr_class
= DW_UNSND (attr_address_class
);
16269 addr_class
= DW_ADDR_none
;
16271 ULONGEST alignment
= get_alignment (cu
, die
);
16273 /* If the pointer size, alignment, or address class is different
16274 than the default, create a type variant marked as such and set
16275 the length accordingly. */
16276 if (TYPE_LENGTH (type
) != byte_size
16277 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16278 && alignment
!= TYPE_RAW_ALIGN (type
))
16279 || addr_class
!= DW_ADDR_none
)
16281 if (gdbarch_address_class_type_flags_p (gdbarch
))
16285 type_flags
= gdbarch_address_class_type_flags
16286 (gdbarch
, byte_size
, addr_class
);
16287 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16289 type
= make_type_with_address_space (type
, type_flags
);
16291 else if (TYPE_LENGTH (type
) != byte_size
)
16293 complaint (_("invalid pointer size %d"), byte_size
);
16295 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16297 complaint (_("Invalid DW_AT_alignment"
16298 " - DIE at %s [in module %s]"),
16299 sect_offset_str (die
->sect_off
),
16300 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16304 /* Should we also complain about unhandled address classes? */
16308 TYPE_LENGTH (type
) = byte_size
;
16309 set_type_align (type
, alignment
);
16310 return set_die_type (die
, type
, cu
);
16313 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16314 the user defined type vector. */
16316 static struct type
*
16317 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16320 struct type
*to_type
;
16321 struct type
*domain
;
16323 to_type
= die_type (die
, cu
);
16324 domain
= die_containing_type (die
, cu
);
16326 /* The calls above may have already set the type for this DIE. */
16327 type
= get_die_type (die
, cu
);
16331 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16332 type
= lookup_methodptr_type (to_type
);
16333 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16335 struct type
*new_type
16336 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16338 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16339 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16340 TYPE_VARARGS (to_type
));
16341 type
= lookup_methodptr_type (new_type
);
16344 type
= lookup_memberptr_type (to_type
, domain
);
16346 return set_die_type (die
, type
, cu
);
16349 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16350 the user defined type vector. */
16352 static struct type
*
16353 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16354 enum type_code refcode
)
16356 struct comp_unit_head
*cu_header
= &cu
->header
;
16357 struct type
*type
, *target_type
;
16358 struct attribute
*attr
;
16360 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16362 target_type
= die_type (die
, cu
);
16364 /* The die_type call above may have already set the type for this DIE. */
16365 type
= get_die_type (die
, cu
);
16369 type
= lookup_reference_type (target_type
, refcode
);
16370 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16371 if (attr
!= nullptr)
16373 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16377 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16379 maybe_set_alignment (cu
, die
, type
);
16380 return set_die_type (die
, type
, cu
);
16383 /* Add the given cv-qualifiers to the element type of the array. GCC
16384 outputs DWARF type qualifiers that apply to an array, not the
16385 element type. But GDB relies on the array element type to carry
16386 the cv-qualifiers. This mimics section 6.7.3 of the C99
16389 static struct type
*
16390 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16391 struct type
*base_type
, int cnst
, int voltl
)
16393 struct type
*el_type
, *inner_array
;
16395 base_type
= copy_type (base_type
);
16396 inner_array
= base_type
;
16398 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16400 TYPE_TARGET_TYPE (inner_array
) =
16401 copy_type (TYPE_TARGET_TYPE (inner_array
));
16402 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16405 el_type
= TYPE_TARGET_TYPE (inner_array
);
16406 cnst
|= TYPE_CONST (el_type
);
16407 voltl
|= TYPE_VOLATILE (el_type
);
16408 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16410 return set_die_type (die
, base_type
, cu
);
16413 static struct type
*
16414 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16416 struct type
*base_type
, *cv_type
;
16418 base_type
= die_type (die
, cu
);
16420 /* The die_type call above may have already set the type for this DIE. */
16421 cv_type
= get_die_type (die
, cu
);
16425 /* In case the const qualifier is applied to an array type, the element type
16426 is so qualified, not the array type (section 6.7.3 of C99). */
16427 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16428 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16430 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16431 return set_die_type (die
, cv_type
, cu
);
16434 static struct type
*
16435 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16437 struct type
*base_type
, *cv_type
;
16439 base_type
= die_type (die
, cu
);
16441 /* The die_type call above may have already set the type for this DIE. */
16442 cv_type
= get_die_type (die
, cu
);
16446 /* In case the volatile qualifier is applied to an array type, the
16447 element type is so qualified, not the array type (section 6.7.3
16449 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16450 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16452 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16453 return set_die_type (die
, cv_type
, cu
);
16456 /* Handle DW_TAG_restrict_type. */
16458 static struct type
*
16459 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16461 struct type
*base_type
, *cv_type
;
16463 base_type
= die_type (die
, cu
);
16465 /* The die_type call above may have already set the type for this DIE. */
16466 cv_type
= get_die_type (die
, cu
);
16470 cv_type
= make_restrict_type (base_type
);
16471 return set_die_type (die
, cv_type
, cu
);
16474 /* Handle DW_TAG_atomic_type. */
16476 static struct type
*
16477 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16479 struct type
*base_type
, *cv_type
;
16481 base_type
= die_type (die
, cu
);
16483 /* The die_type call above may have already set the type for this DIE. */
16484 cv_type
= get_die_type (die
, cu
);
16488 cv_type
= make_atomic_type (base_type
);
16489 return set_die_type (die
, cv_type
, cu
);
16492 /* Extract all information from a DW_TAG_string_type DIE and add to
16493 the user defined type vector. It isn't really a user defined type,
16494 but it behaves like one, with other DIE's using an AT_user_def_type
16495 attribute to reference it. */
16497 static struct type
*
16498 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16500 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16501 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16502 struct type
*type
, *range_type
, *index_type
, *char_type
;
16503 struct attribute
*attr
;
16504 struct dynamic_prop prop
;
16505 bool length_is_constant
= true;
16508 /* There are a couple of places where bit sizes might be made use of
16509 when parsing a DW_TAG_string_type, however, no producer that we know
16510 of make use of these. Handling bit sizes that are a multiple of the
16511 byte size is easy enough, but what about other bit sizes? Lets deal
16512 with that problem when we have to. Warn about these attributes being
16513 unsupported, then parse the type and ignore them like we always
16515 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16516 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16518 static bool warning_printed
= false;
16519 if (!warning_printed
)
16521 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16522 "currently supported on DW_TAG_string_type."));
16523 warning_printed
= true;
16527 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16528 if (attr
!= nullptr && !attr
->form_is_constant ())
16530 /* The string length describes the location at which the length of
16531 the string can be found. The size of the length field can be
16532 specified with one of the attributes below. */
16533 struct type
*prop_type
;
16534 struct attribute
*len
16535 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16536 if (len
== nullptr)
16537 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16538 if (len
!= nullptr && len
->form_is_constant ())
16540 /* Pass 0 as the default as we know this attribute is constant
16541 and the default value will not be returned. */
16542 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16543 prop_type
= cu
->per_cu
->int_type (sz
, true);
16547 /* If the size is not specified then we assume it is the size of
16548 an address on this target. */
16549 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16552 /* Convert the attribute into a dynamic property. */
16553 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16556 length_is_constant
= false;
16558 else if (attr
!= nullptr)
16560 /* This DW_AT_string_length just contains the length with no
16561 indirection. There's no need to create a dynamic property in this
16562 case. Pass 0 for the default value as we know it will not be
16563 returned in this case. */
16564 length
= dwarf2_get_attr_constant_value (attr
, 0);
16566 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16568 /* We don't currently support non-constant byte sizes for strings. */
16569 length
= dwarf2_get_attr_constant_value (attr
, 1);
16573 /* Use 1 as a fallback length if we have nothing else. */
16577 index_type
= objfile_type (objfile
)->builtin_int
;
16578 if (length_is_constant
)
16579 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16582 struct dynamic_prop low_bound
;
16584 low_bound
.kind
= PROP_CONST
;
16585 low_bound
.data
.const_val
= 1;
16586 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16588 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16589 type
= create_string_type (NULL
, char_type
, range_type
);
16591 return set_die_type (die
, type
, cu
);
16594 /* Assuming that DIE corresponds to a function, returns nonzero
16595 if the function is prototyped. */
16598 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16600 struct attribute
*attr
;
16602 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16603 if (attr
&& (DW_UNSND (attr
) != 0))
16606 /* The DWARF standard implies that the DW_AT_prototyped attribute
16607 is only meaningful for C, but the concept also extends to other
16608 languages that allow unprototyped functions (Eg: Objective C).
16609 For all other languages, assume that functions are always
16611 if (cu
->language
!= language_c
16612 && cu
->language
!= language_objc
16613 && cu
->language
!= language_opencl
)
16616 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16617 prototyped and unprototyped functions; default to prototyped,
16618 since that is more common in modern code (and RealView warns
16619 about unprototyped functions). */
16620 if (producer_is_realview (cu
->producer
))
16626 /* Handle DIES due to C code like:
16630 int (*funcp)(int a, long l);
16634 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16636 static struct type
*
16637 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16639 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16640 struct type
*type
; /* Type that this function returns. */
16641 struct type
*ftype
; /* Function that returns above type. */
16642 struct attribute
*attr
;
16644 type
= die_type (die
, cu
);
16646 /* The die_type call above may have already set the type for this DIE. */
16647 ftype
= get_die_type (die
, cu
);
16651 ftype
= lookup_function_type (type
);
16653 if (prototyped_function_p (die
, cu
))
16654 TYPE_PROTOTYPED (ftype
) = 1;
16656 /* Store the calling convention in the type if it's available in
16657 the subroutine die. Otherwise set the calling convention to
16658 the default value DW_CC_normal. */
16659 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16660 if (attr
!= nullptr
16661 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16662 TYPE_CALLING_CONVENTION (ftype
)
16663 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16664 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16665 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16667 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16669 /* Record whether the function returns normally to its caller or not
16670 if the DWARF producer set that information. */
16671 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16672 if (attr
&& (DW_UNSND (attr
) != 0))
16673 TYPE_NO_RETURN (ftype
) = 1;
16675 /* We need to add the subroutine type to the die immediately so
16676 we don't infinitely recurse when dealing with parameters
16677 declared as the same subroutine type. */
16678 set_die_type (die
, ftype
, cu
);
16680 if (die
->child
!= NULL
)
16682 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16683 struct die_info
*child_die
;
16684 int nparams
, iparams
;
16686 /* Count the number of parameters.
16687 FIXME: GDB currently ignores vararg functions, but knows about
16688 vararg member functions. */
16690 child_die
= die
->child
;
16691 while (child_die
&& child_die
->tag
)
16693 if (child_die
->tag
== DW_TAG_formal_parameter
)
16695 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16696 TYPE_VARARGS (ftype
) = 1;
16697 child_die
= sibling_die (child_die
);
16700 /* Allocate storage for parameters and fill them in. */
16701 TYPE_NFIELDS (ftype
) = nparams
;
16702 TYPE_FIELDS (ftype
) = (struct field
*)
16703 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16705 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16706 even if we error out during the parameters reading below. */
16707 for (iparams
= 0; iparams
< nparams
; iparams
++)
16708 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16711 child_die
= die
->child
;
16712 while (child_die
&& child_die
->tag
)
16714 if (child_die
->tag
== DW_TAG_formal_parameter
)
16716 struct type
*arg_type
;
16718 /* DWARF version 2 has no clean way to discern C++
16719 static and non-static member functions. G++ helps
16720 GDB by marking the first parameter for non-static
16721 member functions (which is the this pointer) as
16722 artificial. We pass this information to
16723 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16725 DWARF version 3 added DW_AT_object_pointer, which GCC
16726 4.5 does not yet generate. */
16727 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16728 if (attr
!= nullptr)
16729 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16731 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16732 arg_type
= die_type (child_die
, cu
);
16734 /* RealView does not mark THIS as const, which the testsuite
16735 expects. GCC marks THIS as const in method definitions,
16736 but not in the class specifications (GCC PR 43053). */
16737 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16738 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16741 struct dwarf2_cu
*arg_cu
= cu
;
16742 const char *name
= dwarf2_name (child_die
, cu
);
16744 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16745 if (attr
!= nullptr)
16747 /* If the compiler emits this, use it. */
16748 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16751 else if (name
&& strcmp (name
, "this") == 0)
16752 /* Function definitions will have the argument names. */
16754 else if (name
== NULL
&& iparams
== 0)
16755 /* Declarations may not have the names, so like
16756 elsewhere in GDB, assume an artificial first
16757 argument is "this". */
16761 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16765 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16768 child_die
= sibling_die (child_die
);
16775 static struct type
*
16776 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16778 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16779 const char *name
= NULL
;
16780 struct type
*this_type
, *target_type
;
16782 name
= dwarf2_full_name (NULL
, die
, cu
);
16783 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16784 TYPE_TARGET_STUB (this_type
) = 1;
16785 set_die_type (die
, this_type
, cu
);
16786 target_type
= die_type (die
, cu
);
16787 if (target_type
!= this_type
)
16788 TYPE_TARGET_TYPE (this_type
) = target_type
;
16791 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16792 spec and cause infinite loops in GDB. */
16793 complaint (_("Self-referential DW_TAG_typedef "
16794 "- DIE at %s [in module %s]"),
16795 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16796 TYPE_TARGET_TYPE (this_type
) = NULL
;
16801 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16802 (which may be different from NAME) to the architecture back-end to allow
16803 it to guess the correct format if necessary. */
16805 static struct type
*
16806 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16807 const char *name_hint
, enum bfd_endian byte_order
)
16809 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16810 const struct floatformat
**format
;
16813 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16815 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16817 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16822 /* Allocate an integer type of size BITS and name NAME. */
16824 static struct type
*
16825 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16826 int bits
, int unsigned_p
, const char *name
)
16830 /* Versions of Intel's C Compiler generate an integer type called "void"
16831 instead of using DW_TAG_unspecified_type. This has been seen on
16832 at least versions 14, 17, and 18. */
16833 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16834 && strcmp (name
, "void") == 0)
16835 type
= objfile_type (objfile
)->builtin_void
;
16837 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16842 /* Initialise and return a floating point type of size BITS suitable for
16843 use as a component of a complex number. The NAME_HINT is passed through
16844 when initialising the floating point type and is the name of the complex
16847 As DWARF doesn't currently provide an explicit name for the components
16848 of a complex number, but it can be helpful to have these components
16849 named, we try to select a suitable name based on the size of the
16851 static struct type
*
16852 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16853 struct objfile
*objfile
,
16854 int bits
, const char *name_hint
,
16855 enum bfd_endian byte_order
)
16857 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16858 struct type
*tt
= nullptr;
16860 /* Try to find a suitable floating point builtin type of size BITS.
16861 We're going to use the name of this type as the name for the complex
16862 target type that we are about to create. */
16863 switch (cu
->language
)
16865 case language_fortran
:
16869 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16872 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16874 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16876 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16884 tt
= builtin_type (gdbarch
)->builtin_float
;
16887 tt
= builtin_type (gdbarch
)->builtin_double
;
16889 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16891 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16897 /* If the type we found doesn't match the size we were looking for, then
16898 pretend we didn't find a type at all, the complex target type we
16899 create will then be nameless. */
16900 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16903 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16904 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16907 /* Find a representation of a given base type and install
16908 it in the TYPE field of the die. */
16910 static struct type
*
16911 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16913 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16915 struct attribute
*attr
;
16916 int encoding
= 0, bits
= 0;
16920 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16921 if (attr
!= nullptr)
16922 encoding
= DW_UNSND (attr
);
16923 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16924 if (attr
!= nullptr)
16925 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16926 name
= dwarf2_name (die
, cu
);
16928 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16930 arch
= get_objfile_arch (objfile
);
16931 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16933 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16936 int endianity
= DW_UNSND (attr
);
16941 byte_order
= BFD_ENDIAN_BIG
;
16943 case DW_END_little
:
16944 byte_order
= BFD_ENDIAN_LITTLE
;
16947 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16954 case DW_ATE_address
:
16955 /* Turn DW_ATE_address into a void * pointer. */
16956 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16957 type
= init_pointer_type (objfile
, bits
, name
, type
);
16959 case DW_ATE_boolean
:
16960 type
= init_boolean_type (objfile
, bits
, 1, name
);
16962 case DW_ATE_complex_float
:
16963 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16965 type
= init_complex_type (objfile
, name
, type
);
16967 case DW_ATE_decimal_float
:
16968 type
= init_decfloat_type (objfile
, bits
, name
);
16971 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16973 case DW_ATE_signed
:
16974 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16976 case DW_ATE_unsigned
:
16977 if (cu
->language
== language_fortran
16979 && startswith (name
, "character("))
16980 type
= init_character_type (objfile
, bits
, 1, name
);
16982 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16984 case DW_ATE_signed_char
:
16985 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16986 || cu
->language
== language_pascal
16987 || cu
->language
== language_fortran
)
16988 type
= init_character_type (objfile
, bits
, 0, name
);
16990 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16992 case DW_ATE_unsigned_char
:
16993 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16994 || cu
->language
== language_pascal
16995 || cu
->language
== language_fortran
16996 || cu
->language
== language_rust
)
16997 type
= init_character_type (objfile
, bits
, 1, name
);
16999 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17004 type
= builtin_type (arch
)->builtin_char16
;
17005 else if (bits
== 32)
17006 type
= builtin_type (arch
)->builtin_char32
;
17009 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17011 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17013 return set_die_type (die
, type
, cu
);
17018 complaint (_("unsupported DW_AT_encoding: '%s'"),
17019 dwarf_type_encoding_name (encoding
));
17020 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17024 if (name
&& strcmp (name
, "char") == 0)
17025 TYPE_NOSIGN (type
) = 1;
17027 maybe_set_alignment (cu
, die
, type
);
17029 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17031 return set_die_type (die
, type
, cu
);
17034 /* Parse dwarf attribute if it's a block, reference or constant and put the
17035 resulting value of the attribute into struct bound_prop.
17036 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17039 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17040 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17041 struct type
*default_type
)
17043 struct dwarf2_property_baton
*baton
;
17044 struct obstack
*obstack
17045 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17047 gdb_assert (default_type
!= NULL
);
17049 if (attr
== NULL
|| prop
== NULL
)
17052 if (attr
->form_is_block ())
17054 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17055 baton
->property_type
= default_type
;
17056 baton
->locexpr
.per_cu
= cu
->per_cu
;
17057 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17058 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17059 switch (attr
->name
)
17061 case DW_AT_string_length
:
17062 baton
->locexpr
.is_reference
= true;
17065 baton
->locexpr
.is_reference
= false;
17068 prop
->data
.baton
= baton
;
17069 prop
->kind
= PROP_LOCEXPR
;
17070 gdb_assert (prop
->data
.baton
!= NULL
);
17072 else if (attr
->form_is_ref ())
17074 struct dwarf2_cu
*target_cu
= cu
;
17075 struct die_info
*target_die
;
17076 struct attribute
*target_attr
;
17078 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17079 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17080 if (target_attr
== NULL
)
17081 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17083 if (target_attr
== NULL
)
17086 switch (target_attr
->name
)
17088 case DW_AT_location
:
17089 if (target_attr
->form_is_section_offset ())
17091 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17092 baton
->property_type
= die_type (target_die
, target_cu
);
17093 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17094 prop
->data
.baton
= baton
;
17095 prop
->kind
= PROP_LOCLIST
;
17096 gdb_assert (prop
->data
.baton
!= NULL
);
17098 else if (target_attr
->form_is_block ())
17100 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17101 baton
->property_type
= die_type (target_die
, target_cu
);
17102 baton
->locexpr
.per_cu
= cu
->per_cu
;
17103 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17104 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17105 baton
->locexpr
.is_reference
= true;
17106 prop
->data
.baton
= baton
;
17107 prop
->kind
= PROP_LOCEXPR
;
17108 gdb_assert (prop
->data
.baton
!= NULL
);
17112 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17113 "dynamic property");
17117 case DW_AT_data_member_location
:
17121 if (!handle_data_member_location (target_die
, target_cu
,
17125 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17126 baton
->property_type
= read_type_die (target_die
->parent
,
17128 baton
->offset_info
.offset
= offset
;
17129 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17130 prop
->data
.baton
= baton
;
17131 prop
->kind
= PROP_ADDR_OFFSET
;
17136 else if (attr
->form_is_constant ())
17138 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17139 prop
->kind
= PROP_CONST
;
17143 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17144 dwarf2_name (die
, cu
));
17154 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17156 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17157 struct type
*int_type
;
17159 /* Helper macro to examine the various builtin types. */
17160 #define TRY_TYPE(F) \
17161 int_type = (unsigned_p \
17162 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17163 : objfile_type (objfile)->builtin_ ## F); \
17164 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17171 TRY_TYPE (long_long
);
17175 gdb_assert_not_reached ("unable to find suitable integer type");
17181 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17183 int addr_size
= this->addr_size ();
17184 return int_type (addr_size
, unsigned_p
);
17187 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17188 present (which is valid) then compute the default type based on the
17189 compilation units address size. */
17191 static struct type
*
17192 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17194 struct type
*index_type
= die_type (die
, cu
);
17196 /* Dwarf-2 specifications explicitly allows to create subrange types
17197 without specifying a base type.
17198 In that case, the base type must be set to the type of
17199 the lower bound, upper bound or count, in that order, if any of these
17200 three attributes references an object that has a type.
17201 If no base type is found, the Dwarf-2 specifications say that
17202 a signed integer type of size equal to the size of an address should
17204 For the following C code: `extern char gdb_int [];'
17205 GCC produces an empty range DIE.
17206 FIXME: muller/2010-05-28: Possible references to object for low bound,
17207 high bound or count are not yet handled by this code. */
17208 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17209 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17214 /* Read the given DW_AT_subrange DIE. */
17216 static struct type
*
17217 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17219 struct type
*base_type
, *orig_base_type
;
17220 struct type
*range_type
;
17221 struct attribute
*attr
;
17222 struct dynamic_prop low
, high
;
17223 int low_default_is_valid
;
17224 int high_bound_is_count
= 0;
17226 ULONGEST negative_mask
;
17228 orig_base_type
= read_subrange_index_type (die
, cu
);
17230 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17231 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17232 creating the range type, but we use the result of check_typedef
17233 when examining properties of the type. */
17234 base_type
= check_typedef (orig_base_type
);
17236 /* The die_type call above may have already set the type for this DIE. */
17237 range_type
= get_die_type (die
, cu
);
17241 low
.kind
= PROP_CONST
;
17242 high
.kind
= PROP_CONST
;
17243 high
.data
.const_val
= 0;
17245 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17246 omitting DW_AT_lower_bound. */
17247 switch (cu
->language
)
17250 case language_cplus
:
17251 low
.data
.const_val
= 0;
17252 low_default_is_valid
= 1;
17254 case language_fortran
:
17255 low
.data
.const_val
= 1;
17256 low_default_is_valid
= 1;
17259 case language_objc
:
17260 case language_rust
:
17261 low
.data
.const_val
= 0;
17262 low_default_is_valid
= (cu
->header
.version
>= 4);
17266 case language_pascal
:
17267 low
.data
.const_val
= 1;
17268 low_default_is_valid
= (cu
->header
.version
>= 4);
17271 low
.data
.const_val
= 0;
17272 low_default_is_valid
= 0;
17276 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17277 if (attr
!= nullptr)
17278 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17279 else if (!low_default_is_valid
)
17280 complaint (_("Missing DW_AT_lower_bound "
17281 "- DIE at %s [in module %s]"),
17282 sect_offset_str (die
->sect_off
),
17283 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17285 struct attribute
*attr_ub
, *attr_count
;
17286 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17287 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17289 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17290 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17292 /* If bounds are constant do the final calculation here. */
17293 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17294 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17296 high_bound_is_count
= 1;
17300 if (attr_ub
!= NULL
)
17301 complaint (_("Unresolved DW_AT_upper_bound "
17302 "- DIE at %s [in module %s]"),
17303 sect_offset_str (die
->sect_off
),
17304 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17305 if (attr_count
!= NULL
)
17306 complaint (_("Unresolved DW_AT_count "
17307 "- DIE at %s [in module %s]"),
17308 sect_offset_str (die
->sect_off
),
17309 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17314 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17315 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17316 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17318 /* Normally, the DWARF producers are expected to use a signed
17319 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17320 But this is unfortunately not always the case, as witnessed
17321 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17322 is used instead. To work around that ambiguity, we treat
17323 the bounds as signed, and thus sign-extend their values, when
17324 the base type is signed. */
17326 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17327 if (low
.kind
== PROP_CONST
17328 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17329 low
.data
.const_val
|= negative_mask
;
17330 if (high
.kind
== PROP_CONST
17331 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17332 high
.data
.const_val
|= negative_mask
;
17334 /* Check for bit and byte strides. */
17335 struct dynamic_prop byte_stride_prop
;
17336 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17337 if (attr_byte_stride
!= nullptr)
17339 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17340 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17344 struct dynamic_prop bit_stride_prop
;
17345 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17346 if (attr_bit_stride
!= nullptr)
17348 /* It only makes sense to have either a bit or byte stride. */
17349 if (attr_byte_stride
!= nullptr)
17351 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17352 "- DIE at %s [in module %s]"),
17353 sect_offset_str (die
->sect_off
),
17354 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17355 attr_bit_stride
= nullptr;
17359 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17360 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17365 if (attr_byte_stride
!= nullptr
17366 || attr_bit_stride
!= nullptr)
17368 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17369 struct dynamic_prop
*stride
17370 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17373 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17374 &high
, bias
, stride
, byte_stride_p
);
17377 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17379 if (high_bound_is_count
)
17380 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17382 /* Ada expects an empty array on no boundary attributes. */
17383 if (attr
== NULL
&& cu
->language
!= language_ada
)
17384 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17386 name
= dwarf2_name (die
, cu
);
17388 TYPE_NAME (range_type
) = name
;
17390 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17391 if (attr
!= nullptr)
17392 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17394 maybe_set_alignment (cu
, die
, range_type
);
17396 set_die_type (die
, range_type
, cu
);
17398 /* set_die_type should be already done. */
17399 set_descriptive_type (range_type
, die
, cu
);
17404 static struct type
*
17405 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17409 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17411 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17413 /* In Ada, an unspecified type is typically used when the description
17414 of the type is deferred to a different unit. When encountering
17415 such a type, we treat it as a stub, and try to resolve it later on,
17417 if (cu
->language
== language_ada
)
17418 TYPE_STUB (type
) = 1;
17420 return set_die_type (die
, type
, cu
);
17423 /* Read a single die and all its descendents. Set the die's sibling
17424 field to NULL; set other fields in the die correctly, and set all
17425 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17426 location of the info_ptr after reading all of those dies. PARENT
17427 is the parent of the die in question. */
17429 static struct die_info
*
17430 read_die_and_children (const struct die_reader_specs
*reader
,
17431 const gdb_byte
*info_ptr
,
17432 const gdb_byte
**new_info_ptr
,
17433 struct die_info
*parent
)
17435 struct die_info
*die
;
17436 const gdb_byte
*cur_ptr
;
17438 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17441 *new_info_ptr
= cur_ptr
;
17444 store_in_ref_table (die
, reader
->cu
);
17446 if (die
->has_children
)
17447 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17451 *new_info_ptr
= cur_ptr
;
17454 die
->sibling
= NULL
;
17455 die
->parent
= parent
;
17459 /* Read a die, all of its descendents, and all of its siblings; set
17460 all of the fields of all of the dies correctly. Arguments are as
17461 in read_die_and_children. */
17463 static struct die_info
*
17464 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17465 const gdb_byte
*info_ptr
,
17466 const gdb_byte
**new_info_ptr
,
17467 struct die_info
*parent
)
17469 struct die_info
*first_die
, *last_sibling
;
17470 const gdb_byte
*cur_ptr
;
17472 cur_ptr
= info_ptr
;
17473 first_die
= last_sibling
= NULL
;
17477 struct die_info
*die
17478 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17482 *new_info_ptr
= cur_ptr
;
17489 last_sibling
->sibling
= die
;
17491 last_sibling
= die
;
17495 /* Read a die, all of its descendents, and all of its siblings; set
17496 all of the fields of all of the dies correctly. Arguments are as
17497 in read_die_and_children.
17498 This the main entry point for reading a DIE and all its children. */
17500 static struct die_info
*
17501 read_die_and_siblings (const struct die_reader_specs
*reader
,
17502 const gdb_byte
*info_ptr
,
17503 const gdb_byte
**new_info_ptr
,
17504 struct die_info
*parent
)
17506 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17507 new_info_ptr
, parent
);
17509 if (dwarf_die_debug
)
17511 fprintf_unfiltered (gdb_stdlog
,
17512 "Read die from %s@0x%x of %s:\n",
17513 reader
->die_section
->get_name (),
17514 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17515 bfd_get_filename (reader
->abfd
));
17516 dump_die (die
, dwarf_die_debug
);
17522 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17524 The caller is responsible for filling in the extra attributes
17525 and updating (*DIEP)->num_attrs.
17526 Set DIEP to point to a newly allocated die with its information,
17527 except for its child, sibling, and parent fields. */
17529 static const gdb_byte
*
17530 read_full_die_1 (const struct die_reader_specs
*reader
,
17531 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17532 int num_extra_attrs
)
17534 unsigned int abbrev_number
, bytes_read
, i
;
17535 struct abbrev_info
*abbrev
;
17536 struct die_info
*die
;
17537 struct dwarf2_cu
*cu
= reader
->cu
;
17538 bfd
*abfd
= reader
->abfd
;
17540 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17541 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17542 info_ptr
+= bytes_read
;
17543 if (!abbrev_number
)
17549 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17551 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17553 bfd_get_filename (abfd
));
17555 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17556 die
->sect_off
= sect_off
;
17557 die
->tag
= abbrev
->tag
;
17558 die
->abbrev
= abbrev_number
;
17559 die
->has_children
= abbrev
->has_children
;
17561 /* Make the result usable.
17562 The caller needs to update num_attrs after adding the extra
17564 die
->num_attrs
= abbrev
->num_attrs
;
17566 std::vector
<int> indexes_that_need_reprocess
;
17567 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17569 bool need_reprocess
;
17571 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17572 info_ptr
, &need_reprocess
);
17573 if (need_reprocess
)
17574 indexes_that_need_reprocess
.push_back (i
);
17577 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17578 if (attr
!= nullptr)
17579 cu
->str_offsets_base
= DW_UNSND (attr
);
17581 auto maybe_addr_base
= lookup_addr_base(die
);
17582 if (maybe_addr_base
.has_value ())
17583 cu
->addr_base
= *maybe_addr_base
;
17584 for (int index
: indexes_that_need_reprocess
)
17585 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17590 /* Read a die and all its attributes.
17591 Set DIEP to point to a newly allocated die with its information,
17592 except for its child, sibling, and parent fields. */
17594 static const gdb_byte
*
17595 read_full_die (const struct die_reader_specs
*reader
,
17596 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17598 const gdb_byte
*result
;
17600 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17602 if (dwarf_die_debug
)
17604 fprintf_unfiltered (gdb_stdlog
,
17605 "Read die from %s@0x%x of %s:\n",
17606 reader
->die_section
->get_name (),
17607 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17608 bfd_get_filename (reader
->abfd
));
17609 dump_die (*diep
, dwarf_die_debug
);
17616 /* Returns nonzero if TAG represents a type that we might generate a partial
17620 is_type_tag_for_partial (int tag
)
17625 /* Some types that would be reasonable to generate partial symbols for,
17626 that we don't at present. */
17627 case DW_TAG_array_type
:
17628 case DW_TAG_file_type
:
17629 case DW_TAG_ptr_to_member_type
:
17630 case DW_TAG_set_type
:
17631 case DW_TAG_string_type
:
17632 case DW_TAG_subroutine_type
:
17634 case DW_TAG_base_type
:
17635 case DW_TAG_class_type
:
17636 case DW_TAG_interface_type
:
17637 case DW_TAG_enumeration_type
:
17638 case DW_TAG_structure_type
:
17639 case DW_TAG_subrange_type
:
17640 case DW_TAG_typedef
:
17641 case DW_TAG_union_type
:
17648 /* Load all DIEs that are interesting for partial symbols into memory. */
17650 static struct partial_die_info
*
17651 load_partial_dies (const struct die_reader_specs
*reader
,
17652 const gdb_byte
*info_ptr
, int building_psymtab
)
17654 struct dwarf2_cu
*cu
= reader
->cu
;
17655 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17656 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17657 unsigned int bytes_read
;
17658 unsigned int load_all
= 0;
17659 int nesting_level
= 1;
17664 gdb_assert (cu
->per_cu
!= NULL
);
17665 if (cu
->per_cu
->load_all_dies
)
17669 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17673 &cu
->comp_unit_obstack
,
17674 hashtab_obstack_allocate
,
17675 dummy_obstack_deallocate
);
17679 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17681 /* A NULL abbrev means the end of a series of children. */
17682 if (abbrev
== NULL
)
17684 if (--nesting_level
== 0)
17687 info_ptr
+= bytes_read
;
17688 last_die
= parent_die
;
17689 parent_die
= parent_die
->die_parent
;
17693 /* Check for template arguments. We never save these; if
17694 they're seen, we just mark the parent, and go on our way. */
17695 if (parent_die
!= NULL
17696 && cu
->language
== language_cplus
17697 && (abbrev
->tag
== DW_TAG_template_type_param
17698 || abbrev
->tag
== DW_TAG_template_value_param
))
17700 parent_die
->has_template_arguments
= 1;
17704 /* We don't need a partial DIE for the template argument. */
17705 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17710 /* We only recurse into c++ subprograms looking for template arguments.
17711 Skip their other children. */
17713 && cu
->language
== language_cplus
17714 && parent_die
!= NULL
17715 && parent_die
->tag
== DW_TAG_subprogram
)
17717 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17721 /* Check whether this DIE is interesting enough to save. Normally
17722 we would not be interested in members here, but there may be
17723 later variables referencing them via DW_AT_specification (for
17724 static members). */
17726 && !is_type_tag_for_partial (abbrev
->tag
)
17727 && abbrev
->tag
!= DW_TAG_constant
17728 && abbrev
->tag
!= DW_TAG_enumerator
17729 && abbrev
->tag
!= DW_TAG_subprogram
17730 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17731 && abbrev
->tag
!= DW_TAG_lexical_block
17732 && abbrev
->tag
!= DW_TAG_variable
17733 && abbrev
->tag
!= DW_TAG_namespace
17734 && abbrev
->tag
!= DW_TAG_module
17735 && abbrev
->tag
!= DW_TAG_member
17736 && abbrev
->tag
!= DW_TAG_imported_unit
17737 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17739 /* Otherwise we skip to the next sibling, if any. */
17740 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17744 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17747 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17749 /* This two-pass algorithm for processing partial symbols has a
17750 high cost in cache pressure. Thus, handle some simple cases
17751 here which cover the majority of C partial symbols. DIEs
17752 which neither have specification tags in them, nor could have
17753 specification tags elsewhere pointing at them, can simply be
17754 processed and discarded.
17756 This segment is also optional; scan_partial_symbols and
17757 add_partial_symbol will handle these DIEs if we chain
17758 them in normally. When compilers which do not emit large
17759 quantities of duplicate debug information are more common,
17760 this code can probably be removed. */
17762 /* Any complete simple types at the top level (pretty much all
17763 of them, for a language without namespaces), can be processed
17765 if (parent_die
== NULL
17766 && pdi
.has_specification
== 0
17767 && pdi
.is_declaration
== 0
17768 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17769 || pdi
.tag
== DW_TAG_base_type
17770 || pdi
.tag
== DW_TAG_subrange_type
))
17772 if (building_psymtab
&& pdi
.name
!= NULL
)
17773 add_psymbol_to_list (pdi
.name
, false,
17774 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17775 psymbol_placement::STATIC
,
17776 0, cu
->language
, objfile
);
17777 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17781 /* The exception for DW_TAG_typedef with has_children above is
17782 a workaround of GCC PR debug/47510. In the case of this complaint
17783 type_name_or_error will error on such types later.
17785 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17786 it could not find the child DIEs referenced later, this is checked
17787 above. In correct DWARF DW_TAG_typedef should have no children. */
17789 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17790 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17791 "- DIE at %s [in module %s]"),
17792 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17794 /* If we're at the second level, and we're an enumerator, and
17795 our parent has no specification (meaning possibly lives in a
17796 namespace elsewhere), then we can add the partial symbol now
17797 instead of queueing it. */
17798 if (pdi
.tag
== DW_TAG_enumerator
17799 && parent_die
!= NULL
17800 && parent_die
->die_parent
== NULL
17801 && parent_die
->tag
== DW_TAG_enumeration_type
17802 && parent_die
->has_specification
== 0)
17804 if (pdi
.name
== NULL
)
17805 complaint (_("malformed enumerator DIE ignored"));
17806 else if (building_psymtab
)
17807 add_psymbol_to_list (pdi
.name
, false,
17808 VAR_DOMAIN
, LOC_CONST
, -1,
17809 cu
->language
== language_cplus
17810 ? psymbol_placement::GLOBAL
17811 : psymbol_placement::STATIC
,
17812 0, cu
->language
, objfile
);
17814 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17818 struct partial_die_info
*part_die
17819 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17821 /* We'll save this DIE so link it in. */
17822 part_die
->die_parent
= parent_die
;
17823 part_die
->die_sibling
= NULL
;
17824 part_die
->die_child
= NULL
;
17826 if (last_die
&& last_die
== parent_die
)
17827 last_die
->die_child
= part_die
;
17829 last_die
->die_sibling
= part_die
;
17831 last_die
= part_die
;
17833 if (first_die
== NULL
)
17834 first_die
= part_die
;
17836 /* Maybe add the DIE to the hash table. Not all DIEs that we
17837 find interesting need to be in the hash table, because we
17838 also have the parent/sibling/child chains; only those that we
17839 might refer to by offset later during partial symbol reading.
17841 For now this means things that might have be the target of a
17842 DW_AT_specification, DW_AT_abstract_origin, or
17843 DW_AT_extension. DW_AT_extension will refer only to
17844 namespaces; DW_AT_abstract_origin refers to functions (and
17845 many things under the function DIE, but we do not recurse
17846 into function DIEs during partial symbol reading) and
17847 possibly variables as well; DW_AT_specification refers to
17848 declarations. Declarations ought to have the DW_AT_declaration
17849 flag. It happens that GCC forgets to put it in sometimes, but
17850 only for functions, not for types.
17852 Adding more things than necessary to the hash table is harmless
17853 except for the performance cost. Adding too few will result in
17854 wasted time in find_partial_die, when we reread the compilation
17855 unit with load_all_dies set. */
17858 || abbrev
->tag
== DW_TAG_constant
17859 || abbrev
->tag
== DW_TAG_subprogram
17860 || abbrev
->tag
== DW_TAG_variable
17861 || abbrev
->tag
== DW_TAG_namespace
17862 || part_die
->is_declaration
)
17866 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17867 to_underlying (part_die
->sect_off
),
17872 /* For some DIEs we want to follow their children (if any). For C
17873 we have no reason to follow the children of structures; for other
17874 languages we have to, so that we can get at method physnames
17875 to infer fully qualified class names, for DW_AT_specification,
17876 and for C++ template arguments. For C++, we also look one level
17877 inside functions to find template arguments (if the name of the
17878 function does not already contain the template arguments).
17880 For Ada and Fortran, we need to scan the children of subprograms
17881 and lexical blocks as well because these languages allow the
17882 definition of nested entities that could be interesting for the
17883 debugger, such as nested subprograms for instance. */
17884 if (last_die
->has_children
17886 || last_die
->tag
== DW_TAG_namespace
17887 || last_die
->tag
== DW_TAG_module
17888 || last_die
->tag
== DW_TAG_enumeration_type
17889 || (cu
->language
== language_cplus
17890 && last_die
->tag
== DW_TAG_subprogram
17891 && (last_die
->name
== NULL
17892 || strchr (last_die
->name
, '<') == NULL
))
17893 || (cu
->language
!= language_c
17894 && (last_die
->tag
== DW_TAG_class_type
17895 || last_die
->tag
== DW_TAG_interface_type
17896 || last_die
->tag
== DW_TAG_structure_type
17897 || last_die
->tag
== DW_TAG_union_type
))
17898 || ((cu
->language
== language_ada
17899 || cu
->language
== language_fortran
)
17900 && (last_die
->tag
== DW_TAG_subprogram
17901 || last_die
->tag
== DW_TAG_lexical_block
))))
17904 parent_die
= last_die
;
17908 /* Otherwise we skip to the next sibling, if any. */
17909 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17911 /* Back to the top, do it again. */
17915 partial_die_info::partial_die_info (sect_offset sect_off_
,
17916 struct abbrev_info
*abbrev
)
17917 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17921 /* Read a minimal amount of information into the minimal die structure.
17922 INFO_PTR should point just after the initial uleb128 of a DIE. */
17925 partial_die_info::read (const struct die_reader_specs
*reader
,
17926 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17928 struct dwarf2_cu
*cu
= reader
->cu
;
17929 struct dwarf2_per_objfile
*dwarf2_per_objfile
17930 = cu
->per_cu
->dwarf2_per_objfile
;
17932 int has_low_pc_attr
= 0;
17933 int has_high_pc_attr
= 0;
17934 int high_pc_relative
= 0;
17936 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17937 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17939 bool need_reprocess
;
17940 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17941 info_ptr
, &need_reprocess
);
17942 /* String and address offsets that need to do the reprocessing have
17943 already been read at this point, so there is no need to wait until
17944 the loop terminates to do the reprocessing. */
17945 if (need_reprocess
)
17946 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17947 attribute
&attr
= attr_vec
[i
];
17948 /* Store the data if it is of an attribute we want to keep in a
17949 partial symbol table. */
17955 case DW_TAG_compile_unit
:
17956 case DW_TAG_partial_unit
:
17957 case DW_TAG_type_unit
:
17958 /* Compilation units have a DW_AT_name that is a filename, not
17959 a source language identifier. */
17960 case DW_TAG_enumeration_type
:
17961 case DW_TAG_enumerator
:
17962 /* These tags always have simple identifiers already; no need
17963 to canonicalize them. */
17964 name
= DW_STRING (&attr
);
17968 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17971 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
17972 &objfile
->per_bfd
->storage_obstack
);
17977 case DW_AT_linkage_name
:
17978 case DW_AT_MIPS_linkage_name
:
17979 /* Note that both forms of linkage name might appear. We
17980 assume they will be the same, and we only store the last
17982 linkage_name
= DW_STRING (&attr
);
17985 has_low_pc_attr
= 1;
17986 lowpc
= attr
.value_as_address ();
17988 case DW_AT_high_pc
:
17989 has_high_pc_attr
= 1;
17990 highpc
= attr
.value_as_address ();
17991 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17992 high_pc_relative
= 1;
17994 case DW_AT_location
:
17995 /* Support the .debug_loc offsets. */
17996 if (attr
.form_is_block ())
17998 d
.locdesc
= DW_BLOCK (&attr
);
18000 else if (attr
.form_is_section_offset ())
18002 dwarf2_complex_location_expr_complaint ();
18006 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18007 "partial symbol information");
18010 case DW_AT_external
:
18011 is_external
= DW_UNSND (&attr
);
18013 case DW_AT_declaration
:
18014 is_declaration
= DW_UNSND (&attr
);
18019 case DW_AT_abstract_origin
:
18020 case DW_AT_specification
:
18021 case DW_AT_extension
:
18022 has_specification
= 1;
18023 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18024 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18025 || cu
->per_cu
->is_dwz
);
18027 case DW_AT_sibling
:
18028 /* Ignore absolute siblings, they might point outside of
18029 the current compile unit. */
18030 if (attr
.form
== DW_FORM_ref_addr
)
18031 complaint (_("ignoring absolute DW_AT_sibling"));
18034 const gdb_byte
*buffer
= reader
->buffer
;
18035 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18036 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18038 if (sibling_ptr
< info_ptr
)
18039 complaint (_("DW_AT_sibling points backwards"));
18040 else if (sibling_ptr
> reader
->buffer_end
)
18041 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18043 sibling
= sibling_ptr
;
18046 case DW_AT_byte_size
:
18049 case DW_AT_const_value
:
18050 has_const_value
= 1;
18052 case DW_AT_calling_convention
:
18053 /* DWARF doesn't provide a way to identify a program's source-level
18054 entry point. DW_AT_calling_convention attributes are only meant
18055 to describe functions' calling conventions.
18057 However, because it's a necessary piece of information in
18058 Fortran, and before DWARF 4 DW_CC_program was the only
18059 piece of debugging information whose definition refers to
18060 a 'main program' at all, several compilers marked Fortran
18061 main programs with DW_CC_program --- even when those
18062 functions use the standard calling conventions.
18064 Although DWARF now specifies a way to provide this
18065 information, we support this practice for backward
18067 if (DW_UNSND (&attr
) == DW_CC_program
18068 && cu
->language
== language_fortran
)
18069 main_subprogram
= 1;
18072 if (DW_UNSND (&attr
) == DW_INL_inlined
18073 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18074 may_be_inlined
= 1;
18078 if (tag
== DW_TAG_imported_unit
)
18080 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18081 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18082 || cu
->per_cu
->is_dwz
);
18086 case DW_AT_main_subprogram
:
18087 main_subprogram
= DW_UNSND (&attr
);
18092 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18093 but that requires a full DIE, so instead we just
18095 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18096 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18097 + (need_ranges_base
18101 /* Value of the DW_AT_ranges attribute is the offset in the
18102 .debug_ranges section. */
18103 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18114 /* For Ada, if both the name and the linkage name appear, we prefer
18115 the latter. This lets "catch exception" work better, regardless
18116 of the order in which the name and linkage name were emitted.
18117 Really, though, this is just a workaround for the fact that gdb
18118 doesn't store both the name and the linkage name. */
18119 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18120 name
= linkage_name
;
18122 if (high_pc_relative
)
18125 if (has_low_pc_attr
&& has_high_pc_attr
)
18127 /* When using the GNU linker, .gnu.linkonce. sections are used to
18128 eliminate duplicate copies of functions and vtables and such.
18129 The linker will arbitrarily choose one and discard the others.
18130 The AT_*_pc values for such functions refer to local labels in
18131 these sections. If the section from that file was discarded, the
18132 labels are not in the output, so the relocs get a value of 0.
18133 If this is a discarded function, mark the pc bounds as invalid,
18134 so that GDB will ignore it. */
18135 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18137 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18138 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18140 complaint (_("DW_AT_low_pc %s is zero "
18141 "for DIE at %s [in module %s]"),
18142 paddress (gdbarch
, lowpc
),
18143 sect_offset_str (sect_off
),
18144 objfile_name (objfile
));
18146 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18147 else if (lowpc
>= highpc
)
18149 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18150 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18152 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18153 "for DIE at %s [in module %s]"),
18154 paddress (gdbarch
, lowpc
),
18155 paddress (gdbarch
, highpc
),
18156 sect_offset_str (sect_off
),
18157 objfile_name (objfile
));
18166 /* Find a cached partial DIE at OFFSET in CU. */
18168 struct partial_die_info
*
18169 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18171 struct partial_die_info
*lookup_die
= NULL
;
18172 struct partial_die_info
part_die (sect_off
);
18174 lookup_die
= ((struct partial_die_info
*)
18175 htab_find_with_hash (partial_dies
, &part_die
,
18176 to_underlying (sect_off
)));
18181 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18182 except in the case of .debug_types DIEs which do not reference
18183 outside their CU (they do however referencing other types via
18184 DW_FORM_ref_sig8). */
18186 static const struct cu_partial_die_info
18187 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18189 struct dwarf2_per_objfile
*dwarf2_per_objfile
18190 = cu
->per_cu
->dwarf2_per_objfile
;
18191 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18192 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18193 struct partial_die_info
*pd
= NULL
;
18195 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18196 && cu
->header
.offset_in_cu_p (sect_off
))
18198 pd
= cu
->find_partial_die (sect_off
);
18201 /* We missed recording what we needed.
18202 Load all dies and try again. */
18203 per_cu
= cu
->per_cu
;
18207 /* TUs don't reference other CUs/TUs (except via type signatures). */
18208 if (cu
->per_cu
->is_debug_types
)
18210 error (_("Dwarf Error: Type Unit at offset %s contains"
18211 " external reference to offset %s [in module %s].\n"),
18212 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18213 bfd_get_filename (objfile
->obfd
));
18215 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18216 dwarf2_per_objfile
);
18218 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18219 load_partial_comp_unit (per_cu
);
18221 per_cu
->cu
->last_used
= 0;
18222 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18225 /* If we didn't find it, and not all dies have been loaded,
18226 load them all and try again. */
18228 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18230 per_cu
->load_all_dies
= 1;
18232 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18233 THIS_CU->cu may already be in use. So we can't just free it and
18234 replace its DIEs with the ones we read in. Instead, we leave those
18235 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18236 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18238 load_partial_comp_unit (per_cu
);
18240 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18244 internal_error (__FILE__
, __LINE__
,
18245 _("could not find partial DIE %s "
18246 "in cache [from module %s]\n"),
18247 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18248 return { per_cu
->cu
, pd
};
18251 /* See if we can figure out if the class lives in a namespace. We do
18252 this by looking for a member function; its demangled name will
18253 contain namespace info, if there is any. */
18256 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18257 struct dwarf2_cu
*cu
)
18259 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18260 what template types look like, because the demangler
18261 frequently doesn't give the same name as the debug info. We
18262 could fix this by only using the demangled name to get the
18263 prefix (but see comment in read_structure_type). */
18265 struct partial_die_info
*real_pdi
;
18266 struct partial_die_info
*child_pdi
;
18268 /* If this DIE (this DIE's specification, if any) has a parent, then
18269 we should not do this. We'll prepend the parent's fully qualified
18270 name when we create the partial symbol. */
18272 real_pdi
= struct_pdi
;
18273 while (real_pdi
->has_specification
)
18275 auto res
= find_partial_die (real_pdi
->spec_offset
,
18276 real_pdi
->spec_is_dwz
, cu
);
18277 real_pdi
= res
.pdi
;
18281 if (real_pdi
->die_parent
!= NULL
)
18284 for (child_pdi
= struct_pdi
->die_child
;
18286 child_pdi
= child_pdi
->die_sibling
)
18288 if (child_pdi
->tag
== DW_TAG_subprogram
18289 && child_pdi
->linkage_name
!= NULL
)
18291 gdb::unique_xmalloc_ptr
<char> actual_class_name
18292 (language_class_name_from_physname (cu
->language_defn
,
18293 child_pdi
->linkage_name
));
18294 if (actual_class_name
!= NULL
)
18296 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18298 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
18299 actual_class_name
.get ());
18307 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18309 /* Once we've fixed up a die, there's no point in doing so again.
18310 This also avoids a memory leak if we were to call
18311 guess_partial_die_structure_name multiple times. */
18315 /* If we found a reference attribute and the DIE has no name, try
18316 to find a name in the referred to DIE. */
18318 if (name
== NULL
&& has_specification
)
18320 struct partial_die_info
*spec_die
;
18322 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18323 spec_die
= res
.pdi
;
18326 spec_die
->fixup (cu
);
18328 if (spec_die
->name
)
18330 name
= spec_die
->name
;
18332 /* Copy DW_AT_external attribute if it is set. */
18333 if (spec_die
->is_external
)
18334 is_external
= spec_die
->is_external
;
18338 /* Set default names for some unnamed DIEs. */
18340 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18341 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18343 /* If there is no parent die to provide a namespace, and there are
18344 children, see if we can determine the namespace from their linkage
18346 if (cu
->language
== language_cplus
18347 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18348 && die_parent
== NULL
18350 && (tag
== DW_TAG_class_type
18351 || tag
== DW_TAG_structure_type
18352 || tag
== DW_TAG_union_type
))
18353 guess_partial_die_structure_name (this, cu
);
18355 /* GCC might emit a nameless struct or union that has a linkage
18356 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18358 && (tag
== DW_TAG_class_type
18359 || tag
== DW_TAG_interface_type
18360 || tag
== DW_TAG_structure_type
18361 || tag
== DW_TAG_union_type
)
18362 && linkage_name
!= NULL
)
18364 gdb::unique_xmalloc_ptr
<char> demangled
18365 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18366 if (demangled
!= nullptr)
18370 /* Strip any leading namespaces/classes, keep only the base name.
18371 DW_AT_name for named DIEs does not contain the prefixes. */
18372 base
= strrchr (demangled
.get (), ':');
18373 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18376 base
= demangled
.get ();
18378 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18379 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
18386 /* Process the attributes that had to be skipped in the first round. These
18387 attributes are the ones that need str_offsets_base or addr_base attributes.
18388 They could not have been processed in the first round, because at the time
18389 the values of str_offsets_base or addr_base may not have been known. */
18390 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18391 struct attribute
*attr
)
18393 struct dwarf2_cu
*cu
= reader
->cu
;
18394 switch (attr
->form
)
18396 case DW_FORM_addrx
:
18397 case DW_FORM_GNU_addr_index
:
18398 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18401 case DW_FORM_strx1
:
18402 case DW_FORM_strx2
:
18403 case DW_FORM_strx3
:
18404 case DW_FORM_strx4
:
18405 case DW_FORM_GNU_str_index
:
18407 unsigned int str_index
= DW_UNSND (attr
);
18408 if (reader
->dwo_file
!= NULL
)
18410 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18411 DW_STRING_IS_CANONICAL (attr
) = 0;
18415 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18416 DW_STRING_IS_CANONICAL (attr
) = 0;
18421 gdb_assert_not_reached (_("Unexpected DWARF form."));
18425 /* Read an attribute value described by an attribute form. */
18427 static const gdb_byte
*
18428 read_attribute_value (const struct die_reader_specs
*reader
,
18429 struct attribute
*attr
, unsigned form
,
18430 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18431 bool *need_reprocess
)
18433 struct dwarf2_cu
*cu
= reader
->cu
;
18434 struct dwarf2_per_objfile
*dwarf2_per_objfile
18435 = cu
->per_cu
->dwarf2_per_objfile
;
18436 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18437 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18438 bfd
*abfd
= reader
->abfd
;
18439 struct comp_unit_head
*cu_header
= &cu
->header
;
18440 unsigned int bytes_read
;
18441 struct dwarf_block
*blk
;
18442 *need_reprocess
= false;
18444 attr
->form
= (enum dwarf_form
) form
;
18447 case DW_FORM_ref_addr
:
18448 if (cu
->header
.version
== 2)
18449 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18451 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18453 info_ptr
+= bytes_read
;
18455 case DW_FORM_GNU_ref_alt
:
18456 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18457 info_ptr
+= bytes_read
;
18460 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18461 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18462 info_ptr
+= bytes_read
;
18464 case DW_FORM_block2
:
18465 blk
= dwarf_alloc_block (cu
);
18466 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18468 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18469 info_ptr
+= blk
->size
;
18470 DW_BLOCK (attr
) = blk
;
18472 case DW_FORM_block4
:
18473 blk
= dwarf_alloc_block (cu
);
18474 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18476 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18477 info_ptr
+= blk
->size
;
18478 DW_BLOCK (attr
) = blk
;
18480 case DW_FORM_data2
:
18481 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18484 case DW_FORM_data4
:
18485 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18488 case DW_FORM_data8
:
18489 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18492 case DW_FORM_data16
:
18493 blk
= dwarf_alloc_block (cu
);
18495 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18497 DW_BLOCK (attr
) = blk
;
18499 case DW_FORM_sec_offset
:
18500 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18501 info_ptr
+= bytes_read
;
18503 case DW_FORM_string
:
18504 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18505 DW_STRING_IS_CANONICAL (attr
) = 0;
18506 info_ptr
+= bytes_read
;
18509 if (!cu
->per_cu
->is_dwz
)
18511 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18512 abfd
, info_ptr
, cu_header
,
18514 DW_STRING_IS_CANONICAL (attr
) = 0;
18515 info_ptr
+= bytes_read
;
18519 case DW_FORM_line_strp
:
18520 if (!cu
->per_cu
->is_dwz
)
18522 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18524 cu_header
, &bytes_read
);
18525 DW_STRING_IS_CANONICAL (attr
) = 0;
18526 info_ptr
+= bytes_read
;
18530 case DW_FORM_GNU_strp_alt
:
18532 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18533 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18536 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
18538 DW_STRING_IS_CANONICAL (attr
) = 0;
18539 info_ptr
+= bytes_read
;
18542 case DW_FORM_exprloc
:
18543 case DW_FORM_block
:
18544 blk
= dwarf_alloc_block (cu
);
18545 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18546 info_ptr
+= bytes_read
;
18547 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18548 info_ptr
+= blk
->size
;
18549 DW_BLOCK (attr
) = blk
;
18551 case DW_FORM_block1
:
18552 blk
= dwarf_alloc_block (cu
);
18553 blk
->size
= read_1_byte (abfd
, info_ptr
);
18555 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18556 info_ptr
+= blk
->size
;
18557 DW_BLOCK (attr
) = blk
;
18559 case DW_FORM_data1
:
18560 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18564 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18567 case DW_FORM_flag_present
:
18568 DW_UNSND (attr
) = 1;
18570 case DW_FORM_sdata
:
18571 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18572 info_ptr
+= bytes_read
;
18574 case DW_FORM_udata
:
18575 case DW_FORM_rnglistx
:
18576 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18577 info_ptr
+= bytes_read
;
18580 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18581 + read_1_byte (abfd
, info_ptr
));
18585 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18586 + read_2_bytes (abfd
, info_ptr
));
18590 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18591 + read_4_bytes (abfd
, info_ptr
));
18595 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18596 + read_8_bytes (abfd
, info_ptr
));
18599 case DW_FORM_ref_sig8
:
18600 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18603 case DW_FORM_ref_udata
:
18604 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18605 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18606 info_ptr
+= bytes_read
;
18608 case DW_FORM_indirect
:
18609 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18610 info_ptr
+= bytes_read
;
18611 if (form
== DW_FORM_implicit_const
)
18613 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18614 info_ptr
+= bytes_read
;
18616 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18617 info_ptr
, need_reprocess
);
18619 case DW_FORM_implicit_const
:
18620 DW_SND (attr
) = implicit_const
;
18622 case DW_FORM_addrx
:
18623 case DW_FORM_GNU_addr_index
:
18624 *need_reprocess
= true;
18625 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18626 info_ptr
+= bytes_read
;
18629 case DW_FORM_strx1
:
18630 case DW_FORM_strx2
:
18631 case DW_FORM_strx3
:
18632 case DW_FORM_strx4
:
18633 case DW_FORM_GNU_str_index
:
18635 ULONGEST str_index
;
18636 if (form
== DW_FORM_strx1
)
18638 str_index
= read_1_byte (abfd
, info_ptr
);
18641 else if (form
== DW_FORM_strx2
)
18643 str_index
= read_2_bytes (abfd
, info_ptr
);
18646 else if (form
== DW_FORM_strx3
)
18648 str_index
= read_3_bytes (abfd
, info_ptr
);
18651 else if (form
== DW_FORM_strx4
)
18653 str_index
= read_4_bytes (abfd
, info_ptr
);
18658 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18659 info_ptr
+= bytes_read
;
18661 *need_reprocess
= true;
18662 DW_UNSND (attr
) = str_index
;
18666 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18667 dwarf_form_name (form
),
18668 bfd_get_filename (abfd
));
18672 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18673 attr
->form
= DW_FORM_GNU_ref_alt
;
18675 /* We have seen instances where the compiler tried to emit a byte
18676 size attribute of -1 which ended up being encoded as an unsigned
18677 0xffffffff. Although 0xffffffff is technically a valid size value,
18678 an object of this size seems pretty unlikely so we can relatively
18679 safely treat these cases as if the size attribute was invalid and
18680 treat them as zero by default. */
18681 if (attr
->name
== DW_AT_byte_size
18682 && form
== DW_FORM_data4
18683 && DW_UNSND (attr
) >= 0xffffffff)
18686 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18687 hex_string (DW_UNSND (attr
)));
18688 DW_UNSND (attr
) = 0;
18694 /* Read an attribute described by an abbreviated attribute. */
18696 static const gdb_byte
*
18697 read_attribute (const struct die_reader_specs
*reader
,
18698 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18699 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18701 attr
->name
= abbrev
->name
;
18702 return read_attribute_value (reader
, attr
, abbrev
->form
,
18703 abbrev
->implicit_const
, info_ptr
,
18708 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
18709 unsigned int *bytes_read
)
18711 struct comp_unit_head
*cu_header
= &cu
->header
;
18712 CORE_ADDR retval
= 0;
18714 if (cu_header
->signed_addr_p
)
18716 switch (cu_header
->addr_size
)
18719 retval
= bfd_get_signed_16 (abfd
, buf
);
18722 retval
= bfd_get_signed_32 (abfd
, buf
);
18725 retval
= bfd_get_signed_64 (abfd
, buf
);
18728 internal_error (__FILE__
, __LINE__
,
18729 _("read_address: bad switch, signed [in module %s]"),
18730 bfd_get_filename (abfd
));
18735 switch (cu_header
->addr_size
)
18738 retval
= bfd_get_16 (abfd
, buf
);
18741 retval
= bfd_get_32 (abfd
, buf
);
18744 retval
= bfd_get_64 (abfd
, buf
);
18747 internal_error (__FILE__
, __LINE__
,
18748 _("read_address: bad switch, "
18749 "unsigned [in module %s]"),
18750 bfd_get_filename (abfd
));
18754 *bytes_read
= cu_header
->addr_size
;
18758 /* Cover function for read_initial_length.
18759 Returns the length of the object at BUF, and stores the size of the
18760 initial length in *BYTES_READ and stores the size that offsets will be in
18762 If the initial length size is not equivalent to that specified in
18763 CU_HEADER then issue a complaint.
18764 This is useful when reading non-comp-unit headers. */
18767 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
18768 const struct comp_unit_head
*cu_header
,
18769 unsigned int *bytes_read
,
18770 unsigned int *offset_size
)
18772 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
18774 gdb_assert (cu_header
->initial_length_size
== 4
18775 || cu_header
->initial_length_size
== 8
18776 || cu_header
->initial_length_size
== 12);
18778 if (cu_header
->initial_length_size
!= *bytes_read
)
18779 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
18781 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
18785 static const gdb_byte
*
18786 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
18788 /* If the size of a host char is 8 bits, we can return a pointer
18789 to the buffer, otherwise we have to copy the data to a buffer
18790 allocated on the temporary obstack. */
18791 gdb_assert (HOST_CHAR_BIT
== 8);
18795 static const char *
18796 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
18797 unsigned int *bytes_read_ptr
)
18799 /* If the size of a host char is 8 bits, we can return a pointer
18800 to the string, otherwise we have to copy the string to a buffer
18801 allocated on the temporary obstack. */
18802 gdb_assert (HOST_CHAR_BIT
== 8);
18805 *bytes_read_ptr
= 1;
18808 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
18809 return (const char *) buf
;
18812 /* Return pointer to string at section SECT offset STR_OFFSET with error
18813 reporting strings FORM_NAME and SECT_NAME. */
18815 static const char *
18816 read_indirect_string_at_offset_from (struct objfile
*objfile
,
18817 bfd
*abfd
, LONGEST str_offset
,
18818 struct dwarf2_section_info
*sect
,
18819 const char *form_name
,
18820 const char *sect_name
)
18822 sect
->read (objfile
);
18823 if (sect
->buffer
== NULL
)
18824 error (_("%s used without %s section [in module %s]"),
18825 form_name
, sect_name
, bfd_get_filename (abfd
));
18826 if (str_offset
>= sect
->size
)
18827 error (_("%s pointing outside of %s section [in module %s]"),
18828 form_name
, sect_name
, bfd_get_filename (abfd
));
18829 gdb_assert (HOST_CHAR_BIT
== 8);
18830 if (sect
->buffer
[str_offset
] == '\0')
18832 return (const char *) (sect
->buffer
+ str_offset
);
18835 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18837 static const char *
18838 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18839 bfd
*abfd
, LONGEST str_offset
)
18841 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18843 &dwarf2_per_objfile
->str
,
18844 "DW_FORM_strp", ".debug_str");
18847 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
18849 static const char *
18850 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18851 bfd
*abfd
, LONGEST str_offset
)
18853 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18855 &dwarf2_per_objfile
->line_str
,
18856 "DW_FORM_line_strp",
18857 ".debug_line_str");
18860 /* Read a string at offset STR_OFFSET in the .debug_str section from
18861 the .dwz file DWZ. Throw an error if the offset is too large. If
18862 the string consists of a single NUL byte, return NULL; otherwise
18863 return a pointer to the string. */
18865 static const char *
18866 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
18867 LONGEST str_offset
)
18869 dwz
->str
.read (objfile
);
18871 if (dwz
->str
.buffer
== NULL
)
18872 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
18873 "section [in module %s]"),
18874 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18875 if (str_offset
>= dwz
->str
.size
)
18876 error (_("DW_FORM_GNU_strp_alt pointing outside of "
18877 ".debug_str section [in module %s]"),
18878 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18879 gdb_assert (HOST_CHAR_BIT
== 8);
18880 if (dwz
->str
.buffer
[str_offset
] == '\0')
18882 return (const char *) (dwz
->str
.buffer
+ str_offset
);
18885 /* Return pointer to string at .debug_str offset as read from BUF.
18886 BUF is assumed to be in a compilation unit described by CU_HEADER.
18887 Return *BYTES_READ_PTR count of bytes read from BUF. */
18889 static const char *
18890 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18891 const gdb_byte
*buf
,
18892 const struct comp_unit_head
*cu_header
,
18893 unsigned int *bytes_read_ptr
)
18895 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18897 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
18900 /* Return pointer to string at .debug_line_str offset as read from BUF.
18901 BUF is assumed to be in a compilation unit described by CU_HEADER.
18902 Return *BYTES_READ_PTR count of bytes read from BUF. */
18904 static const char *
18905 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18906 bfd
*abfd
, const gdb_byte
*buf
,
18907 const struct comp_unit_head
*cu_header
,
18908 unsigned int *bytes_read_ptr
)
18910 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18912 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
18916 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18917 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18918 ADDR_SIZE is the size of addresses from the CU header. */
18921 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18922 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18925 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18926 bfd
*abfd
= objfile
->obfd
;
18927 const gdb_byte
*info_ptr
;
18928 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18930 dwarf2_per_objfile
->addr
.read (objfile
);
18931 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18932 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18933 objfile_name (objfile
));
18934 if (addr_base_or_zero
+ addr_index
* addr_size
18935 >= dwarf2_per_objfile
->addr
.size
)
18936 error (_("DW_FORM_addr_index pointing outside of "
18937 ".debug_addr section [in module %s]"),
18938 objfile_name (objfile
));
18939 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18940 + addr_base_or_zero
+ addr_index
* addr_size
);
18941 if (addr_size
== 4)
18942 return bfd_get_32 (abfd
, info_ptr
);
18944 return bfd_get_64 (abfd
, info_ptr
);
18947 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18950 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18952 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18953 cu
->addr_base
, cu
->header
.addr_size
);
18956 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18959 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18960 unsigned int *bytes_read
)
18962 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18963 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18965 return read_addr_index (cu
, addr_index
);
18968 /* Given an index in .debug_addr, fetch the value.
18969 NOTE: This can be called during dwarf expression evaluation,
18970 long after the debug information has been read, and thus per_cu->cu
18971 may no longer exist. */
18974 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
18975 unsigned int addr_index
)
18977 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18978 struct dwarf2_cu
*cu
= per_cu
->cu
;
18979 gdb::optional
<ULONGEST
> addr_base
;
18982 /* We need addr_base and addr_size.
18983 If we don't have PER_CU->cu, we have to get it.
18984 Nasty, but the alternative is storing the needed info in PER_CU,
18985 which at this point doesn't seem justified: it's not clear how frequently
18986 it would get used and it would increase the size of every PER_CU.
18987 Entry points like dwarf2_per_cu_addr_size do a similar thing
18988 so we're not in uncharted territory here.
18989 Alas we need to be a bit more complicated as addr_base is contained
18992 We don't need to read the entire CU(/TU).
18993 We just need the header and top level die.
18995 IWBN to use the aging mechanism to let us lazily later discard the CU.
18996 For now we skip this optimization. */
19000 addr_base
= cu
->addr_base
;
19001 addr_size
= cu
->header
.addr_size
;
19005 cutu_reader
reader (per_cu
, NULL
, 0, 0, false);
19006 addr_base
= reader
.cu
->addr_base
;
19007 addr_size
= reader
.cu
->header
.addr_size
;
19010 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19014 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19015 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19018 static const char *
19019 read_str_index (struct dwarf2_cu
*cu
,
19020 struct dwarf2_section_info
*str_section
,
19021 struct dwarf2_section_info
*str_offsets_section
,
19022 ULONGEST str_offsets_base
, ULONGEST str_index
)
19024 struct dwarf2_per_objfile
*dwarf2_per_objfile
19025 = cu
->per_cu
->dwarf2_per_objfile
;
19026 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19027 const char *objf_name
= objfile_name (objfile
);
19028 bfd
*abfd
= objfile
->obfd
;
19029 const gdb_byte
*info_ptr
;
19030 ULONGEST str_offset
;
19031 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19033 str_section
->read (objfile
);
19034 str_offsets_section
->read (objfile
);
19035 if (str_section
->buffer
== NULL
)
19036 error (_("%s used without %s section"
19037 " in CU at offset %s [in module %s]"),
19038 form_name
, str_section
->get_name (),
19039 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19040 if (str_offsets_section
->buffer
== NULL
)
19041 error (_("%s used without %s section"
19042 " in CU at offset %s [in module %s]"),
19043 form_name
, str_section
->get_name (),
19044 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19045 info_ptr
= (str_offsets_section
->buffer
19047 + str_index
* cu
->header
.offset_size
);
19048 if (cu
->header
.offset_size
== 4)
19049 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19051 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19052 if (str_offset
>= str_section
->size
)
19053 error (_("Offset from %s pointing outside of"
19054 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19055 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19056 return (const char *) (str_section
->buffer
+ str_offset
);
19059 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19061 static const char *
19062 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19064 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19065 ? reader
->cu
->header
.addr_size
: 0;
19066 return read_str_index (reader
->cu
,
19067 &reader
->dwo_file
->sections
.str
,
19068 &reader
->dwo_file
->sections
.str_offsets
,
19069 str_offsets_base
, str_index
);
19072 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19074 static const char *
19075 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19077 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19078 const char *objf_name
= objfile_name (objfile
);
19079 static const char form_name
[] = "DW_FORM_GNU_str_index";
19080 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19082 if (!cu
->str_offsets_base
.has_value ())
19083 error (_("%s used in Fission stub without %s"
19084 " in CU at offset 0x%lx [in module %s]"),
19085 form_name
, str_offsets_attr_name
,
19086 (long) cu
->header
.offset_size
, objf_name
);
19088 return read_str_index (cu
,
19089 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19090 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19091 *cu
->str_offsets_base
, str_index
);
19094 /* Return the length of an LEB128 number in BUF. */
19097 leb128_size (const gdb_byte
*buf
)
19099 const gdb_byte
*begin
= buf
;
19105 if ((byte
& 128) == 0)
19106 return buf
- begin
;
19111 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19120 cu
->language
= language_c
;
19123 case DW_LANG_C_plus_plus
:
19124 case DW_LANG_C_plus_plus_11
:
19125 case DW_LANG_C_plus_plus_14
:
19126 cu
->language
= language_cplus
;
19129 cu
->language
= language_d
;
19131 case DW_LANG_Fortran77
:
19132 case DW_LANG_Fortran90
:
19133 case DW_LANG_Fortran95
:
19134 case DW_LANG_Fortran03
:
19135 case DW_LANG_Fortran08
:
19136 cu
->language
= language_fortran
;
19139 cu
->language
= language_go
;
19141 case DW_LANG_Mips_Assembler
:
19142 cu
->language
= language_asm
;
19144 case DW_LANG_Ada83
:
19145 case DW_LANG_Ada95
:
19146 cu
->language
= language_ada
;
19148 case DW_LANG_Modula2
:
19149 cu
->language
= language_m2
;
19151 case DW_LANG_Pascal83
:
19152 cu
->language
= language_pascal
;
19155 cu
->language
= language_objc
;
19158 case DW_LANG_Rust_old
:
19159 cu
->language
= language_rust
;
19161 case DW_LANG_Cobol74
:
19162 case DW_LANG_Cobol85
:
19164 cu
->language
= language_minimal
;
19167 cu
->language_defn
= language_def (cu
->language
);
19170 /* Return the named attribute or NULL if not there. */
19172 static struct attribute
*
19173 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19178 struct attribute
*spec
= NULL
;
19180 for (i
= 0; i
< die
->num_attrs
; ++i
)
19182 if (die
->attrs
[i
].name
== name
)
19183 return &die
->attrs
[i
];
19184 if (die
->attrs
[i
].name
== DW_AT_specification
19185 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19186 spec
= &die
->attrs
[i
];
19192 die
= follow_die_ref (die
, spec
, &cu
);
19198 /* Return the named attribute or NULL if not there,
19199 but do not follow DW_AT_specification, etc.
19200 This is for use in contexts where we're reading .debug_types dies.
19201 Following DW_AT_specification, DW_AT_abstract_origin will take us
19202 back up the chain, and we want to go down. */
19204 static struct attribute
*
19205 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19209 for (i
= 0; i
< die
->num_attrs
; ++i
)
19210 if (die
->attrs
[i
].name
== name
)
19211 return &die
->attrs
[i
];
19216 /* Return the string associated with a string-typed attribute, or NULL if it
19217 is either not found or is of an incorrect type. */
19219 static const char *
19220 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19222 struct attribute
*attr
;
19223 const char *str
= NULL
;
19225 attr
= dwarf2_attr (die
, name
, cu
);
19229 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19230 || attr
->form
== DW_FORM_string
19231 || attr
->form
== DW_FORM_strx
19232 || attr
->form
== DW_FORM_strx1
19233 || attr
->form
== DW_FORM_strx2
19234 || attr
->form
== DW_FORM_strx3
19235 || attr
->form
== DW_FORM_strx4
19236 || attr
->form
== DW_FORM_GNU_str_index
19237 || attr
->form
== DW_FORM_GNU_strp_alt
)
19238 str
= DW_STRING (attr
);
19240 complaint (_("string type expected for attribute %s for "
19241 "DIE at %s in module %s"),
19242 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19243 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19249 /* Return the dwo name or NULL if not present. If present, it is in either
19250 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19251 static const char *
19252 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19254 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19255 if (dwo_name
== nullptr)
19256 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19260 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19261 and holds a non-zero value. This function should only be used for
19262 DW_FORM_flag or DW_FORM_flag_present attributes. */
19265 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19267 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19269 return (attr
&& DW_UNSND (attr
));
19273 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19275 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19276 which value is non-zero. However, we have to be careful with
19277 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19278 (via dwarf2_flag_true_p) follows this attribute. So we may
19279 end up accidently finding a declaration attribute that belongs
19280 to a different DIE referenced by the specification attribute,
19281 even though the given DIE does not have a declaration attribute. */
19282 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19283 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19286 /* Return the die giving the specification for DIE, if there is
19287 one. *SPEC_CU is the CU containing DIE on input, and the CU
19288 containing the return value on output. If there is no
19289 specification, but there is an abstract origin, that is
19292 static struct die_info
*
19293 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19295 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19298 if (spec_attr
== NULL
)
19299 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19301 if (spec_attr
== NULL
)
19304 return follow_die_ref (die
, spec_attr
, spec_cu
);
19307 /* Stub for free_line_header to match void * callback types. */
19310 free_line_header_voidp (void *arg
)
19312 struct line_header
*lh
= (struct line_header
*) arg
;
19317 /* A convenience function to find the proper .debug_line section for a CU. */
19319 static struct dwarf2_section_info
*
19320 get_debug_line_section (struct dwarf2_cu
*cu
)
19322 struct dwarf2_section_info
*section
;
19323 struct dwarf2_per_objfile
*dwarf2_per_objfile
19324 = cu
->per_cu
->dwarf2_per_objfile
;
19326 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19328 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19329 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19330 else if (cu
->per_cu
->is_dwz
)
19332 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19334 section
= &dwz
->line
;
19337 section
= &dwarf2_per_objfile
->line
;
19342 /* Read directory or file name entry format, starting with byte of
19343 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19344 entries count and the entries themselves in the described entry
19348 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19349 bfd
*abfd
, const gdb_byte
**bufp
,
19350 struct line_header
*lh
,
19351 const struct comp_unit_head
*cu_header
,
19352 void (*callback
) (struct line_header
*lh
,
19355 unsigned int mod_time
,
19356 unsigned int length
))
19358 gdb_byte format_count
, formati
;
19359 ULONGEST data_count
, datai
;
19360 const gdb_byte
*buf
= *bufp
;
19361 const gdb_byte
*format_header_data
;
19362 unsigned int bytes_read
;
19364 format_count
= read_1_byte (abfd
, buf
);
19366 format_header_data
= buf
;
19367 for (formati
= 0; formati
< format_count
; formati
++)
19369 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19371 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19375 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19377 for (datai
= 0; datai
< data_count
; datai
++)
19379 const gdb_byte
*format
= format_header_data
;
19380 struct file_entry fe
;
19382 for (formati
= 0; formati
< format_count
; formati
++)
19384 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19385 format
+= bytes_read
;
19387 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19388 format
+= bytes_read
;
19390 gdb::optional
<const char *> string
;
19391 gdb::optional
<unsigned int> uint
;
19395 case DW_FORM_string
:
19396 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19400 case DW_FORM_line_strp
:
19401 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19408 case DW_FORM_data1
:
19409 uint
.emplace (read_1_byte (abfd
, buf
));
19413 case DW_FORM_data2
:
19414 uint
.emplace (read_2_bytes (abfd
, buf
));
19418 case DW_FORM_data4
:
19419 uint
.emplace (read_4_bytes (abfd
, buf
));
19423 case DW_FORM_data8
:
19424 uint
.emplace (read_8_bytes (abfd
, buf
));
19428 case DW_FORM_data16
:
19429 /* This is used for MD5, but file_entry does not record MD5s. */
19433 case DW_FORM_udata
:
19434 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19438 case DW_FORM_block
:
19439 /* It is valid only for DW_LNCT_timestamp which is ignored by
19444 switch (content_type
)
19447 if (string
.has_value ())
19450 case DW_LNCT_directory_index
:
19451 if (uint
.has_value ())
19452 fe
.d_index
= (dir_index
) *uint
;
19454 case DW_LNCT_timestamp
:
19455 if (uint
.has_value ())
19456 fe
.mod_time
= *uint
;
19459 if (uint
.has_value ())
19465 complaint (_("Unknown format content type %s"),
19466 pulongest (content_type
));
19470 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
19476 /* Read the statement program header starting at OFFSET in
19477 .debug_line, or .debug_line.dwo. Return a pointer
19478 to a struct line_header, allocated using xmalloc.
19479 Returns NULL if there is a problem reading the header, e.g., if it
19480 has a version we don't understand.
19482 NOTE: the strings in the include directory and file name tables of
19483 the returned object point into the dwarf line section buffer,
19484 and must not be freed. */
19486 static line_header_up
19487 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19489 const gdb_byte
*line_ptr
;
19490 unsigned int bytes_read
, offset_size
;
19492 const char *cur_dir
, *cur_file
;
19493 struct dwarf2_section_info
*section
;
19495 struct dwarf2_per_objfile
*dwarf2_per_objfile
19496 = cu
->per_cu
->dwarf2_per_objfile
;
19498 section
= get_debug_line_section (cu
);
19499 section
->read (dwarf2_per_objfile
->objfile
);
19500 if (section
->buffer
== NULL
)
19502 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19503 complaint (_("missing .debug_line.dwo section"));
19505 complaint (_("missing .debug_line section"));
19509 /* We can't do this until we know the section is non-empty.
19510 Only then do we know we have such a section. */
19511 abfd
= section
->get_bfd_owner ();
19513 /* Make sure that at least there's room for the total_length field.
19514 That could be 12 bytes long, but we're just going to fudge that. */
19515 if (to_underlying (sect_off
) + 4 >= section
->size
)
19517 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19521 line_header_up
lh (new line_header ());
19523 lh
->sect_off
= sect_off
;
19524 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
19526 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
19528 /* Read in the header. */
19530 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
19531 &bytes_read
, &offset_size
);
19532 line_ptr
+= bytes_read
;
19534 const gdb_byte
*start_here
= line_ptr
;
19536 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
19538 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19541 lh
->statement_program_end
= start_here
+ lh
->total_length
;
19542 lh
->version
= read_2_bytes (abfd
, line_ptr
);
19544 if (lh
->version
> 5)
19546 /* This is a version we don't understand. The format could have
19547 changed in ways we don't handle properly so just punt. */
19548 complaint (_("unsupported version in .debug_line section"));
19551 if (lh
->version
>= 5)
19553 gdb_byte segment_selector_size
;
19555 /* Skip address size. */
19556 read_1_byte (abfd
, line_ptr
);
19559 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
19561 if (segment_selector_size
!= 0)
19563 complaint (_("unsupported segment selector size %u "
19564 "in .debug_line section"),
19565 segment_selector_size
);
19569 lh
->header_length
= read_offset (abfd
, line_ptr
, offset_size
);
19570 line_ptr
+= offset_size
;
19571 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
19572 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
19574 if (lh
->version
>= 4)
19576 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
19580 lh
->maximum_ops_per_instruction
= 1;
19582 if (lh
->maximum_ops_per_instruction
== 0)
19584 lh
->maximum_ops_per_instruction
= 1;
19585 complaint (_("invalid maximum_ops_per_instruction "
19586 "in `.debug_line' section"));
19589 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
19591 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
19593 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
19595 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
19597 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
19599 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
19600 for (i
= 1; i
< lh
->opcode_base
; ++i
)
19602 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
19606 if (lh
->version
>= 5)
19608 /* Read directory table. */
19609 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19611 [] (struct line_header
*header
, const char *name
,
19612 dir_index d_index
, unsigned int mod_time
,
19613 unsigned int length
)
19615 header
->add_include_dir (name
);
19618 /* Read file name table. */
19619 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19621 [] (struct line_header
*header
, const char *name
,
19622 dir_index d_index
, unsigned int mod_time
,
19623 unsigned int length
)
19625 header
->add_file_name (name
, d_index
, mod_time
, length
);
19630 /* Read directory table. */
19631 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19633 line_ptr
+= bytes_read
;
19634 lh
->add_include_dir (cur_dir
);
19636 line_ptr
+= bytes_read
;
19638 /* Read file name table. */
19639 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19641 unsigned int mod_time
, length
;
19644 line_ptr
+= bytes_read
;
19645 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19646 line_ptr
+= bytes_read
;
19647 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19648 line_ptr
+= bytes_read
;
19649 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19650 line_ptr
+= bytes_read
;
19652 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
19654 line_ptr
+= bytes_read
;
19657 if (line_ptr
> (section
->buffer
+ section
->size
))
19658 complaint (_("line number info header doesn't "
19659 "fit in `.debug_line' section"));
19664 /* Subroutine of dwarf_decode_lines to simplify it.
19665 Return the file name of the psymtab for the given file_entry.
19666 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19667 If space for the result is malloc'd, *NAME_HOLDER will be set.
19668 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19670 static const char *
19671 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19672 const dwarf2_psymtab
*pst
,
19673 const char *comp_dir
,
19674 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19676 const char *include_name
= fe
.name
;
19677 const char *include_name_to_compare
= include_name
;
19678 const char *pst_filename
;
19681 const char *dir_name
= fe
.include_dir (lh
);
19683 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19684 if (!IS_ABSOLUTE_PATH (include_name
)
19685 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19687 /* Avoid creating a duplicate psymtab for PST.
19688 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19689 Before we do the comparison, however, we need to account
19690 for DIR_NAME and COMP_DIR.
19691 First prepend dir_name (if non-NULL). If we still don't
19692 have an absolute path prepend comp_dir (if non-NULL).
19693 However, the directory we record in the include-file's
19694 psymtab does not contain COMP_DIR (to match the
19695 corresponding symtab(s)).
19700 bash$ gcc -g ./hello.c
19701 include_name = "hello.c"
19703 DW_AT_comp_dir = comp_dir = "/tmp"
19704 DW_AT_name = "./hello.c"
19708 if (dir_name
!= NULL
)
19710 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19711 include_name
, (char *) NULL
));
19712 include_name
= name_holder
->get ();
19713 include_name_to_compare
= include_name
;
19715 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19717 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19718 include_name
, (char *) NULL
));
19719 include_name_to_compare
= hold_compare
.get ();
19723 pst_filename
= pst
->filename
;
19724 gdb::unique_xmalloc_ptr
<char> copied_name
;
19725 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19727 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19728 pst_filename
, (char *) NULL
));
19729 pst_filename
= copied_name
.get ();
19732 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19736 return include_name
;
19739 /* State machine to track the state of the line number program. */
19741 class lnp_state_machine
19744 /* Initialize a machine state for the start of a line number
19746 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19747 bool record_lines_p
);
19749 file_entry
*current_file ()
19751 /* lh->file_names is 0-based, but the file name numbers in the
19752 statement program are 1-based. */
19753 return m_line_header
->file_name_at (m_file
);
19756 /* Record the line in the state machine. END_SEQUENCE is true if
19757 we're processing the end of a sequence. */
19758 void record_line (bool end_sequence
);
19760 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19761 nop-out rest of the lines in this sequence. */
19762 void check_line_address (struct dwarf2_cu
*cu
,
19763 const gdb_byte
*line_ptr
,
19764 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19766 void handle_set_discriminator (unsigned int discriminator
)
19768 m_discriminator
= discriminator
;
19769 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19772 /* Handle DW_LNE_set_address. */
19773 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19776 address
+= baseaddr
;
19777 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19780 /* Handle DW_LNS_advance_pc. */
19781 void handle_advance_pc (CORE_ADDR adjust
);
19783 /* Handle a special opcode. */
19784 void handle_special_opcode (unsigned char op_code
);
19786 /* Handle DW_LNS_advance_line. */
19787 void handle_advance_line (int line_delta
)
19789 advance_line (line_delta
);
19792 /* Handle DW_LNS_set_file. */
19793 void handle_set_file (file_name_index file
);
19795 /* Handle DW_LNS_negate_stmt. */
19796 void handle_negate_stmt ()
19798 m_is_stmt
= !m_is_stmt
;
19801 /* Handle DW_LNS_const_add_pc. */
19802 void handle_const_add_pc ();
19804 /* Handle DW_LNS_fixed_advance_pc. */
19805 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19807 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19811 /* Handle DW_LNS_copy. */
19812 void handle_copy ()
19814 record_line (false);
19815 m_discriminator
= 0;
19818 /* Handle DW_LNE_end_sequence. */
19819 void handle_end_sequence ()
19821 m_currently_recording_lines
= true;
19825 /* Advance the line by LINE_DELTA. */
19826 void advance_line (int line_delta
)
19828 m_line
+= line_delta
;
19830 if (line_delta
!= 0)
19831 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19834 struct dwarf2_cu
*m_cu
;
19836 gdbarch
*m_gdbarch
;
19838 /* True if we're recording lines.
19839 Otherwise we're building partial symtabs and are just interested in
19840 finding include files mentioned by the line number program. */
19841 bool m_record_lines_p
;
19843 /* The line number header. */
19844 line_header
*m_line_header
;
19846 /* These are part of the standard DWARF line number state machine,
19847 and initialized according to the DWARF spec. */
19849 unsigned char m_op_index
= 0;
19850 /* The line table index of the current file. */
19851 file_name_index m_file
= 1;
19852 unsigned int m_line
= 1;
19854 /* These are initialized in the constructor. */
19856 CORE_ADDR m_address
;
19858 unsigned int m_discriminator
;
19860 /* Additional bits of state we need to track. */
19862 /* The last file that we called dwarf2_start_subfile for.
19863 This is only used for TLLs. */
19864 unsigned int m_last_file
= 0;
19865 /* The last file a line number was recorded for. */
19866 struct subfile
*m_last_subfile
= NULL
;
19868 /* When true, record the lines we decode. */
19869 bool m_currently_recording_lines
= false;
19871 /* The last line number that was recorded, used to coalesce
19872 consecutive entries for the same line. This can happen, for
19873 example, when discriminators are present. PR 17276. */
19874 unsigned int m_last_line
= 0;
19875 bool m_line_has_non_zero_discriminator
= false;
19879 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19881 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19882 / m_line_header
->maximum_ops_per_instruction
)
19883 * m_line_header
->minimum_instruction_length
);
19884 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19885 m_op_index
= ((m_op_index
+ adjust
)
19886 % m_line_header
->maximum_ops_per_instruction
);
19890 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19892 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19893 CORE_ADDR addr_adj
= (((m_op_index
19894 + (adj_opcode
/ m_line_header
->line_range
))
19895 / m_line_header
->maximum_ops_per_instruction
)
19896 * m_line_header
->minimum_instruction_length
);
19897 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19898 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
19899 % m_line_header
->maximum_ops_per_instruction
);
19901 int line_delta
= (m_line_header
->line_base
19902 + (adj_opcode
% m_line_header
->line_range
));
19903 advance_line (line_delta
);
19904 record_line (false);
19905 m_discriminator
= 0;
19909 lnp_state_machine::handle_set_file (file_name_index file
)
19913 const file_entry
*fe
= current_file ();
19915 dwarf2_debug_line_missing_file_complaint ();
19916 else if (m_record_lines_p
)
19918 const char *dir
= fe
->include_dir (m_line_header
);
19920 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19921 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19922 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19927 lnp_state_machine::handle_const_add_pc ()
19930 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19933 = (((m_op_index
+ adjust
)
19934 / m_line_header
->maximum_ops_per_instruction
)
19935 * m_line_header
->minimum_instruction_length
);
19937 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19938 m_op_index
= ((m_op_index
+ adjust
)
19939 % m_line_header
->maximum_ops_per_instruction
);
19942 /* Return non-zero if we should add LINE to the line number table.
19943 LINE is the line to add, LAST_LINE is the last line that was added,
19944 LAST_SUBFILE is the subfile for LAST_LINE.
19945 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19946 had a non-zero discriminator.
19948 We have to be careful in the presence of discriminators.
19949 E.g., for this line:
19951 for (i = 0; i < 100000; i++);
19953 clang can emit four line number entries for that one line,
19954 each with a different discriminator.
19955 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19957 However, we want gdb to coalesce all four entries into one.
19958 Otherwise the user could stepi into the middle of the line and
19959 gdb would get confused about whether the pc really was in the
19960 middle of the line.
19962 Things are further complicated by the fact that two consecutive
19963 line number entries for the same line is a heuristic used by gcc
19964 to denote the end of the prologue. So we can't just discard duplicate
19965 entries, we have to be selective about it. The heuristic we use is
19966 that we only collapse consecutive entries for the same line if at least
19967 one of those entries has a non-zero discriminator. PR 17276.
19969 Note: Addresses in the line number state machine can never go backwards
19970 within one sequence, thus this coalescing is ok. */
19973 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19974 unsigned int line
, unsigned int last_line
,
19975 int line_has_non_zero_discriminator
,
19976 struct subfile
*last_subfile
)
19978 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19980 if (line
!= last_line
)
19982 /* Same line for the same file that we've seen already.
19983 As a last check, for pr 17276, only record the line if the line
19984 has never had a non-zero discriminator. */
19985 if (!line_has_non_zero_discriminator
)
19990 /* Use the CU's builder to record line number LINE beginning at
19991 address ADDRESS in the line table of subfile SUBFILE. */
19994 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19995 unsigned int line
, CORE_ADDR address
,
19996 struct dwarf2_cu
*cu
)
19998 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20000 if (dwarf_line_debug
)
20002 fprintf_unfiltered (gdb_stdlog
,
20003 "Recording line %u, file %s, address %s\n",
20004 line
, lbasename (subfile
->name
),
20005 paddress (gdbarch
, address
));
20009 cu
->get_builder ()->record_line (subfile
, line
, addr
);
20012 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20013 Mark the end of a set of line number records.
20014 The arguments are the same as for dwarf_record_line_1.
20015 If SUBFILE is NULL the request is ignored. */
20018 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20019 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20021 if (subfile
== NULL
)
20024 if (dwarf_line_debug
)
20026 fprintf_unfiltered (gdb_stdlog
,
20027 "Finishing current line, file %s, address %s\n",
20028 lbasename (subfile
->name
),
20029 paddress (gdbarch
, address
));
20032 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
20036 lnp_state_machine::record_line (bool end_sequence
)
20038 if (dwarf_line_debug
)
20040 fprintf_unfiltered (gdb_stdlog
,
20041 "Processing actual line %u: file %u,"
20042 " address %s, is_stmt %u, discrim %u%s\n",
20044 paddress (m_gdbarch
, m_address
),
20045 m_is_stmt
, m_discriminator
,
20046 (end_sequence
? "\t(end sequence)" : ""));
20049 file_entry
*fe
= current_file ();
20052 dwarf2_debug_line_missing_file_complaint ();
20053 /* For now we ignore lines not starting on an instruction boundary.
20054 But not when processing end_sequence for compatibility with the
20055 previous version of the code. */
20056 else if (m_op_index
== 0 || end_sequence
)
20058 fe
->included_p
= 1;
20059 if (m_record_lines_p
20060 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
20062 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20065 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20066 m_currently_recording_lines
? m_cu
: nullptr);
20071 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20072 m_line_has_non_zero_discriminator
,
20075 buildsym_compunit
*builder
= m_cu
->get_builder ();
20076 dwarf_record_line_1 (m_gdbarch
,
20077 builder
->get_current_subfile (),
20079 m_currently_recording_lines
? m_cu
: nullptr);
20081 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20082 m_last_line
= m_line
;
20088 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20089 line_header
*lh
, bool record_lines_p
)
20093 m_record_lines_p
= record_lines_p
;
20094 m_line_header
= lh
;
20096 m_currently_recording_lines
= true;
20098 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20099 was a line entry for it so that the backend has a chance to adjust it
20100 and also record it in case it needs it. This is currently used by MIPS
20101 code, cf. `mips_adjust_dwarf2_line'. */
20102 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20103 m_is_stmt
= lh
->default_is_stmt
;
20104 m_discriminator
= 0;
20108 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20109 const gdb_byte
*line_ptr
,
20110 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20112 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20113 the pc range of the CU. However, we restrict the test to only ADDRESS
20114 values of zero to preserve GDB's previous behaviour which is to handle
20115 the specific case of a function being GC'd by the linker. */
20117 if (address
== 0 && address
< unrelocated_lowpc
)
20119 /* This line table is for a function which has been
20120 GCd by the linker. Ignore it. PR gdb/12528 */
20122 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20123 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20125 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20126 line_offset
, objfile_name (objfile
));
20127 m_currently_recording_lines
= false;
20128 /* Note: m_currently_recording_lines is left as false until we see
20129 DW_LNE_end_sequence. */
20133 /* Subroutine of dwarf_decode_lines to simplify it.
20134 Process the line number information in LH.
20135 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20136 program in order to set included_p for every referenced header. */
20139 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20140 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20142 const gdb_byte
*line_ptr
, *extended_end
;
20143 const gdb_byte
*line_end
;
20144 unsigned int bytes_read
, extended_len
;
20145 unsigned char op_code
, extended_op
;
20146 CORE_ADDR baseaddr
;
20147 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20148 bfd
*abfd
= objfile
->obfd
;
20149 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20150 /* True if we're recording line info (as opposed to building partial
20151 symtabs and just interested in finding include files mentioned by
20152 the line number program). */
20153 bool record_lines_p
= !decode_for_pst_p
;
20155 baseaddr
= objfile
->text_section_offset ();
20157 line_ptr
= lh
->statement_program_start
;
20158 line_end
= lh
->statement_program_end
;
20160 /* Read the statement sequences until there's nothing left. */
20161 while (line_ptr
< line_end
)
20163 /* The DWARF line number program state machine. Reset the state
20164 machine at the start of each sequence. */
20165 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20166 bool end_sequence
= false;
20168 if (record_lines_p
)
20170 /* Start a subfile for the current file of the state
20172 const file_entry
*fe
= state_machine
.current_file ();
20175 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20178 /* Decode the table. */
20179 while (line_ptr
< line_end
&& !end_sequence
)
20181 op_code
= read_1_byte (abfd
, line_ptr
);
20184 if (op_code
>= lh
->opcode_base
)
20186 /* Special opcode. */
20187 state_machine
.handle_special_opcode (op_code
);
20189 else switch (op_code
)
20191 case DW_LNS_extended_op
:
20192 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20194 line_ptr
+= bytes_read
;
20195 extended_end
= line_ptr
+ extended_len
;
20196 extended_op
= read_1_byte (abfd
, line_ptr
);
20198 switch (extended_op
)
20200 case DW_LNE_end_sequence
:
20201 state_machine
.handle_end_sequence ();
20202 end_sequence
= true;
20204 case DW_LNE_set_address
:
20207 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20208 line_ptr
+= bytes_read
;
20210 state_machine
.check_line_address (cu
, line_ptr
,
20211 lowpc
- baseaddr
, address
);
20212 state_machine
.handle_set_address (baseaddr
, address
);
20215 case DW_LNE_define_file
:
20217 const char *cur_file
;
20218 unsigned int mod_time
, length
;
20221 cur_file
= read_direct_string (abfd
, line_ptr
,
20223 line_ptr
+= bytes_read
;
20224 dindex
= (dir_index
)
20225 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20226 line_ptr
+= bytes_read
;
20228 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20229 line_ptr
+= bytes_read
;
20231 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20232 line_ptr
+= bytes_read
;
20233 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20236 case DW_LNE_set_discriminator
:
20238 /* The discriminator is not interesting to the
20239 debugger; just ignore it. We still need to
20240 check its value though:
20241 if there are consecutive entries for the same
20242 (non-prologue) line we want to coalesce them.
20245 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20246 line_ptr
+= bytes_read
;
20248 state_machine
.handle_set_discriminator (discr
);
20252 complaint (_("mangled .debug_line section"));
20255 /* Make sure that we parsed the extended op correctly. If e.g.
20256 we expected a different address size than the producer used,
20257 we may have read the wrong number of bytes. */
20258 if (line_ptr
!= extended_end
)
20260 complaint (_("mangled .debug_line section"));
20265 state_machine
.handle_copy ();
20267 case DW_LNS_advance_pc
:
20270 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20271 line_ptr
+= bytes_read
;
20273 state_machine
.handle_advance_pc (adjust
);
20276 case DW_LNS_advance_line
:
20279 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20280 line_ptr
+= bytes_read
;
20282 state_machine
.handle_advance_line (line_delta
);
20285 case DW_LNS_set_file
:
20287 file_name_index file
20288 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20290 line_ptr
+= bytes_read
;
20292 state_machine
.handle_set_file (file
);
20295 case DW_LNS_set_column
:
20296 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20297 line_ptr
+= bytes_read
;
20299 case DW_LNS_negate_stmt
:
20300 state_machine
.handle_negate_stmt ();
20302 case DW_LNS_set_basic_block
:
20304 /* Add to the address register of the state machine the
20305 address increment value corresponding to special opcode
20306 255. I.e., this value is scaled by the minimum
20307 instruction length since special opcode 255 would have
20308 scaled the increment. */
20309 case DW_LNS_const_add_pc
:
20310 state_machine
.handle_const_add_pc ();
20312 case DW_LNS_fixed_advance_pc
:
20314 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20317 state_machine
.handle_fixed_advance_pc (addr_adj
);
20322 /* Unknown standard opcode, ignore it. */
20325 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20327 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20328 line_ptr
+= bytes_read
;
20335 dwarf2_debug_line_missing_end_sequence_complaint ();
20337 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20338 in which case we still finish recording the last line). */
20339 state_machine
.record_line (true);
20343 /* Decode the Line Number Program (LNP) for the given line_header
20344 structure and CU. The actual information extracted and the type
20345 of structures created from the LNP depends on the value of PST.
20347 1. If PST is NULL, then this procedure uses the data from the program
20348 to create all necessary symbol tables, and their linetables.
20350 2. If PST is not NULL, this procedure reads the program to determine
20351 the list of files included by the unit represented by PST, and
20352 builds all the associated partial symbol tables.
20354 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20355 It is used for relative paths in the line table.
20356 NOTE: When processing partial symtabs (pst != NULL),
20357 comp_dir == pst->dirname.
20359 NOTE: It is important that psymtabs have the same file name (via strcmp)
20360 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20361 symtab we don't use it in the name of the psymtabs we create.
20362 E.g. expand_line_sal requires this when finding psymtabs to expand.
20363 A good testcase for this is mb-inline.exp.
20365 LOWPC is the lowest address in CU (or 0 if not known).
20367 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20368 for its PC<->lines mapping information. Otherwise only the filename
20369 table is read in. */
20372 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20373 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20374 CORE_ADDR lowpc
, int decode_mapping
)
20376 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20377 const int decode_for_pst_p
= (pst
!= NULL
);
20379 if (decode_mapping
)
20380 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20382 if (decode_for_pst_p
)
20384 /* Now that we're done scanning the Line Header Program, we can
20385 create the psymtab of each included file. */
20386 for (auto &file_entry
: lh
->file_names ())
20387 if (file_entry
.included_p
== 1)
20389 gdb::unique_xmalloc_ptr
<char> name_holder
;
20390 const char *include_name
=
20391 psymtab_include_file_name (lh
, file_entry
, pst
,
20392 comp_dir
, &name_holder
);
20393 if (include_name
!= NULL
)
20394 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20399 /* Make sure a symtab is created for every file, even files
20400 which contain only variables (i.e. no code with associated
20402 buildsym_compunit
*builder
= cu
->get_builder ();
20403 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20405 for (auto &fe
: lh
->file_names ())
20407 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20408 if (builder
->get_current_subfile ()->symtab
== NULL
)
20410 builder
->get_current_subfile ()->symtab
20411 = allocate_symtab (cust
,
20412 builder
->get_current_subfile ()->name
);
20414 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20419 /* Start a subfile for DWARF. FILENAME is the name of the file and
20420 DIRNAME the name of the source directory which contains FILENAME
20421 or NULL if not known.
20422 This routine tries to keep line numbers from identical absolute and
20423 relative file names in a common subfile.
20425 Using the `list' example from the GDB testsuite, which resides in
20426 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20427 of /srcdir/list0.c yields the following debugging information for list0.c:
20429 DW_AT_name: /srcdir/list0.c
20430 DW_AT_comp_dir: /compdir
20431 files.files[0].name: list0.h
20432 files.files[0].dir: /srcdir
20433 files.files[1].name: list0.c
20434 files.files[1].dir: /srcdir
20436 The line number information for list0.c has to end up in a single
20437 subfile, so that `break /srcdir/list0.c:1' works as expected.
20438 start_subfile will ensure that this happens provided that we pass the
20439 concatenation of files.files[1].dir and files.files[1].name as the
20443 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20444 const char *dirname
)
20446 gdb::unique_xmalloc_ptr
<char> copy
;
20448 /* In order not to lose the line information directory,
20449 we concatenate it to the filename when it makes sense.
20450 Note that the Dwarf3 standard says (speaking of filenames in line
20451 information): ``The directory index is ignored for file names
20452 that represent full path names''. Thus ignoring dirname in the
20453 `else' branch below isn't an issue. */
20455 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20457 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20458 filename
= copy
.get ();
20461 cu
->get_builder ()->start_subfile (filename
);
20464 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20465 buildsym_compunit constructor. */
20467 struct compunit_symtab
*
20468 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20471 gdb_assert (m_builder
== nullptr);
20473 m_builder
.reset (new struct buildsym_compunit
20474 (per_cu
->dwarf2_per_objfile
->objfile
,
20475 name
, comp_dir
, language
, low_pc
));
20477 list_in_scope
= get_builder ()->get_file_symbols ();
20479 get_builder ()->record_debugformat ("DWARF 2");
20480 get_builder ()->record_producer (producer
);
20482 processing_has_namespace_info
= false;
20484 return get_builder ()->get_compunit_symtab ();
20488 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20489 struct dwarf2_cu
*cu
)
20491 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20492 struct comp_unit_head
*cu_header
= &cu
->header
;
20494 /* NOTE drow/2003-01-30: There used to be a comment and some special
20495 code here to turn a symbol with DW_AT_external and a
20496 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20497 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20498 with some versions of binutils) where shared libraries could have
20499 relocations against symbols in their debug information - the
20500 minimal symbol would have the right address, but the debug info
20501 would not. It's no longer necessary, because we will explicitly
20502 apply relocations when we read in the debug information now. */
20504 /* A DW_AT_location attribute with no contents indicates that a
20505 variable has been optimized away. */
20506 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20508 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20512 /* Handle one degenerate form of location expression specially, to
20513 preserve GDB's previous behavior when section offsets are
20514 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20515 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20517 if (attr
->form_is_block ()
20518 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20519 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20520 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20521 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20522 && (DW_BLOCK (attr
)->size
20523 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20525 unsigned int dummy
;
20527 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20528 SET_SYMBOL_VALUE_ADDRESS (sym
,
20529 read_address (objfile
->obfd
,
20530 DW_BLOCK (attr
)->data
+ 1,
20533 SET_SYMBOL_VALUE_ADDRESS
20534 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20536 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20537 fixup_symbol_section (sym
, objfile
);
20538 SET_SYMBOL_VALUE_ADDRESS
20540 SYMBOL_VALUE_ADDRESS (sym
)
20541 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20545 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20546 expression evaluator, and use LOC_COMPUTED only when necessary
20547 (i.e. when the value of a register or memory location is
20548 referenced, or a thread-local block, etc.). Then again, it might
20549 not be worthwhile. I'm assuming that it isn't unless performance
20550 or memory numbers show me otherwise. */
20552 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20554 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20555 cu
->has_loclist
= true;
20558 /* Given a pointer to a DWARF information entry, figure out if we need
20559 to make a symbol table entry for it, and if so, create a new entry
20560 and return a pointer to it.
20561 If TYPE is NULL, determine symbol type from the die, otherwise
20562 used the passed type.
20563 If SPACE is not NULL, use it to hold the new symbol. If it is
20564 NULL, allocate a new symbol on the objfile's obstack. */
20566 static struct symbol
*
20567 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20568 struct symbol
*space
)
20570 struct dwarf2_per_objfile
*dwarf2_per_objfile
20571 = cu
->per_cu
->dwarf2_per_objfile
;
20572 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20573 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20574 struct symbol
*sym
= NULL
;
20576 struct attribute
*attr
= NULL
;
20577 struct attribute
*attr2
= NULL
;
20578 CORE_ADDR baseaddr
;
20579 struct pending
**list_to_add
= NULL
;
20581 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20583 baseaddr
= objfile
->text_section_offset ();
20585 name
= dwarf2_name (die
, cu
);
20588 const char *linkagename
;
20589 int suppress_add
= 0;
20594 sym
= allocate_symbol (objfile
);
20595 OBJSTAT (objfile
, n_syms
++);
20597 /* Cache this symbol's name and the name's demangled form (if any). */
20598 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20599 linkagename
= dwarf2_physname (name
, die
, cu
);
20600 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20602 /* Fortran does not have mangling standard and the mangling does differ
20603 between gfortran, iFort etc. */
20604 if (cu
->language
== language_fortran
20605 && symbol_get_demangled_name (sym
) == NULL
)
20606 symbol_set_demangled_name (sym
,
20607 dwarf2_full_name (name
, die
, cu
),
20610 /* Default assumptions.
20611 Use the passed type or decode it from the die. */
20612 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20613 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20615 SYMBOL_TYPE (sym
) = type
;
20617 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20618 attr
= dwarf2_attr (die
,
20619 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20621 if (attr
!= nullptr)
20623 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20626 attr
= dwarf2_attr (die
,
20627 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20629 if (attr
!= nullptr)
20631 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20632 struct file_entry
*fe
;
20634 if (cu
->line_header
!= NULL
)
20635 fe
= cu
->line_header
->file_name_at (file_index
);
20640 complaint (_("file index out of range"));
20642 symbol_set_symtab (sym
, fe
->symtab
);
20648 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20649 if (attr
!= nullptr)
20653 addr
= attr
->value_as_address ();
20654 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20655 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20657 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20658 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20659 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20660 add_symbol_to_list (sym
, cu
->list_in_scope
);
20662 case DW_TAG_subprogram
:
20663 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20665 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20666 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20667 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20668 || cu
->language
== language_ada
20669 || cu
->language
== language_fortran
)
20671 /* Subprograms marked external are stored as a global symbol.
20672 Ada and Fortran subprograms, whether marked external or
20673 not, are always stored as a global symbol, because we want
20674 to be able to access them globally. For instance, we want
20675 to be able to break on a nested subprogram without having
20676 to specify the context. */
20677 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20681 list_to_add
= cu
->list_in_scope
;
20684 case DW_TAG_inlined_subroutine
:
20685 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20687 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20688 SYMBOL_INLINED (sym
) = 1;
20689 list_to_add
= cu
->list_in_scope
;
20691 case DW_TAG_template_value_param
:
20693 /* Fall through. */
20694 case DW_TAG_constant
:
20695 case DW_TAG_variable
:
20696 case DW_TAG_member
:
20697 /* Compilation with minimal debug info may result in
20698 variables with missing type entries. Change the
20699 misleading `void' type to something sensible. */
20700 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20701 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20703 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20704 /* In the case of DW_TAG_member, we should only be called for
20705 static const members. */
20706 if (die
->tag
== DW_TAG_member
)
20708 /* dwarf2_add_field uses die_is_declaration,
20709 so we do the same. */
20710 gdb_assert (die_is_declaration (die
, cu
));
20713 if (attr
!= nullptr)
20715 dwarf2_const_value (attr
, sym
, cu
);
20716 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20719 if (attr2
&& (DW_UNSND (attr2
) != 0))
20720 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20722 list_to_add
= cu
->list_in_scope
;
20726 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20727 if (attr
!= nullptr)
20729 var_decode_location (attr
, sym
, cu
);
20730 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20732 /* Fortran explicitly imports any global symbols to the local
20733 scope by DW_TAG_common_block. */
20734 if (cu
->language
== language_fortran
&& die
->parent
20735 && die
->parent
->tag
== DW_TAG_common_block
)
20738 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20739 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20740 && !dwarf2_per_objfile
->has_section_at_zero
)
20742 /* When a static variable is eliminated by the linker,
20743 the corresponding debug information is not stripped
20744 out, but the variable address is set to null;
20745 do not add such variables into symbol table. */
20747 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20749 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20750 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20751 && dwarf2_per_objfile
->can_copy
)
20753 /* A global static variable might be subject to
20754 copy relocation. We first check for a local
20755 minsym, though, because maybe the symbol was
20756 marked hidden, in which case this would not
20758 bound_minimal_symbol found
20759 = (lookup_minimal_symbol_linkage
20760 (sym
->linkage_name (), objfile
));
20761 if (found
.minsym
!= nullptr)
20762 sym
->maybe_copied
= 1;
20765 /* A variable with DW_AT_external is never static,
20766 but it may be block-scoped. */
20768 = ((cu
->list_in_scope
20769 == cu
->get_builder ()->get_file_symbols ())
20770 ? cu
->get_builder ()->get_global_symbols ()
20771 : cu
->list_in_scope
);
20774 list_to_add
= cu
->list_in_scope
;
20778 /* We do not know the address of this symbol.
20779 If it is an external symbol and we have type information
20780 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20781 The address of the variable will then be determined from
20782 the minimal symbol table whenever the variable is
20784 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20786 /* Fortran explicitly imports any global symbols to the local
20787 scope by DW_TAG_common_block. */
20788 if (cu
->language
== language_fortran
&& die
->parent
20789 && die
->parent
->tag
== DW_TAG_common_block
)
20791 /* SYMBOL_CLASS doesn't matter here because
20792 read_common_block is going to reset it. */
20794 list_to_add
= cu
->list_in_scope
;
20796 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20797 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20799 /* A variable with DW_AT_external is never static, but it
20800 may be block-scoped. */
20802 = ((cu
->list_in_scope
20803 == cu
->get_builder ()->get_file_symbols ())
20804 ? cu
->get_builder ()->get_global_symbols ()
20805 : cu
->list_in_scope
);
20807 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20809 else if (!die_is_declaration (die
, cu
))
20811 /* Use the default LOC_OPTIMIZED_OUT class. */
20812 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20814 list_to_add
= cu
->list_in_scope
;
20818 case DW_TAG_formal_parameter
:
20820 /* If we are inside a function, mark this as an argument. If
20821 not, we might be looking at an argument to an inlined function
20822 when we do not have enough information to show inlined frames;
20823 pretend it's a local variable in that case so that the user can
20825 struct context_stack
*curr
20826 = cu
->get_builder ()->get_current_context_stack ();
20827 if (curr
!= nullptr && curr
->name
!= nullptr)
20828 SYMBOL_IS_ARGUMENT (sym
) = 1;
20829 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20830 if (attr
!= nullptr)
20832 var_decode_location (attr
, sym
, cu
);
20834 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20835 if (attr
!= nullptr)
20837 dwarf2_const_value (attr
, sym
, cu
);
20840 list_to_add
= cu
->list_in_scope
;
20843 case DW_TAG_unspecified_parameters
:
20844 /* From varargs functions; gdb doesn't seem to have any
20845 interest in this information, so just ignore it for now.
20848 case DW_TAG_template_type_param
:
20850 /* Fall through. */
20851 case DW_TAG_class_type
:
20852 case DW_TAG_interface_type
:
20853 case DW_TAG_structure_type
:
20854 case DW_TAG_union_type
:
20855 case DW_TAG_set_type
:
20856 case DW_TAG_enumeration_type
:
20857 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20858 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20861 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20862 really ever be static objects: otherwise, if you try
20863 to, say, break of a class's method and you're in a file
20864 which doesn't mention that class, it won't work unless
20865 the check for all static symbols in lookup_symbol_aux
20866 saves you. See the OtherFileClass tests in
20867 gdb.c++/namespace.exp. */
20871 buildsym_compunit
*builder
= cu
->get_builder ();
20873 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20874 && cu
->language
== language_cplus
20875 ? builder
->get_global_symbols ()
20876 : cu
->list_in_scope
);
20878 /* The semantics of C++ state that "struct foo {
20879 ... }" also defines a typedef for "foo". */
20880 if (cu
->language
== language_cplus
20881 || cu
->language
== language_ada
20882 || cu
->language
== language_d
20883 || cu
->language
== language_rust
)
20885 /* The symbol's name is already allocated along
20886 with this objfile, so we don't need to
20887 duplicate it for the type. */
20888 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20889 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20894 case DW_TAG_typedef
:
20895 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20896 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20897 list_to_add
= cu
->list_in_scope
;
20899 case DW_TAG_base_type
:
20900 case DW_TAG_subrange_type
:
20901 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20902 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20903 list_to_add
= cu
->list_in_scope
;
20905 case DW_TAG_enumerator
:
20906 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20907 if (attr
!= nullptr)
20909 dwarf2_const_value (attr
, sym
, cu
);
20912 /* NOTE: carlton/2003-11-10: See comment above in the
20913 DW_TAG_class_type, etc. block. */
20916 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20917 && cu
->language
== language_cplus
20918 ? cu
->get_builder ()->get_global_symbols ()
20919 : cu
->list_in_scope
);
20922 case DW_TAG_imported_declaration
:
20923 case DW_TAG_namespace
:
20924 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20925 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20927 case DW_TAG_module
:
20928 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20929 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20930 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20932 case DW_TAG_common_block
:
20933 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20934 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20935 add_symbol_to_list (sym
, cu
->list_in_scope
);
20938 /* Not a tag we recognize. Hopefully we aren't processing
20939 trash data, but since we must specifically ignore things
20940 we don't recognize, there is nothing else we should do at
20942 complaint (_("unsupported tag: '%s'"),
20943 dwarf_tag_name (die
->tag
));
20949 sym
->hash_next
= objfile
->template_symbols
;
20950 objfile
->template_symbols
= sym
;
20951 list_to_add
= NULL
;
20954 if (list_to_add
!= NULL
)
20955 add_symbol_to_list (sym
, list_to_add
);
20957 /* For the benefit of old versions of GCC, check for anonymous
20958 namespaces based on the demangled name. */
20959 if (!cu
->processing_has_namespace_info
20960 && cu
->language
== language_cplus
)
20961 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20966 /* Given an attr with a DW_FORM_dataN value in host byte order,
20967 zero-extend it as appropriate for the symbol's type. The DWARF
20968 standard (v4) is not entirely clear about the meaning of using
20969 DW_FORM_dataN for a constant with a signed type, where the type is
20970 wider than the data. The conclusion of a discussion on the DWARF
20971 list was that this is unspecified. We choose to always zero-extend
20972 because that is the interpretation long in use by GCC. */
20975 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20976 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20978 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20979 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20980 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20981 LONGEST l
= DW_UNSND (attr
);
20983 if (bits
< sizeof (*value
) * 8)
20985 l
&= ((LONGEST
) 1 << bits
) - 1;
20988 else if (bits
== sizeof (*value
) * 8)
20992 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20993 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21000 /* Read a constant value from an attribute. Either set *VALUE, or if
21001 the value does not fit in *VALUE, set *BYTES - either already
21002 allocated on the objfile obstack, or newly allocated on OBSTACK,
21003 or, set *BATON, if we translated the constant to a location
21007 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21008 const char *name
, struct obstack
*obstack
,
21009 struct dwarf2_cu
*cu
,
21010 LONGEST
*value
, const gdb_byte
**bytes
,
21011 struct dwarf2_locexpr_baton
**baton
)
21013 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21014 struct comp_unit_head
*cu_header
= &cu
->header
;
21015 struct dwarf_block
*blk
;
21016 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21017 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21023 switch (attr
->form
)
21026 case DW_FORM_addrx
:
21027 case DW_FORM_GNU_addr_index
:
21031 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21032 dwarf2_const_value_length_mismatch_complaint (name
,
21033 cu_header
->addr_size
,
21034 TYPE_LENGTH (type
));
21035 /* Symbols of this form are reasonably rare, so we just
21036 piggyback on the existing location code rather than writing
21037 a new implementation of symbol_computed_ops. */
21038 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21039 (*baton
)->per_cu
= cu
->per_cu
;
21040 gdb_assert ((*baton
)->per_cu
);
21042 (*baton
)->size
= 2 + cu_header
->addr_size
;
21043 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21044 (*baton
)->data
= data
;
21046 data
[0] = DW_OP_addr
;
21047 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21048 byte_order
, DW_ADDR (attr
));
21049 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21052 case DW_FORM_string
:
21055 case DW_FORM_GNU_str_index
:
21056 case DW_FORM_GNU_strp_alt
:
21057 /* DW_STRING is already allocated on the objfile obstack, point
21059 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21061 case DW_FORM_block1
:
21062 case DW_FORM_block2
:
21063 case DW_FORM_block4
:
21064 case DW_FORM_block
:
21065 case DW_FORM_exprloc
:
21066 case DW_FORM_data16
:
21067 blk
= DW_BLOCK (attr
);
21068 if (TYPE_LENGTH (type
) != blk
->size
)
21069 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21070 TYPE_LENGTH (type
));
21071 *bytes
= blk
->data
;
21074 /* The DW_AT_const_value attributes are supposed to carry the
21075 symbol's value "represented as it would be on the target
21076 architecture." By the time we get here, it's already been
21077 converted to host endianness, so we just need to sign- or
21078 zero-extend it as appropriate. */
21079 case DW_FORM_data1
:
21080 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21082 case DW_FORM_data2
:
21083 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21085 case DW_FORM_data4
:
21086 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21088 case DW_FORM_data8
:
21089 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21092 case DW_FORM_sdata
:
21093 case DW_FORM_implicit_const
:
21094 *value
= DW_SND (attr
);
21097 case DW_FORM_udata
:
21098 *value
= DW_UNSND (attr
);
21102 complaint (_("unsupported const value attribute form: '%s'"),
21103 dwarf_form_name (attr
->form
));
21110 /* Copy constant value from an attribute to a symbol. */
21113 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21114 struct dwarf2_cu
*cu
)
21116 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21118 const gdb_byte
*bytes
;
21119 struct dwarf2_locexpr_baton
*baton
;
21121 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21122 sym
->print_name (),
21123 &objfile
->objfile_obstack
, cu
,
21124 &value
, &bytes
, &baton
);
21128 SYMBOL_LOCATION_BATON (sym
) = baton
;
21129 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21131 else if (bytes
!= NULL
)
21133 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21134 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21138 SYMBOL_VALUE (sym
) = value
;
21139 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21143 /* Return the type of the die in question using its DW_AT_type attribute. */
21145 static struct type
*
21146 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21148 struct attribute
*type_attr
;
21150 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21153 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21154 /* A missing DW_AT_type represents a void type. */
21155 return objfile_type (objfile
)->builtin_void
;
21158 return lookup_die_type (die
, type_attr
, cu
);
21161 /* True iff CU's producer generates GNAT Ada auxiliary information
21162 that allows to find parallel types through that information instead
21163 of having to do expensive parallel lookups by type name. */
21166 need_gnat_info (struct dwarf2_cu
*cu
)
21168 /* Assume that the Ada compiler was GNAT, which always produces
21169 the auxiliary information. */
21170 return (cu
->language
== language_ada
);
21173 /* Return the auxiliary type of the die in question using its
21174 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21175 attribute is not present. */
21177 static struct type
*
21178 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21180 struct attribute
*type_attr
;
21182 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21186 return lookup_die_type (die
, type_attr
, cu
);
21189 /* If DIE has a descriptive_type attribute, then set the TYPE's
21190 descriptive type accordingly. */
21193 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21194 struct dwarf2_cu
*cu
)
21196 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21198 if (descriptive_type
)
21200 ALLOCATE_GNAT_AUX_TYPE (type
);
21201 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21205 /* Return the containing type of the die in question using its
21206 DW_AT_containing_type attribute. */
21208 static struct type
*
21209 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21211 struct attribute
*type_attr
;
21212 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21214 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21216 error (_("Dwarf Error: Problem turning containing type into gdb type "
21217 "[in module %s]"), objfile_name (objfile
));
21219 return lookup_die_type (die
, type_attr
, cu
);
21222 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21224 static struct type
*
21225 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21227 struct dwarf2_per_objfile
*dwarf2_per_objfile
21228 = cu
->per_cu
->dwarf2_per_objfile
;
21229 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21232 std::string message
21233 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21234 objfile_name (objfile
),
21235 sect_offset_str (cu
->header
.sect_off
),
21236 sect_offset_str (die
->sect_off
));
21237 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21239 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21242 /* Look up the type of DIE in CU using its type attribute ATTR.
21243 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21244 DW_AT_containing_type.
21245 If there is no type substitute an error marker. */
21247 static struct type
*
21248 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21249 struct dwarf2_cu
*cu
)
21251 struct dwarf2_per_objfile
*dwarf2_per_objfile
21252 = cu
->per_cu
->dwarf2_per_objfile
;
21253 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21254 struct type
*this_type
;
21256 gdb_assert (attr
->name
== DW_AT_type
21257 || attr
->name
== DW_AT_GNAT_descriptive_type
21258 || attr
->name
== DW_AT_containing_type
);
21260 /* First see if we have it cached. */
21262 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21264 struct dwarf2_per_cu_data
*per_cu
;
21265 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21267 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21268 dwarf2_per_objfile
);
21269 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21271 else if (attr
->form_is_ref ())
21273 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21275 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21277 else if (attr
->form
== DW_FORM_ref_sig8
)
21279 ULONGEST signature
= DW_SIGNATURE (attr
);
21281 return get_signatured_type (die
, signature
, cu
);
21285 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21286 " at %s [in module %s]"),
21287 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21288 objfile_name (objfile
));
21289 return build_error_marker_type (cu
, die
);
21292 /* If not cached we need to read it in. */
21294 if (this_type
== NULL
)
21296 struct die_info
*type_die
= NULL
;
21297 struct dwarf2_cu
*type_cu
= cu
;
21299 if (attr
->form_is_ref ())
21300 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21301 if (type_die
== NULL
)
21302 return build_error_marker_type (cu
, die
);
21303 /* If we find the type now, it's probably because the type came
21304 from an inter-CU reference and the type's CU got expanded before
21306 this_type
= read_type_die (type_die
, type_cu
);
21309 /* If we still don't have a type use an error marker. */
21311 if (this_type
== NULL
)
21312 return build_error_marker_type (cu
, die
);
21317 /* Return the type in DIE, CU.
21318 Returns NULL for invalid types.
21320 This first does a lookup in die_type_hash,
21321 and only reads the die in if necessary.
21323 NOTE: This can be called when reading in partial or full symbols. */
21325 static struct type
*
21326 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21328 struct type
*this_type
;
21330 this_type
= get_die_type (die
, cu
);
21334 return read_type_die_1 (die
, cu
);
21337 /* Read the type in DIE, CU.
21338 Returns NULL for invalid types. */
21340 static struct type
*
21341 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21343 struct type
*this_type
= NULL
;
21347 case DW_TAG_class_type
:
21348 case DW_TAG_interface_type
:
21349 case DW_TAG_structure_type
:
21350 case DW_TAG_union_type
:
21351 this_type
= read_structure_type (die
, cu
);
21353 case DW_TAG_enumeration_type
:
21354 this_type
= read_enumeration_type (die
, cu
);
21356 case DW_TAG_subprogram
:
21357 case DW_TAG_subroutine_type
:
21358 case DW_TAG_inlined_subroutine
:
21359 this_type
= read_subroutine_type (die
, cu
);
21361 case DW_TAG_array_type
:
21362 this_type
= read_array_type (die
, cu
);
21364 case DW_TAG_set_type
:
21365 this_type
= read_set_type (die
, cu
);
21367 case DW_TAG_pointer_type
:
21368 this_type
= read_tag_pointer_type (die
, cu
);
21370 case DW_TAG_ptr_to_member_type
:
21371 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21373 case DW_TAG_reference_type
:
21374 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21376 case DW_TAG_rvalue_reference_type
:
21377 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21379 case DW_TAG_const_type
:
21380 this_type
= read_tag_const_type (die
, cu
);
21382 case DW_TAG_volatile_type
:
21383 this_type
= read_tag_volatile_type (die
, cu
);
21385 case DW_TAG_restrict_type
:
21386 this_type
= read_tag_restrict_type (die
, cu
);
21388 case DW_TAG_string_type
:
21389 this_type
= read_tag_string_type (die
, cu
);
21391 case DW_TAG_typedef
:
21392 this_type
= read_typedef (die
, cu
);
21394 case DW_TAG_subrange_type
:
21395 this_type
= read_subrange_type (die
, cu
);
21397 case DW_TAG_base_type
:
21398 this_type
= read_base_type (die
, cu
);
21400 case DW_TAG_unspecified_type
:
21401 this_type
= read_unspecified_type (die
, cu
);
21403 case DW_TAG_namespace
:
21404 this_type
= read_namespace_type (die
, cu
);
21406 case DW_TAG_module
:
21407 this_type
= read_module_type (die
, cu
);
21409 case DW_TAG_atomic_type
:
21410 this_type
= read_tag_atomic_type (die
, cu
);
21413 complaint (_("unexpected tag in read_type_die: '%s'"),
21414 dwarf_tag_name (die
->tag
));
21421 /* See if we can figure out if the class lives in a namespace. We do
21422 this by looking for a member function; its demangled name will
21423 contain namespace info, if there is any.
21424 Return the computed name or NULL.
21425 Space for the result is allocated on the objfile's obstack.
21426 This is the full-die version of guess_partial_die_structure_name.
21427 In this case we know DIE has no useful parent. */
21429 static const char *
21430 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21432 struct die_info
*spec_die
;
21433 struct dwarf2_cu
*spec_cu
;
21434 struct die_info
*child
;
21435 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21438 spec_die
= die_specification (die
, &spec_cu
);
21439 if (spec_die
!= NULL
)
21445 for (child
= die
->child
;
21447 child
= child
->sibling
)
21449 if (child
->tag
== DW_TAG_subprogram
)
21451 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21453 if (linkage_name
!= NULL
)
21455 gdb::unique_xmalloc_ptr
<char> actual_name
21456 (language_class_name_from_physname (cu
->language_defn
,
21458 const char *name
= NULL
;
21460 if (actual_name
!= NULL
)
21462 const char *die_name
= dwarf2_name (die
, cu
);
21464 if (die_name
!= NULL
21465 && strcmp (die_name
, actual_name
.get ()) != 0)
21467 /* Strip off the class name from the full name.
21468 We want the prefix. */
21469 int die_name_len
= strlen (die_name
);
21470 int actual_name_len
= strlen (actual_name
.get ());
21471 const char *ptr
= actual_name
.get ();
21473 /* Test for '::' as a sanity check. */
21474 if (actual_name_len
> die_name_len
+ 2
21475 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21476 name
= obstack_strndup (
21477 &objfile
->per_bfd
->storage_obstack
,
21478 ptr
, actual_name_len
- die_name_len
- 2);
21489 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21490 prefix part in such case. See
21491 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21493 static const char *
21494 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21496 struct attribute
*attr
;
21499 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21500 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21503 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21506 attr
= dw2_linkage_name_attr (die
, cu
);
21507 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21510 /* dwarf2_name had to be already called. */
21511 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21513 /* Strip the base name, keep any leading namespaces/classes. */
21514 base
= strrchr (DW_STRING (attr
), ':');
21515 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21518 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21519 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21521 &base
[-1] - DW_STRING (attr
));
21524 /* Return the name of the namespace/class that DIE is defined within,
21525 or "" if we can't tell. The caller should not xfree the result.
21527 For example, if we're within the method foo() in the following
21537 then determine_prefix on foo's die will return "N::C". */
21539 static const char *
21540 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21542 struct dwarf2_per_objfile
*dwarf2_per_objfile
21543 = cu
->per_cu
->dwarf2_per_objfile
;
21544 struct die_info
*parent
, *spec_die
;
21545 struct dwarf2_cu
*spec_cu
;
21546 struct type
*parent_type
;
21547 const char *retval
;
21549 if (cu
->language
!= language_cplus
21550 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21551 && cu
->language
!= language_rust
)
21554 retval
= anonymous_struct_prefix (die
, cu
);
21558 /* We have to be careful in the presence of DW_AT_specification.
21559 For example, with GCC 3.4, given the code
21563 // Definition of N::foo.
21567 then we'll have a tree of DIEs like this:
21569 1: DW_TAG_compile_unit
21570 2: DW_TAG_namespace // N
21571 3: DW_TAG_subprogram // declaration of N::foo
21572 4: DW_TAG_subprogram // definition of N::foo
21573 DW_AT_specification // refers to die #3
21575 Thus, when processing die #4, we have to pretend that we're in
21576 the context of its DW_AT_specification, namely the contex of die
21579 spec_die
= die_specification (die
, &spec_cu
);
21580 if (spec_die
== NULL
)
21581 parent
= die
->parent
;
21584 parent
= spec_die
->parent
;
21588 if (parent
== NULL
)
21590 else if (parent
->building_fullname
)
21593 const char *parent_name
;
21595 /* It has been seen on RealView 2.2 built binaries,
21596 DW_TAG_template_type_param types actually _defined_ as
21597 children of the parent class:
21600 template class <class Enum> Class{};
21601 Class<enum E> class_e;
21603 1: DW_TAG_class_type (Class)
21604 2: DW_TAG_enumeration_type (E)
21605 3: DW_TAG_enumerator (enum1:0)
21606 3: DW_TAG_enumerator (enum2:1)
21608 2: DW_TAG_template_type_param
21609 DW_AT_type DW_FORM_ref_udata (E)
21611 Besides being broken debug info, it can put GDB into an
21612 infinite loop. Consider:
21614 When we're building the full name for Class<E>, we'll start
21615 at Class, and go look over its template type parameters,
21616 finding E. We'll then try to build the full name of E, and
21617 reach here. We're now trying to build the full name of E,
21618 and look over the parent DIE for containing scope. In the
21619 broken case, if we followed the parent DIE of E, we'd again
21620 find Class, and once again go look at its template type
21621 arguments, etc., etc. Simply don't consider such parent die
21622 as source-level parent of this die (it can't be, the language
21623 doesn't allow it), and break the loop here. */
21624 name
= dwarf2_name (die
, cu
);
21625 parent_name
= dwarf2_name (parent
, cu
);
21626 complaint (_("template param type '%s' defined within parent '%s'"),
21627 name
? name
: "<unknown>",
21628 parent_name
? parent_name
: "<unknown>");
21632 switch (parent
->tag
)
21634 case DW_TAG_namespace
:
21635 parent_type
= read_type_die (parent
, cu
);
21636 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21637 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21638 Work around this problem here. */
21639 if (cu
->language
== language_cplus
21640 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21642 /* We give a name to even anonymous namespaces. */
21643 return TYPE_NAME (parent_type
);
21644 case DW_TAG_class_type
:
21645 case DW_TAG_interface_type
:
21646 case DW_TAG_structure_type
:
21647 case DW_TAG_union_type
:
21648 case DW_TAG_module
:
21649 parent_type
= read_type_die (parent
, cu
);
21650 if (TYPE_NAME (parent_type
) != NULL
)
21651 return TYPE_NAME (parent_type
);
21653 /* An anonymous structure is only allowed non-static data
21654 members; no typedefs, no member functions, et cetera.
21655 So it does not need a prefix. */
21657 case DW_TAG_compile_unit
:
21658 case DW_TAG_partial_unit
:
21659 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21660 if (cu
->language
== language_cplus
21661 && !dwarf2_per_objfile
->types
.empty ()
21662 && die
->child
!= NULL
21663 && (die
->tag
== DW_TAG_class_type
21664 || die
->tag
== DW_TAG_structure_type
21665 || die
->tag
== DW_TAG_union_type
))
21667 const char *name
= guess_full_die_structure_name (die
, cu
);
21672 case DW_TAG_subprogram
:
21673 /* Nested subroutines in Fortran get a prefix with the name
21674 of the parent's subroutine. */
21675 if (cu
->language
== language_fortran
)
21677 if ((die
->tag
== DW_TAG_subprogram
)
21678 && (dwarf2_name (parent
, cu
) != NULL
))
21679 return dwarf2_name (parent
, cu
);
21681 return determine_prefix (parent
, cu
);
21682 case DW_TAG_enumeration_type
:
21683 parent_type
= read_type_die (parent
, cu
);
21684 if (TYPE_DECLARED_CLASS (parent_type
))
21686 if (TYPE_NAME (parent_type
) != NULL
)
21687 return TYPE_NAME (parent_type
);
21690 /* Fall through. */
21692 return determine_prefix (parent
, cu
);
21696 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21697 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21698 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21699 an obconcat, otherwise allocate storage for the result. The CU argument is
21700 used to determine the language and hence, the appropriate separator. */
21702 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21705 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21706 int physname
, struct dwarf2_cu
*cu
)
21708 const char *lead
= "";
21711 if (suffix
== NULL
|| suffix
[0] == '\0'
21712 || prefix
== NULL
|| prefix
[0] == '\0')
21714 else if (cu
->language
== language_d
)
21716 /* For D, the 'main' function could be defined in any module, but it
21717 should never be prefixed. */
21718 if (strcmp (suffix
, "D main") == 0)
21726 else if (cu
->language
== language_fortran
&& physname
)
21728 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21729 DW_AT_MIPS_linkage_name is preferred and used instead. */
21737 if (prefix
== NULL
)
21739 if (suffix
== NULL
)
21746 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21748 strcpy (retval
, lead
);
21749 strcat (retval
, prefix
);
21750 strcat (retval
, sep
);
21751 strcat (retval
, suffix
);
21756 /* We have an obstack. */
21757 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21761 /* Return sibling of die, NULL if no sibling. */
21763 static struct die_info
*
21764 sibling_die (struct die_info
*die
)
21766 return die
->sibling
;
21769 /* Get name of a die, return NULL if not found. */
21771 static const char *
21772 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21773 struct obstack
*obstack
)
21775 if (name
&& cu
->language
== language_cplus
)
21777 std::string canon_name
= cp_canonicalize_string (name
);
21779 if (!canon_name
.empty ())
21781 if (canon_name
!= name
)
21782 name
= obstack_strdup (obstack
, canon_name
);
21789 /* Get name of a die, return NULL if not found.
21790 Anonymous namespaces are converted to their magic string. */
21792 static const char *
21793 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21795 struct attribute
*attr
;
21796 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21798 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21799 if ((!attr
|| !DW_STRING (attr
))
21800 && die
->tag
!= DW_TAG_namespace
21801 && die
->tag
!= DW_TAG_class_type
21802 && die
->tag
!= DW_TAG_interface_type
21803 && die
->tag
!= DW_TAG_structure_type
21804 && die
->tag
!= DW_TAG_union_type
)
21809 case DW_TAG_compile_unit
:
21810 case DW_TAG_partial_unit
:
21811 /* Compilation units have a DW_AT_name that is a filename, not
21812 a source language identifier. */
21813 case DW_TAG_enumeration_type
:
21814 case DW_TAG_enumerator
:
21815 /* These tags always have simple identifiers already; no need
21816 to canonicalize them. */
21817 return DW_STRING (attr
);
21819 case DW_TAG_namespace
:
21820 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21821 return DW_STRING (attr
);
21822 return CP_ANONYMOUS_NAMESPACE_STR
;
21824 case DW_TAG_class_type
:
21825 case DW_TAG_interface_type
:
21826 case DW_TAG_structure_type
:
21827 case DW_TAG_union_type
:
21828 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21829 structures or unions. These were of the form "._%d" in GCC 4.1,
21830 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21831 and GCC 4.4. We work around this problem by ignoring these. */
21832 if (attr
&& DW_STRING (attr
)
21833 && (startswith (DW_STRING (attr
), "._")
21834 || startswith (DW_STRING (attr
), "<anonymous")))
21837 /* GCC might emit a nameless typedef that has a linkage name. See
21838 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21839 if (!attr
|| DW_STRING (attr
) == NULL
)
21841 attr
= dw2_linkage_name_attr (die
, cu
);
21842 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21845 /* Avoid demangling DW_STRING (attr) the second time on a second
21846 call for the same DIE. */
21847 if (!DW_STRING_IS_CANONICAL (attr
))
21849 gdb::unique_xmalloc_ptr
<char> demangled
21850 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21854 /* FIXME: we already did this for the partial symbol... */
21856 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
21858 DW_STRING_IS_CANONICAL (attr
) = 1;
21860 /* Strip any leading namespaces/classes, keep only the base name.
21861 DW_AT_name for named DIEs does not contain the prefixes. */
21862 base
= strrchr (DW_STRING (attr
), ':');
21863 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21866 return DW_STRING (attr
);
21875 if (!DW_STRING_IS_CANONICAL (attr
))
21878 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21879 &objfile
->per_bfd
->storage_obstack
);
21880 DW_STRING_IS_CANONICAL (attr
) = 1;
21882 return DW_STRING (attr
);
21885 /* Return the die that this die in an extension of, or NULL if there
21886 is none. *EXT_CU is the CU containing DIE on input, and the CU
21887 containing the return value on output. */
21889 static struct die_info
*
21890 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21892 struct attribute
*attr
;
21894 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21898 return follow_die_ref (die
, attr
, ext_cu
);
21901 /* A convenience function that returns an "unknown" DWARF name,
21902 including the value of V. STR is the name of the entity being
21903 printed, e.g., "TAG". */
21905 static const char *
21906 dwarf_unknown (const char *str
, unsigned v
)
21908 char *cell
= get_print_cell ();
21909 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21913 /* Convert a DIE tag into its string name. */
21915 static const char *
21916 dwarf_tag_name (unsigned tag
)
21918 const char *name
= get_DW_TAG_name (tag
);
21921 return dwarf_unknown ("TAG", tag
);
21926 /* Convert a DWARF attribute code into its string name. */
21928 static const char *
21929 dwarf_attr_name (unsigned attr
)
21933 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21934 if (attr
== DW_AT_MIPS_fde
)
21935 return "DW_AT_MIPS_fde";
21937 if (attr
== DW_AT_HP_block_index
)
21938 return "DW_AT_HP_block_index";
21941 name
= get_DW_AT_name (attr
);
21944 return dwarf_unknown ("AT", attr
);
21949 /* Convert a DWARF value form code into its string name. */
21951 static const char *
21952 dwarf_form_name (unsigned form
)
21954 const char *name
= get_DW_FORM_name (form
);
21957 return dwarf_unknown ("FORM", form
);
21962 static const char *
21963 dwarf_bool_name (unsigned mybool
)
21971 /* Convert a DWARF type code into its string name. */
21973 static const char *
21974 dwarf_type_encoding_name (unsigned enc
)
21976 const char *name
= get_DW_ATE_name (enc
);
21979 return dwarf_unknown ("ATE", enc
);
21985 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21989 print_spaces (indent
, f
);
21990 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21991 dwarf_tag_name (die
->tag
), die
->abbrev
,
21992 sect_offset_str (die
->sect_off
));
21994 if (die
->parent
!= NULL
)
21996 print_spaces (indent
, f
);
21997 fprintf_unfiltered (f
, " parent at offset: %s\n",
21998 sect_offset_str (die
->parent
->sect_off
));
22001 print_spaces (indent
, f
);
22002 fprintf_unfiltered (f
, " has children: %s\n",
22003 dwarf_bool_name (die
->child
!= NULL
));
22005 print_spaces (indent
, f
);
22006 fprintf_unfiltered (f
, " attributes:\n");
22008 for (i
= 0; i
< die
->num_attrs
; ++i
)
22010 print_spaces (indent
, f
);
22011 fprintf_unfiltered (f
, " %s (%s) ",
22012 dwarf_attr_name (die
->attrs
[i
].name
),
22013 dwarf_form_name (die
->attrs
[i
].form
));
22015 switch (die
->attrs
[i
].form
)
22018 case DW_FORM_addrx
:
22019 case DW_FORM_GNU_addr_index
:
22020 fprintf_unfiltered (f
, "address: ");
22021 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22023 case DW_FORM_block2
:
22024 case DW_FORM_block4
:
22025 case DW_FORM_block
:
22026 case DW_FORM_block1
:
22027 fprintf_unfiltered (f
, "block: size %s",
22028 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22030 case DW_FORM_exprloc
:
22031 fprintf_unfiltered (f
, "expression: size %s",
22032 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22034 case DW_FORM_data16
:
22035 fprintf_unfiltered (f
, "constant of 16 bytes");
22037 case DW_FORM_ref_addr
:
22038 fprintf_unfiltered (f
, "ref address: ");
22039 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22041 case DW_FORM_GNU_ref_alt
:
22042 fprintf_unfiltered (f
, "alt ref address: ");
22043 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22049 case DW_FORM_ref_udata
:
22050 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22051 (long) (DW_UNSND (&die
->attrs
[i
])));
22053 case DW_FORM_data1
:
22054 case DW_FORM_data2
:
22055 case DW_FORM_data4
:
22056 case DW_FORM_data8
:
22057 case DW_FORM_udata
:
22058 case DW_FORM_sdata
:
22059 fprintf_unfiltered (f
, "constant: %s",
22060 pulongest (DW_UNSND (&die
->attrs
[i
])));
22062 case DW_FORM_sec_offset
:
22063 fprintf_unfiltered (f
, "section offset: %s",
22064 pulongest (DW_UNSND (&die
->attrs
[i
])));
22066 case DW_FORM_ref_sig8
:
22067 fprintf_unfiltered (f
, "signature: %s",
22068 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22070 case DW_FORM_string
:
22072 case DW_FORM_line_strp
:
22074 case DW_FORM_GNU_str_index
:
22075 case DW_FORM_GNU_strp_alt
:
22076 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22077 DW_STRING (&die
->attrs
[i
])
22078 ? DW_STRING (&die
->attrs
[i
]) : "",
22079 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22082 if (DW_UNSND (&die
->attrs
[i
]))
22083 fprintf_unfiltered (f
, "flag: TRUE");
22085 fprintf_unfiltered (f
, "flag: FALSE");
22087 case DW_FORM_flag_present
:
22088 fprintf_unfiltered (f
, "flag: TRUE");
22090 case DW_FORM_indirect
:
22091 /* The reader will have reduced the indirect form to
22092 the "base form" so this form should not occur. */
22093 fprintf_unfiltered (f
,
22094 "unexpected attribute form: DW_FORM_indirect");
22096 case DW_FORM_implicit_const
:
22097 fprintf_unfiltered (f
, "constant: %s",
22098 plongest (DW_SND (&die
->attrs
[i
])));
22101 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22102 die
->attrs
[i
].form
);
22105 fprintf_unfiltered (f
, "\n");
22110 dump_die_for_error (struct die_info
*die
)
22112 dump_die_shallow (gdb_stderr
, 0, die
);
22116 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22118 int indent
= level
* 4;
22120 gdb_assert (die
!= NULL
);
22122 if (level
>= max_level
)
22125 dump_die_shallow (f
, indent
, die
);
22127 if (die
->child
!= NULL
)
22129 print_spaces (indent
, f
);
22130 fprintf_unfiltered (f
, " Children:");
22131 if (level
+ 1 < max_level
)
22133 fprintf_unfiltered (f
, "\n");
22134 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22138 fprintf_unfiltered (f
,
22139 " [not printed, max nesting level reached]\n");
22143 if (die
->sibling
!= NULL
&& level
> 0)
22145 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22149 /* This is called from the pdie macro in gdbinit.in.
22150 It's not static so gcc will keep a copy callable from gdb. */
22153 dump_die (struct die_info
*die
, int max_level
)
22155 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22159 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22163 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22164 to_underlying (die
->sect_off
),
22170 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22174 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22176 if (attr
->form_is_ref ())
22177 return (sect_offset
) DW_UNSND (attr
);
22179 complaint (_("unsupported die ref attribute form: '%s'"),
22180 dwarf_form_name (attr
->form
));
22184 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22185 * the value held by the attribute is not constant. */
22188 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22190 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22191 return DW_SND (attr
);
22192 else if (attr
->form
== DW_FORM_udata
22193 || attr
->form
== DW_FORM_data1
22194 || attr
->form
== DW_FORM_data2
22195 || attr
->form
== DW_FORM_data4
22196 || attr
->form
== DW_FORM_data8
)
22197 return DW_UNSND (attr
);
22200 /* For DW_FORM_data16 see attribute::form_is_constant. */
22201 complaint (_("Attribute value is not a constant (%s)"),
22202 dwarf_form_name (attr
->form
));
22203 return default_value
;
22207 /* Follow reference or signature attribute ATTR of SRC_DIE.
22208 On entry *REF_CU is the CU of SRC_DIE.
22209 On exit *REF_CU is the CU of the result. */
22211 static struct die_info
*
22212 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22213 struct dwarf2_cu
**ref_cu
)
22215 struct die_info
*die
;
22217 if (attr
->form_is_ref ())
22218 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22219 else if (attr
->form
== DW_FORM_ref_sig8
)
22220 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22223 dump_die_for_error (src_die
);
22224 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22225 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22231 /* Follow reference OFFSET.
22232 On entry *REF_CU is the CU of the source die referencing OFFSET.
22233 On exit *REF_CU is the CU of the result.
22234 Returns NULL if OFFSET is invalid. */
22236 static struct die_info
*
22237 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22238 struct dwarf2_cu
**ref_cu
)
22240 struct die_info temp_die
;
22241 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22242 struct dwarf2_per_objfile
*dwarf2_per_objfile
22243 = cu
->per_cu
->dwarf2_per_objfile
;
22245 gdb_assert (cu
->per_cu
!= NULL
);
22249 if (cu
->per_cu
->is_debug_types
)
22251 /* .debug_types CUs cannot reference anything outside their CU.
22252 If they need to, they have to reference a signatured type via
22253 DW_FORM_ref_sig8. */
22254 if (!cu
->header
.offset_in_cu_p (sect_off
))
22257 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22258 || !cu
->header
.offset_in_cu_p (sect_off
))
22260 struct dwarf2_per_cu_data
*per_cu
;
22262 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22263 dwarf2_per_objfile
);
22265 /* If necessary, add it to the queue and load its DIEs. */
22266 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22267 load_full_comp_unit (per_cu
, false, cu
->language
);
22269 target_cu
= per_cu
->cu
;
22271 else if (cu
->dies
== NULL
)
22273 /* We're loading full DIEs during partial symbol reading. */
22274 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22275 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22278 *ref_cu
= target_cu
;
22279 temp_die
.sect_off
= sect_off
;
22281 if (target_cu
!= cu
)
22282 target_cu
->ancestor
= cu
;
22284 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22286 to_underlying (sect_off
));
22289 /* Follow reference attribute ATTR of SRC_DIE.
22290 On entry *REF_CU is the CU of SRC_DIE.
22291 On exit *REF_CU is the CU of the result. */
22293 static struct die_info
*
22294 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22295 struct dwarf2_cu
**ref_cu
)
22297 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22298 struct dwarf2_cu
*cu
= *ref_cu
;
22299 struct die_info
*die
;
22301 die
= follow_die_offset (sect_off
,
22302 (attr
->form
== DW_FORM_GNU_ref_alt
22303 || cu
->per_cu
->is_dwz
),
22306 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22307 "at %s [in module %s]"),
22308 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22309 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22314 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22315 Returned value is intended for DW_OP_call*. Returned
22316 dwarf2_locexpr_baton->data has lifetime of
22317 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22319 struct dwarf2_locexpr_baton
22320 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22321 struct dwarf2_per_cu_data
*per_cu
,
22322 CORE_ADDR (*get_frame_pc
) (void *baton
),
22323 void *baton
, bool resolve_abstract_p
)
22325 struct dwarf2_cu
*cu
;
22326 struct die_info
*die
;
22327 struct attribute
*attr
;
22328 struct dwarf2_locexpr_baton retval
;
22329 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22330 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22332 if (per_cu
->cu
== NULL
)
22333 load_cu (per_cu
, false);
22337 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22338 Instead just throw an error, not much else we can do. */
22339 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22340 sect_offset_str (sect_off
), objfile_name (objfile
));
22343 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22345 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22346 sect_offset_str (sect_off
), objfile_name (objfile
));
22348 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22349 if (!attr
&& resolve_abstract_p
22350 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22351 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22353 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22354 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22355 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22357 for (const auto &cand_off
22358 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22360 struct dwarf2_cu
*cand_cu
= cu
;
22361 struct die_info
*cand
22362 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22365 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22368 CORE_ADDR pc_low
, pc_high
;
22369 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22370 if (pc_low
== ((CORE_ADDR
) -1))
22372 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22373 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22374 if (!(pc_low
<= pc
&& pc
< pc_high
))
22378 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22385 /* DWARF: "If there is no such attribute, then there is no effect.".
22386 DATA is ignored if SIZE is 0. */
22388 retval
.data
= NULL
;
22391 else if (attr
->form_is_section_offset ())
22393 struct dwarf2_loclist_baton loclist_baton
;
22394 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22397 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22399 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22401 retval
.size
= size
;
22405 if (!attr
->form_is_block ())
22406 error (_("Dwarf Error: DIE at %s referenced in module %s "
22407 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22408 sect_offset_str (sect_off
), objfile_name (objfile
));
22410 retval
.data
= DW_BLOCK (attr
)->data
;
22411 retval
.size
= DW_BLOCK (attr
)->size
;
22413 retval
.per_cu
= cu
->per_cu
;
22415 age_cached_comp_units (dwarf2_per_objfile
);
22420 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
22423 struct dwarf2_locexpr_baton
22424 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22425 struct dwarf2_per_cu_data
*per_cu
,
22426 CORE_ADDR (*get_frame_pc
) (void *baton
),
22429 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22431 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22434 /* Write a constant of a given type as target-ordered bytes into
22437 static const gdb_byte
*
22438 write_constant_as_bytes (struct obstack
*obstack
,
22439 enum bfd_endian byte_order
,
22446 *len
= TYPE_LENGTH (type
);
22447 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22448 store_unsigned_integer (result
, *len
, byte_order
, value
);
22453 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
22454 pointer to the constant bytes and set LEN to the length of the
22455 data. If memory is needed, allocate it on OBSTACK. If the DIE
22456 does not have a DW_AT_const_value, return NULL. */
22459 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22460 struct dwarf2_per_cu_data
*per_cu
,
22461 struct obstack
*obstack
,
22464 struct dwarf2_cu
*cu
;
22465 struct die_info
*die
;
22466 struct attribute
*attr
;
22467 const gdb_byte
*result
= NULL
;
22470 enum bfd_endian byte_order
;
22471 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22473 if (per_cu
->cu
== NULL
)
22474 load_cu (per_cu
, false);
22478 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22479 Instead just throw an error, not much else we can do. */
22480 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22481 sect_offset_str (sect_off
), objfile_name (objfile
));
22484 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22486 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22487 sect_offset_str (sect_off
), objfile_name (objfile
));
22489 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22493 byte_order
= (bfd_big_endian (objfile
->obfd
)
22494 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22496 switch (attr
->form
)
22499 case DW_FORM_addrx
:
22500 case DW_FORM_GNU_addr_index
:
22504 *len
= cu
->header
.addr_size
;
22505 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22506 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22510 case DW_FORM_string
:
22513 case DW_FORM_GNU_str_index
:
22514 case DW_FORM_GNU_strp_alt
:
22515 /* DW_STRING is already allocated on the objfile obstack, point
22517 result
= (const gdb_byte
*) DW_STRING (attr
);
22518 *len
= strlen (DW_STRING (attr
));
22520 case DW_FORM_block1
:
22521 case DW_FORM_block2
:
22522 case DW_FORM_block4
:
22523 case DW_FORM_block
:
22524 case DW_FORM_exprloc
:
22525 case DW_FORM_data16
:
22526 result
= DW_BLOCK (attr
)->data
;
22527 *len
= DW_BLOCK (attr
)->size
;
22530 /* The DW_AT_const_value attributes are supposed to carry the
22531 symbol's value "represented as it would be on the target
22532 architecture." By the time we get here, it's already been
22533 converted to host endianness, so we just need to sign- or
22534 zero-extend it as appropriate. */
22535 case DW_FORM_data1
:
22536 type
= die_type (die
, cu
);
22537 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22538 if (result
== NULL
)
22539 result
= write_constant_as_bytes (obstack
, byte_order
,
22542 case DW_FORM_data2
:
22543 type
= die_type (die
, cu
);
22544 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22545 if (result
== NULL
)
22546 result
= write_constant_as_bytes (obstack
, byte_order
,
22549 case DW_FORM_data4
:
22550 type
= die_type (die
, cu
);
22551 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22552 if (result
== NULL
)
22553 result
= write_constant_as_bytes (obstack
, byte_order
,
22556 case DW_FORM_data8
:
22557 type
= die_type (die
, cu
);
22558 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22559 if (result
== NULL
)
22560 result
= write_constant_as_bytes (obstack
, byte_order
,
22564 case DW_FORM_sdata
:
22565 case DW_FORM_implicit_const
:
22566 type
= die_type (die
, cu
);
22567 result
= write_constant_as_bytes (obstack
, byte_order
,
22568 type
, DW_SND (attr
), len
);
22571 case DW_FORM_udata
:
22572 type
= die_type (die
, cu
);
22573 result
= write_constant_as_bytes (obstack
, byte_order
,
22574 type
, DW_UNSND (attr
), len
);
22578 complaint (_("unsupported const value attribute form: '%s'"),
22579 dwarf_form_name (attr
->form
));
22586 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
22587 valid type for this die is found. */
22590 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22591 struct dwarf2_per_cu_data
*per_cu
)
22593 struct dwarf2_cu
*cu
;
22594 struct die_info
*die
;
22596 if (per_cu
->cu
== NULL
)
22597 load_cu (per_cu
, false);
22602 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22606 return die_type (die
, cu
);
22609 /* Return the type of the DIE at DIE_OFFSET in the CU named by
22613 dwarf2_get_die_type (cu_offset die_offset
,
22614 struct dwarf2_per_cu_data
*per_cu
)
22616 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22617 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22620 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22621 On entry *REF_CU is the CU of SRC_DIE.
22622 On exit *REF_CU is the CU of the result.
22623 Returns NULL if the referenced DIE isn't found. */
22625 static struct die_info
*
22626 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22627 struct dwarf2_cu
**ref_cu
)
22629 struct die_info temp_die
;
22630 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22631 struct die_info
*die
;
22633 /* While it might be nice to assert sig_type->type == NULL here,
22634 we can get here for DW_AT_imported_declaration where we need
22635 the DIE not the type. */
22637 /* If necessary, add it to the queue and load its DIEs. */
22639 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22640 read_signatured_type (sig_type
);
22642 sig_cu
= sig_type
->per_cu
.cu
;
22643 gdb_assert (sig_cu
!= NULL
);
22644 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22645 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22646 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22647 to_underlying (temp_die
.sect_off
));
22650 struct dwarf2_per_objfile
*dwarf2_per_objfile
22651 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22653 /* For .gdb_index version 7 keep track of included TUs.
22654 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22655 if (dwarf2_per_objfile
->index_table
!= NULL
22656 && dwarf2_per_objfile
->index_table
->version
<= 7)
22658 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22663 sig_cu
->ancestor
= cu
;
22671 /* Follow signatured type referenced by ATTR in SRC_DIE.
22672 On entry *REF_CU is the CU of SRC_DIE.
22673 On exit *REF_CU is the CU of the result.
22674 The result is the DIE of the type.
22675 If the referenced type cannot be found an error is thrown. */
22677 static struct die_info
*
22678 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22679 struct dwarf2_cu
**ref_cu
)
22681 ULONGEST signature
= DW_SIGNATURE (attr
);
22682 struct signatured_type
*sig_type
;
22683 struct die_info
*die
;
22685 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22687 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22688 /* sig_type will be NULL if the signatured type is missing from
22690 if (sig_type
== NULL
)
22692 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22693 " from DIE at %s [in module %s]"),
22694 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22695 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22698 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22701 dump_die_for_error (src_die
);
22702 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22703 " from DIE at %s [in module %s]"),
22704 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22705 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22711 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22712 reading in and processing the type unit if necessary. */
22714 static struct type
*
22715 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22716 struct dwarf2_cu
*cu
)
22718 struct dwarf2_per_objfile
*dwarf2_per_objfile
22719 = cu
->per_cu
->dwarf2_per_objfile
;
22720 struct signatured_type
*sig_type
;
22721 struct dwarf2_cu
*type_cu
;
22722 struct die_info
*type_die
;
22725 sig_type
= lookup_signatured_type (cu
, signature
);
22726 /* sig_type will be NULL if the signatured type is missing from
22728 if (sig_type
== NULL
)
22730 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22731 " from DIE at %s [in module %s]"),
22732 hex_string (signature
), sect_offset_str (die
->sect_off
),
22733 objfile_name (dwarf2_per_objfile
->objfile
));
22734 return build_error_marker_type (cu
, die
);
22737 /* If we already know the type we're done. */
22738 if (sig_type
->type
!= NULL
)
22739 return sig_type
->type
;
22742 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22743 if (type_die
!= NULL
)
22745 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22746 is created. This is important, for example, because for c++ classes
22747 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22748 type
= read_type_die (type_die
, type_cu
);
22751 complaint (_("Dwarf Error: Cannot build signatured type %s"
22752 " referenced from DIE at %s [in module %s]"),
22753 hex_string (signature
), sect_offset_str (die
->sect_off
),
22754 objfile_name (dwarf2_per_objfile
->objfile
));
22755 type
= build_error_marker_type (cu
, die
);
22760 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22761 " from DIE at %s [in module %s]"),
22762 hex_string (signature
), sect_offset_str (die
->sect_off
),
22763 objfile_name (dwarf2_per_objfile
->objfile
));
22764 type
= build_error_marker_type (cu
, die
);
22766 sig_type
->type
= type
;
22771 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22772 reading in and processing the type unit if necessary. */
22774 static struct type
*
22775 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22776 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22778 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22779 if (attr
->form_is_ref ())
22781 struct dwarf2_cu
*type_cu
= cu
;
22782 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22784 return read_type_die (type_die
, type_cu
);
22786 else if (attr
->form
== DW_FORM_ref_sig8
)
22788 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22792 struct dwarf2_per_objfile
*dwarf2_per_objfile
22793 = cu
->per_cu
->dwarf2_per_objfile
;
22795 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22796 " at %s [in module %s]"),
22797 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22798 objfile_name (dwarf2_per_objfile
->objfile
));
22799 return build_error_marker_type (cu
, die
);
22803 /* Load the DIEs associated with type unit PER_CU into memory. */
22806 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22808 struct signatured_type
*sig_type
;
22810 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22811 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
22813 /* We have the per_cu, but we need the signatured_type.
22814 Fortunately this is an easy translation. */
22815 gdb_assert (per_cu
->is_debug_types
);
22816 sig_type
= (struct signatured_type
*) per_cu
;
22818 gdb_assert (per_cu
->cu
== NULL
);
22820 read_signatured_type (sig_type
);
22822 gdb_assert (per_cu
->cu
!= NULL
);
22825 /* Read in a signatured type and build its CU and DIEs.
22826 If the type is a stub for the real type in a DWO file,
22827 read in the real type from the DWO file as well. */
22830 read_signatured_type (struct signatured_type
*sig_type
)
22832 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22834 gdb_assert (per_cu
->is_debug_types
);
22835 gdb_assert (per_cu
->cu
== NULL
);
22837 cutu_reader
reader (per_cu
, NULL
, 0, 1, false);
22839 if (!reader
.dummy_p
)
22841 struct dwarf2_cu
*cu
= reader
.cu
;
22842 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22844 gdb_assert (cu
->die_hash
== NULL
);
22846 htab_create_alloc_ex (cu
->header
.length
/ 12,
22850 &cu
->comp_unit_obstack
,
22851 hashtab_obstack_allocate
,
22852 dummy_obstack_deallocate
);
22854 if (reader
.comp_unit_die
->has_children
)
22855 reader
.comp_unit_die
->child
22856 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22857 reader
.comp_unit_die
);
22858 cu
->dies
= reader
.comp_unit_die
;
22859 /* comp_unit_die is not stored in die_hash, no need. */
22861 /* We try not to read any attributes in this function, because
22862 not all CUs needed for references have been loaded yet, and
22863 symbol table processing isn't initialized. But we have to
22864 set the CU language, or we won't be able to build types
22865 correctly. Similarly, if we do not read the producer, we can
22866 not apply producer-specific interpretation. */
22867 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22870 sig_type
->per_cu
.tu_read
= 1;
22873 /* Decode simple location descriptions.
22874 Given a pointer to a dwarf block that defines a location, compute
22875 the location and return the value.
22877 NOTE drow/2003-11-18: This function is called in two situations
22878 now: for the address of static or global variables (partial symbols
22879 only) and for offsets into structures which are expected to be
22880 (more or less) constant. The partial symbol case should go away,
22881 and only the constant case should remain. That will let this
22882 function complain more accurately. A few special modes are allowed
22883 without complaint for global variables (for instance, global
22884 register values and thread-local values).
22886 A location description containing no operations indicates that the
22887 object is optimized out. The return value is 0 for that case.
22888 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22889 callers will only want a very basic result and this can become a
22892 Note that stack[0] is unused except as a default error return. */
22895 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22897 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22899 size_t size
= blk
->size
;
22900 const gdb_byte
*data
= blk
->data
;
22901 CORE_ADDR stack
[64];
22903 unsigned int bytes_read
, unsnd
;
22909 stack
[++stacki
] = 0;
22948 stack
[++stacki
] = op
- DW_OP_lit0
;
22983 stack
[++stacki
] = op
- DW_OP_reg0
;
22985 dwarf2_complex_location_expr_complaint ();
22989 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22991 stack
[++stacki
] = unsnd
;
22993 dwarf2_complex_location_expr_complaint ();
22997 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23002 case DW_OP_const1u
:
23003 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23007 case DW_OP_const1s
:
23008 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23012 case DW_OP_const2u
:
23013 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23017 case DW_OP_const2s
:
23018 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23022 case DW_OP_const4u
:
23023 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23027 case DW_OP_const4s
:
23028 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23032 case DW_OP_const8u
:
23033 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23038 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23044 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23049 stack
[stacki
+ 1] = stack
[stacki
];
23054 stack
[stacki
- 1] += stack
[stacki
];
23058 case DW_OP_plus_uconst
:
23059 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23065 stack
[stacki
- 1] -= stack
[stacki
];
23070 /* If we're not the last op, then we definitely can't encode
23071 this using GDB's address_class enum. This is valid for partial
23072 global symbols, although the variable's address will be bogus
23075 dwarf2_complex_location_expr_complaint ();
23078 case DW_OP_GNU_push_tls_address
:
23079 case DW_OP_form_tls_address
:
23080 /* The top of the stack has the offset from the beginning
23081 of the thread control block at which the variable is located. */
23082 /* Nothing should follow this operator, so the top of stack would
23084 /* This is valid for partial global symbols, but the variable's
23085 address will be bogus in the psymtab. Make it always at least
23086 non-zero to not look as a variable garbage collected by linker
23087 which have DW_OP_addr 0. */
23089 dwarf2_complex_location_expr_complaint ();
23093 case DW_OP_GNU_uninit
:
23097 case DW_OP_GNU_addr_index
:
23098 case DW_OP_GNU_const_index
:
23099 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23106 const char *name
= get_DW_OP_name (op
);
23109 complaint (_("unsupported stack op: '%s'"),
23112 complaint (_("unsupported stack op: '%02x'"),
23116 return (stack
[stacki
]);
23119 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23120 outside of the allocated space. Also enforce minimum>0. */
23121 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23123 complaint (_("location description stack overflow"));
23129 complaint (_("location description stack underflow"));
23133 return (stack
[stacki
]);
23136 /* memory allocation interface */
23138 static struct dwarf_block
*
23139 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23141 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23144 static struct die_info
*
23145 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23147 struct die_info
*die
;
23148 size_t size
= sizeof (struct die_info
);
23151 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23153 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23154 memset (die
, 0, sizeof (struct die_info
));
23159 /* Macro support. */
23161 static struct macro_source_file
*
23162 macro_start_file (struct dwarf2_cu
*cu
,
23163 int file
, int line
,
23164 struct macro_source_file
*current_file
,
23165 struct line_header
*lh
)
23167 /* File name relative to the compilation directory of this source file. */
23168 gdb::unique_xmalloc_ptr
<char> file_name
= lh
->file_file_name (file
);
23170 if (! current_file
)
23172 /* Note: We don't create a macro table for this compilation unit
23173 at all until we actually get a filename. */
23174 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
23176 /* If we have no current file, then this must be the start_file
23177 directive for the compilation unit's main source file. */
23178 current_file
= macro_set_main (macro_table
, file_name
.get ());
23179 macro_define_special (macro_table
);
23182 current_file
= macro_include (current_file
, line
, file_name
.get ());
23184 return current_file
;
23187 static const char *
23188 consume_improper_spaces (const char *p
, const char *body
)
23192 complaint (_("macro definition contains spaces "
23193 "in formal argument list:\n`%s'"),
23205 parse_macro_definition (struct macro_source_file
*file
, int line
,
23210 /* The body string takes one of two forms. For object-like macro
23211 definitions, it should be:
23213 <macro name> " " <definition>
23215 For function-like macro definitions, it should be:
23217 <macro name> "() " <definition>
23219 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23221 Spaces may appear only where explicitly indicated, and in the
23224 The Dwarf 2 spec says that an object-like macro's name is always
23225 followed by a space, but versions of GCC around March 2002 omit
23226 the space when the macro's definition is the empty string.
23228 The Dwarf 2 spec says that there should be no spaces between the
23229 formal arguments in a function-like macro's formal argument list,
23230 but versions of GCC around March 2002 include spaces after the
23234 /* Find the extent of the macro name. The macro name is terminated
23235 by either a space or null character (for an object-like macro) or
23236 an opening paren (for a function-like macro). */
23237 for (p
= body
; *p
; p
++)
23238 if (*p
== ' ' || *p
== '(')
23241 if (*p
== ' ' || *p
== '\0')
23243 /* It's an object-like macro. */
23244 int name_len
= p
- body
;
23245 std::string
name (body
, name_len
);
23246 const char *replacement
;
23249 replacement
= body
+ name_len
+ 1;
23252 dwarf2_macro_malformed_definition_complaint (body
);
23253 replacement
= body
+ name_len
;
23256 macro_define_object (file
, line
, name
.c_str (), replacement
);
23258 else if (*p
== '(')
23260 /* It's a function-like macro. */
23261 std::string
name (body
, p
- body
);
23264 char **argv
= XNEWVEC (char *, argv_size
);
23268 p
= consume_improper_spaces (p
, body
);
23270 /* Parse the formal argument list. */
23271 while (*p
&& *p
!= ')')
23273 /* Find the extent of the current argument name. */
23274 const char *arg_start
= p
;
23276 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23279 if (! *p
|| p
== arg_start
)
23280 dwarf2_macro_malformed_definition_complaint (body
);
23283 /* Make sure argv has room for the new argument. */
23284 if (argc
>= argv_size
)
23287 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23290 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23293 p
= consume_improper_spaces (p
, body
);
23295 /* Consume the comma, if present. */
23300 p
= consume_improper_spaces (p
, body
);
23309 /* Perfectly formed definition, no complaints. */
23310 macro_define_function (file
, line
, name
.c_str (),
23311 argc
, (const char **) argv
,
23313 else if (*p
== '\0')
23315 /* Complain, but do define it. */
23316 dwarf2_macro_malformed_definition_complaint (body
);
23317 macro_define_function (file
, line
, name
.c_str (),
23318 argc
, (const char **) argv
,
23322 /* Just complain. */
23323 dwarf2_macro_malformed_definition_complaint (body
);
23326 /* Just complain. */
23327 dwarf2_macro_malformed_definition_complaint (body
);
23332 for (i
= 0; i
< argc
; i
++)
23338 dwarf2_macro_malformed_definition_complaint (body
);
23341 /* Skip some bytes from BYTES according to the form given in FORM.
23342 Returns the new pointer. */
23344 static const gdb_byte
*
23345 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23346 enum dwarf_form form
,
23347 unsigned int offset_size
,
23348 struct dwarf2_section_info
*section
)
23350 unsigned int bytes_read
;
23354 case DW_FORM_data1
:
23359 case DW_FORM_data2
:
23363 case DW_FORM_data4
:
23367 case DW_FORM_data8
:
23371 case DW_FORM_data16
:
23375 case DW_FORM_string
:
23376 read_direct_string (abfd
, bytes
, &bytes_read
);
23377 bytes
+= bytes_read
;
23380 case DW_FORM_sec_offset
:
23382 case DW_FORM_GNU_strp_alt
:
23383 bytes
+= offset_size
;
23386 case DW_FORM_block
:
23387 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23388 bytes
+= bytes_read
;
23391 case DW_FORM_block1
:
23392 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23394 case DW_FORM_block2
:
23395 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23397 case DW_FORM_block4
:
23398 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23401 case DW_FORM_addrx
:
23402 case DW_FORM_sdata
:
23404 case DW_FORM_udata
:
23405 case DW_FORM_GNU_addr_index
:
23406 case DW_FORM_GNU_str_index
:
23407 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23410 dwarf2_section_buffer_overflow_complaint (section
);
23415 case DW_FORM_implicit_const
:
23420 complaint (_("invalid form 0x%x in `%s'"),
23421 form
, section
->get_name ());
23429 /* A helper for dwarf_decode_macros that handles skipping an unknown
23430 opcode. Returns an updated pointer to the macro data buffer; or,
23431 on error, issues a complaint and returns NULL. */
23433 static const gdb_byte
*
23434 skip_unknown_opcode (unsigned int opcode
,
23435 const gdb_byte
**opcode_definitions
,
23436 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23438 unsigned int offset_size
,
23439 struct dwarf2_section_info
*section
)
23441 unsigned int bytes_read
, i
;
23443 const gdb_byte
*defn
;
23445 if (opcode_definitions
[opcode
] == NULL
)
23447 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
23452 defn
= opcode_definitions
[opcode
];
23453 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
23454 defn
+= bytes_read
;
23456 for (i
= 0; i
< arg
; ++i
)
23458 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
23459 (enum dwarf_form
) defn
[i
], offset_size
,
23461 if (mac_ptr
== NULL
)
23463 /* skip_form_bytes already issued the complaint. */
23471 /* A helper function which parses the header of a macro section.
23472 If the macro section is the extended (for now called "GNU") type,
23473 then this updates *OFFSET_SIZE. Returns a pointer to just after
23474 the header, or issues a complaint and returns NULL on error. */
23476 static const gdb_byte
*
23477 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
23479 const gdb_byte
*mac_ptr
,
23480 unsigned int *offset_size
,
23481 int section_is_gnu
)
23483 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
23485 if (section_is_gnu
)
23487 unsigned int version
, flags
;
23489 version
= read_2_bytes (abfd
, mac_ptr
);
23490 if (version
!= 4 && version
!= 5)
23492 complaint (_("unrecognized version `%d' in .debug_macro section"),
23498 flags
= read_1_byte (abfd
, mac_ptr
);
23500 *offset_size
= (flags
& 1) ? 8 : 4;
23502 if ((flags
& 2) != 0)
23503 /* We don't need the line table offset. */
23504 mac_ptr
+= *offset_size
;
23506 /* Vendor opcode descriptions. */
23507 if ((flags
& 4) != 0)
23509 unsigned int i
, count
;
23511 count
= read_1_byte (abfd
, mac_ptr
);
23513 for (i
= 0; i
< count
; ++i
)
23515 unsigned int opcode
, bytes_read
;
23518 opcode
= read_1_byte (abfd
, mac_ptr
);
23520 opcode_definitions
[opcode
] = mac_ptr
;
23521 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23522 mac_ptr
+= bytes_read
;
23531 /* A helper for dwarf_decode_macros that handles the GNU extensions,
23532 including DW_MACRO_import. */
23535 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
23537 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23538 struct macro_source_file
*current_file
,
23539 struct line_header
*lh
,
23540 struct dwarf2_section_info
*section
,
23541 int section_is_gnu
, int section_is_dwz
,
23542 unsigned int offset_size
,
23543 htab_t include_hash
)
23545 struct dwarf2_per_objfile
*dwarf2_per_objfile
23546 = cu
->per_cu
->dwarf2_per_objfile
;
23547 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23548 enum dwarf_macro_record_type macinfo_type
;
23549 int at_commandline
;
23550 const gdb_byte
*opcode_definitions
[256];
23552 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23553 &offset_size
, section_is_gnu
);
23554 if (mac_ptr
== NULL
)
23556 /* We already issued a complaint. */
23560 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
23561 GDB is still reading the definitions from command line. First
23562 DW_MACINFO_start_file will need to be ignored as it was already executed
23563 to create CURRENT_FILE for the main source holding also the command line
23564 definitions. On first met DW_MACINFO_start_file this flag is reset to
23565 normally execute all the remaining DW_MACINFO_start_file macinfos. */
23567 at_commandline
= 1;
23571 /* Do we at least have room for a macinfo type byte? */
23572 if (mac_ptr
>= mac_end
)
23574 dwarf2_section_buffer_overflow_complaint (section
);
23578 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23581 /* Note that we rely on the fact that the corresponding GNU and
23582 DWARF constants are the same. */
23584 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23585 switch (macinfo_type
)
23587 /* A zero macinfo type indicates the end of the macro
23592 case DW_MACRO_define
:
23593 case DW_MACRO_undef
:
23594 case DW_MACRO_define_strp
:
23595 case DW_MACRO_undef_strp
:
23596 case DW_MACRO_define_sup
:
23597 case DW_MACRO_undef_sup
:
23599 unsigned int bytes_read
;
23604 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23605 mac_ptr
+= bytes_read
;
23607 if (macinfo_type
== DW_MACRO_define
23608 || macinfo_type
== DW_MACRO_undef
)
23610 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23611 mac_ptr
+= bytes_read
;
23615 LONGEST str_offset
;
23617 str_offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23618 mac_ptr
+= offset_size
;
23620 if (macinfo_type
== DW_MACRO_define_sup
23621 || macinfo_type
== DW_MACRO_undef_sup
23624 struct dwz_file
*dwz
23625 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
23627 body
= read_indirect_string_from_dwz (objfile
,
23631 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
23635 is_define
= (macinfo_type
== DW_MACRO_define
23636 || macinfo_type
== DW_MACRO_define_strp
23637 || macinfo_type
== DW_MACRO_define_sup
);
23638 if (! current_file
)
23640 /* DWARF violation as no main source is present. */
23641 complaint (_("debug info with no main source gives macro %s "
23643 is_define
? _("definition") : _("undefinition"),
23647 if ((line
== 0 && !at_commandline
)
23648 || (line
!= 0 && at_commandline
))
23649 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
23650 at_commandline
? _("command-line") : _("in-file"),
23651 is_define
? _("definition") : _("undefinition"),
23652 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
23656 /* Fedora's rpm-build's "debugedit" binary
23657 corrupted .debug_macro sections.
23660 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
23661 complaint (_("debug info gives %s invalid macro %s "
23662 "without body (corrupted?) at line %d "
23664 at_commandline
? _("command-line") : _("in-file"),
23665 is_define
? _("definition") : _("undefinition"),
23666 line
, current_file
->filename
);
23668 else if (is_define
)
23669 parse_macro_definition (current_file
, line
, body
);
23672 gdb_assert (macinfo_type
== DW_MACRO_undef
23673 || macinfo_type
== DW_MACRO_undef_strp
23674 || macinfo_type
== DW_MACRO_undef_sup
);
23675 macro_undef (current_file
, line
, body
);
23680 case DW_MACRO_start_file
:
23682 unsigned int bytes_read
;
23685 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23686 mac_ptr
+= bytes_read
;
23687 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23688 mac_ptr
+= bytes_read
;
23690 if ((line
== 0 && !at_commandline
)
23691 || (line
!= 0 && at_commandline
))
23692 complaint (_("debug info gives source %d included "
23693 "from %s at %s line %d"),
23694 file
, at_commandline
? _("command-line") : _("file"),
23695 line
== 0 ? _("zero") : _("non-zero"), line
);
23697 if (at_commandline
)
23699 /* This DW_MACRO_start_file was executed in the
23701 at_commandline
= 0;
23704 current_file
= macro_start_file (cu
, file
, line
, current_file
,
23709 case DW_MACRO_end_file
:
23710 if (! current_file
)
23711 complaint (_("macro debug info has an unmatched "
23712 "`close_file' directive"));
23715 current_file
= current_file
->included_by
;
23716 if (! current_file
)
23718 enum dwarf_macro_record_type next_type
;
23720 /* GCC circa March 2002 doesn't produce the zero
23721 type byte marking the end of the compilation
23722 unit. Complain if it's not there, but exit no
23725 /* Do we at least have room for a macinfo type byte? */
23726 if (mac_ptr
>= mac_end
)
23728 dwarf2_section_buffer_overflow_complaint (section
);
23732 /* We don't increment mac_ptr here, so this is just
23735 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
23737 if (next_type
!= 0)
23738 complaint (_("no terminating 0-type entry for "
23739 "macros in `.debug_macinfo' section"));
23746 case DW_MACRO_import
:
23747 case DW_MACRO_import_sup
:
23751 bfd
*include_bfd
= abfd
;
23752 struct dwarf2_section_info
*include_section
= section
;
23753 const gdb_byte
*include_mac_end
= mac_end
;
23754 int is_dwz
= section_is_dwz
;
23755 const gdb_byte
*new_mac_ptr
;
23757 offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23758 mac_ptr
+= offset_size
;
23760 if (macinfo_type
== DW_MACRO_import_sup
)
23762 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
23764 dwz
->macro
.read (objfile
);
23766 include_section
= &dwz
->macro
;
23767 include_bfd
= include_section
->get_bfd_owner ();
23768 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
23772 new_mac_ptr
= include_section
->buffer
+ offset
;
23773 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
23777 /* This has actually happened; see
23778 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
23779 complaint (_("recursive DW_MACRO_import in "
23780 ".debug_macro section"));
23784 *slot
= (void *) new_mac_ptr
;
23786 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
23787 include_mac_end
, current_file
, lh
,
23788 section
, section_is_gnu
, is_dwz
,
23789 offset_size
, include_hash
);
23791 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
23796 case DW_MACINFO_vendor_ext
:
23797 if (!section_is_gnu
)
23799 unsigned int bytes_read
;
23801 /* This reads the constant, but since we don't recognize
23802 any vendor extensions, we ignore it. */
23803 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23804 mac_ptr
+= bytes_read
;
23805 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23806 mac_ptr
+= bytes_read
;
23808 /* We don't recognize any vendor extensions. */
23814 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23815 mac_ptr
, mac_end
, abfd
, offset_size
,
23817 if (mac_ptr
== NULL
)
23822 } while (macinfo_type
!= 0);
23826 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23827 int section_is_gnu
)
23829 struct dwarf2_per_objfile
*dwarf2_per_objfile
23830 = cu
->per_cu
->dwarf2_per_objfile
;
23831 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23832 struct line_header
*lh
= cu
->line_header
;
23834 const gdb_byte
*mac_ptr
, *mac_end
;
23835 struct macro_source_file
*current_file
= 0;
23836 enum dwarf_macro_record_type macinfo_type
;
23837 unsigned int offset_size
= cu
->header
.offset_size
;
23838 const gdb_byte
*opcode_definitions
[256];
23840 struct dwarf2_section_info
*section
;
23841 const char *section_name
;
23843 if (cu
->dwo_unit
!= NULL
)
23845 if (section_is_gnu
)
23847 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23848 section_name
= ".debug_macro.dwo";
23852 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23853 section_name
= ".debug_macinfo.dwo";
23858 if (section_is_gnu
)
23860 section
= &dwarf2_per_objfile
->macro
;
23861 section_name
= ".debug_macro";
23865 section
= &dwarf2_per_objfile
->macinfo
;
23866 section_name
= ".debug_macinfo";
23870 section
->read (objfile
);
23871 if (section
->buffer
== NULL
)
23873 complaint (_("missing %s section"), section_name
);
23876 abfd
= section
->get_bfd_owner ();
23878 /* First pass: Find the name of the base filename.
23879 This filename is needed in order to process all macros whose definition
23880 (or undefinition) comes from the command line. These macros are defined
23881 before the first DW_MACINFO_start_file entry, and yet still need to be
23882 associated to the base file.
23884 To determine the base file name, we scan the macro definitions until we
23885 reach the first DW_MACINFO_start_file entry. We then initialize
23886 CURRENT_FILE accordingly so that any macro definition found before the
23887 first DW_MACINFO_start_file can still be associated to the base file. */
23889 mac_ptr
= section
->buffer
+ offset
;
23890 mac_end
= section
->buffer
+ section
->size
;
23892 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23893 &offset_size
, section_is_gnu
);
23894 if (mac_ptr
== NULL
)
23896 /* We already issued a complaint. */
23902 /* Do we at least have room for a macinfo type byte? */
23903 if (mac_ptr
>= mac_end
)
23905 /* Complaint is printed during the second pass as GDB will probably
23906 stop the first pass earlier upon finding
23907 DW_MACINFO_start_file. */
23911 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23914 /* Note that we rely on the fact that the corresponding GNU and
23915 DWARF constants are the same. */
23917 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23918 switch (macinfo_type
)
23920 /* A zero macinfo type indicates the end of the macro
23925 case DW_MACRO_define
:
23926 case DW_MACRO_undef
:
23927 /* Only skip the data by MAC_PTR. */
23929 unsigned int bytes_read
;
23931 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23932 mac_ptr
+= bytes_read
;
23933 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23934 mac_ptr
+= bytes_read
;
23938 case DW_MACRO_start_file
:
23940 unsigned int bytes_read
;
23943 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23944 mac_ptr
+= bytes_read
;
23945 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23946 mac_ptr
+= bytes_read
;
23948 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
23952 case DW_MACRO_end_file
:
23953 /* No data to skip by MAC_PTR. */
23956 case DW_MACRO_define_strp
:
23957 case DW_MACRO_undef_strp
:
23958 case DW_MACRO_define_sup
:
23959 case DW_MACRO_undef_sup
:
23961 unsigned int bytes_read
;
23963 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23964 mac_ptr
+= bytes_read
;
23965 mac_ptr
+= offset_size
;
23969 case DW_MACRO_import
:
23970 case DW_MACRO_import_sup
:
23971 /* Note that, according to the spec, a transparent include
23972 chain cannot call DW_MACRO_start_file. So, we can just
23973 skip this opcode. */
23974 mac_ptr
+= offset_size
;
23977 case DW_MACINFO_vendor_ext
:
23978 /* Only skip the data by MAC_PTR. */
23979 if (!section_is_gnu
)
23981 unsigned int bytes_read
;
23983 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23984 mac_ptr
+= bytes_read
;
23985 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23986 mac_ptr
+= bytes_read
;
23991 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23992 mac_ptr
, mac_end
, abfd
, offset_size
,
23994 if (mac_ptr
== NULL
)
23999 } while (macinfo_type
!= 0 && current_file
== NULL
);
24001 /* Second pass: Process all entries.
24003 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24004 command-line macro definitions/undefinitions. This flag is unset when we
24005 reach the first DW_MACINFO_start_file entry. */
24007 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24009 NULL
, xcalloc
, xfree
));
24010 mac_ptr
= section
->buffer
+ offset
;
24011 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24012 *slot
= (void *) mac_ptr
;
24013 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
24014 current_file
, lh
, section
,
24015 section_is_gnu
, 0, offset_size
,
24016 include_hash
.get ());
24019 /* Return the .debug_loc section to use for CU.
24020 For DWO files use .debug_loc.dwo. */
24022 static struct dwarf2_section_info
*
24023 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24025 struct dwarf2_per_objfile
*dwarf2_per_objfile
24026 = cu
->per_cu
->dwarf2_per_objfile
;
24030 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24032 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24034 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24035 : &dwarf2_per_objfile
->loc
);
24038 /* A helper function that fills in a dwarf2_loclist_baton. */
24041 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24042 struct dwarf2_loclist_baton
*baton
,
24043 const struct attribute
*attr
)
24045 struct dwarf2_per_objfile
*dwarf2_per_objfile
24046 = cu
->per_cu
->dwarf2_per_objfile
;
24047 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24049 section
->read (dwarf2_per_objfile
->objfile
);
24051 baton
->per_cu
= cu
->per_cu
;
24052 gdb_assert (baton
->per_cu
);
24053 /* We don't know how long the location list is, but make sure we
24054 don't run off the edge of the section. */
24055 baton
->size
= section
->size
- DW_UNSND (attr
);
24056 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24057 baton
->base_address
= cu
->base_address
;
24058 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24062 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24063 struct dwarf2_cu
*cu
, int is_block
)
24065 struct dwarf2_per_objfile
*dwarf2_per_objfile
24066 = cu
->per_cu
->dwarf2_per_objfile
;
24067 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24068 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24070 if (attr
->form_is_section_offset ()
24071 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24072 the section. If so, fall through to the complaint in the
24074 && DW_UNSND (attr
) < section
->get_size (objfile
))
24076 struct dwarf2_loclist_baton
*baton
;
24078 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24080 fill_in_loclist_baton (cu
, baton
, attr
);
24082 if (cu
->base_known
== 0)
24083 complaint (_("Location list used without "
24084 "specifying the CU base address."));
24086 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24087 ? dwarf2_loclist_block_index
24088 : dwarf2_loclist_index
);
24089 SYMBOL_LOCATION_BATON (sym
) = baton
;
24093 struct dwarf2_locexpr_baton
*baton
;
24095 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24096 baton
->per_cu
= cu
->per_cu
;
24097 gdb_assert (baton
->per_cu
);
24099 if (attr
->form_is_block ())
24101 /* Note that we're just copying the block's data pointer
24102 here, not the actual data. We're still pointing into the
24103 info_buffer for SYM's objfile; right now we never release
24104 that buffer, but when we do clean up properly this may
24106 baton
->size
= DW_BLOCK (attr
)->size
;
24107 baton
->data
= DW_BLOCK (attr
)->data
;
24111 dwarf2_invalid_attrib_class_complaint ("location description",
24112 sym
->natural_name ());
24116 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24117 ? dwarf2_locexpr_block_index
24118 : dwarf2_locexpr_index
);
24119 SYMBOL_LOCATION_BATON (sym
) = baton
;
24126 dwarf2_per_cu_data::objfile () const
24128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24130 /* Return the master objfile, so that we can report and look up the
24131 correct file containing this variable. */
24132 if (objfile
->separate_debug_objfile_backlink
)
24133 objfile
= objfile
->separate_debug_objfile_backlink
;
24138 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24139 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24140 CU_HEADERP first. */
24142 static const struct comp_unit_head
*
24143 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24144 const struct dwarf2_per_cu_data
*per_cu
)
24146 const gdb_byte
*info_ptr
;
24149 return &per_cu
->cu
->header
;
24151 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24153 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24154 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24155 rcuh_kind::COMPILE
);
24163 dwarf2_per_cu_data::addr_size () const
24165 struct comp_unit_head cu_header_local
;
24166 const struct comp_unit_head
*cu_headerp
;
24168 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24170 return cu_headerp
->addr_size
;
24176 dwarf2_per_cu_data::offset_size () const
24178 struct comp_unit_head cu_header_local
;
24179 const struct comp_unit_head
*cu_headerp
;
24181 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24183 return cu_headerp
->offset_size
;
24189 dwarf2_per_cu_data::ref_addr_size () const
24191 struct comp_unit_head cu_header_local
;
24192 const struct comp_unit_head
*cu_headerp
;
24194 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24196 if (cu_headerp
->version
== 2)
24197 return cu_headerp
->addr_size
;
24199 return cu_headerp
->offset_size
;
24205 dwarf2_per_cu_data::text_offset () const
24207 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24209 return objfile
->text_section_offset ();
24215 dwarf2_per_cu_data::addr_type () const
24217 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24218 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24219 struct type
*addr_type
= lookup_pointer_type (void_type
);
24220 int addr_size
= this->addr_size ();
24222 if (TYPE_LENGTH (addr_type
) == addr_size
)
24225 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
24229 /* Locate the .debug_info compilation unit from CU's objfile which contains
24230 the DIE at OFFSET. Raises an error on failure. */
24232 static struct dwarf2_per_cu_data
*
24233 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24234 unsigned int offset_in_dwz
,
24235 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24237 struct dwarf2_per_cu_data
*this_cu
;
24241 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24244 struct dwarf2_per_cu_data
*mid_cu
;
24245 int mid
= low
+ (high
- low
) / 2;
24247 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24248 if (mid_cu
->is_dwz
> offset_in_dwz
24249 || (mid_cu
->is_dwz
== offset_in_dwz
24250 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
24255 gdb_assert (low
== high
);
24256 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24257 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24259 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24260 error (_("Dwarf Error: could not find partial DIE containing "
24261 "offset %s [in module %s]"),
24262 sect_offset_str (sect_off
),
24263 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24265 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24267 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24271 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24272 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24273 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24274 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24279 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24281 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24282 : per_cu (per_cu_
),
24284 has_loclist (false),
24285 checked_producer (false),
24286 producer_is_gxx_lt_4_6 (false),
24287 producer_is_gcc_lt_4_3 (false),
24288 producer_is_icc (false),
24289 producer_is_icc_lt_14 (false),
24290 producer_is_codewarrior (false),
24291 processing_has_namespace_info (false)
24296 /* Destroy a dwarf2_cu. */
24298 dwarf2_cu::~dwarf2_cu ()
24303 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24306 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24307 enum language pretend_language
)
24309 struct attribute
*attr
;
24311 /* Set the language we're debugging. */
24312 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24313 if (attr
!= nullptr)
24314 set_cu_language (DW_UNSND (attr
), cu
);
24317 cu
->language
= pretend_language
;
24318 cu
->language_defn
= language_def (cu
->language
);
24321 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24324 /* Increase the age counter on each cached compilation unit, and free
24325 any that are too old. */
24328 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24330 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24332 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24333 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24334 while (per_cu
!= NULL
)
24336 per_cu
->cu
->last_used
++;
24337 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
24338 dwarf2_mark (per_cu
->cu
);
24339 per_cu
= per_cu
->cu
->read_in_chain
;
24342 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24343 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24344 while (per_cu
!= NULL
)
24346 struct dwarf2_per_cu_data
*next_cu
;
24348 next_cu
= per_cu
->cu
->read_in_chain
;
24350 if (!per_cu
->cu
->mark
)
24353 *last_chain
= next_cu
;
24356 last_chain
= &per_cu
->cu
->read_in_chain
;
24362 /* Remove a single compilation unit from the cache. */
24365 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
24367 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24368 struct dwarf2_per_objfile
*dwarf2_per_objfile
24369 = target_per_cu
->dwarf2_per_objfile
;
24371 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24372 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24373 while (per_cu
!= NULL
)
24375 struct dwarf2_per_cu_data
*next_cu
;
24377 next_cu
= per_cu
->cu
->read_in_chain
;
24379 if (per_cu
== target_per_cu
)
24383 *last_chain
= next_cu
;
24387 last_chain
= &per_cu
->cu
->read_in_chain
;
24393 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24394 We store these in a hash table separate from the DIEs, and preserve them
24395 when the DIEs are flushed out of cache.
24397 The CU "per_cu" pointer is needed because offset alone is not enough to
24398 uniquely identify the type. A file may have multiple .debug_types sections,
24399 or the type may come from a DWO file. Furthermore, while it's more logical
24400 to use per_cu->section+offset, with Fission the section with the data is in
24401 the DWO file but we don't know that section at the point we need it.
24402 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24403 because we can enter the lookup routine, get_die_type_at_offset, from
24404 outside this file, and thus won't necessarily have PER_CU->cu.
24405 Fortunately, PER_CU is stable for the life of the objfile. */
24407 struct dwarf2_per_cu_offset_and_type
24409 const struct dwarf2_per_cu_data
*per_cu
;
24410 sect_offset sect_off
;
24414 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24417 per_cu_offset_and_type_hash (const void *item
)
24419 const struct dwarf2_per_cu_offset_and_type
*ofs
24420 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24422 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24425 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24428 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24430 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24431 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24432 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24433 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24435 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24436 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24439 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24440 table if necessary. For convenience, return TYPE.
24442 The DIEs reading must have careful ordering to:
24443 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24444 reading current DIE.
24445 * Not trying to dereference contents of still incompletely read in types
24446 while reading in other DIEs.
24447 * Enable referencing still incompletely read in types just by a pointer to
24448 the type without accessing its fields.
24450 Therefore caller should follow these rules:
24451 * Try to fetch any prerequisite types we may need to build this DIE type
24452 before building the type and calling set_die_type.
24453 * After building type call set_die_type for current DIE as soon as
24454 possible before fetching more types to complete the current type.
24455 * Make the type as complete as possible before fetching more types. */
24457 static struct type
*
24458 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
24460 struct dwarf2_per_objfile
*dwarf2_per_objfile
24461 = cu
->per_cu
->dwarf2_per_objfile
;
24462 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24463 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24464 struct attribute
*attr
;
24465 struct dynamic_prop prop
;
24467 /* For Ada types, make sure that the gnat-specific data is always
24468 initialized (if not already set). There are a few types where
24469 we should not be doing so, because the type-specific area is
24470 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24471 where the type-specific area is used to store the floatformat).
24472 But this is not a problem, because the gnat-specific information
24473 is actually not needed for these types. */
24474 if (need_gnat_info (cu
)
24475 && TYPE_CODE (type
) != TYPE_CODE_FUNC
24476 && TYPE_CODE (type
) != TYPE_CODE_FLT
24477 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
24478 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
24479 && TYPE_CODE (type
) != TYPE_CODE_METHOD
24480 && !HAVE_GNAT_AUX_INFO (type
))
24481 INIT_GNAT_SPECIFIC (type
);
24483 /* Read DW_AT_allocated and set in type. */
24484 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24485 if (attr
!= NULL
&& attr
->form_is_block ())
24487 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24488 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24489 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
24491 else if (attr
!= NULL
)
24493 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
24494 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24495 sect_offset_str (die
->sect_off
));
24498 /* Read DW_AT_associated and set in type. */
24499 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24500 if (attr
!= NULL
&& attr
->form_is_block ())
24502 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24503 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24504 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
24506 else if (attr
!= NULL
)
24508 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
24509 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24510 sect_offset_str (die
->sect_off
));
24513 /* Read DW_AT_data_location and set in type. */
24514 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24515 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
24516 cu
->per_cu
->addr_type ()))
24517 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
24519 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24520 dwarf2_per_objfile
->die_type_hash
24521 = htab_up (htab_create_alloc (127,
24522 per_cu_offset_and_type_hash
,
24523 per_cu_offset_and_type_eq
,
24524 NULL
, xcalloc
, xfree
));
24526 ofs
.per_cu
= cu
->per_cu
;
24527 ofs
.sect_off
= die
->sect_off
;
24529 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24530 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24532 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24533 sect_offset_str (die
->sect_off
));
24534 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24535 struct dwarf2_per_cu_offset_and_type
);
24540 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24541 or return NULL if the die does not have a saved type. */
24543 static struct type
*
24544 get_die_type_at_offset (sect_offset sect_off
,
24545 struct dwarf2_per_cu_data
*per_cu
)
24547 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24548 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
24550 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24553 ofs
.per_cu
= per_cu
;
24554 ofs
.sect_off
= sect_off
;
24555 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24556 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
24563 /* Look up the type for DIE in CU in die_type_hash,
24564 or return NULL if DIE does not have a saved type. */
24566 static struct type
*
24567 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24569 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
24572 /* Add a dependence relationship from CU to REF_PER_CU. */
24575 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24576 struct dwarf2_per_cu_data
*ref_per_cu
)
24580 if (cu
->dependencies
== NULL
)
24582 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24583 NULL
, &cu
->comp_unit_obstack
,
24584 hashtab_obstack_allocate
,
24585 dummy_obstack_deallocate
);
24587 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24589 *slot
= ref_per_cu
;
24592 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24593 Set the mark field in every compilation unit in the
24594 cache that we must keep because we are keeping CU. */
24597 dwarf2_mark_helper (void **slot
, void *data
)
24599 struct dwarf2_per_cu_data
*per_cu
;
24601 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
24603 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24604 reading of the chain. As such dependencies remain valid it is not much
24605 useful to track and undo them during QUIT cleanups. */
24606 if (per_cu
->cu
== NULL
)
24609 if (per_cu
->cu
->mark
)
24611 per_cu
->cu
->mark
= true;
24613 if (per_cu
->cu
->dependencies
!= NULL
)
24614 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24619 /* Set the mark field in CU and in every other compilation unit in the
24620 cache that we must keep because we are keeping CU. */
24623 dwarf2_mark (struct dwarf2_cu
*cu
)
24628 if (cu
->dependencies
!= NULL
)
24629 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24633 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
24637 per_cu
->cu
->mark
= false;
24638 per_cu
= per_cu
->cu
->read_in_chain
;
24642 /* Trivial hash function for partial_die_info: the hash value of a DIE
24643 is its offset in .debug_info for this objfile. */
24646 partial_die_hash (const void *item
)
24648 const struct partial_die_info
*part_die
24649 = (const struct partial_die_info
*) item
;
24651 return to_underlying (part_die
->sect_off
);
24654 /* Trivial comparison function for partial_die_info structures: two DIEs
24655 are equal if they have the same offset. */
24658 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24660 const struct partial_die_info
*part_die_lhs
24661 = (const struct partial_die_info
*) item_lhs
;
24662 const struct partial_die_info
*part_die_rhs
24663 = (const struct partial_die_info
*) item_rhs
;
24665 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24668 struct cmd_list_element
*set_dwarf_cmdlist
;
24669 struct cmd_list_element
*show_dwarf_cmdlist
;
24672 set_dwarf_cmd (const char *args
, int from_tty
)
24674 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
24679 show_dwarf_cmd (const char *args
, int from_tty
)
24681 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
24685 show_check_physname (struct ui_file
*file
, int from_tty
,
24686 struct cmd_list_element
*c
, const char *value
)
24688 fprintf_filtered (file
,
24689 _("Whether to check \"physname\" is %s.\n"),
24693 void _initialize_dwarf2_read ();
24695 _initialize_dwarf2_read ()
24697 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24698 Set DWARF specific variables.\n\
24699 Configure DWARF variables such as the cache size."),
24700 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24701 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24703 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24704 Show DWARF specific variables.\n\
24705 Show DWARF variables such as the cache size."),
24706 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24707 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24709 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24710 &dwarf_max_cache_age
, _("\
24711 Set the upper bound on the age of cached DWARF compilation units."), _("\
24712 Show the upper bound on the age of cached DWARF compilation units."), _("\
24713 A higher limit means that cached compilation units will be stored\n\
24714 in memory longer, and more total memory will be used. Zero disables\n\
24715 caching, which can slow down startup."),
24717 show_dwarf_max_cache_age
,
24718 &set_dwarf_cmdlist
,
24719 &show_dwarf_cmdlist
);
24721 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24722 Set debugging of the DWARF reader."), _("\
24723 Show debugging of the DWARF reader."), _("\
24724 When enabled (non-zero), debugging messages are printed during DWARF\n\
24725 reading and symtab expansion. A value of 1 (one) provides basic\n\
24726 information. A value greater than 1 provides more verbose information."),
24729 &setdebuglist
, &showdebuglist
);
24731 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24732 Set debugging of the DWARF DIE reader."), _("\
24733 Show debugging of the DWARF DIE reader."), _("\
24734 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24735 The value is the maximum depth to print."),
24738 &setdebuglist
, &showdebuglist
);
24740 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24741 Set debugging of the dwarf line reader."), _("\
24742 Show debugging of the dwarf line reader."), _("\
24743 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24744 A value of 1 (one) provides basic information.\n\
24745 A value greater than 1 provides more verbose information."),
24748 &setdebuglist
, &showdebuglist
);
24750 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24751 Set cross-checking of \"physname\" code against demangler."), _("\
24752 Show cross-checking of \"physname\" code against demangler."), _("\
24753 When enabled, GDB's internal \"physname\" code is checked against\n\
24755 NULL
, show_check_physname
,
24756 &setdebuglist
, &showdebuglist
);
24758 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24759 no_class
, &use_deprecated_index_sections
, _("\
24760 Set whether to use deprecated gdb_index sections."), _("\
24761 Show whether to use deprecated gdb_index sections."), _("\
24762 When enabled, deprecated .gdb_index sections are used anyway.\n\
24763 Normally they are ignored either because of a missing feature or\n\
24764 performance issue.\n\
24765 Warning: This option must be enabled before gdb reads the file."),
24768 &setlist
, &showlist
);
24770 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24771 &dwarf2_locexpr_funcs
);
24772 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24773 &dwarf2_loclist_funcs
);
24775 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24776 &dwarf2_block_frame_base_locexpr_funcs
);
24777 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24778 &dwarf2_block_frame_base_loclist_funcs
);
24781 selftests::register_test ("dw2_expand_symtabs_matching",
24782 selftests::dw2_expand_symtabs_matching::run_test
);