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
,
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);
891 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
893 const gdb_byte
*info_ptr
= nullptr;
894 struct die_info
*comp_unit_die
= nullptr;
895 bool dummy_p
= false;
897 /* Release the new CU, putting it on the chain. This cannot be done
902 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
903 int use_existing_cu
);
905 struct dwarf2_per_cu_data
*m_this_cu
;
906 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
908 /* The ordinary abbreviation table. */
909 abbrev_table_up m_abbrev_table_holder
;
911 /* The DWO abbreviation table. */
912 abbrev_table_up m_dwo_abbrev_table
;
915 /* When we construct a partial symbol table entry we only
916 need this much information. */
917 struct partial_die_info
: public allocate_on_obstack
919 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
921 /* Disable assign but still keep copy ctor, which is needed
922 load_partial_dies. */
923 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
925 /* Adjust the partial die before generating a symbol for it. This
926 function may set the is_external flag or change the DIE's
928 void fixup (struct dwarf2_cu
*cu
);
930 /* Read a minimal amount of information into the minimal die
932 const gdb_byte
*read (const struct die_reader_specs
*reader
,
933 const struct abbrev_info
&abbrev
,
934 const gdb_byte
*info_ptr
);
936 /* Offset of this DIE. */
937 const sect_offset sect_off
;
939 /* DWARF-2 tag for this DIE. */
940 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
942 /* Assorted flags describing the data found in this DIE. */
943 const unsigned int has_children
: 1;
945 unsigned int is_external
: 1;
946 unsigned int is_declaration
: 1;
947 unsigned int has_type
: 1;
948 unsigned int has_specification
: 1;
949 unsigned int has_pc_info
: 1;
950 unsigned int may_be_inlined
: 1;
952 /* This DIE has been marked DW_AT_main_subprogram. */
953 unsigned int main_subprogram
: 1;
955 /* Flag set if the SCOPE field of this structure has been
957 unsigned int scope_set
: 1;
959 /* Flag set if the DIE has a byte_size attribute. */
960 unsigned int has_byte_size
: 1;
962 /* Flag set if the DIE has a DW_AT_const_value attribute. */
963 unsigned int has_const_value
: 1;
965 /* Flag set if any of the DIE's children are template arguments. */
966 unsigned int has_template_arguments
: 1;
968 /* Flag set if fixup has been called on this die. */
969 unsigned int fixup_called
: 1;
971 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
972 unsigned int is_dwz
: 1;
974 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
975 unsigned int spec_is_dwz
: 1;
977 /* The name of this DIE. Normally the value of DW_AT_name, but
978 sometimes a default name for unnamed DIEs. */
979 const char *name
= nullptr;
981 /* The linkage name, if present. */
982 const char *linkage_name
= nullptr;
984 /* The scope to prepend to our children. This is generally
985 allocated on the comp_unit_obstack, so will disappear
986 when this compilation unit leaves the cache. */
987 const char *scope
= nullptr;
989 /* Some data associated with the partial DIE. The tag determines
990 which field is live. */
993 /* The location description associated with this DIE, if any. */
994 struct dwarf_block
*locdesc
;
995 /* The offset of an import, for DW_TAG_imported_unit. */
996 sect_offset sect_off
;
999 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1000 CORE_ADDR lowpc
= 0;
1001 CORE_ADDR highpc
= 0;
1003 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1004 DW_AT_sibling, if any. */
1005 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1006 could return DW_AT_sibling values to its caller load_partial_dies. */
1007 const gdb_byte
*sibling
= nullptr;
1009 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1010 DW_AT_specification (or DW_AT_abstract_origin or
1011 DW_AT_extension). */
1012 sect_offset spec_offset
{};
1014 /* Pointers to this DIE's parent, first child, and next sibling,
1016 struct partial_die_info
*die_parent
= nullptr;
1017 struct partial_die_info
*die_child
= nullptr;
1018 struct partial_die_info
*die_sibling
= nullptr;
1020 friend struct partial_die_info
*
1021 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1024 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1025 partial_die_info (sect_offset sect_off
)
1026 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1030 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1032 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1037 has_specification
= 0;
1040 main_subprogram
= 0;
1043 has_const_value
= 0;
1044 has_template_arguments
= 0;
1051 /* This data structure holds a complete die structure. */
1054 /* DWARF-2 tag for this DIE. */
1055 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1057 /* Number of attributes */
1058 unsigned char num_attrs
;
1060 /* True if we're presently building the full type name for the
1061 type derived from this DIE. */
1062 unsigned char building_fullname
: 1;
1064 /* True if this die is in process. PR 16581. */
1065 unsigned char in_process
: 1;
1067 /* True if this DIE has children. */
1068 unsigned char has_children
: 1;
1071 unsigned int abbrev
;
1073 /* Offset in .debug_info or .debug_types section. */
1074 sect_offset sect_off
;
1076 /* The dies in a compilation unit form an n-ary tree. PARENT
1077 points to this die's parent; CHILD points to the first child of
1078 this node; and all the children of a given node are chained
1079 together via their SIBLING fields. */
1080 struct die_info
*child
; /* Its first child, if any. */
1081 struct die_info
*sibling
; /* Its next sibling, if any. */
1082 struct die_info
*parent
; /* Its parent, if any. */
1084 /* An array of attributes, with NUM_ATTRS elements. There may be
1085 zero, but it's not common and zero-sized arrays are not
1086 sufficiently portable C. */
1087 struct attribute attrs
[1];
1090 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1091 but this would require a corresponding change in unpack_field_as_long
1093 static int bits_per_byte
= 8;
1095 /* When reading a variant or variant part, we track a bit more
1096 information about the field, and store it in an object of this
1099 struct variant_field
1101 /* If we see a DW_TAG_variant, then this will be the discriminant
1103 ULONGEST discriminant_value
;
1104 /* If we see a DW_TAG_variant, then this will be set if this is the
1106 bool default_branch
;
1107 /* While reading a DW_TAG_variant_part, this will be set if this
1108 field is the discriminant. */
1109 bool is_discriminant
;
1114 int accessibility
= 0;
1116 /* Extra information to describe a variant or variant part. */
1117 struct variant_field variant
{};
1118 struct field field
{};
1123 const char *name
= nullptr;
1124 std::vector
<struct fn_field
> fnfields
;
1127 /* The routines that read and process dies for a C struct or C++ class
1128 pass lists of data member fields and lists of member function fields
1129 in an instance of a field_info structure, as defined below. */
1132 /* List of data member and baseclasses fields. */
1133 std::vector
<struct nextfield
> fields
;
1134 std::vector
<struct nextfield
> baseclasses
;
1136 /* Number of fields (including baseclasses). */
1139 /* Set if the accessibility of one of the fields is not public. */
1140 int non_public_fields
= 0;
1142 /* Member function fieldlist array, contains name of possibly overloaded
1143 member function, number of overloaded member functions and a pointer
1144 to the head of the member function field chain. */
1145 std::vector
<struct fnfieldlist
> fnfieldlists
;
1147 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1148 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1149 std::vector
<struct decl_field
> typedef_field_list
;
1151 /* Nested types defined by this class and the number of elements in this
1153 std::vector
<struct decl_field
> nested_types_list
;
1156 /* Loaded secondary compilation units are kept in memory until they
1157 have not been referenced for the processing of this many
1158 compilation units. Set this to zero to disable caching. Cache
1159 sizes of up to at least twenty will improve startup time for
1160 typical inter-CU-reference binaries, at an obvious memory cost. */
1161 static int dwarf_max_cache_age
= 5;
1163 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1164 struct cmd_list_element
*c
, const char *value
)
1166 fprintf_filtered (file
, _("The upper bound on the age of cached "
1167 "DWARF compilation units is %s.\n"),
1171 /* local function prototypes */
1173 static void dwarf2_find_base_address (struct die_info
*die
,
1174 struct dwarf2_cu
*cu
);
1176 static dwarf2_psymtab
*create_partial_symtab
1177 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1179 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1180 const gdb_byte
*info_ptr
,
1181 struct die_info
*type_unit_die
);
1183 static void dwarf2_build_psymtabs_hard
1184 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1186 static void scan_partial_symbols (struct partial_die_info
*,
1187 CORE_ADDR
*, CORE_ADDR
*,
1188 int, struct dwarf2_cu
*);
1190 static void add_partial_symbol (struct partial_die_info
*,
1191 struct dwarf2_cu
*);
1193 static void add_partial_namespace (struct partial_die_info
*pdi
,
1194 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1195 int set_addrmap
, struct dwarf2_cu
*cu
);
1197 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1198 CORE_ADDR
*highpc
, int set_addrmap
,
1199 struct dwarf2_cu
*cu
);
1201 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1202 struct dwarf2_cu
*cu
);
1204 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1205 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1206 int need_pc
, struct dwarf2_cu
*cu
);
1208 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1210 static struct partial_die_info
*load_partial_dies
1211 (const struct die_reader_specs
*, const gdb_byte
*, int);
1213 /* A pair of partial_die_info and compilation unit. */
1214 struct cu_partial_die_info
1216 /* The compilation unit of the partial_die_info. */
1217 struct dwarf2_cu
*cu
;
1218 /* A partial_die_info. */
1219 struct partial_die_info
*pdi
;
1221 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1227 cu_partial_die_info () = delete;
1230 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1231 struct dwarf2_cu
*);
1233 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1234 struct attribute
*, struct attr_abbrev
*,
1235 const gdb_byte
*, bool *need_reprocess
);
1237 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1238 struct attribute
*attr
);
1240 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1242 static LONGEST read_checked_initial_length_and_offset
1243 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1244 unsigned int *, unsigned int *);
1246 static sect_offset read_abbrev_offset
1247 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1248 struct dwarf2_section_info
*, sect_offset
);
1250 static const char *read_indirect_string
1251 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1252 const struct comp_unit_head
*, unsigned int *);
1254 static const char *read_indirect_line_string
1255 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1256 const struct comp_unit_head
*, unsigned int *);
1258 static const char *read_indirect_string_at_offset
1259 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1260 LONGEST str_offset
);
1262 static const char *read_indirect_string_from_dwz
1263 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1265 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1269 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1270 ULONGEST str_index
);
1272 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1273 ULONGEST str_index
);
1275 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1277 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1278 struct dwarf2_cu
*);
1280 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1283 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1284 struct dwarf2_cu
*cu
);
1286 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1288 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1289 struct dwarf2_cu
*cu
);
1291 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1293 static struct die_info
*die_specification (struct die_info
*die
,
1294 struct dwarf2_cu
**);
1296 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1297 struct dwarf2_cu
*cu
);
1299 static void dwarf_decode_lines (struct line_header
*, const char *,
1300 struct dwarf2_cu
*, dwarf2_psymtab
*,
1301 CORE_ADDR
, int decode_mapping
);
1303 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1306 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1307 struct dwarf2_cu
*, struct symbol
* = NULL
);
1309 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1310 struct dwarf2_cu
*);
1312 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1315 struct obstack
*obstack
,
1316 struct dwarf2_cu
*cu
, LONGEST
*value
,
1317 const gdb_byte
**bytes
,
1318 struct dwarf2_locexpr_baton
**baton
);
1320 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1322 static int need_gnat_info (struct dwarf2_cu
*);
1324 static struct type
*die_descriptive_type (struct die_info
*,
1325 struct dwarf2_cu
*);
1327 static void set_descriptive_type (struct type
*, struct die_info
*,
1328 struct dwarf2_cu
*);
1330 static struct type
*die_containing_type (struct die_info
*,
1331 struct dwarf2_cu
*);
1333 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1334 struct dwarf2_cu
*);
1336 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1338 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1340 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1342 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1343 const char *suffix
, int physname
,
1344 struct dwarf2_cu
*cu
);
1346 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1348 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1350 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1352 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1354 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1356 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1358 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1359 struct dwarf2_cu
*, dwarf2_psymtab
*);
1361 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1362 values. Keep the items ordered with increasing constraints compliance. */
1365 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1366 PC_BOUNDS_NOT_PRESENT
,
1368 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1369 were present but they do not form a valid range of PC addresses. */
1372 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1375 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1379 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1380 CORE_ADDR
*, CORE_ADDR
*,
1384 static void get_scope_pc_bounds (struct die_info
*,
1385 CORE_ADDR
*, CORE_ADDR
*,
1386 struct dwarf2_cu
*);
1388 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1389 CORE_ADDR
, struct dwarf2_cu
*);
1391 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1392 struct dwarf2_cu
*);
1394 static void dwarf2_attach_fields_to_type (struct field_info
*,
1395 struct type
*, struct dwarf2_cu
*);
1397 static void dwarf2_add_member_fn (struct field_info
*,
1398 struct die_info
*, struct type
*,
1399 struct dwarf2_cu
*);
1401 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1403 struct dwarf2_cu
*);
1405 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1407 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1409 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1411 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1413 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1415 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1417 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1419 static struct type
*read_module_type (struct die_info
*die
,
1420 struct dwarf2_cu
*cu
);
1422 static const char *namespace_name (struct die_info
*die
,
1423 int *is_anonymous
, struct dwarf2_cu
*);
1425 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1427 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1429 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1430 struct dwarf2_cu
*);
1432 static struct die_info
*read_die_and_siblings_1
1433 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1436 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1437 const gdb_byte
*info_ptr
,
1438 const gdb_byte
**new_info_ptr
,
1439 struct die_info
*parent
);
1441 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1442 struct die_info
**, const gdb_byte
*,
1445 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1446 struct die_info
**, const gdb_byte
*);
1448 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1450 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1453 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1455 static const char *dwarf2_full_name (const char *name
,
1456 struct die_info
*die
,
1457 struct dwarf2_cu
*cu
);
1459 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1460 struct dwarf2_cu
*cu
);
1462 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1463 struct dwarf2_cu
**);
1465 static const char *dwarf_tag_name (unsigned int);
1467 static const char *dwarf_attr_name (unsigned int);
1469 static const char *dwarf_form_name (unsigned int);
1471 static const char *dwarf_bool_name (unsigned int);
1473 static const char *dwarf_type_encoding_name (unsigned int);
1475 static struct die_info
*sibling_die (struct die_info
*);
1477 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1479 static void dump_die_for_error (struct die_info
*);
1481 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1484 /*static*/ void dump_die (struct die_info
*, int max_level
);
1486 static void store_in_ref_table (struct die_info
*,
1487 struct dwarf2_cu
*);
1489 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1491 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1493 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1494 const struct attribute
*,
1495 struct dwarf2_cu
**);
1497 static struct die_info
*follow_die_ref (struct die_info
*,
1498 const struct attribute
*,
1499 struct dwarf2_cu
**);
1501 static struct die_info
*follow_die_sig (struct die_info
*,
1502 const struct attribute
*,
1503 struct dwarf2_cu
**);
1505 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1506 struct dwarf2_cu
*);
1508 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1509 const struct attribute
*,
1510 struct dwarf2_cu
*);
1512 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1514 static void read_signatured_type (struct signatured_type
*);
1516 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1517 struct die_info
*die
, struct dwarf2_cu
*cu
,
1518 struct dynamic_prop
*prop
, struct type
*type
);
1520 /* memory allocation interface */
1522 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1524 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1526 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1528 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1529 struct dwarf2_loclist_baton
*baton
,
1530 const struct attribute
*attr
);
1532 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1534 struct dwarf2_cu
*cu
,
1537 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1538 const gdb_byte
*info_ptr
,
1539 struct abbrev_info
*abbrev
);
1541 static hashval_t
partial_die_hash (const void *item
);
1543 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1545 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1546 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1547 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1549 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1550 struct die_info
*comp_unit_die
,
1551 enum language pretend_language
);
1553 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1555 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1557 static struct type
*set_die_type (struct die_info
*, struct type
*,
1558 struct dwarf2_cu
*);
1560 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1562 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1564 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1567 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1570 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1573 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1574 struct dwarf2_per_cu_data
*);
1576 static void dwarf2_mark (struct dwarf2_cu
*);
1578 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1580 static struct type
*get_die_type_at_offset (sect_offset
,
1581 struct dwarf2_per_cu_data
*);
1583 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1585 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1586 enum language pretend_language
);
1588 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1590 /* Class, the destructor of which frees all allocated queue entries. This
1591 will only have work to do if an error was thrown while processing the
1592 dwarf. If no error was thrown then the queue entries should have all
1593 been processed, and freed, as we went along. */
1595 class dwarf2_queue_guard
1598 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1599 : m_per_objfile (per_objfile
)
1603 /* Free any entries remaining on the queue. There should only be
1604 entries left if we hit an error while processing the dwarf. */
1605 ~dwarf2_queue_guard ()
1607 /* Ensure that no memory is allocated by the queue. */
1608 std::queue
<dwarf2_queue_item
> empty
;
1609 std::swap (m_per_objfile
->queue
, empty
);
1612 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1615 dwarf2_per_objfile
*m_per_objfile
;
1618 dwarf2_queue_item::~dwarf2_queue_item ()
1620 /* Anything still marked queued is likely to be in an
1621 inconsistent state, so discard it. */
1624 if (per_cu
->cu
!= NULL
)
1625 free_one_cached_comp_unit (per_cu
);
1630 /* The return type of find_file_and_directory. Note, the enclosed
1631 string pointers are only valid while this object is valid. */
1633 struct file_and_directory
1635 /* The filename. This is never NULL. */
1638 /* The compilation directory. NULL if not known. If we needed to
1639 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1640 points directly to the DW_AT_comp_dir string attribute owned by
1641 the obstack that owns the DIE. */
1642 const char *comp_dir
;
1644 /* If we needed to build a new string for comp_dir, this is what
1645 owns the storage. */
1646 std::string comp_dir_storage
;
1649 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1650 struct dwarf2_cu
*cu
);
1652 static htab_up
allocate_signatured_type_table (struct objfile
*objfile
);
1654 static htab_up
allocate_dwo_unit_table (struct objfile
*objfile
);
1656 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1657 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1658 struct dwp_file
*dwp_file
, const char *comp_dir
,
1659 ULONGEST signature
, int is_debug_types
);
1661 static struct dwp_file
*get_dwp_file
1662 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1664 static struct dwo_unit
*lookup_dwo_comp_unit
1665 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1667 static struct dwo_unit
*lookup_dwo_type_unit
1668 (struct signatured_type
*, const char *, const char *);
1670 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1672 /* A unique pointer to a dwo_file. */
1674 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1676 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1678 static void check_producer (struct dwarf2_cu
*cu
);
1680 static void free_line_header_voidp (void *arg
);
1682 /* Various complaints about symbol reading that don't abort the process. */
1685 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1687 complaint (_("statement list doesn't fit in .debug_line section"));
1691 dwarf2_debug_line_missing_file_complaint (void)
1693 complaint (_(".debug_line section has line data without a file"));
1697 dwarf2_debug_line_missing_end_sequence_complaint (void)
1699 complaint (_(".debug_line section has line "
1700 "program sequence without an end"));
1704 dwarf2_complex_location_expr_complaint (void)
1706 complaint (_("location expression too complex"));
1710 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1713 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1718 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1720 complaint (_("debug info runs off end of %s section"
1722 section
->get_name (),
1723 section
->get_file_name ());
1727 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1729 complaint (_("macro debug info contains a "
1730 "malformed macro definition:\n`%s'"),
1735 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1737 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1741 /* Hash function for line_header_hash. */
1744 line_header_hash (const struct line_header
*ofs
)
1746 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1749 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1752 line_header_hash_voidp (const void *item
)
1754 const struct line_header
*ofs
= (const struct line_header
*) item
;
1756 return line_header_hash (ofs
);
1759 /* Equality function for line_header_hash. */
1762 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1764 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1765 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1767 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1768 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1773 /* See declaration. */
1775 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1776 const dwarf2_debug_sections
*names
,
1778 : objfile (objfile_
),
1779 can_copy (can_copy_
)
1782 names
= &dwarf2_elf_names
;
1784 bfd
*obfd
= objfile
->obfd
;
1786 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1787 locate_sections (obfd
, sec
, *names
);
1790 dwarf2_per_objfile::~dwarf2_per_objfile ()
1792 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1793 free_cached_comp_units ();
1795 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1796 per_cu
->imported_symtabs_free ();
1798 for (signatured_type
*sig_type
: all_type_units
)
1799 sig_type
->per_cu
.imported_symtabs_free ();
1801 /* Everything else should be on the objfile obstack. */
1804 /* See declaration. */
1807 dwarf2_per_objfile::free_cached_comp_units ()
1809 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1810 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1811 while (per_cu
!= NULL
)
1813 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1816 *last_chain
= next_cu
;
1821 /* A helper class that calls free_cached_comp_units on
1824 class free_cached_comp_units
1828 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1829 : m_per_objfile (per_objfile
)
1833 ~free_cached_comp_units ()
1835 m_per_objfile
->free_cached_comp_units ();
1838 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1842 dwarf2_per_objfile
*m_per_objfile
;
1845 /* Try to locate the sections we need for DWARF 2 debugging
1846 information and return true if we have enough to do something.
1847 NAMES points to the dwarf2 section names, or is NULL if the standard
1848 ELF names are used. CAN_COPY is true for formats where symbol
1849 interposition is possible and so symbol values must follow copy
1850 relocation rules. */
1853 dwarf2_has_info (struct objfile
*objfile
,
1854 const struct dwarf2_debug_sections
*names
,
1857 if (objfile
->flags
& OBJF_READNEVER
)
1860 struct dwarf2_per_objfile
*dwarf2_per_objfile
1861 = get_dwarf2_per_objfile (objfile
);
1863 if (dwarf2_per_objfile
== NULL
)
1864 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1868 return (!dwarf2_per_objfile
->info
.is_virtual
1869 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1870 && !dwarf2_per_objfile
->abbrev
.is_virtual
1871 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1874 /* When loading sections, we look either for uncompressed section or for
1875 compressed section names. */
1878 section_is_p (const char *section_name
,
1879 const struct dwarf2_section_names
*names
)
1881 if (names
->normal
!= NULL
1882 && strcmp (section_name
, names
->normal
) == 0)
1884 if (names
->compressed
!= NULL
1885 && strcmp (section_name
, names
->compressed
) == 0)
1890 /* See declaration. */
1893 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1894 const dwarf2_debug_sections
&names
)
1896 flagword aflag
= bfd_section_flags (sectp
);
1898 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1901 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1902 > bfd_get_file_size (abfd
))
1904 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1905 warning (_("Discarding section %s which has a section size (%s"
1906 ") larger than the file size [in module %s]"),
1907 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1908 bfd_get_filename (abfd
));
1910 else if (section_is_p (sectp
->name
, &names
.info
))
1912 this->info
.s
.section
= sectp
;
1913 this->info
.size
= bfd_section_size (sectp
);
1915 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1917 this->abbrev
.s
.section
= sectp
;
1918 this->abbrev
.size
= bfd_section_size (sectp
);
1920 else if (section_is_p (sectp
->name
, &names
.line
))
1922 this->line
.s
.section
= sectp
;
1923 this->line
.size
= bfd_section_size (sectp
);
1925 else if (section_is_p (sectp
->name
, &names
.loc
))
1927 this->loc
.s
.section
= sectp
;
1928 this->loc
.size
= bfd_section_size (sectp
);
1930 else if (section_is_p (sectp
->name
, &names
.loclists
))
1932 this->loclists
.s
.section
= sectp
;
1933 this->loclists
.size
= bfd_section_size (sectp
);
1935 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1937 this->macinfo
.s
.section
= sectp
;
1938 this->macinfo
.size
= bfd_section_size (sectp
);
1940 else if (section_is_p (sectp
->name
, &names
.macro
))
1942 this->macro
.s
.section
= sectp
;
1943 this->macro
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.str
))
1947 this->str
.s
.section
= sectp
;
1948 this->str
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1952 this->str_offsets
.s
.section
= sectp
;
1953 this->str_offsets
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.line_str
))
1957 this->line_str
.s
.section
= sectp
;
1958 this->line_str
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.addr
))
1962 this->addr
.s
.section
= sectp
;
1963 this->addr
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.frame
))
1967 this->frame
.s
.section
= sectp
;
1968 this->frame
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1972 this->eh_frame
.s
.section
= sectp
;
1973 this->eh_frame
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.ranges
))
1977 this->ranges
.s
.section
= sectp
;
1978 this->ranges
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1982 this->rnglists
.s
.section
= sectp
;
1983 this->rnglists
.size
= bfd_section_size (sectp
);
1985 else if (section_is_p (sectp
->name
, &names
.types
))
1987 struct dwarf2_section_info type_section
;
1989 memset (&type_section
, 0, sizeof (type_section
));
1990 type_section
.s
.section
= sectp
;
1991 type_section
.size
= bfd_section_size (sectp
);
1993 this->types
.push_back (type_section
);
1995 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1997 this->gdb_index
.s
.section
= sectp
;
1998 this->gdb_index
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2002 this->debug_names
.s
.section
= sectp
;
2003 this->debug_names
.size
= bfd_section_size (sectp
);
2005 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2007 this->debug_aranges
.s
.section
= sectp
;
2008 this->debug_aranges
.size
= bfd_section_size (sectp
);
2011 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2012 && bfd_section_vma (sectp
) == 0)
2013 this->has_section_at_zero
= true;
2016 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2020 dwarf2_get_section_info (struct objfile
*objfile
,
2021 enum dwarf2_section_enum sect
,
2022 asection
**sectp
, const gdb_byte
**bufp
,
2023 bfd_size_type
*sizep
)
2025 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2026 struct dwarf2_section_info
*info
;
2028 /* We may see an objfile without any DWARF, in which case we just
2039 case DWARF2_DEBUG_FRAME
:
2040 info
= &data
->frame
;
2042 case DWARF2_EH_FRAME
:
2043 info
= &data
->eh_frame
;
2046 gdb_assert_not_reached ("unexpected section");
2049 info
->read (objfile
);
2051 *sectp
= info
->get_bfd_section ();
2052 *bufp
= info
->buffer
;
2053 *sizep
= info
->size
;
2056 /* A helper function to find the sections for a .dwz file. */
2059 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2061 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2063 /* Note that we only support the standard ELF names, because .dwz
2064 is ELF-only (at the time of writing). */
2065 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2067 dwz_file
->abbrev
.s
.section
= sectp
;
2068 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2070 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2072 dwz_file
->info
.s
.section
= sectp
;
2073 dwz_file
->info
.size
= bfd_section_size (sectp
);
2075 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2077 dwz_file
->str
.s
.section
= sectp
;
2078 dwz_file
->str
.size
= bfd_section_size (sectp
);
2080 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2082 dwz_file
->line
.s
.section
= sectp
;
2083 dwz_file
->line
.size
= bfd_section_size (sectp
);
2085 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2087 dwz_file
->macro
.s
.section
= sectp
;
2088 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2090 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2092 dwz_file
->gdb_index
.s
.section
= sectp
;
2093 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2095 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2097 dwz_file
->debug_names
.s
.section
= sectp
;
2098 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2102 /* See dwarf2read.h. */
2105 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2107 const char *filename
;
2108 bfd_size_type buildid_len_arg
;
2112 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2113 return dwarf2_per_objfile
->dwz_file
.get ();
2115 bfd_set_error (bfd_error_no_error
);
2116 gdb::unique_xmalloc_ptr
<char> data
2117 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2118 &buildid_len_arg
, &buildid
));
2121 if (bfd_get_error () == bfd_error_no_error
)
2123 error (_("could not read '.gnu_debugaltlink' section: %s"),
2124 bfd_errmsg (bfd_get_error ()));
2127 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2129 buildid_len
= (size_t) buildid_len_arg
;
2131 filename
= data
.get ();
2133 std::string abs_storage
;
2134 if (!IS_ABSOLUTE_PATH (filename
))
2136 gdb::unique_xmalloc_ptr
<char> abs
2137 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2139 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2140 filename
= abs_storage
.c_str ();
2143 /* First try the file name given in the section. If that doesn't
2144 work, try to use the build-id instead. */
2145 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2146 if (dwz_bfd
!= NULL
)
2148 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2149 dwz_bfd
.reset (nullptr);
2152 if (dwz_bfd
== NULL
)
2153 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2155 if (dwz_bfd
== NULL
)
2156 error (_("could not find '.gnu_debugaltlink' file for %s"),
2157 objfile_name (dwarf2_per_objfile
->objfile
));
2159 std::unique_ptr
<struct dwz_file
> result
2160 (new struct dwz_file (std::move (dwz_bfd
)));
2162 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2165 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2166 result
->dwz_bfd
.get ());
2167 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2168 return dwarf2_per_objfile
->dwz_file
.get ();
2171 /* DWARF quick_symbols_functions support. */
2173 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2174 unique line tables, so we maintain a separate table of all .debug_line
2175 derived entries to support the sharing.
2176 All the quick functions need is the list of file names. We discard the
2177 line_header when we're done and don't need to record it here. */
2178 struct quick_file_names
2180 /* The data used to construct the hash key. */
2181 struct stmt_list_hash hash
;
2183 /* The number of entries in file_names, real_names. */
2184 unsigned int num_file_names
;
2186 /* The file names from the line table, after being run through
2188 const char **file_names
;
2190 /* The file names from the line table after being run through
2191 gdb_realpath. These are computed lazily. */
2192 const char **real_names
;
2195 /* When using the index (and thus not using psymtabs), each CU has an
2196 object of this type. This is used to hold information needed by
2197 the various "quick" methods. */
2198 struct dwarf2_per_cu_quick_data
2200 /* The file table. This can be NULL if there was no file table
2201 or it's currently not read in.
2202 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2203 struct quick_file_names
*file_names
;
2205 /* The corresponding symbol table. This is NULL if symbols for this
2206 CU have not yet been read. */
2207 struct compunit_symtab
*compunit_symtab
;
2209 /* A temporary mark bit used when iterating over all CUs in
2210 expand_symtabs_matching. */
2211 unsigned int mark
: 1;
2213 /* True if we've tried to read the file table and found there isn't one.
2214 There will be no point in trying to read it again next time. */
2215 unsigned int no_file_data
: 1;
2218 /* Utility hash function for a stmt_list_hash. */
2221 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2225 if (stmt_list_hash
->dwo_unit
!= NULL
)
2226 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2227 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2231 /* Utility equality function for a stmt_list_hash. */
2234 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2235 const struct stmt_list_hash
*rhs
)
2237 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2239 if (lhs
->dwo_unit
!= NULL
2240 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2243 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2246 /* Hash function for a quick_file_names. */
2249 hash_file_name_entry (const void *e
)
2251 const struct quick_file_names
*file_data
2252 = (const struct quick_file_names
*) e
;
2254 return hash_stmt_list_entry (&file_data
->hash
);
2257 /* Equality function for a quick_file_names. */
2260 eq_file_name_entry (const void *a
, const void *b
)
2262 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2263 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2265 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2268 /* Delete function for a quick_file_names. */
2271 delete_file_name_entry (void *e
)
2273 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2276 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2278 xfree ((void*) file_data
->file_names
[i
]);
2279 if (file_data
->real_names
)
2280 xfree ((void*) file_data
->real_names
[i
]);
2283 /* The space for the struct itself lives on objfile_obstack,
2284 so we don't free it here. */
2287 /* Create a quick_file_names hash table. */
2290 create_quick_file_names_table (unsigned int nr_initial_entries
)
2292 return htab_up (htab_create_alloc (nr_initial_entries
,
2293 hash_file_name_entry
, eq_file_name_entry
,
2294 delete_file_name_entry
, xcalloc
, xfree
));
2297 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2298 have to be created afterwards. You should call age_cached_comp_units after
2299 processing PER_CU->CU. dw2_setup must have been already called. */
2302 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2304 if (per_cu
->is_debug_types
)
2305 load_full_type_unit (per_cu
);
2307 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2309 if (per_cu
->cu
== NULL
)
2310 return; /* Dummy CU. */
2312 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2315 /* Read in the symbols for PER_CU. */
2318 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2320 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2322 /* Skip type_unit_groups, reading the type units they contain
2323 is handled elsewhere. */
2324 if (IS_TYPE_UNIT_GROUP (per_cu
))
2327 /* The destructor of dwarf2_queue_guard frees any entries left on
2328 the queue. After this point we're guaranteed to leave this function
2329 with the dwarf queue empty. */
2330 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2332 if (dwarf2_per_objfile
->using_index
2333 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2334 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2336 queue_comp_unit (per_cu
, language_minimal
);
2337 load_cu (per_cu
, skip_partial
);
2339 /* If we just loaded a CU from a DWO, and we're working with an index
2340 that may badly handle TUs, load all the TUs in that DWO as well.
2341 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2342 if (!per_cu
->is_debug_types
2343 && per_cu
->cu
!= NULL
2344 && per_cu
->cu
->dwo_unit
!= NULL
2345 && dwarf2_per_objfile
->index_table
!= NULL
2346 && dwarf2_per_objfile
->index_table
->version
<= 7
2347 /* DWP files aren't supported yet. */
2348 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2349 queue_and_load_all_dwo_tus (per_cu
);
2352 process_queue (dwarf2_per_objfile
);
2354 /* Age the cache, releasing compilation units that have not
2355 been used recently. */
2356 age_cached_comp_units (dwarf2_per_objfile
);
2359 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2360 the objfile from which this CU came. Returns the resulting symbol
2363 static struct compunit_symtab
*
2364 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2366 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2368 gdb_assert (dwarf2_per_objfile
->using_index
);
2369 if (!per_cu
->v
.quick
->compunit_symtab
)
2371 free_cached_comp_units
freer (dwarf2_per_objfile
);
2372 scoped_restore decrementer
= increment_reading_symtab ();
2373 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2374 process_cu_includes (dwarf2_per_objfile
);
2377 return per_cu
->v
.quick
->compunit_symtab
;
2380 /* See declaration. */
2382 dwarf2_per_cu_data
*
2383 dwarf2_per_objfile::get_cutu (int index
)
2385 if (index
>= this->all_comp_units
.size ())
2387 index
-= this->all_comp_units
.size ();
2388 gdb_assert (index
< this->all_type_units
.size ());
2389 return &this->all_type_units
[index
]->per_cu
;
2392 return this->all_comp_units
[index
];
2395 /* See declaration. */
2397 dwarf2_per_cu_data
*
2398 dwarf2_per_objfile::get_cu (int index
)
2400 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2402 return this->all_comp_units
[index
];
2405 /* See declaration. */
2408 dwarf2_per_objfile::get_tu (int index
)
2410 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2412 return this->all_type_units
[index
];
2415 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2416 objfile_obstack, and constructed with the specified field
2419 static dwarf2_per_cu_data
*
2420 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2421 struct dwarf2_section_info
*section
,
2423 sect_offset sect_off
, ULONGEST length
)
2425 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2426 dwarf2_per_cu_data
*the_cu
2427 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2428 struct dwarf2_per_cu_data
);
2429 the_cu
->sect_off
= sect_off
;
2430 the_cu
->length
= length
;
2431 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2432 the_cu
->section
= section
;
2433 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2434 struct dwarf2_per_cu_quick_data
);
2435 the_cu
->is_dwz
= is_dwz
;
2439 /* A helper for create_cus_from_index that handles a given list of
2443 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2444 const gdb_byte
*cu_list
, offset_type n_elements
,
2445 struct dwarf2_section_info
*section
,
2448 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2450 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2452 sect_offset sect_off
2453 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2454 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2457 dwarf2_per_cu_data
*per_cu
2458 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2460 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2464 /* Read the CU list from the mapped index, and use it to create all
2465 the CU objects for this objfile. */
2468 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2469 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2470 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2472 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2473 dwarf2_per_objfile
->all_comp_units
.reserve
2474 ((cu_list_elements
+ dwz_elements
) / 2);
2476 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2477 &dwarf2_per_objfile
->info
, 0);
2479 if (dwz_elements
== 0)
2482 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2483 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2487 /* Create the signatured type hash table from the index. */
2490 create_signatured_type_table_from_index
2491 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2492 struct dwarf2_section_info
*section
,
2493 const gdb_byte
*bytes
,
2494 offset_type elements
)
2496 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2498 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2499 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2501 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2503 for (offset_type i
= 0; i
< elements
; i
+= 3)
2505 struct signatured_type
*sig_type
;
2508 cu_offset type_offset_in_tu
;
2510 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2511 sect_offset sect_off
2512 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2514 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2516 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2519 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2520 struct signatured_type
);
2521 sig_type
->signature
= signature
;
2522 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2523 sig_type
->per_cu
.is_debug_types
= 1;
2524 sig_type
->per_cu
.section
= section
;
2525 sig_type
->per_cu
.sect_off
= sect_off
;
2526 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2527 sig_type
->per_cu
.v
.quick
2528 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2529 struct dwarf2_per_cu_quick_data
);
2531 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2534 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2537 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2540 /* Create the signatured type hash table from .debug_names. */
2543 create_signatured_type_table_from_debug_names
2544 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2545 const mapped_debug_names
&map
,
2546 struct dwarf2_section_info
*section
,
2547 struct dwarf2_section_info
*abbrev_section
)
2549 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2551 section
->read (objfile
);
2552 abbrev_section
->read (objfile
);
2554 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2555 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2557 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2559 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2561 struct signatured_type
*sig_type
;
2564 sect_offset sect_off
2565 = (sect_offset
) (extract_unsigned_integer
2566 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2568 map
.dwarf5_byte_order
));
2570 comp_unit_head cu_header
;
2571 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2573 section
->buffer
+ to_underlying (sect_off
),
2576 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2577 struct signatured_type
);
2578 sig_type
->signature
= cu_header
.signature
;
2579 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2580 sig_type
->per_cu
.is_debug_types
= 1;
2581 sig_type
->per_cu
.section
= section
;
2582 sig_type
->per_cu
.sect_off
= sect_off
;
2583 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2584 sig_type
->per_cu
.v
.quick
2585 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2586 struct dwarf2_per_cu_quick_data
);
2588 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2591 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2594 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2597 /* Read the address map data from the mapped index, and use it to
2598 populate the objfile's psymtabs_addrmap. */
2601 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2602 struct mapped_index
*index
)
2604 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2605 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2606 const gdb_byte
*iter
, *end
;
2607 struct addrmap
*mutable_map
;
2610 auto_obstack temp_obstack
;
2612 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2614 iter
= index
->address_table
.data ();
2615 end
= iter
+ index
->address_table
.size ();
2617 baseaddr
= objfile
->text_section_offset ();
2621 ULONGEST hi
, lo
, cu_index
;
2622 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2624 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2626 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2631 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2632 hex_string (lo
), hex_string (hi
));
2636 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2638 complaint (_(".gdb_index address table has invalid CU number %u"),
2639 (unsigned) cu_index
);
2643 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2644 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2645 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2646 dwarf2_per_objfile
->get_cu (cu_index
));
2649 objfile
->partial_symtabs
->psymtabs_addrmap
2650 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2653 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2654 populate the objfile's psymtabs_addrmap. */
2657 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2658 struct dwarf2_section_info
*section
)
2660 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2661 bfd
*abfd
= objfile
->obfd
;
2662 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2663 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2665 auto_obstack temp_obstack
;
2666 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2668 std::unordered_map
<sect_offset
,
2669 dwarf2_per_cu_data
*,
2670 gdb::hash_enum
<sect_offset
>>
2671 debug_info_offset_to_per_cu
;
2672 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2674 const auto insertpair
2675 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2676 if (!insertpair
.second
)
2678 warning (_("Section .debug_aranges in %s has duplicate "
2679 "debug_info_offset %s, ignoring .debug_aranges."),
2680 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2685 section
->read (objfile
);
2687 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2689 const gdb_byte
*addr
= section
->buffer
;
2691 while (addr
< section
->buffer
+ section
->size
)
2693 const gdb_byte
*const entry_addr
= addr
;
2694 unsigned int bytes_read
;
2696 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2700 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2701 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2702 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2703 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2705 warning (_("Section .debug_aranges in %s entry at offset %s "
2706 "length %s exceeds section length %s, "
2707 "ignoring .debug_aranges."),
2708 objfile_name (objfile
),
2709 plongest (entry_addr
- section
->buffer
),
2710 plongest (bytes_read
+ entry_length
),
2711 pulongest (section
->size
));
2715 /* The version number. */
2716 const uint16_t version
= read_2_bytes (abfd
, addr
);
2720 warning (_("Section .debug_aranges in %s entry at offset %s "
2721 "has unsupported version %d, ignoring .debug_aranges."),
2722 objfile_name (objfile
),
2723 plongest (entry_addr
- section
->buffer
), version
);
2727 const uint64_t debug_info_offset
2728 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2729 addr
+= offset_size
;
2730 const auto per_cu_it
2731 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2732 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2734 warning (_("Section .debug_aranges in %s entry at offset %s "
2735 "debug_info_offset %s does not exists, "
2736 "ignoring .debug_aranges."),
2737 objfile_name (objfile
),
2738 plongest (entry_addr
- section
->buffer
),
2739 pulongest (debug_info_offset
));
2742 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2744 const uint8_t address_size
= *addr
++;
2745 if (address_size
< 1 || address_size
> 8)
2747 warning (_("Section .debug_aranges in %s entry at offset %s "
2748 "address_size %u is invalid, ignoring .debug_aranges."),
2749 objfile_name (objfile
),
2750 plongest (entry_addr
- section
->buffer
), address_size
);
2754 const uint8_t segment_selector_size
= *addr
++;
2755 if (segment_selector_size
!= 0)
2757 warning (_("Section .debug_aranges in %s entry at offset %s "
2758 "segment_selector_size %u is not supported, "
2759 "ignoring .debug_aranges."),
2760 objfile_name (objfile
),
2761 plongest (entry_addr
- section
->buffer
),
2762 segment_selector_size
);
2766 /* Must pad to an alignment boundary that is twice the address
2767 size. It is undocumented by the DWARF standard but GCC does
2769 for (size_t padding
= ((-(addr
- section
->buffer
))
2770 & (2 * address_size
- 1));
2771 padding
> 0; padding
--)
2774 warning (_("Section .debug_aranges in %s entry at offset %s "
2775 "padding is not zero, ignoring .debug_aranges."),
2776 objfile_name (objfile
),
2777 plongest (entry_addr
- section
->buffer
));
2783 if (addr
+ 2 * address_size
> entry_end
)
2785 warning (_("Section .debug_aranges in %s entry at offset %s "
2786 "address list is not properly terminated, "
2787 "ignoring .debug_aranges."),
2788 objfile_name (objfile
),
2789 plongest (entry_addr
- section
->buffer
));
2792 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2794 addr
+= address_size
;
2795 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2797 addr
+= address_size
;
2798 if (start
== 0 && length
== 0)
2800 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2802 /* Symbol was eliminated due to a COMDAT group. */
2805 ULONGEST end
= start
+ length
;
2806 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2808 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2810 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2814 objfile
->partial_symtabs
->psymtabs_addrmap
2815 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2818 /* Find a slot in the mapped index INDEX for the object named NAME.
2819 If NAME is found, set *VEC_OUT to point to the CU vector in the
2820 constant pool and return true. If NAME cannot be found, return
2824 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2825 offset_type
**vec_out
)
2828 offset_type slot
, step
;
2829 int (*cmp
) (const char *, const char *);
2831 gdb::unique_xmalloc_ptr
<char> without_params
;
2832 if (current_language
->la_language
== language_cplus
2833 || current_language
->la_language
== language_fortran
2834 || current_language
->la_language
== language_d
)
2836 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2839 if (strchr (name
, '(') != NULL
)
2841 without_params
= cp_remove_params (name
);
2843 if (without_params
!= NULL
)
2844 name
= without_params
.get ();
2848 /* Index version 4 did not support case insensitive searches. But the
2849 indices for case insensitive languages are built in lowercase, therefore
2850 simulate our NAME being searched is also lowercased. */
2851 hash
= mapped_index_string_hash ((index
->version
== 4
2852 && case_sensitivity
== case_sensitive_off
2853 ? 5 : index
->version
),
2856 slot
= hash
& (index
->symbol_table
.size () - 1);
2857 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2858 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2864 const auto &bucket
= index
->symbol_table
[slot
];
2865 if (bucket
.name
== 0 && bucket
.vec
== 0)
2868 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2869 if (!cmp (name
, str
))
2871 *vec_out
= (offset_type
*) (index
->constant_pool
2872 + MAYBE_SWAP (bucket
.vec
));
2876 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2880 /* A helper function that reads the .gdb_index from BUFFER and fills
2881 in MAP. FILENAME is the name of the file containing the data;
2882 it is used for error reporting. DEPRECATED_OK is true if it is
2883 ok to use deprecated sections.
2885 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2886 out parameters that are filled in with information about the CU and
2887 TU lists in the section.
2889 Returns true if all went well, false otherwise. */
2892 read_gdb_index_from_buffer (struct objfile
*objfile
,
2893 const char *filename
,
2895 gdb::array_view
<const gdb_byte
> buffer
,
2896 struct mapped_index
*map
,
2897 const gdb_byte
**cu_list
,
2898 offset_type
*cu_list_elements
,
2899 const gdb_byte
**types_list
,
2900 offset_type
*types_list_elements
)
2902 const gdb_byte
*addr
= &buffer
[0];
2904 /* Version check. */
2905 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2906 /* Versions earlier than 3 emitted every copy of a psymbol. This
2907 causes the index to behave very poorly for certain requests. Version 3
2908 contained incomplete addrmap. So, it seems better to just ignore such
2912 static int warning_printed
= 0;
2913 if (!warning_printed
)
2915 warning (_("Skipping obsolete .gdb_index section in %s."),
2917 warning_printed
= 1;
2921 /* Index version 4 uses a different hash function than index version
2924 Versions earlier than 6 did not emit psymbols for inlined
2925 functions. Using these files will cause GDB not to be able to
2926 set breakpoints on inlined functions by name, so we ignore these
2927 indices unless the user has done
2928 "set use-deprecated-index-sections on". */
2929 if (version
< 6 && !deprecated_ok
)
2931 static int warning_printed
= 0;
2932 if (!warning_printed
)
2935 Skipping deprecated .gdb_index section in %s.\n\
2936 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2937 to use the section anyway."),
2939 warning_printed
= 1;
2943 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2944 of the TU (for symbols coming from TUs),
2945 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2946 Plus gold-generated indices can have duplicate entries for global symbols,
2947 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2948 These are just performance bugs, and we can't distinguish gdb-generated
2949 indices from gold-generated ones, so issue no warning here. */
2951 /* Indexes with higher version than the one supported by GDB may be no
2952 longer backward compatible. */
2956 map
->version
= version
;
2958 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2961 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2962 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2966 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2967 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2968 - MAYBE_SWAP (metadata
[i
]))
2972 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2973 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2975 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2978 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2979 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2981 = gdb::array_view
<mapped_index::symbol_table_slot
>
2982 ((mapped_index::symbol_table_slot
*) symbol_table
,
2983 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2986 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2991 /* Callback types for dwarf2_read_gdb_index. */
2993 typedef gdb::function_view
2994 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2995 get_gdb_index_contents_ftype
;
2996 typedef gdb::function_view
2997 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2998 get_gdb_index_contents_dwz_ftype
;
3000 /* Read .gdb_index. If everything went ok, initialize the "quick"
3001 elements of all the CUs and return 1. Otherwise, return 0. */
3004 dwarf2_read_gdb_index
3005 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3006 get_gdb_index_contents_ftype get_gdb_index_contents
,
3007 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3009 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3010 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3011 struct dwz_file
*dwz
;
3012 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3014 gdb::array_view
<const gdb_byte
> main_index_contents
3015 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3017 if (main_index_contents
.empty ())
3020 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3021 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3022 use_deprecated_index_sections
,
3023 main_index_contents
, map
.get (), &cu_list
,
3024 &cu_list_elements
, &types_list
,
3025 &types_list_elements
))
3028 /* Don't use the index if it's empty. */
3029 if (map
->symbol_table
.empty ())
3032 /* If there is a .dwz file, read it so we can get its CU list as
3034 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3037 struct mapped_index dwz_map
;
3038 const gdb_byte
*dwz_types_ignore
;
3039 offset_type dwz_types_elements_ignore
;
3041 gdb::array_view
<const gdb_byte
> dwz_index_content
3042 = get_gdb_index_contents_dwz (objfile
, dwz
);
3044 if (dwz_index_content
.empty ())
3047 if (!read_gdb_index_from_buffer (objfile
,
3048 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3049 1, dwz_index_content
, &dwz_map
,
3050 &dwz_list
, &dwz_list_elements
,
3052 &dwz_types_elements_ignore
))
3054 warning (_("could not read '.gdb_index' section from %s; skipping"),
3055 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3060 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3061 dwz_list
, dwz_list_elements
);
3063 if (types_list_elements
)
3065 /* We can only handle a single .debug_types when we have an
3067 if (dwarf2_per_objfile
->types
.size () != 1)
3070 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3072 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3073 types_list
, types_list_elements
);
3076 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3078 dwarf2_per_objfile
->index_table
= std::move (map
);
3079 dwarf2_per_objfile
->using_index
= 1;
3080 dwarf2_per_objfile
->quick_file_names_table
=
3081 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3086 /* die_reader_func for dw2_get_file_names. */
3089 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3090 const gdb_byte
*info_ptr
,
3091 struct die_info
*comp_unit_die
)
3093 struct dwarf2_cu
*cu
= reader
->cu
;
3094 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3095 struct dwarf2_per_objfile
*dwarf2_per_objfile
3096 = cu
->per_cu
->dwarf2_per_objfile
;
3097 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3098 struct dwarf2_per_cu_data
*lh_cu
;
3099 struct attribute
*attr
;
3101 struct quick_file_names
*qfn
;
3103 gdb_assert (! this_cu
->is_debug_types
);
3105 /* Our callers never want to match partial units -- instead they
3106 will match the enclosing full CU. */
3107 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3109 this_cu
->v
.quick
->no_file_data
= 1;
3117 sect_offset line_offset
{};
3119 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3120 if (attr
!= nullptr)
3122 struct quick_file_names find_entry
;
3124 line_offset
= (sect_offset
) DW_UNSND (attr
);
3126 /* We may have already read in this line header (TU line header sharing).
3127 If we have we're done. */
3128 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3129 find_entry
.hash
.line_sect_off
= line_offset
;
3130 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3131 &find_entry
, INSERT
);
3134 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3138 lh
= dwarf_decode_line_header (line_offset
, cu
);
3142 lh_cu
->v
.quick
->no_file_data
= 1;
3146 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3147 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3148 qfn
->hash
.line_sect_off
= line_offset
;
3149 gdb_assert (slot
!= NULL
);
3152 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3155 if (strcmp (fnd
.name
, "<unknown>") != 0)
3158 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3160 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3162 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3163 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3164 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3165 fnd
.comp_dir
).release ();
3166 qfn
->real_names
= NULL
;
3168 lh_cu
->v
.quick
->file_names
= qfn
;
3171 /* A helper for the "quick" functions which attempts to read the line
3172 table for THIS_CU. */
3174 static struct quick_file_names
*
3175 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3177 /* This should never be called for TUs. */
3178 gdb_assert (! this_cu
->is_debug_types
);
3179 /* Nor type unit groups. */
3180 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3182 if (this_cu
->v
.quick
->file_names
!= NULL
)
3183 return this_cu
->v
.quick
->file_names
;
3184 /* If we know there is no line data, no point in looking again. */
3185 if (this_cu
->v
.quick
->no_file_data
)
3188 cutu_reader
reader (this_cu
);
3189 if (!reader
.dummy_p
)
3190 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3192 if (this_cu
->v
.quick
->no_file_data
)
3194 return this_cu
->v
.quick
->file_names
;
3197 /* A helper for the "quick" functions which computes and caches the
3198 real path for a given file name from the line table. */
3201 dw2_get_real_path (struct objfile
*objfile
,
3202 struct quick_file_names
*qfn
, int index
)
3204 if (qfn
->real_names
== NULL
)
3205 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3206 qfn
->num_file_names
, const char *);
3208 if (qfn
->real_names
[index
] == NULL
)
3209 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3211 return qfn
->real_names
[index
];
3214 static struct symtab
*
3215 dw2_find_last_source_symtab (struct objfile
*objfile
)
3217 struct dwarf2_per_objfile
*dwarf2_per_objfile
3218 = get_dwarf2_per_objfile (objfile
);
3219 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3220 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3225 return compunit_primary_filetab (cust
);
3228 /* Traversal function for dw2_forget_cached_source_info. */
3231 dw2_free_cached_file_names (void **slot
, void *info
)
3233 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3235 if (file_data
->real_names
)
3239 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3241 xfree ((void*) file_data
->real_names
[i
]);
3242 file_data
->real_names
[i
] = NULL
;
3250 dw2_forget_cached_source_info (struct objfile
*objfile
)
3252 struct dwarf2_per_objfile
*dwarf2_per_objfile
3253 = get_dwarf2_per_objfile (objfile
);
3255 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3256 dw2_free_cached_file_names
, NULL
);
3259 /* Helper function for dw2_map_symtabs_matching_filename that expands
3260 the symtabs and calls the iterator. */
3263 dw2_map_expand_apply (struct objfile
*objfile
,
3264 struct dwarf2_per_cu_data
*per_cu
,
3265 const char *name
, const char *real_path
,
3266 gdb::function_view
<bool (symtab
*)> callback
)
3268 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3270 /* Don't visit already-expanded CUs. */
3271 if (per_cu
->v
.quick
->compunit_symtab
)
3274 /* This may expand more than one symtab, and we want to iterate over
3276 dw2_instantiate_symtab (per_cu
, false);
3278 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3279 last_made
, callback
);
3282 /* Implementation of the map_symtabs_matching_filename method. */
3285 dw2_map_symtabs_matching_filename
3286 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3287 gdb::function_view
<bool (symtab
*)> callback
)
3289 const char *name_basename
= lbasename (name
);
3290 struct dwarf2_per_objfile
*dwarf2_per_objfile
3291 = get_dwarf2_per_objfile (objfile
);
3293 /* The rule is CUs specify all the files, including those used by
3294 any TU, so there's no need to scan TUs here. */
3296 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3298 /* We only need to look at symtabs not already expanded. */
3299 if (per_cu
->v
.quick
->compunit_symtab
)
3302 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3303 if (file_data
== NULL
)
3306 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3308 const char *this_name
= file_data
->file_names
[j
];
3309 const char *this_real_name
;
3311 if (compare_filenames_for_search (this_name
, name
))
3313 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3319 /* Before we invoke realpath, which can get expensive when many
3320 files are involved, do a quick comparison of the basenames. */
3321 if (! basenames_may_differ
3322 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3325 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3326 if (compare_filenames_for_search (this_real_name
, name
))
3328 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3334 if (real_path
!= NULL
)
3336 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3337 gdb_assert (IS_ABSOLUTE_PATH (name
));
3338 if (this_real_name
!= NULL
3339 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3341 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3353 /* Struct used to manage iterating over all CUs looking for a symbol. */
3355 struct dw2_symtab_iterator
3357 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3358 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3359 /* If set, only look for symbols that match that block. Valid values are
3360 GLOBAL_BLOCK and STATIC_BLOCK. */
3361 gdb::optional
<block_enum
> block_index
;
3362 /* The kind of symbol we're looking for. */
3364 /* The list of CUs from the index entry of the symbol,
3365 or NULL if not found. */
3367 /* The next element in VEC to look at. */
3369 /* The number of elements in VEC, or zero if there is no match. */
3371 /* Have we seen a global version of the symbol?
3372 If so we can ignore all further global instances.
3373 This is to work around gold/15646, inefficient gold-generated
3378 /* Initialize the index symtab iterator ITER. */
3381 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3382 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3383 gdb::optional
<block_enum
> block_index
,
3387 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3388 iter
->block_index
= block_index
;
3389 iter
->domain
= domain
;
3391 iter
->global_seen
= 0;
3393 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3395 /* index is NULL if OBJF_READNOW. */
3396 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3397 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3405 /* Return the next matching CU or NULL if there are no more. */
3407 static struct dwarf2_per_cu_data
*
3408 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3410 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3412 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3414 offset_type cu_index_and_attrs
=
3415 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3416 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3417 gdb_index_symbol_kind symbol_kind
=
3418 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3419 /* Only check the symbol attributes if they're present.
3420 Indices prior to version 7 don't record them,
3421 and indices >= 7 may elide them for certain symbols
3422 (gold does this). */
3424 (dwarf2_per_objfile
->index_table
->version
>= 7
3425 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3427 /* Don't crash on bad data. */
3428 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3429 + dwarf2_per_objfile
->all_type_units
.size ()))
3431 complaint (_(".gdb_index entry has bad CU index"
3433 objfile_name (dwarf2_per_objfile
->objfile
));
3437 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3439 /* Skip if already read in. */
3440 if (per_cu
->v
.quick
->compunit_symtab
)
3443 /* Check static vs global. */
3446 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3448 if (iter
->block_index
.has_value ())
3450 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3452 if (is_static
!= want_static
)
3456 /* Work around gold/15646. */
3457 if (!is_static
&& iter
->global_seen
)
3460 iter
->global_seen
= 1;
3463 /* Only check the symbol's kind if it has one. */
3466 switch (iter
->domain
)
3469 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3470 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3471 /* Some types are also in VAR_DOMAIN. */
3472 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3476 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3480 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3484 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3499 static struct compunit_symtab
*
3500 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3501 const char *name
, domain_enum domain
)
3503 struct compunit_symtab
*stab_best
= NULL
;
3504 struct dwarf2_per_objfile
*dwarf2_per_objfile
3505 = get_dwarf2_per_objfile (objfile
);
3507 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3509 struct dw2_symtab_iterator iter
;
3510 struct dwarf2_per_cu_data
*per_cu
;
3512 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3514 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3516 struct symbol
*sym
, *with_opaque
= NULL
;
3517 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3518 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3519 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3521 sym
= block_find_symbol (block
, name
, domain
,
3522 block_find_non_opaque_type_preferred
,
3525 /* Some caution must be observed with overloaded functions
3526 and methods, since the index will not contain any overload
3527 information (but NAME might contain it). */
3530 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3532 if (with_opaque
!= NULL
3533 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3536 /* Keep looking through other CUs. */
3543 dw2_print_stats (struct objfile
*objfile
)
3545 struct dwarf2_per_objfile
*dwarf2_per_objfile
3546 = get_dwarf2_per_objfile (objfile
);
3547 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3548 + dwarf2_per_objfile
->all_type_units
.size ());
3551 for (int i
= 0; i
< total
; ++i
)
3553 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3555 if (!per_cu
->v
.quick
->compunit_symtab
)
3558 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3559 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3562 /* This dumps minimal information about the index.
3563 It is called via "mt print objfiles".
3564 One use is to verify .gdb_index has been loaded by the
3565 gdb.dwarf2/gdb-index.exp testcase. */
3568 dw2_dump (struct objfile
*objfile
)
3570 struct dwarf2_per_objfile
*dwarf2_per_objfile
3571 = get_dwarf2_per_objfile (objfile
);
3573 gdb_assert (dwarf2_per_objfile
->using_index
);
3574 printf_filtered (".gdb_index:");
3575 if (dwarf2_per_objfile
->index_table
!= NULL
)
3577 printf_filtered (" version %d\n",
3578 dwarf2_per_objfile
->index_table
->version
);
3581 printf_filtered (" faked for \"readnow\"\n");
3582 printf_filtered ("\n");
3586 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3587 const char *func_name
)
3589 struct dwarf2_per_objfile
*dwarf2_per_objfile
3590 = get_dwarf2_per_objfile (objfile
);
3592 struct dw2_symtab_iterator iter
;
3593 struct dwarf2_per_cu_data
*per_cu
;
3595 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3597 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3598 dw2_instantiate_symtab (per_cu
, false);
3603 dw2_expand_all_symtabs (struct objfile
*objfile
)
3605 struct dwarf2_per_objfile
*dwarf2_per_objfile
3606 = get_dwarf2_per_objfile (objfile
);
3607 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3608 + dwarf2_per_objfile
->all_type_units
.size ());
3610 for (int i
= 0; i
< total_units
; ++i
)
3612 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3614 /* We don't want to directly expand a partial CU, because if we
3615 read it with the wrong language, then assertion failures can
3616 be triggered later on. See PR symtab/23010. So, tell
3617 dw2_instantiate_symtab to skip partial CUs -- any important
3618 partial CU will be read via DW_TAG_imported_unit anyway. */
3619 dw2_instantiate_symtab (per_cu
, true);
3624 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3625 const char *fullname
)
3627 struct dwarf2_per_objfile
*dwarf2_per_objfile
3628 = get_dwarf2_per_objfile (objfile
);
3630 /* We don't need to consider type units here.
3631 This is only called for examining code, e.g. expand_line_sal.
3632 There can be an order of magnitude (or more) more type units
3633 than comp units, and we avoid them if we can. */
3635 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3637 /* We only need to look at symtabs not already expanded. */
3638 if (per_cu
->v
.quick
->compunit_symtab
)
3641 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3642 if (file_data
== NULL
)
3645 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3647 const char *this_fullname
= file_data
->file_names
[j
];
3649 if (filename_cmp (this_fullname
, fullname
) == 0)
3651 dw2_instantiate_symtab (per_cu
, false);
3659 dw2_map_matching_symbols
3660 (struct objfile
*objfile
,
3661 const lookup_name_info
&name
, domain_enum domain
,
3663 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3664 symbol_compare_ftype
*ordered_compare
)
3666 /* Currently unimplemented; used for Ada. The function can be called if the
3667 current language is Ada for a non-Ada objfile using GNU index. As Ada
3668 does not look for non-Ada symbols this function should just return. */
3671 /* Starting from a search name, return the string that finds the upper
3672 bound of all strings that start with SEARCH_NAME in a sorted name
3673 list. Returns the empty string to indicate that the upper bound is
3674 the end of the list. */
3677 make_sort_after_prefix_name (const char *search_name
)
3679 /* When looking to complete "func", we find the upper bound of all
3680 symbols that start with "func" by looking for where we'd insert
3681 the closest string that would follow "func" in lexicographical
3682 order. Usually, that's "func"-with-last-character-incremented,
3683 i.e. "fund". Mind non-ASCII characters, though. Usually those
3684 will be UTF-8 multi-byte sequences, but we can't be certain.
3685 Especially mind the 0xff character, which is a valid character in
3686 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3687 rule out compilers allowing it in identifiers. Note that
3688 conveniently, strcmp/strcasecmp are specified to compare
3689 characters interpreted as unsigned char. So what we do is treat
3690 the whole string as a base 256 number composed of a sequence of
3691 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3692 to 0, and carries 1 to the following more-significant position.
3693 If the very first character in SEARCH_NAME ends up incremented
3694 and carries/overflows, then the upper bound is the end of the
3695 list. The string after the empty string is also the empty
3698 Some examples of this operation:
3700 SEARCH_NAME => "+1" RESULT
3704 "\xff" "a" "\xff" => "\xff" "b"
3709 Then, with these symbols for example:
3715 completing "func" looks for symbols between "func" and
3716 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3717 which finds "func" and "func1", but not "fund".
3721 funcÿ (Latin1 'ÿ' [0xff])
3725 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3726 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3730 ÿÿ (Latin1 'ÿ' [0xff])
3733 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3734 the end of the list.
3736 std::string after
= search_name
;
3737 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3739 if (!after
.empty ())
3740 after
.back () = (unsigned char) after
.back () + 1;
3744 /* See declaration. */
3746 std::pair
<std::vector
<name_component
>::const_iterator
,
3747 std::vector
<name_component
>::const_iterator
>
3748 mapped_index_base::find_name_components_bounds
3749 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3752 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3754 const char *lang_name
3755 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3757 /* Comparison function object for lower_bound that matches against a
3758 given symbol name. */
3759 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3762 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3763 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3764 return name_cmp (elem_name
, name
) < 0;
3767 /* Comparison function object for upper_bound that matches against a
3768 given symbol name. */
3769 auto lookup_compare_upper
= [&] (const char *name
,
3770 const name_component
&elem
)
3772 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3773 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3774 return name_cmp (name
, elem_name
) < 0;
3777 auto begin
= this->name_components
.begin ();
3778 auto end
= this->name_components
.end ();
3780 /* Find the lower bound. */
3783 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3786 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3789 /* Find the upper bound. */
3792 if (lookup_name_without_params
.completion_mode ())
3794 /* In completion mode, we want UPPER to point past all
3795 symbols names that have the same prefix. I.e., with
3796 these symbols, and completing "func":
3798 function << lower bound
3800 other_function << upper bound
3802 We find the upper bound by looking for the insertion
3803 point of "func"-with-last-character-incremented,
3805 std::string after
= make_sort_after_prefix_name (lang_name
);
3808 return std::lower_bound (lower
, end
, after
.c_str (),
3809 lookup_compare_lower
);
3812 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3815 return {lower
, upper
};
3818 /* See declaration. */
3821 mapped_index_base::build_name_components ()
3823 if (!this->name_components
.empty ())
3826 this->name_components_casing
= case_sensitivity
;
3828 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3830 /* The code below only knows how to break apart components of C++
3831 symbol names (and other languages that use '::' as
3832 namespace/module separator) and Ada symbol names. */
3833 auto count
= this->symbol_name_count ();
3834 for (offset_type idx
= 0; idx
< count
; idx
++)
3836 if (this->symbol_name_slot_invalid (idx
))
3839 const char *name
= this->symbol_name_at (idx
);
3841 /* Add each name component to the name component table. */
3842 unsigned int previous_len
= 0;
3844 if (strstr (name
, "::") != nullptr)
3846 for (unsigned int current_len
= cp_find_first_component (name
);
3847 name
[current_len
] != '\0';
3848 current_len
+= cp_find_first_component (name
+ current_len
))
3850 gdb_assert (name
[current_len
] == ':');
3851 this->name_components
.push_back ({previous_len
, idx
});
3852 /* Skip the '::'. */
3854 previous_len
= current_len
;
3859 /* Handle the Ada encoded (aka mangled) form here. */
3860 for (const char *iter
= strstr (name
, "__");
3862 iter
= strstr (iter
, "__"))
3864 this->name_components
.push_back ({previous_len
, idx
});
3866 previous_len
= iter
- name
;
3870 this->name_components
.push_back ({previous_len
, idx
});
3873 /* Sort name_components elements by name. */
3874 auto name_comp_compare
= [&] (const name_component
&left
,
3875 const name_component
&right
)
3877 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3878 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3880 const char *left_name
= left_qualified
+ left
.name_offset
;
3881 const char *right_name
= right_qualified
+ right
.name_offset
;
3883 return name_cmp (left_name
, right_name
) < 0;
3886 std::sort (this->name_components
.begin (),
3887 this->name_components
.end (),
3891 /* Helper for dw2_expand_symtabs_matching that works with a
3892 mapped_index_base instead of the containing objfile. This is split
3893 to a separate function in order to be able to unit test the
3894 name_components matching using a mock mapped_index_base. For each
3895 symbol name that matches, calls MATCH_CALLBACK, passing it the
3896 symbol's index in the mapped_index_base symbol table. */
3899 dw2_expand_symtabs_matching_symbol
3900 (mapped_index_base
&index
,
3901 const lookup_name_info
&lookup_name_in
,
3902 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3903 enum search_domain kind
,
3904 gdb::function_view
<bool (offset_type
)> match_callback
)
3906 lookup_name_info lookup_name_without_params
3907 = lookup_name_in
.make_ignore_params ();
3909 /* Build the symbol name component sorted vector, if we haven't
3911 index
.build_name_components ();
3913 /* The same symbol may appear more than once in the range though.
3914 E.g., if we're looking for symbols that complete "w", and we have
3915 a symbol named "w1::w2", we'll find the two name components for
3916 that same symbol in the range. To be sure we only call the
3917 callback once per symbol, we first collect the symbol name
3918 indexes that matched in a temporary vector and ignore
3920 std::vector
<offset_type
> matches
;
3922 struct name_and_matcher
3924 symbol_name_matcher_ftype
*matcher
;
3925 const std::string
&name
;
3927 bool operator== (const name_and_matcher
&other
) const
3929 return matcher
== other
.matcher
&& name
== other
.name
;
3933 /* A vector holding all the different symbol name matchers, for all
3935 std::vector
<name_and_matcher
> matchers
;
3937 for (int i
= 0; i
< nr_languages
; i
++)
3939 enum language lang_e
= (enum language
) i
;
3941 const language_defn
*lang
= language_def (lang_e
);
3942 symbol_name_matcher_ftype
*name_matcher
3943 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3945 name_and_matcher key
{
3947 lookup_name_without_params
.language_lookup_name (lang_e
)
3950 /* Don't insert the same comparison routine more than once.
3951 Note that we do this linear walk. This is not a problem in
3952 practice because the number of supported languages is
3954 if (std::find (matchers
.begin (), matchers
.end (), key
)
3957 matchers
.push_back (std::move (key
));
3960 = index
.find_name_components_bounds (lookup_name_without_params
,
3963 /* Now for each symbol name in range, check to see if we have a name
3964 match, and if so, call the MATCH_CALLBACK callback. */
3966 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3968 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3970 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3971 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3974 matches
.push_back (bounds
.first
->idx
);
3978 std::sort (matches
.begin (), matches
.end ());
3980 /* Finally call the callback, once per match. */
3982 for (offset_type idx
: matches
)
3986 if (!match_callback (idx
))
3992 /* Above we use a type wider than idx's for 'prev', since 0 and
3993 (offset_type)-1 are both possible values. */
3994 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3999 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4001 /* A mock .gdb_index/.debug_names-like name index table, enough to
4002 exercise dw2_expand_symtabs_matching_symbol, which works with the
4003 mapped_index_base interface. Builds an index from the symbol list
4004 passed as parameter to the constructor. */
4005 class mock_mapped_index
: public mapped_index_base
4008 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4009 : m_symbol_table (symbols
)
4012 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4014 /* Return the number of names in the symbol table. */
4015 size_t symbol_name_count () const override
4017 return m_symbol_table
.size ();
4020 /* Get the name of the symbol at IDX in the symbol table. */
4021 const char *symbol_name_at (offset_type idx
) const override
4023 return m_symbol_table
[idx
];
4027 gdb::array_view
<const char *> m_symbol_table
;
4030 /* Convenience function that converts a NULL pointer to a "<null>"
4031 string, to pass to print routines. */
4034 string_or_null (const char *str
)
4036 return str
!= NULL
? str
: "<null>";
4039 /* Check if a lookup_name_info built from
4040 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4041 index. EXPECTED_LIST is the list of expected matches, in expected
4042 matching order. If no match expected, then an empty list is
4043 specified. Returns true on success. On failure prints a warning
4044 indicating the file:line that failed, and returns false. */
4047 check_match (const char *file
, int line
,
4048 mock_mapped_index
&mock_index
,
4049 const char *name
, symbol_name_match_type match_type
,
4050 bool completion_mode
,
4051 std::initializer_list
<const char *> expected_list
)
4053 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4055 bool matched
= true;
4057 auto mismatch
= [&] (const char *expected_str
,
4060 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4061 "expected=\"%s\", got=\"%s\"\n"),
4063 (match_type
== symbol_name_match_type::FULL
4065 name
, string_or_null (expected_str
), string_or_null (got
));
4069 auto expected_it
= expected_list
.begin ();
4070 auto expected_end
= expected_list
.end ();
4072 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4074 [&] (offset_type idx
)
4076 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4077 const char *expected_str
4078 = expected_it
== expected_end
? NULL
: *expected_it
++;
4080 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4081 mismatch (expected_str
, matched_name
);
4085 const char *expected_str
4086 = expected_it
== expected_end
? NULL
: *expected_it
++;
4087 if (expected_str
!= NULL
)
4088 mismatch (expected_str
, NULL
);
4093 /* The symbols added to the mock mapped_index for testing (in
4095 static const char *test_symbols
[] = {
4104 "ns2::tmpl<int>::foo2",
4105 "(anonymous namespace)::A::B::C",
4107 /* These are used to check that the increment-last-char in the
4108 matching algorithm for completion doesn't match "t1_fund" when
4109 completing "t1_func". */
4115 /* A UTF-8 name with multi-byte sequences to make sure that
4116 cp-name-parser understands this as a single identifier ("função"
4117 is "function" in PT). */
4120 /* \377 (0xff) is Latin1 'ÿ'. */
4123 /* \377 (0xff) is Latin1 'ÿ'. */
4127 /* A name with all sorts of complications. Starts with "z" to make
4128 it easier for the completion tests below. */
4129 #define Z_SYM_NAME \
4130 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4131 "::tuple<(anonymous namespace)::ui*, " \
4132 "std::default_delete<(anonymous namespace)::ui>, void>"
4137 /* Returns true if the mapped_index_base::find_name_component_bounds
4138 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4139 in completion mode. */
4142 check_find_bounds_finds (mapped_index_base
&index
,
4143 const char *search_name
,
4144 gdb::array_view
<const char *> expected_syms
)
4146 lookup_name_info
lookup_name (search_name
,
4147 symbol_name_match_type::FULL
, true);
4149 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4152 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4153 if (distance
!= expected_syms
.size ())
4156 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4158 auto nc_elem
= bounds
.first
+ exp_elem
;
4159 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4160 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4167 /* Test the lower-level mapped_index::find_name_component_bounds
4171 test_mapped_index_find_name_component_bounds ()
4173 mock_mapped_index
mock_index (test_symbols
);
4175 mock_index
.build_name_components ();
4177 /* Test the lower-level mapped_index::find_name_component_bounds
4178 method in completion mode. */
4180 static const char *expected_syms
[] = {
4185 SELF_CHECK (check_find_bounds_finds (mock_index
,
4186 "t1_func", expected_syms
));
4189 /* Check that the increment-last-char in the name matching algorithm
4190 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4192 static const char *expected_syms1
[] = {
4196 SELF_CHECK (check_find_bounds_finds (mock_index
,
4197 "\377", expected_syms1
));
4199 static const char *expected_syms2
[] = {
4202 SELF_CHECK (check_find_bounds_finds (mock_index
,
4203 "\377\377", expected_syms2
));
4207 /* Test dw2_expand_symtabs_matching_symbol. */
4210 test_dw2_expand_symtabs_matching_symbol ()
4212 mock_mapped_index
mock_index (test_symbols
);
4214 /* We let all tests run until the end even if some fails, for debug
4216 bool any_mismatch
= false;
4218 /* Create the expected symbols list (an initializer_list). Needed
4219 because lists have commas, and we need to pass them to CHECK,
4220 which is a macro. */
4221 #define EXPECT(...) { __VA_ARGS__ }
4223 /* Wrapper for check_match that passes down the current
4224 __FILE__/__LINE__. */
4225 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4226 any_mismatch |= !check_match (__FILE__, __LINE__, \
4228 NAME, MATCH_TYPE, COMPLETION_MODE, \
4231 /* Identity checks. */
4232 for (const char *sym
: test_symbols
)
4234 /* Should be able to match all existing symbols. */
4235 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4238 /* Should be able to match all existing symbols with
4240 std::string with_params
= std::string (sym
) + "(int)";
4241 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4244 /* Should be able to match all existing symbols with
4245 parameters and qualifiers. */
4246 with_params
= std::string (sym
) + " ( int ) const";
4247 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4250 /* This should really find sym, but cp-name-parser.y doesn't
4251 know about lvalue/rvalue qualifiers yet. */
4252 with_params
= std::string (sym
) + " ( int ) &&";
4253 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4257 /* Check that the name matching algorithm for completion doesn't get
4258 confused with Latin1 'ÿ' / 0xff. */
4260 static const char str
[] = "\377";
4261 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4262 EXPECT ("\377", "\377\377123"));
4265 /* Check that the increment-last-char in the matching algorithm for
4266 completion doesn't match "t1_fund" when completing "t1_func". */
4268 static const char str
[] = "t1_func";
4269 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4270 EXPECT ("t1_func", "t1_func1"));
4273 /* Check that completion mode works at each prefix of the expected
4276 static const char str
[] = "function(int)";
4277 size_t len
= strlen (str
);
4280 for (size_t i
= 1; i
< len
; i
++)
4282 lookup
.assign (str
, i
);
4283 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4284 EXPECT ("function"));
4288 /* While "w" is a prefix of both components, the match function
4289 should still only be called once. */
4291 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4293 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4297 /* Same, with a "complicated" symbol. */
4299 static const char str
[] = Z_SYM_NAME
;
4300 size_t len
= strlen (str
);
4303 for (size_t i
= 1; i
< len
; i
++)
4305 lookup
.assign (str
, i
);
4306 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4307 EXPECT (Z_SYM_NAME
));
4311 /* In FULL mode, an incomplete symbol doesn't match. */
4313 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4317 /* A complete symbol with parameters matches any overload, since the
4318 index has no overload info. */
4320 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4321 EXPECT ("std::zfunction", "std::zfunction2"));
4322 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4323 EXPECT ("std::zfunction", "std::zfunction2"));
4324 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4325 EXPECT ("std::zfunction", "std::zfunction2"));
4328 /* Check that whitespace is ignored appropriately. A symbol with a
4329 template argument list. */
4331 static const char expected
[] = "ns::foo<int>";
4332 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4334 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4338 /* Check that whitespace is ignored appropriately. A symbol with a
4339 template argument list that includes a pointer. */
4341 static const char expected
[] = "ns::foo<char*>";
4342 /* Try both completion and non-completion modes. */
4343 static const bool completion_mode
[2] = {false, true};
4344 for (size_t i
= 0; i
< 2; i
++)
4346 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4347 completion_mode
[i
], EXPECT (expected
));
4348 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4349 completion_mode
[i
], EXPECT (expected
));
4351 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4352 completion_mode
[i
], EXPECT (expected
));
4353 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4354 completion_mode
[i
], EXPECT (expected
));
4359 /* Check method qualifiers are ignored. */
4360 static const char expected
[] = "ns::foo<char*>";
4361 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4362 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4363 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4364 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4365 CHECK_MATCH ("foo < char * > ( int ) const",
4366 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4367 CHECK_MATCH ("foo < char * > ( int ) &&",
4368 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4371 /* Test lookup names that don't match anything. */
4373 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4376 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4380 /* Some wild matching tests, exercising "(anonymous namespace)",
4381 which should not be confused with a parameter list. */
4383 static const char *syms
[] = {
4387 "A :: B :: C ( int )",
4392 for (const char *s
: syms
)
4394 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4395 EXPECT ("(anonymous namespace)::A::B::C"));
4400 static const char expected
[] = "ns2::tmpl<int>::foo2";
4401 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4403 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4407 SELF_CHECK (!any_mismatch
);
4416 test_mapped_index_find_name_component_bounds ();
4417 test_dw2_expand_symtabs_matching_symbol ();
4420 }} // namespace selftests::dw2_expand_symtabs_matching
4422 #endif /* GDB_SELF_TEST */
4424 /* If FILE_MATCHER is NULL or if PER_CU has
4425 dwarf2_per_cu_quick_data::MARK set (see
4426 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4427 EXPANSION_NOTIFY on it. */
4430 dw2_expand_symtabs_matching_one
4431 (struct dwarf2_per_cu_data
*per_cu
,
4432 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4433 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4435 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4437 bool symtab_was_null
4438 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4440 dw2_instantiate_symtab (per_cu
, false);
4442 if (expansion_notify
!= NULL
4444 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4445 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4449 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4450 matched, to expand corresponding CUs that were marked. IDX is the
4451 index of the symbol name that matched. */
4454 dw2_expand_marked_cus
4455 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4456 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4457 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4460 offset_type
*vec
, vec_len
, vec_idx
;
4461 bool global_seen
= false;
4462 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4464 vec
= (offset_type
*) (index
.constant_pool
4465 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4466 vec_len
= MAYBE_SWAP (vec
[0]);
4467 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4469 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4470 /* This value is only valid for index versions >= 7. */
4471 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4472 gdb_index_symbol_kind symbol_kind
=
4473 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4474 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4475 /* Only check the symbol attributes if they're present.
4476 Indices prior to version 7 don't record them,
4477 and indices >= 7 may elide them for certain symbols
4478 (gold does this). */
4481 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4483 /* Work around gold/15646. */
4486 if (!is_static
&& global_seen
)
4492 /* Only check the symbol's kind if it has one. */
4497 case VARIABLES_DOMAIN
:
4498 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4501 case FUNCTIONS_DOMAIN
:
4502 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4506 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4509 case MODULES_DOMAIN
:
4510 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4518 /* Don't crash on bad data. */
4519 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4520 + dwarf2_per_objfile
->all_type_units
.size ()))
4522 complaint (_(".gdb_index entry has bad CU index"
4524 objfile_name (dwarf2_per_objfile
->objfile
));
4528 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4529 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4534 /* If FILE_MATCHER is non-NULL, set all the
4535 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4536 that match FILE_MATCHER. */
4539 dw_expand_symtabs_matching_file_matcher
4540 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4541 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4543 if (file_matcher
== NULL
)
4546 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4548 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4550 NULL
, xcalloc
, xfree
));
4551 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4553 NULL
, xcalloc
, xfree
));
4555 /* The rule is CUs specify all the files, including those used by
4556 any TU, so there's no need to scan TUs here. */
4558 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4562 per_cu
->v
.quick
->mark
= 0;
4564 /* We only need to look at symtabs not already expanded. */
4565 if (per_cu
->v
.quick
->compunit_symtab
)
4568 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4569 if (file_data
== NULL
)
4572 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4574 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4576 per_cu
->v
.quick
->mark
= 1;
4580 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4582 const char *this_real_name
;
4584 if (file_matcher (file_data
->file_names
[j
], false))
4586 per_cu
->v
.quick
->mark
= 1;
4590 /* Before we invoke realpath, which can get expensive when many
4591 files are involved, do a quick comparison of the basenames. */
4592 if (!basenames_may_differ
4593 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4597 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4598 if (file_matcher (this_real_name
, false))
4600 per_cu
->v
.quick
->mark
= 1;
4605 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4606 ? visited_found
.get ()
4607 : visited_not_found
.get (),
4614 dw2_expand_symtabs_matching
4615 (struct objfile
*objfile
,
4616 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4617 const lookup_name_info
&lookup_name
,
4618 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4619 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4620 enum search_domain kind
)
4622 struct dwarf2_per_objfile
*dwarf2_per_objfile
4623 = get_dwarf2_per_objfile (objfile
);
4625 /* index_table is NULL if OBJF_READNOW. */
4626 if (!dwarf2_per_objfile
->index_table
)
4629 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4631 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4633 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4635 kind
, [&] (offset_type idx
)
4637 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4638 expansion_notify
, kind
);
4643 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4646 static struct compunit_symtab
*
4647 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4652 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4653 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4656 if (cust
->includes
== NULL
)
4659 for (i
= 0; cust
->includes
[i
]; ++i
)
4661 struct compunit_symtab
*s
= cust
->includes
[i
];
4663 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4671 static struct compunit_symtab
*
4672 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4673 struct bound_minimal_symbol msymbol
,
4675 struct obj_section
*section
,
4678 struct dwarf2_per_cu_data
*data
;
4679 struct compunit_symtab
*result
;
4681 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4684 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4685 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4686 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4690 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4691 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4692 paddress (get_objfile_arch (objfile
), pc
));
4695 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4698 gdb_assert (result
!= NULL
);
4703 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4704 void *data
, int need_fullname
)
4706 struct dwarf2_per_objfile
*dwarf2_per_objfile
4707 = get_dwarf2_per_objfile (objfile
);
4709 if (!dwarf2_per_objfile
->filenames_cache
)
4711 dwarf2_per_objfile
->filenames_cache
.emplace ();
4713 htab_up
visited (htab_create_alloc (10,
4714 htab_hash_pointer
, htab_eq_pointer
,
4715 NULL
, xcalloc
, xfree
));
4717 /* The rule is CUs specify all the files, including those used
4718 by any TU, so there's no need to scan TUs here. We can
4719 ignore file names coming from already-expanded CUs. */
4721 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4723 if (per_cu
->v
.quick
->compunit_symtab
)
4725 void **slot
= htab_find_slot (visited
.get (),
4726 per_cu
->v
.quick
->file_names
,
4729 *slot
= per_cu
->v
.quick
->file_names
;
4733 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4735 /* We only need to look at symtabs not already expanded. */
4736 if (per_cu
->v
.quick
->compunit_symtab
)
4739 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4740 if (file_data
== NULL
)
4743 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4746 /* Already visited. */
4751 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4753 const char *filename
= file_data
->file_names
[j
];
4754 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4759 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4761 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4764 this_real_name
= gdb_realpath (filename
);
4765 (*fun
) (filename
, this_real_name
.get (), data
);
4770 dw2_has_symbols (struct objfile
*objfile
)
4775 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4778 dw2_find_last_source_symtab
,
4779 dw2_forget_cached_source_info
,
4780 dw2_map_symtabs_matching_filename
,
4784 dw2_expand_symtabs_for_function
,
4785 dw2_expand_all_symtabs
,
4786 dw2_expand_symtabs_with_fullname
,
4787 dw2_map_matching_symbols
,
4788 dw2_expand_symtabs_matching
,
4789 dw2_find_pc_sect_compunit_symtab
,
4791 dw2_map_symbol_filenames
4794 /* DWARF-5 debug_names reader. */
4796 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4797 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4799 /* A helper function that reads the .debug_names section in SECTION
4800 and fills in MAP. FILENAME is the name of the file containing the
4801 section; it is used for error reporting.
4803 Returns true if all went well, false otherwise. */
4806 read_debug_names_from_section (struct objfile
*objfile
,
4807 const char *filename
,
4808 struct dwarf2_section_info
*section
,
4809 mapped_debug_names
&map
)
4811 if (section
->empty ())
4814 /* Older elfutils strip versions could keep the section in the main
4815 executable while splitting it for the separate debug info file. */
4816 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4819 section
->read (objfile
);
4821 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4823 const gdb_byte
*addr
= section
->buffer
;
4825 bfd
*const abfd
= section
->get_bfd_owner ();
4827 unsigned int bytes_read
;
4828 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4831 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4832 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4833 if (bytes_read
+ length
!= section
->size
)
4835 /* There may be multiple per-CU indices. */
4836 warning (_("Section .debug_names in %s length %s does not match "
4837 "section length %s, ignoring .debug_names."),
4838 filename
, plongest (bytes_read
+ length
),
4839 pulongest (section
->size
));
4843 /* The version number. */
4844 uint16_t version
= read_2_bytes (abfd
, addr
);
4848 warning (_("Section .debug_names in %s has unsupported version %d, "
4849 "ignoring .debug_names."),
4855 uint16_t padding
= read_2_bytes (abfd
, addr
);
4859 warning (_("Section .debug_names in %s has unsupported padding %d, "
4860 "ignoring .debug_names."),
4865 /* comp_unit_count - The number of CUs in the CU list. */
4866 map
.cu_count
= read_4_bytes (abfd
, addr
);
4869 /* local_type_unit_count - The number of TUs in the local TU
4871 map
.tu_count
= read_4_bytes (abfd
, addr
);
4874 /* foreign_type_unit_count - The number of TUs in the foreign TU
4876 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4878 if (foreign_tu_count
!= 0)
4880 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4881 "ignoring .debug_names."),
4882 filename
, static_cast<unsigned long> (foreign_tu_count
));
4886 /* bucket_count - The number of hash buckets in the hash lookup
4888 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4891 /* name_count - The number of unique names in the index. */
4892 map
.name_count
= read_4_bytes (abfd
, addr
);
4895 /* abbrev_table_size - The size in bytes of the abbreviations
4897 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4900 /* augmentation_string_size - The size in bytes of the augmentation
4901 string. This value is rounded up to a multiple of 4. */
4902 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4904 map
.augmentation_is_gdb
= ((augmentation_string_size
4905 == sizeof (dwarf5_augmentation
))
4906 && memcmp (addr
, dwarf5_augmentation
,
4907 sizeof (dwarf5_augmentation
)) == 0);
4908 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4909 addr
+= augmentation_string_size
;
4912 map
.cu_table_reordered
= addr
;
4913 addr
+= map
.cu_count
* map
.offset_size
;
4915 /* List of Local TUs */
4916 map
.tu_table_reordered
= addr
;
4917 addr
+= map
.tu_count
* map
.offset_size
;
4919 /* Hash Lookup Table */
4920 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4921 addr
+= map
.bucket_count
* 4;
4922 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4923 addr
+= map
.name_count
* 4;
4926 map
.name_table_string_offs_reordered
= addr
;
4927 addr
+= map
.name_count
* map
.offset_size
;
4928 map
.name_table_entry_offs_reordered
= addr
;
4929 addr
+= map
.name_count
* map
.offset_size
;
4931 const gdb_byte
*abbrev_table_start
= addr
;
4934 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4939 const auto insertpair
4940 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4941 if (!insertpair
.second
)
4943 warning (_("Section .debug_names in %s has duplicate index %s, "
4944 "ignoring .debug_names."),
4945 filename
, pulongest (index_num
));
4948 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4949 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4954 mapped_debug_names::index_val::attr attr
;
4955 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4957 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4959 if (attr
.form
== DW_FORM_implicit_const
)
4961 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4965 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4967 indexval
.attr_vec
.push_back (std::move (attr
));
4970 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4972 warning (_("Section .debug_names in %s has abbreviation_table "
4973 "of size %s vs. written as %u, ignoring .debug_names."),
4974 filename
, plongest (addr
- abbrev_table_start
),
4978 map
.entry_pool
= addr
;
4983 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4987 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4988 const mapped_debug_names
&map
,
4989 dwarf2_section_info
§ion
,
4992 sect_offset sect_off_prev
;
4993 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4995 sect_offset sect_off_next
;
4996 if (i
< map
.cu_count
)
4999 = (sect_offset
) (extract_unsigned_integer
5000 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5002 map
.dwarf5_byte_order
));
5005 sect_off_next
= (sect_offset
) section
.size
;
5008 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5009 dwarf2_per_cu_data
*per_cu
5010 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5011 sect_off_prev
, length
);
5012 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5014 sect_off_prev
= sect_off_next
;
5018 /* Read the CU list from the mapped index, and use it to create all
5019 the CU objects for this dwarf2_per_objfile. */
5022 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5023 const mapped_debug_names
&map
,
5024 const mapped_debug_names
&dwz_map
)
5026 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5027 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5029 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5030 dwarf2_per_objfile
->info
,
5031 false /* is_dwz */);
5033 if (dwz_map
.cu_count
== 0)
5036 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5037 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5041 /* Read .debug_names. If everything went ok, initialize the "quick"
5042 elements of all the CUs and return true. Otherwise, return false. */
5045 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5047 std::unique_ptr
<mapped_debug_names
> map
5048 (new mapped_debug_names (dwarf2_per_objfile
));
5049 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5050 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5052 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5053 &dwarf2_per_objfile
->debug_names
,
5057 /* Don't use the index if it's empty. */
5058 if (map
->name_count
== 0)
5061 /* If there is a .dwz file, read it so we can get its CU list as
5063 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5066 if (!read_debug_names_from_section (objfile
,
5067 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5068 &dwz
->debug_names
, dwz_map
))
5070 warning (_("could not read '.debug_names' section from %s; skipping"),
5071 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5076 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5078 if (map
->tu_count
!= 0)
5080 /* We can only handle a single .debug_types when we have an
5082 if (dwarf2_per_objfile
->types
.size () != 1)
5085 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5087 create_signatured_type_table_from_debug_names
5088 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5091 create_addrmap_from_aranges (dwarf2_per_objfile
,
5092 &dwarf2_per_objfile
->debug_aranges
);
5094 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5095 dwarf2_per_objfile
->using_index
= 1;
5096 dwarf2_per_objfile
->quick_file_names_table
=
5097 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5102 /* Type used to manage iterating over all CUs looking for a symbol for
5105 class dw2_debug_names_iterator
5108 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5109 gdb::optional
<block_enum
> block_index
,
5112 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5113 m_addr (find_vec_in_debug_names (map
, name
))
5116 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5117 search_domain search
, uint32_t namei
)
5120 m_addr (find_vec_in_debug_names (map
, namei
))
5123 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5124 block_enum block_index
, domain_enum domain
,
5126 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5127 m_addr (find_vec_in_debug_names (map
, namei
))
5130 /* Return the next matching CU or NULL if there are no more. */
5131 dwarf2_per_cu_data
*next ();
5134 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5136 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5139 /* The internalized form of .debug_names. */
5140 const mapped_debug_names
&m_map
;
5142 /* If set, only look for symbols that match that block. Valid values are
5143 GLOBAL_BLOCK and STATIC_BLOCK. */
5144 const gdb::optional
<block_enum
> m_block_index
;
5146 /* The kind of symbol we're looking for. */
5147 const domain_enum m_domain
= UNDEF_DOMAIN
;
5148 const search_domain m_search
= ALL_DOMAIN
;
5150 /* The list of CUs from the index entry of the symbol, or NULL if
5152 const gdb_byte
*m_addr
;
5156 mapped_debug_names::namei_to_name (uint32_t namei
) const
5158 const ULONGEST namei_string_offs
5159 = extract_unsigned_integer ((name_table_string_offs_reordered
5160 + namei
* offset_size
),
5163 return read_indirect_string_at_offset
5164 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5167 /* Find a slot in .debug_names for the object named NAME. If NAME is
5168 found, return pointer to its pool data. If NAME cannot be found,
5172 dw2_debug_names_iterator::find_vec_in_debug_names
5173 (const mapped_debug_names
&map
, const char *name
)
5175 int (*cmp
) (const char *, const char *);
5177 gdb::unique_xmalloc_ptr
<char> without_params
;
5178 if (current_language
->la_language
== language_cplus
5179 || current_language
->la_language
== language_fortran
5180 || current_language
->la_language
== language_d
)
5182 /* NAME is already canonical. Drop any qualifiers as
5183 .debug_names does not contain any. */
5185 if (strchr (name
, '(') != NULL
)
5187 without_params
= cp_remove_params (name
);
5188 if (without_params
!= NULL
)
5189 name
= without_params
.get ();
5193 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5195 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5197 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5198 (map
.bucket_table_reordered
5199 + (full_hash
% map
.bucket_count
)), 4,
5200 map
.dwarf5_byte_order
);
5204 if (namei
>= map
.name_count
)
5206 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5208 namei
, map
.name_count
,
5209 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5215 const uint32_t namei_full_hash
5216 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5217 (map
.hash_table_reordered
+ namei
), 4,
5218 map
.dwarf5_byte_order
);
5219 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5222 if (full_hash
== namei_full_hash
)
5224 const char *const namei_string
= map
.namei_to_name (namei
);
5226 #if 0 /* An expensive sanity check. */
5227 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5229 complaint (_("Wrong .debug_names hash for string at index %u "
5231 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5236 if (cmp (namei_string
, name
) == 0)
5238 const ULONGEST namei_entry_offs
5239 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5240 + namei
* map
.offset_size
),
5241 map
.offset_size
, map
.dwarf5_byte_order
);
5242 return map
.entry_pool
+ namei_entry_offs
;
5247 if (namei
>= map
.name_count
)
5253 dw2_debug_names_iterator::find_vec_in_debug_names
5254 (const mapped_debug_names
&map
, uint32_t namei
)
5256 if (namei
>= map
.name_count
)
5258 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5260 namei
, map
.name_count
,
5261 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5265 const ULONGEST namei_entry_offs
5266 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5267 + namei
* map
.offset_size
),
5268 map
.offset_size
, map
.dwarf5_byte_order
);
5269 return map
.entry_pool
+ namei_entry_offs
;
5272 /* See dw2_debug_names_iterator. */
5274 dwarf2_per_cu_data
*
5275 dw2_debug_names_iterator::next ()
5280 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5281 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5282 bfd
*const abfd
= objfile
->obfd
;
5286 unsigned int bytes_read
;
5287 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5288 m_addr
+= bytes_read
;
5292 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5293 if (indexval_it
== m_map
.abbrev_map
.cend ())
5295 complaint (_("Wrong .debug_names undefined abbrev code %s "
5297 pulongest (abbrev
), objfile_name (objfile
));
5300 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5301 enum class symbol_linkage
{
5305 } symbol_linkage_
= symbol_linkage::unknown
;
5306 dwarf2_per_cu_data
*per_cu
= NULL
;
5307 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5312 case DW_FORM_implicit_const
:
5313 ull
= attr
.implicit_const
;
5315 case DW_FORM_flag_present
:
5319 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5320 m_addr
+= bytes_read
;
5323 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5324 dwarf_form_name (attr
.form
),
5325 objfile_name (objfile
));
5328 switch (attr
.dw_idx
)
5330 case DW_IDX_compile_unit
:
5331 /* Don't crash on bad data. */
5332 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5334 complaint (_(".debug_names entry has bad CU index %s"
5337 objfile_name (dwarf2_per_objfile
->objfile
));
5340 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5342 case DW_IDX_type_unit
:
5343 /* Don't crash on bad data. */
5344 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5346 complaint (_(".debug_names entry has bad TU index %s"
5349 objfile_name (dwarf2_per_objfile
->objfile
));
5352 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5354 case DW_IDX_GNU_internal
:
5355 if (!m_map
.augmentation_is_gdb
)
5357 symbol_linkage_
= symbol_linkage::static_
;
5359 case DW_IDX_GNU_external
:
5360 if (!m_map
.augmentation_is_gdb
)
5362 symbol_linkage_
= symbol_linkage::extern_
;
5367 /* Skip if already read in. */
5368 if (per_cu
->v
.quick
->compunit_symtab
)
5371 /* Check static vs global. */
5372 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5374 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5375 const bool symbol_is_static
=
5376 symbol_linkage_
== symbol_linkage::static_
;
5377 if (want_static
!= symbol_is_static
)
5381 /* Match dw2_symtab_iter_next, symbol_kind
5382 and debug_names::psymbol_tag. */
5386 switch (indexval
.dwarf_tag
)
5388 case DW_TAG_variable
:
5389 case DW_TAG_subprogram
:
5390 /* Some types are also in VAR_DOMAIN. */
5391 case DW_TAG_typedef
:
5392 case DW_TAG_structure_type
:
5399 switch (indexval
.dwarf_tag
)
5401 case DW_TAG_typedef
:
5402 case DW_TAG_structure_type
:
5409 switch (indexval
.dwarf_tag
)
5412 case DW_TAG_variable
:
5419 switch (indexval
.dwarf_tag
)
5431 /* Match dw2_expand_symtabs_matching, symbol_kind and
5432 debug_names::psymbol_tag. */
5435 case VARIABLES_DOMAIN
:
5436 switch (indexval
.dwarf_tag
)
5438 case DW_TAG_variable
:
5444 case FUNCTIONS_DOMAIN
:
5445 switch (indexval
.dwarf_tag
)
5447 case DW_TAG_subprogram
:
5454 switch (indexval
.dwarf_tag
)
5456 case DW_TAG_typedef
:
5457 case DW_TAG_structure_type
:
5463 case MODULES_DOMAIN
:
5464 switch (indexval
.dwarf_tag
)
5478 static struct compunit_symtab
*
5479 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5480 const char *name
, domain_enum domain
)
5482 struct dwarf2_per_objfile
*dwarf2_per_objfile
5483 = get_dwarf2_per_objfile (objfile
);
5485 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5488 /* index is NULL if OBJF_READNOW. */
5491 const auto &map
= *mapp
;
5493 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5495 struct compunit_symtab
*stab_best
= NULL
;
5496 struct dwarf2_per_cu_data
*per_cu
;
5497 while ((per_cu
= iter
.next ()) != NULL
)
5499 struct symbol
*sym
, *with_opaque
= NULL
;
5500 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5501 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5502 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5504 sym
= block_find_symbol (block
, name
, domain
,
5505 block_find_non_opaque_type_preferred
,
5508 /* Some caution must be observed with overloaded functions and
5509 methods, since the index will not contain any overload
5510 information (but NAME might contain it). */
5513 && strcmp_iw (sym
->search_name (), name
) == 0)
5515 if (with_opaque
!= NULL
5516 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5519 /* Keep looking through other CUs. */
5525 /* This dumps minimal information about .debug_names. It is called
5526 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5527 uses this to verify that .debug_names has been loaded. */
5530 dw2_debug_names_dump (struct objfile
*objfile
)
5532 struct dwarf2_per_objfile
*dwarf2_per_objfile
5533 = get_dwarf2_per_objfile (objfile
);
5535 gdb_assert (dwarf2_per_objfile
->using_index
);
5536 printf_filtered (".debug_names:");
5537 if (dwarf2_per_objfile
->debug_names_table
)
5538 printf_filtered (" exists\n");
5540 printf_filtered (" faked for \"readnow\"\n");
5541 printf_filtered ("\n");
5545 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5546 const char *func_name
)
5548 struct dwarf2_per_objfile
*dwarf2_per_objfile
5549 = get_dwarf2_per_objfile (objfile
);
5551 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5552 if (dwarf2_per_objfile
->debug_names_table
)
5554 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5556 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5558 struct dwarf2_per_cu_data
*per_cu
;
5559 while ((per_cu
= iter
.next ()) != NULL
)
5560 dw2_instantiate_symtab (per_cu
, false);
5565 dw2_debug_names_map_matching_symbols
5566 (struct objfile
*objfile
,
5567 const lookup_name_info
&name
, domain_enum domain
,
5569 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5570 symbol_compare_ftype
*ordered_compare
)
5572 struct dwarf2_per_objfile
*dwarf2_per_objfile
5573 = get_dwarf2_per_objfile (objfile
);
5575 /* debug_names_table is NULL if OBJF_READNOW. */
5576 if (!dwarf2_per_objfile
->debug_names_table
)
5579 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5580 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5582 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5583 auto matcher
= [&] (const char *symname
)
5585 if (ordered_compare
== nullptr)
5587 return ordered_compare (symname
, match_name
) == 0;
5590 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5591 [&] (offset_type namei
)
5593 /* The name was matched, now expand corresponding CUs that were
5595 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5597 struct dwarf2_per_cu_data
*per_cu
;
5598 while ((per_cu
= iter
.next ()) != NULL
)
5599 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5603 /* It's a shame we couldn't do this inside the
5604 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5605 that have already been expanded. Instead, this loop matches what
5606 the psymtab code does. */
5607 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5609 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5610 if (cust
!= nullptr)
5612 const struct block
*block
5613 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5614 if (!iterate_over_symbols_terminated (block
, name
,
5622 dw2_debug_names_expand_symtabs_matching
5623 (struct objfile
*objfile
,
5624 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5625 const lookup_name_info
&lookup_name
,
5626 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5627 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5628 enum search_domain kind
)
5630 struct dwarf2_per_objfile
*dwarf2_per_objfile
5631 = get_dwarf2_per_objfile (objfile
);
5633 /* debug_names_table is NULL if OBJF_READNOW. */
5634 if (!dwarf2_per_objfile
->debug_names_table
)
5637 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5639 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5641 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5643 kind
, [&] (offset_type namei
)
5645 /* The name was matched, now expand corresponding CUs that were
5647 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5649 struct dwarf2_per_cu_data
*per_cu
;
5650 while ((per_cu
= iter
.next ()) != NULL
)
5651 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5657 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5660 dw2_find_last_source_symtab
,
5661 dw2_forget_cached_source_info
,
5662 dw2_map_symtabs_matching_filename
,
5663 dw2_debug_names_lookup_symbol
,
5665 dw2_debug_names_dump
,
5666 dw2_debug_names_expand_symtabs_for_function
,
5667 dw2_expand_all_symtabs
,
5668 dw2_expand_symtabs_with_fullname
,
5669 dw2_debug_names_map_matching_symbols
,
5670 dw2_debug_names_expand_symtabs_matching
,
5671 dw2_find_pc_sect_compunit_symtab
,
5673 dw2_map_symbol_filenames
5676 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5677 to either a dwarf2_per_objfile or dwz_file object. */
5679 template <typename T
>
5680 static gdb::array_view
<const gdb_byte
>
5681 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5683 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5685 if (section
->empty ())
5688 /* Older elfutils strip versions could keep the section in the main
5689 executable while splitting it for the separate debug info file. */
5690 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5693 section
->read (obj
);
5695 /* dwarf2_section_info::size is a bfd_size_type, while
5696 gdb::array_view works with size_t. On 32-bit hosts, with
5697 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5698 is 32-bit. So we need an explicit narrowing conversion here.
5699 This is fine, because it's impossible to allocate or mmap an
5700 array/buffer larger than what size_t can represent. */
5701 return gdb::make_array_view (section
->buffer
, section
->size
);
5704 /* Lookup the index cache for the contents of the index associated to
5707 static gdb::array_view
<const gdb_byte
>
5708 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5710 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5711 if (build_id
== nullptr)
5714 return global_index_cache
.lookup_gdb_index (build_id
,
5715 &dwarf2_obj
->index_cache_res
);
5718 /* Same as the above, but for DWZ. */
5720 static gdb::array_view
<const gdb_byte
>
5721 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5723 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5724 if (build_id
== nullptr)
5727 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5730 /* See symfile.h. */
5733 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5735 struct dwarf2_per_objfile
*dwarf2_per_objfile
5736 = get_dwarf2_per_objfile (objfile
);
5738 /* If we're about to read full symbols, don't bother with the
5739 indices. In this case we also don't care if some other debug
5740 format is making psymtabs, because they are all about to be
5742 if ((objfile
->flags
& OBJF_READNOW
))
5744 dwarf2_per_objfile
->using_index
= 1;
5745 create_all_comp_units (dwarf2_per_objfile
);
5746 create_all_type_units (dwarf2_per_objfile
);
5747 dwarf2_per_objfile
->quick_file_names_table
5748 = create_quick_file_names_table
5749 (dwarf2_per_objfile
->all_comp_units
.size ());
5751 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5752 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5754 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5756 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5757 struct dwarf2_per_cu_quick_data
);
5760 /* Return 1 so that gdb sees the "quick" functions. However,
5761 these functions will be no-ops because we will have expanded
5763 *index_kind
= dw_index_kind::GDB_INDEX
;
5767 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5769 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5773 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5774 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5775 get_gdb_index_contents_from_section
<dwz_file
>))
5777 *index_kind
= dw_index_kind::GDB_INDEX
;
5781 /* ... otherwise, try to find the index in the index cache. */
5782 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5783 get_gdb_index_contents_from_cache
,
5784 get_gdb_index_contents_from_cache_dwz
))
5786 global_index_cache
.hit ();
5787 *index_kind
= dw_index_kind::GDB_INDEX
;
5791 global_index_cache
.miss ();
5797 /* Build a partial symbol table. */
5800 dwarf2_build_psymtabs (struct objfile
*objfile
)
5802 struct dwarf2_per_objfile
*dwarf2_per_objfile
5803 = get_dwarf2_per_objfile (objfile
);
5805 init_psymbol_list (objfile
, 1024);
5809 /* This isn't really ideal: all the data we allocate on the
5810 objfile's obstack is still uselessly kept around. However,
5811 freeing it seems unsafe. */
5812 psymtab_discarder
psymtabs (objfile
);
5813 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5816 /* (maybe) store an index in the cache. */
5817 global_index_cache
.store (dwarf2_per_objfile
);
5819 catch (const gdb_exception_error
&except
)
5821 exception_print (gdb_stderr
, except
);
5825 /* Find the base address of the compilation unit for range lists and
5826 location lists. It will normally be specified by DW_AT_low_pc.
5827 In DWARF-3 draft 4, the base address could be overridden by
5828 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5829 compilation units with discontinuous ranges. */
5832 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5834 struct attribute
*attr
;
5837 cu
->base_address
= 0;
5839 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5840 if (attr
!= nullptr)
5842 cu
->base_address
= attr
->value_as_address ();
5847 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5848 if (attr
!= nullptr)
5850 cu
->base_address
= attr
->value_as_address ();
5856 /* Helper function that returns the proper abbrev section for
5859 static struct dwarf2_section_info
*
5860 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5862 struct dwarf2_section_info
*abbrev
;
5863 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5865 if (this_cu
->is_dwz
)
5866 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5868 abbrev
= &dwarf2_per_objfile
->abbrev
;
5873 /* Fetch the abbreviation table offset from a comp or type unit header. */
5876 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5877 struct dwarf2_section_info
*section
,
5878 sect_offset sect_off
)
5880 bfd
*abfd
= section
->get_bfd_owner ();
5881 const gdb_byte
*info_ptr
;
5882 unsigned int initial_length_size
, offset_size
;
5885 section
->read (dwarf2_per_objfile
->objfile
);
5886 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5887 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5888 offset_size
= initial_length_size
== 4 ? 4 : 8;
5889 info_ptr
+= initial_length_size
;
5891 version
= read_2_bytes (abfd
, info_ptr
);
5895 /* Skip unit type and address size. */
5899 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5902 /* Allocate a new partial symtab for file named NAME and mark this new
5903 partial symtab as being an include of PST. */
5906 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5907 struct objfile
*objfile
)
5909 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
5911 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5913 /* It shares objfile->objfile_obstack. */
5914 subpst
->dirname
= pst
->dirname
;
5917 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5918 subpst
->dependencies
[0] = pst
;
5919 subpst
->number_of_dependencies
= 1;
5921 /* No private part is necessary for include psymtabs. This property
5922 can be used to differentiate between such include psymtabs and
5923 the regular ones. */
5924 subpst
->per_cu_data
= nullptr;
5927 /* Read the Line Number Program data and extract the list of files
5928 included by the source file represented by PST. Build an include
5929 partial symtab for each of these included files. */
5932 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5933 struct die_info
*die
,
5934 dwarf2_psymtab
*pst
)
5937 struct attribute
*attr
;
5939 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5940 if (attr
!= nullptr)
5941 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5943 return; /* No linetable, so no includes. */
5945 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5946 that we pass in the raw text_low here; that is ok because we're
5947 only decoding the line table to make include partial symtabs, and
5948 so the addresses aren't really used. */
5949 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5950 pst
->raw_text_low (), 1);
5954 hash_signatured_type (const void *item
)
5956 const struct signatured_type
*sig_type
5957 = (const struct signatured_type
*) item
;
5959 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5960 return sig_type
->signature
;
5964 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5966 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5967 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5969 return lhs
->signature
== rhs
->signature
;
5972 /* Allocate a hash table for signatured types. */
5975 allocate_signatured_type_table (struct objfile
*objfile
)
5977 return htab_up (htab_create_alloc (41,
5978 hash_signatured_type
,
5980 NULL
, xcalloc
, xfree
));
5983 /* A helper function to add a signatured type CU to a table. */
5986 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5988 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5989 std::vector
<signatured_type
*> *all_type_units
5990 = (std::vector
<signatured_type
*> *) datum
;
5992 all_type_units
->push_back (sigt
);
5997 /* A helper for create_debug_types_hash_table. Read types from SECTION
5998 and fill them into TYPES_HTAB. It will process only type units,
5999 therefore DW_UT_type. */
6002 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6003 struct dwo_file
*dwo_file
,
6004 dwarf2_section_info
*section
, htab_up
&types_htab
,
6005 rcuh_kind section_kind
)
6007 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6008 struct dwarf2_section_info
*abbrev_section
;
6010 const gdb_byte
*info_ptr
, *end_ptr
;
6012 abbrev_section
= (dwo_file
!= NULL
6013 ? &dwo_file
->sections
.abbrev
6014 : &dwarf2_per_objfile
->abbrev
);
6016 if (dwarf_read_debug
)
6017 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6018 section
->get_name (),
6019 abbrev_section
->get_file_name ());
6021 section
->read (objfile
);
6022 info_ptr
= section
->buffer
;
6024 if (info_ptr
== NULL
)
6027 /* We can't set abfd until now because the section may be empty or
6028 not present, in which case the bfd is unknown. */
6029 abfd
= section
->get_bfd_owner ();
6031 /* We don't use cutu_reader here because we don't need to read
6032 any dies: the signature is in the header. */
6034 end_ptr
= info_ptr
+ section
->size
;
6035 while (info_ptr
< end_ptr
)
6037 struct signatured_type
*sig_type
;
6038 struct dwo_unit
*dwo_tu
;
6040 const gdb_byte
*ptr
= info_ptr
;
6041 struct comp_unit_head header
;
6042 unsigned int length
;
6044 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6046 /* Initialize it due to a false compiler warning. */
6047 header
.signature
= -1;
6048 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6050 /* We need to read the type's signature in order to build the hash
6051 table, but we don't need anything else just yet. */
6053 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6054 abbrev_section
, ptr
, section_kind
);
6056 length
= header
.get_length ();
6058 /* Skip dummy type units. */
6059 if (ptr
>= info_ptr
+ length
6060 || peek_abbrev_code (abfd
, ptr
) == 0
6061 || header
.unit_type
!= DW_UT_type
)
6067 if (types_htab
== NULL
)
6070 types_htab
= allocate_dwo_unit_table (objfile
);
6072 types_htab
= allocate_signatured_type_table (objfile
);
6078 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6080 dwo_tu
->dwo_file
= dwo_file
;
6081 dwo_tu
->signature
= header
.signature
;
6082 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6083 dwo_tu
->section
= section
;
6084 dwo_tu
->sect_off
= sect_off
;
6085 dwo_tu
->length
= length
;
6089 /* N.B.: type_offset is not usable if this type uses a DWO file.
6090 The real type_offset is in the DWO file. */
6092 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6093 struct signatured_type
);
6094 sig_type
->signature
= header
.signature
;
6095 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6096 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6097 sig_type
->per_cu
.is_debug_types
= 1;
6098 sig_type
->per_cu
.section
= section
;
6099 sig_type
->per_cu
.sect_off
= sect_off
;
6100 sig_type
->per_cu
.length
= length
;
6103 slot
= htab_find_slot (types_htab
.get (),
6104 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6106 gdb_assert (slot
!= NULL
);
6109 sect_offset dup_sect_off
;
6113 const struct dwo_unit
*dup_tu
6114 = (const struct dwo_unit
*) *slot
;
6116 dup_sect_off
= dup_tu
->sect_off
;
6120 const struct signatured_type
*dup_tu
6121 = (const struct signatured_type
*) *slot
;
6123 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6126 complaint (_("debug type entry at offset %s is duplicate to"
6127 " the entry at offset %s, signature %s"),
6128 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6129 hex_string (header
.signature
));
6131 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6133 if (dwarf_read_debug
> 1)
6134 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6135 sect_offset_str (sect_off
),
6136 hex_string (header
.signature
));
6142 /* Create the hash table of all entries in the .debug_types
6143 (or .debug_types.dwo) section(s).
6144 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6145 otherwise it is NULL.
6147 The result is a pointer to the hash table or NULL if there are no types.
6149 Note: This function processes DWO files only, not DWP files. */
6152 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6153 struct dwo_file
*dwo_file
,
6154 gdb::array_view
<dwarf2_section_info
> type_sections
,
6155 htab_up
&types_htab
)
6157 for (dwarf2_section_info
§ion
: type_sections
)
6158 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6159 types_htab
, rcuh_kind::TYPE
);
6162 /* Create the hash table of all entries in the .debug_types section,
6163 and initialize all_type_units.
6164 The result is zero if there is an error (e.g. missing .debug_types section),
6165 otherwise non-zero. */
6168 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6172 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6173 &dwarf2_per_objfile
->info
, types_htab
,
6174 rcuh_kind::COMPILE
);
6175 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6176 dwarf2_per_objfile
->types
, types_htab
);
6177 if (types_htab
== NULL
)
6179 dwarf2_per_objfile
->signatured_types
= NULL
;
6183 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6185 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6186 dwarf2_per_objfile
->all_type_units
.reserve
6187 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6189 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6190 add_signatured_type_cu_to_table
,
6191 &dwarf2_per_objfile
->all_type_units
);
6196 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6197 If SLOT is non-NULL, it is the entry to use in the hash table.
6198 Otherwise we find one. */
6200 static struct signatured_type
*
6201 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6204 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6206 if (dwarf2_per_objfile
->all_type_units
.size ()
6207 == dwarf2_per_objfile
->all_type_units
.capacity ())
6208 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6210 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6211 struct signatured_type
);
6213 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6214 sig_type
->signature
= sig
;
6215 sig_type
->per_cu
.is_debug_types
= 1;
6216 if (dwarf2_per_objfile
->using_index
)
6218 sig_type
->per_cu
.v
.quick
=
6219 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6220 struct dwarf2_per_cu_quick_data
);
6225 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6228 gdb_assert (*slot
== NULL
);
6230 /* The rest of sig_type must be filled in by the caller. */
6234 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6235 Fill in SIG_ENTRY with DWO_ENTRY. */
6238 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6239 struct signatured_type
*sig_entry
,
6240 struct dwo_unit
*dwo_entry
)
6242 /* Make sure we're not clobbering something we don't expect to. */
6243 gdb_assert (! sig_entry
->per_cu
.queued
);
6244 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6245 if (dwarf2_per_objfile
->using_index
)
6247 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6248 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6251 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6252 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6253 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6254 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6255 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6257 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6258 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6259 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6260 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6261 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6262 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6263 sig_entry
->dwo_unit
= dwo_entry
;
6266 /* Subroutine of lookup_signatured_type.
6267 If we haven't read the TU yet, create the signatured_type data structure
6268 for a TU to be read in directly from a DWO file, bypassing the stub.
6269 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6270 using .gdb_index, then when reading a CU we want to stay in the DWO file
6271 containing that CU. Otherwise we could end up reading several other DWO
6272 files (due to comdat folding) to process the transitive closure of all the
6273 mentioned TUs, and that can be slow. The current DWO file will have every
6274 type signature that it needs.
6275 We only do this for .gdb_index because in the psymtab case we already have
6276 to read all the DWOs to build the type unit groups. */
6278 static struct signatured_type
*
6279 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6281 struct dwarf2_per_objfile
*dwarf2_per_objfile
6282 = cu
->per_cu
->dwarf2_per_objfile
;
6283 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6284 struct dwo_file
*dwo_file
;
6285 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6286 struct signatured_type find_sig_entry
, *sig_entry
;
6289 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6291 /* If TU skeletons have been removed then we may not have read in any
6293 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6295 dwarf2_per_objfile
->signatured_types
6296 = allocate_signatured_type_table (objfile
);
6299 /* We only ever need to read in one copy of a signatured type.
6300 Use the global signatured_types array to do our own comdat-folding
6301 of types. If this is the first time we're reading this TU, and
6302 the TU has an entry in .gdb_index, replace the recorded data from
6303 .gdb_index with this TU. */
6305 find_sig_entry
.signature
= sig
;
6306 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6307 &find_sig_entry
, INSERT
);
6308 sig_entry
= (struct signatured_type
*) *slot
;
6310 /* We can get here with the TU already read, *or* in the process of being
6311 read. Don't reassign the global entry to point to this DWO if that's
6312 the case. Also note that if the TU is already being read, it may not
6313 have come from a DWO, the program may be a mix of Fission-compiled
6314 code and non-Fission-compiled code. */
6316 /* Have we already tried to read this TU?
6317 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6318 needn't exist in the global table yet). */
6319 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6322 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6323 dwo_unit of the TU itself. */
6324 dwo_file
= cu
->dwo_unit
->dwo_file
;
6326 /* Ok, this is the first time we're reading this TU. */
6327 if (dwo_file
->tus
== NULL
)
6329 find_dwo_entry
.signature
= sig
;
6330 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6332 if (dwo_entry
== NULL
)
6335 /* If the global table doesn't have an entry for this TU, add one. */
6336 if (sig_entry
== NULL
)
6337 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6339 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6340 sig_entry
->per_cu
.tu_read
= 1;
6344 /* Subroutine of lookup_signatured_type.
6345 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6346 then try the DWP file. If the TU stub (skeleton) has been removed then
6347 it won't be in .gdb_index. */
6349 static struct signatured_type
*
6350 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6352 struct dwarf2_per_objfile
*dwarf2_per_objfile
6353 = cu
->per_cu
->dwarf2_per_objfile
;
6354 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6355 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6356 struct dwo_unit
*dwo_entry
;
6357 struct signatured_type find_sig_entry
, *sig_entry
;
6360 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6361 gdb_assert (dwp_file
!= NULL
);
6363 /* If TU skeletons have been removed then we may not have read in any
6365 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6367 dwarf2_per_objfile
->signatured_types
6368 = allocate_signatured_type_table (objfile
);
6371 find_sig_entry
.signature
= sig
;
6372 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6373 &find_sig_entry
, INSERT
);
6374 sig_entry
= (struct signatured_type
*) *slot
;
6376 /* Have we already tried to read this TU?
6377 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6378 needn't exist in the global table yet). */
6379 if (sig_entry
!= NULL
)
6382 if (dwp_file
->tus
== NULL
)
6384 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6385 sig
, 1 /* is_debug_types */);
6386 if (dwo_entry
== NULL
)
6389 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6390 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6395 /* Lookup a signature based type for DW_FORM_ref_sig8.
6396 Returns NULL if signature SIG is not present in the table.
6397 It is up to the caller to complain about this. */
6399 static struct signatured_type
*
6400 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6402 struct dwarf2_per_objfile
*dwarf2_per_objfile
6403 = cu
->per_cu
->dwarf2_per_objfile
;
6406 && dwarf2_per_objfile
->using_index
)
6408 /* We're in a DWO/DWP file, and we're using .gdb_index.
6409 These cases require special processing. */
6410 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6411 return lookup_dwo_signatured_type (cu
, sig
);
6413 return lookup_dwp_signatured_type (cu
, sig
);
6417 struct signatured_type find_entry
, *entry
;
6419 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6421 find_entry
.signature
= sig
;
6422 entry
= ((struct signatured_type
*)
6423 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6429 /* Return the address base of the compile unit, which, if exists, is stored
6430 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6431 static gdb::optional
<ULONGEST
>
6432 lookup_addr_base (struct die_info
*comp_unit_die
)
6434 struct attribute
*attr
;
6435 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6436 if (attr
== nullptr)
6437 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6438 if (attr
== nullptr)
6439 return gdb::optional
<ULONGEST
> ();
6440 return DW_UNSND (attr
);
6443 /* Return range lists base of the compile unit, which, if exists, is stored
6444 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6446 lookup_ranges_base (struct die_info
*comp_unit_die
)
6448 struct attribute
*attr
;
6449 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6450 if (attr
== nullptr)
6451 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6452 if (attr
== nullptr)
6454 return DW_UNSND (attr
);
6457 /* Low level DIE reading support. */
6459 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6462 init_cu_die_reader (struct die_reader_specs
*reader
,
6463 struct dwarf2_cu
*cu
,
6464 struct dwarf2_section_info
*section
,
6465 struct dwo_file
*dwo_file
,
6466 struct abbrev_table
*abbrev_table
)
6468 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6469 reader
->abfd
= section
->get_bfd_owner ();
6471 reader
->dwo_file
= dwo_file
;
6472 reader
->die_section
= section
;
6473 reader
->buffer
= section
->buffer
;
6474 reader
->buffer_end
= section
->buffer
+ section
->size
;
6475 reader
->abbrev_table
= abbrev_table
;
6478 /* Subroutine of cutu_reader to simplify it.
6479 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6480 There's just a lot of work to do, and cutu_reader is big enough
6483 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6484 from it to the DIE in the DWO. If NULL we are skipping the stub.
6485 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6486 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6487 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6488 STUB_COMP_DIR may be non-NULL.
6489 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6490 are filled in with the info of the DIE from the DWO file.
6491 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6492 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6493 kept around for at least as long as *RESULT_READER.
6495 The result is non-zero if a valid (non-dummy) DIE was found. */
6498 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6499 struct dwo_unit
*dwo_unit
,
6500 struct die_info
*stub_comp_unit_die
,
6501 const char *stub_comp_dir
,
6502 struct die_reader_specs
*result_reader
,
6503 const gdb_byte
**result_info_ptr
,
6504 struct die_info
**result_comp_unit_die
,
6505 abbrev_table_up
*result_dwo_abbrev_table
)
6507 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6508 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6509 struct dwarf2_cu
*cu
= this_cu
->cu
;
6511 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6512 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6513 int i
,num_extra_attrs
;
6514 struct dwarf2_section_info
*dwo_abbrev_section
;
6515 struct die_info
*comp_unit_die
;
6517 /* At most one of these may be provided. */
6518 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6520 /* These attributes aren't processed until later:
6521 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6522 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6523 referenced later. However, these attributes are found in the stub
6524 which we won't have later. In order to not impose this complication
6525 on the rest of the code, we read them here and copy them to the
6534 if (stub_comp_unit_die
!= NULL
)
6536 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6538 if (! this_cu
->is_debug_types
)
6539 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6540 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6541 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6542 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6543 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6545 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6547 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6548 here (if needed). We need the value before we can process
6550 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6552 else if (stub_comp_dir
!= NULL
)
6554 /* Reconstruct the comp_dir attribute to simplify the code below. */
6555 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6556 comp_dir
->name
= DW_AT_comp_dir
;
6557 comp_dir
->form
= DW_FORM_string
;
6558 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6559 DW_STRING (comp_dir
) = stub_comp_dir
;
6562 /* Set up for reading the DWO CU/TU. */
6563 cu
->dwo_unit
= dwo_unit
;
6564 dwarf2_section_info
*section
= dwo_unit
->section
;
6565 section
->read (objfile
);
6566 abfd
= section
->get_bfd_owner ();
6567 begin_info_ptr
= info_ptr
= (section
->buffer
6568 + to_underlying (dwo_unit
->sect_off
));
6569 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6571 if (this_cu
->is_debug_types
)
6573 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6575 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6576 &cu
->header
, section
,
6578 info_ptr
, rcuh_kind::TYPE
);
6579 /* This is not an assert because it can be caused by bad debug info. */
6580 if (sig_type
->signature
!= cu
->header
.signature
)
6582 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6583 " TU at offset %s [in module %s]"),
6584 hex_string (sig_type
->signature
),
6585 hex_string (cu
->header
.signature
),
6586 sect_offset_str (dwo_unit
->sect_off
),
6587 bfd_get_filename (abfd
));
6589 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6590 /* For DWOs coming from DWP files, we don't know the CU length
6591 nor the type's offset in the TU until now. */
6592 dwo_unit
->length
= cu
->header
.get_length ();
6593 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6595 /* Establish the type offset that can be used to lookup the type.
6596 For DWO files, we don't know it until now. */
6597 sig_type
->type_offset_in_section
6598 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6602 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6603 &cu
->header
, section
,
6605 info_ptr
, rcuh_kind::COMPILE
);
6606 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6607 /* For DWOs coming from DWP files, we don't know the CU length
6609 dwo_unit
->length
= cu
->header
.get_length ();
6612 *result_dwo_abbrev_table
6613 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6614 cu
->header
.abbrev_sect_off
);
6615 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6616 result_dwo_abbrev_table
->get ());
6618 /* Read in the die, but leave space to copy over the attributes
6619 from the stub. This has the benefit of simplifying the rest of
6620 the code - all the work to maintain the illusion of a single
6621 DW_TAG_{compile,type}_unit DIE is done here. */
6622 num_extra_attrs
= ((stmt_list
!= NULL
)
6626 + (comp_dir
!= NULL
));
6627 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6630 /* Copy over the attributes from the stub to the DIE we just read in. */
6631 comp_unit_die
= *result_comp_unit_die
;
6632 i
= comp_unit_die
->num_attrs
;
6633 if (stmt_list
!= NULL
)
6634 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6636 comp_unit_die
->attrs
[i
++] = *low_pc
;
6637 if (high_pc
!= NULL
)
6638 comp_unit_die
->attrs
[i
++] = *high_pc
;
6640 comp_unit_die
->attrs
[i
++] = *ranges
;
6641 if (comp_dir
!= NULL
)
6642 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6643 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6645 if (dwarf_die_debug
)
6647 fprintf_unfiltered (gdb_stdlog
,
6648 "Read die from %s@0x%x of %s:\n",
6649 section
->get_name (),
6650 (unsigned) (begin_info_ptr
- section
->buffer
),
6651 bfd_get_filename (abfd
));
6652 dump_die (comp_unit_die
, dwarf_die_debug
);
6655 /* Skip dummy compilation units. */
6656 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6657 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6660 *result_info_ptr
= info_ptr
;
6664 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6665 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6666 signature is part of the header. */
6667 static gdb::optional
<ULONGEST
>
6668 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6670 if (cu
->header
.version
>= 5)
6671 return cu
->header
.signature
;
6672 struct attribute
*attr
;
6673 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6674 if (attr
== nullptr)
6675 return gdb::optional
<ULONGEST
> ();
6676 return DW_UNSND (attr
);
6679 /* Subroutine of cutu_reader to simplify it.
6680 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6681 Returns NULL if the specified DWO unit cannot be found. */
6683 static struct dwo_unit
*
6684 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6685 struct die_info
*comp_unit_die
,
6686 const char *dwo_name
)
6688 struct dwarf2_cu
*cu
= this_cu
->cu
;
6689 struct dwo_unit
*dwo_unit
;
6690 const char *comp_dir
;
6692 gdb_assert (cu
!= NULL
);
6694 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6695 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6696 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6698 if (this_cu
->is_debug_types
)
6700 struct signatured_type
*sig_type
;
6702 /* Since this_cu is the first member of struct signatured_type,
6703 we can go from a pointer to one to a pointer to the other. */
6704 sig_type
= (struct signatured_type
*) this_cu
;
6705 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6709 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6710 if (!signature
.has_value ())
6711 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6713 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6714 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6721 /* Subroutine of cutu_reader to simplify it.
6722 See it for a description of the parameters.
6723 Read a TU directly from a DWO file, bypassing the stub. */
6726 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6727 int use_existing_cu
)
6729 struct signatured_type
*sig_type
;
6730 struct die_reader_specs reader
;
6732 /* Verify we can do the following downcast, and that we have the
6734 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6735 sig_type
= (struct signatured_type
*) this_cu
;
6736 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6738 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6740 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6741 /* There's no need to do the rereading_dwo_cu handling that
6742 cutu_reader does since we don't read the stub. */
6746 /* If !use_existing_cu, this_cu->cu must be NULL. */
6747 gdb_assert (this_cu
->cu
== NULL
);
6748 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6751 /* A future optimization, if needed, would be to use an existing
6752 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6753 could share abbrev tables. */
6755 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6756 NULL
/* stub_comp_unit_die */,
6757 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6760 &m_dwo_abbrev_table
) == 0)
6767 /* Initialize a CU (or TU) and read its DIEs.
6768 If the CU defers to a DWO file, read the DWO file as well.
6770 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6771 Otherwise the table specified in the comp unit header is read in and used.
6772 This is an optimization for when we already have the abbrev table.
6774 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6775 Otherwise, a new CU is allocated with xmalloc. */
6777 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6778 struct abbrev_table
*abbrev_table
,
6779 int use_existing_cu
,
6781 : die_reader_specs
{},
6784 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6785 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6786 struct dwarf2_section_info
*section
= this_cu
->section
;
6787 bfd
*abfd
= section
->get_bfd_owner ();
6788 struct dwarf2_cu
*cu
;
6789 const gdb_byte
*begin_info_ptr
;
6790 struct signatured_type
*sig_type
= NULL
;
6791 struct dwarf2_section_info
*abbrev_section
;
6792 /* Non-zero if CU currently points to a DWO file and we need to
6793 reread it. When this happens we need to reread the skeleton die
6794 before we can reread the DWO file (this only applies to CUs, not TUs). */
6795 int rereading_dwo_cu
= 0;
6797 if (dwarf_die_debug
)
6798 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6799 this_cu
->is_debug_types
? "type" : "comp",
6800 sect_offset_str (this_cu
->sect_off
));
6802 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6803 file (instead of going through the stub), short-circuit all of this. */
6804 if (this_cu
->reading_dwo_directly
)
6806 /* Narrow down the scope of possibilities to have to understand. */
6807 gdb_assert (this_cu
->is_debug_types
);
6808 gdb_assert (abbrev_table
== NULL
);
6809 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6813 /* This is cheap if the section is already read in. */
6814 section
->read (objfile
);
6816 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6818 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6820 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6823 /* If this CU is from a DWO file we need to start over, we need to
6824 refetch the attributes from the skeleton CU.
6825 This could be optimized by retrieving those attributes from when we
6826 were here the first time: the previous comp_unit_die was stored in
6827 comp_unit_obstack. But there's no data yet that we need this
6829 if (cu
->dwo_unit
!= NULL
)
6830 rereading_dwo_cu
= 1;
6834 /* If !use_existing_cu, this_cu->cu must be NULL. */
6835 gdb_assert (this_cu
->cu
== NULL
);
6836 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6837 cu
= m_new_cu
.get ();
6840 /* Get the header. */
6841 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6843 /* We already have the header, there's no need to read it in again. */
6844 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6848 if (this_cu
->is_debug_types
)
6850 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6851 &cu
->header
, section
,
6852 abbrev_section
, info_ptr
,
6855 /* Since per_cu is the first member of struct signatured_type,
6856 we can go from a pointer to one to a pointer to the other. */
6857 sig_type
= (struct signatured_type
*) this_cu
;
6858 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6859 gdb_assert (sig_type
->type_offset_in_tu
6860 == cu
->header
.type_cu_offset_in_tu
);
6861 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6863 /* LENGTH has not been set yet for type units if we're
6864 using .gdb_index. */
6865 this_cu
->length
= cu
->header
.get_length ();
6867 /* Establish the type offset that can be used to lookup the type. */
6868 sig_type
->type_offset_in_section
=
6869 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6871 this_cu
->dwarf_version
= cu
->header
.version
;
6875 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6876 &cu
->header
, section
,
6879 rcuh_kind::COMPILE
);
6881 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6882 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6883 this_cu
->dwarf_version
= cu
->header
.version
;
6887 /* Skip dummy compilation units. */
6888 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6889 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6895 /* If we don't have them yet, read the abbrevs for this compilation unit.
6896 And if we need to read them now, make sure they're freed when we're
6898 if (abbrev_table
!= NULL
)
6899 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6902 m_abbrev_table_holder
6903 = abbrev_table::read (objfile
, abbrev_section
,
6904 cu
->header
.abbrev_sect_off
);
6905 abbrev_table
= m_abbrev_table_holder
.get ();
6908 /* Read the top level CU/TU die. */
6909 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6910 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6912 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6918 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6919 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6920 table from the DWO file and pass the ownership over to us. It will be
6921 referenced from READER, so we must make sure to free it after we're done
6924 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6925 DWO CU, that this test will fail (the attribute will not be present). */
6926 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6927 if (dwo_name
!= nullptr)
6929 struct dwo_unit
*dwo_unit
;
6930 struct die_info
*dwo_comp_unit_die
;
6932 if (comp_unit_die
->has_children
)
6934 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6935 " has children (offset %s) [in module %s]"),
6936 sect_offset_str (this_cu
->sect_off
),
6937 bfd_get_filename (abfd
));
6939 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6940 if (dwo_unit
!= NULL
)
6942 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6943 comp_unit_die
, NULL
,
6946 &m_dwo_abbrev_table
) == 0)
6952 comp_unit_die
= dwo_comp_unit_die
;
6956 /* Yikes, we couldn't find the rest of the DIE, we only have
6957 the stub. A complaint has already been logged. There's
6958 not much more we can do except pass on the stub DIE to
6959 die_reader_func. We don't want to throw an error on bad
6966 cutu_reader::keep ()
6968 /* Done, clean up. */
6969 gdb_assert (!dummy_p
);
6970 if (m_new_cu
!= NULL
)
6972 struct dwarf2_per_objfile
*dwarf2_per_objfile
6973 = m_this_cu
->dwarf2_per_objfile
;
6974 /* Link this CU into read_in_chain. */
6975 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6976 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6977 /* The chain owns it now. */
6978 m_new_cu
.release ();
6982 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6983 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6984 assumed to have already done the lookup to find the DWO file).
6986 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6987 THIS_CU->is_debug_types, but nothing else.
6989 We fill in THIS_CU->length.
6991 THIS_CU->cu is always freed when done.
6992 This is done in order to not leave THIS_CU->cu in a state where we have
6993 to care whether it refers to the "main" CU or the DWO CU.
6995 When parent_cu is passed, it is used to provide a default value for
6996 str_offsets_base and addr_base from the parent. */
6998 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6999 struct dwarf2_cu
*parent_cu
,
7000 struct dwo_file
*dwo_file
)
7001 : die_reader_specs
{},
7004 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7005 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7006 struct dwarf2_section_info
*section
= this_cu
->section
;
7007 bfd
*abfd
= section
->get_bfd_owner ();
7008 struct dwarf2_section_info
*abbrev_section
;
7009 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7011 if (dwarf_die_debug
)
7012 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7013 this_cu
->is_debug_types
? "type" : "comp",
7014 sect_offset_str (this_cu
->sect_off
));
7016 gdb_assert (this_cu
->cu
== NULL
);
7018 abbrev_section
= (dwo_file
!= NULL
7019 ? &dwo_file
->sections
.abbrev
7020 : get_abbrev_section_for_cu (this_cu
));
7022 /* This is cheap if the section is already read in. */
7023 section
->read (objfile
);
7025 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7027 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7028 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7029 &m_new_cu
->header
, section
,
7030 abbrev_section
, info_ptr
,
7031 (this_cu
->is_debug_types
7033 : rcuh_kind::COMPILE
));
7035 if (parent_cu
!= nullptr)
7037 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7038 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7040 this_cu
->length
= m_new_cu
->header
.get_length ();
7042 /* Skip dummy compilation units. */
7043 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7044 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7050 m_abbrev_table_holder
7051 = abbrev_table::read (objfile
, abbrev_section
,
7052 m_new_cu
->header
.abbrev_sect_off
);
7054 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7055 m_abbrev_table_holder
.get ());
7056 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7060 /* Type Unit Groups.
7062 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7063 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7064 so that all types coming from the same compilation (.o file) are grouped
7065 together. A future step could be to put the types in the same symtab as
7066 the CU the types ultimately came from. */
7069 hash_type_unit_group (const void *item
)
7071 const struct type_unit_group
*tu_group
7072 = (const struct type_unit_group
*) item
;
7074 return hash_stmt_list_entry (&tu_group
->hash
);
7078 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7080 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7081 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7083 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7086 /* Allocate a hash table for type unit groups. */
7089 allocate_type_unit_groups_table (struct objfile
*objfile
)
7091 return htab_up (htab_create_alloc (3,
7092 hash_type_unit_group
,
7094 NULL
, xcalloc
, xfree
));
7097 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7098 partial symtabs. We combine several TUs per psymtab to not let the size
7099 of any one psymtab grow too big. */
7100 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7101 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7103 /* Helper routine for get_type_unit_group.
7104 Create the type_unit_group object used to hold one or more TUs. */
7106 static struct type_unit_group
*
7107 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7109 struct dwarf2_per_objfile
*dwarf2_per_objfile
7110 = cu
->per_cu
->dwarf2_per_objfile
;
7111 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7112 struct dwarf2_per_cu_data
*per_cu
;
7113 struct type_unit_group
*tu_group
;
7115 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7116 struct type_unit_group
);
7117 per_cu
= &tu_group
->per_cu
;
7118 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7120 if (dwarf2_per_objfile
->using_index
)
7122 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7123 struct dwarf2_per_cu_quick_data
);
7127 unsigned int line_offset
= to_underlying (line_offset_struct
);
7128 dwarf2_psymtab
*pst
;
7131 /* Give the symtab a useful name for debug purposes. */
7132 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7133 name
= string_printf ("<type_units_%d>",
7134 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7136 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7138 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7139 pst
->anonymous
= true;
7142 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7143 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7148 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7149 STMT_LIST is a DW_AT_stmt_list attribute. */
7151 static struct type_unit_group
*
7152 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7154 struct dwarf2_per_objfile
*dwarf2_per_objfile
7155 = cu
->per_cu
->dwarf2_per_objfile
;
7156 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7157 struct type_unit_group
*tu_group
;
7159 unsigned int line_offset
;
7160 struct type_unit_group type_unit_group_for_lookup
;
7162 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7164 dwarf2_per_objfile
->type_unit_groups
=
7165 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7168 /* Do we need to create a new group, or can we use an existing one? */
7172 line_offset
= DW_UNSND (stmt_list
);
7173 ++tu_stats
->nr_symtab_sharers
;
7177 /* Ugh, no stmt_list. Rare, but we have to handle it.
7178 We can do various things here like create one group per TU or
7179 spread them over multiple groups to split up the expansion work.
7180 To avoid worst case scenarios (too many groups or too large groups)
7181 we, umm, group them in bunches. */
7182 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7183 | (tu_stats
->nr_stmt_less_type_units
7184 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7185 ++tu_stats
->nr_stmt_less_type_units
;
7188 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7189 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7190 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7191 &type_unit_group_for_lookup
, INSERT
);
7194 tu_group
= (struct type_unit_group
*) *slot
;
7195 gdb_assert (tu_group
!= NULL
);
7199 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7200 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7202 ++tu_stats
->nr_symtabs
;
7208 /* Partial symbol tables. */
7210 /* Create a psymtab named NAME and assign it to PER_CU.
7212 The caller must fill in the following details:
7213 dirname, textlow, texthigh. */
7215 static dwarf2_psymtab
*
7216 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7218 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7219 dwarf2_psymtab
*pst
;
7221 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7223 pst
->psymtabs_addrmap_supported
= true;
7225 /* This is the glue that links PST into GDB's symbol API. */
7226 pst
->per_cu_data
= per_cu
;
7227 per_cu
->v
.psymtab
= pst
;
7232 /* DIE reader function for process_psymtab_comp_unit. */
7235 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7236 const gdb_byte
*info_ptr
,
7237 struct die_info
*comp_unit_die
,
7238 enum language pretend_language
)
7240 struct dwarf2_cu
*cu
= reader
->cu
;
7241 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7242 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7243 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7245 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7246 dwarf2_psymtab
*pst
;
7247 enum pc_bounds_kind cu_bounds_kind
;
7248 const char *filename
;
7250 gdb_assert (! per_cu
->is_debug_types
);
7252 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7254 /* Allocate a new partial symbol table structure. */
7255 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7256 static const char artificial
[] = "<artificial>";
7257 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7258 if (filename
== NULL
)
7260 else if (strcmp (filename
, artificial
) == 0)
7262 debug_filename
.reset (concat (artificial
, "@",
7263 sect_offset_str (per_cu
->sect_off
),
7265 filename
= debug_filename
.get ();
7268 pst
= create_partial_symtab (per_cu
, filename
);
7270 /* This must be done before calling dwarf2_build_include_psymtabs. */
7271 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7273 baseaddr
= objfile
->text_section_offset ();
7275 dwarf2_find_base_address (comp_unit_die
, cu
);
7277 /* Possibly set the default values of LOWPC and HIGHPC from
7279 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7280 &best_highpc
, cu
, pst
);
7281 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7284 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7287 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7289 /* Store the contiguous range if it is not empty; it can be
7290 empty for CUs with no code. */
7291 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7295 /* Check if comp unit has_children.
7296 If so, read the rest of the partial symbols from this comp unit.
7297 If not, there's no more debug_info for this comp unit. */
7298 if (comp_unit_die
->has_children
)
7300 struct partial_die_info
*first_die
;
7301 CORE_ADDR lowpc
, highpc
;
7303 lowpc
= ((CORE_ADDR
) -1);
7304 highpc
= ((CORE_ADDR
) 0);
7306 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7308 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7309 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7311 /* If we didn't find a lowpc, set it to highpc to avoid
7312 complaints from `maint check'. */
7313 if (lowpc
== ((CORE_ADDR
) -1))
7316 /* If the compilation unit didn't have an explicit address range,
7317 then use the information extracted from its child dies. */
7318 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7321 best_highpc
= highpc
;
7324 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7325 best_lowpc
+ baseaddr
)
7327 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7328 best_highpc
+ baseaddr
)
7331 end_psymtab_common (objfile
, pst
);
7333 if (!cu
->per_cu
->imported_symtabs_empty ())
7336 int len
= cu
->per_cu
->imported_symtabs_size ();
7338 /* Fill in 'dependencies' here; we fill in 'users' in a
7340 pst
->number_of_dependencies
= len
;
7342 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7343 for (i
= 0; i
< len
; ++i
)
7345 pst
->dependencies
[i
]
7346 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7349 cu
->per_cu
->imported_symtabs_free ();
7352 /* Get the list of files included in the current compilation unit,
7353 and build a psymtab for each of them. */
7354 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7356 if (dwarf_read_debug
)
7357 fprintf_unfiltered (gdb_stdlog
,
7358 "Psymtab for %s unit @%s: %s - %s"
7359 ", %d global, %d static syms\n",
7360 per_cu
->is_debug_types
? "type" : "comp",
7361 sect_offset_str (per_cu
->sect_off
),
7362 paddress (gdbarch
, pst
->text_low (objfile
)),
7363 paddress (gdbarch
, pst
->text_high (objfile
)),
7364 pst
->n_global_syms
, pst
->n_static_syms
);
7367 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7368 Process compilation unit THIS_CU for a psymtab. */
7371 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7372 bool want_partial_unit
,
7373 enum language pretend_language
)
7375 /* If this compilation unit was already read in, free the
7376 cached copy in order to read it in again. This is
7377 necessary because we skipped some symbols when we first
7378 read in the compilation unit (see load_partial_dies).
7379 This problem could be avoided, but the benefit is unclear. */
7380 if (this_cu
->cu
!= NULL
)
7381 free_one_cached_comp_unit (this_cu
);
7383 cutu_reader
reader (this_cu
, NULL
, 0, false);
7389 else if (this_cu
->is_debug_types
)
7390 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7391 reader
.comp_unit_die
);
7392 else if (want_partial_unit
7393 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7394 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7395 reader
.comp_unit_die
,
7398 /* Age out any secondary CUs. */
7399 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7402 /* Reader function for build_type_psymtabs. */
7405 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7406 const gdb_byte
*info_ptr
,
7407 struct die_info
*type_unit_die
)
7409 struct dwarf2_per_objfile
*dwarf2_per_objfile
7410 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7411 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7412 struct dwarf2_cu
*cu
= reader
->cu
;
7413 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7414 struct signatured_type
*sig_type
;
7415 struct type_unit_group
*tu_group
;
7416 struct attribute
*attr
;
7417 struct partial_die_info
*first_die
;
7418 CORE_ADDR lowpc
, highpc
;
7419 dwarf2_psymtab
*pst
;
7421 gdb_assert (per_cu
->is_debug_types
);
7422 sig_type
= (struct signatured_type
*) per_cu
;
7424 if (! type_unit_die
->has_children
)
7427 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7428 tu_group
= get_type_unit_group (cu
, attr
);
7430 if (tu_group
->tus
== nullptr)
7431 tu_group
->tus
= new std::vector
<signatured_type
*>;
7432 tu_group
->tus
->push_back (sig_type
);
7434 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7435 pst
= create_partial_symtab (per_cu
, "");
7436 pst
->anonymous
= true;
7438 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7440 lowpc
= (CORE_ADDR
) -1;
7441 highpc
= (CORE_ADDR
) 0;
7442 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7444 end_psymtab_common (objfile
, pst
);
7447 /* Struct used to sort TUs by their abbreviation table offset. */
7449 struct tu_abbrev_offset
7451 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7452 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7455 signatured_type
*sig_type
;
7456 sect_offset abbrev_offset
;
7459 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7462 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7463 const struct tu_abbrev_offset
&b
)
7465 return a
.abbrev_offset
< b
.abbrev_offset
;
7468 /* Efficiently read all the type units.
7469 This does the bulk of the work for build_type_psymtabs.
7471 The efficiency is because we sort TUs by the abbrev table they use and
7472 only read each abbrev table once. In one program there are 200K TUs
7473 sharing 8K abbrev tables.
7475 The main purpose of this function is to support building the
7476 dwarf2_per_objfile->type_unit_groups table.
7477 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7478 can collapse the search space by grouping them by stmt_list.
7479 The savings can be significant, in the same program from above the 200K TUs
7480 share 8K stmt_list tables.
7482 FUNC is expected to call get_type_unit_group, which will create the
7483 struct type_unit_group if necessary and add it to
7484 dwarf2_per_objfile->type_unit_groups. */
7487 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7489 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7490 abbrev_table_up abbrev_table
;
7491 sect_offset abbrev_offset
;
7493 /* It's up to the caller to not call us multiple times. */
7494 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7496 if (dwarf2_per_objfile
->all_type_units
.empty ())
7499 /* TUs typically share abbrev tables, and there can be way more TUs than
7500 abbrev tables. Sort by abbrev table to reduce the number of times we
7501 read each abbrev table in.
7502 Alternatives are to punt or to maintain a cache of abbrev tables.
7503 This is simpler and efficient enough for now.
7505 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7506 symtab to use). Typically TUs with the same abbrev offset have the same
7507 stmt_list value too so in practice this should work well.
7509 The basic algorithm here is:
7511 sort TUs by abbrev table
7512 for each TU with same abbrev table:
7513 read abbrev table if first user
7514 read TU top level DIE
7515 [IWBN if DWO skeletons had DW_AT_stmt_list]
7518 if (dwarf_read_debug
)
7519 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7521 /* Sort in a separate table to maintain the order of all_type_units
7522 for .gdb_index: TU indices directly index all_type_units. */
7523 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7524 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7526 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7527 sorted_by_abbrev
.emplace_back
7528 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7529 sig_type
->per_cu
.section
,
7530 sig_type
->per_cu
.sect_off
));
7532 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7533 sort_tu_by_abbrev_offset
);
7535 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7537 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7539 /* Switch to the next abbrev table if necessary. */
7540 if (abbrev_table
== NULL
7541 || tu
.abbrev_offset
!= abbrev_offset
)
7543 abbrev_offset
= tu
.abbrev_offset
;
7545 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7546 &dwarf2_per_objfile
->abbrev
,
7548 ++tu_stats
->nr_uniq_abbrev_tables
;
7551 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7553 if (!reader
.dummy_p
)
7554 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7555 reader
.comp_unit_die
);
7559 /* Print collected type unit statistics. */
7562 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7564 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7566 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7567 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7568 dwarf2_per_objfile
->all_type_units
.size ());
7569 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7570 tu_stats
->nr_uniq_abbrev_tables
);
7571 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7572 tu_stats
->nr_symtabs
);
7573 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7574 tu_stats
->nr_symtab_sharers
);
7575 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7576 tu_stats
->nr_stmt_less_type_units
);
7577 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7578 tu_stats
->nr_all_type_units_reallocs
);
7581 /* Traversal function for build_type_psymtabs. */
7584 build_type_psymtab_dependencies (void **slot
, void *info
)
7586 struct dwarf2_per_objfile
*dwarf2_per_objfile
7587 = (struct dwarf2_per_objfile
*) info
;
7588 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7589 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7590 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7591 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7592 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7595 gdb_assert (len
> 0);
7596 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
7598 pst
->number_of_dependencies
= len
;
7599 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7600 for (i
= 0; i
< len
; ++i
)
7602 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7603 gdb_assert (iter
->per_cu
.is_debug_types
);
7604 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7605 iter
->type_unit_group
= tu_group
;
7608 delete tu_group
->tus
;
7609 tu_group
->tus
= nullptr;
7614 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7615 Build partial symbol tables for the .debug_types comp-units. */
7618 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7620 if (! create_all_type_units (dwarf2_per_objfile
))
7623 build_type_psymtabs_1 (dwarf2_per_objfile
);
7626 /* Traversal function for process_skeletonless_type_unit.
7627 Read a TU in a DWO file and build partial symbols for it. */
7630 process_skeletonless_type_unit (void **slot
, void *info
)
7632 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7633 struct dwarf2_per_objfile
*dwarf2_per_objfile
7634 = (struct dwarf2_per_objfile
*) info
;
7635 struct signatured_type find_entry
, *entry
;
7637 /* If this TU doesn't exist in the global table, add it and read it in. */
7639 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7641 dwarf2_per_objfile
->signatured_types
7642 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
7645 find_entry
.signature
= dwo_unit
->signature
;
7646 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7647 &find_entry
, INSERT
);
7648 /* If we've already seen this type there's nothing to do. What's happening
7649 is we're doing our own version of comdat-folding here. */
7653 /* This does the job that create_all_type_units would have done for
7655 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7656 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7659 /* This does the job that build_type_psymtabs_1 would have done. */
7660 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7661 if (!reader
.dummy_p
)
7662 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7663 reader
.comp_unit_die
);
7668 /* Traversal function for process_skeletonless_type_units. */
7671 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7673 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7675 if (dwo_file
->tus
!= NULL
)
7676 htab_traverse_noresize (dwo_file
->tus
.get (),
7677 process_skeletonless_type_unit
, info
);
7682 /* Scan all TUs of DWO files, verifying we've processed them.
7683 This is needed in case a TU was emitted without its skeleton.
7684 Note: This can't be done until we know what all the DWO files are. */
7687 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7689 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7690 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7691 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7693 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7694 process_dwo_file_for_skeletonless_type_units
,
7695 dwarf2_per_objfile
);
7699 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7702 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7704 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7706 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7711 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7713 /* Set the 'user' field only if it is not already set. */
7714 if (pst
->dependencies
[j
]->user
== NULL
)
7715 pst
->dependencies
[j
]->user
= pst
;
7720 /* Build the partial symbol table by doing a quick pass through the
7721 .debug_info and .debug_abbrev sections. */
7724 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7726 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7728 if (dwarf_read_debug
)
7730 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7731 objfile_name (objfile
));
7734 dwarf2_per_objfile
->reading_partial_symbols
= 1;
7736 dwarf2_per_objfile
->info
.read (objfile
);
7738 /* Any cached compilation units will be linked by the per-objfile
7739 read_in_chain. Make sure to free them when we're done. */
7740 free_cached_comp_units
freer (dwarf2_per_objfile
);
7742 build_type_psymtabs (dwarf2_per_objfile
);
7744 create_all_comp_units (dwarf2_per_objfile
);
7746 /* Create a temporary address map on a temporary obstack. We later
7747 copy this to the final obstack. */
7748 auto_obstack temp_obstack
;
7750 scoped_restore save_psymtabs_addrmap
7751 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7752 addrmap_create_mutable (&temp_obstack
));
7754 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7755 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7757 /* This has to wait until we read the CUs, we need the list of DWOs. */
7758 process_skeletonless_type_units (dwarf2_per_objfile
);
7760 /* Now that all TUs have been processed we can fill in the dependencies. */
7761 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7763 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7764 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7767 if (dwarf_read_debug
)
7768 print_tu_stats (dwarf2_per_objfile
);
7770 set_partial_user (dwarf2_per_objfile
);
7772 objfile
->partial_symtabs
->psymtabs_addrmap
7773 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7774 objfile
->partial_symtabs
->obstack ());
7775 /* At this point we want to keep the address map. */
7776 save_psymtabs_addrmap
.release ();
7778 if (dwarf_read_debug
)
7779 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7780 objfile_name (objfile
));
7783 /* Load the partial DIEs for a secondary CU into memory.
7784 This is also used when rereading a primary CU with load_all_dies. */
7787 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7789 cutu_reader
reader (this_cu
, NULL
, 1, false);
7791 if (!reader
.dummy_p
)
7793 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7796 /* Check if comp unit has_children.
7797 If so, read the rest of the partial symbols from this comp unit.
7798 If not, there's no more debug_info for this comp unit. */
7799 if (reader
.comp_unit_die
->has_children
)
7800 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7807 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7808 struct dwarf2_section_info
*section
,
7809 struct dwarf2_section_info
*abbrev_section
,
7810 unsigned int is_dwz
)
7812 const gdb_byte
*info_ptr
;
7813 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7815 if (dwarf_read_debug
)
7816 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7817 section
->get_name (),
7818 section
->get_file_name ());
7820 section
->read (objfile
);
7822 info_ptr
= section
->buffer
;
7824 while (info_ptr
< section
->buffer
+ section
->size
)
7826 struct dwarf2_per_cu_data
*this_cu
;
7828 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7830 comp_unit_head cu_header
;
7831 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7832 abbrev_section
, info_ptr
,
7833 rcuh_kind::COMPILE
);
7835 /* Save the compilation unit for later lookup. */
7836 if (cu_header
.unit_type
!= DW_UT_type
)
7838 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7839 struct dwarf2_per_cu_data
);
7840 memset (this_cu
, 0, sizeof (*this_cu
));
7844 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7845 struct signatured_type
);
7846 memset (sig_type
, 0, sizeof (*sig_type
));
7847 sig_type
->signature
= cu_header
.signature
;
7848 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7849 this_cu
= &sig_type
->per_cu
;
7851 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7852 this_cu
->sect_off
= sect_off
;
7853 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7854 this_cu
->is_dwz
= is_dwz
;
7855 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7856 this_cu
->section
= section
;
7858 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7860 info_ptr
= info_ptr
+ this_cu
->length
;
7864 /* Create a list of all compilation units in OBJFILE.
7865 This is only done for -readnow and building partial symtabs. */
7868 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7870 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7871 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7872 &dwarf2_per_objfile
->abbrev
, 0);
7874 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7876 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7880 /* Process all loaded DIEs for compilation unit CU, starting at
7881 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7882 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7883 DW_AT_ranges). See the comments of add_partial_subprogram on how
7884 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7887 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7888 CORE_ADDR
*highpc
, int set_addrmap
,
7889 struct dwarf2_cu
*cu
)
7891 struct partial_die_info
*pdi
;
7893 /* Now, march along the PDI's, descending into ones which have
7894 interesting children but skipping the children of the other ones,
7895 until we reach the end of the compilation unit. */
7903 /* Anonymous namespaces or modules have no name but have interesting
7904 children, so we need to look at them. Ditto for anonymous
7907 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7908 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7909 || pdi
->tag
== DW_TAG_imported_unit
7910 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7914 case DW_TAG_subprogram
:
7915 case DW_TAG_inlined_subroutine
:
7916 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7918 case DW_TAG_constant
:
7919 case DW_TAG_variable
:
7920 case DW_TAG_typedef
:
7921 case DW_TAG_union_type
:
7922 if (!pdi
->is_declaration
)
7924 add_partial_symbol (pdi
, cu
);
7927 case DW_TAG_class_type
:
7928 case DW_TAG_interface_type
:
7929 case DW_TAG_structure_type
:
7930 if (!pdi
->is_declaration
)
7932 add_partial_symbol (pdi
, cu
);
7934 if ((cu
->language
== language_rust
7935 || cu
->language
== language_cplus
) && pdi
->has_children
)
7936 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7939 case DW_TAG_enumeration_type
:
7940 if (!pdi
->is_declaration
)
7941 add_partial_enumeration (pdi
, cu
);
7943 case DW_TAG_base_type
:
7944 case DW_TAG_subrange_type
:
7945 /* File scope base type definitions are added to the partial
7947 add_partial_symbol (pdi
, cu
);
7949 case DW_TAG_namespace
:
7950 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7953 if (!pdi
->is_declaration
)
7954 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7956 case DW_TAG_imported_unit
:
7958 struct dwarf2_per_cu_data
*per_cu
;
7960 /* For now we don't handle imported units in type units. */
7961 if (cu
->per_cu
->is_debug_types
)
7963 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7964 " supported in type units [in module %s]"),
7965 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7968 per_cu
= dwarf2_find_containing_comp_unit
7969 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7970 cu
->per_cu
->dwarf2_per_objfile
);
7972 /* Go read the partial unit, if needed. */
7973 if (per_cu
->v
.psymtab
== NULL
)
7974 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7976 cu
->per_cu
->imported_symtabs_push (per_cu
);
7979 case DW_TAG_imported_declaration
:
7980 add_partial_symbol (pdi
, cu
);
7987 /* If the die has a sibling, skip to the sibling. */
7989 pdi
= pdi
->die_sibling
;
7993 /* Functions used to compute the fully scoped name of a partial DIE.
7995 Normally, this is simple. For C++, the parent DIE's fully scoped
7996 name is concatenated with "::" and the partial DIE's name.
7997 Enumerators are an exception; they use the scope of their parent
7998 enumeration type, i.e. the name of the enumeration type is not
7999 prepended to the enumerator.
8001 There are two complexities. One is DW_AT_specification; in this
8002 case "parent" means the parent of the target of the specification,
8003 instead of the direct parent of the DIE. The other is compilers
8004 which do not emit DW_TAG_namespace; in this case we try to guess
8005 the fully qualified name of structure types from their members'
8006 linkage names. This must be done using the DIE's children rather
8007 than the children of any DW_AT_specification target. We only need
8008 to do this for structures at the top level, i.e. if the target of
8009 any DW_AT_specification (if any; otherwise the DIE itself) does not
8012 /* Compute the scope prefix associated with PDI's parent, in
8013 compilation unit CU. The result will be allocated on CU's
8014 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8015 field. NULL is returned if no prefix is necessary. */
8017 partial_die_parent_scope (struct partial_die_info
*pdi
,
8018 struct dwarf2_cu
*cu
)
8020 const char *grandparent_scope
;
8021 struct partial_die_info
*parent
, *real_pdi
;
8023 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8024 then this means the parent of the specification DIE. */
8027 while (real_pdi
->has_specification
)
8029 auto res
= find_partial_die (real_pdi
->spec_offset
,
8030 real_pdi
->spec_is_dwz
, cu
);
8035 parent
= real_pdi
->die_parent
;
8039 if (parent
->scope_set
)
8040 return parent
->scope
;
8044 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8046 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8047 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8048 Work around this problem here. */
8049 if (cu
->language
== language_cplus
8050 && parent
->tag
== DW_TAG_namespace
8051 && strcmp (parent
->name
, "::") == 0
8052 && grandparent_scope
== NULL
)
8054 parent
->scope
= NULL
;
8055 parent
->scope_set
= 1;
8059 /* Nested subroutines in Fortran get a prefix. */
8060 if (pdi
->tag
== DW_TAG_enumerator
)
8061 /* Enumerators should not get the name of the enumeration as a prefix. */
8062 parent
->scope
= grandparent_scope
;
8063 else if (parent
->tag
== DW_TAG_namespace
8064 || parent
->tag
== DW_TAG_module
8065 || parent
->tag
== DW_TAG_structure_type
8066 || parent
->tag
== DW_TAG_class_type
8067 || parent
->tag
== DW_TAG_interface_type
8068 || parent
->tag
== DW_TAG_union_type
8069 || parent
->tag
== DW_TAG_enumeration_type
8070 || (cu
->language
== language_fortran
8071 && parent
->tag
== DW_TAG_subprogram
8072 && pdi
->tag
== DW_TAG_subprogram
))
8074 if (grandparent_scope
== NULL
)
8075 parent
->scope
= parent
->name
;
8077 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8079 parent
->name
, 0, cu
);
8083 /* FIXME drow/2004-04-01: What should we be doing with
8084 function-local names? For partial symbols, we should probably be
8086 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8087 dwarf_tag_name (parent
->tag
),
8088 sect_offset_str (pdi
->sect_off
));
8089 parent
->scope
= grandparent_scope
;
8092 parent
->scope_set
= 1;
8093 return parent
->scope
;
8096 /* Return the fully scoped name associated with PDI, from compilation unit
8097 CU. The result will be allocated with malloc. */
8099 static gdb::unique_xmalloc_ptr
<char>
8100 partial_die_full_name (struct partial_die_info
*pdi
,
8101 struct dwarf2_cu
*cu
)
8103 const char *parent_scope
;
8105 /* If this is a template instantiation, we can not work out the
8106 template arguments from partial DIEs. So, unfortunately, we have
8107 to go through the full DIEs. At least any work we do building
8108 types here will be reused if full symbols are loaded later. */
8109 if (pdi
->has_template_arguments
)
8113 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8115 struct die_info
*die
;
8116 struct attribute attr
;
8117 struct dwarf2_cu
*ref_cu
= cu
;
8119 /* DW_FORM_ref_addr is using section offset. */
8120 attr
.name
= (enum dwarf_attribute
) 0;
8121 attr
.form
= DW_FORM_ref_addr
;
8122 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8123 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8125 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8129 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8130 if (parent_scope
== NULL
)
8133 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8138 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8140 struct dwarf2_per_objfile
*dwarf2_per_objfile
8141 = cu
->per_cu
->dwarf2_per_objfile
;
8142 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8143 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8145 const char *actual_name
= NULL
;
8148 baseaddr
= objfile
->text_section_offset ();
8150 gdb::unique_xmalloc_ptr
<char> built_actual_name
8151 = partial_die_full_name (pdi
, cu
);
8152 if (built_actual_name
!= NULL
)
8153 actual_name
= built_actual_name
.get ();
8155 if (actual_name
== NULL
)
8156 actual_name
= pdi
->name
;
8160 case DW_TAG_inlined_subroutine
:
8161 case DW_TAG_subprogram
:
8162 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8164 if (pdi
->is_external
8165 || cu
->language
== language_ada
8166 || (cu
->language
== language_fortran
8167 && pdi
->die_parent
!= NULL
8168 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8170 /* Normally, only "external" DIEs are part of the global scope.
8171 But in Ada and Fortran, we want to be able to access nested
8172 procedures globally. So all Ada and Fortran subprograms are
8173 stored in the global scope. */
8174 add_psymbol_to_list (actual_name
,
8175 built_actual_name
!= NULL
,
8176 VAR_DOMAIN
, LOC_BLOCK
,
8177 SECT_OFF_TEXT (objfile
),
8178 psymbol_placement::GLOBAL
,
8180 cu
->language
, objfile
);
8184 add_psymbol_to_list (actual_name
,
8185 built_actual_name
!= NULL
,
8186 VAR_DOMAIN
, LOC_BLOCK
,
8187 SECT_OFF_TEXT (objfile
),
8188 psymbol_placement::STATIC
,
8189 addr
, cu
->language
, objfile
);
8192 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8193 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8195 case DW_TAG_constant
:
8196 add_psymbol_to_list (actual_name
,
8197 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8198 -1, (pdi
->is_external
8199 ? psymbol_placement::GLOBAL
8200 : psymbol_placement::STATIC
),
8201 0, cu
->language
, objfile
);
8203 case DW_TAG_variable
:
8205 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8209 && !dwarf2_per_objfile
->has_section_at_zero
)
8211 /* A global or static variable may also have been stripped
8212 out by the linker if unused, in which case its address
8213 will be nullified; do not add such variables into partial
8214 symbol table then. */
8216 else if (pdi
->is_external
)
8219 Don't enter into the minimal symbol tables as there is
8220 a minimal symbol table entry from the ELF symbols already.
8221 Enter into partial symbol table if it has a location
8222 descriptor or a type.
8223 If the location descriptor is missing, new_symbol will create
8224 a LOC_UNRESOLVED symbol, the address of the variable will then
8225 be determined from the minimal symbol table whenever the variable
8227 The address for the partial symbol table entry is not
8228 used by GDB, but it comes in handy for debugging partial symbol
8231 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8232 add_psymbol_to_list (actual_name
,
8233 built_actual_name
!= NULL
,
8234 VAR_DOMAIN
, LOC_STATIC
,
8235 SECT_OFF_TEXT (objfile
),
8236 psymbol_placement::GLOBAL
,
8237 addr
, cu
->language
, objfile
);
8241 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8243 /* Static Variable. Skip symbols whose value we cannot know (those
8244 without location descriptors or constant values). */
8245 if (!has_loc
&& !pdi
->has_const_value
)
8248 add_psymbol_to_list (actual_name
,
8249 built_actual_name
!= NULL
,
8250 VAR_DOMAIN
, LOC_STATIC
,
8251 SECT_OFF_TEXT (objfile
),
8252 psymbol_placement::STATIC
,
8254 cu
->language
, objfile
);
8257 case DW_TAG_typedef
:
8258 case DW_TAG_base_type
:
8259 case DW_TAG_subrange_type
:
8260 add_psymbol_to_list (actual_name
,
8261 built_actual_name
!= NULL
,
8262 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8263 psymbol_placement::STATIC
,
8264 0, cu
->language
, objfile
);
8266 case DW_TAG_imported_declaration
:
8267 case DW_TAG_namespace
:
8268 add_psymbol_to_list (actual_name
,
8269 built_actual_name
!= NULL
,
8270 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8271 psymbol_placement::GLOBAL
,
8272 0, cu
->language
, objfile
);
8275 /* With Fortran 77 there might be a "BLOCK DATA" module
8276 available without any name. If so, we skip the module as it
8277 doesn't bring any value. */
8278 if (actual_name
!= nullptr)
8279 add_psymbol_to_list (actual_name
,
8280 built_actual_name
!= NULL
,
8281 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8282 psymbol_placement::GLOBAL
,
8283 0, cu
->language
, objfile
);
8285 case DW_TAG_class_type
:
8286 case DW_TAG_interface_type
:
8287 case DW_TAG_structure_type
:
8288 case DW_TAG_union_type
:
8289 case DW_TAG_enumeration_type
:
8290 /* Skip external references. The DWARF standard says in the section
8291 about "Structure, Union, and Class Type Entries": "An incomplete
8292 structure, union or class type is represented by a structure,
8293 union or class entry that does not have a byte size attribute
8294 and that has a DW_AT_declaration attribute." */
8295 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8298 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8299 static vs. global. */
8300 add_psymbol_to_list (actual_name
,
8301 built_actual_name
!= NULL
,
8302 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8303 cu
->language
== language_cplus
8304 ? psymbol_placement::GLOBAL
8305 : psymbol_placement::STATIC
,
8306 0, cu
->language
, objfile
);
8309 case DW_TAG_enumerator
:
8310 add_psymbol_to_list (actual_name
,
8311 built_actual_name
!= NULL
,
8312 VAR_DOMAIN
, LOC_CONST
, -1,
8313 cu
->language
== language_cplus
8314 ? psymbol_placement::GLOBAL
8315 : psymbol_placement::STATIC
,
8316 0, cu
->language
, objfile
);
8323 /* Read a partial die corresponding to a namespace; also, add a symbol
8324 corresponding to that namespace to the symbol table. NAMESPACE is
8325 the name of the enclosing namespace. */
8328 add_partial_namespace (struct partial_die_info
*pdi
,
8329 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8330 int set_addrmap
, struct dwarf2_cu
*cu
)
8332 /* Add a symbol for the namespace. */
8334 add_partial_symbol (pdi
, cu
);
8336 /* Now scan partial symbols in that namespace. */
8338 if (pdi
->has_children
)
8339 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8342 /* Read a partial die corresponding to a Fortran module. */
8345 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8346 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8348 /* Add a symbol for the namespace. */
8350 add_partial_symbol (pdi
, cu
);
8352 /* Now scan partial symbols in that module. */
8354 if (pdi
->has_children
)
8355 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8358 /* Read a partial die corresponding to a subprogram or an inlined
8359 subprogram and create a partial symbol for that subprogram.
8360 When the CU language allows it, this routine also defines a partial
8361 symbol for each nested subprogram that this subprogram contains.
8362 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8363 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8365 PDI may also be a lexical block, in which case we simply search
8366 recursively for subprograms defined inside that lexical block.
8367 Again, this is only performed when the CU language allows this
8368 type of definitions. */
8371 add_partial_subprogram (struct partial_die_info
*pdi
,
8372 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8373 int set_addrmap
, struct dwarf2_cu
*cu
)
8375 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8377 if (pdi
->has_pc_info
)
8379 if (pdi
->lowpc
< *lowpc
)
8380 *lowpc
= pdi
->lowpc
;
8381 if (pdi
->highpc
> *highpc
)
8382 *highpc
= pdi
->highpc
;
8385 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8386 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8388 CORE_ADDR this_highpc
;
8389 CORE_ADDR this_lowpc
;
8391 baseaddr
= objfile
->text_section_offset ();
8393 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8394 pdi
->lowpc
+ baseaddr
)
8397 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8398 pdi
->highpc
+ baseaddr
)
8400 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8401 this_lowpc
, this_highpc
- 1,
8402 cu
->per_cu
->v
.psymtab
);
8406 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8408 if (!pdi
->is_declaration
)
8409 /* Ignore subprogram DIEs that do not have a name, they are
8410 illegal. Do not emit a complaint at this point, we will
8411 do so when we convert this psymtab into a symtab. */
8413 add_partial_symbol (pdi
, cu
);
8417 if (! pdi
->has_children
)
8420 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8422 pdi
= pdi
->die_child
;
8426 if (pdi
->tag
== DW_TAG_subprogram
8427 || pdi
->tag
== DW_TAG_inlined_subroutine
8428 || pdi
->tag
== DW_TAG_lexical_block
)
8429 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8430 pdi
= pdi
->die_sibling
;
8435 /* Read a partial die corresponding to an enumeration type. */
8438 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8439 struct dwarf2_cu
*cu
)
8441 struct partial_die_info
*pdi
;
8443 if (enum_pdi
->name
!= NULL
)
8444 add_partial_symbol (enum_pdi
, cu
);
8446 pdi
= enum_pdi
->die_child
;
8449 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8450 complaint (_("malformed enumerator DIE ignored"));
8452 add_partial_symbol (pdi
, cu
);
8453 pdi
= pdi
->die_sibling
;
8457 /* Return the initial uleb128 in the die at INFO_PTR. */
8460 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8462 unsigned int bytes_read
;
8464 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8467 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8468 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8470 Return the corresponding abbrev, or NULL if the number is zero (indicating
8471 an empty DIE). In either case *BYTES_READ will be set to the length of
8472 the initial number. */
8474 static struct abbrev_info
*
8475 peek_die_abbrev (const die_reader_specs
&reader
,
8476 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8478 dwarf2_cu
*cu
= reader
.cu
;
8479 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8480 unsigned int abbrev_number
8481 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8483 if (abbrev_number
== 0)
8486 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8489 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8490 " at offset %s [in module %s]"),
8491 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8492 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8498 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8499 Returns a pointer to the end of a series of DIEs, terminated by an empty
8500 DIE. Any children of the skipped DIEs will also be skipped. */
8502 static const gdb_byte
*
8503 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8507 unsigned int bytes_read
;
8508 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8511 return info_ptr
+ bytes_read
;
8513 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8517 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8518 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8519 abbrev corresponding to that skipped uleb128 should be passed in
8520 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8523 static const gdb_byte
*
8524 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8525 struct abbrev_info
*abbrev
)
8527 unsigned int bytes_read
;
8528 struct attribute attr
;
8529 bfd
*abfd
= reader
->abfd
;
8530 struct dwarf2_cu
*cu
= reader
->cu
;
8531 const gdb_byte
*buffer
= reader
->buffer
;
8532 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8533 unsigned int form
, i
;
8535 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8537 /* The only abbrev we care about is DW_AT_sibling. */
8538 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8541 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8543 if (attr
.form
== DW_FORM_ref_addr
)
8544 complaint (_("ignoring absolute DW_AT_sibling"));
8547 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8548 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8550 if (sibling_ptr
< info_ptr
)
8551 complaint (_("DW_AT_sibling points backwards"));
8552 else if (sibling_ptr
> reader
->buffer_end
)
8553 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
8559 /* If it isn't DW_AT_sibling, skip this attribute. */
8560 form
= abbrev
->attrs
[i
].form
;
8564 case DW_FORM_ref_addr
:
8565 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8566 and later it is offset sized. */
8567 if (cu
->header
.version
== 2)
8568 info_ptr
+= cu
->header
.addr_size
;
8570 info_ptr
+= cu
->header
.offset_size
;
8572 case DW_FORM_GNU_ref_alt
:
8573 info_ptr
+= cu
->header
.offset_size
;
8576 info_ptr
+= cu
->header
.addr_size
;
8584 case DW_FORM_flag_present
:
8585 case DW_FORM_implicit_const
:
8602 case DW_FORM_ref_sig8
:
8605 case DW_FORM_data16
:
8608 case DW_FORM_string
:
8609 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8610 info_ptr
+= bytes_read
;
8612 case DW_FORM_sec_offset
:
8614 case DW_FORM_GNU_strp_alt
:
8615 info_ptr
+= cu
->header
.offset_size
;
8617 case DW_FORM_exprloc
:
8619 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8620 info_ptr
+= bytes_read
;
8622 case DW_FORM_block1
:
8623 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8625 case DW_FORM_block2
:
8626 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8628 case DW_FORM_block4
:
8629 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8635 case DW_FORM_ref_udata
:
8636 case DW_FORM_GNU_addr_index
:
8637 case DW_FORM_GNU_str_index
:
8638 case DW_FORM_rnglistx
:
8639 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8641 case DW_FORM_indirect
:
8642 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8643 info_ptr
+= bytes_read
;
8644 /* We need to continue parsing from here, so just go back to
8646 goto skip_attribute
;
8649 error (_("Dwarf Error: Cannot handle %s "
8650 "in DWARF reader [in module %s]"),
8651 dwarf_form_name (form
),
8652 bfd_get_filename (abfd
));
8656 if (abbrev
->has_children
)
8657 return skip_children (reader
, info_ptr
);
8662 /* Locate ORIG_PDI's sibling.
8663 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8665 static const gdb_byte
*
8666 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8667 struct partial_die_info
*orig_pdi
,
8668 const gdb_byte
*info_ptr
)
8670 /* Do we know the sibling already? */
8672 if (orig_pdi
->sibling
)
8673 return orig_pdi
->sibling
;
8675 /* Are there any children to deal with? */
8677 if (!orig_pdi
->has_children
)
8680 /* Skip the children the long way. */
8682 return skip_children (reader
, info_ptr
);
8685 /* Expand this partial symbol table into a full symbol table. SELF is
8689 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8691 struct dwarf2_per_objfile
*dwarf2_per_objfile
8692 = get_dwarf2_per_objfile (objfile
);
8694 gdb_assert (!readin
);
8695 /* If this psymtab is constructed from a debug-only objfile, the
8696 has_section_at_zero flag will not necessarily be correct. We
8697 can get the correct value for this flag by looking at the data
8698 associated with the (presumably stripped) associated objfile. */
8699 if (objfile
->separate_debug_objfile_backlink
)
8701 struct dwarf2_per_objfile
*dpo_backlink
8702 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8704 dwarf2_per_objfile
->has_section_at_zero
8705 = dpo_backlink
->has_section_at_zero
;
8708 dwarf2_per_objfile
->reading_partial_symbols
= 0;
8710 expand_psymtab (objfile
);
8712 process_cu_includes (dwarf2_per_objfile
);
8715 /* Reading in full CUs. */
8717 /* Add PER_CU to the queue. */
8720 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8721 enum language pretend_language
)
8724 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8727 /* If PER_CU is not yet queued, add it to the queue.
8728 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8730 The result is non-zero if PER_CU was queued, otherwise the result is zero
8731 meaning either PER_CU is already queued or it is already loaded.
8733 N.B. There is an invariant here that if a CU is queued then it is loaded.
8734 The caller is required to load PER_CU if we return non-zero. */
8737 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8738 struct dwarf2_per_cu_data
*per_cu
,
8739 enum language pretend_language
)
8741 /* We may arrive here during partial symbol reading, if we need full
8742 DIEs to process an unusual case (e.g. template arguments). Do
8743 not queue PER_CU, just tell our caller to load its DIEs. */
8744 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8746 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8751 /* Mark the dependence relation so that we don't flush PER_CU
8753 if (dependent_cu
!= NULL
)
8754 dwarf2_add_dependence (dependent_cu
, per_cu
);
8756 /* If it's already on the queue, we have nothing to do. */
8760 /* If the compilation unit is already loaded, just mark it as
8762 if (per_cu
->cu
!= NULL
)
8764 per_cu
->cu
->last_used
= 0;
8768 /* Add it to the queue. */
8769 queue_comp_unit (per_cu
, pretend_language
);
8774 /* Process the queue. */
8777 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8779 if (dwarf_read_debug
)
8781 fprintf_unfiltered (gdb_stdlog
,
8782 "Expanding one or more symtabs of objfile %s ...\n",
8783 objfile_name (dwarf2_per_objfile
->objfile
));
8786 /* The queue starts out with one item, but following a DIE reference
8787 may load a new CU, adding it to the end of the queue. */
8788 while (!dwarf2_per_objfile
->queue
.empty ())
8790 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8792 if ((dwarf2_per_objfile
->using_index
8793 ? !item
.per_cu
->v
.quick
->compunit_symtab
8794 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8795 /* Skip dummy CUs. */
8796 && item
.per_cu
->cu
!= NULL
)
8798 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8799 unsigned int debug_print_threshold
;
8802 if (per_cu
->is_debug_types
)
8804 struct signatured_type
*sig_type
=
8805 (struct signatured_type
*) per_cu
;
8807 sprintf (buf
, "TU %s at offset %s",
8808 hex_string (sig_type
->signature
),
8809 sect_offset_str (per_cu
->sect_off
));
8810 /* There can be 100s of TUs.
8811 Only print them in verbose mode. */
8812 debug_print_threshold
= 2;
8816 sprintf (buf
, "CU at offset %s",
8817 sect_offset_str (per_cu
->sect_off
));
8818 debug_print_threshold
= 1;
8821 if (dwarf_read_debug
>= debug_print_threshold
)
8822 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8824 if (per_cu
->is_debug_types
)
8825 process_full_type_unit (per_cu
, item
.pretend_language
);
8827 process_full_comp_unit (per_cu
, item
.pretend_language
);
8829 if (dwarf_read_debug
>= debug_print_threshold
)
8830 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8833 item
.per_cu
->queued
= 0;
8834 dwarf2_per_objfile
->queue
.pop ();
8837 if (dwarf_read_debug
)
8839 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8840 objfile_name (dwarf2_per_objfile
->objfile
));
8844 /* Read in full symbols for PST, and anything it depends on. */
8847 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8849 struct dwarf2_per_cu_data
*per_cu
;
8854 read_dependencies (objfile
);
8856 per_cu
= per_cu_data
;
8860 /* It's an include file, no symbols to read for it.
8861 Everything is in the parent symtab. */
8866 dw2_do_instantiate_symtab (per_cu
, false);
8869 /* Trivial hash function for die_info: the hash value of a DIE
8870 is its offset in .debug_info for this objfile. */
8873 die_hash (const void *item
)
8875 const struct die_info
*die
= (const struct die_info
*) item
;
8877 return to_underlying (die
->sect_off
);
8880 /* Trivial comparison function for die_info structures: two DIEs
8881 are equal if they have the same offset. */
8884 die_eq (const void *item_lhs
, const void *item_rhs
)
8886 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8887 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8889 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8892 /* Load the DIEs associated with PER_CU into memory. */
8895 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8897 enum language pretend_language
)
8899 gdb_assert (! this_cu
->is_debug_types
);
8901 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8905 struct dwarf2_cu
*cu
= reader
.cu
;
8906 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8908 gdb_assert (cu
->die_hash
== NULL
);
8910 htab_create_alloc_ex (cu
->header
.length
/ 12,
8914 &cu
->comp_unit_obstack
,
8915 hashtab_obstack_allocate
,
8916 dummy_obstack_deallocate
);
8918 if (reader
.comp_unit_die
->has_children
)
8919 reader
.comp_unit_die
->child
8920 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8921 &info_ptr
, reader
.comp_unit_die
);
8922 cu
->dies
= reader
.comp_unit_die
;
8923 /* comp_unit_die is not stored in die_hash, no need. */
8925 /* We try not to read any attributes in this function, because not
8926 all CUs needed for references have been loaded yet, and symbol
8927 table processing isn't initialized. But we have to set the CU language,
8928 or we won't be able to build types correctly.
8929 Similarly, if we do not read the producer, we can not apply
8930 producer-specific interpretation. */
8931 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8936 /* Add a DIE to the delayed physname list. */
8939 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8940 const char *name
, struct die_info
*die
,
8941 struct dwarf2_cu
*cu
)
8943 struct delayed_method_info mi
;
8945 mi
.fnfield_index
= fnfield_index
;
8949 cu
->method_list
.push_back (mi
);
8952 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8953 "const" / "volatile". If so, decrements LEN by the length of the
8954 modifier and return true. Otherwise return false. */
8958 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8960 size_t mod_len
= sizeof (mod
) - 1;
8961 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8969 /* Compute the physnames of any methods on the CU's method list.
8971 The computation of method physnames is delayed in order to avoid the
8972 (bad) condition that one of the method's formal parameters is of an as yet
8976 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8978 /* Only C++ delays computing physnames. */
8979 if (cu
->method_list
.empty ())
8981 gdb_assert (cu
->language
== language_cplus
);
8983 for (const delayed_method_info
&mi
: cu
->method_list
)
8985 const char *physname
;
8986 struct fn_fieldlist
*fn_flp
8987 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8988 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8989 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8990 = physname
? physname
: "";
8992 /* Since there's no tag to indicate whether a method is a
8993 const/volatile overload, extract that information out of the
8995 if (physname
!= NULL
)
8997 size_t len
= strlen (physname
);
9001 if (physname
[len
] == ')') /* shortcut */
9003 else if (check_modifier (physname
, len
, " const"))
9004 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9005 else if (check_modifier (physname
, len
, " volatile"))
9006 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9013 /* The list is no longer needed. */
9014 cu
->method_list
.clear ();
9017 /* Go objects should be embedded in a DW_TAG_module DIE,
9018 and it's not clear if/how imported objects will appear.
9019 To keep Go support simple until that's worked out,
9020 go back through what we've read and create something usable.
9021 We could do this while processing each DIE, and feels kinda cleaner,
9022 but that way is more invasive.
9023 This is to, for example, allow the user to type "p var" or "b main"
9024 without having to specify the package name, and allow lookups
9025 of module.object to work in contexts that use the expression
9029 fixup_go_packaging (struct dwarf2_cu
*cu
)
9031 gdb::unique_xmalloc_ptr
<char> package_name
;
9032 struct pending
*list
;
9035 for (list
= *cu
->get_builder ()->get_global_symbols ();
9039 for (i
= 0; i
< list
->nsyms
; ++i
)
9041 struct symbol
*sym
= list
->symbol
[i
];
9043 if (sym
->language () == language_go
9044 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9046 gdb::unique_xmalloc_ptr
<char> this_package_name
9047 (go_symbol_package_name (sym
));
9049 if (this_package_name
== NULL
)
9051 if (package_name
== NULL
)
9052 package_name
= std::move (this_package_name
);
9055 struct objfile
*objfile
9056 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9057 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9058 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9059 (symbol_symtab (sym
) != NULL
9060 ? symtab_to_filename_for_display
9061 (symbol_symtab (sym
))
9062 : objfile_name (objfile
)),
9063 this_package_name
.get (), package_name
.get ());
9069 if (package_name
!= NULL
)
9071 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9072 const char *saved_package_name
9073 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9074 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9075 saved_package_name
);
9078 sym
= allocate_symbol (objfile
);
9079 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9080 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9081 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9082 e.g., "main" finds the "main" module and not C's main(). */
9083 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9084 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9085 SYMBOL_TYPE (sym
) = type
;
9087 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9091 /* Allocate a fully-qualified name consisting of the two parts on the
9095 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9097 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9100 /* A helper that allocates a struct discriminant_info to attach to a
9103 static struct discriminant_info
*
9104 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9107 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9108 gdb_assert (discriminant_index
== -1
9109 || (discriminant_index
>= 0
9110 && discriminant_index
< TYPE_NFIELDS (type
)));
9111 gdb_assert (default_index
== -1
9112 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9114 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9116 struct discriminant_info
*disc
9117 = ((struct discriminant_info
*)
9119 offsetof (struct discriminant_info
, discriminants
)
9120 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9121 disc
->default_index
= default_index
;
9122 disc
->discriminant_index
= discriminant_index
;
9124 struct dynamic_prop prop
;
9125 prop
.kind
= PROP_UNDEFINED
;
9126 prop
.data
.baton
= disc
;
9128 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9133 /* Some versions of rustc emitted enums in an unusual way.
9135 Ordinary enums were emitted as unions. The first element of each
9136 structure in the union was named "RUST$ENUM$DISR". This element
9137 held the discriminant.
9139 These versions of Rust also implemented the "non-zero"
9140 optimization. When the enum had two values, and one is empty and
9141 the other holds a pointer that cannot be zero, the pointer is used
9142 as the discriminant, with a zero value meaning the empty variant.
9143 Here, the union's first member is of the form
9144 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9145 where the fieldnos are the indices of the fields that should be
9146 traversed in order to find the field (which may be several fields deep)
9147 and the variantname is the name of the variant of the case when the
9150 This function recognizes whether TYPE is of one of these forms,
9151 and, if so, smashes it to be a variant type. */
9154 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9156 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9158 /* We don't need to deal with empty enums. */
9159 if (TYPE_NFIELDS (type
) == 0)
9162 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9163 if (TYPE_NFIELDS (type
) == 1
9164 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9166 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9168 /* Decode the field name to find the offset of the
9170 ULONGEST bit_offset
= 0;
9171 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9172 while (name
[0] >= '0' && name
[0] <= '9')
9175 unsigned long index
= strtoul (name
, &tail
, 10);
9178 || index
>= TYPE_NFIELDS (field_type
)
9179 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9180 != FIELD_LOC_KIND_BITPOS
))
9182 complaint (_("Could not parse Rust enum encoding string \"%s\""
9184 TYPE_FIELD_NAME (type
, 0),
9185 objfile_name (objfile
));
9190 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9191 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9194 /* Make a union to hold the variants. */
9195 struct type
*union_type
= alloc_type (objfile
);
9196 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9197 TYPE_NFIELDS (union_type
) = 3;
9198 TYPE_FIELDS (union_type
)
9199 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9200 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9201 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9203 /* Put the discriminant must at index 0. */
9204 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9205 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9206 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9207 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9209 /* The order of fields doesn't really matter, so put the real
9210 field at index 1 and the data-less field at index 2. */
9211 struct discriminant_info
*disc
9212 = alloc_discriminant_info (union_type
, 0, 1);
9213 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9214 TYPE_FIELD_NAME (union_type
, 1)
9215 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9216 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9217 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9218 TYPE_FIELD_NAME (union_type
, 1));
9220 const char *dataless_name
9221 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9223 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9225 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9226 /* NAME points into the original discriminant name, which
9227 already has the correct lifetime. */
9228 TYPE_FIELD_NAME (union_type
, 2) = name
;
9229 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9230 disc
->discriminants
[2] = 0;
9232 /* Smash this type to be a structure type. We have to do this
9233 because the type has already been recorded. */
9234 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9235 TYPE_NFIELDS (type
) = 1;
9237 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9239 /* Install the variant part. */
9240 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9241 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9242 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9244 /* A union with a single anonymous field is probably an old-style
9246 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9248 /* Smash this type to be a structure type. We have to do this
9249 because the type has already been recorded. */
9250 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9252 /* Make a union to hold the variants. */
9253 struct type
*union_type
= alloc_type (objfile
);
9254 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9255 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9256 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9257 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9258 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9260 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9261 const char *variant_name
9262 = rust_last_path_segment (TYPE_NAME (field_type
));
9263 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9264 TYPE_NAME (field_type
)
9265 = rust_fully_qualify (&objfile
->objfile_obstack
,
9266 TYPE_NAME (type
), variant_name
);
9268 /* Install the union in the outer struct type. */
9269 TYPE_NFIELDS (type
) = 1;
9271 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9272 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9273 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9274 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9276 alloc_discriminant_info (union_type
, -1, 0);
9280 struct type
*disr_type
= nullptr;
9281 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9283 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9285 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9287 /* All fields of a true enum will be structs. */
9290 else if (TYPE_NFIELDS (disr_type
) == 0)
9292 /* Could be data-less variant, so keep going. */
9293 disr_type
= nullptr;
9295 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9296 "RUST$ENUM$DISR") != 0)
9298 /* Not a Rust enum. */
9308 /* If we got here without a discriminant, then it's probably
9310 if (disr_type
== nullptr)
9313 /* Smash this type to be a structure type. We have to do this
9314 because the type has already been recorded. */
9315 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9317 /* Make a union to hold the variants. */
9318 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9319 struct type
*union_type
= alloc_type (objfile
);
9320 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9321 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9322 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9323 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9324 TYPE_FIELDS (union_type
)
9325 = (struct field
*) TYPE_ZALLOC (union_type
,
9326 (TYPE_NFIELDS (union_type
)
9327 * sizeof (struct field
)));
9329 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9330 TYPE_NFIELDS (type
) * sizeof (struct field
));
9332 /* Install the discriminant at index 0 in the union. */
9333 TYPE_FIELD (union_type
, 0) = *disr_field
;
9334 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9335 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9337 /* Install the union in the outer struct type. */
9338 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9339 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9340 TYPE_NFIELDS (type
) = 1;
9342 /* Set the size and offset of the union type. */
9343 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9345 /* We need a way to find the correct discriminant given a
9346 variant name. For convenience we build a map here. */
9347 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9348 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9349 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9351 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9354 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9355 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9359 int n_fields
= TYPE_NFIELDS (union_type
);
9360 struct discriminant_info
*disc
9361 = alloc_discriminant_info (union_type
, 0, -1);
9362 /* Skip the discriminant here. */
9363 for (int i
= 1; i
< n_fields
; ++i
)
9365 /* Find the final word in the name of this variant's type.
9366 That name can be used to look up the correct
9368 const char *variant_name
9369 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9372 auto iter
= discriminant_map
.find (variant_name
);
9373 if (iter
!= discriminant_map
.end ())
9374 disc
->discriminants
[i
] = iter
->second
;
9376 /* Remove the discriminant field, if it exists. */
9377 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9378 if (TYPE_NFIELDS (sub_type
) > 0)
9380 --TYPE_NFIELDS (sub_type
);
9381 ++TYPE_FIELDS (sub_type
);
9383 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9384 TYPE_NAME (sub_type
)
9385 = rust_fully_qualify (&objfile
->objfile_obstack
,
9386 TYPE_NAME (type
), variant_name
);
9391 /* Rewrite some Rust unions to be structures with variants parts. */
9394 rust_union_quirks (struct dwarf2_cu
*cu
)
9396 gdb_assert (cu
->language
== language_rust
);
9397 for (type
*type_
: cu
->rust_unions
)
9398 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9399 /* We don't need this any more. */
9400 cu
->rust_unions
.clear ();
9403 /* Return the symtab for PER_CU. This works properly regardless of
9404 whether we're using the index or psymtabs. */
9406 static struct compunit_symtab
*
9407 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9409 return (per_cu
->dwarf2_per_objfile
->using_index
9410 ? per_cu
->v
.quick
->compunit_symtab
9411 : per_cu
->v
.psymtab
->compunit_symtab
);
9414 /* A helper function for computing the list of all symbol tables
9415 included by PER_CU. */
9418 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9419 htab_t all_children
, htab_t all_type_symtabs
,
9420 struct dwarf2_per_cu_data
*per_cu
,
9421 struct compunit_symtab
*immediate_parent
)
9424 struct compunit_symtab
*cust
;
9426 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9429 /* This inclusion and its children have been processed. */
9434 /* Only add a CU if it has a symbol table. */
9435 cust
= get_compunit_symtab (per_cu
);
9438 /* If this is a type unit only add its symbol table if we haven't
9439 seen it yet (type unit per_cu's can share symtabs). */
9440 if (per_cu
->is_debug_types
)
9442 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9446 result
->push_back (cust
);
9447 if (cust
->user
== NULL
)
9448 cust
->user
= immediate_parent
;
9453 result
->push_back (cust
);
9454 if (cust
->user
== NULL
)
9455 cust
->user
= immediate_parent
;
9459 if (!per_cu
->imported_symtabs_empty ())
9460 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9462 recursively_compute_inclusions (result
, all_children
,
9463 all_type_symtabs
, ptr
, cust
);
9467 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9471 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9473 gdb_assert (! per_cu
->is_debug_types
);
9475 if (!per_cu
->imported_symtabs_empty ())
9478 std::vector
<compunit_symtab
*> result_symtabs
;
9479 htab_t all_children
, all_type_symtabs
;
9480 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9482 /* If we don't have a symtab, we can just skip this case. */
9486 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9487 NULL
, xcalloc
, xfree
);
9488 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9489 NULL
, xcalloc
, xfree
);
9491 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9493 recursively_compute_inclusions (&result_symtabs
, all_children
,
9494 all_type_symtabs
, ptr
, cust
);
9497 /* Now we have a transitive closure of all the included symtabs. */
9498 len
= result_symtabs
.size ();
9500 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9501 struct compunit_symtab
*, len
+ 1);
9502 memcpy (cust
->includes
, result_symtabs
.data (),
9503 len
* sizeof (compunit_symtab
*));
9504 cust
->includes
[len
] = NULL
;
9506 htab_delete (all_children
);
9507 htab_delete (all_type_symtabs
);
9511 /* Compute the 'includes' field for the symtabs of all the CUs we just
9515 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9517 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9519 if (! iter
->is_debug_types
)
9520 compute_compunit_symtab_includes (iter
);
9523 dwarf2_per_objfile
->just_read_cus
.clear ();
9526 /* Generate full symbol information for PER_CU, whose DIEs have
9527 already been loaded into memory. */
9530 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9531 enum language pretend_language
)
9533 struct dwarf2_cu
*cu
= per_cu
->cu
;
9534 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9535 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9536 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9537 CORE_ADDR lowpc
, highpc
;
9538 struct compunit_symtab
*cust
;
9540 struct block
*static_block
;
9543 baseaddr
= objfile
->text_section_offset ();
9545 /* Clear the list here in case something was left over. */
9546 cu
->method_list
.clear ();
9548 cu
->language
= pretend_language
;
9549 cu
->language_defn
= language_def (cu
->language
);
9551 /* Do line number decoding in read_file_scope () */
9552 process_die (cu
->dies
, cu
);
9554 /* For now fudge the Go package. */
9555 if (cu
->language
== language_go
)
9556 fixup_go_packaging (cu
);
9558 /* Now that we have processed all the DIEs in the CU, all the types
9559 should be complete, and it should now be safe to compute all of the
9561 compute_delayed_physnames (cu
);
9563 if (cu
->language
== language_rust
)
9564 rust_union_quirks (cu
);
9566 /* Some compilers don't define a DW_AT_high_pc attribute for the
9567 compilation unit. If the DW_AT_high_pc is missing, synthesize
9568 it, by scanning the DIE's below the compilation unit. */
9569 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9571 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9572 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9574 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9575 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9576 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9577 addrmap to help ensure it has an accurate map of pc values belonging to
9579 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9581 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9582 SECT_OFF_TEXT (objfile
),
9587 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9589 /* Set symtab language to language from DW_AT_language. If the
9590 compilation is from a C file generated by language preprocessors, do
9591 not set the language if it was already deduced by start_subfile. */
9592 if (!(cu
->language
== language_c
9593 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9594 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9596 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9597 produce DW_AT_location with location lists but it can be possibly
9598 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9599 there were bugs in prologue debug info, fixed later in GCC-4.5
9600 by "unwind info for epilogues" patch (which is not directly related).
9602 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9603 needed, it would be wrong due to missing DW_AT_producer there.
9605 Still one can confuse GDB by using non-standard GCC compilation
9606 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9608 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9609 cust
->locations_valid
= 1;
9611 if (gcc_4_minor
>= 5)
9612 cust
->epilogue_unwind_valid
= 1;
9614 cust
->call_site_htab
= cu
->call_site_htab
;
9617 if (dwarf2_per_objfile
->using_index
)
9618 per_cu
->v
.quick
->compunit_symtab
= cust
;
9621 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9622 pst
->compunit_symtab
= cust
;
9626 /* Push it for inclusion processing later. */
9627 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9629 /* Not needed any more. */
9630 cu
->reset_builder ();
9633 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9634 already been loaded into memory. */
9637 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9638 enum language pretend_language
)
9640 struct dwarf2_cu
*cu
= per_cu
->cu
;
9641 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9642 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9643 struct compunit_symtab
*cust
;
9644 struct signatured_type
*sig_type
;
9646 gdb_assert (per_cu
->is_debug_types
);
9647 sig_type
= (struct signatured_type
*) per_cu
;
9649 /* Clear the list here in case something was left over. */
9650 cu
->method_list
.clear ();
9652 cu
->language
= pretend_language
;
9653 cu
->language_defn
= language_def (cu
->language
);
9655 /* The symbol tables are set up in read_type_unit_scope. */
9656 process_die (cu
->dies
, cu
);
9658 /* For now fudge the Go package. */
9659 if (cu
->language
== language_go
)
9660 fixup_go_packaging (cu
);
9662 /* Now that we have processed all the DIEs in the CU, all the types
9663 should be complete, and it should now be safe to compute all of the
9665 compute_delayed_physnames (cu
);
9667 if (cu
->language
== language_rust
)
9668 rust_union_quirks (cu
);
9670 /* TUs share symbol tables.
9671 If this is the first TU to use this symtab, complete the construction
9672 of it with end_expandable_symtab. Otherwise, complete the addition of
9673 this TU's symbols to the existing symtab. */
9674 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9676 buildsym_compunit
*builder
= cu
->get_builder ();
9677 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9678 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9682 /* Set symtab language to language from DW_AT_language. If the
9683 compilation is from a C file generated by language preprocessors,
9684 do not set the language if it was already deduced by
9686 if (!(cu
->language
== language_c
9687 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9688 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9693 cu
->get_builder ()->augment_type_symtab ();
9694 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9697 if (dwarf2_per_objfile
->using_index
)
9698 per_cu
->v
.quick
->compunit_symtab
= cust
;
9701 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9702 pst
->compunit_symtab
= cust
;
9706 /* Not needed any more. */
9707 cu
->reset_builder ();
9710 /* Process an imported unit DIE. */
9713 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9715 struct attribute
*attr
;
9717 /* For now we don't handle imported units in type units. */
9718 if (cu
->per_cu
->is_debug_types
)
9720 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9721 " supported in type units [in module %s]"),
9722 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9725 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9728 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9729 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9730 dwarf2_per_cu_data
*per_cu
9731 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9732 cu
->per_cu
->dwarf2_per_objfile
);
9734 /* If necessary, add it to the queue and load its DIEs. */
9735 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9736 load_full_comp_unit (per_cu
, false, cu
->language
);
9738 cu
->per_cu
->imported_symtabs_push (per_cu
);
9742 /* RAII object that represents a process_die scope: i.e.,
9743 starts/finishes processing a DIE. */
9744 class process_die_scope
9747 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9748 : m_die (die
), m_cu (cu
)
9750 /* We should only be processing DIEs not already in process. */
9751 gdb_assert (!m_die
->in_process
);
9752 m_die
->in_process
= true;
9755 ~process_die_scope ()
9757 m_die
->in_process
= false;
9759 /* If we're done processing the DIE for the CU that owns the line
9760 header, we don't need the line header anymore. */
9761 if (m_cu
->line_header_die_owner
== m_die
)
9763 delete m_cu
->line_header
;
9764 m_cu
->line_header
= NULL
;
9765 m_cu
->line_header_die_owner
= NULL
;
9774 /* Process a die and its children. */
9777 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9779 process_die_scope
scope (die
, cu
);
9783 case DW_TAG_padding
:
9785 case DW_TAG_compile_unit
:
9786 case DW_TAG_partial_unit
:
9787 read_file_scope (die
, cu
);
9789 case DW_TAG_type_unit
:
9790 read_type_unit_scope (die
, cu
);
9792 case DW_TAG_subprogram
:
9793 /* Nested subprograms in Fortran get a prefix. */
9794 if (cu
->language
== language_fortran
9795 && die
->parent
!= NULL
9796 && die
->parent
->tag
== DW_TAG_subprogram
)
9797 cu
->processing_has_namespace_info
= true;
9799 case DW_TAG_inlined_subroutine
:
9800 read_func_scope (die
, cu
);
9802 case DW_TAG_lexical_block
:
9803 case DW_TAG_try_block
:
9804 case DW_TAG_catch_block
:
9805 read_lexical_block_scope (die
, cu
);
9807 case DW_TAG_call_site
:
9808 case DW_TAG_GNU_call_site
:
9809 read_call_site_scope (die
, cu
);
9811 case DW_TAG_class_type
:
9812 case DW_TAG_interface_type
:
9813 case DW_TAG_structure_type
:
9814 case DW_TAG_union_type
:
9815 process_structure_scope (die
, cu
);
9817 case DW_TAG_enumeration_type
:
9818 process_enumeration_scope (die
, cu
);
9821 /* These dies have a type, but processing them does not create
9822 a symbol or recurse to process the children. Therefore we can
9823 read them on-demand through read_type_die. */
9824 case DW_TAG_subroutine_type
:
9825 case DW_TAG_set_type
:
9826 case DW_TAG_array_type
:
9827 case DW_TAG_pointer_type
:
9828 case DW_TAG_ptr_to_member_type
:
9829 case DW_TAG_reference_type
:
9830 case DW_TAG_rvalue_reference_type
:
9831 case DW_TAG_string_type
:
9834 case DW_TAG_base_type
:
9835 case DW_TAG_subrange_type
:
9836 case DW_TAG_typedef
:
9837 /* Add a typedef symbol for the type definition, if it has a
9839 new_symbol (die
, read_type_die (die
, cu
), cu
);
9841 case DW_TAG_common_block
:
9842 read_common_block (die
, cu
);
9844 case DW_TAG_common_inclusion
:
9846 case DW_TAG_namespace
:
9847 cu
->processing_has_namespace_info
= true;
9848 read_namespace (die
, cu
);
9851 cu
->processing_has_namespace_info
= true;
9852 read_module (die
, cu
);
9854 case DW_TAG_imported_declaration
:
9855 cu
->processing_has_namespace_info
= true;
9856 if (read_namespace_alias (die
, cu
))
9858 /* The declaration is not a global namespace alias. */
9860 case DW_TAG_imported_module
:
9861 cu
->processing_has_namespace_info
= true;
9862 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9863 || cu
->language
!= language_fortran
))
9864 complaint (_("Tag '%s' has unexpected children"),
9865 dwarf_tag_name (die
->tag
));
9866 read_import_statement (die
, cu
);
9869 case DW_TAG_imported_unit
:
9870 process_imported_unit_die (die
, cu
);
9873 case DW_TAG_variable
:
9874 read_variable (die
, cu
);
9878 new_symbol (die
, NULL
, cu
);
9883 /* DWARF name computation. */
9885 /* A helper function for dwarf2_compute_name which determines whether DIE
9886 needs to have the name of the scope prepended to the name listed in the
9890 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9892 struct attribute
*attr
;
9896 case DW_TAG_namespace
:
9897 case DW_TAG_typedef
:
9898 case DW_TAG_class_type
:
9899 case DW_TAG_interface_type
:
9900 case DW_TAG_structure_type
:
9901 case DW_TAG_union_type
:
9902 case DW_TAG_enumeration_type
:
9903 case DW_TAG_enumerator
:
9904 case DW_TAG_subprogram
:
9905 case DW_TAG_inlined_subroutine
:
9907 case DW_TAG_imported_declaration
:
9910 case DW_TAG_variable
:
9911 case DW_TAG_constant
:
9912 /* We only need to prefix "globally" visible variables. These include
9913 any variable marked with DW_AT_external or any variable that
9914 lives in a namespace. [Variables in anonymous namespaces
9915 require prefixing, but they are not DW_AT_external.] */
9917 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9919 struct dwarf2_cu
*spec_cu
= cu
;
9921 return die_needs_namespace (die_specification (die
, &spec_cu
),
9925 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9926 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9927 && die
->parent
->tag
!= DW_TAG_module
)
9929 /* A variable in a lexical block of some kind does not need a
9930 namespace, even though in C++ such variables may be external
9931 and have a mangled name. */
9932 if (die
->parent
->tag
== DW_TAG_lexical_block
9933 || die
->parent
->tag
== DW_TAG_try_block
9934 || die
->parent
->tag
== DW_TAG_catch_block
9935 || die
->parent
->tag
== DW_TAG_subprogram
)
9944 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9945 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9946 defined for the given DIE. */
9948 static struct attribute
*
9949 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9951 struct attribute
*attr
;
9953 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9955 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9960 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9961 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9962 defined for the given DIE. */
9965 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9967 const char *linkage_name
;
9969 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9970 if (linkage_name
== NULL
)
9971 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9973 return linkage_name
;
9976 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9977 compute the physname for the object, which include a method's:
9978 - formal parameters (C++),
9979 - receiver type (Go),
9981 The term "physname" is a bit confusing.
9982 For C++, for example, it is the demangled name.
9983 For Go, for example, it's the mangled name.
9985 For Ada, return the DIE's linkage name rather than the fully qualified
9986 name. PHYSNAME is ignored..
9988 The result is allocated on the objfile_obstack and canonicalized. */
9991 dwarf2_compute_name (const char *name
,
9992 struct die_info
*die
, struct dwarf2_cu
*cu
,
9995 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9998 name
= dwarf2_name (die
, cu
);
10000 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10001 but otherwise compute it by typename_concat inside GDB.
10002 FIXME: Actually this is not really true, or at least not always true.
10003 It's all very confusing. compute_and_set_names doesn't try to demangle
10004 Fortran names because there is no mangling standard. So new_symbol
10005 will set the demangled name to the result of dwarf2_full_name, and it is
10006 the demangled name that GDB uses if it exists. */
10007 if (cu
->language
== language_ada
10008 || (cu
->language
== language_fortran
&& physname
))
10010 /* For Ada unit, we prefer the linkage name over the name, as
10011 the former contains the exported name, which the user expects
10012 to be able to reference. Ideally, we want the user to be able
10013 to reference this entity using either natural or linkage name,
10014 but we haven't started looking at this enhancement yet. */
10015 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10017 if (linkage_name
!= NULL
)
10018 return linkage_name
;
10021 /* These are the only languages we know how to qualify names in. */
10023 && (cu
->language
== language_cplus
10024 || cu
->language
== language_fortran
|| cu
->language
== language_d
10025 || cu
->language
== language_rust
))
10027 if (die_needs_namespace (die
, cu
))
10029 const char *prefix
;
10030 const char *canonical_name
= NULL
;
10034 prefix
= determine_prefix (die
, cu
);
10035 if (*prefix
!= '\0')
10037 gdb::unique_xmalloc_ptr
<char> prefixed_name
10038 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10040 buf
.puts (prefixed_name
.get ());
10045 /* Template parameters may be specified in the DIE's DW_AT_name, or
10046 as children with DW_TAG_template_type_param or
10047 DW_TAG_value_type_param. If the latter, add them to the name
10048 here. If the name already has template parameters, then
10049 skip this step; some versions of GCC emit both, and
10050 it is more efficient to use the pre-computed name.
10052 Something to keep in mind about this process: it is very
10053 unlikely, or in some cases downright impossible, to produce
10054 something that will match the mangled name of a function.
10055 If the definition of the function has the same debug info,
10056 we should be able to match up with it anyway. But fallbacks
10057 using the minimal symbol, for instance to find a method
10058 implemented in a stripped copy of libstdc++, will not work.
10059 If we do not have debug info for the definition, we will have to
10060 match them up some other way.
10062 When we do name matching there is a related problem with function
10063 templates; two instantiated function templates are allowed to
10064 differ only by their return types, which we do not add here. */
10066 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10068 struct attribute
*attr
;
10069 struct die_info
*child
;
10072 die
->building_fullname
= 1;
10074 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10078 const gdb_byte
*bytes
;
10079 struct dwarf2_locexpr_baton
*baton
;
10082 if (child
->tag
!= DW_TAG_template_type_param
10083 && child
->tag
!= DW_TAG_template_value_param
)
10094 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10097 complaint (_("template parameter missing DW_AT_type"));
10098 buf
.puts ("UNKNOWN_TYPE");
10101 type
= die_type (child
, cu
);
10103 if (child
->tag
== DW_TAG_template_type_param
)
10105 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10106 &type_print_raw_options
);
10110 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10113 complaint (_("template parameter missing "
10114 "DW_AT_const_value"));
10115 buf
.puts ("UNKNOWN_VALUE");
10119 dwarf2_const_value_attr (attr
, type
, name
,
10120 &cu
->comp_unit_obstack
, cu
,
10121 &value
, &bytes
, &baton
);
10123 if (TYPE_NOSIGN (type
))
10124 /* GDB prints characters as NUMBER 'CHAR'. If that's
10125 changed, this can use value_print instead. */
10126 c_printchar (value
, type
, &buf
);
10129 struct value_print_options opts
;
10132 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10136 else if (bytes
!= NULL
)
10138 v
= allocate_value (type
);
10139 memcpy (value_contents_writeable (v
), bytes
,
10140 TYPE_LENGTH (type
));
10143 v
= value_from_longest (type
, value
);
10145 /* Specify decimal so that we do not depend on
10147 get_formatted_print_options (&opts
, 'd');
10149 value_print (v
, &buf
, &opts
);
10154 die
->building_fullname
= 0;
10158 /* Close the argument list, with a space if necessary
10159 (nested templates). */
10160 if (!buf
.empty () && buf
.string ().back () == '>')
10167 /* For C++ methods, append formal parameter type
10168 information, if PHYSNAME. */
10170 if (physname
&& die
->tag
== DW_TAG_subprogram
10171 && cu
->language
== language_cplus
)
10173 struct type
*type
= read_type_die (die
, cu
);
10175 c_type_print_args (type
, &buf
, 1, cu
->language
,
10176 &type_print_raw_options
);
10178 if (cu
->language
== language_cplus
)
10180 /* Assume that an artificial first parameter is
10181 "this", but do not crash if it is not. RealView
10182 marks unnamed (and thus unused) parameters as
10183 artificial; there is no way to differentiate
10185 if (TYPE_NFIELDS (type
) > 0
10186 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10187 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10188 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10190 buf
.puts (" const");
10194 const std::string
&intermediate_name
= buf
.string ();
10196 if (cu
->language
== language_cplus
)
10198 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10199 &objfile
->per_bfd
->storage_obstack
);
10201 /* If we only computed INTERMEDIATE_NAME, or if
10202 INTERMEDIATE_NAME is already canonical, then we need to
10203 copy it to the appropriate obstack. */
10204 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10205 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
10206 intermediate_name
);
10208 name
= canonical_name
;
10215 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10216 If scope qualifiers are appropriate they will be added. The result
10217 will be allocated on the storage_obstack, or NULL if the DIE does
10218 not have a name. NAME may either be from a previous call to
10219 dwarf2_name or NULL.
10221 The output string will be canonicalized (if C++). */
10223 static const char *
10224 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10226 return dwarf2_compute_name (name
, die
, cu
, 0);
10229 /* Construct a physname for the given DIE in CU. NAME may either be
10230 from a previous call to dwarf2_name or NULL. The result will be
10231 allocated on the objfile_objstack or NULL if the DIE does not have a
10234 The output string will be canonicalized (if C++). */
10236 static const char *
10237 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10239 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10240 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10243 /* In this case dwarf2_compute_name is just a shortcut not building anything
10245 if (!die_needs_namespace (die
, cu
))
10246 return dwarf2_compute_name (name
, die
, cu
, 1);
10248 mangled
= dw2_linkage_name (die
, cu
);
10250 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10251 See https://github.com/rust-lang/rust/issues/32925. */
10252 if (cu
->language
== language_rust
&& mangled
!= NULL
10253 && strchr (mangled
, '{') != NULL
)
10256 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10258 gdb::unique_xmalloc_ptr
<char> demangled
;
10259 if (mangled
!= NULL
)
10262 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10264 /* Do nothing (do not demangle the symbol name). */
10266 else if (cu
->language
== language_go
)
10268 /* This is a lie, but we already lie to the caller new_symbol.
10269 new_symbol assumes we return the mangled name.
10270 This just undoes that lie until things are cleaned up. */
10274 /* Use DMGL_RET_DROP for C++ template functions to suppress
10275 their return type. It is easier for GDB users to search
10276 for such functions as `name(params)' than `long name(params)'.
10277 In such case the minimal symbol names do not match the full
10278 symbol names but for template functions there is never a need
10279 to look up their definition from their declaration so
10280 the only disadvantage remains the minimal symbol variant
10281 `long name(params)' does not have the proper inferior type. */
10282 demangled
.reset (gdb_demangle (mangled
,
10283 (DMGL_PARAMS
| DMGL_ANSI
10284 | DMGL_RET_DROP
)));
10287 canon
= demangled
.get ();
10295 if (canon
== NULL
|| check_physname
)
10297 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10299 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10301 /* It may not mean a bug in GDB. The compiler could also
10302 compute DW_AT_linkage_name incorrectly. But in such case
10303 GDB would need to be bug-to-bug compatible. */
10305 complaint (_("Computed physname <%s> does not match demangled <%s> "
10306 "(from linkage <%s>) - DIE at %s [in module %s]"),
10307 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10308 objfile_name (objfile
));
10310 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10311 is available here - over computed PHYSNAME. It is safer
10312 against both buggy GDB and buggy compilers. */
10326 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
10331 /* Inspect DIE in CU for a namespace alias. If one exists, record
10332 a new symbol for it.
10334 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10337 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10339 struct attribute
*attr
;
10341 /* If the die does not have a name, this is not a namespace
10343 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10347 struct die_info
*d
= die
;
10348 struct dwarf2_cu
*imported_cu
= cu
;
10350 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10351 keep inspecting DIEs until we hit the underlying import. */
10352 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10353 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10355 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10359 d
= follow_die_ref (d
, attr
, &imported_cu
);
10360 if (d
->tag
!= DW_TAG_imported_declaration
)
10364 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10366 complaint (_("DIE at %s has too many recursively imported "
10367 "declarations"), sect_offset_str (d
->sect_off
));
10374 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10376 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10377 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10379 /* This declaration is a global namespace alias. Add
10380 a symbol for it whose type is the aliased namespace. */
10381 new_symbol (die
, type
, cu
);
10390 /* Return the using directives repository (global or local?) to use in the
10391 current context for CU.
10393 For Ada, imported declarations can materialize renamings, which *may* be
10394 global. However it is impossible (for now?) in DWARF to distinguish
10395 "external" imported declarations and "static" ones. As all imported
10396 declarations seem to be static in all other languages, make them all CU-wide
10397 global only in Ada. */
10399 static struct using_direct
**
10400 using_directives (struct dwarf2_cu
*cu
)
10402 if (cu
->language
== language_ada
10403 && cu
->get_builder ()->outermost_context_p ())
10404 return cu
->get_builder ()->get_global_using_directives ();
10406 return cu
->get_builder ()->get_local_using_directives ();
10409 /* Read the import statement specified by the given die and record it. */
10412 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10414 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10415 struct attribute
*import_attr
;
10416 struct die_info
*imported_die
, *child_die
;
10417 struct dwarf2_cu
*imported_cu
;
10418 const char *imported_name
;
10419 const char *imported_name_prefix
;
10420 const char *canonical_name
;
10421 const char *import_alias
;
10422 const char *imported_declaration
= NULL
;
10423 const char *import_prefix
;
10424 std::vector
<const char *> excludes
;
10426 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10427 if (import_attr
== NULL
)
10429 complaint (_("Tag '%s' has no DW_AT_import"),
10430 dwarf_tag_name (die
->tag
));
10435 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10436 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10437 if (imported_name
== NULL
)
10439 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10441 The import in the following code:
10455 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10456 <52> DW_AT_decl_file : 1
10457 <53> DW_AT_decl_line : 6
10458 <54> DW_AT_import : <0x75>
10459 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10460 <59> DW_AT_name : B
10461 <5b> DW_AT_decl_file : 1
10462 <5c> DW_AT_decl_line : 2
10463 <5d> DW_AT_type : <0x6e>
10465 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10466 <76> DW_AT_byte_size : 4
10467 <77> DW_AT_encoding : 5 (signed)
10469 imports the wrong die ( 0x75 instead of 0x58 ).
10470 This case will be ignored until the gcc bug is fixed. */
10474 /* Figure out the local name after import. */
10475 import_alias
= dwarf2_name (die
, cu
);
10477 /* Figure out where the statement is being imported to. */
10478 import_prefix
= determine_prefix (die
, cu
);
10480 /* Figure out what the scope of the imported die is and prepend it
10481 to the name of the imported die. */
10482 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10484 if (imported_die
->tag
!= DW_TAG_namespace
10485 && imported_die
->tag
!= DW_TAG_module
)
10487 imported_declaration
= imported_name
;
10488 canonical_name
= imported_name_prefix
;
10490 else if (strlen (imported_name_prefix
) > 0)
10491 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10492 imported_name_prefix
,
10493 (cu
->language
== language_d
? "." : "::"),
10494 imported_name
, (char *) NULL
);
10496 canonical_name
= imported_name
;
10498 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10499 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10500 child_die
= sibling_die (child_die
))
10502 /* DWARF-4: A Fortran use statement with a “rename list” may be
10503 represented by an imported module entry with an import attribute
10504 referring to the module and owned entries corresponding to those
10505 entities that are renamed as part of being imported. */
10507 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10509 complaint (_("child DW_TAG_imported_declaration expected "
10510 "- DIE at %s [in module %s]"),
10511 sect_offset_str (child_die
->sect_off
),
10512 objfile_name (objfile
));
10516 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10517 if (import_attr
== NULL
)
10519 complaint (_("Tag '%s' has no DW_AT_import"),
10520 dwarf_tag_name (child_die
->tag
));
10525 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10527 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10528 if (imported_name
== NULL
)
10530 complaint (_("child DW_TAG_imported_declaration has unknown "
10531 "imported name - DIE at %s [in module %s]"),
10532 sect_offset_str (child_die
->sect_off
),
10533 objfile_name (objfile
));
10537 excludes
.push_back (imported_name
);
10539 process_die (child_die
, cu
);
10542 add_using_directive (using_directives (cu
),
10546 imported_declaration
,
10549 &objfile
->objfile_obstack
);
10552 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10553 types, but gives them a size of zero. Starting with version 14,
10554 ICC is compatible with GCC. */
10557 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10559 if (!cu
->checked_producer
)
10560 check_producer (cu
);
10562 return cu
->producer_is_icc_lt_14
;
10565 /* ICC generates a DW_AT_type for C void functions. This was observed on
10566 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10567 which says that void functions should not have a DW_AT_type. */
10570 producer_is_icc (struct dwarf2_cu
*cu
)
10572 if (!cu
->checked_producer
)
10573 check_producer (cu
);
10575 return cu
->producer_is_icc
;
10578 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10579 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10580 this, it was first present in GCC release 4.3.0. */
10583 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10585 if (!cu
->checked_producer
)
10586 check_producer (cu
);
10588 return cu
->producer_is_gcc_lt_4_3
;
10591 static file_and_directory
10592 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10594 file_and_directory res
;
10596 /* Find the filename. Do not use dwarf2_name here, since the filename
10597 is not a source language identifier. */
10598 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10599 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10601 if (res
.comp_dir
== NULL
10602 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10603 && IS_ABSOLUTE_PATH (res
.name
))
10605 res
.comp_dir_storage
= ldirname (res
.name
);
10606 if (!res
.comp_dir_storage
.empty ())
10607 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10609 if (res
.comp_dir
!= NULL
)
10611 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10612 directory, get rid of it. */
10613 const char *cp
= strchr (res
.comp_dir
, ':');
10615 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10616 res
.comp_dir
= cp
+ 1;
10619 if (res
.name
== NULL
)
10620 res
.name
= "<unknown>";
10625 /* Handle DW_AT_stmt_list for a compilation unit.
10626 DIE is the DW_TAG_compile_unit die for CU.
10627 COMP_DIR is the compilation directory. LOWPC is passed to
10628 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10631 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10632 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10634 struct dwarf2_per_objfile
*dwarf2_per_objfile
10635 = cu
->per_cu
->dwarf2_per_objfile
;
10636 struct attribute
*attr
;
10637 struct line_header line_header_local
;
10638 hashval_t line_header_local_hash
;
10640 int decode_mapping
;
10642 gdb_assert (! cu
->per_cu
->is_debug_types
);
10644 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10648 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10650 /* The line header hash table is only created if needed (it exists to
10651 prevent redundant reading of the line table for partial_units).
10652 If we're given a partial_unit, we'll need it. If we're given a
10653 compile_unit, then use the line header hash table if it's already
10654 created, but don't create one just yet. */
10656 if (dwarf2_per_objfile
->line_header_hash
== NULL
10657 && die
->tag
== DW_TAG_partial_unit
)
10659 dwarf2_per_objfile
->line_header_hash
10660 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10661 line_header_eq_voidp
,
10662 free_line_header_voidp
,
10666 line_header_local
.sect_off
= line_offset
;
10667 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10668 line_header_local_hash
= line_header_hash (&line_header_local
);
10669 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10671 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10672 &line_header_local
,
10673 line_header_local_hash
, NO_INSERT
);
10675 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10676 is not present in *SLOT (since if there is something in *SLOT then
10677 it will be for a partial_unit). */
10678 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10680 gdb_assert (*slot
!= NULL
);
10681 cu
->line_header
= (struct line_header
*) *slot
;
10686 /* dwarf_decode_line_header does not yet provide sufficient information.
10687 We always have to call also dwarf_decode_lines for it. */
10688 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10692 cu
->line_header
= lh
.release ();
10693 cu
->line_header_die_owner
= die
;
10695 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10699 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10700 &line_header_local
,
10701 line_header_local_hash
, INSERT
);
10702 gdb_assert (slot
!= NULL
);
10704 if (slot
!= NULL
&& *slot
== NULL
)
10706 /* This newly decoded line number information unit will be owned
10707 by line_header_hash hash table. */
10708 *slot
= cu
->line_header
;
10709 cu
->line_header_die_owner
= NULL
;
10713 /* We cannot free any current entry in (*slot) as that struct line_header
10714 may be already used by multiple CUs. Create only temporary decoded
10715 line_header for this CU - it may happen at most once for each line
10716 number information unit. And if we're not using line_header_hash
10717 then this is what we want as well. */
10718 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10720 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10721 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10726 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10729 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10731 struct dwarf2_per_objfile
*dwarf2_per_objfile
10732 = cu
->per_cu
->dwarf2_per_objfile
;
10733 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10734 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10735 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10736 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10737 struct attribute
*attr
;
10738 struct die_info
*child_die
;
10739 CORE_ADDR baseaddr
;
10741 prepare_one_comp_unit (cu
, die
, cu
->language
);
10742 baseaddr
= objfile
->text_section_offset ();
10744 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10746 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10747 from finish_block. */
10748 if (lowpc
== ((CORE_ADDR
) -1))
10750 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10752 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10754 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10755 standardised yet. As a workaround for the language detection we fall
10756 back to the DW_AT_producer string. */
10757 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10758 cu
->language
= language_opencl
;
10760 /* Similar hack for Go. */
10761 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10762 set_cu_language (DW_LANG_Go
, cu
);
10764 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10766 /* Decode line number information if present. We do this before
10767 processing child DIEs, so that the line header table is available
10768 for DW_AT_decl_file. */
10769 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10771 /* Process all dies in compilation unit. */
10772 if (die
->child
!= NULL
)
10774 child_die
= die
->child
;
10775 while (child_die
&& child_die
->tag
)
10777 process_die (child_die
, cu
);
10778 child_die
= sibling_die (child_die
);
10782 /* Decode macro information, if present. Dwarf 2 macro information
10783 refers to information in the line number info statement program
10784 header, so we can only read it if we've read the header
10786 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10788 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10789 if (attr
&& cu
->line_header
)
10791 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10792 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10794 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10798 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10799 if (attr
&& cu
->line_header
)
10801 unsigned int macro_offset
= DW_UNSND (attr
);
10803 dwarf_decode_macros (cu
, macro_offset
, 0);
10809 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10811 struct type_unit_group
*tu_group
;
10813 struct attribute
*attr
;
10815 struct signatured_type
*sig_type
;
10817 gdb_assert (per_cu
->is_debug_types
);
10818 sig_type
= (struct signatured_type
*) per_cu
;
10820 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10822 /* If we're using .gdb_index (includes -readnow) then
10823 per_cu->type_unit_group may not have been set up yet. */
10824 if (sig_type
->type_unit_group
== NULL
)
10825 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10826 tu_group
= sig_type
->type_unit_group
;
10828 /* If we've already processed this stmt_list there's no real need to
10829 do it again, we could fake it and just recreate the part we need
10830 (file name,index -> symtab mapping). If data shows this optimization
10831 is useful we can do it then. */
10832 first_time
= tu_group
->compunit_symtab
== NULL
;
10834 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10839 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10840 lh
= dwarf_decode_line_header (line_offset
, this);
10845 start_symtab ("", NULL
, 0);
10848 gdb_assert (tu_group
->symtabs
== NULL
);
10849 gdb_assert (m_builder
== nullptr);
10850 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10851 m_builder
.reset (new struct buildsym_compunit
10852 (COMPUNIT_OBJFILE (cust
), "",
10853 COMPUNIT_DIRNAME (cust
),
10854 compunit_language (cust
),
10860 line_header
= lh
.release ();
10861 line_header_die_owner
= die
;
10865 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10867 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10868 still initializing it, and our caller (a few levels up)
10869 process_full_type_unit still needs to know if this is the first
10872 tu_group
->num_symtabs
= line_header
->file_names_size ();
10873 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
10874 line_header
->file_names_size ());
10876 auto &file_names
= line_header
->file_names ();
10877 for (i
= 0; i
< file_names
.size (); ++i
)
10879 file_entry
&fe
= file_names
[i
];
10880 dwarf2_start_subfile (this, fe
.name
,
10881 fe
.include_dir (line_header
));
10882 buildsym_compunit
*b
= get_builder ();
10883 if (b
->get_current_subfile ()->symtab
== NULL
)
10885 /* NOTE: start_subfile will recognize when it's been
10886 passed a file it has already seen. So we can't
10887 assume there's a simple mapping from
10888 cu->line_header->file_names to subfiles, plus
10889 cu->line_header->file_names may contain dups. */
10890 b
->get_current_subfile ()->symtab
10891 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10894 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10895 tu_group
->symtabs
[i
] = fe
.symtab
;
10900 gdb_assert (m_builder
== nullptr);
10901 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10902 m_builder
.reset (new struct buildsym_compunit
10903 (COMPUNIT_OBJFILE (cust
), "",
10904 COMPUNIT_DIRNAME (cust
),
10905 compunit_language (cust
),
10908 auto &file_names
= line_header
->file_names ();
10909 for (i
= 0; i
< file_names
.size (); ++i
)
10911 file_entry
&fe
= file_names
[i
];
10912 fe
.symtab
= tu_group
->symtabs
[i
];
10916 /* The main symtab is allocated last. Type units don't have DW_AT_name
10917 so they don't have a "real" (so to speak) symtab anyway.
10918 There is later code that will assign the main symtab to all symbols
10919 that don't have one. We need to handle the case of a symbol with a
10920 missing symtab (DW_AT_decl_file) anyway. */
10923 /* Process DW_TAG_type_unit.
10924 For TUs we want to skip the first top level sibling if it's not the
10925 actual type being defined by this TU. In this case the first top
10926 level sibling is there to provide context only. */
10929 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10931 struct die_info
*child_die
;
10933 prepare_one_comp_unit (cu
, die
, language_minimal
);
10935 /* Initialize (or reinitialize) the machinery for building symtabs.
10936 We do this before processing child DIEs, so that the line header table
10937 is available for DW_AT_decl_file. */
10938 cu
->setup_type_unit_groups (die
);
10940 if (die
->child
!= NULL
)
10942 child_die
= die
->child
;
10943 while (child_die
&& child_die
->tag
)
10945 process_die (child_die
, cu
);
10946 child_die
= sibling_die (child_die
);
10953 http://gcc.gnu.org/wiki/DebugFission
10954 http://gcc.gnu.org/wiki/DebugFissionDWP
10956 To simplify handling of both DWO files ("object" files with the DWARF info)
10957 and DWP files (a file with the DWOs packaged up into one file), we treat
10958 DWP files as having a collection of virtual DWO files. */
10961 hash_dwo_file (const void *item
)
10963 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10966 hash
= htab_hash_string (dwo_file
->dwo_name
);
10967 if (dwo_file
->comp_dir
!= NULL
)
10968 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10973 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10975 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10976 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10978 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10980 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10981 return lhs
->comp_dir
== rhs
->comp_dir
;
10982 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10985 /* Allocate a hash table for DWO files. */
10988 allocate_dwo_file_hash_table (struct objfile
*objfile
)
10990 auto delete_dwo_file
= [] (void *item
)
10992 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10997 return htab_up (htab_create_alloc (41,
11004 /* Lookup DWO file DWO_NAME. */
11007 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11008 const char *dwo_name
,
11009 const char *comp_dir
)
11011 struct dwo_file find_entry
;
11014 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11015 dwarf2_per_objfile
->dwo_files
11016 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11018 find_entry
.dwo_name
= dwo_name
;
11019 find_entry
.comp_dir
= comp_dir
;
11020 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11027 hash_dwo_unit (const void *item
)
11029 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11031 /* This drops the top 32 bits of the id, but is ok for a hash. */
11032 return dwo_unit
->signature
;
11036 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11038 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11039 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11041 /* The signature is assumed to be unique within the DWO file.
11042 So while object file CU dwo_id's always have the value zero,
11043 that's OK, assuming each object file DWO file has only one CU,
11044 and that's the rule for now. */
11045 return lhs
->signature
== rhs
->signature
;
11048 /* Allocate a hash table for DWO CUs,TUs.
11049 There is one of these tables for each of CUs,TUs for each DWO file. */
11052 allocate_dwo_unit_table (struct objfile
*objfile
)
11054 /* Start out with a pretty small number.
11055 Generally DWO files contain only one CU and maybe some TUs. */
11056 return htab_up (htab_create_alloc (3,
11059 NULL
, xcalloc
, xfree
));
11062 /* die_reader_func for create_dwo_cu. */
11065 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11066 const gdb_byte
*info_ptr
,
11067 struct die_info
*comp_unit_die
,
11068 struct dwo_file
*dwo_file
,
11069 struct dwo_unit
*dwo_unit
)
11071 struct dwarf2_cu
*cu
= reader
->cu
;
11072 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11073 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11075 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11076 if (!signature
.has_value ())
11078 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11079 " its dwo_id [in module %s]"),
11080 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11084 dwo_unit
->dwo_file
= dwo_file
;
11085 dwo_unit
->signature
= *signature
;
11086 dwo_unit
->section
= section
;
11087 dwo_unit
->sect_off
= sect_off
;
11088 dwo_unit
->length
= cu
->per_cu
->length
;
11090 if (dwarf_read_debug
)
11091 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11092 sect_offset_str (sect_off
),
11093 hex_string (dwo_unit
->signature
));
11096 /* Create the dwo_units for the CUs in a DWO_FILE.
11097 Note: This function processes DWO files only, not DWP files. */
11100 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11101 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11102 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11104 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11105 const gdb_byte
*info_ptr
, *end_ptr
;
11107 section
.read (objfile
);
11108 info_ptr
= section
.buffer
;
11110 if (info_ptr
== NULL
)
11113 if (dwarf_read_debug
)
11115 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11116 section
.get_name (),
11117 section
.get_file_name ());
11120 end_ptr
= info_ptr
+ section
.size
;
11121 while (info_ptr
< end_ptr
)
11123 struct dwarf2_per_cu_data per_cu
;
11124 struct dwo_unit read_unit
{};
11125 struct dwo_unit
*dwo_unit
;
11127 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11129 memset (&per_cu
, 0, sizeof (per_cu
));
11130 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11131 per_cu
.is_debug_types
= 0;
11132 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11133 per_cu
.section
= §ion
;
11135 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11136 if (!reader
.dummy_p
)
11137 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11138 &dwo_file
, &read_unit
);
11139 info_ptr
+= per_cu
.length
;
11141 // If the unit could not be parsed, skip it.
11142 if (read_unit
.dwo_file
== NULL
)
11145 if (cus_htab
== NULL
)
11146 cus_htab
= allocate_dwo_unit_table (objfile
);
11148 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11149 *dwo_unit
= read_unit
;
11150 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11151 gdb_assert (slot
!= NULL
);
11154 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11155 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11157 complaint (_("debug cu entry at offset %s is duplicate to"
11158 " the entry at offset %s, signature %s"),
11159 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11160 hex_string (dwo_unit
->signature
));
11162 *slot
= (void *)dwo_unit
;
11166 /* DWP file .debug_{cu,tu}_index section format:
11167 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11171 Both index sections have the same format, and serve to map a 64-bit
11172 signature to a set of section numbers. Each section begins with a header,
11173 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11174 indexes, and a pool of 32-bit section numbers. The index sections will be
11175 aligned at 8-byte boundaries in the file.
11177 The index section header consists of:
11179 V, 32 bit version number
11181 N, 32 bit number of compilation units or type units in the index
11182 M, 32 bit number of slots in the hash table
11184 Numbers are recorded using the byte order of the application binary.
11186 The hash table begins at offset 16 in the section, and consists of an array
11187 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11188 order of the application binary). Unused slots in the hash table are 0.
11189 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11191 The parallel table begins immediately after the hash table
11192 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11193 array of 32-bit indexes (using the byte order of the application binary),
11194 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11195 table contains a 32-bit index into the pool of section numbers. For unused
11196 hash table slots, the corresponding entry in the parallel table will be 0.
11198 The pool of section numbers begins immediately following the hash table
11199 (at offset 16 + 12 * M from the beginning of the section). The pool of
11200 section numbers consists of an array of 32-bit words (using the byte order
11201 of the application binary). Each item in the array is indexed starting
11202 from 0. The hash table entry provides the index of the first section
11203 number in the set. Additional section numbers in the set follow, and the
11204 set is terminated by a 0 entry (section number 0 is not used in ELF).
11206 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11207 section must be the first entry in the set, and the .debug_abbrev.dwo must
11208 be the second entry. Other members of the set may follow in any order.
11214 DWP Version 2 combines all the .debug_info, etc. sections into one,
11215 and the entries in the index tables are now offsets into these sections.
11216 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11219 Index Section Contents:
11221 Hash Table of Signatures dwp_hash_table.hash_table
11222 Parallel Table of Indices dwp_hash_table.unit_table
11223 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11224 Table of Section Sizes dwp_hash_table.v2.sizes
11226 The index section header consists of:
11228 V, 32 bit version number
11229 L, 32 bit number of columns in the table of section offsets
11230 N, 32 bit number of compilation units or type units in the index
11231 M, 32 bit number of slots in the hash table
11233 Numbers are recorded using the byte order of the application binary.
11235 The hash table has the same format as version 1.
11236 The parallel table of indices has the same format as version 1,
11237 except that the entries are origin-1 indices into the table of sections
11238 offsets and the table of section sizes.
11240 The table of offsets begins immediately following the parallel table
11241 (at offset 16 + 12 * M from the beginning of the section). The table is
11242 a two-dimensional array of 32-bit words (using the byte order of the
11243 application binary), with L columns and N+1 rows, in row-major order.
11244 Each row in the array is indexed starting from 0. The first row provides
11245 a key to the remaining rows: each column in this row provides an identifier
11246 for a debug section, and the offsets in the same column of subsequent rows
11247 refer to that section. The section identifiers are:
11249 DW_SECT_INFO 1 .debug_info.dwo
11250 DW_SECT_TYPES 2 .debug_types.dwo
11251 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11252 DW_SECT_LINE 4 .debug_line.dwo
11253 DW_SECT_LOC 5 .debug_loc.dwo
11254 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11255 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11256 DW_SECT_MACRO 8 .debug_macro.dwo
11258 The offsets provided by the CU and TU index sections are the base offsets
11259 for the contributions made by each CU or TU to the corresponding section
11260 in the package file. Each CU and TU header contains an abbrev_offset
11261 field, used to find the abbreviations table for that CU or TU within the
11262 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11263 be interpreted as relative to the base offset given in the index section.
11264 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11265 should be interpreted as relative to the base offset for .debug_line.dwo,
11266 and offsets into other debug sections obtained from DWARF attributes should
11267 also be interpreted as relative to the corresponding base offset.
11269 The table of sizes begins immediately following the table of offsets.
11270 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11271 with L columns and N rows, in row-major order. Each row in the array is
11272 indexed starting from 1 (row 0 is shared by the two tables).
11276 Hash table lookup is handled the same in version 1 and 2:
11278 We assume that N and M will not exceed 2^32 - 1.
11279 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11281 Given a 64-bit compilation unit signature or a type signature S, an entry
11282 in the hash table is located as follows:
11284 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11285 the low-order k bits all set to 1.
11287 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11289 3) If the hash table entry at index H matches the signature, use that
11290 entry. If the hash table entry at index H is unused (all zeroes),
11291 terminate the search: the signature is not present in the table.
11293 4) Let H = (H + H') modulo M. Repeat at Step 3.
11295 Because M > N and H' and M are relatively prime, the search is guaranteed
11296 to stop at an unused slot or find the match. */
11298 /* Create a hash table to map DWO IDs to their CU/TU entry in
11299 .debug_{info,types}.dwo in DWP_FILE.
11300 Returns NULL if there isn't one.
11301 Note: This function processes DWP files only, not DWO files. */
11303 static struct dwp_hash_table
*
11304 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11305 struct dwp_file
*dwp_file
, int is_debug_types
)
11307 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11308 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11309 const gdb_byte
*index_ptr
, *index_end
;
11310 struct dwarf2_section_info
*index
;
11311 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11312 struct dwp_hash_table
*htab
;
11314 if (is_debug_types
)
11315 index
= &dwp_file
->sections
.tu_index
;
11317 index
= &dwp_file
->sections
.cu_index
;
11319 if (index
->empty ())
11321 index
->read (objfile
);
11323 index_ptr
= index
->buffer
;
11324 index_end
= index_ptr
+ index
->size
;
11326 version
= read_4_bytes (dbfd
, index_ptr
);
11329 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11333 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11335 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11338 if (version
!= 1 && version
!= 2)
11340 error (_("Dwarf Error: unsupported DWP file version (%s)"
11341 " [in module %s]"),
11342 pulongest (version
), dwp_file
->name
);
11344 if (nr_slots
!= (nr_slots
& -nr_slots
))
11346 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11347 " is not power of 2 [in module %s]"),
11348 pulongest (nr_slots
), dwp_file
->name
);
11351 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11352 htab
->version
= version
;
11353 htab
->nr_columns
= nr_columns
;
11354 htab
->nr_units
= nr_units
;
11355 htab
->nr_slots
= nr_slots
;
11356 htab
->hash_table
= index_ptr
;
11357 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11359 /* Exit early if the table is empty. */
11360 if (nr_slots
== 0 || nr_units
== 0
11361 || (version
== 2 && nr_columns
== 0))
11363 /* All must be zero. */
11364 if (nr_slots
!= 0 || nr_units
!= 0
11365 || (version
== 2 && nr_columns
!= 0))
11367 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11368 " all zero [in modules %s]"),
11376 htab
->section_pool
.v1
.indices
=
11377 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11378 /* It's harder to decide whether the section is too small in v1.
11379 V1 is deprecated anyway so we punt. */
11383 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11384 int *ids
= htab
->section_pool
.v2
.section_ids
;
11385 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11386 /* Reverse map for error checking. */
11387 int ids_seen
[DW_SECT_MAX
+ 1];
11390 if (nr_columns
< 2)
11392 error (_("Dwarf Error: bad DWP hash table, too few columns"
11393 " in section table [in module %s]"),
11396 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11398 error (_("Dwarf Error: bad DWP hash table, too many columns"
11399 " in section table [in module %s]"),
11402 memset (ids
, 255, sizeof_ids
);
11403 memset (ids_seen
, 255, sizeof (ids_seen
));
11404 for (i
= 0; i
< nr_columns
; ++i
)
11406 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11408 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11410 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11411 " in section table [in module %s]"),
11412 id
, dwp_file
->name
);
11414 if (ids_seen
[id
] != -1)
11416 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11417 " id %d in section table [in module %s]"),
11418 id
, dwp_file
->name
);
11423 /* Must have exactly one info or types section. */
11424 if (((ids_seen
[DW_SECT_INFO
] != -1)
11425 + (ids_seen
[DW_SECT_TYPES
] != -1))
11428 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11429 " DWO info/types section [in module %s]"),
11432 /* Must have an abbrev section. */
11433 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11435 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11436 " section [in module %s]"),
11439 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11440 htab
->section_pool
.v2
.sizes
=
11441 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11442 * nr_units
* nr_columns
);
11443 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11444 * nr_units
* nr_columns
))
11447 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11448 " [in module %s]"),
11456 /* Update SECTIONS with the data from SECTP.
11458 This function is like the other "locate" section routines that are
11459 passed to bfd_map_over_sections, but in this context the sections to
11460 read comes from the DWP V1 hash table, not the full ELF section table.
11462 The result is non-zero for success, or zero if an error was found. */
11465 locate_v1_virtual_dwo_sections (asection
*sectp
,
11466 struct virtual_v1_dwo_sections
*sections
)
11468 const struct dwop_section_names
*names
= &dwop_section_names
;
11470 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11472 /* There can be only one. */
11473 if (sections
->abbrev
.s
.section
!= NULL
)
11475 sections
->abbrev
.s
.section
= sectp
;
11476 sections
->abbrev
.size
= bfd_section_size (sectp
);
11478 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11479 || section_is_p (sectp
->name
, &names
->types_dwo
))
11481 /* There can be only one. */
11482 if (sections
->info_or_types
.s
.section
!= NULL
)
11484 sections
->info_or_types
.s
.section
= sectp
;
11485 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11487 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11489 /* There can be only one. */
11490 if (sections
->line
.s
.section
!= NULL
)
11492 sections
->line
.s
.section
= sectp
;
11493 sections
->line
.size
= bfd_section_size (sectp
);
11495 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11497 /* There can be only one. */
11498 if (sections
->loc
.s
.section
!= NULL
)
11500 sections
->loc
.s
.section
= sectp
;
11501 sections
->loc
.size
= bfd_section_size (sectp
);
11503 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11505 /* There can be only one. */
11506 if (sections
->macinfo
.s
.section
!= NULL
)
11508 sections
->macinfo
.s
.section
= sectp
;
11509 sections
->macinfo
.size
= bfd_section_size (sectp
);
11511 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11513 /* There can be only one. */
11514 if (sections
->macro
.s
.section
!= NULL
)
11516 sections
->macro
.s
.section
= sectp
;
11517 sections
->macro
.size
= bfd_section_size (sectp
);
11519 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11521 /* There can be only one. */
11522 if (sections
->str_offsets
.s
.section
!= NULL
)
11524 sections
->str_offsets
.s
.section
= sectp
;
11525 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11529 /* No other kind of section is valid. */
11536 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11537 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11538 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11539 This is for DWP version 1 files. */
11541 static struct dwo_unit
*
11542 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11543 struct dwp_file
*dwp_file
,
11544 uint32_t unit_index
,
11545 const char *comp_dir
,
11546 ULONGEST signature
, int is_debug_types
)
11548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11549 const struct dwp_hash_table
*dwp_htab
=
11550 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11551 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11552 const char *kind
= is_debug_types
? "TU" : "CU";
11553 struct dwo_file
*dwo_file
;
11554 struct dwo_unit
*dwo_unit
;
11555 struct virtual_v1_dwo_sections sections
;
11556 void **dwo_file_slot
;
11559 gdb_assert (dwp_file
->version
== 1);
11561 if (dwarf_read_debug
)
11563 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11565 pulongest (unit_index
), hex_string (signature
),
11569 /* Fetch the sections of this DWO unit.
11570 Put a limit on the number of sections we look for so that bad data
11571 doesn't cause us to loop forever. */
11573 #define MAX_NR_V1_DWO_SECTIONS \
11574 (1 /* .debug_info or .debug_types */ \
11575 + 1 /* .debug_abbrev */ \
11576 + 1 /* .debug_line */ \
11577 + 1 /* .debug_loc */ \
11578 + 1 /* .debug_str_offsets */ \
11579 + 1 /* .debug_macro or .debug_macinfo */ \
11580 + 1 /* trailing zero */)
11582 memset (§ions
, 0, sizeof (sections
));
11584 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11587 uint32_t section_nr
=
11588 read_4_bytes (dbfd
,
11589 dwp_htab
->section_pool
.v1
.indices
11590 + (unit_index
+ i
) * sizeof (uint32_t));
11592 if (section_nr
== 0)
11594 if (section_nr
>= dwp_file
->num_sections
)
11596 error (_("Dwarf Error: bad DWP hash table, section number too large"
11597 " [in module %s]"),
11601 sectp
= dwp_file
->elf_sections
[section_nr
];
11602 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11604 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11605 " [in module %s]"),
11611 || sections
.info_or_types
.empty ()
11612 || sections
.abbrev
.empty ())
11614 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11615 " [in module %s]"),
11618 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11620 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11621 " [in module %s]"),
11625 /* It's easier for the rest of the code if we fake a struct dwo_file and
11626 have dwo_unit "live" in that. At least for now.
11628 The DWP file can be made up of a random collection of CUs and TUs.
11629 However, for each CU + set of TUs that came from the same original DWO
11630 file, we can combine them back into a virtual DWO file to save space
11631 (fewer struct dwo_file objects to allocate). Remember that for really
11632 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11634 std::string virtual_dwo_name
=
11635 string_printf ("virtual-dwo/%d-%d-%d-%d",
11636 sections
.abbrev
.get_id (),
11637 sections
.line
.get_id (),
11638 sections
.loc
.get_id (),
11639 sections
.str_offsets
.get_id ());
11640 /* Can we use an existing virtual DWO file? */
11641 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11642 virtual_dwo_name
.c_str (),
11644 /* Create one if necessary. */
11645 if (*dwo_file_slot
== NULL
)
11647 if (dwarf_read_debug
)
11649 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11650 virtual_dwo_name
.c_str ());
11652 dwo_file
= new struct dwo_file
;
11653 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11655 dwo_file
->comp_dir
= comp_dir
;
11656 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11657 dwo_file
->sections
.line
= sections
.line
;
11658 dwo_file
->sections
.loc
= sections
.loc
;
11659 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11660 dwo_file
->sections
.macro
= sections
.macro
;
11661 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11662 /* The "str" section is global to the entire DWP file. */
11663 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11664 /* The info or types section is assigned below to dwo_unit,
11665 there's no need to record it in dwo_file.
11666 Also, we can't simply record type sections in dwo_file because
11667 we record a pointer into the vector in dwo_unit. As we collect more
11668 types we'll grow the vector and eventually have to reallocate space
11669 for it, invalidating all copies of pointers into the previous
11671 *dwo_file_slot
= dwo_file
;
11675 if (dwarf_read_debug
)
11677 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11678 virtual_dwo_name
.c_str ());
11680 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11683 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11684 dwo_unit
->dwo_file
= dwo_file
;
11685 dwo_unit
->signature
= signature
;
11686 dwo_unit
->section
=
11687 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11688 *dwo_unit
->section
= sections
.info_or_types
;
11689 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11694 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11695 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11696 piece within that section used by a TU/CU, return a virtual section
11697 of just that piece. */
11699 static struct dwarf2_section_info
11700 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11701 struct dwarf2_section_info
*section
,
11702 bfd_size_type offset
, bfd_size_type size
)
11704 struct dwarf2_section_info result
;
11707 gdb_assert (section
!= NULL
);
11708 gdb_assert (!section
->is_virtual
);
11710 memset (&result
, 0, sizeof (result
));
11711 result
.s
.containing_section
= section
;
11712 result
.is_virtual
= true;
11717 sectp
= section
->get_bfd_section ();
11719 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11720 bounds of the real section. This is a pretty-rare event, so just
11721 flag an error (easier) instead of a warning and trying to cope. */
11723 || offset
+ size
> bfd_section_size (sectp
))
11725 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11726 " in section %s [in module %s]"),
11727 sectp
? bfd_section_name (sectp
) : "<unknown>",
11728 objfile_name (dwarf2_per_objfile
->objfile
));
11731 result
.virtual_offset
= offset
;
11732 result
.size
= size
;
11736 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11737 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11738 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11739 This is for DWP version 2 files. */
11741 static struct dwo_unit
*
11742 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11743 struct dwp_file
*dwp_file
,
11744 uint32_t unit_index
,
11745 const char *comp_dir
,
11746 ULONGEST signature
, int is_debug_types
)
11748 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11749 const struct dwp_hash_table
*dwp_htab
=
11750 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11751 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11752 const char *kind
= is_debug_types
? "TU" : "CU";
11753 struct dwo_file
*dwo_file
;
11754 struct dwo_unit
*dwo_unit
;
11755 struct virtual_v2_dwo_sections sections
;
11756 void **dwo_file_slot
;
11759 gdb_assert (dwp_file
->version
== 2);
11761 if (dwarf_read_debug
)
11763 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11765 pulongest (unit_index
), hex_string (signature
),
11769 /* Fetch the section offsets of this DWO unit. */
11771 memset (§ions
, 0, sizeof (sections
));
11773 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11775 uint32_t offset
= read_4_bytes (dbfd
,
11776 dwp_htab
->section_pool
.v2
.offsets
11777 + (((unit_index
- 1) * dwp_htab
->nr_columns
11779 * sizeof (uint32_t)));
11780 uint32_t size
= read_4_bytes (dbfd
,
11781 dwp_htab
->section_pool
.v2
.sizes
11782 + (((unit_index
- 1) * dwp_htab
->nr_columns
11784 * sizeof (uint32_t)));
11786 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11789 case DW_SECT_TYPES
:
11790 sections
.info_or_types_offset
= offset
;
11791 sections
.info_or_types_size
= size
;
11793 case DW_SECT_ABBREV
:
11794 sections
.abbrev_offset
= offset
;
11795 sections
.abbrev_size
= size
;
11798 sections
.line_offset
= offset
;
11799 sections
.line_size
= size
;
11802 sections
.loc_offset
= offset
;
11803 sections
.loc_size
= size
;
11805 case DW_SECT_STR_OFFSETS
:
11806 sections
.str_offsets_offset
= offset
;
11807 sections
.str_offsets_size
= size
;
11809 case DW_SECT_MACINFO
:
11810 sections
.macinfo_offset
= offset
;
11811 sections
.macinfo_size
= size
;
11813 case DW_SECT_MACRO
:
11814 sections
.macro_offset
= offset
;
11815 sections
.macro_size
= size
;
11820 /* It's easier for the rest of the code if we fake a struct dwo_file and
11821 have dwo_unit "live" in that. At least for now.
11823 The DWP file can be made up of a random collection of CUs and TUs.
11824 However, for each CU + set of TUs that came from the same original DWO
11825 file, we can combine them back into a virtual DWO file to save space
11826 (fewer struct dwo_file objects to allocate). Remember that for really
11827 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11829 std::string virtual_dwo_name
=
11830 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11831 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11832 (long) (sections
.line_size
? sections
.line_offset
: 0),
11833 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11834 (long) (sections
.str_offsets_size
11835 ? sections
.str_offsets_offset
: 0));
11836 /* Can we use an existing virtual DWO file? */
11837 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11838 virtual_dwo_name
.c_str (),
11840 /* Create one if necessary. */
11841 if (*dwo_file_slot
== NULL
)
11843 if (dwarf_read_debug
)
11845 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11846 virtual_dwo_name
.c_str ());
11848 dwo_file
= new struct dwo_file
;
11849 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11851 dwo_file
->comp_dir
= comp_dir
;
11852 dwo_file
->sections
.abbrev
=
11853 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11854 sections
.abbrev_offset
, sections
.abbrev_size
);
11855 dwo_file
->sections
.line
=
11856 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11857 sections
.line_offset
, sections
.line_size
);
11858 dwo_file
->sections
.loc
=
11859 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11860 sections
.loc_offset
, sections
.loc_size
);
11861 dwo_file
->sections
.macinfo
=
11862 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11863 sections
.macinfo_offset
, sections
.macinfo_size
);
11864 dwo_file
->sections
.macro
=
11865 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11866 sections
.macro_offset
, sections
.macro_size
);
11867 dwo_file
->sections
.str_offsets
=
11868 create_dwp_v2_section (dwarf2_per_objfile
,
11869 &dwp_file
->sections
.str_offsets
,
11870 sections
.str_offsets_offset
,
11871 sections
.str_offsets_size
);
11872 /* The "str" section is global to the entire DWP file. */
11873 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11874 /* The info or types section is assigned below to dwo_unit,
11875 there's no need to record it in dwo_file.
11876 Also, we can't simply record type sections in dwo_file because
11877 we record a pointer into the vector in dwo_unit. As we collect more
11878 types we'll grow the vector and eventually have to reallocate space
11879 for it, invalidating all copies of pointers into the previous
11881 *dwo_file_slot
= dwo_file
;
11885 if (dwarf_read_debug
)
11887 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11888 virtual_dwo_name
.c_str ());
11890 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11893 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11894 dwo_unit
->dwo_file
= dwo_file
;
11895 dwo_unit
->signature
= signature
;
11896 dwo_unit
->section
=
11897 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11898 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11900 ? &dwp_file
->sections
.types
11901 : &dwp_file
->sections
.info
,
11902 sections
.info_or_types_offset
,
11903 sections
.info_or_types_size
);
11904 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11909 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11910 Returns NULL if the signature isn't found. */
11912 static struct dwo_unit
*
11913 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11914 struct dwp_file
*dwp_file
, const char *comp_dir
,
11915 ULONGEST signature
, int is_debug_types
)
11917 const struct dwp_hash_table
*dwp_htab
=
11918 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11919 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11920 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11921 uint32_t hash
= signature
& mask
;
11922 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11925 struct dwo_unit find_dwo_cu
;
11927 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11928 find_dwo_cu
.signature
= signature
;
11929 slot
= htab_find_slot (is_debug_types
11930 ? dwp_file
->loaded_tus
.get ()
11931 : dwp_file
->loaded_cus
.get (),
11932 &find_dwo_cu
, INSERT
);
11935 return (struct dwo_unit
*) *slot
;
11937 /* Use a for loop so that we don't loop forever on bad debug info. */
11938 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11940 ULONGEST signature_in_table
;
11942 signature_in_table
=
11943 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11944 if (signature_in_table
== signature
)
11946 uint32_t unit_index
=
11947 read_4_bytes (dbfd
,
11948 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11950 if (dwp_file
->version
== 1)
11952 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11953 dwp_file
, unit_index
,
11954 comp_dir
, signature
,
11959 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11960 dwp_file
, unit_index
,
11961 comp_dir
, signature
,
11964 return (struct dwo_unit
*) *slot
;
11966 if (signature_in_table
== 0)
11968 hash
= (hash
+ hash2
) & mask
;
11971 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11972 " [in module %s]"),
11976 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11977 Open the file specified by FILE_NAME and hand it off to BFD for
11978 preliminary analysis. Return a newly initialized bfd *, which
11979 includes a canonicalized copy of FILE_NAME.
11980 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11981 SEARCH_CWD is true if the current directory is to be searched.
11982 It will be searched before debug-file-directory.
11983 If successful, the file is added to the bfd include table of the
11984 objfile's bfd (see gdb_bfd_record_inclusion).
11985 If unable to find/open the file, return NULL.
11986 NOTE: This function is derived from symfile_bfd_open. */
11988 static gdb_bfd_ref_ptr
11989 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11990 const char *file_name
, int is_dwp
, int search_cwd
)
11993 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11994 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11995 to debug_file_directory. */
11996 const char *search_path
;
11997 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11999 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12002 if (*debug_file_directory
!= '\0')
12004 search_path_holder
.reset (concat (".", dirname_separator_string
,
12005 debug_file_directory
,
12007 search_path
= search_path_holder
.get ();
12013 search_path
= debug_file_directory
;
12015 openp_flags flags
= OPF_RETURN_REALPATH
;
12017 flags
|= OPF_SEARCH_IN_PATH
;
12019 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12020 desc
= openp (search_path
, flags
, file_name
,
12021 O_RDONLY
| O_BINARY
, &absolute_name
);
12025 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12027 if (sym_bfd
== NULL
)
12029 bfd_set_cacheable (sym_bfd
.get (), 1);
12031 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12034 /* Success. Record the bfd as having been included by the objfile's bfd.
12035 This is important because things like demangled_names_hash lives in the
12036 objfile's per_bfd space and may have references to things like symbol
12037 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12038 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12043 /* Try to open DWO file FILE_NAME.
12044 COMP_DIR is the DW_AT_comp_dir attribute.
12045 The result is the bfd handle of the file.
12046 If there is a problem finding or opening the file, return NULL.
12047 Upon success, the canonicalized path of the file is stored in the bfd,
12048 same as symfile_bfd_open. */
12050 static gdb_bfd_ref_ptr
12051 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12052 const char *file_name
, const char *comp_dir
)
12054 if (IS_ABSOLUTE_PATH (file_name
))
12055 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12056 0 /*is_dwp*/, 0 /*search_cwd*/);
12058 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12060 if (comp_dir
!= NULL
)
12062 gdb::unique_xmalloc_ptr
<char> path_to_try
12063 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12065 /* NOTE: If comp_dir is a relative path, this will also try the
12066 search path, which seems useful. */
12067 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12068 path_to_try
.get (),
12070 1 /*search_cwd*/));
12075 /* That didn't work, try debug-file-directory, which, despite its name,
12076 is a list of paths. */
12078 if (*debug_file_directory
== '\0')
12081 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12082 0 /*is_dwp*/, 1 /*search_cwd*/);
12085 /* This function is mapped across the sections and remembers the offset and
12086 size of each of the DWO debugging sections we are interested in. */
12089 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12091 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12092 const struct dwop_section_names
*names
= &dwop_section_names
;
12094 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12096 dwo_sections
->abbrev
.s
.section
= sectp
;
12097 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12099 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12101 dwo_sections
->info
.s
.section
= sectp
;
12102 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12104 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12106 dwo_sections
->line
.s
.section
= sectp
;
12107 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12109 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12111 dwo_sections
->loc
.s
.section
= sectp
;
12112 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12114 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12116 dwo_sections
->macinfo
.s
.section
= sectp
;
12117 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12119 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12121 dwo_sections
->macro
.s
.section
= sectp
;
12122 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12124 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12126 dwo_sections
->str
.s
.section
= sectp
;
12127 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12129 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12131 dwo_sections
->str_offsets
.s
.section
= sectp
;
12132 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12134 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12136 struct dwarf2_section_info type_section
;
12138 memset (&type_section
, 0, sizeof (type_section
));
12139 type_section
.s
.section
= sectp
;
12140 type_section
.size
= bfd_section_size (sectp
);
12141 dwo_sections
->types
.push_back (type_section
);
12145 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12146 by PER_CU. This is for the non-DWP case.
12147 The result is NULL if DWO_NAME can't be found. */
12149 static struct dwo_file
*
12150 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12151 const char *dwo_name
, const char *comp_dir
)
12153 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12155 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12158 if (dwarf_read_debug
)
12159 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12163 dwo_file_up
dwo_file (new struct dwo_file
);
12164 dwo_file
->dwo_name
= dwo_name
;
12165 dwo_file
->comp_dir
= comp_dir
;
12166 dwo_file
->dbfd
= std::move (dbfd
);
12168 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12169 &dwo_file
->sections
);
12171 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12172 dwo_file
->sections
.info
, dwo_file
->cus
);
12174 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12175 dwo_file
->sections
.types
, dwo_file
->tus
);
12177 if (dwarf_read_debug
)
12178 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12180 return dwo_file
.release ();
12183 /* This function is mapped across the sections and remembers the offset and
12184 size of each of the DWP debugging sections common to version 1 and 2 that
12185 we are interested in. */
12188 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12189 void *dwp_file_ptr
)
12191 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12192 const struct dwop_section_names
*names
= &dwop_section_names
;
12193 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12195 /* Record the ELF section number for later lookup: this is what the
12196 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12197 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12198 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12200 /* Look for specific sections that we need. */
12201 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12203 dwp_file
->sections
.str
.s
.section
= sectp
;
12204 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12206 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12208 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12209 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12211 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12213 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12214 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12218 /* This function is mapped across the sections and remembers the offset and
12219 size of each of the DWP version 2 debugging sections that we are interested
12220 in. This is split into a separate function because we don't know if we
12221 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12224 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12226 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12227 const struct dwop_section_names
*names
= &dwop_section_names
;
12228 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12230 /* Record the ELF section number for later lookup: this is what the
12231 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12232 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12233 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12235 /* Look for specific sections that we need. */
12236 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12238 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12239 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12241 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12243 dwp_file
->sections
.info
.s
.section
= sectp
;
12244 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12246 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12248 dwp_file
->sections
.line
.s
.section
= sectp
;
12249 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12251 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12253 dwp_file
->sections
.loc
.s
.section
= sectp
;
12254 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12256 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12258 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12259 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12261 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12263 dwp_file
->sections
.macro
.s
.section
= sectp
;
12264 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12266 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12268 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12269 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12271 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12273 dwp_file
->sections
.types
.s
.section
= sectp
;
12274 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12278 /* Hash function for dwp_file loaded CUs/TUs. */
12281 hash_dwp_loaded_cutus (const void *item
)
12283 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12285 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12286 return dwo_unit
->signature
;
12289 /* Equality function for dwp_file loaded CUs/TUs. */
12292 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12294 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12295 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12297 return dua
->signature
== dub
->signature
;
12300 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12303 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
12305 return htab_up (htab_create_alloc (3,
12306 hash_dwp_loaded_cutus
,
12307 eq_dwp_loaded_cutus
,
12308 NULL
, xcalloc
, xfree
));
12311 /* Try to open DWP file FILE_NAME.
12312 The result is the bfd handle of the file.
12313 If there is a problem finding or opening the file, return NULL.
12314 Upon success, the canonicalized path of the file is stored in the bfd,
12315 same as symfile_bfd_open. */
12317 static gdb_bfd_ref_ptr
12318 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12319 const char *file_name
)
12321 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12323 1 /*search_cwd*/));
12327 /* Work around upstream bug 15652.
12328 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12329 [Whether that's a "bug" is debatable, but it is getting in our way.]
12330 We have no real idea where the dwp file is, because gdb's realpath-ing
12331 of the executable's path may have discarded the needed info.
12332 [IWBN if the dwp file name was recorded in the executable, akin to
12333 .gnu_debuglink, but that doesn't exist yet.]
12334 Strip the directory from FILE_NAME and search again. */
12335 if (*debug_file_directory
!= '\0')
12337 /* Don't implicitly search the current directory here.
12338 If the user wants to search "." to handle this case,
12339 it must be added to debug-file-directory. */
12340 return try_open_dwop_file (dwarf2_per_objfile
,
12341 lbasename (file_name
), 1 /*is_dwp*/,
12348 /* Initialize the use of the DWP file for the current objfile.
12349 By convention the name of the DWP file is ${objfile}.dwp.
12350 The result is NULL if it can't be found. */
12352 static std::unique_ptr
<struct dwp_file
>
12353 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12355 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12357 /* Try to find first .dwp for the binary file before any symbolic links
12360 /* If the objfile is a debug file, find the name of the real binary
12361 file and get the name of dwp file from there. */
12362 std::string dwp_name
;
12363 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12365 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12366 const char *backlink_basename
= lbasename (backlink
->original_name
);
12368 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12371 dwp_name
= objfile
->original_name
;
12373 dwp_name
+= ".dwp";
12375 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12377 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12379 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12380 dwp_name
= objfile_name (objfile
);
12381 dwp_name
+= ".dwp";
12382 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12387 if (dwarf_read_debug
)
12388 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12389 return std::unique_ptr
<dwp_file
> ();
12392 const char *name
= bfd_get_filename (dbfd
.get ());
12393 std::unique_ptr
<struct dwp_file
> dwp_file
12394 (new struct dwp_file (name
, std::move (dbfd
)));
12396 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12397 dwp_file
->elf_sections
=
12398 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12399 dwp_file
->num_sections
, asection
*);
12401 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12402 dwarf2_locate_common_dwp_sections
,
12405 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12408 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12411 /* The DWP file version is stored in the hash table. Oh well. */
12412 if (dwp_file
->cus
&& dwp_file
->tus
12413 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12415 /* Technically speaking, we should try to limp along, but this is
12416 pretty bizarre. We use pulongest here because that's the established
12417 portability solution (e.g, we cannot use %u for uint32_t). */
12418 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12419 " TU version %s [in DWP file %s]"),
12420 pulongest (dwp_file
->cus
->version
),
12421 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12425 dwp_file
->version
= dwp_file
->cus
->version
;
12426 else if (dwp_file
->tus
)
12427 dwp_file
->version
= dwp_file
->tus
->version
;
12429 dwp_file
->version
= 2;
12431 if (dwp_file
->version
== 2)
12432 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12433 dwarf2_locate_v2_dwp_sections
,
12436 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
12437 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
12439 if (dwarf_read_debug
)
12441 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12442 fprintf_unfiltered (gdb_stdlog
,
12443 " %s CUs, %s TUs\n",
12444 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12445 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12451 /* Wrapper around open_and_init_dwp_file, only open it once. */
12453 static struct dwp_file
*
12454 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12456 if (! dwarf2_per_objfile
->dwp_checked
)
12458 dwarf2_per_objfile
->dwp_file
12459 = open_and_init_dwp_file (dwarf2_per_objfile
);
12460 dwarf2_per_objfile
->dwp_checked
= 1;
12462 return dwarf2_per_objfile
->dwp_file
.get ();
12465 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12466 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12467 or in the DWP file for the objfile, referenced by THIS_UNIT.
12468 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12469 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12471 This is called, for example, when wanting to read a variable with a
12472 complex location. Therefore we don't want to do file i/o for every call.
12473 Therefore we don't want to look for a DWO file on every call.
12474 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12475 then we check if we've already seen DWO_NAME, and only THEN do we check
12478 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12479 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12481 static struct dwo_unit
*
12482 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12483 const char *dwo_name
, const char *comp_dir
,
12484 ULONGEST signature
, int is_debug_types
)
12486 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12487 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12488 const char *kind
= is_debug_types
? "TU" : "CU";
12489 void **dwo_file_slot
;
12490 struct dwo_file
*dwo_file
;
12491 struct dwp_file
*dwp_file
;
12493 /* First see if there's a DWP file.
12494 If we have a DWP file but didn't find the DWO inside it, don't
12495 look for the original DWO file. It makes gdb behave differently
12496 depending on whether one is debugging in the build tree. */
12498 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12499 if (dwp_file
!= NULL
)
12501 const struct dwp_hash_table
*dwp_htab
=
12502 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12504 if (dwp_htab
!= NULL
)
12506 struct dwo_unit
*dwo_cutu
=
12507 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12508 signature
, is_debug_types
);
12510 if (dwo_cutu
!= NULL
)
12512 if (dwarf_read_debug
)
12514 fprintf_unfiltered (gdb_stdlog
,
12515 "Virtual DWO %s %s found: @%s\n",
12516 kind
, hex_string (signature
),
12517 host_address_to_string (dwo_cutu
));
12525 /* No DWP file, look for the DWO file. */
12527 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12528 dwo_name
, comp_dir
);
12529 if (*dwo_file_slot
== NULL
)
12531 /* Read in the file and build a table of the CUs/TUs it contains. */
12532 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12534 /* NOTE: This will be NULL if unable to open the file. */
12535 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12537 if (dwo_file
!= NULL
)
12539 struct dwo_unit
*dwo_cutu
= NULL
;
12541 if (is_debug_types
&& dwo_file
->tus
)
12543 struct dwo_unit find_dwo_cutu
;
12545 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12546 find_dwo_cutu
.signature
= signature
;
12548 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12551 else if (!is_debug_types
&& dwo_file
->cus
)
12553 struct dwo_unit find_dwo_cutu
;
12555 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12556 find_dwo_cutu
.signature
= signature
;
12557 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12561 if (dwo_cutu
!= NULL
)
12563 if (dwarf_read_debug
)
12565 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12566 kind
, dwo_name
, hex_string (signature
),
12567 host_address_to_string (dwo_cutu
));
12574 /* We didn't find it. This could mean a dwo_id mismatch, or
12575 someone deleted the DWO/DWP file, or the search path isn't set up
12576 correctly to find the file. */
12578 if (dwarf_read_debug
)
12580 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12581 kind
, dwo_name
, hex_string (signature
));
12584 /* This is a warning and not a complaint because it can be caused by
12585 pilot error (e.g., user accidentally deleting the DWO). */
12587 /* Print the name of the DWP file if we looked there, helps the user
12588 better diagnose the problem. */
12589 std::string dwp_text
;
12591 if (dwp_file
!= NULL
)
12592 dwp_text
= string_printf (" [in DWP file %s]",
12593 lbasename (dwp_file
->name
));
12595 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12596 " [in module %s]"),
12597 kind
, dwo_name
, hex_string (signature
),
12599 this_unit
->is_debug_types
? "TU" : "CU",
12600 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12605 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12606 See lookup_dwo_cutu_unit for details. */
12608 static struct dwo_unit
*
12609 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12610 const char *dwo_name
, const char *comp_dir
,
12611 ULONGEST signature
)
12613 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12616 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12617 See lookup_dwo_cutu_unit for details. */
12619 static struct dwo_unit
*
12620 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12621 const char *dwo_name
, const char *comp_dir
)
12623 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12626 /* Traversal function for queue_and_load_all_dwo_tus. */
12629 queue_and_load_dwo_tu (void **slot
, void *info
)
12631 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12632 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12633 ULONGEST signature
= dwo_unit
->signature
;
12634 struct signatured_type
*sig_type
=
12635 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12637 if (sig_type
!= NULL
)
12639 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12641 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12642 a real dependency of PER_CU on SIG_TYPE. That is detected later
12643 while processing PER_CU. */
12644 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12645 load_full_type_unit (sig_cu
);
12646 per_cu
->imported_symtabs_push (sig_cu
);
12652 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12653 The DWO may have the only definition of the type, though it may not be
12654 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12655 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12658 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12660 struct dwo_unit
*dwo_unit
;
12661 struct dwo_file
*dwo_file
;
12663 gdb_assert (!per_cu
->is_debug_types
);
12664 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12665 gdb_assert (per_cu
->cu
!= NULL
);
12667 dwo_unit
= per_cu
->cu
->dwo_unit
;
12668 gdb_assert (dwo_unit
!= NULL
);
12670 dwo_file
= dwo_unit
->dwo_file
;
12671 if (dwo_file
->tus
!= NULL
)
12672 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12676 /* Read in various DIEs. */
12678 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12679 Inherit only the children of the DW_AT_abstract_origin DIE not being
12680 already referenced by DW_AT_abstract_origin from the children of the
12684 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12686 struct die_info
*child_die
;
12687 sect_offset
*offsetp
;
12688 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12689 struct die_info
*origin_die
;
12690 /* Iterator of the ORIGIN_DIE children. */
12691 struct die_info
*origin_child_die
;
12692 struct attribute
*attr
;
12693 struct dwarf2_cu
*origin_cu
;
12694 struct pending
**origin_previous_list_in_scope
;
12696 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12700 /* Note that following die references may follow to a die in a
12704 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12706 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12708 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12709 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12711 if (die
->tag
!= origin_die
->tag
12712 && !(die
->tag
== DW_TAG_inlined_subroutine
12713 && origin_die
->tag
== DW_TAG_subprogram
))
12714 complaint (_("DIE %s and its abstract origin %s have different tags"),
12715 sect_offset_str (die
->sect_off
),
12716 sect_offset_str (origin_die
->sect_off
));
12718 std::vector
<sect_offset
> offsets
;
12720 for (child_die
= die
->child
;
12721 child_die
&& child_die
->tag
;
12722 child_die
= sibling_die (child_die
))
12724 struct die_info
*child_origin_die
;
12725 struct dwarf2_cu
*child_origin_cu
;
12727 /* We are trying to process concrete instance entries:
12728 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12729 it's not relevant to our analysis here. i.e. detecting DIEs that are
12730 present in the abstract instance but not referenced in the concrete
12732 if (child_die
->tag
== DW_TAG_call_site
12733 || child_die
->tag
== DW_TAG_GNU_call_site
)
12736 /* For each CHILD_DIE, find the corresponding child of
12737 ORIGIN_DIE. If there is more than one layer of
12738 DW_AT_abstract_origin, follow them all; there shouldn't be,
12739 but GCC versions at least through 4.4 generate this (GCC PR
12741 child_origin_die
= child_die
;
12742 child_origin_cu
= cu
;
12745 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12749 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12753 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12754 counterpart may exist. */
12755 if (child_origin_die
!= child_die
)
12757 if (child_die
->tag
!= child_origin_die
->tag
12758 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12759 && child_origin_die
->tag
== DW_TAG_subprogram
))
12760 complaint (_("Child DIE %s and its abstract origin %s have "
12762 sect_offset_str (child_die
->sect_off
),
12763 sect_offset_str (child_origin_die
->sect_off
));
12764 if (child_origin_die
->parent
!= origin_die
)
12765 complaint (_("Child DIE %s and its abstract origin %s have "
12766 "different parents"),
12767 sect_offset_str (child_die
->sect_off
),
12768 sect_offset_str (child_origin_die
->sect_off
));
12770 offsets
.push_back (child_origin_die
->sect_off
);
12773 std::sort (offsets
.begin (), offsets
.end ());
12774 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12775 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12776 if (offsetp
[-1] == *offsetp
)
12777 complaint (_("Multiple children of DIE %s refer "
12778 "to DIE %s as their abstract origin"),
12779 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12781 offsetp
= offsets
.data ();
12782 origin_child_die
= origin_die
->child
;
12783 while (origin_child_die
&& origin_child_die
->tag
)
12785 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12786 while (offsetp
< offsets_end
12787 && *offsetp
< origin_child_die
->sect_off
)
12789 if (offsetp
>= offsets_end
12790 || *offsetp
> origin_child_die
->sect_off
)
12792 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12793 Check whether we're already processing ORIGIN_CHILD_DIE.
12794 This can happen with mutually referenced abstract_origins.
12796 if (!origin_child_die
->in_process
)
12797 process_die (origin_child_die
, origin_cu
);
12799 origin_child_die
= sibling_die (origin_child_die
);
12801 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12803 if (cu
!= origin_cu
)
12804 compute_delayed_physnames (origin_cu
);
12808 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12810 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12811 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12812 struct context_stack
*newobj
;
12815 struct die_info
*child_die
;
12816 struct attribute
*attr
, *call_line
, *call_file
;
12818 CORE_ADDR baseaddr
;
12819 struct block
*block
;
12820 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12821 std::vector
<struct symbol
*> template_args
;
12822 struct template_symbol
*templ_func
= NULL
;
12826 /* If we do not have call site information, we can't show the
12827 caller of this inlined function. That's too confusing, so
12828 only use the scope for local variables. */
12829 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12830 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12831 if (call_line
== NULL
|| call_file
== NULL
)
12833 read_lexical_block_scope (die
, cu
);
12838 baseaddr
= objfile
->text_section_offset ();
12840 name
= dwarf2_name (die
, cu
);
12842 /* Ignore functions with missing or empty names. These are actually
12843 illegal according to the DWARF standard. */
12846 complaint (_("missing name for subprogram DIE at %s"),
12847 sect_offset_str (die
->sect_off
));
12851 /* Ignore functions with missing or invalid low and high pc attributes. */
12852 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12853 <= PC_BOUNDS_INVALID
)
12855 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12856 if (!attr
|| !DW_UNSND (attr
))
12857 complaint (_("cannot get low and high bounds "
12858 "for subprogram DIE at %s"),
12859 sect_offset_str (die
->sect_off
));
12863 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12864 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12866 /* If we have any template arguments, then we must allocate a
12867 different sort of symbol. */
12868 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12870 if (child_die
->tag
== DW_TAG_template_type_param
12871 || child_die
->tag
== DW_TAG_template_value_param
)
12873 templ_func
= allocate_template_symbol (objfile
);
12874 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12879 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12880 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12881 (struct symbol
*) templ_func
);
12883 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12884 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12887 /* If there is a location expression for DW_AT_frame_base, record
12889 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12890 if (attr
!= nullptr)
12891 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12893 /* If there is a location for the static link, record it. */
12894 newobj
->static_link
= NULL
;
12895 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12896 if (attr
!= nullptr)
12898 newobj
->static_link
12899 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12900 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12901 cu
->per_cu
->addr_type ());
12904 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12906 if (die
->child
!= NULL
)
12908 child_die
= die
->child
;
12909 while (child_die
&& child_die
->tag
)
12911 if (child_die
->tag
== DW_TAG_template_type_param
12912 || child_die
->tag
== DW_TAG_template_value_param
)
12914 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12917 template_args
.push_back (arg
);
12920 process_die (child_die
, cu
);
12921 child_die
= sibling_die (child_die
);
12925 inherit_abstract_dies (die
, cu
);
12927 /* If we have a DW_AT_specification, we might need to import using
12928 directives from the context of the specification DIE. See the
12929 comment in determine_prefix. */
12930 if (cu
->language
== language_cplus
12931 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12933 struct dwarf2_cu
*spec_cu
= cu
;
12934 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12938 child_die
= spec_die
->child
;
12939 while (child_die
&& child_die
->tag
)
12941 if (child_die
->tag
== DW_TAG_imported_module
)
12942 process_die (child_die
, spec_cu
);
12943 child_die
= sibling_die (child_die
);
12946 /* In some cases, GCC generates specification DIEs that
12947 themselves contain DW_AT_specification attributes. */
12948 spec_die
= die_specification (spec_die
, &spec_cu
);
12952 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12953 /* Make a block for the local symbols within. */
12954 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12955 cstk
.static_link
, lowpc
, highpc
);
12957 /* For C++, set the block's scope. */
12958 if ((cu
->language
== language_cplus
12959 || cu
->language
== language_fortran
12960 || cu
->language
== language_d
12961 || cu
->language
== language_rust
)
12962 && cu
->processing_has_namespace_info
)
12963 block_set_scope (block
, determine_prefix (die
, cu
),
12964 &objfile
->objfile_obstack
);
12966 /* If we have address ranges, record them. */
12967 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12969 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12971 /* Attach template arguments to function. */
12972 if (!template_args
.empty ())
12974 gdb_assert (templ_func
!= NULL
);
12976 templ_func
->n_template_arguments
= template_args
.size ();
12977 templ_func
->template_arguments
12978 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12979 templ_func
->n_template_arguments
);
12980 memcpy (templ_func
->template_arguments
,
12981 template_args
.data (),
12982 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12984 /* Make sure that the symtab is set on the new symbols. Even
12985 though they don't appear in this symtab directly, other parts
12986 of gdb assume that symbols do, and this is reasonably
12988 for (symbol
*sym
: template_args
)
12989 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12992 /* In C++, we can have functions nested inside functions (e.g., when
12993 a function declares a class that has methods). This means that
12994 when we finish processing a function scope, we may need to go
12995 back to building a containing block's symbol lists. */
12996 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12997 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12999 /* If we've finished processing a top-level function, subsequent
13000 symbols go in the file symbol list. */
13001 if (cu
->get_builder ()->outermost_context_p ())
13002 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13005 /* Process all the DIES contained within a lexical block scope. Start
13006 a new scope, process the dies, and then close the scope. */
13009 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13011 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13012 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13013 CORE_ADDR lowpc
, highpc
;
13014 struct die_info
*child_die
;
13015 CORE_ADDR baseaddr
;
13017 baseaddr
= objfile
->text_section_offset ();
13019 /* Ignore blocks with missing or invalid low and high pc attributes. */
13020 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13021 as multiple lexical blocks? Handling children in a sane way would
13022 be nasty. Might be easier to properly extend generic blocks to
13023 describe ranges. */
13024 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13026 case PC_BOUNDS_NOT_PRESENT
:
13027 /* DW_TAG_lexical_block has no attributes, process its children as if
13028 there was no wrapping by that DW_TAG_lexical_block.
13029 GCC does no longer produces such DWARF since GCC r224161. */
13030 for (child_die
= die
->child
;
13031 child_die
!= NULL
&& child_die
->tag
;
13032 child_die
= sibling_die (child_die
))
13033 process_die (child_die
, cu
);
13035 case PC_BOUNDS_INVALID
:
13038 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13039 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13041 cu
->get_builder ()->push_context (0, lowpc
);
13042 if (die
->child
!= NULL
)
13044 child_die
= die
->child
;
13045 while (child_die
&& child_die
->tag
)
13047 process_die (child_die
, cu
);
13048 child_die
= sibling_die (child_die
);
13051 inherit_abstract_dies (die
, cu
);
13052 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13054 if (*cu
->get_builder ()->get_local_symbols () != NULL
13055 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13057 struct block
*block
13058 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13059 cstk
.start_addr
, highpc
);
13061 /* Note that recording ranges after traversing children, as we
13062 do here, means that recording a parent's ranges entails
13063 walking across all its children's ranges as they appear in
13064 the address map, which is quadratic behavior.
13066 It would be nicer to record the parent's ranges before
13067 traversing its children, simply overriding whatever you find
13068 there. But since we don't even decide whether to create a
13069 block until after we've traversed its children, that's hard
13071 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13073 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13074 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13077 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13080 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13082 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13083 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13084 CORE_ADDR pc
, baseaddr
;
13085 struct attribute
*attr
;
13086 struct call_site
*call_site
, call_site_local
;
13089 struct die_info
*child_die
;
13091 baseaddr
= objfile
->text_section_offset ();
13093 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13096 /* This was a pre-DWARF-5 GNU extension alias
13097 for DW_AT_call_return_pc. */
13098 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13102 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13103 "DIE %s [in module %s]"),
13104 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13107 pc
= attr
->value_as_address () + baseaddr
;
13108 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13110 if (cu
->call_site_htab
== NULL
)
13111 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13112 NULL
, &objfile
->objfile_obstack
,
13113 hashtab_obstack_allocate
, NULL
);
13114 call_site_local
.pc
= pc
;
13115 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13118 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13119 "DIE %s [in module %s]"),
13120 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13121 objfile_name (objfile
));
13125 /* Count parameters at the caller. */
13128 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13129 child_die
= sibling_die (child_die
))
13131 if (child_die
->tag
!= DW_TAG_call_site_parameter
13132 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13134 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13135 "DW_TAG_call_site child DIE %s [in module %s]"),
13136 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13137 objfile_name (objfile
));
13145 = ((struct call_site
*)
13146 obstack_alloc (&objfile
->objfile_obstack
,
13147 sizeof (*call_site
)
13148 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13150 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13151 call_site
->pc
= pc
;
13153 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13154 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13156 struct die_info
*func_die
;
13158 /* Skip also over DW_TAG_inlined_subroutine. */
13159 for (func_die
= die
->parent
;
13160 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13161 && func_die
->tag
!= DW_TAG_subroutine_type
;
13162 func_die
= func_die
->parent
);
13164 /* DW_AT_call_all_calls is a superset
13165 of DW_AT_call_all_tail_calls. */
13167 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13168 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13169 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13170 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13172 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13173 not complete. But keep CALL_SITE for look ups via call_site_htab,
13174 both the initial caller containing the real return address PC and
13175 the final callee containing the current PC of a chain of tail
13176 calls do not need to have the tail call list complete. But any
13177 function candidate for a virtual tail call frame searched via
13178 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13179 determined unambiguously. */
13183 struct type
*func_type
= NULL
;
13186 func_type
= get_die_type (func_die
, cu
);
13187 if (func_type
!= NULL
)
13189 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13191 /* Enlist this call site to the function. */
13192 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13193 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13196 complaint (_("Cannot find function owning DW_TAG_call_site "
13197 "DIE %s [in module %s]"),
13198 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13202 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13204 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13206 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13209 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13210 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13212 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13213 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13214 /* Keep NULL DWARF_BLOCK. */;
13215 else if (attr
->form_is_block ())
13217 struct dwarf2_locexpr_baton
*dlbaton
;
13219 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13220 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13221 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13222 dlbaton
->per_cu
= cu
->per_cu
;
13224 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13226 else if (attr
->form_is_ref ())
13228 struct dwarf2_cu
*target_cu
= cu
;
13229 struct die_info
*target_die
;
13231 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13232 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13233 if (die_is_declaration (target_die
, target_cu
))
13235 const char *target_physname
;
13237 /* Prefer the mangled name; otherwise compute the demangled one. */
13238 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13239 if (target_physname
== NULL
)
13240 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13241 if (target_physname
== NULL
)
13242 complaint (_("DW_AT_call_target target DIE has invalid "
13243 "physname, for referencing DIE %s [in module %s]"),
13244 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13246 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13252 /* DW_AT_entry_pc should be preferred. */
13253 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13254 <= PC_BOUNDS_INVALID
)
13255 complaint (_("DW_AT_call_target target DIE has invalid "
13256 "low pc, for referencing DIE %s [in module %s]"),
13257 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13260 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13261 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13266 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13267 "block nor reference, for DIE %s [in module %s]"),
13268 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13270 call_site
->per_cu
= cu
->per_cu
;
13272 for (child_die
= die
->child
;
13273 child_die
&& child_die
->tag
;
13274 child_die
= sibling_die (child_die
))
13276 struct call_site_parameter
*parameter
;
13277 struct attribute
*loc
, *origin
;
13279 if (child_die
->tag
!= DW_TAG_call_site_parameter
13280 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13282 /* Already printed the complaint above. */
13286 gdb_assert (call_site
->parameter_count
< nparams
);
13287 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13289 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13290 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13291 register is contained in DW_AT_call_value. */
13293 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13294 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13295 if (origin
== NULL
)
13297 /* This was a pre-DWARF-5 GNU extension alias
13298 for DW_AT_call_parameter. */
13299 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13301 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13303 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13305 sect_offset sect_off
13306 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13307 if (!cu
->header
.offset_in_cu_p (sect_off
))
13309 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13310 binding can be done only inside one CU. Such referenced DIE
13311 therefore cannot be even moved to DW_TAG_partial_unit. */
13312 complaint (_("DW_AT_call_parameter offset is not in CU for "
13313 "DW_TAG_call_site child DIE %s [in module %s]"),
13314 sect_offset_str (child_die
->sect_off
),
13315 objfile_name (objfile
));
13318 parameter
->u
.param_cu_off
13319 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13321 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13323 complaint (_("No DW_FORM_block* DW_AT_location for "
13324 "DW_TAG_call_site child DIE %s [in module %s]"),
13325 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13330 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13331 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13332 if (parameter
->u
.dwarf_reg
!= -1)
13333 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13334 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13335 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13336 ¶meter
->u
.fb_offset
))
13337 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13340 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13341 "for DW_FORM_block* DW_AT_location is supported for "
13342 "DW_TAG_call_site child DIE %s "
13344 sect_offset_str (child_die
->sect_off
),
13345 objfile_name (objfile
));
13350 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13352 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13353 if (attr
== NULL
|| !attr
->form_is_block ())
13355 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13356 "DW_TAG_call_site child DIE %s [in module %s]"),
13357 sect_offset_str (child_die
->sect_off
),
13358 objfile_name (objfile
));
13361 parameter
->value
= DW_BLOCK (attr
)->data
;
13362 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13364 /* Parameters are not pre-cleared by memset above. */
13365 parameter
->data_value
= NULL
;
13366 parameter
->data_value_size
= 0;
13367 call_site
->parameter_count
++;
13369 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13371 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13372 if (attr
!= nullptr)
13374 if (!attr
->form_is_block ())
13375 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13376 "DW_TAG_call_site child DIE %s [in module %s]"),
13377 sect_offset_str (child_die
->sect_off
),
13378 objfile_name (objfile
));
13381 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13382 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13388 /* Helper function for read_variable. If DIE represents a virtual
13389 table, then return the type of the concrete object that is
13390 associated with the virtual table. Otherwise, return NULL. */
13392 static struct type
*
13393 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13395 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13399 /* Find the type DIE. */
13400 struct die_info
*type_die
= NULL
;
13401 struct dwarf2_cu
*type_cu
= cu
;
13403 if (attr
->form_is_ref ())
13404 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13405 if (type_die
== NULL
)
13408 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13410 return die_containing_type (type_die
, type_cu
);
13413 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13416 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13418 struct rust_vtable_symbol
*storage
= NULL
;
13420 if (cu
->language
== language_rust
)
13422 struct type
*containing_type
= rust_containing_type (die
, cu
);
13424 if (containing_type
!= NULL
)
13426 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13428 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13429 initialize_objfile_symbol (storage
);
13430 storage
->concrete_type
= containing_type
;
13431 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13435 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13436 struct attribute
*abstract_origin
13437 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13438 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13439 if (res
== NULL
&& loc
&& abstract_origin
)
13441 /* We have a variable without a name, but with a location and an abstract
13442 origin. This may be a concrete instance of an abstract variable
13443 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13445 struct dwarf2_cu
*origin_cu
= cu
;
13446 struct die_info
*origin_die
13447 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13448 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13449 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13453 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13454 reading .debug_rnglists.
13455 Callback's type should be:
13456 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13457 Return true if the attributes are present and valid, otherwise,
13460 template <typename Callback
>
13462 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13463 Callback
&&callback
)
13465 struct dwarf2_per_objfile
*dwarf2_per_objfile
13466 = cu
->per_cu
->dwarf2_per_objfile
;
13467 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13468 bfd
*obfd
= objfile
->obfd
;
13469 /* Base address selection entry. */
13472 const gdb_byte
*buffer
;
13473 CORE_ADDR baseaddr
;
13474 bool overflow
= false;
13476 found_base
= cu
->base_known
;
13477 base
= cu
->base_address
;
13479 dwarf2_per_objfile
->rnglists
.read (objfile
);
13480 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13482 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13486 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13488 baseaddr
= objfile
->text_section_offset ();
13492 /* Initialize it due to a false compiler warning. */
13493 CORE_ADDR range_beginning
= 0, range_end
= 0;
13494 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13495 + dwarf2_per_objfile
->rnglists
.size
);
13496 unsigned int bytes_read
;
13498 if (buffer
== buf_end
)
13503 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13506 case DW_RLE_end_of_list
:
13508 case DW_RLE_base_address
:
13509 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13514 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13516 buffer
+= bytes_read
;
13518 case DW_RLE_start_length
:
13519 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13524 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13526 buffer
+= bytes_read
;
13527 range_end
= (range_beginning
13528 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13529 buffer
+= bytes_read
;
13530 if (buffer
> buf_end
)
13536 case DW_RLE_offset_pair
:
13537 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13538 buffer
+= bytes_read
;
13539 if (buffer
> buf_end
)
13544 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13545 buffer
+= bytes_read
;
13546 if (buffer
> buf_end
)
13552 case DW_RLE_start_end
:
13553 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13558 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13560 buffer
+= bytes_read
;
13561 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13562 buffer
+= bytes_read
;
13565 complaint (_("Invalid .debug_rnglists data (no base address)"));
13568 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13570 if (rlet
== DW_RLE_base_address
)
13575 /* We have no valid base address for the ranges
13577 complaint (_("Invalid .debug_rnglists data (no base address)"));
13581 if (range_beginning
> range_end
)
13583 /* Inverted range entries are invalid. */
13584 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13588 /* Empty range entries have no effect. */
13589 if (range_beginning
== range_end
)
13592 range_beginning
+= base
;
13595 /* A not-uncommon case of bad debug info.
13596 Don't pollute the addrmap with bad data. */
13597 if (range_beginning
+ baseaddr
== 0
13598 && !dwarf2_per_objfile
->has_section_at_zero
)
13600 complaint (_(".debug_rnglists entry has start address of zero"
13601 " [in module %s]"), objfile_name (objfile
));
13605 callback (range_beginning
, range_end
);
13610 complaint (_("Offset %d is not terminated "
13611 "for DW_AT_ranges attribute"),
13619 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13620 Callback's type should be:
13621 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13622 Return 1 if the attributes are present and valid, otherwise, return 0. */
13624 template <typename Callback
>
13626 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13627 Callback
&&callback
)
13629 struct dwarf2_per_objfile
*dwarf2_per_objfile
13630 = cu
->per_cu
->dwarf2_per_objfile
;
13631 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13632 struct comp_unit_head
*cu_header
= &cu
->header
;
13633 bfd
*obfd
= objfile
->obfd
;
13634 unsigned int addr_size
= cu_header
->addr_size
;
13635 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13636 /* Base address selection entry. */
13639 unsigned int dummy
;
13640 const gdb_byte
*buffer
;
13641 CORE_ADDR baseaddr
;
13643 if (cu_header
->version
>= 5)
13644 return dwarf2_rnglists_process (offset
, cu
, callback
);
13646 found_base
= cu
->base_known
;
13647 base
= cu
->base_address
;
13649 dwarf2_per_objfile
->ranges
.read (objfile
);
13650 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13652 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13656 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13658 baseaddr
= objfile
->text_section_offset ();
13662 CORE_ADDR range_beginning
, range_end
;
13664 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13665 buffer
+= addr_size
;
13666 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13667 buffer
+= addr_size
;
13668 offset
+= 2 * addr_size
;
13670 /* An end of list marker is a pair of zero addresses. */
13671 if (range_beginning
== 0 && range_end
== 0)
13672 /* Found the end of list entry. */
13675 /* Each base address selection entry is a pair of 2 values.
13676 The first is the largest possible address, the second is
13677 the base address. Check for a base address here. */
13678 if ((range_beginning
& mask
) == mask
)
13680 /* If we found the largest possible address, then we already
13681 have the base address in range_end. */
13689 /* We have no valid base address for the ranges
13691 complaint (_("Invalid .debug_ranges data (no base address)"));
13695 if (range_beginning
> range_end
)
13697 /* Inverted range entries are invalid. */
13698 complaint (_("Invalid .debug_ranges data (inverted range)"));
13702 /* Empty range entries have no effect. */
13703 if (range_beginning
== range_end
)
13706 range_beginning
+= base
;
13709 /* A not-uncommon case of bad debug info.
13710 Don't pollute the addrmap with bad data. */
13711 if (range_beginning
+ baseaddr
== 0
13712 && !dwarf2_per_objfile
->has_section_at_zero
)
13714 complaint (_(".debug_ranges entry has start address of zero"
13715 " [in module %s]"), objfile_name (objfile
));
13719 callback (range_beginning
, range_end
);
13725 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13726 Return 1 if the attributes are present and valid, otherwise, return 0.
13727 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13730 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13731 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13732 dwarf2_psymtab
*ranges_pst
)
13734 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13735 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13736 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13739 CORE_ADDR high
= 0;
13742 retval
= dwarf2_ranges_process (offset
, cu
,
13743 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13745 if (ranges_pst
!= NULL
)
13750 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13751 range_beginning
+ baseaddr
)
13753 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13754 range_end
+ baseaddr
)
13756 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13757 lowpc
, highpc
- 1, ranges_pst
);
13760 /* FIXME: This is recording everything as a low-high
13761 segment of consecutive addresses. We should have a
13762 data structure for discontiguous block ranges
13766 low
= range_beginning
;
13772 if (range_beginning
< low
)
13773 low
= range_beginning
;
13774 if (range_end
> high
)
13782 /* If the first entry is an end-of-list marker, the range
13783 describes an empty scope, i.e. no instructions. */
13789 *high_return
= high
;
13793 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13794 definition for the return value. *LOWPC and *HIGHPC are set iff
13795 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13797 static enum pc_bounds_kind
13798 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13799 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13800 dwarf2_psymtab
*pst
)
13802 struct dwarf2_per_objfile
*dwarf2_per_objfile
13803 = cu
->per_cu
->dwarf2_per_objfile
;
13804 struct attribute
*attr
;
13805 struct attribute
*attr_high
;
13807 CORE_ADDR high
= 0;
13808 enum pc_bounds_kind ret
;
13810 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13813 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13814 if (attr
!= nullptr)
13816 low
= attr
->value_as_address ();
13817 high
= attr_high
->value_as_address ();
13818 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13822 /* Found high w/o low attribute. */
13823 return PC_BOUNDS_INVALID
;
13825 /* Found consecutive range of addresses. */
13826 ret
= PC_BOUNDS_HIGH_LOW
;
13830 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13833 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13834 We take advantage of the fact that DW_AT_ranges does not appear
13835 in DW_TAG_compile_unit of DWO files. */
13836 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13837 unsigned int ranges_offset
= (DW_UNSND (attr
)
13838 + (need_ranges_base
13842 /* Value of the DW_AT_ranges attribute is the offset in the
13843 .debug_ranges section. */
13844 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13845 return PC_BOUNDS_INVALID
;
13846 /* Found discontinuous range of addresses. */
13847 ret
= PC_BOUNDS_RANGES
;
13850 return PC_BOUNDS_NOT_PRESENT
;
13853 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13855 return PC_BOUNDS_INVALID
;
13857 /* When using the GNU linker, .gnu.linkonce. sections are used to
13858 eliminate duplicate copies of functions and vtables and such.
13859 The linker will arbitrarily choose one and discard the others.
13860 The AT_*_pc values for such functions refer to local labels in
13861 these sections. If the section from that file was discarded, the
13862 labels are not in the output, so the relocs get a value of 0.
13863 If this is a discarded function, mark the pc bounds as invalid,
13864 so that GDB will ignore it. */
13865 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13866 return PC_BOUNDS_INVALID
;
13874 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13875 its low and high PC addresses. Do nothing if these addresses could not
13876 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13877 and HIGHPC to the high address if greater than HIGHPC. */
13880 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13881 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13882 struct dwarf2_cu
*cu
)
13884 CORE_ADDR low
, high
;
13885 struct die_info
*child
= die
->child
;
13887 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13889 *lowpc
= std::min (*lowpc
, low
);
13890 *highpc
= std::max (*highpc
, high
);
13893 /* If the language does not allow nested subprograms (either inside
13894 subprograms or lexical blocks), we're done. */
13895 if (cu
->language
!= language_ada
)
13898 /* Check all the children of the given DIE. If it contains nested
13899 subprograms, then check their pc bounds. Likewise, we need to
13900 check lexical blocks as well, as they may also contain subprogram
13902 while (child
&& child
->tag
)
13904 if (child
->tag
== DW_TAG_subprogram
13905 || child
->tag
== DW_TAG_lexical_block
)
13906 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13907 child
= sibling_die (child
);
13911 /* Get the low and high pc's represented by the scope DIE, and store
13912 them in *LOWPC and *HIGHPC. If the correct values can't be
13913 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13916 get_scope_pc_bounds (struct die_info
*die
,
13917 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13918 struct dwarf2_cu
*cu
)
13920 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13921 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13922 CORE_ADDR current_low
, current_high
;
13924 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13925 >= PC_BOUNDS_RANGES
)
13927 best_low
= current_low
;
13928 best_high
= current_high
;
13932 struct die_info
*child
= die
->child
;
13934 while (child
&& child
->tag
)
13936 switch (child
->tag
) {
13937 case DW_TAG_subprogram
:
13938 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13940 case DW_TAG_namespace
:
13941 case DW_TAG_module
:
13942 /* FIXME: carlton/2004-01-16: Should we do this for
13943 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13944 that current GCC's always emit the DIEs corresponding
13945 to definitions of methods of classes as children of a
13946 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13947 the DIEs giving the declarations, which could be
13948 anywhere). But I don't see any reason why the
13949 standards says that they have to be there. */
13950 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13952 if (current_low
!= ((CORE_ADDR
) -1))
13954 best_low
= std::min (best_low
, current_low
);
13955 best_high
= std::max (best_high
, current_high
);
13963 child
= sibling_die (child
);
13968 *highpc
= best_high
;
13971 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13975 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13976 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13978 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13979 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13980 struct attribute
*attr
;
13981 struct attribute
*attr_high
;
13983 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13986 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13987 if (attr
!= nullptr)
13989 CORE_ADDR low
= attr
->value_as_address ();
13990 CORE_ADDR high
= attr_high
->value_as_address ();
13992 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13995 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13996 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13997 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14001 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14002 if (attr
!= nullptr)
14004 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14005 We take advantage of the fact that DW_AT_ranges does not appear
14006 in DW_TAG_compile_unit of DWO files. */
14007 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14009 /* The value of the DW_AT_ranges attribute is the offset of the
14010 address range list in the .debug_ranges section. */
14011 unsigned long offset
= (DW_UNSND (attr
)
14012 + (need_ranges_base
? cu
->ranges_base
: 0));
14014 std::vector
<blockrange
> blockvec
;
14015 dwarf2_ranges_process (offset
, cu
,
14016 [&] (CORE_ADDR start
, CORE_ADDR end
)
14020 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14021 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14022 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14023 blockvec
.emplace_back (start
, end
);
14026 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14030 /* Check whether the producer field indicates either of GCC < 4.6, or the
14031 Intel C/C++ compiler, and cache the result in CU. */
14034 check_producer (struct dwarf2_cu
*cu
)
14038 if (cu
->producer
== NULL
)
14040 /* For unknown compilers expect their behavior is DWARF version
14043 GCC started to support .debug_types sections by -gdwarf-4 since
14044 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14045 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14046 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14047 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14049 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14051 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14052 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14054 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14056 cu
->producer_is_icc
= true;
14057 cu
->producer_is_icc_lt_14
= major
< 14;
14059 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14060 cu
->producer_is_codewarrior
= true;
14063 /* For other non-GCC compilers, expect their behavior is DWARF version
14067 cu
->checked_producer
= true;
14070 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14071 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14072 during 4.6.0 experimental. */
14075 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14077 if (!cu
->checked_producer
)
14078 check_producer (cu
);
14080 return cu
->producer_is_gxx_lt_4_6
;
14084 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14085 with incorrect is_stmt attributes. */
14088 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14090 if (!cu
->checked_producer
)
14091 check_producer (cu
);
14093 return cu
->producer_is_codewarrior
;
14096 /* Return the default accessibility type if it is not overridden by
14097 DW_AT_accessibility. */
14099 static enum dwarf_access_attribute
14100 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14102 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14104 /* The default DWARF 2 accessibility for members is public, the default
14105 accessibility for inheritance is private. */
14107 if (die
->tag
!= DW_TAG_inheritance
)
14108 return DW_ACCESS_public
;
14110 return DW_ACCESS_private
;
14114 /* DWARF 3+ defines the default accessibility a different way. The same
14115 rules apply now for DW_TAG_inheritance as for the members and it only
14116 depends on the container kind. */
14118 if (die
->parent
->tag
== DW_TAG_class_type
)
14119 return DW_ACCESS_private
;
14121 return DW_ACCESS_public
;
14125 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14126 offset. If the attribute was not found return 0, otherwise return
14127 1. If it was found but could not properly be handled, set *OFFSET
14131 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14134 struct attribute
*attr
;
14136 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14141 /* Note that we do not check for a section offset first here.
14142 This is because DW_AT_data_member_location is new in DWARF 4,
14143 so if we see it, we can assume that a constant form is really
14144 a constant and not a section offset. */
14145 if (attr
->form_is_constant ())
14146 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14147 else if (attr
->form_is_section_offset ())
14148 dwarf2_complex_location_expr_complaint ();
14149 else if (attr
->form_is_block ())
14150 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14152 dwarf2_complex_location_expr_complaint ();
14160 /* Add an aggregate field to the field list. */
14163 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14164 struct dwarf2_cu
*cu
)
14166 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14167 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14168 struct nextfield
*new_field
;
14169 struct attribute
*attr
;
14171 const char *fieldname
= "";
14173 if (die
->tag
== DW_TAG_inheritance
)
14175 fip
->baseclasses
.emplace_back ();
14176 new_field
= &fip
->baseclasses
.back ();
14180 fip
->fields
.emplace_back ();
14181 new_field
= &fip
->fields
.back ();
14186 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14187 if (attr
!= nullptr)
14188 new_field
->accessibility
= DW_UNSND (attr
);
14190 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14191 if (new_field
->accessibility
!= DW_ACCESS_public
)
14192 fip
->non_public_fields
= 1;
14194 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14195 if (attr
!= nullptr)
14196 new_field
->virtuality
= DW_UNSND (attr
);
14198 new_field
->virtuality
= DW_VIRTUALITY_none
;
14200 fp
= &new_field
->field
;
14202 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14206 /* Data member other than a C++ static data member. */
14208 /* Get type of field. */
14209 fp
->type
= die_type (die
, cu
);
14211 SET_FIELD_BITPOS (*fp
, 0);
14213 /* Get bit size of field (zero if none). */
14214 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14215 if (attr
!= nullptr)
14217 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14221 FIELD_BITSIZE (*fp
) = 0;
14224 /* Get bit offset of field. */
14225 if (handle_data_member_location (die
, cu
, &offset
))
14226 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14227 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14228 if (attr
!= nullptr)
14230 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14232 /* For big endian bits, the DW_AT_bit_offset gives the
14233 additional bit offset from the MSB of the containing
14234 anonymous object to the MSB of the field. We don't
14235 have to do anything special since we don't need to
14236 know the size of the anonymous object. */
14237 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14241 /* For little endian bits, compute the bit offset to the
14242 MSB of the anonymous object, subtract off the number of
14243 bits from the MSB of the field to the MSB of the
14244 object, and then subtract off the number of bits of
14245 the field itself. The result is the bit offset of
14246 the LSB of the field. */
14247 int anonymous_size
;
14248 int bit_offset
= DW_UNSND (attr
);
14250 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14251 if (attr
!= nullptr)
14253 /* The size of the anonymous object containing
14254 the bit field is explicit, so use the
14255 indicated size (in bytes). */
14256 anonymous_size
= DW_UNSND (attr
);
14260 /* The size of the anonymous object containing
14261 the bit field must be inferred from the type
14262 attribute of the data member containing the
14264 anonymous_size
= TYPE_LENGTH (fp
->type
);
14266 SET_FIELD_BITPOS (*fp
,
14267 (FIELD_BITPOS (*fp
)
14268 + anonymous_size
* bits_per_byte
14269 - bit_offset
- FIELD_BITSIZE (*fp
)));
14272 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14274 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14275 + dwarf2_get_attr_constant_value (attr
, 0)));
14277 /* Get name of field. */
14278 fieldname
= dwarf2_name (die
, cu
);
14279 if (fieldname
== NULL
)
14282 /* The name is already allocated along with this objfile, so we don't
14283 need to duplicate it for the type. */
14284 fp
->name
= fieldname
;
14286 /* Change accessibility for artificial fields (e.g. virtual table
14287 pointer or virtual base class pointer) to private. */
14288 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14290 FIELD_ARTIFICIAL (*fp
) = 1;
14291 new_field
->accessibility
= DW_ACCESS_private
;
14292 fip
->non_public_fields
= 1;
14295 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14297 /* C++ static member. */
14299 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14300 is a declaration, but all versions of G++ as of this writing
14301 (so through at least 3.2.1) incorrectly generate
14302 DW_TAG_variable tags. */
14304 const char *physname
;
14306 /* Get name of field. */
14307 fieldname
= dwarf2_name (die
, cu
);
14308 if (fieldname
== NULL
)
14311 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14313 /* Only create a symbol if this is an external value.
14314 new_symbol checks this and puts the value in the global symbol
14315 table, which we want. If it is not external, new_symbol
14316 will try to put the value in cu->list_in_scope which is wrong. */
14317 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14319 /* A static const member, not much different than an enum as far as
14320 we're concerned, except that we can support more types. */
14321 new_symbol (die
, NULL
, cu
);
14324 /* Get physical name. */
14325 physname
= dwarf2_physname (fieldname
, die
, cu
);
14327 /* The name is already allocated along with this objfile, so we don't
14328 need to duplicate it for the type. */
14329 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14330 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14331 FIELD_NAME (*fp
) = fieldname
;
14333 else if (die
->tag
== DW_TAG_inheritance
)
14337 /* C++ base class field. */
14338 if (handle_data_member_location (die
, cu
, &offset
))
14339 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14340 FIELD_BITSIZE (*fp
) = 0;
14341 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14342 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14344 else if (die
->tag
== DW_TAG_variant_part
)
14346 /* process_structure_scope will treat this DIE as a union. */
14347 process_structure_scope (die
, cu
);
14349 /* The variant part is relative to the start of the enclosing
14351 SET_FIELD_BITPOS (*fp
, 0);
14352 fp
->type
= get_die_type (die
, cu
);
14353 fp
->artificial
= 1;
14354 fp
->name
= "<<variant>>";
14356 /* Normally a DW_TAG_variant_part won't have a size, but our
14357 representation requires one, so set it to the maximum of the
14358 child sizes, being sure to account for the offset at which
14359 each child is seen. */
14360 if (TYPE_LENGTH (fp
->type
) == 0)
14363 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14365 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14366 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14370 TYPE_LENGTH (fp
->type
) = max
;
14374 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14377 /* Can the type given by DIE define another type? */
14380 type_can_define_types (const struct die_info
*die
)
14384 case DW_TAG_typedef
:
14385 case DW_TAG_class_type
:
14386 case DW_TAG_structure_type
:
14387 case DW_TAG_union_type
:
14388 case DW_TAG_enumeration_type
:
14396 /* Add a type definition defined in the scope of the FIP's class. */
14399 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14400 struct dwarf2_cu
*cu
)
14402 struct decl_field fp
;
14403 memset (&fp
, 0, sizeof (fp
));
14405 gdb_assert (type_can_define_types (die
));
14407 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14408 fp
.name
= dwarf2_name (die
, cu
);
14409 fp
.type
= read_type_die (die
, cu
);
14411 /* Save accessibility. */
14412 enum dwarf_access_attribute accessibility
;
14413 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14415 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14417 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14418 switch (accessibility
)
14420 case DW_ACCESS_public
:
14421 /* The assumed value if neither private nor protected. */
14423 case DW_ACCESS_private
:
14426 case DW_ACCESS_protected
:
14427 fp
.is_protected
= 1;
14430 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14433 if (die
->tag
== DW_TAG_typedef
)
14434 fip
->typedef_field_list
.push_back (fp
);
14436 fip
->nested_types_list
.push_back (fp
);
14439 /* Create the vector of fields, and attach it to the type. */
14442 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14443 struct dwarf2_cu
*cu
)
14445 int nfields
= fip
->nfields
;
14447 /* Record the field count, allocate space for the array of fields,
14448 and create blank accessibility bitfields if necessary. */
14449 TYPE_NFIELDS (type
) = nfields
;
14450 TYPE_FIELDS (type
) = (struct field
*)
14451 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14453 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14455 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14457 TYPE_FIELD_PRIVATE_BITS (type
) =
14458 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14459 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14461 TYPE_FIELD_PROTECTED_BITS (type
) =
14462 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14463 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14465 TYPE_FIELD_IGNORE_BITS (type
) =
14466 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14467 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14470 /* If the type has baseclasses, allocate and clear a bit vector for
14471 TYPE_FIELD_VIRTUAL_BITS. */
14472 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14474 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14475 unsigned char *pointer
;
14477 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14478 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14479 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14480 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14481 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14484 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14486 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14488 for (int index
= 0; index
< nfields
; ++index
)
14490 struct nextfield
&field
= fip
->fields
[index
];
14492 if (field
.variant
.is_discriminant
)
14493 di
->discriminant_index
= index
;
14494 else if (field
.variant
.default_branch
)
14495 di
->default_index
= index
;
14497 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14501 /* Copy the saved-up fields into the field vector. */
14502 for (int i
= 0; i
< nfields
; ++i
)
14504 struct nextfield
&field
14505 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14506 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14508 TYPE_FIELD (type
, i
) = field
.field
;
14509 switch (field
.accessibility
)
14511 case DW_ACCESS_private
:
14512 if (cu
->language
!= language_ada
)
14513 SET_TYPE_FIELD_PRIVATE (type
, i
);
14516 case DW_ACCESS_protected
:
14517 if (cu
->language
!= language_ada
)
14518 SET_TYPE_FIELD_PROTECTED (type
, i
);
14521 case DW_ACCESS_public
:
14525 /* Unknown accessibility. Complain and treat it as public. */
14527 complaint (_("unsupported accessibility %d"),
14528 field
.accessibility
);
14532 if (i
< fip
->baseclasses
.size ())
14534 switch (field
.virtuality
)
14536 case DW_VIRTUALITY_virtual
:
14537 case DW_VIRTUALITY_pure_virtual
:
14538 if (cu
->language
== language_ada
)
14539 error (_("unexpected virtuality in component of Ada type"));
14540 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14547 /* Return true if this member function is a constructor, false
14551 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14553 const char *fieldname
;
14554 const char *type_name
;
14557 if (die
->parent
== NULL
)
14560 if (die
->parent
->tag
!= DW_TAG_structure_type
14561 && die
->parent
->tag
!= DW_TAG_union_type
14562 && die
->parent
->tag
!= DW_TAG_class_type
)
14565 fieldname
= dwarf2_name (die
, cu
);
14566 type_name
= dwarf2_name (die
->parent
, cu
);
14567 if (fieldname
== NULL
|| type_name
== NULL
)
14570 len
= strlen (fieldname
);
14571 return (strncmp (fieldname
, type_name
, len
) == 0
14572 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14575 /* Check if the given VALUE is a recognized enum
14576 dwarf_defaulted_attribute constant according to DWARF5 spec,
14580 is_valid_DW_AT_defaulted (ULONGEST value
)
14584 case DW_DEFAULTED_no
:
14585 case DW_DEFAULTED_in_class
:
14586 case DW_DEFAULTED_out_of_class
:
14590 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14594 /* Add a member function to the proper fieldlist. */
14597 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14598 struct type
*type
, struct dwarf2_cu
*cu
)
14600 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14601 struct attribute
*attr
;
14603 struct fnfieldlist
*flp
= nullptr;
14604 struct fn_field
*fnp
;
14605 const char *fieldname
;
14606 struct type
*this_type
;
14607 enum dwarf_access_attribute accessibility
;
14609 if (cu
->language
== language_ada
)
14610 error (_("unexpected member function in Ada type"));
14612 /* Get name of member function. */
14613 fieldname
= dwarf2_name (die
, cu
);
14614 if (fieldname
== NULL
)
14617 /* Look up member function name in fieldlist. */
14618 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14620 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14622 flp
= &fip
->fnfieldlists
[i
];
14627 /* Create a new fnfieldlist if necessary. */
14628 if (flp
== nullptr)
14630 fip
->fnfieldlists
.emplace_back ();
14631 flp
= &fip
->fnfieldlists
.back ();
14632 flp
->name
= fieldname
;
14633 i
= fip
->fnfieldlists
.size () - 1;
14636 /* Create a new member function field and add it to the vector of
14638 flp
->fnfields
.emplace_back ();
14639 fnp
= &flp
->fnfields
.back ();
14641 /* Delay processing of the physname until later. */
14642 if (cu
->language
== language_cplus
)
14643 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14647 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14648 fnp
->physname
= physname
? physname
: "";
14651 fnp
->type
= alloc_type (objfile
);
14652 this_type
= read_type_die (die
, cu
);
14653 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14655 int nparams
= TYPE_NFIELDS (this_type
);
14657 /* TYPE is the domain of this method, and THIS_TYPE is the type
14658 of the method itself (TYPE_CODE_METHOD). */
14659 smash_to_method_type (fnp
->type
, type
,
14660 TYPE_TARGET_TYPE (this_type
),
14661 TYPE_FIELDS (this_type
),
14662 TYPE_NFIELDS (this_type
),
14663 TYPE_VARARGS (this_type
));
14665 /* Handle static member functions.
14666 Dwarf2 has no clean way to discern C++ static and non-static
14667 member functions. G++ helps GDB by marking the first
14668 parameter for non-static member functions (which is the this
14669 pointer) as artificial. We obtain this information from
14670 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14671 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14672 fnp
->voffset
= VOFFSET_STATIC
;
14675 complaint (_("member function type missing for '%s'"),
14676 dwarf2_full_name (fieldname
, die
, cu
));
14678 /* Get fcontext from DW_AT_containing_type if present. */
14679 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14680 fnp
->fcontext
= die_containing_type (die
, cu
);
14682 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14683 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14685 /* Get accessibility. */
14686 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14687 if (attr
!= nullptr)
14688 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14690 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14691 switch (accessibility
)
14693 case DW_ACCESS_private
:
14694 fnp
->is_private
= 1;
14696 case DW_ACCESS_protected
:
14697 fnp
->is_protected
= 1;
14701 /* Check for artificial methods. */
14702 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14703 if (attr
&& DW_UNSND (attr
) != 0)
14704 fnp
->is_artificial
= 1;
14706 /* Check for defaulted methods. */
14707 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14708 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14709 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14711 /* Check for deleted methods. */
14712 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14713 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14714 fnp
->is_deleted
= 1;
14716 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14718 /* Get index in virtual function table if it is a virtual member
14719 function. For older versions of GCC, this is an offset in the
14720 appropriate virtual table, as specified by DW_AT_containing_type.
14721 For everyone else, it is an expression to be evaluated relative
14722 to the object address. */
14724 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14725 if (attr
!= nullptr)
14727 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14729 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14731 /* Old-style GCC. */
14732 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14734 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14735 || (DW_BLOCK (attr
)->size
> 1
14736 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14737 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14739 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14740 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14741 dwarf2_complex_location_expr_complaint ();
14743 fnp
->voffset
/= cu
->header
.addr_size
;
14747 dwarf2_complex_location_expr_complaint ();
14749 if (!fnp
->fcontext
)
14751 /* If there is no `this' field and no DW_AT_containing_type,
14752 we cannot actually find a base class context for the
14754 if (TYPE_NFIELDS (this_type
) == 0
14755 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14757 complaint (_("cannot determine context for virtual member "
14758 "function \"%s\" (offset %s)"),
14759 fieldname
, sect_offset_str (die
->sect_off
));
14764 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14768 else if (attr
->form_is_section_offset ())
14770 dwarf2_complex_location_expr_complaint ();
14774 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14780 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14781 if (attr
&& DW_UNSND (attr
))
14783 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14784 complaint (_("Member function \"%s\" (offset %s) is virtual "
14785 "but the vtable offset is not specified"),
14786 fieldname
, sect_offset_str (die
->sect_off
));
14787 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14788 TYPE_CPLUS_DYNAMIC (type
) = 1;
14793 /* Create the vector of member function fields, and attach it to the type. */
14796 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14797 struct dwarf2_cu
*cu
)
14799 if (cu
->language
== language_ada
)
14800 error (_("unexpected member functions in Ada type"));
14802 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14803 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14805 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14807 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14809 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14810 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14812 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14813 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14814 fn_flp
->fn_fields
= (struct fn_field
*)
14815 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14817 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14818 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14821 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14824 /* Returns non-zero if NAME is the name of a vtable member in CU's
14825 language, zero otherwise. */
14827 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14829 static const char vptr
[] = "_vptr";
14831 /* Look for the C++ form of the vtable. */
14832 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14838 /* GCC outputs unnamed structures that are really pointers to member
14839 functions, with the ABI-specified layout. If TYPE describes
14840 such a structure, smash it into a member function type.
14842 GCC shouldn't do this; it should just output pointer to member DIEs.
14843 This is GCC PR debug/28767. */
14846 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14848 struct type
*pfn_type
, *self_type
, *new_type
;
14850 /* Check for a structure with no name and two children. */
14851 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14854 /* Check for __pfn and __delta members. */
14855 if (TYPE_FIELD_NAME (type
, 0) == NULL
14856 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14857 || TYPE_FIELD_NAME (type
, 1) == NULL
14858 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14861 /* Find the type of the method. */
14862 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14863 if (pfn_type
== NULL
14864 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14865 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14868 /* Look for the "this" argument. */
14869 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14870 if (TYPE_NFIELDS (pfn_type
) == 0
14871 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14872 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14875 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14876 new_type
= alloc_type (objfile
);
14877 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14878 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14879 TYPE_VARARGS (pfn_type
));
14880 smash_to_methodptr_type (type
, new_type
);
14883 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14884 appropriate error checking and issuing complaints if there is a
14888 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14890 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14892 if (attr
== nullptr)
14895 if (!attr
->form_is_constant ())
14897 complaint (_("DW_AT_alignment must have constant form"
14898 " - DIE at %s [in module %s]"),
14899 sect_offset_str (die
->sect_off
),
14900 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14905 if (attr
->form
== DW_FORM_sdata
)
14907 LONGEST val
= DW_SND (attr
);
14910 complaint (_("DW_AT_alignment value must not be negative"
14911 " - DIE at %s [in module %s]"),
14912 sect_offset_str (die
->sect_off
),
14913 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14919 align
= DW_UNSND (attr
);
14923 complaint (_("DW_AT_alignment value must not be zero"
14924 " - DIE at %s [in module %s]"),
14925 sect_offset_str (die
->sect_off
),
14926 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14929 if ((align
& (align
- 1)) != 0)
14931 complaint (_("DW_AT_alignment value must be a power of 2"
14932 " - DIE at %s [in module %s]"),
14933 sect_offset_str (die
->sect_off
),
14934 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14941 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14942 the alignment for TYPE. */
14945 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14948 if (!set_type_align (type
, get_alignment (cu
, die
)))
14949 complaint (_("DW_AT_alignment value too large"
14950 " - DIE at %s [in module %s]"),
14951 sect_offset_str (die
->sect_off
),
14952 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14955 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14956 constant for a type, according to DWARF5 spec, Table 5.5. */
14959 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14964 case DW_CC_pass_by_reference
:
14965 case DW_CC_pass_by_value
:
14969 complaint (_("unrecognized DW_AT_calling_convention value "
14970 "(%s) for a type"), pulongest (value
));
14975 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14976 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14977 also according to GNU-specific values (see include/dwarf2.h). */
14980 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14985 case DW_CC_program
:
14989 case DW_CC_GNU_renesas_sh
:
14990 case DW_CC_GNU_borland_fastcall_i386
:
14991 case DW_CC_GDB_IBM_OpenCL
:
14995 complaint (_("unrecognized DW_AT_calling_convention value "
14996 "(%s) for a subroutine"), pulongest (value
));
15001 /* Called when we find the DIE that starts a structure or union scope
15002 (definition) to create a type for the structure or union. Fill in
15003 the type's name and general properties; the members will not be
15004 processed until process_structure_scope. A symbol table entry for
15005 the type will also not be done until process_structure_scope (assuming
15006 the type has a name).
15008 NOTE: we need to call these functions regardless of whether or not the
15009 DIE has a DW_AT_name attribute, since it might be an anonymous
15010 structure or union. This gets the type entered into our set of
15011 user defined types. */
15013 static struct type
*
15014 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15016 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15018 struct attribute
*attr
;
15021 /* If the definition of this type lives in .debug_types, read that type.
15022 Don't follow DW_AT_specification though, that will take us back up
15023 the chain and we want to go down. */
15024 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15025 if (attr
!= nullptr)
15027 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15029 /* The type's CU may not be the same as CU.
15030 Ensure TYPE is recorded with CU in die_type_hash. */
15031 return set_die_type (die
, type
, cu
);
15034 type
= alloc_type (objfile
);
15035 INIT_CPLUS_SPECIFIC (type
);
15037 name
= dwarf2_name (die
, cu
);
15040 if (cu
->language
== language_cplus
15041 || cu
->language
== language_d
15042 || cu
->language
== language_rust
)
15044 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15046 /* dwarf2_full_name might have already finished building the DIE's
15047 type. If so, there is no need to continue. */
15048 if (get_die_type (die
, cu
) != NULL
)
15049 return get_die_type (die
, cu
);
15051 TYPE_NAME (type
) = full_name
;
15055 /* The name is already allocated along with this objfile, so
15056 we don't need to duplicate it for the type. */
15057 TYPE_NAME (type
) = name
;
15061 if (die
->tag
== DW_TAG_structure_type
)
15063 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15065 else if (die
->tag
== DW_TAG_union_type
)
15067 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15069 else if (die
->tag
== DW_TAG_variant_part
)
15071 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15072 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15076 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15079 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15080 TYPE_DECLARED_CLASS (type
) = 1;
15082 /* Store the calling convention in the type if it's available in
15083 the die. Otherwise the calling convention remains set to
15084 the default value DW_CC_normal. */
15085 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15086 if (attr
!= nullptr
15087 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15089 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15090 TYPE_CPLUS_CALLING_CONVENTION (type
)
15091 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15094 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15095 if (attr
!= nullptr)
15097 if (attr
->form_is_constant ())
15098 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15101 /* For the moment, dynamic type sizes are not supported
15102 by GDB's struct type. The actual size is determined
15103 on-demand when resolving the type of a given object,
15104 so set the type's length to zero for now. Otherwise,
15105 we record an expression as the length, and that expression
15106 could lead to a very large value, which could eventually
15107 lead to us trying to allocate that much memory when creating
15108 a value of that type. */
15109 TYPE_LENGTH (type
) = 0;
15114 TYPE_LENGTH (type
) = 0;
15117 maybe_set_alignment (cu
, die
, type
);
15119 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15121 /* ICC<14 does not output the required DW_AT_declaration on
15122 incomplete types, but gives them a size of zero. */
15123 TYPE_STUB (type
) = 1;
15126 TYPE_STUB_SUPPORTED (type
) = 1;
15128 if (die_is_declaration (die
, cu
))
15129 TYPE_STUB (type
) = 1;
15130 else if (attr
== NULL
&& die
->child
== NULL
15131 && producer_is_realview (cu
->producer
))
15132 /* RealView does not output the required DW_AT_declaration
15133 on incomplete types. */
15134 TYPE_STUB (type
) = 1;
15136 /* We need to add the type field to the die immediately so we don't
15137 infinitely recurse when dealing with pointers to the structure
15138 type within the structure itself. */
15139 set_die_type (die
, type
, cu
);
15141 /* set_die_type should be already done. */
15142 set_descriptive_type (type
, die
, cu
);
15147 /* A helper for process_structure_scope that handles a single member
15151 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15152 struct field_info
*fi
,
15153 std::vector
<struct symbol
*> *template_args
,
15154 struct dwarf2_cu
*cu
)
15156 if (child_die
->tag
== DW_TAG_member
15157 || child_die
->tag
== DW_TAG_variable
15158 || child_die
->tag
== DW_TAG_variant_part
)
15160 /* NOTE: carlton/2002-11-05: A C++ static data member
15161 should be a DW_TAG_member that is a declaration, but
15162 all versions of G++ as of this writing (so through at
15163 least 3.2.1) incorrectly generate DW_TAG_variable
15164 tags for them instead. */
15165 dwarf2_add_field (fi
, child_die
, cu
);
15167 else if (child_die
->tag
== DW_TAG_subprogram
)
15169 /* Rust doesn't have member functions in the C++ sense.
15170 However, it does emit ordinary functions as children
15171 of a struct DIE. */
15172 if (cu
->language
== language_rust
)
15173 read_func_scope (child_die
, cu
);
15176 /* C++ member function. */
15177 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15180 else if (child_die
->tag
== DW_TAG_inheritance
)
15182 /* C++ base class field. */
15183 dwarf2_add_field (fi
, child_die
, cu
);
15185 else if (type_can_define_types (child_die
))
15186 dwarf2_add_type_defn (fi
, child_die
, cu
);
15187 else if (child_die
->tag
== DW_TAG_template_type_param
15188 || child_die
->tag
== DW_TAG_template_value_param
)
15190 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15193 template_args
->push_back (arg
);
15195 else if (child_die
->tag
== DW_TAG_variant
)
15197 /* In a variant we want to get the discriminant and also add a
15198 field for our sole member child. */
15199 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15201 for (die_info
*variant_child
= child_die
->child
;
15202 variant_child
!= NULL
;
15203 variant_child
= sibling_die (variant_child
))
15205 if (variant_child
->tag
== DW_TAG_member
)
15207 handle_struct_member_die (variant_child
, type
, fi
,
15208 template_args
, cu
);
15209 /* Only handle the one. */
15214 /* We don't handle this but we might as well report it if we see
15216 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15217 complaint (_("DW_AT_discr_list is not supported yet"
15218 " - DIE at %s [in module %s]"),
15219 sect_offset_str (child_die
->sect_off
),
15220 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15222 /* The first field was just added, so we can stash the
15223 discriminant there. */
15224 gdb_assert (!fi
->fields
.empty ());
15226 fi
->fields
.back ().variant
.default_branch
= true;
15228 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15232 /* Finish creating a structure or union type, including filling in
15233 its members and creating a symbol for it. */
15236 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15238 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15239 struct die_info
*child_die
;
15242 type
= get_die_type (die
, cu
);
15244 type
= read_structure_type (die
, cu
);
15246 /* When reading a DW_TAG_variant_part, we need to notice when we
15247 read the discriminant member, so we can record it later in the
15248 discriminant_info. */
15249 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15250 sect_offset discr_offset
{};
15251 bool has_template_parameters
= false;
15253 if (is_variant_part
)
15255 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15258 /* Maybe it's a univariant form, an extension we support.
15259 In this case arrange not to check the offset. */
15260 is_variant_part
= false;
15262 else if (discr
->form_is_ref ())
15264 struct dwarf2_cu
*target_cu
= cu
;
15265 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15267 discr_offset
= target_die
->sect_off
;
15271 complaint (_("DW_AT_discr does not have DIE reference form"
15272 " - DIE at %s [in module %s]"),
15273 sect_offset_str (die
->sect_off
),
15274 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15275 is_variant_part
= false;
15279 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15281 struct field_info fi
;
15282 std::vector
<struct symbol
*> template_args
;
15284 child_die
= die
->child
;
15286 while (child_die
&& child_die
->tag
)
15288 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15290 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15291 fi
.fields
.back ().variant
.is_discriminant
= true;
15293 child_die
= sibling_die (child_die
);
15296 /* Attach template arguments to type. */
15297 if (!template_args
.empty ())
15299 has_template_parameters
= true;
15300 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15301 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15302 TYPE_TEMPLATE_ARGUMENTS (type
)
15303 = XOBNEWVEC (&objfile
->objfile_obstack
,
15305 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15306 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15307 template_args
.data (),
15308 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15309 * sizeof (struct symbol
*)));
15312 /* Attach fields and member functions to the type. */
15314 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15315 if (!fi
.fnfieldlists
.empty ())
15317 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15319 /* Get the type which refers to the base class (possibly this
15320 class itself) which contains the vtable pointer for the current
15321 class from the DW_AT_containing_type attribute. This use of
15322 DW_AT_containing_type is a GNU extension. */
15324 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15326 struct type
*t
= die_containing_type (die
, cu
);
15328 set_type_vptr_basetype (type
, t
);
15333 /* Our own class provides vtbl ptr. */
15334 for (i
= TYPE_NFIELDS (t
) - 1;
15335 i
>= TYPE_N_BASECLASSES (t
);
15338 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15340 if (is_vtable_name (fieldname
, cu
))
15342 set_type_vptr_fieldno (type
, i
);
15347 /* Complain if virtual function table field not found. */
15348 if (i
< TYPE_N_BASECLASSES (t
))
15349 complaint (_("virtual function table pointer "
15350 "not found when defining class '%s'"),
15351 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15355 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15358 else if (cu
->producer
15359 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15361 /* The IBM XLC compiler does not provide direct indication
15362 of the containing type, but the vtable pointer is
15363 always named __vfp. */
15367 for (i
= TYPE_NFIELDS (type
) - 1;
15368 i
>= TYPE_N_BASECLASSES (type
);
15371 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15373 set_type_vptr_fieldno (type
, i
);
15374 set_type_vptr_basetype (type
, type
);
15381 /* Copy fi.typedef_field_list linked list elements content into the
15382 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15383 if (!fi
.typedef_field_list
.empty ())
15385 int count
= fi
.typedef_field_list
.size ();
15387 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15388 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15389 = ((struct decl_field
*)
15391 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15392 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15394 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15395 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15398 /* Copy fi.nested_types_list linked list elements content into the
15399 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15400 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15402 int count
= fi
.nested_types_list
.size ();
15404 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15405 TYPE_NESTED_TYPES_ARRAY (type
)
15406 = ((struct decl_field
*)
15407 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15408 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15410 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15411 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15415 quirk_gcc_member_function_pointer (type
, objfile
);
15416 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15417 cu
->rust_unions
.push_back (type
);
15419 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15420 snapshots) has been known to create a die giving a declaration
15421 for a class that has, as a child, a die giving a definition for a
15422 nested class. So we have to process our children even if the
15423 current die is a declaration. Normally, of course, a declaration
15424 won't have any children at all. */
15426 child_die
= die
->child
;
15428 while (child_die
!= NULL
&& child_die
->tag
)
15430 if (child_die
->tag
== DW_TAG_member
15431 || child_die
->tag
== DW_TAG_variable
15432 || child_die
->tag
== DW_TAG_inheritance
15433 || child_die
->tag
== DW_TAG_template_value_param
15434 || child_die
->tag
== DW_TAG_template_type_param
)
15439 process_die (child_die
, cu
);
15441 child_die
= sibling_die (child_die
);
15444 /* Do not consider external references. According to the DWARF standard,
15445 these DIEs are identified by the fact that they have no byte_size
15446 attribute, and a declaration attribute. */
15447 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15448 || !die_is_declaration (die
, cu
))
15450 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15452 if (has_template_parameters
)
15454 struct symtab
*symtab
;
15455 if (sym
!= nullptr)
15456 symtab
= symbol_symtab (sym
);
15457 else if (cu
->line_header
!= nullptr)
15459 /* Any related symtab will do. */
15461 = cu
->line_header
->file_names ()[0].symtab
;
15466 complaint (_("could not find suitable "
15467 "symtab for template parameter"
15468 " - DIE at %s [in module %s]"),
15469 sect_offset_str (die
->sect_off
),
15470 objfile_name (objfile
));
15473 if (symtab
!= nullptr)
15475 /* Make sure that the symtab is set on the new symbols.
15476 Even though they don't appear in this symtab directly,
15477 other parts of gdb assume that symbols do, and this is
15478 reasonably true. */
15479 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15480 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15486 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15487 update TYPE using some information only available in DIE's children. */
15490 update_enumeration_type_from_children (struct die_info
*die
,
15492 struct dwarf2_cu
*cu
)
15494 struct die_info
*child_die
;
15495 int unsigned_enum
= 1;
15499 auto_obstack obstack
;
15501 for (child_die
= die
->child
;
15502 child_die
!= NULL
&& child_die
->tag
;
15503 child_die
= sibling_die (child_die
))
15505 struct attribute
*attr
;
15507 const gdb_byte
*bytes
;
15508 struct dwarf2_locexpr_baton
*baton
;
15511 if (child_die
->tag
!= DW_TAG_enumerator
)
15514 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15518 name
= dwarf2_name (child_die
, cu
);
15520 name
= "<anonymous enumerator>";
15522 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15523 &value
, &bytes
, &baton
);
15529 else if ((mask
& value
) != 0)
15534 /* If we already know that the enum type is neither unsigned, nor
15535 a flag type, no need to look at the rest of the enumerates. */
15536 if (!unsigned_enum
&& !flag_enum
)
15541 TYPE_UNSIGNED (type
) = 1;
15543 TYPE_FLAG_ENUM (type
) = 1;
15546 /* Given a DW_AT_enumeration_type die, set its type. We do not
15547 complete the type's fields yet, or create any symbols. */
15549 static struct type
*
15550 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15552 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15554 struct attribute
*attr
;
15557 /* If the definition of this type lives in .debug_types, read that type.
15558 Don't follow DW_AT_specification though, that will take us back up
15559 the chain and we want to go down. */
15560 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15561 if (attr
!= nullptr)
15563 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15565 /* The type's CU may not be the same as CU.
15566 Ensure TYPE is recorded with CU in die_type_hash. */
15567 return set_die_type (die
, type
, cu
);
15570 type
= alloc_type (objfile
);
15572 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15573 name
= dwarf2_full_name (NULL
, die
, cu
);
15575 TYPE_NAME (type
) = name
;
15577 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15580 struct type
*underlying_type
= die_type (die
, cu
);
15582 TYPE_TARGET_TYPE (type
) = underlying_type
;
15585 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15586 if (attr
!= nullptr)
15588 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15592 TYPE_LENGTH (type
) = 0;
15595 maybe_set_alignment (cu
, die
, type
);
15597 /* The enumeration DIE can be incomplete. In Ada, any type can be
15598 declared as private in the package spec, and then defined only
15599 inside the package body. Such types are known as Taft Amendment
15600 Types. When another package uses such a type, an incomplete DIE
15601 may be generated by the compiler. */
15602 if (die_is_declaration (die
, cu
))
15603 TYPE_STUB (type
) = 1;
15605 /* Finish the creation of this type by using the enum's children.
15606 We must call this even when the underlying type has been provided
15607 so that we can determine if we're looking at a "flag" enum. */
15608 update_enumeration_type_from_children (die
, type
, cu
);
15610 /* If this type has an underlying type that is not a stub, then we
15611 may use its attributes. We always use the "unsigned" attribute
15612 in this situation, because ordinarily we guess whether the type
15613 is unsigned -- but the guess can be wrong and the underlying type
15614 can tell us the reality. However, we defer to a local size
15615 attribute if one exists, because this lets the compiler override
15616 the underlying type if needed. */
15617 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15619 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15620 if (TYPE_LENGTH (type
) == 0)
15621 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15622 if (TYPE_RAW_ALIGN (type
) == 0
15623 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15624 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15627 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15629 return set_die_type (die
, type
, cu
);
15632 /* Given a pointer to a die which begins an enumeration, process all
15633 the dies that define the members of the enumeration, and create the
15634 symbol for the enumeration type.
15636 NOTE: We reverse the order of the element list. */
15639 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15641 struct type
*this_type
;
15643 this_type
= get_die_type (die
, cu
);
15644 if (this_type
== NULL
)
15645 this_type
= read_enumeration_type (die
, cu
);
15647 if (die
->child
!= NULL
)
15649 struct die_info
*child_die
;
15650 struct symbol
*sym
;
15651 std::vector
<struct field
> fields
;
15654 child_die
= die
->child
;
15655 while (child_die
&& child_die
->tag
)
15657 if (child_die
->tag
!= DW_TAG_enumerator
)
15659 process_die (child_die
, cu
);
15663 name
= dwarf2_name (child_die
, cu
);
15666 sym
= new_symbol (child_die
, this_type
, cu
);
15668 fields
.emplace_back ();
15669 struct field
&field
= fields
.back ();
15671 FIELD_NAME (field
) = sym
->linkage_name ();
15672 FIELD_TYPE (field
) = NULL
;
15673 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15674 FIELD_BITSIZE (field
) = 0;
15678 child_die
= sibling_die (child_die
);
15681 if (!fields
.empty ())
15683 TYPE_NFIELDS (this_type
) = fields
.size ();
15684 TYPE_FIELDS (this_type
) = (struct field
*)
15685 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15686 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15687 sizeof (struct field
) * fields
.size ());
15691 /* If we are reading an enum from a .debug_types unit, and the enum
15692 is a declaration, and the enum is not the signatured type in the
15693 unit, then we do not want to add a symbol for it. Adding a
15694 symbol would in some cases obscure the true definition of the
15695 enum, giving users an incomplete type when the definition is
15696 actually available. Note that we do not want to do this for all
15697 enums which are just declarations, because C++0x allows forward
15698 enum declarations. */
15699 if (cu
->per_cu
->is_debug_types
15700 && die_is_declaration (die
, cu
))
15702 struct signatured_type
*sig_type
;
15704 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15705 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15706 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15710 new_symbol (die
, this_type
, cu
);
15713 /* Extract all information from a DW_TAG_array_type DIE and put it in
15714 the DIE's type field. For now, this only handles one dimensional
15717 static struct type
*
15718 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15720 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15721 struct die_info
*child_die
;
15723 struct type
*element_type
, *range_type
, *index_type
;
15724 struct attribute
*attr
;
15726 struct dynamic_prop
*byte_stride_prop
= NULL
;
15727 unsigned int bit_stride
= 0;
15729 element_type
= die_type (die
, cu
);
15731 /* The die_type call above may have already set the type for this DIE. */
15732 type
= get_die_type (die
, cu
);
15736 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15740 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15743 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15744 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15748 complaint (_("unable to read array DW_AT_byte_stride "
15749 " - DIE at %s [in module %s]"),
15750 sect_offset_str (die
->sect_off
),
15751 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15752 /* Ignore this attribute. We will likely not be able to print
15753 arrays of this type correctly, but there is little we can do
15754 to help if we cannot read the attribute's value. */
15755 byte_stride_prop
= NULL
;
15759 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15761 bit_stride
= DW_UNSND (attr
);
15763 /* Irix 6.2 native cc creates array types without children for
15764 arrays with unspecified length. */
15765 if (die
->child
== NULL
)
15767 index_type
= objfile_type (objfile
)->builtin_int
;
15768 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15769 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15770 byte_stride_prop
, bit_stride
);
15771 return set_die_type (die
, type
, cu
);
15774 std::vector
<struct type
*> range_types
;
15775 child_die
= die
->child
;
15776 while (child_die
&& child_die
->tag
)
15778 if (child_die
->tag
== DW_TAG_subrange_type
)
15780 struct type
*child_type
= read_type_die (child_die
, cu
);
15782 if (child_type
!= NULL
)
15784 /* The range type was succesfully read. Save it for the
15785 array type creation. */
15786 range_types
.push_back (child_type
);
15789 child_die
= sibling_die (child_die
);
15792 /* Dwarf2 dimensions are output from left to right, create the
15793 necessary array types in backwards order. */
15795 type
= element_type
;
15797 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15801 while (i
< range_types
.size ())
15802 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15803 byte_stride_prop
, bit_stride
);
15807 size_t ndim
= range_types
.size ();
15809 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15810 byte_stride_prop
, bit_stride
);
15813 /* Understand Dwarf2 support for vector types (like they occur on
15814 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15815 array type. This is not part of the Dwarf2/3 standard yet, but a
15816 custom vendor extension. The main difference between a regular
15817 array and the vector variant is that vectors are passed by value
15819 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15820 if (attr
!= nullptr)
15821 make_vector_type (type
);
15823 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15824 implementation may choose to implement triple vectors using this
15826 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15827 if (attr
!= nullptr)
15829 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15830 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15832 complaint (_("DW_AT_byte_size for array type smaller "
15833 "than the total size of elements"));
15836 name
= dwarf2_name (die
, cu
);
15838 TYPE_NAME (type
) = name
;
15840 maybe_set_alignment (cu
, die
, type
);
15842 /* Install the type in the die. */
15843 set_die_type (die
, type
, cu
);
15845 /* set_die_type should be already done. */
15846 set_descriptive_type (type
, die
, cu
);
15851 static enum dwarf_array_dim_ordering
15852 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15854 struct attribute
*attr
;
15856 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15858 if (attr
!= nullptr)
15859 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15861 /* GNU F77 is a special case, as at 08/2004 array type info is the
15862 opposite order to the dwarf2 specification, but data is still
15863 laid out as per normal fortran.
15865 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15866 version checking. */
15868 if (cu
->language
== language_fortran
15869 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15871 return DW_ORD_row_major
;
15874 switch (cu
->language_defn
->la_array_ordering
)
15876 case array_column_major
:
15877 return DW_ORD_col_major
;
15878 case array_row_major
:
15880 return DW_ORD_row_major
;
15884 /* Extract all information from a DW_TAG_set_type DIE and put it in
15885 the DIE's type field. */
15887 static struct type
*
15888 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15890 struct type
*domain_type
, *set_type
;
15891 struct attribute
*attr
;
15893 domain_type
= die_type (die
, cu
);
15895 /* The die_type call above may have already set the type for this DIE. */
15896 set_type
= get_die_type (die
, cu
);
15900 set_type
= create_set_type (NULL
, domain_type
);
15902 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15903 if (attr
!= nullptr)
15904 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15906 maybe_set_alignment (cu
, die
, set_type
);
15908 return set_die_type (die
, set_type
, cu
);
15911 /* A helper for read_common_block that creates a locexpr baton.
15912 SYM is the symbol which we are marking as computed.
15913 COMMON_DIE is the DIE for the common block.
15914 COMMON_LOC is the location expression attribute for the common
15916 MEMBER_LOC is the location expression attribute for the particular
15917 member of the common block that we are processing.
15918 CU is the CU from which the above come. */
15921 mark_common_block_symbol_computed (struct symbol
*sym
,
15922 struct die_info
*common_die
,
15923 struct attribute
*common_loc
,
15924 struct attribute
*member_loc
,
15925 struct dwarf2_cu
*cu
)
15927 struct dwarf2_per_objfile
*dwarf2_per_objfile
15928 = cu
->per_cu
->dwarf2_per_objfile
;
15929 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15930 struct dwarf2_locexpr_baton
*baton
;
15932 unsigned int cu_off
;
15933 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15934 LONGEST offset
= 0;
15936 gdb_assert (common_loc
&& member_loc
);
15937 gdb_assert (common_loc
->form_is_block ());
15938 gdb_assert (member_loc
->form_is_block ()
15939 || member_loc
->form_is_constant ());
15941 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15942 baton
->per_cu
= cu
->per_cu
;
15943 gdb_assert (baton
->per_cu
);
15945 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15947 if (member_loc
->form_is_constant ())
15949 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15950 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15953 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15955 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15958 *ptr
++ = DW_OP_call4
;
15959 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15960 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15963 if (member_loc
->form_is_constant ())
15965 *ptr
++ = DW_OP_addr
;
15966 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15967 ptr
+= cu
->header
.addr_size
;
15971 /* We have to copy the data here, because DW_OP_call4 will only
15972 use a DW_AT_location attribute. */
15973 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15974 ptr
+= DW_BLOCK (member_loc
)->size
;
15977 *ptr
++ = DW_OP_plus
;
15978 gdb_assert (ptr
- baton
->data
== baton
->size
);
15980 SYMBOL_LOCATION_BATON (sym
) = baton
;
15981 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15984 /* Create appropriate locally-scoped variables for all the
15985 DW_TAG_common_block entries. Also create a struct common_block
15986 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15987 is used to separate the common blocks name namespace from regular
15991 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15993 struct attribute
*attr
;
15995 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15996 if (attr
!= nullptr)
15998 /* Support the .debug_loc offsets. */
15999 if (attr
->form_is_block ())
16003 else if (attr
->form_is_section_offset ())
16005 dwarf2_complex_location_expr_complaint ();
16010 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16011 "common block member");
16016 if (die
->child
!= NULL
)
16018 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16019 struct die_info
*child_die
;
16020 size_t n_entries
= 0, size
;
16021 struct common_block
*common_block
;
16022 struct symbol
*sym
;
16024 for (child_die
= die
->child
;
16025 child_die
&& child_die
->tag
;
16026 child_die
= sibling_die (child_die
))
16029 size
= (sizeof (struct common_block
)
16030 + (n_entries
- 1) * sizeof (struct symbol
*));
16032 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16034 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16035 common_block
->n_entries
= 0;
16037 for (child_die
= die
->child
;
16038 child_die
&& child_die
->tag
;
16039 child_die
= sibling_die (child_die
))
16041 /* Create the symbol in the DW_TAG_common_block block in the current
16043 sym
= new_symbol (child_die
, NULL
, cu
);
16046 struct attribute
*member_loc
;
16048 common_block
->contents
[common_block
->n_entries
++] = sym
;
16050 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16054 /* GDB has handled this for a long time, but it is
16055 not specified by DWARF. It seems to have been
16056 emitted by gfortran at least as recently as:
16057 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16058 complaint (_("Variable in common block has "
16059 "DW_AT_data_member_location "
16060 "- DIE at %s [in module %s]"),
16061 sect_offset_str (child_die
->sect_off
),
16062 objfile_name (objfile
));
16064 if (member_loc
->form_is_section_offset ())
16065 dwarf2_complex_location_expr_complaint ();
16066 else if (member_loc
->form_is_constant ()
16067 || member_loc
->form_is_block ())
16069 if (attr
!= nullptr)
16070 mark_common_block_symbol_computed (sym
, die
, attr
,
16074 dwarf2_complex_location_expr_complaint ();
16079 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16080 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16084 /* Create a type for a C++ namespace. */
16086 static struct type
*
16087 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16089 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16090 const char *previous_prefix
, *name
;
16094 /* For extensions, reuse the type of the original namespace. */
16095 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16097 struct die_info
*ext_die
;
16098 struct dwarf2_cu
*ext_cu
= cu
;
16100 ext_die
= dwarf2_extension (die
, &ext_cu
);
16101 type
= read_type_die (ext_die
, ext_cu
);
16103 /* EXT_CU may not be the same as CU.
16104 Ensure TYPE is recorded with CU in die_type_hash. */
16105 return set_die_type (die
, type
, cu
);
16108 name
= namespace_name (die
, &is_anonymous
, cu
);
16110 /* Now build the name of the current namespace. */
16112 previous_prefix
= determine_prefix (die
, cu
);
16113 if (previous_prefix
[0] != '\0')
16114 name
= typename_concat (&objfile
->objfile_obstack
,
16115 previous_prefix
, name
, 0, cu
);
16117 /* Create the type. */
16118 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16120 return set_die_type (die
, type
, cu
);
16123 /* Read a namespace scope. */
16126 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16128 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16131 /* Add a symbol associated to this if we haven't seen the namespace
16132 before. Also, add a using directive if it's an anonymous
16135 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16139 type
= read_type_die (die
, cu
);
16140 new_symbol (die
, type
, cu
);
16142 namespace_name (die
, &is_anonymous
, cu
);
16145 const char *previous_prefix
= determine_prefix (die
, cu
);
16147 std::vector
<const char *> excludes
;
16148 add_using_directive (using_directives (cu
),
16149 previous_prefix
, TYPE_NAME (type
), NULL
,
16150 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16154 if (die
->child
!= NULL
)
16156 struct die_info
*child_die
= die
->child
;
16158 while (child_die
&& child_die
->tag
)
16160 process_die (child_die
, cu
);
16161 child_die
= sibling_die (child_die
);
16166 /* Read a Fortran module as type. This DIE can be only a declaration used for
16167 imported module. Still we need that type as local Fortran "use ... only"
16168 declaration imports depend on the created type in determine_prefix. */
16170 static struct type
*
16171 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16173 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16174 const char *module_name
;
16177 module_name
= dwarf2_name (die
, cu
);
16178 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16180 return set_die_type (die
, type
, cu
);
16183 /* Read a Fortran module. */
16186 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16188 struct die_info
*child_die
= die
->child
;
16191 type
= read_type_die (die
, cu
);
16192 new_symbol (die
, type
, cu
);
16194 while (child_die
&& child_die
->tag
)
16196 process_die (child_die
, cu
);
16197 child_die
= sibling_die (child_die
);
16201 /* Return the name of the namespace represented by DIE. Set
16202 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16205 static const char *
16206 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16208 struct die_info
*current_die
;
16209 const char *name
= NULL
;
16211 /* Loop through the extensions until we find a name. */
16213 for (current_die
= die
;
16214 current_die
!= NULL
;
16215 current_die
= dwarf2_extension (die
, &cu
))
16217 /* We don't use dwarf2_name here so that we can detect the absence
16218 of a name -> anonymous namespace. */
16219 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16225 /* Is it an anonymous namespace? */
16227 *is_anonymous
= (name
== NULL
);
16229 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16234 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16235 the user defined type vector. */
16237 static struct type
*
16238 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16240 struct gdbarch
*gdbarch
16241 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16242 struct comp_unit_head
*cu_header
= &cu
->header
;
16244 struct attribute
*attr_byte_size
;
16245 struct attribute
*attr_address_class
;
16246 int byte_size
, addr_class
;
16247 struct type
*target_type
;
16249 target_type
= die_type (die
, cu
);
16251 /* The die_type call above may have already set the type for this DIE. */
16252 type
= get_die_type (die
, cu
);
16256 type
= lookup_pointer_type (target_type
);
16258 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16259 if (attr_byte_size
)
16260 byte_size
= DW_UNSND (attr_byte_size
);
16262 byte_size
= cu_header
->addr_size
;
16264 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16265 if (attr_address_class
)
16266 addr_class
= DW_UNSND (attr_address_class
);
16268 addr_class
= DW_ADDR_none
;
16270 ULONGEST alignment
= get_alignment (cu
, die
);
16272 /* If the pointer size, alignment, or address class is different
16273 than the default, create a type variant marked as such and set
16274 the length accordingly. */
16275 if (TYPE_LENGTH (type
) != byte_size
16276 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16277 && alignment
!= TYPE_RAW_ALIGN (type
))
16278 || addr_class
!= DW_ADDR_none
)
16280 if (gdbarch_address_class_type_flags_p (gdbarch
))
16284 type_flags
= gdbarch_address_class_type_flags
16285 (gdbarch
, byte_size
, addr_class
);
16286 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16288 type
= make_type_with_address_space (type
, type_flags
);
16290 else if (TYPE_LENGTH (type
) != byte_size
)
16292 complaint (_("invalid pointer size %d"), byte_size
);
16294 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16296 complaint (_("Invalid DW_AT_alignment"
16297 " - DIE at %s [in module %s]"),
16298 sect_offset_str (die
->sect_off
),
16299 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16303 /* Should we also complain about unhandled address classes? */
16307 TYPE_LENGTH (type
) = byte_size
;
16308 set_type_align (type
, alignment
);
16309 return set_die_type (die
, type
, cu
);
16312 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16313 the user defined type vector. */
16315 static struct type
*
16316 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16319 struct type
*to_type
;
16320 struct type
*domain
;
16322 to_type
= die_type (die
, cu
);
16323 domain
= die_containing_type (die
, cu
);
16325 /* The calls above may have already set the type for this DIE. */
16326 type
= get_die_type (die
, cu
);
16330 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16331 type
= lookup_methodptr_type (to_type
);
16332 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16334 struct type
*new_type
16335 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16337 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16338 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16339 TYPE_VARARGS (to_type
));
16340 type
= lookup_methodptr_type (new_type
);
16343 type
= lookup_memberptr_type (to_type
, domain
);
16345 return set_die_type (die
, type
, cu
);
16348 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16349 the user defined type vector. */
16351 static struct type
*
16352 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16353 enum type_code refcode
)
16355 struct comp_unit_head
*cu_header
= &cu
->header
;
16356 struct type
*type
, *target_type
;
16357 struct attribute
*attr
;
16359 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16361 target_type
= die_type (die
, cu
);
16363 /* The die_type call above may have already set the type for this DIE. */
16364 type
= get_die_type (die
, cu
);
16368 type
= lookup_reference_type (target_type
, refcode
);
16369 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16370 if (attr
!= nullptr)
16372 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16376 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16378 maybe_set_alignment (cu
, die
, type
);
16379 return set_die_type (die
, type
, cu
);
16382 /* Add the given cv-qualifiers to the element type of the array. GCC
16383 outputs DWARF type qualifiers that apply to an array, not the
16384 element type. But GDB relies on the array element type to carry
16385 the cv-qualifiers. This mimics section 6.7.3 of the C99
16388 static struct type
*
16389 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16390 struct type
*base_type
, int cnst
, int voltl
)
16392 struct type
*el_type
, *inner_array
;
16394 base_type
= copy_type (base_type
);
16395 inner_array
= base_type
;
16397 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16399 TYPE_TARGET_TYPE (inner_array
) =
16400 copy_type (TYPE_TARGET_TYPE (inner_array
));
16401 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16404 el_type
= TYPE_TARGET_TYPE (inner_array
);
16405 cnst
|= TYPE_CONST (el_type
);
16406 voltl
|= TYPE_VOLATILE (el_type
);
16407 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16409 return set_die_type (die
, base_type
, cu
);
16412 static struct type
*
16413 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16415 struct type
*base_type
, *cv_type
;
16417 base_type
= die_type (die
, cu
);
16419 /* The die_type call above may have already set the type for this DIE. */
16420 cv_type
= get_die_type (die
, cu
);
16424 /* In case the const qualifier is applied to an array type, the element type
16425 is so qualified, not the array type (section 6.7.3 of C99). */
16426 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16427 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16429 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16430 return set_die_type (die
, cv_type
, cu
);
16433 static struct type
*
16434 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16436 struct type
*base_type
, *cv_type
;
16438 base_type
= die_type (die
, cu
);
16440 /* The die_type call above may have already set the type for this DIE. */
16441 cv_type
= get_die_type (die
, cu
);
16445 /* In case the volatile qualifier is applied to an array type, the
16446 element type is so qualified, not the array type (section 6.7.3
16448 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16449 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16451 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16452 return set_die_type (die
, cv_type
, cu
);
16455 /* Handle DW_TAG_restrict_type. */
16457 static struct type
*
16458 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16460 struct type
*base_type
, *cv_type
;
16462 base_type
= die_type (die
, cu
);
16464 /* The die_type call above may have already set the type for this DIE. */
16465 cv_type
= get_die_type (die
, cu
);
16469 cv_type
= make_restrict_type (base_type
);
16470 return set_die_type (die
, cv_type
, cu
);
16473 /* Handle DW_TAG_atomic_type. */
16475 static struct type
*
16476 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16478 struct type
*base_type
, *cv_type
;
16480 base_type
= die_type (die
, cu
);
16482 /* The die_type call above may have already set the type for this DIE. */
16483 cv_type
= get_die_type (die
, cu
);
16487 cv_type
= make_atomic_type (base_type
);
16488 return set_die_type (die
, cv_type
, cu
);
16491 /* Extract all information from a DW_TAG_string_type DIE and add to
16492 the user defined type vector. It isn't really a user defined type,
16493 but it behaves like one, with other DIE's using an AT_user_def_type
16494 attribute to reference it. */
16496 static struct type
*
16497 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16499 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16500 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16501 struct type
*type
, *range_type
, *index_type
, *char_type
;
16502 struct attribute
*attr
;
16503 struct dynamic_prop prop
;
16504 bool length_is_constant
= true;
16507 /* There are a couple of places where bit sizes might be made use of
16508 when parsing a DW_TAG_string_type, however, no producer that we know
16509 of make use of these. Handling bit sizes that are a multiple of the
16510 byte size is easy enough, but what about other bit sizes? Lets deal
16511 with that problem when we have to. Warn about these attributes being
16512 unsupported, then parse the type and ignore them like we always
16514 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16515 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16517 static bool warning_printed
= false;
16518 if (!warning_printed
)
16520 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16521 "currently supported on DW_TAG_string_type."));
16522 warning_printed
= true;
16526 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16527 if (attr
!= nullptr && !attr
->form_is_constant ())
16529 /* The string length describes the location at which the length of
16530 the string can be found. The size of the length field can be
16531 specified with one of the attributes below. */
16532 struct type
*prop_type
;
16533 struct attribute
*len
16534 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16535 if (len
== nullptr)
16536 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16537 if (len
!= nullptr && len
->form_is_constant ())
16539 /* Pass 0 as the default as we know this attribute is constant
16540 and the default value will not be returned. */
16541 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16542 prop_type
= cu
->per_cu
->int_type (sz
, true);
16546 /* If the size is not specified then we assume it is the size of
16547 an address on this target. */
16548 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16551 /* Convert the attribute into a dynamic property. */
16552 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16555 length_is_constant
= false;
16557 else if (attr
!= nullptr)
16559 /* This DW_AT_string_length just contains the length with no
16560 indirection. There's no need to create a dynamic property in this
16561 case. Pass 0 for the default value as we know it will not be
16562 returned in this case. */
16563 length
= dwarf2_get_attr_constant_value (attr
, 0);
16565 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16567 /* We don't currently support non-constant byte sizes for strings. */
16568 length
= dwarf2_get_attr_constant_value (attr
, 1);
16572 /* Use 1 as a fallback length if we have nothing else. */
16576 index_type
= objfile_type (objfile
)->builtin_int
;
16577 if (length_is_constant
)
16578 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16581 struct dynamic_prop low_bound
;
16583 low_bound
.kind
= PROP_CONST
;
16584 low_bound
.data
.const_val
= 1;
16585 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16587 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16588 type
= create_string_type (NULL
, char_type
, range_type
);
16590 return set_die_type (die
, type
, cu
);
16593 /* Assuming that DIE corresponds to a function, returns nonzero
16594 if the function is prototyped. */
16597 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16599 struct attribute
*attr
;
16601 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16602 if (attr
&& (DW_UNSND (attr
) != 0))
16605 /* The DWARF standard implies that the DW_AT_prototyped attribute
16606 is only meaningful for C, but the concept also extends to other
16607 languages that allow unprototyped functions (Eg: Objective C).
16608 For all other languages, assume that functions are always
16610 if (cu
->language
!= language_c
16611 && cu
->language
!= language_objc
16612 && cu
->language
!= language_opencl
)
16615 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16616 prototyped and unprototyped functions; default to prototyped,
16617 since that is more common in modern code (and RealView warns
16618 about unprototyped functions). */
16619 if (producer_is_realview (cu
->producer
))
16625 /* Handle DIES due to C code like:
16629 int (*funcp)(int a, long l);
16633 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16635 static struct type
*
16636 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16638 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16639 struct type
*type
; /* Type that this function returns. */
16640 struct type
*ftype
; /* Function that returns above type. */
16641 struct attribute
*attr
;
16643 type
= die_type (die
, cu
);
16645 /* The die_type call above may have already set the type for this DIE. */
16646 ftype
= get_die_type (die
, cu
);
16650 ftype
= lookup_function_type (type
);
16652 if (prototyped_function_p (die
, cu
))
16653 TYPE_PROTOTYPED (ftype
) = 1;
16655 /* Store the calling convention in the type if it's available in
16656 the subroutine die. Otherwise set the calling convention to
16657 the default value DW_CC_normal. */
16658 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16659 if (attr
!= nullptr
16660 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16661 TYPE_CALLING_CONVENTION (ftype
)
16662 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16663 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16664 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16666 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16668 /* Record whether the function returns normally to its caller or not
16669 if the DWARF producer set that information. */
16670 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16671 if (attr
&& (DW_UNSND (attr
) != 0))
16672 TYPE_NO_RETURN (ftype
) = 1;
16674 /* We need to add the subroutine type to the die immediately so
16675 we don't infinitely recurse when dealing with parameters
16676 declared as the same subroutine type. */
16677 set_die_type (die
, ftype
, cu
);
16679 if (die
->child
!= NULL
)
16681 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16682 struct die_info
*child_die
;
16683 int nparams
, iparams
;
16685 /* Count the number of parameters.
16686 FIXME: GDB currently ignores vararg functions, but knows about
16687 vararg member functions. */
16689 child_die
= die
->child
;
16690 while (child_die
&& child_die
->tag
)
16692 if (child_die
->tag
== DW_TAG_formal_parameter
)
16694 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16695 TYPE_VARARGS (ftype
) = 1;
16696 child_die
= sibling_die (child_die
);
16699 /* Allocate storage for parameters and fill them in. */
16700 TYPE_NFIELDS (ftype
) = nparams
;
16701 TYPE_FIELDS (ftype
) = (struct field
*)
16702 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16704 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16705 even if we error out during the parameters reading below. */
16706 for (iparams
= 0; iparams
< nparams
; iparams
++)
16707 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16710 child_die
= die
->child
;
16711 while (child_die
&& child_die
->tag
)
16713 if (child_die
->tag
== DW_TAG_formal_parameter
)
16715 struct type
*arg_type
;
16717 /* DWARF version 2 has no clean way to discern C++
16718 static and non-static member functions. G++ helps
16719 GDB by marking the first parameter for non-static
16720 member functions (which is the this pointer) as
16721 artificial. We pass this information to
16722 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16724 DWARF version 3 added DW_AT_object_pointer, which GCC
16725 4.5 does not yet generate. */
16726 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16727 if (attr
!= nullptr)
16728 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16730 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16731 arg_type
= die_type (child_die
, cu
);
16733 /* RealView does not mark THIS as const, which the testsuite
16734 expects. GCC marks THIS as const in method definitions,
16735 but not in the class specifications (GCC PR 43053). */
16736 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16737 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16740 struct dwarf2_cu
*arg_cu
= cu
;
16741 const char *name
= dwarf2_name (child_die
, cu
);
16743 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16744 if (attr
!= nullptr)
16746 /* If the compiler emits this, use it. */
16747 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16750 else if (name
&& strcmp (name
, "this") == 0)
16751 /* Function definitions will have the argument names. */
16753 else if (name
== NULL
&& iparams
== 0)
16754 /* Declarations may not have the names, so like
16755 elsewhere in GDB, assume an artificial first
16756 argument is "this". */
16760 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16764 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16767 child_die
= sibling_die (child_die
);
16774 static struct type
*
16775 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16777 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16778 const char *name
= NULL
;
16779 struct type
*this_type
, *target_type
;
16781 name
= dwarf2_full_name (NULL
, die
, cu
);
16782 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16783 TYPE_TARGET_STUB (this_type
) = 1;
16784 set_die_type (die
, this_type
, cu
);
16785 target_type
= die_type (die
, cu
);
16786 if (target_type
!= this_type
)
16787 TYPE_TARGET_TYPE (this_type
) = target_type
;
16790 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16791 spec and cause infinite loops in GDB. */
16792 complaint (_("Self-referential DW_TAG_typedef "
16793 "- DIE at %s [in module %s]"),
16794 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16795 TYPE_TARGET_TYPE (this_type
) = NULL
;
16800 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16801 (which may be different from NAME) to the architecture back-end to allow
16802 it to guess the correct format if necessary. */
16804 static struct type
*
16805 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16806 const char *name_hint
, enum bfd_endian byte_order
)
16808 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16809 const struct floatformat
**format
;
16812 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16814 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16816 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16821 /* Allocate an integer type of size BITS and name NAME. */
16823 static struct type
*
16824 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16825 int bits
, int unsigned_p
, const char *name
)
16829 /* Versions of Intel's C Compiler generate an integer type called "void"
16830 instead of using DW_TAG_unspecified_type. This has been seen on
16831 at least versions 14, 17, and 18. */
16832 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16833 && strcmp (name
, "void") == 0)
16834 type
= objfile_type (objfile
)->builtin_void
;
16836 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16841 /* Initialise and return a floating point type of size BITS suitable for
16842 use as a component of a complex number. The NAME_HINT is passed through
16843 when initialising the floating point type and is the name of the complex
16846 As DWARF doesn't currently provide an explicit name for the components
16847 of a complex number, but it can be helpful to have these components
16848 named, we try to select a suitable name based on the size of the
16850 static struct type
*
16851 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16852 struct objfile
*objfile
,
16853 int bits
, const char *name_hint
,
16854 enum bfd_endian byte_order
)
16856 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16857 struct type
*tt
= nullptr;
16859 /* Try to find a suitable floating point builtin type of size BITS.
16860 We're going to use the name of this type as the name for the complex
16861 target type that we are about to create. */
16862 switch (cu
->language
)
16864 case language_fortran
:
16868 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16871 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16873 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16875 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16883 tt
= builtin_type (gdbarch
)->builtin_float
;
16886 tt
= builtin_type (gdbarch
)->builtin_double
;
16888 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16890 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16896 /* If the type we found doesn't match the size we were looking for, then
16897 pretend we didn't find a type at all, the complex target type we
16898 create will then be nameless. */
16899 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16902 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16903 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16906 /* Find a representation of a given base type and install
16907 it in the TYPE field of the die. */
16909 static struct type
*
16910 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16912 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16914 struct attribute
*attr
;
16915 int encoding
= 0, bits
= 0;
16919 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16920 if (attr
!= nullptr)
16921 encoding
= DW_UNSND (attr
);
16922 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16923 if (attr
!= nullptr)
16924 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16925 name
= dwarf2_name (die
, cu
);
16927 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16929 arch
= get_objfile_arch (objfile
);
16930 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16932 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16935 int endianity
= DW_UNSND (attr
);
16940 byte_order
= BFD_ENDIAN_BIG
;
16942 case DW_END_little
:
16943 byte_order
= BFD_ENDIAN_LITTLE
;
16946 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16953 case DW_ATE_address
:
16954 /* Turn DW_ATE_address into a void * pointer. */
16955 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16956 type
= init_pointer_type (objfile
, bits
, name
, type
);
16958 case DW_ATE_boolean
:
16959 type
= init_boolean_type (objfile
, bits
, 1, name
);
16961 case DW_ATE_complex_float
:
16962 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16964 type
= init_complex_type (objfile
, name
, type
);
16966 case DW_ATE_decimal_float
:
16967 type
= init_decfloat_type (objfile
, bits
, name
);
16970 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16972 case DW_ATE_signed
:
16973 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16975 case DW_ATE_unsigned
:
16976 if (cu
->language
== language_fortran
16978 && startswith (name
, "character("))
16979 type
= init_character_type (objfile
, bits
, 1, name
);
16981 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16983 case DW_ATE_signed_char
:
16984 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16985 || cu
->language
== language_pascal
16986 || cu
->language
== language_fortran
)
16987 type
= init_character_type (objfile
, bits
, 0, name
);
16989 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16991 case DW_ATE_unsigned_char
:
16992 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16993 || cu
->language
== language_pascal
16994 || cu
->language
== language_fortran
16995 || cu
->language
== language_rust
)
16996 type
= init_character_type (objfile
, bits
, 1, name
);
16998 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17003 type
= builtin_type (arch
)->builtin_char16
;
17004 else if (bits
== 32)
17005 type
= builtin_type (arch
)->builtin_char32
;
17008 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17010 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17012 return set_die_type (die
, type
, cu
);
17017 complaint (_("unsupported DW_AT_encoding: '%s'"),
17018 dwarf_type_encoding_name (encoding
));
17019 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17023 if (name
&& strcmp (name
, "char") == 0)
17024 TYPE_NOSIGN (type
) = 1;
17026 maybe_set_alignment (cu
, die
, type
);
17028 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17030 return set_die_type (die
, type
, cu
);
17033 /* Parse dwarf attribute if it's a block, reference or constant and put the
17034 resulting value of the attribute into struct bound_prop.
17035 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17038 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17039 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17040 struct type
*default_type
)
17042 struct dwarf2_property_baton
*baton
;
17043 struct obstack
*obstack
17044 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17046 gdb_assert (default_type
!= NULL
);
17048 if (attr
== NULL
|| prop
== NULL
)
17051 if (attr
->form_is_block ())
17053 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17054 baton
->property_type
= default_type
;
17055 baton
->locexpr
.per_cu
= cu
->per_cu
;
17056 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17057 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17058 switch (attr
->name
)
17060 case DW_AT_string_length
:
17061 baton
->locexpr
.is_reference
= true;
17064 baton
->locexpr
.is_reference
= false;
17067 prop
->data
.baton
= baton
;
17068 prop
->kind
= PROP_LOCEXPR
;
17069 gdb_assert (prop
->data
.baton
!= NULL
);
17071 else if (attr
->form_is_ref ())
17073 struct dwarf2_cu
*target_cu
= cu
;
17074 struct die_info
*target_die
;
17075 struct attribute
*target_attr
;
17077 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17078 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17079 if (target_attr
== NULL
)
17080 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17082 if (target_attr
== NULL
)
17085 switch (target_attr
->name
)
17087 case DW_AT_location
:
17088 if (target_attr
->form_is_section_offset ())
17090 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17091 baton
->property_type
= die_type (target_die
, target_cu
);
17092 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17093 prop
->data
.baton
= baton
;
17094 prop
->kind
= PROP_LOCLIST
;
17095 gdb_assert (prop
->data
.baton
!= NULL
);
17097 else if (target_attr
->form_is_block ())
17099 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17100 baton
->property_type
= die_type (target_die
, target_cu
);
17101 baton
->locexpr
.per_cu
= cu
->per_cu
;
17102 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17103 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17104 baton
->locexpr
.is_reference
= true;
17105 prop
->data
.baton
= baton
;
17106 prop
->kind
= PROP_LOCEXPR
;
17107 gdb_assert (prop
->data
.baton
!= NULL
);
17111 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17112 "dynamic property");
17116 case DW_AT_data_member_location
:
17120 if (!handle_data_member_location (target_die
, target_cu
,
17124 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17125 baton
->property_type
= read_type_die (target_die
->parent
,
17127 baton
->offset_info
.offset
= offset
;
17128 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17129 prop
->data
.baton
= baton
;
17130 prop
->kind
= PROP_ADDR_OFFSET
;
17135 else if (attr
->form_is_constant ())
17137 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17138 prop
->kind
= PROP_CONST
;
17142 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17143 dwarf2_name (die
, cu
));
17153 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17155 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17156 struct type
*int_type
;
17158 /* Helper macro to examine the various builtin types. */
17159 #define TRY_TYPE(F) \
17160 int_type = (unsigned_p \
17161 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17162 : objfile_type (objfile)->builtin_ ## F); \
17163 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17170 TRY_TYPE (long_long
);
17174 gdb_assert_not_reached ("unable to find suitable integer type");
17180 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17182 int addr_size
= this->addr_size ();
17183 return int_type (addr_size
, unsigned_p
);
17186 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17187 present (which is valid) then compute the default type based on the
17188 compilation units address size. */
17190 static struct type
*
17191 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17193 struct type
*index_type
= die_type (die
, cu
);
17195 /* Dwarf-2 specifications explicitly allows to create subrange types
17196 without specifying a base type.
17197 In that case, the base type must be set to the type of
17198 the lower bound, upper bound or count, in that order, if any of these
17199 three attributes references an object that has a type.
17200 If no base type is found, the Dwarf-2 specifications say that
17201 a signed integer type of size equal to the size of an address should
17203 For the following C code: `extern char gdb_int [];'
17204 GCC produces an empty range DIE.
17205 FIXME: muller/2010-05-28: Possible references to object for low bound,
17206 high bound or count are not yet handled by this code. */
17207 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17208 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17213 /* Read the given DW_AT_subrange DIE. */
17215 static struct type
*
17216 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17218 struct type
*base_type
, *orig_base_type
;
17219 struct type
*range_type
;
17220 struct attribute
*attr
;
17221 struct dynamic_prop low
, high
;
17222 int low_default_is_valid
;
17223 int high_bound_is_count
= 0;
17225 ULONGEST negative_mask
;
17227 orig_base_type
= read_subrange_index_type (die
, cu
);
17229 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17230 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17231 creating the range type, but we use the result of check_typedef
17232 when examining properties of the type. */
17233 base_type
= check_typedef (orig_base_type
);
17235 /* The die_type call above may have already set the type for this DIE. */
17236 range_type
= get_die_type (die
, cu
);
17240 low
.kind
= PROP_CONST
;
17241 high
.kind
= PROP_CONST
;
17242 high
.data
.const_val
= 0;
17244 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17245 omitting DW_AT_lower_bound. */
17246 switch (cu
->language
)
17249 case language_cplus
:
17250 low
.data
.const_val
= 0;
17251 low_default_is_valid
= 1;
17253 case language_fortran
:
17254 low
.data
.const_val
= 1;
17255 low_default_is_valid
= 1;
17258 case language_objc
:
17259 case language_rust
:
17260 low
.data
.const_val
= 0;
17261 low_default_is_valid
= (cu
->header
.version
>= 4);
17265 case language_pascal
:
17266 low
.data
.const_val
= 1;
17267 low_default_is_valid
= (cu
->header
.version
>= 4);
17270 low
.data
.const_val
= 0;
17271 low_default_is_valid
= 0;
17275 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17276 if (attr
!= nullptr)
17277 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17278 else if (!low_default_is_valid
)
17279 complaint (_("Missing DW_AT_lower_bound "
17280 "- DIE at %s [in module %s]"),
17281 sect_offset_str (die
->sect_off
),
17282 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17284 struct attribute
*attr_ub
, *attr_count
;
17285 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17286 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17288 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17289 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17291 /* If bounds are constant do the final calculation here. */
17292 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17293 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17295 high_bound_is_count
= 1;
17299 if (attr_ub
!= NULL
)
17300 complaint (_("Unresolved DW_AT_upper_bound "
17301 "- DIE at %s [in module %s]"),
17302 sect_offset_str (die
->sect_off
),
17303 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17304 if (attr_count
!= NULL
)
17305 complaint (_("Unresolved DW_AT_count "
17306 "- DIE at %s [in module %s]"),
17307 sect_offset_str (die
->sect_off
),
17308 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17313 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17314 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17315 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17317 /* Normally, the DWARF producers are expected to use a signed
17318 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17319 But this is unfortunately not always the case, as witnessed
17320 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17321 is used instead. To work around that ambiguity, we treat
17322 the bounds as signed, and thus sign-extend their values, when
17323 the base type is signed. */
17325 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17326 if (low
.kind
== PROP_CONST
17327 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17328 low
.data
.const_val
|= negative_mask
;
17329 if (high
.kind
== PROP_CONST
17330 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17331 high
.data
.const_val
|= negative_mask
;
17333 /* Check for bit and byte strides. */
17334 struct dynamic_prop byte_stride_prop
;
17335 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17336 if (attr_byte_stride
!= nullptr)
17338 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17339 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17343 struct dynamic_prop bit_stride_prop
;
17344 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17345 if (attr_bit_stride
!= nullptr)
17347 /* It only makes sense to have either a bit or byte stride. */
17348 if (attr_byte_stride
!= nullptr)
17350 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17351 "- DIE at %s [in module %s]"),
17352 sect_offset_str (die
->sect_off
),
17353 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17354 attr_bit_stride
= nullptr;
17358 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17359 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17364 if (attr_byte_stride
!= nullptr
17365 || attr_bit_stride
!= nullptr)
17367 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17368 struct dynamic_prop
*stride
17369 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17372 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17373 &high
, bias
, stride
, byte_stride_p
);
17376 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17378 if (high_bound_is_count
)
17379 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17381 /* Ada expects an empty array on no boundary attributes. */
17382 if (attr
== NULL
&& cu
->language
!= language_ada
)
17383 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17385 name
= dwarf2_name (die
, cu
);
17387 TYPE_NAME (range_type
) = name
;
17389 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17390 if (attr
!= nullptr)
17391 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17393 maybe_set_alignment (cu
, die
, range_type
);
17395 set_die_type (die
, range_type
, cu
);
17397 /* set_die_type should be already done. */
17398 set_descriptive_type (range_type
, die
, cu
);
17403 static struct type
*
17404 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17408 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17410 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17412 /* In Ada, an unspecified type is typically used when the description
17413 of the type is deferred to a different unit. When encountering
17414 such a type, we treat it as a stub, and try to resolve it later on,
17416 if (cu
->language
== language_ada
)
17417 TYPE_STUB (type
) = 1;
17419 return set_die_type (die
, type
, cu
);
17422 /* Read a single die and all its descendents. Set the die's sibling
17423 field to NULL; set other fields in the die correctly, and set all
17424 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17425 location of the info_ptr after reading all of those dies. PARENT
17426 is the parent of the die in question. */
17428 static struct die_info
*
17429 read_die_and_children (const struct die_reader_specs
*reader
,
17430 const gdb_byte
*info_ptr
,
17431 const gdb_byte
**new_info_ptr
,
17432 struct die_info
*parent
)
17434 struct die_info
*die
;
17435 const gdb_byte
*cur_ptr
;
17437 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17440 *new_info_ptr
= cur_ptr
;
17443 store_in_ref_table (die
, reader
->cu
);
17445 if (die
->has_children
)
17446 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17450 *new_info_ptr
= cur_ptr
;
17453 die
->sibling
= NULL
;
17454 die
->parent
= parent
;
17458 /* Read a die, all of its descendents, and all of its siblings; set
17459 all of the fields of all of the dies correctly. Arguments are as
17460 in read_die_and_children. */
17462 static struct die_info
*
17463 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17464 const gdb_byte
*info_ptr
,
17465 const gdb_byte
**new_info_ptr
,
17466 struct die_info
*parent
)
17468 struct die_info
*first_die
, *last_sibling
;
17469 const gdb_byte
*cur_ptr
;
17471 cur_ptr
= info_ptr
;
17472 first_die
= last_sibling
= NULL
;
17476 struct die_info
*die
17477 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17481 *new_info_ptr
= cur_ptr
;
17488 last_sibling
->sibling
= die
;
17490 last_sibling
= die
;
17494 /* Read a die, all of its descendents, and all of its siblings; set
17495 all of the fields of all of the dies correctly. Arguments are as
17496 in read_die_and_children.
17497 This the main entry point for reading a DIE and all its children. */
17499 static struct die_info
*
17500 read_die_and_siblings (const struct die_reader_specs
*reader
,
17501 const gdb_byte
*info_ptr
,
17502 const gdb_byte
**new_info_ptr
,
17503 struct die_info
*parent
)
17505 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17506 new_info_ptr
, parent
);
17508 if (dwarf_die_debug
)
17510 fprintf_unfiltered (gdb_stdlog
,
17511 "Read die from %s@0x%x of %s:\n",
17512 reader
->die_section
->get_name (),
17513 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17514 bfd_get_filename (reader
->abfd
));
17515 dump_die (die
, dwarf_die_debug
);
17521 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17523 The caller is responsible for filling in the extra attributes
17524 and updating (*DIEP)->num_attrs.
17525 Set DIEP to point to a newly allocated die with its information,
17526 except for its child, sibling, and parent fields. */
17528 static const gdb_byte
*
17529 read_full_die_1 (const struct die_reader_specs
*reader
,
17530 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17531 int num_extra_attrs
)
17533 unsigned int abbrev_number
, bytes_read
, i
;
17534 struct abbrev_info
*abbrev
;
17535 struct die_info
*die
;
17536 struct dwarf2_cu
*cu
= reader
->cu
;
17537 bfd
*abfd
= reader
->abfd
;
17539 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17540 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17541 info_ptr
+= bytes_read
;
17542 if (!abbrev_number
)
17548 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17550 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17552 bfd_get_filename (abfd
));
17554 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17555 die
->sect_off
= sect_off
;
17556 die
->tag
= abbrev
->tag
;
17557 die
->abbrev
= abbrev_number
;
17558 die
->has_children
= abbrev
->has_children
;
17560 /* Make the result usable.
17561 The caller needs to update num_attrs after adding the extra
17563 die
->num_attrs
= abbrev
->num_attrs
;
17565 std::vector
<int> indexes_that_need_reprocess
;
17566 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17568 bool need_reprocess
;
17570 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17571 info_ptr
, &need_reprocess
);
17572 if (need_reprocess
)
17573 indexes_that_need_reprocess
.push_back (i
);
17576 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17577 if (attr
!= nullptr)
17578 cu
->str_offsets_base
= DW_UNSND (attr
);
17580 auto maybe_addr_base
= lookup_addr_base(die
);
17581 if (maybe_addr_base
.has_value ())
17582 cu
->addr_base
= *maybe_addr_base
;
17583 for (int index
: indexes_that_need_reprocess
)
17584 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17589 /* Read a die and all its attributes.
17590 Set DIEP to point to a newly allocated die with its information,
17591 except for its child, sibling, and parent fields. */
17593 static const gdb_byte
*
17594 read_full_die (const struct die_reader_specs
*reader
,
17595 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17597 const gdb_byte
*result
;
17599 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17601 if (dwarf_die_debug
)
17603 fprintf_unfiltered (gdb_stdlog
,
17604 "Read die from %s@0x%x of %s:\n",
17605 reader
->die_section
->get_name (),
17606 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17607 bfd_get_filename (reader
->abfd
));
17608 dump_die (*diep
, dwarf_die_debug
);
17615 /* Returns nonzero if TAG represents a type that we might generate a partial
17619 is_type_tag_for_partial (int tag
)
17624 /* Some types that would be reasonable to generate partial symbols for,
17625 that we don't at present. */
17626 case DW_TAG_array_type
:
17627 case DW_TAG_file_type
:
17628 case DW_TAG_ptr_to_member_type
:
17629 case DW_TAG_set_type
:
17630 case DW_TAG_string_type
:
17631 case DW_TAG_subroutine_type
:
17633 case DW_TAG_base_type
:
17634 case DW_TAG_class_type
:
17635 case DW_TAG_interface_type
:
17636 case DW_TAG_enumeration_type
:
17637 case DW_TAG_structure_type
:
17638 case DW_TAG_subrange_type
:
17639 case DW_TAG_typedef
:
17640 case DW_TAG_union_type
:
17647 /* Load all DIEs that are interesting for partial symbols into memory. */
17649 static struct partial_die_info
*
17650 load_partial_dies (const struct die_reader_specs
*reader
,
17651 const gdb_byte
*info_ptr
, int building_psymtab
)
17653 struct dwarf2_cu
*cu
= reader
->cu
;
17654 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17655 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17656 unsigned int bytes_read
;
17657 unsigned int load_all
= 0;
17658 int nesting_level
= 1;
17663 gdb_assert (cu
->per_cu
!= NULL
);
17664 if (cu
->per_cu
->load_all_dies
)
17668 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17672 &cu
->comp_unit_obstack
,
17673 hashtab_obstack_allocate
,
17674 dummy_obstack_deallocate
);
17678 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17680 /* A NULL abbrev means the end of a series of children. */
17681 if (abbrev
== NULL
)
17683 if (--nesting_level
== 0)
17686 info_ptr
+= bytes_read
;
17687 last_die
= parent_die
;
17688 parent_die
= parent_die
->die_parent
;
17692 /* Check for template arguments. We never save these; if
17693 they're seen, we just mark the parent, and go on our way. */
17694 if (parent_die
!= NULL
17695 && cu
->language
== language_cplus
17696 && (abbrev
->tag
== DW_TAG_template_type_param
17697 || abbrev
->tag
== DW_TAG_template_value_param
))
17699 parent_die
->has_template_arguments
= 1;
17703 /* We don't need a partial DIE for the template argument. */
17704 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17709 /* We only recurse into c++ subprograms looking for template arguments.
17710 Skip their other children. */
17712 && cu
->language
== language_cplus
17713 && parent_die
!= NULL
17714 && parent_die
->tag
== DW_TAG_subprogram
)
17716 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17720 /* Check whether this DIE is interesting enough to save. Normally
17721 we would not be interested in members here, but there may be
17722 later variables referencing them via DW_AT_specification (for
17723 static members). */
17725 && !is_type_tag_for_partial (abbrev
->tag
)
17726 && abbrev
->tag
!= DW_TAG_constant
17727 && abbrev
->tag
!= DW_TAG_enumerator
17728 && abbrev
->tag
!= DW_TAG_subprogram
17729 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17730 && abbrev
->tag
!= DW_TAG_lexical_block
17731 && abbrev
->tag
!= DW_TAG_variable
17732 && abbrev
->tag
!= DW_TAG_namespace
17733 && abbrev
->tag
!= DW_TAG_module
17734 && abbrev
->tag
!= DW_TAG_member
17735 && abbrev
->tag
!= DW_TAG_imported_unit
17736 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17738 /* Otherwise we skip to the next sibling, if any. */
17739 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17743 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17746 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17748 /* This two-pass algorithm for processing partial symbols has a
17749 high cost in cache pressure. Thus, handle some simple cases
17750 here which cover the majority of C partial symbols. DIEs
17751 which neither have specification tags in them, nor could have
17752 specification tags elsewhere pointing at them, can simply be
17753 processed and discarded.
17755 This segment is also optional; scan_partial_symbols and
17756 add_partial_symbol will handle these DIEs if we chain
17757 them in normally. When compilers which do not emit large
17758 quantities of duplicate debug information are more common,
17759 this code can probably be removed. */
17761 /* Any complete simple types at the top level (pretty much all
17762 of them, for a language without namespaces), can be processed
17764 if (parent_die
== NULL
17765 && pdi
.has_specification
== 0
17766 && pdi
.is_declaration
== 0
17767 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17768 || pdi
.tag
== DW_TAG_base_type
17769 || pdi
.tag
== DW_TAG_subrange_type
))
17771 if (building_psymtab
&& pdi
.name
!= NULL
)
17772 add_psymbol_to_list (pdi
.name
, false,
17773 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17774 psymbol_placement::STATIC
,
17775 0, cu
->language
, objfile
);
17776 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17780 /* The exception for DW_TAG_typedef with has_children above is
17781 a workaround of GCC PR debug/47510. In the case of this complaint
17782 type_name_or_error will error on such types later.
17784 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17785 it could not find the child DIEs referenced later, this is checked
17786 above. In correct DWARF DW_TAG_typedef should have no children. */
17788 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17789 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17790 "- DIE at %s [in module %s]"),
17791 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17793 /* If we're at the second level, and we're an enumerator, and
17794 our parent has no specification (meaning possibly lives in a
17795 namespace elsewhere), then we can add the partial symbol now
17796 instead of queueing it. */
17797 if (pdi
.tag
== DW_TAG_enumerator
17798 && parent_die
!= NULL
17799 && parent_die
->die_parent
== NULL
17800 && parent_die
->tag
== DW_TAG_enumeration_type
17801 && parent_die
->has_specification
== 0)
17803 if (pdi
.name
== NULL
)
17804 complaint (_("malformed enumerator DIE ignored"));
17805 else if (building_psymtab
)
17806 add_psymbol_to_list (pdi
.name
, false,
17807 VAR_DOMAIN
, LOC_CONST
, -1,
17808 cu
->language
== language_cplus
17809 ? psymbol_placement::GLOBAL
17810 : psymbol_placement::STATIC
,
17811 0, cu
->language
, objfile
);
17813 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17817 struct partial_die_info
*part_die
17818 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17820 /* We'll save this DIE so link it in. */
17821 part_die
->die_parent
= parent_die
;
17822 part_die
->die_sibling
= NULL
;
17823 part_die
->die_child
= NULL
;
17825 if (last_die
&& last_die
== parent_die
)
17826 last_die
->die_child
= part_die
;
17828 last_die
->die_sibling
= part_die
;
17830 last_die
= part_die
;
17832 if (first_die
== NULL
)
17833 first_die
= part_die
;
17835 /* Maybe add the DIE to the hash table. Not all DIEs that we
17836 find interesting need to be in the hash table, because we
17837 also have the parent/sibling/child chains; only those that we
17838 might refer to by offset later during partial symbol reading.
17840 For now this means things that might have be the target of a
17841 DW_AT_specification, DW_AT_abstract_origin, or
17842 DW_AT_extension. DW_AT_extension will refer only to
17843 namespaces; DW_AT_abstract_origin refers to functions (and
17844 many things under the function DIE, but we do not recurse
17845 into function DIEs during partial symbol reading) and
17846 possibly variables as well; DW_AT_specification refers to
17847 declarations. Declarations ought to have the DW_AT_declaration
17848 flag. It happens that GCC forgets to put it in sometimes, but
17849 only for functions, not for types.
17851 Adding more things than necessary to the hash table is harmless
17852 except for the performance cost. Adding too few will result in
17853 wasted time in find_partial_die, when we reread the compilation
17854 unit with load_all_dies set. */
17857 || abbrev
->tag
== DW_TAG_constant
17858 || abbrev
->tag
== DW_TAG_subprogram
17859 || abbrev
->tag
== DW_TAG_variable
17860 || abbrev
->tag
== DW_TAG_namespace
17861 || part_die
->is_declaration
)
17865 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17866 to_underlying (part_die
->sect_off
),
17871 /* For some DIEs we want to follow their children (if any). For C
17872 we have no reason to follow the children of structures; for other
17873 languages we have to, so that we can get at method physnames
17874 to infer fully qualified class names, for DW_AT_specification,
17875 and for C++ template arguments. For C++, we also look one level
17876 inside functions to find template arguments (if the name of the
17877 function does not already contain the template arguments).
17879 For Ada and Fortran, we need to scan the children of subprograms
17880 and lexical blocks as well because these languages allow the
17881 definition of nested entities that could be interesting for the
17882 debugger, such as nested subprograms for instance. */
17883 if (last_die
->has_children
17885 || last_die
->tag
== DW_TAG_namespace
17886 || last_die
->tag
== DW_TAG_module
17887 || last_die
->tag
== DW_TAG_enumeration_type
17888 || (cu
->language
== language_cplus
17889 && last_die
->tag
== DW_TAG_subprogram
17890 && (last_die
->name
== NULL
17891 || strchr (last_die
->name
, '<') == NULL
))
17892 || (cu
->language
!= language_c
17893 && (last_die
->tag
== DW_TAG_class_type
17894 || last_die
->tag
== DW_TAG_interface_type
17895 || last_die
->tag
== DW_TAG_structure_type
17896 || last_die
->tag
== DW_TAG_union_type
))
17897 || ((cu
->language
== language_ada
17898 || cu
->language
== language_fortran
)
17899 && (last_die
->tag
== DW_TAG_subprogram
17900 || last_die
->tag
== DW_TAG_lexical_block
))))
17903 parent_die
= last_die
;
17907 /* Otherwise we skip to the next sibling, if any. */
17908 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17910 /* Back to the top, do it again. */
17914 partial_die_info::partial_die_info (sect_offset sect_off_
,
17915 struct abbrev_info
*abbrev
)
17916 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17920 /* Read a minimal amount of information into the minimal die structure.
17921 INFO_PTR should point just after the initial uleb128 of a DIE. */
17924 partial_die_info::read (const struct die_reader_specs
*reader
,
17925 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17927 struct dwarf2_cu
*cu
= reader
->cu
;
17928 struct dwarf2_per_objfile
*dwarf2_per_objfile
17929 = cu
->per_cu
->dwarf2_per_objfile
;
17931 int has_low_pc_attr
= 0;
17932 int has_high_pc_attr
= 0;
17933 int high_pc_relative
= 0;
17935 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17936 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17938 bool need_reprocess
;
17939 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17940 info_ptr
, &need_reprocess
);
17941 /* String and address offsets that need to do the reprocessing have
17942 already been read at this point, so there is no need to wait until
17943 the loop terminates to do the reprocessing. */
17944 if (need_reprocess
)
17945 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17946 attribute
&attr
= attr_vec
[i
];
17947 /* Store the data if it is of an attribute we want to keep in a
17948 partial symbol table. */
17954 case DW_TAG_compile_unit
:
17955 case DW_TAG_partial_unit
:
17956 case DW_TAG_type_unit
:
17957 /* Compilation units have a DW_AT_name that is a filename, not
17958 a source language identifier. */
17959 case DW_TAG_enumeration_type
:
17960 case DW_TAG_enumerator
:
17961 /* These tags always have simple identifiers already; no need
17962 to canonicalize them. */
17963 name
= DW_STRING (&attr
);
17967 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17970 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
17971 &objfile
->per_bfd
->storage_obstack
);
17976 case DW_AT_linkage_name
:
17977 case DW_AT_MIPS_linkage_name
:
17978 /* Note that both forms of linkage name might appear. We
17979 assume they will be the same, and we only store the last
17981 linkage_name
= DW_STRING (&attr
);
17984 has_low_pc_attr
= 1;
17985 lowpc
= attr
.value_as_address ();
17987 case DW_AT_high_pc
:
17988 has_high_pc_attr
= 1;
17989 highpc
= attr
.value_as_address ();
17990 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17991 high_pc_relative
= 1;
17993 case DW_AT_location
:
17994 /* Support the .debug_loc offsets. */
17995 if (attr
.form_is_block ())
17997 d
.locdesc
= DW_BLOCK (&attr
);
17999 else if (attr
.form_is_section_offset ())
18001 dwarf2_complex_location_expr_complaint ();
18005 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18006 "partial symbol information");
18009 case DW_AT_external
:
18010 is_external
= DW_UNSND (&attr
);
18012 case DW_AT_declaration
:
18013 is_declaration
= DW_UNSND (&attr
);
18018 case DW_AT_abstract_origin
:
18019 case DW_AT_specification
:
18020 case DW_AT_extension
:
18021 has_specification
= 1;
18022 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18023 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18024 || cu
->per_cu
->is_dwz
);
18026 case DW_AT_sibling
:
18027 /* Ignore absolute siblings, they might point outside of
18028 the current compile unit. */
18029 if (attr
.form
== DW_FORM_ref_addr
)
18030 complaint (_("ignoring absolute DW_AT_sibling"));
18033 const gdb_byte
*buffer
= reader
->buffer
;
18034 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18035 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18037 if (sibling_ptr
< info_ptr
)
18038 complaint (_("DW_AT_sibling points backwards"));
18039 else if (sibling_ptr
> reader
->buffer_end
)
18040 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18042 sibling
= sibling_ptr
;
18045 case DW_AT_byte_size
:
18048 case DW_AT_const_value
:
18049 has_const_value
= 1;
18051 case DW_AT_calling_convention
:
18052 /* DWARF doesn't provide a way to identify a program's source-level
18053 entry point. DW_AT_calling_convention attributes are only meant
18054 to describe functions' calling conventions.
18056 However, because it's a necessary piece of information in
18057 Fortran, and before DWARF 4 DW_CC_program was the only
18058 piece of debugging information whose definition refers to
18059 a 'main program' at all, several compilers marked Fortran
18060 main programs with DW_CC_program --- even when those
18061 functions use the standard calling conventions.
18063 Although DWARF now specifies a way to provide this
18064 information, we support this practice for backward
18066 if (DW_UNSND (&attr
) == DW_CC_program
18067 && cu
->language
== language_fortran
)
18068 main_subprogram
= 1;
18071 if (DW_UNSND (&attr
) == DW_INL_inlined
18072 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18073 may_be_inlined
= 1;
18077 if (tag
== DW_TAG_imported_unit
)
18079 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18080 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18081 || cu
->per_cu
->is_dwz
);
18085 case DW_AT_main_subprogram
:
18086 main_subprogram
= DW_UNSND (&attr
);
18091 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18092 but that requires a full DIE, so instead we just
18094 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18095 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18096 + (need_ranges_base
18100 /* Value of the DW_AT_ranges attribute is the offset in the
18101 .debug_ranges section. */
18102 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18113 /* For Ada, if both the name and the linkage name appear, we prefer
18114 the latter. This lets "catch exception" work better, regardless
18115 of the order in which the name and linkage name were emitted.
18116 Really, though, this is just a workaround for the fact that gdb
18117 doesn't store both the name and the linkage name. */
18118 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18119 name
= linkage_name
;
18121 if (high_pc_relative
)
18124 if (has_low_pc_attr
&& has_high_pc_attr
)
18126 /* When using the GNU linker, .gnu.linkonce. sections are used to
18127 eliminate duplicate copies of functions and vtables and such.
18128 The linker will arbitrarily choose one and discard the others.
18129 The AT_*_pc values for such functions refer to local labels in
18130 these sections. If the section from that file was discarded, the
18131 labels are not in the output, so the relocs get a value of 0.
18132 If this is a discarded function, mark the pc bounds as invalid,
18133 so that GDB will ignore it. */
18134 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18136 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18137 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18139 complaint (_("DW_AT_low_pc %s is zero "
18140 "for DIE at %s [in module %s]"),
18141 paddress (gdbarch
, lowpc
),
18142 sect_offset_str (sect_off
),
18143 objfile_name (objfile
));
18145 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18146 else if (lowpc
>= highpc
)
18148 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18149 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18151 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18152 "for DIE at %s [in module %s]"),
18153 paddress (gdbarch
, lowpc
),
18154 paddress (gdbarch
, highpc
),
18155 sect_offset_str (sect_off
),
18156 objfile_name (objfile
));
18165 /* Find a cached partial DIE at OFFSET in CU. */
18167 struct partial_die_info
*
18168 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18170 struct partial_die_info
*lookup_die
= NULL
;
18171 struct partial_die_info
part_die (sect_off
);
18173 lookup_die
= ((struct partial_die_info
*)
18174 htab_find_with_hash (partial_dies
, &part_die
,
18175 to_underlying (sect_off
)));
18180 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18181 except in the case of .debug_types DIEs which do not reference
18182 outside their CU (they do however referencing other types via
18183 DW_FORM_ref_sig8). */
18185 static const struct cu_partial_die_info
18186 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18188 struct dwarf2_per_objfile
*dwarf2_per_objfile
18189 = cu
->per_cu
->dwarf2_per_objfile
;
18190 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18191 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18192 struct partial_die_info
*pd
= NULL
;
18194 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18195 && cu
->header
.offset_in_cu_p (sect_off
))
18197 pd
= cu
->find_partial_die (sect_off
);
18200 /* We missed recording what we needed.
18201 Load all dies and try again. */
18202 per_cu
= cu
->per_cu
;
18206 /* TUs don't reference other CUs/TUs (except via type signatures). */
18207 if (cu
->per_cu
->is_debug_types
)
18209 error (_("Dwarf Error: Type Unit at offset %s contains"
18210 " external reference to offset %s [in module %s].\n"),
18211 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18212 bfd_get_filename (objfile
->obfd
));
18214 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18215 dwarf2_per_objfile
);
18217 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18218 load_partial_comp_unit (per_cu
);
18220 per_cu
->cu
->last_used
= 0;
18221 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18224 /* If we didn't find it, and not all dies have been loaded,
18225 load them all and try again. */
18227 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18229 per_cu
->load_all_dies
= 1;
18231 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18232 THIS_CU->cu may already be in use. So we can't just free it and
18233 replace its DIEs with the ones we read in. Instead, we leave those
18234 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18235 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18237 load_partial_comp_unit (per_cu
);
18239 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18243 internal_error (__FILE__
, __LINE__
,
18244 _("could not find partial DIE %s "
18245 "in cache [from module %s]\n"),
18246 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18247 return { per_cu
->cu
, pd
};
18250 /* See if we can figure out if the class lives in a namespace. We do
18251 this by looking for a member function; its demangled name will
18252 contain namespace info, if there is any. */
18255 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18256 struct dwarf2_cu
*cu
)
18258 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18259 what template types look like, because the demangler
18260 frequently doesn't give the same name as the debug info. We
18261 could fix this by only using the demangled name to get the
18262 prefix (but see comment in read_structure_type). */
18264 struct partial_die_info
*real_pdi
;
18265 struct partial_die_info
*child_pdi
;
18267 /* If this DIE (this DIE's specification, if any) has a parent, then
18268 we should not do this. We'll prepend the parent's fully qualified
18269 name when we create the partial symbol. */
18271 real_pdi
= struct_pdi
;
18272 while (real_pdi
->has_specification
)
18274 auto res
= find_partial_die (real_pdi
->spec_offset
,
18275 real_pdi
->spec_is_dwz
, cu
);
18276 real_pdi
= res
.pdi
;
18280 if (real_pdi
->die_parent
!= NULL
)
18283 for (child_pdi
= struct_pdi
->die_child
;
18285 child_pdi
= child_pdi
->die_sibling
)
18287 if (child_pdi
->tag
== DW_TAG_subprogram
18288 && child_pdi
->linkage_name
!= NULL
)
18290 gdb::unique_xmalloc_ptr
<char> actual_class_name
18291 (language_class_name_from_physname (cu
->language_defn
,
18292 child_pdi
->linkage_name
));
18293 if (actual_class_name
!= NULL
)
18295 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18297 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
18298 actual_class_name
.get ());
18306 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18308 /* Once we've fixed up a die, there's no point in doing so again.
18309 This also avoids a memory leak if we were to call
18310 guess_partial_die_structure_name multiple times. */
18314 /* If we found a reference attribute and the DIE has no name, try
18315 to find a name in the referred to DIE. */
18317 if (name
== NULL
&& has_specification
)
18319 struct partial_die_info
*spec_die
;
18321 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18322 spec_die
= res
.pdi
;
18325 spec_die
->fixup (cu
);
18327 if (spec_die
->name
)
18329 name
= spec_die
->name
;
18331 /* Copy DW_AT_external attribute if it is set. */
18332 if (spec_die
->is_external
)
18333 is_external
= spec_die
->is_external
;
18337 /* Set default names for some unnamed DIEs. */
18339 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18340 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18342 /* If there is no parent die to provide a namespace, and there are
18343 children, see if we can determine the namespace from their linkage
18345 if (cu
->language
== language_cplus
18346 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18347 && die_parent
== NULL
18349 && (tag
== DW_TAG_class_type
18350 || tag
== DW_TAG_structure_type
18351 || tag
== DW_TAG_union_type
))
18352 guess_partial_die_structure_name (this, cu
);
18354 /* GCC might emit a nameless struct or union that has a linkage
18355 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18357 && (tag
== DW_TAG_class_type
18358 || tag
== DW_TAG_interface_type
18359 || tag
== DW_TAG_structure_type
18360 || tag
== DW_TAG_union_type
)
18361 && linkage_name
!= NULL
)
18363 gdb::unique_xmalloc_ptr
<char> demangled
18364 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18365 if (demangled
!= nullptr)
18369 /* Strip any leading namespaces/classes, keep only the base name.
18370 DW_AT_name for named DIEs does not contain the prefixes. */
18371 base
= strrchr (demangled
.get (), ':');
18372 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18375 base
= demangled
.get ();
18377 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18378 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
18385 /* Process the attributes that had to be skipped in the first round. These
18386 attributes are the ones that need str_offsets_base or addr_base attributes.
18387 They could not have been processed in the first round, because at the time
18388 the values of str_offsets_base or addr_base may not have been known. */
18389 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18390 struct attribute
*attr
)
18392 struct dwarf2_cu
*cu
= reader
->cu
;
18393 switch (attr
->form
)
18395 case DW_FORM_addrx
:
18396 case DW_FORM_GNU_addr_index
:
18397 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18400 case DW_FORM_strx1
:
18401 case DW_FORM_strx2
:
18402 case DW_FORM_strx3
:
18403 case DW_FORM_strx4
:
18404 case DW_FORM_GNU_str_index
:
18406 unsigned int str_index
= DW_UNSND (attr
);
18407 if (reader
->dwo_file
!= NULL
)
18409 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18410 DW_STRING_IS_CANONICAL (attr
) = 0;
18414 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18415 DW_STRING_IS_CANONICAL (attr
) = 0;
18420 gdb_assert_not_reached (_("Unexpected DWARF form."));
18424 /* Read an attribute value described by an attribute form. */
18426 static const gdb_byte
*
18427 read_attribute_value (const struct die_reader_specs
*reader
,
18428 struct attribute
*attr
, unsigned form
,
18429 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18430 bool *need_reprocess
)
18432 struct dwarf2_cu
*cu
= reader
->cu
;
18433 struct dwarf2_per_objfile
*dwarf2_per_objfile
18434 = cu
->per_cu
->dwarf2_per_objfile
;
18435 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18436 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18437 bfd
*abfd
= reader
->abfd
;
18438 struct comp_unit_head
*cu_header
= &cu
->header
;
18439 unsigned int bytes_read
;
18440 struct dwarf_block
*blk
;
18441 *need_reprocess
= false;
18443 attr
->form
= (enum dwarf_form
) form
;
18446 case DW_FORM_ref_addr
:
18447 if (cu
->header
.version
== 2)
18448 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
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
) = cu
->header
.read_address (abfd
, info_ptr
, &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
,
18707 /* Cover function for read_initial_length.
18708 Returns the length of the object at BUF, and stores the size of the
18709 initial length in *BYTES_READ and stores the size that offsets will be in
18711 If the initial length size is not equivalent to that specified in
18712 CU_HEADER then issue a complaint.
18713 This is useful when reading non-comp-unit headers. */
18716 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
18717 const struct comp_unit_head
*cu_header
,
18718 unsigned int *bytes_read
,
18719 unsigned int *offset_size
)
18721 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
18723 gdb_assert (cu_header
->initial_length_size
== 4
18724 || cu_header
->initial_length_size
== 8
18725 || cu_header
->initial_length_size
== 12);
18727 if (cu_header
->initial_length_size
!= *bytes_read
)
18728 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
18730 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
18734 /* Return pointer to string at section SECT offset STR_OFFSET with error
18735 reporting strings FORM_NAME and SECT_NAME. */
18737 static const char *
18738 read_indirect_string_at_offset_from (struct objfile
*objfile
,
18739 bfd
*abfd
, LONGEST str_offset
,
18740 struct dwarf2_section_info
*sect
,
18741 const char *form_name
,
18742 const char *sect_name
)
18744 sect
->read (objfile
);
18745 if (sect
->buffer
== NULL
)
18746 error (_("%s used without %s section [in module %s]"),
18747 form_name
, sect_name
, bfd_get_filename (abfd
));
18748 if (str_offset
>= sect
->size
)
18749 error (_("%s pointing outside of %s section [in module %s]"),
18750 form_name
, sect_name
, bfd_get_filename (abfd
));
18751 gdb_assert (HOST_CHAR_BIT
== 8);
18752 if (sect
->buffer
[str_offset
] == '\0')
18754 return (const char *) (sect
->buffer
+ str_offset
);
18757 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18759 static const char *
18760 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18761 bfd
*abfd
, LONGEST str_offset
)
18763 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18765 &dwarf2_per_objfile
->str
,
18766 "DW_FORM_strp", ".debug_str");
18769 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
18771 static const char *
18772 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18773 bfd
*abfd
, LONGEST str_offset
)
18775 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18777 &dwarf2_per_objfile
->line_str
,
18778 "DW_FORM_line_strp",
18779 ".debug_line_str");
18782 /* Read a string at offset STR_OFFSET in the .debug_str section from
18783 the .dwz file DWZ. Throw an error if the offset is too large. If
18784 the string consists of a single NUL byte, return NULL; otherwise
18785 return a pointer to the string. */
18787 static const char *
18788 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
18789 LONGEST str_offset
)
18791 dwz
->str
.read (objfile
);
18793 if (dwz
->str
.buffer
== NULL
)
18794 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
18795 "section [in module %s]"),
18796 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18797 if (str_offset
>= dwz
->str
.size
)
18798 error (_("DW_FORM_GNU_strp_alt pointing outside of "
18799 ".debug_str section [in module %s]"),
18800 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18801 gdb_assert (HOST_CHAR_BIT
== 8);
18802 if (dwz
->str
.buffer
[str_offset
] == '\0')
18804 return (const char *) (dwz
->str
.buffer
+ str_offset
);
18807 /* Return pointer to string at .debug_str offset as read from BUF.
18808 BUF is assumed to be in a compilation unit described by CU_HEADER.
18809 Return *BYTES_READ_PTR count of bytes read from BUF. */
18811 static const char *
18812 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18813 const gdb_byte
*buf
,
18814 const struct comp_unit_head
*cu_header
,
18815 unsigned int *bytes_read_ptr
)
18817 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18819 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
18822 /* Return pointer to string at .debug_line_str offset as read from BUF.
18823 BUF is assumed to be in a compilation unit described by CU_HEADER.
18824 Return *BYTES_READ_PTR count of bytes read from BUF. */
18826 static const char *
18827 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18828 bfd
*abfd
, const gdb_byte
*buf
,
18829 const struct comp_unit_head
*cu_header
,
18830 unsigned int *bytes_read_ptr
)
18832 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18834 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
18838 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18839 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18840 ADDR_SIZE is the size of addresses from the CU header. */
18843 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18844 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18847 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18848 bfd
*abfd
= objfile
->obfd
;
18849 const gdb_byte
*info_ptr
;
18850 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18852 dwarf2_per_objfile
->addr
.read (objfile
);
18853 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18854 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18855 objfile_name (objfile
));
18856 if (addr_base_or_zero
+ addr_index
* addr_size
18857 >= dwarf2_per_objfile
->addr
.size
)
18858 error (_("DW_FORM_addr_index pointing outside of "
18859 ".debug_addr section [in module %s]"),
18860 objfile_name (objfile
));
18861 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18862 + addr_base_or_zero
+ addr_index
* addr_size
);
18863 if (addr_size
== 4)
18864 return bfd_get_32 (abfd
, info_ptr
);
18866 return bfd_get_64 (abfd
, info_ptr
);
18869 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18872 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18874 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18875 cu
->addr_base
, cu
->header
.addr_size
);
18878 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18881 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18882 unsigned int *bytes_read
)
18884 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18885 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18887 return read_addr_index (cu
, addr_index
);
18890 /* Given an index in .debug_addr, fetch the value.
18891 NOTE: This can be called during dwarf expression evaluation,
18892 long after the debug information has been read, and thus per_cu->cu
18893 may no longer exist. */
18896 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
18897 unsigned int addr_index
)
18899 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18900 struct dwarf2_cu
*cu
= per_cu
->cu
;
18901 gdb::optional
<ULONGEST
> addr_base
;
18904 /* We need addr_base and addr_size.
18905 If we don't have PER_CU->cu, we have to get it.
18906 Nasty, but the alternative is storing the needed info in PER_CU,
18907 which at this point doesn't seem justified: it's not clear how frequently
18908 it would get used and it would increase the size of every PER_CU.
18909 Entry points like dwarf2_per_cu_addr_size do a similar thing
18910 so we're not in uncharted territory here.
18911 Alas we need to be a bit more complicated as addr_base is contained
18914 We don't need to read the entire CU(/TU).
18915 We just need the header and top level die.
18917 IWBN to use the aging mechanism to let us lazily later discard the CU.
18918 For now we skip this optimization. */
18922 addr_base
= cu
->addr_base
;
18923 addr_size
= cu
->header
.addr_size
;
18927 cutu_reader
reader (per_cu
, NULL
, 0, false);
18928 addr_base
= reader
.cu
->addr_base
;
18929 addr_size
= reader
.cu
->header
.addr_size
;
18932 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18936 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18937 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18940 static const char *
18941 read_str_index (struct dwarf2_cu
*cu
,
18942 struct dwarf2_section_info
*str_section
,
18943 struct dwarf2_section_info
*str_offsets_section
,
18944 ULONGEST str_offsets_base
, ULONGEST str_index
)
18946 struct dwarf2_per_objfile
*dwarf2_per_objfile
18947 = cu
->per_cu
->dwarf2_per_objfile
;
18948 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18949 const char *objf_name
= objfile_name (objfile
);
18950 bfd
*abfd
= objfile
->obfd
;
18951 const gdb_byte
*info_ptr
;
18952 ULONGEST str_offset
;
18953 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18955 str_section
->read (objfile
);
18956 str_offsets_section
->read (objfile
);
18957 if (str_section
->buffer
== NULL
)
18958 error (_("%s used without %s section"
18959 " in CU at offset %s [in module %s]"),
18960 form_name
, str_section
->get_name (),
18961 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18962 if (str_offsets_section
->buffer
== NULL
)
18963 error (_("%s used without %s section"
18964 " in CU at offset %s [in module %s]"),
18965 form_name
, str_section
->get_name (),
18966 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18967 info_ptr
= (str_offsets_section
->buffer
18969 + str_index
* cu
->header
.offset_size
);
18970 if (cu
->header
.offset_size
== 4)
18971 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18973 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18974 if (str_offset
>= str_section
->size
)
18975 error (_("Offset from %s pointing outside of"
18976 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18977 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18978 return (const char *) (str_section
->buffer
+ str_offset
);
18981 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18983 static const char *
18984 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18986 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18987 ? reader
->cu
->header
.addr_size
: 0;
18988 return read_str_index (reader
->cu
,
18989 &reader
->dwo_file
->sections
.str
,
18990 &reader
->dwo_file
->sections
.str_offsets
,
18991 str_offsets_base
, str_index
);
18994 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18996 static const char *
18997 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18999 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19000 const char *objf_name
= objfile_name (objfile
);
19001 static const char form_name
[] = "DW_FORM_GNU_str_index";
19002 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19004 if (!cu
->str_offsets_base
.has_value ())
19005 error (_("%s used in Fission stub without %s"
19006 " in CU at offset 0x%lx [in module %s]"),
19007 form_name
, str_offsets_attr_name
,
19008 (long) cu
->header
.offset_size
, objf_name
);
19010 return read_str_index (cu
,
19011 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19012 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19013 *cu
->str_offsets_base
, str_index
);
19016 /* Return the length of an LEB128 number in BUF. */
19019 leb128_size (const gdb_byte
*buf
)
19021 const gdb_byte
*begin
= buf
;
19027 if ((byte
& 128) == 0)
19028 return buf
- begin
;
19033 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19042 cu
->language
= language_c
;
19045 case DW_LANG_C_plus_plus
:
19046 case DW_LANG_C_plus_plus_11
:
19047 case DW_LANG_C_plus_plus_14
:
19048 cu
->language
= language_cplus
;
19051 cu
->language
= language_d
;
19053 case DW_LANG_Fortran77
:
19054 case DW_LANG_Fortran90
:
19055 case DW_LANG_Fortran95
:
19056 case DW_LANG_Fortran03
:
19057 case DW_LANG_Fortran08
:
19058 cu
->language
= language_fortran
;
19061 cu
->language
= language_go
;
19063 case DW_LANG_Mips_Assembler
:
19064 cu
->language
= language_asm
;
19066 case DW_LANG_Ada83
:
19067 case DW_LANG_Ada95
:
19068 cu
->language
= language_ada
;
19070 case DW_LANG_Modula2
:
19071 cu
->language
= language_m2
;
19073 case DW_LANG_Pascal83
:
19074 cu
->language
= language_pascal
;
19077 cu
->language
= language_objc
;
19080 case DW_LANG_Rust_old
:
19081 cu
->language
= language_rust
;
19083 case DW_LANG_Cobol74
:
19084 case DW_LANG_Cobol85
:
19086 cu
->language
= language_minimal
;
19089 cu
->language_defn
= language_def (cu
->language
);
19092 /* Return the named attribute or NULL if not there. */
19094 static struct attribute
*
19095 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19100 struct attribute
*spec
= NULL
;
19102 for (i
= 0; i
< die
->num_attrs
; ++i
)
19104 if (die
->attrs
[i
].name
== name
)
19105 return &die
->attrs
[i
];
19106 if (die
->attrs
[i
].name
== DW_AT_specification
19107 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19108 spec
= &die
->attrs
[i
];
19114 die
= follow_die_ref (die
, spec
, &cu
);
19120 /* Return the named attribute or NULL if not there,
19121 but do not follow DW_AT_specification, etc.
19122 This is for use in contexts where we're reading .debug_types dies.
19123 Following DW_AT_specification, DW_AT_abstract_origin will take us
19124 back up the chain, and we want to go down. */
19126 static struct attribute
*
19127 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19131 for (i
= 0; i
< die
->num_attrs
; ++i
)
19132 if (die
->attrs
[i
].name
== name
)
19133 return &die
->attrs
[i
];
19138 /* Return the string associated with a string-typed attribute, or NULL if it
19139 is either not found or is of an incorrect type. */
19141 static const char *
19142 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19144 struct attribute
*attr
;
19145 const char *str
= NULL
;
19147 attr
= dwarf2_attr (die
, name
, cu
);
19151 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19152 || attr
->form
== DW_FORM_string
19153 || attr
->form
== DW_FORM_strx
19154 || attr
->form
== DW_FORM_strx1
19155 || attr
->form
== DW_FORM_strx2
19156 || attr
->form
== DW_FORM_strx3
19157 || attr
->form
== DW_FORM_strx4
19158 || attr
->form
== DW_FORM_GNU_str_index
19159 || attr
->form
== DW_FORM_GNU_strp_alt
)
19160 str
= DW_STRING (attr
);
19162 complaint (_("string type expected for attribute %s for "
19163 "DIE at %s in module %s"),
19164 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19165 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19171 /* Return the dwo name or NULL if not present. If present, it is in either
19172 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19173 static const char *
19174 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19176 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19177 if (dwo_name
== nullptr)
19178 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19182 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19183 and holds a non-zero value. This function should only be used for
19184 DW_FORM_flag or DW_FORM_flag_present attributes. */
19187 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19189 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19191 return (attr
&& DW_UNSND (attr
));
19195 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19197 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19198 which value is non-zero. However, we have to be careful with
19199 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19200 (via dwarf2_flag_true_p) follows this attribute. So we may
19201 end up accidently finding a declaration attribute that belongs
19202 to a different DIE referenced by the specification attribute,
19203 even though the given DIE does not have a declaration attribute. */
19204 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19205 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19208 /* Return the die giving the specification for DIE, if there is
19209 one. *SPEC_CU is the CU containing DIE on input, and the CU
19210 containing the return value on output. If there is no
19211 specification, but there is an abstract origin, that is
19214 static struct die_info
*
19215 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19217 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19220 if (spec_attr
== NULL
)
19221 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19223 if (spec_attr
== NULL
)
19226 return follow_die_ref (die
, spec_attr
, spec_cu
);
19229 /* Stub for free_line_header to match void * callback types. */
19232 free_line_header_voidp (void *arg
)
19234 struct line_header
*lh
= (struct line_header
*) arg
;
19239 /* A convenience function to find the proper .debug_line section for a CU. */
19241 static struct dwarf2_section_info
*
19242 get_debug_line_section (struct dwarf2_cu
*cu
)
19244 struct dwarf2_section_info
*section
;
19245 struct dwarf2_per_objfile
*dwarf2_per_objfile
19246 = cu
->per_cu
->dwarf2_per_objfile
;
19248 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19250 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19251 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19252 else if (cu
->per_cu
->is_dwz
)
19254 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19256 section
= &dwz
->line
;
19259 section
= &dwarf2_per_objfile
->line
;
19264 /* Read directory or file name entry format, starting with byte of
19265 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19266 entries count and the entries themselves in the described entry
19270 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19271 bfd
*abfd
, const gdb_byte
**bufp
,
19272 struct line_header
*lh
,
19273 const struct comp_unit_head
*cu_header
,
19274 void (*callback
) (struct line_header
*lh
,
19277 unsigned int mod_time
,
19278 unsigned int length
))
19280 gdb_byte format_count
, formati
;
19281 ULONGEST data_count
, datai
;
19282 const gdb_byte
*buf
= *bufp
;
19283 const gdb_byte
*format_header_data
;
19284 unsigned int bytes_read
;
19286 format_count
= read_1_byte (abfd
, buf
);
19288 format_header_data
= buf
;
19289 for (formati
= 0; formati
< format_count
; formati
++)
19291 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19293 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19297 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19299 for (datai
= 0; datai
< data_count
; datai
++)
19301 const gdb_byte
*format
= format_header_data
;
19302 struct file_entry fe
;
19304 for (formati
= 0; formati
< format_count
; formati
++)
19306 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19307 format
+= bytes_read
;
19309 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19310 format
+= bytes_read
;
19312 gdb::optional
<const char *> string
;
19313 gdb::optional
<unsigned int> uint
;
19317 case DW_FORM_string
:
19318 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19322 case DW_FORM_line_strp
:
19323 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19330 case DW_FORM_data1
:
19331 uint
.emplace (read_1_byte (abfd
, buf
));
19335 case DW_FORM_data2
:
19336 uint
.emplace (read_2_bytes (abfd
, buf
));
19340 case DW_FORM_data4
:
19341 uint
.emplace (read_4_bytes (abfd
, buf
));
19345 case DW_FORM_data8
:
19346 uint
.emplace (read_8_bytes (abfd
, buf
));
19350 case DW_FORM_data16
:
19351 /* This is used for MD5, but file_entry does not record MD5s. */
19355 case DW_FORM_udata
:
19356 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19360 case DW_FORM_block
:
19361 /* It is valid only for DW_LNCT_timestamp which is ignored by
19366 switch (content_type
)
19369 if (string
.has_value ())
19372 case DW_LNCT_directory_index
:
19373 if (uint
.has_value ())
19374 fe
.d_index
= (dir_index
) *uint
;
19376 case DW_LNCT_timestamp
:
19377 if (uint
.has_value ())
19378 fe
.mod_time
= *uint
;
19381 if (uint
.has_value ())
19387 complaint (_("Unknown format content type %s"),
19388 pulongest (content_type
));
19392 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
19398 /* Read the statement program header starting at OFFSET in
19399 .debug_line, or .debug_line.dwo. Return a pointer
19400 to a struct line_header, allocated using xmalloc.
19401 Returns NULL if there is a problem reading the header, e.g., if it
19402 has a version we don't understand.
19404 NOTE: the strings in the include directory and file name tables of
19405 the returned object point into the dwarf line section buffer,
19406 and must not be freed. */
19408 static line_header_up
19409 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19411 const gdb_byte
*line_ptr
;
19412 unsigned int bytes_read
, offset_size
;
19414 const char *cur_dir
, *cur_file
;
19415 struct dwarf2_section_info
*section
;
19417 struct dwarf2_per_objfile
*dwarf2_per_objfile
19418 = cu
->per_cu
->dwarf2_per_objfile
;
19420 section
= get_debug_line_section (cu
);
19421 section
->read (dwarf2_per_objfile
->objfile
);
19422 if (section
->buffer
== NULL
)
19424 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19425 complaint (_("missing .debug_line.dwo section"));
19427 complaint (_("missing .debug_line section"));
19431 /* We can't do this until we know the section is non-empty.
19432 Only then do we know we have such a section. */
19433 abfd
= section
->get_bfd_owner ();
19435 /* Make sure that at least there's room for the total_length field.
19436 That could be 12 bytes long, but we're just going to fudge that. */
19437 if (to_underlying (sect_off
) + 4 >= section
->size
)
19439 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19443 line_header_up
lh (new line_header ());
19445 lh
->sect_off
= sect_off
;
19446 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
19448 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
19450 /* Read in the header. */
19452 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
19453 &bytes_read
, &offset_size
);
19454 line_ptr
+= bytes_read
;
19456 const gdb_byte
*start_here
= line_ptr
;
19458 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
19460 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19463 lh
->statement_program_end
= start_here
+ lh
->total_length
;
19464 lh
->version
= read_2_bytes (abfd
, line_ptr
);
19466 if (lh
->version
> 5)
19468 /* This is a version we don't understand. The format could have
19469 changed in ways we don't handle properly so just punt. */
19470 complaint (_("unsupported version in .debug_line section"));
19473 if (lh
->version
>= 5)
19475 gdb_byte segment_selector_size
;
19477 /* Skip address size. */
19478 read_1_byte (abfd
, line_ptr
);
19481 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
19483 if (segment_selector_size
!= 0)
19485 complaint (_("unsupported segment selector size %u "
19486 "in .debug_line section"),
19487 segment_selector_size
);
19491 lh
->header_length
= read_offset (abfd
, line_ptr
, offset_size
);
19492 line_ptr
+= offset_size
;
19493 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
19494 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
19496 if (lh
->version
>= 4)
19498 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
19502 lh
->maximum_ops_per_instruction
= 1;
19504 if (lh
->maximum_ops_per_instruction
== 0)
19506 lh
->maximum_ops_per_instruction
= 1;
19507 complaint (_("invalid maximum_ops_per_instruction "
19508 "in `.debug_line' section"));
19511 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
19513 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
19515 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
19517 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
19519 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
19521 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
19522 for (i
= 1; i
< lh
->opcode_base
; ++i
)
19524 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
19528 if (lh
->version
>= 5)
19530 /* Read directory table. */
19531 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19533 [] (struct line_header
*header
, const char *name
,
19534 dir_index d_index
, unsigned int mod_time
,
19535 unsigned int length
)
19537 header
->add_include_dir (name
);
19540 /* Read file name table. */
19541 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19543 [] (struct line_header
*header
, const char *name
,
19544 dir_index d_index
, unsigned int mod_time
,
19545 unsigned int length
)
19547 header
->add_file_name (name
, d_index
, mod_time
, length
);
19552 /* Read directory table. */
19553 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19555 line_ptr
+= bytes_read
;
19556 lh
->add_include_dir (cur_dir
);
19558 line_ptr
+= bytes_read
;
19560 /* Read file name table. */
19561 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19563 unsigned int mod_time
, length
;
19566 line_ptr
+= bytes_read
;
19567 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19568 line_ptr
+= bytes_read
;
19569 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19570 line_ptr
+= bytes_read
;
19571 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19572 line_ptr
+= bytes_read
;
19574 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
19576 line_ptr
+= bytes_read
;
19579 if (line_ptr
> (section
->buffer
+ section
->size
))
19580 complaint (_("line number info header doesn't "
19581 "fit in `.debug_line' section"));
19586 /* Subroutine of dwarf_decode_lines to simplify it.
19587 Return the file name of the psymtab for the given file_entry.
19588 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19589 If space for the result is malloc'd, *NAME_HOLDER will be set.
19590 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19592 static const char *
19593 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19594 const dwarf2_psymtab
*pst
,
19595 const char *comp_dir
,
19596 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19598 const char *include_name
= fe
.name
;
19599 const char *include_name_to_compare
= include_name
;
19600 const char *pst_filename
;
19603 const char *dir_name
= fe
.include_dir (lh
);
19605 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19606 if (!IS_ABSOLUTE_PATH (include_name
)
19607 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19609 /* Avoid creating a duplicate psymtab for PST.
19610 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19611 Before we do the comparison, however, we need to account
19612 for DIR_NAME and COMP_DIR.
19613 First prepend dir_name (if non-NULL). If we still don't
19614 have an absolute path prepend comp_dir (if non-NULL).
19615 However, the directory we record in the include-file's
19616 psymtab does not contain COMP_DIR (to match the
19617 corresponding symtab(s)).
19622 bash$ gcc -g ./hello.c
19623 include_name = "hello.c"
19625 DW_AT_comp_dir = comp_dir = "/tmp"
19626 DW_AT_name = "./hello.c"
19630 if (dir_name
!= NULL
)
19632 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19633 include_name
, (char *) NULL
));
19634 include_name
= name_holder
->get ();
19635 include_name_to_compare
= include_name
;
19637 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19639 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19640 include_name
, (char *) NULL
));
19641 include_name_to_compare
= hold_compare
.get ();
19645 pst_filename
= pst
->filename
;
19646 gdb::unique_xmalloc_ptr
<char> copied_name
;
19647 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19649 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19650 pst_filename
, (char *) NULL
));
19651 pst_filename
= copied_name
.get ();
19654 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19658 return include_name
;
19661 /* State machine to track the state of the line number program. */
19663 class lnp_state_machine
19666 /* Initialize a machine state for the start of a line number
19668 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19669 bool record_lines_p
);
19671 file_entry
*current_file ()
19673 /* lh->file_names is 0-based, but the file name numbers in the
19674 statement program are 1-based. */
19675 return m_line_header
->file_name_at (m_file
);
19678 /* Record the line in the state machine. END_SEQUENCE is true if
19679 we're processing the end of a sequence. */
19680 void record_line (bool end_sequence
);
19682 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19683 nop-out rest of the lines in this sequence. */
19684 void check_line_address (struct dwarf2_cu
*cu
,
19685 const gdb_byte
*line_ptr
,
19686 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19688 void handle_set_discriminator (unsigned int discriminator
)
19690 m_discriminator
= discriminator
;
19691 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19694 /* Handle DW_LNE_set_address. */
19695 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19698 address
+= baseaddr
;
19699 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19702 /* Handle DW_LNS_advance_pc. */
19703 void handle_advance_pc (CORE_ADDR adjust
);
19705 /* Handle a special opcode. */
19706 void handle_special_opcode (unsigned char op_code
);
19708 /* Handle DW_LNS_advance_line. */
19709 void handle_advance_line (int line_delta
)
19711 advance_line (line_delta
);
19714 /* Handle DW_LNS_set_file. */
19715 void handle_set_file (file_name_index file
);
19717 /* Handle DW_LNS_negate_stmt. */
19718 void handle_negate_stmt ()
19720 m_is_stmt
= !m_is_stmt
;
19723 /* Handle DW_LNS_const_add_pc. */
19724 void handle_const_add_pc ();
19726 /* Handle DW_LNS_fixed_advance_pc. */
19727 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19729 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19733 /* Handle DW_LNS_copy. */
19734 void handle_copy ()
19736 record_line (false);
19737 m_discriminator
= 0;
19740 /* Handle DW_LNE_end_sequence. */
19741 void handle_end_sequence ()
19743 m_currently_recording_lines
= true;
19747 /* Advance the line by LINE_DELTA. */
19748 void advance_line (int line_delta
)
19750 m_line
+= line_delta
;
19752 if (line_delta
!= 0)
19753 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19756 struct dwarf2_cu
*m_cu
;
19758 gdbarch
*m_gdbarch
;
19760 /* True if we're recording lines.
19761 Otherwise we're building partial symtabs and are just interested in
19762 finding include files mentioned by the line number program. */
19763 bool m_record_lines_p
;
19765 /* The line number header. */
19766 line_header
*m_line_header
;
19768 /* These are part of the standard DWARF line number state machine,
19769 and initialized according to the DWARF spec. */
19771 unsigned char m_op_index
= 0;
19772 /* The line table index of the current file. */
19773 file_name_index m_file
= 1;
19774 unsigned int m_line
= 1;
19776 /* These are initialized in the constructor. */
19778 CORE_ADDR m_address
;
19780 unsigned int m_discriminator
;
19782 /* Additional bits of state we need to track. */
19784 /* The last file that we called dwarf2_start_subfile for.
19785 This is only used for TLLs. */
19786 unsigned int m_last_file
= 0;
19787 /* The last file a line number was recorded for. */
19788 struct subfile
*m_last_subfile
= NULL
;
19790 /* When true, record the lines we decode. */
19791 bool m_currently_recording_lines
= false;
19793 /* The last line number that was recorded, used to coalesce
19794 consecutive entries for the same line. This can happen, for
19795 example, when discriminators are present. PR 17276. */
19796 unsigned int m_last_line
= 0;
19797 bool m_line_has_non_zero_discriminator
= false;
19801 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19803 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19804 / m_line_header
->maximum_ops_per_instruction
)
19805 * m_line_header
->minimum_instruction_length
);
19806 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19807 m_op_index
= ((m_op_index
+ adjust
)
19808 % m_line_header
->maximum_ops_per_instruction
);
19812 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19814 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19815 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19816 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19817 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19818 / m_line_header
->maximum_ops_per_instruction
)
19819 * m_line_header
->minimum_instruction_length
);
19820 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19821 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19822 % m_line_header
->maximum_ops_per_instruction
);
19824 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19825 advance_line (line_delta
);
19826 record_line (false);
19827 m_discriminator
= 0;
19831 lnp_state_machine::handle_set_file (file_name_index file
)
19835 const file_entry
*fe
= current_file ();
19837 dwarf2_debug_line_missing_file_complaint ();
19838 else if (m_record_lines_p
)
19840 const char *dir
= fe
->include_dir (m_line_header
);
19842 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19843 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19844 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19849 lnp_state_machine::handle_const_add_pc ()
19852 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19855 = (((m_op_index
+ adjust
)
19856 / m_line_header
->maximum_ops_per_instruction
)
19857 * m_line_header
->minimum_instruction_length
);
19859 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19860 m_op_index
= ((m_op_index
+ adjust
)
19861 % m_line_header
->maximum_ops_per_instruction
);
19864 /* Return non-zero if we should add LINE to the line number table.
19865 LINE is the line to add, LAST_LINE is the last line that was added,
19866 LAST_SUBFILE is the subfile for LAST_LINE.
19867 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19868 had a non-zero discriminator.
19870 We have to be careful in the presence of discriminators.
19871 E.g., for this line:
19873 for (i = 0; i < 100000; i++);
19875 clang can emit four line number entries for that one line,
19876 each with a different discriminator.
19877 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19879 However, we want gdb to coalesce all four entries into one.
19880 Otherwise the user could stepi into the middle of the line and
19881 gdb would get confused about whether the pc really was in the
19882 middle of the line.
19884 Things are further complicated by the fact that two consecutive
19885 line number entries for the same line is a heuristic used by gcc
19886 to denote the end of the prologue. So we can't just discard duplicate
19887 entries, we have to be selective about it. The heuristic we use is
19888 that we only collapse consecutive entries for the same line if at least
19889 one of those entries has a non-zero discriminator. PR 17276.
19891 Note: Addresses in the line number state machine can never go backwards
19892 within one sequence, thus this coalescing is ok. */
19895 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19896 unsigned int line
, unsigned int last_line
,
19897 int line_has_non_zero_discriminator
,
19898 struct subfile
*last_subfile
)
19900 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19902 if (line
!= last_line
)
19904 /* Same line for the same file that we've seen already.
19905 As a last check, for pr 17276, only record the line if the line
19906 has never had a non-zero discriminator. */
19907 if (!line_has_non_zero_discriminator
)
19912 /* Use the CU's builder to record line number LINE beginning at
19913 address ADDRESS in the line table of subfile SUBFILE. */
19916 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19917 unsigned int line
, CORE_ADDR address
,
19918 struct dwarf2_cu
*cu
)
19920 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19922 if (dwarf_line_debug
)
19924 fprintf_unfiltered (gdb_stdlog
,
19925 "Recording line %u, file %s, address %s\n",
19926 line
, lbasename (subfile
->name
),
19927 paddress (gdbarch
, address
));
19931 cu
->get_builder ()->record_line (subfile
, line
, addr
);
19934 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19935 Mark the end of a set of line number records.
19936 The arguments are the same as for dwarf_record_line_1.
19937 If SUBFILE is NULL the request is ignored. */
19940 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19941 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19943 if (subfile
== NULL
)
19946 if (dwarf_line_debug
)
19948 fprintf_unfiltered (gdb_stdlog
,
19949 "Finishing current line, file %s, address %s\n",
19950 lbasename (subfile
->name
),
19951 paddress (gdbarch
, address
));
19954 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
19958 lnp_state_machine::record_line (bool end_sequence
)
19960 if (dwarf_line_debug
)
19962 fprintf_unfiltered (gdb_stdlog
,
19963 "Processing actual line %u: file %u,"
19964 " address %s, is_stmt %u, discrim %u%s\n",
19966 paddress (m_gdbarch
, m_address
),
19967 m_is_stmt
, m_discriminator
,
19968 (end_sequence
? "\t(end sequence)" : ""));
19971 file_entry
*fe
= current_file ();
19974 dwarf2_debug_line_missing_file_complaint ();
19975 /* For now we ignore lines not starting on an instruction boundary.
19976 But not when processing end_sequence for compatibility with the
19977 previous version of the code. */
19978 else if (m_op_index
== 0 || end_sequence
)
19980 fe
->included_p
= 1;
19981 if (m_record_lines_p
19982 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
19984 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19987 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19988 m_currently_recording_lines
? m_cu
: nullptr);
19993 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19994 m_line_has_non_zero_discriminator
,
19997 buildsym_compunit
*builder
= m_cu
->get_builder ();
19998 dwarf_record_line_1 (m_gdbarch
,
19999 builder
->get_current_subfile (),
20001 m_currently_recording_lines
? m_cu
: nullptr);
20003 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20004 m_last_line
= m_line
;
20010 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20011 line_header
*lh
, bool record_lines_p
)
20015 m_record_lines_p
= record_lines_p
;
20016 m_line_header
= lh
;
20018 m_currently_recording_lines
= true;
20020 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20021 was a line entry for it so that the backend has a chance to adjust it
20022 and also record it in case it needs it. This is currently used by MIPS
20023 code, cf. `mips_adjust_dwarf2_line'. */
20024 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20025 m_is_stmt
= lh
->default_is_stmt
;
20026 m_discriminator
= 0;
20030 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20031 const gdb_byte
*line_ptr
,
20032 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20034 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20035 the pc range of the CU. However, we restrict the test to only ADDRESS
20036 values of zero to preserve GDB's previous behaviour which is to handle
20037 the specific case of a function being GC'd by the linker. */
20039 if (address
== 0 && address
< unrelocated_lowpc
)
20041 /* This line table is for a function which has been
20042 GCd by the linker. Ignore it. PR gdb/12528 */
20044 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20045 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20047 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20048 line_offset
, objfile_name (objfile
));
20049 m_currently_recording_lines
= false;
20050 /* Note: m_currently_recording_lines is left as false until we see
20051 DW_LNE_end_sequence. */
20055 /* Subroutine of dwarf_decode_lines to simplify it.
20056 Process the line number information in LH.
20057 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20058 program in order to set included_p for every referenced header. */
20061 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20062 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20064 const gdb_byte
*line_ptr
, *extended_end
;
20065 const gdb_byte
*line_end
;
20066 unsigned int bytes_read
, extended_len
;
20067 unsigned char op_code
, extended_op
;
20068 CORE_ADDR baseaddr
;
20069 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20070 bfd
*abfd
= objfile
->obfd
;
20071 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20072 /* True if we're recording line info (as opposed to building partial
20073 symtabs and just interested in finding include files mentioned by
20074 the line number program). */
20075 bool record_lines_p
= !decode_for_pst_p
;
20077 baseaddr
= objfile
->text_section_offset ();
20079 line_ptr
= lh
->statement_program_start
;
20080 line_end
= lh
->statement_program_end
;
20082 /* Read the statement sequences until there's nothing left. */
20083 while (line_ptr
< line_end
)
20085 /* The DWARF line number program state machine. Reset the state
20086 machine at the start of each sequence. */
20087 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20088 bool end_sequence
= false;
20090 if (record_lines_p
)
20092 /* Start a subfile for the current file of the state
20094 const file_entry
*fe
= state_machine
.current_file ();
20097 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20100 /* Decode the table. */
20101 while (line_ptr
< line_end
&& !end_sequence
)
20103 op_code
= read_1_byte (abfd
, line_ptr
);
20106 if (op_code
>= lh
->opcode_base
)
20108 /* Special opcode. */
20109 state_machine
.handle_special_opcode (op_code
);
20111 else switch (op_code
)
20113 case DW_LNS_extended_op
:
20114 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20116 line_ptr
+= bytes_read
;
20117 extended_end
= line_ptr
+ extended_len
;
20118 extended_op
= read_1_byte (abfd
, line_ptr
);
20120 switch (extended_op
)
20122 case DW_LNE_end_sequence
:
20123 state_machine
.handle_end_sequence ();
20124 end_sequence
= true;
20126 case DW_LNE_set_address
:
20129 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20130 line_ptr
+= bytes_read
;
20132 state_machine
.check_line_address (cu
, line_ptr
,
20133 lowpc
- baseaddr
, address
);
20134 state_machine
.handle_set_address (baseaddr
, address
);
20137 case DW_LNE_define_file
:
20139 const char *cur_file
;
20140 unsigned int mod_time
, length
;
20143 cur_file
= read_direct_string (abfd
, line_ptr
,
20145 line_ptr
+= bytes_read
;
20146 dindex
= (dir_index
)
20147 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20148 line_ptr
+= bytes_read
;
20150 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20151 line_ptr
+= bytes_read
;
20153 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20154 line_ptr
+= bytes_read
;
20155 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20158 case DW_LNE_set_discriminator
:
20160 /* The discriminator is not interesting to the
20161 debugger; just ignore it. We still need to
20162 check its value though:
20163 if there are consecutive entries for the same
20164 (non-prologue) line we want to coalesce them.
20167 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20168 line_ptr
+= bytes_read
;
20170 state_machine
.handle_set_discriminator (discr
);
20174 complaint (_("mangled .debug_line section"));
20177 /* Make sure that we parsed the extended op correctly. If e.g.
20178 we expected a different address size than the producer used,
20179 we may have read the wrong number of bytes. */
20180 if (line_ptr
!= extended_end
)
20182 complaint (_("mangled .debug_line section"));
20187 state_machine
.handle_copy ();
20189 case DW_LNS_advance_pc
:
20192 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20193 line_ptr
+= bytes_read
;
20195 state_machine
.handle_advance_pc (adjust
);
20198 case DW_LNS_advance_line
:
20201 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20202 line_ptr
+= bytes_read
;
20204 state_machine
.handle_advance_line (line_delta
);
20207 case DW_LNS_set_file
:
20209 file_name_index file
20210 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20212 line_ptr
+= bytes_read
;
20214 state_machine
.handle_set_file (file
);
20217 case DW_LNS_set_column
:
20218 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20219 line_ptr
+= bytes_read
;
20221 case DW_LNS_negate_stmt
:
20222 state_machine
.handle_negate_stmt ();
20224 case DW_LNS_set_basic_block
:
20226 /* Add to the address register of the state machine the
20227 address increment value corresponding to special opcode
20228 255. I.e., this value is scaled by the minimum
20229 instruction length since special opcode 255 would have
20230 scaled the increment. */
20231 case DW_LNS_const_add_pc
:
20232 state_machine
.handle_const_add_pc ();
20234 case DW_LNS_fixed_advance_pc
:
20236 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20239 state_machine
.handle_fixed_advance_pc (addr_adj
);
20244 /* Unknown standard opcode, ignore it. */
20247 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20249 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20250 line_ptr
+= bytes_read
;
20257 dwarf2_debug_line_missing_end_sequence_complaint ();
20259 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20260 in which case we still finish recording the last line). */
20261 state_machine
.record_line (true);
20265 /* Decode the Line Number Program (LNP) for the given line_header
20266 structure and CU. The actual information extracted and the type
20267 of structures created from the LNP depends on the value of PST.
20269 1. If PST is NULL, then this procedure uses the data from the program
20270 to create all necessary symbol tables, and their linetables.
20272 2. If PST is not NULL, this procedure reads the program to determine
20273 the list of files included by the unit represented by PST, and
20274 builds all the associated partial symbol tables.
20276 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20277 It is used for relative paths in the line table.
20278 NOTE: When processing partial symtabs (pst != NULL),
20279 comp_dir == pst->dirname.
20281 NOTE: It is important that psymtabs have the same file name (via strcmp)
20282 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20283 symtab we don't use it in the name of the psymtabs we create.
20284 E.g. expand_line_sal requires this when finding psymtabs to expand.
20285 A good testcase for this is mb-inline.exp.
20287 LOWPC is the lowest address in CU (or 0 if not known).
20289 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20290 for its PC<->lines mapping information. Otherwise only the filename
20291 table is read in. */
20294 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20295 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20296 CORE_ADDR lowpc
, int decode_mapping
)
20298 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20299 const int decode_for_pst_p
= (pst
!= NULL
);
20301 if (decode_mapping
)
20302 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20304 if (decode_for_pst_p
)
20306 /* Now that we're done scanning the Line Header Program, we can
20307 create the psymtab of each included file. */
20308 for (auto &file_entry
: lh
->file_names ())
20309 if (file_entry
.included_p
== 1)
20311 gdb::unique_xmalloc_ptr
<char> name_holder
;
20312 const char *include_name
=
20313 psymtab_include_file_name (lh
, file_entry
, pst
,
20314 comp_dir
, &name_holder
);
20315 if (include_name
!= NULL
)
20316 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20321 /* Make sure a symtab is created for every file, even files
20322 which contain only variables (i.e. no code with associated
20324 buildsym_compunit
*builder
= cu
->get_builder ();
20325 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20327 for (auto &fe
: lh
->file_names ())
20329 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20330 if (builder
->get_current_subfile ()->symtab
== NULL
)
20332 builder
->get_current_subfile ()->symtab
20333 = allocate_symtab (cust
,
20334 builder
->get_current_subfile ()->name
);
20336 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20341 /* Start a subfile for DWARF. FILENAME is the name of the file and
20342 DIRNAME the name of the source directory which contains FILENAME
20343 or NULL if not known.
20344 This routine tries to keep line numbers from identical absolute and
20345 relative file names in a common subfile.
20347 Using the `list' example from the GDB testsuite, which resides in
20348 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20349 of /srcdir/list0.c yields the following debugging information for list0.c:
20351 DW_AT_name: /srcdir/list0.c
20352 DW_AT_comp_dir: /compdir
20353 files.files[0].name: list0.h
20354 files.files[0].dir: /srcdir
20355 files.files[1].name: list0.c
20356 files.files[1].dir: /srcdir
20358 The line number information for list0.c has to end up in a single
20359 subfile, so that `break /srcdir/list0.c:1' works as expected.
20360 start_subfile will ensure that this happens provided that we pass the
20361 concatenation of files.files[1].dir and files.files[1].name as the
20365 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20366 const char *dirname
)
20368 gdb::unique_xmalloc_ptr
<char> copy
;
20370 /* In order not to lose the line information directory,
20371 we concatenate it to the filename when it makes sense.
20372 Note that the Dwarf3 standard says (speaking of filenames in line
20373 information): ``The directory index is ignored for file names
20374 that represent full path names''. Thus ignoring dirname in the
20375 `else' branch below isn't an issue. */
20377 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20379 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20380 filename
= copy
.get ();
20383 cu
->get_builder ()->start_subfile (filename
);
20386 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20387 buildsym_compunit constructor. */
20389 struct compunit_symtab
*
20390 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20393 gdb_assert (m_builder
== nullptr);
20395 m_builder
.reset (new struct buildsym_compunit
20396 (per_cu
->dwarf2_per_objfile
->objfile
,
20397 name
, comp_dir
, language
, low_pc
));
20399 list_in_scope
= get_builder ()->get_file_symbols ();
20401 get_builder ()->record_debugformat ("DWARF 2");
20402 get_builder ()->record_producer (producer
);
20404 processing_has_namespace_info
= false;
20406 return get_builder ()->get_compunit_symtab ();
20410 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20411 struct dwarf2_cu
*cu
)
20413 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20414 struct comp_unit_head
*cu_header
= &cu
->header
;
20416 /* NOTE drow/2003-01-30: There used to be a comment and some special
20417 code here to turn a symbol with DW_AT_external and a
20418 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20419 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20420 with some versions of binutils) where shared libraries could have
20421 relocations against symbols in their debug information - the
20422 minimal symbol would have the right address, but the debug info
20423 would not. It's no longer necessary, because we will explicitly
20424 apply relocations when we read in the debug information now. */
20426 /* A DW_AT_location attribute with no contents indicates that a
20427 variable has been optimized away. */
20428 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20430 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20434 /* Handle one degenerate form of location expression specially, to
20435 preserve GDB's previous behavior when section offsets are
20436 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20437 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20439 if (attr
->form_is_block ()
20440 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20441 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20442 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20443 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20444 && (DW_BLOCK (attr
)->size
20445 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20447 unsigned int dummy
;
20449 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20450 SET_SYMBOL_VALUE_ADDRESS
20451 (sym
, cu
->header
.read_address (objfile
->obfd
,
20452 DW_BLOCK (attr
)->data
+ 1,
20455 SET_SYMBOL_VALUE_ADDRESS
20456 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20458 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20459 fixup_symbol_section (sym
, objfile
);
20460 SET_SYMBOL_VALUE_ADDRESS
20462 SYMBOL_VALUE_ADDRESS (sym
)
20463 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20467 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20468 expression evaluator, and use LOC_COMPUTED only when necessary
20469 (i.e. when the value of a register or memory location is
20470 referenced, or a thread-local block, etc.). Then again, it might
20471 not be worthwhile. I'm assuming that it isn't unless performance
20472 or memory numbers show me otherwise. */
20474 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20476 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20477 cu
->has_loclist
= true;
20480 /* Given a pointer to a DWARF information entry, figure out if we need
20481 to make a symbol table entry for it, and if so, create a new entry
20482 and return a pointer to it.
20483 If TYPE is NULL, determine symbol type from the die, otherwise
20484 used the passed type.
20485 If SPACE is not NULL, use it to hold the new symbol. If it is
20486 NULL, allocate a new symbol on the objfile's obstack. */
20488 static struct symbol
*
20489 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20490 struct symbol
*space
)
20492 struct dwarf2_per_objfile
*dwarf2_per_objfile
20493 = cu
->per_cu
->dwarf2_per_objfile
;
20494 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20495 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20496 struct symbol
*sym
= NULL
;
20498 struct attribute
*attr
= NULL
;
20499 struct attribute
*attr2
= NULL
;
20500 CORE_ADDR baseaddr
;
20501 struct pending
**list_to_add
= NULL
;
20503 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20505 baseaddr
= objfile
->text_section_offset ();
20507 name
= dwarf2_name (die
, cu
);
20510 const char *linkagename
;
20511 int suppress_add
= 0;
20516 sym
= allocate_symbol (objfile
);
20517 OBJSTAT (objfile
, n_syms
++);
20519 /* Cache this symbol's name and the name's demangled form (if any). */
20520 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20521 linkagename
= dwarf2_physname (name
, die
, cu
);
20522 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20524 /* Fortran does not have mangling standard and the mangling does differ
20525 between gfortran, iFort etc. */
20526 if (cu
->language
== language_fortran
20527 && symbol_get_demangled_name (sym
) == NULL
)
20528 symbol_set_demangled_name (sym
,
20529 dwarf2_full_name (name
, die
, cu
),
20532 /* Default assumptions.
20533 Use the passed type or decode it from the die. */
20534 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20535 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20537 SYMBOL_TYPE (sym
) = type
;
20539 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20540 attr
= dwarf2_attr (die
,
20541 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20543 if (attr
!= nullptr)
20545 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20548 attr
= dwarf2_attr (die
,
20549 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20551 if (attr
!= nullptr)
20553 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20554 struct file_entry
*fe
;
20556 if (cu
->line_header
!= NULL
)
20557 fe
= cu
->line_header
->file_name_at (file_index
);
20562 complaint (_("file index out of range"));
20564 symbol_set_symtab (sym
, fe
->symtab
);
20570 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20571 if (attr
!= nullptr)
20575 addr
= attr
->value_as_address ();
20576 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20577 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20579 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20580 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20581 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20582 add_symbol_to_list (sym
, cu
->list_in_scope
);
20584 case DW_TAG_subprogram
:
20585 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20587 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20588 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20589 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20590 || cu
->language
== language_ada
20591 || cu
->language
== language_fortran
)
20593 /* Subprograms marked external are stored as a global symbol.
20594 Ada and Fortran subprograms, whether marked external or
20595 not, are always stored as a global symbol, because we want
20596 to be able to access them globally. For instance, we want
20597 to be able to break on a nested subprogram without having
20598 to specify the context. */
20599 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20603 list_to_add
= cu
->list_in_scope
;
20606 case DW_TAG_inlined_subroutine
:
20607 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20609 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20610 SYMBOL_INLINED (sym
) = 1;
20611 list_to_add
= cu
->list_in_scope
;
20613 case DW_TAG_template_value_param
:
20615 /* Fall through. */
20616 case DW_TAG_constant
:
20617 case DW_TAG_variable
:
20618 case DW_TAG_member
:
20619 /* Compilation with minimal debug info may result in
20620 variables with missing type entries. Change the
20621 misleading `void' type to something sensible. */
20622 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20623 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20625 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20626 /* In the case of DW_TAG_member, we should only be called for
20627 static const members. */
20628 if (die
->tag
== DW_TAG_member
)
20630 /* dwarf2_add_field uses die_is_declaration,
20631 so we do the same. */
20632 gdb_assert (die_is_declaration (die
, cu
));
20635 if (attr
!= nullptr)
20637 dwarf2_const_value (attr
, sym
, cu
);
20638 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20641 if (attr2
&& (DW_UNSND (attr2
) != 0))
20642 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20644 list_to_add
= cu
->list_in_scope
;
20648 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20649 if (attr
!= nullptr)
20651 var_decode_location (attr
, sym
, cu
);
20652 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20654 /* Fortran explicitly imports any global symbols to the local
20655 scope by DW_TAG_common_block. */
20656 if (cu
->language
== language_fortran
&& die
->parent
20657 && die
->parent
->tag
== DW_TAG_common_block
)
20660 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20661 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20662 && !dwarf2_per_objfile
->has_section_at_zero
)
20664 /* When a static variable is eliminated by the linker,
20665 the corresponding debug information is not stripped
20666 out, but the variable address is set to null;
20667 do not add such variables into symbol table. */
20669 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20671 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20672 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20673 && dwarf2_per_objfile
->can_copy
)
20675 /* A global static variable might be subject to
20676 copy relocation. We first check for a local
20677 minsym, though, because maybe the symbol was
20678 marked hidden, in which case this would not
20680 bound_minimal_symbol found
20681 = (lookup_minimal_symbol_linkage
20682 (sym
->linkage_name (), objfile
));
20683 if (found
.minsym
!= nullptr)
20684 sym
->maybe_copied
= 1;
20687 /* A variable with DW_AT_external is never static,
20688 but it may be block-scoped. */
20690 = ((cu
->list_in_scope
20691 == cu
->get_builder ()->get_file_symbols ())
20692 ? cu
->get_builder ()->get_global_symbols ()
20693 : cu
->list_in_scope
);
20696 list_to_add
= cu
->list_in_scope
;
20700 /* We do not know the address of this symbol.
20701 If it is an external symbol and we have type information
20702 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20703 The address of the variable will then be determined from
20704 the minimal symbol table whenever the variable is
20706 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20708 /* Fortran explicitly imports any global symbols to the local
20709 scope by DW_TAG_common_block. */
20710 if (cu
->language
== language_fortran
&& die
->parent
20711 && die
->parent
->tag
== DW_TAG_common_block
)
20713 /* SYMBOL_CLASS doesn't matter here because
20714 read_common_block is going to reset it. */
20716 list_to_add
= cu
->list_in_scope
;
20718 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20719 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20721 /* A variable with DW_AT_external is never static, but it
20722 may be block-scoped. */
20724 = ((cu
->list_in_scope
20725 == cu
->get_builder ()->get_file_symbols ())
20726 ? cu
->get_builder ()->get_global_symbols ()
20727 : cu
->list_in_scope
);
20729 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20731 else if (!die_is_declaration (die
, cu
))
20733 /* Use the default LOC_OPTIMIZED_OUT class. */
20734 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20736 list_to_add
= cu
->list_in_scope
;
20740 case DW_TAG_formal_parameter
:
20742 /* If we are inside a function, mark this as an argument. If
20743 not, we might be looking at an argument to an inlined function
20744 when we do not have enough information to show inlined frames;
20745 pretend it's a local variable in that case so that the user can
20747 struct context_stack
*curr
20748 = cu
->get_builder ()->get_current_context_stack ();
20749 if (curr
!= nullptr && curr
->name
!= nullptr)
20750 SYMBOL_IS_ARGUMENT (sym
) = 1;
20751 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20752 if (attr
!= nullptr)
20754 var_decode_location (attr
, sym
, cu
);
20756 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20757 if (attr
!= nullptr)
20759 dwarf2_const_value (attr
, sym
, cu
);
20762 list_to_add
= cu
->list_in_scope
;
20765 case DW_TAG_unspecified_parameters
:
20766 /* From varargs functions; gdb doesn't seem to have any
20767 interest in this information, so just ignore it for now.
20770 case DW_TAG_template_type_param
:
20772 /* Fall through. */
20773 case DW_TAG_class_type
:
20774 case DW_TAG_interface_type
:
20775 case DW_TAG_structure_type
:
20776 case DW_TAG_union_type
:
20777 case DW_TAG_set_type
:
20778 case DW_TAG_enumeration_type
:
20779 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20780 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20783 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20784 really ever be static objects: otherwise, if you try
20785 to, say, break of a class's method and you're in a file
20786 which doesn't mention that class, it won't work unless
20787 the check for all static symbols in lookup_symbol_aux
20788 saves you. See the OtherFileClass tests in
20789 gdb.c++/namespace.exp. */
20793 buildsym_compunit
*builder
= cu
->get_builder ();
20795 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20796 && cu
->language
== language_cplus
20797 ? builder
->get_global_symbols ()
20798 : cu
->list_in_scope
);
20800 /* The semantics of C++ state that "struct foo {
20801 ... }" also defines a typedef for "foo". */
20802 if (cu
->language
== language_cplus
20803 || cu
->language
== language_ada
20804 || cu
->language
== language_d
20805 || cu
->language
== language_rust
)
20807 /* The symbol's name is already allocated along
20808 with this objfile, so we don't need to
20809 duplicate it for the type. */
20810 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20811 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20816 case DW_TAG_typedef
:
20817 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20818 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20819 list_to_add
= cu
->list_in_scope
;
20821 case DW_TAG_base_type
:
20822 case DW_TAG_subrange_type
:
20823 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20824 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20825 list_to_add
= cu
->list_in_scope
;
20827 case DW_TAG_enumerator
:
20828 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20829 if (attr
!= nullptr)
20831 dwarf2_const_value (attr
, sym
, cu
);
20834 /* NOTE: carlton/2003-11-10: See comment above in the
20835 DW_TAG_class_type, etc. block. */
20838 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20839 && cu
->language
== language_cplus
20840 ? cu
->get_builder ()->get_global_symbols ()
20841 : cu
->list_in_scope
);
20844 case DW_TAG_imported_declaration
:
20845 case DW_TAG_namespace
:
20846 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20847 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20849 case DW_TAG_module
:
20850 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20851 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20852 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20854 case DW_TAG_common_block
:
20855 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20856 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20857 add_symbol_to_list (sym
, cu
->list_in_scope
);
20860 /* Not a tag we recognize. Hopefully we aren't processing
20861 trash data, but since we must specifically ignore things
20862 we don't recognize, there is nothing else we should do at
20864 complaint (_("unsupported tag: '%s'"),
20865 dwarf_tag_name (die
->tag
));
20871 sym
->hash_next
= objfile
->template_symbols
;
20872 objfile
->template_symbols
= sym
;
20873 list_to_add
= NULL
;
20876 if (list_to_add
!= NULL
)
20877 add_symbol_to_list (sym
, list_to_add
);
20879 /* For the benefit of old versions of GCC, check for anonymous
20880 namespaces based on the demangled name. */
20881 if (!cu
->processing_has_namespace_info
20882 && cu
->language
== language_cplus
)
20883 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20888 /* Given an attr with a DW_FORM_dataN value in host byte order,
20889 zero-extend it as appropriate for the symbol's type. The DWARF
20890 standard (v4) is not entirely clear about the meaning of using
20891 DW_FORM_dataN for a constant with a signed type, where the type is
20892 wider than the data. The conclusion of a discussion on the DWARF
20893 list was that this is unspecified. We choose to always zero-extend
20894 because that is the interpretation long in use by GCC. */
20897 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20898 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20900 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20901 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20902 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20903 LONGEST l
= DW_UNSND (attr
);
20905 if (bits
< sizeof (*value
) * 8)
20907 l
&= ((LONGEST
) 1 << bits
) - 1;
20910 else if (bits
== sizeof (*value
) * 8)
20914 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20915 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20922 /* Read a constant value from an attribute. Either set *VALUE, or if
20923 the value does not fit in *VALUE, set *BYTES - either already
20924 allocated on the objfile obstack, or newly allocated on OBSTACK,
20925 or, set *BATON, if we translated the constant to a location
20929 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20930 const char *name
, struct obstack
*obstack
,
20931 struct dwarf2_cu
*cu
,
20932 LONGEST
*value
, const gdb_byte
**bytes
,
20933 struct dwarf2_locexpr_baton
**baton
)
20935 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20936 struct comp_unit_head
*cu_header
= &cu
->header
;
20937 struct dwarf_block
*blk
;
20938 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20939 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20945 switch (attr
->form
)
20948 case DW_FORM_addrx
:
20949 case DW_FORM_GNU_addr_index
:
20953 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20954 dwarf2_const_value_length_mismatch_complaint (name
,
20955 cu_header
->addr_size
,
20956 TYPE_LENGTH (type
));
20957 /* Symbols of this form are reasonably rare, so we just
20958 piggyback on the existing location code rather than writing
20959 a new implementation of symbol_computed_ops. */
20960 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20961 (*baton
)->per_cu
= cu
->per_cu
;
20962 gdb_assert ((*baton
)->per_cu
);
20964 (*baton
)->size
= 2 + cu_header
->addr_size
;
20965 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20966 (*baton
)->data
= data
;
20968 data
[0] = DW_OP_addr
;
20969 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20970 byte_order
, DW_ADDR (attr
));
20971 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20974 case DW_FORM_string
:
20977 case DW_FORM_GNU_str_index
:
20978 case DW_FORM_GNU_strp_alt
:
20979 /* DW_STRING is already allocated on the objfile obstack, point
20981 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20983 case DW_FORM_block1
:
20984 case DW_FORM_block2
:
20985 case DW_FORM_block4
:
20986 case DW_FORM_block
:
20987 case DW_FORM_exprloc
:
20988 case DW_FORM_data16
:
20989 blk
= DW_BLOCK (attr
);
20990 if (TYPE_LENGTH (type
) != blk
->size
)
20991 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20992 TYPE_LENGTH (type
));
20993 *bytes
= blk
->data
;
20996 /* The DW_AT_const_value attributes are supposed to carry the
20997 symbol's value "represented as it would be on the target
20998 architecture." By the time we get here, it's already been
20999 converted to host endianness, so we just need to sign- or
21000 zero-extend it as appropriate. */
21001 case DW_FORM_data1
:
21002 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21004 case DW_FORM_data2
:
21005 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21007 case DW_FORM_data4
:
21008 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21010 case DW_FORM_data8
:
21011 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21014 case DW_FORM_sdata
:
21015 case DW_FORM_implicit_const
:
21016 *value
= DW_SND (attr
);
21019 case DW_FORM_udata
:
21020 *value
= DW_UNSND (attr
);
21024 complaint (_("unsupported const value attribute form: '%s'"),
21025 dwarf_form_name (attr
->form
));
21032 /* Copy constant value from an attribute to a symbol. */
21035 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21036 struct dwarf2_cu
*cu
)
21038 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21040 const gdb_byte
*bytes
;
21041 struct dwarf2_locexpr_baton
*baton
;
21043 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21044 sym
->print_name (),
21045 &objfile
->objfile_obstack
, cu
,
21046 &value
, &bytes
, &baton
);
21050 SYMBOL_LOCATION_BATON (sym
) = baton
;
21051 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21053 else if (bytes
!= NULL
)
21055 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21056 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21060 SYMBOL_VALUE (sym
) = value
;
21061 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21065 /* Return the type of the die in question using its DW_AT_type attribute. */
21067 static struct type
*
21068 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21070 struct attribute
*type_attr
;
21072 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21075 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21076 /* A missing DW_AT_type represents a void type. */
21077 return objfile_type (objfile
)->builtin_void
;
21080 return lookup_die_type (die
, type_attr
, cu
);
21083 /* True iff CU's producer generates GNAT Ada auxiliary information
21084 that allows to find parallel types through that information instead
21085 of having to do expensive parallel lookups by type name. */
21088 need_gnat_info (struct dwarf2_cu
*cu
)
21090 /* Assume that the Ada compiler was GNAT, which always produces
21091 the auxiliary information. */
21092 return (cu
->language
== language_ada
);
21095 /* Return the auxiliary type of the die in question using its
21096 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21097 attribute is not present. */
21099 static struct type
*
21100 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21102 struct attribute
*type_attr
;
21104 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21108 return lookup_die_type (die
, type_attr
, cu
);
21111 /* If DIE has a descriptive_type attribute, then set the TYPE's
21112 descriptive type accordingly. */
21115 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21116 struct dwarf2_cu
*cu
)
21118 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21120 if (descriptive_type
)
21122 ALLOCATE_GNAT_AUX_TYPE (type
);
21123 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21127 /* Return the containing type of the die in question using its
21128 DW_AT_containing_type attribute. */
21130 static struct type
*
21131 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21133 struct attribute
*type_attr
;
21134 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21136 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21138 error (_("Dwarf Error: Problem turning containing type into gdb type "
21139 "[in module %s]"), objfile_name (objfile
));
21141 return lookup_die_type (die
, type_attr
, cu
);
21144 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21146 static struct type
*
21147 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21149 struct dwarf2_per_objfile
*dwarf2_per_objfile
21150 = cu
->per_cu
->dwarf2_per_objfile
;
21151 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21154 std::string message
21155 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21156 objfile_name (objfile
),
21157 sect_offset_str (cu
->header
.sect_off
),
21158 sect_offset_str (die
->sect_off
));
21159 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21161 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21164 /* Look up the type of DIE in CU using its type attribute ATTR.
21165 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21166 DW_AT_containing_type.
21167 If there is no type substitute an error marker. */
21169 static struct type
*
21170 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21171 struct dwarf2_cu
*cu
)
21173 struct dwarf2_per_objfile
*dwarf2_per_objfile
21174 = cu
->per_cu
->dwarf2_per_objfile
;
21175 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21176 struct type
*this_type
;
21178 gdb_assert (attr
->name
== DW_AT_type
21179 || attr
->name
== DW_AT_GNAT_descriptive_type
21180 || attr
->name
== DW_AT_containing_type
);
21182 /* First see if we have it cached. */
21184 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21186 struct dwarf2_per_cu_data
*per_cu
;
21187 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21189 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21190 dwarf2_per_objfile
);
21191 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21193 else if (attr
->form_is_ref ())
21195 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21197 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21199 else if (attr
->form
== DW_FORM_ref_sig8
)
21201 ULONGEST signature
= DW_SIGNATURE (attr
);
21203 return get_signatured_type (die
, signature
, cu
);
21207 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21208 " at %s [in module %s]"),
21209 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21210 objfile_name (objfile
));
21211 return build_error_marker_type (cu
, die
);
21214 /* If not cached we need to read it in. */
21216 if (this_type
== NULL
)
21218 struct die_info
*type_die
= NULL
;
21219 struct dwarf2_cu
*type_cu
= cu
;
21221 if (attr
->form_is_ref ())
21222 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21223 if (type_die
== NULL
)
21224 return build_error_marker_type (cu
, die
);
21225 /* If we find the type now, it's probably because the type came
21226 from an inter-CU reference and the type's CU got expanded before
21228 this_type
= read_type_die (type_die
, type_cu
);
21231 /* If we still don't have a type use an error marker. */
21233 if (this_type
== NULL
)
21234 return build_error_marker_type (cu
, die
);
21239 /* Return the type in DIE, CU.
21240 Returns NULL for invalid types.
21242 This first does a lookup in die_type_hash,
21243 and only reads the die in if necessary.
21245 NOTE: This can be called when reading in partial or full symbols. */
21247 static struct type
*
21248 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21250 struct type
*this_type
;
21252 this_type
= get_die_type (die
, cu
);
21256 return read_type_die_1 (die
, cu
);
21259 /* Read the type in DIE, CU.
21260 Returns NULL for invalid types. */
21262 static struct type
*
21263 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21265 struct type
*this_type
= NULL
;
21269 case DW_TAG_class_type
:
21270 case DW_TAG_interface_type
:
21271 case DW_TAG_structure_type
:
21272 case DW_TAG_union_type
:
21273 this_type
= read_structure_type (die
, cu
);
21275 case DW_TAG_enumeration_type
:
21276 this_type
= read_enumeration_type (die
, cu
);
21278 case DW_TAG_subprogram
:
21279 case DW_TAG_subroutine_type
:
21280 case DW_TAG_inlined_subroutine
:
21281 this_type
= read_subroutine_type (die
, cu
);
21283 case DW_TAG_array_type
:
21284 this_type
= read_array_type (die
, cu
);
21286 case DW_TAG_set_type
:
21287 this_type
= read_set_type (die
, cu
);
21289 case DW_TAG_pointer_type
:
21290 this_type
= read_tag_pointer_type (die
, cu
);
21292 case DW_TAG_ptr_to_member_type
:
21293 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21295 case DW_TAG_reference_type
:
21296 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21298 case DW_TAG_rvalue_reference_type
:
21299 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21301 case DW_TAG_const_type
:
21302 this_type
= read_tag_const_type (die
, cu
);
21304 case DW_TAG_volatile_type
:
21305 this_type
= read_tag_volatile_type (die
, cu
);
21307 case DW_TAG_restrict_type
:
21308 this_type
= read_tag_restrict_type (die
, cu
);
21310 case DW_TAG_string_type
:
21311 this_type
= read_tag_string_type (die
, cu
);
21313 case DW_TAG_typedef
:
21314 this_type
= read_typedef (die
, cu
);
21316 case DW_TAG_subrange_type
:
21317 this_type
= read_subrange_type (die
, cu
);
21319 case DW_TAG_base_type
:
21320 this_type
= read_base_type (die
, cu
);
21322 case DW_TAG_unspecified_type
:
21323 this_type
= read_unspecified_type (die
, cu
);
21325 case DW_TAG_namespace
:
21326 this_type
= read_namespace_type (die
, cu
);
21328 case DW_TAG_module
:
21329 this_type
= read_module_type (die
, cu
);
21331 case DW_TAG_atomic_type
:
21332 this_type
= read_tag_atomic_type (die
, cu
);
21335 complaint (_("unexpected tag in read_type_die: '%s'"),
21336 dwarf_tag_name (die
->tag
));
21343 /* See if we can figure out if the class lives in a namespace. We do
21344 this by looking for a member function; its demangled name will
21345 contain namespace info, if there is any.
21346 Return the computed name or NULL.
21347 Space for the result is allocated on the objfile's obstack.
21348 This is the full-die version of guess_partial_die_structure_name.
21349 In this case we know DIE has no useful parent. */
21351 static const char *
21352 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21354 struct die_info
*spec_die
;
21355 struct dwarf2_cu
*spec_cu
;
21356 struct die_info
*child
;
21357 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21360 spec_die
= die_specification (die
, &spec_cu
);
21361 if (spec_die
!= NULL
)
21367 for (child
= die
->child
;
21369 child
= child
->sibling
)
21371 if (child
->tag
== DW_TAG_subprogram
)
21373 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21375 if (linkage_name
!= NULL
)
21377 gdb::unique_xmalloc_ptr
<char> actual_name
21378 (language_class_name_from_physname (cu
->language_defn
,
21380 const char *name
= NULL
;
21382 if (actual_name
!= NULL
)
21384 const char *die_name
= dwarf2_name (die
, cu
);
21386 if (die_name
!= NULL
21387 && strcmp (die_name
, actual_name
.get ()) != 0)
21389 /* Strip off the class name from the full name.
21390 We want the prefix. */
21391 int die_name_len
= strlen (die_name
);
21392 int actual_name_len
= strlen (actual_name
.get ());
21393 const char *ptr
= actual_name
.get ();
21395 /* Test for '::' as a sanity check. */
21396 if (actual_name_len
> die_name_len
+ 2
21397 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21398 name
= obstack_strndup (
21399 &objfile
->per_bfd
->storage_obstack
,
21400 ptr
, actual_name_len
- die_name_len
- 2);
21411 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21412 prefix part in such case. See
21413 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21415 static const char *
21416 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21418 struct attribute
*attr
;
21421 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21422 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21425 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21428 attr
= dw2_linkage_name_attr (die
, cu
);
21429 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21432 /* dwarf2_name had to be already called. */
21433 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21435 /* Strip the base name, keep any leading namespaces/classes. */
21436 base
= strrchr (DW_STRING (attr
), ':');
21437 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21440 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21441 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21443 &base
[-1] - DW_STRING (attr
));
21446 /* Return the name of the namespace/class that DIE is defined within,
21447 or "" if we can't tell. The caller should not xfree the result.
21449 For example, if we're within the method foo() in the following
21459 then determine_prefix on foo's die will return "N::C". */
21461 static const char *
21462 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21464 struct dwarf2_per_objfile
*dwarf2_per_objfile
21465 = cu
->per_cu
->dwarf2_per_objfile
;
21466 struct die_info
*parent
, *spec_die
;
21467 struct dwarf2_cu
*spec_cu
;
21468 struct type
*parent_type
;
21469 const char *retval
;
21471 if (cu
->language
!= language_cplus
21472 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21473 && cu
->language
!= language_rust
)
21476 retval
= anonymous_struct_prefix (die
, cu
);
21480 /* We have to be careful in the presence of DW_AT_specification.
21481 For example, with GCC 3.4, given the code
21485 // Definition of N::foo.
21489 then we'll have a tree of DIEs like this:
21491 1: DW_TAG_compile_unit
21492 2: DW_TAG_namespace // N
21493 3: DW_TAG_subprogram // declaration of N::foo
21494 4: DW_TAG_subprogram // definition of N::foo
21495 DW_AT_specification // refers to die #3
21497 Thus, when processing die #4, we have to pretend that we're in
21498 the context of its DW_AT_specification, namely the contex of die
21501 spec_die
= die_specification (die
, &spec_cu
);
21502 if (spec_die
== NULL
)
21503 parent
= die
->parent
;
21506 parent
= spec_die
->parent
;
21510 if (parent
== NULL
)
21512 else if (parent
->building_fullname
)
21515 const char *parent_name
;
21517 /* It has been seen on RealView 2.2 built binaries,
21518 DW_TAG_template_type_param types actually _defined_ as
21519 children of the parent class:
21522 template class <class Enum> Class{};
21523 Class<enum E> class_e;
21525 1: DW_TAG_class_type (Class)
21526 2: DW_TAG_enumeration_type (E)
21527 3: DW_TAG_enumerator (enum1:0)
21528 3: DW_TAG_enumerator (enum2:1)
21530 2: DW_TAG_template_type_param
21531 DW_AT_type DW_FORM_ref_udata (E)
21533 Besides being broken debug info, it can put GDB into an
21534 infinite loop. Consider:
21536 When we're building the full name for Class<E>, we'll start
21537 at Class, and go look over its template type parameters,
21538 finding E. We'll then try to build the full name of E, and
21539 reach here. We're now trying to build the full name of E,
21540 and look over the parent DIE for containing scope. In the
21541 broken case, if we followed the parent DIE of E, we'd again
21542 find Class, and once again go look at its template type
21543 arguments, etc., etc. Simply don't consider such parent die
21544 as source-level parent of this die (it can't be, the language
21545 doesn't allow it), and break the loop here. */
21546 name
= dwarf2_name (die
, cu
);
21547 parent_name
= dwarf2_name (parent
, cu
);
21548 complaint (_("template param type '%s' defined within parent '%s'"),
21549 name
? name
: "<unknown>",
21550 parent_name
? parent_name
: "<unknown>");
21554 switch (parent
->tag
)
21556 case DW_TAG_namespace
:
21557 parent_type
= read_type_die (parent
, cu
);
21558 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21559 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21560 Work around this problem here. */
21561 if (cu
->language
== language_cplus
21562 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21564 /* We give a name to even anonymous namespaces. */
21565 return TYPE_NAME (parent_type
);
21566 case DW_TAG_class_type
:
21567 case DW_TAG_interface_type
:
21568 case DW_TAG_structure_type
:
21569 case DW_TAG_union_type
:
21570 case DW_TAG_module
:
21571 parent_type
= read_type_die (parent
, cu
);
21572 if (TYPE_NAME (parent_type
) != NULL
)
21573 return TYPE_NAME (parent_type
);
21575 /* An anonymous structure is only allowed non-static data
21576 members; no typedefs, no member functions, et cetera.
21577 So it does not need a prefix. */
21579 case DW_TAG_compile_unit
:
21580 case DW_TAG_partial_unit
:
21581 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21582 if (cu
->language
== language_cplus
21583 && !dwarf2_per_objfile
->types
.empty ()
21584 && die
->child
!= NULL
21585 && (die
->tag
== DW_TAG_class_type
21586 || die
->tag
== DW_TAG_structure_type
21587 || die
->tag
== DW_TAG_union_type
))
21589 const char *name
= guess_full_die_structure_name (die
, cu
);
21594 case DW_TAG_subprogram
:
21595 /* Nested subroutines in Fortran get a prefix with the name
21596 of the parent's subroutine. */
21597 if (cu
->language
== language_fortran
)
21599 if ((die
->tag
== DW_TAG_subprogram
)
21600 && (dwarf2_name (parent
, cu
) != NULL
))
21601 return dwarf2_name (parent
, cu
);
21603 return determine_prefix (parent
, cu
);
21604 case DW_TAG_enumeration_type
:
21605 parent_type
= read_type_die (parent
, cu
);
21606 if (TYPE_DECLARED_CLASS (parent_type
))
21608 if (TYPE_NAME (parent_type
) != NULL
)
21609 return TYPE_NAME (parent_type
);
21612 /* Fall through. */
21614 return determine_prefix (parent
, cu
);
21618 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21619 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21620 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21621 an obconcat, otherwise allocate storage for the result. The CU argument is
21622 used to determine the language and hence, the appropriate separator. */
21624 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21627 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21628 int physname
, struct dwarf2_cu
*cu
)
21630 const char *lead
= "";
21633 if (suffix
== NULL
|| suffix
[0] == '\0'
21634 || prefix
== NULL
|| prefix
[0] == '\0')
21636 else if (cu
->language
== language_d
)
21638 /* For D, the 'main' function could be defined in any module, but it
21639 should never be prefixed. */
21640 if (strcmp (suffix
, "D main") == 0)
21648 else if (cu
->language
== language_fortran
&& physname
)
21650 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21651 DW_AT_MIPS_linkage_name is preferred and used instead. */
21659 if (prefix
== NULL
)
21661 if (suffix
== NULL
)
21668 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21670 strcpy (retval
, lead
);
21671 strcat (retval
, prefix
);
21672 strcat (retval
, sep
);
21673 strcat (retval
, suffix
);
21678 /* We have an obstack. */
21679 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21683 /* Return sibling of die, NULL if no sibling. */
21685 static struct die_info
*
21686 sibling_die (struct die_info
*die
)
21688 return die
->sibling
;
21691 /* Get name of a die, return NULL if not found. */
21693 static const char *
21694 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21695 struct obstack
*obstack
)
21697 if (name
&& cu
->language
== language_cplus
)
21699 std::string canon_name
= cp_canonicalize_string (name
);
21701 if (!canon_name
.empty ())
21703 if (canon_name
!= name
)
21704 name
= obstack_strdup (obstack
, canon_name
);
21711 /* Get name of a die, return NULL if not found.
21712 Anonymous namespaces are converted to their magic string. */
21714 static const char *
21715 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21717 struct attribute
*attr
;
21718 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21720 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21721 if ((!attr
|| !DW_STRING (attr
))
21722 && die
->tag
!= DW_TAG_namespace
21723 && die
->tag
!= DW_TAG_class_type
21724 && die
->tag
!= DW_TAG_interface_type
21725 && die
->tag
!= DW_TAG_structure_type
21726 && die
->tag
!= DW_TAG_union_type
)
21731 case DW_TAG_compile_unit
:
21732 case DW_TAG_partial_unit
:
21733 /* Compilation units have a DW_AT_name that is a filename, not
21734 a source language identifier. */
21735 case DW_TAG_enumeration_type
:
21736 case DW_TAG_enumerator
:
21737 /* These tags always have simple identifiers already; no need
21738 to canonicalize them. */
21739 return DW_STRING (attr
);
21741 case DW_TAG_namespace
:
21742 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21743 return DW_STRING (attr
);
21744 return CP_ANONYMOUS_NAMESPACE_STR
;
21746 case DW_TAG_class_type
:
21747 case DW_TAG_interface_type
:
21748 case DW_TAG_structure_type
:
21749 case DW_TAG_union_type
:
21750 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21751 structures or unions. These were of the form "._%d" in GCC 4.1,
21752 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21753 and GCC 4.4. We work around this problem by ignoring these. */
21754 if (attr
&& DW_STRING (attr
)
21755 && (startswith (DW_STRING (attr
), "._")
21756 || startswith (DW_STRING (attr
), "<anonymous")))
21759 /* GCC might emit a nameless typedef that has a linkage name. See
21760 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21761 if (!attr
|| DW_STRING (attr
) == NULL
)
21763 attr
= dw2_linkage_name_attr (die
, cu
);
21764 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21767 /* Avoid demangling DW_STRING (attr) the second time on a second
21768 call for the same DIE. */
21769 if (!DW_STRING_IS_CANONICAL (attr
))
21771 gdb::unique_xmalloc_ptr
<char> demangled
21772 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21776 /* FIXME: we already did this for the partial symbol... */
21778 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
21780 DW_STRING_IS_CANONICAL (attr
) = 1;
21782 /* Strip any leading namespaces/classes, keep only the base name.
21783 DW_AT_name for named DIEs does not contain the prefixes. */
21784 base
= strrchr (DW_STRING (attr
), ':');
21785 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21788 return DW_STRING (attr
);
21797 if (!DW_STRING_IS_CANONICAL (attr
))
21800 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21801 &objfile
->per_bfd
->storage_obstack
);
21802 DW_STRING_IS_CANONICAL (attr
) = 1;
21804 return DW_STRING (attr
);
21807 /* Return the die that this die in an extension of, or NULL if there
21808 is none. *EXT_CU is the CU containing DIE on input, and the CU
21809 containing the return value on output. */
21811 static struct die_info
*
21812 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21814 struct attribute
*attr
;
21816 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21820 return follow_die_ref (die
, attr
, ext_cu
);
21823 /* A convenience function that returns an "unknown" DWARF name,
21824 including the value of V. STR is the name of the entity being
21825 printed, e.g., "TAG". */
21827 static const char *
21828 dwarf_unknown (const char *str
, unsigned v
)
21830 char *cell
= get_print_cell ();
21831 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21835 /* Convert a DIE tag into its string name. */
21837 static const char *
21838 dwarf_tag_name (unsigned tag
)
21840 const char *name
= get_DW_TAG_name (tag
);
21843 return dwarf_unknown ("TAG", tag
);
21848 /* Convert a DWARF attribute code into its string name. */
21850 static const char *
21851 dwarf_attr_name (unsigned attr
)
21855 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21856 if (attr
== DW_AT_MIPS_fde
)
21857 return "DW_AT_MIPS_fde";
21859 if (attr
== DW_AT_HP_block_index
)
21860 return "DW_AT_HP_block_index";
21863 name
= get_DW_AT_name (attr
);
21866 return dwarf_unknown ("AT", attr
);
21871 /* Convert a DWARF value form code into its string name. */
21873 static const char *
21874 dwarf_form_name (unsigned form
)
21876 const char *name
= get_DW_FORM_name (form
);
21879 return dwarf_unknown ("FORM", form
);
21884 static const char *
21885 dwarf_bool_name (unsigned mybool
)
21893 /* Convert a DWARF type code into its string name. */
21895 static const char *
21896 dwarf_type_encoding_name (unsigned enc
)
21898 const char *name
= get_DW_ATE_name (enc
);
21901 return dwarf_unknown ("ATE", enc
);
21907 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21911 print_spaces (indent
, f
);
21912 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21913 dwarf_tag_name (die
->tag
), die
->abbrev
,
21914 sect_offset_str (die
->sect_off
));
21916 if (die
->parent
!= NULL
)
21918 print_spaces (indent
, f
);
21919 fprintf_unfiltered (f
, " parent at offset: %s\n",
21920 sect_offset_str (die
->parent
->sect_off
));
21923 print_spaces (indent
, f
);
21924 fprintf_unfiltered (f
, " has children: %s\n",
21925 dwarf_bool_name (die
->child
!= NULL
));
21927 print_spaces (indent
, f
);
21928 fprintf_unfiltered (f
, " attributes:\n");
21930 for (i
= 0; i
< die
->num_attrs
; ++i
)
21932 print_spaces (indent
, f
);
21933 fprintf_unfiltered (f
, " %s (%s) ",
21934 dwarf_attr_name (die
->attrs
[i
].name
),
21935 dwarf_form_name (die
->attrs
[i
].form
));
21937 switch (die
->attrs
[i
].form
)
21940 case DW_FORM_addrx
:
21941 case DW_FORM_GNU_addr_index
:
21942 fprintf_unfiltered (f
, "address: ");
21943 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21945 case DW_FORM_block2
:
21946 case DW_FORM_block4
:
21947 case DW_FORM_block
:
21948 case DW_FORM_block1
:
21949 fprintf_unfiltered (f
, "block: size %s",
21950 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21952 case DW_FORM_exprloc
:
21953 fprintf_unfiltered (f
, "expression: size %s",
21954 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21956 case DW_FORM_data16
:
21957 fprintf_unfiltered (f
, "constant of 16 bytes");
21959 case DW_FORM_ref_addr
:
21960 fprintf_unfiltered (f
, "ref address: ");
21961 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21963 case DW_FORM_GNU_ref_alt
:
21964 fprintf_unfiltered (f
, "alt ref address: ");
21965 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21971 case DW_FORM_ref_udata
:
21972 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21973 (long) (DW_UNSND (&die
->attrs
[i
])));
21975 case DW_FORM_data1
:
21976 case DW_FORM_data2
:
21977 case DW_FORM_data4
:
21978 case DW_FORM_data8
:
21979 case DW_FORM_udata
:
21980 case DW_FORM_sdata
:
21981 fprintf_unfiltered (f
, "constant: %s",
21982 pulongest (DW_UNSND (&die
->attrs
[i
])));
21984 case DW_FORM_sec_offset
:
21985 fprintf_unfiltered (f
, "section offset: %s",
21986 pulongest (DW_UNSND (&die
->attrs
[i
])));
21988 case DW_FORM_ref_sig8
:
21989 fprintf_unfiltered (f
, "signature: %s",
21990 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21992 case DW_FORM_string
:
21994 case DW_FORM_line_strp
:
21996 case DW_FORM_GNU_str_index
:
21997 case DW_FORM_GNU_strp_alt
:
21998 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21999 DW_STRING (&die
->attrs
[i
])
22000 ? DW_STRING (&die
->attrs
[i
]) : "",
22001 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22004 if (DW_UNSND (&die
->attrs
[i
]))
22005 fprintf_unfiltered (f
, "flag: TRUE");
22007 fprintf_unfiltered (f
, "flag: FALSE");
22009 case DW_FORM_flag_present
:
22010 fprintf_unfiltered (f
, "flag: TRUE");
22012 case DW_FORM_indirect
:
22013 /* The reader will have reduced the indirect form to
22014 the "base form" so this form should not occur. */
22015 fprintf_unfiltered (f
,
22016 "unexpected attribute form: DW_FORM_indirect");
22018 case DW_FORM_implicit_const
:
22019 fprintf_unfiltered (f
, "constant: %s",
22020 plongest (DW_SND (&die
->attrs
[i
])));
22023 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22024 die
->attrs
[i
].form
);
22027 fprintf_unfiltered (f
, "\n");
22032 dump_die_for_error (struct die_info
*die
)
22034 dump_die_shallow (gdb_stderr
, 0, die
);
22038 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22040 int indent
= level
* 4;
22042 gdb_assert (die
!= NULL
);
22044 if (level
>= max_level
)
22047 dump_die_shallow (f
, indent
, die
);
22049 if (die
->child
!= NULL
)
22051 print_spaces (indent
, f
);
22052 fprintf_unfiltered (f
, " Children:");
22053 if (level
+ 1 < max_level
)
22055 fprintf_unfiltered (f
, "\n");
22056 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22060 fprintf_unfiltered (f
,
22061 " [not printed, max nesting level reached]\n");
22065 if (die
->sibling
!= NULL
&& level
> 0)
22067 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22071 /* This is called from the pdie macro in gdbinit.in.
22072 It's not static so gcc will keep a copy callable from gdb. */
22075 dump_die (struct die_info
*die
, int max_level
)
22077 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22081 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22085 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22086 to_underlying (die
->sect_off
),
22092 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22096 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22098 if (attr
->form_is_ref ())
22099 return (sect_offset
) DW_UNSND (attr
);
22101 complaint (_("unsupported die ref attribute form: '%s'"),
22102 dwarf_form_name (attr
->form
));
22106 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22107 * the value held by the attribute is not constant. */
22110 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22112 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22113 return DW_SND (attr
);
22114 else if (attr
->form
== DW_FORM_udata
22115 || attr
->form
== DW_FORM_data1
22116 || attr
->form
== DW_FORM_data2
22117 || attr
->form
== DW_FORM_data4
22118 || attr
->form
== DW_FORM_data8
)
22119 return DW_UNSND (attr
);
22122 /* For DW_FORM_data16 see attribute::form_is_constant. */
22123 complaint (_("Attribute value is not a constant (%s)"),
22124 dwarf_form_name (attr
->form
));
22125 return default_value
;
22129 /* Follow reference or signature attribute ATTR of SRC_DIE.
22130 On entry *REF_CU is the CU of SRC_DIE.
22131 On exit *REF_CU is the CU of the result. */
22133 static struct die_info
*
22134 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22135 struct dwarf2_cu
**ref_cu
)
22137 struct die_info
*die
;
22139 if (attr
->form_is_ref ())
22140 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22141 else if (attr
->form
== DW_FORM_ref_sig8
)
22142 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22145 dump_die_for_error (src_die
);
22146 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22147 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22153 /* Follow reference OFFSET.
22154 On entry *REF_CU is the CU of the source die referencing OFFSET.
22155 On exit *REF_CU is the CU of the result.
22156 Returns NULL if OFFSET is invalid. */
22158 static struct die_info
*
22159 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22160 struct dwarf2_cu
**ref_cu
)
22162 struct die_info temp_die
;
22163 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22164 struct dwarf2_per_objfile
*dwarf2_per_objfile
22165 = cu
->per_cu
->dwarf2_per_objfile
;
22167 gdb_assert (cu
->per_cu
!= NULL
);
22171 if (cu
->per_cu
->is_debug_types
)
22173 /* .debug_types CUs cannot reference anything outside their CU.
22174 If they need to, they have to reference a signatured type via
22175 DW_FORM_ref_sig8. */
22176 if (!cu
->header
.offset_in_cu_p (sect_off
))
22179 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22180 || !cu
->header
.offset_in_cu_p (sect_off
))
22182 struct dwarf2_per_cu_data
*per_cu
;
22184 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22185 dwarf2_per_objfile
);
22187 /* If necessary, add it to the queue and load its DIEs. */
22188 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22189 load_full_comp_unit (per_cu
, false, cu
->language
);
22191 target_cu
= per_cu
->cu
;
22193 else if (cu
->dies
== NULL
)
22195 /* We're loading full DIEs during partial symbol reading. */
22196 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22197 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22200 *ref_cu
= target_cu
;
22201 temp_die
.sect_off
= sect_off
;
22203 if (target_cu
!= cu
)
22204 target_cu
->ancestor
= cu
;
22206 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22208 to_underlying (sect_off
));
22211 /* Follow reference attribute ATTR of SRC_DIE.
22212 On entry *REF_CU is the CU of SRC_DIE.
22213 On exit *REF_CU is the CU of the result. */
22215 static struct die_info
*
22216 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22217 struct dwarf2_cu
**ref_cu
)
22219 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22220 struct dwarf2_cu
*cu
= *ref_cu
;
22221 struct die_info
*die
;
22223 die
= follow_die_offset (sect_off
,
22224 (attr
->form
== DW_FORM_GNU_ref_alt
22225 || cu
->per_cu
->is_dwz
),
22228 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22229 "at %s [in module %s]"),
22230 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22231 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22236 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22237 Returned value is intended for DW_OP_call*. Returned
22238 dwarf2_locexpr_baton->data has lifetime of
22239 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22241 struct dwarf2_locexpr_baton
22242 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22243 struct dwarf2_per_cu_data
*per_cu
,
22244 CORE_ADDR (*get_frame_pc
) (void *baton
),
22245 void *baton
, bool resolve_abstract_p
)
22247 struct dwarf2_cu
*cu
;
22248 struct die_info
*die
;
22249 struct attribute
*attr
;
22250 struct dwarf2_locexpr_baton retval
;
22251 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22252 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22254 if (per_cu
->cu
== NULL
)
22255 load_cu (per_cu
, false);
22259 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22260 Instead just throw an error, not much else we can do. */
22261 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22262 sect_offset_str (sect_off
), objfile_name (objfile
));
22265 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22267 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22268 sect_offset_str (sect_off
), objfile_name (objfile
));
22270 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22271 if (!attr
&& resolve_abstract_p
22272 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22273 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22275 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22276 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22277 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22279 for (const auto &cand_off
22280 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22282 struct dwarf2_cu
*cand_cu
= cu
;
22283 struct die_info
*cand
22284 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22287 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22290 CORE_ADDR pc_low
, pc_high
;
22291 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22292 if (pc_low
== ((CORE_ADDR
) -1))
22294 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22295 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22296 if (!(pc_low
<= pc
&& pc
< pc_high
))
22300 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22307 /* DWARF: "If there is no such attribute, then there is no effect.".
22308 DATA is ignored if SIZE is 0. */
22310 retval
.data
= NULL
;
22313 else if (attr
->form_is_section_offset ())
22315 struct dwarf2_loclist_baton loclist_baton
;
22316 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22319 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22321 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22323 retval
.size
= size
;
22327 if (!attr
->form_is_block ())
22328 error (_("Dwarf Error: DIE at %s referenced in module %s "
22329 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22330 sect_offset_str (sect_off
), objfile_name (objfile
));
22332 retval
.data
= DW_BLOCK (attr
)->data
;
22333 retval
.size
= DW_BLOCK (attr
)->size
;
22335 retval
.per_cu
= cu
->per_cu
;
22337 age_cached_comp_units (dwarf2_per_objfile
);
22342 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
22345 struct dwarf2_locexpr_baton
22346 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22347 struct dwarf2_per_cu_data
*per_cu
,
22348 CORE_ADDR (*get_frame_pc
) (void *baton
),
22351 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22353 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22356 /* Write a constant of a given type as target-ordered bytes into
22359 static const gdb_byte
*
22360 write_constant_as_bytes (struct obstack
*obstack
,
22361 enum bfd_endian byte_order
,
22368 *len
= TYPE_LENGTH (type
);
22369 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22370 store_unsigned_integer (result
, *len
, byte_order
, value
);
22375 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
22376 pointer to the constant bytes and set LEN to the length of the
22377 data. If memory is needed, allocate it on OBSTACK. If the DIE
22378 does not have a DW_AT_const_value, return NULL. */
22381 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22382 struct dwarf2_per_cu_data
*per_cu
,
22383 struct obstack
*obstack
,
22386 struct dwarf2_cu
*cu
;
22387 struct die_info
*die
;
22388 struct attribute
*attr
;
22389 const gdb_byte
*result
= NULL
;
22392 enum bfd_endian byte_order
;
22393 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22395 if (per_cu
->cu
== NULL
)
22396 load_cu (per_cu
, false);
22400 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22401 Instead just throw an error, not much else we can do. */
22402 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22403 sect_offset_str (sect_off
), objfile_name (objfile
));
22406 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22408 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22409 sect_offset_str (sect_off
), objfile_name (objfile
));
22411 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22415 byte_order
= (bfd_big_endian (objfile
->obfd
)
22416 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22418 switch (attr
->form
)
22421 case DW_FORM_addrx
:
22422 case DW_FORM_GNU_addr_index
:
22426 *len
= cu
->header
.addr_size
;
22427 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22428 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22432 case DW_FORM_string
:
22435 case DW_FORM_GNU_str_index
:
22436 case DW_FORM_GNU_strp_alt
:
22437 /* DW_STRING is already allocated on the objfile obstack, point
22439 result
= (const gdb_byte
*) DW_STRING (attr
);
22440 *len
= strlen (DW_STRING (attr
));
22442 case DW_FORM_block1
:
22443 case DW_FORM_block2
:
22444 case DW_FORM_block4
:
22445 case DW_FORM_block
:
22446 case DW_FORM_exprloc
:
22447 case DW_FORM_data16
:
22448 result
= DW_BLOCK (attr
)->data
;
22449 *len
= DW_BLOCK (attr
)->size
;
22452 /* The DW_AT_const_value attributes are supposed to carry the
22453 symbol's value "represented as it would be on the target
22454 architecture." By the time we get here, it's already been
22455 converted to host endianness, so we just need to sign- or
22456 zero-extend it as appropriate. */
22457 case DW_FORM_data1
:
22458 type
= die_type (die
, cu
);
22459 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22460 if (result
== NULL
)
22461 result
= write_constant_as_bytes (obstack
, byte_order
,
22464 case DW_FORM_data2
:
22465 type
= die_type (die
, cu
);
22466 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22467 if (result
== NULL
)
22468 result
= write_constant_as_bytes (obstack
, byte_order
,
22471 case DW_FORM_data4
:
22472 type
= die_type (die
, cu
);
22473 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22474 if (result
== NULL
)
22475 result
= write_constant_as_bytes (obstack
, byte_order
,
22478 case DW_FORM_data8
:
22479 type
= die_type (die
, cu
);
22480 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22481 if (result
== NULL
)
22482 result
= write_constant_as_bytes (obstack
, byte_order
,
22486 case DW_FORM_sdata
:
22487 case DW_FORM_implicit_const
:
22488 type
= die_type (die
, cu
);
22489 result
= write_constant_as_bytes (obstack
, byte_order
,
22490 type
, DW_SND (attr
), len
);
22493 case DW_FORM_udata
:
22494 type
= die_type (die
, cu
);
22495 result
= write_constant_as_bytes (obstack
, byte_order
,
22496 type
, DW_UNSND (attr
), len
);
22500 complaint (_("unsupported const value attribute form: '%s'"),
22501 dwarf_form_name (attr
->form
));
22508 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
22509 valid type for this die is found. */
22512 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22513 struct dwarf2_per_cu_data
*per_cu
)
22515 struct dwarf2_cu
*cu
;
22516 struct die_info
*die
;
22518 if (per_cu
->cu
== NULL
)
22519 load_cu (per_cu
, false);
22524 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22528 return die_type (die
, cu
);
22531 /* Return the type of the DIE at DIE_OFFSET in the CU named by
22535 dwarf2_get_die_type (cu_offset die_offset
,
22536 struct dwarf2_per_cu_data
*per_cu
)
22538 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22539 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22542 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22543 On entry *REF_CU is the CU of SRC_DIE.
22544 On exit *REF_CU is the CU of the result.
22545 Returns NULL if the referenced DIE isn't found. */
22547 static struct die_info
*
22548 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22549 struct dwarf2_cu
**ref_cu
)
22551 struct die_info temp_die
;
22552 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22553 struct die_info
*die
;
22555 /* While it might be nice to assert sig_type->type == NULL here,
22556 we can get here for DW_AT_imported_declaration where we need
22557 the DIE not the type. */
22559 /* If necessary, add it to the queue and load its DIEs. */
22561 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22562 read_signatured_type (sig_type
);
22564 sig_cu
= sig_type
->per_cu
.cu
;
22565 gdb_assert (sig_cu
!= NULL
);
22566 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22567 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22568 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22569 to_underlying (temp_die
.sect_off
));
22572 struct dwarf2_per_objfile
*dwarf2_per_objfile
22573 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22575 /* For .gdb_index version 7 keep track of included TUs.
22576 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22577 if (dwarf2_per_objfile
->index_table
!= NULL
22578 && dwarf2_per_objfile
->index_table
->version
<= 7)
22580 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22585 sig_cu
->ancestor
= cu
;
22593 /* Follow signatured type referenced by ATTR in SRC_DIE.
22594 On entry *REF_CU is the CU of SRC_DIE.
22595 On exit *REF_CU is the CU of the result.
22596 The result is the DIE of the type.
22597 If the referenced type cannot be found an error is thrown. */
22599 static struct die_info
*
22600 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22601 struct dwarf2_cu
**ref_cu
)
22603 ULONGEST signature
= DW_SIGNATURE (attr
);
22604 struct signatured_type
*sig_type
;
22605 struct die_info
*die
;
22607 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22609 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22610 /* sig_type will be NULL if the signatured type is missing from
22612 if (sig_type
== NULL
)
22614 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22615 " from DIE at %s [in module %s]"),
22616 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22617 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22620 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22623 dump_die_for_error (src_die
);
22624 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22625 " from DIE at %s [in module %s]"),
22626 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22627 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22633 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22634 reading in and processing the type unit if necessary. */
22636 static struct type
*
22637 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22638 struct dwarf2_cu
*cu
)
22640 struct dwarf2_per_objfile
*dwarf2_per_objfile
22641 = cu
->per_cu
->dwarf2_per_objfile
;
22642 struct signatured_type
*sig_type
;
22643 struct dwarf2_cu
*type_cu
;
22644 struct die_info
*type_die
;
22647 sig_type
= lookup_signatured_type (cu
, signature
);
22648 /* sig_type will be NULL if the signatured type is missing from
22650 if (sig_type
== NULL
)
22652 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22653 " from DIE at %s [in module %s]"),
22654 hex_string (signature
), sect_offset_str (die
->sect_off
),
22655 objfile_name (dwarf2_per_objfile
->objfile
));
22656 return build_error_marker_type (cu
, die
);
22659 /* If we already know the type we're done. */
22660 if (sig_type
->type
!= NULL
)
22661 return sig_type
->type
;
22664 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22665 if (type_die
!= NULL
)
22667 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22668 is created. This is important, for example, because for c++ classes
22669 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22670 type
= read_type_die (type_die
, type_cu
);
22673 complaint (_("Dwarf Error: Cannot build signatured type %s"
22674 " referenced from DIE at %s [in module %s]"),
22675 hex_string (signature
), sect_offset_str (die
->sect_off
),
22676 objfile_name (dwarf2_per_objfile
->objfile
));
22677 type
= build_error_marker_type (cu
, die
);
22682 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22683 " from DIE at %s [in module %s]"),
22684 hex_string (signature
), sect_offset_str (die
->sect_off
),
22685 objfile_name (dwarf2_per_objfile
->objfile
));
22686 type
= build_error_marker_type (cu
, die
);
22688 sig_type
->type
= type
;
22693 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22694 reading in and processing the type unit if necessary. */
22696 static struct type
*
22697 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22698 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22700 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22701 if (attr
->form_is_ref ())
22703 struct dwarf2_cu
*type_cu
= cu
;
22704 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22706 return read_type_die (type_die
, type_cu
);
22708 else if (attr
->form
== DW_FORM_ref_sig8
)
22710 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22714 struct dwarf2_per_objfile
*dwarf2_per_objfile
22715 = cu
->per_cu
->dwarf2_per_objfile
;
22717 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22718 " at %s [in module %s]"),
22719 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22720 objfile_name (dwarf2_per_objfile
->objfile
));
22721 return build_error_marker_type (cu
, die
);
22725 /* Load the DIEs associated with type unit PER_CU into memory. */
22728 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22730 struct signatured_type
*sig_type
;
22732 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22733 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
22735 /* We have the per_cu, but we need the signatured_type.
22736 Fortunately this is an easy translation. */
22737 gdb_assert (per_cu
->is_debug_types
);
22738 sig_type
= (struct signatured_type
*) per_cu
;
22740 gdb_assert (per_cu
->cu
== NULL
);
22742 read_signatured_type (sig_type
);
22744 gdb_assert (per_cu
->cu
!= NULL
);
22747 /* Read in a signatured type and build its CU and DIEs.
22748 If the type is a stub for the real type in a DWO file,
22749 read in the real type from the DWO file as well. */
22752 read_signatured_type (struct signatured_type
*sig_type
)
22754 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22756 gdb_assert (per_cu
->is_debug_types
);
22757 gdb_assert (per_cu
->cu
== NULL
);
22759 cutu_reader
reader (per_cu
, NULL
, 0, false);
22761 if (!reader
.dummy_p
)
22763 struct dwarf2_cu
*cu
= reader
.cu
;
22764 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22766 gdb_assert (cu
->die_hash
== NULL
);
22768 htab_create_alloc_ex (cu
->header
.length
/ 12,
22772 &cu
->comp_unit_obstack
,
22773 hashtab_obstack_allocate
,
22774 dummy_obstack_deallocate
);
22776 if (reader
.comp_unit_die
->has_children
)
22777 reader
.comp_unit_die
->child
22778 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22779 reader
.comp_unit_die
);
22780 cu
->dies
= reader
.comp_unit_die
;
22781 /* comp_unit_die is not stored in die_hash, no need. */
22783 /* We try not to read any attributes in this function, because
22784 not all CUs needed for references have been loaded yet, and
22785 symbol table processing isn't initialized. But we have to
22786 set the CU language, or we won't be able to build types
22787 correctly. Similarly, if we do not read the producer, we can
22788 not apply producer-specific interpretation. */
22789 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22794 sig_type
->per_cu
.tu_read
= 1;
22797 /* Decode simple location descriptions.
22798 Given a pointer to a dwarf block that defines a location, compute
22799 the location and return the value.
22801 NOTE drow/2003-11-18: This function is called in two situations
22802 now: for the address of static or global variables (partial symbols
22803 only) and for offsets into structures which are expected to be
22804 (more or less) constant. The partial symbol case should go away,
22805 and only the constant case should remain. That will let this
22806 function complain more accurately. A few special modes are allowed
22807 without complaint for global variables (for instance, global
22808 register values and thread-local values).
22810 A location description containing no operations indicates that the
22811 object is optimized out. The return value is 0 for that case.
22812 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22813 callers will only want a very basic result and this can become a
22816 Note that stack[0] is unused except as a default error return. */
22819 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22821 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22823 size_t size
= blk
->size
;
22824 const gdb_byte
*data
= blk
->data
;
22825 CORE_ADDR stack
[64];
22827 unsigned int bytes_read
, unsnd
;
22833 stack
[++stacki
] = 0;
22872 stack
[++stacki
] = op
- DW_OP_lit0
;
22907 stack
[++stacki
] = op
- DW_OP_reg0
;
22909 dwarf2_complex_location_expr_complaint ();
22913 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22915 stack
[++stacki
] = unsnd
;
22917 dwarf2_complex_location_expr_complaint ();
22921 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22926 case DW_OP_const1u
:
22927 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22931 case DW_OP_const1s
:
22932 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22936 case DW_OP_const2u
:
22937 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22941 case DW_OP_const2s
:
22942 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22946 case DW_OP_const4u
:
22947 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22951 case DW_OP_const4s
:
22952 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22956 case DW_OP_const8u
:
22957 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22962 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22968 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22973 stack
[stacki
+ 1] = stack
[stacki
];
22978 stack
[stacki
- 1] += stack
[stacki
];
22982 case DW_OP_plus_uconst
:
22983 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22989 stack
[stacki
- 1] -= stack
[stacki
];
22994 /* If we're not the last op, then we definitely can't encode
22995 this using GDB's address_class enum. This is valid for partial
22996 global symbols, although the variable's address will be bogus
22999 dwarf2_complex_location_expr_complaint ();
23002 case DW_OP_GNU_push_tls_address
:
23003 case DW_OP_form_tls_address
:
23004 /* The top of the stack has the offset from the beginning
23005 of the thread control block at which the variable is located. */
23006 /* Nothing should follow this operator, so the top of stack would
23008 /* This is valid for partial global symbols, but the variable's
23009 address will be bogus in the psymtab. Make it always at least
23010 non-zero to not look as a variable garbage collected by linker
23011 which have DW_OP_addr 0. */
23013 dwarf2_complex_location_expr_complaint ();
23017 case DW_OP_GNU_uninit
:
23021 case DW_OP_GNU_addr_index
:
23022 case DW_OP_GNU_const_index
:
23023 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23030 const char *name
= get_DW_OP_name (op
);
23033 complaint (_("unsupported stack op: '%s'"),
23036 complaint (_("unsupported stack op: '%02x'"),
23040 return (stack
[stacki
]);
23043 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23044 outside of the allocated space. Also enforce minimum>0. */
23045 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23047 complaint (_("location description stack overflow"));
23053 complaint (_("location description stack underflow"));
23057 return (stack
[stacki
]);
23060 /* memory allocation interface */
23062 static struct dwarf_block
*
23063 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23065 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23068 static struct die_info
*
23069 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23071 struct die_info
*die
;
23072 size_t size
= sizeof (struct die_info
);
23075 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23077 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23078 memset (die
, 0, sizeof (struct die_info
));
23083 /* Macro support. */
23085 static struct macro_source_file
*
23086 macro_start_file (struct dwarf2_cu
*cu
,
23087 int file
, int line
,
23088 struct macro_source_file
*current_file
,
23089 struct line_header
*lh
)
23091 /* File name relative to the compilation directory of this source file. */
23092 gdb::unique_xmalloc_ptr
<char> file_name
= lh
->file_file_name (file
);
23094 if (! current_file
)
23096 /* Note: We don't create a macro table for this compilation unit
23097 at all until we actually get a filename. */
23098 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
23100 /* If we have no current file, then this must be the start_file
23101 directive for the compilation unit's main source file. */
23102 current_file
= macro_set_main (macro_table
, file_name
.get ());
23103 macro_define_special (macro_table
);
23106 current_file
= macro_include (current_file
, line
, file_name
.get ());
23108 return current_file
;
23111 static const char *
23112 consume_improper_spaces (const char *p
, const char *body
)
23116 complaint (_("macro definition contains spaces "
23117 "in formal argument list:\n`%s'"),
23129 parse_macro_definition (struct macro_source_file
*file
, int line
,
23134 /* The body string takes one of two forms. For object-like macro
23135 definitions, it should be:
23137 <macro name> " " <definition>
23139 For function-like macro definitions, it should be:
23141 <macro name> "() " <definition>
23143 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23145 Spaces may appear only where explicitly indicated, and in the
23148 The Dwarf 2 spec says that an object-like macro's name is always
23149 followed by a space, but versions of GCC around March 2002 omit
23150 the space when the macro's definition is the empty string.
23152 The Dwarf 2 spec says that there should be no spaces between the
23153 formal arguments in a function-like macro's formal argument list,
23154 but versions of GCC around March 2002 include spaces after the
23158 /* Find the extent of the macro name. The macro name is terminated
23159 by either a space or null character (for an object-like macro) or
23160 an opening paren (for a function-like macro). */
23161 for (p
= body
; *p
; p
++)
23162 if (*p
== ' ' || *p
== '(')
23165 if (*p
== ' ' || *p
== '\0')
23167 /* It's an object-like macro. */
23168 int name_len
= p
- body
;
23169 std::string
name (body
, name_len
);
23170 const char *replacement
;
23173 replacement
= body
+ name_len
+ 1;
23176 dwarf2_macro_malformed_definition_complaint (body
);
23177 replacement
= body
+ name_len
;
23180 macro_define_object (file
, line
, name
.c_str (), replacement
);
23182 else if (*p
== '(')
23184 /* It's a function-like macro. */
23185 std::string
name (body
, p
- body
);
23188 char **argv
= XNEWVEC (char *, argv_size
);
23192 p
= consume_improper_spaces (p
, body
);
23194 /* Parse the formal argument list. */
23195 while (*p
&& *p
!= ')')
23197 /* Find the extent of the current argument name. */
23198 const char *arg_start
= p
;
23200 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23203 if (! *p
|| p
== arg_start
)
23204 dwarf2_macro_malformed_definition_complaint (body
);
23207 /* Make sure argv has room for the new argument. */
23208 if (argc
>= argv_size
)
23211 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23214 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23217 p
= consume_improper_spaces (p
, body
);
23219 /* Consume the comma, if present. */
23224 p
= consume_improper_spaces (p
, body
);
23233 /* Perfectly formed definition, no complaints. */
23234 macro_define_function (file
, line
, name
.c_str (),
23235 argc
, (const char **) argv
,
23237 else if (*p
== '\0')
23239 /* Complain, but do define it. */
23240 dwarf2_macro_malformed_definition_complaint (body
);
23241 macro_define_function (file
, line
, name
.c_str (),
23242 argc
, (const char **) argv
,
23246 /* Just complain. */
23247 dwarf2_macro_malformed_definition_complaint (body
);
23250 /* Just complain. */
23251 dwarf2_macro_malformed_definition_complaint (body
);
23256 for (i
= 0; i
< argc
; i
++)
23262 dwarf2_macro_malformed_definition_complaint (body
);
23265 /* Skip some bytes from BYTES according to the form given in FORM.
23266 Returns the new pointer. */
23268 static const gdb_byte
*
23269 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23270 enum dwarf_form form
,
23271 unsigned int offset_size
,
23272 struct dwarf2_section_info
*section
)
23274 unsigned int bytes_read
;
23278 case DW_FORM_data1
:
23283 case DW_FORM_data2
:
23287 case DW_FORM_data4
:
23291 case DW_FORM_data8
:
23295 case DW_FORM_data16
:
23299 case DW_FORM_string
:
23300 read_direct_string (abfd
, bytes
, &bytes_read
);
23301 bytes
+= bytes_read
;
23304 case DW_FORM_sec_offset
:
23306 case DW_FORM_GNU_strp_alt
:
23307 bytes
+= offset_size
;
23310 case DW_FORM_block
:
23311 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23312 bytes
+= bytes_read
;
23315 case DW_FORM_block1
:
23316 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23318 case DW_FORM_block2
:
23319 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23321 case DW_FORM_block4
:
23322 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23325 case DW_FORM_addrx
:
23326 case DW_FORM_sdata
:
23328 case DW_FORM_udata
:
23329 case DW_FORM_GNU_addr_index
:
23330 case DW_FORM_GNU_str_index
:
23331 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23334 dwarf2_section_buffer_overflow_complaint (section
);
23339 case DW_FORM_implicit_const
:
23344 complaint (_("invalid form 0x%x in `%s'"),
23345 form
, section
->get_name ());
23353 /* A helper for dwarf_decode_macros that handles skipping an unknown
23354 opcode. Returns an updated pointer to the macro data buffer; or,
23355 on error, issues a complaint and returns NULL. */
23357 static const gdb_byte
*
23358 skip_unknown_opcode (unsigned int opcode
,
23359 const gdb_byte
**opcode_definitions
,
23360 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23362 unsigned int offset_size
,
23363 struct dwarf2_section_info
*section
)
23365 unsigned int bytes_read
, i
;
23367 const gdb_byte
*defn
;
23369 if (opcode_definitions
[opcode
] == NULL
)
23371 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
23376 defn
= opcode_definitions
[opcode
];
23377 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
23378 defn
+= bytes_read
;
23380 for (i
= 0; i
< arg
; ++i
)
23382 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
23383 (enum dwarf_form
) defn
[i
], offset_size
,
23385 if (mac_ptr
== NULL
)
23387 /* skip_form_bytes already issued the complaint. */
23395 /* A helper function which parses the header of a macro section.
23396 If the macro section is the extended (for now called "GNU") type,
23397 then this updates *OFFSET_SIZE. Returns a pointer to just after
23398 the header, or issues a complaint and returns NULL on error. */
23400 static const gdb_byte
*
23401 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
23403 const gdb_byte
*mac_ptr
,
23404 unsigned int *offset_size
,
23405 int section_is_gnu
)
23407 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
23409 if (section_is_gnu
)
23411 unsigned int version
, flags
;
23413 version
= read_2_bytes (abfd
, mac_ptr
);
23414 if (version
!= 4 && version
!= 5)
23416 complaint (_("unrecognized version `%d' in .debug_macro section"),
23422 flags
= read_1_byte (abfd
, mac_ptr
);
23424 *offset_size
= (flags
& 1) ? 8 : 4;
23426 if ((flags
& 2) != 0)
23427 /* We don't need the line table offset. */
23428 mac_ptr
+= *offset_size
;
23430 /* Vendor opcode descriptions. */
23431 if ((flags
& 4) != 0)
23433 unsigned int i
, count
;
23435 count
= read_1_byte (abfd
, mac_ptr
);
23437 for (i
= 0; i
< count
; ++i
)
23439 unsigned int opcode
, bytes_read
;
23442 opcode
= read_1_byte (abfd
, mac_ptr
);
23444 opcode_definitions
[opcode
] = mac_ptr
;
23445 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23446 mac_ptr
+= bytes_read
;
23455 /* A helper for dwarf_decode_macros that handles the GNU extensions,
23456 including DW_MACRO_import. */
23459 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
23461 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23462 struct macro_source_file
*current_file
,
23463 struct line_header
*lh
,
23464 struct dwarf2_section_info
*section
,
23465 int section_is_gnu
, int section_is_dwz
,
23466 unsigned int offset_size
,
23467 htab_t include_hash
)
23469 struct dwarf2_per_objfile
*dwarf2_per_objfile
23470 = cu
->per_cu
->dwarf2_per_objfile
;
23471 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23472 enum dwarf_macro_record_type macinfo_type
;
23473 int at_commandline
;
23474 const gdb_byte
*opcode_definitions
[256];
23476 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23477 &offset_size
, section_is_gnu
);
23478 if (mac_ptr
== NULL
)
23480 /* We already issued a complaint. */
23484 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
23485 GDB is still reading the definitions from command line. First
23486 DW_MACINFO_start_file will need to be ignored as it was already executed
23487 to create CURRENT_FILE for the main source holding also the command line
23488 definitions. On first met DW_MACINFO_start_file this flag is reset to
23489 normally execute all the remaining DW_MACINFO_start_file macinfos. */
23491 at_commandline
= 1;
23495 /* Do we at least have room for a macinfo type byte? */
23496 if (mac_ptr
>= mac_end
)
23498 dwarf2_section_buffer_overflow_complaint (section
);
23502 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23505 /* Note that we rely on the fact that the corresponding GNU and
23506 DWARF constants are the same. */
23508 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23509 switch (macinfo_type
)
23511 /* A zero macinfo type indicates the end of the macro
23516 case DW_MACRO_define
:
23517 case DW_MACRO_undef
:
23518 case DW_MACRO_define_strp
:
23519 case DW_MACRO_undef_strp
:
23520 case DW_MACRO_define_sup
:
23521 case DW_MACRO_undef_sup
:
23523 unsigned int bytes_read
;
23528 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23529 mac_ptr
+= bytes_read
;
23531 if (macinfo_type
== DW_MACRO_define
23532 || macinfo_type
== DW_MACRO_undef
)
23534 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23535 mac_ptr
+= bytes_read
;
23539 LONGEST str_offset
;
23541 str_offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23542 mac_ptr
+= offset_size
;
23544 if (macinfo_type
== DW_MACRO_define_sup
23545 || macinfo_type
== DW_MACRO_undef_sup
23548 struct dwz_file
*dwz
23549 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
23551 body
= read_indirect_string_from_dwz (objfile
,
23555 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
23559 is_define
= (macinfo_type
== DW_MACRO_define
23560 || macinfo_type
== DW_MACRO_define_strp
23561 || macinfo_type
== DW_MACRO_define_sup
);
23562 if (! current_file
)
23564 /* DWARF violation as no main source is present. */
23565 complaint (_("debug info with no main source gives macro %s "
23567 is_define
? _("definition") : _("undefinition"),
23571 if ((line
== 0 && !at_commandline
)
23572 || (line
!= 0 && at_commandline
))
23573 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
23574 at_commandline
? _("command-line") : _("in-file"),
23575 is_define
? _("definition") : _("undefinition"),
23576 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
23580 /* Fedora's rpm-build's "debugedit" binary
23581 corrupted .debug_macro sections.
23584 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
23585 complaint (_("debug info gives %s invalid macro %s "
23586 "without body (corrupted?) at line %d "
23588 at_commandline
? _("command-line") : _("in-file"),
23589 is_define
? _("definition") : _("undefinition"),
23590 line
, current_file
->filename
);
23592 else if (is_define
)
23593 parse_macro_definition (current_file
, line
, body
);
23596 gdb_assert (macinfo_type
== DW_MACRO_undef
23597 || macinfo_type
== DW_MACRO_undef_strp
23598 || macinfo_type
== DW_MACRO_undef_sup
);
23599 macro_undef (current_file
, line
, body
);
23604 case DW_MACRO_start_file
:
23606 unsigned int bytes_read
;
23609 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23610 mac_ptr
+= bytes_read
;
23611 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23612 mac_ptr
+= bytes_read
;
23614 if ((line
== 0 && !at_commandline
)
23615 || (line
!= 0 && at_commandline
))
23616 complaint (_("debug info gives source %d included "
23617 "from %s at %s line %d"),
23618 file
, at_commandline
? _("command-line") : _("file"),
23619 line
== 0 ? _("zero") : _("non-zero"), line
);
23621 if (at_commandline
)
23623 /* This DW_MACRO_start_file was executed in the
23625 at_commandline
= 0;
23628 current_file
= macro_start_file (cu
, file
, line
, current_file
,
23633 case DW_MACRO_end_file
:
23634 if (! current_file
)
23635 complaint (_("macro debug info has an unmatched "
23636 "`close_file' directive"));
23639 current_file
= current_file
->included_by
;
23640 if (! current_file
)
23642 enum dwarf_macro_record_type next_type
;
23644 /* GCC circa March 2002 doesn't produce the zero
23645 type byte marking the end of the compilation
23646 unit. Complain if it's not there, but exit no
23649 /* Do we at least have room for a macinfo type byte? */
23650 if (mac_ptr
>= mac_end
)
23652 dwarf2_section_buffer_overflow_complaint (section
);
23656 /* We don't increment mac_ptr here, so this is just
23659 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
23661 if (next_type
!= 0)
23662 complaint (_("no terminating 0-type entry for "
23663 "macros in `.debug_macinfo' section"));
23670 case DW_MACRO_import
:
23671 case DW_MACRO_import_sup
:
23675 bfd
*include_bfd
= abfd
;
23676 struct dwarf2_section_info
*include_section
= section
;
23677 const gdb_byte
*include_mac_end
= mac_end
;
23678 int is_dwz
= section_is_dwz
;
23679 const gdb_byte
*new_mac_ptr
;
23681 offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23682 mac_ptr
+= offset_size
;
23684 if (macinfo_type
== DW_MACRO_import_sup
)
23686 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
23688 dwz
->macro
.read (objfile
);
23690 include_section
= &dwz
->macro
;
23691 include_bfd
= include_section
->get_bfd_owner ();
23692 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
23696 new_mac_ptr
= include_section
->buffer
+ offset
;
23697 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
23701 /* This has actually happened; see
23702 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
23703 complaint (_("recursive DW_MACRO_import in "
23704 ".debug_macro section"));
23708 *slot
= (void *) new_mac_ptr
;
23710 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
23711 include_mac_end
, current_file
, lh
,
23712 section
, section_is_gnu
, is_dwz
,
23713 offset_size
, include_hash
);
23715 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
23720 case DW_MACINFO_vendor_ext
:
23721 if (!section_is_gnu
)
23723 unsigned int bytes_read
;
23725 /* This reads the constant, but since we don't recognize
23726 any vendor extensions, we ignore it. */
23727 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23728 mac_ptr
+= bytes_read
;
23729 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23730 mac_ptr
+= bytes_read
;
23732 /* We don't recognize any vendor extensions. */
23738 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23739 mac_ptr
, mac_end
, abfd
, offset_size
,
23741 if (mac_ptr
== NULL
)
23746 } while (macinfo_type
!= 0);
23750 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23751 int section_is_gnu
)
23753 struct dwarf2_per_objfile
*dwarf2_per_objfile
23754 = cu
->per_cu
->dwarf2_per_objfile
;
23755 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23756 struct line_header
*lh
= cu
->line_header
;
23758 const gdb_byte
*mac_ptr
, *mac_end
;
23759 struct macro_source_file
*current_file
= 0;
23760 enum dwarf_macro_record_type macinfo_type
;
23761 unsigned int offset_size
= cu
->header
.offset_size
;
23762 const gdb_byte
*opcode_definitions
[256];
23764 struct dwarf2_section_info
*section
;
23765 const char *section_name
;
23767 if (cu
->dwo_unit
!= NULL
)
23769 if (section_is_gnu
)
23771 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23772 section_name
= ".debug_macro.dwo";
23776 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23777 section_name
= ".debug_macinfo.dwo";
23782 if (section_is_gnu
)
23784 section
= &dwarf2_per_objfile
->macro
;
23785 section_name
= ".debug_macro";
23789 section
= &dwarf2_per_objfile
->macinfo
;
23790 section_name
= ".debug_macinfo";
23794 section
->read (objfile
);
23795 if (section
->buffer
== NULL
)
23797 complaint (_("missing %s section"), section_name
);
23800 abfd
= section
->get_bfd_owner ();
23802 /* First pass: Find the name of the base filename.
23803 This filename is needed in order to process all macros whose definition
23804 (or undefinition) comes from the command line. These macros are defined
23805 before the first DW_MACINFO_start_file entry, and yet still need to be
23806 associated to the base file.
23808 To determine the base file name, we scan the macro definitions until we
23809 reach the first DW_MACINFO_start_file entry. We then initialize
23810 CURRENT_FILE accordingly so that any macro definition found before the
23811 first DW_MACINFO_start_file can still be associated to the base file. */
23813 mac_ptr
= section
->buffer
+ offset
;
23814 mac_end
= section
->buffer
+ section
->size
;
23816 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23817 &offset_size
, section_is_gnu
);
23818 if (mac_ptr
== NULL
)
23820 /* We already issued a complaint. */
23826 /* Do we at least have room for a macinfo type byte? */
23827 if (mac_ptr
>= mac_end
)
23829 /* Complaint is printed during the second pass as GDB will probably
23830 stop the first pass earlier upon finding
23831 DW_MACINFO_start_file. */
23835 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23838 /* Note that we rely on the fact that the corresponding GNU and
23839 DWARF constants are the same. */
23841 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23842 switch (macinfo_type
)
23844 /* A zero macinfo type indicates the end of the macro
23849 case DW_MACRO_define
:
23850 case DW_MACRO_undef
:
23851 /* Only skip the data by MAC_PTR. */
23853 unsigned int bytes_read
;
23855 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23856 mac_ptr
+= bytes_read
;
23857 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23858 mac_ptr
+= bytes_read
;
23862 case DW_MACRO_start_file
:
23864 unsigned int bytes_read
;
23867 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23868 mac_ptr
+= bytes_read
;
23869 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23870 mac_ptr
+= bytes_read
;
23872 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
23876 case DW_MACRO_end_file
:
23877 /* No data to skip by MAC_PTR. */
23880 case DW_MACRO_define_strp
:
23881 case DW_MACRO_undef_strp
:
23882 case DW_MACRO_define_sup
:
23883 case DW_MACRO_undef_sup
:
23885 unsigned int bytes_read
;
23887 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23888 mac_ptr
+= bytes_read
;
23889 mac_ptr
+= offset_size
;
23893 case DW_MACRO_import
:
23894 case DW_MACRO_import_sup
:
23895 /* Note that, according to the spec, a transparent include
23896 chain cannot call DW_MACRO_start_file. So, we can just
23897 skip this opcode. */
23898 mac_ptr
+= offset_size
;
23901 case DW_MACINFO_vendor_ext
:
23902 /* Only skip the data by MAC_PTR. */
23903 if (!section_is_gnu
)
23905 unsigned int bytes_read
;
23907 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23908 mac_ptr
+= bytes_read
;
23909 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23910 mac_ptr
+= bytes_read
;
23915 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23916 mac_ptr
, mac_end
, abfd
, offset_size
,
23918 if (mac_ptr
== NULL
)
23923 } while (macinfo_type
!= 0 && current_file
== NULL
);
23925 /* Second pass: Process all entries.
23927 Use the AT_COMMAND_LINE flag to determine whether we are still processing
23928 command-line macro definitions/undefinitions. This flag is unset when we
23929 reach the first DW_MACINFO_start_file entry. */
23931 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
23933 NULL
, xcalloc
, xfree
));
23934 mac_ptr
= section
->buffer
+ offset
;
23935 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
23936 *slot
= (void *) mac_ptr
;
23937 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
23938 current_file
, lh
, section
,
23939 section_is_gnu
, 0, offset_size
,
23940 include_hash
.get ());
23943 /* Return the .debug_loc section to use for CU.
23944 For DWO files use .debug_loc.dwo. */
23946 static struct dwarf2_section_info
*
23947 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23949 struct dwarf2_per_objfile
*dwarf2_per_objfile
23950 = cu
->per_cu
->dwarf2_per_objfile
;
23954 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23956 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23958 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23959 : &dwarf2_per_objfile
->loc
);
23962 /* A helper function that fills in a dwarf2_loclist_baton. */
23965 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23966 struct dwarf2_loclist_baton
*baton
,
23967 const struct attribute
*attr
)
23969 struct dwarf2_per_objfile
*dwarf2_per_objfile
23970 = cu
->per_cu
->dwarf2_per_objfile
;
23971 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23973 section
->read (dwarf2_per_objfile
->objfile
);
23975 baton
->per_cu
= cu
->per_cu
;
23976 gdb_assert (baton
->per_cu
);
23977 /* We don't know how long the location list is, but make sure we
23978 don't run off the edge of the section. */
23979 baton
->size
= section
->size
- DW_UNSND (attr
);
23980 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23981 baton
->base_address
= cu
->base_address
;
23982 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23986 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23987 struct dwarf2_cu
*cu
, int is_block
)
23989 struct dwarf2_per_objfile
*dwarf2_per_objfile
23990 = cu
->per_cu
->dwarf2_per_objfile
;
23991 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23992 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23994 if (attr
->form_is_section_offset ()
23995 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23996 the section. If so, fall through to the complaint in the
23998 && DW_UNSND (attr
) < section
->get_size (objfile
))
24000 struct dwarf2_loclist_baton
*baton
;
24002 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24004 fill_in_loclist_baton (cu
, baton
, attr
);
24006 if (cu
->base_known
== 0)
24007 complaint (_("Location list used without "
24008 "specifying the CU base address."));
24010 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24011 ? dwarf2_loclist_block_index
24012 : dwarf2_loclist_index
);
24013 SYMBOL_LOCATION_BATON (sym
) = baton
;
24017 struct dwarf2_locexpr_baton
*baton
;
24019 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24020 baton
->per_cu
= cu
->per_cu
;
24021 gdb_assert (baton
->per_cu
);
24023 if (attr
->form_is_block ())
24025 /* Note that we're just copying the block's data pointer
24026 here, not the actual data. We're still pointing into the
24027 info_buffer for SYM's objfile; right now we never release
24028 that buffer, but when we do clean up properly this may
24030 baton
->size
= DW_BLOCK (attr
)->size
;
24031 baton
->data
= DW_BLOCK (attr
)->data
;
24035 dwarf2_invalid_attrib_class_complaint ("location description",
24036 sym
->natural_name ());
24040 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24041 ? dwarf2_locexpr_block_index
24042 : dwarf2_locexpr_index
);
24043 SYMBOL_LOCATION_BATON (sym
) = baton
;
24050 dwarf2_per_cu_data::objfile () const
24052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24054 /* Return the master objfile, so that we can report and look up the
24055 correct file containing this variable. */
24056 if (objfile
->separate_debug_objfile_backlink
)
24057 objfile
= objfile
->separate_debug_objfile_backlink
;
24062 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24063 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24064 CU_HEADERP first. */
24066 static const struct comp_unit_head
*
24067 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24068 const struct dwarf2_per_cu_data
*per_cu
)
24070 const gdb_byte
*info_ptr
;
24073 return &per_cu
->cu
->header
;
24075 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24077 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24078 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24079 rcuh_kind::COMPILE
);
24087 dwarf2_per_cu_data::addr_size () const
24089 struct comp_unit_head cu_header_local
;
24090 const struct comp_unit_head
*cu_headerp
;
24092 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24094 return cu_headerp
->addr_size
;
24100 dwarf2_per_cu_data::offset_size () const
24102 struct comp_unit_head cu_header_local
;
24103 const struct comp_unit_head
*cu_headerp
;
24105 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24107 return cu_headerp
->offset_size
;
24113 dwarf2_per_cu_data::ref_addr_size () const
24115 struct comp_unit_head cu_header_local
;
24116 const struct comp_unit_head
*cu_headerp
;
24118 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24120 if (cu_headerp
->version
== 2)
24121 return cu_headerp
->addr_size
;
24123 return cu_headerp
->offset_size
;
24129 dwarf2_per_cu_data::text_offset () const
24131 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24133 return objfile
->text_section_offset ();
24139 dwarf2_per_cu_data::addr_type () const
24141 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24142 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24143 struct type
*addr_type
= lookup_pointer_type (void_type
);
24144 int addr_size
= this->addr_size ();
24146 if (TYPE_LENGTH (addr_type
) == addr_size
)
24149 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
24153 /* Locate the .debug_info compilation unit from CU's objfile which contains
24154 the DIE at OFFSET. Raises an error on failure. */
24156 static struct dwarf2_per_cu_data
*
24157 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24158 unsigned int offset_in_dwz
,
24159 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24161 struct dwarf2_per_cu_data
*this_cu
;
24165 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24168 struct dwarf2_per_cu_data
*mid_cu
;
24169 int mid
= low
+ (high
- low
) / 2;
24171 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24172 if (mid_cu
->is_dwz
> offset_in_dwz
24173 || (mid_cu
->is_dwz
== offset_in_dwz
24174 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
24179 gdb_assert (low
== high
);
24180 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24181 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24183 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24184 error (_("Dwarf Error: could not find partial DIE containing "
24185 "offset %s [in module %s]"),
24186 sect_offset_str (sect_off
),
24187 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24189 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24191 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24195 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24196 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24197 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24198 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24203 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24205 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24206 : per_cu (per_cu_
),
24208 has_loclist (false),
24209 checked_producer (false),
24210 producer_is_gxx_lt_4_6 (false),
24211 producer_is_gcc_lt_4_3 (false),
24212 producer_is_icc (false),
24213 producer_is_icc_lt_14 (false),
24214 producer_is_codewarrior (false),
24215 processing_has_namespace_info (false)
24220 /* Destroy a dwarf2_cu. */
24222 dwarf2_cu::~dwarf2_cu ()
24227 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24230 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24231 enum language pretend_language
)
24233 struct attribute
*attr
;
24235 /* Set the language we're debugging. */
24236 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24237 if (attr
!= nullptr)
24238 set_cu_language (DW_UNSND (attr
), cu
);
24241 cu
->language
= pretend_language
;
24242 cu
->language_defn
= language_def (cu
->language
);
24245 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24248 /* Increase the age counter on each cached compilation unit, and free
24249 any that are too old. */
24252 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24254 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24256 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24257 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24258 while (per_cu
!= NULL
)
24260 per_cu
->cu
->last_used
++;
24261 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
24262 dwarf2_mark (per_cu
->cu
);
24263 per_cu
= per_cu
->cu
->read_in_chain
;
24266 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24267 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24268 while (per_cu
!= NULL
)
24270 struct dwarf2_per_cu_data
*next_cu
;
24272 next_cu
= per_cu
->cu
->read_in_chain
;
24274 if (!per_cu
->cu
->mark
)
24277 *last_chain
= next_cu
;
24280 last_chain
= &per_cu
->cu
->read_in_chain
;
24286 /* Remove a single compilation unit from the cache. */
24289 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
24291 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24292 struct dwarf2_per_objfile
*dwarf2_per_objfile
24293 = target_per_cu
->dwarf2_per_objfile
;
24295 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24296 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24297 while (per_cu
!= NULL
)
24299 struct dwarf2_per_cu_data
*next_cu
;
24301 next_cu
= per_cu
->cu
->read_in_chain
;
24303 if (per_cu
== target_per_cu
)
24307 *last_chain
= next_cu
;
24311 last_chain
= &per_cu
->cu
->read_in_chain
;
24317 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24318 We store these in a hash table separate from the DIEs, and preserve them
24319 when the DIEs are flushed out of cache.
24321 The CU "per_cu" pointer is needed because offset alone is not enough to
24322 uniquely identify the type. A file may have multiple .debug_types sections,
24323 or the type may come from a DWO file. Furthermore, while it's more logical
24324 to use per_cu->section+offset, with Fission the section with the data is in
24325 the DWO file but we don't know that section at the point we need it.
24326 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24327 because we can enter the lookup routine, get_die_type_at_offset, from
24328 outside this file, and thus won't necessarily have PER_CU->cu.
24329 Fortunately, PER_CU is stable for the life of the objfile. */
24331 struct dwarf2_per_cu_offset_and_type
24333 const struct dwarf2_per_cu_data
*per_cu
;
24334 sect_offset sect_off
;
24338 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24341 per_cu_offset_and_type_hash (const void *item
)
24343 const struct dwarf2_per_cu_offset_and_type
*ofs
24344 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24346 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24349 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24352 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24354 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24355 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24356 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24357 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24359 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24360 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24363 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24364 table if necessary. For convenience, return TYPE.
24366 The DIEs reading must have careful ordering to:
24367 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24368 reading current DIE.
24369 * Not trying to dereference contents of still incompletely read in types
24370 while reading in other DIEs.
24371 * Enable referencing still incompletely read in types just by a pointer to
24372 the type without accessing its fields.
24374 Therefore caller should follow these rules:
24375 * Try to fetch any prerequisite types we may need to build this DIE type
24376 before building the type and calling set_die_type.
24377 * After building type call set_die_type for current DIE as soon as
24378 possible before fetching more types to complete the current type.
24379 * Make the type as complete as possible before fetching more types. */
24381 static struct type
*
24382 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
24384 struct dwarf2_per_objfile
*dwarf2_per_objfile
24385 = cu
->per_cu
->dwarf2_per_objfile
;
24386 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24387 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24388 struct attribute
*attr
;
24389 struct dynamic_prop prop
;
24391 /* For Ada types, make sure that the gnat-specific data is always
24392 initialized (if not already set). There are a few types where
24393 we should not be doing so, because the type-specific area is
24394 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24395 where the type-specific area is used to store the floatformat).
24396 But this is not a problem, because the gnat-specific information
24397 is actually not needed for these types. */
24398 if (need_gnat_info (cu
)
24399 && TYPE_CODE (type
) != TYPE_CODE_FUNC
24400 && TYPE_CODE (type
) != TYPE_CODE_FLT
24401 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
24402 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
24403 && TYPE_CODE (type
) != TYPE_CODE_METHOD
24404 && !HAVE_GNAT_AUX_INFO (type
))
24405 INIT_GNAT_SPECIFIC (type
);
24407 /* Read DW_AT_allocated and set in type. */
24408 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24409 if (attr
!= NULL
&& attr
->form_is_block ())
24411 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24412 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24413 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
24415 else if (attr
!= NULL
)
24417 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
24418 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24419 sect_offset_str (die
->sect_off
));
24422 /* Read DW_AT_associated and set in type. */
24423 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24424 if (attr
!= NULL
&& attr
->form_is_block ())
24426 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24427 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24428 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
24430 else if (attr
!= NULL
)
24432 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
24433 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24434 sect_offset_str (die
->sect_off
));
24437 /* Read DW_AT_data_location and set in type. */
24438 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24439 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
24440 cu
->per_cu
->addr_type ()))
24441 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
24443 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24444 dwarf2_per_objfile
->die_type_hash
24445 = htab_up (htab_create_alloc (127,
24446 per_cu_offset_and_type_hash
,
24447 per_cu_offset_and_type_eq
,
24448 NULL
, xcalloc
, xfree
));
24450 ofs
.per_cu
= cu
->per_cu
;
24451 ofs
.sect_off
= die
->sect_off
;
24453 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24454 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24456 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24457 sect_offset_str (die
->sect_off
));
24458 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24459 struct dwarf2_per_cu_offset_and_type
);
24464 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24465 or return NULL if the die does not have a saved type. */
24467 static struct type
*
24468 get_die_type_at_offset (sect_offset sect_off
,
24469 struct dwarf2_per_cu_data
*per_cu
)
24471 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24472 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
24474 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24477 ofs
.per_cu
= per_cu
;
24478 ofs
.sect_off
= sect_off
;
24479 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24480 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
24487 /* Look up the type for DIE in CU in die_type_hash,
24488 or return NULL if DIE does not have a saved type. */
24490 static struct type
*
24491 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24493 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
24496 /* Add a dependence relationship from CU to REF_PER_CU. */
24499 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24500 struct dwarf2_per_cu_data
*ref_per_cu
)
24504 if (cu
->dependencies
== NULL
)
24506 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24507 NULL
, &cu
->comp_unit_obstack
,
24508 hashtab_obstack_allocate
,
24509 dummy_obstack_deallocate
);
24511 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24513 *slot
= ref_per_cu
;
24516 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24517 Set the mark field in every compilation unit in the
24518 cache that we must keep because we are keeping CU. */
24521 dwarf2_mark_helper (void **slot
, void *data
)
24523 struct dwarf2_per_cu_data
*per_cu
;
24525 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
24527 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24528 reading of the chain. As such dependencies remain valid it is not much
24529 useful to track and undo them during QUIT cleanups. */
24530 if (per_cu
->cu
== NULL
)
24533 if (per_cu
->cu
->mark
)
24535 per_cu
->cu
->mark
= true;
24537 if (per_cu
->cu
->dependencies
!= NULL
)
24538 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24543 /* Set the mark field in CU and in every other compilation unit in the
24544 cache that we must keep because we are keeping CU. */
24547 dwarf2_mark (struct dwarf2_cu
*cu
)
24552 if (cu
->dependencies
!= NULL
)
24553 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24557 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
24561 per_cu
->cu
->mark
= false;
24562 per_cu
= per_cu
->cu
->read_in_chain
;
24566 /* Trivial hash function for partial_die_info: the hash value of a DIE
24567 is its offset in .debug_info for this objfile. */
24570 partial_die_hash (const void *item
)
24572 const struct partial_die_info
*part_die
24573 = (const struct partial_die_info
*) item
;
24575 return to_underlying (part_die
->sect_off
);
24578 /* Trivial comparison function for partial_die_info structures: two DIEs
24579 are equal if they have the same offset. */
24582 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24584 const struct partial_die_info
*part_die_lhs
24585 = (const struct partial_die_info
*) item_lhs
;
24586 const struct partial_die_info
*part_die_rhs
24587 = (const struct partial_die_info
*) item_rhs
;
24589 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24592 struct cmd_list_element
*set_dwarf_cmdlist
;
24593 struct cmd_list_element
*show_dwarf_cmdlist
;
24596 set_dwarf_cmd (const char *args
, int from_tty
)
24598 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
24603 show_dwarf_cmd (const char *args
, int from_tty
)
24605 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
24609 show_check_physname (struct ui_file
*file
, int from_tty
,
24610 struct cmd_list_element
*c
, const char *value
)
24612 fprintf_filtered (file
,
24613 _("Whether to check \"physname\" is %s.\n"),
24617 void _initialize_dwarf2_read ();
24619 _initialize_dwarf2_read ()
24621 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24622 Set DWARF specific variables.\n\
24623 Configure DWARF variables such as the cache size."),
24624 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24625 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24627 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24628 Show DWARF specific variables.\n\
24629 Show DWARF variables such as the cache size."),
24630 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24631 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24633 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24634 &dwarf_max_cache_age
, _("\
24635 Set the upper bound on the age of cached DWARF compilation units."), _("\
24636 Show the upper bound on the age of cached DWARF compilation units."), _("\
24637 A higher limit means that cached compilation units will be stored\n\
24638 in memory longer, and more total memory will be used. Zero disables\n\
24639 caching, which can slow down startup."),
24641 show_dwarf_max_cache_age
,
24642 &set_dwarf_cmdlist
,
24643 &show_dwarf_cmdlist
);
24645 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24646 Set debugging of the DWARF reader."), _("\
24647 Show debugging of the DWARF reader."), _("\
24648 When enabled (non-zero), debugging messages are printed during DWARF\n\
24649 reading and symtab expansion. A value of 1 (one) provides basic\n\
24650 information. A value greater than 1 provides more verbose information."),
24653 &setdebuglist
, &showdebuglist
);
24655 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24656 Set debugging of the DWARF DIE reader."), _("\
24657 Show debugging of the DWARF DIE reader."), _("\
24658 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24659 The value is the maximum depth to print."),
24662 &setdebuglist
, &showdebuglist
);
24664 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24665 Set debugging of the dwarf line reader."), _("\
24666 Show debugging of the dwarf line reader."), _("\
24667 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24668 A value of 1 (one) provides basic information.\n\
24669 A value greater than 1 provides more verbose information."),
24672 &setdebuglist
, &showdebuglist
);
24674 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24675 Set cross-checking of \"physname\" code against demangler."), _("\
24676 Show cross-checking of \"physname\" code against demangler."), _("\
24677 When enabled, GDB's internal \"physname\" code is checked against\n\
24679 NULL
, show_check_physname
,
24680 &setdebuglist
, &showdebuglist
);
24682 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24683 no_class
, &use_deprecated_index_sections
, _("\
24684 Set whether to use deprecated gdb_index sections."), _("\
24685 Show whether to use deprecated gdb_index sections."), _("\
24686 When enabled, deprecated .gdb_index sections are used anyway.\n\
24687 Normally they are ignored either because of a missing feature or\n\
24688 performance issue.\n\
24689 Warning: This option must be enabled before gdb reads the file."),
24692 &setlist
, &showlist
);
24694 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24695 &dwarf2_locexpr_funcs
);
24696 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24697 &dwarf2_loclist_funcs
);
24699 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24700 &dwarf2_block_frame_base_locexpr_funcs
);
24701 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24702 &dwarf2_block_frame_base_loclist_funcs
);
24705 selftests::register_test ("dw2_expand_symtabs_matching",
24706 selftests::dw2_expand_symtabs_matching::run_test
);